~audio-recorder/audio-recorder/trunk

« back to all changes in this revision

Viewing changes to src/settings-pipe.c

  • Committer: Osmo Antero
  • Date: 2015-02-06 14:13:34 UTC
  • Revision ID: osmoma@gmail.com-20150206141334-ifaeqyan4ygxo49g
Updated README and INSTALL files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 *
9
9
 * This library is distributed in the hope that it will be useful,
10
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
12
 * See the GNU Library General Public License 3 for more details.
13
13
 *
14
14
 * You should have received a copy of the GNU Library General Public
34
34
 
35
35
static void get_profiles() {
36
36
    GtkTreeModel *store = gtk_combo_box_get_model(GTK_COMBO_BOX(g_profiles));
37
 
    gtk_list_store_clear(GTK_LIST_STORE(store));   
 
37
    gtk_list_store_clear(GTK_LIST_STORE(store));
38
38
 
39
39
    media_profiles_load();
40
 
 
 
40
 
41
41
    GList *list = profiles_get_list();
42
 
      
 
42
 
43
43
    GList *item = g_list_first(list);
44
44
    while (item) {
45
45
        ProfileRec *rec = (ProfileRec*)item->data;
46
 
               
 
46
 
47
47
        gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(g_profiles), rec->id, rec->id);
48
 
 
 
48
 
49
49
        LOG_DEBUG("Loading media profile: %s\n", rec->id);
50
 
 
 
50
 
51
51
        item = g_list_next(item);
52
 
    }     
 
52
    }
53
53
}
54
54
 
55
55
static void populate_fields(gchar *profile_name) {
57
57
    gtk_entry_set_text(GTK_ENTRY(g_saved_id), "");
58
58
    gtk_entry_set_text(GTK_ENTRY(g_file_ext), "");
59
59
 
60
 
    GtkTextBuffer *buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(g_pipe_text));    
 
60
    GtkTextBuffer *buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(g_pipe_text));
61
61
    gtk_text_buffer_set_text(buf, "", -1);
62
62
 
63
63
    const ProfileRec *rec = profiles_find_rec(profile_name);
64
64
    if (!rec) {
65
 
        return; 
66
 
    }      
 
65
        return;
 
66
    }
67
67
 
68
68
    // Save current selection in g_saved_id
69
69
    gtk_entry_set_text(GTK_ENTRY(g_saved_id), rec->id);
81
81
 
82
82
    *file_ext = g_strdup(gtk_entry_get_text(GTK_ENTRY(g_file_ext)));
83
83
 
84
 
    GtkTextBuffer *buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(g_pipe_text));  
85
 
    
 
84
    GtkTextBuffer *buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(g_pipe_text));
 
85
 
86
86
    GtkTextIter start_t, end_t;
87
87
    gtk_text_buffer_get_start_iter(buf, &start_t);
88
 
    gtk_text_buffer_get_end_iter(buf, &end_t);    
89
 
    
 
88
    gtk_text_buffer_get_end_iter(buf, &end_t);
 
89
 
90
90
    *pipe_text = gtk_text_buffer_get_text(buf, &start_t, &end_t, FALSE);
91
91
}
92
92
 
97
97
    gchar *old_name = NULL;
98
98
    gchar *name = NULL;
99
99
    gchar *file_ext =  NULL;
100
 
    gchar *pipe_text = NULL;  
 
100
    gchar *pipe_text = NULL;
101
101
    read_fields(&old_name, &name, &file_ext, &pipe_text);
102
102
 
103
103
    if (str_length0(name) < 1) {
104
104
        goto LBL_1;
105
 
    }  
 
105
    }
106
106
 
107
107
    if (str_length0(file_ext) < 1) {
108
108
        goto LBL_1;
109
 
    }  
 
109
    }
110
110
 
111
111
    if (str_length0(pipe_text) < 1) {
112
112
        goto LBL_1;
113
 
    }  
 
113
    }
114
114
 
115
115
    // Ok
116
 
    ret = TRUE;  
 
116
    ret = TRUE;
117
117
 
118
 
 LBL_1: 
 
118
LBL_1:
119
119
    g_free(old_name);
120
120
    g_free(name);
121
121
    g_free(file_ext);
122
122
    g_free(pipe_text);
123
123
 
124
124
    LOG_DEBUG("check_fields() function returns: %s\n", ret ? "TRUE" : "FALSE");
125
 
    
126
 
    return ret;  
 
125
 
 
126
    return ret;
127
127
}
128
128
 
