• 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.12
  • kdenetwork
  • kopete
  • libkopete
kopetemessage.cpp
Go to the documentation of this file.
1 /*
2  kopetemessage.cpp - Base class for Kopete messages
3 
4  Copyright (c) 2002-2003 by Martijn Klingens <klingens@kde.org>
5  Copyright (c) 2002-2006 by Olivier Goffart <ogoffart@kde.org>
6  Copyright (c) 2006-2007 by Charles Connell <charles@connells.org>
7  Copyright (c) 2007 by MichaĆ«l Larouche <larouche@kde.org>
8  Copyright (c) 2008 by Roman Jarosz <kedgedev@centrum.cz>
9 
10  Kopete (c) 2002-2008 by the Kopete developers <kopete-devel@kde.org>
11 
12  *************************************************************************
13  * *
14  * This library is free software; you can redistribute it and/or *
15  * modify it under the terms of the GNU Lesser General Public *
16  * License as published by the Free Software Foundation; either *
17  * version 2 of the License, or (at your option) any later version. *
18  * *
19  *************************************************************************
20 */
21 
22 #include <stdlib.h>
23 
24 #include <QtCore/QDateTime>
25 #include <QtCore/QLatin1String>
26 #include <QtCore/QPointer>
27 #include <QtCore/QRegExp>
28 #include <QtCore/QTextCodec>
29 #include <QtGui/QTextDocument>
30 #include <QtGui/QColor>
31 
32 #include <kdebug.h>
33 #include <kstringhandler.h>
34 
35 #include "kopetemessage.h"
36 #include "kopetemetacontact.h"
37 #include "kopeteprotocol.h"
38 #include "kopetechatsession.h"
39 #include "kopetecontact.h"
40 #include "kopeteemoticons.h"
41 
42 
43 namespace Kopete
44 {
45 
46 class Message::Private
47  : public QSharedData
48 {
49 public:
50  Private() //assign next message id, it can't be changed later
51  : id(nextId++), direction(Internal), format(Qt::PlainText), type(TypeNormal), importance(Normal), state(StateUnknown),
52  delayed(false), formattingOverride(false), forceHtml(false), isRightToLeft(false),
53  timeStamp( QDateTime::currentDateTime() ), body(new QTextDocument), parsedBodyDirty(true), escapedBodyDirty(true),
54  fileTransfer(0)
55  {}
56  Private (const Private &other);
57  ~Private();
58 
59  const uint id;
60  QPointer<Contact> from;
61  ContactPtrList to;
62  QPointer<ChatSession> manager;
63 
64  MessageDirection direction;
65  Qt::TextFormat format;
66  MessageType type;
67  QString requestedPlugin;
68  MessageImportance importance;
69  MessageState state;
70  bool delayed;
71  bool formattingOverride, forceHtml;
72  bool isRightToLeft;
73  QDateTime timeStamp;
74  QFont font;
75  QStringList classes;
76 
77  QColor foregroundColor;
78  QColor backgroundColor;
79  QString subject;
80 
81  QTextDocument* body;
82  mutable QString parsedBody;
83  mutable bool parsedBodyDirty;
84  mutable QString escapedBody;
85  mutable bool escapedBodyDirty;
86 
87  class FileTransferInfo
88  {
89  public:
90  FileTransferInfo() : disabled(false), fileSize(0)
91  {}
92 
93  bool disabled;
94  QString fileName;
95  unsigned long fileSize;
96  QPixmap filePreview;
97  };
98  FileTransferInfo* fileTransfer;
99 
100  static uint nextId;
101 };
102 
103 // Start with 1 as 0 is reserved for invalid id;
104 uint Message::Private::nextId = 1;
105 
106 Message::Private::Private (const Message::Private &other)
107  : QSharedData (other), id(other.id)
108 {
109  from = other.from;
110  to = other.to;
111  manager = other.manager;
112 
113  direction = other.direction;
114  format = other.format;
115  type = other.type;
116  requestedPlugin = other.requestedPlugin;
117  importance = other.importance;
118  state = other.state;
119  delayed = other.delayed;
120  formattingOverride = other.formattingOverride;
121  isRightToLeft = other.isRightToLeft;
122  timeStamp = other.timeStamp;
123  font = other.font;
124  classes = other.classes;
125 
126  foregroundColor = other.foregroundColor;
127  backgroundColor = other.backgroundColor;
128  subject = other.subject;
129 
130  body = other.body->clone();
131  parsedBody = other.parsedBody;
132  parsedBodyDirty = other.parsedBodyDirty;
133  escapedBody = other.escapedBody;
134  escapedBodyDirty = other.escapedBodyDirty;
135 
136  if ( other.fileTransfer )
137  fileTransfer = new FileTransferInfo( *other.fileTransfer );
138  else
139  fileTransfer = 0;
140 }
141 
142 Message::Private::~Private ()
143 {
144  delete fileTransfer;
145 
146  delete body;
147 }
148 
149 Message::Message()
150  : d( new Private )
151 {
152 }
153 
154 Message::Message( const Contact *fromKC, const Contact *toKC )
155  : d(new Private)
156 {
157  d->from = const_cast<Contact*>(fromKC);
158  QList<Contact *> contacts;
159  contacts << const_cast<Contact*>(toKC);
160 
161  d->to = contacts;
162 }
163 
164 Message::Message( const Contact *fromKC, const QList<Contact*> &toKC )
165  : d( new Private )
166 {
167  d->from = const_cast<Contact*>(fromKC);
168  d->to = toKC;
169 }
170 
171 Message::Message( const Message &other )
172  : d(other.d)
173 {
174 }
175 
176 Message& Message::operator=( const Message &other )
177 {
178  d = other.d;
179  return *this;
180 }
181 
182 Message::~Message()
183 {
184 }
185 
186 uint Message::id() const
187 {
188  return d->id;
189 }
190 
191 uint Message::nextId()
192 {
193  return Message::Private::nextId++;
194 }
195 
196 void Message::setBackgroundOverride( bool enabled )
197 {
198  setFormattingOverride(enabled);
199 }
200 
201 void Message::setForegroundOverride( bool enabled )
202 {
203  setFormattingOverride(enabled);
204 }
205 
206 void Message::setRichTextOverride( bool enabled )
207 {
208  setFormattingOverride(enabled);
209 }
210 
211 void Message::setFormattingOverride( bool enabled )
212 {
213  d->formattingOverride = enabled;
214  d->parsedBodyDirty=true;
215  d->escapedBodyDirty=true;
216 }
217 
218 void Message::setForegroundColor( const QColor &color )
219 {
220  d->foregroundColor=color;
221 }
222 
223 void Message::setBackgroundColor( const QColor &color )
224 {
225  d->backgroundColor=color;
226 }
227 
228 void Message::setFont( const QFont &font )
229 {
230  d->font = font;
231 }
232 
233 void Message::setPlainBody (const QString &body)
234 {
235  doSetBody (body, Qt::PlainText);
236 }
237 
238 void Message::setHtmlBody (const QString &body)
239 {
240  doSetBody (body, Qt::RichText);
241 }
242 
243 void Message::setForcedHtmlBody( const QString &body)
244 {
245  setHtmlBody(body);
246  d->forceHtml = true;
247 }
248 
249 void Message::doSetBody (QString body, Qt::TextFormat f)
250 {
251  // Remove ObjectReplacementCharacter because otherwise html text will be empty
252  if ( body.contains( QChar( QChar::ObjectReplacementCharacter ) ) )
253  body.replace( QChar( QChar::ObjectReplacementCharacter ), QChar( ' ' ) );
254 
255  if (f == Qt::PlainText)
256  d->body->setPlainText(body);
257  else
258  d->body->setHtml(body);
259  d->format = f;
260  d->isRightToLeft = d->body->toPlainText().isRightToLeft();
261  d->escapedBodyDirty = true;
262  d->parsedBodyDirty = true;
263 }
264 
265 void Message::setBody (const QTextDocument *_body)
266 {
267  doSetBody (_body, Qt::RichText);
268 }
269 
270 void Message::doSetBody (const QTextDocument *body, Qt::TextFormat f)
271 {
272  delete d->body;
273  d->body = body->clone(); // delete the old body and replace it with a *copy* of the new one
274  d->format = f;
275  d->isRightToLeft = d->body->toPlainText().isRightToLeft();
276  d->escapedBodyDirty = true;
277  d->parsedBodyDirty = true;
278 }
279 
280 void Message::setImportance(Message::MessageImportance i)
281 {
282  d->importance = i;
283 }
284 
285 QString Message::unescape( const QString &xml )
286 {
287  QString data = xml;
288 
289  // Remove linebreak and multiple spaces. First return nbsp's to normal spaces :)
290  data = data.simplified();
291 
292  int pos;
293  while ( ( pos = data.indexOf( '<' ) ) != -1 )
294  {
295  int endPos = data.indexOf( '>', pos + 1 );
296  if( endPos == -1 )
297  break; // No more complete elements left
298 
299  // Take the part between < and >, and extract the element name from that
300  int matchWidth = endPos - pos + 1;
301  const QString match = data.mid( pos + 1, matchWidth - 2 ).simplified();
302  int elemEndPos = match.indexOf( ' ' );
303  const QString elem = ( elemEndPos == -1 ? match.toLower() : match.left( elemEndPos ).toLower() );
304  if ( elem == QLatin1String( "img" ) )
305  {
306  // Replace smileys with their original text'
307  const QString attrTitle = QLatin1String( "title=\"" );
308  int titlePos = match.indexOf( attrTitle, elemEndPos );
309  int titleEndPos = match.indexOf( '"', titlePos + attrTitle.length() );
310  if( titlePos == -1 || titleEndPos == -1 )
311  {
312  // Not a smiley but a normal <img>
313  // Don't update pos, we restart at this position :)
314  data.remove( pos, matchWidth );
315  }
316  else
317  {
318  QString orig = match.mid( titlePos + attrTitle.length(),
319  titleEndPos - titlePos - attrTitle.length() );
320  data.replace( pos, matchWidth, orig );
321  pos += orig.length();
322  }
323  }
324  else if ( elem == QLatin1String( "/p" ) || elem == QLatin1String( "/div" ) ||
325  elem == QLatin1String( "br" ) )
326  {
327  // Replace paragraph, div and line breaks with a newline
328  data.replace( pos, matchWidth, '\n' );
329  pos++;
330  }
331  else
332  {
333  // Remove all other elements entirely
334  // Don't update pos, we restart at this position :)
335  data.remove( pos, matchWidth );
336  }
337  }
338 
339  // Replace stuff starting with '&'
340  data.replace( QLatin1String( "&gt;" ), QLatin1String( ">" ) );
341  data.replace( QLatin1String( "&lt;" ), QLatin1String( "<" ) );
342  data.replace( QLatin1String( "&quot;" ), QLatin1String( "\"" ) );
343  data.replace( QLatin1String( "&nbsp;" ), QLatin1String( " " ) );
344  data.replace( QLatin1String( "&amp;" ), QLatin1String( "&" ) );
345  data.replace( QLatin1String( "&#160;" ), QLatin1String( " " ) ); //this one is used in jabber: note, we should escape all &#xx;
346 
347  return data;
348 }
349 
350 QString Message::escape( const QString &text )
351 {
352  QString html = Qt::escape( text );
353  //Replace carriage returns inside the text
354  html.replace( QLatin1Char( '\n' ), QLatin1String( "<br />" ) );
355  //Replace a tab with 4 spaces
356  html.replace( QLatin1Char( '\t' ), QLatin1String( "&nbsp;&nbsp;&nbsp;&nbsp;" ) );
357 
358  //Replace multiple spaces with &nbsp;
359  //do not replace every space so we break the linebreak
360  html.replace( QRegExp( QLatin1String( "\\s\\s" ) ), QLatin1String( "&nbsp; " ) );
361 
362  return html;
363 }
364 
365 QString Message::plainBody() const
366 {
367  // Remove ObjectReplacementCharacter which can be there if html text contains img tag.
368  QString plainText = d->body->toPlainText();
369  plainText.replace( QChar( QChar::ObjectReplacementCharacter ), QChar( ' ' ) );
370  return plainText;
371 }
372 
373 QString Message::escapedBody() const
374 {
375 // kDebug(14010) << escapedBody() << " " << d->richTextOverride;
376 
377 // the escaped body is cached because QRegExp is very expensive, so it shouldn't be used any more than necessary
378  if (!d->escapedBodyDirty)
379  return d->escapedBody;
380  else {
381  QString html;
382  if ( d->format == Qt::PlainText || (d->formattingOverride && !d->forceHtml))
383  html = Qt::convertFromPlainText( d->body->toPlainText(), Qt::WhiteSpaceNormal );
384  else
385  html = d->body->toHtml();
386 
387 // all this regex business is to take off the outer HTML document provided by QTextDocument
388 // remove the head
389  QRegExp badStuff ("<![^<>]*>|<head[^<>]*>.*</head[^<>]*>|</?html[^<>]*>|</?body[^<>]*>");
390  html = html.remove (badStuff);
391 // remove newlines that may be present, since they end up being displayed in the chat window. real newlines are represented with <br>, so we know \n's are meaningless
392  html = html.remove ('\n');
393  d->escapedBody = html;
394  d->escapedBodyDirty = false;
395  return html;
396  }
397 }
398 
399 QString Message::parsedBody() const
400 {
401  //kDebug(14000) << "messageformat: " << d->format;
402  if ( !d->parsedBodyDirty )
403  return d->parsedBody;
404 
405  d->parsedBody = Kopete::Emoticons::parseEmoticons(parseLinks(escapedBody(), Qt::RichText));
406  d->parsedBodyDirty = false;
407  return d->parsedBody;
408 }
409 
410 static QString makeRegExp( const char *pattern )
411 {
412  const QString urlChar = QLatin1String( "\\+\\-\\w\\./#@&;:=\\?~%_,\\!\\$\\*\\(\\)" );
413  const QString boundaryStart = QString( "(^|[^%1])(" ).arg( urlChar );
414  const QString boundaryEnd = QString( ")([^%1]|$)" ).arg( urlChar );
415 
416  return boundaryStart + QLatin1String(pattern) + boundaryEnd;
417 }
418 
419 const QStringList Message::regexpPatterns()
420 {
421  const QString name = QLatin1String( "[\\w\\+\\-=_\\.]+" );
422  const QString userAndPassword = QString( "(?:%1(?::%1)?\\@)" ).arg( name );
423  const QString urlChar = QLatin1String( "\\+\\-\\w\\./#@&;:=\\?~%_,\\!\\$\\*\\(\\)" );
424  const QString urlSection = QString( "[%1]+" ).arg( urlChar );
425  const QString domain = QLatin1String( "[\\-\\w_]+(?:\\.[\\-\\w_]+)+" );
426  QStringList patternList;
427  patternList << makeRegExp("\\w+://%1?\\w%2").arg( userAndPassword, urlSection )
428  << makeRegExp("%1?www\\.%2%3").arg( userAndPassword, domain, urlSection )
429  << makeRegExp("%1@%2").arg( name, domain );
430  return patternList;
431 }
432 
433 QString Message::parseLinks( const QString &message, Qt::TextFormat format )
434 {
435  if ( format & Qt::RichText )
436  {
437  // < in HTML *always* means start-of-tag
438  QStringList entries = message.split( QChar('<'), QString::KeepEmptyParts );
439 
440  QStringList::Iterator it = entries.begin();
441 
442  // first one is different: it doesn't start with an HTML tag.
443  if ( it != entries.end() )
444  {
445  *it = parseLinks( *it, Qt::PlainText );
446  ++it;
447  }
448 
449  for ( ; it != entries.end(); ++it )
450  {
451  QString curr = *it;
452  // > in HTML means start-of-tag if and only if it's the first one after a <
453  int tagclose = curr.indexOf( QChar('>') );
454  // no >: the HTML is broken, but we can cope
455  if ( tagclose == -1 )
456  continue;
457  QString tag = curr.left( tagclose + 1 );
458  QString body = curr.mid( tagclose + 1 );
459  *it = tag + parseLinks( body, Qt::PlainText );
460  }
461  return entries.join(QLatin1String("<"));
462  }
463 
464  QString result = message;
465 
466  // common subpatterns - may not contain matching parens!
467  const QString name = QLatin1String( "[\\w\\+\\-=_\\.]+" );
468  const QString userAndPassword = QString( "(?:%1(?::%1)?\\@)" ).arg( name );
469  const QString urlChar = QLatin1String( "\\+\\-\\w\\./#@&;:=\\?~%_,\\!\\$\\*\\(\\)" );
470  const QString urlSection = QString( "[%1]+" ).arg( urlChar );
471  const QString domain = QLatin1String( "[\\-\\w_]+(?:\\.[\\-\\w_]+)+" );
472 
473  //Replace http/https/ftp links:
474  // Replace (stuff)://[user:password@](linkstuff) with a link
475  result.replace(
476  QRegExp( makeRegExp("\\w+://%1?\\w%2").arg( userAndPassword, urlSection ) ),
477  QLatin1String("\\1<a href=\"\\2\" title=\"\\2\">\\2</a>\\3" ) );
478 
479  // Replace www.X.Y(linkstuff) with a http: link
480  result.replace(
481  QRegExp( makeRegExp("%1?www\\.%2%3").arg( userAndPassword, domain, urlSection ) ),
482  QLatin1String("\\1<a href=\"http://\\2\" title=\"http://\\2\">\\2</a>\\3" ) );
483 
484  //Replace Email Links
485  // Replace user@domain with a mailto: link
486  result.replace(
487  QRegExp( makeRegExp("%1@%2").arg( name, domain ) ),
488  QLatin1String("\\1<a href=\"mailto:\\2\" title=\"mailto:\\2\">\\2</a>\\3") );
489 
490  //Workaround for Bug 85061: Highlighted URLs adds a ' ' after the URL itself
491  // the trailing &nbsp; is included in the url.
492  result.replace( QRegExp( QLatin1String("(<a href=\"[^\"]+)(&nbsp;)(\")") ) , QLatin1String("\\1\\3") );
493 
494  return result;
495 }
496 
497 
498 
499 QDateTime Message::timestamp() const
500 {
501  return d->timeStamp;
502 }
503 
504 void Message::setTimestamp(const QDateTime &timestamp)
505 {
506  d->timeStamp = timestamp;
507 }
508 
509 const Contact *Message::from() const
510 {
511  return d->from;
512 }
513 
514 QList<Contact*> Message::to() const
515 {
516  return d->to;
517 }
518 
519 Message::MessageType Message::type() const
520 {
521  return d->type;
522 }
523 
524 void Message::setType(MessageType type)
525 {
526  d->type = type;
527 }
528 
529 QString Message::requestedPlugin() const
530 {
531  return d->requestedPlugin;
532 }
533 
534 void Message::setRequestedPlugin(const QString &requestedPlugin)
535 {
536  d->requestedPlugin = requestedPlugin;
537 }
538 
539 QColor Message::foregroundColor() const
540 {
541  return d->foregroundColor;
542 }
543 
544 QColor Message::backgroundColor() const
545 {
546  return d->backgroundColor;
547 }
548 
549 bool Message::isRightToLeft() const
550 {
551  return d->isRightToLeft;
552 }
553 
554 QFont Message::font() const
555 {
556  return d->font;
557 }
558 
559 QString Message::subject() const
560 {
561  return d->subject;
562 }
563 
564 void Message::setSubject(const QString &subject)
565 {
566  d->subject = subject;
567 }
568 
569 const QTextDocument *Message::body() const
570 {
571  return d->body;
572 }
573 
574 Qt::TextFormat Message::format() const
575 {
576  return d->format;
577 }
578 
579 Message::MessageDirection Message::direction() const
580 {
581  return d->direction;
582 }
583 
584 void Message::setDirection(MessageDirection direction)
585 {
586  d->direction = direction;
587 }
588 
589 Message::MessageImportance Message::importance() const
590 {
591  return d->importance;
592 }
593 
594 Message::MessageState Message::state() const
595 {
596  return d->state;
597 }
598 
599 void Message::setState(MessageState state)
600 {
601  d->state = state;
602 }
603 
604 ChatSession *Message::manager() const
605 {
606  return d->manager;
607 }
608 
609 void Message::setManager(ChatSession *kmm)
610 {
611  d->manager=kmm;
612 }
613 
614 QString Message::getHtmlStyleAttribute() const
615 {
616  QString styleAttribute;
617 
618  styleAttribute = QString::fromUtf8("style=\"");
619 
620  if( !d->formattingOverride)
621  {
622  // Affect foreground(color) and background color to message.
623  // we only do this if the formatting won't get stripped anyway
624  if( d->foregroundColor.isValid() )
625  {
626  styleAttribute += QString::fromUtf8("color: %1; ").arg(d->foregroundColor.name());
627  }
628  if( d->backgroundColor.isValid() )
629  {
630  styleAttribute += QString::fromUtf8("background-color: %1; ").arg(d->backgroundColor.name());
631  }
632 
633  // Affect font parameters.
634  if( d->font!=QFont() )
635  {
636  QString fontstr;
637  if(!d->font.family().isNull())
638  fontstr+=QLatin1String("font-family: ")+d->font.family()+QLatin1String("; ");
639  if(d->font.italic())
640  fontstr+=QLatin1String("font-style: italic; ");
641  if(d->font.strikeOut())
642  fontstr+=QLatin1String("text-decoration: line-through; ");
643  if(d->font.underline())
644  fontstr+=QLatin1String("text-decoration: underline; ");
645  if(d->font.bold())
646  fontstr+=QLatin1String("font-weight: bold;");
647 
648  styleAttribute += fontstr;
649  }
650  }
651 
652  styleAttribute += QString::fromUtf8("\"");
653 
654  return styleAttribute;
655 }
656 
657 void Message::setFileTransferDisabled( bool disabled )
658 {
659  if ( !d->fileTransfer )
660  d->fileTransfer = new Message::Private::FileTransferInfo();
661 
662  d->fileTransfer->disabled = disabled;
663 }
664 
665 bool Message::fileTransferDisabled() const
666 {
667  return ( d->fileTransfer ) ? d->fileTransfer->disabled : false;
668 }
669 
670 void Message::setFileName( const QString &fileName )
671 {
672  if ( !d->fileTransfer )
673  d->fileTransfer = new Message::Private::FileTransferInfo();
674 
675  d->fileTransfer->fileName = fileName;
676 }
677 
678 QString Message::fileName() const
679 {
680  return ( d->fileTransfer ) ? d->fileTransfer->fileName : QString();
681 }
682 
683 void Message::setFileSize( unsigned long size )
684 {
685  if ( !d->fileTransfer )
686  d->fileTransfer = new Message::Private::FileTransferInfo();
687 
688  d->fileTransfer->fileSize = size;
689 }
690 
691 unsigned long Message::fileSize() const
692 {
693  return ( d->fileTransfer ) ? d->fileTransfer->fileSize : 0;
694 }
695 
696 void Message::setFilePreview( const QPixmap &preview )
697 {
698  if ( !d->fileTransfer )
699  d->fileTransfer = new Message::Private::FileTransferInfo();
700 
701  d->fileTransfer->filePreview = preview;
702 }
703 
704 QPixmap Message::filePreview() const
705 {
706  return ( d->fileTransfer ) ? d->fileTransfer->filePreview : QPixmap();
707 }
708 
709 // prime candidate for removal
710 #if 0
711 QString Message::decodeString( const QByteArray &message, const QTextCodec *providedCodec, bool *success )
712 {
713  /*
714  Note to everyone. This function is not the most efficient, that is for sure.
715  However, it *is* the only way we can be guaranteed that a given string is
716  decoded properly.
717  */
718 
719  if( success )
720  *success = true;
721 
722  // Avoid heavy codec tests on empty message.
723  if( message.isEmpty() )
724  return QString::fromAscii( message );
725 
726  //Check first 128 chars
727  int charsToCheck = message.length();
728  charsToCheck = 128 > charsToCheck ? charsToCheck : 128;
729 
730 #ifdef __GNUC__
731  #warning Rewrite the following code: heuristicContentMatch() do not existe anymore.
732 #endif
733  //They are providing a possible codec. Check if it is valid
734 // if( providedCodec && providedCodec->heuristicContentMatch( message, charsToCheck ) >= charsToCheck )
735  {
736  //All chars decodable.
737  return providedCodec->toUnicode( message );
738  }
739 
740  //NOTE see KEncodingDetector@kdecore
741  //Check if it is UTF
742  if( KStringHandler::isUtf8(message) )
743  {
744  //We have a UTF string almost for sure. At least we know it will be decoded.
745  return QString::fromUtf8( message );
746  }
747 /*
748  //Try codecForContent - exact match
749  QTextCodec *testCodec = QTextCodec::codecForContent(message, charsToCheck);
750  if( testCodec && testCodec->heuristicContentMatch( message, charsToCheck ) >= charsToCheck )
751  {
752  //All chars decodable.
753  return testCodec->toUnicode( message );
754  }
755 
756  kWarning(14000) << "Unable to decode string using provided codec(s), taking best guesses!";
757  if( success )
758  *success = false;
759 
760  //We don't have any clues here.
761 
762  //Try local codec
763  testCodec = QTextCodec::codecForLocale();
764  if( testCodec && testCodec->heuristicContentMatch( message, charsToCheck ) >= charsToCheck )
765  {
766  //All chars decodable.
767  kDebug(14000) << "Using locale's codec";
768  return testCodec->toUnicode( message );
769  }
770 
771  //Try latin1 codec
772  testCodec = QTextCodec::codecForMib(4);
773  if( testCodec && testCodec->heuristicContentMatch( message, charsToCheck ) >= charsToCheck )
774  {
775  //All chars decodable.
776  kDebug(14000) << "Using latin1";
777  return testCodec->toUnicode( message );
778  }
779 
780  kDebug(14000) << "Using latin1 and cleaning string";
781  //No codec decoded. Just decode latin1, and clean out any junk.
782  QString result = QLatin1String( message );
783  const uint length = message.length();
784  for( uint i = 0; i < length; ++i )
785  {
786  if( !result[i].isPrint() )
787  result[i] = '?';
788  }
789 
790  return result;
791 */
792  return QString();
793 }
794 #endif
795 
796 QStringList Message::classes() const
797 {
798  return d->classes;
799 }
800 
801 void Message::addClass(const QString & classe)
802 {
803  d->classes.append(classe);
804 }
805 
806 void Message::setClasses(const QStringList & classes)
807 {
808  d->classes = classes;
809 }
810 
811 }
812 
813 bool Kopete::Message::delayed() const
814 {
815  return d->delayed;
816 }
817 
818 void Kopete::Message::setDelayed(bool delay)
819 {
820  d->delayed = delay;
821 }
Kopete::Message::setDelayed
void setDelayed(bool delay)
Set the "delayed" attribute of the message.
Definition: kopetemessage.cpp:818
Kopete::Message::setTimestamp
void setTimestamp(const QDateTime &timestamp)
Set the message timestamp.
Definition: kopetemessage.cpp:504
Kopete::Message::~Message
~Message()
Deref and clean private object if refcount == 0.
Definition: kopetemessage.cpp:182
kopetemetacontact.h
Kopete::ContactPtrList
QList< Contact * > ContactPtrList
Definition: kopetechatsession.h:52
Kopete::Message::format
Qt::TextFormat format() const
Accessor method for the format of the message.
Definition: kopetemessage.cpp:574
Kopete::Message::setSubject
void setSubject(const QString &subject)
Set message subject.
Definition: kopetemessage.cpp:564
Kopete::Message::fileName
QString fileName() const
Accessor method for the file name of incoming file transfer.
Definition: kopetemessage.cpp:678
Kopete::Message::setImportance
void setImportance(MessageImportance importance)
Set the importance.
Definition: kopetemessage.cpp:280
Kopete::Emoticons::parseEmoticons
static QString parseEmoticons(const QString &text, KEmoticonsTheme::ParseMode mode=KEmoticonsTheme::DefaultParse, const QStringList &exclude=QStringList())
Definition: kopeteemoticons.cpp:36
Kopete::Message::setForegroundColor
void setForegroundColor(const QColor &color)
Sets the foreground color for the message.
Definition: kopetemessage.cpp:218
Kopete::Message::setForcedHtmlBody
void setForcedHtmlBody(const QString &body)
Sets the body of the message, which is used even if formatting is overridden.
Definition: kopetemessage.cpp:243
Kopete::Message::operator=
Message & operator=(const Message &other)
Assignment operator Just like the copy constructor it just refs and doesn't copy. ...
Definition: kopetemessage.cpp:176
Kopete::Message::filePreview
QPixmap filePreview() const
Accessor method for the file preview icon.
Definition: kopetemessage.cpp:704
Kopete::Message::setHtmlBody
void setHtmlBody(const QString &body)
Sets the body of the message.
Definition: kopetemessage.cpp:238
Kopete::Message::unescape
static QString unescape(const QString &xml)
Unescapes a string, removing XML entity references and returns a plain text.
Definition: kopetemessage.cpp:285
Kopete::Message::setFileName
void setFileName(const QString &fileName)
Set file name of incoming file transfer.
Definition: kopetemessage.cpp:670
Kopete::Message::type
MessageType type() const
Accessor method for the message type.
Definition: kopetemessage.cpp:519
Kopete::Message::TypeNormal
A typical message.
Definition: kopetemessage.h:100
Kopete::Message::MessageState
MessageState
Definition: kopetemessage.h:116
Kopete::Message::fileTransferDisabled
bool fileTransferDisabled() const
Accessor method for the file transfer state.
Definition: kopetemessage.cpp:665
Kopete::Message::setFileTransferDisabled
void setFileTransferDisabled(bool disabled)
Set the state of incoming file transfer.
Definition: kopetemessage.cpp:657
Kopete::Message::Normal
Default notification, for normal message.
Definition: kopetemessage.h:112
Kopete::ChatSession
Definition: kopetechatsession.h:74
Kopete::Message::foregroundColor
QColor foregroundColor() const
Accessor method for the foreground color.
Definition: kopetemessage.cpp:539
Kopete::Message::Internal
(Default) Message which are not sent via the network. This is just a notification a plugin can show i...
Definition: kopetemessage.h:92
Kopete::Message::subject
QString subject() const
Accessor method for the subject of the message.
Definition: kopetemessage.cpp:559
Kopete::Message::isRightToLeft
bool isRightToLeft() const
Accesssor method for the direction of the text based on what language it is in.
Definition: kopetemessage.cpp:549
Kopete::Message::setClasses
void setClasses(const QStringList &classes)
Set the classes.
Definition: kopetemessage.cpp:806
Kopete::Message::direction
MessageDirection direction() const
Accessor method for the direction of the message.
Definition: kopetemessage.cpp:579
Kopete::Message::body
const QTextDocument * body() const
Accessor method for the body of the message This is used internaly, to modify it make a copy of it wi...
Definition: kopetemessage.cpp:569
Kopete::Message::setDirection
void setDirection(MessageDirection direction)
Set the message direction.
Definition: kopetemessage.cpp:584
Kopete::Message::escapedBody
QString escapedBody() const
Get the message body as escaped (X)HTML format.
Definition: kopetemessage.cpp:373
Kopete::Message::escape
static QString escape(const QString &)
Transform a plaintext message into HTML.
Definition: kopetemessage.cpp:350
Kopete::Message::StateUnknown
state of message isn't known (e.g. protocol doesn't support message acknowledgment) ...
Definition: kopetemessage.h:118
kopeteemoticons.h
Kopete::Message::Message
Message()
Constructs a new empty message.
Definition: kopetemessage.cpp:149
Kopete::Message::setBackgroundColor
void setBackgroundColor(const QColor &color)
Sets the background color for the message.
Definition: kopetemessage.cpp:223
Kopete::Message::setManager
void setManager(ChatSession *manager)
Set the messagemanager for this message.
Definition: kopetemessage.cpp:609
kopeteprotocol.h
Kopete::Message::MessageDirection
MessageDirection
Direction of a message.
Definition: kopetemessage.h:88
kopetechatsession.h
Kopete::Message::addClass
void addClass(const QString &classe)
Add a class.
Definition: kopetemessage.cpp:801
Kopete::Message::setRichTextOverride
void KDE_DEPRECATED setRichTextOverride(bool enable)
Does nothing.
Definition: kopetemessage.cpp:206
Kopete::Message::id
uint id() const
Get unique message id.
Definition: kopetemessage.cpp:186
Kopete::Message::backgroundColor
QColor backgroundColor() const
Accessor method for the background color of the message.
Definition: kopetemessage.cpp:544
Kopete::Message::setPlainBody
void setPlainBody(const QString &body)
Sets the body of the message.
Definition: kopetemessage.cpp:233
Kopete::makeRegExp
static QString makeRegExp(const char *pattern)
Definition: kopetemessage.cpp:410
Kopete::Contact
Definition: kopetecontact.h:58
Kopete::Message::MessageImportance
MessageImportance
Specifies the type of notification that will be sent with this message.
Definition: kopetemessage.h:109
Kopete::Message::setRequestedPlugin
void setRequestedPlugin(const QString &requestedPlugin)
Set a view plugin which will display the message.
Definition: kopetemessage.cpp:534
Kopete::Message::delayed
bool delayed() const
Accessor method for the "delayed" attribute of the message.
Definition: kopetemessage.cpp:813
Kopete::Message::state
MessageState state() const
Accessor method for the state.
Definition: kopetemessage.cpp:594
Kopete::Message::setFormattingOverride
void setFormattingOverride(bool enable)
Ignores peer's formatting.
Definition: kopetemessage.cpp:211
Kopete::Message::setForegroundOverride
void KDE_DEPRECATED setForegroundOverride(bool enable)
Does nothing.
Definition: kopetemessage.cpp:201
Kopete::Message::requestedPlugin
QString requestedPlugin() const
Accessor method for the preferred plugin If null, Kopete will use the user's preferred plugin...
Definition: kopetemessage.cpp:529
Kopete::Message::MessageType
MessageType
Specifies the type of the message.
Definition: kopetemessage.h:98
Kopete::Message::fileSize
unsigned long fileSize() const
Accessor method for the file transfer size.
Definition: kopetemessage.cpp:691
Kopete::Message::setBody
void setBody(const QTextDocument *body)
Sets the body of the message The format is changed to RichText automatically.
Definition: kopetemessage.cpp:265
Kopete::Message::nextId
static uint nextId()
Get next unique message id.
Definition: kopetemessage.cpp:191
Kopete::Message::timestamp
QDateTime timestamp() const
Accessor method for the timestamp of the message.
Definition: kopetemessage.cpp:499
Kopete::Message::classes
QStringList classes() const
Definition: kopetemessage.cpp:796
Kopete::Message::importance
MessageImportance importance() const
Accessor method for the importance.
Definition: kopetemessage.cpp:589
Kopete::Message::setType
void setType(MessageType type)
Set message type.
Definition: kopetemessage.cpp:524
Kopete::Message::font
QFont font() const
Accessor method for the font of the message.
Definition: kopetemessage.cpp:554
Kopete::Message::setFilePreview
void setFilePreview(const QPixmap &preview)
Set file preview icon for file transfer.
Definition: kopetemessage.cpp:696
Kopete::Message::to
QList< Contact * > to() const
Accessor method for the Contacts that this message was sent to.
Definition: kopetemessage.cpp:514
Kopete::Message::getHtmlStyleAttribute
QString getHtmlStyleAttribute() const
Return HTML style attribute for this message.
Definition: kopetemessage.cpp:614
Kopete::Message::setState
void setState(MessageState state)
Set the state of message.
Definition: kopetemessage.cpp:599
kopetemessage.h
Kopete::Message::plainBody
QString plainBody() const
Get the message body back as plain text.
Definition: kopetemessage.cpp:365
Kopete::Message::parsedBody
QString parsedBody() const
Get the message body as parsed HTML with Emoticons, and URL parsed This should be ready to be shown i...
Definition: kopetemessage.cpp:399
Kopete::Message::from
const Contact * from() const
Accessor method for the Contact that sent this message.
Definition: kopetemessage.cpp:509
Kopete::Message::manager
ChatSession * manager() const
Get the related message manager.
Definition: kopetemessage.cpp:604
Kopete::Message
Representation of a message in Kopete.
Definition: kopetemessage.h:82
Kopete::Message::setBackgroundOverride
void KDE_DEPRECATED setBackgroundOverride(bool enable)
Does nothing.
Definition: kopetemessage.cpp:196
Kopete::Message::regexpPatterns
const QStringList regexpPatterns()
returns QStringList with regexp patterns will be used to look for links in the message ...
Definition: kopetemessage.cpp:419
Kopete::Message::setFileSize
void setFileSize(unsigned long size)
Set file transfer size.
Definition: kopetemessage.cpp:683
Kopete::Message::setFont
void setFont(const QFont &font)
Sets the font for the message.
Definition: kopetemessage.cpp:228
kopetecontact.h
name
const char * name
Definition: kopeteonlinestatus.cpp:104
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:53:51 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