OSDN Git Service

Maemo: Fix package file watching.
authorChristian Kandeler <christian.kandeler@nokia.com>
Thu, 19 May 2011 14:18:39 +0000 (16:18 +0200)
committerDaniel Teske <daniel.teske@nokia.com>
Thu, 19 May 2011 14:39:55 +0000 (16:39 +0200)
Had been broken by 45c9cf7a1298feed925d18596c30ac9c6cd1dac5 ff.
This change uses the FileManager and thereby also improves interaction
with external editors that change the inode (e.g. emacs).

Change-Id: I6d889d435931eb0199de93610bea643e50e9f025
Reviewed-on: http://codereview.qt.nokia.com/24
Reviewed-by: Daniel Teske <daniel.teske@nokia.com>
src/plugins/qt4projectmanager/qt-maemo/maemoglobal.h
src/plugins/qt4projectmanager/qt-maemo/qt4maemotarget.cpp
src/plugins/qt4projectmanager/qt-maemo/qt4maemotarget.h

index 0dee759..260a585 100644 (file)
@@ -35,6 +35,7 @@
 
 #include "maemodeviceconfigurations.h"
 
+#include <coreplugin/ifile.h>
 #include <utils/environment.h>
 
 #include <projectexplorer/buildstep.h>
@@ -59,6 +60,32 @@ namespace Qt4ProjectManager {
 class BaseQtVersion;
 namespace Internal {
 
+class WatchableFile : public Core::IFile
+{
+    Q_OBJECT
+public:
+    WatchableFile(const QString &fileName, QObject *parent = 0)
+        : Core::IFile(parent), m_fileName(fileName) {}
+
+    bool save(QString *, const QString &, bool) { return false; }
+    QString fileName() const { return m_fileName; }
+    QString defaultPath() const { return QString(); }
+    QString suggestedFileName() const { return QString(); }
+    QString mimeType() const { return QLatin1String("text/plain"); }
+    bool isModified() const { return false; }
+    bool isReadOnly() const { return false; }
+    bool isSaveAsAllowed() const { return false; }
+    ReloadBehavior reloadBehavior(ChangeTrigger, ChangeType) const { return BehaviorSilent; }
+    bool reload(QString *, ReloadFlag, ChangeType) { emit modified(); return true; }
+    void rename(const QString &) {}
+
+signals:
+    void modified();
+
+private:
+    QString m_fileName;
+};
+
 class MaemoGlobal
 {
     Q_DECLARE_TR_FUNCTIONS(Qt4ProjectManager::Internal::MaemoGlobal)
index a711a51..20de82f 100644 (file)
@@ -662,15 +662,17 @@ void AbstractDebBasedQt4MaemoTarget::handleTargetAddedSpecial()
             setPackageManagerIcon(iconPath);
     }
     m_filesWatcher->addDirectory(debianDirPath(), Utils::FileSystemWatcher::WatchAllChanges);
-    m_filesWatcher->addFile(changeLogFilePath(), Utils::FileSystemWatcher::WatchAllChanges);
-    m_filesWatcher->addFile(controlFilePath(), Utils::FileSystemWatcher::WatchAllChanges);
+    m_controlFile = new WatchableFile(controlFilePath(), this);
+    connect(m_controlFile, SIGNAL(modified()), SIGNAL(controlChanged()));
+    m_changeLogFile = new WatchableFile(changeLogFilePath(), this);
+    connect(m_changeLogFile, SIGNAL(modified()), SIGNAL(changeLogChanged()));
+    Core::FileManager::instance()->addFiles(QList<Core::IFile *>()
+        << m_controlFile << m_changeLogFile);
     connect(m_filesWatcher, SIGNAL(directoryChanged(QString)), this,
         SLOT(handleDebianDirContentsChanged()));
-    connect(m_filesWatcher, SIGNAL(fileChanged(QString)), this,
-        SLOT(handleDebianFileChanged(QString)));
     handleDebianDirContentsChanged();
-    handleDebianFileChanged(changeLogFilePath());
-    handleDebianFileChanged(controlFilePath());
+    emit controlChanged();
+    emit changeLogChanged();
 }
 
 bool AbstractDebBasedQt4MaemoTarget::targetCanBeRemoved() const
@@ -685,14 +687,6 @@ void AbstractDebBasedQt4MaemoTarget::removeTarget()
         qDebug("%s", qPrintable(error));
 }
 
-void AbstractDebBasedQt4MaemoTarget::handleDebianFileChanged(const QString &filePath)
-{
-    if (filePath == changeLogFilePath())
-        emit changeLogChanged();
-    else if (filePath == controlFilePath())
-        emit controlChanged();
-}
-
 void AbstractDebBasedQt4MaemoTarget::handleDebianDirContentsChanged()
 {
     emit debianDirContentsChanged();
@@ -985,9 +979,10 @@ AbstractQt4MaemoTarget::ActionStatus AbstractRpmBasedQt4MaemoTarget::createSpeci
 
 void AbstractRpmBasedQt4MaemoTarget::handleTargetAddedSpecial()
 {
-    m_filesWatcher->addFile(specFilePath(), Utils::FileSystemWatcher::WatchAllChanges);
-    connect(m_filesWatcher, SIGNAL(fileChanged(QString)), this,
-        SIGNAL(specFileChanged()));
+    m_specFile = new WatchableFile(specFilePath(), this);
+    connect(m_specFile, SIGNAL(modified()), SIGNAL(specFileChanged()));
+    Core::FileManager::instance()->addFile(m_specFile);
+    emit specFileChanged();
 }
 
 bool AbstractRpmBasedQt4MaemoTarget::targetCanBeRemoved() const
index a640e68..81dd1ea 100644 (file)
@@ -48,6 +48,7 @@ namespace Qt4ProjectManager {
 class Qt4Project;
 namespace Internal {
 class Qt4MaemoDeployConfigurationFactory;
+class WatchableFile;
 
 class AbstractQt4MaemoTarget : public Qt4BaseTarget
 {
@@ -141,7 +142,6 @@ protected:
 
 private slots:
     void handleDebianDirContentsChanged();
-    void handleDebianFileChanged(const QString &filePath);
 
 private:
     virtual bool setProjectVersionInternal(const QString &version,
@@ -172,6 +172,9 @@ private:
         QString *error = 0);
     QString defaultPackageFileName() const;
     bool setPackageManagerNameInternal(const QString &name, QString *error = 0);
+
+    WatchableFile *m_controlFile;
+    WatchableFile *m_changeLogFile;
 };
 
 
@@ -213,6 +216,8 @@ private:
     QByteArray getValueForTag(const QByteArray &tag, QString *error) const;
     bool setValueForTag(const QByteArray &tag, const QByteArray &value,
         QString *error);
+
+    WatchableFile *m_specFile;
 };