2
* urlobject.cpp - helper class for handling links
3
* Copyright (C) 2003-2006 Michail Pishchagin
5
* This library is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU Lesser General Public
7
* License as published by the Free Software Foundation; either
8
* version 2.1 of the License, or (at your option) any later version.
10
* This library is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Lesser General Public License for more details.
15
* You should have received a copy of the GNU Lesser General Public
16
* License along with this library; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
#include "urlobject.h"
23
#include <QApplication>
27
#include "iconaction.h"
30
class URLObject::Private : QObject
35
IconAction *act_mailto, *act_browser, *act_add_to_roster, *act_copy;
38
Private(URLObject *parent)
44
tr = qApp->translate("URLLabel", "Open mail composer");
45
act_mailto = new IconAction(tr, "psi/email", tr, 0, this);
46
connect(act_mailto, SIGNAL(activated()), SLOT(popupAction()));
48
tr = qApp->translate("URLLabel", "Open web browser");
49
act_browser = new IconAction(tr, "psi/www", tr, 0, this);
50
connect(act_browser, SIGNAL(activated()), SLOT(popupAction()));
52
tr = qApp->translate("URLLabel", "Add to Roster");
53
act_add_to_roster = new IconAction(tr, "psi/addContact", tr, 0, this);
54
connect(act_add_to_roster, SIGNAL(activated()), SLOT(popupAction()));
56
tr = qApp->translate("URLLabel", "Copy location");
57
act_copy = new IconAction(tr, tr, 0, this);
58
connect(act_copy, SIGNAL(activated()), SLOT(popupCopy()));
61
QString copyString(QString from)
65
int colon = l.find(':');
68
QString service = l.left( colon );
70
if ( service == "mailto" || service == "jabber" || service == "jid" || service == "xmpp" ) {
72
l = l.mid( colon + 1 );
82
void popupAction(QString lnk) {
83
emit urlObject->openURL(lnk);
90
void popupCopy(QString lnk) {
91
QApplication::clipboard()->setText( copyString(lnk), QClipboard::Clipboard );
92
if(QApplication::clipboard()->supportsSelection())
93
QApplication::clipboard()->setText( copyString(lnk), QClipboard::Selection );
104
* \brief Helper class for handling clicking on URLs
108
* Default constructor.
110
URLObject::URLObject()
113
d = new Private(this);
117
* Returns instance of the class, and creates it if necessary.
119
URLObject *URLObject::getInstance()
121
static URLObject *urlObject = 0;
123
urlObject = new URLObject();
128
* Creates QMenu with actions corresponding to link's type.
129
* @param lnk link in service:url format
131
QMenu *URLObject::createPopupMenu(const QString &lnk)
134
if ( d->link.isEmpty() )
137
int colon = d->link.find(':');
140
QString service = d->link.left( colon );
142
QMenu *m = new QMenu;
144
if ( service == "mailto" ) {
145
m->addAction(d->act_mailto);
147
else if ( service == "jabber" || service == "jid" || service == "xmpp" ) {
148
// TODO: need more actions to jabber item. Ex: "add to roster", "send message"
149
m->addAction(d->act_add_to_roster);
151
else { //if ( service == "http" || service == "https" || service.isEmpty() ) {
152
m->addAction(d->act_browser);
155
m->addAction(d->act_copy);
160
* Simulates default action using the passed URL.
161
* \param lnk URL string
163
void URLObject::popupAction(QString lnk)
168
#include "urlobject.moc"