1 /* 2 * Copyright (C) 2009, 2010, 2011, 2013, 2014 Nicolas Bonnefon and other contributors 3 * 4 * This file is part of glogg. 5 * 6 * glogg 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 * glogg 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 glogg. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #ifndef MAINWINDOW_H 21 #define MAINWINDOW_H 22 23 #include <memory> 24 #include <QMainWindow> 25 26 #include "session.h" 27 #include "crawlerwidget.h" 28 #include "infoline.h" 29 #include "signalmux.h" 30 #include "tabbedcrawlerwidget.h" 31 #include "quickfindwidget.h" 32 #include "quickfindmux.h" 33 #ifdef GLOGG_SUPPORTS_VERSION_CHECKING 34 #include "versionchecker.h" 35 #endif 36 #include "utils.h" 37 38 class QAction; 39 class QActionGroup; 40 class Session; 41 class RecentFiles; 42 class MenuActionToolTipBehavior; 43 class ExternalCommunicator; 44 45 // Main window of the application, creates menus, toolbar and 46 // the CrawlerWidget 47 class MainWindow : public QMainWindow 48 { 49 Q_OBJECT 50 51 public: 52 // Constructor 53 // The ownership of the session is transferred to us 54 MainWindow( std::unique_ptr<Session> session, 55 std::shared_ptr<ExternalCommunicator> external_communicator ); 56 57 // Re-install the geometry stored in config file 58 // (should be done before 'Widget::show()') 59 void reloadGeometry(); 60 // Re-load the files from the previous session 61 void reloadSession(); 62 // Loads the initial file (parameter passed or from config file) 63 void loadInitialFile( QString fileName ); 64 // Starts the lower priority activities the MW controls such as 65 // version checking etc... 66 void startBackgroundTasks(); 67 68 protected: 69 void closeEvent( QCloseEvent* event ); 70 // Drag and drop support 71 void dragEnterEvent( QDragEnterEvent* event ); 72 void dropEvent( QDropEvent* event ); 73 void keyPressEvent( QKeyEvent* keyEvent ); 74 75 private slots: 76 void open(); 77 void openRecentFile(); 78 void closeTab(); 79 void closeAll(); 80 void selectAll(); 81 void copy(); 82 void find(); 83 void filters(); 84 void options(); 85 void about(); 86 void aboutQt(); 87 void encodingChanged( QAction* action ); 88 89 // Change the view settings 90 void toggleOverviewVisibility( bool isVisible ); 91 void toggleMainLineNumbersVisibility( bool isVisible ); 92 void toggleFilteredLineNumbersVisibility( bool isVisible ); 93 94 // Change the follow mode checkbox and send the followSet signal down 95 void changeFollowMode( bool follow ); 96 97 // Update the line number displayed in the status bar. 98 // Must be passed as the internal (starts at 0) line number. 99 void lineNumberHandler( int line ); 100 101 // Instructs the widget to update the loading progress gauge 102 void updateLoadingProgress( int progress ); 103 // Instructs the widget to display the 'normal' status bar, 104 // without the progress gauge and with file info 105 // or an error recovery when loading is finished 106 void handleLoadingFinished( LoadingStatus status ); 107 108 // Save the new state as default setting when a crawler 109 // is changing their view options. 110 void handleSearchRefreshChanged( int state ); 111 void handleIgnoreCaseChanged( int state ); 112 113 // Close the tab with the passed index 114 void closeTab( int index ); 115 // Setup the tab with current index for view 116 void currentTabChanged( int index ); 117 118 // Instructs the widget to change the pattern in the QuickFind widget 119 // and confirm it. 120 void changeQFPattern( const QString& newPattern ); 121 122 // Load a file in a new tab (non-interactive) 123 // (for use from e.g. IPC) 124 void loadFileNonInteractive( const QString& file_name ); 125 126 // Notify the user a new version is available 127 void newVersionNotification( const QString& new_version ); 128 129 signals: 130 // Is emitted when new settings must be used 131 void optionsChanged(); 132 // Is emitted when the 'follow' option is enabled/disabled 133 void followSet( bool checked ); 134 // Is emitted before the QuickFind box is activated, 135 // to allow crawlers to get search in the right view. 136 void enteringQuickFind(); 137 // Emitted when the quickfind bar is closed. 138 void exitingQuickFind(); 139 140 private: 141 void createActions(); 142 void createMenus(); 143 void createContextMenu(); 144 void createToolBars(); 145 void createStatusBar(); 146 void createRecentFileToolTipTimer(); 147 void readSettings(); 148 void writeSettings(); 149 bool loadFile( const QString& fileName ); 150 void updateTitleBar( const QString& file_name ); 151 void updateRecentFileActions(); 152 QString strippedName( const QString& fullFileName ) const; 153 CrawlerWidget* currentCrawlerWidget() const; 154 void displayQuickFindBar( QuickFindMux::QFDirection direction ); 155 void updateMenuBarFromDocument( const CrawlerWidget* crawler ); 156 void updateInfoLine(); 157 158 std::unique_ptr<Session> session_; 159 std::shared_ptr<ExternalCommunicator> externalCommunicator_; 160 std::shared_ptr<RecentFiles> recentFiles_; 161 QString loadingFileName; 162 163 // Encoding 164 struct EncodingList { 165 const char* name; 166 }; 167 168 static const EncodingList encoding_list[]; 169 170 enum { MaxRecentFiles = 5 }; 171 QAction *recentFileActions[MaxRecentFiles]; 172 MenuActionToolTipBehavior *recentFileActionBehaviors[MaxRecentFiles]; 173 QAction *separatorAction; 174 175 QMenu *fileMenu; 176 QMenu *editMenu; 177 QMenu *viewMenu; 178 QMenu *toolsMenu; 179 QMenu *encodingMenu; 180 QMenu *helpMenu; 181 182 InfoLine *infoLine; 183 QLabel* lineNbField; 184 QToolBar *toolBar; 185 186 QAction *openAction; 187 QAction *closeAction; 188 QAction *closeAllAction; 189 QAction *exitAction; 190 QAction *copyAction; 191 QAction *selectAllAction; 192 QAction *findAction; 193 QAction *overviewVisibleAction; 194 QAction *lineNumbersVisibleInMainAction; 195 QAction *lineNumbersVisibleInFilteredAction; 196 QAction *followAction; 197 QAction *reloadAction; 198 QAction *stopAction; 199 QAction *filtersAction; 200 QAction *optionsAction; 201 QAction *aboutAction; 202 QAction *aboutQtAction; 203 QActionGroup *encodingGroup; 204 QAction *encodingAction[static_cast<int>( Encoding::ENCODING_MAX )]; 205 206 QIcon mainIcon_; 207 208 // Multiplex signals to any of the CrawlerWidgets 209 SignalMux signalMux_; 210 211 // QuickFind widget 212 QuickFindWidget quickFindWidget_; 213 214 // Multiplex signals to/from the QuickFindWidget 215 QuickFindMux quickFindMux_; 216 217 // The main widget 218 TabbedCrawlerWidget mainTabWidget_; 219 220 // Version checker 221 #ifdef GLOGG_SUPPORTS_VERSION_CHECKING 222 VersionChecker versionChecker_; 223 #endif 224 }; 225 226 #endif 227