예제 #1
0
void CometClient::postSynchronously(const QString &requestUrlString, const QString &postDataString, int requestIdentifier, int timeoutMilliseconds) {
    QUrl requestUrl(requestUrlString);
    QNetworkRequest request(requestUrl);

    request.setAttribute(QNetworkRequest::User, QVariant(requestIdentifier));
    request.setRawHeader("X-Requested-With", "XMLHttpRequest");
    request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");

    QByteArray data;
    data.append(postDataString);
    QNetworkReply *reply = nam->post(request, data);
    requestsMade.insert(reply);

    QTimer timer; //the timer handles timeout event
    timer.setSingleShot(true);

    QEventLoop loop;
    QObject::connect(reply, SIGNAL(readyRead()), &loop, SLOT(quit()));
    QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
    timer.start(timeoutMilliseconds);
    loop.exec(QEventLoop::ExcludeUserInputEvents);
    if(timer.isActive()) {
        timer.stop();
    } else {
        qDebug() << "postSynchronously() timeout occured";
        //reply->abort();
    }
}
void smallPictureView::wheelEvent(QWheelEvent *e){
    if(!allImgs.isEmpty()){
        if (e->orientation() == Qt::Vertical) {
            if(wheelFlag == 0){
                QTimer *timer = new QTimer(this);
                connect(timer, SIGNAL(timeout()), this, SLOT(wheelChangeImg()));
                timer->start(400);
                timer->setSingleShot(true);//once
            }
            int numDegrees = e->delta() / 8;//滚动的角度,*8就是鼠标滚动的距离
            int numSteps = numDegrees / 15;//滚动的步数,*15就是鼠标滚动的角度
            wheelFlag += numSteps;
            //selectedNum-=wheelFlag;
            selectedNum -= numSteps;
            if(selectedNum<0){
                selectedNum = imgNum-1;
            }else if(selectedNum>=imgNum){
                selectedNum = 0;
            }
           // qDebug()<<"垂直滚动 = "<<numSteps;//垂直滚动
            currentfile = allPixItem.at(selectedNum)->data(1001).toString();
            emit sendToDisplayImg(all_Qimg[selectedNum],all_size[selectedNum]);
        } else {
         qDebug()<<"水平滚动 = ";      //水平滚动
        }
        e->accept();      //接收该事件
    }else{
        QMessageBox message(QMessageBox::NoIcon, "提示", "请先选择图片文件!");
        message.setIconPixmap(QPixmap("../2.png"));
        message.exec();
    }
}
예제 #3
0
파일: updater.cpp 프로젝트: JayFoxRox/citra
void UpdaterPrivate::StopUpdateCheck(int delay, bool async) {
    if (main_process == nullptr || main_process->state() == QProcess::NotRunning) {
        return;
    }

    if (delay > 0) {
        main_process->terminate();
        if (async) {
            QTimer* timer = new QTimer(this);
            timer->setSingleShot(true);

            connect(timer, &QTimer::timeout, [=]() {
                StopUpdateCheck(0, false);
                timer->deleteLater();
            });

            timer->start(delay);
        } else {
            if (!main_process->waitForFinished(delay)) {
                main_process->kill();
                main_process->waitForFinished(100);
            }
        }
    } else {
        main_process->kill();
        main_process->waitForFinished(100);
    }
}
예제 #4
0
void BootConfig::start_install() {
    bool to_stdout = false;
    QStringList args;
    xterm->setProcessChannelMode(QProcess::ForwardedChannels);
    xterm->setStandardInputFile(QProcess::nullDevice());
    if (!to_stdout) {
        args.append("-into");
        args.append(QString("%1").arg(ui->xterm->winId()));
        args.append("-geometry");
        args.append("484x316");
        args.append("-e");
        args.append("nixos-install");
    }
    args.append("--root");
    args.append("/mnt");
    connect(xterm,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(install_finished(int,QProcess::ExitStatus)));
    if (to_stdout) {
        xterm->start("nixos-install",args);
    } else {
        xterm->start("xterm",args);
    }
    QTimer *foo = new QTimer();
    connect(foo,SIGNAL(timeout()),this,SLOT(debug1()));
    foo->setInterval(400 * 1000);
    foo->setSingleShot(true);
    foo->start();
}
void    Btowngtw::receiveCMD(QString value, QString key) {
    qDebug() << m_gtwID << " Receive command from Gateway: " << value;
    PlantMessage myMsg;
    SysError theSysError;
    if(OpenMsg::parse(value, myMsg)) {

        QTimer *timer = new QTimer(this);
        connect(timer, SIGNAL(timeout()), this, SLOT(stopTimer()));
        timer->setSingleShot(true);
        int msgID = qrand() % ((MAX_TIMER_ID + 1) - 0) + 0;
        m_timeoutMap.insert(msgID, key);
        timer->setProperty(TIMER_ID.toStdString().c_str(), msgID);
        timer->setProperty(TYPE.toStdString().c_str(), sender()->property(TYPE.toStdString().c_str()).toString());
        timer->setProperty(FRAME_TYPE.toStdString().c_str(), OpenMsg::getFrameType(value));
        qDebug() << " timer getProperty: " << sender()->property(TYPE.toStdString().c_str()).toString() << " " << timer->property(TYPE.toStdString().c_str()).toString();
        timer->start(TIMEOUT);

        qDebug() << m_gtwID << " Parsing ok, emit sendCommand Signal";
        myMsg.setSourceAddr(QPair<QString, QString>(PlantMessage::EXTERNAL, key), true);
        myMsg.setDestAddr(QPair<QString, QString>(PlantMessage::INTERNAL, PlantMessage::DEVICE), true);
        myMsg.setType(sender()->property(TYPE.toStdString().c_str()).toString());
        myMsg.setId(msgID);
        emit ReleaseMessage(myMsg, theSysError);
    }
    else {
        qDebug() << m_gtwID << " Receive command from Gateway is WRONG FORMAT";
    }
}
예제 #6
0
void CQplayerGUI::mouseReleaseEvent(QMouseEvent *e)
{
    static int init = 0;
    static QTimer timer;
    static QPoint p;
    touchAdjust(e);
    if(init == 0){
        init++;
        timer.setSingleShot(true);
        timer.setInterval(1000);
        connect(&timer,SIGNAL(timeout()),this,SLOT(clickStateReset()));
    }
    if(!ui->frameMovie->geometry().contains(e->globalPos()))
        return;
    clickCnt++;
    if(clickCnt == 1){  //第一次点击
        p = e->pos();
        timer.start();
    }
    else {  //第二次点击
        clickCnt = 0;
        timer.stop();
        if((e->pos() - p).manhattanLength() < 200)//两次点击距离10pix之内为有效双击
            media->screenNormal();
    }
}
예제 #7
0
void QgsComposerLabel::contentChanged()
{
  if ( mHtmlState )
  {
    const QString textToDraw = displayText();

    //mHtmlLoaded tracks whether the QWebPage has completed loading
    //its html contents, set it initially to false. The loadingHtmlFinished slot will
    //set this to true after html is loaded.
    mHtmlLoaded = false;

    const QUrl baseUrl = QUrl::fromLocalFile( mComposition->project()->fileInfo().absoluteFilePath() );
    mWebPage->mainFrame()->setHtml( textToDraw, baseUrl );

    //For very basic html labels with no external assets, the html load will already be
    //complete before we even get a chance to start the QEventLoop. Make sure we check
    //this before starting the loop
    if ( !mHtmlLoaded )
    {
      //Setup event loop and timeout for rendering html
      QEventLoop loop;

      //Connect timeout and webpage loadFinished signals to loop
      connect( mWebPage, SIGNAL( loadFinished( bool ) ), &loop, SLOT( quit() ) );

      // Start a 20 second timeout in case html loading will never complete
      QTimer timeoutTimer;
      timeoutTimer.setSingleShot( true );
      connect( &timeoutTimer, SIGNAL( timeout() ), &loop, SLOT( quit() ) );
      timeoutTimer.start( 20000 );

      // Pause until html is loaded
      loop.exec();
    }
  }
예제 #8
0
bool Spider::get(NetWorker *instance,QString url){
    QString address1 = "http://192.168.60.131:9200/bcc/_search?q=url:\"";
    QString address2 = "http://192.168.60.132:9200/bcc/_search?q=url:\"";
    QString address3 = "http://192.168.60.133:9200/bcc/_search?q=url:\"";
    QString address4 = "http://192.168.60.134:9200/bcc/_search?q=url:\"";
    //QString url = "http://192.168.60.134:9200/bcc/_search?q=url:\"http://www.lagou.co/jobs/218581.html?source=search\"";
    int count = rand();
    qDebug()<<address1+url+"\"";
    if(count%4==0){
        instance->get(address1+url+"\"");
    }else if(count%4==1){
        instance->get(address2+url+"\"");
    }else if(count%4==2){
        instance->get(address3+url+"\"");
    }else {
        instance->get(address4+url+"\"");
    };
    QEventLoop eventLoop;
    QTimer timer;
    timer.setSingleShot(true);
    QObject::connect(instance, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit()));
    QObject::connect(&timer,SIGNAL(timeout()),&eventLoop,SLOT(quit()));
    timer.start(3000);
    eventLoop.exec();       //block until finish
    if(timer.isActive()){
        timer.stop();
        //return false;
    }
    return instance->flag;
}
void OMIProxy::readTransferServerMessage(QString message)
{
  // send the message to interactive simulation widget
  /* QTimer and QSignalMapper are the best :) */
  QSignalMapper *pSingnalMapper = new QSignalMapper;
  QTimer *pTimer = new QTimer;
  pTimer->setSingleShot(true);
  pTimer->setInterval(1000);          // 1 sec
  connect(pTimer, SIGNAL(timeout()), pSingnalMapper, SLOT(map()));
  pSingnalMapper->setMapping(pTimer, message);
  connect(pSingnalMapper, SIGNAL(mapped(QString)), mpInteractiveSimulationTab, SLOT(recievedResult(QString)));
  pTimer->start();
  // move the cursor down before adding to the logger.
  QTextCursor textCursor = mpTransferServerTextEdit->textCursor();
  textCursor.movePosition(QTextCursor::End);
  mpTransferServerTextEdit->setTextCursor(textCursor);
  // log the message
  mpTransferServerTextEdit->setCurrentFont(QFont("Times New Roman", 10, QFont::Bold, false));
  mpTransferServerTextEdit->insertPlainText(QString(">>---- Message Received : ").append(QTime::currentTime().toString()).append(" ----"));
  mpTransferServerTextEdit->setCurrentFont(QFont("Times New Roman", 10, QFont::Normal, false));
  mpTransferServerTextEdit->insertPlainText(QString("\n>>  ").append(message).append("\n"));
  // move the cursor
  textCursor.movePosition(QTextCursor::End);
  mpTransferServerTextEdit->setTextCursor(textCursor);
}
예제 #10
0
void StratumClient::stop() {
  QEventLoop waitLoop;
  QTimer disconnectTimer;
  disconnectTimer.setSingleShot(true);
  disconnectTimer.setInterval(RECONNECT_TIMER_INTERVAL);
  connect(m_socket, &QTcpSocket::disconnected, &waitLoop, &QEventLoop::quit);
  connect(&disconnectTimer, &QTimer::timeout, &waitLoop, &QEventLoop::quit);
  m_socket->disconnectFromHost();
  disconnectTimer.start();
  if (m_socket->state() != QTcpSocket::UnconnectedState) {
    waitLoop.exec();
  }

  if (!disconnectTimer.isActive()) {
    m_socket->abort();
    disconnectTimer.stop();
  }

  if (m_reconnectTimerId != -1) {
    killTimer(m_reconnectTimerId);
    m_reconnectTimerId = -1;
  }

  if (m_responseTimerId != -1) {
    killTimer(m_responseTimerId);
    m_responseTimerId = -1;
  }

  m_activeRequestMap.clear();
  m_currentSessionId.clear();
  QWriteLocker lock(&m_jobLock);
  m_currentJob = Job();
}
예제 #11
0
void Spider::post(const QMap<QString, QVariant> &map,NetWorker *instance){
    QString address1 = "http://192.168.60.131:9200/bcc/1";
    QString address2 = "http://192.168.60.132:9200/bcc/1";
    QString address3 = "http://192.168.60.133:9200/bcc/1";
    QString address4 = "http://192.168.60.134:9200/bcc/1";
    QJsonDocument doc=QJsonDocument::fromVariant(QVariant(map));
    QByteArray j=doc.toJson();
    QString result(j);
    qDebug()<<result;
    int count = rand();
    if(count%4==0){
        instance->post(QUrl(address1),j);
    }else if(count%4==1){
        instance->post(QUrl(address2),j);
    }else if(count%4==2){
        instance->post(QUrl(address3),j);
    }else {
        instance->post(QUrl(address4),j);
    }
    QEventLoop eventLoop;
    QTimer timer;
    timer.setSingleShot(true);
    QObject::connect(instance, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit()));
    QObject::connect(&timer,SIGNAL(timeout()),&eventLoop,SLOT(quit()));
    timer.start(2000);
    eventLoop.exec();       //block until finish
    if(timer.isActive()){
        timer.stop();
    }
}
예제 #12
0
void Authorization::set_icon(const bool &isReset, const bool &hasFailed)
{
    if (hasFailed)
        ui->b_reset->setIcon(QIcon(":/icon-error"));
    else
        ui->b_reset->setIcon(QIcon(":/icon-ok"));

    ui->b_reset->setEnabled(true);

    QTimer *timer = new QTimer(this);
    timer->setSingleShot(true);
    timer->start(1000);

    if (hasFailed)
        if (isReset)
            QObject::connect(timer, &QTimer::timeout, [=] { ui->b_reset->setIcon(QIcon(":/icon-reset")); });
        else
            QObject::connect(timer, &QTimer::timeout, [=] {
                ui->b_reset->setIcon(QIcon(":/icon-reset-dark"));
                ui->b_reset->setDisabled(true);
            });
    else
        if (isReset)
            QObject::connect(timer, &QTimer::timeout, [=] {
                ui->b_reset->setIcon(QIcon(":/icon-reset-dark"));
                ui->b_reset->setDisabled(true);
            });
        else
            QObject::connect(timer, &QTimer::timeout, [=] { ui->b_reset->setIcon(QIcon(":/icon-reset")); });
}
예제 #13
0
void HostipRunner::search( const QString &searchTerm, const GeoDataLatLonBox & )
{
    if( !searchTerm.contains('.') ) {
        // Simple IP/hostname heuristic to avoid requests not needed:
        // String must contain at least one dot.
        slotNoResults();
    }
    else {
        QEventLoop eventLoop;

        QTimer timer;
        timer.setSingleShot( true );
        timer.setInterval( 15000 );

        connect( &timer, SIGNAL(timeout()),
                 &eventLoop, SLOT(quit()));
        connect( this, SIGNAL(searchFinished(QVector<GeoDataPlacemark*>)),
                 &eventLoop, SLOT(quit()) );

        // Lookup the IP address for a hostname, or the hostname if an IP address was given
        QHostInfo ::lookupHost( searchTerm, this, SLOT(slotLookupFinished(QHostInfo)));
        timer.start();

        eventLoop.exec();
    }
}
예제 #14
0
QString ConnectionTester::Private::publicIpAddress() const
{
    QString ret;
    QEventLoop eventLoop;
    QNetworkAccessManager mgr;
    QTimer timer;

    timer.setSingleShot(true);

    QObject::connect(&mgr, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit()));
    QObject::connect(&timer, SIGNAL(timeout()), &eventLoop, SLOT(quit()));

    QNetworkRequest req(QUrl(QString("http://icanhazip.com")));
    QNetworkReply *reply = mgr.get(req);

    timer.start(10000);

    eventLoop.exec();

    if (reply->error() == QNetworkReply::NoError)
    {
        ret = QString(reply->readAll()).trimmed();
    }

    delete reply;

    return ret;
}
예제 #15
0
파일: main.cpp 프로젝트: ypvk/WebSearch
void testGetRequest()
{
    QString url = "http://m.baidu.com/s?word=abc&ts=1223145&rq=ab";
    QNetworkAccessManager* networkAccessManager = new QNetworkAccessManager();
    QNetworkRequest request;
    request.setUrl(QUrl(url));
    request.setRawHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
    //request.setRawHeader("Accept-Encoding", "gzip, deflate, sdch");
    request.setRawHeader("Accept-Language", "h-CN,zh;q=0.8");
    request.setRawHeader("Host", "m.baidu.com");
    request.setRawHeader("Referer", "http://m.baidu.com");
    request.setRawHeader("Connection", "keep-alive");
    request.setRawHeader("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.93 Safari/537.36");
    QNetworkReply* reply = networkAccessManager->get(request);
    QEventLoop loop;
    NetWorkCookieJar* cookieJar = new NetWorkCookieJar(networkAccessManager);
    networkAccessManager->setCookieJar(cookieJar);
    QTimer timer;
    timer.setSingleShot(true);
    QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
    QObject::connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
    timer.start(5000);
    loop.exec();
    timer.stop();
    qDebug() << request.rawHeaderList();
    qDebug() << reply->readAll();
    qDebug() << cookieJar->getCookies();
    networkAccessManager->deleteLater();
    reply->deleteLater();
}
예제 #16
0
void deletepatient::on_Delete_clicked()

{

    QFile file("patient.dat");

    QFile file1("temp.dat");

    file.remove();

    file1.rename("patient.dat");

    pa=new prompta("Record deleted successfully!",this);

    pa->move(300,200);

    pa->show();

    QTimer *msgBoxCloseTimer = new QTimer(this);

    msgBoxCloseTimer->setInterval(3000);

    msgBoxCloseTimer->setSingleShot(true);

    connect(msgBoxCloseTimer, SIGNAL(timeout()), pa, SLOT(reject())); // or accept()

    msgBoxCloseTimer->start();

    pa->exec();

    for(int i=0;i<ui->tableWidget->rowCount();i++)

        ui->tableWidget->removeRow(0);

}
예제 #17
0
http::Response * Server::wait(QFuture<http::Response *> future) {
	
	QEventLoop loop;
	
	// Interrrupt the event loop when the result is available
	QFutureWatcher<http::Response *> watcher;
	watcher.setFuture(future);
	loop.connect(&watcher, SIGNAL(finished()), SLOT(quit()));
	
	// Prevent infinite loop if the future completes before we start the loop
	QTimer timer;
	loop.connect(&timer, SIGNAL(timeout()), SLOT(quit()));
	timer.setSingleShot(false);
	timer.start(1000);
	
	// Process events while waiting so that the UI stays responsive
	while(!future.isFinished()) {
		loop.exec();
	}
	
	http::Response * response = future.result();
	
	if(response->ok()) {
		m_lastErrorString.clear();
	} else if(!response->error().empty()) {
		m_lastErrorString = toQString(response->error());
	} else if(!response->data().empty()) {
		m_lastErrorString = toQString(response->data());
	} else {
		m_lastErrorString = "HTTP Error " + QString::number(response->status());
	}
	
	return response;
}
예제 #18
0
void deletepatient::on_Back_clicked()

