mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Remove some unused Settings methods
This commit is contained in:
parent
7fc087ea95
commit
1ffb2d4a92
|
@ -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)
|
||||
|
|
|
@ -33,15 +33,10 @@ public:
|
|||
~Settings() = default;
|
||||
static Settings& getInstance();
|
||||
void switchProfile(const QString& profile);
|
||||
QString detectProfile();
|
||||
QList<QString> searchProfiles();
|
||||
QString askProfiles();
|
||||
void createSettingsDir(); ///< Creates a path to the settings dir, if it doesn't already exist
|
||||
|
||||
void createPersonal(QString basename); ///< Write a default personnal settings file for a profile
|
||||
|
||||
void executeSettingsDialog(QWidget* parent);
|
||||
|
||||
static QString getSettingsDirPath();
|
||||
|
||||
struct DhtServer
|
||||
|
@ -262,9 +257,6 @@ public:
|
|||
void save(QString path, bool writePersonal = true);
|
||||
void load();
|
||||
|
||||
private:
|
||||
static QString genRandomProfileName();
|
||||
|
||||
private:
|
||||
static Settings* settings;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user