PCManFM-Qt
settings.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_SETTINGS_H
22 #define PCMANFM_SETTINGS_H
23 
24 #include <QObject>
25 #include <libfm/fm.h>
26 #include "folderview.h"
27 #include "foldermodel.h"
28 #include "desktopwindow.h"
29 #include "sidepane.h"
30 #include "thumbnailloader.h"
31 
32 namespace PCManFM {
33 
34 enum OpenDirTargetType {
35  OpenInCurrentTab,
36  OpenInNewTab,
37  OpenInNewWindow,
38  OpenInLastActiveWindow
39 };
40 
41 class Settings : public QObject {
42  Q_OBJECT
43 public:
44  Settings();
45  virtual ~Settings();
46 
47  bool load(QString profile = "default");
48  bool save(QString profile = QString());
49 
50  bool loadFile(QString filePath);
51  bool saveFile(QString filePath);
52 
53  QString profileDir(QString profile, bool useFallback = false);
54 
55  // setter/getter functions
56  QString profileName() const {
57  return profileName_;
58  }
59 
60  bool supportTrash() const {
61  return supportTrash_;
62  }
63 
64  QString fallbackIconThemeName() const {
65  return fallbackIconThemeName_;
66  }
67 
68  bool useFallbackIconTheme() const {
69  return useFallbackIconTheme_;
70  }
71 
72  void setFallbackIconThemeName(QString iconThemeName) {
73  fallbackIconThemeName_ = iconThemeName;
74  }
75 
76  OpenDirTargetType bookmarkOpenMethod() {
77  return bookmarkOpenMethod_;
78  }
79 
80  void setBookmarkOpenMethod(OpenDirTargetType bookmarkOpenMethod) {
81  bookmarkOpenMethod_ = bookmarkOpenMethod;
82  }
83 
84  QString suCommand() const {
85  return suCommand_;
86  }
87 
88  void setSuCommand(QString suCommand) {
89  suCommand_ = suCommand;
90  }
91 
92  QString terminal() {
93  return terminal_;
94  }
95  void setTerminal(QString terminalCommand);
96 
97  QString archiver() const {
98  return archiver_;
99  }
100 
101  void setArchiver(QString archiver) {
102  archiver_ = archiver;
103  // override libfm FmConfig
104  g_free(fm_config->archiver);
105  fm_config->archiver = g_strdup(archiver_.toLocal8Bit().constData());
106  }
107 
108  bool mountOnStartup() const {
109  return mountOnStartup_;
110  }
111 
112  void setMountOnStartup(bool mountOnStartup) {
113  mountOnStartup_ = mountOnStartup;
114  }
115 
116  bool mountRemovable() {
117  return mountRemovable_;
118  }
119 
120  void setMountRemovable(bool mountRemovable) {
121  mountRemovable_ = mountRemovable;
122  }
123 
124  bool autoRun() const {
125  return autoRun_;
126  }
127 
128  void setAutoRun(bool autoRun) {
129  autoRun_ = autoRun;
130  }
131 
132  bool closeOnUnmount() const {
133  return closeOnUnmount_;
134  }
135 
136  void setCloseOnUnmount(bool value) {
137  closeOnUnmount_ = value;
138  }
139 
140  DesktopWindow::WallpaperMode wallpaperMode() const {
141  return DesktopWindow::WallpaperMode(wallpaperMode_);
142  }
143 
144  void setWallpaperMode(int wallpaperMode) {
145  wallpaperMode_ = wallpaperMode;
146  }
147 
148  QString wallpaper() const {
149  return wallpaper_;
150  }
151 
152  void setWallpaper(QString wallpaper) {
153  wallpaper_ = wallpaper;
154  }
155 
156  const QColor& desktopBgColor() const {
157  return desktopBgColor_;
158  }
159 
160  void setDesktopBgColor(QColor desktopBgColor) {
161  desktopBgColor_ = desktopBgColor;
162  }
163 
164  const QColor& desktopFgColor() const {
165  return desktopFgColor_;
166  }
167 
168  void setDesktopFgColor(QColor desktopFgColor) {
169  desktopFgColor_ = desktopFgColor;
170  }
171 
172  const QColor& desktopShadowColor() const {
173  return desktopShadowColor_;
174  }
175 
176  void setDesktopShadowColor(QColor desktopShadowColor) {
177  desktopShadowColor_ = desktopShadowColor;
178  }
179 
180  QFont desktopFont() const {
181  return desktopFont_;
182  }
183 
184  void setDesktopFont(QFont font) {
185  desktopFont_ = font;
186  }
187 
188  bool showWmMenu() const {
189  return showWmMenu_;
190  }
191 
192  void setShowWmMenu(bool value) {
193  showWmMenu_ = value;
194  }
195 
196  bool desktopShowHidden() const {
197  return desktopShowHidden_;
198  }
199 
200  void setDesktopShowHidden(bool desktopShowHidden) {
201  desktopShowHidden_ = desktopShowHidden;
202  }
203 
204  Qt::SortOrder desktopSortOrder() const {
205  return desktopSortOrder_;
206  }
207 
208  void setDesktopSortOrder(Qt::SortOrder desktopSortOrder) {
209  desktopSortOrder_ = desktopSortOrder;
210  }
211 
212  Fm::FolderModel::ColumnId desktopSortColumn() const {
213  return desktopSortColumn_;
214  }
215 
216  void setDesktopSortColumn(Fm::FolderModel::ColumnId desktopSortColumn) {
217  desktopSortColumn_ = desktopSortColumn;
218  }
219 
220  bool alwaysShowTabs() const {
221  return alwaysShowTabs_;
222  }
223 
224  void setAlwaysShowTabs(bool alwaysShowTabs) {
225  alwaysShowTabs_ = alwaysShowTabs;
226  }
227 
228  bool showTabClose() const {
229  return showTabClose_;
230  }
231 
232  void setShowTabClose(bool showTabClose) {
233  showTabClose_ = showTabClose;
234  }
235 
236  bool rememberWindowSize() const {
237  return rememberWindowSize_;
238  }
239 
240  void setRememberWindowSize(bool rememberWindowSize) {
241  rememberWindowSize_ = rememberWindowSize;
242  }
243 
244  int windowWidth() const {
245  if(rememberWindowSize_)
246  return lastWindowWidth_;
247  else
248  return fixedWindowWidth_;
249  }
250 
251  int windowHeight() const {
252  if(rememberWindowSize_)
253  return lastWindowHeight_;
254  else
255  return fixedWindowHeight_;
256  }
257 
258  bool windowMaximized() const {
259  if(rememberWindowSize_)
260  return lastWindowMaximized_;
261  else
262  return false;
263  }
264 
265  int fixedWindowWidth() const {
266  return fixedWindowWidth_;
267  }
268 
269  void setFixedWindowWidth(int fixedWindowWidth) {
270  fixedWindowWidth_ = fixedWindowWidth;
271  }
272 
273  int fixedWindowHeight() const {
274  return fixedWindowHeight_;
275  }
276 
277  void setFixedWindowHeight(int fixedWindowHeight) {
278  fixedWindowHeight_ = fixedWindowHeight;
279  }
280 
281  void setLastWindowWidth(int lastWindowWidth) {
282  lastWindowWidth_ = lastWindowWidth;
283  }
284 
285  void setLastWindowHeight(int lastWindowHeight) {
286  lastWindowHeight_ = lastWindowHeight;
287  }
288 
289  void setLastWindowMaximized(bool lastWindowMaximized) {
290  lastWindowMaximized_ = lastWindowMaximized;
291  }
292 
293  int splitterPos() const {
294  return splitterPos_;
295  }
296 
297  void setSplitterPos(int splitterPos) {
298  splitterPos_ = splitterPos;
299  }
300 
301  Fm::SidePane::Mode sidePaneMode() const {
302  return sidePaneMode_;
303  }
304 
305  void setSidePaneMode(Fm::SidePane::Mode sidePaneMode) {
306  sidePaneMode_ = sidePaneMode;
307  }
308 
309  Fm::FolderView::ViewMode viewMode() const {
310  return viewMode_;
311  }
312 
313  void setViewMode(Fm::FolderView::ViewMode viewMode) {
314  viewMode_ = viewMode;
315  }
316 
317  bool showHidden() const {
318  return showHidden_;
319  }
320 
321  void setShowHidden(bool showHidden) {
322  showHidden_ = showHidden;
323  }
324 
325  Qt::SortOrder sortOrder() const {
326  return sortOrder_;
327  }
328 
329  void setSortOrder(Qt::SortOrder sortOrder) {
330  sortOrder_ = sortOrder;
331  }
332 
333  Fm::FolderModel::ColumnId sortColumn() const {
334  return sortColumn_;
335  }
336 
337  void setSortColumn(Fm::FolderModel::ColumnId sortColumn) {
338  sortColumn_ = sortColumn;
339  }
340 
341  bool sortFolderFirst() const {
342  return sortFolderFirst_;
343  }
344 
345  void setSortFolderFirst(bool folderFirst) {
346  sortFolderFirst_ = folderFirst;
347  }
348 
349  bool showFilter() const {
350  return showFilter_;
351  }
352 
353  void setShowFilter(bool value) {
354  showFilter_ = value;
355  }
356 
357  // settings for use with libfm
358  bool singleClick() const {
359  return singleClick_;
360  }
361 
362  void setSingleClick(bool singleClick) {
363  singleClick_ = singleClick;
364  }
365 
366  int autoSelectionDelay() const {
367  return autoSelectionDelay_;
368  }
369 
370  void setAutoSelectionDelay(int value) {
371  autoSelectionDelay_ = value;
372  }
373 
374  bool useTrash() const {
375  if(!supportTrash_)
376  return false;
377  return useTrash_;
378  }
379 
380  void setUseTrash(bool useTrash) {
381  useTrash_ = useTrash;
382  }
383 
384  bool confirmDelete() const {
385  return confirmDelete_;
386  }
387 
388  void setConfirmDelete(bool confirmDelete) {
389  confirmDelete_ = confirmDelete;
390  }
391 
392  bool noUsbTrash() const {
393  return noUsbTrash_;
394  }
395 
396  void setNoUsbTrash(bool noUsbTrash) {
397  noUsbTrash_ = noUsbTrash;
398  fm_config->no_usb_trash = noUsbTrash_; // also set this to libfm since FmFileOpsJob reads this config value before trashing files.
399  }
400 
401  bool confirmTrash() const {
402  return confirmTrash_;
403  }
404 
405  void setConfirmTrash(bool value) {
406  confirmTrash_ = value;
407  }
408 
409  bool quickExec() const {
410  return quickExec_;
411  }
412 
413  void setQuickExec(bool value) {
414  quickExec_ = value;
415  fm_config->quick_exec = quickExec_;
416  }
417 
418  // bool thumbnailLocal_;
419  // bool thumbnailMax;
420 
421  int bigIconSize() const {
422  return bigIconSize_;
423  }
424 
425  void setBigIconSize(int bigIconSize) {
426  bigIconSize_ = bigIconSize;
427  }
428 
429  int smallIconSize() const {
430  return smallIconSize_;
431  }
432 
433  void setSmallIconSize(int smallIconSize) {
434  smallIconSize_ = smallIconSize;
435  }
436 
437  int sidePaneIconSize() const {
438  return sidePaneIconSize_;
439  }
440 
441  void setSidePaneIconSize(int sidePaneIconSize) {
442  sidePaneIconSize_ = sidePaneIconSize;
443  }
444 
445  int thumbnailIconSize() const {
446  return thumbnailIconSize_;
447  }
448 
449  bool showThumbnails() {
450  return showThumbnails_;
451  }
452 
453  void setShowThumbnails(bool show) {
454  showThumbnails_ = show;
455  }
456 
457  void setThumbnailLocalFilesOnly(bool value) {
458  Fm::ThumbnailLoader::setLocalFilesOnly(value);
459  }
460 
461  bool thumbnailLocalFilesOnly() {
462  return Fm::ThumbnailLoader::localFilesOnly();
463  }
464 
465  int maxThumbnailFileSize() {
466  return Fm::ThumbnailLoader::maxThumbnailFileSize();
467  }
468 
469  void setMaxThumbnailFileSize(int size) {
470  Fm::ThumbnailLoader::setMaxThumbnailFileSize(size);
471  }
472 
473  void setThumbnailIconSize(int thumbnailIconSize) {
474  thumbnailIconSize_ = thumbnailIconSize;
475  }
476 
477  bool siUnit() {
478  return siUnit_;
479  }
480 
481  void setSiUnit(bool siUnit) {
482  siUnit_ = siUnit;
483  // override libfm FmConfig settings. FIXME: should we do this?
484  fm_config->si_unit = (gboolean)siUnit_;
485  }
486 
487  bool backupAsHidden() const {
488  return backupAsHidden_;
489  }
490 
491  void setBackupAsHidden(bool value) {
492  backupAsHidden_ = value;
493  fm_config->backup_as_hidden = backupAsHidden_; // also set this to libfm since fm_file_info_is_hidden() reads this value internally.
494  }
495 
496  bool showFullNames() const {
497  return showFullNames_;
498  }
499 
500  void setShowFullNames(bool value) {
501  showFullNames_ = value;
502  }
503 
504  bool shadowHidden() const {
505  return shadowHidden_;
506  }
507 
508  void setShadowHidden(bool value) {
509  shadowHidden_ = value;
510  }
511 
512  bool onlyUserTemplates() const {
513  return onlyUserTemplates_;
514  }
515 
516  void setOnlyUserTemplates(bool value) {
517  onlyUserTemplates_ = value;
518  fm_config->only_user_templates = onlyUserTemplates_;
519  }
520 
521  bool templateTypeOnce() const {
522  return templateTypeOnce_;
523  }
524 
525  void setTemplateTypeOnce(bool value) {
526  templateTypeOnce_ = value;
527  fm_config->template_type_once = templateTypeOnce_;
528  }
529 
530  bool templateRunApp() const {
531  return templateRunApp_;
532  }
533 
534  void setTemplateRunApp(bool value) {
535  templateRunApp_ = value;
536  fm_config->template_run_app = templateRunApp_;
537  }
538 
539 private:
540  QString profileName_;
541  bool supportTrash_;
542 
543  // PCManFM specific
544  QString fallbackIconThemeName_;
545  bool useFallbackIconTheme_;
546 
547  OpenDirTargetType bookmarkOpenMethod_;
548  QString suCommand_;
549  QString terminal_;
550  bool mountOnStartup_;
551  bool mountRemovable_;
552  bool autoRun_;
553  bool closeOnUnmount_;
554 
555  int wallpaperMode_;
556  QString wallpaper_;
557  QColor desktopBgColor_;
558  QColor desktopFgColor_;
559  QColor desktopShadowColor_;
560  QFont desktopFont_;
561  bool showWmMenu_;
562 
563  bool desktopShowHidden_;
564  Qt::SortOrder desktopSortOrder_;
565  Fm::FolderModel::ColumnId desktopSortColumn_;
566 
567  bool alwaysShowTabs_;
568  bool showTabClose_;
569  bool rememberWindowSize_;
570  int fixedWindowWidth_;
571  int fixedWindowHeight_;
572  int lastWindowWidth_;
573  int lastWindowHeight_;
574  bool lastWindowMaximized_;
575  int splitterPos_;
576  Fm::SidePane::Mode sidePaneMode_;
577 
578  Fm::FolderView::ViewMode viewMode_;
579  bool showHidden_;
580  Qt::SortOrder sortOrder_;
581  Fm::FolderModel::ColumnId sortColumn_;
582  bool sortFolderFirst_;
583  bool showFilter_;
584 
585  // settings for use with libfm
586  bool singleClick_;
587  int autoSelectionDelay_;
588  bool useTrash_;
589  bool confirmDelete_;
590  bool noUsbTrash_; // do not trash files on usb removable devices
591  bool confirmTrash_; // Confirm before moving files into "trash can"
592  bool quickExec_; // Don't ask options on launch executable file
593 
594  bool showThumbnails_;
595 
596  QString archiver_;
597  bool siUnit_;
598  bool backupAsHidden_;
599  bool showFullNames_;
600  bool shadowHidden_;
601 
602  int bigIconSize_;
603  int smallIconSize_;
604  int sidePaneIconSize_;
605  int thumbnailIconSize_;
606 
607  bool onlyUserTemplates_;
608  bool templateTypeOnce_;
609  bool templateRunApp_;
610 };
611 
612 }
613 
614 #endif // PCMANFM_SETTINGS_H
Definition: settings.h:41
Definition: application.h:39