bool QConnectionManager::connectToNetworkService(const QString &servicePath) { qDebug() << servicePath << netman->state(); if (!servicesMap.contains(servicePath) || !serviceInProgress.isEmpty()) return false; NetworkTechnology technology; QString type = servicesMap.value(servicePath)->type(); if (type.isEmpty()) return false; technology.setPath(netman->technologyPathForType(type)); if (technology.powered()) { if (servicePath.contains("cellular")) { QOfonoManager oManager; if (!oManager.available()) { qDebug() << "ofono not available."; return false; } if (oManager.modems().count() < 1) return false; QOfonoNetworkRegistration ofonoReg; ofonoReg.setModemPath(oManager.modems().at(0)); if (ofonoReg.status() != "registered" && ofonoReg.status() != "roaming") { //not on any cell network so bail qDebug() << "ofono is not registered yet"; return false; } QOfonoConnectionManager oConnManager; oConnManager.setModemPath(oManager.modems().at(0)); //isCellRoaming if (servicesMap.value(servicePath)->roaming() && !oConnManager.roamingAllowed()) { //roaming and user doesnt want connection while roaming qDebug() << "roaming not allowed"; return false; } requestConnect(servicePath); } else { requestConnect(servicePath); } } return true; }
void QConnectionManager::connectToType(const QString &type) { qDebug() << type; currentType = type; QString techPath = netman->technologyPathForType(type); if (techPath.isEmpty()) { Q_EMIT errorReported("","Type not valid"); return; } NetworkTechnology netTech; netTech.setPath(techPath); if (!netTech.powered()) { // user has indicated they want a connection netTech.setPowered(true); } QStringList servicesList = netman->servicesList(type); bool needConfig = false; if (servicesList.isEmpty()) { if (type == "wifi") { QObject::connect(&netTech,SIGNAL(scanFinished()),this,SLOT(onScanFinished())); netTech.scan(); } else { needConfig = true; // Q_EMIT errorReported("Service not found"); ?? do we want to report an error } } else { currentType = ""; Q_FOREACH (const QString path, servicesList) { // try harder with cell. a favorite is one that has been connected // if there is a context configured but not yet connected, try to connect anyway if (servicesMap.contains(path) && (servicesMap.value(path)->favorite() || servicesMap.value(path)->type() == "cellular")) { connectToNetworkService(path); needConfig = false; return; } else { needConfig = true; } } } if (needConfig) { Q_EMIT configurationNeeded(type); } }
void NetworkManager::getTechnologiesReply(QDBusPendingCallWatcher *call) { Q_ASSERT(call); pr_dbg() << "Got reply with technolgies"; QDBusPendingReply<ConnmanObjectList> reply = *call; if (reply.isError()) { pr_dbg() << "Error getTechnologiesReply:" << reply.error().message(); disconnectFromConnman(); // TODO: set up timer to reconnect in a bit //QTimer::singleShot(10000,this,SLOT(connectToConnman())); } else { ConnmanObjectList lst = reply.value(); ConnmanObject obj; foreach (obj, lst) { // TODO: consider optimizations NetworkTechnology *tech = new NetworkTechnology(obj.objpath.path(), obj.properties, this); m_technologiesCache.insert(tech->type(), tech); pr_dbg() << "Technology: " << tech->type(); pr_dbg() << "\tConnected:" << tech->connected(); pr_dbg() << "\tPowered:" << tech->powered(); } connect(m_manager, SIGNAL(TechnologyAdded(const QDBusObjectPath &, const QVariantMap &)), this, SLOT(technologyAdded(const QDBusObjectPath &, const QVariantMap &))); connect(m_manager, SIGNAL(TechnologyRemoved(const QDBusObjectPath &)), this, SLOT(technologyRemoved(const QDBusObjectPath &))); emit technologiesChanged(); }
void NetworkManager::getTechnologiesReply(QDBusPendingCallWatcher *call) { Q_ASSERT(call); QDBusPendingReply<ConnmanObjectList> reply = *call; if (reply.isError()) { qDebug() << "Error getTechnologiesReply: " << reply.error().message(); disconnectFromConnman(); // TODO: set up timer to reconnect in a bit //QTimer::singleShot(10000,this,SLOT(connectToConnman())); } else { ConnmanObjectList lst = reply.value(); ConnmanObject obj; foreach (obj, lst) { // TODO: consider optimizations NetworkTechnology *tech = new NetworkTechnology(obj.objpath.path(), obj.properties, this); m_technologiesCache.insert(tech->type(), tech); qDebug() << "From NT: " << tech->type() << " " << tech->connected() << " " << tech->powered(); } if (!m_technologiesCache.isEmpty()) { emit technologiesChanged(m_technologiesCache, QStringList()); } }
void QConnectionManager::serviceStateChanged(const QString &state) { NetworkService *service = static_cast<NetworkService *>(sender()); qDebug() << state << service->name(); if (currentNetworkState == "disconnect") { ua->sendConnectReply("Clear"); } if (state == "failure") { serviceInProgress.clear(); Q_EMIT errorReported(service->path(), "Connection failure: "+ service->name()); autoConnect(); } if (currentNetworkState == "configuration" && state == "ready" && netman->state() != "online") { goodConnectTimer->start(); } //manual connection if ((state == "ready" || state == "online") && service->path() != serviceInProgress) { qDebug() << "manual connection of" << service->path() << "detected, enabling auto connect timeout"; lastManuallyConnectedService = service->path(); manualConnnectionTimer.start(); } //auto migrate if (service->path() == serviceInProgress && state == "online") { serviceInProgress.clear(); } //auto migrate if (state == "idle") { if (lastManuallyConnectedService == service->path()) { lastManuallyConnectedService.clear(); manualConnnectionTimer.invalidate(); } if (serviceInProgress == service->path()) serviceInProgress.clear(); previousConnectedService = service->path(); if (service->type() == "ethernet") { //keep this alive NetworkTechnology tech; tech.setPath(netman->technologyPathForService(service->path())); if (tech.powered()) { requestConnect(service->path()); } } else { updateServicesMap(); qDebug() <<"serviceInProgress"<< serviceInProgress; // If a manual connection has recently been detected autoConnect() will do nothing. // Always call autoConnect() here as this state change could be that manual connection // disconnecting. autoConnect(); } } if (!(currentNetworkState == "online" && state == "association")) Q_EMIT connectionState(state, service->type()); currentNetworkState = state; QSettings confFile; confFile.beginGroup("Connectionagent"); confFile.setValue("connected",currentNetworkState); }