~ubuntu-branches/ubuntu/saucy/clementine/saucy

« back to all changes in this revision

Viewing changes to src/internet/icecastfilterwidget.cpp

  • Committer: Package Import Robot
  • Author(s): Thomas PIERSON
  • Date: 2012-01-01 20:43:39 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120101204339-lsb6nndwhfy05sde
Tags: 1.0.1+dfsg-1
New upstream release. (Closes: #653926, #651611, #657391)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of Clementine.
 
2
   Copyright 2010, David Sansome <me@davidsansome.com>
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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/>.
 
16
*/
 
17
 
 
18
#include "icecastmodel.h"
 
19
#include "icecastfilterwidget.h"
 
20
#include "ui_icecastfilterwidget.h"
 
21
#include "ui/iconloader.h"
 
22
#include "widgets/maclineedit.h"
 
23
 
 
24
#include <QMenu>
 
25
#include <QSettings>
 
26
#include <QSignalMapper>
 
27
 
 
28
const char* IcecastFilterWidget::kSettingsGroup = "Icecast";
 
29
 
 
30
IcecastFilterWidget::IcecastFilterWidget(QWidget *parent)
 
31
  : QWidget(parent),
 
32
    ui_(new Ui_IcecastFilterWidget),
 
33
    menu_(new QMenu(tr("Display options"), this)),
 
34
    sort_mode_mapper_(new QSignalMapper(this))
 
35
{
 
36
  ui_->setupUi(this);
 
37
 
 
38
  // Icons
 
39
  ui_->options->setIcon(IconLoader::Load("configure"));
 
40
 
 
41
  // Options actions
 
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);
 
46
 
 
47
  // Options menu
 
48
  menu_->setIcon(ui_->options->icon());
 
49
  menu_->addActions(group->actions());
 
50
  ui_->options->setMenu(menu_);
 
51
 
 
52
  connect(sort_mode_mapper_, SIGNAL(mapped(int)), SLOT(SortModeChanged(int)));
 
53
 
 
54
#ifdef Q_OS_DARWIN
 
55
  delete ui_->filter;
 
56
  MacLineEdit* lineedit = new MacLineEdit(this);
 
57
  ui_->horizontalLayout->insertWidget(1, lineedit);
 
58
  filter_ = lineedit;
 
59
#else
 
60
  filter_ = ui_->filter;
 
61
#endif
 
62
}
 
63
 
 
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()));
 
69
}
 
70
 
 
71
IcecastFilterWidget::~IcecastFilterWidget() {
 
72
  delete ui_;
 
73
}
 
74
 
 
75
void IcecastFilterWidget::FocusOnFilter(QKeyEvent *event) {
 
76
  ui_->filter->setFocus(Qt::OtherFocusReason);
 
77
  QApplication::sendEvent(ui_->filter, event);
 
78
}
 
79
 
 
80
void IcecastFilterWidget::SetIcecastModel(IcecastModel* model) {
 
81
  model_ = model;
 
82
  connect(filter_->widget(), SIGNAL(textChanged(QString)),
 
83
          model_, SLOT(SetFilterText(QString)));
 
84
 
 
85
  // Load settings
 
86
  QSettings s;
 
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();
 
91
      break;
 
92
 
 
93
    case IcecastModel::SortMode_GenreAlphabetical:
 
94
      ui_->action_sort_genre_alphabetically->trigger();
 
95
      break;
 
96
 
 
97
    case IcecastModel::SortMode_StationAlphabetical:
 
98
      ui_->action_sort_station->trigger();
 
99
      break;
 
100
  }
 
101
}
 
102
 
 
103
void IcecastFilterWidget::SortModeChanged(int mode) {
 
104
  model_->SetSortMode(IcecastModel::SortMode(mode));
 
105
 
 
106
  QSettings s;
 
107
  s.beginGroup(kSettingsGroup);
 
108
  s.setValue("sort_by", mode);
 
109
}