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

List:       kfm-devel
Subject:    [patch] keditbookmarks listening to updates
From:       Alexander Kellett <kelletta () eidetica ! com>
Date:       2001-09-25 22:28:26
[Download RAW message or body]

Okay, this seems to work well enough here.  Though i'm certain it
needs more testing. Its just an extension of my previous patchs to
allow keditbookmarks to recieve bookmark file updates in a sane way.

David: i've changed kbookmarkmanager:findByAddress a fair bit to
be a bit more fault tolerant, it seemed like the correct place to
put it but i'm not certain?, whats your opinion on it?

mvg,
Alex
-- 
Eidetica                                           kelletta@eidetica.com
Kruislaan 400                               tel +31 20 888 4090 fax 4001
NL 1098 SM Amsterdam
http://www.eidetica.com/                               Alexander Kellett

vim: tw=70 cindent!

["keditbookmarks-bookmarkchanges.diff" (text/plain)]

Index: toplevel.cpp
===================================================================
RCS file: /home/kde/kdebase/konqueror/keditbookmarks/toplevel.cpp,v
retrieving revision 1.42
diff -u -3 -p -r1.42 toplevel.cpp
--- toplevel.cpp	2001/06/04 01:04:44	1.42
+++ toplevel.cpp	2001/09/25 21:33:42
@@ -17,6 +17,7 @@
 */
 
 #include "toplevel.h"
+#include "kbookmarklistener.h"
 #include "commands.h"
 #include <kaction.h>
 #include <kbookmarkdrag.h>
@@ -40,7 +41,7 @@
 #include <assert.h>
 #include <stdlib.h>
 
-//#define DEBUG_ADDRESSES
+#define DEBUG_ADDRESSES
 
 // toplevel item (there should be only one!)
 KEBListViewItem::KEBListViewItem(QListView *parent, const KBookmark & group )
@@ -112,7 +113,8 @@ QDragObject *KEBListView::dragObject() c
 KEBTopLevel * KEBTopLevel::s_topLevel = 0L;
 
 KEBTopLevel::KEBTopLevel( const QString & bookmarksFile )
-    : KMainWindow(), m_commandHistory( actionCollection() )
+    : KMainWindow(), m_commandHistory( actionCollection() ),
+      DCOPObject("KBookmarkListener")
 {
     // Create the bookmark manager.
     // It will be available in KBookmarkManager::self() from now.
@@ -150,7 +152,7 @@ KEBTopLevel::KEBTopLevel( const QString 
              SLOT(slotSelectionChanged() ) );
     connect( kapp->clipboard(), SIGNAL(dataChanged()),
              SLOT(slotClipboardDataChanged() ) );
-    // If someone plays with konq's bookmarks while we're open, update.
+    // If someone plays with konq's bookmarks while we're open, update. (when \
                applicable)
     connect( KBookmarkManager::self(), SIGNAL( changed(const QString &, const \
                QString &) ),
              SLOT( slotBookmarksChanged(const QString &, const QString &) ) );
     // Update GUI after executing command
@@ -374,6 +376,35 @@ void KEBTopLevel::slotNewFolder()
     }
 }
 
