1 /*
2 Copyright (C) 2011-2014 Yubico AB.  All rights reserved.
3 
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are
6 met:
7 
8    1. Redistributions of source code must retain the above copyright
9       notice, this list of conditions and the following disclaimer.
10 
11    2. Redistributions in binary form must reproduce the above
12       copyright notice, this list of conditions and the following
13       disclaimer in the documentation and/or other materials provided
14       with the distribution.
15 
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef MAINWINDOW_H
30 #define MAINWINDOW_H
31 
32 #include <QMainWindow>
33 #include "qtimer.h"
34 
35 class ToolPage;
36 class OtpPage;
37 class OathPage;
38 class StaticPage;
39 class ChalRespPage;
40 class SettingPage;
41 class AboutPage;
42 
43 class Diagnostics;
44 class HelpBox;
45 
46 class QStackedWidget;
47 
48 namespace Ui {
49     class MainWindow;
50 }
51 
52 class MainWindow : public QMainWindow {
53     Q_OBJECT
54 
55 public:
56     explicit MainWindow(QWidget *parent = 0);
57     ~MainWindow();
58 
59     enum Page {
60         Page_Otp,
61         Page_Oath,
62         Page_Static,
63         Page_ChalResp,
64         Page_Settings,
65         Page_Tools,
66         Page_About
67     };
68 
69 private:
70     Ui::MainWindow *ui;
71 
72     int m_currentPage;
73 
74     OtpPage *m_otpPage;
75     OathPage *m_oathPage;
76     StaticPage *m_staticPage;
77     ChalRespPage *m_chalRespPage;
78     SettingPage *m_settingPage;
79     ToolPage *m_toolPage;
80     AboutPage *m_aboutPage;
81 
82     Diagnostics *m_diagnostics;
83     HelpBox *m_help;
84 
85     QTimer *m_timer;
86 
87     QAction *animationAction;
88     QAction *diagnosticsAction;
89 
90     void createPages();
91 
92 private slots:
93     void setCurrentPage(int pageIndex, int tab = 0, int slot = 0);
94 
95     // Device Widget
96     void resetDeviceInfo();
97     void keyFound(bool found, bool* featuresMatrix, int error);
98 
99     // Status Widget
100     void showStatusMessage(const QString &text, int status = 1);
101     void clearStatusMessage();
102 
103     void copyToClipboard(const QString &str);
104     void on_serialNoDecCopyBtn_clicked();
105     void on_serialNoHexCopyBtn_clicked();
106     void on_serialNoModhexCopyBtn_clicked();
107 
108     void toggleAnimation(bool checked);
109     void triggerDiagnostics();
110     void triggerHelp(int index);
111 
112     void aboutToQuit();
113 };
114 
115 #endif // MAINWINDOW_H
116