[gnome-software] sources dialog: Port to G_DECLARE_FINAL_TYPE macro
- From: Kalev Lember <klember src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] sources dialog: Port to G_DECLARE_FINAL_TYPE macro
- Date: Mon, 7 Sep 2015 17:36:21 +0000 (UTC)
commit 50b9992888570855861764e5ff5a725311c22e83
Author: Kalev Lember <klember redhat com>
Date: Mon Sep 7 15:03:02 2015 +0200
sources dialog: Port to G_DECLARE_FINAL_TYPE macro
src/gs-sources-dialog.c | 152 ++++++++++++++++++++++-------------------------
src/gs-sources-dialog.h | 24 +------
2 files changed, 74 insertions(+), 102 deletions(-)
---
diff --git a/src/gs-sources-dialog.c b/src/gs-sources-dialog.c
index 4fa8ade..dde6171 100644
--- a/src/gs-sources-dialog.c
+++ b/src/gs-sources-dialog.c
@@ -30,8 +30,10 @@
#include "gs-sources-dialog-row.h"
#include "gs-utils.h"
-struct _GsSourcesDialogPrivate
+struct _GsSourcesDialog
{
+ GtkDialog parent_instance;
+
GCancellable *cancellable;
GsPluginLoader *plugin_loader;
GtkWidget *button_back;
@@ -47,7 +49,7 @@ struct _GsSourcesDialogPrivate
GtkWidget *stack;
};
-G_DEFINE_TYPE_WITH_PRIVATE (GsSourcesDialog, gs_sources_dialog, GTK_TYPE_DIALOG)
+G_DEFINE_TYPE (GsSourcesDialog, gs_sources_dialog, GTK_TYPE_DIALOG)
static void
add_source (GtkListBox *listbox, GsApp *app)
@@ -148,11 +150,10 @@ get_sources_cb (GsPluginLoader *plugin_loader,
GList *l;
GList *list;
GsApp *app;
- GsSourcesDialogPrivate *priv = gs_sources_dialog_get_instance_private (dialog);
_cleanup_error_free_ GError *error = NULL;
/* show results */
- gs_stop_spinner (GTK_SPINNER (priv->spinner));
+ gs_stop_spinner (GTK_SPINNER (dialog->spinner));
/* get the results */
list = gs_plugin_loader_get_sources_finish (plugin_loader, res, &error);
@@ -168,20 +169,20 @@ get_sources_cb (GsPluginLoader *plugin_loader,
} else {
g_warning ("failed to get sources: %s", error->message);
}
- gtk_stack_set_visible_child_name (GTK_STACK (priv->stack), "empty");
- gtk_style_context_add_class (gtk_widget_get_style_context (priv->label_header),
+ gtk_stack_set_visible_child_name (GTK_STACK (dialog->stack), "empty");
+ gtk_style_context_add_class (gtk_widget_get_style_context (dialog->label_header),
"dim-label");
goto out;
}
- gtk_style_context_remove_class (gtk_widget_get_style_context (priv->label_header),
+ gtk_style_context_remove_class (gtk_widget_get_style_context (dialog->label_header),
"dim-label");
/* add each */
- gtk_stack_set_visible_child_name (GTK_STACK (priv->stack), "sources");
+ gtk_stack_set_visible_child_name (GTK_STACK (dialog->stack), "sources");
for (l = list; l != NULL; l = l->next) {
app = GS_APP (l->data);
- add_source (GTK_LIST_BOX (priv->listbox), app);
+ add_source (GTK_LIST_BOX (dialog->listbox), app);
}
out:
if (list != NULL)
@@ -191,18 +192,16 @@ out:
static void
reload_sources (GsSourcesDialog *dialog)
{
- GsSourcesDialogPrivate *priv = gs_sources_dialog_get_instance_private (dialog);
-
- gtk_stack_set_visible_child_name (GTK_STACK (priv->stack), "waiting");
- gs_start_spinner (GTK_SPINNER (priv->spinner));
- gtk_widget_hide (priv->button_back);
- gs_container_remove_all (GTK_CONTAINER (priv->listbox));
+ gtk_stack_set_visible_child_name (GTK_STACK (dialog->stack), "waiting");
+ gs_start_spinner (GTK_SPINNER (dialog->spinner));
+ gtk_widget_hide (dialog->button_back);
+ gs_container_remove_all (GTK_CONTAINER (dialog->listbox));
/* get the list of non-core software sources */
- gs_plugin_loader_get_sources_async (priv->plugin_loader,
+ gs_plugin_loader_get_sources_async (dialog->plugin_loader,
GS_PLUGIN_REFINE_FLAGS_DEFAULT |
GS_PLUGIN_REFINE_FLAGS_REQUIRE_RELATED,
- priv->cancellable,
+ dialog->cancellable,
(GAsyncReadyCallback) get_sources_cb,
dialog);
}
@@ -265,15 +264,14 @@ list_row_activated_cb (GtkListBox *list_box,
{
GPtrArray *related;
GsApp *app;
- GsSourcesDialogPrivate *priv = gs_sources_dialog_get_instance_private (dialog);
guint cnt_apps = 0;
guint i;
- gtk_stack_set_visible_child_name (GTK_STACK (priv->stack), "details");
+ gtk_stack_set_visible_child_name (GTK_STACK (dialog->stack), "details");
- gtk_widget_show (priv->button_back);
+ gtk_widget_show (dialog->button_back);
- gs_container_remove_all (GTK_CONTAINER (priv->listbox_apps));
+ gs_container_remove_all (GTK_CONTAINER (dialog->listbox_apps));
app = GS_APP (g_object_get_data (G_OBJECT (row),
"GsShell::app"));
related = gs_app_get_related (app);
@@ -282,7 +280,7 @@ list_row_activated_cb (GtkListBox *list_box,
switch (gs_app_get_kind (app_tmp)) {
case GS_APP_KIND_NORMAL:
case GS_APP_KIND_SYSTEM:
- add_app (GTK_LIST_BOX (priv->listbox_apps), app_tmp);
+ add_app (GTK_LIST_BOX (dialog->listbox_apps), app_tmp);
cnt_apps++;
break;
default:
@@ -291,21 +289,20 @@ list_row_activated_cb (GtkListBox *list_box,
}
/* save this */
- g_object_set_data_full (G_OBJECT (priv->stack), "GsShell::app",
+ g_object_set_data_full (G_OBJECT (dialog->stack), "GsShell::app",
g_object_ref (app),
(GDestroyNotify) g_object_unref);
- gtk_widget_set_visible (priv->scrolledwindow_apps, cnt_apps != 0);
- gtk_widget_set_visible (priv->label2, cnt_apps != 0);
- gtk_widget_set_visible (priv->grid_noresults, cnt_apps == 0);
+ gtk_widget_set_visible (dialog->scrolledwindow_apps, cnt_apps != 0);
+ gtk_widget_set_visible (dialog->label2, cnt_apps != 0);
+ gtk_widget_set_visible (dialog->grid_noresults, cnt_apps == 0);
}
static void
back_button_cb (GtkWidget *widget, GsSourcesDialog *dialog)
{
- GsSourcesDialogPrivate *priv = gs_sources_dialog_get_instance_private (dialog);
- gtk_widget_hide (priv->button_back);
- gtk_stack_set_visible_child_name (GTK_STACK (priv->stack), "sources");
+ gtk_widget_hide (dialog->button_back);
+ gtk_stack_set_visible_child_name (GTK_STACK (dialog->stack), "sources");
}
static void
@@ -315,7 +312,6 @@ app_removed_cb (GObject *source,
{
GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source);
GsSourcesDialog *dialog = GS_SOURCES_DIALOG (user_data);
- GsSourcesDialogPrivate *priv = gs_sources_dialog_get_instance_private (dialog);
_cleanup_error_free_ GError *error = NULL;
if (!gs_plugin_loader_app_action_finish (plugin_loader, res, &error)) {
@@ -325,35 +321,34 @@ app_removed_cb (GObject *source,
}
/* enable button */
- gtk_widget_set_sensitive (priv->button_remove, TRUE);
- gtk_button_set_label (GTK_BUTTON (priv->button_remove), _("Remove Source"));
+ gtk_widget_set_sensitive (dialog->button_remove, TRUE);
+ gtk_button_set_label (GTK_BUTTON (dialog->button_remove), _("Remove Source"));
/* allow going back */
- gtk_widget_set_sensitive (priv->button_back, TRUE);
- gtk_widget_set_sensitive (priv->listbox_apps, TRUE);
+ gtk_widget_set_sensitive (dialog->button_back, TRUE);
+ gtk_widget_set_sensitive (dialog->listbox_apps, TRUE);
}
static void
remove_button_cb (GtkWidget *widget, GsSourcesDialog *dialog)
{
GsApp *app;
- GsSourcesDialogPrivate *priv = gs_sources_dialog_get_instance_private (dialog);
/* disable button */
- gtk_widget_set_sensitive (priv->button_remove, FALSE);
- gtk_button_set_label (GTK_BUTTON (priv->button_remove), _("Removing…"));
+ gtk_widget_set_sensitive (dialog->button_remove, FALSE);
+ gtk_button_set_label (GTK_BUTTON (dialog->button_remove), _("Removing…"));
/* disallow going back */
- gtk_widget_set_sensitive (priv->button_back, FALSE);
- gtk_widget_set_sensitive (priv->listbox_apps, FALSE);
+ gtk_widget_set_sensitive (dialog->button_back, FALSE);
+ gtk_widget_set_sensitive (dialog->listbox_apps, FALSE);
/* remove source */
- app = GS_APP (g_object_get_data (G_OBJECT (priv->stack), "GsShell::app"));
+ app = GS_APP (g_object_get_data (G_OBJECT (dialog->stack), "GsShell::app"));
g_debug ("removing source '%s'", gs_app_get_name (app));
- gs_plugin_loader_app_action_async (priv->plugin_loader,
+ gs_plugin_loader_app_action_async (dialog->plugin_loader,
app,
GS_PLUGIN_LOADER_ACTION_REMOVE,
- priv->cancellable,
+ dialog->cancellable,
app_removed_cb,
dialog);
}
@@ -361,24 +356,23 @@ remove_button_cb (GtkWidget *widget, GsSourcesDialog *dialog)
static gboolean
key_press_event (GsSourcesDialog *dialog, GdkEventKey *event)
{
- GsSourcesDialogPrivate *priv = gs_sources_dialog_get_instance_private (dialog);
GdkKeymap *keymap;
GdkModifierType state;
gboolean is_rtl;
- if (!gtk_widget_is_visible (priv->button_back) || !gtk_widget_is_sensitive (priv->button_back))
+ if (!gtk_widget_is_visible (dialog->button_back) || !gtk_widget_is_sensitive (dialog->button_back))
return GDK_EVENT_PROPAGATE;
state = event->state;
keymap = gdk_keymap_get_default ();
gdk_keymap_add_virtual_modifiers (keymap, &state);
state = state & gtk_accelerator_get_default_mod_mask ();
- is_rtl = gtk_widget_get_direction (priv->button_back) == GTK_TEXT_DIR_RTL;
+ is_rtl = gtk_widget_get_direction (dialog->button_back) == GTK_TEXT_DIR_RTL;
if ((!is_rtl && state == GDK_MOD1_MASK && event->keyval == GDK_KEY_Left) ||
(is_rtl && state == GDK_MOD1_MASK && event->keyval == GDK_KEY_Right) ||
event->keyval == GDK_KEY_Back) {
- gtk_widget_activate (priv->button_back);
+ gtk_widget_activate (dialog->button_back);
return GDK_EVENT_STOP;
}
@@ -388,16 +382,14 @@ key_press_event (GsSourcesDialog *dialog, GdkEventKey *event)
static gboolean
button_press_event (GsSourcesDialog *dialog, GdkEventButton *event)
{
- GsSourcesDialogPrivate *priv = gs_sources_dialog_get_instance_private (dialog);
-
/* Mouse hardware back button is 8 */
if (event->button != 8)
return GDK_EVENT_PROPAGATE;
- if (!gtk_widget_is_visible (priv->button_back) || !gtk_widget_is_sensitive (priv->button_back))
+ if (!gtk_widget_is_visible (dialog->button_back) || !gtk_widget_is_sensitive (dialog->button_back))
return GDK_EVENT_PROPAGATE;
- gtk_widget_activate (priv->button_back);
+ gtk_widget_activate (dialog->button_back);
return GDK_EVENT_STOP;
}
@@ -440,10 +432,8 @@ updates_changed_cb (GsPluginLoader *plugin_loader,
static void
set_plugin_loader (GsSourcesDialog *dialog, GsPluginLoader *plugin_loader)
{
- GsSourcesDialogPrivate *priv = gs_sources_dialog_get_instance_private (dialog);
-
- priv->plugin_loader = g_object_ref (plugin_loader);
- g_signal_connect (priv->plugin_loader, "updates-changed",
+ dialog->plugin_loader = g_object_ref (plugin_loader);
+ g_signal_connect (dialog->plugin_loader, "updates-changed",
G_CALLBACK (updates_changed_cb), dialog);
}
@@ -451,16 +441,15 @@ static void
gs_sources_dialog_dispose (GObject *object)
{
GsSourcesDialog *dialog = GS_SOURCES_DIALOG (object);
- GsSourcesDialogPrivate *priv = gs_sources_dialog_get_instance_private (dialog);
- if (priv->plugin_loader != NULL) {
- g_signal_handlers_disconnect_by_func (priv->plugin_loader, updates_changed_cb, dialog);
- g_clear_object (&priv->plugin_loader);
+ if (dialog->plugin_loader != NULL) {
+ g_signal_handlers_disconnect_by_func (dialog->plugin_loader, updates_changed_cb, dialog);
+ g_clear_object (&dialog->plugin_loader);
}
- if (priv->cancellable != NULL) {
- g_cancellable_cancel (priv->cancellable);
- g_clear_object (&priv->cancellable);
+ if (dialog->cancellable != NULL) {
+ g_cancellable_cancel (dialog->cancellable);
+ g_clear_object (&dialog->cancellable);
}
G_OBJECT_CLASS (gs_sources_dialog_parent_class)->dispose (object);
@@ -469,29 +458,28 @@ gs_sources_dialog_dispose (GObject *object)
static void
gs_sources_dialog_init (GsSourcesDialog *dialog)
{
- GsSourcesDialogPrivate *priv = gs_sources_dialog_get_instance_private (dialog);
_cleanup_free_ gchar *label_text = NULL;
_cleanup_free_ gchar *os_name = NULL;
gtk_widget_init_template (GTK_WIDGET (dialog));
- priv->cancellable = g_cancellable_new ();
+ dialog->cancellable = g_cancellable_new ();
- gtk_list_box_set_header_func (GTK_LIST_BOX (priv->listbox),
+ gtk_list_box_set_header_func (GTK_LIST_BOX (dialog->listbox),
list_header_func,
dialog,
NULL);
- gtk_list_box_set_sort_func (GTK_LIST_BOX (priv->listbox),
+ gtk_list_box_set_sort_func (GTK_LIST_BOX (dialog->listbox),
list_sort_func,
dialog, NULL);
- g_signal_connect (priv->listbox, "row-activated",
+ g_signal_connect (dialog->listbox, "row-activated",
G_CALLBACK (list_row_activated_cb), dialog);
- gtk_list_box_set_header_func (GTK_LIST_BOX (priv->listbox_apps),
+ gtk_list_box_set_header_func (GTK_LIST_BOX (dialog->listbox_apps),
list_header_func,
dialog,
NULL);
- gtk_list_box_set_sort_func (GTK_LIST_BOX (priv->listbox_apps),
+ gtk_list_box_set_sort_func (GTK_LIST_BOX (dialog->listbox_apps),
list_sort_func,
dialog, NULL);
@@ -501,11 +489,11 @@ gs_sources_dialog_init (GsSourcesDialog *dialog)
replaced by the name of the actual distro, e.g. Fedora. */
label_text = g_strdup_printf (_("Software sources can be downloaded from the internet. They give you
access to additional software that is not provided by %s."),
os_name);
- gtk_label_set_text (GTK_LABEL (priv->label_empty), label_text);
+ gtk_label_set_text (GTK_LABEL (dialog->label_empty), label_text);
- g_signal_connect (priv->button_back, "clicked",
+ g_signal_connect (dialog->button_back, "clicked",
G_CALLBACK (back_button_cb), dialog);
- g_signal_connect (priv->button_remove, "clicked",
+ g_signal_connect (dialog->button_remove, "clicked",
G_CALLBACK (remove_button_cb), dialog);
/* global keynav and mouse back button */
@@ -525,17 +513,17 @@ gs_sources_dialog_class_init (GsSourcesDialogClass *klass)
gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/Software/gs-sources-dialog.ui");
- gtk_widget_class_bind_template_child_private (widget_class, GsSourcesDialog, button_back);
- gtk_widget_class_bind_template_child_private (widget_class, GsSourcesDialog, button_remove);
- gtk_widget_class_bind_template_child_private (widget_class, GsSourcesDialog, grid_noresults);
- gtk_widget_class_bind_template_child_private (widget_class, GsSourcesDialog, label2);
- gtk_widget_class_bind_template_child_private (widget_class, GsSourcesDialog, label_empty);
- gtk_widget_class_bind_template_child_private (widget_class, GsSourcesDialog, label_header);
- gtk_widget_class_bind_template_child_private (widget_class, GsSourcesDialog, listbox);
- gtk_widget_class_bind_template_child_private (widget_class, GsSourcesDialog, listbox_apps);
- gtk_widget_class_bind_template_child_private (widget_class, GsSourcesDialog, scrolledwindow_apps);
- gtk_widget_class_bind_template_child_private (widget_class, GsSourcesDialog, spinner);
- gtk_widget_class_bind_template_child_private (widget_class, GsSourcesDialog, stack);
+ gtk_widget_class_bind_template_child (widget_class, GsSourcesDialog, button_back);
+ gtk_widget_class_bind_template_child (widget_class, GsSourcesDialog, button_remove);
+ gtk_widget_class_bind_template_child (widget_class, GsSourcesDialog, grid_noresults);
+ gtk_widget_class_bind_template_child (widget_class, GsSourcesDialog, label2);
+ gtk_widget_class_bind_template_child (widget_class, GsSourcesDialog, label_empty);
+ gtk_widget_class_bind_template_child (widget_class, GsSourcesDialog, label_header);
+ gtk_widget_class_bind_template_child (widget_class, GsSourcesDialog, listbox);
+ gtk_widget_class_bind_template_child (widget_class, GsSourcesDialog, listbox_apps);
+ gtk_widget_class_bind_template_child (widget_class, GsSourcesDialog, scrolledwindow_apps);
+ gtk_widget_class_bind_template_child (widget_class, GsSourcesDialog, spinner);
+ gtk_widget_class_bind_template_child (widget_class, GsSourcesDialog, stack);
}
GtkWidget *
diff --git a/src/gs-sources-dialog.h b/src/gs-sources-dialog.h
index 17e5e98..a75e93a 100644
--- a/src/gs-sources-dialog.h
+++ b/src/gs-sources-dialog.h
@@ -27,33 +27,17 @@
#include "gs-app.h"
#include "gs-plugin-loader.h"
-#define GS_TYPE_SOURCES_DIALOG (gs_sources_dialog_get_type())
-#define GS_SOURCES_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GS_TYPE_SOURCES_DIALOG,
GsSourcesDialog))
-#define GS_SOURCES_DIALOG_CLASS(cls) (G_TYPE_CHECK_CLASS_CAST((cls), GS_TYPE_SOURCES_DIALOG,
GsSourcesDialogClass))
-#define GS_IS_SOURCES_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GS_TYPE_SOURCES_DIALOG))
-#define GS_IS_SOURCES_DIALOG_CLASS(cls) (G_TYPE_CHECK_CLASS_TYPE((cls),
GS_TYPE_SOURCES_DIALOG))
-#define GS_SOURCES_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GS_TYPE_SOURCES_DIALOG,
GsSourcesDialogClass))
-
G_BEGIN_DECLS
-typedef struct _GsSourcesDialog GsSourcesDialog;
-typedef struct _GsSourcesDialogClass GsSourcesDialogClass;
-typedef struct _GsSourcesDialogPrivate GsSourcesDialogPrivate;
-
-struct _GsSourcesDialog
-{
- GtkDialog parent;
-};
+#define GS_TYPE_SOURCES_DIALOG (gs_sources_dialog_get_type ())
-struct _GsSourcesDialogClass
-{
- GtkDialogClass parent_class;
-};
+G_DECLARE_FINAL_TYPE (GsSourcesDialog, gs_sources_dialog, GS, SOURCES_DIALOG, GtkDialog)
-GType gs_sources_dialog_get_type (void);
GtkWidget *gs_sources_dialog_new (GtkWindow *parent,
GsPluginLoader *plugin_loader);
+G_END_DECLS
+
#endif /* GS_SOURCES_DIALOG_H */
/* vim: set noexpandtab: */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]