added an optional cache for hashes, so that hashed files are remembered for some days.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3729 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2010-10-31 20:35:31 +00:00
parent 5cc222d251
commit 630156a5e8
11 changed files with 493 additions and 45 deletions

View file

@ -115,7 +115,6 @@ private:
QAction* sendchatlinkAct;
QAction* copylinklocalhtmlAct;
QTreeView *shareddirtreeview;
/** Qt Designer generated object */
Ui::SharedFilesDialog ui;

View file

@ -21,6 +21,7 @@
#include "DirectoriesPage.h"
#include "gui/ShareManager.h"
#include <QMessageBox>
#include "rshare.h"
#include <retroshare/rsfiles.h>
@ -52,10 +53,19 @@ DirectoriesPage::DirectoriesPage(QWidget * parent, Qt::WFlags flags)
ui.checkBox->setChecked(false); /* signal not emitted */
}
uint32_t t = rsFiles->rememberHashFilesDuration() ;
bool b = rsFiles->rememberHashFiles() ;
ui.rememberHashesSB->setValue(t) ;
ui.rememberHashesCB->setChecked(b) ;
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)));
connect(ui.editButton, SIGNAL(clicked()), this, SLOT(editDirectories()));
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)));
/* Hide platform specific features */
#ifdef Q_WS_WIN
@ -63,6 +73,40 @@ DirectoriesPage::DirectoriesPage(QWidget * parent, Qt::WFlags flags)
#endif
}
void DirectoriesPage::setRememberHashesDuration(int d)
{
rsFiles->setRememberHashFilesDuration(d) ;
}
void DirectoriesPage::toggleRememberHashes(bool b)
{
if(!b)
{
if(QMessageBox::question(NULL,"Cache cleaning confirmation","The will forget any former hash of non shared files. Do you confirm ?") == QMessageBox::Ok)
{
rsFiles->clearHashCache() ;
rsFiles->setRememberHashFiles(b) ;
ui.rememberHashesSB->setEnabled(false) ;
ui.cleanHashCachePB->setEnabled(false) ;
}
else
ui.rememberHashesCB->setChecked(true) ;
}
else
{
rsFiles->setRememberHashFiles(true) ;
ui.rememberHashesSB->setEnabled(true) ;
ui.cleanHashCachePB->setEnabled(true) ;
}
}
void DirectoriesPage::clearHashCache()
{
if(QMessageBox::question(NULL,"Cache cleaning confirmation","The will forget any former hash of non shared files. Do you confirm ?", QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok)
rsFiles->clearHashCache() ;
}
void
DirectoriesPage::closeEvent (QCloseEvent * event)
{

View file

@ -42,15 +42,13 @@ class DirectoriesPage: public ConfigPage
private slots:
#ifdef TO_REMOVE
void addShareDirectory();
void removeShareDirectory();
#endif
void editDirectories() ;
void setIncomingDirectory();
void setPartialsDirectory();
void shareDownloadDirectory(int state);
void clearHashCache() ;
void setRememberHashesDuration(int) ;
void toggleRememberHashes(bool) ;
private:

View file

@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>477</width>
<width>483</width>
<height>439</height>
</rect>
</property>
@ -604,29 +604,96 @@
<property name="title">
<string>Shared Directories</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="2">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QListWidget" name="dirList"/>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="checkBox">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Automatically share incoming directory (Recommended)</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QCheckBox" name="checkBox">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Automatically share incoming directory (Recommended)</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="editButton">
<property name="text">
<string>Edit Share</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="editButton">
<property name="text">
<string>Edit Share</string>
</property>
</widget>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QCheckBox" name="rememberHashesCB">
<property name="toolTip">
<string>&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans'; font-size:10pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p align=&quot;justify&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Remember file hashes even if not shared. &lt;/p&gt;
&lt;p align=&quot;justify&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;This might be useful if you're sharing an &lt;/p&gt;
&lt;p align=&quot;justify&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;external HD, to avoid re-hashing files when &lt;/p&gt;
&lt;p align=&quot;justify&quot; style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;you plug it in.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Remember hashed files for </string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="rememberHashesSB">
<property name="suffix">
<string> days</string>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>365</number>
</property>
<property name="value">
<number>10</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="cleanHashCachePB">
<property name="toolTip">
<string>Forget any hashed file that is not anymore shared.</string>
</property>
<property name="text">
<string>Clean Hash Cache</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>