File indexing completed on 2024-04-28 17:06:25

0001 /*
0002     SPDX-FileCopyrightText: 2000 Shie Erlich <krusader@users.sourceforge.net>
0003     SPDX-FileCopyrightText: 2000 Rafi Yanai <krusader@users.sourceforge.net>
0004     SPDX-FileCopyrightText: 2004-2022 Krusader Krew <https://krusader.org>
0005 
0006     SPDX-License-Identifier: GPL-2.0-or-later
0007 */
0008 
0009 #ifndef PANELFUNC_H
0010 #define PANELFUNC_H
0011 
0012 // QtCore
0013 #include <QObject>
0014 #include <QTimer>
0015 #include <QUrl>
0016 // QtGui
0017 #include <QClipboard>
0018 
0019 #include <KCoreAddons/KJob>
0020 #include <KIO/Global>
0021 #include <KService/KService>
0022 
0023 class DirHistoryQueue;
0024 class FileItem;
0025 class FileSystem;
0026 class KrViewItem;
0027 class ListPanel;
0028 class SizeCalculator;
0029 
0030 class ListPanelFunc : public QObject
0031 {
0032     friend class ListPanel;
0033     Q_OBJECT
0034 public slots:
0035     void execute(const QString &);
0036     void goInside(const QString &);
0037     void openUrl(const QUrl &path, const QString &nameToMakeCurrent = QString(), bool manuallyEntered = false);
0038     void rename(const QString &oldname, const QString &newname);
0039 
0040     // actions
0041     void historyBackward();
0042     void historyForward();
0043     void dirUp();
0044     void refresh();
0045     void home();
0046     void root();
0047     void cdToOtherPanel();
0048     void FTPDisconnect();
0049     void newFTPconnection();
0050     void terminal();
0051     void view();
0052     void viewDlg();
0053     void editFile(const QUrl &filePath = QUrl());
0054     /** Ask for a filename; if it doesn't exist, create it; edit it */
0055     void askEditFile();
0056     void moveFilesDelayed()
0057     {
0058         moveFiles(true);
0059     }
0060     void copyFilesDelayed()
0061     {
0062         copyFiles(true);
0063     }
0064     void moveFiles(bool enqueue = false)
0065     {
0066         copyFiles(enqueue, true);
0067     }
0068     void copyFiles(bool enqueue = false, bool move = false);
0069 
0070     /*!
0071      * asks the user the new directory name
0072      */
0073     void mkdir();
0074     /** Delete or move selected files to trash - depending on user setting. */
0075     void defaultDeleteFiles()
0076     {
0077         defaultOrAlternativeDeleteFiles(false);
0078     }
0079     /** Delete or move selected files to trash - inverting the user setting. */
0080     void alternativeDeleteFiles()
0081     {
0082         defaultOrAlternativeDeleteFiles(true);
0083     }
0084     /** Delete virtual files or directories in virtual filesystem. */
0085     void removeVirtualFiles();
0086     void rename();
0087     void krlink(bool sym = true);
0088     void createChecksum();
0089     void matchChecksum();
0090     void pack();
0091     void unpack();
0092     void testArchive();
0093     /** Calculate the occupied space of the currently selected items and show a dialog. */
0094     void calcSpace();
0095     /** Calculate the occupied space of the current item without dialog. */
0096     void quickCalcSpace();
0097     void properties();
0098     void cut()
0099     {
0100         copyToClipboard(true);
0101     }
0102     void copyToClipboard(bool move = false);
0103     void pasteFromClipboard();
0104     void syncOtherPanel();
0105     /** Disable refresh if panel is not visible. */
0106     void setPaused(bool paused);
0107 
0108 public:
0109     explicit ListPanelFunc(ListPanel *parent);
0110     ~ListPanelFunc() override;
0111 
0112     FileSystem *files(); // return a pointer to the filesystem
0113     QUrl virtualDirectory(); // return the current URL (simulated when panel is paused)
0114 
0115     FileItem *getFileItem(KrViewItem *item);
0116     FileItem *getFileItem(const QString &name);
0117 
0118     void refreshActions();
0119     void redirectLink();
0120     void runService(const KService &service, const QList<QUrl> &urls);
0121     void displayOpenWithDialog(const QList<QUrl> &urls);
0122     QUrl browsableArchivePath(const QString &);
0123     void deleteFiles(bool moveToTrash);
0124 
0125     ListPanelFunc *otherFunc();
0126     bool atHome();
0127 
0128     /** Ask user for confirmation before deleting files. Returns only confirmed files.*/
0129     static QList<QUrl> confirmDeletion(const QList<QUrl> &urls, bool moveToTrash, bool virtualFS, bool showPath);
0130 
0131 protected slots:
0132     // Load the current url from history and refresh filesystem and panel to it
0133     void doRefresh();
0134     void slotFileCreated(KJob *job, const QUrl filePath); // a file has been created by askEditFile() or slotStatEdit()
0135     void historyGotoPos(int pos);
0136     void clipboardChanged(QClipboard::Mode mode);
0137     // Update the directory size in view
0138     void slotSizeCalculated(const QUrl &url, KIO::filesize_t size);
0139     // Get some information about a file that is going to be edited
0140     // and perform some steps before the edition
0141     void slotStatEdit(KJob *job);
0142 
0143 protected:
0144     QUrl cleanPath(const QUrl &url);
0145     bool isSyncing(const QUrl &url);
0146     // when externallyExecutable == true, the file can be executed or opened with other software
0147     void openFileNameInternal(const QString &name, bool externallyExecutable);
0148     void immediateOpenUrl(const QUrl &url);
0149     void openUrlInternal(const QUrl &url, const QString &makeCurrent, bool immediately, bool manuallyEntered);
0150     void runCommand(const QString &cmd);
0151 
0152     ListPanel *panel; // our ListPanel
0153     DirHistoryQueue *history;
0154     FileSystem *fileSystemP; // pointer to fileSystem.
0155     QTimer delayTimer;
0156     QUrl syncURL;
0157     bool urlManuallyEntered;
0158 
0159     static QPointer<ListPanelFunc> copyToClipboardOrigin;
0160 
0161 private:
0162     void defaultOrAlternativeDeleteFiles(bool invert);
0163     bool getSelectedFiles(QStringList &args);
0164     SizeCalculator *createAndConnectSizeCalculator(const QList<QUrl> &urls);
0165     bool _isPaused; // do not refresh while panel is not visible
0166     bool _refreshAfterPaused; // refresh after not paused anymore
0167     QPointer<SizeCalculator> _quickSizeCalculator;
0168 };
0169 
0170 #endif