summaryrefslogtreecommitdiffstats
path: root/quanta/parts/kafka/kafkadragobject.cpp
blob: 4b609998914cdc21b1ab64c17a724895f7b6bd1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/***************************************************************************
                               kafkadragobject.h
                             -------------------
 
    copyright            : (C) 2004 - Paulo Moura Guedes
    email                : moura@kdewebdev.org
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include <kdebug.h>

#include <tqdom.h> 
#include <tqtextstream.h> 
 
#include "kafkadragobject.h"
#include "node.h"
#include "kafkacommon.h" // for debug only

char const* KafkaDragObject::m_mimetype = "application/kafka-nodeselection";

KafkaDragObject::KafkaDragObject(Node const* item, TQWidget* dragSource, const char* name)
    : TQStoredDrag(m_mimetype, dragSource, name), m_item(item)
{
    TQDomDocument doc("KafkaSelection");
    TQString docstart = "<KafkaSelection/>";
    doc.setContent(docstart);
    TQDomElement itemsElement = doc.createElement("Items");
    doc.documentElement().appendChild(itemsElement);
    //kdDebug(25001) << doc.toString() << endl;
    item->save(itemsElement);
    //TQDataStream s(m_array, IO_WriteOnly);
    TQTextStream s(m_array, IO_WriteOnly);
    s << doc.toString();
    //s << "biltre";
    /*
    kdDebug(25001) << m_array.size() << endl;    
    kdDebug(25001) << doc.toString() << endl;
    kdDebug(25001) << TQString(m_array) << endl;
    */
    //setEncodedData(m_array);
}

KafkaDragObject::~KafkaDragObject()
{}

TQByteArray KafkaDragObject::tqencodedData(const char* mimetype) const
{
    if(m_mimetype == mimetype)
        return m_array;
    
    return TQByteArray();
}

Node const* KafkaDragObject::getItem() const
{
    return m_item;
}

bool KafkaDragObject::canDecode(TQMimeSource *e)
{
    return e->provides(m_mimetype);
}

bool KafkaDragObject::decode(TQMimeSource* e, Node* node)
{
    if(!node || !e->provides(m_mimetype))
        return false;
    
    TQByteArray data = e->tqencodedData(m_mimetype);    
    //kdDebug(25001) << TQString(data) << endl;
    TQDomDocument doc;
    doc.setContent(data, false);
    //kdDebug(25001) << doc.toString() << endl;
    node->load(doc.documentElement().firstChild().toElement());
    
    kdDebug(25001) << "Load: " << endl;
    kafkaCommon::coutTree(node, 3);
    
    return node;
}

#include "kafkadragobject.moc"