lomiri-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 <lomiri/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  LOMIRI_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 importFile(VpnConnection::Type type, const QString &filepath);
81 
82  void remove(VpnConnection* connection);
83 
84 Q_SIGNALS:
85  void addFinished(VpnConnection * connection);
86 
87 protected:
88  class Priv;
89  std::shared_ptr<Priv> d;
90 };
91 
92 }
93 
94 Q_DECLARE_METATYPE(connectivityqt::VpnConnection*)
vpn-connection.h
connectivityqt::VpnConnectionsListModel
Definition: vpn-connections-list-model.h:34
connectivityqt::VpnConnectionsListModel::RoleId
@ RoleId
Definition: vpn-connections-list-model.h:45
connectivityqt::VpnConnectionsListModel::Roles
Roles
Definition: vpn-connections-list-model.h:43
connectivityqt::VpnConnection
Definition: vpn-connection.h:31
connectivityqt::VpnConnectionsListModel::RoleType
@ RoleType
Definition: vpn-connections-list-model.h:48
connectivityqt
Definition: connectivity.cpp:36
connectivityqt::VpnConnectionsListModel::RoleActivatable
@ RoleActivatable
Definition: vpn-connections-list-model.h:47
connectivityqt::VpnConnection::Type
Type
Definition: vpn-connection.h:40
connectivityqt::VpnConnectionsListModel::d
std::shared_ptr< Priv > d
Definition: vpn-connections-list-model.h:88
connectivityqt::VpnConnectionsListModel::RoleActive
@ RoleActive
Definition: vpn-connections-list-model.h:46
connectivityqt::VpnConnectionsListModel::roleNames
QHash< int, QByteArray > roleNames() const override
Definition: vpn-connections-list-model.h:66