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