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

« back to all changes in this revision

Viewing changes to .pc/remove-references-to-non-dfsg-files.patch/src/ui/settingsdialog.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 "config.h"
19
 
#include "core/backgroundstreams.h"
20
 
#include "core/networkproxyfactory.h"
21
 
#include "iconloader.h"
22
 
#include "mainwindow.h"
23
 
#include "settingsdialog.h"
24
 
#include "engines/enginebase.h"
25
 
#include "engines/gstengine.h"
26
 
#include "playlist/playlistview.h"
27
 
#include "songinfo/songinfofetcher.h"
28
 
#include "songinfo/songinfotextview.h"
29
 
#include "widgets/osd.h"
30
 
#include "widgets/osdpretty.h"
31
 
 
32
 
#include "ui_settingsdialog.h"
33
 
 
34
 
#ifdef HAVE_LIBLASTFM
35
 
# include "radio/lastfmconfig.h"
36
 
#endif
37
 
 
38
 
#ifdef HAVE_WIIMOTEDEV
39
 
# include "ui/wiimotedevshortcutsconfig.h"
40
 
# include "ui_wiimotedevshortcutsconfig.h"
41
 
# include "wiimotedev/shortcuts.h"
42
 
#endif
43
 
 
44
 
#ifdef HAVE_REMOTE
45
 
# include "remote/remoteconfig.h"
46
 
#endif
47
 
 
48
 
#include <QColorDialog>
49
 
#include <QDir>
50
 
#include <QFontDialog>
51
 
#include <QSettings>
52
 
 
53
 
#include <QtDebug>
54
 
 
55
 
void SettingsDialog::AddStream(const QString& name) {
56
 
  QGroupBox* box = new QGroupBox(tr(name.toUtf8()));
57
 
  QSlider* slider = new QSlider(Qt::Horizontal, box);
58
 
  QCheckBox* check = new QCheckBox(box);
59
 
  QHBoxLayout* layout = new QHBoxLayout(box);
60
 
  layout->addWidget(slider);
61
 
  layout->addWidget(check);
62
 
 
63
 
  QVBoxLayout* streams_layout = qobject_cast<QVBoxLayout*>(
64
 
        ui_->streams_page->layout());
65
 
  streams_layout->insertWidget(streams_layout->count() - 1, box);
66
 
 
67
 
  slider->setProperty("stream_name", name);
68
 
  check->setProperty("stream_name", name);
69
 
 
70
 
  connect(slider, SIGNAL(valueChanged(int)), SLOT(StreamVolumeChanged(int)));
71
 
  connect(check, SIGNAL(toggled(bool)), SLOT(EnableStream(bool)));
72
 
 
73
 
  slider->setValue(streams_->GetStreamVolume(name));
74
 
  check->setCheckState(streams_->IsPlaying(name) ? Qt::Checked : Qt::Unchecked);
75
 
}
76
 
 
77
 
void SettingsDialog::EnableStream(bool enabled) {
78
 
  const QString name = sender()->property("stream_name").toString();
79
 
  streams_->EnableStream(name, enabled);
80
 
}
81
 
 
82
 
void SettingsDialog::StreamVolumeChanged(int value) {
83
 
  const QString name = sender()->property("stream_name").toString();
84
 
  streams_->SetStreamVolume(name, value);
85
 
}
86
 
 
87
 
void SettingsDialog::AddStreams() {
88
 
  foreach (const QString& name, streams_->streams()) {
89
 
    AddStream(name);
90
 
  }
91
 
}
92
 
 
93
 
SettingsDialog::SettingsDialog(BackgroundStreams* streams, QWidget* parent)
94
 
  : QDialog(parent),
95
 
    gst_engine_(NULL),
96
 
    ui_(new Ui_SettingsDialog),
97
 
    loading_settings_(false),
98
 
    pretty_popup_(new OSDPretty(OSDPretty::Mode_Draggable)),
99
 
    streams_(streams)
100
 
