]> cloud.milkyroute.net Git - dolphin.git/blob - src/settings/kcm/kcmdolphinviewmodes.cpp
9b4aa0dc72c188adc675338f93d25dc6408f5b27
[dolphin.git] / src / settings / kcm / kcmdolphinviewmodes.cpp
1 /***************************************************************************
2 * Copyright (C) 2008 by Peter Penz <peter.penz19@gmail.com> *
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 "kcmdolphinviewmodes.h"
21
22 #include <KLocalizedString>
23 #include <KPluginFactory>
24 #include <KPluginLoader>
25 #include <QIcon>
26
27 #include <settings/viewmodes/viewsettingstab.h>
28
29 #include <QDBusConnection>
30 #include <QDBusMessage>
31 #include <QPushButton>
32 #include <QVBoxLayout>
33 #include <QTabWidget>
34
35 K_PLUGIN_FACTORY(KCMDolphinViewModesConfigFactory, registerPlugin<DolphinViewModesConfigModule>(QStringLiteral("dolphinviewmodes"));)
36 K_EXPORT_PLUGIN(KCMDolphinViewModesConfigFactory("kcmdolphinviewmodes"))
37
38 DolphinViewModesConfigModule::DolphinViewModesConfigModule(QWidget* parent, const QVariantList& args) :
39 KCModule(parent),
40 m_tabs()
41 {
42 Q_UNUSED(args);
43
44 setButtons(KCModule::Default | KCModule::Help);
45
46 QVBoxLayout* topLayout = new QVBoxLayout(this);
47 topLayout->setMargin(0);
48
49 QTabWidget* tabWidget = new QTabWidget(this);
50
51 // Initialize 'Icons' tab
52 ViewSettingsTab* iconsTab = new ViewSettingsTab(ViewSettingsTab::IconsMode, tabWidget);
53 tabWidget->addTab(iconsTab, QIcon::fromTheme(QStringLiteral("view-list-icons")), i18nc("@title:tab", "Icons"));
54 connect(iconsTab, &ViewSettingsTab::changed, this, &DolphinViewModesConfigModule::viewModeChanged);
55
56 // Initialize 'Compact' tab
57 ViewSettingsTab* compactTab = new ViewSettingsTab(ViewSettingsTab::CompactMode, tabWidget);
58 tabWidget->addTab(compactTab, QIcon::fromTheme(QStringLiteral("view-list-details")), i18nc("@title:tab", "Compact"));
59 connect(compactTab, &ViewSettingsTab::changed, this, &DolphinViewModesConfigModule::viewModeChanged);
60
61 // Initialize 'Details' tab
62 ViewSettingsTab* detailsTab = new ViewSettingsTab(ViewSettingsTab::DetailsMode, tabWidget);
63 tabWidget->addTab(detailsTab, QIcon::fromTheme(QStringLiteral("view-list-tree")), i18nc("@title:tab", "Details"));
64 connect(detailsTab, &ViewSettingsTab::changed, this, &DolphinViewModesConfigModule::viewModeChanged);
65
66 m_tabs.append(iconsTab);
67 m_tabs.append(compactTab);
68 m_tabs.append(detailsTab);
69
70 topLayout->addWidget(tabWidget, 0, 0);
71 }
72
73 DolphinViewModesConfigModule::~DolphinViewModesConfigModule()
74 {
75 }
76
77 void DolphinViewModesConfigModule::save()
78 {
79 foreach (ViewSettingsTab* tab, m_tabs) {
80 tab->applySettings();
81 }
82 reparseConfiguration();
83 }
84
85 void DolphinViewModesConfigModule::defaults()
86 {
87 foreach (ViewSettingsTab* tab, m_tabs) {
88 tab->restoreDefaultSettings();
89 }
90 reparseConfiguration();
91 }
92
93 void DolphinViewModesConfigModule::reparseConfiguration()
94 {
95 QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/KonqMain"), QStringLiteral("org.kde.Konqueror.Main"), QStringLiteral("reparseConfiguration"));
96 QDBusConnection::sessionBus().send(message);
97 }
98
99 void DolphinViewModesConfigModule::viewModeChanged()
100 {
101 emit changed(true);
102 }
103
104 #include "kcmdolphinviewmodes.moc"