1 /* This file is part of the KDE project
2 Copyright (C) 2008 David Faure <faure@kde.org>
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 ( at
7 your option ) version 3 or, at the discretion of KDE e.V. ( which shall
8 act as a proxy as in section 14 of the GPLv3 ), any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; see the file COPYING. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
21 #include "componentchooserfilemanager.h"
22 #include <kbuildsycocaprogressdialog.h>
25 #include <kmimetypetrader.h>
26 #include <kopenwithdialog.h>
27 #include <kglobalsettings.h>
28 #include <kconfiggroup.h>
30 CfgFileManager::CfgFileManager(QWidget
*parent
)
31 : QWidget(parent
), Ui::FileManagerConfig_UI(),CfgPlugin()
34 connect(btnSelectFileManager
,SIGNAL(clicked()),this, SLOT(slotAddFileManager()));
37 CfgFileManager::~CfgFileManager() {
40 void CfgFileManager::configChanged()
45 void CfgFileManager::defaults()
50 static KService::List
appOffers()
52 return KMimeTypeTrader::self()->query("inode/directory", "Application");
55 void CfgFileManager::load(KConfig
*) {
56 qDeleteAll(mDynamicWidgets
);
57 mDynamicWidgets
.clear();
58 const KService::List apps
= appOffers();
60 Q_FOREACH(const KService::Ptr
& service
, apps
)
62 QRadioButton
* button
= new QRadioButton(service
->name(), this);
63 connect(button
,SIGNAL(toggled(bool)),this,SLOT(configChanged()));
64 button
->setProperty("storageId", service
->storageId());
65 radioLayout
->addWidget(button
);
67 button
->setChecked(true);
70 mDynamicWidgets
<< button
;
76 void CfgFileManager::save(KConfig
*)
79 Q_FOREACH(QRadioButton
* button
, qFindChildren
<QRadioButton
*>(this)) {
80 if (button
->isChecked()) {
81 storageId
= button
->property("storageId").toString();
85 kDebug() << storageId
;
86 if (!storageId
.isEmpty()) {
87 // This is taken from filetypes/mimetypedata.cpp
88 KSharedConfig::Ptr profile
= KSharedConfig::openConfig("mimeapps.list", KConfig::NoGlobals
, "xdgdata-apps");
89 if (!profile
->isConfigWritable(true)) // warn user if mimeapps.list is root-owned (#155126/#94504)
91 KConfigGroup
addedApps(profile
, "Added Associations");
92 QStringList userApps
= addedApps
.readXdgListEntry("inode/directory");
93 userApps
.removeAll(storageId
); // remove if present, to make it first in the list
94 userApps
.prepend(storageId
);
95 addedApps
.writeXdgListEntry("inode/directory", userApps
);
97 KBuildSycocaProgressDialog::rebuildKSycoca(this);
103 void CfgFileManager::slotAddFileManager()
106 proc
<< "keditfiletype";
107 proc
<< "inode/directory";
108 if (proc
.execute() == 0) {