<commit_before>#include "pcloudapp.h"
#include "common.h"
#include <QMenu>
#include <QProcess>
#include <QUrl>
#include <QDir>
#include <QDesktopServices>

#ifdef Q_OS_MAC
#include <objc/objc.h>
#include <objc/message.h>
#endif

void PCloudApp::hideAllWindows(){
    if (reglog)
        reglog->hide();
    if (regwin)
        regwin->hide();
    if (logwin)
        logwin->hide();
    if (settingswin)
        settingswin->hide();
    if (incomingshareswin)
        incomingshareswin->hide();
    if (outgoingshareswin)
        outgoingshareswin->hide();
}

void PCloudApp::setUser(binresult *userinfo, bool rememebr){
    emit logInSignal(find_res(userinfo, "auth")->str, find_res(userinfo, "email")->str, (quint64)find_res(userinfo, "userid")->num, rememebr);
/*  emitting signal should be enough
 *  it seems that it is very important to have q-type parameters to this one
 *
    QString auth = find_res(userinfo, "auth")->str;
    QString email = find_res(userinfo, "email")->str;
    uint64_t uid = find_res(userinfo, "userid")->num;
    emit logInSignal(auth, email, uid, remember);
    logIn(auth, email, uid, remember);
    */
}

void PCloudApp::showWindow(QMainWindow *win)
{
    win->raise();
    win->activateWindow();
    win->showNormal();
    win->setWindowState(Qt::WindowActive);
    this->setActiveWindow(win);
}

void PCloudApp::showRegLog(){
    hideAllWindows();
    if (!reglog)
        reglog=new RegLogWindow(this);
    showWindow(reglog);
}

void PCloudApp::showRegister(){
    hideAllWindows();
    if (!regwin)
        regwin=new RegisterWindow(this);
    showWindow(regwin);
}

void PCloudApp::showLogin(){
    hideAllWindows();
    if (!logwin)
        logwin=new LoginWindow(this);
    showWindow(logwin);
}

void PCloudApp::showSettings(){
    hideAllWindows();
    if (!settingswin)
        settingswin=new SettingsWindow(this);
    showWindow(settingswin);
}


void PCloudApp::openCloudDir(){
    QString path = settings->get("path");

#ifdef Q_OS_WIN
    int retray = 5;
    char drive = path.toUtf8().at(0);
    if (drive >= 'A' && drive <= 'Z')
        drive -= 'A';
    else if (drive >= 'a' && drive <= 'z')
        drive -= 'a';
    else return;

    while (retray-- && !isConnected(drive)){
        Sleep(1000);
    }

    QProcess process;
    process.start("explorer", QStringList() << path);

#else
    if (isMounted()){
        QDesktopServices::openUrl(QUrl::fromLocalFile(path));
    }
#endif
}

void PCloudApp::shareFolder(){
    hideAllWindows();
    if (!sharefolderwin)
        sharefolderwin=new ShareFolderWindow(this);
    showWindow(sharefolderwin);
}

void PCloudApp::outgoingShares(){
    hideAllWindows();
    if (!outgoingshareswin)
        outgoingshareswin=new SharesWindow(this, 0);
    showWindow(outgoingshareswin);
}

void PCloudApp::incomingShares()
{
    hideAllWindows();
    if (!incomingshareswin)
        incomingshareswin=new SharesWindow(this, 1);
    showWindow(incomingshareswin);
}

void PCloudApp::logOut(){<commit_msg>Fixed problem with open pCloud drive/folder.<commit_after>#include "pcloudapp.h"
#include "common.h"
#include <QMenu>
#include <QProcess>
#include <QUrl>
#include <QDir>
#include <QDesktopServices>

#ifdef Q_OS_MAC
#include <objc/objc.h>
#include <objc/message.h>
#endif

void PCloudApp::hideAllWindows(){
    if (reglog)
        reglog->hide();
    if (regwin)
        regwin->hide();
    if (logwin)
        logwin->hide();
    if (settingswin)
        settingswin->hide();
    if (incomingshareswin)
        incomingshareswin->hide();
    if (outgoingshareswin)
        outgoingshareswin->hide();
}

void PCloudApp::setUser(binresult *userinfo, bool rememebr){
    emit logInSignal(find_res(userinfo, "auth")->str, find_res(userinfo, "email")->str, (quint64)find_res(userinfo, "userid")->num, rememebr);
/*  emitting signal should be enough
 *  it seems that it is very important to have q-type parameters to this one
 *
    QString auth = find_res(userinfo, "auth")->str;
    QString email = find_res(userinfo, "email")->str;
    uint64_t uid = find_res(userinfo, "userid")->num;
    emit logInSignal(auth, email, uid, remember);
    logIn(auth, email, uid, remember);
    */
}

void PCloudApp::showWindow(QMainWindow *win)
{
    win->raise();
    win->activateWindow();
    win->showNormal();
    win->setWindowState(Qt::WindowActive);
    this->setActiveWindow(win);
}

void PCloudApp::showRegLog(){
    hideAllWindows();
    if (!reglog)
        reglog=new RegLogWindow(this);
    showWindow(reglog);
}

void PCloudApp::showRegister(){
    hideAllWindows();
    if (!regwin)
        regwin=new RegisterWindow(this);
    showWindow(regwin);
}

void PCloudApp::showLogin(){
    hideAllWindows();
    if (!logwin)
        logwin=new LoginWindow(this);
    showWindow(logwin);
}

void PCloudApp::showSettings(){
    hideAllWindows();
    if (!settingswin)
        settingswin=new SettingsWindow(this);
    showWindow(settingswin);
}


void PCloudApp::openCloudDir(){
    QString path = settings->get("path");

#ifdef Q_OS_WIN
    int retray = 5;
    char drive = path.toUtf8().at(0);
    if (drive >= 'A' && drive <= 'Z')
        drive -= 'A';
    else if (drive >= 'a' && drive <= 'z')
        drive -= 'a';
    else return;

    while (retray-- && !isConnected(drive)){
        Sleep(1000);
    }

    if (!QProcess::startDetached("explorer.exe", QStringList(path))){
        QDesktopServices::openUrl(QUrl::fromLocalFile(path));
    }

#else
    if (isMounted()){
        QDesktopServices::openUrl(QUrl::fromLocalFile(path));
    }
#endif
}

void PCloudApp::shareFolder(){
    hideAllWindows();
    if (!sharefolderwin)
        sharefolderwin=new ShareFolderWindow(this);
    showWindow(sharefolderwin);
}

void PCloudApp::outgoingShares(){
    hideAllWindows();
    if (!outgoingshareswin)
        outgoingshareswin=new SharesWindow(this, 0);
    showWindow(outgoingshareswin);
}

void PCloudApp::incomingShares()
{
    hideAllWindows();
    if (!incomingshareswin)
        incomingshareswin=new SharesWindow(this, 1);
    showWindow(incomingshareswin);
}

void PCloudApp::logOut(){
{'fraction_non_alphanumeric': 0.14889071487263764, 'fraction_numerical': 0.0042728019720624484, 'mean_word_length': 3.728826728826729, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6774005', 'n_tokens_mistral': 2099, 'n_tokens_neox': 2064, 'n_words': 415}