mainwindow.h 4.99 KB
Newer Older
1 2
#ifndef MAINWINDOW_H_
#define MAINWINDOW_H_
3

4 5
#include "storemodel.h"
#include "trayicon.h"
6
#include <QFileSystemModel>
7
#include <QMainWindow>
8
#include <QProcess>
9
#include <QQueue>
10
#include <QSettings>
11
#include <QTimer>
12
#include <QTreeView>
13 14 15 16 17 18 19 20 21 22
#if SINGLE_APP
#include "singleapplication.h"
#else
#define SingleApplication QApplication
#endif

namespace Ui {
class MainWindow;
}

23 24
/*!
    \struct execQueueItem
Philip Rinn's avatar
Philip Rinn committed
25
    \brief Execution queue items for non-interactive ordered execution.
26
 */
27
struct execQueueItem {
28 29 30
  QString app;
  QString args;
  QString input;
31 32
};

33 34
struct UserInfo;

35 36 37 38 39 40 41
/*!
    \class MainWindow
    \brief The MainWindow class does way too much, not only is it a switchboard,
    configuration handler and more, it's also the process-manager.

    This class could really do with an overhaul.
 */
42 43
class MainWindow : public QMainWindow {
  Q_OBJECT
44

45
  enum actionType { GPG, GIT, EDIT, DELETE, GPG_INTERNAL, PWGEN };
46

47
public:
48 49 50 51 52
  enum clipBoardType {
    CLIPBOARD_NEVER = 0,
    CLIPBOARD_ALWAYS = 1,
    CLIPBOARD_ON_DEMAND = 2
  };
53

54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
  explicit MainWindow(QWidget *parent = 0);
  ~MainWindow();
  void setPassExecutable(QString);
  void setGitExecutable(QString);
  void setGpgExecutable(QString);
  QString getGpgExecutable();
  bool checkConfig();
  void setApp(SingleApplication *app);
  void setText(QString);
  QStringList getSecretKeys();
  void generateKeyPair(QString, QDialog *);
  void userDialog(QString = "");
  QString generatePassword();
  void config();
  void executePassGitInit();
69

70
protected:
71
  void closeEvent(QCloseEvent *event);
72
  void keyPressEvent(QKeyEvent *event);
73 74
  void changeEvent(QEvent *event);
  bool eventFilter(QObject *obj, QEvent *event);
75

76
private slots:
77 78 79
  void on_updateButton_clicked();
  void on_pushButton_clicked();
  void on_treeView_clicked(const QModelIndex &index);
80
  void on_treeView_doubleClicked(const QModelIndex &index);
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
  void on_configButton_clicked();
  void readyRead(bool finished);
  void processFinished(int, QProcess::ExitStatus);
  void processError(QProcess::ProcessError);
  void clearClipboard();
  void clearPanel();
  void on_lineEdit_textChanged(const QString &arg1);
  void on_lineEdit_returnPressed();
  void on_addButton_clicked();
  void on_deleteButton_clicked();
  void on_editButton_clicked();
  void on_usersButton_clicked();
  void messageAvailable(QString message);
  void on_profileBox_currentIndexChanged(QString);
  void on_copyPasswordButton_clicked();
  void showContextMenu(const QPoint &pos);
  void showBrowserContextMenu(const QPoint &pos);
  void addFolder();
  void editPassword();
  void focusInput();
  void copyPasswordToClipboard();

103
private:
104 105 106
  QAction *actionAddPassword;
  QAction *actionAddFolder;

107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
  QApplication *QtPass;
  QScopedPointer<QSettings> settings;
  QScopedPointer<Ui::MainWindow> ui;
  QFileSystemModel model;
  StoreModel proxyModel;
  QScopedPointer<QItemSelectionModel> selectionModel;
  QScopedPointer<QProcess> process;
  bool usePass;
  clipBoardType useClipboard;
  bool useAutoclear;
  bool useAutoclearPanel;
  bool hidePassword;
  bool hideContent;
  bool addGPGId;
  int autoclearSeconds;
  int autoclearPanelSeconds;
  QString passStore;
  QString passExecutable;
  QString gitExecutable;
  QString gpgExecutable;
  QString pwgenExecutable;
  QString gpgHome;
  bool useWebDav;
  QString webDavUrl;
  QString webDavUser;
  QString webDavPassword;
  QProcess fusedav;
  QString clippedPass;
  QString autoclearPass;
  QTimer *autoclearTimer;
  actionType currentAction;
  QString lastDecrypt;
  bool wrapperRunning;
  QStringList env;
  QQueue<execQueueItem> *execQueue;
  bool freshStart;
  QDialog *keygen;
  QString currentDir;
  QHash<QString, QString> profiles;
  QString profile;
  bool startupPhase;
  TrayIcon *tray;
  bool useTrayIcon;
  bool hideOnClose;
  bool startMinimized;
  bool useGit;
  bool usePwgen;
154 155 156
  bool avoidCapitals;
  bool avoidNumbers;
  bool lessRandom;
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
  bool useSymbols;
  int passwordLength;
  QString passwordChars;
  bool useTemplate;
  QString passTemplate;
  bool templateAllFields;
  bool autoPull;
  bool autoPush;
  bool alwaysOnTop;
  void updateText();
  void executePass(QString, QString = QString());
  void executeWrapper(QString, QString, QString = QString());
  void enableUiElements(bool state);
  void selectFirstFile();
  QModelIndex firstFile(QModelIndex parentIndex);
  QString getDir(const QModelIndex &, bool);
  QString getFile(const QModelIndex &, bool);
  void setPassword(QString, bool, bool);
  QSettings &getSettings();
  QList<UserInfo> listKeys(QString keystring = "", bool secret = false);
  QStringList getRecipientList(QString for_file);
  QString getRecipientString(QString for_file, QString separator = " ",
                             int *count = NULL);
  void mountWebDav();
  void updateEnv();
  void updateProfileBox();
  void initTrayIcon();
  void destroyTrayIcon();
  bool removeDir(const QString &dirName);
  void waitFor(int seconds);
  void clearTemplateWidgets();
  void setClippedPassword(const QString &pass);
  const QString &getClippedPassword();
190
  void reencryptPath(QString dir);
191 192
};

193
#endif // MAINWINDOW_H_