File indexing completed on 2024-04-14 04:52:51

0001 /* This file is part of FSView.
0002     SPDX-FileCopyrightText: 2002, 2003 Josef Weidendorfer <Josef.Weidendorfer@gmx.de>
0003 
0004     SPDX-License-Identifier: GPL-2.0-only
0005 */
0006 
0007 /*
0008  * The KPart embedding the FSView widget
0009  */
0010 
0011 #ifndef FSVIEW_PART_H
0012 #define FSVIEW_PART_H
0013 
0014 #include <kparts_version.h>
0015 #include <kparts/part.h>
0016 
0017 #include <KIO/Job>
0018 
0019 #include "fsview.h"
0020 #include "browserextension.h"
0021 
0022 class KActionMenu;
0023 
0024 class FSViewPart;
0025 
0026 class FSViewNavigationExtension : public BrowserExtension
0027 {
0028     Q_OBJECT
0029 
0030 public:
0031     explicit FSViewNavigationExtension(FSViewPart *viewPart);
0032     ~FSViewNavigationExtension() override;
0033 
0034 public slots:
0035     void selected(TreeMapItem *);
0036 
0037     void itemSingleClicked(TreeMapItem *i);
0038     void itemDoubleClicked(TreeMapItem *i);
0039 
0040     void trash();
0041     void del();
0042     void editMimeType();
0043 
0044     void refresh();
0045 
0046     void copy()
0047     {
0048         copySelection(false);
0049     }
0050     void cut()
0051     {
0052         copySelection(true);
0053     }
0054 private:
0055     void copySelection(bool move);
0056 
0057     FSView *_view;
0058 };
0059 
0060 class FSJob: public KIO::Job
0061 {
0062     Q_OBJECT
0063 
0064 public:
0065     explicit FSJob(FSView *);
0066 
0067     virtual void kill(bool quietly = true);
0068 
0069 public slots:
0070     void progressSlot(int percent, int dirs, const QString &lastDir);
0071 
0072 #if QT_VERSION_MAJOR < 6
0073 protected slots:
0074     void slotInfoMessage(KJob * job, const QString & plain, const QString & rich=QString()) override;
0075 #endif
0076 
0077 private:
0078     FSView *_view;
0079 };
0080 
0081 class FSViewPart : public KParts::ReadOnlyPart
0082 {
0083     Q_OBJECT
0084     Q_PROPERTY(bool supportsUndo READ supportsUndo)
0085 public:
0086     FSViewPart(QWidget *parentWidget,
0087                QObject *parent,
0088                const KPluginMetaData& metaData,
0089                const QList<QVariant> &args);
0090     ~FSViewPart() override;
0091 
0092     bool supportsUndo() const
0093     {
0094         return false;
0095     }
0096 
0097     FSView *view() const
0098     {
0099         return _view;
0100     }
0101 
0102     /**
0103      * Return custom componentName for KXMLGUIClient, as for historical reasons the plugin id is not used
0104      */
0105     QString componentName() const override;
0106 
0107 public slots:
0108     void updateActions();
0109     void contextMenu(TreeMapItem *, const QPoint &);
0110     void showInfo();
0111     void showHelp();
0112     void startedSlot();
0113     void completedSlot(int dirs);
0114     void slotShowVisMenu();
0115     void slotShowAreaMenu();
0116     void slotShowDepthMenu();
0117     void slotShowColorMenu();
0118     void slotProperties();
0119 
0120 protected:
0121     /**
0122      * This must be implemented by each part
0123      */
0124     bool openFile() override;
0125     bool openUrl(const QUrl &url) override;
0126     bool closeUrl() override;
0127 
0128 private:
0129     void setNonStandardActionEnabled(const char *actionName, bool enabled);
0130     KFileItemList selectedFileItems() const;
0131 
0132     FSView *_view;
0133     FSJob *_job;
0134     FSViewNavigationExtension *_ext;
0135     KActionMenu *_visMenu, *_areaMenu, *_depthMenu, *_colorMenu;
0136 };
0137 
0138 #endif // FSVIEW_PART_H