1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
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
|
/* -*- Mode: vala; indent-tabs-mode: t; c-basic-offset: 2; tab-width: 8 -*- */
/*
* Copyright (C) 2011 Alexander Larsson <alexl@redhat.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using Gtk;
using Folks;
public class Contacts.SetupWindow : Gtk.Window {
public bool succeeded;
private ulong source_list_changed_id;
public Label title_label;
public Grid content_grid;
ToolButton select_button;
ListStore list_store;
TreeView tree_view;
public void update_content () {
foreach (var w in content_grid.get_children ()) {
w.destroy ();
}
var l = new Label (_("Welcome to Contacts! Please select where you want to keep your address book:"));
l.set_line_wrap (true);
l.set_max_width_chars (5);
l.set_halign (Align.FILL);
l.set_alignment (0.0f, 0.5f);
content_grid.add (l);
Button goa_button;
if (has_goa_account ()) {
select_button.show ();
tree_view = new TreeView ();
var store = new ListStore (2, typeof (string), typeof (Folks.PersonaStore));
list_store = store;
tree_view.set_model (store);
tree_view.set_headers_visible (false);
tree_view.get_selection ().set_mode (SelectionMode.BROWSE);
var column = new Gtk.TreeViewColumn ();
tree_view.append_column (column);
var renderer = new Gtk.CellRendererText ();
column.pack_start (renderer, false);
column.add_attribute (renderer, "text", 0);
var scrolled = new ScrolledWindow(null, null);
scrolled.set_size_request (340, 220);
scrolled.set_policy (PolicyType.NEVER, PolicyType.AUTOMATIC);
scrolled.set_vexpand (false);
scrolled.set_shadow_type (ShadowType.IN);
scrolled.add (tree_view);
content_grid.add (scrolled);
TreeIter iter;
foreach (var persona_store in Contact.get_eds_address_books ()) {
var name = Contact.format_persona_store_name (persona_store);
store.append (out iter);
store.set (iter, 0, name, 1, persona_store);
if (persona_store == App.app.contacts_store.aggregator.primary_store) {
tree_view.get_selection ().select_iter (iter);
}
}
goa_button = new Button.with_label (_("Online Account Settings"));
content_grid.add (goa_button);
} else {
select_button.hide ();
l = new Label (_("Setup an online account or use a local address book"));
content_grid.add (l);
goa_button = new Button.with_label (_("Online Accounts"));
content_grid.add (goa_button);
var b = new Button.with_label (_("Use Local Address Book"));
content_grid.add (b);
b.clicked.connect ( () => {
var source = eds_source_list.peek_source_by_uid (eds_local_store);
select_source (source);
});
}
goa_button.clicked.connect ( (button) => {
try {
update_content ();
Process.spawn_command_line_async ("gnome-control-center online-accounts");
}
catch (Error e) {
// TODO: Show error dialog
}
});
content_grid.show_all ();
}
private void select_source (E.Source source) {
try {
E.BookClient.set_default_source (source);
} catch {
warning ("Failed to set address book");
}
succeeded = true;
App.app.settings.set_boolean ("did-initial-setup", true);
destroy ();
}
public SetupWindow () {
var grid = new Grid ();
this.add (grid);
this.set_title (_("Contacts Setup"));
this.set_default_size (640, 480);
this.hide_titlebar_when_maximized = true;
var toolbar = new Toolbar ();
toolbar.set_icon_size (IconSize.MENU);
toolbar.get_style_context ().add_class (STYLE_CLASS_MENUBAR);
toolbar.set_vexpand (false);
toolbar.set_hexpand (true);
grid.attach (toolbar, 0, 0, 1, 1);
var cancel_button = new ToolButton (null, _("Cancel"));
cancel_button.is_important = true;
toolbar.add (cancel_button);
cancel_button.clicked.connect ( (button) => {
this.destroy ();
});
var item = new ToolItem ();
title_label = new Label ("");
title_label.set_markup ("<b>%s</b>".printf (_("Contacts Setup")));
title_label.set_no_show_all (true);
item.add (title_label);
item.set_expand (true);
toolbar.add (item);
select_button = new ToolButton (null, _("Select"));
select_button.is_important = true;
select_button.set_no_show_all (true);
toolbar.add (select_button);
select_button.clicked.connect ( (button) => {
PersonaStore selected_store;
TreeIter iter;
if (tree_view.get_selection() .get_selected (null, out iter)) {
list_store.get (iter, 1, out selected_store);
var e_store = selected_store as Edsf.PersonaStore;
select_source (e_store.source);
}
});
var frame = new Frame (null);
frame.get_style_context ().add_class ("contacts-content");
var box = new EventBox ();
box.set_hexpand (true);
box.set_vexpand (true);
box.get_style_context ().add_class ("contacts-main-view");
box.get_style_context ().add_class ("view");
frame.add (box);
grid.attach (frame, 0, 1, 1, 1);
content_grid = new Grid ();
content_grid.set_border_width (12);
content_grid.set_orientation (Orientation.VERTICAL);
content_grid.set_halign (Align.CENTER);
content_grid.set_row_spacing (8);
box.add (content_grid);
update_content ();
source_list_changed_id = eds_source_list.changed.connect ( () => {
update_content ();
});
grid.show_all ();
}
public override void destroy () {
if (source_list_changed_id != 0) {
eds_source_list.disconnect (source_list_changed_id);
source_list_changed_id = 0;
}
base.destroy ();
}
public override bool window_state_event (Gdk.EventWindowState e) {
base.window_state_event (e);
if ((e.new_window_state & Gdk.WindowState.MAXIMIZED) != 0)
title_label.show ();
else
title_label.hide ();
return false;
}
}
|