示例#1
0
文件: Widget.cpp 项目: Yadoms/yadoms
      void CWidget::remove(CWorkerTools::WorkerProgressFunc progressCallback, const std::string & widgetName)
      {
         YADOMS_LOG(information) << "Removing widget " << widgetName;

         shared::CDataContainer callbackData;
         callbackData.set("widgetName", widgetName);

         progressCallback(true, 0.0f, i18n::CClientStrings::UpdateWidgetRemove, shared::CStringExtension::EmptyString, callbackData);


         try
         {
            /////////////////////////////////////////////
            //1. remove plugin folder
            /////////////////////////////////////////////
            Poco::Path widgetPath(CWorkerTools::getWidgetBasePath());
            widgetPath.append(widgetName);

            Poco::File toDelete(widgetPath);
            if (toDelete.exists())
               toDelete.remove(true);

            progressCallback(true, 100.0f, i18n::CClientStrings::UpdateWidgetSuccess, shared::CStringExtension::EmptyString, callbackData);
         }
         catch (std::exception & ex)
         {
            //fail to remove package
            YADOMS_LOG(error) << "Fail to delete widget : " << widgetName << " : " << ex.what();
            progressCallback(false, 100.0f, i18n::CClientStrings::UpdateWidgetRemoveFailed, ex.what(), callbackData);
         }
      }
示例#2
0
void OutputTableBase::openFile(QString appendix) {
    QString fileNameApp = insertAppendix(fileName, appendix);
    QString useFileName = (runNumber() == 1 || hasSummary()) ?
                          fileNameApp : insertNumber(fileNameApp, runNumber());

    QString path = FileLocations::location(FileLocationInfo::Output).absolutePath();
    QString filePath = path + "/" + useFileName;
    outputFilePaths << filePath;

    file.setFileName(filePath);
    if (!file.open(QIODevice::Text | QIODevice::WriteOnly))
        throw Exception("Could not open output file to write table:\n'" + filePath + "'");

    // If more than one file then give the first file a number too
    if (runNumber() == 2 && !hasSummary()) {
        QString filePath = path + "/" + fileNameApp;
        QFile prevFile(filePath);

        QString newName = path + "/" + insertNumber(fileNameApp, 1);
        outputFilePaths[0] = newName;

        // Delete any existing file named newName
        QFile toDelete(newName);
        toDelete.remove();
        prevFile.rename(newName);
    }
}
示例#3
0
void DataInput::onFinishedQml()
{
    QString txt;

    int typeNumber = typeToInt(type);
    switch(typeNumber)
    {
    case 0: {
//        emit runPattern(pattern->name(), true);
    }
        break;

    case 1: {

        txt = reply->readAll();
        int idx=txt.indexOf(QRegExp("#([0-9a-fA-F]{6})"));
        QColor c=QColor("#000000");
        if(idx!=-1)
        {
            c=QColor(txt.mid(idx,7));
            emit setColor(c);
            emit setValueRet(c.name().toUpper());
        }
        else
        {
            emit setColor(c);
            emit setValueRet("NO VALUE");
        }
    }
        break;
    }
    delete reply;
    emit toDelete(this);
}
示例#4
0
    bool RangeDeleter::queueDelete(const std::string& ns,
                                   const BSONObj& min,
                                   const BSONObj& max,
                                   const BSONObj& shardKeyPattern,
                                   bool secondaryThrottle,
                                   Notification* notifyDone,
                                   std::string* errMsg) {
        string dummy;
        if (errMsg == NULL) errMsg = &dummy;

        auto_ptr<RangeDeleteEntry> toDelete(new RangeDeleteEntry(ns,
                                                                 min.getOwned(),
                                                                 max.getOwned(),
                                                                 shardKeyPattern.getOwned(),
                                                                 secondaryThrottle));
        toDelete->notifyDone = notifyDone;

        {
            scoped_lock sl(_queueMutex);
            if (_stopRequested) {
                *errMsg = "deleter is already stopped.";
                return false;
            }

            if (!canEnqueue_inlock(ns, min, max, errMsg)) {
                return false;
            }

            _deleteSet.insert(new NSMinMax(ns, min, max));
        }

        {
            boost::scoped_ptr<OperationContext> txn(getGlobalEnvironment()->newOpCtx());
            _env->getCursorIds(txn.get(), ns, &toDelete->cursorsToWait);
        }

        toDelete->stats.queueStartTS = jsTime();

        {
            scoped_lock sl(_queueMutex);

            if (toDelete->cursorsToWait.empty()) {
                toDelete->stats.queueEndTS = jsTime();
                _taskQueue.push_back(toDelete.release());
                _taskQueueNotEmptyCV.notify_one();
            }
            else {
                log() << "rangeDeleter waiting for " << toDelete->cursorsToWait.size()
                      << " cursors in " << ns << " to finish" << endl;

                _notReadyQueue.push_back(toDelete.release());
            }
        }

        return true;
    }
