]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinsettings.cpp
Changes to Undo/Redo in regard to ProgressIndicator
[dolphin.git] / src / dolphinsettings.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at), *
3 * Cvetoslav Ludmiloff and Patrice Tremblay *
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 *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20
21 #include "dolphinsettings.h"
22
23 #include <assert.h>
24 #include <qdir.h>
25
26 #include <kapplication.h>
27 #include <kbookmark.h>
28 #include <kbookmarkmanager.h>
29 #include <kicontheme.h>
30 #include <klocale.h>
31 #include <kstandarddirs.h>
32
33 #include "generalsettings.h"
34 #include "iconsmodesettings.h"
35 #include "previewsmodesettings.h"
36 #include "detailsmodesettings.h"
37 #include "sidebarsettings.h"
38
39 #include <Q3IconView>
40
41 DolphinSettings& DolphinSettings::instance()
42 {
43 static DolphinSettings* instance = 0;
44 if (instance == 0) {
45 instance = new DolphinSettings();
46 }
47 return *instance;
48 }
49
50 KBookmark DolphinSettings::bookmark(int index) const
51 {
52 int i = 0;
53 KBookmarkGroup root = bookmarkManager()->root();
54 KBookmark bookmark = root.first();
55 while (!bookmark.isNull()) {
56 if (i == index) {
57 return bookmark;
58 }
59 ++i;
60 bookmark = root.next(bookmark);
61 }
62
63 return KBookmark();
64 }
65
66 KBookmarkManager* DolphinSettings::bookmarkManager() const
67 {
68 QString basePath = KGlobal::instance()->instanceName();
69 basePath.append("/bookmarks.xml");
70 const QString file = KStandardDirs::locateLocal("data", basePath);
71
72 return KBookmarkManager::managerForFile(file, "dolphin", false);
73 }
74
75 void DolphinSettings::save()
76 {
77 m_generalSettings->writeConfig();
78 m_iconsModeSettings->writeConfig();
79 m_previewsModeSettings->writeConfig();
80 m_detailsModeSettings->writeConfig();
81 m_sidebarSettings->writeConfig();
82
83 QString basePath = KGlobal::instance()->instanceName();
84 basePath.append("/bookmarks.xml");
85 const QString file = KStandardDirs::locateLocal( "data", basePath);
86
87 KBookmarkManager* manager = KBookmarkManager::managerForFile(file, "dolphin", false);
88 manager->save(false);
89 }
90
91 void DolphinSettings::calculateGridSize(int hint)
92 {
93 // TODO: remove in KDE4
94 const int previewSize = m_iconsModeSettings->previewSize();
95 const int iconSize = m_iconsModeSettings->iconSize();
96 const int maxSize = (previewSize > iconSize) ? previewSize : iconSize;
97 const Q3IconView::Arrangement arrangement = (m_iconsModeSettings->arrangement() == "LeftToRight") ?
98 Q3IconView::LeftToRight : Q3IconView::TopToBottom;
99
100 int gridWidth = 0;
101 int gridHeight = 0;
102 if (arrangement == Q3IconView::LeftToRight) {
103 int widthUnit = maxSize + (maxSize / 2);
104 if (widthUnit < K3Icon::SizeLarge) {
105 widthUnit = K3Icon::SizeLarge;
106 }
107
108 gridWidth = widthUnit + hint * K3Icon::SizeLarge;
109
110 gridHeight = iconSize;
111 if (gridHeight <= K3Icon::SizeMedium) {
112 gridHeight = gridHeight * 2;
113 }
114 else {
115 gridHeight += maxSize / 2;
116 }
117 }
118 else {
119 assert(arrangement == Q3IconView::TopToBottom);
120 gridWidth = maxSize + (hint + 1) * (8 * m_iconsModeSettings->fontSize());
121
122 // The height-setting is ignored yet by KFileIconView if the TopToBottom
123 // arrangement is active. Anyway write the setting to have a defined value.
124 gridHeight = maxSize;
125 }
126
127 m_iconsModeSettings->setGridWidth(gridWidth);
128 m_iconsModeSettings->setGridHeight(gridHeight);
129 }
130
131 int DolphinSettings::textWidthHint() const
132 {
133 // TODO: remove in KDE4
134 const int previewSize = m_iconsModeSettings->previewSize();
135 const int iconSize = m_iconsModeSettings->iconSize();
136 const Q3IconView::Arrangement arrangement = (m_iconsModeSettings->arrangement() == "LeftToRight") ?
137 Q3IconView::LeftToRight : Q3IconView::TopToBottom;
138
139 const int gridWidth = m_iconsModeSettings->gridWidth();
140
141 const int maxSize = (previewSize > iconSize) ? previewSize : iconSize;
142 int hint = 0;
143 if (arrangement == Q3IconView::LeftToRight) {
144 int widthUnit = maxSize + (maxSize / 2);
145 if (widthUnit < K3Icon::SizeLarge) {
146 widthUnit = K3Icon::SizeLarge;
147 }
148 hint = (gridWidth - widthUnit) / K3Icon::SizeLarge;
149 }
150 else {
151 assert(arrangement == Q3IconView::TopToBottom);
152 hint = (gridWidth - maxSize) / (8 * m_iconsModeSettings->fontSize()) - 1;
153 if (hint > 2) {
154 hint = 2;
155 }
156 }
157 return hint;
158 }
159
160 DolphinSettings::DolphinSettings()
161 {
162 m_generalSettings = new GeneralSettings();
163 m_iconsModeSettings = new IconsModeSettings();
164 m_previewsModeSettings = new PreviewsModeSettings();
165 m_detailsModeSettings = new DetailsModeSettings();
166 m_sidebarSettings = new SidebarSettings();
167 }
168
169 DolphinSettings::~DolphinSettings()
170 {
171 delete m_generalSettings;
172 m_generalSettings = 0;
173
174 delete m_iconsModeSettings;
175 m_iconsModeSettings = 0;
176
177 delete m_previewsModeSettings;
178 m_previewsModeSettings = 0;
179
180 delete m_detailsModeSettings;
181 m_detailsModeSettings = 0;
182
183 delete m_sidebarSettings;
184 m_sidebarSettings = 0;
185 }