Changeset View
Changeset View
Standalone View
Standalone View
kcms/componentchooser/componentchooserfilemanager.cpp
Show First 20 Lines • Show All 44 Lines • ▼ Show 20 Line(s) | 44 | { | |||
---|---|---|---|---|---|
45 | emit changed(true); | 45 | emit changed(true); | ||
46 | } | 46 | } | ||
47 | 47 | | |||
48 | void CfgFileManager::defaults() | 48 | void CfgFileManager::defaults() | ||
49 | { | 49 | { | ||
50 | load(nullptr); | 50 | load(nullptr); | ||
51 | } | 51 | } | ||
52 | 52 | | |||
53 | bool CfgFileManager::isDefaults() const | ||||
54 | { | ||||
55 | if (!mDynamicRadioButtons.isEmpty()) { | ||||
56 | return !mDynamicRadioButtons.first()->isChecked(); | ||||
57 | } else { | ||||
58 | return false; | ||||
59 | } | ||||
60 | } | ||||
61 | | ||||
53 | static KService::List appOffers() | 62 | static KService::List appOffers() | ||
54 | { | 63 | { | ||
55 | return KMimeTypeTrader::self()->query(QStringLiteral("inode/directory"), QStringLiteral("Application")); | 64 | return KMimeTypeTrader::self()->query(QStringLiteral("inode/directory"), QStringLiteral("Application")); | ||
56 | } | 65 | } | ||
57 | 66 | | |||
58 | void CfgFileManager::load(KConfig *) { | 67 | void CfgFileManager::load(KConfig *) { | ||
59 | qDeleteAll(mDynamicWidgets); | 68 | qDeleteAll(mDynamicRadioButtons); | ||
60 | mDynamicWidgets.clear(); | 69 | mDynamicRadioButtons.clear(); | ||
61 | const KService::List apps = appOffers(); | 70 | const KService::List apps = appOffers(); | ||
62 | bool first = true; | 71 | bool first = true; | ||
63 | Q_FOREACH(const KService::Ptr& service, apps) | 72 | for (const KService::Ptr& service : apps) { | ||
ervin: Opening curly brace should be on the same line than for | |||||
ervin: Is it me or it's in fact not done? Also should have space before & not after. | |||||
64 | { | | |||
65 | QRadioButton* button = new QRadioButton(service->name(), this); | 73 | QRadioButton* button = new QRadioButton(service->name(), this); | ||
66 | connect(button, &QRadioButton::toggled, this, &CfgFileManager::configChanged); | 74 | connect(button, &QRadioButton::toggled, this, &CfgFileManager::configChanged); | ||
67 | button->setProperty("storageId", service->storageId()); | 75 | button->setProperty("storageId", service->storageId()); | ||
68 | radioLayout->addWidget(button); | 76 | radioLayout->addWidget(button); | ||
69 | if (first) { | 77 | if (first) { | ||
70 | button->setChecked(true); | 78 | button->setChecked(true); | ||
71 | first = false; | 79 | first = false; | ||
72 | } | 80 | } | ||
73 | mDynamicWidgets << button; | 81 | mDynamicRadioButtons << button; | ||
74 | } | 82 | } | ||
75 | 83 | | |||
76 | emit changed(false); | 84 | emit changed(false); | ||
77 | } | 85 | } | ||
78 | 86 | | |||
79 | static const char s_DefaultApplications[] = "Default Applications"; | 87 | static const char s_DefaultApplications[] = "Default Applications"; | ||
80 | static const char s_AddedAssociations[] = "Added Associations"; | 88 | static const char s_AddedAssociations[] = "Added Associations"; | ||
81 | static const char s_RemovedAssociations[] = "Removed Associations"; | | |||
82 | 89 | | |||
83 | void CfgFileManager::save(KConfig *) | 90 | void CfgFileManager::save(KConfig *) | ||
84 | { | 91 | { | ||
85 | QString storageId; | 92 | QString storageId; | ||
86 | Q_FOREACH(QRadioButton* button, qFindChildren<QRadioButton*>(this)) { | 93 | for (QRadioButton *button : qAsConst(mDynamicRadioButtons)) { | ||
ervin: Space before * not after | |||||
ervin: Is it me or it's not done in fact? | |||||
87 | if (button->isChecked()) { | 94 | if (button->isChecked()) { | ||
88 | storageId = button->property("storageId").toString(); | 95 | storageId = button->property("storageId").toString(); | ||
89 | } | 96 | } | ||
90 | } | 97 | } | ||
91 | 98 | | |||
92 | qDebug() << storageId; | | |||
93 | if (!storageId.isEmpty()) { | 99 | if (!storageId.isEmpty()) { | ||
94 | // This is taken from filetypes/mimetypedata.cpp | 100 | // This is taken from filetypes/mimetypedata.cpp | ||
95 | KSharedConfig::Ptr profile = KSharedConfig::openConfig(QStringLiteral("mimeapps.list"), KConfig::NoGlobals, QStandardPaths::GenericConfigLocation); | 101 | KSharedConfig::Ptr profile = KSharedConfig::openConfig(QStringLiteral("mimeapps.list"), KConfig::NoGlobals, QStandardPaths::GenericConfigLocation); | ||
96 | if (!profile->isConfigWritable(true)) // warn user if mimeapps.list is root-owned (#155126/#94504) | 102 | if (!profile->isConfigWritable(true)) // warn user if mimeapps.list is root-owned (#155126/#94504) | ||
97 | return; | 103 | return; | ||
98 | const QString mime = QStringLiteral("inode/directory"); | 104 | const QString mime = QStringLiteral("inode/directory"); | ||
99 | KConfigGroup addedApps(profile, s_AddedAssociations); | 105 | KConfigGroup addedApps(profile, s_AddedAssociations); | ||
100 | QStringList userApps = addedApps.readXdgListEntry(mime); | 106 | QStringList userApps = addedApps.readXdgListEntry(mime); | ||
101 | userApps.removeAll(storageId); // remove if present, to make it first in the list | 107 | userApps.removeAll(storageId); // remove if present, to make it first in the list | ||
102 | userApps.prepend(storageId); | 108 | userApps.prepend(storageId); | ||
103 | addedApps.writeXdgListEntry(mime, userApps); | 109 | addedApps.writeXdgListEntry(mime, userApps); | ||
104 | 110 | | |||
105 | // Save the default file manager as per mime-apps spec 1.0.1 | 111 | // Save the default file manager as per mime-apps spec 1.0.1 | ||
106 | KConfigGroup defaultApp(profile, s_DefaultApplications); | 112 | KConfigGroup defaultApp(profile, s_DefaultApplications); | ||
107 | defaultApp.writeXdgListEntry(mime, QStringList(storageId)); | 113 | defaultApp.writeXdgListEntry(mime, QStringList(storageId)); | ||
108 | 114 | | |||
109 | Kdelibs4SharedConfig::syncConfigGroup(QLatin1String("Added Associations"), QStringLiteral("mimeapps.list")); | | |||
110 | | ||||
111 | profile->sync(); | 115 | profile->sync(); | ||
112 | 116 | | |||
113 | // Clean out any kde-mimeapps.list which would take precedence any cancel our changes. | | |||
114 | // (also taken from filetypes/mimetypedata.cpp) | | |||
115 | const QString desktops = QString::fromLocal8Bit(qgetenv("XDG_CURRENT_DESKTOP")); | | |||
116 | foreach (const QString &desktop, desktops.split(":", QString::SkipEmptyParts)) { | | |||
117 | const QString file = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) | | |||
118 | + QLatin1Char('/') + desktop.toLower() + QLatin1String("-mimeapps.list"); | | |||
119 | if (QFileInfo::exists(file)) { | | |||
120 | qDebug() << "Cleaning up" << file; | | |||
121 | KConfig conf(file, KConfig::NoGlobals); | | |||
122 | KConfigGroup(&conf, s_DefaultApplications).deleteEntry(mime); | | |||
123 | KConfigGroup(&conf, s_AddedAssociations).deleteEntry(mime); | | |||
124 | KConfigGroup(&conf, s_RemovedAssociations).deleteEntry(mime); | | |||
125 | } | | |||
126 | } | | |||
127 | | ||||
128 | KBuildSycocaProgressDialog::rebuildKSycoca(this); | 117 | KBuildSycocaProgressDialog::rebuildKSycoca(this); | ||
129 | } | 118 | } | ||
130 | 119 | | |||
131 | emit changed(false); | 120 | emit changed(false); | ||
132 | } | 121 | } | ||
133 | 122 | | |||
134 | void CfgFileManager::slotAddFileManager() | 123 | void CfgFileManager::slotAddFileManager() | ||
135 | { | 124 | { | ||
136 | KProcess proc; | 125 | KProcess proc; | ||
137 | proc << QStringLiteral("keditfiletype5"); | 126 | proc << QStringLiteral("keditfiletype5"); | ||
138 | proc << QStringLiteral("inode/directory"); | 127 | proc << QStringLiteral("inode/directory"); | ||
139 | if (proc.execute() == 0) { | 128 | if (proc.execute() == 0) { | ||
140 | load(nullptr); | 129 | load(nullptr); | ||
141 | } | 130 | } | ||
142 | } | 131 | } |
Opening curly brace should be on the same line than for