X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fsettingsdlg.cpp;h=84c72ea4aa21a08590cc5e3753c099cd122267a4;hb=HEAD;hp=c88da36290346b8dec68ec3fbfee947ade10b57e;hpb=e2743dbaf2c4aec93ffd5453e0eb8efe99be9995;p=irwi diff --git a/src/settingsdlg.cpp b/src/settingsdlg.cpp index c88da36..84c72ea 100644 --- a/src/settingsdlg.cpp +++ b/src/settingsdlg.cpp @@ -10,9 +10,13 @@ #include #include #include +#include +#include SettingsDlg::SettingsDlg(QWidget *parent) : QDialog(parent) + , m_busy(true) + , m_netConfMan(NULL) { QSettings settings(this); m_layout = new QVBoxLayout(this); @@ -23,14 +27,14 @@ SettingsDlg::SettingsDlg(QWidget *parent) m_selectRemoteBtn = new QPushButton(tr("Select remote"), this); m_aboutBtn = new QPushButton(tr("About"), this); m_rateUpBtn = new QPushButton( - QIcon(settings.value("rateUpIcon", - "/usr/share/icons/hicolor/48x48/hildon/chat_smiley_happy.png"). - toString()), + QIcon(settings.value("symbolPath", + "/usr/share/irwi/symbols/"). + toString() + "symbol_thumbs_up.png"), "", this); m_rateDownBtn = new QPushButton( - QIcon(settings.value("rateDownIcon", - "/usr/share/icons/hicolor/48x48/hildon/chat_smiley_sad.png"). - toString()), + QIcon(settings.value("symbolPath", + "/usr/share/irwi/symbols/"). + toString() + "symbol_thumbs_down.png"), "", this); m_rateUpBtn->setMaximumSize(72, 72); m_rateDownBtn->setMaximumSize(72, 72); @@ -61,14 +65,23 @@ SettingsDlg::SettingsDlg(QWidget *parent) m_layout->addLayout(m_btnLayout); this->setLayout(m_layout); - QString selectedRemote = QSettings(this).value("remoteName", "").toString(); - if (selectedRemote == "") { - m_remoteNameLabel->setText("No remote selected"); - enableRateBtns(false); + QString remoteName = settings.value("remoteName", "").toString(); + if (remoteName == "") { + m_remoteNameLabel->setText(tr("No remote selected")); } else { - setRemote(selectedRemote); - setBusy(); + // Create remote by name and update it's info if online + m_remote = Remote(remoteName); + connect(&m_remote, SIGNAL(infoUpdated()), + this, SLOT(updateRemoteInfo())); + m_remoteNameLabel->setText(settings.value("remoteMfg", "").toString() + + " " + remoteName); } + m_netConfMan = new QTM_PREPEND_NAMESPACE( + QNetworkConfigurationManager)(this); + connect(m_netConfMan, SIGNAL(updateCompleted()), + this, SLOT(onNetworkStatusUpdate())); + m_netConfMan->updateConfigurations(); + enableRateBtns(false); } SettingsDlg::~SettingsDlg() @@ -83,18 +96,26 @@ SettingsDlg::~SettingsDlg() delete m_btnLayout; delete m_remoteNameLayout; delete m_layout; + delete m_netConfMan; } void SettingsDlg::setBusy(bool busy) { +#ifdef Q_WS_MAEMO_5 setAttribute(Qt::WA_Maemo5ShowProgressIndicator, busy); - setEnabled(!busy); +#endif + m_busy = busy; } void SettingsDlg::showAdvSettingsDlg() { AdvSettingsDlg dlg; dlg.exec(); + if (QSettings(this).value("remoteName", "").toString() == "") { + m_remoteNameLabel->setText(tr("No remote selected")); + m_ratingLabel->setText(""); + enableRateBtns(false); + } } void SettingsDlg::showSelectRemoteDlg() @@ -102,7 +123,9 @@ void SettingsDlg::showSelectRemoteDlg() SelectRemoteDlg dlg; connect(&dlg, SIGNAL(remoteChanged(Remote)), this, SLOT(setRemote(Remote))); - dlg.exec(); + if (dlg.exec() == QDialog::Rejected) { + onNetworkStatusUpdate(); + } } void SettingsDlg::showAboutDlg() @@ -114,23 +137,25 @@ void SettingsDlg::showAboutDlg() void SettingsDlg::setRemote(Remote r) { m_remote = r; - processRemoteChange(); + connect(&m_remote, SIGNAL(infoUpdated()), + this, SLOT(updateRemoteInfo())); updateRemoteInfo(); + enableRateBtns(); } -void SettingsDlg::setRemote(const QString &name) -{ - setBusy(); - m_remote = Remote(name); - processRemoteChange(); - m_remote.updateInfo(); // request update from server -} - -void SettingsDlg::processRemoteChange() +void SettingsDlg::onNetworkStatusUpdate() { - connect(&m_remote, SIGNAL(infoUpdated()), - this, SLOT(updateRemoteInfo())); - enableRateBtns(); + if (m_netConfMan->isOnline() && + QSettings(this).value("remoteName", "").toString() != "") { + setBusy(); + m_remote.updateInfo(); + enableRateBtns(); + } else if (!m_netConfMan->isOnline()) { + m_ratingLabel->setText(tr("Offline")); + setBusy(false); + } else { + setBusy(false); + } } void SettingsDlg::updateRemoteInfo() @@ -143,20 +168,20 @@ void SettingsDlg::updateRemoteInfo() void SettingsDlg::rateUpClicked() { - m_remote.sendRating(Rating::Up); processRatingSent(); + m_remote.sendRating(Rating::Up); } void SettingsDlg::rateDownClicked() { - m_remote.sendRating(Rating::Down); processRatingSent(); + m_remote.sendRating(Rating::Down); } void SettingsDlg::processRatingSent() { + setBusy(); enableRateBtns(false); - m_remote.updateInfo(); } void SettingsDlg::enableRateBtns(bool enable) @@ -165,4 +190,11 @@ void SettingsDlg::enableRateBtns(bool enable) m_rateDownBtn->setEnabled(enable); } +void SettingsDlg::showEvent(QShowEvent *event) +{ + setBusy(m_busy); + QDialog::showEvent(event); +} + +