~noskcaj/ubuntu/saucy/sflphone/merge-1.2.3-2

« back to all changes in this revision

Viewing changes to kde/src/klib/macromodel.h

  • Committer: Jackson Doak
  • Date: 2013-07-10 21:04:46 UTC
  • mfrom: (20.1.3 sid)
  • Revision ID: noskcaj@ubuntu.com-20130710210446-y8f587vza807icr9
Properly merged from upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
 *   Copyright (C) 2013 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
 
 
19
#ifndef MACRO_MODEL_H
 
20
#define MACRO_MODEL_H
 
21
 
 
22
#include <QtCore/QAbstractItemModel>
 
23
#include <QtCore/QHash>
 
24
#include "../lib/typedefs.h"
 
25
 
 
26
//KDE
 
27
class KAction;
 
28
 
 
29
//SFLPhone
 
30
 
 
31
class Macro;
 
32
 
 
33
///Interface to interpret DTMFs instead of using the daemon directly
 
34
class LIB_EXPORT MacroListener {
 
35
public:
 
36
   virtual void addDTMF(const QString& sequence) = 0;
 
37
   virtual ~MacroListener() {}
 
38
};
 
39
 
 
40
///AkonadiBackend: Implement a backend for Akonadi
 
41
class LIB_EXPORT MacroModel : public QAbstractItemModel {
 
42
   Q_OBJECT
 
43
   friend class Macro;
 
44
 
 
45
private:
 
46
   
 
47
   enum IndexType {
 
48
      CategoryIndex = 1,
 
49
      MacroIndex = 2
 
50
   };
 
51
   
 
52
   struct IndexPointer {
 
53
      IndexPointer(IndexType _type, void* _data) : type(_type),data(_data) {}
 
54
      IndexType type;
 
55
      void* data;
 
56
   };
 
57
 
 
58
   struct MacroCategory {
 
59
      MacroCategory():m_pPointer(nullptr){}
 
60
      QString m_Name;
 
61
      QList<Macro*> m_lContent;
 
62
      IndexPointer* m_pPointer;
 
63
   };
 
64
public:
 
65
   static MacroModel* getInstance();
 
66
   static void addListener(MacroListener* interface);
 
67
 
 
68
   enum MacroFields {
 
69
      Name        = 100,
 
70
      Category    = 101,
 
71
      Delay       = 102,
 
72
      Description = 103,
 
73
      Sequence    = 104
 
74
   };
 
75
 
 
76
   void initMacros();
 
77
 
 
78
   //Getters
 
79
   Macro* getCurrentMacro();
 
80
 
 
81
   //Mutator
 
82
   MacroModel::MacroCategory* createCategory(const QString& name);
 
83
 
 
84
   //Model implementation
 
85
   virtual bool          setData     ( const QModelIndex& index, const QVariant &value, int role   );
 
86
   virtual QVariant      data        ( const QModelIndex& index, int role = Qt::DisplayRole        ) const;
 
87
   virtual int           rowCount    ( const QModelIndex& parent = QModelIndex()                   ) const;
 
88
   virtual Qt::ItemFlags flags       ( const QModelIndex& index                                    ) const;
 
89
   virtual int           columnCount ( const QModelIndex& parent = QModelIndex()                   ) const;
 
90
   virtual QModelIndex   parent      ( const QModelIndex& index                                    ) const;
 
91
   virtual QModelIndex   index       ( int row, int column, const QModelIndex& parent=QModelIndex()) const;
 
92
   virtual QVariant      headerData  ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
 
93
 
 
94
private:
 
95
   //Singleton constructor
 
96
   explicit MacroModel(QObject* parent = nullptr);
 
97
 
 
98
   //Attributes
 
99
   static MacroModel*         m_pInstance  ;
 
100
 
 
101
private:
 
102
   void updateTreeModel(Macro* newMacro);
 
103
   QHash<QString,Macro*> m_hMacros;
 
104
   QList<MacroCategory*> m_lCategories;
 
105
   QList<MacroListener*> m_lListeners;
 
106
   Macro*                m_pCurrentMacro;
 
107
   Macro*                m_pCurrentMacroMemento;
 
108
 
 
109
public Q_SLOTS:
 
110
   Macro* newMacro(const QString& id = "");
 
111
   bool removeMacro(QModelIndex idx);
 
112
   void setCurrent(QModelIndex current,QModelIndex previous);
 
113
   void save();
 
114
 
 
115
private Q_SLOTS:
 
116
   void changed(Macro* macro);
 
117
 
 
118
Q_SIGNALS:
 
119
   void addAction(KAction*);
 
120
   void selectMacro(Macro* macro);
 
121
};
 
122
 
 
123
class LIB_EXPORT Macro : public QObject {
 
124
   Q_OBJECT
 
125
   friend class MacroModel; //Use factory method
 
126
public:
 
127
   Macro(const Macro* macro);
 
128
   MacroModel::MacroCategory* m_pCat;
 
129
   //Getters
 
130
   QString  name();
 
131
   QString  description();
 
132
   QString  sequence();
 
133
   QString  escaped();
 
134
   QString  id();
 
135
   int      delay();
 
136
   QString  category();
 
137
   KAction* action();
 
138
 
 
139
   QModelIndex index();
 
140
 
 
141
   //Setters
 
142
   void setName(QString value);
 
143
   void setDescription(QString value);
 
144
   void setSequence(QString value);
 
145
   void setEscaped(QString value);
 
146
   void setId(QString value);
 
147
   void setDelay(int value);
 
148
   void setCategory(QString value);
 
149
   
 
150
private:
 
151
   explicit Macro(QObject* parent = nullptr);
 
152
   int         m_Position;
 
153
   QString     m_Name;
 
154
   QString     m_Description;
 
155
   QString     m_Sequence;
 
156
   QString     m_Escaped;
 
157
   QString     m_Id;
 
158
   int         m_Delay;
 
159
   QString     m_Category;
 
160
   KAction*    m_Action;
 
161
   MacroModel* m_pModel;
 
162
   MacroModel::IndexPointer* m_pPointer;
 
163
public Q_SLOTS:
 
164
   void execute();
 
165
private Q_SLOTS:
 
166
   void nextStep();
 
167
 
 
168
Q_SIGNALS:
 
169
   void changed(Macro*);
 
170
};
 
171
 
 
172
#endif