~ubuntu-branches/ubuntu/vivid/gnomeradio/vivid-201504031246

« back to all changes in this revision

Viewing changes to .pc/gnomeradio-media_types.patch/src/record.c

  • Committer: Package Import Robot
  • Author(s): POJAR GEORGE
  • Date: 2013-06-15 15:14:16 UTC
  • Revision ID: package-import@ubuntu.com-20130615151416-nivhws9zlhdocegi
Tags: 1.8-2ubuntu14
* debian/patches/gnomeradio-thread_safe.patch: Replace strtok() with
  strtok_r(), readdir() with readdir_r() and localtime() with localtime_r()
  for thread safe.
* Improved mixer error message in debian/patches/gnomeradio-alsamixer.patch.
* Moved changes applied to src/record.c from gnomeradio-media_types.patch to
  gnomeradio-record_information.patch.
  - Improved error message when getting information for file.
* debian/{control, rules}: Enable PIE hardening.
* Refresh patches:
  - debian/patches/gnomeradio-gstreamer-1.0.patch
  - debian/patches/gnomeradio-keyboard_shortcuts.patch
  - debian/patches/gnomeradio-non_modal.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* record.c
2
 
 *
3
 
 * Copyright (C) 2001 J�rgen Scheibengruber
4
 
 *
5
 
 * This program is free software; you can redistribute it and/or 
6
 
 * modify it under the terms of the GNU General Public License as 
7
 
 * published by the Free Software Foundation; either version 2 of the
8
 
 * License, or (at your option) any later version.
9
 
 *
10
 
 * This program is distributed in the hope that it will be useful,
11
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 * GNU General Public License for more details.
14
 
 *
15
 
 * You should have received a copy of the GNU General Public License
16
 
 * along with this program; if not, write to the Free Software
17
 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18
 
 * USA
19
 
 */
20
 
 
21
 
/*** the recording functionality */
22
 
 
23
 
#include <config.h>
24
 
 
25
 
#include <sys/types.h>
26
 
#include <signal.h>
27
 
#include <gtk/gtk.h>
28
 
#include <glib/gi18n.h>
29
 
#include "gui.h"
30
 
#include "rec_tech.h"
31
 
#include "prefs.h"
32
 
 
33
 
static int timeout_id = -1;
34
 
static GtkWidget *file_lbl, *type_lbl, *size_lbl, *length_lbl;
35
 
static GtkWidget *status_dialog;
36
 
 
37
 
extern GtkWidget *level;
38
 
 
39
 
void close_status_window(void)
40
 
{
41
 
        if (timeout_id >= 0)
42
 
        {
43
 
                g_source_remove(timeout_id);
44
 
                timeout_id = -1;
45
 
        }
46
 
 
47
 
        if (status_dialog)
48
 
                gtk_widget_destroy(GTK_WIDGET(status_dialog));
49
 
        status_dialog = NULL;
50
 
        
51
 
        tray_icon_items_set_sensible(TRUE);
52
 
        recording_set_sensible(TRUE);
53
 
}
54
 
 
55
 
static char *seconds_to_full_string (guint seconds)
56
 
