blob: e41618671c3fcf34b7e5848b330076a061961023 [file] [log] [blame]
Ilya Moiseenko656d52d2013-10-25 14:19:10 -07001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2/*
3 * @copyright See LICENCE for copyright and license information.
4 *
5 * @author Ilya Moiseenko <iliamo@ucla.edu>
6 */
7
8#include "network-manager.h"
Ilya Moiseenko656d52d2013-10-25 14:19:10 -07009
10NetworkManager::NetworkManager()
11{
12 if (!QDBusConnection::systemBus().isConnected())
13 {
Ilya Moiseenko656d52d2013-10-25 14:19:10 -070014 return;
15 }
16
Ilya Moiseenko69abb972013-11-04 16:02:20 -080017 autoconfigProcess = new QProcess(this);
Ilya Moiseenko393cbdc2013-10-29 00:45:40 -070018 connect(autoconfigProcess,SIGNAL(finished(int)),this,SLOT(autoconfigFinished()));
19 connect(autoconfigProcess, SIGNAL(error(QProcess::ProcessError)), this, SLOT(autoconfigFinished()));
20
Ilya Moiseenko656d52d2013-10-25 14:19:10 -070021 QDBusConnection::systemBus().connect("org.freedesktop.NetworkManager",
22 "/org/freedesktop/NetworkManager",
23 "org.freedesktop.NetworkManager",
24 "StateChanged", this, SLOT(stateChanged(uint)));
25}
26
27void NetworkManager::stateChanged(uint state)
28{
Ilya Moiseenko656d52d2013-10-25 14:19:10 -070029 if(state == NM_STATE_CONNECTED_GLOBAL)
30 autoconfigDaemon();
31}
32
33void NetworkManager::autoconfigDaemon()
34{
Ilya Moiseenko393cbdc2013-10-29 00:45:40 -070035 if(IsAutoconfigRunning())
36 return;
37
Ilya Moiseenko69abb972013-11-04 16:02:20 -080038 isAutoconfigRunning = true;
39
40 if(autoconfigProcess != NULL)
41 autoconfigProcess->start(NDND_AUTOCONFIG_COMMAND);
Ilya Moiseenko393cbdc2013-10-29 00:45:40 -070042}
43
44void NetworkManager::autoconfigFinished()
45{
Ilya Moiseenko393cbdc2013-10-29 00:45:40 -070046 isAutoconfigRunning = false;
47}
48
49bool NetworkManager::IsAutoconfigRunning()
50{
51 return isAutoconfigRunning;
Ilya Moiseenko656d52d2013-10-25 14:19:10 -070052}
Alexander Afanasyeva822b572013-11-04 12:36:34 -080053
54#if WAF
55#include "network-manager.moc"
56#include "network-manager.cpp.moc"
57#endif