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

kpimutils

  • KPIMUtils
  • LinkLocator
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
KPIMUtils::LinkLocator Class Reference

#include <linklocator.h>

Inherited by KPIMUtils::SpellingFilter::TextCensor.

Public Member Functions

 LinkLocator (const QString &text, int pos=0)
 
 ~LinkLocator ()
 
QString getEmailAddress ()
 
QString getUrl ()
 
int maxAddressLen () const
 
int maxUrlLen () const
 
void setMaxAddressLen (int length)
 
void setMaxUrlLen (int length)
 

Static Public Member Functions

static QString convertToHtml (const QString &plainText, int flags=0, int maxUrlLen=4096, int maxAddressLen=255)
 
static QString pngToDataUrl (const QString &iconPath)
 

Static Public Attributes

static const int HighlightText = 0x08
 
static const int IgnoreUrls = 0x04
 
static const int PreserveSpaces = 0x01
 
static const int ReplaceSmileys = 0x02
 

Protected Member Functions

bool atUrl () const
 
QString highlightedText ()
 
bool isEmptyUrl (const QString &url) const
 

Protected Attributes

int mPos
 
QString mText
 

Detailed Description

LinkLocator assists in identifying sections of text that can usefully be converted in hyperlinks in HTML.

It is intended to be used in two ways: either by calling convertToHtml() to convert a plaintext string into HTML, or to be derived from where more control is needed.

please note that you are responsible for handling the links. That means you should not execute the link directly but instead open it for example. See the KRun documentation about this parameter if applicable.

Definition at line 48 of file linklocator.h.

Constructor & Destructor Documentation

LinkLocator::LinkLocator ( const QString &  text,
int  pos = 0 
)
explicit

Constructs a LinkLocator that will search a plaintext string from a given starting point.

Private class that helps to provide binary compatibility between releases.

Parameters
textThe string in which to search.
posAn index into 'text' from where the search should begin.

Definition at line 58 of file linklocator.cpp.

LinkLocator::~LinkLocator ( )

Destructor.

Definition at line 71 of file linklocator.cpp.

Member Function Documentation

QString LinkLocator::convertToHtml ( const QString &  plainText,
int  flags = 0,
int  maxUrlLen = 4096,
int  maxAddressLen = 255 
)
static

Converts plaintext into html.

The following characters are converted to HTML entities: & " < >. Newlines are also preserved.

Parameters
plainTextThe text to be converted into HTML.
flagsThe flags to consider when processing plainText. Currently supported flags are:
  • PreserveSpaces, preserves the appearance of sequences of space and tab characters in the resulting HTML.
  • ReplaceSmileys, replace text smileys with emoticon images.
  • IgnoreUrls, doesn't parse any URLs.
  • HighlightText, interprets text highlighting markup like bold, underlined and /italic/.
maxUrlLenThe maximum length of permitted URLs. (
See also
maxUrlLen().)
Parameters
maxAddressLenThe maximum length of permitted email addresses. (
See also
maxAddressLen().)
Returns
An HTML version of the text supplied in the 'plainText' parameter, suitable for inclusion in the BODY of an HTML document.

Definition at line 291 of file linklocator.cpp.

QString LinkLocator::getEmailAddress ( )

Attempts to grab an email address.

If there is an @ symbol at the current scan position, then the text will be searched both backwards and forwards to find the email address. If there is no @ symbol at the current scan position, an empty string is returned. If an address is found, then the current scan position is set to the index of the last character in the address.

Returns
The email address at the current scan position, or an empty string.

Definition at line 225 of file linklocator.cpp.

QString LinkLocator::getUrl ( )

Attempts to grab a URL starting at the current scan position.

If there is no URL at the current scan position, then an empty string is returned. If a URL is found, the current scan position is set to the index of the last character in the URL.

Returns
The URL at the current scan position, or an empty string.

Definition at line 96 of file linklocator.cpp.

QString LinkLocator::highlightedText ( )
protected

Highlight text according to bold, /italic/ and underlined markup.

Returns
A HTML string.

Definition at line 449 of file linklocator.cpp.

int LinkLocator::maxAddressLen ( ) const

Returns the current limit on the maximum length of an email address.

See also
setMaxAddressLen().

Definition at line 91 of file linklocator.cpp.

int LinkLocator::maxUrlLen ( ) const

Returns the current limit on the maximum length of a URL.

See also
setMaxUrlLen().

Definition at line 81 of file linklocator.cpp.

QString LinkLocator::pngToDataUrl ( const QString &  iconPath)
static

Embeds the given PNG image into a data URL.

Parameters
iconPathpath to the PNG image
Returns
A data URL, QString() if the image could not be read.

Definition at line 433 of file linklocator.cpp.

void LinkLocator::setMaxAddressLen ( int  length)

Sets the maximum length of email addresses that will be matched by getEmailAddress().

By default, this is set to 255 characters. The reason for this limit is that there may be possible security implications in handling addresses of unlimited length.

See also
maxAddressLen().
Parameters
lengthThe new maximum length of email addresses that will be matched by getEmailAddress().

Definition at line 86 of file linklocator.cpp.

void LinkLocator::setMaxUrlLen ( int  length)

Sets the maximum length of URLs that will be matched by getUrl().

By default, this is set to 4096 characters. The reason for this limit is that there may be possible security implications in handling URLs of unlimited length.

See also
maxUrlLen()
Parameters
lengthA new maximum length of URLs that will be matched by getUrl().

Definition at line 76 of file linklocator.cpp.

Member Data Documentation

int KPIMUtils::LinkLocator::mPos
protected

The current scan position.

Definition at line 167 of file linklocator.h.

QString KPIMUtils::LinkLocator::mText
protected

The plaintext string being scanned for URLs and email addresses.

Definition at line 162 of file linklocator.h.


The documentation for this class was generated from the following files:
  • linklocator.h
  • linklocator.cpp
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:37:25 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kpimutils

Skip menu "kpimutils"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • Modules
  • Related Pages

kdepimlibs API Reference

Skip menu "kdepimlibs API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2

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