]> sjero.net Git - linphone/blob - gtk/calllogs.c
Expand row in calllog
[linphone] / gtk / calllogs.c
1 /*
2 linphone, gtk-glade interface.
3 Copyright (C) 2008  Simon MORLAT (simon.morlat@linphone.org)
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (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 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 */
19
20 #include "linphone.h"
21
22
23 static void fill_renderers(GtkTreeView *v){
24         GtkTreeViewColumn *c;
25         GtkCellRenderer *r;
26         r=gtk_cell_renderer_pixbuf_new();
27
28         c=gtk_tree_view_column_new_with_attributes("icon",r,"pixbuf",0,NULL);
29         gtk_tree_view_append_column (v,c);
30
31         r=gtk_cell_renderer_text_new ();
32         c=gtk_tree_view_column_new_with_attributes("sipaddress",r,"markup",1,NULL);
33         gtk_tree_view_append_column (v,c);
34 }
35
36 void linphone_gtk_call_log_update(GtkWidget *w){
37         GtkTreeView *v=GTK_TREE_VIEW(linphone_gtk_get_widget(w,"logs_view"));
38         GtkTreeStore *store;
39         const MSList *logs;
40
41         store=(GtkTreeStore*)gtk_tree_view_get_model(v);
42         if (store==NULL){
43                 store=gtk_tree_store_new(3,GDK_TYPE_PIXBUF,G_TYPE_STRING,G_TYPE_POINTER);
44                 gtk_tree_view_set_model(v,GTK_TREE_MODEL(store));
45                 g_object_unref(G_OBJECT(store));
46                 fill_renderers(GTK_TREE_VIEW(linphone_gtk_get_widget(w,"logs_view")));
47 //              gtk_button_set_image(GTK_BUTTON(linphone_gtk_get_widget(w,"call_back_button")),
48 //                                   create_pixmap (linphone_gtk_get_ui_config("callback_button","status-green.png")));
49         }
50         gtk_tree_store_clear (store);
51
52         for (logs=linphone_core_get_call_logs(linphone_gtk_get_core());logs!=NULL;logs=logs->next){
53                 LinphoneCallLog *cl=(LinphoneCallLog*)logs->data;
54                 GtkTreeIter iter, iter2;
55                 LinphoneAddress *la=linphone_call_log_get_dir(cl)==LinphoneCallIncoming ? linphone_call_log_get_from(cl) : linphone_call_log_get_to(cl);
56                 char *addr= linphone_address_as_string_uri_only (la);
57                 const char *display;
58                 gchar *logtxt, *headtxt, *minutes, *seconds;
59                 gchar quality[20];
60                 const char *status=NULL;
61                 gchar *start_date=NULL;
62                 int duration=linphone_call_log_get_duration(cl);
63                 time_t start_date_time=linphone_call_log_get_start_date(cl);
64                 
65 #if GLIB_CHECK_VERSION(2,26,0)
66                 if (start_date_time){
67                         GDateTime *dt=g_date_time_new_from_unix_local(start_date_time);
68                         start_date=g_date_time_format(dt,"%c");
69                         g_date_time_unref(dt);
70                 }
71 #else
72                 start_date=g_strdup(ctime(&start_date_time));
73 #endif
74                 
75                 display=linphone_address_get_display_name (la);
76                 if (display==NULL){
77                         display=linphone_address_get_username (la);
78                         if (display==NULL)
79                                 display=linphone_address_get_domain (la);
80                 }
81                 if (linphone_call_log_get_quality(cl)!=-1){
82                         snprintf(quality,sizeof(quality),"%.1f",linphone_call_log_get_quality(cl));
83                 }else snprintf(quality,sizeof(quality)-1,"%s",_("n/a"));
84                 switch(linphone_call_log_get_status(cl)){
85                         case LinphoneCallAborted:
86                                 status=_("Aborted");
87                         break;
88                         case LinphoneCallMissed:
89                                 status=_("Missed");
90                         break;
91                         case LinphoneCallDeclined:
92                                 status=_("Declined");
93                         break;
94                         default:
95                         break;
96                 }
97                 minutes=g_markup_printf_escaped(
98                         ngettext("%i minute", "%i minutes", duration/60),
99                         duration/60);
100                 seconds=g_markup_printf_escaped(
101                         ngettext("%i second", "%i seconds", duration%60),
102                         duration%60);
103                 if (status==NULL) {
104                                 headtxt=g_markup_printf_escaped(_("<big><b>%s</b></big>\t%s"),display,start_date ? start_date : "");
105                                 logtxt=g_markup_printf_escaped(
106                                 _("<small><i>%s</i>\t" 
107                                   "<i>Quality: %s</i></small>\n%s\t%s\t"),
108                                 addr, quality, minutes, seconds);
109                 } else {
110                         headtxt=g_markup_printf_escaped(_("<big><b>%s</b></big>\t%s"),display,start_date ? start_date : "");
111                         logtxt=g_markup_printf_escaped(
112                         _("<small><i>%s</i></small>\t"
113                                 "\n%s"),addr, status);
114                 }
115                 g_free(minutes);
116                 g_free(seconds);
117                 if (start_date) g_free(start_date);
118                 gtk_tree_store_append (store,&iter,NULL);
119
120                 GdkPixbuf *incoming = create_pixbuf("call_status_incoming.png");
121                 GdkPixbuf *outgoing = create_pixbuf("call_status_outgoing.png");
122                 gtk_tree_store_set (store,&iter,
123                                0, linphone_call_log_get_dir(cl)==LinphoneCallOutgoing ? outgoing : incoming,
124                                1, headtxt,2,la,-1);     
125                 gtk_tree_store_append (store,&iter2,&iter);
126                 gtk_tree_store_set (store,&iter2,1,logtxt,2,la,-1);
127                 ms_free(addr);
128                 g_free(logtxt);
129                 g_free(headtxt);
130         }
131         
132 }
133
134 static bool_t put_selection_to_uribar(GtkWidget *treeview){
135         GtkTreeSelection *sel;
136
137         sel=gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
138         if (sel!=NULL){
139                 GtkTreeModel *model=NULL;
140                 GtkTreeIter iter;
141                 if (gtk_tree_selection_get_selected (sel,&model,&iter)){
142                         gpointer pla;
143                         LinphoneAddress *la;
144                         char *tmp;
145                         gtk_tree_model_get(model,&iter,2,&pla,-1);
146                         la=(LinphoneAddress*)pla;
147                         tmp=linphone_address_as_string (la);
148                         gtk_entry_set_text(GTK_ENTRY(linphone_gtk_get_widget(linphone_gtk_get_main_window(),"uribar")),tmp);
149                         ms_free(tmp);
150                         return TRUE;
151                 }
152         }
153         return FALSE;
154 }
155
156 void linphone_gtk_history_row_activated(GtkWidget *treeview){
157         if (put_selection_to_uribar(treeview)){
158                 GtkWidget *mw=linphone_gtk_get_main_window();
159                 linphone_gtk_start_call(linphone_gtk_get_widget(mw,"start_call"));
160         }
161 }
162
163 void linphone_gtk_history_row_selected(GtkWidget *treeview){
164         put_selection_to_uribar(treeview);
165 }
166
167 void linphone_gtk_clear_call_logs(GtkWidget *button){
168         linphone_core_clear_call_logs (linphone_gtk_get_core());
169         linphone_gtk_call_log_update(gtk_widget_get_toplevel(button));
170 }
171
172 void linphone_gtk_call_log_callback(GtkWidget *button){
173         GtkWidget *mw=linphone_gtk_get_main_window();
174         if (put_selection_to_uribar(linphone_gtk_get_widget(mw,"logs_view")))
175                         linphone_gtk_start_call(linphone_gtk_get_widget(mw,"start_call"));
176 }
177
178 void linphone_gtk_call_log_response(GtkWidget *w, guint response_id){
179         GtkWidget *mw=linphone_gtk_get_main_window();
180         if (response_id==1){
181                 if (put_selection_to_uribar(linphone_gtk_get_widget(w,"logs_view")))
182                         linphone_gtk_start_call(linphone_gtk_get_widget(mw,"start_call"));
183         }else if (response_id==2){
184                 linphone_core_clear_call_logs (linphone_gtk_get_core());
185                 linphone_gtk_call_log_update(w);
186                 return;
187         }
188         g_object_set_data(G_OBJECT(mw),"call_logs",NULL);
189         gtk_widget_destroy(w);
190 }
191
192
193
194 GtkWidget * linphone_gtk_show_call_logs(void){
195         GtkWidget *mw=linphone_gtk_get_main_window();
196
197         GtkWidget *w=(GtkWidget*)g_object_get_data(G_OBJECT(linphone_gtk_get_main_window()),"call_logs");
198         if (w==NULL){
199                 w=linphone_gtk_create_window("call_logs");
200 //              gtk_button_set_image(GTK_BUTTON(linphone_gtk_get_widget(w,"call_back_button")),
201 //                                   create_pixmap (linphone_gtk_get_ui_config("callback_button","status-green.png")));
202                 g_object_set_data(G_OBJECT(mw),"call_logs",w);
203                 g_signal_connect(G_OBJECT(w),"response",(GCallback)linphone_gtk_call_log_response,NULL);
204                 gtk_widget_show(w);
205                 linphone_gtk_call_log_update(w);
206         }else gtk_window_present(GTK_WINDOW(w));
207         return w;
208 }
209