1
/* This file is part of Clementine.
2
Copyright 2010, David Sansome <me@davidsansome.com>
4
Clementine is free software: you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation, either version 3 of the License, or
7
(at your option) any later version.
9
Clementine is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
18
#include "icecastmodel.h"
19
#include "icecastfilterwidget.h"
20
#include "ui_icecastfilterwidget.h"
21
#include "ui/iconloader.h"
22
#include "widgets/maclineedit.h"
26
#include <QSignalMapper>
28
const char* IcecastFilterWidget::kSettingsGroup = "Icecast";
30
IcecastFilterWidget::IcecastFilterWidget(QWidget *parent)
32
ui_(new Ui_IcecastFilterWidget),
33
menu_(new QMenu(tr("Display options"), this)),
34
sort_mode_mapper_(new QSignalMapper(this))
39
ui_->options->setIcon(IconLoader::Load("configure"));
42
QActionGroup* group = new QActionGroup(this);
43
AddAction(group, ui_->action_sort_genre_popularity, IcecastModel::SortMode_GenreByPopularity);
44
AddAction(group, ui_->action_sort_genre_alphabetically, IcecastModel::SortMode_GenreAlphabetical);
45
AddAction(group, ui_->action_sort_station, IcecastModel::SortMode_StationAlphabetical);
48
menu_->setIcon(ui_->options->icon());
49
menu_->addActions(group->actions());
50
ui_->options->setMenu(menu_);
52
connect(sort_mode_mapper_, SIGNAL(mapped(int)), SLOT(SortModeChanged(int)));
56
MacLineEdit* lineedit = new MacLineEdit(this);
57
ui_->horizontalLayout->insertWidget(1, lineedit);
60
filter_ = ui_->filter;
64
void IcecastFilterWidget::AddAction(
65
QActionGroup* group, QAction* action, IcecastModel::SortMode mode) {
66
group->addAction(action);
67
sort_mode_mapper_->setMapping(action, mode);
68
connect(action, SIGNAL(triggered()), sort_mode_mapper_, SLOT(map()));
71
IcecastFilterWidget::~IcecastFilterWidget() {
75
void IcecastFilterWidget::FocusOnFilter(QKeyEvent *event) {
76
ui_->filter->setFocus(Qt::OtherFocusReason);
77
QApplication::sendEvent(ui_->filter, event);
80
void IcecastFilterWidget::SetIcecastModel(IcecastModel* model) {
82
connect(filter_->widget(), SIGNAL(textChanged(QString)),
83
model_, SLOT(SetFilterText(QString)));
87
s.beginGroup(kSettingsGroup);
88
switch (s.value("sort_by", IcecastModel::SortMode_GenreByPopularity).toInt()) {
89
case IcecastModel::SortMode_GenreByPopularity:
90
ui_->action_sort_genre_popularity->trigger();
93
case IcecastModel::SortMode_GenreAlphabetical:
94
ui_->action_sort_genre_alphabetically->trigger();
97
case IcecastModel::SortMode_StationAlphabetical:
98
ui_->action_sort_station->trigger();
103
void IcecastFilterWidget::SortModeChanged(int mode) {
104
model_->SetSortMode(IcecastModel::SortMode(mode));
107
s.beginGroup(kSettingsGroup);
108
s.setValue("sort_by", mode);