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

KDE3Support

  • sources
  • kde-4.14
  • kdelibs
  • kde3support
  • kio
k3bookmarkdrag.cpp
Go to the documentation of this file.
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 "k3bookmarkdrag.h"
22 #include <k3urldrag.h>
23 #include <kdebug.h>
24 #include <Qt3Support/Q3CString>
25 
26 K3BookmarkDrag * K3BookmarkDrag::newDrag( const Q3ValueList<KBookmark> & bookmarks, QWidget * dragSource, const char * name )
27 {
28  KUrl::List urls;
29 
30  for ( Q3ValueListConstIterator<KBookmark> it = bookmarks.constBegin(); it != bookmarks.constEnd(); ++it ) {
31  urls.append( (*it).url() );
32  }
33 
34  // See KURLDrag::newDrag
35  Q3StrList uris;
36  KUrl::List::ConstIterator uit = urls.constBegin();
37  KUrl::List::ConstIterator uEnd = urls.constEnd();
38  // Get each URL encoded in utf8 - and since we get it in escaped
39  // form on top of that, .toLatin1().constData() is fine.
40  for ( ; uit != uEnd ; ++uit )
41  uris.append( K3URLDrag::urlToString(*uit).toLatin1() );
42 
43  return new K3BookmarkDrag( bookmarks, uris, dragSource, name );
44 }
45 
46 K3BookmarkDrag * K3BookmarkDrag::newDrag( const KBookmark & bookmark, QWidget * dragSource, const char * name )
47 {
48  Q3ValueList<KBookmark> bookmarks;
49  bookmarks.append( KBookmark(bookmark) );
50  return newDrag(bookmarks, dragSource, name);
51 }
52 
53 K3BookmarkDrag::K3BookmarkDrag( const Q3ValueList<KBookmark> & bookmarks, const Q3StrList & urls,
54  QWidget * dragSource, const char * name )
55  : Q3UriDrag( urls, dragSource, name ), m_bookmarks( bookmarks ), m_doc("xbel")
56 {
57  // We need to create the XML for this drag right now and not
58  // in encodedData because when cutting a folder, the children
59  // wouldn't be part of the bookmarks anymore, when encodedData
60  // is requested.
61  QDomElement elem = m_doc.createElement("xbel");
62  m_doc.appendChild( elem );
63  for ( Q3ValueListConstIterator<KBookmark> it = bookmarks.begin(); it != bookmarks.end(); ++it ) {
64  elem.appendChild( (*it).internalElement().cloneNode( true /* deep */ ) );
65  }
66  //kDebug(7043) << "K3BookmarkDrag::K3BookmarkDrag " << m_doc.toString();
67 }
68 
69 const char* K3BookmarkDrag::format( int i ) const
70 {
71  if ( i == 0 )
72  return "application/x-xbel";
73  else if ( i == 1 )
74  return "text/uri-list";
75  else if ( i == 2 )
76  return "text/plain";
77  else return 0;
78 }
79 
80 QByteArray K3BookmarkDrag::encodedData( const char* mime ) const
81 {
82  QByteArray a;
83  Q3CString mimetype( mime );
84  if ( mimetype == "text/uri-list" )
85  return Q3UriDrag::encodedData( mime );
86  else if ( mimetype == "application/x-xbel" )
87  {
88  a = m_doc.toByteArray();
89  //kDebug(7043) << "K3BookmarkDrag::encodedData " << m_doc.toCString();
90  }
91  else if ( mimetype == "text/plain" )
92  {
93  KUrl::List m_lstDragURLs;
94  if ( K3URLDrag::decode( this, m_lstDragURLs ) )
95  {
96  QStringList uris;
97  KUrl::List::ConstIterator uit = m_lstDragURLs.constBegin();
98  KUrl::List::ConstIterator uEnd = m_lstDragURLs.constEnd();
99  for ( ; uit != uEnd ; ++uit )
100  uris.append( (*uit).prettyUrl() );
101 
102  Q3CString s = uris.join( "\n" ).toLocal8Bit();
103  a.resize( s.length() + 1 ); // trailing zero
104  memcpy( a.data(), s.data(), s.length() + 1 );
105  }
106  }
107  return a;
108 }
109 
110 bool K3BookmarkDrag::canDecode( const QMimeSource * e )
111 {
112  return e->provides("text/uri-list") || e->provides("application/x-xbel") ||
113  e->provides("text/plain");
114 }
115 
116 Q3ValueList<KBookmark> K3BookmarkDrag::decode( const QMimeSource * e )
117 {
118  Q3ValueList<KBookmark> bookmarks;
119  if ( e->provides("application/x-xbel") )
120  {
121  QByteArray s( e->encodedData("application/x-xbel") );
122  //kDebug(7043) << "K3BookmarkDrag::decode s=" << QCString(s);
123  QDomDocument doc;
124  doc.setContent( s );
125  QDomElement elem = doc.documentElement();
126  QDomNodeList children = elem.childNodes();
127  for ( int childno = 0; childno < children.count(); childno++)
128  {
129  bookmarks.append( KBookmark( children.item(childno).cloneNode(true).toElement() ));
130  }
131  return bookmarks;
132  }
133  if ( e->provides("text/uri-list") )
134  {
135  KUrl::List m_lstDragURLs;
136  //kDebug(7043) << "K3BookmarkDrag::decode uri-list";
137  if ( K3URLDrag::decode( e, m_lstDragURLs ) )
138  {
139  KUrl::List::ConstIterator uit = m_lstDragURLs.constBegin();
140  KUrl::List::ConstIterator uEnd = m_lstDragURLs.constEnd();
141  for ( ; uit != uEnd ; ++uit )
142  {
143  //kDebug(7043) << "K3BookmarkDrag::decode url=" << (*uit).url();
144  bookmarks.append( KBookmark::standaloneBookmark(
145  (*uit).prettyUrl(), (*uit) ));
146  }
147  return bookmarks;
148  }
149  }
150  if( e->provides("text/plain") )
151  {
152  //kDebug(7043) << "K3BookmarkDrag::decode text/plain";
153  QString s;
154  if(Q3TextDrag::decode( e, s ))
155  {
156 
157  QStringList listDragURLs = s.split(QChar('\n'), QString::SkipEmptyParts);
158  QStringList::ConstIterator it = listDragURLs.constBegin();
159  QStringList::ConstIterator end = listDragURLs.constEnd();
160  for( ; it!=end; ++it)
161  {
162  //kDebug(7043)<<"K3BookmarkDrag::decode string"<<(*it);
163  bookmarks.append( KBookmark::standaloneBookmark( KUrl(*it).prettyUrl(), KUrl(*it)));
164  }
165  return bookmarks;
166  }
167  }
168  bookmarks.append( KBookmark() );
169  return bookmarks;
170 }
K3BookmarkDrag::m_doc
QDomDocument m_doc
Definition: k3bookmarkdrag.h:56
QWidget
QMimeSource::encodedData
virtual QByteArray encodedData(const char *format) const =0
QDomNodeList::item
QDomNode item(int index) const
kdebug.h
K3URLDrag::urlToString
static QString urlToString(const KUrl &url)
Converts a URL to a string representation suitable for dragging.
Definition: k3urldrag.cpp:251
QDomNode::appendChild
QDomNode appendChild(const QDomNode &newChild)
QByteArray
k3urldrag.h
Q3StoredDrag::encodedData
virtual QByteArray encodedData(const char *format) const
QChar
QString::split
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
Q3ValueListConstIterator
mimetype
MimetypeJob * mimetype(const KUrl &url, JobFlags flags=DefaultFlags)
QDomNodeList
QObject::children
const QObjectList & children() const
K3BookmarkDrag::format
virtual const char * format(int i) const
Definition: k3bookmarkdrag.cpp:69
K3BookmarkDrag::K3BookmarkDrag
K3BookmarkDrag(const Q3ValueList< KBookmark > &bookmarks, const Q3StrList &urls, QWidget *dragSource, const char *name)
Definition: k3bookmarkdrag.cpp:53
Q3UriDrag
QStringList::join
QString join(const QString &separator) const
QByteArray::length
int length() const
K3URLDrag::decode
static bool decode(const QMimeSource *e, KUrl::List &urls)
Convenience method that decodes the contents of e into a list of KUrls.
Definition: k3urldrag.cpp:93
KBookmark
QDomNode::childNodes
QDomNodeList childNodes() const
KUrl
K3BookmarkDrag::canDecode
static bool canDecode(const QMimeSource *e)
Definition: k3bookmarkdrag.cpp:110
K3BookmarkDrag::newDrag
static K3BookmarkDrag * newDrag(const Q3ValueList< KBookmark > &bookmarks, QWidget *dragSource=0, const char *name=0)
Definition: k3bookmarkdrag.cpp:26
Q3PtrList::append
void append(const type *item)
QDomNode::toElement
QDomElement toElement() const
QByteArray::resize
void resize(int size)
Q3ValueList< KBookmark >
QDomNodeList::count
int count() const
QList::append
void append(const T &value)
QString
QStringList
Q3ValueList::append
Q3ValueList< T >::Iterator append(const T &x)
QString::toLocal8Bit
QByteArray toLocal8Bit() const
Q3StrList
QDomDocument
k3bookmarkdrag.h
Q3CString
KUrl::List
QString::toLatin1
QByteArray toLatin1() const
K3BookmarkDrag::encodedData
virtual QByteArray encodedData(const char *mime) const
Definition: k3bookmarkdrag.cpp:80
QDomNode::cloneNode
QDomNode cloneNode(bool deep) const
QList< KUrl >::ConstIterator
typedef ConstIterator
QByteArray::data
char * data()
KBookmark::standaloneBookmark
static KBookmark standaloneBookmark(const QString &text, const KUrl &url, const QString &icon=QString())
QList::constEnd
const_iterator constEnd() const
Q3TextDrag::decode
bool decode(const QMimeSource *source, QString &string)
QDomDocument::createElement
QDomElement createElement(const QString &tagName)
QList::constBegin
const_iterator constBegin() const
QDomElement
QMimeSource::provides
virtual bool provides(const char *mimeType) const
end
const KShortcut & end()
K3BookmarkDrag
Definition: k3bookmarkdrag.h:31
KUrl::prettyUrl
QString prettyUrl(AdjustPathOption trailing=LeaveTrailingSlash) const
K3BookmarkDrag::decode
static Q3ValueList< KBookmark > decode(const QMimeSource *e)
Definition: k3bookmarkdrag.cpp:116
QMimeSource
QDomDocument::toByteArray
QByteArray toByteArray(int indent) const
QDomDocument::setContent
bool setContent(const QByteArray &data, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:26:47 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDE3Support

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

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • 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

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal