~audio-recorder/audio-recorder/trunk

22 by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions.
1
/*
1424 by Osmo Antero
Version 3.0.0
2
 * Copyright (c) 2011- Osmo Antero.
3 by Osmo Antero Maatta
Updated some filenames and traslations
3
 *
4
 * This library is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU Library General Public
6
 * License as published by the Free Software Foundation; either
239 by Osmo Antero
Moving to GPL3 license. All src/*.c should now comply to GPL3.
7
 * version 3 of the License (GPL3), or any later version.
3 by Osmo Antero Maatta
Updated some filenames and traslations
8
 *
9
 * This library is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
463 by Osmo Antero
Updated README and INSTALL files.
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
239 by Osmo Antero
Moving to GPL3 license. All src/*.c should now comply to GPL3.
12
 * See the GNU Library General Public License 3 for more details.
3 by Osmo Antero Maatta
Updated some filenames and traslations
13
 *
14
 * You should have received a copy of the GNU Library General Public
239 by Osmo Antero
Moving to GPL3 license. All src/*.c should now comply to GPL3.
15
 * License 3 along with this program; if not, see /usr/share/common-licenses/GPL file
1012.1.5 by David Rabel
GPL boilerplate updated in source files.
16
 * or <http://www.gnu.org/licenses/>.
239 by Osmo Antero
Moving to GPL3 license. All src/*.c should now comply to GPL3.
17
*/
3 by Osmo Antero Maatta
Updated some filenames and traslations
18
#include <string.h>
19
#include <glib.h>
1423 by Osmo Antero
Fix problem with duplicate messages from media players.
20
#include <glib/gprintf.h>
3 by Osmo Antero Maatta
Updated some filenames and traslations
21
#include <gdk/gdk.h>
101 by Osmo Antero
New media-player interface that's based on the MediaPlayer2 standard. See src/dbus-mpris2.c.
22
#include <gio/gio.h>
295 by Osmo Antero
Using now players' .desktop file to get program name and executable (improved code).
23
#include <gio/gdesktopappinfo.h>
101 by Osmo Antero
New media-player interface that's based on the MediaPlayer2 standard. See src/dbus-mpris2.c.
24
#include <unistd.h>
3 by Osmo Antero Maatta
Updated some filenames and traslations
25
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
26
#include "dconf.h"
3 by Osmo Antero Maatta
Updated some filenames and traslations
27
#include "log.h"
28
#include "utility.h"
29
#include "support.h"
30
#include "dbus-player.h"
31
40 by Osmo Antero Maatta
Added ability to record from multiple devices. Major changes in all modules.
32
#include "audio-sources.h"
33
101 by Osmo Antero
New media-player interface that's based on the MediaPlayer2 standard. See src/dbus-mpris2.c.
34
// MPRIS2 compliant players.
35
#include "dbus-mpris2.h"
3 by Osmo Antero Maatta
Updated some filenames and traslations
36
173 by Osmo Antero
Support new systems; Ubuntu 12.10, Fedora 18. Improved timer and VAD-modules. Better gst-pipeline.
37
// Send commands to rec-manager.c
38
#include "rec-manager-struct.h"
39
1423 by Osmo Antero
Fix problem with duplicate messages from media players.
40
// rec-manager.c
41
#include "rec-manager.h"
42
3 by Osmo Antero Maatta
Updated some filenames and traslations
43
// List of players
44
static GHashTable *g_player_list = NULL;
45
46
static void dbus_player_disconnect_signals();
47
static void dbus_player_clear_list();
48
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
49
static void dbus_player_get_saved();
50
static void dbus_player_save(MediaPlayerRec *pl);
295 by Osmo Antero
Using now players' .desktop file to get program name and executable (improved code).
51
static void dbus_player_delete_saved(const gchar *service_name);
1423 by Osmo Antero
Fix problem with duplicate messages from media players.
52
static gboolean dbus_player_msg_is_duplicate(MediaPlayerRec *player);
53
54
static const gchar *status_name(gint status) __attribute__((unused));
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
55
295 by Osmo Antero
Using now players' .desktop file to get program name and executable (improved code).
56
gboolean add_player_to_list(gchar *desktop_file, gchar *service_name);
3 by Osmo Antero Maatta
Updated some filenames and traslations
57
58
void dbus_player_init() {
59
    LOG_DEBUG("Init dbus-player.c.\n");
60
61
    g_player_list = NULL;
62
101 by Osmo Antero
New media-player interface that's based on the MediaPlayer2 standard. See src/dbus-mpris2.c.
63
    mpris2_module_init();
3 by Osmo Antero Maatta
Updated some filenames and traslations
64
}
65
66
void dbus_player_exit() {
67
    LOG_DEBUG("Clean up dbus-player.c.\n");
68
69
    // Disconnect DBus signals for all Media Players
70
    dbus_player_disconnect_signals();
71
72
    // Clear the player list
73
    dbus_player_clear_list();
74
101 by Osmo Antero
New media-player interface that's based on the MediaPlayer2 standard. See src/dbus-mpris2.c.
75
    mpris2_module_exit();
3 by Osmo Antero Maatta
Updated some filenames and traslations
76
}
77
173 by Osmo Antero
Support new systems; Ubuntu 12.10, Fedora 18. Improved timer and VAD-modules. Better gst-pipeline.
78
static RecorderCommand *convert_data(MediaPlayerRec *pl) {
79
    // Convert MediaPlayerRec to RecorderCommand
80
81
    if (!pl) return NULL;
82
    TrackInfo *tr = &pl->track;
83
84
    RecorderCommand *cmd = g_malloc0(sizeof(RecorderCommand));
1268 by Osmo Antero
(work in progress) Changing and adding better field names to support ID3 tagging better.
85
86
    cmd->title = g_strndup(tr->title, MPRIS_STRLEN);
1408 by Osmo Antero
Version 2.1.1. Fix to support longer filenames + fix to find default output device.
87
    cmd->artist = g_strndup(tr->artist, MPRIS_STRLEN);  // Actually a list of artists separated by '\v' (should we remove '\v'?)  
173 by Osmo Antero
Support new systems; Ubuntu 12.10, Fedora 18. Improved timer and VAD-modules. Better gst-pipeline.
88
    cmd->album = g_strndup(tr->album, MPRIS_STRLEN);
1408 by Osmo Antero
Version 2.1.1. Fix to support longer filenames + fix to find default output device.
89
    cmd->genre = g_strndup(tr->genre, MPRIS_STRLEN); // Actually a list of genres separated by '\v' (should we remove '\v'?)
1268 by Osmo Antero
(work in progress) Changing and adding better field names to support ID3 tagging better.
90
1408 by Osmo Antero
Version 2.1.1. Fix to support longer filenames + fix to find default output device.
91
    cmd->albumArtist = g_strndup(tr->albumArtist, MPRIS_STRLEN); // Actually a list of albumArtists separated by '\v' (should we remove '\v'?)
1268 by Osmo Antero
(work in progress) Changing and adding better field names to support ID3 tagging better.
92
    cmd->url = g_strndup(tr->url, MPRIS_STRLEN);
93
    cmd->artUrl = g_strndup(tr->artUrl, MPRIS_STRLEN);
94
95
    cmd->trackId = g_strndup(tr->trackId, MPRIS_STRLEN);
96
    cmd->trackNumber = tr->trackNumber;
97
98
    cmd->discNumber = tr->discNumber;
99
100
    cmd->trackLength = tr->trackLength;
101
    cmd->trackPos = tr->trackPos;
102
173 by Osmo Antero
Support new systems; Ubuntu 12.10, Fedora 18. Improved timer and VAD-modules. Better gst-pipeline.
103
    cmd->flags = tr->flags;
104
105
    if (tr->status == PLAYER_STATUS_PAUSED) {
106
        cmd->type = RECORDING_PAUSE;
107
108
    } else if (tr->status == PLAYER_STATUS_PLAYING) {
109
        cmd->type = RECORDING_START;
110
111
    } else if (tr->status == PLAYER_STATUS_NOTIFY_MSG) {
112
        cmd->type = RECORDING_NOTIFY_MSG;
113
114
    } else {
115
        // tr.status == PLAYER_STATUS_CLOSED ||
116
        // tr.status == PLAYER_STATUS_STOPPED
117
        cmd->type = RECORDING_STOP;
118
    }
119
120
    return cmd;
3 by Osmo Antero Maatta
Updated some filenames and traslations
121
}
122
1423 by Osmo Antero
Fix problem with duplicate messages from media players.
123
static gboolean dbus_player_msg_is_duplicate(MediaPlayerRec *player) {
124
    // Check if player->track (TrackInfo) is duplicate of the previous one.
125
    // Return TRUE if duplicate, otherwise FALSE. 
126
    if (!player) return FALSE;
127
128
    // Track info
129
    TrackInfo *tr = &player->track;
130
131
    // Track info
132
    TrackInfo *prev_tr = &player->prev_track;
133
134
    // Check if message is duplicate of previous one
135
    //if (tr->trackLength != prev_tr->trackLength) return FALSE;
136
    //if (tr->trackPos != prev_tr->trackPos) return FALSE;
137
138
    if (tr->trackNumber != prev_tr->trackNumber) {
139
        return FALSE;
140
    }
141
    
142
    if (tr->discNumber != prev_tr->discNumber) {
143
        return FALSE;
144
    }
145
146
    if (tr->audioBitrate != prev_tr->audioBitrate) {
147
        return FALSE;
148
    }
149
150
    if (str_compare(tr->title, prev_tr->title, FALSE)) {
151
        return FALSE;
152
    }
153
154
    if (str_compare(tr->artist, prev_tr->artist, FALSE)) {
155
        return FALSE;
156
    }
157
158
    if (str_compare(tr->album, prev_tr->album, FALSE)) {
159
        return FALSE;
160
    }
161
162
    if (str_compare(tr->genre, prev_tr->genre, TRUE)) {
163
        return FALSE;
164
    }
165
166
    if (str_compare(tr->albumArtist, prev_tr->albumArtist, FALSE)) {
167
        return FALSE;
168
    }
169
170
    if (str_compare(tr->url, prev_tr->url, FALSE)) {
171
        return FALSE;
172
    }
173
174
    //if (str_compare(tr->artUrl, prev_tr->artUrl)) return FALSE;
175
176
    if (str_compare(tr->trackId, prev_tr->trackId, FALSE)) {
177
        return FALSE;
178
    }
179
180
    if (str_compare(tr->contentCreated, prev_tr->contentCreated, FALSE)) {
181
        return FALSE;
182
    }
183
184
    // This TrackInfo is 100% duplicate of the previous one
185
    return TRUE;
186
}
187
188
void dbus_player_process_data(gpointer player_rec, gboolean restart) {
173 by Osmo Antero
Support new systems; Ubuntu 12.10, Fedora 18. Improved timer and VAD-modules. Better gst-pipeline.
189
    // Send message to the rec-manager.c
1423 by Osmo Antero
Fix problem with duplicate messages from media players.
190
191
    MediaPlayerRec *player = (MediaPlayerRec*)player_rec;
173 by Osmo Antero
Support new systems; Ubuntu 12.10, Fedora 18. Improved timer and VAD-modules. Better gst-pipeline.
192
    if (!player) return;
193
1423 by Osmo Antero
Fix problem with duplicate messages from media players.
194
    // Current track
195
    TrackInfo *tr = &player->track;
196
197
    // Previous track (saved track data)
198
    TrackInfo *prev_tr = &player->prev_track;
199
200
    // Got PLAYING message from media player? 
201
    if (tr->status == PLAYER_STATUS_PLAYING) {
202
203
        // Note !
204
        // Check if this message from DBus is duplicate of previous one.
205
        // Some media players send numerous duplicate messages. Messages confuse audio recorder.
206
        if (dbus_player_msg_is_duplicate(player)) {
207
208
            // Increment duplicate msg count. This is just for debugging!.
209
            player->msg_count++;
210
211
            // Is recording paused?
212
            gboolean is_paused = rec_manager_is_paused();
213
214
            if (is_paused) {
215
216
                LOG_PLAYER("%s: This DBus message (#%i) is duplicate of previous one. Continuing PAUSED recording.\n", player->app_name, player->msg_count+1);
217
           
218
                // Continue paused recording
219
                rec_manager_continue_recording();
220
221
            } else {
222
223
                LOG_PLAYER("%s: This DBus message (#%i) is duplicate of previous one, %s. Dropping this message.\n", 
224
                        player->app_name, player->msg_count+1, status_name(tr->status));
225
            }
226
227
            // Is duplicate. Drop this message. 
228
            return;
229
        }
230
231
        
232
        // Start new recording
233
234
        // Stop the player first?
235
        if (restart ) { // || (tr->status == PLAYER_STATUS_STOP)
236
            rec_manager_stop_recording();
237
        }
238
239
        // Save, remember this track for next time !
240
        memcpy(prev_tr, tr, sizeof(TrackInfo));
241
242
        // Set msg count to 1 (just for debugging)
243
        player->msg_count = 1;
244
245
        // Continues to LBL_1
246
    }
247
248
249
    // Got PAUSED message from media player? 
250
    if (tr->status == PLAYER_STATUS_PAUSED) {
251
        // Do nothing.
252
        // Continues to LBL_1
253
    }
254
255
    // Got STOPPED message from media player? 
256
    if (tr->status == PLAYER_STATUS_STOPPED) {
257
        // Nullify prev_tr (forget lastly received track data) 
258
        memset(prev_tr, '\0', sizeof(TrackInfo));
259
    }
260
261
// LBL_1:
262
263
    // Debug:
264
    //dbus_player_debug_print(player);
265
173 by Osmo Antero
Support new systems; Ubuntu 12.10, Fedora 18. Improved timer and VAD-modules. Better gst-pipeline.
266
    // Convert MediaPlayerRec to RecorderCommand
267
    RecorderCommand *cmd = convert_data(player);
268
1423 by Osmo Antero
Fix problem with duplicate messages from media players.
269
    // Send this command to rec-manager queue. 
270
    // Rec-manager will free the cmd structure after processing.
173 by Osmo Antero
Support new systems; Ubuntu 12.10, Fedora 18. Improved timer and VAD-modules. Better gst-pipeline.
271
    rec_manager_send_command(cmd);
3 by Osmo Antero Maatta
Updated some filenames and traslations
272
}
273
274
void dbus_player_player_changed(gchar *service_name) {
2192 by Osmo Antero
Version 3.3.0. Initial suport for PipeWire. Removed suport for Skype
275
    // Re-connect DBus signals/methods for the given service_name (Media Player etc.)
3 by Osmo Antero Maatta
Updated some filenames and traslations
276
277
    // Disconnect all signals/object methods
278
    dbus_player_disconnect_signals();
279
280
    // Get MediaPlayerRec for this service_name
281
    MediaPlayerRec *player = dbus_player_lookup_service_name(service_name);
282
283
    if (player && player->func_set_signals) {
284
285
        LOG_PLAYER("Connect DBus signals for %s (%s).\n", player->app_name, player->service_name);
286
2192 by Osmo Antero
Version 3.3.0. Initial suport for PipeWire. Removed suport for Skype
287
        // Start application (Media Player, etc)
3 by Osmo Antero Maatta
Updated some filenames and traslations
288
        if (player->func_start_app) {
289
            player->func_start_app(player);
290
        }
291
292
        // Connect signals so we receive track-changed/start/stop messages from this app (over DBus)
293
        player->func_set_signals(player, TRUE); // TRUE=connect/register, FALSE=disconnect/unregister
294
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
295
        // Save this player in GSettings so user doesn't need to refresh the combo manually.
296
        dbus_player_save(player);
3 by Osmo Antero Maatta
Updated some filenames and traslations
297
    }
298
}
299
300
static void dbus_player_disconnect_signals() {
301
    // Disconnect all signal-functions from the DBus
302
    GHashTableIter iter;
303
    gpointer key, value;
304
305
    g_hash_table_iter_init(&iter, g_player_list);
22 by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions.
306
    while (g_hash_table_iter_next(&iter, &key, &value)) {
3 by Osmo Antero Maatta
Updated some filenames and traslations
307
        MediaPlayerRec *player = (MediaPlayerRec*)value;
308
        if (player && player->func_set_signals) {
309
            // Disconnect signals
106 by Osmo Antero
Improved MPRIS2 module. VLC media player should now work with ar.
310
            player->func_set_signals(player, FALSE); // FALSE=disconnect/unregister
3 by Osmo Antero Maatta
Updated some filenames and traslations
311
        }
312
    }
313
}
314
315
GHashTable *dbus_player_get_list_ref() {
1427 by Osmo Antero
Version 3.0.2
316
    if (!g_player_list) {
3 by Osmo Antero Maatta
Updated some filenames and traslations
317
        g_player_list = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, dbus_player_delete_item);
1427 by Osmo Antero
Version 3.0.2
318
    }
