+ label_ = 0;
+}
+
+bool CallListener::handleConnection()
+{
+ if(!initialized_)
+ {
+ return false;
+ }
+
+ ConnectionManager cm;
+
+ if(cm.isConnected())
+ {
+ closeConnection_ = false;
+ return true;
+ }
+
+ closeConnection_ = true;
+
+ Settings::ConnectionType configType = Settings::instance()->getConnectionType();
+
+ if(configType == Settings::ALWAYS_ASK)
+ {
+ showError(tr("Automatic connecting is not allowed by settings."));
+ return false;
+ }
+
+ showDelayedResult(tr("Connecting..."), BANNER_DELAY);
+
+ ConnectionManager::Connection best;
+
+ ConnectionManager::ConnectionType lookupType = ConnectionManager::NO_TYPE;
+
+ switch(configType)
+ {
+ case Settings::WLAN:
+ lookupType = ConnectionManager::WLAN;
+ break;
+ case Settings::GPRS:
+ lookupType = ConnectionManager::GPRS;
+ break;
+ default:
+ lookupType = ConnectionManager::NO_TYPE;
+ break;
+ }
+
+ int cretries = 0;
+
+ while(cretries < CONNECTION_LOOKUP_RETRIES)
+ {
+ if(!initialized_)
+ {
+ return false;
+ }
+
+ if(cm.getBestConnection(best, lookupType))
+ {
+ break;
+ }
+
+ qDebug() << "No connections found, retrying...";
+
+ cretries++;
+
+ sleep(WAIT_BETWEEN_RETRIES);
+
+ }
+
+ if(cretries >= CONNECTION_LOOKUP_RETRIES)
+ {
+ showError(tr("No available 3G or WLAN networks found."));
+ return false;
+ }
+
+ int retries = 0;
+
+ while(retries < CONNECT_RETRIES)
+ {
+ if(!initialized_)
+ {
+ return false;
+ }
+
+ sleep(WAIT_BETWEEN_RETRIES);
+
+ if(cm.connect(best.id))
+ {
+ break;
+ }
+ else if(cm.error() == ConnectionManager::INVALID_IAP)
+ {
+ showError(tr("Selected access point doesn't exist."));
+ return false;
+ }
+
+ qDebug() << "Unable to connect, retrying...";
+ retries++;
+
+ }
+
+ if(initialized_ && retries >= CONNECT_RETRIES)
+ {
+ showError(tr("Unable to connect to network."));
+ return false;
+ }
+
+ return initialized_;
+}
+
+void CallListener::showError(QString const& msg)
+{
+ qDebug() << "Error: " << msg;
+ box_->setTimeout(ERROR_BANNER_TIMEOUT);
+ showResult(msg);
+}
+
+void CallListener::timerEvent(QTimerEvent* event)
+{
+ Q_UNUSED(event);
+ killTimer(timer_);
+ timer_ = 0;
+}
+
+void CallListener::sleep(int ms)
+{
+ if(timer_)
+ {
+ killTimer(timer_);
+ }
+
+ timer_ = startTimer(ms);
+
+ while(timer_)
+ {
+ QCoreApplication::processEvents(QEventLoop::WaitForMoreEvents);
+ }