示例#5
0
文件: Widget.cpp 项目: Yadoms/yadoms
      void CWidget::update(CWorkerTools::WorkerProgressFunc progressCallback, const std::string & widgetName, const std::string & downloadUrl)
      {
         YADOMS_LOG(information) << "Updating widget " << widgetName << " from " << downloadUrl;

         shared::CDataContainer callbackData;
         callbackData.set("widgetName", widgetName);
         callbackData.set("downloadUrl", downloadUrl);

         progressCallback(true, 0.0f, i18n::CClientStrings::UpdateWidgetUpdate, shared::CStringExtension::EmptyString, callbackData);
         /////////////////////////////////////////////
         //1. download package
         /////////////////////////////////////////////
         try
         {
            YADOMS_LOG(information) << "Downloading widget package";
            progressCallback(true, 0.0f, i18n::CClientStrings::UpdateWidgetDownload, shared::CStringExtension::EmptyString, callbackData);
            Poco::Path downloadedPackage = CWorkerTools::downloadPackage(downloadUrl, progressCallback, i18n::CClientStrings::UpdateWidgetDownload, 0.0, 90.0);
            YADOMS_LOG(information) << "Downloading widget package with sucess";



            /////////////////////////////////////////////
            //2. deploy package
            /////////////////////////////////////////////
            try
            {
               YADOMS_LOG(information) << "Deploy widget package " << downloadedPackage.toString();
               progressCallback(true, 90.0f, i18n::CClientStrings::UpdateWidgetDeploy, shared::CStringExtension::EmptyString, callbackData);
               Poco::Path widgetPath = CWorkerTools::deployWidgetPackage(downloadedPackage);

               YADOMS_LOG(information) << "Widget installed with success";
               progressCallback(true, 100.0f, i18n::CClientStrings::UpdateWidgetSuccess, shared::CStringExtension::EmptyString, callbackData);
            }
            catch (std::exception & ex)
            {
               //fail to extract package file
               YADOMS_LOG(error) << "Fail to deploy widget package : " << ex.what();
                progressCallback(false, 100.0f, i18n::CClientStrings::UpdateWidgetDeployFailed, ex.what(), callbackData);
            }


            //delete downloaded zip file
            Poco::File toDelete(downloadedPackage.toString());
            if (toDelete.exists())
               toDelete.remove();

         }
         catch (std::exception & ex)
         {
            //fail to download package
            YADOMS_LOG(error) << "Fail to download pwidget ackage : " << ex.what();
            progressCallback(false, 100.0f, i18n::CClientStrings::UpdateWidgetDownloadFailed, ex.what(), callbackData);
         }
      }
示例#6
0
    bool RangeDeleter::queueDelete(const std::string& ns,
                                   const BSONObj& min,
                                   const BSONObj& max,
                                   const BSONObj& shardKeyPattern,
                                   bool secondaryThrottle,
                                   Notification* notifyDone,
                                   std::string* errMsg) {
        string dummy;
        if (errMsg == NULL) errMsg = &dummy;

        auto_ptr<RangeDeleteEntry> toDelete(new RangeDeleteEntry);
        toDelete->ns = ns;
        toDelete->min = min.getOwned();
        toDelete->max = max.getOwned();
        toDelete->shardKeyPattern = shardKeyPattern.getOwned();
        toDelete->secondaryThrottle = secondaryThrottle;
        toDelete->notifyDone = notifyDone;

        {
            scoped_lock sl(_queueMutex);
            if (_stopRequested) {
                *errMsg = "deleter is already stopped.";
                return false;
            }

            if (!canEnqueue_inlock(ns, min, max, errMsg)) {
                return false;
            }

            _deleteSet.insert(new NSMinMax(ns, min, max));
            _stats->incTotalDeletes_inlock();
            _stats->incPendingDeletes_inlock();
        }

        _env->getCursorIds(ns, &toDelete->cursorsToWait);

        {
            scoped_lock sl(_queueMutex);

            if (toDelete->cursorsToWait.empty()) {
                _taskQueue.push_back(toDelete.release());
                _taskQueueNotEmptyCV.notify_one();
            }
            else {
                log() << "rangeDeleter waiting for " << toDelete->cursorsToWait.size()
                      << " cursors in " << ns << " to finish" << endl;

                _notReadyQueue.push_back(toDelete.release());
            }
        }

        return true;
    }
