1 /* 2 This file was part of Clementine. 3 Copyright 2010, David Sansome <me@davidsansome.com> 4 Copyright 2018-2021, Jonas Kvinge <jonas@jkvinge.net> 5 6 Strawberry is free software: you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 Strawberry is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with Strawberry. If not, see <http://www.gnu.org/licenses/>. 18 19 */ 20 21 #ifndef LOGINSTATEWIDGET_H 22 #define LOGINSTATEWIDGET_H 23 24 #include "config.h" 25 26 #include <QWidget> 27 #include <QObject> 28 #include <QList> 29 #include <QString> 30 #include <QDate> 31 32 class QEvent; 33 34 class Ui_LoginStateWidget; 35 36 class LoginStateWidget : public QWidget { 37 Q_OBJECT 38 39 public: 40 explicit LoginStateWidget(QWidget *parent = nullptr); 41 ~LoginStateWidget() override; 42 43 enum State { LoggedIn, LoginInProgress, LoggedOut }; 44 45 // Installs an event handler on the field so that pressing enter will emit 46 // LoginClicked() instead of doing the default action (closing the dialog). 47 void AddCredentialField(QWidget *widget); 48 49 // This widget (usually a QGroupBox) will be hidden when SetLoggedIn(true) is called. 50 void AddCredentialGroup(QWidget *widget); 51 52 // QObject 53 bool eventFilter(QObject *object, QEvent *event) override; 54 55 public slots: 56 // Changes the "You are logged in/out" label, shows/hides any QGroupBoxes added with AddCredentialGroup. 57 void SetLoggedIn(const LoginStateWidget::State state, const QString &account_name = QString()); 58 59 // Hides the "You are logged in/out" label completely. 60 void HideLoggedInState(); 61 62 void SetAccountTypeText(const QString &text); 63 void SetAccountTypeVisible(const bool visible); 64 65 void SetExpires(const QDate expires); 66 67 signals: 68 void LogoutClicked(); 69 void LoginClicked(); 70 71 private slots: 72 void Logout(); 73 void FocusLastCredentialField(); 74 75 private: 76 Ui_LoginStateWidget *ui_; 77 78 State state_; 79 80 QList<QObject*> credential_fields_; 81 QList<QWidget*> credential_groups_; 82 }; 83 84 #endif // LOGINSTATEWIDGET_H 85