empathy-account-assistant.c 39.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 * Copyright (C) 2009 Collabora Ltd.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Authors: Cosimo Cecchi <cosimo.cecchi@collabora.co.uk>
 */

/* empathy-account-assistant.c */

23 24
#include <config.h>
#include <glib/gi18n-lib.h>
25
#include <telepathy-glib/util.h>
Cosimo Cecchi's avatar
Cosimo Cecchi committed
26
#include <gdk/gdkkeysyms.h>
27 28

#include "empathy-account-assistant.h"
29
#include "empathy-import-widget.h"
30
#include "empathy-import-utils.h"
31
#include "empathy-auto-salut-account-helper.h"
32

33
#include <libempathy/empathy-account-settings.h>
34 35
#include <libempathy/empathy-utils.h>

36 37
#include <libempathy-gtk/empathy-account-widget.h>
#include <libempathy-gtk/empathy-protocol-chooser.h>
38
#include <libempathy-gtk/empathy-ui-utils.h>
39

40 41 42
#define DEBUG_FLAG EMPATHY_DEBUG_ACCOUNT
#include <libempathy/empathy-debug.h>

43 44 45
G_DEFINE_TYPE (EmpathyAccountAssistant, empathy_account_assistant,
    GTK_TYPE_ASSISTANT)

46 47 48 49 50 51 52 53 54
#define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountAssistant)

typedef enum {
  RESPONSE_IMPORT = 1,
  RESPONSE_ENTER_ACCOUNT = 2,
  RESPONSE_CREATE_ACCOUNT = 3,
  RESPONSE_SALUT_ONLY = 4
} FirstPageResponse;

55 56 57 58 59
typedef enum {
  RESPONSE_CREATE_AGAIN = 1,
  RESPONSE_CREATE_STOP = 2
} CreateEnterPageResponse;

60
typedef enum {
61 62 63
  PAGE_INTRO = 0,
  PAGE_IMPORT = 1,
  PAGE_ENTER_CREATE = 2,
64
  PAGE_SALUT = 3,
65
} PageID;
66

67
enum {
68 69
  PROP_PARENT = 1,
  PROP_CONNECTION_MGRS,
70 71
};

72 73
typedef struct {
  FirstPageResponse first_resp;
74 75
  CreateEnterPageResponse create_enter_resp;
  gboolean enter_create_forward;
76
  TpAccountManager *account_mgr;
77
  EmpathyConnectionManagers *connection_mgrs;
78
  PageID current_page_id;
79

80 81
  /* enter or create page */
  GtkWidget *enter_or_create_page;
82 83
  GtkWidget *current_account_widget;
  EmpathyAccountWidget *current_widget_object;
84 85 86
  GtkWidget *first_label;
  GtkWidget *second_label;
  GtkWidget *chooser;
87
  GtkWidget *create_again_radio;
88
  EmpathyAccountSettings *settings;
89
  gboolean is_creating;
90

91 92
  /* import page */
  EmpathyImportWidget *iw;
93
  GtkWidget *import_page;
94

95 96 97 98
  /* salut page */
  GtkWidget *salut_page;
  EmpathyAccountSettings *salut_settings;
  GtkWidget *salut_account_widget;
99
  gboolean create_salut_account;
100
  gboolean display_salut_page;
101

102
  GtkWindow *parent_window;
Cosimo Cecchi's avatar
Cosimo Cecchi committed
103 104

  gboolean dispose_run;
105 106
} EmpathyAccountAssistantPriv;

107 108 109 110 111 112
static GtkWidget * account_assistant_build_enter_or_create_page (
    EmpathyAccountAssistant *self);
static void account_assistant_finish_enter_or_create_page (
    EmpathyAccountAssistant *self,
    gboolean is_enter);

113 114
static void do_constructed (GObject *object);

115
static GtkWidget *
116
build_error_vbox (const gchar *primary_message,
117
    const gchar *secondary_message)
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
{
  GtkWidget *main_vbox, *w, *hbox;
  PangoAttrList *list;

  main_vbox = gtk_vbox_new (FALSE, 12);
  gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
  gtk_widget_show (main_vbox);

  hbox = gtk_hbox_new (FALSE, 12);
  gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);
  gtk_widget_show (hbox);

  w = gtk_image_new_from_stock (GTK_STOCK_DIALOG_ERROR,
      GTK_ICON_SIZE_DIALOG);
  gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
  gtk_widget_show (w);

135
  w = gtk_label_new (primary_message);
136 137 138 139 140 141
  gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
  list = pango_attr_list_new ();
  pango_attr_list_insert (list, pango_attr_scale_new (PANGO_SCALE_LARGE));
  pango_attr_list_insert (list, pango_attr_weight_new (PANGO_WEIGHT_BOLD));
  gtk_label_set_attributes (GTK_LABEL (w), list);
  gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
Cosimo Cecchi's avatar
Cosimo Cecchi committed
142
  gtk_label_set_line_wrap (GTK_LABEL (w), TRUE);
143 144 145 146
  gtk_widget_show (w);

  pango_attr_list_unref (list);

147
  w = gtk_label_new (secondary_message);
148 149 150
  gtk_label_set_use_markup (GTK_LABEL (w), TRUE);
  gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0);
  gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
151
  gtk_label_set_line_wrap (GTK_LABEL (w), TRUE);
152 153
  gtk_widget_show (w);

154 155 156 157 158 159 160 161
  return main_vbox;
}

static GtkWidget *
account_assistant_build_error_page (EmpathyAccountAssistant *self,
    GError *error, gint page_num)
{
  GtkWidget *main_vbox, *w;
162 163
  const char *primary_message;
  gchar *secondary_message, *markup;
164 165 166 167 168 169 170 171 172 173 174 175 176
  EmpathyAccountAssistantPriv *priv = GET_PRIV (self);

  if (page_num == PAGE_IMPORT)
    primary_message = _("There was an error while importing the accounts.");
  else if (page_num >= PAGE_ENTER_CREATE &&
      priv->first_resp == RESPONSE_ENTER_ACCOUNT)
    primary_message = _("There was an error while parsing the account details.");
  else if (page_num >= PAGE_ENTER_CREATE &&
      priv->first_resp == RESPONSE_CREATE_ACCOUNT)
    primary_message = _("There was an error while creating the account.");
  else
    primary_message = _("There was an error.");

177 178 179
  markup = g_markup_printf_escaped ("<span style=\"italic\">%s</span>",
      error->message);
  secondary_message = g_strdup_printf (_("The error message was: %s"), markup);
180

181
  main_vbox = build_error_vbox (primary_message, secondary_message);
182

183
  w = gtk_label_new (_("You can either go back and try to enter your "
184
          "accounts' details again or quit this assistant and add accounts "
185 186 187
          "later from the Edit menu."));
  gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 6);
  gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
