[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [calligra] /: Expansion of the References section by adding features to insert hyperlinks,
From:       Aman Madaan <madaan.amanmadaan () gmail ! com>
Date:       2013-04-08 13:02:51
Message-ID: 20130408130251.49D09A605B () git ! kde ! org
[Download RAW message or body]

Git commit 5612ffd0717a27a0b30ad313c3ba60b8eee8ec8b by Aman Madaan.
Committed on 08/04/2013 at 11:23.
Pushed by amanm into branch 'master'.

Expansion of the References section by adding features to insert hyperlinks,
bookmarks and links to bookmarks.

This patch adds the following features :

1. Inserting hyperlinks

   -- User has a choice of inserting a link by specifying the target and the
link text.
   -- The user may fetch the title from the web page itself (contents of the
"title" tag ). This feature also handles URL redirects.This feature will especially
help in cases when a user has a list of links referred to and a list of references
has to be created. Just copy/pasting the URL, clicking fetch and then insert will do \
the job.

2. Linking to bookmarks

   -- A user can specify a bookmark name and the link text. To help the user
with inserting a bookmark, an auto completer is used.

3. Adding Bookmark using a labeled widget ( similar to the way footnote and
endnote labels are entered)

4. Improvement to the Manage Bookmarks ui by adding feature to insert a bookmark
and fixing bugs.

A list of commit headlines follow :

    Added licenses
    Fixed Insert and Rename feature in ManageBookmarks.
    Deleted Advanced options.
    Combined bookmark name line edit and the list widget into an editable combobox.
    Finised Internationalization
    Modify insertText() to accomodate links
    Merged LinkedInsertionDialog, WeblinkInsertionWidget and
    Add a new bookmark to the list as it is added
    Simple Link insertion finished.
    Added the SimpleLinkWidget to the references dock
    sg

M  +18   -2    libs/kotext/KoTextEditor.cpp
M  +9    -1    libs/kotext/KoTextEditor.h
M  +7    -1    plugins/textshape/CMakeLists.txt
M  +119  -22   plugins/textshape/ReferencesTool.cpp
M  +27   -10   plugins/textshape/ReferencesTool.h
A  +295  -0    plugins/textshape/dialogs/LinkInsertionDialog.cpp     [License: LGPL \
(v2+)] A  +80   -0    plugins/textshape/dialogs/LinkInsertionDialog.h     [License: \
LGPL (v2+)] A  +221  -0    plugins/textshape/dialogs/LinkInsertionDialog.ui
A  +55   -0    plugins/textshape/dialogs/ManageBookmark.ui
A  +177  -0    plugins/textshape/dialogs/ManageBookmarkDialog.cpp     [License: LGPL \
(v2+)] A  +76   -0    plugins/textshape/dialogs/ManageBookmarkDialog.h     [License: \
LGPL (v2+)] A  +0    -0    plugins/textshape/dialogs/SelectBookmarkDialog.h     \
[License: Trivial file] A  +104  -0    \
plugins/textshape/dialogs/SimpleLinksWidget.cpp     [License: LGPL (v2+)] A  +52   -0 \
plugins/textshape/dialogs/SimpleLinksWidget.h     [License: LGPL (v2+)] A  +90   -0   \
plugins/textshape/dialogs/SimpleLinksWidget.ui A  +0    -0    \
plugins/textshape/dialogs/UnifiedLinkInsertionDialog.h     [License: Trivial file]

http://commits.kde.org/calligra/5612ffd0717a27a0b30ad313c3ba60b8eee8ec8b

diff --git a/libs/kotext/KoTextEditor.cpp b/libs/kotext/KoTextEditor.cpp
index 4ddfa26..1a88757 100644
--- a/libs/kotext/KoTextEditor.cpp
+++ b/libs/kotext/KoTextEditor.cpp
@@ -1412,7 +1412,7 @@ KoInlineCite *KoTextEditor::insertCitation()
     return cite;
 }
 
-void KoTextEditor::insertText(const QString &text)
+void KoTextEditor::insertText(const QString &text, const QString &hRef)
 {
     if (isEditProtected()) {
         return;
@@ -1442,7 +1442,18 @@ void KoTextEditor::insertText(const QString &text)
     if (format.hasProperty(KoCharacterStyle::ChangeTrackerId)) {
         format.clearProperty(KoCharacterStyle::ChangeTrackerId);
     }
+    static QRegExp urlScanner("\\S+://\\S+");
+    if (!hRef.isEmpty()) {
+        format.setAnchor(true);
+        format.setProperty(KoCharacterStyle::AnchorType, KoCharacterStyle::Anchor);
+        if ((urlScanner.indexIn(hRef)) == 0) {//web url
+            format.setAnchorHref(hRef);
+        } else {
+            format.setAnchorHref("#"+hRef);
+        }
+    }
     d->caret.insertText(text, format);
+
     int endPosition = d->caret.position();
 
     //Mark the inserted text
@@ -1457,7 +1468,12 @@ void KoTextEditor::insertText(const QString &text)
         d->caret.endEditBlock();
         endEditBlock();
     }
-
+    if (!hRef.isEmpty()) {
+        format.setAnchor(false);
+        format.clearProperty(KoCharacterStyle::Anchor);
+        format.clearProperty(KoCharacterStyle::AnchorType);
+        d->caret.setCharFormat(format);
+    }
     emit cursorPositionChanged();
 }
 
diff --git a/libs/kotext/KoTextEditor.h b/libs/kotext/KoTextEditor.h
index f96ab70..9fd3c05 100644
--- a/libs/kotext/KoTextEditor.h
+++ b/libs/kotext/KoTextEditor.h
@@ -441,7 +441,15 @@ public slots:
 
     KoInlineCite *insertCitation();
 
-    void insertText(const QString &text);
+    /**
+     * Inserts the supplied text at the current cursor position. If the second \
argument is +     * supplied, a link is inserted at the current cursor position with \
the hRef as given +     * by the user. To test whether the supplied link destination \
is a web url or a bookmark, +     * a regular expression ( \\S+://\\S+ ) is used. 
+     * @param text is the text to be inserted
+     * @param hRef if supplied is the Hypertext reference
+     */
+    void insertText(const QString &text, const QString &hRef = QString());
 
     void insertHtml(const QString &html);
 
