Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[connectionagent] fix bug when no services are found, send config nee…
…ded signal.

also implement remembering connection state
  • Loading branch information
Lorn Potter committed Apr 25, 2013
1 parent 41dd222 commit 9eeeae1
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 12 deletions.
58 changes: 46 additions & 12 deletions connd/qconnectionmanager.cpp
Expand Up @@ -49,6 +49,11 @@ QConnectionManager::QConnectionManager(QObject *parent) :
currentNotification(0),
askForRoaming(0)
{
qDebug() << Q_FUNC_INFO << netman->state();

// let me control autoconnect
netman->setSessionMode(true);

connectionAdaptor = new ConnAdaptor(this);
QDBusConnection dbus = QDBusConnection::sessionBus();

Expand Down Expand Up @@ -97,11 +102,14 @@ QConnectionManager::QConnectionManager(QObject *parent) :
techPreferenceList << "wifi" << "bluetooth" << "cellular";

updateServicesMap();
currentNetworkState = netman->state();

// let me control autoconnect
netman->setSessionMode(true);
QSettings confFile;
confFile.beginGroup("Connectionagent");
if (confFile.value("connected").toBool()) {
autoConnect();
}

currentNetworkState = netman->state();
}

QConnectionManager::~QConnectionManager()
Expand Down Expand Up @@ -159,6 +167,7 @@ void QConnectionManager::sendUserReply(const QVariantMap &input)

void QConnectionManager::onServiceAdded(const QString &servicePath)
{
qDebug() << Q_FUNC_INFO;
if (!servicesMap.contains(servicePath)) {
updateServicesMap();
}
Expand All @@ -184,6 +193,7 @@ void QConnectionManager::onServiceAdded(const QString &servicePath)

void QConnectionManager::onServiceRemoved(const QString &/*servicePath*/)
{
qDebug() << Q_FUNC_INFO;
updateServicesMap();
}

Expand All @@ -194,6 +204,8 @@ void QConnectionManager::serviceErrorChanged(const QString &error)

void QConnectionManager::serviceStateChanged(const QString &state)
{
qDebug() << Q_FUNC_INFO << state;

NetworkService *service = qobject_cast<NetworkService *>(sender());

if (currentNetworkState == "disconnect") {
Expand All @@ -202,12 +214,14 @@ void QConnectionManager::serviceStateChanged(const QString &state)
if (state == "failure") {
service->requestDisconnect();
service->remove(); //reset this service
okToConnect = true;
}

//auto migrate
if (state == "online" || state == "ready") {
if(!connectedServices.contains(service->path()))
connectedServices.prepend(service->path());
okToConnect = true;
}
//auto migrate
if (state == "idle") {
Expand All @@ -217,12 +231,25 @@ void QConnectionManager::serviceStateChanged(const QString &state)
if (!(currentNetworkState == "online" && state == "association"))
Q_EMIT connectionState(state, service->type());

//todo
// if state == idle && service exists
// do not autoconnect, user probably wanted to disconnect
if (currentNetworkState == "disconnect" && state == "idle"
&& servicesMap.contains(service->path())) {
okToConnect = false;
}/* else {
okToConnect = true;
}*/

currentNetworkState = state;
currentNetworkState = state;
QSettings confFile;
confFile.beginGroup("Connectionagent");
confFile.setValue("connected",currentNetworkState);
}

bool QConnectionManager::autoConnect()
{
qDebug() << Q_FUNC_INFO;
QString selectedService;
uint strength = 0;
QString currentType;
Expand Down Expand Up @@ -274,6 +301,7 @@ void QConnectionManager::connectToType(const QString &type)
netTech.setPowered(true);
}
QStringList servicesList = netman->servicesList(type);
bool needConfig = false;

if (servicesList.isEmpty()) {
if (type == "wifi") {
Expand All @@ -282,11 +310,10 @@ void QConnectionManager::connectToType(const QString &type)
netTech.scan();
} else {
qDebug() << Q_FUNC_INFO << "services list is empty";
onScanFinished();
needConfig = true;
}
} else {
currentType = "";
bool needConfig = false;

Q_FOREACH (const QString path, servicesList) {
// try harder with cell. a favorite is one that has been connected
Expand All @@ -301,16 +328,18 @@ void QConnectionManager::connectToType(const QString &type)
needConfig = true;
}
}
if (needConfig) {
Q_EMIT configurationNeeded(type);
serviceConnect = false;
okToConnect = false;
}
}
if (needConfig) {
Q_EMIT configurationNeeded(type);
serviceConnect = false;
okToConnect = false;
}
}

void QConnectionManager::connectToNetworkService(const QString &servicePath)
{
qDebug() << Q_FUNC_INFO << servicePath;

serviceConnect = true;
NetworkTechnology *tech = netman->getTechnology(servicesMap.value(servicePath)->type());
tech->setIdleTimeout(120);
Expand Down Expand Up @@ -374,6 +403,7 @@ QString QConnectionManager::findBestConnectableService()

void QConnectionManager::connectionHandover(const QString &oldService, const QString &newService)
{
qDebug() << Q_FUNC_INFO;
if (newService.isEmpty())
return;
if (servicesMap.contains(oldService))
Expand All @@ -386,7 +416,8 @@ void QConnectionManager::connectionHandover(const QString &oldService, const QSt

void QConnectionManager::networkStateChanged(const QString &state)
{
if (state == "idle") {
qDebug() << Q_FUNC_INFO << state;
if (state == "idle" && okToConnect) {
//automigrate
QString bestService = findBestConnectableService();

Expand Down Expand Up @@ -416,3 +447,6 @@ void QConnectionManager::setAskRoaming(bool value)
askForRoaming = value;
}

void QConnectionManager::connmanAvailabilityChanged(bool b)
{
}
2 changes: 2 additions & 0 deletions connd/qconnectionmanager.h
Expand Up @@ -106,6 +106,8 @@ private slots:
void networkStateChanged(const QString &state);
void onServiceStrengthChanged(uint);

void connmanAvailabilityChanged(bool b);

};

#endif // QCONNECTIONMANAGER_H

0 comments on commit 9eeeae1

Please sign in to comment.