mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-21 05:44:29 -05: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
@ -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 <iostream>
|
||||
#include <sstream>
|
||||
@ -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;
|
||||
|
@ -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<std::string> &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<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);
|
||||
|
||||
FileIndexMonitor mon(NULL, "", "OWN ID");
|
||||
FileIndexMonitor mon(NULL,NULL, "", "OWN ID");
|
||||
|
||||
/* setup monitor */
|
||||
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)
|
||||
: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;
|
||||
}
|
||||
|
@ -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<std::string> dirList);
|
||||
virtual void setSharedDirectories(std::list<std::string> dirList);
|
||||
|
||||
/***
|
||||
* Configuration - store shared directories
|
||||
|
@ -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<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 void ForceDirectoryCheck();
|
||||
virtual bool InDirectoryCheck();
|
||||
virtual void setFileHashingCallback( void(*cb)(const std::string&));
|
||||
|
||||
/***
|
||||
* 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 void ForceDirectoryCheck() = 0;
|
||||
virtual bool InDirectoryCheck() = 0;
|
||||
virtual void setFileHashingCallback( void(*cb)(const std::string&)) = 0;
|
||||
|
||||
|
||||
|
||||
/***
|
||||
* Directory Control
|
||||
|
@ -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;
|
||||
|
@ -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("<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);
|
||||
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)
|
||||
{
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
@ -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:
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user