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

KUtils

  • sources
  • kde-4.12
  • kdelibs
  • 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;
KEmoticonsProvider::Emoticon::picHTMLCode
QString picHTMLCode
Definition: kemoticonsprovider.h:47
KEmoticonsProvider::Emoticon::picPath
QString picPath
Definition: kemoticonsprovider.h:46
KEmoticonsProvider::addEmoticonIndex
void addEmoticonIndex(const QString &path, const QStringList &emoList)
Add an emoticon to the index.
Definition: kemoticonsprovider.cpp:135
KEmoticonsProvider::fileName
QString fileName() const
Returns the file name of the theme.
Definition: kemoticonsprovider.cpp:99
KEmoticonsProvider::emoticonsIndex
QHash< QChar, QList< Emoticon > > emoticonsIndex() const
Returns a QHash that contains emoticons indexed by the first char.
Definition: kemoticonsprovider.cpp:130
netaccess.h
kdebug.h
KEmoticonsProvider::Copy
< Copy the emoticon file into the theme directory
Definition: kemoticonsprovider.h:55
KEmoticonsProvider::Emoticon::matchTextEscaped
QString matchTextEscaped
Definition: kemoticonsprovider.h:45
QString
QHash< QString, QStringList >
kemoticonsprovider.h
QObject
KUrl
KEmoticonsProvider::KEmoticonsProvider
KEmoticonsProvider(QObject *parent=0)
Default constructor.
Definition: kemoticonsprovider.cpp:45
kemoticons.h
KEmoticonsProvider::emoticonsMap
QHash< QString, QStringList > emoticonsMap() const
Returns a QHash that contains the emoticons path as keys and the text as values.
Definition: kemoticonsprovider.cpp:121
KEmoticonsProvider::addEmoticonsMap
void addEmoticonsMap(QString key, QStringList value)
Insert a new item in the emoticons map.
Definition: kemoticonsprovider.cpp:109
KIO::NetAccess::dircopy
static bool dircopy(const KUrl &src, const KUrl &target, QWidget *window)
QStringList
KEmoticonsProvider::removeEmoticonsMap
void removeEmoticonsMap(QString key)
Remove an item from the emoticons map.
Definition: kemoticonsprovider.cpp:116
KEmoticonsProvider::removeEmoticonIndex
void removeEmoticonIndex(const QString &path, const QStringList &emoList)
Remove an emoticon from the index.
Definition: kemoticonsprovider.cpp:158
KEmoticonsProvider::loadTheme
virtual bool loadTheme(const QString &path)
Load the theme inside the directory path.
Definition: kemoticonsprovider.cpp:55
KEmoticonsProvider::themePath
QString themePath() const
Returns the theme path.
Definition: kemoticonsprovider.cpp:94
KEmoticonsProvider::save
virtual void save()
Save the emoticon theme.
Definition: kemoticonsprovider.cpp:80
KEmoticonsProvider::~KEmoticonsProvider
virtual ~KEmoticonsProvider()
Destructor.
Definition: kemoticonsprovider.cpp:50
KEmoticonsProvider::Emoticon::matchText
QString matchText
Definition: kemoticonsprovider.h:44
KEmoticonsProvider::Emoticon
Definition: kemoticonsprovider.h:39
kstandarddirs.h
KEmoticonsProvider::d
KEmoticonsProviderPrivate *const d
Private class.
Definition: kemoticonsprovider.h:164
KEmoticonsProvider::removeEmoticon
virtual bool removeEmoticon(const QString &emo)
Remove the emoticon emo, this will not delete the image file too.
Definition: kemoticonsprovider.cpp:64
KEmoticonsProvider::AddEmoticonOption
AddEmoticonOption
Options to pass to addEmoticon.
Definition: kemoticonsprovider.h:53
KEmoticonsProvider::createNew
virtual void createNew()
Create a new theme.
Definition: kemoticonsprovider.cpp:126
KEmoticonsProvider::clearEmoticonsMap
void clearEmoticonsMap()
Clears the emoticons map.
Definition: kemoticonsprovider.cpp:104
KEmoticonsProvider::addEmoticon
virtual bool addEmoticon(const QString &emo, const QString &text, AddEmoticonOption option=DoNotCopy)
Add the emoticon emo with text text.
Definition: kemoticonsprovider.cpp:70
QList
Definition: dialog.h:29
KEmoticonsProvider::setThemeName
void setThemeName(const QString &name)
Set the theme name.
Definition: kemoticonsprovider.cpp:89
KEmoticonsProvider::themeName
QString themeName() const
Returns the theme name.
Definition: kemoticonsprovider.cpp:84
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:50:34 by doxygen 1.8.7 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 API Reference

Skip menu "kdelibs 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
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



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