Ejemplo n.º 1
0
/* todo: zrefaktoryzowac update_*table, bo moze wystarczy jedna funckcja? */
static void update_librarytable(AG_Event *event) {

        AG_Table *tbl = AG_SELF();

	if(libraryData) {
        	AG_TableBegin(tbl);

		do {
			if(libraryData->type == MPD_DATA_TYPE_SONG)  {

				if(libraryData->song->file && 
					libraryData->song->title && 
					libraryData->song->artist ) {  
				
					AG_TableAddRow(tbl, "%s:%s:%s:%s",
					libraryData->song->artist, 
					libraryData->song->title,
					format_time(libraryData->song->time),
					libraryData->song->file); 
				}
			}
			libraryData = mpd_data_get_next(libraryData);
		} while(libraryData);

		AG_TableEnd(tbl);
	}
}
Ejemplo n.º 2
0
static void update_playlisttable(AG_Event *event) {

        AG_Table *tbl = AG_SELF();

	if(playlistData) {
        	AG_TableBegin(tbl);

		do {
			if(playlistData->type == MPD_DATA_TYPE_SONG) 
				printf("%i, %s\n", 
				playlistData->song->id,
				playlistData->song->title);
				AG_TableAddRow(tbl, "%s:%s:%s:%i",
					playlistData->song->artist, 
					playlistData->song->title,
					format_time(playlistData->song->time),
					playlistData->song->id);

			playlistData = mpd_data_get_next(playlistData);

			/*if(mpd_data_is_last(playlistData)) {
				printf("last\n");
			}*/

		} while(playlistData);

		AG_TableEnd(tbl);
	}
}
Ejemplo n.º 3
0
/* -------------------------------------------------------------------------- */
static GPtrArray *mpd_get_playlists(struct lcd_stuff_mpd *mpd)
{
    MpdData     *data;
    GPtrArray   *array;

    array = g_ptr_array_new();

    for (data = mpd_database_get_directory(mpd->mpd, "/");
            data != NULL; data = mpd_data_get_next(data)) {
        switch (data->type) {
            case MPD_DATA_TYPE_PLAYLIST:
                g_ptr_array_add(array, g_path_get_basename(data->playlist->path));
                g_free(data->playlist);
                data->playlist = NULL;
                break;

            case MPD_DATA_TYPE_DIRECTORY:
            case MPD_INFO_ENTITY_TYPE_SONG:
                g_free(data->directory);
                data->directory = NULL;
                break;

            default:
                break;
        }
    }

    return array;
}
Ejemplo n.º 4
0
void updatePlayList(MpdObj *mi,thread_data *my_data)
{
    {
        MpdData *data = mpd_playlist_get_changes(mi,-1);
        //my_data->ptr_MPD_info->songList ="";
        if(data)
        {
            //printf("Playlist:""\n");
            std::string buffor;
            my_data->ptr_MPD_info->songList.erase(my_data->ptr_MPD_info->songList.begin(),my_data->ptr_MPD_info->songList.end());
            do{
                if(data->type == MPD_DATA_TYPE_SONG)
                {
                    //printf("%i"": %s - %s\n", data->song->id, data->song->artist, data->song->title);
                    buffor = std::to_string(data->song->id)+" ";
                    if ( data->song->name != NULL){
                        buffor +=std::string(data->song->name)+" ";
                    }
                    if (data->song->artist != NULL){
                        buffor += std::string(data->song->artist)+" ";
                    }
                    if  ( data->song->title != NULL ){
                        buffor +=std::string(data->song->title)+" ";
                    }
                    my_data->ptr_MPD_info->songList.push_back(buffor);
                }
                data = mpd_data_get_next(data);
            }while(data);
        }
    }
}
Ejemplo n.º 5
0
static gboolean serverstats_idle_handler(ss_str * s)
{
    GtkTreeIter iter;
    MpdDBStats *stats = NULL;
    if (s->data == NULL || !mpd_check_connected(connection) || cancel_query)
    {

        if (gtk_tree_model_get_iter_first(s->model, &iter))
        {
            do
            {
                guint d;
                gulong i;
                gchar *value = NULL;
                gtk_tree_model_get(s->model, &iter, 0, &i, -1);
                d = (guint) 100 *(i / (double)s->max_i);
                value = format_time_real(i, "");
                gtk_list_store_set(GTK_LIST_STORE(s->model), &iter, 2, d, 3, value, -1);
                g_free(value);
            } while (gtk_tree_model_iter_next(s->model, &iter));
        }

        if (s->data)
            mpd_data_free(s->data);
        gtk_tree_view_set_model(GTK_TREE_VIEW(serverstats_tree), s->model);
        gtk_tree_view_set_search_column(GTK_TREE_VIEW(serverstats_tree), 1);
        gtk_widget_set_sensitive(GTK_WIDGET(s->box), TRUE);
        gtk_widget_hide(gtk_widget_get_parent(s->pb));

        if (cancel_query)
            gtk_list_store_clear(GTK_LIST_STORE(s->model));
        g_free(s);
        cancel_query = FALSE;
        return FALSE;
    }
    mpd_database_search_stats_start(connection);
    mpd_database_search_add_constraint(connection, s->tag, s->data->tag);

    stats = mpd_database_search_stats_commit(connection);
    if (stats)
    {
        gtk_list_store_prepend(GTK_LIST_STORE(s->model), &iter);
        gtk_list_store_set(GTK_LIST_STORE(s->model), &iter, 0, (unsigned long)(stats->playTime), 1, s->data->tag, -1);
        s->max_i = MAX(s->max_i, stats->playTime);

        mpd_database_search_free_stats(stats);
    }
    /* limit the amount of updating to 0.2 % */
    if ((int)((1000 * s->hits) / s->total) % 5 == 0)
    {
        gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(s->pb), s->hits / (double)s->total);
    }
    s->hits++;
    s->data = mpd_data_get_next(s->data);
    return TRUE;
}
Ejemplo n.º 6
0
static void add_command(gpointer user_data, const char *param)
{
	gulong songs = 0;
	MpdData *data = advanced_search(param, FALSE);
	for (; data; data = mpd_data_get_next(data))
	{

		if ((songs & 16383) == 16383)
		{
			mpd_playlist_queue_commit(connection);
		}
		if (data->type == MPD_DATA_TYPE_SONG)
		{
			mpd_playlist_queue_add(connection, data->song->file);
			songs++;
		}
	}
	mpd_playlist_queue_commit(connection);
}
Ejemplo n.º 7
0
/**
 * Easy command interface
 */
