~mandel/ubuntu-download-manager/wily-add-appid-metadata

« back to all changes in this revision

Viewing changes to src/common/priv/ubuntu/transfers/system/network_session.h

  • Committer: CI bot
  • Author(s): Manuel de la Pena, Manuel de la Peña
  • Date: 2014-11-26 12:56:56 UTC
  • mfrom: (330.1.17 adapt-network-changes)
  • Revision ID: ps-jenkins@lists.canonical.com-20141126125656-ixnxtea9a4h5eo6p
Ensure that the download manager does track network changes correctly. Fixes: #1235138, #1390205
Approved by: Barry Warsaw, PS Jenkins bot, Manuel de la Peña

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2013-2014 Canonical Ltd.
 
3
 *
 
4
 * This library is free software; you can redistribute it and/or
 
5
 * modify it under the terms of version 3 of the GNU Lesser General Public
 
6
 * License as published by the Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
11
 * General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU Lesser General Public
 
14
 * License along with this library; if not, write to the
 
15
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
16
 * Boston, MA 02110-1301, USA.
 
17
 */
 
18
 
 
19
#ifndef TRANSFERS_LIB_NETWORK_SESSION_H
 
20
#define TRANSFERS_LIB_NETWORK_SESSION_H
 
21
 
 
22
#include <QMutex>
 
23
#include <QNetworkConfigurationManager>
 
24
#include <QObject>
 
25
 
 
26
#include "nm_interface.h"
 
27
 
 
28
namespace Ubuntu {
 
29
 
 
30
namespace Transfers {
 
31
 
 
32
namespace System {
 
33
 
 
34
class NetworkSession : public QObject {
 
35
    Q_OBJECT
 
36
 
 
37
 public:
 
38
    ~NetworkSession();
 
39
 
 
40
    virtual bool isError();
 
41
    virtual bool isOnline();
 
42
    virtual QNetworkConfiguration::BearerType sessionType();
 
43
 
 
44
    static NetworkSession* instance();
 
45
 
 
46
    // only used for testing so that we can inject a fake
 
47
    static void setInstance(NetworkSession* instance);
 
48
    static void deleteInstance();
 
49
 
 
50
 signals:
 
51
    void sessionTypeChanged(QNetworkConfiguration::BearerType type);
 
52
    void onlineStateChanged(bool state);
 
53
 
 
54
 protected:
 
55
    explicit NetworkSession(QObject* parent=0);
 
56
 
 
57
 private:
 
58
    QNetworkConfiguration::BearerType convertNMString(const QString& str);
 
59
    void onPropertiesChanged(const QVariantMap& changedProperties);
 
60
 
 
61
 private:
 
62
    // used for the singleton
 
63
    static NetworkSession* _instance;
 
64
    static QMutex _mutex;
 
65
 
 
66
    QNetworkConfigurationManager* _configManager = nullptr;
 
67
    NMInterface* _nm = nullptr;
 
68
    QNetworkConfiguration::BearerType _sessionType =
 
69
        QNetworkConfiguration::BearerUnknown;
 
70
    bool _error = false;
 
71
    QString _errorMsg = QString::null;
 
72
};
 
73
 
 
74
}
 
75
 
 
76
}
 
77
 
 
78
}
 
79
 
 
80
#endif