Exemplo n.º 1
0
// Search button handler for the search button on the main page
void gui::search_button_handler()
{
	// Clear both playlist and song list widgets and update the playlist list widget
	playslists->clear();
	songs->clear();
	update_playlists();
}
Exemplo n.º 2
0
// Button handler for saving manually added playlists
void gui::add_save_playlist_button_handler()
{
	// Try getting popularity as an integer
	int popularity;
	popularity = atoi(add_popularity->text().toStdString().c_str());
	std::stringstream out;
	out << popularity;

	// Verify that popularity is an integer and its greater than 0
	if (add_popularity->text().length() == (int)out.str().length() && popularity >= 0)
	{
		// Create a temporary playlist object
		playlist_obj temp;
		temp.songs = add_songs;
		temp.popularity = popularity;

		// Try saving the playlist
		if (list_of_playlists->insert_playlist(temp))
		{
			// If successful, reset add page and return to main page
			add_songs.clear();
			add_displayed_song = NULL;
			add_selected_songs_list->clear();
			add_popularity->setText("0");
			add_search_song->setText("");
			add_load_file->setText("");
			add_selected_song_label->setText("-- No song selected --");
			window->setCurrentIndex(0);
			
			// Rebuild the trie to update all preprocessed values
			// - Four suggested songs
			// - Eight most popular playlists
			delete trie;
			build_trie();

			// Update the playlist widget to reflect changes
			playslists->clear();
			update_playlists();
		}
		else
		{
			// If not successful with saving playlist, show error message
			QMessageBox messageBox;
			messageBox.setWindowTitle("Error");
    		messageBox.setText("Error Adding Playlist. Playlist Not Added");
   			messageBox.exec();
		}
	}
	else
	{
		// If popularity entry is invalid, show error message
		QMessageBox messageBox;
		messageBox.setWindowTitle("Error");
    	messageBox.setText("Please Enter A Valid Popularity (Integer Greater Than or Equal to 0)");
   		messageBox.exec();
	}
}
Exemplo n.º 3
0
/**
 * Run all pending updates.
 *
 * Returns true on success, false on failure.
 */