Cosimo Cecchi's avatar
Cosimo Cecchi committed
188
  gtk_label_set_line_wrap (GTK_LABEL (w), TRUE);
189 190
  gtk_widget_show (w);

191 192
  g_free (markup);
  g_free (secondary_message);
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
  return main_vbox;
}

static void
account_assistant_back_button_clicked_cb (GtkButton *button,
    EmpathyAccountAssistant *self)
{
  gint page_num;

  page_num = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button),
          "page-num"));
  gtk_assistant_remove_action_widget (GTK_ASSISTANT (self),
      GTK_WIDGET (button));
  gtk_assistant_set_current_page (GTK_ASSISTANT (self), page_num);
}

static void
account_assistant_present_error_page (EmpathyAccountAssistant *self,
    GError *error, gint page_num)
{
  GtkWidget *error_page, *back_button;
  gint num;

  error_page = account_assistant_build_error_page (self, error,
      page_num);
  num = gtk_assistant_append_page (GTK_ASSISTANT (self), error_page);
  gtk_assistant_set_page_title (GTK_ASSISTANT (self), error_page,
      _("An error occurred"));
  gtk_assistant_set_page_type (GTK_ASSISTANT (self), error_page,
      GTK_ASSISTANT_PAGE_SUMMARY);

  back_button = gtk_button_new_from_stock (GTK_STOCK_GO_BACK);
  gtk_assistant_add_action_widget (GTK_ASSISTANT (self), back_button);
  g_object_set_data (G_OBJECT (back_button),
      "page-num", GINT_TO_POINTER (page_num));
  g_signal_connect (back_button, "clicked",
      G_CALLBACK (account_assistant_back_button_clicked_cb), self);
  gtk_widget_show (back_button);

  gtk_assistant_set_current_page (GTK_ASSISTANT (self), num);
}

235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
static void
update_create_page_buttons (EmpathyAccountAssistant *self)
{
  EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
  GtkAssistantPageType type;

  if (priv->display_salut_page ||
      priv->create_enter_resp == RESPONSE_CREATE_AGAIN)
    type = GTK_ASSISTANT_PAGE_CONTENT;
  else
    type = GTK_ASSISTANT_PAGE_CONFIRM;

  gtk_assistant_set_page_type (GTK_ASSISTANT (self), priv->enter_or_create_page,
      type);
}

251 252 253 254 255 256 257 258 259 260
static void
account_assistant_reset_enter_create_page (EmpathyAccountAssistant *self)
{
  EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
  GtkWidget *page;
  gint idx;

  page = account_assistant_build_enter_or_create_page (self);
  idx = gtk_assistant_append_page (GTK_ASSISTANT (self), page);
  priv->enter_or_create_page = page;
261
  update_create_page_buttons (self);
262 263 264 265 266 267 268 269

  gtk_assistant_set_current_page (GTK_ASSISTANT (self), idx);

  account_assistant_finish_enter_or_create_page (self,
      priv->first_resp == RESPONSE_ENTER_ACCOUNT ?
      TRUE : FALSE);
}

270 271 272 273 274 275 276
static void
account_assistant_account_enabled_cb (GObject *source,
    GAsyncResult *result,
    gpointer user_data)
{
  GError *error = NULL;
  EmpathyAccountAssistant *self = user_data;
277
  EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
278 279
  const gchar *protocol;
  TpAccount *account = TP_ACCOUNT (source);
280 281
  gint current_idx;
  gboolean salut_created = FALSE;
282

283
  tp_account_set_enabled_finish (account, result, &error);
284 285 286 287 288 289 290

  if (error)
    {
      g_warning ("Error enabling an account: %s", error->message);
      g_error_free (error);
    }

291 292 293
  protocol = tp_account_get_protocol (account);
  if (!tp_strdiff (protocol, "local-xmpp"))
    {
294
      salut_created = TRUE;
295 296
    }

297 298
  empathy_connect_new_account (account, priv->account_mgr);

299 300 301 302 303 304
  current_idx = gtk_assistant_get_current_page (GTK_ASSISTANT (self));
  if (current_idx == PAGE_SALUT && !salut_created)
    /* We are on the Salut page and aren't creating the salut account so don't
     * terminate the assistant. */
    return;

305 306 307 308
  if (priv->create_enter_resp == RESPONSE_CREATE_STOP)
    g_signal_emit_by_name (self, "close");
  else
    account_assistant_reset_enter_create_page (self);
309 310
}

311 312 313 314 315 316
static void
account_assistant_apply_account_cb (GObject *source,
    GAsyncResult *result,
    gpointer user_data)
{
  GError *error = NULL;
317
  EmpathyAccountAssistant *self = user_data;
318
  EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
319
  EmpathyAccountSettings *settings = EMPATHY_ACCOUNT_SETTINGS (source);
320
  TpAccount *account;
321

322
  empathy_account_settings_apply_finish (settings, result, NULL, &error);
323

324 325
  priv->is_creating = FALSE;

326
  if (error != NULL)
327
    {
328 329
      account_assistant_present_error_page (self, error,
          gtk_assistant_get_current_page (GTK_ASSISTANT (self)));
330
      g_error_free (error);
331
      return;
332
    }
333 334 335

  /* enable the newly created account */
  account = empathy_account_settings_get_account (settings);
336
  tp_account_set_enabled_async (account, TRUE,
337
      account_assistant_account_enabled_cb, self);
338 339
}

340
static void
341
account_assistant_apply_account_and_finish (EmpathyAccountAssistant *self,
342 343
    EmpathyAccountSettings *settings,
    gboolean set_display_name)
