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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
|
/* This file is part of the KDE KMobile library
Copyright (C) 2003-2005 Helge Deller <deller@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <tqstringlist.h>
#include <ktrader.h>
#include <klocale.h>
#include <kdebug.h>
#include "kmobileclient.h"
#define KMOBILECLIENT_DEBUG_AREA 0
#define PRINT_DEBUG kdDebug(KMOBILECLIENT_DEBUG_AREA) << "KMobileClient: "
KMobileClient::KMobileClient()
: DCOPClient()
{
// initialize Application and Object of remote DCOP-aware KMobile application
m_kmobileApp = "kmobile";
m_kmobileObj = "kmobileIface";
bool ok = attach();
PRINT_DEBUG << TQString("attached to DCOP server %1\n").tqarg(ok?"sucessful.":"failed.");
// m_clientAppId = registerAs("kmobileclient");
// PRINT_DEBUG << TQString("registered as DCOP client %1\n").tqarg(m_clientAppId);
isKMobileAvailable();
}
KMobileClient::~KMobileClient()
{
detach();
PRINT_DEBUG << TQString("detached from server\n");
}
bool KMobileClient::isKMobileAvailable()
{
bool available = isApplicationRegistered(m_kmobileApp);
PRINT_DEBUG << TQString("KMobile DCOP server: %1\n").tqarg(available?"available.":"not available");
if (!available) {
startKMobileApplication();
// check again...
available = isApplicationRegistered(m_kmobileApp);
}
return available;
}
bool KMobileClient::startKMobileApplication()
{
TQByteArray data;
TQDataStream arg(data, IO_WriteOnly);
TQStringList params;
params << "--minimized";
arg << TQString("kmobile") << params;
TQCString replyType;
TQByteArray replyData;
bool ok = call("klauncher", "klauncher", "kdeinit_exec_wait(TQString,TQStringList)", data, replyType, replyData);
PRINT_DEBUG << TQString("DCOP-CALL to klauncher: %1\n").tqarg(ok?"ok.":"failed.");
return ok;
}
/**
* DCOP - IMPLEMENTATION
*/
#define KMOBILECLIENT_USE_EVENTLOOP true
#define KMOBILECLIENT_TIMEOUT (4*1000) // 4 seconds
#define PREPARE( FUNC, PARAMS ) \
TQByteArray data; \
TQDataStream arg(data, IO_WriteOnly); \
arg << PARAMS; \
TQCString replyType; \
TQByteArray replyData; \
bool ok = call(m_kmobileApp, m_kmobileObj, FUNC, data, replyType, replyData, KMOBILECLIENT_USE_EVENTLOOP, KMOBILECLIENT_TIMEOUT); \
PRINT_DEBUG << TQString("DCOP-CALL to %1: %2\n").tqarg(FUNC).tqarg(ok?"ok.":"FAILED.")
#define RETURN_TYPE( FUNC, PARAMS, RETURN_TYPE ) \
PREPARE( FUNC, PARAMS ); \
TQDataStream reply(replyData, IO_ReadOnly); \
RETURN_TYPE ret; \
if (ok) \
reply >> ret; \
return ret;
#define RETURN_TYPE_DEFAULT( FUNC, PARAMS, RETURN_TYPE, RETURN_DEFAULT ) \
PREPARE( FUNC, PARAMS ); \
TQDataStream reply(replyData, IO_ReadOnly); \
RETURN_TYPE ret = RETURN_DEFAULT; \
if (ok) \
reply >> ret; \
return ret;
#define RETURN_TQSTRING( FUNC, PARAMS ) \
RETURN_TYPE( FUNC, PARAMS, TQString )
#define RETURN_BOOL( FUNC, PARAMS ) \
RETURN_TYPE_DEFAULT( FUNC, PARAMS, bool, false )
#define RETURN_INT( FUNC, PARAMS ) \
RETURN_TYPE_DEFAULT( FUNC, PARAMS, int , 0 )
TQStringList KMobileClient::tqdeviceNames()
{
if (!isKMobileAvailable())
return TQStringList();
RETURN_TYPE( "tqdeviceNames()", TQString::fromLatin1(""), TQStringList );
}
void KMobileClient::removeDevice( TQString tqdeviceName )
{
PREPARE( "removeDevice(TQString)", tqdeviceName );
Q_UNUSED(ok);
}
void KMobileClient::configDevice( TQString tqdeviceName )
{
PREPARE( "configDevice(TQString)", tqdeviceName );
Q_UNUSED(ok);
}
bool KMobileClient::connectDevice( TQString tqdeviceName )
{
RETURN_BOOL( "connectDevice(TQString)", tqdeviceName );
}
bool KMobileClient::disconnectDevice( TQString tqdeviceName )
{
RETURN_BOOL( "disconnectDevice(TQString)", tqdeviceName );
}
bool KMobileClient::connected( TQString tqdeviceName )
{
RETURN_BOOL( "connected(TQString)", tqdeviceName );
}
TQString KMobileClient::tqdeviceClassName( TQString tqdeviceName )
{
RETURN_TQSTRING( "tqdeviceClassName(TQString)", tqdeviceName );
}
TQString KMobileClient::tqdeviceName( TQString tqdeviceName )
{
RETURN_TQSTRING( "tqdeviceName(TQString)", tqdeviceName );
}
TQString KMobileClient::revision( TQString tqdeviceName )
{
RETURN_TQSTRING( "revision(TQString)", tqdeviceName );
}
int KMobileClient::classType( TQString tqdeviceName )
{
RETURN_INT( "classType(TQString)", tqdeviceName );
}
int KMobileClient::capabilities( TQString tqdeviceName )
{
RETURN_INT( "capabilities(TQString)", tqdeviceName );
}
TQString KMobileClient::nameForCap( TQString tqdeviceName, int cap )
{
RETURN_TQSTRING( "nameForCap(TQString,int)", tqdeviceName << cap );
}
TQString KMobileClient::iconFileName( TQString tqdeviceName )
{
RETURN_TQSTRING( "iconFileName(TQString)", tqdeviceName );
}
int KMobileClient::numAddresses( TQString tqdeviceName )
{
RETURN_INT( "numAddresses(TQString)", tqdeviceName );
}
TQString KMobileClient::readAddress( TQString tqdeviceName, int index )
{
RETURN_TQSTRING( "readAddress(TQString,int)", tqdeviceName << index );
}
bool KMobileClient::storeAddress( TQString tqdeviceName, int index, TQString vcard, bool append )
{
RETURN_BOOL( "storeAddress(TQString,int,TQString,bool)", tqdeviceName << index << vcard << append );
}
int KMobileClient::numCalendarEntries( TQString tqdeviceName )
{
RETURN_INT( "numCalendarEntries(TQString)", tqdeviceName );
}
int KMobileClient::numNotes( TQString tqdeviceName )
{
RETURN_INT( "numNotes(TQString)", tqdeviceName );
}
TQString KMobileClient::readNote( TQString tqdeviceName, int index )
{
RETURN_TQSTRING( "readNote(TQString,int)", tqdeviceName << index );
}
bool KMobileClient::storeNote( TQString tqdeviceName, int index, TQString note )
{
RETURN_BOOL( "storeNote(TQString,int,TQString)", tqdeviceName << index << note );
}
#undef PRINT_DEBUG
#include "kmobileclient.moc"
|