behaviour.cpp 5.21 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/**
 *  Copyright (c) 2001 David Faure <david@mandrakesoft.com>
 *
 *  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
Dirk Mueller's avatar
Dirk Mueller committed
16
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17
 */
David Faure's avatar
David Faure committed
18

19
// Behaviour options for konqueror
20

21 22 23 24
// Own
#include "behaviour.h"

// Qt
25 26
#include <QDBusConnection>
#include <QDBusMessage>
27 28 29
#include <QCheckBox>
#include <QGroupBox>
#include <QLabel>
Laurent Montel's avatar
Laurent Montel committed
30
#include <QVBoxLayout>
31

32
// KDE
Laurent Montel's avatar
Laurent Montel committed
33
#include <KLocalizedString>
Laurent Montel's avatar
Laurent Montel committed
34

35
#include <kurlrequester.h>
36
#include <kconfiggroup.h>
Laurent Montel's avatar
Laurent Montel committed
37
#include <QStandardPaths>
38
#include <KSharedConfig>
39

40
// Local
41
#include "konqkcmfactory.h"
Frans Englich's avatar
 
Frans Englich committed
42

Matthias Kretz's avatar
Matthias Kretz committed
43
KBehaviourOptions::KBehaviourOptions(QWidget *parent, const QVariantList &)
44
    : KCModule(parent)
45 46
    , g_pConfig(KSharedConfig::openConfig(QStringLiteral("konquerorrc"), KConfig::IncludeGlobals))
    , groupname(QStringLiteral("FMSettings"))
David Faure's avatar
David Faure committed
47
{
Urs Wolfer's avatar
Urs Wolfer committed
48
    setQuickHelp(i18n("<h1>Konqueror Behavior</h1> You can configure how Konqueror behaves as a file manager here."));
49

Urs Wolfer's avatar
Urs Wolfer committed
50
    QVBoxLayout *mainLayout = new QVBoxLayout(this);
51

52
    QGroupBox *miscGb = new QGroupBox(i18n("Misc Options"), this);
Urs Wolfer's avatar
Urs Wolfer committed
53 54
    QHBoxLayout *miscHLayout = new QHBoxLayout;
    QVBoxLayout *miscLayout = new QVBoxLayout;
55

Urs Wolfer's avatar
Urs Wolfer committed
56 57
    winPixmap = new QLabel(this);
    winPixmap->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
58
    winPixmap->setPixmap(QPixmap(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kcontrol/pics/onlyone.png"))));
Urs Wolfer's avatar
Urs Wolfer committed
59
    winPixmap->setFixedSize(winPixmap->sizeHint());
60

Urs Wolfer's avatar
Urs Wolfer committed
61
    cbNewWin = new QCheckBox(i18n("Open folders in separate &windows"), this);
62
    cbNewWin->setToolTip(i18n("If this option is checked, Konqueror will open a new window when "
Urs Wolfer's avatar
Urs Wolfer committed
63
                                "you open a folder, rather than showing that folder's contents in the current window."));
64
    connect(cbNewWin, &QAbstractButton::toggled, this, &KBehaviourOptions::markAsChanged);
Laurent Montel's avatar
Laurent Montel committed
65
    connect(cbNewWin, &QAbstractButton::toggled, this, &KBehaviourOptions::updateWinPixmap);
66

Urs Wolfer's avatar
Urs Wolfer committed
67
    miscLayout->addWidget(cbNewWin);
68

Urs Wolfer's avatar
Urs Wolfer committed
69
    QHBoxLayout *previewLayout = new QHBoxLayout;
70 71 72
    QWidget *spacer = new QWidget(this);
    spacer->setMinimumSize(20, 0);
    spacer->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum);
73

Urs Wolfer's avatar
Urs Wolfer committed
74 75 76
    previewLayout->addWidget(spacer);

    miscLayout->addLayout(previewLayout);
77

Urs Wolfer's avatar
Urs Wolfer committed
78 79
    miscHLayout->addLayout(miscLayout);
    miscHLayout->addWidget(winPixmap);
80

Urs Wolfer's avatar
Urs Wolfer committed
81 82 83 84
    miscGb->setLayout(miscHLayout);

    mainLayout->addWidget(miscGb);

Burkhard Lück's avatar
Burkhard Lück committed
85
    cbShowDeleteCommand = new QCheckBox(i18n("Show 'Delete' me&nu entries which bypass the trashcan"), this);
86
    mainLayout->addWidget(cbShowDeleteCommand);
87
    connect(cbShowDeleteCommand, &QAbstractButton::toggled, this, &KBehaviourOptions::markAsChanged);
88

89
    cbShowDeleteCommand->setToolTip(i18n("Check this if you want 'Delete' menu commands to be displayed "
90
                                           "on the desktop and in the file manager's menus and context menus. "
91 92 93
                                           "You can always delete files by holding the Shift key "
                                           "while calling 'Move to Trash'."));

Urs Wolfer's avatar
Urs Wolfer committed
94
    mainLayout->addStretch();
David Faure's avatar
David Faure committed
95 96
}

Laurent Montel's avatar
Laurent Montel committed
97 98 99 100
KBehaviourOptions::~KBehaviourOptions()
{
}

101
void KBehaviourOptions::load()
David Faure's avatar
David Faure committed
102
{
103
    KConfigGroup cg(g_pConfig, groupname);
104
    cbNewWin->setChecked(cg.readEntry("AlwaysNewWin", false));
105 106
    updateWinPixmap(cbNewWin->isChecked());

107
    KSharedConfig::Ptr globalconfig = KSharedConfig::openConfig(QStringLiteral("kdeglobals"), KConfig::NoGlobals);
108
    KConfigGroup cg2(globalconfig, "KDE");
109
    cbShowDeleteCommand->setChecked(cg2.readEntry("ShowDeleteCommand", false));
David Faure's avatar
David Faure committed
110 111
}

112
void KBehaviourOptions::defaults()
David Faure's avatar
David Faure committed
113
{
114
    cbNewWin->setChecked(false);
David Faure's avatar
David Faure committed
115

116
    cbShowDeleteCommand->setChecked(false);
David Faure's avatar
David Faure committed
117 118
}

119
void KBehaviourOptions::save()
David Faure's avatar
David Faure committed
120
{
121
    KConfigGroup cg(g_pConfig, groupname);
122

123
    cg.writeEntry("AlwaysNewWin", cbNewWin->isChecked());
124

125
    KSharedConfig::Ptr globalconfig = KSharedConfig::openConfig(QStringLiteral("kdeglobals"), KConfig::NoGlobals);
126
    KConfigGroup cg2(globalconfig, "KDE");
127
    cg2.writeEntry("ShowDeleteCommand", cbShowDeleteCommand->isChecked());
128
    cg2.sync();
Laurent Montel's avatar
Laurent Montel committed
129

David Faure's avatar
David Faure committed
130 131
    // Send signal to all konqueror instances
    QDBusMessage message =
132
        QDBusMessage::createSignal(QStringLiteral("/KonqMain"), QStringLiteral("org.kde.Konqueror.Main"), QStringLiteral("reparseConfiguration"));
Stephan Kulow's avatar
Stephan Kulow committed
133
    QDBusConnection::sessionBus().send(message);
David Faure's avatar
David Faure committed
134 135
}

136 137
void KBehaviourOptions::updateWinPixmap(bool b)
{
138
    if (b) {
139
        winPixmap->setPixmap(QPixmap(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kcontrol/pics/overlapping.png"))));
140
    } else {
141
        winPixmap->setPixmap(QPixmap(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kcontrol/pics/onlyone.png"))));
142
    }
143
}
144