comparison src/audacious/ui_lastfm.c @ 3193:1fef0ac7395e trunk

fixed crashes
author Cristi Magherusan <majeru@atheme-project.org>
date Sat, 28 Jul 2007 14:45:48 +0300
parents bcf611cf5ae2
children f985357757e0
comparison
equal deleted inserted replaced
3185:c87dfbb3711e 3193:1fef0ac7395e
1 #include <gtk/gtk.h> 1 #include <gtk/gtk.h>
2 #include <glib/gi18n.h> 2 #include <glib/gi18n.h>
3 #include <gdk/gdkkeysyms.h> 3 #include <gdk/gdkkeysyms.h>
4 #include "configdb.h" 4 #include "configdb.h"
5 #include "playback.h" 5 #include "playback.h"
6
7 #define DEBUG 1 6 #define DEBUG 1
8 typedef struct { 7 typedef struct {
9 gchar *username, 8 gchar *username,
10 *session; 9 *session;
11 }last_fm; 10 }last_fm;
38 } 37 }
39 void command(gchar *comm) 38 void command(gchar *comm)
40 { 39 {
41 /* get the session from mowgli*/ 40 /* get the session from mowgli*/
42 if(login_data->session) 41 if(login_data->session)
43 { 42 {
44 g_free(login_data->session); 43 g_free(login_data->session);
45 login_data->session=NULL; 44 login_data->session=NULL;
46 } 45 }
47 login_data->session = g_strdup(mowgli_global_storage_get("lastfm_session_id")); 46 login_data->session = g_strdup(mowgli_global_storage_get("lastfm_session_id"));
48 gchar *url=g_strdup_printf("http://ws.audioscrobbler.com/radio/control.php?session=%s&command=%s&debug=0",login_data->session,comm); 47 gchar *url=g_strdup_printf("http://ws.audioscrobbler.com/radio/control.php?session=%s&command=%s&debug=0",login_data->session,comm);
49 g_thread_create(open_url,url,FALSE,NULL); 48 g_thread_create(open_url,url,FALSE,NULL);
50 if(!g_str_has_prefix(comm,"love")) 49 if(!g_str_has_prefix(comm,"love"))
51 g_thread_create((gpointer)playback_initiate,NULL,FALSE,NULL); 50 g_thread_create((gpointer)playback_initiate,NULL,FALSE,NULL);
52 return; 51 return;
53 52
54 } 53 }
55 static void change_track_data_cb(gpointer track, gpointer unused) 54 static void change_track_data_cb(gpointer track, gpointer unused)
56 { 55 {
57 gchar **inf, 56 gchar **inf,
58 **t, 57 **t,
59 *alb, 58 *alb,
60 *tr; 59 *tr;
61 tr=((track_data*)track)->title; 60 tr=g_strdup(((track_data*)track)->title);
62 61
63 if(tr==NULL) 62 if(tr==NULL)
64 return ; 63 return ;
64 if(g_strrstr(tr,"last.fm")==NULL)
65 {
66 gtk_entry_set_text(GTK_ENTRY(lastfm_url_entry),"Not last.fm stream");
67 return;
68 }
69
65 #if DEBUG 70 #if DEBUG
66 g_print("New Track: %s \n",tr); 71 g_print("New Track: %s \n",tr);
67 #endif 72 #endif
68 if(g_str_has_prefix(tr,"lastfm://")) 73 if(g_str_has_prefix(tr,"lastfm://"))
69 return; 74 return;
70
71 if(g_strrstr(tr,"Neighbour")!=NULL) 75 if(g_strrstr(tr,"Neighbour")!=NULL)
72 { 76 {
73 gchar *temp=g_strdup_printf("lastfm://user/%s/neighbours", login_data->username); 77 gchar *temp=g_strdup_printf("lastfm://user/%s/neighbours", login_data->username);
74 gtk_entry_set_text(GTK_ENTRY(lastfm_url_entry),temp); 78 gtk_entry_set_text(GTK_ENTRY(lastfm_url_entry),temp);
75 g_free(temp); 79 g_free(temp);
87 gchar* artist_markup=g_strdup_printf("<b>Artist:</b> %s" ,inf[0]); 91 gchar* artist_markup=g_strdup_printf("<b>Artist:</b> %s" ,inf[0]);
88 gtk_label_set_markup(GTK_LABEL(artist_label),artist_markup); 92 gtk_label_set_markup(GTK_LABEL(artist_label),artist_markup);
89 g_free(artist_markup); 93 g_free(artist_markup);
90 94
91 t = g_strsplit(inf[1], g_strrstr(inf[1],"("),2); 95 t = g_strsplit(inf[1], g_strrstr(inf[1],"("),2);
96 if(t[0]==NULL) return;
92 alb = g_strdup(mowgli_global_storage_get("lastfm_album")); 97 alb = g_strdup(mowgli_global_storage_get("lastfm_album"));
93 98
94 gchar* title_markup=g_strdup_printf("<b>Title:</b> %s" ,t[0]); 99 gchar* title_markup=g_strdup_printf("<b>Title:</b> %s" ,t[0]);
95 gtk_label_set_markup( GTK_LABEL(title_label),title_markup); 100 gtk_label_set_markup( GTK_LABEL(title_label),title_markup);
96 g_free(title_markup); 101 g_free(title_markup);
109 114
110 static void show_login_error_dialog(void) 115 static void show_login_error_dialog(void)
111 { 116 {
112 const gchar *markup = 117 const gchar *markup =
113 N_("<b><big>Couldn't find your lastfm login data.</big></b>\n\n" 118 N_("<b><big>Couldn't find your lastfm login data.</big></b>\n\n"
114 "Check if your Scrobbler's plugin login settings are configured properly.\n"); 119 "Check if your Scrobbler's plugin login settings are configured properly.\n");
115 120
116 GtkWidget *dialog = 121 GtkWidget *dialog =
117 gtk_message_dialog_new_with_markup(NULL, 122 gtk_message_dialog_new_with_markup(NULL,
118 GTK_DIALOG_DESTROY_WITH_PARENT, 123 GTK_DIALOG_DESTROY_WITH_PARENT,
119 GTK_MESSAGE_ERROR, 124 GTK_MESSAGE_ERROR,
173 gboolean add_press_callback(GtkWidget *love) 178 gboolean add_press_callback(GtkWidget *love)
174 { 179 {
175 gchar *text=NULL; 180 gchar *text=NULL;
176 gint poz=0; 181 gint poz=0;
177 text = g_strdup(gtk_entry_get_text(GTK_ENTRY(lastfm_url_entry))); 182 text = g_strdup(gtk_entry_get_text(GTK_ENTRY(lastfm_url_entry)));
183 if(playback_get_playing()==TRUE)
184 playback_stop();
185
178 poz = playlist_get_length(current_playlist); 186 poz = playlist_get_length(current_playlist);
179 playlist_add_url(current_playlist, text); 187 playlist_add_url(current_playlist, text);
180 sleep(1); 188 sleep(1);
181 playlist_set_position(current_playlist, poz); 189 playlist_set_position(current_playlist, poz);
182 playback_initiate(); 190 playback_initiate();
206 window=NULL; 214 window=NULL;
207 return FALSE; 215 return FALSE;
208 } 216 }
209 static gboolean keypress_callback(GtkWidget * widget, GdkEventKey * event, gpointer data) 217 static gboolean keypress_callback(GtkWidget * widget, GdkEventKey * event, gpointer data)
210 { 218 {
211 switch (event->keyval) 219 switch (event->keyval)
212 { 220 {
213 case GDK_Escape: 221 case GDK_Escape:
214 gtk_widget_hide_all(widget); 222 gtk_widget_hide_all(widget);
215 break; 223 break;
216 default: 224 default:
217 return FALSE; 225 return FALSE;
218 } 226 }
219 return TRUE; 227 return TRUE;
220 } 228 }
221 229
222 230
223 GtkWidget *ui_lastfm_create(void) 231 GtkWidget *ui_lastfm_create(void)
224 { 232 {
321 gtk_widget_set_size_request(GTK_WIDGET(window),400,124); 329 gtk_widget_set_size_request(GTK_WIDGET(window),400,124);
322 gtk_window_set_resizable(GTK_WINDOW(window),FALSE); 330 gtk_window_set_resizable(GTK_WINDOW(window),FALSE);
323 gtk_widget_show_all(gui_window); 331 gtk_widget_show_all(gui_window);
324 return window; 332 return window;
325 } 333 }
326 334 #if 0
327 static void no_lastfm_plugin_dialog(void) 335 static void no_lastfm_plugin_dialog(void)
328 { 336 {
329 const gchar *markup = 337 const gchar *markup =
330 N_("<b><big>The lastfm radio plugin could not be found.</big></b>\n\n" 338 N_("<b><big>The lastfm radio plugin could not be found.</big></b>\n\n"
331 "Check if the AudioScrobbler plugin was compiled in\n"); 339 "Check if the AudioScrobbler plugin was compiled in\n");
337 GTK_BUTTONS_OK, 345 GTK_BUTTONS_OK,
338 _(markup)); 346 _(markup));
339 gtk_dialog_run(GTK_DIALOG(dialog)); 347 gtk_dialog_run(GTK_DIALOG(dialog));
340 gtk_widget_destroy(dialog); 348 gtk_widget_destroy(dialog);
341 } 349 }
342 350 #endif
343 351
344 352
345 void ui_lastfm(void) 353 void ui_lastfm(void)
346 { 354 {
347 /*if(!mowgli_global_storage_get("lastfm_loaded")) 355 /*if(!mowgli_global_storage_get("lastfm_loaded"))
348 { 356 {
349 no_lastfm_plugin_dialog(); 357 no_lastfm_plugin_dialog();
350 return; 358 return;
351 } 359 }
352 */ 360 */
353 init_last_fm(); 361 init_last_fm();
354 if(!gui_window) 362 if(!gui_window)
355 { 363 {
356 if((gui_window = ui_lastfm_create())!=NULL); 364 if((gui_window = ui_lastfm_create())!=NULL);
357 gtk_widget_show_all(gui_window); 365 gtk_widget_show_all(gui_window);
358 #if 0 /*here should be set the artist, title and album labels at the first run, because it isn't captured by the hook*/ 366 #if 0 /*here should be set the artist, title and album labels at the first run, because it isn't captured by the hook*/
359 gchar* current_title = playlist_get_songtitle(current_playlist,playlist_get_position(current_playlist)); 367 gchar* current_title = playlist_get_songtitle(current_playlist,playlist_get_position(current_playlist));
360 if(current_title) 368 if(current_title)
361 change_track_data_cb(current_title,NULL); 369 change_track_data_cb(current_title,NULL);
362 #endif 370 #endif
363 } 371 }
364 else 372 else
365 gtk_widget_show_all(gui_window); 373 gtk_widget_show_all(gui_window);
366 374
367 } 375 }
368 376