-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPasteOMaticPaster.cpp
133 lines (109 loc) · 2.67 KB
/
PasteOMaticPaster.cpp
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
* Copyright 2006-2010, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Author:
* Andras Sevcsik <[email protected]>
*/
#include "defines.h"
#include "PasteOMaticPaster.h"
#include <Clipboard.h>
#include <Entry.h>
#include <Messenger.h>
#include <iostream>
using namespace std;
#include <stdlib.h>
#include <string.h>
PasteOMaticPaster::PasteOMaticPaster(BHandler *handler) : BLooper()
{
fHandler = handler;
success = false;
}
void PasteOMaticPaster::MessageReceived(BMessage *message)
{
void *data;
char *returnString;
int32 size;
entry_ref ref;
BMessage reply;
BMessage *clip;
switch (message->what)
{
case MESSAGE_PASTE_POINTER:
cout << "Paster: got pointer\n";
message->PrintToStream();
message->FindPointer("data", &data);
message->FindInt32("size", &size);
returnString = _Paste(data, (size_t)size);
break;
case MESSAGE_PASTE_REF:
cout << "Paster: got ref\n";
message->PrintToStream();
message->FindRef("ref", &ref);
returnString = _Paste(&ref);
}
if (success)
{
cerr << "Paster sending SUCCESS message: ";
reply.what = MESSAGE_PASTE_SUCCESS;
reply.AddString("link", returnString);
be_clipboard->Lock();
be_clipboard->Clear();
if ((clip = be_clipboard->Data()))
{
clip->AddData("text/plain", B_MIME_TYPE, returnString, strlen(returnString));
be_clipboard->Commit();
}
be_clipboard->Unlock();
reply.PrintToStream();
fHandler->Looper()->Lock();
fHandler->MessageReceived(&reply);
fHandler->Looper()->Unlock();
}
else
{
cerr << "Paster sending FAIL message: ";
reply.what = MESSAGE_PASTE_FAIL;
reply.AddString("error", returnString);
reply.PrintToStream();
fHandler->Looper()->Lock();
fHandler->MessageReceived(&reply);
fHandler->Looper()->Unlock();
}
Quit();
}
PasteOMaticPaster::~PasteOMaticPaster()
{
}
bool PasteOMaticPaster::Check(char *type, size_t size)
{
cerr << "Check(char *type, size_t size) not implemented\n";
return false;
}
char *PasteOMaticPaster::_Paste(void *data, size_t size)
{
cerr << "Paste(void *data, size_t size) not implemented\n";
return NULL;
}
char *PasteOMaticPaster::_Paste(entry_ref *ref)
{
cerr << "Paste(entry_ref *ref) not implemented\n";
return NULL;
}
void PasteOMaticPaster::_Progress(int8 percentage)
{
BMessage message;
message.what = MESSAGE_PASTE_PROGRESS;
message.AddInt8("percentage", percentage);
fHandler->Looper()->Lock();
fHandler->MessageReceived(&message);
fHandler->Looper()->Unlock();
}
void PasteOMaticPaster::_Progress()
{
BMessage message;
message.what = MESSAGE_PASTE_PROGRESS;
fHandler->Looper()->Lock();
fHandler->MessageReceived(&message);
fHandler->Looper()->Unlock();
}