2010-03-24 00:11:46 +01:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
2010-03-24 00:11:46 +01: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/>.
|
|
|
|
*/
|
|
|
|
|
2010-03-08 19:05:41 +01:00
|
|
|
#include "playlistsequence.h"
|
2010-05-10 23:50:31 +02:00
|
|
|
#include "ui_playlistsequence.h"
|
2010-05-19 17:45:29 +02:00
|
|
|
#include "ui/iconloader.h"
|
2010-03-08 15:08:54 +01:00
|
|
|
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QActionGroup>
|
|
|
|
#include <QSettings>
|
|
|
|
#include <QtDebug>
|
2010-05-19 17:45:29 +02:00
|
|
|
#include <QPainter>
|
2010-03-08 15:08:54 +01:00
|
|
|
|
2010-03-08 19:05:41 +01:00
|
|
|
const char* PlaylistSequence::kSettingsGroup = "PlaylistSequence";
|
2010-03-08 15:08:54 +01:00
|
|
|
|
2010-04-14 16:48:10 +02:00
|
|
|
PlaylistSequence::PlaylistSequence(QWidget *parent, SettingsProvider *settings)
|
2010-03-08 15:08:54 +01:00
|
|
|
: QWidget(parent),
|
2010-05-10 23:50:31 +02:00
|
|
|
ui_(new Ui_PlaylistSequence),
|
2010-04-14 16:48:10 +02:00
|
|
|
settings_(settings ? settings : new DefaultSettingsProvider),
|
2010-03-08 15:08:54 +01:00
|
|
|
repeat_menu_(new QMenu(this)),
|
|
|
|
shuffle_menu_(new QMenu(this)),
|
|
|
|
loading_(false),
|
|
|
|
repeat_mode_(Repeat_Off),
|
2010-11-20 19:49:54 +01:00
|
|
|
shuffle_mode_(Shuffle_Off),
|
|
|
|
dynamic_(false)
|
2010-03-08 15:08:54 +01:00
|
|
|
{
|
2010-05-10 23:50:31 +02:00
|
|
|
ui_->setupUi(this);
|
2010-03-08 15:08:54 +01:00
|
|
|
|
2010-05-19 17:45:29 +02:00
|
|
|
// Icons
|
|
|
|
ui_->repeat->setIcon(AddDesaturatedIcon(IconLoader::Load("media-playlist-repeat")));
|
|
|
|
ui_->shuffle->setIcon(AddDesaturatedIcon(IconLoader::Load("media-playlist-shuffle")));
|
|
|
|
|
2010-04-14 16:48:10 +02:00
|
|
|
settings_->set_group(kSettingsGroup);
|
|
|
|
|
2010-03-08 15:08:54 +01:00
|
|
|
QActionGroup* repeat_group = new QActionGroup(this);
|
2010-05-10 23:50:31 +02:00
|
|
|
repeat_group->addAction(ui_->action_repeat_off);
|
|
|
|
repeat_group->addAction(ui_->action_repeat_track);
|
|
|
|
repeat_group->addAction(ui_->action_repeat_album);
|
|
|
|
repeat_group->addAction(ui_->action_repeat_playlist);
|
2010-03-08 15:08:54 +01:00
|
|
|
repeat_menu_->addActions(repeat_group->actions());
|
2010-05-10 23:50:31 +02:00
|
|
|
ui_->repeat->setMenu(repeat_menu_);
|
2010-03-08 15:08:54 +01:00
|
|
|
|
|
|
|
QActionGroup* shuffle_group = new QActionGroup(this);
|
2010-05-10 23:50:31 +02:00
|
|
|
shuffle_group->addAction(ui_->action_shuffle_off);
|
|
|
|
shuffle_group->addAction(ui_->action_shuffle_all);
|
2011-11-27 16:01:10 +01:00
|
|
|
shuffle_group->addAction(ui_->action_shuffle_inside_album);
|
|
|
|
shuffle_group->addAction(ui_->action_shuffle_albums);
|
2010-03-08 15:08:54 +01:00
|
|
|
shuffle_menu_->addActions(shuffle_group->actions());
|
2010-05-10 23:50:31 +02:00
|
|
|
ui_->shuffle->setMenu(shuffle_menu_);
|
2010-03-08 15:08:54 +01:00
|
|
|
|
|
|
|
connect(repeat_group, SIGNAL(triggered(QAction*)), SLOT(RepeatActionTriggered(QAction*)));
|
|
|
|
connect(shuffle_group, SIGNAL(triggered(QAction*)), SLOT(ShuffleActionTriggered(QAction*)));
|
|
|
|
|
|
|
|
Load();
|
|
|
|
}
|
|
|
|
|
2010-05-10 23:50:31 +02:00
|
|
|
PlaylistSequence::~PlaylistSequence() {
|
|
|
|
delete ui_;
|
|
|
|
}
|
|
|
|
|
2010-03-08 19:05:41 +01:00
|
|
|
void PlaylistSequence::Load() {
|
2010-03-08 15:08:54 +01:00
|
|
|
loading_ = true; // Stops these setter functions calling Save()
|
2010-04-14 16:48:10 +02:00
|
|
|
SetShuffleMode(ShuffleMode(settings_->value("shuffle_mode", Shuffle_Off).toInt()));
|
|
|
|
SetRepeatMode(RepeatMode(settings_->value("repeat_mode", Repeat_Off).toInt()));
|
2010-03-08 15:08:54 +01:00
|
|
|
loading_ = false;
|
|
|
|
}
|
|
|
|
|
2010-03-08 19:05:41 +01:00
|
|
|
void PlaylistSequence::Save() {
|
2010-03-08 15:08:54 +01:00
|
|
|
if (loading_) return;
|
|
|
|
|
2010-04-14 16:48:10 +02:00
|
|
|
settings_->setValue("shuffle_mode", shuffle_mode_);
|
|
|
|
settings_->setValue("repeat_mode", repeat_mode_);
|
2010-03-08 15:08:54 +01:00
|
|
|
}
|
|
|
|
|
2010-05-19 17:45:29 +02:00
|
|
|
QIcon PlaylistSequence::AddDesaturatedIcon(const QIcon& icon) {
|
|
|
|
QIcon ret;
|
|
|
|
foreach (const QSize& size, icon.availableSizes()) {
|
|
|
|
QPixmap on(icon.pixmap(size));
|
|
|
|
QPixmap off(DesaturatedPixmap(on));
|
|
|
|
|
|
|
|
ret.addPixmap(off, QIcon::Normal, QIcon::Off);
|
|
|
|
ret.addPixmap(on, QIcon::Normal, QIcon::On);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
QPixmap PlaylistSequence::DesaturatedPixmap(const QPixmap& pixmap) {
|
|
|
|
QPixmap ret(pixmap.size());
|
|
|
|
ret.fill(Qt::transparent);
|
|
|
|
|
|
|
|
QPainter p(&ret);
|
|
|
|
p.setOpacity(0.5);
|
|
|
|
p.drawPixmap(0, 0, pixmap);
|
|
|
|
p.end();
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-03-08 19:05:41 +01:00
|
|
|
void PlaylistSequence::RepeatActionTriggered(QAction* action) {
|
2010-03-08 15:08:54 +01:00
|
|
|
RepeatMode mode = Repeat_Off;
|
2010-05-10 23:50:31 +02:00
|
|
|
if (action == ui_->action_repeat_track) mode = Repeat_Track;
|
|
|
|
if (action == ui_->action_repeat_album) mode = Repeat_Album;
|
|
|
|
if (action == ui_->action_repeat_playlist) mode = Repeat_Playlist;
|
2010-03-08 15:08:54 +01:00
|
|
|
|
|
|
|
SetRepeatMode(mode);
|
|
|
|
}
|
|
|
|
|
2010-03-08 19:05:41 +01:00
|
|
|
void PlaylistSequence::ShuffleActionTriggered(QAction* action) {
|
2010-03-08 15:08:54 +01:00
|
|
|
ShuffleMode mode = Shuffle_Off;
|
2011-11-27 16:01:10 +01:00
|
|
|
if (action == ui_->action_shuffle_all) mode = Shuffle_All;
|
|
|
|
if (action == ui_->action_shuffle_inside_album) mode = Shuffle_InsideAlbum;
|
|
|
|
if (action == ui_->action_shuffle_albums) mode = Shuffle_Albums;
|
2010-03-08 15:08:54 +01:00
|
|
|
|
|
|
|
SetShuffleMode(mode);
|
|
|
|
}
|
|
|
|
|
2010-03-08 19:05:41 +01:00
|
|
|
void PlaylistSequence::SetRepeatMode(RepeatMode mode) {
|
2010-05-10 23:50:31 +02:00
|
|
|
ui_->repeat->setChecked(mode != Repeat_Off);
|
2010-03-08 15:08:54 +01:00
|
|
|
|
|
|
|
switch(mode) {
|
2010-05-10 23:50:31 +02:00
|
|
|
case Repeat_Off: ui_->action_repeat_off->setChecked(true); break;
|
|
|
|
case Repeat_Track: ui_->action_repeat_track->setChecked(true); break;
|
|
|
|
case Repeat_Album: ui_->action_repeat_album->setChecked(true); break;
|
|
|
|
case Repeat_Playlist: ui_->action_repeat_playlist->setChecked(true); break;
|
2010-03-08 15:08:54 +01:00
|
|
|
}
|
|
|
|
|
2010-12-07 22:14:40 +01:00
|
|
|
if (mode != repeat_mode_) {
|
|
|
|
repeat_mode_ = mode;
|
2010-03-08 15:08:54 +01:00
|
|
|
emit RepeatModeChanged(mode);
|
2010-12-07 22:14:40 +01:00
|
|
|
}
|
|
|
|
|
2010-03-08 15:08:54 +01:00
|
|
|
Save();
|
|
|
|
}
|
|
|
|
|
2010-03-08 19:05:41 +01:00
|
|
|
void PlaylistSequence::SetShuffleMode(ShuffleMode mode) {
|
2010-05-10 23:50:31 +02:00
|
|
|
ui_->shuffle->setChecked(mode != Shuffle_Off);
|
2010-03-08 15:08:54 +01:00
|
|
|
|
|
|
|
switch (mode) {
|
2011-11-27 16:01:10 +01:00
|
|
|
case Shuffle_Off: ui_->action_shuffle_off->setChecked(true); break;
|
|
|
|
case Shuffle_All: ui_->action_shuffle_all->setChecked(true); break;
|
|
|
|
case Shuffle_InsideAlbum: ui_->action_shuffle_inside_album->setChecked(true); break;
|
|
|
|
case Shuffle_Albums: ui_->action_shuffle_albums->setChecked(true); break;
|
2010-03-08 15:08:54 +01:00
|
|
|
}
|
|
|
|
|
2010-12-07 22:14:40 +01:00
|
|
|
|
|
|
|
if (mode != shuffle_mode_) {
|
|
|
|
shuffle_mode_ = mode;
|
2010-03-08 15:08:54 +01:00
|
|
|
emit ShuffleModeChanged(mode);
|
2010-12-07 22:14:40 +01:00
|
|
|
}
|
|
|
|
|
2010-03-08 15:08:54 +01:00
|
|
|
Save();
|
|
|
|
}
|
2010-11-20 19:49:54 +01:00
|
|
|
|
|
|
|
void PlaylistSequence::SetUsingDynamicPlaylist(bool dynamic) {
|
|
|
|
dynamic_ = dynamic;
|
|
|
|
const QString not_available(tr("Not available while using a dynamic playlist"));
|
|
|
|
|
|
|
|
setEnabled(!dynamic);
|
|
|
|
ui_->shuffle->setToolTip(dynamic ? not_available : tr("Shuffle"));
|
|
|
|
ui_->repeat->setToolTip(dynamic ? not_available : tr("Repeat"));
|
|
|
|
}
|
|
|
|
|
|
|
|
PlaylistSequence::ShuffleMode PlaylistSequence::shuffle_mode() const {
|
|
|
|
return dynamic_ ? Shuffle_Off : shuffle_mode_;
|
|
|
|
}
|
|
|
|
|
|
|
|
PlaylistSequence::RepeatMode PlaylistSequence::repeat_mode() const {
|
|
|
|
return dynamic_ ? Repeat_Off : repeat_mode_;
|
|
|
|
}
|
2011-03-17 09:21:05 +01:00
|
|
|
|
|
|
|
//called from global shortcut
|
|
|
|
void PlaylistSequence::CycleShuffleMode() {
|
|
|
|
ShuffleMode mode = Shuffle_Off;
|
|
|
|
//we cycle through the shuffle modes
|
|
|
|
switch (shuffle_mode()) {
|
2011-11-27 16:01:10 +01:00
|
|
|
case Shuffle_Off: mode = Shuffle_All; break;
|
|
|
|
case Shuffle_All: mode = Shuffle_InsideAlbum; break;
|
|
|
|
case Shuffle_InsideAlbum: mode = Shuffle_Albums; break;
|
|
|
|
case Shuffle_Albums: break;
|
2011-03-17 09:21:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
SetShuffleMode(mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
//called from global shortcut
|
|
|
|
void PlaylistSequence::CycleRepeatMode() {
|
|
|
|
RepeatMode mode = Repeat_Off;
|
|
|
|
//we cycle through the repeat modes
|
|
|
|
switch (repeat_mode()) {
|
|
|
|
case Repeat_Off: mode = Repeat_Track; break;
|
|
|
|
case Repeat_Track: mode = Repeat_Album; break;
|
|
|
|
case Repeat_Album: mode = Repeat_Playlist; break;
|
|
|
|
case Repeat_Playlist: break;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetRepeatMode(mode);
|
|
|
|
}
|