fix: default app settings
This commit is contained in:
parent
54d2f054f2
commit
51eb065399
4 changed files with 34 additions and 16 deletions
|
@ -17,6 +17,7 @@ find_package(Qt5 COMPONENTS Core DBus Quick LinguistTools REQUIRED)
|
||||||
find_package(KF5KIO)
|
find_package(KF5KIO)
|
||||||
find_package(KF5Solid)
|
find_package(KF5Solid)
|
||||||
find_package(KF5WindowSystem)
|
find_package(KF5WindowSystem)
|
||||||
|
find_package(KF5Config)
|
||||||
|
|
||||||
qt5_add_dbus_adaptor(DBUS_SOURCES
|
qt5_add_dbus_adaptor(DBUS_SOURCES
|
||||||
com.cutefish.FileManager.xml
|
com.cutefish.FileManager.xml
|
||||||
|
@ -84,6 +85,7 @@ target_link_libraries(cutefish-filemanager
|
||||||
KF5::KIOWidgets
|
KF5::KIOWidgets
|
||||||
KF5::Solid
|
KF5::Solid
|
||||||
KF5::WindowSystem
|
KF5::WindowSystem
|
||||||
|
KF5::ConfigCore
|
||||||
|
|
||||||
# FishUI
|
# FishUI
|
||||||
)
|
)
|
||||||
|
|
|
@ -17,7 +17,7 @@ sudo mk-build-deps -i -t "apt-get --yes" -r
|
||||||
### Debian
|
### 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
|
### ArchLinux
|
||||||
|
|
1
debian/control
vendored
1
debian/control
vendored
|
@ -8,6 +8,7 @@ Build-Depends: cmake,
|
||||||
libkf5kio-dev,
|
libkf5kio-dev,
|
||||||
libkf5solid-dev,
|
libkf5solid-dev,
|
||||||
libkf5windowsystem-dev,
|
libkf5windowsystem-dev,
|
||||||
|
libkf5config-dev,
|
||||||
qtbase5-dev,
|
qtbase5-dev,
|
||||||
qtbase5-private-dev,
|
qtbase5-private-dev,
|
||||||
qtdeclarative5-dev,
|
qtdeclarative5-dev,
|
||||||
|
|
|
@ -33,6 +33,10 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
|
|
||||||
|
#include <KConfig>
|
||||||
|
#include <KConfigGroup>
|
||||||
|
#include <KSharedConfig>
|
||||||
|
|
||||||
static MimeAppManager *SELF = nullptr;
|
static MimeAppManager *SELF = nullptr;
|
||||||
|
|
||||||
MimeAppManager *MimeAppManager::self()
|
MimeAppManager *MimeAppManager::self()
|
||||||
|
@ -292,17 +296,23 @@ bool MimeAppManager::setDefaultAppForType(const QString &mimeType, const QString
|
||||||
if (QFile::exists(desktop)) {
|
if (QFile::exists(desktop)) {
|
||||||
QFileInfo info(desktop);
|
QFileInfo info(desktop);
|
||||||
desktop = info.completeBaseName();
|
desktop = info.completeBaseName();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// QSettings settings(mimeappsFile, QSettings::IniFormat);
|
KSharedConfig::Ptr profile = KSharedConfig::openConfig(QStringLiteral("mimeapps.list"),
|
||||||
// settings.setIniCodec("UTF-8");
|
KConfig::NoGlobals,
|
||||||
|
QStandardPaths::GenericConfigLocation);
|
||||||
|
KConfigGroup defaultApp(profile, "Default Applications");
|
||||||
|
defaultApp.writeXdgListEntry(mimeType, {desktop});
|
||||||
|
|
||||||
// if (!settings.isWritable())
|
KConfigGroup addedApps(profile, "Added Associations");
|
||||||
// return false;
|
QStringList apps = addedApps.readXdgListEntry(mimeType);
|
||||||
|
apps.removeAll(desktop);
|
||||||
|
apps.prepend(desktop); // make it the preferred app
|
||||||
|
addedApps.writeXdgListEntry(mimeType, apps);
|
||||||
|
|
||||||
// settings.beginGroup("Default Applications");
|
profile->sync();
|
||||||
// settings.setValue(mimeType, desktop);
|
|
||||||
// settings.sync();
|
|
||||||
|
|
||||||
return true;
|
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
|
// ref: https://specifications.freedesktop.org/mime-apps-spec/1.0.1/ar01s03.html
|
||||||
|
|
||||||
QString mimeappsFile = mimeAppsListFilePath();
|
|
||||||
QMimeType mimeType;
|
QMimeType mimeType;
|
||||||
QString value = desktop;
|
QString value = desktop;
|
||||||
|
|
||||||
|
@ -323,17 +332,23 @@ bool MimeAppManager::setDefaultAppForFile(const QString &filePath, const QString
|
||||||
if (QFile::exists(value)) {
|
if (QFile::exists(value)) {
|
||||||
QFileInfo info(value);
|
QFileInfo info(value);
|
||||||
value = info.fileName();
|
value = info.fileName();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QSettings settings(mimeappsFile, QSettings::IniFormat);
|
KSharedConfig::Ptr profile = KSharedConfig::openConfig(QStringLiteral("mimeapps.list"),
|
||||||
settings.setIniCodec("UTF-8");
|
KConfig::NoGlobals,
|
||||||
|
QStandardPaths::GenericConfigLocation);
|
||||||
|
KConfigGroup defaultApp(profile, "Default Applications");
|
||||||
|
defaultApp.writeXdgListEntry(mimeType.name(), {desktop});
|
||||||
|
|
||||||
if (!settings.isWritable())
|
KConfigGroup addedApps(profile, "Added Associations");
|
||||||
return false;
|
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
|
profile->sync();
|
||||||
settings.setValue(mimeType.name(), value);
|
|
||||||
settings.sync();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue