[gnome-software] repos dialog: Expose third party switch in the row class
- From: Kalev Lember <klember src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] repos dialog: Expose third party switch in the row class
- Date: Mon, 26 Feb 2018 16:02:14 +0000 (UTC)
commit 324b40f3a7e8771c7812961587387329394c6aea
Author: Kalev Lember <klember redhat com>
Date: Mon Feb 26 11:35:27 2018 +0100
repos dialog: Expose third party switch in the row class
Instead of having a wrapper in the row class, just provide a getter for
the switch and move all the signal handling to the dialog class. This
avoids having a large wrapper in the row class when we need to use more
of the switch signals in the future.
src/gs-repos-dialog-row.c | 54 +++--------------------------------------------
src/gs-repos-dialog-row.h | 4 +---
src/gs-repos-dialog.c | 11 +++++-----
3 files changed, 10 insertions(+), 59 deletions(-)
---
diff --git a/src/gs-repos-dialog-row.c b/src/gs-repos-dialog-row.c
index 5f641315..ec0f6507 100644
--- a/src/gs-repos-dialog-row.c
+++ b/src/gs-repos-dialog-row.c
@@ -41,12 +41,6 @@ typedef struct
G_DEFINE_TYPE_WITH_PRIVATE (GsReposDialogRow, gs_repos_dialog_row, GTK_TYPE_LIST_BOX_ROW)
-enum {
- PROP_0,
- PROP_SWITCH_ACTIVE,
- PROP_LAST
-};
-
enum {
SIGNAL_BUTTON_CLICKED,
SIGNAL_LAST
@@ -62,14 +56,6 @@ gs_repos_dialog_row_set_switch_enabled (GsReposDialogRow *row,
gtk_widget_set_visible (priv->active_switch, switch_enabled);
}
-void
-gs_repos_dialog_row_set_switch_active (GsReposDialogRow *row,
- gboolean switch_active)
-{
- GsReposDialogRowPrivate *priv = gs_repos_dialog_row_get_instance_private (row);
- gtk_switch_set_active (GTK_SWITCH (priv->active_switch), switch_active);
-}
-
void
gs_repos_dialog_row_set_name (GsReposDialogRow *row, const gchar *name)
{
@@ -265,38 +251,12 @@ button_clicked_cb (GtkWidget *widget, GsReposDialogRow *row)
g_signal_emit (row, signals[SIGNAL_BUTTON_CLICKED], 0);
}
-static void
-gs_repos_dialog_switch_active_cb (GtkSwitch *active_switch,
- GParamSpec *pspec,
- GsReposDialogRow *row)
-{
- g_object_notify (G_OBJECT (row), "switch-active");
-}
-
-gboolean
-gs_repos_dialog_row_get_switch_active (GsReposDialogRow *row)
+GtkWidget *
+gs_repos_dialog_row_get_switch (GsReposDialogRow *row)
{
GsReposDialogRowPrivate *priv = gs_repos_dialog_row_get_instance_private (row);
- return gtk_switch_get_active (GTK_SWITCH (priv->active_switch));
-}
-
-static void
-gs_repos_dialog_row_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GsReposDialogRow *row = GS_REPOS_DIALOG_ROW (object);
- switch (prop_id) {
- case PROP_SWITCH_ACTIVE:
- g_value_set_boolean (value,
- gs_repos_dialog_row_get_switch_active (row));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
+ return priv->active_switch;
}
static void
@@ -324,8 +284,6 @@ gs_repos_dialog_row_init (GsReposDialogRow *row)
GsReposDialogRowPrivate *priv = gs_repos_dialog_row_get_instance_private (row);
gtk_widget_init_template (GTK_WIDGET (row));
- g_signal_connect (priv->active_switch, "notify::active",
- G_CALLBACK (gs_repos_dialog_switch_active_cb), row);
g_signal_connect (priv->button, "clicked",
G_CALLBACK (button_clicked_cb), row);
}
@@ -333,17 +291,11 @@ gs_repos_dialog_row_init (GsReposDialogRow *row)
static void
gs_repos_dialog_row_class_init (GsReposDialogRowClass *klass)
{
- GParamSpec *pspec;
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- object_class->get_property = gs_repos_dialog_row_get_property;
widget_class->destroy = gs_repos_dialog_row_destroy;
- pspec = g_param_spec_string ("switch-active", NULL, NULL, FALSE,
- G_PARAM_READABLE);
- g_object_class_install_property (object_class, PROP_SWITCH_ACTIVE, pspec);
-
signals [SIGNAL_BUTTON_CLICKED] =
g_signal_new ("button-clicked",
G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
diff --git a/src/gs-repos-dialog-row.h b/src/gs-repos-dialog-row.h
index b08d4e31..d67be767 100644
--- a/src/gs-repos-dialog-row.h
+++ b/src/gs-repos-dialog-row.h
@@ -40,9 +40,7 @@ struct _GsReposDialogRowClass
GtkWidget *gs_repos_dialog_row_new (void);
void gs_repos_dialog_row_set_switch_enabled (GsReposDialogRow *row,
gboolean switch_enabled);
-void gs_repos_dialog_row_set_switch_active (GsReposDialogRow *row,
- gboolean switch_active);
-gboolean gs_repos_dialog_row_get_switch_active (GsReposDialogRow *row);
+GtkWidget *gs_repos_dialog_row_get_switch (GsReposDialogRow *row);
void gs_repos_dialog_row_set_name (GsReposDialogRow *row,
const gchar *name);
void gs_repos_dialog_row_set_comment (GsReposDialogRow *row,
diff --git a/src/gs-repos-dialog.c b/src/gs-repos-dialog.c
index 652cf36c..daaf4308 100644
--- a/src/gs-repos-dialog.c
+++ b/src/gs-repos-dialog.c
@@ -47,6 +47,7 @@ struct _GsReposDialog
GtkWidget *row_third_party;
GtkWidget *spinner;
GtkWidget *stack;
+ GtkWidget *switch_third_party;
};
G_DEFINE_TYPE (GsReposDialog, gs_repos_dialog, GTK_TYPE_DIALOG)
@@ -406,13 +407,13 @@ install_third_party_repo (GsReposDialog *dialog, gboolean install)
}
static void
-third_party_switch_switch_active_cb (GsReposDialogRow *row,
+third_party_switch_switch_active_cb (GtkSwitch *switch_third_party,
GParamSpec *pspec,
GsReposDialog *dialog)
{
gboolean active;
- active = gs_repos_dialog_row_get_switch_active (GS_REPOS_DIALOG_ROW (dialog->row_third_party));
+ active = gtk_switch_get_active (GTK_SWITCH (dialog->switch_third_party));
install_third_party_repo (dialog, active);
g_settings_set_boolean (dialog->settings, "show-nonfree-prompt", FALSE);
}
@@ -429,8 +430,7 @@ refresh_third_party_repo (GsReposDialog *dialog)
/* if the third party repo package is installed, show the switch as active */
switch_active = (gs_app_get_state (dialog->third_party_repo) == AS_APP_STATE_INSTALLED);
- gs_repos_dialog_row_set_switch_active (GS_REPOS_DIALOG_ROW (dialog->row_third_party),
- switch_active);
+ gtk_switch_set_active (GTK_SWITCH (dialog->switch_third_party), switch_active);
gtk_widget_show (dialog->frame_third_party);
}
@@ -699,7 +699,8 @@ gs_repos_dialog_init (GsReposDialog *dialog)
gtk_label_set_text (GTK_LABEL (dialog->label_description), label_description_text);
/* set up third party repository row */
- g_signal_connect (dialog->row_third_party, "notify::switch-active",
+ dialog->switch_third_party = gs_repos_dialog_row_get_switch (GS_REPOS_DIALOG_ROW
(dialog->row_third_party));
+ g_signal_connect (dialog->switch_third_party, "notify::active",
G_CALLBACK (third_party_switch_switch_active_cb),
dialog);
gs_repos_dialog_row_set_switch_enabled (GS_REPOS_DIALOG_ROW (dialog->row_third_party), TRUE);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]