File indexing completed on 2024-04-14 04:53:05
0001 /* 0002 SPDX-FileCopyrightText: 2001 Joseph Wenninger <jowenn@kde.org> 0003 SPDX-FileCopyrightText: 2019 Raphael Rosch <kde-dev@insaner.com> 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef _SIDEBAR_WIDGET_ 0008 #define _SIDEBAR_WIDGET_ 0009 0010 #include <QActionGroup> 0011 #include <kconfiggroup.h> 0012 #include <QTimer> 0013 0014 #include <QPointer> 0015 #include <QUrl> 0016 0017 #include <kparts/part.h> 0018 #include <KParts/PartActivateEvent> 0019 #include <KSharedConfig> 0020 0021 #include "konqsidebarplugin.h" 0022 #include "module_manager.h" 0023 #include "browserextension.h" 0024 0025 class KonqMultiTabBar; 0026 class KonqSidebarPlugin; 0027 class QMenu; 0028 class QHBoxLayout; 0029 class QSplitter; 0030 0031 class ButtonInfo 0032 { 0033 public: 0034 ButtonInfo() 0035 { 0036 } 0037 ButtonInfo(const KSharedConfig::Ptr &configFile_, 0038 const QString &file_, 0039 const QUrl &url_, 0040 const QString &id, 0041 const QString &dispName_, 0042 const QString &iconName_) 0043 : configFile(configFile_), file(file_), 0044 pluginId(id), displayName(dispName_), 0045 iconName(iconName_), initURL(url_) 0046 { 0047 } 0048 0049 KonqSidebarPlugin *plugin(QObject *parent); 0050 0051 KSharedConfig::Ptr configFile; 0052 QString file; 0053 QPointer<QWidget> dock; 0054 KonqSidebarModule *module = nullptr; 0055 KonqSidebarPlugin *m_plugin = nullptr; 0056 0057 QString pluginId; 0058 QString displayName; 0059 QString iconName; 0060 QUrl initURL; 0061 0062 bool configOpen = false; 0063 bool canToggleShowHiddenFolders = false; 0064 bool showHiddenFolders = false; 0065 }; 0066 0067 class Sidebar_Widget: public QWidget 0068 { 0069 Q_OBJECT 0070 public: 0071 friend class ButtonInfo; 0072 public: 0073 Sidebar_Widget(QWidget *parent, KParts::ReadOnlyPart *par, 0074 const QString ¤tProfile); 0075 ~Sidebar_Widget() override; 0076 bool openUrl(const QUrl &url); 0077 void stdAction(const char *handlestd); 0078 0079 KParts::NavigationExtension *getExtension(); 0080 BrowserExtension *getBrowserExtension(); 0081 QSize sizeHint() const override; 0082 0083 public Q_SLOTS: 0084 void addWebSideBar(const QUrl &url, const QString &name); 0085 0086 protected: 0087 void customEvent(QEvent *ev) override; 0088 //void resizeEvent(QResizeEvent* ev); 0089 bool eventFilter(QObject *, QEvent *) override; 0090 void mousePressEvent(QMouseEvent *) override; 0091 0092 protected Q_SLOTS: 0093 void showHidePage(int value); 0094 void createButtons(); 0095 void updateButtons(); 0096 void slotRestoreDeletedButtons(); 0097 void slotRollback(); 0098 void aboutToShowConfigMenu(); 0099 void saveConfig(); 0100 0101 void slotMultipleViews(); 0102 void slotShowTabsLeft(); 0103 void slotShowConfigurationButton(); 0104 0105 void slotSetName(); 0106 void slotSetURL(); 0107 void slotSetIcon(); 0108 void slotToggleShowHiddenFolders(); 0109 void slotRemove(); 0110 0111 void slotUrlsDropped(const QList<QUrl> &urls); 0112 0113 Q_SIGNALS: 0114 void started(KIO::Job *); 0115 void completed(); 0116 void fileSelection(const KFileItemList &items); 0117 void fileMouseOver(const KFileItem &item); 0118 void curViewUrlChanged(const QUrl &url); 0119 0120 /* The following public slots are wrappers for browserextension signals */ 0121 public Q_SLOTS: 0122 void openUrlRequest(const QUrl &url, const KParts::OpenUrlArguments &args, const BrowserArguments &browserArgs); 0123 /* @internal 0124 * ### KDE4 remove me 0125 */ 0126 void submitFormRequest(const char *, const QString &, const QByteArray &, const QString &, const QString &, const QString &); 0127 void createNewWindow(const QUrl &url, const KParts::OpenUrlArguments &args, const BrowserArguments &browserArgs, 0128 const WindowArgs &windowArgs); 0129 0130 void slotEnableAction(KonqSidebarModule *module, const char *name, bool enabled); 0131 0132 private: 0133 0134 QUrl cleanupURL(const QString &url); 0135 QUrl cleanupURL(const QUrl &url); 0136 bool addButton(const QString &desktopFileName, int pos = -1); 0137 bool createView(ButtonInfo &buttonInfo); 0138 0139 //Changes m_storedCurViewUrl and emits the curViewUrlChanged signal 0140 void setStoredCurViewUrl(const QUrl &url); 0141 KonqSidebarModule *loadModule(QWidget *par, const QString &desktopName, 0142 ButtonInfo &buttonInfo, const KSharedConfig::Ptr &config); 0143 void readConfig(); 0144 void doLayout(); 0145 void connectModule(KonqSidebarModule *mod); 0146 void collapseExpandSidebar(); 0147 void doEnableActions(); 0148 ButtonInfo ¤tButtonInfo() 0149 { 0150 return m_buttons[m_currentButtonIndex]; 0151 } 0152 0153 /** 0154 * Create a module without the interactive "createNewModule" implemented 0155 * in the plugin. 0156 */ 0157 bool createDirectModule(const QString &templ, 0158 const QString &name, 0159 const QUrl &url, 0160 const QString &icon, 0161 const QString &module, 0162 const QString &treeModule = QString()); 0163 private Q_SLOTS: 0164 void aboutToShowAddMenu(); 0165 void triggeredAddMenu(QAction *action); 0166 0167 void slotPopupMenu(KonqSidebarModule *, const QPoint &global, const KFileItemList &items, 0168 const KParts::OpenUrlArguments &args = KParts::OpenUrlArguments(), 0169 const BrowserArguments &browserArgs = BrowserArguments(), 0170 KParts::NavigationExtension::PopupFlags flags = KParts::NavigationExtension::DefaultPopupItems, 0171 const KParts::NavigationExtension::ActionGroupMap &actionGroups = KParts::NavigationExtension::ActionGroupMap()); 0172 0173 void slotStatResult(KJob *job); 0174 0175 private: 0176 KParts::ReadOnlyPart *m_partParent; 0177 QSplitter *m_area; 0178 0179 KonqMultiTabBar *m_buttonBar; 0180 QVector<ButtonInfo> m_buttons; 0181 QHBoxLayout *m_layout; 0182 QAction *m_showTabLeft; 0183 QMenu *m_menu; 0184 0185 QMenu *m_addMenu; 0186 QActionGroup m_addMenuActionGroup; 0187 QMap<QAction *, KonqSidebarPlugin *> m_pluginForAction; 0188 0189 QPointer<KonqSidebarModule> m_activeModule; // during RMB popups inside the module 0190 0191 int m_currentButtonIndex; // during RMB popups (over tabs) only, see currentButtonInfo 0192 0193 KConfigGroup *m_config; 0194 QTimer m_configTimer; 0195 0196 QUrl m_storedCurViewUrl; 0197 QUrl m_origURL; 0198 0199 int m_savedWidth; 0200 int m_latestViewed; 0201 0202 bool m_singleWidgetMode; 0203 bool m_showTabsLeft; 0204 bool m_hideTabs; 0205 bool m_showExtraButtons; 0206 bool m_somethingVisible; 0207 bool m_noUpdate; 0208 0209 QAction *m_multiViews; 0210 QAction *m_showConfigButton; 0211 0212 QStringList m_visibleViews; // The views that are actually open 0213 QStringList m_openViews; // The views that should be opened 0214 0215 ModuleManager m_moduleManager; 0216 0217 bool m_urlBeforeInstanceFlag = false; 0218 0219 Q_SIGNALS: 0220 void panelHasBeenExpanded(bool); 0221 }; 0222 0223 #endif