• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeio/bookmarks
 

tdeio/bookmarks

kbookmarkdrag.cc
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 
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Library General Public
00008    License version 2 as published by the Free Software Foundation.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018    Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include "kbookmarkdrag.h"
00022 #include <kurldrag.h>
00023 #include <kdebug.h>
00024 
00025 KBookmarkDrag * KBookmarkDrag::newDrag( const TQValueList<KBookmark> & bookmarks, TQWidget * dragSource, const char * name )
00026 {
00027     KURL::List urls;
00028 
00029     for ( TQValueListConstIterator<KBookmark> it = bookmarks.begin(); it != bookmarks.end(); ++it ) {
00030        urls.append( (*it).url() );
00031     }
00032 
00033     // See KURLDrag::newDrag
00034     TQStrList uris;
00035     KURL::List::ConstIterator uit = urls.begin();
00036     KURL::List::ConstIterator uEnd = urls.end();
00037     // Get each URL encoded in utf8 - and since we get it in escaped
00038     // form on top of that, .latin1() is fine.
00039     for ( ; uit != uEnd ; ++uit )
00040         uris.append( KURLDrag::urlToString(*uit).latin1() );
00041 
00042     return new KBookmarkDrag( bookmarks, uris, dragSource, name );
00043 }
00044 
00045 KBookmarkDrag * KBookmarkDrag::newDrag( const KBookmark & bookmark, TQWidget * dragSource, const char * name )
00046 {
00047     TQValueList<KBookmark> bookmarks;
00048     bookmarks.append( KBookmark(bookmark) );
00049     return newDrag(bookmarks, dragSource, name);
00050 }
00051 
00052 KBookmarkDrag::KBookmarkDrag( const TQValueList<KBookmark> & bookmarks, const TQStrList & urls,
00053                   TQWidget * dragSource, const char * name )
00054     : TQUriDrag( urls, dragSource, name ), m_bookmarks( bookmarks ), m_doc("xbel")
00055 {
00056     // We need to create the XML for this drag right now and not
00057     // in encodedData because when cutting a folder, the children
00058     // wouldn't be part of the bookmarks anymore, when encodedData
00059     // is requested.
00060     TQDomElement elem = m_doc.createElement("xbel");
00061     m_doc.appendChild( elem );
00062     for ( TQValueListConstIterator<KBookmark> it = bookmarks.begin(); it != bookmarks.end(); ++it ) {
00063        elem.appendChild( (*it).internalElement().cloneNode( true /* deep */ ) );
00064     }
00065     //kdDebug(7043) << "KBookmarkDrag::KBookmarkDrag " << m_doc.toString() << endl;
00066 }
00067 
00068 const char* KBookmarkDrag::format( int i ) const
00069 {
00070     if ( i == 0 )
00071         return "application/x-xbel";
00072     else if ( i == 1 )
00073     return "text/uri-list";
00074     else if ( i == 2 )
00075     return "text/plain";
00076     else return 0;
00077 }
00078 
00079 TQByteArray KBookmarkDrag::encodedData( const char* mime ) const
00080 {
00081     TQByteArray a;
00082     TQCString mimetype( mime );
00083     if ( mimetype == "text/uri-list" )
00084         return TQUriDrag::encodedData( mime );
00085     else if ( mimetype == "application/x-xbel" )
00086     {
00087         a = m_doc.toCString();
00088         //kdDebug(7043) << "KBookmarkDrag::encodedData " << m_doc.toCString() << endl;
00089     }
00090     else if ( mimetype == "text/plain" )
00091     {
00092         KURL::List m_lstDragURLs;
00093         if ( KURLDrag::decode( this, m_lstDragURLs ) )
00094         {
00095             TQStringList uris;
00096             KURL::List::ConstIterator uit = m_lstDragURLs.begin();
00097             KURL::List::ConstIterator uEnd = m_lstDragURLs.end();
00098             for ( ; uit != uEnd ; ++uit )
00099                 uris.append( (*uit).prettyURL() );
00100 
00101             TQCString s = uris.join( "\n" ).local8Bit();
00102             a.resize( s.length() + 1 ); // trailing zero
00103             memcpy( a.data(), s.data(), s.length() + 1 );
00104         }
00105     }
00106     return a;
00107 }
00108 
00109 bool KBookmarkDrag::canDecode( const TQMimeSource * e )
00110 {
00111     return e->provides("text/uri-list") || e->provides("application/x-xbel") ||
00112            e->provides("text/plain");
00113 }
00114 
00115 TQValueList<KBookmark> KBookmarkDrag::decode( const TQMimeSource * e )
00116 {
00117     TQValueList<KBookmark> bookmarks;
00118     if ( e->provides("application/x-xbel") )
00119     {
00120         TQByteArray s( e->encodedData("application/x-xbel") );
00121         //kdDebug(7043) << "KBookmarkDrag::decode s=" << TQCString(s) << endl;
00122         TQDomDocument doc;
00123         doc.setContent( s );
00124         TQDomElement elem = doc.documentElement();
00125         TQDomNodeList children = elem.childNodes();
00126         for ( uint childno = 0; childno < children.count(); childno++) 
00127         {
00128            bookmarks.append( KBookmark( children.item(childno).cloneNode(true).toElement() ));
00129         }
00130         return bookmarks;
00131     }
00132     if ( e->provides("text/uri-list") )
00133     {
00134         KURL::List m_lstDragURLs;
00135         //kdDebug(7043) << "KBookmarkDrag::decode uri-list" << endl;
00136         if ( KURLDrag::decode( e, m_lstDragURLs ) )
00137         {
00138             KURL::List::ConstIterator uit = m_lstDragURLs.begin();
00139             KURL::List::ConstIterator uEnd = m_lstDragURLs.end();
00140             for ( ; uit != uEnd ; ++uit )
00141             {
00142                 //kdDebug(7043) << "KBookmarkDrag::decode url=" << (*uit).url() << endl;
00143                 bookmarks.append( KBookmark::standaloneBookmark( 
00144                                         (*uit).prettyURL(), (*uit) ));
00145             }
00146             return bookmarks;
00147         }
00148     }
00149     if( e->provides("text/plain") )
00150     {        
00151         //kdDebug(7043) << "KBookmarkDrag::decode text/plain" << endl;
00152         TQString s;
00153         if(TQTextDrag::decode( e, s ))
00154         {
00155             
00156             TQStringList listDragURLs = TQStringList::split(TQChar('\n'), s);
00157             TQStringList::ConstIterator it = listDragURLs.begin();
00158             TQStringList::ConstIterator end = listDragURLs.end();
00159             for( ; it!=end; ++it)
00160             {
00161                 //kdDebug(7043)<<"KBookmarkDrag::decode string"<<(*it)<<endl;
00162                 bookmarks.append( KBookmark::standaloneBookmark( KURL(*it).prettyURL(), KURL(*it)));
00163             }
00164             return bookmarks;
00165         }
00166     }
00167     bookmarks.append( KBookmark() );
00168     return bookmarks;
00169 }

tdeio/bookmarks

Skip menu "tdeio/bookmarks"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdeio/bookmarks

Skip menu "tdeio/bookmarks"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeio/bookmarks by doxygen 1.7.6.1
This website is maintained by Timothy Pearson.