bool gimmix_connect (void) { char *host = NULL; char *pass = NULL; int port; host = cfg_get_key_value (conf, "mpd_hostname"); pass = cfg_get_key_value (conf, "mpd_password"); port = atoi (cfg_get_key_value (conf, "mpd_port")); gmo = mpd_new (host, port, pass); mpd_signal_connect_error (gmo, (ErrorCallback)gimmix_mpd_connection_error_callback, NULL); if (mpd_connect(gmo) == MPD_OK) { mpd_send_password (gmo); printf ("connected to mpd\n"); mpd_signal_connect_connection_changed (gmo, (ConnectionChangedCallback)gimmix_mpd_connection_changed_callback, NULL); return true; } else { mpd_free (gmo); gmo = NULL; } return false; }
static int skin_init_widget(char *skin_name, ConfigFile *skinconf, char *prefix, GmuWidget *w) { int tmp_x1 = 0, tmp_y1 = 0, tmp_x2 = 0, tmp_y2 = 0; char *tmp_img_prefix = NULL; char *val, tmp[256]; int result = 0; snprintf(tmp, 255, "%s.PosX1", prefix); val = cfg_get_key_value(*skinconf, tmp); if (val) tmp_x1 = atoi(val); snprintf(tmp, 255, "%s.PosY1", prefix); val = cfg_get_key_value(*skinconf, tmp); if (val) tmp_y1 = atoi(val); snprintf(tmp, 255, "%s.PosX2", prefix); val = cfg_get_key_value(*skinconf, tmp); if (val) tmp_x2 = atoi(val); snprintf(tmp, 255, "%s.PosY2", prefix); val = cfg_get_key_value(*skinconf, tmp); if (val) tmp_y2 = atoi(val); snprintf(tmp, 255, "%s.ImagePrefix", prefix); val = cfg_get_key_value(*skinconf, tmp); if (val) tmp_img_prefix = val; if (tmp_img_prefix) { snprintf(tmp, 255, "%s/themes/%s/%s", gmu_core_get_base_dir(), skin_name, tmp_img_prefix); gmu_widget_new(w, tmp, tmp_x1, tmp_y1, tmp_x2, tmp_y2); result = 1; } return result; }
static gboolean gimmix_timer (void) { gchar time[15]; int new_status; float fraction; mpd_status_update (gmo); new_status = mpd_player_get_state (gmo); if (status == new_status) { if (status == MPD_PLAYER_PLAY || status == MPD_PLAYER_PAUSE) { gimmix_get_progress_status (gmo, &fraction, time); gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(progress), fraction); gtk_progress_bar_set_text (GTK_PROGRESS_BAR(progress), time); /* Update the system tray tooltip progress bar */ if (strncasecmp(cfg_get_key_value(conf, "enable_systray"), "true", 4) == 0) if (strncasecmp(cfg_get_key_value(conf, "enable_notification"), "true", 4) == 0) { gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(tooltip->progressbar), fraction); gtk_progress_bar_set_text (GTK_PROGRESS_BAR(tooltip->progressbar), time); } } return TRUE; } else { status = new_status; return TRUE; } }
void gimmix_tag_editor_show (void) { GimmixStatus status; SongInfo *info; gchar *song; status = gimmix_get_status (gmo); if (status == PLAY || status == PAUSE) { info = gimmix_get_song_info (gmo); song = g_strdup_printf ("%s/%s", cfg_get_key_value(conf, "music_directory"), info->file); if (gimmix_tag_editor_populate (song)) gtk_widget_show (GTK_WIDGET(tag_editor_window)); else { g_warning (_("Invalid music directory.")); gimmix_tag_editor_error (dir_error); } gimmix_free_song_info (info); g_free (song); } return; }
void gimmix_metadata_init (void) { metadata_song_title = glade_xml_get_widget (xml, "metadata_song_label"); metadata_song_artist = glade_xml_get_widget (xml, "metadata_artist_label"); metadata_song_album = glade_xml_get_widget (xml, "metadata_album_label"); metadata_song_genre = glade_xml_get_widget (xml, "metadata_genre_label"); metadata_song_albumreview = glade_xml_get_widget (xml, "metadata_albuminfo"); metadata_song_albumbox = glade_xml_get_widget (xml, "metadata_album_box"); metadata_song_artistbox = glade_xml_get_widget (xml, "metadata_artist_box"); metadata_song_genrebox = glade_xml_get_widget (xml, "metadata_genre_box"); metadata_song_cover = glade_xml_get_widget (xml, "metadata_albumart"); metadata_container = glade_xml_get_widget (xml, "metadata_container"); #ifndef HAVE_COVER_PLUGIN gimmix_metadata_show_song_cover (FALSE); #else if (!strncasecmp(cfg_get_key_value(conf,"coverart_enable"),"true",4)) { gimmix_metadata_show_song_cover (TRUE); } else { gimmix_metadata_show_song_cover (FALSE); } #endif return; }
void gimmix_tag_editor_show (void) { GimmixStatus status; mpd_Song *info; gchar *song = NULL; status = gimmix_get_status (gmo); if (status == PLAY || status == PAUSE) { info = mpd_playlist_get_current_song (gmo); #if HAVE_TAGEDITOR song = g_strdup_printf ("%s/%s", cfg_get_key_value(conf, "music_directory"), info->file); if (gimmix_tag_editor_populate (song)) gtk_widget_show (GTK_WIDGET(tag_editor_window)); #else if (gimmix_tag_editor_populate (info)) gtk_widget_show (GTK_WIDGET(tag_editor_window)); #endif else { #ifdef HAVE_TAGEDITOR g_warning (_("Invalid music directory.")); gimmix_tag_editor_error (dir_error); #else gimmix_tag_editor_error (_("An error occurred while trying to get song information. Please try again.")); #endif } g_free (song); } return; }
static gboolean cb_gimmix_main_window_delete_event (GtkWidget *widget, GdkEvent *event, gpointer data) { if (strncasecmp(cfg_get_key_value(conf, "enable_systray"), "true", 4) == 0) { gimmix_window_visible_toggle (); return TRUE; } /* stop playback on exit */ if (strncasecmp(cfg_get_key_value(conf, "stop_on_exit"), "true", 4) == 0) gimmix_stop (gmo); /* save window position and mode */ gimmix_save_window_pos (); return FALSE; }
static void gimmix_status_changed (MpdObj *mo, ChangedStatusType id) { if (id&MPD_CST_SONGID) { gimmix_set_song_info (); gimmix_update_current_playlist (); } if (id&MPD_CST_STATE) { int state = mpd_player_get_state (gmo); if (state == MPD_PLAYER_PLAY) { gtk_image_set_from_stock (GTK_IMAGE(image_play), "gtk-media-pause", GTK_ICON_SIZE_BUTTON); gtk_tooltips_set_tip (play_button_tooltip, play_button, _("Pause <x or c>"), NULL); gimmix_set_song_info (); } if (state == MPD_PLAYER_PAUSE) { gtk_image_set_from_stock (GTK_IMAGE(image_play), "gtk-media-play", GTK_ICON_SIZE_BUTTON); gtk_tooltips_set_tip (play_button_tooltip, play_button, _("Play <x or c>"), NULL); } if (state == MPD_PLAYER_STOP) { gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(progress), 0.0); gtk_progress_bar_set_text (GTK_PROGRESS_BAR(progress), _("Stopped")); if (strncasecmp(cfg_get_key_value(conf, "enable_systray"), "true", 4) == 0) { gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR(tooltip->progressbar), 0.0); gtk_progress_bar_set_text (GTK_PROGRESS_BAR(tooltip->progressbar), _("Stopped")); } gimmix_show_ver_info (); gtk_image_set_from_stock (GTK_IMAGE(image_play), "gtk-media-play", GTK_ICON_SIZE_BUTTON); gtk_tooltips_set_tip (play_button_tooltip, play_button, _("Play <x or c>"), NULL); } g_object_ref_sink (play_button_tooltip); gimmix_update_current_playlist (); } if (id&MPD_CST_PLAYLIST) gimmix_update_current_playlist (); if (id&MPD_CST_VOLUME) gimmix_update_volume (); if (id&MPD_CST_RANDOM) gimmix_update_shuffle (); if (id&MPD_CST_REPEAT) gimmix_update_repeat (); return; }
MpdObj * gimmix_mpd_connect (void) { MpdObj *mo; char *host; char *pass; int port; host = cfg_get_key_value (conf, "mpd_hostname"); pass = cfg_get_key_value (conf, "mpd_password"); port = atoi (cfg_get_key_value (conf, "mpd_port")); mo = mpd_new (host, port, pass); if (mpd_connect (mo) == MPD_OK) { mpd_signal_connect_status_changed (mo, (StatusChangedCallback)gimmix_status_changed, NULL); return mo; } return NULL; }
bool gimmix_config_get_bool (const char *key) { bool ret = false; //g_print ("%s:%s\n", key, cfg_get_key_value(conf,key)); int cmpval = strncasecmp (cfg_get_key_value(conf,(char*)key), "true", 4); if (cmpval == 0) { g_print (""); ret = true; } return ret; }
char* gimmix_config_get_proxy_string (void) { char *ret = NULL; char *host = NULL; host = cfg_get_key_value (conf,"proxy_host"); if ((host != NULL) && strlen(host)) { char *port = NULL; port = cfg_get_key_value (conf,"proxy_port"); if (port && strlen(port)) { ret = g_strdup_printf ("%s:%s", host, port); } else { ret = g_strdup_printf (host); } } return ret; }
static void gimmix_lyrics_plugin_proxy_init (nxml_t *n) { char *proxy = NULL; if (!strncasecmp(cfg_get_key_value(conf,"proxy_enable"),"true",4)) { proxy = gimmix_config_get_proxy_string (); nxml_set_proxy (n, proxy, NULL); g_free (proxy); } return; }
void gimmix_covers_plugin_init (void) { gchar *cpath = NULL; GtkWidget *widget = NULL; /* check if .gimmix/covers exists */ cpath = cfg_get_path_to_config_file (COVERS_DIR); g_mkdir_with_parents (cpath, 00755); g_free (cpath); /* check if .gimmix/covers/covers.db exists */ cpath = cfg_get_path_to_config_file (COVERS_DBF); if (!g_file_test(cpath,G_FILE_TEST_EXISTS)) { FILE *fp = fopen (cpath, "w"); fclose (fp); } g_free (cpath); /* initialize curl */ curl = curl_easy_init (); /* initialize mutex */ mutex = g_mutex_new (); /* initialize cover database */ gimmix_covers_plugin_cover_db_init (); /* initialize metadata widgets */ gimmix_plcbox_eventbox = glade_xml_get_widget (xml, "cover_event_box"); gimmix_plcbox_image = glade_xml_get_widget (xml, "gimmix_plcbox_image"); gimmix_metadata_image = glade_xml_get_widget (xml, "gimmix_metadata_image"); gimmix_plcbox_frame = glade_xml_get_widget (xml, "gimmix_plc_image_frame"); /* some signals */ g_signal_connect (gimmix_plcbox_eventbox, "button_press_event", G_CALLBACK(cb_gimmix_covers_plugin_plc_popup), NULL); /* an ugly way to calculate size of the album picture placeholder */ widget = glade_xml_get_widget (xml,"plcvbox"); g_signal_connect (widget, "size-allocate", G_CALLBACK(cb_gimmix_covers_plugin_plcbox_size_allocated), NULL); /* configuration init */ if (!strncasecmp(cfg_get_key_value(conf,"coverart_enable"),"false",4)) gtk_widget_hide (gimmix_plcbox_frame); return; }
void gimmix_set_song_info (void) { gchar *markup; gchar *title; SongInfo *song = NULL; song = gimmix_get_song_info (gmo); if (song == NULL) return; if (song->title != NULL) { title = g_strdup_printf ("%s - %s", "Gimmix", song->title); gtk_window_set_title (GTK_WINDOW(main_window), title); g_free (title); markup = g_markup_printf_escaped ("<span size=\"large\"weight=\"bold\">%s</span>", song->title); } else { title = g_path_get_basename (song->file); gimmix_strip_file_ext (title); markup = g_markup_printf_escaped ("<span size=\"large\"weight=\"bold\">%s</span>", title); g_free (title); gtk_window_set_title (GTK_WINDOW(main_window), "Gimmix"); } gtk_label_set_markup (GTK_LABEL(song_label), markup); if (song->artist != NULL) { gchar *string; string = g_markup_printf_escaped ("<i>by %s</i>", song->artist); gtk_label_set_markup (GTK_LABEL(artist_label), string); g_free (string); } else gtk_label_set_text (GTK_LABEL(artist_label), NULL); g_free (markup); if (strncasecmp(cfg_get_key_value(conf, "enable_systray"), "true", 4) == 0) gimmix_update_systray_tooltip (song); gimmix_free_song_info (song); return; }
void gimmix_lyrics_plugin_update_lyrics (void) { LYRICS_NODE *node = NULL; mpd_Song *s = NULL; sleep (2); if (mpd_player_get_state(gmo)!=MPD_PLAYER_STOP) { if (mpd_playlist_get_playlist_length(gmo)) s = mpd_playlist_get_current_song (gmo); else s = NULL; } if (s) { if (s->artist) gimmix_covers_plugin_set_artist (s->artist); if (s->title) gimmix_covers_plugin_set_songtitle (s->title); #ifndef HAVE_COVER_PLUGIN gimmix_metadata_set_song_details (s, NULL); #else if (!strncasecmp(cfg_get_key_value(conf,"coverart_enable"),"false",5)) { gimmix_metadata_set_song_details (s, NULL); } #endif } node = lyrics_search (); gimmix_lyrics_populate_textview (node); if (node) { if (node->lyrics) g_free (node->lyrics); g_free (node); } return; }
/* Add a new key to the configuration */ int cfg_add_key(ConfigFile *cf, char *key, char *value) { int result = 0; int strsize = 0; int i; if (cfg_get_key_value(*cf, key) != NULL) /* Key already exists->overwrite */ { for (i = 0; i < cf->lastkey; i++) if (strncmp(key, cf->key[i], 127) == 0) { free(cf->key[i]); /* Free allocated memory */ free(cf->value[i]); /* Allocate memory for the new string and save it... */ strsize = (strlen(key) < 127 ? strlen(key) : 126) + 1; cf->key[i] = (char*)malloc(strsize * sizeof(char)); sprintf(cf->key[i], "%s", key); strsize = (strlen(key) < 127 ? strlen(value) : 126) + 1; cf->value[i] = (char*)malloc(strsize * sizeof(char)); sprintf(cf->value[i], "%s", value); break; } } else if (cf->lastkey < MAXKEYS) { strsize = (strlen(key) < 127 ? strlen(key) : 126) + 1; cf->key[cf->lastkey] = (char*)malloc(strsize * sizeof(char)); sprintf(cf->key[cf->lastkey], "%s", key); strsize = (strlen(key) < 127 ? strlen(value) : 126) + 1; cf->value[cf->lastkey] = (char*)malloc(strsize * sizeof(char)); sprintf(cf->value[cf->lastkey], "%s", value); (cf->lastkey)++; } else result = -1; return result; }
static int skin_config_load(Skin *skin, char *skin_name) { int result = 1; ConfigFile skinconf; char skin_file[256]; memset(skin, 0, sizeof(Skin)); skin->version = 1; skin->buffer = NULL; skin->title_scroller_offset_x1 = -1; skin->title_scroller_offset_x2 = -1; skin->title_scroller_offset_y = -1; skin->symbols_width = 0; skin->symbols_height = 0; skin->symbol_play_offset_x = -1; skin->symbol_play_offset_y = -1; skin->symbol_pause_offset_x = -1; skin->symbol_pause_offset_y = -1; skin->symbol_stereo_offset_x = -1; skin->symbol_stereo_offset_y = -1; skin->volume_offset_x = -1; skin->volume_offset_y = -1; skin->bitrate_offset_x = -1; skin->bitrate_offset_y = -1; skin->frequency_offset_x = -1; skin->frequency_offset_y = -1; skin->time_offset_x = -1; skin->time_offset_y = -1; skin->display_symbols = NULL; skin->arrow_up = NULL; skin->arrow_down = NULL; snprintf(skin_file, 255, "%s/themes/%s/theme.conf", gmu_core_get_base_dir(), skin_name); cfg_init_config_file_struct(&skinconf); if (cfg_read_config_file(&skinconf, skin_file) != 0) { printf("skin: Could not read skin config \"%s\".\n", skin_file); result = 0; } else { char *val; val = cfg_get_key_value(skinconf, "FormatVersion"); if (val) skin->version = atoi(val); strncpy(skin->name, skin_name, 127); switch (skin->version) { case 2: /* New theme format with support for a resizable window */ printf("skin: Modern theme file format found.\n"); skin_init_widget(skin_name, &skinconf, "Display", &(skin->display)); skin_init_widget(skin_name, &skinconf, "ListView", &(skin->lv)); skin_init_widget(skin_name, &skinconf, "Header", &(skin->header)); skin_init_widget(skin_name, &skinconf, "Footer", &(skin->footer)); val = cfg_get_key_value(skinconf, "Display.TitleScrollerOffsetX1"); if (val) skin->title_scroller_offset_x1 = atoi(val); val = cfg_get_key_value(skinconf, "Display.TitleScrollerOffsetX2"); if (val) skin->title_scroller_offset_x2 = atoi(val); val = cfg_get_key_value(skinconf, "Display.TitleScrollerOffsetY"); if (val) skin->title_scroller_offset_y = atoi(val); val = cfg_get_key_value(skinconf, "Display.BitrateOffsetX"); if (val) skin->bitrate_offset_x = atoi(val); val = cfg_get_key_value(skinconf, "Display.BitrateOffsetY"); if (val) skin->bitrate_offset_y = atoi(val); val = cfg_get_key_value(skinconf, "Display.TimeOffsetX"); if (val) skin->time_offset_x = atoi(val); val = cfg_get_key_value(skinconf, "Display.TimeOffsetY"); if (val) skin->time_offset_y = atoi(val); val = cfg_get_key_value(skinconf, "Display.FrequencyOffsetX"); if (val) skin->frequency_offset_x = atoi(val); val = cfg_get_key_value(skinconf, "Display.FrequencyOffsetY"); if (val) skin->frequency_offset_y = atoi(val); val = cfg_get_key_value(skinconf, "Display.SymbolsWidth"); if (val) skin->symbols_width = atoi(val); val = cfg_get_key_value(skinconf, "Display.SymbolsHeight"); if (val) skin->symbols_height = atoi(val); val = cfg_get_key_value(skinconf, "Display.Symbol.Play.OffsetX"); if (val) skin->symbol_play_offset_x = atoi(val); val = cfg_get_key_value(skinconf, "Display.Symbol.Play.OffsetY"); if (val) skin->symbol_play_offset_y = atoi(val); val = cfg_get_key_value(skinconf, "Display.Symbol.Pause.OffsetX"); if (val) skin->symbol_pause_offset_x = atoi(val); val = cfg_get_key_value(skinconf, "Display.Symbol.Pause.OffsetY"); if (val) skin->symbol_pause_offset_y = atoi(val); val = cfg_get_key_value(skinconf, "Display.Symbol.Stereo.OffsetX"); if (val) skin->symbol_stereo_offset_x = atoi(val); val = cfg_get_key_value(skinconf, "Display.Symbol.Stereo.OffsetY"); if (val) skin->symbol_stereo_offset_y = atoi(val); /* fonts */ val = cfg_get_key_value(skinconf, "Display.Font"); if (val) strncpy(skin->font_display_name, val, 127); val = cfg_get_key_value(skinconf, "Display.FontCharWidth"); if (val) skin->font_display_char_width = atoi(val); val = cfg_get_key_value(skinconf, "Display.FontCharHeight"); if (val) skin->font_display_char_height = atoi(val); val = cfg_get_key_value(skinconf, "Font1"); if (val) strncpy(skin->font1_name, val, 127); val = cfg_get_key_value(skinconf, "Font1CharWidth"); if (val) skin->font1_char_width = atoi(val); val = cfg_get_key_value(skinconf, "Font1CharHeight"); if (val) skin->font1_char_height = atoi(val); val = cfg_get_key_value(skinconf, "Font2"); if (val) strncpy(skin->font2_name, val, 127); val = cfg_get_key_value(skinconf, "Font2CharWidth"); if (val) skin->font2_char_width = atoi(val); val = cfg_get_key_value(skinconf, "Font2CharHeight"); if (val) skin->font2_char_height = atoi(val); result = 1; /* load images (symbols, arrows) */ { char tmp[256]; SDL_Surface *tmp_sf; val = cfg_get_key_value(skinconf, "Display.Symbols"); if (val) { snprintf(tmp, 255, "%s/themes/%s/%s", gmu_core_get_base_dir(), skin->name, val); if ((tmp_sf = IMG_Load(tmp))) { skin->display_symbols = SDL_DisplayFormatAlpha(tmp_sf); SDL_FreeSurface(tmp_sf); } } val = cfg_get_key_value(skinconf, "Icon.ArrowUp"); if (val) { snprintf(tmp, 255, "%s/themes/%s/%s", gmu_core_get_base_dir(), skin->name, val); if ((tmp_sf = IMG_Load(tmp))) { skin->arrow_up = SDL_DisplayFormatAlpha(tmp_sf); SDL_FreeSurface(tmp_sf); } } val = cfg_get_key_value(skinconf, "Icon.ArrowDown"); if (val) { snprintf(tmp, 255, "%s/themes/%s/%s", gmu_core_get_base_dir(), skin->name, val); if ((tmp_sf = IMG_Load(tmp))) { skin->arrow_down = SDL_DisplayFormatAlpha(tmp_sf); SDL_FreeSurface(tmp_sf); } } } /* fonts */ { int a, b, c; char tmp[256]; printf("skin: Loading fonts...\n"); snprintf(tmp, 255, "%s/themes/%s/%s", gmu_core_get_base_dir(), skin->name, skin->font_display_name); printf("skin: Loading %s\n", tmp); a = lcd_init(&skin->font_display, tmp, skin->font_display_char_width, skin->font_display_char_height); snprintf(tmp, 255, "%s/themes/%s/%s", gmu_core_get_base_dir(), skin->name, skin->font1_name); printf("skin: Loading %s\n", tmp); b = lcd_init(&skin->font1, tmp, skin->font1_char_width, skin->font1_char_height); snprintf(tmp, 255, "%s/themes/%s/%s", gmu_core_get_base_dir(), skin->name, skin->font2_name); printf("skin: Loading %s\n", tmp); c = lcd_init(&skin->font2, tmp, skin->font2_char_width, skin->font2_char_height); if (a && b && c) printf("skin: Skin data loaded successfully.\n"); else result = 0; } break; default: printf("skin: Invalid file format version: %d.\n", skin->version); skin->version = 0; break; } } cfg_free_config_file_struct(&skinconf); return result; }
static CoverNode* gimmix_covers_plugin_get_metadata (char *arg1, char *arg1d, char *arg2, char *arg2d) { char *url = NULL; CoverNode *node = NULL; char *u_artist = NULL; char *u_title = NULL; nxml_t *nxml = NULL; nxml_data_t *nroot = NULL; nxml_data_t *ndata = NULL; nxml_data_t *nndata = NULL; char *str = NULL; char *location = NULL; nxml_error_t e; u_artist = gimmix_url_encode (arg1d); u_title = gimmix_url_encode (arg2d); location = cfg_get_key_value (conf, "coverart_location"); if (!arg1 && !arg1d) { url = g_strdup_printf (AMAZON_URL1, location, AMAZON_KEY, arg2, u_title); } else { url = g_strdup_printf (AMAZON_URL2, location, AMAZON_KEY, arg1, u_artist, arg2, u_title); } //g_print ("%s\n", url); e = nxml_new (&nxml); nxml_set_timeout (nxml, 20); gimmix_covers_plugin_proxy_init (nxml); nxml_parse_url (nxml, url); nxml_root_element (nxml, &nroot); nxml_find_element (nxml, nroot, "Items", &ndata); nxml_find_element (nxml, ndata, "Item", &nndata); if (nndata) { nxml_data_t *child = NULL; nxml_data_t *d = NULL; nxml_data_t *t = NULL; child = nndata; node = gimmix_cover_node_new (); /* large image */ nxml_find_element (nxml, child, "LargeImage", &d); nxml_find_element (nxml, d, "URL", &t); nxml_get_string (t, &str); if (str!=NULL) { node->img_large = g_strdup (str); free (str); } /* medium image */ nxml_find_element (nxml, child, "MediumImage", &d); nxml_find_element (nxml, d, "URL", &t); nxml_get_string (t, &str); if (str!=NULL) { node->img_medium = g_strdup (str); free (str); str = NULL; } /* small image */ nxml_find_element (nxml, child, "SmallImage", &d); nxml_find_element (nxml, d, "URL", &t); nxml_get_string (t, &str); if (str!=NULL) { node->img_small = g_strdup (str); free (str); str = NULL; } /* editorial reviews */ nxml_find_element (nxml, child, "EditorialReviews", &d); nxml_find_element (nxml, d, "EditorialReview", &t); nxml_find_element (nxml, t, "Content", &d); nxml_get_string (d, &str); if (str!=NULL) { g_print ("%s\n", str); node->album_info = g_strdup (str); free (str); } } nxml_free (nxml); g_free (url); return node; }
static void gimmix_covers_plugin_find_cover (mpd_Song *s) { CoverNode *node = NULL; char *temp = NULL; char salbum[256] = ""; char sartist[256] = ""; char sperformer[256] = ""; if (s != NULL) { char *result = NULL; guint len = 0; /* first look into the local cover database */ if (!s->artist || !s->album) { gimmix_covers_plugin_set_cover_image_path (result); return; } if (s->artist) len = strlen (s->artist); strncpy (sartist, s->artist, len); g_strstrip (sartist); strncpy (salbum, s->album, strlen(s->album)); g_strstrip (salbum); if (s->performer) { strncpy (sperformer, s->performer, strlen(s->performer)); g_strstrip (sperformer); } temp = g_strdup_printf ("%s-%s", sartist, salbum); gimmix_strcrep (temp, ' ', '_'); result = cfg_get_key_value (cover_db, temp); g_free (temp); //g_print ("result: %s\n", result); if (result!=NULL) { gimmix_covers_plugin_set_cover_image_path (result); g_print ("cover found on disk\n"); return; } /* if not found locally, fetch it from amazon */ else { //g_print ("beginning to fetch \n"); char *ptr = cfg_get_path_to_config_file (COVERS_DIR); temp = g_strdup_printf ("%s/temp.jpg", ptr); g_free (ptr); node = gimmix_covers_plugin_get_metadata ("Artist", sartist, "Title", salbum); if (node!=NULL) { if (gimmix_covers_plugin_download(node->img_large,temp) || gimmix_covers_plugin_download(node->img_medium,temp) || gimmix_covers_plugin_download(node->img_small,temp)) { gimmix_cover_plugin_save_cover (sartist, salbum); gimmix_covers_plugin_save_albuminfo (sartist, salbum, node->album_info); gimmix_covers_plugin_find_cover (s); } g_free (node); g_free (temp); return; } node = gimmix_covers_plugin_get_metadata (NULL, NULL, "Title", salbum); if (node!=NULL) { if (gimmix_covers_plugin_download(node->img_large,temp) || gimmix_covers_plugin_download(node->img_medium,temp) || gimmix_covers_plugin_download(node->img_small,temp)) { gimmix_cover_plugin_save_cover (sartist, salbum); gimmix_covers_plugin_save_albuminfo (sartist, salbum, node->album_info); gimmix_covers_plugin_find_cover (s); } g_free (node); g_free (temp); return; } else { node = gimmix_covers_plugin_get_metadata ("Performer", sperformer, "Title", salbum); if (node!=NULL) { if (gimmix_covers_plugin_download(node->img_large,temp) || gimmix_covers_plugin_download(node->img_medium,temp) || gimmix_covers_plugin_download(node->img_small,temp)) { gimmix_cover_plugin_save_cover (sartist, salbum); gimmix_covers_plugin_save_albuminfo (sartist, salbum, node->album_info); gimmix_covers_plugin_find_cover (s); } g_free (node); g_free (temp); return; } else { /* set default icon */ gimmix_covers_plugin_set_cover_image_path (NULL); } } } } gimmix_covers_plugin_set_cover_image_path (NULL); return; }
/* if default = TRUE, set the default cover */ void gimmix_covers_plugin_update_cover (gboolean defaultc) { guint height; GdkPixbuf *pixbuf = NULL; mpd_Song *s = NULL; g_mutex_lock (mutex); height = h3_size; if (defaultc) { pixbuf = gimmix_covers_plugin_get_default_cover (96, height); gtk_image_set_from_pixbuf (GTK_IMAGE(gimmix_plcbox_image), pixbuf); g_object_unref (pixbuf); pixbuf = gimmix_covers_plugin_get_default_cover (64, 64); gimmix_covers_plugin_set_metadata_image (pixbuf); g_object_unref (pixbuf); if (gimmix_config_get_bool("enable_systray")) { if (gimmix_config_get_bool("enable_notification")) { pixbuf = gimmix_covers_plugin_get_default_cover (48, 48); gimmix_tooltip_set_icon (tooltip, pixbuf); g_object_unref (pixbuf); } } g_mutex_unlock (mutex); goto ret; } else { pixbuf = gimmix_covers_plugin_get_cover_image_of_size (96, height); } sleep (2); g_print ("sleep over\n"); if (mpd_player_get_state(gmo)!=MPD_PLAYER_STOP) { if (mpd_playlist_get_playlist_length(gmo)) s = mpd_playlist_get_current_song (gmo); else s = NULL; } if (pixbuf != NULL) { char *areview = NULL; /* main window cover art */ gtk_image_set_from_pixbuf (GTK_IMAGE(gimmix_plcbox_image), pixbuf); g_object_unref (pixbuf); /* metadata cover art */ if (s!=NULL) pixbuf = gimmix_covers_plugin_get_cover_image_of_size (64, 64); else pixbuf = gimmix_covers_plugin_get_default_cover (64, 64); gimmix_covers_plugin_set_metadata_image (pixbuf); g_object_unref (pixbuf); /* metadata albuminfo */ s = mpd_playlist_get_current_song (gmo); areview = gimmix_covers_plugin_get_albuminfo (s); gimmix_metadata_set_song_details (s, areview); if (areview) g_free (areview); /* also system tray tooltip image */ if (!strncasecmp(cfg_get_key_value(conf,"enable_systray"),"true",4)) { if (!strncasecmp(cfg_get_key_value(conf,"enable_notification"),"true",4)) { pixbuf = gimmix_covers_plugin_get_cover_image_of_size (48, 48); gimmix_tooltip_set_icon (tooltip, pixbuf); g_object_unref (pixbuf); } } } g_mutex_unlock (mutex); ret: /*while (gtk_events_pending()) gtk_main_iteration ();*/ return; }
void gimmix_init (void) { GtkWidget *widget; GtkWidget *progressbox; GtkAdjustment *vol_adj; GdkPixbuf *app_icon; gchar *path; /* Set the application icon */ main_window = glade_xml_get_widget (xml, "main_window"); g_signal_connect (G_OBJECT(main_window), "delete-event", G_CALLBACK(cb_gimmix_main_window_delete_event), NULL); gtk_window_set_default_size (GTK_WINDOW(main_window), -1, 80); gtk_window_resize (GTK_WINDOW(main_window), atoi(cfg_get_key_value(conf, "window_width")), atoi(cfg_get_key_value(conf, "window_height"))); gtk_window_move (GTK_WINDOW(main_window), atoi(cfg_get_key_value(conf, "window_xpos")), atoi(cfg_get_key_value(conf, "window_ypos"))); path = gimmix_get_full_image_path (GIMMIX_APP_ICON); app_icon = gdk_pixbuf_new_from_file_at_size (path, 48, 48, NULL); gtk_window_set_icon (GTK_WINDOW(main_window), app_icon); g_object_unref (app_icon); g_free (path); /* connect the key press signal */ g_signal_connect (G_OBJECT(main_window), "key-press-event", G_CALLBACK(cb_gimmix_key_press), NULL); g_signal_connect (G_OBJECT(main_window), "configure-event", G_CALLBACK(cb_gimmix_main_window_configure_event), (gpointer)glade_xml_get_widget(xml, "volume_window")); /* connect the destroy signal */ g_signal_connect(G_OBJECT(main_window), "destroy", G_CALLBACK(gtk_main_quit), NULL); /* set icons for buttons */ gtk_image_set_from_stock (GTK_IMAGE(glade_xml_get_widget(xml, "image_prev")), "gtk-media-previous", GTK_ICON_SIZE_BUTTON); gtk_image_set_from_stock (GTK_IMAGE(glade_xml_get_widget(xml, "image_play")), "gtk-media-play", GTK_ICON_SIZE_BUTTON); gtk_image_set_from_stock (GTK_IMAGE(glade_xml_get_widget(xml, "image_next")), "gtk-media-next", GTK_ICON_SIZE_BUTTON); gtk_image_set_from_stock (GTK_IMAGE(glade_xml_get_widget(xml, "image_stop")), "gtk-media-stop", GTK_ICON_SIZE_BUTTON); g_signal_connect (G_OBJECT(glade_xml_get_widget (xml, "prev_button")), "clicked", G_CALLBACK(cb_prev_button_clicked), NULL); g_signal_connect (G_OBJECT(glade_xml_get_widget (xml, "play_button")), "clicked", G_CALLBACK(cb_play_button_clicked), NULL); g_signal_connect (G_OBJECT(glade_xml_get_widget (xml, "next_button")), "clicked", G_CALLBACK(cb_next_button_clicked), NULL); g_signal_connect (G_OBJECT(glade_xml_get_widget (xml, "stop_button")), "clicked", G_CALLBACK(cb_stop_button_clicked), NULL); g_signal_connect (G_OBJECT(glade_xml_get_widget (xml, "pref_button")), "clicked", G_CALLBACK(cb_pref_button_clicked), NULL); shuffle_toggle_button = glade_xml_get_widget (xml, "shuffle_toggle"); repeat_toggle_button = glade_xml_get_widget (xml, "repeat_toggle"); volume_window = glade_xml_get_widget (xml, "volume_window"); volume_scale = glade_xml_get_widget (xml, "volume_scale"); volume_button = glade_xml_get_widget (xml, "volume_button"); playlist_button = glade_xml_get_widget (xml, "playlist_button"); playlist_box = glade_xml_get_widget (xml, "playlistbox"); song_label = glade_xml_get_widget (xml, "song_label"); artist_label = glade_xml_get_widget (xml, "artist_label"); search_entry = glade_xml_get_widget (xml, "search_label"); play_button = glade_xml_get_widget (xml, "play_button"); image_play = glade_xml_get_widget (xml, "image_play"); g_signal_connect (G_OBJECT(playlist_button), "button-press-event", G_CALLBACK(cb_playlist_button_press), NULL); if (is_gimmix_repeat (gmo)) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(repeat_toggle_button), TRUE); g_signal_connect (G_OBJECT(repeat_toggle_button), "toggled", G_CALLBACK(cb_repeat_button_toggled), NULL); if (is_gimmix_shuffle (gmo)) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(shuffle_toggle_button), TRUE); g_signal_connect (G_OBJECT(shuffle_toggle_button), "toggled", G_CALLBACK(cb_shuffle_button_toggled), NULL); widget = glade_xml_get_widget (xml, "info_button"); g_signal_connect (G_OBJECT(widget), "button-release-event", G_CALLBACK(cb_info_button_press), NULL); g_signal_connect (G_OBJECT(volume_scale), "value_changed", G_CALLBACK(cb_volume_scale_changed), NULL); g_signal_connect (G_OBJECT(volume_scale), "scroll_event", G_CALLBACK(cb_volume_slider_scroll), NULL); vol_adj = gtk_range_get_adjustment (GTK_RANGE(volume_scale)); gtk_adjustment_set_value (GTK_ADJUSTMENT(vol_adj), mpd_status_get_volume (gmo)); g_signal_connect (G_OBJECT(volume_button), "clicked", G_CALLBACK(cb_volume_button_clicked), volume_window); g_signal_connect (G_OBJECT(volume_button), "scroll_event", G_CALLBACK(cb_volume_slider_scroll), NULL); progress = glade_xml_get_widget (xml,"progress"); progressbox = glade_xml_get_widget (xml,"progress_event_box"); g_signal_connect (G_OBJECT(progressbox), "button_press_event", G_CALLBACK(cb_gimmix_progress_seek), NULL); play_button_tooltip = gtk_tooltips_new (); if (strncasecmp(cfg_get_key_value(conf, "enable_systray"), "true", 4) == 0) { gimmix_create_systray_icon (); } if (strncasecmp(cfg_get_key_value(conf, "full_view_mode"), "true", 4) == 0) { gtk_widget_show (playlist_box); gtk_window_set_resizable (GTK_WINDOW(main_window), TRUE); } else { gtk_widget_hide (playlist_box); gtk_window_set_resizable (GTK_WINDOW(main_window), FALSE); } mpd_status_update (gmo); status = mpd_player_get_state (gmo); if (status == MPD_PLAYER_PLAY) { gimmix_set_song_info (); status = -1; gtk_image_set_from_stock (GTK_IMAGE(image_play), "gtk-media-pause", GTK_ICON_SIZE_BUTTON); gtk_tooltips_set_tip (play_button_tooltip, play_button, _("Pause <x or c>"), NULL); } else if (status == MPD_PLAYER_PAUSE) { gimmix_set_song_info (); } else if (status == MPD_PLAYER_STOP) { gtk_progress_bar_set_text (GTK_PROGRESS_BAR(progress), _("Stopped")); if (strncasecmp(cfg_get_key_value(conf, "enable_systray"), "true", 4) == 0) gtk_progress_bar_set_text (GTK_PROGRESS_BAR(tooltip->progressbar), _("Stopped")); gimmix_show_ver_info (); } g_timeout_add (300, (GSourceFunc)gimmix_timer, NULL); /* connect the main mpd callbacks */ mpd_signal_connect_status_changed (gmo, (StatusChangedCallback)gimmix_status_changed, NULL); mpd_signal_connect_error (gmo, (ErrorCallback)gimmix_mpd_error, NULL); /* initialize playlist and tag editor */ gimmix_playlist_init (); gimmix_tag_editor_init (); gimmix_update_current_playlist (); /* initialize preferences dialog */ gimmix_prefs_init (); g_object_unref (xml); /* show the main window */ gtk_widget_show (main_window); /* check if library needs to be updated on startup */ if (strncasecmp(cfg_get_key_value(conf, "update_on_startup"), "true", 4) == 0) gimmix_library_update (); return; }