51
54
// Translators: This is a command line option.
52
55
// Output audio level values in a terminal window. This makes it easier to set correct level (dB or %) value in the Timer.
53
56
{ "debug-signal", 'd', 0, G_OPTION_ARG_INT, &g_debug_levels, N_("List signal level values in a terminal window (0=do not list values, 1=list values)."), NULL},
58
// Translators: This is a command line option. Notice: Do not translate the "identity|status|start|stop|pause|show|quit" words.
59
// Control the recorder from command line with --command argument.
60
// --command=identity returns the program name and version.
61
// --command=status returns one of: "not running" | "on" | "off" | "paused".
62
{ "command", 'c', 0, G_OPTION_ARG_STRING, &g_command_arg, N_("Send a command to the recorder; identity|status|start|stop|pause|show|hide|quit."), NULL},
57
67
static void *win_update_gui_ex(gpointer user_data);
58
68
static void *win_set_filename_ex(gpointer user_data);
59
69
static void *win_set_error_text_ex(gpointer user_data);
70
static void *win_show_window_ex(gpointer user_data);
60
71
static gboolean win_delete_cb(GtkWidget *widget, GdkEvent *event, gpointer data);
73
static void *send_client_request(gpointer data);
62
75
static void win_call_gui_func(GThreadFunc func, gpointer user_data) {
63
76
// Create a thread to call GUI (GTK) related functions.
64
77
// GUI functions are called from many places (inside/outside threads) and we have to set gdk_threads_enter() and gdk_threads_leave().
1115
1161
g_thread_init(NULL);
1116
1162
gdk_threads_init();
1117
gdk_threads_enter();
1119
1164
gst_init(&argc, &argv);
1166
// Check if user wants to control the recorder (the running instance of the recorder) from the command line.
1167
if (g_command_arg != NULL) {
1169
// $ audio-recorder --command <argument>
1171
// Check if we find existing instance of Audio-Recorder. Do not start this program twice.
1172
gchar *identity = dbus_service_client_request("get_identity", NULL); // <-- Should return "Audio Recorder #.#"
1174
// Got an answer from existing instance?
1175
if (identity != NULL) {
1176
// Send client request (execute methode call over DBus)
1177
send_client_request(g_command_arg);
1182
// And kill this duplicate instance of audio-recorder
1188
// Let this instance run
1193
// Simply print program name + version and exit?
1194
if (!g_strcmp0(g_command_arg, "identity")) {
1195
send_client_request(g_command_arg);
1196
// This will call exit(0)
1199
// Simply print recording status (not running | on | off | paused) and exit?
1200
else if (!g_strcmp0(g_command_arg, "status")) {
1201
send_client_request(g_command_arg);
1202
// This will call exit(0)
1206
else if (!g_strcmp0(g_command_arg, "quit")) {
1207
send_client_request(g_command_arg);
1208
// This will call exit(0)
1211
// Initialize modules
1121
1212
rec_manager_init();
1123
1214
audio_sources_init();
1201
1305
// Otherwise Media Players and Skype may show up before this app's main window. Skype may even block.
1202
1306
win_set_device_id();
1308
// Send client request (execute method call over DBus).
1309
// We must call this from a thread. Otherwise DBus server (in dbus-service.c) and
1310
// client request (also in dbus-service.c) will conflict & block.
1311
g_thread_create(send_client_request, (gpointer)g_command_arg, FALSE, NULL);
1314
gdk_threads_enter();
1206
1316
gdk_threads_leave();
1321
static void *send_client_request(gpointer data) {
1322
// Send command via DBus to the existing instance of audio-recorder
1323
if (!data) return 0;
1325
// $ audio-recorder --command identity // Print program name + version. Eg. "Audio Recorder 1.0"
1327
// $ audio-recorder --command start
1328
// $ audio-recorder --command stop
1329
// $ audio-recorder --command pause
1331
// $ audio-recorder --command status // Print status; "not running" | "on" | "off" | "paused"
1333
// $ audio-recorder --command show
1334
// $ audio-recorder --command quit
1336
// You can also combine
1337
// $ audio-recorder --command start+show
1338
// $ audio-recorder --command stop+hide
1339
// $ audio-recorder --command stop+quit
1342
gchar *command = g_ascii_strdown((gchar*)data, -1);
1344
gboolean done = FALSE;
1347
if (!g_strcmp0(command, "identity")) {
1349
// Call get_identity(). This should return program name and version.
1350
ret = dbus_service_client_request("get_identity", NULL/*no args*/);
1352
// Eg. "Audio Recorder 2.x"
1353
ret = about_program_name();
1355
g_print("%s\n", ret);
1361
else if (!g_strcmp0(command, "status")) {
1364
ret = dbus_service_client_request("get_state", NULL/*no args*/);
1366
// Audio-recorder is not running
1367
ret = g_strdup("not running");
1369
g_print("%s\n", ret);
1375
else if (!g_strcmp0(command, "quit")) {
1377
// Call set_state("quit"). Terminate application.
1378
ret = dbus_service_client_request("set_state", "quit");
1384
// -------------------------------------------------
1386
if (g_strrstr(command, "start")) {
1388
// Call set_state("start")
1389
ret = dbus_service_client_request("set_state", "start");
1390
if (g_strcmp0(ret, "OK")) {
1391
LOG_ERROR("Cannot execute client/dbus request %s.\n", "set_state(\"start\")");
1397
if (g_strrstr(command, "stop")) {
1399
// Call set_state("stop")
1400
ret = dbus_service_client_request("set_state", "stop");
1401
if (g_strcmp0(ret, "OK")) {
1402
LOG_ERROR("Cannot execute client/dbus request %s.\n", "set_state(\"stop\")");
1408
if (g_strrstr(command, "pause")) {
1410
// Call set_state("pause")
1411
ret = dbus_service_client_request("set_state", "pause");
1412
if (g_strcmp0(ret, "OK")) {
1413
LOG_ERROR("Cannot execute client/dbus request %s.\n", "set_state(\"pause\")");
1419
if (g_strrstr(command, "show")) {
1421
// Call set_state("show")
1422
ret = dbus_service_client_request("set_state", "show");
1423
if (g_strcmp0(ret, "OK")) {
1424
LOG_ERROR("Cannot execute client/dbus request %s.\n", "set_state(\"show\")");
1430
if (g_strrstr(command, "hide")) {
1432
// Call set_state("hide")
1433
ret = dbus_service_client_request("set_state", "hide");
1434
if (g_strcmp0(ret, "OK")) {
1435
LOG_ERROR("Cannot execute client/dbus request %s.\n", "set_state(\"hide\")");
1441
if (g_strrstr(command, "identity")) {
1443
// Call set_state("start")
1444
ret = dbus_service_client_request("get_identity", NULL/*no args*/);
1446
LOG_ERROR("Cannot execute client/dbus request %s.\n", "get_identity()");
1448
g_print("%s\n", ret);
1453
if (g_strrstr(command, "status")) {
1456
ret = dbus_service_client_request("get_state", NULL /*no args*/);
1458
// Audio-recorder is not running
1459
ret = g_strdup("not running");
1461
// Print state; not running|on|off|paused
1462
g_print("%s\n", ret);
1468
LOG_ERROR("Invalid argument in --command=%s. See --help for more information.\n", command);
1473
// FALSE: Remove idle function