1 /*
2  * This file is part of Licq, an instant messaging client for UNIX.
3  * Copyright (C) 2009-2014 Licq developers <licq-dev@googlegroups.com>
4  *
5  * Licq is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * Licq 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
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with Licq; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18  */
19 
20 #ifndef CONFIG_SHORTCUTS_H
21 #define CONFIG_SHORTCUTS_H
22 
23 #include <QKeySequence>
24 #include <QObject>
25 #include <QMap>
26 
27 namespace Licq
28 {
29 class IniFile;
30 }
31 
32 namespace LicqQtGui
33 {
34 namespace Config
35 {
36 /**
37  * Keybort shortcuts configuration
38  */
39 class Shortcuts : public QObject
40 {
41   Q_OBJECT
42 
43 public:
44   enum ShortcutType
45   {
46     ChatColorBack,
47     ChatColorFore,
48     ChatEmoticonMenu,
49     ChatEncodingMenu,
50     ChatEventMenu,
51     ChatHistory,
52     ChatPopupNextMessage,
53     ChatTab01,
54     ChatTab02,
55     ChatTab03,
56     ChatTab04,
57     ChatTab05,
58     ChatTab06,
59     ChatTab07,
60     ChatTab08,
61     ChatTab09,
62     ChatTab10,
63     ChatToggleSecure,
64     ChatToggleSendServer,
65     ChatToggleUrgent,
66     ChatUserInfo,
67     ChatUserMenu,
68 #ifdef Q_WS_X11
69     GlobalPopupMessage,
70     GlobalShowMainwin,
71 #endif
72     InputClear,
73     InputDeleteLine,
74     InputDeleteLineBack,
75     InputDeleteWordBack,
76     MainwinAccountManager,
77     MainwinAddGroup,
78     MainwinEditGroups,
79     MainwinExit,
80     MainwinHide,
81     MainwinNetworkLog,
82     MainwinPopupAllMessages,
83     MainwinPopupMessage,
84     MainwinSetAutoResponse,
85     MainwinSettings,
86     MainwinStatusAway,
87     MainwinStatusDoNotDisturb,
88     MainwinStatusFreeForChat,
89     MainwinStatusInvisible,
90     MainwinStatusNotAvailable,
91     MainwinStatusOccupied,
92     MainwinStatusOffline,
93     MainwinStatusOnline,
94     MainwinToggleEmptyGroups,
95     MainwinToggleMiniMode,
96     MainwinToggleShowHeader,
97     MainwinToggleShowOffline,
98     MainwinUserCheckAutoresponse,
99     MainwinUserSendChatRequest,
100     MainwinUserSendMessage,
101     MainwinUserSendFile,
102     MainwinUserSendUrl,
103     MainwinUserViewHistory,
104     MainwinUserViewMessage,
105   };
106 
107   /**
108    * Create the singleton instance
109    *
110    * @param parent Parent object
111    */
112   static void createInstance(QObject* parent = NULL);
113 
114   /**
115    * Get the singleton instance
116    *
117    * @return The instance
118    */
instance()119   static Shortcuts* instance()
120   { return myInstance; }
121 
122   /**
123    * Constuctor
124    */
125   Shortcuts(QObject* parent = 0);
126 
127   /**
128    * Destructor
129    */
~Shortcuts()130   ~Shortcuts() {}
131 
132   /**
133    * Allow or disallow signals for configuration changes
134    *
135    * @param block True to block signals or false to unblock and send any pending signals
136    */
137   void blockUpdates(bool block);
138 
139   /**
140    * Get a keyboard shortcut
141    *
142    * @param function Function to get shortcut for
143    * @return The currently assigned shortcut
144    */
getShortcut(ShortcutType function)145   QKeySequence getShortcut(ShortcutType function) const
146   { return myShortcutsMap.value(function); }
147 
148 public slots:
149   /**
150    * Load configuration from file
151    */
152   void loadConfiguration(Licq::IniFile& iniFile);
153 
154   /**
155    * Save configuration to file
156    */
157   void saveConfiguration(Licq::IniFile& iniFile) const;
158 
159   /**
160    * Set a keyboard shortcut
161    *
162    * @param function Function to set shortcut for
163    * @param shortcut New shortcut to assign
164    */
165   void setShortcut(ShortcutType function, const QKeySequence& shortcut);
166 
167 signals:
168   /**
169    * Shortcut has changed
170    */
171   void shortcutsChanged();
172 
173 private:
174   static Shortcuts* myInstance;
175 
176   // Changes has been made that should trigger changed() signal
177   bool myBlockUpdates;
178   bool myShortcutsHasChanged;
179 
180   QMap<ShortcutType, QKeySequence> myShortcutsMap;
181   QMap<ShortcutType, int> myDefaultShortcutsMap;
182   QMap<ShortcutType, QString> myConfigKeysMap;
183 };
184 
185 } // namespace Config
186 } // namespace LicqQtGui
187 
188 #endif
189