mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
added a checkbox in settings for tuning auto-check of shared directories
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4107 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
5492f405c3
commit
7c6682b89f
@ -57,6 +57,13 @@ FileIndexMonitor::FileIndexMonitor(CacheStrapper *cs, NotifyBase *cb_in,std::str
|
||||
{
|
||||
updatePeriod = 60;
|
||||
}
|
||||
|
||||
bool FileIndexMonitor::autoCheckEnabled() const
|
||||
{
|
||||
RsStackMutex mtx(fiMutex) ; /* LOCKED DIRS */
|
||||
return updatePeriod > 0 ;
|
||||
}
|
||||
|
||||
bool FileIndexMonitor::rememberHashFiles()
|
||||
{
|
||||
RsStackMutex mtx(fiMutex) ; /* LOCKED DIRS */
|
||||
@ -443,51 +450,69 @@ bool FileIndexMonitor::updateCache(const CacheData &data) /* we call this one *
|
||||
}
|
||||
|
||||
|
||||
void FileIndexMonitor::setPeriod(int period)
|
||||
uint32_t FileIndexMonitor::getPeriod() const
|
||||
{
|
||||
//#ifdef FIM_DEBUG
|
||||
std::cerr << "FileIndexMonitor::setPeriod() getting watch period" << std::endl;
|
||||
//#endif
|
||||
RsStackMutex mtx(fiMutex) ; /* LOCKED DIRS */
|
||||
return updatePeriod ;
|
||||
}
|
||||
|
||||
void FileIndexMonitor::setPeriod(uint32_t period)
|
||||
{
|
||||
RsStackMutex mtx(fiMutex) ; /* LOCKED DIRS */
|
||||
updatePeriod = period;
|
||||
//#ifdef FIM_DEBUG
|
||||
std::cerr << "FileIndexMonitor::setPeriod() Setting watch period to " << updatePeriod << std::endl;
|
||||
//#endif
|
||||
}
|
||||
|
||||
void FileIndexMonitor::run()
|
||||
//void FileIndexMonitor::run(std::string& current_job)
|
||||
{
|
||||
if(autoCheckEnabled())
|
||||
updateCycle();
|
||||
|
||||
while(isRunning())
|
||||
{
|
||||
|
||||
for(int i = 0; i < updatePeriod; i++)
|
||||
int i=0 ;
|
||||
for(;;i++)
|
||||
{
|
||||
|
||||
if (isRunning() == false) {
|
||||
if(!isRunning())
|
||||
return;
|
||||
}
|
||||
|
||||
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||
#ifndef WINDOWS_SYS
|
||||
sleep(1);
|
||||
#else
|
||||
Sleep(1000);
|
||||
#endif
|
||||
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||
/********************************** WINDOWS/UNIX SPECIFIC PART ******************/
|
||||
|
||||
/* check dirs if they've changed */
|
||||
if (internal_setSharedDirectories())
|
||||
{
|
||||
break;
|
||||
|
||||
{
|
||||
RsStackMutex mtx(fiMutex) ;
|
||||
|
||||
if(i >= abs(updatePeriod))
|
||||
break ;
|
||||
}
|
||||
}
|
||||
|
||||
if(i < abs(updatePeriod) || autoCheckEnabled())
|
||||
updateCycle();
|
||||
|
||||
#ifdef FIM_DEBUG
|
||||
{
|
||||
RsStackMutex mtx(fiMutex) ;
|
||||
std::cerr <<"*********** FileIndex **************" << std::endl ;
|
||||
fi.printFileIndex(std::cerr) ;
|
||||
std::cerr <<"************** END *****************" << std::endl ;
|
||||
std::cerr << std::endl ;
|
||||
#endif
|
||||
}
|
||||
|
||||
updateCycle();
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -142,7 +142,6 @@ class FileIndexMonitor: public CacheSource, public RsThread
|
||||
void getSharedDirectories(std::list<SharedDirInfo>& dirs);
|
||||
void updateShareFlags(const SharedDirInfo& info) ;
|
||||
|
||||
void setPeriod(int insecs);
|
||||
void forceDirectoryCheck();
|
||||
bool inDirectoryCheck();
|
||||
|
||||
@ -157,6 +156,10 @@ class FileIndexMonitor: public CacheSource, public RsThread
|
||||
bool rememberHashFiles() ;
|
||||
// Remove any memory of formerly hashed files that are not shared anymore
|
||||
void clearHashFiles() ;
|
||||
void setPeriod(uint32_t insecs);
|
||||
uint32_t getPeriod() const;
|
||||
|
||||
bool autoCheckEnabled() const ;
|
||||
|
||||
private:
|
||||
/* the mutex should be locked before calling these 3. */
|
||||
|
@ -161,6 +161,16 @@ bool ftFiMonitor::search(const std::string &hash, uint32_t hintflags, FileInfo &
|
||||
return false;
|
||||
};
|
||||
|
||||
int ftFiMonitor::watchPeriod() const
|
||||
{
|
||||
return getPeriod() ;
|
||||
}
|
||||
void ftFiMonitor::setWatchPeriod(int seconds)
|
||||
{
|
||||
setPeriod(seconds) ;// call FileIndexMonitor
|
||||
IndicateConfigChanged() ;
|
||||
}
|
||||
|
||||
void ftFiMonitor::setRememberHashCacheDuration(uint32_t days)
|
||||
{
|
||||
setRememberHashFilesDuration(days) ; // calls FileIndexMonitor
|
||||
@ -204,6 +214,7 @@ RsSerialiser *ftFiMonitor::setupSerialiser()
|
||||
|
||||
const std::string hash_cache_duration_ss("HASH_CACHE_DURATION");
|
||||
const std::string hash_cache_ss("HASH_CACHE");
|
||||
const std::string watch_file_duration_ss("WATCH_FILES_DELAY");
|
||||
|
||||
bool ftFiMonitor::saveList(bool &cleanup, std::list<RsItem *>& sList)
|
||||
{
|
||||
@ -235,12 +246,21 @@ bool ftFiMonitor::saveList(bool &cleanup, std::list<RsItem *>& sList)
|
||||
std::map<std::string, std::string> configMap;
|
||||
|
||||
/* basic control parameters */
|
||||
{
|
||||
std::ostringstream s ;
|
||||
s << rememberHashFilesDuration() ;
|
||||
|
||||
configMap[hash_cache_duration_ss] = s.str() ;
|
||||
}
|
||||
configMap[hash_cache_ss] = rememberHashFiles()?"YES":"NO" ;
|
||||
|
||||
{
|
||||
std::ostringstream s ;
|
||||
s << watchPeriod() ;
|
||||
|
||||
configMap[watch_file_duration_ss] = s.str() ;
|
||||
}
|
||||
|
||||
RsConfigKeyValueSet *rskv = new RsConfigKeyValueSet();
|
||||
|
||||
/* Convert to TLV */
|
||||
@ -297,6 +317,13 @@ bool ftFiMonitor::loadList(std::list<RsItem *>& load)
|
||||
}
|
||||
if(configMap.end() != (mit = configMap.find(hash_cache_ss)))
|
||||
setRememberHashFiles( mit->second == "YES") ;
|
||||
|
||||
if(configMap.end() != (mit = configMap.find(watch_file_duration_ss)))
|
||||
{
|
||||
uint32_t t=0 ;
|
||||
if(sscanf(mit->second.c_str(),"%d",&t) == 1)
|
||||
setWatchPeriod(t);
|
||||
}
|
||||
}
|
||||
|
||||
RsFileConfigItem *fi = dynamic_cast<RsFileConfigItem *>(*it);
|
||||
|
@ -71,6 +71,8 @@ class ftFiMonitor: public FileIndexMonitor, public ftSearch, public p3Config
|
||||
void setRememberHashCache(bool) ;
|
||||
bool rememberHashCache() ;
|
||||
void clearHashCache() ;
|
||||
void setWatchPeriod(int seconds) ; // can be negative, which means auto-check disabled.
|
||||
int watchPeriod() const ;
|
||||
|
||||
/***
|
||||
* Configuration - store shared directories
|
||||
|
@ -167,9 +167,8 @@ void ftServer::StartupThreads()
|
||||
|
||||
/* startup Monitor Thread */
|
||||
/* startup the FileMonitor (after cache load) */
|
||||
mFiMon->setPeriod(600); /* 10 minutes */
|
||||
/* start it up */
|
||||
//mFiMon->setSharedDirectories(dbase_dirs);
|
||||
|
||||
mFiMon->start();
|
||||
|
||||
/* Controller thread */
|
||||
@ -644,6 +643,15 @@ bool ftServer::removeSharedDirectory(std::string dir)
|
||||
|
||||
return true;
|
||||
}
|
||||
void ftServer::setWatchPeriod(int minutes)
|
||||
{
|
||||
mFiMon->setWatchPeriod(minutes*60) ;
|
||||
}
|
||||
int ftServer::watchPeriod() const
|
||||
{
|
||||
return mFiMon->watchPeriod()/60 ;
|
||||
}
|
||||
|
||||
void ftServer::setRememberHashFiles(bool b)
|
||||
{
|
||||
mFiMon->setRememberHashCache(b) ;
|
||||
|
@ -205,6 +205,8 @@ virtual bool shareDownloadDirectory(bool share);
|
||||
virtual bool rememberHashFiles() const ;
|
||||
virtual void setRememberHashFiles(bool) ;
|
||||
virtual void clearHashCache() ;
|
||||
virtual void setWatchPeriod(int minutes) ;
|
||||
virtual int watchPeriod() const ;
|
||||
|
||||
/***************************************************************/
|
||||
/*************** Control Interface *****************************/
|
||||
|
@ -189,6 +189,10 @@ class RsFiles
|
||||
virtual void clearHashCache() = 0 ;
|
||||
virtual bool rememberHashFiles() const =0;
|
||||
virtual void setRememberHashFiles(bool) =0;
|
||||
virtual void setWatchPeriod(int minutes) =0;
|
||||
virtual int watchPeriod() const =0;
|
||||
|
||||
|
||||
|
||||
virtual bool getShareDownloadDirectory() = 0;
|
||||
virtual bool shareDownloadDirectory(bool share) = 0;
|
||||
|
@ -42,6 +42,11 @@ DirectoriesPage::DirectoriesPage(QWidget * parent, Qt::WFlags flags)
|
||||
ui.rememberHashesSB->setValue(t) ;
|
||||
ui.rememberHashesCB->setChecked(b) ;
|
||||
|
||||
int u = rsFiles->watchPeriod() ;
|
||||
ui.autoCheckDirectoriesDelay_SB->setValue(abs(u)) ;
|
||||
ui.autoCheckDirectories_CB->setChecked(u>0) ;
|
||||
ui.autoCheckDirectoriesDelay_SB->setEnabled(u>0) ;
|
||||
|
||||
connect(ui.incomingButton, SIGNAL(clicked( bool ) ), this , SLOT( setIncomingDirectory() ) );
|
||||
connect(ui.partialButton, SIGNAL(clicked( bool ) ), this , SLOT( setPartialsDirectory() ) );
|
||||
connect(ui.checkBox, SIGNAL(stateChanged(int)), this, SLOT(shareDownloadDirectory(int)));
|
||||
@ -49,6 +54,8 @@ DirectoriesPage::DirectoriesPage(QWidget * parent, Qt::WFlags flags)
|
||||
connect(ui.cleanHashCachePB, SIGNAL(clicked()), this, SLOT(clearHashCache()));
|
||||
connect(ui.rememberHashesCB, SIGNAL(toggled(bool)), this, SLOT(toggleRememberHashes(bool)));
|
||||
connect(ui.rememberHashesSB, SIGNAL(valueChanged(int)), this, SLOT(setRememberHashesDuration(int)));
|
||||
connect(ui.autoCheckDirectoriesDelay_SB, SIGNAL(valueChanged(int)), this, SLOT(setAutoCheckDirectoriesDelay(int)));
|
||||
connect(ui.autoCheckDirectories_CB, SIGNAL(toggled(bool)), this, SLOT(toggleAutoCheckDirectories(bool)));
|
||||
|
||||
/* Hide platform specific features */
|
||||
#ifdef Q_WS_WIN
|
||||
@ -56,6 +63,24 @@ DirectoriesPage::DirectoriesPage(QWidget * parent, Qt::WFlags flags)
|
||||
#endif
|
||||
}
|
||||
|
||||
void DirectoriesPage::setAutoCheckDirectoriesDelay(int b)
|
||||
{
|
||||
rsFiles->setWatchPeriod(ui.autoCheckDirectoriesDelay_SB->value()) ;
|
||||
}
|
||||
void DirectoriesPage::toggleAutoCheckDirectories(bool b)
|
||||
{
|
||||
if(!b)
|
||||
{
|
||||
rsFiles->setWatchPeriod(-ui.autoCheckDirectoriesDelay_SB->value()) ;
|
||||
ui.autoCheckDirectoriesDelay_SB->setEnabled(false) ;
|
||||
}
|
||||
else
|
||||
{
|
||||
rsFiles->setWatchPeriod(ui.autoCheckDirectoriesDelay_SB->value()) ;
|
||||
ui.autoCheckDirectoriesDelay_SB->setEnabled(true) ;
|
||||
}
|
||||
}
|
||||
|
||||
void DirectoriesPage::setRememberHashesDuration(int d)
|
||||
{
|
||||
rsFiles->setRememberHashFilesDuration(d) ;
|
||||
|
@ -49,6 +49,8 @@ class DirectoriesPage: public ConfigPage
|
||||
void clearHashCache() ;
|
||||
void setRememberHashesDuration(int) ;
|
||||
void toggleRememberHashes(bool) ;
|
||||
void setAutoCheckDirectoriesDelay(int) ;
|
||||
void toggleAutoCheckDirectories(bool) ;
|
||||
|
||||
private:
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>485</width>
|
||||
<height>439</height>
|
||||
<height>549</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
@ -684,6 +684,36 @@ you plug it in.</string>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="autoCheckDirectories_CB">
|
||||
<property name="text">
|
||||
<string>Auto-check shared directories every </string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="autoCheckDirectoriesDelay_SB">
|
||||
<property name="suffix">
|
||||
<string> minute(s)</string>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>5000</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>10</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
Loading…
Reference in New Issue
Block a user