|
|
|
@ -72,98 +72,6 @@ void Settings::switchProfile(const QString& profile)
@@ -72,98 +72,6 @@ void Settings::switchProfile(const QString& profile)
|
|
|
|
|
load(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
QString Settings::genRandomProfileName() |
|
|
|
|
{ |
|
|
|
|
QDir dir(getSettingsDirPath()); |
|
|
|
|
QString basename = "imported_"; |
|
|
|
|
QString randname; |
|
|
|
|
do { |
|
|
|
|
randname = QString().setNum(qrand()*qrand()*qrand(), 16); |
|
|
|
|
randname.truncate(6); |
|
|
|
|
randname = basename + randname; |
|
|
|
|
} while (QFile(dir.filePath(randname)).exists()); |
|
|
|
|
return randname; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
QString Settings::detectProfile() |
|
|
|
|
{ |
|
|
|
|
QDir dir(getSettingsDirPath()); |
|
|
|
|
QString path, profile = getCurrentProfile(); |
|
|
|
|
path = dir.filePath(profile + Core::TOX_EXT); |
|
|
|
|
QFile file(path); |
|
|
|
|
if (profile.isEmpty() || !file.exists()) |
|
|
|
|
{ |
|
|
|
|
setCurrentProfile(""); |
|
|
|
|
#if 1 // deprecation attempt
|
|
|
|
|
// if the last profile doesn't exist, fall back to old "data"
|
|
|
|
|
path = dir.filePath(Core::CONFIG_FILE_NAME); |
|
|
|
|
QFile file(path); |
|
|
|
|
if (file.exists()) |
|
|
|
|
{ |
|
|
|
|
profile = genRandomProfileName(); |
|
|
|
|
setCurrentProfile(profile); |
|
|
|
|
file.rename(profile + Core::TOX_EXT); |
|
|
|
|
return profile; |
|
|
|
|
} |
|
|
|
|
else if (QFile(path = dir.filePath("tox_save")).exists()) // also import tox_save if no data
|
|
|
|
|
{ |
|
|
|
|
profile = genRandomProfileName(); |
|
|
|
|
setCurrentProfile(profile); |
|
|
|
|
QFile(path).rename(profile + Core::TOX_EXT); |
|
|
|
|
return profile; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
#endif |
|
|
|
|
{ |
|
|
|
|
profile = askProfiles(); |
|
|
|
|
if (profile.isEmpty()) |
|
|
|
|
{ |
|
|
|
|
return ""; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
switchProfile(profile); |
|
|
|
|
return dir.filePath(profile + Core::TOX_EXT); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
return path; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
QList<QString> Settings::searchProfiles() |
|
|
|
|
{ |
|
|
|
|
QList<QString> out; |
|
|
|
|
QDir dir(getSettingsDirPath()); |
|
|
|
|
dir.setFilter(QDir::Files | QDir::NoDotAndDotDot); |
|
|
|
|
dir.setNameFilters(QStringList("*.tox")); |
|
|
|
|
for (QFileInfo file : dir.entryInfoList()) |
|
|
|
|
out += file.completeBaseName(); |
|
|
|
|
|
|
|
|
|
return out; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
QString Settings::askProfiles() |
|
|
|
|
{ // TODO: allow user to create new Tox ID, even if a profile already exists
|
|
|
|
|
QList<QString> profiles = searchProfiles(); |
|
|
|
|
if (profiles.empty()) return ""; |
|
|
|
|
bool ok; |
|
|
|
|
QString profile = GUI::itemInputDialog(nullptr, |
|
|
|
|
tr("Choose a profile"), |
|
|
|
|
tr("Please choose which identity to use"), |
|
|
|
|
profiles, |
|
|
|
|
0, // which slot to start on
|
|
|
|
|
false, // if the user can enter their own input
|
|
|
|
|
&ok); |
|
|
|
|
if (!ok) // user cancelled
|
|
|
|
|
return ""; |
|
|
|
|
else |
|
|
|
|
return profile; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Settings::load() |
|
|
|
|
{ |
|
|
|
|
if (loaded) |
|
|
|
|