示例#7
0
    bool RangeDeleter::queueDelete(OperationContext* txn,
                                   const RangeDeleterOptions& options,
                                   Notification* notifyDone,
                                   std::string* errMsg) {
        string dummy;
        if (errMsg == NULL) errMsg = &dummy;

        const string& ns(options.range.ns);
        const BSONObj& min(options.range.minKey);
        const BSONObj& max(options.range.maxKey);

        auto_ptr<RangeDeleteEntry> toDelete(
                new RangeDeleteEntry(options));
        toDelete->notifyDone = notifyDone;

        {
            boost::lock_guard<boost::mutex> sl(_queueMutex);
            if (_stopRequested) {
                *errMsg = "deleter is already stopped.";
                return false;
            }

            if (!canEnqueue_inlock(ns, min, max, errMsg)) {
                return false;
            }

            _deleteSet.insert(new NSMinMax(ns, min.getOwned(), max.getOwned()));
        }

        if (options.waitForOpenCursors) {
            _env->getCursorIds(txn, ns, &toDelete->cursorsToWait);
        }

        toDelete->stats.queueStartTS = jsTime();

        if (!toDelete->cursorsToWait.empty())
            logCursorsWaiting(toDelete.get());

        {
            boost::lock_guard<boost::mutex> sl(_queueMutex);

            if (toDelete->cursorsToWait.empty()) {
                toDelete->stats.queueEndTS = jsTime();
                _taskQueue.push_back(toDelete.release());
                _taskQueueNotEmptyCV.notify_one();
            }
            else {
                _notReadyQueue.push_back(toDelete.release());
            }
        }

        return true;
    }
示例#8
0
void DataInput::onProcessFinished()
{
    while(readingProcess)
        QThread::usleep(200);
    process->close();
    process->deleteLater();
    //qDebug()<<processOutput;
    int idx = processOutput.indexOf(QRegExp("#([0-9a-fA-F]{6})"));
    QColor c=QColor("#000000");
    if(idx!=-1)
    {
        c=QColor(processOutput.mid(idx,7));
        emit setColor(c);
        emit addReceiveEvent(QDateTime::currentDateTime().toTime_t(), c.name().toUpper(), "SCRIPT");
        input->setArg2(c.name());
    }
    else
    {
        bool found = false;
        int currentIndex = 0;
        int idx2;
        QString pName;
        while(!found)
        {
            idx = processOutput.indexOf("\"", currentIndex);
            if(idx == -1)
                break;
            currentIndex = idx+1;
            idx2 = processOutput.indexOf("\"", currentIndex);
            if(idx2 == -1)
                break;
            currentIndex = idx2+1;

            pName = processOutput.mid(idx+1, idx2-idx-1);
            for(int i=0; i<patternList.count(); i++)
            {
                if(patternList[i] == pName)
                {
                    emit runPattern(pName, false);
                    emit addReceiveEvent(QDateTime::currentDateTime().toTime_t(), pName, "SCRIPT");
                    input->setArg2(pName);
                    found = true;
                    break;
                }
            }

        }
        if(!found)
            input->setArg2("NO VALUE");
    }
    emit toDelete(this);
}
示例#9
0
bool RangeDeleter::canEnqueue_inlock(StringData ns,
                                     const BSONObj& min,
                                     const BSONObj& max,
                                     string* errMsg) const {
    NSMinMax toDelete(ns.toString(), min, max);
    if (_deleteSet.count(&toDelete) > 0) {
        *errMsg = str::stream() << "ns: " << ns << ", min: " << min << ", max: " << max
                                << " is already being processed for deletion.";
        return false;
    }

    return true;
}
示例#10
0
/**
 * Destroys the PsiContactList along with all PsiAccounts.
 */
PsiContactList::~PsiContactList()
{
	emit destroying();
	accountsLoaded_ = false;

	// PsiAccount calls some signals while being deleted prior to being unlinked,
	// which in result could cause calls to PsiContactList::accounts()
	QList<PsiAccount*> toDelete(accounts_);

	enabledAccounts_.clear();

	foreach(PsiAccount* account, toDelete)
		delete account;
}
示例#11
0
void DataInput::onError()
{
    if(type == "SCRIPT")
    {
        //qDebug() << "Script error:";
        //qDebug() << process->errorString();
        process->deleteLater();
//        while(process)
            QThread::usleep(200);
    }
    else
    {
        delete reply;
    }
    emit toDelete(this);
}
示例#12
0
void DPMeans<T,DS>::updateCenters()
{
  KMeans<T,DS>::updateCenters();
//  this->ps_ = DS::computeCenters(*this->spx_,this->z_,this->K_,this->Ns_);

  vector<bool> toDelete(this->K_,false);
  for(uint32_t k=0; k<this->K_; ++k)
  {
    if (!this->cls_[k]->isInstantiated()) 
//    if (this->Ns_(k) <= 0) 
      toDelete[k] = true;
  }

  uint32_t kNew = this->K_;
  for(int32_t k=this->K_-1; k>-1; --k)
    if(toDelete[k])
    {
      cout<<"cluster k "<<k<<" empty"<<endl;
#pragma omp parallel for 
      for(uint32_t i=0; i<this->N_; ++i)
      {
        if(static_cast<int32_t>(this->cld_->z(i)) >= k) this->cld_->z(i) -= 1;
      }
      kNew --;
    }

//  Matrix<T,Dynamic,Dynamic> psNew(this->D_,kNew);
//  int32_t offset = 0;
  for(int32_t k=this->K_; k >=0 ; --k)
    if(toDelete[k])
    {
      this->cls_.erase(this->cls_.begin()+k);
    }
//  for(uint32_t k=0; k<this->K_; ++k)
//    if(toDelete[k])
//    {
//      offset ++;
//    }else{
//      psNew.col(k-offset) = this->ps_.col(k);
//    }
//  this->ps_ = psNew;
  this->K_ = kNew;
};
示例#13
0
void DataInput::onProcessFinishedQml()
{
    while(readingProcess)
        QThread::usleep(200);
    process->close();
    process->deleteLater();
    int idx = processOutput.indexOf(QRegExp("#([0-9a-fA-F]{6})"));
    QColor c=QColor("#000000");
    if(idx!=-1)
    {
        c=QColor(processOutput.mid(idx,7));
        emit setColor(c);
        emit setValueRet(c.name().toUpper());
    }
    else
    {
        emit setColor(c);
        emit setValueRet("NO VALUE");
    }
    emit toDelete(this);
}
示例#14
0
 TEST_FIXTURE(UrlTagFixtureClass, DeleteUrlNoMatch) {
     wxURI toDelete(wxT("http://localhost/backend.php"));
     Finder.DeleteUrl(toDelete, SourceDirs);
     CHECK_EQUAL(2, DatabaseRecordsNumDb1());
 }
