]> sjero.net Git - linphone/blob - gtk/calllogs.c
20ff8181ff273b39bcffb5ed851a5430c96ac87b
[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=gtk_cell_renderer_pixbuf_new ();
26
27         c=gtk_tree_view_column_new_with_attributes("icon",r,"pixbuf",0,NULL);
28         gtk_tree_view_append_column (v,c);
29
30         r=gtk_cell_renderer_text_new ();
31         c=gtk_tree_view_column_new_with_attributes("sipaddress",r,"markup",1,NULL);
32         gtk_tree_view_append_column (v,c);
33 }
34
35 void linphone_gtk_call_log_update(GtkWidget *w){
36         GtkTreeView *v=GTK_TREE_VIEW(linphone_gtk_get_widget(w,"logs_view"));
37         GtkListStore *store;
38         const MSList *logs;
39
40         store=(GtkListStore*)gtk_tree_view_get_model(v);
41         if (store==NULL){
42                 store=gtk_list_store_new(3,GDK_TYPE_PIXBUF,G_TYPE_STRING,G_TYPE_POINTER);
43                 gtk_tree_view_set_model(v,GTK_TREE_MODEL(store));
44                 g_object_unref(G_OBJECT(store));
45                 fill_renderers(GTK_TREE_VIEW(linphone_gtk_get_widget(w,"logs_view")));
46 //              gtk_button_set_image(GTK_BUTTON(linphone_gtk_get_widget(w,"call_back_button")),
47 //                                   create_pixmap (linphone_gtk_get_ui_config("callback_button","status-green.png")));
48         }
49         gtk_list_store_clear (store);
50
51         for (logs=linphone_core_get_call_logs(linphone_gtk_get_core());logs!=NULL;logs=logs->next){
52                 LinphoneCallLog *cl=(LinphoneCallLog*)logs->data;
53                 GtkTreeIter iter;
54                 LinphoneAddress *la=cl->dir==LinphoneCallIncoming ? cl->from : cl->to;
55                 char *addr= linphone_address_as_string_uri_only (la);
56                 const char *display;
57                 gchar *logtxt, *minutes, *seconds;
58                 gchar quality[20];
59                 const char *status=NULL;
60                 gchar *start_date=NULL;
61                 
62 #if GLIB_CHECK_VERSION(2,26,0)
63                 if (cl->start_date_time){
64                         GDateTime *dt=g_date_time_new_from_unix_local(cl->start_date_time);
65                         start_date=g_date_time_format(dt,"%c");
66                         g_date_time_unref(dt);
67                 }
68 #endif
69                 
70                 display=linphone_address_get_display_name (la);
71                 if (display==NULL){
72                         display=linphone_address_get_username (la);
73                         if (display==NULL)
74                                 display=linphone_address_get_domain (la);
75                 }
76                 if (cl->quality!=-1){
77                         snprintf(quality,sizeof(quality),"%.1f",cl->quality);
78                 }
79                 switch(cl->status){
80                         case LinphoneCallAborted:
81                                 status=_("Aborted");
82                         break;
83                         case LinphoneCallMissed:
84                                 status=_("Missed");
85                         break;
86                         case LinphoneCallDeclined:
87                                 status=_("Declined");
88                         break;
89                         default:
90                         break;
91                 }
92                 minutes=g_markup_printf_escaped(
93                         ngettext("%i minute", "%i minutes", cl->duration/60),
94                         cl->duration/60);
95                 seconds=g_markup_printf_escaped(
96                         ngettext("%i second", "%i seconds", cl->duration%60),
97                         cl->duration%60);
98                 if (status==NULL) logtxt=g_markup_printf_escaped(
99                                 _("<big><b>%s</b></big>\t<small><i>%s</i>\t"
100                                         "<i>Quality: %s</i></small>\n%s\t%s %s\t"),
101                                 display, addr, cl->quality!=-1 ? quality : _("n/a"),
102                                 start_date ? start_date : cl->start_date, minutes, seconds);
103                 else logtxt=g_markup_printf_escaped(
104                                 _("<big><b>%s</b></big>\t<small><i>%s</i></small>\t"
105                                         "\n%s\t%s"),
106                                 display, addr,
107                                 start_date ? start_date : cl->start_date, status);
108                 g_free(minutes);
109                 g_free(seconds);
110                 if (start_date) g_free(start_date);
111                 gtk_list_store_append (store,&iter);
112
113                 GdkPixbuf *incoming = create_pixbuf("call_status_incoming.png");
114                 GdkPixbuf *outgoing = create_pixbuf("call_status_outgoing.png");
115                 gtk_list_store_set (store,&iter,
116                                0, cl->dir==LinphoneCallOutgoing ? outgoing : incoming,
117                                1, logtxt,2,la,-1);
118                 ms_free(addr);
119                 g_free(logtxt);
120         }
121         
122 }
123
124 static bool_t put_selection_to_uribar(GtkWidget *treeview){
125         GtkTreeSelection *sel;
126
127         sel=gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
128         if (sel!=NULL){
129                 GtkTreeModel *model=NULL;
130                 GtkTreeIter iter;
131                 if (gtk_tree_selection_get_selected (sel,&model,&iter)){
132                         gpointer pla;
133                         LinphoneAddress *la;
134                         char *tmp;
135                         gtk_tree_model_get(model,&iter,2,&pla,-1);
136                         la=(LinphoneAddress*)pla;
137                         tmp=linphone_address_as_string (la);
138                         gtk_entry_set_text(GTK_ENTRY(linphone_gtk_get_widget(linphone_gtk_get_main_window(),"uribar")),tmp);
139                         ms_free(tmp);
140                         return TRUE;
141                 }
142         }
143         return FALSE;
144 }
145
146 void linphone_gtk_history_row_activated(GtkWidget *treeview){
147         if (put_selection_to_uribar(treeview)){
148                 GtkWidget *mw=linphone_gtk_get_main_window();
149                 linphone_gtk_start_call(linphone_gtk_get_widget(mw,"start_call"));
150         }
151 }
152
153 void linphone_gtk_history_row_selected(GtkWidget *treeview){
154         put_selection_to_uribar(treeview);
155 }
156
157 void linphone_gtk_clear_call_logs(GtkWidget *button){
158         linphone_core_clear_call_logs (linphone_gtk_get_core());
159         linphone_gtk_call_log_update(gtk_widget_get_toplevel(button));
160 }
161
162 void linphone_gtk_call_log_callback(GtkWidget *button){
163         GtkWidget *mw=linphone_gtk_get_main_window();
164         if (put_selection_to_uribar(linphone_gtk_get_widget(mw,"logs_view")))
165                         linphone_gtk_start_call(linphone_gtk_get_widget(mw,"start_call"));
166 }
167
168 void linphone_gtk_call_log_response(GtkWidget *w, guint response_id){
169         GtkWidget *mw=linphone_gtk_get_main_window();
170         if (response_id==1){
171                 if (put_selection_to_uribar(linphone_gtk_get_widget(w,"logs_view")))
172                         linphone_gtk_start_call(linphone_gtk_get_widget(mw,"start_call"));
173         }else if (response_id==2){
174                 linphone_core_clear_call_logs (linphone_gtk_get_core());
175                 linphone_gtk_call_log_update(w);
176                 return;
177         }
178         g_object_set_data(G_OBJECT(mw),"call_logs",NULL);
179         gtk_widget_destroy(w);
180 }
181
182
183
184 GtkWidget * linphone_gtk_show_call_logs(void){
185         GtkWidget *mw=linphone_gtk_get_main_window();
186
187         GtkWidget *w=(GtkWidget*)g_object_get_data(G_OBJECT(linphone_gtk_get_main_window()),"call_logs");
188         if (w==NULL){
189                 w=linphone_gtk_create_window("call_logs");
190 //              gtk_button_set_image(GTK_BUTTON(linphone_gtk_get_widget(w,"call_back_button")),
191 //                                   create_pixmap (linphone_gtk_get_ui_config("callback_button","status-green.png")));
192                 g_object_set_data(G_OBJECT(mw),"call_logs",w);
193                 g_signal_connect(G_OBJECT(w),"response",(GCallback)linphone_gtk_call_log_response,NULL);
194                 gtk_widget_show(w);
195                 linphone_gtk_call_log_update(w);
196         }else gtk_window_present(GTK_WINDOW(w));
197         return w;
198 }
199