1 #include "settingsdlg.h"
2 #include "advsettingsdlg.h"
3 #include "selectremotedlg.h"
10 #include <QPushButton>
13 #include <QNetworkConfiguration>
16 SettingsDlg::SettingsDlg(QWidget *parent)
20 QSettings settings(this);
21 m_layout = new QVBoxLayout(this);
22 m_btnLayout = new QHBoxLayout();
23 m_remoteNameLayout = new QHBoxLayout();
25 m_advSettingsBtn = new QPushButton(tr("Advanced"), this);
26 m_selectRemoteBtn = new QPushButton(tr("Select remote"), this);
27 m_aboutBtn = new QPushButton(tr("About"), this);
28 m_rateUpBtn = new QPushButton(
29 QIcon(settings.value("rateUpIcon",
30 "/usr/share/icons/hicolor/48x48/hildon/chat_smiley_happy.png").
33 m_rateDownBtn = new QPushButton(
34 QIcon(settings.value("rateDownIcon",
35 "/usr/share/icons/hicolor/48x48/hildon/chat_smiley_sad.png").
38 m_rateUpBtn->setMaximumSize(72, 72);
39 m_rateDownBtn->setMaximumSize(72, 72);
41 m_btnLayout->addWidget(m_advSettingsBtn);
42 m_btnLayout->addWidget(m_selectRemoteBtn);
43 m_btnLayout->addWidget(m_aboutBtn);
45 m_remoteNameLabel = new QLabel(this);
46 m_ratingLabel = new QLabel(this);
47 m_remoteNameLayout->addWidget(m_remoteNameLabel);
48 m_remoteNameLayout->addWidget(m_ratingLabel);
49 m_remoteNameLayout->addWidget(m_rateUpBtn);
50 m_remoteNameLayout->addWidget(m_rateDownBtn);
52 connect(m_advSettingsBtn, SIGNAL(clicked()),
53 this, SLOT(showAdvSettingsDlg()));
54 connect(m_selectRemoteBtn, SIGNAL(clicked()),
55 this, SLOT(showSelectRemoteDlg()));
56 connect(m_aboutBtn, SIGNAL(clicked()),
57 this, SLOT(showAboutDlg()));
58 connect(m_rateUpBtn, SIGNAL(clicked()),
59 this, SLOT(rateUpClicked()));
60 connect(m_rateDownBtn, SIGNAL(clicked()),
61 this, SLOT(rateDownClicked()));
63 m_layout->addLayout(m_remoteNameLayout);
64 m_layout->addLayout(m_btnLayout);
65 this->setLayout(m_layout);
67 QString selectedRemote = settings.value("remoteName", "").toString();
68 if (selectedRemote == "") {
69 m_remoteNameLabel->setText(tr("No remote selected"));
70 enableRateBtns(false);
72 // Create remote by name and update it's info if online
73 m_remote = Remote(selectedRemote);
74 connect(&m_remote, SIGNAL(infoUpdated()),
75 this, SLOT(updateRemoteInfo()));
76 m_remoteNameLabel->setText(selectedRemote);
77 m_netConfMan = new QTM_PREPEND_NAMESPACE(
78 QNetworkConfigurationManager)(this);
79 connect(m_netConfMan, SIGNAL(updateCompleted()),
80 this, SLOT(onNetworkStatusUpdate()));
81 m_netConfMan->updateConfigurations();
82 enableRateBtns(false);
86 SettingsDlg::~SettingsDlg()
88 delete m_advSettingsBtn;
89 delete m_selectRemoteBtn;
93 delete m_remoteNameLabel;
96 delete m_remoteNameLayout;
101 void SettingsDlg::setBusy(bool busy)
103 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, busy);
107 void SettingsDlg::showAdvSettingsDlg()
113 void SettingsDlg::showSelectRemoteDlg()
116 connect(&dlg, SIGNAL(remoteChanged(Remote)),
117 this, SLOT(setRemote(Remote)));
119 onNetworkStatusUpdate();
122 void SettingsDlg::showAboutDlg()
128 void SettingsDlg::setRemote(Remote r)
131 connect(&m_remote, SIGNAL(infoUpdated()),
132 this, SLOT(updateRemoteInfo()));
137 void SettingsDlg::onNetworkStatusUpdate()
139 if (m_netConfMan->isOnline()) {
140 m_remote.updateInfo();
143 m_ratingLabel->setText(tr("Offline"));
148 void SettingsDlg::updateRemoteInfo()
151 m_remoteNameLabel->setText(m_remote.mfg() + " " + m_remote.name());
152 m_ratingLabel->setText(tr("Rating") + ": "
153 + QString::number(m_remote.rating()));
156 void SettingsDlg::rateUpClicked()
159 m_remote.sendRating(Rating::Up);
162 void SettingsDlg::rateDownClicked()
165 m_remote.sendRating(Rating::Down);
168 void SettingsDlg::processRatingSent()
171 enableRateBtns(false);
174 void SettingsDlg::enableRateBtns(bool enable)
176 m_rateUpBtn->setEnabled(enable);
177 m_rateDownBtn->setEnabled(enable);
180 void SettingsDlg::showEvent(QShowEvent *event)
183 QDialog::showEvent(event);