summaryrefslogtreecommitdiffstats
path: root/tdeio/bookmarks
diff options
context:
space:
mode:
Diffstat (limited to 'tdeio/bookmarks')
-rw-r--r--tdeio/bookmarks/CMakeLists.txt55
-rw-r--r--tdeio/bookmarks/Makefile.am40
-rw-r--r--tdeio/bookmarks/dptrtemplate.h57
-rw-r--r--tdeio/bookmarks/kbookmark.cc535
-rw-r--r--tdeio/bookmarks/kbookmark.h329
-rw-r--r--tdeio/bookmarks/kbookmarkbar.cc554
-rw-r--r--tdeio/bookmarks/kbookmarkbar.h131
-rw-r--r--tdeio/bookmarks/kbookmarkdombuilder.cc81
-rw-r--r--tdeio/bookmarks/kbookmarkdombuilder.h48
-rw-r--r--tdeio/bookmarks/kbookmarkdrag.cc169
-rw-r--r--tdeio/bookmarks/kbookmarkdrag.h57
-rw-r--r--tdeio/bookmarks/kbookmarkexporter.cc32
-rw-r--r--tdeio/bookmarks/kbookmarkexporter.h50
-rw-r--r--tdeio/bookmarks/kbookmarkimporter.cc101
-rw-r--r--tdeio/bookmarks/kbookmarkimporter.h106
-rw-r--r--tdeio/bookmarks/kbookmarkimporter_crash.cc215
-rw-r--r--tdeio/bookmarks/kbookmarkimporter_crash.h74
-rw-r--r--tdeio/bookmarks/kbookmarkimporter_ie.cc185
-rw-r--r--tdeio/bookmarks/kbookmarkimporter_ie.h90
-rw-r--r--tdeio/bookmarks/kbookmarkimporter_kde1.cc156
-rw-r--r--tdeio/bookmarks/kbookmarkimporter_kde1.h49
-rw-r--r--tdeio/bookmarks/kbookmarkimporter_ns.cc243
-rw-r--r--tdeio/bookmarks/kbookmarkimporter_ns.h132
-rw-r--r--tdeio/bookmarks/kbookmarkimporter_opera.cc170
-rw-r--r--tdeio/bookmarks/kbookmarkimporter_opera.h86
-rw-r--r--tdeio/bookmarks/kbookmarkmanager.cc727
-rw-r--r--tdeio/bookmarks/kbookmarkmanager.h367
-rw-r--r--tdeio/bookmarks/kbookmarkmenu.cc1187
-rw-r--r--tdeio/bookmarks/kbookmarkmenu.h265
-rw-r--r--tdeio/bookmarks/kbookmarkmenu_p.h224
-rw-r--r--tdeio/bookmarks/kbookmarknotifier.h45
31 files changed, 6560 insertions, 0 deletions
diff --git a/tdeio/bookmarks/CMakeLists.txt b/tdeio/bookmarks/CMakeLists.txt
new file mode 100644
index 000000000..93121cbac
--- /dev/null
+++ b/tdeio/bookmarks/CMakeLists.txt
@@ -0,0 +1,55 @@
+#################################################
+#
+# (C) 2010 Serghei Amelian
+# serghei (DOT) amelian (AT) gmail.com
+#
+# Improvements and feedback are welcome
+#
+# This file is released under GPL >= 2
+#
+#################################################
+
+include_directories(
+ ${TQT_INCLUDE_DIRS}
+ ${CMAKE_CURRENT_BINARY_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${CMAKE_BINARY_DIR}/tdecore
+ ${CMAKE_SOURCE_DIR}/dcop
+ ${CMAKE_SOURCE_DIR}/tdefx
+ ${CMAKE_SOURCE_DIR}/tdecore
+ ${CMAKE_SOURCE_DIR}/tdeui
+ ${CMAKE_SOURCE_DIR}/tdeio
+ ${CMAKE_SOURCE_DIR}/tdeio/tdeio
+ ${CMAKE_SOURCE_DIR}/tdeio/tdefile
+)
+
+
+##### headers ###################################
+
+install( FILES
+ kbookmark.h kbookmarkbar.h kbookmarkdrag.h kbookmarkexporter.h
+ kbookmarkimporter.h kbookmarkmanager.h kbookmarkmenu.h
+ kbookmarknotifier.h kbookmarkimporter_crash.h
+ kbookmarkimporter_opera.h kbookmarkimporter_ie.h
+ kbookmarkimporter_ns.h kbookmarkimporter_kde1.h
+ kbookmarkdombuilder.h
+ DESTINATION ${INCLUDE_INSTALL_DIR} )
+
+
+##### kbookmarks ################################
+
+set( target kbookmarks )
+
+set( ${target}_SRCS
+ kbookmark.cc kbookmarkbar.cc kbookmarkdrag.cc kbookmarkexporter.cc
+ kbookmarkimporter.cc kbookmarkmanager.cc kbookmarkmenu.cc
+ kbookmarkimporter_crash.cc kbookmarkimporter_opera.cc
+ kbookmarkimporter_ie.cc kbookmarkimporter_ns.cc
+ kbookmarkimporter_kde1.cc kbookmarkdombuilder.cc
+ kbookmarkmanager.skel kbookmarknotifier.skel
+)
+
+tde_add_library( ${target} STATIC_PIC AUTOMOC
+ SOURCES ${${target}_SRCS}
+ DEPENDENCIES dcopidl
+)
diff --git a/tdeio/bookmarks/Makefile.am b/tdeio/bookmarks/Makefile.am
new file mode 100644
index 000000000..e1ec3a8df
--- /dev/null
+++ b/tdeio/bookmarks/Makefile.am
@@ -0,0 +1,40 @@
+# This file is part of the KDE libraries
+# Copyright (C) 1997 Stephan Kulow (coolo@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 General Public License
+# along with this library; see the file COPYING. If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+
+
+INCLUDES= -I$(srcdir)/../libltdl/ -I$(top_srcdir) -I$(top_srcdir)/tdefx -I$(top_builddir)/tdeio/tdeio $(all_includes)
+
+noinst_LTLIBRARIES = libkbookmarks.la
+
+METASOURCES = AUTO
+
+# convenience lib - no _LDFLAGS or _LIBADD !
+
+include_HEADERS = \
+ kbookmark.h kbookmarkbar.h kbookmarkdrag.h kbookmarkexporter.h \
+ kbookmarkimporter.h kbookmarkmanager.h kbookmarkmenu.h kbookmarknotifier.h \
+ kbookmarkimporter_crash.h kbookmarkimporter_opera.h kbookmarkimporter_ie.h \
+ kbookmarkimporter_ns.h kbookmarkimporter_kde1.h kbookmarkdombuilder.h
+libkbookmarks_la_SOURCES = \
+ kbookmark.cc kbookmarkbar.cc kbookmarkdrag.cc kbookmarkexporter.cc \
+ kbookmarkimporter.cc kbookmarkmanager.cc kbookmarkmenu.cc \
+ kbookmarkimporter_crash.cc kbookmarkimporter_opera.cc kbookmarkimporter_ie.cc \
+ kbookmarkimporter_ns.cc kbookmarkimporter_kde1.cc kbookmarkdombuilder.cc \
+ kbookmarkmanager.skel kbookmarknotifier.skel
+
+include $(top_srcdir)/admin/Doxyfile.am
diff --git a/tdeio/bookmarks/dptrtemplate.h b/tdeio/bookmarks/dptrtemplate.h
new file mode 100644
index 000000000..dbc059e7e
--- /dev/null
+++ b/tdeio/bookmarks/dptrtemplate.h
@@ -0,0 +1,57 @@
+// -*- c-basic-offset:4; indent-tabs-mode:nil -*-
+// vim: set ts=4 sts=4 sw=4 et:
+/* This file is part of the KDE project
+ Copyright (C) 2003 Alexander Kellett <lypanov@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., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef __dptrtemplate_h__
+#define __dptrtemplate_h__
+
+#include <tqptrdict.h>
+
+template<class Instance, class PrivateData>
+class dPtrTemplate {
+public:
+ static PrivateData* d( const Instance* instance )
+ {
+ if ( !d_ptr ) {
+ cleanup_d_ptr();
+ d_ptr = new TQPtrDict<PrivateData>;
+ tqAddPostRoutine( cleanup_d_ptr );
+ }
+ PrivateData* ret = d_ptr->find( (void*) instance );
+ if ( ! ret ) {
+ ret = new PrivateData;
+ d_ptr->replace( (void*) instance, ret );
+ }
+ return ret;
+ }
+ static void delete_d( const Instance* instance )
+ {
+ if ( d_ptr )
+ d_ptr->remove( (void*) instance );
+ }
+private:
+ static void cleanup_d_ptr()
+ {
+ delete d_ptr;
+ }
+ static TQPtrDict<PrivateData>* d_ptr;
+};
+
+#endif
diff --git a/tdeio/bookmarks/kbookmark.cc b/tdeio/bookmarks/kbookmark.cc
new file mode 100644
index 000000000..ab1cc398a
--- /dev/null
+++ b/tdeio/bookmarks/kbookmark.cc
@@ -0,0 +1,535 @@
+// -*- c-basic-offset:4; indent-tabs-mode:nil -*-
+// vim: set ts=4 sts=4 sw=4 et:
+/* This file is part of the KDE libraries
+ Copyright (C) 2000 David Faure <faure@kde.org>
+ Copyright (C) 2003 Alexander Kellett <lypanov@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 version 2 as published by the Free Software Foundation.
+
+ 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 "kbookmark.h"
+#include <tqvaluestack.h>
+#include <kdebug.h>
+#include <kmimetype.h>
+#include <kstringhandler.h>
+#include <kinputdialog.h>
+#include <kglobal.h>
+#include <klocale.h>
+#include <assert.h>
+#include <kapplication.h>
+#include <dcopclient.h>
+#include <kbookmarkmanager.h>
+
+KBookmarkGroup::KBookmarkGroup()
+ : KBookmark( TQDomElement() )
+{
+}
+
+KBookmarkGroup::KBookmarkGroup( TQDomElement elem )
+ : KBookmark(elem)
+{
+}
+
+TQString KBookmarkGroup::groupAddress() const
+{
+ if (m_address.isEmpty())
+ m_address = address();
+ return m_address;
+}
+
+bool KBookmarkGroup::isOpen() const
+{
+ return element.attribute("folded") == "no"; // default is: folded
+}
+
+// Returns first element node equal to or after node n
+static TQDomElement firstElement(TQDomNode n)
+{
+ while(!n.isNull() && !n.isElement())
+ n = n.nextSibling();
+ return n.toElement();
+}
+
+// Returns first element node equal to or before node n
+static TQDomElement lastElement(TQDomNode n)
+{
+ while(!n.isNull() && !n.isElement())
+ n = n.previousSibling();
+ return n.toElement();
+}
+
+KBookmark KBookmarkGroup::first() const
+{
+ return KBookmark( nextKnownTag( firstElement(element.firstChild()), true ) );
+}
+
+KBookmark KBookmarkGroup::previous( const KBookmark & current ) const
+{
+ return KBookmark( nextKnownTag( lastElement(current.element.previousSibling()), false ) );
+}
+
+KBookmark KBookmarkGroup::next( const KBookmark & current ) const
+{
+ return KBookmark( nextKnownTag( firstElement(current.element.nextSibling()), true ) );
+}
+
+// KDE4: Change TQDomElement to TQDomNode so that we can get rid of
+// firstElement() and lastElement()
+TQDomElement KBookmarkGroup::nextKnownTag( TQDomElement start, bool goNext ) const
+{
+ static const TQString & bookmark = TDEGlobal::staticQString("bookmark");
+ static const TQString & folder = TDEGlobal::staticQString("folder");
+ static const TQString & separator = TDEGlobal::staticQString("separator");
+
+ for( TQDomNode n = start; !n.isNull(); )
+ {
+ TQDomElement elem = n.toElement();
+ TQString tag = elem.tagName();
+ if (tag == folder || tag == bookmark || tag == separator)
+ return elem;
+ if (goNext)
+ n = n.nextSibling();
+ else
+ n = n.previousSibling();
+ }
+ return TQDomElement();
+}
+
+KBookmarkGroup KBookmarkGroup::createNewFolder( KBookmarkManager* mgr, const TQString & text, bool emitSignal )
+{
+ TQString txt( text );
+ if ( text.isEmpty() )
+ {
+ bool ok;
+ TQString caption = parentGroup().fullText().isEmpty() ?
+ i18n( "Create New Bookmark Folder" ) :
+ i18n( "Create New Bookmark Folder in %1" )
+ .arg( parentGroup().text() );
+ txt = KInputDialog::getText( caption, i18n( "New folder:" ),
+ TQString::null, &ok );
+ if ( !ok )
+ return KBookmarkGroup();
+ }
+
+ Q_ASSERT(!element.isNull());
+ TQDomDocument doc = element.ownerDocument();
+ TQDomElement groupElem = doc.createElement( "folder" );
+ element.appendChild( groupElem );
+ TQDomElement textElem = doc.createElement( "title" );
+ groupElem.appendChild( textElem );
+ textElem.appendChild( doc.createTextNode( txt ) );
+
+ KBookmarkGroup grp(groupElem);
+
+ if (emitSignal)
+ emit mgr->notifier().createdNewFolder(
+ mgr->path(), grp.fullText(),
+ grp.address() );
+
+ return grp;
+
+}
+
+KBookmark KBookmarkGroup::createNewSeparator()
+{
+ Q_ASSERT(!element.isNull());
+ TQDomDocument doc = element.ownerDocument();
+ Q_ASSERT(!doc.isNull());
+ TQDomElement sepElem = doc.createElement( "separator" );
+ element.appendChild( sepElem );
+ return KBookmark(sepElem);
+}
+
+bool KBookmarkGroup::moveItem( const KBookmark & item, const KBookmark & after )
+{
+ TQDomNode n;
+ if ( !after.isNull() )
+ n = element.insertAfter( item.element, after.element );
+ else // first child
+ {
+ if ( element.firstChild().isNull() ) // Empty element -> set as real first child
+ n = element.insertBefore( item.element, TQDomElement() );
+
+ // we have to skip everything up to the first valid child
+ TQDomElement firstChild = nextKnownTag(element.firstChild().toElement(), true);
+ if ( !firstChild.isNull() )
+ n = element.insertBefore( item.element, firstChild );
+ else
+ {
+ // No real first child -> append after the <title> etc.
+ n = element.appendChild( item.element );
+ }
+ }
+ return (!n.isNull());
+}
+
+KBookmark KBookmarkGroup::addBookmark( KBookmarkManager* mgr, const KBookmark &bm, bool emitSignal )
+{
+ element.appendChild( bm.internalElement() );
+
+ if (emitSignal) {
+ if ( bm.hasMetaData() ) {
+ mgr->notifyCompleteChange( "" );
+ } else {
+ emit mgr->notifier().addedBookmark(
+ mgr->path(), bm.url().url(),
+ bm.fullText(), bm.address(), bm.icon() );
+ }
+ }
+
+ return bm;
+}
+
+KBookmark KBookmarkGroup::addBookmark( KBookmarkManager* mgr, const TQString & text, const KURL & url, const TQString & icon, bool emitSignal )
+{
+ //kdDebug(7043) << "KBookmarkGroup::addBookmark " << text << " into " << m_address << endl;
+ TQDomDocument doc = element.ownerDocument();
+ TQDomElement elem = doc.createElement( "bookmark" );
+ elem.setAttribute( "href", url.url( 0, 106 ) ); // write utf8 URL (106 is mib enum for utf8)
+ TQString _icon = icon;
+ if ( _icon.isEmpty() )
+ _icon = KMimeType::iconForURL( url );
+ elem.setAttribute( "icon", _icon );
+
+ TQDomElement textElem = doc.createElement( "title" );
+ elem.appendChild( textElem );
+ textElem.appendChild( doc.createTextNode( text ) );
+
+ return addBookmark( mgr, KBookmark( elem ), emitSignal );
+}
+
+void KBookmarkGroup::deleteBookmark( KBookmark bk )
+{
+ element.removeChild( bk.element );
+}
+
+bool KBookmarkGroup::isToolbarGroup() const
+{
+ return ( element.attribute("toolbar") == "yes" );
+}
+
+TQDomElement KBookmarkGroup::findToolbar() const
+{
+ if ( element.attribute("toolbar") == "yes" )
+ return element;
+ for (TQDomNode n = element.firstChild(); !n.isNull() ; n = n.nextSibling() )
+ {
+ TQDomElement e = n.toElement();
+ // Search among the "folder" children only
+ if ( e.tagName() == "folder" )
+ {
+ if ( e.attribute("toolbar") == "yes" )
+ return e;
+ else
+ {
+ TQDomElement result = KBookmarkGroup(e).findToolbar();
+ if (!result.isNull())
+ return result;
+ }
+ }
+ }
+ return TQDomElement();
+}
+
+TQValueList<KURL> KBookmarkGroup::groupUrlList() const
+{
+ TQValueList<KURL> urlList;
+ for ( KBookmark bm = first(); !bm.isNull(); bm = next(bm) )
+ {
+ if ( bm.isSeparator() || bm.isGroup() )
+ continue;
+ urlList << bm.url();
+ }
+ return urlList;
+}
+
+//////
+
+bool KBookmark::isGroup() const
+{
+ TQString tag = element.tagName();
+ return ( tag == "folder"
+ || tag == "xbel" ); // don't forget the toplevel group
+}
+
+bool KBookmark::isSeparator() const
+{
+ return (element.tagName() == "separator");
+}
+
+bool KBookmark::hasParent() const
+{
+ TQDomElement parent = element.parentNode().toElement();
+ return !parent.isNull();
+}
+
+TQString KBookmark::text() const
+{
+ return KStringHandler::csqueeze( fullText() );
+}
+
+TQString KBookmark::fullText() const
+{
+ if (isSeparator())
+ return i18n("--- separator ---");
+
+ return element.namedItem("title").toElement().text();
+}
+
+KURL KBookmark::url() const
+{
+ return KURL(element.attribute("href"), 106); // Decode it from utf8 (106 is mib enum for utf8)
+}
+
+TQString KBookmark::icon() const
+{
+ TQString icon = element.attribute("icon");
+ if ( icon.isEmpty() )
+ // Default icon depends on URL for bookmarks, and is default directory
+ // icon for groups.
+ if ( isGroup() )
+ icon = "bookmark_folder";
+ else
+ if ( isSeparator() )
+ icon = "eraser"; // whatever
+ else
+ icon = KMimeType::iconForURL( url() );
+ return icon;
+}
+
+KBookmarkGroup KBookmark::parentGroup() const
+{
+ return KBookmarkGroup( element.parentNode().toElement() );
+}
+
+KBookmarkGroup KBookmark::toGroup() const
+{
+ Q_ASSERT( isGroup() );
+ return KBookmarkGroup(element);
+}
+
+TQString KBookmark::address() const
+{
+ if ( element.tagName() == "xbel" )
+ return ""; // not TQString::null !
+ else
+ {
+ // Use keditbookmarks's DEBUG_ADDRESSES flag to debug this code :)
+ if (!hasParent())
+ {
+ Q_ASSERT(hasParent());
+ return "ERROR"; // Avoid an infinite loop
+ }
+ KBookmarkGroup group = parentGroup();
+ TQString parentAddress = group.address();
+ uint counter = 0;
+ // Implementation note: we don't use QDomNode's childNode list because we
+ // would have to skip "TEXT", which KBookmarkGroup already does for us.
+ for ( KBookmark bk = group.first() ; !bk.isNull() ; bk = group.next(bk), ++counter )
+ {
+ if ( bk.element == element )
+ return parentAddress + "/" + TQString::number(counter);
+ }
+ kdWarning() << "KBookmark::address : this can't happen! " << parentAddress << endl;
+ return "ERROR";
+ }
+}
+
+KBookmark KBookmark::standaloneBookmark( const TQString & text, const KURL & url, const TQString & icon )
+{
+ TQDomDocument doc("xbel");
+ TQDomElement elem = doc.createElement("xbel");
+ doc.appendChild( elem );
+ KBookmarkGroup grp( elem );
+ grp.addBookmark( 0L, text, url, icon, false );
+ return grp.first();
+}
+
+// For some strange reason TQString("").left(0) returns TQString::null;
+// That breaks commonParent()
+TQString KBookmark::left(const TQString & str, uint len)
+{
+ //kdDebug()<<"********"<<TQString("").left(0).isNull()<<endl;
+ if(len == 0)
+ return TQString("");
+ else
+ return str.left(len);
+}
+
+TQString KBookmark::commonParent(TQString A, TQString B)
+{
+ TQString error("ERROR");
+ if(A == error || B == error)
+ return error;
+
+ A += "/";
+ B += "/";
+
+ uint lastCommonSlash = 0;
+ uint lastPos = A.length() < B.length() ? A.length() : B.length();
+ for(uint i=0; i < lastPos; ++i)
+ {
+ if(A[i] != B[i])
+ return left(A, lastCommonSlash);
+ if(A[i] == '/')
+ lastCommonSlash = i;
+ }
+ return left(A, lastCommonSlash);
+}
+
+static TQDomNode cd_or_create(TQDomNode node, TQString name)
+{
+ TQDomNode subnode = node.namedItem(name);
+ if (subnode.isNull())
+ {
+ subnode = node.ownerDocument().createElement(name);
+ node.appendChild(subnode);
+ }
+ return subnode;
+}
+
+static TQDomText get_or_create_text(TQDomNode node)
+{
+ TQDomNode subnode = node.firstChild();
+ if (subnode.isNull())
+ {
+ subnode = node.ownerDocument().createTextNode("");
+ node.appendChild(subnode);
+ }
+ return subnode.toText();
+}
+
+// Look for a metadata with owner="http://www.kde.org" or without any owner (for compatibility)
+static TQDomNode findOrCreateMetadata( TQDomNode& parent )
+{
+ static const char kdeOwner[] = "http://www.kde.org";
+ TQDomElement metadataElement;
+ for ( TQDomNode _node = parent.firstChild(); !_node.isNull(); _node = _node.nextSibling() ) {
+ TQDomElement elem = _node.toElement();
+ if ( !elem.isNull() && elem.tagName() == "metadata" ) {
+ const TQString owner = elem.attribute( "owner" );
+ if ( owner == kdeOwner )
+ return elem;
+ if ( owner.isEmpty() )
+ metadataElement = elem;
+ }
+ }
+ if ( metadataElement.isNull() ) {
+ metadataElement = parent.ownerDocument().createElement( "metadata" );
+ parent.appendChild(metadataElement);
+ }
+ metadataElement.setAttribute( "owner", kdeOwner );
+ return metadataElement;
+}
+
+bool KBookmark::hasMetaData() const
+{
+ // ### NOTE: this code creates <info> and <metadata>, despite its name and the const.
+ // It doesn't matter much in practice since it's only called for newly-created bookmarks,
+ // which will get metadata soon after anyway.
+ TQDomNode n = cd_or_create( internalElement(), "info" );
+ return findOrCreateMetadata( n ).hasChildNodes();
+}
+
+void KBookmark::updateAccessMetadata()
+{
+ kdDebug(7043) << "KBookmark::updateAccessMetadata " << address() << " " << url().prettyURL() << endl;
+
+ const uint timet = TQDateTime::currentDateTime().toTime_t();
+ setMetaDataItem( "time_added", TQString::number( timet ), DontOverwriteMetaData );
+ setMetaDataItem( "time_visited", TQString::number( timet ) );
+
+ TQString countStr = metaDataItem( "visit_count" ); // TODO use spec'ed name
+ bool ok;
+ int currentCount = countStr.toInt(&ok);
+ if (!ok)
+ currentCount = 0;
+ currentCount++;
+ setMetaDataItem( "visit_count", TQString::number( currentCount ) );
+
+ // TODO - for 4.0 - time_modified
+}
+
+TQString KBookmark::metaDataItem( const TQString &key ) const
+{
+ TQDomNode infoNode = cd_or_create( internalElement(), "info" );
+ infoNode = findOrCreateMetadata( infoNode );
+ for ( TQDomNode n = infoNode.firstChild(); !n.isNull(); n = n.nextSibling() ) {
+ if ( !n.isElement() ) {
+ continue;
+ }
+ const TQDomElement e = n.toElement();
+ if ( e.tagName() == key ) {
+ return e.text();
+ }
+ }
+ return TQString::null;
+}
+
+void KBookmark::setMetaDataItem( const TQString &key, const TQString &value, MetaDataOverwriteMode mode )
+{
+ TQDomNode infoNode = cd_or_create( internalElement(), "info" );
+ infoNode = findOrCreateMetadata( infoNode );
+
+ TQDomNode item = cd_or_create( infoNode, key );
+ TQDomText text = get_or_create_text( item );
+ if ( mode == DontOverwriteMetaData && !text.data().isEmpty() ) {
+ return;
+ }
+
+ text.setData( value );
+}
+
+void KBookmarkGroupTraverser::traverse(const KBookmarkGroup &root)
+{
+ // non-recursive bookmark iterator
+ TQValueStack<KBookmarkGroup> stack;
+ stack.push(root);
+ KBookmark bk = stack.top().first();
+ for (;;) {
+ if (bk.isNull())
+ {
+ if (stack.isEmpty())
+ return;
+ if (stack.count() > 1)
+ visitLeave(stack.top());
+ bk = stack.pop();
+ bk = stack.top().next(bk);
+ if (bk.isNull())
+ continue;
+ }
+
+ if (bk.isGroup())
+ {
+ KBookmarkGroup gp = bk.toGroup();
+ visitEnter(gp);
+ if (!gp.first().isNull())
+ {
+ stack.push(gp);
+ bk = gp.first();
+ continue;
+ }
+ // empty group
+ visitLeave(gp);
+ }
+ else
+ visit(bk);
+
+ bk = stack.top().next(bk);
+ }
+
+ // never reached
+}
+
diff --git a/tdeio/bookmarks/kbookmark.h b/tdeio/bookmarks/kbookmark.h
new file mode 100644
index 000000000..4e5dc9149
--- /dev/null
+++ b/tdeio/bookmarks/kbookmark.h
@@ -0,0 +1,329 @@
+// -*- c-basic-offset: 4; indent-tabs-mode:nil -*-
+// vim: set ts=4 sts=4 sw=4 et:
+/* This file is part of the KDE libraries
+ Copyright (C) 2000 David Faure <faure@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 version 2 as published by the Free Software Foundation.
+
+ 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 __kbookmark_h
+#define __kbookmark_h
+
+#include <tqstring.h>
+#include <tqvaluelist.h>
+#include <tqdom.h>
+#include <kurl.h>
+
+class KBookmarkManager;
+class KBookmarkGroup;
+
+class TDEIO_EXPORT KBookmark
+{
+ friend class KBookmarkGroup;
+public:
+ enum MetaDataOverwriteMode {
+ OverwriteMetaData, DontOverwriteMetaData
+ };
+
+ KBookmark( ) {}
+ KBookmark( TQDomElement elem ) : element(elem) {}
+
+ static KBookmark standaloneBookmark( const TQString & text, const KURL & url, const TQString & icon = TQString::null );
+
+ /**
+ * Whether the bookmark is a group or a normal bookmark
+ */
+ bool isGroup() const;
+
+ /**
+ * Whether the bookmark is a separator
+ */
+ bool isSeparator() const;
+
+ /**
+ * @return true if this is a null bookmark. This will never
+ * be the case for a real bookmark (in a menu), but it's used
+ * for instance as the end condition for KBookmarkGroup::next()
+ */
+ bool isNull() const {return element.isNull();}
+
+ /**
+ * @return true if bookmark is contained by a TQDomDocument,
+ * if not it is most likely that it has become separated and
+ * is thus invalid and/or has been deleted from the bookmarks.
+ * @since 3.2
+ */
+ bool hasParent() const;
+
+ /**
+ * Text shown for the bookmark
+ * If bigger than 40, the text is shortened by
+ * replacing middle characters with "..." (see KStringHandler::csqueeze)
+ */
+ TQString text() const;
+ /**
+ * Text shown for the bookmark, not truncated.
+ * You should not use this - this is mainly for keditbookmarks.
+ */
+ TQString fullText() const;
+ /**
+ * URL contained by the bookmark
+ */
+ KURL url() const;
+ /**
+ * @return the pixmap file for this bookmark
+ * (i.e. the name of the icon)
+ */
+ TQString icon() const;
+
+ /**
+ * @return the group containing this bookmark
+ */
+ KBookmarkGroup parentGroup() const;
+
+ /**
+ * Convert this to a group - do this only if
+ * isGroup() returns true.
+ */
+ KBookmarkGroup toGroup() const;
+
+ /**
+ * Return the "address" of this bookmark in the whole tree.
+ * This is used when telling other processes about a change
+ * in a given bookmark. The encoding of the address is "/4/2", for
+ * instance, to design the 2nd child inside the 4th child of the root bk.
+ */
+ TQString address() const;
+
+ // Hard to decide. Good design would imply that each bookmark
+ // knows about its manager, so that there can be several managers.
+ // But if we say there is only one manager (i.e. set of bookmarks)
+ // per application, then KBookmarkManager::self() is much easier.
+ //KBookmarkManager * manager() const { return m_manager; }
+
+ /**
+ * @internal for KEditBookmarks
+ */
+ TQDomElement internalElement() const { return element; }
+
+ /**
+ * Updates the bookmarks access metadata
+ * Call when a user accesses the bookmark
+ * @since 3.2
+ */
+ void updateAccessMetadata();
+
+ // Utility functions (internal)
+
+ /**
+ * @return address of parent
+ */
+ static TQString parentAddress( const TQString & address )
+ { return address.left( address.findRev('/') ); }
+
+ /**
+ * @return position in parent (e.g. /4/5/2 -> 2)
+ */
+ static uint positionInParent( const TQString & address )
+ { return address.mid( address.findRev('/') + 1 ).toInt(); }
+
+ /**
+ * @return address of previous sibling (e.g. /4/5/2 -> /4/5/1)
+ * Returns TQString::null for a first child
+ */
+ static TQString previousAddress( const TQString & address )
+ {
+ uint pp = positionInParent(address);
+ return pp>0 ? parentAddress(address) + '/' + TQString::number(pp-1) : TQString::null;
+ }
+
+ /**
+ * @return address of next sibling (e.g. /4/5/2 -> /4/5/3)
+ * This doesn't check whether it actually exists
+ */
+ static TQString nextAddress( const TQString & address )
+ { return parentAddress(address) + '/' + TQString::number(positionInParent(address)+1); }
+
+ /**
+ * @return the common parent of both addresses which
+ * has the greatest depth
+ * @since 3.5
+ */
+ static TQString commonParent(TQString A, TQString B);
+
+ /**
+ * Get the value of a specific metadata item.
+ * @param key Name of the metadata item
+ * @return Value of the metadata item. TQString::null is returned in case
+ * the specified key does not exist.
+ * @since 3.4
+ */
+ TQString metaDataItem( const TQString &key ) const;
+
+ /**
+ * Change the value of a specific metadata item, or create the given item
+ * if it doesn't exist already.
+ * @param key Name of the metadata item to change
+ * @param value Value to use for the specified metadata item
+ * @param mode Whether to overwrite the item's value if it exists already or not.
+ * @since 3.4
+ */
+ void setMetaDataItem( const TQString &key, const TQString &value, MetaDataOverwriteMode mode = OverwriteMetaData );
+
+protected:
+ TQDomElement element;
+ // Note: you can't add new member variables here.
+ // The KBookmarks are created on the fly, as wrappers
+ // around internal QDomElements. Any additional information
+ // has to be implemented as an attribute of the TQDomElement.
+
+private:
+ bool hasMetaData() const;
+ static TQString left(const TQString & str, uint len);
+};
+
+/**
+ * A group of bookmarks
+ */
+class TDEIO_EXPORT KBookmarkGroup : public KBookmark
+{
+public:
+ /**
+ * Create an invalid group. This is mostly for use in TQValueList,
+ * and other places where we need a null group.
+ * Also used as a parent for a bookmark that doesn't have one
+ * (e.g. Netscape bookmarks)
+ */
+ KBookmarkGroup();
+
+ /**
+ * Create a bookmark group as specified by the given element
+ */
+ KBookmarkGroup( TQDomElement elem );
+
+ /**
+ * Much like KBookmark::address, but caches the
+ * address into m_address.
+ */
+ TQString groupAddress() const;
+
+ /**
+ * @return true if the bookmark folder is opened in the bookmark editor
+ */
+ bool isOpen() const;
+
+ /**
+ * Return the first child bookmark of this group
+ */
+ KBookmark first() const;
+ /**
+ * Return the prevous sibling of a child bookmark of this group
+ * @param current has to be one of our child bookmarks.
+ */
+ KBookmark previous( const KBookmark & current ) const;
+ /**
+ * Return the next sibling of a child bookmark of this group
+ * @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
+ * @param mgr the manager of the bookmark
+ * @param text for the folder. If empty, the user will be queried for it.
+ * @param emitSignal if true emit KBookmarkNotifier signal
+ */
+ KBookmarkGroup createNewFolder( KBookmarkManager* mgr, const TQString & text = TQString::null, bool emitSignal = true );
+ /**
+ * Create a new bookmark separator
+ * Don't forget to use KBookmarkManager::self()->emitChanged( parentBookmark );
+ */
+ KBookmark createNewSeparator();
+
+ /**
+ * Create a new bookmark, as the last child of this group
+ * Don't forget to use KBookmarkManager::self()->emitChanged( parentBookmark );
+ * @param mgr the manager of the bookmark
+ * @param bm the bookmark to add
+ * @param emitSignal if true emit KBookmarkNotifier signal
+ * @since 3.4
+ */
+ KBookmark addBookmark( KBookmarkManager* mgr, const KBookmark &bm, bool emitSignal = true );
+
+ /**
+ * Create a new bookmark, as the last child of this group
+ * Don't forget to use KBookmarkManager::self()->emitChanged( parentBookmark );
+ * @param mgr the manager of the bookmark
+ * @param text for the bookmark
+ * @param url the URL that the bookmark points to
+ * @param icon the name of the icon to associate with the bookmark. A suitable default
+ * will be determined from the URL if not specified.
+ * @param emitSignal if true emit KBookmarkNotifier signal
+ */
+ KBookmark addBookmark( KBookmarkManager* mgr, const TQString & text, const KURL & url, const TQString & icon = TQString::null, bool emitSignal = true );
+
+ /**
+ * Moves @p item after @p after (which should be a child of ours).
+ * If item is null, @p item is moved as the first child.
+ * Don't forget to use KBookmarkManager::self()->emitChanged( parentBookmark );
+ */
+ bool moveItem( const KBookmark & item, const KBookmark & after );
+
+ /**
+ * Delete a bookmark - it has to be one of our children !
+ * Don't forget to use KBookmarkManager::self()->emitChanged( parentBookmark );
+ */
+ void deleteBookmark( KBookmark bk );
+
+ /**
+ * @return true if this is the toolbar group
+ */
+ bool isToolbarGroup() const;
+ /**
+ * @internal
+ */
+ TQDomElement findToolbar() const;
+
+ /**
+ * @return the list of urls of bookmarks at top level of the group
+ * @since 3.2
+ */
+ TQValueList<KURL> groupUrlList() const;
+
+protected:
+ TQDomElement nextKnownTag( TQDomElement start, bool goNext ) const;
+
+private:
+ mutable TQString m_address;
+ // Note: you can't add other member variables here, except for caching info.
+ // The KBookmarks are created on the fly, as wrappers
+ // around internal QDomElements. Any additional information
+ // has to be implemented as an attribute of the TQDomElement.
+};
+
+/**
+ * @since 3.2
+ */
+class TDEIO_EXPORT KBookmarkGroupTraverser {
+protected:
+ virtual ~KBookmarkGroupTraverser() { ; }
+ void traverse(const KBookmarkGroup &);
+ virtual void visit(const KBookmark &) { ; }
+ virtual void visitEnter(const KBookmarkGroup &) { ; }
+ virtual void visitLeave(const KBookmarkGroup &) { ; }
+private:
+ class KBookmarkGroupTraverserPrivate *d;
+};
+
+#endif
diff --git a/tdeio/bookmarks/kbookmarkbar.cc b/tdeio/bookmarks/kbookmarkbar.cc
new file mode 100644
index 000000000..e73801808
--- /dev/null
+++ b/tdeio/bookmarks/kbookmarkbar.cc
@@ -0,0 +1,554 @@
+// -*- c-basic-offset:4; indent-tabs-mode:nil -*-
+// vim: set ts=4 sts=4 sw=4 et:
+/* 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., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+#include <tqregexp.h>
+#include <tqfile.h>
+
+#include <kbookmarkbar.h>
+#include <kbookmarkdrag.h>
+
+#include <kbookmarkmenu.h>
+#include <kdebug.h>
+
+#include <ktoolbar.h>
+#include <ktoolbarbutton.h>
+
+#include <tdeconfig.h>
+#include <kpopupmenu.h>
+
+#include "kbookmarkdrag.h"
+#include "kbookmarkmenu_p.h"
+#include "kbookmarkdombuilder.h"
+
+#include "dptrtemplate.h"
+
+#include <tqapplication.h>
+
+class KBookmarkBarPrivate : public dPtrTemplate<KBookmarkBar, KBookmarkBarPrivate>
+{
+public:
+ TQPtrList<KAction> m_actions;
+ bool m_readOnly;
+ KBookmarkManager* m_filteredMgr;
+ KToolBar* m_sepToolBar;
+ int m_sepIndex;
+ bool m_atFirst;
+ TQString m_dropAddress;
+ TQString m_highlightedAddress;
+public:
+ KBookmarkBarPrivate() {
+ m_readOnly = false;
+ m_filteredMgr = 0;
+ m_sepToolBar = 0;
+ m_sepIndex = -1;
+ m_atFirst = false;
+ }
+};
+template<> TQPtrDict<KBookmarkBarPrivate>* dPtrTemplate<KBookmarkBar, KBookmarkBarPrivate>::d_ptr = 0;
+
+KBookmarkBarPrivate* KBookmarkBar::dptr() const
+{
+ return KBookmarkBarPrivate::d( this );
+}
+
+// usage of KXBELBookmarkImporterImpl is just plain evil, but it reduces code dup. so...
+class ToolbarFilter : public KXBELBookmarkImporterImpl
+{
+public:
+ ToolbarFilter() : m_visible(false) { ; }
+ void filter( const KBookmarkGroup &grp ) { traverse(grp); }
+private:
+ virtual void visit( const KBookmark & );
+ virtual void visitEnter( const KBookmarkGroup & );
+ virtual void visitLeave( const KBookmarkGroup & );
+private:
+ bool m_visible;
+ KBookmarkGroup m_visibleStart;
+};
+
+KBookmarkBar::KBookmarkBar( KBookmarkManager* mgr,
+ KBookmarkOwner *_owner, KToolBar *_toolBar,
+ KActionCollection *coll,
+ TQObject *parent, const char *name )
+ : TQObject( parent, name ), m_pOwner(_owner), m_toolBar(_toolBar),
+ m_actionCollection( coll ), m_pManager(mgr)
+{
+ m_lstSubMenus.setAutoDelete( true );
+
+ m_toolBar->setAcceptDrops( true );
+ m_toolBar->installEventFilter( this ); // for drops
+
+ dptr()->m_actions.setAutoDelete( true );
+
+ connect( mgr, TQT_SIGNAL( changed(const TQString &, const TQString &) ),
+ TQT_SLOT( slotBookmarksChanged(const TQString &) ) );
+
+ KBookmarkGroup toolbar = getToolbar();
+ fillBookmarkBar( toolbar );
+}
+
+TQString KBookmarkBar::parentAddress()
+{
+ return dptr()->m_filteredMgr ? TQString::null : m_pManager->toolbar().address();
+}
+
+#define CURRENT_TOOLBAR() ( \
+ dptr()->m_filteredMgr ? dptr()->m_filteredMgr->root() \
+ : m_pManager->toolbar() )
+
+#define CURRENT_MANAGER() ( \
+ dptr()->m_filteredMgr ? dptr()->m_filteredMgr \
+ : m_pManager )
+
+KBookmarkGroup KBookmarkBar::getToolbar()
+{
+ if ( KBookmarkSettings::self()->m_filteredtoolbar )
+ {
+ if ( !dptr()->m_filteredMgr ) {
+ dptr()->m_filteredMgr = KBookmarkManager::createTempManager();
+ } else {
+ KBookmarkGroup bkRoot = dptr()->m_filteredMgr->root();
+ TQValueList<KBookmark> bks;
+ for (KBookmark bm = bkRoot.first(); !bm.isNull(); bm = bkRoot.next(bm))
+ bks << bm;
+ for ( TQValueListConstIterator<KBookmark> it = bks.begin(); it != bks.end(); ++it )
+ bkRoot.deleteBookmark( (*it) );
+ }
+ ToolbarFilter filter;
+ KBookmarkDomBuilder builder( dptr()->m_filteredMgr->root(),
+ dptr()->m_filteredMgr );
+ builder.connectImporter( &filter );
+ filter.filter( m_pManager->root() );
+ }
+
+ return CURRENT_TOOLBAR();
+}
+
+KBookmarkBar::~KBookmarkBar()
+{
+ //clear();
+ KBookmarkBarPrivate::delete_d(this);
+}
+
+void KBookmarkBar::clear()
+{
+ TQPtrListIterator<KAction> it( dptr()->m_actions );
+ m_toolBar->clear();
+ for (; it.current(); ++it ) {
+ (*it)->unplugAll();
+ }
+ dptr()->m_actions.clear();
+ m_lstSubMenus.clear();
+}
+
+void KBookmarkBar::slotBookmarksChanged( const TQString & group )
+{
+ KBookmarkGroup tb = getToolbar(); // heavy for non cached toolbar version
+ kdDebug(7043) << "slotBookmarksChanged( " << group << " )" << endl;
+
+ if ( tb.isNull() )
+ return;
+
+ if ( KBookmark::commonParent(group, tb.address()) == group // Is group a parent of tb.address?
+ || KBookmarkSettings::self()->m_filteredtoolbar )
+ {
+ clear();
+ fillBookmarkBar( tb );
+ }
+ else
+ {
+ // Iterate recursively into child menus
+ TQPtrListIterator<KBookmarkMenu> it( m_lstSubMenus );
+ for (; it.current(); ++it )
+ {
+ it.current()->slotBookmarksChanged( group );
+ }
+ }
+}
+
+void KBookmarkBar::fillBookmarkBar(KBookmarkGroup & parent)
+{
+ if (parent.isNull())
+ return;
+
+ for (KBookmark bm = parent.first(); !bm.isNull(); bm = parent.next(bm))
+ {
+ TQString text = bm.text();
+ text.replace( '&', "&&" );
+ if (!bm.isGroup())
+ {
+ if ( bm.isSeparator() )
+ m_toolBar->insertLineSeparator();
+ else
+ {
+ KAction *action = new KBookmarkAction( text, bm.icon(), 0, m_actionCollection, 0 );
+ connect(action, TQT_SIGNAL( activated ( KAction::ActivationReason, TQt::ButtonState )),
+ this, TQT_SLOT( slotBookmarkSelected( KAction::ActivationReason, TQt::ButtonState ) ));
+
+ action->setProperty( "url", bm.url().url() );
+ action->setProperty( "address", bm.address() );
+
+ action->setToolTip( bm.url().pathOrURL() );
+
+ action->plug(m_toolBar);
+
+ dptr()->m_actions.append( action );
+ }
+ }
+ else
+ {
+ KActionMenu *action = new KBookmarkActionMenu( text, bm.icon(),
+ m_actionCollection,
+ "bookmarkbar-actionmenu");
+ action->setProperty( "address", bm.address() );
+ action->setProperty( "readOnly", dptr()->m_readOnly );
+ action->setDelayed( false );
+
+ // this flag doesn't have any UI yet
+ TDEGlobal::config()->setGroup( "Settings" );
+ bool addEntriesBookmarkBar = TDEGlobal::config()->readBoolEntry("AddEntriesBookmarkBar",true);
+
+ KBookmarkMenu *menu = new KBookmarkMenu(CURRENT_MANAGER(), m_pOwner, action->popupMenu(),
+ m_actionCollection, false, addEntriesBookmarkBar,
+ bm.address());
+ connect(menu, TQT_SIGNAL( aboutToShowContextMenu(const KBookmark &, TQPopupMenu * ) ),
+ this, TQT_SIGNAL( aboutToShowContextMenu(const KBookmark &, TQPopupMenu * ) ));
+ connect(menu, TQT_SIGNAL( openBookmark( const TQString &, TQt::ButtonState) ),
+ this, TQT_SIGNAL( openBookmark( const TQString &, TQt::ButtonState) ));
+ menu->fillBookmarkMenu();
+ action->plug(m_toolBar);
+ m_lstSubMenus.append( menu );
+
+ dptr()->m_actions.append( action );
+ }
+ }
+}
+
+void KBookmarkBar::setReadOnly(bool readOnly)
+{
+ dptr()->m_readOnly = readOnly;
+}
+
+bool KBookmarkBar::isReadOnly() const
+{
+ return dptr()->m_readOnly;
+}
+
+void KBookmarkBar::slotBookmarkSelected( KAction::ActivationReason /*reason*/, TQt::ButtonState state )
+{
+ if (!m_pOwner) return; // this view doesn't handle bookmarks...
+
+ const KAction* action = dynamic_cast<const KAction *>(sender());
+ if(action)
+ {
+ const TQString & url = sender()->property("url").toString();
+ m_pOwner->openBookmarkURL(url);
+ emit openBookmark( url, state );
+ }
+}
+
+void KBookmarkBar::slotBookmarkSelected()
+{
+ slotBookmarkSelected(KAction::ToolBarActivation, Qt::NoButton);
+}
+
+static const int const_sepId = -9999; // FIXME this is ugly,
+ // surely there is another
+ // way of doing this...
+
+static void removeTempSep(KBookmarkBarPrivate* p)
+{
+ if (p->m_sepToolBar) {
+ p->m_sepToolBar->removeItem(const_sepId);
+ p->m_sepToolBar = 0; // needed?
+ }
+}
+
+static KAction* findPluggedAction(TQPtrList<KAction> actions, KToolBar *tb, int id)
+{
+ TQPtrListIterator<KAction> it( actions );
+ for (; (*it); ++it )
+ if ((*it)->isPlugged(tb, id))
+ return (*it);
+ return 0;
+}
+
+/**
+ * Handle a TQDragMoveEvent event on a toolbar drop
+ * @return the address of the bookmark to be dropped after/before
+ * else a TQString::null if event should be ignored
+ * @param pos the current TQDragMoveEvent position
+ * @param the toolbar
+ * @param actions the list of actions plugged into the bar
+ * @param atFirst bool reference, when true the position before the
+ * returned action was dropped on
+ */
+static TQString handleToolbarDragMoveEvent(
+ KBookmarkBarPrivate *p, KToolBar *tb, TQPoint pos, TQPtrList<KAction> actions,
+ bool &atFirst, KBookmarkManager *mgr
+) {
+ Q_UNUSED( mgr );
+ Q_ASSERT( actions.isEmpty() || (tb == dynamic_cast<KToolBar*>(actions.first()->container(0))) );
+ p->m_sepToolBar = tb;
+ p->m_sepToolBar->removeItemDelayed(const_sepId);
+
+ int index = 0;
+ KToolBarButton* b;
+
+ b = dynamic_cast<KToolBarButton*>(tb->childAt(pos));
+ KAction *a = 0;
+ TQString address;
+ atFirst = false;
+
+ if (b)
+ {
+ index = tb->itemIndex(b->id());
+ TQRect r = b->geometry();
+ if (pos.x() < ((r.left() + r.right())/2))
+ {
+ // if in first half of button then
+ // we jump to previous index
+ if ( index == 0 )
+ atFirst = true;
+ else {
+ index--;
+ b = tb->getButton(tb->idAt(index));
+ }
+ }
+ }
+ else if (actions.isEmpty())
+ {
+ atFirst = true;
+ index = 0;
+ // we skip the action related stuff
+ // and do what it should have...
+ // FIXME - here we want to get the
+ // parent address of the bookmark
+ // bar itself and return that + "/0"
+ p->m_sepIndex = 0;
+ goto skipact;
+ }
+ else // (!b)
+ {
+ index = actions.count() - 1;
+ b = tb->getButton(tb->idAt(index));
+ // if !b and not past last button, we didn't find button
+ if (pos.x() <= b->geometry().left())
+ goto skipact; // TODO - rename
+ }
+
+ if ( !b )
+ return TQString::null; // TODO Make it works for that case
+
+ a = findPluggedAction(actions, tb, b->id());
+ Q_ASSERT(a);
+ address = a->property("address").toString();
+ p->m_sepIndex = index + (atFirst ? 0 : 1);
+
+#if 0
+ { // ugly workaround to fix the goto scoping problems...
+ KBookmark bk = mgr->findByAddress( address );
+ if (bk.isGroup()) // TODO - fix this ****!!!, manhatten distance should be used!!!
+ {
+ kdDebug() << "kbookmarkbar:: popping up " << bk.text() << endl;
+ KBookmarkActionMenu *menu = dynamic_cast<KBookmarkActionMenu*>(a);
+ Q_ASSERT(menu);
+ menu->popup(tb->mapToGlobal(b->geometry().center()));
+ }
+ }
+#endif
+
+skipact:
+ tb->insertLineSeparator(p->m_sepIndex, const_sepId);
+ return address;
+}
+
+// TODO - document!!!!
+static KAction* handleToolbarMouseButton(TQPoint pos, TQPtrList<KAction> actions,
+ KBookmarkManager * /*mgr*/, TQPoint & pt)
+{
+ KAction *act = actions.first();
+ if (!act) {
+ return 0;
+ }
+
+ KToolBar *tb = dynamic_cast<KToolBar*>(act->container(0));
+ Q_ASSERT(tb);
+
+ KToolBarButton *b;
+ b = dynamic_cast<KToolBarButton*>(tb->childAt(pos));
+ if (!b)
+ return 0;
+
+ KAction *a = 0;
+ a = findPluggedAction(actions, tb, b->id());
+ Q_ASSERT(a);
+ pt = tb->mapToGlobal(pos);
+
+ return a;
+}
+
+// TODO *** drop improvements ***
+// open submenus on drop interactions
+
+// TODO *** generic rmb improvements ***
+// don't *ever* show the rmb on press, always relase, possible???
+
+class KBookmarkBarRMBAssoc : public dPtrTemplate<KBookmarkBar, RMB> { };
+template<> TQPtrDict<RMB>* dPtrTemplate<KBookmarkBar, RMB>::d_ptr = 0;
+
+static RMB* rmbSelf(KBookmarkBar *m) { return KBookmarkBarRMBAssoc::d(m); }
+
+void RMB::begin_rmb_action(KBookmarkBar *self)
+{
+ RMB *s = rmbSelf(self);
+ s->recv = self;
+ s->m_parentAddress = self->parentAddress();
+ s->s_highlightedAddress = self->dptr()->m_highlightedAddress; // rename in RMB
+ s->m_pManager = self->m_pManager;
+ s->m_pOwner = self->m_pOwner;
+ s->m_parentMenu = 0;
+}
+
+void KBookmarkBar::slotRMBActionEditAt( int val )
+{ RMB::begin_rmb_action(this); rmbSelf(this)->slotRMBActionEditAt( val ); }
+
+void KBookmarkBar::slotRMBActionProperties( int val )
+{ RMB::begin_rmb_action(this); rmbSelf(this)->slotRMBActionProperties( val ); }
+
+void KBookmarkBar::slotRMBActionInsert( int val )
+{ RMB::begin_rmb_action(this); rmbSelf(this)->slotRMBActionInsert( val ); }
+
+void KBookmarkBar::slotRMBActionRemove( int val )
+{ RMB::begin_rmb_action(this); rmbSelf(this)->slotRMBActionRemove( val ); }
+
+void KBookmarkBar::slotRMBActionCopyLocation( int val )
+{ RMB::begin_rmb_action(this); rmbSelf(this)->slotRMBActionCopyLocation( val ); }
+
+bool KBookmarkBar::eventFilter( TQObject *o, TQEvent *e )
+{
+ if (dptr()->m_readOnly || dptr()->m_filteredMgr) // note, we assume m_pManager in various places,
+ // this shouldn't really be the case
+ return false; // todo: make this limit the actions
+
+ if ( (e->type() == TQEvent::MouseButtonRelease) || (e->type() == TQEvent::MouseButtonPress) ) // FIXME, which one?
+ {
+ TQMouseEvent *mev = (TQMouseEvent*)e;
+
+ TQPoint pt;
+ KAction *_a;
+
+ // FIXME, see how this holds up on an empty toolbar
+ _a = handleToolbarMouseButton( mev->pos(), dptr()->m_actions, m_pManager, pt );
+ if (_a && mev->button() == Qt::RightButton)
+ {
+ dptr()->m_highlightedAddress = _a->property("address").toString();
+ KBookmark bookmark = m_pManager->findByAddress( dptr()->m_highlightedAddress );
+ RMB::begin_rmb_action(this);
+ KPopupMenu *pm = new KPopupMenu;
+ rmbSelf(this)->fillContextMenu( pm, dptr()->m_highlightedAddress, 0 );
+ emit aboutToShowContextMenu( rmbSelf(this)->atAddress( dptr()->m_highlightedAddress ), pm );
+ rmbSelf(this)->fillContextMenu2( pm, dptr()->m_highlightedAddress, 0 );
+ pm->popup( pt );
+ mev->accept();
+ }
+
+ return !!_a; // ignore the event if we didn't find the button
+ }
+ else if ( e->type() == TQEvent::DragLeave )
+ {
+ removeTempSep(dptr());
+ dptr()->m_dropAddress = TQString::null;
+ }
+ else if ( e->type() == TQEvent::Drop )
+ {
+ removeTempSep(dptr());
+ TQDropEvent *dev = (TQDropEvent*)e;
+ if ( !KBookmarkDrag::canDecode( dev ) )
+ return false;
+ TQValueList<KBookmark> list = KBookmarkDrag::decode( dev );
+ if (list.count() > 1)
+ kdWarning(7043) << "Sorry, currently you can only drop one address "
+ "onto the bookmark bar!" << endl;
+ KBookmark toInsert = list.first();
+ KBookmark bookmark = m_pManager->findByAddress( dptr()->m_dropAddress );
+ Q_ASSERT(!bookmark.isNull());
+ kdDebug(7043) << "inserting "
+ << TQString(dptr()->m_atFirst ? "before" : "after")
+ << " dptr()->m_dropAddress == " << dptr()->m_dropAddress << endl;
+ KBookmarkGroup parentBookmark = bookmark.parentGroup();
+ Q_ASSERT(!parentBookmark.isNull());
+ KBookmark newBookmark = parentBookmark.addBookmark(
+ m_pManager, toInsert.fullText(),
+ toInsert.url() );
+ parentBookmark.moveItem( newBookmark, dptr()->m_atFirst ? KBookmark() : bookmark );
+ m_pManager->emitChanged( parentBookmark );
+ return true;
+ }
+ else if ( e->type() == TQEvent::DragMove )
+ {
+ TQDragMoveEvent *dme = (TQDragMoveEvent*)e;
+ if (!KBookmarkDrag::canDecode( dme ))
+ return false;
+ bool _atFirst;
+ TQString dropAddress;
+ KToolBar *tb = (KToolBar*)o;
+ dropAddress = handleToolbarDragMoveEvent(dptr(), tb, dme->pos(), dptr()->m_actions, _atFirst, m_pManager);
+ if (!dropAddress.isNull())
+ {
+ dptr()->m_dropAddress = dropAddress;
+ dptr()->m_atFirst = _atFirst;
+ dme->accept();
+ }
+ }
+ return false;
+}
+
+static bool showInToolbar( const KBookmark &bk ) {
+ return (bk.internalElement().attributes().namedItem("showintoolbar").toAttr().value() == "yes");
+}
+
+void ToolbarFilter::visit( const KBookmark &bk ) {
+ //kdDebug() << "visit(" << bk.text() << ")" << endl;
+ if ( m_visible || showInToolbar(bk) )
+ KXBELBookmarkImporterImpl::visit(bk);
+}
+
+void ToolbarFilter::visitEnter( const KBookmarkGroup &grp ) {
+ //kdDebug() << "visitEnter(" << grp.text() << ")" << endl;
+ if ( !m_visible && showInToolbar(grp) )
+ {
+ m_visibleStart = grp;
+ m_visible = true;
+ }
+ if ( m_visible )
+ KXBELBookmarkImporterImpl::visitEnter(grp);
+}
+
+void ToolbarFilter::visitLeave( const KBookmarkGroup &grp ) {
+ //kdDebug() << "visitLeave()" << endl;
+ if ( m_visible )
+ KXBELBookmarkImporterImpl::visitLeave(grp);
+ if ( m_visible && grp.address() == m_visibleStart.address() )
+ m_visible = false;
+}
+
+#include "kbookmarkbar.moc"
diff --git a/tdeio/bookmarks/kbookmarkbar.h b/tdeio/bookmarks/kbookmarkbar.h
new file mode 100644
index 000000000..1f100d183
--- /dev/null
+++ b/tdeio/bookmarks/kbookmarkbar.h
@@ -0,0 +1,131 @@
+// -*- c-basic-offset:4; indent-tabs-mode:nil -*-
+// vim: set ts=4 sts=4 sw=4 et:
+/* 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., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+#ifndef KBOOKMARKBAR_H
+#define KBOOKMARKBAR_H
+
+#include <tqobject.h>
+#include <tqguardedptr.h>
+#include <tqptrlist.h>
+#include <kbookmark.h>
+#include <kaction.h>
+
+class KToolBar;
+class KBookmarkMenu;
+class KBookmarkOwner;
+class KActionCollection;
+class KAction;
+class TQPopupMenu;
+
+/**
+ * This class provides a bookmark toolbar. Using this class is nearly
+ * identical to using KBookmarkMenu so follow the directions
+ * there.
+ */
+class TDEIO_EXPORT KBookmarkBar : public TQObject
+{
+ Q_OBJECT
+
+ friend class RMB;
+public:
+ /**
+ * Fills a bookmark toolbar
+ *
+ * @param manager the bookmark manager
+ * @param owner implementation of the KBookmarkOwner interface (callbacks)
+ * @param toolBar toolbar to fill
+ *
+ * The KActionCollection pointer argument is now obsolete.
+ *
+ * @param parent the parent widget for the bookmark toolbar
+ * @param name the internal name for the bookmark toolbar
+ */
+ KBookmarkBar( KBookmarkManager* manager,
+ KBookmarkOwner *owner, KToolBar *toolBar,
+ KActionCollection *,
+ TQObject *parent = 0L, const char *name = 0L);
+
+ virtual ~KBookmarkBar();
+
+ /**
+ * @since 3.2
+ */
+ bool isReadOnly() const;
+
+ /**
+ * @since 3.2
+ */
+ void setReadOnly(bool);
+
+ /**
+ * @since 3.2
+ */
+ TQString parentAddress();
+
+signals:
+ /**
+ * @since 3.2
+ */
+ void aboutToShowContextMenu( const KBookmark &, TQPopupMenu * );
+ /**
+ * @since 3.4
+ */
+ void openBookmark( const TQString& url, TQt::ButtonState state );
+
+public slots:
+ void clear();
+
+ void slotBookmarksChanged( const TQString & );
+ void slotBookmarkSelected();
+
+ /**
+ * @since 3.4
+ */
+ void slotBookmarkSelected( KAction::ActivationReason reason, TQt::ButtonState state );
+
+ /// @since 3.2
+ void slotRMBActionRemove( int );
+ /// @since 3.2
+ void slotRMBActionInsert( int );
+ /// @since 3.2
+ void slotRMBActionCopyLocation( int );
+ /// @since 3.2
+ void slotRMBActionEditAt( int );
+ /// @since 3.2
+ void slotRMBActionProperties( int );
+
+protected:
+ void fillBookmarkBar( KBookmarkGroup & parent );
+ virtual bool eventFilter( TQObject *o, TQEvent *e );
+
+private:
+ KBookmarkGroup getToolbar();
+
+ KBookmarkOwner *m_pOwner;
+ TQGuardedPtr<KToolBar> m_toolBar;
+ KActionCollection *m_actionCollection;
+ KBookmarkManager *m_pManager;
+ TQPtrList<KBookmarkMenu> m_lstSubMenus;
+
+private:
+ class KBookmarkBarPrivate* dptr() const;
+};
+
+#endif // KBOOKMARKBAR_H
diff --git a/tdeio/bookmarks/kbookmarkdombuilder.cc b/tdeio/bookmarks/kbookmarkdombuilder.cc
new file mode 100644
index 000000000..5c0882d05
--- /dev/null
+++ b/tdeio/bookmarks/kbookmarkdombuilder.cc
@@ -0,0 +1,81 @@
+/* This file is part of the KDE project
+ Copyright (C) 2000 David Faure <faure@kde.org>
+ Copyright (C) 2002-2003 Alexander Kellett <lypanov@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 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this program; see the file COPYING. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <kbookmarkmanager.h>
+#include <kdebug.h>
+
+#include "kbookmarkdombuilder.h"
+
+KBookmarkDomBuilder::KBookmarkDomBuilder(
+ const KBookmarkGroup &bkGroup, KBookmarkManager *manager
+) {
+ m_manager = manager;
+ m_stack.push(bkGroup);
+}
+
+KBookmarkDomBuilder::~KBookmarkDomBuilder() {
+ m_list.clear();
+ m_stack.clear();
+}
+
+void KBookmarkDomBuilder::connectImporter(const TQObject *importer) {
+ connect(importer, TQT_SIGNAL( newBookmark(const TQString &, const TQCString &, const TQString &) ),
+ TQT_SLOT( newBookmark(const TQString &, const TQCString &, const TQString &) ));
+ connect(importer, TQT_SIGNAL( newFolder(const TQString &, bool, const TQString &) ),
+ TQT_SLOT( newFolder(const TQString &, bool, const TQString &) ));
+ connect(importer, TQT_SIGNAL( newSeparator() ),
+ TQT_SLOT( newSeparator() ) );
+ connect(importer, TQT_SIGNAL( endFolder() ),
+ TQT_SLOT( endFolder() ) );
+}
+
+void KBookmarkDomBuilder::newBookmark(
+ const TQString &text, const TQCString &url, const TQString &additionalInfo
+) {
+ KBookmark bk = m_stack.top().addBookmark(
+ m_manager, text,
+ KURL( TQString::fromUtf8(url), 106 /*utf8*/ ),
+ TQString::null, false);
+ // store additional info
+ bk.internalElement().setAttribute("netscapeinfo", additionalInfo);
+}
+
+void KBookmarkDomBuilder::newFolder(
+ const TQString & text, bool open, const TQString & additionalInfo
+) {
+ // we use a qvaluelist so that we keep pointers to valid objects in the stack
+ KBookmarkGroup gp = m_stack.top().createNewFolder(m_manager, text, false);
+ m_list.append(gp);
+ m_stack.push(m_list.last());
+ // store additional info
+ TQDomElement element = m_list.last().internalElement();
+ element.setAttribute("netscapeinfo", additionalInfo);
+ element.setAttribute("folded", (open?"no":"yes"));
+}
+
+void KBookmarkDomBuilder::newSeparator() {
+ m_stack.top().createNewSeparator();
+}
+
+void KBookmarkDomBuilder::endFolder() {
+ m_stack.pop();
+}
+
+#include "kbookmarkdombuilder.moc"
diff --git a/tdeio/bookmarks/kbookmarkdombuilder.h b/tdeio/bookmarks/kbookmarkdombuilder.h
new file mode 100644
index 000000000..44fe7b170
--- /dev/null
+++ b/tdeio/bookmarks/kbookmarkdombuilder.h
@@ -0,0 +1,48 @@
+/* This file is part of the KDE project
+ Copyright (C) 2003 Alexander Kellett <lypanov@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 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this program; see the file COPYING. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef __kbookmarkdombuilder_h
+#define __kbookmarkdombuilder_h
+
+#include <tqvaluestack.h>
+#include <tqobject.h>
+#include <kbookmark.h>
+
+/**
+ * @since 3.2
+ */
+class TDEIO_EXPORT KBookmarkDomBuilder : public TQObject {
+ Q_OBJECT
+public:
+ KBookmarkDomBuilder(const KBookmarkGroup &group, KBookmarkManager *);
+ virtual ~KBookmarkDomBuilder();
+ void connectImporter(const TQObject *);
+protected slots:
+ void newBookmark(const TQString &text, const TQCString &url, const TQString &additionalInfo);
+ void newFolder(const TQString &text, bool open, const TQString &additionalInfo);
+ void newSeparator();
+ void endFolder();
+private:
+ TQValueStack<KBookmarkGroup> m_stack;
+ TQValueList<KBookmarkGroup> m_list;
+ KBookmarkManager *m_manager;
+ class KBookmarkDomBuilderPrivate *p;
+};
+
+#endif
diff --git a/tdeio/bookmarks/kbookmarkdrag.cc b/tdeio/bookmarks/kbookmarkdrag.cc
new file mode 100644
index 000000000..d13893eed
--- /dev/null
+++ b/tdeio/bookmarks/kbookmarkdrag.cc
@@ -0,0 +1,169 @@
+// -*- c-basic-offset:4; indent-tabs-mode:nil -*-
+// vim: set ts=4 sts=4 sw=4 et:
+/* This file is part of the KDE libraries
+ Copyright (C) 2000 David Faure <faure@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 version 2 as published by the Free Software Foundation.
+
+ 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 "kbookmarkdrag.h"
+#include <kurldrag.h>
+#include <kdebug.h>
+
+KBookmarkDrag * KBookmarkDrag::newDrag( const TQValueList<KBookmark> & bookmarks, TQWidget * dragSource, const char * name )
+{
+ KURL::List urls;
+
+ for ( TQValueListConstIterator<KBookmark> it = bookmarks.begin(); it != bookmarks.end(); ++it ) {
+ urls.append( (*it).url() );
+ }
+
+ // See KURLDrag::newDrag
+ TQStrList uris;
+ KURL::List::ConstIterator uit = urls.begin();
+ KURL::List::ConstIterator uEnd = urls.end();
+ // Get each URL encoded in utf8 - and since we get it in escaped
+ // form on top of that, .latin1() is fine.
+ for ( ; uit != uEnd ; ++uit )
+ uris.append( KURLDrag::urlToString(*uit).latin1() );
+
+ return new KBookmarkDrag( bookmarks, uris, dragSource, name );
+}
+
+KBookmarkDrag * KBookmarkDrag::newDrag( const KBookmark & bookmark, TQWidget * dragSource, const char * name )
+{
+ TQValueList<KBookmark> bookmarks;
+ bookmarks.append( KBookmark(bookmark) );
+ return newDrag(bookmarks, dragSource, name);
+}
+
+KBookmarkDrag::KBookmarkDrag( const TQValueList<KBookmark> & bookmarks, const TQStrList & urls,
+ TQWidget * dragSource, const char * name )
+ : TQUriDrag( urls, dragSource, name ), m_bookmarks( bookmarks ), m_doc("xbel")
+{
+ // We need to create the XML for this drag right now and not
+ // in encodedData because when cutting a folder, the children
+ // wouldn't be part of the bookmarks anymore, when encodedData
+ // is requested.
+ TQDomElement elem = m_doc.createElement("xbel");
+ m_doc.appendChild( elem );
+ for ( TQValueListConstIterator<KBookmark> it = bookmarks.begin(); it != bookmarks.end(); ++it ) {
+ elem.appendChild( (*it).internalElement().cloneNode( true /* deep */ ) );
+ }
+ //kdDebug(7043) << "KBookmarkDrag::KBookmarkDrag " << m_doc.toString() << endl;
+}
+
+const char* KBookmarkDrag::format( int i ) const
+{
+ if ( i == 0 )
+ return "application/x-xbel";
+ else if ( i == 1 )
+ return "text/uri-list";
+ else if ( i == 2 )
+ return "text/plain";
+ else return 0;
+}
+
+TQByteArray KBookmarkDrag::encodedData( const char* mime ) const
+{
+ TQByteArray a;
+ TQCString mimetype( mime );
+ if ( mimetype == "text/uri-list" )
+ return TQUriDrag::encodedData( mime );
+ else if ( mimetype == "application/x-xbel" )
+ {
+ a = m_doc.toCString();
+ //kdDebug(7043) << "KBookmarkDrag::encodedData " << m_doc.toCString() << endl;
+ }
+ else if ( mimetype == "text/plain" )
+ {
+ KURL::List m_lstDragURLs;
+ if ( KURLDrag::decode( this, m_lstDragURLs ) )
+ {
+ TQStringList uris;
+ KURL::List::ConstIterator uit = m_lstDragURLs.begin();
+ KURL::List::ConstIterator uEnd = m_lstDragURLs.end();
+ for ( ; uit != uEnd ; ++uit )
+ uris.append( (*uit).prettyURL() );
+
+ TQCString s = uris.join( "\n" ).local8Bit();
+ a.resize( s.length() + 1 ); // trailing zero
+ memcpy( a.data(), s.data(), s.length() + 1 );
+ }
+ }
+ return a;
+}
+
+bool KBookmarkDrag::canDecode( const TQMimeSource * e )
+{
+ return e->provides("text/uri-list") || e->provides("application/x-xbel") ||
+ e->provides("text/plain");
+}
+
+TQValueList<KBookmark> KBookmarkDrag::decode( const TQMimeSource * e )
+{
+ TQValueList<KBookmark> bookmarks;
+ if ( e->provides("application/x-xbel") )
+ {
+ TQByteArray s( e->encodedData("application/x-xbel") );
+ //kdDebug(7043) << "KBookmarkDrag::decode s=" << TQCString(s) << endl;
+ TQDomDocument doc;
+ doc.setContent( s );
+ TQDomElement elem = doc.documentElement();
+ TQDomNodeList children = elem.childNodes();
+ for ( uint childno = 0; childno < children.count(); childno++)
+ {
+ bookmarks.append( KBookmark( children.item(childno).cloneNode(true).toElement() ));
+ }
+ return bookmarks;
+ }
+ if ( e->provides("text/uri-list") )
+ {
+ KURL::List m_lstDragURLs;
+ //kdDebug(7043) << "KBookmarkDrag::decode uri-list" << endl;
+ if ( KURLDrag::decode( e, m_lstDragURLs ) )
+ {
+ KURL::List::ConstIterator uit = m_lstDragURLs.begin();
+ KURL::List::ConstIterator uEnd = m_lstDragURLs.end();
+ for ( ; uit != uEnd ; ++uit )
+ {
+ //kdDebug(7043) << "KBookmarkDrag::decode url=" << (*uit).url() << endl;
+ bookmarks.append( KBookmark::standaloneBookmark(
+ (*uit).prettyURL(), (*uit) ));
+ }
+ return bookmarks;
+ }
+ }
+ if( e->provides("text/plain") )
+ {
+ //kdDebug(7043) << "KBookmarkDrag::decode text/plain" << endl;
+ TQString s;
+ if(TQTextDrag::decode( e, s ))
+ {
+
+ TQStringList listDragURLs = TQStringList::split(TQChar('\n'), s);
+ TQStringList::ConstIterator it = listDragURLs.begin();
+ TQStringList::ConstIterator end = listDragURLs.end();
+ for( ; it!=end; ++it)
+ {
+ //kdDebug(7043)<<"KBookmarkDrag::decode string"<<(*it)<<endl;
+ bookmarks.append( KBookmark::standaloneBookmark( KURL(*it).prettyURL(), KURL(*it)));
+ }
+ return bookmarks;
+ }
+ }
+ bookmarks.append( KBookmark() );
+ return bookmarks;
+}
diff --git a/tdeio/bookmarks/kbookmarkdrag.h b/tdeio/bookmarks/kbookmarkdrag.h
new file mode 100644
index 000000000..016bd6849
--- /dev/null
+++ b/tdeio/bookmarks/kbookmarkdrag.h
@@ -0,0 +1,57 @@
+// -*- c-basic-offset:4; indent-tabs-mode:nil -*-
+// vim: set ts=4 sts=4 sw=4 et:
+/* This file is part of the KDE libraries
+ Copyright (C) 2000 David Faure <faure@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 version 2 as published by the Free Software Foundation.
+
+ 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 __kebdrag_h
+#define __kebdrag_h
+
+#include <tqdragobject.h>
+#include <kbookmark.h>
+
+// Clipboard/dnd data : URLs + XML for bookmarks
+class TDEIO_EXPORT KBookmarkDrag : public TQUriDrag
+{
+public:
+ static KBookmarkDrag * newDrag( const TQValueList<KBookmark> & bookmarks,
+ TQWidget * dragSource = 0,
+ const char * name = 0 );
+ static KBookmarkDrag * newDrag( const KBookmark & bookmark,
+ TQWidget * dragSource = 0,
+ const char * name = 0 );
+protected:
+ KBookmarkDrag( const TQValueList<KBookmark> & bookmarks,
+ const TQStrList & urls,
+ TQWidget * dragSource,
+ const char * name );
+public:
+ virtual ~KBookmarkDrag() {}
+
+ virtual const char* format( int i ) const;
+ virtual TQByteArray encodedData( const char* mime ) const;
+
+ static bool canDecode( const TQMimeSource * e );
+ static TQValueList<KBookmark> decode( const TQMimeSource * e );
+
+protected:
+ TQValueList<KBookmark> m_bookmarks;
+ TQDomDocument m_doc;
+ class KBookmarkDragPrivate;
+ KBookmarkDragPrivate * d;
+};
+#endif
diff --git a/tdeio/bookmarks/kbookmarkexporter.cc b/tdeio/bookmarks/kbookmarkexporter.cc
new file mode 100644
index 000000000..30c52bdb8
--- /dev/null
+++ b/tdeio/bookmarks/kbookmarkexporter.cc
@@ -0,0 +1,32 @@
+// -*- c-basic-offset:4; indent-tabs-mode:nil -*-
+// vim: set ts=4 sts=4 sw=4 et:
+/* This file is part of the KDE libraries
+ Copyright (C) 2003 Alexander Kellett <lypanov@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 version 2 as published by the Free Software Foundation.
+
+ 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 <stdio.h>
+
+#include <tqfile.h>
+#include <tqtextcodec.h>
+#include <tqstylesheet.h>
+
+#include <kdebug.h>
+#include <klocale.h>
+
+#include "kbookmarkmanager.h"
+#include "kbookmarkexporter.h"
+
+// todo - put stuff in here :)
diff --git a/tdeio/bookmarks/kbookmarkexporter.h b/tdeio/bookmarks/kbookmarkexporter.h
new file mode 100644
index 000000000..68e8f475a
--- /dev/null
+++ b/tdeio/bookmarks/kbookmarkexporter.h
@@ -0,0 +1,50 @@
+// -*- c-basic-offset:4; indent-tabs-mode:nil -*-
+// vim: set ts=4 sts=4 sw=4 et:
+/* This file is part of the KDE libraries
+ Copyright (C) 1996-1998 Martin R. Jones <mjones@kde.org>
+ Copyright (C) 2000 David Faure <faure@kde.org>
+ Copyright (C) 2003 Alexander Kellett <lypanov@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 version 2 as published by the Free Software Foundation.
+
+ 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 __kbookmarkexporter_h
+#define __kbookmarkexporter_h
+
+#include <tqtextstream.h>
+#include <kbookmark.h>
+
+/**
+ * @since 3.2
+ */
+class TDEIO_EXPORT KBookmarkExporterBase
+{
+public:
+ KBookmarkExporterBase(KBookmarkManager* mgr, const TQString & fileName)
+ : m_fileName(fileName), m_pManager(mgr)
+ { ; }
+ virtual ~KBookmarkExporterBase() {}
+ virtual void write(KBookmarkGroup) = 0;
+protected:
+ TQString m_fileName;
+ KBookmarkManager* m_pManager;
+private:
+ class KBookmarkExporterBasePrivate *d;
+};
+
+// for SC
+#include "kbookmarkimporter_ns.h"
+
+#endif
diff --git a/tdeio/bookmarks/kbookmarkimporter.cc b/tdeio/bookmarks/kbookmarkimporter.cc
new file mode 100644
index 000000000..366802905
--- /dev/null
+++ b/tdeio/bookmarks/kbookmarkimporter.cc
@@ -0,0 +1,101 @@
+// -*- c-basic-offset:4; indent-tabs-mode:nil -*-
+// vim: set ts=4 sts=4 sw=4 et:
+/* This file is part of the KDE libraries
+ Copyright (C) 2003 Alexander Kellett <lypanov@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 version 2 as published by the Free Software Foundation.
+
+ 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 <tdefiledialog.h>
+#include <kstringhandler.h>
+#include <klocale.h>
+#include <kdebug.h>
+#include <kcharsets.h>
+#include <tqtextcodec.h>
+
+#include <sys/types.h>
+#include <stddef.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <assert.h>
+
+#include "kbookmarkmanager.h"
+
+#include "kbookmarkimporter_ns.h"
+#include "kbookmarkimporter_opera.h"
+#include "kbookmarkimporter_ie.h"
+
+#include "kbookmarkimporter.h"
+
+void KXBELBookmarkImporterImpl::parse()
+{
+ //kdDebug() << "KXBELBookmarkImporterImpl::parse()" << endl;
+ KBookmarkManager *manager = KBookmarkManager::managerForFile(m_fileName);
+ KBookmarkGroup root = manager->root();
+ traverse(root);
+ // FIXME delete it!
+ // delete manager;
+}
+
+void KXBELBookmarkImporterImpl::visit(const KBookmark &bk)
+{
+ //kdDebug() << "KXBELBookmarkImporterImpl::visit" << endl;
+ if (bk.isSeparator())
+ emit newSeparator();
+ else
+ emit newBookmark(bk.fullText(), bk.url().url().utf8(), "");
+}
+
+void KXBELBookmarkImporterImpl::visitEnter(const KBookmarkGroup &grp)
+{
+ //kdDebug() << "KXBELBookmarkImporterImpl::visitEnter" << endl;
+ emit newFolder(grp.fullText(), false, "");
+}
+
+void KXBELBookmarkImporterImpl::visitLeave(const KBookmarkGroup &)
+{
+ //kdDebug() << "KXBELBookmarkImporterImpl::visitLeave" << endl;
+ emit endFolder();
+}
+
+void KBookmarkImporterBase::setupSignalForwards(TQObject *src, TQObject *dst)
+{
+ connect(src, TQT_SIGNAL( newBookmark( const TQString &, const TQCString &, const TQString & ) ),
+ dst, TQT_SIGNAL( newBookmark( const TQString &, const TQCString &, const TQString & ) ));
+ connect(src, TQT_SIGNAL( newFolder( const TQString &, bool, const TQString & ) ),
+ dst, TQT_SIGNAL( newFolder( const TQString &, bool, const TQString & ) ));
+ connect(src, TQT_SIGNAL( newSeparator() ),
+ dst, TQT_SIGNAL( newSeparator() ) );
+ connect(src, TQT_SIGNAL( endFolder() ),
+ dst, TQT_SIGNAL( endFolder() ) );
+}
+
+KBookmarkImporterBase* KBookmarkImporterBase::factory( const TQString &type )
+{
+ if (type == "netscape")
+ return new KNSBookmarkImporterImpl;
+ else if (type == "mozilla")
+ return new KMozillaBookmarkImporterImpl;
+ else if (type == "xbel")
+ return new KXBELBookmarkImporterImpl;
+ else if (type == "ie")
+ return new KIEBookmarkImporterImpl;
+ else if (type == "opera")
+ return new KOperaBookmarkImporterImpl;
+ else
+ return 0;
+}
+
+#include <kbookmarkimporter.moc>
diff --git a/tdeio/bookmarks/kbookmarkimporter.h b/tdeio/bookmarks/kbookmarkimporter.h
new file mode 100644
index 000000000..cc87b2004
--- /dev/null
+++ b/tdeio/bookmarks/kbookmarkimporter.h
@@ -0,0 +1,106 @@
+// -*- c-basic-offset:4; indent-tabs-mode:nil -*-
+// vim: set ts=4 sts=4 sw=4 et:
+/* This file is part of the KDE libraries
+ Copyright (C) 2000 David Faure <faure@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 version 2 as published by the Free Software Foundation.
+
+ 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 __kbookmarkimporter_h
+#define __kbookmarkimporter_h
+
+#include <tqdom.h>
+#include <tqcstring.h>
+#include <tqstringlist.h>
+#include <ksimpleconfig.h>
+
+#include "kbookmark.h"
+
+/**
+ * A class for importing NS bookmarks
+ * KEditBookmarks uses it to insert bookmarks into its DOM tree,
+ * and KActionMenu uses it to create actions directly.
+ * @since 3.2
+ */
+class TDEIO_EXPORT KBookmarkImporterBase : public TQObject
+{
+ Q_OBJECT
+public:
+ KBookmarkImporterBase() {}
+ virtual ~KBookmarkImporterBase() {}
+
+ void setFilename(const TQString &filename) { m_fileName = filename; }
+
+ virtual void parse() = 0;
+ virtual TQString findDefaultLocation(bool forSaving = false) const = 0;
+
+ // TODO - make this static?
+ void setupSignalForwards(TQObject *src, TQObject *dst);
+ static KBookmarkImporterBase *factory(const TQString &type);
+
+signals:
+ /**
+ * Notify about a new bookmark
+ * Use "html" for the icon
+ */
+ void newBookmark(const TQString & text, const TQCString & url, const TQString & additionalInfo);
+
+ /**
+ * Notify about a new folder
+ * Use "bookmark_folder" for the icon
+ */
+ void newFolder(const TQString & text, bool open, const TQString & additionalInfo);
+
+ /**
+ * Notify about a new separator
+ */
+ void newSeparator();
+
+ /**
+ * Tell the outside world that we're going down
+ * one menu
+ */
+ void endFolder();
+
+protected:
+ TQString m_fileName;
+
+private:
+ class KBookmarkImporterBasePrivate *d;
+};
+
+/**
+ * A class for importing XBEL files
+ */
+class TDEIO_EXPORT KXBELBookmarkImporterImpl : public KBookmarkImporterBase, protected KBookmarkGroupTraverser
+{
+ Q_OBJECT
+public:
+ KXBELBookmarkImporterImpl() {}
+ virtual void parse();
+ virtual TQString findDefaultLocation(bool = false) const { return TQString::null; }
+protected:
+ virtual void visit(const KBookmark &);
+ virtual void visitEnter(const KBookmarkGroup &);
+ virtual void visitLeave(const KBookmarkGroup &);
+private:
+ class KXBELBookmarkImporterImplPrivate *d;
+};
+
+// for SC
+#include "kbookmarkimporter_ns.h"
+#include "kbookmarkimporter_kde1.h"
+
+#endif
diff --git a/tdeio/bookmarks/kbookmarkimporter_crash.cc b/tdeio/bookmarks/kbookmarkimporter_crash.cc
new file mode 100644
index 000000000..b2871eecd
--- /dev/null
+++ b/tdeio/bookmarks/kbookmarkimporter_crash.cc
@@ -0,0 +1,215 @@
+// -*- c-basic-offset:4; indent-tabs-mode:nil -*-
+// vim: set ts=4 sts=4 sw=4 et:
+/* This file is part of the KDE libraries
+ Copyright (C) 2002-2003 Alexander Kellett <lypanov@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 version 2 as published by the Free Software Foundation.
+
+ 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 "kbookmarkimporter_crash.h"
+
+#include <tdefiledialog.h>
+#include <kstringhandler.h>
+#include <klocale.h>
+#include <kdebug.h>
+#include <kapplication.h>
+#include <kstandarddirs.h>
+#include <tqfile.h>
+#include <tqdir.h>
+#include <tqstring.h>
+#include <tqtextcodec.h>
+#include <dcopclient.h>
+
+#include <sys/types.h>
+#include <stddef.h>
+#include <dirent.h>
+#include <sys/stat.h>
+
+typedef TQMap<TQString, TQString> ViewMap;
+
+// KDE 4.0: remove this BC keeping stub
+void KCrashBookmarkImporter::parseCrashLog( TQString /*filename*/, bool /*del*/ )
+{
+ ;
+}
+
+ViewMap KCrashBookmarkImporterImpl::parseCrashLog_noemit( const TQString & filename, bool del )
+{
+ static const int g_lineLimit = 16*1024;
+
+ TQFile f( filename );
+ ViewMap views;
+
+ if ( !f.open( IO_ReadOnly ) )
+ return views;
+
+ TQCString s( g_lineLimit );
+
+ TQTextCodec * codec = TQTextCodec::codecForName( "UTF-8" );
+ Q_ASSERT( codec );
+ if ( !codec )
+ return views;
+
+ while ( f.readLine( s.data(), g_lineLimit ) >=0 )
+ {
+ if ( s[s.length()-1] != '\n' )
+ {
+ kdWarning() << "Crash bookmarks contain a line longer than " << g_lineLimit << ". Skipping." << endl;
+ continue;
+ }
+ TQString t = codec->toUnicode( s.stripWhiteSpace() );
+ TQRegExp rx( "(.*)\\((.*)\\):(.*)$" );
+ rx.setMinimal( true );
+ if ( !rx.exactMatch( t ) )
+ continue;
+ if ( rx.cap(1) == "opened" )
+ views[rx.cap(2)] = rx.cap(3);
+ else if ( rx.cap(1) == "close" )
+ views.remove( rx.cap(2) );
+ }
+
+ f.close();
+
+ if ( del )
+ f.remove();
+
+ return views;
+}
+
+TQStringList KCrashBookmarkImporter::getCrashLogs()
+{
+ return KCrashBookmarkImporterImpl::getCrashLogs();
+}
+
+TQStringList KCrashBookmarkImporterImpl::getCrashLogs()
+{
+ TQMap<TQString, bool> activeLogs;
+
+ DCOPClient* dcop = kapp->dcopClient();
+
+ QCStringList apps = dcop->registeredApplications();
+ for ( QCStringList::Iterator it = apps.begin(); it != apps.end(); ++it )
+ {
+ TQCString &clientId = *it;
+
+ if ( tqstrncmp(clientId, "konqueror", 9) != 0 )
+ continue;
+
+ TQByteArray data, replyData;
+ TQCString replyType;
+ TQDataStream arg( data, IO_WriteOnly );
+
+ if ( !dcop->call( clientId.data(), "KonquerorIface",
+ "crashLogFile()", data, replyType, replyData) )
+ {
+ kdWarning() << "can't find dcop function KonquerorIface::crashLogFile()" << endl;
+ continue;
+ }
+
+ if ( replyType != "TQString" )
+ continue;
+
+ TQDataStream reply( replyData, IO_ReadOnly );
+ TQString ret;
+ reply >> ret;
+ activeLogs[ret] = true;
+ }
+
+ TQDir d( KCrashBookmarkImporterImpl().findDefaultLocation() );
+ d.setSorting( TQDir::Time );
+ d.setFilter( TQDir::Files );
+ d.setNameFilter( "konqueror-crash-*.log" );
+
+ const TQFileInfoList *list = d.entryInfoList();
+ TQFileInfoListIterator it( *list );
+
+ TQFileInfo *fi;
+ TQStringList crashFiles;
+
+ int count = 0;
+ for ( ; (( fi = it.current() ) != 0) && (count < 20); ++it, ++count )
+ {
+ bool stillAlive = activeLogs.contains( fi->absFilePath() );
+ if ( !stillAlive )
+ crashFiles << fi->absFilePath();
+ }
+ // Delete remaining ones
+ for ( ; ( fi = it.current() ) != 0; ++it )
+ {
+ TQFile::remove( fi->absFilePath() );
+ }
+
+ return crashFiles;
+}
+
+void KCrashBookmarkImporterImpl::parse()
+{
+ TQDict<bool> signatureMap;
+ TQStringList crashFiles = KCrashBookmarkImporterImpl::getCrashLogs();
+ int count = 1;
+ for ( TQStringList::Iterator it = crashFiles.begin(); it != crashFiles.end(); ++it )
+ {
+ ViewMap views;
+ views = parseCrashLog_noemit( *it, m_shouldDelete );
+ TQString signature;
+ for ( ViewMap::Iterator vit = views.begin(); vit != views.end(); ++vit )
+ signature += "|"+vit.data();
+ if (signatureMap[signature])
+ {
+ // Duplicate... throw away and skip
+ TQFile::remove(*it);
+ continue;
+ }
+
+ signatureMap.insert(signature, (bool *) true); // hack
+
+ int outerFolder = ( crashFiles.count() > 1 ) && (views.count() > 0);
+ if ( outerFolder )
+ emit newFolder( TQString("Konqueror Window %1").arg(count++), false, "" );
+ for ( ViewMap::Iterator vit = views.begin(); vit != views.end(); ++vit )
+ emit newBookmark( vit.data(), vit.data().latin1(), TQString("") );
+ if ( outerFolder )
+ emit endFolder();
+ }
+}
+
+TQString KCrashBookmarkImporter::crashBookmarksDir()
+{
+ static KCrashBookmarkImporterImpl *p = 0;
+ if (!p)
+ p = new KCrashBookmarkImporterImpl;
+ return p->findDefaultLocation();
+}
+
+void KCrashBookmarkImporterImpl::setShouldDelete( bool shouldDelete )
+{
+ m_shouldDelete = shouldDelete;
+}
+
+void KCrashBookmarkImporter::parseCrashBookmarks( bool del )
+{
+ KCrashBookmarkImporterImpl importer;
+ importer.setFilename( m_fileName );
+ importer.setShouldDelete( del );
+ importer.setupSignalForwards( &importer, this );
+ importer.parse();
+}
+
+TQString KCrashBookmarkImporterImpl::findDefaultLocation( bool ) const
+{
+ return locateLocal( "tmp", "" );
+}
+
+#include "kbookmarkimporter_crash.moc"
diff --git a/tdeio/bookmarks/kbookmarkimporter_crash.h b/tdeio/bookmarks/kbookmarkimporter_crash.h
new file mode 100644
index 000000000..f4fc9af32
--- /dev/null
+++ b/tdeio/bookmarks/kbookmarkimporter_crash.h
@@ -0,0 +1,74 @@
+// -*- c-basic-offset:4; indent-tabs-mode:nil -*-
+// vim: set ts=4 sts=4 sw=4 et:
+/* This file is part of the KDE libraries
+ Copyright (C) 2002 Alexander Kellett <lypanov@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 version 2 as published by the Free Software Foundation.
+
+ 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 __kbookmarkimporter_crash_h
+#define __kbookmarkimporter_crash_h
+
+#include <tqdom.h>
+#include <tqcstring.h>
+#include <tqstringlist.h>
+#include <tqmap.h>
+#include <ksimpleconfig.h>
+#include <kdemacros.h>
+
+#include "kbookmarkimporter.h"
+
+/**
+ * A class for importing all crash sessions as bookmarks
+ * @deprecated
+ */
+class TDEIO_EXPORT_DEPRECATED KCrashBookmarkImporter : public TQObject
+{
+ Q_OBJECT
+public:
+ KCrashBookmarkImporter( const TQString & fileName ) : m_fileName(fileName) {}
+ ~KCrashBookmarkImporter() {}
+ void parseCrashBookmarks( bool del = true );
+ static TQString crashBookmarksDir( );
+ static TQStringList getCrashLogs(); // EMPTY!
+signals:
+ void newBookmark( const TQString & text, const TQCString & url, const TQString & additionalInfo );
+ void newFolder( const TQString & text, bool open, const TQString & additionalInfo );
+ void newSeparator();
+ void endFolder();
+protected:
+ TQString m_fileName;
+ void parseCrashLog( TQString filename, bool del ); // EMPTY!
+};
+
+/**
+ * A class for importing all crash sessions as bookmarks
+ * @since 3.2
+ */
+class TDEIO_EXPORT KCrashBookmarkImporterImpl : public KBookmarkImporterBase
+{
+public:
+ KCrashBookmarkImporterImpl() : m_shouldDelete(false) { }
+ void setShouldDelete(bool);
+ virtual void parse();
+ virtual TQString findDefaultLocation(bool forSaving = false) const;
+ static TQStringList getCrashLogs();
+private:
+ bool m_shouldDelete;
+ TQMap<TQString, TQString> parseCrashLog_noemit( const TQString & filename, bool del );
+ class KCrashBookmarkImporterImplPrivate *d;
+};
+
+#endif
diff --git a/tdeio/bookmarks/kbookmarkimporter_ie.cc b/tdeio/bookmarks/kbookmarkimporter_ie.cc
new file mode 100644
index 000000000..092ebe596
--- /dev/null
+++ b/tdeio/bookmarks/kbookmarkimporter_ie.cc
@@ -0,0 +1,185 @@
+// -*- c-basic-offset:4; indent-tabs-mode:nil -*-
+// vim: set ts=4 sts=4 sw=4 et:
+/* This file is part of the KDE libraries
+ Copyright (C) 2002-2003 Alexander Kellett <lypanov@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 version 2 as published by the Free Software Foundation.
+
+ 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 <tdefiledialog.h>
+#include <kstringhandler.h>
+#include <klocale.h>
+#include <kdebug.h>
+#include <tqtextcodec.h>
+
+#include <sys/types.h>
+#include <stddef.h>
+#include <dirent.h>
+#include <sys/stat.h>
+
+#include "kbookmarkimporter.h"
+#include "kbookmarkimporter_ie.h"
+
+/* antlarr: KDE 4: Make them const TQString & */
+void KIEBookmarkImporter::parseIEBookmarks_url_file( TQString filename, TQString name ) {
+ static const int g_lineLimit = 16*1024;
+
+ TQFile f(filename);
+
+ if(f.open(IO_ReadOnly)) {
+
+ TQCString s(g_lineLimit);
+
+ while(f.readLine(s.data(), g_lineLimit)>=0) {
+ if ( s[s.length()-1] != '\n' ) // Gosh, this line is longer than g_lineLimit. Skipping.
+ {
+ kdWarning() << "IE bookmarks contain a line longer than " << g_lineLimit << ". Skipping." << endl;
+ continue;
+ }
+ TQCString t = s.stripWhiteSpace();
+ TQRegExp rx( "URL=(.*)" );
+ if (rx.exactMatch(t)) {
+ emit newBookmark( name, TQString(rx.cap(1)).latin1(), TQString("") );
+ }
+ }
+
+ f.close();
+ }
+}
+
+/* antlarr: KDE 4: Make them const TQString & */
+void KIEBookmarkImporter::parseIEBookmarks_dir( TQString dirname, TQString foldername )
+{
+
+ TQDir dir(dirname);
+ dir.setFilter( TQDir::Files | TQDir::Dirs );
+ dir.setSorting( TQDir::Name | TQDir::DirsFirst );
+ dir.setNameFilter("*.url"); // AK - possibly add ";index.ini" ?
+ dir.setMatchAllDirs(true);
+
+ const TQFileInfoList *list = dir.entryInfoList();
+ if (!list) return;
+
+ if (dirname != m_fileName)
+ emit newFolder( foldername, false, "" );
+
+ TQFileInfoListIterator it( *list );
+ TQFileInfo *fi;
+
+ while ( (fi = it.current()) != 0 ) {
+ ++it;
+
+ if (fi->fileName() == "." || fi->fileName() == "..") continue;
+
+ if (fi->isDir()) {
+ parseIEBookmarks_dir(fi->absFilePath(), fi->fileName());
+
+ } else if (fi->isFile()) {
+ if (fi->fileName().endsWith(".url")) {
+ TQString name = fi->fileName();
+ name.truncate(name.length() - 4); // .url
+ parseIEBookmarks_url_file(fi->absFilePath(), name);
+ }
+ // AK - add index.ini
+ }
+ }
+
+ if (dirname != m_fileName)
+ emit endFolder();
+}
+
+
+void KIEBookmarkImporter::parseIEBookmarks( )
+{
+ parseIEBookmarks_dir( m_fileName );
+}
+
+TQString KIEBookmarkImporter::IEBookmarksDir()
+{
+ static KIEBookmarkImporterImpl* p = 0;
+ if (!p)
+ p = new KIEBookmarkImporterImpl;
+ return p->findDefaultLocation();
+}
+
+void KIEBookmarkImporterImpl::parse() {
+ KIEBookmarkImporter importer(m_fileName);
+ setupSignalForwards(&importer, this);
+ importer.parseIEBookmarks();
+}
+
+TQString KIEBookmarkImporterImpl::findDefaultLocation(bool) const
+{
+ // notify user that they must give a new dir such
+ // as "Favourites" as otherwise it'll just place
+ // lots of .url files in the given dir and gui
+ // stuff in the exporter is ugly so that exclues
+ // the possibility of just writing to Favourites
+ // and checking if overwriting...
+ return KFileDialog::getExistingDirectory();
+}
+
+/////////////////////////////////////////////////
+
+class IEExporter : private KBookmarkGroupTraverser {
+public:
+ IEExporter( const TQString & );
+ void write( const KBookmarkGroup &grp ) { traverse(grp); };
+private:
+ virtual void visit( const KBookmark & );
+ virtual void visitEnter( const KBookmarkGroup & );
+ virtual void visitLeave( const KBookmarkGroup & );
+private:
+ TQDir m_currentDir;
+};
+
+static TQString ieStyleQuote( const TQString &str ) {
+ TQString s(str);
+ s.replace(TQRegExp("[/\\:*?\"<>|]"), "_");
+ return s;
+}
+
+IEExporter::IEExporter( const TQString & dname ) {
+ m_currentDir.setPath( dname );
+}
+
+void IEExporter::visit( const KBookmark &bk ) {
+ TQString fname = m_currentDir.path() + "/" + ieStyleQuote( bk.fullText() ) + ".url";
+ // kdDebug() << "visit(" << bk.text() << "), fname == " << fname << endl;
+ TQFile file( fname );
+ file.open( IO_WriteOnly );
+ TQTextStream ts( &file );
+ ts << "[InternetShortcut]\r\n";
+ ts << "URL=" << bk.url().url().utf8() << "\r\n";
+}
+
+void IEExporter::visitEnter( const KBookmarkGroup &grp ) {
+ TQString dname = m_currentDir.path() + "/" + ieStyleQuote( grp.fullText() );
+ // kdDebug() << "visitEnter(" << grp.text() << "), dname == " << dname << endl;
+ m_currentDir.mkdir( dname );
+ m_currentDir.cd( dname );
+}
+
+void IEExporter::visitLeave( const KBookmarkGroup & ) {
+ // kdDebug() << "visitLeave()" << endl;
+ m_currentDir.cdUp();
+}
+
+void KIEBookmarkExporterImpl::write(KBookmarkGroup parent) {
+ IEExporter exporter( m_fileName );
+ exporter.write( parent );
+}
+
+#include "kbookmarkimporter_ie.moc"
diff --git a/tdeio/bookmarks/kbookmarkimporter_ie.h b/tdeio/bookmarks/kbookmarkimporter_ie.h
new file mode 100644
index 000000000..b1b7c651c
--- /dev/null
+++ b/tdeio/bookmarks/kbookmarkimporter_ie.h
@@ -0,0 +1,90 @@
+// -*- c-basic-offset:4; indent-tabs-mode:nil -*-
+// vim: set ts=4 sts=4 sw=4 et:
+/* This file is part of the KDE libraries
+ Copyright (C) 2002 Alexander Kellett <lypanov@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 version 2 as published by the Free Software Foundation.
+
+ 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 __kbookmarkimporter_ie_h
+#define __kbookmarkimporter_ie_h
+
+#include <tqdom.h>
+#include <tqcstring.h>
+#include <tqstringlist.h>
+#include <ksimpleconfig.h>
+#include <kdemacros.h>
+
+#include <kbookmarkimporter.h>
+
+/**
+ * A class for importing IE bookmarks
+ * @deprecated
+ */
+class TDEIO_EXPORT_DEPRECATED KIEBookmarkImporter : public TQObject
+{
+ Q_OBJECT
+public:
+ KIEBookmarkImporter( const TQString & fileName ) : m_fileName(fileName) {}
+ ~KIEBookmarkImporter() {}
+
+ void parseIEBookmarks();
+
+ // Usual place for IE bookmarks
+ static TQString IEBookmarksDir();
+
+signals:
+ void newBookmark( const TQString & text, const TQCString & url, const TQString & additionalInfo );
+ void newFolder( const TQString & text, bool open, const TQString & additionalInfo );
+ void newSeparator();
+ void endFolder();
+
+protected:
+ void parseIEBookmarks_dir( TQString dirname, TQString name = TQString::null );
+ void parseIEBookmarks_url_file( TQString filename, TQString name );
+
+ TQString m_fileName;
+};
+
+/**
+ * A class for importing IE bookmarks
+ * @since 3.2
+ */
+class TDEIO_EXPORT KIEBookmarkImporterImpl : public KBookmarkImporterBase
+{
+public:
+ KIEBookmarkImporterImpl() { }
+ virtual void parse();
+ virtual TQString findDefaultLocation(bool forSaving = false) const;
+private:
+ class KIEBookmarkImporterImplPrivate *d;
+};
+
+/*
+ * @since 3.2
+ */
+class TDEIO_EXPORT KIEBookmarkExporterImpl : public KBookmarkExporterBase
+{
+public:
+ KIEBookmarkExporterImpl(KBookmarkManager* mgr, const TQString & path)
+ : KBookmarkExporterBase(mgr, path)
+ { ; }
+ virtual ~KIEBookmarkExporterImpl() {}
+ virtual void write(KBookmarkGroup);
+private:
+ class KIEBookmarkExporterImplPrivate *d;
+};
+
+#endif
diff --git a/tdeio/bookmarks/kbookmarkimporter_kde1.cc b/tdeio/bookmarks/kbookmarkimporter_kde1.cc
new file mode 100644
index 000000000..6aca22b84
--- /dev/null
+++ b/tdeio/bookmarks/kbookmarkimporter_kde1.cc
@@ -0,0 +1,156 @@
+// -*- c-basic-offset:4; indent-tabs-mode:nil -*-
+// vim: set ts=4 sts=4 sw=4 et:
+/* This file is part of the KDE libraries
+ Copyright (C) 2000 David Faure <faure@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 version 2 as published by the Free Software Foundation.
+
+ 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 "kbookmarkimporter_kde1.h"
+#include <tdefiledialog.h>
+#include <kstringhandler.h>
+#include <klocale.h>
+#include <kdebug.h>
+#include <kcharsets.h>
+#include <tqtextcodec.h>
+
+#include <sys/types.h>
+#include <stddef.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <assert.h>
+
+////////////////////
+
+void KBookmarkImporter::import( const TQString & path )
+{
+ TQDomElement elem = m_pDoc->documentElement();
+ Q_ASSERT(!elem.isNull());
+ scanIntern( elem, path );
+}
+
+void KBookmarkImporter::scanIntern( TQDomElement & parentElem, const TQString & _path )
+{
+ kdDebug(7043) << "KBookmarkImporter::scanIntern " << _path << endl;
+ // Substitute all symbolic links in the path
+ TQDir dir( _path );
+ TQString canonical = dir.canonicalPath();
+
+ if ( m_lstParsedDirs.contains(canonical) )
+ {
+ kdWarning() << "Directory " << canonical << " already parsed" << endl;
+ return;
+ }
+
+ m_lstParsedDirs.append( canonical );
+
+ DIR *dp;
+ struct dirent *ep;
+ dp = opendir( TQFile::encodeName(_path) );
+ if ( dp == 0L )
+ return;
+
+ // Loop thru all directory entries
+ while ( ( ep = readdir( dp ) ) != 0L )
+ {
+ if ( strcmp( ep->d_name, "." ) != 0 && strcmp( ep->d_name, ".." ) != 0 )
+ {
+ KURL file;
+ file.setPath( TQString( _path ) + '/' + TQFile::decodeName(ep->d_name) );
+
+ KMimeType::Ptr res = KMimeType::findByURL( file, 0, true );
+ //kdDebug(7043) << " - " << file.url() << " -> " << res->name() << endl;
+
+ if ( res->name() == "inode/directory" )
+ {
+ // We could use KBookmarkGroup::createNewFolder, but then it
+ // would notify about the change, so we'd need a flag, etc.
+ TQDomElement groupElem = m_pDoc->createElement( "folder" );
+ parentElem.appendChild( groupElem );
+ TQDomElement textElem = m_pDoc->createElement( "title" );
+ groupElem.appendChild( textElem );
+ textElem.appendChild( m_pDoc->createTextNode( TDEIO::decodeFileName( ep->d_name ) ) );
+ if ( TDEIO::decodeFileName( ep->d_name ) == "Toolbar" )
+ groupElem.setAttribute("toolbar","yes");
+ scanIntern( groupElem, file.path() );
+ }
+ else if ( (res->name() == "application/x-desktop")
+ || (res->name() == "media/builtin-mydocuments")
+ || (res->name() == "media/builtin-mycomputer")
+ || (res->name() == "media/builtin-mynetworkplaces")
+ || (res->name() == "media/builtin-printers")
+ || (res->name() == "media/builtin-trash")
+ || (res->name() == "media/builtin-webbrowser") )
+ {
+ KSimpleConfig cfg( file.path(), true );
+ cfg.setDesktopGroup();
+ TQString type = cfg.readEntry( "Type" );
+ // Is it really a bookmark file ?
+ if ( type == "Link" )
+ parseBookmark( parentElem, ep->d_name, cfg, 0 /* desktop group */ );
+ else
+ kdWarning(7043) << " Not a link ? Type=" << type << endl;
+ }
+ else if ( res->name() == "text/plain")
+ {
+ // maybe its an IE Favourite..
+ KSimpleConfig cfg( file.path(), true );
+ TQStringList grp = cfg.groupList().grep( "internetshortcut", false );
+ if ( grp.count() == 0 )
+ continue;
+ cfg.setGroup( *grp.begin() );
+
+ TQString url = cfg.readPathEntry("URL");
+ if (!url.isEmpty() )
+ parseBookmark( parentElem, ep->d_name, cfg, *grp.begin() );
+ } else
+ kdWarning(7043) << "Invalid bookmark : found mimetype='" << res->name() << "' for file='" << file.path() << "'!" << endl;
+ }
+ }
+
+ closedir( dp );
+}
+
+void KBookmarkImporter::parseBookmark( TQDomElement & parentElem, TQCString _text,
+ KSimpleConfig& _cfg, const TQString &_group )
+{
+ if ( !_group.isEmpty() )
+ _cfg.setGroup( _group );
+ else
+ _cfg.setDesktopGroup();
+
+ TQString url = _cfg.readPathEntry( "URL" );
+ TQString icon = _cfg.readEntry( "Icon" );
+ if (icon.right( 4 ) == ".xpm" ) // prevent warnings
+ icon.truncate( icon.length() - 4 );
+
+ TQString text = TDEIO::decodeFileName( TQString::fromLocal8Bit(_text) );
+ if ( text.length() > 8 && text.right( 8 ) == ".desktop" )
+ text.truncate( text.length() - 8 );
+ if ( text.length() > 7 && text.right( 7 ) == ".kdelnk" )
+ text.truncate( text.length() - 7 );
+
+ TQDomElement elem = m_pDoc->createElement( "bookmark" );
+ parentElem.appendChild( elem );
+ elem.setAttribute( "href", url );
+ //if ( icon != "www" ) // No need to save the default
+ // Hmm, after all, it makes KBookmark::pixmapFile faster,
+ // and it shows a nice feature to those reading the file
+ elem.setAttribute( "icon", icon );
+ TQDomElement textElem = m_pDoc->createElement( "title" );
+ elem.appendChild( textElem );
+ textElem.appendChild( m_pDoc->createTextNode( text ) );
+ kdDebug(7043) << "KBookmarkImporter::parseBookmark text=" << text << endl;
+}
diff --git a/tdeio/bookmarks/kbookmarkimporter_kde1.h b/tdeio/bookmarks/kbookmarkimporter_kde1.h
new file mode 100644
index 000000000..5af4f04e9
--- /dev/null
+++ b/tdeio/bookmarks/kbookmarkimporter_kde1.h
@@ -0,0 +1,49 @@
+// -*- c-basic-offset:4; indent-tabs-mode:nil -*-
+// vim: set ts=4 sts=4 sw=4 et:
+/* This file is part of the KDE libraries
+ Copyright (C) 2000 David Faure <faure@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 version 2 as published by the Free Software Foundation.
+
+ 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 __kbookmarkimporter_kde1_h
+#define __kbookmarkimporter_kde1_h
+
+#include <tqdom.h>
+#include <tqcstring.h>
+#include <tqstringlist.h>
+#include <ksimpleconfig.h>
+
+/**
+ * A class for importing the previous bookmarks (desktop files)
+ * Separated from KBookmarkManager to save memory (we throw this one
+ * out once the import is done)
+ */
+class TDEIO_EXPORT KBookmarkImporter
+{
+public:
+ KBookmarkImporter( TQDomDocument * doc ) : m_pDoc(doc) {}
+
+ void import( const TQString & path );
+
+private:
+ void scanIntern( TQDomElement & parentElem, const TQString & _path );
+ void parseBookmark( TQDomElement & parentElem, TQCString _text,
+ KSimpleConfig& _cfg, const TQString &_group );
+ TQDomDocument * m_pDoc;
+ TQStringList m_lstParsedDirs;
+};
+
+#endif
diff --git a/tdeio/bookmarks/kbookmarkimporter_ns.cc b/tdeio/bookmarks/kbookmarkimporter_ns.cc
new file mode 100644
index 000000000..8ce06a79b
--- /dev/null
+++ b/tdeio/bookmarks/kbookmarkimporter_ns.cc
@@ -0,0 +1,243 @@
+// -*- c-basic-offset:4; indent-tabs-mode:nil -*-
+// vim: set ts=4 sts=4 sw=4 et:
+/* This file is part of the KDE libraries
+ Copyright (C) 1996-1998 Martin R. Jones <mjones@kde.org>
+ Copyright (C) 2000 David Faure <faure@kde.org>
+ Copyright (C) 2003 Alexander Kellett <lypanov@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 version 2 as published by the Free Software Foundation.
+
+ 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 "kbookmarkimporter.h"
+#include "kbookmarkexporter.h"
+#include "kbookmarkmanager.h"
+#include <tdefiledialog.h>
+#include <kstringhandler.h>
+#include <klocale.h>
+#include <kdebug.h>
+#include <kcharsets.h>
+#include <tqtextcodec.h>
+#include <tqstylesheet.h>
+
+#include <sys/types.h>
+#include <stddef.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <assert.h>
+
+void KNSBookmarkImporterImpl::parse()
+{
+ TQFile f(m_fileName);
+ TQTextCodec * codec = m_utf8 ? TQTextCodec::codecForName("UTF-8") : TQTextCodec::codecForLocale();
+ Q_ASSERT(codec);
+ if (!codec)
+ return;
+
+ if(f.open(IO_ReadOnly)) {
+
+ static const int g_lineLimit = 16*1024;
+ TQCString s(g_lineLimit);
+ // skip header
+ while(f.readLine(s.data(), g_lineLimit) >= 0 && !s.contains("<DL>"));
+
+ while(f.readLine(s.data(), g_lineLimit)>=0) {
+ if ( s[s.length()-1] != '\n' ) // Gosh, this line is longer than g_lineLimit. Skipping.
+ {
+ kdWarning() << "Netscape bookmarks contain a line longer than " << g_lineLimit << ". Skipping." << endl;
+ continue;
+ }
+ TQCString t = s.stripWhiteSpace();
+ if(t.left(12).upper() == "<DT><A HREF=" ||
+ t.left(16).upper() == "<DT><H3><A HREF=") {
+ int firstQuotes = t.find('"')+1;
+ int secondQuotes = t.find('"', firstQuotes);
+ if (firstQuotes != -1 && secondQuotes != -1)
+ {
+ TQCString link = t.mid(firstQuotes, secondQuotes-firstQuotes);
+ int endTag = t.find('>', secondQuotes+1);
+ TQCString name = t.mid(endTag+1);
+ name = name.left(name.findRev('<'));
+ if ( name.right(4) == "</A>" )
+ name = name.left( name.length() - 4 );
+ TQString qname = KCharsets::resolveEntities( codec->toUnicode( name ) );
+ TQCString additionalInfo = t.mid( secondQuotes+1, endTag-secondQuotes-1 );
+
+ emit newBookmark( qname,
+ link, codec->toUnicode(additionalInfo) );
+ }
+ }
+ else if(t.left(7).upper() == "<DT><H3") {
+ int endTag = t.find('>', 7);
+ TQCString name = t.mid(endTag+1);
+ name = name.left(name.findRev('<'));
+ TQString qname = KCharsets::resolveEntities( codec->toUnicode( name ) );
+ TQCString additionalInfo = t.mid( 8, endTag-8 );
+ bool folded = (additionalInfo.left(6) == "FOLDED");
+ if (folded) additionalInfo.remove(0,7);
+
+ emit newFolder( qname,
+ !folded,
+ codec->toUnicode(additionalInfo) );
+ }
+ else if(t.left(4).upper() == "<HR>")
+ emit newSeparator();
+ else if(t.left(8).upper() == "</DL><P>")
+ emit endFolder();
+ }
+
+ f.close();
+ }
+}
+
+TQString KNSBookmarkImporterImpl::findDefaultLocation(bool forSaving) const
+{
+ if (m_utf8)
+ {
+ if ( forSaving )
+ return KFileDialog::getSaveFileName( TQDir::homeDirPath() + "/.mozilla",
+ i18n("*.html|HTML Files (*.html)") );
+ else
+ return KFileDialog::getOpenFileName( TQDir::homeDirPath() + "/.mozilla",
+ i18n("*.html|HTML Files (*.html)") );
+ }
+ else
+ {
+ return TQDir::homeDirPath() + "/.netscape/bookmarks.html";
+ }
+}
+
+////////////////////////////////////////////////////////////////
+
+
+void KNSBookmarkImporter::parseNSBookmarks( bool utf8 )
+{
+ KNSBookmarkImporterImpl importer;
+ importer.setFilename(m_fileName);
+ importer.setUtf8(utf8);
+ importer.setupSignalForwards(&importer, this);
+ importer.parse();
+}
+
+TQString KNSBookmarkImporter::netscapeBookmarksFile( bool forSaving )
+{
+ static KNSBookmarkImporterImpl *p = 0;
+ if (!p)
+ {
+ p = new KNSBookmarkImporterImpl;
+ p->setUtf8(false);
+ }
+ return p->findDefaultLocation(forSaving);
+}
+
+TQString KNSBookmarkImporter::mozillaBookmarksFile( bool forSaving )
+{
+ static KNSBookmarkImporterImpl *p = 0;
+ if (!p)
+ {
+ p = new KNSBookmarkImporterImpl;
+ p->setUtf8(true);
+ }
+ return p->findDefaultLocation(forSaving);
+}
+
+
+////////////////////////////////////////////////////////////////
+// compat only
+////////////////////////////////////////////////////////////////
+
+void KNSBookmarkExporter::write(bool utf8) {
+ KNSBookmarkExporterImpl exporter(m_pManager, m_fileName);
+ exporter.setUtf8(utf8);
+ exporter.write(m_pManager->root());
+}
+
+void KNSBookmarkExporter::writeFolder(TQTextStream &/*stream*/, KBookmarkGroup /*gp*/) {
+ // TODO - requires a d pointer workaround hack?
+}
+
+////////////////////////////////////////////////////////////////
+
+void KNSBookmarkExporterImpl::setUtf8(bool utf8) {
+ m_utf8 = utf8;
+}
+
+void KNSBookmarkExporterImpl::write(KBookmarkGroup parent) {
+ if (TQFile::exists(m_fileName)) {
+ ::rename(
+ TQFile::encodeName(m_fileName),
+ TQFile::encodeName(m_fileName + ".beforekde"));
+ }
+
+ TQFile file(m_fileName);
+
+ if (!file.open(IO_WriteOnly)) {
+ kdError(7043) << "Can't write to file " << m_fileName << endl;
+ return;
+ }
+
+ TQTextStream fstream(&file);
+ fstream.setEncoding(m_utf8 ? TQTextStream::UnicodeUTF8 : TQTextStream::Locale);
+
+ TQString charset
+ = m_utf8 ? "UTF-8" : TQString::fromLatin1(TQTextCodec::codecForLocale()->name()).upper();
+
+ fstream << "<!DOCTYPE NETSCAPE-Bookmark-file-1>" << endl
+ << i18n("<!-- This file was generated by Konqueror -->") << endl
+ << "<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset="
+ << charset << "\">" << endl
+ << "<TITLE>" << i18n("Bookmarks") << "</TITLE>" << endl
+ << "<H1>" << i18n("Bookmarks") << "</H1>" << endl
+ << "<DL><p>" << endl
+ << folderAsString(parent)
+ << "</DL><P>" << endl;
+}
+
+TQString KNSBookmarkExporterImpl::folderAsString(KBookmarkGroup parent) const {
+ TQString str;
+ TQTextStream fstream(&str, IO_WriteOnly);
+
+ for (KBookmark bk = parent.first(); !bk.isNull(); bk = parent.next(bk)) {
+ if (bk.isSeparator()) {
+ fstream << "<HR>" << endl;
+ continue;
+ }
+
+ TQString text = TQStyleSheet::escape(bk.fullText());
+
+ if (bk.isGroup() ) {
+ fstream << "<DT><H3 "
+ << (!bk.toGroup().isOpen() ? "FOLDED " : "")
+ << bk.internalElement().attribute("netscapeinfo") << ">"
+ << text << "</H3>" << endl
+ << "<DL><P>" << endl
+ << folderAsString(bk.toGroup())
+ << "</DL><P>" << endl;
+ continue;
+
+ } else {
+ // note - netscape seems to use local8bit for url...
+ fstream << "<DT><A HREF=\"" << bk.url().url() << "\""
+ << bk.internalElement().attribute("netscapeinfo") << ">"
+ << text << "</A>" << endl;
+ continue;
+ }
+ }
+
+ return str;
+}
+
+////
+
+#include "kbookmarkimporter_ns.moc"
diff --git a/tdeio/bookmarks/kbookmarkimporter_ns.h b/tdeio/bookmarks/kbookmarkimporter_ns.h
new file mode 100644
index 000000000..10844fc63
--- /dev/null
+++ b/tdeio/bookmarks/kbookmarkimporter_ns.h
@@ -0,0 +1,132 @@
+// -*- c-basic-offset:4; indent-tabs-mode:nil -*-
+// vim: set ts=4 sts=4 sw=4 et:
+/* This file is part of the KDE libraries
+ Copyright (C) 2000 David Faure <faure@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 version 2 as published by the Free Software Foundation.
+
+ 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 __kbookmarkimporter_ns_h
+#define __kbookmarkimporter_ns_h
+
+#include <tqdom.h>
+#include <tqcstring.h>
+#include <tqstringlist.h>
+#include <ksimpleconfig.h>
+#include <kdemacros.h>
+
+#include "kbookmarkimporter.h"
+#include "kbookmarkexporter.h"
+
+/**
+ * A class for importing NS bookmarks
+ * @deprecated
+ */
+class TDEIO_EXPORT_DEPRECATED KNSBookmarkImporter : public TQObject
+{
+ Q_OBJECT
+public:
+ KNSBookmarkImporter( const TQString & fileName ) : m_fileName(fileName) {}
+ ~KNSBookmarkImporter() {}
+
+ // for compat reasons only
+ void parseNSBookmarks() { parseNSBookmarks(false); }
+ // go for it. Set utf8 to true for Mozilla, false for Netscape.
+ void parseNSBookmarks( bool utf8 );
+
+ static TQString netscapeBookmarksFile( bool forSaving=false );
+ static TQString mozillaBookmarksFile( bool forSaving=false );
+
+signals:
+ void newBookmark( const TQString & text, const TQCString & url, const TQString & additionalInfo );
+ void newFolder( const TQString & text, bool open, const TQString & additionalInfo );
+ void newSeparator();
+ void endFolder();
+
+protected:
+ TQString m_fileName;
+};
+
+/**
+ * A class for importing NS bookmarks
+ * utf8 defaults to off
+ * @since 3.2
+ */
+class TDEIO_EXPORT KNSBookmarkImporterImpl : public KBookmarkImporterBase
+{
+public:
+ KNSBookmarkImporterImpl() : m_utf8(false) { }
+ void setUtf8(bool utf8) { m_utf8 = utf8; }
+ virtual void parse();
+ virtual TQString findDefaultLocation(bool forSaving = false) const;
+private:
+ bool m_utf8;
+ class KNSBookmarkImporterImplPrivate *d;
+};
+
+/**
+ * A class for importing Mozilla bookmarks
+ * utf8 defaults to on
+ * @since 3.2
+ */
+class TDEIO_EXPORT KMozillaBookmarkImporterImpl : public KNSBookmarkImporterImpl
+{
+public:
+ KMozillaBookmarkImporterImpl() { setUtf8(true); }
+private:
+ class KMozillaBookmarkImporterImplPrivate *d;
+};
+
+/**
+ * A class that exports all the current bookmarks to Netscape/Mozilla bookmarks
+ * Warning, it overwrites the existing bookmarks.html file !
+ * @deprecated
+ */
+class TDEIO_EXPORT_DEPRECATED KNSBookmarkExporter
+{
+public:
+ KNSBookmarkExporter(KBookmarkManager* mgr, const TQString & fileName)
+ : m_fileName(fileName), m_pManager(mgr) { }
+ ~KNSBookmarkExporter() {}
+
+ void write() { write(false); } // deprecated
+ void write( bool utf8 );
+
+protected:
+ void writeFolder(TQTextStream &stream, KBookmarkGroup parent);
+ TQString m_fileName;
+ KBookmarkManager* m_pManager;
+};
+
+/**
+ * @since 3.2
+ */
+class TDEIO_EXPORT KNSBookmarkExporterImpl : public KBookmarkExporterBase
+{
+public:
+ KNSBookmarkExporterImpl(KBookmarkManager* mgr, const TQString & fileName)
+ : KBookmarkExporterBase(mgr, fileName)
+ { ; }
+ virtual ~KNSBookmarkExporterImpl() {}
+ virtual void write(KBookmarkGroup);
+ void setUtf8(bool);
+protected:
+ TQString folderAsString(KBookmarkGroup) const;
+private:
+ bool m_utf8;
+ class KNSBookmarkExporterImplPrivate *d;
+};
+
+#endif
diff --git a/tdeio/bookmarks/kbookmarkimporter_opera.cc b/tdeio/bookmarks/kbookmarkimporter_opera.cc
new file mode 100644
index 000000000..57b5d6208
--- /dev/null
+++ b/tdeio/bookmarks/kbookmarkimporter_opera.cc
@@ -0,0 +1,170 @@
+// -*- c-basic-offset:4; indent-tabs-mode:nil -*-
+// vim: set ts=4 sts=4 sw=4 et:
+/* This file is part of the KDE libraries
+ Copyright (C) 2002-2003 Alexander Kellett <lypanov@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 version 2 as published by the Free Software Foundation.
+
+ 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 <tdefiledialog.h>
+#include <kstringhandler.h>
+#include <klocale.h>
+#include <kdebug.h>
+#include <tqtextcodec.h>
+
+#include <sys/types.h>
+#include <stddef.h>
+#include <dirent.h>
+#include <sys/stat.h>
+
+#include "kbookmarkimporter.h"
+#include "kbookmarkimporter_opera.h"
+
+void KOperaBookmarkImporter::parseOperaBookmarks( )
+{
+ TQFile file(m_fileName);
+ if(!file.open(IO_ReadOnly)) {
+ return;
+ }
+
+ TQTextCodec * codec = TQTextCodec::codecForName("UTF-8");
+ Q_ASSERT(codec);
+ if (!codec)
+ return;
+
+ int lineno = 0;
+ TQString url, name, type;
+ static const int g_lineLimit = 16*1024;
+ TQCString line(g_lineLimit);
+
+ while ( file.readLine(line.data(), g_lineLimit) >=0 ) {
+ lineno++;
+
+ // skip lines that didn't fit in buffer and first two headers lines
+ if ( line[line.length()-1] != '\n' || lineno <= 2 )
+ continue;
+
+ TQString currentLine = codec->toUnicode(line).stripWhiteSpace();
+
+ if (currentLine.isEmpty()) {
+ // end of data block
+ if (type.isNull())
+ continue;
+ else if ( type == "URL")
+ emit newBookmark( name, url.latin1(), "" );
+ else if (type == "FOLDER" )
+ emit newFolder( name, false, "" );
+
+ type = TQString::null;
+ name = TQString::null;
+ url = TQString::null;
+
+ } else if (currentLine == "-") {
+ // end of folder
+ emit endFolder();
+
+ } else {
+ // data block line
+ TQString tag;
+ if ( tag = "#", currentLine.startsWith( tag ) )
+ type = currentLine.remove( 0, tag.length() );
+ else if ( tag = "NAME=", currentLine.startsWith( tag ) )
+ name = currentLine.remove(0, tag.length());
+ else if ( tag = "URL=", currentLine.startsWith( tag ) )
+ url = currentLine.remove(0, tag.length());
+ }
+ }
+
+}
+
+TQString KOperaBookmarkImporter::operaBookmarksFile()
+{
+ static KOperaBookmarkImporterImpl *p = 0;
+ if (!p)
+ p = new KOperaBookmarkImporterImpl;
+ return p->findDefaultLocation();
+}
+
+void KOperaBookmarkImporterImpl::parse() {
+ KOperaBookmarkImporter importer(m_fileName);
+ setupSignalForwards(&importer, this);
+ importer.parseOperaBookmarks();
+}
+
+TQString KOperaBookmarkImporterImpl::findDefaultLocation(bool saving) const
+{
+ return saving ? KFileDialog::getSaveFileName(
+ TQDir::homeDirPath() + "/.opera",
+ i18n("*.adr|Opera Bookmark Files (*.adr)") )
+ : KFileDialog::getOpenFileName(
+ TQDir::homeDirPath() + "/.opera",
+ i18n("*.adr|Opera Bookmark Files (*.adr)") );
+}
+
+/////////////////////////////////////////////////
+
+class OperaExporter : private KBookmarkGroupTraverser {
+public:
+ OperaExporter();
+ TQString generate( const KBookmarkGroup &grp ) { traverse(grp); return m_string; };
+private:
+ virtual void visit( const KBookmark & );
+ virtual void visitEnter( const KBookmarkGroup & );
+ virtual void visitLeave( const KBookmarkGroup & );
+private:
+ TQString m_string;
+ TQTextStream m_out;
+};
+
+OperaExporter::OperaExporter() : m_out(&m_string, IO_WriteOnly) {
+ m_out << "Opera Hotlist version 2.0" << endl;
+ m_out << "Options: encoding = utf8, version=3" << endl;
+}
+
+void OperaExporter::visit( const KBookmark &bk ) {
+ // kdDebug() << "visit(" << bk.text() << ")" << endl;
+ m_out << "#URL" << endl;
+ m_out << "\tNAME=" << bk.fullText() << endl;
+ m_out << "\tURL=" << bk.url().url().utf8() << endl;
+ m_out << endl;
+}
+
+void OperaExporter::visitEnter( const KBookmarkGroup &grp ) {
+ // kdDebug() << "visitEnter(" << grp.text() << ")" << endl;
+ m_out << "#FOLDER" << endl;
+ m_out << "\tNAME="<< grp.fullText() << endl;
+ m_out << endl;
+}
+
+void OperaExporter::visitLeave( const KBookmarkGroup & ) {
+ // kdDebug() << "visitLeave()" << endl;
+ m_out << "-" << endl;
+ m_out << endl;
+}
+
+void KOperaBookmarkExporterImpl::write(KBookmarkGroup parent) {
+ OperaExporter exporter;
+ TQString content = exporter.generate( parent );
+ TQFile file(m_fileName);
+ if (!file.open(IO_WriteOnly)) {
+ kdError(7043) << "Can't write to file " << m_fileName << endl;
+ return;
+ }
+ TQTextStream fstream(&file);
+ fstream.setEncoding(TQTextStream::UnicodeUTF8);
+ fstream << content;
+}
+
+#include "kbookmarkimporter_opera.moc"
diff --git a/tdeio/bookmarks/kbookmarkimporter_opera.h b/tdeio/bookmarks/kbookmarkimporter_opera.h
new file mode 100644
index 000000000..f6f1028b1
--- /dev/null
+++ b/tdeio/bookmarks/kbookmarkimporter_opera.h
@@ -0,0 +1,86 @@
+// -*- c-basic-offset:4; indent-tabs-mode:nil -*-
+// vim: set ts=4 sts=4 sw=4 et:
+/* This file is part of the KDE libraries
+ Copyright (C) 2002 Alexander Kellett <lypanov@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 version 2 as published by the Free Software Foundation.
+
+ 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 __kbookmarkimporter_opera_h
+#define __kbookmarkimporter_opera_h
+
+#include <tqdom.h>
+#include <tqcstring.h>
+#include <tqstringlist.h>
+#include <ksimpleconfig.h>
+
+#include <kbookmarkimporter.h>
+
+/**
+ * A class for importing Opera bookmarks
+ * @deprecated
+ */
+class TDEIO_EXPORT_DEPRECATED KOperaBookmarkImporter : public TQObject
+{
+ Q_OBJECT
+public:
+ KOperaBookmarkImporter( const TQString & fileName ) : m_fileName(fileName) {}
+ ~KOperaBookmarkImporter() {}
+
+ void parseOperaBookmarks();
+
+ // Usual place for Opera bookmarks
+ static TQString operaBookmarksFile();
+
+signals:
+ void newBookmark( const TQString & text, const TQCString & url, const TQString & additionalInfo );
+ void newFolder( const TQString & text, bool open, const TQString & additionalInfo );
+ void newSeparator();
+ void endFolder();
+
+protected:
+ TQString m_fileName;
+};
+
+/**
+ * A class for importing Opera bookmarks
+ * @since 3.2
+ */
+class TDEIO_EXPORT KOperaBookmarkImporterImpl : public KBookmarkImporterBase
+{
+public:
+ KOperaBookmarkImporterImpl() { }
+ virtual void parse();
+ virtual TQString findDefaultLocation(bool forSaving = false) const;
+private:
+ class KOperaBookmarkImporterImplPrivate *d;
+};
+
+/**
+ * @since 3.2
+ */
+class TDEIO_EXPORT KOperaBookmarkExporterImpl : public KBookmarkExporterBase
+{
+public:
+ KOperaBookmarkExporterImpl(KBookmarkManager* mgr, const TQString & filename)
+ : KBookmarkExporterBase(mgr, filename)
+ { ; }
+ virtual ~KOperaBookmarkExporterImpl() {}
+ virtual void write(KBookmarkGroup);
+private:
+ class KOperaBookmarkExporterImplPrivate *d;
+};
+
+#endif
diff --git a/tdeio/bookmarks/kbookmarkmanager.cc b/tdeio/bookmarks/kbookmarkmanager.cc
new file mode 100644
index 000000000..a87e0f20e
--- /dev/null
+++ b/tdeio/bookmarks/kbookmarkmanager.cc
@@ -0,0 +1,727 @@
+// -*- c-basic-offset:4; indent-tabs-mode:nil -*-
+// vim: set ts=4 sts=4 sw=4 et:
+/* This file is part of the KDE libraries
+ Copyright (C) 2000 David Faure <faure@kde.org>
+ Copyright (C) 2003 Alexander Kellett <lypanov@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 version 2 as published by the Free Software Foundation.
+
+ 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 "kbookmarkmanager.h"
+#include "kbookmarkmenu.h"
+#include "kbookmarkmenu_p.h"
+#include "kbookmarkimporter.h"
+#include <kdebug.h>
+#include <krun.h>
+#include <kstandarddirs.h>
+#include <ksavefile.h>
+#include <dcopref.h>
+#include <tqregexp.h>
+#include <kmessagebox.h>
+#include <kprocess.h>
+#include <klocale.h>
+#include <kapplication.h>
+#include <dcopclient.h>
+#include <tqfile.h>
+#include <tqfileinfo.h>
+#include <tqtextstream.h>
+#include <kstaticdeleter.h>
+#include <tqptrstack.h>
+
+#include "dptrtemplate.h"
+
+class KBookmarkManagerPrivate : public dPtrTemplate<KBookmarkManager, KBookmarkManagerPrivate> {
+public:
+ KBookmarkManagerPrivate()
+ { m_browserEditor = true; }
+ TQString m_editorCaption;
+ bool m_browserEditor;
+};
+template<> TQPtrDict<KBookmarkManagerPrivate>* dPtrTemplate<KBookmarkManager, KBookmarkManagerPrivate>::d_ptr = 0;
+
+KBookmarkManagerPrivate* KBookmarkManager::dptr() const {
+ return KBookmarkManagerPrivate::d( this );
+}
+
+// TODO - clean this stuff up by just using the above dptrtemplate?
+TQPtrList<KBookmarkManager>* KBookmarkManager::s_pSelf;
+static KStaticDeleter<TQPtrList<KBookmarkManager> > sdbm;
+
+class KBookmarkMap : private KBookmarkGroupTraverser {
+public:
+ KBookmarkMap( KBookmarkManager * );
+ void update();
+ TQValueList<KBookmark> find( const TQString &url ) const
+ { return m_bk_map[url]; }
+private:
+ virtual void visit(const KBookmark &);
+ virtual void visitEnter(const KBookmarkGroup &) { ; }
+ virtual void visitLeave(const KBookmarkGroup &) { ; }
+private:
+ typedef TQValueList<KBookmark> KBookmarkList;
+ TQMap<TQString, KBookmarkList> m_bk_map;
+ KBookmarkManager *m_manager;
+};
+
+static KBookmarkMap *s_bk_map = 0;
+
+KBookmarkMap::KBookmarkMap( KBookmarkManager *manager ) {
+ m_manager = manager;
+}
+
+void KBookmarkMap::update()
+{
+ m_bk_map.clear();
+ KBookmarkGroup root = m_manager->root();
+ traverse(root);
+}
+
+void KBookmarkMap::visit(const KBookmark &bk)
+{
+ if (!bk.isSeparator()) {
+ // add bookmark to url map
+ m_bk_map[bk.internalElement().attribute("href")].append(bk);
+ }
+}
+
+
+KBookmarkManager* KBookmarkManager::managerForFile( const TQString& bookmarksFile, bool bImportDesktopFiles )
+{
+ if ( !s_pSelf ) {
+ sdbm.setObject( s_pSelf, new TQPtrList<KBookmarkManager> );
+ s_pSelf->setAutoDelete( true );
+ }
+ TQPtrListIterator<KBookmarkManager> it ( *s_pSelf );
+ for ( ; it.current() ; ++it )
+ if ( it.current()->path() == bookmarksFile )
+ return it.current();
+
+ KBookmarkManager* mgr = new KBookmarkManager( bookmarksFile, bImportDesktopFiles );
+ s_pSelf->append( mgr );
+ return mgr;
+}
+
+// principally used for filtered toolbars
+KBookmarkManager* KBookmarkManager::createTempManager()
+{
+ if ( !s_pSelf ) {
+ sdbm.setObject( s_pSelf, new TQPtrList<KBookmarkManager> );
+ s_pSelf->setAutoDelete( true );
+ }
+ KBookmarkManager* mgr = new KBookmarkManager();
+ s_pSelf->append( mgr );
+ return mgr;
+}
+
+#define PI_DATA "version=\"1.0\" encoding=\"UTF-8\""
+
+KBookmarkManager::KBookmarkManager( const TQString & bookmarksFile, bool bImportDesktopFiles )
+ : DCOPObject(TQCString("KBookmarkManager-")+bookmarksFile.utf8()), m_doc("xbel"), m_docIsLoaded(false)
+{
+ m_toolbarDoc.clear();
+
+ m_update = true;
+ m_showNSBookmarks = true;
+
+ Q_ASSERT( !bookmarksFile.isEmpty() );
+ m_bookmarksFile = bookmarksFile;
+
+ if ( !TQFile::exists(m_bookmarksFile) )
+ {
+ TQDomElement topLevel = m_doc.createElement("xbel");
+ m_doc.appendChild( topLevel );
+ m_doc.insertBefore( m_doc.createProcessingInstruction( "xml", PI_DATA), topLevel );
+ if ( bImportDesktopFiles )
+ importDesktopFiles();
+ m_docIsLoaded = true;
+ }
+
+ connectDCOPSignal(0, objId(), "bookmarksChanged(TQString)", "notifyChanged(TQString)", false);
+ connectDCOPSignal(0, objId(), "bookmarkConfigChanged()", "notifyConfigChanged()", false);
+}
+
+KBookmarkManager::KBookmarkManager( )
+ : DCOPObject(TQCString("KBookmarkManager-generated")), m_doc("xbel"), m_docIsLoaded(true)
+{
+ m_toolbarDoc.clear(); // strange ;-)
+
+ m_update = false; // TODO - make it read/write
+ m_showNSBookmarks = true;
+
+ m_bookmarksFile = TQString::null; // AK - check all codepaths for this one
+
+ TQDomElement topLevel = m_doc.createElement("xbel");
+ m_doc.appendChild( topLevel );
+ m_doc.insertBefore( m_doc.createProcessingInstruction( "xml", PI_DATA), topLevel );
+
+ // TODO - enable this via some sort of api and fix the above DCOPObject script somehow
+#if 0
+ connectDCOPSignal(0, objId(), "bookmarksChanged(TQString)", "notifyChanged(TQString)", false);
+ connectDCOPSignal(0, objId(), "bookmarkConfigChanged()", "notifyConfigChanged()", false);
+#endif
+}
+
+KBookmarkManager::~KBookmarkManager()
+{
+ if ( s_pSelf )
+ s_pSelf->removeRef( this );
+}
+
+void KBookmarkManager::setUpdate( bool update )
+{
+ m_update = update;
+}
+
+const TQDomDocument &KBookmarkManager::internalDocument() const
+{
+ if(!m_docIsLoaded)
+ {
+ parse();
+ m_toolbarDoc.clear();
+ }
+ return m_doc;
+}
+
+
+void KBookmarkManager::parse() const
+{
+ m_docIsLoaded = true;
+ //kdDebug(7043) << "KBookmarkManager::parse " << m_bookmarksFile << endl;
+ TQFile file( m_bookmarksFile );
+ if ( !file.open( IO_ReadOnly ) )
+ {
+ kdWarning() << "Can't open " << m_bookmarksFile << endl;
+ return;
+ }
+ m_doc = TQDomDocument("xbel");
+ m_doc.setContent( &file );
+
+ TQDomElement docElem = m_doc.documentElement();
+ if ( docElem.isNull() )
+ kdWarning() << "KBookmarkManager::parse : can't parse " << m_bookmarksFile << endl;
+ else
+ {
+ TQString mainTag = docElem.tagName();
+ if ( mainTag == "BOOKMARKS" )
+ {
+ kdWarning() << "Old style bookmarks found. Calling convertToXBEL." << endl;
+ docElem.setTagName("xbel");
+ if ( docElem.hasAttribute( "HIDE_NSBK" ) && m_showNSBookmarks ) // non standard either, but we need it
+ {
+ docElem.setAttribute( "hide_nsbk", docElem.attribute( "HIDE_NSBK" ) == "1" ? "yes" : "no" );
+ docElem.removeAttribute( "HIDE_NSBK" );
+ }
+
+ convertToXBEL( docElem );
+ save();
+ }
+ else if ( mainTag != "xbel" )
+ kdWarning() << "KBookmarkManager::parse : unknown main tag " << mainTag << endl;
+
+ TQDomNode n = m_doc.documentElement().previousSibling();
+ if ( n.isProcessingInstruction() )
+ {
+ TQDomProcessingInstruction pi = n.toProcessingInstruction();
+ pi.parentNode().removeChild(pi);
+ }
+
+ TQDomProcessingInstruction pi;
+ pi = m_doc.createProcessingInstruction( "xml", PI_DATA );
+ m_doc.insertBefore( pi, docElem );
+ }
+
+ file.close();
+ if ( !s_bk_map )
+ s_bk_map = new KBookmarkMap( const_cast<KBookmarkManager*>( this ) );
+ s_bk_map->update();
+}
+
+void KBookmarkManager::convertToXBEL( TQDomElement & group )
+{
+ TQDomNode n = group.firstChild();
+ while( !n.isNull() )
+ {
+ TQDomElement e = n.toElement();
+ if ( !e.isNull() )
+ if ( e.tagName() == "TEXT" )
+ {
+ e.setTagName("title");
+ }
+ else if ( e.tagName() == "SEPARATOR" )
+ {
+ e.setTagName("separator"); // so close...
+ }
+ else if ( e.tagName() == "GROUP" )
+ {
+ e.setTagName("folder");
+ convertAttribute(e, "ICON","icon"); // non standard, but we need it
+ if ( e.hasAttribute( "TOOLBAR" ) ) // non standard either, but we need it
+ {
+ e.setAttribute( "toolbar", e.attribute( "TOOLBAR" ) == "1" ? "yes" : "no" );
+ e.removeAttribute( "TOOLBAR" );
+ }
+
+ convertAttribute(e, "NETSCAPEINFO","netscapeinfo"); // idem
+ bool open = (e.attribute("OPEN") == "1");
+ e.removeAttribute("OPEN");
+ e.setAttribute("folded", open ? "no" : "yes");
+ convertToXBEL( e );
+ }
+ else
+ if ( e.tagName() == "BOOKMARK" )
+ {
+ e.setTagName("bookmark"); // so much difference :-)
+ convertAttribute(e, "ICON","icon"); // non standard, but we need it
+ convertAttribute(e, "NETSCAPEINFO","netscapeinfo"); // idem
+ convertAttribute(e, "URL","href");
+ TQString text = e.text();
+ while ( !e.firstChild().isNull() ) // clean up the old contained text
+ e.removeChild(e.firstChild());
+ TQDomElement titleElem = e.ownerDocument().createElement("title");
+ e.appendChild( titleElem ); // should be the only child anyway
+ titleElem.appendChild( e.ownerDocument().createTextNode( text ) );
+ }
+ else
+ kdWarning(7043) << "Unknown tag " << e.tagName() << endl;
+ n = n.nextSibling();
+ }
+}
+
+void KBookmarkManager::convertAttribute( TQDomElement elem, const TQString & oldName, const TQString & newName )
+{
+ if ( elem.hasAttribute( oldName ) )
+ {
+ elem.setAttribute( newName, elem.attribute( oldName ) );
+ elem.removeAttribute( oldName );
+ }
+}
+
+void KBookmarkManager::importDesktopFiles()
+{
+ KBookmarkImporter importer( const_cast<TQDomDocument *>(&internalDocument()) );
+ TQString path(TDEGlobal::dirs()->saveLocation("data", "kfm/bookmarks", true));
+ importer.import( path );
+ //kdDebug(7043) << internalDocument().toCString() << endl;
+
+ save();
+}
+
+bool KBookmarkManager::save( bool toolbarCache ) const
+{
+ return saveAs( m_bookmarksFile, toolbarCache );
+}
+
+bool KBookmarkManager::saveAs( const TQString & filename, bool toolbarCache ) const
+{
+ kdDebug(7043) << "KBookmarkManager::save " << filename << endl;
+
+ // Save the bookmark toolbar folder for quick loading
+ // but only when it will actually make things quicker
+ const TQString cacheFilename = filename + TQString::fromLatin1(".tbcache");
+ if(toolbarCache && !root().isToolbarGroup())
+ {
+ KSaveFile cacheFile( cacheFilename );
+ if ( cacheFile.status() == 0 )
+ {
+ TQString str;
+ TQTextStream stream(&str, IO_WriteOnly);
+ stream << root().findToolbar();
+ TQCString cstr = str.utf8();
+ cacheFile.file()->writeBlock( cstr.data(), cstr.length() );
+ cacheFile.close();
+ }
+ }
+ else // remove any (now) stale cache
+ {
+ TQFile::remove( cacheFilename );
+ }
+
+ KSaveFile file( filename );
+ if ( file.status() == 0 )
+ {
+ file.backupFile( file.name(), TQString::null, ".bak" );
+ TQCString cstr;
+ cstr = internalDocument().toCString(); // is in UTF8
+ file.file()->writeBlock( cstr.data(), cstr.length() );
+ if ( file.close() )
+ return true;
+ }
+
+ static int hadSaveError = false;
+ file.abort();
+ if ( !hadSaveError ) {
+ TQString error = i18n("Unable to save bookmarks in %1. Reported error was: %2. "
+ "This error message will only be shown once. The cause "
+ "of the error needs to be fixed as quickly as possible, "
+ "which is most likely a full hard drive.")
+ .arg(filename).arg(TQString::fromLocal8Bit(strerror(file.status())));
+ if (tqApp->type() != TQApplication::Tty)
+ KMessageBox::error( 0L, error );
+ else
+ kdError() << error << endl;
+ }
+ hadSaveError = true;
+ return false;
+}
+
+KBookmarkGroup KBookmarkManager::root() const
+{
+ return KBookmarkGroup(internalDocument().documentElement());
+}
+
+KBookmarkGroup KBookmarkManager::toolbar()
+{
+ kdDebug(7043) << "KBookmarkManager::toolbar begin" << endl;
+ // Only try to read from a toolbar cache if the full document isn't loaded
+ if(!m_docIsLoaded)
+ {
+ kdDebug(7043) << "KBookmarkManager::toolbar trying cache" << endl;
+ const TQString cacheFilename = m_bookmarksFile + TQString::fromLatin1(".tbcache");
+ TQFileInfo bmInfo(m_bookmarksFile);
+ TQFileInfo cacheInfo(cacheFilename);
+ if (m_toolbarDoc.isNull() &&
+ TQFile::exists(cacheFilename) &&
+ bmInfo.lastModified() < cacheInfo.lastModified())
+ {
+ kdDebug(7043) << "KBookmarkManager::toolbar reading file" << endl;
+ TQFile file( cacheFilename );
+
+ if ( file.open( IO_ReadOnly ) )
+ {
+ m_toolbarDoc = TQDomDocument("cache");
+ m_toolbarDoc.setContent( &file );
+ kdDebug(7043) << "KBookmarkManager::toolbar opened" << endl;
+ }
+ }
+ if (!m_toolbarDoc.isNull())
+ {
+ kdDebug(7043) << "KBookmarkManager::toolbar returning element" << endl;
+ TQDomElement elem = m_toolbarDoc.firstChild().toElement();
+ return KBookmarkGroup(elem);
+ }
+ }
+
+ // Fallback to the normal way if there is no cache or if the bookmark file
+ // is already loaded
+ TQDomElement elem = root().findToolbar();
+ if (elem.isNull())
+ return root(); // Root is the bookmark toolbar if none has been set.
+ else
+ return KBookmarkGroup(root().findToolbar());
+}
+
+KBookmark KBookmarkManager::findByAddress( const TQString & address, bool tolerant )
+{
+ //kdDebug(7043) << "KBookmarkManager::findByAddress " << address << endl;
+ KBookmark result = root();
+ // The address is something like /5/10/2+
+ TQStringList addresses = TQStringList::split(TQRegExp("[/+]"),address);
+ // kdWarning() << addresses.join(",") << endl;
+ for ( TQStringList::Iterator it = addresses.begin() ; it != addresses.end() ; )
+ {
+ bool append = ((*it) == "+");
+ uint number = (*it).toUInt();
+ Q_ASSERT(result.isGroup());
+ KBookmarkGroup group = result.toGroup();
+ KBookmark bk = group.first(), lbk = bk; // last non-null bookmark
+ for ( uint i = 0 ; ( (i<number) || append ) && !bk.isNull() ; ++i ) {
+ lbk = bk;
+ bk = group.next(bk);
+ //kdWarning() << i << endl;
+ }
+ it++;
+ int shouldBeGroup = !bk.isGroup() && (it != addresses.end());
+ if ( tolerant && ( bk.isNull() || shouldBeGroup ) ) {
+ if (!lbk.isNull()) result = lbk;
+ //kdWarning() << "break" << endl;
+ break;
+ }
+ //kdWarning() << "found section" << endl;
+ result = bk;
+ }
+ if (result.isNull()) {
+ kdWarning() << "KBookmarkManager::findByAddress: couldn't find item " << address << endl;
+ Q_ASSERT(!tolerant);
+ }
+ //kdWarning() << "found " << result.address() << endl;
+ return result;
+ }
+
+static TQString pickUnusedTitle( KBookmarkGroup parentBookmark,
+ const TQString &title, const TQString &url
+) {
+ // If this title is already used, we'll try to find something unused.
+ KBookmark ch = parentBookmark.first();
+ int count = 1;
+ TQString uniqueTitle = title;
+ do
+ {
+ while ( !ch.isNull() )
+ {
+ if ( uniqueTitle == ch.text() )
+ {
+ // Title already used !
+ if ( url != ch.url().url() )
+ {
+ uniqueTitle = title + TQString(" (%1)").arg(++count);
+ // New title -> restart search from the beginning
+ ch = parentBookmark.first();
+ break;
+ }
+ else
+ {
+ // this exact URL already exists
+ return TQString::null;
+ }
+ }
+ ch = parentBookmark.next( ch );
+ }
+ } while ( !ch.isNull() );
+
+ return uniqueTitle;
+}
+
+KBookmarkGroup KBookmarkManager::addBookmarkDialog(
+ const TQString & _url, const TQString & _title,
+ const TQString & _parentBookmarkAddress
+) {
+ TQString url = _url;
+ TQString title = _title;
+ TQString parentBookmarkAddress = _parentBookmarkAddress;
+
+ if ( url.isEmpty() )
+ {
+ KMessageBox::error( 0L, i18n("Cannot add bookmark with empty URL."));
+ return KBookmarkGroup();
+ }
+
+ if ( title.isEmpty() )
+ title = url;
+
+ if ( KBookmarkSettings::self()->m_advancedaddbookmark)
+ {
+ KBookmarkEditDialog dlg( title, url, this, KBookmarkEditDialog::InsertionMode, parentBookmarkAddress );
+ if ( dlg.exec() != KDialogBase::Accepted )
+ return KBookmarkGroup();
+ title = dlg.finalTitle();
+ url = dlg.finalUrl();
+ parentBookmarkAddress = dlg.finalAddress();
+ }
+
+ KBookmarkGroup parentBookmark;
+ parentBookmark = findByAddress( parentBookmarkAddress ).toGroup();
+ Q_ASSERT( !parentBookmark.isNull() );
+
+ TQString uniqueTitle = pickUnusedTitle( parentBookmark, title, url );
+ if ( !uniqueTitle.isNull() )
+ parentBookmark.addBookmark( this, uniqueTitle, KURL( url ));
+
+ return parentBookmark;
+}
+
+
+void KBookmarkManager::emitChanged( /*KDE4 const*/ KBookmarkGroup & group )
+{
+ save();
+
+ // Tell the other processes too
+ // kdDebug(7043) << "KBookmarkManager::emitChanged : broadcasting change " << group.address() << endl;
+
+ TQByteArray data;
+ TQDataStream ds( data, IO_WriteOnly );
+ ds << group.address();
+
+ emitDCOPSignal("bookmarksChanged(TQString)", data);
+
+ // We do get our own broadcast, so no need for this anymore
+ //emit changed( group );
+}
+
+void KBookmarkManager::emitConfigChanged()
+{
+ emitDCOPSignal("bookmarkConfigChanged()", TQByteArray());
+}
+
+void KBookmarkManager::notifyCompleteChange( TQString caller ) // DCOP call
+{
+ if (!m_update) return;
+
+ //kdDebug(7043) << "KBookmarkManager::notifyCompleteChange" << endl;
+ // The bk editor tells us we should reload everything
+ // Reparse
+ parse();
+ // Tell our GUI
+ // (emit where group is "" to directly mark the root menu as dirty)
+ emit changed( "", caller );
+}
+
+void KBookmarkManager::notifyConfigChanged() // DCOP call
+{
+ kdDebug() << "reloaded bookmark config!" << endl;
+ KBookmarkSettings::self()->readSettings();
+ parse(); // reload, and thusly recreate the menus
+}
+
+void KBookmarkManager::notifyChanged( TQString groupAddress ) // DCOP call
+{
+ if (!m_update) return;
+
+ // Reparse (the whole file, no other choice)
+ // if someone else notified us
+ if (callingDcopClient()->senderId() != DCOPClient::mainClient()->appId())
+ parse();
+
+ //kdDebug(7043) << "KBookmarkManager::notifyChanged " << groupAddress << endl;
+ //KBookmarkGroup group = findByAddress( groupAddress ).toGroup();
+ //Q_ASSERT(!group.isNull());
+ emit changed( groupAddress, TQString::null );
+}
+
+bool KBookmarkManager::showNSBookmarks() const
+{
+ return KBookmarkMenu::showDynamicBookmarks("netscape").show;
+}
+
+void KBookmarkManager::setShowNSBookmarks( bool show )
+{
+ m_showNSBookmarks = show;
+ if (this->path() != userBookmarksFile())
+ return;
+ KBookmarkMenu::DynMenuInfo info
+ = KBookmarkMenu::showDynamicBookmarks("netscape");
+ info.show = show;
+ KBookmarkMenu::setDynamicBookmarks("netscape", info);
+}
+
+void KBookmarkManager::setEditorOptions( const TQString& caption, bool browser )
+{
+ dptr()->m_editorCaption = caption;
+ dptr()->m_browserEditor = browser;
+}
+
+void KBookmarkManager::slotEditBookmarks()
+{
+ TDEProcess proc;
+ proc << TQString::fromLatin1("keditbookmarks");
+ if (!dptr()->m_editorCaption.isNull())
+ proc << TQString::fromLatin1("--customcaption") << dptr()->m_editorCaption;
+ if (!dptr()->m_browserEditor)
+ proc << TQString::fromLatin1("--nobrowser");
+ proc << m_bookmarksFile;
+ proc.start(TDEProcess::DontCare);
+}
+
+void KBookmarkManager::slotEditBookmarksAtAddress( const TQString& address )
+{
+ TDEProcess proc;
+ proc << TQString::fromLatin1("keditbookmarks")
+ << TQString::fromLatin1("--address") << address
+ << m_bookmarksFile;
+ proc.start(TDEProcess::DontCare);
+}
+
+///////
+
+void KBookmarkOwner::openBookmarkURL( const TQString& url )
+{
+ (void) new KRun(KURL( url ));
+}
+
+void KBookmarkOwner::virtual_hook( int, void* )
+{ /*BASE::virtual_hook( id, data );*/ }
+
+bool KBookmarkManager::updateAccessMetadata( const TQString & url, bool emitSignal )
+{
+ if (!s_bk_map) {
+ s_bk_map = new KBookmarkMap(this);
+ s_bk_map->update();
+ }
+
+ TQValueList<KBookmark> list = s_bk_map->find(url);
+ if ( list.count() == 0 )
+ return false;
+
+ for ( TQValueList<KBookmark>::iterator it = list.begin();
+ it != list.end(); ++it )
+ (*it).updateAccessMetadata();
+
+ if (emitSignal)
+ emit notifier().updatedAccessMetadata( path(), url );
+
+ return true;
+}
+
+void KBookmarkManager::updateFavicon( const TQString &url, const TQString &faviconurl, bool emitSignal )
+{
+ Q_UNUSED(faviconurl);
+
+ if (!s_bk_map) {
+ s_bk_map = new KBookmarkMap(this);
+ s_bk_map->update();
+ }
+
+ TQValueList<KBookmark> list = s_bk_map->find(url);
+ for ( TQValueList<KBookmark>::iterator it = list.begin();
+ it != list.end(); ++it )
+ {
+ // TODO - update favicon data based on faviconurl
+ // but only when the previously used icon
+ // isn't a manually set one.
+ }
+
+ if (emitSignal)
+ {
+ // TODO
+ // emit notifier().updatedFavicon( path(), url, faviconurl );
+ }
+}
+
+TQString KBookmarkManager::userBookmarksFile()
+{
+ return locateLocal("data", TQString::fromLatin1("konqueror/bookmarks.xml"));
+}
+
+KBookmarkManager* KBookmarkManager::userBookmarksManager()
+{
+ return KBookmarkManager::managerForFile( userBookmarksFile() );
+}
+
+KBookmarkSettings* KBookmarkSettings::s_self = 0;
+
+void KBookmarkSettings::readSettings()
+{
+ TDEConfig config("kbookmarkrc", false, false);
+ config.setGroup("Bookmarks");
+
+ // add bookmark dialog usage - no reparse
+ s_self->m_advancedaddbookmark = config.readBoolEntry("AdvancedAddBookmarkDialog", false);
+
+ // these three alter the menu, therefore all need a reparse
+ s_self->m_contextmenu = config.readBoolEntry("ContextMenuActions", true);
+ s_self->m_quickactions = config.readBoolEntry("QuickActionSubmenu", false);
+ s_self->m_filteredtoolbar = config.readBoolEntry("FilteredToolbar", false);
+}
+
+KBookmarkSettings *KBookmarkSettings::self()
+{
+ if (!s_self)
+ {
+ s_self = new KBookmarkSettings;
+ readSettings();
+ }
+ return s_self;
+}
+
+#include "kbookmarkmanager.moc"
diff --git a/tdeio/bookmarks/kbookmarkmanager.h b/tdeio/bookmarks/kbookmarkmanager.h
new file mode 100644
index 000000000..4a129704a
--- /dev/null
+++ b/tdeio/bookmarks/kbookmarkmanager.h
@@ -0,0 +1,367 @@
+// -*- c-basic-offset:4; indent-tabs-mode:nil -*-
+// vim: set ts=4 sts=4 sw=4 et:
+/* This file is part of the KDE libraries
+ Copyright (C) 2000 David Faure <faure@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 version 2 as published by the Free Software Foundation.
+
+ 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 __kbookmarkmanager_h
+#define __kbookmarkmanager_h
+
+#include <tqstring.h>
+#include <tqstringlist.h>
+#include <tqobject.h>
+#include <tqdom.h>
+#include <dcopobject.h>
+#include "kbookmark.h"
+#include "kbookmarknotifier.h"
+
+/**
+ * This class implements the reading/writing of bookmarks in XML.
+ * The bookmarks file is read and written using the XBEL standard
+ * (http://pyxml.sourceforge.net/topics/xbel/)
+ *
+ * A sample file looks like this :
+ * \code
+ * <xbel>
+ * <bookmark href="http://developer.kde.org"><title>Developer Web Site</title></bookmark>
+ * <folder folded="no">
+ * <title>Title of this folder</title>
+ * <bookmark icon="kde" href="http://www.kde.org"><title>KDE Web Site</title></bookmark>
+ * <folder toolbar="yes">
+ * <title>My own bookmarks</title>
+ * <bookmark href="http://www.koffice.org"><title>KOffice Web Site</title></bookmark>
+ * <separator/>
+ * <bookmark href="http://www.tdevelop.org"><title>KDevelop Web Site</title></bookmark>
+ * </folder>
+ * </folder>
+ * </xbel>
+ * \endcode
+ */
+class TDEIO_EXPORT KBookmarkManager : public TQObject, public DCOPObject
+{
+ Q_OBJECT
+ K_DCOP
+protected:
+ /**
+ * Creates a bookmark manager with a path to the bookmarks. By
+ * default, it will use the KDE standard dirs to find and create the
+ * correct location. If you are using your own app-specific
+ * bookmarks directory, you must instantiate this class with your
+ * own path <em>before</em> KBookmarkManager::managerForFile() is ever
+ * called.
+ *
+ * @param bookmarksFile full path to the bookmarks file,
+ * Use ~/.trinity/share/apps/konqueror/bookmarks.xml for the konqueror bookmarks
+ *
+ * @param bImportDesktopFiles if true, and if the bookmarksFile
+ * doesn't already exist, import bookmarks from desktop files
+ */
+ KBookmarkManager( const TQString & bookmarksFile, bool bImportDesktopFiles = true );
+
+ /**
+ * @since 3.2
+ */
+ KBookmarkManager();
+
+public:
+ /**
+ * Destructor
+ */
+ ~KBookmarkManager();
+
+ /**
+ * Set the update flag. Defaults to true. TODO - check
+ * @param update if true then KBookmarkManager will listen to DCOP update requests.
+ */
+ void setUpdate( bool update );
+
+ /**
+ * Save the bookmarks to the default konqueror XML file on disk.
+ * You should use emitChanged() instead of this function, it saves
+ * and notifies everyone that the file has changed.
+ * @param toolbarCache iff true save a cache of the toolbar folder, too
+ * @return true if saving was successful
+ */
+ bool save( bool toolbarCache = true ) const;
+
+ /**
+ * Save the bookmarks to the given XML file on disk.
+ * @param filename full path to the desired bookmarks file location
+ * @param toolbarCache iff true save a cache of the toolbar folder, too
+ * @return true if saving was successful
+ */
+ bool saveAs( const TQString & filename, bool toolbarCache = true ) const;
+
+ /**
+ * Update access time stamps for a given url.
+ * @param url the viewed url
+ * @param emitSignal iff true emit KBookmarkNotifier signal
+ * @since 3.2
+ * @return true if any metadata was modified (bookmarks file is not saved automatically)
+ */
+ bool updateAccessMetadata( const TQString &url, bool emitSignal = true );
+
+ /*
+ * NB. currently *unimplemented*
+ *
+ * Update favicon url for a given url.
+ * @param url the viewed url
+ * @param faviconurl the favicion url
+ * @emitSignal iff true emit KBookmarkNotifier signal
+ * @since 3.3
+ */
+ void updateFavicon( const TQString &url, const TQString &faviconurl, bool emitSignal = true );
+
+ /**
+ * This will return the path that this manager is using to read
+ * the bookmarks.
+ * @internal
+ * @return the path containing the bookmarks
+ */
+ TQString path() { return m_bookmarksFile; }
+
+ /**
+ * This will return the root bookmark. It is used to iterate
+ * through the bookmarks manually. It is mostly used internally.
+ *
+ * @return the root (top-level) bookmark
+ */
+ KBookmarkGroup root() const;
+
+ /**
+ * This returns the root of the toolbar menu.
+ * In the XML, this is the group with the attribute TOOLBAR=1
+ *
+ * @return the toolbar group
+ */
+ KBookmarkGroup toolbar();
+
+ /**
+ * @return the bookmark designated by @p address
+ * @param address the address belonging to the bookmark you're looking for
+ * @param tolerate when true tries to find the most tolerable bookmark position
+ * @see KBookmark::address
+ */
+ KBookmark findByAddress( const TQString & address, bool tolerate = false );
+
+ /**
+ * Saves the bookmark file and notifies everyone.
+ * @param group the parent of all changed bookmarks
+ */
+ void emitChanged( KBookmarkGroup & group );
+
+ void emitConfigChanged();
+
+ /**
+ * @return true if the NS bookmarks should be dynamically shown
+ * in the toplevel kactionmenu
+ * @deprecated
+ */
+ bool showNSBookmarks() const;
+
+ /**
+ * Shows an extra menu for NS bookmarks. Set this to false, if you don't
+ * want this.
+ */
+ void setShowNSBookmarks( bool show );
+
+ /**
+ * Set options with which slotEditBookmarks called keditbookmarks
+ * this can be used to change the appearance of the keditbookmarks
+ * in order to provide a slightly differing outer shell depending
+ * on the bookmarks file / app which calls it.
+ * @param caption the --caption string, for instance "Konsole"
+ * @param browser iff false display no browser specific
+ * menu items in keditbookmarks :: --nobrowser
+ * @since 3.2
+ */
+ void setEditorOptions( const TQString& caption, bool browser );
+
+ /**
+ * This static function will return an instance of the
+ * KBookmarkManager, responsible for the given @p bookmarksFile.
+ * If you do not instantiate this class either
+ * natively or in a derived class, then it will return an object
+ * with the default behaviors. If you wish to use different
+ * behaviors, you <em>must</em> derive your own class and
+ * instantiate it before this method is ever called.
+ *
+ * @param bookmarksFile full path to the bookmarks file,
+ * Use ~/.trinity/share/apps/konqueror/bookmarks.xml for the konqueror bookmarks
+ *
+ * @param bImportDesktopFiles if true, and if the bookmarksFile
+ * doesn't already exist, import bookmarks from desktop files
+ * @return a pointer to an instance of the KBookmarkManager.
+ */
+ static KBookmarkManager* managerForFile( const TQString& bookmarksFile,
+ bool bImportDesktopFiles = true );
+
+
+ static KBookmarkManager* createTempManager();
+
+ /**
+ * Returns a pointer to the users main bookmark collection.
+ * @since 3.2
+ */
+ static KBookmarkManager* userBookmarksManager();
+
+ /**
+ * Returns the path to the user's main bookmark collection file.
+ * @since 3.5.5
+ */
+ static TQString userBookmarksFile();
+
+ /**
+ * @internal
+ */
+ const TQDomDocument & internalDocument() const;
+
+ /**
+ * Access to bookmark notifier, for emitting signals.
+ * We need this object to exist in one instance only, so we could
+ * connectDCOP to it by name.
+ */
+ KBookmarkNotifier& notifier() { return m_notifier; }
+
+ /**
+ * @since 3.2
+ */
+ KBookmarkGroup addBookmarkDialog( const TQString & _url, const TQString & _title,
+ const TQString & _parentBookmarkAddress = TQString::null );
+
+public slots:
+ void slotEditBookmarks();
+ void slotEditBookmarksAtAddress( const TQString& address );
+
+public:
+k_dcop:
+ /**
+ * Reparse the whole bookmarks file and notify about the change
+ * (Called by the bookmark editor)
+ */
+ ASYNC notifyCompleteChange( TQString caller );
+
+ /**
+ * Emit the changed signal for the group whose address is given
+ * @see KBookmark::address()
+ * Called by the instance of konqueror that saved the file after
+ * a small change (new bookmark or new folder).
+ */
+ ASYNC notifyChanged( TQString groupAddress );
+
+ ASYNC notifyConfigChanged();
+
+signals:
+ /**
+ * Signals that the group (or any of its children) with the address
+ * @p groupAddress (e.g. "/4/5")
+ * has been modified by the caller @p caller.
+ */
+ void changed( const TQString & groupAddress, const TQString & caller );
+
+protected:
+ // consts added to avoid a copy-and-paste of internalDocument
+ void parse() const;
+ void importDesktopFiles();
+ static void convertToXBEL( TQDomElement & group );
+ static void convertAttribute( TQDomElement elem, const TQString & oldName, const TQString & newName );
+
+private:
+ KBookmarkNotifier m_notifier;
+ TQString m_bookmarksFile;
+ mutable TQDomDocument m_doc;
+ mutable TQDomDocument m_toolbarDoc;
+ mutable bool m_docIsLoaded;
+ bool m_update;
+ static TQPtrList<KBookmarkManager>* s_pSelf;
+ bool m_showNSBookmarks;
+
+private:
+ class KBookmarkManagerPrivate* dptr() const;
+};
+
+/**
+ * The KBookmarkMenu and KBookmarkBar classes gives the user
+ * the ability to either edit bookmarks or add their own. In the
+ * first case, the app may want to open the bookmark in a special way.
+ * In the second case, the app <em>must</em> supply the name and the
+ * URL for the bookmark.
+ *
+ * This class gives the app this callback-like ability.
+ *
+ * If your app does not give the user the ability to add bookmarks and
+ * you don't mind using the default bookmark editor to edit your
+ * bookmarks, then you don't need to overload this class at all.
+ * Rather, just use something like:
+ *
+ * <CODE>
+ * bookmarks = new KBookmarkMenu(new KBookmarkOwner(), ...)
+ * </CODE>
+ *
+ * If you wish to use your own editor or allow the user to add
+ * bookmarks, you must overload this class.
+ */
+class TDEIO_EXPORT KBookmarkOwner
+{
+public:
+ /**
+ * This function is called if the user selects a bookmark. It will
+ * open up the bookmark in a default fashion unless you override it.
+ */
+ virtual void openBookmarkURL(const TQString& _url);
+
+ /**
+ * This function is called whenever the user wants to add the
+ * current page to the bookmarks list. The title will become the
+ * "name" of the bookmark. You must overload this function if you
+ * wish to give your users the ability to add bookmarks.
+ *
+ * @return the title of the current page.
+ */
+ virtual TQString currentTitle() const { return TQString::null; }
+
+ /**
+ * This function is called whenever the user wants to add the
+ * current page to the bookmarks list. The URL will become the URL
+ * of the bookmark. You must overload this function if you wish to
+ * give your users the ability to add bookmarks.
+ *
+ * @return the URL of the current page.
+ */
+ virtual TQString currentURL() const { return TQString::null; }
+
+protected:
+ virtual void virtual_hook( int id, void* data );
+};
+
+/**
+ * @since 3.2
+ */
+class TDEIO_EXPORT KExtendedBookmarkOwner : public TQObject, virtual public KBookmarkOwner
+{
+ Q_OBJECT
+public:
+ typedef TQValueList<QPair<TQString,TQString> > QStringPairList;
+public slots:
+ void fillBookmarksList( KExtendedBookmarkOwner::QStringPairList & list ) { emit signalFillBookmarksList( list ); };
+signals:
+ void signalFillBookmarksList( KExtendedBookmarkOwner::QStringPairList & list );
+private:
+ class KExtendedBookmarkOwnerPrivate;
+ KExtendedBookmarkOwnerPrivate *d;
+};
+
+#endif
diff --git a/tdeio/bookmarks/kbookmarkmenu.cc b/tdeio/bookmarks/kbookmarkmenu.cc
new file mode 100644
index 000000000..a4d88ae57
--- /dev/null
+++ b/tdeio/bookmarks/kbookmarkmenu.cc
@@ -0,0 +1,1187 @@
+// -*- c-basic-offset:4; indent-tabs-mode:nil -*-
+// vim: set ts=4 sts=4 sw=4 et:
+/* This file is part of the KDE project
+ 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., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "kbookmarkmenu.h"
+#include "kbookmarkmenu_p.h"
+#include "kbookmarkimporter.h"
+#include "kbookmarkimporter_opera.h"
+#include "kbookmarkimporter_ie.h"
+#include "kbookmarkdrag.h"
+
+#include <kapplication.h>
+#include <tdeconfig.h>
+#include <kdebug.h>
+#include <kdialogbase.h>
+#include <kiconloader.h>
+#include <klineedit.h>
+#include <klocale.h>
+#include <kmessagebox.h>
+#include <kpopupmenu.h>
+#include <kstdaccel.h>
+#include <kstdaction.h>
+#include <kstringhandler.h>
+
+#include <tqclipboard.h>
+#include <tqfile.h>
+#include <tqheader.h>
+#include <tqlabel.h>
+#include <tqlayout.h>
+#include <tqlineedit.h>
+#include <tqlistview.h>
+#include <tqpushbutton.h>
+
+#include <dptrtemplate.h>
+
+template class TQPtrList<KBookmarkMenu>;
+
+static TQString makeTextNodeMod(KBookmark bk, const TQString &m_nodename, const TQString &m_newText) {
+ TQDomNode subnode = bk.internalElement().namedItem(m_nodename);
+ if (subnode.isNull()) {
+ subnode = bk.internalElement().ownerDocument().createElement(m_nodename);
+ bk.internalElement().appendChild(subnode);
+ }
+
+ if (subnode.firstChild().isNull()) {
+ TQDomText domtext = subnode.ownerDocument().createTextNode("");
+ subnode.appendChild(domtext);
+ }
+
+ TQDomText domtext = subnode.firstChild().toText();
+
+ TQString m_oldText = domtext.data();
+ domtext.setData(m_newText);
+
+ return m_oldText;
+}
+
+/********************************************************************/
+/********************************************************************/
+/********************************************************************/
+
+KBookmarkMenu::KBookmarkMenu( KBookmarkManager* mgr,
+ KBookmarkOwner * _owner, KPopupMenu * _parentMenu,
+ KActionCollection *collec, bool _isRoot, bool _add,
+ const TQString & parentAddress )
+ : TQObject(),
+ m_bIsRoot(_isRoot), m_bAddBookmark(_add),
+ m_bAddShortcuts(true),
+ m_pManager(mgr), m_pOwner(_owner),
+ m_parentMenu( _parentMenu ),
+ m_actionCollection( collec ),
+ m_parentAddress( parentAddress )
+{
+ m_parentMenu->setKeyboardShortcutsEnabled( true );
+
+ m_lstSubMenus.setAutoDelete( true );
+ m_actions.setAutoDelete( true );
+
+ if (m_actionCollection)
+ {
+ m_actionCollection->setHighlightingEnabled(true);
+ disconnect( m_actionCollection, TQT_SIGNAL( actionHighlighted( KAction * ) ), 0, 0 );
+ connect( m_actionCollection, TQT_SIGNAL( actionHighlighted( KAction * ) ),
+ this, TQT_SLOT( slotActionHighlighted( KAction * ) ) );
+ }
+
+ m_bNSBookmark = m_parentAddress.isNull();
+ if ( !m_bNSBookmark ) // not for the netscape bookmark
+ {
+ //kdDebug(7043) << "KBookmarkMenu::KBookmarkMenu " << this << " address : " << m_parentAddress << endl;
+
+ connect( _parentMenu, TQT_SIGNAL( aboutToShow() ),
+ TQT_SLOT( slotAboutToShow() ) );
+
+ if ( KBookmarkSettings::self()->m_contextmenu )
+ {
+ (void) _parentMenu->contextMenu();
+ connect( _parentMenu, TQT_SIGNAL( aboutToShowContextMenu(KPopupMenu*, int, TQPopupMenu*) ),
+ this, TQT_SLOT( slotAboutToShowContextMenu(KPopupMenu*, int, TQPopupMenu*) ));
+ }
+
+ if ( m_bIsRoot )
+ {
+ connect( m_pManager, TQT_SIGNAL( changed(const TQString &, const TQString &) ),
+ TQT_SLOT( slotBookmarksChanged(const TQString &) ) );
+ }
+ }
+
+ // add entries that possibly have a shortcut, so they are available _before_ first popup
+ if ( m_bIsRoot )
+ {
+ if ( m_bAddBookmark )
+ {
+ addAddBookmark();
+ if ( extOwner() )
+ addAddBookmarksList(); // FIXME
+ }
+
+ addEditBookmarks();
+ }
+
+ m_bDirty = true;
+}
+
+KBookmarkMenu::~KBookmarkMenu()
+{
+ //kdDebug(7043) << "KBookmarkMenu::~KBookmarkMenu() " << this << endl;
+ TQPtrListIterator<KAction> it( m_actions );
+ for (; it.current(); ++it )
+ it.current()->unplugAll();
+
+ m_lstSubMenus.clear();
+ m_actions.clear();
+}
+
+void KBookmarkMenu::ensureUpToDate()
+{
+ slotAboutToShow();
+}
+
+void KBookmarkMenu::slotAboutToShow()
+{
+ // Did the bookmarks change since the last time we showed them ?
+ if ( m_bDirty )
+ {
+ m_bDirty = false;
+ refill();
+ }
+}
+
+TQString KBookmarkMenu::s_highlightedAddress;
+TQString KBookmarkMenu::s_highlightedImportType;
+TQString KBookmarkMenu::s_highlightedImportLocation;
+
+void KBookmarkMenu::slotActionHighlighted( KAction* action )
+{
+ if (action->isA("KBookmarkActionMenu") || action->isA("KBookmarkAction"))
+ {
+ s_highlightedAddress = action->property("address").toString();
+ //kdDebug() << "KBookmarkMenu::slotActionHighlighted" << s_highlightedAddress << endl;
+ }
+ else if (action->isA("KImportedBookmarksActionMenu"))
+ {
+ s_highlightedImportType = action->property("type").toString();
+ s_highlightedImportLocation = action->property("location").toString();
+ }
+ else
+ {
+ s_highlightedAddress = TQString::null;
+ s_highlightedImportType = TQString::null;
+ s_highlightedImportLocation = TQString::null;
+ }
+}
+
+/********************************************************************/
+/********************************************************************/
+/********************************************************************/
+
+class KBookmarkMenuRMBAssoc : public dPtrTemplate<KBookmarkMenu, RMB> { };
+template<> TQPtrDict<RMB>* dPtrTemplate<KBookmarkMenu, RMB>::d_ptr = 0;
+
+static RMB* rmbSelf(KBookmarkMenu *m) { return KBookmarkMenuRMBAssoc::d(m); }
+
+// TODO check via dcop before making any changes to the bookmarks file???
+
+void RMB::begin_rmb_action(KBookmarkMenu *self)
+{
+ RMB *s = rmbSelf(self);
+ s->recv = self;
+ s->m_parentAddress = self->m_parentAddress;
+ s->s_highlightedAddress = KBookmarkMenu::s_highlightedAddress;
+ s->m_pManager = self->m_pManager;
+ s->m_pOwner = self->m_pOwner;
+ s->m_parentMenu = self->m_parentMenu;
+}
+
+bool RMB::invalid( int val )
+{
+ bool valid = true;
+
+ if (val == 1)
+ s_highlightedAddress = m_parentAddress;
+
+ if (s_highlightedAddress.isNull())
+ valid = false;
+
+ return !valid;
+}
+
+KBookmark RMB::atAddress(const TQString & address)
+{
+ KBookmark bookmark = m_pManager->findByAddress( address );
+ Q_ASSERT(!bookmark.isNull());
+ return bookmark;
+}
+
+void KBookmarkMenu::slotAboutToShowContextMenu( KPopupMenu*, int, TQPopupMenu* contextMenu )
+{
+ //kdDebug(7043) << "KBookmarkMenu::slotAboutToShowContextMenu" << s_highlightedAddress << endl;
+ if (s_highlightedAddress.isNull())
+ {
+ KPopupMenu::contextMenuFocus()->hideContextMenu();
+ return;
+ }
+ contextMenu->clear();
+ fillContextMenu( contextMenu, s_highlightedAddress, 0 );
+}
+
+void RMB::fillContextMenu( TQPopupMenu* contextMenu, const TQString & address, int val )
+{
+ KBookmark bookmark = atAddress(address);
+
+ int id;
+
+ // binner:
+ // "Add Bookmark Here" when pointing at a bookmark looks strange and if you
+ // call it you have to close and reopen the menu to see an entry was added?
+ //
+ // TODO rename these, but, message freeze... umm...
+
+// if (bookmark.isGroup()) {
+ id = contextMenu->insertItem( SmallIcon("bookmark_add"), i18n( "Add Bookmark Here" ), recv, TQT_SLOT(slotRMBActionInsert(int)) );
+ contextMenu->setItemParameter( id, val );
+/* }
+ else
+ {
+ id = contextMenu->insertItem( SmallIcon("bookmark_add"), i18n( "Add Bookmark Here" ), recv, TQT_SLOT(slotRMBActionInsert(int)) );
+ contextMenu->setItemParameter( id, val );
+ }*/
+}
+
+void RMB::fillContextMenu2( TQPopupMenu* contextMenu, const TQString & address, int val )
+{
+ KBookmark bookmark = atAddress(address);
+
+ int id;
+
+ if (bookmark.isGroup()) {
+ id = contextMenu->insertItem( i18n( "Open Folder in Bookmark Editor" ), recv, TQT_SLOT(slotRMBActionEditAt(int)) );
+ contextMenu->setItemParameter( id, val );
+ contextMenu->insertSeparator();
+ id = contextMenu->insertItem( SmallIcon("editdelete"), i18n( "Delete Folder" ), recv, TQT_SLOT(slotRMBActionRemove(int)) );
+ contextMenu->setItemParameter( id, val );
+ contextMenu->insertSeparator();
+ id = contextMenu->insertItem( i18n( "Properties" ), recv, TQT_SLOT(slotRMBActionProperties(int)) );
+ contextMenu->setItemParameter( id, val );
+ }
+ else
+ {
+ id = contextMenu->insertItem( i18n( "Copy Link Address" ), recv, TQT_SLOT(slotRMBActionCopyLocation(int)) );
+ contextMenu->setItemParameter( id, val );
+ contextMenu->insertSeparator();
+ id = contextMenu->insertItem( SmallIcon("editdelete"), i18n( "Delete Bookmark" ), recv, TQT_SLOT(slotRMBActionRemove(int)) );
+ contextMenu->setItemParameter( id, val );
+ contextMenu->insertSeparator();
+ id = contextMenu->insertItem( i18n( "Properties" ), recv, TQT_SLOT(slotRMBActionProperties(int)) );
+ contextMenu->setItemParameter( id, val );
+ }
+}
+
+void RMB::slotRMBActionEditAt( int val )
+{
+ kdDebug(7043) << "KBookmarkMenu::slotRMBActionEditAt" << s_highlightedAddress << endl;
+ if (invalid(val)) { hidePopup(); return; }
+
+ KBookmark bookmark = atAddress(s_highlightedAddress);
+
+ m_pManager->slotEditBookmarksAtAddress( s_highlightedAddress );
+}
+
+void RMB::slotRMBActionProperties( int val )
+{
+ kdDebug(7043) << "KBookmarkMenu::slotRMBActionProperties" << s_highlightedAddress << endl;
+ if (invalid(val)) { hidePopup(); return; }
+
+ KBookmark bookmark = atAddress(s_highlightedAddress);
+
+ TQString folder = bookmark.isGroup() ? TQString::null : bookmark.url().pathOrURL();
+ KBookmarkEditDialog dlg( bookmark.fullText(), folder,
+ m_pManager, KBookmarkEditDialog::ModifyMode, 0,
+ 0, 0, i18n("Bookmark Properties") );
+ if ( dlg.exec() != KDialogBase::Accepted )
+ return;
+
+ makeTextNodeMod(bookmark, "title", dlg.finalTitle());
+ if ( !dlg.finalUrl().isNull() )
+ {
+ KURL u = KURL::fromPathOrURL(dlg.finalUrl());
+ bookmark.internalElement().setAttribute("href", u.url(0, 106));
+ }
+
+ kdDebug(7043) << "Requested move to " << dlg.finalAddress() << "!" << endl;
+
+ KBookmarkGroup parentBookmark = atAddress(m_parentAddress).toGroup();
+ m_pManager->emitChanged( parentBookmark );
+}
+
+void RMB::slotRMBActionInsert( int val )
+{
+ kdDebug(7043) << "KBookmarkMenu::slotRMBActionInsert" << s_highlightedAddress << endl;
+ if (invalid(val)) { hidePopup(); return; }
+
+ TQString url = m_pOwner->currentURL();
+ if (url.isEmpty())
+ {
+ KMessageBox::error( 0L, i18n("Cannot add bookmark with empty URL."));
+ return;
+ }
+ TQString title = m_pOwner->currentTitle();
+ if (title.isEmpty())
+ title = url;
+
+ KBookmark bookmark = atAddress( s_highlightedAddress );
+
+ // TODO use unique title
+
+ if (bookmark.isGroup())
+ {
+ KBookmarkGroup parentBookmark = bookmark.toGroup();
+ Q_ASSERT(!parentBookmark.isNull());
+ parentBookmark.addBookmark( m_pManager, title, KURL( url ) );
+ m_pManager->emitChanged( parentBookmark );
+ }
+ else
+ {
+ KBookmarkGroup parentBookmark = bookmark.parentGroup();
+ Q_ASSERT(!parentBookmark.isNull());
+ KBookmark newBookmark = parentBookmark.addBookmark( m_pManager, title, KURL( url ) );
+ parentBookmark.moveItem( newBookmark, parentBookmark.previous(bookmark) );
+ m_pManager->emitChanged( parentBookmark );
+ }
+}
+
+void RMB::slotRMBActionRemove( int val )
+{
+ //kdDebug(7043) << "KBookmarkMenu::slotRMBActionRemove" << s_highlightedAddress << endl;
+ if (invalid(val)) { hidePopup(); return; }
+
+ KBookmark bookmark = atAddress( s_highlightedAddress );
+ bool folder = bookmark.isGroup();
+
+ if (KMessageBox::warningContinueCancel(
+ m_parentMenu,
+ folder ? i18n("Are you sure you wish to remove the bookmark folder\n\"%1\"?").arg(bookmark.text())
+ : i18n("Are you sure you wish to remove the bookmark\n\"%1\"?").arg(bookmark.text()),
+ folder ? i18n("Bookmark Folder Deletion")
+ : i18n("Bookmark Deletion"),
+ KStdGuiItem::del())
+ != KMessageBox::Continue
+ )
+ return;
+
+ KBookmarkGroup parentBookmark = atAddress( m_parentAddress ).toGroup();
+ parentBookmark.deleteBookmark( bookmark );
+ m_pManager->emitChanged( parentBookmark );
+ if (m_parentMenu)
+ m_parentMenu->hide();
+}
+
+void RMB::slotRMBActionCopyLocation( int val )
+{
+ //kdDebug(7043) << "KBookmarkMenu::slotRMBActionCopyLocation" << s_highlightedAddress << endl;
+ if (invalid(val)) { hidePopup(); return; }
+
+ KBookmark bookmark = atAddress( s_highlightedAddress );
+
+ if ( !bookmark.isGroup() )
+ {
+ kapp->clipboard()->setData( KBookmarkDrag::newDrag(bookmark, 0),
+ TQClipboard::Selection );
+ kapp->clipboard()->setData( KBookmarkDrag::newDrag(bookmark, 0),
+ TQClipboard::Clipboard );
+ }
+}
+
+void RMB::hidePopup() {
+ KPopupMenu::contextMenuFocus()->hideContextMenu();
+}
+
+/********************************************************************/
+/********************************************************************/
+/********************************************************************/
+
+void KBookmarkMenu::fillContextMenu( TQPopupMenu* contextMenu, const TQString & address, int val )
+{
+ RMB::begin_rmb_action(this);
+ rmbSelf(this)->fillContextMenu(contextMenu, address, val);
+ emit aboutToShowContextMenu( rmbSelf(this)->atAddress(address), contextMenu);
+ rmbSelf(this)->fillContextMenu2(contextMenu, address, val);
+}
+
+void KBookmarkMenu::slotRMBActionEditAt( int val )
+{ RMB::begin_rmb_action(this); rmbSelf(this)->slotRMBActionEditAt( val ); }
+
+void KBookmarkMenu::slotRMBActionProperties( int val )
+{ RMB::begin_rmb_action(this); rmbSelf(this)->slotRMBActionProperties( val ); }
+
+void KBookmarkMenu::slotRMBActionInsert( int val )
+{ RMB::begin_rmb_action(this); rmbSelf(this)->slotRMBActionInsert( val ); }
+
+void KBookmarkMenu::slotRMBActionRemove( int val )
+{ RMB::begin_rmb_action(this); rmbSelf(this)->slotRMBActionRemove( val ); }
+
+void KBookmarkMenu::slotRMBActionCopyLocation( int val )
+{ RMB::begin_rmb_action(this); rmbSelf(this)->slotRMBActionCopyLocation( val ); }
+
+void KBookmarkMenu::slotBookmarksChanged( const TQString & groupAddress )
+{
+ if (m_bNSBookmark)
+ return;
+
+ if ( groupAddress == m_parentAddress )
+ {
+ //kdDebug(7043) << "KBookmarkMenu::slotBookmarksChanged -> setting m_bDirty on " << groupAddress << endl;
+ m_bDirty = true;
+ }
+ else
+ {
+ // Iterate recursively into child menus
+ TQPtrListIterator<KBookmarkMenu> it( m_lstSubMenus );
+ for (; it.current(); ++it )
+ {
+ it.current()->slotBookmarksChanged( groupAddress );
+ }
+ }
+}
+
+void KBookmarkMenu::refill()
+{
+ //kdDebug(7043) << "KBookmarkMenu::refill()" << endl;
+ m_lstSubMenus.clear();
+
+ TQPtrListIterator<KAction> it( m_actions );
+ for (; it.current(); ++it )
+ it.current()->unplug( m_parentMenu );
+
+ m_parentMenu->clear();
+ m_actions.clear();
+
+ fillBookmarkMenu();
+ m_parentMenu->adjustSize();
+}
+
+void KBookmarkMenu::addAddBookmarksList()
+{
+ if (!kapp->authorizeKAction("bookmarks"))
+ return;
+
+ TQString title = i18n( "Bookmark Tabs as Folder..." );
+
+ KAction * paAddBookmarksList = new KAction( title,
+ "bookmarks_list_add",
+ 0,
+ this,
+ TQT_SLOT( slotAddBookmarksList() ),
+ m_actionCollection, m_bIsRoot ? "add_bookmarks_list" : 0 );
+
+ paAddBookmarksList->setToolTip( i18n( "Add a folder of bookmarks for all open tabs." ) );
+
+ paAddBookmarksList->plug( m_parentMenu );
+ m_actions.append( paAddBookmarksList );
+}
+
+void KBookmarkMenu::addAddBookmark()
+{
+ if (!kapp->authorizeKAction("bookmarks"))
+ return;
+
+ TQString title = i18n( "Add Bookmark" );
+
+ KAction * paAddBookmarks = new KAction( title,
+ "bookmark_add",
+ m_bIsRoot && m_bAddShortcuts ? KStdAccel::addBookmark() : KShortcut(),
+ this,
+ TQT_SLOT( slotAddBookmark() ),
+ m_actionCollection, m_bIsRoot ? "add_bookmark" : 0 );
+
+ paAddBookmarks->setToolTip( i18n( "Add a bookmark for the current document" ) );
+
+ paAddBookmarks->plug( m_parentMenu );
+ m_actions.append( paAddBookmarks );
+}
+
+void KBookmarkMenu::addEditBookmarks()
+{
+ if (!kapp->authorizeKAction("bookmarks"))
+ return;
+
+ KAction * m_paEditBookmarks = KStdAction::editBookmarks( m_pManager, TQT_SLOT( slotEditBookmarks() ),
+ m_actionCollection, "edit_bookmarks" );
+ m_paEditBookmarks->plug( m_parentMenu );
+ m_paEditBookmarks->setToolTip( i18n( "Edit your bookmark collection in a separate window" ) );
+ m_actions.append( m_paEditBookmarks );
+}
+
+void KBookmarkMenu::addNewFolder()
+{
+ if (!kapp->authorizeKAction("bookmarks"))
+ return;
+
+ TQString title = i18n( "&New Bookmark Folder..." );
+ int p;
+ while ( ( p = title.find( '&' ) ) >= 0 )
+ title.remove( p, 1 );
+
+ KAction * paNewFolder = new KAction( title,
+ "folder_new", //"folder",
+ 0,
+ this,
+ TQT_SLOT( slotNewFolder() ),
+ m_actionCollection );
+
+ paNewFolder->setToolTip( i18n( "Create a new bookmark folder in this menu" ) );
+
+ paNewFolder->plug( m_parentMenu );
+ m_actions.append( paNewFolder );
+}
+
+void KBookmarkMenu::fillBookmarkMenu()
+{
+ if (!kapp->authorizeKAction("bookmarks"))
+ return;
+
+ if ( m_bIsRoot )
+ {
+ if ( m_bAddBookmark )
+ {
+ addAddBookmark();
+ if ( extOwner() )
+ addAddBookmarksList(); // FIXME
+ }
+
+ addEditBookmarks();
+
+ if ( m_bAddBookmark && !KBookmarkSettings::self()->m_advancedaddbookmark )
+ addNewFolder();
+ }
+
+ if ( m_bIsRoot
+ && KBookmarkManager::userBookmarksFile() == m_pManager->path() )
+ {
+ bool haveSep = false;
+
+ TQValueList<TQString> keys = KBookmarkMenu::dynamicBookmarksList();
+ TQValueList<TQString>::const_iterator it;
+ for ( it = keys.begin(); it != keys.end(); ++it )
+ {
+ DynMenuInfo info;
+ info = showDynamicBookmarks((*it));
+
+ if ( !info.show || !TQFile::exists( info.location ) )
+ continue;
+
+ if (!haveSep)
+ {
+ m_parentMenu->insertSeparator();
+ haveSep = true;
+ }
+
+ KActionMenu * actionMenu;
+ actionMenu = new KImportedBookmarksActionMenu(
+ info.name, info.type,
+ m_actionCollection, "kbookmarkmenu" );
+
+ actionMenu->setProperty( "type", info.type );
+ actionMenu->setProperty( "location", info.location );
+
+ actionMenu->plug( m_parentMenu );
+ m_actions.append( actionMenu );
+
+ KBookmarkMenu *subMenu =
+ new KBookmarkMenu( m_pManager, m_pOwner, actionMenu->popupMenu(),
+ m_actionCollection, false,
+ m_bAddBookmark, TQString::null );
+ connect( subMenu, TQT_SIGNAL( openBookmark( const TQString &, TQt::ButtonState ) ),
+ this, TQT_SIGNAL( openBookmark( const TQString &, TQt::ButtonState ) ));
+ m_lstSubMenus.append(subMenu);
+
+ connect(actionMenu->popupMenu(), TQT_SIGNAL(aboutToShow()), subMenu, TQT_SLOT(slotNSLoad()));
+ }
+ }
+
+ KBookmarkGroup parentBookmark = m_pManager->findByAddress( m_parentAddress ).toGroup();
+ Q_ASSERT(!parentBookmark.isNull());
+ bool separatorInserted = false;
+ for ( KBookmark bm = parentBookmark.first(); !bm.isNull(); bm = parentBookmark.next(bm) )
+ {
+ TQString text = KStringHandler::csqueeze(bm.fullText(), 60);
+ text.replace( '&', "&&" );
+ if ( !separatorInserted && m_bIsRoot) {
+ // inserted before the first konq bookmark, to avoid the separator if no konq bookmark
+ m_parentMenu->insertSeparator();
+ separatorInserted = true;
+ }
+ if ( !bm.isGroup() )
+ {
+ if ( bm.isSeparator() )
+ {
+ m_parentMenu->insertSeparator();
+ }
+ else
+ {
+ //kdDebug(7043) << "Creating URL bookmark menu item for " << bm.text() << endl;
+ KAction * action = new KBookmarkAction( text, bm.icon(), 0, m_actionCollection, 0 );
+ connect(action, TQT_SIGNAL( activated ( KAction::ActivationReason, TQt::ButtonState )),
+ this, TQT_SLOT( slotBookmarkSelected( KAction::ActivationReason, TQt::ButtonState ) ));
+
+ action->setProperty( "url", bm.url().url() );
+ action->setProperty( "address", bm.address() );
+
+ action->setToolTip( bm.url().pathOrURL() );
+
+ action->plug( m_parentMenu );
+ m_actions.append( action );
+ }
+ }
+ else
+ {
+ //kdDebug(7043) << "Creating bookmark submenu named " << bm.text() << endl;
+ KActionMenu * actionMenu = new KBookmarkActionMenu( text, bm.icon(),
+ m_actionCollection,
+ "kbookmarkmenu" );
+ actionMenu->setProperty( "address", bm.address() );
+ actionMenu->plug( m_parentMenu );
+ m_actions.append( actionMenu );
+
+ KBookmarkMenu *subMenu = new KBookmarkMenu( m_pManager, m_pOwner, actionMenu->popupMenu(),
+ m_actionCollection, false,
+ m_bAddBookmark,
+ bm.address() );
+
+ connect(subMenu, TQT_SIGNAL( aboutToShowContextMenu( const KBookmark &, TQPopupMenu * ) ),
+ this, TQT_SIGNAL( aboutToShowContextMenu( const KBookmark &, TQPopupMenu * ) ));
+ connect(subMenu, TQT_SIGNAL( openBookmark( const TQString &, TQt::ButtonState ) ),
+ this, TQT_SIGNAL( openBookmark( const TQString &, TQt::ButtonState ) ));
+ m_lstSubMenus.append( subMenu );
+ }
+ }
+
+ if ( !m_bIsRoot && m_bAddBookmark )
+ {
+ if ( m_parentMenu->count() > 0 )
+ m_parentMenu->insertSeparator();
+
+ if ( KBookmarkSettings::self()->m_quickactions )
+ {
+ KActionMenu * actionMenu = new KActionMenu( i18n("Quick Actions"), m_actionCollection, 0L );
+ fillContextMenu( actionMenu->popupMenu(), m_parentAddress, 1 );
+ actionMenu->plug( m_parentMenu );
+ m_actions.append( actionMenu );
+ }
+ else
+ {
+ addAddBookmark();
+ if ( extOwner() )
+ addAddBookmarksList(); // FIXME
+ addNewFolder();
+ }
+ }
+}
+
+void KBookmarkMenu::slotAddBookmarksList()
+{
+ KExtendedBookmarkOwner *extOwner = dynamic_cast<KExtendedBookmarkOwner*>(m_pOwner);
+ if (!extOwner)
+ {
+ kdWarning() << "erm, sorry ;-)" << endl;
+ return;
+ }
+
+ KExtendedBookmarkOwner::QStringPairList list;
+ extOwner->fillBookmarksList( list );
+
+ KBookmarkGroup parentBookmark = m_pManager->findByAddress( m_parentAddress ).toGroup();
+ Q_ASSERT(!parentBookmark.isNull());
+ KBookmarkGroup group = parentBookmark.createNewFolder( m_pManager );
+ if ( group.isNull() )
+ return; // user canceled i guess
+
+ KExtendedBookmarkOwner::QStringPairList::const_iterator it;
+ for ( it = list.begin(); it != list.end(); ++it )
+ group.addBookmark( m_pManager, (*it).first, KURL((*it).second) );
+
+ m_pManager->emitChanged( parentBookmark );
+}
+
+
+void KBookmarkMenu::slotAddBookmark()
+{
+ KBookmarkGroup parentBookmark;
+ parentBookmark = m_pManager->addBookmarkDialog(m_pOwner->currentURL(), m_pOwner->currentTitle(), m_parentAddress);
+ if (!parentBookmark.isNull())
+ m_pManager->emitChanged( parentBookmark );
+}
+
+void KBookmarkMenu::slotNewFolder()
+{
+ if ( !m_pOwner ) return; // this view doesn't handle bookmarks...
+ KBookmarkGroup parentBookmark = m_pManager->findByAddress( m_parentAddress ).toGroup();
+ Q_ASSERT(!parentBookmark.isNull());
+ KBookmarkGroup group = parentBookmark.createNewFolder( m_pManager );
+ if ( !group.isNull() )
+ {
+ KBookmarkGroup parentGroup = group.parentGroup();
+ m_pManager->emitChanged( parentGroup );
+ }
+}
+
+void KBookmarkMenu::slotBookmarkSelected( KAction::ActivationReason /*reason*/, TQt::ButtonState state )
+{
+ kdDebug(7043) << "KBookmarkMenu::slotBookmarkSelected()" << endl;
+ if ( !m_pOwner ) return; // this view doesn't handle bookmarks...
+ const KAction* action = dynamic_cast<const KAction *>(sender());
+ if(action)
+ {
+ const TQString& url = sender()->property("url").toString();
+ m_pOwner->openBookmarkURL( url );
+ emit openBookmark( url, state );
+ }
+}
+
+void KBookmarkMenu::slotBookmarkSelected()
+{
+ slotBookmarkSelected(KAction::PopupMenuActivation, Qt::NoButton);
+}
+
+KExtendedBookmarkOwner* KBookmarkMenu::extOwner()
+{
+ return dynamic_cast<KExtendedBookmarkOwner*>(m_pOwner);
+}
+
+void KBookmarkMenu::slotNSLoad()
+{
+ // only fill menu once
+ m_parentMenu->disconnect(TQT_SIGNAL(aboutToShow()));
+
+ // not NSImporter, but kept old name for BC reasons
+ KBookmarkMenuNSImporter importer( m_pManager, this, m_actionCollection );
+ importer.openBookmarks(s_highlightedImportLocation, s_highlightedImportType);
+}
+
+/********************************************************************/
+/********************************************************************/
+/********************************************************************/
+
+KBookmarkEditFields::KBookmarkEditFields(TQWidget *main, TQBoxLayout *vbox, FieldsSet fieldsSet)
+{
+ bool isF = (fieldsSet != FolderFieldsSet);
+
+ TQGridLayout *grid = new TQGridLayout( vbox, 2, isF ? 2 : 1 );
+
+ m_title = new KLineEdit( main );
+ grid->addWidget( m_title, 0, 1 );
+ grid->addWidget( new TQLabel( m_title, i18n( "Name:" ), main ), 0, 0 );
+ m_title->setFocus();
+ if (isF)
+ {
+ m_url = new KLineEdit( main );
+ grid->addWidget( m_url, 1, 1 );
+ grid->addWidget( new TQLabel( m_url, i18n( "Location:" ), main ), 1, 0 );
+ }
+ else
+ {
+ m_url = 0;
+ }
+
+ main->setMinimumSize( 300, 0 );
+}
+
+void KBookmarkEditFields::setName(const TQString &str)
+{
+ m_title->setText(str);
+}
+
+void KBookmarkEditFields::setLocation(const TQString &str)
+{
+ m_url->setText(str);
+}
+
+/********************************************************************/
+/********************************************************************/
+/********************************************************************/
+
+// TODO - make the dialog use Properties as a title when in Modify mode... (dirk noticed the bug...)
+KBookmarkEditDialog::KBookmarkEditDialog(const TQString& title, const TQString& url, KBookmarkManager * mgr, BookmarkEditType editType, const TQString& address,
+ TQWidget * parent, const char * name, const TQString& caption )
+ : KDialogBase(parent, name, true, caption,
+ (editType == InsertionMode) ? (User1|Ok|Cancel) : (Ok|Cancel),
+ Ok, false, KGuiItem()),
+ m_folderTree(0), m_mgr(mgr), m_editType(editType), m_address(address)
+{
+ setButtonOK( (editType == InsertionMode) ? KGuiItem( i18n( "&Add" ), "bookmark_add") : i18n( "&Update" ) );
+ if (editType == InsertionMode) {
+ setButtonGuiItem( User1, KGuiItem( i18n( "&New Folder..." ), "folder_new") );
+ }
+
+ bool folder = url.isNull();
+
+ m_main = new TQWidget( this );
+ setMainWidget( m_main );
+
+ TQBoxLayout *vbox = new TQVBoxLayout( m_main, 0, spacingHint() );
+ KBookmarkEditFields::FieldsSet fs =
+ folder ? KBookmarkEditFields::FolderFieldsSet
+ : KBookmarkEditFields::BookmarkFieldsSet;
+ m_fields = new KBookmarkEditFields(m_main, vbox, fs);
+ m_fields->setName(title);
+ if ( !folder )
+ m_fields->setLocation(url);
+
+ if ( editType == InsertionMode )
+ {
+ m_folderTree = KBookmarkFolderTree::createTree( m_mgr, m_main, name, m_address );
+ connect( m_folderTree, TQT_SIGNAL( doubleClicked(TQListViewItem*) ),
+ this, TQT_SLOT( slotDoubleClicked(TQListViewItem*) ) );
+ vbox->addWidget( m_folderTree );
+ connect( this, TQT_SIGNAL( user1Clicked() ), TQT_SLOT( slotUser1() ) );
+ }
+}
+
+void KBookmarkEditDialog::slotDoubleClicked( TQListViewItem* item )
+{
+ Q_ASSERT( m_folderTree );
+ m_folderTree->setCurrentItem( item );
+ accept();
+}
+
+void KBookmarkEditDialog::slotOk()
+{
+ accept();
+}
+
+void KBookmarkEditDialog::slotCancel()
+{
+ reject();
+}
+
+TQString KBookmarkEditDialog::finalAddress() const
+{
+ Q_ASSERT( m_folderTree );
+ return KBookmarkFolderTree::selectedAddress( m_folderTree );
+}
+
+TQString KBookmarkEditDialog::finalUrl() const
+{
+ return m_fields->m_url ? m_fields->m_url->text() : TQString::null;
+}
+
+TQString KBookmarkEditDialog::finalTitle() const
+{
+ return m_fields->m_title ? m_fields->m_title->text() : TQString::null;
+}
+
+void KBookmarkEditDialog::slotUser1()
+{
+ // kdDebug(7043) << "KBookmarkEditDialog::slotUser1" << endl;
+ Q_ASSERT( m_folderTree );
+
+ TQString address = KBookmarkFolderTree::selectedAddress( m_folderTree );
+ if ( address.isNull() ) return;
+ KBookmarkGroup bm = m_mgr->findByAddress( address ).toGroup();
+ Q_ASSERT(!bm.isNull());
+ Q_ASSERT(m_editType == InsertionMode);
+
+ KBookmarkGroup group = bm.createNewFolder( m_mgr );
+ if ( !group.isNull() )
+ {
+ KBookmarkGroup parentGroup = group.parentGroup();
+ m_mgr->emitChanged( parentGroup );
+ }
+ KBookmarkFolderTree::fillTree( m_folderTree, m_mgr );
+}
+
+/********************************************************************/
+/********************************************************************/
+/********************************************************************/
+
+static void fillGroup( TQListView* listview, KBookmarkFolderTreeItem * parentItem, KBookmarkGroup group, bool expandOpenGroups = true, const TQString& address = TQString::null )
+{
+ bool noSubGroups = true;
+ KBookmarkFolderTreeItem * lastItem = 0L;
+ KBookmarkFolderTreeItem * item = 0L;
+ for ( KBookmark bk = group.first() ; !bk.isNull() ; bk = group.next(bk) )
+ {
+ if ( bk.isGroup() )
+ {
+ KBookmarkGroup grp = bk.toGroup();
+ item = new KBookmarkFolderTreeItem( parentItem, lastItem, grp );
+ fillGroup( listview, item, grp, expandOpenGroups, address );
+ if ( expandOpenGroups && grp.isOpen() )
+ item->setOpen( true );
+ lastItem = item;
+ noSubGroups = false;
+ }
+ if (bk.address() == address) {
+ listview->setCurrentItem( lastItem );
+ listview->ensureItemVisible( item );
+ }
+ }
+ if ( noSubGroups ) {
+ parentItem->setOpen( true );
+ }
+}
+
+TQListView* KBookmarkFolderTree::createTree( KBookmarkManager* mgr, TQWidget* parent, const char* name, const TQString& address )
+{
+ TQListView *listview = new TQListView( parent, name );
+
+ listview->setRootIsDecorated( false );
+ listview->header()->hide();
+ listview->addColumn( i18n("Bookmark"), 200 );
+ listview->setSorting( -1, false );
+ listview->setSelectionMode( TQListView::Single );
+ listview->setAllColumnsShowFocus( true );
+ listview->setResizeMode( TQListView::AllColumns );
+ listview->setMinimumSize( 60, 100 );
+
+ fillTree( listview, mgr, address );
+
+ return listview;
+}
+
+void KBookmarkFolderTree::fillTree( TQListView *listview, KBookmarkManager* mgr, const TQString& address )
+{
+ listview->clear();
+
+ KBookmarkGroup root = mgr->root();
+ KBookmarkFolderTreeItem * rootItem = new KBookmarkFolderTreeItem( listview, root );
+ listview->setCurrentItem( rootItem );
+ rootItem->setSelected( true );
+ fillGroup( listview, rootItem, root, (address == root.groupAddress() || address.isNull()) ? true : false, address );
+ rootItem->setOpen( true );
+}
+
+static KBookmarkFolderTreeItem* ft_cast( TQListViewItem *i )
+{
+ return static_cast<KBookmarkFolderTreeItem*>( i );
+}
+
+TQString KBookmarkFolderTree::selectedAddress( TQListView *listview )
+{
+ if ( !listview)
+ return TQString::null;
+ KBookmarkFolderTreeItem *item = ft_cast( listview->currentItem() );
+ return item ? item->m_bookmark.address() : TQString::null;
+}
+
+void KBookmarkFolderTree::setAddress( TQListView *listview, const TQString & address )
+{
+ KBookmarkFolderTreeItem* it = ft_cast( listview->firstChild() );
+ while ( true ) {
+ kdDebug(7043) << it->m_bookmark.address() << endl;
+ it = ft_cast( it->itemBelow() );
+ if ( !it )
+ return;
+ if ( it->m_bookmark.address() == address )
+ break;
+ }
+ it->setSelected( true );
+ listview->setCurrentItem( it );
+}
+
+/********************************************************************/
+/********************************************************************/
+/********************************************************************/
+
+// toplevel item
+KBookmarkFolderTreeItem::KBookmarkFolderTreeItem( TQListView *parent, const KBookmark & gp )
+ : TQListViewItem(parent, i18n("Bookmarks")), m_bookmark(gp)
+{
+ setPixmap(0, SmallIcon("bookmark"));
+ setExpandable(true);
+}
+
+// group
+KBookmarkFolderTreeItem::KBookmarkFolderTreeItem( KBookmarkFolderTreeItem *parent, TQListViewItem *after, const KBookmarkGroup & gp )
+ : TQListViewItem(parent, after, gp.fullText()), m_bookmark(gp)
+{
+ setPixmap(0, SmallIcon( gp.icon() ) );
+ setExpandable(true);
+}
+
+/********************************************************************/
+/********************************************************************/
+/********************************************************************/
+
+// NOTE - KBookmarkMenuNSImporter is really === KBookmarkMenuImporter
+// i.e, it is _not_ ns specific. and in KDE4 it should be renamed.
+
+void KBookmarkMenuNSImporter::openNSBookmarks()
+{
+ openBookmarks( KNSBookmarkImporter::netscapeBookmarksFile(), "netscape" );
+}
+
+void KBookmarkMenuNSImporter::openBookmarks( const TQString &location, const TQString &type )
+{
+ mstack.push(m_menu);
+
+ KBookmarkImporterBase *importer = KBookmarkImporterBase::factory(type);
+ if (!importer)
+ return;
+ importer->setFilename(location);
+ connectToImporter(*importer);
+ importer->parse();
+
+ delete importer;
+}
+
+void KBookmarkMenuNSImporter::connectToImporter(const TQObject &importer)
+{
+ connect( &importer, TQT_SIGNAL( newBookmark( const TQString &, const TQCString &, const TQString & ) ),
+ TQT_SLOT( newBookmark( const TQString &, const TQCString &, const TQString & ) ) );
+ connect( &importer, TQT_SIGNAL( newFolder( const TQString &, bool, const TQString & ) ),
+ TQT_SLOT( newFolder( const TQString &, bool, const TQString & ) ) );
+ connect( &importer, TQT_SIGNAL( newSeparator() ), TQT_SLOT( newSeparator() ) );
+ connect( &importer, TQT_SIGNAL( endFolder() ), TQT_SLOT( endFolder() ) );
+}
+
+void KBookmarkMenuNSImporter::newBookmark( const TQString & text, const TQCString & url, const TQString & )
+{
+ TQString _text = KStringHandler::csqueeze(text);
+ _text.replace( '&', "&&" );
+ KAction * action = new KBookmarkAction(_text, "html", 0, 0, "", m_actionCollection, 0);
+ connect(action, TQT_SIGNAL( activated ( KAction::ActivationReason, TQt::ButtonState )),
+ m_menu, TQT_SLOT( slotBookmarkSelected( KAction::ActivationReason, TQt::ButtonState ) ));
+ action->setProperty( "url", url );
+ action->setToolTip( url );
+ action->plug( mstack.top()->m_parentMenu );
+ mstack.top()->m_actions.append( action );
+}
+
+void KBookmarkMenuNSImporter::newFolder( const TQString & text, bool, const TQString & )
+{
+ TQString _text = KStringHandler::csqueeze(text);
+ _text.replace( '&', "&&" );
+ KActionMenu * actionMenu = new KActionMenu( _text, "folder", m_actionCollection, 0L );
+ actionMenu->plug( mstack.top()->m_parentMenu );
+ mstack.top()->m_actions.append( actionMenu );
+ KBookmarkMenu *subMenu = new KBookmarkMenu( m_pManager, m_menu->m_pOwner, actionMenu->popupMenu(),
+ m_actionCollection, false,
+ m_menu->m_bAddBookmark, TQString::null );
+ connect( subMenu, TQT_SIGNAL( openBookmark( const TQString &, TQt::ButtonState ) ),
+ m_menu, TQT_SIGNAL( openBookmark( const TQString &, TQt::ButtonState ) ));
+ mstack.top()->m_lstSubMenus.append( subMenu );
+
+ mstack.push(subMenu);
+}
+
+void KBookmarkMenuNSImporter::newSeparator()
+{
+ mstack.top()->m_parentMenu->insertSeparator();
+}
+
+void KBookmarkMenuNSImporter::endFolder()
+{
+ mstack.pop();
+}
+
+/********************************************************************/
+/********************************************************************/
+/********************************************************************/
+
+KBookmarkMenu::DynMenuInfo KBookmarkMenu::showDynamicBookmarks( const TQString &id )
+{
+ TDEConfig config("kbookmarkrc", false, false);
+ config.setGroup("Bookmarks");
+
+ DynMenuInfo info;
+ info.show = false;
+
+ if (!config.hasKey("DynamicMenus")) {
+ // upgrade path
+ if (id == "netscape") {
+ KBookmarkManager *manager = KBookmarkManager::userBookmarksManager();
+ info.show = manager->root().internalElement().attribute("hide_nsbk") != "yes";
+ info.location = KNSBookmarkImporter::netscapeBookmarksFile();
+ info.type = "netscape";
+ info.name = i18n("Netscape Bookmarks");
+ } // else, no show
+
+ } else {
+ // have new version config
+ if (config.hasGroup("DynamicMenu-" + id)) {
+ config.setGroup("DynamicMenu-" + id);
+ info.show = config.readBoolEntry("Show");
+ info.location = config.readPathEntry("Location");
+ info.type = config.readEntry("Type");
+ info.name = config.readEntry("Name");
+ } // else, no show
+ }
+
+ return info;
+}
+
+TQStringList KBookmarkMenu::dynamicBookmarksList()
+{
+ TDEConfig config("kbookmarkrc", false, false);
+ config.setGroup("Bookmarks");
+
+ TQStringList mlist;
+ if (config.hasKey("DynamicMenus"))
+ mlist = config.readListEntry("DynamicMenus");
+ else
+ mlist << "netscape";
+
+ return mlist;
+}
+
+void KBookmarkMenu::setDynamicBookmarks(const TQString &id, const DynMenuInfo &newMenu)
+{
+ TDEConfig config("kbookmarkrc", false, false);
+
+ // add group unconditionally
+ config.setGroup("DynamicMenu-" + id);
+ config.writeEntry("Show", newMenu.show);
+ config.writePathEntry("Location", newMenu.location);
+ config.writeEntry("Type", newMenu.type);
+ config.writeEntry("Name", newMenu.name);
+
+ TQStringList elist;
+
+ config.setGroup("Bookmarks");
+ if (!config.hasKey("DynamicMenus")) {
+ if (newMenu.type != "netscape") {
+ // update from old xbel method to new rc method
+ // though only if not writing the netscape setting
+ config.setGroup("DynamicMenu-" "netscape");
+ DynMenuInfo xbelSetting;
+ xbelSetting = showDynamicBookmarks("netscape");
+ config.writeEntry("Show", xbelSetting.show);
+ config.writePathEntry("Location", xbelSetting.location);
+ config.writeEntry("Type", xbelSetting.type);
+ config.writeEntry("Name", xbelSetting.name);
+ }
+ } else {
+ elist = config.readListEntry("DynamicMenus");
+ }
+
+ // make sure list includes type
+ config.setGroup("Bookmarks");
+ if (elist.contains(id) < 1) {
+ elist << id;
+ config.writeEntry("DynamicMenus", elist);
+ }
+
+ config.sync();
+}
+
+#include "kbookmarkmenu.moc"
+#include "kbookmarkmenu_p.moc"
diff --git a/tdeio/bookmarks/kbookmarkmenu.h b/tdeio/bookmarks/kbookmarkmenu.h
new file mode 100644
index 000000000..35e6191e3
--- /dev/null
+++ b/tdeio/bookmarks/kbookmarkmenu.h
@@ -0,0 +1,265 @@
+// -*- c-basic-offset:4; indent-tabs-mode:nil -*-
+// vim: set ts=4 sts=4 sw=4 et:
+/* This file is part of the KDE project
+ 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., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef __kbookmarkmenu_h__
+#define __kbookmarkmenu_h__
+
+#include <sys/types.h>
+
+#include <tqptrlist.h>
+#include <tqptrstack.h>
+#include <tqobject.h>
+#include <tqlistview.h>
+
+#include <kdialogbase.h>
+#include <klocale.h>
+#include <kaction.h>
+
+#include "kbookmark.h"
+#include "kbookmarkmanager.h"
+
+class TQString;
+class TQPopupMenu;
+class TQPushButton;
+class TQListView;
+class KLineEdit;
+class KBookmark;
+class KBookmarkGroup;
+class KAction;
+class KActionMenu;
+class KActionCollection;
+class KBookmarkOwner;
+class KBookmarkMenu;
+class KPopupMenu;
+
+namespace TDEIO { class Job; }
+
+/**
+ * This class provides a bookmark menu. It is typically used in
+ * cooperation with KActionMenu but doesn't have to be.
+ *
+ * If you use this class by itself, then it will use KDE defaults for
+ * everything -- the bookmark path, bookmark editor, bookmark launcher..
+ * everything. These defaults reside in the classes
+ * KBookmarkOwner (editing bookmarks) and KBookmarkManager
+ * (almost everything else). If you wish to change the defaults in
+ * any way, you must reimplement and instantiate those classes
+ * <em>before</em> this class is ever called.
+ *
+ * Using this class is very simple:
+ *
+ * 1) Create a popup menu (either KActionMenu or KPopupMenu will do)
+ * 2) Instantiate a new KBookmarkMenu object using the above popup
+ * menu as a parameter
+ * 3) Insert your (now full) popup menu wherever you wish
+ *
+ * Again, if you wish to modify any defaults, the procedure is:
+ *
+ * 1a) Reimplement your own KBookmarkOwner
+ * 1b) Reimplement and instantiate your own KBookmarkManager
+ */
+class TDEIO_EXPORT KBookmarkMenu : public TQObject
+{
+ Q_OBJECT
+ friend class KBookmarkMenuNSImporter;
+ friend class RMB;
+public:
+ /**
+ * Fills a bookmark menu
+ * (one instance of KBookmarkMenu is created for the toplevel menu,
+ * but also one per submenu).
+ *
+ * @param mgr The bookmark manager to use (i.e. for reading and writing)
+ * @param owner implementation of the KBookmarkOwner callback interface.
+ * @param parentMenu menu to be filled
+ * @param collec parent collection for the KActions.
+ * Only used for other menus than the toplevel one.
+ * @param root true for the toplevel menu
+ * @param add true to show the "Add Bookmark" and "New Folder" entries
+ * @param parentAddress the address of the group containing the items
+ * that we want to show.
+ * @see KBookmark::address.
+ * Be careful :
+ * A _null_ parentAddress denotes a NS-bookmark menu.
+ * An _empty_ parentAddress denotes the toplevel bookmark menu
+ */
+ KBookmarkMenu( KBookmarkManager* mgr,
+ KBookmarkOwner * owner, KPopupMenu * parentMenu,
+ KActionCollection * collec, bool root, bool add = true,
+ const TQString & parentAddress = "" );
+
+ ~KBookmarkMenu();
+
+ /**
+ * Even if you think you need to use this, you are probably wrong.
+ * It fills a bookmark menu starting a given KBookmark.
+ * This is public for KBookmarkBar.
+ */
+ void fillBookmarkMenu();
+
+ /**
+ * Call ensureUpToDate() if you need KBookmarkMenu to adjust to its
+ * final size before it is executed.
+ **/
+ void ensureUpToDate();
+
+ /**
+ * Structure used for storing information about
+ * the dynamic menu setting
+ * @since 3.2
+ */
+ // TODO - transform into class
+ struct DynMenuInfo {
+ bool show;
+ TQString location;
+ TQString type;
+ TQString name;
+ class DynMenuInfoPrivate *d;
+ };
+
+ /**
+ * @return dynmenu info block for the given dynmenu name
+ * @since 3.2
+ */
+ static DynMenuInfo showDynamicBookmarks( const TQString &id );
+
+ /**
+ * Shows an extra menu for the given bookmarks file and type.
+ * Upgrades from option inside XBEL to option in rc file
+ * on first call of this function.
+ * @param id the unique identification for the dynamic menu
+ * @param info a DynMenuInfo struct containing the to be added/modified data
+ * @since 3.2
+ */
+ static void setDynamicBookmarks( const TQString &id, const DynMenuInfo &info );
+
+ /**
+ * @return list of dynamic menu ids
+ * @since 3.2
+ */
+ static TQStringList dynamicBookmarksList();
+
+signals:
+ void aboutToShowContextMenu( const KBookmark &, TQPopupMenu * );
+ /**
+ * @since 3.4
+ */
+ void openBookmark( const TQString& url, TQt::ButtonState state );
+
+public slots: // public for bookmark bar
+ void slotBookmarksChanged( const TQString & );
+
+protected slots:
+ void slotAboutToShow();
+ void slotAboutToShowContextMenu( KPopupMenu *, int, TQPopupMenu * );
+ void slotActionHighlighted( KAction * );
+
+ void slotRMBActionRemove( int );
+ void slotRMBActionInsert( int );
+ void slotRMBActionCopyLocation( int );
+ void slotRMBActionEditAt( int );
+ void slotRMBActionProperties( int );
+
+ void slotBookmarkSelected();
+ /**
+ * @ since 3.4
+ */
+ void slotBookmarkSelected( KAction::ActivationReason reason, TQt::ButtonState state );
+ void slotAddBookmarksList();
+ void slotAddBookmark();
+ void slotNewFolder();
+
+ /**
+ * load Netscape's bookmarks
+ */
+ void slotNSLoad();
+
+protected:
+ KExtendedBookmarkOwner* extOwner();
+ void refill();
+ void addAddBookmark();
+ void addAddBookmarksList();
+ void addEditBookmarks();
+ void addNewFolder();
+
+ void fillContextMenu( TQPopupMenu *, const TQString &, int );
+
+ bool m_bIsRoot:1;
+ bool m_bAddBookmark:1;
+ bool m_bDirty:1;
+ bool m_bNSBookmark:1;
+ bool m_bAddShortcuts:1;
+
+ KBookmarkManager * m_pManager;
+ KBookmarkOwner *m_pOwner;
+ /**
+ * The menu in which we plug our actions.
+ * Supplied in the constructor.
+ */
+ KPopupMenu * m_parentMenu;
+ /**
+ * List of our sub menus
+ */
+ TQPtrList<KBookmarkMenu> m_lstSubMenus;
+ KActionCollection * m_actionCollection;
+ /**
+ * List of our actions.
+ */
+ TQPtrList<KAction> m_actions;
+ /**
+ * Parent bookmark for this menu.
+ */
+ TQString m_parentAddress;
+
+ // TODO make non static!
+ static TQString s_highlightedAddress;
+ static TQString s_highlightedImportLocation;
+ static TQString s_highlightedImportType;
+};
+
+/**
+ * A class connected to KNSBookmarkImporter, to fill KActionMenus.
+ */
+class TDEIO_EXPORT KBookmarkMenuNSImporter : public TQObject
+{
+ Q_OBJECT
+public:
+ KBookmarkMenuNSImporter( KBookmarkManager* mgr, KBookmarkMenu * menu, KActionCollection * act ) :
+ m_menu(menu), m_actionCollection(act), m_pManager(mgr) {}
+
+ void openNSBookmarks();
+ void openBookmarks( const TQString &location, const TQString &type );
+ void connectToImporter( const TQObject &importer );
+
+protected slots:
+ void newBookmark( const TQString & text, const TQCString & url, const TQString & );
+ void newFolder( const TQString & text, bool, const TQString & );
+ void newSeparator();
+ void endFolder();
+
+protected:
+ TQPtrStack<KBookmarkMenu> mstack;
+ KBookmarkMenu * m_menu;
+ KActionCollection * m_actionCollection;
+ KBookmarkManager* m_pManager;
+};
+
+#endif
diff --git a/tdeio/bookmarks/kbookmarkmenu_p.h b/tdeio/bookmarks/kbookmarkmenu_p.h
new file mode 100644
index 000000000..cb88607fe
--- /dev/null
+++ b/tdeio/bookmarks/kbookmarkmenu_p.h
@@ -0,0 +1,224 @@
+// -*- c-basic-offset:4; indent-tabs-mode:nil -*-
+// vim: set ts=4 sts=4 sw=4 et:
+/* This file is part of the KDE project
+ Copyright (C) 2003 Alexander Kellett <lypanov@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., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef __kbookmarkmenu_p_h__
+#define __kbookmarkmenu_p_h__
+
+#include <sys/types.h>
+
+#include <tqptrlist.h>
+#include <tqptrstack.h>
+#include <tqobject.h>
+#include <tqlistview.h>
+
+#include <kdialogbase.h>
+#include <klocale.h>
+#include <kaction.h>
+
+#include "kbookmark.h"
+#include "kbookmarkimporter.h"
+#include "kbookmarkmanager.h"
+
+class TQString;
+class TQPopupMenu;
+class TQPushButton;
+class TQListView;
+class KLineEdit;
+class KBookmark;
+class KBookmarkGroup;
+class KAction;
+class KActionMenu;
+class KActionCollection;
+class KBookmarkOwner;
+class KBookmarkMenu;
+class KBookmarkBar;
+class KPopupMenu;
+
+class KImportedBookmarksActionMenu : public KActionMenu {
+ Q_OBJECT
+ TQ_PROPERTY( TQString type READ type WRITE setType )
+ TQ_PROPERTY( TQString location READ location WRITE setLocation )
+public:
+ const TQString type() const { return m_type; }
+ void setType(const TQString &type) { m_type = type; }
+ const TQString location() const { return m_location; }
+ void setLocation(const TQString &location) { m_location = location; }
+private:
+ TQString m_type;
+ TQString m_location;
+public:
+ KImportedBookmarksActionMenu(
+ const TQString &text, const TQString& sIconName,
+ KActionCollection* parent, const char* name)
+ : KActionMenu(text, sIconName, parent, name) {
+ ;
+ }
+};
+
+class KBookmarkActionMenu : public KActionMenu {
+ Q_OBJECT
+ TQ_PROPERTY( TQString url READ url WRITE setUrl )
+ TQ_PROPERTY( TQString address READ address WRITE setAddress )
+ TQ_PROPERTY( bool readOnly READ readOnly WRITE setReadOnly )
+public:
+ const TQString url() const { return m_url; }
+ void setUrl(const TQString &url) { m_url = url; }
+ const TQString address() const { return m_address; }
+ void setAddress(const TQString &address) { m_address = address; }
+ bool readOnly() const { return m_readOnly; }
+ void setReadOnly(bool readOnly) { m_readOnly = readOnly; }
+private:
+ TQString m_url;
+ TQString m_address;
+ bool m_readOnly;
+public:
+ KBookmarkActionMenu(
+ const TQString &text, const TQString& sIconName,
+ KActionCollection* parent, const char* name)
+ : KActionMenu(text, sIconName, parent, name) {
+ ;
+ }
+};
+
+class KBookmarkAction : public KAction {
+ Q_OBJECT
+ TQ_PROPERTY( TQString url READ url WRITE setUrl )
+ TQ_PROPERTY( TQString address READ address WRITE setAddress )
+public:
+ const TQString url() const { return m_url; }
+ void setUrl(const TQString &url) { m_url = url; }
+ const TQString address() const { return m_address; }
+ void setAddress(const TQString &address) { m_address = address; }
+private:
+ TQString m_url;
+ TQString m_address;
+public:
+ // KDE4: remove
+ KBookmarkAction(
+ const TQString& text, const TQString& sIconName, const KShortcut& cut,
+ const TQObject* receiver, const char* slot,
+ KActionCollection* parent, const char* name)
+ : KAction(text, sIconName, cut, receiver, slot, parent, name) {
+ }
+ KBookmarkAction(
+ const TQString& text, const TQString& sIconName, const KShortcut& cut,
+ KActionCollection* parent, const char* name)
+ : KAction(text, sIconName, cut, parent, name) {
+ }
+};
+
+class KBookmarkEditFields {
+public:
+ typedef enum { FolderFieldsSet, BookmarkFieldsSet } FieldsSet;
+ KLineEdit * m_url;
+ KLineEdit * m_title;
+ KBookmarkEditFields(TQWidget *main, TQBoxLayout *vbox, FieldsSet isFolder);
+ void setName(const TQString &str);
+ void setLocation(const TQString &str);
+};
+
+class KBookmarkEditDialog : public KDialogBase
+{
+ Q_OBJECT
+
+public:
+ typedef enum { ModifyMode, InsertionMode } BookmarkEditType;
+
+ KBookmarkEditDialog( const TQString& title, const TQString& url, KBookmarkManager *, BookmarkEditType editType, const TQString& address = TQString::null,
+ TQWidget * = 0, const char * = 0, const TQString& caption = i18n( "Add Bookmark" ) );
+
+ TQString finalUrl() const;
+ TQString finalTitle() const;
+ TQString finalAddress() const;
+
+protected slots:
+ void slotOk();
+ void slotCancel();
+ void slotUser1();
+ void slotDoubleClicked(TQListViewItem* item);
+
+private:
+ TQWidget * m_main;
+ KBookmarkEditFields * m_fields;
+ TQListView * m_folderTree;
+ TQPushButton * m_button;
+ KBookmarkManager * m_mgr;
+ BookmarkEditType m_editType;
+ TQString m_address;
+};
+
+class KBookmarkFolderTreeItem : public TQListViewItem
+{
+ // make this an accessor
+ friend class KBookmarkFolderTree;
+public:
+ KBookmarkFolderTreeItem( TQListView *, const KBookmark & );
+ KBookmarkFolderTreeItem( KBookmarkFolderTreeItem *, TQListViewItem *, const KBookmarkGroup & );
+private:
+ KBookmark m_bookmark;
+};
+
+class KBookmarkFolderTree
+{
+public:
+ static TQListView* createTree( KBookmarkManager *, TQWidget * = 0, const char * = 0, const TQString& = TQString::null );
+ static void fillTree( TQListView*, KBookmarkManager *, const TQString& = TQString::null );
+ static TQString selectedAddress( TQListView* );
+ static void setAddress( TQListView *, const TQString & );
+};
+
+class KBookmarkSettings
+{
+public:
+ bool m_advancedaddbookmark;
+ bool m_contextmenu;
+ bool m_quickactions;
+ bool m_filteredtoolbar;
+ static KBookmarkSettings *s_self;
+ static void readSettings();
+ static KBookmarkSettings *self();
+};
+
+class RMB
+{
+public:
+ static void begin_rmb_action(KBookmarkMenu *);
+ static void begin_rmb_action(KBookmarkBar *);
+ bool invalid( int val );
+ KBookmark atAddress(const TQString & address);
+ void fillContextMenu( TQPopupMenu* contextMenu, const TQString & address, int val );
+ void fillContextMenu2( TQPopupMenu* contextMenu, const TQString & address, int val );
+ void slotRMBActionEditAt( int val );
+ void slotRMBActionProperties( int val );
+ void slotRMBActionInsert( int val );
+ void slotRMBActionRemove( int val );
+ void slotRMBActionCopyLocation( int val );
+ void hidePopup();
+public:
+ TQObject *recv;
+ KBookmarkManager *m_pManager;
+ TQString s_highlightedAddress;
+ TQString m_parentAddress;
+ KBookmarkOwner *m_pOwner;
+ TQWidget *m_parentMenu;
+};
+
+#endif
diff --git a/tdeio/bookmarks/kbookmarknotifier.h b/tdeio/bookmarks/kbookmarknotifier.h
new file mode 100644
index 000000000..f99e570bc
--- /dev/null
+++ b/tdeio/bookmarks/kbookmarknotifier.h
@@ -0,0 +1,45 @@
+// -*- c-basic-offset:4; indent-tabs-mode:nil -*-
+// vim: set ts=4 sts=4 sw=4 et:
+/* This file is part of the KDE libraries
+ Copyright (C) 2001, 2003 Alexander Kellett <lypanov@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., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef __kbookmarknotifier_h__
+#define __kbookmarknotifier_h__
+
+#include <dcopobject.h>
+
+/**
+ * DCOP interface for a bookmark notifier (an object which emits signals
+ * upon changes to the bookmarks)
+ */
+class TDEIO_EXPORT KBookmarkNotifier : virtual public DCOPObject
+{
+ K_DCOP
+
+public:
+ KBookmarkNotifier(TQCString objId = "KBookmarkNotifier") : DCOPObject(objId) {}
+
+k_dcop_signals:
+ void addedBookmark( TQString filename, TQString url, TQString text, TQString address, TQString icon );
+ void createdNewFolder( TQString filename, TQString text, TQString address );
+ void updatedAccessMetadata( TQString filename, TQString url );
+};
+
+#endif
+