1
0
Fork 0
mirror of https://gitlab.gnome.org/GNOME/calls.git synced 2024-12-04 20:07:36 +00:00

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 *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);
}

View file

@ -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;
}

View file

@ -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

View file

@ -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>