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

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 LISTPANEL_H
0010 #define LISTPANEL_H
0011 
0012 // QtCore
0013 #include <QDir>
0014 #include <QEvent>
0015 #include <QList>
0016 #include <QPointer>
0017 #include <QString>
0018 #include <QUrl>
0019 // QtGui
0020 #include <QDropEvent>
0021 #include <QHideEvent>
0022 #include <QIcon>
0023 #include <QKeyEvent>
0024 #include <QPixmap>
0025 #include <QPixmapCache>
0026 #include <QShowEvent>
0027 // QtWidgets
0028 #include <QGridLayout>
0029 #include <QLabel>
0030 #include <QLayout>
0031 #include <QProgressBar>
0032 #include <QSplitter>
0033 #include <QToolButton>
0034 #include <QWidget>
0035 
0036 #include <KCompletion/KLineEdit>
0037 #include <KConfigCore/KConfigGroup>
0038 #include <KIO/Job>
0039 #include <KIOCore/KFileItem>
0040 #include <KIOFileWidgets/KUrlNavigator>
0041 
0042 #include "krpanel.h"
0043 #include "panelcontextmenu.h"
0044 
0045 #define PROP_SYNC_BUTTON_ON 1
0046 #define PROP_LOCKED 2
0047 #define PROP_PINNED 4
0048 
0049 class DirHistoryButton;
0050 class KrBookmarkButton;
0051 class KrErrorDisplay;
0052 class KrSqueezedTextLabel;
0053 class KrSearchBar;
0054 class KrView;
0055 class KrViewItem;
0056 class ListPanelActions;
0057 class ListPanelFunc;
0058 class MediaButton;
0059 class Sidebar;
0060 class SizeCalculator;
0061 
0062 class ListPanel : public QWidget, public KrPanel
0063 {
0064     friend class ListPanelFunc;
0065     Q_OBJECT
0066 public:
0067     enum TabState {
0068         DEFAULT,
0069         LOCKED,
0070         // locked tab with changeable address
0071         PINNED
0072     };
0073 
0074     // constructor create the panel, but DOESN'T fill it with data, use start()
0075     ListPanel(QWidget *parent, AbstractPanelManager *manager, const KConfigGroup &cfg = KConfigGroup());
0076     ~ListPanel() override;
0077 
0078     void otherPanelChanged() override;
0079 
0080     void start(const QUrl &url = QUrl());
0081 
0082     void reparent(QWidget *parent, AbstractPanelManager *manager);
0083 
0084     int getType()
0085     {
0086         return panelType;
0087     }
0088     void changeType(int);
0089     bool isLocked()
0090     {
0091         return _tabState == TabState::LOCKED;
0092     }
0093     bool isPinned()
0094     {
0095         return _tabState == TabState::PINNED;
0096     }
0097     void setTabState(TabState tabState)
0098     {
0099         _tabState = tabState;
0100     }
0101 
0102     ListPanelActions *actions()
0103     {
0104         return _actions;
0105     }
0106     QString lastLocalPath() const;
0107     QString getCurrentName() const;
0108     QStringList getSelectedNames();
0109     void setButtons();
0110     void setJumpBack(QUrl url);
0111 
0112     int getProperties();
0113     void setProperties(int);
0114 
0115     void getFocusCandidates(QVector<QWidget *> &widgets);
0116 
0117     void saveSettings(KConfigGroup cfg, bool saveHistory);
0118     void restoreSettings(KConfigGroup cfg);
0119 
0120     void setPinnedUrl(QUrl &pinnedUrl)
0121     {
0122         _pinnedUrl = pinnedUrl;
0123     };
0124     QUrl pinnedUrl() const
0125     {
0126         return _pinnedUrl;
0127     };
0128 
0129 public slots:
0130     void handleDrop(QDropEvent *event, bool onView = false); // handle drops on frame or view
0131     void handleDrop(const QUrl &destination, QDropEvent *event); // handle drops with destination
0132     void popRightClickMenu(const QPoint &);
0133     void popEmptyRightClickMenu(const QPoint &);
0134     void compareDirs(bool otherPanelToo = true);
0135     void slotFocusOnMe(bool focus = true);
0136     void slotUpdateTotals();
0137     // react to file changes in filesystem (path change or refresh)
0138     void slotStartUpdate(bool directoryChange);
0139     void toggleSidebar();
0140     void panelVisible(); // called when the panel becomes active
0141     void panelHidden(); // called when panel becomes inactive
0142     void slotRefreshColors();
0143     void cancelProgress(); // cancel filesystem refresh and/or preview (if running)
0144     void setNavigatorUrl(const QUrl &url);
0145 
0146     void openMedia();
0147     void openHistory();
0148     void openBookmarks();
0149     void rightclickMenu();
0150     void toggleSyncBrowse();
0151     void editLocation();
0152     void showSearchBar();
0153     void showSearchBarSelection();
0154     void showSearchBarFilter();
0155     void jumpBack();
0156     void setJumpBack()
0157     {
0158         setJumpBack(virtualPath());
0159     }
0160 
0161     ///////////////////////// service functions - called internally ////////////////////////
0162     void prepareToDelete(); // internal use only
0163 
0164 protected:
0165     void keyPressEvent(QKeyEvent *e) override;
0166     void mousePressEvent(QMouseEvent *) override
0167     {
0168         slotFocusOnMe();
0169     }
0170     void showEvent(QShowEvent *) override;
0171     void hideEvent(QHideEvent *) override;
0172     bool eventFilter(QObject *watched, QEvent *e) override;
0173 
0174     void showButtonMenu(QToolButton *b);
0175     void createView();
0176     void updateButtons();
0177 
0178     static int defaultPanelType();
0179     static bool isNavigatorEditModeSet(); // return the navigator edit mode setting
0180 
0181 protected slots:
0182     void slotCurrentChanged(KrViewItem *item);
0183     void startDragging(const QStringList &, const QPixmap &);
0184     void slotPreviewJobStarted(KJob *job);
0185     void slotPreviewJobPercent(KJob *job, unsigned long percent);
0186     void slotPreviewJobResult(KJob *job);
0187     // those handle the in-panel refresh notifications
0188     void slotRefreshJobStarted(KIO::Job *job);
0189     void inlineRefreshInfoMessage(KJob *job, const QString &msg);
0190     void inlineRefreshListResult(KJob *job);
0191     void inlineRefreshPercent(KJob *, unsigned long);
0192     void slotFilesystemError(const QString &msg);
0193     void duplicateTab(KrViewItem *item);
0194     void duplicateTab(const QUrl &url, bool nextToThis = false);
0195     void slotNavigatorUrlChanged(const QUrl &url);
0196     void resetNavigatorMode(); // set navigator mode after focus was lost
0197     // update filesystem meta info, disk-free and mount status
0198     void updateFilesystemStats(const QString &metaInfo, const QString &fsType, KIO::filesize_t total, KIO::filesize_t free);
0199 
0200 signals:
0201     void signalStatus(QString msg); // emitted when we need to update the status bar
0202     void pathChanged(const QUrl &url); // directory changed or refreshed
0203     void activate(); // emitted when the user changes panels
0204     void finishedDragging(); // NOTE: currently not used
0205     void signalRefreshColors(bool active);
0206 
0207 protected:
0208     int panelType;
0209     QString _lastLocalPath;
0210     QUrl _jumpBackURL;
0211     int colorMask;
0212     bool compareMode;
0213     // FilterSpec    filter;
0214     KJob *previewJob;
0215     KIO::Job *inlineRefreshJob;
0216     ListPanelActions *_actions;
0217 
0218     QPixmap currDragPix;
0219     QWidget *clientArea;
0220     QSplitter *sidebarSplitter;
0221     KUrlNavigator *urlNavigator;
0222     KrSearchBar *searchBar;
0223     QToolButton *backButton, *forwardButton;
0224     QToolButton *cdRootButton;
0225     QToolButton *cdHomeButton;
0226     QToolButton *cdUpButton;
0227     QToolButton *cdOtherButton;
0228     QToolButton *sidebarPositionButton;
0229     QToolButton *sidebarButton;
0230     Sidebar *sidebar; // lazy initialized
0231     KrBookmarkButton *bookmarksButton;
0232     KrSqueezedTextLabel *status, *totals, *freeSpace;
0233 
0234     QProgressBar *quickSizeCalcProgress;
0235     QToolButton *cancelQuickSizeCalcButton;
0236     QProgressBar *previewProgress;
0237     DirHistoryButton *historyButton;
0238     MediaButton *mediaButton;
0239     QToolButton *syncBrowseButton;
0240     QToolButton *cancelProgressButton; // for thumbnail previews and filesystem refresh
0241     KrErrorDisplay *fileSystemError;
0242 
0243 private:
0244     bool handleDropInternal(QDropEvent *event, const QString &dir);
0245     int sidebarPosition() const; // 0: West, 1: North, 2: East, 3: South
0246     void setSidebarPosition(int);
0247     void connectQuickSizeCalculator(SizeCalculator *sizeCalculator);
0248 
0249 private:
0250     QUrl _navigatorUrl; // distinguish between new user set URL and new custom set URL
0251     QUrl _pinnedUrl; // only for TabState::PINNED
0252     TabState _tabState;
0253     QList<int> sidebarSplitterSizes;
0254     QScopedPointer<PanelContextMenu> _contextMenu;
0255 };
0256 
0257 #endif