]> cloud.milkyroute.net Git - dolphin.git/blob - src/generalviewsettingspage.cpp
use KGraphicsUtils::blendColor() instead of custom mixColors() method
[dolphin.git] / src / generalviewsettingspage.cpp
1 /***************************************************************************
2 * Copyright (C) 2006 by Peter Penz <peter.penz@gmx.at> *
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 "generalviewsettingspage.h"
21 #include "dolphinmainwindow.h"
22 #include "dolphinsettings.h"
23 #include "dolphin_generalsettings.h"
24 #include "viewproperties.h"
25
26 #include <QtGui/QLabel>
27 #include <QtGui/QGroupBox>
28 #include <QtGui/QRadioButton>
29 #include <QtGui/QSlider>
30 #include <QtGui/QSpinBox>
31 #include <QtGui/QBoxLayout>
32
33 #include <kconfiggroup.h>
34 #include <kdialog.h>
35 #include <kglobal.h>
36 #include <klocale.h>
37 #include <khbox.h>
38
39 GeneralViewSettingsPage::GeneralViewSettingsPage(DolphinMainWindow* mainWindow,
40 QWidget* parent) :
41 KVBox(parent),
42 m_mainWindow(mainWindow),
43 m_localProps(0),
44 m_globalProps(0),
45 m_maxPreviewSize(0),
46 m_spinBox(0)
47 {
48 const int spacing = KDialog::spacingHint();
49 const int margin = KDialog::marginHint();
50 const QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
51
52 setSpacing(spacing);
53 setMargin(margin);
54
55 QGroupBox* propsBox = new QGroupBox(i18n("View Properties"), this);
56
57 m_localProps = new QRadioButton(i18n("Remember view properties for each folder"), propsBox);
58 m_globalProps = new QRadioButton(i18n("Use common view properties for all folders"), propsBox);
59
60 QVBoxLayout* propsBoxLayout = new QVBoxLayout(propsBox);
61 propsBoxLayout->addWidget(m_localProps);
62 propsBoxLayout->addWidget(m_globalProps);
63
64 // create 'File Previews' box
65 QGroupBox* previewBox = new QGroupBox(i18n("File Previews"), this);
66
67 QLabel* maxFileSize = new QLabel(i18n("Maximum file size:"), previewBox);
68
69 KHBox* vBox = new KHBox(previewBox);
70 vBox->setSpacing(spacing);
71 m_maxPreviewSize = new QSlider(Qt::Horizontal, vBox);
72
73 m_spinBox = new QSpinBox(vBox);
74
75 connect(m_maxPreviewSize, SIGNAL(valueChanged(int)),
76 m_spinBox, SLOT(setValue(int)));
77 connect(m_spinBox, SIGNAL(valueChanged(int)),
78 m_maxPreviewSize, SLOT(setValue(int)));
79
80 QVBoxLayout* previewBoxLayout = new QVBoxLayout(previewBox);
81 previewBoxLayout->addWidget(maxFileSize);
82 previewBoxLayout->addWidget(vBox);
83
84 // Add a dummy widget with no restriction regarding
85 // a vertical resizing. This assures that the dialog layout
86 // is not stretched vertically.
87 new QWidget(this);
88
89 loadSettings();
90 }
91
92
93 GeneralViewSettingsPage::~GeneralViewSettingsPage()
94 {
95 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
96 settings->setDefaults();
97
98 loadSettings();
99 }
100
101 void GeneralViewSettingsPage::applySettings()
102 {
103 const KUrl& url = m_mainWindow->activeView()->url();
104 ViewProperties props(url); // read current view properties
105
106 const bool useGlobalProps = m_globalProps->isChecked();
107
108 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
109 settings->setGlobalViewProps(useGlobalProps);
110
111 if (useGlobalProps) {
112 // Remember the global view properties by applying the current view properties.
113 // It is important that GeneralSettings::globalViewProps() is set before
114 // the class ViewProperties is used, as ViewProperties uses this setting
115 // to find the destination folder for storing the view properties.
116 ViewProperties globalProps(url);
117 globalProps.setDirProperties(props);
118 }
119
120 KConfigGroup globalConfig(KGlobal::config(), "PreviewSettings");
121 const int byteCount = m_maxPreviewSize->value() * 1024 * 1024; // value() returns size in MB
122 globalConfig.writeEntry("MaximumSize",
123 byteCount,
124 KConfigBase::Normal | KConfigBase::Global);
125 globalConfig.sync();
126 }
127
128 void GeneralViewSettingsPage::restoreDefaults()
129 {
130 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
131 settings->setDefaults();
132 loadSettings();
133 }
134
135 void GeneralViewSettingsPage::loadSettings()
136 {
137 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
138 if (settings->globalViewProps()) {
139 m_globalProps->setChecked(true);
140 } else {
141 m_localProps->setChecked(true);
142 }
143
144 const int min = 1; // MB
145 const int max = 100; // MB
146 m_maxPreviewSize->setRange(min, max);
147 m_maxPreviewSize->setPageStep(10);
148 m_maxPreviewSize->setSingleStep(1);
149 m_maxPreviewSize->setTickPosition(QSlider::TicksBelow);
150
151 KConfigGroup globalConfig(KGlobal::config(), "PreviewSettings");
152 const int maxByteSize = globalConfig.readEntry("MaximumSize", 1024 * 1024 /* 1 MB */);
153 int maxMByteSize = maxByteSize / (1024 * 1024);
154 if (maxMByteSize < 1) {
155 maxMByteSize = 1;
156 } else if (maxMByteSize > max) {
157 maxMByteSize = max;
158 }
159 m_maxPreviewSize->setValue(maxMByteSize);
160
161 m_spinBox->setRange(min, max);
162 m_spinBox->setSingleStep(1);
163 m_spinBox->setSuffix(" MB");
164 m_spinBox->setValue(m_maxPreviewSize->value());
165 }
166
167 #include "generalviewsettingspage.moc"