added pause to file hashing

This commit is contained in:
csoler 2017-09-10 22:07:36 +02:00
parent ea25d4b5a4
commit eff5c5d6ee
11 changed files with 95 additions and 2 deletions

View file

@ -275,6 +275,15 @@ bool LocalDirectoryUpdater::filterFile(const std::string& fname) const
return true ; return true ;
} }
void LocalDirectoryUpdater::togglePauseHashingProcess()
{
mHashCache->togglePauseHashingProcess() ;
}
bool LocalDirectoryUpdater::hashingProcessPaused()
{
return mHashCache->hashingProcessPaused();
}
bool LocalDirectoryUpdater::inDirectoryCheck() const bool LocalDirectoryUpdater::inDirectoryCheck() const
{ {
return mHashCache->isRunning(); return mHashCache->isRunning();

View file

@ -40,6 +40,8 @@ public:
void forceUpdate(); void forceUpdate();
bool inDirectoryCheck() const ; bool inDirectoryCheck() const ;
void togglePauseHashingProcess();
bool hashingProcessPaused();
void setHashSalt(const RsFileHash& hash) { mHashSalt = hash; } void setHashSalt(const RsFileHash& hash) { mHashSalt = hash; }
const RsFileHash& hashSalt() const { return mHashSalt; } const RsFileHash& hashSalt() const { return mHashSalt; }

View file

@ -44,6 +44,7 @@ HashStorage::HashStorage(const std::string& save_file_name)
mTotalSizeToHash = 0; mTotalSizeToHash = 0;
mTotalFilesToHash = 0; mTotalFilesToHash = 0;
mMaxStorageDurationDays = DEFAULT_HASH_STORAGE_DURATION_DAYS ; mMaxStorageDurationDays = DEFAULT_HASH_STORAGE_DURATION_DAYS ;
mHashingProcessPaused = false;
{ {
RS_STACK_MUTEX(mHashMtx) ; RS_STACK_MUTEX(mHashMtx) ;
@ -52,6 +53,18 @@ HashStorage::HashStorage(const std::string& save_file_name)
try_load_import_old_hash_cache(); try_load_import_old_hash_cache();
} }
} }
void HashStorage::togglePauseHashingProcess()
{
RS_STACK_MUTEX(mHashMtx) ;
mHashingProcessPaused = !mHashingProcessPaused ;
}
bool HashStorage::hashingProcessPaused()
{
RS_STACK_MUTEX(mHashMtx) ;
return mHashingProcessPaused;
}
static std::string friendlyUnit(uint64_t val) static std::string friendlyUnit(uint64_t val)
{ {
const std::string units[5] = {"B","KB","MB","GB","TB"}; const std::string units[5] = {"B","KB","MB","GB","TB"};
@ -78,12 +91,14 @@ void HashStorage::data_tick()
RsFileHash hash; RsFileHash hash;
uint64_t size = 0; uint64_t size = 0;
{ {
bool empty ; bool empty ;
uint32_t st ; uint32_t st ;
{ {
RS_STACK_MUTEX(mHashMtx) ; RS_STACK_MUTEX(mHashMtx) ;
if(mChanged && mLastSaveTime + MIN_INTERVAL_BETWEEN_HASH_CACHE_SAVE < time(NULL)) if(mChanged && mLastSaveTime + MIN_INTERVAL_BETWEEN_HASH_CACHE_SAVE < time(NULL))
{ {
locked_save(); locked_save();
@ -136,6 +151,19 @@ void HashStorage::data_tick()
} }
mInactivitySleepTime = DEFAULT_INACTIVITY_SLEEP_TIME; mInactivitySleepTime = DEFAULT_INACTIVITY_SLEEP_TIME;
bool paused = false ;
{
RS_STACK_MUTEX(mHashMtx) ;
paused = mHashingProcessPaused ;
}
if(paused)
{
usleep(MAX_INACTIVITY_SLEEP_TIME) ;
std::cerr << "Hashing process currently paused." << std::endl;
return;
}
else
{ {
RS_STACK_MUTEX(mHashMtx) ; RS_STACK_MUTEX(mHashMtx) ;

View file

@ -84,6 +84,8 @@ public:
uint32_t rememberHashFilesDuration() const { return mMaxStorageDurationDays ; } uint32_t rememberHashFilesDuration() const { return mMaxStorageDurationDays ; }
void clear() { mFiles.clear(); mChanged=true; } // drop all known hashes. Not something to do, except if you want to rehash the entire database void clear() { mFiles.clear(); mChanged=true; } // drop all known hashes. Not something to do, except if you want to rehash the entire database
bool empty() const { return mFiles.empty() ; } bool empty() const { return mFiles.empty() ; }
void togglePauseHashingProcess() ;
bool hashingProcessPaused();
// Functions called by the thread // Functions called by the thread
@ -112,6 +114,7 @@ private:
std::map<std::string, HashStorageInfo> mFiles ; // stored as (full_path, hash_info) std::map<std::string, HashStorageInfo> mFiles ; // stored as (full_path, hash_info)
std::string mFilePath ; // file where the hash database is stored std::string mFilePath ; // file where the hash database is stored
bool mChanged ; bool mChanged ;
bool mHashingProcessPaused ;
struct FileHashJob struct FileHashJob
{ {

View file

@ -442,7 +442,10 @@ bool p3FileDatabase::loadList(std::list<RsItem *>& load)
std::string b ; std::string b ;
for(uint32_t i=0;i<kit->value.size();++i) for(uint32_t i=0;i<kit->value.size();++i)
if(kit->value[i] == ';') if(kit->value[i] == ';')
{
ignored_prefixes.push_back(b) ; ignored_prefixes.push_back(b) ;
b.clear();
}
else else
b.push_back(kit->value[i]) ; b.push_back(kit->value[i]) ;
} }
@ -451,7 +454,10 @@ bool p3FileDatabase::loadList(std::list<RsItem *>& load)
std::string b ; std::string b ;
for(uint32_t i=0;i<kit->value.size();++i) for(uint32_t i=0;i<kit->value.size();++i)
if(kit->value[i] == ';') if(kit->value[i] == ';')
{
ignored_suffixes.push_back(b) ; ignored_suffixes.push_back(b) ;
b.clear();
}
else else
b.push_back(kit->value[i]) ; b.push_back(kit->value[i]) ;
} }
@ -972,6 +978,16 @@ void p3FileDatabase::forceDirectoryCheck() // Force re-sweep the di
{ {
mLocalDirWatcher->forceUpdate(); mLocalDirWatcher->forceUpdate();
} }
void p3FileDatabase::togglePauseHashingProcess()
{
RS_STACK_MUTEX(mFLSMtx) ;
mLocalDirWatcher->togglePauseHashingProcess();
}
bool p3FileDatabase::hashingProcessPaused()
{
RS_STACK_MUTEX(mFLSMtx) ;
return mLocalDirWatcher->hashingProcessPaused();
}
bool p3FileDatabase::inDirectoryCheck() bool p3FileDatabase::inDirectoryCheck()
{ {
RS_STACK_MUTEX(mFLSMtx) ; RS_STACK_MUTEX(mFLSMtx) ;

View file

@ -148,6 +148,8 @@ class p3FileDatabase: public p3Service, public p3Config, public ftSearch //, pub
void forceDirectoryCheck(); // Force re-sweep the directories and see what's changed void forceDirectoryCheck(); // Force re-sweep the directories and see what's changed
bool inDirectoryCheck(); bool inDirectoryCheck();
void togglePauseHashingProcess();
bool hashingProcessPaused();
protected: protected:

View file

@ -844,6 +844,9 @@ void ftServer::setWatchEnabled(bool b) { mFileDatabase->setWatchEnab
void ftServer::setWatchPeriod(int minutes) { mFileDatabase->setWatchPeriod(minutes*60) ; } void ftServer::setWatchPeriod(int minutes) { mFileDatabase->setWatchPeriod(minutes*60) ; }
void ftServer::setFollowSymLinks(bool b) { mFileDatabase->setFollowSymLinks(b) ; } void ftServer::setFollowSymLinks(bool b) { mFileDatabase->setFollowSymLinks(b) ; }
void ftServer::togglePauseHashingProcess() { mFileDatabase->togglePauseHashingProcess() ; }
bool ftServer::hashingProcessPaused() { return mFileDatabase->hashingProcessPaused() ; }
bool ftServer::getShareDownloadDirectory() bool ftServer::getShareDownloadDirectory()
{ {
std::list<SharedDirInfo> dirList; std::list<SharedDirInfo> dirList;

View file

@ -225,6 +225,8 @@ public:
virtual bool watchEnabled() ; virtual bool watchEnabled() ;
virtual bool followSymLinks() const; virtual bool followSymLinks() const;
virtual void setFollowSymLinks(bool b); virtual void setFollowSymLinks(bool b);
virtual void togglePauseHashingProcess();
virtual bool hashingProcessPaused();
/***************************************************************/ /***************************************************************/
/*************** Data Transfer Interface ***********************/ /*************** Data Transfer Interface ***********************/

View file

@ -263,6 +263,8 @@ class RsFiles
virtual bool watchEnabled() =0; virtual bool watchEnabled() =0;
virtual bool followSymLinks() const=0; virtual bool followSymLinks() const=0;
virtual void setFollowSymLinks(bool b)=0 ; virtual void setFollowSymLinks(bool b)=0 ;
virtual void togglePauseHashingProcess() =0; // pauses/resumes the hashing process.
virtual bool hashingProcessPaused() =0;
virtual bool getShareDownloadDirectory() = 0; virtual bool getShareDownloadDirectory() = 0;
virtual bool shareDownloadDirectory(bool share) = 0; virtual bool shareDownloadDirectory(bool share) = 0;

View file

@ -22,7 +22,9 @@
#include <QLayout> #include <QLayout>
#include <QLabel> #include <QLabel>
#include <QMovie> #include <QMovie>
#include <QToolButton>
#include "retroshare/rsfiles.h"
#include "hashingstatus.h" #include "hashingstatus.h"
#include "gui/common/ElidedLabel.h" #include "gui/common/ElidedLabel.h"
#include "gui/notifyqt.h" #include "gui/notifyqt.h"
@ -61,13 +63,14 @@ HashingStatus::~HashingStatus()
void HashingStatus::updateHashingInfo(const QString& s) void HashingStatus::updateHashingInfo(const QString& s)
{ {
if (s.isEmpty()) { if (s.isEmpty())
{
statusHashing->hide() ; statusHashing->hide() ;
hashloader->hide() ; hashloader->hide() ;
movie->stop() ; movie->stop() ;
} else { } else {
hashloader->setToolTip(s) ; setToolTip(s + "\n"+QObject::tr("Click to pause the hashing process"));
if (_compactMode) { if (_compactMode) {
statusHashing->hide() ; statusHashing->hide() ;
@ -80,3 +83,24 @@ void HashingStatus::updateHashingInfo(const QString& s)
movie->start() ; movie->start() ;
} }
} }
void HashingStatus::mousePressEvent(QMouseEvent *)
{
rsFiles->togglePauseHashingProcess() ;
if(rsFiles->hashingProcessPaused())
{
movie->stop() ;
hashloader->setPixmap(QPixmap(":/images/resume.png")) ;
mLastText = statusHashing->text();
statusHashing->setText(QObject::tr("[Hashing is paused]"));
setToolTip(QObject::tr("Click to resume the hashing process"));
}
else
{
hashloader->setMovie(movie) ;
statusHashing->setText(mLastText);
movie->start() ;
}
}

View file

@ -35,6 +35,7 @@ public:
~HashingStatus(); ~HashingStatus();
void setCompactMode(bool compact) {_compactMode = compact; } void setCompactMode(bool compact) {_compactMode = compact; }
void mousePressEvent(QMouseEvent *);
public slots: public slots:
void updateHashingInfo(const QString&) ; void updateHashingInfo(const QString&) ;
@ -42,6 +43,7 @@ public slots:
private: private:
ElidedLabel *statusHashing; ElidedLabel *statusHashing;
QLabel *hashloader; QLabel *hashloader;
QString mLastText ;
QMovie *movie; QMovie *movie;
bool _compactMode; bool _compactMode;
}; };