File indexing completed on 2024-04-28 15:52:02

0001 /*
0002     SPDX-FileCopyrightText: 2002 Wilco Greven <greven@kde.org>
0003     SPDX-FileCopyrightText: 2003 Benjamin Meyer <benjamin@csh.rit.edu>
0004     SPDX-FileCopyrightText: 2003 Laurent Montel <montel@kde.org>
0005     SPDX-FileCopyrightText: 2003 Luboš Luňák <l.lunak@kde.org>
0006     SPDX-FileCopyrightText: 2004 Christophe Devriese <Christophe.Devriese@student.kuleuven.ac.be>
0007     SPDX-FileCopyrightText: 2004 Albert Astals Cid <aacid@kde.org>
0008 
0009     SPDX-License-Identifier: GPL-2.0-or-later
0010 */
0011 
0012 #ifndef _OKULAR_SHELL_H_
0013 #define _OKULAR_SHELL_H_
0014 
0015 #include "config-okular.h"
0016 #include <QAction>
0017 #include <QList>
0018 #include <QMimeDatabase>
0019 #include <QMimeType>
0020 #include <kparts/mainwindow.h>
0021 #include <kparts/readwritepart.h>
0022 
0023 #if HAVE_DBUS
0024 #include <QDBusAbstractAdaptor> // for Q_NOREPLY
0025 #else
0026 #define Q_NOREPLY
0027 #endif
0028 #include <QStackedWidget>
0029 
0030 #include "welcomescreen.h"
0031 
0032 class Sidebar;
0033 class KRecentFilesAction;
0034 class KToggleAction;
0035 class QTabWidget;
0036 class KPluginFactory;
0037 
0038 /**
0039  * This is the application "Shell".  It has a menubar and a toolbar
0040  * but relies on the "Part" to do all the real work.
0041  *
0042  * @short Application Shell
0043  * @author Wilco Greven <greven@kde.org>
0044  * @version 0.1
0045  */
0046 class Shell : public KParts::MainWindow
0047 {
0048     Q_OBJECT
0049     Q_CLASSINFO("D-Bus Interface", "org.kde.okular")
0050 
0051     friend class MainShellTest;
0052     friend class AnnotationToolBarTest;
0053 
0054 public:
0055     /**
0056      * Constructor
0057      */
0058     explicit Shell(const QString &serializedOptions = QString());
0059 
0060     /**
0061      * Default Destructor
0062      */
0063     ~Shell() override;
0064 
0065     QSize sizeHint() const override;
0066 
0067     /**
0068      * Returns false if Okular component wasn't found
0069      **/
0070     bool isValid() const;
0071 
0072     bool openDocument(const QUrl &url, const QString &serializedOptions);
0073 
0074 public Q_SLOTS:
0075     Q_SCRIPTABLE Q_NOREPLY void tryRaise(const QString &startupId);
0076     Q_SCRIPTABLE bool openDocument(const QString &urlString, const QString &serializedOptions = QString());
0077     Q_SCRIPTABLE bool canOpenDocs(int numDocs, int desktop);
0078 
0079 protected:
0080     /**
0081      * This method is called when it is time for the app to save its
0082      * properties for session management purposes.
0083      */
0084     void saveProperties(KConfigGroup &) override;
0085 
0086     /**
0087      * This method is called when this app is restored.  The KConfig
0088      * object points to the session management config file that was saved
0089      * with @ref saveProperties
0090      */
0091     void readProperties(const KConfigGroup &) override;
0092 
0093     /**
0094      * Expose internal functions for session restore testing
0095      */
0096     void savePropertiesInternal(KConfig *config, int num)
0097     {
0098         KMainWindow::savePropertiesInternal(config, num);
0099     }
0100     void readPropertiesInternal(KConfig *config, int num)
0101     {
0102         KMainWindow::readPropertiesInternal(config, num);
0103     }
0104 
0105     void readSettings();
0106     void writeSettings();
0107     void setFullScreen(bool);
0108 
0109     using KParts::MainWindow::setCaption;
0110     void setCaption(const QString &caption) override;
0111 
0112     bool queryClose() override;
0113 
0114     void showEvent(QShowEvent *event) override;
0115     void keyPressEvent(QKeyEvent *) override;
0116 
0117 private Q_SLOTS:
0118     void fileOpen();
0119 
0120     void slotUpdateFullScreen();
0121     void slotShowMenubar();
0122 
0123     void openUrl(const QUrl &url, const QString &serializedOptions = QString());
0124     void showOpenRecentMenu();
0125     void closeUrl();
0126     void print();
0127     void setPrintEnabled(bool enabled);
0128     void setCloseEnabled(bool enabled);
0129     void setTabIcon(const QMimeType &mimeType);
0130     void handleDroppedUrls(const QList<QUrl> &urls);
0131 
0132     // Tab event handlers
0133     void setActiveTab(int tab);
0134     void closeTab(int tab);
0135     void activateNextTab();
0136     void activatePrevTab();
0137     void undoCloseTab();
0138     void moveTabData(int from, int to);
0139 
0140     void slotFitWindowToPage(const QSize pageViewSize, const QSize pageSize);
0141 
0142     void hideWelcomeScreen();
0143     void showWelcomeScreen();
0144     void refreshRecentsOnWelcomeScreen();
0145 
0146     void forgetRecentItem(QUrl const &url);
0147 
0148 Q_SIGNALS:
0149     void moveSplitter(int sideWidgetSize);
0150 
0151 private:
0152     void saveRecents();
0153     void setupAccel();
0154     void setupActions();
0155     void openNewTab(const QUrl &url, const QString &serializedOptions);
0156     void applyOptionsToPart(QObject *part, const QString &serializedOptions);
0157     void connectPart(const KParts::ReadWritePart *part);
0158     int findTabIndex(QObject *sender) const;
0159     int findTabIndex(const QUrl &url) const;
0160 
0161 private:
0162     void reloadAllXML();
0163     bool eventFilter(QObject *obj, QEvent *event) override;
0164 
0165     KPluginFactory *m_partFactory;
0166     KRecentFilesAction *m_recent;
0167     QStringList m_fileformats;
0168     bool m_fileformatsscanned;
0169     QAction *m_printAction;
0170     QAction *m_closeAction;
0171     KToggleAction *m_fullScreenAction;
0172     KToggleAction *m_showMenuBarAction;
0173     bool m_menuBarWasShown, m_toolBarWasShown;
0174     bool m_unique;
0175     QTabWidget *m_tabWidget;
0176     KToggleAction *m_openInTab;
0177     WelcomeScreen *m_welcomeScreen;
0178     QStackedWidget *m_centralStackedWidget;
0179     Sidebar *m_sidebar = nullptr;
0180 
0181     struct TabState {
0182         explicit TabState(KParts::ReadWritePart *p)
0183             : part(p)
0184             , printEnabled(false)
0185             , closeEnabled(false)
0186         {
0187         }
0188         KParts::ReadWritePart *part;
0189         bool printEnabled;
0190         bool closeEnabled;
0191     };
0192     QList<TabState> m_tabs;
0193     QList<QUrl> m_closedTabUrls;
0194     QAction *m_nextTabAction;
0195     QAction *m_prevTabAction;
0196     QAction *m_undoCloseTab;
0197     QAction *m_showSidebarAction = nullptr;
0198     QAction *m_lockSidebarAction = nullptr;
0199 
0200     bool m_isValid;
0201 };
0202 
0203 #endif
0204 
0205 // vim:ts=2:sw=2:tw=78:et