]> git.0d.be Git - empathy.git/blob - src/empathy-account-assistant.c
Add private struct and responses to first page
[empathy.git] / src / empathy-account-assistant.c
1 /*
2  * Copyright (C) 2009 Collabora Ltd.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17  *
18  * Authors: Cosimo Cecchi <cosimo.cecchi@collabora.co.uk>
19  */
20
21 /* empathy-account-assistant.c */
22
23 #include <glib/gi18n.h>
24
25 #include "empathy-account-assistant.h"
26
27 #include <libempathy/empathy-utils.h>
28
29 #include <libempathy-gtk/empathy-ui-utils.h>
30
31 G_DEFINE_TYPE (EmpathyAccountAssistant, empathy_account_assistant,
32     GTK_TYPE_ASSISTANT)
33
34 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyAccountAssistant)
35
36 typedef enum {
37   RESPONSE_IMPORT = 1,
38   RESPONSE_ENTER_ACCOUNT = 2,
39   RESPONSE_CREATE_ACCOUNT = 3,
40   RESPONSE_SALUT_ONLY = 4
41 } FirstPageResponse;
42
43 typedef struct {
44   FirstPageResponse first_resp;
45 } EmpathyAccountAssistantPriv;
46
47 static void
48 account_assistant_radio_choice_toggled_cb (GtkToggleButton *button,
49     EmpathyAccountAssistant *self)
50 {
51   FirstPageResponse response;
52   EmpathyAccountAssistantPriv *priv = GET_PRIV (self);
53
54   response = GPOINTER_TO_INT (g_object_get_data
55       (G_OBJECT (button), "response"));
56
57   g_print ("choice %d toggled\n", response);
58   priv->first_resp = response;
59 }
60
61 static GtkWidget *
62 account_assistant_build_introduction_page (EmpathyAccountAssistant *self)
63 {
64   GtkWidget *main_vbox, *hbox_1, *w, *radio, *vbox_1;
65   GdkPixbuf *pix;
66
67   main_vbox = gtk_vbox_new (FALSE, 12);
68   gtk_widget_show (main_vbox);
69   gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 12);
70
71   hbox_1 = gtk_hbox_new (FALSE, 12);
72   gtk_box_pack_start (GTK_BOX (main_vbox), hbox_1, TRUE, TRUE, 0);
73   gtk_widget_show (hbox_1);
74
75   w = gtk_label_new (_("With Empathy you can chat with people \nonline nearby "
76           "and with friends and colleagues \nwho use Google Talk, AIM, "
77           "Windows Live \nand many other chat programs. With a microphone \n"
78           "or a webcam you can also have audio or video calls."));
79   gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
80   gtk_box_pack_start (GTK_BOX (hbox_1), w, TRUE, TRUE, 0);
81   gtk_widget_show (w);
82
83   pix = empathy_pixbuf_from_icon_name_sized ("empathy", 96);
84   w = gtk_image_new_from_pixbuf (pix);
85   gtk_box_pack_start (GTK_BOX (hbox_1), w, TRUE, TRUE, 6);
86   gtk_widget_show (w);
87
88   g_object_unref (pix);
89
90   w = gtk_label_new (_("Do you have an account you've been using with another "
91           "chat program?"));
92   gtk_misc_set_alignment (GTK_MISC (w), 0, 0);
93   gtk_box_pack_start (GTK_BOX (main_vbox), w, FALSE, FALSE, 0);
94   gtk_widget_show (w);
95
96   w = gtk_alignment_new (0, 0, 0, 0);
97   gtk_alignment_set_padding (GTK_ALIGNMENT (w), 0, 0, 12, 0);
98   gtk_box_pack_start (GTK_BOX (main_vbox), w, TRUE, TRUE, 0);
99   gtk_widget_show (w);
100
101   vbox_1 = gtk_vbox_new (FALSE, 6);
102   gtk_container_add (GTK_CONTAINER (w), vbox_1);
103   gtk_widget_show (vbox_1);
104
105   /* TODO: this will have to be updated when kutio's branch have landed */
106   radio = gtk_radio_button_new_with_label (NULL,
107       _("Yes, import my account details from "));
108   gtk_box_pack_start (GTK_BOX (vbox_1), radio, TRUE, TRUE, 0);
109   g_object_set_data (G_OBJECT (radio), "response",
110       GINT_TO_POINTER (RESPONSE_IMPORT));
111   gtk_widget_show (radio);
112
113   g_signal_connect (radio, "clicked",
114       G_CALLBACK (account_assistant_radio_choice_toggled_cb), self);
115
116   w = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio),
117       _("Yes, I'll enter my account details now"));
118   gtk_box_pack_start (GTK_BOX (vbox_1), w, TRUE, TRUE, 0);
119   g_object_set_data (G_OBJECT (w), "response",
120       GINT_TO_POINTER (RESPONSE_ENTER_ACCOUNT));
121   gtk_widget_show (w);
122
123   g_signal_connect (w, "clicked",
124       G_CALLBACK (account_assistant_radio_choice_toggled_cb), self);
125
126   w = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio),
127       _("No, I want a new account"));
128   gtk_box_pack_start (GTK_BOX (vbox_1), w, TRUE, TRUE, 0);
129   g_object_set_data (G_OBJECT (w), "response",
130       GINT_TO_POINTER (RESPONSE_CREATE_ACCOUNT));
131   gtk_widget_show (w);
132
133   g_signal_connect (w, "clicked",
134       G_CALLBACK (account_assistant_radio_choice_toggled_cb), self);
135
136   w = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio),
137       _("No, I just want to see people online nearby for now"));
138   gtk_box_pack_start (GTK_BOX (vbox_1), w, TRUE, TRUE, 0);
139   g_object_set_data (G_OBJECT (w), "response",
140       GINT_TO_POINTER (RESPONSE_SALUT_ONLY));
141   gtk_widget_show (w);
142
143   g_signal_connect (w, "clicked",
144       G_CALLBACK (account_assistant_radio_choice_toggled_cb), self);
145
146   return main_vbox;
147 }
148
149 static void
150 empathy_account_assistant_class_init (EmpathyAccountAssistantClass *klass)
151 {
152   g_type_class_add_private (klass, sizeof (EmpathyAccountAssistantPriv));
153 }
154
155 static void
156 empathy_account_assistant_init (EmpathyAccountAssistant *self)
157 {
158   EmpathyAccountAssistantPriv *priv;
159   GtkWidget *page;
160
161   priv = G_TYPE_INSTANCE_GET_PRIVATE (self, EMPATHY_TYPE_ACCOUNT_ASSISTANT,
162       EmpathyAccountAssistantPriv);
163   self->priv = priv;
164
165   /* first page */
166   page = account_assistant_build_introduction_page (self);
167   gtk_assistant_append_page (GTK_ASSISTANT (self), page);
168   gtk_assistant_set_page_title (GTK_ASSISTANT (self), page,
169       _("Welcome to Empathy"));
170   gtk_assistant_set_page_type (GTK_ASSISTANT (self), page,
171       GTK_ASSISTANT_PAGE_INTRO);
172   gtk_assistant_set_page_complete (GTK_ASSISTANT (self), page, TRUE);
173 }
174
175 GtkWidget *
176 empathy_account_assistant_new (void)
177 {
178   return g_object_new (EMPATHY_TYPE_ACCOUNT_ASSISTANT, NULL);
179 }