Added KBookmark::standaloneBookmark so that Carsten can easily create

a KBookmark from thin air :)
Used it in KBookmarkDrag when receiving a URL drop.

svn path=/trunk/kdebase/libkonq/; revision=74017
This commit is contained in:
David Faure 2000-12-08 23:33:05 +00:00
parent f1060ec395
commit 4a87e5595e
3 changed files with 14 additions and 7 deletions

View file

@ -265,3 +265,13 @@ QString KBookmark::address() const
return "ERROR";
}
}
static KBookmark KBookmark::standaloneBookmark( const QString & text, const KURL & url )
{
QDomDocument doc("xbel");
QDomElement elem = doc.createElement("xbel");
doc.appendChild( elem );
KBookmarkGroup grp( elem );
grp.addBookmark( text, url );
return grp.first();
}

View file

@ -30,6 +30,8 @@ class KBookmark
public:
KBookmark( QDomElement elem ) : element(elem) {}
static KBookmark standaloneBookmark( const QString & text, const KURL & url );
/**
* Whether the bookmark is a group or a normal bookmark
*/

View file

@ -61,7 +61,7 @@ QByteArray KBookmarkDrag::encodedData( const char* mime ) const
return QUriDrag::encodedData( mime );
else if ( mimetype == "application/x-xbel" )
{
QDomDocument doc("xbel"); // plan for the future :)
QDomDocument doc("xbel");
QDomElement elem = doc.createElement("xbel");
doc.appendChild( elem );
elem.appendChild( m_bookmark.internalElement().cloneNode( true /* deep */ ) );
@ -94,15 +94,10 @@ KBookmark KBookmarkDrag::decode( const QMimeSource * e )
KURL::List m_lstDragURLs;
if ( KURLDrag::decode( e, m_lstDragURLs ) )
{
QDomDocument doc("xbel");
QDomElement elem = doc.createElement("xbel");
doc.appendChild( elem );
if ( m_lstDragURLs.count() > 1 )
kdWarning() << "Only first URL inserted, known limitation" << endl;
//kdDebug() << "KBookmarkDrag::decode url=" << m_lstDragURLs.first().url() << endl;
KBookmarkGroup grp( elem );
grp.addBookmark( m_lstDragURLs.first().fileName(), m_lstDragURLs.first().url() );
return grp.first();
return KBookmark::standaloneBookmark( m_lstDragURLs.first().fileName(), m_lstDragURLs.first() );
}
}
return KBookmark(QDomElement());