{

    pa=new prompta("Any unsaved data might be lost",this);

    pa->move(300,200);

    pa->show();

    QTimer *msgBoxCloseTimer = new QTimer(this);

    msgBoxCloseTimer->setInterval(3000);

    msgBoxCloseTimer->setSingleShot(true);

    connect(msgBoxCloseTimer, SIGNAL(timeout()), pa, SLOT(reject())); // or accept()

    msgBoxCloseTimer->start();

    pa->exec();

    this->close();

    QFile file("temp.dat");

    file.remove();

    this->close();
}
예제 #19
0
void CQplayerGUI::touchAdjust(QMouseEvent *e)
{
    static int init = 0;
    static QTimer timer;
    if(init == 0){
        init++;
        timer.setSingleShot(true);
        timer.setInterval(1000);
        connect(&timer,SIGNAL(timeout()),this,SLOT(clickStateReset()));
    }
    if(ui->frameMovie->geometry() != media->row_rect)
        return;
    qDebug()<<ui->logWidget->geometry()<<"    "<<e->globalPos();
    if(!ui->logWidget->geometry().contains(e->globalPos()))
        return;
    clickCnt++;
    timer.start();
    if(clickCnt >= 3) {
        clickCnt = 0;
        timer.stop();
        system("rm /etc/pointercal.xinput  /.pointercal/ -rf");
		stop();
        system("xinput_calibrator_once.sh &");
    }
}
예제 #20
0
/**
 * QThread::run()
 *
 * Open the serial port and set it up, then starts polling.
 *
 */
