示例#1
0
SongIterator Connection::CommitSearchSongs()
{
	prechecksNoCommandsList();
	mpd_search_commit(m_connection.get());
	checkErrors();
	return SongIterator(m_connection.get(), defaultFetcher<Song>(mpd_recv_song));
}
示例#2
0
int mpd_list_artists()
{
    int num = 0;

    mpd_search_db_tags(mpd.conn, MPD_TAG_ARTIST);
    if (!mpd_search_commit(mpd.conn)) {
        syslog(LOG_DEBUG, "%s: search_commit error\n", __func__);
        return 0;
    }

    struct mpd_pair *pair;
    while ((pair = mpd_recv_pair_tag(mpd.conn, MPD_TAG_ARTIST)) != NULL) {
        syslog(LOG_DEBUG, "%s: %s\n", __func__, pair->value);
        mpd_return_pair(mpd.conn, pair);
        num++;
    }

    if (!mpd_response_finish(mpd.conn)) {
        syslog(LOG_DEBUG, "%s: error\n", __func__);
        return 0;
    }

    syslog(LOG_DEBUG, "%s: found %i\n", __func__, num);
    return num;
}
示例#3
0
文件: command.c 项目: daaang/mpc
int
cmd_list(int argc, char **argv, struct mpd_connection *conn)
{
	enum mpd_tag_type type = get_search_type(argv[0]);
	if (type == MPD_TAG_UNKNOWN)
		return -1;

	--argc;
	++argv;

	mpd_search_db_tags(conn, type);

	if (argc > 0 && !add_constraints(argc, argv, conn))
		return -1;

	if (!mpd_search_commit(conn))
		printErrorAndExit(conn);

	struct mpd_pair *pair;
	while ((pair = mpd_recv_pair_tag(conn, type)) != NULL) {
		printf("%s\n", charset_from_utf8(pair->value));
		mpd_return_pair(conn, pair);
	}

	my_finishCommand(conn);
	return 0;
}
示例#4
0
文件: mpd.cpp 项目: kpence/kpmpc
std::string Mpd::getTag(const char *_album, mpd_tag_type type) {
    std::string tagRet = "";
    mpd_song *song;
    if (!mpd_search_db_songs(conn, false)) { err(); return NULL; }

    if (!mpd_search_add_tag_constraint(conn, MPD_OPERATOR_DEFAULT, MPD_TAG_ALBUM, _album)) { err(); return NULL; }

    if (!mpd_search_commit(conn)) { err(); return NULL; }

    if (type == MPD_TAG_UNKNOWN) {
        if ((song = mpd_recv_song(conn)) != NULL) {
            if (mpd_song_get_uri(song) != NULL)
                tagRet = mpd_song_get_uri(song);
            else
                tagRet = "";
        }
    } else if ((song = mpd_recv_song(conn)) != NULL) {
        if (mpd_song_get_tag(song, type, 0) != NULL)
            tagRet = mpd_song_get_tag(song, type, 0);
        else
            tagRet = "";
    }

    mpd_song_free(song);

    if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS) { err(); return NULL; }

    if (!mpd_response_finish(conn)) { err(); return NULL; }

    return tagRet;
}
示例#5
0
文件: mpd.cpp 项目: kpence/kpmpc
/* mpd functions */
bool Mpd::update(mpd_tag_type type, const char *value) {
    mpd_pair *pair;
    album.clear();

    if (!mpd_search_db_tags(conn, MPD_TAG_ALBUM)) { err(); return false; }

    if (strcmp(value, "") != 0)
        if (!mpd_search_add_tag_constraint(conn, MPD_OPERATOR_DEFAULT, type, value)) { err(); return false; }

    if (!mpd_search_commit(conn)) { err(); return false; }

    while ((pair = mpd_recv_pair_tag(conn, MPD_TAG_ALBUM)) != NULL) {
        album.push_back(Album(pair->value));
        mpd_return_pair(conn, pair);
    }

    if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS) { err(); return false; }

    if (!mpd_response_finish(conn)) { err(); return false; }

    cout << "Successful Update" << endl;
    for (std::vector<Album>::iterator i = album.begin(); i != album.end(); ++i)
        i->buildTags();
    sys->sortAlbums(MPD_TAG_UNKNOWN);
    for (std::vector<Album>::iterator i = album.begin(); i != album.end(); ++i)
        i->build();
    return true;
}
示例#6
0
int
cmd_findadd(int argc, char **argv, struct mpd_connection *conn)
{
    mpd_search_add_db_songs(conn, true);
    if (!add_constraints(argc, argv, conn))
        return -1;

    if (!mpd_search_commit(conn))
        printErrorAndExit(conn);

    my_finishCommand(conn);
    return 0;
}
示例#7
0
文件: search.c 项目: cykerway/ncmpcr
static int fetch_items(MENU_SEARCH *menu,char *str,CLIENT_OBJECT *cli,DB_OBJECT *db)
{
    if (!(str && strlen(str)))
        return 1;

    /* send query */
    if (!mpd_search_db_songs(cli->conn,false))
        clear_or_exit_on_error(cli->conn);
    if (!mpd_search_add_tag_constraint(cli->conn,MPD_OPERATOR_DEFAULT,MPD_TAG_TITLE,str))
        clear_or_exit_on_error(cli->conn);
    if (!mpd_search_commit(cli->conn))
        clear_or_exit_on_error(cli->conn);

    /* process response */
    int block = 1024;
    menu->items = (MENU_SEARCH_ITEM*)calloc(block,sizeof(MENU_SEARCH_ITEM));

    struct mpd_song *song;
    int i = 0;
	while ((song = mpd_recv_song(cli->conn))) {

        /* realloc if memory not enough */
        if (i >= block) {
            block *= 2;
            menu->items = (MENU_SEARCH_ITEM*)realloc(menu->items,block*sizeof(MENU_SEARCH_ITEM));
        }

        unsigned id = mpd_song_get_id(song);
        const char *uri = mpd_song_get_uri(song);
        const char *title = mpd_song_get_tag(song,MPD_TAG_TITLE,0);

        menu->items[i].id = id;
        menu->items[i].title = (char *)malloc((strlen(title)+1)*sizeof(char));
        strcpy(menu->items[i].title,title);
        menu->items[i++].node = get_node_by_uri(db,uri);

		mpd_song_free(song);

	}

    if (mpd_connection_get_error(cli->conn) == MPD_ERROR_SUCCESS)
        mpd_response_finish(cli->conn);
    else
        clear_or_exit_on_error(cli->conn);

    menu->num = i;

    return 0;
}
示例#8
0
文件: main.c 项目: rborisov/pircar
static int do_search(int argc, char ** argv, struct mpd_connection *conn, bool exact)
{
    mpd_search_db_songs(conn, exact);
    if (!add_constraints(argc, argv, conn))
        return -1;

    if (!mpd_search_commit(conn))
        printErrorAndExit(conn);

    print_entity_list(conn, MPD_ENTITY_TYPE_SONG);

    my_finishCommand(conn);

    return 0;
}
示例#9
0
static int do_search ( int argc, char ** argv, struct mpd_connection *conn, int exact )
{
    mpd_search_db_songs(conn, exact);
    if (!add_constraints(argc, argv, conn))
        return -1;

    if (!mpd_search_commit(conn))
        printErrorAndExit(conn);

    print_filenames(conn);

    my_finishCommand(conn);

    return 0;
}
示例#10
0
文件: mpd_client.c 项目: kvbx/ympd
int mpd_search(char *buffer, char *searchstr)
{
    int i = 0;
    char *cur = buffer;
    const char *end = buffer + MAX_SIZE;
    struct mpd_song *song;

    if(mpd_search_db_songs(mpd.conn, false) == false)
        RETURN_ERROR_AND_RECOVER("mpd_search_db_songs");
    else if(mpd_search_add_any_tag_constraint(mpd.conn, MPD_OPERATOR_DEFAULT, searchstr) == false)
        RETURN_ERROR_AND_RECOVER("mpd_search_add_any_tag_constraint");
    else if(mpd_search_commit(mpd.conn) == false)
        RETURN_ERROR_AND_RECOVER("mpd_search_commit");
    else {
        cur += json_emit_raw_str(cur, end - cur, "{\"type\":\"search\",\"data\":[ ");

        while((song = mpd_recv_song(mpd.conn)) != NULL) {
            cur += json_emit_raw_str(cur, end - cur, "{\"type\":\"song\",\"uri\":");
            cur += json_emit_quoted_str(cur, end - cur, mpd_song_get_uri(song));
            cur += json_emit_raw_str(cur, end - cur, ",\"album\":");
            cur += json_emit_quoted_str(cur, end - cur, mpd_get_album(song));
            cur += json_emit_raw_str(cur, end - cur, ",\"artist\":");
            cur += json_emit_quoted_str(cur, end - cur, mpd_get_artist(song));
            cur += json_emit_raw_str(cur, end - cur, ",\"duration\":");
            cur += json_emit_int(cur, end - cur, mpd_song_get_duration(song));
            cur += json_emit_raw_str(cur, end - cur, ",\"title\":");
            cur += json_emit_quoted_str(cur, end - cur, mpd_get_title(song));
            cur += json_emit_raw_str(cur, end - cur, "},");
            mpd_song_free(song);

            /* Maximum results */
            if(i++ >= 300)
            {
                cur += json_emit_raw_str(cur, end - cur, "{\"type\":\"wrap\"},");
                break;
            }
        }

        /* remove last ',' */
        cur--;

        cur += json_emit_raw_str(cur, end - cur, "]}");
    }
    return cur - buffer;
}
示例#11
0
StringIterator Connection::GetList(mpd_tag_type type)
{
	prechecksNoCommandsList();
	mpd_search_db_tags(m_connection.get(), type);
	mpd_search_commit(m_connection.get());
	checkErrors();
	return StringIterator(m_connection.get(), [type](StringIterator::State &state) {
		auto src = mpd_recv_pair_tag(state.connection(), type);
		if (src != nullptr)
		{
			state.setObject(src->value);
			mpd_return_pair(state.connection(), src);
			return true;
		}
		else
			return false;
	});
}
示例#12
0
文件: main.c 项目: rborisov/pircar
static int find_songname_id(struct mpd_connection *conn, const char *s)
{
    int res = -1;

    mpd_search_queue_songs(conn, false);

    const char *pattern = s; //charset_to_utf8(s);
    mpd_search_add_any_tag_constraint(conn, MPD_OPERATOR_DEFAULT,
                           pattern);
    mpd_search_commit(conn);

    struct mpd_song *song = mpd_recv_song(conn);
    if (song != NULL) {
        res = mpd_song_get_id(song);

        mpd_song_free(song);
    }

    my_finishCommand(conn);

    return res;
}
示例#13
0
void TopWidget::updateAlbumList()
{
	albumList.clear();
	albumList << "(Any)";
	mpdconfirm(mpd_search_db_tags(mpd, MPD_TAG_ALBUM));
	if (selectedArtist != "(Any)")
		mpd_search_add_tag_constraint(mpd, MPD_OPERATOR_DEFAULT, MPD_TAG_ARTIST, selectedArtist.toUtf8().constData());
	mpd_search_commit(mpd);
	mpd_pair * mp;
	while((mp = mpd_recv_pair_tag(mpd, MPD_TAG_ALBUM)) != NULL)
	{
		const QString album = mp->value;
		if (album != "")
			albumList << album;
		mpd_return_pair(mpd, mp);
	}
	albumListWidget->setModel(albumModel);
	albumModel->setStringList(albumList);
	parent->setTracks(Track::searchByArtist(selectedArtist));
	parent->playlistChanged = true;
	parent->trackView->update();
	parent->trackView->resetScroll();
	
}
示例#14
0
int main(int argc, char *argv[]) {
	int opts;

	const char   *short_opts  = "t:r:b:a:p:s:h";
	struct option long_opts[] = {
		{ "title",	required_argument,	0, 't' },
		{ "artist",	required_argument,	0, 'r' },
		{ "album",	required_argument,	0, 'b' },
		{ "addr",	required_argument,	0, 'a' },
		{ "port",	required_argument,	0, 'p' },
		{ "secret",	required_argument,	0, 's' },
		{ "help",	no_argument,		0, 'h' },
		{ 0,		0,			0,  0  }
	};

	unsigned int id = 0;

	struct mpd_song *song = NULL;
	struct mpd_connection *mpd = NULL;

	char *mpd_addr = getenv("MPD_HOST");
	int   mpd_port = getenv("MPD_PORT") ? atoi(getenv("MPD_PORT")) : 0;
	char *mpd_pass = NULL;

	char *title  = NULL;
	char *artist = NULL;
	char *album  = NULL;

	if (argc == 1) {
		help();
		return -1;
	}

	while ((opts = getopt_long(argc, argv, short_opts, long_opts, 0)) != -1) {
		switch (opts) {
			case 't': { title = optarg;		break;     }
			case 'r': { artist = optarg;		break;     }
			case 'b': { album = optarg;		break;     }
			case 'a': { mpd_addr = optarg;		break;     }
			case 'p': { mpd_port = atoi(optarg);	break;     }
			case 's': { mpd_pass = optarg;		break;     }
			default :
			case 'h': { help();			return -1; }
		}
	}

	mpd = mpd_connection_new(mpd_addr, mpd_port, 30000);
	CHECK_MPD_CONN(mpd);

	if (mpd_pass != NULL) {
		mpd_run_password(mpd, mpd_pass);
		CHECK_MPD_CONN(mpd);
	}

	mpd_search_queue_songs(mpd, false);

	if (title) {
		mpd_search_add_tag_constraint(
			mpd, MPD_OPERATOR_DEFAULT,
			MPD_TAG_TITLE, title
		);
	}

	if (artist) {
		mpd_search_add_tag_constraint(
			mpd, MPD_OPERATOR_DEFAULT,
			MPD_TAG_ARTIST, artist
		);
	}

	if (album) {
		mpd_search_add_tag_constraint(
			mpd, MPD_OPERATOR_DEFAULT,
			MPD_TAG_ALBUM, album
		);
	}

	mpd_search_commit(mpd);

	song = mpd_recv_song(mpd);

	mpd_response_finish(mpd);

	if (song) {
		id = mpd_song_get_id(song);

		mpd_song_free(song);

		mpd_run_play_id(mpd, id);
		CHECK_MPD_CONN(mpd);
	}

	mpd_connection_free(mpd);

	return 0;
}
示例#15
0
文件: example.c 项目: Fyzick/capstone
int main(int argc, char ** argv) {
	struct mpd_connection *conn;

	conn = mpd_connection_new(NULL, 0, 30000);

	if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS)
		return handle_error(conn);

	{
		int i;
		for(i=0;i<3;i++) {
			printf("version[%i]: %i\n",i,
			       mpd_connection_get_server_version(conn)[i]);
		}
	}

	if(argc==1) {
		struct mpd_status * status;
		struct mpd_song *song;
		const struct mpd_audio_format *audio_format;

		mpd_command_list_begin(conn, true);
		mpd_send_status(conn);
		mpd_send_current_song(conn);
		mpd_command_list_end(conn);

		status = mpd_recv_status(conn);
		if (status == NULL)
			return handle_error(conn);

		printf("volume: %i\n", mpd_status_get_volume(status));
		printf("repeat: %i\n", mpd_status_get_repeat(status));
		printf("queue version: %u\n", mpd_status_get_queue_version(status));
		printf("queue length: %i\n", mpd_status_get_queue_length(status));
		if (mpd_status_get_error(status) != NULL)
			printf("error: %s\n", mpd_status_get_error(status));

		if (mpd_status_get_state(status) == MPD_STATE_PLAY ||
		    mpd_status_get_state(status) == MPD_STATE_PAUSE) {
			printf("song: %i\n", mpd_status_get_song_pos(status));
			printf("elaspedTime: %i\n",mpd_status_get_elapsed_time(status));
			printf("elasped_ms: %u\n", mpd_status_get_elapsed_ms(status));
			printf("totalTime: %i\n", mpd_status_get_total_time(status));
			printf("bitRate: %i\n", mpd_status_get_kbit_rate(status));
		}

		audio_format = mpd_status_get_audio_format(status);
		if (audio_format != NULL) {
			printf("sampleRate: %i\n", audio_format->sample_rate);
			printf("bits: %i\n", audio_format->bits);
			printf("channels: %i\n", audio_format->channels);
		}

		mpd_status_free(status);

		if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS)
			return handle_error(conn);

		mpd_response_next(conn);

		while ((song = mpd_recv_song(conn)) != NULL) {
			printf("uri: %s\n", mpd_song_get_uri(song));
			print_tag(song, MPD_TAG_ARTIST, "artist");
			print_tag(song, MPD_TAG_ALBUM, "album");
			print_tag(song, MPD_TAG_TITLE, "title");
			print_tag(song, MPD_TAG_TRACK, "track");
			print_tag(song, MPD_TAG_NAME, "name");
			print_tag(song, MPD_TAG_DATE, "date");

			if (mpd_song_get_duration(song) > 0) {
				printf("time: %u\n", mpd_song_get_duration(song));
			}

			printf("pos: %u\n", mpd_song_get_pos(song));

			mpd_song_free(song);
		}

		if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS ||
		    !mpd_response_finish(conn))
			return handle_error(conn);
	}
	else if(argc==3 && strcmp(argv[1],"lsinfo")==0) {
		struct mpd_entity * entity;

		if (!mpd_send_list_meta(conn, argv[2]))
			return handle_error(conn);

		while ((entity = mpd_recv_entity(conn)) != NULL) {
			const struct mpd_song *song;
			const struct mpd_directory *dir;
			const struct mpd_playlist *pl;

			switch (mpd_entity_get_type(entity)) {
			case MPD_ENTITY_TYPE_UNKNOWN:
				break;

			case MPD_ENTITY_TYPE_SONG:
				song = mpd_entity_get_song(entity);
				printf("uri: %s\n", mpd_song_get_uri(song));
				print_tag(song, MPD_TAG_ARTIST, "artist");
				print_tag(song, MPD_TAG_ALBUM, "album");
				print_tag(song, MPD_TAG_TITLE, "title");
				print_tag(song, MPD_TAG_TRACK, "track");
				break;

			case MPD_ENTITY_TYPE_DIRECTORY:
				dir = mpd_entity_get_directory(entity);
				printf("directory: %s\n", mpd_directory_get_path(dir));
				break;

			case MPD_ENTITY_TYPE_PLAYLIST:
				pl = mpd_entity_get_playlist(entity);
				printf("playlist: %s\n",
				       mpd_playlist_get_path(pl));
				break;
			}

			mpd_entity_free(entity);
		}

		if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS ||
		    !mpd_response_finish(conn))
			return handle_error(conn);
	}
	else if(argc==2 && strcmp(argv[1],"artists")==0) {
		struct mpd_pair *pair;

		if (!mpd_search_db_tags(conn, MPD_TAG_ARTIST) ||
		    !mpd_search_commit(conn))
			return handle_error(conn);

		while ((pair = mpd_recv_pair_tag(conn,
						 MPD_TAG_ARTIST)) != NULL) {
			printf("%s\n", pair->value);
			mpd_return_pair(conn, pair);
		}

		if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS ||
		    !mpd_response_finish(conn))
			return handle_error(conn);
	} else if (argc == 2 && strcmp(argv[1], "playlists") == 0) {
		if (!mpd_send_list_playlists(conn))
			return handle_error(conn);

		struct mpd_playlist *playlist;
		while ((playlist = mpd_recv_playlist(conn)) != NULL) {
			printf("%s\n",
			       mpd_playlist_get_path(playlist));
			mpd_playlist_free(playlist);
		}

		if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS ||
		    !mpd_response_finish(conn))
			return handle_error(conn);
	} else if (argc == 2 && strcmp(argv[1], "idle") == 0) {
		enum mpd_idle idle = mpd_run_idle(conn);
		if (idle == 0 &&
		    mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS)
			return handle_error(conn);

		for (unsigned j = 0;; ++j) {
			enum mpd_idle i = 1 << j;
			const char *name = mpd_idle_name(i);

			if (name == NULL)
				break;

			if (idle & i)
				printf("%s\n", name);
		}
	} else if (argc == 3 && strcmp(argv[1], "subscribe") == 0) {
		/* subscribe to a channel and print all messages */

		if (!mpd_run_subscribe(conn, argv[2]))
			return handle_error(conn);

		while (mpd_run_idle_mask(conn, MPD_IDLE_MESSAGE) != 0) {
			if (!mpd_send_read_messages(conn))
				return handle_error(conn);

			struct mpd_message *msg;
			while ((msg = mpd_recv_message(conn)) != NULL) {
				printf("%s\n", mpd_message_get_text(msg));
				mpd_message_free(msg);
			}

			if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS ||
			    !mpd_response_finish(conn))
				return handle_error(conn);
		}

		return handle_error(conn);
	} else if (argc == 2 && strcmp(argv[1], "channels") == 0) {
		/* print a list of channels */

		if (!mpd_send_channels(conn))
			return handle_error(conn);

		struct mpd_pair *pair;
		while ((pair = mpd_recv_channel_pair(conn)) != NULL) {
			printf("%s\n", pair->value);
			mpd_return_pair(conn, pair);
		}

		if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS ||
		    !mpd_response_finish(conn))
			return handle_error(conn);
	} else if (argc == 4 && strcmp(argv[1], "message") == 0) {
		/* send a message to a channel */

		if (!mpd_run_send_message(conn, argv[2], argv[3]))
			return handle_error(conn);
	}

	mpd_connection_free(conn);

	return 0;
}
示例#16
0
TopWidget::TopWidget(MainWindow * parent) : QWidget(parent)
{
	this->parent = parent;
	setMinimumWidth(300);
	setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);

	stopButton = new QToolButton();
	stopButton->setIcon(QIcon(DATAPATH "stop.png"));
	pauseButton = new QToolButton();
	pauseButton->setIcon(QIcon(DATAPATH "pause.png"));
	playButton = new QToolButton();
	playButton->setIcon(QIcon(DATAPATH "play.png"));
	prevButton = new QToolButton();
	prevButton->setIcon(QIcon(DATAPATH "prev.png"));
	nextButton = new QToolButton();
	nextButton->setIcon(QIcon(DATAPATH "next.png"));
	randomButton = new QToolButton();
	randomButton->setIcon(QIcon(DATAPATH "random.png"));
	libraryButton = new QToolButton();
	if(Settings::getLibraryFolded())
		libraryButton->setIcon(QIcon(DATAPATH "unfold.png"));
	else
		libraryButton->setIcon(QIcon(DATAPATH "fold.png"));

	trackBar = new Slider(parent);
	volumeBar = new Slider(parent);
	volumeBar->setMaximumWidth(70);
	volumeBar->setValue(100);
	volumeBar->style = 2;

	playModeBox = new QComboBox();
	playModeBox->setMaximumWidth(150);
	playModeBox->addItem("Normal");
	playModeBox->addItem("Loop All");
	playModeBox->addItem("Loop Track");
	playModeBox->addItem("Shuffle");

	grid = new QGridLayout();
	grid->addWidget(stopButton, 0, 0);
	grid->addWidget(pauseButton, 0, 1);
	grid->addWidget(playButton, 0, 2);
	grid->addWidget(prevButton, 0, 3);
	grid->addWidget(nextButton, 0, 4);
	grid->addWidget(randomButton, 0, 5);
	grid->addWidget(trackBar, 0, 6);
	grid->addWidget(playModeBox, 0, 7);
	grid->addWidget(volumeBar, 0, 8);
	grid->addWidget(libraryButton, 0, 9);
	grid->setContentsMargins(4, 4, 4, 4);

	connect(trackBar, SIGNAL(changed()), this, SLOT(onTrackBarChanged()));
	connect(volumeBar, SIGNAL(step()), this, SLOT(onVolumeBarChanged()));
	connect(pauseButton, SIGNAL(clicked()), this, SLOT(onPauseClick()));
	connect(playButton, SIGNAL(clicked()), this, SLOT(onPlayClick()));
	connect(stopButton, SIGNAL(clicked()), this, SLOT(onStopClick()));
	connect(prevButton, SIGNAL(clicked()), this, SLOT(onPrevClick()));
	connect(nextButton, SIGNAL(clicked()), this, SLOT(onNextClick()));
	connect(libraryButton, SIGNAL(clicked()), this, SLOT(onLibraryClick()));
	setLayout(grid);

	//Library View
	libraryWidget = new QWidget();
	libraryGrid = new QGridLayout();
	artistLabel = new QLabel("Artists: ");
	artistListWidget = new QListView();
	artistListWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
	artistModel = new QStringListModel();
	albumLabel = new QLabel("Albums: ");
	albumListWidget = new QListView();
	albumListWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
	albumModel = new QStringListModel();
	libraryGrid->addWidget(artistLabel, 1, 0);
	libraryGrid->addWidget(artistListWidget, 2, 0);
	libraryGrid->addWidget(albumLabel, 1, 1);
	libraryGrid->addWidget(albumListWidget, 2, 1);
	libraryGrid->setContentsMargins(0, 0, 0, 0);
	libraryWidget->setLayout(libraryGrid);
	if(Settings::getLibraryFolded())
		foldLibrary();
	else
		unfoldLibrary();

	artistList << "(Any)";
	mpdconfirm(mpd_search_db_tags(mpd, MPD_TAG_ARTIST));
	mpd_search_commit(mpd);
	mpd_pair * mp;
	while((mp = mpd_recv_pair_tag(mpd, MPD_TAG_ARTIST)) != NULL)
	{
		const QString artist = mp->value;
		if (artist != "")
			artistList << artist;
		mpd_return_pair(mpd, mp);
	}
	artistListWidget->setModel(artistModel);
	artistModel->setStringList(artistList);

	albumListWidget->setModel(albumModel);
	albumModel->setStringList(albumList);

	connect(artistListWidget->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(onArtistSelectionChanged(QItemSelection)));
	connect(albumListWidget->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(onAlbumSelectionChanged(QItemSelection)));

	artistListWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
	albumListWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);
	selectedArtist = "(Any)";

}