File indexing completed on 2024-04-14 04:53:06

0001 /* This file is part of the KDE project
0002     SPDX-FileCopyrightText: 2006 David Faure <faure@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef KONQ_APPLICATION_H
0008 #define KONQ_APPLICATION_H
0009 
0010 #include "konqprivate_export.h"
0011 #include <config-konqueror.h>
0012 
0013 #include <QApplication>
0014 
0015 #include <KAboutData>
0016 
0017 #include <QCommandLineParser>
0018 
0019 #ifdef KActivities_FOUND
0020 namespace KActivities {
0021     class Consumer;
0022 }
0023 #endif
0024 
0025 class KonqMainWindow;
0026 class QDBusMessage;
0027 class KonqBrowser;
0028 
0029 namespace KParts {
0030     class Part;
0031 }
0032 
0033 class KONQ_TESTS_EXPORT KonquerorApplication : public QApplication
0034 {
0035     Q_OBJECT
0036 public:
0037     KonquerorApplication(int &argc, char **argv);
0038     int start();
0039 
0040     static QString currentActivity();
0041 
0042 public slots:
0043     void slotReparseConfiguration();
0044 signals:
0045     void configurationChanged();
0046     void aboutToConfigure();
0047 
0048 private slots:
0049     void slotAddToCombo(const QString &url, const QDBusMessage &msg);
0050     void slotRemoveFromCombo(const QString &url, const QDBusMessage &msg);
0051     void slotComboCleared(const QDBusMessage &msg);
0052 
0053 private:
0054 
0055     using WindowCreationResult = QPair<KonqMainWindow*, int>;
0056 
0057     void setupAboutData();
0058     void setupParser();
0059     int startFirstInstance();
0060     int performStart(const QString &workingDirectory, bool firstInstance = false);
0061     void restoreSession();
0062     void listSessions();
0063     int openSession(const QString &session);
0064     //TODO: remove the second argument when workaround with activities won't be necessary anymore
0065     //See the comment in the body of createEmptyWindow()
0066     WindowCreationResult createEmptyWindow(bool firstInstance, bool calledFromPerformStart = false);
0067     void preloadWindow(const QStringList &args);
0068     WindowCreationResult createWindowsForUrlArguments(const QStringList &args, const QString &workingDirectory, KonqMainWindow *mainwin= nullptr);
0069 
0070     /**
0071      * @brief What to do when running Konqueror as root
0072      */
0073     enum KonquerorAsRootBehavior {
0074         NotRoot, //!< Konqueror is not being run as root
0075         PreventRunningAsRoot, //!< The user tried to run Konqueror as root but answered to exit when asked
0076         RunInDangerousMode //!< The user decided to run Konqueror as user enabling the `--no-sandbox` chromium flag
0077     };
0078 
0079     /**
0080      * @brief Checks whether Konqueror is being run as root and, if so, asks the user what to do
0081      * @return NotRoot if Konqueror isn't being run as root or PreventRunningAsRoot or RunInDangerousMode, according
0082      * to the user's choice, otherwise
0083      */
0084     static KonquerorAsRootBehavior checkRootBehavior();
0085 
0086 private:
0087     KAboutData m_aboutData;
0088     QCommandLineParser m_parser;
0089     bool m_sessionRecoveryAttempted = false;
0090     KonquerorAsRootBehavior m_runningAsRootBehavior = NotRoot;
0091     KonqBrowser *m_browser;
0092     bool m_forceNewProcess = false;
0093 
0094 #ifdef KActivities_FOUND
0095     KActivities::Consumer* m_activityConsumer;
0096 #endif
0097 
0098 };
0099 
0100 #endif