blob: 4f552b640f5bd299860a246c0dae71562d0c9c80 [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()
12{
13 if (!QDBusConnection::systemBus().isConnected())
14 {
Ilya Moiseenko656d52d2013-10-25 14:19:10 -070015 return;
16 }
17
Ilya Moiseenko69abb972013-11-04 16:02:20 -080018 autoconfigProcess = new QProcess(this);
Ilya Moiseenko393cbdc2013-10-29 00:45:40 -070019 connect(autoconfigProcess,SIGNAL(finished(int)),this,SLOT(autoconfigFinished()));
20 connect(autoconfigProcess, SIGNAL(error(QProcess::ProcessError)), this, SLOT(autoconfigFinished()));
21
Ilya Moiseenko656d52d2013-10-25 14:19:10 -070022 QDBusConnection::systemBus().connect("org.freedesktop.NetworkManager",
23 "/org/freedesktop/NetworkManager",
24 "org.freedesktop.NetworkManager",
25 "StateChanged", this, SLOT(stateChanged(uint)));
26}
27
28void NetworkManager::stateChanged(uint state)
29{
Ilya Moiseenko656d52d2013-10-25 14:19:10 -070030 if(state == NM_STATE_CONNECTED_GLOBAL)
31 autoconfigDaemon();
32}
33
34void NetworkManager::autoconfigDaemon()
35{
Ilya Moiseenko393cbdc2013-10-29 00:45:40 -070036 if(IsAutoconfigRunning())
37 return;
38
Ilya Moiseenko69abb972013-11-04 16:02:20 -080039 isAutoconfigRunning = true;
40
41 if(autoconfigProcess != NULL)
42 autoconfigProcess->start(NDND_AUTOCONFIG_COMMAND);
Ilya Moiseenko393cbdc2013-10-29 00:45:40 -070043}
44
45void NetworkManager::autoconfigFinished()
46{
Ilya Moiseenko393cbdc2013-10-29 00:45:40 -070047 isAutoconfigRunning = false;
48}
49
50bool NetworkManager::IsAutoconfigRunning()
51{
52 return isAutoconfigRunning;
Ilya Moiseenko656d52d2013-10-25 14:19:10 -070053}
Alexander Afanasyeva822b572013-11-04 12:36:34 -080054
55#if WAF
56#include "network-manager.moc"
57#include "network-manager.cpp.moc"
58#endif