aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 1 | /* |
Guillaume Roguez | 77c579d | 2018-01-30 15:54:02 -0500 | [diff] [blame] | 2 | * Copyright (C) 2016-2018 Savoir-faire Linux Inc. |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 3 | * Author: Alexandre Viau <alexandre.viau@savoirfairelinux.com> |
Hugo Lefeuvre | 24356d4 | 2018-05-11 10:41:41 -0400 | [diff] [blame] | 4 | * Author: Hugo Lefeuvre <hugo.lefeuvre@savoirfairelinux.com> |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | */ |
| 20 | |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 21 | // GTK+ related |
| 22 | #include <glib/gi18n.h> |
| 23 | #include <gtk/gtk.h> |
| 24 | |
| 25 | // LRC |
| 26 | #include <account.h> |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 27 | #include <profilemodel.h> |
| 28 | #include <profile.h> |
| 29 | #include <accountmodel.h> |
| 30 | #include <personmodel.h> |
Sébastien Blin | 61c19d1 | 2018-05-16 12:55:34 -0400 | [diff] [blame] | 31 | #include "api/newaccountmodel.h" |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 32 | |
| 33 | // Ring Client |
| 34 | #include "utils/models.h" |
| 35 | #include "avatarmanipulation.h" |
| 36 | #include "accountcreationwizard.h" |
aviau | 2da3d9c | 2016-09-06 11:28:36 -0400 | [diff] [blame] | 37 | #include "usernameregistrationbox.h" |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 38 | |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 39 | struct _AccountCreationWizard |
| 40 | { |
Hugo Lefeuvre | 395931b | 2018-07-17 12:13:14 -0400 | [diff] [blame^] | 41 | GtkScrolledWindow parent; |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | struct _AccountCreationWizardClass |
| 45 | { |
Hugo Lefeuvre | 395931b | 2018-07-17 12:13:14 -0400 | [diff] [blame^] | 46 | GtkScrolledWindowClass parent_class; |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | typedef struct _AccountCreationWizardPrivate AccountCreationWizardPrivate; |
| 50 | |
| 51 | struct _AccountCreationWizardPrivate |
| 52 | { |
Sébastien Blin | 61c19d1 | 2018-05-16 12:55:34 -0400 | [diff] [blame] | 53 | AccountInfoPointer const *accountInfo_ = nullptr; |
| 54 | gchar* accountId; |
| 55 | gchar* username; |
| 56 | gchar* password; |
| 57 | gchar* avatar; |
| 58 | |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 59 | GtkWidget *stack_account_creation; |
| 60 | QMetaObject::Connection account_state_changed; |
aviau | 2da3d9c | 2016-09-06 11:28:36 -0400 | [diff] [blame] | 61 | QMetaObject::Connection name_registration_ended; |
| 62 | gboolean username_available; |
| 63 | |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 64 | /* choose_account_type_vbox */ |
| 65 | GtkWidget *choose_account_type_vbox; |
| 66 | GtkWidget *choose_account_type_ring_logo; |
| 67 | GtkWidget *button_new_account; |
| 68 | GtkWidget *button_existing_account; |
| 69 | GtkWidget *button_wizard_cancel; |
Sébastien Blin | 61c19d1 | 2018-05-16 12:55:34 -0400 | [diff] [blame] | 70 | GtkWidget *button_show_advanced; |
| 71 | GtkWidget *button_new_sip_account; |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 72 | |
Adrien Beraud | 50215a4 | 2017-09-15 20:24:52 +0200 | [diff] [blame] | 73 | /* existing account */ |
| 74 | GtkWidget *existing_account; |
| 75 | GtkWidget *button_existing_account_next; |
| 76 | GtkWidget *button_existing_account_previous; |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 77 | GtkWidget *entry_existing_account_pin; |
Adrien Beraud | 50215a4 | 2017-09-15 20:24:52 +0200 | [diff] [blame] | 78 | GtkWidget *entry_existing_account_archive; |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 79 | GtkWidget *entry_existing_account_password; |
| 80 | GtkWidget *retrieving_account; |
| 81 | |
| 82 | /* account creation */ |
| 83 | GtkWidget *account_creation; |
aviau | 692fe6d | 2016-11-08 14:37:34 -0500 | [diff] [blame] | 84 | GtkWidget *entry_username; |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 85 | GtkWidget *entry_password; |
| 86 | GtkWidget *entry_password_confirm; |
Sébastien Blin | a8ac86b | 2018-06-29 09:52:40 -0400 | [diff] [blame] | 87 | GtkWidget *label_password_error; |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 88 | GtkWidget *button_account_creation_next; |
| 89 | GtkWidget *button_account_creation_previous; |
| 90 | GtkWidget *box_avatarselection; |
| 91 | GtkWidget *avatar_manipulation; |
aviau | 2da3d9c | 2016-09-06 11:28:36 -0400 | [diff] [blame] | 92 | GtkWidget *box_username_entry; |
Sébastien Blin | a8ac86b | 2018-06-29 09:52:40 -0400 | [diff] [blame] | 93 | GtkWidget *switch_register; |
aviau | 2da3d9c | 2016-09-06 11:28:36 -0400 | [diff] [blame] | 94 | GtkWidget *username_registration_box; |
aviau | 692fe6d | 2016-11-08 14:37:34 -0500 | [diff] [blame] | 95 | GtkWidget *entry_display_name; |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 96 | |
| 97 | /* generating_account_spinner */ |
| 98 | GtkWidget *vbox_generating_account_spinner; |
| 99 | |
aviau | 2da3d9c | 2016-09-06 11:28:36 -0400 | [diff] [blame] | 100 | /* registering_username_spinner */ |
| 101 | GtkWidget *vbox_registering_username_spinner; |
| 102 | |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 103 | /* error_view */ |
| 104 | GtkWidget *error_view; |
| 105 | GtkWidget *button_error_view_ok; |
| 106 | |
| 107 | }; |
| 108 | |
Hugo Lefeuvre | 395931b | 2018-07-17 12:13:14 -0400 | [diff] [blame^] | 109 | G_DEFINE_TYPE_WITH_PRIVATE(AccountCreationWizard, account_creation_wizard, GTK_TYPE_SCROLLED_WINDOW); |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 110 | |
| 111 | #define ACCOUNT_CREATION_WIZARD_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), ACCOUNT_CREATION_WIZARD_TYPE, AccountCreationWizardPrivate)) |
| 112 | |
| 113 | /* signals */ |
| 114 | enum { |
| 115 | ACCOUNT_CREATION_CANCELED, |
| 116 | ACCOUNT_CREATION_COMPLETED, |
| 117 | LAST_SIGNAL |
| 118 | }; |
| 119 | |
| 120 | static guint account_creation_wizard_signals[LAST_SIGNAL] = { 0 }; |
| 121 | |
| 122 | static void |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 123 | account_creation_wizard_dispose(GObject *object) |
| 124 | { |
| 125 | AccountCreationWizardPrivate *priv = ACCOUNT_CREATION_WIZARD_GET_PRIVATE(object); |
Hugo Lefeuvre | 24356d4 | 2018-05-11 10:41:41 -0400 | [diff] [blame] | 126 | |
| 127 | // make sure preview is stopped and destroyed |
| 128 | account_creation_wizard_show_preview(ACCOUNT_CREATION_WIZARD(object), FALSE); |
| 129 | |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 130 | QObject::disconnect(priv->account_state_changed); |
| 131 | G_OBJECT_CLASS(account_creation_wizard_parent_class)->dispose(object); |
| 132 | } |
| 133 | |
| 134 | static void |
| 135 | account_creation_wizard_init(AccountCreationWizard *view) |
| 136 | { |
| 137 | gtk_widget_init_template(GTK_WIDGET(view)); |
| 138 | } |
| 139 | |
| 140 | static void |
| 141 | account_creation_wizard_class_init(AccountCreationWizardClass *klass) |
| 142 | { |
| 143 | G_OBJECT_CLASS(klass)->dispose = account_creation_wizard_dispose; |
| 144 | |
| 145 | gtk_widget_class_set_template_from_resource(GTK_WIDGET_CLASS (klass), |
| 146 | "/cx/ring/RingGnome/accountcreationwizard.ui"); |
| 147 | |
| 148 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountCreationWizard, stack_account_creation); |
| 149 | |
| 150 | /* choose_account_type_vbox */ |
| 151 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountCreationWizard, choose_account_type_vbox); |
| 152 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountCreationWizard, choose_account_type_ring_logo); |
| 153 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountCreationWizard, button_new_account); |
| 154 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountCreationWizard, button_existing_account); |
| 155 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountCreationWizard, button_wizard_cancel); |
Sébastien Blin | 61c19d1 | 2018-05-16 12:55:34 -0400 | [diff] [blame] | 156 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountCreationWizard, button_show_advanced); |
| 157 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountCreationWizard, button_new_sip_account); |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 158 | |
Adrien Beraud | 50215a4 | 2017-09-15 20:24:52 +0200 | [diff] [blame] | 159 | /* existing account */ |
| 160 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountCreationWizard, existing_account); |
| 161 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountCreationWizard, button_existing_account_next); |
| 162 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountCreationWizard, button_existing_account_previous); |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 163 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountCreationWizard, entry_existing_account_pin); |
Adrien Beraud | 50215a4 | 2017-09-15 20:24:52 +0200 | [diff] [blame] | 164 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountCreationWizard, entry_existing_account_archive); |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 165 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountCreationWizard, entry_existing_account_password); |
| 166 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountCreationWizard, retrieving_account); |
| 167 | |
| 168 | /* account creation */ |
| 169 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountCreationWizard, account_creation); |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 170 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountCreationWizard, entry_password); |
| 171 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountCreationWizard, entry_password_confirm); |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 172 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountCreationWizard, button_account_creation_next); |
| 173 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountCreationWizard, button_account_creation_previous); |
| 174 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountCreationWizard, box_avatarselection); |
| 175 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountCreationWizard, label_password_error); |
aviau | 2da3d9c | 2016-09-06 11:28:36 -0400 | [diff] [blame] | 176 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountCreationWizard, box_username_entry); |
Sébastien Blin | a8ac86b | 2018-06-29 09:52:40 -0400 | [diff] [blame] | 177 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountCreationWizard, switch_register); |
aviau | 692fe6d | 2016-11-08 14:37:34 -0500 | [diff] [blame] | 178 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountCreationWizard, entry_display_name); |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 179 | |
| 180 | /* generating_account_spinner */ |
| 181 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountCreationWizard, vbox_generating_account_spinner); |
| 182 | |
aviau | 2da3d9c | 2016-09-06 11:28:36 -0400 | [diff] [blame] | 183 | /* registering_username_spinner */ |
| 184 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountCreationWizard, vbox_registering_username_spinner); |
| 185 | |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 186 | /* error view */ |
| 187 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountCreationWizard, error_view); |
| 188 | gtk_widget_class_bind_template_child_private(GTK_WIDGET_CLASS (klass), AccountCreationWizard, button_error_view_ok); |
| 189 | |
| 190 | /* add signals */ |
| 191 | account_creation_wizard_signals[ACCOUNT_CREATION_COMPLETED] = g_signal_new("account-creation-completed", |
| 192 | G_TYPE_FROM_CLASS(klass), |
| 193 | (GSignalFlags) (G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION), |
| 194 | 0, |
| 195 | nullptr, |
| 196 | nullptr, |
| 197 | g_cclosure_marshal_VOID__VOID, |
| 198 | G_TYPE_NONE, 0); |
| 199 | |
| 200 | account_creation_wizard_signals[ACCOUNT_CREATION_CANCELED] = g_signal_new("account-creation-canceled", |
| 201 | G_TYPE_FROM_CLASS(klass), |
| 202 | (GSignalFlags) (G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION), |
| 203 | 0, |
| 204 | nullptr, |
| 205 | nullptr, |
| 206 | g_cclosure_marshal_VOID__VOID, |
| 207 | G_TYPE_NONE, 0); |
| 208 | } |
| 209 | |
Sébastien Blin | 61c19d1 | 2018-05-16 12:55:34 -0400 | [diff] [blame] | 210 | void |
| 211 | account_creation_show_error_view(AccountCreationWizard *view, const std::string& id) |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 212 | { |
| 213 | AccountCreationWizardPrivate *priv = ACCOUNT_CREATION_WIZARD_GET_PRIVATE(view); |
Sébastien Blin | 61c19d1 | 2018-05-16 12:55:34 -0400 | [diff] [blame] | 214 | if (priv->accountId && id == priv->accountId) |
| 215 | gtk_stack_set_visible_child(GTK_STACK(priv->stack_account_creation), priv->error_view); |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | static gboolean |
| 219 | create_ring_account(AccountCreationWizard *view, |
aviau | 692fe6d | 2016-11-08 14:37:34 -0500 | [diff] [blame] | 220 | gchar *display_name, |
| 221 | gchar *username, |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 222 | gchar *password, |
Adrien Beraud | 50215a4 | 2017-09-15 20:24:52 +0200 | [diff] [blame] | 223 | gchar *pin, |
| 224 | gchar *archivePath) |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 225 | { |
| 226 | g_return_val_if_fail(IS_ACCOUNT_CREATION_WIZARD(view), G_SOURCE_REMOVE); |
| 227 | AccountCreationWizardPrivate *priv = ACCOUNT_CREATION_WIZARD_GET_PRIVATE(view); |
| 228 | |
Sébastien Blin | 61c19d1 | 2018-05-16 12:55:34 -0400 | [diff] [blame] | 229 | priv->username = g_strdup(username); |
| 230 | priv->password = g_strdup(password); |
| 231 | std::string accountId = lrc::api::NewAccountModel::createNewAccount( |
| 232 | lrc::api::profile::Type::RING, |
| 233 | display_name? display_name : "", |
| 234 | archivePath? archivePath : "", |
| 235 | password? password : "", |
| 236 | pin? pin : ""); |
| 237 | priv->accountId = g_strdup(accountId.c_str()); |
| 238 | priv->avatar = g_strdup(avatar_manipulation_get_temporary(AVATAR_MANIPULATION(priv->avatar_manipulation))); |
| 239 | // NOTE: NewAccountModel::accountAdded will be triggered here and will call account_creation_wizard_account_added |
aviau | 2da3d9c | 2016-09-06 11:28:36 -0400 | [diff] [blame] | 240 | |
Sébastien Blin | 61c19d1 | 2018-05-16 12:55:34 -0400 | [diff] [blame] | 241 | g_object_ref(view); // ref so its not destroyed too early |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 242 | |
| 243 | return G_SOURCE_REMOVE; |
| 244 | } |
| 245 | |
Sébastien Blin | 61c19d1 | 2018-05-16 12:55:34 -0400 | [diff] [blame] | 246 | void |
| 247 | account_creation_wizard_account_added(AccountCreationWizard *view, AccountInfoPointer const & accountInfo) |
| 248 | { |
| 249 | g_return_if_fail(IS_ACCOUNT_CREATION_WIZARD(view)); |
| 250 | AccountCreationWizardPrivate *priv = ACCOUNT_CREATION_WIZARD_GET_PRIVATE(view); |
| 251 | priv->accountInfo_ = &accountInfo; |
| 252 | if ((*priv->accountInfo_)->id != priv->accountId) { |
| 253 | // Not for this account. Abort |
| 254 | return; |
| 255 | } |
| 256 | // Register username |
| 257 | if (priv->username) { |
| 258 | (*priv->accountInfo_)->accountModel->registerName(priv->accountId, priv->password, priv->username); |
| 259 | } |
| 260 | // Set avatar if any. |
| 261 | if (priv->avatar) { |
| 262 | try { |
| 263 | (*priv->accountInfo_)->accountModel->setAvatar(priv->accountId, priv->avatar); |
| 264 | } catch (std::out_of_range&) { |
| 265 | g_warning("Can't set avatar for unknown account"); |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | g_signal_emit(G_OBJECT(view), account_creation_wizard_signals[ACCOUNT_CREATION_COMPLETED], 0); |
| 270 | g_object_unref(view); |
| 271 | } |
| 272 | |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 273 | static gboolean |
| 274 | create_new_ring_account(AccountCreationWizard *win) |
| 275 | { |
| 276 | g_return_val_if_fail(IS_ACCOUNT_CREATION_WIZARD(win), G_SOURCE_REMOVE); |
| 277 | AccountCreationWizardPrivate *priv = ACCOUNT_CREATION_WIZARD_GET_PRIVATE(win); |
| 278 | |
Stepan Salenikovich | ec16deb | 2017-04-14 14:18:37 -0400 | [diff] [blame] | 279 | /* Tuleap: #1441 |
| 280 | * if the user did not validate the avatar area selection, we still take that as the image |
| 281 | * for their avatar; otherwise many users end up with no avatar by default |
| 282 | * TODO: improve avatar creation process to not need this fix |
| 283 | */ |
| 284 | avatar_manipulation_wizard_completed(AVATAR_MANIPULATION(priv->avatar_manipulation)); |
| 285 | |
aviau | 692fe6d | 2016-11-08 14:37:34 -0500 | [diff] [blame] | 286 | gchar *display_name = g_strdup(gtk_entry_get_text(GTK_ENTRY(priv->entry_display_name))); |
| 287 | gchar *username = g_strdup(gtk_entry_get_text(GTK_ENTRY(priv->entry_username))); |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 288 | gchar *password = g_strdup(gtk_entry_get_text(GTK_ENTRY(priv->entry_password))); |
| 289 | gtk_entry_set_text(GTK_ENTRY(priv->entry_password), ""); |
| 290 | gtk_entry_set_text(GTK_ENTRY(priv->entry_password_confirm), ""); |
| 291 | |
Adrien Beraud | 50215a4 | 2017-09-15 20:24:52 +0200 | [diff] [blame] | 292 | auto status = create_ring_account(win, display_name, username, password, nullptr, nullptr); |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 293 | |
Hugo Lefeuvre | 24356d4 | 2018-05-11 10:41:41 -0400 | [diff] [blame] | 294 | // Now that we've use the preview to generate the avatar, we can safely close it. Don't |
| 295 | // assume owner will do it for us, this might not always be the case |
| 296 | account_creation_wizard_show_preview(win, FALSE); |
| 297 | |
aviau | 692fe6d | 2016-11-08 14:37:34 -0500 | [diff] [blame] | 298 | g_free(display_name); |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 299 | g_free(password); |
aviau | 692fe6d | 2016-11-08 14:37:34 -0500 | [diff] [blame] | 300 | g_free(username); |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 301 | |
| 302 | return status; |
| 303 | } |
| 304 | |
| 305 | static gboolean |
| 306 | create_existing_ring_account(AccountCreationWizard *win) |
| 307 | { |
| 308 | g_return_val_if_fail(IS_ACCOUNT_CREATION_WIZARD(win), G_SOURCE_REMOVE); |
| 309 | AccountCreationWizardPrivate *priv = ACCOUNT_CREATION_WIZARD_GET_PRIVATE(win); |
| 310 | |
| 311 | gchar *password = g_strdup(gtk_entry_get_text(GTK_ENTRY(priv->entry_existing_account_password))); |
| 312 | gtk_entry_set_text(GTK_ENTRY(priv->entry_existing_account_password), ""); |
| 313 | |
Adrien Beraud | 50215a4 | 2017-09-15 20:24:52 +0200 | [diff] [blame] | 314 | gchar *pin = nullptr; |
| 315 | auto curPin = gtk_entry_get_text(GTK_ENTRY(priv->entry_existing_account_pin)); |
| 316 | if (curPin and strlen(curPin) > 0) { |
| 317 | pin = g_strdup(curPin); |
| 318 | gtk_entry_set_text(GTK_ENTRY(priv->entry_existing_account_pin), ""); |
| 319 | } |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 320 | |
Adrien Beraud | 50215a4 | 2017-09-15 20:24:52 +0200 | [diff] [blame] | 321 | gchar *archive = nullptr; |
| 322 | auto archivePath = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(priv->entry_existing_account_archive)); |
| 323 | if (archivePath) { |
| 324 | archive = g_strdup(archivePath); |
| 325 | gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(priv->entry_existing_account_archive), nullptr); |
| 326 | } |
| 327 | |
| 328 | auto status = create_ring_account(win, NULL, NULL, password, pin, archive); |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 329 | |
| 330 | g_free(password); |
| 331 | g_free(pin); |
| 332 | |
| 333 | return status; |
| 334 | } |
| 335 | |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 336 | static void |
| 337 | show_generating_account_spinner(AccountCreationWizard *view) |
| 338 | { |
| 339 | AccountCreationWizardPrivate *priv = ACCOUNT_CREATION_WIZARD_GET_PRIVATE(view); |
| 340 | gtk_stack_set_visible_child(GTK_STACK(priv->stack_account_creation), priv->vbox_generating_account_spinner); |
| 341 | } |
| 342 | |
| 343 | static void |
| 344 | account_creation_next_clicked(G_GNUC_UNUSED GtkButton *button, AccountCreationWizard *win) |
| 345 | { |
| 346 | AccountCreationWizardPrivate *priv = ACCOUNT_CREATION_WIZARD_GET_PRIVATE(win); |
| 347 | |
| 348 | /* Check for correct password */ |
| 349 | const gchar *password = gtk_entry_get_text(GTK_ENTRY(priv->entry_password)); |
| 350 | const gchar *password_confirm = gtk_entry_get_text(GTK_ENTRY(priv->entry_password_confirm)); |
| 351 | |
| 352 | if (g_strcmp0(password, password_confirm) != 0) |
| 353 | { |
aviau | 2da3d9c | 2016-09-06 11:28:36 -0400 | [diff] [blame] | 354 | gtk_label_set_text(GTK_LABEL(priv->label_password_error), _("Passwords don't match")); |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 355 | return; |
| 356 | } |
| 357 | |
| 358 | show_generating_account_spinner(win); |
| 359 | |
| 360 | /* now create account after a short timeout so that the the save doesn't |
| 361 | * happen freeze the client before the widget changes happen; |
| 362 | * the timeout function should then display the next step in account creation |
| 363 | */ |
| 364 | g_timeout_add_full(G_PRIORITY_DEFAULT, 300, (GSourceFunc)create_new_ring_account, win, NULL); |
| 365 | } |
| 366 | |
| 367 | static void |
| 368 | show_retrieving_account(AccountCreationWizard *win) |
| 369 | { |
| 370 | AccountCreationWizardPrivate *priv = ACCOUNT_CREATION_WIZARD_GET_PRIVATE(win); |
| 371 | gtk_stack_set_visible_child(GTK_STACK(priv->stack_account_creation), priv->retrieving_account); |
| 372 | } |
| 373 | |
| 374 | static void |
Adrien Beraud | 50215a4 | 2017-09-15 20:24:52 +0200 | [diff] [blame] | 375 | existing_account_next_clicked(AccountCreationWizard *win) |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 376 | { |
| 377 | show_retrieving_account(win); |
| 378 | |
| 379 | /* now create account after a short timeout so that the the save doesn't |
| 380 | * happen freeze the client before the widget changes happen; |
| 381 | * the timeout function should then display the next step in account creation |
| 382 | */ |
| 383 | g_timeout_add_full(G_PRIORITY_DEFAULT, 300, (GSourceFunc)create_existing_ring_account, win, NULL); |
| 384 | } |
| 385 | |
| 386 | static void |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 387 | show_choose_account_type(AccountCreationWizard *view) |
| 388 | { |
| 389 | AccountCreationWizardPrivate *priv = ACCOUNT_CREATION_WIZARD_GET_PRIVATE(view); |
Hugo Lefeuvre | 395931b | 2018-07-17 12:13:14 -0400 | [diff] [blame^] | 390 | |
| 391 | /* Make sure other stack elements are hidden, otherwise their width will prevent |
| 392 | the window to be correctly resized at this stage. */ |
| 393 | gtk_widget_hide(priv->account_creation); |
| 394 | gtk_widget_hide(priv->existing_account); |
| 395 | |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 396 | gtk_stack_set_visible_child(GTK_STACK(priv->stack_account_creation), priv->choose_account_type_vbox); |
| 397 | } |
| 398 | |
| 399 | static void |
Hugo Lefeuvre | 24356d4 | 2018-05-11 10:41:41 -0400 | [diff] [blame] | 400 | account_creation_previous_clicked(G_GNUC_UNUSED GtkButton *button, AccountCreationWizard *view) |
| 401 | { |
| 402 | // make sure to stop preview before going back to choose account type |
| 403 | account_creation_wizard_show_preview(view, FALSE); |
| 404 | show_choose_account_type(view); |
| 405 | } |
| 406 | |
| 407 | static void |
Adrien Beraud | 50215a4 | 2017-09-15 20:24:52 +0200 | [diff] [blame] | 408 | show_existing_account(AccountCreationWizard *view) |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 409 | { |
| 410 | AccountCreationWizardPrivate *priv = ACCOUNT_CREATION_WIZARD_GET_PRIVATE(view); |
Hugo Lefeuvre | 395931b | 2018-07-17 12:13:14 -0400 | [diff] [blame^] | 411 | |
| 412 | gtk_widget_show(priv->existing_account); |
Adrien Beraud | 50215a4 | 2017-09-15 20:24:52 +0200 | [diff] [blame] | 413 | gtk_stack_set_visible_child(GTK_STACK(priv->stack_account_creation), priv->existing_account); |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | static void |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 417 | wizard_cancel_clicked(G_GNUC_UNUSED GtkButton *button, AccountCreationWizard *view) |
| 418 | { |
Hugo Lefeuvre | 24356d4 | 2018-05-11 10:41:41 -0400 | [diff] [blame] | 419 | account_creation_wizard_cancel(view); |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | static void |
Sébastien Blin | 61c19d1 | 2018-05-16 12:55:34 -0400 | [diff] [blame] | 423 | show_advanced(G_GNUC_UNUSED GtkButton *button, AccountCreationWizard *view) |
| 424 | { |
| 425 | AccountCreationWizardPrivate *priv = ACCOUNT_CREATION_WIZARD_GET_PRIVATE(view); |
| 426 | gtk_widget_set_visible(GTK_WIDGET(priv->button_new_sip_account), !gtk_widget_is_visible(GTK_WIDGET(priv->button_new_sip_account))); |
| 427 | } |
| 428 | |
| 429 | static void |
| 430 | create_new_sip_account(G_GNUC_UNUSED GtkButton *button, AccountCreationWizard *view) |
| 431 | { |
| 432 | lrc::api::NewAccountModel::createNewAccount(lrc::api::profile::Type::SIP, "SIP"); |
| 433 | g_signal_emit(G_OBJECT(view), account_creation_wizard_signals[ACCOUNT_CREATION_COMPLETED], 0); |
| 434 | g_object_unref(view); |
| 435 | } |
| 436 | |
| 437 | static void |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 438 | entries_existing_account_changed(G_GNUC_UNUSED GtkEntry *entry, AccountCreationWizard *view) |
| 439 | { |
| 440 | AccountCreationWizardPrivate *priv = ACCOUNT_CREATION_WIZARD_GET_PRIVATE(view); |
| 441 | |
| 442 | const gchar *pin = gtk_entry_get_text(GTK_ENTRY(priv->entry_existing_account_pin)); |
Adrien Beraud | 50215a4 | 2017-09-15 20:24:52 +0200 | [diff] [blame] | 443 | const gchar *archive_path = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(priv->entry_existing_account_archive)); |
| 444 | |
| 445 | bool hasPin = pin and strlen(pin) > 0; |
| 446 | bool hasArchive = archive_path and strlen(archive_path) > 0; |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 447 | |
aviau | 16a94be | 2016-11-10 17:37:32 -0500 | [diff] [blame] | 448 | gtk_widget_set_sensitive( |
Adrien Beraud | 50215a4 | 2017-09-15 20:24:52 +0200 | [diff] [blame] | 449 | priv->entry_existing_account_pin, |
| 450 | (not hasArchive) |
| 451 | ); |
| 452 | gtk_widget_set_sensitive( |
| 453 | priv->entry_existing_account_archive, |
| 454 | (not hasPin) |
| 455 | ); |
| 456 | gtk_widget_set_sensitive( |
| 457 | priv->button_existing_account_next, |
| 458 | (hasArchive || hasPin) |
aviau | 16a94be | 2016-11-10 17:37:32 -0500 | [diff] [blame] | 459 | ); |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | static void |
aviau | 2da3d9c | 2016-09-06 11:28:36 -0400 | [diff] [blame] | 463 | entries_new_account_changed(AccountCreationWizard *view) |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 464 | { |
| 465 | AccountCreationWizardPrivate *priv = ACCOUNT_CREATION_WIZARD_GET_PRIVATE(view); |
| 466 | |
aviau | 692fe6d | 2016-11-08 14:37:34 -0500 | [diff] [blame] | 467 | const gchar *display_name = gtk_entry_get_text(GTK_ENTRY(priv->entry_display_name)); |
| 468 | const gchar *username = gtk_entry_get_text(GTK_ENTRY(priv->entry_username)); |
Sébastien Blin | a8ac86b | 2018-06-29 09:52:40 -0400 | [diff] [blame] | 469 | const gboolean sign_up_blockchain = gtk_switch_get_active(GTK_SWITCH(priv->switch_register)); |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 470 | |
aviau | 2da3d9c | 2016-09-06 11:28:36 -0400 | [diff] [blame] | 471 | if ( |
aviau | 692fe6d | 2016-11-08 14:37:34 -0500 | [diff] [blame] | 472 | strlen(display_name) > 0 && // Display name is longer than 0 |
aviau | 692fe6d | 2016-11-08 14:37:34 -0500 | [diff] [blame] | 473 | ( |
| 474 | (sign_up_blockchain && strlen(username) > 0 && priv->username_available) || // we are signing up, username is set and avaialble |
| 475 | !sign_up_blockchain // We are not signing up |
| 476 | ) |
aviau | 2da3d9c | 2016-09-06 11:28:36 -0400 | [diff] [blame] | 477 | ) |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 478 | { |
| 479 | gtk_widget_set_sensitive(priv->button_account_creation_next, TRUE); |
| 480 | } |
| 481 | else |
| 482 | { |
| 483 | gtk_widget_set_sensitive(priv->button_account_creation_next, FALSE); |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | static void |
Sébastien Blin | a8ac86b | 2018-06-29 09:52:40 -0400 | [diff] [blame] | 488 | sign_up_blockchain_switched(GtkSwitch* switch_btn, GParamSpec*, AccountCreationWizard *view) |
aviau | 2da3d9c | 2016-09-06 11:28:36 -0400 | [diff] [blame] | 489 | { |
| 490 | AccountCreationWizardPrivate *priv = ACCOUNT_CREATION_WIZARD_GET_PRIVATE(view); |
Sébastien Blin | a8ac86b | 2018-06-29 09:52:40 -0400 | [diff] [blame] | 491 | gboolean sign_up_blockchain = gtk_switch_get_active(switch_btn); |
aviau | 2da3d9c | 2016-09-06 11:28:36 -0400 | [diff] [blame] | 492 | |
| 493 | username_registration_box_set_use_blockchain( |
| 494 | USERNAME_REGISTRATION_BOX(priv->username_registration_box), |
| 495 | sign_up_blockchain |
| 496 | ); |
| 497 | |
aviau | 692fe6d | 2016-11-08 14:37:34 -0500 | [diff] [blame] | 498 | gtk_widget_set_sensitive(priv->entry_username, sign_up_blockchain); |
| 499 | |
| 500 | if (!sign_up_blockchain) |
| 501 | { |
| 502 | gtk_entry_set_text(GTK_ENTRY(priv->entry_username), ""); |
| 503 | } |
| 504 | |
aviau | 2da3d9c | 2016-09-06 11:28:36 -0400 | [diff] [blame] | 505 | /* Unchecking blockchain signup when there is an empty username should |
| 506 | * result in activating the next button. |
Sébastien Blin | a8ac86b | 2018-06-29 09:52:40 -0400 | [diff] [blame] | 507 | */ |
aviau | 2da3d9c | 2016-09-06 11:28:36 -0400 | [diff] [blame] | 508 | entries_new_account_changed(view); |
| 509 | } |
| 510 | |
| 511 | static void |
| 512 | username_availability_changed(AccountCreationWizard *view, gboolean username_available) |
| 513 | { |
| 514 | AccountCreationWizardPrivate *priv = ACCOUNT_CREATION_WIZARD_GET_PRIVATE(view); |
| 515 | priv->username_available = username_available; |
| 516 | entries_new_account_changed(view); |
| 517 | } |
| 518 | |
| 519 | static void |
| 520 | build_creation_wizard_view(AccountCreationWizard *view, gboolean show_cancel_button) |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 521 | { |
| 522 | g_return_if_fail(IS_ACCOUNT_CREATION_WIZARD(view)); |
| 523 | AccountCreationWizardPrivate *priv = ACCOUNT_CREATION_WIZARD_GET_PRIVATE(view); |
| 524 | |
| 525 | /* set ring logo */ |
| 526 | GError *error = NULL; |
| 527 | GdkPixbuf* logo_ring = gdk_pixbuf_new_from_resource_at_scale("/cx/ring/RingGnome/ring-logo-blue", |
| 528 | -1, 50, TRUE, &error); |
| 529 | if (logo_ring == NULL) { |
| 530 | g_debug("Could not load logo: %s", error->message); |
| 531 | g_clear_error(&error); |
| 532 | } else |
| 533 | gtk_image_set_from_pixbuf(GTK_IMAGE(priv->choose_account_type_ring_logo), logo_ring); |
| 534 | |
aviau | 2da3d9c | 2016-09-06 11:28:36 -0400 | [diff] [blame] | 535 | /* create the username_registration_box */ |
Sébastien Blin | 79efc02 | 2018-06-29 11:11:09 -0400 | [diff] [blame] | 536 | priv->username_registration_box = username_registration_box_new_empty(false); |
Sébastien Blin | a8ac86b | 2018-06-29 09:52:40 -0400 | [diff] [blame] | 537 | gtk_box_pack_end(GTK_BOX(priv->box_username_entry), GTK_WIDGET(priv->username_registration_box), false, false, 0); |
aviau | 2da3d9c | 2016-09-06 11:28:36 -0400 | [diff] [blame] | 538 | gtk_widget_show(priv->username_registration_box); |
aviau | 692fe6d | 2016-11-08 14:37:34 -0500 | [diff] [blame] | 539 | priv->entry_username = GTK_WIDGET( |
aviau | 2da3d9c | 2016-09-06 11:28:36 -0400 | [diff] [blame] | 540 | username_registration_box_get_entry( |
| 541 | USERNAME_REGISTRATION_BOX(priv->username_registration_box) |
| 542 | ) |
| 543 | ); |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 544 | |
| 545 | /* use the real name / username of the logged in user as the default */ |
| 546 | const char* real_name = g_get_real_name(); |
| 547 | const char* user_name = g_get_user_name(); |
| 548 | g_debug("real_name = %s",real_name); |
| 549 | g_debug("user_name = %s",user_name); |
| 550 | |
| 551 | /* check first if the real name was determined */ |
| 552 | if (g_strcmp0 (real_name,"Unknown") != 0) |
aviau | 692fe6d | 2016-11-08 14:37:34 -0500 | [diff] [blame] | 553 | gtk_entry_set_text(GTK_ENTRY(priv->entry_display_name), real_name); |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 554 | else |
aviau | 692fe6d | 2016-11-08 14:37:34 -0500 | [diff] [blame] | 555 | gtk_entry_set_text(GTK_ENTRY(priv->entry_display_name), user_name); |
| 556 | |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 557 | /* cancel button */ |
| 558 | gtk_widget_set_visible(priv->button_wizard_cancel, show_cancel_button); |
| 559 | |
| 560 | /* choose_account_type signals */ |
Hugo Lefeuvre | 24356d4 | 2018-05-11 10:41:41 -0400 | [diff] [blame] | 561 | g_signal_connect_swapped(priv->button_new_account, "clicked", G_CALLBACK(account_creation_wizard_show_preview), view); |
Adrien Beraud | 50215a4 | 2017-09-15 20:24:52 +0200 | [diff] [blame] | 562 | g_signal_connect_swapped(priv->button_existing_account, "clicked", G_CALLBACK(show_existing_account), view); |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 563 | g_signal_connect(priv->button_wizard_cancel, "clicked", G_CALLBACK(wizard_cancel_clicked), view); |
Sébastien Blin | 61c19d1 | 2018-05-16 12:55:34 -0400 | [diff] [blame] | 564 | g_signal_connect(priv->button_show_advanced, "clicked", G_CALLBACK(show_advanced), view); |
| 565 | g_signal_connect(priv->button_new_sip_account, "clicked", G_CALLBACK(create_new_sip_account), view); |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 566 | |
| 567 | /* account_creation signals */ |
aviau | 692fe6d | 2016-11-08 14:37:34 -0500 | [diff] [blame] | 568 | g_signal_connect_swapped(priv->entry_username, "changed", G_CALLBACK(entries_new_account_changed), view); |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 569 | g_signal_connect(priv->button_account_creation_next, "clicked", G_CALLBACK(account_creation_next_clicked), view); |
Hugo Lefeuvre | 24356d4 | 2018-05-11 10:41:41 -0400 | [diff] [blame] | 570 | g_signal_connect(priv->button_account_creation_previous, "clicked", G_CALLBACK(account_creation_previous_clicked), view); |
aviau | 2da3d9c | 2016-09-06 11:28:36 -0400 | [diff] [blame] | 571 | g_signal_connect_swapped(priv->entry_password, "changed", G_CALLBACK(entries_new_account_changed), view); |
| 572 | g_signal_connect_swapped(priv->entry_password_confirm, "changed", G_CALLBACK(entries_new_account_changed), view); |
aviau | 692fe6d | 2016-11-08 14:37:34 -0500 | [diff] [blame] | 573 | g_signal_connect_swapped(priv->entry_display_name, "changed", G_CALLBACK(entries_new_account_changed), view); |
Sébastien Blin | a8ac86b | 2018-06-29 09:52:40 -0400 | [diff] [blame] | 574 | g_signal_connect(priv->switch_register, "notify::active", G_CALLBACK(sign_up_blockchain_switched), view); |
aviau | 2da3d9c | 2016-09-06 11:28:36 -0400 | [diff] [blame] | 575 | g_signal_connect_swapped(priv->username_registration_box, "username-availability-changed", G_CALLBACK(username_availability_changed), view); |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 576 | |
Adrien Beraud | 50215a4 | 2017-09-15 20:24:52 +0200 | [diff] [blame] | 577 | /* existing_account signals */ |
| 578 | g_signal_connect_swapped(priv->button_existing_account_previous, "clicked", G_CALLBACK(show_choose_account_type), view); |
| 579 | g_signal_connect_swapped(priv->button_existing_account_next, "clicked", G_CALLBACK(existing_account_next_clicked), view); |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 580 | g_signal_connect(priv->entry_existing_account_pin, "changed", G_CALLBACK(entries_existing_account_changed), view); |
Adrien Beraud | 50215a4 | 2017-09-15 20:24:52 +0200 | [diff] [blame] | 581 | g_signal_connect(priv->entry_existing_account_archive, "file-set", G_CALLBACK(entries_existing_account_changed), view); |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 582 | g_signal_connect(priv->entry_existing_account_password, "changed", G_CALLBACK(entries_existing_account_changed), view); |
| 583 | |
| 584 | /* error_view signals */ |
| 585 | g_signal_connect_swapped(priv->button_error_view_ok, "clicked", G_CALLBACK(show_choose_account_type), view); |
| 586 | |
| 587 | show_choose_account_type(view); |
Sébastien Blin | 61c19d1 | 2018-05-16 12:55:34 -0400 | [diff] [blame] | 588 | |
Sébastien Blin | a8ac86b | 2018-06-29 09:52:40 -0400 | [diff] [blame] | 589 | gtk_button_set_relief(GTK_BUTTON(priv->button_show_advanced), GTK_RELIEF_NONE); |
| 590 | |
Sébastien Blin | 61c19d1 | 2018-05-16 12:55:34 -0400 | [diff] [blame] | 591 | auto provider = gtk_css_provider_new(); |
| 592 | gtk_css_provider_load_from_data(provider, |
| 593 | ".black { color: grey; font-size: 0.8em; }\ |
| 594 | .transparent-button { margin-left: 10px; border: 0; background-color: rgba(0,0,0,0); margin-right: 0; padding-right: 0;}", |
| 595 | -1, nullptr |
| 596 | ); |
| 597 | gtk_style_context_add_provider_for_screen(gdk_display_get_default_screen(gdk_display_get_default()), |
| 598 | GTK_STYLE_PROVIDER(provider), |
| 599 | GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); |
aviau | 6aeb485 | 2016-08-18 16:01:09 -0400 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | GtkWidget * |
| 603 | account_creation_wizard_new(bool show_cancel_button) |
| 604 | { |
| 605 | gpointer view = g_object_new(ACCOUNT_CREATION_WIZARD_TYPE, NULL); |
| 606 | |
| 607 | build_creation_wizard_view(ACCOUNT_CREATION_WIZARD(view), show_cancel_button); |
| 608 | return (GtkWidget *)view; |
| 609 | } |
Hugo Lefeuvre | 24356d4 | 2018-05-11 10:41:41 -0400 | [diff] [blame] | 610 | |
| 611 | void |
| 612 | account_creation_wizard_show_preview(AccountCreationWizard *win, gboolean show_preview) |
| 613 | { |
| 614 | AccountCreationWizardPrivate *priv = ACCOUNT_CREATION_WIZARD_GET_PRIVATE(win); |
| 615 | |
Hugo Lefeuvre | 395931b | 2018-07-17 12:13:14 -0400 | [diff] [blame^] | 616 | if (priv->account_creation) { |
| 617 | if (show_preview) |
| 618 | gtk_widget_show(priv->account_creation); |
| 619 | else |
| 620 | gtk_widget_hide(priv->account_creation); |
| 621 | } |
| 622 | |
| 623 | /* Similarily to general settings view, we construct and destroy the avatar manipulation widget |
Hugo Lefeuvre | 24356d4 | 2018-05-11 10:41:41 -0400 | [diff] [blame] | 624 | each time the profile is made visible / hidden. While not the most elegant solution, this |
| 625 | allows us to run the preview if and only if it is displayed, and always stop it when hidden. */ |
| 626 | if (show_preview && !priv->avatar_manipulation) { |
| 627 | priv->avatar_manipulation = avatar_manipulation_new_from_wizard(); |
| 628 | gtk_box_pack_start(GTK_BOX(priv->box_avatarselection), priv->avatar_manipulation, true, true, 0); |
| 629 | gtk_stack_set_visible_child(GTK_STACK(priv->stack_account_creation), priv->account_creation); |
| 630 | } else if (priv->avatar_manipulation) { |
| 631 | /* make sure the AvatarManipulation widget is destroyed so the VideoWidget inside of it is too; |
| 632 | * NOTE: destorying its parent (box_avatarselection) first will cause a mystery 'BadDrawable' |
| 633 | * crash due to X error */ |
| 634 | gtk_container_remove(GTK_CONTAINER(priv->box_avatarselection), priv->avatar_manipulation); |
| 635 | priv->avatar_manipulation = nullptr; |
| 636 | } |
| 637 | } |
| 638 | |
| 639 | void |
| 640 | account_creation_wizard_cancel(AccountCreationWizard *win) |
| 641 | { |
| 642 | // make sure to stop preview before doing something else |
| 643 | account_creation_wizard_show_preview(win, FALSE); |
| 644 | g_signal_emit(G_OBJECT(win), account_creation_wizard_signals[ACCOUNT_CREATION_CANCELED], 0); |
| 645 | } |