fix: default app settings

This commit is contained in:
kate 2022-01-26 13:18:43 +08:00
parent 54d2f054f2
commit 51eb065399
4 changed files with 34 additions and 16 deletions

View file

@ -17,6 +17,7 @@ find_package(Qt5 COMPONENTS Core DBus Quick LinguistTools REQUIRED)
find_package(KF5KIO)
find_package(KF5Solid)
find_package(KF5WindowSystem)
find_package(KF5Config)
qt5_add_dbus_adaptor(DBUS_SOURCES
com.cutefish.FileManager.xml
@ -84,6 +85,7 @@ target_link_libraries(cutefish-filemanager
KF5::KIOWidgets
KF5::Solid
KF5::WindowSystem
KF5::ConfigCore
# FishUI
)

View file

@ -17,7 +17,7 @@ sudo mk-build-deps -i -t "apt-get --yes" -r
### Debian
```
sudo apt install build-essential cmake extra-cmake-modules libkf5kio-dev libkf5solid-dev libkf5windowsystem-dev qtbase5-dev qtbase5-private-dev qtdeclarative5-dev qtquickcontrols2-5-dev qttools5-dev qttools5-dev-tools
sudo apt install build-essential cmake extra-cmake-modules libkf5kio-dev libkf5solid-dev libkf5windowsystem-dev libkf5config-dev qtbase5-dev qtbase5-private-dev qtdeclarative5-dev qtquickcontrols2-5-dev qttools5-dev qttools5-dev-tools
```
### ArchLinux

1
debian/control vendored
View file

@ -8,6 +8,7 @@ Build-Depends: cmake,
libkf5kio-dev,
libkf5solid-dev,
libkf5windowsystem-dev,
libkf5config-dev,
qtbase5-dev,
qtbase5-private-dev,
qtdeclarative5-dev,

View file

@ -33,6 +33,10 @@
#include <QDebug>
#include <QSet>
#include <KConfig>
#include <KConfigGroup>
#include <KSharedConfig>
static MimeAppManager *SELF = nullptr;
MimeAppManager *MimeAppManager::self()
@ -292,17 +296,23 @@ bool MimeAppManager::setDefaultAppForType(const QString &mimeType, const QString
if (QFile::exists(desktop)) {
QFileInfo info(desktop);
desktop = info.completeBaseName();
} else {
return false;
}
// QSettings settings(mimeappsFile, QSettings::IniFormat);
// settings.setIniCodec("UTF-8");
KSharedConfig::Ptr profile = KSharedConfig::openConfig(QStringLiteral("mimeapps.list"),
KConfig::NoGlobals,
QStandardPaths::GenericConfigLocation);
KConfigGroup defaultApp(profile, "Default Applications");
defaultApp.writeXdgListEntry(mimeType, {desktop});
// if (!settings.isWritable())
// return false;
KConfigGroup addedApps(profile, "Added Associations");
QStringList apps = addedApps.readXdgListEntry(mimeType);
apps.removeAll(desktop);
apps.prepend(desktop); // make it the preferred app
addedApps.writeXdgListEntry(mimeType, apps);
// settings.beginGroup("Default Applications");
// settings.setValue(mimeType, desktop);
// settings.sync();
profile->sync();
return true;
}
@ -311,7 +321,6 @@ bool MimeAppManager::setDefaultAppForFile(const QString &filePath, const QString
{
// ref: https://specifications.freedesktop.org/mime-apps-spec/1.0.1/ar01s03.html
QString mimeappsFile = mimeAppsListFilePath();
QMimeType mimeType;
QString value = desktop;
@ -323,17 +332,23 @@ bool MimeAppManager::setDefaultAppForFile(const QString &filePath, const QString
if (QFile::exists(value)) {
QFileInfo info(value);
value = info.fileName();
} else {
return false;
}
QSettings settings(mimeappsFile, QSettings::IniFormat);
settings.setIniCodec("UTF-8");
KSharedConfig::Ptr profile = KSharedConfig::openConfig(QStringLiteral("mimeapps.list"),
KConfig::NoGlobals,
QStandardPaths::GenericConfigLocation);
KConfigGroup defaultApp(profile, "Default Applications");
defaultApp.writeXdgListEntry(mimeType.name(), {desktop});
if (!settings.isWritable())
return false;
KConfigGroup addedApps(profile, "Added Associations");
QStringList apps = addedApps.readXdgListEntry(mimeType.name());
apps.removeAll(desktop);
apps.prepend(desktop); // make it the preferred app
addedApps.writeXdgListEntry(mimeType.name(), apps);
settings.beginGroup(QStringLiteral("Default Applications")); // Added Associations
settings.setValue(mimeType.name(), value);
settings.sync();
profile->sync();
return true;
}