Debian packaging: 0.0.4-1
[beifahrer] / src / my-info-window.vala
1 /* This file is part of Beifahrer.
2  *
3  * Copyright (C) 2010 Philipp Zabel
4  *
5  * Beifahrer is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * Beifahrer 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
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with Beifahrer. If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 using Gtk;
20 using Hildon;
21
22 public class MyInformationWindow : StackableWindow {
23         enum FieldIndex {
24                 NAME = 0,
25                 CELL = 1,
26                 PHONE = 2,
27                 EMAIL = 3,
28                 BIRTHDAY = 4,
29         }
30
31         AdacMitfahrclub adac;
32         Gtk.Label[] fields;
33
34         private async void get_information () {
35                 Hildon.gtk_window_set_progress_indicator (this, 1);
36                 bool logged_in = yield adac.login_async ();
37                 if (!logged_in) {
38                         Banner.show_information (this, null, "Login failed.");
39                         return;
40                 }
41
42                 MyInformation my_info = yield adac.get_my_information ();
43                 if (my_info != null) {
44                         fields[FieldIndex.NAME].set_label (my_info.first_name + " " + my_info.last_name);
45                         fields[FieldIndex.CELL].set_label (my_info.cell);
46                         fields[FieldIndex.PHONE].set_label (my_info.phone1);
47                         fields[FieldIndex.EMAIL].set_label (my_info.email1);
48                 }
49                 Hildon.gtk_window_set_progress_indicator (this, 0);
50         }
51
52         public MyInformationWindow (AdacMitfahrclub _adac) {
53                 adac = _adac;
54
55                 get_information.begin ();
56         }
57
58         const string[] labels = {
59                 "Name", "Cell", "Phone", "E-mail", "Birthday"
60         };
61
62         construct {
63                 set_title ("My information");
64
65                 var menu = new AppMenu ();
66                 var goto_website = new Gtk.Button.with_label (_("Show website"));
67                 goto_website.show ();
68                 menu.append (goto_website);
69                 set_main_menu (menu);
70
71                 var table = new Gtk.Table (5, 2, false);
72
73                 fields = new Gtk.Label[5];
74                 for (int i = 0; i < 5; i++) {
75                         var label = new Gtk.Label (_(labels[i]));
76                         label.set_alignment (0.0f, 0.0f);
77                         Hildon.helper_set_logical_color (label, RcFlags.FG, StateType.NORMAL, "SecondaryTextColor");
78                         table.attach (label, 0, 1, i, i+1, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
79
80                         fields[i] = new Gtk.Label ("");
81                         fields[i].set_alignment (0.0f, 0.0f);
82                         table.attach (fields[i], 1, 2, i, i+1, AttachOptions.FILL, AttachOptions.FILL, 0, 0);
83                 }
84
85                 add (table);
86                 table.show_all ();
87
88                 goto_website.clicked.connect (on_goto_website_clicked);
89         }
90
91         void on_goto_website_clicked () {
92                 BeifahrerProgram.open_browser (this, adac.get_my_information_url ());
93         }
94 }
95
96 //      Anrede
97 //      Date registered_since;
98 //      string password;
99 /*
100         // Address
101         string street; string number;
102         string PLZ; string city;
103         string land;
104
105         // Contact
106         string telefon1;
107         string telefon2;
108         string telefon3;
109         string handy;
110         string email1;
111         string email2;
112         bool smoker;
113         string occupation;
114         string familienstand;
115         string language1; // list
116         string language2;
117         string language3;
118
119         // Newsletter
120         bool newsletter;
121         bool newsletter_html;
122
123         // Kfz
124         int fahrleistung;
125         int vmax;
126         string kfz_vendor;
127         string kfz_model;
128         int year;
129         string co2;
130
131         bool adac_member;
132 */
133
134 // 1. login
135 // 2. parse https://mitfahrclub.adac.de/users/view