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