{
57
 
        long days, hours, minutes;
58
 
        char *time = NULL;
59
 
        const char *minutefmt;
60
 
        const char *hourfmt;
61
 
        const char *secondfmt;
62
 
 
63
 
        days    = seconds / (60 * 60 * 24);
64
 
        hours   = (seconds / (60 * 60));
65
 
        minutes = (seconds / 60) - ((days * 24 * 60) + (hours * 60));
66
 
        seconds = seconds % 60;
67
 
 
68
 
        minutefmt = ngettext ("%ld minute", "%ld minutes", minutes);
69
 
        hourfmt = ngettext ("%ld hour", "%ld hours", hours);
70
 
        secondfmt = ngettext ("%ld second", "%ld seconds", seconds);
71
 
 
72
 
        if (hours > 0) {
73
 
                if (minutes > 0)
74
 
                        if (seconds > 0) {
75
 
                                char *fmt;
76
 
                                /* Translators: the format is "X hours X minutes X seconds" */
77
 
                                fmt = g_strdup_printf (_("%s %s %s"), hourfmt, minutefmt, secondfmt);
78
 
                                time = g_strdup_printf (fmt, hours, minutes, seconds);
79
 
                                g_free (fmt);
80
 
                        } else {
81
 
                                char *fmt;
82
 
                                /* Translators: the format is "X hours X minutes" */
83
 
                                fmt = g_strdup_printf (_("%s %s"), hourfmt, minutefmt);
84
 
                                time = g_strdup_printf (fmt, hours, minutes);
85
 
                                g_free (fmt);
86
 
                        }
87
 
                else
88
 
                        if (seconds > 0) {
89
 
                                char *fmt;
90
 
                                /* Translators: the format is "X minutes X seconds" */
91
 
                                fmt = g_strdup_printf (_("%s %s"), minutefmt, secondfmt);
92
 
                                time = g_strdup_printf (fmt, minutes, seconds);
93
 
                                g_free (fmt);
94
 
                        } else {
95
 
                                time = g_strdup_printf (minutefmt, minutes);
96
 
                        }
97
 
        } else {
98
 
                if (minutes > 0) {
99
 
                        if (seconds > 0) {
100
 
                                char *fmt;
101
 
                                /* Translators: the format is "X minutes X seconds" */
102
 
                                fmt = g_strdup_printf (_("%s %s"), minutefmt, secondfmt);
103
 
                                time = g_strdup_printf (fmt, minutes, seconds);
104
 
                                g_free (fmt);
105
 
                        } else {
106
 
                                time = g_strdup_printf (minutefmt, minutes);
107
 
                        }
108
 
 
109
 
                } else {
110
 
                        time = g_strdup_printf (secondfmt, seconds);
111
 
                }
112
 
        }
113
 
 
114
 
        return time;
115
 
}
116
 
 
117
 
static gboolean timeout_cb(gpointer data)
118
 
{
119
 
        Recording *recording = data;
120
 
        gint s;
121
 
        gchar *size = NULL;
122
 
        gchar *name;
123
 
        gchar *utf8_name = NULL;
124
 
        GError *error = NULL;
125
 
        GFile *file;
126
 
        GFileInfo *file_info;
127
 
        const gchar *content_type;
128
 
        gchar *description;
129
 
        gchar *mime;
130
 
        gchar *type;
131
 
 
132
 
        g_assert(recording);    
133
 
        
134
 
        if (!gtk_widget_get_visible(status_dialog))
135
 
                gtk_widget_show_all(status_dialog);
136
 
        
137
 
        /* name */
138
 
        name = g_path_get_basename(recording->filename);
139
 
        utf8_name = g_filename_to_utf8 (name, -1, NULL, NULL, NULL);
140
 
        gtk_label_set_text(GTK_LABEL(file_lbl), utf8_name);
141
 
        g_free (name);
142
 
 
143
 
        /* type */
144
 
        file = g_file_new_for_path(recording->filename);
145
 
        file_info = g_file_query_info(file,
146
 
                                      G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
147
 
                                      G_FILE_QUERY_INFO_NONE,
148
 
                                      NULL,
149
 
                                      &error);
150
 
 
151
 
        if (error == NULL) {
152
 
                content_type = g_file_info_get_content_type(file_info);
153
 
                description = g_content_type_get_description(content_type);
154
 
                mime = g_content_type_get_mime_type(content_type);
155
 
                type = g_strconcat(description, " (", mime, ")", NULL);
156
 
                gtk_label_set_text(GTK_LABEL(type_lbl), type);
157
 
 
158
 
                g_free(description);
159
 
                g_free(type);
160
 
        } else  {
161
 
                g_message ("%s", error->message);
162
 
                g_error_free(error);
163
 
 
164
 
                return FALSE;
165
 
        }
166
 
 
167
 
        g_object_unref(file_info);
168
 
        g_object_unref(file);
169
 
 
170
 
        /* size */
171
 
        s = get_file_size(recording->filename);
172
 
        if (s > 0) {
173
 
                size = g_format_size_full(s, G_FORMAT_SIZE_LONG_FORMAT);
174
 
        } else {
175
 
                close_status_window();
176
 
                recording_stop(recording);
177
 
 
178
 
                char* text;
179
 
                text = g_strdup_printf(_("Error writing to file \"%s\"!"), utf8_name);
180
 
                char* detail;
181
 
                detail = g_strdup_printf("Please check for sufficient write file permissions.");
182
 
                show_error_message(text, detail);
183
 
                g_free (utf8_name);
184
 
                g_free(text);
185
 
                g_free(detail);
186
 
 
187
 
                return FALSE;
188
 
        }       
189
 
 
190
 
        /* length */
191
 
        GstElement *pipeline;
192
 
        gint64 val = -1;
193
 
        gint secs;
194
 
 
195
 
        pipeline = recording->pipeline;
196
 
 
197
 
        if (gst_element_query_position (pipeline, GST_FORMAT_TIME, &val) && val != -1) {
198
 
                gchar* length;
199
 
                secs = val / GST_SECOND;
200
 
 
201
 
                length = seconds_to_full_string(secs);
202
 
                gtk_label_set_text(GTK_LABEL(length_lbl), length);
203
 
                g_free(length);
204
 
        }
205
 
 
206
 
        gtk_label_set_text(GTK_LABEL(size_lbl), size);
207
 
        g_free(size);
208
 
        
209
 
        return TRUE;
210
 
}       
211
 
        
212
 
