Add description to the previously committed patch
[debian/pino.git] / src / dm_entry.vala
1 /* dm_entry.vala
2  *
3  * Copyright (C) 2009-2010  troorl
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser 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  * This program 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 Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  *
18  * Author:
19  *      troorl <troorl@gmail.com>
20  */
21
22 using Gtk;
23 using RestAPI;
24
25 public class DmEntry : Entry {
26         
27         private RestAPIRe api;
28
29         private bool _can_send = false;
30         public bool can_send {
31                 get { return _can_send; }
32         }
33         
34         public string warning_text {
35                 get { return _("You can't send direct message to this user. He (or she) must follow you too"); }
36         }
37         
38         public DmEntry(RestAPIRe _api) {
39                 api = _api;
40                 
41                 set_icon_from_stock(EntryIconPosition.SECONDARY, "gtk-dialog-warning");
42                 set_icon_tooltip_text(EntryIconPosition.SECONDARY, _("Check"));
43                 icon_press.connect((pos, event) => {
44                         if(event.button.button == 1)
45                                 check();
46                 });
47                 set_size_request(150, -1);
48         }
49         
50         private void set_warning() {
51                 set_icon_from_stock(EntryIconPosition.SECONDARY, "gtk-dialog-warning");
52                 set_tooltip_text(warning_text);
53                 _can_send = false;
54         }
55         
56         private void set_ok() {
57                 set_icon_from_stock(EntryIconPosition.SECONDARY, "gtk-apply");
58                 set_tooltip_text(_("You can send direct message to this user"));
59                 _can_send = true;
60         }
61         
62         public void check() {
63                 /*if (!Thread.supported()) {
64                         error("Cannot run without threads.");
65                         return;
66                 }
67                 
68                 try {
69                         weak Thread thread_1 = Thread.create(get_friendship, false);
70                         thread_1.join();
71                 } catch(ThreadError e) {
72                         warning("Error: %s", e.message);
73                         return;
74         }*/
75         
76         set_icon_from_stock(EntryIconPosition.SECONDARY, "gtk-refresh");
77                 set_tooltip_text(_("Checking..."));
78                 
79                 bool answer = false;
80                 
81                 try {
82                         answer = api.check_friendship(text);
83                 } catch(RestError e) {
84                         set_warning();
85                         return;
86                 } catch(ParseError e) {
87                         set_warning();
88                         return;
89                 }
90                 
91                 if(answer) {
92                         set_ok();
93                 } else {
94                         set_warning();
95                 }
96         }
97         
98         /*
99         private void* get_friendship() {
100                 set_icon_from_stock(EntryIconPosition.SECONDARY, "gtk-refresh");
101                 set_tooltip_text(_("Checking..."));
102                 
103                 bool answer = false;
104                 
105                 try {
106                         answer = api.check_friendship(text);
107                 } catch(RestError e) {
108                         set_warning();
109                         return null;
110                 }
111                 
112                 if(answer) {
113                         set_ok();
114                 } else {
115                         set_warning();
116                 }
117                 
118                 return null;
119         }
120         */
121 }