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

fix(login): start login screen on profile select by -p option

This commit is contained in:
Anthony Bilinski 2018-04-19 23:54:14 -07:00
parent 2d87999922
commit 1af3ad69e8
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
3 changed files with 11 additions and 8 deletions

View File

@ -328,7 +328,7 @@ int main(int argc, char* argv[])
!Profile::isEncrypted(profileName)) { !Profile::isEncrypted(profileName)) {
profile = Profile::loadProfile(profileName); profile = Profile::loadProfile(profileName);
} else { } else {
LoginScreen loginScreen{}; LoginScreen loginScreen{profileName};
loginScreen.exec(); loginScreen.exec();
profile = loginScreen.getProfile(); profile = loginScreen.getProfile();
if (profile) { if (profile) {

View File

@ -32,7 +32,7 @@
#include <QMessageBox> #include <QMessageBox>
#include <QToolButton> #include <QToolButton>
LoginScreen::LoginScreen(QWidget* parent) LoginScreen::LoginScreen(QString initialProfile, QWidget* parent)
: QDialog(parent) : QDialog(parent)
, ui(new Ui::LoginScreen) , ui(new Ui::LoginScreen)
, quitShortcut{QKeySequence(Qt::CTRL + Qt::Key_Q), this} , quitShortcut{QKeySequence(Qt::CTRL + Qt::Key_Q), this}
@ -59,7 +59,7 @@ LoginScreen::LoginScreen(QWidget* parent)
connect(ui->autoLoginCB, &QCheckBox::stateChanged, this, &LoginScreen::onAutoLoginToggled); connect(ui->autoLoginCB, &QCheckBox::stateChanged, this, &LoginScreen::onAutoLoginToggled);
connect(ui->importButton, &QPushButton::clicked, this, &LoginScreen::onImportProfile); connect(ui->importButton, &QPushButton::clicked, this, &LoginScreen::onImportProfile);
reset(); reset(initialProfile);
this->setStyleSheet(Style::getStylesheet(":/ui/loginScreen/loginScreen.css")); this->setStyleSheet(Style::getStylesheet(":/ui/loginScreen/loginScreen.css"));
retranslateUi(); retranslateUi();
@ -75,7 +75,7 @@ LoginScreen::~LoginScreen()
/** /**
* @brief Resets the UI, clears all fields. * @brief Resets the UI, clears all fields.
*/ */
void LoginScreen::reset() void LoginScreen::reset(QString initialProfile)
{ {
ui->newUsername->clear(); ui->newUsername->clear();
ui->newPass->clear(); ui->newPass->clear();
@ -84,13 +84,16 @@ void LoginScreen::reset()
ui->loginUsernames->clear(); ui->loginUsernames->clear();
Profile::scanProfiles(); Profile::scanProfiles();
QString lastUsed = Settings::getInstance().getCurrentProfile(); if (initialProfile.isEmpty()) {
initialProfile = Settings::getInstance().getCurrentProfile();
}
QVector<QString> profiles = Profile::getProfiles(); QVector<QString> profiles = Profile::getProfiles();
for (QString profile : profiles) { for (QString profile : profiles) {
ui->loginUsernames->addItem(profile); ui->loginUsernames->addItem(profile);
if (profile == lastUsed) if (profile == initialProfile) {
ui->loginUsernames->setCurrentIndex(ui->loginUsernames->count() - 1); ui->loginUsernames->setCurrentIndex(ui->loginUsernames->count() - 1);
} }
}
if (profiles.isEmpty()) { if (profiles.isEmpty()) {
ui->stackedWidget->setCurrentIndex(0); ui->stackedWidget->setCurrentIndex(0);

View File

@ -36,9 +36,9 @@ class LoginScreen : public QDialog
Q_OBJECT Q_OBJECT
public: public:
explicit LoginScreen(QWidget* parent = nullptr); LoginScreen(QString selectedProfile = QString(), QWidget* parent = nullptr);
~LoginScreen(); ~LoginScreen();
void reset(); void reset(QString selectedProfile = QString());
Profile* getProfile() const; Profile* getProfile() const;
bool event(QEvent* event) final override; bool event(QEvent* event) final override;