1 //=============================================================================
2 //  MuseScore
3 //  Music Composition & Notation
4 //
5 //  Copyright (C) 2014 Werner Schweer
6 //
7 //  This program is free software; you can redistribute it and/or modify
8 //  it under the terms of the GNU General Public License version 2
9 //  as published by the Free Software Foundation and appearing in
10 //  the file LICENCE.GPL
11 //=============================================================================
12 
13 #include "musescore.h"
14 #include "logindialog.h"
15 #include "loginmanager.h"
16 
17 namespace Ms {
18 
19 //---------------------------------------------------------
20 //   showLoginDialog
21 //---------------------------------------------------------
22 
showLoginDialog()23 void MuseScore::showLoginDialog()
24       {
25       if (loginDialog == nullptr) {
26             loginDialog = new LoginDialog(loginManager());
27 
28             }
29       loginDialog->setVisible(true);
30       }
31 
32 //---------------------------------------------------------
33 //   LoginDialog
34 //---------------------------------------------------------
35 
LoginDialog(LoginManager * loginManager)36 LoginDialog::LoginDialog(LoginManager* loginManager)
37  : QDialog(0)
38       {
39       setObjectName("LoginDialog");
40       setupUi(this);
41       setStyleSheet("QLineEdit { "
42             "padding: 8px 8px;"
43       "}");
44 
45       setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
46       connect(buttonBox,   SIGNAL(clicked(QAbstractButton*)), SLOT(buttonBoxClicked(QAbstractButton*)));
47       _loginManager = loginManager;
48       createAccountLabel->setText("<a href=\"https://musescore.com/user/register\">" + tr("Create an account") + "</a>");
49       forgotPasswordLabel->setText("<a href=\"https://musescore.com/user/password\">" + tr("Forgot password?") + "</a>");
50       connect(_loginManager, SIGNAL(loginSuccess()), this, SLOT(onLoginSuccess()));
51       connect(_loginManager, SIGNAL(loginError(const QString&)), this, SLOT(onLoginError(const QString&)));
52 
53       MuseScore::restoreGeometry(this);
54       }
55 
56 //---------------------------------------------------------
57 //   buttonBoxClicked
58 //---------------------------------------------------------
59 
buttonBoxClicked(QAbstractButton * button)60 void LoginDialog::buttonBoxClicked(QAbstractButton* button)
61       {
62       QDialogButtonBox::StandardButton sb = buttonBox->standardButton(button);
63       if (sb == QDialogButtonBox::Ok) {
64             if (usernameEdit->text().trimmed().isEmpty() || passwordEdit->text().trimmed().isEmpty())
65                   QMessageBox::critical(this, tr("Login error"), tr("Please fill in your username and password"));
66             login();
67             }
68       else
69            setVisible(false);
70       }
71 
72 //---------------------------------------------------------
73 //   login
74 //---------------------------------------------------------
75 
login()76 void LoginDialog::login()
77       {
78       _loginManager->login(usernameEdit->text(), passwordEdit->text());
79       }
80 
81 //---------------------------------------------------------
82 //   onLoginError
83 //---------------------------------------------------------
84 
onLoginError(const QString & error)85 void LoginDialog::onLoginError(const QString& error)
86       {
87       QMessageBox::critical(this, tr("Login error"), error);
88       }
89 
90 //---------------------------------------------------------
91 //   onLoginSuccess
92 //---------------------------------------------------------
93 
onLoginSuccess()94 void LoginDialog::onLoginSuccess()
95       {
96       emit loginSuccessful();
97       setVisible(false);
98       }
99 
100 //---------------------------------------------------------
101 //   hideEvent
102 //---------------------------------------------------------
103 
hideEvent(QHideEvent * event)104 void LoginDialog::hideEvent(QHideEvent* event)
105       {
106       MuseScore::saveGeometry(this);
107       QDialog::hideEvent(event);
108       }
109 
110 }
111 
112