Ilya Moiseenko | 656d52d | 2013-10-25 14:19:10 -0700 | [diff] [blame] | 1 | /* -*- 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 Moiseenko | 656d52d | 2013-10-25 14:19:10 -0700 | [diff] [blame] | 9 | |
| 10 | NetworkManager::NetworkManager() |
| 11 | { |
| 12 | if (!QDBusConnection::systemBus().isConnected()) |
| 13 | { |
Ilya Moiseenko | 656d52d | 2013-10-25 14:19:10 -0700 | [diff] [blame] | 14 | return; |
| 15 | } |
| 16 | |
Ilya Moiseenko | 69abb97 | 2013-11-04 16:02:20 -0800 | [diff] [blame^] | 17 | autoconfigProcess = new QProcess(this); |
Ilya Moiseenko | 393cbdc | 2013-10-29 00:45:40 -0700 | [diff] [blame] | 18 | connect(autoconfigProcess,SIGNAL(finished(int)),this,SLOT(autoconfigFinished())); |
| 19 | connect(autoconfigProcess, SIGNAL(error(QProcess::ProcessError)), this, SLOT(autoconfigFinished())); |
| 20 | |
Ilya Moiseenko | 656d52d | 2013-10-25 14:19:10 -0700 | [diff] [blame] | 21 | QDBusConnection::systemBus().connect("org.freedesktop.NetworkManager", |
| 22 | "/org/freedesktop/NetworkManager", |
| 23 | "org.freedesktop.NetworkManager", |
| 24 | "StateChanged", this, SLOT(stateChanged(uint))); |
| 25 | } |
| 26 | |
| 27 | void NetworkManager::stateChanged(uint state) |
| 28 | { |
Ilya Moiseenko | 656d52d | 2013-10-25 14:19:10 -0700 | [diff] [blame] | 29 | if(state == NM_STATE_CONNECTED_GLOBAL) |
| 30 | autoconfigDaemon(); |
| 31 | } |
| 32 | |
| 33 | void NetworkManager::autoconfigDaemon() |
| 34 | { |
Ilya Moiseenko | 393cbdc | 2013-10-29 00:45:40 -0700 | [diff] [blame] | 35 | if(IsAutoconfigRunning()) |
| 36 | return; |
| 37 | |
Ilya Moiseenko | 69abb97 | 2013-11-04 16:02:20 -0800 | [diff] [blame^] | 38 | isAutoconfigRunning = true; |
| 39 | |
| 40 | if(autoconfigProcess != NULL) |
| 41 | autoconfigProcess->start(NDND_AUTOCONFIG_COMMAND); |
Ilya Moiseenko | 393cbdc | 2013-10-29 00:45:40 -0700 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | void NetworkManager::autoconfigFinished() |
| 45 | { |
Ilya Moiseenko | 393cbdc | 2013-10-29 00:45:40 -0700 | [diff] [blame] | 46 | isAutoconfigRunning = false; |
| 47 | } |
| 48 | |
| 49 | bool NetworkManager::IsAutoconfigRunning() |
| 50 | { |
| 51 | return isAutoconfigRunning; |
Ilya Moiseenko | 656d52d | 2013-10-25 14:19:10 -0700 | [diff] [blame] | 52 | } |
Alexander Afanasyev | a822b57 | 2013-11-04 12:36:34 -0800 | [diff] [blame] | 53 | |
| 54 | #if WAF |
| 55 | #include "network-manager.moc" |
| 56 | #include "network-manager.cpp.moc" |
| 57 | #endif |