~audio-recorder/audio-recorder/trunk

« back to all changes in this revision

Viewing changes to src/dbus-skype.c

  • Committer: Osmo Antero
  • Date: 2012-09-29 18:12:44 UTC
  • Revision ID: osmoma@gmail.com-20120929181244-gmrxd5xww9pua60a
Support new systems; Ubuntu 12.10, Fedora 18. Improved timer and VAD-modules. Better gst-pipeline.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include <dbus/dbus.h>
25
25
#include <dbus/dbus-glib.h>
26
26
 
27
 
#include "dbus-player.h"
28
 
#include "dbus-mpris2.h"
 
27
//#include "dbus-player.h"
 
28
//#include "dbus-mpris2.h"
29
29
#include "dbus-skype.h"
30
30
 
 
31
#include "rec-manager-struct.h"
 
32
 
31
33
#include "utility.h"
32
34
#include "dconf.h"
33
35
#include "log.h"
83
85
 
84
86
void *skype_monitor_thread(gpointer user_data);
85
87
 
 
88
static void skype_send_notification(gchar *msg);
 
89
 
86
90
void skype_module_init() {
87
91
    LOG_DEBUG("Init dbus-skype.c.\n");
88
92
 
129
133
        g_skype_dbus_conn = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
130
134
 
131
135
        if (!g_skype_dbus_conn) {
132
 
            LOG_ERROR("dbus_player_connect_to_dbus: Cannot connect to DBus: %s\n", 
133
 
                                                      error ? error->message : "");
 
136
            LOG_ERROR("skype_connect_to_dbus: Cannot connect to DBus: %s\n", (error ? error->message : ""));
134
137
 
135
138
            if (error)
136
139
                g_error_free(error);
378
381
 
379
382
            if (gui_msg1_sent < 2) {
380
383
                // Send message to the GUI (normally a red message label)
381
 
                dbus_player_send_notification(NULL,
382
 
                                              // Translators: The "Public API" setting refers to Skype's Options -> Public API menu.
383
 
                                              _("Access to Skype denied.\nAnswer YES to grant access to Skype.\nYou can enable/disable this in the Skype's \"Public API\" settings."));
 
384
                skype_send_notification(
 
385
  // Translators: The "Public API" setting refers to Skype's Options -> Public API menu.
 
386
  _("Access to Skype denied.\nAnswer YES to grant access to Skype.\nYou can enable/disable this in the Skype's \"Public API\" settings."));
384
387
 
385
388
                // Send only once
386
389
                gui_msg1_sent += 1;
393
396
            if (gui_msg2_sent < 2) {
394
397
                // Send message to the GUI (normally a red message label)
395
398
                // Translators: This message is shown in the GUI. A red label.
396
 
                dbus_player_send_notification(NULL, _("Skype is offline. Cannot connect to Skype unless you login."));
 
399
                skype_send_notification(_("Skype is offline. Cannot connect to Skype unless you login."));
397
400
 
398
401
                // Send only once
399
402
                gui_msg2_sent += 1;
442
445
            // Got a sensible answer.
443
446
 
444
447
            // Reset the GUI/error label
445
 
            dbus_player_send_notification(NULL, NULL);
 
448
            skype_send_notification(NULL);
446
449
 
447
450
            // Settle PROTOCOL. Strictly, we should test the return value from skype_settle_protocol.
448
451
            skype_settle_protocol();
463
466
    return 0;
464
467
}
465
468
 
466
 
void skype_get_app_name(MediaPlayerRec *player) {
467
 
    // Set application name.
 
469
gchar *skype_get_app_name() {
 
470
    // Return application name.
468
471
 
469
 
    // Name of Skype application.
470
 
    // Translators:  English "Skype" name is OK:
471
 
    player->app_name = g_strdup(_("Skype"));
 
472
    // Name of the Skype application.
 
473
    // Translators: English "Skype" name is OK:
 
474
    return g_strdup(_("Skype"));
472
475
}
473
476
 
474
477
void skype_get_info(gpointer player_rec) {
475
 
    MediaPlayerRec *player = (MediaPlayerRec*)player_rec;
476
 
    if (!player) return;
477
 
 
 
478
    ;
478
479
}
479
480
 
480
481
gchar *skype_send_message(gchar *command) {
912
913
 
913
914
    g_skype.paused = FALSE;
914
915
 
915
 
    // Call dbus-player and rec-manager.
916
 
    // We simply create a MediaPlayer record and send it to the dbus-player.c (it passes this further to rec-manager.c and gst-recorder.c)
917
 
 
918
 
    MediaPlayerRec *player = mpris2_player_new(NULL);
919
 
    TrackInfo *track = &player->track;
920
 
 
921
 
    // Set fields
922
 
    track->status = PLAYER_STATUS_PLAYING;
 
916
    // Send message to rec-manager.c
 
917
 
 
918
    // Create new RecorderCommand
 
919
    RecorderCommand *cmd = g_malloc0(sizeof(RecorderCommand));
 
920
    cmd->type = RECORDING_START;
923
921
 
924
922
    // Set track name
925
 
    str_copy(track->track, g_skype.filename, MPRIS_STRLEN-1);
 
923
    cmd->track = g_strndup(g_skype.filename, DEF_STR_LEN);
926
924
 
927
925
    // Set folder name as artist ;-)
928
 
    str_copy(track->artist, skype_folder, MPRIS_STRLEN-1);
 
926
    cmd->artist = g_strndup(skype_folder, DEF_STR_LEN);
929
927
 
930
928
    // Set (call) partner name as album ;-)
931
 
    str_copy(track->album, partner_name, MPRIS_STRLEN-1);
932
 
 
933
 
    /// Send to the dbus-player.c
934
 
    dbus_player_process_data(player);
935
 
 
936
 
    // Now delete this MediaPlayerRec
937
 
    dbus_player_delete_item(player);
 
929
    cmd->album = g_strndup(partner_name, DEF_STR_LEN);
 
930
    
 
931
    // We do not set these:
 
932
    // cmd->track_pos = 0
 
933
    // cmd->track_len = 0;
 
934
    // cmd->flags = 0;
 
935
 
 
936
    // Send command to rec-manager.c. 
 
937
    // It will free the cmd structure after processing.
 
938
    rec_manager_send_command(cmd);    
938
939
 
939
940
    // Free values
940
941
    g_free(skype_program);
945
946
    g_free(call_type);
946
947
    g_free(target_phone);
947
948
    g_free(skype_folder);
948
 
 
949
949
}
950
950
 
951
951
void skype_stop_recording() {
961
961
    finished_ok = status && (!g_strcmp0(status, "FINISHED"));
962
962
    g_free(status);
963
963
 
964
 
    // Call dbus-player and rec-manager.
965
 
    // We simply create a MediaPlayer record and send it to the dbus-player.c (it passes this further to rec-manager.c and gst-recorder.c)
966
 
    MediaPlayerRec *player = mpris2_player_new(NULL);
 
964
    // Create new RecorderCommand
 
965
    RecorderCommand *cmd = g_malloc0(sizeof(RecorderCommand));
 
966
    cmd->type = RECORDING_STOP;
967
967
 
968
 
    str_copy(player->track.track, g_skype.filename, MPRIS_STRLEN-1);
969
 
    player->track.status = PLAYER_STATUS_STOPPED;
 
968
    // Set track name
 
969
    cmd->track = g_strndup(g_skype.filename, DEF_STR_LEN);
970
970
 
971
971
    // Got DURATION messages and ok?
972
972
    if (g_skype.call_duration < 1  && !finished_ok) {
975
975
        LOG_SKYPE("Skype determines that the file is empty. Delete the recorded %s file.\n", g_skype.filename);
976
976
 
977
977
        // Set the delete flag
978
 
        player->track.flags = RECORDING_DELETE_FILE;
 
978
        cmd->flags = RECORDING_DELETE_FILE;
979
979
    }
980
980
 
981
 
    /// Send to the dbus-player.c
982
 
    dbus_player_process_data(player);
983
 
 
984
 
    // Now delete this MediaPlayerRec
985
 
    dbus_player_delete_item(player);
 
981
    // Send command to rec-manager.c. 
 
982
    // It will free the cmd structure after processing.
 
983
    rec_manager_send_command(cmd);    
986
984
 
987
985
    // Reset values
988
986
    g_skype.call_no = 0;
989
987
    g_skype.call_duration = 0;
990
988
    g_skype.paused = FALSE;
991
989
 
992
 
    if (g_skype.filename)
 
990
    if (g_skype.filename) {
993
991
        g_free(g_skype.filename);
 
992
    }
994
993
 
995
994
    g_skype.filename = NULL;
996
995
 
1001
1000
    g_skype.paused = TRUE;
1002
1001
    LOG_SKYPE("Skype: pause recording.\n");
1003
1002
 
1004
 
    // Call dbus-player and rec-manager.
1005
 
    // We simply create a MediaPlayer record and send it to the dbus-player.c (it passes this further to rec-manager.c and gst-recorder.c)
1006
 
    MediaPlayerRec *player = mpris2_player_new(NULL);
1007
 
 
1008
 
    player->track.status = PLAYER_STATUS_PAUSED;
1009
 
 
1010
 
    /// Send to the dbus-player.c
1011
 
    dbus_player_process_data(player);
1012
 
 
1013
 
    // Now delete this MediaPlayerRec
1014
 
    dbus_player_delete_item(player);
 
1003
    // Create new RecorderCommand
 
1004
    RecorderCommand *cmd = g_malloc0(sizeof(RecorderCommand));
 
1005
    cmd->type = RECORDING_PAUSE;
 
1006
 
 
1007
    // Set track name
 
1008
    cmd->track = g_strndup(g_skype.filename, DEF_STR_LEN);
 
1009
 
 
1010
    // Send command to rec-manager.c. 
 
1011
    // It will free the cmd structure after processing.
 
1012
    rec_manager_send_command(cmd);    
1015
1013
}
1016
1014
 
1017
1015
void skype_handle_CALL(gchar *msg) {
1256
1254
    return val;
1257
1255
}
1258
1256
 
 
1257
static void skype_send_notification(gchar *msg) {
 
1258
    RecorderCommand *cmd = g_malloc0(sizeof(RecorderCommand));
 
1259
    cmd->type = RECORDING_NOTIFY_MSG;
 
1260
    cmd->track = g_strndup(msg, DEF_STR_LEN);
 
1261
 
 
1262
    // Send command to rec-manager.c. 
 
1263
    // It will free the cmd structure after processing.
 
1264
    rec_manager_send_command(cmd);
 
1265
}
1259
1266