Commit cad0a3e0 authored by Vyas Giridharan's avatar Vyas Giridharan Committed by Ernestas Kulik

floating-bar: port to GLib type declaration macros.

Porting Nautilus object declarations to G_DECLARE_*_TYPE will
reduce a huge number of boilerplate code.

That will make nautilus code easier for newcomers and others alike.

https://bugzilla.gnome.org/show_bug.cgi?id=786815
parent 560e5c2d
......@@ -27,8 +27,10 @@
#define HOVER_HIDE_TIMEOUT_INTERVAL 100
struct _NautilusFloatingBarDetails
struct _NautilusFloatingBar
{
GtkBox parent;
gchar *primary_label;
gchar *details_label;
......@@ -78,8 +80,8 @@ nautilus_floating_bar_finalize (GObject *obj)
NautilusFloatingBar *self = NAUTILUS_FLOATING_BAR (obj);
nautilus_floating_bar_remove_hover_timeout (self);
g_free (self->priv->primary_label);
g_free (self->priv->details_label);
g_free (self->primary_label);
g_free (self->details_label);
G_OBJECT_CLASS (nautilus_floating_bar_parent_class)->finalize (obj);
}
......@@ -96,19 +98,19 @@ nautilus_floating_bar_get_property (GObject *object,
{
case PROP_PRIMARY_LABEL:
{
g_value_set_string (value, self->priv->primary_label);
g_value_set_string (value, self->primary_label);
}
break;
case PROP_DETAILS_LABEL:
{
g_value_set_string (value, self->priv->details_label);
g_value_set_string (value, self->details_label);
}
break;
case PROP_SHOW_SPINNER:
{
g_value_set_boolean (value, self->priv->show_spinner);
g_value_set_boolean (value, self->show_spinner);
}
break;
......@@ -161,27 +163,27 @@ update_labels (NautilusFloatingBar *self)
{
gboolean primary_visible, details_visible;
primary_visible = (self->priv->primary_label != NULL) &&
(strlen (self->priv->primary_label) > 0);
details_visible = (self->priv->details_label != NULL) &&
(strlen (self->priv->details_label) > 0);
primary_visible = (self->primary_label != NULL) &&
(strlen (self->primary_label) > 0);
details_visible = (self->details_label != NULL) &&
(strlen (self->details_label) > 0);
gtk_label_set_text (GTK_LABEL (self->priv->primary_label_widget),
self->priv->primary_label);
gtk_widget_set_visible (self->priv->primary_label_widget, primary_visible);
gtk_label_set_text (GTK_LABEL (self->primary_label_widget),
self->primary_label);
gtk_widget_set_visible (self->primary_label_widget, primary_visible);
gtk_label_set_text (GTK_LABEL (self->priv->details_label_widget),
self->priv->details_label);
gtk_widget_set_visible (self->priv->details_label_widget, details_visible);
gtk_label_set_text (GTK_LABEL (self->details_label_widget),
self->details_label);
gtk_widget_set_visible (self->details_label_widget, details_visible);
}
void
nautilus_floating_bar_remove_hover_timeout (NautilusFloatingBar *self)
{
if (self->priv->hover_timeout_id != 0)
if (self->hover_timeout_id != 0)
{
g_source_remove (self->priv->hover_timeout_id);
self->priv->hover_timeout_id = 0;
g_source_remove (self->hover_timeout_id);
self->hover_timeout_id = 0;
}
}
......@@ -212,7 +214,7 @@ check_pointer_timeout (gpointer user_data)
if (pointer_y == -1 || pointer_y < data->y_down_limit || pointer_y > data->y_upper_limit)
{
gtk_widget_show (data->floating_bar);
NAUTILUS_FLOATING_BAR (data->floating_bar)->priv->hover_timeout_id = 0;
NAUTILUS_FLOATING_BAR (data->floating_bar)->hover_timeout_id = 0;
return G_SOURCE_REMOVE;
}
......@@ -235,9 +237,9 @@ overlay_enter_notify_cb (GtkWidget *parent,
NautilusFloatingBar *self = NAUTILUS_FLOATING_BAR (widget);
if (self->priv->hover_timeout_id != 0)
if (self->hover_timeout_id != 0)
{
g_source_remove (self->priv->hover_timeout_id);
g_source_remove (self->hover_timeout_id);
}
if (event->window != gtk_widget_get_window (widget))
......@@ -245,7 +247,7 @@ overlay_enter_notify_cb (GtkWidget *parent,
return GDK_EVENT_PROPAGATE;
}
if (NAUTILUS_FLOATING_BAR (widget)->priv->is_interactive)
if (NAUTILUS_FLOATING_BAR (widget)->is_interactive)
{
return GDK_EVENT_PROPAGATE;
}
......@@ -259,11 +261,11 @@ overlay_enter_notify_cb (GtkWidget *parent,
data->y_down_limit = y_pos;
data->y_upper_limit = y_pos + gtk_widget_get_allocated_height (widget);
self->priv->hover_timeout_id = g_timeout_add_full (G_PRIORITY_DEFAULT, HOVER_HIDE_TIMEOUT_INTERVAL,
check_pointer_timeout, data,
check_pointer_data_free);
self->hover_timeout_id = g_timeout_add_full (G_PRIORITY_DEFAULT, HOVER_HIDE_TIMEOUT_INTERVAL,
check_pointer_timeout, data,
check_pointer_data_free);
g_source_set_name_by_id (self->priv->hover_timeout_id, "[nautilus-floating-bar] overlay_enter_notify_cb");
g_source_set_name_by_id (self->hover_timeout_id, "[nautilus-floating-bar] overlay_enter_notify_cb");
return GDK_EVENT_STOP;
}
......@@ -392,9 +394,9 @@ nautilus_floating_bar_constructed (GObject *obj)
w = gtk_spinner_new ();
gtk_box_pack_start (GTK_BOX (box), w, FALSE, FALSE, 0);
gtk_widget_set_visible (w, self->priv->show_spinner);
gtk_widget_set_visible (w, self->show_spinner);
gtk_spinner_start (GTK_SPINNER (w));
self->priv->spinner = w;
self->spinner = w;
gtk_widget_set_size_request (w, 16, 16);
gtk_widget_set_margin_start (w, 8);
......@@ -413,13 +415,13 @@ nautilus_floating_bar_constructed (GObject *obj)
gtk_label_set_ellipsize (GTK_LABEL (w), PANGO_ELLIPSIZE_MIDDLE);
gtk_label_set_single_line_mode (GTK_LABEL (w), TRUE);
gtk_container_add (GTK_CONTAINER (labels_box), w);
self->priv->primary_label_widget = w;
self->primary_label_widget = w;
gtk_widget_show (w);
w = gtk_label_new (NULL);
gtk_label_set_single_line_mode (GTK_LABEL (w), TRUE);
gtk_container_add (GTK_CONTAINER (labels_box), w);
self->priv->details_label_widget = w;
self->details_label_widget = w;
gtk_widget_show (w);
}
......@@ -428,9 +430,6 @@ nautilus_floating_bar_init (NautilusFloatingBar *self)
{
GtkStyleContext *context;
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, NAUTILUS_TYPE_FLOATING_BAR,
NautilusFloatingBarDetails);
context = gtk_widget_get_style_context (GTK_WIDGET (self));
gtk_style_context_add_class (context, "floating-bar");
}
......@@ -480,7 +479,6 @@ nautilus_floating_bar_class_init (NautilusFloatingBarClass *klass)
G_TYPE_NONE, 1,
G_TYPE_INT);
g_type_class_add_private (klass, sizeof (NautilusFloatingBarDetails));
g_object_class_install_properties (oclass, NUM_PROPERTIES, properties);
}
......@@ -488,10 +486,10 @@ void
nautilus_floating_bar_set_primary_label (NautilusFloatingBar *self,
const gchar *label)
{
if (g_strcmp0 (self->priv->primary_label, label) != 0)
if (g_strcmp0 (self->primary_label, label) != 0)
{
g_free (self->priv->primary_label);
self->priv->primary_label = g_strdup (label);
g_free (self->primary_label);
self->primary_label = g_strdup (label);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_PRIMARY_LABEL]);
......@@ -503,10 +501,10 @@ void
nautilus_floating_bar_set_details_label (NautilusFloatingBar *self,
const gchar *label)
{
if (g_strcmp0 (self->priv->details_label, label) != 0)
if (g_strcmp0 (self->details_label, label) != 0)
{
g_free (self->priv->details_label);
self->priv->details_label = g_strdup (label);
g_free (self->details_label);
self->details_label = g_strdup (label);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_DETAILS_LABEL]);
......@@ -527,10 +525,10 @@ void
nautilus_floating_bar_set_show_spinner (NautilusFloatingBar *self,
gboolean show_spinner)
{
if (self->priv->show_spinner != show_spinner)
if (self->show_spinner != show_spinner)
{
self->priv->show_spinner = show_spinner;
gtk_widget_set_visible (self->priv->spinner,
self->show_spinner = show_spinner;
gtk_widget_set_visible (self->spinner,
show_spinner);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SHOW_SPINNER]);
......@@ -573,7 +571,7 @@ nautilus_floating_bar_add_action (NautilusFloatingBar *self,
g_signal_connect (button, "clicked",
G_CALLBACK (action_button_clicked_cb), self);
self->priv->is_interactive = TRUE;
self->is_interactive = TRUE;
}
void
......@@ -601,5 +599,5 @@ nautilus_floating_bar_cleanup_actions (NautilusFloatingBar *self)
g_list_free (children);
self->priv->is_interactive = FALSE;
self->is_interactive = FALSE;
}
......@@ -28,32 +28,7 @@
#define NAUTILUS_FLOATING_BAR_ACTION_ID_STOP 1
#define NAUTILUS_TYPE_FLOATING_BAR nautilus_floating_bar_get_type()
#define NAUTILUS_FLOATING_BAR(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), NAUTILUS_TYPE_FLOATING_BAR, NautilusFloatingBar))
#define NAUTILUS_FLOATING_BAR_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_FLOATING_BAR, NautilusFloatingBarClass))
#define NAUTILUS_IS_FLOATING_BAR(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), NAUTILUS_TYPE_FLOATING_BAR))
#define NAUTILUS_IS_FLOATING_BAR_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_FLOATING_BAR))
#define NAUTILUS_FLOATING_BAR_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS ((obj), NAUTILUS_TYPE_FLOATING_BAR, NautilusFloatingBarClass))
typedef struct _NautilusFloatingBar NautilusFloatingBar;
typedef struct _NautilusFloatingBarClass NautilusFloatingBarClass;
typedef struct _NautilusFloatingBarDetails NautilusFloatingBarDetails;
struct _NautilusFloatingBar {
GtkBox parent;
NautilusFloatingBarDetails *priv;
};
struct _NautilusFloatingBarClass {
GtkBoxClass parent_class;
};
/* GObject */
GType nautilus_floating_bar_get_type (void);
G_DECLARE_FINAL_TYPE (NautilusFloatingBar, nautilus_floating_bar, NAUTILUS, FLOATING_BAR, GtkBox)
GtkWidget * nautilus_floating_bar_new (const gchar *primary_label,
const gchar *details_label,
......
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