summaryrefslogtreecommitdiffstats
path: root/ksysv/ksvdrag.cpp
blob: 7d945360a494de6e39c8d880ef03a272088f7907 (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
91
92
93
94
95
96
97
98
99
100
101
102
// (c) 2000 Peter Putzer

#include <tqstring.h>
#include <tqcstring.h>

#include <kurl.h>

#include "Data.h"
#include "ksvdraglist.h"
#include "ksvdrag.h"

class KSVDrag::Private
{
public:
  TQByteArray mNative;
  TQString mText;
  KURL mURL;
};

KSVDrag::KSVDrag (const KSVData& item, TQWidget* source, const char* name)
  : TQDragObject (source, name),
    d (new Private())
{
  TQDataStream ds (d->mNative, IO_ReadWrite);
  ds << item;

  d->mText = item.filenameAndPath ();
  d->mURL.setPath (item.path() + "/" + item.filename());
}

KSVDrag::KSVDrag (const KSVItem& item, TQWidget* source, const char* name)
  : TQDragObject (source, name),
    d (new Private())
{
  TQDataStream ds (d->mNative, IO_ReadWrite);
  ds << *item.data();

  d->mText = item.toString();
  d->mURL.setPath (item.path() + "/" + item.filename());
}

KSVDrag::~KSVDrag ()
{
  delete d;
}

const char* KSVDrag::format (int i) const
{
  switch (i)
	{
	case Native:
	  return "application/x-ksysv";
	  break;
	  
	case Text:
	  return "text/plain";
	  break;
	  
	case URL:
	  return "text/uri-list";
	  break;
	  
	default:
	  return 0L;
	}
}

TQByteArray KSVDrag::encodedData (const char* format) const
{
  TQByteArray res;

  if (!strcmp (format, "application/x-ksysv"))
    {
      res = d->mNative;
    }
  else if (!strcmp (format, "text/plain"))
    {
      TQDataStream ds (res, IO_ReadWrite);
	  ds << d->mText;
    }
  else if (!strcmp (format, "text/uri-list"))
    {
      res = TQCString(d->mURL.url().latin1()).copy();
    }

  return res;
}

bool KSVDrag::decodeNative (const TQMimeSource* mime, KSVData& data)
{
  if (mime && mime->provides ("application/x-ksysv"))
	{
	  TQDataStream ds (mime->encodedData ("application/x-ksysv"), IO_ReadOnly);
	  ds >> data;

	  return true;
	}

  return false;
}

#include "ksvdrag.moc"