• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.11.5 API Reference
  • KDE Home
  • Contact Us
 

KUtils

  • kutils
  • kemoticons
kemoticonsprovider.cpp
Go to the documentation of this file.
1 /**********************************************************************************
2  * Copyright (C) 2008 by Carlo Segato <brandon.ml@gmail.com> *
3  * *
4  * This library is free software; you can redistribute it and/or *
5  * modify it under the terms of the GNU Lesser General Public *
6  * License as published by the Free Software Foundation; either *
7  * version 2.1 of the License, or (at your option) any later version. *
8  * *
9  * This library is distributed in the hope that it will be useful, *
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
12  * Lesser General Public License for more details. *
13  * *
14  * You should have received a copy of the GNU Lesser General Public *
15  * License along with this library. If not, see <http://www.gnu.org/licenses/>.*
16  * *
17  **********************************************************************************/
18 
19 #include "kemoticonsprovider.h"
20 #include "kemoticons.h"
21 
22 #include <QtCore/QFileInfo>
23 #include <QtCore/QDir>
24 #include <QtGui/QTextDocument>
25 
26 #include <kio/netaccess.h>
27 #include "kstandarddirs.h"
28 #include "kdebug.h"
29 
30 class KEmoticonsProviderPrivate
31 {
32 public:
33  KEmoticonsProviderPrivate();
34  QString m_themeName;
35  QString m_fileName;
36  QString m_themePath;
37  QHash<QString, QStringList> m_emoticonsMap;
38  QHash<QChar, QList<KEmoticonsProvider::Emoticon> > m_emoticonsIndex;
39 };
40 
41 KEmoticonsProviderPrivate::KEmoticonsProviderPrivate()
42 {
43 }
44 
45 KEmoticonsProvider::KEmoticonsProvider(QObject *parent)
46  : QObject(parent), d(new KEmoticonsProviderPrivate)
47 {
48 }
49 
50 KEmoticonsProvider::~KEmoticonsProvider()
51 {
52  delete d;
53 }
54 
55 bool KEmoticonsProvider::loadTheme(const QString &path)
56 {
57  QFileInfo info(path);
58  d->m_fileName = info.fileName();
59  d->m_themeName = info.dir().dirName();
60  d->m_themePath = info.absolutePath();
61  return true;
62 }
63 
64 bool KEmoticonsProvider::removeEmoticon(const QString &emo)
65 {
66  Q_UNUSED(emo);
67  return false;
68 }
69 
70 bool KEmoticonsProvider::addEmoticon(const QString &emo, const QString &text, AddEmoticonOption option)
71 {
72  if (option == Copy) {
73  KIO::NetAccess::dircopy(KUrl(emo), KUrl(d->m_themePath));
74  }
75 
76  Q_UNUSED(text);
77  return false;
78 }
79 
80 void KEmoticonsProvider::save()
81 {
82 }
83 
84 QString KEmoticonsProvider::themeName() const
85 {
86  return d->m_themeName;
87 }
88 
89 void KEmoticonsProvider::setThemeName(const QString &name)
90 {
91  d->m_themeName = name;
92 }
93 
94 QString KEmoticonsProvider::themePath() const
95 {
96  return d->m_themePath;
97 }
98 
99 QString KEmoticonsProvider::fileName() const
100 {
101  return d->m_fileName;
102 }
103 
104 void KEmoticonsProvider::clearEmoticonsMap()
105 {
106  d->m_emoticonsMap.clear();
107 }
108 
109 void KEmoticonsProvider::addEmoticonsMap(QString key, QStringList value)
110 {
111  if (!value.isEmpty()) {
112  d->m_emoticonsMap.insert(key, value);
113  }
114 }
115 
116 void KEmoticonsProvider::removeEmoticonsMap(QString key)
117 {
118  d->m_emoticonsMap.remove(key);
119 }
120 
121 QHash<QString, QStringList> KEmoticonsProvider::emoticonsMap() const
122 {
123  return d->m_emoticonsMap;
124 }
125 
126 void KEmoticonsProvider::createNew()
127 {
128 }
129 
130 QHash<QChar, QList<KEmoticonsProvider::Emoticon> > KEmoticonsProvider::emoticonsIndex() const
131 {
132  return d->m_emoticonsIndex;
133 }
134 
135 void KEmoticonsProvider::addEmoticonIndex(const QString &path, const QStringList &emoList)
136 {
137  foreach(const QString &s, emoList) {
138  KEmoticonsProvider::Emoticon e;
139  QPixmap p;
140 
141  QString escaped = Qt::escape(s);
142  e.picPath = path;
143  p.load(path);
144 
145  e.picHTMLCode = QString("<img align=\"center\" title=\"%1\" alt=\"%1\" src=\"%2\" width=\"%3\" height=\"%4\" />").arg(escaped).arg(path).arg(p.width()).arg(p.height());
146 
147  e.matchTextEscaped = escaped;
148  e.matchText = s;
149 
150  if (!s.isEmpty() && !escaped.isEmpty())
151  {
152  d->m_emoticonsIndex[escaped[0]].append(e);
153  d->m_emoticonsIndex[s[0]].append(e);
154  }
155  }
156 }
157 
158 void KEmoticonsProvider::removeEmoticonIndex(const QString &path, const QStringList &emoList)
159 {
160  foreach(const QString &s, emoList) {
161  QString escaped = Qt::escape(s);
162 
163  if (s.isEmpty() || escaped.isEmpty())
164  {
165  continue;
166  }
167 
168  QList<Emoticon> ls = d->m_emoticonsIndex.value(escaped[0]);
169 
170  for (int i = 0; i < ls.size(); ++i) {
171  if (ls.at(i).picPath == path) {
172  ls.removeAt(i);
173  }
174  }
175 
176  ls = d->m_emoticonsIndex.value(s[0]);
177 
178  for (int i = 0; i < ls.size(); ++i) {
179  if (ls.at(i).picPath == path) {
180  ls.removeAt(i);
181  }
182  }
183  }
184 }
185 
186 
187 // kate: space-indent on; indent-width 4; replace-tabs on;
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Thu Sep 25 2014 04:20:50 by doxygen 1.8.3.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KUtils

Skip menu "KUtils"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.11.5 API Reference

Skip menu "kdelibs-4.11.5 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal