Esempio n. 1
0
void DatabaseFileWatcher::restartDirMonitoring(const QString &previousDirPath)
{
    if (m_watcher->files().contains(m_databasePath))
        return;

    QString existing = closestExistingParent(m_databasePath);
    if (existing.isEmpty()) {
        qWarning() << "QServiceManager: can't find existing directory for path to database" << m_databasePath
            << "serviceAdded() and serviceRemoved() will not be emitted";
        return;
    }
    if (existing == m_databasePath) {
            if (!previousDirPath.isEmpty())
                m_watcher->removePath(previousDirPath);

            setEnabled(true);
    } else {
        if (previousDirPath != existing) {
            if (!previousDirPath.isEmpty())
                m_watcher->removePath(previousDirPath);
            if (!m_watcher->directories().contains(existing))
                m_watcher->addPath(existing);
        }
    }
}
Esempio n. 2
0
QString DatabaseFileWatcher::closestExistingParent(const QString &path)
{
    if (QFile::exists(path))
        return path;

    int lastSep = path.lastIndexOf(QDir::separator());
    if (lastSep < 0)
        return QString();
    return closestExistingParent(path.mid(0, lastSep));
}
Esempio n. 3
0
void DatabaseFileWatcher::restartDirMonitoring(const QString &dbPath, const QString &previousDirPath)
{
    if (m_watcher->files().contains(dbPath))
        return;

    QString existing = closestExistingParent(dbPath);
    if (existing.isEmpty()) {
        qWarning() << "QServiceManager: can't find existing directory for path to database" << dbPath
            << "serviceAdded() and serviceRemoved() will not be emitted";
        return;
    }
    if (existing == dbPath) {
        ServiceDatabase *db = 0;
        DatabaseManager::DbScope scope;
        if (m_manager->m_userDb && dbPath == m_manager->m_userDb->databasePath()) {
            db = m_manager->m_userDb;
            scope = DatabaseManager::UserOnlyScope;
        } else if (dbPath == m_manager->m_systemDb->databasePath()) {
            db = m_manager->m_systemDb;
            scope = DatabaseManager::SystemScope;
        }

        if (db) {
            if (!previousDirPath.isEmpty())
                m_watcher->removePath(previousDirPath);
            QMutableListIterator<QString> i(m_monitoredDbPaths);
            while (i.hasNext()) {
                if (i.next() == dbPath)
                    i.remove();
            }

            QStringList newServices = m_manager->getServiceNames(QString(), scope);
            for (int i=0; i<newServices.count(); i++)
                emit m_manager->serviceAdded(newServices[i], scope);
            setEnabled(db, true);
        }
    } else {
        if (previousDirPath != existing) {
            if (!previousDirPath.isEmpty())
                m_watcher->removePath(previousDirPath);
            if (!m_watcher->directories().contains(existing))
                m_watcher->addPath(existing);
            if (!m_monitoredDbPaths.contains(dbPath))
                m_monitoredDbPaths << dbPath;
        }
    }
}