129
129
static gboolean find_row(gchar *find_name, GtkTreeIter *iter) {
131
131
 
132
132
    gboolean ret = gtk_tree_model_get_iter_first(model, iter);
133
133
    while (ret) {
134
 
    
 
134
 
135
135
        gchar *name = NULL;
136
136
        gtk_tree_model_get(GTK_TREE_MODEL(model), iter, 0, &name, -1);
137
 
        
 
137
 
138
138
        if (!g_strcmp0(find_name, name)) {
139
139
            g_free(name);
140
140
            return TRUE;
141
 
        }  
142
 
        
 
141
        }
 
142
 
143
143
        g_free(name);
144
 
         
 
144
 
145
145
        ret = gtk_tree_model_iter_next(model, iter);
146
146
    }
147
 
    
 
147
 
148
148
    return FALSE;
149
149
}
150
150
 
151
151
static void new_profile() {
152
152
    populate_fields("");
153
 
    
154
 
    GtkWidget *entry = gtk_bin_get_child(GTK_BIN(g_profiles));    
 
153
 
 
154
    GtkWidget *entry = gtk_bin_get_child(GTK_BIN(g_profiles));
155
155
    gtk_entry_set_text(GTK_ENTRY(entry), "");
156
 
    
 
156
 
157
157
    LOG_DEBUG("Create a new profile.\n");
158
 
    
159
 
    gtk_widget_grab_focus(g_profiles);          
 
158
 
 
159
    gtk_widget_grab_focus(g_profiles);
160
160
}
161
161
 
162
162
static void delete_profile() {
163
163
    gchar *old_name = NULL;
164
164
    gchar *name = NULL;
165
165
    gchar *file_ext =  NULL;
166
 
    gchar *pipe_text = NULL;  
 
166
    gchar *pipe_text = NULL;
167
167
    read_fields(&old_name, &name, &file_ext, &pipe_text);
168
168
 
169
 
    const gchar *str = NULL; 
 
169
    const gchar *str = NULL;
170
170
 
171
171
    if (str_length0(old_name) > 0) {
172
 
        str = old_name;   
 
172
        str = old_name;
173
173
    } else {
174
 
        str = name;       
175
 
    }  
176
 
    
177
 
    profiles_delete(str);  
178
 
    
 
174
        str = name;
 
175
    }
 
176
 
 
177
    profiles_delete(str);
 
178
 
179
179
    populate_fields("");
180
 
    
 
180
 
181
181
    get_profiles();
182
182
 
183
183
    gtk_combo_box_set_active_iter(GTK_COMBO_BOX(g_profiles), NULL);
184
 
    
185
 
    GtkWidget *entry = gtk_bin_get_child(GTK_BIN(g_profiles));    
186
 
    gtk_entry_set_text(GTK_ENTRY(entry), "");       
 
184
 
 
185
    GtkWidget *entry = gtk_bin_get_child(GTK_BIN(g_profiles));
 
186
    gtk_entry_set_text(GTK_ENTRY(entry), "");
187
187
 
188
188
    g_free(old_name);
189
189
    g_free(name);
200
200
    gchar *old_name = NULL;
201
201
    gchar *name = NULL;
202
202
    gchar *file_ext =  NULL;
203
 
    gchar *pipe_text = NULL;  
 
203
    gchar *pipe_text = NULL;
204
204
    read_fields(&old_name, &name, &file_ext, &pipe_text);
205
205
 
206
206
    LOG_DEBUG("Save profile: old name:%s, new name:%s, file ext:%s, pipe text:%s\n", old_name, name, file_ext, pipe_text);
208
208
    profiles_update(old_name, name, file_ext, pipe_text);
209
209
 
210
210
    get_profiles();
211
 
    
 
211
 
212
212
    GtkTreeIter iter;
213
213
    gboolean found = find_row(name, &iter);
214
214
 
215
 
    if (found) {    
 
215
    if (found) {
216
216
        gtk_combo_box_set_active_iter(GTK_COMBO_BOX(g_profiles), &iter);
217
217
    }
218
218
 
227
227
    profiles_reset();
228
228
 
229
229
    populate_fields("");
230
 
    
231
 
    GtkWidget *entry = gtk_bin_get_child(GTK_BIN(g_profiles));    
232
 
    gtk_entry_set_text(GTK_ENTRY(entry), "");       
233
 
    
 
230
 
 
231
    GtkWidget *entry = gtk_bin_get_child(GTK_BIN(g_profiles));
 
232
    gtk_entry_set_text(GTK_ENTRY(entry), "");
 
233
 
234
234
    get_profiles();
235
235
}
236
236
 
238
238
 
239
239
    gchar *name =       gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(g_profiles));
240
240
    const gchar *id = gtk_combo_box_get_active_id(GTK_COMBO_BOX(g_profiles));
