xed-progress-message-area.c: Clean up code style

This commit is contained in:
JosephMcc 2017-01-07 04:13:12 -08:00
parent 01ace1d02f
commit a1671a6227
1 changed files with 118 additions and 128 deletions

View File

@ -2,7 +2,7 @@
* xed-progress-message-area.c * xed-progress-message-area.c
* This file is part of xed * This file is part of xed
* *
* Copyright (C) 2005 - Paolo Maggi * Copyright (C) 2005 - Paolo Maggi
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -16,20 +16,20 @@
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, * Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA. * Boston, MA 02110-1301, USA.
*/ */
/* /*
* Modified by the xed Team, 2005. See the AUTHORS file for a * Modified by the xed Team, 2005. See the AUTHORS file for a
* list of people on the xed Team. * list of people on the xed Team.
* See the ChangeLog files for a list of changes. * See the ChangeLog files for a list of changes.
* *
* $Id$ * $Id$
*/ */
/* TODO: add properties */ /* TODO: add properties */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include <config.h> #include <config.h>
#endif #endif
@ -40,9 +40,10 @@
#include "xed-progress-message-area.h" #include "xed-progress-message-area.h"
enum { enum
PROP_0, {
PROP_HAS_CANCEL_BUTTON PROP_0,
PROP_HAS_CANCEL_BUTTON
}; };
@ -50,194 +51,183 @@ enum {
struct _XedProgressMessageAreaPrivate struct _XedProgressMessageAreaPrivate
{ {
GtkWidget *image; GtkWidget *image;
GtkWidget *label; GtkWidget *label;
GtkWidget *progress; GtkWidget *progress;
}; };
G_DEFINE_TYPE(XedProgressMessageArea, xed_progress_message_area, GTK_TYPE_INFO_BAR) G_DEFINE_TYPE(XedProgressMessageArea, xed_progress_message_area, GTK_TYPE_INFO_BAR)
static void static void
xed_progress_message_area_set_has_cancel_button (XedProgressMessageArea *area, xed_progress_message_area_set_has_cancel_button (XedProgressMessageArea *area,
gboolean has_button) gboolean has_button)
{ {
if (has_button) if (has_button)
gtk_info_bar_add_button (GTK_INFO_BAR (area), {
GTK_STOCK_CANCEL, gtk_info_bar_add_button (GTK_INFO_BAR (area), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
GTK_RESPONSE_CANCEL); }
g_object_notify (G_OBJECT (area), "has-cancel-button"); g_object_notify (G_OBJECT (area), "has-cancel-button");
} }
static void static void
xed_progress_message_area_set_property (GObject *object, xed_progress_message_area_set_property (GObject *object,
guint prop_id, guint prop_id,
const GValue *value, const GValue *value,
GParamSpec *pspec) GParamSpec *pspec)
{ {
XedProgressMessageArea *area; XedProgressMessageArea *area;
area = XED_PROGRESS_MESSAGE_AREA (object); area = XED_PROGRESS_MESSAGE_AREA (object);
switch (prop_id) switch (prop_id)
{ {
case PROP_HAS_CANCEL_BUTTON: case PROP_HAS_CANCEL_BUTTON:
xed_progress_message_area_set_has_cancel_button (area, xed_progress_message_area_set_has_cancel_button (area, g_value_get_boolean (value));
g_value_get_boolean (value)); break;
break; default:
default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break;
break; }
}
} }
static void static void
xed_progress_message_area_get_property (GObject *object, xed_progress_message_area_get_property (GObject *object,
guint prop_id, guint prop_id,
GValue *value, GValue *value,
GParamSpec *pspec) GParamSpec *pspec)
{ {
switch (prop_id) switch (prop_id)
{ {
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
} }
} }
static void static void
xed_progress_message_area_class_init (XedProgressMessageAreaClass *klass) xed_progress_message_area_class_init (XedProgressMessageAreaClass *klass)
{ {
GObjectClass *gobject_class = G_OBJECT_CLASS (klass); GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->set_property = xed_progress_message_area_set_property; gobject_class->set_property = xed_progress_message_area_set_property;
gobject_class->get_property = xed_progress_message_area_get_property; gobject_class->get_property = xed_progress_message_area_get_property;
g_object_class_install_property (gobject_class, g_object_class_install_property (gobject_class,
PROP_HAS_CANCEL_BUTTON, PROP_HAS_CANCEL_BUTTON,
g_param_spec_boolean ("has-cancel-button", g_param_spec_boolean ("has-cancel-button",
"Has Cancel Button", "Has Cancel Button",
"If the message area has a cancel button", "If the message area has a cancel button",
TRUE, TRUE,
G_PARAM_WRITABLE | G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS)); G_PARAM_STATIC_STRINGS));
g_type_class_add_private (gobject_class, sizeof(XedProgressMessageAreaPrivate)); g_type_class_add_private (gobject_class, sizeof(XedProgressMessageAreaPrivate));
} }
static void static void
xed_progress_message_area_init (XedProgressMessageArea *area) xed_progress_message_area_init (XedProgressMessageArea *area)
{ {
GtkWidget *vbox; GtkWidget *vbox;
GtkWidget *hbox; GtkWidget *hbox;
area->priv = XED_PROGRESS_MESSAGE_AREA_GET_PRIVATE (area);
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
gtk_widget_show (vbox);
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4); area->priv = XED_PROGRESS_MESSAGE_AREA_GET_PRIVATE (area);
gtk_widget_show (hbox);
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
area->priv->image = gtk_image_new_from_icon_name (GTK_STOCK_MISSING_IMAGE, vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
GTK_ICON_SIZE_SMALL_TOOLBAR); gtk_widget_show (vbox);
gtk_widget_show (area->priv->image);
gtk_widget_set_halign (area->priv->image, GTK_ALIGN_CENTER);
gtk_widget_set_valign (area->priv->image, GTK_ALIGN_CENTER);
gtk_box_pack_start (GTK_BOX (hbox), area->priv->image, FALSE, FALSE, 4);
area->priv->label = gtk_label_new ("");
gtk_widget_show (area->priv->label);
gtk_box_pack_start (GTK_BOX (hbox), area->priv->label, TRUE, TRUE, 0);
gtk_label_set_use_markup (GTK_LABEL (area->priv->label), TRUE);
gtk_misc_set_alignment (GTK_MISC (area->priv->label), 0.0, 0.5);
gtk_label_set_ellipsize (GTK_LABEL (area->priv->label),
PANGO_ELLIPSIZE_END);
area->priv->progress = gtk_progress_bar_new (); hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
gtk_widget_show (area->priv->progress); gtk_widget_show (hbox);
gtk_box_pack_start (GTK_BOX (vbox), area->priv->progress, TRUE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
gtk_widget_set_size_request (area->priv->progress, -1, 15);
GtkWidget *content; area->priv->image = gtk_image_new_from_icon_name (GTK_STOCK_MISSING_IMAGE, GTK_ICON_SIZE_SMALL_TOOLBAR);
gtk_widget_show (area->priv->image);
content = gtk_info_bar_get_content_area (GTK_INFO_BAR (area)); gtk_widget_set_halign (area->priv->image, GTK_ALIGN_CENTER);
gtk_container_add (GTK_CONTAINER (content), vbox); gtk_widget_set_valign (area->priv->image, GTK_ALIGN_CENTER);
gtk_box_pack_start (GTK_BOX (hbox), area->priv->image, FALSE, FALSE, 4);
area->priv->label = gtk_label_new ("");
gtk_widget_show (area->priv->label);
gtk_box_pack_start (GTK_BOX (hbox), area->priv->label, TRUE, TRUE, 0);
gtk_label_set_use_markup (GTK_LABEL (area->priv->label), TRUE);
gtk_misc_set_alignment (GTK_MISC (area->priv->label), 0.0, 0.5);
gtk_label_set_ellipsize (GTK_LABEL (area->priv->label), PANGO_ELLIPSIZE_END);
area->priv->progress = gtk_progress_bar_new ();
gtk_widget_show (area->priv->progress);
gtk_box_pack_start (GTK_BOX (vbox), area->priv->progress, TRUE, FALSE, 0);
gtk_widget_set_size_request (area->priv->progress, -1, 15);
GtkWidget *content;
content = gtk_info_bar_get_content_area (GTK_INFO_BAR (area));
gtk_container_add (GTK_CONTAINER (content), vbox);
} }
GtkWidget * GtkWidget *
xed_progress_message_area_new (const gchar *stock_id, xed_progress_message_area_new (const gchar *stock_id,
const gchar *markup, const gchar *markup,
gboolean has_cancel) gboolean has_cancel)
{ {
XedProgressMessageArea *area; XedProgressMessageArea *area;
g_return_val_if_fail (stock_id != NULL, NULL); g_return_val_if_fail (stock_id != NULL, NULL);
g_return_val_if_fail (markup != NULL, NULL); g_return_val_if_fail (markup != NULL, NULL);
area = XED_PROGRESS_MESSAGE_AREA (g_object_new (XED_TYPE_PROGRESS_MESSAGE_AREA, area = XED_PROGRESS_MESSAGE_AREA (g_object_new (XED_TYPE_PROGRESS_MESSAGE_AREA,
"has-cancel-button", has_cancel, "has-cancel-button", has_cancel,
NULL)); NULL));
xed_progress_message_area_set_stock_image (area, xed_progress_message_area_set_stock_image (area, stock_id);
stock_id); xed_progress_message_area_set_markup (area, markup);
xed_progress_message_area_set_markup (area, return GTK_WIDGET (area);
markup);
return GTK_WIDGET (area);
} }
void void
xed_progress_message_area_set_stock_image (XedProgressMessageArea *area, xed_progress_message_area_set_stock_image (XedProgressMessageArea *area,
const gchar *stock_id) const gchar *stock_id)
{ {
g_return_if_fail (XED_IS_PROGRESS_MESSAGE_AREA (area)); g_return_if_fail (XED_IS_PROGRESS_MESSAGE_AREA (area));
g_return_if_fail (stock_id != NULL); g_return_if_fail (stock_id != NULL);
gtk_image_set_from_stock (GTK_IMAGE (area->priv->image), gtk_image_set_from_stock (GTK_IMAGE (area->priv->image), stock_id, GTK_ICON_SIZE_SMALL_TOOLBAR);
stock_id,
GTK_ICON_SIZE_SMALL_TOOLBAR);
} }
void void
xed_progress_message_area_set_markup (XedProgressMessageArea *area, xed_progress_message_area_set_markup (XedProgressMessageArea *area,
const gchar *markup) const gchar *markup)
{ {
g_return_if_fail (XED_IS_PROGRESS_MESSAGE_AREA (area)); g_return_if_fail (XED_IS_PROGRESS_MESSAGE_AREA (area));
g_return_if_fail (markup != NULL); g_return_if_fail (markup != NULL);
gtk_label_set_markup (GTK_LABEL (area->priv->label), gtk_label_set_markup (GTK_LABEL (area->priv->label), markup);
markup);
} }
void void
xed_progress_message_area_set_text (XedProgressMessageArea *area, xed_progress_message_area_set_text (XedProgressMessageArea *area,
const gchar *text) const gchar *text)
{ {
g_return_if_fail (XED_IS_PROGRESS_MESSAGE_AREA (area)); g_return_if_fail (XED_IS_PROGRESS_MESSAGE_AREA (area));
g_return_if_fail (text != NULL); g_return_if_fail (text != NULL);
gtk_label_set_text (GTK_LABEL (area->priv->label), gtk_label_set_text (GTK_LABEL (area->priv->label), text);
text);
} }
void void
xed_progress_message_area_set_fraction (XedProgressMessageArea *area, xed_progress_message_area_set_fraction (XedProgressMessageArea *area,
gdouble fraction) gdouble fraction)
{ {
g_return_if_fail (XED_IS_PROGRESS_MESSAGE_AREA (area)); g_return_if_fail (XED_IS_PROGRESS_MESSAGE_AREA (area));
gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (area->priv->progress), gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (area->priv->progress), fraction);
fraction);
} }
void void
xed_progress_message_area_pulse (XedProgressMessageArea *area) xed_progress_message_area_pulse (XedProgressMessageArea *area)
{ {
g_return_if_fail (XED_IS_PROGRESS_MESSAGE_AREA (area)); g_return_if_fail (XED_IS_PROGRESS_MESSAGE_AREA (area));
gtk_progress_bar_pulse (GTK_PROGRESS_BAR (area->priv->progress)); gtk_progress_bar_pulse (GTK_PROGRESS_BAR (area->priv->progress));
} }