コード例 #1
0
ファイル: mainwindow.cpp プロジェクト: ypvk/WebSearch
void MainWindow::runSearchJob(int threadNum)
{
    //TODO change

    QList<QPair<QString, QString> > keyWords = DBUtil::getKeyWords();
    QList<EngineInfo> engineInfos = DBUtil::getEngineInfos();
    if (configDialog->isUseProxyApi())
    {
        queryProxys(configDialog->getProxyApiValue());
    }
    else
    {
        proxys = DBUtil::getProxys();
    }
    if (keyWords.isEmpty() || engineInfos.isEmpty())
    {
        qDebug() << "empty job";
        this->onJobFinished();
        return;
    }
    int deta = proxys.count() / threadNum;
    if (deta == 0) deta = 1;

    for(int i = 0; i < threadNum; i++)
    {
        QList<QPair<QString, int> > tmpProxys;
        for (int j = 0; j < deta; j++)
        {
            if(!proxys.isEmpty()) {
                tmpProxys << proxys.first();
                proxys.pop_front();
            }
        }
        //build clickInfo
        QList<ClickInfo> clickInfos;
        for (int j = 0; j < engineInfos.size(); j++)
        {
            clickInfos << ClickInfo(engineInfos.at(j), keyWords, tmpProxys, 1);
        }
//        Browser* browser = new Browser(NULL, i);
//        connect(browser, SIGNAL(updateClickInfo(UpdateInfo)), this, SLOT(onJobUpdate(UpdateInfo)));
//        connect(browser, SIGNAL(jobFinished(int)), this, SLOT(onJobFinishedById(int)));
//        browser->show();
//        browser->move(this->pos() + QPoint(200, 200));
//        browsers.append(browser);
//        browser->search(clickInfos);
        QueryThread* thread = new QueryThread(NULL, clickInfos, i);
        connect(thread, SIGNAL(updateClickInfo(UpdateInfo)), this, SLOT(onJobUpdate(UpdateInfo)));
        connect(thread, SIGNAL(finished()), this, SLOT(onTheadFinished()));
        thread->start();
    }
}
コード例 #2
0
ファイル: window.cpp プロジェクト: 7omate/pydio-sync-ui
Window::Window()
{
    QCommandLineParser parser;
    QCommandLineOption pathToAgentOption("p", "Path to sync agent", "agentPath");
    parser.addOption(pathToAgentOption);
    QCommandLineOption skipAgentStartOption("s", "Do not try to start agent on start up", "skipAgentStart");
    parser.addOption(skipAgentStartOption);
    QCommandLineOption dumbTestOption("test", "Super simple start/stop test.");
    parser.addOption(dumbTestOption);
    parser.process(*qApp);
    bool startAgent = true;
    if(parser.isSet(skipAgentStartOption) && parser.value(skipAgentStartOption) == "true"){
        startAgent = false;
    }
    cmdHelper = new CmdHelper(this, (parser.isSet(pathToAgentOption))?parser.value(pathToAgentOption):"");
    if(parser.isSet(dumbTestOption)){
        QTimer *t = new QTimer(this);
        connect(t, SIGNAL(timeout()), qApp, SLOT(quit()));
        t->setInterval(5000);
        t->setSingleShot(true);
        t->start();
        qDebug()<<"Dumb test, will exit in 5 seconds...";
    }
    else{
        if(startAgent){
#if defined(Q_OS_WIN) || defined(Q_OS_LINUX)
            cmdHelper->launchAgentProcess();
#elif defined(Q_OS_MAC)
            qDebug()<<"Starting agent via launchctl command.";
            cmdHelper->launchAgentMac();
#endif

        }

        if(CHECK_FOR_UPDATE){
            updateDialog = new UpdateDialog(this);
            updatePinger = new PydioUpdatePinger(this);
            connect(updatePinger, SIGNAL(updateFound(QString,QString,QString,QString)),
                    updateDialog, SLOT(proposeDownload(QString,QString,QString,QString)));
            updatePinger->lookForUpdate();
        }

        QString dataDir = CmdHelper::getAppDataDir() +'/'+ PORT_CONFIG_FILE_NAME;
        portConfigurer = new PortConfigurer(dataDir);
        pollTimer = new QTimer(this);
        pollTimer->setInterval(POLL_INTERVAL);
        pollTimer->setSingleShot(true);

        httpManager = new HTTPManager(this);
        this->createTrayIcon();
        tray->show();

        aboutDialog = new AboutDialog(this);

        connect(pollTimer, SIGNAL(timeout()), httpManager, SLOT(poll()));
        connect(httpManager, SIGNAL(requestFinished()), pollTimer, SLOT(start()));
        connect(httpManager, SIGNAL(newJob(Job*)), tray, SLOT(onNewJob(Job*)));
        connect(httpManager, SIGNAL(jobUpdated(QString)), tray, SLOT(onJobUpdate(QString)));
        connect(httpManager, SIGNAL(jobDeleted(QString)), tray, SLOT(onJobDeleted(QString)));
        connect(httpManager, SIGNAL(connectionProblem()), tray, SLOT(connectionLost()));
        connect(httpManager, SIGNAL(agentReached()), this, SLOT(agentReached()));
        connect(httpManager, SIGNAL(noActiveJobsAtLaunch()), this, SLOT(show()));
        connect(httpManager, SIGNAL(jobsCleared()), tray, SLOT(jobsCleared()));
        connect(httpManager, SIGNAL(webUI404()), this, SLOT(notFoundFromPython()));
        connect(httpManager, SIGNAL(noInternetConnection()), tray, SLOT(noInternetConnection()));
        connect(httpManager, SIGNAL(internetConnectionOk()), tray, SLOT(internetConnectionOk()));
        connect(httpManager, SIGNAL(connectionProblem()), this, SLOT(connectionLost()));
        connect(httpManager, SIGNAL(jobNotifyMessage(QString,QString,QString)), tray, SLOT(notificationReceived(QString,QString,QString)));

        connect(tray, SIGNAL(about()), this, SLOT(about()));
        connect(tray, SIGNAL(pauseSync()), httpManager, SLOT(pauseSync()));
        connect(tray, SIGNAL(resumeSync()), httpManager, SLOT(resumeSync()));
        connect(tray, SIGNAL(quit()), this, SLOT(cleanQuit()));
        connect(tray, SIGNAL(launchAgentSignal()), cmdHelper, SLOT(launchAgentProcess()));
//        connect(cmdHelper, SIGNAL(winAgentLaunched()), this, SLOT(show()));

        settingsWebView = new QWebView();

        jsDialog = new JSEventHandler(this);

        portConfigurer->updatePorts();
        httpManager->setUrl(AGENT_SERVER_URL + portConfigurer->port(), portConfigurer->username(), portConfigurer->password());
        httpManager->poll();

        //this->setWindowFlags(Qt::Tool);
        setWindowTitle(PYDIO_DATA_DIR);
        setWindowIcon(QIcon(":/images/PydioSync-Systray-Mac.png"));
    }
}