diff --git a/plugins/textshape/CMakeLists.txt b/plugins/textshape/CMakeLists.txt
index b2bf9ae..375c730 100644
--- a/plugins/textshape/CMakeLists.txt
+++ b/plugins/textshape/CMakeLists.txt
@@ -49,8 +49,10 @@ SET ( textshape_SRCS
     dialogs/SimpleParagraphWidget.cpp
     dialogs/SimpleTableWidget.cpp
     dialogs/SimpleInsertWidget.cpp
+    dialogs/LinkInsertionDialog.cpp
     dialogs/SimpleTableOfContentsWidget.cpp
     dialogs/SimpleCitationBibliographyWidget.cpp
+    dialogs/SimpleLinksWidget.cpp
     dialogs/SimpleSpellCheckingWidget.cpp
     dialogs/CitationInsertionDialog.cpp
     dialogs/InsertBibliographyDialog.cpp
@@ -101,6 +103,7 @@ SET ( textshape_SRCS
     dialogs/BibliographyTemplate.cpp
     dialogs/BibliographyPreview.cpp
     dialogs/ListLevelChooser.cpp
+    dialogs/ManageBookmarkDialog.cpp
 
     commands/ChangeListLevelCommand.cpp
     commands/ShowChangesCommand.cpp
@@ -146,13 +149,16 @@ kde4_add_ui_files(textshape_SRCS
     dialogs/TableDialog.ui
     dialogs/BibliographyConfigureDialog.ui
     dialogs/TableOfContentsConfigure.ui
+    dialogs/SimpleLinksWidget.ui
     dialogs/TableOfContentsStyleConfigure.ui
-
     dialogs/FontDecorations.ui
     dialogs/LanguageTab.ui
     dialogs/ChangeConfigureDialog.ui
     dialogs/AcceptRejectChangeDialog.ui
     dialogs/TrackedChangeManager.ui
+    dialogs/LinkInsertionDialog.ui
+    dialogs/ManageBookmark.ui
+
 )
 
 kde4_add_plugin(textshape ${textshape_SRCS})
diff --git a/plugins/textshape/ReferencesTool.cpp \
b/plugins/textshape/ReferencesTool.cpp index 4336d71..dfb01ef 100644
--- a/plugins/textshape/ReferencesTool.cpp
+++ b/plugins/textshape/ReferencesTool.cpp
@@ -1,5 +1,6 @@
 /* This file is part of the KDE project
  * Copyright (C) 2011 C. Boemann <cbo@boemann.dk>
+ * Copyright (C) 2013 Aman Madaan <madaan.amanmadaan@gmail.com>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -23,11 +24,13 @@
 #include "dialogs/SimpleCitationBibliographyWidget.h"
 #include "dialogs/SimpleFootEndNotesWidget.h"
 #include "dialogs/SimpleCaptionsWidget.h"
+#include "dialogs/SimpleLinksWidget.h"
 #include "dialogs/TableOfContentsConfigure.h"
 #include "dialogs/NotesConfigurationDialog.h"
 #include "dialogs/CitationInsertionDialog.h"
 #include "dialogs/InsertBibliographyDialog.h"
 #include "dialogs/BibliographyConfigureDialog.h"
+#include "dialogs/LinkInsertionDialog.h"
 
 #include <KoTextLayoutRootArea.h>
 #include <KoCanvasBase.h>
@@ -38,50 +41,77 @@
 #include <KoInlineNote.h>
 #include <KoTextDocumentLayout.h>
 #include <KoIcon.h>
+#include <QMessageBox>
 
-#include <kdebug.h>
-
-#include <klocale.h>
-#include <kaction.h>
+#include <KDebug>
+#include <KLocale>
+#include <KAction>
 #include <QTextDocument>
 #include <QLineEdit>
 #include <QBoxLayout>
 #include <QMenu>
 
-LabeledNoteWidget::LabeledNoteWidget(KAction *action)
+LabeledWidget::LabeledWidget(KAction *action, const QString label, LabelPosition lb, \
bool warningLabelRequired)  : QWidget()
     , m_action(action)
 {
     setMouseTracking(true);
-    QHBoxLayout *layout = new QHBoxLayout();
-    QLabel *l = new QLabel(i18n("Insert with label:"));
-    l->setIndent(l->style()->pixelMetric(QStyle::PM_SmallIconSize)
-        + l->style()->pixelMetric(QStyle::PM_MenuPanelWidth)
-        + 4);
-    layout->addWidget(l);
+    QBoxLayout *layout;
+    QLabel *l = new QLabel(label);
+    l->setWordWrap(true);
     m_lineEdit = new QLineEdit();
+    if (lb == LabeledWidget::INLINE) { // label followed by line edit
+        layout = new QHBoxLayout();
+        l->setIndent(l->style()->pixelMetric(QStyle::PM_SmallIconSize)
+                    + l->style()->pixelMetric(QStyle::PM_MenuPanelWidth) + 4);
+    } else { //Label goes above the text edit
+        layout = new QVBoxLayout();
+        m_lineEdit->setFixedWidth(300); //TODO : assuming a reasonable width, is \
there a better way? +    }
+    layout->addWidget(l);
     layout->addWidget(m_lineEdit);
+    if (warningLabelRequired) {
+        m_warningLabel[0] = new QLabel("");
+        m_warningLabel[1] = new QLabel("");
+        m_warningLabel[0]->setWordWrap(true);
+        m_warningLabel[1]->setWordWrap(true);
+        layout->addWidget(m_warningLabel[0]);
+        layout->addWidget(m_warningLabel[1]);
+    }
     layout->setMargin(0);
     setLayout(layout);
-
     connect(m_lineEdit, SIGNAL(returnPressed()), this, SLOT(returnPressed()));
+    connect(m_lineEdit, SIGNAL(textChanged(QString)), this, \
SIGNAL(lineEditChanged(QString)));  }
 
-void LabeledNoteWidget::returnPressed()
+void LabeledWidget::returnPressed()
 {
     emit triggered(m_lineEdit->text());
 }
 
-
-void LabeledNoteWidget::enterEvent(QEvent *event)
+void LabeledWidget::enterEvent(QEvent *event)
 {
     m_action->activate(QAction::Hover);
     QWidget::enterEvent(event);
 }
 
+void LabeledWidget::setWarningText(int pos, const QString& warning)
+{
+    if ((m_warningLabel[pos] == NULL)) {
+        return;
+    }
+    m_warningLabel[pos]->setText(warning);
+}
+
+void LabeledWidget::clearLineEdit()
+{
+    m_lineEdit->setText("");
+}
+
 ReferencesTool::ReferencesTool(KoCanvasBase* canvas): TextTool(canvas),
     m_configure(0),
-    m_stocw(0)
+    m_stocw(0),
+    m_canvas(canvas)
 {
     createActions();
 }
@@ -110,7 +140,7 @@ void ReferencesTool::createActions()
     connect(action, SIGNAL(triggered()), this, SLOT(insertAutoFootNote()));
 
     action = new KAction(i18n("Insert Labeled Footnote"), this);
-    QWidget *w = new LabeledNoteWidget(action);
+    QWidget *w = new LabeledWidget(action, i18n("Insert with label:"), \
LabeledWidget::INLINE, false);  action->setDefaultWidget(w);
     addAction("insert_labeledfootnote", action);
     connect(w, SIGNAL(triggered(QString)), this, \
SLOT(insertLabeledFootNote(QString))); @@ -120,7 +150,7 @@ void \
                ReferencesTool::createActions()
     connect(action, SIGNAL(triggered()), this, SLOT(insertAutoEndNote()));
 
     action = new KAction(i18n("Insert Labeled Endnote"), this);
-    w = new LabeledNoteWidget(action);
+    w = new LabeledWidget(action, i18n("Insert with label:"), LabeledWidget::INLINE, \
false);  action->setDefaultWidget(w);
     addAction("insert_labeledendnote", action);
     connect(w, SIGNAL(triggered(QString)), this, \
SLOT(insertLabeledEndNote(QString))); @@ -133,24 +163,47 @@ void \
ReferencesTool::createActions()  addAction("format_endnotes",action);
     connect(action, SIGNAL(triggered()), this, SLOT(showEndnotesConfigureDialog()));
 
-    action = new KAction(i18n("Insert Citation"),this);
+    action = new KAction(i18n("Insert Citation"), this);
     addAction("insert_citation",action);
     action->setToolTip(i18n("Insert a citation into the document."));
     connect(action, SIGNAL(triggered()), this, SLOT(insertCitation()));
 
-    action = new KAction(i18n("Insert Bibliography"),this);
+    action = new KAction(i18n("Insert Bibliography"), this);
     addAction("insert_bibliography",action);
     action->setToolTip(i18n("Insert a bibliography into the document."));
 
     action = new KAction(i18n("Insert Custom Bibliography"), this);
     addAction("insert_custom_bibliography", action);
     action->setToolTip(i18n("Insert a custom Bibliography into the document."));
+
     action = new KAction(i18n("Configure"),this);
     addAction("configure_bibliography",action);
     action->setToolTip(i18n("Configure the bibliography"));
     connect(action, SIGNAL(triggered()), this, SLOT(configureBibliography()));
+
+    action = new KAction(i18n("Insert Link"), this);
+    addAction("insert_link", action);
+    action->setToolTip(i18n("Insert a weblink or link to a bookmark."));
+    connect(action, SIGNAL(triggered()), this, SLOT(insertLink()));
+
+    action = new KAction(i18n("Add Bookmark"), this);
+    m_bmark = new LabeledWidget(action, i18n("Add Bookmark :"), \
LabeledWidget::ABOVE, true); +    connect(m_bmark, SIGNAL(lineEditChanged(QString)), \
this, SLOT(validateBookmark(QString))); +    action->setDefaultWidget(m_bmark);
+    addAction("insert_bookmark", action);
+    connect(m_bmark, SIGNAL(triggered(QString)), this, \
SLOT(insertBookmark(QString))); +    action->setToolTip(i18n("Insert a Bookmark. This \
is useful to create links that point to areas within the document")); +
+    action = new KAction(i18n("Bookmarks"), this);
+    addAction("invoke_bookmark_handler", action);
+    action->setToolTip(i18n("Display a pop up that hosts the options to add new \
Bookmark or handle existing Bookmarks")); +
+    action = new KAction(i18n("Manage Bookmarks"), this);
+    addAction("manage_bookmarks", action);
+    action->setToolTip(i18n("Manage your Bookmarks. Check where are they pointing \
to, Delete or Rename."));  }
 
+
 void ReferencesTool::activate(ToolActivation toolActivation, const QSet<KoShape*> \
&shapes)  {
     TextTool::activate(toolActivation, shapes);
@@ -167,9 +220,11 @@ QList<QWidget*> ReferencesTool::createOptionWidgets()
     QList<QWidget *> widgets;
     m_stocw = new SimpleTableOfContentsWidget(this, 0);
 
-    m_sfenw = new SimpleFootEndNotesWidget(this,0);
+    m_sfenw = new SimpleFootEndNotesWidget(this, 0);
+
+    m_scbw = new SimpleCitationBibliographyWidget(this, 0);
 
-    m_scbw = new SimpleCitationBibliographyWidget(this,0);
+    m_slw = new SimpleLinksWidget(this, 0);
     // Connect to/with simple table of contents option widget
     connect(m_stocw, SIGNAL(doneWithFocus()), this, SLOT(returnFocusToCanvas()));
 
@@ -179,6 +234,8 @@ QList<QWidget*> ReferencesTool::createOptionWidgets()
     // Connect to/with simple citation index option widget
     connect(m_sfenw, SIGNAL(doneWithFocus()), this, SLOT(returnFocusToCanvas()));
 
+    connect(m_slw, SIGNAL(doneWithFocus()), this, SLOT(returnFocusToCanvas()));
+
     m_stocw->setWindowTitle(i18n("Table of Contents"));
     widgets.append(m_stocw);
 
@@ -187,6 +244,9 @@ QList<QWidget*> ReferencesTool::createOptionWidgets()
 
     m_scbw->setWindowTitle(i18n("Citations and Bibliography"));
     widgets.append(m_scbw);
+
+    m_slw->setWindowTitle(i18n("Links and Bookmarks"));
+    widgets.append(m_slw);
     //widgets.insert(i18n("Captions"), scapw);
     connect(textEditor(), SIGNAL(cursorPositionChanged()), this, \
SLOT(updateButtons()));  return widgets;
@@ -321,4 +381,41 @@ void ReferencesTool::customToCGenerated()
     }
 }
 
+void ReferencesTool::insertLink()
+{
+    new LinkInsertionDialog(textEditor(), m_slw);
+}
+
+bool ReferencesTool::validateBookmark(QString bookmarkName)
+{
+    bookmarkName = bookmarkName.trimmed();
+    if (bookmarkName.isEmpty()) {
+        m_bmark->setWarningText(0, i18n("Bookmark cannot be empty"));
+        return false;
+    }
+    const KoBookmarkManager *manager = \
KoTextDocument(editor()->document()).textRangeManager()->bookmarkManager(); +    \
QStringList existingBookmarks = manager->bookmarkNameList(); +    int position = \
existingBookmarks.indexOf(bookmarkName); +    if (position != -1) {
+        m_bmark->setWarningText(0, i18n("Duplicate Name. Click \"Manage \
Bookmarks\"")); +        m_bmark->setWarningText(1, i18n("to Rename or Delete \
Bookmarks")); +        return false;
+    } else {
+        m_bmark->setWarningText(0, "");
+        m_bmark->setWarningText(1, "");
+        return true;
+    }
+}
+
+void ReferencesTool::insertBookmark(QString bookMarkName)
+{
+    bookMarkName = bookMarkName.trimmed();
+    m_bmark->setWarningText(0, "");
+    m_bmark->setWarningText(1, "");
+    if (validateBookmark(bookMarkName)) {
+        editor()->addBookmark(bookMarkName);
+        m_bmark->clearLineEdit();
+    }
+}
+
 #include <ReferencesTool.moc>
diff --git a/plugins/textshape/ReferencesTool.h b/plugins/textshape/ReferencesTool.h
index 21caea8..c272d80 100644
--- a/plugins/textshape/ReferencesTool.h
+++ b/plugins/textshape/ReferencesTool.h
@@ -1,5 +1,6 @@
 /* This file is part of the KDE project
  * Copyright (C) 2011 C. Boemann <cbo@boemann.dk>
+ * Copyright (C) 2013 Aman Madaan <madaan.amanmadaan@gmail.com>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -21,6 +22,7 @@
 #define REFERENCESTOOL_H
 
 #include "TextTool.h"
+#include <signal.h>
 
 class KoCanvasBase;
 class TableOfContentsConfigure;
@@ -30,7 +32,8 @@ class SimpleCitationBibliographyWidget;
 class KoInlineNote;
 class KoTextEditor;
 class QPainter;
-
+class SimpleLinksWidget;
+class LabeledWidget;
 /// This tool is the ui for inserting Table of Contents, Citations/bibliography, \
footnotes, endnotes, index, table of illustrations etc  
 class ReferencesTool : public TextTool
@@ -83,34 +86,48 @@ private slots:
     void updateButtons();
 
     void customToCGenerated();
-
+    /// insert a Link
+    void insertLink();
+    ///insert a bookmark
+    void insertBookmark(QString bookmarkName);
+    /// validate a bookmark
+    bool validateBookmark(QString bookmarkName);
 private:
     TableOfContentsConfigure *m_configure;
     SimpleTableOfContentsWidget *m_stocw;
-        SimpleFootEndNotesWidget *m_sfenw;
-        KoInlineNote *m_note;
+    SimpleFootEndNotesWidget *m_sfenw;
+    KoInlineNote *m_note;
     SimpleCitationBibliographyWidget *m_scbw;
+    SimpleLinksWidget *m_slw;
+    LabeledWidget *m_bmark;
+    KoCanvasBase *m_canvas;
 };
 
 class KAction;
 class QLineEdit;
-
-class LabeledNoteWidget : public QWidget
+class QLabel;
+class LabeledWidget : public QWidget
 {
     Q_OBJECT
 public:
-    explicit LabeledNoteWidget(KAction *action);
-    KAction *m_action;
-    QLineEdit *m_lineEdit;
-
+    enum LabelPosition {INLINE, ABOVE};
+    LabeledWidget(KAction *action, const QString label, LabelPosition pos, bool \
warningLabelRequired); +    void setWarningText(int pos, const QString &warning);
+    void clearLineEdit();
 signals:
     void triggered(QString label);
+    void lineEditChanged(QString);
 
 private slots:
     void returnPressed();
 
 protected:
     virtual void enterEvent(QEvent *event);
+
+private :
+    QLineEdit *m_lineEdit;
+    QLabel *m_warningLabel[2];
+    KAction *m_action;
 };
 
 #endif // REFERENCESTOOL_H
diff --git a/plugins/textshape/dialogs/LinkInsertionDialog.cpp \
b/plugins/textshape/dialogs/LinkInsertionDialog.cpp new file mode 100644
index 0000000..e5c8e23
--- /dev/null
+++ b/plugins/textshape/dialogs/LinkInsertionDialog.cpp
@@ -0,0 +1,295 @@
+/* This file is part of the KDE project
+ * Copyright (C) 2013 Aman Madaan <madaan.amanmadaan@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.q
+ */
+#include "LinkInsertionDialog.h"
+#include "SimpleTableOfContentsWidget.h"
+#include <QString>
+#include <QCompleter>
+#include <QComboBox>
+#include <QLabel>
+#include <QDialogButtonBox>
+
+
+LinkInsertionDialog::LinkInsertionDialog(KoTextEditor* editor, QWidget* parent)
+    : QDialog(parent)
+    , m_editor(editor)
+    , m_bookmarkManager(0)
+    , m_bookmarkList(0)
+    , m_reply(0)
+    , m_networkAccessManager(0)
+    , m_linkURL(0)
+    , m_timeoutTimer(0)
+{
+    dlg.setupUi(this);
+    setUpdatesEnabled(false);
+    // set up the tabs with selected text
+    QString suggestedLinkText;
+    if (m_editor->hasSelection()) {
+        suggestedLinkText = m_editor->selectedText();
+        dlg.hyperlinkText->setText(suggestedLinkText);
+        dlg.bookmarkLinkText->setText(suggestedLinkText);
+    }
+    connect(dlg.buttonBox, SIGNAL(accepted()), this, SLOT(insertLink()));
+    connect(dlg.buttonBox, SIGNAL(rejected()), this, SLOT(close()));
+    dlg.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
+
+    ///setting up the web link insertion tab
+    m_networkAccessManager = new QNetworkAccessManager(this);
+    connect(dlg.fetchTitleButton, SIGNAL(clicked()), this, \
SLOT(fetchTitleFromURL())); +    dlg.fetchTitleButton->setEnabled(false);
+    setUpdatesEnabled(true);
+
+    ///setting up the bookmark link insertion tab
+    //connect(dlg.bookmarkListWidget, SIGNAL(itemActivated(QListWidgetItem *)), \
this, SLOT(slotItemClicked(QListWidgetItem *))); +    m_bookmarkManager =  \
KoTextDocument(editor->document()).textRangeManager()->bookmarkManager(); +    \
m_bookmarkList = m_bookmarkManager->bookmarkNameList(); +    QCompleter \
*bookmarkAutoCompleter = new QCompleter(m_bookmarkList, this); +    \
dlg.bookmarkLinkURL->setCompleter(bookmarkAutoCompleter); +    \
dlg.bookmarkLinkURL->addItems(m_bookmarkList); +    \
dlg.bookmarkLinkURL->clearEditText(); +    connect(dlg.hyperlinkURL, \
SIGNAL(textChanged(QString)), this, SLOT(enableDisableButtons(QString))); +    \
connect(dlg.hyperlinkText, SIGNAL(textChanged(QString)), this, \
SLOT(enableDisableButtons(QString))); +    connect(dlg.bookmarkLinkURL, \
SIGNAL(textChanged(QString)), this, SLOT(enableDisableButtons(QString))); +    \
connect(dlg.bookmarkLinkText, SIGNAL(textChanged(QString)), this, \
SLOT(enableDisableButtons(QString))); +
+    connect(dlg.linkTypesTab, SIGNAL(currentChanged(int)), this, \
SLOT(checkInsertEnableValidity(int))); +    show();
+}
+void LinkInsertionDialog::enableDisableButtons(QString text)
+{
+    text = text.trimmed();
+    QObject *signalSender = (sender());
+    if (qobject_cast< QLineEdit* >(signalSender) == dlg.hyperlinkURL) {  //deal with \
fetch button +        if (!text.isEmpty()) { // is empty?
+            if (!QUrl(text).isValid()) { //not empty, is it valid?
+                dlg.fetchTitleButton->setEnabled(false);
+                dlg.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);//not \
valid too, time to get out +                displayInlineWarning(i18n("The URL is \
invalid"), dlg.weblinkStatusLabel); +                return;
+             } else { //valid but non empty, can fetch but not sure about the others \
so can't OK +                displayInlineWarning("", dlg.weblinkStatusLabel);
+                dlg.fetchTitleButton->setEnabled(true);
+             }
+        } else { //field is empty, no other choice
+            dlg.fetchTitleButton->setEnabled(false);
+            dlg.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
+            return;
+        }
+    } else if (qobject_cast< QComboBox* >(signalSender) == dlg.bookmarkLinkURL) { \
//need to check existence +            if \
(dlg.bookmarkLinkURL->currentText().isEmpty()) { +                \
displayInlineWarning("", dlg.bookmarkLinkStatusLabel); +                \
dlg.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); +                \
return; +            } else if (!exists(dlg.bookmarkLinkURL->currentText())) { \
//definitely can't go in +                displayInlineWarning(i18n("Bookmark does \
not exist"), dlg.bookmarkLinkStatusLabel); +                \
dlg.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); +                \
return; +            } else {  //non empty and exits
+                displayInlineWarning("", dlg.bookmarkLinkStatusLabel); //can clear \
the label but cannot be sure about OK +            }
+    } else if (text.isEmpty()) { //for others, empty is definitely incorrect
+        dlg.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
+        return;
+    }
+    switch (dlg.linkTypesTab->currentIndex()) { //handle cases that reach here, only \
doubt is completeness +    case 0 :
+        if (!dlg.hyperlinkText->text().isEmpty() && \
QUrl(dlg.hyperlinkURL->text()).isValid() && !dlg.hyperlinkURL->text().isEmpty()) { +  \
dlg.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); +        }
+        break;
+    case 1:
+        if (!dlg.bookmarkLinkText->text().isEmpty() && \
!dlg.bookmarkLinkURL->currentText().isEmpty() && \
exists(dlg.bookmarkLinkURL->currentText())) { +            \
dlg.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); +        }
+        break;
+    }
+}
+
+void LinkInsertionDialog::checkInsertEnableValidity(int currentTab)
+{
+    dlg.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
+    switch (currentTab) {
+     case 0 :
+        if (!dlg.hyperlinkText->text().isEmpty() && \
QUrl(dlg.hyperlinkURL->text()).isValid() && !dlg.hyperlinkURL->text().isEmpty()) { +  \
dlg.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); +        }
+        break;
+    case 1:
+        if (!dlg.bookmarkLinkText->text().isEmpty() && \
!dlg.bookmarkLinkURL->currentText().isEmpty() && \
exists(dlg.bookmarkLinkURL->currentText())) { +            \
dlg.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); +        }
+        break;
+    }
+}
+
+void LinkInsertionDialog::insertLink()
+{
+    if (dlg.linkTypesTab->currentIndex() == 0) {
+        QString linkText = dlg.hyperlinkText->text();
+        QString linkURL = dlg.hyperlinkURL->text();
+        insertHyperlink(linkURL, linkText);
+    } else {
+        QString linkName = dlg.bookmarkLinkURL->currentText();
+        QString linkText = dlg.bookmarkLinkText->text();
+        insertBookmarkLink(linkName, linkText);
+    }
+}
+
+void LinkInsertionDialog::displayInlineWarning(const QString& warning, QLabel \
*label) const +{
+    label->setText(warning);
+}
+
+void LinkInsertionDialog::insertHyperlink(QString& linkURLString, const QString& \
linkText) +{
+    QString linkhtml;
+    QUrl linkURL  = QUrl(linkURLString);
+    dlg.weblinkStatusLabel->setText("");
+    if (!linkURL.isValid()) {
+        displayInlineWarning(i18n("The URL is invalid"), dlg.weblinkStatusLabel);
+    } else {
+        if ((linkURL.scheme()).isEmpty()) {  //prepend a scheme if not present
+            linkURLString.prepend("http://");
+        }
+        m_editor->insertText(linkText, linkURLString);
+        this->close();
+    }
+}
+
+void LinkInsertionDialog::insertBookmarkLink(const QString &linkURL, const QString \
&linkText) +{
+    dlg.bookmarkLinkStatusLabel->setText("");
+    m_editor->insertText(linkText, linkURL);
+    this->close();
+}
+
+bool LinkInsertionDialog::exists(const QString &bookmarkName) const
+{
+    return m_bookmarkList.contains(bookmarkName);
+}
+
+void LinkInsertionDialog::fetchTitleFromURL()
+{
+    QString linkURLString = dlg.hyperlinkURL->text();
+    m_linkURL = QUrl(linkURLString);
+    if (m_linkURL.isValid()) {
+        if ((m_linkURL.scheme()).isEmpty()) {  //prepend a scheme if not present
+            linkURLString.prepend("http://");
+            dlg.hyperlinkURL->setText(linkURLString);
+            m_linkURL.setUrl(linkURLString);
+        }
+        sendRequest();
+    } else {
+        displayInlineWarning(i18n("The URL is invalid"), dlg.weblinkStatusLabel);
+        return;
+    }
+    dlg.weblinkStatusLabel->setText(i18n("Fetching the title : 0% complete"));
+}
+void LinkInsertionDialog::sendRequest()
+{
+    QNetworkRequest request;
+    request.setUrl(m_linkURL);
+    m_reply = m_networkAccessManager->get(request);
+    //start a timer to notify user when it takes too long to get the title
+    if (m_timeoutTimer.isActive()) { //a timer for every redirection
+        m_timeoutTimer.stop();
+    }
+    m_timeoutTimer.setInterval(FETCH_TIMEOUT);
+    m_timeoutTimer.setSingleShot(true);
+    m_timeoutTimer.start();
+    connect(&m_timeoutTimer, SIGNAL(timeout()), this, SLOT(fetchTitleTimeout()));
+    connect(m_reply, SIGNAL(finished()), this, SLOT(replyFinished()));
+    connect(m_reply, SIGNAL(error(QNetworkReply::NetworkError)), this, \
SLOT(fetchTitleError(QNetworkReply::NetworkError))); +    connect(m_reply, \
SIGNAL(downloadProgress(qint64,qint64)), this, \
SLOT(updateTitleDownloadProgress(qint64,qint64))); +}
+
+void LinkInsertionDialog::fetchTitleTimeout()
+{
+    if (!m_reply->isFinished()) {
+        displayInlineWarning(i18n("Fetch timed out"), dlg.weblinkStatusLabel);
+        m_reply->abort();
+    }
+}
+
+void LinkInsertionDialog::replyFinished()
+{
+    //check for redirections
+    QVariant possibleRedirectVariant =
+                        \
m_reply->attribute(QNetworkRequest::RedirectionTargetAttribute); +    QUrl \
possibleRedirectUrl = possibleRedirectVariant.toUrl(); +    if \
(!possibleRedirectUrl.isEmpty() && m_linkURL != possibleRedirectUrl) { //redirect +   \
if (possibleRedirectUrl.toString().at(0) == '/') { //redirection to a relative url +  \
if (m_linkURL.toString().at(m_linkURL.toString().length() - 1) == '/') { //initially \
of the form http:xyz.com/ +                \
possibleRedirectUrl.setUrl(m_linkURL.toString() + \
possibleRedirectUrl.toString().remove(0,1)); +            } else {
+                possibleRedirectUrl.setUrl(m_linkURL.toString() + \
possibleRedirectUrl.toString()); +            }
+        }
+        m_linkURL = possibleRedirectUrl;
+        sendRequest();
+        return;
+    }
+    const QString res = m_reply->readAll();
+    static QRegExp titleStart("<title");//title tag can have attributes, so can't \
search for <title> +    static QRegExp titleEnd("</title>");
+    int start = titleStart.indexIn(res);
+    if (start == -1) { //perhaps TITLE?, rare but possible
+        start = QRegExp("<TITLE").indexIn(res);
+        if (start == -1) {
+            displayInlineWarning("Error fetching title", dlg.weblinkStatusLabel);
+            return;
+        }
+    }
+    //now move to the end of the title
+    while (res.at(start) != QChar('>')) {
+        start++;
+    }
+    start++; //eat the '>'
+    int end = titleEnd.indexIn(res);
+    if (end == -1) {
+        end = QRegExp("</TITLE>").indexIn(res);
+        if (end == -1) {
+            displayInlineWarning("Error fetching title", dlg.weblinkStatusLabel);
+            return;
+        }
+    }
+    dlg.hyperlinkText->setText(QStringRef(&res, start, end - start).toString());
+    dlg.weblinkStatusLabel->setText("");
+}
+
+void LinkInsertionDialog::updateTitleDownloadProgress(qint64 received, qint64 total)
+{
+    float percentComplete = (static_cast<float>(received) / total) * 100;
+    dlg.weblinkStatusLabel->setText(i18n("Fetching the title : %1 % complete", \
QString::number(percentComplete))); +}
+
+LinkInsertionDialog::~LinkInsertionDialog()
+{
+    m_networkAccessManager->deleteLater();
+}
+
+void LinkInsertionDialog::fetchTitleError(QNetworkReply::NetworkError)
+{
+    m_timeoutTimer.stop();
+    displayInlineWarning(i18n("The URL is invalid"), dlg.weblinkStatusLabel);
+}
+
+void LinkInsertionDialog::accept()
+{
+    //Overloaded to prevent the dialog from closing
+}
diff --git a/plugins/textshape/dialogs/LinkInsertionDialog.h \
b/plugins/textshape/dialogs/LinkInsertionDialog.h new file mode 100644
index 0000000..294248c
--- /dev/null
+++ b/plugins/textshape/dialogs/LinkInsertionDialog.h
@@ -0,0 +1,80 @@
+/* This file is part of the KDE project
+ * Copyright (C) 2013 Aman Madaan <madaan.amanmadaan@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+#ifndef LINKINSERTDIALOG
+#define LINKINSERTDIALOG
+#include <ui_LinkInsertionDialog.h>
+#include <QDialog>
+#include <qnetworkreply.h>
+#include <qnetworkaccessmanager.h>
+#include <QWidget>
+#include <KoBookmarkManager.h>
+#include <KoTextRangeManager.h>
+#include <KoTextDocument.h>
+#include <QListWidget>
+#define FETCH_TIMEOUT 5000
+
+class LinkInsertionDialog : public QDialog
+{
+    Q_OBJECT
+public :
+    LinkInsertionDialog(KoTextEditor *editor, QWidget *parent = 0);
+    virtual ~LinkInsertionDialog();
+
+private slots:
+    void insertLink();
+
+public slots:
+
+    void fetchTitleFromURL();
+    void replyFinished();
+    void fetchTitleError(QNetworkReply::NetworkError);
+    void updateTitleDownloadProgress(qint64, qint64);
+    void fetchTitleTimeout();
+    /**
+    * Verifies the text entered in the four line edits : Weblink URL, Weblink text,
+    * Bookmark name and Bookmark text. The "Ok" button is enabled only if the input
+    * is valid. 
+    * @param text is the text to be verified.
+    */
+    void enableDisableButtons(QString text);
+
+    /**
+    * Once all the line edits for a tab have been verified, the OK button is \
enabled. +    * If the tab is switched, the validity of OK should be recalculated for \
the new tab.  +    * @param text is the current active tab.
+    */
+    void checkInsertEnableValidity(int);
+
+private :
+    Ui::LinkInsertionDialog dlg;
+    KoTextEditor *m_editor;
+    const KoBookmarkManager *m_bookmarkManager;
+    QStringList m_bookmarkList;
+    QNetworkReply *m_reply;
+    QNetworkAccessManager *m_networkAccessManager;
+    QUrl m_linkURL;
+    QTimer m_timeoutTimer;
+    void accept();
+    void sendRequest();
+    void insertBookmarkLink(const QString &URL, const QString& text);
+    void insertHyperlink(QString &linkURL, const QString& linkText);
+    void displayInlineWarning(const QString &title, QLabel *label) const;
+    bool exists(const QString &) const;
+};
+#endif
diff --git a/plugins/textshape/dialogs/LinkInsertionDialog.ui \
b/plugins/textshape/dialogs/LinkInsertionDialog.ui new file mode 100755
index 0000000..e93a37a
--- /dev/null
+++ b/plugins/textshape/dialogs/LinkInsertionDialog.ui
@@ -0,0 +1,221 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>LinkInsertionDialog</class>
+ <widget class="QDialog" name="LinkInsertionDialog">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>567</width>
+    <height>241</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Link</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout_3">
+   <item>
+    <widget class="QTabWidget" name="linkTypesTab">
+     <property name="toolTip">
+      <string/>
+     </property>
+     <property name="currentIndex">
+      <number>0</number>
+     </property>
+     <property name="movable">
+      <bool>true</bool>
+     </property>
+     <widget class="QWidget" name="weblinkInsertionTab">
+      <attribute name="title">
+       <string>Web Link</string>
+      </attribute>
+      <attribute name="toolTip">
+       <string>Insert links to web documents. You can provide both URL and a label \
for the link, + or just enter the URL and hit &quot;Fetch the title from \
URL&quot;</string> +      </attribute>
+      <layout class="QVBoxLayout" name="verticalLayout">
+       <item>
+        <layout class="QGridLayout" name="gridLayout">
+         <item row="0" column="0">
+          <widget class="QLabel" name="label_2">
+           <property name="toolTip">
+            <string>The address of your document ( Uniform Resource \
Locator)</string> +           </property>
+           <property name="text">
+            <string> URL:</string>
+           </property>
+           <property name="alignment">
+            <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+           </property>
+          </widget>
+         </item>
+         <item row="0" column="1" colspan="2">
+          <widget class="QLineEdit" name="hyperlinkURL"/>
+         </item>
+         <item row="1" column="1">
+          <widget class="QPushButton" name="fetchTitleButton">
+           <property name="toolTip">
+            <string>Hit this button to get the title from the URL. Redirections are \
also handled. </string> +           </property>
+           <property name="text">
+            <string>Fetch Title From URL</string>
+           </property>
+          </widget>
+         </item>
+         <item row="1" column="2">
+          <spacer name="horizontalSpacer">
+           <property name="orientation">
+            <enum>Qt::Horizontal</enum>
+           </property>
+           <property name="sizeHint" stdset="0">
+            <size>
+             <width>168</width>
+             <height>20</height>
+            </size>
+           </property>
+          </spacer>
+         </item>
+         <item row="2" column="0">
+          <widget class="QLabel" name="label">
+           <property name="toolTip">
+            <string>The text that will be displayed for your link</string>
+           </property>
+           <property name="text">
+            <string> Text:</string>
+           </property>
+           <property name="alignment">
+            <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+           </property>
+          </widget>
+         </item>
+         <item row="2" column="1" colspan="2">
+          <widget class="QLineEdit" name="hyperlinkText"/>
+         </item>
+        </layout>
+       </item>
+       <item>
+        <widget class="QLabel" name="weblinkStatusLabel">
+         <property name="lineWidth">
+          <number>2</number>
+         </property>
+         <property name="text">
+          <string/>
+         </property>
+         <property name="wordWrap">
+          <bool>true</bool>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </widget>
+     <widget class="QWidget" name="bookmarkLinkInsertionTab">
+      <attribute name="title">
+       <string>Link To Bookmark</string>
+      </attribute>
+      <attribute name="toolTip">
+       <string>Insert links to Bookmarks. To create bookmarks,
+click &quot;Bookmarks&quot; in the Links and References section</string>
+      </attribute>
+      <widget class="QWidget" name="layoutWidget">
+       <property name="geometry">
+        <rect>
+         <x>5</x>
+         <y>5</y>
+         <width>531</width>
+         <height>78</height>
+        </rect>
+       </property>
+       <layout class="QGridLayout" name="gridLayout_2">
+        <item row="0" column="0">
+         <widget class="QLabel" name="label_5">
+          <property name="toolTip">
+           <string>The name of the bookmark to where the link has to point \
to</string> +          </property>
+          <property name="text">
+           <string> Name:</string>
+          </property>
+          <property name="alignment">
+           <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+          </property>
+         </widget>
+        </item>
+        <item row="0" column="1">
+         <widget class="QComboBox" name="bookmarkLinkURL">
+          <property name="editable">
+           <bool>true</bool>
+          </property>
+         </widget>
+        </item>
+        <item row="1" column="1">
+         <spacer name="verticalSpacer_2">
+          <property name="orientation">
+           <enum>Qt::Vertical</enum>
+          </property>
+          <property name="sizeHint" stdset="0">
+           <size>
+            <width>20</width>
+            <height>18</height>
+           </size>
+          </property>
+         </spacer>
+        </item>
+        <item row="2" column="0">
+         <widget class="QLabel" name="label_6">
+          <property name="toolTip">
+           <string>The text that will be displayed for your link</string>
+          </property>
+          <property name="text">
+           <string> Text:</string>
+          </property>
+          <property name="alignment">
+           <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
+          </property>
+         </widget>
+        </item>
+        <item row="2" column="1">
+         <widget class="QLineEdit" name="bookmarkLinkText"/>
+        </item>
+       </layout>
+      </widget>
+      <widget class="QLabel" name="bookmarkLinkStatusLabel">
+       <property name="geometry">
+        <rect>
+         <x>10</x>
+         <y>140</y>
+         <width>531</width>
+         <height>17</height>
+        </rect>
+       </property>
+       <property name="text">
+        <string/>
+       </property>
+      </widget>
+      <zorder>layoutWidget</zorder>
+      <zorder>buttonBox</zorder>
+      <zorder>bookmarkLinkStatusLabel</zorder>
+     </widget>
+    </widget>
+   </item>
+   <item>
+    <widget class="QDialogButtonBox" name="buttonBox">
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
+     </property>
+     <property name="standardButtons">
+      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <tabstops>
+  <tabstop>linkTypesTab</tabstop>
+  <tabstop>hyperlinkURL</tabstop>
+  <tabstop>fetchTitleButton</tabstop>
+  <tabstop>hyperlinkText</tabstop>
+  <tabstop>buttonBox</tabstop>
+  <tabstop>bookmarkLinkText</tabstop>
+ </tabstops>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/plugins/textshape/dialogs/ManageBookmark.ui \
b/plugins/textshape/dialogs/ManageBookmark.ui new file mode 100644
index 0000000..7927dc6
--- /dev/null
+++ b/plugins/textshape/dialogs/ManageBookmark.ui
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ManageBookmark</class>
+ <widget class="QWidget" name="ManageBookmark">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>332</width>
+    <height>219</height>
+   </rect>
+  </property>
+  <layout class="QGridLayout" name="gridLayout">
+   <item row="0" column="0" rowspan="5">
+    <widget class="QListWidget" name="bookmarkList"/>
+   </item>
+   <item row="0" column="1">
+    <widget class="QPushButton" name="buttonRename">
+     <property name="text">
+      <string>&amp;Rename</string>
+     </property>
+    </widget>
+   </item>
+   <item row="1" column="1">
+    <widget class="QPushButton" name="buttonDelete">
+     <property name="text">
+      <string>&amp;Delete</string>
+     </property>
+    </widget>
+   </item>
+   <item row="2" column="1">
+    <widget class="QPushButton" name="buttonInsert">
+     <property name="text">
+      <string>Insert</string>
+     </property>
+    </widget>
+   </item>
+   <item row="3" column="1">
+    <spacer name="verticalSpacer">
+     <property name="orientation">
+      <enum>Qt::Vertical</enum>
+     </property>
+     <property name="sizeHint" stdset="0">
+      <size>
+       <width>20</width>
+       <height>40</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/plugins/textshape/dialogs/ManageBookmarkDialog.cpp \
b/plugins/textshape/dialogs/ManageBookmarkDialog.cpp new file mode 100644
index 0000000..1060fb7
--- /dev/null
+++ b/plugins/textshape/dialogs/ManageBookmarkDialog.cpp
@@ -0,0 +1,177 @@
+/* This file is part of the KDE project
+ * Copyright (C) 2007-2008 Fredy Yanardi <fyanardi@gmail.com>
+ * Copyright (C) 2013 Aman Madaan <madaan.amanmadaan@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "ManageBookmarkDialog.h"
+
+#include <kmessagebox.h>
+#include <kinputdialog.h>
+
+static QString lastBookMarkItem;
+
+ManageBookmark::ManageBookmark(QList<QString> nameList, KoTextEditor *editor, \
QWidget *parent) +        : QWidget(parent),
+          m_editor(editor)
+{
+    widget.setupUi(this);
+    widget.bookmarkList->addItems(nameList);
+    widget.bookmarkList->setFocus(Qt::ActiveWindowFocusReason);
+    const int count = widget.bookmarkList->count();
+    if (count > 0) {
+        int row = 0;
+        if (! lastBookMarkItem.isNull()) {
+            QList<QListWidgetItem *> items = \
widget.bookmarkList->findItems(lastBookMarkItem, Qt::MatchExactly); +            if \
(items.count() > 0) +                row = widget.bookmarkList->row(items[0]);
+        }
+        widget.bookmarkList->setCurrentRow(row);
+    }
+
+    connect(widget.bookmarkList, SIGNAL(currentRowChanged(int)), this, \
SLOT(selectionChanged(int))); +    connect(widget.buttonRename, SIGNAL(clicked()), \
this, SLOT(slotBookmarkRename())); +    connect(widget.buttonDelete, \
SIGNAL(clicked()), this, SLOT(slotBookmarkDelete())); +    \
connect(widget.buttonInsert, SIGNAL(clicked()), this, SLOT(slotBookmarkInsert())); +  \
connect(widget.bookmarkList, SIGNAL(itemActivated(QListWidgetItem *)), +            \
this, SLOT(slotBookmarkItemActivated(QListWidgetItem *))); +    \
selectionChanged(bookmarkRow()); +}
+
+QString ManageBookmark::bookmarkName() const
+{
+    const QListWidgetItem *item = widget.bookmarkList->currentItem();
+    return item ? item->text() : QString();
+}
+
+int ManageBookmark::bookmarkRow() const
+{
+    return widget.bookmarkList->currentRow();
+}
+
+void ManageBookmark::selectionChanged(int currentRow)
+{
+    widget.buttonRename->setEnabled(currentRow != -1);
+    widget.buttonDelete->setEnabled(currentRow != -1);
+    emit bookmarkSelectionChanged(currentRow);
+}
+
+void ManageBookmark::slotBookmarkRename()
+{
+    bool ok = 0;
+    QListWidgetItem *item = widget.bookmarkList->currentItem();
+    Q_ASSERT(item);
+    QString curName = item->text();
+    QString newName = item->text();
+    while (true) {
+        newName = KInputDialog::getText(i18n("Rename Bookmark"),
+                                        i18n("Please provide a new name for the \
bookmark"), +                                        newName,
+                                        &ok,
+                                        parentWidget());
+        if (curName != newName  && ok) {
+            QList<QListWidgetItem *> items = widget.bookmarkList->findItems(newName, \
Qt::MatchExactly); +            if (items.count() > 0) {
+                KMessageBox::error(parentWidget(), i18n("A bookmark with the name \
\"%1\" already exists.", newName)); +                continue;
+            }
+            item->setText(newName);
+            emit bookmarkNameChanged(curName, newName);
+        }
+        break;
+    }
+}
+
+void ManageBookmark::slotBookmarkDelete()
+{
+    int currentRow = widget.bookmarkList->currentRow();
+    Q_ASSERT(currentRow >= 0);
+    QListWidgetItem *deletedItem = widget.bookmarkList->takeItem(currentRow);
+    QString deletedName = deletedItem->text();
+    emit bookmarkItemDeleted(deletedName);
+    delete deletedItem;
+}
+
+void ManageBookmark::slotBookmarkItemActivated(QListWidgetItem *item)
+{
+    Q_ASSERT(item);
+    lastBookMarkItem = item->text();
+    emit bookmarkItemDoubleClicked(item);
+}
+
+void ManageBookmark::slotBookmarkInsert()
+{
+    QString bookmarkName;
+    bool ok = 0;
+    while (true) {
+        bookmarkName = KInputDialog::getText(i18n("Insert Bookmark"),
+                                            i18n("Please provide a name for the \
bookmark"), +                                            bookmarkName,
+                                            &ok,
+                                            parentWidget());
+        if (ok) {
+            QList<QListWidgetItem *> items = \
widget.bookmarkList->findItems(bookmarkName, Qt::MatchExactly); +            if \
(items.count() > 0) { +                KMessageBox::error(parentWidget(), i18n("A \
bookmark with the name \"%1\" already exists.", bookmarkName)); +                \
continue; +            } else {
+                m_editor->addBookmark(bookmarkName);
+                widget.bookmarkList->insertItem(widget.bookmarkList->count(), \
bookmarkName); +            }
+        }
+        break;
+    }
+}
+
+ManageBookmarkDialog::ManageBookmarkDialog(QList<QString> nameList, KoTextEditor \
*editor, QWidget *parent) +        : KDialog(parent)
+{
+    ui = new ManageBookmark(nameList, editor, this);
+    setMainWidget(ui);
+    setCaption(i18n("Manage Bookmarks"));
+    setModal(true);
+    setButtons(Ok | Cancel);
+    setDefaultButton(Ok);
+    showButtonSeparator(true);
+    connect(ui, SIGNAL(bookmarkSelectionChanged(int)), this, \
SLOT(selectionChanged(int))); +    connect(ui, SIGNAL(bookmarkNameChanged(const \
QString &, const QString &)), +            this, SIGNAL(nameChanged(const QString &, \
const QString &))); +    connect(ui, SIGNAL(bookmarkItemDeleted(const QString &)),
+                this, SIGNAL(bookmarkDeleted(const QString &)));
+    connect(ui, SIGNAL(bookmarkItemDoubleClicked(QListWidgetItem *)),
+            this, SLOT(bookmarkDoubleClicked(QListWidgetItem *)));
+    selectionChanged(ui->bookmarkRow());
+}
+
+QString ManageBookmarkDialog::selectedBookmarkName()
+{
+    return ui->bookmarkName();
+}
+
+void ManageBookmarkDialog::selectionChanged(int currentRow)
+{
+    enableButtonOk(currentRow != -1);
+}
+
+void ManageBookmarkDialog::bookmarkDoubleClicked(QListWidgetItem *item)
+{
+    Q_UNUSED(item);
+    accept();
+}
+
+#include <ManageBookmarkDialog.moc>
+
diff --git a/plugins/textshape/dialogs/ManageBookmarkDialog.h \
b/plugins/textshape/dialogs/ManageBookmarkDialog.h new file mode 100644
index 0000000..9dc746c
--- /dev/null
+++ b/plugins/textshape/dialogs/ManageBookmarkDialog.h
@@ -0,0 +1,76 @@
+/* This file is part of the KDE project
+ * Copyright (C) 2007-2008 Fredy Yanardi <fyanardi@gmail.com>
+ * Copyright (C) 2013 Aman Madaan <madaan.amanmadaan@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef SELECTBOOKMARKDIALOG_H
+#define SELECTBOOKMARKDIALOG_H
+#include <KoTextEditor.h>
+#include <ui_SelectBookmark.h>
+
+#include <QWidget>
+#include <KDialog>
+
+class ManageBookmark : public QWidget
+{
+    Q_OBJECT
+public:
+    explicit ManageBookmark(QList<QString> nameList, KoTextEditor *editor, QWidget \
*parent = 0); +    QString bookmarkName() const;
+    int bookmarkRow() const;
+
+signals:
+    void bookmarkSelectionChanged(int currentRow);
+    void bookmarkNameChanged(const QString &oldName, const QString &newName);
+    void bookmarkItemDeleted(const QString &deletedName);
+    void bookmarkItemDoubleClicked(QListWidgetItem *item);
+
+private slots:
+    void selectionChanged(int currentRow);
+    void slotBookmarkRename();
+    void slotBookmarkDelete();
+    void slotBookmarkInsert();
+    void slotBookmarkItemActivated(QListWidgetItem *item);
+
+private:
+    Ui::SelectBookmark widget;
+    KoTextEditor *m_editor;
+};
+
+class ManageBookmarkDialog : public KDialog
+{
+    Q_OBJECT
+public:
+    explicit ManageBookmarkDialog(QList<QString> nameList, KoTextEditor *editor, \
QWidget *parent = 0); +    QString selectedBookmarkName();
+
+signals:
+    void nameChanged(const QString &oldName, const QString &newName);
+    void bookmarkDeleted(const QString &deletedName);
+
+private slots:
+    void selectionChanged(int currentRow);
+    void bookmarkDoubleClicked(QListWidgetItem *item);
+
+private:
+    ManageBookmark *ui;
+
+};
+
+#endif
+
diff --git a/plugins/textshape/dialogs/SelectBookmarkDialog.h \
b/plugins/textshape/dialogs/SelectBookmarkDialog.h new file mode 100644
index 0000000..e69de29
diff --git a/plugins/textshape/dialogs/SimpleLinksWidget.cpp \
b/plugins/textshape/dialogs/SimpleLinksWidget.cpp new file mode 100644
index 0000000..1e2c89c
--- /dev/null
+++ b/plugins/textshape/dialogs/SimpleLinksWidget.cpp
@@ -0,0 +1,104 @@
+/* This file is part of the KDE project
+ * Copyright (C) 2001 David Faure <faure@kde.org>
+ * Copyright (C) 2005-2007, 2009, 2010 Thomas Zander <zander@kde.org>
+ * Copyright (C) 2010-2011 Boudewijn Rempt <boud@kogmbh.com>
+ * Copyright (C) 2013 Aman Madaan <madaan.amanmadaan@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+#include <QWidget>
+#include "SimpleLinksWidget.h"
+#include "ReferencesTool.h"
+#include <KAction>
+#include <KoBookmarkManager.h>
+#include "ManageBookmarkDialog.h"
+#include <KoTextDocument.h>
+#include <KoBookmark.h>
+#include <KoTextRangeManager.h>
+#include <KoTextRange.h>
+
+SimpleLinksWidget::SimpleLinksWidget(ReferencesTool *tool, QWidget *parent)
+    : QWidget(parent)
+    , m_referenceTool(tool)
+{
+    widget.setupUi(this);
+    Q_ASSERT(tool);
+    widget.insertLink->setDefaultAction(tool->action("insert_link"));
+    widget.invokeBookmarkHandler->setDefaultAction(tool->action("invoke_bookmark_handler"));
 +    widget.invokeBookmarkHandler->setNumColumns(1);
+    connect(widget.insertLink, SIGNAL(clicked(bool)), this, \
SIGNAL(doneWithFocus())); +    connect(widget.invokeBookmarkHandler, \
SIGNAL(clicked(bool)), this, SIGNAL(doneWithFocus())); +    \
connect(widget.invokeBookmarkHandler, SIGNAL(aboutToShowMenu()), this, \
SLOT(preparePopUpMenu())); +}
+
+void SimpleLinksWidget::preparePopUpMenu()
+{
+    if (widget.invokeBookmarkHandler->isFirstTimeMenuShown()) {
+        widget.invokeBookmarkHandler->addAction(m_referenceTool->action("insert_bookmark"));
 +        widget.invokeBookmarkHandler->addSeparator();
+        widget.invokeBookmarkHandler->addAction(m_referenceTool->action("manage_bookmarks"));
 +        connect(m_referenceTool->action("manage_bookmarks"),
+                SIGNAL(triggered()), this, SLOT(manageBookmarks()), \
Qt::UniqueConnection); +    }
+}
+
+void SimpleLinksWidget::manageBookmarks()
+{
+    QString name;
+    const KoBookmarkManager *manager =  \
KoTextDocument(m_referenceTool->editor()->document()).textRangeManager()->bookmarkManager();
 +    QPointer<ManageBookmarkDialog> dia = new \
ManageBookmarkDialog(manager->bookmarkNameList(), m_referenceTool->editor(), \
m_referenceTool->canvas()->canvasWidget()); +    connect(dia, \
SIGNAL(nameChanged(const QString &, const QString &)), manager, SLOT(rename(const \
QString &, const QString &))); +    connect(dia, SIGNAL(bookmarkDeleted(const QString \
&)), manager, SLOT(remove(const QString &))); +    if (dia->exec() == \
QDialog::Accepted) { +        name = dia->selectedBookmarkName();
+    } else {
+        delete dia;
+        return;
+    }
+    delete dia;
+    KoBookmark *bookmark = manager->bookmark(name);
+#if 0
+    KoShape *shape = bookmark->shape();
+    KoSelection *selection = canvasBase()->shapeManager()->selection();
+    selection->deselectAll();
+    selection->select(shape);
+
+    QString tool = KoToolManager::instance()->preferredToolForSelection(selection->selectedShapes());
 +    KoToolManager::instance()->switchToolRequested(tool);
+#else
+#ifdef __GNUC__
+    #warning FIXME: port to textlayout-rework
+#endif
+#endif
+
+    KoCanvasResourceManager *rm = m_referenceTool->canvas()->resourceManager();
+    if ((bookmark->positionOnlyMode() == false) && bookmark->hasRange()) {
+        rm->clearResource(KoText::SelectedTextPosition);
+        rm->clearResource(KoText::SelectedTextAnchor);
+    }
+    if (bookmark->positionOnlyMode()) {
+        rm->setResource(KoText::CurrentTextPosition, bookmark->rangeStart());
+        rm->setResource(KoText::CurrentTextAnchor, bookmark->rangeStart());
+    } else {
+        rm->setResource(KoText::CurrentTextPosition, bookmark->rangeStart());
+        rm->setResource(KoText::CurrentTextAnchor, bookmark->rangeEnd());
+    }
+}
+
+SimpleLinksWidget::~SimpleLinksWidget()
+{
+
+}
\ No newline at end of file
diff --git a/plugins/textshape/dialogs/SimpleLinksWidget.h \
b/plugins/textshape/dialogs/SimpleLinksWidget.h new file mode 100644
index 0000000..9d81342
--- /dev/null
+++ b/plugins/textshape/dialogs/SimpleLinksWidget.h
@@ -0,0 +1,52 @@
+/* This file is part of the KDE project
+ * Copyright (C) 2001 David Faure <faure@kde.org>
+ * Copyright (C) 2005-2007, 2009, 2010 Thomas Zander <zander@kde.org>
+ * Copyright (C) 2010-2011 Boudewijn Rempt <boud@kogmbh.com>
+ * Copyright (C) 2013 Aman Madaan <madaan.amanmadaan@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+#ifndef SIMPLELINKSWIDGET_H
+#define SIMPLELINKSWIDGET_H
+
+#include  <ui_SimpleLinksWidget.h>
+#include "FormattingButton.h"
+#include <QWidget>
+#include <KoTextEditor.h>
+
+class ReferencesTool;
+
+class SimpleLinksWidget : public QWidget
+{
+    Q_OBJECT
+public:
+    SimpleLinksWidget(ReferencesTool *tool, QWidget *parent = 0);
+    virtual ~SimpleLinksWidget();
+
+signals:
+    void doneWithFocus();
+
+public slots:
+    void preparePopUpMenu();
+
+private slots:
+    void manageBookmarks();
+
+private:
+    Ui::SimpleLinksWidget widget;
+    ReferencesTool *m_referenceTool;
+};
+#endif
\ No newline at end of file
diff --git a/plugins/textshape/dialogs/SimpleLinksWidget.ui \
b/plugins/textshape/dialogs/SimpleLinksWidget.ui new file mode 100644
index 0000000..3fe4711
--- /dev/null
+++ b/plugins/textshape/dialogs/SimpleLinksWidget.ui
@@ -0,0 +1,90 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>SimpleLinksWidget</class>
+ <widget class="QWidget" name="SimpleLinksWidget">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>180</width>
+    <height>38</height>
+   </rect>
+  </property>
+  <property name="sizePolicy">
+   <sizepolicy hsizetype="Fixed" vsizetype="Minimum">
+    <horstretch>0</horstretch>
+    <verstretch>0</verstretch>
+   </sizepolicy>
+  </property>
+  <layout class="QGridLayout" name="gridLayout_2" columnstretch="0,0">
+   <property name="margin">
+    <number>0</number>
+   </property>
+   <property name="spacing">
+    <number>0</number>
+   </property>
+   <item row="0" column="0">
+    <layout class="QGridLayout" name="gridLayout">
+     <property name="spacing">
+      <number>2</number>
+     </property>
+     <item row="0" column="0">
+      <widget class="QToolButton" name="insertLink">
+       <property name="text">
+        <string>Hyperlinks</string>
+       </property>
+       <property name="autoRaise">
+        <bool>false</bool>
+       </property>
+      </widget>
+     </item>
+     <item row="0" column="1">
+      <widget class="FormattingButton" name="invokeBookmarkHandler">
+       <property name="text">
+        <string>Bookmarks</string>
+       </property>
+       <property name="popupMode">
+        <enum>QToolButton::InstantPopup</enum>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
+   <item row="0" column="1">
+    <spacer name="horizontalSpacer_2">
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
+     </property>
+     <property name="sizeType">
+      <enum>QSizePolicy::Preferred</enum>
+     </property>
+     <property name="sizeHint" stdset="0">
+      <size>
+       <width>0</width>
+       <height>20</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
+   <item row="1" column="0">
+    <widget class="QWidget" name="SpecialSpacer" native="true">
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Preferred" vsizetype="Expanding">
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
+     </property>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <customwidgets>
+  <customwidget>
+   <class>FormattingButton</class>
+   <extends>QToolButton</extends>
+   <header>dialogs/FormattingButton.h</header>
+  </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/plugins/textshape/dialogs/UnifiedLinkInsertionDialog.h \
b/plugins/textshape/dialogs/UnifiedLinkInsertionDialog.h new file mode 100644
index 0000000..e69de29


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic