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

List:       kde-devel
Subject:    Konqueror bookmark ipe patch - working now
From:       Oelewapperke <oelewapperke () ulyssis ! org>
Date:       2003-01-30 22:44:26
[Download RAW message or body]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

right click on the bookmark button's submenus works, presents options, and 
"open" "open in new tab" "open in new background tab" and "delete" work. Try 
it out. I'm looking for comments, suggestions etc.

For adding support for other places to access bookmarks, you have to overload 
MouseEvent, and send it to the KIPEBookmarkOwner.

Also : should I commit this ?

sorry for the multiple files though, the two new files (kipe*) go into 
kdelibs/kio/bookmarks/ 

Oelewapperke (who will be out of contact for about a week unfortunately)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE+OarKJFU6C5Uo8MgRApLdAKC1rtdKDiXwbHwLrfcgUzUh/QD/QACfZ8Ke
zqpxdC/0e6RleRcSHnkeafQ=
=+Ea+
-----END PGP SIGNATURE-----

["kipebookmarkbar.cc" (text/x-c++src)]

/* This file is part of the KDE project
   Copyright (C) 1999 Kurt Granroth <granroth@kde.org>
   Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>

   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., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.
*/
#include <qregexp.h>

#include <kaction.h>
#include <kbookmarkmenu.h>

#include <ktoolbar.h>

#include <kconfig.h>
#include <kpopupmenu.h>

#include <kipebookmarkbar.h>

KIPEBookmarkBar::KIPEBookmarkBar( KBookmarkManager* mgr,
                            KIPEBookmarkOwner *_owner, KToolBar *_toolBar,
                            KActionCollection *coll,
                            QObject *parent, const char *name )
    : QObject( parent, name ), m_pOwner(_owner), m_toolBar(_toolBar),
      m_actionCollection( coll ), m_pManager(mgr)
{
    m_lstSubMenus.setAutoDelete( true );

    connect( mgr, SIGNAL( changed(const QString &, const QString &) ),
             SLOT( slotBookmarksChanged(const QString &) ) );

    KBookmarkGroup toolbar = mgr->toolbar();
    fillBookmarkBar( toolbar );
}

KIPEBookmarkBar::~KIPEBookmarkBar()
{
    clear();
}

void KIPEBookmarkBar::clear()
{
    m_lstSubMenus.clear();

    if ( m_toolBar )
        m_toolBar->clear();
}

void KIPEBookmarkBar::slotBookmarksChanged( const QString & group )
{
    KBookmarkGroup tb = m_pManager->toolbar();
    if ( tb.isNull() )
        return;
    if ( tb.address() == group )
    {
        clear();

        fillBookmarkBar( tb );
    } else
    {
        // Iterate recursively into child menus
        QPtrListIterator<KBookmarkMenu> it( m_lstSubMenus );
        for (; it.current(); ++it )
        {
            it.current()->slotBookmarksChanged( group );
        }
    }

}

void KIPEBookmarkBar::fillBookmarkBar(KBookmarkGroup & parent)
{
  if (parent.isNull())
    return;

  for (KBookmark bm = parent.first(); !bm.isNull(); bm = parent.next(bm))
  {
    QString text = bm.text();
    text.replace( '&', "&&" );
    if ( bm.isSeparator() )
      m_toolBar->insertLineSeparator();
    else
    {
      m_toolBar->insertWidget( 0, 25, new KIPEToolBarButton( m_toolBar, bm, m_pOwner ) );
    }
  }
}

void KIPEBookmarkBar::slotBookmarkSelected()
{
    if (!m_pOwner) return; // this view doesn't handle bookmarks...

    m_pOwner->openBookmarkURL(QString::fromUtf8(sender()->name()));
}

#include "kipebookmarkbar.moc"

["patchforkdelibs_kio_bookmarks.patch" (text/x-diff)]

? .kbookmark.h.swp
Index: Makefile.am
===================================================================
RCS file: /home/kde/kdelibs/kio/bookmarks/Makefile.am,v
retrieving revision 1.1
diff -u -3 -p -b -r1.1 Makefile.am
--- Makefile.am	4 Mar 2002 13:40:28 -0000	1.1
+++ Makefile.am	30 Jan 2003 22:30:27 -0000
@@ -27,8 +27,9 @@ METASOURCES = AUTO
 
 include_HEADERS = \
 	kbookmark.h kbookmarkbar.h kbookmarkdrag.h kbookmarkexporter.h \
-	kbookmarkimporter.h kbookmarkmanager.h kbookmarkmenu.h kbookmarknotifier.h
+	kbookmarkimporter.h kbookmarkmanager.h kbookmarkmenu.h kbookmarknotifier.h \
+  kipebookmarkbar.h
 libkbookmarks_la_SOURCES = \
 	kbookmark.cc kbookmarkbar.cc kbookmarkdrag.cc kbookmarkexporter.cc \
 	kbookmarkimporter.cc kbookmarkmanager.cc kbookmarkmenu.cc \
-	kbookmarkmanager.skel kbookmarknotifier.skel 
+	kbookmarkmanager.skel kbookmarknotifier.skel kipebookmarkbar.cc
Index: kbookmarkmanager.h
===================================================================
RCS file: /home/kde/kdelibs/kio/bookmarks/kbookmarkmanager.h,v
retrieving revision 1.17
diff -u -3 -p -b -r1.17 kbookmarkmanager.h
--- kbookmarkmanager.h	30 Mar 2002 07:13:27 -0000	1.17
+++ kbookmarkmanager.h	30 Jan 2003 22:30:27 -0000
@@ -266,4 +266,29 @@ protected:
   virtual void virtual_hook( int id, void* data );
 };
 
+class KIPEBookmarkOwner : public KBookmarkOwner
+{
+public:
+  /**
+   * These functions are called when a mouse event occurs over a bookmark
+   * by default, they do nothing.
+   * If they return "true" that means the user has given some sort of command, and you
+   * think the popupmenu should be closed
+   */
+  virtual bool mousePressEvent ( KBookmark & b, QMouseEvent * e )
+  {
+    return true;
+  }
+  
+  virtual bool mouseReleaseEvent ( KBookmark & b, QMouseEvent * e )
+  {
+    return true;
+  }
+  
+  virtual bool mouseDoubleClickEvent ( KBookmark & b, QMouseEvent * e )
+  {
+    return true;
+  }
+};
+
 #endif

["kipebookmarkbar.h" (text/x-chdr)]

/* This file is part of the KDE project
   Copyright (C) 1999 Kurt Granroth <granroth@kde.org>

   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., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.
*/
#ifndef KIPEBOOKMARKBAR_H
#define KIPEBOOKMARKBAR_H

#include <qobject.h>
#include <qguardedptr.h>
#include <qptrlist.h>
#include <kbookmark.h>

#include <ktoolbar.h>
#include <qpopupmenu.h>
#include <kiconloader.h>
#include <ktoolbarbutton.h>
#include <qstyle.h>
#include <kbookmarkmanager.h>
class KBookmarkMenu;
class KIPEBookmarkOwner;
class KActionCollection;
class KAction;

/**
 * This class provides a bookmark toolbar.  Using this class is nearly
 * identical to using @ref KBookmarkMenu so follow the directions
 * there.
 */
class KIPEBookmarkBar : public QObject
{
    Q_OBJECT
public:
    /**
     * Is a bookmark toolbar
     */
    KIPEBookmarkBar( KBookmarkManager* mgr,
                  KIPEBookmarkOwner *owner, KToolBar *toolBar,
                  KActionCollection *,
                  QObject *parent = 0L, const char *name = 0L);

    virtual ~KIPEBookmarkBar();

public slots:
    void slotBookmarksChanged( const QString & );
    void slotBookmarkSelected();
    void clear();

protected:
    void fillBookmarkBar( KBookmarkGroup & parent );

private:
    KIPEBookmarkOwner    *m_pOwner;
    QGuardedPtr<KToolBar> m_toolBar;
    KActionCollection *m_actionCollection;
    KBookmarkManager *m_pManager;
    QPtrList<KBookmarkMenu> m_lstSubMenus;
};

