share of incoming directory by default

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1359 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
alexandrut 2009-07-12 13:22:31 +00:00
parent 49e9066afb
commit 990ed277bd
9 changed files with 440 additions and 312 deletions

View File

@ -78,7 +78,8 @@ ftFileControl::ftFileControl(std::string fname,
} }
ftController::ftController(CacheStrapper *cs, ftDataMultiplex *dm, std::string configDir) ftController::ftController(CacheStrapper *cs, ftDataMultiplex *dm, std::string configDir)
:CacheTransfer(cs), p3Config(CONFIG_TYPE_FT_CONTROL), mDataplex(dm), mFtActive(false),mTurtle(NULL) :CacheTransfer(cs), p3Config(CONFIG_TYPE_FT_CONTROL), mDataplex(dm), mFtActive(false),
mTurtle(NULL), mShareDownloadDir(true)
{ {
/* TODO */ /* TODO */
} }
@ -1293,6 +1294,7 @@ bool ftController::CancelCacheFile(RsPeerId id, std::string path, std::string ha
const std::string download_dir_ss("DOWN_DIR"); const std::string download_dir_ss("DOWN_DIR");
const std::string partial_dir_ss("PART_DIR"); const std::string partial_dir_ss("PART_DIR");
const std::string share_dwl_dir("SHARE_DWL_DIR");
/* p3Config Interface */ /* p3Config Interface */
@ -1323,6 +1325,7 @@ std::list<RsItem *> ftController::saveList(bool &cleanup)
/* basic control parameters */ /* basic control parameters */
configMap[download_dir_ss] = getDownloadDirectory(); configMap[download_dir_ss] = getDownloadDirectory();
configMap[partial_dir_ss] = getPartialsDirectory(); configMap[partial_dir_ss] = getPartialsDirectory();
configMap[share_dwl_dir] = mShareDownloadDir ? "YES" : "NO";
RsConfigKeyValueSet *rskv = new RsConfigKeyValueSet(); RsConfigKeyValueSet *rskv = new RsConfigKeyValueSet();
@ -1462,6 +1465,27 @@ bool ftController::loadConfigMap(std::map<std::string, std::string> &configMap)
setPartialsDirectory(mit->second); setPartialsDirectory(mit->second);
} }
if (configMap.end() != (mit = configMap.find(share_dwl_dir)))
{
if (mit->second == "YES")
{
setShareDownloadDirectory(true);
}
else if (mit->second == "NO")
{
setShareDownloadDirectory(false);
}
}
return true; return true;
} }
void ftController::setShareDownloadDirectory(bool value)
{
mShareDownloadDir = value;
}
bool ftController::getShareDownloadDirectory()
{
return mShareDownloadDir;
}

View File

@ -118,6 +118,9 @@ void setFtSearchNExtra(ftSearch *, ftExtraList *);
void setTurtleRouter(p3turtle *) ; void setTurtleRouter(p3turtle *) ;
bool activate(); bool activate();
void setShareDownloadDirectory(bool value);
bool getShareDownloadDirectory();
virtual void run(); virtual void run();
/***************************************************************/ /***************************************************************/
@ -172,7 +175,6 @@ virtual std::list<RsItem *> saveList(bool &cleanup);
virtual bool loadList(std::list<RsItem *> load); virtual bool loadList(std::list<RsItem *> load);
bool loadConfigMap(std::map<std::string, std::string> &configMap); bool loadConfigMap(std::map<std::string, std::string> &configMap);
private: private:
/* RunTime Functions */ /* RunTime Functions */
@ -218,6 +220,9 @@ bool setPeerState(ftTransferModule *tm, std::string id,
bool mFtActive; bool mFtActive;
bool mFtPendingDone; bool mFtPendingDone;
std::list<ftPendingRequest> mPendingRequests; std::list<ftPendingRequest> mPendingRequests;
/* share incoming directory */
bool mShareDownloadDir;
}; };
#endif #endif

View File

@ -500,6 +500,27 @@ bool ftServer::removeSharedDirectory(std::string dir)
return true; return true;
} }
void ftServer::setShareDownloadDirectory(bool value)
{
mFtController->setShareDownloadDirectory(value);
}
bool ftServer::getShareDownloadDirectory()
{
return mFtController->getShareDownloadDirectory();
}
bool ftServer::shareDownloadDirectory()
{
std::string dir = mFtController->getDownloadDirectory();
return addSharedDirectory(dir);
}
bool ftServer::unshareDownloadDirectory()
{
std::string dir = mFtController->getDownloadDirectory();
return removeSharedDirectory(dir);
}
/***************************************************************/ /***************************************************************/
/****************** End of RsFiles Interface *******************/ /****************** End of RsFiles Interface *******************/

View File

@ -169,6 +169,10 @@ virtual bool setSharedDirectories(std::list<std::string> &dirs);
virtual bool addSharedDirectory(std::string dir); virtual bool addSharedDirectory(std::string dir);
virtual bool removeSharedDirectory(std::string dir); virtual bool removeSharedDirectory(std::string dir);
virtual void setShareDownloadDirectory(bool value);
virtual bool getShareDownloadDirectory();
virtual bool shareDownloadDirectory();
virtual bool unshareDownloadDirectory();
/***************************************************************/ /***************************************************************/
/*************** Control Interface *****************************/ /*************** Control Interface *****************************/

