CallListener::CallListener(): eniro_(0), connectionManager_(0),
closeConnection_(false), initialized_(false), box_(0), label_(0),
-retries_(-1), site_(Eniro::FI)
+retries_(-1), site_(Eniro::FI), autoconnect_(false)
{
}
SLOT(callTerminate()));
site_ = Eniro::stringToSite(Settings::instance()->get("site"));
+ connectionName_ = Settings::instance()->get("connection");
+ autoconnect_ = (Settings::instance()->get("autoconnect") == "1");
Settings::close();
qDebug() << "Starting...";
showDelayedResult(tr("Searching..."), BANNER_DELAY);
- if(!connectionManager_->isConnected())
+ if(!handleConnection())
{
- connectionManager_->connect();
- closeConnection_ = true;
- }
- else
- {
- closeConnection_ = false;
+ qDebug() << "Unable to connect";
+ return;
}
qDebug() << "Starting to search...";
else
{
timedMessage_ = "";
- message = tr("Search failed:") + " " + eniro_->errorString() + ".";
- showResult(message);
+ showError(tr("Search failed:") + " " + eniro_->errorString() + ".");
}
}
else
box_ = 0;
label_ = 0;
}
+
+bool CallListener::handleConnection()
+{
+ if(!connectionManager_)
+ {
+ qDebug() << "Error: connection manager not initialized";
+ return false;
+ }
+
+ if(connectionManager_->isConnected())
+ {
+ closeConnection_ = false;
+ return true;
+ }
+
+ closeConnection_ = true;
+ int retries = 0;
+
+ if(autoconnect_)
+ {
+ QString conn;
+
+ if(connectionName_.size() != 0 && connectionName_ != "0")
+ {
+ conn = connectionName_;
+ }
+ else
+ {
+ ConnectionManager::Connection best;
+
+ if(!connectionManager_->getBestConnection(best))
+ {
+ showError(tr("No network connections found."));
+ return false;
+ }
+
+ conn = best.id;
+ }
+
+ while(retries < CONNECT_RETRIES)
+ {
+ if(connectionManager_->connect(conn))
+ {
+ break;
+ }
+ else if(connectionManager_->error() == ConnectionManager::INVALID_IAP)
+ {
+ showError(tr("Selected access point doesn't exist."));
+ return false;
+ }
+
+ retries++;
+ }
+ }
+ else
+ {
+ while(retries < CONNECT_RETRIES)
+ {
+ if(connectionManager_->connect())
+ {
+ break;
+ }
+ else
+ {
+ qDebug() << "Automatic connection failed";
+ }
+
+ retries++;
+ }
+ }
+
+ if(retries >= CONNECT_RETRIES)
+ {
+ ConnectionManager::NetworkMode mode = connectionManager_->getNetworkMode();
+
+ if(mode != ConnectionManager::NETWORK_3G &&
+ mode != ConnectionManager::NETWORK_3_5G)
+ {
+ showError(tr("No 3G or WLAN network available."));
+ }
+ else
+ {
+ showError(tr("Unable to connect to network."));
+ }
+
+ return false;
+ }
+
+ return true;
+}
+
+void CallListener::showError(QString const& msg)
+{
+ qDebug() << "Error: " << msg;
+ box_->setTimeout(ERROR_BANNER_TIMEOUT);
+ showResult(msg);
+}