File indexing completed on 2024-04-21 16:33:19

0001 /*
0002     SPDX-FileCopyrightText: 2000 Shie Erlich <krusader@users.sourceforge.net>
0003     SPDX-FileCopyrightText: 2000 Rafi Yanai <krusader@users.sourceforge.net>
0004     SPDX-FileCopyrightText: 2004-2022 Krusader Krew <https://krusader.org>
0005 
0006     SPDX-License-Identifier: GPL-2.0-or-later
0007 */
0008 
0009 #ifndef KRUSADER_H
0010 #define KRUSADER_H
0011 
0012 #ifdef HAVE_CONFIG_H
0013 #include <config.h>
0014 #endif
0015 
0016 #include "krmainwindow.h"
0017 
0018 // QtCore
0019 #include <QCommandLineParser>
0020 #include <QEvent>
0021 #include <QPointer>
0022 #include <QStringList>
0023 #include <QTimer>
0024 // QtGui
0025 #include <QHideEvent>
0026 #include <QMoveEvent>
0027 #include <QResizeEvent>
0028 #include <QShowEvent>
0029 // QtWidgets
0030 #include <QAction>
0031 
0032 #include <KConfigCore/KConfig>
0033 #include <KConfigCore/KConfigGroup>
0034 #include <KConfigWidgets/KStandardAction>
0035 #include <KNotifications/KStatusNotifierItem>
0036 #include <KParts/MainWindow>
0037 
0038 class KStartupInfoData;
0039 class KStartupInfoId;
0040 
0041 class KrusaderStatus;
0042 class KrPleaseWaitHandler;
0043 class PopularUrls;
0044 class ViewActions;
0045 class ListPanelActions;
0046 class TabActions;
0047 class KrView;
0048 
0049 /**
0050  * @brief The main window of this file manager
0051  */
0052 class Krusader : public KParts::MainWindow, public KrMainWindow
0053 {
0054     Q_OBJECT
0055     Q_CLASSINFO("D-Bus Interface", "org.krusader.Instance")
0056 
0057 public:
0058     explicit Krusader(const QCommandLineParser &parser);
0059     ~Krusader() override;
0060 
0061     void setTray(bool forceCreation = false);
0062 
0063     // KrMainWindow implementation
0064     QWidget *widget() override
0065     {
0066         return this;
0067     }
0068     KrView *activeView() override;
0069     ViewActions *viewActions() override
0070     {
0071         return _viewActions;
0072     }
0073     KActionCollection *actions() override
0074     {
0075         return actionCollection();
0076     }
0077     AbstractPanelManager *activeManager() override;
0078     AbstractPanelManager *leftManager() override;
0079     AbstractPanelManager *rightManager() override;
0080     PopularUrls *popularUrls() override
0081     {
0082         return _popularUrls;
0083     }
0084     KrActions *krActions() override
0085     {
0086         return _krActions;
0087     }
0088     ListPanelActions *listPanelActions() override
0089     {
0090         return _listPanelActions;
0091     }
0092     TabActions *tabActions() override
0093     {
0094         return _tabActions;
0095     }
0096     void plugActionList(const char *name, QList<QAction *> &list) override
0097     {
0098         KParts::MainWindow::plugActionList(name, list);
0099     }
0100 
0101     /**
0102      * Icon name that depends on whether krusader runs with root-privileges or not
0103      *
0104      * @return icon name
0105      */
0106     static const char *appIconName();
0107 
0108 public slots:
0109     void quit();
0110     void moveToTop();
0111     void statusBarUpdate(const QString &mess);
0112     // in use by Krusader only
0113     void saveSettings();
0114     void savePosition();
0115     void updateUserActions();
0116 
0117 protected slots:
0118     void doOpenUrl();
0119     void slotGotNewStartup(const KStartupInfoId &id, const KStartupInfoData &data);
0120     void slotGotRemoveStartup(const KStartupInfoId &id, const KStartupInfoData &data);
0121 
0122 protected:
0123     void closeEvent(QCloseEvent *event) override;
0124     void showEvent(QShowEvent *event) override;
0125     bool queryClose() override;
0126     void setupActions();
0127     bool versionControl(); // handle version differences in krusaderrc
0128     bool event(QEvent *) override;
0129 
0130 public Q_SLOTS:
0131     Q_SCRIPTABLE bool isRunning();
0132     Q_SCRIPTABLE bool isLeftActive();
0133     Q_SCRIPTABLE bool openUrl(QString url);
0134 
0135 public:
0136     static Krusader *App; // a kApp style pointer
0137     static QString AppName; // the name of the application
0138     PopularUrls *_popularUrls; // holds a sorted list of the most popular urls visited
0139 
0140     // the internal progress bar variales + functions
0141     KrPleaseWaitHandler *plzWait;
0142     void startWaiting(QString msg = "Please Wait", int count = 0, bool cancel = false);
0143     void stopWait();
0144     bool wasWaitingCancelled() const;
0145 
0146 signals:
0147     void changeMessage(QString);
0148     // emitted when we are about to quit
0149     void shutdown();
0150 
0151 private:
0152     void acceptClose();
0153 
0154 private:
0155     KrActions *_krActions;
0156     ViewActions *_viewActions;
0157     ListPanelActions *_listPanelActions;
0158     TabActions *_tabActions;
0159     QPointer<KStatusNotifierItem> sysTray;
0160     bool isStarting;
0161     QTimer _openUrlTimer;
0162     QString _urlToOpen;
0163     bool _quit;
0164 };
0165 
0166 // main modules
0167 #define krApp Krusader::App
0168 
0169 #endif