PCManFM-Qt
 All Classes
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(QString filename);
68  void setWallpaperMode(WallpaperMode mode = WallpaperStretch);
69  void setLastSlide(QString filename);
70  void setWallpaperDir(QString dirname);
71  void setSlideShowInterval(int interval);
72  void setWallpaperRandomize(bool randomize);
73 
74  // void setWallpaperAlpha(qreal alpha);
75  void updateWallpaper();
76  bool pickWallpaper();
77  void nextWallpaper();
78  void updateFromSettings(Settings& settings, bool changeSlide = true);
79 
80  void queueRelayout(int delay = 0);
81 
82  int screenNum() const {
83  return screenNum_;
84  }
85 
86  void setScreenNum(int num);
87 
88  QScreen* getDesktopScreen() const;
89 
90 protected:
91  virtual void prepareFolderMenu(Fm::FolderMenu* menu) override;
92  virtual void prepareFileMenu(Fm::FileMenu* menu) override;
93  virtual void resizeEvent(QResizeEvent* event) override;
94  virtual void onFileClicked(int type, const std::shared_ptr<const Fm::FileInfo>& fileInfo) override;
95 
96  void loadItemPositions();
97  void saveItemPositions();
98 
99  QImage loadWallpaperFile(QSize requiredSize);
100 
101  virtual bool event(QEvent* event) override;
102  virtual bool eventFilter(QObject* watched, QEvent* event) override;
103 
104  virtual void childDragMoveEvent(QDragMoveEvent* e) override;
105  virtual void childDropEvent(QDropEvent* e) override;
106  virtual void closeEvent(QCloseEvent* event) override;
107  virtual void paintEvent(QPaintEvent* event) override;
108 
109 protected Q_SLOTS:
110  void onOpenDirRequested(const Fm::FilePath& path, int target);
111  void onDesktopPreferences();
112  void selectAll();
113  void toggleDesktop();
114 
115  void onRowsAboutToBeRemoved(const QModelIndex& parent, int start, int end);
116  void onRowsInserted(const QModelIndex& parent, int start, int end);
117  void onLayoutChanged();
118  void onModelSortFilterChanged();
119  void onDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight);
120  void onFolderStartLoading();
121  void onFolderFinishLoading();
122  void onFilesAdded(const Fm::FileInfoList files);
123 
124  void relayoutItems();
125  void onStickToCurrentPos(bool toggled);
126 
127  // void updateWorkArea();
128 
129  // file operations
130  void onCutActivated();
131  void onCopyActivated();
132  void onCopyFullPathActivated();
133  void onPasteActivated();
134  void onRenameActivated();
135  void onBulkRenameActivated();
136  void onDeleteActivated();
137  void onFilePropertiesActivated();
138 
139  void updateTrashIcon();
140 
141 private:
142  void removeBottomGap();
143  void addDesktopActions(QMenu* menu);
144  void paintBackground(QPaintEvent* event);
145  void paintDropIndicator();
146  bool stickToPosition(const std::string& file, QPoint& pos, const QRect& workArea, const QSize& grid, bool reachedLastCell = false);
147  static void alignToGrid(QPoint& pos, const QPoint& topLeft, const QSize& grid, const int spacing);
148 
149  void updateShortcutsFromSettings(Settings& settings);
150  void createTrashShortcut(int items);
151  void createHomeShortcut();
152  void createComputerShortcut();
153  void createNetworkShortcut();
154 
155  void createTrash();
156  static void onTrashChanged(GFileMonitor* monitor, GFile* gf, GFile* other, GFileMonitorEvent evt, DesktopWindow* pThis);
157  void trustOurDesktopShortcut(std::shared_ptr<const Fm::FileInfo> file);
158  bool isTrashCan(std::shared_ptr<const Fm::FileInfo> file);
159 
160 private:
161  Fm::ProxyFolderModel* proxyModel_;
162  Fm::CachedFolderModel* model_;
163  std::shared_ptr<Fm::Folder> folder_;
164  Fm::FolderViewListView* listView_;
165 
166  QColor fgColor_;
167  QColor bgColor_;
168  QColor shadowColor_;
169  QString wallpaperFile_;
170  WallpaperMode wallpaperMode_;
171  QString lastSlide_;
172  QString wallpaperDir_;
173  int slideShowInterval_;
174  QTimer* wallpaperTimer_;
175  bool wallpaperRandomize_;
176  QPixmap wallpaperPixmap_;
177  Launcher fileLauncher_;
178  bool showWmMenu_;
179  bool desktopHideItems_;
180 
181  int screenNum_;
182  std::unordered_map<std::string, QPoint> customItemPos_;
183  QHash<QModelIndex, QString> displayNames_; // only for desktop entries and shortcuts
184  QTimer* relayoutTimer_;
185  QTimer* selectionTimer_;
186 
187  QRect dropRect_;
188 
189  QTimer* trashUpdateTimer_;
190  GFileMonitor* trashMonitor_;
191 };
192 
193 }
194 
195 #endif // PCMANFM_DESKTOPWINDOW_H
Definition: application.h:56
Definition: settings.h:122
Definition: view.h:37
Definition: launcher.h:30
Definition: desktopwindow.h:46