comparison src/sid/xs_fileinfo.c @ 12:3da1b8942b8b trunk

[svn] - remove src/Input src/Output src/Effect src/General src/Visualization src/Container
author nenolod
date Mon, 18 Sep 2006 03:14:20 -0700
parents src/Input/sid/xs_fileinfo.c@13389e613d67
children 6c3c7b841382
comparison
equal deleted inserted replaced
11:cff1d04026ae 12:3da1b8942b8b
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 GStaticMutex xs_fileinfowin_mutex = G_STATIC_MUTEX_INIT;
36 GStaticMutex xs_status_mutex = G_STATIC_MUTEX_INIT;
37 extern t_xs_status xs_status;
38
39 #define LUW(x) lookup_widget(xs_fileinfowin, x)
40
41
42 void xs_fileinfo_update(void)
43 {
44 gboolean isEnabled;
45 GtkAdjustment *tmpAdj;
46
47 g_static_mutex_lock(&xs_status_mutex);
48 g_static_mutex_lock(&xs_fileinfowin_mutex);
49
50 /* Check if control window exists, we are currently playing and have a tune */
51 if (xs_fileinfowin) {
52 if (xs_status.tuneInfo && xs_status.isPlaying && (xs_status.tuneInfo->nsubTunes > 1)) {
53 tmpAdj = gtk_range_get_adjustment(GTK_RANGE(LUW("fileinfo_subctrl_adj")));
54
55 tmpAdj->value = xs_status.currSong;
56 tmpAdj->lower = 1;
57 tmpAdj->upper = xs_status.tuneInfo->nsubTunes;
58 g_static_mutex_unlock(&xs_status_mutex);
59 g_static_mutex_unlock(&xs_fileinfowin_mutex);
60 gtk_adjustment_value_changed(tmpAdj);
61 g_static_mutex_lock(&xs_status_mutex);
62 g_static_mutex_lock(&xs_fileinfowin_mutex);
63 isEnabled = TRUE;
64 } else
65 isEnabled = FALSE;
66
67 /* Enable or disable subtune-control in fileinfo window */
68 gtk_widget_set_sensitive(LUW("fileinfo_subctrl_prev"), isEnabled);
69 gtk_widget_set_sensitive(LUW("fileinfo_subctrl_adj"), isEnabled);
70 gtk_widget_set_sensitive(LUW("fileinfo_subctrl_next"), isEnabled);
71 }
72
73 g_static_mutex_unlock(&xs_status_mutex);
74 g_static_mutex_unlock(&xs_fileinfowin_mutex);
75 }
76
77
78 void xs_fileinfo_setsong(void)
79 {
80 gint n;
81
82 g_static_mutex_lock(&xs_status_mutex);
83 g_static_mutex_lock(&xs_fileinfowin_mutex);
84
85 if (xs_status.tuneInfo && xs_status.isPlaying) {
86 n = (gint) gtk_range_get_adjustment(GTK_RANGE(LUW("fileinfo_subctrl_adj")))->value;
87 if ((n >= 1) && (n <= xs_status.tuneInfo->nsubTunes))
88 xs_status.currSong = n;
89 }
90
91 g_static_mutex_unlock(&xs_fileinfowin_mutex);
92 g_static_mutex_unlock(&xs_status_mutex);
93 }
94
95
96 void xs_fileinfo_ok(void)
97 {
98 g_static_mutex_lock(&xs_fileinfowin_mutex);
99 if (xs_fileinfowin) {
100 gtk_widget_destroy(xs_fileinfowin);
101 xs_fileinfowin = NULL;
102 }
103 g_static_mutex_unlock(&xs_fileinfowin_mutex);
104 }
105
106
107 gboolean xs_fileinfo_delete(GtkWidget * widget, GdkEvent * event, gpointer user_data)
108 {
109 (void) widget;
110 (void) event;
111 (void) user_data;
112
113 XSDEBUG("delete_event\n");
114 xs_fileinfo_ok();
115 return FALSE;
116 }
117
118
119
120 void xs_fileinfo_subtune(GtkWidget * widget, void *data)
121 {
122 t_xs_stil_subnode *tmpNode;
123 GtkWidget *tmpItem, *tmpText;
124 gint tmpIndex;
125 gchar *subName, *subAuthor;
126
127 (void) widget;
128 (void) data;
129
130 /* Freeze text-widget and delete the old text */
131 tmpText = LUW("fileinfo_sub_info");
132
133 if (xs_fileinfostil) {
134 /* Get subtune number */
135 tmpItem = gtk_menu_get_active(GTK_MENU(data));
136 tmpIndex = g_list_index(GTK_MENU_SHELL(data)->children, tmpItem);
137
138 /* Get subtune information */
139 tmpNode = &xs_fileinfostil->subTunes[tmpIndex];
140 subName = tmpNode->pName;
141 subAuthor = tmpNode->pAuthor;
142
143 /* Put in the new text, if available */
144 if (tmpNode->pInfo) {
145 gsize pInfo_utf8_size;
146 gchar *pInfo_utf8 = g_locale_to_utf8( tmpNode->pInfo , strlen(tmpNode->pInfo) , NULL , &pInfo_utf8_size , NULL );
147 gtk_text_buffer_set_text( GTK_TEXT_BUFFER(gtk_text_view_get_buffer(GTK_TEXT_VIEW(tmpText))),
148 pInfo_utf8, pInfo_utf8_size);
149 }
150 } else {
151 /* We don't have any information */
152 subName = NULL;
153 subAuthor = NULL;
154 }
155
156 /* Get and set subtune information */
157 gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_sub_name")), subName ? g_locale_to_utf8(subName,strlen(subName),NULL,NULL,NULL) : "");
158 gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_sub_author")), subAuthor ? g_locale_to_utf8(subAuthor,strlen(subAuthor),NULL,NULL,NULL) : "");
159 }
160
161
162 void xs_fileinfo(gchar * pcFilename)
163 {
164 GtkWidget *tmpMenuItem, *tmpMenu, *tmpOptionMenu;
165 t_xs_tuneinfo *tmpInfo;
166 t_xs_stil_subnode *tmpNode;
167 gchar tmpStr[64];
168 gint n;
169
170 /* Current implementation leaves old fileinfo window untouched if
171 * no information can be found for the new file. Hmm...
172 */
173
174 /* Get new tune information */
175 g_static_mutex_lock(&xs_fileinfowin_mutex);
176 g_static_mutex_lock(&xs_status_mutex);
177 if ((tmpInfo = xs_status.sidPlayer->plrGetSIDInfo(pcFilename)) == NULL) {
178 g_static_mutex_unlock(&xs_fileinfowin_mutex);
179 g_static_mutex_unlock(&xs_status_mutex);
180 return;
181 }
182 g_static_mutex_unlock(&xs_status_mutex);
183
184 xs_fileinfostil = xs_stil_get(pcFilename);
185
186 /* Check if there already is an open fileinfo window */
187 if (xs_fileinfowin) {
188 /* Raise old window */
189 gdk_window_raise(xs_fileinfowin->window);
190
191 /* Delete items */
192 tmpOptionMenu = LUW("fileinfo_sub_tune");
193 gtk_widget_destroy(GTK_OPTION_MENU(tmpOptionMenu)->menu);
194 GTK_OPTION_MENU(tmpOptionMenu)->menu = gtk_menu_new();
195 } else {
196 /* If not, create a new one */
197 xs_fileinfowin = create_xs_fileinfowin();
198
199 /* Connect additional signals */
200 gtk_signal_connect(GTK_OBJECT(gtk_range_get_adjustment(GTK_RANGE(LUW("fileinfo_subctrl_adj")))),
201 "value_changed", GTK_SIGNAL_FUNC(xs_fileinfo_setsong), NULL);
202 }
203
204
205 /* Set the generic song information */
206 gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_filename")), g_locale_to_utf8(pcFilename,strlen(pcFilename),NULL,NULL,NULL) );
207 gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_songname")), g_locale_to_utf8(tmpInfo->sidName,strlen(tmpInfo->sidName),NULL,NULL,NULL) );
208 gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_composer")), g_locale_to_utf8(tmpInfo->sidComposer,strlen(tmpInfo->sidComposer),NULL,NULL,NULL) );
209 gtk_entry_set_text(GTK_ENTRY(LUW("fileinfo_copyright")), g_locale_to_utf8(tmpInfo->sidCopyright,strlen(tmpInfo->sidCopyright),NULL,NULL,NULL) );
210
211 /* Main tune - the pseudo tune */
212 tmpOptionMenu = LUW("fileinfo_sub_tune");
213 tmpMenu = GTK_OPTION_MENU(tmpOptionMenu)->menu;
214
215 tmpMenuItem = gtk_menu_item_new_with_label("General info");
216 gtk_widget_show(tmpMenuItem);
217 gtk_menu_append(GTK_MENU(tmpMenu), tmpMenuItem);
218 gtk_signal_connect(GTK_OBJECT(tmpMenuItem), "activate", GTK_SIGNAL_FUNC(xs_fileinfo_subtune), tmpMenu);
219
220 /* Other menu items */
221 for (n = 1; n <= tmpInfo->nsubTunes; n++) {
222 if (xs_fileinfostil) {
223 snprintf(tmpStr, sizeof(tmpStr), "Tune #%i: ", n);
224 tmpNode = &xs_fileinfostil->subTunes[n];
225 if (tmpNode->pName)
226 xs_pnstrcat(tmpStr, sizeof(tmpStr), tmpNode->pName);
227 else if (tmpNode->pInfo)
228 xs_pnstrcat(tmpStr, sizeof(tmpStr), tmpNode->pInfo);
229 else
230 xs_pnstrcat(tmpStr, sizeof(tmpStr), "---");
231 } else {
232 snprintf(tmpStr, sizeof(tmpStr), "Tune #%i", n);
233 }
234
235 tmpMenuItem = gtk_menu_item_new_with_label(tmpStr);
236 gtk_widget_show(tmpMenuItem);
237 gtk_menu_append(GTK_MENU(tmpMenu), tmpMenuItem);
238
239 gtk_signal_connect(GTK_OBJECT(tmpMenuItem), "activate", GTK_SIGNAL_FUNC(xs_fileinfo_subtune), tmpMenu);
240 }
241
242 /* Set the subtune information */
243 xs_fileinfo_subtune(NULL, tmpMenu);
244
245 /* Free temporary tuneinfo */
246 xs_tuneinfo_free(tmpInfo);
247
248 /* Show the window */
249 gtk_widget_show(xs_fileinfowin);
250
251 g_static_mutex_unlock(&xs_fileinfowin_mutex);
252
253 xs_fileinfo_update();
254 }