From f7a4fceb3c0c07e5286b6ae58853ea1c705c0728 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Thu, 19 May 2011 16:18:39 +0200 Subject: [PATCH] Maemo: Fix package file watching. 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 --- .../qt4projectmanager/qt-maemo/maemoglobal.h | 27 ++++++++++++++++++++ .../qt4projectmanager/qt-maemo/qt4maemotarget.cpp | 29 +++++++++------------- .../qt4projectmanager/qt-maemo/qt4maemotarget.h | 7 +++++- 3 files changed, 45 insertions(+), 18 deletions(-) diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemoglobal.h b/src/plugins/qt4projectmanager/qt-maemo/maemoglobal.h index 0dee759671..260a5851a7 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemoglobal.h +++ b/src/plugins/qt4projectmanager/qt-maemo/maemoglobal.h @@ -35,6 +35,7 @@ #include "maemodeviceconfigurations.h" +#include #include #include @@ -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) diff --git a/src/plugins/qt4projectmanager/qt-maemo/qt4maemotarget.cpp b/src/plugins/qt4projectmanager/qt-maemo/qt4maemotarget.cpp index a711a51e26..20de82fc70 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/qt4maemotarget.cpp +++ b/src/plugins/qt4projectmanager/qt-maemo/qt4maemotarget.cpp @@ -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() + << 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 diff --git a/src/plugins/qt4projectmanager/qt-maemo/qt4maemotarget.h b/src/plugins/qt4projectmanager/qt-maemo/qt4maemotarget.h index a640e68cd5..81dd1ea010 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/qt4maemotarget.h +++ b/src/plugins/qt4projectmanager/qt-maemo/qt4maemotarget.h @@ -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; }; -- 2.11.0