1 /* This file is part of the KDE project 2 SPDX-FileCopyrightText: 2007 David Faure <faure@kde.org> 3 4 SPDX-License-Identifier: LGPL-2.0-or-later 5 */ 6 7 #ifndef DOLPHINPART_H 8 #define DOLPHINPART_H 9 10 #include <KParts/ReadOnlyPart> 11 12 #include <QAction> 13 #include <QUrl> 14 15 class DolphinNewFileMenu; 16 class DolphinViewActionHandler; 17 class QActionGroup; 18 class KFileItemList; 19 class KFileItem; 20 class DolphinPartBrowserExtension; 21 class DolphinRemoteEncoding; 22 class KDirLister; 23 class DolphinView; 24 class DolphinRemoveAction; 25 26 class DolphinPart : public KParts::ReadOnlyPart 27 { 28 Q_OBJECT 29 // Used by konqueror. Technically it means "we want undo enabled if 30 // there are things in the undo history and the current part is a dolphin part". 31 // Even though it's konqueror doing the undo... 32 Q_PROPERTY( bool supportsUndo READ supportsUndo ) 33 34 Q_PROPERTY( QString currentViewMode READ currentViewMode WRITE setCurrentViewMode ) 35 36 // Used by konqueror when typing something like /home/dfaure/*.diff in the location bar 37 Q_PROPERTY( QString nameFilter READ nameFilter WRITE setNameFilter ) 38 39 // Used by konqueror to implement the --select command-line option 40 Q_PROPERTY( QList<QUrl> filesToSelect READ filesToSelect WRITE setFilesToSelect ) 41 42 public: 43 explicit DolphinPart(QWidget* parentWidget, QObject* parent, 44 const KPluginMetaData& metaData, const QVariantList& args); 45 ~DolphinPart() override; 46 47 /** 48 * Standard KParts::ReadOnlyPart openUrl method. 49 * Called by Konqueror to view a directory in DolphinPart. 50 */ 51 bool openUrl(const QUrl& url) override; 52 53 /// see the supportsUndo property supportsUndo()54 bool supportsUndo() const { return true; } 55 56 /** 57 * Used by konqueror for setting the view mode 58 * @param viewModeName internal name for the view mode, like "icons" 59 * Those names come from the Actions line in dolphinpart.desktop, 60 * and have to match the name of the KActions. 61 */ 62 void setCurrentViewMode(const QString& viewModeName); 63 64 /** 65 * Used by konqueror for displaying the current view mode. 66 * @see setCurrentViewMode 67 */ 68 QString currentViewMode() const; 69 70 /// Returns the view owned by this part; used by DolphinPartBrowserExtension view()71 DolphinView* view() { return m_view; } 72 73 /** 74 * Sets a name filter, like *.diff 75 */ 76 void setNameFilter(const QString& nameFilter); 77 78 /** 79 * Returns the current name filter. Used by konqueror to show it in the URL. 80 */ nameFilter()81 QString nameFilter() const { return m_nameFilter; } 82 83 protected: 84 /** 85 * We reimplement openUrl so no need to implement openFile. 86 */ openFile()87 bool openFile() override { return true; } 88 89 Q_SIGNALS: 90 /** 91 * Emitted when the view mode changes. Used by konqueror. 92 */ 93 void viewModeChanged(); 94 95 96 /** 97 * Emitted whenever the current URL is about to be changed. 98 */ 99 void aboutToOpenURL(); 100 101 private Q_SLOTS: 102 void slotMessage(const QString& msg); 103 void slotErrorMessage(const QString& msg); 104 /** 105 * Shows the information for the item \a item inside the statusbar. If the 106 * item is null, the default statusbar information is shown. 107 */ 108 void slotRequestItemInfo(const KFileItem& item); 109 /** 110 * Handles clicking on an item 111 */ 112 void slotItemActivated(const KFileItem& item); 113 /** 114 * Handles activation of multiple items 115 */ 116 void slotItemsActivated(const KFileItemList& items); 117 /** 118 * Creates a new window showing the content of \a url. 119 */ 120 void createNewWindow(const QUrl &url); 121 /** 122 * Opens the context menu on the current mouse position. 123 * @pos Position in screen coordinates. 124 * @item File item context. If item is null, the context menu 125 * should be applied to \a url. 126 * @url URL which contains \a item. 127 * @customActions Actions that should be added to the context menu, 128 * if the file item is null. 129 */ 130 void slotOpenContextMenu(const QPoint& pos, 131 const KFileItem& item, 132 const QUrl& url, 133 const QList<QAction*>& customActions); 134 135 /** 136 * Informs the host that we are opening \a url (e.g. after a redirection 137 * coming from KDirLister). 138 * Testcase 1: fish://localhost 139 * Testcase 2: showing a directory that is being renamed by another window (#180156) 140 */ 141 void slotDirectoryRedirection(const QUrl& oldUrl, const QUrl& newUrl); 142 143 /** 144 * Updates the state of the 'Edit' menu actions and emits 145 * the signal selectionChanged(). 146 */ 147 void slotSelectionChanged(const KFileItemList& selection); 148 149 /** 150 * Updates the text of the paste action dependent from 151 * the number of items which are in the clipboard. 152 */ 153 void updatePasteAction(); 154 155 /** 156 * Connected to all "Go" menu actions provided by DolphinPart 157 */ 158 void slotGoTriggered(QAction* action); 159 160 /** 161 * Connected to the "editMimeType" action 162 */ 163 void slotEditMimeType(); 164 165 /** 166 * Connected to the "select_items_matching" action. 167 * Opens a dialog which permits to select all items matching a pattern like "*.jpg". 168 */ 169 void slotSelectItemsMatchingPattern(); 170 171 /** 172 * Connected to the "unselect_items_matching" action. 173 * Opens a dialog which permits to unselect all items matching a pattern like "*.jpg". 174 */ 175 void slotUnselectItemsMatchingPattern(); 176 177 /** 178 * Open a terminal window, starting with the current directory. 179 */ 180 void slotOpenTerminal(); 181 182 /** 183 * Open preferred search tool in the current directory to find files. 184 */ 185 void slotFindFile(); 186 187 /** 188 * Updates the 'Create New...' sub menu, just before it's shown. 189 */ 190 void updateNewMenu(); 191 192 /** 193 * Updates the number of items (= number of files + number of 194 * directories) in the statusbar. If files are selected, the number 195 * of selected files and the sum of the filesize is shown. 196 */ 197 void updateStatusBar(); 198 199 /** 200 * Notify container of folder loading progress. 201 */ 202 void updateProgress(int percent); 203 204 void createDirectory(); 205 206 /** 207 * Called by konqueror --select 208 */ 209 void setFilesToSelect(const QList<QUrl> &files); filesToSelect()210 QList<QUrl> filesToSelect() const { return QList<QUrl>(); } // silence moc 211 212 bool eventFilter(QObject*, QEvent*) override; 213 214 private: 215 void createActions(); 216 void createGoAction(const char* name, const char* iconName, 217 const QString& text, const QString& url, 218 QActionGroup* actionGroup); 219 220 void openSelectionDialog(const QString& title, const QString& text, 221 bool selectItems); 222 QString urlToLocalFilePath(const QUrl &url); 223 QString localFilePathOrHome() const; 224 225 private: 226 DolphinView* m_view; 227 DolphinViewActionHandler* m_actionHandler; 228 DolphinRemoteEncoding* m_remoteEncoding; 229 DolphinPartBrowserExtension* m_extension; 230 DolphinNewFileMenu* m_newFileMenu; 231 QAction* m_findFileAction; 232 QAction* m_openTerminalAction; 233 QString m_nameFilter; 234 DolphinRemoveAction* m_removeAction; 235 Q_DISABLE_COPY(DolphinPart) 236 }; 237 238 #endif /* DOLPHINPART_H */ 239