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 <QGroupBox>
23 #include <QHeaderView>
24 #include <QTreeWidget>
25 #include <QVBoxLayout>
26
27 #include "config/shortcuts.h"
28
29 #include "widgets/shortcutedit.h"
30
31 #include "settingsdlg.h"
32
33 using namespace LicqQtGui;
34 /* TRANSLATOR LicqQtGui::Settings::Shortcuts */
35
Shortcuts(SettingsDlg * parent)36 Settings::Shortcuts::Shortcuts(SettingsDlg* parent)
37 : QObject(parent)
38 {
39 parent->addPage(SettingsDlg::MainwinShortcutsPage, createPageMainwinShortcuts(parent),
40 tr("Shortcuts"), SettingsDlg::ContactListPage);
41 parent->addPage(SettingsDlg::ChatShortcutsPage, createPageChatShortcuts(parent),
42 tr("Shortcuts"), SettingsDlg::ChatPage);
43
44 load();
45 }
46
createPageMainwinShortcuts(QWidget * parent)47 QWidget* Settings::Shortcuts::createPageMainwinShortcuts(QWidget* parent)
48 {
49 QWidget* w = new QWidget(parent);
50 myPageMainwinShortcutsLayout = new QVBoxLayout(w);
51 myPageMainwinShortcutsLayout->setContentsMargins(0, 0, 0, 0);
52
53 myMainwinBox = new QGroupBox(tr("Contact List Shortcuts"));
54 myMainwinLayout = new QVBoxLayout(myMainwinBox);
55
56 myMainwinList = new QTreeWidget();
57 myMainwinList->setSelectionMode(QTreeWidget::NoSelection);
58 myMainwinList->setSelectionBehavior(QTreeWidget::SelectRows);
59 myMainwinList->setIndentation(0);
60 QStringList headers;
61 headers << tr("Action") << tr("Shortcut");
62 myMainwinList->setHeaderLabels(headers);
63 QTreeWidgetItem* item;
64 ShortcutEdit* editor;
65
66 #define ADD_MAINWINSHORTCUT(shortcut, name) \
67 item = new QTreeWidgetItem(myMainwinList); \
68 item->setText(0, name); \
69 editor = new ShortcutEdit(); \
70 connect(editor, SIGNAL(keySequenceChanged(const QKeySequence&)), SLOT(mainwinShortcutChanged(const QKeySequence&))); \
71 myMainwinShortcuts.insert(shortcut, editor); \
72 myMainwinList->setItemWidget(item, 1, editor);
73
74 ADD_MAINWINSHORTCUT(Config::Shortcuts::MainwinUserViewMessage, tr("View message from user"))
75 ADD_MAINWINSHORTCUT(Config::Shortcuts::MainwinUserSendMessage, tr("Send message to user"))
76 ADD_MAINWINSHORTCUT(Config::Shortcuts::MainwinUserSendUrl, tr("Send URL to user"))
77 ADD_MAINWINSHORTCUT(Config::Shortcuts::MainwinUserSendFile, tr("Send file to user"))
78 ADD_MAINWINSHORTCUT(Config::Shortcuts::MainwinUserSendChatRequest, tr("Send chat request to user"))
79 ADD_MAINWINSHORTCUT(Config::Shortcuts::MainwinUserCheckAutoresponse, tr("Check user auto response"))
80 ADD_MAINWINSHORTCUT(Config::Shortcuts::MainwinUserViewHistory, tr("View user history"))
81
82 ADD_MAINWINSHORTCUT(Config::Shortcuts::MainwinAccountManager, tr("Open account manager"))
83 ADD_MAINWINSHORTCUT(Config::Shortcuts::MainwinPopupAllMessages, tr("Open all unread messages"))
84 ADD_MAINWINSHORTCUT(Config::Shortcuts::MainwinPopupMessage, tr("Open next unread message"))
85 ADD_MAINWINSHORTCUT(Config::Shortcuts::MainwinAddGroup, tr("Add group"))
86 ADD_MAINWINSHORTCUT(Config::Shortcuts::MainwinEditGroups, tr("Edit groups"))
87 ADD_MAINWINSHORTCUT(Config::Shortcuts::MainwinSetAutoResponse, tr("Set auto response"))
88 ADD_MAINWINSHORTCUT(Config::Shortcuts::MainwinNetworkLog, tr("Show network log"))
89 ADD_MAINWINSHORTCUT(Config::Shortcuts::MainwinToggleMiniMode, tr("Toggle mini mode"))
90 ADD_MAINWINSHORTCUT(Config::Shortcuts::MainwinToggleShowOffline, tr("Toggle show offline users"))
91 ADD_MAINWINSHORTCUT(Config::Shortcuts::MainwinToggleEmptyGroups, tr("Toggle empty groups"))
92 ADD_MAINWINSHORTCUT(Config::Shortcuts::MainwinToggleShowHeader, tr("Toggle column headers visible"))
93 ADD_MAINWINSHORTCUT(Config::Shortcuts::MainwinSettings, tr("Open settings"))
94 ADD_MAINWINSHORTCUT(Config::Shortcuts::MainwinHide, tr("Hide contact list"))
95 ADD_MAINWINSHORTCUT(Config::Shortcuts::MainwinExit, tr("Exit Licq"))
96
97 ADD_MAINWINSHORTCUT(Config::Shortcuts::MainwinStatusOnline, tr("Switch status to Online"))
98 ADD_MAINWINSHORTCUT(Config::Shortcuts::MainwinStatusAway, tr("Switch status to Away"))
99 ADD_MAINWINSHORTCUT(Config::Shortcuts::MainwinStatusNotAvailable, tr("Switch status to N/A"))
100 ADD_MAINWINSHORTCUT(Config::Shortcuts::MainwinStatusOccupied, tr("Switch status to Occupied"))
101 ADD_MAINWINSHORTCUT(Config::Shortcuts::MainwinStatusDoNotDisturb, tr("Switch status to DND"))
102 ADD_MAINWINSHORTCUT(Config::Shortcuts::MainwinStatusFreeForChat, tr("Switch status to Free For Chat"))
103 ADD_MAINWINSHORTCUT(Config::Shortcuts::MainwinStatusOffline, tr("Switch status to Offline"))
104 ADD_MAINWINSHORTCUT(Config::Shortcuts::MainwinStatusInvisible, tr("Toggle status Invisible"))
105
106 #undef ADD_MAINWINSHORTCUT
107
108 myMainwinList->resizeColumnToContents(0);
109 myMainwinLayout->addWidget(myMainwinList);
110
111 myPageMainwinShortcutsLayout->addWidget(myMainwinBox);
112
113 return w;
114 }
115
createPageChatShortcuts(QWidget * parent)116 QWidget* Settings::Shortcuts::createPageChatShortcuts(QWidget* parent)
117 {
118 QWidget* w = new QWidget(parent);
119 myPageChatShortcutsLayout = new QVBoxLayout(w);
120 myPageChatShortcutsLayout->setContentsMargins(0, 0, 0, 0);
121
122 myChatBox = new QGroupBox(tr("Contact List Shortcuts"));
123 myChatLayout = new QVBoxLayout(myChatBox);
124
125 myChatList = new QTreeWidget();
126 myChatList->setSelectionMode(QTreeWidget::NoSelection);
127 myChatList->setSelectionBehavior(QTreeWidget::SelectRows);
128 myChatList->setIndentation(0);
129 QStringList headers;
130 headers << tr("Action") << tr("Shortcut");
131 myChatList->setHeaderLabels(headers);
132 QTreeWidgetItem* item;
133 ShortcutEdit* editor;
134
135 #define ADD_CHATSHORTCUT(shortcut, name) \
136 item = new QTreeWidgetItem(myChatList); \
137 item->setText(0, name); \
138 editor = new ShortcutEdit(); \
139 connect(editor, SIGNAL(keySequenceChanged(const QKeySequence&)), SLOT(chatShortcutChanged(const QKeySequence&))); \
140 myChatShortcuts.insert(shortcut, editor); \
141 myChatList->setItemWidget(item, 1, editor);
142
143 ADD_CHATSHORTCUT(Config::Shortcuts::ChatUserMenu, tr("Open user menu"))
144 ADD_CHATSHORTCUT(Config::Shortcuts::ChatHistory, tr("Open history"))
145 ADD_CHATSHORTCUT(Config::Shortcuts::ChatUserInfo, tr("Open user information"))
146 ADD_CHATSHORTCUT(Config::Shortcuts::ChatEncodingMenu, tr("Select encoding"))
147 ADD_CHATSHORTCUT(Config::Shortcuts::ChatToggleSecure, tr("Open / close secure channel"))
148 ADD_CHATSHORTCUT(Config::Shortcuts::ChatEventMenu, tr("Select message type"))
149 ADD_CHATSHORTCUT(Config::Shortcuts::ChatToggleSendServer, tr("Toggle send through server"))
150 ADD_CHATSHORTCUT(Config::Shortcuts::ChatToggleUrgent, tr("Toggle urgent"))
151 ADD_CHATSHORTCUT(Config::Shortcuts::ChatEmoticonMenu, tr("Insert smiley"))
152 ADD_CHATSHORTCUT(Config::Shortcuts::ChatColorFore, tr("Change text color"))
153 ADD_CHATSHORTCUT(Config::Shortcuts::ChatColorBack, tr("Change background color"))
154 ADD_CHATSHORTCUT(Config::Shortcuts::ChatPopupNextMessage, tr("Open next unread message"))
155
156 ADD_CHATSHORTCUT(Config::Shortcuts::ChatTab01, tr("Switch to tab 1"))
157 ADD_CHATSHORTCUT(Config::Shortcuts::ChatTab02, tr("Switch to tab 2"))
158 ADD_CHATSHORTCUT(Config::Shortcuts::ChatTab03, tr("Switch to tab 3"))
159 ADD_CHATSHORTCUT(Config::Shortcuts::ChatTab04, tr("Switch to tab 4"))
160 ADD_CHATSHORTCUT(Config::Shortcuts::ChatTab05, tr("Switch to tab 5"))
161 ADD_CHATSHORTCUT(Config::Shortcuts::ChatTab06, tr("Switch to tab 6"))
162 ADD_CHATSHORTCUT(Config::Shortcuts::ChatTab07, tr("Switch to tab 7"))
163 ADD_CHATSHORTCUT(Config::Shortcuts::ChatTab08, tr("Switch to tab 8"))
164 ADD_CHATSHORTCUT(Config::Shortcuts::ChatTab09, tr("Switch to tab 9"))
165 ADD_CHATSHORTCUT(Config::Shortcuts::ChatTab10, tr("Switch to tab 10"))
166
167 #undef ADD_CHATSHORTCUT
168
169 myChatList->resizeColumnToContents(0);
170 myChatLayout->addWidget(myChatList);
171
172 myPageChatShortcutsLayout->addWidget(myChatBox);
173
174 return w;
175 }
176
load()177 void Settings::Shortcuts::load()
178 {
179 Config::Shortcuts* shortcutsConfig = Config::Shortcuts::instance();
180 QMap<Config::Shortcuts::ShortcutType, ShortcutEdit*>::iterator i;
181
182 for (i = myMainwinShortcuts.begin(); i != myMainwinShortcuts.end(); ++i)
183 i.value()->setKeySequence(shortcutsConfig->getShortcut(i.key()));
184 myMainwinList->resizeColumnToContents(1);
185
186 for (i = myChatShortcuts.begin(); i != myChatShortcuts.end(); ++i)
187 i.value()->setKeySequence(shortcutsConfig->getShortcut(i.key()));
188 myChatList->resizeColumnToContents(1);
189 }
190
apply()191 void Settings::Shortcuts::apply()
192 {
193 Config::Shortcuts* shortcutsConfig = Config::Shortcuts::instance();
194 shortcutsConfig->blockUpdates(true);
195
196 QMap<Config::Shortcuts::ShortcutType, ShortcutEdit*>::iterator i;
197 for (i = myMainwinShortcuts.begin(); i != myMainwinShortcuts.end(); ++i)
198 shortcutsConfig->setShortcut(i.key(), i.value()->keySequence());
199 for (i = myChatShortcuts.begin(); i != myChatShortcuts.end(); ++i)
200 shortcutsConfig->setShortcut(i.key(), i.value()->keySequence());
201
202 shortcutsConfig->blockUpdates(false);
203 }
204
mainwinShortcutChanged(const QKeySequence & shortcut)205 void Settings::Shortcuts::mainwinShortcutChanged(const QKeySequence& shortcut)
206 {
207 // An empty shortcut is never a conflict
208 if (shortcut.isEmpty())
209 return;
210
211 // Get the action that was changed so we can except it from the check
212 ShortcutEdit* editor = dynamic_cast<ShortcutEdit*>(sender());
213 if (editor == NULL)
214 return;
215
216 // Check if shortcut is in conflict with any of the other actions
217 QMap<Config::Shortcuts::ShortcutType, ShortcutEdit*>::iterator i;
218 for (i = myMainwinShortcuts.begin(); i != myMainwinShortcuts.end(); ++i)
219 if (i.value() != editor && i.value()->keySequence() == shortcut)
220 i.value()->setKeySequence(QKeySequence());
221 }
222
chatShortcutChanged(const QKeySequence & shortcut)223 void Settings::Shortcuts::chatShortcutChanged(const QKeySequence& shortcut)
224 {
225 // An empty shortcut is never a conflict
226 if (shortcut.isEmpty())
227 return;
228
229 // Get the action that was changed so we can except it from the check
230 ShortcutEdit* editor = dynamic_cast<ShortcutEdit*>(sender());
231 if (editor == NULL)
232 return;
233
234 // Check if shortcut is in conflict with any of the other actions
235 QMap<Config::Shortcuts::ShortcutType, ShortcutEdit*>::iterator i;
236 for (i = myChatShortcuts.begin(); i != myChatShortcuts.end(); ++i)
237 if (i.value() != editor && i.value()->keySequence() == shortcut)
238 i.value()->setKeySequence(QKeySequence());
239 }
240