Commit cf25ec8f authored by Cosimo Cecchi's avatar Cosimo Cecchi
Browse files

open-with: first attempt to split the dialog into a widget + interface

Like GtkFileChooser does; GtkOpenWith is a generic interface, which is
now implemented by both GtkOpenWithDialog and GtkOpenWithWidget (and in
the future also by GtkOpenWithComboBox).
parent 9d6055d0
......@@ -246,7 +246,9 @@ gtk_public_h_sources = \
gtkmountoperation.h \
gtknotebook.h \
gtkoffscreenwindow.h \
gtkopenwith.h \
gtkopenwithdialog.h \
gtkopenwithwidget.h \
gtkorientable.h \
gtkpagesetup.h \
gtkpaned.h \
......@@ -374,6 +376,7 @@ gtk_private_h_sources = \
gtkmenuprivate.h \
gtkmnemonichash.h \
gtkmountoperationprivate.h \
gtkopenwithprivate.h \
gtkpango.h \
gtkpathbar.h \
gtkplugprivate.h \
......@@ -517,6 +520,8 @@ gtk_base_c_sources = \
gtkmountoperation.c \
gtknotebook.c \
gtkoffscreenwindow.c \
gtkopenwith.c \
gtkopenwithwidget.c \
gtkopenwithdialog.c \
gtkorientable.c \
gtkpagesetup.c \
......
......@@ -129,7 +129,9 @@
#include <gtk/gtkmountoperation.h>
#include <gtk/gtknotebook.h>
#include <gtk/gtkoffscreenwindow.h>
#include <gtk/gtkopenwith.h>
#include <gtk/gtkopenwithdialog.h>
#include <gtk/gtkopenwithwidget.h>
#include <gtk/gtkorientable.h>
#include <gtk/gtkpagesetup.h>
#include <gtk/gtkpapersize.h>
......
......@@ -565,6 +565,13 @@ typedef enum
} GtkScrollablePolicy;
typedef enum
{
GTK_OPEN_WITH_WIDGET_SHOW_MODE_RECOMMENDED,
GTK_OPEN_WITH_WIDGET_SHOW_MODE_ALL,
GTK_OPEN_WITH_WIDGET_SHOW_MODE_HEADINGS
} GtkOpenWithWidgetShowMode;
G_END_DECLS
......
/*
* gtkopenwith.c: open-with interface
*
* Copyright (C) 2010 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This library 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 Library General Public
* License along with the Gnome Library; see the file COPYING.LIB. If not,
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Authors: Cosimo Cecchi <ccecchi@redhat.com>
*/
#include <config.h>
#include "gtkopenwith.h"
#include "gtkintl.h"
#include "gtkopenwithprivate.h"
#include "gtkwidget.h"
#include <glib.h>
G_DEFINE_INTERFACE (GtkOpenWith, gtk_open_with, GTK_TYPE_WIDGET);
static void
gtk_open_with_default_init (GtkOpenWithIface *iface)
{
GParamSpec *pspec;
pspec = g_param_spec_string ("content-type",
P_("Content type"),
P_("The content type used by the open with object"),
NULL,
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS);
g_object_interface_install_property (iface, pspec);
}
gchar *
gtk_open_with_get_content_type (GtkOpenWith *self)
{
gchar *retval = NULL;
g_return_val_if_fail (GTK_IS_OPEN_WITH (self), NULL);
g_object_get (self,
"content-type", &retval,
NULL);
return retval;
}
GAppInfo *
gtk_open_with_get_app_info (GtkOpenWith *self)
{
return GTK_OPEN_WITH_GET_IFACE (self)->get_app_info (self);
}
/*
* gtkopenwith.h: open-with interface
*
* Copyright (C) 2010 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This library 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 Library General Public
* License along with the Gnome Library; see the file COPYING.LIB. If not,
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Authors: Cosimo Cecchi <ccecchi@redhat.com>
*/
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
#error "Only <gtk/gtk.h> can be included directly."
#endif
#ifndef __GTK_OPEN_WITH_H__
#define __GTK_OPEN_WITH_H__
#include <glib.h>
#include <gio/gio.h>
G_BEGIN_DECLS
#define GTK_TYPE_OPEN_WITH\
(gtk_open_with_get_type ())
#define GTK_OPEN_WITH(obj)\
(G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_OPEN_WITH, GtkOpenWith))
#define GTK_IS_OPEN_WITH(obj)\
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_OPEN_WITH))
typedef struct _GtkOpenWith GtkOpenWith;
GType gtk_open_with_get_type () G_GNUC_CONST;
GAppInfo * gtk_open_with_get_app_info (GtkOpenWith *self);
gchar * gtk_open_with_get_content_type (GtkOpenWith *self);
G_END_DECLS
#endif /* __GTK_OPEN_WITH_H__ */
This diff is collapsed.
......@@ -47,7 +47,6 @@
#define GTK_OPEN_WITH_DIALOG_GET_CLASS(obj)\
(G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_OPEN_WITH_DIALOG, GtkOpenWithDialogClass))
typedef struct _GtkOpenWithDialog GtkOpenWithDialog;
typedef struct _GtkOpenWithDialogClass GtkOpenWithDialogClass;
typedef struct _GtkOpenWithDialogPrivate GtkOpenWithDialogPrivate;
......@@ -62,9 +61,6 @@ struct _GtkOpenWithDialog {
struct _GtkOpenWithDialogClass {
GtkDialogClass parent_class;
void (*application_selected) (GtkOpenWithDialog *dialog,
GAppInfo *application);
/* padding for future class expansion */
gpointer padding[16];
};
......@@ -78,16 +74,9 @@ struct _GtkOpenWithDialogClass {
*/
typedef enum {
GTK_OPEN_WITH_DIALOG_MODE_SELECT_ONE,
GTK_OPEN_WITH_DIALOG_MODE_SELECT_DEFAULT,
GTK_OPEN_WITH_DIALOG_MODE_RADIO,
GTK_OPEN_WITH_DIALOG_MODE_SELECT_DEFAULT
} GtkOpenWithDialogMode;
typedef enum {
GTK_OPEN_WITH_DIALOG_SHOW_MODE_RECOMMENDED,
GTK_OPEN_WITH_DIALOG_SHOW_MODE_ALL,
GTK_OPEN_WITH_DIALOG_SHOW_MODE_HEADINGS
} GtkOpenWithDialogShowMode;
GType gtk_open_with_dialog_get_type (void) G_GNUC_CONST;
GtkWidget * gtk_open_with_dialog_new (GtkWindow *parent,
......@@ -99,16 +88,10 @@ GtkWidget * gtk_open_with_dialog_new_for_content_type (GtkWindow *parent,
GtkOpenWithDialogMode mode,
const gchar *content_type);
void gtk_open_with_dialog_set_show_mode (GtkOpenWithDialog *self,
GtkOpenWithDialogShowMode show_mode);
GtkOpenWithDialogShowMode gtk_open_with_dialog_get_show_mode (GtkOpenWithDialog *self);
void gtk_open_with_dialog_set_show_set_as_default_button (GtkOpenWithDialog *self,
gboolean show_button);
gboolean gtk_open_with_get_show_set_as_default_button (GtkOpenWithDialog *self);
GAppInfo * gtk_open_with_dialog_get_selected_application (GtkOpenWithDialog *self);
GtkOpenWithDialogMode gtk_open_with_dialog_get_mode (GtkOpenWithDialog *self);
GtkWidget * gtk_open_with_dialog_get_widget (GtkOpenWithDialog *self);
#endif /* __GTK_OPEN_WITH_DIALOG_H__ */
/*
* gtkopenwith.c: open-with interface
*
* Copyright (C) 2010 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This library 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 Library General Public
* License along with the Gnome Library; see the file COPYING.LIB. If not,
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Authors: Cosimo Cecchi <ccecchi@redhat.com>
*/
#ifndef __GTK_OPEN_WITH_PRIVATE_H__
#define __GTK_OPEN_WITH_PRIVATE_H__
#include <glib.h>
#include <gio/gio.h>
#include "gtkopenwithwidget.h"
typedef struct _GtkOpenWithIface GtkOpenWithIface;
typedef GtkOpenWithIface GtkOpenWithInterface;
#define GTK_OPEN_WITH_GET_IFACE(inst)\
(G_TYPE_INSTANCE_GET_INTERFACE ((inst), GTK_TYPE_OPEN_WITH, GtkOpenWithIface))
struct _GtkOpenWithIface {
GTypeInterface base_iface;
GAppInfo * (* get_app_info) (GtkOpenWith *object);
};
void _gtk_open_with_widget_refilter (GtkOpenWithWidget *self);
#endif /* __GTK_OPEN_WITH_PRIVATE_H__ */
This diff is collapsed.
/*
* gtkopenwithwidget.h: an open-with widget
*
* Copyright (C) 2004 Novell, Inc.
* Copyright (C) 2007, 2010 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This library 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 Library General Public
* License along with the Gnome Library; see the file COPYING.LIB. If not,
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Authors: Dave Camp <dave@novell.com>
* Alexander Larsson <alexl@redhat.com>
* Cosimo Cecchi <ccecchi@redhat.com>
*/
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
#error "Only <gtk/gtk.h> can be included directly."
#endif
#ifndef __GTK_OPEN_WITH_WIDGET_H__
#define __GTK_OPEN_WITH_WIDGET_H__
#include <gtk/gtkbox.h>
#include <gio/gio.h>
#define GTK_TYPE_OPEN_WITH_WIDGET\
(gtk_open_with_widget_get_type ())
#define GTK_OPEN_WITH_WIDGET(obj)\
(G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_OPEN_WITH_WIDGET, GtkOpenWithWidget))
#define GTK_OPEN_WITH_WIDGET_CLASS(klass)\
(G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_OPEN_WITH_WIDGET, GtkOpenWithWidgetClass))
#define GTK_IS_OPEN_WITH_WIDGET(obj)\
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_OPEN_WITH_WIDGET))
#define GTK_IS_OPEN_WITH_WIDGET_CLASS(klass)\
(G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_OPEN_WITH_WIDGET))
#define GTK_OPEN_WITH_WIDGET_GET_CLASS(obj)\
(G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_OPEN_WITH_WIDGET, GtkOpenWithWidgetClass))
typedef struct _GtkOpenWithWidget GtkOpenWithWidget;
typedef struct _GtkOpenWithWidgetClass GtkOpenWithWidgetClass;
typedef struct _GtkOpenWithWidgetPrivate GtkOpenWithWidgetPrivate;
struct _GtkOpenWithWidget {
GtkBox parent;
/*< private >*/
GtkOpenWithWidgetPrivate *priv;
};
struct _GtkOpenWithWidgetClass {
GtkBoxClass parent_class;
void (* application_selected) (GtkOpenWithWidget *self,
GAppInfo *app_info);
void (* application_activated) (GtkOpenWithWidget *self,
GAppInfo *app_info);
/* padding for future class expansion */
gpointer padding[16];
};
GType gtk_open_with_widget_get_type (void) G_GNUC_CONST;
GtkWidget * gtk_open_with_widget_new (const gchar *content_type);
void gtk_open_with_widget_set_show_mode (GtkOpenWithWidget *self,
GtkOpenWithWidgetShowMode show_mode);
GtkOpenWithWidgetShowMode gtk_open_with_widget_get_show_mode (GtkOpenWithWidget *self);
#endif /* __GTK_OPEN_WITH_WIDGET_H__ */
......@@ -25,7 +25,7 @@
static GtkWidget *toplevel;
static GFile *file;
static GtkWidget *grid, *file_l, *open, *show_mode, *show_set_as_default;
static GtkWidget *grid, *file_l, *open, *show_mode;
static GtkWidget *radio_file, *radio_file_default, *radio_content, *radio_content_default, *dialog;
static void
......@@ -40,7 +40,7 @@ dialog_response (GtkDialog *d,
if (response_id == GTK_RESPONSE_OK)
{
app_info = gtk_open_with_dialog_get_selected_application (GTK_OPEN_WITH_DIALOG (d));
app_info = gtk_open_with_get_app_info (GTK_OPEN_WITH (d));
name = g_app_info_get_name (app_info);
g_print ("Application selected: %s\n", name);
......@@ -57,6 +57,7 @@ display_dialog (GtkButton *b,
gboolean use_file = FALSE;
gboolean default_mode = FALSE;
gchar *content_type = NULL;
GtkWidget *open_with_widget;
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (radio_file)))
{
......@@ -105,11 +106,10 @@ display_dialog (GtkButton *b,
content_type);
}
gtk_open_with_dialog_set_show_mode (GTK_OPEN_WITH_DIALOG (dialog),
open_with_widget = gtk_open_with_dialog_get_widget (GTK_OPEN_WITH_DIALOG (dialog));
gtk_open_with_widget_set_show_mode (GTK_OPEN_WITH_WIDGET (open_with_widget),
gtk_combo_box_get_active (GTK_COMBO_BOX (show_mode)));
gtk_open_with_dialog_set_show_set_as_default_button (GTK_OPEN_WITH_DIALOG (dialog),
gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (show_set_as_default)));
gtk_widget_show (dialog);
g_signal_connect (dialog, "response",
......@@ -127,26 +127,11 @@ show_mode_changed (GtkComboBox *b,
gint active;
active = gtk_combo_box_get_active (b);
gtk_open_with_dialog_set_show_mode (GTK_OPEN_WITH_DIALOG (dialog),
gtk_open_with_widget_set_show_mode (GTK_OPEN_WITH_WIDGET (gtk_open_with_dialog_get_widget (GTK_OPEN_WITH_DIALOG (dialog))),
active);
}
}
static void
show_set_as_default_toggled (GtkToggleButton *b,
gpointer user_data)
{
if (dialog != NULL)
{
gboolean toggled;
toggled = gtk_toggle_button_get_active (b);
gtk_open_with_dialog_set_show_set_as_default_button (GTK_OPEN_WITH_DIALOG (dialog),
toggled);
}
}
static void
button_clicked (GtkButton *b,
gpointer user_data)
......@@ -231,13 +216,6 @@ main (int argc,
g_signal_connect (show_mode, "changed",
G_CALLBACK (show_mode_changed), NULL);
show_set_as_default = gtk_check_button_new_with_label ("Show set as default");
gtk_grid_attach_next_to (GTK_GRID (grid), show_set_as_default,
show_mode, GTK_POS_BOTTOM, 1, 1);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (show_set_as_default), TRUE);
g_signal_connect (show_set_as_default, "toggled",
G_CALLBACK (show_set_as_default_toggled), NULL);
gtk_container_add (GTK_CONTAINER (toplevel), grid);
gtk_widget_show_all (toplevel);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment