From 80a8b41d663c77cf63390e0313e2f8034879aa62 Mon Sep 17 00:00:00 2001 From: csoler Date: Thu, 22 Jan 2009 21:06:54 +0000 Subject: [PATCH] Added a display for file hashing activity using notifyQt class. This time it works nicely. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@938 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/dbase/fimonitor.cc | 12 +++---- libretroshare/src/dbase/fimonitor.h | 9 +++--- libretroshare/src/dbase/fimontest.cc | 2 +- libretroshare/src/ft/ftdbase.cc | 4 +-- libretroshare/src/ft/ftdbase.h | 6 ++-- libretroshare/src/ft/ftserver.cc | 7 ++-- libretroshare/src/ft/ftserver.h | 1 - libretroshare/src/rsiface/rsfiles.h | 3 -- libretroshare/src/rsiface/rsiface.h | 1 + retroshare-gui/src/gui/MainWindow.cpp | 43 ++++++++----------------- retroshare-gui/src/gui/MainWindow.h | 3 ++ retroshare-gui/src/main.cpp | 21 +++++++----- retroshare-gui/src/rsiface/notifyqt.cpp | 5 +++ retroshare-gui/src/rsiface/notifyqt.h | 6 +++- retroshare-gui/src/rsiface/rsiface.h | 1 + 15 files changed, 61 insertions(+), 63 deletions(-) diff --git a/libretroshare/src/dbase/fimonitor.cc b/libretroshare/src/dbase/fimonitor.cc index b3d971f9a..972824b11 100644 --- a/libretroshare/src/dbase/fimonitor.cc +++ b/libretroshare/src/dbase/fimonitor.cc @@ -24,6 +24,8 @@ #include "dbase/fimonitor.h" #include "util/rsdir.h" #include "serialiser/rsserviceids.h" +#include "rsiface/rsiface.h" +#include "rsiface/rsnotify.h" #include #include @@ -40,10 +42,10 @@ * #define FIM_DEBUG 1 ***********/ -FileIndexMonitor::FileIndexMonitor(CacheStrapper *cs, std::string cachedir, std::string pid) +FileIndexMonitor::FileIndexMonitor(CacheStrapper *cs, NotifyBase *cb_in,std::string cachedir, std::string pid) :CacheSource(RS_SERVICE_TYPE_FILE_INDEX, false, cs, cachedir), fi(pid), pendingDirs(false), pendingForceCacheWrite(false), - mForceCheck(false), mInCheck(false),_hashing_info_callback(NULL) + mForceCheck(false), mInCheck(false),cb(cb_in) { updatePeriod = 60; @@ -596,8 +598,7 @@ void FileIndexMonitor::updateCycle() RsStackMutex stack(fiMutex); /**** LOCKED DIRS ****/ mInCheck = false; } - if(_hashing_info_callback != NULL) - (*_hashing_info_callback)("") ; + cb->notifyHashingInfo("") ; } /* interface */ @@ -797,8 +798,7 @@ bool FileIndexMonitor::hashFile(std::string fullpath, FileEntry &fent) unsigned char sha_buf[SHA_DIGEST_LENGTH]; unsigned char gblBuf[512]; - if(_hashing_info_callback != NULL) - (*_hashing_info_callback)("Hashing "+f_hash) ; + cb->notifyHashingInfo(fent.name) ; #ifdef FIM_DEBUG std::cerr << "File to hash = " << f_hash << std::endl; diff --git a/libretroshare/src/dbase/fimonitor.h b/libretroshare/src/dbase/fimonitor.h index 0d4a952a4..6831984ab 100644 --- a/libretroshare/src/dbase/fimonitor.h +++ b/libretroshare/src/dbase/fimonitor.h @@ -59,6 +59,7 @@ std::string FileIndexMonitor::findRealRoot(std::string base); ******************************************************************************************/ +class NotifyBase ; /****************************************************************************************** @@ -68,7 +69,7 @@ std::string FileIndexMonitor::findRealRoot(std::string base); class FileIndexMonitor: public CacheSource, public RsThread { public: - FileIndexMonitor(CacheStrapper *cs, std::string cachedir, std::string pid); + FileIndexMonitor(CacheStrapper *cs, NotifyBase *cb_in, std::string cachedir, std::string pid); virtual ~FileIndexMonitor(); /* external interface for filetransfer */ @@ -96,7 +97,7 @@ void getSharedDirectories(std::list &dirs); void setPeriod(int insecs); void forceDirectoryCheck(); bool inDirectoryCheck(); -void setFileHashingCallback(void (*cb)(const std::string&)) { _hashing_info_callback = cb ; } + /* util fns */ private: @@ -123,9 +124,9 @@ bool hashFile(std::string path, FileEntry &fi); /* To Implement */ bool mInCheck; std::list pendingDirList; -bool internal_setSharedDirectories(); + bool internal_setSharedDirectories(); - void (*_hashing_info_callback)(const std::string&) ; + NotifyBase *cb ; }; diff --git a/libretroshare/src/dbase/fimontest.cc b/libretroshare/src/dbase/fimontest.cc index 4db1b8766..f3945c870 100644 --- a/libretroshare/src/dbase/fimontest.cc +++ b/libretroshare/src/dbase/fimontest.cc @@ -72,7 +72,7 @@ int main(int argc, char **argv) sleep(1); - FileIndexMonitor mon(NULL, "", "OWN ID"); + FileIndexMonitor mon(NULL,NULL, "", "OWN ID"); /* setup monitor */ mon.setPeriod(period); diff --git a/libretroshare/src/ft/ftdbase.cc b/libretroshare/src/ft/ftdbase.cc index fc1d6930d..cf4897e1e 100644 --- a/libretroshare/src/ft/ftdbase.cc +++ b/libretroshare/src/ft/ftdbase.cc @@ -119,8 +119,8 @@ bool ftFiStore::search(std::string hash, uint64_t size, uint32_t hintflags, File } -ftFiMonitor::ftFiMonitor(CacheStrapper *cs, std::string cachedir, std::string pid) - :FileIndexMonitor(cs, cachedir, pid), p3Config(CONFIG_TYPE_FT_SHARED) +ftFiMonitor::ftFiMonitor(CacheStrapper *cs,NotifyBase *cb_in, std::string cachedir, std::string pid) + :FileIndexMonitor(cs,cb_in, cachedir, pid), p3Config(CONFIG_TYPE_FT_SHARED) { return; } diff --git a/libretroshare/src/ft/ftdbase.h b/libretroshare/src/ft/ftdbase.h index 373b0cb1a..720d5805f 100644 --- a/libretroshare/src/ft/ftdbase.h +++ b/libretroshare/src/ft/ftdbase.h @@ -54,13 +54,13 @@ virtual bool search(std::string hash, uint64_t size, uint32_t hintflags, FileInf class ftFiMonitor: public FileIndexMonitor, public ftSearch, public p3Config { public: - ftFiMonitor(CacheStrapper *cs, std::string cachedir, std::string pid); + ftFiMonitor(CacheStrapper *cs,NotifyBase *cb_in, std::string cachedir, std::string pid); /* overloaded search function */ -virtual bool search(std::string hash, uint64_t size, uint32_t hintflags, FileInfo &info) const; + virtual bool search(std::string hash, uint64_t size, uint32_t hintflags, FileInfo &info) const; /* overloaded set dirs enables config indication */ -virtual void setSharedDirectories(std::list dirList); + virtual void setSharedDirectories(std::list dirList); /*** * Configuration - store shared directories diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index 7871d3f36..078d08fc2 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -30,6 +30,7 @@ const int ftserverzone = 29539; #include "ft/ftextralist.h" #include "ft/ftfilesearch.h" #include "ft/ftcontroller.h" +#include "ft/ftfileprovider.h" #include "ft/ftdatamultiplex.h" @@ -125,7 +126,7 @@ void ftServer::SetupFtServer(NotifyBase *cb) /* Make Cache Source/Store */ mFiStore = new ftFiStore(mCacheStrapper, mFtController, cb, ownId, remotecachedir); - mFiMon = new ftFiMonitor(mCacheStrapper, localcachedir, ownId); + mFiMon = new ftFiMonitor(mCacheStrapper,cb, localcachedir, ownId); /* now add the set to the cachestrapper */ CachePair cp(mFiMon, mFiStore, CacheId(RS_SERVICE_TYPE_FILE_INDEX, 0)); @@ -424,10 +425,6 @@ bool ftServer::InDirectoryCheck() { return mFiMon->inDirectoryCheck(); } -void ftServer::setFileHashingCallback( void (*cb)(const std::string&) ) -{ - mFiMon->setFileHashingCallback( cb ) ; -} bool ftServer::getSharedDirectories(std::list &dirs) { diff --git a/libretroshare/src/ft/ftserver.h b/libretroshare/src/ft/ftserver.h index faf1af4f5..3957e5754 100644 --- a/libretroshare/src/ft/ftserver.h +++ b/libretroshare/src/ft/ftserver.h @@ -149,7 +149,6 @@ virtual int SearchBoolExp(Expression * exp, std::list &results); virtual bool ConvertSharedFilePath(std::string path, std::string &fullpath); virtual void ForceDirectoryCheck(); virtual bool InDirectoryCheck(); -virtual void setFileHashingCallback( void(*cb)(const std::string&)); /*** * Directory Handling diff --git a/libretroshare/src/rsiface/rsfiles.h b/libretroshare/src/rsiface/rsfiles.h index 5ea3e6851..3f8575035 100644 --- a/libretroshare/src/rsiface/rsfiles.h +++ b/libretroshare/src/rsiface/rsfiles.h @@ -139,9 +139,6 @@ virtual int SearchBoolExp(Expression * exp, std::list &results) = 0; virtual bool ConvertSharedFilePath(std::string path, std::string &fullpath) = 0; virtual void ForceDirectoryCheck() = 0; virtual bool InDirectoryCheck() = 0; -virtual void setFileHashingCallback( void(*cb)(const std::string&)) = 0; - - /*** * Directory Control diff --git a/libretroshare/src/rsiface/rsiface.h b/libretroshare/src/rsiface/rsiface.h index 0f479dce5..7d12ea68e 100644 --- a/libretroshare/src/rsiface/rsiface.h +++ b/libretroshare/src/rsiface/rsiface.h @@ -199,6 +199,7 @@ class NotifyBase virtual void notifyListChange(int list, int type) { (void) list; (void) type; return; } virtual void notifyErrorMsg(int list, int sev, std::string msg) { (void) list; (void) sev; (void) msg; return; } virtual void notifyChat() { return; } + virtual void notifyHashingInfo(std::string fileinfo) { (void)fileinfo; return ; } }; const int NOTIFY_LIST_NEIGHBOURS = 1; diff --git a/retroshare-gui/src/gui/MainWindow.cpp b/retroshare-gui/src/gui/MainWindow.cpp index 1f22df448..698e98776 100644 --- a/retroshare-gui/src/gui/MainWindow.cpp +++ b/retroshare-gui/src/gui/MainWindow.cpp @@ -112,27 +112,6 @@ #define RS_RELEASE_VERSION 1 -// This static function is a callback passed to the file hashing thread. As it is called -// from a separate thread without locks, it should not perturbate the interface. That's why -// I'm only using show()/hide() and setText() instead of add/remove widgets. -// -static QLabel *hash_info_label = NULL ; -static void displayHashingInfo(const std::string& s) -{ - return ; - - // I disabled this, because it's causing core dumps. I'll see what I can do. - -// if(hash_info_label != NULL) -// if(s == "") -// hash_info_label->hide() ; -// else -// { -// hash_info_label->show() ; -// hash_info_label->setText(QString::fromStdString(s)) ; -// } -} - /** Constructor */ MainWindow::MainWindow(QWidget* parent, Qt::WFlags flags) : RWindow("MainWindow", parent, flags) @@ -333,9 +312,9 @@ MainWindow::MainWindow(QWidget* parent, Qt::WFlags flags) peerstatus = new PeerStatus(); statusBar()->addWidget(peerstatus); - hash_info_label = new QLabel("") ; - statusBar()->addPermanentWidget(hash_info_label); - hash_info_label->hide() ; + _hashing_info_label = new QLabel("") ; + statusBar()->addPermanentWidget(_hashing_info_label); + _hashing_info_label->hide() ; statusBar()->addPermanentWidget(statusRates = new QLabel(tr("Down: 0.00 (kB/s) | Up: 0.00 (kB/s) "))); @@ -393,11 +372,6 @@ MainWindow::MainWindow(QWidget* parent, Qt::WFlags flags) QTimer *timer = new QTimer(this); timer->connect(timer, SIGNAL(timeout()), this, SLOT(updateStatus())); timer->start(5113); - - // Here we're setting the callback responsible for displaying what's happening to - // file hashing. - // - rsFiles->setFileHashingCallback(displayHashingInfo) ; } void MainWindow::updateStatus() @@ -419,6 +393,17 @@ void MainWindow::updateStatus() } +void MainWindow::updateHashingInfo(const QString& s) +{ + if(s == "") + _hashing_info_label->hide() ; + else + { + _hashing_info_label->setText("Hashing file " + s) ; + _hashing_info_label->show() ; + } +} + /** Creates a new action associated with a config page. */ QAction* MainWindow::createPageAction(QIcon img, QString text, QActionGroup *group) { diff --git a/retroshare-gui/src/gui/MainWindow.h b/retroshare-gui/src/gui/MainWindow.h index 55501ba37..acb0ffbd2 100644 --- a/retroshare-gui/src/gui/MainWindow.h +++ b/retroshare-gui/src/gui/MainWindow.h @@ -116,6 +116,7 @@ public slots: void startqcheckers(); void playFiles(QStringList files); + void updateHashingInfo(const QString&) ; private slots: @@ -211,6 +212,8 @@ private: /** Qt Designer generated object */ Ui::MainWindow ui; + + QLabel *_hashing_info_label ; }; #endif diff --git a/retroshare-gui/src/main.cpp b/retroshare-gui/src/main.cpp index f9d50d18b..8a09d2e19 100644 --- a/retroshare-gui/src/main.cpp +++ b/retroshare-gui/src/main.cpp @@ -141,14 +141,19 @@ int main(int argc, char *argv[]) //skinWindow->setCentralWidget(w); /* Attach the Dialogs, to the Notify Class */ - notify->setNetworkDialog(w->networkDialog); - notify->setPeersDialog(w->peersDialog); - notify->setDirDialog(w->sharedfilesDialog); - notify->setTransfersDialog(w->transfersDialog); - notify->setChatDialog(w->chatDialog); - notify->setMessagesDialog(w->messagesDialog); - notify->setChannelsDialog(w->channelsDialog); - notify->setMessengerWindow(w->messengerWindow); + notify->setNetworkDialog(w->networkDialog); + notify->setPeersDialog(w->peersDialog); + notify->setDirDialog(w->sharedfilesDialog); + notify->setTransfersDialog(w->transfersDialog); + notify->setChatDialog(w->chatDialog); + notify->setMessagesDialog(w->messagesDialog); + notify->setChannelsDialog(w->channelsDialog); + notify->setMessengerWindow(w->messengerWindow); + + // I'm using a signal to transfer the hashing info to the mainwindow, because Qt schedules signals properly to + // avoid clashes between infos from threads. + // + QObject::connect(notify,SIGNAL(hashingInfo(const QString&)),w,SLOT(updateHashingInfo(const QString&))) ; /* 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 82ae709f9..f35e6710f 100644 --- a/retroshare-gui/src/rsiface/notifyqt.cpp +++ b/retroshare-gui/src/rsiface/notifyqt.cpp @@ -36,6 +36,11 @@ void NotifyQt::notifyErrorMsg(int list, int type, std::string msg) return; } +void NotifyQt::notifyHashingInfo(std::string fileinfo) +{ + emit hashingInfo(QString::fromStdString(fileinfo)) ; +} + void NotifyQt::notifyChat() { return; diff --git a/retroshare-gui/src/rsiface/notifyqt.h b/retroshare-gui/src/rsiface/notifyqt.h index 3bc0f0a89..1a028eb1f 100644 --- a/retroshare-gui/src/rsiface/notifyqt.h +++ b/retroshare-gui/src/rsiface/notifyqt.h @@ -45,10 +45,14 @@ 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: + void hashingInfo(const QString&) const ; public slots: -void UpdateGUI(); /* called by timer */ + void UpdateGUI(); /* called by timer */ private: diff --git a/retroshare-gui/src/rsiface/rsiface.h b/retroshare-gui/src/rsiface/rsiface.h index 0f479dce5..7d12ea68e 100644 --- a/retroshare-gui/src/rsiface/rsiface.h +++ b/retroshare-gui/src/rsiface/rsiface.h @@ -199,6 +199,7 @@ class NotifyBase virtual void notifyListChange(int list, int type) { (void) list; (void) type; return; } virtual void notifyErrorMsg(int list, int sev, std::string msg) { (void) list; (void) sev; (void) msg; return; } virtual void notifyChat() { return; } + virtual void notifyHashingInfo(std::string fileinfo) { (void)fileinfo; return ; } }; const int NOTIFY_LIST_NEIGHBOURS = 1;