1 /* vi: set sw=4 ts=4:
2  *
3  * Copyright (C) 2001 - 2015 Christian Hohnstaedt.
4  *
5  * All rights reserved.
6  */
7 
8 #ifndef __MAINWINDOW_H
9 #define __MAINWINDOW_H
10 
11 #include "ui_MainWindow.h"
12 
13 #include "lib/oid.h"
14 #include "lib/Passwd.h"
15 #include "lib/main.h"
16 #include "lib/database_model.h"
17 #include "lib/dbhistory.h"
18 
19 #include <QList>
20 #include <QMenu>
21 #include <QToolTip>
22 #include <QProgressBar>
23 
24 class db_x509;
25 class pki_multi;
26 class NewX509;
27 class OidResolver;
28 class QProgressBar;
29 class DHgen;
30 class Help;
31 
32 class tipMenu : public QMenu
33 {
34 	Q_OBJECT
35 
36     public:
tipMenu(QString n,QWidget * w)37 	tipMenu(QString n, QWidget *w) : QMenu(n, w) {}
event(QEvent * e)38 	bool event (QEvent * e)
39 	{
40 		const QHelpEvent *helpEvent = static_cast <QHelpEvent *>(e);
41 		if (helpEvent->type() == QEvent::ToolTip && activeAction() &&
42 		    activeAction()->toolTip() != activeAction()->text()) {
43 			QToolTip::showText(helpEvent->globalPos(),
44 				activeAction()->toolTip());
45 		} else {
46 			QToolTip::hideText();
47 		}
48 		return QMenu::event(e);
49 	}
50 };
51 
52 class MainWindow: public QMainWindow, public Ui::MainWindow
53 {
54 	Q_OBJECT
55 
56 	private:
57 		static OidResolver *resolver;
58 		QString string_opt;
59 		QList<QWidget*> wdList;
60 		QList<QWidget*> wdMenuList;
61 		QList<QWidget*> scardList;
62 		QList<QAction*> acList;
63 		tipMenu *historyMenu;
64 		void set_geometry(QString geo);
65 		QLineEdit *searchEdit;
66 		QStringList urlsToOpen;
67 		int checkOldGetNewPass(Passwd &pass);
68 		void checkDB();
69 		QProgressBar *dhgenBar;
70 		DHgen *dhgen;
71 		const QList<QStringList> getTranslators() const;
72 		QList<XcaTreeView *> views;
73 		dbhistory history;
74 		void exportIndex(const QString &fname, bool hierarchy) const;
75 
76 	protected:
77 		void init_images();
78 		void init_menu();
79 		int force_load;
80 		NIDlist *read_nidlist(QString name);
81 		QLabel *statusLabel;
82 		QString homedir;
83 		void keyPressEvent(QKeyEvent *e);
84 		void update_history_menu();
85 
86 	public:
87 		int exitApp;
88 		QLabel *dbindex;
89 		Help *helpdlg;
90 		MainWindow();
91 		virtual ~MainWindow();
92 		void loadSettings();
93 		void saveSettings();
94 		void load_engine();
getResolver()95 		static OidResolver *getResolver()
96 		{
97 			return resolver;
98 		}
99 		bool mkDir(QString dir);
100 		void setItemEnabled(bool enable);
101 		void enableTokenMenu(bool enable);
102 		void importAnything(QString file);
103 		void importAnything(const QStringList &files);
104 		void importMulti(pki_multi *multi, int force);
105 		void dropEvent(QDropEvent *event);
106 		void dragEnterEvent(QDragEnterEvent *event);
107 		void initResolver();
108 
109 	public slots:
110 		enum open_result init_database(const QString &dbName,
111 				const Passwd &pass = Passwd());
112 		enum open_result setup_open_database();
113 		void new_database();
114 		void load_database();
115 		void close_database();
116 		void dump_database();
117 		void default_database();
118 		void about();
119 		void loadPem();
120 		bool pastePem(QString text, bool silent=false);
121 		void pastePem();
122 		void changeDbPass();
123 		void openURLs(QStringList &files);
124 		void openURLs();
125 		void changeEvent(QEvent *event);
126 		void exportIndex();
127 		void exportIndexHierarchy();
128 		void openRemoteSqlDB();
129 		void generateDHparamDone();
130 
131 	protected slots:
132 		void closeEvent(QCloseEvent * event);
133 
134 	private slots:
135 		void setOptions();
136 		void manageToken();
137 		void initToken();
138 		void changePin(bool so=false);
139 		void changeSoPin();
140 		void initPin();
141 		void generateDHparam();
142 		void open_database(QAction* a);
143 };
144 #endif
145