kcmdolphinviewmodes.cpp 4.05 KB
Newer Older
1
/***************************************************************************
2
 *   Copyright (C) 2008 by Peter Penz <peter.penz19@gmail.com>             *
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
 ***************************************************************************/

20
#include "kcmdolphinviewmodes.h"
21

Roman Inflianskas's avatar
Roman Inflianskas committed
22
23
#include "settings/viewmodes/viewsettingstab.h"

Laurent Montel's avatar
Laurent Montel committed
24
#include <KLocalizedString>
Peter Penz's avatar
Peter Penz committed
25
26
#include <KPluginFactory>
#include <KPluginLoader>
27

28
29
#include <QDBusConnection>
#include <QDBusMessage>
Roman Inflianskas's avatar
Roman Inflianskas committed
30
#include <QIcon>
31
#include <QTabWidget>
Roman Inflianskas's avatar
Roman Inflianskas committed
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),
38
    m_tabs()
39
{
40
    Q_UNUSED(args)
41
42
43
44

    setButtons(KCModule::Default | KCModule::Help);

    QVBoxLayout* topLayout = new QVBoxLayout(this);
Laurent Montel's avatar
Laurent Montel committed
45
    topLayout->setContentsMargins(0, 0, 0, 0);
46

47
    QTabWidget* tabWidget = new QTabWidget(this);
48

49
50
    // Initialize 'Icons' tab
    ViewSettingsTab* iconsTab = new ViewSettingsTab(ViewSettingsTab::IconsMode, tabWidget);
51
    tabWidget->addTab(iconsTab, QIcon::fromTheme(QStringLiteral("view-list-icons")), i18nc("@title:tab", "Icons"));
52
    connect(iconsTab, &ViewSettingsTab::changed, this, &DolphinViewModesConfigModule::viewModeChanged);
53

54
55
    // Initialize 'Compact' tab
    ViewSettingsTab* compactTab = new ViewSettingsTab(ViewSettingsTab::CompactMode, tabWidget);
56
    tabWidget->addTab(compactTab, QIcon::fromTheme(QStringLiteral("view-list-details")), i18nc("@title:tab", "Compact"));
57
    connect(compactTab, &ViewSettingsTab::changed, this, &DolphinViewModesConfigModule::viewModeChanged);
58

59
60
    // Initialize 'Details' tab
    ViewSettingsTab* detailsTab = new ViewSettingsTab(ViewSettingsTab::DetailsMode, tabWidget);
61
    tabWidget->addTab(detailsTab, QIcon::fromTheme(QStringLiteral("view-list-tree")), i18nc("@title:tab", "Details"));
62
    connect(detailsTab, &ViewSettingsTab::changed, this, &DolphinViewModesConfigModule::viewModeChanged);
63

64
65
66
    m_tabs.append(iconsTab);
    m_tabs.append(compactTab);
    m_tabs.append(detailsTab);
67

68
    topLayout->addWidget(tabWidget, 0, {});
69
70
}

71
DolphinViewModesConfigModule::~DolphinViewModesConfigModule()
72
73
74
{
}

75
void DolphinViewModesConfigModule::save()
76
{
77
78
    foreach (ViewSettingsTab* tab, m_tabs) {
        tab->applySettings();
79
    }
80
    reparseConfiguration();
81
82
}

83
void DolphinViewModesConfigModule::defaults()
84
{
85
86
    foreach (ViewSettingsTab* tab, m_tabs) {
        tab->restoreDefaultSettings();
87
    }
88
89
90
    reparseConfiguration();
}

91
void DolphinViewModesConfigModule::reparseConfiguration()
92
{
93
    QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/KonqMain"), QStringLiteral("org.kde.Konqueror.Main"), QStringLiteral("reparseConfiguration"));
94
    QDBusConnection::sessionBus().send(message);
95
96
}

97
98
99
100
101
void DolphinViewModesConfigModule::viewModeChanged()
{
    emit changed(true);
}

102
#include "kcmdolphinviewmodes.moc"