[SCM] ktp-text-ui packaging branch, master, updated. debian/15.12.1-1-1918-gdf4b0ec
Maximiliano Curia
maxy at moszumanska.debian.org
Sat May 28 00:25:26 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-text-ui.git;a=commitdiff;h=e746a43
The following commit has been merged in the master branch:
commit e746a43972a4a52e6d8bc60b63c08082e442145b
Author: David Rosca <nowrep at gmail.com>
Date: Thu Jul 16 17:27:16 2015 +0200
Add option to use different emoticons for each account
The ui to set the emoticons is accessible from emoticons filter plugin
settings.
REVIEW: 123893
---
app/emoticon-text-edit-action.cpp | 9 +-
app/emoticon-text-edit-action.h | 4 +-
app/emoticon-text-edit-selector.cpp | 18 +-
app/emoticon-text-edit-selector.h | 4 +-
filters/emoticons/CMakeLists.txt | 21 ++
filters/emoticons/emoticon-config.cpp | 247 +++++++++++++++++++++
filters/emoticons/emoticon-config.h | 54 +++++
filters/emoticons/emoticon-config.ui | 73 ++++++
filters/emoticons/emoticon-filter.cpp | 13 +-
filters/emoticons/emoticon-filter.h | 3 -
.../kcm_ktptextui_message_filter_emoticons.desktop | 9 +
lib/CMakeLists.txt | 1 +
lib/emoticons-manager.cpp | 59 +++++
.../imgursharer.h => lib/emoticons-manager.h | 26 +--
14 files changed, 500 insertions(+), 41 deletions(-)
diff --git a/app/emoticon-text-edit-action.cpp b/app/emoticon-text-edit-action.cpp
index 2ee628e..13b6686 100644
--- a/app/emoticon-text-edit-action.cpp
+++ b/app/emoticon-text-edit-action.cpp
@@ -19,6 +19,7 @@
*/
#include "emoticon-text-edit-action.h"
#include "emoticon-text-edit-selector.h"
+#include "chat-window.h"
#include <KLocalizedString>
@@ -29,9 +30,9 @@
class EmoticonTextEditAction::EmoticonTextEditActionPrivate
{
public:
- EmoticonTextEditActionPrivate() {
+ EmoticonTextEditActionPrivate( ChatWindow *chatWindow ) {
emoticonMenu = new QMenu();
- selector = new EmoticonTextEditSelector( emoticonMenu );
+ selector = new EmoticonTextEditSelector( chatWindow , emoticonMenu );
QWidgetAction *action = new QWidgetAction( emoticonMenu );
action->setDefaultWidget( selector );
emoticonMenu->addAction( action );
@@ -46,8 +47,8 @@ public:
EmoticonTextEditSelector *selector;
};
-EmoticonTextEditAction::EmoticonTextEditAction( QObject * parent )
- : KActionMenu( i18n( "Add Smiley" ), parent ), d( new EmoticonTextEditActionPrivate() )
+EmoticonTextEditAction::EmoticonTextEditAction( ChatWindow * chatWindow )
+ : KActionMenu( i18n( "Add Smiley" ), chatWindow ), d( new EmoticonTextEditActionPrivate( chatWindow ) )
{
setMenu( d->emoticonMenu );
setIcon( QIcon::fromTheme( QStringLiteral( "face-smile" ) ) );
diff --git a/app/emoticon-text-edit-action.h b/app/emoticon-text-edit-action.h
index a5ae531..bb61e33 100644
--- a/app/emoticon-text-edit-action.h
+++ b/app/emoticon-text-edit-action.h
@@ -23,11 +23,13 @@
#include <KActionMenu>
+class ChatWindow;
+
class EmoticonTextEditAction : public KActionMenu
{
Q_OBJECT
public:
- explicit EmoticonTextEditAction( QObject * parent );
+ explicit EmoticonTextEditAction( ChatWindow * chatWindow );
~EmoticonTextEditAction();
Q_SIGNALS:
void emoticonActivated(const QString&);
diff --git a/app/emoticon-text-edit-selector.cpp b/app/emoticon-text-edit-selector.cpp
index 22742fb..387e239 100644
--- a/app/emoticon-text-edit-selector.cpp
+++ b/app/emoticon-text-edit-selector.cpp
@@ -19,6 +19,9 @@
*/
#include "emoticon-text-edit-selector.h"
+#include "emoticons-manager.h"
+#include "chat-window.h"
+#include "chat-tab.h"
#include <KEmoticons>
#include <kemoticonstheme.h>
@@ -27,9 +30,6 @@
#include <QPixmap>
#include <QHBoxLayout>
-// Use a static for this as calls to the KEmoticons constructor are expensive.
-Q_GLOBAL_STATIC( KEmoticons, sEmoticons )
-
EmoticonTextEditItem::EmoticonTextEditItem(const QString &emoticonText, const QString &pixmapPath, QListWidget *parent)
: QListWidgetItem( parent )
{
@@ -63,11 +63,13 @@ public:
EmoticonTextEditSelectorPrivate() {
}
QListWidget *listEmoticon;
+ ChatWindow *chatWindow;
};
-EmoticonTextEditSelector::EmoticonTextEditSelector( QWidget * parent )
+EmoticonTextEditSelector::EmoticonTextEditSelector( ChatWindow *chatWindow, QWidget * parent )
:QWidget( parent ), d( new EmoticonTextEditSelectorPrivate() )
{
+ d->chatWindow = chatWindow;
QHBoxLayout *lay = new QHBoxLayout( this );
lay->setSpacing( 0 );
lay->setContentsMargins( 0, 0, 0, 0 );
@@ -91,11 +93,9 @@ EmoticonTextEditSelector::~EmoticonTextEditSelector()
void EmoticonTextEditSelector::slotCreateEmoticonList()
{
d->listEmoticon->clear();
- static QString cachedEmoticonsThemeName;
- if ( cachedEmoticonsThemeName.isEmpty() ) {
- cachedEmoticonsThemeName = KEmoticons::currentThemeName();
- }
- const QHash<QString, QStringList> list = sEmoticons->theme( cachedEmoticonsThemeName ).emoticonsMap();
+
+ Tp::AccountPtr currentAccount = d->chatWindow->getCurrentTab()->account();
+ const QHash<QString, QStringList> list = EmoticonsManager::themeForAccount( currentAccount ).emoticonsMap();
QStringList emoticonKeys = list.keys();
qSort(emoticonKeys);
diff --git a/app/emoticon-text-edit-selector.h b/app/emoticon-text-edit-selector.h
index fb1584f..ab1e610 100644
--- a/app/emoticon-text-edit-selector.h
+++ b/app/emoticon-text-edit-selector.h
@@ -24,6 +24,8 @@
#include <QWidget>
#include <QListWidgetItem>
+class ChatWindow;
+
class EmoticonTextEditItem : public QListWidgetItem
{
public:
@@ -41,7 +43,7 @@ class EmoticonTextEditSelector : public QWidget
{
Q_OBJECT
public:
- explicit EmoticonTextEditSelector( QWidget * parent = 0 );
+ explicit EmoticonTextEditSelector( ChatWindow *chatWindow, QWidget * parent = Q_NULLPTR );
~EmoticonTextEditSelector();
public Q_SLOTS:
diff --git a/filters/emoticons/CMakeLists.txt b/filters/emoticons/CMakeLists.txt
index 447b223..4cebe93 100644
--- a/filters/emoticons/CMakeLists.txt
+++ b/filters/emoticons/CMakeLists.txt
@@ -1,13 +1,33 @@
add_library (ktptextui_message_filter_emoticons MODULE emoticon-filter.cpp)
target_link_libraries (ktptextui_message_filter_emoticons
+ ktpchat
KF5::Emoticons
KF5::CoreAddons
KTp::CommonInternals
)
+ki18n_wrap_ui(kcm_ktptextui_message_filter_emoticons_SRCS
+ emoticon-config.ui
+)
+
+add_library(kcm_ktptextui_message_filter_emoticons MODULE emoticon-config.cpp
+ ${kcm_ktptextui_message_filter_emoticons_SRCS}
+)
+
+kcoreaddons_desktop_to_json(kcm_ktptextui_message_filter_emoticons kcm_ktptextui_message_filter_emoticons.desktop)
+
+target_link_libraries (kcm_ktptextui_message_filter_emoticons
+ ktpchat
+ KF5::KCMUtils
+ KF5::ItemViews
+ KF5::Emoticons
+ KTp::CommonInternals
+)
+
# Install:
install (TARGETS ktptextui_message_filter_emoticons
+ kcm_ktptextui_message_filter_emoticons
DESTINATION ${PLUGIN_INSTALL_DIR}
)
@@ -16,5 +36,6 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/ktptextui_message_filter_emoticons.de
@ONLY)
install (FILES ${CMAKE_CURRENT_BINARY_DIR}/ktptextui_message_filter_emoticons.desktop
+ ${CMAKE_CURRENT_SOURCE_DIR}/kcm_ktptextui_message_filter_emoticons.desktop
DESTINATION ${SERVICES_INSTALL_DIR}
)
diff --git a/filters/emoticons/emoticon-config.cpp b/filters/emoticons/emoticon-config.cpp
new file mode 100644
index 0000000..5b446a8
--- /dev/null
+++ b/filters/emoticons/emoticon-config.cpp
@@ -0,0 +1,247 @@
+/*
+ * Copyright (C) 2015 David Rosca <nowrep at gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "emoticon-config.h"
+
+#include <QLabel>
+#include <QComboBox>
+#include <QInputDialog>
+#include <QListWidgetItem>
+
+#include <KEmoticons>
+#include <KEmoticonsTheme>
+#include <KConfigGroup>
+#include <KPluginFactory>
+#include <KLocalizedString>
+#include <KWidgetItemDelegate>
+
+#include <KTp/core.h>
+#include <TelepathyQt/AccountSet>
+#include <TelepathyQt/AccountManager>
+
+K_PLUGIN_FACTORY_WITH_JSON(EmoticonConfigFactory,
+ "kcm_ktptextui_message_filter_emoticons.json",
+ registerPlugin<EmoticonFilterConfig>();)
+
+enum {
+ AccountNameRole = Qt::UserRole + 10,
+ AccountIdRole = Qt::UserRole + 11,
+ EmoticonsThemeRole = Qt::UserRole + 12
+};
+
+static QIcon previewEmoticon(const KEmoticonsTheme &theme)
+{
+ QString path = theme.tokenize(QStringLiteral(":)"))[0].picPath;
+ if (path.isEmpty()) {
+ path = theme.emoticonsMap().keys().value(0);
+ }
+ return QIcon(path);
+}
+
+class ItemDelegate : public KWidgetItemDelegate
+{
+ Q_OBJECT
+
+public:
+ explicit ItemDelegate(QAbstractItemView *itemView, QObject *parent = Q_NULLPTR)
+ : KWidgetItemDelegate(itemView, parent)
+ , m_comboBox(new QComboBox())
+ {
+ // For size calculation in sizeHint()
+ m_comboBox->addItem(previewEmoticon(m_emoticons.theme()), QStringLiteral("name"));
+ }
+
+ QList<QWidget*> createItemWidgets(const QModelIndex &index) const Q_DECL_OVERRIDE
+ {
+ Q_UNUSED(index);
+
+ QComboBox *comboBox = new QComboBox();
+ connect(comboBox, &QComboBox::currentTextChanged, this, &ItemDelegate::comboBoxCurrentTextChanged);
+
+ for (const QString &name : m_emoticons.themeList()) {
+ KEmoticonsTheme theme = m_emoticons.theme(name);
+ comboBox->addItem(previewEmoticon(theme), theme.themeName());
+ }
+
+ return {comboBox};
+ }
+
+ void updateItemWidgets(const QList<QWidget*> widgets, const QStyleOptionViewItem &option, const QPersistentModelIndex &index) const Q_DECL_OVERRIDE
+ {
+ const int margin = option.fontMetrics.height() / 2;
+ QComboBox *comboBox = static_cast<QComboBox*>(widgets.at(0));
+ comboBox->move((option.rect.width() + margin) / 2, margin);
+ comboBox->resize(option.rect.width() / 2 - margin, comboBox->sizeHint().height());
+ comboBox->setCurrentText(index.data(EmoticonsThemeRole).toString());
+ }
+
+ void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE
+ {
+ QStyle *style = itemView()->style();
+ const int margin = option.fontMetrics.height() / 2;
+ const QPalette::ColorRole colorRole = option.state & QStyle::State_Selected ? QPalette::HighlightedText : QPalette::Text;
+
+ style->drawPrimitive(QStyle::PE_PanelItemViewItem, &option, painter);
+
+ QRect textRect = option.rect;
+ textRect.setWidth(textRect.width() / 2 - margin);
+ textRect.setX(textRect.x() + margin);
+ const QString text = elidedText(option.fontMetrics, textRect.width(), Qt::ElideRight, index.data(AccountNameRole).toString());
+ style->drawItemText(painter, textRect, Qt::AlignLeft | Qt::AlignVCenter, option.palette, true, text, colorRole);
+ }
+
+ QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const Q_DECL_OVERRIDE
+ {
+ Q_UNUSED(index);
+ Q_UNUSED(option);
+
+ const int margin = option.fontMetrics.height() / 2;
+ QSize size;
+ size.setWidth(m_comboBox->sizeHint().width() * 2 + 3 * margin);
+ size.setHeight(m_comboBox->sizeHint().height() + 2 * margin);
+ return size;
+ }
+
+Q_SIGNALS:
+ void dataChanged(const QModelIndex &index, int role, const QVariant &data);
+
+private Q_SLOTS:
+ void comboBoxCurrentTextChanged(const QString &themeName)
+ {
+ Q_EMIT dataChanged(focusedIndex(), EmoticonsThemeRole, themeName);
+ }
+
+private:
+ QComboBox *m_comboBox;
+ KEmoticons m_emoticons;
+};
+
+EmoticonFilterConfig::EmoticonFilterConfig(QWidget *parent, const QVariantList &args)
+ : KCModule(parent, args)
+ , m_config(KSharedConfig::openConfig(QStringLiteral("ktp-text-uirc")))
+{
+ ui.setupUi(this);
+
+ ItemDelegate *delegate = new ItemDelegate(ui.listWidget, this);
+ ui.listWidget->setItemDelegate(delegate);
+
+ connect(delegate, &ItemDelegate::dataChanged, this, &EmoticonFilterConfig::dataChanged);
+ connect(ui.addBtn, &QPushButton::clicked, this, &EmoticonFilterConfig::addClicked);
+ connect(ui.removeBtn, &QPushButton::clicked, this, &EmoticonFilterConfig::removeClicked);
+ connect(ui.listWidget, &QListWidget::currentItemChanged, this, &EmoticonFilterConfig::updateButtons);
+ connect(ui.listWidget, &QListWidget::itemSelectionChanged, this, &EmoticonFilterConfig::updateButtons);
+}
+
+void EmoticonFilterConfig::load()
+{
+ for (const Tp::AccountPtr &account : KTp::accountManager()->validAccounts()->accounts()) {
+ const QString name = account->normalizedName().isEmpty() ? account->displayName() : account->normalizedName();
+ m_accounts[account->uniqueIdentifier()] = name;
+ }
+
+ KConfigGroup group = m_config->group("Filter-Emoticons");
+ for (const QString &key : group.keyList()) {
+ if (!m_accounts.contains(key)) {
+ continue;
+ }
+ QListWidgetItem *item = new QListWidgetItem();
+ item->setData(AccountIdRole, key);
+ item->setData(AccountNameRole, m_accounts.value(key));
+ item->setData(EmoticonsThemeRole, group.readEntry<QString>(key, QString()));
+ ui.listWidget->addItem(item);
+ }
+
+ updateButtons();
+}
+
+void EmoticonFilterConfig::save()
+{
+ KConfigGroup group = m_config->group("Filter-Emoticons");
+ group.deleteGroup();
+
+ for (int i = 0; i < ui.listWidget->count(); ++i) {
+ QListWidgetItem *item = ui.listWidget->item(i);
+ group.writeEntry<QString>(item->data(AccountIdRole).toString(), item->data(EmoticonsThemeRole).toString());
+ }
+
+ m_config->sync();
+}
+
+void EmoticonFilterConfig::defaults()
+{
+ ui.listWidget->clear();
+ load();
+}
+
+void EmoticonFilterConfig::addClicked()
+{
+ const QString account = QInputDialog::getItem(this, i18n("Add account"), i18n("Select account:"), accountsNotInList(), 0, false);
+ if (account.isEmpty()) {
+ return;
+ }
+
+ QListWidgetItem *item = new QListWidgetItem();
+ item->setData(AccountIdRole, m_accounts.key(account));
+ item->setData(AccountNameRole, account);
+ item->setData(EmoticonsThemeRole, KEmoticons::currentThemeName());
+ ui.listWidget->addItem(item);
+
+ updateButtons();
+ Q_EMIT changed();
+}
+
+void EmoticonFilterConfig::removeClicked()
+{
+ QListWidgetItem *item = ui.listWidget->currentItem();
+ if (!item) {
+ return;
+ }
+
+ delete item;
+ updateButtons();
+ Q_EMIT changed();
+}
+
+void EmoticonFilterConfig::dataChanged(const QModelIndex &index, int role, const QVariant &data)
+{
+ QListWidgetItem *item = ui.listWidget->item(index.row());
+ if (!item) {
+ return;
+ }
+
+ item->setData(role, data);
+ Q_EMIT changed();
+}
+
+void EmoticonFilterConfig::updateButtons()
+{
+ ui.addBtn->setEnabled(!accountsNotInList().isEmpty());
+ ui.removeBtn->setEnabled(!ui.listWidget->selectedItems().isEmpty());
+}
+
+QStringList EmoticonFilterConfig::accountsNotInList() const
+{
+ QStringList names = m_accounts.values();
+ for (int i = 0; i < ui.listWidget->count(); ++i) {
+ QListWidgetItem *item = ui.listWidget->item(i);
+ names.removeOne(item->data(AccountNameRole).toString());
+ }
+ return names;
+}
+
+#include "emoticon-config.moc"
diff --git a/filters/emoticons/emoticon-config.h b/filters/emoticons/emoticon-config.h
new file mode 100644
index 0000000..bd55dd1
--- /dev/null
+++ b/filters/emoticons/emoticon-config.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2015 David Rosca <nowrep at gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef EMOTICON_CONFIG_H
+#define EMOTICON_CONFIG_H
+
+#include <QHash>
+
+#include <KCModule>
+#include <KSharedConfig>
+
+#include "ui_emoticon-config.h"
+
+class EmoticonFilterConfig : public KCModule
+{
+ Q_OBJECT
+
+public:
+ explicit EmoticonFilterConfig(QWidget *parent = Q_NULLPTR, const QVariantList &args = QVariantList());
+
+ void load() Q_DECL_OVERRIDE;
+ void save() Q_DECL_OVERRIDE;
+ void defaults() Q_DECL_OVERRIDE;
+
+private Q_SLOTS:
+ void addClicked();
+ void removeClicked();
+ void dataChanged(const QModelIndex &index, int role, const QVariant &data);
+ void updateButtons();
+
+private:
+ QStringList accountsNotInList() const;
+
+ Ui::EmoticonConfig ui;
+ KSharedConfig::Ptr m_config;
+ QHash<QString, QString> m_accounts;
+};
+
+#endif // EMOTICON_CONFIG_H
diff --git a/filters/emoticons/emoticon-config.ui b/filters/emoticons/emoticon-config.ui
new file mode 100644
index 0000000..28bbad2
--- /dev/null
+++ b/filters/emoticons/emoticon-config.ui
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>EmoticonConfig</class>
+ <widget class="QWidget" name="EmoticonConfig">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>470</width>
+ <height>300</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>LatexConfig</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Custom emoticons for account:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QListWidget" name="listWidget"/>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="addBtn">
+ <property name="text">
+ <string/>
+ </property>
+ <property name="icon">
+ <iconset theme="list-add">
+ <normaloff>../../../kaccounts-integration/src</normaloff>../../../kaccounts-integration/src</iconset>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="removeBtn">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string/>
+ </property>
+ <property name="icon">
+ <iconset theme="list-remove">
+ <normaloff>../../../kaccounts-integration/src</normaloff>../../../kaccounts-integration/src</iconset>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/filters/emoticons/emoticon-filter.cpp b/filters/emoticons/emoticon-filter.cpp
index 565ae84..b758303 100644
--- a/filters/emoticons/emoticon-filter.cpp
+++ b/filters/emoticons/emoticon-filter.cpp
@@ -17,31 +17,24 @@
*/
#include "emoticon-filter.h"
+#include "emoticons-manager.h"
#include <KPluginFactory>
#include <KEmoticons>
-class EmoticonFilter::Private
-{
-public:
- KEmoticons emoticons;
-};
-
EmoticonFilter::EmoticonFilter(QObject *parent, const QVariantList &)
- : KTp::AbstractMessageFilter(parent),
- d(new Private)
+ : KTp::AbstractMessageFilter(parent)
{
}
void EmoticonFilter::filterMessage(KTp::Message &message, const KTp::MessageContext &context)
{
Q_UNUSED(context)
- message.setMainMessagePart(d->emoticons.theme().parseEmoticons(message.mainMessagePart()));
+ message.setMainMessagePart(EmoticonsManager::themeForAccount(context.account()).parseEmoticons(message.mainMessagePart()));
}
EmoticonFilter::~EmoticonFilter()
{
- delete d;
}
K_PLUGIN_FACTORY(MessageFilterFactory, registerPlugin<EmoticonFilter>();)
diff --git a/filters/emoticons/emoticon-filter.h b/filters/emoticons/emoticon-filter.h
index 0f5a1ec..fa1442c 100644
--- a/filters/emoticons/emoticon-filter.h
+++ b/filters/emoticons/emoticon-filter.h
@@ -30,9 +30,6 @@ public:
virtual ~EmoticonFilter();
void filterMessage(KTp::Message &message, const KTp::MessageContext &context);
-private:
- class Private;
- Private *d;
};
#endif
diff --git a/filters/emoticons/kcm_ktptextui_message_filter_emoticons.desktop b/filters/emoticons/kcm_ktptextui_message_filter_emoticons.desktop
new file mode 100644
index 0000000..a247383
--- /dev/null
+++ b/filters/emoticons/kcm_ktptextui_message_filter_emoticons.desktop
@@ -0,0 +1,9 @@
+[Desktop Entry]
+Type=Service
+X-KDE-ServiceTypes=KCModule
+
+X-KDE-Library=kcm_ktptextui_message_filter_emoticons
+X-KDE-ParentApp=emoticons
+X-KDE-ParentComponents=emoticons
+
+Name=Emoticons
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index d6af848..5294521 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -23,6 +23,7 @@ set(ktpchat_SRCS
authenticationwizard.cpp
otr-notifications.cpp
ktp-debug.cpp
+ emoticons-manager.cpp
)
set(ktpchat_UI
diff --git a/lib/emoticons-manager.cpp b/lib/emoticons-manager.cpp
new file mode 100644
index 0000000..fb2a83c
--- /dev/null
+++ b/lib/emoticons-manager.cpp
@@ -0,0 +1,59 @@
+/*
+ * Emoticons Manager
+ *
+ * Copyright (C) 2015 David Rosca <nowrep at gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "emoticons-manager.h"
+
+#include <KEmoticons>
+#include <KConfigGroup>
+#include <KSharedConfig>
+
+class EmoticonsManagerPrivate
+{
+public:
+ EmoticonsManagerPrivate()
+ {
+ config = KSharedConfig::openConfig(QStringLiteral("ktp-text-uirc"));
+ }
+
+ KEmoticons emoticons;
+ KSharedConfig::Ptr config;
+ QHash<QString, KEmoticonsTheme> themeHash;
+};
+
+Q_GLOBAL_STATIC(EmoticonsManagerPrivate, sPrivate)
+
+// static
+KEmoticonsTheme EmoticonsManager::themeForAccount(const Tp::AccountPtr &account)
+{
+ const QString id = account->uniqueIdentifier();
+
+ if (!sPrivate->themeHash.contains(id)) {
+ KConfigGroup group = sPrivate->config->group("Filter-Emoticons");
+ QString themeName = group.readEntry<QString>(id, QString());
+
+ if (themeName.isEmpty()) {
+ themeName = sPrivate->emoticons.currentThemeName();
+ }
+
+ sPrivate->themeHash.insert(id, sPrivate->emoticons.theme(themeName));
+ }
+
+ return sPrivate->themeHash.value(id);
+}
diff --git a/image-sharer/imgursharer.h b/lib/emoticons-manager.h
similarity index 59%
copy from image-sharer/imgursharer.h
copy to lib/emoticons-manager.h
index e6121ff..128ab11 100644
--- a/image-sharer/imgursharer.h
+++ b/lib/emoticons-manager.h
@@ -1,5 +1,7 @@
/*
- * Copyright (C) 2014 Ahmed I. Khalil <ahmedibrahimkhali at gmail.com>
+ * Emoticons Manager
+ *
+ * Copyright (C) 2015 David Rosca <nowrep at gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -13,23 +15,21 @@
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef IMGURSHARER_H
-#define IMGURSHARER_H
+#ifndef EMOTICONS_MANAGER_H
+#define EMOTICONS_MANAGER_H
-#include "abstractsharer.h"
+#include <TelepathyQt/Account>
+#include "ktpchat_export.h"
-class ImgurSharer : public AbstractSharer
+class KEmoticonsTheme;
+
+class KDE_TELEPATHY_CHAT_EXPORT EmoticonsManager
{
public:
- ImgurSharer(const QString& contentPath);
-
- QUrl url() const;
- QByteArray postBody(const QByteArray &imageData);
- virtual void parseResponse(const QByteArray& responseData);
+ static KEmoticonsTheme themeForAccount(const Tp::AccountPtr &account);
};
-#endif // IMGURSHARER_H
+#endif
--
ktp-text-ui packaging
More information about the pkg-kde-commits
mailing list