Ejemplo n.º 1
0
void DatabaseFileWatcher::databaseDirectoryChanged(const QString &path)
{
    for (int i=0; i<m_monitoredDbPaths.count(); i++) {
        if (m_monitoredDbPaths[i].contains(path))
            restartDirMonitoring(m_monitoredDbPaths[i], path);
    }
}
Ejemplo n.º 2
0
void DatabaseFileWatcher::databaseChanged(const QString &path)
{
    if (!QFile::exists(m_databasePath)) {
        restartDirMonitoring(QString());;
    }

    emit notifyChange();
    // if database was deleted, the path may have been dropped
    if (!m_watcher->files().contains(path) && QFile::exists(path))
        m_watcher->addPath(path);
}
Ejemplo n.º 3
0
void DatabaseFileWatcher::notifyChanges(ServiceDatabase *database, DatabaseManager::DbScope scope)
{
    #ifdef Q_OS_SYMBIAN
        scope = DatabaseManager::SystemScope;
    #endif

    QString dbPath = database->databasePath();
    if (!QFile::exists(dbPath)) {
        m_knownServices.remove(dbPath);
        restartDirMonitoring(dbPath, QString());
        return;
    }

    QStringList currentServices = database->getServiceNames(QString());
    if (database->lastError().code() !=DBError::NoError) {
        qWarning("QServiceManager: failed to get current service names for serviceAdded() and serviceRemoved() signals");
        return;
    }

    const QStringList &knownServicesRef = m_knownServices[dbPath];

    QSet<QString> currentServicesSet = currentServices.toSet();
    QSet<QString> knownServicesSet = knownServicesRef.toSet();
    if (currentServicesSet == knownServicesSet)
        return;

    QStringList newServices;
    for (int i=0; i<currentServices.count(); i++) {
        if (!knownServicesSet.contains(currentServices[i]))
            newServices << currentServices[i];
    }

    QStringList removedServices;
    for (int i=0; i<knownServicesRef.count(); i++) {
        if (!currentServicesSet.contains(knownServicesRef[i]))
            removedServices << knownServicesRef[i];
    }

    m_knownServices[dbPath] = currentServices;
    for (int i=0; i<newServices.count(); i++)
        emit m_manager->serviceAdded(newServices[i], scope);
    for (int i=0; i<removedServices.count(); i++)
        emit m_manager->serviceRemoved(removedServices[i], scope);
}
Ejemplo n.º 4
0
void DatabaseFileWatcher::setEnabled(bool enabled)
{
    if (!m_watcher) {
        m_watcher = new QFileSystemWatcher(this);
        connect(m_watcher, SIGNAL(fileChanged(QString)),
            SLOT(databaseChanged(QString)));
        connect(m_watcher, SIGNAL(directoryChanged(QString)),
            SLOT(databaseDirectoryChanged(QString)));
    }

    if (enabled) {
        if (QFile::exists(m_databasePath)) {
            if (!m_watcher->files().contains(m_databasePath))
                    m_watcher->addPath(m_databasePath);
        } else {
            restartDirMonitoring(QString());
        }
    } else {
        m_watcher->removePath(m_databasePath);
    }
}
Ejemplo n.º 5
0
void DatabaseFileWatcher::setEnabled(ServiceDatabase *database, bool enabled)
{
    if (!m_watcher) {
        m_watcher = new QFileSystemWatcher(this);
        connect(m_watcher, SIGNAL(fileChanged(QString)),
            SLOT(databaseChanged(QString)));
        connect(m_watcher, SIGNAL(directoryChanged(QString)),
            SLOT(databaseDirectoryChanged(QString)));
    }

    QString path = database->databasePath();
    if (enabled) {
        if (QFile::exists(path)) {
            m_knownServices[path] = database->getServiceNames(QString());
            m_watcher->addPath(path);
        } else {
            restartDirMonitoring(path, QString());
        }
    } else {
        m_watcher->removePath(path);
        m_knownServices.remove(path);
    }
}
Ejemplo n.º 6
0
void DatabaseFileWatcher::databaseDirectoryChanged(const QString &path)
{
    if (m_databasePath.contains(path)) {
        restartDirMonitoring(path);
    }
}