blob: c6d474bd1236cef5a2c1219f7877ec9647f0f0b2 [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
Alexander Afanasyev669ea1a2013-11-08 22:25:23 -08008#include "config.h"
Ilya Moiseenko656d52d2013-10-25 14:19:10 -07009#include "network-manager.h"
Ilya Moiseenko656d52d2013-10-25 14:19:10 -070010
11NetworkManager::NetworkManager()
Alexander Afanasyev50bea562013-11-09 20:09:03 -080012 : isAutoconfigRunning(false)
Ilya Moiseenko656d52d2013-10-25 14:19:10 -070013{
14 if (!QDBusConnection::systemBus().isConnected())
15 {
Ilya Moiseenko656d52d2013-10-25 14:19:10 -070016 return;
17 }
18
Ilya Moiseenko69abb972013-11-04 16:02:20 -080019 autoconfigProcess = new QProcess(this);
Ilya Moiseenko393cbdc2013-10-29 00:45:40 -070020 connect(autoconfigProcess,SIGNAL(finished(int)),this,SLOT(autoconfigFinished()));
21 connect(autoconfigProcess, SIGNAL(error(QProcess::ProcessError)), this, SLOT(autoconfigFinished()));
22
Ilya Moiseenko656d52d2013-10-25 14:19:10 -070023 QDBusConnection::systemBus().connect("org.freedesktop.NetworkManager",
24 "/org/freedesktop/NetworkManager",
25 "org.freedesktop.NetworkManager",
26 "StateChanged", this, SLOT(stateChanged(uint)));
27}
28
29void NetworkManager::stateChanged(uint state)
30{
Ilya Moiseenko656d52d2013-10-25 14:19:10 -070031 if(state == NM_STATE_CONNECTED_GLOBAL)
32 autoconfigDaemon();
33}
34
35void NetworkManager::autoconfigDaemon()
36{
Ilya Moiseenko393cbdc2013-10-29 00:45:40 -070037 if(IsAutoconfigRunning())
38 return;
39
Ilya Moiseenko69abb972013-11-04 16:02:20 -080040 isAutoconfigRunning = true;
41
42 if(autoconfigProcess != NULL)
43 autoconfigProcess->start(NDND_AUTOCONFIG_COMMAND);
Ilya Moiseenko393cbdc2013-10-29 00:45:40 -070044}
45
46void NetworkManager::autoconfigFinished()
47{
Ilya Moiseenko393cbdc2013-10-29 00:45:40 -070048 isAutoconfigRunning = false;
49}
50
51bool NetworkManager::IsAutoconfigRunning()
52{
53 return isAutoconfigRunning;
Ilya Moiseenko656d52d2013-10-25 14:19:10 -070054}
Alexander Afanasyeva822b572013-11-04 12:36:34 -080055
56#if WAF
57#include "network-manager.moc"
58#include "network-manager.cpp.moc"
59#endif