NDE-FileMAN
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 NDEFILEMAN_DESKTOPWINDOW_H
22 #define NDEFILEMAN_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 #include <QMenu>
36 #include <QDesktopWidget>
37 #include <QFileSystemWatcher>
38 #include <QDir>
39 #include <QFileInfo>
40 #include <QStandardPaths>
41 #include <XdgDesktopFile>
42 #include <QScroller>
43 
44 class XdgDesktopFile;
45 
46 namespace Fm {
47 class CachedFolderModel;
48 class ProxyFolderModel;
49 class FolderViewListView;
50 }
51 
52 namespace NDEFileMAN {
53 
54 class Settings;
55 
56 
57 class DesktopWindow : public View {
58  Q_OBJECT
59 public:
60  friend class Application;
61 
62  enum WallpaperMode {
63  WallpaperNone,
64  WallpaperStretch,
65  WallpaperFit,
66  WallpaperCenter,
67  WallpaperTile,
68  WallpaperZoom
69  };
70 
71  explicit DesktopWindow(int screenNum);
72  virtual ~DesktopWindow();
73 
74  void setForeground(const QColor& color);
75  void setShadow(const QColor& color);
76  void setBackground(const QColor& color);
77  void setDesktopFolder();
78  void setWallpaperFile(QString filename);
79  void setWallpaperMode(WallpaperMode mode = WallpaperStretch);
80  void setLastSlide(QString filename);
81  void setWallpaperDir(QString dirname);
82  void setSlideShowInterval(int interval);
83  void setWallpaperRandomize(bool randomize);
84 
85  // void setWallpaperAlpha(qreal alpha);
86  void updateWallpaper();
87  bool pickWallpaper();
88  void nextWallpaper();
89  void updateFromSettings(Settings& settings, bool changeSlide = true);
90 
91  void queueRelayout(int delay = 100);
92 
93  int screenNum() const {
94  return screenNum_;
95  }
96 
97  void setScreenNum(int num);
98 
99  QScreen* getDesktopScreen() const;
100 
101  bool isPanelPositionChange() {
102  return isPanelPositionChange_;
103  }
104  void setPanelPositionChange(bool change) {
105  isPanelPositionChange_ = change;
106  }
107 
108 protected:
109  virtual void prepareFolderMenu(Fm::FolderMenu* menu) override;
110  virtual void prepareFileMenu(Fm::FileMenu* menu) override;
111  virtual void resizeEvent(QResizeEvent* event) override;
112  virtual void onFileClicked(int type, const std::shared_ptr<const Fm::FileInfo>& fileInfo) override;
113 
114  void loadItemPositions();
115  void saveItemPositions();
116 
117 
118  QImage loadWallpaperFile(QSize requiredSize);
119 
120  virtual bool event(QEvent* event) override;
121  virtual bool eventFilter(QObject* watched, QEvent* event) override;
122 
123  virtual void childDragMoveEvent(QDragMoveEvent* e) override;
124  virtual void childDropEvent(QDropEvent* e) override;
125  virtual void closeEvent(QCloseEvent* event) override;
126  virtual void paintEvent(QPaintEvent* event) override;
127 
128 protected Q_SLOTS:
129  void onOpenDirRequested(const Fm::FilePath& path, int target);
130  void onDesktopPreferences();
131  void selectAll();
132 
133  void onRowsAboutToBeRemoved(const QModelIndex& parent, int start, int end);
134  void onRowsInserted(const QModelIndex& parent, int start, int end);
135  void onLayoutChanged();
136  void onModelSortFilterChanged();
137  void onDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight);
138  void onFolderStartLoading();
139  void onFolderFinishLoading();
140  void onFilesAdded(const Fm::FileInfoList files);
141 
142  void relayoutItems();
143  void onStickToCurrentPos(bool toggled);
144 
145  // void updateWorkArea();
146 
147  // file operations
148  void onCutActivated();
149  void onCopyActivated();
150  void onCopyFullPathActivated();
151  void onPasteActivated();
152  void onRenameActivated();
153  void onBulkRenameActivated();
154  void onDeleteActivated();
155  void onFilePropertiesActivated();
156  void onDesktopReloadActivated(); // 刷新
157 
158  void updateTrashIcon();
159 
160  void onOpenSystemInfo(); // 打开系统信息
161  void onCancelAllStickPos(); // 取消桌面图标所以固定座标
162  void onDisplaySettings(); // 显示设置
163  void onPersonalise(); // 个性化
164  void onDesktopSortActionTriggered(bool checked); //桌面排序
165  void desktopResize();
166  void toggleAutoSort(); // 自动排序
167  void appDirectoryChanged(const QString &path);
168  bool removeDesktopIcon(const QSet<QString> deletedFiles,const QString &path);
169 
170 private:
171  void removeBottomGap();
172  void addDesktopActions(QMenu* menu);
173  void paintBackground(QPaintEvent* event);
174  void paintDropIndicator();
175  // 桌面外拖入坐标计算
176  bool stickToPosition(const std::string& file, QPoint& pos, const QRect& workArea, const QSize& grid, bool reachedLastCell = false);
177  //多态加载-桌面内计算坐标
178  bool stickToPosition(const QPoint& selPos,const std::string& file, QPoint& pos, const QRect& workArea, const QSize& grid, bool reachedLastCell = false);
179  static void alignToGrid(QPoint& pos, const QPoint& topLeft, const QSize& grid, const int spacing);
180 
181  void updateShortcutsFromSettings(Settings& settings);
182  void createTrashShortcut(int items);
183  void createHomeShortcut();
184  void createComputerShortcut();
185  void createNetworkShortcut();
186 
187  void createTrash();
188  static void onTrashChanged(GFileMonitor* monitor, GFile* gf, GFile* other, GFileMonitorEvent evt, DesktopWindow* pThis);
189  void trustOurDesktopShortcut(std::shared_ptr<const Fm::FileInfo> file);
190  bool isTrashCan(std::shared_ptr<const Fm::FileInfo> file);
191 
192  void createDesktopViewMenu(QMenu* menu);
193  void createDesktopSortMenu(QMenu* menu);
194  void addDesktopSortMenuItem(QMenu* menu, const QString &title, int id);
195  void desktopAutoSort();
196  bool stickToAutoSortPosition(const std::string& file, QPoint& pos, const QPoint& selPos, const QRect& workArea, const QSize& grid, bool reachedLastCell = false);
197  void panelPositionChanged();
198  void removeItemsOnAutoSort();
199  void initsetting(void);
200 
201 private:
202  Fm::ProxyFolderModel* proxyModel_;
203  Fm::CachedFolderModel* model_;
204  std::shared_ptr<Fm::Folder> folder_;
205  Fm::FolderViewListView* listView_;
206  QDesktopWidget *desktopwidget;
207 
208  QColor fgColor_;
209  QColor bgColor_;
210  QColor shadowColor_;
211  QString wallpaperFile_;
212  WallpaperMode wallpaperMode_;
213  QString lastSlide_;
214  QString wallpaperDir_;
215  int slideShowInterval_;
216  QTimer* wallpaperTimer_;
217  bool wallpaperRandomize_;
218  QPixmap wallpaperPixmap_;
219  Launcher fileLauncher_;
220  bool showWmMenu_;
221  //bool desktopHideItems_;
222  bool desktopAutoSort_;
223  bool isReoveItem_;
224  bool isInserted_;
225  bool isResizeDesktop_;
226  bool isPanelPositionChange_;
227  bool isAutoSortAndResize_;
228  bool isDesktopOrderRefresh_;
229  bool moveItem_;
230  bool isReload_;
231  bool isDesktopSort_;
232 
233  int screenNum_;
234  std::unordered_map<std::string, QPoint> customItemPos_;
235  QHash<QModelIndex, QString> displayNames_; // only for desktop entries and shortcuts
236  QTimer* relayoutTimer_;
237  QTimer* selectionTimer_;
238 
239  QRect dropRect_;
240 
241  QTimer* trashUpdateTimer_;
242  GFileMonitor* trashMonitor_;
243 
244  QMenu* desktopViewMenu_;
245  QMenu* desktopSortMenu_;
246  QActionGroup* desktopSortActionGroup_;
247  QPoint desktopWorkArea_; // 桌面图标左上角初始坐标
248  QPoint desktopLastIconPosition_; // 最后一个桌面图标坐标
249 
250 
251  QFileSystemWatcher* desktopFileDirectoryWatcher; //桌面desktop监控
252  QMap<QString,QStringList> currentContsMap; //当前监控内容的目录列表
253  QScroller* scroller; //支持窗口滑动
254 
255 };
256 
257 }
258 
259 #endif // NDEFILEMAN_DESKTOPWINDOW_H
Definition: desktopwindow.h:46
Definition: view.h:37
Definition: desktopwindow.h:57
Definition: launcher.h:30
Definition: settings.h:170
Definition: application.h:60
Definition: application.cpp:67