2422
|
1 /* Audacious - Cross-platform multimedia player
|
|
2 * Copyright (C) 2005-2007 Audacious development team
|
|
3 *
|
|
4 * Based on BMP:
|
|
5 * Copyright (C) 2003-2004 BMP development team.
|
|
6 *
|
|
7 * Based on XMMS:
|
|
8 * Copyright (C) 1998-2003 XMMS development team.
|
|
9 *
|
|
10 * This program is free software; you can redistribute it and/or modify
|
|
11 * it under the terms of the GNU General Public License as published by
|
|
12 * the Free Software Foundation; under version 2 of the License.
|
|
13 *
|
|
14 * This program is distributed in the hope that it will be useful,
|
|
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17 * GNU General Public License for more details.
|
|
18 *
|
|
19 * You should have received a copy of the GNU General Public License
|
|
20 * along with this program; if not, write to the Free Software
|
|
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
22 */
|
|
23
|
|
24 #ifdef HAVE_CONFIG_H
|
|
25 # include "config.h"
|
|
26 #endif
|
|
27
|
|
28 #define NEED_GLADE
|
|
29 #include "util.h"
|
|
30
|
|
31 #include <glib.h>
|
|
32 #include <glib/gi18n.h>
|
|
33 #include <glade/glade.h>
|
|
34 #include <gtk/gtk.h>
|
|
35 #include <stdlib.h>
|
|
36 #include <string.h>
|
|
37 #include <ctype.h>
|
|
38
|
|
39 #include "platform/smartinclude.h"
|
|
40 #include <errno.h>
|
|
41
|
|
42 #ifdef HAVE_FTS_H
|
|
43 # include <fts.h>
|
|
44 #endif
|
|
45
|
|
46 #include "glade.h"
|
|
47 #include "input.h"
|
|
48 #include "main.h"
|
|
49 #include "playback.h"
|
|
50 #include "strings.h"
|
|
51 #include "ui_playlist.h"
|
|
52
|
|
53 #ifdef USE_CHARDET
|
|
54 #include "../librcd/librcd.h"
|
|
55 #ifdef HAVE_UDET
|
|
56 #include <libudet_c.h>
|
|
57 #endif
|
|
58 #endif
|
|
59
|
|
60 #define URL_HISTORY_MAX_SIZE 30
|
|
61
|
|
62 static void
|
|
63 util_add_url_callback(GtkWidget * widget,
|
|
64 GtkEntry * entry)
|
|
65 {
|
|
66 const gchar *text;
|
|
67
|
|
68 text = gtk_entry_get_text(entry);
|
|
69 if (g_list_find_custom(cfg.url_history, text, (GCompareFunc) strcasecmp))
|
|
70 return;
|
|
71
|
|
72 cfg.url_history = g_list_prepend(cfg.url_history, g_strdup(text));
|
|
73
|
|
74 while (g_list_length(cfg.url_history) > URL_HISTORY_MAX_SIZE) {
|
|
75 GList *node = g_list_last(cfg.url_history);
|
|
76 g_free(node->data);
|
|
77 cfg.url_history = g_list_delete_link(cfg.url_history, node);
|
|
78 }
|
|
79 }
|
|
80
|
|
81 GtkWidget *
|
|
82 util_add_url_dialog_new(const gchar * caption, GCallback ok_func,
|
|
83 GCallback enqueue_func)
|
|
84 {
|
|
85 GtkWidget *win, *vbox, *bbox, *enqueue, *ok, *cancel, *combo, *entry,
|
|
86 *label;
|
|
87 GList *url;
|
|
88
|
|
89 win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
|
90 gtk_window_set_title(GTK_WINDOW(win), _("Add/Open URL Dialog"));
|
|
91 gtk_window_set_type_hint(GTK_WINDOW(win), GDK_WINDOW_TYPE_HINT_DIALOG);
|
|
92 gtk_window_set_position(GTK_WINDOW(win), GTK_WIN_POS_CENTER);
|
|
93 gtk_window_set_default_size(GTK_WINDOW(win), 400, -1);
|
|
94 gtk_container_set_border_width(GTK_CONTAINER(win), 12);
|
|
95
|
|
96 vbox = gtk_vbox_new(FALSE, 10);
|
|
97 gtk_container_add(GTK_CONTAINER(win), vbox);
|
|
98
|
|
99 label = gtk_label_new(caption);
|
|
100 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
|
|
101 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
|
|
102
|
|
103 combo = gtk_combo_box_entry_new_text();
|
|
104 gtk_box_pack_start(GTK_BOX(vbox), combo, FALSE, FALSE, 0);
|
|
105
|
|
106 entry = gtk_bin_get_child(GTK_BIN(combo));
|
|
107 gtk_window_set_focus(GTK_WINDOW(win), entry);
|
|
108 gtk_entry_set_text(GTK_ENTRY(entry), "");
|
|
109
|
|
110 for (url = cfg.url_history; url; url = g_list_next(url))
|
|
111 gtk_combo_box_append_text(GTK_COMBO_BOX(combo), (const gchar *) url->data);
|
|
112
|
|
113 g_signal_connect(entry, "activate",
|
|
114 G_CALLBACK(util_add_url_callback),
|
|
115 entry);
|
|
116 g_signal_connect(entry, "activate",
|
|
117 G_CALLBACK(ok_func),
|
|
118 entry);
|
|
119 g_signal_connect_swapped(entry, "activate",
|
|
120 G_CALLBACK(gtk_widget_destroy),
|
|
121 win);
|
|
122
|
|
123 bbox = gtk_hbutton_box_new();
|
|
124 gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END);
|
|
125 gtk_button_box_set_spacing(GTK_BUTTON_BOX(bbox), 5);
|
|
126 gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
|
|
127
|
|
128 ok = gtk_button_new_from_stock(GTK_STOCK_OPEN);
|
|
129 g_signal_connect(ok, "clicked",
|
|
130 G_CALLBACK(util_add_url_callback), entry);
|
|
131 g_signal_connect(ok, "clicked",
|
|
132 G_CALLBACK(ok_func), entry);
|
|
133 g_signal_connect_swapped(ok, "clicked",
|
|
134 G_CALLBACK(gtk_widget_destroy),
|
|
135 win);
|
|
136 gtk_box_pack_start(GTK_BOX(bbox), ok, FALSE, FALSE, 0);
|
|
137
|
|
138 enqueue = gtk_button_new_from_stock(GTK_STOCK_ADD);
|
|
139 gtk_box_pack_start(GTK_BOX(bbox), enqueue, FALSE, FALSE, 0);
|
|
140
|
|
141 g_signal_connect(enqueue, "clicked",
|
|
142 G_CALLBACK(util_add_url_callback),
|
|
143 entry);
|
|
144 g_signal_connect(enqueue, "clicked",
|
|
145 G_CALLBACK(enqueue_func),
|
|
146 entry);
|
|
147 g_signal_connect_swapped(enqueue, "clicked",
|
|
148 G_CALLBACK(gtk_widget_destroy),
|
|
149 win);
|
|
150
|
|
151 cancel = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
|
|
152 gtk_box_pack_start(GTK_BOX(bbox), cancel, FALSE, FALSE, 0);
|
|
153
|
|
154 g_signal_connect_swapped(cancel, "clicked",
|
|
155 G_CALLBACK(gtk_widget_destroy),
|
|
156 win);
|
|
157
|
|
158 gtk_widget_show_all(vbox);
|
|
159
|
|
160 return win;
|
|
161 }
|