CallListener::~CallListener()
{
end();
+ DB::removeDatabase();
}
bool CallListener::begin()
this,
SLOT(callTerminate()));
- findGprsId();
-
qDebug() << "Starting...";
return true;
Source::SearchDetails const& details,
bool error)
{
+ if(closeConnection_)
+ {
+ closeConnection_ = false;
+ ConnectionManager cm;
+ cm.disconnect(true);
+ }
+
// If box is not visible, the call must have been terminated already
if(!initialized_ || !box_->isVisible())
{
retries_ = -1;
currentSearch_ = "";
-
- if(closeConnection_)
- {
- closeConnection_ = false;
- ConnectionManager cm;
- cm.disconnect(true);
- }
}
QString CallListener::createResult(QString const& name, QString const& street, QString const& city)
box_->hide();
}
- if(closeConnection_)
- {
- closeConnection_ = false;
- ConnectionManager cm;
- cm.disconnect(true);
- }
-
searchClose();
-
- if(gprsId_.isEmpty())
- {
- findGprsId();
- }
}
void CallListener::showDelayedResult(QString const& text, int delay)
void CallListener::searchClose()
{
+ if(!initialized_)
+ {
+ return;
+ }
+
initialized_ = false;
qDebug() << "Closing search...";
delete box_;
box_ = 0;
label_ = 0;
+
+ if(closeConnection_)
+ {
+ closeConnection_ = false;
+ ConnectionManager cm;
+ cm.disconnect(true);
+ }
}
bool CallListener::handleConnection()
}
int cretries = 0;
+ int scans = 0;
+ bool found = false;
+ int maxScans = GPRS_SCANS;
- bool tryGprs = (!gprsId_.isEmpty() &&
- (configType == Settings::ANY || configType == Settings::GPRS));
+ if(lookupType != ConnectionManager::GPRS)
+ {
+ maxScans = WLAN_SCANS;
+ }
while(cretries < CONNECTION_LOOKUP_RETRIES)
{
return false;
}
- if(cm.getBestConnection(best, lookupType))
+ if(scans < maxScans)
{
- break;
+ if(cm.getBestConnection(best, lookupType))
+ {
+ found = true;
+ }
+
+ scans++;
}
- // ICD doesn't always find gprs connection during call, so
- // try to use gprs anyway.
- if(tryGprs && is3g())
+ // If there is only gprs connection available,
+ // make sure that we are on 3g network
+ if(found && (best.type != ConnectionManager::GPRS || is3g()))
{
- best.id = gprsId_;
- qDebug() << "Trying gprs";
break;
}
+ if(found)
+ {
+ sleep(WAIT_BETWEEN_RETRIES);
+ }
+
qDebug() << "No connections found, retrying...";
cretries++;
- sleep(WAIT_BETWEEN_RETRIES);
-
}
if(cretries >= CONNECTION_LOOKUP_RETRIES)
return false;
}
+ qDebug() << "Connecting to " << best.name;
+
if(cm.connect(best.id))
{
break;
return false;
}
- sleep(WAIT_BETWEEN_RETRIES);
+ retries++;
qDebug() << "Unable to connect, retrying...";
- retries++;
+
+ if(retries < CONNECT_RETRIES)
+ {
+ sendRetrySignal(best.id, initialized_);
+ }
}
- if(initialized_ && retries >= CONNECT_RETRIES)
+ if(retries >= CONNECT_RETRIES)
{
- showError(tr("Unable to connect to network."));
+ sendRetrySignal(best.id, false);
+
+ if(initialized_)
+ {
+ showError(tr("Unable to connect to network."));
+ }
+
return false;
}
void CallListener::showError(QString const& msg, int timeout)
{
qDebug() << "Error: " << msg;
+
+ if(!initialized_ || !box_)
+ {
+ return;
+ }
+
box_->setTimeout(ERROR_BANNER_TIMEOUT);
if(timeout)
}
}
-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);
- }
-}
-
-void CallListener::findGprsId()
-{
- ConnectionManager cm;
-
- QList<ConnectionManager::Connection> connections;
-
- if(cm.scanConnections(connections, ConnectionManager::GPRS) &&
- connections.size() > 0)
- {
- gprsId_ = connections.at(0).id;
- }
-}
-
bool CallListener::is3g()
{
QDBusMessage msg = QDBusMessage::createMethodCall("com.nokia.phone.net",
uint status = rep.arguments().value(6).toUInt();
- if(status & 0x10) // 3.5G (HSUPA)
+ if(status & 0x10 || status & 0x08)
{
return true;
}
- else if(status & 0x08) // 3G (HSDPA)
+
+ return false;
+}
+
+void CallListener::sendRetrySignal(QString const& iap, bool retry)
+{
+ QDBusMessage msg = QDBusMessage::createSignal("/com/nokia/icd_ui",
+ "com.nokia.icd_ui",
+ "retry");
+
+ QList<QVariant> arguments;
+ arguments.append(QVariant(iap));
+ arguments.append(QVariant(retry));
+ msg.setArguments(arguments);
+
+ QDBusConnection::systemBus().send(msg);
+
+ qDebug() << "Retry signal sent";
+}
+
+void CallListener::timerEvent(QTimerEvent* event)
+{
+ Q_UNUSED(event);
+ killTimer(timer_);
+ timer_ = 0;
+}
+
+void CallListener::sleep(int ms)
+{
+ if(timer_)
{
- return true;
+ killTimer(timer_);
}
- // Something else
- return false;
+ timer_ = startTimer(ms);
+
+ while(timer_)
+ {
+ QCoreApplication::processEvents(QEventLoop::WaitForMoreEvents);
+ }
}