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