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