mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-27 00:19:25 -05:00
added pause to file hashing
This commit is contained in:
parent
ea25d4b5a4
commit
eff5c5d6ee
@ -275,6 +275,15 @@ bool LocalDirectoryUpdater::filterFile(const std::string& fname) const
|
||||
return true ;
|
||||
}
|
||||
|
||||
void LocalDirectoryUpdater::togglePauseHashingProcess()
|
||||
{
|
||||
mHashCache->togglePauseHashingProcess() ;
|
||||
}
|
||||
bool LocalDirectoryUpdater::hashingProcessPaused()
|
||||
{
|
||||
return mHashCache->hashingProcessPaused();
|
||||
}
|
||||
|
||||
bool LocalDirectoryUpdater::inDirectoryCheck() const
|
||||
{
|
||||
return mHashCache->isRunning();
|
||||
|
@ -40,6 +40,8 @@ public:
|
||||
|
||||
void forceUpdate();
|
||||
bool inDirectoryCheck() const ;
|
||||
void togglePauseHashingProcess();
|
||||
bool hashingProcessPaused();
|
||||
|
||||
void setHashSalt(const RsFileHash& hash) { mHashSalt = hash; }
|
||||
const RsFileHash& hashSalt() const { return mHashSalt; }
|
||||
|
@ -44,6 +44,7 @@ HashStorage::HashStorage(const std::string& save_file_name)
|
||||
mTotalSizeToHash = 0;
|
||||
mTotalFilesToHash = 0;
|
||||
mMaxStorageDurationDays = DEFAULT_HASH_STORAGE_DURATION_DAYS ;
|
||||
mHashingProcessPaused = false;
|
||||
|
||||
{
|
||||
RS_STACK_MUTEX(mHashMtx) ;
|
||||
@ -52,6 +53,18 @@ HashStorage::HashStorage(const std::string& save_file_name)
|
||||
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)
|
||||
{
|
||||
const std::string units[5] = {"B","KB","MB","GB","TB"};
|
||||
@ -78,12 +91,14 @@ void HashStorage::data_tick()
|
||||
RsFileHash hash;
|
||||
uint64_t size = 0;
|
||||
|
||||
|
||||
{
|
||||
bool empty ;
|
||||
uint32_t st ;
|
||||
|
||||
{
|
||||
RS_STACK_MUTEX(mHashMtx) ;
|
||||
|
||||
if(mChanged && mLastSaveTime + MIN_INTERVAL_BETWEEN_HASH_CACHE_SAVE < time(NULL))
|
||||
{
|
||||
locked_save();
|
||||
@ -136,6 +151,19 @@ void HashStorage::data_tick()
|
||||
}
|
||||
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) ;
|
||||
|
||||
|
@ -84,6 +84,8 @@ public:
|
||||
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
|
||||
bool empty() const { return mFiles.empty() ; }
|
||||
void togglePauseHashingProcess() ;
|
||||
bool hashingProcessPaused();
|
||||
|
||||
// Functions called by the thread
|
||||
|
||||
@ -112,6 +114,7 @@ private:
|
||||
std::map<std::string, HashStorageInfo> mFiles ; // stored as (full_path, hash_info)
|
||||
std::string mFilePath ; // file where the hash database is stored
|
||||
bool mChanged ;
|
||||
bool mHashingProcessPaused ;
|
||||
|
||||
struct FileHashJob
|
||||
{
|
||||
|
@ -442,7 +442,10 @@ bool p3FileDatabase::loadList(std::list<RsItem *>& load)
|
||||
std::string b ;
|
||||
for(uint32_t i=0;i<kit->value.size();++i)
|
||||
if(kit->value[i] == ';')
|
||||
{
|
||||
ignored_prefixes.push_back(b) ;
|
||||
b.clear();
|
||||
}
|
||||
else
|
||||
b.push_back(kit->value[i]) ;
|
||||
}
|
||||
@ -451,7 +454,10 @@ bool p3FileDatabase::loadList(std::list<RsItem *>& load)
|
||||
std::string b ;
|
||||
for(uint32_t i=0;i<kit->value.size();++i)
|
||||
if(kit->value[i] == ';')
|
||||
{
|
||||
ignored_suffixes.push_back(b) ;
|
||||
b.clear();
|
||||
}
|
||||
else
|
||||
b.push_back(kit->value[i]) ;
|
||||
}
|
||||
@ -972,6 +978,16 @@ void p3FileDatabase::forceDirectoryCheck() // Force re-sweep the di
|
||||
{
|
||||
mLocalDirWatcher->forceUpdate();
|
||||
}
|
||||
void p3FileDatabase::togglePauseHashingProcess()
|
||||
{
|
||||
RS_STACK_MUTEX(mFLSMtx) ;
|
||||
mLocalDirWatcher->togglePauseHashingProcess();
|
||||
}
|
||||
bool p3FileDatabase::hashingProcessPaused()
|
||||
{
|
||||
RS_STACK_MUTEX(mFLSMtx) ;
|
||||
return mLocalDirWatcher->hashingProcessPaused();
|
||||
}
|
||||
bool p3FileDatabase::inDirectoryCheck()
|
||||
{
|
||||
RS_STACK_MUTEX(mFLSMtx) ;
|
||||
|
@ -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
|
||||
bool inDirectoryCheck();
|
||||
void togglePauseHashingProcess();
|
||||
bool hashingProcessPaused();
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -844,6 +844,9 @@ void ftServer::setWatchEnabled(bool b) { mFileDatabase->setWatchEnab
|
||||
void ftServer::setWatchPeriod(int minutes) { mFileDatabase->setWatchPeriod(minutes*60) ; }
|
||||
void ftServer::setFollowSymLinks(bool b) { mFileDatabase->setFollowSymLinks(b) ; }
|
||||
|
||||
void ftServer::togglePauseHashingProcess() { mFileDatabase->togglePauseHashingProcess() ; }
|
||||
bool ftServer::hashingProcessPaused() { return mFileDatabase->hashingProcessPaused() ; }
|
||||
|
||||
bool ftServer::getShareDownloadDirectory()
|
||||
{
|
||||
std::list<SharedDirInfo> dirList;
|
||||
|
@ -225,6 +225,8 @@ public:
|
||||
virtual bool watchEnabled() ;
|
||||
virtual bool followSymLinks() const;
|
||||
virtual void setFollowSymLinks(bool b);
|
||||
virtual void togglePauseHashingProcess();
|
||||
virtual bool hashingProcessPaused();
|
||||
|
||||
/***************************************************************/
|
||||
/*************** Data Transfer Interface ***********************/
|
||||
|
@ -263,6 +263,8 @@ class RsFiles
|
||||
virtual bool watchEnabled() =0;
|
||||
virtual bool followSymLinks() const=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 shareDownloadDirectory(bool share) = 0;
|
||||
|
@ -22,7 +22,9 @@
|
||||
#include <QLayout>
|
||||
#include <QLabel>
|
||||
#include <QMovie>
|
||||
#include <QToolButton>
|
||||
|
||||
#include "retroshare/rsfiles.h"
|
||||
#include "hashingstatus.h"
|
||||
#include "gui/common/ElidedLabel.h"
|
||||
#include "gui/notifyqt.h"
|
||||
@ -61,13 +63,14 @@ HashingStatus::~HashingStatus()
|
||||
|
||||
void HashingStatus::updateHashingInfo(const QString& s)
|
||||
{
|
||||
if (s.isEmpty()) {
|
||||
if (s.isEmpty())
|
||||
{
|
||||
statusHashing->hide() ;
|
||||
hashloader->hide() ;
|
||||
|
||||
movie->stop() ;
|
||||
} else {
|
||||
hashloader->setToolTip(s) ;
|
||||
setToolTip(s + "\n"+QObject::tr("Click to pause the hashing process"));
|
||||
|
||||
if (_compactMode) {
|
||||
statusHashing->hide() ;
|
||||
@ -80,3 +83,24 @@ void HashingStatus::updateHashingInfo(const QString& s)
|
||||
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() ;
|
||||
}
|
||||
}
|
||||
|
@ -35,6 +35,7 @@ public:
|
||||
~HashingStatus();
|
||||
|
||||
void setCompactMode(bool compact) {_compactMode = compact; }
|
||||
void mousePressEvent(QMouseEvent *);
|
||||
|
||||
public slots:
|
||||
void updateHashingInfo(const QString&) ;
|
||||
@ -42,6 +43,7 @@ public slots:
|
||||
private:
|
||||
ElidedLabel *statusHashing;
|
||||
QLabel *hashloader;
|
||||
QString mLastText ;
|
||||
QMovie *movie;
|
||||
bool _compactMode;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user