1 /*
2 * %kadu copyright begin%
3 * Copyright 2013 Bartosz Brachaczek (b.brachaczek@gmail.com)
4 * Copyright 2012, 2013, 2014 Rafał Przemysław Malinowski (rafal.przemyslaw.malinowski@gmail.com)
5 * %kadu copyright end%
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "configuration/configuration.h"
22 #include "configuration/deprecated-configuration-api.h"
23 #include "gui/actions/action.h"
24 #include "gui/widgets/chat-edit-box.h"
25
26 #include "configuration/emoticon-configuration.h"
27 #include "expander/animated-emoticon-path-provider.h"
28 #include "expander/static-emoticon-path-provider.h"
29 #include "gui/emoticon-selector.h"
30
31 #include "insert-emoticon-action.h"
32
InsertEmoticonAction(QObject * parent)33 InsertEmoticonAction::InsertEmoticonAction(QObject *parent) :
34 ActionDescription(parent)
35 {
36 setType(ActionDescription::TypeChat);
37 setName("insertEmoticonAction");
38 setIcon(KaduIcon("face-smile"));
39 setText(tr("Insert Emoticon"));
40 }
41
~InsertEmoticonAction()42 InsertEmoticonAction::~InsertEmoticonAction()
43 {
44 }
45
actionInstanceCreated(Action * action)46 void InsertEmoticonAction::actionInstanceCreated(Action *action)
47 {
48 ActionDescription::actionInstanceCreated(action);
49
50 updateActionState(action);
51 }
52
updateActionState(Action * action)53 void InsertEmoticonAction::updateActionState(Action *action)
54 {
55 ActionDescription::updateActionState(action);
56
57 if (Configuration.enabled())
58 {
59 action->setToolTip(tr("Insert emoticon"));
60 action->setEnabled(true);
61 }
62 else
63 {
64 action->setToolTip(tr("Insert emoticon - enable in configuration"));
65 action->setEnabled(false);
66 }
67 }
68
actionTriggered(QAction * sender,bool toggled)69 void InsertEmoticonAction::actionTriggered(QAction *sender, bool toggled)
70 {
71 Q_UNUSED(toggled)
72
73 ChatEditBox *chatEditBox = qobject_cast<ChatEditBox *>(sender->parent());
74 if (!chatEditBox)
75 return;
76
77 QList<QWidget *> widgets = sender->associatedWidgets();
78 if (widgets.isEmpty())
79 return;
80
81 if (Configuration.emoticonTheme().emoticons().isEmpty())
82 return;
83
84 EmoticonPathProvider *emoticonPathProvider = Configuration.animate()
85 ? static_cast<EmoticonPathProvider *>(new AnimatedEmoticonPathProvider())
86 : static_cast<EmoticonPathProvider *>(new StaticEmoticonPathProvider());
87
88 EmoticonSelector *emoticonSelector = new EmoticonSelector(Configuration.emoticonTheme().emoticons(), emoticonPathProvider,
89 widgets.at(widgets.size() - 1));
90 connect(emoticonSelector, SIGNAL(emoticonClicked(QString)), chatEditBox, SLOT(insertPlainText(QString)));
91 emoticonSelector->show();
92 }
93
setConfiguration(const EmoticonConfiguration & configuration)94 void InsertEmoticonAction::setConfiguration(const EmoticonConfiguration &configuration)
95 {
96 Configuration = configuration;
97
98 foreach (Action *action, actions())
99 updateActionState(action);
100 }
101
102 #include "moc_insert-emoticon-action.cpp"
103