static void set_single(gpointer data, const char *param) { int val = mpd_server_check_command_allowed(connection, "single"); if (val == MPD_SERVER_COMMAND_NOT_SUPPORTED) { char * mesg = g_strdup_printf("%s: %s", _("Single"), _("The used MPD server is too old and does not support this.")); playlist3_message_show(pl3_messages,mesg,ERROR_CRITICAL); g_free(mesg); } else if (val == MPD_SERVER_COMMAND_NOT_ALLOWED) { char * mesg = g_strdup_printf("%s: %s", _("Single"), _("You have insufficient permission to use this option.")); playlist3_message_show(pl3_messages, mesg, ERROR_WARNING); g_free(mesg); } else if (val == MPD_SERVER_COMMAND_ALLOWED) { if (g_utf8_collate(param, "on") == 0) { mpd_player_set_single(connection, TRUE); } else if (g_utf8_collate(param, "off") == 0) { mpd_player_set_single(connection, FALSE); } else { mpd_player_set_single(connection, !mpd_player_get_single(connection)); } } }
int mpd_sticker_song_set(MpdObj *mi, const char *path, const char *tag, const char *value) { if(!mpd_check_connected(mi)) { debug_printf(DEBUG_INFO,"not connected\n"); return MPD_NOT_CONNECTED; } if(mpd_server_check_command_allowed(mi, "sticker") != MPD_SERVER_COMMAND_ALLOWED) { debug_printf(DEBUG_WARNING, "Command not allowed\n"); return MPD_SERVER_NOT_SUPPORTED; } if(mpd_lock_conn(mi)) { debug_printf(DEBUG_ERROR,"lock failed\n"); return MPD_LOCK_FAILED; } mpd_sendSetSongSticker(mi->connection,path, tag,value); mpd_finishCommand(mi->connection); if(mpd_unlock_conn(mi)) { debug_printf(DEBUG_ERROR, "Failed to unlock"); return MPD_LOCK_FAILED; } return MPD_OK; }
static void repeat_current_song_command(gpointer user_data, const char *param) { int val = mpd_server_check_command_allowed(connection, "single"); if (val == MPD_SERVER_COMMAND_NOT_SUPPORTED) { char * mesg = g_strdup_printf("%s: %s", _("Repeat current song"), _("The used MPD server is too old and does not support this.")); playlist3_message_show(pl3_messages, mesg, ERROR_CRITICAL); g_free(mesg); } else if (val == MPD_SERVER_COMMAND_NOT_ALLOWED) { char * mesg = g_strdup_printf("%s: %s", _("Repeat current song"), _("You have insufficient permission to use this option.")); playlist3_message_show(pl3_messages,mesg, ERROR_WARNING); g_free(mesg); } else if (val == MPD_SERVER_COMMAND_ALLOWED) { playlist3_message_show(pl3_messages, _("The current song will be forever repeated."), ERROR_INFO); mpd_player_set_repeat(connection, TRUE); mpd_player_set_single(connection, TRUE); } }
MpdData *mpd_database_get_playlist_content(MpdObj *mi,char *playlist) { MpdData *data = NULL; mpd_InfoEntity *ent = NULL; if(!mpd_check_connected(mi)) { debug_printf(DEBUG_WARNING,"not connected\n"); return NULL; } if(!mpd_server_check_version(mi, 0,12,0)) { debug_printf(DEBUG_WARNING, "only works with mpd higher then 0.12.0"); return NULL; } if(mpd_server_check_command_allowed(mi, "listplaylistinfo") != MPD_SERVER_COMMAND_ALLOWED) { debug_printf(DEBUG_WARNING, "Listing playlist content not supported or allowed"); return NULL; } if(mpd_lock_conn(mi)) { debug_printf(DEBUG_WARNING,"lock failed\n"); return NULL; } mpd_sendListPlaylistInfoCommand(mi->connection, playlist); while (( ent = mpd_getNextInfoEntity(mi->connection)) != NULL) { data = mpd_new_data_struct_append( data ); if(ent->type == MPD_INFO_ENTITY_TYPE_DIRECTORY) { data->type = MPD_DATA_TYPE_DIRECTORY; data->directory = ent->info.directory->path; ent->info.directory->path = NULL; } else if (ent->type == MPD_INFO_ENTITY_TYPE_SONG) { data->type = MPD_DATA_TYPE_SONG; data->song = ent->info.song; ent->info.song = NULL; } else if (ent->type == MPD_INFO_ENTITY_TYPE_PLAYLISTFILE) { data->type = MPD_DATA_TYPE_PLAYLIST; data->playlist = ent->info.playlistFile->path; ent->info.playlistFile->path = NULL; } mpd_freeInfoEntity(ent); } mpd_finishCommand(mi->connection); /* unlock */ mpd_unlock_conn(mi); if(data == NULL) { return NULL; } return mpd_data_get_first(data); }
int mpd_sticker_supported ( MpdObj *mi) { if(mi == NULL) return FALSE; if(mpd_server_check_command_allowed(mi, "sticker") == MPD_SERVER_COMMAND_ALLOWED) { return TRUE; } return FALSE; }
char * mpd_sticker_song_get(MpdObj *mi, const char *path, const char *tag) { char *retv_value = NULL; char *retv = NULL; if(!mpd_check_connected(mi)) { debug_printf(DEBUG_INFO,"not connected\n"); return NULL; } if(mpd_server_check_command_allowed(mi, "sticker") != MPD_SERVER_COMMAND_ALLOWED) { debug_printf(DEBUG_WARNING, "Command not allowed\n"); return NULL; } if(mpd_lock_conn(mi)) { debug_printf(DEBUG_ERROR,"lock failed\n"); return NULL; } mpd_sendGetSongSticker(mi->connection,path, tag); retv_value = mpd_getNextSticker(mi->connection); mpd_finishCommand(mi->connection); if(retv_value && strlen(retv_value) > strlen(tag)){ retv = g_strdup(&retv_value[strlen(tag)]+1); } free(retv_value); if(mi->connection->error == MPD_ERROR_ACK && mi->connection->errorCode == MPD_ACK_ERROR_NO_EXIST) { mpd_clearError(mi->connection); g_free(retv); retv = NULL; } if(mpd_unlock_conn(mi)) { debug_printf(DEBUG_ERROR, "Failed to unlock"); g_free(retv); return NULL; } return retv; }
static void update_database_command(gpointer user_data, const char *param) { int val = mpd_server_check_command_allowed(connection, "update"); if (val == MPD_SERVER_COMMAND_NOT_SUPPORTED) { char * mesg = g_strdup_printf("%s: %s", _("Update database"), _("The used MPD server is too old and does not support this.")); playlist3_message_show(pl3_messages, mesg, ERROR_CRITICAL); g_free(mesg); } else if (val == MPD_SERVER_COMMAND_NOT_ALLOWED) { char * mesg = g_strdup_printf("%s: %s", _("Update database"), _("You have insufficient permission to use this option.")); playlist3_message_show(pl3_messages,mesg, ERROR_WARNING); g_free(mesg); } else if (val == MPD_SERVER_COMMAND_ALLOWED) { mpd_database_update_dir(connection, "/"); } }
int mpd_playlist_set_priority(MpdObj *mi, int song_id, int priority) { if(!mpd_check_connected(mi)) { debug_printf(DEBUG_WARNING,"not connected\n"); return MPD_NOT_CONNECTED; } if(mpd_server_check_command_allowed(mi, "prioid") != MPD_SERVER_COMMAND_ALLOWED) { return MPD_SERVER_NOT_SUPPORTED; } if(mpd_lock_conn(mi)) { debug_printf(DEBUG_ERROR,"lock failed\n"); return MPD_LOCK_FAILED; } mpd_sendSetPrioId(mi->connection,priority, song_id); mpd_finishCommand(mi->connection); /* unlock */ mpd_unlock_conn(mi); return MPD_OK; }
void control_window_status_update(MpdObj * mi, ChangedStatusType what, GtkWidget *base) { GtkWidget *volume_button, *progress, *play_image; /* Bail out of base == NULL */ if(base == NULL) return; /* Get the different subwidgets from the parent */ volume_button = g_object_get_data(G_OBJECT(base), "vol"); progress = g_object_get_data(G_OBJECT(base), "progress"); play_image = g_object_get_data(G_OBJECT(base), "play_image"); if (what & MPD_CST_STATE) { int state = mpd_player_get_state(mi); switch (state) { case MPD_PLAYER_PLAY: gtk_image_set_from_stock(GTK_IMAGE(play_image), "gtk-media-pause", GTK_ICON_SIZE_BUTTON); break; case MPD_PLAYER_PAUSE: gtk_image_set_from_stock(GTK_IMAGE(play_image), "gtk-media-play", GTK_ICON_SIZE_BUTTON); break; default: gtk_image_set_from_stock(GTK_IMAGE(play_image), "gtk-media-play", GTK_ICON_SIZE_BUTTON); /* Make sure it's reset correctly */ gmpc_progress_set_time(GMPC_PROGRESS(progress), 0, 0); } } if (what & MPD_CST_ELAPSED_TIME) { if (mpd_check_connected(connection)) { int totalTime = mpd_status_get_total_song_time(connection); int elapsedTime = mpd_status_get_elapsed_song_time(connection); gmpc_progress_set_time(GMPC_PROGRESS(progress), totalTime, elapsedTime); } else { gmpc_progress_set_time(GMPC_PROGRESS(progress), 0, 0); } } if (what & MPD_CST_VOLUME) { int volume = gtk_scale_button_get_value(GTK_SCALE_BUTTON(volume_button))*100; int new_volume = mpd_status_get_volume(connection); if (new_volume >= 0 && mpd_server_check_command_allowed(connection, "setvol") == MPD_SERVER_COMMAND_ALLOWED ) { gtk_widget_set_sensitive(volume_button, TRUE); /* don't do anything if nothing is changed */ if (new_volume != volume) { gtk_scale_button_set_value(GTK_SCALE_BUTTON(volume_button), new_volume/100.0); } } else { gtk_widget_set_sensitive(volume_button, FALSE); } } }