{
101
 
  ui_->setupUi(this);
102
 
  pretty_popup_->SetMessage(tr("OSD Preview"), tr("Drag to reposition"),
103
 
                            QImage(":nocover.png"));
104
 
 
105
 
#ifdef HAVE_LIBLASTFM
106
 
  ui_->list->insertItem(Page_Lastfm, tr("Last.fm"));
107
 
  ui_->list->item(Page_Lastfm)->setIcon(QIcon(":/last.fm/as.png"));
108
 
 
109
 
  QWidget* lastfm_page = new QWidget;
110
 
  QVBoxLayout* lastfm_layout = new QVBoxLayout;
111
 
  lastfm_layout->setContentsMargins(0, 0, 0, 0);
112
 
  lastfm_config_ = new LastFMConfig;
113
 
  lastfm_layout->addWidget(lastfm_config_);
114
 
  lastfm_page->setLayout(lastfm_layout);
115
 
 
116
 
  ui_->stacked_widget->insertWidget(Page_Lastfm, lastfm_page);
117
 
 
118
 
  connect(lastfm_config_, SIGNAL(ValidationComplete(bool)), SLOT(ValidationComplete(bool)));
119
 
#endif
120
 
 
121
 
#ifdef HAVE_REMOTE
122
 
  ui_->list->insertItem(Page_Remote, tr("Remote Control"));
123
 
  ui_->list->item(Page_Remote)->setIcon(IconLoader::Load("network-server"));
124
 
 
125
 
  QWidget* remote_page = new QWidget;
126
 
  QVBoxLayout* remote_layout = new QVBoxLayout;
127
 
  remote_layout->setContentsMargins(0, 0, 0, 0);
128
 
 
129
 
  remote_config_ = new RemoteConfig;
130
 
  remote_layout->addWidget(remote_config_);
131
 
  remote_page->setLayout(remote_layout);
132
 
 
133
 
  ui_->stacked_widget->insertWidget(Page_Remote, remote_page);
134
 
 
135
 
  connect(remote_config_, SIGNAL(ValidationComplete(bool)), SLOT(ValidationComplete(bool)));
136
 
#endif
137
 
 
138
 
  connect(ui_->magnatune, SIGNAL(ValidationComplete(bool)), SLOT(ValidationComplete(bool)));
139
 
 
140
 
  // Icons
141
 
  ui_->list->item(Page_Playback)->setIcon(IconLoader::Load("media-playback-start"));
142
 
  ui_->list->item(Page_SongInformation)->setIcon(IconLoader::Load("view-media-lyrics"));
143
 
  ui_->list->item(Page_GlobalShortcuts)->setIcon(IconLoader::Load("input-keyboard"));
144
 
  ui_->list->item(Page_Notifications)->setIcon(IconLoader::Load("help-hint"));
145
 
  ui_->list->item(Page_Library)->setIcon(IconLoader::Load("folder-sound"));
146
 
  ui_->list->item(Page_BackgroundStreams)->setIcon(QIcon(":/icons/32x32/weather-showers-scattered.png"));
147
 
  ui_->list->item(Page_Proxy)->setIcon(IconLoader::Load("applications-internet"));
148
 
 
149
 
  AddStreams();
150
 
 
151
 
#ifdef HAVE_WIIMOTEDEV
152
 
  // Wiimotedev page
153
 
  ui_->list->insertItem(Page_Wiimotedev, "Wiimotedev");
154
 
  ui_->list->item(Page_Wiimotedev)->setIcon(QIcon(":/icons/32x32/wiimotedev.png"));
155
 
 
156
 
  QWidget* wiimotedev_page = new QWidget(this);
157
 
  wiimotedev_page->setObjectName(QString::fromUtf8("wiimotedev_page"));
158
 
  QVBoxLayout* wiimotedev_layout = new QVBoxLayout(wiimotedev_page);
159
 
  wiimotedev_layout->setObjectName(QString::fromUtf8("wiimotedev_layout"));
160
 
  wiimotedev_config_ = new WiimotedevShortcutsConfig(wiimotedev_page);
161
 
  wiimotedev_config_->setObjectName(QString::fromUtf8("wiimotedev_config"));
162
 
  wiimotedev_layout->addWidget(wiimotedev_config_);
163
 
 
164
 
  ui_->stacked_widget->addWidget(wiimotedev_page);
165
 
 
166
 
  connect(wiimotedev_config_, SIGNAL(SetWiimotedevInterfaceActived(bool)), this, SIGNAL(SetWiimotedevInterfaceActived(bool)));
167
 
#endif
168
 
 
169
 
  // Playback
170
 
  connect(ui_->fading_cross, SIGNAL(toggled(bool)), SLOT(FadingOptionsChanged()));
171
 
  connect(ui_->fading_out, SIGNAL(toggled(bool)), SLOT(FadingOptionsChanged()));
172
 
  connect(ui_->fading_auto, SIGNAL(toggled(bool)), SLOT(FadingOptionsChanged()));
173
 
  connect(ui_->gst_plugin, SIGNAL(currentIndexChanged(int)), SLOT(GstPluginChanged(int)));
174
 
 
175
 
  connect(ui_->replaygain_preamp, SIGNAL(valueChanged(int)), SLOT(RgPreampChanged(int)));
176
 
  ui_->replaygain_preamp_label->setMinimumWidth(
177
 
      QFontMetrics(ui_->replaygain_preamp_label->font()).width("-WW.W dB"));
178
 
  RgPreampChanged(ui_->replaygain_preamp->value());
179
 
 
180
 
  // Behaviour
181
 
  connect(ui_->b_show_tray_icon_, SIGNAL(toggled(bool)), SLOT(ShowTrayIconToggled(bool)));
182
 
 
183
 
  ui_->doubleclick_addmode->setItemData(0, MainWindow::AddBehaviour_Append);
184
 
  ui_->doubleclick_addmode->setItemData(1, MainWindow::AddBehaviour_Load);
185
 
  ui_->doubleclick_addmode->setItemData(2, MainWindow::AddBehaviour_OpenInNew);
186
 
  ui_->doubleclick_addmode->setItemData(3, MainWindow::AddBehaviour_Enqueue);
187
 
 
188
 
  ui_->doubleclick_playmode->setItemData(0, MainWindow::PlayBehaviour_Never);
189
 
  ui_->doubleclick_playmode->setItemData(1, MainWindow::PlayBehaviour_IfStopped);
190
 
  ui_->doubleclick_playmode->setItemData(2, MainWindow::PlayBehaviour_Always);
191
 
 
192
 
  ui_->menu_playmode->setItemData(0, MainWindow::PlayBehaviour_Never);
193
 
  ui_->menu_playmode->setItemData(1, MainWindow::PlayBehaviour_IfStopped);
194
 
  ui_->menu_playmode->setItemData(2, MainWindow::PlayBehaviour_Always);
195
 
 
196
 
  // Populate the language combo box.  We do this by looking at all the
197
 
  // compiled in translations.
198
 
  QDir dir(":/translations/");
199
 
  QStringList codes(dir.entryList(QStringList() << "*.qm"));
200
 
  QRegExp lang_re("^clementine_(.*).qm$");
201
 
  foreach (const QString& filename, codes) {
202
 
    // The regex captures the "ru" from "clementine_ru.qm"
203
 
    if (!lang_re.exactMatch(filename))
204
 
      continue;
205
 
 
206
 
    QString code = lang_re.cap(1);
207
 
    QString name = QString("%1 (%2)").arg(
208
 
        QLocale::languageToString(QLocale(code).language()), code);
209
 
 
210
 
    language_map_[name] = code;
211
 
  }
212
 
 
213
 
  language_map_["English (en)"] = "en";
214
 
 
215
 
  // Sort the names and show them in the UI
216
 
  QStringList names = language_map_.keys();
217
 
  qStableSort(names);
218
 
  ui_->language->addItems(names);
219
 
 
220
 
  // Song info
221
 
  QFile song_info_preview(":/lumberjacksong.txt");
222
 
  song_info_preview.open(QIODevice::ReadOnly);
223
 
  ui_->song_info_font_preview->setText(QString::fromUtf8(song_info_preview.readAll()));
224
 
 
225
 
  connect(ui_->song_info_font_size, SIGNAL(valueChanged(double)), SLOT(SongInfoFontSizeChanged(double)));
226
 
 
227
 
  // Global shortcuts
228
 
#ifdef Q_OS_MAC
229
 
  if (QSysInfo::MacintoshVersion != QSysInfo::MV_SNOWLEOPARD) {
230
 
    ui_->list->item(Page_GlobalShortcuts)->setFlags(Qt::NoItemFlags);
231
 
  }
232
 
#endif
233
 
 
234
 
  // List box
235
 
  connect(ui_->list, SIGNAL(currentTextChanged(QString)), SLOT(CurrentTextChanged(QString)));
236
 
  ui_->list->setCurrentRow(Page_Playback);
237
 
 
238
 
  // Notifications
239
 
  ui_->notifications_bg_preset->setItemData(0, QColor(OSDPretty::kPresetBlue), Qt::DecorationRole);
240
 
  ui_->notifications_bg_preset->setItemData(1, QColor(OSDPretty::kPresetOrange), Qt::DecorationRole);
241
 
 
242
 
  connect(ui_->notifications_none, SIGNAL(toggled(bool)), SLOT(NotificationTypeChanged()));
243
 
  connect(ui_->notifications_native, SIGNAL(toggled(bool)), SLOT(NotificationTypeChanged()));
244
 
  connect(ui_->notifications_tray, SIGNAL(toggled(bool)), SLOT(NotificationTypeChanged()));
245
 
  connect(ui_->notifications_pretty, SIGNAL(toggled(bool)), SLOT(NotificationTypeChanged()));
246
 
  connect(ui_->notifications_opacity, SIGNAL(valueChanged(int)), SLOT(PrettyOpacityChanged(int)));
247
 
  connect(ui_->notifications_bg_preset, SIGNAL(activated(int)), SLOT(PrettyColorPresetChanged(int)));
248
 
  connect(ui_->notifications_fg_choose, SIGNAL(clicked()), SLOT(ChooseFgColor()));
249
 
 
250
 
  if (!OSD::SupportsNativeNotifications())
251
 
    ui_->notifications_native->setEnabled(false);
252
 
  if (!OSD::SupportsTrayPopups())
253
 
    ui_->notifications_tray->setEnabled(false);
254
 
 
255
 
  connect(ui_->stacked_widget, SIGNAL(currentChanged(int)), SLOT(UpdatePopupVisible()));
256
 
  connect(ui_->notifications_pretty, SIGNAL(toggled(bool)), SLOT(UpdatePopupVisible()));
257
 
 
258
 
  // Make sure the list is big enough to show all the items
259
 
  ui_->list->setMinimumWidth(ui_->list->sizeHintForColumn(0));
260
 
 
261
 
#ifdef Q_OS_DARWIN
262
 
  ui_->b_show_tray_icon_->setEnabled(false);
263
 
  ui_->startup_group_->setEnabled(false);
264
 
#endif
265
 
 
266
 
  ui_->buttonBox->button(QDialogButtonBox::Cancel)->setShortcut(QKeySequence::Close);
267
 
}
268
 
 
269
 