344 345 346
{
  EmpathyAccountAssistantPriv *priv = GET_PRIV (self);

347
  if (settings == NULL)
348 349
    return;

350 351
  priv->is_creating = TRUE;

352
  if (set_display_name)
353 354 355 356 357
    {
      gchar *display_name;

      display_name = empathy_account_widget_get_default_display_name (
        priv->current_widget_object);
358

359 360
      empathy_account_settings_set_display_name_async (settings,
        display_name, NULL, NULL);
361

362 363
      g_free (display_name);
    }
364

365
  empathy_account_settings_apply_async (settings,
366
      account_assistant_apply_account_cb, self);
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390
}

static void
account_assistant_handle_apply_cb (EmpathyAccountWidget *widget_object,
    gboolean is_valid,
    EmpathyAccountAssistant *self)
{
  EmpathyAccountAssistantPriv *priv = GET_PRIV (self);

  gtk_assistant_set_page_complete (GTK_ASSISTANT (self),
      priv->enter_or_create_page, is_valid);
}

static void
account_assistant_protocol_changed_cb (GtkComboBox *chooser,
    EmpathyAccountAssistant *self)
{
  EmpathyAccountSettings *settings;
  EmpathyAccountAssistantPriv *priv;
  GtkWidget *account_widget;
  EmpathyAccountWidget *widget_object = NULL;

  priv = GET_PRIV (self);

391 392
  settings = empathy_protocol_chooser_create_account_settings (
      EMPATHY_PROTOCOL_CHOOSER (chooser));
393

394
  if (settings == NULL)
395 396
    return;

397 398 399
  if (priv->first_resp == RESPONSE_CREATE_ACCOUNT)
    empathy_account_settings_set_boolean (settings, "register", TRUE);

400
  widget_object = empathy_account_widget_new_for_protocol (settings, TRUE);
401
  account_widget = empathy_account_widget_get_widget (widget_object);
402 403 404 405 406 407 408 409 410 411

  if (priv->current_account_widget != NULL)
    {
      g_signal_handlers_disconnect_by_func (priv->current_widget_object,
          account_assistant_handle_apply_cb, self);
      gtk_widget_destroy (priv->current_account_widget);
    }

  priv->current_account_widget = account_widget;
  priv->current_widget_object = widget_object;
412 413 414 415

  if (priv->settings != NULL)
    g_object_unref (priv->settings);

416 417 418 419 420
  priv->settings = settings;

  g_signal_connect (priv->current_widget_object, "handle-apply",
      G_CALLBACK (account_assistant_handle_apply_cb), self);

421 422 423 424 425 426
  if (empathy_account_settings_is_valid (settings))
    {
      gtk_assistant_set_page_complete (GTK_ASSISTANT (self),
          priv->enter_or_create_page, TRUE);
    }

427 428 429 430 431 432 433 434 435
  gtk_box_pack_start (GTK_BOX (priv->enter_or_create_page), account_widget,
      FALSE, FALSE, 0);
  gtk_widget_show (account_widget);
}

static gboolean
account_assistant_chooser_enter_details_filter_func (
    TpConnectionManager *cm,
    TpConnectionManagerProtocol *protocol,
436
    const gchar *service,
437 438
    gpointer user_data)
{
439
  if (!tp_strdiff (protocol->name, "local-xmpp"))
440 441 442 443 444 445 446 447 448
    return FALSE;

  return TRUE;
}

static gboolean
account_assistant_chooser_create_account_filter_func (
    TpConnectionManager *cm,
    TpConnectionManagerProtocol *protocol,
449
    const gchar *service,
450 451
    gpointer user_data)
{
452
  if (service != NULL)
453 454
    return FALSE;

455 456 457 458 459 460 461 462
  return tp_connection_manager_protocol_can_register (protocol);
}

static void
account_assistant_finish_enter_or_create_page (EmpathyAccountAssistant *self,
    gboolean is_enter)
{
  EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
463

464 465 466 467
  if (is_enter)
    {
      gtk_label_set_label (GTK_LABEL (priv->first_label),
          _("What kind of chat account do you have?"));
468
      /*      gtk_label_set_label (GTK_LABEL (priv->second_label),
469
          _("If you have other accounts to set up, you can do "
Cosimo Cecchi's avatar
Cosimo Cecchi committed
470
              "that at any time from the Edit menu."));
471 472 473
      */
      gtk_label_set_label (GTK_LABEL (priv->second_label),
          _("Do you have any other chat accounts you want to set up?"));
474 475 476 477 478 479 480 481 482 483 484
      empathy_protocol_chooser_set_visible (
          EMPATHY_PROTOCOL_CHOOSER (priv->chooser),
          account_assistant_chooser_enter_details_filter_func, self);

      gtk_assistant_set_page_title (GTK_ASSISTANT (self),
          priv->enter_or_create_page, _("Enter your account details"));
    }
  else
    {
      gtk_label_set_label (GTK_LABEL (priv->first_label),
          _("What kind of chat account do you want to create?"));
485
      /*      gtk_label_set_label (GTK_LABEL (priv->second_label),
Cosimo Cecchi's avatar
Cosimo Cecchi committed
486
          _("You can register other accounts, or setup "
487
              "an existing one at any time from the Edit menu."));
488 489 490
      */
      gtk_label_set_label (GTK_LABEL (priv->second_label),
          _("Do you want to create other chat accounts?"));
491 492 493 494 495 496 497 498
      empathy_protocol_chooser_set_visible (
          EMPATHY_PROTOCOL_CHOOSER (priv->chooser),
          account_assistant_chooser_create_account_filter_func, self);

      gtk_assistant_set_page_title (GTK_ASSISTANT (self),
          priv->enter_or_create_page,
          _("Enter the details for the new account"));
    }
499

500 501
  g_signal_connect (priv->chooser, "changed",
      G_CALLBACK (account_assistant_protocol_changed_cb), self);
502

503 504 505 506
  /* trigger show the first account widget */
  account_assistant_protocol_changed_cb (GTK_COMBO_BOX (priv->chooser), self);
}

