Changeset View
Changeset View
Standalone View
Standalone View
plugins/rellinks/plugin_rellinks.cpp
Show All 35 Lines | |||||
36 | #include <kpluginfactory.h> | 36 | #include <kpluginfactory.h> | ||
37 | #include <khtml_part.h> | 37 | #include <khtml_part.h> | ||
38 | #include <khtmlview.h> | 38 | #include <khtmlview.h> | ||
39 | #include <kiconloader.h> | 39 | #include <kiconloader.h> | ||
40 | #include <kcomponentdata.h> | 40 | #include <kcomponentdata.h> | ||
41 | #include <KLocalizedString> | 41 | #include <KLocalizedString> | ||
42 | #include <QMenu> | 42 | #include <QMenu> | ||
43 | #include <ktoolbar.h> | 43 | #include <ktoolbar.h> | ||
44 | #include <kurl.h> | | |||
45 | #include <kactionmenu.h> | 44 | #include <kactionmenu.h> | ||
46 | #include <kactioncollection.h> | 45 | #include <kactioncollection.h> | ||
47 | // local includes | 46 | // local includes | ||
48 | #include "plugin_rellinks.h" | 47 | #include "plugin_rellinks.h" | ||
49 | 48 | | |||
50 | 49 | | |||
51 | /** Rellinks factory */ | 50 | /** Rellinks factory */ | ||
52 | K_PLUGIN_FACTORY(RelLinksFactory, registerPlugin<RelLinksPlugin>();) | 51 | K_PLUGIN_FACTORY(RelLinksFactory, registerPlugin<RelLinksPlugin>();) | ||
53 | #include <kaboutdata.h> | 52 | #include <kaboutdata.h> | ||
54 | 53 | | |||
54 | static QUrl resolvedUrl(const QUrl &base, const QString& rel) { | ||||
dfaure: static in front, & after QString | |||||
55 | return QUrl(base).resolved(QUrl(rel)); | ||||
56 | } | ||||
57 | | ||||
55 | Q_DECLARE_METATYPE(DOM::Element); | 58 | Q_DECLARE_METATYPE(DOM::Element); | ||
56 | 59 | | |||
57 | /** Constructor of the plugin. */ | 60 | /** Constructor of the plugin. */ | ||
58 | RelLinksPlugin::RelLinksPlugin(QObject *parent, const QVariantList &) | 61 | RelLinksPlugin::RelLinksPlugin(QObject *parent, const QVariantList &) | ||
59 | : KParts::Plugin(parent), | 62 | : KParts::Plugin(parent), | ||
60 | m_part(0), | 63 | m_part(0), | ||
61 | m_viewVisible(false), | 64 | m_viewVisible(false), | ||
62 | m_linksFound(false) | 65 | m_linksFound(false) | ||
▲ Show 20 Lines • Show All 314 Lines • ▼ Show 20 Line(s) | 376 | // kDebug() << "lrel=" << lrel; | |||
377 | QString href = e.getAttribute("href").string(); | 380 | QString href = e.getAttribute("href").string(); | ||
378 | // if nowhere to go, ignore the link | 381 | // if nowhere to go, ignore the link | ||
379 | if (href.isEmpty()) { | 382 | if (href.isEmpty()) { | ||
380 | continue; | 383 | continue; | ||
381 | } | 384 | } | ||
382 | QString title = e.getAttribute("title").string(); | 385 | QString title = e.getAttribute("title").string(); | ||
383 | QString hreflang = e.getAttribute("hreflang").string(); | 386 | QString hreflang = e.getAttribute("hreflang").string(); | ||
384 | 387 | | |||
385 | KUrl ref(m_part->url(), href); | 388 | QUrl ref(resolvedUrl(m_part->url(), href)); | ||
386 | if (title.isEmpty()) { | 389 | if (title.isEmpty()) { | ||
387 | title = ref.prettyUrl(); | 390 | title = ref.toDisplayString(); | ||
388 | } | 391 | } | ||
389 | 392 | | |||
390 | // escape ampersand before settings as action title, otherwise the menu entry will interpret it as an | 393 | // escape ampersand before settings as action title, otherwise the menu entry will interpret it as an | ||
391 | // accelerator | 394 | // accelerator | ||
392 | title.replace('&', QLatin1String("&&")); | 395 | title.replace('&', QLatin1String("&&")); | ||
393 | 396 | | |||
394 | // -- Menus activation -- | 397 | // -- Menus activation -- | ||
395 | 398 | | |||
▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Line(s) | 469 | if (rx.indexIn(url) != -1) { | |||
468 | int lenval = rx.cap(2).length(); | 471 | int lenval = rx.cap(2).length(); | ||
469 | QString nval_str = QString::number(val + 1); | 472 | QString nval_str = QString::number(val + 1); | ||
470 | //prepend by zeros if the original also contains zeros. | 473 | //prepend by zeros if the original also contains zeros. | ||
471 | if (nval_str.length() < lenval && rx.cap(2)[0] == '0') { | 474 | if (nval_str.length() < lenval && rx.cap(2)[0] == '0') { | ||
472 | nval_str.prepend(zeros.left(lenval - nval_str.length())); | 475 | nval_str.prepend(zeros.left(lenval - nval_str.length())); | ||
473 | } | 476 | } | ||
474 | 477 | | |||
475 | QString href = rx.cap(1) + nval_str + rx.cap(3); | 478 | QString href = rx.cap(1) + nval_str + rx.cap(3); | ||
476 | KUrl ref(m_part->url(), href); | 479 | QUrl ref(resolvedUrl(m_part->url(), href)); | ||
477 | QString title = i18n("[Autodetected] %1", ref.prettyUrl()); | 480 | QString title = i18n("[Autodetected] %1", ref.toDisplayString()); | ||
478 | DOM::Element e = m_part->document().createElement("link"); | 481 | DOM::Element e = m_part->document().createElement("link"); | ||
479 | e.setAttribute("href", href); | 482 | e.setAttribute("href", href); | ||
480 | QAction *a = actionCollection()->action(QStringLiteral("rellinks_next")); | 483 | QAction *a = actionCollection()->action(QStringLiteral("rellinks_next")); | ||
481 | a->setEnabled(true); | 484 | a->setEnabled(true); | ||
482 | a->setToolTip(title); | 485 | a->setToolTip(title); | ||
483 | a->setData(QVariant::fromValue(e)); | 486 | a->setData(QVariant::fromValue(e)); | ||
484 | 487 | | |||
485 | if (val > 1) { | 488 | if (val > 1) { | ||
486 | nval_str = QString::number(val - 1); | 489 | nval_str = QString::number(val - 1); | ||
487 | if (nval_str.length() < lenval && rx.cap(2)[0] == '0') { | 490 | if (nval_str.length() < lenval && rx.cap(2)[0] == '0') { | ||
488 | nval_str.prepend(zeros.left(lenval - nval_str.length())); | 491 | nval_str.prepend(zeros.left(lenval - nval_str.length())); | ||
489 | } | 492 | } | ||
490 | QString href = rx.cap(1) + nval_str + rx.cap(3); | 493 | QString href = rx.cap(1) + nval_str + rx.cap(3); | ||
491 | KUrl ref(m_part->url(), href); | 494 | QUrl ref(resolvedUrl(m_part->url(), href)); | ||
492 | QString title = i18n("[Autodetected] %1", ref.prettyUrl()); | 495 | QString title = i18n("[Autodetected] %1", ref.toDisplayString()); | ||
493 | e = m_part->document().createElement("link"); | 496 | e = m_part->document().createElement("link"); | ||
494 | e.setAttribute("href", href); | 497 | e.setAttribute("href", href); | ||
495 | QAction *a = actionCollection()->action(QStringLiteral("rellinks_prev")); | 498 | QAction *a = actionCollection()->action(QStringLiteral("rellinks_prev")); | ||
496 | a->setEnabled(true); | 499 | a->setEnabled(true); | ||
497 | a->setToolTip(title); | 500 | a->setToolTip(title); | ||
498 | a->setData(QVariant::fromValue(e)); | 501 | a->setData(QVariant::fromValue(e)); | ||
499 | } | 502 | } | ||
500 | } | 503 | } | ||
501 | } | 504 | } | ||
502 | 505 | | |||
503 | void RelLinksPlugin::goToLink(DOM::Element e) | 506 | void RelLinksPlugin::goToLink(DOM::Element e) | ||
504 | { | 507 | { | ||
505 | // have the KHTML part open it | 508 | // have the KHTML part open it | ||
506 | KHTMLPart *part = qobject_cast<KHTMLPart *>(parent()); | 509 | KHTMLPart *part = qobject_cast<KHTMLPart *>(parent()); | ||
507 | if (!part) { | 510 | if (!part) { | ||
508 | return; | 511 | return; | ||
509 | } | 512 | } | ||
510 | QString href = e.getAttribute("href").string(); | 513 | QString href = e.getAttribute("href").string(); | ||
511 | KUrl url(part->url(), href); | 514 | QUrl url(resolvedUrl(part->url(), href)); | ||
512 | QString target = e.getAttribute("target").string(); | 515 | QString target = e.getAttribute("target").string(); | ||
513 | 516 | | |||
514 | // URL arguments | 517 | // URL arguments | ||
515 | KParts::OpenUrlArguments arguments; | 518 | KParts::OpenUrlArguments arguments; | ||
516 | KParts::BrowserArguments browserArguments; | 519 | KParts::BrowserArguments browserArguments; | ||
517 | browserArguments.frameName = target; | 520 | browserArguments.frameName = target; | ||
518 | 521 | | |||
519 | // Add base url if not valid | 522 | // Add base url if not valid | ||
520 | if (url.isValid()) { | 523 | if (url.isValid()) { | ||
521 | part->browserExtension()->openUrlRequest(url, arguments, browserArguments); | 524 | part->browserExtension()->openUrlRequest(url, arguments, browserArguments); | ||
522 | } else { | 525 | } else { | ||
523 | KUrl baseURL = part->baseURL(); | 526 | QUrl baseURL = part->baseURL(); | ||
524 | QString endURL = url.prettyUrl(); | 527 | QString endURL = url.toDisplayString(); | ||
525 | KUrl realURL = KUrl(baseURL, endURL); | 528 | QUrl realURL = resolvedUrl(baseURL, endURL); | ||
KUrl(base, end) didn't return a relative URL. On the contrary, it would resolve end against base if end is relative. On the next line the URL is passed to openUrlRequest, which only supports absolute URLs. dfaure: KUrl(base, end) didn't return a relative URL. On the contrary, it would resolve end against… | |||||
526 | part->browserExtension()->openUrlRequest(realURL, arguments, browserArguments); | 529 | part->browserExtension()->openUrlRequest(realURL, arguments, browserArguments); | ||
527 | } | 530 | } | ||
528 | 531 | | |||
529 | } | 532 | } | ||
530 | 533 | | |||
531 | void RelLinksPlugin::disableAll() | 534 | void RelLinksPlugin::disableAll() | ||
532 | { | 535 | { | ||
533 | m_linksFound = false; | 536 | m_linksFound = false; | ||
▲ Show 20 Lines • Show All 106 Lines • Show Last 20 Lines |
static in front, & after QString