3
* Copyright (C) 2001 J�rgen Scheibengruber
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.
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.
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
21
/*** the recording functionality */
25
#include <sys/types.h>
28
#include <glib/gi18n.h>
34
extern GtkWidget *level;
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;
42
static int timeout_id = -1;
44
void close_status_window(void)
46
if (timeout_id >= 0) {
47
g_source_remove (timeout_id);
52
gtk_widget_destroy(GTK_WIDGET(status_dialog));
55
tray_menu_items_set_sensible(TRUE);
56
recording_set_sensible(TRUE);
59
static char *seconds_to_full_string (guint seconds)
61
long days, hours, minutes;
63
const char *minutefmt;
65
const char *secondfmt;
67
days = seconds / (60 * 60 * 24);
68
hours = (seconds / (60 * 60));
69
minutes = (seconds / 60) - ((days * 24 * 60) + (hours * 60));
70
seconds = seconds % 60;
72
minutefmt = ngettext ("%ld minute", "%ld minutes", minutes);
73
hourfmt = ngettext ("%ld hour", "%ld hours", hours);
74
secondfmt = ngettext ("%ld second", "%ld seconds", seconds);
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);
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);
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);
99
time = g_strdup_printf (minutefmt, minutes);
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);
110
time = g_strdup_printf (minutefmt, minutes);
114
time = g_strdup_printf (secondfmt, seconds);
121
static gboolean timeout_cb (gpointer data)
123
Recording *recording = data;
125
g_assert (recording);
127
if (!gtk_widget_get_visible (status_dialog))
128
gtk_widget_show_all (status_dialog);
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,
141
const gchar *display_name, *content_type;
142
gchar *description, *mime, *type, *size;
145
display_name = g_file_info_get_display_name (info);
147
gtk_label_set_text (GTK_LABEL (file_lbl), display_name);
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);
154
gtk_label_set_text (GTK_LABEL (type_lbl), type);
156
g_free (description);
160
file_size = g_file_info_get_attribute_uint64 (info, G_FILE_ATTRIBUTE_STANDARD_SIZE);
162
size = g_format_size_full (file_size, G_FORMAT_SIZE_LONG_FORMAT);
163
gtk_label_set_text (GTK_LABEL (size_lbl), size);
167
g_object_unref (info);
171
if (gst_element_query_position (recording->pipeline, GST_FORMAT_TIME, &position)) {
175
secs = position / GST_SECOND;
176
length = seconds_to_full_string (secs);
178
gtk_label_set_text (GTK_LABEL (length_lbl), length);
187
void run_status_window(Recording *recording)
189
timeout_id = g_timeout_add(500, (GSourceFunc) timeout_cb, recording);
192
void stop_rec_button_clicked_cb(GtkButton *button, gpointer data)
194
Recording *recording = data;
195
close_status_window();
196
recording_stop(recording);
199
static gint delete_event_cb(GtkWidget* window, GdkEventAny* e, gpointer data)
201
stop_rec_button_clicked_cb(NULL, data);
205
GtkWidget* record_status_window(Recording *recording)
214
gchar *text, *markup;
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);
220
vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 12);
221
gtk_container_set_border_width(GTK_CONTAINER(vbox), 8);
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);
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);
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);
240
gtk_grid_attach(GTK_GRID(grid), label, 1, 0, 1, 1);
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);
247
expander = gtk_expander_new(_("Details"));
248
gtk_grid_attach(GTK_GRID(grid), expander, 1, 2, 1, 1);
250
gtk_box_pack_start (GTK_BOX(vbox), grid, TRUE, TRUE, 0);
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);
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);
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);
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);
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);
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);
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);
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);
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);
290
gtk_container_add (GTK_CONTAINER (expander), grid);
292
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
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);
298
gtk_box_pack_start (GTK_BOX(box), image, FALSE, FALSE, 2);
299
gtk_box_pack_start (GTK_BOX(box), label, FALSE, FALSE, 2);
301
gtk_container_add(GTK_CONTAINER(button), box);
303
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
305
gtk_box_pack_end (GTK_BOX (box), button, TRUE, FALSE, 0);
306
gtk_box_pack_start (GTK_BOX(vbox), box, FALSE, FALSE, 0);
308
gtk_container_add(GTK_CONTAINER(status_dialog), vbox);
309
gtk_widget_grab_focus (button);
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);
315
gtk_window_set_position(GTK_WINDOW(status_dialog), GTK_WIN_POS_CENTER);
317
return status_dialog;