Alexander Afanasyev | b6392e3 | 2014-05-12 23:43:50 -0700 | [diff] [blame^] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2013-2014, Regents of the University of California, |
| 4 | * |
| 5 | * This file is part of NFD Control Center. See AUTHORS.md for complete list of NFD |
| 6 | * authors and contributors. |
| 7 | * |
| 8 | * NFD Control Center is free software: you can redistribute it and/or modify it under the |
| 9 | * terms of the GNU General Public License as published by the Free Software Foundation, |
| 10 | * either version 3 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * NFD Control Center is distributed in the hope that it will be useful, but WITHOUT ANY |
| 13 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 14 | * PARTICULAR PURPOSE. See the GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along with NFD |
| 17 | * Control Center, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * \author Ilya Moiseenko <iliamo@ucla.edu> |
| 20 | */ |
| 21 | |
| 22 | #include "network-manager.hpp" |
| 23 | #include "config.hpp" |
| 24 | |
| 25 | NetworkManager::NetworkManager() |
| 26 | : isAutoconfigRunning(false) |
| 27 | { |
| 28 | if (!QDBusConnection::systemBus().isConnected()) |
| 29 | { |
| 30 | return; |
| 31 | } |
| 32 | |
| 33 | autoconfigProcess = new QProcess(this); |
| 34 | connect(autoconfigProcess,SIGNAL(finished(int)),this,SLOT(autoconfigFinished())); |
| 35 | connect(autoconfigProcess, SIGNAL(error(QProcess::ProcessError)), |
| 36 | this, SLOT(autoconfigFinished())); |
| 37 | |
| 38 | QDBusConnection::systemBus().connect("org.freedesktop.NetworkManager", |
| 39 | "/org/freedesktop/NetworkManager", |
| 40 | "org.freedesktop.NetworkManager", |
| 41 | "StateChanged", this, SLOT(stateChanged(uint))); |
| 42 | |
| 43 | QDBusConnection::systemBus().connect("org.freedesktop.UPower", |
| 44 | "/org/freedesktop/UPower", |
| 45 | "org.freedesktop.UPower", |
| 46 | "Resuming", this, SLOT(autoconfigDaemon())); |
| 47 | } |
| 48 | |
| 49 | void NetworkManager::stateChanged(uint state) |
| 50 | { |
| 51 | if (state == NM_STATE_CONNECTED_GLOBAL) |
| 52 | autoconfigDaemon(); |
| 53 | } |
| 54 | |
| 55 | void NetworkManager::autoconfigDaemon() |
| 56 | { |
| 57 | if (IsAutoconfigRunning()) |
| 58 | return; |
| 59 | |
| 60 | isAutoconfigRunning = true; |
| 61 | |
| 62 | if (autoconfigProcess != 0) |
| 63 | autoconfigProcess->start(NFD_AUTOCONFIG_COMMAND); |
| 64 | } |
| 65 | |
| 66 | void NetworkManager::autoconfigFinished() |
| 67 | { |
| 68 | isAutoconfigRunning = false; |
| 69 | } |
| 70 | |
| 71 | bool NetworkManager::IsAutoconfigRunning() |
| 72 | { |
| 73 | return isAutoconfigRunning; |
| 74 | } |
| 75 | |
| 76 | #if WAF |
| 77 | #include "network-manager.moc" |
| 78 | #include "network-manager.cpp.moc" |
| 79 | #endif |