[calls] account-widgets: Make row activatable
- From: Evangelos Ribeiro Tzaras <devrtz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [calls] account-widgets: Make row activatable
- Date: Tue, 24 May 2022 13:16:01 +0000 (UTC)
commit c1be092dea4e67ceaf081dd7dd8c17158755b684
Author: Evangelos Ribeiro Tzaras <devrtz fortysixandtwo eu>
Date: Sat May 21 18:05:13 2022 +0200
account-widgets: Make row activatable
This brings us closer to the intended design and let's us get rid of
some code.
src/calls-account-overview.c | 55 ++++++++++++++++++++++++++------------------
src/calls-account-row.c | 34 ++++++++++++---------------
src/calls-account-row.h | 1 +
src/ui/account-overview.ui | 1 +
4 files changed, 50 insertions(+), 41 deletions(-)
---
diff --git a/src/calls-account-overview.c b/src/calls-account-overview.c
index ef55934b..5454f86e 100644
--- a/src/calls-account-overview.c
+++ b/src/calls-account-overview.c
@@ -56,7 +56,7 @@ struct _CallsAccountOverview {
GtkWidget *intro;
GtkWidget *overview;
GtkWidget *add_btn;
- GtkWidget *add_row;
+ GtkListBoxRow *add_row;
/* The window where we add the account providers widget */
GtkWindow *account_window;
@@ -135,37 +135,51 @@ attach_account_widget (CallsAccountOverview *self,
static void
-on_add_account_clicked (CallsAccountOverview *self)
+on_account_row_activated (GtkListBox *box,
+ GtkListBoxRow *row,
+ CallsAccountOverview *self)
{
+ CallsAccount *account = NULL;
+ CallsAccountRow *acc_row;
CallsAccountProvider *provider;
GtkWidget *widget;
- /* For now we only have a single AccountProvider */
- provider = CALLS_ACCOUNT_PROVIDER (self->providers->data);
+ g_assert (GTK_IS_LIST_BOX_ROW (row) );
+ g_assert (CALLS_IS_ACCOUNT_OVERVIEW (self));
+
+ if (row == self->add_row) {
+ /* TODO this needs changing if we ever have multiple account providers */
+ provider = CALLS_ACCOUNT_PROVIDER (self->providers->data);
+ widget = calls_account_provider_get_account_widget (provider);
+
+ } else if (CALLS_IS_ACCOUNT_ROW (row)) {
+ acc_row = CALLS_ACCOUNT_ROW (row);
+
+ provider = calls_account_row_get_account_provider (acc_row);
+ widget = calls_account_provider_get_account_widget (provider);
+ account = calls_account_row_get_account (acc_row);
+
+ } else {
+ g_warning ("Unknown type of row activated!");
+ g_assert_not_reached ();
+ return;
+ }
- widget = calls_account_provider_get_account_widget (provider);
attach_account_widget (self, widget);
- calls_account_provider_add_new_account (provider);
+ if (account)
+ calls_account_provider_edit_account (provider, account);
+ else
+ calls_account_provider_add_new_account (provider);
gtk_window_present (self->account_window);
}
static void
-on_edit_account_clicked (CallsAccountRow *row,
- CallsAccountProvider *provider,
- CallsAccount *account,
- CallsAccountOverview *self)
+on_add_account_clicked (CallsAccountOverview *self)
{
- GtkWidget *widget;
-
- widget = calls_account_provider_get_account_widget (provider);
- attach_account_widget (self, widget);
-
- calls_account_provider_edit_account (provider, account);
-
- gtk_window_present (self->account_window);
+ on_account_row_activated (NULL, self->add_row, self);
}
@@ -222,10 +236,6 @@ update_account_list (CallsAccountOverview *self)
G_CALLBACK (on_account_message),
self);
- g_signal_connect (account_row, "edit-clicked",
- G_CALLBACK (on_edit_account_clicked),
- self);
-
gtk_list_box_insert (GTK_LIST_BOX (self->overview),
GTK_WIDGET (account_row),
0);
@@ -286,6 +296,7 @@ calls_account_overview_class_init (CallsAccountOverviewClass *klass)
gtk_widget_class_bind_template_child (widget_class, CallsAccountOverview, in_app_notification);
gtk_widget_class_bind_template_callback (widget_class, on_add_account_clicked);
+ gtk_widget_class_bind_template_callback (widget_class, on_account_row_activated);
}
diff --git a/src/calls-account-row.c b/src/calls-account-row.c
index b86bda0d..a2709bd9 100644
--- a/src/calls-account-row.c
+++ b/src/calls-account-row.c
@@ -47,12 +47,6 @@ enum {
};
static GParamSpec *props[PROP_LAST_PROP];
-enum {
- EDIT_CLICKED,
- N_SIGNALS
-};
-static guint signals[N_SIGNALS];
-
struct _CallsAccountRow {
HdyActionRow parent;
@@ -158,6 +152,10 @@ calls_account_row_get_property (GObject *object,
g_value_set_boolean (value, calls_account_row_get_online (self));
break;
+ case PROP_PROVIDER:
+ g_value_set_object (value, calls_account_row_get_account_provider (self));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -174,23 +172,12 @@ calls_account_row_class_init (CallsAccountRowClass *klass)
object_class->set_property = calls_account_row_set_property;
object_class->get_property = calls_account_row_get_property;
- signals[EDIT_CLICKED] =
- g_signal_new ("edit-clicked",
- CALLS_TYPE_ACCOUNT_ROW,
- G_SIGNAL_RUN_FIRST,
- 0,
- NULL, NULL, NULL,
- G_TYPE_NONE,
- 2,
- CALLS_TYPE_ACCOUNT_PROVIDER,
- CALLS_TYPE_ACCOUNT);
-
props[PROP_PROVIDER] =
g_param_spec_object ("provider",
"Provider",
"The provider of the account this row represents",
CALLS_TYPE_ACCOUNT_PROVIDER,
- G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS);
props[PROP_ACCOUNT] =
@@ -204,7 +191,7 @@ calls_account_row_class_init (CallsAccountRowClass *klass)
props[PROP_ONLINE] =
g_param_spec_boolean ("online",
"online",
- "The state of the online switch",
+ "If the account is online",
FALSE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
@@ -267,3 +254,12 @@ calls_account_row_get_account (CallsAccountRow *self)
return self->account;
}
+
+
+CallsAccountProvider *
+calls_account_row_get_account_provider (CallsAccountRow *self)
+{
+ g_return_val_if_fail (CALLS_IS_ACCOUNT_ROW (self), NULL);
+
+ return self->provider;
+}
diff --git a/src/calls-account-row.h b/src/calls-account-row.h
index cfb84b2a..ac05d0b8 100644
--- a/src/calls-account-row.h
+++ b/src/calls-account-row.h
@@ -42,5 +42,6 @@ gboolean calls_account_row_get_online (CallsAccountRow *s
void calls_account_row_set_online (CallsAccountRow *self,
gboolean online);
CallsAccount *calls_account_row_get_account (CallsAccountRow *self);
+CallsAccountProvider *calls_account_row_get_account_provider (CallsAccountRow *self);
G_END_DECLS
diff --git a/src/ui/account-overview.ui b/src/ui/account-overview.ui
index 436cca03..f2b092a5 100644
--- a/src/ui/account-overview.ui
+++ b/src/ui/account-overview.ui
@@ -77,6 +77,7 @@
<property name="margin-bottom">18</property>
<property name="margin-start">12</property>
<property name="margin-end">12</property>
+ <signal name="row-activated" handler="on_account_row_activated" swapped="no"/>
<!-- placeholder -->
<child type="placeholder"/>
<style>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]