Mudlet  0
Mudclient
KeyUnit.h
Go to the documentation of this file.
1 #ifndef MUDLET_KEYUNIT_H
2 #define MUDLET_KEYUNIT_H
3 
4 /***************************************************************************
5  * Copyright (C) 2008-2011 by Heiko Koehn - KoehnHeiko@googlemail.com *
6  * Copyright (C) 2014 by Ahmed Charles - acharles@outlook.com *
7  * Copyright (C) 2018 by Stephen Lyons - slysven@virginmedia.com *
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  * This program is distributed in the hope that it will be useful, *
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
17  * GNU General Public License for more details. *
18  * *
19  * You should have received a copy of the GNU General Public License *
20  * along with this program; if not, write to the *
21  * Free Software Foundation, Inc., *
22  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
23  ***************************************************************************/
24 
25 
26 #include "pre_guard.h"
27 #include <QMap>
28 #include <QMutex>
29 #include <QPointer>
30 #include <QString>
31 #include "post_guard.h"
32 
33 #include <list>
34 
35 class Host;
36 class TKey;
37 
38 
39 class KeyUnit
40 {
41  friend class XMLexport;
42  friend class XMLimport;
43 
44 public:
45  KeyUnit(Host* pHost);
46 
47  std::list<TKey*> getKeyRootNodeList()
48  {
49  QMutexLocker locker(&mKeyUnitLock);
50  return mKeyRootNodeList;
51  }
52 
53  TKey* getKey(int id);
54  void removeAllTempKeys();
55  void compileAll();
56  TKey* findKey(QString & name);
57  bool enableKey(const QString& name);
58  bool disableKey(const QString& name);
59  bool killKey(QString& name);
60  bool registerKey(TKey* pT);
61  void unregisterKey(TKey* pT);
62  void reParentKey(int childID, int oldParentID, int newParentID, int parentPosition = -1, int childPosition = -1);
64  int getNewID();
65  QString getKeyName(int keyCode, int modifier);
66  void setupKeyNames();
67  void uninstall(const QString&);
68  void _uninstall(TKey* pChild, const QString& packageName);
69  bool processDataStream(int, int);
70  void markCleanup( TKey * pT );
71  void doCleanup();
72  void stopAllTriggers();
73  void reenableAllTriggers();
74 
75  QMultiMap<QString, TKey*> mLookupTable;
76  std::list<TKey*> mCleanupList;
77  QMutex mKeyUnitLock;
86  QList<TKey*> uninstallList;
87  // Past behaviour is to only process the first key binding that matches,
88  // ignoring any duplicates - but changing that behaviour unconditionally
89  // could break things - so only do it if this flag is set:
91 
92 private:
93  KeyUnit() = default;
94 
95  TKey* getKeyPrivate(int id);
96  void initStats();
97  void _assembleReport(TKey*);
98  void addKeyRootNode(TKey* pT, int parentPosition = -1, int childPosition = -1);
99  void addKey(TKey* pT);
100  void removeKeyRootNode(TKey* pT);
101  void removeKey(TKey*);
102  QPointer<Host> mpHost;
103  QMap<int, TKey*> mKeyMap;
104  std::list<TKey*> mKeyRootNodeList;
105  int mMaxID;
107  QMap<int, QString> mKeys;
108 };
109 
110 #endif // MUDLET_KEYUNIT_H
void _uninstall(TKey *pChild, const QString &packageName)
Definition: KeyUnit.cpp:50
void removeKeyRootNode(TKey *pT)
Definition: KeyUnit.cpp:238
int statsActiveKeysMax
Definition: KeyUnit.h:81
bool killKey(QString &name)
Definition: KeyUnit.cpp:157
void addKeyRootNode(TKey *pT, int parentPosition=-1, int childPosition=-1)
Definition: KeyUnit.cpp:184
int statsActiveKeysAverage
Definition: KeyUnit.h:83
void addKey(TKey *pT)
Definition: KeyUnit.cpp:302
void _assembleReport(TKey *)
Definition: KeyUnit.cpp:388
Definition: Host.h:62
int statsTempKeys
Definition: KeyUnit.h:79
void stopAllTriggers()
Definition: KeyUnit.cpp:99
int statsKeyTotal
Definition: KeyUnit.h:78
QList< TKey * > uninstallList
Definition: KeyUnit.h:86
void uninstall(const QString &)
Definition: KeyUnit.cpp:60
QString assembleReport()
Definition: KeyUnit.cpp:403
void removeAllTempKeys()
Definition: KeyUnit.cpp:174
int mMaxID
Definition: KeyUnit.h:105
void doCleanup()
Definition: KeyUnit.cpp:445
QMutex mKeyUnitLock
Definition: KeyUnit.h:77
void markCleanup(TKey *pT)
Definition: KeyUnit.cpp:435
TKey * getKeyPrivate(int id)
Definition: KeyUnit.cpp:263
QString getKeyName(int keyCode, int modifier)
Definition: KeyUnit.cpp:335
bool processDataStream(int, int)
Definition: KeyUnit.cpp:74
std::list< TKey * > mCleanupList
Definition: KeyUnit.h:76
TKey * findKey(QString &name)
Definition: KeyUnit.cpp:113
bool mModuleMember
Definition: KeyUnit.h:106
bool mRunAllKeyMatches
Definition: KeyUnit.h:90
TKey * getKey(int id)
Definition: KeyUnit.cpp:252
int getNewID()
Definition: KeyUnit.cpp:330
int statsActiveKeysMin
Definition: KeyUnit.h:82
std::list< TKey * > getKeyRootNodeList()
Definition: KeyUnit.h:47
bool disableKey(const QString &name)
Definition: KeyUnit.cpp:140
int statsTempKeysCreated
Definition: KeyUnit.h:84
KeyUnit()=default
QMap< int, QString > mKeys
Definition: KeyUnit.h:107
void removeKey(TKey *)
Definition: KeyUnit.cpp:316
void initStats()
Definition: KeyUnit.cpp:376
void unregisterKey(TKey *pT)
Definition: KeyUnit.cpp:287
void setupKeyNames()
Definition: KeyUnit.cpp:453
QPointer< Host > mpHost
Definition: KeyUnit.h:102
void reenableAllTriggers()
Definition: KeyUnit.cpp:106
bool registerKey(TKey *pT)
Definition: KeyUnit.cpp:272
QMap< int, TKey * > mKeyMap
Definition: KeyUnit.h:103
Definition: TKey.h:36
bool enableKey(const QString &name)
Definition: KeyUnit.cpp:123
int statsTempKeysKilled
Definition: KeyUnit.h:85
void compileAll()
Definition: KeyUnit.cpp:90
int statsActiveKeys
Definition: KeyUnit.h:80
QMultiMap< QString, TKey * > mLookupTable
Definition: KeyUnit.h:75
void reParentKey(int childID, int oldParentID, int newParentID, int parentPosition=-1, int childPosition=-1)
Definition: KeyUnit.cpp:212
std::list< TKey * > mKeyRootNodeList
Definition: KeyUnit.h:104