[gnome-software] app folder dialog: Port to G_DECLARE_FINAL_TYPE macro
- From: Kalev Lember <klember src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] app folder dialog: Port to G_DECLARE_FINAL_TYPE macro
- Date: Mon, 7 Sep 2015 17:36:32 +0000 (UTC)
commit b572c9e942496b70db73a8a6d48f8486e3e847ca
Author: Kalev Lember <klember redhat com>
Date: Mon Sep 7 15:15:42 2015 +0200
app folder dialog: Port to G_DECLARE_FINAL_TYPE macro
src/gs-app-folder-dialog.c | 133 +++++++++++++++++++-------------------------
src/gs-app-folder-dialog.h | 21 +------
2 files changed, 59 insertions(+), 95 deletions(-)
---
diff --git a/src/gs-app-folder-dialog.c b/src/gs-app-folder-dialog.c
index b3ba49f..b5fccfc 100644
--- a/src/gs-app-folder-dialog.c
+++ b/src/gs-app-folder-dialog.c
@@ -28,9 +28,10 @@
#include "gs-folders.h"
#include "gs-app-folder-dialog.h"
-typedef struct _GsAppFolderDialogPrivate GsAppFolderDialogPrivate;
-struct _GsAppFolderDialogPrivate
+struct _GsAppFolderDialog
{
+ GtkDialog parent_instance;
+
GList *apps;
GsFolders *folders;
GtkWidget *cancel_button;
@@ -43,21 +44,18 @@ struct _GsAppFolderDialogPrivate
GtkListBoxRow *selected_row;
};
-G_DEFINE_TYPE_WITH_PRIVATE (GsAppFolderDialog, gs_app_folder_dialog, GTK_TYPE_DIALOG)
-
-#define PRIVATE(o) (gs_app_folder_dialog_get_instance_private (o))
+G_DEFINE_TYPE (GsAppFolderDialog, gs_app_folder_dialog, GTK_TYPE_DIALOG)
static void
gs_app_folder_dialog_destroy (GtkWidget *widget)
{
GsAppFolderDialog *dialog = GS_APP_FOLDER_DIALOG (widget);
- GsAppFolderDialogPrivate *priv = PRIVATE (dialog);
- g_list_free (priv->apps);
- priv->apps = NULL;
+ g_list_free (dialog->apps);
+ dialog->apps = NULL;
- g_clear_object (&priv->folders);
- g_clear_object (&priv->rows);
+ g_clear_object (&dialog->folders);
+ g_clear_object (&dialog->rows);
GTK_WIDGET_CLASS (gs_app_folder_dialog_parent_class)->destroy (widget);
}
@@ -71,24 +69,23 @@ cancel_cb (GsAppFolderDialog *dialog)
static void
apply_changes (GsAppFolderDialog *dialog)
{
- GsAppFolderDialogPrivate *priv = PRIVATE (dialog);
const gchar *folder;
GList *l;
- if (priv->selected_row)
- folder = (const gchar *)g_object_get_data (G_OBJECT (priv->selected_row), "folder");
+ if (dialog->selected_row)
+ folder = (const gchar *)g_object_get_data (G_OBJECT (dialog->selected_row), "folder");
else
folder = NULL;
- for (l = priv->apps; l; l = l->next) {
+ for (l = dialog->apps; l; l = l->next) {
GsApp *app = l->data;
- gs_folders_set_app_folder (priv->folders,
+ gs_folders_set_app_folder (dialog->folders,
gs_app_get_id (app),
gs_app_get_categories (app),
folder);
}
- gs_folders_save (priv->folders);
+ gs_folders_save (dialog->folders);
}
static void
@@ -103,11 +100,9 @@ static GtkWidget *create_row (GsAppFolderDialog *dialog, const gchar *folder);
static void
new_folder_cb (GsAppFolderDialog *dialog)
{
- GsAppFolderDialogPrivate *priv = PRIVATE (dialog);
-
- gtk_entry_set_text (GTK_ENTRY (priv->new_folder_entry), "");
- gtk_widget_show (priv->new_folder_popover);
- gtk_widget_grab_focus (priv->new_folder_entry);
+ gtk_entry_set_text (GTK_ENTRY (dialog->new_folder_entry), "");
+ gtk_widget_show (dialog->new_folder_popover);
+ gtk_widget_grab_focus (dialog->new_folder_entry);
}
static void
@@ -132,18 +127,16 @@ update_header_func (GtkListBoxRow *row,
static void
gs_app_folder_dialog_init (GsAppFolderDialog *dialog)
{
- GsAppFolderDialogPrivate *priv = PRIVATE (dialog);
-
- priv->folders = gs_folders_get ();
+ dialog->folders = gs_folders_get ();
gtk_widget_init_template (GTK_WIDGET (dialog));
- g_signal_connect_swapped (priv->cancel_button, "clicked",
+ g_signal_connect_swapped (dialog->cancel_button, "clicked",
G_CALLBACK (cancel_cb), dialog);
- g_signal_connect_swapped (priv->done_button, "clicked",
+ g_signal_connect_swapped (dialog->done_button, "clicked",
G_CALLBACK (done_cb), dialog);
- priv->rows = gtk_size_group_new (GTK_SIZE_GROUP_VERTICAL);
+ dialog->rows = gtk_size_group_new (GTK_SIZE_GROUP_VERTICAL);
- gtk_list_box_set_header_func (GTK_LIST_BOX (priv->app_folder_list),
+ gtk_list_box_set_header_func (GTK_LIST_BOX (dialog->app_folder_list),
update_header_func, NULL, NULL);
}
@@ -156,22 +149,21 @@ gs_app_folder_dialog_class_init (GsAppFolderDialogClass *klass)
gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/Software/app-folder-dialog.ui");
- gtk_widget_class_bind_template_child_private (widget_class, GsAppFolderDialog, cancel_button);
- gtk_widget_class_bind_template_child_private (widget_class, GsAppFolderDialog, done_button);
- gtk_widget_class_bind_template_child_private (widget_class, GsAppFolderDialog, app_folder_list);
+ gtk_widget_class_bind_template_child (widget_class, GsAppFolderDialog, cancel_button);
+ gtk_widget_class_bind_template_child (widget_class, GsAppFolderDialog, done_button);
+ gtk_widget_class_bind_template_child (widget_class, GsAppFolderDialog, app_folder_list);
}
static GtkWidget *
create_row (GsAppFolderDialog *dialog, const gchar *folder)
{
- GsAppFolderDialogPrivate *priv = PRIVATE (dialog);
GtkWidget *row;
GtkWidget *box;
GtkWidget *label;
GtkWidget *image;
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
- label = gtk_label_new (gs_folders_get_folder_name (priv->folders, folder));
+ label = gtk_label_new (gs_folders_get_folder_name (dialog->folders, folder));
g_object_set (label,
"margin-start", 20,
"margin-end", 20,
@@ -197,7 +189,7 @@ create_row (GsAppFolderDialog *dialog, const gchar *folder)
g_object_set_data (G_OBJECT (row), "image", image);
g_object_set_data_full (G_OBJECT (row), "folder", g_strdup (folder), g_free);
- gtk_size_group_add_widget (priv->rows, row);
+ gtk_size_group_add_widget (dialog->rows, row);
return row;
}
@@ -205,21 +197,18 @@ create_row (GsAppFolderDialog *dialog, const gchar *folder)
static void
set_apps (GsAppFolderDialog *dialog, GList *apps)
{
- GsAppFolderDialogPrivate *priv = PRIVATE (dialog);
-
- priv->apps = g_list_copy (apps);
+ dialog->apps = g_list_copy (apps);
}
static void
populate_list (GsAppFolderDialog *dialog)
{
- GsAppFolderDialogPrivate *priv = PRIVATE (dialog);
guint i;
_cleanup_free_ gchar **folders = NULL;
- folders = gs_folders_get_nonempty_folders (priv->folders);
+ folders = gs_folders_get_nonempty_folders (dialog->folders);
for (i = 0; folders[i]; i++) {
- gtk_list_box_insert (GTK_LIST_BOX (priv->app_folder_list),
+ gtk_list_box_insert (GTK_LIST_BOX (dialog->app_folder_list),
create_row (dialog, folders[i]), -1);
}
}
@@ -227,30 +216,27 @@ populate_list (GsAppFolderDialog *dialog)
static void
select_row (GtkListBox *list_box, GtkListBoxRow *row, GsAppFolderDialog *dialog)
{
- GsAppFolderDialogPrivate *priv = PRIVATE (dialog);
GtkWidget *image;
- if (priv->selected_row) {
- image = g_object_get_data (G_OBJECT (priv->selected_row), "image");
+ if (dialog->selected_row) {
+ image = g_object_get_data (G_OBJECT (dialog->selected_row), "image");
gtk_widget_hide (image);
- gtk_widget_set_sensitive (priv->done_button, FALSE);
+ gtk_widget_set_sensitive (dialog->done_button, FALSE);
}
- priv->selected_row = row;
+ dialog->selected_row = row;
- if (priv->selected_row) {
- image = g_object_get_data (G_OBJECT (priv->selected_row), "image");
+ if (dialog->selected_row) {
+ image = g_object_get_data (G_OBJECT (dialog->selected_row), "image");
gtk_widget_show (image);
- gtk_widget_set_sensitive (priv->done_button, TRUE);
+ gtk_widget_set_sensitive (dialog->done_button, TRUE);
}
}
static void
row_activated (GtkListBox *list_box, GtkListBoxRow *row, GsAppFolderDialog *dialog)
{
- GsAppFolderDialogPrivate *priv = PRIVATE (dialog);
-
- if (row == priv->new_folder_button) {
+ if (row == dialog->new_folder_button) {
new_folder_cb (dialog);
} else {
select_row (list_box, row, dialog);
@@ -275,21 +261,20 @@ activate_entry (GtkEntry *entry, GtkWidget *button)
static void
add_folder_add (GtkButton *button, GsAppFolderDialog *dialog)
{
- GsAppFolderDialogPrivate *priv = PRIVATE (dialog);
const gchar *folder;
- gtk_widget_hide (priv->new_folder_popover);
+ gtk_widget_hide (dialog->new_folder_popover);
- folder = gtk_entry_get_text (GTK_ENTRY (priv->new_folder_entry));
+ folder = gtk_entry_get_text (GTK_ENTRY (dialog->new_folder_entry));
if (folder[0] != '\0') {
const gchar *id;
GtkWidget *row;
- id = gs_folders_add_folder (priv->folders, folder);
+ id = gs_folders_add_folder (dialog->folders, folder);
row = create_row (dialog, id);
- gtk_list_box_insert (GTK_LIST_BOX (priv->app_folder_list),
+ gtk_list_box_insert (GTK_LIST_BOX (dialog->app_folder_list),
row,
- gtk_list_box_row_get_index (priv->new_folder_button));
- select_row (GTK_LIST_BOX (priv->app_folder_list),
+ gtk_list_box_row_get_index (dialog->new_folder_button));
+ select_row (GTK_LIST_BOX (dialog->app_folder_list),
GTK_LIST_BOX_ROW (row),
dialog);
}
@@ -298,27 +283,24 @@ add_folder_add (GtkButton *button, GsAppFolderDialog *dialog)
static void
add_folder_cancel (GtkButton *button, GsAppFolderDialog *dialog)
{
- GsAppFolderDialogPrivate *priv = PRIVATE (dialog);
-
- gtk_widget_hide (priv->new_folder_popover);
+ gtk_widget_hide (dialog->new_folder_popover);
}
static void
create_folder_name_popover (GsAppFolderDialog *dialog)
{
- GsAppFolderDialogPrivate *priv = PRIVATE (dialog);
GtkWidget *grid, *label, *button;
_cleanup_free_ gchar *title = NULL;
- priv->new_folder_popover = gtk_popover_new (GTK_WIDGET (priv->new_folder_button));
- gtk_popover_set_position (GTK_POPOVER (priv->new_folder_popover), GTK_POS_TOP);
+ dialog->new_folder_popover = gtk_popover_new (GTK_WIDGET (dialog->new_folder_button));
+ gtk_popover_set_position (GTK_POPOVER (dialog->new_folder_popover), GTK_POS_TOP);
grid = gtk_grid_new ();
gtk_grid_set_column_homogeneous (GTK_GRID (grid), TRUE);
gtk_grid_set_row_spacing (GTK_GRID (grid), 12);
gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
g_object_set (grid, "margin", 12, NULL);
- gtk_container_add (GTK_CONTAINER (priv->new_folder_popover), grid);
+ gtk_container_add (GTK_CONTAINER (dialog->new_folder_popover), grid);
title = g_strdup_printf ("<b>%s</b>", _("Folder Name"));
label = gtk_label_new (title);
@@ -326,10 +308,10 @@ create_folder_name_popover (GsAppFolderDialog *dialog)
gtk_widget_set_halign (label, GTK_ALIGN_CENTER);
gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 2, 1);
- priv->new_folder_entry = gtk_entry_new ();
- gtk_entry_set_width_chars (GTK_ENTRY (priv->new_folder_entry), 25);
- gtk_widget_set_halign (priv->new_folder_entry, GTK_ALIGN_FILL);
- gtk_grid_attach (GTK_GRID (grid), priv->new_folder_entry, 0, 1, 2, 1);
+ dialog->new_folder_entry = gtk_entry_new ();
+ gtk_entry_set_width_chars (GTK_ENTRY (dialog->new_folder_entry), 25);
+ gtk_widget_set_halign (dialog->new_folder_entry, GTK_ALIGN_FILL);
+ gtk_grid_attach (GTK_GRID (grid), dialog->new_folder_entry, 0, 1, 2, 1);
button = gtk_button_new_with_mnemonic (_("_Cancel"));
g_signal_connect (button, "clicked", G_CALLBACK (add_folder_cancel), dialog);
@@ -343,8 +325,8 @@ create_folder_name_popover (GsAppFolderDialog *dialog)
gtk_style_context_add_class (gtk_widget_get_style_context (button), GTK_STYLE_CLASS_SUGGESTED_ACTION);
gtk_widget_set_sensitive (button, FALSE);
- g_signal_connect (priv->new_folder_entry, "notify::text", G_CALLBACK (update_sensitive), button);
- g_signal_connect (priv->new_folder_entry, "activate", G_CALLBACK (activate_entry), button);
+ g_signal_connect (dialog->new_folder_entry, "notify::text", G_CALLBACK (update_sensitive), button);
+ g_signal_connect (dialog->new_folder_entry, "activate", G_CALLBACK (activate_entry), button);
gtk_widget_show_all (grid);
}
@@ -352,19 +334,18 @@ create_folder_name_popover (GsAppFolderDialog *dialog)
static void
add_new_folder_row (GsAppFolderDialog *dialog)
{
- GsAppFolderDialogPrivate *priv = PRIVATE (dialog);
GtkWidget *row, *button;
button = gtk_image_new_from_icon_name ("list-add-symbolic", GTK_ICON_SIZE_MENU);
gtk_widget_set_halign (button, GTK_ALIGN_FILL);
gtk_widget_set_valign (button, GTK_ALIGN_FILL);
row = gtk_list_box_row_new ();
- priv->new_folder_button = GTK_LIST_BOX_ROW (row);
+ dialog->new_folder_button = GTK_LIST_BOX_ROW (row);
gtk_container_add (GTK_CONTAINER (row), button);
- gtk_list_box_insert (GTK_LIST_BOX (priv->app_folder_list), row, -1);
- gtk_size_group_add_widget (priv->rows, row);
+ gtk_list_box_insert (GTK_LIST_BOX (dialog->app_folder_list), row, -1);
+ gtk_size_group_add_widget (dialog->rows, row);
- g_signal_connect (priv->app_folder_list, "row-activated",
+ g_signal_connect (dialog->app_folder_list, "row-activated",
G_CALLBACK (row_activated), dialog);
gtk_widget_show_all (row);
diff --git a/src/gs-app-folder-dialog.h b/src/gs-app-folder-dialog.h
index 35bf515..90ab76f 100644
--- a/src/gs-app-folder-dialog.h
+++ b/src/gs-app-folder-dialog.h
@@ -26,29 +26,12 @@
#include "gs-app.h"
-#define GS_TYPE_APP_FOLDER_DIALOG (gs_app_folder_dialog_get_type())
-#define GS_APP_FOLDER_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GS_TYPE_APP_FOLDER_DIALOG,
GsAppFolderDialog))
-#define GS_APP_FOLDER_DIALOG_CLASS(cls) (G_TYPE_CHECK_CLASS_CAST((cls),
GS_TYPE_APP_FOLDER_DIALOG, GsAppFolderDialogClass))
-#define GS_IS_APP_FOLDER_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GS_TYPE_APP_FOLDER_DIALOG))
-#define GS_IS_APP_FOLDER_DIALOG_CLASS(cls) (G_TYPE_CHECK_CLASS_TYPE((cls), GS_TYPE_APP_FOLDER_DIALOG))
-#define GS_APP_FOLDER_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GS_TYPE_APP_FOLDER_DIALOG,
GsAppFolderDialogClass))
-
G_BEGIN_DECLS
-typedef struct _GsAppFolderDialog GsAppFolderDialog;
-typedef struct _GsAppFolderDialogClass GsAppFolderDialogClass;
-
-struct _GsAppFolderDialog
-{
- GtkDialog parent;
-};
+#define GS_TYPE_APP_FOLDER_DIALOG (gs_app_folder_dialog_get_type ())
-struct _GsAppFolderDialogClass
-{
- GtkDialogClass parent_class;
-};
+G_DECLARE_FINAL_TYPE (GsAppFolderDialog, gs_app_folder_dialog, GS, APP_FOLDER_DIALOG, GtkDialog)
-GType gs_app_folder_dialog_get_type (void);
GtkWidget *gs_app_folder_dialog_new (GtkWindow *parent,
GList *apps);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]