1bb02e0acSNicolas Bonnefon /* 2093a1bf6SNicolas Bonnefon * Copyright (C) 2009, 2010, 2011, 2013, 2014 Nicolas Bonnefon and other contributors 3bb02e0acSNicolas Bonnefon * 4bb02e0acSNicolas Bonnefon * This file is part of glogg. 5bb02e0acSNicolas Bonnefon * 6bb02e0acSNicolas Bonnefon * glogg is free software: you can redistribute it and/or modify 7bb02e0acSNicolas Bonnefon * it under the terms of the GNU General Public License as published by 8bb02e0acSNicolas Bonnefon * the Free Software Foundation, either version 3 of the License, or 9bb02e0acSNicolas Bonnefon * (at your option) any later version. 10bb02e0acSNicolas Bonnefon * 11bb02e0acSNicolas Bonnefon * glogg is distributed in the hope that it will be useful, 12bb02e0acSNicolas Bonnefon * but WITHOUT ANY WARRANTY; without even the implied warranty of 13bb02e0acSNicolas Bonnefon * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14bb02e0acSNicolas Bonnefon * GNU General Public License for more details. 15bb02e0acSNicolas Bonnefon * 16bb02e0acSNicolas Bonnefon * You should have received a copy of the GNU General Public License 17bb02e0acSNicolas Bonnefon * along with glogg. If not, see <http://www.gnu.org/licenses/>. 18bb02e0acSNicolas Bonnefon */ 19bb02e0acSNicolas Bonnefon 20bb02e0acSNicolas Bonnefon #ifndef MAINWINDOW_H 21bb02e0acSNicolas Bonnefon #define MAINWINDOW_H 22bb02e0acSNicolas Bonnefon 23d96f3f21SNicolas Bonnefon #include <memory> 24bb02e0acSNicolas Bonnefon #include <QMainWindow> 25d96f3f21SNicolas Bonnefon 26d96f3f21SNicolas Bonnefon #include "session.h" 27bb02e0acSNicolas Bonnefon #include "crawlerwidget.h" 28bb02e0acSNicolas Bonnefon #include "infoline.h" 29313a820fSNicolas Bonnefon #include "signalmux.h" 30093a1bf6SNicolas Bonnefon #include "tabbedcrawlerwidget.h" 31b423cd88SNicolas Bonnefon #include "quickfindwidget.h" 32b423cd88SNicolas Bonnefon #include "quickfindmux.h" 33431d01deSNicolas Bonnefon #ifdef GLOGG_SUPPORTS_VERSION_CHECKING 34431d01deSNicolas Bonnefon #include "versionchecker.h" 35431d01deSNicolas Bonnefon #endif 36*209000a6SNicolas Bonnefon #include "utils.h" 37bb02e0acSNicolas Bonnefon 38bb02e0acSNicolas Bonnefon class QAction; 395fa25391SNicolas Bonnefon class QActionGroup; 40d96f3f21SNicolas Bonnefon class Session; 41bb02e0acSNicolas Bonnefon class RecentFiles; 42bb02e0acSNicolas Bonnefon class MenuActionToolTipBehavior; 4309aff35dSNicolas Bonnefon class ExternalCommunicator; 44bb02e0acSNicolas Bonnefon 45bb02e0acSNicolas Bonnefon // Main window of the application, creates menus, toolbar and 46bb02e0acSNicolas Bonnefon // the CrawlerWidget 47bb02e0acSNicolas Bonnefon class MainWindow : public QMainWindow 48bb02e0acSNicolas Bonnefon { 49bb02e0acSNicolas Bonnefon Q_OBJECT 50bb02e0acSNicolas Bonnefon 51bb02e0acSNicolas Bonnefon public: 52d96f3f21SNicolas Bonnefon // Constructor 53d96f3f21SNicolas Bonnefon // The ownership of the session is transferred to us 5409aff35dSNicolas Bonnefon MainWindow( std::unique_ptr<Session> session, 5509aff35dSNicolas Bonnefon std::shared_ptr<ExternalCommunicator> external_communicator ); 56bb02e0acSNicolas Bonnefon 57d1edc4fcSNicolas Bonnefon // Re-install the geometry stored in config file 58d1edc4fcSNicolas Bonnefon // (should be done before 'Widget::show()') 59d1edc4fcSNicolas Bonnefon void reloadGeometry(); 608964a9adSNicolas Bonnefon // Re-load the files from the previous session 618964a9adSNicolas Bonnefon void reloadSession(); 62bb02e0acSNicolas Bonnefon // Loads the initial file (parameter passed or from config file) 63bb02e0acSNicolas Bonnefon void loadInitialFile( QString fileName ); 648a9275b2SNicolas Bonnefon // Starts the lower priority activities the MW controls such as 658a9275b2SNicolas Bonnefon // version checking etc... 668a9275b2SNicolas Bonnefon void startBackgroundTasks(); 67bb02e0acSNicolas Bonnefon 68bb02e0acSNicolas Bonnefon protected: 69bb02e0acSNicolas Bonnefon void closeEvent( QCloseEvent* event ); 70bb02e0acSNicolas Bonnefon // Drag and drop support 71bb02e0acSNicolas Bonnefon void dragEnterEvent( QDragEnterEvent* event ); 72bb02e0acSNicolas Bonnefon void dropEvent( QDropEvent* event ); 738570d8d2SNicolas Bonnefon void keyPressEvent( QKeyEvent* keyEvent ); 74bb02e0acSNicolas Bonnefon 75bb02e0acSNicolas Bonnefon private slots: 76bb02e0acSNicolas Bonnefon void open(); 77bb02e0acSNicolas Bonnefon void openRecentFile(); 7863dc3514SGustav Andersson void closeTab(); 7963dc3514SGustav Andersson void closeAll(); 80bb02e0acSNicolas Bonnefon void selectAll(); 81bb02e0acSNicolas Bonnefon void copy(); 82bb02e0acSNicolas Bonnefon void find(); 83bb02e0acSNicolas Bonnefon void filters(); 84bb02e0acSNicolas Bonnefon void options(); 85bb02e0acSNicolas Bonnefon void about(); 86bb02e0acSNicolas Bonnefon void aboutQt(); 875fa25391SNicolas Bonnefon void encodingChanged( QAction* action ); 88bb02e0acSNicolas Bonnefon 89bb02e0acSNicolas Bonnefon // Change the view settings 90bb02e0acSNicolas Bonnefon void toggleOverviewVisibility( bool isVisible ); 91bb02e0acSNicolas Bonnefon void toggleMainLineNumbersVisibility( bool isVisible ); 92bb02e0acSNicolas Bonnefon void toggleFilteredLineNumbersVisibility( bool isVisible ); 93bb02e0acSNicolas Bonnefon 94b297d2f4SNicolas Bonnefon // Change the follow mode checkbox and send the followSet signal down 95b297d2f4SNicolas Bonnefon void changeFollowMode( bool follow ); 96bb02e0acSNicolas Bonnefon 97bb02e0acSNicolas Bonnefon // Update the line number displayed in the status bar. 98bb02e0acSNicolas Bonnefon // Must be passed as the internal (starts at 0) line number. 99bb02e0acSNicolas Bonnefon void lineNumberHandler( int line ); 100bb02e0acSNicolas Bonnefon 101bb02e0acSNicolas Bonnefon // Instructs the widget to update the loading progress gauge 102bb02e0acSNicolas Bonnefon void updateLoadingProgress( int progress ); 103bb02e0acSNicolas Bonnefon // Instructs the widget to display the 'normal' status bar, 104bb02e0acSNicolas Bonnefon // without the progress gauge and with file info 105812146a8SNicolas Bonnefon // or an error recovery when loading is finished 106812146a8SNicolas Bonnefon void handleLoadingFinished( LoadingStatus status ); 107bb02e0acSNicolas Bonnefon 108f688be2eSNicolas Bonnefon // Save the new state as default setting when a crawler 109f688be2eSNicolas Bonnefon // is changing their view options. 110f688be2eSNicolas Bonnefon void handleSearchRefreshChanged( int state ); 111f688be2eSNicolas Bonnefon void handleIgnoreCaseChanged( int state ); 112f688be2eSNicolas Bonnefon 113cdd89779SNicolas Bonnefon // Close the tab with the passed index 114cdd89779SNicolas Bonnefon void closeTab( int index ); 115ee835f33SNicolas Bonnefon // Setup the tab with current index for view 116ee835f33SNicolas Bonnefon void currentTabChanged( int index ); 117bb02e0acSNicolas Bonnefon 1188570d8d2SNicolas Bonnefon // Instructs the widget to change the pattern in the QuickFind widget 1198570d8d2SNicolas Bonnefon // and confirm it. 1208570d8d2SNicolas Bonnefon void changeQFPattern( const QString& newPattern ); 1218570d8d2SNicolas Bonnefon 12209aff35dSNicolas Bonnefon // Load a file in a new tab (non-interactive) 12309aff35dSNicolas Bonnefon // (for use from e.g. IPC) 12409aff35dSNicolas Bonnefon void loadFileNonInteractive( const QString& file_name ); 12509aff35dSNicolas Bonnefon 126460de700SNicolas Bonnefon // Notify the user a new version is available 127460de700SNicolas Bonnefon void newVersionNotification( const QString& new_version ); 128460de700SNicolas Bonnefon 129bb02e0acSNicolas Bonnefon signals: 130bb02e0acSNicolas Bonnefon // Is emitted when new settings must be used 131bb02e0acSNicolas Bonnefon void optionsChanged(); 132bb02e0acSNicolas Bonnefon // Is emitted when the 'follow' option is enabled/disabled 133bb02e0acSNicolas Bonnefon void followSet( bool checked ); 1348570d8d2SNicolas Bonnefon // Is emitted before the QuickFind box is activated, 1358570d8d2SNicolas Bonnefon // to allow crawlers to get search in the right view. 1368570d8d2SNicolas Bonnefon void enteringQuickFind(); 1378570d8d2SNicolas Bonnefon // Emitted when the quickfind bar is closed. 1388570d8d2SNicolas Bonnefon void exitingQuickFind(); 139bb02e0acSNicolas Bonnefon 140bb02e0acSNicolas Bonnefon private: 141bb02e0acSNicolas Bonnefon void createActions(); 142bb02e0acSNicolas Bonnefon void createMenus(); 143bb02e0acSNicolas Bonnefon void createContextMenu(); 144bb02e0acSNicolas Bonnefon void createToolBars(); 145bb02e0acSNicolas Bonnefon void createStatusBar(); 146bb02e0acSNicolas Bonnefon void createRecentFileToolTipTimer(); 147bb02e0acSNicolas Bonnefon void readSettings(); 148bb02e0acSNicolas Bonnefon void writeSettings(); 149bb02e0acSNicolas Bonnefon bool loadFile( const QString& fileName ); 1500e97f16dSNicolas Bonnefon void updateTitleBar( const QString& file_name ); 151bb02e0acSNicolas Bonnefon void updateRecentFileActions(); 152bb02e0acSNicolas Bonnefon QString strippedName( const QString& fullFileName ) const; 15327ddfd3aSNicolas Bonnefon CrawlerWidget* currentCrawlerWidget() const; 154b423cd88SNicolas Bonnefon void displayQuickFindBar( QuickFindMux::QFDirection direction ); 1555fa25391SNicolas Bonnefon void updateMenuBarFromDocument( const CrawlerWidget* crawler ); 1565fa25391SNicolas Bonnefon void updateInfoLine(); 157bb02e0acSNicolas Bonnefon 158d96f3f21SNicolas Bonnefon std::unique_ptr<Session> session_; 15909aff35dSNicolas Bonnefon std::shared_ptr<ExternalCommunicator> externalCommunicator_; 16011582726SNicolas Bonnefon std::shared_ptr<RecentFiles> recentFiles_; 161bb02e0acSNicolas Bonnefon QString loadingFileName; 162bb02e0acSNicolas Bonnefon 1635fa25391SNicolas Bonnefon // Encoding 1645fa25391SNicolas Bonnefon struct EncodingList { 1655fa25391SNicolas Bonnefon const char* name; 1665fa25391SNicolas Bonnefon }; 1675fa25391SNicolas Bonnefon 1685fa25391SNicolas Bonnefon static const EncodingList encoding_list[]; 1695fa25391SNicolas Bonnefon 170bb02e0acSNicolas Bonnefon enum { MaxRecentFiles = 5 }; 171bb02e0acSNicolas Bonnefon QAction *recentFileActions[MaxRecentFiles]; 172bb02e0acSNicolas Bonnefon MenuActionToolTipBehavior *recentFileActionBehaviors[MaxRecentFiles]; 173bb02e0acSNicolas Bonnefon QAction *separatorAction; 174bb02e0acSNicolas Bonnefon 175bb02e0acSNicolas Bonnefon QMenu *fileMenu; 176bb02e0acSNicolas Bonnefon QMenu *editMenu; 177bb02e0acSNicolas Bonnefon QMenu *viewMenu; 178bb02e0acSNicolas Bonnefon QMenu *toolsMenu; 1795fa25391SNicolas Bonnefon QMenu *encodingMenu; 180bb02e0acSNicolas Bonnefon QMenu *helpMenu; 181bb02e0acSNicolas Bonnefon 182bb02e0acSNicolas Bonnefon InfoLine *infoLine; 183bb02e0acSNicolas Bonnefon QLabel* lineNbField; 184bb02e0acSNicolas Bonnefon QToolBar *toolBar; 185bb02e0acSNicolas Bonnefon 186bb02e0acSNicolas Bonnefon QAction *openAction; 18763dc3514SGustav Andersson QAction *closeAction; 18863dc3514SGustav Andersson QAction *closeAllAction; 189bb02e0acSNicolas Bonnefon QAction *exitAction; 190bb02e0acSNicolas Bonnefon QAction *copyAction; 191bb02e0acSNicolas Bonnefon QAction *selectAllAction; 192bb02e0acSNicolas Bonnefon QAction *findAction; 193bb02e0acSNicolas Bonnefon QAction *overviewVisibleAction; 194bb02e0acSNicolas Bonnefon QAction *lineNumbersVisibleInMainAction; 195bb02e0acSNicolas Bonnefon QAction *lineNumbersVisibleInFilteredAction; 196bb02e0acSNicolas Bonnefon QAction *followAction; 197bb02e0acSNicolas Bonnefon QAction *reloadAction; 198bb02e0acSNicolas Bonnefon QAction *stopAction; 199bb02e0acSNicolas Bonnefon QAction *filtersAction; 200bb02e0acSNicolas Bonnefon QAction *optionsAction; 201bb02e0acSNicolas Bonnefon QAction *aboutAction; 202bb02e0acSNicolas Bonnefon QAction *aboutQtAction; 2035fa25391SNicolas Bonnefon QActionGroup *encodingGroup; 204*209000a6SNicolas Bonnefon QAction *encodingAction[static_cast<int>( Encoding::ENCODING_MAX )]; 205bb02e0acSNicolas Bonnefon 206bb02e0acSNicolas Bonnefon QIcon mainIcon_; 207313a820fSNicolas Bonnefon 208313a820fSNicolas Bonnefon // Multiplex signals to any of the CrawlerWidgets 209313a820fSNicolas Bonnefon SignalMux signalMux_; 21027ddfd3aSNicolas Bonnefon 211b423cd88SNicolas Bonnefon // QuickFind widget 212b423cd88SNicolas Bonnefon QuickFindWidget quickFindWidget_; 213b423cd88SNicolas Bonnefon 214b423cd88SNicolas Bonnefon // Multiplex signals to/from the QuickFindWidget 215b423cd88SNicolas Bonnefon QuickFindMux quickFindMux_; 216b423cd88SNicolas Bonnefon 21727ddfd3aSNicolas Bonnefon // The main widget 218093a1bf6SNicolas Bonnefon TabbedCrawlerWidget mainTabWidget_; 219431d01deSNicolas Bonnefon 220431d01deSNicolas Bonnefon // Version checker 221431d01deSNicolas Bonnefon #ifdef GLOGG_SUPPORTS_VERSION_CHECKING 222431d01deSNicolas Bonnefon VersionChecker versionChecker_; 223431d01deSNicolas Bonnefon #endif 224bb02e0acSNicolas Bonnefon }; 225bb02e0acSNicolas Bonnefon 226bb02e0acSNicolas Bonnefon #endif 227