void run_status_window(Recording *recording)
213
 
{
214
 
        timeout_id = g_timeout_add(500, (GSourceFunc) timeout_cb, recording);
215
 
}
216
 
 
217
 
void stop_rec_button_clicked_cb(GtkButton *button, gpointer data)
218
 
{
219
 
        Recording *recording = data;
220
 
        close_status_window();
221
 
        recording_stop(recording);
222
 
}               
223
 
 
224
 
static gint delete_event_cb(GtkWidget* window, GdkEventAny* e, gpointer data)
225
 
{
226
 
        stop_rec_button_clicked_cb(NULL, data);
227
 
        return TRUE;
228
 
}
229
 
 
230
 
GtkWidget* record_status_window(Recording *recording)
231
 
{
232
 
        GtkWidget *btn_label, *btn_pixmap, *button;
233
 
        GtkWidget *vbox, *btn_box, *hbox;
234
 
        GtkWidget *f_lbl, *t_lbl, *s_lbl, *l_lbl;
235
 
        GtkWidget *grid, *r_grid;
236
 
        GtkWidget *title;
237
 
        GtkWidget *image;
238
 
        GtkWidget *level_box;
239
 
        GtkWidget *expander;
240
 
        char *text, *str;
241
 
 
242
 
        status_dialog = gtk_window_new(GTK_WINDOW_TOPLEVEL);
243
 
        gtk_window_set_title(GTK_WINDOW(status_dialog),_("Gnomeradio recording status"));
244
 
        gtk_window_set_resizable(GTK_WINDOW(status_dialog), FALSE);
245
 
 
246
 
        vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 12);
247
 
        gtk_container_set_border_width(GTK_CONTAINER(vbox), 8);
248
 
 
249
 
        grid = gtk_grid_new();
250
 
        gtk_grid_set_row_spacing(GTK_GRID(grid), 5);
251
 
        gtk_grid_set_column_spacing(GTK_GRID(grid), 15);
252
 
        gtk_container_set_border_width(GTK_CONTAINER(grid), 5);
253
 
 
254
 
        image = gtk_image_new_from_icon_name("gnomeradio", GTK_ICON_SIZE_DIALOG);
255
 
        gtk_image_set_pixel_size(GTK_IMAGE(image), 42);
256
 
        gtk_widget_set_valign(image, GTK_ALIGN_START);
257
 
        gtk_grid_attach(GTK_GRID(grid), image, 0, 0, 1, 3);
258
 
 
259
 
        str = g_strdup_printf(_("Recording from station %s"), recording->station);
260
 
        text = g_strdup_printf("<big><b>%s</b></big>", str);
261
 
        g_free(str);
262
 
        title = gtk_label_new(text);
263
 
        g_free(text);
264
 
        gtk_widget_set_halign(title, GTK_ALIGN_START);
265
 
        gtk_label_set_use_markup(GTK_LABEL(title), TRUE);
266
 
        gtk_grid_attach(GTK_GRID(grid), title, 1, 0, 1, 1);
267
 
 
268
 
        level_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
269
 
        level = gtk_progress_bar_new();
270
 
        gtk_box_pack_start(GTK_BOX(level_box), level, FALSE, TRUE, 0);
271
 
        gtk_grid_attach(GTK_GRID(grid), level_box, 1, 1, 1, 1);
272
 
 
273
 
        expander = gtk_expander_new(_("Details"));
274
 
        gtk_grid_attach(GTK_GRID(grid), expander, 1, 2, 1, 1);
275
 
 
276
 
        r_grid = gtk_grid_new();
277
 
        gtk_grid_set_row_spacing(GTK_GRID(r_grid), 5);