507 508 509 510 511 512 513 514 515 516
static gint
account_assistant_page_forward_func (gint current_page,
    gpointer user_data)
{
  EmpathyAccountAssistant *self = user_data;
  EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
  gint retval;

  retval = current_page;

517
  if (current_page == PAGE_INTRO)
518 519 520 521
    {
      if (priv->first_resp == RESPONSE_ENTER_ACCOUNT ||
          priv->first_resp == RESPONSE_CREATE_ACCOUNT)
        retval = PAGE_ENTER_CREATE;
522
      else if (priv->first_resp == RESPONSE_IMPORT)
523
        retval = PAGE_IMPORT;
524 525
      else if (priv->first_resp == RESPONSE_SALUT_ONLY)
        retval = PAGE_SALUT;
526
    }
527 528
  else if (current_page == PAGE_IMPORT)
    {
529 530 531 532 533
      if (priv->display_salut_page)
        retval = PAGE_SALUT;
      else
        /* Don't go forward */
        retval = -1;
534
    }
535 536 537 538 539
  else if (current_page == PAGE_SALUT)
    {
      /* Don't go forward */
      retval = -1;
    }
540
  else if (current_page >= PAGE_ENTER_CREATE)
541
    {
542 543 544 545 546
      if (priv->create_enter_resp == RESPONSE_CREATE_AGAIN)
        {
          priv->enter_create_forward = TRUE;
          retval = current_page;
        }
547
      else if (priv->display_salut_page)
548 549 550
        {
          retval = PAGE_SALUT;
        }
551 552 553 554 555
      else
        {
          /* Don't go forward */
          retval = -1;
        }
556 557
    }

558 559 560
  return retval;
}

561 562 563 564 565 566 567 568 569 570
static void
update_intro_page_buttons (EmpathyAccountAssistant *self)
{
  EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
  GtkWidget *intro_page;

  intro_page = gtk_assistant_get_nth_page (GTK_ASSISTANT (self),
      PAGE_INTRO);

  if (priv->first_resp == RESPONSE_SALUT_ONLY &&
571
      !priv->display_salut_page)
572 573 574 575 576 577 578
    gtk_assistant_set_page_type (GTK_ASSISTANT (self), intro_page,
        GTK_ASSISTANT_PAGE_SUMMARY);
  else
    gtk_assistant_set_page_type (GTK_ASSISTANT (self), intro_page,
        GTK_ASSISTANT_PAGE_INTRO);
}

579 580 581 582 583 584 585 586 587 588 589
static void
account_assistant_radio_choice_toggled_cb (GtkToggleButton *button,
    EmpathyAccountAssistant *self)
{
  FirstPageResponse response;
  EmpathyAccountAssistantPriv *priv = GET_PRIV (self);

  response = GPOINTER_TO_INT (g_object_get_data
      (G_OBJECT (button), "response"));

  priv->first_resp = response;
590 591

  update_intro_page_buttons (self);
592 593
}

594
static GtkWidget *
595
account_assistant_build_introduction_page (EmpathyAccountAssistant *self)
596
{
597
  EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
598 599
  GtkWidget *main_vbox, *hbox_1, *w, *vbox_1;
  GtkWidget *radio = NULL;
600
  GdkPixbuf *pix;
601
  const gchar *str;
602 603 604 605 606 607 608 609 610

  main_vbox = gtk_vbox_new (FALSE, 12);
  gtk_widget_show (main_vbox);
  gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);

  hbox_1 = gtk_hbox_new (FALSE, 12);
  gtk_box_pack_start (GTK_BOX (main_vbox), hbox_1, TRUE, TRUE, 0);
  gtk_widget_show (hbox_1);

611
  w = gtk_label_new (
Cosimo Cecchi's avatar
Cosimo Cecchi committed
612 613 614 615
      _("With Empathy you can chat with people "
        "online nearby and with friends and colleagues "
        "who use Google Talk, AIM, Windows Live "
        "and many other chat programs. With a microphone "
616
        "or a webcam you can also have audio or video calls."));
617
  gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
Cosimo Cecchi's avatar
Cosimo Cecchi committed
618 619
  gtk_label_set_line_wrap (GTK_LABEL (w), TRUE);
  gtk_box_pack_start (GTK_BOX (hbox_1), w, FALSE, FALSE, 0);
620 621
  gtk_widget_show (w);

622
  pix = empathy_pixbuf_from_icon_name_sized ("empathy", 80);
623
  w = gtk_image_new_from_pixbuf (pix);
Cosimo Cecchi's avatar
Cosimo Cecchi committed
624
  gtk_box_pack_start (GTK_BOX (hbox_1), w, FALSE, FALSE, 6);
625 626 627 628
  gtk_widget_show (w);

  g_object_unref (pix);

629
  w = gtk_label_new (_("Do you have an account you've been using "
Cosimo Cecchi's avatar
Cosimo Cecchi committed
630
          "with another chat program?"));
631
  gtk_misc_set_alignment (GTK_MISC (w), 0, 0);
Cosimo Cecchi's avatar
Cosimo Cecchi committed
632
  gtk_label_set_line_wrap (GTK_LABEL (w), TRUE);
633 634 635 636 637 638 639 640
  gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0);
  gtk_widget_show (w);

  w = gtk_alignment_new (0, 0, 0, 0);
  gtk_alignment_set_padding (GTK_ALIGNMENT (w), 0, 0, 12, 0);
  gtk_box_pack_start (GTK_BOX (main_vbox), w, TRUE, TRUE, 0);
  gtk_widget_show (w);

641
  vbox_1 = gtk_vbox_new (TRUE, 0);
642 643 644
  gtk_container_add (GTK_CONTAINER (w), vbox_1);
  gtk_widget_show (vbox_1);

645
  if (empathy_import_accounts_to_import ())
646 647 648 649 650 651 652 653 654 655 656 657
    {
      hbox_1 = gtk_hbox_new (FALSE, 0);
      gtk_box_pack_start (GTK_BOX (vbox_1), hbox_1, TRUE, TRUE, 0);
      gtk_widget_show (hbox_1);

      radio = gtk_radio_button_new_with_label (NULL,
          _("Yes, import my account details from "));
      gtk_box_pack_start (GTK_BOX (hbox_1), radio, TRUE, TRUE, 0);
      g_object_set_data (G_OBJECT (radio), "response",
          GINT_TO_POINTER (RESPONSE_IMPORT));
      gtk_widget_show (radio);

658 659
      w = gtk_combo_box_text_new ();
      gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (w), "Pidgin");
660 661 662 663 664 665
      gtk_box_pack_start (GTK_BOX (hbox_1), w, TRUE, TRUE, 0);
      gtk_combo_box_set_active (GTK_COMBO_BOX (w), 0);
      gtk_widget_show (w);

      g_signal_connect (radio, "clicked",
          G_CALLBACK (account_assistant_radio_choice_toggled_cb), self);
666 667 668 669 670
      priv->first_resp = RESPONSE_IMPORT;
    }
  else
    {
      priv->first_resp = RESPONSE_ENTER_ACCOUNT;
671
    }
672

673 674 675
  str = _("Yes, I'll enter my account details now");

  if (radio == NULL)
676
    {
677 678 679 680 681 682 683 684
      radio = gtk_radio_button_new_with_label (NULL, str);
      w = radio;
    }
  else
    {
      w = gtk_radio_button_new_with_label_from_widget (
          GTK_RADIO_BUTTON (radio), str);
    }
685

686
  gtk_box_pack_start (GTK_BOX (vbox_1), w, TRUE, TRUE, 0);
687 688
  g_object_set_data (G_OBJECT (w), "response",
      GINT_TO_POINTER (RESPONSE_ENTER_ACCOUNT));
689 690
  gtk_widget_show (w);

691 692 693
  g_signal_connect (w, "clicked",
      G_CALLBACK (account_assistant_radio_choice_toggled_cb), self);

Cosimo Cecchi's avatar
Cosimo Cecchi committed
694 695
  w = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio),
      _("No, I want a new account"));
696
  gtk_box_pack_start (GTK_BOX (vbox_1), w, TRUE, TRUE, 0);
697 698
  g_object_set_data (G_OBJECT (w), "response",
      GINT_TO_POINTER (RESPONSE_CREATE_ACCOUNT));
699 700
  gtk_widget_show (w);

701 702 703
  g_signal_connect (w, "clicked",
      G_CALLBACK (account_assistant_radio_choice_toggled_cb), self);

Cosimo Cecchi's avatar
Cosimo Cecchi committed
704 705
  w = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio),
      _("No, I just want to see people online nearby for now"));
706
  gtk_box_pack_start (GTK_BOX (vbox_1), w, TRUE, TRUE, 0);
707 708
  g_object_set_data (G_OBJECT (w), "response",
      GINT_TO_POINTER (RESPONSE_SALUT_ONLY));
709 710
  gtk_widget_show (w);

711 712 713
  g_signal_connect (w, "clicked",
      G_CALLBACK (account_assistant_radio_choice_toggled_cb), self);

714 715 716
  return main_vbox;
}

717 718 719
static GtkWidget *
account_assistant_build_import_page (EmpathyAccountAssistant *self)
{
720 721 722
  GtkWidget *main_vbox, *w, *import;
  EmpathyImportWidget *iw;
  EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
723 724

  main_vbox = gtk_vbox_new (FALSE, 12);
725 726 727
  gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
  w = gtk_label_new (_("Select the accounts you want to import:"));
  gtk_misc_set_alignment (GTK_MISC (w), 0.0, 0.5);
728 729 730
  gtk_widget_show (w);
  gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 6);

731
  w = gtk_alignment_new (0, 0, 1, 1);
732
  gtk_alignment_set_padding (GTK_ALIGNMENT (w), 0, 0, 12, 0);
733
  gtk_box_pack_start (GTK_BOX (main_vbox), w, TRUE, TRUE, 0);
734 735
  gtk_widget_show (w);

736 737
  /* NOTE: this is hardcoded as we support pidgin only */
  iw = empathy_import_widget_new (EMPATHY_IMPORT_APPLICATION_PIDGIN);
738 739 740 741 742 743
  import = empathy_import_widget_get_widget (iw);
  gtk_container_add (GTK_CONTAINER (w), import);
  gtk_widget_show (import);

  priv->iw = iw;

744 745 746 747 748
  gtk_widget_show (main_vbox);

  return main_vbox;
}

749 750 751 752 753 754 755 756 757 758 759
static void
account_assistant_radio_create_again_clicked_cb (GtkButton *button,
    EmpathyAccountAssistant *self)
{
  CreateEnterPageResponse response;
  EmpathyAccountAssistantPriv *priv = GET_PRIV (self);

  response = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button),
          "response"));

  priv->create_enter_resp = response;
760 761

  update_create_page_buttons (self);
762 763
}

764
static GtkWidget *
765
account_assistant_build_enter_or_create_page (EmpathyAccountAssistant *self)
766
{
767
  EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
768
  GtkWidget *main_vbox, *w, *chooser, *vbox, *hbox, *radio;
769 770 771 772 773

  main_vbox = gtk_vbox_new (FALSE, 12);
  gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
  gtk_widget_show (main_vbox);

774 775 776 777
  hbox = gtk_hbox_new (FALSE, 6);
  gtk_box_pack_start (GTK_BOX (main_vbox), hbox, FALSE, FALSE, 0);
  gtk_widget_show (hbox);

778
  w = gtk_label_new (NULL);
779
  gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
780 781
  gtk_widget_show (w);
  priv->first_label = w;
782 783 784 785 786 787 788

  w = gtk_alignment_new (0, 0, 0, 0);
  gtk_alignment_set_padding (GTK_ALIGNMENT (w), 0, 0, 12, 0);
  gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0);
  gtk_widget_show (w);

  chooser = empathy_protocol_chooser_new ();
789
  gtk_box_pack_start (GTK_BOX (hbox), chooser, FALSE, FALSE, 0);
790
  gtk_widget_show (chooser);
791
  priv->chooser = chooser;
792

793 794 795
  vbox = gtk_vbox_new (FALSE, 6);
  gtk_box_pack_end (GTK_BOX (main_vbox), vbox, FALSE, FALSE, 0);
  gtk_widget_show (vbox);
796

797
  w = gtk_label_new (NULL);
798
  gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0);
Cosimo Cecchi's avatar
Cosimo Cecchi committed
799 800
  gtk_label_set_line_wrap (GTK_LABEL (w), TRUE);
  gtk_misc_set_alignment (GTK_MISC (w), 0.0, 0.5);
801
  gtk_widget_show (w);
802
  priv->second_label = w;
