PCManFM-Qt
application.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_APPLICATION_H
22 #define PCMANFM_APPLICATION_H
23 
24 #include <QApplication>
25 #include "settings.h"
26 #include "libfmqt.h"
27 #include "editbookmarksdialog.h"
28 #include <QAbstractNativeEventFilter>
29 #include <QVector>
30 #include <QPointer>
31 #include <QProxyStyle>
32 #include <QTranslator>
33 #include <gio/gio.h>
34 
35 
36 class QScreen;
37 
38 namespace PCManFM {
39 
40 class DesktopWindow;
41 class PreferencesDialog;
42 class DesktopPreferencesDialog;
43 
44 class ProxyStyle: public QProxyStyle {
45  Q_OBJECT
46 public:
47  ProxyStyle() : QProxyStyle() {}
48  virtual ~ProxyStyle() {}
49  virtual int styleHint(StyleHint hint, const QStyleOption * option = 0, const QWidget * widget = 0, QStyleHintReturn * returnData = 0) const;
50 };
51 
52 class Application : public QApplication, public QAbstractNativeEventFilter {
53  Q_OBJECT
54  Q_PROPERTY(bool desktopManagerEnabled READ desktopManagerEnabled)
55 
56 public:
57  Application(int& argc, char** argv);
58  virtual ~Application();
59 
60  void init();
61  int exec();
62 
63  Settings& settings() {
64  return settings_;
65  }
66 
67  Fm::LibFmQt& libFm() {
68  return libFm_;
69  }
70 
71  // public interface exported via dbus
72  void launchFiles(QStringList paths, bool inNewWindow);
73  void setWallpaper(QString path, QString modeString);
74  void preferences(QString page);
75  void desktopPrefrences(QString page);
76  void editBookmarks();
77  void desktopManager(bool enabled);
78  void findFiles(QStringList paths);
79 
80  bool desktopManagerEnabled() {
81  return enableDesktopManager_;
82  }
83 
84  void updateFromSettings();
85  void updateDesktopsFromSettings();
86 
87  void openFolderInTerminal(FmPath* path);
88  void openFolders(FmFileInfoList* files);
89 
90  QString profileName() {
91  return profileName_;
92  }
93 
94  virtual bool nativeEventFilter(const QByteArray & eventType, void * message, long * result);
95 
96 protected Q_SLOTS:
97  void onAboutToQuit();
98 
99  void onLastWindowClosed();
100  void onSaveStateRequest(QSessionManager & manager);
101  void onScreenResized(int num);
102  void onScreenCountChanged(int newCount);
103  void initVolumeManager();
104 
105  void onVirtualGeometryChanged(const QRect& rect);
106  void onScreenDestroyed(QObject* screenObj);
107  void onScreenAdded(QScreen* newScreen);
108  void reloadDesktopsAsNeeded();
109 
110 protected:
111  virtual bool eventFilter(QObject* watched, QEvent* event);
112  bool parseCommandLineArgs();
113  DesktopWindow* createDesktopWindow(int screenNum);
114  bool autoMountVolume(GVolume* volume, bool interactive = true);
115 
116  static void onVolumeAdded(GVolumeMonitor* monitor, GVolume* volume, Application* pThis);
117 
118 private:
119  bool isPrimaryInstance;
120  Fm::LibFmQt libFm_;
121  Settings settings_;
122  QString profileName_;
123  bool daemonMode_;
124  bool enableDesktopManager_;
125  QVector<DesktopWindow*> desktopWindows_;
126  QPointer<PreferencesDialog> preferencesDialog_;
127  QPointer<DesktopPreferencesDialog> desktopPreferencesDialog_;
128  QPointer<Fm::EditBookmarksDialog> editBookmarksialog_;
129  QTranslator translator;
130  QTranslator qtTranslator;
131  GVolumeMonitor* volumeMonitor_;
132  int argc_;
133  char** argv_;
134 };
135 
136 }
137 
138 #endif // PCMANFM_APPLICATION_H
Definition: application.h:52
Definition: settings.h:33
Definition: libfmqt.h:33
Definition: application.h:38
Definition: application.h:44
Definition: desktopwindow.h:42