annotate src/audacious/ui_urlopener.c @ 2814:77a012c3b521 trunk

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