示例#1
0
static void
pragha_scanner_import_playlist (PraghaDatabase *database,
                                const gchar *playlist_file)
{
	gchar *playlist = NULL;
	gint playlist_id = 0;
	GSList *list = NULL, *i = NULL;

	playlist = get_display_filename(playlist_file, FALSE);

	if (pragha_database_find_playlist(database, playlist))
		goto duplicated;

#ifdef HAVE_PLPARSER
	gchar *uri = g_filename_to_uri (playlist_file, NULL, NULL);
	list = pragha_totem_pl_parser_parse_from_uri(uri);
	g_free (uri);
#else
	list = pragha_pl_parser_parse_from_file_by_extension (playlist_file);
#endif

	playlist_id = pragha_database_add_new_playlist (database, playlist);
	if(list) {
		for (i=list; i != NULL; i = i->next) {
			pragha_database_add_playlist_track (database, playlist_id, i->data);
			g_free(i->data);
		}
		g_slist_free(list);
	}

duplicated:
	g_free(playlist);
}
示例#2
0
void
pragha_application_add_location (PraghaApplication *pragha)
{
	PraghaPlaylist *playlist;
	PraghaDatabase *cdbase;
	PraghaMusicobject *mobj;
	GtkWidget *dialog, *table, *uri_entry, *label_name, *name_entry;
	const gchar *uri = NULL, *name = NULL;
	gchar *clipboard_location = NULL, *real_name = NULL;
	GSList *list = NULL, *i = NULL;
	GList *mlist = NULL;
	guint row = 0;
	gint result;

	/* Create dialog window */

	table = pragha_hig_workarea_table_new ();
	pragha_hig_workarea_table_add_section_title(table, &row, _("Enter the URL of an internet radio stream"));

	uri_entry = gtk_entry_new();
	gtk_entry_set_max_length(GTK_ENTRY(uri_entry), 255);

	pragha_hig_workarea_table_add_wide_control (table, &row, uri_entry);

	label_name = gtk_label_new_with_mnemonic(_("Give it a name to save"));
	name_entry = gtk_entry_new();
	gtk_entry_set_max_length(GTK_ENTRY(name_entry), 255);

	pragha_hig_workarea_table_add_row (table, &row, label_name, name_entry);

	/* Get item from clipboard to fill GtkEntry */
	clipboard_location = totem_open_location_set_from_clipboard (uri_entry);
	if (clipboard_location != NULL && strcmp (clipboard_location, "") != 0) {
		gtk_entry_set_text (GTK_ENTRY(uri_entry), clipboard_location);
		g_free (clipboard_location);
	}

	dialog = gtk_dialog_new_with_buttons (_("Add a location"),
	                                      GTK_WINDOW(pragha_application_get_window(pragha)),
	                                      GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
	                                      _("_Cancel"), GTK_RESPONSE_CANCEL,
	                                      _("_Ok"), GTK_RESPONSE_ACCEPT,
	                                      NULL);

	gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);

	gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), table);

	gtk_window_set_default_size(GTK_WINDOW (dialog), 450, -1);

	gtk_entry_set_activates_default (GTK_ENTRY(uri_entry), TRUE);
	gtk_entry_set_activates_default (GTK_ENTRY(name_entry), TRUE);

	gtk_widget_show_all(dialog);

	result = gtk_dialog_run(GTK_DIALOG(dialog));
	switch(result) {
	case GTK_RESPONSE_ACCEPT:
		if (gtk_entry_get_text_length (GTK_ENTRY(uri_entry)))
			uri = gtk_entry_get_text(GTK_ENTRY(uri_entry));

		playlist = pragha_application_get_playlist (pragha);

		if (string_is_not_empty(uri)) {
			if (gtk_entry_get_text_length (GTK_ENTRY(name_entry)))
				name = gtk_entry_get_text(GTK_ENTRY(name_entry));

			#ifdef HAVE_PLPARSER
			list = pragha_totem_pl_parser_parse_from_uri (uri);
			#else
			list = g_slist_append (list, g_strdup(uri));
			#endif

			for (i = list; i != NULL; i = i->next) {
				if (string_is_not_empty(name))
					real_name = new_radio (playlist, i->data, name);

				mobj = new_musicobject_from_location (i->data, real_name);
				mlist = g_list_append(mlist, mobj);

				if (real_name) {
					g_free (real_name);
					real_name = NULL;
				}
				g_free(i->data);
			}
			g_slist_free(list);

			/* Append playlist and save on database */

			pragha_playlist_append_mobj_list (playlist, mlist);
			g_list_free(mlist);

			cdbase = pragha_application_get_database (pragha);
			pragha_database_change_playlists_done (cdbase);
		}
		break;
	case GTK_RESPONSE_CANCEL:
		break;
	default:
		break;
	}
	gtk_widget_destroy(dialog);

	return;
}