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; }
static void gimmix_covers_plugin_save_albuminfo (char *artist, char *album, char *info) { FILE *fp = NULL; char *path = NULL; char *artist_e = NULL; char *album_e = NULL; char *temp = NULL; if (info == NULL || !strlen(info)) return; /* save album info */ artist_e = gimmix_url_encode (artist); album_e = gimmix_url_encode (album); temp = cfg_get_path_to_config_file (COVERS_DIR); path = g_strdup_printf ("%s/%s-%s.albuminfo", temp, artist_e, album_e); if ((fp=fopen(path, "w"))) { fprintf (fp, info); fclose (fp); } g_free (temp); g_free (path); g_free (artist_e); g_free (album_e); return; }
LYRICS_NODE* lyrics_search (void) { gchar *url = NULL; char *path = NULL; LYRICS_NODE *ret = NULL; if (search_artist != NULL && search_title != NULL) { /* first check if the lyrics exist in ~/.lyrics/ */ path = g_strdup_printf ("%s/%s-%s.txt", cfg_get_path_to_config_file(LYRICS_DIR), search_artist, search_title); if (g_file_test(path,G_FILE_TEST_EXISTS)) { GString *str = g_string_new (""); FILE *fp = NULL; char line[PATH_MAX+1] = ""; ret = (LYRICS_NODE*) malloc(sizeof(LYRICS_NODE)); memset (ret, 0, sizeof(LYRICS_NODE)); strncpy (ret->artist, search_artist, strlen(search_artist)); strncpy (ret->title, search_title, strlen(search_title)); fp = fopen (path, "r"); if (fp != NULL) { while (fgets(line, PATH_MAX, fp)) { str = g_string_append (str, line); } ret->lyrics = g_strdup (str->str); g_string_free (str, TRUE); fclose (fp); } g_free (path); return ret; } char *artist_e = lyrics_url_encode (search_artist); char *title_e = lyrics_url_encode (search_title); url = g_strdup_printf ("%s&artist=%s&songtitle=%s", SEARCH_URL, artist_e, title_e); g_free (artist_e); g_free (title_e); //g_print ("%s\n", url); ret = lyrics_perform_search (url); g_free (url); if (ret) { //g_print ("everything ok\n"); if (ret->lyrics != NULL) { FILE *fp = fopen (path, "w"); fprintf (fp, "%s", ret->lyrics); fclose (fp); } } } return ret; }
void gimmix_config_save (void) { char *rcfile; rcfile = cfg_get_path_to_config_file (CONFIG_FILE); cfg_write_config_file (&conf, rcfile); chmod (rcfile, S_IRUSR|S_IWUSR); g_free (rcfile); return; }
void gimmix_lyrics_plugin_init (void) { char *cpath = NULL; lyrics_textview = GTK_WIDGET (gtk_builder_get_object (xml, "lyrics_textview")); g_signal_connect (gtk_builder_get_object (xml,"lyrics_get_btn"), "clicked", G_CALLBACK(cb_gimmix_lyrics_get_btn_clicked), NULL); /* check if .gimmix/lyrics exists */ cpath = cfg_get_path_to_config_file (LYRICS_DIR); g_mkdir_with_parents (cpath, 00755); g_free (cpath); lyrics_dir = cfg_get_path_to_config_file (LYRICS_DIR); return; }
bool gimmix_config_init (void) { char *rcfile; cfg_init_config_file_struct (&conf); cfg_add_key (&conf, "mpd_hostname", "localhost"); cfg_add_key (&conf, "mpd_port", "6600"); cfg_add_key (&conf, "mpd_password", ""); cfg_add_key (&conf, "proxy_enable", "false"); cfg_add_key (&conf, "proxy_host", ""); cfg_add_key (&conf, "proxy_port", "8080"); cfg_add_key (&conf, "music_directory", ""); cfg_add_key (&conf, "enable_systray", "true"); cfg_add_key (&conf, "enable_notification", "true"); cfg_add_key (&conf, "play_on_add", "false"); cfg_add_key (&conf, "stop_on_exit", "false"); cfg_add_key (&conf, "window_xpos", "200"); cfg_add_key (&conf, "window_ypos", "300"); cfg_add_key (&conf, "window_width", "335"); cfg_add_key (&conf, "window_height", "65"); cfg_add_key (&conf, "full_view_mode", "false"); cfg_add_key (&conf, "enable_search", "true"); cfg_add_key (&conf, "pl_column_title_show", "true"); cfg_add_key (&conf, "pl_column_artist_show", "false"); cfg_add_key (&conf, "pl_column_album_show", "false"); cfg_add_key (&conf, "pl_column_length_show", "true"); #ifdef HAVE_COVER_PLUGIN cfg_add_key (&conf, "coverart_enable", "true"); /* set United States as the default cover location */ cfg_add_key (&conf, "coverart_location", "us"); #else cfg_add_key (&conf, "coverart_enable", "false"); #endif cfg_add_key (&conf, "update_on_startup", "false"); rcfile = cfg_get_path_to_config_file (CONFIG_FILE); if (cfg_read_config_file (&conf, rcfile) != 0) { g_free (rcfile); return false; } else { g_free (rcfile); return true; } return false; }
bool gimmix_config_exists (void) { char *config_file; bool status; config_file = cfg_get_path_to_config_file (CONFIG_FILE); if (g_file_test(config_file, G_FILE_TEST_EXISTS)) status = true; else status = false; free (config_file); return status; }
static void gimmix_covers_plugin_cover_db_save (void) { char *rcfile = NULL; rcfile = cfg_get_path_to_config_file (COVERS_DBF); cfg_write_config_file (&cover_db, rcfile); cfg_read_config_file (&cover_db, rcfile); cfg_free_config_file_struct (&cover_db); gimmix_covers_plugin_cover_db_init (); g_free (rcfile); return; }
static void gimmix_covers_plugin_cover_db_init (void) { char *rcfile = NULL; cfg_init_config_file_struct (&cover_db); rcfile = cfg_get_path_to_config_file (COVERS_DBF); if (cfg_read_config_file(&cover_db,rcfile)) { g_error ("cover db init failed\n"); } g_free (rcfile); return; }
void gimmix_lyrics_plugin_init (void) { char *cpath = NULL; lyrics_textview = glade_xml_get_widget (xml, "lyrics_textview"); g_signal_connect (G_OBJECT(glade_xml_get_widget(xml,"lyrics_get_btn")), "clicked", G_CALLBACK(cb_gimmix_lyrics_get_btn_clicked), NULL); /* check if .gimmix/lyrics exists */ cpath = cfg_get_path_to_config_file (LYRICS_DIR); g_mkdir_with_parents (cpath, 00755); g_free (cpath); lyrics_dir = cfg_get_path_to_config_file (LYRICS_DIR); /* initialize mutex */ l_mutex = g_mutex_new (); return; }
static void on_fr_apply_clicked (GtkWidget *widget, gpointer data) { GtkWidget *entry; GtkWidget *s_checkbox; const gchar *host; const gchar *port; const gchar *password; const gchar *dir; gchar *rcfile; entry = glade_xml_get_widget (xml,"fr_hostname"); host = gtk_entry_get_text (GTK_ENTRY(entry)); cfg_add_key (&cf, "mpd_hostname", (char *)host); entry = glade_xml_get_widget (xml,"fr_port"); port = gtk_entry_get_text (GTK_ENTRY(entry)); cfg_add_key (&cf, "mpd_port", (char *)port); entry = glade_xml_get_widget (xml,"fr_password"); password = gtk_entry_get_text (GTK_ENTRY(entry)); cfg_add_key (&cf, "mpd_password", (char *)password); entry = glade_xml_get_widget (xml, "fst_music_dir"); dir = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER(entry)); cfg_add_key (&cf, "music_directory", (char *)dir); s_checkbox = glade_xml_get_widget (xml, "fr_systray_toggle"); if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(s_checkbox))) cfg_add_key (&cf, "enable_systray", "true"); else cfg_add_key (&cf, "enable_systray", "false"); rcfile = cfg_get_path_to_config_file (CONFIG_FILE); cfg_write_config_file (&cf, rcfile); g_free (rcfile); return; }
static void gimmix_cover_plugin_save_cover (char *artist, char *album) { char *artist_e = NULL; char *album_e = NULL; char *old_path = NULL; char *new_path = NULL; char *key = NULL; char *temp = NULL; if (artist == NULL || album == NULL) return; artist_e = gimmix_url_encode (artist); album_e = gimmix_url_encode (album); /* save cover art */ temp = cfg_get_path_to_config_file (COVERS_DIR); old_path = g_strdup_printf ("%s/temp.jpg", temp); new_path = g_strdup_printf ("%s/%s-%s.jpg", temp, artist_e, album_e); g_rename (old_path, new_path); g_free (temp); /* okay, add an entry to covers.db */ key = g_strdup_printf ("%s-%s", artist, album); gimmix_strcrep (key, ' ', '_'); //g_print ("%s\n\n%s\n",key, new_path); cfg_add_key (&cover_db, key, new_path); gimmix_covers_plugin_cover_db_save (); g_free (old_path); g_free (new_path); g_free (artist_e); g_free (album_e); //g_free (key); return; }
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; }
gchar* gimmix_covers_plugin_get_albuminfo (mpd_Song *s) { FILE *fp = NULL; char *artist_e = NULL; char *album_e = NULL; char *path = NULL; char line[256] = ""; char *ret = NULL; char *temp = NULL; char *p = NULL; if (s == NULL) { return NULL; } if (s->artist == NULL || s->album == NULL) { return NULL; } artist_e = gimmix_url_encode (s->artist); album_e = gimmix_url_encode (s->album); temp = cfg_get_path_to_config_file (COVERS_DIR); path = g_strdup_printf ("%s/%s-%s.albuminfo", temp, artist_e, album_e); g_free (artist_e); g_free (album_e); if ((fp=fopen(path,"r"))) { GString *str = g_string_new (""); while (fgets(line,255,fp)) { str = g_string_append (str, line); } fclose (fp); ret = g_strdup (str->str); g_free (path); g_free (temp); g_string_free (str, TRUE); return ret; } artist_e = gimmix_url_encode (s->performer); album_e = gimmix_url_encode (s->album); g_free (path); p = cfg_get_path_to_config_file (COVERS_DIR); path = g_strdup_printf ("%s/%s-%s.albuminfo", p, artist_e, album_e); g_free (p); g_free (temp); g_free (artist_e); g_free (album_e); if ((fp=fopen(path,"r"))) { GString *str = g_string_new (""); while (fgets(line,255,fp)) { str = g_string_append (str, line); } fclose (fp); ret = g_strdup (str->str); g_free (path); g_string_free (str, TRUE); return ret; } g_free (path); return ret; }
static void cb_gimmix_covers_plugin_set_cover_from_file (void) { GtkWidget *dialog; GtkFileFilter *filter = NULL; GtkImage *preview; mpd_Song *song = NULL; gchar *artist = NULL; gchar *album = NULL; if (!(song=mpd_playlist_get_current_song(gmo))) return; artist = (song->artist != NULL) ? g_strdup (song->artist) : NULL; album = (song->album != NULL) ? g_strdup (song->album) : NULL; dialog = gtk_file_chooser_dialog_new ("Open File", GTK_WINDOW(main_window), GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); preview = (GtkImage*)gtk_image_new (); gtk_file_chooser_set_preview_widget (GTK_FILE_CHOOSER(dialog), GTK_WIDGET(preview)); g_signal_connect (GTK_FILE_CHOOSER(dialog), "update-preview", G_CALLBACK (cb_gimmix_covers_plugin_cover_file_preview), preview); filter = gtk_file_filter_new (); gtk_file_filter_set_name (filter, "Images (.jpg)"); gtk_file_filter_add_pattern (filter, "*.jpg"); gtk_file_chooser_add_filter (GTK_FILE_CHOOSER(dialog), filter); if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) { char *filename = NULL; gchar *contents = NULL; gsize len = 0; filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); if (g_file_get_contents(filename, &contents, &len, NULL)) { gchar *temp = NULL; char *p = cfg_get_path_to_config_file (COVERS_DIR); temp = g_strdup_printf ("%s/temp.jpg", p); g_free (p); if (g_file_set_contents (temp, contents, len, NULL)) { if (artist!=NULL && album!=NULL) { gimmix_cover_plugin_save_cover (artist, album); g_thread_create ((GThreadFunc)gimmix_covers_plugin_update_cover, FALSE, FALSE, NULL); g_free (artist); g_free (album); } } else { gimmix_error ("There was an error while setting the album cover. Please try using a different image."); } g_free (temp); } g_free (filename); } gtk_widget_destroy (dialog); return; }