241
 
    
242
 
    LOG_DEBUG("Selected profile:%s\n", name); 
243
 
 
244
 
    // Strings are equal?    
 
241
 
 
242
    LOG_DEBUG("Selected profile:%s\n", name);
 
243
 
 
244
    // Strings are equal?
245
245
    if (g_strcmp0(name, id) == 0) {
246
246
        // Combo: selection by using popup/down menu
247
 
        
 
247
 
248
248
        populate_fields(name);
249
 
    } 
250
 
    
 
249
    }
 
250
 
251
251
    g_free(name);
252
252
}
253
253
 
274
274
 
275
275
    GtkWidget *text_field = gtk_text_view_new();
276
276
    gtk_widget_show(text_field);
277
 
    
 
277
 
278
278
    gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW(text_field), GTK_WRAP_WORD_CHAR);
279
279
 
280
280
    GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_field));
301
301
 
302
302
    // Translators: This is a filename "test.xxx".
303
303
    parms->filename = g_strdup_printf(_("test.%s"), ext);
304
 
 
 
304
 
305
305
    // Get partial pipline for this profile_id
306
306
    parms->profile_str = g_strdup(pipe_text);
307
307
    parms->file_ext = g_strdup(ext);
309
309
    // Get audio source and device list
310
310
    gchar *audio_source = NULL;
311
311
    parms->dev_list = audio_sources_get_device_NEW(&audio_source);
312
 
    parms->source = audio_source; 
 
312
    parms->source = audio_source;
313
313
 
314
314
    GString *str = pipeline_create_command_str(parms);
315
315
 
323
323
    gchar *s3 = g_strdup_printf(_("# This command will record to %s file."), parms->filename);
324
324
 
325
325
    gchar *tmp_str = g_strdup_printf("%s\n%s\n%s\n\n", s1, s2, s3);
326
 
 
 
326
 
327
327
    str = g_string_prepend(str, tmp_str);
328
 
    
 
328
 
329
329
    g_free(s3);
330
330
    g_free(tmp_str);
331
331
 
332
 
    gchar *cmd = g_string_free(str, FALSE);   
 
332
    gchar *cmd = g_string_free(str, FALSE);
333
333
 
334
334
    // Show gst_launch command in a dialog
335
335
    show_cmd_dialog(cmd);
336
 
 
 
336
 
337
337
    g_free(old_name);
338
338
    g_free(name);
339
339
    g_free(ext);
340
340
    g_free(pipe_text);
341
341
 
342
342
    g_free(cmd);
343
 
 
 
343
 
344
344
    pipeline_free_parms(parms);
345
345
    parms = NULL;
346
346
}
347
347
 
348
348
static void show_cmd_clicked(GtkButton *button, gpointer user_data) {
349
 
    show_recording_command();   
 
349
    show_recording_command();
350
350
}
351
351
 
352
352
static void reset_clicked(GtkButton *button, gpointer user_data) {
353
 
    load_defaults();  
 
353
    load_defaults();
354
354
}
355
355
 
356
356
static void new_clicked(GtkButton *button, gpointer user_data) {
357
 
    new_profile();   
 
357
    new_profile();
358
358
}
359
359
 
360
360
static void delete_clicked(GtkButton *button, gpointer user_data) {
361
 
    delete_profile();   
 
361
    delete_profile();
362
362
}
363
363
 
364
364
static void save_clicked(GtkButton *button, gpointer user_data) {
365
 
    save_profile();   
 
365
    save_profile();
366
366
}
367
367
 
368
368
GtkWidget *page_to_edit_pipelines() {
369
369
 
370
370
    GtkWidget *vbox2 = gtk_box_new(GTK_ORIENTATION_VERTICAL, 3);
371
 
 
372
 
    // Create a GtkGrid. 
 
371
 
 
372
    // Create a GtkGrid.
373
373
    // Ref: http://developer.gnome.org/gtk3/3.3/GtkGrid.html
374
374
    GtkWidget *grid2 = gtk_grid_new();
375
 
    
 
375
 
376
376
    gtk_grid_set_column_homogeneous(GTK_GRID(grid2), TRUE);
377
377
    gtk_grid_set_column_spacing(GTK_GRID(grid2), 1);
378
378
 
390
390
    g_profiles = gtk_combo_box_text_new_with_entry();
391
391
    g_signal_connect(g_profiles, "changed", G_CALLBACK(title_changed), NULL);
392
392
    gtk_grid_attach_next_to(GTK_GRID(grid2), g_profiles, label0, GTK_POS_RIGHT, 3, 1);
393
 
 
 
393
 
394
394
    // Hidden field to hold selected g_profiles entry
395
395
    g_saved_id = gtk_entry_new();
396
 
    gtk_widget_hide(g_saved_id); 
 
396
    gtk_widget_hide(g_saved_id);
397
397
 
398
398
    // File extension.
399
 
 
 
399
 
400
400
    // Translators: This is a GUI label. Keep it short.
401
401
    label0 = gtk_label_new(_("File extension:"));
402
402
    gtk_widget_set_halign(label0, GTK_ALIGN_START);
413
413
    gtk_grid_attach(GTK_GRID(grid2), label0, 0, 2, 1, 1);
414
414
 
415
415
    g_pipe_text = gtk_text_view_new();
416
 
    
 
416
 
417
417
    gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(g_pipe_text), GTK_WRAP_WORD);
