1 /**************************************************************************** 2 * This file is part of qtFM, a simple, fast file manager. 3 * Copyright (C) 2010,2011,2012 Wittfella 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/> 17 * 18 * Contact e-mail: wittfella@qtfm.org 19 * 20 ****************************************************************************/ 21 22 23 #ifndef MAINWINDOW_H 24 #define MAINWINDOW_H 25 26 #include <QMainWindow> 27 #include <QSettings> 28 #include <QSplitter> 29 #include <QTreeView> 30 #include <QListView> 31 #include <QLabel> 32 #include <QStackedWidget> 33 #include <QSortFilterProxyModel> 34 #include <QComboBox> 35 #include <QSignalMapper> 36 #include <QToolBar> 37 #include <QItemDelegate> 38 #include <QStyledItemDelegate> 39 #include <QVector> 40 41 #include "mymodel.h" 42 #include "bookmarkmodel.h" 43 #include "progressdlg.h" 44 #include "propertiesdlg.h" 45 #include "icondlg.h" 46 #include "tabbar.h" 47 #include "fileutils.h" 48 #include "mimeutils.h" 49 #include "customactionsmanager.h" 50 #include "iconview.h" 51 #include "iconlist.h" 52 #include "completer.h" 53 #include "sortmodel.h" 54 55 // libdisks 56 #ifndef NO_UDISKS 57 #include "disks.h" 58 #endif 59 60 // service 61 #ifndef NO_DBUS 62 #include "service.h" 63 #endif 64 65 QT_BEGIN_NAMESPACE 66 class QAction; 67 class QMenu; 68 QT_END_NAMESPACE 69 70 /** 71 * @class MainWindow 72 * @brief The main window class 73 * @author Wittefella 74 */ 75 class MainWindow : public QMainWindow 76 { 77 Q_OBJECT 78 79 public: 80 MainWindow(); 81 myModel *modelList; 82 83 protected: 84 void closeEvent(QCloseEvent *event); 85 86 public slots: 87 void treeSelectionChanged(QModelIndex,QModelIndex); 88 void listSelectionChanged(const QItemSelection, const QItemSelection); 89 void listDoubleClicked(QModelIndex); 90 void lateStart(); 91 void goUpDir(); 92 void goBackDir(); 93 void goHomeDir(); 94 void deleteFile(); 95 void trashFile(); 96 void cutFile(); 97 void copyFile(); 98 bool cutCopyFile(const QString &source, QString dest, qint64 totalSize, bool cut); 99 bool pasteFiles(const QList<QUrl> &files, const QString &newPath, const QStringList &cutList); 100 bool linkFiles(const QList<QUrl> &files, const QString &newPath); 101 void newDir(); 102 void newFile(); 103 void pathEditChanged(QString); 104 void terminalRun(); 105 void executeFile(QModelIndex, bool); 106 void runFile(); 107 void openFile(); 108 void clipboardChanged(); 109 void toggleDetails(); 110 void toggleHidden(); 111 void toggleIcons(); 112 void toggleSortBy(QAction* action); 113 void toggleSortOrder(); 114 void setSortOrder(Qt::SortOrder order); 115 void setSortColumn(QAction *columnAct); 116 void toggleThumbs(); 117 void addBookmarkAction(); 118 void addSeparatorAction(); 119 void delBookmark(); 120 void editBookmark(); 121 void toggleWrapBookmarks(); 122 void showEditDialog(); 123 bool copyFolder(const QString &srcFolder, const QString &dstFolder, qint64, bool); 124 void renameFile(); 125 void actionMapper(QString); 126 void folderPropertiesLauncher(); 127 void bookmarkClicked(QModelIndex); 128 void bookmarkPressed(QModelIndex); 129 void bookmarkShortcutTrigger(); 130 void contextMenuEvent(QContextMenuEvent *); 131 void toggleLockLayout(); 132 void dragLauncher(const QMimeData *data, const QString &newPath, Common::DragMode dragMode); 133 void pasteLauncher(const QMimeData *data, const QString &newPath, const QStringList &cutList, bool link = false); 134 void pasteLauncher(const QList<QUrl> &files, const QString &newPath, const QStringList &cutList, bool link = false); 135 void pasteClipboard(); 136 void progressFinished(int,QStringList); 137 void listItemClicked(QModelIndex); 138 void listItemPressed(QModelIndex); 139 void tabChanged(int index); 140 void newWindow(); 141 void openTab(); 142 void openNewTab(); 143 void tabsOnTop(); 144 int addTab(QString path); 145 void clearCutItems(); 146 void zoomInAction(); 147 void zoomOutAction(); 148 void focusAction(); 149 void openFolderAction(); 150 void exitAction(); 151 void dirLoaded(bool thumbs = true); 152 void updateDir(); 153 void handleReloadDir(const QString &path); 154 void thumbUpdate(const QString &path); 155 void addressChanged(int,int); 156 void loadSettings(bool wState = true, bool hState = true, bool tabState = true, bool thumbState = true); 157 void firstRunBookmarks(bool isFirstRun); 158 void loadBookmarks(); 159 void writeBookmarks(); 160 void handleBookmarksChanged(); 161 void firstRunCustomActions(bool isFirstRun); 162 void showAboutBox(); 163 164 signals: 165 void updateCopyProgress(qint64, qint64, QString); 166 void copyProgressFinished(int,QStringList); 167 168 private slots: 169 void readShortcuts(); 170 void selectApp(); 171 void selectAppForFiles(); 172 void openInApp(); 173 void updateGrid(); 174 // libdisks 175 #ifndef NO_UDISKS 176 void populateMedia(); 177 void handleMediaMountpointChanged(QString path, QString mountpoint); 178 int mediaBookmarkExists(QString path); 179 void handleMediaAdded(QString path); 180 void handleMediaRemoved(QString path); 181 void handleMediaChanged(QString path, bool present); 182 void handleMediaUnmount(); 183 void handleMediaEject(); 184 void handleMediaError(QString path, QString error); 185 #endif 186 void clearCache(); 187 void handlePathRequested(QString path); 188 void slowPathEdit(); 189 void refresh(bool modelRefresh = true, bool loadDir = true); 190 void enableReload(); 191 private: 192 void createActions(); 193 void createActionIcons(); 194 void createMenus(); 195 void createToolBars(); 196 void writeSettings(); 197 void recurseFolder(QString path, QString parent, QStringList *); 198 int showReplaceMsgBox(const QFileInfo &f1, const QFileInfo &f2); 199 QMenu* createOpenWithMenu(); 200 201 int zoom; 202 int zoomTree; 203 int zoomList; 204 int zoomDetail; 205 int zoomBook; 206 int currentView; // 0=list, 1=icons, 2=details 207 int currentSortColumn; // 0=name, 1=size, 3=date 208 Qt::SortOrder currentSortOrder; 209 210 QCompleter *customComplete; 211 tabBar *tabs; 212 MimeUtils *mimeUtils; 213 214 myProgressDialog * progress; 215 PropertiesDialog * properties; 216 QSettings *settings; 217 QDockWidget *dockTree; 218 QDockWidget *dockBookmarks; 219 QVBoxLayout *mainLayout; 220 QStackedWidget *stackWidget; 221 QTreeView *tree; 222 QTreeView *detailTree; 223 QListView *list; 224 QListView *bookmarksList; 225 QComboBox *pathEdit; 226 227 QString term; 228 QFileInfo curIndex; 229 QModelIndex backIndex; 230 231 QSortFilterProxyModel *modelTree; 232 QSortFilterProxyModel *modelView; 233 234 bookmarkmodel *modelBookmarks; 235 QItemSelectionModel *treeSelectionModel; 236 QItemSelectionModel *listSelectionModel; 237 QStringList mounts; 238 239 QList<QIcon> *actionIcons; 240 QList<QAction*> *actionList; 241 QList<QAction*> bookmarkActionList; 242 CustomActionsManager* customActManager; 243 244 //QToolBar *editToolBar; 245 //QToolBar *viewToolBar; 246 QToolBar *navToolBar; 247 QToolBar *addressToolBar; 248 QToolBar *menuToolBar; 249 QStatusBar * status; 250 QLabel * statusSize; 251 QLabel * statusName; 252 QLabel * statusDate; 253 QString startPath; 254 255 QAction *closeAct; 256 QAction *exitAct; 257 QAction *upAct; 258 QAction *backAct; 259 QAction *homeAct; 260 QAction *newTabAct; 261 QAction *hiddenAct; 262 QAction *filterAct; 263 QAction *detailAct; 264 QAction *addBookmarkAct; 265 QAction *addSeparatorAct; 266 QAction *delBookmarkAct; 267 QAction *editBookmarkAct; 268 QAction *wrapBookmarksAct; 269 QAction *deleteAct; 270 QAction *iconAct; 271 QActionGroup *sortByActGrp; 272 QAction *sortNameAct; 273 QAction *sortDateAct; 274 QAction *sortSizeAct; 275 QAction *sortAscAct; 276 QAction *newDirAct; 277 QAction *newFileAct; 278 QAction *cutAct; 279 QAction *copyAct; 280 QAction *pasteAct; 281 QAction *settingsAct; 282 QAction *renameAct; 283 QAction *terminalAct; 284 QAction *openAct; 285 QAction *runAct; 286 QAction *thumbsAct; 287 QAction *folderPropertiesAct; 288 QAction *lockLayoutAct; 289 //QAction *escapeAct; 290 QAction *refreshAct; 291 QAction *zoomInAct; 292 QAction *zoomOutAct; 293 QAction *focusAddressAct; 294 QAction *focusTreeAct; 295 QAction *focusBookmarksAct; 296 QAction *focusListAct; 297 QAction *openFolderAct; 298 QAction *newWinAct; 299 QAction *openTabAct; 300 QAction *openInTabAct; 301 QAction *closeTabAct; 302 QAction *tabsOnTopAct; 303 QAction *aboutAct; 304 QAction *aboutQtAct; 305 #ifndef NO_UDISKS 306 QAction *mediaUnmountAct; 307 QAction *mediaEjectAct; 308 #endif 309 QAction *trashAct; 310 QAction *clearCacheAct; 311 // libdisks 312 #ifndef NO_UDISKS 313 Disks *disks; 314 #endif 315 QString trashDir; 316 317 #ifndef NO_DBUS 318 qtfm *service; 319 #endif 320 321 bool pathHistory; 322 bool showPathInWindowTitle; 323 324 IconViewDelegate *ivdelegate; 325 IconListDelegate *ildelegate; 326 327 // copy of original new filename 328 QString copyXof; 329 // custom timestamp for copy of 330 QString copyXofTS; 331 332 bool ignoreReload; 333 334 QVector<QString> progressQueue; 335 336 protected: 337 bool eventFilter(QObject *o, QEvent *e); 338 }; 339 340 341 342 343 344 345 #endif 346