32
32
#include <codeclist.h>
33
33
#include <sflphone_const.h>
35
#include "contacts/calltree.h"
36
39
#define UNIX_DAY 86400
37
40
#define UNIX_WEEK 86400 * 6
38
#define UNIX_TWO_DAYS 86400 * 2
41
#define UNIX_TWO_DAYS 86400 * 2
40
gint is_callID_callstruct ( gconstpointer a, gconstpointer b)
43
gint is_callID_callstruct (gconstpointer a, gconstpointer b)
42
callable_obj_t * c = (callable_obj_t*)a;
43
if(g_strcasecmp(c->_callID, (const gchar*) b) == 0)
45
callable_obj_t * c = (callable_obj_t*) a;
47
if (g_strcasecmp (c->_callID, (const gchar*) b) == 0) {
53
gint get_state_callstruct ( gconstpointer a, gconstpointer b)
54
gint get_state_callstruct (gconstpointer a, gconstpointer b)
55
callable_obj_t * c = (callable_obj_t*)a;
56
if( c->_state == *((call_state_t*)b))
56
callable_obj_t * c = (callable_obj_t*) a;
58
if (c->_state == * ( (call_state_t*) b)) {
75
74
return g_strndup (format, 0);
78
return g_strndup(name, end - name);
77
return g_strndup (name, end - name);
82
81
gchar* call_get_peer_number (const gchar *format)
84
DEBUG(" callable_obj: %s", format);
86
gchar * number = g_strrstr(format, "<") + 1;
87
gchar * end = g_strrstr(format, ">");
90
number = g_strndup(number, end - number );
83
DEBUG (" callable_obj: %s", format);
85
gchar * number = g_strrstr (format, "<") + 1;
86
gchar * end = g_strrstr (format, ">");
89
number = g_strndup (number, end - number);
92
number = g_strdup(format);
91
number = g_strdup (format);
97
96
gchar* call_get_audio_codec (callable_obj_t *obj)
99
gchar *audio_codec = "";
106
audio_codec = dbus_get_current_codec_name (obj);
107
codec = codec_list_get_by_name (audio_codec, NULL);
109
samplerate = codec->sample_rate;
110
format = g_markup_printf_escaped ("%s/%i", audio_codec, samplerate);
98
gchar *audio_codec = "";
104
audio_codec = dbus_get_current_codec_name (obj);
105
codec = codec_list_get_by_name (audio_codec, NULL);
108
samplerate = codec->sample_rate;
109
format = g_markup_printf_escaped ("%s/%i", audio_codec, samplerate);
116
void call_add_error(callable_obj_t * call, gpointer dialog)
116
void call_add_error (callable_obj_t * call, gpointer dialog)
118
118
g_ptr_array_add (call->_error_dialogs, dialog);
121
void call_remove_error(callable_obj_t * call, gpointer dialog)
121
void call_remove_error (callable_obj_t * call, gpointer dialog)
123
123
g_ptr_array_remove (call->_error_dialogs, dialog);
126
void call_remove_all_errors(callable_obj_t * call)
126
void call_remove_all_errors (callable_obj_t * call)
128
128
g_ptr_array_foreach (call->_error_dialogs, (GFunc) gtk_widget_destroy, NULL);
131
void threaded_clock_incrementer (void *pc)
134
callable_obj_t *call = (callable_obj_t *) pc;
137
while (call->clockStarted) {
140
time_t start, current;
142
gdk_threads_enter ();
144
set_timestamp (& (call->_time_current));
146
start = call->_time_start;
147
current = call->_time_current;
149
if (current == start) {
150
g_snprintf (call->_timestr, 20, "00:00");
154
duration = (int) difftime (current, start);
156
if (duration / 60 == 0) {
158
g_snprintf (call->_timestr, 20, "00:0%d", duration);
160
g_snprintf (call->_timestr, 20, "00:%d", duration);
163
if (duration%60 < 10) {
164
g_snprintf (call->_timestr, 20, "0%d:0%d", duration/60, duration%60);
166
g_snprintf (call->_timestr, 20, "%d:%d", duration/60, duration%60);
170
// Update clock only if call is active (current, hold, recording transfer)
171
if ( (call->_state != CALL_STATE_INVALID) &&
172
(call->_state != CALL_STATE_INCOMING) &&
173
(call->_state != CALL_STATE_RINGING) &&
174
(call->_state != CALL_STATE_DIALING) &&
175
(call->_state != CALL_STATE_FAILURE) &&
176
(call->_state != CALL_STATE_BUSY)) {
177
calltree_update_clock();
181
gdk_threads_leave ();
188
DEBUG ("CallableObj: Stopping Thread");
190
g_thread_exit (NULL);
194
void stop_call_clock (callable_obj_t *c)
197
DEBUG ("CallableObj: Stop call clock");
200
ERROR ("CallableObj: Callable object is NULL");
204
if (c->_type == CALL && c->clockStarted) {
206
/// no need to join here, only need to call g_thread_exit at the end of the threaded function
207
// g_thread_join (c->tid);
131
211
void create_new_call (callable_type_t type, call_state_t state, gchar* callID , gchar* accountID, gchar* peer_name, gchar* peer_number, callable_obj_t ** new_call)
214
GError *err1 = NULL ;
134
215
callable_obj_t *obj;
218
DEBUG ("CallableObj: Create new call");
220
DEBUG ("Account: %s", accountID);
137
222
// Allocate memory
138
223
obj = g_new0 (callable_obj_t, 1);
150
235
obj->_peer_info = g_strdup (get_peer_info (peer_name, peer_number));
152
237
obj->_trsft_to = "";
153
set_timestamp (&(obj->_time_start));
154
set_timestamp (&(obj->_time_stop));
238
set_timestamp (& (obj->_time_start));
239
set_timestamp (& (obj->_time_current));
240
set_timestamp (& (obj->_time_stop));
241
// g_snprintf(obj->_timestr, 20, "00:00");
156
243
if (g_strcasecmp (callID, "") == 0)
157
244
call_id = generate_call_id ();
159
246
call_id = callID;
161
249
obj->_callID = g_strdup (call_id);
162
250
obj->_confID = NULL;
252
obj->clockStarted = 1;
254
if (obj->_type == CALL) {
255
// pthread_create(&(obj->tid), NULL, threaded_clock_incrementer, obj);
256
if ( (obj->tid = g_thread_create ( (GThreadFunc) threaded_clock_incrementer, (void *) obj, TRUE, &err1)) == NULL) {
257
DEBUG ("Thread creation failed!");
258
g_error_free (err1) ;
309
417
start = obj->_time_start;
310
418
end = obj->_time_stop;
312
420
if (start == end)
313
return g_markup_printf_escaped("<small>Duration:</small> 0:00");
315
duration = (int) difftime(end, start);
317
if( duration / 60 == 0 )
320
res = g_markup_printf_escaped("00:0%i", duration);
322
res = g_markup_printf_escaped("00:%i", duration);
326
if( duration%60 < 10 )
327
res = g_markup_printf_escaped("%i:0%i" , duration/60 , duration%60);
329
res = g_markup_printf_escaped("%i:%i" , duration/60 , duration%60);
331
return g_markup_printf_escaped("<small>Duration:</small> %s", res);
421
return g_markup_printf_escaped ("<small>Duration:</small> 0:00");
423
duration = (int) difftime (end, start);
425
if (duration / 60 == 0) {
427
res = g_markup_printf_escaped ("00:0%i", duration);
429
res = g_markup_printf_escaped ("00:%i", duration);
431
if (duration%60 < 10)
432
res = g_markup_printf_escaped ("%i:0%i" , duration/60 , duration%60);
434
res = g_markup_printf_escaped ("%i:%i" , duration/60 , duration%60);
437
return g_markup_printf_escaped ("<small>Duration:</small> %s", res);
335
441
gchar* serialize_history_entry (callable_obj_t *entry)
337
443
// "0|514-276-5468|Savoir-faire Linux|144562458" for instance
340
446
gchar* separator = "|";
341
447
gchar* history_state, *timestamp;
345
451
// and the timestamps
346
452
timestamp = convert_timestamp_to_gchar (entry->_time_stop);
348
result = g_strconcat (history_state, separator,
349
entry->_peer_number, separator,
350
g_strcasecmp (entry->_peer_name,"") ==0 ? "empty": entry->_peer_name, separator,
351
timestamp, separator,
352
g_strcasecmp (entry->_accountID,"") ==0 ? "empty": entry->_accountID,
454
gchar* peer_name = (entry->_peer_name == NULL || g_strcasecmp (entry->_peer_name,"") == 0) ? "empty": entry->_peer_name;
455
gchar* account_id = (entry->_accountID == NULL || g_strcasecmp (entry->_accountID,"") == 0) ? "empty": entry->_accountID;
457
result = g_strconcat (history_state, separator,
458
entry->_peer_number, separator,
459
peer_name, separator,
460
timestamp, separator,
358
467
gchar* get_history_id_from_state (history_state_t state)
360
469
// Refer to history_state_t enum in callable_obj.h
374
gchar* get_formatted_start_timestamp (callable_obj_t *obj) {
482
gchar* get_formatted_start_timestamp (callable_obj_t *obj)
378
487
unsigned char str[100];
382
// Fetch the current timestamp
490
// Fetch the current timestamp
384
492
lt = obj->_time_start;
386
494
ptr = localtime (<);
388
if (now - lt < UNIX_WEEK) {
389
if (now-lt < UNIX_DAY) {
390
strftime((char *)str, 100, N_("today at %R"), (const struct tm *)ptr);
392
if (now - lt < UNIX_TWO_DAYS) {
393
strftime((char *)str, 100, N_("yesterday at %R"), (const struct tm *)ptr);
395
strftime((char *)str, 100, N_("%A at %R"), (const struct tm *)ptr);
399
strftime((char *)str, 100, N_("%x at %R"), (const struct tm *)ptr);
496
if (now - lt < UNIX_WEEK) {
497
if (now-lt < UNIX_DAY) {
498
strftime ( (char *) str, 100, N_ ("today at %R"), (const struct tm *) ptr);
500
if (now - lt < UNIX_TWO_DAYS) {
501
strftime ( (char *) str, 100, N_ ("yesterday at %R"), (const struct tm *) ptr);
503
strftime ( (char *) str, 100, N_ ("%A at %R"), (const struct tm *) ptr);
507
strftime ( (char *) str, 100, N_ ("%x at %R"), (const struct tm *) ptr);
402
510
// result function of the current locale
403
return g_markup_printf_escaped("\n%s\n" , str);
511
return g_markup_printf_escaped ("\n%s\n" , str);