~ubuntu-branches/ubuntu/wily/sflphone/wily

« back to all changes in this revision

Viewing changes to kde/src/lib/abstractitembackend.h

  • Committer: Package Import Robot
  • Author(s): Francois Marier, Francois Marier, Mark Purcell
  • Date: 2014-10-18 15:08:50 UTC
  • mfrom: (1.1.12)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20141018150850-2exfk34ckb15pcwi
Tags: 1.4.1-0.1
[ Francois Marier ]
* Non-maintainer upload
* New upstream release (closes: #759576, #741130)
  - debian/rules +PJPROJECT_VERSION := 2.2.1
  - add upstream patch to fix broken TLS support
  - add patch to fix pjproject regression

[ Mark Purcell ]
* Build-Depends:
  - sflphone-daemon + libavformat-dev, libavcodec-dev, libswscale-dev,
  libavdevice-dev, libavutil-dev
  - sflphone-gnome + libclutter-gtk-1.0-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
 *   Copyright (C) 2014 by Savoir-Faire Linux                               *
 
3
 *   Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> *
 
4
 *                                                                          *
 
5
 *   This library is free software; you can redistribute it and/or          *
 
6
 *   modify it under the terms of the GNU Lesser General Public             *
 
7
 *   License as published by the Free Software Foundation; either           *
 
8
 *   version 2.1 of the License, or (at your option) any later version.     *
 
9
 *                                                                          *
 
10
 *   This library is distributed in the hope that it will be useful,        *
 
11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of         *
 
12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU      *
 
13
 *   Lesser General Public License for more details.                        *
 
14
 *                                                                          *
 
15
 *   You should have received a copy of the GNU General Public License      *
 
16
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.  *
 
17
 ***************************************************************************/
 
18
#ifndef ABSTRACTITEMBACKENDBASE_H
 
19
#define ABSTRACTITEMBACKENDBASE_H
 
20
 
 
21
#include <QObject>
 
22
#include <QHash>
 
23
#include <QStringList>
 
24
#include <QVariant>
 
25
#include <QtCore/QAbstractItemModel>
 
26
 
 
27
#include "typedefs.h"
 
28
#include "contact.h"
 
29
 
 
30
//SFLPhone
 
31
class Contact;
 
32
class Account;
 
33
class Call   ;
 
34
 
 
35
class LIB_EXPORT AbstractItemBackendBase {
 
36
public:
 
37
   virtual ~AbstractItemBackendBase(){}
 
38
 
 
39
   enum SupportedFeatures {
 
40
      NONE        = 0x0      ,
 
41
      LOAD        = 0x1 <<  0, /* Load this backend, DO NOT load anything before "load" is called         */
 
42
      SAVE        = 0x1 <<  1, /* Save an item                                                            */
 
43
      EDIT        = 0x1 <<  2, /* Edit, but **DOT NOT**, save an item)                                    */
 
44
      PROBE       = 0x1 <<  3, /* Check if the backend has new items (some backends do this automagically)*/
 
45
      ADD         = 0x1 <<  4, /* Add (and save) a new item to the backend                                */
 
46
      SAVE_ALL    = 0x1 <<  5, /* Save all items at once, this may or may not be faster than "add"        */
 
47
      CLEAR       = 0x1 <<  6, /* Clear all items from this backend                                       */
 
48
      REMOVE      = 0x1 <<  7, /* Remove a single item                                                    */
 
49
      EXPORT      = 0x1 <<  8, /* Export all items, format and output need to be defined by each backends */
 
50
      IMPORT      = 0x1 <<  9, /* Import items from an external source, details defined by each backends  */
 
51
      ENABLEABLE  = 0x1 << 10, /*Can be enabled, I know, it is not a word, but Java use it too            */
 
52
      DISABLEABLE = 0x1 << 11, /*Can be disabled, I know, it is not a word, but Java use it too           */
 
53
      MANAGEABLE  = 0x1 << 12, /* Can be managed the config GUI                                       */
 
54
   };
 
55
 
 
56
   //Management methods
 
57
   virtual QString name () const =0;
 
58
   virtual QVariant icon() const =0;
 
59
   virtual bool isEnabled() const = 0;
 
60
   virtual bool enable (bool);
 
61
   virtual QByteArray  id() const = 0;
 
62
 
 
63
   virtual SupportedFeatures  supportedFeatures() const = 0;
 
64
 
 
65
   virtual bool load()   = 0;
 
66
   virtual bool reload() = 0;
 
67
   virtual bool clear();
 
68
 
 
69
   QVector<AbstractItemBackendBase*> baseChildrenBackends() const;
 
70
protected:
 
71
   QVector<AbstractItemBackendBase*> m_lBaseChildren;
 
72
};
 
73
 
 
74
///AbstractItemBackendInterface: Allow different way to handle contact without poluting the library
 
75
template <class T> class LIB_EXPORT AbstractItemBackendInterface : public AbstractItemBackendBase
 
76
{
 
77
public:
 
78
 
 
79
   explicit AbstractItemBackendInterface(AbstractItemBackendInterface<T>* parent = nullptr);
 
80
   virtual ~AbstractItemBackendInterface() {}
 
81
 
 
82
   virtual bool save(const T* item) =0;
 
83
   virtual bool append(const T* item) =0;
 
84
   virtual bool batchSave(const QList<T*> contacts);
 
85
   virtual bool remove(T* item);
 
86
 
 
87
   ///Edit 'item', the implementation may be a GUI or something else
 
88
   virtual bool        edit       ( T*       item     ) = 0;
 
89
   ///Add a new item to the backend
 
90
   virtual bool        addNew     ( T*       item     ) = 0;
 
91
 
 
92
   ///Add a new phone number to an existing item
 
93
   virtual bool addPhoneNumber( T*       item , PhoneNumber* number )=0;
 
94
 
 
95
   AbstractItemBackendInterface<T>* parentBackend() const;
 
96
 
 
97
   QVector<AbstractItemBackendInterface<T>*> childrenBackends() const;
 
98
   void addChildren(AbstractItemBackendInterface<T>* c);
 
99
 
 
100
   virtual QList<T*> items() const = 0;
 
101
 
 
102
private:
 
103
   AbstractItemBackendInterface<T>* m_pParent;
 
104
   QVector<AbstractItemBackendInterface<T>*> m_lChildren;
 
105
};
 
106
 
 
107
// those classes cannot be typedefs because Qt doesn't support template QObjects
 
108
 
 
109
class LIB_EXPORT AbstractContactBackend : public QObject, public AbstractItemBackendInterface<Contact>
 
110
{
 
111
   #pragma GCC diagnostic push
 
112
   #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
 
113
   Q_OBJECT
 
114
   #pragma GCC diagnostic pop
 
115
public:
 
116
   explicit AbstractContactBackend(AbstractItemBackendInterface<Contact>* parentBackend = nullptr,
 
117
                                   QObject* parent = nullptr);
 
118
   virtual ~AbstractContactBackend();
 
119
 
 
120
 
 
121
Q_SIGNALS:
 
122
   void reloaded();
 
123
   void newContactAdded(Contact* c);
 
124
};
 
125
 
 
126
class LIB_EXPORT AbstractHistoryBackend : public QObject, public AbstractItemBackendInterface<Call>
 
127
{
 
128
   #pragma GCC diagnostic push
 
129
   #pragma GCC diagnostic ignored "-Wzero-as-null-pointer-constant"
 
130
   Q_OBJECT
 
131
   #pragma GCC diagnostic pop
 
132
public:
 
133
   explicit AbstractHistoryBackend(AbstractItemBackendInterface<Call>* parentBackend = nullptr,
 
134
                                   QObject* parent = nullptr);
 
135
   virtual ~AbstractHistoryBackend();
 
136
 
 
137
Q_SIGNALS:
 
138
   void reloaded();
 
139
   void newHistoryCallAdded(Call* c);
 
140
};
 
141
 
 
142
template <class T> AbstractItemBackendInterface<T>* AbstractItemBackendInterface<T>::parentBackend() const
 
143
{
 
144
   return m_pParent;
 
145
}
 
146
 
 
147
template <class T> QVector<AbstractItemBackendInterface<T>*> AbstractItemBackendInterface<T>::childrenBackends() const
 
148
{
 
149
   return m_lChildren;
 
150
}
 
151
 
 
152
template <class T> void AbstractItemBackendInterface<T>::addChildren(AbstractItemBackendInterface<T>* c)
 
153
{
 
154
   m_lChildren << c;
 
155
   m_lBaseChildren << c;
 
156
}
 
157
 
 
158
 
 
159
template <class T> AbstractItemBackendInterface<T>::AbstractItemBackendInterface(AbstractItemBackendInterface<T>* parent):
 
160
   m_pParent(parent)
 
161
{
 
162
   if (parent)
 
163
      parent->addChildren(this);
 
164
}
 
165
 
 
166
#endif