示例#15
0
//__________________________________________________________________________________
void DeleteTreeVariable (long dv, _SimpleList & parms, bool doDeps)
{
    if (dv>=0) {
        _String *name  = (_String*)variableNames.Retrieve (dv);
        _String myName = *name&".";
        long    vidx   = variableNames.GetXtra (dv);

        UpdateChangingFlas (vidx);

        _SimpleList recCache;
        variableNames.Find (name,recCache);
        _String     nextVarID;
        long        nvid;
        if ((nvid = variableNames.Next (dv,recCache))>=0) {
            nextVarID = *(_String*)variableNames.Retrieve(nvid);
        }


        {
            _SimpleList tcache;
            long        iv,
                        k = variableNames.Traverser (tcache, iv, variableNames.GetRoot());

            for (; k>=0; k = variableNames.Traverser (tcache, iv)) {
                _Variable * thisVar = FetchVar(k);

                if (thisVar->CheckFForDependence (vidx,false)) {
                    _PMathObj curValue = thisVar->Compute();
                    curValue->nInstances++;
                    thisVar->SetValue (curValue);
                    DeleteObject (curValue);
                }
            }
        }

        _Variable* delvar = (FetchVar(dv));
        if (delvar->ObjectClass() != TREE) {
            variableNames.Delete (variableNames.Retrieve(dv),true);
            (*((_SimpleList*)&variablePtrs))[vidx]=0;
            freeSlots<<vidx;
            DeleteObject (delvar);
        } else {
            ((_VariableContainer*)delvar)->Clear();
        }
        if (doDeps) {
            _List toDelete;
            recCache.Clear();
            long nextVar = variableNames.Find (&nextVarID,recCache);
            for (; nextVar>=0; nextVar = variableNames.Next (nextVar, recCache)) {
                _String dependent = *(_String*)variableNames.Retrieve (nextVar);
                if (dependent.startswith(myName)) {
                    if (dependent.Find ('.', myName.sLength+1, -1)>=0) {
                        _Variable * checkDep = FetchVar (nextVar);
                        if (!checkDep->IsIndependent()) {
                            _PMathObj curValue = checkDep->Compute();
                            curValue->nInstances++;
                            checkDep->SetValue (curValue);
                            DeleteObject (curValue);
                        }
                        parms << variableNames.GetXtra (nextVar);
                    } else {
                        toDelete && & dependent;
                    }
                } else {
                    break;
                }
            }

            for (long k=0; k<toDelete.lLength; k++) {
                //StringToConsole (*(_String*)toDelete(k));
                //BufferToConsole ("\n");
                DeleteTreeVariable (*(_String*)toDelete(k),parms,false);
            }
        }
    }
}
示例#16
0
void DataInput::start()
{
    QNetworkRequest nr;
    QString url;
    int typeNumber = typeToInt(type);
    switch(typeNumber)
    {
    case 0: {
        url = "http://api.thingm.com/blink1/eventsall/" + iftttKey;
//        url = "http://api.thingm.com/blink1/events/04CE5FA11A002B8E";
        nr.setUrl(QUrl(url));
        reply = networkManager->get(nr);
        connect(reply, SIGNAL(finished()), this, SLOT(onFinished()));
        connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onError()));
    }
        break;

    case 1: {
        url = input->arg1();
        if(!url.startsWith("http://") && !url.startsWith("https://"))
            url="http://"+url;
        QUrl correctUrl(url);
        if(correctUrl.isValid())
        {
            nr.setUrl(QUrl(url));
            reply = networkManager->get(nr);
            connect(reply, SIGNAL(finished()), this, SLOT(onFinished()));
            connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onError()));
        }
        else
        {
            emit setValueRet("NOT FOUND");
            input->setArg2("NOT FOUND");
            input->setDate(-1);
            emit toDelete(this);
        }
    }
        break;

    case 2: {
        QFileInfo fileInfo;
        fileInfo.setFile(input->arg1());
        if(!fileInfo.exists()){
            input->setArg2("NOT FOUND");
            input->setDate(-1);
        }
        if(fileInfo.lastModified().toTime_t() != (uint)input->date()) {
            QFile f(input->arg1());
            if(!f.open(QIODevice::ReadOnly | QIODevice::Text))
            {
                //qDebug() << "File error:";
                //qDebug() << "File not found.";
                emit setValueRet("NOT FOUND");
                input->setArg2("NOT FOUND");
                input->setDate(-1);
                emit toDelete(this);
                return;
            }
            input->setDate(fileInfo.lastModified().toTime_t());
            QString txt = "";
            QTextStream in(&f);
            txt.append(in.readAll());
            int idx=txt.indexOf(QRegExp("#([0-9a-fA-F]{6})"));
            QColor c=QColor("#000000");
            f.close();
            if(idx!=-1)
            {
                c=QColor(txt.mid(idx,7));
                emit setColor(c);
                emit addReceiveEvent(fileInfo.lastModified().toTime_t(), c.name().toUpper(), "FILE");
                input->setArg2(c.name());
            }
            else
            {
                QStringList list;
                list.append("pattern:"); list.append("\"pattern\":");
                QString patternName;
                int index=-1;
                for(int i=0; i<list.count(); i++) {
                    index = txt.indexOf(list.at(i),0);
                    if(index != -1)
                        break;
                }
                if(index != -1) {
                    index = txt.indexOf(":", index);
                    int idx1, idx2;
                    idx1 = txt.indexOf("\"", index);
                    idx2 = txt.indexOf("\"", idx1+1);
                    patternName = txt.mid(idx1+1, idx2-idx1-1);
                    for(int i=0; i<patternList.count(); i++) {
                        if(patternList[i] == patternName) {
                            emit runPattern(patternName, false);
                            emit addReceiveEvent(fileInfo.lastModified().toTime_t(), patternName, "FILE");
                            input->setArg2(patternName);
                            break;
                        }
                    }

                }else{
                    input->setArg2("NO VALUE");
                }
            }
        }
        emit toDelete(this);
    }
        break;

    case 3: {
        process = new QProcess;
        connect(process, SIGNAL(readyReadStandardOutput()), this, SLOT(onProcessOutput()));
        connect(process, SIGNAL(readyReadStandardError()), this, SLOT(onError()));
        connect(process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(onError()));
        connect(process, SIGNAL(finished(int)), this, SLOT(onProcessFinished()));
//        QString path = QStandardPaths::displayName(QStandardPaths::DocumentsLocation);
        QString path = QStandardPaths::locate(QStandardPaths::DocumentsLocation, input->arg1());
        QFile f(path);
        QFileInfo fileInfo;
        fileInfo.setFile(path);
        if(f.exists()){
            if(fileInfo.lastModified().toTime_t() != (uint)input->date()){
                input->setDate(fileInfo.lastModified().toTime_t());
                process->start(path);
            }else{
                emit toDelete(this);
            }
        }else
        {
            //qDebug() << "Script error:";
            //qDebug() << "Script doesn't' exist!";
            emit setValueRet("NOT FOUND");
            input->setArg2("NOT FOUND");
            input->setDate(-1);
            emit toDelete(this);
        }
    }
        break;

    default: {
        emit toDelete(this);
    }
        break;
    }
}
示例#17
0
void Uninstaller::uninstall(ProgressloggerInterface* dp)
{
    m_dp = dp;
    m_dp->setProgressMax(0);
    m_dp->addItem(tr("Starting Uninstallation"),LOGINFO);

    QSettings installlog(m_mountpoint + "/.rockbox/rbutil.log", QSettings::IniFormat, this);

    for(int i=0; i< uninstallSections.size() ; i++)
    {
        m_dp->addItem(tr("Uninstalling %1...").arg(uninstallSections.at(i)), LOGINFO);
        QCoreApplication::processEvents();
        // create list of all other install sections
        QStringList sections = installlog.childGroups();
        sections.removeAt(sections.indexOf(uninstallSections.at(i)));
        installlog.beginGroup(uninstallSections.at(i));
        QStringList toDeleteList = installlog.allKeys();
        QStringList dirList;
        installlog.endGroup();

        // iterate over all entries
        for(int j =0; j < toDeleteList.size(); j++ )
        {
            // check if current file is in use by another section
            bool deleteFile = true;
            for(int s = 0; s < sections.size(); s++)
            {
                installlog.beginGroup(sections.at(s));
                if(installlog.contains(toDeleteList.at(j)))
                {
                    deleteFile = false;
                    qDebug() << "file still in use:" << toDeleteList.at(j);
                }
                installlog.endGroup();
            }

            installlog.beginGroup(uninstallSections.at(i));
            QFileInfo toDelete(m_mountpoint + "/" + toDeleteList.at(j));
            if(toDelete.isFile())  // if it is a file remove it
            {
                if(deleteFile && !QFile::remove(toDelete.filePath()))
                    m_dp->addItem(tr("Could not delete %1")
                          .arg(toDelete.filePath()),LOGWARNING);
                installlog.remove(toDeleteList.at(j));
                qDebug() << "deleted: " << toDelete.filePath() ;
            }
            else  // if it is a dir, remember it for later deletion
            {
                // no need to keep track on folders still in use -- only empty
                // folders will be rm'ed.
                dirList << toDeleteList.at(j);
            }
            installlog.endGroup();
            QCoreApplication::processEvents();
        }
        // delete the dirs
        installlog.beginGroup(uninstallSections.at(i));
        for(int j=0; j < dirList.size(); j++ )
        {
            installlog.remove(dirList.at(j));
            QDir dir(m_mountpoint);
            dir.rmdir(dirList.at(j)); // rm works only on empty folders
        }

        installlog.endGroup();
        //installlog.removeGroup(uninstallSections.at(i))
    }
    uninstallSections.clear();
    installlog.sync();
    m_dp->setProgressMax(1);
    m_dp->setProgressValue(1);
    m_dp->addItem(tr("Uninstallation finished"),LOGOK);
    m_dp->setFinished();
}
示例#18
0
void DataInput::start()
{
    QNetworkRequest nr;
    QString url;
    //qDebug() << "DataInput:start:"<<type<<":"<<input->arg1();

    if( type == "ifttt" ) {
        // url = "http://api.thingm.com/blink1/eventsall/" + iftttKey;
        url = "http://feed.thingm.com/blink1/eventsall/" + iftttKey;
        //url = "http://localhost:3232/blink1/eventsall/" + iftttKey;
        nr.setUrl(QUrl(url));
        reply = networkManager->get(nr);
        connect(reply, SIGNAL(finished()), this, SLOT(onFinished()));
        connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onError()));
    }
    else if( type == "url" ) { 
        url = input->arg1();
        //qDebug() << "datainput:start url: "<<url; 
        if(!url.startsWith("http://") && !url.startsWith("https://"))
            url="http://"+url;
        QUrl correctUrl(url);
        if(correctUrl.isValid()) {
            nr.setUrl(QUrl(url));
            reply = networkManager->get(nr);
            connect(reply, SIGNAL(finished()), this, SLOT(onFinished()));
            connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onError()));
        }
        else {
            input->setArg2("Bad URL");
            input->setDate(-1);  // FIXME: don't like -1 here
            emit toDelete(this);
        }
    }
    else if( type == "file" ) { 
        QFileInfo fileInfo;
        fileInfo.setFile(input->arg1());
        if( !fileInfo.exists() ) {
            qDebug() << "datainput:start: no file";
            input->setArg2("Not Found");
            input->setDate(-1);
        }
        else { 
            int lastModTime = fileInfo.lastModified().toTime_t(); // why was cast to uint?
            if( lastModTime > input->date()) {
                qDebug() << "datainput:start: file newer";
                QFile f(input->arg1());
                if(!f.open(QIODevice::ReadOnly | QIODevice::Text)) {
                    input->setArg2("Couldn't Open");
                    input->setDate(-1);  // FIXME: why -1? what does it mean?
                    emit toDelete(this);
                    return;
                }
                input->setDate( lastModTime); //fileInfo.lastModified().toTime_t());
                QString txt = "";
                QTextStream in(&f);
                txt.append(in.readAll());

                bool good = parsePatternOrColor( txt, type, lastModTime );
                if( !good ) { 
                    input->setArg2("Bad Parse");
                }
            } // last modified
            else { 
                //input->setArg2("Old File");  // FIXME: should do something to indicate older file
                //input->setDate(-1);
            }
        }
        emit toDelete(this);
    }
    else if( type == "script" ) { 
        //QString path = QStandardPaths::locate(QStandardPaths::DocumentsLocation, input->arg1());
        QFileInfo fileInfo;
        fileInfo.setFile( input->arg1() );
        if( !fileInfo.exists() ) {
            input->setArg2("Not Found");
            input->setDate(-1);
            emit toDelete(this);
        } 
        else if( !fileInfo.isExecutable() ) { 
            input->setArg2("Not Executable");
            input->setDate(-1);
            emit toDelete(this);
        }
        else { 
            // FIXME: should check new value compare to lastVal
            // (and FIXME: need to refactor to properly use lastVal for all monitor types)
            //if(fileInfo.lastModified().toTime_t() != (uint)input->date()){
            // no, don't do lastModTime check on exec file, jeez
            input->setDate(fileInfo.lastModified().toTime_t());
            process = new QProcess;
            connect(process, SIGNAL(readyReadStandardOutput()), this, SLOT(onProcessOutput()));
            connect(process, SIGNAL(readyReadStandardError()), this, SLOT(onError()));
            connect(process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(onError()));
            connect(process, SIGNAL(finished(int)), this, SLOT(onProcessFinished()));
            // start process running
            process->start( fileInfo.canonicalFilePath() );
        }
    }
示例#19
0
//__________________________________________________________________________________
void DeleteVariable (long dv, bool deleteself)
{
    if (dv>=0) {

        _String *name  = (_String*)variableNames.Retrieve (dv);
        _String myName = *name&'.';
        long    vidx   = variableNames.GetXtra (dv);

        UpdateChangingFlas (vidx);

        _SimpleList recCache;
        variableNames.Find (name,recCache);
        _String     nextVarID;// = *(_String*)variableNames.Retrieve(variableNames.Next (dv,recCache));
        long        nvid;
        if ((nvid = variableNames.Next (dv,recCache))>=0) {
            nextVarID = *(_String*)variableNames.Retrieve(nvid);
        }

        if (deleteself) {
            _SimpleList tcache;
            long        iv,
                        k = variableNames.Traverser (tcache, iv, variableNames.GetRoot());

            for (; k>=0; k = variableNames.Traverser (tcache, iv)) {
                _Variable * thisVar = FetchVar(k);

                if (thisVar->CheckFForDependence (vidx,false)) {
                    _PMathObj curValue = thisVar->Compute();
                    curValue->nInstances++; // this could be a leak 01/05/2004.
                    thisVar->SetValue (curValue);
                    DeleteObject (curValue);
                }
            }

            _Variable* delvar = (FetchVar(dv));
            DeleteObject (delvar);

            variableNames.Delete (variableNames.Retrieve(dv),true);
            (*((_SimpleList*)&variablePtrs))[vidx]=0;
            freeSlots<<vidx;
        } else {
            _Variable* delvar = (FetchVar(dv));
            if (delvar->IsContainer()) {
                _VariableContainer* dc = (_VariableContainer*)delvar;
                dc->Clear();
            }
        }

        _List       toDelete;

        recCache.Clear();
        long nextVar = variableNames.Find (&nextVarID,recCache);

        for (; nextVar>=0; nextVar = variableNames.Next (nextVar, recCache)) {
            _String dependent = *(_String*)variableNames.Retrieve (nextVar);
            if (dependent.startswith(myName)) {
                toDelete && & dependent;
            } else {
                break;
            }
        }

        for (long k=0; k< toDelete.lLength; k++) {
            DeleteVariable (*(_String*)toDelete(k));
        }
    }
}
示例#20
0
void DataInput::onFinished()
{
    int date;
    QString txt;

    int typeNumber = typeToInt(type);
    switch(typeNumber)
    {
    case 0: {
        txt = reply->readAll();
        QString dateString = "";
        if(input->type().toUpper() == "IFTTT.COM") {

            if(responseTo==NULL) emit iftttToCheck(txt); else emit iftttToCheck(txt,input);
        }
    }
        break;

    case 1: {
        QDateTime dt = reply->header(QNetworkRequest::LastModifiedHeader).toDateTime();
        date = dt.toTime_t();
        if(date != -1) {
            if(input->date() != date) {
                input->setDate(date);

                txt = reply->readAll();
                int idx=txt.indexOf(QRegExp("#([0-9a-fA-F]{6})"));
                QColor c=QColor("#000000");
                if(idx!=-1)
                {
                    c=QColor(txt.mid(idx,7));
                    emit setColor(c);
                    emit addReceiveEvent(date, c.name().toUpper(), "URL");
                    input->setArg2(c.name());
                }
                else
                {
                    QStringList list;
                    list.append("pattern:"); list.append("\"pattern\":");
                    QString patternName;
                    int index=-1;
                    for(int i=0; i<list.count(); i++) {
                        index = txt.indexOf(list.at(i),0);
                        if(index != -1)
                            break;
                    }

                    if(index != -1) {
                        index = txt.indexOf(":", index);
                        int idx1, idx2;
                        idx1 = txt.indexOf("\"", index);
                        idx2 = txt.indexOf("\"", idx1+1);
                        patternName = txt.mid(idx1+1, idx2-idx1-1);

                        for(int i=0; i<patternList.count(); i++)
                        {
                            if(patternName == patternList[i]) {
                                emit runPattern(patternName, false);
                                emit addReceiveEvent(date, patternName, "URL");
                                input->setArg2(patternName);
                                break;
                            }
                        }
                    }else{
                        input->setArg2("NO VALUE");
                    }
                }
            }
        }else{
            input->setArg2("NO VALUE");
        }
    }
        break;
    }
    delete reply;
    emit toDelete(this);
}
示例#21
0
void DataInput::startQml()
{
    QNetworkRequest nr;
    QString url;
    int typeNumber = typeToInt(type);
    switch(typeNumber)
    {
    case 0: {
        url = "http://api.thingm.com/blink1/events/" + iftttKey;
//        url = "http://api.thingm.com/blink1/events/04CE5FA11A002B8E";
        nr.setUrl(QUrl(url));
        reply = networkManager->get(nr);
        connect(reply, SIGNAL(finished()), this, SLOT(onFinishedQml()));
        connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onError()));
    }
        break;

    case 1: {
        url = rule;
        QUrl correctUrl(url);
        if(correctUrl.isValid())
        {
            nr.setUrl(QUrl(url));
            reply = networkManager->get(nr);
            connect(reply, SIGNAL(finished()), this, SLOT(onFinishedQml()));
            connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onError()));
        }
        else
        {
            emit setValueRet("NOT FOUND");
            emit toDelete(this);
        }
    }
        break;

    case 2: {
        QFile f(rule);
        if(!f.open(QIODevice::ReadOnly | QIODevice::Text))
        {
            //qDebug() << "File error:";
            //qDebug() << "File not found.";
            emit setValueRet("NOT FOUND");
            emit toDelete(this);
            return;
        }
        QString txt = "";
        QTextStream in(&f);
        txt.append(in.readAll());
        int idx=txt.indexOf(QRegExp("#([0-9a-fA-F]{6})"));
        QColor c=QColor("#000000");
        f.close();
        if(idx!=-1)
        {
            c=QColor(txt.mid(idx,7));
            emit setColor(c);
            emit setValueRet(c.name().toUpper());
        }
        else
        {
            emit setColor(c);
            emit setValueRet("NO VALUE");

        }
        emit toDelete(this);
    }
        break;

    case 3: {
        process = new QProcess;
        connect(process, SIGNAL(readyReadStandardOutput()), this, SLOT(onProcessOutput()));
        connect(process, SIGNAL(readyReadStandardError()), this, SLOT(onError()));
        connect(process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(onError()));
        connect(process, SIGNAL(finished(int)), this, SLOT(onProcessFinishedQml()));
        QString path = QStandardPaths::locate(QStandardPaths::DocumentsLocation, rule);
        QFile f(path);
        if(f.exists())
            process->start(path);
        else
        {
            //qDebug() << "Script error:";
            //qDebug() << "Script doesn't' exist!";
            emit setValueRet("NOT FOUND");
            emit toDelete(this);
        }
    }
        break;

    default: {
        emit toDelete(this);
    }
        break;
    }
}