View File

@ -157,6 +157,10 @@ virtual bool getSharedDirectories(std::list<std::string> &dirs) = 0;
virtual bool addSharedDirectory(std::string dir) = 0; virtual bool addSharedDirectory(std::string dir) = 0;
virtual bool removeSharedDirectory(std::string dir) = 0; virtual bool removeSharedDirectory(std::string dir) = 0;
virtual void setShareDownloadDirectory(bool value) = 0;
virtual bool getShareDownloadDirectory() = 0;
virtual bool shareDownloadDirectory() = 0;
virtual bool unshareDownloadDirectory() = 0;
}; };

View File

@ -24,6 +24,7 @@
#include "rsiface/rsfiles.h" #include "rsiface/rsfiles.h"
#include "DirectoriesDialog.h" #include "DirectoriesDialog.h"
#include <algorithm>
/** Constructor */ /** Constructor */
DirectoriesDialog::DirectoriesDialog(QWidget *parent) DirectoriesDialog::DirectoriesDialog(QWidget *parent)
@ -39,13 +40,21 @@ DirectoriesDialog::DirectoriesDialog(QWidget *parent)
connect(ui.removeButton, SIGNAL(clicked( bool ) ), this , SLOT( removeShareDirectory() ) ); connect(ui.removeButton, SIGNAL(clicked( bool ) ), this , SLOT( removeShareDirectory() ) );
connect(ui.incomingButton, SIGNAL(clicked( bool ) ), this , SLOT( setIncomingDirectory() ) ); connect(ui.incomingButton, SIGNAL(clicked( bool ) ), this , SLOT( setIncomingDirectory() ) );
connect(ui.partialButton, SIGNAL(clicked( bool ) ), this , SLOT( setPartialsDirectory() ) ); connect(ui.partialButton, SIGNAL(clicked( bool ) ), this , SLOT( setPartialsDirectory() ) );
connect(ui.checkBox, SIGNAL(stateChanged(int)), this, SLOT(shareDownloadDirectory(int)));
ui.addButton->setToolTip(tr("Add a Share Directory")); ui.addButton->setToolTip(tr("Add a Share Directory"));
ui.removeButton->setToolTip(tr("Remove Shared Directory")); ui.removeButton->setToolTip(tr("Remove Shared Directory"));
ui.incomingButton->setToolTip(tr("Browse")); ui.incomingButton->setToolTip(tr("Browse"));
ui.partialButton->setToolTip(tr("Browse")); ui.partialButton->setToolTip(tr("Browse"));
if (rsFiles->getShareDownloadDirectory())
{
ui.checkBox->setDown(true); /* signal not emitted */
}
else
{
ui.checkBox->setDown(false); /* signal not emitted */
}
/* Hide platform specific features */ /* Hide platform specific features */
#ifdef Q_WS_WIN #ifdef Q_WS_WIN
@ -57,6 +66,26 @@ DirectoriesDialog::DirectoriesDialog(QWidget *parent)
bool bool
DirectoriesDialog::save(QString &errmsg) DirectoriesDialog::save(QString &errmsg)
{ {
/* this is usefull especially when shared incoming files is
* default option and when the user don't check/uncheck the
* checkBox, so no signal is emitted to update the shared list */
if (ui.checkBox->isChecked())
{
std::list<std::string>::const_iterator it;
std::list<std::string> dirs;
rsFiles->getSharedDirectories(dirs);
if (dirs.end() == std::find(dirs.begin(), dirs.end(), rsFiles->getDownloadDirectory()))
{
rsFiles->shareDownloadDirectory();
}
rsFiles->setShareDownloadDirectory(true);
}
else
{
rsFiles->unshareDownloadDirectory();
rsFiles->setShareDownloadDirectory(false);
}
return true; return true;
} }
@ -84,8 +113,6 @@ void DirectoriesDialog::load()
ui.partialsDir->setText(QString::fromStdString(rsFiles->getPartialsDirectory())); ui.partialsDir->setText(QString::fromStdString(rsFiles->getPartialsDirectory()));
listWidget->update(); /* update display */ listWidget->update(); /* update display */
} }
void DirectoriesDialog::addShareDirectory() void DirectoriesDialog::addShareDirectory()
@ -130,6 +157,17 @@ void DirectoriesDialog::setIncomingDirectory()
if (dir != "") if (dir != "")
{ {
rsFiles->setDownloadDirectory(dir); rsFiles->setDownloadDirectory(dir);
if (ui.checkBox->isChecked())
{
std::list<std::string>::const_iterator it;
std::list<std::string> dirs;
rsFiles->getSharedDirectories(dirs);
if (dirs.end() == std::find(dirs.begin(), dirs.end(), rsFiles->getDownloadDirectory()))
{
rsFiles->shareDownloadDirectory();
}
}
} }
load(); load();
} }
@ -147,3 +185,24 @@ void DirectoriesDialog::setPartialsDirectory()
load(); load();
} }
void DirectoriesDialog::shareDownloadDirectory(int state)
{
if (state == Qt::Checked)
{
std::list<std::string>::const_iterator it;
std::list<std::string> dirs;
rsFiles->getSharedDirectories(dirs);
if (dirs.end() == std::find(dirs.begin(), dirs.end(), rsFiles->getDownloadDirectory()))
{
rsFiles->shareDownloadDirectory();
}
rsFiles->setShareDownloadDirectory(true);
}
else
{
rsFiles->unshareDownloadDirectory();
rsFiles->setShareDownloadDirectory(false);
}
load();
}

