~ubuntu-branches/ubuntu/wily/sflphone/wily

« back to all changes in this revision

Viewing changes to gnome/src/seekslider.c

  • Committer: Package Import Robot
  • Author(s): Mark Purcell
  • Date: 2014-01-28 18:23:36 UTC
  • mfrom: (1.1.11)
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: package-import@ubuntu.com-20140128182336-3xenud1kbnwmf3mz
* New upstream release 
  - Fixes "New Upstream Release" (Closes: #735846)
  - Fixes "Ringtone does not stop" (Closes: #727164)
  - Fixes "[sflphone-kde] crash on startup" (Closes: #718178)
  - Fixes "sflphone GUI crashes when call is hung up" (Closes: #736583)
* Build-Depends: ensure GnuTLS 2.6
  - libucommon-dev (>= 6.0.7-1.1), libccrtp-dev (>= 2.0.6-3)
  - Fixes "FTBFS Build-Depends libgnutls{26,28}-dev" (Closes: #722040)
* Fix "boost 1.49 is going away" unversioned Build-Depends: (Closes: #736746)
* Add Build-Depends: libsndfile-dev, nepomuk-core-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 *  Copyright (C) 2012 Savoir-Faire Linux Inc.
 
2
 *  Copyright (C) 2012-2013 Savoir-Faire Linux Inc.
3
3
 *
4
4
 *  This program is free software; you can redistribute it and/or modify
5
5
 *  it under the terms of the GNU General Public License as published by
36
36
#include <string.h>
37
37
#include "seekslider.h"
38
38
#include "dbus.h"
39
 
#include "calltab.h"
40
39
 
41
40
/**
42
41
 * SECTION:sfl-seekslider
89
88
    gboolean is_dragging;
90
89
    gboolean can_update_scale;
91
90
    gboolean is_playing;
 
91
    gchar *file_path;
92
92
};
93
93
 
94
94
enum
95
95
{
96
96
    PROP_0,
 
97
    PROP_FILE_PATH,
 
98
    N_PROPERTIES
97
99
};
98
100
 
 
101
static GParamSpec *obj_properties[N_PROPERTIES] = { NULL, };
 
102
 
99
103
G_DEFINE_TYPE(SFLSeekSlider, sfl_seekslider, GTK_TYPE_HBOX)
100
104
 
101
105
static void
108
112
    object_class->set_property = sfl_seekslider_set_property;
109
113
    object_class->get_property = sfl_seekslider_get_property;
110
114
 
 
115
    obj_properties[PROP_FILE_PATH] = g_param_spec_string("file-path", "File path",
 
116
            "Set file path for playback", "" /* default value */, G_PARAM_READWRITE);
 
117
 
 
118
    g_object_class_install_properties(object_class, N_PROPERTIES, obj_properties);
111
119
    g_type_class_add_private(klass, sizeof(SFLSeekSliderPrivate));
112
120
}
113
121
 
186
194
    seekslider->priv->current = 0;
187
195
    seekslider->priv->size = 0;
188
196
    seekslider->priv->is_playing = FALSE;
 
197
    seekslider->priv->file_path = NULL;
189
198
}
190
199
 
191
200
static void
199
208
    seekslider = SFL_SEEKSLIDER(object);
200
209
    g_return_if_fail(seekslider->priv != NULL);
201
210
 
 
211
    /* Ensure that we've stopped playback */
 
212
    sfl_seekslider_stop_playback_record_cb(NULL, seekslider);
 
213
 
202
214
    G_OBJECT_CLASS(sfl_seekslider_parent_class)->finalize(object);
203
215
}
204
216
 
206
218
static void
207
219
sfl_seekslider_set_property (GObject *object, guint prop_id, const GValue *value G_GNUC_UNUSED, GParamSpec *pspec)
208
220
{
209
 
    G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
 
221
    SFLSeekSlider *self = SFL_SEEKSLIDER(object);
 
222
 
 
223
    switch (prop_id)
 
224
    {
 
225
        case PROP_FILE_PATH:
 
226
            /* no change */
 
227
            if (g_strcmp0(self->priv->file_path, g_value_get_string(value)) == 0)
 
228
                break;
 
229
 
 
230
            /* cache is_playing as it will be modified */
 
231
            const gboolean resume_playing = self->priv->is_playing;
 
232
            if (resume_playing)
 
233
                sfl_seekslider_stop_playback_record_cb(NULL, self);
 
234
 
 
235
            g_free(self->priv->file_path);
 
236
            self->priv->file_path = g_value_dup_string(value);
 
237
            g_debug("filepath: %s\n", self->priv->file_path);
 
238
 
 
239
            if (resume_playing)
 
240
                sfl_seekslider_play_playback_record_cb(NULL, self);
 
241
            break;
 
242
 
 
243
        default:
 
244
            /* We don't have any other property... */
 
245
            G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
 
246
            break;
 
247
    }
210
248
}
211
249
 
212
250
static void
213
251
sfl_seekslider_get_property (GObject *object, guint prop_id, GValue *value G_GNUC_UNUSED, GParamSpec *pspec)
214
252
{
215
 
    G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
 
253
    SFLSeekSlider *self = SFL_SEEKSLIDER(object);
 
254
 
 
255
    switch (prop_id)
 
256
    {
 
257
        case PROP_FILE_PATH:
 
258
            g_value_set_string(value, self->priv->file_path);
 
259
            break;
 
260
 
 
261
        default:
 
262
            /* We don't have any other property... */
 
263
            G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
 
264
            break;
 
265
    }
216
266
}
217
267
 
 
268
 
218
269
/**
219
270
 * sfl_seekslider_new:
220
271
 * @shell_player: the #RBShellPlayer instance
298
349
 
299
350
static void sfl_seekslider_play_playback_record_cb (GtkButton *button G_GNUC_UNUSED, gpointer user_data)
300
351
{
301
 
    SFLSeekSlider *seekslider = SFL_SEEKSLIDER(user_data);
 
352
    SFLSeekSlider *self = SFL_SEEKSLIDER(user_data);
302
353
 
303
 
    callable_obj_t *selectedCall = calltab_get_selected_call(history_tab);
304
 
    if (selectedCall == NULL)
 
354
    if (self->priv->file_path == NULL || (*self->priv->file_path == 0))
305
355
        return;
306
356
 
307
 
    g_debug("Start selected call file playback %s", selectedCall->_recordfile);
308
 
    seekslider->priv->is_playing = selectedCall->_record_is_playing =
309
 
        dbus_start_recorded_file_playback(selectedCall->_recordfile);
 
357
    g_debug("Start file playback %s", self->priv->file_path);
 
358
    self->priv->is_playing = dbus_start_recorded_file_playback(self->priv->file_path);
310
359
 
311
 
    if (seekslider->priv->is_playing)
312
 
        sfl_seekslider_set_display(seekslider, SFL_SEEKSLIDER_DISPLAY_PAUSE);
 
360
    if (self->priv->is_playing)
 
361
        sfl_seekslider_set_display(self, SFL_SEEKSLIDER_DISPLAY_PAUSE);
313
362
}
314
363
 
315
 
static void sfl_seekslider_stop_playback_record_cb (GtkButton *button G_GNUC_UNUSED, gpointer user_data)
 
364
static void sfl_seekslider_stop_playback_record_cb(GtkButton *button G_GNUC_UNUSED, gpointer user_data)
316
365
{
317
 
    SFLSeekSlider *seekslider = SFL_SEEKSLIDER(user_data);
318
 
 
319
 
    callable_obj_t *selectedCall = calltab_get_selected_call(history_tab);
320
 
    if (selectedCall == NULL)
321
 
        return;
322
 
 
323
 
    if (selectedCall->_recordfile == NULL ||
324
 
        strlen(selectedCall->_recordfile) == 0)
325
 
        return;
326
 
 
327
 
    dbus_stop_recorded_file_playback(selectedCall->_recordfile);
328
 
    g_debug("Stop selected call file playback %s", selectedCall->_recordfile);
329
 
    seekslider->priv->is_playing = selectedCall->_record_is_playing = FALSE;
330
 
 
331
 
    sfl_seekslider_set_display(seekslider, SFL_SEEKSLIDER_DISPLAY_PLAY);
 
366
    SFLSeekSlider *self = SFL_SEEKSLIDER(user_data);
 
367
 
 
368
    if (self->priv->file_path == NULL || (*self->priv->file_path == 0))
 
369
        return;
 
370
 
 
371
    if (self->priv->is_playing) {
 
372
        dbus_stop_recorded_file_playback(self->priv->file_path);
 
373
        g_debug("Stop file playback %s", self->priv->file_path);
 
374
        self->priv->is_playing = FALSE;
 
375
    }
 
376
 
 
377
    sfl_seekslider_set_display(self, SFL_SEEKSLIDER_DISPLAY_PLAY);
332
378
}
333
379
 
334
380
void sfl_seekslider_update_timelabel(SFLSeekSlider *seekslider, guint current, guint size)
382
428
 
383
429
void sfl_seekslider_set_display(SFLSeekSlider *seekslider, SFLSeekSliderDisplay display) {
384
430
 
385
 
    if (seekslider == NULL)
 
431
    if (seekslider == NULL || !seekslider->priv ||
 
432
        !GTK_IS_WIDGET(seekslider->priv->playRecordWidget) ||
 
433
        !GTK_IS_WIDGET(seekslider->priv->stopRecordWidget))
386
434
        return;
387
435
 
388
436
    switch (display) {
408
456
    seekslider->priv->can_update_scale = FALSE;
409
457
    gtk_range_set_value(GTK_RANGE(seekslider->priv->hscale), 0.0);
410
458
    sfl_seekslider_set_display(seekslider, SFL_SEEKSLIDER_DISPLAY_PLAY);
411
 
    sfl_seekslider_stop_playback_record_cb(NULL, seekslider);
 
459
    if (seekslider->priv->is_playing)
 
460
        sfl_seekslider_stop_playback_record_cb(NULL, seekslider);
412
461
    gtk_label_set_text(GTK_LABEL(seekslider->priv->timeLabel), "");
413
462
    seekslider->priv->current = 0;
414
463
    seekslider->priv->size = 0;
415
464
    seekslider->priv->is_playing = FALSE;
416
465
    seekslider->priv->can_update_scale = TRUE;
417
466
}
 
467
 
 
468
gboolean
 
469
sfl_seekslider_has_path(SFLSeekSlider *seekslider, const gchar *file_path)
 
470
{
 
471
    return g_strcmp0(seekslider->priv->file_path, file_path) == 0;
 
472
}