• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

KIO

kbookmark.cc

Go to the documentation of this file.
00001 // -*- c-basic-offset:4; indent-tabs-mode:nil -*-
00002 // vim: set ts=4 sts=4 sw=4 et:
00003 /* This file is part of the KDE libraries
00004    Copyright (C) 2000 David Faure <faure@kde.org>
00005    Copyright (C) 2003 Alexander Kellett <lypanov@kde.org>
00006    Copyright (C) 2008 Norbert Frese <nf2@scheinwelt.at>
00007 
00008    This library is free software; you can redistribute it and/or
00009    modify it under the terms of the GNU Library General Public
00010    License version 2 as published by the Free Software Foundation.
00011 
00012    This library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Library General Public License for more details.
00016 
00017    You should have received a copy of the GNU Library General Public License
00018    along with this library; see the file COPYING.LIB.  If not, write to
00019    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020    Boston, MA 02110-1301, USA.
00021 */
00022 
00023 #include "kbookmark.h"
00024 #include <QStack>
00025 #include <kdebug.h>
00026 #include <kmimetype.h>
00027 #include <kstringhandler.h>
00028 #include <kglobal.h>
00029 #include <klocale.h>
00030 #include <assert.h>
00031 #include <kbookmarkmanager.h>
00032 
00033 #include <qdatetime.h>
00034 #include <qmimedata.h>
00035 
00036 #define METADATA_KDE_OWNER "http://www.kde.org"
00037 #define METADATA_FREEDESKTOP_OWNER "http://freedesktop.org"
00038 #define METADATA_MIME_OWNER "http://www.freedesktop.org/standards/shared-mime-info"
00039 
00041 
00042 static QDomNode cd(QDomNode node, const QString &name, bool create)
00043 {
00044     QDomNode subnode = node.namedItem(name);
00045     if (create && subnode.isNull())
00046     {
00047         subnode = node.ownerDocument().createElement(name);
00048         node.appendChild(subnode);
00049     }
00050     return subnode;
00051 }
00052 
00053 static QDomNode cd_or_create(QDomNode node, const QString &name)
00054 {
00055     return cd(node, name, true);
00056 }
00057 
00058 static QDomText get_or_create_text(QDomNode node)
00059 {
00060     QDomNode subnode = node.firstChild();
00061     if (subnode.isNull())
00062     {
00063         subnode = node.ownerDocument().createTextNode("");
00064         node.appendChild(subnode);
00065     }
00066     return subnode.toText();
00067 }
00068 
00069 static QDomNode findMetadata(const QString & forOwner, QDomNode& parent, bool create)
00070 {
00071     bool forOwnerIsKDE = forOwner == METADATA_KDE_OWNER;
00072 
00073     QDomElement metadataElement;
00074     for ( QDomNode _node = parent.firstChild(); !_node.isNull(); _node = _node.nextSibling() ) {
00075         QDomElement elem = _node.toElement();
00076         if ( !elem.isNull() && elem.tagName() == "metadata" ) {
00077             const QString owner = elem.attribute( "owner" );
00078             if ( owner == forOwner )
00079                 return elem;
00080             if ( owner.isEmpty() && forOwnerIsKDE )
00081                 metadataElement = elem;
00082         }
00083     }
00084     if ( create && metadataElement.isNull() ) {
00085         metadataElement = parent.ownerDocument().createElement( "metadata" );
00086         parent.appendChild(metadataElement);
00087         metadataElement.setAttribute( "owner", forOwner );
00088 
00089     } else if (!metadataElement.isNull() && forOwnerIsKDE) {
00090         // i'm not sure if this is good, we shouln't take over foreign metatdata
00091         metadataElement.setAttribute( "owner", METADATA_KDE_OWNER );
00092     }
00093     return metadataElement;
00094 }
00095 
00097 
00098 KBookmarkGroup::KBookmarkGroup()
00099  : KBookmark( QDomElement() )
00100 {
00101 }
00102 
00103 KBookmarkGroup::KBookmarkGroup( const QDomElement &elem )
00104  : KBookmark(elem)
00105 {
00106 }
00107 
00108 bool KBookmarkGroup::isOpen() const
00109 {
00110     return element.attribute("folded") == "no"; // default is: folded
00111 }
00112 
00113 KBookmark KBookmarkGroup::first() const
00114 {
00115     return KBookmark( nextKnownTag( element.firstChildElement(), true ) );
00116 }
00117 
00118 KBookmark KBookmarkGroup::previous( const KBookmark & current ) const
00119 {
00120     return KBookmark( nextKnownTag( current.element.previousSiblingElement(), false ) );
00121 }
00122 
00123 KBookmark KBookmarkGroup::next( const KBookmark & current ) const
00124 {
00125     return KBookmark( nextKnownTag( current.element.nextSiblingElement(), true ) );
00126 }
00127 
00128 int KBookmarkGroup::indexOf(const KBookmark& child) const
00129 {
00130     uint counter = 0;
00131     for ( KBookmark bk = first(); !bk.isNull(); bk = next(bk), ++counter ) {
00132         if ( bk.element == child.element )
00133             return counter;
00134     }
00135     return -1;
00136 }
00137 
00138 QDomElement KBookmarkGroup::nextKnownTag( const QDomElement &start, bool goNext ) const
00139 {
00140     static const QString & bookmark = KGlobal::staticQString("bookmark");
00141     static const QString & folder = KGlobal::staticQString("folder");
00142     static const QString & separator = KGlobal::staticQString("separator");
00143 
00144     for( QDomElement elem = start; !elem.isNull(); )
00145     {
00146         QString tag = elem.tagName();
00147         if (tag == folder || tag == bookmark || tag == separator)
00148             return elem;
00149         if (goNext)
00150             elem = elem.nextSiblingElement();
00151         else
00152             elem = elem.previousSiblingElement();
00153     }
00154     return QDomElement();
00155 }
00156 
00157 KBookmarkGroup KBookmarkGroup::createNewFolder( const QString & text )
00158 {
00159     if (isNull())
00160         return KBookmarkGroup();
00161     QDomDocument doc = element.ownerDocument();
00162     QDomElement groupElem = doc.createElement( "folder" );
00163     element.appendChild( groupElem );
00164     QDomElement textElem = doc.createElement( "title" );
00165     groupElem.appendChild( textElem );
00166     textElem.appendChild( doc.createTextNode( text ) );
00167     return KBookmarkGroup(groupElem);
00168 
00169 }
00170 
00171 KBookmark KBookmarkGroup::createNewSeparator()
00172 {
00173     if (isNull())
00174         return KBookmark();
00175     QDomDocument doc = element.ownerDocument();
00176     Q_ASSERT(!doc.isNull());
00177     QDomElement sepElem = doc.createElement( "separator" );
00178     element.appendChild( sepElem );
00179     return KBookmark(sepElem);
00180 }
00181 
00182 #ifndef KDE_NO_DEPRECATED
00183 bool KBookmarkGroup::moveItem( const KBookmark & bookmark, const KBookmark & after )
00184 {
00185     return moveBookmark(bookmark, after);
00186 }
00187 #endif
00188 
00189 bool KBookmarkGroup::moveBookmark( const KBookmark & item, const KBookmark & after )
00190 {
00191     QDomNode n;
00192     if ( !after.isNull() )
00193         n = element.insertAfter( item.element, after.element );
00194     else // first child
00195     {
00196         if ( element.firstChild().isNull() ) // Empty element -> set as real first child
00197             n = element.insertBefore( item.element, QDomElement() );
00198 
00199         // we have to skip everything up to the first valid child
00200         QDomElement firstChild = nextKnownTag(element.firstChild().toElement(), true);
00201         if ( !firstChild.isNull() )
00202             n = element.insertBefore( item.element, firstChild );
00203         else
00204         {
00205             // No real first child -> append after the <title> etc.
00206             n = element.appendChild( item.element );
00207         }
00208     }
00209     return (!n.isNull());
00210 }
00211 
00212 KBookmark KBookmarkGroup::addBookmark( const KBookmark &bm )
00213 {
00214     element.appendChild( bm.internalElement() );
00215     return bm;
00216 }
00217 
00218 KBookmark KBookmarkGroup::addBookmark( const QString & text, const KUrl & url, const QString & icon )
00219 {
00220     if (isNull())
00221         return KBookmark();
00222     QDomDocument doc = element.ownerDocument();
00223     QDomElement elem = doc.createElement( "bookmark" );
00224     elem.setAttribute( "href", url.url() ); // gives us utf8
00225 
00226     QDomElement textElem = doc.createElement( "title" );
00227     elem.appendChild( textElem );
00228     textElem.appendChild( doc.createTextNode( text ) );
00229 
00230     KBookmark newBookmark =  addBookmark( KBookmark( elem ) );
00231 
00232     // as icons are moved to metadata, we have to use the KBookmark API for this
00233     newBookmark.setIcon(icon.isEmpty() ? KMimeType::iconNameForUrl( url ) : icon );
00234     return newBookmark;
00235 }
00236 
00237 void KBookmarkGroup::deleteBookmark( const KBookmark &bk )
00238 {
00239     element.removeChild( bk.element );
00240 }
00241 
00242 bool KBookmarkGroup::isToolbarGroup() const
00243 {
00244     return ( element.attribute("toolbar") == "yes" );
00245 }
00246 
00247 QDomElement KBookmarkGroup::findToolbar() const
00248 {
00249     if ( element.attribute("toolbar") == "yes" )
00250         return element;
00251     for (QDomNode n = element.firstChild(); !n.isNull() ; n = n.nextSibling() )
00252     {
00253         QDomElement e = n.toElement();
00254         // Search among the "folder" children only
00255         if ( e.tagName() == "folder" )
00256         {
00257             if ( e.attribute("toolbar") == "yes" )
00258                 return e;
00259             else
00260             {
00261                 QDomElement result = KBookmarkGroup(e).findToolbar();
00262                 if (!result.isNull())
00263                     return result;
00264             }
00265         }
00266     }
00267     return QDomElement();
00268 }
00269 
00270 QList<KUrl> KBookmarkGroup::groupUrlList() const
00271 {
00272     QList<KUrl> urlList;
00273     for ( KBookmark bm = first(); !bm.isNull(); bm = next(bm) )
00274     {
00275         if ( bm.isSeparator() || bm.isGroup() )
00276            continue;
00277         urlList << bm.url();
00278     }
00279     return urlList;
00280 }
00281 
00283 
00284 KBookmark::KBookmark()
00285 {
00286 }
00287 
00288 KBookmark::KBookmark( const QDomElement &elem ) : element(elem)
00289 {
00290 }
00291 
00292 bool KBookmark::isGroup() const
00293 {
00294     QString tag = element.tagName();
00295     return ( tag == "folder"
00296              || tag == "xbel" ); // don't forget the toplevel group
00297 }
00298 
00299 bool KBookmark::isSeparator() const
00300 {
00301     return (element.tagName() == "separator");
00302 }
00303 
00304 bool KBookmark::isNull() const
00305 {
00306     return element.isNull();
00307 }
00308 
00309 bool KBookmark::hasParent() const
00310 {
00311     QDomElement parent = element.parentNode().toElement();
00312     return !parent.isNull();
00313 }
00314 
00315 QString KBookmark::text() const
00316 {
00317     return KStringHandler::csqueeze( fullText() );
00318 }
00319 
00320 QString KBookmark::fullText() const
00321 {
00322     if (isSeparator())
00323         return i18n("--- separator ---");
00324 
00325     QString text = element.namedItem("title").toElement().text();
00326     text.replace('\n', ' '); // #140673
00327     return text;
00328 }
00329 
00330 void KBookmark::setFullText(const QString &fullText)
00331 {
00332     QDomNode titleNode = element.namedItem("title");
00333     if (titleNode.isNull()) {
00334         titleNode = element.ownerDocument().createElement("title");
00335         element.appendChild(titleNode);
00336     }
00337 
00338     if (titleNode.firstChild().isNull()) {
00339         QDomText domtext = titleNode.ownerDocument().createTextNode("");
00340         titleNode.appendChild(domtext);
00341     }
00342 
00343     QDomText domtext = titleNode.firstChild().toText();
00344     domtext.setData(fullText);
00345 }
00346 
00347 KUrl KBookmark::url() const
00348 {
00349     return KUrl(element.attribute("href").toAscii()); // Decodes it from utf8
00350 }
00351 
00352 void KBookmark::setUrl(const KUrl &url)
00353 {
00354     element.setAttribute("href", url.url());
00355 }
00356 
00357 QString KBookmark::icon() const
00358 {
00359     QDomNode metaDataNode = metaData(METADATA_FREEDESKTOP_OWNER, false);
00360     QDomElement iconElement = cd(metaDataNode, "bookmark:icon", false).toElement();
00361 
00362     QString icon = iconElement.attribute("name");
00363 
00364     // migration code
00365     if (icon.isEmpty())
00366       icon = element.attribute("icon");
00367     if (icon == "www") // common icon for kde3 bookmarks
00368         return "internet-web-browser";
00369     // end migration code
00370 
00371     if (icon == "bookmark_folder") {
00372         return "folder-bookmarks";
00373     }
00374     if (icon.isEmpty()) {
00375         // Default icon depends on URL for bookmarks, and is default directory
00376         // icon for groups.
00377         if (isGroup()) {
00378             icon = "folder-bookmarks";
00379         }
00380         else {
00381             if (isSeparator()) {
00382                 icon = "edit-clear"; // whatever
00383             } else {
00384                 // get icon from mimeType
00385                 QString _mimeType = mimeType();
00386                 if (!_mimeType.isEmpty()) {
00387                     KMimeType::Ptr mime = KMimeType::mimeType(_mimeType, KMimeType::ResolveAliases);
00388                     if (mime) {
00389                         return mime->iconName();
00390                     }
00391                 }
00392                 // get icon from URL
00393                 icon = KMimeType::iconNameForUrl(url());
00394             }
00395         }
00396     }
00397     return icon;
00398 }
00399 
00400 void KBookmark::setIcon(const QString &icon)
00401 {
00402     QDomNode metaDataNode = metaData(METADATA_FREEDESKTOP_OWNER, true);
00403     QDomElement iconElement = cd_or_create(metaDataNode, "bookmark:icon").toElement();
00404     iconElement.setAttribute ( "name", icon );
00405 
00406     // migration code
00407     if(!element.attribute("icon").isEmpty())
00408         element.removeAttribute("icon");
00409 }
00410 
00411 QString KBookmark::description() const
00412 {
00413     if (isSeparator())
00414         return QString();
00415 
00416     QString description = element.namedItem("desc").toElement().text();
00417     description.replace('\n', ' '); // #140673
00418     return description;
00419 }
00420 
00421 void KBookmark::setDescription(const QString &description)
00422 {
00423     QDomNode descNode = element.namedItem("desc");
00424     if (descNode.isNull()) {
00425         descNode = element.ownerDocument().createElement("desc");
00426         element.appendChild(descNode);
00427     }
00428 
00429     if (descNode.firstChild().isNull()) {
00430         QDomText domtext = descNode.ownerDocument().createTextNode(QString());
00431         descNode.appendChild(domtext);
00432     }
00433 
00434     QDomText domtext = descNode.firstChild().toText();
00435     domtext.setData(description);
00436 }
00437 
00438 QString KBookmark::mimeType() const
00439 {
00440     QDomNode metaDataNode = metaData(METADATA_MIME_OWNER, false);
00441     QDomElement mimeTypeElement = cd(metaDataNode, "mime:mime-type", false).toElement();
00442     return mimeTypeElement.attribute("type");
00443 }
00444 
00445 void KBookmark::setMimeType(const QString &mimeType)
00446 {
00447     QDomNode metaDataNode = metaData(METADATA_MIME_OWNER, true);
00448     QDomElement iconElement = cd_or_create(metaDataNode, "mime:mime-type").toElement();
00449     iconElement.setAttribute ( "type", mimeType );
00450 }
00451 
00452 bool KBookmark::showInToolbar() const
00453 {
00454     if(element.hasAttribute("showintoolbar"))
00455     {
00456         bool show = element.attribute("showintoolbar") == "yes";
00457         const_cast<QDomElement *>(&element)->removeAttribute("showintoolbar");
00458         const_cast<KBookmark *>(this)->setShowInToolbar(show);
00459     }
00460     return  metaDataItem("showintoolbar") == "yes";
00461 }
00462 
00463 
00464 void KBookmark::setShowInToolbar(bool show)
00465 {
00466     setMetaDataItem("showintoolbar", show ? "yes" : "no");
00467 }
00468 
00469 KBookmarkGroup KBookmark::parentGroup() const
00470 {
00471     return KBookmarkGroup( element.parentNode().toElement() );
00472 }
00473 
00474 KBookmarkGroup KBookmark::toGroup() const
00475 {
00476     Q_ASSERT( isGroup() );
00477     return KBookmarkGroup(element);
00478 }
00479 
00480 QString KBookmark::address() const
00481 {
00482     if ( element.tagName() == "xbel" )
00483         return ""; // not QString() !
00484     else
00485     {
00486         // Use keditbookmarks's DEBUG_ADDRESSES flag to debug this code :)
00487         if (element.parentNode().isNull())
00488         {
00489             Q_ASSERT(false);
00490             return "ERROR"; // Avoid an infinite loop
00491         }
00492         KBookmarkGroup group = parentGroup();
00493         QString parentAddress = group.address();
00494         int pos = group.indexOf(*this);
00495         Q_ASSERT(pos != -1);
00496         return parentAddress + '/' + QString::number(pos);
00497     }
00498 }
00499 
00500 int KBookmark::positionInParent() const
00501 {
00502     return parentGroup().indexOf(*this);
00503 }
00504 
00505 QDomElement KBookmark::internalElement() const
00506 {
00507     return element;
00508 }
00509 
00510 KBookmark KBookmark::standaloneBookmark( const QString & text, const KUrl & url, const QString & icon )
00511 {
00512     QDomDocument doc("xbel");
00513     QDomElement elem = doc.createElement("xbel");
00514     doc.appendChild( elem );
00515     KBookmarkGroup grp( elem );
00516     grp.addBookmark( text, url, icon );
00517     return grp.first();
00518 }
00519 
00520 
00521 QString KBookmark::commonParent(const QString &first, const QString &second)
00522 {
00523     QString A = first;
00524     QString B = second;
00525     QString error("ERROR");
00526     if(A == error || B == error)
00527         return error;
00528 
00529     A += '/';
00530     B += '/';
00531 
00532     uint lastCommonSlash = 0;
00533     uint lastPos = A.length() < B.length() ? A.length() : B.length();
00534     for(uint i=0; i < lastPos; ++i)
00535     {
00536         if(A[i] != B[i])
00537             return A.left(lastCommonSlash);
00538         if(A[i] == '/')
00539             lastCommonSlash = i;
00540     }
00541     return A.left(lastCommonSlash);
00542 }
00543 
00544 void KBookmark::updateAccessMetadata()
00545 {
00546     kDebug(7043) << "KBookmark::updateAccessMetadata " << address() << " " << url().prettyUrl();
00547 
00548     const uint timet = QDateTime::currentDateTime().toTime_t();
00549     setMetaDataItem( "time_added", QString::number( timet ), DontOverwriteMetaData );
00550     setMetaDataItem( "time_visited", QString::number( timet ) );
00551 
00552     QString countStr = metaDataItem( "visit_count" ); // TODO use spec'ed name
00553     bool ok;
00554     int currentCount = countStr.toInt(&ok);
00555     if (!ok)
00556         currentCount = 0;
00557     currentCount++;
00558     setMetaDataItem( "visit_count", QString::number( currentCount ) );
00559 
00560     // TODO - for 4.0 - time_modified
00561 }
00562 
00563 QString KBookmark::parentAddress( const QString & address )
00564 {
00565     return address.left( address.lastIndexOf(QLatin1Char('/')) );
00566 }
00567 
00568 uint KBookmark::positionInParent( const QString & address )
00569 {
00570     return address.mid( address.lastIndexOf(QLatin1Char('/')) + 1 ).toInt();
00571 }
00572 
00573 QString KBookmark::previousAddress( const QString & address )
00574 {
00575     uint pp = positionInParent(address);
00576     return pp>0
00577         ? parentAddress(address) + QLatin1Char('/') + QString::number(pp-1)
00578         : QString();
00579 }
00580 
00581 QString KBookmark::nextAddress( const QString & address )
00582 {
00583     return parentAddress(address) + QLatin1Char('/') +
00584         QString::number(positionInParent(address)+1);
00585 }
00586 
00587 QDomNode KBookmark::metaData(const QString &owner, bool create) const
00588 {
00589     QDomNode infoNode = cd( internalElement(), "info", create);
00590     if (infoNode.isNull()) return QDomNode();
00591     return findMetadata(owner, infoNode , create);
00592 }
00593 
00594 QString KBookmark::metaDataItem( const QString &key ) const
00595 {
00596     QDomNode metaDataNode = metaData(METADATA_KDE_OWNER, false);
00597     for ( QDomElement e = metaDataNode.firstChildElement(); !e.isNull(); e = e.nextSiblingElement() )
00598     {
00599         if ( e.tagName() == key ) {
00600             return e.text();
00601         }
00602     }
00603     return QString();
00604 }
00605 
00606 void KBookmark::setMetaDataItem( const QString &key, const QString &value, MetaDataOverwriteMode mode )
00607 {
00608     QDomNode metaDataNode = metaData(METADATA_KDE_OWNER, true);
00609     QDomNode item = cd_or_create( metaDataNode, key );
00610     QDomText text = get_or_create_text( item );
00611     if ( mode == DontOverwriteMetaData && !text.data().isEmpty() ) {
00612         return;
00613     }
00614 
00615     text.setData( value );
00616 }
00617 
00618 
00619 bool KBookmark::operator==(const KBookmark& rhs) const
00620 {
00621     return element == rhs.element;
00622 }
00623 
00625 
00626 KBookmarkGroupTraverser::~KBookmarkGroupTraverser()
00627 {
00628 }
00629 
00630 void KBookmarkGroupTraverser::traverse(const KBookmarkGroup &root)
00631 {
00632     QStack<KBookmarkGroup> stack;
00633     stack.push(root);
00634     KBookmark bk = root.first();
00635     for(;;) {
00636         if(bk.isNull()) {
00637             if(stack.count() == 1) // only root is on the stack
00638                 return;
00639             if(stack.count() > 0) {
00640                 visitLeave(stack.top());
00641                 bk = stack.pop();
00642             }
00643             bk = stack.top().next(bk);
00644         } else if(bk.isGroup()) {
00645             KBookmarkGroup gp = bk.toGroup();
00646             visitEnter(gp);
00647             bk = gp.first();
00648             stack.push(gp);
00649         } else {
00650             visit(bk);
00651             bk = stack.top().next(bk);
00652         }
00653     }
00654 }
00655 
00656 void KBookmarkGroupTraverser::visit(const KBookmark &)
00657 {
00658 }
00659 
00660 void KBookmarkGroupTraverser::visitEnter(const KBookmarkGroup &)
00661 {
00662 }
00663 
00664 void KBookmarkGroupTraverser::visitLeave(const KBookmarkGroup &)
00665 {
00666 }
00667 
00668 void KBookmark::populateMimeData( QMimeData* mimeData ) const
00669 {
00670     KBookmark::List bookmarkList;
00671     bookmarkList.append( *this );
00672     bookmarkList.populateMimeData( mimeData );
00673 }
00674 
00675 KBookmark::List::List() : QList<KBookmark>()
00676 {
00677 }
00678 
00679 void KBookmark::List::populateMimeData( QMimeData* mimeData ) const
00680 {
00681     KUrl::List urls;
00682 
00683     QDomDocument doc( "xbel" );
00684     QDomElement elem = doc.createElement( "xbel" );
00685     doc.appendChild( elem );
00686 
00687     for ( const_iterator it = begin(), end = this->end() ; it != end ; ++it ) {
00688         urls.append( (*it).url() );
00689         elem.appendChild( (*it).internalElement().cloneNode( true /* deep */ ) );
00690     }
00691 
00692     // This sets text/uri-list and text/plain into the mimedata
00693     urls.populateMimeData( mimeData, KUrl::MetaDataMap() );
00694 
00695     mimeData->setData( "application/x-xbel", doc.toByteArray() );
00696 }
00697 
00698 bool KBookmark::List::canDecode( const QMimeData *mimeData )
00699 {
00700     return mimeData->hasFormat( "application/x-xbel" )  || KUrl::List::canDecode(mimeData);
00701 }
00702 
00703 QStringList KBookmark::List::mimeDataTypes()
00704 {
00705     return QStringList()<<("application/x-xbel")<<KUrl::List::mimeDataTypes();
00706 }
00707 
00708 #ifndef KDE_NO_DEPRECATED
00709 KBookmark::List KBookmark::List::fromMimeData( const QMimeData *mimeData )
00710 {
00711     QDomDocument doc;
00712     kWarning(7043) << "Deprecated method called, with wrong lifetime of QDomDocument, will probably crash";
00713     return fromMimeData(mimeData, doc);
00714 }
00715 #endif
00716 
00717 KBookmark::List KBookmark::List::fromMimeData( const QMimeData *mimeData, QDomDocument& doc )
00718 {
00719     KBookmark::List bookmarks;
00720     QByteArray payload = mimeData->data( "application/x-xbel" );
00721     if ( !payload.isEmpty() ) {
00722         doc.setContent( payload );
00723         QDomElement elem = doc.documentElement();
00724         const QDomNodeList children = elem.childNodes();
00725         for ( int childno = 0; childno < children.count(); childno++)
00726         {
00727             bookmarks.append( KBookmark( children.item(childno).toElement() ));
00728         }
00729         return bookmarks;
00730     }
00731     const KUrl::List urls = KUrl::List::fromMimeData( mimeData );
00732     if ( !urls.isEmpty() )
00733     {
00734         KUrl::List::ConstIterator uit = urls.begin();
00735         KUrl::List::ConstIterator uEnd = urls.end();
00736         for ( ; uit != uEnd ; ++uit )
00737         {
00738             //kDebug(7043) << "url=" << (*uit);
00739             bookmarks.append( KBookmark::standaloneBookmark(
00740                                   (*uit).prettyUrl(), (*uit) ));
00741         }
00742     }
00743     return bookmarks;
00744 }
00745 

KIO

Skip menu "KIO"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal