PageRenderTime 72ms CodeModel.GetById 30ms app.highlight 7ms RepoModel.GetById 33ms app.codeStats 0ms

/thirdparty/liblastfm2/src/ws/linux/LNetworkConnectionMonitor_linux.cpp

http://github.com/tomahawk-player/tomahawk
C++ | 86 lines | 53 code | 12 blank | 21 comment | 11 complexity | 55835795ca7f12b9d9ef797be2c8a6c0 MD5 | raw file
 1/*
 2   Copyright 2010 Last.fm Ltd.
 3      - Primarily authored by Max Howell, Jono Cole and Doug Mansell
 4
 5   This file is part of liblastfm.
 6
 7   liblastfm is free software: you can redistribute it and/or modify
 8   it under the terms of the GNU General Public License as published by
 9   the Free Software Foundation, either version 3 of the License, or
10   (at your option) any later version.
11
12   liblastfm is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU General Public License for more details.
16
17   You should have received a copy of the GNU General Public License
18   along with liblastfm.  If not, see <http://www.gnu.org/licenses/>.
19*/
20
21
22#include "LNetworkConnectionMonitor.h"
23
24#include <QDBusConnection>
25#include <QDBusInterface>
26#include <QDBusReply>
27
28LNetworkConnectionMonitor::LNetworkConnectionMonitor( QObject* parent ) :
29    NetworkConnectionMonitor( parent )
30{
31    m_nmInterface = new QDBusInterface( QString( "org.freedesktop.NetworkManager" ),
32                                        QString( "/org/freedesktop/NetworkManager" ),
33                                        QString( "org.freedesktop.NetworkManager" ),
34                                        QDBusConnection::systemBus(),
35                                        this );
36
37    //get current connection state
38    QDBusInterface* dbusInterface = new QDBusInterface( QString( "org.freedesktop.NetworkManager" ),
39                                                        QString( "/org/freedesktop/NetworkManager" ),
40                                                        QString( "org.freedesktop.DBus.Properties" ),
41                                                        QDBusConnection::systemBus(),
42                                                        this );
43
44    QDBusReply<QVariant> reply = dbusInterface->call( "Get", "org.freedesktop.NetworkManager", "state" );
45    if ( reply.isValid() )
46    {
47        if ( reply.value() == Connected )
48        {
49            setConnected( true );
50        }
51        else if ( reply.value() == Disconnected )
52        {
53            setConnected( false );
54        }
55    }
56    else
57    {
58        qDebug() << "Error: " << reply.error();
59    }
60    delete dbusInterface;
61
62    //connect network manager signals
63   connect( m_nmInterface, SIGNAL( StateChange( uint ) ), this, SLOT( onStateChange( uint ) ) );
64
65}
66
67LNetworkConnectionMonitor::~LNetworkConnectionMonitor()
68{
69    delete m_nmInterface;
70}
71
72
73void
74LNetworkConnectionMonitor::onStateChange( uint newState )
75{
76    qDebug() << "Networkmanager state change!";
77    
78    if ( newState == Disconnected )
79    {
80       setConnected( false );
81    }
82    else if ( newState == Connected )
83    {
84       setConnected( true );
85    }
86}