static void output_set(gpointer data, const char *param)
{
	gchar *str_param = g_strstrip(g_strdup(param));
	gchar **split = g_strsplit(str_param, " ", 2);
	if (split)
	{
		int output = -1;
		if (split[0])
		{
			output = (int)strtol(split[0], NULL, 10);
		}
		if (output >= 0)
		{
			/* Default to 'select' if no specific action given */
			if (!split[1] || g_utf8_collate(split[1], _("select")) == 0)
			{
				MpdData *devices = mpd_server_get_output_devices(connection);
				MpdData *d = devices;
				gboolean found = FALSE;

				while (d != NULL && d->output_dev->id != -10)
				{
					if (d->output_dev->id == output)
					{
						found = TRUE;
						break;
					}
					d = mpd_data_get_next(d);
				}

				if (found)
				{
					g_debug("select output %i\n", output);
					d = devices;
					while (d != NULL && d->output_dev->id != -10)
					{
						mpd_server_set_output_device(connection, d->output_dev->id,
													 d->output_dev->id == output ? 1 : 0);
						d = mpd_data_get_next(d);
					}
				} else
				{
					/* Let user know their request failed, otherwise they will likely be mystified */
					gchar *str = g_strdup_printf("Can't select output %i because it does not exist", output);
					g_debug("%s\n", str);
					playlist3_message_show(pl3_messages, str, ERROR_WARNING);
					g_free(str);
				}
			} else if (g_utf8_collate(split[1], _("enable")) == 0)
			{
				g_debug("enable output %i\n", output);
				mpd_server_set_output_device(connection, output, 1);
			} else if (g_utf8_collate(split[1], _("disable")) == 0)
			{
				mpd_server_set_output_device(connection, output, 0);
				g_debug("disable output %i\n", output);
			}
		}
		g_free(split);
	}
	g_free(str_param);
}