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)
: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 */
}
@ -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 partial_dir_ss("PART_DIR");
const std::string share_dwl_dir("SHARE_DWL_DIR");
/* p3Config Interface */
@ -1323,6 +1325,7 @@ std::list<RsItem *> ftController::saveList(bool &cleanup)
/* basic control parameters */
configMap[download_dir_ss] = getDownloadDirectory();
configMap[partial_dir_ss] = getPartialsDirectory();
configMap[share_dwl_dir] = mShareDownloadDir ? "YES" : "NO";
RsConfigKeyValueSet *rskv = new RsConfigKeyValueSet();
@ -1462,6 +1465,27 @@ bool ftController::loadConfigMap(std::map<std::string, std::string> &configMap)
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;
}
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 *) ;
bool activate();
void setShareDownloadDirectory(bool value);
bool getShareDownloadDirectory();
virtual void run();
/***************************************************************/
@ -172,7 +175,6 @@ virtual std::list<RsItem *> saveList(bool &cleanup);
virtual bool loadList(std::list<RsItem *> load);
bool loadConfigMap(std::map<std::string, std::string> &configMap);
private:
/* RunTime Functions */
@ -218,6 +220,9 @@ bool setPeerState(ftTransferModule *tm, std::string id,
bool mFtActive;
bool mFtPendingDone;
std::list<ftPendingRequest> mPendingRequests;
/* share incoming directory */
bool mShareDownloadDir;
};
#endif

View File

@ -500,6 +500,27 @@ bool ftServer::removeSharedDirectory(std::string dir)
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 *******************/

View File

@ -169,6 +169,10 @@ virtual bool setSharedDirectories(std::list<std::string> &dirs);
virtual bool addSharedDirectory(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 *****************************/

View File

@ -157,6 +157,10 @@ virtual bool getSharedDirectories(std::list<std::string> &dirs) = 0;
virtual bool addSharedDirectory(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 "DirectoriesDialog.h"
#include <algorithm>
/** Constructor */
DirectoriesDialog::DirectoriesDialog(QWidget *parent)
@ -39,13 +40,21 @@ DirectoriesDialog::DirectoriesDialog(QWidget *parent)
connect(ui.removeButton, SIGNAL(clicked( bool ) ), this , SLOT( removeShareDirectory() ) );
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)));
ui.addButton->setToolTip(tr("Add a Share Directory"));
ui.removeButton->setToolTip(tr("Remove Shared Directory"));
ui.incomingButton->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 */
#ifdef Q_WS_WIN
@ -57,6 +66,26 @@ DirectoriesDialog::DirectoriesDialog(QWidget *parent)
bool
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;
}
@ -84,8 +113,6 @@ void DirectoriesDialog::load()
ui.partialsDir->setText(QString::fromStdString(rsFiles->getPartialsDirectory()));
listWidget->update(); /* update display */
}
void DirectoriesDialog::addShareDirectory()
@ -130,6 +157,17 @@ void DirectoriesDialog::setIncomingDirectory()
if (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();
}
@ -147,3 +185,24 @@ void DirectoriesDialog::setPartialsDirectory()
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 setIncomingDirectory();
void setPartialsDirectory();
void shareDownloadDirectory(int state);
private:

View File

@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DirectoriesDialog</class>
<widget class="QWidget" name="DirectoriesDialog">
@ -10,7 +11,7 @@
</rect>
</property>
<property name="sizePolicy">
<sizepolicy vsizetype="Expanding" hsizetype="Expanding" >
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
@ -502,22 +503,10 @@
<enum>Qt::NoContextMenu</enum>
</property>
<layout class="QGridLayout">
<property name="leftMargin" >
<property name="margin">
<number>6</number>
</property>
<property name="topMargin" >
<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" >
<property name="spacing">
<number>0</number>
</property>
<item row="0" column="0">
@ -526,7 +515,7 @@
<string>Shared Directories</string>
</property>
<layout class="QGridLayout">
<item rowspan="3" row="0" column="0" >
<item row="0" column="0" rowspan="3">
<widget class="QListWidget" name="dirList"/>
</item>
<item row="0" column="1">
@ -547,7 +536,8 @@
<string/>
</property>
<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 name="iconSize">
<size>
@ -575,7 +565,8 @@
<string/>
</property>
<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 name="iconSize">
<size>
@ -590,7 +581,7 @@
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" >
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>71</height>
@ -632,7 +623,8 @@
<string/>
</property>
<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 name="iconSize">
<size>
@ -642,6 +634,19 @@
</property>
</widget>
</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>
</widget>
</item>
@ -676,7 +681,8 @@
<string/>
</property>
<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 name="iconSize">
<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 removeSharedDirectory(std::string dir) = 0;
virtual void setShareDownloadDirectory(bool value) = 0;
virtual bool getShareDownloadDirectory() = 0;
virtual bool shareDownloadDirectory() = 0;
virtual bool unshareDownloadDirectory() = 0;
};