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

refactor(startup): condense and rename scanProfiles

This commit is contained in:
jenli669 2019-06-24 01:35:23 +02:00
parent ac640bb4bd
commit 8bc6fc9fd8
No known key found for this signature in database
GPG Key ID: 8267F9F7C2BF7E5E
3 changed files with 18 additions and 22 deletions

View File

@ -269,21 +269,17 @@ QStringList Profile::getFilesByExt(QString extension)
* @brief Scan for profile, automatically importing them if needed.
* @warning NOT thread-safe.
*/
void Profile::scanProfiles()
const QStringList Profile::getAllProfileNames()
{
profiles.clear();
QStringList toxfiles = getFilesByExt("tox"), inifiles = getFilesByExt("ini");
for (QString toxfile : toxfiles) {
for (const QString& toxfile : toxfiles) {
if (!inifiles.contains(toxfile)) {
Settings::getInstance().createPersonal(toxfile);
}
profiles.append(toxfile);
}
}
QStringList Profile::getProfiles()
{
return profiles;
}

View File

@ -67,8 +67,7 @@ public:
bool rename(QString newName);
static void scanProfiles();
static QStringList getProfiles();
static const QStringList getAllProfileNames();
static bool exists(QString name);
static bool isEncrypted(QString name);

View File

@ -59,7 +59,7 @@ LoginScreen::LoginScreen(const QString& initialProfileName, QWidget* parent)
connect(ui->autoLoginCB, &QCheckBox::stateChanged, this, &LoginScreen::onAutoLoginToggled);
connect(ui->importButton, &QPushButton::clicked, this, &LoginScreen::onImportProfile);
reset(initialProfile);
reset(initialProfileName);
this->setStyleSheet(Style::getStylesheet("loginScreen/loginScreen.css"));
retranslateUi();
@ -84,7 +84,7 @@ void LoginScreen::closeEvent(QCloseEvent* event)
/**
* @brief Resets the UI, clears all fields.
*/
void LoginScreen::reset(QString initialProfile)
void LoginScreen::reset(const QString& initialProfileName)
{
ui->newUsername->clear();
ui->newPass->clear();
@ -92,25 +92,26 @@ void LoginScreen::reset(QString initialProfile)
ui->loginPassword->clear();
ui->loginUsernames->clear();
Profile::scanProfiles();
if (initialProfile.isEmpty()) {
initialProfile = Settings::getInstance().getCurrentProfile();
}
QStringList profiles = Profile::getProfiles();
for (QString profile : profiles) {
ui->loginUsernames->addItem(profile);
if (profile == initialProfile) {
ui->loginUsernames->setCurrentIndex(ui->loginUsernames->count() - 1);
}
}
QStringList allProfileNames = Profile::getAllProfileNames();
if (profiles.isEmpty()) {
if (allProfileNames.isEmpty()) {
ui->stackedWidget->setCurrentIndex(0);
ui->newUsername->setFocus();
} else {
for (const QString& profileName : allProfileNames) {
ui->loginUsernames->addItem(profileName);
}
ui->loginUsernames->setCurrentText(initialProfileName);
ui->stackedWidget->setCurrentIndex(1);
ui->loginPassword->setFocus();
}
}
void LoginScreen::onProfileLoaded()
{
done(0);
}
void LoginScreen::onProfileLoadFailed() {
QMessageBox::critical(this, tr("Couldn't load this profile"), tr("Wrong password."));