class KIPEBookmarkPopup : public QPopupMenu 
{
  Q_OBJECT
  public:
    KIPEBookmarkPopup(QPoint start, KBookmarkGroup & bm, KIPEBookmarkOwner * owner) : \
QPopupMenu(), _owner(owner), _bm(bm)  {
      // kdDebug() << k_funcinfo << endl;

      insertItems();
      popup( start );
    }

    bool isCheckable()
    {
      return false;
    }

  private:
    KIPEBookmarkOwner * _owner;
    
    int selecteditem;
    KBookmarkGroup & _bm;

  protected:
    void insertItems()
    {
      clear();
      
      int i = 0;
      for (KBookmark bm = _bm.first(); !bm.isNull(); bm = _bm.next(bm))
      {
        QPixmap pm = KGlobal::iconLoader()->loadIcon( bm.icon() , KIcon::Toolbar);
        insertItem( pm, bm.text(), this, SLOT( doNothing() ), i++ );
      }
    }
    
    virtual void mousePressEvent( QMouseEvent * e )
    {
      int item = itemAtPos( e->pos() );
      KBookmark b(bookmarkFromItem(item));
      
      if (_owner->mousePressEvent(b, e)) close(false);
    }
    
//    virtual void mouseReleaseEvent( QMouseEvent * e )
//    {
//      int item = itemAtPos( e->pos() );
//      KBookmark b(bookmarkFromItem(item));
//      
//      if (_owner->mouseReleaseEvent(b, e)) close(true);
//    }

    virtual void mouseDoubleClickEvent( QMouseEvent * e )
    {
      int item = itemAtPos( e->pos() );
      KBookmark b(bookmarkFromItem(item));
      
      if (_owner->mouseDoubleClickEvent(b, e)) close(false);
    }

    KBookmark bookmarkFromItem(const int item)
    {
        KBookmark bm;
        int i = 0;
        for (bm = _bm.first(); !bm.isNull(); bm = _bm.next(bm))
        {
          if (i == item) break;
          i++;
        }
        assert(i == item);
        return bm;
    }

    public slots:
    
    void doNothing()
    {}
};

class KIPEToolBarButton : public KToolBarButton
{
  Q_OBJECT
  public:
    KIPEToolBarButton(QWidget* w, KBookmark bm, KIPEBookmarkOwner * owner)
      : KToolBarButton( bm.icon(), 0, w, NULL, bm.text()) ,_bm(bm), _owner(owner)
      {
        //kdDebug() << k_funcinfo << endl;
      }

  private:
    KBookmark _bm;
    KIPEBookmarkOwner * _owner;

  protected:
    void drawButton( QPainter *p)
    {
      KToolBarButton::drawButton(p);
      if (! _bm.isNull())
        if (_bm.isGroup())
        {
          QStyle::SFlags arrowFlags = QStyle::Style_Default;

          if (isDown())       arrowFlags |= QStyle::Style_Down;
          if (isEnabled())    arrowFlags |= QStyle::Style_Enabled;

          style().drawPrimitive(QStyle::PE_ArrowDown, p,
              QRect(width()-7, height()-7, 7, 7), colorGroup(),
              arrowFlags, QStyleOption() );
        }
    }

    virtual void mousePressEvent( QMouseEvent * me )
    {
      //kdDebug() << k_funcinfo << endl;

      if (me->button() == Qt::RightButton)
      {
        return;
      }

      if (me->button() == Qt::LeftButton && _bm.isGroup() )
      {
        new KIPEBookmarkPopup( QPoint( mapToGlobal( QPoint(0, height() ) ).x(), \
mapToGlobal( QPoint(0, height() ) ).y() ), (KBookmarkGroup&) _bm, _owner);  return;
      }

      KToolBarButton::mousePressEvent( me );
    }
};

#endif // KIPEBOOKMARKBAR_H


["patchfor_kdebase_konqueror.patch" (text/x-diff)]

? keditbookmarks/.toplevel.cpp.swp
? preloader/Makefile.in
Index: konq_mainwindow.cc
===================================================================
RCS file: /home/kde/kdebase/konqueror/konq_mainwindow.cc,v
retrieving revision 1.1083.2.6
diff -u -3 -p -b -r1.1083.2.6 konq_mainwindow.cc
--- konq_mainwindow.cc	14 Jan 2003 22:07:03 -0000	1.1083.2.6
+++ konq_mainwindow.cc	30 Jan 2003 22:29:42 -0000
@@ -61,7 +61,7 @@
 
 #include <dcopclient.h>
 #include <kaboutdata.h>
