Replace returnMessage by returnCode in blacklist function.

This commit is contained in:
zhangpengfei 2021-02-04 20:01:21 +08:00
parent ef755ef9de
commit 1fe631efa8
3 changed files with 20 additions and 14 deletions

View File

@ -100,13 +100,13 @@ void GlobalSettings::resetAll()
}); });
} }
bool GlobalSettings::setBlockDirs(const QString &path, QString &returnMessage, bool remove) bool GlobalSettings::setBlockDirs(const QString &path, int &returnCode, bool remove)
{ {
if(remove) if(remove)
{ {
if(path.isEmpty()) if(path.isEmpty())
{ {
returnMessage = QString(tr("I can't remove an empty path string!")); returnCode = PATH_EMPTY;
return false; return false;
} }
@ -115,7 +115,8 @@ bool GlobalSettings::setBlockDirs(const QString &path, QString &returnMessage, b
} }
if(!path.startsWith("/home")) if(!path.startsWith("/home"))
{ {
returnMessage = QString(tr("I can only search your user directory, it doesn't make any sense if you block an directory which is not in user directory!")); // returnCode = QString(tr("I can only search your user directory, it doesn't make any sense if you block an directory which is not in user directory!"));
returnCode = PATH_NOT_IN_HOME;
return false; return false;
} }
@ -127,7 +128,8 @@ bool GlobalSettings::setBlockDirs(const QString &path, QString &returnMessage, b
{ {
if(pathKey.startsWith(i)) if(pathKey.startsWith(i))
{ {
returnMessage = QString(tr("My parent folder has been blocked!")); // returnCode = QString(tr("My parent folder has been blocked!"));
returnCode = PATH_PARENT_BLOCKED;
return false; return false;
} }

View File

@ -38,6 +38,9 @@
#define CONTENT_INDEX_DATABASE_STATE "content_index_database_state" #define CONTENT_INDEX_DATABASE_STATE "content_index_database_state"
#define INDEX_GENERATOR_NORMAL_EXIT "index_generator_normal_exit" #define INDEX_GENERATOR_NORMAL_EXIT "index_generator_normal_exit"
#define INOTIFY_NORMAL_EXIT "inotify_normal_exit" #define INOTIFY_NORMAL_EXIT "inotify_normal_exit"
#define PATH_EMPTY 1;
#define PATH_NOT_IN_HOME 2;
#define PATH_PARENT_BLOCKED 3;
class LIBSEARCH_EXPORT GlobalSettings : public QObject class LIBSEARCH_EXPORT GlobalSettings : public QObject
{ {
@ -63,7 +66,7 @@ public Q_SLOTS:
* @param true to remove blocking,false to set blocking,default set false. * @param true to remove blocking,false to set blocking,default set false.
* @return * @return
*/ */
bool setBlockDirs(const QString& path, QString &returnMessage,bool remove = false); bool setBlockDirs(const QString& path, int &returnCode,bool remove = false);
QStringList getBlockDirs(); QStringList getBlockDirs();
void forceSync(const QString& = nullptr); void forceSync(const QString& = nullptr);

View File

@ -270,8 +270,8 @@ void SettingsWidget::onBtnDelClicked(const QString& path) {
return; return;
} }
QString returnMessage; int returnCode = 0;
if (GlobalSettings::getInstance()->setBlockDirs(path, returnMessage, true)) { if (GlobalSettings::getInstance()->setBlockDirs(path, returnCode, true)) {
qDebug()<<"Remove block dir in onBtnDelClicked() successed."; qDebug()<<"Remove block dir in onBtnDelClicked() successed.";
Q_FOREACH (FolderListItem * item, m_dirListWidget->findChildren<FolderListItem*>()) { Q_FOREACH (FolderListItem * item, m_dirListWidget->findChildren<FolderListItem*>()) {
if (item->getPath() == path) { if (item->getPath() == path) {
@ -283,10 +283,10 @@ void SettingsWidget::onBtnDelClicked(const QString& path) {
} }
} }
} else { } else {
qWarning()<<returnMessage; // qWarning()<<returnCode;
qDebug()<<"Remove block dir in onBtnAddClicked() failed. Message: "<<returnMessage; qDebug()<<"Remove block dir in onBtnAddClicked() failed. Code: "<<returnCode;
QMessageBox message(QMessageBox::Warning, tr("Search"), returnMessage, QMessageBox::Ok, this); QMessageBox message(QMessageBox::Warning, tr("Search"), QString::number(returnCode), QMessageBox::Ok, this);
message.exec(); message.exec();
} }
} }
@ -365,17 +365,18 @@ void SettingsWidget::onBtnAddClicked() {
} }
QString selectedDir = 0; QString selectedDir = 0;
QString returnMessage = 0; QString returnMessage = 0;
int returnCode;
selectedDir = fileDialog->selectedFiles().first(); selectedDir = fileDialog->selectedFiles().first();
qDebug()<<"Selected a folder in onBtnAddClicked(): "<<selectedDir<<". ->settings-widget.cpp #238"; qDebug()<<"Selected a folder in onBtnAddClicked(): "<<selectedDir<<". ->settings-widget.cpp #238";
if (GlobalSettings::getInstance()->setBlockDirs(selectedDir, returnMessage)) { if (GlobalSettings::getInstance()->setBlockDirs(selectedDir, returnCode)) {
setupBlackList(GlobalSettings::getInstance()->getBlockDirs()); setupBlackList(GlobalSettings::getInstance()->getBlockDirs());
qDebug()<<"Add block dir in onBtnAddClicked() successed. ->settings-widget.cpp #238"; qDebug()<<"Add block dir in onBtnAddClicked() successed. ->settings-widget.cpp #238";
} else { } else {
qWarning()<<returnMessage; // qWarning()<<returnMessage;
qDebug()<<"Add block dir in onBtnAddClicked() failed. Message: "<<returnMessage<<" ->settings-widget.cpp #238"; qDebug()<<"Add block dir in onBtnAddClicked() failed. Code: "<<returnCode<<" ->settings-widget.cpp #238";
// QMessageBox::warning(this, tr("Search"), returnMessage); // QMessageBox::warning(this, tr("Search"), returnMessage);
QMessageBox message(QMessageBox::Warning, tr("Search"), returnMessage, QMessageBox::Ok, this); QMessageBox message(QMessageBox::Warning, tr("Search"), QString::number(returnCode), QMessageBox::Ok, this);
message.exec(); message.exec();
} }
} }