mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-19 11:54:22 -04:00
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
This commit is contained in:
parent
c7adb4907c
commit
80a8b41d66
15 changed files with 61 additions and 63 deletions
|
@ -24,6 +24,8 @@
|
||||||
#include "dbase/fimonitor.h"
|
#include "dbase/fimonitor.h"
|
||||||
#include "util/rsdir.h"
|
#include "util/rsdir.h"
|
||||||
#include "serialiser/rsserviceids.h"
|
#include "serialiser/rsserviceids.h"
|
||||||
|
#include "rsiface/rsiface.h"
|
||||||
|
#include "rsiface/rsnotify.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
@ -40,10 +42,10 @@
|
||||||
* #define FIM_DEBUG 1
|
* #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),
|
:CacheSource(RS_SERVICE_TYPE_FILE_INDEX, false, cs, cachedir), fi(pid),
|
||||||
pendingDirs(false), pendingForceCacheWrite(false),
|
pendingDirs(false), pendingForceCacheWrite(false),
|
||||||
mForceCheck(false), mInCheck(false),_hashing_info_callback(NULL)
|
mForceCheck(false), mInCheck(false),cb(cb_in)
|
||||||
|
|
||||||
{
|
{
|
||||||
updatePeriod = 60;
|
updatePeriod = 60;
|
||||||
|
@ -596,8 +598,7 @@ void FileIndexMonitor::updateCycle()
|
||||||
RsStackMutex stack(fiMutex); /**** LOCKED DIRS ****/
|
RsStackMutex stack(fiMutex); /**** LOCKED DIRS ****/
|
||||||
mInCheck = false;
|
mInCheck = false;
|
||||||
}
|
}
|
||||||
if(_hashing_info_callback != NULL)
|
cb->notifyHashingInfo("") ;
|
||||||
(*_hashing_info_callback)("") ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* interface */
|
/* interface */
|
||||||
|
@ -797,8 +798,7 @@ bool FileIndexMonitor::hashFile(std::string fullpath, FileEntry &fent)
|
||||||
unsigned char sha_buf[SHA_DIGEST_LENGTH];
|
unsigned char sha_buf[SHA_DIGEST_LENGTH];
|
||||||
unsigned char gblBuf[512];
|
unsigned char gblBuf[512];
|
||||||
|
|
||||||
if(_hashing_info_callback != NULL)
|
cb->notifyHashingInfo(fent.name) ;
|
||||||
(*_hashing_info_callback)("Hashing "+f_hash) ;
|
|
||||||
|
|
||||||
#ifdef FIM_DEBUG
|
#ifdef FIM_DEBUG
|
||||||
std::cerr << "File to hash = " << f_hash << std::endl;
|
std::cerr << "File to hash = " << f_hash << std::endl;
|
||||||
|
|
|
@ -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
|
class FileIndexMonitor: public CacheSource, public RsThread
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FileIndexMonitor(CacheStrapper *cs, std::string cachedir, std::string pid);
|
FileIndexMonitor(CacheStrapper *cs, NotifyBase *cb_in, std::string cachedir, std::string pid);
|
||||||
virtual ~FileIndexMonitor();
|
virtual ~FileIndexMonitor();
|
||||||
|
|
||||||
/* external interface for filetransfer */
|
/* external interface for filetransfer */
|
||||||
|
@ -96,7 +97,7 @@ void getSharedDirectories(std::list<std::string> &dirs);
|
||||||
void setPeriod(int insecs);
|
void setPeriod(int insecs);
|
||||||
void forceDirectoryCheck();
|
void forceDirectoryCheck();
|
||||||
bool inDirectoryCheck();
|
bool inDirectoryCheck();
|
||||||
void setFileHashingCallback(void (*cb)(const std::string&)) { _hashing_info_callback = cb ; }
|
|
||||||
/* util fns */
|
/* util fns */
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -125,7 +126,7 @@ bool hashFile(std::string path, FileEntry &fi); /* To Implement */
|
||||||
std::list<std::string> pendingDirList;
|
std::list<std::string> pendingDirList;
|
||||||
bool internal_setSharedDirectories();
|
bool internal_setSharedDirectories();
|
||||||
|
|
||||||
void (*_hashing_info_callback)(const std::string&) ;
|
NotifyBase *cb ;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,7 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
sleep(1);
|
sleep(1);
|
||||||
|
|
||||||
FileIndexMonitor mon(NULL, "", "OWN ID");
|
FileIndexMonitor mon(NULL,NULL, "", "OWN ID");
|
||||||
|
|
||||||
/* setup monitor */
|
/* setup monitor */
|
||||||
mon.setPeriod(period);
|
mon.setPeriod(period);
|
||||||
|
|
|
@ -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)
|
ftFiMonitor::ftFiMonitor(CacheStrapper *cs,NotifyBase *cb_in, std::string cachedir, std::string pid)
|
||||||
:FileIndexMonitor(cs, cachedir, pid), p3Config(CONFIG_TYPE_FT_SHARED)
|
:FileIndexMonitor(cs,cb_in, cachedir, pid), p3Config(CONFIG_TYPE_FT_SHARED)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ virtual bool search(std::string hash, uint64_t size, uint32_t hintflags, FileInf
|
||||||
class ftFiMonitor: public FileIndexMonitor, public ftSearch, public p3Config
|
class ftFiMonitor: public FileIndexMonitor, public ftSearch, public p3Config
|
||||||
{
|
{
|
||||||
public:
|
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 */
|
/* 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;
|
||||||
|
|
|
@ -30,6 +30,7 @@ const int ftserverzone = 29539;
|
||||||
#include "ft/ftextralist.h"
|
#include "ft/ftextralist.h"
|
||||||
#include "ft/ftfilesearch.h"
|
#include "ft/ftfilesearch.h"
|
||||||
#include "ft/ftcontroller.h"
|
#include "ft/ftcontroller.h"
|
||||||
|
#include "ft/ftfileprovider.h"
|
||||||
#include "ft/ftdatamultiplex.h"
|
#include "ft/ftdatamultiplex.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -125,7 +126,7 @@ void ftServer::SetupFtServer(NotifyBase *cb)
|
||||||
|
|
||||||
/* Make Cache Source/Store */
|
/* Make Cache Source/Store */
|
||||||
mFiStore = new ftFiStore(mCacheStrapper, mFtController, cb, ownId, remotecachedir);
|
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 */
|
/* now add the set to the cachestrapper */
|
||||||
CachePair cp(mFiMon, mFiStore, CacheId(RS_SERVICE_TYPE_FILE_INDEX, 0));
|
CachePair cp(mFiMon, mFiStore, CacheId(RS_SERVICE_TYPE_FILE_INDEX, 0));
|
||||||
|
@ -424,10 +425,6 @@ bool ftServer::InDirectoryCheck()
|
||||||
{
|
{
|
||||||
return mFiMon->inDirectoryCheck();
|
return mFiMon->inDirectoryCheck();
|
||||||
}
|
}
|
||||||
void ftServer::setFileHashingCallback( void (*cb)(const std::string&) )
|
|
||||||
{
|
|
||||||
mFiMon->setFileHashingCallback( cb ) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ftServer::getSharedDirectories(std::list<std::string> &dirs)
|
bool ftServer::getSharedDirectories(std::list<std::string> &dirs)
|
||||||
{
|
{
|
||||||
|
|
|
@ -149,7 +149,6 @@ virtual int SearchBoolExp(Expression * exp, std::list<FileDetail> &results);
|
||||||
virtual bool ConvertSharedFilePath(std::string path, std::string &fullpath);
|
virtual bool ConvertSharedFilePath(std::string path, std::string &fullpath);
|
||||||
virtual void ForceDirectoryCheck();
|
virtual void ForceDirectoryCheck();
|
||||||
virtual bool InDirectoryCheck();
|
virtual bool InDirectoryCheck();
|
||||||
virtual void setFileHashingCallback( void(*cb)(const std::string&));
|
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* Directory Handling
|
* Directory Handling
|
||||||
|
|
|
@ -139,9 +139,6 @@ virtual int SearchBoolExp(Expression * exp, std::list<FileDetail> &results) = 0;
|
||||||
virtual bool ConvertSharedFilePath(std::string path, std::string &fullpath) = 0;
|
virtual bool ConvertSharedFilePath(std::string path, std::string &fullpath) = 0;
|
||||||
virtual void ForceDirectoryCheck() = 0;
|
virtual void ForceDirectoryCheck() = 0;
|
||||||
virtual bool InDirectoryCheck() = 0;
|
virtual bool InDirectoryCheck() = 0;
|
||||||
virtual void setFileHashingCallback( void(*cb)(const std::string&)) = 0;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* Directory Control
|
* Directory Control
|
||||||
|
|
|
@ -199,6 +199,7 @@ class NotifyBase
|
||||||
virtual void notifyListChange(int list, int type) { (void) list; (void) type; return; }
|
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 notifyErrorMsg(int list, int sev, std::string msg) { (void) list; (void) sev; (void) msg; return; }
|
||||||
virtual void notifyChat() { return; }
|
virtual void notifyChat() { return; }
|
||||||
|
virtual void notifyHashingInfo(std::string fileinfo) { (void)fileinfo; return ; }
|
||||||
};
|
};
|
||||||
|
|
||||||
const int NOTIFY_LIST_NEIGHBOURS = 1;
|
const int NOTIFY_LIST_NEIGHBOURS = 1;
|
||||||
|
|
|
@ -112,27 +112,6 @@
|
||||||
|
|
||||||
#define RS_RELEASE_VERSION 1
|
#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 */
|
/** Constructor */
|
||||||
MainWindow::MainWindow(QWidget* parent, Qt::WFlags flags)
|
MainWindow::MainWindow(QWidget* parent, Qt::WFlags flags)
|
||||||
: RWindow("MainWindow", parent, flags)
|
: RWindow("MainWindow", parent, flags)
|
||||||
|
@ -333,9 +312,9 @@ MainWindow::MainWindow(QWidget* parent, Qt::WFlags flags)
|
||||||
peerstatus = new PeerStatus();
|
peerstatus = new PeerStatus();
|
||||||
statusBar()->addWidget(peerstatus);
|
statusBar()->addWidget(peerstatus);
|
||||||
|
|
||||||
hash_info_label = new QLabel("") ;
|
_hashing_info_label = new QLabel("") ;
|
||||||
statusBar()->addPermanentWidget(hash_info_label);
|
statusBar()->addPermanentWidget(_hashing_info_label);
|
||||||
hash_info_label->hide() ;
|
_hashing_info_label->hide() ;
|
||||||
|
|
||||||
statusBar()->addPermanentWidget(statusRates = new QLabel(tr("<strong>Down:</strong> 0.00 (kB/s) | <strong>Up:</strong> 0.00 (kB/s) ")));
|
statusBar()->addPermanentWidget(statusRates = new QLabel(tr("<strong>Down:</strong> 0.00 (kB/s) | <strong>Up:</strong> 0.00 (kB/s) ")));
|
||||||
|
|
||||||
|
@ -393,11 +372,6 @@ MainWindow::MainWindow(QWidget* parent, Qt::WFlags flags)
|
||||||
QTimer *timer = new QTimer(this);
|
QTimer *timer = new QTimer(this);
|
||||||
timer->connect(timer, SIGNAL(timeout()), this, SLOT(updateStatus()));
|
timer->connect(timer, SIGNAL(timeout()), this, SLOT(updateStatus()));
|
||||||
timer->start(5113);
|
timer->start(5113);
|
||||||
|
|
||||||
// Here we're setting the callback responsible for displaying what's happening to
|
|
||||||
// file hashing.
|
|
||||||
//
|
|
||||||
rsFiles->setFileHashingCallback(displayHashingInfo) ;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::updateStatus()
|
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. */
|
/** Creates a new action associated with a config page. */
|
||||||
QAction* MainWindow::createPageAction(QIcon img, QString text, QActionGroup *group)
|
QAction* MainWindow::createPageAction(QIcon img, QString text, QActionGroup *group)
|
||||||
{
|
{
|
||||||
|
|
|
@ -116,6 +116,7 @@ public slots:
|
||||||
void startqcheckers();
|
void startqcheckers();
|
||||||
|
|
||||||
void playFiles(QStringList files);
|
void playFiles(QStringList files);
|
||||||
|
void updateHashingInfo(const QString&) ;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
|
@ -211,6 +212,8 @@ private:
|
||||||
|
|
||||||
/** Qt Designer generated object */
|
/** Qt Designer generated object */
|
||||||
Ui::MainWindow ui;
|
Ui::MainWindow ui;
|
||||||
|
|
||||||
|
QLabel *_hashing_info_label ;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -150,6 +150,11 @@ int main(int argc, char *argv[])
|
||||||
notify->setChannelsDialog(w->channelsDialog);
|
notify->setChannelsDialog(w->channelsDialog);
|
||||||
notify->setMessengerWindow(w->messengerWindow);
|
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 */
|
/* only show window, if not startMinimized */
|
||||||
if (!startMinimised)
|
if (!startMinimised)
|
||||||
{
|
{
|
||||||
|
|
|
@ -36,6 +36,11 @@ void NotifyQt::notifyErrorMsg(int list, int type, std::string msg)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NotifyQt::notifyHashingInfo(std::string fileinfo)
|
||||||
|
{
|
||||||
|
emit hashingInfo(QString::fromStdString(fileinfo)) ;
|
||||||
|
}
|
||||||
|
|
||||||
void NotifyQt::notifyChat()
|
void NotifyQt::notifyChat()
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -45,6 +45,10 @@ virtual void notifyListPreChange(int list, int type);
|
||||||
virtual void notifyListChange(int list, int type);
|
virtual void notifyListChange(int list, int type);
|
||||||
virtual void notifyErrorMsg(int list, int sev, std::string msg);
|
virtual void notifyErrorMsg(int list, int sev, std::string msg);
|
||||||
virtual void notifyChat();
|
virtual void notifyChat();
|
||||||
|
virtual void notifyHashingInfo(std::string fileinfo);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void hashingInfo(const QString&) const ;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
|
|
|
@ -199,6 +199,7 @@ class NotifyBase
|
||||||
virtual void notifyListChange(int list, int type) { (void) list; (void) type; return; }
|
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 notifyErrorMsg(int list, int sev, std::string msg) { (void) list; (void) sev; (void) msg; return; }
|
||||||
virtual void notifyChat() { return; }
|
virtual void notifyChat() { return; }
|
||||||
|
virtual void notifyHashingInfo(std::string fileinfo) { (void)fileinfo; return ; }
|
||||||
};
|
};
|
||||||
|
|
||||||
const int NOTIFY_LIST_NEIGHBOURS = 1;
|
const int NOTIFY_LIST_NEIGHBOURS = 1;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue