1 #include "settingsdlg.h"
2 #include "advsettingsdlg.h"
3 #include "selectremotedlg.h"
10 #include <QPushButton>
13 #include <QNetworkConfiguration>
15 SettingsDlg::SettingsDlg(QWidget *parent)
18 QSettings settings(this);
19 m_layout = new QVBoxLayout(this);
20 m_btnLayout = new QHBoxLayout();
21 m_remoteNameLayout = new QHBoxLayout();
23 m_advSettingsBtn = new QPushButton(tr("Advanced"), this);
24 m_selectRemoteBtn = new QPushButton(tr("Select remote"), this);
25 m_aboutBtn = new QPushButton(tr("About"), this);
26 m_rateUpBtn = new QPushButton(
27 QIcon(settings.value("rateUpIcon",
28 "/usr/share/icons/hicolor/48x48/hildon/chat_smiley_happy.png").
31 m_rateDownBtn = new QPushButton(
32 QIcon(settings.value("rateDownIcon",
33 "/usr/share/icons/hicolor/48x48/hildon/chat_smiley_sad.png").
36 m_rateUpBtn->setMaximumSize(72, 72);
37 m_rateDownBtn->setMaximumSize(72, 72);
39 m_btnLayout->addWidget(m_advSettingsBtn);
40 m_btnLayout->addWidget(m_selectRemoteBtn);
41 m_btnLayout->addWidget(m_aboutBtn);
43 m_remoteNameLabel = new QLabel(this);
44 m_ratingLabel = new QLabel(this);
45 m_remoteNameLayout->addWidget(m_remoteNameLabel);
46 m_remoteNameLayout->addWidget(m_ratingLabel);
47 m_remoteNameLayout->addWidget(m_rateUpBtn);
48 m_remoteNameLayout->addWidget(m_rateDownBtn);
50 connect(m_advSettingsBtn, SIGNAL(clicked()),
51 this, SLOT(showAdvSettingsDlg()));
52 connect(m_selectRemoteBtn, SIGNAL(clicked()),
53 this, SLOT(showSelectRemoteDlg()));
54 connect(m_aboutBtn, SIGNAL(clicked()),
55 this, SLOT(showAboutDlg()));
56 connect(m_rateUpBtn, SIGNAL(clicked()),
57 this, SLOT(rateUpClicked()));
58 connect(m_rateDownBtn, SIGNAL(clicked()),
59 this, SLOT(rateDownClicked()));
61 m_layout->addLayout(m_remoteNameLayout);
62 m_layout->addLayout(m_btnLayout);
63 this->setLayout(m_layout);
65 QString selectedRemote = settings.value("remoteName", "").toString();
66 if (selectedRemote == "") {
67 m_remoteNameLabel->setText(tr("No remote selected"));
68 enableRateBtns(false);
70 // Create remote by name and update it's info if online
71 m_remote = Remote(selectedRemote);
72 m_remoteNameLabel->setText(selectedRemote);
73 m_netConfMan = new QTM_PREPEND_NAMESPACE(
74 QNetworkConfigurationManager)(this);
75 connect(m_netConfMan, SIGNAL(updateCompleted()),
76 this, SLOT(onNetworkStatusUpdate()));
77 m_netConfMan->updateConfigurations();
78 enableRateBtns(false);
82 SettingsDlg::~SettingsDlg()
84 delete m_advSettingsBtn;
85 delete m_selectRemoteBtn;
89 delete m_remoteNameLabel;
92 delete m_remoteNameLayout;
97 void SettingsDlg::setBusy(bool busy)
99 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, busy);
103 void SettingsDlg::showAdvSettingsDlg()
109 void SettingsDlg::showSelectRemoteDlg()
112 connect(&dlg, SIGNAL(remoteChanged(Remote)),
113 this, SLOT(setRemote(Remote)));
115 onNetworkStatusUpdate();
118 void SettingsDlg::showAboutDlg()
124 void SettingsDlg::setRemote(Remote r)
131 void SettingsDlg::onNetworkStatusUpdate()
133 if (m_netConfMan->isOnline()) {
135 connect(&m_remote, SIGNAL(infoUpdated()),
136 this, SLOT(updateRemoteInfo()));
137 m_remote.updateInfo();
140 m_ratingLabel->setText(tr("Offline"));
144 void SettingsDlg::updateRemoteInfo()
147 m_remoteNameLabel->setText(m_remote.mfg() + " " + m_remote.name());
148 m_ratingLabel->setText(tr("Rating") + ": "
149 + QString::number(m_remote.rating()));
152 void SettingsDlg::rateUpClicked()
154 m_remote.sendRating(Rating::Up);
158 void SettingsDlg::rateDownClicked()
160 m_remote.sendRating(Rating::Down);
164 void SettingsDlg::processRatingSent()
166 enableRateBtns(false);
167 m_remote.updateInfo();
170 void SettingsDlg::enableRateBtns(bool enable)
172 m_rateUpBtn->setEnabled(enable);
173 m_rateDownBtn->setEnabled(enable);