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

tdeio/bookmarks

  • tdeio
  • bookmarks
kbookmarkdrag.cpp
1 /* This file is part of the KDE libraries
2  Copyright (C) 2000 David Faure <faure@kde.org>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License version 2 as published by the Free Software Foundation.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Library General Public License for more details.
12 
13  You should have received a copy of the GNU Library General Public License
14  along with this library; see the file COPYING.LIB. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17 */
18 
19 #include "kbookmarkdrag.h"
20 #include <kurldrag.h>
21 #include <kdebug.h>
22 
23 KBookmarkDrag * KBookmarkDrag::newDrag( const TQValueList<KBookmark> & bookmarks, TQWidget * dragSource, const char * name )
24 {
25  KURL::List urls;
26 
27  for ( TQValueListConstIterator<KBookmark> it = bookmarks.begin(); it != bookmarks.end(); ++it ) {
28  urls.append( (*it).url() );
29  }
30 
31  // See KURLDrag::newDrag
32  TQStrList uris;
33  KURL::List::ConstIterator uit = urls.begin();
34  KURL::List::ConstIterator uEnd = urls.end();
35  // Get each URL encoded in utf8 - and since we get it in escaped
36  // form on top of that, .latin1() is fine.
37  for ( ; uit != uEnd ; ++uit )
38  uris.append( KURLDrag::urlToString(*uit).latin1() );
39 
40  return new KBookmarkDrag( bookmarks, uris, dragSource, name );
41 }
42 
43 KBookmarkDrag * KBookmarkDrag::newDrag( const KBookmark & bookmark, TQWidget * dragSource, const char * name )
44 {
45  TQValueList<KBookmark> bookmarks;
46  bookmarks.append( KBookmark(bookmark) );
47  return newDrag(bookmarks, dragSource, name);
48 }
49 
50 KBookmarkDrag::KBookmarkDrag( const TQValueList<KBookmark> & bookmarks, const TQStrList & urls,
51  TQWidget * dragSource, const char * name )
52  : TQUriDrag( urls, dragSource, name ), m_bookmarks( bookmarks ), m_doc("xbel")
53 {
54  // We need to create the XML for this drag right now and not
55  // in encodedData because when cutting a folder, the children
56  // wouldn't be part of the bookmarks anymore, when encodedData
57  // is requested.
58  TQDomElement elem = m_doc.createElement("xbel");
59  m_doc.appendChild( elem );
60  for ( TQValueListConstIterator<KBookmark> it = bookmarks.begin(); it != bookmarks.end(); ++it ) {
61  elem.appendChild( (*it).internalElement().cloneNode( true /* deep */ ) );
62  }
63  //kdDebug(7043) << "KBookmarkDrag::KBookmarkDrag " << m_doc.toString() << endl;
64 }
65 
66 const char* KBookmarkDrag::format( int i ) const
67 {
68  if ( i == 0 )
69  return "application/x-xbel";
70  else if ( i == 1 )
71  return "text/uri-list";
72  else if ( i == 2 )
73  return "text/plain";
74  else return 0;
75 }
76 
77 TQByteArray KBookmarkDrag::encodedData( const char* mime ) const
78 {
79  TQByteArray a;
80  TQCString mimetype( mime );
81  if ( mimetype == "text/uri-list" )
82  return TQUriDrag::encodedData( mime );
83  else if ( mimetype == "application/x-xbel" )
84  {
85  a = m_doc.toCString();
86  //kdDebug(7043) << "KBookmarkDrag::encodedData " << m_doc.toCString() << endl;
87  }
88  else if ( mimetype == "text/plain" )
89  {
90  KURL::List m_lstDragURLs;
91  if ( KURLDrag::decode( this, m_lstDragURLs ) )
92  {
93  TQStringList uris;
94  KURL::List::ConstIterator uit = m_lstDragURLs.begin();
95  KURL::List::ConstIterator uEnd = m_lstDragURLs.end();
96  for ( ; uit != uEnd ; ++uit )
97  uris.append( (*uit).prettyURL() );
98 
99  TQCString s = uris.join( "\n" ).local8Bit();
100  a.resize( s.length() + 1 ); // trailing zero
101  memcpy( a.data(), s.data(), s.length() + 1 );
102  }
103  }
104  return a;
105 }
106 
107 bool KBookmarkDrag::canDecode( const TQMimeSource * e )
108 {
109  return e->provides("text/uri-list") || e->provides("application/x-xbel") ||
110  e->provides("text/plain");
111 }
112 
113 TQValueList<KBookmark> KBookmarkDrag::decode( const TQMimeSource * e )
114 {
115  TQValueList<KBookmark> bookmarks;
116  if ( e->provides("application/x-xbel") )
117  {
118  TQByteArray s( e->encodedData("application/x-xbel") );
119  //kdDebug(7043) << "KBookmarkDrag::decode s=" << TQCString(s) << endl;
120  TQDomDocument doc;
121  doc.setContent( s );
122  TQDomElement elem = doc.documentElement();
123  TQDomNodeList children = elem.childNodes();
124  for ( uint childno = 0; childno < children.count(); childno++)
125  {
126  bookmarks.append( KBookmark( children.item(childno).cloneNode(true).toElement() ));
127  }
128  return bookmarks;
129  }
130  if ( e->provides("text/uri-list") )
131  {
132  KURL::List m_lstDragURLs;
133  //kdDebug(7043) << "KBookmarkDrag::decode uri-list" << endl;
134  if ( KURLDrag::decode( e, m_lstDragURLs ) )
135  {
136  KURL::List::ConstIterator uit = m_lstDragURLs.begin();
137  KURL::List::ConstIterator uEnd = m_lstDragURLs.end();
138  for ( ; uit != uEnd ; ++uit )
139  {
140  //kdDebug(7043) << "KBookmarkDrag::decode url=" << (*uit).url() << endl;
141  bookmarks.append( KBookmark::standaloneBookmark(
142  (*uit).prettyURL(), (*uit) ));
143  }
144  return bookmarks;
145  }
146  }
147  if( e->provides("text/plain") )
148  {
149  //kdDebug(7043) << "KBookmarkDrag::decode text/plain" << endl;
150  TQString s;
151  if(TQTextDrag::decode( e, s ))
152  {
153 
154  TQStringList listDragURLs = TQStringList::split(TQChar('\n'), s);
155  TQStringList::ConstIterator it = listDragURLs.begin();
156  TQStringList::ConstIterator end = listDragURLs.end();
157  for( ; it!=end; ++it)
158  {
159  //kdDebug(7043)<<"KBookmarkDrag::decode string"<<(*it)<<endl;
160  bookmarks.append( KBookmark::standaloneBookmark( KURL(*it).prettyURL(), KURL(*it)));
161  }
162  return bookmarks;
163  }
164  }
165  bookmarks.append( KBookmark() );
166  return bookmarks;
167 }

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
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeio/bookmarks by doxygen 1.8.8
This website is maintained by Timothy Pearson.