1 /*****************************************************************************
2  * Copyright (C) 2000 Shie Erlich <krusader@users.sourceforge.net>           *
3  * Copyright (C) 2000 Rafi Yanai <krusader@users.sourceforge.net>            *
4  * Copyright (C) 2004-2019 Krusader Krew [https://krusader.org]              *
5  *                                                                           *
6  * This file is part of Krusader [https://krusader.org].                     *
7  *                                                                           *
8  * Krusader is free software: you can redistribute it and/or modify          *
9  * it under the terms of the GNU General Public License as published by      *
10  * the Free Software Foundation, either version 2 of the License, or         *
11  * (at your option) any later version.                                       *
12  *                                                                           *
13  * Krusader is distributed in the hope that it will be useful,               *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
16  * GNU General Public License for more details.                              *
17  *                                                                           *
18  * You should have received a copy of the GNU General Public License         *
19  * along with Krusader.  If not, see [http://www.gnu.org/licenses/].         *
20  *****************************************************************************/
21 
22 #ifndef KRUSADER_H
23 #define KRUSADER_H
24 
25 #ifdef HAVE_CONFIG_H
26 #include <config.h>
27 #endif
28 
29 #include "krmainwindow.h"
30 
31 // QtCore
32 #include <QCommandLineParser>
33 #include <QEvent>
34 #include <QPointer>
35 #include <QStringList>
36 #include <QTimer>
37 // QtGui
38 #include <QHideEvent>
39 #include <QMoveEvent>
40 #include <QResizeEvent>
41 #include <QShowEvent>
42 // QtWidgets
43 #include <QAction>
44 
45 #include <KConfigCore/KConfig>
46 #include <KConfigCore/KConfigGroup>
47 #include <KConfigWidgets/KStandardAction>
48 #include <KNotifications/KStatusNotifierItem>
49 #include <KParts/MainWindow>
50 
51 #ifdef __KJSEMBED__
52 class KrJS;
53 #endif
54 
55 class KStartupInfoData;
56 class KStartupInfoId;
57 
58 class KrusaderStatus;
59 class KRPleaseWaitHandler;
60 class PopularUrls;
61 class ViewActions;
62 class ListPanelActions;
63 class TabActions;
64 class KrView;
65 
66 /**
67  * @brief The main window of this file manager
68  */
69 class Krusader : public KParts::MainWindow, public KrMainWindow
70 {
71     Q_OBJECT
72     Q_CLASSINFO("D-Bus Interface", "org.krusader.Instance")
73 
74 public:
75     explicit Krusader(const QCommandLineParser &parser);
76     virtual ~Krusader();
77 
78     void setTray(bool forceCreation = false);
79 
80     // KrMainWindow implementation
widget()81     virtual QWidget *widget() Q_DECL_OVERRIDE {
82         return this;
83     }
84     virtual KrView *activeView() Q_DECL_OVERRIDE;
viewActions()85     ViewActions *viewActions() Q_DECL_OVERRIDE {
86         return _viewActions;
87     }
actions()88     virtual KActionCollection *actions() Q_DECL_OVERRIDE {
89         return actionCollection();
90     }
91     virtual AbstractPanelManager *activeManager() Q_DECL_OVERRIDE;
92     virtual AbstractPanelManager *leftManager() Q_DECL_OVERRIDE;
93     virtual AbstractPanelManager *rightManager() Q_DECL_OVERRIDE;
popularUrls()94     virtual PopularUrls *popularUrls() Q_DECL_OVERRIDE {
95         return _popularUrls;
96     }
krActions()97     virtual KrActions *krActions() Q_DECL_OVERRIDE {
98         return _krActions;
99     }
listPanelActions()100     virtual ListPanelActions *listPanelActions() Q_DECL_OVERRIDE {
101         return _listPanelActions;
102     }
tabActions()103     virtual TabActions *tabActions() Q_DECL_OVERRIDE {
104         return _tabActions;
105     }
plugActionList(const char * name,QList<QAction * > & list)106     virtual void plugActionList(const char *name, QList<QAction*> &list) Q_DECL_OVERRIDE {
107         KParts::MainWindow::plugActionList(name, list);
108     }
109 
110     /**
111      * Icon name that depends on whether krusader runs with root-privileges or not
112      *
113      * @return icon name
114      */
115     static const char* appIconName();
116 
117 public slots:
118     void quit();
119     void moveToTop();
120     void statusBarUpdate(const QString& mess);
121     // in use by Krusader only
122     void saveSettings();
123     void savePosition();
124     void updateUserActions();
125 
126 protected slots:
127     void doOpenUrl();
128     void slotGotNewStartup(const KStartupInfoId &id, const KStartupInfoData &data);
129     void slotGotRemoveStartup(const KStartupInfoId &id, const KStartupInfoData &data);
130 
131 protected:
132     void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE;
133     void showEvent(QShowEvent *event) Q_DECL_OVERRIDE;
134     bool queryClose() Q_DECL_OVERRIDE;
135     void setupActions();
136     bool versionControl();  // handle version differences in krusaderrc
137     bool event(QEvent *) Q_DECL_OVERRIDE;
138 
139 public Q_SLOTS:
140     Q_SCRIPTABLE bool isRunning();
141     Q_SCRIPTABLE bool isLeftActive();
142     Q_SCRIPTABLE bool openUrl(QString url);
143 
144 public:
145     static Krusader *App;       // a kApp style pointer
146     static QString   AppName;   // the name of the application
147     PopularUrls *_popularUrls; // holds a sorted list of the most popular urls visited
148 
149     // the internal progress bar variales + functions
150     KRPleaseWaitHandler* plzWait;
151     void startWaiting(QString msg = "Please Wait", int count = 0 , bool cancel = false);
152     void stopWait();
153     bool wasWaitingCancelled() const;
154 
155 #ifdef __KJSEMBED__
156     static KrJS *js;
157 #endif
158 
159 signals:
160     void changeMessage(QString);
161     // emitted when we are about to quit
162     void shutdown();
163 
164 private:
165     void acceptClose();
166 
167 private:
168     KrActions *_krActions;
169     ViewActions *_viewActions;
170     ListPanelActions *_listPanelActions;
171     TabActions *_tabActions;
172     QPointer<KStatusNotifierItem> sysTray;
173     bool         isStarting;
174     bool         isExiting;
175     QTimer      _openUrlTimer;
176     QString     _urlToOpen;
177     bool        _quit;
178 };
179 
180 
181 // main modules
182 #define krApp        Krusader::App
183 
184 #ifdef __KJSEMBED__
185 #define krJS   Krusader::App->js
186 #endif
187 
188 #endif
189