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 LISTPANEL_H 24 #define LISTPANEL_H 25 26 // QtCore 27 #include <QString> 28 #include <QDir> 29 #include <QList> 30 #include <QEvent> 31 #include <QPointer> 32 #include <QUrl> 33 // QtGui 34 #include <QPixmap> 35 #include <QPixmapCache> 36 #include <QIcon> 37 #include <QDropEvent> 38 #include <QKeyEvent> 39 #include <QShowEvent> 40 #include <QHideEvent> 41 // QtWidgets 42 #include <QProgressBar> 43 #include <QWidget> 44 #include <QLabel> 45 #include <QLayout> 46 #include <QSplitter> 47 #include <QToolButton> 48 #include <QGridLayout> 49 50 #include <KCompletion/KLineEdit> 51 #include <KConfigCore/KConfigGroup> 52 #include <KIO/Job> 53 #include <KIOCore/KFileItem> 54 #include <KIOFileWidgets/KUrlNavigator> 55 56 #include "krpanel.h" 57 58 #define PROP_SYNC_BUTTON_ON 1 59 #define PROP_LOCKED 2 60 #define PROP_PINNED 4 61 62 class DirHistoryButton; 63 class KrBookmarkButton; 64 class KrErrorDisplay; 65 class KrSqueezedTextLabel; 66 class KrSearchBar; 67 class KrView; 68 class KrViewItem; 69 class ListPanelActions; 70 class ListPanelFunc; 71 class MediaButton; 72 class Sidebar; 73 class SizeCalculator; 74 75 class ListPanel : public QWidget, public KrPanel 76 { 77 friend class ListPanelFunc; 78 Q_OBJECT 79 public: 80 81 enum TabState { 82 DEFAULT, 83 LOCKED, 84 // locked tab with changeable address 85 PINNED 86 }; 87 88 // constructor create the panel, but DOESN'T fill it with data, use start() 89 ListPanel(QWidget *parent, AbstractPanelManager *manager, KConfigGroup cfg = KConfigGroup()); 90 ~ListPanel(); 91 92 virtual void otherPanelChanged() Q_DECL_OVERRIDE; 93 94 void start(const QUrl &url = QUrl()); 95 96 void reparent(QWidget *parent, AbstractPanelManager *manager); 97 getType()98 int getType() { 99 return panelType; 100 } 101 void changeType(int); isLocked()102 bool isLocked() { 103 return _tabState == TabState::LOCKED; 104 } isPinned()105 bool isPinned() { 106 return _tabState == TabState::PINNED; 107 } setTabState(TabState tabState)108 void setTabState(TabState tabState) { 109 _tabState = tabState; 110 } 111 actions()112 ListPanelActions *actions() { 113 return _actions; 114 } 115 QString lastLocalPath() const; 116 QString getCurrentName() const; 117 QStringList getSelectedNames(); 118 void setButtons(); 119 void setJumpBack(QUrl url); 120 121 int getProperties(); 122 void setProperties(int); 123 124 void getFocusCandidates(QVector<QWidget*> &widgets); 125 126 void saveSettings(KConfigGroup cfg, bool saveHistory); 127 void restoreSettings(KConfigGroup cfg); 128 setPinnedUrl(QUrl & pinnedUrl)129 void setPinnedUrl(QUrl &pinnedUrl) { _pinnedUrl = pinnedUrl; }; pinnedUrl()130 QUrl pinnedUrl() const { return _pinnedUrl; }; 131 132 public slots: 133 void popRightClickMenu(const QPoint&); 134 void popEmptyRightClickMenu(const QPoint &); 135 void compareDirs(bool otherPanelToo = true); 136 void slotFocusOnMe(bool focus = true); 137 void slotUpdateTotals(); 138 // react to file changes in filesystem (path change or refresh) 139 void slotStartUpdate(bool directoryChange); 140 void toggleSidebar(); 141 void panelVisible(); // called when the panel becomes active 142 void panelHidden(); // called when panel becomes inactive 143 void refreshColors(); 144 void cancelProgress(); // cancel filesystem refresh and/or preview (if running) 145 void setNavigatorUrl(const QUrl &url); 146 147 void openMedia(); 148 void openHistory(); 149 void openBookmarks(); 150 void rightclickMenu(); 151 void toggleSyncBrowse(); 152 void editLocation(); 153 void showSearchBar(); 154 void showSearchBarSelection(); 155 void showSearchBarFilter(); 156 void jumpBack(); setJumpBack()157 void setJumpBack() { 158 setJumpBack(virtualPath()); 159 } 160 161 ///////////////////////// service functions - called internally //////////////////////// 162 void prepareToDelete(); // internal use only 163 164 protected: 165 virtual void keyPressEvent(QKeyEvent *e) Q_DECL_OVERRIDE; mousePressEvent(QMouseEvent *)166 virtual void mousePressEvent(QMouseEvent*) Q_DECL_OVERRIDE { 167 slotFocusOnMe(); 168 } 169 virtual void showEvent(QShowEvent *) Q_DECL_OVERRIDE; 170 virtual void hideEvent(QHideEvent *) Q_DECL_OVERRIDE; 171 virtual bool eventFilter(QObject * watched, QEvent * e) Q_DECL_OVERRIDE; 172 173 void showButtonMenu(QToolButton *b); 174 void createView(); 175 void updateButtons(); 176 177 static int defaultPanelType(); 178 static bool isNavigatorEditModeSet(); // return the navigator edit mode setting 179 180 protected slots: 181 void slotCurrentChanged(KrViewItem *item); 182 void handleDrop(QDropEvent *event, bool onView = false); // handle drops on frame or view 183 void handleDrop(const QUrl &destination, QDropEvent *event); // handle drops with destination 184 void startDragging(QStringList, QPixmap); 185 void slotPreviewJobStarted(KJob *job); 186 void slotPreviewJobPercent(KJob *job, unsigned long percent); 187 void slotPreviewJobResult(KJob *job); 188 // those handle the in-panel refresh notifications 189 void slotRefreshJobStarted(KIO::Job* job); 190 void inlineRefreshInfoMessage(KJob* job, const QString &msg); 191 void inlineRefreshListResult(KJob* job); 192 void inlineRefreshPercent(KJob*, unsigned long); 193 void slotFilesystemError(QString msg); 194 void newTab(KrViewItem *item); 195 void newTab(const QUrl &url, bool nextToThis = false); 196 void slotNavigatorUrlChanged(const QUrl &url); 197 void resetNavigatorMode(); // set navigator mode after focus was lost 198 // update filesystem meta info, disk-free and mount status 199 void updateFilesystemStats(const QString &metaInfo, const QString &fsType, 200 KIO::filesize_t total, KIO::filesize_t free); 201 202 signals: 203 void signalStatus(QString msg); // emmited when we need to update the status bar 204 void pathChanged(const QUrl &url); // directory changed or refreshed 205 void activate(); // emitted when the user changes panels 206 void finishedDragging(); // NOTE: currently not used 207 void refreshColors(bool active); 208 209 protected: 210 int panelType; 211 QString _lastLocalPath; 212 QUrl _jumpBackURL; 213 int colorMask; 214 bool compareMode; 215 //FilterSpec filter; 216 KJob *previewJob; 217 KIO::Job *inlineRefreshJob; 218 ListPanelActions *_actions; 219 220 QPixmap currDragPix; 221 QWidget *clientArea; 222 QSplitter *sidebarSplitter; 223 KUrlNavigator* urlNavigator; 224 KrSearchBar* searchBar; 225 QToolButton *backButton, *forwardButton; 226 QToolButton *cdRootButton; 227 QToolButton *cdHomeButton; 228 QToolButton *cdUpButton; 229 QToolButton *cdOtherButton; 230 QToolButton *sidebarPositionButton; 231 QToolButton *sidebarButton; 232 Sidebar *sidebar; // lazy initialized 233 KrBookmarkButton *bookmarksButton; 234 KrSqueezedTextLabel *status, *totals, *freeSpace; 235 236 QProgressBar *quickSizeCalcProgress; 237 QToolButton *cancelQuickSizeCalcButton; 238 QProgressBar *previewProgress; 239 DirHistoryButton* historyButton; 240 MediaButton *mediaButton; 241 QToolButton *syncBrowseButton; 242 QToolButton *cancelProgressButton; // for thumbnail previews and filesystem refresh 243 KrErrorDisplay *fileSystemError; 244 245 private: 246 bool handleDropInternal(QDropEvent *event, const QString &dir); 247 int sidebarPosition() const; // 0: West, 1: North, 2: East, 3: South 248 void setSidebarPosition(int); 249 void connectQuickSizeCalculator(SizeCalculator *sizeCalculator); 250 251 private: 252 QUrl _navigatorUrl; // distinguish between new user set URL and new custom set URL 253 QUrl _pinnedUrl; // only for TabState::PINNED 254 TabState _tabState; 255 QList<int> sidebarSplitterSizes; 256 }; 257 258 #endif 259