File indexing completed on 2024-04-21 16:30:14
0001 /* This file is part of the KDE project 0002 SPDX-FileCopyrightText: 2007 David Faure <faure@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef DOLPHINPART_H 0008 #define DOLPHINPART_H 0009 0010 #include <KParts/ReadOnlyPart> 0011 0012 #include <QAction> 0013 #include <QUrl> 0014 0015 class DolphinNewFileMenu; 0016 class DolphinViewActionHandler; 0017 class QActionGroup; 0018 class KFileItemList; 0019 class KFileItem; 0020 class DolphinPartBrowserExtension; 0021 class DolphinRemoteEncoding; 0022 class KDirLister; 0023 class DolphinView; 0024 class DolphinRemoveAction; 0025 0026 class DolphinPart : public KParts::ReadOnlyPart 0027 { 0028 Q_OBJECT 0029 // Used by konqueror. Technically it means "we want undo enabled if 0030 // there are things in the undo history and the current part is a dolphin part". 0031 // Even though it's konqueror doing the undo... 0032 Q_PROPERTY(bool supportsUndo READ supportsUndo CONSTANT) 0033 0034 Q_PROPERTY(QString currentViewMode READ currentViewMode WRITE setCurrentViewMode) 0035 0036 // Used by konqueror when typing something like /home/dfaure/*.diff in the location bar 0037 Q_PROPERTY(QString nameFilter READ nameFilter WRITE setNameFilter) 0038 0039 // Used by konqueror to implement the --select command-line option 0040 Q_PROPERTY(QList<QUrl> filesToSelect READ filesToSelect WRITE setFilesToSelect) 0041 0042 public: 0043 explicit DolphinPart(QWidget *parentWidget, QObject *parent, const KPluginMetaData &metaData, const QVariantList &args); 0044 ~DolphinPart() override; 0045 0046 /** 0047 * Standard KParts::ReadOnlyPart openUrl method. 0048 * Called by Konqueror to view a directory in DolphinPart. 0049 */ 0050 bool openUrl(const QUrl &url) override; 0051 0052 /// see the supportsUndo property 0053 bool supportsUndo() const 0054 { 0055 return true; 0056 } 0057 0058 /** 0059 * Used by konqueror for setting the view mode 0060 * @param viewModeName internal name for the view mode, like "icons" 0061 * Those names come from the Actions line in dolphinpart.desktop, 0062 * and have to match the name of the KActions. 0063 */ 0064 void setCurrentViewMode(const QString &viewModeName); 0065 0066 /** 0067 * Used by konqueror for displaying the current view mode. 0068 * @see setCurrentViewMode 0069 */ 0070 QString currentViewMode() const; 0071 0072 /// Returns the view owned by this part; used by DolphinPartBrowserExtension 0073 DolphinView *view() 0074 { 0075 return m_view; 0076 } 0077 0078 /** 0079 * Sets a name filter, like *.diff 0080 */ 0081 void setNameFilter(const QString &nameFilter); 0082 0083 /** 0084 * Returns the current name filter. Used by konqueror to show it in the URL. 0085 */ 0086 QString nameFilter() const 0087 { 0088 return m_nameFilter; 0089 } 0090 0091 /** 0092 * Don't use this. Always @returns an empty list. It only exists to silence moc. 0093 */ 0094 QList<QUrl> filesToSelect() const 0095 { 0096 return QList<QUrl>(); 0097 } 0098 0099 protected: 0100 /** 0101 * We reimplement openUrl so no need to implement openFile. 0102 */ 0103 bool openFile() override 0104 { 0105 return true; 0106 } 0107 0108 Q_SIGNALS: 0109 /** 0110 * Emitted when the view mode changes. Used by konqueror. 0111 */ 0112 void viewModeChanged(); 0113 0114 /** 0115 * Emitted whenever the current URL is about to be changed. 0116 */ 0117 void aboutToOpenURL(); 0118 0119 private Q_SLOTS: 0120 void slotMessage(const QString &msg); 0121 void slotErrorMessage(const QString &msg); 0122 /** 0123 * Shows the information for the item \a item inside the statusbar. If the 0124 * item is null, the default statusbar information is shown. 0125 */ 0126 void slotRequestItemInfo(const KFileItem &item); 0127 /** 0128 * Handles clicking on an item 0129 */ 0130 void slotItemActivated(const KFileItem &item); 0131 /** 0132 * Handles activation of multiple items 0133 */ 0134 void slotItemsActivated(const KFileItemList &items); 0135 /** 0136 * Creates a new window showing the content of \a url. 0137 */ 0138 void createNewWindow(const QUrl &url); 0139 /** 0140 * Opens the context menu on the current mouse position. 0141 * @pos Position in screen coordinates. 0142 * @item File item context. If item is null, the context menu 0143 * should be applied to \a url. 0144 * @selectedItems The selected items for which the context menu 0145 * is opened. This list generally includes \a item. 0146 * @url URL which contains \a item. 0147 */ 0148 void slotOpenContextMenu(const QPoint &pos, const KFileItem &_item, const KFileItemList &selectedItems, const QUrl &); 0149 0150 /** 0151 * Informs the host that we are opening \a url (e.g. after a redirection 0152 * coming from KDirLister). 0153 * Testcase 1: fish://localhost 0154 * Testcase 2: showing a directory that is being renamed by another window (#180156) 0155 */ 0156 void slotDirectoryRedirection(const QUrl &oldUrl, const QUrl &newUrl); 0157 0158 /** 0159 * Updates the state of the 'Edit' menu actions and emits 0160 * the signal selectionChanged(). 0161 */ 0162 void slotSelectionChanged(const KFileItemList &selection); 0163 0164 /** 0165 * Updates the text of the paste action dependent from 0166 * the number of items which are in the clipboard. 0167 */ 0168 void updatePasteAction(); 0169 0170 /** 0171 * Connected to all "Go" menu actions provided by DolphinPart 0172 */ 0173 void slotGoTriggered(QAction *action); 0174 0175 /** 0176 * Connected to the "editMimeType" action 0177 */ 0178 void slotEditMimeType(); 0179 0180 /** 0181 * Connected to the "select_items_matching" action. 0182 * Opens a dialog which permits to select all items matching a pattern like "*.jpg". 0183 */ 0184 void slotSelectItemsMatchingPattern(); 0185 0186 /** 0187 * Connected to the "unselect_items_matching" action. 0188 * Opens a dialog which permits to unselect all items matching a pattern like "*.jpg". 0189 */ 0190 void slotUnselectItemsMatchingPattern(); 0191 0192 /** 0193 * Open a terminal window, starting with the current directory. 0194 */ 0195 void slotOpenTerminal(); 0196 0197 /** 0198 * Open preferred search tool in the current directory to find files. 0199 */ 0200 void slotFindFile(); 0201 0202 /** 0203 * Updates the 'Create New...' sub menu, just before it's shown. 0204 */ 0205 void updateNewMenu(); 0206 0207 /** 0208 * Updates the number of items (= number of files + number of 0209 * directories) in the statusbar. If files are selected, the number 0210 * of selected files and the sum of the filesize is shown. 0211 */ 0212 void updateStatusBar(); 0213 0214 /** 0215 * Notify container of folder loading progress. 0216 */ 0217 void updateProgress(int percent); 0218 0219 void createDirectory(); 0220 0221 /** 0222 * Called by konqueror --select 0223 */ 0224 void setFilesToSelect(const QList<QUrl> &files); 0225 0226 bool eventFilter(QObject *, QEvent *) override; 0227 0228 private: 0229 void createActions(); 0230 void createGoAction(const char *name, const char *iconName, const QString &text, const QString &url, QActionGroup *actionGroup); 0231 0232 void openSelectionDialog(const QString &title, const QString &text, bool selectItems); 0233 QString urlToLocalFilePath(const QUrl &url); 0234 QString localFilePathOrHome() const; 0235 0236 private: 0237 DolphinView *m_view; 0238 DolphinViewActionHandler *m_actionHandler; 0239 DolphinRemoteEncoding *m_remoteEncoding; 0240 DolphinPartBrowserExtension *m_extension; 0241 DolphinNewFileMenu *m_newFileMenu; 0242 QAction *m_findFileAction; 0243 QAction *m_openTerminalAction; 0244 QString m_nameFilter; 0245 DolphinRemoveAction *m_removeAction; 0246 Q_DISABLE_COPY(DolphinPart) 0247 }; 0248 0249 #endif /* DOLPHINPART_H */