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