PCManFM-Qt
 All Classes
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  bool pathBarButtons() const {
538  return pathBarButtons_;
539  }
540 
541  void setPathBarButtons(bool value) {
542  pathBarButtons_ = value;
543  }
544 
545  // settings for use with libfm
546  bool singleClick() const {
547  return singleClick_;
548  }
549 
550  void setSingleClick(bool singleClick) {
551  singleClick_ = singleClick;
552  }
553 
554  int autoSelectionDelay() const {
555  return autoSelectionDelay_;
556  }
557 
558  void setAutoSelectionDelay(int value) {
559  autoSelectionDelay_ = value;
560  }
561 
562  bool useTrash() const {
563  if(!supportTrash_)
564  return false;
565  return useTrash_;
566  }
567 
568  void setUseTrash(bool useTrash) {
569  useTrash_ = useTrash;
570  }
571 
572  bool confirmDelete() const {
573  return confirmDelete_;
574  }
575 
576  void setConfirmDelete(bool confirmDelete) {
577  confirmDelete_ = confirmDelete;
578  }
579 
580  bool noUsbTrash() const {
581  return noUsbTrash_;
582  }
583 
584  void setNoUsbTrash(bool noUsbTrash) {
585  noUsbTrash_ = noUsbTrash;
586  fm_config->no_usb_trash = noUsbTrash_; // also set this to libfm since FmFileOpsJob reads this config value before trashing files.
587  }
588 
589  bool confirmTrash() const {
590  return confirmTrash_;
591  }
592 
593  void setConfirmTrash(bool value) {
594  confirmTrash_ = value;
595  }
596 
597  bool quickExec() const {
598  return quickExec_;
599  }
600 
601  void setQuickExec(bool value) {
602  quickExec_ = value;
603  fm_config->quick_exec = quickExec_;
604  }
605 
606  // bool thumbnailLocal_;
607  // bool thumbnailMax;
608 
609  int bigIconSize() const {
610  return bigIconSize_;
611  }
612 
613  void setBigIconSize(int bigIconSize) {
614  bigIconSize_ = bigIconSize;
615  }
616 
617  int smallIconSize() const {
618  return smallIconSize_;
619  }
620 
621  void setSmallIconSize(int smallIconSize) {
622  smallIconSize_ = smallIconSize;
623  }
624 
625  int sidePaneIconSize() const {
626  return sidePaneIconSize_;
627  }
628 
629  void setSidePaneIconSize(int sidePaneIconSize) {
630  sidePaneIconSize_ = sidePaneIconSize;
631  }
632 
633  int thumbnailIconSize() const {
634  return thumbnailIconSize_;
635  }
636 
637  QSize folderViewCellMargins() const {
638  return folderViewCellMargins_;
639  }
640 
641  void setFolderViewCellMargins(QSize size) {
642  folderViewCellMargins_ = size;
643  }
644 
645  QSize desktopCellMargins() const {
646  return desktopCellMargins_;
647  }
648 
649  void setDesktopCellMargins(QSize size) {
650  desktopCellMargins_ = size;
651  }
652 
653 
654  bool showThumbnails() {
655  return showThumbnails_;
656  }
657 
658  void setShowThumbnails(bool show) {
659  showThumbnails_ = show;
660  }
661 
662  void setThumbnailLocalFilesOnly(bool value) {
663  Fm::ThumbnailLoader::setLocalFilesOnly(value);
664  }
665 
666  bool thumbnailLocalFilesOnly() {
667  return Fm::ThumbnailLoader::localFilesOnly();
668  }
669 
670  int maxThumbnailFileSize() {
671  return Fm::ThumbnailLoader::maxThumbnailFileSize();
672  }
673 
674  void setMaxThumbnailFileSize(int size) {
675  Fm::ThumbnailLoader::setMaxThumbnailFileSize(size);
676  }
677 
678  void setThumbnailIconSize(int thumbnailIconSize) {
679  thumbnailIconSize_ = thumbnailIconSize;
680  }
681 
682  bool siUnit() {
683  return siUnit_;
684  }
685 
686  void setSiUnit(bool siUnit) {
687  siUnit_ = siUnit;
688  // override libfm FmConfig settings. FIXME: should we do this?
689  fm_config->si_unit = (gboolean)siUnit_;
690  }
691 
692  bool backupAsHidden() const {
693  return backupAsHidden_;
694  }
695 
696  void setBackupAsHidden(bool value) {
697  backupAsHidden_ = value;
698  fm_config->backup_as_hidden = backupAsHidden_; // also set this to libfm since fm_file_info_is_hidden() reads this value internally.
699  }
700 
701  bool showFullNames() const {
702  return showFullNames_;
703  }
704 
705  void setShowFullNames(bool value) {
706  showFullNames_ = value;
707  }
708 
709  bool shadowHidden() const {
710  return shadowHidden_;
711  }
712 
713  void setShadowHidden(bool value) {
714  shadowHidden_ = value;
715  }
716 
717  bool onlyUserTemplates() const {
718  return onlyUserTemplates_;
719  }
720 
721  void setOnlyUserTemplates(bool value) {
722  onlyUserTemplates_ = value;
723  fm_config->only_user_templates = onlyUserTemplates_;
724  }
725 
726  bool templateTypeOnce() const {
727  return templateTypeOnce_;
728  }
729 
730  void setTemplateTypeOnce(bool value) {
731  templateTypeOnce_ = value;
732  fm_config->template_type_once = templateTypeOnce_;
733  }
734 
735  bool templateRunApp() const {
736  return templateRunApp_;
737  }
738 
739  void setTemplateRunApp(bool value) {
740  templateRunApp_ = value;
741  fm_config->template_run_app = templateRunApp_;
742  }
743 
744  // per-folder settings
745  FolderSettings loadFolderSettings(Fm::Path path) const;
746 
747  void saveFolderSettings(Fm::Path path, const FolderSettings &settings);
748 
749  void clearFolderSettings(Fm::Path path) const;
750 
751 private:
752  QString profileName_;
753  bool supportTrash_;
754 
755  // PCManFM specific
756  QString fallbackIconThemeName_;
757  bool useFallbackIconTheme_;
758 
759  OpenDirTargetType bookmarkOpenMethod_;
760  QString suCommand_;
761  QString terminal_;
762  bool mountOnStartup_;
763  bool mountRemovable_;
764  bool autoRun_;
765  bool closeOnUnmount_;
766 
767  int wallpaperMode_;
768  QString wallpaper_;
769  QColor desktopBgColor_;
770  QColor desktopFgColor_;
771  QColor desktopShadowColor_;
772  QFont desktopFont_;
773  int desktopIconSize_;
774  bool showWmMenu_;
775 
776  bool desktopShowHidden_;
777  Qt::SortOrder desktopSortOrder_;
778  Fm::FolderModel::ColumnId desktopSortColumn_;
779  bool desktopSortFolderFirst_;
780 
781  bool alwaysShowTabs_;
782  bool showTabClose_;
783  bool rememberWindowSize_;
784  int fixedWindowWidth_;
785  int fixedWindowHeight_;
786  int lastWindowWidth_;
787  int lastWindowHeight_;
788  bool lastWindowMaximized_;
789  int splitterPos_;
790  Fm::SidePane::Mode sidePaneMode_;
791  bool showMenuBar_;
792  bool fullWidthTabBar_;
793 
794  Fm::FolderView::ViewMode viewMode_;
795  bool showHidden_;
796  Qt::SortOrder sortOrder_;
797  Fm::FolderModel::ColumnId sortColumn_;
798  bool sortFolderFirst_;
799  bool sortCaseSensitive_;
800  bool showFilter_;
801  bool pathBarButtons_;
802 
803  // settings for use with libfm
804  bool singleClick_;
805  int autoSelectionDelay_;
806  bool useTrash_;
807  bool confirmDelete_;
808  bool noUsbTrash_; // do not trash files on usb removable devices
809  bool confirmTrash_; // Confirm before moving files into "trash can"
810  bool quickExec_; // Don't ask options on launch executable file
811 
812  bool showThumbnails_;
813 
814  QString archiver_;
815  bool siUnit_;
816  bool backupAsHidden_;
817  bool showFullNames_;
818  bool shadowHidden_;
819 
820  bool placesHome_;
821  bool placesDesktop_;
822  bool placesApplications_;
823  bool placesTrash_;
824  bool placesRoot_;
825  bool placesComputer_;
826  bool placesNetwork_;
827 
828  int bigIconSize_;
829  int smallIconSize_;
830  int sidePaneIconSize_;
831  int thumbnailIconSize_;
832 
833  bool onlyUserTemplates_;
834  bool templateTypeOnce_;
835  bool templateRunApp_;
836 
837  QSize folderViewCellMargins_;
838  QSize desktopCellMargins_;
839 };
840 
841 }
842 
843 #endif // PCMANFM_SETTINGS_H
Definition: settings.h:121
Definition: settings.h:41