add more spacing
[personal-kdebase.git] / runtime / kcontrol / componentchooser / componentchooserfilemanager.cpp
blob4c730b0198555e04383b5c0f72cb17da7f945c22
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>
23 #include <kdebug.h>
24 #include <kprocess.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()
33 setupUi(this);
34 connect(btnSelectFileManager,SIGNAL(clicked()),this, SLOT(slotAddFileManager()));
37 CfgFileManager::~CfgFileManager() {
40 void CfgFileManager::configChanged()
42 emit changed(true);
45 void CfgFileManager::defaults()
47 load(0);
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();
59 bool first = true;
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);
66 if (first) {
67 button->setChecked(true);
68 first = false;
70 mDynamicWidgets << button;
73 emit changed(false);
76 void CfgFileManager::save(KConfig *)
78 QString storageId;
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)
90 return;
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);
96 profile->sync();
97 KBuildSycocaProgressDialog::rebuildKSycoca(this);
100 emit changed(false);
103 void CfgFileManager::slotAddFileManager()
105 KProcess proc;
106 proc << "keditfiletype";
107 proc << "inode/directory";
108 if (proc.execute() == 0) {
109 load(0);