From 543e27a1daa1f40fabc09a599ce18e78be69678b Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 12 Feb 2009 11:48:43 +0000 Subject: [PATCH] Changed PreMods() and postMods() functions into signals in notifyqt so that these functions do not cause a data race when called from a callback in libretroshare. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1038 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- retroshare-gui/src/gui/SharedFilesDialog.cpp | 12 +-- retroshare-gui/src/gui/SharedFilesDialog.h | 7 +- retroshare-gui/src/main.cpp | 2 + retroshare-gui/src/rsiface/notifyqt.cpp | 53 +---------- retroshare-gui/src/rsiface/notifyqt.h | 97 ++++++++++---------- 5 files changed, 64 insertions(+), 107 deletions(-) diff --git a/retroshare-gui/src/gui/SharedFilesDialog.cpp b/retroshare-gui/src/gui/SharedFilesDialog.cpp index b734442ed..603ac9436 100644 --- a/retroshare-gui/src/gui/SharedFilesDialog.cpp +++ b/retroshare-gui/src/gui/SharedFilesDialog.cpp @@ -359,27 +359,21 @@ void SharedFilesDialog::openfolder() void SharedFilesDialog::preModDirectories(bool update_local) { + std::cerr << "SharedFilesDialog::preModDirectories called with update_local = " << update_local << std::endl ; if (update_local) - { localModel->preMods(); - } else - { model->preMods(); - } } -void SharedFilesDialog::ModDirectories(bool update_local) +void SharedFilesDialog::postModDirectories(bool update_local) { + std::cerr << "SharedFilesDialog::postModDirectories called with update_local = " << update_local << std::endl ; if (update_local) - { localModel->postMods(); - } else - { model->postMods(); - } } diff --git a/retroshare-gui/src/gui/SharedFilesDialog.h b/retroshare-gui/src/gui/SharedFilesDialog.h index 0e89245ff..687a3bd9f 100644 --- a/retroshare-gui/src/gui/SharedFilesDialog.h +++ b/retroshare-gui/src/gui/SharedFilesDialog.h @@ -41,13 +41,14 @@ public: SharedFilesDialog(QWidget *parent = 0); /** Default Destructor */ - /* For handling the model updates */ - void preModDirectories(bool update_local); - void ModDirectories(bool update_local); private slots: + /* For handling the model updates */ + void preModDirectories(bool update_local); + void postModDirectories(bool update_local); + void checkUpdate(); void forceCheck(); diff --git a/retroshare-gui/src/main.cpp b/retroshare-gui/src/main.cpp index 7940b21fa..054183f21 100644 --- a/retroshare-gui/src/main.cpp +++ b/retroshare-gui/src/main.cpp @@ -153,6 +153,8 @@ int main(int argc, char *argv[]) // avoid clashes between infos from threads. // QObject::connect(notify,SIGNAL(hashingInfo(const QString&)),w,SLOT(updateHashingInfo(const QString&))) ; + QObject::connect(notify,SIGNAL(filesPreMod( bool)),w->sharedfilesDialog,SLOT(preModDirectories(bool))) ; + QObject::connect(notify,SIGNAL(filesPostMod( bool)),w->sharedfilesDialog,SLOT(postModDirectories(bool))) ; /* only show window, if not startMinimized */ if (!startMinimised) diff --git a/retroshare-gui/src/rsiface/notifyqt.cpp b/retroshare-gui/src/rsiface/notifyqt.cpp index f35e6710f..933dd3360 100644 --- a/retroshare-gui/src/rsiface/notifyqt.cpp +++ b/retroshare-gui/src/rsiface/notifyqt.cpp @@ -62,7 +62,8 @@ void NotifyQt::notifyListChange(int list, int type) //displayFriends(); break; case NOTIFY_LIST_DIRLIST: - displayDirectories(); + emit filesPostMod(false) ; /* Remote */ + emit filesPostMod(true) ; /* Local */ break; case NOTIFY_LIST_SEARCHLIST: //displaySearch(); @@ -97,7 +98,8 @@ void NotifyQt::notifyListPreChange(int list, int type) //preDisplayFriends(); break; case NOTIFY_LIST_DIRLIST: - preDisplayDirectories(); + emit filesPreMod(false) ; /* remote */ + emit filesPreMod(true) ; /* local */ break; case NOTIFY_LIST_SEARCHLIST: //preDisplaySearch(); @@ -279,53 +281,6 @@ void NotifyQt::displayFriends() mWindow->insertPeers(); } - - - - -void NotifyQt::preDisplayDirectories() -{ - //iface->lockData(); /* Lock Interface */ - -#ifdef NOTIFY_DEBUG - std::ostringstream out; - out << "NotifyQt::preDisplayDirectories()" << std::endl; - - std::cerr << out.str(); -#endif - - //iface->unlockData(); /* UnLock Interface */ - - if (dDialog) - { - dDialog->preModDirectories(false); /* Remote */ - dDialog->preModDirectories(true); /* Local */ - } -} - - -void NotifyQt::displayDirectories() -{ - //iface->lockData(); /* Lock Interface */ - -#ifdef NOTIFY_DEBUG - std::ostringstream out; - out << "NotifyQt::displayDirectories()" << std::endl; - - std::cerr << out.str(); -#endif - - //iface->unlockData(); /* UnLock Interface */ - - - if (dDialog) - { - dDialog->ModDirectories(false); /* Remote */ - dDialog->ModDirectories(true); /* Local */ - } -} - - void NotifyQt::displaySearch() { iface->lockData(); /* Lock Interface */ diff --git a/retroshare-gui/src/rsiface/notifyqt.h b/retroshare-gui/src/rsiface/notifyqt.h index 1a028eb1f..c2de85b49 100644 --- a/retroshare-gui/src/rsiface/notifyqt.h +++ b/retroshare-gui/src/rsiface/notifyqt.h @@ -20,35 +20,40 @@ class MessengerWindow; //class NotifyQt: public NotifyBase, public QObject class NotifyQt: public QObject, public NotifyBase { - Q_OBJECT - public: - NotifyQt() : cDialog(NULL), pDialog(NULL), - dDialog(NULL), tDialog(NULL), - hDialog(NULL), mDialog(NULL), - sDialog(NULL), mWindow(NULL) + Q_OBJECT + public: + NotifyQt() : cDialog(NULL), pDialog(NULL), + dDialog(NULL), tDialog(NULL), + hDialog(NULL), mDialog(NULL), + sDialog(NULL), mWindow(NULL) { return; } - virtual ~NotifyQt() { return; } + virtual ~NotifyQt() { return; } - void setNetworkDialog(NetworkDialog *c) { cDialog = c; } - void setPeersDialog(PeersDialog *p) { pDialog = p; } - void setDirDialog(SharedFilesDialog *d) { dDialog = d; } - void setTransfersDialog(TransfersDialog *t) { tDialog = t; } - void setChatDialog(ChatDialog *m) { hDialog = m; } - void setMessagesDialog(MessagesDialog *m) { mDialog = m; } - void setChannelsDialog(ChannelsDialog *s) { sDialog = s; } - void setMessengerWindow(MessengerWindow *mw) { mWindow = mw; } + void setNetworkDialog(NetworkDialog *c) { cDialog = c; } + void setPeersDialog(PeersDialog *p) { pDialog = p; } + void setDirDialog(SharedFilesDialog *d) { dDialog = d; } + void setTransfersDialog(TransfersDialog *t) { tDialog = t; } + void setChatDialog(ChatDialog *m) { hDialog = m; } + void setMessagesDialog(MessagesDialog *m) { mDialog = m; } + void setChannelsDialog(ChannelsDialog *s) { sDialog = s; } + void setMessengerWindow(MessengerWindow *mw) { mWindow = mw; } - void setRsIface(RsIface *i) { iface = i; } + void setRsIface(RsIface *i) { iface = i; } -virtual void notifyListPreChange(int list, int type); -virtual void notifyListChange(int list, int type); -virtual void notifyErrorMsg(int list, int sev, std::string msg); -virtual void notifyChat(); -virtual void notifyHashingInfo(std::string fileinfo); + virtual void notifyListPreChange(int list, int type); + virtual void notifyListChange(int list, int type); + virtual void notifyErrorMsg(int list, int sev, std::string msg); + virtual void notifyChat(); + virtual void notifyHashingInfo(std::string fileinfo); signals: + // It's beneficial to send info to the GUI using signals, because signals are thread-safe + // as they get queued by Qt. + // void hashingInfo(const QString&) const ; + void filesPreMod(bool) const ; + void filesPostMod(bool) const ; public slots: @@ -56,34 +61,34 @@ virtual void notifyHashingInfo(std::string fileinfo); private: - void displayNeighbours(); - void displayFriends(); - void displayDirectories(); - void displaySearch(); - void displayChat(); - void displayMessages(); - void displayChannels(); - void displayTransfers(); + void displayNeighbours(); + void displayFriends(); +// void displayDirectories(); + void displaySearch(); + void displayChat(); + void displayMessages(); + void displayChannels(); + void displayTransfers(); - void preDisplayNeighbours(); - void preDisplayFriends(); - void preDisplayDirectories(); - void preDisplaySearch(); - void preDisplayMessages(); - void preDisplayChannels(); - void preDisplayTransfers(); + void preDisplayNeighbours(); + void preDisplayFriends(); +// void preDisplayDirectories(); + void preDisplaySearch(); + void preDisplayMessages(); + void preDisplayChannels(); + void preDisplayTransfers(); - /* so we can update windows */ - NetworkDialog *cDialog; - PeersDialog *pDialog; - SharedFilesDialog *dDialog; - TransfersDialog *tDialog; - ChatDialog *hDialog; - MessagesDialog *mDialog; - ChannelsDialog *sDialog; - MessengerWindow *mWindow; + /* so we can update windows */ + NetworkDialog *cDialog; + PeersDialog *pDialog; + SharedFilesDialog *dDialog; + TransfersDialog *tDialog; + ChatDialog *hDialog; + MessagesDialog *mDialog; + ChannelsDialog *sDialog; + MessengerWindow *mWindow; - RsIface *iface; + RsIface *iface; }; #endif