]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/viewmodes/viewmodesettings.cpp
use save() instead of writeConfig()
[dolphin.git] / src / settings / viewmodes / viewmodesettings.cpp
1 /***************************************************************************
2 * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
19
20 #include "viewmodesettings.h"
21
22 #include "dolphin_iconsmodesettings.h"
23 #include "dolphin_detailsmodesettings.h"
24 #include "dolphin_compactmodesettings.h"
25
26 #define VIEWMODESETTINGS_SET_VALUE(mode, setValue, value) \
27 switch (mode) { \
28 case ViewModeSettings::IconsMode: IconsModeSettings::setValue(value); break; \
29 case ViewModeSettings::CompactMode: CompactModeSettings::setValue(value); break; \
30 case ViewModeSettings::DetailsMode: DetailsModeSettings::setValue(value); break; \
31 default: Q_ASSERT(false); break; \
32 }
33
34 #define VIEWMODESETTINGS_RETURN_VALUE(mode, getValue, type) \
35 type value; \
36 switch (m_mode) { \
37 case IconsMode: value = IconsModeSettings::getValue(); break; \
38 case CompactMode: value = CompactModeSettings::getValue(); break; \
39 case DetailsMode: value = DetailsModeSettings::getValue(); break; \
40 default: value = IconsModeSettings::getValue(); \
41 Q_ASSERT(false); \
42 break; \
43 } \
44 return value
45
46 ViewModeSettings::ViewModeSettings(ViewMode mode) :
47 m_mode(mode)
48 {
49 }
50
51 ViewModeSettings::~ViewModeSettings()
52 {
53 }
54
55 void ViewModeSettings::setIconSize(int size) const
56 {
57 VIEWMODESETTINGS_SET_VALUE(m_mode, setIconSize, size);
58 }
59
60 int ViewModeSettings::iconSize() const
61 {
62 VIEWMODESETTINGS_RETURN_VALUE(m_mode, iconSize, int);
63 }
64
65 void ViewModeSettings::setPreviewSize(int size) const
66 {
67 VIEWMODESETTINGS_SET_VALUE(m_mode, setPreviewSize, size);
68 }
69
70 int ViewModeSettings::previewSize() const
71 {
72 VIEWMODESETTINGS_RETURN_VALUE(m_mode, previewSize, int);
73 }
74
75 void ViewModeSettings::setUseSystemFont(bool flag)
76 {
77 VIEWMODESETTINGS_SET_VALUE(m_mode, setUseSystemFont, flag);
78 }
79
80 bool ViewModeSettings::useSystemFont() const
81 {
82 VIEWMODESETTINGS_RETURN_VALUE(m_mode, useSystemFont, bool);
83 }
84
85 void ViewModeSettings::setFontFamily(const QString& fontFamily)
86 {
87 VIEWMODESETTINGS_SET_VALUE(m_mode, setFontFamily, fontFamily);
88 }
89
90 QString ViewModeSettings::fontFamily() const
91 {
92 VIEWMODESETTINGS_RETURN_VALUE(m_mode, fontFamily, QString);
93 }
94
95 void ViewModeSettings::setFontSize(qreal fontSize)
96 {
97 VIEWMODESETTINGS_SET_VALUE(m_mode, setFontSize, fontSize);
98 }
99
100 qreal ViewModeSettings::fontSize() const
101 {
102 VIEWMODESETTINGS_RETURN_VALUE(m_mode, fontSize, qreal);
103 }
104
105 void ViewModeSettings::setItalicFont(bool italic)
106 {
107 VIEWMODESETTINGS_SET_VALUE(m_mode, setItalicFont, italic);
108 }
109
110 bool ViewModeSettings::italicFont() const
111 {
112 VIEWMODESETTINGS_RETURN_VALUE(m_mode, italicFont, bool);
113 }
114
115 void ViewModeSettings::setFontWeight(int fontWeight)
116 {
117 VIEWMODESETTINGS_SET_VALUE(m_mode, setFontWeight, fontWeight);
118 }
119
120 int ViewModeSettings::fontWeight() const
121 {
122 VIEWMODESETTINGS_RETURN_VALUE(m_mode, fontWeight, int);
123 }
124
125 void ViewModeSettings::readConfig()
126 {
127 switch (m_mode) {
128 case ViewModeSettings::IconsMode: IconsModeSettings::self()->load(); break;
129 case ViewModeSettings::CompactMode: CompactModeSettings::self()->load(); break;
130 case ViewModeSettings::DetailsMode: DetailsModeSettings::self()->load(); break;
131 default: Q_ASSERT(false); break;
132 }
133 }
134
135 void ViewModeSettings::save()
136 {
137 switch (m_mode) {
138 case ViewModeSettings::IconsMode: IconsModeSettings::self()->save(); break;
139 case ViewModeSettings::CompactMode: CompactModeSettings::self()->save(); break;
140 case ViewModeSettings::DetailsMode: DetailsModeSettings::self()->save(); break;
141 default: Q_ASSERT(false); break;
142 }
143 }