PageRenderTime 102ms CodeModel.GetById 40ms app.highlight 3ms RepoModel.GetById 57ms app.codeStats 0ms

/thirdparty/liblastfm2/src/ws/InternetConnectionMonitor.h

http://github.com/tomahawk-player/tomahawk
C++ Header | 80 lines | 39 code | 16 blank | 25 comment | 0 complexity | 624b62add8129495bb5e8787c848d47d MD5 | raw file
 1/*
 2   Copyright 2009 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#ifndef LASTFM_CONNECTION_MONITOR_H
22#define LASTFM_CONNECTION_MONITOR_H
23
24#include <lastfm/global.h>
25#include <QObject>
26
27class NetworkConnectionMonitor;
28
29#ifdef Q_WS_X11
30class LNetworkConnectionMonitor;
31#endif
32
33namespace lastfm {
34
35class LASTFM_DLLEXPORT InternetConnectionMonitor : public QObject
36{
37    Q_OBJECT
38    enum NMState
39    {
40        Unknown,
41        Asleep,
42        Connecting,
43        Connected,
44        Disconnected
45    };
46
47public:
48    /** if internet is unavailable you will get a down() signal soon, otherwise
49      * you won't get a signal until the net goes down */
50    InternetConnectionMonitor( QObject *parent = 0 );
51
52    bool isDown() const { return !m_up; }
53    bool isUp() const { return m_up; }
54
55    NetworkConnectionMonitor* createNetworkConnectionMonitor();
56
57signals:
58    /** yay! internet has returned */
59    void up( const QString& connectionName = "" );
60    
61    /** we think the internet is unavailable, but well, still try, but show
62      * an unhappy face in the statusbar or something */
63    void down( const QString& connectionName = "" );
64    
65    /** emitted after the above */
66    void connectivityChanged( bool );
67
68private slots:
69    void onFinished( QNetworkReply* reply );
70    void onNetworkUp();
71    void onNetworkDown();
72
73private:
74    bool m_up;
75    NetworkConnectionMonitor* m_networkMonitor;
76};
77
78} //namespace lastfm
79
80#endif