SettingsDialog::~SettingsDialog() {
270
 
  delete pretty_popup_;
271
 
  delete ui_;
272
 
}
273
 
 
274
 
void SettingsDialog::CurrentTextChanged(const QString &text) {
275
 
  ui_->title->setText("<b>" + text + "</b>");
276
 
}
277
 
 
278
 
void SettingsDialog::SetLibraryDirectoryModel(LibraryDirectoryModel* model) {
279
 
  ui_->library_config->SetModel(model);
280
 
}
281
 
 
282
 
void SettingsDialog::SetGlobalShortcutManager(GlobalShortcuts *manager) {
283
 
  ui_->global_shortcuts->SetManager(manager);
284
 
}
285
 
 
286
 
void SettingsDialog::ValidationComplete(bool success) {
287
 
  ui_->buttonBox->setEnabled(true);
288
 
 
289
 
  if (success)
290
 
    accept();
291
 
}
292
 
 
293
 
void SettingsDialog::accept() {
294
 
#ifdef HAVE_LIBLASTFM
295
 
  if (lastfm_config_->NeedsValidation()) {
296
 
    lastfm_config_->Validate();
297
 
    ui_->buttonBox->setEnabled(false);
298
 
    return;
299
 
  } else {
300
 
    lastfm_config_->Save();
301
 
  }
302
 
#endif
303
 
 
304
 
#ifdef HAVE_REMOTE
305
 
  if (remote_config_->NeedsValidation()) {
306
 
    remote_config_->Validate();
307
 
    ui_->buttonBox->setEnabled(false);
308
 
    return;
309
 
  } else {
310
 
    remote_config_->Save();
311
 
  }
312
 
#endif
313
 
 
314
 
  if (ui_->magnatune->NeedsValidation()) {
315
 
    ui_->magnatune->Validate();
316
 
    ui_->buttonBox->setEnabled(false);
317
 
    return;
318
 
  } else {
319
 
    ui_->magnatune->Save();
320
 
  }
321
 
 
322
 
  QSettings s;
323
 
 
324
 
  // Behaviour
325
 
  MainWindow::StartupBehaviour behaviour = MainWindow::Startup_Remember;
326
 
  if (ui_->b_always_hide_->isChecked()) behaviour = MainWindow::Startup_AlwaysHide;
327
 
  if (ui_->b_always_show_->isChecked()) behaviour = MainWindow::Startup_AlwaysShow;
328
 
  if (ui_->b_remember_->isChecked())    behaviour = MainWindow::Startup_Remember;
329
 
 
330
 
  MainWindow::AddBehaviour doubleclick_addmode = MainWindow::AddBehaviour(
331
 
    ui_->doubleclick_addmode->itemData(ui_->doubleclick_addmode->currentIndex()).toInt());
332
 
  MainWindow::PlayBehaviour doubleclick_playmode = MainWindow::PlayBehaviour(
333
 
    ui_->doubleclick_playmode->itemData(ui_->doubleclick_playmode->currentIndex()).toInt());
334
 
  MainWindow::PlayBehaviour menu_playmode = MainWindow::PlayBehaviour(
335
 
    ui_->menu_playmode->itemData(ui_->menu_playmode->currentIndex()).toInt());
336
 
 
337
 
  s.beginGroup(MainWindow::kSettingsGroup);
338
 
  s.setValue("showtray", ui_->b_show_tray_icon_->isChecked());
339
 
  s.setValue("keeprunning", ui_->b_keep_running_->isChecked());
340
 
  s.setValue("startupbehaviour", int(behaviour));
341
 
  s.setValue("doubleclick_addmode", doubleclick_addmode);
342
 
  s.setValue("doubleclick_playmode", doubleclick_playmode);
343
 
  s.setValue("menu_playmode", menu_playmode);
344
 
  s.endGroup();
345
 
 
346
 
  s.beginGroup("General");
347
 
  s.setValue("language", language_map_.contains(ui_->language->currentText()) ?
348
 
             language_map_[ui_->language->currentText()] : QString());
349
 
  s.endGroup();
350
 
 
351
 
  // Playback
352
 
  s.beginGroup(Playlist::kSettingsGroup);
353
 
  s.setValue("glow_effect", ui_->current_glow->isChecked());
354
 
  s.setValue("greyoutdeleted", ui_->b_grey_out_deleted_->isChecked());
355
 
  s.endGroup();
356
 
 
357
 
  s.beginGroup(Engine::Base::kSettingsGroup);
358
 
  s.setValue("FadeoutEnabled", ui_->fading_out->isChecked());
359
 
  s.setValue("FadeoutDuration", ui_->fading_duration->value());
360
 
  s.setValue("CrossfadeEnabled", ui_->fading_cross->isChecked());
361
 
  s.setValue("AutoCrossfadeEnabled", ui_->fading_auto->isChecked());
362
 
  s.setValue("NoCrossfadeSameAlbum", ui_->fading_samealbum->isChecked());
363
 
  s.endGroup();
364
 
 
365
 
  s.beginGroup(GstEngine::kSettingsGroup);
366
 
  s.setValue("sink", ui_->gst_plugin->itemData(ui_->gst_plugin->currentIndex()).toString());
367
 
  s.setValue("device", ui_->gst_device->text());
368
 
  s.setValue("rgenabled", ui_->replaygain->isChecked());
369
 
  s.setValue("rgmode", ui_->replaygain_mode->currentIndex());
370
 
  s.setValue("rgpreamp", float(ui_->replaygain_preamp->value()) / 10 - 15);
371
 
  s.setValue("rgcompression", ui_->replaygain_compression->isChecked());
372
 
  s.setValue("bufferduration", ui_->buffer_duration->value());
373
 
  s.endGroup();
374
 
 
375
 
  // Song info
376
 
  s.beginGroup(SongInfoTextView::kSettingsGroup);
377
 
  s.setValue("font_size", ui_->song_info_font_preview->font().pointSizeF());
378
 
  s.setValue("timeout", ui_->song_info_timeout->value());
379
 
  s.endGroup();
380
 
 
381
 
  ui_->lyric_settings->Save();
382
 
 
383
 
  // Wii remotes
384
 
#ifdef HAVE_WIIMOTEDEV
385
 
  s.beginGroup(WiimotedevShortcuts::kActionsGroup);
386
 
  s.remove("");
387
 
  foreach (const WiimotedevShortcutsConfig::Shortcut& shortcut, wiimotedev_config_->actions_)
388
 
    s.setValue(QString::number(shortcut.button), shortcut.action);
389
 
  s.endGroup();
390
 
 
391
 
  s.beginGroup(WiimotedevShortcuts::kSettingsGroup);
392
 
  s.setValue("first_conf", false);
393
 
  s.setValue("enabled", wiimotedev_config_->ui_->wiimotedev_enable->isChecked());
394
 
  s.setValue("only_when_focused", wiimotedev_config_->ui_->wiimotedev_focus->isChecked());
395
 
  s.setValue("use_active_action", wiimotedev_config_->ui_->wiimotedev_active->isChecked());
396
 
  s.setValue("use_notification", wiimotedev_config_->ui_->wiimotedev_notification->isChecked());
397
 
  s.setValue("device", wiimotedev_config_->ui_->wiimotedev_device->value());
398
 
  s.endGroup();
399
 
#endif
400
 
 
401
 
  // Notifications
402
 
  OSD::Behaviour osd_behaviour = OSD::Disabled;
403
 
  if      (ui_->notifications_none->isChecked())   osd_behaviour = OSD::Disabled;
404
 
  else if (ui_->notifications_native->isChecked()) osd_behaviour = OSD::Native;
405
 
  else if (ui_->notifications_tray->isChecked())   osd_behaviour = OSD::TrayPopup;
406
 
  else if (ui_->notifications_pretty->isChecked()) osd_behaviour = OSD::Pretty;
407
 
 
408
 
  s.beginGroup(OSD::kSettingsGroup);
409
 
  s.setValue("Behaviour", int(osd_behaviour));
410
 
  s.setValue("Timeout", ui_->notifications_duration->value() * 1000);
411
 
  s.setValue("ShowOnVolumeChange", ui_->notifications_volume->isChecked());
412
 
  s.setValue("ShowOnPlayModeChange", ui_->notifications_play_mode->isChecked());
413
 
  s.setValue("ShowArt", ui_->notifications_art->isChecked());
414
 
  s.endGroup();
415
 
 
416
 
  s.beginGroup(OSDPretty::kSettingsGroup);
417
 
  s.setValue("foreground_color", pretty_popup_->foreground_color());
418
 
  s.setValue("background_color", pretty_popup_->background_color());
419
 
  s.setValue("background_opacity", pretty_popup_->background_opacity());
420
 
  s.setValue("popup_display", pretty_popup_->popup_display());
421
 
  s.setValue("popup_pos", pretty_popup_->popup_pos());
422
 
  s.endGroup();
423
 
 
424
 
  // Network proxy
425
 
  NetworkProxyFactory::Mode mode = NetworkProxyFactory::Mode_System;
426
 
  if      (ui_->proxy_direct->isChecked()) mode = NetworkProxyFactory::Mode_Direct;
427
 
  else if (ui_->proxy_system->isChecked()) mode = NetworkProxyFactory::Mode_System;
428
 
  else if (ui_->proxy_manual->isChecked()) mode = NetworkProxyFactory::Mode_Manual;
429
 
 
430
 
  s.beginGroup(NetworkProxyFactory::kSettingsGroup);
431
 
  s.setValue("mode", mode);
432
 
  s.setValue("type", ui_->proxy_type->currentIndex() == 0 ?
433
 
             QNetworkProxy::HttpProxy : QNetworkProxy::Socks5Proxy);
434
 
  s.setValue("hostname", ui_->proxy_hostname->text());
435
 
  s.setValue("port", ui_->proxy_port->value());
436
 
  s.setValue("use_authentication", ui_->proxy_auth->isChecked());
437
 
  s.setValue("username", ui_->proxy_username->text());
438
 
  s.setValue("password", ui_->proxy_password->text());
439
 
  s.endGroup();
440
 
 
441
 
  ui_->library_config->Save();
442
 
  ui_->magnatune->Save();
443
 
  ui_->global_shortcuts->Save();
444
 
 
445
 
  streams_->SaveStreams();
446
 
 
447
 
  QDialog::accept();
448
 
 
449
 
  NetworkProxyFactory::Instance()->ReloadSettings();
450
 
}
451
 
 
452
 
void SettingsDialog::showEvent(QShowEvent*) {
453
 
  QSettings s;
454
 
  loading_settings_ = true;
455
 
 
456
 
  if (ui_->gst_plugin->count() <= 1 && gst_engine_) {
457
 
    GstEngine::PluginDetailsList list = gst_engine_->GetOutputsList();
458
 
 
459
 
    ui_->gst_plugin->setItemData(0, GstEngine::kAutoSink);
460
 
    foreach (const GstEngine::PluginDetails& details, list) {
461
 
      if (details.name == "autoaudiosink")
462
 
        continue;
463
 
 
464
 
      ui_->gst_plugin->addItem(details.long_name, details.name);
465
 
    }
466
 
    ui_->gst_group->setEnabled(true);
467
 
    ui_->replaygain_group->setEnabled(true);
468
 
  }
469
 
 
470
 
  // Behaviour
471
 
  s.beginGroup(MainWindow::kSettingsGroup);
472
 
  ui_->b_show_tray_icon_->setChecked(s.value("showtray", true).toBool());
473
 
  ui_->b_keep_running_->setChecked(s.value("keeprunning",
474
 
      ui_->b_show_tray_icon_->isChecked()).toBool());
475
 
  ui_->doubleclick_addmode->setCurrentIndex(ui_->doubleclick_addmode->findData(
476
 
      s.value("doubleclick_addmode", MainWindow::AddBehaviour_Append).toInt()));
477
 
  ui_->doubleclick_playmode->setCurrentIndex(ui_->doubleclick_playmode->findData(
478
 
      s.value("doubleclick_playmode", MainWindow::PlayBehaviour_IfStopped).toInt()));
479
 
  ui_->menu_playmode->setCurrentIndex(ui_->menu_playmode->findData(
480
 
      s.value("menu_playmode", MainWindow::PlayBehaviour_IfStopped).toInt()));
481
 
 
482
 
  MainWindow::StartupBehaviour behaviour = MainWindow::StartupBehaviour(
483
 
      s.value("startupbehaviour", MainWindow::Startup_Remember).toInt());
484
 
  switch (behaviour) {
485
 
    case MainWindow::Startup_AlwaysHide: ui_->b_always_hide_->setChecked(true); break;
486
 
    case MainWindow::Startup_AlwaysShow: ui_->b_always_show_->setChecked(true); break;
487
 
    case MainWindow::Startup_Remember:   ui_->b_remember_->setChecked(true);    break;
488
 
  }
489
 
  s.endGroup();
490
 
 
491
 
  s.beginGroup("General");
492
 
  QString name = language_map_.key(s.value("language").toString());
493
 
  if (name.isEmpty())
494
 
    ui_->language->setCurrentIndex(0);
495
 
  else
496
 
    ui_->language->setCurrentIndex(ui_->language->findText(name));
497
 
  s.endGroup();
498
 
 
499
 
  // Song Info
500
 
  s.beginGroup(SongInfoTextView::kSettingsGroup);
501
 
  ui_->song_info_font_size->setValue(
502
 
      s.value("font_size", SongInfoTextView::kDefaultFontSize).toReal());
503
 
  ui_->song_info_timeout->setValue(
504
 
      s.value("timeout", SongInfoFetcher::kDefaultTimeoutDuration).toInt());
505
 
  s.endGroup();
506
 
 
507
 
  ui_->lyric_settings->Load();
508
 
 
509
 
  // Last.fm
510
 
#ifdef HAVE_LIBLASTFM
511
 
  lastfm_config_->Load();
512
 
#endif
513
 
 
514
 
#ifdef HAVE_REMOTE
515
 
  remote_config_->Load();
516
 
#endif
517
 
 
518
 
  // Magnatune
519
 
  ui_->magnatune->Load();
520
 
 
521
 
  // Global Shortcuts
522
 
  ui_->global_shortcuts->Load();
523
 
 
524
 
  // Playback
525
 
  s.beginGroup(Playlist::kSettingsGroup);
526
 
  ui_->current_glow->setChecked(s.value("glow_effect", true).toBool());
527
 
  ui_->b_grey_out_deleted_->setChecked(s.value("greyoutdeleted", false).toBool());
528
 
  s.endGroup();
529
 
 
530
 
  s.beginGroup(Engine::Base::kSettingsGroup);
531
 
  ui_->fading_out->setChecked(s.value("FadeoutEnabled", true).toBool());
532
 
  ui_->fading_cross->setChecked(s.value("CrossfadeEnabled", true).toBool());
533
 
  ui_->fading_auto->setChecked(s.value("AutoCrossfadeEnabled", false).toBool());
534
 
  ui_->fading_duration->setValue(s.value("FadeoutDuration", 2000).toInt());
535
 
  ui_->fading_samealbum->setChecked(s.value("NoCrossfadeSameAlbum", true).toBool());
536
 
  s.endGroup();
537
 
 
538
 
  s.beginGroup(GstEngine::kSettingsGroup);
539
 
  QString sink = s.value("sink", GstEngine::kAutoSink).toString();
540
 
  ui_->gst_plugin->setCurrentIndex(0);
541
 
  for (int i=0 ; i<ui_->gst_plugin->count() ; ++i) {
542
 
    if (ui_->gst_plugin->itemData(i).toString() == sink) {
543
 
      ui_->gst_plugin->setCurrentIndex(i);
544
 
      break;
545
 
    }
546
 
  }
547
 
  ui_->gst_device->setText(s.value("device").toString());
548
 
  ui_->replaygain->setChecked(s.value("rgenabled", false).toBool());
549
 
  ui_->replaygain_mode->setCurrentIndex(s.value("rgmode", 0).toInt());
550
 
  ui_->replaygain_preamp->setValue(s.value("rgpreamp", 0.0).toDouble() * 10 + 150);
551
 
  ui_->replaygain_compression->setChecked(s.value("rgcompression", true).toBool());
552
 
  ui_->buffer_duration->setValue(s.value("bufferduration", 1000).toInt());
553
 
  s.endGroup();
554
 
 
555
 
  // Notifications
556
 
  s.beginGroup(OSD::kSettingsGroup);
557
 
  OSD::Behaviour osd_behaviour = OSD::Behaviour(s.value("Behaviour", OSD::Native).toInt());
558
 
  switch (osd_behaviour) {
559
 
    case OSD::Native:
560
 
      if (OSD::SupportsNativeNotifications()) {
561
 
        ui_->notifications_native->setChecked(true);
562
 
        break;
563
 
      }
564
 
      // Fallthrough
565
 
 
566
 
    case OSD::Pretty:
567
 
      ui_->notifications_pretty->setChecked(true);
568
 
      break;
569
 
 
570
 
    case OSD::TrayPopup:
571
 
      if (OSD::SupportsTrayPopups()) {
572
 
        ui_->notifications_tray->setChecked(true);
573
 
        break;
574
 
      }
575
 
      // Fallthrough
576
 
 
577
 
    case OSD::Disabled:
578
 
    default:
579
 
      ui_->notifications_none->setChecked(true);
580
 
      break;
581
 
  }
582
 
  ui_->notifications_duration->setValue(s.value("Timeout", 5000).toInt() / 1000);
583
 
  ui_->notifications_volume->setChecked(s.value("ShowOnVolumeChange", false).toBool());
584
 
  ui_->notifications_play_mode->setChecked(s.value("ShowOnPlayModeChange", true).toBool());
585
 
  ui_->notifications_art->setChecked(s.value("ShowArt", true).toBool());
586
 
  s.endGroup();
587
 
 
588
 
  // Pretty OSD
589
 
  pretty_popup_->ReloadSettings();
590
 
  ui_->notifications_opacity->setValue(pretty_popup_->background_opacity() * 100);
591
 
 
592
 
  QRgb color = pretty_popup_->background_color();
593
 
  if (color == OSDPretty::kPresetBlue)
594
 
    ui_->notifications_bg_preset->setCurrentIndex(0);
595
 
  else if (color == OSDPretty::kPresetOrange)
596
 
    ui_->notifications_bg_preset->setCurrentIndex(1);
597
 
  else
598
 
    ui_->notifications_bg_preset->setCurrentIndex(2);
599
 
  ui_->notifications_bg_preset->setItemData(2, QColor(color), Qt::DecorationRole);
600
 
  UpdatePopupVisible();
601
 
 
602
 
  ui_->library_config->Load();
603
 
 
604
 
  // Network proxy
605
 
  s.beginGroup(NetworkProxyFactory::kSettingsGroup);
606
 
  NetworkProxyFactory::Mode mode = NetworkProxyFactory::Mode(
607
 
      s.value("mode", NetworkProxyFactory::Mode_System).toInt());
608
 
  switch (mode) {
609
 
  case NetworkProxyFactory::Mode_Manual:
610
 
    ui_->proxy_manual->setChecked(true);
611
 
    break;
612
 
 
613
 
  case NetworkProxyFactory::Mode_Direct:
614
 
    ui_->proxy_direct->setChecked(true);
615
 
    break;
616
 
 
617
 
  case NetworkProxyFactory::Mode_System:
618
 
  default:
619
 
    ui_->proxy_system->setChecked(true);
620
 
    break;
621
 
  }
622
 
 
623
 
  ui_->proxy_type->setCurrentIndex(s.value("type", QNetworkProxy::HttpProxy)
624
 
      .toInt() == QNetworkProxy::HttpProxy ? 0 : 1);
625
 
  ui_->proxy_hostname->setText(s.value("hostname").toString());
626
 
  ui_->proxy_port->setValue(s.value("port").toInt());
627
 
  ui_->proxy_auth->setChecked(s.value("use_authentication", false).toBool());
628
 
  ui_->proxy_username->setText(s.value("username").toString());
629
 
  ui_->proxy_password->setText(s.value("password").toString());
630
 
  s.endGroup();
631
 
 
632
 
  loading_settings_ = false;
633
 
}
634
 
 
635
 
void SettingsDialog::hideEvent(QHideEvent *) {
636
 
  pretty_popup_->hide();
637
 
}
638
 
 
639
 
void SettingsDialog::NotificationTypeChanged() {
640
 
  bool enabled = !ui_->notifications_none->isChecked();
641
 
  bool pretty = ui_->notifications_pretty->isChecked();
642
 
 
643
 
  ui_->notifications_general->setEnabled(enabled);
644
 
  ui_->notifications_pretty_group->setEnabled(pretty);
645
 
}
646
 
 
647
 
void SettingsDialog::PrettyOpacityChanged(int value) {
648
 
  pretty_popup_->set_background_opacity(qreal(value) / 100.0);
649
 
}
650
 
 
651
 
void SettingsDialog::UpdatePopupVisible() {
652
 
  pretty_popup_->setVisible(
653
 
      isVisible() &&
654
 
      ui_->notifications_pretty->isChecked() &&
655
 
      ui_->stacked_widget->currentWidget() == ui_->notifications_page);
656
 
}
657
 
 
658
 
void SettingsDialog::PrettyColorPresetChanged(int index) {
659
 
  if (loading_settings_)
660
 
    return;
661
 
 
662
 
  switch (index) {
663
 
  case 0:
664
 
    pretty_popup_->set_background_color(OSDPretty::kPresetBlue);
665
 
    break;
666
 
 
667
 
  case 1:
668
 
    pretty_popup_->set_background_color(OSDPretty::kPresetOrange);
669
 
    break;
670
 
 
671
 
  case 2:
672
 
  default:
673
 
    ChooseBgColor();
674
 
    break;
675
 
  }
676
 
}
677
 
 
678
 
void SettingsDialog::ChooseBgColor() {
679
 
  QColor color = QColorDialog::getColor(pretty_popup_->background_color(), this);
680
 
  if (!color.isValid())
681
 
    return;
682
 
 
683
 
  pretty_popup_->set_background_color(color.rgb());
684
 
  ui_->notifications_bg_preset->setItemData(2, color, Qt::DecorationRole);
685
 
}
686
 
 
687
 
void SettingsDialog::ChooseFgColor() {
688
 
  QColor color = QColorDialog::getColor(pretty_popup_->foreground_color(), this);
689
 
  if (!color.isValid())
690
 
    return;
691
 
 
692
 
  pretty_popup_->set_foreground_color(color.rgb());
693
 
}
694
 
 
695
 
void SettingsDialog::ShowTrayIconToggled(bool on) {
696
 
  ui_->b_always_hide_->setEnabled(on);
697
 
  if (!on && ui_->b_always_hide_->isChecked())
698
 
    ui_->b_remember_->setChecked(true);
699
 
}
700
 
 
701
 
void SettingsDialog::GstPluginChanged(int index) {
702
 
  QString name = ui_->gst_plugin->itemData(index).toString();
703
 
 
704
 
  bool enabled = GstEngine::DoesThisSinkSupportChangingTheOutputDeviceToAUserEditableString(name);
705
 
 
706
 
  ui_->gst_device->setEnabled(enabled);
707
 
  ui_->gst_device_label->setEnabled(enabled);
708
 
}
709
 
 
710
 
void SettingsDialog::RgPreampChanged(int value) {
711
 
  float db = float(value) / 10 - 15;
712
 
  QString db_str;
713
 
  db_str.sprintf("%+.1f dB", db);
714
 
  ui_->replaygain_preamp_label->setText(db_str);
715
 
}
716
 
 
717
 
void SettingsDialog::FadingOptionsChanged() {
718
 
  ui_->fading_options->setEnabled(
719
 
      ui_->fading_out->isChecked() || ui_->fading_cross->isChecked() ||
720
 
      ui_->fading_auto->isChecked());
721
 
}
722
 
 
723
 
void SettingsDialog::OpenAtPage(Page page) {
724
 
  ui_->list->setCurrentRow(page);
725
 
  show();
726
 
}
727
 
 
728
 
void SettingsDialog::SetSongInfoView(SongInfoView* view) {
729
 
  ui_->lyric_settings->SetSongInfoView(view);
730
 
}
731
 
 
732
 
void SettingsDialog::SongInfoFontSizeChanged(double value) {
733
 
  QFont font;
734
 
  font.setPointSizeF(value);
735
 
 
736
 
  ui_->song_info_font_preview->setFont(font);
737
 
}