418
 
    
 
418
 
419
419
    gtk_box_pack_start(GTK_BOX(vbox2), g_pipe_text, TRUE, TRUE, 0);
420
420
 
421
421
    GtkWidget *vbox3 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 3);
426
426
 
427
427
    // Translators: Button label in Additional settings -> Recording commands.
428
428
    GtkWidget *button0 = gtk_button_new_with_label(_("Show cmd"));
429
 
    g_signal_connect(button0, "clicked", G_CALLBACK(show_cmd_clicked), NULL);        
 
429
    g_signal_connect(button0, "clicked", G_CALLBACK(show_cmd_clicked), NULL);
430
430
    gtk_box_pack_start(GTK_BOX(box0), button0, TRUE, FALSE, 0);
431
431
 
432
432
    // Translators: Button label in Additional settings -> Recording commands.
433
433
    button0 = gtk_button_new_with_label(_("Reset"));
434
 
    g_signal_connect(button0, "clicked", G_CALLBACK(reset_clicked), NULL);    
 
434
    g_signal_connect(button0, "clicked", G_CALLBACK(reset_clicked), NULL);
435
435
    gtk_box_pack_start(GTK_BOX(box0), button0, TRUE, FALSE, 0);
436
436
 
437
437
    gtk_box_pack_start(GTK_BOX(vbox3), box0, FALSE, FALSE, 0);
438
438
 
439
439
    box0 = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL);
440
440
    gtk_widget_show(box0);
441
 
    
 
441
 
442
442
    gtk_button_box_set_layout(GTK_BUTTON_BOX(box0), GTK_BUTTONBOX_END);
443
443
 
444
444
    // Translators: Button label in Additional settings -> Recording commands.
445
445
    button0 = gtk_button_new_with_label(_("New"));
446
 
    g_signal_connect(button0, "clicked", G_CALLBACK(new_clicked), NULL);    
 
446
    g_signal_connect(button0, "clicked", G_CALLBACK(new_clicked), NULL);
447
447
    gtk_box_pack_start(GTK_BOX(box0), button0, TRUE, FALSE, 0);
448
448
 
449
449
    // Translators: Button label in Additional settings -> Recording commands.
450
450
    button0 = gtk_button_new_with_label(_("Delete"));
451
 
    g_signal_connect(button0, "clicked", G_CALLBACK(delete_clicked), NULL);        
 
451
    g_signal_connect(button0, "clicked", G_CALLBACK(delete_clicked), NULL);
452
452
    gtk_box_pack_start(GTK_BOX(box0), button0, TRUE, FALSE, 0);
453
453
 
454
454
    // Translators: Button label in Additional settings -> Recording commands.
455
455
    button0 = gtk_button_new_with_label(_("Save"));
456
 
    g_signal_connect(button0, "clicked", G_CALLBACK(save_clicked), NULL);    
 
456
    g_signal_connect(button0, "clicked", G_CALLBACK(save_clicked), NULL);
457
457
    gtk_box_pack_start(GTK_BOX(box0), button0, TRUE, FALSE, 0);
458
458
 
459
459
    gtk_box_pack_end(GTK_BOX(vbox3), box0, FALSE, FALSE, 0);
460
460
 
461
461
    gtk_box_pack_start(GTK_BOX(vbox2), vbox3, FALSE, TRUE, 0);
462
 
    
 
462
 
463
463
    // Fill text combo with profiles names/titles
464
464
    get_profiles();
465
465
 
474
474
    gboolean found =  find_row(str_value, &iter);
475
475
 
476
476
    // Select it
477
 
    if (found) {    
 
477
    if (found) {
478
478
        gtk_combo_box_set_active_iter(GTK_COMBO_BOX(g_profiles), &iter);
479
479
 
480
480
    } else {
485
485
    g_free(str_value);
486
486
 
487
487
    return vbox2;
488
 
    
 
488
 
489
489
}
490
490
 
491
491