278
 
        gtk_grid_set_column_spacing(GTK_GRID(r_grid), 15);
279
 
        gtk_container_set_border_width(GTK_CONTAINER(r_grid), 5);
280
 
 
281
 
        f_lbl = gtk_label_new(_("Name:"));
282
 
        gtk_widget_set_halign(f_lbl, GTK_ALIGN_START);
283
 
        gtk_grid_attach(GTK_GRID(r_grid), f_lbl, 0, 0, 1, 1);
284
 
 
285
 
        t_lbl = gtk_label_new(_("Type:"));
286
 
        gtk_widget_set_halign(t_lbl, GTK_ALIGN_START);
287
 
        gtk_grid_attach(GTK_GRID(r_grid), t_lbl, 0, 1, 1, 1);
288
 
 
289
 
        s_lbl = gtk_label_new(_("Size:"));
290
 
        gtk_widget_set_halign(s_lbl, GTK_ALIGN_START);
291
 
        gtk_grid_attach(GTK_GRID(r_grid), s_lbl, 0, 2, 1, 1);
292
 
 
293
 
        l_lbl = gtk_label_new(_("Length:"));
294
 
        gtk_widget_set_halign(l_lbl, GTK_ALIGN_START);
295
 
        gtk_grid_attach(GTK_GRID(r_grid), l_lbl, 0, 3, 1, 1);
296
 
 
297
 
        file_lbl = gtk_label_new(NULL);
298
 
        gtk_label_set_ellipsize(GTK_LABEL(file_lbl), PANGO_ELLIPSIZE_START);
299
 
        gtk_widget_set_halign(file_lbl, GTK_ALIGN_START);
300
 
        gtk_grid_attach(GTK_GRID(r_grid), file_lbl, 1, 0, 1, 1);
301
 
 
302
 
        type_lbl = gtk_label_new(NULL);
303
 
        gtk_widget_set_halign(type_lbl, GTK_ALIGN_START);
304
 
        gtk_grid_attach(GTK_GRID(r_grid), type_lbl, 1, 1, 1, 1);
305
 
 
306
 
        size_lbl = gtk_label_new(NULL);
307
 
        gtk_widget_set_halign(size_lbl, GTK_ALIGN_START);
308
 
        gtk_grid_attach(GTK_GRID(r_grid), size_lbl, 1, 2, 1, 1);
309
 
 
310
 
        length_lbl = gtk_label_new(NULL);
311
 
        gtk_widget_set_halign(length_lbl, GTK_ALIGN_START);
312
 
        gtk_grid_attach(GTK_GRID(r_grid), length_lbl, 1, 3, 1, 1);
313
 
 
314
 
        gtk_container_add(GTK_CONTAINER(expander), r_grid);
315
 
 
316
 
        button = gtk_button_new();
317
 
        btn_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
318
 
        btn_label = gtk_label_new(_("Stop Recording"));
319
 
        btn_pixmap = gtk_image_new_from_stock(GTK_STOCK_STOP, GTK_ICON_SIZE_BUTTON);
320
 
        
321
 
        gtk_box_pack_start (GTK_BOX(btn_box), btn_pixmap, FALSE, FALSE, 2);
322
 
        gtk_box_pack_start (GTK_BOX(btn_box), btn_label, FALSE, FALSE, 2);
323
 
 
324
 
        gtk_container_add(GTK_CONTAINER(button), btn_box);
325
 
        
326
 
        hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
327
 
        gtk_box_pack_end (GTK_BOX(hbox), button, TRUE, FALSE, 0);
328
 
        
329
 
        gtk_box_pack_start(GTK_BOX(vbox), grid, TRUE, TRUE, 0);
330
 
        gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
331
 
 
332
 
        gtk_container_add(GTK_CONTAINER(status_dialog), vbox);
333
 
        gtk_widget_grab_focus (button);
334
 
 
335
 
        g_signal_connect(G_OBJECT(status_dialog), "delete_event", G_CALLBACK(delete_event_cb), recording);
336
 
        g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(stop_rec_button_clicked_cb), recording);
337
 
        g_signal_connect(G_OBJECT(status_dialog), "key-press-event", G_CALLBACK(key_press_event_cb), recording);
338
 
 
339
 
        gtk_window_set_position(GTK_WINDOW(status_dialog), GTK_WIN_POS_CENTER);
340
 
 
341
 
        return status_dialog;
342
 
}