1 /* 2 Actiona 3 Copyright (C) 2005 Jonathan Mercier-Ganady 4 5 Actiona is free software: you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation, either version 3 of the License, or 8 (at your option) any later version. 9 10 Actiona is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18 Contact : jmgr@jmgr.info 19 */ 20 21 #pragma once 22 23 #include "script.h" 24 #include "executer.h" 25 #include "heatmapmode.h" 26 27 #include <QMainWindow> 28 #ifndef ACT_NO_UPDATER 29 #include <QCryptographicHash> 30 #include <QFile> 31 #endif 32 33 #include <memory> 34 35 namespace Ui 36 { 37 class MainWindow; 38 } 39 40 namespace ActionTools 41 { 42 class ActionFactory; 43 class ActionInstance; 44 class ActionDefinition; 45 } 46 47 namespace Tools 48 { 49 class Updater; 50 } 51 52 class QToolBox; 53 class QSystemTrayIcon; 54 class ScriptModel; 55 class ProgressSplashScreen; 56 class QTreeWidget; 57 class QTreeWidgetItem; 58 class NewActionModel; 59 class QNetworkReply; 60 class QFile; 61 class QProgressDialog; 62 class QUndoGroup; 63 class QStandardItemModel; 64 class QCommandLineParser; 65 class QNetworkAccessManager; 66 class ActionDialog; 67 class QModelIndex; 68 class NewActionProxyModel; 69 class ScriptProxyModel; 70 class QHotkey; 71 72 #ifdef Q_OS_WIN 73 class QWinTaskbarButton; 74 class QWinTaskbarProgress; 75 #endif 76 77 #include <QNetworkReply> 78 #include <QSystemTrayIcon> 79 80 class MainWindow : public QMainWindow 81 { 82 Q_OBJECT 83 public: 84 MainWindow(QCommandLineParser &commandLineParser, ProgressSplashScreen *splashScreen, const QString &startScript, const QString &usedLocale); 85 ~MainWindow() override; 86 87 signals: 88 void needToShow(); 89 90 public slots: 91 void otherInstanceMessage(const QString &message); 92 93 private slots: 94 void postInit(); 95 void on_actionSave_triggered(); 96 void on_actionSave_as_triggered(); 97 void on_actionSave_copy_as_triggered(); 98 void on_actionOpen_triggered(); 99 void on_actionNew_triggered(); 100 void on_actionQuit_triggered(); 101 void on_deleteDropTarget_clicked(); 102 void on_actionDelete_action_triggered(); 103 void on_actionDelete_all_actions_triggered(); 104 void on_actionSelect_all_actions_triggered(); 105 void on_actionSelect_none_triggered(); 106 void on_actionInverse_selection_triggered(); 107 void on_actionAbout_triggered(); 108 void on_actionClear_triggered(); 109 void on_actionExport_executable_triggered(); 110 void on_actionSettings_triggered(); 111 void on_actionParameters_triggered(); 112 void on_actionMove_up_triggered(); 113 void on_actionMove_down_triggered(); 114 void on_actionExecute_triggered(); 115 void on_actionExecute_selection_triggered(); 116 void on_actionCut_triggered(); 117 void on_actionCopy_triggered(); 118 void on_actionPaste_triggered(); 119 void on_actionUndo_triggered(); 120 void on_actionRedo_triggered(); 121 void on_actionSet_action_color_triggered(); 122 void on_actionClear_selection_color_triggered(); 123 void on_actionEnable_all_actions_triggered(); 124 void on_actionDisable_all_actions_triggered(); 125 void on_actionEnable_selection_triggered(); 126 void on_actionDisable_selection_triggered(); 127 void on_actionNew_action_triggered(); 128 void on_actionEdit_action_triggered(); 129 void on_actionJump_to_line_triggered(); 130 void on_actionCheck_for_updates_triggered(); 131 void on_actionCreate_shortcut_triggered(); 132 void on_actionImport_script_content_triggered(); 133 void on_actionExport_script_content_triggered(); 134 void on_actionScriptSettings_triggered(); 135 void on_actionResources_triggered(); 136 void on_scriptView_customContextMenuRequested(const QPoint &pos); 137 void on_actionHelp_triggered(); 138 void on_actionTake_screenshot_triggered(); 139 void on_actionsfilterLineEdit_textChanged(const QString &text); 140 void on_scriptFilterLineEdit_textChanged(const QString &text); 141 void on_scriptFilterCriteriaFlagsComboBox_flagsChanged(unsigned int flags); 142 void systemTrayIconActivated(QSystemTrayIcon::ActivationReason reason); 143 void scriptEdited(); 144 void actionSelectionChanged(); 145 void editAction(const QModelIndex &index); 146 void wantToAddAction(const QString &actionId); 147 void wantToAddAction(int row, const QString &actionId); 148 void scriptFileDropped(const QString &scriptFilename); 149 void scriptContentDropped(const QString &scriptContent); 150 void addAction(); 151 void openRecentFile(); 152 void newActionDoubleClicked(const QModelIndex &index); 153 void actionEnabled(); 154 void packLoadError(const QString &error); 155 void stopExecution(); 156 void startOrStopExecution(); 157 void pauseOrResumeExecution(); 158 void scriptExecutionStopped(); 159 void postExecution(); 160 void logItemDoubleClicked(int itemRow); 161 void logItemClicked(int itemRow); 162 #ifndef ACT_NO_UPDATER 163 void updateError(const QString &message); 164 void updateNoResult(); 165 void updateSuccess(const Tools::Version &version, 166 const QDate &releaseDate, 167 const QString &type, 168 const QString &changelog, 169 const QString &filename, 170 int size, 171 const QString &hash); 172 void updateCanceled(); 173 void updateDownloadProgress(qint64 bytesReceived, qint64 bytesTotal); 174 void updateDownloadFinished(); 175 void updateDownloadDataAvailable(); 176 void updateDownloadCanceled(); 177 void postDownloadOperation(); 178 #endif 179 180 protected: 181 void showEvent(QShowEvent *event) override; 182 183 private: 184 void logItemClicked(int itemRow, bool doubleClick); 185 void updateUndoRedoStatus(); 186 void execute(bool onlySelection); 187 void fillNewActionModel(); 188 ActionDialog *actionDialog(ActionTools::ActionInstance *actionInstance); 189 bool editAction(ActionTools::ActionInstance *actionInstance, const QString &field = QString(), const QString &subField = QString(), int line = -1, int column = -1); 190 bool editAction(ActionTools::ActionInstance *actionInstance, int exception); 191 void openParametersDialog(int parameter = -1, int line = -1, int column = -1); 192 void openResourceDialog(const QString &resource = QString()); 193 QList<int> selectedRows() const; 194 bool loadFile(const QString &fileName, bool verbose = true); 195 bool saveFile(const QString &fileName, bool copy = false); 196 void setCurrentFile(const QString &fileName); 197 void closeEvent(QCloseEvent *event) override; 198 bool maybeSave(); 199 bool save(); 200 bool saveAs(); 201 void deleteSelection(); 202 void actionSelectionChanged(int selectionCount); 203 void actionCountChanged(); 204 void enabledActionsCountChanged(bool hasEnabledActions); 205 void scriptWasModified(bool modified); 206 void readSettings(); 207 void writeSettings(); 208 void updateRecentFileActions(); 209 void updateProxySettings(); 210 bool checkReadResult(ActionTools::Script::ReadResult result); 211 void setTaskbarProgress(int value, int max); 212 void enableTaskbarProgress(bool enable); 213 ActionTools::Script::ReadResult readScript(QIODevice *device); 214 bool writeScript(QIODevice *device); 215 std::unique_ptr<QProgressDialog> createStandardProgressDialog(); 216 ActionDialog *getOrCreateActionDialog(const ActionTools::ActionDefinition *actionDefinition); 217 #ifndef ACT_NO_UPDATER 218 void checkForUpdate(bool silent); 219 #endif 220 221 Ui::MainWindow *ui; 222 bool mScriptModified; 223 QString mCurrentFile; 224 int mMaxRecentFiles; 225 QList<QAction *> mRecentFileActs; 226 ActionTools::ActionFactory *mActionFactory; 227 ActionTools::Script *mScript; 228 ScriptModel *mScriptModel; 229 QSystemTrayIcon *mSystemTrayIcon; 230 ProgressSplashScreen *mSplashScreen; 231 QFile *mFile; 232 QStringList mPackLoadErrors; 233 LibExecuter::Executer mExecuter; 234 bool mWasNewActionDockShown; 235 bool mWasConsoleDockShown; 236 QUndoGroup *mUndoGroup; 237 QPoint mPreviousWindowPosition; 238 QStandardItemModel *mCompletionModel; 239 QString mStartScript; 240 QCommandLineParser &mCommandLineParser; 241 int mAddActionRow; 242 QString mAddAction; 243 QAction *mStopExecutionAction; 244 QMap<int, ActionDialog *> mActionDialogs; 245 QString mUsedLocale; 246 NewActionProxyModel *mNewActionProxyModel; 247 ScriptProxyModel *mScriptProxyModel; 248 NewActionModel *mNewActionModel; 249 HeatmapMode mHeatmapMode; 250 QHotkey *mStartStopExecutionHotkey; 251 QHotkey *mPauseExecutionHotkey; 252 #ifndef ACT_NO_UPDATER 253 QNetworkAccessManager *mNetworkAccessManager; 254 QNetworkReply *mUpdateDownloadNetworkReply; 255 Tools::Updater *mUpdater; 256 bool mSilentUpdate; 257 QProgressDialog *mUpdaterProgressDialog; 258 bool mInstallAfterUpdateDownload; 259 QFile mUpdateFile; 260 int mUpdateFileSize; 261 QString mUpdateFileHash; 262 QCryptographicHash mHashCalculator; 263 #endif 264 #ifdef Q_OS_WIN 265 QWinTaskbarButton *mTaskbarButton; 266 QWinTaskbarProgress* mTaskbarProgress; 267 #endif 268 269 Q_DISABLE_COPY(MainWindow) 270 }; 271 272