【问题标题】:Alternative to gnome_url_show() in xfcexfce 中 gnome_url_show() 的替代方法
【发布时间】:2013-06-07 19:25:17
【问题描述】:

我想知道 xfce 是否有类似于 gnome 的 gnome_url_show() 的功能。

如果不是这种情况,我想知道打开网址的另一种便捷方式是什么?例如,如果您向按钮添加信号处理程序,单击该按钮会打开一个网站。

gtk有这样的功能吗?我知道它至少内置了一些东西,因为当您创建一个带有 url 的标签时,可以单击它来打开 url。我浏览了各种文档,但还没有找到解决方案。

gtk_show_uri() 不适用于 xfce,因为它需要 gvfs 而我没有使用 gnome。

【问题讨论】:

  • 不是答案,但是:您可以在不安装 gnome 的情况下安装 gvfs。至少在 Debian 上,对于 gvfs,您需要软件包 libgnomevfs2-0,而不是 Gnome 软件包。安装这些软件包可能是另一种选择。

标签: c gtk gnome xfce


【解决方案1】:

感谢 xfce4-weather-plugin 源,我发现这是一个实用的解决方案:

gchar *str = g_strdup_printf("exo-open --launch WebBrowser %s", url);
g_spawn_command_line_async(str, NULL);
g_free(str);

考虑到该插件是核心 xfce 应用程序的一部分,我认为这是执行此操作的适当方式。我还发现了 exo_execute_preferred_application() 但是我不想包含另一个库。

可以在此处找到此主题的变体:http://git.xfce.org/xfce/libxfce4ui/tree/libxfce4ui/xfce-dialogs.c#n66 这可能更可取,因为如果未安装 exo,它将回退到 gtk_show_uri()。尽管 gtk_show_uri() 可能由于 xfce 系统上缺少 gvfs 而无法工作(毕竟用户使用的是 xfce,而不是 gnome)。 xfce 面板使用这个函数来加载一个 url。

static void
xfce_dialog_show_help_uri (GdkScreen *screen,
                           GtkWindow *parent,
                           GString   *uri)
{
  GError   *error = NULL;
  gchar    *path;
  gchar    *cmd;
  gboolean  result;

  g_return_if_fail (GDK_IS_SCREEN (screen));
  g_return_if_fail (parent == NULL || GTK_IS_WINDOW (parent));

  path = g_find_program_in_path ("exo-open");
  if (G_LIKELY (path != NULL))
    {
      cmd = g_strdup_printf ("%s --launch WebBrowser '%s'", path, uri->str);

      result = xfce_spawn_command_line_on_screen (screen, cmd, FALSE, TRUE, &error);

      g_free (path);
      g_free (cmd);
    }
  else
    {
      /* not very likely to happen, but it is possible exo is not installed */
      result = gtk_show_uri (screen, uri->str, gtk_get_current_event_time (), &error);
    }

  if (!result)
    {
      xfce_dialog_show_error (parent, error,
          _("Failed to open web browser for online documentation"));
      g_error_free (error);
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-09
    • 2011-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多