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