xref: /glogg/src/mainwindow.h (revision 63dc3514bd03c96bdf0ef0b81ad120096d426001)
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     // Close the tab with the passed index
103     void closeTab( int index );
104     // Setup the tab with current index for view
105     void currentTabChanged( int index );
106 
107     // Instructs the widget to change the pattern in the QuickFind widget
108     // and confirm it.
109     void changeQFPattern( const QString& newPattern );
110 
111     // Load a file in a new tab (non-interactive)
112     // (for use from e.g. IPC)
113     void loadFileNonInteractive( const QString& file_name );
114 
115     // Notify the user a new version is available
116     void newVersionNotification( const QString& new_version );
117 
118   signals:
119     // Is emitted when new settings must be used
120     void optionsChanged();
121     // Is emitted when the 'follow' option is enabled/disabled
122     void followSet( bool checked );
123     // Is emitted before the QuickFind box is activated,
124     // to allow crawlers to get search in the right view.
125     void enteringQuickFind();
126     // Emitted when the quickfind bar is closed.
127     void exitingQuickFind();
128 
129   private:
130     void createActions();
131     void createMenus();
132     void createContextMenu();
133     void createToolBars();
134     void createStatusBar();
135     void createRecentFileToolTipTimer();
136     void readSettings();
137     void writeSettings();
138     bool loadFile( const QString& fileName );
139     void updateTitleBar( const QString& file_name );
140     void updateRecentFileActions();
141     QString strippedName( const QString& fullFileName ) const;
142     CrawlerWidget* currentCrawlerWidget() const;
143     void displayQuickFindBar( QuickFindMux::QFDirection direction );
144 
145     std::unique_ptr<Session> session_;
146     std::shared_ptr<ExternalCommunicator> externalCommunicator_;
147     std::shared_ptr<RecentFiles> recentFiles_;
148     QString loadingFileName;
149 
150     enum { MaxRecentFiles = 5 };
151     QAction *recentFileActions[MaxRecentFiles];
152     MenuActionToolTipBehavior *recentFileActionBehaviors[MaxRecentFiles];
153     QAction *separatorAction;
154 
155     QMenu *fileMenu;
156     QMenu *editMenu;
157     QMenu *viewMenu;
158     QMenu *toolsMenu;
159     QMenu *helpMenu;
160 
161     InfoLine *infoLine;
162     QLabel* lineNbField;
163     QToolBar *toolBar;
164 
165     QAction *openAction;
166     QAction *closeAction;
167     QAction *closeAllAction;
168     QAction *exitAction;
169     QAction *copyAction;
170     QAction *selectAllAction;
171     QAction *findAction;
172     QAction *overviewVisibleAction;
173     QAction *lineNumbersVisibleInMainAction;
174     QAction *lineNumbersVisibleInFilteredAction;
175     QAction *followAction;
176     QAction *reloadAction;
177     QAction *stopAction;
178     QAction *filtersAction;
179     QAction *optionsAction;
180     QAction *aboutAction;
181     QAction *aboutQtAction;
182 
183     QIcon mainIcon_;
184 
185     // Multiplex signals to any of the CrawlerWidgets
186     SignalMux signalMux_;
187 
188     // QuickFind widget
189     QuickFindWidget quickFindWidget_;
190 
191     // Multiplex signals to/from the QuickFindWidget
192     QuickFindMux quickFindMux_;
193 
194     // The main widget
195     TabbedCrawlerWidget mainTabWidget_;
196 
197     // Version checker
198 #ifdef GLOGG_SUPPORTS_VERSION_CHECKING
199     VersionChecker versionChecker_;
200 #endif
201 };
202 
203 #endif
204