Home · All Classes · Main Classes · Deprecated

mextensionwatcher.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002 **
00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
00004 ** All rights reserved.
00005 ** Contact: Nokia Corporation (directui@nokia.com)
00006 **
00007 ** This file is part of libmeegotouch.
00008 **
00009 ** If you have questions regarding the use of this file, please contact
00010 ** Nokia at directui@nokia.com.
00011 **
00012 ** This library is free software; you can redistribute it and/or
00013 ** modify it under the terms of the GNU Lesser General Public
00014 ** License version 2.1 as published by the Free Software Foundation
00015 ** and appearing in the file LICENSE.LGPL included in the packaging
00016 ** of this file.
00017 **
00018 ****************************************************************************/
00019 
00020 #include "mextensionwatcher.h"
00021 #include "mdesktopentry.h"
00022 #include "mapplicationextensionmetadata.h"
00023 #include <QFile>
00024 #include <QStringList>
00025 
00026 
00027 MExtensionWatcher::MExtensionWatcher()
00028 {
00029     connect(&watcher, SIGNAL(fileChanged(const QString &)), this, SLOT(notifyDataChanged(const QString &)));
00030 }
00031 
00032 MExtensionWatcher::~MExtensionWatcher()
00033 {
00034 }
00035 
00036 void MExtensionWatcher::addExtension(
00037     QSharedPointer<const MDesktopEntry> extension)
00038 {
00039     QString fileName = extension->fileName();
00040     if (!extensionsToWatch.contains(fileName)) {
00041         extensionsToWatch.insert(fileName, extension);
00042         watcher.addPath(fileName);
00043     }
00044 }
00045 
00046 void MExtensionWatcher::removeExtension(const QString &fileName)
00047 {
00048     extensionsToWatch.remove(fileName);
00049 }
00050 
00051 void MExtensionWatcher::notifyDataChanged(const QString &path) const
00052 {
00053     // If the file does not exist anymore no need to signal an update for it
00054     // observation of the file removal is handled by the instance managers
00055     if (!QFile::exists(path)) {
00056         return;
00057     }
00058     QHash<QString, QSharedPointer<const MDesktopEntry> >::const_iterator
00059         extension =  extensionsToWatch.find(path);
00060     if (extension != extensionsToWatch.constEnd()) {
00061         emit extensionChanged(*extension.value());
00062     }
00063     if (!watcher.files().contains(path)) {
00064         // if the file is removed and recreated, we need to re-add
00065         // the path to the watcher
00066         watcher.addPath(path);
00067     }
00068 }

Copyright © 2010 Nokia Corporation Generated on Thu Nov 4 2010 18:14:20 (PDT)
Doxygen 1.7.1
MeeGo Touch