+QString KEBTopLevel::correctAddress(QString address) 
+{
+   if (address == "ERROR") address = "/32473827432"; // EVIL!!!
+   KBookmark bk = KBookmarkManager::self()->findByAddress(address);
+   kdWarning() << "correctAddress - " << address << bk.address() << endl;
+   return bk.address();
+}
+
+void KEBTopLevel::createNewFolder(QString text, QString address) // DCOP call
+{
+   //kdWarning() << "createNewFolder - " << text << "," << address << endl;
+   if (!m_bModified) return; // see comment below
+   address = correctAddress(address);
+   CreateCommand * cmd = new CreateCommand( i18n("Create Folder in Konqueror"), \
address, text, QString :: null, true ); +   m_commandHistory.addCommand( cmd );
+}
+
+void KEBTopLevel::addBookmark(QString url, QString text, QString address, QString \
icon) // DCOP call +{
+   //kdWarning() << "addBookmark - " << url << "," << text << "," << address << \
endl; +   if (!m_bModified) return;
+   /* needed as otherwise we get duplicates as updates are enabled for a
+    * non-modified document... maybe updates should only come through to
+    * keditbookmarks to remove this hack ...  */
+   address = correctAddress(address);
+   CreateCommand * cmd = new CreateCommand( i18n("Add Bookmark in Konqueror"), \
address, text, icon, KURL(url) ); +   m_commandHistory.addCommand( cmd );
+}
+
 void KEBTopLevel::slotNewBookmark()
 {
     if( !m_pListView->selectedItem() )
@@ -538,6 +569,7 @@ void KEBTopLevel::setModified( bool modi
     m_bModified = modified;
     setCaption( i18n("Bookmark Editor"), m_bModified );
     actionCollection()->action("file_save")->setEnabled( m_bModified );
+    KBookmarkManager::self()->setUpdate( !m_bModified ); // only update when \
non-modified  }
 
 void KEBTopLevel::slotDocumentRestored()
Index: toplevel.h
===================================================================
RCS file: /home/kde/kdebase/konqueror/keditbookmarks/toplevel.h,v
retrieving revision 1.16
diff -u -3 -p -r1.16 toplevel.h
--- toplevel.h	2001/06/04 01:04:44	1.16
+++ toplevel.h	2001/09/25 21:33:42
@@ -21,6 +21,7 @@
 
 #include <kmainwindow.h>
 #include <kbookmark.h>
+#include <kbookmarklistener.h>
 #include <qlistview.h>
 #include <klistview.h>
 #include <kcommand.h>
@@ -62,7 +63,7 @@ protected:
     virtual QDragObject *dragObject() const;
 };
 
-class KEBTopLevel : public KMainWindow
+class KEBTopLevel : public KMainWindow, virtual public KBookmarkListener
 {
     Q_OBJECT
 public:
@@ -71,6 +72,9 @@ public:
     KEBTopLevel( const QString & bookmarksFile );
     virtual ~KEBTopLevel();
 
+    void addBookmark( QString url, QString text, QString address, QString icon );
+    void createNewFolder( QString text, QString address );
+
     bool save();
 
     void setModified( bool modified = true );
@@ -132,6 +136,7 @@ protected:
     void fillListView();
     void pasteData( const QString & cmdName, QMimeSource * data, const QString & \
                insertionAddress );
     void itemMoved(QListViewItem * item, const QString & newAddress, bool copy);
+    QString correctAddress(QString address);
 
     bool m_bModified;
     bool m_bCanPaste;


["kbookmarklistener.h" (text/plain)]

/* This file is part of the KDE project
   Copyright (C) 2001 Alexander Kellett <kelletta@eidetica.com>

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This program 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
    General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; see the file COPYING.  If not, write to
   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.
*/

#ifndef __kbookmarklistener_h__
#define __kbookmarklistener_h__

#include <dcopobject.h>
#include <qvaluelist.h>
#include <dcopref.h>

/**
 * DCOP interface for a bookmark listener
 */
class KBookmarkListener : virtual public DCOPObject
{
  K_DCOP

k_dcop:
  virtual void addBookmark( QString url, QString text, QString address, QString \
icon/*, QString path*/ ) = 0;  virtual void createNewFolder( QString text, QString \
address/*, QString path*/ ) = 0;

};

#endif


["libkonq-bookmarkchanges.diff" (text/plain)]

? kbookmarklistener.h
Index: Makefile.am
===================================================================
RCS file: /home/kde/kdebase/libkonq/Makefile.am,v
retrieving revision 1.86
diff -u -3 -p -r1.86 Makefile.am
--- Makefile.am	2001/05/19 01:06:41	1.86
+++ Makefile.am	2001/09/25 21:32:48
@@ -26,7 +26,7 @@ libkonq_la_LIBADD = $(LIB_KPARTS)
 libkonq_la_SOURCES = konq_popupmenu.cc knewmenu.cc \
    kbookmarkmenu.cc kbookmark.cc kbookmarkbar.cc kbookmarkimporter.cc \
    kbookmarkexporter.cc kbookmarkmanager.cc kbookmarkmanager.skel \
-   kbookmarkdrag.cc \
+   kbookmarkdrag.cc kbookmarklistener.stub kbookmarklistener.skel \
    konq_dirlister.cc \
    kfileivi.cc konq_iconviewwidget.cc konq_imagepreviewjob.cc \
    konq_settings.cc konq_drag.cc  \
@@ -46,7 +46,7 @@ METASOURCES = AUTO
 
 include_HEADERS = konq_popupmenu.h knewmenu.h \
     kbookmark.h kbookmarkmenu.h kbookmarkbar.h kbookmarkimporter.h \
-    kbookmarkexporter.h kbookmarkmanager.h kbookmarkdrag.h \
+    kbookmarkexporter.h kbookmarkmanager.h kbookmarkdrag.h kbookmarklistener_stub.h \
     konq_dirlister.h konq_fileitem.h konq_mimetyperesolver.h \
     kfileivi.h konq_drag.h konq_iconviewwidget.h konq_imagepreviewjob.h \
     konq_defaults.h konq_settings.h \
Index: kbookmark.cc
===================================================================
RCS file: /home/kde/kdebase/libkonq/kbookmark.cc,v
retrieving revision 1.88
diff -u -3 -p -r1.88 kbookmark.cc
--- kbookmark.cc	2001/07/08 23:43:08	1.88
+++ kbookmark.cc	2001/09/25 21:32:48
@@ -17,6 +17,7 @@
 */
 
 #include "kbookmark.h"
+#include "kbookmarklistener_stub.h"
 #include <kdebug.h>
 #include <kglobal.h>
 #include <kmimetype.h>
@@ -28,6 +29,8 @@
 #include <qtextstream.h>
 #include <klocale.h>
 #include <assert.h>
+#include <kapp.h>
+#include <dcopclient.h>
 
 #include "konq_faviconmgr.h"
 
@@ -107,7 +110,18 @@ KBookmarkGroup KBookmarkGroup::createNew
     QDomElement textElem = doc.createElement( "title" );
     groupElem.appendChild( textElem );
     textElem.appendChild( doc.createTextNode( txt ) );
-    return KBookmarkGroup(groupElem);
+
+    KBookmarkGroup grp(groupElem);
+
+    if ( (strcmp(kapp->name(),"keditbookmarks") != 0)
+      && kapp->dcopClient()->isApplicationRegistered("keditbookmarks")) 
+    {
+       KBookmarkListener_stub listener("keditbookmarks","KBookmarkListener");
+       listener.createNewFolder( grp.fullText(), grp.address() );
+    }
+
+    return grp;
+
 }
 
 KBookmark KBookmarkGroup::createNewSeparator()
@@ -160,8 +174,17 @@ KBookmark KBookmarkGroup::addBookmark( c
     QDomElement textElem = doc.createElement( "title" );
     elem.appendChild( textElem );
     textElem.appendChild( doc.createTextNode( text ) );
+
+    KBookmark bk(elem);
+
+    if ( (strcmp(kapp->name(),"keditbookmarks") != 0)
+      && kapp->dcopClient()->isApplicationRegistered("keditbookmarks")) 
+    {
+       KBookmarkListener_stub listener("keditbookmarks","KBookmarkListener");
+       listener.addBookmark( url.url(), text, bk.address(), icon );
+    }
 
-    return KBookmark(elem);
+    return bk;
 }
 
 void KBookmarkGroup::deleteBookmark( KBookmark bk )
Index: kbookmark.h
===================================================================
RCS file: /home/kde/kdebase/libkonq/kbookmark.h,v
retrieving revision 1.37
diff -u -3 -p -r1.37 kbookmark.h
--- kbookmark.h	2000/12/15 17:23:25	1.37
+++ kbookmark.h	2001/09/25 21:32:48
@@ -183,7 +183,7 @@ public:
      * @param current has to be one of our child bookmarks.
      */
     KBookmark next( const KBookmark & current ) const;
-
+    
     /**
      * Create a new bookmark folder, as the last child of this group
      * @p text for the folder. If empty, the user will be queried for it.
Index: kbookmarkmanager.cc
===================================================================
RCS file: /home/kde/kdebase/libkonq/kbookmarkmanager.cc,v
retrieving revision 1.13
diff -u -3 -p -r1.13 kbookmarkmanager.cc
--- kbookmarkmanager.cc	2001/05/13 11:56:32	1.13
+++ kbookmarkmanager.cc	2001/09/25 21:32:48
@@ -50,6 +50,8 @@ KBookmarkManager::KBookmarkManager( cons
         delete s_pSelf;
     s_pSelf = this;
 
+    m_update = true;
+
     if (bookmarksFile.isEmpty())
         m_bookmarksFile = locateLocal("data", QString::fromLatin1("konqueror/bookmarks.xml"));
     else
@@ -74,6 +76,11 @@ KBookmarkManager::~KBookmarkManager()
     s_pSelf = 0L;
 }
 
+void KBookmarkManager::setUpdate(bool update)
+{
+    m_update = update;
+}
+
 void KBookmarkManager::parse()
 {
     //kdDebug(1203) << "KBookmarkManager::parse " << m_bookmarksFile << endl;
@@ -222,20 +229,32 @@ KBookmark KBookmarkManager::findByAddres
     KBookmark result = root();
     // The address is something like /5/10/2
     QStringList addresses = QStringList::split('/',address);
-    for ( QStringList::Iterator it = addresses.begin() ; it != addresses.end() ; ++it )
+    for ( QStringList::Iterator it = addresses.begin() ; it != addresses.end() ; )
     {
         uint number = (*it).toUInt();
         //kdDebug(1203) << "KBookmarkManager::findByAddress " << number << endl;
         ASSERT(result.isGroup());
         KBookmarkGroup group = result.toGroup();
-        KBookmark bk = group.first();
-        for ( uint i = 0 ; i < number ; ++i )
+        KBookmark bk = group.first(), lbk = bk;
+        for ( uint i = 0 ; i < number && !bk.isNull() ; ++i ) {
+            lbk = bk;
             bk = group.next(bk);
-        ASSERT(!bk.isNull());
+            kdWarning() << i << endl;
+        }
+        it++;
+        if ( bk.isNull() || ( !bk.isGroup() && (it != addresses.end()) ) ) {
+           if (!lbk.isNull()) 
+              result = lbk;
+           //kdWarning() << "break" << endl;
+           break;
+        }
+        //kdWarning() << "found section" << endl;
         result = bk;
     }
-    if (result.isNull())
+    if (result.isNull()) {
         kdWarning() << "KBookmarkManager::findByAddress: couldn't find item " << address << endl;
+    }
+    //kdWarning() << "found " << result.address() << endl;
     return result;
 }
 
@@ -254,8 +273,10 @@ void KBookmarkManager::emitChanged( KBoo
     //emit changed( group );
 }
 
-void KBookmarkManager::notifyCompleteChange( QString caller )
+void KBookmarkManager::notifyCompleteChange( QString caller ) // DCOP call
 {
+    if (!m_update) return;
+
     //kdDebug(1203) << "KBookmarkManager::notifyCompleteChange" << endl;
     // The bk editor tells us we should reload everything
     // Reparse
@@ -271,6 +292,8 @@ void KBookmarkManager::notifyCompleteCha
 
 void KBookmarkManager::notifyChanged( QString groupAddress ) // DCOP call
 {
+    if (!m_update) return;
+
     // Reparse (the whole file, no other choice)
     // Of course, if we are the emitter this is a bit stupid....
     parse();
Index: kbookmarkmanager.h
===================================================================
RCS file: /home/kde/kdebase/libkonq/kbookmarkmanager.h,v
retrieving revision 1.7
diff -u -3 -p -r1.7 kbookmarkmanager.h
--- kbookmarkmanager.h	2001/02/26 23:16:58	1.7
+++ kbookmarkmanager.h	2001/09/25 21:32:48
@@ -68,6 +68,13 @@ public:
 
     ~KBookmarkManager();
 
+
+    /**
+     * Set the update flag. 
+     * @param update iff true will KBookmarkManager listen to DCOP update requests.
+     */
+    void KBookmarkManager::setUpdate(bool update);
+
     /**
      * Save the bookmarks to the XML file on disk.
      * @return true if saving was successful
@@ -165,6 +172,7 @@ protected:
     void convertAttribute( QDomElement elem, const QString & oldName, const QString & newName );
     QString m_bookmarksFile;
     QDomDocument m_doc;
+    bool m_update;
     static KBookmarkManager* s_pSelf;
 };
 
Index: kbookmarkmenu.cc
===================================================================
RCS file: /home/kde/kdebase/libkonq/kbookmarkmenu.cc,v
retrieving revision 1.90
diff -u -3 -p -r1.90 kbookmarkmenu.cc
--- kbookmarkmenu.cc	2001/07/29 22:14:37	1.90
+++ kbookmarkmenu.cc	2001/09/25 21:32:48
@@ -46,6 +46,7 @@
 #include <kiconloader.h>
 #include <kio/job.h>
 #include <kglobal.h>
+#include <dcopclient.h>
 #include <klocale.h>
 #include <kmessagebox.h>
 #include <kurl.h>


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

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