803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832

  w = gtk_alignment_new (0, 0, 0, 0);
  gtk_alignment_set_padding (GTK_ALIGNMENT (w), 0, 0, 12, 0);
  gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0);
  gtk_widget_show (w);

  hbox = gtk_hbox_new (FALSE, 6);
  gtk_container_add (GTK_CONTAINER (w), hbox);
  gtk_widget_show (hbox);

  radio = gtk_radio_button_new_with_label (NULL, _("Yes"));
  gtk_box_pack_start (GTK_BOX (hbox), radio, FALSE, FALSE, 0);
  g_object_set_data (G_OBJECT (radio), "response",
      GINT_TO_POINTER (RESPONSE_CREATE_AGAIN));
  gtk_widget_show (radio);

  w = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio),
      _("No, that's all for now"));
  gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
  g_object_set_data (G_OBJECT (w), "response",
      GINT_TO_POINTER (RESPONSE_CREATE_STOP));
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (w), TRUE);
  priv->create_enter_resp = RESPONSE_CREATE_STOP;
  priv->create_again_radio = w;
  gtk_widget_show (w);

  g_signal_connect (w, "clicked",
      G_CALLBACK (account_assistant_radio_create_again_clicked_cb), self);
  g_signal_connect (radio, "clicked",
      G_CALLBACK (account_assistant_radio_create_again_clicked_cb), self);
833

834 835 836
  return main_vbox;
}

837 838 839 840 841 842 843 844 845 846 847 848
static void
account_assistant_close_cb (GtkAssistant *assistant,
    gpointer user_data)
{
  EmpathyAccountAssistantPriv *priv = GET_PRIV (assistant);

  if (priv->is_creating)
    return;

  gtk_widget_destroy (GTK_WIDGET (assistant));
}

849 850 851 852
static void
impl_signal_apply (GtkAssistant *assistant)
{
  EmpathyAccountAssistant *self = EMPATHY_ACCOUNT_ASSISTANT (assistant);
853
  EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
854 855 856 857
  gint current_page;

  current_page = gtk_assistant_get_current_page (assistant);

858 859 860
  if (current_page == PAGE_SALUT)
    {
      if (priv->create_salut_account)
861 862 863 864
        /* create_salut_account_settings() already set the display name of the
         * account so there is no need to set it again. */
        account_assistant_apply_account_and_finish (self, priv->salut_settings,
            FALSE);
865 866
      return;
    }
867
  else if (current_page >= PAGE_ENTER_CREATE &&
868 869 870
      priv->settings != NULL &&
      empathy_account_settings_is_valid (priv->settings))
    {
871
      account_assistant_apply_account_and_finish (self, priv->settings, TRUE);
872 873
      g_object_unref (priv->settings);
      priv->settings = NULL;
874
    }
875 876 877 878
  else if (current_page == PAGE_IMPORT)
    {
      empathy_import_widget_add_selected_accounts (priv->iw);
    }
879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894
}

static void
impl_signal_cancel (GtkAssistant *assistant)
{
  gtk_widget_destroy (GTK_WIDGET (assistant));
}

static void
impl_signal_prepare (GtkAssistant *assistant,
    GtkWidget *current_page)
{
  EmpathyAccountAssistant *self = EMPATHY_ACCOUNT_ASSISTANT (assistant);
  EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
  gint current_idx;

895
  /* check from which page we are coming from */
896 897
  if (priv->current_page_id == PAGE_IMPORT)
    empathy_import_widget_add_selected_accounts (priv->iw);
898

899
  current_idx = gtk_assistant_get_current_page (assistant);
900
  priv->current_page_id = current_idx;
901

902
  if (current_idx >= PAGE_ENTER_CREATE)
903
    {
904
      if (!priv->enter_create_forward && current_idx != PAGE_SALUT)
905 906 907 908 909 910 911 912
        {
          account_assistant_finish_enter_or_create_page (self,
              priv->first_resp == RESPONSE_ENTER_ACCOUNT ?
              TRUE : FALSE);
        }
      else
        {
          priv->enter_create_forward = FALSE;
913 914 915 916 917
        }

      if (priv->settings != NULL &&
          empathy_account_settings_is_valid (priv->settings))
        {
918 919
          account_assistant_apply_account_and_finish (self, priv->settings,
              TRUE);
920 921
          g_object_unref (priv->settings);
          priv->settings = NULL;
922
        }
923 924 925
    }
}

926 927 928 929 930 931 932 933 934 935 936 937 938
static void
do_get_property (GObject *object,
    guint property_id,
    GValue *value,
    GParamSpec *pspec)
{
  EmpathyAccountAssistantPriv *priv = GET_PRIV (object);

  switch (property_id)
    {
    case PROP_PARENT:
      g_value_set_object (value, priv->parent_window);
      break;
939 940 941
    case PROP_CONNECTION_MGRS:
      g_value_set_object (value, priv->connection_mgrs);
      break;
942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
    }
}

static void
do_set_property (GObject *object,
    guint property_id,
    const GValue *value,
    GParamSpec *pspec)
{
  EmpathyAccountAssistantPriv *priv = GET_PRIV (object);

  switch (property_id)
    {
    case PROP_PARENT:
      priv->parent_window = g_value_get_object (value);
      break;
960 961 962
    case PROP_CONNECTION_MGRS:
      priv->connection_mgrs = g_value_dup_object (value);
      break;
963 964 965 966 967
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
    }
}

Cosimo Cecchi's avatar
Cosimo Cecchi committed
968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983
static void
do_dispose (GObject *obj)
{
  EmpathyAccountAssistantPriv *priv = GET_PRIV (obj);

  if (priv->dispose_run)
    return;

  priv->dispose_run = TRUE;

  if (priv->settings != NULL)
    {
      g_object_unref (priv->settings);
      priv->settings = NULL;
    }

984 985 986
  g_object_unref (priv->account_mgr);
  priv->account_mgr = NULL;

987 988 989
  g_object_unref (priv->connection_mgrs);
  priv->connection_mgrs = NULL;

Cosimo Cecchi's avatar
Cosimo Cecchi committed
990 991 992 993
  if (G_OBJECT_CLASS (empathy_account_assistant_parent_class)->dispose != NULL)
    G_OBJECT_CLASS (empathy_account_assistant_parent_class)->dispose (obj);
}

