]> cloud.milkyroute.net Git - dolphin.git/blob - src/generalviewsettingspage.cpp
Move the pasteIntoFolder() method from the contextmenu into DolphinView. This allows...
[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(const KUrl& url,
43 QWidget* parent) :
44 ViewSettingsPageBase(parent),
45 m_url(url),
46 m_localProps(0),
47 m_globalProps(0),
48 m_maxPreviewSize(0),
49 m_spinBox(0),
50 m_useFileThumbnails(0),
51 m_showSelectionToggle(0)
52 {
53 const int spacing = KDialog::spacingHint();
54 const int margin = KDialog::marginHint();
55 const QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
56
57 setSpacing(spacing);
58 setMargin(margin);
59
60 QGroupBox* propsBox = new QGroupBox(i18nc("@title:group", "View Properties"), this);
61
62 m_localProps = new QRadioButton(i18nc("@option:radio", "Remember view properties for each folder"), propsBox);
63 connect(m_localProps, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
64
65 m_globalProps = new QRadioButton(i18nc("@option:radio", "Use common view properties for all folders"), propsBox);
66 connect(m_globalProps, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
67
68 QVBoxLayout* propsBoxLayout = new QVBoxLayout(propsBox);
69 propsBoxLayout->addWidget(m_localProps);
70 propsBoxLayout->addWidget(m_globalProps);
71
72 // create 'File Previews' box
73 QGroupBox* previewBox = new QGroupBox(i18nc("@title:group", "File Previews"), this);
74
75 KHBox* vBox = new KHBox(previewBox);
76 vBox->setSpacing(spacing);
77
78 new QLabel(i18nc("@label:slider", "Maximum file size:"), vBox);
79 m_maxPreviewSize = new QSlider(Qt::Horizontal, vBox);
80
81 m_spinBox = new QSpinBox(vBox);
82
83 connect(m_maxPreviewSize, SIGNAL(valueChanged(int)),
84 m_spinBox, SLOT(setValue(int)));
85 connect(m_spinBox, SIGNAL(valueChanged(int)),
86 m_maxPreviewSize, SLOT(setValue(int)));
87
88 connect(m_maxPreviewSize, SIGNAL(valueChanged(int)),
89 this, SIGNAL(changed()));
90 connect(m_spinBox, SIGNAL(valueChanged(int)),
91 this, SIGNAL(changed()));
92
93 m_useFileThumbnails = new QCheckBox(i18nc("@option:check", "Use thumbnails embedded in files"), previewBox);
94 connect(m_useFileThumbnails, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
95
96 QVBoxLayout* previewBoxLayout = new QVBoxLayout(previewBox);
97 previewBoxLayout->addWidget(vBox);
98 previewBoxLayout->addWidget(m_useFileThumbnails);
99
100 m_showSelectionToggle = new QCheckBox(i18nc("@option:check", "Show selection toggle"), this);
101 connect(m_showSelectionToggle, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
102
103 // Add a dummy widget with no restriction regarding
104 // a vertical resizing. This assures that the dialog layout
105 // is not stretched vertically.
106 new QWidget(this);
107
108 loadSettings();
109 }
110
111
112 GeneralViewSettingsPage::~GeneralViewSettingsPage()
113 {
114 }
115
116 void GeneralViewSettingsPage::applySettings()
117 {
118 ViewProperties props(m_url); // read current view properties
119
120 const bool useGlobalProps = m_globalProps->isChecked();
121
122 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
123 settings->setGlobalViewProps(useGlobalProps);
124
125 if (useGlobalProps) {
126 // Remember the global view properties by applying the current view properties.
127 // It is important that GeneralSettings::globalViewProps() is set before
128 // the class ViewProperties is used, as ViewProperties uses this setting
129 // to find the destination folder for storing the view properties.
130 ViewProperties globalProps(m_url);
131 globalProps.setDirProperties(props);
132 }
133
134 KConfigGroup globalConfig(KGlobal::config(), "PreviewSettings");
135 const int byteCount = m_maxPreviewSize->value() * 1024 * 1024; // value() returns size in MB
136 globalConfig.writeEntry("MaximumSize",
137 byteCount,
138 KConfigBase::Normal | KConfigBase::Global);
139 globalConfig.writeEntry("UseFileThumbnails",
140 m_useFileThumbnails->isChecked(),
141 KConfigBase::Normal | KConfigBase::Global);
142 globalConfig.sync();
143
144 settings->setShowSelectionToggle(m_showSelectionToggle->isChecked());
145 }
146
147 void GeneralViewSettingsPage::restoreDefaults()
148 {
149 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
150 settings->setDefaults();
151 loadSettings();
152 }
153
154 void GeneralViewSettingsPage::loadSettings()
155 {
156 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
157 if (settings->globalViewProps()) {
158 m_globalProps->setChecked(true);
159 } else {
160 m_localProps->setChecked(true);
161 }
162
163 const int min = 1; // MB
164 const int max = 100; // MB
165 m_maxPreviewSize->setRange(min, max);
166 m_maxPreviewSize->setPageStep(10);
167 m_maxPreviewSize->setSingleStep(1);
168 m_maxPreviewSize->setTickPosition(QSlider::TicksBelow);
169
170 KConfigGroup globalConfig(KGlobal::config(), "PreviewSettings");
171 // TODO: The default value of 5 MB must match with the default value inside
172 // kdelibs/kio/kio/previewjob.cpp. Maybe a static getter method in PreviewJob
173 // should be added for getting the default size?
174 const int maxByteSize = globalConfig.readEntry("MaximumSize", 5 * 1024 * 1024 /* 5 MB */);
175 int maxMByteSize = maxByteSize / (1024 * 1024);
176 if (maxMByteSize < 1) {
177 maxMByteSize = 1;
178 } else if (maxMByteSize > max) {
179 maxMByteSize = max;
180 }
181
182 m_spinBox->setRange(min, max);
183 m_spinBox->setSingleStep(1);
184 m_spinBox->setSuffix(" MB");
185
186 m_maxPreviewSize->setValue(maxMByteSize);
187 m_spinBox->setValue(m_maxPreviewSize->value());
188
189 const bool useFileThumbnails = globalConfig.readEntry("UseFileThumbnails", true);
190 m_useFileThumbnails->setChecked(useFileThumbnails);
191
192 m_showSelectionToggle->setChecked(settings->showSelectionToggle());
193 }
194
195 #include "generalviewsettingspage.moc"