summaryrefslogtreecommitdiffstats
path: root/src/gui/urlfieldwidget.cpp
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-03-01 19:17:32 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-03-01 19:17:32 +0000
commite38d2351b83fa65c66ccde443777647ef5cb6cff (patch)
tree1897fc20e9f73a81c520a5b9f76f8ed042124883 /src/gui/urlfieldwidget.cpp
downloadtellico-e38d2351b83fa65c66ccde443777647ef5cb6cff.tar.gz
tellico-e38d2351b83fa65c66ccde443777647ef5cb6cff.zip
Added KDE3 version of Tellico
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/tellico@1097620 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/gui/urlfieldwidget.cpp')
-rw-r--r--src/gui/urlfieldwidget.cpp98
1 files changed, 98 insertions, 0 deletions
diff --git a/src/gui/urlfieldwidget.cpp b/src/gui/urlfieldwidget.cpp
new file mode 100644
index 0000000..f3c2afd
--- /dev/null
+++ b/src/gui/urlfieldwidget.cpp
@@ -0,0 +1,98 @@
+/***************************************************************************
+ copyright : (C) 2005-2006 by Robby Stephenson
+ ***************************************************************************/
+
+/***************************************************************************
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of version 2 of the GNU General Public License as *
+ * published by the Free Software Foundation; *
+ * *
+ ***************************************************************************/
+
+#include "urlfieldwidget.h"
+#include "../field.h"
+#include "../latin1literal.h"
+#include "../tellico_kernel.h"
+
+#include <klineedit.h>
+#include <kurlrequester.h>
+#include <kurllabel.h>
+
+using Tellico::GUI::URLFieldWidget;
+
+// subclass of KURLCompletion is needed so the KURLLabel
+// can open relative links. I don't want to have to have to update
+// the base directory of the completion every time a new document is opened
+QString URLFieldWidget::URLCompletion::makeCompletion(const QString& text_) {
+ // KURLCompletion::makeCompletion() uses an internal variable instead
+ // of calling KURLCompletion::dir() so need to set the base dir before completing
+ setDir(Kernel::self()->URL().directory());
+ return KURLCompletion::makeCompletion(text_);
+}
+
+URLFieldWidget::URLFieldWidget(Data::FieldPtr field_, QWidget* parent_, const char* name_/*=0*/)
+ : FieldWidget(field_, parent_, name_), m_run(0) {
+
+ m_requester = new KURLRequester(this);
+ m_requester->lineEdit()->setCompletionObject(new URLCompletion());
+ m_requester->lineEdit()->setAutoDeleteCompletionObject(true);
+ connect(m_requester, SIGNAL(textChanged(const QString&)), SIGNAL(modified()));
+ connect(m_requester, SIGNAL(textChanged(const QString&)), label(), SLOT(setURL(const QString&)));
+ connect(label(), SIGNAL(leftClickedURL(const QString&)), SLOT(slotOpenURL(const QString&)));
+ registerWidget();
+
+ // special case, remember if it's a relative url
+ m_isRelative = field_->property(QString::fromLatin1("relative")) == Latin1Literal("true");
+}
+
+URLFieldWidget::~URLFieldWidget() {
+ if(m_run) {
+ m_run->abort();
+ }
+}
+
+QString URLFieldWidget::text() const {
+ if(m_isRelative) {
+ return KURL::relativeURL(Kernel::self()->URL(), m_requester->url());
+ }
+ // for comparison purposes and to be consistent with the file listing importer
+ // I want the full url here, including the protocol
+ // the requester only returns the path, so create a KURL
+ return KURL(m_requester->url()).url();
+}
+
+void URLFieldWidget::setText(const QString& text_) {
+ blockSignals(true);
+
+ m_requester->blockSignals(true);
+ m_requester->setURL(text_);
+ m_requester->blockSignals(false);
+ static_cast<KURLLabel*>(label())->setURL(text_);
+
+ blockSignals(false);
+}
+
+void URLFieldWidget::clear() {
+ m_requester->clear();
+ editMultiple(false);
+}
+
+void URLFieldWidget::updateFieldHook(Data::FieldPtr, Data::FieldPtr newField_) {
+ m_isRelative = newField_->property(QString::fromLatin1("relative")) == Latin1Literal("true");
+}
+
+void URLFieldWidget::slotOpenURL(const QString& url_) {
+ if(url_.isEmpty()) {
+ return;
+ }
+ // just in case, interpret string relative to document url
+ m_run = new KRun(KURL(Kernel::self()->URL(), url_));
+}
+
+QWidget* URLFieldWidget::widget() {
+ return m_requester;
+}
+
+#include "urlfieldwidget.moc"