comparison Plugins/Input/sid/xs_fileinfo.c @ 269:1b82a9932b60 trunk

[svn] Import sid plugin. Ported from XMMS by giacomo.
author chainsaw
date Thu, 08 Dec 2005 15:12:12 -0800
parents
children d0e9693d2115
comparison
equal deleted inserted replaced
268:1368faba73c9 269:1b82a9932b60
1 /*
2 XMMS-SID - SIDPlay input plugin for X MultiMedia System (XMMS)
3
4 File information window
5
6 Programmed and designed by Matti 'ccr' Hamalainen <ccr@tnsp.org>
7 (C) Copyright 1999-2005 Tecnic Software productions (TNSP)
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 */
23 #include <gdk/gdkkeysyms.h>
24 #include <gtk/gtk.h>
25
26 #include "xs_fileinfo.h"
27 #include "xs_support.h"
28 #include "xs_stil.h"
29 #include "xs_config.h"
30 #include "xs_interface.h"
31 #include "xs_glade.h"
32
33 static GtkWidget *xs_fileinfowin = NULL;
34 static t_xs_stil_node *xs_fileinfostil = NULL;
35 XS_MUTEX(xs_fileinfowin);
36
37 #define LUW(x) lookup_widget(xs_fileinfowin, x)
38
39
40 void xs_fileinfo_update(void)
41 {
42 gboolean isEnabled;
43 GtkAdjustment *tmpAdj;
44
45 XS_MUTEX_LOCK(xs_status);
46 XS_MUTEX_LOCK(xs_fileinfowin);
47
48 /* Check if control window exists, we are currently playing and have a tune */
49 if (xs_fileinfowin) {
50 if (xs_status.tuneInfo && xs_status.isPlaying && (xs_status.tuneInfo->nsubTunes > 1)) {
51 tmpAdj = gtk_range_get_adjustment(GTK_RANGE(LUW("fileinfo_subctrl_adj")));
52
53 tmpAdj->value = xs_status.currSong;
54 tmpAdj->lower = 1;
55 tmpAdj->upper = xs_status.tuneInfo->nsubTunes;
56 XS_MUTEX_UNLOCK(xs_status);
57 XS_MUTEX_UNLOCK(xs_fileinfowin);
58 gtk_adjustment_value_changed(tmpAdj);
59 XS_MUTEX_LOCK(xs_status);
60 XS_MUTEX_LOCK(xs_fileinfowin);
61 isEnabled = TRUE;
62 } else
63 isEnabled = FALSE;
64
65 /* Enable or disable subtune-control in fileinfo window */
66 gtk_widget_set_sensitive(LUW("fileinfo_subctrl_prev"), isEnabled);
67 gtk_widget_set_sensitive(LUW("fileinfo_subctrl_adj"), isEnabled);
68 gtk_widget_set_sensitive(LUW("fileinfo_subctrl_next"), isEnabled);
69 }
70
71 XS_MUTEX_UNLOCK(xs_status);
72 XS_MUTEX_UNLOCK(xs_fileinfowin);
73 }
74
75
76 void xs_fileinfo_setsong(void)
77 {
78 gint n;
79
80 XS_MUTEX_LOCK(xs_status);
81 XS_MUTEX_LOCK(xs_fileinfowin);
82
83 if (xs_status.tuneInfo && xs_status.isPlaying) {
84 n = (gint) gtk_range_get_adjustment(GTK_RANGE(LUW("fileinfo_subctrl_adj")))->value;
85 if ((n >= 1) && (n <= xs_status.tuneInfo->nsubTunes))
86 xs_status.currSong = n;
87 }
88
89 XS_MUTEX_UNLOCK(xs_fileinfowin);
90 XS_MUTEX_UNLOCK(xs_status);
91 }
92
93
94 void xs_fileinfo_ok(void)
95 {
96 XS_MUTEX_LOCK(xs_fileinfowin);
97 if (xs_fileinfowin) {
98 gtk_widget_destroy(xs_fileinfowin);
99 xs_fileinfowin = NULL;
100 }
101 XS_MUTEX_UNLOCK(xs_fileinfowin);
102 }
103
104
105 gboolean xs_fileinfo_delete(GtkWidget * widget, GdkEvent * event, gpointer user_data)
106 {
107 (void) widget;
108 (void) event;
109 (void) user_data;
110
111 XSDEBUG("delete_event\n");
112 xs_fileinfo_ok();
113 return FALSE;
114 }
115
116
117
118 void xs_fileinfo_subtune(GtkWidget * widget, void *data)
119 {
120 t_xs_stil_subnode *tmpNode;
121 GtkWidget *tmpItem, *tmpText;
122 gint tmpIndex;
123 gchar *subName, *subAuthor;
124
125 (void) widget;
126 (void) data;
127
128 /* Freeze text-widget and delete the old text */
129 tmpText = LUW("fileinfo_sub_info");
130
131 if (xs_fileinfostil) {
132 /* Get subtune number */
133 tmpItem = gtk_menu_get_active(GTK_MENU(data));
134 tmpIndex = g_list_index(GTK_MENU_SHELL(data)->children, tmpItem);
135
136 /* Get subtune information */
137 tmpNode = &xs_fileinfostil->subTunes[tmpIndex];
138 subName = tmpNode->pName;
139 subAuthor = tmpNode->pAuthor;
140
141 /* Put in the new text, if available */
142 if (tmpNode->pInfo) {
143 gsize pInfo_utf8_size;
144 gchar *pInfo_utf8 = g_locale_to_utf8( tmpNode->pInfo , strlen(tmpNode->pInfo) , NULL , &pInfo_utf8_size , NULL );
145 gtk_text_buffer_set_text( GTK_TEXT_BUFFER(gtk_text_view_get_buffer(GTK_TEXT_VIEW(tmpText))),
146 pInfo_utf8, pInfo_utf8_size);
147 }
148 } else {
149 /* We don't have any information */
150 subName = NULL;
151 subAuthor = NULL;
152 }
153
154 /* Get and set subtune information */
155 gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_sub_name")), subName ? g_locale_to_utf8(subName,strlen(subName),NULL,NULL,NULL) : "");
156 gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_sub_author")), subAuthor ? g_locale_to_utf8(subAuthor,strlen(subAuthor),NULL,NULL,NULL) : "");
157 }
158
159
160 void xs_fileinfo(gchar * pcFilename)
161 {
162 GtkWidget *tmpMenuItem, *tmpMenu, *tmpOptionMenu;
163 t_xs_tuneinfo *tmpInfo;
164 t_xs_stil_subnode *tmpNode;
165 gchar tmpStr[64];
166 gint n;
167
168 /* Current implementation leaves old fileinfo window untouched if
169 * no information can be found for the new file. Hmm...
170 */
171
172 /* Get new tune information */
173 XS_MUTEX_LOCK(xs_fileinfowin);
174 XS_MUTEX_LOCK(xs_status);
175 if ((tmpInfo = xs_status.sidPlayer->plrGetSIDInfo(pcFilename)) == NULL) {
176 XS_MUTEX_UNLOCK(xs_fileinfowin);
177 XS_MUTEX_UNLOCK(xs_status);
178 return;
179 }
180 XS_MUTEX_UNLOCK(xs_status);
181
182 xs_fileinfostil = xs_stil_get(pcFilename);
183
184 /* Check if there already is an open fileinfo window */
185 if (xs_fileinfowin) {
186 /* Raise old window */
187 gdk_window_raise(xs_fileinfowin->window);
188
189 /* Delete items */
190 tmpOptionMenu = LUW("fileinfo_sub_tune");
191 gtk_widget_destroy(GTK_OPTION_MENU(tmpOptionMenu)->menu);
192 GTK_OPTION_MENU(tmpOptionMenu)->menu = gtk_menu_new();
193 } else {
194 /* If not, create a new one */
195 xs_fileinfowin = create_xs_fileinfowin();
196
197 /* Connect additional signals */
198 gtk_signal_connect(GTK_OBJECT(gtk_range_get_adjustment(GTK_RANGE(LUW("fileinfo_subctrl_adj")))),
199 "value_changed", GTK_SIGNAL_FUNC(xs_fileinfo_setsong), NULL);
200 }
201
202
203 /* Set the generic song information */
204 gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_filename")), g_locale_to_utf8(pcFilename,strlen(pcFilename),NULL,NULL,NULL) );
205 gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_songname")), g_locale_to_utf8(tmpInfo->sidName,strlen(tmpInfo->sidName),NULL,NULL,NULL) );
206 gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_composer")), g_locale_to_utf8(tmpInfo->sidComposer,strlen(tmpInfo->sidComposer),NULL,NULL,NULL) );
207 gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_copyright")), g_locale_to_utf8(tmpInfo->sidCopyright,strlen(tmpInfo->sidCopyright),NULL,NULL,NULL) );
208
209 /* Main tune - the pseudo tune */
210 tmpOptionMenu = LUW("fileinfo_sub_tune");
211 tmpMenu = GTK_OPTION_MENU(tmpOptionMenu)->menu;
212
213 tmpMenuItem = gtk_menu_item_new_with_label("General info");
214 gtk_widget_show(tmpMenuItem);
215 gtk_menu_append(GTK_MENU(tmpMenu), tmpMenuItem);
216 gtk_signal_connect(GTK_OBJECT(tmpMenuItem), "activate", GTK_SIGNAL_FUNC(xs_fileinfo_subtune), tmpMenu);
217
218 /* Other menu items */
219 for (n = 1; n <= tmpInfo->nsubTunes; n++) {
220 if (xs_fileinfostil) {
221 snprintf(tmpStr, sizeof(tmpStr), "Tune #%i: ", n);
222 tmpNode = &xs_fileinfostil->subTunes[n];
223 if (tmpNode->pName)
224 xs_pnstrcat(tmpStr, sizeof(tmpStr), tmpNode->pName);
225 else if (tmpNode->pInfo)
226 xs_pnstrcat(tmpStr, sizeof(tmpStr), tmpNode->pInfo);
227 else
228 xs_pnstrcat(tmpStr, sizeof(tmpStr), "---");
229 } else {
230 snprintf(tmpStr, sizeof(tmpStr), "Tune #%i", n);
231 }
232
233 tmpMenuItem = gtk_menu_item_new_with_label(tmpStr);
234 gtk_widget_show(tmpMenuItem);
235 gtk_menu_append(GTK_MENU(tmpMenu), tmpMenuItem);
236
237 gtk_signal_connect(GTK_OBJECT(tmpMenuItem), "activate", GTK_SIGNAL_FUNC(xs_fileinfo_subtune), tmpMenu);
238 }
239
240 /* Set the subtune information */
241 xs_fileinfo_subtune(NULL, tmpMenu);
242
243 /* Free temporary tuneinfo */
244 xs_tuneinfo_free(tmpInfo);
245
246 /* Show the window */
247 gtk_widget_show(xs_fileinfowin);
248
249 XS_MUTEX_UNLOCK(xs_fileinfowin);
250
251 xs_fileinfo_update();
252 }