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