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

kopete/libkopete

  • sources
  • kde-4.14
  • kdenetwork
  • kopete
  • libkopete
kopetefileengine.cpp
Go to the documentation of this file.
1 /*
2 * kopetefileengine.h - Kopete file engine
3 *
4 * Copyright (c) 2007 by Guillermo A. Amaral B <me@guillermoamaral.com>
5 * Kopete (c) 2007 by the Kopete developers <kopete-devel@kde.org>
6 *
7 * Based on Kopete Mime Source Factory
8 * Copyright (c) 2004 by Richard Smith <kde@metafoo.co.uk>
9 *
10 *************************************************************************
11 * *
12 * This library is free software; you can redistribute it and/or *
13 * modify it under the terms of the GNU Lesser General Public *
14 * License as published by the Free Software Foundation; either *
15 * version 2 of the License, or (at your option) any later version. *
16 * *
17 *************************************************************************
18 */
19 
20 #include "kopetefileengine.h"
21 
22 #include "kopeteaccountmanager.h"
23 #include "kopetecontactlist.h"
24 #include "kopeteaccount.h"
25 #include "kopetecontact.h"
26 #include "kopetemetacontact.h"
27 #include "kopetepicture.h"
28 
29 #include <kdebug.h>
30 #include <kiconloader.h>
31 
32 #include <QPixmap>
33 #include <qdiriterator.h>
34 #include <qstring.h>
35 #include <qstringlist.h>
36 
37 namespace Kopete
38 {
39  QAbstractFileEngine *FileEngineHandler::create(const QString &fileName) const
40  {
41  bool handle = false;
42  handle |= fileName.startsWith("kopete-account-icon", Qt::CaseInsensitive);
43  handle |= fileName.startsWith("kopete-contact-icon", Qt::CaseInsensitive);
44  handle |= fileName.startsWith("kopete-metacontact-icon", Qt::CaseInsensitive);
45  handle |= fileName.startsWith("kopete-metacontact-photo", Qt::CaseInsensitive);
46  handle |= fileName.startsWith("kopete-onlinestatus-icon", Qt::CaseInsensitive);
47  return handle ? new FileEngine(fileName) : 0;
48  }
49 
50  FileEngine::FileEngine()
51  : m_buffer(&m_data)
52  {
53  kDebug(14010) ;
54  }
55 
56  FileEngine::FileEngine(const QString& fileName)
57  : m_fileName(fileName), m_buffer(&m_data)
58  {
59  kDebug(14010) << fileName;
60  }
61 
62  FileEngine::~FileEngine()
63  {
64  kDebug(14010) << m_fileName;
65  }
66 
67  bool FileEngine::open(QIODevice::OpenMode openMode)
68  {
69  kDebug(14010) << m_fileName << " " << openMode;
70 
71  // flag used to signal something went wrong when creating a mimesource
72  bool completed = false;
73 
74  QPixmap tmpPixmap;
75  QImage tmpImage;
76 
77  // extract and decode arguments
78  QStringList parts = m_fileName.split(QChar(':'), QString::SkipEmptyParts);
79  QStringList::iterator partsEnd = parts.end();
80  for (QStringList::iterator it = parts.begin(); it != partsEnd; ++it)
81  *it = QUrl::fromPercentEncoding((*it).toUtf8());
82 
83  if (parts[0] == QString::fromLatin1("kopete-contact-icon"))
84  {
85  if (parts.size() >= 4)
86  {
87  Account *account = AccountManager::self()->findAccount(parts[1], parts[2]);
88 
89  if (account)
90  {
91  Contact *contact = account->contacts().value( parts[3] );
92 
93  if (contact)
94  {
95  tmpPixmap = QPixmap(contact->onlineStatus().iconFor(contact).pixmap(16));
96  completed = true;
97  }
98  else
99  {
100  kDebug(14010) << "kopete-contact-icon: contact not found";
101  }
102  }
103  else
104  {
105  kDebug(14010) << "kopete-contact-icon: account not found";
106  }
107  }
108  else
109  {
110  kDebug(14010) << "kopete-contact-icon: insufficient information in m_fileName: " << parts;
111  }
112  }
113 
114  if (parts[0] == QString::fromLatin1("kopete-account-icon"))
115  {
116  if (parts.size() >= 3)
117  {
118  Account *account = AccountManager::self()->findAccount(parts[1], parts[2]);
119 
120  if (account)
121  {
122  tmpPixmap = QPixmap(account->myself()->onlineStatus().iconFor(account->myself()).pixmap(16));
123  completed = true;
124  }
125  else
126  {
127  kDebug(14010) << "kopete-account-icon: account not found";
128  }
129  }
130  else
131  {
132  kDebug(14010) << "kopete-account-icon: insufficient information in m_fileName: " << parts;
133  }
134  }
135 
136  if (parts[0] == QString::fromLatin1("kopete-metacontact-icon"))
137  {
138  if (parts.size() >= 2)
139  {
140  MetaContact *mc = ContactList::self()->metaContact(parts[1]);
141 
142  if (mc)
143  {
144  tmpPixmap = QPixmap(SmallIcon(mc->statusIcon()));
145  completed = true;
146  }
147  }
148  else
149  {
150  kDebug(14010) << "kopete-metacontact-icon: insufficient information in m_fileName: " << parts;
151  }
152  }
153 
154  if (parts[0] == QString::fromLatin1("kopete-metacontact-photo"))
155  {
156  if (parts.size() >= 2)
157  {
158  MetaContact *mc = ContactList::self()->metaContact(parts[1]);
159 
160  if (mc)
161  {
162  tmpImage = QImage(mc->picture().image());
163  completed = true;
164  }
165  }
166  else
167  {
168  kDebug(14010) << "kopete-metacontact-photo: insufficient information in m_fileName: " << parts;
169  }
170  }
171 
172  if (parts[0] == QString::fromLatin1("kopete-onlinestatus-icon"))
173  {
174  if (parts.size() >= 2)
175  {
176  /*
177  * We are using a dirty trick here: this mime source is supposed to return the
178  * icon for an arbitrary KOS instance. To do this, the caller needs to ask
179  * the KOS for the mime source key first, which also ensures the icon is
180  * currently in the cache. The cache is global, so we just need to find any
181  * existing KOS instance to return us the rendered icon from the cache.
182  * To find a valid KOS, we ask Kopete's account manager to locate an existing
183  * account. We'll use the myself() instance of that account to reference its
184  * current KOS object, which in turn has access to the global KOS icon cache.
185  * Note that if the cache has been invalidated in the meantime, we'll just
186  * get an empty pixmap back.
187  */
188 
189  Account *account = AccountManager::self()->accounts().first();
190 
191  if (account)
192  {
193  tmpPixmap = QPixmap(account->myself()->onlineStatus().iconFor(parts[1]));
194  completed = true;
195  }
196  else
197  {
198  kDebug(14010) << "kopete-onlinestatus-icon: no active account found";
199  }
200  }
201  else
202  {
203  kDebug(14010) << "kopete-onlinestatus-icon: insufficient information in m_fileName: " << parts;
204  }
205  }
206 
207  close();
208 
209  if (completed)
210  {
211  m_buffer.open(QIODevice::WriteOnly);
212 
213  if (!tmpImage.isNull())
214  {
215  tmpImage.save(&m_buffer, "JPEG");
216  }
217  else
218  {
219  if (!tmpPixmap.isNull())
220  {
221  tmpPixmap.save(&m_buffer, "PNG");
222  }
223  else
224  {
225  completed = false;
226  }
227  }
228 
229  m_buffer.close();
230  m_buffer.open(openMode);
231  m_buffer.seek(0);
232  }
233 
234  kDebug(14010) << "return: " << completed;
235 
236  return completed;
237  }
238 
239  bool FileEngine::close()
240  {
241  kDebug(14010) ;
242 
243  if(m_buffer.isOpen())
244  {
245  m_buffer.close();
246  }
247 
248  m_data.clear();
249 
250  return true;
251  }
252 
253  qint64 FileEngine::size() const
254  {
255  return m_buffer.size();
256  }
257 
258  qint64 FileEngine::pos() const
259  {
260  return m_buffer.pos();
261  }
262 
263  bool FileEngine::seek(qint64 newPos)
264  {
265  return m_buffer.seek(newPos);
266  }
267 
268  bool FileEngine::isSequential() const
269  {
270  return false;
271  }
272 
273  bool FileEngine::remove()
274  {
275  return false;
276  }
277 
278  bool FileEngine::rename(const QString &newName)
279  {
280  Q_UNUSED(newName);
281  return false;
282  }
283 
284  bool FileEngine::mkdir(const QString &dirName, bool createParentDirectories) const
285  {
286  Q_UNUSED(dirName);
287  Q_UNUSED(createParentDirectories);
288  return false;
289  }
290 
291  bool FileEngine::rmdir(const QString &dirName, bool recurseParentDirectories) const
292  {
293  Q_UNUSED(dirName);
294  Q_UNUSED(recurseParentDirectories);
295  return false;
296  }
297 
298  bool FileEngine::setSize(qint64 size)
299  {
300  Q_UNUSED(size);
301  return false;
302  }
303 
304  bool FileEngine::caseSensitive() const
305  {
306  return false;
307  }
308 
309  bool FileEngine::isRelativePath() const
310  {
311  return false;
312  }
313 
314  QStringList FileEngine::entryList(QDir::Filters filters, const QStringList &filterNames) const
315  {
316  Q_UNUSED(filters);
317  Q_UNUSED(filterNames);
318  return QStringList();
319  }
320 
321  FileEngine::FileFlags FileEngine::fileFlags(FileFlags type) const
322  {
323  Q_UNUSED(type);
324  return 0;
325  }
326 
327  bool FileEngine::setPermissions(uint perms)
328  {
329  Q_UNUSED(perms);
330  return false;
331  }
332 
333  QString FileEngine::fileName(FileName file) const
334  {
335  Q_UNUSED(file);
336  return m_fileName;
337  }
338 
339  uint FileEngine::ownerId(FileOwner owner) const
340  {
341  Q_UNUSED(owner);
342  return 0;
343  }
344 
345  QString FileEngine::owner(FileOwner owner) const
346  {
347  Q_UNUSED(owner);
348  return QString();
349  }
350 
351  QDateTime FileEngine::fileTime(FileTime time) const
352  {
353  Q_UNUSED(time);
354  return QDateTime();
355  }
356 
357  void FileEngine::setFileName(const QString &file)
358  {
359  m_fileName = file;
360  }
361 
362  qint64 FileEngine::read(char *data, qint64 maxlen)
363  {
364  return m_buffer.read(data, maxlen);;
365  }
366 
367  qint64 FileEngine::readLine(char *data, qint64 maxlen)
368  {
369  return m_buffer.readLine(data, maxlen);
370  }
371 
372  qint64 FileEngine::write(const char *data, qint64 len)
373  {
374  Q_UNUSED(data);
375  Q_UNUSED(len);
376  return -1;
377  }
378 
379  bool FileEngine::atEnd() const
380  {
381  return m_buffer.atEnd();
382  }
383 } // END namespace Kopete
QIODevice::OpenMode
typedef OpenMode
Kopete::FileEngine::remove
bool remove()
Definition: kopetefileengine.cpp:273
kopetemetacontact.h
Kopete::ContactList::self
static ContactList * self()
The contact list is a singleton object.
Definition: kopetecontactlist.cpp:71
Kopete::Account::myself
Contact * myself() const
Retrieve the 'myself' contact.
Definition: kopeteaccount.cpp:537
QByteArray::clear
void clear()
QBuffer::size
virtual qint64 size() const
Kopete::FileEngine::rename
bool rename(const QString &newName)
Definition: kopetefileengine.cpp:278
Kopete::FileEngineHandler::create
QAbstractFileEngine * create(const QString &fileName) const
Definition: kopetefileengine.cpp:39
Kopete::FileEngine::open
bool open(QIODevice::OpenMode openMode)
Definition: kopetefileengine.cpp:67
Kopete::FileEngine
Definition: kopetefileengine.h:37
Kopete::FileEngine::rmdir
bool rmdir(const QString &dirName, bool recurseParentDirectories) const
Definition: kopetefileengine.cpp:291
Kopete::FileEngine::pos
qint64 pos() const
Definition: kopetefileengine.cpp:258
kopeteaccount.h
Kopete::FileEngine::readLine
qint64 readLine(char *data, qint64 maxlen)
Definition: kopetefileengine.cpp:367
Kopete::FileEngine::seek
bool seek(qint64)
Definition: kopetefileengine.cpp:263
QImage::save
bool save(const QString &fileName, const char *format, int quality) const
QChar
QString::split
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
Kopete::FileEngine::close
bool close()
Definition: kopetefileengine.cpp:239
QImage::isNull
bool isNull() const
Kopete::FileEngine::setFileName
void setFileName(const QString &file)
Definition: kopetefileengine.cpp:357
Kopete::AccountManager::self
static AccountManager * self()
Retrieve the instance of AccountManager.
Definition: kopeteaccountmanager.cpp:77
Kopete::FileEngine::owner
QString owner(FileOwner) const
Definition: kopetefileengine.cpp:345
QIcon::pixmap
QPixmap pixmap(const QSize &size, Mode mode, State state) const
QList::size
int size() const
Kopete::FileEngine::isRelativePath
bool isRelativePath() const
Definition: kopetefileengine.cpp:309
Kopete::Picture::image
QImage image()
Return the current picture as QImage.
Definition: kopetepicture.cpp:78
Kopete::AccountManager::findAccount
Account * findAccount(const QString &protocolId, const QString &accountId)
Return the account asked.
Definition: kopeteaccountmanager.cpp:329
Kopete::FileEngine::isSequential
bool isSequential() const
Definition: kopetefileengine.cpp:268
Kopete::Contact::onlineStatus
OnlineStatus onlineStatus() const
Get the online status of the contact.
Definition: kopetecontact.cpp:173
QBuffer::atEnd
virtual bool atEnd() const
Kopete::FileEngine::entryList
QStringList entryList(QDir::Filters filters, const QStringList &filterNames) const
Definition: kopetefileengine.cpp:314
Kopete::OnlineStatus::iconFor
QIcon iconFor(const Contact *contact) const
Return a status icon generated for the given Contact.
Definition: kopeteonlinestatus.cpp:294
QPixmap::save
bool save(const QString &fileName, const char *format, int quality) const
Kopete::FileEngine::size
qint64 size() const
Definition: kopetefileengine.cpp:253
Kopete::FileEngine::ownerId
uint ownerId(FileOwner) const
Definition: kopetefileengine.cpp:339
Kopete::MetaContact::picture
Picture & picture() const
Return the correct Kopete::Picture object depending of the metacontact photo source.
Definition: kopetemetacontact.cpp:750
Kopete::FileEngine::atEnd
bool atEnd() const
Definition: kopetefileengine.cpp:379
kopetepicture.h
QDir::Filters
typedef Filters
Kopete::FileEngine::FileEngine
FileEngine()
Definition: kopetefileengine.cpp:50
QString::startsWith
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
kopetecontactlist.h
QBuffer::open
virtual bool open(QFlags< QIODevice::OpenModeFlag > flags)
QIODevice::read
qint64 read(char *data, qint64 maxSize)
QIODevice::isOpen
bool isOpen() const
QString
QUrl::fromPercentEncoding
QString fromPercentEncoding(const QByteArray &input)
QBuffer::pos
virtual qint64 pos() const
Kopete::Contact
Definition: kopetecontact.h:58
QList::iterator
Kopete::ContactList::metaContact
MetaContact * metaContact(const QString &metaContactId) const
Return the metacontact referenced by the given id.
Definition: kopetecontactlist.cpp:124
QStringList
QPixmap
QList::end
iterator end()
QPixmap::isNull
bool isNull() const
QImage
Kopete::FileEngine::fileTime
QDateTime fileTime(FileTime time) const
Definition: kopetefileengine.cpp:351
QBuffer::close
virtual void close()
Kopete::FileEngine::setPermissions
bool setPermissions(uint perms)
Definition: kopetefileengine.cpp:327
Kopete::FileEngine::mkdir
bool mkdir(const QString &dirName, bool createParentDirectories) const
Definition: kopetefileengine.cpp:284
kopeteaccountmanager.h
Kopete::FileEngine::~FileEngine
~FileEngine()
Definition: kopetefileengine.cpp:62
Kopete::FileEngine::fileName
QString fileName(FileName file=DefaultName) const
Definition: kopetefileengine.cpp:333
Kopete::FileEngine::write
qint64 write(const char *data, qint64 len)
Definition: kopetefileengine.cpp:372
Kopete::AccountManager::accounts
const QList< Account * > & accounts() const
Retrieve the list of accounts.
Definition: kopeteaccountmanager.cpp:313
Kopete::MetaContact
Definition: kopetemetacontact.h:54
QString::fromLatin1
QString fromLatin1(const char *str, int size)
Kopete::MetaContact::statusIcon
QString statusIcon
Definition: kopetemetacontact.h:60
Kopete::FileEngine::fileFlags
FileFlags fileFlags(FileFlags type) const
Definition: kopetefileengine.cpp:321
Kopete::FileEngine::caseSensitive
bool caseSensitive() const
Definition: kopetefileengine.cpp:304
QBuffer::seek
virtual bool seek(qint64 pos)
QAbstractFileEngine::FileFlags
typedef FileFlags
Kopete::Account
The Kopete::Account class handles one account.
Definition: kopeteaccount.h:72
Kopete::Account::contacts
const QHash< QString, Contact * > & contacts()
Retrieve the list of contacts for this account (except myself contact)
Definition: kopeteaccount.cpp:333
QAbstractFileEngine
QList::begin
iterator begin()
kopetecontact.h
Kopete::FileEngine::setSize
bool setSize(qint64 size)
Definition: kopetefileengine.cpp:298
QDateTime
kopetefileengine.h
Kopete::FileEngine::read
qint64 read(char *data, qint64 maxlen)
Definition: kopetefileengine.cpp:362
QIODevice::readLine
qint64 readLine(char *data, qint64 maxSize)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:29:19 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kopete/libkopete

Skip menu "kopete/libkopete"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdenetwork API Reference

Skip menu "kdenetwork API Reference"
  • kget
  • kopete
  •   kopete
  •   libkopete
  • krdc
  • krfb

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