NDE-FileMAN
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 NDEFILEMAN_APPLICATION_H
22 #define NDEFILEMAN_APPLICATION_H
23 
24 #include <QApplication>
25 #include "settings.h"
26 #include <libfm-qt/libfmqt.h>
27 #include <libfm-qt/editbookmarksdialog.h>
28 #include <QVector>
29 #include <QPointer>
30 #include <QProxyStyle>
31 #include <QTranslator>
32 #include <gio/gio.h>
33 #include <QDir>
34 
35 #include <libfm-qt/core/filepath.h>
36 #include <libfm-qt/core/fileinfo.h>
37 #include <KScreen/Types>
38 #include <KScreen/ConfigOperation>
39 #include <KScreen/GetConfigOperation>
40 
41 class QScreen;
42 
43 class QFileSystemWatcher;
44 
45 namespace NDEFileMAN {
46 
47 class MainWindow;
48 class DesktopWindow;
49 class PreferencesDialog;
50 class DesktopPreferencesDialog;
51 
52 class ProxyStyle: public QProxyStyle {
53  Q_OBJECT
54 public:
55  ProxyStyle() : QProxyStyle() {}
56  virtual ~ProxyStyle() {}
57  virtual int styleHint(StyleHint hint, const QStyleOption* option = 0, const QWidget* widget = 0, QStyleHintReturn* returnData = 0) const;
58 };
59 
60 class Application : public QApplication {
61  Q_OBJECT
62  Q_PROPERTY(bool desktopManagerEnabled READ desktopManagerEnabled)
63 
64 public:
65  Application(int& argc, char** argv);
66  virtual ~Application();
67 
68  void init();
69  int exec();
70 
71  Settings& settings() {
72  return settings_;
73  }
74 
75  Fm::LibFmQt& libFm() {
76  return libFm_;
77  }
78 
79  // public interface exported via dbus
80  void launchFiles(QString cwd, QStringList paths, bool inNewWindow);
81  void setWallpaper(QString path, QString modeString);
82  void preferences(QString page);
83  void desktopPrefrences(QString page);
84  void editBookmarks();
85  void desktopManager(bool enabled);
86  void findFiles(QStringList paths = QStringList());
87  void connectToServer();
88  void setWallpaperPathInfo(QString path);
89  void setWallpaperautochangeTime(QString interval);
90  void initWallpaperAutoChange();
91  void setAutoChangeWallpaper(QString path, QString modeString);
92 
93  bool desktopManagerEnabled() {
94  return enableDesktopManager_;
95  }
96 
97  void updateFromSettings();
98  void updateDesktopsFromSettings(bool changeSlide = true);
99 
100  void openFolderInTerminal(Fm::FilePath path);
101  void openFolders(Fm::FileInfoList files);
102 
103  QString profileName() {
104  return profileName_;
105  }
106 
107 protected Q_SLOTS:
108  void onAboutToQuit();
109  void onSigtermNotified();
110 
111  void onLastWindowClosed();
112  void onSaveStateRequest(QSessionManager& manager);
113  void initVolumeManager();
114 
115  void onVirtualGeometryChanged(const QRect& rect);
116  void onAvailableGeometryChanged(const QRect& rect);
117  void onScreenDestroyed(QObject* screenObj);
118  void onScreenAdded(QScreen* newScreen);
119  void onScreenRemoved(QScreen* oldScreen);
120  void reloadDesktopsAsNeeded();
121 
122  void onFindFileAccepted();
123  void onConnectToServerAccepted();
124 
125 protected:
126  //virtual bool eventFilter(QObject* watched, QEvent* event);
127  bool parseCommandLineArgs();
128  DesktopWindow* createDesktopWindow(int screenNum);
129  bool autoMountVolume(GVolume* volume, bool interactive = true);
130 
131  static void onVolumeAdded(GVolumeMonitor* monitor, GVolume* volume, Application* pThis);
132 
133 private Q_SLOTS:
134  void onUserDirsChanged();
135  void handleTimeoutwallpaper();
136 
137 private:
138  void initWatch();
139  void installSigtermHandler();
140  void screenMonitor();
141  void loadConfiguration(KScreen::ConfigPtr config);
142 
143  bool isPrimaryInstance;
144  Fm::LibFmQt libFm_;
145  Settings settings_;
146  QString profileName_;
147  bool daemonMode_;
148  bool enableDesktopManager_;
149  QVector<DesktopWindow*> desktopWindows_;
150  QPointer<PreferencesDialog> preferencesDialog_;
151  QPointer<DesktopPreferencesDialog> desktopPreferencesDialog_;
152  QPointer<Fm::EditBookmarksDialog> editBookmarksialog_;
153  QTranslator translator;
154  QTranslator qtTranslator;
155  GVolumeMonitor* volumeMonitor_;
156 
157  QFileSystemWatcher* userDirsWatcher_;
158  QString userDirsFile_;
159  QString userDesktopFolder_;
160  bool ndeRunning_;
161  QTimer *wallPaperSwitch_time_;
162  QList<QFileInfo> *fileInfo;
163  int currentWallpaper_;
164 
165  int argc_;
166  char** argv_;
167 };
168 
169 }
170 
171 #endif // NDEFILEMAN_APPLICATION_H
Definition: application.h:52
Definition: desktopwindow.h:57
Definition: settings.h:170
Definition: application.h:60
Definition: application.cpp:67