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 <libfm-qt/folderview.h>
27 #include <libfm-qt/foldermodel.h>
28 #include "desktopwindow.h"
29 #include <libfm-qt/sidepane.h>
30 #include <libfm-qt/thumbnailloader.h>
31 
32 namespace PCManFM {
33 
34 enum OpenDirTargetType {
35  OpenInCurrentTab,
36  OpenInNewTab,
37  OpenInNewWindow,
38  OpenInLastActiveWindow
39 };
40 
42 public:
44  isCustomized_(false),
45  sortOrder_(Qt::AscendingOrder),
46  sortColumn_(Fm::FolderModel::ColumnFileName),
47  viewMode_(Fm::FolderView::IconMode),
48  showHidden_(false),
49  sortFolderFirst_(true),
50  sortCaseSensitive_(true) {
51  }
52 
53  bool isCustomized() const {
54  return isCustomized_;
55  }
56 
57  void setCustomized(bool value) {
58  isCustomized_ = value;
59  }
60 
61  Qt::SortOrder sortOrder() const {
62  return sortOrder_;
63  }
64 
65  void setSortOrder(Qt::SortOrder value) {
66  sortOrder_ = value;
67  }
68 
69  Fm::FolderModel::ColumnId sortColumn() const {
70  return sortColumn_;
71  }
72 
73  void setSortColumn(Fm::FolderModel::ColumnId value) {
74  sortColumn_ = value;
75  }
76 
77  Fm::FolderView::ViewMode viewMode() const {
78  return viewMode_;
79  }
80 
81  void setViewMode(Fm::FolderView::ViewMode value) {
82  viewMode_ = value;
83  }
84 
85  bool sortFolderFirst() const {
86  return sortFolderFirst_;
87  }
88 
89  void setSortFolderFirst(bool value) {
90  sortFolderFirst_ = value;
91  }
92 
93  bool showHidden() const {
94  return showHidden_;
95  }
96 
97  void setShowHidden(bool value) {
98  showHidden_ = value;
99  }
100 
101  bool sortCaseSensitive() const {
102  return sortCaseSensitive_;
103  }
104 
105  void setSortCaseSensitive(bool value) {
106  sortCaseSensitive_ = value;
107  }
108 
109 private:
110  bool isCustomized_;
111  Qt::SortOrder sortOrder_;
112  Fm::FolderModel::ColumnId sortColumn_;
113  Fm::FolderView::ViewMode viewMode_;
114  bool showHidden_;
115  bool sortFolderFirst_;
116  bool sortCaseSensitive_;
117  // columns?
118 };
119 
120 
121 class Settings : public QObject {
122  Q_OBJECT
123 public:
124  Settings();
125  virtual ~Settings();
126 
127  bool load(QString profile = "default");
128  bool save(QString profile = QString());
129 
130  bool loadFile(QString filePath);
131  bool saveFile(QString filePath);
132 
133  static QString xdgUserConfigDir();
134 
135  QString profileDir(QString profile, bool useFallback = false);
136 
137  // setter/getter functions
138  QString profileName() const {
139  return profileName_;
140  }
141 
142  bool supportTrash() const {
143  return supportTrash_;
144  }
145 
146  QString fallbackIconThemeName() const {
147  return fallbackIconThemeName_;
148  }
149 
150  bool useFallbackIconTheme() const {
151  return useFallbackIconTheme_;
152  }
153 
154  void setFallbackIconThemeName(QString iconThemeName) {
155  fallbackIconThemeName_ = iconThemeName;
156  }
157 
158  OpenDirTargetType bookmarkOpenMethod() {
159  return bookmarkOpenMethod_;
160  }
161 
162  void setBookmarkOpenMethod(OpenDirTargetType bookmarkOpenMethod) {
163  bookmarkOpenMethod_ = bookmarkOpenMethod;
164  }
165 
166  QString suCommand() const {
167  return suCommand_;
168  }
169 
170  void setSuCommand(QString suCommand) {
171  suCommand_ = suCommand;
172  }
173 
174  QString terminal() {
175  return terminal_;
176  }
177  void setTerminal(QString terminalCommand);
178 
179  QString archiver() const {
180  return archiver_;
181  }
182 
183  void setArchiver(QString archiver) {
184  archiver_ = archiver;
185  // override libfm FmConfig
186  g_free(fm_config->archiver);
187  fm_config->archiver = g_strdup(archiver_.toLocal8Bit().constData());
188  }
189 
190  bool mountOnStartup() const {
191  return mountOnStartup_;
192  }
193 
194  void setMountOnStartup(bool mountOnStartup) {
195  mountOnStartup_ = mountOnStartup;
196  }
197 
198  bool mountRemovable() {
199  return mountRemovable_;
200  }
201 
202  void setMountRemovable(bool mountRemovable) {
203  mountRemovable_ = mountRemovable;
204  }
205 
206  bool autoRun() const {
207  return autoRun_;
208  }
209 
210  void setAutoRun(bool autoRun) {
211  autoRun_ = autoRun;
212  }
213 
214  bool closeOnUnmount() const {
215  return closeOnUnmount_;
216  }
217 
218  void setCloseOnUnmount(bool value) {
219  closeOnUnmount_ = value;
220  }
221 
222  DesktopWindow::WallpaperMode wallpaperMode() const {
223  return DesktopWindow::WallpaperMode(wallpaperMode_);
224  }
225 
226  void setWallpaperMode(int wallpaperMode) {
227  wallpaperMode_ = wallpaperMode;
228  }
229 
230  QString wallpaper() const {
231  return wallpaper_;
232  }
233 
234  void setWallpaper(QString wallpaper) {
235  wallpaper_ = wallpaper;
236  }
237 
238  const QColor& desktopBgColor() const {
239  return desktopBgColor_;
240  }
241 
242  void setDesktopBgColor(QColor desktopBgColor) {
243  desktopBgColor_ = desktopBgColor;
244  }
245 
246  const QColor& desktopFgColor() const {
247  return desktopFgColor_;
248  }
249 
250  void setDesktopFgColor(QColor desktopFgColor) {
251  desktopFgColor_ = desktopFgColor;
252  }
253 
254  const QColor& desktopShadowColor() const {
255  return desktopShadowColor_;
256  }
257 
258  void setDesktopShadowColor(QColor desktopShadowColor) {
259  desktopShadowColor_ = desktopShadowColor;
260  }
261 
262  QFont desktopFont() const {
263  return desktopFont_;
264  }
265 
266  void setDesktopFont(QFont font) {
267  desktopFont_ = font;
268  }
269 
270  int desktopIconSize() const {
271  return desktopIconSize_;
272  }
273 
274  void setDesktopIconSize(int desktopIconSize) {
275  desktopIconSize_ = desktopIconSize;
276  }
277 
278  bool showWmMenu() const {
279  return showWmMenu_;
280  }
281 
282  void setShowWmMenu(bool value) {
283  showWmMenu_ = value;
284  }
285 
286  bool desktopShowHidden() const {
287  return desktopShowHidden_;
288  }
289 
290  void setDesktopShowHidden(bool desktopShowHidden) {
291  desktopShowHidden_ = desktopShowHidden;
292  }
293 
294  Qt::SortOrder desktopSortOrder() const {
295  return desktopSortOrder_;
296  }
297 
298  void setDesktopSortOrder(Qt::SortOrder desktopSortOrder) {
299  desktopSortOrder_ = desktopSortOrder;
300  }
301 
302  Fm::FolderModel::ColumnId desktopSortColumn() const {
303  return desktopSortColumn_;
304  }
305 
306  void setDesktopSortColumn(Fm::FolderModel::ColumnId desktopSortColumn) {
307  desktopSortColumn_ = desktopSortColumn;
308  }
309 
310  bool desktopSortFolderFirst() const {
311  return desktopSortFolderFirst_;
312  }
313 
314  void setSesktopSortFolderFirst(bool desktopFolderFirst) {
315  desktopSortFolderFirst_ = desktopFolderFirst;
316  }
317 
318  bool alwaysShowTabs() const {
319  return alwaysShowTabs_;
320  }
321 
322  void setAlwaysShowTabs(bool alwaysShowTabs) {
323  alwaysShowTabs_ = alwaysShowTabs;
324  }
325 
326  bool showTabClose() const {
327  return showTabClose_;
328  }
329 
330  void setShowTabClose(bool showTabClose) {
331  showTabClose_ = showTabClose;
332  }
333 
334  bool rememberWindowSize() const {
335  return rememberWindowSize_;
336  }
337 
338  void setRememberWindowSize(bool rememberWindowSize) {
339  rememberWindowSize_ = rememberWindowSize;
340  }
341 
342  int windowWidth() const {
343  if(rememberWindowSize_)
344  return lastWindowWidth_;
345  else
346  return fixedWindowWidth_;
347  }
348 
349  int windowHeight() const {
350  if(rememberWindowSize_)
351  return lastWindowHeight_;
352  else
353  return fixedWindowHeight_;
354  }
355 
356  bool windowMaximized() const {
357  if(rememberWindowSize_)
358  return lastWindowMaximized_;
359  else
360  return false;
361  }
362 
363  int fixedWindowWidth() const {
364  return fixedWindowWidth_;
365  }
366 
367  void setFixedWindowWidth(int fixedWindowWidth) {
368  fixedWindowWidth_ = fixedWindowWidth;
369  }
370 
371  int fixedWindowHeight() const {
372  return fixedWindowHeight_;
373  }
374 
375  void setFixedWindowHeight(int fixedWindowHeight) {
376  fixedWindowHeight_ = fixedWindowHeight;
377  }
378 
379  void setLastWindowWidth(int lastWindowWidth) {
380  lastWindowWidth_ = lastWindowWidth;
381  }
382 
383  void setLastWindowHeight(int lastWindowHeight) {
384  lastWindowHeight_ = lastWindowHeight;
385  }
386 
387  void setLastWindowMaximized(bool lastWindowMaximized) {
388  lastWindowMaximized_ = lastWindowMaximized;
389  }
390 
391  int splitterPos() const {
392  return splitterPos_;
393  }
394 
395  void setSplitterPos(int splitterPos) {
396  splitterPos_ = splitterPos;
397  }
398 
399  Fm::SidePane::Mode sidePaneMode() const {
400  return sidePaneMode_;
401  }
402 
403  void setSidePaneMode(Fm::SidePane::Mode sidePaneMode) {
404  sidePaneMode_ = sidePaneMode;
405  }
406 
407  bool showMenuBar() const {
408  return showMenuBar_;
409  }
410 
411  void setShowMenuBar(bool showMenuBar) {
412  showMenuBar_ = showMenuBar;
413  }
414 
415  bool fullWidthTabBar() const {
416  return fullWidthTabBar_;
417  }
418 
419  void setFullWidthTabBar(bool fullWith) {
420  fullWidthTabBar_ = fullWith;
421  }
422 
423  Fm::FolderView::ViewMode viewMode() const {
424  return viewMode_;
425  }
426 
427  void setViewMode(Fm::FolderView::ViewMode viewMode) {
428  viewMode_ = viewMode;
429  }
430 
431  bool showHidden() const {
432  return showHidden_;
433  }
434 
435  void setShowHidden(bool showHidden) {
436  showHidden_ = showHidden;
437  }
438 
439  bool sortCaseSensitive() const {
440  return sortCaseSensitive_;
441  }
442 
443  void setSortCaseSensitive(bool value) {
444  sortCaseSensitive_ = value;
445  }
446 
447 
448  bool placesHome() const {
449  return placesHome_;
450  }
451 
452  void setPlacesHome(bool placesHome) {
453  placesHome_ = placesHome;
454  }
455 
456  bool placesDesktop() const {
457  return placesDesktop_;
458  }
459 
460  void setPlacesDesktop(bool placesDesktop) {
461  placesDesktop_ = placesDesktop;
462  }
463 
464  bool placesApplications() const {
465  return placesApplications_;
466  }
467 
468  void setPlacesApplications(bool placesApplications) {
469  placesApplications_ = placesApplications;
470  }
471 
472  bool placesTrash() const {
473  return placesTrash_;
474  }
475 
476  void setPlacesTrash(bool placesTrash) {
477  placesTrash_ = placesTrash;
478  }
479 
480  bool placesRoot() const {
481  return placesRoot_;
482  }
483 
484  void setPlacesRoot(bool placesRoot) {
485  placesRoot_ = placesRoot;
486  }
487 
488  bool placesComputer() const {
489  return placesComputer_;
490  }
491 
492  void setPlacesComputer(bool placesComputer) {
493  placesComputer_ = placesComputer;
494  }
495 
496  bool placesNetwork() const {
497  return placesNetwork_;
498  }
499 
500  void setPlacesNetwork(bool placesNetwork) {
501  placesNetwork_ = placesNetwork;
502  }
503 
504 
505  Qt::SortOrder sortOrder() const {
506  return sortOrder_;
507  }
508 
509  void setSortOrder(Qt::SortOrder sortOrder) {
510  sortOrder_ = sortOrder;
511  }
512 
513  Fm::FolderModel::ColumnId sortColumn() const {
514  return sortColumn_;
515  }
516 
517  void setSortColumn(Fm::FolderModel::ColumnId sortColumn) {
518  sortColumn_ = sortColumn;
519  }
520 
521  bool sortFolderFirst() const {
522  return sortFolderFirst_;
523  }
524 
525  void setSortFolderFirst(bool folderFirst) {
526  sortFolderFirst_ = folderFirst;
527  }
528 
529  bool showFilter() const {
530  return showFilter_;
531  }
532 
533  void setShowFilter(bool value) {
534  showFilter_ = value;
535  }
536 
537  // settings for use with libfm
538  bool singleClick() const {
539  return singleClick_;
540  }
541 
542  void setSingleClick(bool singleClick) {
543  singleClick_ = singleClick;
544  }
545 
546  int autoSelectionDelay() const {
547  return autoSelectionDelay_;
548  }
549 
550  void setAutoSelectionDelay(int value) {
551  autoSelectionDelay_ = value;
552  }
553 
554  bool useTrash() const {
555  if(!supportTrash_)
556  return false;
557  return useTrash_;
558  }
559 
560  void setUseTrash(bool useTrash) {
561  useTrash_ = useTrash;
562  }
563 
564  bool confirmDelete() const {
565  return confirmDelete_;
566  }
567 
568  void setConfirmDelete(bool confirmDelete) {
569  confirmDelete_ = confirmDelete;
570  }
571 
572  bool noUsbTrash() const {
573  return noUsbTrash_;
574  }
575 
576  void setNoUsbTrash(bool noUsbTrash) {
577  noUsbTrash_ = noUsbTrash;
578  fm_config->no_usb_trash = noUsbTrash_; // also set this to libfm since FmFileOpsJob reads this config value before trashing files.
579  }
580 
581  bool confirmTrash() const {
582  return confirmTrash_;
583  }
584 
585  void setConfirmTrash(bool value) {
586  confirmTrash_ = value;
587  }
588 
589  bool quickExec() const {
590  return quickExec_;
591  }
592 
593  void setQuickExec(bool value) {
594  quickExec_ = value;
595  fm_config->quick_exec = quickExec_;
596  }
597 
598  // bool thumbnailLocal_;
599  // bool thumbnailMax;
600 
601  int bigIconSize() const {
602  return bigIconSize_;
603  }
604 
605  void setBigIconSize(int bigIconSize) {
606  bigIconSize_ = bigIconSize;
607  }
608 
609  int smallIconSize() const {
610  return smallIconSize_;
611  }
612 
613  void setSmallIconSize(int smallIconSize) {
614  smallIconSize_ = smallIconSize;
615  }
616 
617  int sidePaneIconSize() const {
618  return sidePaneIconSize_;
619  }
620 
621  void setSidePaneIconSize(int sidePaneIconSize) {
622  sidePaneIconSize_ = sidePaneIconSize;
623  }
624 
625  int thumbnailIconSize() const {
626  return thumbnailIconSize_;
627  }
628 
629  QSize folderViewCellMargins() const {
630  return folderViewCellMargins_;
631  }
632 
633  void setFolderViewCellMargins(QSize size) {
634  folderViewCellMargins_ = size;
635  }
636 
637  QSize desktopCellMargins() const {
638  return desktopCellMargins_;
639  }
640 
641  void setDesktopCellMargins(QSize size) {
642  desktopCellMargins_ = size;
643  }
644 
645 
646  bool showThumbnails() {
647  return showThumbnails_;
648  }
649 
650  void setShowThumbnails(bool show) {
651  showThumbnails_ = show;
652  }
653 
654  void setThumbnailLocalFilesOnly(bool value) {
655  Fm::ThumbnailLoader::setLocalFilesOnly(value);
656  }
657 
658  bool thumbnailLocalFilesOnly() {
659  return Fm::ThumbnailLoader::localFilesOnly();
660  }
661 
662  int maxThumbnailFileSize() {
663  return Fm::ThumbnailLoader::maxThumbnailFileSize();
664  }
665 
666  void setMaxThumbnailFileSize(int size) {
667  Fm::ThumbnailLoader::setMaxThumbnailFileSize(size);
668  }
669 
670  void setThumbnailIconSize(int thumbnailIconSize) {
671  thumbnailIconSize_ = thumbnailIconSize;
672  }
673 
674  bool siUnit() {
675  return siUnit_;
676  }
677 
678  void setSiUnit(bool siUnit) {
679  siUnit_ = siUnit;
680  // override libfm FmConfig settings. FIXME: should we do this?
681  fm_config->si_unit = (gboolean)siUnit_;
682  }
683 
684  bool backupAsHidden() const {
685  return backupAsHidden_;
686  }
687 
688  void setBackupAsHidden(bool value) {
689  backupAsHidden_ = value;
690  fm_config->backup_as_hidden = backupAsHidden_; // also set this to libfm since fm_file_info_is_hidden() reads this value internally.
691  }
692 
693  bool showFullNames() const {
694  return showFullNames_;
695  }
696 
697  void setShowFullNames(bool value) {
698  showFullNames_ = value;
699  }
700 
701  bool shadowHidden() const {
702  return shadowHidden_;
703  }
704 
705  void setShadowHidden(bool value) {
706  shadowHidden_ = value;
707  }
708 
709  bool onlyUserTemplates() const {
710  return onlyUserTemplates_;
711  }
712 
713  void setOnlyUserTemplates(bool value) {
714  onlyUserTemplates_ = value;
715  fm_config->only_user_templates = onlyUserTemplates_;
716  }
717 
718  bool templateTypeOnce() const {
719  return templateTypeOnce_;
720  }
721 
722  void setTemplateTypeOnce(bool value) {
723  templateTypeOnce_ = value;
724  fm_config->template_type_once = templateTypeOnce_;
725  }
726 
727  bool templateRunApp() const {
728  return templateRunApp_;
729  }
730 
731  void setTemplateRunApp(bool value) {
732  templateRunApp_ = value;
733  fm_config->template_run_app = templateRunApp_;
734  }
735 
736  // per-folder settings
737  FolderSettings loadFolderSettings(Fm::Path path) const;
738 
739  void saveFolderSettings(Fm::Path path, const FolderSettings &settings);
740 
741  void clearFolderSettings(Fm::Path path) const;
742 
743 private:
744  QString profileName_;
745  bool supportTrash_;
746 
747  // PCManFM specific
748  QString fallbackIconThemeName_;
749  bool useFallbackIconTheme_;
750 
751  OpenDirTargetType bookmarkOpenMethod_;
752  QString suCommand_;
753  QString terminal_;
754  bool mountOnStartup_;
755  bool mountRemovable_;
756  bool autoRun_;
757  bool closeOnUnmount_;
758 
759  int wallpaperMode_;
760  QString wallpaper_;
761  QColor desktopBgColor_;
762  QColor desktopFgColor_;
763  QColor desktopShadowColor_;
764  QFont desktopFont_;
765  int desktopIconSize_;
766  bool showWmMenu_;
767 
768  bool desktopShowHidden_;
769  Qt::SortOrder desktopSortOrder_;
770  Fm::FolderModel::ColumnId desktopSortColumn_;
771  bool desktopSortFolderFirst_;
772 
773  bool alwaysShowTabs_;
774  bool showTabClose_;
775  bool rememberWindowSize_;
776  int fixedWindowWidth_;
777  int fixedWindowHeight_;
778  int lastWindowWidth_;
779  int lastWindowHeight_;
780  bool lastWindowMaximized_;
781  int splitterPos_;
782  Fm::SidePane::Mode sidePaneMode_;
783  bool showMenuBar_;
784  bool fullWidthTabBar_;
785 
786  Fm::FolderView::ViewMode viewMode_;
787  bool showHidden_;
788  Qt::SortOrder sortOrder_;
789  Fm::FolderModel::ColumnId sortColumn_;
790  bool sortFolderFirst_;
791  bool sortCaseSensitive_;
792  bool showFilter_;
793 
794  // settings for use with libfm
795  bool singleClick_;
796  int autoSelectionDelay_;
797  bool useTrash_;
798  bool confirmDelete_;
799  bool noUsbTrash_; // do not trash files on usb removable devices
800  bool confirmTrash_; // Confirm before moving files into "trash can"
801  bool quickExec_; // Don't ask options on launch executable file
802 
803  bool showThumbnails_;
804 
805  QString archiver_;
806  bool siUnit_;
807  bool backupAsHidden_;
808  bool showFullNames_;
809  bool shadowHidden_;
810 
811  bool placesHome_;
812  bool placesDesktop_;
813  bool placesApplications_;
814  bool placesTrash_;
815  bool placesRoot_;
816  bool placesComputer_;
817  bool placesNetwork_;
818 
819  int bigIconSize_;
820  int smallIconSize_;
821  int sidePaneIconSize_;
822  int thumbnailIconSize_;
823 
824  bool onlyUserTemplates_;
825  bool templateTypeOnce_;
826  bool templateRunApp_;
827 
828  QSize folderViewCellMargins_;
829  QSize desktopCellMargins_;
830 };
831 
832 }
833 
834 #endif // PCMANFM_SETTINGS_H
Definition: settings.h:121
Definition: application.cpp:57
Definition: settings.h:41