-#include <kbookmarkbar.h>
+#include <kipebookmarkbar.h>
 #include <kbookmarkmenu.h>
 #include <kdebug.h>
 #include <kedittoolbar.h>
@@ -90,6 +90,8 @@
 #include <kiconloader.h>
 #include <kpopupmenu.h>
 
+#include <kdebug.h>
+
 template class QPtrList<QPixmap>;
 template class QPtrList<KToggleAction>;
 
@@ -304,7 +306,7 @@ void KonqMainWindow::initBookmarkBar()
   if (!bar) return;
   if (m_paBookmarkBar) return;
 
-  m_paBookmarkBar = new KBookmarkBar( KonqBookmarkManager::self(), this, bar, \
m_bookmarkBarActionCollection, this ); +  m_paBookmarkBar = new KIPEBookmarkBar( \
KonqBookmarkManager::self(), this, bar, m_bookmarkBarActionCollection, this );  
   // hide if empty
   if (bar->count() == 0 )
@@ -4340,6 +4342,102 @@ bool KonqMainWindow::isMimeTypeAssociate
 
     KMessageBox::error( this, i18n("There appears to be a configuration error. You \
have associated Konqueror with %1, but it can't handle this file \
type.").arg(mimeType));  return true;
+}
+
+bool KonqMainWindow::mousePressEvent ( KBookmark & b, QMouseEvent * e )
+{
+    switch ( e->button() )
+    {
+        case LeftButton:
+            openBookmarkURL(QString::fromUtf8(b.url().url().utf8()));
+            break;
+        case RightButton:
+            showBookmarkContextMenu(b,e->globalPos());
+            break;
+        case MidButton:
+            KonqOpenURLRequest req;
+            req.newTab = true;
+            req.newTabInFront = true;
+            openURL( 0L, QString::fromUtf8(b.url().url().utf8()), QString::null, req \
); +            break;
+    }
+    return true; // true = close the menu
+}
+
+void KonqMainWindow::showBookmarkContextMenu(KBookmark & b, const QPoint & pos)
+{
+   static QPopupMenu * bookmarkpopup;
+
+   selectedbookmark = &b;
+
+   if ( ! bookmarkpopup )
+   {
+      bookmarkpopup = new QPopupMenu();
+
+      bookmarkpopup->insertItem("Open", this, SLOT( slotBookmarkPopupOpen() ));
+      bookmarkpopup->insertItem("Open In New Tab", this, SLOT( \
slotBookmarkPopupOpenInNewTab() )); +      bookmarkpopup->insertItem("Open In \
Background Tab", this, SLOT( slotBookmarkPopupOpenInBackgroundTab() )); +      \
bookmarkpopup->insertSeparator(); +      bookmarkpopup->insertItem("Rename", this, \
SLOT( slotBookmarkPopupRename() )); +      bookmarkpopup->insertItem("Change Url", \
this, SLOT( slotBookmarkPopupChangeUrl() )); +      bookmarkpopup->insertItem("Change \
Icon", this, SLOT( slotBookmarkPopupChangeIcon() )); +      \
bookmarkpopup->insertItem("Delete", this, SLOT( slotBookmarkPopupDelete() )); +      \
bookmarkpopup->insertSeparator(); +      bookmarkpopup->insertItem("Copy", this, \
SLOT( slotBookmarkPopupCopy() )); +   }
+
+   bookmarkpopup->exec(pos); // execute synchronously
+}
+
+void KonqMainWindow::slotBookmarkPopupOpen()
+{
+    openURL( 0L, QString::fromUtf8(selectedbookmark->url().url().utf8()) );
+}
+          
+void KonqMainWindow::slotBookmarkPopupOpenInNewTab()
+{
+    KonqOpenURLRequest req;
+    req.newTab = true;
+    req.newTabInFront = true;
+    openURL( 0L, QString::fromUtf8(selectedbookmark->url().url().utf8()), \
QString::null, req ); +}
+          
+void KonqMainWindow::slotBookmarkPopupOpenInBackgroundTab()
+{
+    KonqOpenURLRequest req;
+    req.newTab = true;
+    req.newTabInFront = false;
+    openURL( 0L, QString::fromUtf8(selectedbookmark->url().url().utf8()), \
QString::null, req ); +}
+          
+void KonqMainWindow::slotBookmarkPopupRename()
+{
+    bool really = false;
+    KLineEditDlg::getText( "Rename to", selectedbookmark->fulltext(), &really, 0);
+    if (really)
+        selectedbookmark->
+    kdDebug() << k_funcinfo << endl;
+}
+
+void KonqMainWindow::slotBookmarkPopupChangeUrl()
+{
+    kdDebug() << k_funcinfo << endl;
+}
+
+void KonqMainWindow::slotBookmarkPopupChangeIcon()
+{
+    kdDebug() << k_funcinfo << endl;
+}
+
+void KonqMainWindow::slotBookmarkPopupCopy()
+{
+    kdDebug() << k_funcinfo << endl;
+}
+          
+void KonqMainWindow::slotBookmarkPopupDelete()
+{
+    selectedbookmark->parentGroup().deleteBookmark(*selectedbookmark);
+    kdDebug() << "Saving : " << KonqBookmarkManager::self()->save() << endl;
 }
 
 // KonqFrameContainerBase implementation END
