2010-03-23 23:11:46 +00:00
/* This file is part of Clementine.
2010-11-20 13:27:10 +00:00
Copyright 2010 , David Sansome < me @ davidsansome . com >
2010-03-23 23:11:46 +00:00
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 19:16:07 +00:00
# include "mainwindow.h"
2010-05-10 21:50:31 +00:00
# include "ui_mainwindow.h"
2012-01-09 20:08:09 +01:00
# include "core/appearance.h"
2012-02-12 13:41:50 +00:00
# include "core/application.h"
2010-12-03 13:53:43 +00:00
# include "core/backgroundstreams.h"
2010-05-10 21:50:31 +00:00
# include "core/commandlineoptions.h"
# include "core/database.h"
2010-12-11 10:54:42 +00:00
# include "core/deletefiles.h"
2010-05-10 21:50:31 +00:00
# include "core/globalshortcuts.h"
2011-04-22 16:50:29 +00:00
# include "core/logging.h"
2010-05-10 21:50:31 +00:00
# include "core/mac_startup.h"
# include "core/mergedproxymodel.h"
2011-01-10 22:26:13 +00:00
# include "core/mimedata.h"
2010-08-02 14:22:05 +00:00
# include "core/modelfuturewatcher.h"
2010-12-05 23:41:41 +00:00
# include "core/mpris_common.h"
2010-12-30 16:20:33 +00:00
# include "core/network.h"
2010-05-10 21:50:31 +00:00
# include "core/player.h"
2010-06-15 18:24:08 +00:00
# include "core/songloader.h"
2010-05-10 21:50:31 +00:00
# include "core/stylesheetloader.h"
2010-06-23 13:21:30 +00:00
# include "core/taskmanager.h"
2011-03-17 19:52:21 +00:00
# include "core/utilities.h"
2010-06-26 12:41:18 +00:00
# include "devices/devicemanager.h"
2010-08-08 13:06:52 +00:00
# include "devices/devicestatefiltermodel.h"
2010-10-01 19:27:01 +00:00
# include "devices/deviceview.h"
2010-04-04 17:50:11 +00:00
# include "engines/enginebase.h"
2010-12-26 13:01:35 +00:00
# include "engines/gstengine.h"
2011-09-24 14:44:23 +01:00
# include "globalsearch/globalsearch.h"
2012-06-04 18:18:37 +01:00
# include "globalsearch/globalsearchview.h"
2011-09-24 14:44:23 +01:00
# include "globalsearch/librarysearchprovider.h"
2011-07-15 13:27:50 +00:00
# include "internet/magnatuneservice.h"
# include "internet/internetmodel.h"
# include "internet/internetview.h"
# include "internet/internetviewcontainer.h"
# include "internet/savedradio.h"
2010-05-10 21:50:31 +00:00
# include "library/groupbydialog.h"
2010-10-01 19:27:01 +00:00
# include "library/library.h"
2010-08-31 21:24:57 +00:00
# include "library/librarybackend.h"
2010-06-24 17:34:23 +00:00
# include "library/librarydirectorymodel.h"
2010-10-01 19:27:01 +00:00
# include "library/libraryfilterwidget.h"
# include "library/libraryviewcontainer.h"
2011-03-12 21:19:41 +00:00
# include "musicbrainz/tagfetcher.h"
2010-05-10 21:50:31 +00:00
# include "playlist/playlistbackend.h"
# include "playlist/playlist.h"
2010-05-20 21:21:55 +00:00
# include "playlist/playlistmanager.h"
2010-05-10 21:50:31 +00:00
# include "playlist/playlistsequence.h"
2010-05-20 14:12:15 +00:00
# include "playlist/playlistview.h"
2010-07-11 15:37:40 +00:00
# include "playlist/queue.h"
# include "playlist/queuemanager.h"
2010-05-10 21:50:31 +00:00
# include "playlist/songplaylistitem.h"
2010-05-22 20:06:19 +00:00
# include "playlistparsers/playlistparser.h"
2012-03-12 14:11:24 +00:00
# include "podcasts/podcastservice.h"
2010-12-04 16:19:30 +00:00
# include "smartplaylists/generator.h"
2011-01-10 22:26:13 +00:00
# include "smartplaylists/generatormimedata.h"
2010-10-02 16:23:33 +00:00
# include "songinfo/artistinfoview.h"
2010-10-10 16:09:20 +00:00
# include "songinfo/songinfoview.h"
2010-05-10 21:50:31 +00:00
# include "transcoder/transcodedialog.h"
# include "ui/about.h"
# include "ui/addstreamdialog.h"
2011-04-27 19:10:37 +00:00
# include "ui/albumcovermanager.h"
2010-05-10 21:50:31 +00:00
# include "ui/edittagdialog.h"
# include "ui/equalizer.h"
2010-05-19 15:45:29 +00:00
# include "ui/iconloader.h"
2010-06-24 16:26:49 +00:00
# include "ui/organisedialog.h"
2010-12-11 10:54:42 +00:00
# include "ui/organiseerrordialog.h"
2010-06-24 16:26:49 +00:00
# include "ui/qtsystemtrayicon.h"
2010-05-10 21:50:31 +00:00
# include "ui/settingsdialog.h"
# include "ui/systemtrayicon.h"
2011-03-06 14:07:41 +00:00
# include "ui/trackselectiondialog.h"
2011-01-16 00:39:51 +00:00
# include "ui/windows7thumbbar.h"
2011-01-24 20:45:15 +00:00
# include "version.h"
2010-05-31 20:49:44 +00:00
# include "widgets/errordialog.h"
2010-10-01 19:27:01 +00:00
# include "widgets/fileview.h"
2010-05-10 21:50:31 +00:00
# include "widgets/multiloadingindicator.h"
# include "widgets/osd.h"
2010-10-10 14:04:05 +00:00
# include "widgets/stylehelper.h"
2010-05-10 21:50:31 +00:00
# include "widgets/trackslider.h"
2010-12-18 17:28:02 +00:00
# ifdef Q_OS_DARWIN
# include "ui / macsystemtrayicon.h"
# endif
# ifdef HAVE_LIBLASTFM
2011-07-15 13:27:50 +00:00
# include "internet / lastfmservice.h"
2010-12-18 17:28:02 +00:00
# endif
2011-03-12 21:19:32 +00:00
# ifdef HAVE_WIIMOTEDEV
2010-08-25 13:02:53 +00:00
# include "wiimotedev / shortcuts.h"
2010-08-23 17:42:51 +00:00
# endif
2010-06-10 22:48:23 +00:00
# ifdef ENABLE_VISUALISATIONS
# include "visualisations / visualisationcontainer.h"
# endif
2012-05-27 21:15:58 +01:00
# ifdef HAVE_MOODBAR
# include "moodbar / moodbarcontroller.h"
# include "moodbar / moodbarproxystyle.h"
# endif
2010-10-01 19:27:01 +00:00
# include <QCloseEvent>
2009-12-24 19:16:07 +00:00
# include <QDir>
2010-10-01 19:27:01 +00:00
# include <QFileDialog>
# include <QFileSystemModel>
# include <QLinearGradient>
2009-12-24 19:16:07 +00:00
# include <QMenu>
# include <QMessageBox>
# include <QSettings>
2010-10-01 19:27:01 +00:00
# include <QShortcut>
2009-12-24 19:16:07 +00:00
# include <QSignalMapper>
2010-10-01 19:27:01 +00:00
# include <QSortFilterProxyModel>
# include <QStatusBar>
# include <QtDebug>
2010-03-20 22:45:54 +00:00
# include <QTimer>
2010-10-01 19:27:01 +00:00
# include <QUndoStack>
2010-12-30 16:20:33 +00:00
# ifdef Q_OS_WIN32
# include <qtsparkle / Updater>
# endif
2009-12-24 19:16:07 +00:00
2009-12-29 19:57:33 +00:00
# include <cmath>
2011-06-09 23:08:43 +00:00
# include <gst/cdda/gstcddabasesrc.h>
2010-04-14 22:36:28 +00:00
using boost : : shared_ptr ;
2010-05-15 17:45:04 +00:00
using boost : : scoped_ptr ;
2010-04-14 22:36:28 +00:00
2010-04-14 19:38:09 +00:00
# ifdef Q_OS_DARWIN
// Non exported mac-specific function.
void qt_mac_set_dock_menu ( QMenu * ) ;
# endif
2009-12-24 19:16:07 +00:00
const char * MainWindow : : kSettingsGroup = " MainWindow " ;
2010-05-03 18:52:35 +00:00
const char * MainWindow : : kAllFilesFilterSpec =
QT_TR_NOOP ( " All Files (*) " ) ;
2009-12-24 19:16:07 +00:00
2012-02-12 13:41:50 +00:00
MainWindow : : MainWindow ( Application * app ,
SystemTrayIcon * tray_icon ,
OSD * osd ,
QWidget * parent )
2009-12-24 19:16:07 +00:00
: QMainWindow ( parent ) ,
2010-05-10 21:50:31 +00:00
ui_ ( new Ui_MainWindow ) ,
2011-01-16 00:39:51 +00:00
thumbbar_ ( new Windows7ThumbBar ( this ) ) ,
2012-02-12 13:41:50 +00:00
app_ ( app ) ,
2011-01-04 11:33:22 +00:00
tray_icon_ ( tray_icon ) ,
osd_ ( osd ) ,
2010-03-21 19:02:56 +00:00
global_shortcuts_ ( new GlobalShortcuts ( this ) ) ,
2011-02-19 18:24:11 +00:00
remote_ ( NULL ) ,
2012-06-04 18:18:37 +01:00
global_search_view_ ( new GlobalSearchView ( app_ , this ) ) ,
2010-10-01 19:27:01 +00:00
library_view_ ( new LibraryViewContainer ( this ) ) ,
file_view_ ( new FileView ( this ) ) ,
2011-07-15 13:27:50 +00:00
internet_view_ ( new InternetViewContainer ( this ) ) ,
2010-10-01 19:27:01 +00:00
device_view_ ( new DeviceView ( this ) ) ,
2010-10-16 17:20:54 +00:00
song_info_view_ ( new SongInfoView ( this ) ) ,
artist_info_view_ ( new ArtistInfoView ( this ) ) ,
2010-06-02 16:27:52 +00:00
settings_dialog_ ( NULL ) ,
2010-06-02 15:58:07 +00:00
cover_manager_ ( NULL ) ,
2010-04-14 21:58:51 +00:00
equalizer_ ( new Equalizer ) ,
2010-08-27 19:09:03 +00:00
error_dialog_ ( NULL ) ,
2012-02-12 13:41:50 +00:00
organise_dialog_ ( new OrganiseDialog ( app_ - > task_manager ( ) ) ) ,
2010-08-27 19:09:03 +00:00
queue_manager_ ( NULL ) ,
2010-06-10 22:48:23 +00:00
# ifdef ENABLE_VISUALISATIONS
2010-08-27 19:09:03 +00:00
visualisation_ ( NULL ) ,
2010-08-25 21:14:37 +00:00
# endif
2011-03-12 21:19:32 +00:00
# ifdef HAVE_WIIMOTEDEV
2010-08-25 21:14:37 +00:00
wiimotedev_shortcuts_ ( NULL ) ,
2010-12-31 18:13:28 +00:00
# endif
2010-01-15 16:22:19 +00:00
playlist_menu_ ( new QMenu ( this ) ) ,
2011-03-20 17:38:15 +00:00
playlist_add_to_another_ ( NULL ) ,
2012-07-29 03:11:00 +02:00
playlistitem_actions_separator_ ( NULL ) ,
2009-12-24 19:16:07 +00:00
library_sort_model_ ( new QSortFilterProxyModel ( this ) ) ,
2010-04-19 14:10:31 +00:00
track_position_timer_ ( new QTimer ( this ) ) ,
2011-01-24 21:16:26 +00:00
was_maximized_ ( false ) ,
doubleclick_addmode_ ( AddBehaviour_Append ) ,
doubleclick_playmode_ ( PlayBehaviour_IfStopped ) ,
menu_playmode_ ( PlayBehaviour_IfStopped )
2009-12-24 19:16:07 +00:00
{
2011-04-24 18:07:09 +00:00
qLog ( Debug ) < < " Starting " ;
2012-02-12 13:41:50 +00:00
connect ( app , SIGNAL ( ErrorAdded ( QString ) ) , SLOT ( ShowErrorDialog ( QString ) ) ) ;
2012-03-10 22:39:24 +00:00
connect ( app , SIGNAL ( SettingsDialogRequested ( SettingsDialog : : Page ) ) ,
SLOT ( OpenSettingsDialogAtPage ( SettingsDialog : : Page ) ) ) ;
2011-01-19 15:36:40 +00:00
2010-06-02 15:58:07 +00:00
// Initialise the UI
2010-05-10 21:50:31 +00:00
ui_ - > setupUi ( this ) ;
2012-02-06 18:00:17 +01:00
# ifdef Q_OS_DARWIN
ui_ - > menu_help - > menuAction ( ) - > setVisible ( false ) ;
# endif
2012-02-06 17:32:13 +01:00
2012-02-12 13:41:50 +00:00
ui_ - > multi_loading_indicator - > SetTaskManager ( app_ - > task_manager ( ) ) ;
ui_ - > now_playing - > SetApplication ( app_ ) ;
2010-11-21 21:36:27 +00:00
2012-02-12 13:41:50 +00:00
int volume = app_ - > player ( ) - > GetVolume ( ) ;
2010-11-21 21:36:27 +00:00
ui_ - > volume - > setValue ( volume ) ;
VolumeChanged ( volume ) ;
2009-12-24 19:16:07 +00:00
2011-08-28 21:33:59 +01:00
// Initialise the global search widget
StyleHelper : : setBaseColor ( palette ( ) . color ( QPalette : : Highlight ) . darker ( ) ) ;
2011-08-29 02:37:55 +01:00
2011-09-24 14:44:23 +01:00
// Add global search providers
2012-02-12 13:41:50 +00:00
app_ - > global_search ( ) - > AddProvider ( new LibrarySearchProvider (
app_ - > library_backend ( ) , tr ( " Library " ) , " library " ,
2012-02-13 20:44:04 +00:00
IconLoader : : Load ( " folder-sound " ) , true , app_ , this ) ) ;
2011-09-24 14:44:23 +01:00
2012-02-12 13:41:50 +00:00
app_ - > global_search ( ) - > ReloadSettings ( ) ;
2012-06-10 23:05:30 +01:00
global_search_view_ - > ReloadSettings ( ) ;
2011-10-03 16:03:03 +02:00
2012-06-04 18:18:37 +01:00
connect ( global_search_view_ , SIGNAL ( AddToPlaylist ( QMimeData * ) ) , SLOT ( AddToPlaylist ( QMimeData * ) ) ) ;
2011-08-28 21:33:59 +01:00
2010-10-01 19:27:01 +00:00
// Add tabs to the fancy tab widget
2012-06-04 18:18:37 +01:00
ui_ - > tabs - > AddTab ( global_search_view_ , IconLoader : : Load ( " search " ) , tr ( " Search " ) ) ;
2010-10-09 18:18:06 +00:00
ui_ - > tabs - > AddTab ( library_view_ , IconLoader : : Load ( " folder-sound " ) , tr ( " Library " ) ) ;
ui_ - > tabs - > AddTab ( file_view_ , IconLoader : : Load ( " document-open " ) , tr ( " Files " ) ) ;
2011-07-15 13:27:50 +00:00
ui_ - > tabs - > AddTab ( internet_view_ , IconLoader : : Load ( " applications-internet " ) , tr ( " Internet " ) ) ;
2010-10-09 18:18:06 +00:00
ui_ - > tabs - > AddTab ( device_view_ , IconLoader : : Load ( " multimedia-player-ipod-mini-blue " ) , tr ( " Devices " ) ) ;
ui_ - > tabs - > AddSpacer ( ) ;
2010-10-10 16:09:20 +00:00
ui_ - > tabs - > AddTab ( song_info_view_ , IconLoader : : Load ( " view-media-lyrics " ) , tr ( " Song info " ) ) ;
2010-11-20 15:09:57 +00:00
ui_ - > tabs - > AddTab ( artist_info_view_ , IconLoader : : Load ( " x-clementine-artist " ) , tr ( " Artist info " ) ) ;
2010-10-01 19:27:01 +00:00
2010-10-06 18:16:49 +00:00
// Add the now playing widget to the fancy tab widget
2010-10-09 18:18:06 +00:00
ui_ - > tabs - > AddBottomWidget ( ui_ - > now_playing ) ;
2010-10-06 18:16:49 +00:00
2010-10-09 18:18:06 +00:00
ui_ - > tabs - > SetBackgroundPixmap ( QPixmap ( " :/sidebar_background.png " ) ) ;
2010-10-01 19:27:01 +00:00
2009-12-29 19:57:33 +00:00
track_position_timer_ - > setInterval ( 1000 ) ;
connect ( track_position_timer_ , SIGNAL ( timeout ( ) ) , SLOT ( UpdateTrackPosition ( ) ) ) ;
2010-02-03 23:12:21 +00:00
// Start initialising the player
2011-04-24 18:07:09 +00:00
qLog ( Debug ) < < " Initialising player " ;
2012-02-12 13:41:50 +00:00
app_ - > player ( ) - > Init ( ) ;
background_streams_ = new BackgroundStreams ( app_ - > player ( ) - > engine ( ) , this ) ;
2010-12-03 13:53:43 +00:00
background_streams_ - > LoadStreams ( ) ;
2009-12-24 19:16:07 +00:00
// Models
2011-04-24 18:07:09 +00:00
qLog ( Debug ) < < " Creating models " ;
2012-02-12 13:41:50 +00:00
library_sort_model_ - > setSourceModel ( app_ - > library ( ) - > model ( ) ) ;
2010-05-09 00:10:26 +00:00
library_sort_model_ - > setSortRole ( LibraryModel : : Role_SortText ) ;
2009-12-24 19:16:07 +00:00
library_sort_model_ - > setDynamicSortFilter ( true ) ;
library_sort_model_ - > sort ( 0 ) ;
2010-11-28 15:14:48 +00:00
connect ( ui_ - > playlist , SIGNAL ( ViewSelectionModelChanged ( ) ) , SLOT ( PlaylistViewSelectionModelChanged ( ) ) ) ;
2012-02-12 13:41:50 +00:00
ui_ - > playlist - > SetManager ( app_ - > playlist_manager ( ) ) ;
2012-03-03 01:20:37 +01:00
ui_ - > playlist - > view ( ) - > SetApplication ( app_ ) ;
2010-03-10 00:04:04 +00:00
2010-10-01 19:27:01 +00:00
library_view_ - > view ( ) - > setModel ( library_sort_model_ ) ;
2012-02-12 13:41:50 +00:00
library_view_ - > view ( ) - > SetApplication ( app_ ) ;
internet_view_ - > SetApplication ( app_ ) ;
device_view_ - > SetApplication ( app_ ) ;
2009-12-26 15:13:38 +00:00
2012-02-12 13:41:50 +00:00
organise_dialog_ - > SetDestinationModel ( app_ - > library ( ) - > model ( ) - > directory_model ( ) ) ;
2010-06-24 17:34:23 +00:00
2010-05-19 15:45:29 +00:00
// Icons
2011-04-24 18:07:09 +00:00
qLog ( Debug ) < < " Creating UI " ;
2010-05-19 15:45:29 +00:00
ui_ - > action_about - > setIcon ( IconLoader : : Load ( " help-about " ) ) ;
2010-09-30 21:25:31 +00:00
ui_ - > action_about_qt - > setIcon ( QIcon ( " :/trolltech/qmessagebox/images/qtlogo-64.png " ) ) ;
2010-05-19 15:45:29 +00:00
ui_ - > action_add_file - > setIcon ( IconLoader : : Load ( " document-open " ) ) ;
ui_ - > action_add_folder - > setIcon ( IconLoader : : Load ( " document-open-folder " ) ) ;
ui_ - > action_add_stream - > setIcon ( IconLoader : : Load ( " document-open-remote " ) ) ;
ui_ - > action_clear_playlist - > setIcon ( IconLoader : : Load ( " edit-clear-list " ) ) ;
ui_ - > action_configure - > setIcon ( IconLoader : : Load ( " configure " ) ) ;
ui_ - > action_cover_manager - > setIcon ( IconLoader : : Load ( " download " ) ) ;
ui_ - > action_edit_track - > setIcon ( IconLoader : : Load ( " edit-rename " ) ) ;
ui_ - > action_equalizer - > setIcon ( IconLoader : : Load ( " view-media-equalizer " ) ) ;
ui_ - > action_jump - > setIcon ( IconLoader : : Load ( " go-jump " ) ) ;
ui_ - > action_next_track - > setIcon ( IconLoader : : Load ( " media-skip-forward " ) ) ;
ui_ - > action_open_media - > setIcon ( IconLoader : : Load ( " document-open " ) ) ;
2011-06-09 23:08:43 +00:00
ui_ - > action_open_cd - > setIcon ( IconLoader : : Load ( " media-optical " ) ) ;
2010-05-19 15:45:29 +00:00
ui_ - > action_play_pause - > setIcon ( IconLoader : : Load ( " media-playback-start " ) ) ;
ui_ - > action_previous_track - > setIcon ( IconLoader : : Load ( " media-skip-backward " ) ) ;
ui_ - > action_quit - > setIcon ( IconLoader : : Load ( " application-exit " ) ) ;
ui_ - > action_remove_from_playlist - > setIcon ( IconLoader : : Load ( " list-remove " ) ) ;
ui_ - > action_repeat_mode - > setIcon ( IconLoader : : Load ( " media-playlist-repeat " ) ) ;
ui_ - > action_shuffle - > setIcon ( IconLoader : : Load ( " x-clementine-shuffle " ) ) ;
ui_ - > action_shuffle_mode - > setIcon ( IconLoader : : Load ( " media-playlist-shuffle " ) ) ;
ui_ - > action_stop - > setIcon ( IconLoader : : Load ( " media-playback-stop " ) ) ;
ui_ - > action_stop_after_this_track - > setIcon ( IconLoader : : Load ( " media-playback-stop " ) ) ;
2010-05-20 14:12:15 +00:00
ui_ - > action_new_playlist - > setIcon ( IconLoader : : Load ( " document-new " ) ) ;
ui_ - > action_load_playlist - > setIcon ( IconLoader : : Load ( " document-open " ) ) ;
ui_ - > action_save_playlist - > setIcon ( IconLoader : : Load ( " document-save " ) ) ;
2011-02-17 19:57:14 +00:00
ui_ - > action_full_library_scan - > setIcon ( IconLoader : : Load ( " view-refresh " ) ) ;
2010-06-14 20:00:17 +00:00
ui_ - > action_rain - > setIcon ( IconLoader : : Load ( " weather-showers-scattered " ) ) ;
2010-05-19 15:45:29 +00:00
2009-12-24 20:27:32 +00:00
// File view connections
2011-01-10 22:26:13 +00:00
connect ( file_view_ , SIGNAL ( AddToPlaylist ( QMimeData * ) ) , SLOT ( AddToPlaylist ( QMimeData * ) ) ) ;
2010-10-01 19:27:01 +00:00
connect ( file_view_ , SIGNAL ( PathChanged ( QString ) ) , SLOT ( FilePathChanged ( QString ) ) ) ;
connect ( file_view_ , SIGNAL ( CopyToLibrary ( QList < QUrl > ) ) , SLOT ( CopyFilesToLibrary ( QList < QUrl > ) ) ) ;
connect ( file_view_ , SIGNAL ( MoveToLibrary ( QList < QUrl > ) ) , SLOT ( MoveFilesToLibrary ( QList < QUrl > ) ) ) ;
2012-01-29 18:44:00 +00:00
connect ( file_view_ , SIGNAL ( EditTags ( QList < QUrl > ) ) , SLOT ( EditFileTags ( QList < QUrl > ) ) ) ;
2010-10-01 19:27:01 +00:00
connect ( file_view_ , SIGNAL ( CopyToDevice ( QList < QUrl > ) ) , SLOT ( CopyFilesToDevice ( QList < QUrl > ) ) ) ;
2012-02-12 13:41:50 +00:00
file_view_ - > SetTaskManager ( app_ - > task_manager ( ) ) ;
2009-12-24 19:16:07 +00:00
// Action connections
2012-02-12 13:41:50 +00:00
connect ( ui_ - > action_next_track , SIGNAL ( triggered ( ) ) , app_ - > player ( ) , SLOT ( Next ( ) ) ) ;
connect ( ui_ - > action_previous_track , SIGNAL ( triggered ( ) ) , app_ - > player ( ) , SLOT ( Previous ( ) ) ) ;
connect ( ui_ - > action_play_pause , SIGNAL ( triggered ( ) ) , app_ - > player ( ) , SLOT ( PlayPause ( ) ) ) ;
connect ( ui_ - > action_stop , SIGNAL ( triggered ( ) ) , app_ - > player ( ) , SLOT ( Stop ( ) ) ) ;
2011-02-16 22:43:05 +00:00
connect ( ui_ - > action_quit , SIGNAL ( triggered ( ) ) , SLOT ( Exit ( ) ) ) ;
2010-05-10 21:50:31 +00:00
connect ( ui_ - > action_stop_after_this_track , SIGNAL ( triggered ( ) ) , SLOT ( StopAfterCurrent ( ) ) ) ;
2012-02-12 13:41:50 +00:00
connect ( ui_ - > action_mute , SIGNAL ( triggered ( ) ) , app_ - > player ( ) , SLOT ( Mute ( ) ) ) ;
2010-12-18 17:28:02 +00:00
# ifdef HAVE_LIBLASTFM
2011-07-15 13:27:50 +00:00
connect ( ui_ - > action_ban , SIGNAL ( triggered ( ) ) , InternetModel : : Service < LastFMService > ( ) , SLOT ( Ban ( ) ) ) ;
2010-05-10 21:50:31 +00:00
connect ( ui_ - > action_love , SIGNAL ( triggered ( ) ) , SLOT ( Love ( ) ) ) ;
2011-07-15 13:27:50 +00:00
connect ( ui_ - > action_toggle_scrobbling , SIGNAL ( triggered ( ) ) , InternetModel : : Service < LastFMService > ( ) , SLOT ( ToggleScrobbling ( ) ) ) ;
2010-12-18 17:28:02 +00:00
# endif
2012-02-12 13:41:50 +00:00
connect ( ui_ - > action_clear_playlist , SIGNAL ( triggered ( ) ) , app_ - > playlist_manager ( ) , SLOT ( ClearCurrent ( ) ) ) ;
2012-07-06 00:00:33 +02:00
connect ( ui_ - > action_remove_duplicates , SIGNAL ( triggered ( ) ) , app_ - > playlist_manager ( ) , SLOT ( RemoveDuplicatesCurrent ( ) ) ) ;
2010-05-10 21:50:31 +00:00
connect ( ui_ - > action_remove_from_playlist , SIGNAL ( triggered ( ) ) , SLOT ( PlaylistRemoveCurrent ( ) ) ) ;
connect ( ui_ - > action_edit_track , SIGNAL ( triggered ( ) ) , SLOT ( EditTracks ( ) ) ) ;
connect ( ui_ - > action_renumber_tracks , SIGNAL ( triggered ( ) ) , SLOT ( RenumberTracks ( ) ) ) ;
connect ( ui_ - > action_selection_set_value , SIGNAL ( triggered ( ) ) , SLOT ( SelectionSetValue ( ) ) ) ;
connect ( ui_ - > action_edit_value , SIGNAL ( triggered ( ) ) , SLOT ( EditValue ( ) ) ) ;
2011-03-06 14:07:41 +00:00
connect ( ui_ - > action_auto_complete_tags , SIGNAL ( triggered ( ) ) , SLOT ( AutoCompleteTags ( ) ) ) ;
2010-08-27 15:42:58 +00:00
connect ( ui_ - > action_configure , SIGNAL ( triggered ( ) ) , SLOT ( OpenSettingsDialog ( ) ) ) ;
connect ( ui_ - > action_about , SIGNAL ( triggered ( ) ) , SLOT ( ShowAboutDialog ( ) ) ) ;
2010-09-30 21:25:31 +00:00
connect ( ui_ - > action_about_qt , SIGNAL ( triggered ( ) ) , qApp , SLOT ( aboutQt ( ) ) ) ;
2012-02-12 13:41:50 +00:00
connect ( ui_ - > action_shuffle , SIGNAL ( triggered ( ) ) , app_ - > playlist_manager ( ) , SLOT ( ShuffleCurrent ( ) ) ) ;
2010-05-11 20:02:19 +00:00
connect ( ui_ - > action_open_media , SIGNAL ( triggered ( ) ) , SLOT ( AddFile ( ) ) ) ;
2011-06-09 23:08:43 +00:00
connect ( ui_ - > action_open_cd , SIGNAL ( triggered ( ) ) , SLOT ( AddCDTracks ( ) ) ) ;
2010-05-11 20:02:19 +00:00
connect ( ui_ - > action_add_file , SIGNAL ( triggered ( ) ) , SLOT ( AddFile ( ) ) ) ;
connect ( ui_ - > action_add_folder , SIGNAL ( triggered ( ) ) , SLOT ( AddFolder ( ) ) ) ;
2010-05-10 21:50:31 +00:00
connect ( ui_ - > action_add_stream , SIGNAL ( triggered ( ) ) , SLOT ( AddStream ( ) ) ) ;
2012-03-12 14:11:24 +00:00
connect ( ui_ - > action_add_podcast , SIGNAL ( triggered ( ) ) , SLOT ( AddPodcast ( ) ) ) ;
2010-08-27 15:42:58 +00:00
connect ( ui_ - > action_cover_manager , SIGNAL ( triggered ( ) ) , SLOT ( ShowCoverManager ( ) ) ) ;
2010-05-10 21:50:31 +00:00
connect ( ui_ - > action_equalizer , SIGNAL ( triggered ( ) ) , equalizer_ . get ( ) , SLOT ( show ( ) ) ) ;
2010-08-27 15:42:58 +00:00
connect ( ui_ - > action_transcode , SIGNAL ( triggered ( ) ) , SLOT ( ShowTranscodeDialog ( ) ) ) ;
2010-05-20 14:12:15 +00:00
connect ( ui_ - > action_jump , SIGNAL ( triggered ( ) ) , ui_ - > playlist - > view ( ) , SLOT ( JumpToCurrentlyPlayingTrack ( ) ) ) ;
2012-02-12 13:41:50 +00:00
connect ( ui_ - > action_update_library , SIGNAL ( triggered ( ) ) , app_ - > library ( ) , SLOT ( IncrementalScan ( ) ) ) ;
connect ( ui_ - > action_full_library_scan , SIGNAL ( triggered ( ) ) , app_ - > library ( ) , SLOT ( FullScan ( ) ) ) ;
2010-08-27 19:09:03 +00:00
connect ( ui_ - > action_queue_manager , SIGNAL ( triggered ( ) ) , SLOT ( ShowQueueManager ( ) ) ) ;
2009-12-24 19:16:07 +00:00
2011-06-19 14:42:00 +00:00
background_streams_ - > AddAction ( " Rain " , ui_ - > action_rain ) ;
background_streams_ - > AddAction ( " Hypnotoad " , ui_ - > action_hypnotoad ) ;
2012-01-10 17:00:17 +01:00
background_streams_ - > AddAction ( " Make it so! " , ui_ - > action_enterprise ) ;
2011-06-19 14:42:00 +00:00
2011-04-19 20:11:24 +00:00
// Playlist view actions
ui_ - > action_next_playlist - > setShortcuts ( QList < QKeySequence > ( )
< < QKeySequence : : fromString ( " Ctrl+Tab " )
< < QKeySequence : : fromString ( " Ctrl+PgDown " ) ) ;
ui_ - > action_previous_playlist - > setShortcuts ( QList < QKeySequence > ( )
< < QKeySequence : : fromString ( " Ctrl+Shift+Tab " )
< < QKeySequence : : fromString ( " Ctrl+PgUp " ) ) ;
// Actions for switching tabs will be global to the entire window, so adding them here
addAction ( ui_ - > action_next_playlist ) ;
addAction ( ui_ - > action_previous_playlist ) ;
2009-12-24 19:16:07 +00:00
// Give actions to buttons
2010-05-10 21:50:31 +00:00
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 ) ;
ui_ - > love_button - > setDefaultAction ( ui_ - > action_love ) ;
ui_ - > ban_button - > setDefaultAction ( ui_ - > action_ban ) ;
2011-04-07 16:25:52 +00:00
ui_ - > scrobbling_button - > setDefaultAction ( ui_ - > action_toggle_scrobbling ) ;
2010-06-18 15:07:21 +00:00
ui_ - > clear_playlist_button - > setDefaultAction ( ui_ - > action_clear_playlist ) ;
2010-05-20 14:12:15 +00:00
ui_ - > playlist - > SetActions ( ui_ - > action_new_playlist , ui_ - > action_save_playlist ,
2011-04-19 20:11:24 +00:00
ui_ - > action_load_playlist ,
ui_ - > action_next_playlist , /* These two actions aren't associated */
ui_ - > action_previous_playlist /* to a button but to the main window */ ) ;
2010-06-10 22:48:23 +00:00
2011-04-07 16:25:52 +00:00
2010-06-10 22:48:23 +00:00
# ifdef ENABLE_VISUALISATIONS
2010-08-27 19:09:03 +00:00
connect ( ui_ - > action_visualisations , SIGNAL ( triggered ( ) ) , SLOT ( ShowVisualisations ( ) ) ) ;
2010-06-10 22:48:23 +00:00
# else
ui_ - > action_visualisations - > setEnabled ( false ) ;
# endif
2009-12-24 19:16:07 +00:00
2010-03-12 01:03:43 +00:00
// Add the shuffle and repeat action groups to the menu
2010-06-16 19:21:15 +00:00
ui_ - > action_shuffle_mode - > setMenu ( ui_ - > playlist_sequence - > shuffle_menu ( ) ) ;
ui_ - > action_repeat_mode - > setMenu ( ui_ - > playlist_sequence - > repeat_menu ( ) ) ;
2010-03-12 01:03:43 +00:00
2009-12-24 19:16:07 +00:00
// Stop actions
QMenu * stop_menu = new QMenu ( this ) ;
2010-05-10 21:50:31 +00:00
stop_menu - > addAction ( ui_ - > action_stop ) ;
stop_menu - > addAction ( ui_ - > action_stop_after_this_track ) ;
ui_ - > stop_button - > setMenu ( stop_menu ) ;
2009-12-24 19:16:07 +00:00
// Player connections
2012-02-12 13:41:50 +00:00
connect ( ui_ - > volume , SIGNAL ( valueChanged ( int ) ) , app_ - > player ( ) , SLOT ( SetVolume ( int ) ) ) ;
connect ( app_ - > player ( ) , SIGNAL ( Error ( QString ) ) , SLOT ( ShowErrorDialog ( QString ) ) ) ;
connect ( app_ - > player ( ) , SIGNAL ( SongChangeRequestProcessed ( QUrl , bool ) ) , app_ - > playlist_manager ( ) , SLOT ( SongChangeRequestProcessed ( QUrl , bool ) ) ) ;
connect ( app_ - > player ( ) , SIGNAL ( Paused ( ) ) , SLOT ( MediaPaused ( ) ) ) ;
connect ( app_ - > player ( ) , SIGNAL ( Playing ( ) ) , SLOT ( MediaPlaying ( ) ) ) ;
connect ( app_ - > player ( ) , SIGNAL ( Stopped ( ) ) , SLOT ( MediaStopped ( ) ) ) ;
connect ( app_ - > player ( ) , SIGNAL ( Seeked ( qlonglong ) ) , SLOT ( Seeked ( qlonglong ) ) ) ;
connect ( app_ - > player ( ) , SIGNAL ( TrackSkipped ( PlaylistItemPtr ) ) , SLOT ( TrackSkipped ( PlaylistItemPtr ) ) ) ;
connect ( app_ - > player ( ) , SIGNAL ( VolumeChanged ( int ) ) , SLOT ( VolumeChanged ( int ) ) ) ;
connect ( app_ - > player ( ) , SIGNAL ( Paused ( ) ) , ui_ - > playlist , SLOT ( ActivePaused ( ) ) ) ;
connect ( app_ - > player ( ) , SIGNAL ( Playing ( ) ) , ui_ - > playlist , SLOT ( ActivePlaying ( ) ) ) ;
connect ( app_ - > player ( ) , SIGNAL ( Stopped ( ) ) , ui_ - > playlist , SLOT ( ActiveStopped ( ) ) ) ;
connect ( app_ - > player ( ) , SIGNAL ( Paused ( ) ) , osd_ , SLOT ( Paused ( ) ) ) ;
connect ( app_ - > player ( ) , SIGNAL ( Stopped ( ) ) , osd_ , SLOT ( Stopped ( ) ) ) ;
connect ( app_ - > player ( ) , SIGNAL ( PlaylistFinished ( ) ) , osd_ , SLOT ( PlaylistFinished ( ) ) ) ;
connect ( app_ - > player ( ) , SIGNAL ( VolumeChanged ( int ) ) , osd_ , SLOT ( VolumeChanged ( int ) ) ) ;
connect ( app_ - > player ( ) , SIGNAL ( VolumeChanged ( int ) ) , ui_ - > volume , SLOT ( setValue ( int ) ) ) ;
connect ( app_ - > player ( ) , SIGNAL ( ForceShowOSD ( Song , bool ) ) , SLOT ( ForceShowOSD ( Song , bool ) ) ) ;
connect ( app_ - > playlist_manager ( ) , SIGNAL ( CurrentSongChanged ( Song ) ) , SLOT ( SongChanged ( Song ) ) ) ;
connect ( app_ - > playlist_manager ( ) , SIGNAL ( CurrentSongChanged ( Song ) ) , app_ - > player ( ) , SLOT ( CurrentMetadataChanged ( Song ) ) ) ;
connect ( app_ - > playlist_manager ( ) , SIGNAL ( EditingFinished ( QModelIndex ) ) , SLOT ( PlaylistEditFinished ( QModelIndex ) ) ) ;
connect ( app_ - > playlist_manager ( ) , SIGNAL ( Error ( QString ) ) , SLOT ( ShowErrorDialog ( QString ) ) ) ;
connect ( app_ - > playlist_manager ( ) , SIGNAL ( SummaryTextChanged ( QString ) ) , ui_ - > playlist_summary , SLOT ( setText ( QString ) ) ) ;
connect ( app_ - > playlist_manager ( ) , SIGNAL ( PlayRequested ( QModelIndex ) ) , SLOT ( PlayIndex ( QModelIndex ) ) ) ;
2009-12-24 19:16:07 +00:00
2010-05-20 14:12:15 +00:00
connect ( ui_ - > playlist - > view ( ) , SIGNAL ( doubleClicked ( QModelIndex ) ) , SLOT ( PlayIndex ( QModelIndex ) ) ) ;
2011-02-23 23:59:12 +00:00
connect ( ui_ - > playlist - > view ( ) , SIGNAL ( PlayItem ( QModelIndex ) ) , SLOT ( PlayIndex ( QModelIndex ) ) ) ;
2012-02-12 13:41:50 +00:00
connect ( ui_ - > playlist - > view ( ) , SIGNAL ( PlayPause ( ) ) , app_ - > player ( ) , SLOT ( PlayPause ( ) ) ) ;
2010-05-20 14:12:15 +00:00
connect ( ui_ - > playlist - > view ( ) , SIGNAL ( RightClicked ( QPoint , QModelIndex ) ) , SLOT ( PlaylistRightClick ( QPoint , QModelIndex ) ) ) ;
2011-01-26 23:20:56 +00:00
connect ( ui_ - > playlist - > view ( ) , SIGNAL ( SeekTrack ( int ) ) , ui_ - > track_slider , SLOT ( Seek ( int ) ) ) ;
2011-06-08 14:48:43 +00:00
connect ( ui_ - > playlist - > view ( ) , SIGNAL ( BackgroundPropertyChanged ( ) ) , SLOT ( RefreshStyleSheet ( ) ) ) ;
2010-01-15 17:12:47 +00:00
2012-02-12 13:41:50 +00:00
connect ( ui_ - > track_slider , SIGNAL ( ValueChanged ( int ) ) , app_ - > player ( ) , SLOT ( SeekTo ( int ) ) ) ;
2010-03-06 15:33:57 +00:00
2009-12-24 19:16:07 +00:00
// Library connections
2011-01-10 22:26:13 +00:00
connect ( library_view_ - > view ( ) , SIGNAL ( AddToPlaylistSignal ( QMimeData * ) ) , SLOT ( AddToPlaylist ( QMimeData * ) ) ) ;
2010-10-01 19:27:01 +00:00
connect ( library_view_ - > view ( ) , SIGNAL ( ShowConfigDialog ( ) ) , SLOT ( ShowLibraryConfig ( ) ) ) ;
2012-02-12 13:41:50 +00:00
connect ( app_ - > library_model ( ) , SIGNAL ( TotalSongCountUpdated ( int ) ) , library_view_ - > view ( ) , SLOT ( TotalSongCountUpdated ( int ) ) ) ;
2012-08-26 13:36:44 +01:00
connect ( app_ - > library_model ( ) , SIGNAL ( modelAboutToBeReset ( ) ) , library_view_ - > view ( ) , SLOT ( SaveFocus ( ) ) ) ;
connect ( app_ - > library_model ( ) , SIGNAL ( modelReset ( ) ) , library_view_ - > view ( ) , SLOT ( RestoreFocus ( ) ) ) ;
2009-12-24 19:16:07 +00:00
2012-02-12 13:41:50 +00:00
connect ( app_ - > task_manager ( ) , SIGNAL ( PauseLibraryWatchers ( ) ) , app_ - > library ( ) , SLOT ( PauseWatcher ( ) ) ) ;
connect ( app_ - > task_manager ( ) , SIGNAL ( ResumeLibraryWatchers ( ) ) , app_ - > library ( ) , SLOT ( ResumeWatcher ( ) ) ) ;
2010-06-24 21:46:18 +00:00
2010-07-04 20:52:45 +00:00
// Devices connections
2011-01-10 22:26:13 +00:00
connect ( device_view_ , SIGNAL ( AddToPlaylistSignal ( QMimeData * ) ) , SLOT ( AddToPlaylist ( QMimeData * ) ) ) ;
2010-07-04 20:52:45 +00:00
2010-05-09 20:18:05 +00:00
// Library filter widget
2011-02-06 13:18:18 +00:00
QActionGroup * library_view_group = new QActionGroup ( this ) ;
library_show_all_ = library_view_group - > addAction ( tr ( " Show all songs " ) ) ;
library_show_duplicates_ = library_view_group - > addAction ( tr ( " Show only duplicates " ) ) ;
library_show_untagged_ = library_view_group - > addAction ( tr ( " Show only untagged " ) ) ;
library_show_all_ - > setCheckable ( true ) ;
library_show_duplicates_ - > setCheckable ( true ) ;
library_show_untagged_ - > setCheckable ( true ) ;
library_show_all_ - > setChecked ( true ) ;
connect ( library_view_group , SIGNAL ( triggered ( QAction * ) ) , SLOT ( ChangeLibraryQueryMode ( QAction * ) ) ) ;
2011-01-30 21:00:49 +00:00
2010-06-09 15:38:00 +00:00
QAction * library_config_action = new QAction (
IconLoader : : Load ( " configure " ) , tr ( " Configure library... " ) , this ) ;
connect ( library_config_action , SIGNAL ( triggered ( ) ) , SLOT ( ShowLibraryConfig ( ) ) ) ;
2010-10-01 19:27:01 +00:00
library_view_ - > filter ( ) - > SetSettingsGroup ( kSettingsGroup ) ;
2012-02-12 13:41:50 +00:00
library_view_ - > filter ( ) - > SetLibraryModel ( app_ - > library ( ) - > model ( ) ) ;
2011-01-30 21:00:49 +00:00
2011-02-02 16:22:04 +00:00
QAction * separator = new QAction ( this ) ;
separator - > setSeparator ( true ) ;
2011-02-06 13:18:18 +00:00
library_view_ - > filter ( ) - > AddMenuAction ( library_show_all_ ) ;
library_view_ - > filter ( ) - > AddMenuAction ( library_show_duplicates_ ) ;
library_view_ - > filter ( ) - > AddMenuAction ( library_show_untagged_ ) ;
2011-02-02 16:22:04 +00:00
library_view_ - > filter ( ) - > AddMenuAction ( separator ) ;
2010-10-01 19:27:01 +00:00
library_view_ - > filter ( ) - > AddMenuAction ( library_config_action ) ;
2009-12-24 19:16:07 +00:00
2010-01-15 16:22:19 +00:00
// Playlist menu
2010-02-23 18:33:09 +00:00
playlist_play_pause_ = playlist_menu_ - > addAction ( tr ( " Play " ) , this , SLOT ( PlaylistPlay ( ) ) ) ;
2010-05-10 21:50:31 +00:00
playlist_menu_ - > addAction ( ui_ - > action_stop ) ;
2010-05-19 15:45:29 +00:00
playlist_stop_after_ = playlist_menu_ - > addAction ( IconLoader : : Load ( " media-playback-stop " ) , tr ( " Stop after this track " ) , this , SLOT ( PlaylistStopAfter ( ) ) ) ;
2010-07-11 21:52:00 +00:00
playlist_queue_ = playlist_menu_ - > addAction ( " " , this , SLOT ( PlaylistQueue ( ) ) ) ;
2010-07-26 15:21:56 +00:00
playlist_queue_ - > setShortcut ( QKeySequence ( " Ctrl+D " ) ) ;
ui_ - > playlist - > addAction ( playlist_queue_ ) ;
2010-03-24 00:12:52 +00:00
playlist_menu_ - > addSeparator ( ) ;
2010-05-10 21:50:31 +00:00
playlist_menu_ - > addAction ( ui_ - > action_remove_from_playlist ) ;
2010-05-20 21:21:55 +00:00
playlist_undoredo_ = playlist_menu_ - > addSeparator ( ) ;
2010-05-10 21:50:31 +00:00
playlist_menu_ - > addAction ( ui_ - > action_edit_track ) ;
playlist_menu_ - > addAction ( ui_ - > action_edit_value ) ;
playlist_menu_ - > addAction ( ui_ - > action_renumber_tracks ) ;
playlist_menu_ - > addAction ( ui_ - > action_selection_set_value ) ;
2011-03-06 14:07:41 +00:00
playlist_menu_ - > addAction ( ui_ - > action_auto_complete_tags ) ;
2010-01-15 16:22:19 +00:00
playlist_menu_ - > addSeparator ( ) ;
2010-06-24 23:36:39 +00:00
playlist_copy_to_library_ = playlist_menu_ - > addAction ( IconLoader : : Load ( " edit-copy " ) , tr ( " Copy to library... " ) , this , SLOT ( PlaylistCopyToLibrary ( ) ) ) ;
playlist_move_to_library_ = playlist_menu_ - > addAction ( IconLoader : : Load ( " go-jump " ) , tr ( " Move to library... " ) , this , SLOT ( PlaylistMoveToLibrary ( ) ) ) ;
playlist_organise_ = playlist_menu_ - > addAction ( IconLoader : : Load ( " edit-copy " ) , tr ( " Organise files... " ) , this , SLOT ( PlaylistMoveToLibrary ( ) ) ) ;
2010-08-08 13:06:52 +00:00
playlist_copy_to_device_ = playlist_menu_ - > addAction ( IconLoader : : Load ( " multimedia-player-ipod-mini-blue " ) , tr ( " Copy to device... " ) , this , SLOT ( PlaylistCopyToDevice ( ) ) ) ;
2010-12-11 10:54:42 +00:00
playlist_delete_ = playlist_menu_ - > addAction ( IconLoader : : Load ( " edit-delete " ) , tr ( " Delete from disk... " ) , this , SLOT ( PlaylistDelete ( ) ) ) ;
2011-03-06 13:10:14 +00:00
playlist_open_in_browser_ = playlist_menu_ - > addAction ( IconLoader : : Load ( " document-open-folder " ) , tr ( " Show in file browser... " ) , this , SLOT ( PlaylistOpenInBrowser ( ) ) ) ;
2010-06-24 23:36:39 +00:00
playlist_menu_ - > addSeparator ( ) ;
2012-07-29 03:11:00 +02:00
playlistitem_actions_separator_ = playlist_menu_ - > addSeparator ( ) ;
2010-05-10 21:50:31 +00:00
playlist_menu_ - > addAction ( ui_ - > action_clear_playlist ) ;
playlist_menu_ - > addAction ( ui_ - > action_shuffle ) ;
2012-07-29 02:38:24 +02:00
playlist_menu_ - > addAction ( ui_ - > action_remove_duplicates ) ;
2010-01-15 16:22:19 +00:00
2010-07-26 12:05:50 +00:00
# ifdef Q_OS_DARWIN
ui_ - > action_shuffle - > setShortcut ( QKeySequence ( ) ) ;
# endif
2011-03-06 18:26:06 +00:00
// We have to add the actions on the playlist menu to this QWidget otherwise
// their shortcut keys don't work
addActions ( playlist_menu_ - > actions ( ) ) ;
2010-05-20 21:21:55 +00:00
connect ( ui_ - > playlist , SIGNAL ( UndoRedoActionsChanged ( QAction * , QAction * ) ) ,
SLOT ( PlaylistUndoRedoChanged ( QAction * , QAction * ) ) ) ;
2012-02-12 13:41:50 +00:00
playlist_copy_to_device_ - > setDisabled ( app_ - > device_manager ( ) - > connected_devices_model ( ) - > rowCount ( ) = = 0 ) ;
connect ( app_ - > device_manager ( ) - > connected_devices_model ( ) , SIGNAL ( IsEmptyChanged ( bool ) ) ,
2010-08-08 13:06:52 +00:00
playlist_copy_to_device_ , SLOT ( setDisabled ( bool ) ) ) ;
2012-06-16 21:17:13 +01:00
// Global search shortcut
QAction * global_search_action = new QAction ( this ) ;
global_search_action - > setShortcuts ( QList < QKeySequence > ( )
< < QKeySequence ( " Ctrl+F " )
< < QKeySequence ( " Ctrl+L " ) ) ;
addAction ( global_search_action ) ;
connect ( global_search_action , SIGNAL ( triggered ( ) ) ,
SLOT ( FocusGlobalSearchField ( ) ) ) ;
2011-07-15 13:27:50 +00:00
// Internet connections
2012-02-12 13:41:50 +00:00
connect ( app_ - > internet_model ( ) , SIGNAL ( StreamError ( QString ) ) , SLOT ( ShowErrorDialog ( QString ) ) ) ;
connect ( app_ - > internet_model ( ) , SIGNAL ( StreamMetadataFound ( QUrl , Song ) ) , app_ - > playlist_manager ( ) , SLOT ( SetActiveStreamMetadata ( QUrl , Song ) ) ) ;
connect ( app_ - > internet_model ( ) , SIGNAL ( AddToPlaylist ( QMimeData * ) ) , SLOT ( AddToPlaylist ( QMimeData * ) ) ) ;
2012-03-11 17:57:15 +00:00
connect ( app_ - > internet_model ( ) , SIGNAL ( ScrollToIndex ( QModelIndex ) ) , SLOT ( ScrollToInternetIndex ( QModelIndex ) ) ) ;
2010-12-18 17:28:02 +00:00
# ifdef HAVE_LIBLASTFM
2011-07-15 13:27:50 +00:00
LastFMService * lastfm_service = InternetModel : : Service < LastFMService > ( ) ;
2011-04-16 15:27:34 +00:00
connect ( lastfm_service , SIGNAL ( ButtonVisibilityChanged ( bool ) ) , SLOT ( LastFMButtonVisibilityChanged ( bool ) ) ) ;
connect ( lastfm_service , SIGNAL ( ScrobbleButtonVisibilityChanged ( bool ) ) , SLOT ( ScrobbleButtonVisibilityChanged ( bool ) ) ) ;
connect ( lastfm_service , SIGNAL ( ScrobblingEnabledChanged ( bool ) ) , SLOT ( ScrobblingEnabledChanged ( bool ) ) ) ;
connect ( lastfm_service , SIGNAL ( ScrobbledRadioStream ( ) ) , SLOT ( ScrobbledRadioStream ( ) ) ) ;
2010-12-18 17:28:02 +00:00
# endif
2012-02-12 13:41:50 +00:00
connect ( app_ - > internet_model ( ) - > Service < MagnatuneService > ( ) , SIGNAL ( DownloadFinished ( QStringList ) ) , osd_ , SLOT ( MagnatuneDownloadFinished ( QStringList ) ) ) ;
2011-07-15 13:27:50 +00:00
connect ( internet_view_ - > tree ( ) , SIGNAL ( AddToPlaylistSignal ( QMimeData * ) ) , SLOT ( AddToPlaylist ( QMimeData * ) ) ) ;
2009-12-26 21:35:45 +00:00
2010-05-27 22:53:07 +00:00
// Connections to the saved streams service
2011-07-15 13:27:50 +00:00
connect ( InternetModel : : Service < SavedRadio > ( ) , SIGNAL ( ShowAddStreamDialog ( ) ) , SLOT ( AddStream ( ) ) ) ;
2010-05-27 22:53:07 +00:00
2010-06-22 14:09:13 +00:00
# ifdef Q_OS_DARWIN
mac : : SetApplicationHandler ( this ) ;
# endif
2009-12-24 19:16:07 +00:00
// Tray icon
2010-06-22 11:52:55 +00:00
tray_icon_ - > SetupMenu ( ui_ - > action_previous_track ,
ui_ - > action_play_pause ,
ui_ - > action_stop ,
ui_ - > action_stop_after_this_track ,
ui_ - > action_next_track ,
2010-11-21 21:36:27 +00:00
ui_ - > action_mute ,
2010-06-22 11:52:55 +00:00
ui_ - > action_love ,
ui_ - > action_ban ,
ui_ - > action_quit ) ;
2012-02-12 13:41:50 +00:00
connect ( tray_icon_ , SIGNAL ( PlayPause ( ) ) , app_ - > player ( ) , SLOT ( PlayPause ( ) ) ) ;
connect ( tray_icon_ , SIGNAL ( SeekForward ( ) ) , app_ - > player ( ) , SLOT ( SeekForward ( ) ) ) ;
connect ( tray_icon_ , SIGNAL ( SeekBackward ( ) ) , app_ - > player ( ) , SLOT ( SeekBackward ( ) ) ) ;
connect ( tray_icon_ , SIGNAL ( NextTrack ( ) ) , app_ - > player ( ) , SLOT ( Next ( ) ) ) ;
connect ( tray_icon_ , SIGNAL ( PreviousTrack ( ) ) , app_ - > player ( ) , SLOT ( Previous ( ) ) ) ;
2010-06-22 11:52:55 +00:00
connect ( tray_icon_ , SIGNAL ( ShowHide ( ) ) , SLOT ( ToggleShowHide ( ) ) ) ;
connect ( tray_icon_ , SIGNAL ( ChangeVolume ( int ) ) , SLOT ( VolumeWheelEvent ( int ) ) ) ;
2010-12-03 13:53:43 +00:00
2011-01-16 00:39:51 +00:00
// Windows 7 thumbbar buttons
thumbbar_ - > SetActions ( QList < QAction * > ( )
< < ui_ - > action_previous_track
< < ui_ - > action_play_pause
< < ui_ - > action_stop
< < ui_ - > action_next_track
< < NULL // spacer
< < ui_ - > action_love
< < ui_ - > action_ban ) ;
2010-12-30 16:20:33 +00:00
# if (defined(Q_OS_DARWIN) && defined(HAVE_SPARKLE)) || defined(Q_OS_WIN32)
// Add check for updates item to application menu.
2011-01-02 18:33:31 +00:00
QAction * check_updates = ui_ - > menu_tools - > addAction ( tr ( " Check for updates... " ) ) ;
2010-12-30 16:20:33 +00:00
check_updates - > setMenuRole ( QAction : : ApplicationSpecificRole ) ;
connect ( check_updates , SIGNAL ( triggered ( bool ) ) , SLOT ( CheckForUpdates ( ) ) ) ;
# endif
2010-05-25 13:19:28 +00:00
2010-12-30 16:20:33 +00:00
# ifdef Q_OS_WIN32
2011-04-24 18:07:09 +00:00
qLog ( Debug ) < < " Creating sparkle updater " ;
2010-12-30 16:20:33 +00:00
qtsparkle : : Updater * updater = new qtsparkle : : Updater (
2011-11-25 16:49:28 +01:00
QUrl ( " https://clementine-data.appspot.com/sparkle-windows " ) , this ) ;
2010-12-30 16:20:33 +00:00
updater - > SetNetworkAccessManager ( new NetworkAccessManager ( this ) ) ;
2011-12-02 14:47:25 +00:00
updater - > SetVersion ( CLEMENTINE_VERSION_SPARKLE ) ;
2010-12-30 16:20:33 +00:00
connect ( check_updates , SIGNAL ( triggered ( ) ) , updater , SLOT ( CheckNow ( ) ) ) ;
# endif
2009-12-30 16:24:55 +00:00
// Global shortcuts
2012-02-12 13:41:50 +00:00
connect ( global_shortcuts_ , SIGNAL ( Play ( ) ) , app_ - > player ( ) , SLOT ( Play ( ) ) ) ;
connect ( global_shortcuts_ , SIGNAL ( Pause ( ) ) , app_ - > player ( ) , SLOT ( Pause ( ) ) ) ;
2010-05-10 21:50:31 +00:00
connect ( global_shortcuts_ , SIGNAL ( PlayPause ( ) ) , ui_ - > action_play_pause , SLOT ( trigger ( ) ) ) ;
connect ( global_shortcuts_ , SIGNAL ( Stop ( ) ) , ui_ - > action_stop , SLOT ( trigger ( ) ) ) ;
2010-05-17 11:06:50 +00:00
connect ( global_shortcuts_ , SIGNAL ( StopAfter ( ) ) , ui_ - > action_stop_after_this_track , SLOT ( trigger ( ) ) ) ;
2010-05-10 21:50:31 +00:00
connect ( global_shortcuts_ , SIGNAL ( Next ( ) ) , ui_ - > action_next_track , SLOT ( trigger ( ) ) ) ;
connect ( global_shortcuts_ , SIGNAL ( Previous ( ) ) , ui_ - > action_previous_track , SLOT ( trigger ( ) ) ) ;
2012-02-12 13:41:50 +00:00
connect ( global_shortcuts_ , SIGNAL ( IncVolume ( ) ) , app_ - > player ( ) , SLOT ( VolumeUp ( ) ) ) ;
connect ( global_shortcuts_ , SIGNAL ( DecVolume ( ) ) , app_ - > player ( ) , SLOT ( VolumeDown ( ) ) ) ;
connect ( global_shortcuts_ , SIGNAL ( Mute ( ) ) , app_ - > player ( ) , SLOT ( Mute ( ) ) ) ;
connect ( global_shortcuts_ , SIGNAL ( SeekForward ( ) ) , app_ - > player ( ) , SLOT ( SeekForward ( ) ) ) ;
connect ( global_shortcuts_ , SIGNAL ( SeekBackward ( ) ) , app_ - > player ( ) , SLOT ( SeekBackward ( ) ) ) ;
2010-07-24 12:39:09 +00:00
connect ( global_shortcuts_ , SIGNAL ( ShowHide ( ) ) , SLOT ( ToggleShowHide ( ) ) ) ;
2012-02-12 13:41:50 +00:00
connect ( global_shortcuts_ , SIGNAL ( ShowOSD ( ) ) , app_ - > player ( ) , SLOT ( ShowOSD ( ) ) ) ;
connect ( global_shortcuts_ , SIGNAL ( TogglePrettyOSD ( ) ) , app_ - > player ( ) , SLOT ( TogglePrettyOSD ( ) ) ) ;
2011-04-07 16:25:52 +00:00
# ifdef HAVE_LIBLASTFM
2012-02-12 13:41:50 +00:00
connect ( global_shortcuts_ , SIGNAL ( ToggleScrobbling ( ) ) , app_ - > internet_model ( ) - > InternetModel : : Service < LastFMService > ( ) , SLOT ( ToggleScrobbling ( ) ) ) ;
2011-04-07 16:25:52 +00:00
# endif
2010-02-24 22:26:01 +00:00
2012-02-12 13:41:50 +00:00
connect ( global_shortcuts_ , SIGNAL ( RateCurrentSong ( int ) ) , app_ - > playlist_manager ( ) , SLOT ( RateCurrentSong ( int ) ) ) ;
2010-12-17 00:21:20 +00:00
2010-10-09 18:18:06 +00:00
// Fancy tabs
connect ( ui_ - > tabs , SIGNAL ( ModeChanged ( FancyTabWidget : : Mode ) ) , SLOT ( SaveGeometry ( ) ) ) ;
connect ( ui_ - > tabs , SIGNAL ( CurrentChanged ( int ) ) , SLOT ( SaveGeometry ( ) ) ) ;
2010-09-26 16:00:28 +00:00
// Lyrics
2010-10-10 16:09:20 +00:00
ConnectInfoView ( song_info_view_ ) ;
2010-10-02 16:23:33 +00:00
ConnectInfoView ( artist_info_view_ ) ;
2010-09-26 16:00:28 +00:00
2009-12-24 19:16:07 +00:00
// Analyzer
2012-02-12 13:41:50 +00:00
ui_ - > analyzer - > SetEngine ( app_ - > player ( ) - > engine ( ) ) ;
2010-06-23 15:52:56 +00:00
ui_ - > analyzer - > SetActions ( ui_ - > action_visualisations ) ;
2009-12-24 19:16:07 +00:00
2010-04-07 16:26:04 +00:00
// Equalizer
2011-04-24 18:07:09 +00:00
qLog ( Debug ) < < " Creating equalizer " ;
2010-04-14 21:58:51 +00:00
connect ( equalizer_ . get ( ) , SIGNAL ( ParametersChanged ( int , QList < int > ) ) ,
2012-02-12 13:41:50 +00:00
app_ - > player ( ) - > engine ( ) , SLOT ( SetEqualizerParameters ( int , QList < int > ) ) ) ;
2010-04-14 21:58:51 +00:00
connect ( equalizer_ . get ( ) , SIGNAL ( EnabledChanged ( bool ) ) ,
2012-02-12 13:41:50 +00:00
app_ - > player ( ) - > engine ( ) , SLOT ( SetEqualizerEnabled ( bool ) ) ) ;
app_ - > player ( ) - > engine ( ) - > SetEqualizerEnabled ( equalizer_ - > is_enabled ( ) ) ;
app_ - > player ( ) - > engine ( ) - > SetEqualizerParameters (
2010-04-08 15:13:34 +00:00
equalizer_ - > preamp_value ( ) , equalizer_ - > gain_values ( ) ) ;
2010-04-07 16:26:04 +00:00
2010-01-15 17:12:47 +00:00
// Statusbar widgets
2010-06-16 19:21:15 +00:00
ui_ - > playlist_summary - > setMinimumWidth ( QFontMetrics ( font ( ) ) . width ( " WW selected of WW tracks - [ WW:WW ] " ) ) ;
ui_ - > status_bar_stack - > setCurrentWidget ( ui_ - > playlist_summary_page ) ;
connect ( ui_ - > multi_loading_indicator , SIGNAL ( TaskCountChange ( int ) ) , SLOT ( TaskCountChanged ( int ) ) ) ;
2010-01-15 17:12:47 +00:00
2012-05-27 23:44:49 +01:00
ui_ - > track_slider - > SetApplication ( app ) ;
2012-05-27 21:15:58 +01:00
# ifdef HAVE_MOODBAR
2012-05-25 22:02:10 +01:00
// Moodbar connections
connect ( app_ - > moodbar_controller ( ) , SIGNAL ( CurrentMoodbarDataChanged ( QByteArray ) ) ,
ui_ - > track_slider - > moodbar_style ( ) , SLOT ( SetMoodbarData ( QByteArray ) ) ) ;
2012-05-27 21:15:58 +01:00
# endif
2012-05-25 22:02:10 +01:00
2010-06-16 22:00:39 +00:00
// Now playing widget
2011-04-24 18:07:09 +00:00
qLog ( Debug ) < < " Creating now playing widget " ;
2010-06-16 22:00:39 +00:00
ui_ - > now_playing - > set_ideal_height ( ui_ - > status_bar - > sizeHint ( ) . height ( ) +
2011-03-07 20:21:34 +00:00
ui_ - > player_controls - > sizeHint ( ) . height ( ) ) ;
2012-02-12 13:41:50 +00:00
connect ( app_ - > player ( ) , SIGNAL ( Stopped ( ) ) , ui_ - > now_playing , SLOT ( Stopped ( ) ) ) ;
2010-06-18 00:06:59 +00:00
connect ( ui_ - > now_playing , SIGNAL ( ShowAboveStatusBarChanged ( bool ) ) ,
SLOT ( NowPlayingWidgetPositionChanged ( bool ) ) ) ;
Fixes issu...
,'``.._ ,'``.
:,--._:)\,:,._,.: All Glory to
:`--,'' :`...';\ the HYPNO TOAD!
`,' `---' `.
/ :
/ \
,' :\.___,-.
`...,---'``````-..._ |: \
( ) ;: ) \ _,-.
`. ( // `' \
: `.// ) ) , ;
,-|`. _,'/ ) ) ,' ,'
( :`.`-..____..=:.-': . _,' ,'
`,'\ ``--....-)=' `._, \ ,') _ '``._
_.-/ _ `. (_) / )' ; / \ \`-.'
`--( `-:`. `' ___..' _,-' |/ `.)
`-. `.`.``-----``--, .'
|/`.\`' ,','); SSt
` (/ (/
2010-07-12 19:51:23 +00:00
connect ( ui_ - > action_hypnotoad , SIGNAL ( toggled ( bool ) ) , ui_ - > now_playing , SLOT ( AllHail ( bool ) ) ) ;
2010-12-10 14:26:29 +00:00
connect ( ui_ - > action_kittens , SIGNAL ( toggled ( bool ) ) , ui_ - > now_playing , SLOT ( EnableKittens ( bool ) ) ) ;
2010-06-18 00:06:59 +00:00
NowPlayingWidgetPositionChanged ( ui_ - > now_playing - > show_above_status_bar ( ) ) ;
2010-06-16 22:00:39 +00:00
2009-12-24 19:16:07 +00:00
// Load theme
2012-01-14 16:27:49 +01:00
// This is tricky: we need to save the default/system palette now, before
// loading user preferred theme (which will overide it), to be able to restore it later
const_cast < QPalette & > ( Appearance : : kDefaultPalette ) = QApplication : : palette ( ) ;
2012-02-12 13:41:50 +00:00
app_ - > appearance ( ) - > LoadUserTheme ( ) ;
2010-02-27 16:36:25 +00:00
StyleSheetLoader * css_loader = new StyleSheetLoader ( this ) ;
css_loader - > SetStyleSheet ( this , " :mainwindow.css " ) ;
2009-12-24 19:16:07 +00:00
2010-05-20 21:21:55 +00:00
// Load playlists
2012-02-12 13:41:50 +00:00
app_ - > playlist_manager ( ) - > Init ( app_ - > library_backend ( ) , app_ - > playlist_backend ( ) ,
ui_ - > playlist_sequence , ui_ - > playlist ) ;
2010-05-20 21:21:55 +00:00
2011-03-17 08:21:05 +00:00
// We need to connect these global shortcuts here after the playlist have been initialized
2012-02-12 13:41:50 +00:00
connect ( global_shortcuts_ , SIGNAL ( CycleShuffleMode ( ) ) , app_ - > playlist_manager ( ) - > sequence ( ) , SLOT ( CycleShuffleMode ( ) ) ) ;
connect ( global_shortcuts_ , SIGNAL ( CycleRepeatMode ( ) ) , app_ - > playlist_manager ( ) - > sequence ( ) , SLOT ( CycleRepeatMode ( ) ) ) ;
connect ( app_ - > playlist_manager ( ) - > sequence ( ) , SIGNAL ( RepeatModeChanged ( PlaylistSequence : : RepeatMode ) ) , osd_ , SLOT ( RepeatModeChanged ( PlaylistSequence : : RepeatMode ) ) ) ;
connect ( app_ - > playlist_manager ( ) - > sequence ( ) , SIGNAL ( ShuffleModeChanged ( PlaylistSequence : : ShuffleMode ) ) , osd_ , SLOT ( ShuffleModeChanged ( PlaylistSequence : : ShuffleMode ) ) ) ;
2011-03-17 08:21:05 +00:00
2011-04-07 16:25:52 +00:00
# ifdef HAVE_LIBLASTFM
2012-06-25 12:30:53 +02:00
connect ( InternetModel : : Service < LastFMService > ( ) , SIGNAL ( ScrobbleSubmitted ( ) ) , SLOT ( ScrobbleSubmitted ( ) ) ) ;
connect ( InternetModel : : Service < LastFMService > ( ) , SIGNAL ( ScrobbleError ( int ) ) , SLOT ( ScrobbleError ( int ) ) ) ;
2011-04-07 16:25:52 +00:00
2012-02-12 13:41:50 +00:00
LastFMButtonVisibilityChanged ( app_ - > internet_model ( ) - > InternetModel : : Service < LastFMService > ( ) - > AreButtonsVisible ( ) ) ;
ScrobbleButtonVisibilityChanged ( app_ - > internet_model ( ) - > InternetModel : : Service < LastFMService > ( ) - > IsScrobbleButtonVisible ( ) ) ;
ScrobblingEnabledChanged ( app_ - > internet_model ( ) - > InternetModel : : Service < LastFMService > ( ) - > IsScrobblingEnabled ( ) ) ;
2011-04-07 16:25:52 +00:00
# else
LastFMButtonVisibilityChanged ( false ) ;
ScrobbleButtonVisibilityChanged ( false ) ;
# endif
2009-12-24 20:27:32 +00:00
// Load settings
2011-04-24 18:07:09 +00:00
qLog ( Debug ) < < " Loading settings " ;
2010-02-27 16:52:18 +00:00
settings_ . beginGroup ( kSettingsGroup ) ;
2009-12-24 19:16:07 +00:00
2010-02-27 16:52:18 +00:00
restoreGeometry ( settings_ . value ( " geometry " ) . toByteArray ( ) ) ;
2010-06-12 19:32:17 +00:00
if ( ! ui_ - > splitter - > restoreState ( settings_ . value ( " splitter_state " ) . toByteArray ( ) ) ) {
2010-12-19 14:29:25 +00:00
ui_ - > splitter - > setSizes ( QList < int > ( ) < < 300 < < width ( ) - 300 ) ;
2009-12-24 19:16:07 +00:00
}
2010-10-09 18:18:06 +00:00
ui_ - > tabs - > SetCurrentIndex ( settings_ . value ( " current_tab " , 0 ) . toInt ( ) ) ;
2011-03-18 15:09:30 +00:00
FancyTabWidget : : Mode default_mode = FancyTabWidget : : Mode_LargeSidebar ;
2010-10-09 18:18:06 +00:00
ui_ - > tabs - > SetMode ( FancyTabWidget : : Mode ( settings_ . value (
2011-01-29 21:28:11 +00:00
" tab_mode " , default_mode ) . toInt ( ) ) ) ;
2010-10-01 19:27:01 +00:00
file_view_ - > SetPath ( settings_ . value ( " file_path " , QDir : : homePath ( ) ) . toString ( ) ) ;
2009-12-24 20:27:32 +00:00
2010-05-15 17:45:04 +00:00
ReloadSettings ( ) ;
2011-05-28 08:50:29 +00:00
// Reload pretty OSD to avoid issues with fonts
osd_ - > ReloadPrettyOSDSettings ( ) ;
2011-06-08 14:48:43 +00:00
// Reload playlist settings, for BG and glowing
ui_ - > playlist - > view ( ) - > ReloadSettings ( ) ;
2010-04-14 21:27:27 +00:00
# ifndef Q_OS_DARWIN
2010-04-06 23:46:34 +00:00
StartupBehaviour behaviour =
StartupBehaviour ( settings_ . value ( " startupbehaviour " , Startup_Remember ) . toInt ( ) ) ;
2010-03-31 03:07:11 +00:00
bool hidden = settings_ . value ( " hidden " , false ) . toBool ( ) ;
2010-04-06 23:46:34 +00:00
switch ( behaviour ) {
case Startup_AlwaysHide : hide ( ) ; break ;
case Startup_AlwaysShow : show ( ) ; break ;
case Startup_Remember : setVisible ( ! hidden ) ; break ;
}
2010-02-26 18:22:44 +00:00
// Force the window to show in case somehow the config has tray and window set to hide
2010-06-22 11:52:55 +00:00
if ( hidden & & ! tray_icon_ - > IsVisible ( ) ) {
2010-02-27 16:52:18 +00:00
settings_ . setValue ( " hidden " , false ) ;
2010-02-26 18:22:44 +00:00
show ( ) ;
}
2010-04-14 21:58:51 +00:00
# else // Q_OS_DARWIN
2010-04-14 19:38:09 +00:00
// Always show mainwindow on startup on OS X.
show ( ) ;
# endif
2009-12-24 19:16:07 +00:00
2010-04-14 21:27:27 +00:00
QShortcut * close_window_shortcut = new QShortcut ( this ) ;
close_window_shortcut - > setKey ( Qt : : CTRL + Qt : : Key_W ) ;
2010-06-17 17:08:56 +00:00
connect ( close_window_shortcut , SIGNAL ( activated ( ) ) , SLOT ( SetHiddenInTray ( ) ) ) ;
2010-04-14 21:27:27 +00:00
2011-03-12 21:19:32 +00:00
# ifdef HAVE_WIIMOTEDEV
2010-09-01 15:37:09 +00:00
// http://code.google.com/p/clementine-player/issues/detail?id=670
// Switched position, mayby something is not ready ?
2012-02-12 13:41:50 +00:00
wiimotedev_shortcuts_ . reset ( new WiimotedevShortcuts ( osd_ , this , app_ - > player ( ) ) ) ;
2010-09-01 15:37:09 +00:00
# endif
2011-02-25 20:10:41 +00:00
CheckFullRescanRevisions ( ) ;
2011-04-24 18:07:09 +00:00
qLog ( Debug ) < < " Started " ;
2009-12-24 19:16:07 +00:00
}
MainWindow : : ~ MainWindow ( ) {
SaveGeometry ( ) ;
2010-05-10 21:50:31 +00:00
delete ui_ ;
2009-12-24 19:16:07 +00:00
}
2010-04-06 23:46:34 +00:00
void MainWindow : : ReloadSettings ( ) {
2010-04-14 19:38:09 +00:00
# ifndef Q_OS_DARWIN
2010-04-06 23:46:34 +00:00
bool show_tray = settings_ . value ( " showtray " , true ) . toBool ( ) ;
2010-02-26 18:22:44 +00:00
2010-06-22 11:52:55 +00:00
tray_icon_ - > SetVisible ( show_tray ) ;
2010-04-06 23:46:34 +00:00
if ( ! show_tray & & ! isVisible ( ) )
show ( ) ;
2010-04-14 19:38:09 +00:00
# endif
2010-05-15 17:45:04 +00:00
2011-01-24 21:16:26 +00:00
QSettings s ;
s . beginGroup ( kSettingsGroup ) ;
doubleclick_addmode_ = AddBehaviour (
s . value ( " doubleclick_addmode " , AddBehaviour_Append ) . toInt ( ) ) ;
doubleclick_playmode_ = PlayBehaviour (
s . value ( " doubleclick_playmode " , PlayBehaviour_IfStopped ) . toInt ( ) ) ;
menu_playmode_ = PlayBehaviour (
s . value ( " menu_playmode " , PlayBehaviour_IfStopped ) . toInt ( ) ) ;
2011-06-08 14:48:43 +00:00
2010-05-15 17:45:04 +00:00
}
2011-01-02 14:50:17 +00:00
void MainWindow : : ReloadAllSettings ( ) {
ReloadSettings ( ) ;
// Other settings
2012-03-09 12:15:24 +00:00
app_ - > ReloadSettings ( ) ;
2012-02-12 13:41:50 +00:00
app_ - > global_search ( ) - > ReloadSettings ( ) ;
app_ - > library ( ) - > ReloadSettings ( ) ;
app_ - > player ( ) - > ReloadSettings ( ) ;
2011-01-02 14:50:17 +00:00
osd_ - > ReloadSettings ( ) ;
2011-11-05 19:09:02 +00:00
library_view_ - > ReloadSettings ( ) ;
2011-01-02 14:50:17 +00:00
song_info_view_ - > ReloadSettings ( ) ;
2012-02-12 13:41:50 +00:00
app_ - > player ( ) - > engine ( ) - > ReloadSettings ( ) ;
2011-01-02 14:50:17 +00:00
ui_ - > playlist - > view ( ) - > ReloadSettings ( ) ;
2012-02-12 13:41:50 +00:00
app_ - > internet_model ( ) - > ReloadSettings ( ) ;
2011-03-12 21:19:32 +00:00
# ifdef HAVE_WIIMOTEDEV
2011-01-02 14:50:17 +00:00
wiimotedev_shortcuts_ - > ReloadSettings ( ) ;
# endif
}
2011-06-08 14:48:43 +00:00
void MainWindow : : RefreshStyleSheet ( ) {
setStyleSheet ( styleSheet ( ) ) ;
}
2009-12-24 19:16:07 +00:00
void MainWindow : : MediaStopped ( ) {
2010-11-23 19:38:15 +00:00
setWindowTitle ( QCoreApplication : : applicationName ( ) ) ;
2010-05-10 21:50:31 +00:00
ui_ - > action_stop - > setEnabled ( false ) ;
ui_ - > action_stop_after_this_track - > setEnabled ( false ) ;
2010-05-19 15:45:29 +00:00
ui_ - > action_play_pause - > setIcon ( IconLoader : : Load ( " media-playback-start " ) ) ;
2010-05-10 21:50:31 +00:00
ui_ - > action_play_pause - > setText ( tr ( " Play " ) ) ;
2009-12-29 16:15:21 +00:00
2010-05-10 21:50:31 +00:00
ui_ - > action_play_pause - > setEnabled ( true ) ;
2009-12-29 19:22:02 +00:00
2010-05-10 21:50:31 +00:00
ui_ - > action_ban - > setEnabled ( false ) ;
ui_ - > action_love - > setEnabled ( false ) ;
2011-04-21 22:19:28 +00:00
tray_icon_ - > LastFMButtonLoveStateChanged ( false ) ;
tray_icon_ - > LastFMButtonBanStateChanged ( false ) ;
2009-12-29 19:57:33 +00:00
track_position_timer_ - > stop ( ) ;
2010-06-16 19:21:15 +00:00
ui_ - > track_slider - > SetStopped ( ) ;
2010-01-17 21:11:03 +00:00
tray_icon_ - > SetProgress ( 0 ) ;
2010-04-19 13:53:26 +00:00
tray_icon_ - > SetStopped ( ) ;
2009-12-24 19:16:07 +00:00
}
void MainWindow : : MediaPaused ( ) {
2010-05-10 21:50:31 +00:00
ui_ - > action_stop - > setEnabled ( true ) ;
ui_ - > action_stop_after_this_track - > setEnabled ( true ) ;
2010-05-19 15:45:29 +00:00
ui_ - > action_play_pause - > setIcon ( IconLoader : : Load ( " media-playback-start " ) ) ;
2010-05-10 21:50:31 +00:00
ui_ - > action_play_pause - > setText ( tr ( " Play " ) ) ;
2009-12-29 16:15:21 +00:00
2010-05-10 21:50:31 +00:00
ui_ - > action_play_pause - > setEnabled ( true ) ;
2009-12-29 19:57:33 +00:00
track_position_timer_ - > stop ( ) ;
2010-04-19 13:53:26 +00:00
tray_icon_ - > SetPaused ( ) ;
2009-12-24 19:16:07 +00:00
}
void MainWindow : : MediaPlaying ( ) {
2010-05-10 21:50:31 +00:00
ui_ - > action_stop - > setEnabled ( true ) ;
ui_ - > action_stop_after_this_track - > setEnabled ( true ) ;
2010-05-19 15:45:29 +00:00
ui_ - > action_play_pause - > setIcon ( IconLoader : : Load ( " media-playback-pause " ) ) ;
2010-05-10 21:50:31 +00:00
ui_ - > action_play_pause - > setText ( tr ( " Pause " ) ) ;
2009-12-29 16:15:21 +00:00
2012-02-12 13:41:50 +00:00
bool enable_play_pause = ! ( app_ - > player ( ) - > GetCurrentItem ( ) - > options ( ) & PlaylistItem : : PauseDisabled ) ;
2011-03-07 21:33:01 +00:00
ui_ - > action_play_pause - > setEnabled ( enable_play_pause ) ;
2009-12-29 19:22:02 +00:00
2012-02-12 13:41:50 +00:00
bool can_seek = ! ( app_ - > player ( ) - > GetCurrentItem ( ) - > options ( ) & PlaylistItem : : SeekDisabled ) ;
2011-11-28 18:19:11 +00:00
ui_ - > track_slider - > SetCanSeek ( can_seek ) ;
2010-12-18 17:28:02 +00:00
# ifdef HAVE_LIBLASTFM
2012-02-12 13:41:50 +00:00
bool is_lastfm = ( app_ - > player ( ) - > GetCurrentItem ( ) - > options ( ) & PlaylistItem : : LastFMControls ) ;
2011-07-15 13:27:50 +00:00
LastFMService * lastfm = InternetModel : : Service < LastFMService > ( ) ;
2011-03-07 21:33:01 +00:00
bool enable_ban = lastfm - > IsScrobblingEnabled ( ) & & is_lastfm ;
bool enable_love = lastfm - > IsScrobblingEnabled ( ) ;
2009-12-29 20:48:50 +00:00
2011-03-07 21:33:01 +00:00
ui_ - > action_ban - > setEnabled ( enable_ban ) ;
ui_ - > action_love - > setEnabled ( enable_love ) ;
2011-04-21 22:19:28 +00:00
tray_icon_ - > LastFMButtonBanStateChanged ( enable_ban ) ;
tray_icon_ - > LastFMButtonLoveStateChanged ( enable_love ) ;
2011-03-07 21:33:01 +00:00
tray_icon_ - > SetPlaying ( enable_play_pause , enable_ban , enable_love ) ;
2010-12-18 17:28:02 +00:00
# else
2011-03-07 21:33:01 +00:00
tray_icon_ - > SetPlaying ( enable_play_pause ) ;
2010-12-18 17:28:02 +00:00
# endif
2010-01-15 17:12:47 +00:00
2009-12-29 19:57:33 +00:00
track_position_timer_ - > start ( ) ;
UpdateTrackPosition ( ) ;
2009-12-24 19:16:07 +00:00
}
2010-11-21 21:36:27 +00:00
void MainWindow : : VolumeChanged ( int volume ) {
ui_ - > action_mute - > setChecked ( ! volume ) ;
2011-06-22 21:50:25 +00:00
tray_icon_ - > MuteButtonStateChanged ( ! volume ) ;
2010-11-21 21:36:27 +00:00
}
2010-11-23 19:38:15 +00:00
void MainWindow : : SongChanged ( const Song & song ) {
setWindowTitle ( song . PrettyTitleWithArtist ( ) ) ;
2011-04-07 16:25:52 +00:00
# ifdef HAVE_LIBLASTFM
if ( ui_ - > action_toggle_scrobbling - > isVisible ( ) )
2011-07-15 13:27:50 +00:00
SetToggleScrobblingIcon ( InternetModel : : Service < LastFMService > ( ) - > IsScrobblingEnabled ( ) ) ;
2011-04-07 16:25:52 +00:00
# endif
2010-11-23 19:38:15 +00:00
}
2010-10-17 19:27:31 +00:00
void MainWindow : : TrackSkipped ( PlaylistItemPtr item ) {
// If it was a library item then we have to increment its skipped count in
// the database.
2011-04-28 10:32:56 +00:00
if ( item & & item - > IsLocalLibraryItem ( ) & & item - > Metadata ( ) . id ( ) ! = - 1 & &
2012-02-12 13:41:50 +00:00
app_ - > playlist_manager ( ) - > active ( ) - > get_lastfm_status ( ) ! = Playlist : : LastFM_Scrobbled & &
app_ - > playlist_manager ( ) - > active ( ) - > get_lastfm_status ( ) ! = Playlist : : LastFM_Queued ) {
2010-11-01 21:15:52 +00:00
Song song = item - > Metadata ( ) ;
2012-02-12 13:41:50 +00:00
const qint64 position = app_ - > player ( ) - > engine ( ) - > position_nanosec ( ) ;
const qint64 length = app_ - > player ( ) - > engine ( ) - > length_nanosec ( ) ;
2010-11-01 21:15:52 +00:00
const float percentage = ( length = = 0 ? 1 : float ( position ) / length ) ;
2012-02-12 13:41:50 +00:00
app_ - > library_backend ( ) - > IncrementSkipCountAsync ( song . id ( ) , percentage ) ;
2010-10-17 19:27:31 +00:00
}
}
2010-12-18 17:28:02 +00:00
# ifdef HAVE_LIBLASTFM
2009-12-29 20:48:50 +00:00
void MainWindow : : ScrobblingEnabledChanged ( bool value ) {
2011-04-07 16:25:52 +00:00
if ( ui_ - > action_toggle_scrobbling - > isVisible ( ) )
SetToggleScrobblingIcon ( value ) ;
2012-02-12 13:41:50 +00:00
if ( ! app_ - > player ( ) - > GetState ( ) = = Engine : : Idle ) {
2009-12-30 04:14:29 +00:00
return ;
2011-04-07 16:25:52 +00:00
}
else {
//invalidate current song, we will scrobble the next one
2012-02-12 13:41:50 +00:00
if ( app_ - > playlist_manager ( ) - > active ( ) - > get_lastfm_status ( ) = = Playlist : : LastFM_New )
app_ - > playlist_manager ( ) - > active ( ) - > set_lastfm_status ( Playlist : : LastFM_Seeked ) ;
2011-04-07 16:25:52 +00:00
}
2009-12-30 04:14:29 +00:00
2012-02-12 13:41:50 +00:00
bool is_lastfm = ( app_ - > player ( ) - > GetCurrentItem ( ) - > options ( ) & PlaylistItem : : LastFMControls ) ;
2010-05-10 21:50:31 +00:00
ui_ - > action_ban - > setEnabled ( value & & is_lastfm ) ;
2011-04-21 22:19:28 +00:00
tray_icon_ - > LastFMButtonBanStateChanged ( value & & is_lastfm ) ;
2010-05-10 21:50:31 +00:00
ui_ - > action_love - > setEnabled ( value ) ;
2011-04-21 22:19:28 +00:00
tray_icon_ - > LastFMButtonLoveStateChanged ( value ) ;
2009-12-29 20:48:50 +00:00
}
2010-12-18 17:28:02 +00:00
# endif
2009-12-29 20:48:50 +00:00
2010-04-07 19:26:49 +00:00
void MainWindow : : LastFMButtonVisibilityChanged ( bool value ) {
2010-05-10 21:50:31 +00:00
ui_ - > action_ban - > setVisible ( value ) ;
ui_ - > action_love - > setVisible ( value ) ;
ui_ - > last_fm_controls - > setVisible ( value ) ;
2011-04-21 22:19:28 +00:00
tray_icon_ - > LastFMButtonVisibilityChanged ( value ) ;
2010-04-07 19:26:49 +00:00
}
2011-04-07 16:25:52 +00:00
void MainWindow : : ScrobbleButtonVisibilityChanged ( bool value ) {
ui_ - > action_toggle_scrobbling - > setVisible ( value ) ;
ui_ - > scrobbling_button - > setVisible ( value ) ;
//when you reshow the buttons
if ( value ) {
//check if the song was scrobbled
2012-02-12 13:41:50 +00:00
if ( app_ - > playlist_manager ( ) - > active ( ) - > get_lastfm_status ( ) = = Playlist : : LastFM_Scrobbled ) {
2011-04-07 16:25:52 +00:00
ui_ - > action_toggle_scrobbling - > setIcon ( QIcon ( " :/last.fm/as.png " ) ) ;
} else {
# ifdef HAVE_LIBLASTFM
2012-02-12 13:41:50 +00:00
SetToggleScrobblingIcon ( app_ - > internet_model ( ) - > InternetModel : : Service < LastFMService > ( ) - > IsScrobblingEnabled ( ) ) ;
2011-04-07 16:25:52 +00:00
# endif
}
}
}
2009-12-24 19:16:07 +00:00
void MainWindow : : resizeEvent ( QResizeEvent * ) {
SaveGeometry ( ) ;
}
void MainWindow : : SaveGeometry ( ) {
2010-02-27 16:52:18 +00:00
settings_ . setValue ( " geometry " , saveGeometry ( ) ) ;
2010-06-12 19:32:17 +00:00
settings_ . setValue ( " splitter_state " , ui_ - > splitter - > saveState ( ) ) ;
2010-10-09 18:18:06 +00:00
settings_ . setValue ( " current_tab " , ui_ - > tabs - > current_index ( ) ) ;
settings_ . setValue ( " tab_mode " , ui_ - > tabs - > mode ( ) ) ;
2009-12-24 19:16:07 +00:00
}
void MainWindow : : PlayIndex ( const QModelIndex & index ) {
if ( ! index . isValid ( ) )
return ;
2010-05-25 19:39:04 +00:00
int row = index . row ( ) ;
2012-02-12 13:41:50 +00:00
if ( index . model ( ) = = app_ - > playlist_manager ( ) - > current ( ) - > proxy ( ) ) {
2010-05-25 19:39:04 +00:00
// The index was in the proxy model (might've been filtered), so we need
// to get the actual row in the source model.
2012-02-12 13:41:50 +00:00
row = app_ - > playlist_manager ( ) - > current ( ) - > proxy ( ) - > mapToSource ( index ) . row ( ) ;
2010-05-25 19:39:04 +00:00
}
2012-02-12 13:41:50 +00:00
app_ - > playlist_manager ( ) - > SetActiveToCurrent ( ) ;
app_ - > player ( ) - > PlayAt ( row , Engine : : Manual , true ) ;
2009-12-24 19:16:07 +00:00
}
void MainWindow : : VolumeWheelEvent ( int delta ) {
2010-05-10 21:50:31 +00:00
ui_ - > volume - > setValue ( ui_ - > volume - > value ( ) + delta / 30 ) ;
2009-12-24 19:16:07 +00:00
}
2010-06-22 11:52:55 +00:00
void MainWindow : : ToggleShowHide ( ) {
if ( settings_ . value ( " hidden " ) . toBool ( ) ) {
show ( ) ;
SetHiddenInTray ( false ) ;
} else if ( isActiveWindow ( ) ) {
hide ( ) ;
setWindowState ( ( windowState ( ) & ~ Qt : : WindowMinimized ) | Qt : : WindowActive ) ;
SetHiddenInTray ( true ) ;
} else if ( isMinimized ( ) ) {
hide ( ) ;
setWindowState ( ( windowState ( ) & ~ Qt : : WindowMinimized ) | Qt : : WindowActive ) ;
SetHiddenInTray ( false ) ;
2010-09-02 13:41:25 +00:00
} else if ( ! isVisible ( ) )
{
show ( ) ;
activateWindow ( ) ;
2010-06-22 11:52:55 +00:00
} else {
// Window is not hidden but does not have focus; bring it to front.
activateWindow ( ) ;
raise ( ) ;
2009-12-24 19:16:07 +00:00
}
}
void MainWindow : : StopAfterCurrent ( ) {
2012-02-12 13:41:50 +00:00
app_ - > playlist_manager ( ) - > current ( ) - > StopAfter ( app_ - > playlist_manager ( ) - > current ( ) - > current_row ( ) ) ;
2009-12-24 19:16:07 +00:00
}
void MainWindow : : closeEvent ( QCloseEvent * event ) {
2010-12-04 17:31:50 +00:00
QSettings s ;
s . beginGroup ( kSettingsGroup ) ;
bool keep_running = s . value ( " keeprunning " , tray_icon_ - > IsVisible ( ) ) . toBool ( ) ;
if ( keep_running & & event - > spontaneous ( ) ) {
2010-02-26 18:22:44 +00:00
event - > ignore ( ) ;
SetHiddenInTray ( true ) ;
2010-04-07 16:26:04 +00:00
} else {
QApplication : : quit ( ) ;
2010-02-26 18:22:44 +00:00
}
2009-12-24 19:16:07 +00:00
}
void MainWindow : : SetHiddenInTray ( bool hidden ) {
2010-02-27 16:52:18 +00:00
settings_ . setValue ( " hidden " , hidden ) ;
2010-04-19 14:10:31 +00:00
2010-04-19 14:23:57 +00:00
// Some window managers don't remember maximized state between calls to
// hide() and show(), so we have to remember it ourself.
2010-04-19 14:10:31 +00:00
if ( hidden ) {
was_maximized_ = isMaximized ( ) ;
hide ( ) ;
} else {
if ( was_maximized_ )
showMaximized ( ) ;
else
show ( ) ;
}
2009-12-24 19:16:07 +00:00
}
2009-12-24 20:27:32 +00:00
void MainWindow : : FilePathChanged ( const QString & path ) {
2010-02-27 16:52:18 +00:00
settings_ . setValue ( " file_path " , path ) ;
2009-12-24 20:27:32 +00:00
}
2009-12-29 19:57:33 +00:00
2011-03-21 15:15:17 +00:00
void MainWindow : : Seeked ( qlonglong microseconds ) {
const int position = microseconds / kUsecPerSec ;
2012-02-12 13:41:50 +00:00
const int length = app_ - > player ( ) - > GetCurrentItem ( ) - > Metadata ( ) . length_nanosec ( ) / kNsecPerSec ;
2011-03-21 15:15:17 +00:00
tray_icon_ - > SetProgress ( double ( position ) / length * 100 ) ;
2011-04-07 16:25:52 +00:00
//if we seeked, scrobbling is canceled, update the icon
if ( ui_ - > action_toggle_scrobbling - > isVisible ( ) )
SetToggleScrobblingIcon ( true ) ;
2011-03-21 15:15:17 +00:00
}
2009-12-29 19:57:33 +00:00
void MainWindow : : UpdateTrackPosition ( ) {
2010-01-17 21:11:03 +00:00
// Track position in seconds
2012-02-12 13:41:50 +00:00
Playlist * playlist = app_ - > playlist_manager ( ) - > active ( ) ;
2011-04-17 14:11:37 +00:00
2012-02-12 13:41:50 +00:00
PlaylistItemPtr item ( app_ - > player ( ) - > GetCurrentItem ( ) ) ;
2011-02-13 18:29:27 +00:00
const int position = std : : floor (
2012-02-12 13:41:50 +00:00
float ( app_ - > player ( ) - > engine ( ) - > position_nanosec ( ) ) / kNsecPerSec + 0.5 ) ;
2011-02-14 19:34:37 +00:00
const int length = item - > Metadata ( ) . length_nanosec ( ) / kNsecPerSec ;
2011-04-17 14:11:37 +00:00
const int scrobble_point = playlist - > scrobble_point_nanosec ( ) / kNsecPerSec ;
2009-12-29 19:57:33 +00:00
2010-01-18 02:49:07 +00:00
if ( length < = 0 ) {
// Probably a stream that we don't know the length of
2010-06-16 19:21:15 +00:00
ui_ - > track_slider - > SetStopped ( ) ;
2010-01-18 02:49:07 +00:00
tray_icon_ - > SetProgress ( 0 ) ;
return ;
}
2011-04-07 16:25:52 +00:00
# ifdef HAVE_LIBLASTFM
2011-07-15 13:27:50 +00:00
LastFMService * lastfm_service = InternetModel : : Service < LastFMService > ( ) ;
2011-04-17 14:11:37 +00:00
const bool last_fm_enabled = ui_ - > action_toggle_scrobbling - > isVisible ( ) & &
lastfm_service - > IsScrobblingEnabled ( ) & &
lastfm_service - > IsAuthenticated ( ) ;
2011-04-07 16:25:52 +00:00
# endif
2010-01-18 02:49:07 +00:00
2010-01-17 21:11:03 +00:00
// Time to scrobble?
2011-04-17 14:11:37 +00:00
if ( position > = scrobble_point ) {
if ( playlist - > get_lastfm_status ( ) = = Playlist : : LastFM_New ) {
# ifdef HAVE_LIBLASTFM
2011-04-28 10:32:56 +00:00
if ( lastfm_service - > IsScrobblingEnabled ( ) & & lastfm_service - > IsAuthenticated ( ) ) {
2011-04-22 16:50:29 +00:00
qLog ( Info ) < < " Scrobbling at " < < scrobble_point ;
2011-04-17 14:11:37 +00:00
lastfm_service - > Scrobble ( ) ;
}
# endif
}
2011-04-16 23:17:48 +00:00
2010-10-17 19:27:31 +00:00
// Update the play count for the song if it's from the library
2011-04-17 14:11:37 +00:00
if ( ! playlist - > have_incremented_playcount ( ) & &
item - > IsLocalLibraryItem ( ) & & item - > Metadata ( ) . id ( ) ! = - 1 & &
playlist - > get_lastfm_status ( ) ! = Playlist : : LastFM_Seeked ) {
2012-02-12 13:41:50 +00:00
app_ - > library_backend ( ) - > IncrementPlayCountAsync ( item - > Metadata ( ) . id ( ) ) ;
2011-04-17 14:11:37 +00:00
playlist - > set_have_incremented_playcount ( ) ;
2010-10-17 19:27:31 +00:00
}
2009-12-29 19:57:33 +00:00
}
2010-01-15 17:12:47 +00:00
2010-01-17 21:11:03 +00:00
// Update the slider
2010-06-16 19:21:15 +00:00
ui_ - > track_slider - > SetValue ( position , length ) ;
2010-01-17 21:11:03 +00:00
// Update the tray icon every 10 seconds
2010-10-17 18:26:25 +00:00
if ( position % 10 = = 0 ) {
2011-04-22 16:50:29 +00:00
qLog ( Debug ) < < " position " < < position < < " scrobble point " < < scrobble_point
2011-04-17 14:11:37 +00:00
< < " status " < < playlist - > get_lastfm_status ( ) ;
2010-01-17 21:11:03 +00:00
tray_icon_ - > SetProgress ( double ( position ) / length * 100 ) ;
2011-04-07 16:25:52 +00:00
//if we're waiting for the scrobble point, update the icon
# ifdef HAVE_LIBLASTFM
2011-04-17 14:11:37 +00:00
if ( position < scrobble_point & &
playlist - > get_lastfm_status ( ) = = Playlist : : LastFM_New & &
last_fm_enabled ) {
2011-04-07 16:25:52 +00:00
ui_ - > action_toggle_scrobbling - > setIcon ( CreateOverlayedIcon ( position , scrobble_point ) ) ;
}
# endif
2010-01-17 21:11:03 +00:00
}
2009-12-29 19:57:33 +00:00
}
2009-12-29 20:48:50 +00:00
2010-12-18 17:28:02 +00:00
# ifdef HAVE_LIBLASTFM
2011-04-16 15:27:34 +00:00
void MainWindow : : ScrobbledRadioStream ( ) {
ui_ - > action_love - > setEnabled ( true ) ;
2011-04-21 22:19:28 +00:00
tray_icon_ - > LastFMButtonLoveStateChanged ( true ) ;
2011-04-16 15:27:34 +00:00
}
2009-12-29 20:48:50 +00:00
void MainWindow : : Love ( ) {
2011-07-15 13:27:50 +00:00
InternetModel : : Service < LastFMService > ( ) - > Love ( ) ;
2010-05-10 21:50:31 +00:00
ui_ - > action_love - > setEnabled ( false ) ;
2011-04-21 22:19:28 +00:00
tray_icon_ - > LastFMButtonLoveStateChanged ( false ) ;
2009-12-29 20:48:50 +00:00
}
2010-12-18 17:28:02 +00:00
# endif
2009-12-29 23:17:54 +00:00
2011-01-24 21:16:26 +00:00
void MainWindow : : ApplyAddBehaviour ( MainWindow : : AddBehaviour b , MimeData * data ) const {
switch ( b ) {
case AddBehaviour_Append :
data - > clear_first_ = false ;
data - > enqueue_now_ = false ;
break ;
case AddBehaviour_Enqueue :
data - > clear_first_ = false ;
data - > enqueue_now_ = true ;
break ;
case AddBehaviour_Load :
data - > clear_first_ = true ;
data - > enqueue_now_ = false ;
break ;
2011-02-09 17:51:59 +00:00
case AddBehaviour_OpenInNew :
2011-02-16 18:29:35 +00:00
data - > open_in_new_playlist_ = true ;
2011-02-09 17:51:59 +00:00
break ;
2011-01-24 21:16:26 +00:00
}
}
void MainWindow : : ApplyPlayBehaviour ( MainWindow : : PlayBehaviour b , MimeData * data ) const {
switch ( b ) {
case PlayBehaviour_Always :
data - > play_now_ = true ;
break ;
case PlayBehaviour_Never :
data - > play_now_ = false ;
break ;
case PlayBehaviour_IfStopped :
2012-02-12 13:41:50 +00:00
data - > play_now_ = ! ( app_ - > player ( ) - > GetState ( ) = = Engine : : Playing ) ;
2011-01-24 21:16:26 +00:00
break ;
}
}
2011-01-10 22:26:13 +00:00
void MainWindow : : AddToPlaylist ( QMimeData * data ) {
2010-05-15 17:45:04 +00:00
if ( ! data )
return ;
2011-01-10 22:26:13 +00:00
if ( MimeData * mime_data = qobject_cast < MimeData * > ( data ) ) {
// Should we replace the flags with the user's preference?
2011-09-18 23:26:21 +01:00
if ( mime_data - > override_user_settings_ ) {
// Do nothing
} else if ( mime_data - > from_doubleclick_ ) {
2011-01-24 21:16:26 +00:00
ApplyAddBehaviour ( doubleclick_addmode_ , mime_data ) ;
ApplyPlayBehaviour ( doubleclick_playmode_ , mime_data ) ;
} else {
ApplyPlayBehaviour ( menu_playmode_ , mime_data ) ;
2011-01-10 22:26:13 +00:00
}
2011-02-09 17:51:59 +00:00
// Should we create a new playlist for the songs?
2011-02-16 18:29:35 +00:00
if ( mime_data - > open_in_new_playlist_ ) {
2012-02-12 13:41:50 +00:00
app_ - > playlist_manager ( ) - > New ( mime_data - > get_name_for_new_playlist ( ) ) ;
2011-02-09 17:51:59 +00:00
}
2010-05-25 19:39:04 +00:00
}
2012-02-12 13:41:50 +00:00
app_ - > playlist_manager ( ) - > current ( ) - > dropMimeData ( data , Qt : : CopyAction , - 1 , 0 , QModelIndex ( ) ) ;
2011-01-10 22:26:13 +00:00
delete data ;
2010-05-09 18:36:10 +00:00
}
2011-03-20 17:38:15 +00:00
void MainWindow : : AddToPlaylist ( QAction * action ) {
int destination = action - > data ( ) . toInt ( ) ;
PlaylistItemList items ;
//get the selected playlist items
foreach ( const QModelIndex & index , ui_ - > playlist - > view ( ) - > selectionModel ( ) - > selection ( ) . indexes ( ) ) {
if ( index . column ( ) ! = 0 )
continue ;
2012-02-12 13:41:50 +00:00
int row = app_ - > playlist_manager ( ) - > current ( ) - > proxy ( ) - > mapToSource ( index ) . row ( ) ;
items < < app_ - > playlist_manager ( ) - > current ( ) - > item_at ( row ) ;
2011-03-20 17:38:15 +00:00
}
2011-03-25 19:16:12 +00:00
SongList songs ;
foreach ( PlaylistItemPtr item , items ) {
songs < < item - > Metadata ( ) ;
}
2011-03-20 17:38:15 +00:00
//we're creating a new playlist
if ( destination = = - 1 ) {
//save the current playlist to reactivate it
2012-02-12 13:41:50 +00:00
int current_id = app_ - > playlist_manager ( ) - > current_id ( ) ;
2011-03-25 19:16:12 +00:00
//get the name from selection
2012-02-12 13:41:50 +00:00
app_ - > playlist_manager ( ) - > New ( app_ - > playlist_manager ( ) - > GetNameForNewPlaylist ( songs ) ) ;
if ( app_ - > playlist_manager ( ) - > current ( ) - > id ( ) ! = current_id ) {
2011-03-20 17:38:15 +00:00
//I'm sure the new playlist was created and is selected, so I can just insert items
2012-02-12 13:41:50 +00:00
app_ - > playlist_manager ( ) - > current ( ) - > InsertItems ( items ) ;
2011-03-20 17:38:15 +00:00
//set back the current playlist
2012-02-12 13:41:50 +00:00
app_ - > playlist_manager ( ) - > SetCurrentPlaylist ( current_id ) ;
2011-03-20 17:38:15 +00:00
}
}
else {
//we're inserting in a existing playlist
2012-02-12 13:41:50 +00:00
app_ - > playlist_manager ( ) - > playlist ( destination ) - > InsertItems ( items ) ;
2011-03-20 17:38:15 +00:00
}
}
2010-01-15 16:22:19 +00:00
void MainWindow : : PlaylistRightClick ( const QPoint & global_pos , const QModelIndex & index ) {
2012-02-12 13:41:50 +00:00
QModelIndex source_index = app_ - > playlist_manager ( ) - > current ( ) - > proxy ( ) - > mapToSource ( index ) ;
2010-11-28 14:47:35 +00:00
playlist_menu_index_ = source_index ;
2010-06-24 23:36:39 +00:00
// Is this song currently playing?
2012-02-12 13:41:50 +00:00
if ( app_ - > playlist_manager ( ) - > current ( ) - > current_row ( ) = = source_index . row ( ) & & app_ - > player ( ) - > GetState ( ) = = Engine : : Playing ) {
2010-02-23 18:33:09 +00:00
playlist_play_pause_ - > setText ( tr ( " Pause " ) ) ;
2010-05-19 15:45:29 +00:00
playlist_play_pause_ - > setIcon ( IconLoader : : Load ( " media-playback-pause " ) ) ;
2010-01-15 16:22:19 +00:00
} else {
2010-02-23 18:33:09 +00:00
playlist_play_pause_ - > setText ( tr ( " Play " ) ) ;
2010-05-19 15:45:29 +00:00
playlist_play_pause_ - > setIcon ( IconLoader : : Load ( " media-playback-start " ) ) ;
2010-01-15 16:22:19 +00:00
}
2010-06-24 23:36:39 +00:00
// Are we allowed to pause?
2010-01-17 15:48:31 +00:00
if ( index . isValid ( ) ) {
playlist_play_pause_ - > setEnabled (
2012-02-12 13:41:50 +00:00
app_ - > playlist_manager ( ) - > current ( ) - > current_row ( ) ! = source_index . row ( ) | |
! ( app_ - > playlist_manager ( ) - > current ( ) - > item_at ( source_index . row ( ) ) - > options ( ) & PlaylistItem : : PauseDisabled ) ) ;
2010-01-17 15:48:31 +00:00
} else {
playlist_play_pause_ - > setEnabled ( false ) ;
}
2010-01-15 16:22:19 +00:00
playlist_stop_after_ - > setEnabled ( index . isValid ( ) ) ;
2010-07-11 21:52:00 +00:00
// Are any of the selected songs editable or queued?
2010-05-20 14:12:15 +00:00
QModelIndexList selection = ui_ - > playlist - > view ( ) - > selectionModel ( ) - > selection ( ) . indexes ( ) ;
2011-02-21 18:18:16 +00:00
bool cue_selected = false ;
2010-03-24 00:12:52 +00:00
int editable = 0 ;
2011-03-20 12:43:10 +00:00
int streams = 0 ;
2010-07-11 21:52:00 +00:00
int in_queue = 0 ;
int not_in_queue = 0 ;
2010-03-24 16:36:44 +00:00
foreach ( const QModelIndex & index , selection ) {
2010-01-16 16:12:47 +00:00
if ( index . column ( ) ! = 0 )
continue ;
2011-02-21 18:18:16 +00:00
2012-02-12 13:41:50 +00:00
PlaylistItemPtr item = app_ - > playlist_manager ( ) - > current ( ) - > item_at ( index . row ( ) ) ;
2011-03-20 12:43:10 +00:00
if ( item - > Metadata ( ) . has_cue ( ) ) {
2011-02-21 18:18:16 +00:00
cue_selected = true ;
2011-03-20 12:43:10 +00:00
} else if ( item - > Metadata ( ) . IsEditable ( ) ) {
2010-03-24 00:12:52 +00:00
editable + + ;
2010-01-16 16:12:47 +00:00
}
2010-07-11 21:52:00 +00:00
2011-03-20 12:43:10 +00:00
if ( item - > Metadata ( ) . is_stream ( ) ) {
streams + + ;
}
2010-07-11 21:52:00 +00:00
if ( index . data ( Playlist : : Role_QueuePosition ) . toInt ( ) = = - 1 )
not_in_queue + + ;
else
in_queue + + ;
2010-01-16 16:12:47 +00:00
}
2011-02-21 18:18:16 +00:00
2011-03-20 12:43:10 +00:00
int all = not_in_queue + in_queue ;
2011-02-21 18:18:16 +00:00
// this is available when we have one or many files and at least one of
// those is not CUE related
2010-05-10 21:50:31 +00:00
ui_ - > action_edit_track - > setEnabled ( editable ) ;
2011-02-21 18:18:16 +00:00
ui_ - > action_edit_track - > setVisible ( editable ) ;
2011-03-06 14:07:41 +00:00
ui_ - > action_auto_complete_tags - > setEnabled ( editable ) ;
ui_ - > action_auto_complete_tags - > setVisible ( editable ) ;
2011-02-21 18:18:16 +00:00
// the rest of the read / write actions work only when there are no CUEs
// involved
if ( cue_selected )
editable = 0 ;
2010-03-31 19:09:35 +00:00
2011-03-20 12:43:10 +00:00
// no 'show in browser' action if only streams are selected
playlist_open_in_browser_ - > setVisible ( streams ! = all ) ;
2010-03-31 19:09:35 +00:00
bool track_column = ( index . column ( ) = = Playlist : : Column_Track ) ;
2010-05-10 21:50:31 +00:00
ui_ - > action_renumber_tracks - > setVisible ( editable > = 2 & & track_column ) ;
ui_ - > action_selection_set_value - > setVisible ( editable > = 2 & & ! track_column ) ;
ui_ - > action_edit_value - > setVisible ( editable ) ;
ui_ - > action_remove_from_playlist - > setEnabled ( ! selection . isEmpty ( ) ) ;
2010-03-24 00:12:52 +00:00
2010-06-24 23:36:39 +00:00
playlist_copy_to_library_ - > setVisible ( false ) ;
playlist_move_to_library_ - > setVisible ( false ) ;
playlist_organise_ - > setVisible ( false ) ;
playlist_delete_ - > setVisible ( false ) ;
2010-12-11 10:54:42 +00:00
playlist_copy_to_device_ - > setVisible ( false ) ;
2010-06-24 23:36:39 +00:00
2010-07-11 21:52:00 +00:00
if ( in_queue = = 1 & & not_in_queue = = 0 )
playlist_queue_ - > setText ( tr ( " Dequeue track " ) ) ;
else if ( in_queue > 1 & & not_in_queue = = 0 )
playlist_queue_ - > setText ( tr ( " Dequeue selected tracks " ) ) ;
else if ( in_queue = = 0 & & not_in_queue = = 1 )
playlist_queue_ - > setText ( tr ( " Queue track " ) ) ;
else if ( in_queue = = 0 & & not_in_queue > 1 )
playlist_queue_ - > setText ( tr ( " Queue selected tracks " ) ) ;
else
playlist_queue_ - > setText ( tr ( " Toggle queue status " ) ) ;
if ( not_in_queue = = 0 )
playlist_queue_ - > setIcon ( IconLoader : : Load ( " go-previous " ) ) ;
else
playlist_queue_ - > setIcon ( IconLoader : : Load ( " go-next " ) ) ;
2010-03-24 16:13:05 +00:00
if ( ! index . isValid ( ) ) {
2010-05-10 21:50:31 +00:00
ui_ - > action_selection_set_value - > setVisible ( false ) ;
ui_ - > action_edit_value - > setVisible ( false ) ;
2010-03-24 16:13:05 +00:00
} else {
Playlist : : Column column = ( Playlist : : Column ) index . column ( ) ;
2011-02-21 18:18:16 +00:00
bool column_is_editable = Playlist : : column_is_editable ( column )
& & editable ;
2010-03-25 23:48:58 +00:00
2010-05-10 21:50:31 +00:00
ui_ - > action_selection_set_value - > setVisible (
2010-06-24 23:36:39 +00:00
ui_ - > action_selection_set_value - > isVisible ( ) & & column_is_editable ) ;
2010-05-10 21:50:31 +00:00
ui_ - > action_edit_value - > setVisible (
2010-06-24 23:36:39 +00:00
ui_ - > action_edit_value - > isVisible ( ) & & column_is_editable ) ;
2010-03-24 16:13:05 +00:00
QString column_name = Playlist : : column_name ( column ) ;
2012-02-12 13:41:50 +00:00
QString column_value = app_ - > playlist_manager ( ) - > current ( ) - > data ( source_index ) . toString ( ) ;
2010-03-24 16:13:05 +00:00
if ( column_value . length ( ) > 25 )
column_value = column_value . left ( 25 ) + " ... " ;
2010-05-10 21:50:31 +00:00
ui_ - > action_selection_set_value - > setText ( tr ( " Set %1 to \" %2 \" ... " )
2010-03-24 16:13:05 +00:00
. arg ( column_name . toLower ( ) ) . arg ( column_value ) ) ;
2010-05-10 21:50:31 +00:00
ui_ - > action_edit_value - > setText ( tr ( " Edit tag \" %1 \" ... " ) . arg ( column_name ) ) ;
2010-06-24 23:36:39 +00:00
// Is it a library item?
2012-02-12 13:41:50 +00:00
PlaylistItemPtr item = app_ - > playlist_manager ( ) - > current ( ) - > item_at ( source_index . row ( ) ) ;
2011-03-20 16:07:24 +00:00
if ( item - > IsLocalLibraryItem ( ) & & item - > Metadata ( ) . id ( ) ! = - 1 ) {
2010-06-24 23:36:39 +00:00
playlist_organise_ - > setVisible ( editable ) ;
} else {
playlist_copy_to_library_ - > setVisible ( editable ) ;
playlist_move_to_library_ - > setVisible ( editable ) ;
}
2010-12-11 10:54:42 +00:00
playlist_delete_ - > setVisible ( editable ) ;
playlist_copy_to_device_ - > setVisible ( editable ) ;
2011-11-06 16:12:44 +01:00
// Remove old item actions, if any.
foreach ( QAction * action , playlistitem_actions_ ) {
playlist_menu_ - > removeAction ( action ) ;
}
// Get the new item actions, and add them
2012-07-29 03:11:00 +02:00
playlistitem_actions_ = item - > actions ( ) ;
playlistitem_actions_separator_ - > setVisible ( ! playlistitem_actions_ . isEmpty ( ) ) ;
playlist_menu_ - > insertActions ( playlistitem_actions_separator_ , playlistitem_actions_ ) ;
2010-03-24 16:13:05 +00:00
}
2010-01-16 16:12:47 +00:00
2011-03-20 17:38:15 +00:00
//if it isn't the first time we right click, we need to remove the menu previously created
if ( playlist_add_to_another_ ! = NULL ) {
playlist_menu_ - > removeAction ( playlist_add_to_another_ ) ;
delete playlist_add_to_another_ ;
}
//create the playlist submenu
QMenu * add_to_another_menu = new QMenu ( tr ( " Add to another playlist " ) , this ) ;
2012-05-12 19:12:33 +01:00
add_to_another_menu - > setIcon ( IconLoader : : Load ( " list-add " ) ) ;
2011-03-20 18:31:15 +00:00
2011-03-20 17:38:15 +00:00
PlaylistBackend : : Playlist playlist ;
2012-02-12 13:41:50 +00:00
foreach ( playlist , app_ - > playlist_backend ( ) - > GetAllPlaylists ( ) ) {
2011-03-20 17:38:15 +00:00
//don't add the current playlist
2012-02-12 13:41:50 +00:00
if ( playlist . id ! = app_ - > playlist_manager ( ) - > current ( ) - > id ( ) ) {
2011-03-20 17:38:15 +00:00
QAction * existing_playlist = new QAction ( this ) ;
existing_playlist - > setText ( playlist . name ) ;
existing_playlist - > setData ( playlist . id ) ;
add_to_another_menu - > addAction ( existing_playlist ) ;
}
}
add_to_another_menu - > addSeparator ( ) ;
//add to a new playlist
QAction * new_playlist = new QAction ( this ) ;
new_playlist - > setText ( tr ( " New playlist " ) ) ;
new_playlist - > setData ( - 1 ) ; //fake id
add_to_another_menu - > addAction ( new_playlist ) ;
2011-03-20 18:31:15 +00:00
playlist_add_to_another_ = playlist_menu_ - > insertMenu ( ui_ - > action_remove_from_playlist ,
add_to_another_menu ) ;
2011-03-20 17:38:15 +00:00
connect ( add_to_another_menu , SIGNAL ( triggered ( QAction * ) ) , SLOT ( AddToPlaylist ( QAction * ) ) ) ;
2010-01-15 16:22:19 +00:00
playlist_menu_ - > popup ( global_pos ) ;
}
void MainWindow : : PlaylistPlay ( ) {
2012-02-12 13:41:50 +00:00
if ( app_ - > playlist_manager ( ) - > current ( ) - > current_row ( ) = = playlist_menu_index_ . row ( ) ) {
app_ - > player ( ) - > PlayPause ( ) ;
2010-01-15 16:22:19 +00:00
} else {
2010-05-25 19:39:04 +00:00
PlayIndex ( playlist_menu_index_ ) ;
2010-01-15 16:22:19 +00:00
}
}
void MainWindow : : PlaylistStopAfter ( ) {
2012-02-12 13:41:50 +00:00
app_ - > playlist_manager ( ) - > current ( ) - > StopAfter ( playlist_menu_index_ . row ( ) ) ;
2010-01-15 16:22:19 +00:00
}
2010-01-16 16:12:47 +00:00
void MainWindow : : EditTracks ( ) {
SongList songs ;
2010-12-21 13:42:06 +00:00
PlaylistItemList items ;
2010-01-16 16:12:47 +00:00
foreach ( const QModelIndex & index ,
2010-05-20 14:12:15 +00:00
ui_ - > playlist - > view ( ) - > selectionModel ( ) - > selection ( ) . indexes ( ) ) {
2010-01-16 16:12:47 +00:00
if ( index . column ( ) ! = 0 )
continue ;
2012-02-12 13:41:50 +00:00
int row = app_ - > playlist_manager ( ) - > current ( ) - > proxy ( ) - > mapToSource ( index ) . row ( ) ;
PlaylistItemPtr item ( app_ - > playlist_manager ( ) - > current ( ) - > item_at ( row ) ) ;
2010-12-21 13:42:06 +00:00
Song song = item - > Metadata ( ) ;
2010-01-16 16:12:47 +00:00
if ( song . IsEditable ( ) ) {
songs < < song ;
2010-12-21 13:42:06 +00:00
items < < item ;
2010-01-16 16:12:47 +00:00
}
}
2010-08-27 15:42:58 +00:00
EnsureEditTagDialogCreated ( ) ;
2010-12-21 13:42:06 +00:00
edit_tag_dialog_ - > SetSongs ( songs , items ) ;
edit_tag_dialog_ - > show ( ) ;
}
2010-03-29 16:59:01 +00:00
2010-12-21 13:42:06 +00:00
void MainWindow : : EditTagDialogAccepted ( ) {
foreach ( PlaylistItemPtr item , edit_tag_dialog_ - > playlist_items ( ) ) {
item - > Reload ( ) ;
}
2010-01-16 16:12:47 +00:00
2010-12-21 13:42:06 +00:00
// This is really lame but we don't know what rows have changed
ui_ - > playlist - > view ( ) - > update ( ) ;
2011-08-27 23:09:42 +01:00
2012-02-12 13:41:50 +00:00
app_ - > playlist_manager ( ) - > current ( ) - > Save ( ) ;
2010-01-16 16:12:47 +00:00
}
2010-01-16 17:52:51 +00:00
2010-03-22 22:46:53 +00:00
void MainWindow : : RenumberTracks ( ) {
2011-08-27 23:16:57 +01:00
QModelIndexList indexes =
ui_ - > playlist - > view ( ) - > selectionModel ( ) - > selection ( ) . indexes ( ) ;
int track = 1 ;
2010-03-22 22:46:53 +00:00
2010-04-27 17:15:11 +00:00
// Get the index list in order
qStableSort ( indexes ) ;
2010-03-22 22:46:53 +00:00
// if first selected song has a track number set, start from that offset
2011-08-27 22:43:02 +01:00
if ( ! indexes . isEmpty ( ) ) {
2012-02-12 13:41:50 +00:00
const Song first_song = app_ - > playlist_manager ( ) - > current ( ) - > item_at ( indexes [ 0 ] . row ( ) ) - > Metadata ( ) ;
2011-08-27 22:43:02 +01:00
if ( first_song . track ( ) > 0 )
track = first_song . track ( ) ;
2010-03-22 22:46:53 +00:00
}
foreach ( const QModelIndex & index , indexes ) {
if ( index . column ( ) ! = 0 )
continue ;
2012-02-12 13:41:50 +00:00
const QModelIndex source_index = app_ - > playlist_manager ( ) - > current ( ) - > proxy ( ) - > mapToSource ( index ) ;
2011-08-27 23:16:57 +01:00
int row = source_index . row ( ) ;
2012-02-12 13:41:50 +00:00
Song song = app_ - > playlist_manager ( ) - > current ( ) - > item_at ( row ) - > Metadata ( ) ;
2010-03-22 22:46:53 +00:00
if ( song . IsEditable ( ) ) {
song . set_track ( track ) ;
2012-01-06 21:27:02 +00:00
TagReaderReply * reply =
TagReaderClient : : Instance ( ) - > SaveFile ( song . url ( ) . toLocalFile ( ) , song ) ;
NewClosure ( reply , SIGNAL ( Finished ( bool ) ) ,
this , SLOT ( SongSaveComplete ( TagReaderReply * , QPersistentModelIndex ) ) ,
reply , QPersistentModelIndex ( source_index ) ) ;
2010-03-22 22:46:53 +00:00
}
track + + ;
}
}
2012-01-06 21:27:02 +00:00
void MainWindow : : SongSaveComplete ( TagReaderReply * reply ,
const QPersistentModelIndex & index ) {
if ( reply - > is_successful ( ) & & index . isValid ( ) ) {
2012-02-12 13:41:50 +00:00
app_ - > playlist_manager ( ) - > current ( ) - > ReloadItems ( QList < int > ( ) < < index . row ( ) ) ;
2010-08-02 14:22:05 +00:00
}
2012-01-06 21:27:02 +00:00
reply - > deleteLater ( ) ;
2010-08-02 14:22:05 +00:00
}
2010-03-24 00:12:52 +00:00
void MainWindow : : SelectionSetValue ( ) {
Playlist : : Column column = ( Playlist : : Column ) playlist_menu_index_ . column ( ) ;
2012-02-12 13:41:50 +00:00
QVariant column_value = app_ - > playlist_manager ( ) - > current ( ) - > data ( playlist_menu_index_ ) ;
2010-03-24 00:12:52 +00:00
2010-11-28 14:47:35 +00:00
QModelIndexList indexes =
ui_ - > playlist - > view ( ) - > selectionModel ( ) - > selection ( ) . indexes ( ) ;
2010-03-24 00:12:52 +00:00
foreach ( const QModelIndex & index , indexes ) {
if ( index . column ( ) ! = 0 )
continue ;
2012-02-12 13:41:50 +00:00
const QModelIndex source_index = app_ - > playlist_manager ( ) - > current ( ) - > proxy ( ) - > mapToSource ( index ) ;
2011-08-27 23:16:57 +01:00
int row = source_index . row ( ) ;
2012-02-12 13:41:50 +00:00
Song song = app_ - > playlist_manager ( ) - > current ( ) - > item_at ( row ) - > Metadata ( ) ;
2010-03-24 00:12:52 +00:00
2010-11-28 14:47:35 +00:00
if ( Playlist : : set_column_value ( song , column , column_value ) ) {
2012-01-06 21:27:02 +00:00
TagReaderReply * reply =
TagReaderClient : : Instance ( ) - > SaveFile ( song . url ( ) . toLocalFile ( ) , song ) ;
NewClosure ( reply , SIGNAL ( Finished ( bool ) ) ,
this , SLOT ( SongSaveComplete ( TagReaderReply * , QPersistentModelIndex ) ) ,
reply , QPersistentModelIndex ( source_index ) ) ;
2010-03-24 00:12:52 +00:00
}
}
}
2010-03-25 23:48:58 +00:00
void MainWindow : : EditValue ( ) {
2010-08-30 16:49:10 +00:00
QModelIndex current = ui_ - > playlist - > view ( ) - > currentIndex ( ) ;
if ( ! current . isValid ( ) )
return ;
// Edit the last column that was right-clicked on. If nothing's ever been
// right clicked then look for the first editable column.
int column = playlist_menu_index_ . column ( ) ;
if ( column = = - 1 ) {
for ( int i = 0 ; i < ui_ - > playlist - > view ( ) - > model ( ) - > columnCount ( ) ; + + i ) {
if ( ui_ - > playlist - > view ( ) - > isColumnHidden ( i ) )
continue ;
if ( ! Playlist : : column_is_editable ( Playlist : : Column ( i ) ) )
continue ;
column = i ;
break ;
}
}
ui_ - > playlist - > view ( ) - > edit ( current . sibling ( current . row ( ) , column ) ) ;
2010-03-25 23:48:58 +00:00
}
2010-05-11 20:02:19 +00:00
void MainWindow : : AddFile ( ) {
2010-02-24 22:26:01 +00:00
// Last used directory
2010-02-27 16:52:18 +00:00
QString directory = settings_ . value ( " add_media_path " , QDir : : currentPath ( ) ) . toString ( ) ;
2010-02-24 22:26:01 +00:00
2012-02-12 13:41:50 +00:00
PlaylistParser parser ( app_ - > library_backend ( ) ) ;
2010-06-15 18:24:08 +00:00
2010-02-24 22:26:01 +00:00
// Show dialog
2010-03-07 14:42:51 +00:00
QStringList file_names = QFileDialog : : getOpenFileNames (
2011-11-04 14:14:07 +01:00
this , tr ( " Add file " ) , directory ,
2012-01-29 20:10:00 +00:00
QString ( " %1 (%2);;%3;;%4 " ) . arg (
tr ( " Music " ) ,
FileView : : kFileFilter ,
parser . filters ( ) ,
tr ( kAllFilesFilterSpec ) ) ) ;
2010-02-24 22:26:01 +00:00
if ( file_names . isEmpty ( ) )
return ;
// Save last used directory
2010-02-27 16:52:18 +00:00
settings_ . setValue ( " add_media_path " , file_names [ 0 ] ) ;
2010-02-24 22:26:01 +00:00
2010-06-15 18:24:08 +00:00
// Convert to URLs
QList < QUrl > urls ;
2010-02-24 22:26:01 +00:00
foreach ( const QString & path , file_names ) {
2011-03-13 14:43:03 +00:00
urls < < QUrl : : fromLocalFile ( QFileInfo ( path ) . canonicalFilePath ( ) ) ;
2010-02-24 22:26:01 +00:00
}
2011-01-10 22:26:13 +00:00
MimeData * data = new MimeData ;
data - > setUrls ( urls ) ;
AddToPlaylist ( data ) ;
2010-02-24 22:26:01 +00:00
}
2010-05-11 20:02:19 +00:00
void MainWindow : : AddFolder ( ) {
// Last used directory
QString directory = settings_ . value ( " add_folder_path " , QDir : : currentPath ( ) ) . toString ( ) ;
// Show dialog
directory = QFileDialog : : getExistingDirectory ( this , tr ( " Add folder " ) , directory ) ;
if ( directory . isEmpty ( ) )
return ;
// Save last used directory
settings_ . setValue ( " add_folder_path " , directory ) ;
// Add media
2011-01-10 22:26:13 +00:00
MimeData * data = new MimeData ;
2011-03-13 14:43:03 +00:00
data - > setUrls ( QList < QUrl > ( ) < < QUrl : : fromLocalFile ( QFileInfo ( directory ) . canonicalFilePath ( ) ) ) ;
2011-01-10 22:26:13 +00:00
AddToPlaylist ( data ) ;
2010-05-11 20:02:19 +00:00
}
2010-02-24 22:26:01 +00:00
void MainWindow : : AddStream ( ) {
2010-08-27 15:42:58 +00:00
if ( ! add_stream_dialog_ ) {
add_stream_dialog_ . reset ( new AddStreamDialog ) ;
connect ( add_stream_dialog_ . get ( ) , SIGNAL ( accepted ( ) ) , SLOT ( AddStreamAccepted ( ) ) ) ;
2011-07-15 13:27:50 +00:00
add_stream_dialog_ - > set_add_on_accept ( InternetModel : : Service < SavedRadio > ( ) ) ;
2010-08-27 15:42:58 +00:00
}
2010-02-24 22:26:01 +00:00
add_stream_dialog_ - > show ( ) ;
}
void MainWindow : : AddStreamAccepted ( ) {
2011-01-10 22:26:13 +00:00
MimeData * data = new MimeData ;
data - > setUrls ( QList < QUrl > ( ) < < add_stream_dialog_ - > url ( ) ) ;
AddToPlaylist ( data ) ;
2010-03-07 20:19:35 +00:00
}
2010-03-24 16:36:44 +00:00
2011-06-09 23:08:43 +00:00
void MainWindow : : AddCDTracks ( ) {
MimeData * data = new MimeData ;
// We are putting empty data, but we specify cdda mimetype to indicate that
// we want to load audio cd tracks
data - > open_in_new_playlist_ = true ;
data - > setData ( Playlist : : kCddaMimeType , QByteArray ( ) ) ;
AddToPlaylist ( data ) ;
}
2010-03-24 16:36:44 +00:00
void MainWindow : : PlaylistRemoveCurrent ( ) {
2010-05-20 14:12:15 +00:00
ui_ - > playlist - > view ( ) - > RemoveSelected ( ) ;
2010-03-24 16:36:44 +00:00
}
2010-03-31 00:30:57 +00:00
2010-04-11 17:58:58 +00:00
void MainWindow : : PlaylistEditFinished ( const QModelIndex & index ) {
if ( index = = playlist_menu_index_ )
SelectionSetValue ( ) ;
}
2010-04-12 22:44:29 +00:00
void MainWindow : : CommandlineOptionsReceived ( const QByteArray & serialized_options ) {
if ( serialized_options = = " wake up! " ) {
// Old versions of Clementine sent this - just ignore it
return ;
}
CommandlineOptions options ;
options . Load ( serialized_options ) ;
2010-04-12 23:35:47 +00:00
if ( options . is_empty ( ) ) {
show ( ) ;
activateWindow ( ) ;
}
else
CommandlineOptionsReceived ( options ) ;
2010-04-12 22:44:29 +00:00
}
void MainWindow : : CommandlineOptionsReceived ( const CommandlineOptions & options ) {
switch ( options . player_action ( ) ) {
case CommandlineOptions : : Player_Play :
2012-02-12 13:41:50 +00:00
app_ - > player ( ) - > Play ( ) ;
2010-04-12 22:44:29 +00:00
break ;
case CommandlineOptions : : Player_PlayPause :
2012-02-12 13:41:50 +00:00
app_ - > player ( ) - > PlayPause ( ) ;
2010-04-12 22:44:29 +00:00
break ;
case CommandlineOptions : : Player_Pause :
2012-02-12 13:41:50 +00:00
app_ - > player ( ) - > Pause ( ) ;
2010-04-12 22:44:29 +00:00
break ;
case CommandlineOptions : : Player_Stop :
2012-02-12 13:41:50 +00:00
app_ - > player ( ) - > Stop ( ) ;
2010-04-12 22:44:29 +00:00
break ;
case CommandlineOptions : : Player_Previous :
2012-02-12 13:41:50 +00:00
app_ - > player ( ) - > Previous ( ) ;
2010-04-12 22:44:29 +00:00
break ;
case CommandlineOptions : : Player_Next :
2012-02-12 13:41:50 +00:00
app_ - > player ( ) - > Next ( ) ;
2010-04-12 22:44:29 +00:00
break ;
case CommandlineOptions : : Player_None :
break ;
}
switch ( options . url_list_action ( ) ) {
case CommandlineOptions : : UrlList_Load :
2012-02-12 13:41:50 +00:00
app_ - > playlist_manager ( ) - > ClearCurrent ( ) ;
2010-04-12 22:44:29 +00:00
// fallthrough
2011-01-10 22:26:13 +00:00
case CommandlineOptions : : UrlList_Append : {
MimeData * data = new MimeData ;
data - > setUrls ( options . urls ( ) ) ;
AddToPlaylist ( data ) ;
2010-04-12 22:44:29 +00:00
break ;
2011-01-10 22:26:13 +00:00
}
2010-04-12 22:44:29 +00:00
}
2010-04-12 23:35:47 +00:00
if ( options . set_volume ( ) ! = - 1 )
2012-02-12 13:41:50 +00:00
app_ - > player ( ) - > SetVolume ( options . set_volume ( ) ) ;
2010-04-12 23:35:47 +00:00
if ( options . volume_modifier ( ) ! = 0 )
2012-02-12 13:41:50 +00:00
app_ - > player ( ) - > SetVolume ( app_ - > player ( ) - > GetVolume ( ) + options . volume_modifier ( ) ) ;
2010-04-12 23:35:47 +00:00
if ( options . seek_to ( ) ! = - 1 )
2012-02-12 13:41:50 +00:00
app_ - > player ( ) - > SeekTo ( options . seek_to ( ) ) ;
2010-04-13 20:22:29 +00:00
else if ( options . seek_by ( ) ! = 0 )
2012-02-12 13:41:50 +00:00
app_ - > player ( ) - > SeekTo ( app_ - > player ( ) - > engine ( ) - > position_nanosec ( ) / kNsecPerSec + options . seek_by ( ) ) ;
2010-04-12 23:35:47 +00:00
if ( options . play_track_at ( ) ! = - 1 )
2012-02-12 13:41:50 +00:00
app_ - > player ( ) - > PlayAt ( options . play_track_at ( ) , Engine : : Manual , true ) ;
2010-04-12 23:35:47 +00:00
if ( options . show_osd ( ) )
2012-02-12 13:41:50 +00:00
app_ - > player ( ) - > ShowOSD ( ) ;
2011-06-05 08:21:17 +00:00
if ( options . toggle_pretty_osd ( ) )
2012-02-12 13:41:50 +00:00
app_ - > player ( ) - > TogglePrettyOSD ( ) ;
2010-04-12 22:44:29 +00:00
}
2010-04-13 20:45:40 +00:00
2012-02-13 20:44:04 +00:00
void MainWindow : : ForceShowOSD ( const Song & song , const bool toggle ) {
2011-06-05 13:34:12 +00:00
if ( toggle ) {
2011-06-05 08:21:17 +00:00
osd_ - > SetPrettyOSDToggleMode ( toggle ) ;
2011-06-05 13:34:12 +00:00
}
2012-02-13 20:44:04 +00:00
osd_ - > ReshowCurrentSong ( ) ;
2010-04-13 20:45:40 +00:00
}
2010-04-14 21:27:27 +00:00
2010-06-14 13:22:45 +00:00
void MainWindow : : Activate ( ) {
show ( ) ;
}
2010-06-15 21:56:33 +00:00
bool MainWindow : : LoadUrl ( const QString & url ) {
if ( ! QFile : : exists ( url ) )
return false ;
2011-01-10 22:26:13 +00:00
MimeData * data = new MimeData ;
data - > setUrls ( QList < QUrl > ( ) < < QUrl : : fromLocalFile ( url ) ) ;
AddToPlaylist ( data ) ;
2010-06-15 21:56:33 +00:00
return true ;
}
2010-04-15 15:23:12 +00:00
void MainWindow : : CheckForUpdates ( ) {
2010-12-30 16:20:33 +00:00
# if defined(Q_OS_DARWIN)
2010-04-15 15:23:12 +00:00
mac : : CheckForUpdates ( ) ;
# endif
}
2010-05-20 21:21:55 +00:00
void MainWindow : : PlaylistUndoRedoChanged ( QAction * undo , QAction * redo ) {
playlist_menu_ - > insertAction ( playlist_undoredo_ , undo ) ;
playlist_menu_ - > insertAction ( playlist_undoredo_ , redo ) ;
}
2010-06-09 15:38:00 +00:00
void MainWindow : : ShowLibraryConfig ( ) {
2010-08-27 15:42:58 +00:00
EnsureSettingsDialogCreated ( ) ;
2010-06-09 15:38:00 +00:00
settings_dialog_ - > OpenAtPage ( SettingsDialog : : Page_Library ) ;
}
2010-06-16 19:21:15 +00:00
void MainWindow : : TaskCountChanged ( int count ) {
if ( count = = 0 ) {
ui_ - > status_bar_stack - > setCurrentWidget ( ui_ - > playlist_summary_page ) ;
} else {
ui_ - > status_bar_stack - > setCurrentWidget ( ui_ - > multi_loading_indicator ) ;
}
}
2010-06-18 00:06:59 +00:00
void MainWindow : : NowPlayingWidgetPositionChanged ( bool above_status_bar ) {
if ( above_status_bar ) {
ui_ - > status_bar - > setParent ( ui_ - > centralWidget ) ;
} else {
ui_ - > status_bar - > setParent ( ui_ - > player_controls_container ) ;
}
ui_ - > status_bar - > parentWidget ( ) - > layout ( ) - > addWidget ( ui_ - > status_bar ) ;
ui_ - > status_bar - > show ( ) ;
}
2010-06-24 16:26:49 +00:00
2012-01-29 18:44:00 +00:00
void MainWindow : : CopyFilesToLibrary ( const QList < QUrl > & urls ) {
2012-02-12 13:41:50 +00:00
organise_dialog_ - > SetDestinationModel ( app_ - > library_model ( ) - > directory_model ( ) ) ;
2010-06-24 16:26:49 +00:00
organise_dialog_ - > SetUrls ( urls ) ;
2010-06-24 20:26:17 +00:00
organise_dialog_ - > SetCopy ( true ) ;
2010-06-24 16:26:49 +00:00
organise_dialog_ - > show ( ) ;
}
2012-01-29 18:44:00 +00:00
void MainWindow : : MoveFilesToLibrary ( const QList < QUrl > & urls ) {
2012-02-12 13:41:50 +00:00
organise_dialog_ - > SetDestinationModel ( app_ - > library_model ( ) - > directory_model ( ) ) ;
2010-06-24 16:26:49 +00:00
organise_dialog_ - > SetUrls ( urls ) ;
2010-06-24 20:26:17 +00:00
organise_dialog_ - > SetCopy ( false ) ;
2010-06-24 16:26:49 +00:00
organise_dialog_ - > show ( ) ;
}
2010-06-24 23:36:39 +00:00
2012-01-29 18:44:00 +00:00
void MainWindow : : CopyFilesToDevice ( const QList < QUrl > & urls ) {
2012-02-12 13:41:50 +00:00
organise_dialog_ - > SetDestinationModel ( app_ - > device_manager ( ) - > connected_devices_model ( ) , true ) ;
2010-09-18 09:54:33 +00:00
organise_dialog_ - > SetCopy ( true ) ;
if ( organise_dialog_ - > SetUrls ( urls ) )
organise_dialog_ - > show ( ) ;
else {
QMessageBox : : warning ( this , tr ( " Error " ) ,
tr ( " None of the selected songs were suitable for copying to a device " ) ) ;
}
}
2012-01-29 18:44:00 +00:00
void MainWindow : : EditFileTags ( const QList < QUrl > & urls ) {
EnsureEditTagDialogCreated ( ) ;
SongList songs ;
foreach ( const QUrl & url , urls ) {
Song song ;
song . set_url ( url ) ;
song . set_valid ( true ) ;
song . set_filetype ( Song : : Type_Mpeg ) ;
songs < < song ;
}
edit_tag_dialog_ - > SetSongs ( songs ) ;
edit_tag_dialog_ - > show ( ) ;
}
2010-06-24 23:36:39 +00:00
void MainWindow : : PlaylistCopyToLibrary ( ) {
PlaylistOrganiseSelected ( true ) ;
}
void MainWindow : : PlaylistMoveToLibrary ( ) {
PlaylistOrganiseSelected ( false ) ;
}
void MainWindow : : PlaylistOrganiseSelected ( bool copy ) {
2010-08-08 13:06:52 +00:00
QModelIndexList proxy_indexes = ui_ - > playlist - > view ( ) - > selectionModel ( ) - > selectedRows ( ) ;
SongList songs ;
2010-06-24 23:36:39 +00:00
2010-08-08 13:06:52 +00:00
foreach ( const QModelIndex & proxy_index , proxy_indexes ) {
2012-02-12 13:41:50 +00:00
QModelIndex index = app_ - > playlist_manager ( ) - > current ( ) - > proxy ( ) - > mapToSource ( proxy_index ) ;
2010-06-24 23:36:39 +00:00
2012-02-12 13:41:50 +00:00
songs < < app_ - > playlist_manager ( ) - > current ( ) - > item_at ( index . row ( ) ) - > Metadata ( ) ;
2010-06-24 23:36:39 +00:00
}
2012-02-12 13:41:50 +00:00
organise_dialog_ - > SetDestinationModel ( app_ - > library_model ( ) - > directory_model ( ) ) ;
2010-08-08 13:06:52 +00:00
organise_dialog_ - > SetSongs ( songs ) ;
2010-06-24 23:36:39 +00:00
organise_dialog_ - > SetCopy ( copy ) ;
organise_dialog_ - > show ( ) ;
}
void MainWindow : : PlaylistDelete ( ) {
2010-12-11 10:54:42 +00:00
// Note: copied from LibraryView::Delete
if ( QMessageBox : : question ( this , tr ( " Delete files " ) ,
tr ( " These files will be deleted from disk, are you sure you want to continue? " ) ,
QMessageBox : : Yes , QMessageBox : : Cancel ) ! = QMessageBox : : Yes )
return ;
// We can cheat and always take the storage of the first directory, since
// they'll all be FilesystemMusicStorage in a library and deleting doesn't
// check the actual directory.
boost : : shared_ptr < MusicStorage > storage =
2012-02-12 13:41:50 +00:00
app_ - > library_model ( ) - > directory_model ( ) - > index ( 0 , 0 ) . data ( MusicStorage : : Role_Storage )
2010-12-11 10:54:42 +00:00
. value < boost : : shared_ptr < MusicStorage > > ( ) ;
// Get selected songs
SongList selected_songs ;
QModelIndexList proxy_indexes = ui_ - > playlist - > view ( ) - > selectionModel ( ) - > selectedRows ( ) ;
foreach ( const QModelIndex & proxy_index , proxy_indexes ) {
2012-02-12 13:41:50 +00:00
QModelIndex index = app_ - > playlist_manager ( ) - > current ( ) - > proxy ( ) - > mapToSource ( proxy_index ) ;
selected_songs < < app_ - > playlist_manager ( ) - > current ( ) - > item_at ( index . row ( ) ) - > Metadata ( ) ;
2010-12-11 10:54:42 +00:00
}
ui_ - > playlist - > view ( ) - > RemoveSelected ( ) ;
2012-02-12 13:41:50 +00:00
DeleteFiles * delete_files = new DeleteFiles ( app_ - > task_manager ( ) , storage ) ;
2010-12-11 10:54:42 +00:00
connect ( delete_files , SIGNAL ( Finished ( SongList ) ) , SLOT ( DeleteFinished ( SongList ) ) ) ;
delete_files - > Start ( selected_songs ) ;
}
2011-03-17 19:52:21 +00:00
void MainWindow : : PlaylistOpenInBrowser ( ) {
2011-10-26 14:54:24 +02:00
QList < QUrl > urls ;
2011-03-06 13:10:14 +00:00
QModelIndexList proxy_indexes = ui_ - > playlist - > view ( ) - > selectionModel ( ) - > selectedRows ( ) ;
2011-03-17 19:52:21 +00:00
2011-03-06 13:10:14 +00:00
foreach ( const QModelIndex & proxy_index , proxy_indexes ) {
2012-02-12 13:41:50 +00:00
const QModelIndex index = app_ - > playlist_manager ( ) - > current ( ) - > proxy ( ) - > mapToSource ( proxy_index ) ;
2011-10-26 14:54:24 +02:00
urls < < index . sibling ( index . row ( ) , Playlist : : Column_Filename ) . data ( ) . toString ( ) ;
2011-03-06 13:10:14 +00:00
}
2011-03-17 19:52:21 +00:00
2011-10-26 14:54:24 +02:00
Utilities : : OpenInFileBrowser ( urls ) ;
2011-03-06 13:10:14 +00:00
}
2010-12-11 10:54:42 +00:00
void MainWindow : : DeleteFinished ( const SongList & songs_with_errors ) {
if ( songs_with_errors . isEmpty ( ) )
return ;
OrganiseErrorDialog * dialog = new OrganiseErrorDialog ( this ) ;
dialog - > Show ( OrganiseErrorDialog : : Type_Delete , songs_with_errors ) ;
// It deletes itself when the user closes it
2010-07-11 15:37:40 +00:00
}
2010-06-24 23:36:39 +00:00
2010-07-11 15:37:40 +00:00
void MainWindow : : PlaylistQueue ( ) {
2010-07-11 16:58:22 +00:00
QModelIndexList indexes ;
foreach ( const QModelIndex & proxy_index ,
ui_ - > playlist - > view ( ) - > selectionModel ( ) - > selectedRows ( ) ) {
2012-02-12 13:41:50 +00:00
indexes < < app_ - > playlist_manager ( ) - > current ( ) - > proxy ( ) - > mapToSource ( proxy_index ) ;
2010-07-11 16:58:22 +00:00
}
2012-02-12 13:41:50 +00:00
app_ - > playlist_manager ( ) - > current ( ) - > queue ( ) - > ToggleTracks ( indexes ) ;
2010-06-24 23:36:39 +00:00
}
2010-08-08 13:06:52 +00:00
void MainWindow : : PlaylistCopyToDevice ( ) {
QModelIndexList proxy_indexes = ui_ - > playlist - > view ( ) - > selectionModel ( ) - > selectedRows ( ) ;
SongList songs ;
foreach ( const QModelIndex & proxy_index , proxy_indexes ) {
2012-02-12 13:41:50 +00:00
QModelIndex index = app_ - > playlist_manager ( ) - > current ( ) - > proxy ( ) - > mapToSource ( proxy_index ) ;
2010-08-08 13:06:52 +00:00
2012-02-12 13:41:50 +00:00
songs < < app_ - > playlist_manager ( ) - > current ( ) - > item_at ( index . row ( ) ) - > Metadata ( ) ;
2010-08-08 13:06:52 +00:00
}
2012-02-12 13:41:50 +00:00
organise_dialog_ - > SetDestinationModel ( app_ - > device_manager ( ) - > connected_devices_model ( ) , true ) ;
2010-08-08 13:06:52 +00:00
organise_dialog_ - > SetCopy ( true ) ;
2010-09-15 20:00:17 +00:00
if ( organise_dialog_ - > SetSongs ( songs ) )
organise_dialog_ - > show ( ) ;
else {
QMessageBox : : warning ( this , tr ( " Error " ) ,
tr ( " None of the selected songs were suitable for copying to a device " ) ) ;
}
2010-08-08 13:06:52 +00:00
}
2010-08-27 15:42:58 +00:00
2011-02-06 13:18:18 +00:00
void MainWindow : : ChangeLibraryQueryMode ( QAction * action ) {
if ( action = = library_show_duplicates_ ) {
library_view_ - > filter ( ) - > SetQueryMode ( QueryOptions : : QueryMode_Duplicates ) ;
} else if ( action = = library_show_untagged_ ) {
library_view_ - > filter ( ) - > SetQueryMode ( QueryOptions : : QueryMode_Untagged ) ;
} else {
library_view_ - > filter ( ) - > SetQueryMode ( QueryOptions : : QueryMode_All ) ;
}
}
2010-08-27 15:42:58 +00:00
void MainWindow : : ShowCoverManager ( ) {
if ( ! cover_manager_ ) {
2012-02-12 13:41:50 +00:00
cover_manager_ . reset ( new AlbumCoverManager ( app_ ) ) ;
2010-08-27 15:42:58 +00:00
cover_manager_ - > Init ( ) ;
// Cover manager connections
2011-01-10 22:26:13 +00:00
connect ( cover_manager_ . get ( ) , SIGNAL ( AddToPlaylist ( QMimeData * ) ) , SLOT ( AddToPlaylist ( QMimeData * ) ) ) ;
2010-08-27 15:42:58 +00:00
}
cover_manager_ - > show ( ) ;
}
void MainWindow : : EnsureSettingsDialogCreated ( ) {
if ( settings_dialog_ )
return ;
2012-03-09 15:25:49 +00:00
settings_dialog_ . reset ( new SettingsDialog ( app_ , background_streams_ ) ) ;
2010-08-27 15:42:58 +00:00
settings_dialog_ - > SetGlobalShortcutManager ( global_shortcuts_ ) ;
2010-10-10 16:46:35 +00:00
settings_dialog_ - > SetSongInfoView ( song_info_view_ ) ;
2010-08-27 15:42:58 +00:00
// Settings
2011-01-02 14:50:17 +00:00
connect ( settings_dialog_ . get ( ) , SIGNAL ( accepted ( ) ) , SLOT ( ReloadAllSettings ( ) ) ) ;
2011-03-12 21:19:32 +00:00
# ifdef HAVE_WIIMOTEDEV
2010-08-31 20:35:11 +00:00
connect ( settings_dialog_ . get ( ) , SIGNAL ( SetWiimotedevInterfaceActived ( bool ) ) , wiimotedev_shortcuts_ . get ( ) , SLOT ( SetWiimotedevInterfaceActived ( bool ) ) ) ;
# endif
2011-05-22 21:15:11 +00:00
// Allows custom notification preview
connect ( settings_dialog_ . get ( ) , SIGNAL ( NotificationPreview ( OSD : : Behaviour , QString , QString ) ) ,
SLOT ( HandleNotificationPreview ( OSD : : Behaviour , QString , QString ) ) ) ;
2010-08-27 15:42:58 +00:00
}
void MainWindow : : OpenSettingsDialog ( ) {
EnsureSettingsDialogCreated ( ) ;
settings_dialog_ - > show ( ) ;
}
void MainWindow : : OpenSettingsDialogAtPage ( SettingsDialog : : Page page ) {
EnsureSettingsDialogCreated ( ) ;
settings_dialog_ - > OpenAtPage ( page ) ;
}
void MainWindow : : EnsureEditTagDialogCreated ( ) {
if ( edit_tag_dialog_ )
return ;
2012-02-12 13:41:50 +00:00
edit_tag_dialog_ . reset ( new EditTagDialog ( app_ ) ) ;
2010-12-21 13:42:06 +00:00
connect ( edit_tag_dialog_ . get ( ) , SIGNAL ( accepted ( ) ) , SLOT ( EditTagDialogAccepted ( ) ) ) ;
connect ( edit_tag_dialog_ . get ( ) , SIGNAL ( Error ( QString ) ) , SLOT ( ShowErrorDialog ( QString ) ) ) ;
2010-08-27 15:42:58 +00:00
}
void MainWindow : : ShowAboutDialog ( ) {
if ( ! about_dialog_ ) {
about_dialog_ . reset ( new About ) ;
}
about_dialog_ - > show ( ) ;
}
void MainWindow : : ShowTranscodeDialog ( ) {
if ( ! transcode_dialog_ ) {
transcode_dialog_ . reset ( new TranscodeDialog ) ;
}
transcode_dialog_ - > show ( ) ;
}
2010-08-27 19:09:03 +00:00
void MainWindow : : ShowErrorDialog ( const QString & message ) {
if ( ! error_dialog_ ) {
error_dialog_ . reset ( new ErrorDialog ) ;
}
error_dialog_ - > ShowMessage ( message ) ;
}
2011-02-25 20:10:41 +00:00
void MainWindow : : CheckFullRescanRevisions ( ) {
2012-02-12 13:41:50 +00:00
int from = app_ - > database ( ) - > startup_schema_version ( ) ;
int to = app_ - > database ( ) - > current_schema_version ( ) ;
2011-02-25 20:10:41 +00:00
// if we're restoring DB from scratch or nothing has
// changed, do nothing
if ( from = = 0 | | from = = to ) {
return ;
}
// collect all reasons
QSet < QString > reasons ;
for ( int i = from ; i < = to ; i + + ) {
2012-02-12 13:41:50 +00:00
QString reason = app_ - > library ( ) - > full_rescan_reason ( i ) ;
2011-02-25 20:10:41 +00:00
if ( ! reason . isEmpty ( ) ) {
reasons . insert ( reason ) ;
}
}
// if we have any...
if ( ! reasons . isEmpty ( ) ) {
QString message = tr ( " The version of Clementine you've just updated to requires a full library rescan "
2011-03-22 14:53:48 +00:00
" because of the new features listed below: " ) + " <ul> " ;
2011-02-25 20:10:41 +00:00
foreach ( const QString & reason , reasons ) {
message + = ( " <li> " + reason + " </li> " ) ;
}
2011-03-22 14:53:48 +00:00
message + = " </ul> " + tr ( " Would you like to run a full rescan right now? " ) ;
2011-02-25 20:10:41 +00:00
if ( QMessageBox : : question ( this , tr ( " Library rescan notice " ) ,
message , QMessageBox : : Yes , QMessageBox : : No ) = = QMessageBox : : Yes ) {
2012-02-12 13:41:50 +00:00
app_ - > library ( ) - > FullScan ( ) ;
2011-02-25 20:10:41 +00:00
}
}
}
2010-08-27 19:09:03 +00:00
void MainWindow : : ShowQueueManager ( ) {
if ( ! queue_manager_ ) {
queue_manager_ . reset ( new QueueManager ) ;
2012-02-12 13:41:50 +00:00
queue_manager_ - > SetPlaylistManager ( app_ - > playlist_manager ( ) ) ;
2010-08-27 19:09:03 +00:00
}
queue_manager_ - > show ( ) ;
}
void MainWindow : : ShowVisualisations ( ) {
# ifdef ENABLE_VISUALISATIONS
if ( ! visualisation_ ) {
visualisation_ . reset ( new VisualisationContainer ) ;
visualisation_ - > SetActions ( ui_ - > action_previous_track , ui_ - > action_play_pause ,
ui_ - > action_stop , ui_ - > action_next_track ) ;
2012-02-12 13:41:50 +00:00
connect ( app_ - > player ( ) , SIGNAL ( Stopped ( ) ) , visualisation_ . get ( ) , SLOT ( Stopped ( ) ) ) ;
connect ( app_ - > player ( ) , SIGNAL ( ForceShowOSD ( Song , bool ) ) , visualisation_ . get ( ) , SLOT ( SongMetadataChanged ( Song ) ) ) ;
connect ( app_ - > playlist_manager ( ) , SIGNAL ( CurrentSongChanged ( Song ) ) , visualisation_ . get ( ) , SLOT ( SongMetadataChanged ( Song ) ) ) ;
2010-08-27 19:09:03 +00:00
2012-02-12 13:41:50 +00:00
visualisation_ - > SetEngine ( qobject_cast < GstEngine * > ( app_ - > player ( ) - > engine ( ) ) ) ;
2010-08-27 19:09:03 +00:00
}
visualisation_ - > show ( ) ;
# endif // ENABLE_VISUALISATIONS
}
2010-10-01 19:27:01 +00:00
2010-10-02 13:37:10 +00:00
void MainWindow : : ConnectInfoView ( SongInfoBase * view ) {
2012-02-12 13:41:50 +00:00
connect ( app_ - > playlist_manager ( ) , SIGNAL ( CurrentSongChanged ( Song ) ) , view , SLOT ( SongChanged ( Song ) ) ) ;
connect ( app_ - > player ( ) , SIGNAL ( PlaylistFinished ( ) ) , view , SLOT ( SongFinished ( ) ) ) ;
connect ( app_ - > player ( ) , SIGNAL ( Stopped ( ) ) , view , SLOT ( SongFinished ( ) ) ) ;
2010-10-16 14:45:23 +00:00
connect ( view , SIGNAL ( ShowSettingsDialog ( ) ) , SLOT ( ShowSongInfoConfig ( ) ) ) ;
2011-11-11 21:35:25 +00:00
connect ( view , SIGNAL ( DoGlobalSearch ( QString ) ) ,
2012-06-16 21:17:13 +01:00
SLOT ( DoGlobalSearch ( QString ) ) ) ;
2010-12-04 16:19:30 +00:00
}
void MainWindow : : AddSongInfoGenerator ( smart_playlists : : GeneratorPtr gen ) {
if ( ! gen )
return ;
2012-02-12 13:41:50 +00:00
gen - > set_library ( app_ - > library_backend ( ) ) ;
2010-12-04 16:19:30 +00:00
2011-01-10 22:26:13 +00:00
AddToPlaylist ( new smart_playlists : : GeneratorMimeData ( gen ) ) ;
2010-10-16 14:45:23 +00:00
}
void MainWindow : : ShowSongInfoConfig ( ) {
OpenSettingsDialogAtPage ( SettingsDialog : : Page_SongInformation ) ;
2010-10-02 13:37:10 +00:00
}
2010-11-28 15:14:48 +00:00
void MainWindow : : PlaylistViewSelectionModelChanged ( ) {
connect ( ui_ - > playlist - > view ( ) - > selectionModel ( ) ,
SIGNAL ( currentChanged ( QModelIndex , QModelIndex ) ) ,
SLOT ( PlaylistCurrentChanged ( QModelIndex ) ) ) ;
}
void MainWindow : : PlaylistCurrentChanged ( const QModelIndex & proxy_current ) {
const QModelIndex source_current =
2012-02-12 13:41:50 +00:00
app_ - > playlist_manager ( ) - > current ( ) - > proxy ( ) - > mapToSource ( proxy_current ) ;
2010-11-28 15:14:48 +00:00
// If the user moves the current index using the keyboard and then presses
// F2, we don't want that editing the last column that was right clicked on.
if ( source_current ! = playlist_menu_index_ )
playlist_menu_index_ = QModelIndex ( ) ;
}
2010-12-31 18:13:28 +00:00
2011-01-04 11:33:22 +00:00
void MainWindow : : Raise ( ) {
show ( ) ;
activateWindow ( ) ;
}
2011-01-15 20:51:48 +00:00
# ifdef Q_OS_WIN32
2011-01-16 00:39:51 +00:00
bool MainWindow : : winEvent ( MSG * msg , long * ) {
thumbbar_ - > HandleWinEvent ( msg ) ;
2011-01-15 20:51:48 +00:00
return false ;
}
# endif // Q_OS_WIN32
2011-02-16 22:43:05 +00:00
void MainWindow : : Exit ( ) {
2012-02-12 13:41:50 +00:00
if ( app_ - > player ( ) - > engine ( ) - > is_fadeout_enabled ( ) ) {
2011-02-16 23:44:03 +00:00
// To shut down the application when fadeout will be finished
2012-02-12 13:41:50 +00:00
connect ( app_ - > player ( ) - > engine ( ) , SIGNAL ( FadeoutFinishedSignal ( ) ) , qApp , SLOT ( quit ( ) ) ) ;
if ( app_ - > player ( ) - > GetState ( ) = = Engine : : Playing ) {
app_ - > player ( ) - > Stop ( ) ;
2011-02-16 23:44:03 +00:00
hide ( ) ;
tray_icon_ - > SetVisible ( false ) ;
return ; // Don't quit the application now: wait for the fadeout finished signal
}
2011-02-16 23:03:00 +00:00
}
2011-02-16 23:44:03 +00:00
qApp - > quit ( ) ;
2011-02-16 22:43:05 +00:00
}
2011-03-06 14:07:41 +00:00
void MainWindow : : AutoCompleteTags ( ) {
// Create the tag fetching stuff if it hasn't been already
if ( ! tag_fetcher_ ) {
tag_fetcher_ . reset ( new TagFetcher ) ;
track_selection_dialog_ . reset ( new TrackSelectionDialog ) ;
track_selection_dialog_ - > set_save_on_close ( true ) ;
2011-03-12 21:19:41 +00:00
connect ( tag_fetcher_ . get ( ) , SIGNAL ( ResultAvailable ( Song , SongList ) ) ,
track_selection_dialog_ . get ( ) , SLOT ( FetchTagFinished ( Song , SongList ) ) ,
2011-03-06 14:07:41 +00:00
Qt : : QueuedConnection ) ;
2011-03-12 21:19:41 +00:00
connect ( tag_fetcher_ . get ( ) , SIGNAL ( Progress ( Song , QString ) ) ,
track_selection_dialog_ . get ( ) , SLOT ( FetchTagProgress ( Song , QString ) ) ) ;
2011-03-06 14:07:41 +00:00
connect ( track_selection_dialog_ . get ( ) , SIGNAL ( accepted ( ) ) ,
SLOT ( AutoCompleteTagsAccepted ( ) ) ) ;
2011-03-13 12:52:08 +00:00
connect ( track_selection_dialog_ . get ( ) , SIGNAL ( finished ( int ) ) ,
tag_fetcher_ . get ( ) , SLOT ( Cancel ( ) ) ) ;
2011-03-06 14:07:41 +00:00
}
// Get the selected songs and start fetching tags for them
SongList songs ;
autocomplete_tag_items_ . clear ( ) ;
foreach ( const QModelIndex & index ,
ui_ - > playlist - > view ( ) - > selectionModel ( ) - > selection ( ) . indexes ( ) ) {
if ( index . column ( ) ! = 0 )
continue ;
2012-02-12 13:41:50 +00:00
int row = app_ - > playlist_manager ( ) - > current ( ) - > proxy ( ) - > mapToSource ( index ) . row ( ) ;
PlaylistItemPtr item ( app_ - > playlist_manager ( ) - > current ( ) - > item_at ( row ) ) ;
2011-03-06 14:07:41 +00:00
Song song = item - > Metadata ( ) ;
if ( song . IsEditable ( ) ) {
songs < < song ;
autocomplete_tag_items_ < < item ;
}
}
track_selection_dialog_ - > Init ( songs ) ;
2011-03-12 21:19:41 +00:00
tag_fetcher_ - > StartFetch ( songs ) ;
2011-03-06 14:07:41 +00:00
track_selection_dialog_ - > show ( ) ;
}
2011-03-06 15:11:52 +00:00
2011-03-06 14:07:41 +00:00
void MainWindow : : AutoCompleteTagsAccepted ( ) {
foreach ( PlaylistItemPtr item , autocomplete_tag_items_ ) {
item - > Reload ( ) ;
}
// This is really lame but we don't know what rows have changed
ui_ - > playlist - > view ( ) - > update ( ) ;
}
2011-04-07 16:25:52 +00:00
QPixmap MainWindow : : CreateOverlayedIcon ( int position , int scrobble_point ) {
QPixmap normal_icon = QIcon ( " :/last.fm/as_light.png " ) . pixmap ( 16 ) ;
QPixmap light_icon = QIcon ( " :/last.fm/as.png " ) . pixmap ( 16 ) ;
QRect rect ( normal_icon . rect ( ) ) ;
//calculates the progress
double perc = 1.0 - ( ( double ) position / ( double ) scrobble_point ) ;
QPolygon mask ;
mask < < rect . topRight ( ) ;
mask < < rect . topLeft ( ) ;
mask < < QPoint ( rect . left ( ) , rect . height ( ) * perc ) ;
mask < < QPoint ( rect . right ( ) , ( rect . height ( ) ) * perc ) ;
QPixmap ret ( light_icon ) ;
QPainter p ( & ret ) ;
// Draw the red icon over the light red one
p . setClipRegion ( mask ) ;
p . drawPixmap ( 0 , 0 , normal_icon ) ;
p . setClipping ( false ) ;
p . end ( ) ;
return ret ;
}
void MainWindow : : SetToggleScrobblingIcon ( bool value ) {
if ( ! value ) {
ui_ - > action_toggle_scrobbling - > setIcon ( QIcon ( " :/last.fm/as_disabled.png " ) ) ;
} else {
ui_ - > action_toggle_scrobbling - > setIcon ( QIcon ( " :/last.fm/as_light.png " ) ) ;
}
}
# ifdef HAVE_LIBLASTFM
2012-06-25 12:30:53 +02:00
void MainWindow : : ScrobbleSubmitted ( ) {
2011-07-15 13:27:50 +00:00
const LastFMService * lastfm_service = InternetModel : : Service < LastFMService > ( ) ;
2011-04-16 23:17:48 +00:00
const bool last_fm_enabled = ui_ - > action_toggle_scrobbling - > isVisible ( ) & &
lastfm_service - > IsScrobblingEnabled ( ) & &
lastfm_service - > IsAuthenticated ( ) ;
2012-06-25 12:30:53 +02:00
app_ - > playlist_manager ( ) - > active ( ) - > set_lastfm_status ( Playlist : : LastFM_Scrobbled ) ;
// update the button icon
if ( last_fm_enabled )
ui_ - > action_toggle_scrobbling - > setIcon ( QIcon ( " :/last.fm/as.png " ) ) ;
}
void MainWindow : : ScrobbleError ( int value ) {
2011-04-16 23:17:48 +00:00
switch ( value ) {
case - 1 :
// custom error value got from initial validity check
2012-02-12 13:41:50 +00:00
app_ - > playlist_manager ( ) - > active ( ) - > set_lastfm_status ( Playlist : : LastFM_Invalid ) ;
2011-04-16 23:17:48 +00:00
break ;
2011-04-07 16:25:52 +00:00
2011-04-28 10:32:56 +00:00
case 30 :
// Hack: when offline, liblastfm doesn't inform us, so set the status
// as queued; in this way we won't try to scrobble again, it will be done automatically
2012-02-12 13:41:50 +00:00
app_ - > playlist_manager ( ) - > active ( ) - > set_lastfm_status ( Playlist : : LastFM_Queued ) ;
2011-04-28 10:32:56 +00:00
break ;
2011-04-16 23:17:48 +00:00
default :
if ( value > 3 ) {
// we're for sure in an error state
2012-02-12 13:41:50 +00:00
app_ - > playlist_manager ( ) - > active ( ) - > set_lastfm_status ( Playlist : : LastFM_Error ) ;
2011-04-22 16:50:29 +00:00
qLog ( Warning ) < < " Last.fm scrobbling error: " < < value ;
2011-04-16 23:17:48 +00:00
}
break ;
2011-04-07 16:25:52 +00:00
}
}
# endif
2011-05-22 21:15:11 +00:00
void MainWindow : : HandleNotificationPreview ( OSD : : Behaviour type , QString line1 , QString line2 ) {
2012-02-12 13:41:50 +00:00
if ( ! app_ - > playlist_manager ( ) - > current ( ) - > GetAllSongs ( ) . isEmpty ( ) ) {
2011-05-22 21:15:11 +00:00
// Show a preview notification for the first song in the current playlist
2012-02-12 13:41:50 +00:00
osd_ - > ShowPreview ( type , line1 , line2 , app_ - > playlist_manager ( ) - > current ( ) - > GetAllSongs ( ) . first ( ) ) ;
2011-05-22 21:15:11 +00:00
} else {
qLog ( Debug ) < < " The current playlist is empty, showing a fake song " ;
// Create a fake song
Song fake ;
fake . Init ( " Title " , " Artist " , " Album " , 123 ) ;
fake . set_genre ( " Classical " ) ;
fake . set_composer ( " Anonymous " ) ;
fake . set_track ( 1 ) ;
fake . set_disc ( 1 ) ;
fake . set_year ( 2011 ) ;
osd_ - > ShowPreview ( type , line1 , line2 , fake ) ;
}
}
2012-03-11 17:57:15 +00:00
void MainWindow : : ScrollToInternetIndex ( const QModelIndex & index ) {
internet_view_ - > ScrollToIndex ( index ) ;
ui_ - > tabs - > SetCurrentWidget ( internet_view_ ) ;
}
2012-03-12 14:11:24 +00:00
void MainWindow : : AddPodcast ( ) {
app_ - > internet_model ( ) - > Service < PodcastService > ( ) - > AddPodcast ( ) ;
}
2012-06-16 21:17:13 +01:00
void MainWindow : : FocusGlobalSearchField ( ) {
ui_ - > tabs - > SetCurrentWidget ( global_search_view_ ) ;
global_search_view_ - > FocusSearchField ( ) ;
}
void MainWindow : : DoGlobalSearch ( const QString & query ) {
FocusGlobalSearchField ( ) ;
global_search_view_ - > StartSearch ( query ) ;
}