From 05c654373fd61b483edaa8602d4bea2c08ab9d1f Mon Sep 17 00:00:00 2001 From: Dubslow Date: Wed, 10 Sep 2014 08:12:43 -0500 Subject: [PATCH] Fixed misusing tox_load; profiles are significantly less buggy --- core.cpp | 30 +++++++++++++++++++++++++----- core.h | 9 ++++++--- widget/form/settingsform.cpp | 10 ++++------ 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/core.cpp b/core.cpp index 81f7b1030..e23d3661d 100644 --- a/core.cpp +++ b/core.cpp @@ -113,7 +113,7 @@ Core::~Core() alcCaptureCloseDevice(alInDev); } -void Core::start() +void Core::get_tox() { // IPv6 needed for LAN discovery, but can crash some weird routers. On by default, can be disabled in options. bool enableIPv6 = Settings::getInstance().getEnableIPv6(); @@ -160,13 +160,18 @@ void Core::start() emit failedToStart(); return; } +} + +void Core::start() +{ + get_tox(); qsrand(time(nullptr)); // where do we find the data file? QString path; { // read data from whose profile? - path = Settings::getSettingsDirPath() + '/' + Settings::getInstance().getCurrentProfile() + TOX_EXT; + path = Settings::getSettingsDirPath() + QDir::separator() + Settings::getInstance().getCurrentProfile() + TOX_EXT; #if 1 // deprecation attempt // if the last profile doesn't exist, fall back to old "data" @@ -174,7 +179,7 @@ void Core::start() QFile file(path); if (!file.exists()) { - path = Settings::getSettingsDirPath() + '/' + CONFIG_FILE_NAME; + path = Settings::getSettingsDirPath() + QDir::separator() + CONFIG_FILE_NAME; } #endif } @@ -909,10 +914,10 @@ void Core::saveConfiguration() Settings::getInstance().setCurrentProfile(profile); } - QString path = dir + '/' + profile + TOX_EXT; + QString path = dir + QDir::separator() + profile + TOX_EXT; QFileInfo info(path); if (!info.exists()) // fall back to old school 'data' - { //path = dir + '/' + CONFIG_FILE_NAME; + { //path = dir + QDir::separator() + CONFIG_FILE_NAME; qDebug() << path << " does not exist"; } @@ -946,6 +951,21 @@ void Core::saveConfiguration(const QString& path) Settings::getInstance().save(); } +void Core::switchConfiguration(QString profile) +{ + saveConfiguration(); + + if (tox) { + toxav_kill(toxav); + tox_kill(tox); + } + + get_tox(); + + Settings::getInstance().setCurrentProfile(profile); + loadConfiguration(Settings::getSettingsDirPath() + QDir::separator() + profile + TOX_EXT); +} + void Core::loadFriends() { const uint32_t friendCount = tox_count_friendlist(tox); diff --git a/core.h b/core.h index 5de02e7f7..f07618b40 100644 --- a/core.h +++ b/core.h @@ -127,9 +127,7 @@ public: void saveConfiguration(); void saveConfiguration(const QString& path); - void loadConfiguration(QString path); - - static QString sanitize(QString name); + void switchConfiguration(QString profile); QString getIDString(); @@ -286,6 +284,11 @@ private: void checkConnection(); void onBootstrapTimer(); + + void loadConfiguration(QString path); + static QString sanitize(QString name); + + void get_tox(); void loadFriends(); diff --git a/widget/form/settingsform.cpp b/widget/form/settingsform.cpp index bb8c12093..e3f1660a0 100644 --- a/widget/form/settingsform.cpp +++ b/widget/form/settingsform.cpp @@ -120,7 +120,7 @@ QList SettingsForm::searchProfiles() QString SettingsForm::getSelectedSavePath() { - return Settings::getSettingsDirPath() + profiles.currentText() + Widget::getInstance()->getCore()->TOX_EXT; + return Settings::getSettingsDirPath() + QDir::separator() + profiles.currentText() + Widget::getInstance()->getCore()->TOX_EXT; } void SettingsForm::setFriendAddress(const QString& friendAddress) @@ -143,15 +143,13 @@ void SettingsForm::show(Ui::MainWindow &ui) void SettingsForm::onLoadClicked() { - Widget::getInstance()->getCore()->saveConfiguration(); - Settings::getInstance().setCurrentProfile(profiles.currentText()); - Widget::getInstance()->getCore()->loadConfiguration(getSelectedSavePath()); + Widget::getInstance()->getCore()->switchConfiguration(profiles.currentText()); } void SettingsForm::onExportClicked() { QString current = getSelectedSavePath(); - QString path = QFileDialog::getSaveFileName(0, tr("Export profile", "save dialog title"), QDir::homePath() + '/' + profiles.currentText() + Widget::getInstance()->getCore()->TOX_EXT, tr("Tox save file (*.tox)", "save dialog filter")); + QString path = QFileDialog::getSaveFileName(0, tr("Export profile", "save dialog title"), QDir::homePath() + QDir::separator() + profiles.currentText() + Widget::getInstance()->getCore()->TOX_EXT, tr("Tox save file (*.tox)", "save dialog filter")); QFile::copy(getSelectedSavePath(), path); } @@ -181,8 +179,8 @@ void SettingsForm::onImportClicked() QString profilePath = Settings::getSettingsDirPath() + profile + Widget::getInstance()->getCore()->TOX_EXT; Settings::getInstance().setCurrentProfile(profile); QFile::copy(path, profilePath); - Widget::getInstance()->getCore()->loadConfiguration(profilePath); profiles.addItem(profile); + Widget::getInstance()->getCore()->switchConfiguration(profile); } void SettingsForm::onTestVideoClicked()