Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed setting of default apps with GLib backend #219

Merged
merged 1 commit into from
Jul 7, 2020

Conversation

tsujan
Copy link
Member

@tsujan tsujan commented Jul 6, 2020

In LXQt, although the GLib backend reads ~/.config/lxqt-mimeapps.list, it writes to ~/.config/mimeapps.list on setting default apps. Since we want to set default apps only for LXQt, the patch directly writes them to lxqt-mimeapps.list — after adding the needed associations to mimeapps.list (GLib always does the latter).

The patch considers XDG_CURRENT_DESKTOP and works outside LXQt too. In other words, it isn't limited to lxqt-mimeapps.list.

Fixes #218

@tsujan tsujan requested a review from luis-pereira July 6, 2020 11:00
Copy link
Member

@luis-pereira luis-pereira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed it, but dismiss it. Never seen the $desktop-mimeapps.list being used.


$XDG_CONFIG_HOME/$desktop-mimeapps.list | user overrides, desktop-specific (for advanced users)
$XDG_CONFIG_HOME/mimeapps.list | user overrides (recommended location for user configuration GUIs)

The standard seems to incentivize not using it. I took GLib implementation by reading it and not writing as a implicit statement that $desktop-mimeapps.list was something that a advanced user would edit by hand.

  1. If we are going this way we must take XDG_CURRENT_DESKTOP into account. libqtxdg isn't LXQt specific (there are people using it).
  2. Does this rationale also applies to Added Associations and Removed Associations ?
  3. Not sure about changed signal behavior. Will test.

It was a long long day, will continue tomorrow. Have to rest now.

GDesktopAppInfo *gApp = XdgDesktopFileToGDesktopAppinfo(app);
if (gApp == nullptr)
return false;

GError *error = nullptr;
if (g_app_info_set_as_default_for_type(G_APP_INFO(gApp),
mimeType.toUtf8().constData(), &error) == FALSE) {
QString confDir = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can eat our own food and use XdgDirs::configHome(). It also uses QStandardPaths but shields us from changes in Qt itself.

@tsujan
Copy link
Member Author

tsujan commented Jul 6, 2020

If we are going this way we must take XDG_CURRENT_DESKTOP into account. libqtxdg isn't LXQt specific

I have no problem with that.

Does this rationale also applies to Added Associations and Removed Associations ?

No, because they only use mimeapps.list.

It was a long long day, will continue tomorrow. Have to rest now.

Today was like 3 days to me ;) With these patches, I made default apps work at last. The only remaining challenge is finding a reliable way of restoring the previous settings. Honestly, SettingsCache::loadToSettings is very inefficient (lxqt/liblxqt#262 is only one part of the problem). Will find a way tomorrow; should sleep too.

In LXQt, although the GLib backend reads `~/.config/lxqt-mimeapps.list`, it writes to `~/.config/mimeapps.list` on setting default apps. Since we want to set default apps only for LXQt, the patch directly writes them to `lxqt-mimeapps.list` — after adding the needed associations to `mimeapps.list` (GLib always does the latter).

The patch considers `XDG_CURRENT_DESKTOP` and works outside LXQt too. In other words, it isn't limited to `lxqt-mimeapps.list`.

Fixes #218
@tsujan
Copy link
Member Author

tsujan commented Jul 7, 2020

Updated the patch to consider XDG_CURRENT_DESKTOP and use XdgDirs::configHome().

@luis-pereira
Copy link
Member

No, because they only use mimeapps.list.

You mean the GLib implementation. I was referring to the standard.

It was a long long day, will continue tomorrow. Have to rest now.

Today was like 3 days to me ;) With these patches, I made default apps work at last. The only remaining challenge is finding a reliable way of restoring the previous settings. Honestly, SettingsCache::loadToSettings is very inefficient (lxqt/liblxqt#262 is only one part of the problem). Will find a way tomorrow; should sleep too.

SettingsCache::loadToSettings() is very old. I remember that when I first downloaded Razor-qt source, it was already there.

@tsujan
Copy link
Member Author

tsujan commented Jul 7, 2020

You mean the GLib implementation. I was referring to the standard.

I just supposed that GLib follows standards, knowing that Gnome devs have had a big part in implementing them.

GLib does this: It gives priority to the DE-specific mimeapps.list when reading default apps but ignores it when setting default apps. That isn't good even if it's a standard -- IMO, it's self-contradictory and a bug.

Apart from it, when GLib sets a default app, it adds the needed associations to the DE-independent mimeapps.list. I think that's reasonable because, although those associations may already exist, it's better to be safe than sorry.

@tsujan tsujan merged commit df290cd into master Jul 7, 2020
@tsujan tsujan deleted the fix_set_default_app branch July 7, 2020 18:40
tsujan added a commit to lxqt/libfm-qt that referenced this pull request Jul 9, 2020
GLib has a weird problem. On the one hand, `g_app_info_set_as_default_for_type()` writes to `~/.config/mimeapps.list`. On the other hand, the DE-specific list — e.g., `~/.config/lxqt-mimeapps.list` in LXQt — has priority over it and GLib respects that. Therefore, if the latter exists and contains some default apps, `g_app_info_set_as_default_for_type()` could not change them.

This patch solves the problem by adding a utility function that sets the default app directly inside the DE-specific list.

Also, see lxqt/libqtxdg#219.
tsujan added a commit to lxqt/libfm-qt that referenced this pull request Jul 9, 2020
GLib has a weird problem. On the one hand, `g_app_info_set_as_default_for_type()` writes to `~/.config/mimeapps.list`. On the other hand, the DE-specific list — e.g., `~/.config/lxqt-mimeapps.list` in LXQt — has priority over it and GLib respects that. Therefore, if the latter exists and contains some default apps, `g_app_info_set_as_default_for_type()` could not change them.

This patch solves the problem by adding a utility function that sets the default app directly inside the DE-specific list.

Also, see lxqt/libqtxdg#219.
tsujan added a commit to lxqt/libfm-qt that referenced this pull request Jul 19, 2020
GLib has a weird problem. On the one hand, `g_app_info_set_as_default_for_type()` writes to `~/.config/mimeapps.list`. On the other hand, the DE-specific list — e.g., `~/.config/lxqt-mimeapps.list` in LXQt — has priority over it and GLib respects that. Therefore, if the latter exists and contains some default apps, `g_app_info_set_as_default_for_type()` could not change them.

This patch solves the problem by adding a utility function that sets the default app directly inside the DE-specific list.

Also, see lxqt/libqtxdg#219.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Problem with setting default apps with the GLib backend
2 participants