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

kio/bookmarks

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

kio/bookmarks

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

kio/bookmarks

Skip menu "kio/bookmarks"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kio/bookmarks by doxygen 1.8.13
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |