1 #include "settingsdlg.h"
2 #include "advsettingsdlg.h"
3 #include "selectremotedlg.h"
10 #include <QPushButton>
14 SettingsDlg::SettingsDlg(QWidget *parent)
17 QSettings settings(this);
18 m_layout = new QVBoxLayout(this);
19 m_btnLayout = new QHBoxLayout();
20 m_remoteNameLayout = new QHBoxLayout();
22 m_advSettingsBtn = new QPushButton(tr("Advanced"), this);
23 m_selectRemoteBtn = new QPushButton(tr("Select remote"), this);
24 m_aboutBtn = new QPushButton(tr("About"), this);
25 m_rateUpBtn = new QPushButton(
26 QIcon(settings.value("rateUpIcon",
27 "/usr/share/icons/hicolor/48x48/hildon/chat_smiley_happy.png").
30 m_rateDownBtn = new QPushButton(
31 QIcon(settings.value("rateDownIcon",
32 "/usr/share/icons/hicolor/48x48/hildon/chat_smiley_sad.png").
35 m_rateUpBtn->setMaximumSize(72, 72);
36 m_rateDownBtn->setMaximumSize(72, 72);
38 m_btnLayout->addWidget(m_advSettingsBtn);
39 m_btnLayout->addWidget(m_selectRemoteBtn);
40 m_btnLayout->addWidget(m_aboutBtn);
42 m_remoteNameLabel = new QLabel(this);
43 m_ratingLabel = new QLabel(this);
44 m_remoteNameLayout->addWidget(m_remoteNameLabel);
45 m_remoteNameLayout->addWidget(m_ratingLabel);
46 m_remoteNameLayout->addWidget(m_rateUpBtn);
47 m_remoteNameLayout->addWidget(m_rateDownBtn);
49 connect(m_advSettingsBtn, SIGNAL(clicked()),
50 this, SLOT(showAdvSettingsDlg()));
51 connect(m_selectRemoteBtn, SIGNAL(clicked()),
52 this, SLOT(showSelectRemoteDlg()));
53 connect(m_aboutBtn, SIGNAL(clicked()),
54 this, SLOT(showAboutDlg()));
55 connect(m_rateUpBtn, SIGNAL(clicked()),
56 this, SLOT(rateUpClicked()));
57 connect(m_rateDownBtn, SIGNAL(clicked()),
58 this, SLOT(rateDownClicked()));
60 m_layout->addLayout(m_remoteNameLayout);
61 m_layout->addLayout(m_btnLayout);
62 this->setLayout(m_layout);
64 QString selectedRemote = QSettings(this).value("remoteName", "").toString();
65 if (selectedRemote == "") {
66 m_remoteNameLabel->setText("No remote selected");
67 enableRateBtns(false);
69 setRemote(selectedRemote);
74 SettingsDlg::~SettingsDlg()
76 delete m_advSettingsBtn;
77 delete m_selectRemoteBtn;
81 delete m_remoteNameLabel;
84 delete m_remoteNameLayout;
88 void SettingsDlg::setBusy(bool busy)
90 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, busy);
94 void SettingsDlg::showAdvSettingsDlg()
100 void SettingsDlg::showSelectRemoteDlg()
103 connect(&dlg, SIGNAL(remoteChanged(Remote)),
104 this, SLOT(setRemote(Remote)));
108 void SettingsDlg::showAboutDlg()
114 void SettingsDlg::setRemote(Remote r)
117 processRemoteChange();
121 void SettingsDlg::setRemote(const QString &name)
124 m_remote = Remote(name);
125 processRemoteChange();
126 m_remote.updateInfo(); // request update from server
129 void SettingsDlg::processRemoteChange()
131 connect(&m_remote, SIGNAL(infoUpdated()),
132 this, SLOT(updateRemoteInfo()));
136 void SettingsDlg::updateRemoteInfo()
139 m_remoteNameLabel->setText(m_remote.mfg() + " " + m_remote.name());
140 m_ratingLabel->setText(tr("Rating") + ": "
141 + QString::number(m_remote.rating()));
144 void SettingsDlg::rateUpClicked()
146 m_remote.sendRating(Rating::Up);
150 void SettingsDlg::rateDownClicked()
152 m_remote.sendRating(Rating::Down);
156 void SettingsDlg::processRatingSent()
158 enableRateBtns(false);
159 m_remote.updateInfo();
162 void SettingsDlg::enableRateBtns(bool enable)
164 m_rateUpBtn->setEnabled(enable);
165 m_rateDownBtn->setEnabled(enable);