#include <QTcpSocket>
#include <QFuture>
#include <QtConcurrentMap>
+#include "appsettings.h"
+#if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5)
+#include <QMaemo5InformationBox>
+#endif
item->setFont(font);
}
ui->listWidget->addItem(item);
- asycItems.append(*item);
+ if (AppSettings::isConnected()) {
+ asycItems.append(*item);
+ }
}
settings.endGroup();
// QFuture<QListWidgetItem> itemFutur = QtConcurrent::mapped(asycItems, asyncTestItem);
- mFuturWatcher->setFuture(QtConcurrent::mapped(asycItems, asyncTestItem));
+ if (AppSettings::isConnected()) {
+ mFuturWatcher->setFuture(QtConcurrent::mapped(asycItems, asyncTestItem));
+ }
+ else {
+#if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5)
+ QMaemo5InformationBox::information(this, tr("No network connection available!"), QMaemo5InformationBox::DefaultTimeout);
+#endif
+ }
}
QListWidgetItem AccountDialog::asyncTestItem(const QListWidgetItem& item)
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <QStringList>
+#include <QNetworkInterface>
#include "appsettings.h"
AppSettings::AppSettings() {
AppSettings::~AppSettings() {
;
}
+bool AppSettings::isConnected() {
+ QNetworkInterface wlan = QNetworkInterface::interfaceFromName("wlan0");
+ QNetworkInterface gprs = QNetworkInterface::interfaceFromName("gprs0");
+ if( (wlan.isValid() && wlan.flags().testFlag(QNetworkInterface::IsUp)) || (gprs.isValid() && gprs.flags().testFlag(QNetworkInterface::IsUp)) )
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+}
QString AppSettings::getCurrentKey() {
QSettings sets;
return sets.value("config/currentKey", "").toString();
#include "aboutdialog.h"
#include "accountdialog.h"
#include "appsettings.h"
+#if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5)
+#include <QMaemo5InformationBox>
+#endif
PlayerMainWindow::PlayerMainWindow(QWidget *parent) :
QMainWindow(parent),
// check if last used connection is still valid or showConfig
- QSettings settings;
- QString last_ip = AccountDialog::currentIp();
- if (!last_ip.isNull() && !last_ip.isEmpty()) {
- QTcpSocket * socket = new QTcpSocket;
- if(last_ip.contains(":"))
- {
- QStringList hostSplit = last_ip.split(":");
- QString ip = hostSplit.at(0);
- QString port = hostSplit.at(1);
- socket->connectToHost(ip,port.toInt());
- }
- else {
- socket->connectToHost(last_ip,8080);
+
+ // check for network
+ if (AppSettings::isConnected()) {
+ QSettings settings;
+ QString last_ip = AccountDialog::currentIp();
+ if (!last_ip.isNull() && !last_ip.isEmpty()) {
+ QTcpSocket * socket = new QTcpSocket;
+ if(last_ip.contains(":"))
+ {
+ QStringList hostSplit = last_ip.split(":");
+ QString ip = hostSplit.at(0);
+ QString port = hostSplit.at(1);
+ socket->connectToHost(ip,port.toInt());
+ }
+ else {
+ socket->connectToHost(last_ip,8080);
+ }
+ if (!socket->waitForConnected(1000)) {
+ showConfig();
+ }
+ else {
+ mIp= last_ip;
+
+ mPlayListMainWindow->init();
+ mBrowserMainWindow->init();
+ mTimer->start(5000);
+ askStatus();
+ }
+ delete socket;
}
- if (!socket->waitForConnected(1000)) {
- showConfig();
- }
else {
- mIp= last_ip;
-
- mPlayListMainWindow->init();
- mBrowserMainWindow->init();
- mTimer->start(5000);
- askStatus();
+ showConfig();
}
- delete socket;
}
else {
- showConfig();
+#if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5)
+ QMaemo5InformationBox::information(this, tr("Network unavailable!"), QMaemo5InformationBox::DefaultTimeout);
+#endif
+ showConfig();
}
-
-
}
void PlayerMainWindow::showConfig()
{
mTimer->stop();
- AccountDialog * dialog = new AccountDialog;
- dialog->exec();
-
- mIp= AccountDialog::currentIp();
+ // check for network
+ if (AppSettings::isConnected()) {
+ AccountDialog * dialog = new AccountDialog(this);
+ dialog->exec();
- mPlayListMainWindow->init();
- mBrowserMainWindow->init();
- mTimer->start(5000);
- askStatus();
+ mIp= AccountDialog::currentIp();
+
+ mPlayListMainWindow->init();
+ mBrowserMainWindow->init();
+ mTimer->start(5000);
+ askStatus();
+ }
+ else {
+#if defined(Q_WS_S60) || defined(Q_WS_MAEMO_5)
+ QMaemo5InformationBox::information(this, tr("Network unavailable!"), QMaemo5InformationBox::DefaultTimeout);
+#endif
+ QTimer::singleShot(20000, this, SLOT(showConfig()));
+ }
}
void PlayerMainWindow::showAbout()
{
void PlayerMainWindow::askStatus()
{
//qDebug() << "Status requested. at:" << QTime::currentTime().toString("hh::mm:ss");
- QNetworkReply * reply = mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml")));
- connect(reply,SIGNAL(readyRead()),this,SLOT(parseXmlStatus()));
+ if (AppSettings::isConnected()) {
+ QNetworkReply * reply = mNetManager->get(QNetworkRequest(QUrl("http://"+mIp+"/requests/status.xml")));
+ connect(reply,SIGNAL(readyRead()),this,SLOT(parseXmlStatus()));
+ connect(reply,SIGNAL(error(QNetworkReply::NetworkError)),this,SLOT(error(QNetworkReply::NetworkError)));
+ }
+ else {
+ showConfig(); // this will handle stopping and restarting the timer.
+ }
}
void PlayerMainWindow::parseXmlStatus()