[nautilus] x-content-bar: make NautilusXContentBar a GtkInfoBar
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus] x-content-bar: make NautilusXContentBar a GtkInfoBar
- Date: Tue, 15 Mar 2011 18:36:22 +0000 (UTC)
commit d73ded51a677700ad76201851af255f5ba6192d3
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Tue Mar 15 14:27:54 2011 -0400
x-content-bar: make NautilusXContentBar a GtkInfoBar
src/nautilus-x-content-bar.c | 103 ++++++++++++++++++------------------------
src/nautilus-x-content-bar.h | 10 +---
2 files changed, 46 insertions(+), 67 deletions(-)
---
diff --git a/src/nautilus-x-content-bar.c b/src/nautilus-x-content-bar.c
index efd60f9..498beaa 100644
--- a/src/nautilus-x-content-bar.c
+++ b/src/nautilus-x-content-bar.c
@@ -49,9 +49,37 @@ enum {
PROP_X_CONTENT_TYPE,
};
-G_DEFINE_TYPE (NautilusXContentBar, nautilus_x_content_bar, GTK_TYPE_HBOX)
+enum {
+ CONTENT_BAR_RESPONSE_APP = 1
+};
+
+G_DEFINE_TYPE (NautilusXContentBar, nautilus_x_content_bar, GTK_TYPE_INFO_BAR)
+
+static void
+content_bar_response_cb (GtkInfoBar *infobar,
+ gint response_id,
+ gpointer user_data)
+{
+ GAppInfo *default_app;
+ NautilusXContentBar *bar = user_data;
+
+ if (response_id != CONTENT_BAR_RESPONSE_APP) {
+ return;
+ }
+
+ if (bar->priv->x_content_type == NULL ||
+ bar->priv->mount == NULL)
+ return;
+
+ default_app = g_app_info_get_default_for_type (bar->priv->x_content_type, FALSE);
+ if (default_app != NULL) {
+ nautilus_launch_application_for_mount (default_app, bar->priv->mount,
+ GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (bar))));
+ g_object_unref (default_app);
+ }
+}
-void
+static void
nautilus_x_content_bar_set_x_content_type (NautilusXContentBar *bar, const char *x_content_type)
{
char *message;
@@ -105,15 +133,7 @@ nautilus_x_content_bar_set_x_content_type (NautilusXContentBar *bar, const char
icon = g_app_info_get_icon (default_app);
if (icon != NULL) {
- GdkPixbuf *pixbuf;
- int icon_size;
- NautilusIconInfo *icon_info;
- icon_size = nautilus_get_icon_size_for_stock_size (GTK_ICON_SIZE_BUTTON);
- icon_info = nautilus_icon_info_lookup (icon, icon_size);
- pixbuf = nautilus_icon_info_get_pixbuf_at_size (icon_info, icon_size);
- image = gtk_image_new_from_pixbuf (pixbuf);
- g_object_unref (pixbuf);
- g_object_unref (icon_info);
+ image = gtk_image_new_from_gicon (icon, GTK_ICON_SIZE_BUTTON);
} else {
image = NULL;
}
@@ -134,19 +154,7 @@ nautilus_x_content_bar_set_x_content_type (NautilusXContentBar *bar, const char
g_free (description);
}
-const char *
-nautilus_x_content_bar_get_x_content_type (NautilusXContentBar *bar)
-{
- return bar->priv->x_content_type;
-}
-
-GMount *
-nautilus_x_content_bar_get_mount (NautilusXContentBar *bar)
-{
- return bar->priv->mount != NULL ? g_object_ref (bar->priv->mount) : NULL;
-}
-
-void
+static void
nautilus_x_content_bar_set_mount (NautilusXContentBar *bar, GMount *mount)
{
if (bar->priv->mount != NULL) {
@@ -246,42 +254,23 @@ nautilus_x_content_bar_class_init (NautilusXContentBarClass *klass)
}
static void
-button_clicked_callback (GtkWidget *button, NautilusXContentBar *bar)
-{
- GAppInfo *default_app;
-
- if (bar->priv->x_content_type == NULL ||
- bar->priv->mount == NULL)
- return;
-
- default_app = g_app_info_get_default_for_type (bar->priv->x_content_type, FALSE);
- if (default_app != NULL) {
- nautilus_launch_application_for_mount (default_app, bar->priv->mount,
- GTK_WINDOW (gtk_widget_get_toplevel (button)));
- g_object_unref (default_app);
- }
-}
-
-static void
nautilus_x_content_bar_init (NautilusXContentBar *bar)
{
- GtkWidget *hbox;
-
bar->priv = NAUTILUS_X_CONTENT_BAR_GET_PRIVATE (bar);
- hbox = GTK_WIDGET (bar);
-
bar->priv->label = gtk_label_new (NULL);
+ gtk_style_context_add_class (gtk_widget_get_style_context (bar->priv->label),
+ "nautilus-cluebar-label");
gtk_label_set_ellipsize (GTK_LABEL (bar->priv->label), PANGO_ELLIPSIZE_END);
gtk_misc_set_alignment (GTK_MISC (bar->priv->label), 0.0, 0.5);
- gtk_box_pack_start (GTK_BOX (bar), bar->priv->label, TRUE, TRUE, 0);
+ gtk_container_add (GTK_CONTAINER (bar), bar->priv->label);
- bar->priv->button = gtk_button_new ();
- gtk_box_pack_end (GTK_BOX (hbox), bar->priv->button, FALSE, FALSE, 0);
+ bar->priv->button = gtk_info_bar_add_button (GTK_INFO_BAR (bar),
+ "",
+ CONTENT_BAR_RESPONSE_APP);
- g_signal_connect (bar->priv->button,
- "clicked",
- G_CALLBACK (button_clicked_callback),
+ g_signal_connect (bar, "response",
+ G_CALLBACK (content_bar_response_cb),
bar);
}
@@ -289,12 +278,8 @@ GtkWidget *
nautilus_x_content_bar_new (GMount *mount,
const char *x_content_type)
{
- GObject *bar;
-
- bar = g_object_new (NAUTILUS_TYPE_X_CONTENT_BAR,
- "mount", mount,
- "x-content-type", x_content_type,
- NULL);
-
- return GTK_WIDGET (bar);
+ return g_object_new (NAUTILUS_TYPE_X_CONTENT_BAR,
+ "mount", mount,
+ "x-content-type", x_content_type,
+ NULL);
}
diff --git a/src/nautilus-x-content-bar.h b/src/nautilus-x-content-bar.h
index 922cb19..c266de4 100644
--- a/src/nautilus-x-content-bar.h
+++ b/src/nautilus-x-content-bar.h
@@ -41,26 +41,20 @@ typedef struct NautilusXContentBarPrivate NautilusXContentBarPrivate;
typedef struct
{
- GtkHBox box;
+ GtkInfoBar parent;
NautilusXContentBarPrivate *priv;
} NautilusXContentBar;
typedef struct
{
- GtkHBoxClass parent_class;
+ GtkInfoBarClass parent_class;
} NautilusXContentBarClass;
GType nautilus_x_content_bar_get_type (void) G_GNUC_CONST;
GtkWidget *nautilus_x_content_bar_new (GMount *mount,
const char *x_content_type);
-const char *nautilus_x_content_bar_get_x_content_type (NautilusXContentBar *bar);
-void nautilus_x_content_bar_set_x_content_type (NautilusXContentBar *bar,
- const char *x_content_type);
-void nautilus_x_content_bar_set_mount (NautilusXContentBar *bar,
- GMount *mount);
-GMount *nautilus_x_content_bar_get_mount (NautilusXContentBar *bar);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]