Index: konq_mainwindow.h
===================================================================
RCS file: /home/kde/kdebase/konqueror/konq_mainwindow.h,v
retrieving revision 1.374
diff -u -3 -p -b -r1.374 konq_mainwindow.h
--- konq_mainwindow.h	8 Nov 2002 10:41:46 -0000	1.374
+++ konq_mainwindow.h	30 Jan 2003 22:29:42 -0000
@@ -40,6 +40,9 @@
 #include "konq_combo.h"
 #include "konq_frame.h"
 
+//FIXME only for debugging ...
+#include <kdebug.h>
+
 class QFile;
 class KAction;
 class KActionCollection;
@@ -51,7 +54,7 @@ class KProgress;
 class KSelectAction;
 class KToggleAction;
 class KonqBidiHistoryAction;
-class KBookmarkBar;
+class KIPEBookmarkBar;
 class KonqView;
 class KonqComboAction;
 class KonqFrame;
@@ -82,7 +85,7 @@ namespace KParts {
 
 
 class KonqMainWindow : public KParts::MainWindow,
-		       virtual public KBookmarkOwner,
+		       virtual public KIPEBookmarkOwner,
 		       public KonqFrameContainerBase
 {
   Q_OBJECT
@@ -437,6 +440,10 @@ protected slots:
   void slotIconsChanged();
 
 protected:
+
+  // KIPEBookmarkOwner implementation
+  virtual bool mousePressEvent ( KBookmark & b, QMouseEvent * e );
+  
   static QString detectNameFilter( QString & url );
 
   virtual bool eventFilter(QObject*obj,QEvent *ev);
@@ -472,6 +479,20 @@ private slots:
   void initBookmarkBar();
 
 private:
+  KBookmark * selectedbookmark;
+  void showBookmarkContextMenu(KBookmark&, const QPoint&);
+
+public slots:
+  void slotBookmarkPopupOpen();
+  void slotBookmarkPopupOpenInNewTab();
+  void slotBookmarkPopupOpenInBackgroundTab();
+  void slotBookmarkPopupRename();
+  void slotBookmarkPopupChangeUrl();
+  void slotBookmarkPopupChangeIcon();
+  void slotBookmarkPopupDelete();
+  void slotBookmarkPopupCopy();
+
+private:
   /**
    * takes care of hiding the bookmarkbar and calling setChecked( false ) on the
    * corresponding action
@@ -570,7 +591,7 @@ private:
 
   KonqLogoAction *m_paAnimatedLogo;
 
-  KBookmarkBar *m_paBookmarkBar;
+  KIPEBookmarkBar *m_paBookmarkBar;
 
   KAction * m_paFindFiles;
   KToggleAction *m_ptaUseHTML;


>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<

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

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