1 /***************************************************************************** 2 * Copyright (C) 2000 Shie Erlich <krusader@users.sourceforge.net> * 3 * Copyright (C) 2000 Rafi Yanai <krusader@users.sourceforge.net> * 4 * Copyright (C) 2004-2019 Krusader Krew [https://krusader.org] * 5 * * 6 * This file is part of Krusader [https://krusader.org]. * 7 * * 8 * Krusader is free software: you can redistribute it and/or modify * 9 * it under the terms of the GNU General Public License as published by * 10 * the Free Software Foundation, either version 2 of the License, or * 11 * (at your option) any later version. * 12 * * 13 * Krusader is distributed in the hope that it will be useful, * 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 16 * GNU General Public License for more details. * 17 * * 18 * You should have received a copy of the GNU General Public License * 19 * along with Krusader. If not, see [http://www.gnu.org/licenses/]. * 20 *****************************************************************************/ 21 22 23 #ifndef PANELFUNC_H 24 #define PANELFUNC_H 25 26 // QtCore 27 #include <QObject> 28 #include <QTimer> 29 #include <QUrl> 30 // QtGui 31 #include <QClipboard> 32 33 #include <KCoreAddons/KJob> 34 #include <KIO/Global> 35 #include <KService/KService> 36 37 class DirHistoryQueue; 38 class FileItem; 39 class FileSystem; 40 class KrViewItem; 41 class ListPanel; 42 class SizeCalculator; 43 44 class ListPanelFunc : public QObject 45 { 46 friend class ListPanel; 47 Q_OBJECT 48 public slots: 49 void execute(const QString&); 50 void goInside(const QString&); 51 void openUrl(const QUrl &path, const QString& nameToMakeCurrent = QString(), 52 bool manuallyEntered = false); 53 void rename(const QString &oldname, const QString &newname); 54 55 // actions 56 void historyBackward(); 57 void historyForward(); 58 void dirUp(); 59 void refresh(); 60 void home(); 61 void root(); 62 void cdToOtherPanel(); 63 void FTPDisconnect(); 64 void newFTPconnection(); 65 void terminal(); 66 void view(); 67 void viewDlg(); 68 void editFile(const QUrl &fileToCreate = QUrl()); 69 /** Create a new textfile and edit it. */ 70 void editNewFile(); moveFilesDelayed()71 void moveFilesDelayed() { moveFiles(true); } copyFilesDelayed()72 void copyFilesDelayed() { copyFiles(true); } 73 void moveFiles(bool enqueue = false) { copyFiles(enqueue, true); } 74 void copyFiles(bool enqueue = false, bool move = false); 75 76 /*! 77 * asks the user the new directory name 78 */ 79 void mkdir(); 80 /** Delete or move selected files to trash - depending on user setting. */ defaultDeleteFiles()81 void defaultDeleteFiles() { defaultOrAlternativeDeleteFiles(false); } 82 /** Delete or move selected files to trash - inverting the user setting. */ alternativeDeleteFiles()83 void alternativeDeleteFiles() { defaultOrAlternativeDeleteFiles(true); } 84 /** Delete virtual files or directories in virtual filesystem. */ 85 void removeVirtualFiles(); 86 void rename(); 87 void krlink(bool sym = true); 88 void createChecksum(); 89 void matchChecksum(); 90 void pack(); 91 void unpack(); 92 void testArchive(); 93 /** Calculate the occupied space of the currently selected items and show a dialog. */ 94 void calcSpace(); 95 /** Calculate the occupied space of the current item without dialog. */ 96 void quickCalcSpace(); 97 void properties(); cut()98 void cut() { 99 copyToClipboard(true); 100 } 101 void copyToClipboard(bool move = false); 102 void pasteFromClipboard(); 103 void syncOtherPanel(); 104 /** Disable refresh if panel is not visible. */ 105 void setPaused(bool paused); 106 107 public: 108 explicit ListPanelFunc(ListPanel *parent); 109 ~ListPanelFunc(); 110 111 FileSystem* files(); // return a pointer to the filesystem 112 QUrl virtualDirectory(); // return the current URL (simulated when panel is paused) 113 114 FileItem* getFileItem(KrViewItem *item); 115 FileItem* getFileItem(const QString& name); 116 117 void refreshActions(); 118 void redirectLink(); 119 void runService(const KService &service, QList<QUrl> urls); 120 void displayOpenWithDialog(QList<QUrl> urls); 121 QUrl browsableArchivePath(const QString &); 122 void deleteFiles(bool moveToTrash); 123 124 ListPanelFunc* otherFunc(); 125 bool atHome(); 126 127 /** Ask user for confirmation before deleting files. Returns only confirmed files.*/ 128 static QList<QUrl> confirmDeletion(const QList<QUrl> &urls, bool moveToTrash, 129 bool virtualFS, bool showPath); 130 131 protected slots: 132 // Load the current url from history and refresh filesystem and panel to it 133 void doRefresh(); 134 void slotFileCreated(KJob *job, const QUrl filePath); // a file has been created by editNewFile() 135 void historyGotoPos(int pos); 136 void clipboardChanged(QClipboard::Mode mode); 137 // Update the directory size in view 138 void slotSizeCalculated(const QUrl &url, KIO::filesize_t size); 139 140 protected: 141 QUrl cleanPath(const QUrl &url); 142 bool isSyncing(const QUrl &url); 143 // when externallyExecutable == true, the file can be executed or opened with other software 144 void openFileNameInternal(const QString &name, bool externallyExecutable); 145 void immediateOpenUrl(const QUrl &url); 146 void openUrlInternal(const QUrl &url, const QString& makeCurrent, 147 bool immediately, bool manuallyEntered); 148 void runCommand(QString cmd); 149 150 ListPanel* panel; // our ListPanel 151 DirHistoryQueue* history; 152 FileSystem* fileSystemP; // pointer to fileSystem. 153 QTimer delayTimer; 154 QUrl syncURL; 155 bool urlManuallyEntered; 156 157 static QPointer<ListPanelFunc> copyToClipboardOrigin; 158 159 private: 160 void defaultOrAlternativeDeleteFiles(bool invert); 161 bool getSelectedFiles(QStringList& args); 162 SizeCalculator *createAndConnectSizeCalculator(const QList<QUrl> &urls); 163 bool _isPaused; // do not refresh while panel is not visible 164 bool _refreshAfterPaused; // refresh after not paused anymore 165 QPointer<SizeCalculator> _quickSizeCalculator; 166 }; 167 168 #endif 169