1
// -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*-
3
* Copyright (c) 2013-2014 Pantheon Chat Developers (http://launchpad.net/pantheon-chat)
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Library General Public
7
* License as published by the Free Software Foundation; either
8
* version 2 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Library General Public License for more details.
15
* You should have received a copy of the GNU Library General Public
16
* License along with this library; if not, write to the
17
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18
* Boston, MA 02111-1307, USA.
20
* Authored by: Corentin Noël <corentin@elementaryos.org>
23
public class Chat.AccountPopover : Gtk.Popover {
24
private Gtk.ListStore model;
25
private Gtk.Label name_label;
26
private Gtk.Label message_label;
27
private Gtk.Button avatar_image;
29
public AccountPopover () {
30
avatar_image = new Gtk.Button.from_icon_name ("avatar-default", Gtk.IconSize.DIALOG);
31
avatar_image.relief = Gtk.ReliefStyle.NONE;
33
name_label = new Gtk.Label ("");
34
name_label.xalign = 0;
36
message_label = new Gtk.Label ("");
37
message_label.use_markup = true;
38
message_label.xalign = 0;
40
var profile_container = new Gtk.Grid ();
41
profile_container.column_spacing = 12;
42
profile_container.row_spacing = 6;
43
profile_container.margin = 12;
44
profile_container.attach (avatar_image, 0, 0, 1, 2);
45
profile_container.attach (name_label, 1, 0, 1, 1);
46
profile_container.attach (message_label, 1, 1, 1, 1);
48
model = new Gtk.ListStore (3, typeof (Gdk.Pixbuf), typeof (string), typeof (TelepathyGLib.Account));
50
var view = new Gtk.IconView.with_model (model);
51
view.activate_on_single_click = true;
52
view.set_pixbuf_column (0);
53
view.set_tooltip_column (1);
54
view.item_activated.connect ((path) => {
57
model.get_iter (out iter, path);
59
model.get_value (iter, 2, out val);
63
var layout = new Gtk.Grid ();
64
layout.orientation = Gtk.Orientation.VERTICAL;
65
layout.add (profile_container);
66
layout.add (new Gtk.Separator (Gtk.Orientation.HORIZONTAL));
74
model.append (out iter);
75
Gdk.Pixbuf pixbuf = Gtk.IconTheme.get_default ().load_icon ("list-add-symbolic", 24, Gtk.IconLookupFlags.GENERIC_FALLBACK);
76
model.set (iter, 0, pixbuf, 1, _("Add Account…"));
84
private void load_accounts () {
85
var telepathy_manager = TelepathyManager.get_default ();
86
var accounts = telepathy_manager.get_accounts ();
87
foreach (var account in accounts) {
91
telepathy_manager.account_added.connect ((account) => {add_button (account);});
92
foreach (unowned TelepathyGLib.Contact contact in telepathy_manager.get_myself_list ()) {
93
if (contact.avatar_file != null) {
94
avatar_image.image = new Gtk.Image.from_gicon (new FileIcon (contact.avatar_file), Gtk.IconSize.DIALOG);
95
name_label.label = contact.alias;
96
message_label.label = contact.presence_message;
100
telepathy_manager.myself_changed.connect ((contact) => {
101
if (contact.avatar_file != null) {
102
avatar_image.image = new Gtk.Image.from_gicon (new FileIcon (contact.avatar_file), Gtk.IconSize.DIALOG);
103
name_label.label = contact.alias;
104
message_label.label = contact.presence_message;
109
private void add_button (TelepathyGLib.Account account) {
112
model.prepend (out iter);
113
Gdk.Pixbuf pixbuf = Gtk.IconTheme.get_default ().load_icon (account.icon_name, 24, Gtk.IconLookupFlags.GENERIC_FALLBACK);
114
model.set (iter, 0, pixbuf, 1, account.display_name, 2, account);
116
critical (e.message);
b'\\ No newline at end of file'