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 34 class QAction; 35 class Session; 36 class RecentFiles; 37 class MenuActionToolTipBehavior; 38 class ExternalCommunicator; 39 40 // Main window of the application, creates menus, toolbar and 41 // the CrawlerWidget 42 class MainWindow : public QMainWindow 43 { 44 Q_OBJECT 45 46 public: 47 // Constructor 48 // The ownership of the session is transferred to us 49 MainWindow( std::unique_ptr<Session> session, 50 std::shared_ptr<ExternalCommunicator> external_communicator ); 51 52 // Re-load the files from the previous session 53 void reloadSession(); 54 // Loads the initial file (parameter passed or from config file) 55 void loadInitialFile( QString fileName ); 56 // Starts the lower priority activities the MW controls such as 57 // version checking etc... 58 void startBackgroundTasks(); 59 60 protected: 61 void closeEvent( QCloseEvent* event ); 62 // Drag and drop support 63 void dragEnterEvent( QDragEnterEvent* event ); 64 void dropEvent( QDropEvent* event ); 65 void keyPressEvent( QKeyEvent* keyEvent ); 66 67 private slots: 68 void open(); 69 void openRecentFile(); 70 void selectAll(); 71 void copy(); 72 void find(); 73 void filters(); 74 void options(); 75 void about(); 76 void aboutQt(); 77 78 // Change the view settings 79 void toggleOverviewVisibility( bool isVisible ); 80 void toggleMainLineNumbersVisibility( bool isVisible ); 81 void toggleFilteredLineNumbersVisibility( bool isVisible ); 82 83 // Disable the follow mode checkbox and send the followSet signal down 84 void disableFollow(); 85 86 // Update the line number displayed in the status bar. 87 // Must be passed as the internal (starts at 0) line number. 88 void lineNumberHandler( int line ); 89 90 // Instructs the widget to update the loading progress gauge 91 void updateLoadingProgress( int progress ); 92 // Instructs the widget to display the 'normal' status bar, 93 // without the progress gauge and with file info 94 // or an error recovery when loading is finished 95 void handleLoadingFinished( LoadingStatus status ); 96 97 // Close the tab with the passed index 98 void closeTab( int index ); 99 // Setup the tab with current index for view 100 void currentTabChanged( int index ); 101 102 // Instructs the widget to change the pattern in the QuickFind widget 103 // and confirm it. 104 void changeQFPattern( const QString& newPattern ); 105 106 // Load a file in a new tab (non-interactive) 107 // (for use from e.g. IPC) 108 void loadFileNonInteractive( const QString& file_name ); 109 110 signals: 111 // Is emitted when new settings must be used 112 void optionsChanged(); 113 // Is emitted when the 'follow' option is enabled/disabled 114 void followSet( bool checked ); 115 // Is emitted before the QuickFind box is activated, 116 // to allow crawlers to get search in the right view. 117 void enteringQuickFind(); 118 // Emitted when the quickfind bar is closed. 119 void exitingQuickFind(); 120 121 private: 122 void createActions(); 123 void createMenus(); 124 void createContextMenu(); 125 void createToolBars(); 126 void createStatusBar(); 127 void createRecentFileToolTipTimer(); 128 void readSettings(); 129 void writeSettings(); 130 bool loadFile( const QString& fileName ); 131 void updateTitleBar( const QString& file_name ); 132 void updateRecentFileActions(); 133 QString strippedName( const QString& fullFileName ) const; 134 CrawlerWidget* currentCrawlerWidget() const; 135 void displayQuickFindBar( QuickFindMux::QFDirection direction ); 136 137 std::unique_ptr<Session> session_; 138 std::shared_ptr<ExternalCommunicator> externalCommunicator_; 139 std::shared_ptr<RecentFiles> recentFiles_; 140 QString loadingFileName; 141 142 enum { MaxRecentFiles = 5 }; 143 QAction *recentFileActions[MaxRecentFiles]; 144 MenuActionToolTipBehavior *recentFileActionBehaviors[MaxRecentFiles]; 145 QAction *separatorAction; 146 147 QMenu *fileMenu; 148 QMenu *editMenu; 149 QMenu *viewMenu; 150 QMenu *toolsMenu; 151 QMenu *helpMenu; 152 153 InfoLine *infoLine; 154 QLabel* lineNbField; 155 QToolBar *toolBar; 156 157 QAction *openAction; 158 QAction *exitAction; 159 QAction *copyAction; 160 QAction *selectAllAction; 161 QAction *findAction; 162 QAction *overviewVisibleAction; 163 QAction *lineNumbersVisibleInMainAction; 164 QAction *lineNumbersVisibleInFilteredAction; 165 QAction *followAction; 166 QAction *reloadAction; 167 QAction *stopAction; 168 QAction *filtersAction; 169 QAction *optionsAction; 170 QAction *aboutAction; 171 QAction *aboutQtAction; 172 173 QIcon mainIcon_; 174 175 // Multiplex signals to any of the CrawlerWidgets 176 SignalMux signalMux_; 177 178 // QuickFind widget 179 QuickFindWidget quickFindWidget_; 180 181 // Multiplex signals to/from the QuickFindWidget 182 QuickFindMux quickFindMux_; 183 184 // The main widget 185 TabbedCrawlerWidget mainTabWidget_; 186 }; 187 188 #endif 189