bool
Control::run_pending_updates()
{
	/* MPD has new current song */
	if (idle_events & MPD_IDLE_PLAYER) {
		if (!get_current_song()) {
			return false;
		}
		/* MPD_IDLE_PLAYER will be subtracted below */
	}

	/* MPD has new status information */
	if (idle_events & (MPD_IDLE_PLAYER | MPD_IDLE_MIXER | MPD_IDLE_OPTIONS | MPD_IDLE_QUEUE)) {
		if (!get_status()) {
			return false;
		}
		set_update_done(MPD_IDLE_PLAYER);
		set_update_done(MPD_IDLE_MIXER);
		set_update_done(MPD_IDLE_OPTIONS);
		/* MPD_IDLE_QUEUE will be subtracted below */
	}

	/* MPD has updates to queue */
	if (idle_events & MPD_IDLE_QUEUE) {
		if (!update_queue()) {
			return false;
		}
		set_update_done(MPD_IDLE_QUEUE);
	}

	/* MPD has updates to a stored playlist */
	if (idle_events & MPD_IDLE_STORED_PLAYLIST) {
		if (!update_playlist_index()) {
			return false;
		}
		if (!update_playlists()) {
			return false;
		}
		set_update_done(MPD_IDLE_STORED_PLAYLIST);
	}

	/* MPD has new song database */
	if (idle_events & MPD_IDLE_DATABASE) {
		if (!update_library()) {
			return false;
		}
		set_update_done(MPD_IDLE_DATABASE);
	}

	/* Hack to make has_pending_updates() work smoothly without too much
	 * effort. We don't care about the rest of the events, so we just
	 * pretend they never happened. */
	idle_events = 0;

	return true;
}
Exemplo n.º 4
0
// Button handler for loading playlists from a file
void gui::add_load_file_button_handler()
{
	// Get filename from LineEdit
	string file_name = add_load_file->text().toStdString();

	// Attempt to add playlists in the file
	if(list_of_playlists->insert_playlists(file_name))
	{
		// If successful, reset add page and return to main page
		add_songs.clear();
		add_displayed_song = NULL;
		add_selected_songs_list->clear();
		add_popularity->setText("0");
		add_search_song->setText("");
		add_load_file->setText("");
		add_selected_song_label->setText("-- No song selected --");
		window->setCurrentIndex(0);

		// Rebuild the trie to update all preprocessed values
		// - Four suggested songs
		// - Eight most popular playlists
		delete trie;
		build_trie();

		// Update the playlist widget to reflect changes
		playslists->clear();
		update_playlists();
	}
	else
	{
		// If not successful, show error message
		QMessageBox messageBox;
		messageBox.setWindowTitle("Error");
    	messageBox.setText("One Or More Playlists Not Added. Check File Name and Contents.");
   		messageBox.exec();
	}
}
Exemplo n.º 5
0
// Initialize widgets and add them to the main page
void gui::generate_main_page()
{
	// Initialize Help Button
	help_button = new QPushButton("?", this);
	connect(help_button, SIGNAL(clicked()), this, SLOT(help_button_handler()));
	help_button->setFixedHeight(25);
	help_button->setFixedWidth(25);

	// Initialize Search Button
	search_button = new QPushButton("Search!", this);
	connect(search_button, SIGNAL(clicked()), this, SLOT(search_button_handler()));

	// Initialize Add Playlist Button
	add_playlist_button = new QPushButton("Add", this);
	connect(add_playlist_button, SIGNAL(clicked()), this, SLOT(add_playlist_button_handler()));

	// Initialize Playlist Label
	playlist_label = new QLabel(this);
	playlist_label->setFrameStyle(QFrame::NoFrame);
	playlist_label->setText("Top 8 Playlists:");
	playlist_label->setPalette(text);

	// Initialize Songs Label
	songs_label = new QLabel(this);
	songs_label->setFrameStyle(QFrame::NoFrame);
	songs_label->setText("Songs:");
	songs_label->setPalette(text);

	// Initialize Current Song Title Label
	current_label = new QLabel(this);
	current_label->setFrameStyle(QFrame::NoFrame);
	current_label->setText("Now Playing:");
	current_label->setPalette(text);

	// Initialize Current Song Label
	current_song_label = new QLabel(this);
	current_song_label->setFrameStyle(QFrame::NoFrame);
	current_song_label->setText("");
	current_song_label->setPalette(text);

	// Initialize QCompleter WordList Model
	word_model = new QStringListModel();

	// Initialize QCompleter
	completer = new QCompleter(word_model);
	completer->setCompletionMode(QCompleter::PopupCompletion);
	completer->setModelSorting(QCompleter::UnsortedModel);

	// Initialize Search Bar
	search_bar = new QLineEdit("", this);
	search_bar->setReadOnly(false);
	search_bar->setAlignment(Qt::AlignLeft | Qt::AlignTop);
	search_bar->setCompleter(completer);
	search_bar->installEventFilter(this);
	connect(search_bar, SIGNAL(textEdited(const QString &)), this, SLOT(update_suggestions(const QString &)));
	
	// Initialize Playlist List
	playslists = new QListWidget(this);
	update_playlists();

	// Initialize Songs List
	songs = new QListWidget(this);
	connect(playslists, SIGNAL(itemSelectionChanged()), this, SLOT(update_songs()));
	connect(songs, SIGNAL(itemSelectionChanged()), this, SLOT(print_song_info()));

	// Initialize Layout
	main_layout = new QGridLayout;
	main_layout->setRowMinimumHeight(4,5);
	main_layout->setRowMinimumHeight(7,5);
	main_layout->setRowMinimumHeight(1,5);

	// Add Buttons
	main_layout->addWidget(help_button, 0, 0, 1, 1);
	main_layout->addWidget(search_button, 0, 2, 1, 1);
	main_layout->addWidget(add_playlist_button, 9, 2, 1, 1);

	// Add Labels
	main_layout->addWidget(playlist_label, 2, 0, 1, -1);
	main_layout->addWidget(songs_label, 5, 0, 1, -1);
	main_layout->addWidget(current_label, 8, 0, 1, -1);
	main_layout->addWidget(current_song_label, 9, 0, 1, 2);

	// Add Search Bar
	main_layout->addWidget(search_bar, 0, 1, 1, 1);

	// Add Lists
	main_layout->addWidget(playslists, 3, 0, 1, -1);
	main_layout->addWidget(songs, 6, 0, 1, -1);
}