On Sunday 08 November 2009 03:26:07 pm Kelvie Wong wrote:
> 2009/11/8 Brian Milco <[email protected]>:
> > Hi,
> >
> > This is my first submission to any open source project so please be
> > gentle. :)
> >
> > As a quick intro, I've been using Linux since 1998, KDE as my main
> > desktop since 2002, and Basket for the last 2 or 3 years to organize
> > some projects. I've been working with C++/Qt off and on for the last 7
> > months, however the bulk of my short programming experience is in VBA
> > for Access maintaining a database application for a small/medium size
> > business.
> >
> > I've attached a patch that allows you to type in
> > "basket://path/to/another+basket" and have it turned into a link that
> > can be clicked and opens "another basket". I'd like to add an
> > interface for selecting the linked basket, and to make the displayed
> > text be just the linked basket's name, or some other user defined
> > text.
> >
> > But before I do any more, I wanted to get some feedback and help. I'm
> > sure this patch has flaws which is why I'm looking for suggestions,
> > especially getting to know the Basket code base, KDE coding, or
> > anything else I'm doing wrong. :)
> >
> > Thanks for your time and help!
> > Brian =)
> 
> Rather than using "git diff" and sending it to me, could you make a
> commit using git (with a short message), and send the patch using the
> "git format-patch" command?
> 
> This is so I can attribute the patch directly to you without
> "tweaking" it myself.
> 
Ok, this should be what you're looking for.

Thanks for your time,
Brian
From e5687e5a01453c69545090f2bfd0d9b769adb55d Mon Sep 17 00:00:00 2001
From: Brian C. Milco <[email protected]>
Date: Sun, 8 Nov 2009 12:18:05 -0800
Subject: [PATCH] Added Basic Wiki Style Links

---
 src/basket.cpp         |    2 ++
 src/basket.h           |    2 ++
 src/basketlistview.cpp |   23 +++++++++++++++++++++++
 src/basketlistview.h   |    1 +
 src/bnpview.cpp        |   22 +++++++++++++++++++++-
 src/bnpview.h          |    2 ++
 src/note.cpp           |    3 ++-
 7 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/src/basket.cpp b/src/basket.cpp
index a1196fc..acc1981 100644
--- a/src/basket.cpp
+++ b/src/basket.cpp
@@ -2162,6 +2162,8 @@ void Basket::contentsMouseReleaseEvent(QMouseEvent *event)
             } else if (link == "basket-internal-import") {
                 KMenu *menu = Global::bnpView->popupMenu("fileimport");
                 menu->exec(event->globalPos());
+            } else if (link.startsWith("basket://")) {
+                emit basketLink(link);
             } else {
                 KRun *run = new KRun(KUrl(link), window()); //  open the URL.
                 run->setAutoDelete(true);
diff --git a/src/basket.h b/src/basket.h
index 8b5ccc7..ed67cc6 100644
--- a/src/basket.h
+++ b/src/basket.h
@@ -104,6 +104,8 @@ public:
     void clickedToInsert(QMouseEvent *event, Note *clicked = 0, int zone = 0);
 private slots:
     void setFocusIfNotInPopupMenu();
+signals:
+    void basketLink(QString link);
 
 /// LAYOUT:
 private:
diff --git a/src/basketlistview.cpp b/src/basketlistview.cpp
index 89de6ff..ad3dd63 100644
--- a/src/basketlistview.cpp
+++ b/src/basketlistview.cpp
@@ -522,3 +522,26 @@ Qt::DropActions BasketTreeListView::supportedDropActions() const
 {
     return Qt::MoveAction | Qt::CopyAction;
 }
+
+QTreeWidgetItem* BasketTreeListView::findBasket(QTreeWidgetItem *parent, QStringList pages)
+{
+    QTreeWidgetItem *found = 0;
+    QString page = pages.first();
+    pages.removeFirst();
+
+    for(int i = 0; i < parent->childCount(); i++) {
+        QTreeWidgetItem *child = parent->child(i);
+        if(child->text(0) == page) {
+            if(pages.count() > 0) {
+                found = this->findBasket(child, pages);
+                break;
+            } else {
+                found = child;
+                break;
+            }
+        } else
+            found = 0;
+    }
+
+    return found;
+}
diff --git a/src/basketlistview.h b/src/basketlistview.h
index 29bb5e4..b128efb 100644
--- a/src/basketlistview.h
+++ b/src/basketlistview.h
@@ -93,6 +93,7 @@ public:
     void resizeEvent(QResizeEvent *event);
     void contextMenuEvent(QContextMenuEvent *event);
     Qt::DropActions supportedDropActions() const;
+    QTreeWidgetItem* findBasket(QTreeWidgetItem *parent, QStringList pages);
 protected:
     bool event(QEvent *e);
     void focusInEvent(QFocusEvent*);
diff --git a/src/bnpview.cpp b/src/bnpview.cpp
index 39d2beb..c53f1d0 100644
--- a/src/bnpview.cpp
+++ b/src/bnpview.cpp
@@ -1081,7 +1081,7 @@ Basket* BNPView::loadBasket(const QString &folderName)
     connect(basket, SIGNAL(propertiesChanged(Basket*)), this, SLOT(updateBasketListViewItem(Basket*)));
 
     connect(basket->decoration()->filterBar(), SIGNAL(newFilter(const FilterData&)), this, SLOT(newFilterFromFilterBar()));
-
+    connect(basket, SIGNAL(basketLink(QString)), this, SLOT(loadBasketLink(QString)));
     return basket;
 }
 
@@ -2811,3 +2811,23 @@ void BNPView::disconnectTagsMenuDelayed()
     disconnect(m_lastOpenedTagsMenu, SIGNAL(aboutToHide()),  currentBasket(), SLOT(unlockHovering()));
     disconnect(m_lastOpenedTagsMenu, SIGNAL(aboutToHide()),  currentBasket(), SLOT(disableNextClick()));
 }
+
+void BNPView::loadBasketLink(QString link)
+{
+    QStringList pages;
+    //remove "basket://"
+    QString l = link.mid(9, link.length() - 9);
+    l = l.replace(QString("+"), QString(" "));
+
+    if(l.endsWith("/"))
+        l = l.mid(0, l.length() -1);
+    pages = l.split("/");
+
+    QTreeWidgetItem *item = m_tree->findBasket(m_tree->invisibleRootItem(), pages);
+
+    if(!item)
+        return;
+
+    Basket* basket = ((BasketListViewItem*)item)->basket();
+    this->setCurrentBasket(basket);
+}
diff --git a/src/bnpview.h b/src/bnpview.h
index e598592..e1259f5 100644
--- a/src/bnpview.h
+++ b/src/bnpview.h
@@ -203,6 +203,8 @@ public slots:
     void timeoutTryHide();
     void timeoutHide();
 
+    void loadBasketLink(QString link);
+
 public:
     static QString s_fileToOpen;
 
diff --git a/src/note.cpp b/src/note.cpp
index 3d60f74..d1edb91 100644
--- a/src/note.cpp
+++ b/src/note.cpp
@@ -656,7 +656,8 @@ Note::Zone Note::zoneAt(const QPoint &pos, bool toAdd)
 QString Note::linkAt(const QPoint &pos)
 {
     QString link = m_content->linkAt(pos - QPoint(contentX(), NOTE_MARGIN));
-    if (link.isEmpty())
+
+    if (link.isEmpty() || link.startsWith("basket://"))
         return link;
     else
         return NoteFactory::filteredURL(KUrl(link)).prettyUrl();//KURIFilter::self()->filteredURI(link);
-- 
1.6.0.4

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Basket-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/basket-devel

Reply via email to