2010-03-24 00:11:46 +01:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
|
|
|
|
Clementine is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Clementine is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "player.h"
|
|
|
|
#include "playlist.h"
|
|
|
|
#include "library.h"
|
|
|
|
#include "libraryconfig.h"
|
|
|
|
#include "songplaylistitem.h"
|
|
|
|
#include "systemtrayicon.h"
|
2009-12-26 16:13:38 +01:00
|
|
|
#include "radiomodel.h"
|
2010-04-04 19:50:11 +02:00
|
|
|
#include "engines/enginebase.h"
|
2009-12-29 20:57:33 +01:00
|
|
|
#include "lastfmservice.h"
|
2010-01-08 15:52:05 +01:00
|
|
|
#include "osd.h"
|
2010-01-15 18:12:47 +01:00
|
|
|
#include "trackslider.h"
|
2010-01-16 17:12:47 +01:00
|
|
|
#include "edittagdialog.h"
|
2010-01-16 18:52:51 +01:00
|
|
|
#include "multiloadingindicator.h"
|
2010-02-03 17:17:04 +01:00
|
|
|
#include "settingsdialog.h"
|
|
|
|
#include "libraryconfigdialog.h"
|
2010-02-03 21:45:32 +01:00
|
|
|
#include "about.h"
|
2010-02-24 23:26:01 +01:00
|
|
|
#include "addstreamdialog.h"
|
2010-02-27 17:36:25 +01:00
|
|
|
#include "stylesheetloader.h"
|
2010-02-28 19:04:50 +01:00
|
|
|
#include "albumcovermanager.h"
|
2010-03-07 15:42:51 +01:00
|
|
|
#include "m3uparser.h"
|
2010-03-10 22:39:25 +01:00
|
|
|
#include "xspfparser.h"
|
2010-03-08 19:05:41 +01:00
|
|
|
#include "playlistsequence.h"
|
2010-04-01 01:11:45 +02:00
|
|
|
#include "groupbydialog.h"
|
2010-04-07 15:51:14 +02:00
|
|
|
#include "engines/gstengine.h"
|
2010-04-07 18:26:04 +02:00
|
|
|
#include "equalizer.h"
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-03-21 20:02:56 +01:00
|
|
|
#include "globalshortcuts/globalshortcuts.h"
|
2009-12-30 17:24:55 +01:00
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
#include <QFileSystemModel>
|
|
|
|
#include <QSortFilterProxyModel>
|
|
|
|
#include <QUndoStack>
|
|
|
|
#include <QDir>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QSettings>
|
|
|
|
#include <QtDebug>
|
|
|
|
#include <QCloseEvent>
|
|
|
|
#include <QSignalMapper>
|
2010-02-24 23:26:01 +01:00
|
|
|
#include <QFileDialog>
|
2010-03-20 23:45:54 +01:00
|
|
|
#include <QTimer>
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2009-12-29 20:57:33 +01:00
|
|
|
#include <cmath>
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
const int MainWindow::kStateVersion = 1;
|
|
|
|
const char* MainWindow::kSettingsGroup = "MainWindow";
|
2010-03-07 15:42:51 +01:00
|
|
|
const char* MainWindow::kMediaFilterSpec =
|
2010-03-10 22:39:25 +01:00
|
|
|
"Music (*.mp3 *.ogg *.flac *.mpc *.m4a *.aac *.wma);;Playlists (*.m3u *.xspf *.xml)";
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-03-03 21:35:19 +01:00
|
|
|
MainWindow::MainWindow(QNetworkAccessManager* network, QWidget *parent)
|
2009-12-24 20:16:07 +01:00
|
|
|
: QMainWindow(parent),
|
2009-12-29 20:57:33 +01:00
|
|
|
tray_icon_(new SystemTrayIcon(this)),
|
2010-01-08 15:52:05 +01:00
|
|
|
osd_(new OSD(tray_icon_, this)),
|
2010-01-15 18:12:47 +01:00
|
|
|
track_slider_(new TrackSlider(this)),
|
2010-03-08 19:05:41 +01:00
|
|
|
playlist_sequence_(new PlaylistSequence(this)),
|
2010-01-16 17:12:47 +01:00
|
|
|
edit_tag_dialog_(new EditTagDialog(this)),
|
2010-01-16 18:52:51 +01:00
|
|
|
multi_loading_indicator_(new MultiLoadingIndicator(this)),
|
2010-02-03 17:17:04 +01:00
|
|
|
library_config_dialog_(new LibraryConfigDialog(this)),
|
2010-02-03 21:45:32 +01:00
|
|
|
about_dialog_(new About(this)),
|
2009-12-26 22:35:45 +01:00
|
|
|
radio_model_(new RadioModel(this)),
|
2010-03-10 01:04:04 +01:00
|
|
|
playlist_(new Playlist(this)),
|
|
|
|
player_(new Player(playlist_, radio_model_->GetLastFMService(), this)),
|
2009-12-24 20:16:07 +01:00
|
|
|
library_(new Library(player_->GetEngine(), this)),
|
2010-03-21 20:02:56 +01:00
|
|
|
global_shortcuts_(new GlobalShortcuts(this)),
|
2010-02-03 19:32:48 +01:00
|
|
|
settings_dialog_(new SettingsDialog(this)),
|
2010-02-24 23:26:01 +01:00
|
|
|
add_stream_dialog_(new AddStreamDialog(this)),
|
2010-03-03 21:35:19 +01:00
|
|
|
cover_manager_(new AlbumCoverManager(network, this)),
|
2010-04-01 01:11:45 +02:00
|
|
|
group_by_dialog_(new GroupByDialog(this)),
|
2010-04-07 18:26:04 +02:00
|
|
|
equalizer_(new Equalizer(this)),
|
2010-01-15 17:22:19 +01:00
|
|
|
playlist_menu_(new QMenu(this)),
|
2009-12-24 20:16:07 +01:00
|
|
|
library_sort_model_(new QSortFilterProxyModel(this)),
|
2010-03-10 01:04:04 +01:00
|
|
|
track_position_timer_(new QTimer(this))
|
2009-12-24 20:16:07 +01:00
|
|
|
{
|
|
|
|
ui_.setupUi(this);
|
|
|
|
tray_icon_->setIcon(windowIcon());
|
2010-01-08 17:21:22 +01:00
|
|
|
tray_icon_->setToolTip(QCoreApplication::applicationName());
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
ui_.volume->setValue(player_->GetVolume());
|
|
|
|
|
2009-12-29 20:57:33 +01:00
|
|
|
track_position_timer_->setInterval(1000);
|
|
|
|
connect(track_position_timer_, SIGNAL(timeout()), SLOT(UpdateTrackPosition()));
|
|
|
|
|
2010-02-04 00:12:21 +01:00
|
|
|
// Start initialising the player
|
|
|
|
player_->Init();
|
|
|
|
|
2010-04-07 15:51:14 +02:00
|
|
|
if (GstEngine* engine = qobject_cast<GstEngine*>(player_->GetEngine()))
|
|
|
|
settings_dialog_->SetGstEngine(engine);
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
// Models
|
|
|
|
library_sort_model_->setSourceModel(library_);
|
|
|
|
library_sort_model_->setSortRole(Library::Role_SortText);
|
|
|
|
library_sort_model_->setDynamicSortFilter(true);
|
|
|
|
library_sort_model_->sort(0);
|
|
|
|
|
2010-03-10 01:04:04 +01:00
|
|
|
playlist_->Restore();
|
|
|
|
|
|
|
|
playlist_->IgnoreSorting(true);
|
|
|
|
ui_.playlist->setModel(playlist_);
|
2010-03-28 00:45:46 +01:00
|
|
|
ui_.playlist->setItemDelegates(library_);
|
2010-03-10 01:04:04 +01:00
|
|
|
playlist_->IgnoreSorting(false);
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
ui_.library_view->setModel(library_sort_model_);
|
|
|
|
ui_.library_view->SetLibrary(library_);
|
2010-02-03 17:17:04 +01:00
|
|
|
library_config_dialog_->SetModel(library_->GetDirectoryModel());
|
|
|
|
settings_dialog_->SetLibraryDirectoryModel(library_->GetDirectoryModel());
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2009-12-26 16:13:38 +01:00
|
|
|
ui_.radio_view->setModel(radio_model_);
|
|
|
|
|
2010-03-26 13:22:19 +01:00
|
|
|
cover_manager_->Init();
|
|
|
|
|
2009-12-24 21:27:32 +01:00
|
|
|
// File view connections
|
2009-12-24 23:26:58 +01:00
|
|
|
connect(ui_.file_view, SIGNAL(Queue(QList<QUrl>)), SLOT(QueueFiles(QList<QUrl>)));
|
2009-12-24 21:27:32 +01:00
|
|
|
connect(ui_.file_view, SIGNAL(PathChanged(QString)), SLOT(FilePathChanged(QString)));
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
// Action connections
|
|
|
|
connect(ui_.action_next_track, SIGNAL(triggered()), player_, SLOT(Next()));
|
|
|
|
connect(ui_.action_previous_track, SIGNAL(triggered()), player_, SLOT(Previous()));
|
|
|
|
connect(ui_.action_play_pause, SIGNAL(triggered()), player_, SLOT(PlayPause()));
|
|
|
|
connect(ui_.action_stop, SIGNAL(triggered()), player_, SLOT(Stop()));
|
|
|
|
connect(ui_.action_quit, SIGNAL(triggered()), qApp, SLOT(quit()));
|
|
|
|
connect(ui_.action_stop_after_this_track, SIGNAL(triggered()), SLOT(StopAfterCurrent()));
|
|
|
|
connect(ui_.library_filter, SIGNAL(textChanged(QString)), library_, SLOT(SetFilterText(QString)));
|
2009-12-29 21:48:50 +01:00
|
|
|
connect(ui_.action_ban, SIGNAL(triggered()), radio_model_->GetLastFMService(), SLOT(Ban()));
|
|
|
|
connect(ui_.action_love, SIGNAL(triggered()), SLOT(Love()));
|
2010-03-10 01:04:04 +01:00
|
|
|
connect(ui_.action_clear_playlist, SIGNAL(triggered()), playlist_, SLOT(Clear()));
|
2010-03-24 17:36:44 +01:00
|
|
|
connect(ui_.action_remove_from_playlist, SIGNAL(triggered()), SLOT(PlaylistRemoveCurrent()));
|
2010-01-16 17:12:47 +01:00
|
|
|
connect(ui_.action_edit_track, SIGNAL(triggered()), SLOT(EditTracks()));
|
2010-03-22 23:46:53 +01:00
|
|
|
connect(ui_.action_renumber_tracks, SIGNAL(triggered()), SLOT(RenumberTracks()));
|
2010-03-24 01:12:52 +01:00
|
|
|
connect(ui_.action_selection_set_value, SIGNAL(triggered()), SLOT(SelectionSetValue()));
|
2010-03-26 00:48:58 +01:00
|
|
|
connect(ui_.action_edit_value, SIGNAL(triggered()), SLOT(EditValue()));
|
2010-02-03 17:17:04 +01:00
|
|
|
connect(ui_.action_configure, SIGNAL(triggered()), settings_dialog_, SLOT(show()));
|
2010-02-03 21:45:32 +01:00
|
|
|
connect(ui_.action_about, SIGNAL(triggered()), about_dialog_, SLOT(show()));
|
2010-03-10 01:04:04 +01:00
|
|
|
connect(ui_.action_shuffle, SIGNAL(triggered()), playlist_, SLOT(Shuffle()));
|
2010-02-24 23:26:01 +01:00
|
|
|
connect(ui_.action_open_media, SIGNAL(triggered()), SLOT(AddMedia()));
|
|
|
|
connect(ui_.action_add_media, SIGNAL(triggered()), SLOT(AddMedia()));
|
|
|
|
connect(ui_.action_add_stream, SIGNAL(triggered()), SLOT(AddStream()));
|
2010-02-28 19:04:50 +01:00
|
|
|
connect(ui_.action_cover_manager, SIGNAL(triggered()), cover_manager_, SLOT(show()));
|
2010-04-07 18:26:04 +02:00
|
|
|
connect(ui_.action_equalizer, SIGNAL(triggered()), equalizer_, SLOT(show()));
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
// Give actions to buttons
|
|
|
|
ui_.forward_button->setDefaultAction(ui_.action_next_track);
|
|
|
|
ui_.back_button->setDefaultAction(ui_.action_previous_track);
|
|
|
|
ui_.pause_play_button->setDefaultAction(ui_.action_play_pause);
|
|
|
|
ui_.stop_button->setDefaultAction(ui_.action_stop);
|
2009-12-29 20:22:02 +01:00
|
|
|
ui_.love_button->setDefaultAction(ui_.action_love);
|
|
|
|
ui_.ban_button->setDefaultAction(ui_.action_ban);
|
2010-01-14 13:27:50 +01:00
|
|
|
ui_.clear_playlist_button->setDefaultAction(ui_.action_clear_playlist);
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-03-12 02:03:43 +01:00
|
|
|
// Add the shuffle and repeat action groups to the menu
|
|
|
|
ui_.action_shuffle_mode->setMenu(playlist_sequence_->shuffle_menu());
|
|
|
|
ui_.action_repeat_mode->setMenu(playlist_sequence_->repeat_menu());
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
// Stop actions
|
|
|
|
QMenu* stop_menu = new QMenu(this);
|
|
|
|
stop_menu->addAction(ui_.action_stop);
|
|
|
|
stop_menu->addAction(ui_.action_stop_after_this_track);
|
|
|
|
ui_.stop_button->setMenu(stop_menu);
|
|
|
|
|
|
|
|
// Player connections
|
|
|
|
connect(ui_.volume, SIGNAL(valueChanged(int)), player_, SLOT(SetVolume(int)));
|
|
|
|
|
|
|
|
connect(player_, SIGNAL(Error(QString)), SLOT(ReportError(QString)));
|
|
|
|
connect(player_, SIGNAL(Paused()), SLOT(MediaPaused()));
|
|
|
|
connect(player_, SIGNAL(Playing()), SLOT(MediaPlaying()));
|
|
|
|
connect(player_, SIGNAL(Stopped()), SLOT(MediaStopped()));
|
|
|
|
|
2010-03-10 01:04:04 +01:00
|
|
|
connect(player_, SIGNAL(Paused()), playlist_, SLOT(Paused()));
|
|
|
|
connect(player_, SIGNAL(Playing()), playlist_, SLOT(Playing()));
|
|
|
|
connect(player_, SIGNAL(Stopped()), playlist_, SLOT(Stopped()));
|
|
|
|
|
|
|
|
connect(player_, SIGNAL(Paused()), ui_.playlist, SLOT(StopGlowing()));
|
|
|
|
connect(player_, SIGNAL(Playing()), ui_.playlist, SLOT(StartGlowing()));
|
|
|
|
connect(player_, SIGNAL(Stopped()), ui_.playlist, SLOT(StopGlowing()));
|
|
|
|
|
2010-01-08 15:52:05 +01:00
|
|
|
connect(player_, SIGNAL(Paused()), osd_, SLOT(Paused()));
|
|
|
|
connect(player_, SIGNAL(Stopped()), osd_, SLOT(Stopped()));
|
2010-01-08 17:40:34 +01:00
|
|
|
connect(player_, SIGNAL(VolumeChanged(int)), osd_, SLOT(VolumeChanged(int)));
|
2010-03-24 21:58:17 +01:00
|
|
|
connect(player_, SIGNAL(ForceShowOSD(Song)), osd_, SLOT(SongChanged(Song)));
|
2010-03-10 01:04:04 +01:00
|
|
|
connect(playlist_, SIGNAL(CurrentSongChanged(Song)), osd_, SLOT(SongChanged(Song)));
|
2010-03-21 01:30:05 +01:00
|
|
|
connect(playlist_, SIGNAL(CurrentSongChanged(Song)), player_, SLOT(CurrentMetadataChanged(Song)));
|
2010-03-24 21:58:17 +01:00
|
|
|
connect(playlist_, SIGNAL(PlaylistChanged()), player_, SLOT(PlaylistChanged()));
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-03-10 01:04:04 +01:00
|
|
|
connect(ui_.playlist, SIGNAL(doubleClicked(QModelIndex)), SLOT(PlayIndex(QModelIndex)));
|
|
|
|
connect(ui_.playlist, SIGNAL(PlayPauseItem(QModelIndex)), SLOT(PlayIndex(QModelIndex)));
|
|
|
|
connect(ui_.playlist, SIGNAL(RightClicked(QPoint,QModelIndex)), SLOT(PlaylistRightClick(QPoint,QModelIndex)));
|
2010-01-15 18:12:47 +01:00
|
|
|
|
2010-03-10 01:04:04 +01:00
|
|
|
connect(track_slider_, SIGNAL(ValueChanged(int)), player_, SLOT(Seek(int)));
|
2010-03-06 16:33:57 +01:00
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
// Library connections
|
|
|
|
connect(library_, SIGNAL(Error(QString)), SLOT(ReportError(QString)));
|
2010-04-04 15:31:21 +02:00
|
|
|
connect(ui_.library_view, SIGNAL(doubleClicked(QModelIndex)), SLOT(AddLibraryItemToPlaylist(QModelIndex)));
|
|
|
|
connect(ui_.library_view, SIGNAL(AddToPlaylist(QModelIndex)), SLOT(AddLibraryItemToPlaylist(QModelIndex)));
|
2010-02-03 17:17:04 +01:00
|
|
|
connect(ui_.library_view, SIGNAL(ShowConfigDialog()), library_config_dialog_, SLOT(show()));
|
2009-12-24 20:16:07 +01:00
|
|
|
connect(library_, SIGNAL(TotalSongCountUpdated(int)), ui_.library_view, SLOT(TotalSongCountUpdated(int)));
|
2010-01-16 18:52:51 +01:00
|
|
|
connect(library_, SIGNAL(ScanStarted()), SLOT(LibraryScanStarted()));
|
|
|
|
connect(library_, SIGNAL(ScanFinished()), SLOT(LibraryScanFinished()));
|
2010-03-23 18:26:54 +01:00
|
|
|
connect(library_, SIGNAL(BackendReady(boost::shared_ptr<LibraryBackendInterface>)),
|
|
|
|
cover_manager_, SLOT(SetBackend(boost::shared_ptr<LibraryBackendInterface>)));
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
// Age filters
|
|
|
|
QActionGroup* filter_age_group = new QActionGroup(this);
|
|
|
|
filter_age_group->addAction(ui_.filter_age_all);
|
|
|
|
filter_age_group->addAction(ui_.filter_age_today);
|
|
|
|
filter_age_group->addAction(ui_.filter_age_week);
|
|
|
|
filter_age_group->addAction(ui_.filter_age_month);
|
|
|
|
filter_age_group->addAction(ui_.filter_age_three_months);
|
|
|
|
filter_age_group->addAction(ui_.filter_age_year);
|
|
|
|
filter_age_group->setExclusive(true);
|
|
|
|
|
|
|
|
QSignalMapper* filter_age_mapper = new QSignalMapper(this);
|
|
|
|
filter_age_mapper->setMapping(ui_.filter_age_all, -1);
|
|
|
|
filter_age_mapper->setMapping(ui_.filter_age_today, 60*60*24);
|
|
|
|
filter_age_mapper->setMapping(ui_.filter_age_week, 60*60*24*7);
|
|
|
|
filter_age_mapper->setMapping(ui_.filter_age_month, 60*60*24*30);
|
|
|
|
filter_age_mapper->setMapping(ui_.filter_age_three_months, 60*60*24*30*3);
|
|
|
|
filter_age_mapper->setMapping(ui_.filter_age_year, 60*60*24*365);
|
|
|
|
|
|
|
|
connect(ui_.filter_age_all, SIGNAL(triggered()), filter_age_mapper, SLOT(map()));
|
|
|
|
connect(ui_.filter_age_today, SIGNAL(triggered()), filter_age_mapper, SLOT(map()));
|
|
|
|
connect(ui_.filter_age_week, SIGNAL(triggered()), filter_age_mapper, SLOT(map()));
|
|
|
|
connect(ui_.filter_age_month, SIGNAL(triggered()), filter_age_mapper, SLOT(map()));
|
|
|
|
connect(ui_.filter_age_three_months, SIGNAL(triggered()), filter_age_mapper, SLOT(map()));
|
|
|
|
connect(ui_.filter_age_year, SIGNAL(triggered()), filter_age_mapper, SLOT(map()));
|
|
|
|
connect(filter_age_mapper, SIGNAL(mapped(int)), library_, SLOT(SetFilterAge(int)));
|
|
|
|
connect(ui_.library_filter_clear, SIGNAL(clicked()), SLOT(ClearLibraryFilter()));
|
|
|
|
|
2010-03-31 02:30:57 +02:00
|
|
|
// "Group by ..."
|
2010-04-01 19:20:31 +02:00
|
|
|
ui_.group_by_artist->setProperty("group_by", QVariant::fromValue(
|
|
|
|
Library::Grouping(Library::GroupBy_Artist)));
|
|
|
|
ui_.group_by_artist_album->setProperty("group_by", QVariant::fromValue(
|
|
|
|
Library::Grouping(Library::GroupBy_Artist, Library::GroupBy_Album)));
|
|
|
|
ui_.group_by_artist_yearalbum->setProperty("group_by", QVariant::fromValue(
|
|
|
|
Library::Grouping(Library::GroupBy_Artist, Library::GroupBy_YearAlbum)));
|
|
|
|
ui_.group_by_album->setProperty("group_by", QVariant::fromValue(
|
|
|
|
Library::Grouping(Library::GroupBy_Album)));
|
|
|
|
ui_.group_by_genre_album->setProperty("group_by", QVariant::fromValue(
|
|
|
|
Library::Grouping(Library::GroupBy_Genre, Library::GroupBy_Album)));
|
|
|
|
ui_.group_by_genre_artist_album->setProperty("group_by", QVariant::fromValue(
|
|
|
|
Library::Grouping(Library::GroupBy_Genre, Library::GroupBy_Artist, Library::GroupBy_Album)));
|
|
|
|
|
2010-03-31 17:18:39 +02:00
|
|
|
group_by_group_ = new QActionGroup(this);
|
|
|
|
group_by_group_->addAction(ui_.group_by_artist);
|
|
|
|
group_by_group_->addAction(ui_.group_by_artist_album);
|
|
|
|
group_by_group_->addAction(ui_.group_by_artist_yearalbum);
|
|
|
|
group_by_group_->addAction(ui_.group_by_album);
|
|
|
|
group_by_group_->addAction(ui_.group_by_genre_album);
|
|
|
|
group_by_group_->addAction(ui_.group_by_genre_artist_album);
|
|
|
|
group_by_group_->addAction(ui_.group_by_advanced);
|
2010-04-01 01:11:45 +02:00
|
|
|
|
2010-03-31 17:18:39 +02:00
|
|
|
connect(group_by_group_, SIGNAL(triggered(QAction*)), SLOT(GroupByClicked(QAction*)));
|
2010-04-01 01:11:45 +02:00
|
|
|
connect(library_, SIGNAL(GroupingChanged(Library::Grouping)),
|
|
|
|
group_by_dialog_, SLOT(LibraryGroupingChanged(Library::Grouping)));
|
|
|
|
connect(library_, SIGNAL(GroupingChanged(Library::Grouping)),
|
|
|
|
SLOT(LibraryGroupingChanged(Library::Grouping)));
|
|
|
|
connect(group_by_dialog_, SIGNAL(Accepted(Library::Grouping)),
|
|
|
|
library_, SLOT(SetGroupBy(Library::Grouping)));
|
2010-03-31 02:30:57 +02:00
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
// Library config menu
|
|
|
|
QMenu* library_menu = new QMenu(this);
|
|
|
|
library_menu->addActions(filter_age_group->actions());
|
|
|
|
library_menu->addSeparator();
|
2010-03-31 17:18:39 +02:00
|
|
|
library_menu->addActions(group_by_group_->actions());
|
2010-03-31 02:30:57 +02:00
|
|
|
library_menu->addSeparator();
|
2010-02-23 19:33:09 +01:00
|
|
|
library_menu->addAction(tr("Configure library..."), library_config_dialog_, SLOT(show()));
|
2009-12-24 20:16:07 +01:00
|
|
|
ui_.library_options->setMenu(library_menu);
|
2010-04-01 02:12:25 +02:00
|
|
|
connect(library_config_dialog_, SIGNAL(accepted()), ui_.library_view, SLOT(ReloadSettings()));
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-01-15 17:22:19 +01:00
|
|
|
// Playlist menu
|
2010-02-23 19:33:09 +01:00
|
|
|
playlist_play_pause_ = playlist_menu_->addAction(tr("Play"), this, SLOT(PlaylistPlay()));
|
2010-01-15 17:22:19 +01:00
|
|
|
playlist_menu_->addAction(ui_.action_stop);
|
2010-02-23 19:33:09 +01:00
|
|
|
playlist_stop_after_ = playlist_menu_->addAction(QIcon(":media-playback-stop.png"), tr("Stop after this track"), this, SLOT(PlaylistStopAfter()));
|
2010-03-24 01:12:52 +01:00
|
|
|
playlist_menu_->addSeparator();
|
2010-03-24 17:36:44 +01:00
|
|
|
playlist_menu_->addAction(ui_.action_remove_from_playlist);
|
|
|
|
playlist_menu_->addSeparator();
|
2010-01-16 17:12:47 +01:00
|
|
|
playlist_menu_->addAction(ui_.action_edit_track);
|
2010-03-26 00:48:58 +01:00
|
|
|
playlist_menu_->addAction(ui_.action_edit_value);
|
2010-03-22 23:46:53 +01:00
|
|
|
playlist_menu_->addAction(ui_.action_renumber_tracks);
|
2010-03-24 01:12:52 +01:00
|
|
|
playlist_menu_->addAction(ui_.action_selection_set_value);
|
2010-01-15 17:22:19 +01:00
|
|
|
playlist_menu_->addSeparator();
|
|
|
|
playlist_menu_->addAction(ui_.action_clear_playlist);
|
2010-02-04 00:56:41 +01:00
|
|
|
playlist_menu_->addAction(ui_.action_shuffle);
|
2010-01-15 17:22:19 +01:00
|
|
|
|
2009-12-26 22:35:45 +01:00
|
|
|
// Radio connections
|
2010-02-23 19:33:09 +01:00
|
|
|
connect(radio_model_, SIGNAL(TaskStarted(MultiLoadingIndicator::TaskType)), multi_loading_indicator_, SLOT(TaskStarted(MultiLoadingIndicator::TaskType)));
|
|
|
|
connect(radio_model_, SIGNAL(TaskFinished(MultiLoadingIndicator::TaskType)), multi_loading_indicator_, SLOT(TaskFinished(MultiLoadingIndicator::TaskType)));
|
2009-12-26 22:35:45 +01:00
|
|
|
connect(radio_model_, SIGNAL(StreamError(QString)), SLOT(ReportError(QString)));
|
2010-02-04 00:12:21 +01:00
|
|
|
connect(radio_model_, SIGNAL(StreamFinished()), player_, SLOT(NextItem()));
|
2009-12-26 22:35:45 +01:00
|
|
|
connect(radio_model_, SIGNAL(StreamReady(QUrl,QUrl)), player_, SLOT(StreamReady(QUrl,QUrl)));
|
2010-03-10 01:04:04 +01:00
|
|
|
connect(radio_model_, SIGNAL(StreamMetadataFound(QUrl,Song)), playlist_, SLOT(SetStreamMetadata(QUrl,Song)));
|
2009-12-30 02:41:37 +01:00
|
|
|
connect(radio_model_, SIGNAL(AddItemToPlaylist(RadioItem*)), SLOT(InsertRadioItem(RadioItem*)));
|
2009-12-29 21:48:50 +01:00
|
|
|
connect(radio_model_->GetLastFMService(), SIGNAL(ScrobblingEnabledChanged(bool)), SLOT(ScrobblingEnabledChanged(bool)));
|
2009-12-30 00:17:54 +01:00
|
|
|
connect(ui_.radio_view, SIGNAL(doubleClicked(QModelIndex)), SLOT(RadioDoubleClick(QModelIndex)));
|
2009-12-26 22:35:45 +01:00
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
// Tray icon
|
|
|
|
QMenu* tray_menu = new QMenu(this);
|
|
|
|
tray_menu->addAction(ui_.action_previous_track);
|
|
|
|
tray_menu->addAction(ui_.action_play_pause);
|
|
|
|
tray_menu->addAction(ui_.action_stop);
|
|
|
|
tray_menu->addAction(ui_.action_next_track);
|
2010-01-15 17:44:54 +01:00
|
|
|
tray_menu->addSeparator();
|
2009-12-29 20:22:02 +01:00
|
|
|
tray_menu->addAction(ui_.action_love);
|
|
|
|
tray_menu->addAction(ui_.action_ban);
|
2009-12-24 20:16:07 +01:00
|
|
|
tray_menu->addSeparator();
|
|
|
|
tray_menu->addAction(ui_.action_quit);
|
|
|
|
tray_icon_->setContextMenu(tray_menu);
|
|
|
|
|
|
|
|
connect(tray_icon_, SIGNAL(WheelEvent(int)), SLOT(VolumeWheelEvent(int)));
|
|
|
|
connect(tray_icon_, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), SLOT(TrayClicked(QSystemTrayIcon::ActivationReason)));
|
|
|
|
|
2009-12-30 17:24:55 +01:00
|
|
|
// Global shortcuts
|
2010-03-21 20:02:56 +01:00
|
|
|
connect(global_shortcuts_, SIGNAL(PlayPause()), ui_.action_play_pause, SLOT(trigger()));
|
|
|
|
connect(global_shortcuts_, SIGNAL(Stop()), ui_.action_stop, SLOT(trigger()));
|
|
|
|
connect(global_shortcuts_, SIGNAL(Next()), ui_.action_next_track, SLOT(trigger()));
|
|
|
|
connect(global_shortcuts_, SIGNAL(Previous()), ui_.action_previous_track, SLOT(trigger()));
|
2009-12-30 17:24:55 +01:00
|
|
|
|
2010-02-03 17:51:56 +01:00
|
|
|
// Settings
|
2010-04-07 01:46:34 +02:00
|
|
|
connect(settings_dialog_, SIGNAL(accepted()), SLOT(ReloadSettings()));
|
2010-02-03 17:51:56 +01:00
|
|
|
connect(settings_dialog_, SIGNAL(accepted()), player_, SLOT(ReloadSettings()));
|
2010-02-03 18:21:25 +01:00
|
|
|
connect(settings_dialog_, SIGNAL(accepted()), osd_, SLOT(ReloadSettings()));
|
2010-04-01 02:12:25 +02:00
|
|
|
connect(settings_dialog_, SIGNAL(accepted()), ui_.library_view, SLOT(ReloadSettings()));
|
2010-04-07 15:51:14 +02:00
|
|
|
connect(settings_dialog_, SIGNAL(accepted()), player_->GetEngine(), SLOT(ReloadSettings()));
|
2010-02-03 17:51:56 +01:00
|
|
|
|
2010-02-24 23:26:01 +01:00
|
|
|
// Add stream dialog
|
|
|
|
connect(add_stream_dialog_, SIGNAL(accepted()), SLOT(AddStreamAccepted()));
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
// Analyzer
|
|
|
|
ui_.analyzer->set_engine(player_->GetEngine());
|
|
|
|
|
2010-04-07 18:26:04 +02:00
|
|
|
// Equalizer
|
|
|
|
connect(equalizer_, SIGNAL(ParametersChanged(int,QList<int>)),
|
|
|
|
player_->GetEngine(), SLOT(setEqualizerParameters(int,QList<int>)));
|
|
|
|
connect(equalizer_, SIGNAL(EnabledChanged(bool)),
|
|
|
|
player_->GetEngine(), SLOT(setEqualizerEnabled(bool)));
|
|
|
|
equalizer_->ReloadSettings();
|
|
|
|
|
2010-01-15 18:12:47 +01:00
|
|
|
// Statusbar widgets
|
2010-03-10 01:09:49 +01:00
|
|
|
playlist_->set_sequence(playlist_sequence_);
|
2010-03-08 19:05:41 +01:00
|
|
|
ui_.statusBar->addPermanentWidget(playlist_sequence_);
|
2010-01-15 18:12:47 +01:00
|
|
|
ui_.statusBar->addPermanentWidget(track_slider_);
|
2010-01-16 18:52:51 +01:00
|
|
|
ui_.statusBar->addWidget(multi_loading_indicator_);
|
|
|
|
multi_loading_indicator_->hide();
|
2010-01-15 18:12:47 +01:00
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
// Load theme
|
2010-02-27 17:36:25 +01:00
|
|
|
StyleSheetLoader* css_loader = new StyleSheetLoader(this);
|
|
|
|
css_loader->SetStyleSheet(this, ":mainwindow.css");
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2009-12-24 21:27:32 +01:00
|
|
|
// Load settings
|
2010-02-27 17:52:18 +01:00
|
|
|
settings_.beginGroup(kSettingsGroup);
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-02-27 17:52:18 +01:00
|
|
|
restoreGeometry(settings_.value("geometry").toByteArray());
|
|
|
|
if (!restoreState(settings_.value("state").toByteArray(), kStateVersion)) {
|
2009-12-24 20:16:07 +01:00
|
|
|
tabifyDockWidget(ui_.files_dock, ui_.radio_dock);
|
|
|
|
tabifyDockWidget(ui_.files_dock, ui_.library_dock);
|
|
|
|
}
|
|
|
|
|
2010-02-27 17:52:18 +01:00
|
|
|
ui_.file_view->SetPath(settings_.value("file_path", QDir::homePath()).toString());
|
2009-12-24 21:27:32 +01:00
|
|
|
|
2010-04-01 01:11:45 +02:00
|
|
|
library_->SetGroupBy(Library::Grouping(
|
|
|
|
Library::GroupBy(settings_.value("group_by1", int(Library::GroupBy_Artist)).toInt()),
|
|
|
|
Library::GroupBy(settings_.value("group_by2", int(Library::GroupBy_Album)).toInt()),
|
|
|
|
Library::GroupBy(settings_.value("group_by3", int(Library::GroupBy_None)).toInt())));
|
2010-03-31 02:30:57 +02:00
|
|
|
|
2010-04-07 01:46:34 +02:00
|
|
|
StartupBehaviour behaviour =
|
|
|
|
StartupBehaviour(settings_.value("startupbehaviour", Startup_Remember).toInt());
|
2010-03-31 05:07:11 +02:00
|
|
|
bool hidden = settings_.value("hidden", false).toBool();
|
|
|
|
bool show_tray = settings_.value("showtray", true).toBool();
|
2010-04-07 01:46:34 +02:00
|
|
|
|
|
|
|
switch (behaviour) {
|
|
|
|
case Startup_AlwaysHide: hide(); break;
|
|
|
|
case Startup_AlwaysShow: show(); break;
|
|
|
|
case Startup_Remember: setVisible(!hidden); break;
|
|
|
|
}
|
2010-02-26 19:22:44 +01:00
|
|
|
|
2010-03-31 05:07:11 +02:00
|
|
|
if (show_tray)
|
2010-02-26 19:22:44 +01:00
|
|
|
tray_icon_->show();
|
|
|
|
|
|
|
|
// Force the window to show in case somehow the config has tray and window set to hide
|
2010-03-31 05:07:11 +02:00
|
|
|
if (hidden && !show_tray) {
|
2010-02-27 17:52:18 +01:00
|
|
|
settings_.setValue("hidden", false);
|
2010-02-26 19:22:44 +01:00
|
|
|
show();
|
|
|
|
}
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-03-23 18:26:54 +01:00
|
|
|
library_->Init();
|
2009-12-24 20:16:07 +01:00
|
|
|
library_->StartThreads();
|
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow::~MainWindow() {
|
|
|
|
SaveGeometry();
|
|
|
|
}
|
|
|
|
|
2010-04-07 01:46:34 +02:00
|
|
|
void MainWindow::ReloadSettings() {
|
|
|
|
bool show_tray = settings_.value("showtray", true).toBool();
|
2010-02-26 19:22:44 +01:00
|
|
|
|
2010-04-07 01:46:34 +02:00
|
|
|
tray_icon_->setVisible(show_tray);
|
|
|
|
if (!show_tray && !isVisible())
|
|
|
|
show();
|
2010-02-26 19:22:44 +01:00
|
|
|
}
|
|
|
|
|
2009-12-24 23:26:58 +01:00
|
|
|
void MainWindow::QueueFiles(const QList<QUrl>& urls) {
|
2010-03-10 01:04:04 +01:00
|
|
|
QModelIndex playlist_index = playlist_->InsertPaths(urls);
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
if (playlist_index.isValid() && player_->GetState() != Engine::Playing)
|
2010-03-30 02:51:00 +02:00
|
|
|
player_->PlayAt(playlist_index.row(), true);
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::ReportError(const QString& message) {
|
2010-04-01 18:59:32 +02:00
|
|
|
// TODO: rate limiting
|
2009-12-24 20:16:07 +01:00
|
|
|
QMessageBox::warning(this, "Error", message);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::MediaStopped() {
|
|
|
|
ui_.action_stop->setEnabled(false);
|
|
|
|
ui_.action_stop_after_this_track->setEnabled(false);
|
|
|
|
ui_.action_play_pause->setIcon(QIcon(":media-playback-start.png"));
|
2010-02-23 19:33:09 +01:00
|
|
|
ui_.action_play_pause->setText(tr("Play"));
|
2009-12-29 17:15:21 +01:00
|
|
|
|
|
|
|
ui_.action_play_pause->setEnabled(true);
|
2009-12-29 20:22:02 +01:00
|
|
|
|
2009-12-29 21:48:50 +01:00
|
|
|
ui_.action_ban->setEnabled(false);
|
|
|
|
ui_.action_love->setEnabled(false);
|
2009-12-29 20:57:33 +01:00
|
|
|
|
|
|
|
track_position_timer_->stop();
|
2010-01-15 18:12:47 +01:00
|
|
|
track_slider_->SetStopped();
|
2010-01-17 22:11:03 +01:00
|
|
|
tray_icon_->SetProgress(0);
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::MediaPaused() {
|
|
|
|
ui_.action_stop->setEnabled(true);
|
|
|
|
ui_.action_stop_after_this_track->setEnabled(true);
|
|
|
|
ui_.action_play_pause->setIcon(QIcon(":media-playback-start.png"));
|
2010-02-23 19:33:09 +01:00
|
|
|
ui_.action_play_pause->setText(tr("Play"));
|
2009-12-29 17:15:21 +01:00
|
|
|
|
|
|
|
ui_.action_play_pause->setEnabled(true);
|
2009-12-29 20:57:33 +01:00
|
|
|
|
|
|
|
track_position_timer_->stop();
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::MediaPlaying() {
|
|
|
|
ui_.action_stop->setEnabled(true);
|
|
|
|
ui_.action_stop_after_this_track->setEnabled(true);
|
|
|
|
ui_.action_play_pause->setIcon(QIcon(":media-playback-pause.png"));
|
2010-02-23 19:33:09 +01:00
|
|
|
ui_.action_play_pause->setText(tr("Pause"));
|
2009-12-29 17:15:21 +01:00
|
|
|
|
|
|
|
ui_.action_play_pause->setEnabled(
|
2010-02-03 15:21:53 +01:00
|
|
|
! (player_->GetCurrentItemOptions() & PlaylistItem::PauseDisabled));
|
2009-12-29 20:22:02 +01:00
|
|
|
|
2010-02-03 15:21:53 +01:00
|
|
|
bool is_lastfm = (player_->GetCurrentItemOptions() & PlaylistItem::LastFMControls);
|
2009-12-29 21:48:50 +01:00
|
|
|
LastFMService* lastfm = radio_model_->GetLastFMService();
|
|
|
|
|
|
|
|
ui_.action_ban->setEnabled(lastfm->IsScrobblingEnabled() && is_lastfm);
|
|
|
|
ui_.action_love->setEnabled(lastfm->IsScrobblingEnabled());
|
2009-12-29 20:57:33 +01:00
|
|
|
|
2010-01-15 18:12:47 +01:00
|
|
|
track_slider_->SetCanSeek(!is_lastfm);
|
|
|
|
|
2009-12-29 20:57:33 +01:00
|
|
|
track_position_timer_->start();
|
|
|
|
UpdateTrackPosition();
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
2009-12-29 21:48:50 +01:00
|
|
|
void MainWindow::ScrobblingEnabledChanged(bool value) {
|
2009-12-30 05:14:29 +01:00
|
|
|
if (!player_->GetState() == Engine::Idle)
|
|
|
|
return;
|
|
|
|
|
2010-02-03 15:21:53 +01:00
|
|
|
bool is_lastfm = (player_->GetCurrentItemOptions() & PlaylistItem::LastFMControls);
|
2009-12-30 05:14:29 +01:00
|
|
|
ui_.action_ban->setEnabled(value && is_lastfm);
|
2009-12-29 21:48:50 +01:00
|
|
|
ui_.action_love->setEnabled(value);
|
|
|
|
}
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
void MainWindow::resizeEvent(QResizeEvent*) {
|
|
|
|
SaveGeometry();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::SaveGeometry() {
|
2010-02-27 17:52:18 +01:00
|
|
|
settings_.setValue("geometry", saveGeometry());
|
|
|
|
settings_.setValue("state", saveState(kStateVersion));
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::PlayIndex(const QModelIndex& index) {
|
|
|
|
if (!index.isValid())
|
|
|
|
return;
|
|
|
|
|
2010-03-30 02:51:00 +02:00
|
|
|
player_->PlayAt(index.row(), true);
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
2010-04-04 15:31:21 +02:00
|
|
|
void MainWindow::AddLibraryItemToPlaylist(const QModelIndex& index) {
|
|
|
|
QModelIndex idx = index;
|
|
|
|
if (idx.model() == library_sort_model_)
|
|
|
|
idx = library_sort_model_->mapToSource(idx);
|
|
|
|
|
2009-12-24 20:16:07 +01:00
|
|
|
QModelIndex first_song =
|
2010-04-04 15:31:21 +02:00
|
|
|
playlist_->InsertSongs(library_->GetChildSongs(idx));
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
if (first_song.isValid() && player_->GetState() != Engine::Playing)
|
2010-03-30 02:51:00 +02:00
|
|
|
player_->PlayAt(first_song.row(), true);
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::VolumeWheelEvent(int delta) {
|
2010-04-01 01:45:52 +02:00
|
|
|
ui_.volume->setValue(ui_.volume->value() + delta / 30);
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::TrayClicked(QSystemTrayIcon::ActivationReason reason) {
|
|
|
|
switch (reason) {
|
|
|
|
case QSystemTrayIcon::DoubleClick:
|
|
|
|
case QSystemTrayIcon::Trigger:
|
2010-03-29 15:24:40 +02:00
|
|
|
if(isMinimized()) {
|
|
|
|
hide();
|
|
|
|
setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
|
|
|
|
SetHiddenInTray(false);
|
|
|
|
} else {
|
|
|
|
SetHiddenInTray(isVisible());
|
|
|
|
}
|
2009-12-24 20:16:07 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case QSystemTrayIcon::MiddleClick:
|
|
|
|
player_->PlayPause();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::StopAfterCurrent() {
|
2010-03-10 01:04:04 +01:00
|
|
|
playlist_->StopAfter(playlist_->current_index());
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
2010-02-26 19:22:44 +01:00
|
|
|
/**
|
|
|
|
* Exit if the tray icon is not visible, otherwise ignore and set hidden in tray.
|
|
|
|
*/
|
2009-12-24 20:16:07 +01:00
|
|
|
void MainWindow::closeEvent(QCloseEvent* event) {
|
2010-02-26 19:22:44 +01:00
|
|
|
if (tray_icon_->isVisible()) {
|
|
|
|
event->ignore();
|
|
|
|
SetHiddenInTray(true);
|
2010-04-07 18:26:04 +02:00
|
|
|
} else {
|
|
|
|
QApplication::quit();
|
2010-02-26 19:22:44 +01:00
|
|
|
}
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::SetHiddenInTray(bool hidden) {
|
2010-02-27 17:52:18 +01:00
|
|
|
settings_.setValue("hidden", hidden);
|
2010-04-07 01:46:34 +02:00
|
|
|
setVisible(!hidden);
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::ClearLibraryFilter() {
|
|
|
|
ui_.library_filter->clear();
|
|
|
|
ui_.library_filter->setFocus();
|
|
|
|
}
|
2009-12-24 21:27:32 +01:00
|
|
|
|
|
|
|
void MainWindow::FilePathChanged(const QString& path) {
|
2010-02-27 17:52:18 +01:00
|
|
|
settings_.setValue("file_path", path);
|
2009-12-24 21:27:32 +01:00
|
|
|
}
|
2009-12-29 20:57:33 +01:00
|
|
|
|
|
|
|
void MainWindow::UpdateTrackPosition() {
|
2010-01-17 22:11:03 +01:00
|
|
|
// Track position in seconds
|
|
|
|
const int position = std::floor(float(player_->GetEngine()->position()) / 1000.0 + 0.5);
|
2010-02-03 15:21:53 +01:00
|
|
|
const int length = player_->GetCurrentItem().length();
|
2009-12-29 20:57:33 +01:00
|
|
|
|
2010-01-18 03:49:07 +01:00
|
|
|
if (length <= 0) {
|
|
|
|
// Probably a stream that we don't know the length of
|
|
|
|
track_slider_->SetStopped();
|
|
|
|
tray_icon_->SetProgress(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-01-17 22:11:03 +01:00
|
|
|
// Time to scrobble?
|
2009-12-29 21:48:50 +01:00
|
|
|
LastFMService* lastfm = radio_model_->GetLastFMService();
|
|
|
|
|
2010-03-10 01:04:04 +01:00
|
|
|
if (!playlist_->has_scrobbled() &&
|
|
|
|
position >= playlist_->scrobble_point()) {
|
2009-12-29 21:48:50 +01:00
|
|
|
lastfm->Scrobble();
|
2010-03-10 01:04:04 +01:00
|
|
|
playlist_->set_scrobbled(true);
|
2009-12-29 20:57:33 +01:00
|
|
|
}
|
2010-01-15 18:12:47 +01:00
|
|
|
|
2010-01-17 22:11:03 +01:00
|
|
|
// Update the slider
|
|
|
|
track_slider_->SetValue(position, length);
|
|
|
|
|
|
|
|
// Update the tray icon every 10 seconds
|
|
|
|
if (position % 10 == 1) {
|
|
|
|
tray_icon_->SetProgress(double(position) / length * 100);
|
|
|
|
}
|
2009-12-29 20:57:33 +01:00
|
|
|
}
|
2009-12-29 21:48:50 +01:00
|
|
|
|
|
|
|
void MainWindow::Love() {
|
|
|
|
radio_model_->GetLastFMService()->Love();
|
|
|
|
ui_.action_love->setEnabled(false);
|
|
|
|
}
|
2009-12-30 00:17:54 +01:00
|
|
|
|
|
|
|
void MainWindow::RadioDoubleClick(const QModelIndex& index) {
|
2009-12-30 02:41:37 +01:00
|
|
|
InsertRadioItem(radio_model_->IndexToItem(index));
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::InsertRadioItem(RadioItem* item) {
|
2010-03-10 01:04:04 +01:00
|
|
|
QModelIndex first_song = playlist_->InsertRadioStations(
|
2009-12-30 02:41:37 +01:00
|
|
|
QList<RadioItem*>() << item);
|
2009-12-30 00:17:54 +01:00
|
|
|
|
|
|
|
if (first_song.isValid() && player_->GetState() != Engine::Playing)
|
2010-03-30 02:51:00 +02:00
|
|
|
player_->PlayAt(first_song.row(), true);
|
2009-12-30 00:17:54 +01:00
|
|
|
}
|
2010-01-15 17:22:19 +01:00
|
|
|
|
|
|
|
void MainWindow::PlaylistRightClick(const QPoint& global_pos, const QModelIndex& index) {
|
|
|
|
playlist_menu_index_ = index;
|
|
|
|
|
2010-03-10 01:04:04 +01:00
|
|
|
if (playlist_->current_index() == index.row() && player_->GetState() == Engine::Playing) {
|
2010-02-23 19:33:09 +01:00
|
|
|
playlist_play_pause_->setText(tr("Pause"));
|
2010-01-15 17:22:19 +01:00
|
|
|
playlist_play_pause_->setIcon(QIcon(":media-playback-pause.png"));
|
|
|
|
} else {
|
2010-02-23 19:33:09 +01:00
|
|
|
playlist_play_pause_->setText(tr("Play"));
|
2010-01-15 17:22:19 +01:00
|
|
|
playlist_play_pause_->setIcon(QIcon(":media-playback-start.png"));
|
|
|
|
}
|
|
|
|
|
2010-01-17 16:48:31 +01:00
|
|
|
if (index.isValid()) {
|
|
|
|
playlist_play_pause_->setEnabled(
|
2010-03-10 01:04:04 +01:00
|
|
|
playlist_->current_index() != index.row() ||
|
|
|
|
! (playlist_->item_at(index.row())->options() & PlaylistItem::PauseDisabled));
|
2010-01-17 16:48:31 +01:00
|
|
|
} else {
|
|
|
|
playlist_play_pause_->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
2010-01-15 17:22:19 +01:00
|
|
|
playlist_stop_after_->setEnabled(index.isValid());
|
|
|
|
|
2010-01-16 17:12:47 +01:00
|
|
|
// Are any of the selected songs editable?
|
2010-03-24 17:36:44 +01:00
|
|
|
QModelIndexList selection = ui_.playlist->selectionModel()->selection().indexes();
|
2010-03-24 01:12:52 +01:00
|
|
|
int editable = 0;
|
2010-03-24 17:36:44 +01:00
|
|
|
foreach (const QModelIndex& index, selection) {
|
2010-01-16 17:12:47 +01:00
|
|
|
if (index.column() != 0)
|
|
|
|
continue;
|
2010-03-10 01:04:04 +01:00
|
|
|
if (playlist_->item_at(index.row())->Metadata().IsEditable()) {
|
2010-03-24 01:12:52 +01:00
|
|
|
editable++;
|
2010-01-16 17:12:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ui_.action_edit_track->setEnabled(editable);
|
2010-03-31 21:09:35 +02:00
|
|
|
|
|
|
|
bool track_column = (index.column() == Playlist::Column_Track);
|
|
|
|
ui_.action_renumber_tracks->setVisible(editable >= 2 && track_column);
|
|
|
|
ui_.action_selection_set_value->setVisible(editable >= 2 && !track_column);
|
2010-03-26 00:48:58 +01:00
|
|
|
ui_.action_edit_value->setVisible(editable);
|
2010-03-24 17:36:44 +01:00
|
|
|
ui_.action_remove_from_playlist->setEnabled(!selection.isEmpty());
|
2010-03-24 01:12:52 +01:00
|
|
|
|
2010-03-24 17:13:05 +01:00
|
|
|
if (!index.isValid()) {
|
|
|
|
ui_.action_selection_set_value->setVisible(false);
|
2010-03-26 00:48:58 +01:00
|
|
|
ui_.action_edit_value->setVisible(false);
|
2010-03-24 17:13:05 +01:00
|
|
|
} else {
|
|
|
|
Playlist::Column column = (Playlist::Column)index.column();
|
2010-03-26 00:48:58 +01:00
|
|
|
bool editable = Playlist::column_is_editable(column);
|
|
|
|
|
2010-03-24 17:13:05 +01:00
|
|
|
ui_.action_selection_set_value->setVisible(
|
2010-03-26 00:48:58 +01:00
|
|
|
ui_.action_selection_set_value->isVisible() && editable);
|
|
|
|
ui_.action_edit_value->setVisible(
|
|
|
|
ui_.action_edit_value->isVisible() && editable);
|
2010-03-24 17:13:05 +01:00
|
|
|
|
|
|
|
QString column_name = Playlist::column_name(column);
|
|
|
|
QString column_value = playlist_->data(index).toString();
|
|
|
|
if (column_value.length() > 25)
|
|
|
|
column_value = column_value.left(25) + "...";
|
|
|
|
|
|
|
|
ui_.action_selection_set_value->setText(tr("Set %1 to \"%2\"...")
|
|
|
|
.arg(column_name.toLower()).arg(column_value));
|
2010-03-26 00:48:58 +01:00
|
|
|
ui_.action_edit_value->setText(tr("Edit tag \"%1\"...").arg(column_name));
|
2010-03-24 17:13:05 +01:00
|
|
|
}
|
2010-01-16 17:12:47 +01:00
|
|
|
|
2010-01-15 17:22:19 +01:00
|
|
|
playlist_menu_->popup(global_pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::PlaylistPlay() {
|
2010-03-10 01:04:04 +01:00
|
|
|
if (playlist_->current_index() == playlist_menu_index_.row()) {
|
2010-01-15 17:22:19 +01:00
|
|
|
player_->PlayPause();
|
|
|
|
} else {
|
2010-03-30 02:51:00 +02:00
|
|
|
player_->PlayAt(playlist_menu_index_.row(), true);
|
2010-01-15 17:22:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::PlaylistStopAfter() {
|
2010-03-10 01:04:04 +01:00
|
|
|
playlist_->StopAfter(playlist_menu_index_.row());
|
2010-01-15 17:22:19 +01:00
|
|
|
}
|
2010-01-16 17:12:47 +01:00
|
|
|
|
|
|
|
void MainWindow::EditTracks() {
|
|
|
|
SongList songs;
|
|
|
|
QList<int> rows;
|
|
|
|
|
|
|
|
foreach (const QModelIndex& index,
|
2010-03-10 01:04:04 +01:00
|
|
|
ui_.playlist->selectionModel()->selection().indexes()) {
|
2010-01-16 17:12:47 +01:00
|
|
|
if (index.column() != 0)
|
|
|
|
continue;
|
2010-03-10 01:04:04 +01:00
|
|
|
Song song = playlist_->item_at(index.row())->Metadata();
|
2010-01-16 17:12:47 +01:00
|
|
|
|
|
|
|
if (song.IsEditable()) {
|
|
|
|
songs << song;
|
|
|
|
rows << index.row();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
edit_tag_dialog_->SetSongs(songs);
|
2010-03-29 18:59:01 +02:00
|
|
|
edit_tag_dialog_->SetTagCompleter(library_);
|
|
|
|
|
2010-01-16 17:12:47 +01:00
|
|
|
if (edit_tag_dialog_->exec() == QDialog::Rejected)
|
|
|
|
return;
|
|
|
|
|
2010-03-10 01:04:04 +01:00
|
|
|
playlist_->ReloadItems(rows);
|
2010-01-16 17:12:47 +01:00
|
|
|
}
|
2010-01-16 18:52:51 +01:00
|
|
|
|
2010-03-22 23:46:53 +01:00
|
|
|
void MainWindow::RenumberTracks() {
|
|
|
|
QModelIndexList indexes=ui_.playlist->selectionModel()->selection().indexes();
|
|
|
|
int track=1;
|
|
|
|
|
|
|
|
// if first selected song has a track number set, start from that offset
|
|
|
|
if (indexes.size()) {
|
|
|
|
Song first_song=playlist_->item_at(indexes[0].row())->Metadata();
|
|
|
|
if (int first_track = first_song.track())
|
|
|
|
track = first_track;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (const QModelIndex& index, indexes) {
|
|
|
|
if (index.column() != 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
int row = index.row();
|
|
|
|
Song song = playlist_->item_at(row)->Metadata();
|
|
|
|
|
|
|
|
if (song.IsEditable()) {
|
|
|
|
song.set_track(track);
|
|
|
|
song.Save();
|
|
|
|
playlist_->item_at(row)->Reload();
|
|
|
|
}
|
|
|
|
track++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-24 01:12:52 +01:00
|
|
|
void MainWindow::SelectionSetValue() {
|
|
|
|
Playlist::Column column = (Playlist::Column)playlist_menu_index_.column();
|
|
|
|
QVariant column_value = playlist_->data(playlist_menu_index_);
|
|
|
|
|
|
|
|
QModelIndexList indexes=ui_.playlist->selectionModel()->selection().indexes();
|
|
|
|
foreach (const QModelIndex& index, indexes) {
|
|
|
|
if (index.column() != 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
int row = index.row();
|
|
|
|
Song song = playlist_->item_at(row)->Metadata();
|
|
|
|
|
2010-03-26 00:48:58 +01:00
|
|
|
if(Playlist::set_column_value(song, column, column_value)) {
|
2010-03-24 01:12:52 +01:00
|
|
|
song.Save();
|
|
|
|
playlist_->item_at(row)->Reload();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-26 00:48:58 +01:00
|
|
|
void MainWindow::EditValue() {
|
|
|
|
ui_.playlist->edit(playlist_menu_index_);
|
2010-03-31 21:09:35 +02:00
|
|
|
connect(playlist_, SIGNAL(dataChanged(QModelIndex, QModelIndex)), SLOT(SelectionSetValue()));
|
2010-03-26 00:48:58 +01:00
|
|
|
}
|
|
|
|
|
2010-01-16 18:52:51 +01:00
|
|
|
void MainWindow::LibraryScanStarted() {
|
2010-02-23 19:33:09 +01:00
|
|
|
multi_loading_indicator_->TaskStarted(MultiLoadingIndicator::UpdatingLibrary);
|
2010-01-16 18:52:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::LibraryScanFinished() {
|
2010-02-23 19:33:09 +01:00
|
|
|
multi_loading_indicator_->TaskFinished(MultiLoadingIndicator::UpdatingLibrary);
|
2010-01-16 18:52:51 +01:00
|
|
|
}
|
2010-02-03 22:48:00 +01:00
|
|
|
|
2010-02-24 23:26:01 +01:00
|
|
|
void MainWindow::AddMedia() {
|
|
|
|
// Last used directory
|
2010-02-27 17:52:18 +01:00
|
|
|
QString directory = settings_.value("add_media_path", QDir::currentPath()).toString();
|
2010-02-24 23:26:01 +01:00
|
|
|
|
|
|
|
// Show dialog
|
2010-03-07 15:42:51 +01:00
|
|
|
QStringList file_names = QFileDialog::getOpenFileNames(
|
|
|
|
this, "Add media", directory, kMediaFilterSpec);
|
2010-02-24 23:26:01 +01:00
|
|
|
if (file_names.isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Save last used directory
|
2010-02-27 17:52:18 +01:00
|
|
|
settings_.setValue("add_media_path", file_names[0]);
|
2010-02-24 23:26:01 +01:00
|
|
|
|
|
|
|
// Add media
|
|
|
|
QList<QUrl> urls;
|
|
|
|
foreach (const QString& path, file_names) {
|
2010-03-07 15:42:51 +01:00
|
|
|
if (path.endsWith(".m3u")) {
|
|
|
|
QFile file(path);
|
|
|
|
QFileInfo info(file);
|
|
|
|
file.open(QIODevice::ReadOnly);
|
|
|
|
M3UParser parser(&file, info.dir());
|
|
|
|
const SongList& songs = parser.Parse();
|
2010-03-10 01:04:04 +01:00
|
|
|
playlist_->InsertSongs(songs);
|
2010-03-10 22:39:25 +01:00
|
|
|
} else if (path.endsWith(".xspf") || path.endsWith(".xml")) {
|
|
|
|
QFile file(path);
|
|
|
|
file.open(QIODevice::ReadOnly);
|
|
|
|
XSPFParser parser(&file);
|
|
|
|
const SongList& songs = parser.Parse();
|
|
|
|
playlist_->InsertSongs(songs);
|
2010-03-07 15:42:51 +01:00
|
|
|
} else {
|
|
|
|
QUrl url(path);
|
|
|
|
if (url.scheme().isEmpty())
|
|
|
|
url.setScheme("file");
|
|
|
|
urls << url;
|
|
|
|
}
|
2010-02-24 23:26:01 +01:00
|
|
|
}
|
2010-03-10 01:04:04 +01:00
|
|
|
playlist_->InsertPaths(urls);
|
2010-02-24 23:26:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::AddStream() {
|
|
|
|
add_stream_dialog_->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainWindow::AddStreamAccepted() {
|
|
|
|
QList<QUrl> urls;
|
|
|
|
urls << add_stream_dialog_->url();
|
2010-02-26 19:22:44 +01:00
|
|
|
|
2010-03-10 01:04:04 +01:00
|
|
|
playlist_->InsertStreamUrls(urls);
|
2010-03-07 21:19:35 +01:00
|
|
|
}
|
2010-03-24 17:36:44 +01:00
|
|
|
|
|
|
|
void MainWindow::PlaylistRemoveCurrent() {
|
|
|
|
ui_.playlist->RemoveSelected();
|
|
|
|
}
|
2010-03-31 02:30:57 +02:00
|
|
|
|
|
|
|
void MainWindow::GroupByClicked(QAction* action) {
|
2010-04-01 19:20:31 +02:00
|
|
|
if (action->property("group_by").isNull()) {
|
2010-04-01 01:11:45 +02:00
|
|
|
group_by_dialog_->show();
|
2010-03-31 02:30:57 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-04-01 19:20:31 +02:00
|
|
|
Library::Grouping g = action->property("group_by").value<Library::Grouping>();
|
2010-03-31 02:30:57 +02:00
|
|
|
library_->SetGroupBy(g);
|
2010-04-01 01:11:45 +02:00
|
|
|
}
|
2010-03-31 02:30:57 +02:00
|
|
|
|
2010-04-01 01:11:45 +02:00
|
|
|
void MainWindow::LibraryGroupingChanged(const Library::Grouping& g) {
|
|
|
|
// Save the settings
|
2010-03-31 02:30:57 +02:00
|
|
|
settings_.setValue("group_by1", int(g[0]));
|
|
|
|
settings_.setValue("group_by2", int(g[1]));
|
|
|
|
settings_.setValue("group_by3", int(g[2]));
|
|
|
|
|
2010-04-01 01:11:45 +02:00
|
|
|
// Now make sure the correct action is checked
|
2010-03-31 17:18:39 +02:00
|
|
|
foreach (QAction* action, group_by_group_->actions()) {
|
2010-04-01 19:20:31 +02:00
|
|
|
if (action->property("group_by").isNull())
|
|
|
|
continue;
|
2010-03-31 17:18:39 +02:00
|
|
|
|
2010-04-01 19:20:31 +02:00
|
|
|
if (g == action->property("group_by").value<Library::Grouping>()) {
|
2010-03-31 17:18:39 +02:00
|
|
|
action->setChecked(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ui_.group_by_advanced->setChecked(true);
|
2010-03-31 02:30:57 +02:00
|
|
|
}
|