void KettlerConnection::run()
{
    // Open and configure serial port
    m_serial = new QSerialPort();
    m_serial->setPortName(m_serialPortName);

    m_timer = new QTimer();
    QTimer *startupTimer = new QTimer();

    if (!m_serial->open(QSerialPort::ReadWrite))
    {
        qDebug() << "Error opening serial";
        this->exit(-1);
    } else {
        configurePort(m_serial);

        // Discard any existing data
        QByteArray data = m_serial->readAll();

        // Set up polling
        connect(m_timer, SIGNAL(timeout()), this, SLOT(requestAll()),Qt::DirectConnection);

        // Set up initial model detection
        connect(startupTimer, SIGNAL(timeout()), this, SLOT(initializePcConnection()),Qt::DirectConnection);
    }

    m_timer->setInterval(1000);
    m_timer->start();

    startupTimer->setSingleShot(true);
    startupTimer->setInterval(0);
    startupTimer->start();

    exec();
}
예제 #21
0
void ClientBlock::action_forecast_send()
{
    if (client_actions->contains("setforecast")) {
        QNetworkAccessManager* m_manager;
        m_manager = new QNetworkAccessManager(this);
        connect(m_manager, SIGNAL(finished(QNetworkReply*)),
                 this, SLOT(replyFinished(QNetworkReply*)));

        QUrl url = QUrl("http://api.openweathermap.org/data/2.5/weather?q=shebekino&APPID=5437baa043723201a6fb434e5366ec57", QUrl::TolerantMode);
        QNetworkRequest rq=QNetworkRequest(url);
        m_manager->get(rq);

        QTimer timer;
        timer.setSingleShot(true);
        QEventLoop loop;
        connect(m_manager,  SIGNAL(finished(QNetworkReply*)), &loop, SLOT(quit()) );
        connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
        timer.start(5000);
        loop.exec();

        if(timer.isActive()) {
            QTimer::singleShot(1000, &loop, SLOT(quit()));
            loop.exec();
        }

        delete m_manager;
    }
예제 #22
0
void addlens::on_Cancel_clicked()

{

    p=new prompta("Any unsaved data might be lost",this);

    p->move(200,200);

    p->show();

    QTimer *msgBoxCloseTimer = new QTimer(this);

    msgBoxCloseTimer->setInterval(3000);

    msgBoxCloseTimer->setSingleShot(true);

    connect(msgBoxCloseTimer, SIGNAL(timeout()), p, SLOT(reject())); // or accept()

    msgBoxCloseTimer->start();

    p->exec();

    this->close();

}
예제 #23
0
bool Utils::sendBlockingNetRequest(const QUrl& theUrl, QString& reply)
{
    QNetworkAccessManager manager;
    QEventLoop q;
    QTimer tT;

    manager.setProxy(M_PREFS->getProxy(QUrl("http://merkaartor.be")));

    tT.setSingleShot(true);
    connect(&tT, SIGNAL(timeout()), &q, SLOT(quit()));
    connect(&manager, SIGNAL(finished(QNetworkReply*)),
            &q, SLOT(quit()));

    QNetworkReply *netReply = manager.get(QNetworkRequest(theUrl));

    tT.start(M_PREFS->getNetworkTimeout());
    q.exec();
    if(tT.isActive()) {
        // download complete
        tT.stop();
    } else {
        return false;
    }

    reply = netReply->readAll();
    return true;
}
예제 #24
0
void Sound::slotNotificationDisplayed(Snore::Notification notification)
{
    if (notification.hints().value("silent").toBool()) {
        return;
    }
    m_player->setVolume(settingsValue(QLatin1String("Volume")).toInt());

    QString sound = notification.hints().value("sound").toString();
    if (sound.isEmpty()) {
        sound = settingsValue(QLatin1String("Sound")).toString();
    }
    snoreDebug(SNORE_DEBUG) << "SoundFile:" << sound;
    if (!sound.isEmpty()) {
        m_player->setMedia(QUrl::fromLocalFile(sound));
        snoreDebug(SNORE_DEBUG) << "SoundFile:" << m_player->media().canonicalUrl();
        m_player->play();
        QTimer *timeout = new QTimer(this);
        timeout->setSingleShot(true);
        timeout->setInterval(notification.timeout() * 1000);
        connect(timeout, &QTimer::timeout, [this, timeout] {
            m_player->stop();
            timeout->deleteLater();
        });
    }
}
void smallPictureView::mousePressEvent(QMouseEvent *e){
    if(!allImgs.isEmpty()){
        currentfile = this->itemAt(e->pos())->data(1001).toString();
        if(currentfile!=""){
            for(int i=0;i<imgNum;i++){
                if(!allImgs.at(i).absoluteFilePath().compare(currentfile))
                    selectedNum = i;
            }
            //qDebug()<<"selectednum"<<selectedNum<<currentfile;
        }
        if(selectedNum!=oldSelectNum){
            if(wheelFlag == 0){
                QTimer *timer = new QTimer(this);
                connect(timer, SIGNAL(timeout()), this, SLOT(wheelChangeImg()));
                timer->start(300);
                timer->setSingleShot(true);//once
            }
            wheelFlag = 1;
            //changeSelectNum();
            emit sendToDisplayImg(all_Qimg[selectedNum],all_size[selectedNum]);
        }
    }else{
        QMessageBox message(QMessageBox::NoIcon, "提示", "请先选择图片文件!");
        message.setIconPixmap(QPixmap("../2.png"));
        message.exec();
    }
}
예제 #26
0
void WaitForWindowTest::testWaitEndedByModalDialog() {
    WaitForWindow waitForWindow("theName");
    waitForWindow.setActive(true);

    //WaitFor* must be registered in order to be used with QSignalSpy
    int waitForStarType = qRegisterMetaType<WaitFor*>("WaitFor*");
    QSignalSpy waitEndedSpy(&waitForWindow, SIGNAL(waitEnded(WaitFor*)));

    QDialog* modalDialog = new QDialog(mMainWindow); //krazy:exclude=qclasses
    modalDialog->setObjectName("theName");

    QTimer timerAccept;
    timerAccept.setSingleShot(true);
    timerAccept.setInterval(1500);
    connect(&timerAccept, SIGNAL(timeout()), modalDialog, SLOT(accept()));

    //Check that the condition was met before closing the modal dialog to ensure
    //that the processing of events or signals is not halted due to being modal.
    queueAssertConditionMet(&waitForWindow, &waitEndedSpy, 500);

    timerAccept.start();
    modalDialog->exec(); //krazy:exclude=crashy

    modalDialog->deleteLater();

    QVERIFY(waitForWindow.conditionMet());
    QCOMPARE(waitEndedSpy.count(), 1);
    QVariant argument = waitEndedSpy.at(0).at(0);
    QCOMPARE(argument.userType(), waitForStarType);
    QCOMPARE(qvariant_cast<WaitFor*>(argument), &waitForWindow);
}
예제 #27
0
/**
 * QML wrapper to download an url and returning it as text
 *
 * @param url
 * @return {QString} the content of the downloaded url
 */
QString ScriptingService::downloadUrlToString(QUrl url) {
    QNetworkAccessManager *manager = new QNetworkAccessManager(this);
    QEventLoop loop;
    QTimer timer;

    timer.setSingleShot(true);
    connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
    connect(manager, SIGNAL(finished(QNetworkReply *)), &loop, SLOT(quit()));

    // 10 sec timeout for the request
    timer.start(10000);

    QNetworkRequest networkRequest = QNetworkRequest(url);

#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
    networkRequest.setAttribute(QNetworkRequest::FollowRedirectsAttribute,
                                true);
#endif

    QNetworkReply *reply = manager->get(networkRequest);
    loop.exec();

    // if we didn't get a timeout let us return the content
    if (timer.isActive()) {
        // get the text from the network reply
        QString data = reply->readAll();
        if (data.size() > 0) {
            return data;
        }
    }

    // timer elapsed, no reply from network request or empty data
    return "";
}
예제 #28
0
FenetreProgression::FenetreProgression(QString logiciel, QWidget *parent, QString source) : QDialog(parent)
{
	m_curAction = new QLabel("Copie des fichiers de profil en cour...");
    m_curAction->setAlignment(Qt::AlignHCenter);
	
	m_progressBar = new QProgressBar;
	m_progressBar->setMaximum(100);
	m_progressBar->setMinimum(0);
	m_progressBar->setValue(0);
	m_progressBar->setAlignment(Qt::AlignHCenter);
	
	m_bouton = new QPushButton("OK");
	m_bouton->setEnabled(false);
	
	QVBoxLayout *layoutPrincipale = new QVBoxLayout;
	layoutPrincipale->addWidget(m_curAction);
	layoutPrincipale->addWidget(m_progressBar);
	layoutPrincipale->addWidget(m_bouton);
	
    setWindowTitle("Copie...");
	setWindowIcon(QIcon("icone.png"));
	setLayout(layoutPrincipale);
	
	m_logiciel = logiciel;
	m_source = source;
	
    // le timer pour permettre la creation de la fenetre
    QTimer *timer = new QTimer(this);
    timer->setSingleShot(true);
    QWidget::connect(timer, SIGNAL(timeout()), this, SLOT(copyDirIm()));
    timer->start(500);
	
    // Le bouton OK
	QWidget::connect(m_bouton, SIGNAL(clicked()), this, SLOT(accept()));
}
예제 #29
0
void OsmNominatimRunner::search( const QString &searchTerm, const GeoDataLatLonBox &preferred )
{    
    QString base = "http://nominatim.openstreetmap.org/search?";
    QString query = "q=%1&format=xml&addressdetails=1&accept-language=%2";
    QString url = QString(base + query).arg(searchTerm).arg(MarbleLocale::languageCode());
    if( !preferred.isEmpty() ) {
        GeoDataCoordinates::Unit deg = GeoDataCoordinates::Degree;
        QString viewbox( "&viewbox=%1,%2,%3,%4&bounded=1" ); // left, top, right, bottom
        url += viewbox.arg(preferred.west(deg))
                      .arg(preferred.north(deg))
                      .arg(preferred.east(deg))
                      .arg(preferred.south(deg));

    }
    m_request.setUrl(QUrl(url));
    m_request.setRawHeader("User-Agent", TinyWebBrowser::userAgent("Browser", "OsmNominatimRunner") );

    QEventLoop eventLoop;

    QTimer timer;
    timer.setSingleShot( true );
    timer.setInterval( 15000 );

    connect( &timer, SIGNAL(timeout()),
             &eventLoop, SLOT(quit()));
    connect( this, SIGNAL(searchFinished(QVector<GeoDataPlacemark*>)),
             &eventLoop, SLOT(quit()) );

    // @todo FIXME Must currently be done in the main thread, see bug 257376
    QTimer::singleShot( 0, this, SLOT(startSearch()) );
    timer.start();

    eventLoop.exec();
}
예제 #30
0
void WeatherModel::replyFinished(QNetworkReply *reply)
{
    QByteArray data = reply->readAll();
    qDebug() << data;

    QJsonDocument doc = QJsonDocument::fromJson(data);

    QJsonObject query = doc.object().value("query").toObject();
    if (query.contains("results")) {
        QJsonObject res = query.value("results").toObject();
        QJsonObject cond = res.value("channel").toObject().value("item").toObject().value("condition").toObject();

        //m_results[reply->url()] = cond.value("text").toString();
        if (m_results.contains(reply->url())) {
            Report* r = m_results.value(reply->url());
            r->weather = cond.value("text").toString();
            r->lastSync = QDateTime::currentDateTime();
            emit dataChanged(createIndex(r->pos, 1),
                             createIndex(r->pos, 3));

            QTimer *t = new QTimer();
            t->setInterval(3000);
            t->setSingleShot(true);
            // Passing data in this way is simple, but not really pretty....
            t->setObjectName(reply->url().toString());
            connect(t, &QTimer::timeout,
                    this, &WeatherModel::updateData);
            t->start();
        }
    }
}