xref: /glogg/src/mainwindow.h (revision 460de7006b8563388072e22dac4e20bfd129dd32)
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 selectAll();
74     void copy();
75     void find();
76     void filters();
77     void options();
78     void about();
79     void aboutQt();
80 
81     // Change the view settings
82     void toggleOverviewVisibility( bool isVisible );
83     void toggleMainLineNumbersVisibility( bool isVisible );
84     void toggleFilteredLineNumbersVisibility( bool isVisible );
85 
86     // Disable the follow mode checkbox and send the followSet signal down
87     void disableFollow();
88 
89     // Update the line number displayed in the status bar.
90     // Must be passed as the internal (starts at 0) line number.
91     void lineNumberHandler( int line );
92 
93     // Instructs the widget to update the loading progress gauge
94     void updateLoadingProgress( int progress );
95     // Instructs the widget to display the 'normal' status bar,
96     // without the progress gauge and with file info
97     // or an error recovery when loading is finished
98     void handleLoadingFinished( LoadingStatus status );
99 
100     // Close the tab with the passed index
101     void closeTab( int index );
102     // Setup the tab with current index for view
103     void currentTabChanged( int index );
104 
105     // Instructs the widget to change the pattern in the QuickFind widget
106     // and confirm it.
107     void changeQFPattern( const QString& newPattern );
108 
109     // Load a file in a new tab (non-interactive)
110     // (for use from e.g. IPC)
111     void loadFileNonInteractive( const QString& file_name );
112 
113     // Notify the user a new version is available
114     void newVersionNotification( const QString& new_version );
115 
116   signals:
117     // Is emitted when new settings must be used
118     void optionsChanged();
119     // Is emitted when the 'follow' option is enabled/disabled
120     void followSet( bool checked );
121     // Is emitted before the QuickFind box is activated,
122     // to allow crawlers to get search in the right view.
123     void enteringQuickFind();
124     // Emitted when the quickfind bar is closed.
125     void exitingQuickFind();
126 
127   private:
128     void createActions();
129     void createMenus();
130     void createContextMenu();
131     void createToolBars();
132     void createStatusBar();
133     void createRecentFileToolTipTimer();
134     void readSettings();
135     void writeSettings();
136     bool loadFile( const QString& fileName );
137     void updateTitleBar( const QString& file_name );
138     void updateRecentFileActions();
139     QString strippedName( const QString& fullFileName ) const;
140     CrawlerWidget* currentCrawlerWidget() const;
141     void displayQuickFindBar( QuickFindMux::QFDirection direction );
142 
143     std::unique_ptr<Session> session_;
144     std::shared_ptr<ExternalCommunicator> externalCommunicator_;
145     std::shared_ptr<RecentFiles> recentFiles_;
146     QString loadingFileName;
147 
148     enum { MaxRecentFiles = 5 };
149     QAction *recentFileActions[MaxRecentFiles];
150     MenuActionToolTipBehavior *recentFileActionBehaviors[MaxRecentFiles];
151     QAction *separatorAction;
152 
153     QMenu *fileMenu;
154     QMenu *editMenu;
155     QMenu *viewMenu;
156     QMenu *toolsMenu;
157     QMenu *helpMenu;
158 
159     InfoLine *infoLine;
160     QLabel* lineNbField;
161     QToolBar *toolBar;
162 
163     QAction *openAction;
164     QAction *exitAction;
165     QAction *copyAction;
166     QAction *selectAllAction;
167     QAction *findAction;
168     QAction *overviewVisibleAction;
169     QAction *lineNumbersVisibleInMainAction;
170     QAction *lineNumbersVisibleInFilteredAction;
171     QAction *followAction;
172     QAction *reloadAction;
173     QAction *stopAction;
174     QAction *filtersAction;
175     QAction *optionsAction;
176     QAction *aboutAction;
177     QAction *aboutQtAction;
178 
179     QIcon mainIcon_;
180 
181     // Multiplex signals to any of the CrawlerWidgets
182     SignalMux signalMux_;
183 
184     // QuickFind widget
185     QuickFindWidget quickFindWidget_;
186 
187     // Multiplex signals to/from the QuickFindWidget
188     QuickFindMux quickFindMux_;
189 
190     // The main widget
191     TabbedCrawlerWidget mainTabWidget_;
192 
193     // Version checker
194 #ifdef GLOGG_SUPPORTS_VERSION_CHECKING
195     VersionChecker versionChecker_;
196 #endif
197 };
198 
199 #endif
200