30
30
#include "psiplugin.h"
31
#include "eventfilter.h"
31
32
#include "urlevent.h"
34
class URLWatcherPlugin : public QObject, public PsiPlugin
35
class URLWatcherPlugin : public QObject, public PsiPlugin, public EventFilter
37
Q_INTERFACES(PsiPlugin)
38
Q_INTERFACES(PsiPlugin EventFilter)
40
41
URLWatcherPlugin();
41
42
~URLWatcherPlugin();
42
virtual QString name() const;
44
virtual QString name() const;
43
45
virtual QString shortName() const;
44
virtual void message( const QString& message, const QString& fromJid, const QString& fromDisplay);
46
virtual QString version() const;
47
virtual QWidget* options() const;
48
virtual bool enable();
49
virtual bool disable();
51
virtual bool processEvent(int account, const QDomElement& e);
52
virtual bool processMessage(int account, const QString& fromJid, const QString& body, const QString& subject) ;
47
56
QList<URLEvent> urls_;
49
58
QTextEdit* viewerText_;
92
102
return "urlWatcher";
105
QString URLWatcherPlugin::version() const
110
QWidget* URLWatcherPlugin::options() const
115
bool URLWatcherPlugin::enable()
122
bool URLWatcherPlugin::disable()
95
129
QString resolveEntities(const QString &in)
129
163
static bool linkify_pmatch(const QString &str1, int at, const QString &str2)
131
165
if(str2.length() > (str1.length()-at))
134
168
for(int n = 0; n < (int)str2.length(); ++n) {
135
169
if(str1.at(n+at).toLower() != str2.at(n).toLower())
142
176
static bool linkify_isOneOf(const QChar &c, const QString &charlist)
144
178
for(int i = 0; i < (int)charlist.length(); ++i) {
145
179
if(c == charlist.at(i))
152
186
// encodes a few dangerous html characters
183
217
// at least one char for each of the three sections
184
218
int n = addy.indexOf('@');
185
219
if(n == -1 || n == 0)
187
221
int d = addy.indexOf('.', n+1);
188
222
if(d == -1 || d == 0)
190
224
if((addy.length()-1) - d <= 0)
192
226
if(addy.indexOf("..") != -1)
198
void URLWatcherPlugin::message( const QString& message, const QString& fromJid, const QString& fromDisplay)
232
bool URLWatcherPlugin::processEvent(int account, const QDomElement& e)
240
bool URLWatcherPlugin::processMessage(int account, const QString& fromJid, const QString& body, const QString& subject)
201
QString out = message;
203
248
bool isUrl, isEmail;
204
249
QString linked, link, href;
206
251
for(int n = 0; n < (int)out.length(); ++n) {
211
256
if(linkify_pmatch(out, n, "http://")) {
216
261
else if(linkify_pmatch(out, n, "https://")) {
221
266
else if(linkify_pmatch(out, n, "ftp://")) {
226
271
else if(linkify_pmatch(out, n, "news://")) {
231
276
else if (linkify_pmatch(out, n, "ed2k://")) {
236
281
else if(linkify_pmatch(out, n, "www.")) {
238
283
href = "http://";
240
285
else if(linkify_pmatch(out, n, "ftp.")) {
244
289
else if(linkify_pmatch(out, n, "@")) {
246
291
href = "mailto:";
321
366
qWarning(qPrintable(QString("it's a url %1").arg(newUrl)));
322
newUrl=QString("<%1> <a href='%2'>%2</a><br />").arg(fromDisplay).arg(newUrl);
367
newUrl=QString("<%1> <a href='%2'>%2</a><br />").arg(fromJid).arg(newUrl);
323
368
viewerText_->append(newUrl);
327
#include "urlwatcherplugin.moc"
b'\\ No newline at end of file'
374
#include "urlwatcherplugin.moc"