]>
cloud.milkyroute.net Git - dolphin.git/blob - src/dolphinsettings.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz (peter.penz@gmx.at), *
3 * Cvetoslav Ludmiloff and Patrice Tremblay *
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. *
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. *
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 ***************************************************************************/
21 #include "dolphinsettings.h"
26 #include <kapplication.h>
27 #include <kbookmark.h>
28 #include <kbookmarkmanager.h>
29 #include <kicontheme.h>
31 #include <kstandarddirs.h>
33 #include "generalsettings.h"
34 #include "iconsmodesettings.h"
35 #include "detailsmodesettings.h"
39 DolphinSettings
& DolphinSettings::instance()
41 static DolphinSettings
* instance
= 0;
43 instance
= new DolphinSettings();
48 KBookmark
DolphinSettings::bookmark(int index
) const
51 KBookmarkGroup root
= bookmarkManager()->root();
52 KBookmark bookmark
= root
.first();
53 while (!bookmark
.isNull()) {
58 bookmark
= root
.next(bookmark
);
64 KBookmarkManager
* DolphinSettings::bookmarkManager() const
66 QString basePath
= KGlobal::instance()->instanceName();
67 basePath
.append("/bookmarks.xml");
68 const QString file
= KStandardDirs::locateLocal("data", basePath
);
70 return KBookmarkManager::managerForFile(file
, "dolphin", false);
73 void DolphinSettings::save()
75 m_generalSettings
->writeConfig();
76 m_iconsModeSettings
->writeConfig();
77 m_detailsModeSettings
->writeConfig();
79 QString basePath
= KGlobal::instance()->instanceName();
80 basePath
.append("/bookmarks.xml");
81 const QString file
= KStandardDirs::locateLocal( "data", basePath
);
83 KBookmarkManager
* manager
= KBookmarkManager::managerForFile(file
, "dolphin", false);
87 void DolphinSettings::calculateGridSize(int hint
)
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
;
98 if (arrangement
== Q3IconView::LeftToRight
) {
99 int widthUnit
= maxSize
+ (maxSize
/ 2);
100 if (widthUnit
< K3Icon::SizeLarge
) {
101 widthUnit
= K3Icon::SizeLarge
;
104 gridWidth
= widthUnit
+ hint
* K3Icon::SizeLarge
;
106 gridHeight
= iconSize
;
107 if (gridHeight
<= K3Icon::SizeMedium
) {
108 gridHeight
= gridHeight
* 2;
111 gridHeight
+= maxSize
/ 2;
115 assert(arrangement
== Q3IconView::TopToBottom
);
116 gridWidth
= maxSize
+ (hint
+ 1) * (8 * m_iconsModeSettings
->fontSize());
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
;
123 m_iconsModeSettings
->setGridWidth(gridWidth
);
124 m_iconsModeSettings
->setGridHeight(gridHeight
);
127 int DolphinSettings::textWidthHint() const
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
;
135 const int gridWidth
= m_iconsModeSettings
->gridWidth();
137 const int maxSize
= (previewSize
> iconSize
) ? previewSize
: iconSize
;
139 if (arrangement
== Q3IconView::LeftToRight
) {
140 int widthUnit
= maxSize
+ (maxSize
/ 2);
141 if (widthUnit
< K3Icon::SizeLarge
) {
142 widthUnit
= K3Icon::SizeLarge
;
144 hint
= (gridWidth
- widthUnit
) / K3Icon::SizeLarge
;
147 assert(arrangement
== Q3IconView::TopToBottom
);
148 hint
= (gridWidth
- maxSize
) / (8 * m_iconsModeSettings
->fontSize()) - 1;
156 DolphinSettings::DolphinSettings()
158 m_generalSettings
= new GeneralSettings();
159 m_iconsModeSettings
= new IconsModeSettings();
160 m_detailsModeSettings
= new DetailsModeSettings();
163 DolphinSettings::~DolphinSettings()
165 delete m_generalSettings
;
166 m_generalSettings
= 0;
168 delete m_iconsModeSettings
;
169 m_iconsModeSettings
= 0;
171 delete m_detailsModeSettings
;
172 m_detailsModeSettings
= 0;