3 by Osmo Antero Maatta
Updated some filenames and traslations
319
320
    return g_player_list;
321
}
322
323
static gboolean dbus_palyer_remove_node(gpointer key, gpointer value, gpointer user_data) {
324
    // Return TRUE so this (key, value) pair gets removed and deleted.
325
    return TRUE;
326
}
327
328
static void dbus_player_clear_list() {
329
    // Delete the entire g_player_list
22 by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions.
330
    if (g_player_list) {
3 by Osmo Antero Maatta
Updated some filenames and traslations
331
        g_hash_table_foreach_remove(g_player_list, dbus_palyer_remove_node, NULL);
332
        g_hash_table_unref(g_player_list);
333
    }
334
    g_player_list = NULL;
335
}
336
337
void dbus_player_delete_item(gpointer data) {
338
    MediaPlayerRec *player = (MediaPlayerRec*)data;
339
    if (!player) return;
340
341
    LOG_PLAYER("dbus_player_delete_item: %s (%s).\n", player->app_name, player->service_name);
342
343
    if (player->func_set_signals) {
344
        // Disconnect signals
345
        player->func_set_signals(player, FALSE); // TRUE=connect, FALSE=disconnect
346
    }
347
106 by Osmo Antero
Improved MPRIS2 module. VLC media player should now work with ar.
348
    if (G_IS_DBUS_PROXY(player->proxy)) {
3 by Osmo Antero Maatta
Updated some filenames and traslations
349
        g_object_unref(player->proxy);
350
    }
351
    player->proxy = NULL;
352
106 by Osmo Antero
Improved MPRIS2 module. VLC media player should now work with ar.
353
    if (G_IS_DBUS_PROXY(player->prop_proxy)) {
101 by Osmo Antero
New media-player interface that's based on the MediaPlayer2 standard. See src/dbus-mpris2.c.
354
        g_object_unref(player->prop_proxy);
355
    }
356
    player->prop_proxy = NULL;
357
3 by Osmo Antero Maatta
Updated some filenames and traslations
358
    g_free(player->service_name);
295 by Osmo Antero
Using now players' .desktop file to get program name and executable (improved code).
359
    g_free(player->desktop_file);
360
    g_free(player->exec_cmd);
3 by Osmo Antero Maatta
Updated some filenames and traslations
361
    g_free(player->app_name);
40 by Osmo Antero Maatta
Added ability to record from multiple devices. Major changes in all modules.
362
    g_free(player->icon_name);
1427 by Osmo Antero
Version 3.0.2
363
3 by Osmo Antero Maatta
Updated some filenames and traslations
364
    g_free(player);
365
}
366
295 by Osmo Antero
Using now players' .desktop file to get program name and executable (improved code).
367
MediaPlayerRec *dbus_player_lookup_app_name(const gchar *app_name) {
3 by Osmo Antero Maatta
Updated some filenames and traslations
368
    // Lookup player by its application name (p->app_name).
2192 by Osmo Antero
Version 3.3.0. Initial suport for PipeWire. Removed suport for Skype
369
    // Typical app_names are "Amarok 2.3.2", "RhythmBox 2.3".
3 by Osmo Antero Maatta
Updated some filenames and traslations
370
    GHashTableIter iter;
371
    gpointer key, value;
372
373
    if (str_length(app_name, 1024) < 1) return NULL;
374
375
    g_hash_table_iter_init(&iter, g_player_list);
22 by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions.
376
    while (g_hash_table_iter_next(&iter, &key, &value)) {
3 by Osmo Antero Maatta
Updated some filenames and traslations
377
        MediaPlayerRec *p = (MediaPlayerRec*)value;
378
        if (!g_strcmp0(p->app_name, app_name)) {
379
            return p;
380
        }
381
    }
382
    return NULL;
383
}
384
295 by Osmo Antero
Using now players' .desktop file to get program name and executable (improved code).
385
MediaPlayerRec *dbus_player_lookup_service_name(const gchar *service_name) {
3 by Osmo Antero Maatta
Updated some filenames and traslations
386
    // Lookup player by its service name (p->service_name).
101 by Osmo Antero
New media-player interface that's based on the MediaPlayer2 standard. See src/dbus-mpris2.c.
387
    // "org.mpris.MediaPlayer2.Player.banshee" is a typical service_name.
3 by Osmo Antero Maatta
Updated some filenames and traslations
388
    GHashTableIter iter;
389
    gpointer key, value;
390
391
    if (str_length(service_name, 1024) < 1) return NULL;
392
393
    g_hash_table_iter_init(&iter, g_player_list);
22 by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions.
394
    while (g_hash_table_iter_next(&iter, &key, &value)) {
3 by Osmo Antero Maatta
Updated some filenames and traslations
395
        MediaPlayerRec *p = (MediaPlayerRec*)value;
396
        if (!g_strcmp0(p->service_name, service_name)) {
397
            return p;
398
        }
399
    }
400
    return NULL;
401
}
402
1423 by Osmo Antero
Fix problem with duplicate messages from media players.
403
static const gchar *status_name(gint status) {
404
static gchar s[80]; 
405
406
    s[0] = '\0';
407
408
    switch (status) {
409
410
    case PLAYER_STATUS_CLOSED:
411
        g_sprintf(s, "Status:%d  PLAYER_STATUS_CLOSED (not running)", status);
412
        break;
413
414
    case PLAYER_STATUS_STOPPED:
415
        g_sprintf(s, "Status:%d  PLAYER_STATUS_STOPPED", status);
416
        break;
417
418
    case PLAYER_STATUS_PAUSED:
419
        g_sprintf(s, "Status:%d  PLAYER_STATUS_PAUSED", status);
420
        break;
421
422
    case PLAYER_STATUS_PLAYING:
423
        g_sprintf(s, "Status:%d  PLAYER_STATUS_PLAYING", status);
424
        break;
425
426
    case PLAYER_STATUS_NOTIFY_MSG:
427
        // Simply a msg to the GUI.
428
        g_sprintf(s, "Status:%d  PLAYER_STATUS_NOTIFY_MSG", status);
429
        break;
430
431
    default:
432
        g_sprintf(s, "Unknown status:%d\n", status);
433
    }
434
435
    return &s[0];
436
}
437
3 by Osmo Antero Maatta
Updated some filenames and traslations
438
void dbus_player_debug_print(MediaPlayerRec *p) {
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
439
    if (!p) return;
440
3 by Osmo Antero Maatta
Updated some filenames and traslations
441
    LOG_PLAYER("------------------------------\n");
442
443
    LOG_PLAYER("Player app name:%s\n", p->app_name);
444
    LOG_PLAYER("Service name:%s\n", p->service_name);
295 by Osmo Antero
Using now players' .desktop file to get program name and executable (improved code).
445
    LOG_PLAYER("Desktop file:%s.desktop\n", p->desktop_file);
446
    LOG_PLAYER("Executable command:%s\n", p->exec_cmd);
22 by Osmo Antero Maatta
Formatted the code using astyle. See README for instructions.
447
3 by Osmo Antero Maatta
Updated some filenames and traslations
448
    TrackInfo *tr = &p->track;
449
1423 by Osmo Antero
Fix problem with duplicate messages from media players.
450
    LOG_PLAYER("%s\n", status_name(tr->status));
3 by Osmo Antero Maatta
Updated some filenames and traslations
451
452
    if (tr->status != PLAYER_STATUS_NOTIFY_MSG) {
1268 by Osmo Antero
(work in progress) Changing and adding better field names to support ID3 tagging better.
453
        LOG_PLAYER("Title:%s\n", tr->title);
3 by Osmo Antero Maatta
Updated some filenames and traslations
454
        LOG_PLAYER("Artist:%s\n", tr->artist);
455
        LOG_PLAYER("Album:%s\n", tr->album);
1268 by Osmo Antero
(work in progress) Changing and adding better field names to support ID3 tagging better.
456
        LOG_PLAYER("Genre:%s\n", tr->genre);
1423 by Osmo Antero
Fix problem with duplicate messages from media players.
457
        LOG_PLAYER("AlbumArtist:%s\n", tr->albumArtist);
458
        LOG_PLAYER("Url:%s\n", tr->url);
459
        LOG_PLAYER("ArtUrl:%s\n", tr->artUrl);
460
        LOG_PLAYER("TrackId:%s\n", tr->trackId);
461
        LOG_PLAYER("ContentCreated:%s\n", tr->contentCreated);
462
1268 by Osmo Antero
(work in progress) Changing and adding better field names to support ID3 tagging better.
463
464
        LOG_PLAYER("Track length in microsecs:%ld\n", tr->trackLength);
465
        LOG_PLAYER("Track pos in microsecs:%ld\n", tr->trackPos);
3 by Osmo Antero Maatta
Updated some filenames and traslations
466
        LOG_PLAYER("Flags:%d\n", tr->flags);
1423 by Osmo Antero
Fix problem with duplicate messages from media players.
467
468
        LOG_PLAYER("Msg count:%d\n", p->msg_count);
469
470
3 by Osmo Antero Maatta
Updated some filenames and traslations
471
    } else {
101 by Osmo Antero
New media-player interface that's based on the MediaPlayer2 standard. See src/dbus-mpris2.c.
472
        // Simply a msg to the GUI.
1268 by Osmo Antero
(work in progress) Changing and adding better field names to support ID3 tagging better.
473
        LOG_PLAYER("Message:%s\n", tr->title);
3 by Osmo Antero Maatta
Updated some filenames and traslations
474
    }
475
476
    LOG_PLAYER("------------------------------\n");
477
}
478
479
GHashTable *dbus_player_get_player_list() {
480
    // Clear the old list
481
    dbus_player_clear_list();
482
483
    // Populate the list.
101 by Osmo Antero
New media-player interface that's based on the MediaPlayer2 standard. See src/dbus-mpris2.c.
484
    // Detect players that follow the org.mpris.MediaPlayer2.* standard.
485
    mpris2_detect_players();
486
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
487
    // Add lastly used and saved players to the list
488
    dbus_player_get_saved();
489
463 by Osmo Antero
Updated README and INSTALL files.
490
    // Make sure the most popular players are in the list (on our target distros).
288 by Osmo Antero
Failed to read properties (Identity, DesktopEntry) from some media players. Changes in dbus-mpris2.c
491
    // Notice: Audio-recorder will automatically detect and remember the last used players.
463 by Osmo Antero
Updated README and INSTALL files.
492
    //         Start your media-player, then press [Refresh]-button at end of Source: listbox to detect it.
493
    //         You do not need to hard-code other, new players here.
101 by Osmo Antero
New media-player interface that's based on the MediaPlayer2 standard. See src/dbus-mpris2.c.
494
495
    // Add Rhythmbox manually (check if installed)
295 by Osmo Antero
Using now players' .desktop file to get program name and executable (improved code).
496
    add_player_to_list("rhythmbox", "org.mpris.MediaPlayer2.rhythmbox");
101 by Osmo Antero
New media-player interface that's based on the MediaPlayer2 standard. See src/dbus-mpris2.c.
497
3 by Osmo Antero Maatta
Updated some filenames and traslations
498
    return g_player_list;
499
}
500
295 by Osmo Antero
Using now players' .desktop file to get program name and executable (improved code).
501
gboolean add_player_to_list(gchar *desktop_file, gchar *service_name) {
101 by Osmo Antero
New media-player interface that's based on the MediaPlayer2 standard. See src/dbus-mpris2.c.
502
    // Add player manually to the list. Check if it's installed.
503
504
    // Already in the list?
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
505
    if (dbus_player_lookup_service_name(service_name)) return TRUE;
101 by Osmo Antero
New media-player interface that's based on the MediaPlayer2 standard. See src/dbus-mpris2.c.
506
295 by Osmo Antero
Using now players' .desktop file to get program name and executable (improved code).
507
    // New MediaPlayer record
508
    MediaPlayerRec *player = mpris2_player_new(service_name);
509
510
    // Set desktop file
511
    player->desktop_file = g_strdup(desktop_file);
512
1428 by Osmo Antero
Version 3.0.4.
513
    // Read rest from player's .desktop file
295 by Osmo Antero
Using now players' .desktop file to get program name and executable (improved code).
514
    get_details_from_desktop_file(player, desktop_file);
515
516
    // Find executable /usr/bin/exec_cmd
517
    gchar *path = find_command_path(player->exec_cmd);
518
101 by Osmo Antero
New media-player interface that's based on the MediaPlayer2 standard. See src/dbus-mpris2.c.
519
    if (!path) {
520
        // Not installed.
295 by Osmo Antero
Using now players' .desktop file to get program name and executable (improved code).
521
        dbus_player_delete_item(player);
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
522
        return FALSE;
101 by Osmo Antero
New media-player interface that's based on the MediaPlayer2 standard. See src/dbus-mpris2.c.
523
    }
524
    g_free(path);
525
526
    // Function to connect/disconnect event signals for this player
527
    player->func_set_signals = mpris2_set_signals;
528
1268 by Osmo Antero
(work in progress) Changing and adding better field names to support ID3 tagging better.
529
    // Function to get track-info (album, title/song name/title, genre, etc.)
101 by Osmo Antero
New media-player interface that's based on the MediaPlayer2 standard. See src/dbus-mpris2.c.
530
    player->func_get_info = mpris2_get_metadata;
531
532
    // Function to start/run the media player
533
    player->func_start_app = mpris2_start_app;
534
535
    // Function to check if this player is running
536
    player->func_check_is_running = mpris2_service_is_running;
537
538
    if (!dbus_player_lookup_app_name(player->app_name)) {
539
        // Add to list
540
        GHashTable *player_list = dbus_player_get_list_ref();
541
        g_hash_table_insert(player_list, g_strdup(player->service_name), player);
542
    } else {
543
        // Duplicate or bad record. Free it.
544
        dbus_player_delete_item(player);
545
    }
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
546
547
    return TRUE;
101 by Osmo Antero
New media-player interface that's based on the MediaPlayer2 standard. See src/dbus-mpris2.c.
548
}
549
173 by Osmo Antero
Support new systems; Ubuntu 12.10, Fedora 18. Improved timer and VAD-modules. Better gst-pipeline.
550
void dbus_player_send_notification(gchar *msg) {
551
    RecorderCommand *cmd = g_malloc0(sizeof(RecorderCommand));
552
    cmd->type = RECORDING_NOTIFY_MSG;
1268 by Osmo Antero
(work in progress) Changing and adding better field names to support ID3 tagging better.
553
554
    // Convey message in the title field
555
    cmd->title = g_strndup(msg, MPRIS_STRLEN);
173 by Osmo Antero
Support new systems; Ubuntu 12.10, Fedora 18. Improved timer and VAD-modules. Better gst-pipeline.
556
463 by Osmo Antero
Updated README and INSTALL files.
557
    // Send command to rec-manager.c.
173 by Osmo Antero
Support new systems; Ubuntu 12.10, Fedora 18. Improved timer and VAD-modules. Better gst-pipeline.
558
    // It will free the cmd structure after processing.
559
    rec_manager_send_command(cmd);
3 by Osmo Antero Maatta
Updated some filenames and traslations
560
}
561
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
562
// --------------------------------------------------------------------
563
// Support functions to read/write values to "players/saved-player-list" in GSettings.
564
// --------------------------------------------------------------------
565
295 by Osmo Antero
Using now players' .desktop file to get program name and executable (improved code).
566
static void split_value(gchar *str, gchar **desktop_file, gchar **service_name) {
567
    // Split str on "\t" and return the parts.
568
    *desktop_file = NULL;
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
569
    *service_name = NULL;
295 by Osmo Antero
Using now players' .desktop file to get program name and executable (improved code).
570
571
    if (!str) return;
572
573
    // Split on '\t'
574
    gchar **args = g_strsplit(str, "\t", 3);
575
463 by Osmo Antero
Updated README and INSTALL files.
576
    // We cope only 2 arguments
295 by Osmo Antero
Using now players' .desktop file to get program name and executable (improved code).
577
    if  (g_strv_length(args) != 2)  {
578
        goto LBL_1;
579
    }
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
580
288 by Osmo Antero
Failed to read properties (Identity, DesktopEntry) from some media players. Changes in dbus-mpris2.c
581
    if (args && args[0]) {
295 by Osmo Antero
Using now players' .desktop file to get program name and executable (improved code).
582
        *desktop_file = g_strdup(args[0]);
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
583
288 by Osmo Antero
Failed to read properties (Identity, DesktopEntry) from some media players. Changes in dbus-mpris2.c
584
        if (args[1]) {
585
            *service_name = g_strdup(args[1]);
586
        }
463 by Osmo Antero
Updated README and INSTALL files.
587
    }
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
588
463 by Osmo Antero
Updated README and INSTALL files.
589
LBL_1:
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
590
    // Delete args
591
    g_strfreev(args);
592
}
593
295 by Osmo Antero
Using now players' .desktop file to get program name and executable (improved code).
594
gchar *get_base_name(gchar *service_name) {
595
    // Take last part of service_name and return it.
596
    // Eg. take "vlc" from "org.mpris.MediaPlayer2.vlc"
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
597
598
    // Find last "."
298 by Osmo Antero
Fixed some string warnings in dbus modules.
599
    gchar *pos = g_strrstr0(service_name, ".");
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
600
    if (pos) {
601
        return g_strdup(pos+1);
602
    }
603
604
    return NULL;
605
}
606
295 by Osmo Antero
Using now players' .desktop file to get program name and executable (improved code).
607
static void dbus_player_delete_saved(const gchar *service_name) {
608
    // Delete service_name from GSettings.
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
609
    // See dconf-editor, key: /apps/audio-recorder/players/players/saved-player-list
610
    GList *list = NULL;
295 by Osmo Antero
Using now players' .desktop file to get program name and executable (improved code).
611
    GList *new_list = NULL;
612
613
    if (!service_name) return;
614
298 by Osmo Antero
Fixed some string warnings in dbus modules.
615
    str_trim((gchar*)service_name);
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
616
463 by Osmo Antero
Updated README and INSTALL files.
617
    // Get saved-player-list from GSettings.
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
618
    const gchar *conf_key = "players/saved-player-list";
619
    conf_get_string_list((gchar*)conf_key, &list);
463 by Osmo Antero
Updated README and INSTALL files.
620
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
621
    GList *item = g_list_first(list);
622
    while (item) {
295 by Osmo Antero
Using now players' .desktop file to get program name and executable (improved code).
623
        // Take values. Eg: "amarok \t org.mpris.MediaPlayer2.amarok"
624
        gchar *str = (gchar*)item->data;
625
        gchar *desktop_file = NULL;
626
        gchar *service = NULL;
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
627
288 by Osmo Antero
Failed to read properties (Identity, DesktopEntry) from some media players. Changes in dbus-mpris2.c
628
        // Split on '\t'
295 by Osmo Antero
Using now players' .desktop file to get program name and executable (improved code).
629
        split_value(str, &desktop_file, &service);
630
631
        // Service names match?
632
        if (!g_strcmp0(service_name, service)) {
633
            // Drop this node
634
            ;
635
        } else {
636
            // Keep this node
637
            new_list = g_list_append(new_list, g_strdup(str));
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
638
        }
639
295 by Osmo Antero
Using now players' .desktop file to get program name and executable (improved code).
640
        g_free(desktop_file);
641
        g_free(service);
642
643
        item = g_list_next(item);
644
    }
645
463 by Osmo Antero
Updated README and INSTALL files.
646
    // Save changes to GSettings
295 by Osmo Antero
Using now players' .desktop file to get program name and executable (improved code).
647
    conf_save_string_list((gchar*)conf_key, new_list);
648
649
    // Free delete_list
463 by Osmo Antero
Updated README and INSTALL files.
650
    str_list_free(new_list);
295 by Osmo Antero
Using now players' .desktop file to get program name and executable (improved code).
651
    new_list = NULL;
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
652
653
    // Free list
463 by Osmo Antero
Updated README and INSTALL files.
654
    str_list_free(list);
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
655
    list = NULL;
656
}
657
658
static void dbus_player_save(MediaPlayerRec *pl) {
659
    // Save pl->app_name/pl->service_name to GSettings.
660
    // See dconf-editor, key: /apps/audio-recorder/players/players/saved-player-list
661
    GList *list = NULL;
295 by Osmo Antero
Using now players' .desktop file to get program name and executable (improved code).
662
    if (!pl->service_name) return;
288 by Osmo Antero
Failed to read properties (Identity, DesktopEntry) from some media players. Changes in dbus-mpris2.c
663
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
664
    // Delete old value
295 by Osmo Antero
Using now players' .desktop file to get program name and executable (improved code).
665
    dbus_player_delete_saved(pl->service_name);
666
667
    // str must have format "vlc \t org.mpris.MediaPlayer2.vlc"
668
    gchar *str = g_strdup_printf("%s\t%s", check_null(pl->desktop_file), pl->service_name);
669
463 by Osmo Antero
Updated README and INSTALL files.
670
    // Get saved-player-list from Gsettings.
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
671
    const gchar *conf_key = "players/saved-player-list";
672
    conf_get_string_list((gchar*)conf_key, &list);
673
295 by Osmo Antero
Using now players' .desktop file to get program name and executable (improved code).
674
    // Add new entry and save in GSettings/DConf
675
    list = g_list_prepend(list, g_strdup(str));
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
676
    conf_save_string_list((gchar*)conf_key, list);
677
678
#if defined(DEBUG_PLAYER) || defined(DEBUG_ALL)
679
    LOG_PLAYER("----------------------------\n");
680
    str_list_print("New, saved saved-player-list", list);
681
    LOG_PLAYER("----------------------------\n");
682
#endif
463 by Osmo Antero
Updated README and INSTALL files.
683
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
684
    // Free list
463 by Osmo Antero
Updated README and INSTALL files.
685
    str_list_free(list);
686
    list = NULL;
295 by Osmo Antero
Using now players' .desktop file to get program name and executable (improved code).
687
    g_free(str);
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
688
}
689
690
static void dbus_player_get_saved() {
463 by Osmo Antero
Updated README and INSTALL files.
691
    // Get saved-player-list from GSettings.
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
692
    // See dconf-editor, key: /apps/audio-recorder/players/players/saved-player-list
693
    const gchar *conf_key = "players/saved-player-list";
694
695
    // Get list
696
    GList *list = NULL;
697
    conf_get_string_list((gchar*)conf_key, &list);
698
699
#if defined(DEBUG_PLAYER) || defined(DEBUG_ALL)
700
    LOG_PLAYER("----------------------------\n");
701
    str_list_print("Get saved-player-list", list);
702
    LOG_PLAYER("----------------------------\n");
703
#endif
704
705
    // Add saved & still existing media-players to the list
706
    GList *item = g_list_first(list);
707
    while (item) {
295 by Osmo Antero
Using now players' .desktop file to get program name and executable (improved code).
708
        // Read values. Eg. "vlc \t org.mpris.MediaPlayer2.vlc"
709
        gchar *str = (gchar*)item->data;
710
        gchar *desktop_file = NULL;
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
711
        gchar *service_name = NULL;
463 by Osmo Antero
Updated README and INSTALL files.
712
288 by Osmo Antero
Failed to read properties (Identity, DesktopEntry) from some media players. Changes in dbus-mpris2.c
713
        // Split on '\t'
295 by Osmo Antero
Using now players' .desktop file to get program name and executable (improved code).
714
        split_value(str, &desktop_file, &service_name);
715
463 by Osmo Antero
Updated README and INSTALL files.
716
        // We will not tolerate errors here.
303 by Osmo Antero
Fixed a bug when saved-player-list field in GSettings contains bad values or values from older a.r versions.
717
        // Wipe out the entire list if one line is bad (eg. it has older format)!
718
        if (!(desktop_file && service_name)) {
719
            g_free(desktop_file);
720
            g_free(service_name);
721
            conf_save_string_list((gchar*)conf_key, NULL);
722
            goto LBL_1;
723
        }
724
295 by Osmo Antero
Using now players' .desktop file to get program name and executable (improved code).
725
        // Add media-player to the list (to be shown in the "Source:" listbox).
726
        if (!add_player_to_list(desktop_file, service_name)) {
727
728
            // It's probably uninstalled. Delete form GSettings too.
463 by Osmo Antero
Updated README and INSTALL files.
729
            LOG_PLAYER("Player %s, (%s) removed from the list. It's probably uninstalled.\n",
295 by Osmo Antero
Using now players' .desktop file to get program name and executable (improved code).
730
                       desktop_file, service_name);
731
732
            dbus_player_delete_saved(service_name);
463 by Osmo Antero
Updated README and INSTALL files.
733
        }
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
734
295 by Osmo Antero
Using now players' .desktop file to get program name and executable (improved code).
735
        g_free(desktop_file);
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
736
        g_free(service_name);
737
738
        item = g_list_next(item);
739
    }
740
303 by Osmo Antero
Fixed a bug when saved-player-list field in GSettings contains bad values or values from older a.r versions.
741
LBL_1: {
742
        // Free list
463 by Osmo Antero
Updated README and INSTALL files.
743
        str_list_free(list);
744
        list = NULL;
303 by Osmo Antero
Fixed a bug when saved-player-list field in GSettings contains bad values or values from older a.r versions.
745
    }
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
746
}
747
463 by Osmo Antero
Updated README and INSTALL files.
748
void get_details_from_desktop_file(MediaPlayerRec *pl, const gchar *desktop_file) {
1428 by Osmo Antero
Version 3.0.4.
749
    // Find AppInfo for the given .desktop file
750
    // I assume here that .desktop filenames are in ascii (not multibyte) strings
298 by Osmo Antero
Fixed some string warnings in dbus modules.
751
752
    if (!desktop_file) {
753
        goto LBL_1;
754
    }
755
463 by Osmo Antero
Updated README and INSTALL files.
756
    gchar *s = NULL;
298 by Osmo Antero
Fixed some string warnings in dbus modules.
757
295 by Osmo Antero
Using now players' .desktop file to get program name and executable (improved code).
758
    // Ends with ".desktop"?
759
    if (g_str_has_suffix(desktop_file, ".desktop")) {
760
        s = g_strdup(desktop_file);
761
    } else {
463 by Osmo Antero
Updated README and INSTALL files.
762
        // Add ".desktop"
295 by Osmo Antero
Using now players' .desktop file to get program name and executable (improved code).
763
        s = g_strdup_printf("%s.desktop", desktop_file);
764
    }
765
766
    // Get GDesktopAppInfo from propgram.desktop file
767
    GDesktopAppInfo *app_info = g_desktop_app_info_new(s);
1428 by Osmo Antero
Version 3.0.4.
768
769
    gchar *found_str = NULL;
770
771
    // .desktop file was found?
772
    if (!G_IS_DESKTOP_APP_INFO(app_info)) {
773
        // No. Search for it.     
774
775
        g_free(s); s = NULL;
776
777
        // Find application's basename 
778
        // Eg. "amarok" of "org.kde.amarok"
779
        gchar *p = strrchr(desktop_file, '.');
780
781
        if (p && (str_length0(p) > 1)) {
782
            s = g_strdup(p + 1);
783
        } else {
784
            s = g_strdup(desktop_file);
785
        }
786
787
        gchar ***results = g_desktop_app_info_search(s);
788
        // results: gchar *results[][]
789
        // results is a 2-dim array of gchar* strings, the first (i dimension) contains results (another array) for each search string we passed in (in s).
790
        // Please see: https://developer.gnome.org/gio/stable/gio-Desktop-file-based-GAppInfo.html#g-desktop-app-info-search
791
        
792
        gchar *s2 = g_strdup_printf("%s.desktop", s);
793
794
        for (guint i=0; results && results[i] != NULL; i++) { 
795
796
            for (guint j=0; results[i][j] != NULL; j++) {
797
        
798
                // Some nitpicking here
799
                gchar *s1_down = g_ascii_strdown(results[i][j], str_length0(results[i][j]));
800
                gchar *s2_down = g_ascii_strdown(s2, str_length0(s2));
801
802
                if (g_strrstr(s1_down, s2_down)) {
803
                    // Probably safe with utf8 (multibyte)
804
                    // https://developer.gnome.org/glib/stable/glib-String-Utility-Functions.html#g-strrstr
805
                    found_str = g_strdup(results[i][j]);
806
                }
807
808
                g_free(s1_down);
809
                g_free(s2_down);
810
811
                if (found_str) {
812
                    break;
813
                }
814
815
            } // j...
816
817
        } // i...
818
819
        g_free(s2);
820
        
821
        // Free gchar *results[][]
822
        // Be carefull
823
        for (guint i=0; results[i] != NULL; i++) {
824
            g_strfreev(results[i]);
825
        }      
826
        g_free(results); 
827
        results = NULL;
828
829
        // Try again      
830
        if (found_str) {
831
            // Load AppInfo
832
            app_info = g_desktop_app_info_new(found_str);
833
        }            
834
835
    }
836
837
    g_free(found_str);
295 by Osmo Antero
Using now players' .desktop file to get program name and executable (improved code).
838
    g_free(s);
839
1428 by Osmo Antero
Version 3.0.4.
840
    // Do we have AppInfo?
841
    if (!G_IS_DESKTOP_APP_INFO(app_info)) {
295 by Osmo Antero
Using now players' .desktop file to get program name and executable (improved code).
842
        goto LBL_1;
843
    }
844
845
    // Read application title
846
    const gchar *app_name = g_app_info_get_name(G_APP_INFO(app_info));
847
    if (!app_name) {
848
        app_name = g_app_info_get_display_name(G_APP_INFO(app_info));
849
    }
850
851
    pl->app_name = g_strdup(app_name);
852
853
    // Read executable command and its arguments
854
    pl->exec_cmd = g_strdup((gchar*)g_app_info_get_commandline(G_APP_INFO(app_info)));
855
1428 by Osmo Antero
Version 3.0.4.
856
    pl->icon_name = g_desktop_app_info_get_string(app_info, "Icon");
857
    if (!pl->icon_name){
858
        pl->icon_name = g_strdup((gchar *)g_app_info_get_executable(G_APP_INFO(app_info)));    
859
    }
295 by Osmo Antero
Using now players' .desktop file to get program name and executable (improved code).
860
861
    g_object_unref(app_info);
862
1430 by Osmo Antero
Version 3.0.4. Nitpicking with media-players' executables and desktop files
863
864
865
    // Remove %U from the exec command.
866
    // %u, %U in the exec command (.desktop file) is normally replaced by a file argument 
867
    // Some media players show an error if the file argument is empty
868
    str_trim(pl->exec_cmd);
869
870
    gchar *p = g_strrstr(pl->exec_cmd, "%U");
871
    if (!p)
872
        p = g_strrstr(pl->exec_cmd, "%u");
873
874
    if (p)
875
        *p = '\0'; 
876
463 by Osmo Antero
Updated README and INSTALL files.
877
LBL_1: {
1428 by Osmo Antero
Version 3.0.4.
878
        // Basename 
879
        // Eg. take "vlc" from "org.mpris.MediaPlayer2.vlc"
295 by Osmo Antero
Using now players' .desktop file to get program name and executable (improved code).
880
        gchar *base_name = get_base_name(pl->service_name);
881
882
        // Make sure these values are set
1428 by Osmo Antero
Version 3.0.4.
883
        if (!pl->app_name) {
295 by Osmo Antero
Using now players' .desktop file to get program name and executable (improved code).
884
            pl->app_name = g_strdup(base_name);
885
        }
886
1428 by Osmo Antero
Version 3.0.4.
887
        if (!pl->desktop_file) {
295 by Osmo Antero
Using now players' .desktop file to get program name and executable (improved code).
888
            pl->desktop_file = g_strdup(base_name);
889
        }
890
1428 by Osmo Antero
Version 3.0.4.
891
        if (!pl->exec_cmd) {
892
            pl->exec_cmd = g_strdup(base_name);
893
        }
894
895
        if (!pl->exec_cmd) {
896
            pl->exec_cmd = g_strdup(base_name);
897
        }
898
899
        if (!pl->icon_name) {
900
            pl->icon_name = g_strdup(base_name);
295 by Osmo Antero
Using now players' .desktop file to get program name and executable (improved code).
901
        }
463 by Osmo Antero
Updated README and INSTALL files.
902
295 by Osmo Antero
Using now players' .desktop file to get program name and executable (improved code).
903
        g_free(base_name);
904
905
    }
906
}
907
1423 by Osmo Antero
Fix problem with duplicate messages from media players.
908
void dbus_player_reset_values(gchar *audio_source) {
909
    // Reset audio_source's internal values (in dbus-player.c module).
910
911
    // Get MediaPlayerRec for this audio_source (service name)
912
    MediaPlayerRec *player = dbus_player_lookup_service_name(audio_source);
913
914
    if (!player) {
915
        return;
916
    }    
917
918
    // Nullify player->prev_track (TrackInfo record).
1428 by Osmo Antero
Version 3.0.4.
919
    // User has stopped recording from the GUI (Button or Menu), 
920
    // We must clear MediaPlayerRec`s prev_track record.
921
    // User can later re-start recording from the media-player, and it is not counted as duplicate START_RECORDING message. 
1423 by Osmo Antero
Fix problem with duplicate messages from media players.
922
    // This is important for some media players.
923
    TrackInfo *tr = &player->prev_track;
924
    memset(tr, '\0', sizeof(TrackInfo));
925
}
926
213 by osmoma at gmail
A.r will now remember lastly used media-players. New key in data/org.gnome.audio-recorder.gschema.xml.
927