KUtils
kemoticonsprovider.cpp
Go to the documentation of this file.
00001 /********************************************************************************** 00002 * Copyright (C) 2008 by Carlo Segato <brandon.ml@gmail.com> * 00003 * * 00004 * This library is free software; you can redistribute it and/or * 00005 * modify it under the terms of the GNU Lesser General Public * 00006 * License as published by the Free Software Foundation; either * 00007 * version 2.1 of the License, or (at your option) any later version. * 00008 * * 00009 * This library is distributed in the hope that it will be useful, * 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00012 * Lesser General Public License for more details. * 00013 * * 00014 * You should have received a copy of the GNU Lesser General Public * 00015 * License along with this library. If not, see <http://www.gnu.org/licenses/>.* 00016 * * 00017 **********************************************************************************/ 00018 00019 #include "kemoticonsprovider.h" 00020 #include "kemoticons.h" 00021 00022 #include <QtCore/QFileInfo> 00023 #include <QtCore/QDir> 00024 #include <QtGui/QTextDocument> 00025 00026 #include <kio/netaccess.h> 00027 #include "kstandarddirs.h" 00028 #include "kdebug.h" 00029 00030 class KEmoticonsProviderPrivate 00031 { 00032 public: 00033 KEmoticonsProviderPrivate(); 00034 QString m_themeName; 00035 QString m_fileName; 00036 QString m_themePath; 00037 QHash<QString, QStringList> m_emoticonsMap; 00038 QHash<QChar, QList<KEmoticonsProvider::Emoticon> > m_emoticonsIndex; 00039 }; 00040 00041 KEmoticonsProviderPrivate::KEmoticonsProviderPrivate() 00042 { 00043 } 00044 00045 KEmoticonsProvider::KEmoticonsProvider(QObject *parent) 00046 : QObject(parent), d(new KEmoticonsProviderPrivate) 00047 { 00048 } 00049 00050 KEmoticonsProvider::~KEmoticonsProvider() 00051 { 00052 delete d; 00053 } 00054 00055 bool KEmoticonsProvider::loadTheme(const QString &path) 00056 { 00057 QFileInfo info(path); 00058 d->m_fileName = info.fileName(); 00059 d->m_themeName = info.dir().dirName(); 00060 d->m_themePath = info.absolutePath(); 00061 return true; 00062 } 00063 00064 bool KEmoticonsProvider::removeEmoticon(const QString &emo) 00065 { 00066 Q_UNUSED(emo); 00067 return false; 00068 } 00069 00070 bool KEmoticonsProvider::addEmoticon(const QString &emo, const QString &text, AddEmoticonOption option) 00071 { 00072 if (option == Copy) { 00073 KIO::NetAccess::dircopy(KUrl(emo), KUrl(d->m_themePath)); 00074 } 00075 00076 Q_UNUSED(text); 00077 return false; 00078 } 00079 00080 void KEmoticonsProvider::save() 00081 { 00082 } 00083 00084 QString KEmoticonsProvider::themeName() const 00085 { 00086 return d->m_themeName; 00087 } 00088 00089 void KEmoticonsProvider::setThemeName(const QString &name) 00090 { 00091 d->m_themeName = name; 00092 } 00093 00094 QString KEmoticonsProvider::themePath() const 00095 { 00096 return d->m_themePath; 00097 } 00098 00099 QString KEmoticonsProvider::fileName() const 00100 { 00101 return d->m_fileName; 00102 } 00103 00104 void KEmoticonsProvider::clearEmoticonsMap() 00105 { 00106 d->m_emoticonsMap.clear(); 00107 } 00108 00109 void KEmoticonsProvider::addEmoticonsMap(QString key, QStringList value) 00110 { 00111 if (!value.isEmpty()) { 00112 d->m_emoticonsMap.insert(key, value); 00113 } 00114 } 00115 00116 void KEmoticonsProvider::removeEmoticonsMap(QString key) 00117 { 00118 d->m_emoticonsMap.remove(key); 00119 } 00120 00121 QHash<QString, QStringList> KEmoticonsProvider::emoticonsMap() const 00122 { 00123 return d->m_emoticonsMap; 00124 } 00125 00126 void KEmoticonsProvider::createNew() 00127 { 00128 } 00129 00130 QHash<QChar, QList<KEmoticonsProvider::Emoticon> > KEmoticonsProvider::emoticonsIndex() const 00131 { 00132 return d->m_emoticonsIndex; 00133 } 00134 00135 void KEmoticonsProvider::addEmoticonIndex(const QString &path, const QStringList &emoList) 00136 { 00137 foreach(const QString &s, emoList) { 00138 KEmoticonsProvider::Emoticon e; 00139 QPixmap p; 00140 00141 QString escaped = Qt::escape(s); 00142 e.picPath = path; 00143 p.load(path); 00144 00145 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()); 00146 00147 e.matchTextEscaped = escaped; 00148 e.matchText = s; 00149 00150 if (!s.isEmpty() && !escaped.isEmpty()) 00151 { 00152 d->m_emoticonsIndex[escaped[0]].append(e); 00153 d->m_emoticonsIndex[s[0]].append(e); 00154 } 00155 } 00156 } 00157 00158 void KEmoticonsProvider::removeEmoticonIndex(const QString &path, const QStringList &emoList) 00159 { 00160 foreach(const QString &s, emoList) { 00161 QString escaped = Qt::escape(s); 00162 00163 if (s.isEmpty() || escaped.isEmpty()) 00164 { 00165 continue; 00166 } 00167 00168 QList<Emoticon> ls = d->m_emoticonsIndex.value(escaped[0]); 00169 00170 for (int i = 0; i < ls.size(); ++i) { 00171 if (ls.at(i).picPath == path) { 00172 ls.removeAt(i); 00173 } 00174 } 00175 00176 ls = d->m_emoticonsIndex.value(s[0]); 00177 00178 for (int i = 0; i < ls.size(); ++i) { 00179 if (ls.at(i).picPath == path) { 00180 ls.removeAt(i); 00181 } 00182 } 00183 } 00184 } 00185 00186 00187 // kate: space-indent on; indent-width 4; replace-tabs on;
KDE 4.6 API Reference