]> sjero.net Git - linphone/blob - gtk/calllogs.c
9e703a8ffd6615e65020e35cc99a2ac2e7bf5bea
[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=linphone_call_log_get_dir(cl)==LinphoneCallIncoming ? linphone_call_log_get_from(cl) : linphone_call_log_get_to(cl);
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                 int duration=linphone_call_log_get_duration(cl);
62                 time_t start_date_time=linphone_call_log_get_start_date(cl);
63                 
64 #if GLIB_CHECK_VERSION(2,26,0)
65                 if (start_date_time){
66                         GDateTime *dt=g_date_time_new_from_unix_local(start_date_time);
67                         start_date=g_date_time_format(dt,"%c");
68                         g_date_time_unref(dt);
69                 }
70 #else
71                 start_date=g_strdup(ctime(&start_date_time));
72 #endif
73                 
74                 display=linphone_address_get_display_name (la);
75                 if (display==NULL){
76                         display=linphone_address_get_username (la);
77                         if (display==NULL)
78                                 display=linphone_address_get_domain (la);
79                 }
80                 if (linphone_call_log_get_quality(cl)!=-1){
81                         snprintf(quality,sizeof(quality),"%.1f",linphone_call_log_get_quality(cl));
82                 }else snprintf(quality,sizeof(quality)-1,"%s",_("n/a"));
83                 switch(linphone_call_log_get_status(cl)){
84                         case LinphoneCallAborted:
85                                 status=_("Aborted");
86                         break;
87                         case LinphoneCallMissed:
88                                 status=_("Missed");
89                         break;
90                         case LinphoneCallDeclined:
91                                 status=_("Declined");
92                         break;
93                         default:
94                         break;
95                 }
96                 minutes=g_markup_printf_escaped(
97                         ngettext("%i minute", "%i minutes", duration/60),
98                         duration/60);
99                 seconds=g_markup_printf_escaped(
100                         ngettext("%i second", "%i seconds", duration%60),
101                         duration%60);
102                 if (status==NULL) logtxt=g_markup_printf_escaped(
103                                 _("<big><b>%s</b></big>\t<small><i>%s</i>\t"
104                                         "<i>Quality: %s</i></small>\n%s\t%s %s\t"),
105                                 display, addr, quality ,
106                                 start_date ? start_date : "", minutes, seconds);
107                 else logtxt=g_markup_printf_escaped(
108                                 _("<big><b>%s</b></big>\t<small><i>%s</i></small>\t"
109                                         "\n%s\t%s"),
110                                 display, addr,
111                                 start_date ? start_date : "", status);
112                 g_free(minutes);
113                 g_free(seconds);
114                 if (start_date) g_free(start_date);
115                 gtk_list_store_append (store,&iter);
116
117                 GdkPixbuf *incoming = create_pixbuf("call_status_incoming.png");
118                 GdkPixbuf *outgoing = create_pixbuf("call_status_outgoing.png");
119                 gtk_list_store_set (store,&iter,
120                                0, linphone_call_log_get_dir(cl)==LinphoneCallOutgoing ? outgoing : incoming,
121                                1, logtxt,2,la,-1);
122                 ms_free(addr);
123                 g_free(logtxt);
124         }
125         
126 }
127
128 static bool_t put_selection_to_uribar(GtkWidget *treeview){
129         GtkTreeSelection *sel;
130
131         sel=gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
132         if (sel!=NULL){
133                 GtkTreeModel *model=NULL;
134                 GtkTreeIter iter;
135                 if (gtk_tree_selection_get_selected (sel,&model,&iter)){
136                         gpointer pla;
137                         LinphoneAddress *la;
138                         char *tmp;
139                         gtk_tree_model_get(model,&iter,2,&pla,-1);
140                         la=(LinphoneAddress*)pla;
141                         tmp=linphone_address_as_string (la);
142                         gtk_entry_set_text(GTK_ENTRY(linphone_gtk_get_widget(linphone_gtk_get_main_window(),"uribar")),tmp);
143                         ms_free(tmp);
144                         return TRUE;
145                 }
146         }
147         return FALSE;
148 }
149
150 void linphone_gtk_history_row_activated(GtkWidget *treeview){
151         if (put_selection_to_uribar(treeview)){
152                 GtkWidget *mw=linphone_gtk_get_main_window();
153                 linphone_gtk_start_call(linphone_gtk_get_widget(mw,"start_call"));
154         }
155 }
156
157 void linphone_gtk_history_row_selected(GtkWidget *treeview){
158         put_selection_to_uribar(treeview);
159 }
160
161 void linphone_gtk_clear_call_logs(GtkWidget *button){
162         linphone_core_clear_call_logs (linphone_gtk_get_core());
163         linphone_gtk_call_log_update(gtk_widget_get_toplevel(button));
164 }
165
166 void linphone_gtk_call_log_callback(GtkWidget *button){
167         GtkWidget *mw=linphone_gtk_get_main_window();
168         if (put_selection_to_uribar(linphone_gtk_get_widget(mw,"logs_view")))
169                         linphone_gtk_start_call(linphone_gtk_get_widget(mw,"start_call"));
170 }
171
172 void linphone_gtk_call_log_response(GtkWidget *w, guint response_id){
173         GtkWidget *mw=linphone_gtk_get_main_window();
174         if (response_id==1){
175                 if (put_selection_to_uribar(linphone_gtk_get_widget(w,"logs_view")))
176                         linphone_gtk_start_call(linphone_gtk_get_widget(mw,"start_call"));
177         }else if (response_id==2){
178                 linphone_core_clear_call_logs (linphone_gtk_get_core());
179                 linphone_gtk_call_log_update(w);
180                 return;
181         }
182         g_object_set_data(G_OBJECT(mw),"call_logs",NULL);
183         gtk_widget_destroy(w);
184 }
185
186
187
188 GtkWidget * linphone_gtk_show_call_logs(void){
189         GtkWidget *mw=linphone_gtk_get_main_window();
190
191         GtkWidget *w=(GtkWidget*)g_object_get_data(G_OBJECT(linphone_gtk_get_main_window()),"call_logs");
192         if (w==NULL){
193                 w=linphone_gtk_create_window("call_logs");
194 //              gtk_button_set_image(GTK_BUTTON(linphone_gtk_get_widget(w,"call_back_button")),
195 //                                   create_pixmap (linphone_gtk_get_ui_config("callback_button","status-green.png")));
196                 g_object_set_data(G_OBJECT(mw),"call_logs",w);
197                 g_signal_connect(G_OBJECT(w),"response",(GCallback)linphone_gtk_call_log_response,NULL);
198                 gtk_widget_show(w);
199                 linphone_gtk_call_log_update(w);
200         }else gtk_window_present(GTK_WINDOW(w));
201         return w;
202 }
203