diff --git a/libretroshare/src/ft/ftcontroller.cc b/libretroshare/src/ft/ftcontroller.cc index 68f9e4bf2..f6c740253 100644 --- a/libretroshare/src/ft/ftcontroller.cc +++ b/libretroshare/src/ft/ftcontroller.cc @@ -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 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 &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; +} diff --git a/libretroshare/src/ft/ftcontroller.h b/libretroshare/src/ft/ftcontroller.h index 5e7ae79f7..1662aa67e 100644 --- a/libretroshare/src/ft/ftcontroller.h +++ b/libretroshare/src/ft/ftcontroller.h @@ -26,7 +26,7 @@ #ifndef FT_CONTROLLER_HEADER #define FT_CONTROLLER_HEADER -/* +/* * ftController * * Top level download controller. @@ -69,8 +69,8 @@ class ftFileControl enum {DOWNLOADING,COMPLETED,ERROR_COMPLETION}; ftFileControl(); - ftFileControl(std::string fname, std::string tmppath, std::string dest, - uint64_t size, std::string hash, uint32_t flags, + ftFileControl(std::string fname, std::string tmppath, std::string dest, + uint64_t size, std::string hash, uint32_t flags, ftFileCreator *fc, ftTransferModule *tm, uint32_t cb_flags); std::string mName; @@ -118,14 +118,17 @@ void setFtSearchNExtra(ftSearch *, ftExtraList *); void setTurtleRouter(p3turtle *) ; bool activate(); +void setShareDownloadDirectory(bool value); +bool getShareDownloadDirectory(); + virtual void run(); /***************************************************************/ /********************** Controller Access **********************/ /***************************************************************/ -bool FileRequest(std::string fname, std::string hash, - uint64_t size, std::string dest, uint32_t flags, +bool FileRequest(std::string fname, std::string hash, + uint64_t size, std::string dest, uint32_t flags, std::list &sourceIds); bool FileCancel(std::string hash); @@ -151,7 +154,7 @@ bool moveFile(const std::string& source,const std::string& dest) ; protected: -virtual bool RequestCacheFile(RsPeerId id, std::string path, std::string hash, uint64_t size); +virtual bool RequestCacheFile(RsPeerId id, std::string path, std::string hash, uint64_t size); virtual bool CancelCacheFile(RsPeerId id, std::string path, std::string hash, uint64_t size); /***************************************************************/ @@ -172,7 +175,6 @@ virtual std::list saveList(bool &cleanup); virtual bool loadList(std::list load); bool loadConfigMap(std::map &configMap); - private: /* RunTime Functions */ @@ -185,7 +187,7 @@ bool setPeerState(ftTransferModule *tm, std::string id, /* pointers to other components */ - ftSearch *mSearch; + ftSearch *mSearch; ftDataMultiplex *mDataplex; ftExtraList *mExtraList; p3turtle *mTurtle ; @@ -218,6 +220,9 @@ bool setPeerState(ftTransferModule *tm, std::string id, bool mFtActive; bool mFtPendingDone; std::list mPendingRequests; + + /* share incoming directory */ + bool mShareDownloadDir; }; #endif diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index 45b9c7cda..2d5df009f 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -203,17 +203,17 @@ void ftServer::run() { if ((now - info.lastTS) > 10) { -#ifdef SERVER_DEBUG +#ifdef SERVER_DEBUG std::cout << "info.lastTS = " << info.lastTS << ", now=" << now << std::endl ; #endif toDels.push_back(sit->first); } - } + } } if(!toDels.empty()) mFtDataplex->deleteServers(toDels) ; - + #ifdef WIN32 Sleep(1000); #else @@ -232,11 +232,11 @@ void ftServer::run() /********************** Controller Access **********************/ /***************************************************************/ -bool ftServer::FileRequest(std::string fname, std::string hash, uint64_t size, +bool ftServer::FileRequest(std::string fname, std::string hash, uint64_t size, std::string dest, uint32_t flags, std::list srcIds) { std::cerr << "Requesting " << fname << std::endl ; - return mFtController->FileRequest(fname, hash, size, + return mFtController->FileRequest(fname, hash, size, dest, flags, srcIds); } @@ -320,7 +320,7 @@ bool ftServer::FileDetails(std::string hash, uint32_t hintflags, FileInfo &info) /******************* ExtraFileList Access **********************/ /***************************************************************/ -bool ftServer::ExtraFileAdd(std::string fname, std::string hash, uint64_t size, +bool ftServer::ExtraFileAdd(std::string fname, std::string hash, uint64_t size, uint32_t period, uint32_t flags) { return mFtExtra->addExtraFile(fname, hash, size, period, flags); @@ -354,7 +354,7 @@ bool ftServer::ExtraFileMove(std::string fname, std::string hash, uint64_t size, int ftServer::RequestDirDetails(std::string uid, std::string path, DirDetails &details) { -#ifdef SERVER_DEBUG +#ifdef SERVER_DEBUG std::cerr << "ftServer::RequestDirDetails(uid:" << uid; std::cerr << ", path:" << path << ", ...) -> mFiStore"; std::cerr << std::endl; @@ -367,10 +367,10 @@ int ftServer::RequestDirDetails(std::string uid, std::string path, DirDetails &d #endif return mFiStore->RequestDirDetails(uid, path, details); } - + int ftServer::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags) { -#ifdef SERVER_DEBUG +#ifdef SERVER_DEBUG std::cerr << "ftServer::RequestDirDetails(ref:" << ref; std::cerr << ", flags:" << flags << ", ...) -> mFiStore"; std::cerr << std::endl; @@ -384,7 +384,7 @@ int ftServer::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags) #endif return mFiStore->RequestDirDetails(ref, details, flags); } - + /***************************************************************/ /******************** Search Interface *************************/ /***************************************************************/ @@ -392,7 +392,7 @@ int ftServer::RequestDirDetails(void *ref, DirDetails &details, uint32_t flags) int ftServer::SearchKeywords(std::list keywords, std::list &results,uint32_t flags) { -#ifdef SERVER_DEBUG +#ifdef SERVER_DEBUG std::cerr << "ftServer::SearchKeywords()"; std::cerr << std::endl; @@ -405,33 +405,33 @@ int ftServer::SearchKeywords(std::list keywords, std::listSearchKeywords(keywords, results,flags); } - + int ftServer::SearchBoolExp(Expression * exp, std::list &results) { return mFiStore->searchBoolExp(exp, results); } - + /***************************************************************/ /*************** Local Shared Dir Interface ********************/ /***************************************************************/ - + bool ftServer::ConvertSharedFilePath(std::string path, std::string &fullpath) { return mFiMon->convertSharedFilePath(path, fullpath); } - + void ftServer::ForceDirectoryCheck() { mFiMon->forceDirectoryCheck(); return; } - + bool ftServer::InDirectoryCheck() { return mFiMon->inDirectoryCheck(); } - + bool ftServer::getSharedDirectories(std::list &dirs) { mFiMon->getSharedDirectories(dirs); @@ -459,14 +459,14 @@ bool ftServer::removeSharedDirectory(std::string dir) std::list dirList; std::list::iterator it; -#ifdef SERVER_DEBUG +#ifdef SERVER_DEBUG std::cerr << "ftServer::removeSharedDirectory(" << dir << ")"; std::cerr << std::endl; #endif mFiMon->getSharedDirectories(dirList); -#ifdef SERVER_DEBUG +#ifdef SERVER_DEBUG for(it = dirList.begin(); it != dirList.end(); it++) { std::cerr << "ftServer::removeSharedDirectory()"; @@ -475,10 +475,10 @@ bool ftServer::removeSharedDirectory(std::string dir) } #endif - if (dirList.end() == (it = + if (dirList.end() == (it = std::find(dirList.begin(), dirList.end(), dir))) { -#ifdef SERVER_DEBUG +#ifdef SERVER_DEBUG std::cerr << "ftServer::removeSharedDirectory()"; std::cerr << " Cannot Find Directory... Fail"; std::cerr << std::endl; @@ -488,7 +488,7 @@ bool ftServer::removeSharedDirectory(std::string dir) } -#ifdef SERVER_DEBUG +#ifdef SERVER_DEBUG std::cerr << "ftServer::removeSharedDirectory()"; std::cerr << " Updating Directories"; std::cerr << std::endl; @@ -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 *******************/ @@ -538,7 +559,7 @@ bool ftServer::loadConfigMap(std::map &configMap) /***************************************************************/ /* Client Send */ -bool ftServer::sendDataRequest(std::string peerId, std::string hash, +bool ftServer::sendDataRequest(std::string peerId, std::string hash, uint64_t size, uint64_t offset, uint32_t chunksize) { if(mTurtleRouter->isTurtlePeer(peerId)) @@ -579,7 +600,7 @@ bool ftServer::sendData(std::string peerId, std::string hash, uint64_t size, uin uint64_t offset = 0; uint32_t chunk; -#ifdef SERVER_DEBUG +#ifdef SERVER_DEBUG std::cerr << "ftServer::sendData() to " << peerId << std::endl; std::cerr << "hash: " << hash; std::cerr << " offset: " << baseoffset; @@ -624,7 +645,7 @@ bool ftServer::sendData(std::string peerId, std::string hash, uint64_t size, uin mP3iface->SendFileData(rfd); /* print the data pointer */ -#ifdef SERVER_DEBUG +#ifdef SERVER_DEBUG std::cerr << "ftServer::sendData() Packet: " << std::endl; std::cerr << " offset: " << rfd->fd.file_offset; std::cerr << " chunk: " << chunk; @@ -651,7 +672,7 @@ bool ftServer::sendData(std::string peerId, std::string hash, uint64_t size, uin */ int ftServer::tick() { - rslog(RSL_DEBUG_BASIC, ftserverzone, + rslog(RSL_DEBUG_BASIC, ftserverzone, "filedexserver::tick()"); if (mP3iface == NULL) @@ -661,7 +682,7 @@ int ftServer::tick() #endif std::ostringstream out; - rslog(RSL_DEBUG_BASIC, ftserverzone, + rslog(RSL_DEBUG_BASIC, ftserverzone, "filedexserver::tick() Invalid Interface()"); return 1; @@ -712,13 +733,13 @@ bool ftServer::handleCacheData() int i = 0; int i_init = 0; -#ifdef SERVER_DEBUG +#ifdef SERVER_DEBUG //std::cerr << "ftServer::handleCacheData()" << std::endl; #endif while((ci = mP3iface -> GetSearchResult()) != NULL) { -#ifdef SERVER_DEBUG +#ifdef SERVER_DEBUG std::cerr << "ftServer::handleCacheData() Recvd SearchResult (CacheResponse!)" << std::endl; std::ostringstream out; if (i++ == i_init) @@ -747,7 +768,7 @@ bool ftServer::handleCacheData() i_init = i; while((cr = mP3iface -> RequestedSearch()) != NULL) { -#ifdef SERVER_DEBUG +#ifdef SERVER_DEBUG /* just delete these */ std::ostringstream out; out << "Requested Search:" << std::endl; @@ -758,7 +779,7 @@ bool ftServer::handleCacheData() } - // Now handle it replacement (pushed cache results) + // Now handle it replacement (pushed cache results) { std::list > cacheUpdates; std::list >::iterator it; @@ -768,7 +789,7 @@ bool ftServer::handleCacheData() { /* construct reply */ RsCacheItem *ci = new RsCacheItem(); - + /* id from incoming */ ci -> PeerId(it->first); @@ -779,7 +800,7 @@ bool ftServer::handleCacheData() ci -> cacheType = (it->second).cid.type; ci -> cacheSubId = (it->second).cid.subid; -#ifdef SERVER_DEBUG +#ifdef SERVER_DEBUG std::ostringstream out2; out2 << "Outgoing CacheStrapper Update -> RsCacheItem:" << std::endl; ci -> print(out2); @@ -788,7 +809,7 @@ bool ftServer::handleCacheData() //rslog(RSL_DEBUG_BASIC, ftserverzone, out2.str()); mP3iface -> SendSearchResult(ci); - + i++; } } @@ -808,7 +829,7 @@ bool ftServer::handleFileData() i_init = i; while((fr = mP3iface -> GetFileRequest()) != NULL ) { -#ifdef SERVER_DEBUG +#ifdef SERVER_DEBUG std::cerr << "ftServer::handleFileData() Recvd ftFiler Request" << std::endl; std::ostringstream out; if (i == i_init) @@ -820,8 +841,8 @@ bool ftServer::handleFileData() #endif i++; /* count */ - mFtDataplex->recvDataRequest(fr->PeerId(), - fr->file.hash, fr->file.filesize, + mFtDataplex->recvDataRequest(fr->PeerId(), + fr->file.hash, fr->file.filesize, fr->fileoffset, fr->chunksize); FileInfo(ffr); @@ -832,7 +853,7 @@ FileInfo(ffr); i_init = i; while((fd = mP3iface -> GetFileData()) != NULL ) { -#ifdef SERVER_DEBUG +#ifdef SERVER_DEBUG std::cerr << "ftServer::handleFileData() Recvd ftFiler Data" << std::endl; std::cerr << "hash: " << fd->fd.file.hash; std::cerr << " length: " << fd->fd.binData.bin_len; @@ -851,12 +872,12 @@ FileInfo(ffr); /* incoming data */ mFtDataplex->recvData(fd->PeerId(), - fd->fd.file.hash, fd->fd.file.filesize, - fd->fd.file_offset, - fd->fd.binData.bin_len, + fd->fd.file.hash, fd->fd.file.filesize, + fd->fd.file_offset, + fd->fd.binData.bin_len, fd->fd.binData.bin_data); - /* we've stolen the data part -> so blank before delete + /* we've stolen the data part -> so blank before delete */ fd->fd.binData.TlvShallowClear(); delete fd; @@ -882,7 +903,7 @@ bool ftServer::addConfiguration(p3ConfigMgr *cfgmgr) cfgmgr->addConfiguration("ft_shared.cfg", mFiMon); cfgmgr->addConfiguration("ft_extra.cfg", mFtExtra); cfgmgr->addConfiguration("ft_transfers.cfg", mFtController); - + return true; } diff --git a/libretroshare/src/ft/ftserver.h b/libretroshare/src/ft/ftserver.h index f7a1bf10a..96a3e9e39 100644 --- a/libretroshare/src/ft/ftserver.h +++ b/libretroshare/src/ft/ftserver.h @@ -26,7 +26,7 @@ #ifndef FT_SERVER_HEADER #define FT_SERVER_HEADER -/* +/* * ftServer. * * Top level File Transfer interface. @@ -114,14 +114,14 @@ ftController *getController() const { return mFtController ; } /*** * Control of Downloads ***/ -virtual bool FileRequest(std::string fname, std::string hash, uint64_t size, +virtual bool FileRequest(std::string fname, std::string hash, uint64_t size, std::string dest, uint32_t flags, std::list srcIds); virtual bool FileCancel(std::string hash); virtual bool FileControl(std::string hash, uint32_t flags); virtual bool FileClearCompleted(); /*** - * Download/Upload Details + * Download/Upload Details ***/ virtual bool FileDownloads(std::list &hashs); virtual bool FileUploads(std::list &hashs); @@ -130,10 +130,10 @@ virtual bool FileDetails(std::string hash, uint32_t hintflags, FileInfo &info); /*** * Extra List Access ***/ -virtual bool ExtraFileAdd(std::string fname, std::string hash, uint64_t size, +virtual bool ExtraFileAdd(std::string fname, std::string hash, uint64_t size, uint32_t period, uint32_t flags); virtual bool ExtraFileRemove(std::string hash, uint32_t flags); -virtual bool ExtraFileHash(std::string localpath, +virtual bool ExtraFileHash(std::string localpath, uint32_t period, uint32_t flags); virtual bool ExtraFileStatus(std::string localpath, FileInfo &info); virtual bool ExtraFileMove(std::string fname, std::string hash, uint64_t size, @@ -150,14 +150,14 @@ virtual int SearchKeywords(std::list keywords, std::list &results); /*** - * Utility Functions + * Utility Functions ***/ virtual bool ConvertSharedFilePath(std::string path, std::string &fullpath); virtual void ForceDirectoryCheck(); virtual bool InDirectoryCheck(); /*** - * Directory Handling + * Directory Handling ***/ virtual void setDownloadDirectory(std::string path); virtual void setPartialsDirectory(std::string path); @@ -169,6 +169,10 @@ virtual bool setSharedDirectories(std::list &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 *****************************/ @@ -180,7 +184,7 @@ virtual bool removeSharedDirectory(std::string dir); public: virtual bool sendData(std::string peerId, std::string hash, uint64_t size, uint64_t offset, uint32_t chunksize, void *data); -virtual bool sendDataRequest(std::string peerId, +virtual bool sendDataRequest(std::string peerId, std::string hash, uint64_t size, uint64_t offset, uint32_t chunksize); @@ -217,7 +221,7 @@ bool loadConfigMap(std::map &configMap); private: - /* no need for Mutex protection - + /* no need for Mutex protection - * as each component is protected independently. */ diff --git a/libretroshare/src/rsiface/rsfiles.h b/libretroshare/src/rsiface/rsfiles.h index aed7177df..62d3e9a1f 100644 --- a/libretroshare/src/rsiface/rsfiles.h +++ b/libretroshare/src/rsiface/rsfiles.h @@ -55,7 +55,7 @@ const uint32_t RS_FILE_PEER_OFFLINE = 0x00002000; /************************************ * Used To indicate where to search. * - * The Order of these is very important, + * The Order of these is very important, * it specifies the search order too. * */ @@ -101,13 +101,13 @@ virtual ~RsFiles() { return; } /*** * Control of Downloads. ***/ -virtual bool FileRequest(std::string fname, std::string hash, uint64_t size, +virtual bool FileRequest(std::string fname, std::string hash, uint64_t size, std::string dest, uint32_t flags, std::list srcIds) = 0; virtual bool FileCancel(std::string hash) = 0; virtual bool FileControl(std::string hash, uint32_t flags) = 0; virtual bool FileClearCompleted() = 0; -/*** +/*** * Download / Upload Details. ***/ virtual bool FileDownloads(std::list &hashs) = 0; @@ -121,7 +121,7 @@ virtual bool FileDetails(std::string hash, uint32_t hintflags, FileInfo &info) = virtual bool ExtraFileAdd(std::string fname, std::string hash, uint64_t size, uint32_t period, uint32_t flags) = 0; virtual bool ExtraFileRemove(std::string hash, uint32_t flags) = 0; -virtual bool ExtraFileHash(std::string localpath, +virtual bool ExtraFileHash(std::string localpath, uint32_t period, uint32_t flags) = 0; virtual bool ExtraFileStatus(std::string localpath, FileInfo &info) = 0; virtual bool ExtraFileMove(std::string fname, std::string hash, uint64_t size, @@ -157,6 +157,10 @@ virtual bool getSharedDirectories(std::list &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; }; diff --git a/retroshare-gui/src/gui/Preferences/DirectoriesDialog.cpp b/retroshare-gui/src/gui/Preferences/DirectoriesDialog.cpp index 67d7d3e15..4c8fa5789 100644 --- a/retroshare-gui/src/gui/Preferences/DirectoriesDialog.cpp +++ b/retroshare-gui/src/gui/Preferences/DirectoriesDialog.cpp @@ -24,6 +24,7 @@ #include "rsiface/rsfiles.h" #include "DirectoriesDialog.h" +#include /** 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")); - + 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::const_iterator it; + std::list 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::const_iterator it; + std::list 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::const_iterator it; + std::list 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(); +} diff --git a/retroshare-gui/src/gui/Preferences/DirectoriesDialog.h b/retroshare-gui/src/gui/Preferences/DirectoriesDialog.h index 2fd06b6d0..6cfa54b38 100644 --- a/retroshare-gui/src/gui/Preferences/DirectoriesDialog.h +++ b/retroshare-gui/src/gui/Preferences/DirectoriesDialog.h @@ -15,7 +15,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. ****************************************************************/ @@ -29,7 +29,7 @@ #include "configpage.h" #include "ui_DirectoriesDialog.h" -class DirectoriesDialog : public ConfigPage +class DirectoriesDialog : public ConfigPage { Q_OBJECT @@ -49,8 +49,9 @@ private slots: void removeShareDirectory(); void setIncomingDirectory(); void setPartialsDirectory(); + void shareDownloadDirectory(int state); + - private: /** A RshareSettings object used for saving/loading settings */ RshareSettings* _settings; diff --git a/retroshare-gui/src/gui/Preferences/DirectoriesDialog.ui b/retroshare-gui/src/gui/Preferences/DirectoriesDialog.ui index efcb7ca35..b0893dfcb 100644 --- a/retroshare-gui/src/gui/Preferences/DirectoriesDialog.ui +++ b/retroshare-gui/src/gui/Preferences/DirectoriesDialog.ui @@ -1,7 +1,8 @@ - + + DirectoriesDialog - - + + 0 0 @@ -9,162 +10,162 @@ 349 - - + + 0 0 - + - - - + + + 0 0 0 - - - + + + 208 208 208 - - - + + + 255 255 255 - - - + + + 247 247 247 - - - + + + 104 104 104 - - - + + + 139 139 139 - - - + + + 0 0 0 - - - + + + 255 255 255 - - - + + + 0 0 0 - - - + + + 255 255 255 - - - + + + 240 240 240 - - - + + + 0 0 0 - - - + + + 0 0 128 - - - + + + 255 255 255 - - - + + + 0 0 255 - - - + + + 255 0 255 - - - + + + 231 231 231 @@ -173,153 +174,153 @@ - - - + + + 0 0 0 - - - + + + 208 208 208 - - - + + + 255 255 255 - - - + + + 247 247 247 - - - + + + 104 104 104 - - - + + + 139 139 139 - - - + + + 0 0 0 - - - + + + 255 255 255 - - - + + + 0 0 0 - - - + + + 255 255 255 - - - + + + 240 240 240 - - - + + + 0 0 0 - - - + + + 192 192 192 - - - + + + 0 0 0 - - - + + + 0 0 255 - - - + + + 255 0 255 - - - + + + 231 231 231 @@ -328,153 +329,153 @@ - - - + + + 104 104 104 - - - + + + 208 208 208 - - - + + + 255 255 255 - - - + + + 247 247 247 - - - + + + 104 104 104 - - - + + + 139 139 139 - - - + + + 104 104 104 - - - + + + 255 255 255 - - - + + + 104 104 104 - - - + + + 240 240 240 - - - + + + 240 240 240 - - - + + + 0 0 0 - - - + + + 0 0 128 - - - + + + 255 255 255 - - - + + + 0 0 255 - - - + + + 255 0 255 - - - + + + 231 231 231 @@ -484,7 +485,7 @@ - + Arial 10 @@ -495,61 +496,50 @@ false - + true - + Qt::NoContextMenu - - + + 6 - - 6 - - - 6 - - - 6 - - + 0 - - 0 - - - - + + + Shared Directories - - - + + + - - - + + + 34 34 - + 34 34 - + - - :/images/directoryadd_24x24_shadow.png + + + :/images/directoryadd_24x24_shadow.png:/images/directoryadd_24x24_shadow.png - + 24 24 @@ -557,27 +547,28 @@ - - - + + + 34 34 - + 34 34 - + - - :/images/directoryremove_24x24_shadow.png + + + :/images/directoryremove_24x24_shadow.png:/images/directoryremove_24x24_shadow.png - + 24 24 @@ -585,12 +576,12 @@ - + - + Qt::Vertical - + 20 71 @@ -601,40 +592,41 @@ - - - + + + Incoming Directory - - - - + + + + true - - - + + + 31 31 - + 31 31 - + - - :/images/directoryselect_24x24_shadow.png + + + :/images/directoryselect_24x24_shadow.png:/images/directoryselect_24x24_shadow.png - + 24 24 @@ -642,43 +634,57 @@ + + + + true + + + Automatically share incoming directory (Recommanded) + + + false + + + - - - + + + Partials Direcrtory - - - - + + + + true - - - + + + 31 31 - + 31 31 - + - - :/images/directoryselect_24x24_shadow.png + + + :/images/directoryselect_24x24_shadow.png:/images/directoryselect_24x24_shadow.png - + 24 24 @@ -699,7 +705,7 @@ removeButton - + diff --git a/retroshare-gui/src/rsiface/rsfiles.h b/retroshare-gui/src/rsiface/rsfiles.h index aed7177df..62d3e9a1f 100644 --- a/retroshare-gui/src/rsiface/rsfiles.h +++ b/retroshare-gui/src/rsiface/rsfiles.h @@ -55,7 +55,7 @@ const uint32_t RS_FILE_PEER_OFFLINE = 0x00002000; /************************************ * Used To indicate where to search. * - * The Order of these is very important, + * The Order of these is very important, * it specifies the search order too. * */ @@ -101,13 +101,13 @@ virtual ~RsFiles() { return; } /*** * Control of Downloads. ***/ -virtual bool FileRequest(std::string fname, std::string hash, uint64_t size, +virtual bool FileRequest(std::string fname, std::string hash, uint64_t size, std::string dest, uint32_t flags, std::list srcIds) = 0; virtual bool FileCancel(std::string hash) = 0; virtual bool FileControl(std::string hash, uint32_t flags) = 0; virtual bool FileClearCompleted() = 0; -/*** +/*** * Download / Upload Details. ***/ virtual bool FileDownloads(std::list &hashs) = 0; @@ -121,7 +121,7 @@ virtual bool FileDetails(std::string hash, uint32_t hintflags, FileInfo &info) = virtual bool ExtraFileAdd(std::string fname, std::string hash, uint64_t size, uint32_t period, uint32_t flags) = 0; virtual bool ExtraFileRemove(std::string hash, uint32_t flags) = 0; -virtual bool ExtraFileHash(std::string localpath, +virtual bool ExtraFileHash(std::string localpath, uint32_t period, uint32_t flags) = 0; virtual bool ExtraFileStatus(std::string localpath, FileInfo &info) = 0; virtual bool ExtraFileMove(std::string fname, std::string hash, uint64_t size, @@ -157,6 +157,10 @@ virtual bool getSharedDirectories(std::list &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; };