1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Profiles, with at least a few bugs:

sanitizing file names isn't done, delete fails because of autosaves, and imports segfault for me
This commit is contained in:
dubslow 2014-07-16 20:00:23 -05:00
parent f423c174e7
commit 46848d7712
4 changed files with 57 additions and 6 deletions

View File

@ -21,8 +21,8 @@
#include <QClipboard>
#include <QApplication>
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();

View File

@ -29,15 +29,17 @@
#include <QComboBox>
#include <QDir>
#include <QFileInfo>
#include <QFileDialog>
#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;

View File

@ -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;
}

View File

@ -142,7 +142,7 @@ private:
Core* core;
QThread* coreThread;
AddFriendForm friendForm;
SettingsForm settingsForm;
SettingsForm* settingsForm;
FilesForm filesForm;
static Widget* instance;
FriendWidget* activeFriendWidget;