From 46848d77128d35049e9f47df8dbed1addfa305e6 Mon Sep 17 00:00:00 2001 From: dubslow Date: Wed, 16 Jul 2014 20:00:23 -0500 Subject: [PATCH] Profiles, with at least a few bugs: sanitizing file names isn't done, delete fails because of autosaves, and imports segfault for me --- widget/form/settingsform.cpp | 44 ++++++++++++++++++++++++++++++++++-- widget/form/settingsform.h | 10 +++++++- widget/widget.cpp | 7 ++++-- widget/widget.h | 2 +- 4 files changed, 57 insertions(+), 6 deletions(-) diff --git a/widget/form/settingsform.cpp b/widget/form/settingsform.cpp index 92c12b8c0..f36f3e63b 100644 --- a/widget/form/settingsform.cpp +++ b/widget/form/settingsform.cpp @@ -21,8 +21,8 @@ #include #include -SettingsForm::SettingsForm() - : QObject() +SettingsForm::SettingsForm(Core* core) + : QObject(), core(core) { main = new QWidget(), head = new QWidget(); hboxcont1 = new QWidget(), hboxcont2 = new QWidget(); @@ -86,6 +86,10 @@ SettingsForm::SettingsForm() head->setLayout(&headLayout); headLayout.addWidget(&headLabel); + connect(&loadConf, SIGNAL(clicked()), this, SLOT(onLoadClicked())); + connect(&exportConf, SIGNAL(clicked()), this, SLOT(onExportClicked())); + connect(&delConf, SIGNAL(clicked()), this, SLOT(onDeleteClicked())); + connect(&importConf, SIGNAL(clicked()), this, SLOT(onImportClicked())); connect(&videoTest, SIGNAL(clicked()), this, SLOT(onTestVideoClicked())); connect(&enableIPv6, SIGNAL(stateChanged(int)), this, SLOT(onEnableIPv6Updated())); connect(&useTranslations, SIGNAL(stateChanged(int)), this, SLOT(onUseTranslationUpdated())); @@ -107,6 +111,11 @@ void SettingsForm::populateProfiles() } } +QString SettingsForm::getSelectedSavePath() +{ + return Settings::getSettingsDirPath() + profiles.currentText() + core->TOX_EXT; +} + void SettingsForm::setFriendAddress(const QString& friendAddress) { id.setText(friendAddress); @@ -122,6 +131,37 @@ void SettingsForm::show(Ui::Widget &ui) head->show(); } +void SettingsForm::onLoadClicked() +{ + core->saveConfiguration(); + core->loadConfiguration(getSelectedSavePath()); + // loadConf also setsCurrentProfile +} + +void SettingsForm::onExportClicked() +{ + QString current = getSelectedSavePath(); + QString path = QFileDialog::getSaveFileName(0, tr("Export profile", "save dialog title"), QDir::homePath() + '/' + profiles.currentText() + core->TOX_EXT, tr("Tox save file (*.tox)", "save dialog filter")); + // dunno if that "~" works + QFile::copy(getSelectedSavePath(), path); +} + +void SettingsForm::onDeleteClicked() +{ // this should really be guarded by a pop up + QFile::remove(getSelectedSavePath()); +} + +void SettingsForm::onImportClicked() +{ + QString path = QFileDialog::getOpenFileName(0, tr("Import profile", "import dialog title"), QDir::homePath(), tr("Tox save file (*.tox)", "import dialog filter")); + // again, the "~"... + QFileInfo info(path); + QString profile = info.completeBaseName(); + QString profilePath = Settings::getSettingsDirPath() + profile + core->TOX_EXT; + QFile::copy(path, profilePath); + core->loadConfiguration(profilePath); +} + void SettingsForm::onTestVideoClicked() { Widget::getInstance()->showTestCamview(); diff --git a/widget/form/settingsform.h b/widget/form/settingsform.h index 070c4e1b4..3a69a1a70 100644 --- a/widget/form/settingsform.h +++ b/widget/form/settingsform.h @@ -29,15 +29,17 @@ #include #include #include +#include #include "widget/tool/clickablelabel.h" #include "ui_widget.h" #include "widget/selfcamview.h" +#include "core.h" class SettingsForm : public QObject { Q_OBJECT public: - SettingsForm(); + SettingsForm(Core* core); ~SettingsForm(); void show(Ui::Widget& ui); @@ -46,6 +48,10 @@ public slots: void setFriendAddress(const QString& friendAddress); private slots: + void onLoadClicked(); + void onExportClicked(); + void onDeleteClicked(); + void onImportClicked(); void onTestVideoClicked(); void onEnableIPv6Updated(); void onUseTranslationUpdated(); @@ -64,6 +70,8 @@ private: QVBoxLayout layout, headLayout; QWidget *main, *head, *hboxcont1, *hboxcont2; void populateProfiles(); + QString getSelectedSavePath(); + Core* core; public: //QLineEdit name, statusText; diff --git a/widget/widget.cpp b/widget/widget.cpp index 468ea3b83..4722dabd0 100644 --- a/widget/widget.cpp +++ b/widget/widget.cpp @@ -141,6 +141,8 @@ Widget::Widget(QWidget *parent) : isWindowMinimized = 0; + settingsForm = new SettingsForm(core); + ui->mainContent->setLayout(new QVBoxLayout()); ui->mainHead->setLayout(new QVBoxLayout()); ui->mainHead->layout()->setMargin(0); @@ -217,7 +219,7 @@ Widget::Widget(QWidget *parent) : connect(core, &Core::statusSet, this, &Widget::onStatusSet); connect(core, &Core::usernameSet, this, &Widget::setUsername); connect(core, &Core::statusMessageSet, this, &Widget::setStatusMessage); - connect(core, &Core::friendAddressGenerated, &settingsForm, &SettingsForm::setFriendAddress); + connect(core, &Core::friendAddressGenerated, settingsForm, &SettingsForm::setFriendAddress); connect(core, SIGNAL(fileDownloadFinished(const QString&)), &filesForm, SLOT(onFileDownloadComplete(const QString&))); connect(core, SIGNAL(fileUploadFinished(const QString&)), &filesForm, SLOT(onFileUploadComplete(const QString&))); connect(core, &Core::friendAdded, this, &Widget::addFriend); @@ -281,6 +283,7 @@ Widget::~Widget() settings.setValue("geometry", geometry()); settings.setValue("maximized", isMaximized()); settings.setValue("useNativeTheme", useNativeTheme); + delete settingsForm; delete ui; } @@ -391,7 +394,7 @@ void Widget::onTransferClicked() void Widget::onSettingsClicked() { hideMainForms(); - settingsForm.show(*ui); + settingsForm->show(*ui); isFriendWidgetActive = 0; isGroupWidgetActive = 0; } diff --git a/widget/widget.h b/widget/widget.h index 42953e6e8..b5a4b1b5a 100644 --- a/widget/widget.h +++ b/widget/widget.h @@ -142,7 +142,7 @@ private: Core* core; QThread* coreThread; AddFriendForm friendForm; - SettingsForm settingsForm; + SettingsForm* settingsForm; FilesForm filesForm; static Widget* instance; FriendWidget* activeFriendWidget;