summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJasmine Hassan <[email protected]>2012-10-29 06:38:41 +0200
committerJasmine Hassan <[email protected]>2012-10-29 15:21:56 +0200
commit7b59638eafc0950ac4778d144558311abfc4dcf6 (patch)
tree6440608629a71acede3d22e883d21e32b8f34e59
parentdc95eb7d3665927604cfd582dbc2027655fd6c7d (diff)
downloadmate-user-share-7b59638eafc0950ac4778d144558311abfc4dcf6.tar.bz2
mate-user-share-7b59638eafc0950ac4778d144558311abfc4dcf6.tar.xz
[share-bar] make it a (improved) GtkInfoBar
1. Instead of a GtkBox. This fixes the different appearance of the bar from the rest of the stock Nautilus bars. http://git.gnome.org/browse/gnome-user-share/commit/?id=1cfba2417317e5059635568cb49e5093e989e4fa => Note: Don't use GTK3 functions: gtk_box_new(), gtk_widget_set_halign() Stick with gtk_vbox_new() and gtk_misc_set_alignment(), for now. 2. share-bar: remove unused nautilus_share_bar_get_button() http://git.gnome.org/browse/gnome-user-share/commit/?id=71f364b6646a470e829f87bb1f076ca360fc24c5 3. share-bar: make the label property write only http://git.gnome.org/browse/gnome-user-share/commit/?id=c307a0196399f0ff29be4a7a4fad0a6c43a22e1b 4. share-bar: don't set italic text http://git.gnome.org/browse/gnome-user-share/commit/?id=05df1dd95aef7b164932d89d91004df264bbdbe4 5. Improve the nautilus cluebar (text more concise and bar more compact) http://git.gnome.org/browse/gnome-user-share/commit/?id=8ae76ce81119e63ac6fdfdd537d256bf82069e0a 6. share-bar: remove empty finalize method http://git.gnome.org/browse/gnome-user-share/commit/?id=d1c1de37ba47b723a43c0adff9f78a2fa56e45ae
-rw-r--r--src/caja-share-bar.c158
-rw-r--r--src/caja-share-bar.h6
-rw-r--r--src/share-extension.c19
3 files changed, 55 insertions, 128 deletions
diff --git a/src/caja-share-bar.c b/src/caja-share-bar.c
index df2d6a7..c1e0c06 100644
--- a/src/caja-share-bar.c
+++ b/src/caja-share-bar.c
@@ -27,15 +27,11 @@
#include "caja-share-bar.h"
-static void caja_share_bar_finalize (GObject *object);
-
#define CAJA_SHARE_BAR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CAJA_TYPE_SHARE_BAR, CajaShareBarPrivate))
struct CajaShareBarPrivate
{
- GtkWidget *button;
- GtkWidget *label;
- char *str;
+ GtkWidget *label;
};
enum {
@@ -43,26 +39,7 @@ enum {
PROP_LABEL
};
-enum {
- ACTIVATE,
- LAST_SIGNAL
-};
-
-static guint signals [LAST_SIGNAL] = { 0, };
-
-G_DEFINE_TYPE (CajaShareBar, caja_share_bar, GTK_TYPE_HBOX)
-
-GtkWidget *
-caja_share_bar_get_button (CajaShareBar *bar)
-{
- GtkWidget *button;
-
- g_return_val_if_fail (bar != NULL, NULL);
-
- button = bar->priv->button;
-
- return button;
-}
+G_DEFINE_TYPE (CajaShareBar, caja_share_bar, GTK_TYPE_INFO_BAR)
static void
caja_share_bar_set_property (GObject *object,
@@ -76,11 +53,8 @@ caja_share_bar_set_property (GObject *object,
switch (prop_id) {
case PROP_LABEL: {
- char *str;
- g_free (self->priv->str);
- str = g_strdup_printf ("<i>%s</i>", g_value_get_string (value));
- gtk_label_set_markup (GTK_LABEL (self->priv->label), str);
- self->priv->str = g_value_dup_string (value);
+ gtk_label_set_text (GTK_LABEL (self->priv->label),
+ g_value_get_string (value));
break;
}
default:
@@ -90,116 +64,63 @@ caja_share_bar_set_property (GObject *object,
}
static void
-caja_share_bar_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- CajaShareBar *self;
-
- self = CAJA_SHARE_BAR (object);
-
- switch (prop_id) {
- case PROP_LABEL:
- g_value_set_string (value, self->priv->str);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
caja_share_bar_class_init (CajaShareBarClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- object_class->finalize = caja_share_bar_finalize;
- object_class->get_property = caja_share_bar_get_property;
object_class->set_property = caja_share_bar_set_property;
g_type_class_add_private (klass, sizeof (CajaShareBarPrivate));
- g_object_class_install_property (G_OBJECT_CLASS(klass),
- PROP_LABEL, g_param_spec_string ("label",
- "label", "The widget's main label", NULL, G_PARAM_READWRITE));
-
-
- signals [ACTIVATE] = g_signal_new ("activate",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (CajaShareBarClass, activate),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
-
-}
-
-static void
-button_clicked_cb (GtkWidget *button,
- CajaShareBar *bar)
-{
- g_signal_emit (bar, signals [ACTIVATE], 0);
+ g_object_class_install_property (G_OBJECT_CLASS(klass), PROP_LABEL,
+ g_param_spec_string ("label", "label",
+ "The widget's main label",
+ NULL,
+ G_PARAM_WRITABLE));
}
static void
caja_share_bar_init (CajaShareBar *bar)
{
- GtkWidget *label;
- GtkWidget *hbox;
- GtkWidget *vbox;
- GtkWidget *image;
- char *hint;
-
- bar->priv = CAJA_SHARE_BAR_GET_PRIVATE (bar);
-
- hbox = GTK_WIDGET (bar);
-
- vbox = gtk_vbox_new (FALSE, 6);
- gtk_widget_show (vbox);
- gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
+ GtkWidget *content_area;
+ GtkWidget *action_area;
+ GtkWidget *label;
+ GtkWidget *vbox;
+ GtkWidget *button;
+ PangoAttrList *attrs;
- label = gtk_label_new (_("Personal File Sharing"));
- gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
- gtk_widget_show (label);
- gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0);
+ bar->priv = CAJA_SHARE_BAR_GET_PRIVATE (bar);
- bar->priv->label = gtk_label_new ("");
- hint = g_strdup_printf ("<i>%s</i>", "");
- gtk_label_set_markup (GTK_LABEL (bar->priv->label), hint);
- gtk_misc_set_alignment (GTK_MISC (bar->priv->label), 0.0, 0.5);
- gtk_widget_show (bar->priv->label);
- gtk_box_pack_start (GTK_BOX (vbox), bar->priv->label, TRUE, TRUE, 0);
+ content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (bar));
+ action_area = gtk_info_bar_get_action_area (GTK_INFO_BAR (bar));
+ gtk_button_box_set_layout (GTK_BUTTON_BOX (action_area), GTK_BUTTONBOX_CENTER);
- bar->priv->button = gtk_button_new_with_label (_("Launch Preferences"));
- gtk_widget_show (bar->priv->button);
- gtk_box_pack_end (GTK_BOX (hbox), bar->priv->button, FALSE, FALSE, 0);
+ vbox = gtk_vbox_new (FALSE, 3);
+ gtk_container_add (GTK_CONTAINER (content_area), vbox);
- image = gtk_image_new_from_icon_name ("folder-remote", GTK_ICON_SIZE_BUTTON);
- gtk_widget_show (image);
- gtk_button_set_image (GTK_BUTTON (bar->priv->button), image);
+ attrs = pango_attr_list_new ();
+ pango_attr_list_insert (attrs, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
+ label = gtk_label_new (_("Personal File Sharing"));
+ gtk_label_set_attributes (GTK_LABEL (label), attrs);
+ pango_attr_list_unref (attrs);
- g_signal_connect (bar->priv->button, "clicked",
- G_CALLBACK (button_clicked_cb),
- bar);
-
- gtk_widget_set_tooltip_text (bar->priv->button,
- _("Launch Personal File Sharing Preferences"));
-}
-
-static void
-caja_share_bar_finalize (GObject *object)
-{
- CajaShareBar *bar;
+ gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+ gtk_widget_show (label);
+ gtk_container_add (GTK_CONTAINER (vbox), label);
- g_return_if_fail (object != NULL);
- g_return_if_fail (CAJA_IS_SHARE_BAR (object));
+ bar->priv->label = gtk_label_new (NULL);
+ gtk_misc_set_alignment (GTK_MISC (bar->priv->label), 0.0, 0.5);
+ gtk_widget_show (bar->priv->label);
+ gtk_container_add (GTK_CONTAINER (vbox), bar->priv->label);
- bar = CAJA_SHARE_BAR (object);
+ button = gtk_info_bar_add_button (GTK_INFO_BAR (bar),
+ _("Preferences"),
+ CAJA_SHARE_BAR_RESPONSE_PREFERENCES);
- g_return_if_fail (bar->priv != NULL);
+ gtk_widget_set_tooltip_text (button,
+ _("Launch Personal File Sharing Preferences"));
- G_OBJECT_CLASS (caja_share_bar_parent_class)->finalize (object);
+ gtk_widget_show_all (vbox);
}
GtkWidget *
@@ -208,6 +129,7 @@ caja_share_bar_new (const char *label)
GObject *result;
result = g_object_new (CAJA_TYPE_SHARE_BAR,
+ "message-type", GTK_MESSAGE_QUESTION,
"label", label,
NULL);
diff --git a/src/caja-share-bar.h b/src/caja-share-bar.h
index ae738fa..a4e05fd 100644
--- a/src/caja-share-bar.h
+++ b/src/caja-share-bar.h
@@ -34,18 +34,20 @@ G_BEGIN_DECLS
#define CAJA_IS_SHARE_BAR_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), CAJA_TYPE_SHARE_BAR))
#define CAJA_SHARE_BAR_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), CAJA_TYPE_SHARE_BAR, CajaShareBarClass))
+#define CAJA_SHARE_BAR_RESPONSE_PREFERENCES 1
+
typedef struct CajaShareBarPrivate CajaShareBarPrivate;
typedef struct
{
- GtkHBox box;
+ GtkInfoBar parent;
CajaShareBarPrivate *priv;
} CajaShareBar;
typedef struct
{
- GtkHBoxClass parent_class;
+ GtkInfoBarClass parent_class;
void (* activate) (CajaShareBar *bar);
diff --git a/src/share-extension.c b/src/share-extension.c
index 83fb36f..01a574a 100644
--- a/src/share-extension.c
+++ b/src/share-extension.c
@@ -104,10 +104,13 @@ launch_prefs_on_window (GtkWindow *window)
}
static void
-bar_activated_cb (CajaShareBar *bar,
- gpointer data)
+bar_response_cb (CajaShareBar *bar,
+ gint response,
+ gpointer data)
{
- launch_prefs_on_window (GTK_WINDOW (data));
+ if (response == CAJA_SHARE_BAR_RESPONSE_PREFERENCES) {
+ launch_prefs_on_window (GTK_WINDOW (data));
+ }
}
static void
@@ -170,17 +173,17 @@ caja_user_share_get_location_widget (CajaLocationWidgetProvider *iface,
share = CAJA_USER_SHARE (iface);
if (is_dir[0] != FALSE && is_dir[1] != FALSE) {
- bar = caja_share_bar_new (_("You can share files from this folder and receive files to it"));
+ bar = caja_share_bar_new (_("May be used to share or receive files"));
} else if (is_dir[0] != FALSE) {
- bar = caja_share_bar_new (_("You can share files from this folder over the network and Bluetooth"));
+ bar = caja_share_bar_new (_("May be shared over the network or Bluetooth"));
} else {
- bar = caja_share_bar_new (_("You can receive files over Bluetooth into this folder"));
+ bar = caja_share_bar_new (_("May be used to receive files over Bluetooth"));
}
add_widget (share, caja_share_bar_get_button (CAJA_SHARE_BAR (bar)));
- g_signal_connect (bar, "activate",
- G_CALLBACK (bar_activated_cb),
+ g_signal_connect (bar, "response",
+ G_CALLBACK (bar_response_cb),
window);
gtk_widget_show (bar);