~ubuntu-branches/ubuntu/utopic/gnomeradio/utopic

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): POJAR GEORGE
  • Date: 2013-12-24 10:38:24 UTC
  • Revision ID: package-import@ubuntu.com-20131224103824-ud5r2yrtyblv9ew6
Tags: 1.8-2ubuntu26
* debian/patches/gnomeradio-g_object.patch: Removed useless calls to the
  G_OBJECT() macro. (LP: #1267306)
* Updated debian/patches/gnomeradio-about.patch: Update COPYING file with
  latest versions from gnu.org. (LP: #1266203)
* Updated debian/patches/gnomeradio-gtk_stock.patch: UI make it more sleek, 
  remove relief from the UI buttons. (LP: #1265154)
* Updated debian/patches/gnomeradio-gtk_application.patch: Make the main
  window a GtkApplicationWindow.
* Updated debian/patches/gnomeradio-ngettext.patch: Fix localization, use
  g_dngettext instead of ngettext.
* Updated debian/patches/gnomeradio-record_information.patch: Use GDateTime
  instead of time_t.
* Moved changes from debian/patches/gnomeradio-thread_safe.patch to
  debian/patches/gnomeradio-alsa.patch and removed it as result.
* debian/control: Updated to Standards-Version 3.9.5, no changes needed.

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
#include "trayicon.h"
 
33
 
 
34
extern GtkWidget *level;
 
35
 
 
36
static GtkWidget *status_dialog;
 
37
static GtkWidget *file_lbl;
 
38
static GtkWidget *type_lbl;
 
39
static GtkWidget *size_lbl;
 
40
static GtkWidget *length_lbl;
 
41
 
 
42
static int timeout_id = -1;
 
43
 
 
44
void close_status_window(void)
 
45
{
 
46
        if (timeout_id >= 0) {
 
47
                g_source_remove (timeout_id);
 
48
                timeout_id = -1;
 
49
        }
 
50
 
 
51
        if (status_dialog)
 
52
                gtk_widget_destroy(GTK_WIDGET(status_dialog));
 
53
        status_dialog = NULL;
 
54
        
 
55
        tray_menu_items_set_sensible(TRUE);
 
56
        recording_set_sensible(TRUE);
 
57
}
 
58
 
 
59
static char *seconds_to_full_string (guint seconds)
 
60
{
 
61
        long days, hours, minutes;
 
62
        char *time = NULL;
 
63
        const char *minutefmt;
 
64
        const char *hourfmt;
 
65
        const char *secondfmt;
 
66
 
 
67
        days    = seconds / (60 * 60 * 24);
 
68
        hours   = (seconds / (60 * 60));
 
69
        minutes = (seconds / 60) - ((days * 24 * 60) + (hours * 60));
 
70
        seconds = seconds % 60;
 
71
 
 
72
        minutefmt = ngettext ("%ld minute", "%ld minutes", minutes);
 
73
        hourfmt = ngettext ("%ld hour", "%ld hours", hours);
 
74
        secondfmt = ngettext ("%ld second", "%ld seconds", seconds);
 
75
 
 
76
        if (hours > 0) {
 
77
                if (minutes > 0)
 
78
                        if (seconds > 0) {
 
79
                                char *fmt;
 
80
                                /* Translators: the format is "X hours X minutes X seconds" */
 
81
                                fmt = g_strdup_printf (_("%s %s %s"), hourfmt, minutefmt, secondfmt);
 
82
                                time = g_strdup_printf (fmt, hours, minutes, seconds);
 
83
                                g_free (fmt);
 
84
                        } else {
 
85
                                char *fmt;
 
86
                                /* Translators: the format is "X hours X minutes" */
 
87
                                fmt = g_strdup_printf (_("%s %s"), hourfmt, minutefmt);
 
88
                                time = g_strdup_printf (fmt, hours, minutes);
 
89
                                g_free (fmt);
 
90
                        }
 
91
                else
 
92
                        if (seconds > 0) {
 
93
                                char *fmt;
 
94
                                /* Translators: the format is "X minutes X seconds" */
 
95
                                fmt = g_strdup_printf (_("%s %s"), minutefmt, secondfmt);
 
96
                                time = g_strdup_printf (fmt, minutes, seconds);
 
97
                                g_free (fmt);
 
98
                        } else {
 
99
                                time = g_strdup_printf (minutefmt, minutes);
 
100
                        }
 
101
        } else {
 
102
                if (minutes > 0) {
 
103
                        if (seconds > 0) {
 
104
                                char *fmt;
 
105
                                /* Translators: the format is "X minutes X seconds" */
 
106
                                fmt = g_strdup_printf (_("%s %s"), minutefmt, secondfmt);
 
107
                                time = g_strdup_printf (fmt, minutes, seconds);
 
108
                                g_free (fmt);
 
109
                        } else {
 
110
                                time = g_strdup_printf (minutefmt, minutes);
 
111
                        }
 
112
 
 
113
                } else {
 
114
                        time = g_strdup_printf (secondfmt, seconds);
 
115
                }
 
116
        }
 
117
 
 
118
        return time;
 
119
}
 
120
 
 
121
static gboolean timeout_cb (gpointer data)
 
122
{
 
123
        Recording *recording = data;
 
124
 
 
125
        g_assert (recording);
 
126
 
 
127
        if (!gtk_widget_get_visible (status_dialog))
 
128
                gtk_widget_show_all (status_dialog);
 
129
 
 
130
        GFileInfo *info;
 
131
 
 
132
        info = g_file_query_info (recording->file,
 
133
                                  G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME ","
 
134
                                  G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE ","
 
135
                                  G_FILE_ATTRIBUTE_STANDARD_SIZE,
 
136
                                  G_FILE_QUERY_INFO_NONE,
 
137
                                  NULL,
 
138
                                  NULL);
 
139
 
 
140
        if (info != NULL) {
 
141
                const gchar *display_name, *content_type;
 
142
                gchar *description, *mime, *type, *size;
 
143
                gint64 file_size;
 
144
 
 
145
                display_name = g_file_info_get_display_name (info);
 
146
 
 
147
                gtk_label_set_text (GTK_LABEL (file_lbl), display_name);
 
148
 
 
149
                content_type = g_file_info_get_content_type (info);
 
150
                description = g_content_type_get_description (content_type);
 
151
                mime = g_content_type_get_mime_type (content_type);
 
152
                type = g_strdup_printf ("%s (%s)", description, mime);
 
153
 
 
154
                gtk_label_set_text (GTK_LABEL (type_lbl), type);
 
155
 
 
156
                g_free (description);
 
157
                g_free (mime);
 
158
                g_free (type);
 
159
 
 
160
                file_size = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_STANDARD_SIZE);
 
161
 
 
162
                size = g_format_size_full (file_size, G_FORMAT_SIZE_LONG_FORMAT);
 
163
                gtk_label_set_text (GTK_LABEL (size_lbl), size);
 
164
 
 
165
                g_free (size);
 
166
 
 
167
                g_object_unref (info);
 
168
 
 
169
                gint64 position;
 
170
 
 
171
                if (gst_element_query_position (recording->pipeline, GST_FORMAT_TIME, &position)) {
 
172
                        gchar* length;
 
173
                        gint secs;
 
174
 
 
175
                        secs = position / GST_SECOND;
 
176
                        length = seconds_to_full_string (secs);
 
177
 
 
178
                        gtk_label_set_text (GTK_LABEL (length_lbl), length);
 
179
 
 
180
                        g_free (length);
 
181
                }
 
182
        }
 
183
        
 
184
        return TRUE;
 
185
}       
 
186
        
 
187
void run_status_window(Recording *recording)
 
188
{
 
189
        timeout_id = g_timeout_add(500, (GSourceFunc) timeout_cb, recording);
 
190
}
 
191
 
 
192
void stop_rec_button_clicked_cb(GtkButton *button, gpointer data)
 
193
{
 
194
        Recording *recording = data;
 
195
        close_status_window();
 
196
        recording_stop(recording);
 
197
}               
 
198
 
 
199
static gint delete_event_cb(GtkWidget* window, GdkEventAny* e, gpointer data)
 
200
{
 
201
        stop_rec_button_clicked_cb(NULL, data);
 
202
        return TRUE;
 
203
}
 
204
 
 
205
GtkWidget* record_status_window(Recording *recording)
 
206
{
 
207
        GtkWidget *vbox;
 
208
        GtkWidget *grid;
 
209
        GtkWidget *image;
 
210
        GtkWidget *box;
 
211
        GtkWidget *label;
 
212
        GtkWidget *expander;
 
213
        GtkWidget *button;
 
214
        gchar *text, *markup;
 
215
 
 
216
        status_dialog = gtk_window_new(GTK_WINDOW_TOPLEVEL);
 
217
        gtk_window_set_title(GTK_WINDOW(status_dialog),_("Gnomeradio recording status"));
 
218
        gtk_window_set_resizable(GTK_WINDOW(status_dialog), FALSE);
 
219
 
 
220
        vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 12);
 
221
        gtk_container_set_border_width(GTK_CONTAINER(vbox), 8);
 
222
 
 
223
        grid = gtk_grid_new();
 
224
        gtk_grid_set_row_spacing(GTK_GRID(grid), 5);
 
225
        gtk_grid_set_column_spacing(GTK_GRID(grid), 15);
 
226
        gtk_container_set_border_width(GTK_CONTAINER(grid), 5);
 
227
 
 
228
        image = gtk_image_new_from_icon_name("gnomeradio", GTK_ICON_SIZE_DIALOG);
 
229
        gtk_image_set_pixel_size(GTK_IMAGE(image), 42);
 
230
        gtk_widget_set_valign(image, GTK_ALIGN_START);
 
231
        gtk_grid_attach(GTK_GRID(grid), image, 0, 0, 1, 3);
 
232
 
 
233
        label = gtk_label_new (NULL);
 
234
        gtk_widget_set_halign (label, GTK_ALIGN_START);
 
235
        text = g_markup_printf_escaped (_("Recording from station %s"), recording->station);
 
236
        markup = g_strdup_printf ("<span size=\"larger\" weight=\"bold\">%s</span>", text);
 
237
        gtk_label_set_markup (GTK_LABEL (label), markup);
 
238
        g_free (text);
 
239
        g_free (markup);
 
240
        gtk_grid_attach(GTK_GRID(grid), label, 1, 0, 1, 1);
 
241
 
 
242
        box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
 
243
        level = gtk_progress_bar_new();
 
244
        gtk_box_pack_start (GTK_BOX (box), level, FALSE, TRUE, 0);
 
245
        gtk_grid_attach (GTK_GRID (grid), box, 1, 1, 1, 1);
 
246
 
 
247
        expander = gtk_expander_new(_("Details"));
 
248
        gtk_grid_attach(GTK_GRID(grid), expander, 1, 2, 1, 1);
 
249
 
 
250
        gtk_box_pack_start (GTK_BOX(vbox), grid, TRUE, TRUE, 0);
 
251
 
 
252
        grid = gtk_grid_new ();
 
253
        gtk_grid_set_row_spacing (GTK_GRID (grid), 5);
 
254
        gtk_grid_set_column_spacing (GTK_GRID (grid), 15);
 
255
        gtk_container_set_border_width (GTK_CONTAINER (grid), 5);
 
256
 
 
257
        label = gtk_label_new (_("Name:"));
 
258
        gtk_widget_set_halign (label, GTK_ALIGN_START);
 
259
        gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1);
 
260
 
 
261
        label = gtk_label_new (_("Type:"));
 
262
        gtk_widget_set_halign (label, GTK_ALIGN_START);
 
263
        gtk_grid_attach (GTK_GRID (grid), label, 0, 1, 1, 1);
 
264
 
 
265
        label = gtk_label_new (_("Size:"));
 
266
        gtk_widget_set_halign (label, GTK_ALIGN_START);
 
267
        gtk_grid_attach (GTK_GRID (grid), label, 0, 2, 1, 1);
 
268
 
 
269
        label = gtk_label_new (_("Length:"));
 
270
        gtk_widget_set_halign(label, GTK_ALIGN_START);
 
271
        gtk_grid_attach (GTK_GRID (grid), label, 0, 3, 1, 1);
 
272
 
 
273
        file_lbl = gtk_label_new(NULL);
 
274
        gtk_label_set_ellipsize(GTK_LABEL(file_lbl), PANGO_ELLIPSIZE_START);
 
275
        gtk_widget_set_halign(file_lbl, GTK_ALIGN_START);
 
276
        gtk_grid_attach (GTK_GRID (grid), file_lbl, 1, 0, 1, 1);
 
277
 
 
278
        type_lbl = gtk_label_new(NULL);
 
279
        gtk_widget_set_halign(type_lbl, GTK_ALIGN_START);
 
280
        gtk_grid_attach (GTK_GRID (grid), type_lbl, 1, 1, 1, 1);
 
281
 
 
282
        size_lbl = gtk_label_new(NULL);
 
283
        gtk_widget_set_halign(size_lbl, GTK_ALIGN_START);
 
284
        gtk_grid_attach (GTK_GRID (grid), size_lbl, 1, 2, 1, 1);
 
285
 
 
286
        length_lbl = gtk_label_new(NULL);
 
287
        gtk_widget_set_halign(length_lbl, GTK_ALIGN_START);
 
288
        gtk_grid_attach (GTK_GRID (grid), length_lbl, 1, 3, 1, 1);
 
289
 
 
290
        gtk_container_add (GTK_CONTAINER (expander), grid);
 
291
 
 
292
        box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
 
293
 
 
294
        button = gtk_button_new ();
 
295
        label = gtk_label_new (_("Stop Recording"));
 
296
        image = gtk_image_new_from_icon_name ("process-stop", GTK_ICON_SIZE_BUTTON);
 
297
        
 
298
        gtk_box_pack_start (GTK_BOX(box), image, FALSE, FALSE, 2);
 
299
        gtk_box_pack_start (GTK_BOX(box), label, FALSE, FALSE, 2);
 
300
 
 
301
        gtk_container_add(GTK_CONTAINER(button), box);
 
302
        
 
303
        box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
 
304
 
 
305
        gtk_box_pack_end (GTK_BOX (box), button, TRUE, FALSE, 0);
 
306
        gtk_box_pack_start (GTK_BOX(vbox), box, FALSE, FALSE, 0);
 
307
 
 
308
        gtk_container_add(GTK_CONTAINER(status_dialog), vbox);
 
309
        gtk_widget_grab_focus (button);
 
310
 
 
311
        g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(stop_rec_button_clicked_cb), recording);
 
312
        g_signal_connect(G_OBJECT(status_dialog), "delete_event", G_CALLBACK(delete_event_cb), recording);
 
313
        g_signal_connect(G_OBJECT(status_dialog), "key-press-event", G_CALLBACK(key_press_event_cb), recording);
 
314
 
 
315
        gtk_window_set_position(GTK_WINDOW(status_dialog), GTK_WIN_POS_CENTER);
 
316
 
 
317
        return status_dialog;
 
318
}