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

Fixed misusing tox_load; profiles are significantly less buggy

This commit is contained in:
Dubslow 2014-09-10 08:12:43 -05:00
parent e477c4ef64
commit 05c654373f
3 changed files with 35 additions and 14 deletions

View File

@ -113,7 +113,7 @@ Core::~Core()
alcCaptureCloseDevice(alInDev); 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. // IPv6 needed for LAN discovery, but can crash some weird routers. On by default, can be disabled in options.
bool enableIPv6 = Settings::getInstance().getEnableIPv6(); bool enableIPv6 = Settings::getInstance().getEnableIPv6();
@ -160,13 +160,18 @@ void Core::start()
emit failedToStart(); emit failedToStart();
return; return;
} }
}
void Core::start()
{
get_tox();
qsrand(time(nullptr)); qsrand(time(nullptr));
// where do we find the data file? // where do we find the data file?
QString path; QString path;
{ // read data from whose profile? { // 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 1 // deprecation attempt
// if the last profile doesn't exist, fall back to old "data" // if the last profile doesn't exist, fall back to old "data"
@ -174,7 +179,7 @@ void Core::start()
QFile file(path); QFile file(path);
if (!file.exists()) if (!file.exists())
{ {
path = Settings::getSettingsDirPath() + '/' + CONFIG_FILE_NAME; path = Settings::getSettingsDirPath() + QDir::separator() + CONFIG_FILE_NAME;
} }
#endif #endif
} }
@ -909,10 +914,10 @@ void Core::saveConfiguration()
Settings::getInstance().setCurrentProfile(profile); Settings::getInstance().setCurrentProfile(profile);
} }
QString path = dir + '/' + profile + TOX_EXT; QString path = dir + QDir::separator() + profile + TOX_EXT;
QFileInfo info(path); QFileInfo info(path);
if (!info.exists()) // fall back to old school 'data' 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"; qDebug() << path << " does not exist";
} }
@ -946,6 +951,21 @@ void Core::saveConfiguration(const QString& path)
Settings::getInstance().save(); 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() void Core::loadFriends()
{ {
const uint32_t friendCount = tox_count_friendlist(tox); const uint32_t friendCount = tox_count_friendlist(tox);

9
core.h
View File

@ -127,9 +127,7 @@ public:
void saveConfiguration(); void saveConfiguration();
void saveConfiguration(const QString& path); void saveConfiguration(const QString& path);
void loadConfiguration(QString path); void switchConfiguration(QString profile);
static QString sanitize(QString name);
QString getIDString(); QString getIDString();
@ -287,6 +285,11 @@ private:
void checkConnection(); void checkConnection();
void onBootstrapTimer(); void onBootstrapTimer();
void loadConfiguration(QString path);
static QString sanitize(QString name);
void get_tox();
void loadFriends(); void loadFriends();
static void sendAllFileData(Core* core, ToxFile* file); static void sendAllFileData(Core* core, ToxFile* file);

View File

@ -120,7 +120,7 @@ QList<QString> SettingsForm::searchProfiles()
QString SettingsForm::getSelectedSavePath() 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) void SettingsForm::setFriendAddress(const QString& friendAddress)
@ -143,15 +143,13 @@ void SettingsForm::show(Ui::MainWindow &ui)
void SettingsForm::onLoadClicked() void SettingsForm::onLoadClicked()
{ {
Widget::getInstance()->getCore()->saveConfiguration(); Widget::getInstance()->getCore()->switchConfiguration(profiles.currentText());
Settings::getInstance().setCurrentProfile(profiles.currentText());
Widget::getInstance()->getCore()->loadConfiguration(getSelectedSavePath());
} }
void SettingsForm::onExportClicked() void SettingsForm::onExportClicked()
{ {
QString current = getSelectedSavePath(); 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); QFile::copy(getSelectedSavePath(), path);
} }
@ -181,8 +179,8 @@ void SettingsForm::onImportClicked()
QString profilePath = Settings::getSettingsDirPath() + profile + Widget::getInstance()->getCore()->TOX_EXT; QString profilePath = Settings::getSettingsDirPath() + profile + Widget::getInstance()->getCore()->TOX_EXT;
Settings::getInstance().setCurrentProfile(profile); Settings::getInstance().setCurrentProfile(profile);
QFile::copy(path, profilePath); QFile::copy(path, profilePath);
Widget::getInstance()->getCore()->loadConfiguration(profilePath);
profiles.addItem(profile); profiles.addItem(profile);
Widget::getInstance()->getCore()->switchConfiguration(profile);
} }
void SettingsForm::onTestVideoClicked() void SettingsForm::onTestVideoClicked()