994 995 996
static void
empathy_account_assistant_class_init (EmpathyAccountAssistantClass *klass)
{
997
  GObjectClass *oclass = G_OBJECT_CLASS (klass);
998
  GtkAssistantClass *gtkclass = GTK_ASSISTANT_CLASS (klass);
999 1000 1001 1002 1003
  GParamSpec *param_spec;

  oclass->get_property = do_get_property;
  oclass->set_property = do_set_property;
  oclass->constructed = do_constructed;
Cosimo Cecchi's avatar
Cosimo Cecchi committed
1004
  oclass->dispose = do_dispose;
1005

1006 1007 1008 1009
  gtkclass->apply = impl_signal_apply;
  gtkclass->prepare = impl_signal_prepare;
  gtkclass->cancel = impl_signal_cancel;

1010 1011 1012 1013 1014 1015
  param_spec = g_param_spec_object ("parent-window",
      "parent-window", "The parent window",
      GTK_TYPE_WINDOW,
      G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
  g_object_class_install_property (oclass, PROP_PARENT, param_spec);

1016 1017 1018 1019 1020 1021
  param_spec = g_param_spec_object ("connection-managers",
      "connection-managers", "A EmpathyConnectionManagers",
      EMPATHY_TYPE_CONNECTION_MANAGERS,
      G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT_ONLY);
  g_object_class_install_property (oclass, PROP_CONNECTION_MGRS, param_spec);

1022
  g_type_class_add_private (klass, sizeof (EmpathyAccountAssistantPriv));
1023 1024
}

1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039
static void
create_salut_check_box_toggled_cb (GtkWidget *widget,
    EmpathyAccountAssistant *self)
{
  EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
  gboolean sensitive;
  gboolean page_valid;

  sensitive = !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));

  gtk_widget_set_sensitive (priv->salut_account_widget, sensitive);

  if (!sensitive)
    {
      page_valid = TRUE;
1040
      priv->create_salut_account = FALSE;
1041 1042 1043 1044 1045
    }
  else
    {
      /* page is complete if the account is valid */
      page_valid = empathy_account_settings_is_valid (priv->salut_settings);
1046
      priv->create_salut_account = TRUE;
1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072
    }

  gtk_assistant_set_page_complete (GTK_ASSISTANT (self), priv->salut_page,
      page_valid);
}

static void
account_assistant_salut_handle_apply_cb (EmpathyAccountWidget *widget_object,
    gboolean is_valid,
    EmpathyAccountAssistant *self)
{
  EmpathyAccountAssistantPriv *priv = GET_PRIV (self);

  gtk_assistant_set_page_complete (GTK_ASSISTANT (self),
      priv->salut_page, is_valid);
}

static GtkWidget *
account_assistant_build_salut_page (EmpathyAccountAssistant *self)
{
  EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
  GtkWidget *main_vbox, *hbox_1, *w;
  GdkPixbuf *pix;
  EmpathyAccountSettings *settings;
  GtkWidget *account_widget;
  EmpathyAccountWidget *widget_object;
1073
  gchar *markup;
1074 1075 1076 1077 1078 1079 1080 1081 1082

  main_vbox = gtk_vbox_new (FALSE, 12);
  gtk_widget_show (main_vbox);
  gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);

  hbox_1 = gtk_hbox_new (FALSE, 12);
  gtk_box_pack_start (GTK_BOX (main_vbox), hbox_1, TRUE, TRUE, 0);
  gtk_widget_show (hbox_1);

1083
  w = gtk_label_new (NULL);
1084
  markup = g_strdup_printf ("%s (<span style=\"italic\">%s</span>).",
1085 1086 1087 1088 1089
      _("Empathy can automatically discover and chat with the people "
        "connected on the same network as you. "
        "If you want to use this feature, please check that the "
        "details below are correct. "
        "You can easily change these details later or disable this feature "
1090 1091 1092 1093
        "by using the 'Accounts' dialog"),
      _("Edit->Accounts"));
  gtk_label_set_markup (GTK_LABEL (w), markup);
  g_free (markup);
1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105
  gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
  gtk_label_set_line_wrap (GTK_LABEL (w), TRUE);
  gtk_box_pack_start (GTK_BOX (hbox_1), w, FALSE, FALSE, 0);
  gtk_widget_show (w);

  pix = empathy_pixbuf_from_icon_name_sized ("im-local-xmpp", 80);
  w = gtk_image_new_from_pixbuf (pix);
  gtk_box_pack_start (GTK_BOX (hbox_1), w, FALSE, FALSE, 6);
  gtk_widget_show (w);

  g_object_unref (pix);

1106 1107
  w = gtk_check_button_new_with_mnemonic (
      _("I do _not want to enable this feature for now"));
1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135
  gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0);
  g_signal_connect (w, "toggled",
      G_CALLBACK (create_salut_check_box_toggled_cb), self);
  gtk_widget_show (w);

  w = gtk_alignment_new (0, 0, 0, 0);
  gtk_alignment_set_padding (GTK_ALIGNMENT (w), 0, 0, 12, 0);
  gtk_box_pack_start (GTK_BOX (main_vbox), w, TRUE, TRUE, 0);
  gtk_widget_show (w);

  settings = create_salut_account_settings ();

  widget_object = empathy_account_widget_new_for_protocol (settings, TRUE);
  account_widget = empathy_account_widget_get_widget (widget_object);

  priv->salut_settings = settings;
  priv->salut_account_widget = account_widget;

  g_signal_connect (widget_object, "handle-apply",
      G_CALLBACK (account_assistant_salut_handle_apply_cb), self);

  gtk_box_pack_start (GTK_BOX (main_vbox), account_widget,
      FALSE, FALSE, 0);
  gtk_widget_show (account_widget);

  return main_vbox;
}

1136 1137 1138
static GtkWidget *
account_assistant_build_salut_error_page (EmpathyAccountAssistant *self)
{
1139 1140 1141 1142
  GtkWidget *vbox;
  gchar *markup;

  markup = g_strdup_printf ("%s (<span style=\"italic\">%s</span>).",
1143
      _("You won't be able to chat with people connected to your local "
1144 1145 1146
        "network, as telepathy-salut is not installed. If you want to enable "
        "this feature, please install the telepathy-salut package and create "
        "a People Nearby account from the Accounts dialog"),
1147 1148 1149 1150 1151
        _("Edit->Accounts"));

  vbox = build_error_vbox (_("telepathy-salut not installed"), markup);
  g_free (markup);
  return vbox;
1152 1153
}

