PCManFM-Qt
desktopwindow.h
1 /*
2 
3  Copyright (C) 2013 Hong Jen Yee (PCMan) <pcman.tw@gmail.com>
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 along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 
20 
21 #ifndef PCMANFM_DESKTOPWINDOW_H
22 #define PCMANFM_DESKTOPWINDOW_H
23 
24 #include "view.h"
25 #include "launcher.h"
26 #include <unordered_map>
27 #include <string>
28 
29 #include <QHash>
30 #include <QPoint>
31 #include <QByteArray>
32 #include <QScreen>
33 #include <xcb/xcb.h>
34 #include <libfm-qt/core/folder.h>
35 
36 namespace Fm {
37 class CachedFolderModel;
38 class ProxyFolderModel;
39 class FolderViewListView;
40 }
41 
42 namespace PCManFM {
43 
44 class Settings;
45 
46 class DesktopWindow : public View {
47  Q_OBJECT
48 public:
49  friend class Application;
50 
51  enum WallpaperMode {
52  WallpaperNone,
53  WallpaperStretch,
54  WallpaperFit,
55  WallpaperCenter,
56  WallpaperTile,
57  WallpaperZoom
58  };
59 
60  explicit DesktopWindow(int screenNum);
61  virtual ~DesktopWindow();
62 
63  void setForeground(const QColor& color);
64  void setShadow(const QColor& color);
65  void setBackground(const QColor& color);
66  void setDesktopFolder();
67  void setWallpaperFile(const QString& filename);
68  void setWallpaperMode(WallpaperMode mode = WallpaperStretch);
69  void setLastSlide(const QString& filename);
70  void setWallpaperDir(const QString& dirname);
71  void setSlideShowInterval(int interval);
72  void setWallpaperRandomize(bool randomize);
73 
74  // void setWallpaperAlpha(qreal alpha);
75  void updateWallpaper(bool checkMTime = false);
76  bool pickWallpaper();
77  void nextWallpaper();
78  void updateFromSettings(Settings& settings, bool changeSlide = true);
79 
80  void queueRelayout(int delay = 0);
81 
82  void saveItemPositions();
83 
84  int screenNum() const {
85  return screenNum_;
86  }
87 
88  void setScreenNum(int num);
89 
90  QScreen* getDesktopScreen() const;
91 
92 protected:
93  virtual void prepareFolderMenu(Fm::FolderMenu* menu) override;
94  virtual void prepareFileMenu(Fm::FileMenu* menu) override;
95  virtual void resizeEvent(QResizeEvent* event) override;
96  virtual void onFileClicked(int type, const std::shared_ptr<const Fm::FileInfo>& fileInfo) override;
97 
98  void loadItemPositions();
99  void retrieveCustomPos();
100  void storeCustomPos();
101 
102  QImage loadWallpaperFile(QSize requiredSize, bool checkMTime);
103 
104  virtual bool event(QEvent* event) override;
105  virtual bool eventFilter(QObject* watched, QEvent* event) override;
106 
107  virtual void childDragMoveEvent(QDragMoveEvent* e) override;
108  virtual void childDropEvent(QDropEvent* e) override;
109  virtual void closeEvent(QCloseEvent* event) override;
110  virtual void paintEvent(QPaintEvent* event) override;
111 
112 protected Q_SLOTS:
113  void onDesktopPreferences();
114  void onCreatingShortcut();
115  void selectAll();
116  void toggleDesktop();
117 
118  void onRowsAboutToBeRemoved(const QModelIndex& parent, int start, int end);
119  void onRowsInserted(const QModelIndex& parent, int start, int end);
120  void onLayoutChanged();
121  void onModelSortFilterChanged();
122  void onFolderStartLoading();
123  void onFolderFinishLoading();
124  void onFilesAdded(const Fm::FileInfoList files);
125 
126  void relayoutItems();
127  void onStickToCurrentPos(bool toggled);
128 
129  // void updateWorkArea();
130 
131  // file operations
132  void onCutActivated();
133  void onCopyActivated();
134  void onCopyFullPathActivated();
135  void onPasteActivated();
136  void onRenameActivated();
137  void onBulkRenameActivated();
138  void onDeleteActivated();
139  void onFilePropertiesActivated();
140 
141  void updateTrashIcon();
142 
143  void onInlineRenaming(const QString& oldName, const QString& newName);
144 
145  void onDecidingDrop(bool accepted);
146 
147 private:
148  void removeBottomGap();
149  QRect getWorkArea(QScreen* screen) const;
150  void addDesktopActions(QMenu* menu);
151  void paintBackground(QPaintEvent* event);
152  void paintDropIndicator();
153  bool stickToPosition(const std::string& file, QPoint& pos,
154  const QRect& workArea, const QSize& grid,
155  const std::set<std::string>& droppedFiles, bool reachedLastCell);
156  static void alignToGrid(QPoint& pos, const QPoint& topLeft, const QSize& grid, const int spacing);
157 
158  void updateShortcutsFromSettings(Settings& settings);
159  void createTrashShortcut(int items);
160  void createHomeShortcut();
161  void createComputerShortcut();
162  void createNetworkShortcut();
163 
164  void createTrash();
165  static void onTrashChanged(GFileMonitor* monitor, GFile* gf, GFile* other, GFileMonitorEvent evt, DesktopWindow* pThis);
166  void trustOurDesktopShortcut(std::shared_ptr<const Fm::FileInfo> file);
167  bool isTrashCan(std::shared_ptr<const Fm::FileInfo> file) const;
168 
169  QImage getWallpaperImage() const;
170 
171  QModelIndex navigateWithKey(int key, Qt::KeyboardModifiers modifiers, const QModelIndex& start = QModelIndex());
172 
173  QModelIndex indexForPos(bool* isTrash, const QPoint& pos, const QRect& workArea, const QSize& grid) const;
174 
175 private:
176  Fm::ProxyFolderModel* proxyModel_;
177  Fm::FolderModel* model_;
178  std::shared_ptr<Fm::Folder> folder_;
179  Fm::FolderViewListView* listView_;
180 
181  QColor fgColor_;
182  QColor bgColor_;
183  QColor shadowColor_;
184  QString wallpaperFile_;
185  WallpaperMode wallpaperMode_;
186  QString lastSlide_;
187  QString wallpaperDir_;
188  int slideShowInterval_;
189  QTimer* wallpaperTimer_;
190  bool wallpaperRandomize_;
191  QPixmap wallpaperPixmap_;
192  Launcher fileLauncher_;
193  bool desktopHideItems_;
194 
195  int screenNum_;
196  std::unordered_map<std::string, QPoint> customItemPos_; // real custom positions
197  std::unordered_map<std::string, QPoint> customPosStorage_; // savable custom positions
198  QTimer* relayoutTimer_;
199  QTimer* selectionTimer_;
200 
201  QRect dropRect_;
202 
203  QTimer* trashUpdateTimer_;
204  GFileMonitor* trashMonitor_;
205 
206  QStringList filesToTrust_;
207 };
208 
209 }
210 
211 #endif // PCMANFM_DESKTOPWINDOW_H
Definition: application.h:56
Definition: desktopwindow.h:46
Definition: launcher.h:30
Definition: settings.h:154
Definition: view.h:37