1
/****************************************************************************
2
* Copyright (C) 2013 by Savoir-Faire Linux *
3
* Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> *
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. *
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. *
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
***************************************************************************/
22
#include <QtCore/QAbstractItemModel>
23
#include <QtCore/QHash>
24
#include "../lib/typedefs.h"
33
///Interface to interpret DTMFs instead of using the daemon directly
34
class LIB_EXPORT MacroListener {
36
virtual void addDTMF(const QString& sequence) = 0;
37
virtual ~MacroListener() {}
40
///AkonadiBackend: Implement a backend for Akonadi
41
class LIB_EXPORT MacroModel : public QAbstractItemModel {
53
IndexPointer(IndexType _type, void* _data) : type(_type),data(_data) {}
58
struct MacroCategory {
59
MacroCategory():m_pPointer(nullptr){}
61
QList<Macro*> m_lContent;
62
IndexPointer* m_pPointer;
65
static MacroModel* getInstance();
66
static void addListener(MacroListener* interface);
79
Macro* getCurrentMacro();
82
MacroModel::MacroCategory* createCategory(const QString& name);
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;
95
//Singleton constructor
96
explicit MacroModel(QObject* parent = nullptr);
99
static MacroModel* m_pInstance ;
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;
110
Macro* newMacro(const QString& id = "");
111
bool removeMacro(QModelIndex idx);
112
void setCurrent(QModelIndex current,QModelIndex previous);
116
void changed(Macro* macro);
119
void addAction(KAction*);
120
void selectMacro(Macro* macro);
123
class LIB_EXPORT Macro : public QObject {
125
friend class MacroModel; //Use factory method
127
Macro(const Macro* macro);
128
MacroModel::MacroCategory* m_pCat;
131
QString description();
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);
151
explicit Macro(QObject* parent = nullptr);
154
QString m_Description;
161
MacroModel* m_pModel;
162
MacroModel::IndexPointer* m_pPointer;
169
void changed(Macro*);