1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173
static void
account_mgr_prepare_cb (GObject *source_object,
    GAsyncResult *result,
    gpointer user_data)
{
  EmpathyAccountAssistant *self = user_data;
  EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
  TpAccountManager *manager = TP_ACCOUNT_MANAGER (source_object);
  GError *error = NULL;

  if (!tp_account_manager_prepare_finish (manager, result, &error))
    {
      DEBUG ("Failed to prepare account manager: %s", error->message);
      g_error_free (error);
      return;
    }

  if (!should_create_salut_account (manager))
    {
      DEBUG ("No need to create a Salut account");
1174
      priv->display_salut_page = FALSE;
1175 1176

      update_intro_page_buttons (self);
1177 1178 1179

      gtk_assistant_set_page_type (GTK_ASSISTANT (self), priv->import_page,
          GTK_ASSISTANT_PAGE_CONFIRM);
1180 1181

      update_create_page_buttons (self);
1182 1183 1184
    }
}

1185 1186 1187
static void
empathy_account_assistant_init (EmpathyAccountAssistant *self)
{
1188
  EmpathyAccountAssistantPriv *priv;
1189

1190 1191 1192 1193
  priv = G_TYPE_INSTANCE_GET_PRIVATE (self, EMPATHY_TYPE_ACCOUNT_ASSISTANT,
      EmpathyAccountAssistantPriv);
  self->priv = priv;

1194 1195 1196
  gtk_window_set_title (GTK_WINDOW (self),
      _("Messaging and VoIP Accounts Assistant"));

1197
  priv->account_mgr = tp_account_manager_dup ();
1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217
}

static void
do_constructed (GObject *object)
{
  GtkAssistant *assistant = GTK_ASSISTANT (object);
  EmpathyAccountAssistant *self = EMPATHY_ACCOUNT_ASSISTANT (object);
  EmpathyAccountAssistantPriv *priv = GET_PRIV (object);
  GtkWidget *page;

  /* set us as transient for the parent window if any */
  if (priv->parent_window)
    gtk_window_set_transient_for (GTK_WINDOW (object),
        priv->parent_window);

  /* set the dialog hint, so this will be centered over the parent window */
  gtk_window_set_type_hint (GTK_WINDOW (object), GDK_WINDOW_TYPE_HINT_DIALOG);

  g_assert (priv->connection_mgrs != NULL);
  g_assert (empathy_connection_managers_is_ready (priv->connection_mgrs));
1218

1219 1220 1221
  g_signal_connect (self, "close",
      G_CALLBACK (account_assistant_close_cb), NULL);

1222 1223 1224 1225
  gtk_assistant_set_forward_page_func (assistant,
      account_assistant_page_forward_func, self, NULL);

  /* first page (introduction) */
1226
  page = account_assistant_build_introduction_page (self);
1227 1228
  gtk_assistant_append_page (assistant, page);
  gtk_assistant_set_page_title (assistant, page,
Cosimo Cecchi's avatar
Cosimo Cecchi committed
1229
      _("Welcome to Empathy"));
1230
  gtk_assistant_set_page_type (assistant, page,
Cosimo Cecchi's avatar
Cosimo Cecchi committed
1231
      GTK_ASSISTANT_PAGE_INTRO);
1232 1233 1234 1235 1236 1237 1238 1239
  gtk_assistant_set_page_complete (assistant, page, TRUE);

  /* second page (import accounts) */
  page = account_assistant_build_import_page (self);
  gtk_assistant_append_page (assistant, page);
  gtk_assistant_set_page_title (assistant, page,
      _("Import your existing accounts"));
  gtk_assistant_set_page_complete (assistant, page, TRUE);
1240
  gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_CONTENT);
1241
  priv->import_page = page;
1242 1243

  /* third page (enter account details) */
1244
  page = account_assistant_build_enter_or_create_page (self);
1245
  gtk_assistant_append_page (assistant, page);
1246
  gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_CONTENT);
1247
  priv->enter_or_create_page = page;
1248

1249
  /* fourth page (salut details) */
1250 1251 1252 1253 1254 1255 1256 1257 1258 1259
  if (empathy_connection_managers_get_cm (priv->connection_mgrs, "salut")
      != NULL)
    {
      page = account_assistant_build_salut_page (self);
      gtk_assistant_append_page (assistant, page);
      gtk_assistant_set_page_title (assistant, page,
          _("Please enter personal details"));
      gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_CONFIRM);

      priv->create_salut_account = TRUE;
1260 1261 1262 1263 1264 1265

      if (empathy_account_settings_is_valid (priv->salut_settings))
        {
          gtk_assistant_set_page_complete (GTK_ASSISTANT (self),
              page, TRUE);
        }
1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276
    }
  else
    {
      page = account_assistant_build_salut_error_page (self);
      gtk_assistant_append_page (assistant, page);
      gtk_assistant_set_page_title (assistant, page, _("An error occurred"));
      gtk_assistant_set_page_type (assistant, page, GTK_ASSISTANT_PAGE_SUMMARY);

      priv->create_salut_account = FALSE;
    }

1277
  priv->salut_page = page;
1278
  priv->display_salut_page = TRUE;
1279 1280 1281

  tp_account_manager_prepare_async (priv->account_mgr, NULL,
      account_mgr_prepare_cb, self);
1282

1283
  gtk_window_set_resizable (GTK_WINDOW (self), FALSE);
1284 1285 1286
}

GtkWidget *
1287 1288
empathy_account_assistant_show (GtkWindow *window,
    EmpathyConnectionManagers *connection_mgrs)
1289
{
1290 1291 1292 1293
  static GtkWidget *dialog = NULL;

  if (dialog == NULL)
    {
1294
      dialog = g_object_new (EMPATHY_TYPE_ACCOUNT_ASSISTANT,
1295 1296 1297
          "parent-window", window,
          "connection-managers", connection_mgrs,
          NULL);
1298 1299 1300 1301 1302 1303
      g_object_add_weak_pointer (G_OBJECT (dialog), (gpointer *) &dialog);
    }

  gtk_window_present (GTK_WINDOW (dialog));

  return dialog;
1304
}
1305 1306