[epiphany] download-widget: Use G_DECLARE_FINAL_TYPE
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] download-widget: Use G_DECLARE_FINAL_TYPE
- Date: Wed, 10 Feb 2016 06:21:45 +0000 (UTC)
commit a83dfdef3b157cf508eee0299bd0ed4dfc7e7063
Author: Michael Catanzaro <mcatanzaro igalia com>
Date: Tue Feb 9 23:17:54 2016 -0600
download-widget: Use G_DECLARE_FINAL_TYPE
lib/widgets/ephy-download-widget.c | 159 +++++++++++++++++------------------
lib/widgets/ephy-download-widget.h | 27 +------
2 files changed, 80 insertions(+), 106 deletions(-)
---
diff --git a/lib/widgets/ephy-download-widget.c b/lib/widgets/ephy-download-widget.c
index 77cb30d..687212b 100644
--- a/lib/widgets/ephy-download-widget.c
+++ b/lib/widgets/ephy-download-widget.c
@@ -31,13 +31,10 @@
#include <glib/gi18n.h>
#include <webkit2/webkit2.h>
-G_DEFINE_TYPE (EphyDownloadWidget, ephy_download_widget, GTK_TYPE_GRID)
-
-#define DOWNLOAD_WIDGET_PRIVATE(o) \
- (G_TYPE_INSTANCE_GET_PRIVATE ((o), EPHY_TYPE_DOWNLOAD_WIDGET, EphyDownloadWidgetPrivate))
-
-struct _EphyDownloadWidgetPrivate
+struct _EphyDownloadWidget
{
+ GtkGrid parent_instance;
+
EphyDownload *download;
GtkWidget *filename;
@@ -47,6 +44,8 @@ struct _EphyDownloadWidgetPrivate
GtkWidget *action_button;
};
+G_DEFINE_TYPE (EphyDownloadWidget, ephy_download_widget, GTK_TYPE_GRID)
+
enum
{
PROP_0,
@@ -137,13 +136,13 @@ update_download_icon (EphyDownloadWidget *widget)
GIcon *icon;
const char *content_type;
- content_type = ephy_download_get_content_type (widget->priv->download);
+ content_type = ephy_download_get_content_type (widget->download);
if (content_type)
icon = g_content_type_get_icon (content_type);
else
icon = g_icon_new_for_string ("package-x-generic", NULL);
- gtk_image_set_from_gicon (GTK_IMAGE (widget->priv->icon), icon, GTK_ICON_SIZE_DIALOG);
+ gtk_image_set_from_gicon (GTK_IMAGE (widget->icon), icon, GTK_ICON_SIZE_DIALOG);
g_object_unref (icon);
}
@@ -153,12 +152,12 @@ update_download_destination (EphyDownloadWidget *widget)
char *dest;
char *markup;
- dest = get_destination_basename_from_download (widget->priv->download);
+ dest = get_destination_basename_from_download (widget->download);
if (!dest)
return;
markup = g_markup_printf_escaped ("<b>%s</b>", dest);
g_free (dest);
- gtk_label_set_markup (GTK_LABEL (widget->priv->filename), markup);
+ gtk_label_set_markup (GTK_LABEL (widget->filename), markup);
g_free (markup);
}
@@ -169,7 +168,7 @@ update_status_label (EphyDownloadWidget *widget,
char *markup;
markup = g_markup_printf_escaped ("<span size='small'>%s</span>", download_label);
- gtk_label_set_markup (GTK_LABEL (widget->priv->status), markup);
+ gtk_label_set_markup (GTK_LABEL (widget->status), markup);
g_free (markup);
}
@@ -209,11 +208,11 @@ download_progress_cb (WebKitDownload *download,
g_free (total);
g_free (remaining);
- gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (widget->priv->progress),
+ gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (widget->progress),
progress);
} else if (received_length > 0) {
download_label = g_format_size (received_length);
- gtk_progress_bar_pulse (GTK_PROGRESS_BAR (widget->priv->progress));
+ gtk_progress_bar_pulse (GTK_PROGRESS_BAR (widget->progress));
}
if (download_label) {
@@ -226,9 +225,9 @@ static void
download_finished_cb (EphyDownload *download,
EphyDownloadWidget *widget)
{
- gtk_widget_hide (widget->priv->progress);
+ gtk_widget_hide (widget->progress);
update_status_label (widget, _("Finished"));
- gtk_image_set_from_icon_name (GTK_IMAGE (gtk_button_get_image (GTK_BUTTON (widget->priv->action_button))),
+ gtk_image_set_from_icon_name (GTK_IMAGE (gtk_button_get_image (GTK_BUTTON (widget->action_button))),
"folder-open-symbolic",
GTK_ICON_SIZE_MENU);
}
@@ -242,12 +241,12 @@ download_failed_cb (EphyDownload *download,
g_signal_handlers_disconnect_by_func (download, download_progress_cb, widget);
- gtk_widget_hide (widget->priv->progress);
+ gtk_widget_hide (widget->progress);
error_msg = g_strdup_printf (_("Error downloading: %s"), error->message);
update_status_label (widget, error_msg);
g_free (error_msg);
- gtk_image_set_from_icon_name (GTK_IMAGE (gtk_button_get_image (GTK_BUTTON (widget->priv->action_button))),
+ gtk_image_set_from_icon_name (GTK_IMAGE (gtk_button_get_image (GTK_BUTTON (widget->action_button))),
"list-remove-symbolic",
GTK_ICON_SIZE_MENU);
}
@@ -263,25 +262,25 @@ download_content_type_changed_cb (EphyDownload *download,
static void
widget_action_button_clicked_cb (EphyDownloadWidget *widget)
{
- if (ephy_download_is_active (widget->priv->download)) {
+ if (ephy_download_is_active (widget->download)) {
WebKitDownload *download;
- download = ephy_download_get_webkit_download (widget->priv->download);
+ download = ephy_download_get_webkit_download (widget->download);
g_signal_handlers_disconnect_matched (download, G_SIGNAL_MATCH_DATA, 0, 0,
NULL, NULL, widget);
- g_signal_handlers_disconnect_matched (widget->priv->download, G_SIGNAL_MATCH_DATA, 0, 0,
+ g_signal_handlers_disconnect_matched (widget->download, G_SIGNAL_MATCH_DATA, 0, 0,
NULL, NULL, widget);
update_status_label (widget, _("Cancelling…"));
- gtk_widget_set_sensitive (widget->priv->action_button, FALSE);
+ gtk_widget_set_sensitive (widget->action_button, FALSE);
- ephy_download_cancel (widget->priv->download);
- } else if (ephy_download_failed (widget->priv->download, NULL)) {
+ ephy_download_cancel (widget->download);
+ } else if (ephy_download_failed (widget->download, NULL)) {
EphyDownloadsManager *manager;
manager = ephy_embed_shell_get_downloads_manager (ephy_embed_shell_get_default ());
- ephy_downloads_manager_remove_download (manager, widget->priv->download);
+ ephy_downloads_manager_remove_download (manager, widget->download);
} else {
- ephy_download_do_download_action (widget->priv->download,
+ ephy_download_do_download_action (widget->download,
EPHY_DOWNLOAD_ACTION_BROWSE_TO);
}
}
@@ -325,7 +324,7 @@ ephy_download_widget_set_property (GObject *object,
switch (property_id) {
case PROP_DOWNLOAD:
- widget->priv->download = g_value_dup_object (value);
+ widget->download = g_value_dup_object (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -342,15 +341,15 @@ ephy_download_widget_dispose (GObject *object)
widget = EPHY_DOWNLOAD_WIDGET (object);
- if (widget->priv->download != NULL) {
- WebKitDownload *download = ephy_download_get_webkit_download (widget->priv->download);
+ if (widget->download != NULL) {
+ WebKitDownload *download = ephy_download_get_webkit_download (widget->download);
g_signal_handlers_disconnect_matched (download, G_SIGNAL_MATCH_DATA, 0, 0,
NULL, NULL, widget);
- g_signal_handlers_disconnect_matched (widget->priv->download, G_SIGNAL_MATCH_DATA, 0, 0,
+ g_signal_handlers_disconnect_matched (widget->download, G_SIGNAL_MATCH_DATA, 0, 0,
NULL, NULL, widget);
- g_object_unref (widget->priv->download);
- widget->priv->download = NULL;
+ g_object_unref (widget->download);
+ widget->download = NULL;
}
G_OBJECT_CLASS (ephy_download_widget_parent_class)->dispose (object);
@@ -360,7 +359,6 @@ static void
ephy_download_widget_constructed (GObject *object)
{
EphyDownloadWidget *widget = EPHY_DOWNLOAD_WIDGET (object);
- EphyDownloadWidgetPrivate *priv = widget->priv;
WebKitDownload *download;
const char *action_icon_name = NULL;
GError *error = NULL;
@@ -370,82 +368,82 @@ ephy_download_widget_constructed (GObject *object)
gtk_widget_set_margin_start (GTK_WIDGET (widget), 5);
gtk_widget_set_margin_end (GTK_WIDGET (widget), 5);
- priv->icon = gtk_image_new ();
- gtk_widget_set_margin_end (priv->icon, 10);
+ widget->icon = gtk_image_new ();
+ gtk_widget_set_margin_end (widget->icon, 10);
update_download_icon (widget);
- gtk_grid_attach (GTK_GRID (widget), priv->icon, 0, 0, 1, 3);
- gtk_widget_show (priv->icon);
-
- priv->filename = gtk_label_new (NULL);
- gtk_widget_set_valign (priv->filename, GTK_ALIGN_CENTER);
- gtk_widget_set_margin_bottom (priv->filename, 6);
- gtk_label_set_xalign (GTK_LABEL (priv->filename), 0);
- gtk_label_set_max_width_chars (GTK_LABEL (priv->filename), 30);
- gtk_label_set_ellipsize (GTK_LABEL (priv->filename), PANGO_ELLIPSIZE_END);
+ gtk_grid_attach (GTK_GRID (widget), widget->icon, 0, 0, 1, 3);
+ gtk_widget_show (widget->icon);
+
+ widget->filename = gtk_label_new (NULL);
+ gtk_widget_set_valign (widget->filename, GTK_ALIGN_CENTER);
+ gtk_widget_set_margin_bottom (widget->filename, 6);
+ gtk_label_set_xalign (GTK_LABEL (widget->filename), 0);
+ gtk_label_set_max_width_chars (GTK_LABEL (widget->filename), 30);
+ gtk_label_set_ellipsize (GTK_LABEL (widget->filename), PANGO_ELLIPSIZE_END);
update_download_destination (widget);
- gtk_grid_attach (GTK_GRID (widget), priv->filename, 1, 0, 1, 1);
- gtk_widget_show (priv->filename);
-
- priv->progress = gtk_progress_bar_new ();
- gtk_widget_set_valign (priv->progress, GTK_ALIGN_CENTER);
- gtk_widget_set_margin_start (priv->progress, 2);
- gtk_widget_set_margin_bottom (priv->progress, 4);
- gtk_progress_bar_set_pulse_step (GTK_PROGRESS_BAR (priv->progress), 0.05);
- gtk_grid_attach (GTK_GRID (widget), priv->progress, 1, 1, 1, 1);
- if (ephy_download_is_active (priv->download))
- gtk_widget_show (priv->progress);
-
- priv->status = gtk_label_new (NULL);
- gtk_widget_set_valign (priv->status, GTK_ALIGN_CENTER);
- gtk_label_set_xalign (GTK_LABEL (priv->status), 0);
- g_object_set (priv->status, "width-request", 260, NULL);
- gtk_label_set_max_width_chars (GTK_LABEL (priv->status), 30);
- gtk_label_set_ellipsize (GTK_LABEL (priv->status), PANGO_ELLIPSIZE_END);
- if (ephy_download_failed (priv->download, &error)) {
+ gtk_grid_attach (GTK_GRID (widget), widget->filename, 1, 0, 1, 1);
+ gtk_widget_show (widget->filename);
+
+ widget->progress = gtk_progress_bar_new ();
+ gtk_widget_set_valign (widget->progress, GTK_ALIGN_CENTER);
+ gtk_widget_set_margin_start (widget->progress, 2);
+ gtk_widget_set_margin_bottom (widget->progress, 4);
+ gtk_progress_bar_set_pulse_step (GTK_PROGRESS_BAR (widget->progress), 0.05);
+ gtk_grid_attach (GTK_GRID (widget), widget->progress, 1, 1, 1, 1);
+ if (ephy_download_is_active (widget->download))
+ gtk_widget_show (widget->progress);
+
+ widget->status = gtk_label_new (NULL);
+ gtk_widget_set_valign (widget->status, GTK_ALIGN_CENTER);
+ gtk_label_set_xalign (GTK_LABEL (widget->status), 0);
+ g_object_set (widget->status, "width-request", 260, NULL);
+ gtk_label_set_max_width_chars (GTK_LABEL (widget->status), 30);
+ gtk_label_set_ellipsize (GTK_LABEL (widget->status), PANGO_ELLIPSIZE_END);
+ if (ephy_download_failed (widget->download, &error)) {
char *error_msg;
error_msg = g_strdup_printf (_("Error downloading: %s"), error->message);
update_status_label (widget, error_msg);
g_free (error_msg);
- } else if (ephy_download_succeeded (priv->download)) {
+ } else if (ephy_download_succeeded (widget->download)) {
update_status_label (widget, _("Finished"));
} else {
update_status_label (widget, _("Starting…"));
}
- gtk_grid_attach (GTK_GRID (widget), priv->status, 1, 2, 1, 1);
- gtk_widget_show (priv->status);
+ gtk_grid_attach (GTK_GRID (widget), widget->status, 1, 2, 1, 1);
+ gtk_widget_show (widget->status);
- if (ephy_download_succeeded (priv->download))
+ if (ephy_download_succeeded (widget->download))
action_icon_name = "folder-open-symbolic";
- else if (ephy_download_failed (priv->download, NULL))
+ else if (ephy_download_failed (widget->download, NULL))
action_icon_name = "list-remove-symbolic";
else
action_icon_name = "window-close-symbolic";
- priv->action_button = gtk_button_new_from_icon_name (action_icon_name, GTK_ICON_SIZE_MENU);
- g_signal_connect_swapped (priv->action_button, "clicked",
+ widget->action_button = gtk_button_new_from_icon_name (action_icon_name, GTK_ICON_SIZE_MENU);
+ g_signal_connect_swapped (widget->action_button, "clicked",
G_CALLBACK (widget_action_button_clicked_cb),
widget);
- gtk_widget_set_valign (priv->action_button, GTK_ALIGN_CENTER);
- gtk_widget_set_margin_start (priv->action_button, 10);
- gtk_style_context_add_class (gtk_widget_get_style_context (priv->action_button),
+ gtk_widget_set_valign (widget->action_button, GTK_ALIGN_CENTER);
+ gtk_widget_set_margin_start (widget->action_button, 10);
+ gtk_style_context_add_class (gtk_widget_get_style_context (widget->action_button),
"download-circular-button");
- gtk_grid_attach (GTK_GRID (widget), priv->action_button, 3, 0, 1, 3);
- gtk_widget_show (priv->action_button);
+ gtk_grid_attach (GTK_GRID (widget), widget->action_button, 3, 0, 1, 3);
+ gtk_widget_show (widget->action_button);
- download = ephy_download_get_webkit_download (priv->download);
+ download = ephy_download_get_webkit_download (widget->download);
g_signal_connect (download, "notify::estimated-progress",
G_CALLBACK (download_progress_cb),
widget);
g_signal_connect (download, "notify::destination",
G_CALLBACK (download_destination_changed_cb),
widget);
- g_signal_connect (priv->download, "completed",
+ g_signal_connect (widget->download, "completed",
G_CALLBACK (download_finished_cb),
widget);
- g_signal_connect (priv->download, "error",
+ g_signal_connect (widget->download, "error",
G_CALLBACK (download_failed_cb),
widget);
- g_signal_connect (priv->download, "notify::content-type",
+ g_signal_connect (widget->download, "notify::content-type",
G_CALLBACK (download_content_type_changed_cb),
widget);
}
@@ -455,8 +453,6 @@ ephy_download_widget_class_init (EphyDownloadWidgetClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- g_type_class_add_private (klass, sizeof (EphyDownloadWidgetPrivate));
-
object_class->constructed = ephy_download_widget_constructed;
object_class->get_property = ephy_download_widget_get_property;
object_class->set_property = ephy_download_widget_set_property;
@@ -480,7 +476,6 @@ ephy_download_widget_class_init (EphyDownloadWidgetClass *klass)
static void
ephy_download_widget_init (EphyDownloadWidget *widget)
{
- widget->priv = DOWNLOAD_WIDGET_PRIVATE (widget);
}
/**
@@ -495,7 +490,7 @@ EphyDownload *
ephy_download_widget_get_download (EphyDownloadWidget *widget)
{
g_return_val_if_fail (EPHY_IS_DOWNLOAD_WIDGET (widget), NULL);
- return widget->priv->download;
+ return widget->download;
}
/**
diff --git a/lib/widgets/ephy-download-widget.h b/lib/widgets/ephy-download-widget.h
index bf1335b..0cd3a35 100644
--- a/lib/widgets/ephy-download-widget.h
+++ b/lib/widgets/ephy-download-widget.h
@@ -28,30 +28,9 @@
G_BEGIN_DECLS
-#define EPHY_TYPE_DOWNLOAD_WIDGET ephy_download_widget_get_type()
-#define EPHY_DOWNLOAD_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
EPHY_TYPE_DOWNLOAD_WIDGET, EphyDownloadWidget))
-#define EPHY_DOWNLOAD_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EPHY_TYPE_DOWNLOAD_WIDGET,
EphyDownloadWidgetClass))
-#define EPHY_IS_DOWNLOAD_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
EPHY_TYPE_DOWNLOAD_WIDGET))
-#define EPHY_IS_DOWNLOAD_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EPHY_TYPE_DOWNLOAD_WIDGET))
-#define EPHY_DOWNLOAD_WIDGET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EPHY_TYPE_DOWNLOAD_WIDGET,
EphyDownloadWidgetClass))
-
-typedef struct _EphyDownloadWidget EphyDownloadWidget;
-typedef struct _EphyDownloadWidgetClass EphyDownloadWidgetClass;
-typedef struct _EphyDownloadWidgetPrivate EphyDownloadWidgetPrivate;
-
-struct _EphyDownloadWidget
-{
- GtkGrid parent;
-
- EphyDownloadWidgetPrivate *priv;
-};
-
-struct _EphyDownloadWidgetClass
-{
- GtkGridClass parent_class;
-};
-
-GType ephy_download_widget_get_type (void) G_GNUC_CONST;
+#define EPHY_TYPE_DOWNLOAD_WIDGET ephy_download_widget_get_type()
+
+G_DECLARE_FINAL_TYPE (EphyDownloadWidget, ephy_download_widget, EPHY, DOWNLOAD_WIDGET, GtkGrid)
GtkWidget *ephy_download_widget_new (EphyDownload *ephy_download);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]