Updating branch refs/heads/master to 956b4bb92d5b39699df3e9a0a6eb3f99e022caa1 (commit) from d64b4b629756357bd71b6fcdc77ca6b05a3de3e3 (commit)
commit 956b4bb92d5b39699df3e9a0a6eb3f99e022caa1 Author: Stephan Arts <step...@xfce.org> Date: Fri Mar 30 01:25:13 2012 +0200 Launch default editor configured in $XDG_DATA_DIR/mime.db configure.in.in | 1 + src/Makefile.am | 4 +- src/db.c | 23 ------ src/db.h | 26 ------ src/main_window.c | 116 +++++++++++++++------------- src/mime_db.c | 223 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/mime_db.h | 82 +++++++++++++++++++ 7 files changed, 371 insertions(+), 104 deletions(-) diff --git a/configure.in.in b/configure.in.in index 310f9c2..c83c30a 100644 --- a/configure.in.in +++ b/configure.in.in @@ -57,6 +57,7 @@ XDT_CHECK_PACKAGE([GLIB], [glib-2.0], [2.24.0]) XDT_CHECK_PACKAGE([GTHREAD], [gthread-2.0], [2.24.0]) XDT_CHECK_PACKAGE([GOBJECT], [gobject-2.0], [2.24.0]) XDT_CHECK_PACKAGE([GIO], [gio-2.0], [2.18.0]) +XDT_CHECK_PACKAGE([GIO_UNIX], [gio-unix-2.0], [2.18.0]) XDT_CHECK_PACKAGE([DBUS_GLIB], [dbus-glib-1], [0.34]) XDT_CHECK_PACKAGE([LIBXFCE4UTIL], [libxfce4util-1.0], [4.8.0]) XDT_CHECK_PACKAGE([LIBXFCE4UI], [libxfce4ui-1], [4.9.0]) diff --git a/src/Makefile.am b/src/Makefile.am index e86d739..4f55735 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -18,7 +18,7 @@ ristretto_SOURCES = \ file.c file.h \ privacy_dialog.h privacy_dialog.c \ util.c util.h \ - db.c db.h \ + mime_db.c mime_db.h \ icon_bar.c icon_bar.h \ main.c @@ -27,6 +27,7 @@ ristretto_CFLAGS = \ $(GLIB_CFLAGS) \ $(GTHREAD_CFLAGS) \ $(GIO_CFLAGS) \ + $(GIO_UNIX_CFLAGS) \ $(LIBEXIF_CFLAGS) \ $(XFCONF_CFLAGS) \ $(EXO_CFLAGS) \ @@ -44,6 +45,7 @@ ristretto_LDADD = \ $(GLIB_LIBS) \ $(GTHREAD_LIBS) \ $(GIO_LIBS) \ + $(GIO_UNIX_LIBS) \ $(LIBEXIF_LIBS) \ $(XFCONF_LIBS) \ $(EXO_LIBS) \ diff --git a/src/db.c b/src/db.c deleted file mode 100644 index 9989850..0000000 --- a/src/db.c +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) Stephan Arts 2012 <step...@xfce.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#include <config.h> -#include <glib.h> -#include <locale.h> - -#include "db.h" diff --git a/src/db.h b/src/db.h deleted file mode 100644 index 3d59cdd..0000000 --- a/src/db.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) Stephan Arts 2011 <step...@xfce.org> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Library General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef __RISTRETTO_DB_H__ -#define __RISTRETTO_DB_H__ - -G_BEGIN_DECLS - -G_END_DECLS - -#endif /* __RSTTO_DB_H__ */ diff --git a/src/main_window.c b/src/main_window.c index 5e1e0a1..db7462e 100644 --- a/src/main_window.c +++ b/src/main_window.c @@ -23,6 +23,7 @@ #include <string.h> #include <gio/gio.h> +#include <gio/gdesktopappinfo.h> #include <libxfce4ui/libxfce4ui.h> #include <libexif/exif-data.h> @@ -32,6 +33,7 @@ #include <cairo/cairo.h> #include "settings.h" +#include "mime_db.h" #include "util.h" #include "file.h" #include "icon_bar.h" @@ -63,58 +65,60 @@ struct _RsttoMainWindowPriv { - RsttoImageList *image_list; + RsttoImageList *image_list; - DBusGConnection *connection; - DBusGProxy *filemanager_proxy; + RsttoMimeDB *db; - guint show_fs_toolbar_timeout_id; - gint window_save_geometry_timer_id; + DBusGConnection *connection; + DBusGProxy *filemanager_proxy; + + guint show_fs_toolbar_timeout_id; + gint window_save_geometry_timer_id; - gboolean fs_toolbar_sticky; + gboolean fs_toolbar_sticky; - RsttoImageListIter *iter; + RsttoImageListIter *iter; - GtkActionGroup *action_group; - GtkUIManager *ui_manager; - GtkRecentManager *recent_manager; - RsttoSettings *settings_manager; + GtkActionGroup *action_group; + GtkUIManager *ui_manager; + GtkRecentManager *recent_manager; + RsttoSettings *settings_manager; RsttoWallpaperManager *wallpaper_manager; - GtkWidget *menubar; - GtkWidget *toolbar; - GtkWidget *warning; - GtkWidget *warning_label; - GtkWidget *image_viewer_menu; - GtkWidget *position_menu; - GtkWidget *image_viewer; - GtkWidget *p_viewer_s_window; - GtkWidget *table; - GtkWidget *t_bar_s_window; - GtkWidget *thumbnailbar; - GtkWidget *statusbar; - guint statusbar_context_id; - - GtkWidget *back; - GtkWidget *forward; - - guint t_open_merge_id; - guint recent_merge_id; - guint play_merge_id; - guint pause_merge_id; - guint toolbar_play_merge_id; - guint toolbar_pause_merge_id; - guint toolbar_fullscreen_merge_id; - guint toolbar_unfullscreen_merge_id; - - GtkAction *play_action; - GtkAction *pause_action; - GtkAction *recent_action; - - gboolean playing; - gint play_timeout_id; - - GtkFileFilter *filter; + GtkWidget *menubar; + GtkWidget *toolbar; + GtkWidget *warning; + GtkWidget *warning_label; + GtkWidget *image_viewer_menu; + GtkWidget *position_menu; + GtkWidget *image_viewer; + GtkWidget *p_viewer_s_window; + GtkWidget *table; + GtkWidget *t_bar_s_window; + GtkWidget *thumbnailbar; + GtkWidget *statusbar; + guint statusbar_context_id; + + GtkWidget *back; + GtkWidget *forward; + + guint t_open_merge_id; + guint recent_merge_id; + guint play_merge_id; + guint pause_merge_id; + guint toolbar_play_merge_id; + guint toolbar_pause_merge_id; + guint toolbar_fullscreen_merge_id; + guint toolbar_unfullscreen_merge_id; + + GtkAction *play_action; + GtkAction *pause_action; + GtkAction *recent_action; + + gboolean playing; + gint play_timeout_id; + + GtkFileFilter *filter; }; enum @@ -472,11 +476,19 @@ rstto_main_window_init (RsttoMainWindow *window) guint navigationbar_position = 3; guint thumbnail_size = 3; + gchar *db_path = NULL; gtk_window_set_title (GTK_WINDOW (window), RISTRETTO_APP_TITLE); window->priv = g_new0(RsttoMainWindowPriv, 1); + + db_path = xfce_resource_save_location ( + XFCE_RESOURCE_DATA, "ristretto/mime.db", TRUE); + if (db_path != NULL) + { + window->priv->db = rstto_mime_db_new ( db_path, NULL); + } window->priv->iter = NULL; @@ -2862,16 +2874,12 @@ cb_rstto_main_window_edit ( { RsttoFile *r_file = rstto_image_list_iter_get_file(window->priv->iter); const gchar *content_type = rstto_file_get_content_type (r_file); - GList *app_infos = g_app_info_get_all_for_type (content_type); - GList *iter = app_infos; + const gchar *editor = rstto_mime_db_lookup (window->priv->db, content_type); + GList *files = g_list_prepend (NULL, rstto_file_get_file (r_file)); - while (iter) - { - g_debug("N: %s", g_app_info_get_name (iter->data)); - g_debug("DN:%s", g_app_info_get_display_name (iter->data)); - g_debug("D: %s", g_app_info_get_description (iter->data)); - iter = g_list_next (iter); - } + GDesktopAppInfo *app_info = g_desktop_app_info_new (editor); + g_app_info_launch (G_APP_INFO(app_info), files, NULL, NULL); + g_list_free (files); } /** diff --git a/src/mime_db.c b/src/mime_db.c new file mode 100644 index 0000000..59d1b08 --- /dev/null +++ b/src/mime_db.c @@ -0,0 +1,223 @@ +/* + * Copyright (c) Stephan Arts 2012 <step...@xfce.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include <config.h> +#include <stdlib.h> +#include <fcntl.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <sys/mman.h> + + +#include <glib.h> +#include <gio/gio.h> +#include <locale.h> + +#include <libxfce4util/libxfce4util.h> + +#include "mime_db.h" + +static void +rstto_mime_db_init (GObject *); +static void +rstto_mime_db_class_init (GObjectClass *); + +static void +rstto_mime_db_dispose (GObject *object); +static void +rstto_mime_db_finalize (GObject *object); + +static void +rstto_mime_db_set_property ( + GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec ); + +static void +rstto_mime_db_get_property ( + GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + +enum +{ + PROP_0, + PROP_FILE +}; + +static GObjectClass *parent_class = NULL; + +GType +rstto_mime_db_get_type (void) +{ + static GType rstto_mime_db_type = 0; + + if (!rstto_mime_db_type) + { + static const GTypeInfo rstto_mime_db_info = + { + sizeof (RsttoMimeDBClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) rstto_mime_db_class_init, + (GClassFinalizeFunc) NULL, + NULL, + sizeof (RsttoMimeDB), + 0, + (GInstanceInitFunc) rstto_mime_db_init, + NULL + }; + + rstto_mime_db_type = g_type_register_static (G_TYPE_OBJECT, "RsttoMimeDB", &rstto_mime_db_info, 0); + } + return rstto_mime_db_type; +} + +struct _RsttoMimeDBPriv +{ + GFile *file; + XfceRc *rc; +}; + +static void +rstto_mime_db_init (GObject *object) +{ + RsttoMimeDB *mime_db = RSTTO_MIME_DB (object); + + mime_db->priv = g_new0 (RsttoMimeDBPriv, 1); +} + +static void +rstto_mime_db_class_init (GObjectClass *object_class) +{ + RsttoMimeDBClass *mime_db_class = RSTTO_MIME_DB_CLASS (object_class); + + parent_class = g_type_class_peek_parent (mime_db_class); + + object_class->dispose = rstto_mime_db_dispose; + object_class->finalize = rstto_mime_db_finalize; + + object_class->set_property = rstto_mime_db_set_property; + object_class->get_property = rstto_mime_db_get_property; + +} + +/** + * rstto_mime_db_dispose: + * @object: + * + */ +static void +rstto_mime_db_dispose (GObject *object) +{ + RsttoMimeDB *mime_db = RSTTO_MIME_DB (object); + + if (mime_db->priv) + { + xfce_rc_close (mime_db->priv->rc); + g_free (mime_db->priv); + mime_db->priv = NULL; + } +} + +/** + * rstto_mime_db_finalize: + * @object: + * + */ +static void +rstto_mime_db_finalize (GObject *object) +{ +} + +static void +rstto_mime_db_set_property ( + GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec ) +{ + switch (property_id) + { + case PROP_FILE: + break; + default: + break; + } +} + +static void +rstto_mime_db_get_property ( + GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + + switch (property_id) + { + case PROP_FILE: + break; + default: + break; + } + +} + +RsttoMimeDB * +rstto_mime_db_new (const gchar *path, GError **error) +{ + + RsttoMimeDB *mime_db = NULL; + XfceRc *rc = NULL; + + rc = xfce_rc_simple_open (path, FALSE); + + if (rc != NULL) + { + mime_db = g_object_new (RSTTO_TYPE_MIME_DB, NULL); + mime_db->priv->rc = rc; + + xfce_rc_set_group (rc, "preferred-editor"); + } + + return mime_db; +} + + +const gchar * +rstto_mime_db_lookup ( + RsttoMimeDB *mime_db, + const gchar *key) +{ + return xfce_rc_read_entry (mime_db->priv->rc, key, NULL); +} + + +void +rstto_mime_db_store ( + RsttoMimeDB *mime_db, + const gchar *key, + const gchar *value) +{ + xfce_rc_write_entry (mime_db->priv->rc, key, value); + xfce_rc_flush (mime_db->priv->rc); +} + diff --git a/src/mime_db.h b/src/mime_db.h new file mode 100644 index 0000000..e5d1e78 --- /dev/null +++ b/src/mime_db.h @@ -0,0 +1,82 @@ +/* + * Copyright (c) Stephan Arts 2011 <step...@xfce.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef __RISTRETTO_MIME_DB_H__ +#define __RISTRETTO_MIME_DB_H__ + +G_BEGIN_DECLS + + +#define RSTTO_TYPE_MIME_DB rstto_mime_db_get_type() + +#define RSTTO_MIME_DB(obj)( \ + G_TYPE_CHECK_INSTANCE_CAST ((obj), \ + RSTTO_TYPE_MIME_DB, \ + RsttoMimeDB)) + +#define RSTTO_IS_MIME_DB(obj)( \ + G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ + RSTTO_TYPE_MIME_DB)) + +#define RSTTO_MIME_DB_CLASS(klass)( \ + G_TYPE_CHECK_CLASS_CAST ((klass), \ + RSTTO_TYPE_MIME_DB, \ + RsttoMimeDBClass)) + +#define RSTTO_IS_MIME_DB_CLASS(klass)( \ + G_TYPE_CHECK_CLASS_TYPE ((klass), \ + RSTTO_TYPE_MIME_DB())) + + +typedef struct _RsttoMimeDB RsttoMimeDB; +typedef struct _RsttoMimeDBPriv RsttoMimeDBPriv; + +struct _RsttoMimeDB +{ + GObject parent; + + RsttoMimeDBPriv *priv; +}; + +typedef struct _RsttoMimeDBClass RsttoMimeDBClass; + +struct _RsttoMimeDBClass +{ + GObjectClass parent_class; +}; + +GType +rstto_mime_db_get_type (); + +RsttoMimeDB * +rstto_mime_db_new (const gchar *path, GError **); + +const gchar * +rstto_mime_db_lookup ( + RsttoMimeDB *mime_db, + const gchar *key); + +void +rstto_mime_db_store ( + RsttoMimeDB *mime_db, + const gchar *key, + const gchar *value); + +G_END_DECLS + +#endif /* __RSTTO_MIME_DB_H__ */ _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org https://mail.xfce.org/mailman/listinfo/xfce4-commits