Exemple #1
0
DQmlLocalServer::DQmlLocalServer(QQmlEngine *engine, QQuickView *view, const QString &file)
    : DQmlServer(engine, view, file)
{
    connect(&m_tracker, SIGNAL(fileAdded(QString,QString,QString)), this, SLOT(reloadQml()));
    connect(&m_tracker, SIGNAL(fileRemoved(QString,QString,QString)), this, SLOT(reloadQml()));
    connect(&m_tracker, SIGNAL(fileChanged(QString,QString,QString)), this, SLOT(reloadQml()));
}
Exemple #2
0
/**
  * Creates a new instance of watcher thread. The watcher is not started but keeps the references
  * to the directory to be watched, and the associated filter. The lastPass member is used to
  * detect modification/creation of files between two passes.
  */
Watcher::Watcher(QString url, bool recursive, Filter *filterP) : QThread(), m_watchSem(1) {
    m_url = url;
    m_recursive = recursive;
    m_filterP = filterP;
    m_lastPass = QDateTime::currentDateTime();

    // connect the activity signals/slots
    connect(this, SIGNAL(displayActivity(QString)), filterP, SIGNAL(displayActivity(QString)));
    connect(this, SIGNAL(displayProgress(int,int,int)), filterP, SIGNAL(displayProgress(int,int,int)));

    // connect the scan results signals/slots
    connect(this, SIGNAL(fileAdded(QString)), filterP, SLOT(fileAdded(QString)));
    connect(this, SIGNAL(fileDeleted(QString)), filterP, SLOT(fileDeleted(QString)));
    connect(this, SIGNAL(fileModified(QString)), filterP, SLOT(fileModified(QString)));
    connect(this, SIGNAL(directoryAdded(QString)), filterP, SLOT(directoryAdded(QString)));
    connect(this, SIGNAL(directoryDeleted(QString)), filterP, SLOT(directoryDeleted(QString)));
    connect(this, SIGNAL(directoryModified(QString)), filterP, SLOT(directoryModified(QString)));
}
Exemple #3
0
bool TrashImpl::copyToTrash( const TQString& origPath, int trashId, const TQString& fileId )
{
    kdDebug() << k_funcinfo << endl;
    const TQString dest = filesPath( trashId, fileId );
    if ( !copy( origPath, dest ) )
        return false;
    fileAdded();
    return true;
}
Exemple #4
0
void DQmlFileTracker::onDirChange(const QString &path)
{
    qCDebug(DQML_LOG) << "change in directory" << path;
    QString id = idFromPath(path);
    if (id.isEmpty()) {
        untrack(id);
        qCDebug(DQML_LOG) << " - no entry, cancel tracking...";
        return;
    }

    Entry &entry = m_set[id];
    QDir dir(path);
    QDirIterator iterator(dir);
    QHash<QString, quint64> currentContent;
    while (iterator.hasNext()) {
        iterator.next();
        QFileInfo i = iterator.fileInfo();
        if (i.isFile() && m_suffixes.contains(i.suffix().toLower())) {
            QString name = i.fileName();
            quint64 time = i.lastModified().toMSecsSinceEpoch();
            currentContent[name] = time;
        }
    }

    QSet<QString> allPaths = QSet<QString>::fromList(currentContent.keys()).unite(QSet<QString>::fromList(entry.content.keys()));
    foreach (QString p, allPaths) {
        bool was = entry.content.contains(p);
        bool is = currentContent.contains(p);
        if (was && is) {
            // If file was there before and is still there, check match the last modified
            // timestamp and emit fileChange if it has been modified..
            if (currentContent.value(p) > entry.content.value(p)) {
                qCDebug(DQML_LOG) << " - changed:" << id << p;
                emit fileChanged(id, path, p);
            }
        } else if (is) {
            // File is there now, but wasn't before -> added..
            qCDebug(DQML_LOG) << " - added:" << id << p;
#ifdef Q_OS_LINUX
            m_watcher.addPath(QFileInfo(path + QStringLiteral("/") + p).canonicalFilePath());
#endif
            emit fileAdded(id, path, p);
        } else if (was) {
            // file was there, but isn't anymore -> removed
            qCDebug(DQML_LOG) << " - removed:" << id << p;
#ifdef Q_OS_LINUX
            // Need to use absoluteFilePath here as the file is gone and
            // canonicalFilePath() will return a null string.
            m_watcher.removePath(QFileInfo(path + QStringLiteral("/") + p).absoluteFilePath());
#endif
            emit fileRemoved(id, path, p);
        }
    }
Exemple #5
0
bool TrashImpl::moveToTrash( const TQString& origPath, int trashId, const TQString& fileId )
{
    kdDebug() << k_funcinfo << endl;
    const TQString dest = filesPath( trashId, fileId );
    if ( !move( origPath, dest ) ) {
        // Maybe the move failed due to no permissions to delete source.
        // In that case, delete dest to keep things consistent, since TDEIO doesn't do it.
        if ( TQFileInfo( dest ).isFile() )
            TQFile::remove( dest );
        else
            synchronousDel( dest, false, true );
        return false;
    }
    fileAdded();
    return true;
}
Exemple #6
0
//////////////////////////////////////////////////////////////////////////
/// Add a FileSystemWatcher to the directory
/// 
/// Creates a FileSystemWatcher, connects all the signals, adds it to the
/// list of watchers and starts it.
//////////////////////////////////////////////////////////////////////////
void SyncSystem::slotStartNodeWatching(const QString& dir)
{
  QString watchDir = joinPath(m_CurrentSourcePath, dir);
  qDebug() << "[SyncSystem.Debug] slotStartNodeWatching in dir " << watchDir;

  FileSystemWatcher* watcher = new FileSystemWatcher();
  connect(watcher, SIGNAL(fileAdded(QString)), SLOT(slotFileAdded(QString)));
  connect(watcher, SIGNAL(fileDeleted(QString)), SLOT(slotFileDeleted(QString)));
  connect(watcher, SIGNAL(fileChanged(QString)), SLOT(slotFileChanged(QString)));
  connect(watcher, SIGNAL(fileRenamed(QString,QString)), SLOT(slotFileRenamed(QString,QString)));
  connect(watcher, SIGNAL(filewatchError(QString)), SLOT(slotFilewatchError(QString)));
  connect(watcher, SIGNAL(filewatchLostSync(QString)), SLOT(slotLostSync()));
  m_FileSystemWatchers.append(watcher);
  watcher->setWatchDir(watchDir);
  watcher->setRelativeDir(dir);
  watcher->start();
}
Exemple #7
0
/**
  * Watches the given directory. Detects the new directories but delegates their initial inspection
  * to the getSubDirectories method. The latter will recursively list all of their sub directories.
  */
void Watcher::watchDirectory(QString directory) {
    if (m_stop)
        return;

    // now watch all contained files
    QDirExt rootDir(directory);

    // get the directory entries
    QStringList entries = rootDir.entryList();

#ifdef _VERBOSE_WATCHER
    qDebug() << "Watching into " << directory;
#endif

    // has the directory been removed?
    // if so, just return, the removal signal will be sent later on.
    QFileInfoExt entryInfo(directory);
    if (!entryInfo.exists())
        return;

    // has the directory changed since last pass?
    if (entryInfo.lastModified() >= m_lastPass) {
#ifdef _VERBOSE_WATCHER
        qDebug() << "Detected modified directory " << directory;
#endif
        // signal
        directoryModified(directory);
    }

    // walk through the list
    int numNewDirs = 0;
    for (QList<QString>::iterator i = entries.begin(); !m_stop && numNewDirs < NEW_DIRS_PER_PASS && i != entries.end(); i++) {
        QString entryPath = directory;
        entryPath.append(QDirExt::separator(directory));
        entryPath.append(*i);
        QFileInfoExt entryInfo(entryPath);

        if (entryInfo.isHidden())
            continue; // we don't care about these ones.

        if (!entryInfo.isDir()) {
            // a regular file found

            // is it new?
            if (!m_files.findPath(entryPath) && m_numWatchedFiles < MAX_WATCHED_FILES) {
                m_newFiles.addPath(entryPath);
                ++m_numWatchedFiles;

#ifdef _VERBOSE_PATH
            m_newFiles.dump("file added, dumping new files");
#endif

#ifdef _VERBOSE_WATCHER
            qDebug() << "Detected new file " << entryPath;
#endif
                // signal new file
                fileAdded(entryInfo.absoluteFilePath());
            } else if (entryInfo.lastModified() >= m_lastPass) {
#ifdef _VERBOSE_WATCHER
                qDebug() << "Detected modified file " << entryPath;
#endif
                // signal modified file
                fileModified(entryInfo.absoluteFilePath());
            }
        } else {
            // if the directory is not in the list, and doing a recursive watch, browse it.
            if (m_recursive && !m_files.findPath(entryPath)) {
                // go through new dir's content
                displayProgress(0, 0, 0); // back and forth moving progress
                getNewSubDirectories(entryPath);
#ifdef _VERBOSE_PATH
                m_newFiles.dump("new directory browsed, dumping new files");
#endif
                ++numNewDirs;
            }
        }
    }
}
Exemple #8
0
  bool TableView::addFile(const QString& alias, openstudio::SqlFile sqlFile)
  {
    if (alias.isEmpty() || !sqlFile.connectionOpen()) return false;

    setSortingEnabled(false);

    detail::DataDictionaryTable ddTable = sqlFile.dataDictionary();

    detail::DataDictionaryTable::iterator iter;
    for (iter=ddTable.begin();iter!=ddTable.end();++iter)
    {
      // skip runPeriod
      if (sqlFile.reportingFrequencyFromDB((*iter).reportingFrequency)
          && *(sqlFile.reportingFrequencyFromDB((*iter).reportingFrequency)) != ReportingFrequency::RunPeriod)
      {

        int row = addRow();
        item(row, m_slHeaders.indexOf("Alias"))->setText(alias);
        item(row, m_slHeaders.indexOf("File"))->setText(openstudio::toQString(sqlFile.energyPlusSqliteFile()));
        item(row, m_slHeaders.indexOf("Environment Period"))->setText(openstudio::toQString((*iter).envPeriod));
        item(row, m_slHeaders.indexOf("Reporting Frequency"))->setText(openstudio::toQString((*iter).reportingFrequency));
        item(row, m_slHeaders.indexOf("Key Value"))->setText(openstudio::toQString((*iter).keyValue));
        item(row, m_slHeaders.indexOf("Variable Name"))->setText(openstudio::toQString((*iter).name));
        item(row, m_slHeaders.indexOf("File"))->setData(Qt::UserRole, RVD_TIMESERIES);
      } // end skip runPeriod
    }

    /* illuminance maps */
    std::vector<std::string> mapNames(sqlFile.illuminanceMapNames());
    std::vector<std::string>::iterator nameIter;
    for (nameIter=mapNames.begin(); nameIter!=mapNames.end(); ++nameIter)
    {
      // retrieve mapIndex for map name to retrieve environment period and zone name
      QString envPeriod = "";
      QString keyValue = "";
      boost::optional<int> mapIndex = sqlFile.illuminanceMapIndex(*nameIter);
      if (mapIndex)
      {
        boost::optional<std::string> strValue;
        boost::optional<int> intValue;
        std::stringstream s;
        s << "select Environment from daylightmaps where MapNumber=" << *mapIndex;
        strValue = sqlFile.execAndReturnFirstString(s.str());
        if (strValue) envPeriod = openstudio::toQString(*strValue);
        s.str("");
        s << "select Zone from daylightmaps where MapNumber=" << *mapIndex;
        intValue = sqlFile.execAndReturnFirstInt(s.str());
        if (intValue)
        {
          s.str("");
          s << "select ZoneName from zones where ZoneIndex=" << *intValue;
          strValue = sqlFile.execAndReturnFirstString(s.str());
          if (strValue) keyValue = openstudio::toQString(*strValue);
        }
      }
      int row = addRow();
      item(row, m_slHeaders.indexOf("Alias"))->setText(alias);
      item(row, m_slHeaders.indexOf("File"))->setText(openstudio::toQString(sqlFile.energyPlusSqliteFile()));
      item(row,  m_slHeaders.indexOf("Environment Period"))->setText(envPeriod); // environment period
      /* update based on email from Dan 8/10/10
         item(row, 3)->setText("Illuminance"); // reporting frequency
         item(row, 4)->setText(keyValue); // illuminance zone?
         item(row, 5)->setText(openstudio::toQString(*nameIter));
         */
      item(row, m_slHeaders.indexOf("Reporting Frequency"))->setText("Hourly"); // reporting frequency
      item(row, m_slHeaders.indexOf("Key Value"))->setText(keyValue); // illuminance zone
      item(row, m_slHeaders.indexOf("Variable Name"))->setText("Illuminance Map"); // Variable Name
      item(row, m_slHeaders.indexOf("File"))->setData(Qt::UserRole, RVD_ILLUMINANCEMAP);
      item(row, m_slHeaders.indexOf("Alias"))->setData(Qt::UserRole, openstudio::toQString(*nameIter)); // map name for retrieving from database
    }

    resizeColumnToContents(m_slHeaders.indexOf("Alias"));
    hideColumn(m_slHeaders.indexOf("File"));
    resizeColumnToContents(m_slHeaders.indexOf("Variable Name"));
    resizeColumnToContents(m_slHeaders.indexOf("Key Value"));
    resizeColumnToContents(m_slHeaders.indexOf("Reporting Frequency"));
    //  resizeColumnToContents(5);

    setSortingEnabled(true);

    emit( fileAdded() );

    return true;
  }