/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. This file is part of liblastfm.
  5. liblastfm is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. liblastfm is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with liblastfm. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef LASTFM_CONNECTION_MONITOR_H
  17. #define LASTFM_CONNECTION_MONITOR_H
  18. #include <lastfm/global.h>
  19. #include <QObject>
  20. class NetworkConnectionMonitor;
  21. #ifdef Q_WS_X11
  22. class LNetworkConnectionMonitor;
  23. #endif
  24. namespace lastfm {
  25. class LASTFM_DLLEXPORT InternetConnectionMonitor : public QObject
  26. {
  27. Q_OBJECT
  28. enum NMState
  29. {
  30. Unknown,
  31. Asleep,
  32. Connecting,
  33. Connected,
  34. Disconnected
  35. };
  36. public:
  37. /** if internet is unavailable you will get a down() signal soon, otherwise
  38. * you won't get a signal until the net goes down */
  39. InternetConnectionMonitor( QObject *parent = 0 );
  40. bool isDown() const { return !m_up; }
  41. bool isUp() const { return m_up; }
  42. NetworkConnectionMonitor* createNetworkConnectionMonitor();
  43. signals:
  44. /** yay! internet has returned */
  45. void up( const QString& connectionName = "" );
  46. /** we think the internet is unavailable, but well, still try, but show
  47. * an unhappy face in the statusbar or something */
  48. void down( const QString& connectionName = "" );
  49. /** emitted after the above */
  50. void connectivityChanged( bool );
  51. private slots:
  52. void onFinished( QNetworkReply* reply );
  53. void onNetworkUp();
  54. void onNetworkDown();
  55. private:
  56. bool m_up;
  57. NetworkConnectionMonitor* m_networkMonitor;
  58. };
  59. } //namespace lastfm
  60. #endif