connectivity-api
vpn-connections-list-model.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2014 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License version 3,
6  * 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
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authors:
17  * Pete Woods <pete.woods@canonical.com>
18  */
19 
20 #pragma once
21 
23 
24 #include <QAbstractItemModel>
25 #include <unity/util/DefinesPtrs.h>
26 
27 namespace connectivityqt
28 {
29 namespace internal
30 {
31 struct VpnConnectionsListModelParameters;
32 }
33 
34 class Q_DECL_EXPORT VpnConnectionsListModel : public QAbstractListModel
35 {
36  Q_OBJECT
37 
38  Q_ENUMS(Roles)
39 
40 public:
41  UNITY_DEFINES_PTRS(VpnConnectionsListModel);
42 
43  enum Roles
44  {
49  RoleConnection
50  };
51 
52  VpnConnectionsListModel(const internal::VpnConnectionsListModelParameters& parameters);
53 
55 
56  int columnCount(const QModelIndex &parent) const override;
57 
58  int rowCount(const QModelIndex &parent) const override;
59 
60  QVariant data(const QModelIndex &index, int role) const override;
61 
62  bool setData(const QModelIndex &index, const QVariant &value, int role) override;
63 
64  Qt::ItemFlags flags(const QModelIndex & index) const override;
65 
66  QHash<int, QByteArray> roleNames() const override
67  {
68  QHash<int, QByteArray> roles;
69  roles[RoleId] = "id";
70  roles[RoleActive] = "active";
71  roles[RoleActivatable] = "activatable";
72  roles[RoleType] = "type";
73  roles[RoleConnection] = "connection";
74  return roles;
75  }
76 
77 public Q_SLOTS:
78  void add(VpnConnection::Type type);
79 
80  void remove(VpnConnection* connection);
81 
82 Q_SIGNALS:
83  void addFinished(VpnConnection * connection);
84 
85 protected:
86  class Priv;
87  std::shared_ptr<Priv> d;
88 };
89 
90 }
91 
92 Q_DECLARE_METATYPE(connectivityqt::VpnConnection*)
Definition: vpn-connection.h:31
Roles
Definition: vpn-connections-list-model.h:43
Definition: vpn-connections-list-model.h:45
QHash< int, QByteArray > roleNames() const override
Definition: vpn-connections-list-model.h:66
Definition: connectivity.cpp:32
std::shared_ptr< Priv > d
Definition: vpn-connections-list-model.h:86
Definition: vpn-connections-list-model.h:34
Definition: vpn-connections-list-model.h:48
Definition: vpn-connections-list-model.h:47
Type
Definition: vpn-connection.h:40
Definition: vpn-connections-list-model.h:46