]> cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinsettings.cpp
minor cosmetic update of the progress indication
[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
38 #include <Q3IconView>
39
40 DolphinSettings& DolphinSettings::instance()
41 {
42 static DolphinSettings* instance = 0;
43 if (instance == 0) {
44 instance = new DolphinSettings();
45 }
46 return *instance;
47 }
48
49 KBookmark DolphinSettings::bookmark(int index) const
50 {
51 int i = 0;
52 KBookmarkGroup root = bookmarkManager()->root();
53 KBookmark bookmark = root.first();
54 while (!bookmark.isNull()) {
55 if (i == index) {
56 return bookmark;
57 }
58 ++i;
59 bookmark = root.next(bookmark);
60 }
61
62 return KBookmark();
63 }
64
65 KBookmarkManager* DolphinSettings::bookmarkManager() const
66 {
67 QString basePath = KGlobal::instance()->instanceName();
68 basePath.append("/bookmarks.xml");
69 const QString file = KStandardDirs::locateLocal("data", basePath);
70
71 return KBookmarkManager::managerForFile(file, "dolphin", false);
72 }
73
74 void DolphinSettings::save()
75 {
76 m_generalSettings->writeConfig();
77 m_iconsModeSettings->writeConfig();
78 m_previewsModeSettings->writeConfig();
79 m_detailsModeSettings->writeConfig();
80
81 QString basePath = KGlobal::instance()->instanceName();
82 basePath.append("/bookmarks.xml");
83 const QString file = KStandardDirs::locateLocal( "data", basePath);
84
85 KBookmarkManager* manager = KBookmarkManager::managerForFile(file, "dolphin", false);
86 manager->save(false);
87 }
88
89 void DolphinSettings::calculateGridSize(int hint)
90 {
91 // TODO: remove in KDE4
92 const int previewSize = m_iconsModeSettings->previewSize();
93 const int iconSize = m_iconsModeSettings->iconSize();
94 const int maxSize = (previewSize > iconSize) ? previewSize : iconSize;
95 const Q3IconView::Arrangement arrangement = (m_iconsModeSettings->arrangement() == "LeftToRight") ?
96 Q3IconView::LeftToRight : Q3IconView::TopToBottom;
97
98 int gridWidth = 0;
99 int gridHeight = 0;
100 if (arrangement == Q3IconView::LeftToRight) {
101 int widthUnit = maxSize + (maxSize / 2);
102 if (widthUnit < K3Icon::SizeLarge) {
103 widthUnit = K3Icon::SizeLarge;
104 }
105
106 gridWidth = widthUnit + hint * K3Icon::SizeLarge;
107
108 gridHeight = iconSize;
109 if (gridHeight <= K3Icon::SizeMedium) {
110 gridHeight = gridHeight * 2;
111 }
112 else {
113 gridHeight += maxSize / 2;
114 }
115 }
116 else {
117 assert(arrangement == Q3IconView::TopToBottom);
118 gridWidth = maxSize + (hint + 1) * (8 * m_iconsModeSettings->fontSize());
119
120 // The height-setting is ignored yet by KFileIconView if the TopToBottom
121 // arrangement is active. Anyway write the setting to have a defined value.
122 gridHeight = maxSize;
123 }
124
125 m_iconsModeSettings->setGridWidth(gridWidth);
126 m_iconsModeSettings->setGridHeight(gridHeight);
127 }
128
129 int DolphinSettings::textWidthHint() const
130 {
131 // TODO: remove in KDE4
132 const int previewSize = m_iconsModeSettings->previewSize();
133 const int iconSize = m_iconsModeSettings->iconSize();
134 const Q3IconView::Arrangement arrangement = (m_iconsModeSettings->arrangement() == "LeftToRight") ?
135 Q3IconView::LeftToRight : Q3IconView::TopToBottom;
136
137 const int gridWidth = m_iconsModeSettings->gridWidth();
138
139 const int maxSize = (previewSize > iconSize) ? previewSize : iconSize;
140 int hint = 0;
141 if (arrangement == Q3IconView::LeftToRight) {
142 int widthUnit = maxSize + (maxSize / 2);
143 if (widthUnit < K3Icon::SizeLarge) {
144 widthUnit = K3Icon::SizeLarge;
145 }
146 hint = (gridWidth - widthUnit) / K3Icon::SizeLarge;
147 }
148 else {
149 assert(arrangement == Q3IconView::TopToBottom);
150 hint = (gridWidth - maxSize) / (8 * m_iconsModeSettings->fontSize()) - 1;
151 if (hint > 2) {
152 hint = 2;
153 }
154 }
155 return hint;
156 }
157
158 DolphinSettings::DolphinSettings()
159 {
160 m_generalSettings = new GeneralSettings();
161 m_iconsModeSettings = new IconsModeSettings();
162 m_previewsModeSettings = new PreviewsModeSettings();
163 m_detailsModeSettings = new DetailsModeSettings();
164 }
165
166 DolphinSettings::~DolphinSettings()
167 {
168 delete m_generalSettings;
169 m_generalSettings = 0;
170
171 delete m_iconsModeSettings;
172 m_iconsModeSettings = 0;
173
174 delete m_previewsModeSettings;
175 m_previewsModeSettings = 0;
176
177 delete m_detailsModeSettings;
178 m_detailsModeSettings = 0;
179 }