PCManFM-Qt
placesmodel.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 FM_PLACESMODEL_H
22 #define FM_PLACESMODEL_H
23 
24 #include "libfmqtglobals.h"
25 #include <QStandardItemModel>
26 #include <QStandardItem>
27 #include <QList>
28 #include <QAction>
29 #include <libfm/fm.h>
30 
31 namespace Fm {
32 
33 class PlacesModelItem;
34 class PlacesModelVolumeItem;
35 class PlacesModelMountItem;
36 class PlacesModelBookmarkItem;
37 
38 class LIBFM_QT_API PlacesModel : public QStandardItemModel {
39 Q_OBJECT
40 friend class PlacesView;
41 public:
42 
43  // QAction used for popup menus
44  class ItemAction : public QAction {
45  public:
46  ItemAction(const QModelIndex& index, QString text, QObject* parent = 0):
47  QAction(text, parent),
48  index_(index) {
49  }
50 
51  QPersistentModelIndex& index() {
52  return index_;
53  }
54  private:
55  QPersistentModelIndex index_;
56  };
57 
58 public:
59  explicit PlacesModel(QObject* parent = 0);
60  virtual ~PlacesModel();
61 
62  bool showTrash() {
63  return trashItem_ != NULL;
64  }
65  void setShowTrash(bool show);
66 
67  bool showApplications() {
68  return showApplications_;
69  }
70  void setShowApplications(bool show);
71 
72  bool showDesktop() {
73  return showDesktop_;
74  }
75  void setShowDesktop(bool show);
76 
77 public Q_SLOTS:
78  void updateIcons();
79  void updateTrash();
80 
81 protected:
82 
83  PlacesModelItem* itemFromPath(FmPath* path);
84  PlacesModelItem* itemFromPath(QStandardItem* rootItem, FmPath* path);
85  PlacesModelVolumeItem* itemFromVolume(GVolume* volume);
86  PlacesModelMountItem* itemFromMount(GMount* mount);
87  PlacesModelBookmarkItem* itemFromBookmark(FmBookmarkItem* bkitem);
88 
89  virtual Qt::ItemFlags flags(const QModelIndex& index) const;
90  virtual QStringList mimeTypes() const;
91  virtual QMimeData* mimeData(const QModelIndexList& indexes) const;
92  virtual bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent);
93  Qt::DropActions supportedDropActions() const;
94 
95  void createTrashItem();
96 
97 private:
98  void loadBookmarks();
99 
100  static void onVolumeAdded(GVolumeMonitor* monitor, GVolume* volume, PlacesModel* pThis);
101  static void onVolumeRemoved(GVolumeMonitor* monitor, GVolume* volume, PlacesModel* pThis);
102  static void onVolumeChanged(GVolumeMonitor* monitor, GVolume* volume, PlacesModel* pThis);
103  static void onMountAdded(GVolumeMonitor* monitor, GMount* mount, PlacesModel* pThis);
104  static void onMountRemoved(GVolumeMonitor* monitor, GMount* mount, PlacesModel* pThis);
105  static void onMountChanged(GVolumeMonitor* monitor, GMount* mount, PlacesModel* pThis);
106 
107  static void onBookmarksChanged(FmBookmarks* bookmarks, PlacesModel* pThis);
108 
109  static void onTrashChanged(GFileMonitor *monitor, GFile *gf, GFile *other, GFileMonitorEvent evt, PlacesModel* pThis);
110 private:
111  FmBookmarks* bookmarks;
112  GVolumeMonitor* volumeMonitor;
113  QList<FmJob*> jobs;
114  bool showApplications_;
115  bool showDesktop_;
116  QStandardItem* placesRoot;
117  QStandardItem* devicesRoot;
118  QStandardItem* bookmarksRoot;
119  PlacesModelItem* trashItem_;
120  GFileMonitor* trashMonitor_;
121  PlacesModelItem* desktopItem;
122  PlacesModelItem* homeItem;
123  PlacesModelItem* computerItem;
124  PlacesModelItem* networkItem;
125  PlacesModelItem* applicationsItem;
126  QIcon ejectIcon_;
127 };
128 
129 }
130 
131 #endif // FM_PLACESMODEL_H
Definition: placesmodel.h:38
Definition: appchoosercombobox.cpp:26
Definition: placesmodelitem.h:111
Definition: placesmodelitem.h:34
Definition: placesmodel.h:44
Definition: placesview.h:33
Definition: placesmodelitem.h:79
Definition: placesmodelitem.h:97