2010-11-23 23:36:00 +01:00
|
|
|
/* This file is part of Clementine.
|
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
|
|
|
|
|
|
|
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-11-24 00:05:42 +01:00
|
|
|
#include "icecastmodel.h"
|
2010-11-23 23:36:00 +01:00
|
|
|
#include "icecastfilterwidget.h"
|
|
|
|
#include "ui_icecastfilterwidget.h"
|
|
|
|
#include "ui/iconloader.h"
|
|
|
|
|
2012-06-27 17:15:10 +02:00
|
|
|
#include <QKeyEvent>
|
2010-11-23 23:36:00 +01:00
|
|
|
#include <QMenu>
|
2010-11-24 22:16:33 +01:00
|
|
|
#include <QSettings>
|
2010-11-24 00:05:42 +01:00
|
|
|
#include <QSignalMapper>
|
2010-11-23 23:36:00 +01:00
|
|
|
|
2010-11-24 22:16:33 +01:00
|
|
|
const char* IcecastFilterWidget::kSettingsGroup = "Icecast";
|
|
|
|
|
2010-11-23 23:36:00 +01:00
|
|
|
IcecastFilterWidget::IcecastFilterWidget(QWidget *parent)
|
|
|
|
: QWidget(parent),
|
2010-11-24 00:05:42 +01:00
|
|
|
ui_(new Ui_IcecastFilterWidget),
|
2011-11-05 20:09:02 +01:00
|
|
|
menu_(new QMenu(tr("Display options"), this)),
|
2010-11-24 00:05:42 +01:00
|
|
|
sort_mode_mapper_(new QSignalMapper(this))
|
2010-11-23 23:36:00 +01:00
|
|
|
{
|
|
|
|
ui_->setupUi(this);
|
|
|
|
|
|
|
|
// Icons
|
|
|
|
ui_->options->setIcon(IconLoader::Load("configure"));
|
|
|
|
|
2010-11-24 00:05:42 +01:00
|
|
|
// Options actions
|
|
|
|
QActionGroup* group = new QActionGroup(this);
|
|
|
|
AddAction(group, ui_->action_sort_genre_popularity, IcecastModel::SortMode_GenreByPopularity);
|
|
|
|
AddAction(group, ui_->action_sort_genre_alphabetically, IcecastModel::SortMode_GenreAlphabetical);
|
|
|
|
AddAction(group, ui_->action_sort_station, IcecastModel::SortMode_StationAlphabetical);
|
2010-11-23 23:36:00 +01:00
|
|
|
|
2010-11-24 00:05:42 +01:00
|
|
|
// Options menu
|
2011-11-05 20:09:02 +01:00
|
|
|
menu_->setIcon(ui_->options->icon());
|
|
|
|
menu_->addActions(group->actions());
|
|
|
|
ui_->options->setMenu(menu_);
|
2010-11-23 23:36:00 +01:00
|
|
|
|
2010-11-24 00:05:42 +01:00
|
|
|
connect(sort_mode_mapper_, SIGNAL(mapped(int)), SLOT(SortModeChanged(int)));
|
2010-11-23 23:36:00 +01:00
|
|
|
}
|
|
|
|
|
2010-11-24 00:05:42 +01:00
|
|
|
void IcecastFilterWidget::AddAction(
|
|
|
|
QActionGroup* group, QAction* action, IcecastModel::SortMode mode) {
|
|
|
|
group->addAction(action);
|
|
|
|
sort_mode_mapper_->setMapping(action, mode);
|
|
|
|
connect(action, SIGNAL(triggered()), sort_mode_mapper_, SLOT(map()));
|
|
|
|
}
|
|
|
|
|
2010-11-23 23:36:00 +01:00
|
|
|
IcecastFilterWidget::~IcecastFilterWidget() {
|
|
|
|
delete ui_;
|
|
|
|
}
|
|
|
|
|
2011-03-13 15:14:16 +01:00
|
|
|
void IcecastFilterWidget::FocusOnFilter(QKeyEvent *event) {
|
|
|
|
ui_->filter->setFocus(Qt::OtherFocusReason);
|
|
|
|
QApplication::sendEvent(ui_->filter, event);
|
|
|
|
}
|
|
|
|
|
2010-11-23 23:36:00 +01:00
|
|
|
void IcecastFilterWidget::SetIcecastModel(IcecastModel* model) {
|
|
|
|
model_ = model;
|
2012-06-27 17:15:10 +02:00
|
|
|
connect(ui_->filter, SIGNAL(textChanged(QString)),
|
2010-11-24 00:05:42 +01:00
|
|
|
model_, SLOT(SetFilterText(QString)));
|
2010-11-24 22:16:33 +01:00
|
|
|
|
|
|
|
// Load settings
|
|
|
|
QSettings s;
|
|
|
|
s.beginGroup(kSettingsGroup);
|
|
|
|
switch (s.value("sort_by", IcecastModel::SortMode_GenreByPopularity).toInt()) {
|
|
|
|
case IcecastModel::SortMode_GenreByPopularity:
|
|
|
|
ui_->action_sort_genre_popularity->trigger();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IcecastModel::SortMode_GenreAlphabetical:
|
|
|
|
ui_->action_sort_genre_alphabetically->trigger();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IcecastModel::SortMode_StationAlphabetical:
|
|
|
|
ui_->action_sort_station->trigger();
|
|
|
|
break;
|
|
|
|
}
|
2010-11-23 23:36:00 +01:00
|
|
|
}
|
|
|
|
|
2010-11-24 00:05:42 +01:00
|
|
|
void IcecastFilterWidget::SortModeChanged(int mode) {
|
|
|
|
model_->SetSortMode(IcecastModel::SortMode(mode));
|
2010-11-24 22:16:33 +01:00
|
|
|
|
|
|
|
QSettings s;
|
|
|
|
s.beginGroup(kSettingsGroup);
|
|
|
|
s.setValue("sort_by", mode);
|
2010-11-24 00:05:42 +01:00
|
|
|
}
|