View File

@ -49,6 +49,7 @@ private slots:
void removeShareDirectory(); void removeShareDirectory();
void setIncomingDirectory(); void setIncomingDirectory();
void setPartialsDirectory(); void setPartialsDirectory();
void shareDownloadDirectory(int state);
private: private:

View File

@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<class>DirectoriesDialog</class> <class>DirectoriesDialog</class>
<widget class="QWidget" name="DirectoriesDialog"> <widget class="QWidget" name="DirectoriesDialog">
@ -10,7 +11,7 @@
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy vsizetype="Expanding" hsizetype="Expanding" > <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
@ -502,22 +503,10 @@
<enum>Qt::NoContextMenu</enum> <enum>Qt::NoContextMenu</enum>
</property> </property>
<layout class="QGridLayout"> <layout class="QGridLayout">
<property name="leftMargin" > <property name="margin">
<number>6</number> <number>6</number>
</property> </property>
<property name="topMargin" > <property name="spacing">
<number>6</number>
</property>
<property name="rightMargin" >
<number>6</number>
</property>
<property name="bottomMargin" >
<number>6</number>
</property>
<property name="horizontalSpacing" >
<number>0</number>
</property>
<property name="verticalSpacing" >
<number>0</number> <number>0</number>
</property> </property>
<item row="0" column="0"> <item row="0" column="0">
@ -526,7 +515,7 @@
<string>Shared Directories</string> <string>Shared Directories</string>
</property> </property>
<layout class="QGridLayout"> <layout class="QGridLayout">
<item rowspan="3" row="0" column="0" > <item row="0" column="0" rowspan="3">
<widget class="QListWidget" name="dirList"/> <widget class="QListWidget" name="dirList"/>
</item> </item>
<item row="0" column="1"> <item row="0" column="1">
@ -547,7 +536,8 @@
<string/> <string/>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="../images.qrc" >:/images/directoryadd_24x24_shadow.png</iconset> <iconset resource="../images.qrc">
<normaloff>:/images/directoryadd_24x24_shadow.png</normaloff>:/images/directoryadd_24x24_shadow.png</iconset>
</property> </property>
<property name="iconSize"> <property name="iconSize">
<size> <size>
@ -575,7 +565,8 @@
<string/> <string/>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="../images.qrc" >:/images/directoryremove_24x24_shadow.png</iconset> <iconset resource="../images.qrc">
<normaloff>:/images/directoryremove_24x24_shadow.png</normaloff>:/images/directoryremove_24x24_shadow.png</iconset>
</property> </property>
<property name="iconSize"> <property name="iconSize">
<size> <size>
@ -590,7 +581,7 @@
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
</property> </property>
<property name="sizeHint" > <property name="sizeHint" stdset="0">
<size> <size>
<width>20</width> <width>20</width>
<height>71</height> <height>71</height>
@ -632,7 +623,8 @@
<string/> <string/>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="../images.qrc" >:/images/directoryselect_24x24_shadow.png</iconset> <iconset resource="../images.qrc">
<normaloff>:/images/directoryselect_24x24_shadow.png</normaloff>:/images/directoryselect_24x24_shadow.png</iconset>
</property> </property>
<property name="iconSize"> <property name="iconSize">
<size> <size>
@ -642,6 +634,19 @@
</property> </property>
</widget> </widget>
</item> </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 (Recommanded)</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
@ -676,7 +681,8 @@
<string/> <string/>
</property> </property>
<property name="icon"> <property name="icon">
<iconset resource="../images.qrc" >:/images/directoryselect_24x24_shadow.png</iconset> <iconset resource="../images.qrc">
<normaloff>:/images/directoryselect_24x24_shadow.png</normaloff>:/images/directoryselect_24x24_shadow.png</iconset>
</property> </property>
<property name="iconSize"> <property name="iconSize">
<size> <size>

View File

@ -157,6 +157,10 @@ virtual bool getSharedDirectories(std::list<std::string> &dirs) = 0;
virtual bool addSharedDirectory(std::string dir) = 0; virtual bool addSharedDirectory(std::string dir) = 0;
virtual bool removeSharedDirectory(std::string dir) = 0; virtual bool removeSharedDirectory(std::string dir) = 0;
virtual void setShareDownloadDirectory(bool value) = 0;
virtual bool getShareDownloadDirectory() = 0;
virtual bool shareDownloadDirectory() = 0;
virtual bool unshareDownloadDirectory() = 0;
}; };