diff --git a/src/filetransferinstance.cpp b/src/filetransferinstance.cpp index 1001e4525..ddb1ab267 100644 --- a/src/filetransferinstance.cpp +++ b/src/filetransferinstance.cpp @@ -209,7 +209,10 @@ bool isFileWritable(QString& path) void FileTransferInstance::acceptRecvRequest() { QString path = Settings::getInstance().getAutoAcceptDir(Core::getInstance()->getFriendAddress(friendId)); - if (path.isEmpty()) path = Settings::getInstance().getGlobalAutoAcceptDir(); + + if (path.isEmpty()) + path = Settings::getInstance().getGlobalAutoAcceptDir(); + if (!path.isEmpty()) { QDir dir(path); diff --git a/src/misc/settings.cpp b/src/misc/settings.cpp index 2b526dd90..f6fa5bfee 100644 --- a/src/misc/settings.cpp +++ b/src/misc/settings.cpp @@ -114,8 +114,6 @@ void Settings::load() proxyPort = s.value("proxyPort", 0).toInt(); currentProfile = s.value("currentProfile", "").toString(); autoAwayTime = s.value("autoAwayTime", 10).toInt(); - autoSaveEnabled = s.value("autoSaveEnabled", false).toBool(); - autoSaveDir = s.value("autoSaveDir", QStandardPaths::locate(QStandardPaths::HomeLocation, QString(), QStandardPaths::LocateDirectory)).toString(); s.endGroup(); s.beginGroup("Widgets"); @@ -156,7 +154,11 @@ void Settings::load() s.endGroup(); s.beginGroup("AutoAccept"); - globalAutoAcceptDir = s.value("globalAutoAcceptDir", "").toString(); + autoSaveEnabled = s.value("autoSaveEnabled", false).toBool(); + globalAutoAcceptDir = s.value("globalAutoAcceptDir", + QStandardPaths::locate(QStandardPaths::HomeLocation, QString(), QStandardPaths::LocateDirectory) + ).toString(); + for (auto& key : s.childKeys()) autoAccept[key] = s.value(key).toString(); s.endGroup(); @@ -241,8 +243,6 @@ void Settings::save(QString path) s.setValue("proxyPort", proxyPort); s.setValue("currentProfile", currentProfile); s.setValue("autoAwayTime", autoAwayTime); - s.setValue("autoSaveEnabled", autoSaveEnabled); - s.setValue("autoSaveDir", autoSaveDir); s.endGroup(); s.beginGroup("Widgets"); @@ -283,6 +283,7 @@ void Settings::save(QString path) s.endGroup(); s.beginGroup("AutoAccept"); + s.setValue("autoSaveEnabled", autoSaveEnabled); s.setValue("globalAutoAcceptDir", globalAutoAcceptDir); for (auto& id : autoAccept.keys()) s.setValue(id, autoAccept.value(id)); @@ -475,17 +476,6 @@ void Settings::setTranslation(QString newValue) translation = newValue; } - -QString Settings::getAutoSaveFilesDir() const -{ - return autoSaveDir; -} - -void Settings::setAutoSaveFilesDir(QString newValue) -{ - autoSaveDir = newValue; -} - bool Settings::getForceTCP() const { return forceTCP; diff --git a/src/misc/settings.h b/src/misc/settings.h index 60204c9ad..90650bed5 100644 --- a/src/misc/settings.h +++ b/src/misc/settings.h @@ -70,9 +70,6 @@ public: QString getTranslation() const; void setTranslation(QString newValue); - QString getAutoSaveFilesDir() const; - void setAutoSaveFilesDir(QString newValue); - void setAutoSaveEnabled(bool newValue); bool getAutoSaveEnabled() const; @@ -210,13 +207,11 @@ private: bool enableIPv6; QString translation; - QString autoSaveDir; static bool makeToxPortable; bool autostartInTray; bool closeToTray; bool minimizeToTray; bool useEmoticons; - bool autoSaveEnabled; bool forceTCP; @@ -234,6 +229,7 @@ private: QHash widgetSettings; QHash autoAccept; + bool autoSaveEnabled; QString globalAutoAcceptDir; // GUI diff --git a/src/widget/form/chatform.cpp b/src/widget/form/chatform.cpp index 2c5d8b16f..02fc86e44 100644 --- a/src/widget/form/chatform.cpp +++ b/src/widget/form/chatform.cpp @@ -202,7 +202,7 @@ void ChatForm::onFileRecvRequest(ToxFile file) QTime::currentTime().toString("hh:mm"), false))); if (!Settings::getInstance().getAutoAcceptDir(Core::getInstance()->getFriendAddress(f->friendId)).isEmpty() - || !Settings::getInstance().getGlobalAutoAcceptDir().isEmpty()) + || Settings::getInstance().getAutoSaveEnabled()) fileTrans->pressFromHtml("btnB"); } diff --git a/src/widget/form/settings/generalform.cpp b/src/widget/form/settings/generalform.cpp index dd04118a9..8ebcb8137 100644 --- a/src/widget/form/settings/generalform.cpp +++ b/src/widget/form/settings/generalform.cpp @@ -51,7 +51,7 @@ GeneralForm::GeneralForm(SettingsWidget *myParent) : bodyUI->statusChanges->setChecked(Settings::getInstance().getStatusChangeNotificationEnabled()); bodyUI->useEmoticons->setChecked(Settings::getInstance().getUseEmoticons()); bodyUI->autoacceptFiles->setChecked(Settings::getInstance().getAutoSaveEnabled()); - bodyUI->autoSaveFilesDir->setText(Settings::getInstance().getAutoSaveFilesDir()); + bodyUI->autoSaveFilesDir->setText(Settings::getInstance().getGlobalAutoAcceptDir()); for (auto entry : SmileyPack::listSmileyPacks()) { @@ -172,8 +172,7 @@ void GeneralForm::onEmoticonSizeChanged() void GeneralForm::onTimestampSelected(int index) { - Settings::getInstance().setTimestampFormat( - bodyUI->timestamp->currentText().split(" ").at(0)); + Settings::getInstance().setTimestampFormat(timeFormats[index]); } void GeneralForm::onAutoAwayChanged() @@ -199,12 +198,12 @@ void GeneralForm::onAutoAcceptFileChange() void GeneralForm::onAutoSaveDirChange() { - QString previousDir = Settings::getInstance().getAutoSaveFilesDir(); + QString previousDir = Settings::getInstance().getGlobalAutoAcceptDir(); QString directory = QFileDialog::getExistingDirectory(0, tr("Choose an auto accept directory","popup title")); if(directory.isEmpty()) directory = previousDir; - Settings::getInstance().setAutoSaveFilesDir(directory); + Settings::getInstance().setGlobalAutoAcceptDir(directory); bodyUI->autoSaveFilesDir->setText(directory); } diff --git a/src/widget/friendwidget.cpp b/src/widget/friendwidget.cpp index 7d790a221..5062f1ebe 100644 --- a/src/widget/friendwidget.cpp +++ b/src/widget/friendwidget.cpp @@ -49,28 +49,28 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event) QPoint pos = event->globalPos(); QString id = Core::getInstance()->getFriendAddress(friendId); QString dir = Settings::getInstance().getAutoAcceptDir(id); - QString globalDir = Settings::getInstance().getGlobalAutoAcceptDir(); QMenu menu; QMenu* inviteMenu = menu.addMenu(tr("Invite to group","Menu to invite a friend to a groupchat")); QAction* copyId = menu.addAction(tr("Copy friend ID","Menu to copy the Tox ID of that friend")); QMap groupActions; + for (Group* group : GroupList::groupList) { QAction* groupAction = inviteMenu->addAction(group->widget->getName()); groupActions[groupAction] = group; } + if (groupActions.isEmpty()) inviteMenu->setEnabled(false); + menu.addSeparator(); QAction* autoAccept = menu.addAction(tr("Auto accept files from this friend", "context menu entry")); QAction* disableAutoAccept = menu.addAction(tr("Manually accept files from this friend", "context menu entry")); - QAction* globalAA = menu.addAction(tr("Auto accept files from all friends", "context menu entry")); - QAction* disableGlobalAA = menu.addAction(tr("Disable global auto accept", "context menu entry")); + if (dir.isEmpty()) disableAutoAccept->setEnabled(false); - if (globalDir.isEmpty()) - disableGlobalAA->setEnabled(false); menu.addSeparator(); + QAction* removeFriendAction = menu.addAction(tr("Remove friend", "Menu to remove the friend from our friendlist")); QAction* selectedItem = menu.exec(pos); @@ -100,25 +100,6 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event) Settings::getInstance().setAutoAcceptDir(id, dir); } } - else if (selectedItem == disableAutoAccept) - { - Settings::getInstance().setAutoAcceptDir(id, ""); - } - else if (selectedItem == globalAA) - { - if (globalDir.isEmpty()) - globalDir = QDir::homePath(); - globalDir = QFileDialog::getExistingDirectory(0, tr("Choose an auto accept directory","popup title"), dir); - if (!globalDir.isEmpty()) - { - qDebug() << "FriendWidget: setting global auto accept dir to" << globalDir; - Settings::getInstance().setGlobalAutoAcceptDir(globalDir); - } - } - else if (selectedItem == disableGlobalAA) - { - Settings::getInstance().setGlobalAutoAcceptDir(""); - } else if (groupActions.contains(selectedItem)) { Group* group = groupActions[selectedItem];