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 #include "shortcuts.h"
21
22 #include <licq/inifile.h>
23
24 using namespace LicqQtGui;
25 /* TRANSLATOR LicqQtGui::Config::Shortcuts */
26
27 Config::Shortcuts* Config::Shortcuts::myInstance = NULL;
28
createInstance(QObject * parent)29 void Config::Shortcuts::createInstance(QObject* parent)
30 {
31 myInstance = new Config::Shortcuts(parent);
32 }
33
Shortcuts(QObject * parent)34 Config::Shortcuts::Shortcuts(QObject* parent)
35 : QObject(parent),
36 myBlockUpdates(false),
37 myShortcutsHasChanged(false)
38 {
39 // Define all shortcuts here by populating config file keys and default values in the maps
40
41 #define ADD_SHORTCUT(function, inikey, def) \
42 myDefaultShortcutsMap.insert(function, def); \
43 myConfigKeysMap.insert(function, inikey);
44
45 // Shortcuts for message dialog
46 ADD_SHORTCUT(ChatColorBack, "Chat.ColorBack", Qt::ALT + Qt::Key_B)
47 ADD_SHORTCUT(ChatColorFore, "Chat.ColorFore", Qt::ALT + Qt::Key_T)
48 ADD_SHORTCUT(ChatEmoticonMenu, "Chat.EmoticonMenu", Qt::ALT + Qt::Key_L)
49 ADD_SHORTCUT(ChatEncodingMenu, "Chat.EncodingMenu", Qt::ALT + Qt::Key_O)
50 ADD_SHORTCUT(ChatEventMenu, "Chat.EventMenu", Qt::ALT + Qt::Key_P)
51 ADD_SHORTCUT(ChatHistory, "Chat.History", Qt::ALT + Qt::Key_H)
52 ADD_SHORTCUT(ChatPopupNextMessage, "Chat.PopupNextMessage", 0);
53 ADD_SHORTCUT(ChatTab01, "Chat.Tab01", Qt::ALT + Qt::Key_1)
54 ADD_SHORTCUT(ChatTab02, "Chat.Tab02", Qt::ALT + Qt::Key_2)
55 ADD_SHORTCUT(ChatTab03, "Chat.Tab03", Qt::ALT + Qt::Key_3)
56 ADD_SHORTCUT(ChatTab04, "Chat.Tab04", Qt::ALT + Qt::Key_4)
57 ADD_SHORTCUT(ChatTab05, "Chat.Tab05", Qt::ALT + Qt::Key_5)
58 ADD_SHORTCUT(ChatTab06, "Chat.Tab06", Qt::ALT + Qt::Key_6)
59 ADD_SHORTCUT(ChatTab07, "Chat.Tab07", Qt::ALT + Qt::Key_7)
60 ADD_SHORTCUT(ChatTab08, "Chat.Tab08", Qt::ALT + Qt::Key_8)
61 ADD_SHORTCUT(ChatTab09, "Chat.Tab09", Qt::ALT + Qt::Key_9)
62 ADD_SHORTCUT(ChatTab10, "Chat.Tab10", Qt::ALT + Qt::Key_0)
63 ADD_SHORTCUT(ChatToggleSecure, "Chat.ToggleSecure", Qt::ALT + Qt::Key_E)
64 ADD_SHORTCUT(ChatToggleSendServer, "Chat.ToggleSendServer", Qt::ALT + Qt::Key_N)
65 ADD_SHORTCUT(ChatToggleUrgent, "Chat.ToggleUrgent", Qt::ALT + Qt::Key_R)
66 ADD_SHORTCUT(ChatUserInfo, "Chat.UserInfo", Qt::ALT + Qt::Key_I)
67 ADD_SHORTCUT(ChatUserMenu, "Chat.UserMenu", Qt::ALT + Qt::Key_M)
68
69 // Shortcuts available outside Licq
70 #ifdef Q_WS_X11
71 ADD_SHORTCUT(GlobalPopupMessage, "Global.PopupMessage", 0)
72 ADD_SHORTCUT(GlobalShowMainwin, "Global.ShowMainwin", 0)
73 #endif
74
75 // Shortcuts for MLEdit used for text input in several dialogs including message dialog
76 ADD_SHORTCUT(InputClear, "Input.Clear", Qt::CTRL + Qt::Key_L)
77 ADD_SHORTCUT(InputDeleteLine, "Input.DeleteLine", Qt::CTRL + Qt::Key_U)
78 ADD_SHORTCUT(InputDeleteLineBack, "Input.DeleteLineBack", Qt::CTRL + Qt::Key_N)
79 ADD_SHORTCUT(InputDeleteWordBack, "Input.DeleteWordBack", Qt::CTRL + Qt::Key_W)
80
81 // Shortcuts for main window (contact list)
82 ADD_SHORTCUT(MainwinAccountManager, "Mainwin.AccountManager", 0)
83 ADD_SHORTCUT(MainwinAddGroup, "Mainwin.AddGroup", 0)
84 ADD_SHORTCUT(MainwinEditGroups, "Mainwin.EditGroups", Qt::CTRL + Qt::Key_G)
85 ADD_SHORTCUT(MainwinExit, "Mainwin.Exit", Qt::CTRL + Qt::Key_Q)
86 ADD_SHORTCUT(MainwinHide, "Mainwin.Hide", Qt::CTRL + Qt::Key_H)
87 ADD_SHORTCUT(MainwinNetworkLog, "Mainwin.NetworkLog", 0)
88 ADD_SHORTCUT(MainwinPopupAllMessages, "Mainwin.PopupAllMessages", Qt::CTRL + Qt::Key_P)
89 ADD_SHORTCUT(MainwinPopupMessage, "Mainwin.PopupMessage", Qt::CTRL + Qt::Key_I)
90 ADD_SHORTCUT(MainwinSetAutoResponse, "Mainwin.SetAutoResponse", 0)
91 ADD_SHORTCUT(MainwinSettings, "Mainwin.Settings", 0)
92 ADD_SHORTCUT(MainwinStatusAway, "Mainwin.StatusAway", Qt::ALT + Qt::Key_A)
93 ADD_SHORTCUT(MainwinStatusDoNotDisturb, "Mainwin.StatusDoNotDisturb", Qt::ALT + Qt::Key_D)
94 ADD_SHORTCUT(MainwinStatusFreeForChat, "Mainwin.StatusFreeForChat", Qt::ALT + Qt::Key_H)
95 ADD_SHORTCUT(MainwinStatusInvisible, "Mainwin.StatusInvisible", Qt::ALT + Qt::Key_I)
96 ADD_SHORTCUT(MainwinStatusNotAvailable, "Mainwin.StatusNotAvailable", Qt::ALT + Qt::Key_N)
97 ADD_SHORTCUT(MainwinStatusOccupied, "Mainwin.StatusOccupied", Qt::ALT + Qt::Key_C)
98 ADD_SHORTCUT(MainwinStatusOffline, "Mainwin.StatusOffline", Qt::ALT + Qt::Key_F)
99 ADD_SHORTCUT(MainwinStatusOnline, "Mainwin.StatusOnline", Qt::ALT + Qt::Key_O)
100 ADD_SHORTCUT(MainwinToggleEmptyGroups, "Mainwin.MainwinToggleEmptyGroups", 0)
101 ADD_SHORTCUT(MainwinToggleMiniMode, "Mainwin.MainwinToggleMiniMode", Qt::CTRL + Qt::Key_M)
102 ADD_SHORTCUT(MainwinToggleShowHeader, "Mainwin.MainwinToggleShowHeader", 0)
103 ADD_SHORTCUT(MainwinToggleShowOffline, "Mainwin.MainwinToggleShowOffline", Qt::CTRL + Qt::Key_O)
104 ADD_SHORTCUT(MainwinUserCheckAutoresponse, "Mainwin.UserCheckAutoresponse", Qt::CTRL + Qt::Key_C)
105 ADD_SHORTCUT(MainwinUserSendChatRequest, "Mainwin.UserSendChatRequest", Qt::CTRL + Qt::Key_C)
106 ADD_SHORTCUT(MainwinUserSendMessage, "Mainwin.UserSendMessage", Qt::CTRL + Qt::Key_S)
107 ADD_SHORTCUT(MainwinUserSendFile, "Mainwin.UserSendFile", Qt::CTRL + Qt::Key_F)
108 ADD_SHORTCUT(MainwinUserSendUrl, "Mainwin.UserSendUrl", Qt::CTRL + Qt::Key_U)
109 ADD_SHORTCUT(MainwinUserViewHistory, "Mainwin.UserViewHistory", 0);
110 ADD_SHORTCUT(MainwinUserViewMessage, "Mainwin.UserViewMessage", Qt::CTRL + Qt::Key_V)
111
112 #undef ADD_SHORTCUT
113 }
114
loadConfiguration(Licq::IniFile & iniFile)115 void Config::Shortcuts::loadConfiguration(Licq::IniFile& iniFile)
116 {
117 std::string s;
118
119 #ifdef Q_WS_X11
120 // Old varibable for backwards compatibility
121 iniFile.setSection("functions");
122 iniFile.get("MsgPopupKey", s, "none");
123 QString oldMsgPopupKey = (s != "none" ? QString::fromLatin1(s.c_str()) : QString());
124 #endif
125
126 iniFile.setSection("shortcuts");
127
128 QMap<ShortcutType, QString>::iterator i;
129 for (i = myConfigKeysMap.begin(); i != myConfigKeysMap.end(); ++i)
130 {
131 iniFile.get(i.value().toLatin1().data(), s);
132 if (s.empty())
133 {
134 #ifdef Q_WS_X11
135 if (i.key() == GlobalPopupMessage && !oldMsgPopupKey.isEmpty())
136 myShortcutsMap[i.key()] = QKeySequence(oldMsgPopupKey);
137 else
138 #endif
139 myShortcutsMap[i.key()] = QKeySequence(myDefaultShortcutsMap[i.key()]);
140 }
141 else if(s == "None")
142 myShortcutsMap[i.key()] = QKeySequence();
143 else
144 myShortcutsMap[i.key()] = QKeySequence(s.c_str());
145 }
146
147 emit shortcutsChanged();
148 }
149
saveConfiguration(Licq::IniFile & iniFile) const150 void Config::Shortcuts::saveConfiguration(Licq::IniFile& iniFile) const
151 {
152 iniFile.setSection("shortcuts");
153
154 QMap<ShortcutType, QString>::const_iterator i;
155 for (i = myConfigKeysMap.begin(); i != myConfigKeysMap.end(); ++i)
156 iniFile.set(i.value().toLatin1().data(),
157 myShortcutsMap[i.key()].isEmpty() ? "None" :
158 myShortcutsMap[i.key()].toString(QKeySequence::PortableText).toLatin1().constData());
159 }
160
blockUpdates(bool block)161 void Config::Shortcuts::blockUpdates(bool block)
162 {
163 myBlockUpdates = block;
164
165 if (block)
166 return;
167
168 if (myShortcutsHasChanged)
169 {
170 myShortcutsHasChanged = false;
171 emit shortcutsChanged();
172 }
173 }
174
setShortcut(ShortcutType function,const QKeySequence & shortcut)175 void Config::Shortcuts::setShortcut(ShortcutType function, const QKeySequence& shortcut)
176 {
177 QKeySequence& var = myShortcutsMap[function];
178 if (var == shortcut)
179 return;
180
181 var = shortcut;
182
183 if (myBlockUpdates)
184 myShortcutsHasChanged = true;
185 else
186 emit shortcutsChanged();
187 }
188