From f12cd5774d696b3635bb8f206862e96a97487861 Mon Sep 17 00:00:00 2001 From: Phenom Date: Sat, 12 May 2018 14:31:17 +0200 Subject: [PATCH] Fix Partial Dir Check Add WrongValue StyleSheet property, when bad directory selected. Update QLineEdit with current setting so it's possible to see if something is modified. No need to restart. --- libretroshare/src/ft/ftcontroller.cc | 30 ++++----- libretroshare/src/ft/ftcontroller.h | 4 +- libretroshare/src/ft/ftserver.cc | 61 ++++++++++++------- libretroshare/src/ft/ftserver.h | 4 +- libretroshare/src/retroshare/rsfiles.h | 4 +- .../src/gui/qss/stylesheet/qss.default | 6 ++ .../src/gui/settings/TransferPage.cpp | 56 ++++++++++++----- retroshare-gui/src/qss/blacknight.qss | 7 +++ retroshare-gui/src/qss/qdarkstyle.qss | 6 ++ 9 files changed, 120 insertions(+), 58 deletions(-) diff --git a/libretroshare/src/ft/ftcontroller.cc b/libretroshare/src/ft/ftcontroller.cc index f1500036f..9abec040f 100644 --- a/libretroshare/src/ft/ftcontroller.cc +++ b/libretroshare/src/ft/ftcontroller.cc @@ -1472,24 +1472,24 @@ bool ftController::setPartialsDirectory(std::string path) /* check it is not a subdir of download / shared directories (BAD) - TODO */ { - RsStackMutex stack(ctrlMutex); + RsStackMutex stack(ctrlMutex); - path = RsDirUtil::convertPathToUnix(path); + path = RsDirUtil::convertPathToUnix(path); - if (path.find(mDownloadPath) == std::string::npos) { - return false; - } + if (path.find(mDownloadPath) != std::string::npos) { + return false; + } - if (rsFiles) { - std::list::iterator it; - std::list dirs; - rsFiles->getSharedDirectories(dirs); - for (it = dirs.begin(); it != dirs.end(); ++it) { - if (path.find((*it).filename) == std::string::npos) { - return false; - } - } - } + if (rsFiles) { + std::list::iterator it; + std::list dirs; + rsFiles->getSharedDirectories(dirs); + for (it = dirs.begin(); it != dirs.end(); ++it) { + if (path.find((*it).filename) != std::string::npos) { + return false; + } + } + } } /* check if it exists */ diff --git a/libretroshare/src/ft/ftcontroller.h b/libretroshare/src/ft/ftcontroller.h index 5a9140267..564660879 100644 --- a/libretroshare/src/ft/ftcontroller.h +++ b/libretroshare/src/ft/ftcontroller.h @@ -175,8 +175,8 @@ class ftController: public RsTickingThread, public pqiServiceMonitor, public p3C void FileDownloads(std::list &hashs); /* Directory Handling */ - bool setDownloadDirectory(std::string path); - bool setPartialsDirectory(std::string path); + bool setDownloadDirectory(std::string path); + bool setPartialsDirectory(std::string path); std::string getDownloadDirectory(); std::string getPartialsDirectory(); bool FileDetails(const RsFileHash &hash, FileInfo &info); diff --git a/libretroshare/src/ft/ftserver.cc b/libretroshare/src/ft/ftserver.cc index f2200d7db..a3c344460 100644 --- a/libretroshare/src/ft/ftserver.cc +++ b/libretroshare/src/ft/ftserver.cc @@ -23,35 +23,40 @@ * */ -#include -#include -#include "util/rsdebug.h" -#include "util/rsdir.h" -#include "util/rsprint.h" #include "crypto/chacha20.h" -#include "retroshare/rstypes.h" -#include "retroshare/rspeers.h" //const int ftserverzone = 29539; #include "file_sharing/p3filelists.h" -#include "ft/ftturtlefiletransferitem.h" -#include "ft/ftserver.h" -#include "ft/ftextralist.h" -#include "ft/ftfilesearch.h" #include "ft/ftcontroller.h" -#include "ft/ftfileprovider.h" #include "ft/ftdatamultiplex.h" //#include "ft/ftdwlqueue.h" -#include "turtle/p3turtle.h" -#include "pqi/p3notify.h" -#include "rsserver/p3face.h" +#include "ft/ftextralist.h" +#include "ft/ftfileprovider.h" +#include "ft/ftfilesearch.h" +#include "ft/ftserver.h" +#include "ft/ftturtlefiletransferitem.h" -#include "pqi/pqi.h" #include "pqi/p3linkmgr.h" +#include "pqi/p3notify.h" +#include "pqi/pqi.h" + +#include "retroshare/rstypes.h" +#include "retroshare/rspeers.h" #include "rsitems/rsfiletransferitems.h" #include "rsitems/rsserviceids.h" +#include "rsserver/p3face.h" +#include "rsserver/rsaccounts.h" +#include "turtle/p3turtle.h" + +#include "util/rsdebug.h" +#include "util/rsdir.h" +#include "util/rsprint.h" + +#include +#include + /*** * #define SERVER_DEBUG 1 * #define SERVER_DEBUG_CACHE 1 @@ -145,9 +150,19 @@ void ftServer::SetupFtServer() /* make Controller */ mFtController = new ftController(mFtDataplex, mServiceCtrl, getServiceInfo().mServiceType); mFtController -> setFtSearchNExtra(mFtSearch, mFtExtra); - std::string tmppath = "."; - mFtController->setPartialsDirectory(tmppath); - mFtController->setDownloadDirectory(tmppath); + + std::string emergencySaveDir = rsAccounts->PathAccountDirectory(); + std::string emergencyPartialsDir = rsAccounts->PathAccountDirectory(); + if (emergencySaveDir != "") + { + emergencySaveDir += "/"; + emergencyPartialsDir += "/"; + } + emergencySaveDir += "Downloads"; + emergencyPartialsDir += "Partials"; + + mFtController->setDownloadDirectory(emergencySaveDir); + mFtController->setPartialsDirectory(emergencyPartialsDir); /* complete search setup */ mFtSearch->addSearchMode(mFtExtra, RS_FILE_HINTS_EXTRA); @@ -412,9 +427,9 @@ void ftServer::requestDirUpdate(void *ref) } /* Directory Handling */ -void ftServer::setDownloadDirectory(std::string path) +bool ftServer::setDownloadDirectory(std::string path) { - mFtController->setDownloadDirectory(path); + return mFtController->setDownloadDirectory(path); } std::string ftServer::getDownloadDirectory() @@ -422,9 +437,9 @@ std::string ftServer::getDownloadDirectory() return mFtController->getDownloadDirectory(); } -void ftServer::setPartialsDirectory(std::string path) +bool ftServer::setPartialsDirectory(std::string path) { - mFtController->setPartialsDirectory(path); + return mFtController->setPartialsDirectory(path); } std::string ftServer::getPartialsDirectory() diff --git a/libretroshare/src/ft/ftserver.h b/libretroshare/src/ft/ftserver.h index 191b201b4..440113d11 100644 --- a/libretroshare/src/ft/ftserver.h +++ b/libretroshare/src/ft/ftserver.h @@ -202,8 +202,8 @@ public: * Directory Handling ***/ virtual void requestDirUpdate(void *ref) ; // triggers the update of the given reference. Used when browsing. - virtual void setDownloadDirectory(std::string path); - virtual void setPartialsDirectory(std::string path); + virtual bool setDownloadDirectory(std::string path); + virtual bool setPartialsDirectory(std::string path); virtual std::string getDownloadDirectory(); virtual std::string getPartialsDirectory(); diff --git a/libretroshare/src/retroshare/rsfiles.h b/libretroshare/src/retroshare/rsfiles.h index d7efb2937..ccd4428be 100644 --- a/libretroshare/src/retroshare/rsfiles.h +++ b/libretroshare/src/retroshare/rsfiles.h @@ -278,8 +278,8 @@ class RsFiles ***/ virtual void requestDirUpdate(void *ref) =0 ; // triggers the update of the given reference. Used when browsing. - virtual void setDownloadDirectory(std::string path) = 0; - virtual void setPartialsDirectory(std::string path) = 0; + virtual bool setDownloadDirectory(std::string path) = 0; + virtual bool setPartialsDirectory(std::string path) = 0; virtual std::string getDownloadDirectory() = 0; virtual std::string getPartialsDirectory() = 0; diff --git a/retroshare-gui/src/gui/qss/stylesheet/qss.default b/retroshare-gui/src/gui/qss/stylesheet/qss.default index 8be8eb2e1..3e08e4d14 100644 --- a/retroshare-gui/src/gui/qss/stylesheet/qss.default +++ b/retroshare-gui/src/gui/qss/stylesheet/qss.default @@ -244,9 +244,15 @@ OpModeStatus[opMode="Minimal"] { background: #FFCCCC; } +/*Property Values at end to overwrite other settings*/ + [new=false] { background: #F8F8F8; } [new=true] { background: #DCECFD; } + +[WrongValue="true"] { + background-color: #FF8080; +} diff --git a/retroshare-gui/src/gui/settings/TransferPage.cpp b/retroshare-gui/src/gui/settings/TransferPage.cpp index a4c6a1b9d..7899f8422 100644 --- a/retroshare-gui/src/gui/settings/TransferPage.cpp +++ b/retroshare-gui/src/gui/settings/TransferPage.cpp @@ -22,15 +22,17 @@ #include "TransferPage.h" #include "rshare.h" +#include "gui/ShareManager.h" +#include "util/misc.h" + +#include "retroshare/rsiface.h" +#include "retroshare/rsfiles.h" +#include "retroshare/rspeers.h" + +#include #include -#include -#include -#include -#include -#include - TransferPage::TransferPage(QWidget * parent, Qt::WindowFlags flags) : ConfigPage(parent, flags) { @@ -225,11 +227,23 @@ void TransferPage::setIncomingDirectory() return; } - ui.incomingDir->setText(qdir); - std::string dir = ui.incomingDir->text().toUtf8().constData(); - - if(!dir.empty()) - rsFiles->setDownloadDirectory(dir); + std::string dir = qdir.toUtf8().constData(); + if(!dir.empty()) + { + if (!rsFiles->setDownloadDirectory(dir)) + { + ui.incomingDir->setToolTip( tr("Invalid Input. Have you got the right to write on it?") ); + ui.incomingDir->setProperty("WrongValue", true); + } + else + { + ui.incomingDir->setToolTip( "" ); + ui.incomingDir->setProperty("WrongValue", false); + } + } + ui.incomingDir->style()->unpolish(ui.incomingDir); + ui.incomingDir->style()->polish( ui.incomingDir); + whileBlocking(ui.incomingDir)->setText(QString::fromUtf8(rsFiles->getDownloadDirectory().c_str())); } void TransferPage::setPartialsDirectory() @@ -239,11 +253,25 @@ void TransferPage::setPartialsDirectory() return; } - ui.partialsDir->setText(qdir); - std::string dir = ui.partialsDir->text().toUtf8().constData(); + std::string dir = qdir.toUtf8().constData(); if (!dir.empty()) - rsFiles->setPartialsDirectory(dir); + { + if (!rsFiles->setPartialsDirectory(dir)) + { + ui.partialsDir->setToolTip( tr("Invalid Input. It can't be an already shared directory.") ); + ui.partialsDir->setProperty("WrongValue", true); + } + else + { + ui.partialsDir->setToolTip( "" ); + ui.partialsDir->setProperty("WrongValue", false); + } + } + ui.partialsDir->style()->unpolish(ui.partialsDir); + ui.partialsDir->style()->polish( ui.partialsDir); + whileBlocking(ui.partialsDir)->setText(QString::fromUtf8(rsFiles->getPartialsDirectory().c_str())); } + void TransferPage::toggleAutoCheckDirectories(bool b) { ui.autoCheckDirectoriesDelay_SB->setEnabled(b); diff --git a/retroshare-gui/src/qss/blacknight.qss b/retroshare-gui/src/qss/blacknight.qss index 1b89a5f4c..3d56385ab 100644 --- a/retroshare-gui/src/qss/blacknight.qss +++ b/retroshare-gui/src/qss/blacknight.qss @@ -293,9 +293,16 @@ OpModeStatus[opMode="Minimal"] { background: #700000; } +/*Property Values at end to overwrite other settings*/ + [new=false] { background: #202020; } [new=true] { background: #005000; } + +[WrongValue=true] { + background-color: #702020; +} + diff --git a/retroshare-gui/src/qss/qdarkstyle.qss b/retroshare-gui/src/qss/qdarkstyle.qss index ccb0d47f7..6c325dc1a 100644 --- a/retroshare-gui/src/qss/qdarkstyle.qss +++ b/retroshare-gui/src/qss/qdarkstyle.qss @@ -1126,9 +1126,15 @@ OpModeStatus[opMode="Minimal"] { background: #700000; } +/*Property Values at end to overwrite other settings*/ + [new=false] { background: #202020; } [new=true] { background: #005000; } + +[WrongValue="true"] { + background-color: #702020; +}