account-widgets: Make row activatable

This brings us closer to the intended design and let's us get rid of
some code.
This commit is contained in:
Evangelos Ribeiro Tzaras
2022-05-21 18:05:13 +02:00
parent f102fb3fcd
commit c1be092dea
4 changed files with 50 additions and 41 deletions

View File

@@ -56,7 +56,7 @@ struct _CallsAccountOverview {
GtkWidget *intro; GtkWidget *intro;
GtkWidget *overview; GtkWidget *overview;
GtkWidget *add_btn; GtkWidget *add_btn;
GtkWidget *add_row; GtkListBoxRow *add_row;
/* The window where we add the account providers widget */ /* The window where we add the account providers widget */
GtkWindow *account_window; GtkWindow *account_window;
@@ -135,37 +135,51 @@ attach_account_widget (CallsAccountOverview *self,
static void 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; CallsAccountProvider *provider;
GtkWidget *widget; GtkWidget *widget;
/* For now we only have a single AccountProvider */ g_assert (GTK_IS_LIST_BOX_ROW (row) );
provider = CALLS_ACCOUNT_PROVIDER (self->providers->data); 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); 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); gtk_window_present (self->account_window);
} }
static void static void
on_edit_account_clicked (CallsAccountRow *row, on_add_account_clicked (CallsAccountOverview *self)
CallsAccountProvider *provider,
CallsAccount *account,
CallsAccountOverview *self)
{ {
GtkWidget *widget; on_account_row_activated (NULL, self->add_row, self);
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);
} }
@@ -222,10 +236,6 @@ update_account_list (CallsAccountOverview *self)
G_CALLBACK (on_account_message), G_CALLBACK (on_account_message),
self); 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_list_box_insert (GTK_LIST_BOX (self->overview),
GTK_WIDGET (account_row), GTK_WIDGET (account_row),
0); 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_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_add_account_clicked);
gtk_widget_class_bind_template_callback (widget_class, on_account_row_activated);
} }

View File

@@ -47,12 +47,6 @@ enum {
}; };
static GParamSpec *props[PROP_LAST_PROP]; static GParamSpec *props[PROP_LAST_PROP];
enum {
EDIT_CLICKED,
N_SIGNALS
};
static guint signals[N_SIGNALS];
struct _CallsAccountRow { struct _CallsAccountRow {
HdyActionRow parent; HdyActionRow parent;
@@ -158,6 +152,10 @@ calls_account_row_get_property (GObject *object,
g_value_set_boolean (value, calls_account_row_get_online (self)); g_value_set_boolean (value, calls_account_row_get_online (self));
break; break;
case PROP_PROVIDER:
g_value_set_object (value, calls_account_row_get_account_provider (self));
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break; break;
@@ -174,23 +172,12 @@ calls_account_row_class_init (CallsAccountRowClass *klass)
object_class->set_property = calls_account_row_set_property; object_class->set_property = calls_account_row_set_property;
object_class->get_property = calls_account_row_get_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] = props[PROP_PROVIDER] =
g_param_spec_object ("provider", g_param_spec_object ("provider",
"Provider", "Provider",
"The provider of the account this row represents", "The provider of the account this row represents",
CALLS_TYPE_ACCOUNT_PROVIDER, CALLS_TYPE_ACCOUNT_PROVIDER,
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS); G_PARAM_STATIC_STRINGS);
props[PROP_ACCOUNT] = props[PROP_ACCOUNT] =
@@ -204,7 +191,7 @@ calls_account_row_class_init (CallsAccountRowClass *klass)
props[PROP_ONLINE] = props[PROP_ONLINE] =
g_param_spec_boolean ("online", g_param_spec_boolean ("online",
"online", "online",
"The state of the online switch", "If the account is online",
FALSE, FALSE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
@@ -267,3 +254,12 @@ calls_account_row_get_account (CallsAccountRow *self)
return self->account; 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;
}

View File

@@ -42,5 +42,6 @@ gboolean calls_account_row_get_online (CallsAccountRow *s
void calls_account_row_set_online (CallsAccountRow *self, void calls_account_row_set_online (CallsAccountRow *self,
gboolean online); gboolean online);
CallsAccount *calls_account_row_get_account (CallsAccountRow *self); CallsAccount *calls_account_row_get_account (CallsAccountRow *self);
CallsAccountProvider *calls_account_row_get_account_provider (CallsAccountRow *self);
G_END_DECLS G_END_DECLS

View File

@@ -77,6 +77,7 @@
<property name="margin-bottom">18</property> <property name="margin-bottom">18</property>
<property name="margin-start">12</property> <property name="margin-start">12</property>
<property name="margin-end">12</property> <property name="margin-end">12</property>
<signal name="row-activated" handler="on_account_row_activated" swapped="no"/>
<!-- placeholder --> <!-- placeholder -->
<child type="placeholder"/> <child type="placeholder"/>
<style> <style>