]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/previewssettingspage.cpp
Added the Trash KCM to Dolphin, it's visible in the Settings Dialog, in the 'Trash...
[dolphin.git] / src / settings / previewssettingspage.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 "previewssettingspage.h"
21 #include "dolphinsettings.h"
22
23 #include "dolphin_generalsettings.h"
24
25 #include <QCheckBox>
26 #include <QGroupBox>
27 #include <QLabel>
28 #include <QRadioButton>
29 #include <QSlider>
30 #include <QSpinBox>
31 #include <QBoxLayout>
32
33 #include <kconfiggroup.h>
34 #include <kdialog.h>
35 #include <kglobal.h>
36 #include <klocale.h>
37 #include <khbox.h>
38 #include <kvbox.h>
39
40 // default settings
41 const bool USE_THUMBNAILS = true;
42 const int MAX_PREVIEW_SIZE = 5; // 5 MB
43
44 PreviewsSettingsPage::PreviewsSettingsPage(QWidget* parent) :
45 SettingsPageBase(parent),
46 m_maxPreviewSize(0),
47 m_spinBox(0),
48 m_useFileThumbnails(0)
49 {
50 KVBox* vBox = new KVBox(this);
51 vBox->setSpacing(KDialog::spacingHint());
52 vBox->setMargin(KDialog::marginHint());
53
54 new QLabel("TODO: a major rewrite of this dialog will be done in 4.3", vBox);
55
56 KHBox* hBox = new KHBox(vBox);
57 hBox->setSpacing(KDialog::spacingHint());
58
59 new QLabel(i18nc("@label:slider", "Maximum file size:"), hBox);
60 m_maxPreviewSize = new QSlider(Qt::Horizontal, hBox);
61 m_maxPreviewSize->setPageStep(10);
62 m_maxPreviewSize->setSingleStep(1);
63 m_maxPreviewSize->setTickPosition(QSlider::TicksBelow);
64 m_maxPreviewSize->setRange(1, 100); /* MB */
65
66 m_spinBox = new QSpinBox(hBox);
67 m_spinBox->setSingleStep(1);
68 m_spinBox->setSuffix(" MB");
69 m_spinBox->setRange(1, 100); /* MB */
70
71 connect(m_maxPreviewSize, SIGNAL(valueChanged(int)),
72 m_spinBox, SLOT(setValue(int)));
73 connect(m_spinBox, SIGNAL(valueChanged(int)),
74 m_maxPreviewSize, SLOT(setValue(int)));
75
76 connect(m_maxPreviewSize, SIGNAL(valueChanged(int)),
77 this, SIGNAL(changed()));
78 connect(m_spinBox, SIGNAL(valueChanged(int)),
79 this, SIGNAL(changed()));
80
81 m_useFileThumbnails = new QCheckBox(i18nc("@option:check", "Use thumbnails embedded in files"), vBox);
82 connect(m_useFileThumbnails, SIGNAL(toggled(bool)), this, SIGNAL(changed()));
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(vBox);
88
89 loadSettings();
90 }
91
92
93 PreviewsSettingsPage::~PreviewsSettingsPage()
94 {
95 }
96
97 void PreviewsSettingsPage::applySettings()
98 {
99 KConfigGroup globalConfig(KGlobal::config(), "PreviewSettings");
100 const int byteCount = m_maxPreviewSize->value() * 1024 * 1024; // value() returns size in MB
101 globalConfig.writeEntry("MaximumSize",
102 byteCount,
103 KConfigBase::Normal | KConfigBase::Global);
104 globalConfig.writeEntry("UseFileThumbnails",
105 m_useFileThumbnails->isChecked(),
106 KConfigBase::Normal | KConfigBase::Global);
107 globalConfig.sync();
108 }
109
110 void PreviewsSettingsPage::restoreDefaults()
111 {
112 m_maxPreviewSize->setValue(MAX_PREVIEW_SIZE);
113 m_useFileThumbnails->setChecked(USE_THUMBNAILS);
114 }
115
116 void PreviewsSettingsPage::loadSettings()
117 {
118 const int min = 1; // MB
119 const int max = 100; // MB
120
121 KConfigGroup globalConfig(KGlobal::config(), "PreviewSettings");
122 // TODO: The default value of 5 MB must match with the default value inside
123 // kdelibs/kio/kio/previewjob.cpp. Maybe a static getter method in PreviewJob
124 // should be added for getting the default size?
125 const int maxByteSize = globalConfig.readEntry("MaximumSize", MAX_PREVIEW_SIZE * 1024 * 1024);
126 int maxMByteSize = maxByteSize / (1024 * 1024);
127 if (maxMByteSize < min) {
128 maxMByteSize = min;
129 } else if (maxMByteSize > max) {
130 maxMByteSize = max;
131 }
132 m_maxPreviewSize->setValue(maxMByteSize);
133
134 const bool useFileThumbnails = globalConfig.readEntry("UseFileThumbnails", USE_THUMBNAILS);
135 m_useFileThumbnails->setChecked(useFileThumbnails);
136 }
137
138 #include "previewssettingspage.moc"