]> cloud.milkyroute.net Git - dolphin.git/blob - src/generalviewsettingspage.cpp
Adapt to new konsole api
[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 <QLabel>
27 #include <QGroupBox>
28 #include <QRadioButton>
29 #include <QSlider>
30 #include <QSpinBox>
31 #include <QVBoxLayout>
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 {
47 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
48 Q_ASSERT(settings != 0);
49
50 const int spacing = KDialog::spacingHint();
51 const int margin = KDialog::marginHint();
52 const QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
53
54 setSpacing(spacing);
55 setMargin(margin);
56
57 QGroupBox* propsBox = new QGroupBox(i18n("View Properties"), this);
58
59 m_localProps = new QRadioButton(i18n("Remember view properties for each folder"), propsBox);
60 m_globalProps = new QRadioButton(i18n("Use common view properties for all folders"), propsBox);
61 if (settings->globalViewProps()) {
62 m_globalProps->setChecked(true);
63 } else {
64 m_localProps->setChecked(true);
65 }
66
67 QVBoxLayout* propsBoxLayout = new QVBoxLayout(propsBox);
68 propsBoxLayout->addWidget(m_localProps);
69 propsBoxLayout->addWidget(m_globalProps);
70
71 // create 'File Previews' box
72 QGroupBox* previewBox = new QGroupBox(i18n("File Previews"), this);
73
74 QLabel* maxFileSize = new QLabel(i18n("Maximum file size:"), previewBox);
75
76 KHBox* vBox = new KHBox(previewBox);
77 vBox->setSpacing(spacing);
78
79 const int min = 1; // MB
80 const int max = 100; // MB
81 m_maxPreviewSize = new QSlider(Qt::Horizontal, vBox);
82 m_maxPreviewSize->setRange(min, max);
83 m_maxPreviewSize->setPageStep(10);
84 m_maxPreviewSize->setSingleStep(1);
85 m_maxPreviewSize->setTickPosition(QSlider::TicksBelow);
86
87 KConfigGroup globalConfig(KGlobal::config(), "PreviewSettings");
88 const int maxByteSize = globalConfig.readEntry("MaximumSize", 1024 * 1024 /* 1 MB */);
89 int maxMByteSize = maxByteSize / (1024 * 1024);
90 if (maxMByteSize < 1) {
91 maxMByteSize = 1;
92 } else if (maxMByteSize > max) {
93 maxMByteSize = max;
94 }
95 m_maxPreviewSize->setValue(maxMByteSize);
96
97 QSpinBox* spinBox = new QSpinBox(vBox);
98 spinBox->setRange(min, max);
99 spinBox->setSingleStep(1);
100 spinBox->setSuffix(" MB");
101 spinBox->setValue(m_maxPreviewSize->value());
102
103 connect(m_maxPreviewSize, SIGNAL(valueChanged(int)),
104 spinBox, SLOT(setValue(int)));
105 connect(spinBox, SIGNAL(valueChanged(int)),
106 m_maxPreviewSize, SLOT(setValue(int)));
107
108 QVBoxLayout* previewBoxLayout = new QVBoxLayout(previewBox);
109 previewBoxLayout->addWidget(maxFileSize);
110 previewBoxLayout->addWidget(vBox);
111
112 // Add a dummy widget with no restriction regarding
113 // a vertical resizing. This assures that the dialog layout
114 // is not stretched vertically.
115 new QWidget(this);
116 }
117
118
119 GeneralViewSettingsPage::~GeneralViewSettingsPage()
120 {}
121
122 void GeneralViewSettingsPage::applySettings()
123 {
124 const KUrl& url = m_mainWindow->activeView()->url();
125 ViewProperties props(url); // read current view properties
126
127 const bool useGlobalProps = m_globalProps->isChecked();
128
129 GeneralSettings* settings = DolphinSettings::instance().generalSettings();
130 Q_ASSERT(settings != 0);
131 settings->setGlobalViewProps(useGlobalProps);
132
133 if (useGlobalProps) {
134 // Remember the global view properties by applying the current view properties.
135 // It is important that GeneralSettings::globalViewProps() is set before
136 // the class ViewProperties is used, as ViewProperties uses this setting
137 // to find the destination folder for storing the view properties.
138 ViewProperties globalProps(url);
139 globalProps.setDirProperties(props);
140 }
141
142 KConfigGroup globalConfig(KGlobal::config(), "PreviewSettings");
143 const int byteCount = m_maxPreviewSize->value() * 1024 * 1024; // value() returns size in MB
144 globalConfig.writeEntry("MaximumSize",
145 byteCount,
146 KConfigBase::Normal | KConfigBase::Global);
147 globalConfig.sync();
148 }
149
150 #include "generalviewsettingspage.moc"