Subversion Repositories tpanel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 andreas 1
/*
435 andreas 2
 * Copyright (C) 2020 to 2024 by Andreas Theofilu <andreas@theosys.at>
3 andreas 3
 *
4
 * This program is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software Foundation,
16
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
17
 */
18
 
270 andreas 19
#include <QtGlobal>
20
 
3 andreas 21
#include <vector>
14 andreas 22
#include <thread>
23
#include <mutex>
186 andreas 24
 
36 andreas 25
#ifdef __ANDROID__
264 andreas 26
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
183 andreas 27
#       include <QtAndroidExtras/QAndroidJniObject>
28
#       include <QtAndroidExtras/QtAndroid>
216 andreas 29
#   else
30
#       include <QJniObject>
31
#       include <QCoreApplication>
183 andreas 32
#   endif
33
#   include <android/log.h>
182 andreas 34
#endif
134 andreas 35
#include <unistd.h>
36
#ifndef __ANDROID__
183 andreas 37
#   include <fstab.h>
134 andreas 38
#endif
14 andreas 39
 
186 andreas 40
#if __cplusplus < 201402L
41
#   error "This module requires at least C++14 standard!"
42
#else
43
#   if __cplusplus < 201703L
44
#       include <experimental/filesystem>
45
namespace fs = std::experimental::filesystem;
46
#       warning "Support for C++14 and experimental filesystem will be removed in a future version!"
47
#   else
48
#       include <filesystem>
49
#       ifdef __ANDROID__
50
namespace fs = std::__fs::filesystem;
51
#       else
52
namespace fs = std::filesystem;
53
#       endif
54
#   endif
55
#endif
56
 
235 andreas 57
#ifdef __APPLE__
58
#   include <unistd.h>
59
#   ifndef HOST_NAME_MAX
60
#       ifdef MAXHOSTNAMELEN
61
#           define HOST_NAME_MAX    MAXHOSTNAMELEN
62
#       else
63
#           define HOST_NAME_MAX    64
64
#       endif   // MAXHOSTNAMELEN
65
#   endif       // HOST_NAME_MAX
66
#endif          // __APPLE__
67
 
3 andreas 68
#include "tpagemanager.h"
4 andreas 69
#include "tcolor.h"
3 andreas 70
#include "terror.h"
8 andreas 71
#include "ticons.h"
14 andreas 72
#include "tbutton.h"
8 andreas 73
#include "tprjresources.h"
11 andreas 74
#include "tresources.h"
271 andreas 75
#include "tresources.h"
71 andreas 76
#include "tsystemsound.h"
77
#include "tvalidatefile.h"
122 andreas 78
#include "ttpinit.h"
211 andreas 79
#include "tconfig.h"
299 andreas 80
#include "tlock.h"
336 andreas 81
#include "tintborder.h"
264 andreas 82
#ifdef Q_OS_IOS
83
#include "ios/tiosbattery.h"
84
#endif
326 andreas 85
#if TESTMODE == 1
86
#include "testmode.h"
87
#endif
3 andreas 88
 
89
using std::vector;
90
using std::string;
11 andreas 91
using std::map;
92
using std::pair;
93
using std::to_string;
14 andreas 94
using std::thread;
95
using std::atomic;
96
using std::mutex;
21 andreas 97
using std::bind;
3 andreas 98
 
8 andreas 99
TIcons *gIcons = nullptr;
100
TPrjResources *gPrjResources = nullptr;
14 andreas 101
TPageManager *gPageManager = nullptr;
169 andreas 102
//std::vector<amx::ANET_COMMAND> TPageManager::mCommands;
103
 
14 andreas 104
extern amx::TAmxNet *gAmxNet;
90 andreas 105
extern std::atomic<bool> _netRunning;
92 andreas 106
extern bool _restart_;                          //!< If this is set to true then the whole program will start over.
8 andreas 107
 
21 andreas 108
bool prg_stopped = false;
14 andreas 109
 
37 andreas 110
#ifdef __ANDROID__
255 andreas 111
string javaJStringToString(JNIEnv *env, jstring str)
112
{
113
    if (!str)
114
        return string();
115
 
116
    const jclass stringClass = env->GetObjectClass(str);
117
    const jmethodID getBytes = env->GetMethodID(stringClass, "getBytes", "(Ljava/lang/String;)[B");
118
    const jbyteArray stringJbytes = (jbyteArray) env->CallObjectMethod(str, getBytes, env->NewStringUTF("UTF-8"));
119
 
120
    size_t length = (size_t) env->GetArrayLength(stringJbytes);
121
    jbyte* pBytes = env->GetByteArrayElements(stringJbytes, NULL);
122
 
123
    string ret = std::string((char *)pBytes, length);
124
    env->ReleaseByteArrayElements(stringJbytes, pBytes, JNI_ABORT);
125
 
126
    env->DeleteLocalRef(stringJbytes);
127
    env->DeleteLocalRef(stringClass);
128
    return ret;
129
}
130
 
38 andreas 131
JNIEXPORT void JNICALL Java_org_qtproject_theosys_BatteryState_informBatteryStatus(JNIEnv *, jclass, jint level, jboolean charging, jint chargeType)
132
{
61 andreas 133
    DECL_TRACER("JNICALL Java_org_qtproject_theosys_BatteryState_informBatteryStatus(JNIEnv *, jclass, jint level, jboolean charging, jint chargeType)");
134
 
38 andreas 135
    if (gPageManager)
136
        gPageManager->informBatteryStatus(level, charging, chargeType);
137
}
138
 
36 andreas 139
JNIEXPORT void JNICALL Java_org_qtproject_theosys_NetworkStatus_informTPanelNetwork(JNIEnv */*env*/, jclass /*clazz*/, jboolean conn, jint level, jint type)
140
{
61 andreas 141
    DECL_TRACER("JNICALL Java_org_qtproject_theosys_NetworkStatus_informTPanelNetwork(JNIEnv */*env*/, jclass /*clazz*/, jboolean conn, jint level, jint type)");
365 andreas 142
 
143
    //Call native side conterpart
144
    if (gPageManager)
36 andreas 145
        gPageManager->informTPanelNetwork(conn, level, type);
146
}
47 andreas 147
 
61 andreas 148
JNIEXPORT void JNICALL Java_org_qtproject_theosys_PhoneCallState_informPhoneState(JNIEnv *env, jclass, jboolean call, jstring pnumber)
47 andreas 149
{
61 andreas 150
    DECL_TRACER("JNICALL Java_org_qtproject_theosys_PhoneCallState_informPhoneState(JNIEnv *env, jclass, jboolean call, jstring pnumber)");
151
 
152
    string phoneNumber;
153
 
154
    if (pnumber)
255 andreas 155
        phoneNumber = javaJStringToString(env, pnumber);
61 andreas 156
 
157
    if (gPageManager)
158
        gPageManager->informPhoneState(call, phoneNumber);
47 andreas 159
}
160
 
61 andreas 161
JNIEXPORT void JNICALL Java_org_qtproject_theosys_Logger_logger(JNIEnv *env, jclass, jint mode, jstring msg)
47 andreas 162
{
163
    if (!msg)
164
        return;
165
 
255 andreas 166
    string ret = javaJStringToString(env, msg);
47 andreas 167
 
61 andreas 168
    try
169
    {
170
        if (TStreamError::checkFilter(mode))
260 andreas 171
        {
172
            *TError::Current()->getStream() << TError::append(mode) << ret << std::endl;
173
            TStreamError::resetFlags();
174
        }
61 andreas 175
    }
176
    catch (std::exception& e)
177
    {
178
        __android_log_print(ANDROID_LOG_ERROR, "tpanel", "%s", e.what());
179
    }
47 andreas 180
}
130 andreas 181
 
182
JNIEXPORT void JNICALL Java_org_qtproject_theosys_Orientation_informTPanelOrientation(JNIEnv */*env*/, jclass /*clazz*/, jint orientation)
183
{
184
    DECL_TRACER("Java_org_qtproject_theosys_Orientation_informTPanelOrientation(JNIEnv */*env*/, jclass /*clazz*/, jint orientation)");
185
 
134 andreas 186
    if (!gPageManager)
187
        return;
188
 
189
    if (gPageManager->onOrientationChange())
130 andreas 190
        gPageManager->onOrientationChange()(orientation);
134 andreas 191
 
192
    gPageManager->setOrientation(orientation);
193
 
194
    if (gPageManager->getInformOrientation())
195
        gPageManager->sendOrientation();
130 andreas 196
}
255 andreas 197
 
198
/* -------- Settings -------- */
256 andreas 199
 
200
JNIEXPORT void JNICALL Java_org_qtproject_theosys_SettingsActivity_saveSettings(JNIEnv *env, jclass clazz)
255 andreas 201
{
256 andreas 202
    DECL_TRACER("Java_org_qtproject_theosys_SettingsActivity_saveSettings(JNIEnv *env, jclass clazz)");
255 andreas 203
 
256 andreas 204
    Q_UNUSED(env);
255 andreas 205
    Q_UNUSED(clazz);
206
 
259 andreas 207
    TConfig::setTemporary(true);
208
    string oldNetlinx = TConfig::getController();
209
    int oldPort = TConfig::getPort();
210
    int oldChannelID = TConfig::getChannel();
211
    string oldSurface = TConfig::getFtpSurface();
212
    bool oldToolbarSuppress = TConfig::getToolbarSuppress();
213
    bool oldToolbarForce = TConfig::getToolbarForce();
214
    TConfig::setTemporary(false);
215
    MSG_DEBUG("Old values:\n" <<
216
              "   NetLinx: " << oldNetlinx << "\n" <<
217
              "   Port:    " << oldPort << "\n" <<
218
              "   Channel: " << oldChannelID << "\n" <<
219
              "   Surface: " << oldSurface << "\n" <<
220
              "   TB suppr:" << oldToolbarSuppress << "\n" <<
221
              "   TB force:" << oldToolbarForce);
256 andreas 222
    TConfig::saveSettings();
259 andreas 223
 
224
    MSG_DEBUG("New values:\n" <<
225
              "   NetLinx: " << TConfig::getController() << "\n" <<
226
              "   Port:    " << TConfig::getPort() << "\n" <<
227
              "   Channel: " << TConfig::getChannel() << "\n" <<
228
              "   Surface: " << TConfig::getFtpSurface() << "\n" <<
229
              "   TB suppr:" << TConfig::getToolbarSuppress() << "\n" <<
230
              "   TB force:" << TConfig::getToolbarForce());
231
 
232
    if (gPageManager && gPageManager->onSettingsChanged())
233
        gPageManager->onSettingsChanged()(oldNetlinx, oldPort, oldChannelID, oldSurface, oldToolbarSuppress, oldToolbarForce);
256 andreas 234
}
235
 
236
JNIEXPORT void JNICALL Java_org_qtproject_theosys_SettingsActivity_setNetlinxIp(JNIEnv *env, jclass clazz, jstring ip)
237
{
238
    DECL_TRACER("Java_org_qtproject_theosys_Settings_setNetlinxIp(JNIEnv *env, jclass clazz, jstring ip)");
239
 
240
    Q_UNUSED(clazz);
241
 
255 andreas 242
    string netlinxIp = javaJStringToString(env, ip);
243
 
244
    if (TConfig::getController() != netlinxIp)
245
        TConfig::saveController(netlinxIp);
246
}
247
 
256 andreas 248
JNIEXPORT void JNICALL Java_org_qtproject_theosys_SettingsActivity_setNetlinxPort(JNIEnv *env, jclass clazz, jint port)
255 andreas 249
{
256 andreas 250
    DECL_TRACER("Java_org_qtproject_theosys_Settings_setNetlinxPort(JNIEnv *env, jclass clazz, jint port)");
255 andreas 251
 
252
    Q_UNUSED(env);
253
    Q_UNUSED(clazz);
254
 
255
    if (port > 0 && port < 65535 && TConfig::getPort() != port)
256
        TConfig::savePort(port);
257
}
258
 
256 andreas 259
JNIEXPORT void JNICALL Java_org_qtproject_theosys_SettingsActivity_setNetlinxChannel(JNIEnv *env, jclass clazz, jint channel)
255 andreas 260
{
256 andreas 261
    DECL_TRACER("Java_org_qtproject_theosys_Settings_setNetlinxChannel(JNIEnv *env, jclass clazz, jint channel)");
255 andreas 262
 
263
    Q_UNUSED(env);
264
    Q_UNUSED(clazz);
265
 
266
    if (channel >= 10000 && channel < 20000 && TConfig::getChannel() != channel)
271 andreas 267
        TConfig::saveChannel(channel);
255 andreas 268
}
256 andreas 269
 
270
JNIEXPORT void JNICALL Java_org_qtproject_theosys_SettingsActivity_setNetlinxType(JNIEnv *env, jclass clazz, jstring type)
271
{
272
    DECL_TRACER("Java_org_qtproject_theosys_Settings_setNetlinxType(JNIEnv *env, jclass clazz, jstring type)");
273
 
274
    Q_UNUSED(clazz);
275
 
276
    string netlinxType = javaJStringToString(env, type);
277
 
278
    if (TConfig::getPanelType() != netlinxType)
279
        TConfig::savePanelType(netlinxType);
280
}
281
 
282
JNIEXPORT void JNICALL Java_org_qtproject_theosys_SettingsActivity_setNetlinxFtpUser(JNIEnv *env, jclass clazz, jstring user)
283
{
284
    DECL_TRACER("Java_org_qtproject_theosys_Settings_setNetlinxFtpUser(JNIEnv *env, jclass clazz, jstring user)");
285
 
286
    Q_UNUSED(clazz);
287
 
288
    string netlinxFtpUser = javaJStringToString(env, user);
289
 
290
    if (TConfig::getFtpUser() != netlinxFtpUser)
291
        TConfig::saveFtpUser(netlinxFtpUser);
292
}
293
 
294
JNIEXPORT void JNICALL Java_org_qtproject_theosys_SettingsActivity_setNetlinxFtpPassword(JNIEnv *env, jclass clazz, jstring pw)
295
{
296
    DECL_TRACER("Java_org_qtproject_theosys_Settings_setNetlinxFtpPassword(JNIEnv *env, jclass clazz, jstring pw)");
297
 
298
    Q_UNUSED(clazz);
299
 
300
    string netlinxPw = javaJStringToString(env, pw);
301
 
302
    if (TConfig::getFtpPassword() != netlinxPw)
303
        TConfig::saveFtpPassword(netlinxPw);
304
}
305
 
306
JNIEXPORT void JNICALL Java_org_qtproject_theosys_SettingsActivity_setNetlinxSurface(JNIEnv *env, jclass clazz, jstring surface)
307
{
308
    DECL_TRACER("Java_org_qtproject_theosys_Settings_setNetlinxIp(JNIEnv *env, jclass clazz, jstring surface)");
309
 
310
    Q_UNUSED(clazz);
311
 
312
    string netlinxSurface = javaJStringToString(env, surface);
313
 
314
    if (TConfig::getFtpSurface() != netlinxSurface)
315
        TConfig::saveFtpSurface(netlinxSurface);
316
}
317
 
318
JNIEXPORT void JNICALL Java_org_qtproject_theosys_SettingsActivity_setNetlinxFtpPassive(JNIEnv *env, jclass clazz, jboolean passive)
319
{
320
    DECL_TRACER("Java_org_qtproject_theosys_Settings_setNetlinxIp(JNIEnv *env, jclass clazz, jboolean passive)");
321
 
322
    Q_UNUSED(env);
323
    Q_UNUSED(clazz);
324
 
325
    if (TConfig::getFtpPassive() != passive)
326
        TConfig::saveFtpPassive(passive);
327
}
328
 
329
JNIEXPORT void JNICALL Java_org_qtproject_theosys_SettingsActivity_setViewScale(JNIEnv *env, jclass clazz, jboolean scale)
330
{
331
    DECL_TRACER("Java_org_qtproject_theosys_Settings_setViewScale(JNIEnv *env, jclass clazz, jboolean scale)");
332
 
333
    Q_UNUSED(env);
334
    Q_UNUSED(clazz);
335
 
336
    if (TConfig::getScale() != scale)
337
        TConfig::saveScale(scale);
338
}
339
 
340
JNIEXPORT void JNICALL Java_org_qtproject_theosys_SettingsActivity_setViewToolbar(JNIEnv *env, jclass clazz, jboolean bar)
341
{
342
    DECL_TRACER("Java_org_qtproject_theosys_Settings_setViewToolbar(JNIEnv *env, jclass clazz, jboolean bar)");
343
 
344
    Q_UNUSED(env);
345
    Q_UNUSED(clazz);
346
 
260 andreas 347
    if (TConfig::getToolbarSuppress() == bar)
348
        TConfig::saveToolbarSuppress(!bar);
256 andreas 349
}
350
 
351
JNIEXPORT void JNICALL Java_org_qtproject_theosys_SettingsActivity_setViewToolbarForce(JNIEnv *env, jclass clazz, jboolean bar)
352
{
353
    DECL_TRACER("Java_org_qtproject_theosys_Settings_setViewToolbarForce(JNIEnv *env, jclass clazz, jboolean bar)");
354
 
355
    Q_UNUSED(env);
356
    Q_UNUSED(clazz);
357
 
358
    if (TConfig::getToolbarForce() != bar)
359
        TConfig::saveToolbarForce(bar);
360
}
361
 
362
JNIEXPORT void JNICALL Java_org_qtproject_theosys_SettingsActivity_setViewRotation(JNIEnv *env, jclass clazz, jboolean rotate)
363
{
364
    DECL_TRACER("Java_org_qtproject_theosys_Settings_setViewRotation(JNIEnv *env, jclass clazz, jboolean rotate)");
365
 
366
    Q_UNUSED(env);
367
    Q_UNUSED(clazz);
368
 
369
    if (TConfig::getRotationFixed() != rotate)
370
        TConfig::setRotationFixed(rotate);
371
}
372
 
373
JNIEXPORT void JNICALL Java_org_qtproject_theosys_SettingsActivity_setSoundSystem(JNIEnv *env, jclass clazz, jstring sound)
374
{
375
    DECL_TRACER("Java_org_qtproject_theosys_Settings_setSoundSystem(JNIEnv *env, jclass clazz, jstring sound)");
376
 
377
    Q_UNUSED(clazz);
378
 
379
    string s = javaJStringToString(env, sound);
380
 
381
    if (TConfig::getSystemSound() != s)
382
        TConfig::saveSystemSoundFile(s);
383
}
384
 
385
JNIEXPORT void JNICALL Java_org_qtproject_theosys_SettingsActivity_setSoundSingle(JNIEnv *env, jclass clazz, jstring sound)
386
{
387
    DECL_TRACER("Java_org_qtproject_theosys_Settings_setSoundSingle(JNIEnv *env, jclass clazz, jstring sound)");
388
 
389
    Q_UNUSED(clazz);
390
 
391
    string s = javaJStringToString(env, sound);
392
 
393
    if (TConfig::getSingleBeepSound() != s)
394
        TConfig::saveSingleBeepFile(s);
395
}
396
 
397
JNIEXPORT void JNICALL Java_org_qtproject_theosys_SettingsActivity_setSoundDouble(JNIEnv *env, jclass clazz, jstring sound)
398
{
399
    DECL_TRACER("Java_org_qtproject_theosys_Settings_setSoundDouble(JNIEnv *env, jclass clazz, jstring sound)");
400
 
401
    Q_UNUSED(clazz);
402
 
403
    string s = javaJStringToString(env, sound);
404
 
405
    if (TConfig::getDoubleBeepSound() != s)
406
        TConfig::saveDoubleBeepFile(s);
407
}
408
 
409
JNIEXPORT void JNICALL Java_org_qtproject_theosys_SettingsActivity_setSoundEnable(JNIEnv *env, jclass clazz, jboolean sound)
410
{
411
    DECL_TRACER("Java_org_qtproject_theosys_Settings_setSoundEnable(JNIEnv *env, jclass clazz, jboolean sound)");
412
 
413
    Q_UNUSED(env);
414
    Q_UNUSED(clazz);
415
 
416
    if (TConfig::getSystemSoundState() != sound)
417
        TConfig::saveSystemSoundState(sound);
418
}
419
 
420
JNIEXPORT void JNICALL Java_org_qtproject_theosys_SettingsActivity_setSoundVolume(JNIEnv *env, jclass clazz, jint sound)
421
{
422
    DECL_TRACER("Java_org_qtproject_theosys_Settings_setSoundVolume(JNIEnv *env, jclass clazz, jint sound)");
423
 
424
    Q_UNUSED(env);
425
    Q_UNUSED(clazz);
426
 
427
    if (TConfig::getSystemVolume() != sound)
428
        TConfig::saveSystemVolume(sound);
429
}
430
 
431
JNIEXPORT void JNICALL Java_org_qtproject_theosys_SettingsActivity_setSoundGain(JNIEnv *env, jclass clazz, jint sound)
432
{
433
    DECL_TRACER("Java_org_qtproject_theosys_Settings_setSoundGain(JNIEnv *env, jclass clazz, jint sound)");
434
 
435
    Q_UNUSED(env);
436
    Q_UNUSED(clazz);
437
 
438
    if (TConfig::getSystemGain() != sound)
439
        TConfig::saveSystemGain(sound);
440
}
257 andreas 441
 
442
JNIEXPORT void JNICALL Java_org_qtproject_theosys_SettingsActivity_setSipProxy(JNIEnv *env, jclass clazz, jstring sip)
443
{
444
    DECL_TRACER("Java_org_qtproject_theosys_Settings_setSipProxy(JNIEnv *env, jclass clazz, jstring sip)");
445
 
446
    Q_UNUSED(clazz);
447
 
448
    string sipStr = javaJStringToString(env, sip);
449
 
450
    if (TConfig::getSIPproxy() != sipStr)
451
        TConfig::setSIPproxy(sipStr);
452
}
453
 
454
JNIEXPORT void JNICALL Java_org_qtproject_theosys_SettingsActivity_setSipPort(JNIEnv *env, jclass clazz, jint sip)
455
{
456
    DECL_TRACER("Java_org_qtproject_theosys_Settings_setSipPort(JNIEnv *env, jclass clazz, jint sip)");
457
 
458
    Q_UNUSED(env);
459
    Q_UNUSED(clazz);
460
 
461
    if (TConfig::getSIPport() != sip)
462
        TConfig::setSIPport(sip);
463
}
464
 
465
JNIEXPORT void JNICALL Java_org_qtproject_theosys_SettingsActivity_setSipTlsPort(JNIEnv *env, jclass clazz, jint sip)
466
{
467
    DECL_TRACER("Java_org_qtproject_theosys_Settings_setSipTlsPort(JNIEnv *env, jclass clazz, jint sip)");
468
 
469
    Q_UNUSED(env);
470
    Q_UNUSED(clazz);
471
 
472
    if (TConfig::getSIPportTLS() != sip)
473
        TConfig::setSIPportTLS(sip);
474
}
475
 
476
JNIEXPORT void JNICALL Java_org_qtproject_theosys_SettingsActivity_setSipStun(JNIEnv *env, jclass clazz, jstring sip)
477
{
478
    DECL_TRACER("Java_org_qtproject_theosys_Settings_setSipStun(JNIEnv *env, jclass clazz, jstring sip)");
479
 
480
    Q_UNUSED(clazz);
481
 
482
    string sipStr = javaJStringToString(env, sip);
483
 
484
    if (TConfig::getSIPstun() != sipStr)
485
        TConfig::setSIPstun(sipStr);
486
}
487
 
488
JNIEXPORT void JNICALL Java_org_qtproject_theosys_SettingsActivity_setSipDomain(JNIEnv *env, jclass clazz, jstring sip)
489
{
490
    DECL_TRACER("Java_org_qtproject_theosys_Settings_setSipDomain(JNIEnv *env, jclass clazz, jstring sip)");
491
 
492
    Q_UNUSED(clazz);
493
 
494
    string sipStr = javaJStringToString(env, sip);
495
 
496
    if (TConfig::getSIPdomain() != sipStr)
497
        TConfig::setSIPdomain(sipStr);
498
}
499
 
500
JNIEXPORT void JNICALL Java_org_qtproject_theosys_SettingsActivity_setSipUser(JNIEnv *env, jclass clazz, jstring sip)
501
{
502
    DECL_TRACER("Java_org_qtproject_theosys_Settings_setSipUser(JNIEnv *env, jclass clazz, jstring sip)");
503
 
504
    Q_UNUSED(clazz);
505
 
506
    string sipStr = javaJStringToString(env, sip);
507
 
508
    if (TConfig::getSIPuser() != sipStr)
509
        TConfig::setSIPuser(sipStr);
510
}
511
 
512
JNIEXPORT void JNICALL Java_org_qtproject_theosys_SettingsActivity_setSipPassword(JNIEnv *env, jclass clazz, jstring sip)
513
{
514
    DECL_TRACER("Java_org_qtproject_theosys_Settings_setSipPassword(JNIEnv *env, jclass clazz, jstring sip)");
515
 
516
    Q_UNUSED(clazz);
517
 
518
    string sipStr = javaJStringToString(env, sip);
519
 
520
    if (TConfig::getSIPpassword() != sipStr)
521
        TConfig::setSIPpassword(sipStr);
522
}
523
 
524
JNIEXPORT void JNICALL Java_org_qtproject_theosys_SettingsActivity_setSipIpv4(JNIEnv *env, jclass clazz, jboolean sip)
525
{
526
    DECL_TRACER("Java_org_qtproject_theosys_Settings_setSipIpv4(JNIEnv *env, jclass clazz, jboolean sip)");
527
 
528
    Q_UNUSED(env);
529
    Q_UNUSED(clazz);
530
 
531
    if (TConfig::getSIPnetworkIPv4() != sip)
532
        TConfig::setSIPnetworkIPv4(sip);
533
}
534
 
535
JNIEXPORT void JNICALL Java_org_qtproject_theosys_SettingsActivity_setSipIpv6(JNIEnv *env, jclass clazz, jboolean sip)
536
{
537
    DECL_TRACER("Java_org_qtproject_theosys_Settings_setSipIpv6(JNIEnv *env, jclass clazz, jboolean sip)");
538
 
539
    Q_UNUSED(env);
540
    Q_UNUSED(clazz);
541
 
542
    if (TConfig::getSIPnetworkIPv6() != sip)
543
        TConfig::setSIPnetworkIPv6(sip);
544
}
545
 
546
JNIEXPORT void JNICALL Java_org_qtproject_theosys_SettingsActivity_setSipEnabled(JNIEnv *env, jclass clazz, jboolean sip)
547
{
548
    DECL_TRACER("Java_org_qtproject_theosys_Settings_setSipEnabled(JNIEnv *env, jclass clazz, jboolean sip)");
549
 
550
    Q_UNUSED(env);
551
    Q_UNUSED(clazz);
552
 
553
    if (TConfig::getSIPstatus() != sip)
554
        TConfig::setSIPstatus(sip);
555
}
556
 
557
JNIEXPORT void JNICALL Java_org_qtproject_theosys_SettingsActivity_setSipIphone(JNIEnv *env, jclass clazz, jboolean sip)
558
{
559
    DECL_TRACER("Java_org_qtproject_theosys_Settings_setSipIphone(JNIEnv *env, jclass clazz, jboolean sip)");
560
 
561
    Q_UNUSED(env);
562
    Q_UNUSED(clazz);
563
 
564
    if (TConfig::getSIPiphone() != sip)
565
        TConfig::setSIPiphone(sip);
566
}
567
 
568
JNIEXPORT void JNICALL Java_org_qtproject_theosys_SettingsActivity_setLogInfo(JNIEnv *env, jclass clazz, jboolean log)
569
{
570
    DECL_TRACER("Java_org_qtproject_theosys_Settings_setLogInfo(JNIEnv *env, jclass clazz, jboolean log)");
571
 
572
    Q_UNUSED(env);
573
    Q_UNUSED(clazz);
574
 
575
    uint logSwitch = (log ? HLOG_INFO : 0);
576
 
577
    if ((TConfig::getLogLevelBits() & HLOG_INFO) != logSwitch)
578
    {
579
        if (!(TConfig::getLogLevelBits() & HLOG_INFO))
580
            TConfig::saveLogLevel(TConfig::getLogLevelBits() | HLOG_INFO);
581
        else
582
            TConfig::saveLogLevel(TConfig::getLogLevelBits() ^ HLOG_INFO);
583
    }
584
}
585
 
586
JNIEXPORT void JNICALL Java_org_qtproject_theosys_SettingsActivity_setLogWarning(JNIEnv *env, jclass clazz, jboolean log)
587
{
588
    DECL_TRACER("Java_org_qtproject_theosys_Settings_setLogWarning(JNIEnv *env, jclass clazz, jboolean log)");
589
 
590
    Q_UNUSED(env);
591
    Q_UNUSED(clazz);
592
 
593
    uint logSwitch = (log ? HLOG_WARNING : 0);
594
 
595
    if ((TConfig::getLogLevelBits() & HLOG_WARNING) != logSwitch)
596
    {
597
        if (!(TConfig::getLogLevelBits() & HLOG_INFO))
598
            TConfig::saveLogLevel(TConfig::getLogLevelBits() | HLOG_WARNING);
599
        else
600
            TConfig::saveLogLevel(TConfig::getLogLevelBits() ^ HLOG_WARNING);
601
    }
602
}
603
 
604
JNIEXPORT void JNICALL Java_org_qtproject_theosys_SettingsActivity_setLogError(JNIEnv *env, jclass clazz, jboolean log)
605
{
606
    DECL_TRACER("Java_org_qtproject_theosys_Settings_setLogError(JNIEnv *env, jclass clazz, jboolean log)");
607
 
608
    Q_UNUSED(env);
609
    Q_UNUSED(clazz);
610
 
611
    uint logSwitch = (log ? HLOG_ERROR : 0);
612
 
613
    if ((TConfig::getLogLevelBits() & HLOG_ERROR) != logSwitch)
614
    {
615
        if (!(TConfig::getLogLevelBits() & HLOG_ERROR))
616
            TConfig::saveLogLevel(TConfig::getLogLevelBits() | HLOG_ERROR);
617
        else
618
            TConfig::saveLogLevel(TConfig::getLogLevelBits() ^ HLOG_ERROR);
619
    }
620
}
621
 
622
JNIEXPORT void JNICALL Java_org_qtproject_theosys_SettingsActivity_setLogTrace(JNIEnv *env, jclass clazz, jboolean log)
623
{
624
    DECL_TRACER("Java_org_qtproject_theosys_Settings_setLogTrace(JNIEnv *env, jclass clazz, jboolean log)");
625
 
626
    Q_UNUSED(env);
627
    Q_UNUSED(clazz);
628
 
629
    uint logSwitch = (log ? HLOG_TRACE : 0);
630
 
631
    if ((TConfig::getLogLevelBits() & HLOG_TRACE) != logSwitch)
632
    {
633
        if (!(TConfig::getLogLevelBits() & HLOG_TRACE))
634
            TConfig::saveLogLevel(TConfig::getLogLevelBits() | HLOG_TRACE);
635
        else
636
            TConfig::saveLogLevel(TConfig::getLogLevelBits() ^ HLOG_TRACE);
637
    }
638
}
639
 
640
JNIEXPORT void JNICALL Java_org_qtproject_theosys_SettingsActivity_setLogDebug(JNIEnv *env, jclass clazz, jboolean log)
641
{
642
    DECL_TRACER("Java_org_qtproject_theosys_Settings_setLogDebug(JNIEnv *env, jclass clazz, jboolean log)");
643
 
644
    Q_UNUSED(env);
645
    Q_UNUSED(clazz);
646
 
647
    uint logSwitch = (log ? HLOG_DEBUG : 0);
648
 
649
    if ((TConfig::getLogLevelBits() & HLOG_DEBUG) != logSwitch)
650
    {
651
        if (!(TConfig::getLogLevelBits() & HLOG_DEBUG))
652
            TConfig::saveLogLevel(TConfig::getLogLevelBits() | HLOG_DEBUG);
653
        else
654
            TConfig::saveLogLevel(TConfig::getLogLevelBits() ^ HLOG_DEBUG);
655
    }
656
}
657
 
658
JNIEXPORT void JNICALL Java_org_qtproject_theosys_SettingsActivity_setLogProfile(JNIEnv *env, jclass clazz, jboolean log)
659
{
660
    DECL_TRACER("Java_org_qtproject_theosys_Settings_setLogProfile(JNIEnv *env, jclass clazz, jboolean log)");
661
 
662
    Q_UNUSED(env);
663
    Q_UNUSED(clazz);
664
 
665
    if (TConfig::getProfiling() != log)
666
        TConfig::saveProfiling(log);
667
}
668
 
669
JNIEXPORT void JNICALL Java_org_qtproject_theosys_SettingsActivity_setLogLongFormat(JNIEnv *env, jclass clazz, jboolean log)
670
{
671
    DECL_TRACER("Java_org_qtproject_theosys_Settings_setLogLongFormat(JNIEnv *env, jclass clazz, jboolean log)");
672
 
673
    Q_UNUSED(env);
674
    Q_UNUSED(clazz);
675
 
676
    if (TConfig::isLongFormat() != log)
677
        TConfig::saveFormat(log);
678
}
679
 
680
JNIEXPORT void JNICALL Java_org_qtproject_theosys_SettingsActivity_setLogEnableFile(JNIEnv *env, jclass clazz, jboolean log)
681
{
682
    DECL_TRACER("Java_org_qtproject_theosys_Settings_setLogEnableFile(JNIEnv *env, jclass clazz, jboolean log)");
683
 
684
    Q_UNUSED(env);
685
    Q_UNUSED(clazz);
686
 
383 andreas 687
    TConfig::setLogFileEnabled(log);
385 andreas 688
    TStreamError::setLogFileEnabled(log);
689
    string logFile = TConfig::getLogFile();
383 andreas 690
 
385 andreas 691
    if (log && !logFile.empty() && fs::is_regular_file(logFile))
692
        TStreamError::setLogFile(logFile);
693
    else if (!log)
694
        TStreamError::setLogFile("");
383 andreas 695
 
385 andreas 696
    __android_log_print(ANDROID_LOG_DEBUG, "tpanel", "JAVA::setLogEnableFile: Logfile was %s", (log ? "ENABLED" : "DISABLED"));
257 andreas 697
}
698
 
699
JNIEXPORT void JNICALL Java_org_qtproject_theosys_SettingsActivity_setLogFile(JNIEnv *env, jclass clazz, jstring log)
700
{
701
    DECL_TRACER("Java_org_qtproject_theosys_Settings_setLogFile(JNIEnv *env, jclass clazz, jstring sip)");
702
 
703
    Q_UNUSED(clazz);
704
 
705
    string logStr = javaJStringToString(env, log);
706
 
707
    if (TConfig::getLogFile() != logStr)
385 andreas 708
    {
257 andreas 709
        TConfig::saveLogFile(logStr);
385 andreas 710
        __android_log_print(ANDROID_LOG_DEBUG, "tpanel", "JAVA::setLogFile: Logfile set to: %s", logStr.c_str());
711
 
712
        if (fs::is_regular_file(logStr))
713
            TStreamError::setLogFile(logStr);
714
        else
715
        {
716
            TStreamError::setLogFile("");
717
            __android_log_print(ANDROID_LOG_WARN, "tpanel", "JAVA::setLogFile: Logfile \"%s\" is not accessible!", logStr.c_str());
718
        }
719
    }
257 andreas 720
}
397 andreas 721
 
722
JNIEXPORT void JNICALL Java_org_qtproject_theosys_SettingsActivity_setPassword1(JNIEnv *env, jclass clazz, jstring pw)
723
{
724
    DECL_TRACER("JNICALL Java_org_qtproject_theosys_SettingsActivity_setPassword1(JNIEnv *env, jclass clazz, jstring pw)");
725
 
726
    Q_UNUSED(clazz);
727
 
728
    string password = javaJStringToString(env, pw);
729
    TConfig::savePassword1(password);
730
}
731
 
732
JNIEXPORT void JNICALL Java_org_qtproject_theosys_SettingsActivity_setPassword2(JNIEnv *env, jclass clazz, jstring pw)
733
{
734
    DECL_TRACER("JNICALL Java_org_qtproject_theosys_SettingsActivity_setPassword2(JNIEnv *env, jclass clazz, jstring pw)");
735
 
736
    Q_UNUSED(clazz);
737
 
738
    string password = javaJStringToString(env, pw);
739
    TConfig::savePassword2(password);
740
}
741
 
742
JNIEXPORT void JNICALL Java_org_qtproject_theosys_SettingsActivity_setPassword3(JNIEnv *env, jclass clazz, jstring pw)
743
{
744
    DECL_TRACER("JNICALL Java_org_qtproject_theosys_SettingsActivity_setPassword3(JNIEnv *env, jclass clazz, jstring pw)");
745
 
746
    Q_UNUSED(clazz);
747
 
748
    string password = javaJStringToString(env, pw);
749
    TConfig::savePassword3(password);
750
}
751
 
752
JNIEXPORT void JNICALL Java_org_qtproject_theosys_SettingsActivity_setPassword4(JNIEnv *env, jclass clazz, jstring pw)
753
{
754
    DECL_TRACER("JNICALL Java_org_qtproject_theosys_SettingsActivity_setPassword4(JNIEnv *env, jclass clazz, jstring pw)");
755
 
756
    Q_UNUSED(clazz);
757
 
758
    string password = javaJStringToString(env, pw);
759
    TConfig::savePassword4(password);
760
}
37 andreas 761
#endif
36 andreas 762
 
3 andreas 763
TPageManager::TPageManager()
764
{
299 andreas 765
    TLOCKER(surface_mutex);
3 andreas 766
    DECL_TRACER("TPageManager::TPageManager()");
767
 
14 andreas 768
    gPageManager = this;
122 andreas 769
    TTPInit *tinit = new TTPInit;
186 andreas 770
    string projectPath = TConfig::getProjectPath();
197 andreas 771
    string pp = projectPath + "/prj.xma";
186 andreas 772
 
773
    tinit->setPath(projectPath);
156 andreas 774
    bool haveSurface = false;
122 andreas 775
 
776
    if (tinit->isVirgin())
156 andreas 777
        haveSurface = tinit->loadSurfaceFromController();
778
    else
779
        haveSurface = true;
122 andreas 780
 
197 andreas 781
    if (!fs::exists(pp))
193 andreas 782
    {
197 andreas 783
        projectPath = TConfig::getSystemProjectPath();
784
        pp = projectPath + "/prj.xma";
193 andreas 785
        mSetupActive = true;
786
    }
186 andreas 787
 
156 andreas 788
    if (!haveSurface)
789
    {
271 andreas 790
        if (!isValidFile(pp))
791
            tinit->reinitialize();
156 andreas 792
    }
159 andreas 793
    else
794
        tinit->makeSystemFiles();
156 andreas 795
 
122 andreas 796
    delete tinit;
156 andreas 797
 
43 andreas 798
    // Read the AMX panel settings.
186 andreas 799
    mTSettings = new TSettings(projectPath);
3 andreas 800
 
801
    if (TError::isError())
14 andreas 802
    {
23 andreas 803
        MSG_ERROR("Settings were not read successfull!");
3 andreas 804
        return;
14 andreas 805
    }
3 andreas 806
 
193 andreas 807
    if (!mSetupActive)
808
    {
197 andreas 809
        mSystemSettings = new TSettings(TConfig::getSystemProjectPath());
193 andreas 810
 
811
        if (TError::isError())
812
        {
813
            MSG_ERROR("System settings were not read successfull!");
814
            delete mTSettings;
815
            mTSettings = nullptr;
816
            return;
817
        }
818
    }
819
    else
820
        mSystemSettings = mTSettings;
821
 
178 andreas 822
    // Set the panel type from the project information
193 andreas 823
    if (!mSetupActive)
824
        TConfig::savePanelType(mTSettings->getPanelType());
178 andreas 825
 
122 andreas 826
    readMap();  // Start the initialisation of the AMX part.
827
 
8 andreas 828
    gPrjResources = new TPrjResources(mTSettings->getResourcesList());
4 andreas 829
    mPalette = new TPalette();
830
    vector<PALETTE_SETUP> pal = mTSettings->getSettings().palettes;
831
 
83 andreas 832
    if (pal.size() > 0)
833
    {
834
        vector<PALETTE_SETUP>::iterator iterPal;
4 andreas 835
 
118 andreas 836
        for (iterPal = pal.begin(); iterPal != pal.end(); ++iterPal)
83 andreas 837
            mPalette->initialize(iterPal->file);
838
    }
839
 
4 andreas 840
    if (!TError::isError())
841
        TColor::setPalette(mPalette);
842
 
7 andreas 843
    mFonts = new TFont();
844
 
845
    if (TError::isError())
846
    {
847
        MSG_ERROR("Initializing fonts was not successfull!");
848
    }
849
 
8 andreas 850
    gIcons = new TIcons();
851
 
852
    if (TError::isError())
853
    {
854
        MSG_ERROR("Initializing icons was not successfull!");
855
    }
856
 
3 andreas 857
    mPageList = new TPageList();
32 andreas 858
    mExternal = new TExternal();
4 andreas 859
    PAGELIST_T page;
860
 
194 andreas 861
    if (!mSetupActive)
3 andreas 862
    {
194 andreas 863
        if (!mTSettings->getSettings().powerUpPage.empty())
14 andreas 864
        {
194 andreas 865
            if (readPage(mTSettings->getSettings().powerUpPage))
866
            {
867
                MSG_TRACE("Found power up page " << mTSettings->getSettings().powerUpPage);
868
                page = findPage(mTSettings->getSettings().powerUpPage);
869
                mActualPage = page.pageID;
870
            }
14 andreas 871
        }
194 andreas 872
        else
873
        {
874
            MSG_WARNING("No power up page defined! Setting default page to 1.");
875
            mActualPage = 1;
876
        }
3 andreas 877
    }
23 andreas 878
    else
879
    {
194 andreas 880
        if (!mSystemSettings->getSettings().powerUpPage.empty())
881
        {
882
            if (readPage(mSystemSettings->getSettings().powerUpPage))
883
            {
884
                MSG_TRACE("Found power up page " << mSystemSettings->getSettings().powerUpPage);
885
                page = findPage(mSystemSettings->getSettings().powerUpPage);
886
                mActualPage = page.pageID;
887
            }
888
        }
889
        else
890
        {
891
            MSG_WARNING("No power up page defined! Setting default page to 5001.");
892
            mActualPage = 5001;
893
        }
23 andreas 894
    }
3 andreas 895
 
4 andreas 896
    TPage *pg = getPage(mActualPage);
897
 
194 andreas 898
    vector<string> popups;
3 andreas 899
 
194 andreas 900
    if (!mSetupActive)
901
        popups = mTSettings->getSettings().powerUpPopup;
902
    else
903
        popups = mSystemSettings->getSettings().powerUpPopup;
904
 
83 andreas 905
    if (popups.size() > 0)
3 andreas 906
    {
83 andreas 907
        vector<string>::iterator iter;
908
 
118 andreas 909
        for (iter = popups.begin(); iter != popups.end(); ++iter)
14 andreas 910
        {
88 andreas 911
            if (readSubPage(*iter))
83 andreas 912
            {
88 andreas 913
                MSG_TRACE("Found power up popup " << *iter);
3 andreas 914
 
88 andreas 915
                if (pg)
916
                {
917
                    TSubPage *spage = getSubPage(*iter);
350 andreas 918
                    spage->setParent(pg->getHandle());
88 andreas 919
                    pg->addSubPage(spage);
920
                }
83 andreas 921
            }
4 andreas 922
        }
3 andreas 923
    }
11 andreas 924
 
73 andreas 925
    // Here we initialize the system resources like borders, cursors, sliders, ...
926
    mSystemDraw = new TSystemDraw(TConfig::getSystemPath(TConfig::BASE));
927
 
928
    // Here are the commands supported by this emulation.
13 andreas 929
    MSG_INFO("Registering commands ...");
318 andreas 930
    REG_CMD(doLEVON, "LEVON");  // Enable device to send level changes to the master.
931
    REG_CMD(doLEVOF, "LEVOF");  // Disable the device from sending level changes to the master.
932
    REG_CMD(doRXON, "RXON");    // Enable device to send STRING changes to the master.
933
    REG_CMD(doRXOF, "RXOF");    // Disable the device from sending STRING changes to the master.
147 andreas 934
    REG_CMD(doAFP, "@AFP");     // Flips to a page with the specified page name using an animated transition.
935
    REG_CMD(doAFP, "^AFP");     // Flips to a page with the specified page name using an animated transition.
38 andreas 936
    REG_CMD(doAPG, "@APG");     // Add a specific popup page to a specified popup group.
937
    REG_CMD(doCPG, "@CPG");     // Clear all popup pages from specified popup group.
938
    REG_CMD(doDPG, "@DPG");     // Delete a specific popup page from specified popup group if it exists
939
//    REG_CMD(doPDR, "@PDR");     // Set the popup location reset flag.
940
    REG_CMD(doPHE, "@PHE");     // Set the hide effect for the specified popup page to the named hide effect.
941
    REG_CMD(doPHP, "@PHP");     // Set the hide effect position.
942
    REG_CMD(doPHT, "@PHT");     // Set the hide effect time for the specified popup page.
943
    REG_CMD(doPPA, "@PPA");     // Close all popups on a specified page.
104 andreas 944
    REG_CMD(doPPA, "^PPA");     // G5: Close all popups on a specified page.
38 andreas 945
    REG_CMD(doPPF, "@PPF");     // Deactivate a specific popup page on either a specified page or the current page.
104 andreas 946
    REG_CMD(doPPF, "^PPF");     // G5: Deactivate a specific popup page on either a specified page or the current page.
38 andreas 947
    REG_CMD(doPPF, "PPOF");     // Deactivate a specific popup page on either a specified page or the current page
948
    REG_CMD(doPPG, "@PPG");     // Toggle a specific popup page on either a specified page or the current page.
104 andreas 949
    REG_CMD(doPPG, "^PPG");     // G5: Toggle a specific popup page on either a specified page or the current page.
38 andreas 950
    REG_CMD(doPPG, "PPOG");     // Toggle a specific popup page on either a specified page or the current page.
951
    REG_CMD(doPPK, "@PPK");     // Kill a specific popup page from all pages.
104 andreas 952
    REG_CMD(doPPK, "^PPK");     // G5: Kill a specific popup page from all pages.
38 andreas 953
    REG_CMD(doPPM, "@PPM");     // Set the modality of a specific popup page to Modal or NonModal.
104 andreas 954
    REG_CMD(doPPM, "^PPM");     // G5: Set the modality of a specific popup page to Modal or NonModal.
38 andreas 955
    REG_CMD(doPPN, "@PPN");     // Activate a specific popup page to launch on either a specified page or the current page.
104 andreas 956
    REG_CMD(doPPN, "^PPN");     // G5: Activate a specific popup page to launch on either a specified page or the current page.
38 andreas 957
    REG_CMD(doPPN, "PPON");     // Activate a specific popup page to launch on either a specified page or the current page.
958
    REG_CMD(doPPT, "@PPT");     // Set a specific popup page to timeout within a specified time.
104 andreas 959
    REG_CMD(doPPT, "^PPT");     // G5: Set a specific popup page to timeout within a specified time.
38 andreas 960
    REG_CMD(doPPX, "@PPX");     // Close all popups on all pages.
104 andreas 961
    REG_CMD(doPPX, "^PPX");     // G5: Close all popups on all pages.
38 andreas 962
    REG_CMD(doPSE, "@PSE");     // Set the show effect for the specified popup page to the named show effect.
963
    REG_CMD(doPSP, "@PSP");     // Set the show effect position.
964
    REG_CMD(doPST, "@PST");     // Set the show effect time for the specified popup page.
965
    REG_CMD(doPAGE, "PAGE");    // Flip to a specified page.
104 andreas 966
    REG_CMD(doPAGE, "^PGE");    // G5: Flip to a specified page.
11 andreas 967
 
38 andreas 968
    REG_CMD(doANI, "^ANI");     // Run a button animation (in 1/10 second).
969
    REG_CMD(doAPF, "^APF");     // Add page flip action to a button if it does not already exist.
43 andreas 970
    REG_CMD(doBAT, "^BAT");     // Append non-unicode text.
60 andreas 971
    REG_CMD(doBAU, "^BAU");     // Append unicode text. Same format as ^UNI.
43 andreas 972
    REG_CMD(doBCB, "^BCB");     // Set the border color.
82 andreas 973
    REG_CMD(getBCB, "?BCB");    // Get the current border color.
60 andreas 974
    REG_CMD(doBCF, "^BCF");     // Set the fill color to the specified color.
82 andreas 975
    REG_CMD(getBCF, "?BCF");    // Get the current fill color.
60 andreas 976
    REG_CMD(doBCT, "^BCT");     // Set the text color to the specified color.
82 andreas 977
    REG_CMD(getBCT, "?BCT");    // Get the current text color.
60 andreas 978
    REG_CMD(doBDO, "^BDO");     // Set the button draw order
979
    REG_CMD(doBFB, "^BFB");     // Set the feedback type of the button.
224 andreas 980
    REG_CMD(doBIM, "^BIM");     // Set the input mask for the specified address
149 andreas 981
    REG_CMD(doBMC, "^BMC");     // Button copy command.
982
    REG_CMD(doBMF, "^BMF");     // Button Modify Command - Set any/all button parameters by sending embedded codes and data.
106 andreas 983
//    REG_CMD(doBMI, "^BMI");    // Set the button mask image.
149 andreas 984
    REG_CMD(doBML, "^BML");     // Set the maximum length of the text area button.
38 andreas 985
    REG_CMD(doBMP, "^BMP");     // Assign a picture to those buttons with a defined addressrange.
82 andreas 986
    REG_CMD(getBMP, "?BMP");    // Get the current bitmap name.
38 andreas 987
    REG_CMD(doBOP, "^BOP");     // Set the button opacity.
106 andreas 988
    REG_CMD(getBOP, "?BOP");    // Get the button opacity.
60 andreas 989
    REG_CMD(doBOR, "^BOR");     // Set a border to a specific border style.
107 andreas 990
    REG_CMD(doBOS, "^BOS");     // Set the button to display either a Video or Non-Video window.
60 andreas 991
    REG_CMD(doBRD, "^BRD");     // Set the border of a button state/states.
107 andreas 992
    REG_CMD(getBRD, "?BRD");    // Get the border of a button state/states.
103 andreas 993
//    REG_CMD(doBSF, "^BSF");     // Set the focus to the text area.
38 andreas 994
    REG_CMD(doBSP, "^BSP");     // Set the button size and position.
107 andreas 995
    REG_CMD(doBSM, "^BSM");     // Submit text for text area buttons.
996
    REG_CMD(doBSO, "^BSO");     // Set the sound played when a button is pressed.
38 andreas 997
    REG_CMD(doBWW, "^BWW");     // Set the button word wrap feature to those buttons with a defined address range.
108 andreas 998
    REG_CMD(getBWW, "?BWW");    // Get the button word wrap feature to those buttons with a defined address range.
38 andreas 999
    REG_CMD(doCPF, "^CPF");     // Clear all page flips from a button.
1000
    REG_CMD(doDPF, "^DPF");     // Delete page flips from button if it already exists.
1001
    REG_CMD(doENA, "^ENA");     // Enable or disable buttons with a set variable text range.
1002
    REG_CMD(doFON, "^FON");     // Set a font to a specific Font ID value for those buttons with a range.
108 andreas 1003
    REG_CMD(getFON, "?FON");    // Get the current font index.
388 andreas 1004
    REG_CMD(doGDI, "^GDI");     // Change the bargraph drag increment.
416 andreas 1005
    REG_CMD(doGIV, "^GIV");     // Invert the joystick axis to move the origin to another corner.
60 andreas 1006
    REG_CMD(doGLH, "^GLH");     // Change the bargraph upper limit.
1007
    REG_CMD(doGLL, "^GLL");     // Change the bargraph lower limit.
388 andreas 1008
    REG_CMD(doGRD, "^GRD");     // Change the bargraph ramp down time.
1009
    REG_CMD(doGRU, "^GRU");     // Change the bargraph ramp up time.
361 andreas 1010
    REG_CMD(doGSN, "^GSN");     // Set slider/cursor name.
108 andreas 1011
    REG_CMD(doGSC, "^GSC");     // Change the bargraph slider color or joystick cursor color.
38 andreas 1012
    REG_CMD(doICO, "^ICO");     // Set the icon to a button.
108 andreas 1013
    REG_CMD(getICO, "?ICO");    // Get the current icon index.
1014
    REG_CMD(doJSB, "^JSB");     // Set bitmap/picture alignment using a numeric keypad layout for those buttons with a defined address range.
1015
    REG_CMD(getJSB, "?JSB");    // Get the current bitmap justification.
1016
    REG_CMD(doJSI, "^JSI");     // Set icon alignment using a numeric keypad layout for those buttons with a defined address range.
1017
    REG_CMD(getJSI, "?JSI");    // Get the current icon justification.
1018
    REG_CMD(doJST, "^JST");     // Set text alignment using a numeric keypad layout for those buttons with a defined address range.
1019
    REG_CMD(getJST, "?JST");    // Get the current text justification.
395 andreas 1020
    REG_CMD(doMSP, "^MSP");     // Set marquee line speed.
38 andreas 1021
    REG_CMD(doSHO, "^SHO");     // Show or hide a button with a set variable text range.
108 andreas 1022
    REG_CMD(doTEC, "^TEC");     // Set the text effect color for the specified addresses/states to the specified color.
1023
    REG_CMD(getTEC, "?TEC");    // Get the current text effect color.
110 andreas 1024
    REG_CMD(doTEF, "^TEF");     // Set the text effect. The Text Effect is specified by name and can be found in TPD4.
1025
    REG_CMD(getTEF, "?TEF");    // Get the current text effect name.
103 andreas 1026
//    REG_CMD(doTOP, "^TOP");     // Send events to the Master as string events.
38 andreas 1027
    REG_CMD(doTXT, "^TXT");     // Assign a text string to those buttons with a defined address range.
110 andreas 1028
    REG_CMD(getTXT, "?TXT");    // Get the current text information.
104 andreas 1029
    REG_CMD(doUNI, "^UNI");     // Set Unicode text.
1030
    REG_CMD(doUTF, "^UTF");     // G5: Set button state text using UTF-8 text command.
148 andreas 1031
    REG_CMD(doVTP, "^VTP");     // Simulates a touch/release/pulse at the given coordinate
14 andreas 1032
 
400 andreas 1033
    REG_CMD(doLPB, "^LPB");     // Assigns a user name to a button.
1034
    REG_CMD(doLPC, "^LPC");     // Clear all users from the User Access Passwords list on the Password Setup page.
1035
    REG_CMD(doLPR, "^LPR");     // Remove a given user from the User Access Passwords list on the Password Setup page.
1036
    REG_CMD(doLPS, "^LPS");     // Set the user name and password.
103 andreas 1037
 
111 andreas 1038
    REG_CMD(doKPS, "^KPS");     // Set the keyboard passthru.
1039
    REG_CMD(doVKS, "^VKS");     // Send one or more virtual key strokes to the G4 application.
103 andreas 1040
 
400 andreas 1041
    REG_CMD(doAPWD, "@PWD");    // Set the page flip password.
1042
    REG_CMD(doPWD, "^PWD");     // Set the page flip password. Password level is required and must be 1 - 4.
103 andreas 1043
 
38 andreas 1044
    REG_CMD(doBBR, "^BBR");     // Set the bitmap of a button to use a particular resource.
97 andreas 1045
    REG_CMD(doRAF, "^RAF");     // Add new resources
1046
    REG_CMD(doRFR, "^RFR");     // Force a refresh for a given resource.
38 andreas 1047
    REG_CMD(doRMF, "^RMF");     // Modify an existing resource.
111 andreas 1048
    REG_CMD(doRSR, "^RSR");     // Change the refresh rate for a given resource.
21 andreas 1049
 
108 andreas 1050
    REG_CMD(doABEEP, "ABEEP");  // Output a single beep even if beep is Off.
1051
    REG_CMD(doADBEEP, "ADBEEP");// Output a double beep even if beep is Off.
62 andreas 1052
    REG_CMD(doAKB, "@AKB");     // Pop up the keyboard icon and initialize the text string to that specified.
1053
    REG_CMD(doAKEYB, "AKEYB");  // Pop up the keyboard icon and initialize the text string to that specified.
1054
    REG_CMD(doAKP, "@AKP");     // Pop up the keypad icon and initialize the text string to that specified.
1055
    REG_CMD(doAKEYP, "AKEYP");  // Pop up the keypad icon and initialize the text string to that specified.
63 andreas 1056
    REG_CMD(doAKEYR, "AKEYR");  // Remove the Keyboard/Keypad.
1057
    REG_CMD(doAKR, "@AKR");     // Remove the Keyboard/Keypad.
71 andreas 1058
    REG_CMD(doBEEP, "BEEP");    // Play a single beep.
104 andreas 1059
    REG_CMD(doBEEP, "^ABP");    // G5: Play a single beep.
71 andreas 1060
    REG_CMD(doDBEEP, "DBEEP");  // Play a double beep.
104 andreas 1061
    REG_CMD(doDBEEP, "^ADB");   // G5: Play a double beep.
62 andreas 1062
    REG_CMD(doEKP, "@EKP");     // Pop up the keypad icon and initialize the text string to that specified.
63 andreas 1063
    REG_CMD(doPKP, "@PKB");     // Present a private keyboard.
1064
    REG_CMD(doPKP, "PKEYP");    // Present a private keypad.
1065
    REG_CMD(doPKP, "@PKP");     // Present a private keypad.
408 andreas 1066
    REG_CMD(doRPP, "^RPP");     // Reset protected password command
64 andreas 1067
    REG_CMD(doSetup, "SETUP");  // Send panel to SETUP page.
104 andreas 1068
    REG_CMD(doSetup, "^STP");   // G5: Open setup page.
64 andreas 1069
    REG_CMD(doShutdown, "SHUTDOWN");// Shut down the App
82 andreas 1070
    REG_CMD(doSOU, "@SOU");     // Play a sound file.
104 andreas 1071
    REG_CMD(doSOU, "^SOU");     // G5: Play a sound file.
326 andreas 1072
    REG_CMD(doMUT, "^MUT");     // G5: Panel Volume Mute
63 andreas 1073
    REG_CMD(doTKP, "@TKP");     // Present a telephone keypad.
104 andreas 1074
    REG_CMD(doTKP, "^TKP");     // G5: Bring up a telephone keypad.
63 andreas 1075
    REG_CMD(doTKP, "@VKB");     // Present a virtual keyboard
104 andreas 1076
    REG_CMD(doTKP, "^VKB");     // G5: Bring up a virtual keyboard.
129 andreas 1077
#ifndef _NOSIP_
103 andreas 1078
    // Here the SIP commands will take place
123 andreas 1079
    REG_CMD(doPHN, "^PHN");     // SIP commands
127 andreas 1080
    REG_CMD(getPHN, "?PHN");    // SIP state commands
129 andreas 1081
#endif
300 andreas 1082
    // SubView commands
1083
//    REG_CMD(doEPR, "^EPR");     // Execute Push on Release.
1084
//    REG_CMD(doSCE, "^SCE");     // Configures subpage custom events.
1085
//    REG_CMD(doSDR, "^SDR");     // Enabling subpage dynamic reordering.
318 andreas 1086
    REG_CMD(doSHA, "^SHA");     // Subpage Hide All Command
1087
    REG_CMD(doSHD, "^SHD");     // Hides subpage
1088
    REG_CMD(doSPD, "^SPD");     //  Set the padding between subpages on a subpage viewer button
300 andreas 1089
    REG_CMD(doSSH, "^SSH");     // Subpage show command.
318 andreas 1090
    REG_CMD(doSTG, "^STG");     // Subpage toggle command
300 andreas 1091
 
225 andreas 1092
    // ListView commands (G5)
1093
    REG_CMD(doLVD, "^LVD");     // G5: Set Listview Data Source
230 andreas 1094
    REG_CMD(doLVE, "^LVE");     // G5: Set ListView custom event number
227 andreas 1095
    REG_CMD(doLVF, "^LVF");     // G5: Listview Filter
230 andreas 1096
    REG_CMD(doLVL, "^LVL");     // G5: ListView layout
233 andreas 1097
    REG_CMD(doLVM, "^LVM");     // G5: ListView map fields
1098
    REG_CMD(doLVN, "^LVN");     // G5: ListView navigate
1099
    REG_CMD(doLVR, "^LVR");     // G5: ListView refresh data
1100
    REG_CMD(doLVS, "^LVS");     // G5: ListView sort data
225 andreas 1101
 
103 andreas 1102
    // State commands
14 andreas 1103
    REG_CMD(doON, "ON");
1104
    REG_CMD(doOFF, "OFF");
15 andreas 1105
    REG_CMD(doLEVEL, "LEVEL");
1106
    REG_CMD(doBLINK, "BLINK");
127 andreas 1107
    REG_CMD(doVER, "^VER?");    // Return version string to master
279 andreas 1108
#ifndef _NOSIP_
127 andreas 1109
    REG_CMD(doWCN, "^WCN?");    // Return SIP phone number
279 andreas 1110
#endif
134 andreas 1111
    // TPControl commands
1112
    REG_CMD(doTPCCMD, "TPCCMD");    // Profile related options
1113
    REG_CMD(doTPCACC, "TPCACC");    // Device orientation
279 andreas 1114
#ifndef _NOSIP_
153 andreas 1115
    REG_CMD(doTPCSIP, "TPCSIP");    // Show the built in SIP phone
279 andreas 1116
#endif
134 andreas 1117
    // Virtual internal commands
26 andreas 1118
    REG_CMD(doFTR, "#FTR");     // File transfer (virtual internal command)
23 andreas 1119
 
123 andreas 1120
    // At least we must add the SIP client
129 andreas 1121
#ifndef _NOSIP_
127 andreas 1122
    mSIPClient = new TSIPClient;
123 andreas 1123
 
1124
    if (TError::isError())
1125
    {
1126
        MSG_ERROR("Error initializing the SIP client!");
1127
        TConfig::setSIPstatus(false);
1128
    }
129 andreas 1129
#endif
88 andreas 1130
    TError::clear();
299 andreas 1131
    runClickQueue();
303 andreas 1132
    runUpdateSubViewItem();
3 andreas 1133
}
1134
 
1135
TPageManager::~TPageManager()
1136
{
1137
    DECL_TRACER("TPageManager::~TPageManager()");
129 andreas 1138
#ifndef _NOSIP_
127 andreas 1139
    if (mSIPClient)
1140
    {
1141
        delete mSIPClient;
1142
        mSIPClient = nullptr;
1143
    }
129 andreas 1144
#endif
3 andreas 1145
    PCHAIN_T *p = mPchain;
1146
    PCHAIN_T *next = nullptr;
37 andreas 1147
#ifdef __ANDROID__
36 andreas 1148
    stopNetworkState();
37 andreas 1149
#endif
3 andreas 1150
    try
1151
    {
1152
        while (p)
1153
        {
1154
            next = p->next;
1155
 
1156
            if (p->page)
1157
                delete p->page;
1158
 
1159
            delete p;
1160
            p = next;
1161
        }
1162
 
1163
        SPCHAIN_T *sp = mSPchain;
1164
        SPCHAIN_T *snext = nullptr;
1165
 
1166
        while (sp)
1167
        {
1168
            snext = sp->next;
1169
 
1170
            if (sp->page)
1171
                delete sp->page;
1172
 
1173
            delete sp;
5 andreas 1174
            sp = snext;
3 andreas 1175
        }
1176
 
1177
        mPchain = nullptr;
1178
        mSPchain = nullptr;
14 andreas 1179
        setPChain(mPchain);
1180
        setSPChain(mSPchain);
3 andreas 1181
 
13 andreas 1182
        if (mAmxNet)
1183
        {
1184
            delete mAmxNet;
1185
            mAmxNet = nullptr;
1186
        }
1187
 
3 andreas 1188
        if (mTSettings)
1189
        {
1190
            delete mTSettings;
1191
            mTSettings = nullptr;
1192
        }
1193
 
1194
        if (mPageList)
1195
        {
1196
            delete mPageList;
1197
            mPageList = nullptr;
1198
        }
5 andreas 1199
 
1200
        if (mPalette)
1201
        {
1202
            delete mPalette;
1203
            mPalette = nullptr;
1204
        }
7 andreas 1205
 
1206
        if (mFonts)
1207
        {
1208
            delete mFonts;
1209
            mFonts = nullptr;
1210
        }
8 andreas 1211
 
1212
        if (gIcons)
1213
        {
1214
            delete gIcons;
1215
            gIcons = nullptr;
1216
        }
1217
 
1218
        if (gPrjResources)
1219
        {
1220
            delete gPrjResources;
1221
            gPrjResources = nullptr;
1222
        }
40 andreas 1223
 
33 andreas 1224
        if (mExternal)
1225
        {
1226
            delete mExternal;
1227
            mExternal = nullptr;
1228
        }
433 andreas 1229
 
1230
        if (!mButtonStates.empty())
1231
        {
1232
            vector<TButtonStates *>::iterator iter;
1233
 
1234
            for (iter = mButtonStates.begin(); iter != mButtonStates.end(); ++iter)
1235
                delete *iter;
1236
 
1237
            mButtonStates.clear();
1238
        }
3 andreas 1239
    }
1240
    catch (std::exception& e)
1241
    {
1242
        MSG_ERROR("Memory error: " << e.what());
1243
    }
90 andreas 1244
 
1245
    gPageManager = nullptr;
3 andreas 1246
}
1247
 
11 andreas 1248
void TPageManager::initialize()
1249
{
1250
    DECL_TRACER("TPageManager::initialize()");
1251
 
14 andreas 1252
    surface_mutex.lock();
11 andreas 1253
    dropAllSubPages();
1254
    dropAllPages();
1255
 
186 andreas 1256
    string projectPath = TConfig::getProjectPath();
1257
 
1258
    if (!fs::exists(projectPath + "/prj.xma"))
1259
        projectPath += "/__system";
1260
 
90 andreas 1261
    if (mAmxNet && mAmxNet->isConnected())
1262
        mAmxNet->close();
88 andreas 1263
 
11 andreas 1264
    if (mTSettings)
1265
        mTSettings->loadSettings();
1266
    else
186 andreas 1267
        mTSettings = new TSettings(projectPath);
11 andreas 1268
 
1269
    if (TError::isError())
14 andreas 1270
    {
1271
        surface_mutex.unlock();
11 andreas 1272
        return;
14 andreas 1273
    }
11 andreas 1274
 
178 andreas 1275
    // Set the panel type from the project information
1276
    TConfig::savePanelType(mTSettings->getPanelType());
1277
 
88 andreas 1278
    if (gPrjResources)
1279
        delete gPrjResources;
11 andreas 1280
 
88 andreas 1281
    gPrjResources = new TPrjResources(mTSettings->getResourcesList());
11 andreas 1282
 
88 andreas 1283
    if (mPalette)
1284
        delete mPalette;
1285
 
1286
    mPalette = new TPalette();
1287
 
11 andreas 1288
    vector<PALETTE_SETUP> pal = mTSettings->getSettings().palettes;
1289
 
83 andreas 1290
    if (pal.size() > 0)
1291
    {
1292
        vector<PALETTE_SETUP>::iterator iterPal;
11 andreas 1293
 
118 andreas 1294
        for (iterPal = pal.begin(); iterPal != pal.end(); ++iterPal)
83 andreas 1295
            mPalette->initialize(iterPal->file);
1296
    }
1297
 
11 andreas 1298
    if (!TError::isError())
1299
        TColor::setPalette(mPalette);
1300
 
88 andreas 1301
    if (mFonts)
1302
        delete mFonts;
11 andreas 1303
 
88 andreas 1304
    mFonts = new TFont();
1305
 
11 andreas 1306
    if (TError::isError())
1307
    {
1308
        MSG_ERROR("Initializing fonts was not successfull!");
14 andreas 1309
        surface_mutex.unlock();
11 andreas 1310
        return;
1311
    }
1312
 
88 andreas 1313
    if (gIcons)
1314
        delete gIcons;
11 andreas 1315
 
88 andreas 1316
    gIcons = new TIcons();
1317
 
11 andreas 1318
    if (TError::isError())
1319
    {
1320
        MSG_ERROR("Initializing icons was not successfull!");
14 andreas 1321
        surface_mutex.unlock();
11 andreas 1322
        return;
1323
    }
1324
 
88 andreas 1325
    if (mPageList)
1326
        delete mPageList;
11 andreas 1327
 
88 andreas 1328
    mPageList = new TPageList();
11 andreas 1329
 
88 andreas 1330
    if (mExternal)
1331
        delete mExternal;
1332
 
1333
    mExternal = new TExternal();
1334
 
11 andreas 1335
    PAGELIST_T page;
1336
 
1337
    if (!mTSettings->getSettings().powerUpPage.empty())
1338
    {
88 andreas 1339
        if (readPage(mTSettings->getSettings().powerUpPage))
14 andreas 1340
        {
88 andreas 1341
            MSG_TRACE("Found power up page " << mTSettings->getSettings().powerUpPage);
1342
            page = findPage(mTSettings->getSettings().powerUpPage);
1343
            mActualPage = page.pageID;
14 andreas 1344
        }
11 andreas 1345
    }
1346
 
1347
    TPage *pg = getPage(mActualPage);
1348
 
1349
    vector<string> popups = mTSettings->getSettings().powerUpPopup;
1350
 
83 andreas 1351
    if (popups.size() > 0)
11 andreas 1352
    {
83 andreas 1353
        vector<string>::iterator iter;
1354
 
118 andreas 1355
        for (iter = popups.begin(); iter != popups.end(); ++iter)
14 andreas 1356
        {
88 andreas 1357
            if (readSubPage(*iter))
83 andreas 1358
            {
88 andreas 1359
                MSG_TRACE("Found power up popup " << *iter);
11 andreas 1360
 
88 andreas 1361
                if (pg)
1362
                {
1363
                    TSubPage *spage = getSubPage(*iter);
350 andreas 1364
                    spage->setParent(pg->getHandle());
88 andreas 1365
                    pg->addSubPage(spage);
1366
                }
83 andreas 1367
            }
11 andreas 1368
        }
1369
    }
1370
 
88 andreas 1371
    // Here we initialize the system resources like borders, cursors, sliders, ...
1372
    if (mSystemDraw)
1373
        delete mSystemDraw;
1374
 
1375
    mSystemDraw = new TSystemDraw(TConfig::getSystemPath(TConfig::BASE));
1376
 
1377
    TError::clear();        // Clear all errors who may be occured until here
1378
 
11 andreas 1379
    // Start the thread
92 andreas 1380
    startComm();
1381
 
1382
    surface_mutex.unlock();
1383
}
1384
 
1385
bool TPageManager::startComm()
1386
{
1387
    DECL_TRACER("TPageManager::startComm()");
1388
 
1389
    if (mAmxNet && mAmxNet->isNetRun())
1390
        return true;
1391
 
1392
    try
11 andreas 1393
    {
92 andreas 1394
        if (!mAmxNet)
13 andreas 1395
        {
92 andreas 1396
            if (_netRunning)
13 andreas 1397
            {
92 andreas 1398
                // Wait until previous connection thread ended
1399
                while (_netRunning)
1400
                    std::this_thread::sleep_for(std::chrono::milliseconds(100));
13 andreas 1401
            }
14 andreas 1402
 
92 andreas 1403
            mAmxNet = new amx::TAmxNet();
1404
            mAmxNet->setCallback(bind(&TPageManager::doCommand, this, std::placeholders::_1));
1405
            mAmxNet->setPanelID(TConfig::getChannel());
134 andreas 1406
            mAmxNet->setSerialNum(V_SERIAL);
13 andreas 1407
        }
90 andreas 1408
 
1409
        if (!mAmxNet->isNetRun())
1410
            mAmxNet->Run();
85 andreas 1411
    }
92 andreas 1412
    catch (std::exception& e)
1413
    {
1414
        MSG_ERROR("Error starting the AmxNet thread: " << e.what());
1415
        return false;
1416
    }
14 andreas 1417
 
92 andreas 1418
    return true;
11 andreas 1419
}
1420
 
38 andreas 1421
void TPageManager::startUp()
1422
{
1423
    DECL_TRACER("TPageManager::startUp()");
1424
 
44 andreas 1425
    if (mAmxNet)
90 andreas 1426
    {
1427
        MSG_WARNING("Communication with controller already initialized!");
44 andreas 1428
        return;
90 andreas 1429
    }
44 andreas 1430
 
92 andreas 1431
    if (!startComm())
1432
        return;
90 andreas 1433
 
38 andreas 1434
#ifdef __ANDROID__
130 andreas 1435
    initOrientation();
38 andreas 1436
    initNetworkState();
1437
#endif
1438
}
89 andreas 1439
 
1440
void TPageManager::reset()
1441
{
1442
    DECL_TRACER("TPageManager::reset()");
1443
 
100 andreas 1444
    // Freshly initialize everything.
89 andreas 1445
    initialize();
1446
}
1447
 
169 andreas 1448
void TPageManager::runCommands()
1449
{
1450
    DECL_TRACER("TPageManager::runCommands()");
1451
 
418 andreas 1452
    if (cmdLoop_busy)
169 andreas 1453
        return;
1454
 
1455
    try
1456
    {
1457
        mThreadCommand = std::thread([=] { this->commandLoop(); });
1458
        mThreadCommand.detach();
1459
    }
1460
    catch (std::exception& e)
1461
    {
1462
        MSG_ERROR("Error starting thread for command loop: " << e.what());
1463
        _netRunning = false;
1464
    }
1465
}
1466
 
197 andreas 1467
void TPageManager::showSetup()
1468
{
1469
    DECL_TRACER("TPageManager::showSetup()");
251 andreas 1470
#ifdef Q_OS_ANDROID
260 andreas 1471
    // Scan Netlinx for TP4 files and update the list of setup.
1472
    if (TConfig::getController().compare("0.0.0.0") != 0)
1473
    {
1474
        if (_startWait)
1475
            _startWait(string("Please wait while I try to load the list of surface files from Netlinx (") + TConfig::getController() + ")");
1476
 
1477
        TTPInit tpinit;
1478
        std::vector<TTPInit::FILELIST_t> fileList;
1479
        tpinit.setPath(TConfig::getProjectPath());
1480
        fileList = tpinit.getFileList(".tp4");
1481
 
1482
        if (fileList.size() > 0)
1483
        {
1484
            vector<TTPInit::FILELIST_t>::iterator iter;
264 andreas 1485
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
260 andreas 1486
            QAndroidJniObject::callStaticMethod<void>("org/qtproject/theosys/Settings", "clearSurfaces");
1487
#else
1488
            QJniObject::callStaticMethod<void>("org/qtproject/theosys/Settings", "clearSurfaces");
1489
#endif
1490
            for (iter = fileList.begin(); iter != fileList.end(); ++iter)
1491
            {
264 andreas 1492
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
260 andreas 1493
                QAndroidJniObject str = QAndroidJniObject::fromString(iter->fname.c_str());
1494
                QAndroidJniObject::callStaticMethod<void>("org/qtproject/theosys/Settings", "addSurface", "(Ljava/lang/String;)V", str.object<jstring>());
1495
#else
1496
                QJniObject str = QJniObject::fromString(iter->fname.c_str());
1497
                QJniObject::callStaticMethod<void>("org/qtproject/theosys/Settings", "addSurface", "(Ljava/lang/String;)V", str.object<jstring>());
1498
#endif
1499
            }
1500
        }
1501
 
1502
        if (_stopWait)
1503
            _stopWait();
1504
    }
1505
 
367 andreas 1506
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
1507
    QAndroidJniObject::callStaticMethod<void>("org/qtproject/theosys/Settings", "setLogLevel", "(Ljava/lang/Integer;)V", TConfig::getLogLevelBits());
383 andreas 1508
    QAndroidJniObject strPath = QAndroidJniObject::fromString(TConfig::getLogFile().c_str());
385 andreas 1509
    QAndroidJniObject::callStaticMethod<void>("org/qtproject/theosys/Settings", "setLogEnableFile", "(Z)V", TConfig::getLogFileEnabled());
383 andreas 1510
    QAndroidJniObject::callStaticMethod<void>("org/qtproject/theosys/Settings", "setLogPath", "(Ljava/lang/String;)V", strPath.object<jstring>());
406 andreas 1511
 
1512
    QAndroidJniObject pw1 = QAndroidJniObject::fromString(TConfig::getPassword1().c_str());
1513
    QAndroidJniObject pw2 = QAndroidJniObject::fromString(TConfig::getPassword2().c_str());
1514
    QAndroidJniObject pw3 = QAndroidJniObject::fromString(TConfig::getPassword3().c_str());
1515
    QAndroidJniObject pw4 = QAndroidJniObject::fromString(TConfig::getPassword4().c_str());
1516
    QAndroidJniObject::callStaticMethod<void>("org/qtproject/theosys/Settings", "setPassword", "(ILjava/lang/String;)V", 1, pw1.object<jstring>());
1517
    QAndroidJniObject::callStaticMethod<void>("org/qtproject/theosys/Settings", "setPassword", "(ILjava/lang/String;)V", 2, pw2.object<jstring>());
1518
    QAndroidJniObject::callStaticMethod<void>("org/qtproject/theosys/Settings", "setPassword", "(ILjava/lang/String;)V", 3, pw3.object<jstring>());
1519
    QAndroidJniObject::callStaticMethod<void>("org/qtproject/theosys/Settings", "setPassword", "(ILjava/lang/String;)V", 4, pw4.object<jstring>());
367 andreas 1520
#else
1521
    QJniObject::callStaticMethod<void>("org/qtproject/theosys/Settings", "setLogLevel", "(I)V", TConfig::getLogLevelBits());
385 andreas 1522
    QJniObject::callStaticMethod<void>("org/qtproject/theosys/Settings", "setLogEnableFile", "(I)V", (TConfig::getLogFileEnabled() ? 1 : 0));
383 andreas 1523
    QJniObject strPath = QJniObject::fromString(TConfig::getLogFile().c_str());
1524
    QJniObject::callStaticMethod<void>("org/qtproject/theosys/Settings", "setLogPath", "(Ljava/lang/String;)V", strPath.object<jstring>());
397 andreas 1525
 
1526
    QJniObject pw1 = QJniObject::fromString(TConfig::getPassword1().c_str());
1527
    QJniObject pw2 = QJniObject::fromString(TConfig::getPassword2().c_str());
1528
    QJniObject pw3 = QJniObject::fromString(TConfig::getPassword3().c_str());
1529
    QJniObject pw4 = QJniObject::fromString(TConfig::getPassword4().c_str());
1530
    QJniObject::callStaticMethod<void>("org/qtproject/theosys/Settings", "setPassword", "(ILjava/lang/String;)V", 1, pw1.object<jstring>());
1531
    QJniObject::callStaticMethod<void>("org/qtproject/theosys/Settings", "setPassword", "(ILjava/lang/String;)V", 2, pw2.object<jstring>());
1532
    QJniObject::callStaticMethod<void>("org/qtproject/theosys/Settings", "setPassword", "(ILjava/lang/String;)V", 3, pw3.object<jstring>());
1533
    QJniObject::callStaticMethod<void>("org/qtproject/theosys/Settings", "setPassword", "(ILjava/lang/String;)V", 4, pw4.object<jstring>());
367 andreas 1534
#endif
1535
 
255 andreas 1536
    enterSetup();
250 andreas 1537
#else
1538
        if (_callShowSetup)
1539
            _callShowSetup();
1540
#endif
197 andreas 1541
}
1542
 
1543
void TPageManager::hideSetup()
1544
{
1545
    DECL_TRACER("TPageManager::hideSetup()");
1546
 
206 andreas 1547
    if (!mSetupActive || mSavedPage >= SYSTEM_PAGE_START)
197 andreas 1548
        return;
1549
 
198 andreas 1550
    mSetupActive = false;
197 andreas 1551
 
198 andreas 1552
    if (!mSavedPage)
1553
    {
1554
        string sPage = mTSettings->getPowerUpPage();
197 andreas 1555
 
198 andreas 1556
        if (!setPage(sPage, true))
1557
            setPage(1, true);
197 andreas 1558
 
1559
        return;
1560
    }
1561
 
198 andreas 1562
    setPage(mSavedPage, true);
213 andreas 1563
    MSG_PROTOCOL("Activated page: " << mSavedPage);
197 andreas 1564
 
198 andreas 1565
    if (mSavedSubpages.size() > 0)
197 andreas 1566
    {
198 andreas 1567
        vector<int>::iterator iter;
197 andreas 1568
 
198 andreas 1569
        for (iter = mSavedSubpages.begin(); iter != mSavedSubpages.end(); ++iter)
1570
        {
1571
            showSubPage(*iter);
213 andreas 1572
            MSG_PROTOCOL("Activated subpage: " << *iter);
198 andreas 1573
        }
217 andreas 1574
 
1575
        mSavedSubpages.clear();
197 andreas 1576
    }
1577
}
1578
 
205 andreas 1579
int TPageManager::getSelectedRow(ulong handle)
1580
{
1581
    DECL_TRACER("TPageManager::getSelectedRow(ulong handle)");
1582
 
300 andreas 1583
    int nPage = (handle >> 16) & 0x0000ffff;
205 andreas 1584
 
206 andreas 1585
    if ((nPage && TPage::isRegularPage(nPage)) || TPage::isSystemPage(nPage)) // Do we have a page?
205 andreas 1586
    {                                                   // Yes, then look on page
1587
        TPage *pg = getPage(nPage);
1588
 
1589
        if (!pg)
1590
            return -1;
1591
 
1592
        return pg->getSelectedRow(handle);
1593
    }
206 andreas 1594
    else if (TPage::isRegularSubPage(nPage) || TPage::isSystemSubPage(nPage))
205 andreas 1595
    {
1596
        TSubPage *subPg = getSubPage(nPage);
1597
 
1598
        if (!subPg)
1599
            return -1;
1600
 
1601
        return subPg->getSelectedRow(handle);
1602
    }
1603
 
271 andreas 1604
    MSG_WARNING("Invalid handle " << handleToString(handle) << " detected!");
205 andreas 1605
    return -1;
1606
}
1607
 
1608
string TPageManager::getSelectedItem(ulong handle)
1609
{
1610
    DECL_TRACER("TPageManager::getSelectedItem(ulong handle)");
1611
 
300 andreas 1612
    int nPage = (handle >> 16) & 0x0000ffff;
205 andreas 1613
 
206 andreas 1614
    if ((nPage && TPage::isRegularPage(nPage)) || TPage::isSystemPage(nPage)) // Do we have a page?
205 andreas 1615
    {                                                   // Yes, then look on page
1616
        TPage *pg = getPage(nPage);
1617
 
1618
        if (!pg)
1619
            return string();
1620
 
1621
        return pg->getSelectedItem(handle);
1622
    }
206 andreas 1623
    else if (TPage::isRegularSubPage(nPage) || TPage::isSystemSubPage(nPage))
205 andreas 1624
    {
1625
        TSubPage *subPg = getSubPage(nPage);
1626
 
1627
        if (!subPg)
1628
            return string();
1629
 
1630
        return subPg->getSelectedItem(handle);
1631
    }
1632
 
271 andreas 1633
    MSG_WARNING("Invalid handle " << handleToString(handle) << " detected!");
205 andreas 1634
    return string();
1635
}
1636
 
206 andreas 1637
void TPageManager::setSelectedRow(ulong handle, int row, const std::string& text)
205 andreas 1638
{
1639
    DECL_TRACER("TPageManager::setSelectedRow(ulong handle, int row)");
1640
 
300 andreas 1641
    int nPage = (handle >> 16) & 0x0000ffff;
205 andreas 1642
 
206 andreas 1643
    if (TPage::isRegularPage(nPage) || TPage::isSystemPage(nPage)) // Do we have a page?
205 andreas 1644
    {                                                   // Yes, then look on page
1645
        TPage *pg = getPage(nPage);
1646
 
1647
        if (!pg)
1648
            return;
1649
 
1650
        pg->setSelectedRow(handle, row);
1651
    }
206 andreas 1652
    else if (TPage::isRegularSubPage(nPage) || TPage::isSystemSubPage(nPage))   // Do we have a subpage?
1653
    {                                                   // Yes, then look on subpage
205 andreas 1654
        TSubPage *subPg = getSubPage(nPage);
1655
 
1656
        if (!subPg)
1657
            return;
1658
 
1659
        subPg->setSelectedRow(handle, row);
206 andreas 1660
        // Check if this is a system list. If so we must set the selected
1661
        // text to the input line or "label".
1662
        TPage *mainPage = nullptr;
1663
 
1664
        if (nPage >= SYSTEM_SUBPAGE_START)  // System subpage?
1665
        {
1666
            switch(nPage)
1667
            {
1668
                case SYSTEM_SUBPAGE_SYSTEMSOUND:
1669
                case SYSTEM_SUBPAGE_SINGLEBEEP:
1670
                case SYSTEM_SUBPAGE_DOUBLEBEEP:
1671
                    mainPage = getPage(SYSTEM_PAGE_SOUND);
1672
                break;
1673
 
1674
                case SYSTEM_SUBPAGE_SURFACE:
1675
                    mainPage = getPage(SYSTEM_PAGE_CONTROLLER);
1676
                break;
1677
            }
1678
        }
1679
 
1680
        if (mainPage)
1681
        {
1682
            if (nPage == SYSTEM_SUBPAGE_SYSTEMSOUND)  // System sound beep
1683
            {
1684
                Button::TButton *bt = mainPage->getButton(SYSTEM_PAGE_SOUND_TXSYSSOUND);
1685
 
1686
                if (bt)
1687
                {
1688
                    bt->setText(text, -1);
1689
                    TConfig::setTemporary(true);
1690
                    TConfig::saveSystemSoundFile(text);
1691
                }
1692
            }
1693
            else if (nPage == SYSTEM_SUBPAGE_SINGLEBEEP) // System sound single beep
1694
            {
1695
                Button::TButton *bt = mainPage->getButton(SYSTEM_PAGE_SOUND_TXSINGLEBEEP);
1696
 
1697
                if (bt)
1698
                {
1699
                    bt->setText(text, -1);
1700
                    TConfig::setTemporary(true);
1701
                    TConfig::saveSingleBeepFile(text);
1702
                }
1703
            }
1704
            else if (nPage == SYSTEM_SUBPAGE_DOUBLEBEEP) // System sound double beep
1705
            {
1706
                Button::TButton *bt = mainPage->getButton(SYSTEM_PAGE_SOUND_TXDOUBLEBEEP);
1707
 
1708
                if (bt)
1709
                {
1710
                    bt->setText(text, -1);
1711
                    TConfig::setTemporary(true);
1712
                    TConfig::saveDoubleBeepFile(text);
1713
                }
1714
            }
1715
            else if (nPage == SYSTEM_SUBPAGE_SURFACE)   // System TP4 files (surface files)
1716
            {
1717
                Button::TButton *bt = mainPage->getButton(SYSTEM_PAGE_CTRL_SURFACE);
1718
 
1719
                if (bt)
1720
                {
1721
                    MSG_DEBUG("Setting text: " << text);
1722
                    bt->setText(text, -1);
1723
                    TConfig::setTemporary(true);
1724
                    TConfig::saveFtpSurface(text);
1725
                }
1726
            }
1727
 
1728
            // Close the list subpage
1729
            subPg->drop();
1730
        }
205 andreas 1731
    }
1732
}
1733
 
383 andreas 1734
void TPageManager::redrawObject(ulong handle)
1735
{
1736
    DECL_TRACER("TPageManager::redrawObject(ulong handle)");
1737
 
1738
    int pnumber = (int)((handle >> 16) & 0x0000ffff);
1739
    int btnumber = (int)(handle & 0x0000ffff);
1740
 
1741
    if (pnumber < REGULAR_SUBPAGE_START)    // Is it a page?
1742
    {
1743
        TPage *page = getPage(pnumber);
1744
 
1745
        if (!page)
1746
        {
1747
            MSG_WARNING("Page " << pnumber << " not found!");
1748
            return;
1749
        }
1750
 
1751
        if (!page->isVisilble())
1752
            return;
1753
 
1754
        if (btnumber == 0)
1755
        {
1756
            page->show();
1757
            return;
1758
        }
1759
 
1760
        Button::TButton *button = page->getButton(btnumber);
1761
 
1762
        if (!button)
1763
        {
1764
            MSG_WARNING("Button " << btnumber << " on page " << pnumber << " not found!");
1765
            return;
1766
        }
1767
 
1768
        button->showLastButton();
1769
    }
1770
    else if (pnumber >= REGULAR_SUBPAGE_START && pnumber < SYSTEM_PAGE_START)
1771
    {
1772
        TSubPage *spage = getSubPage(pnumber);
1773
 
1774
        if (!spage)
1775
        {
1776
            MSG_WARNING("Subpage " << pnumber << " not found!");
1777
            return;
1778
        }
1779
 
1780
        if (!spage->isVisible())
1781
            return;
1782
 
1783
        if (btnumber == 0)
1784
        {
1785
            spage->show();
1786
            return;
1787
        }
1788
 
1789
        Button::TButton *button = spage->getButton(btnumber);
1790
 
1791
        if (!button)
1792
        {
1793
            MSG_WARNING("Button " << btnumber << " on subpage " << pnumber << " not found!");
1794
            return;
1795
        }
1796
 
1797
        button->showLastButton();
1798
    }
1799
    else
1800
    {
1801
        MSG_WARNING("System pages are not handled by redraw method! Ignoring page " << pnumber << ".");
1802
    }
1803
}
1804
 
198 andreas 1805
#ifdef _SCALE_SKIA_
197 andreas 1806
void TPageManager::setSetupScaleFactor(double scale, double sw, double sh)
1807
{
1808
    DECL_TRACER("TPageManager::setSetupScaleFactor(double scale, double sw, double sh)");
1809
 
1810
    mScaleSystem = scale;
1811
    mScaleSystemWidth = sw;
1812
    mScaleSystemHeight = sh;
1813
}
198 andreas 1814
#endif
197 andreas 1815
 
11 andreas 1816
/*
1817
 * The following method is called by the class TAmxNet whenever an event from
169 andreas 1818
 * the Netlinx occured.
11 andreas 1819
 */
1820
void TPageManager::doCommand(const amx::ANET_COMMAND& cmd)
1821
{
1822
    DECL_TRACER("TPageManager::doCommand(const amx::ANET_COMMAND& cmd)");
1823
 
169 andreas 1824
    if (!cmdLoop_busy)
1825
        runCommands();
1826
 
11 andreas 1827
    mCommands.push_back(cmd);
169 andreas 1828
}
11 andreas 1829
 
169 andreas 1830
void TPageManager::commandLoop()
1831
{
1832
    DECL_TRACER("TPageManager::commandLoop()");
1833
 
418 andreas 1834
    if (cmdLoop_busy)
11 andreas 1835
        return;
1836
 
418 andreas 1837
    cmdLoop_busy = true;
11 andreas 1838
    string com;
1839
 
169 andreas 1840
    while (cmdLoop_busy && !killed && !_restart_)
11 andreas 1841
    {
169 andreas 1842
        while (mCommands.size() > 0)
11 andreas 1843
        {
169 andreas 1844
            amx::ANET_COMMAND bef = mCommands.at(0);
1845
            mCommands.erase(mCommands.begin());
11 andreas 1846
 
169 andreas 1847
            switch (bef.MC)
1848
            {
1849
                case 0x0006:
1850
                case 0x0018:	// feedback channel on
1851
                    com.assign("ON-");
1852
                    com.append(to_string(bef.data.chan_state.channel));
1853
                    parseCommand(bef.device1, bef.data.chan_state.port, com);
1854
                break;
11 andreas 1855
 
169 andreas 1856
                case 0x0007:
1857
                case 0x0019:	// feedback channel off
1858
                    com.assign("OFF-");
1859
                    com.append(to_string(bef.data.chan_state.channel));
1860
                    parseCommand(bef.device1, bef.data.chan_state.port, com);
1861
                break;
11 andreas 1862
 
169 andreas 1863
                case 0x000a:	// level value change
1864
                    com = "LEVEL-";
1865
                    com += to_string(bef.data.message_value.value);
1866
                    com += ",";
11 andreas 1867
 
169 andreas 1868
                    switch (bef.data.message_value.type)
1869
                    {
1870
                        case 0x10: com += to_string(bef.data.message_value.content.byte); break;
1871
                        case 0x11: com += to_string(bef.data.message_value.content.ch); break;
1872
                        case 0x20: com += to_string(bef.data.message_value.content.integer); break;
1873
                        case 0x21: com += to_string(bef.data.message_value.content.sinteger); break;
1874
                        case 0x40: com += to_string(bef.data.message_value.content.dword); break;
1875
                        case 0x41: com += to_string(bef.data.message_value.content.sdword); break;
1876
                        case 0x4f: com += to_string(bef.data.message_value.content.fvalue); break;
1877
                        case 0x8f: com += to_string(bef.data.message_value.content.dvalue); break;
1878
                    }
11 andreas 1879
 
169 andreas 1880
                    parseCommand(bef.device1, bef.data.message_value.port, com);
1881
                break;
11 andreas 1882
 
169 andreas 1883
                case 0x000c:	// Command string
11 andreas 1884
                {
169 andreas 1885
                    amx::ANET_MSG_STRING msg = bef.data.message_string;
11 andreas 1886
 
169 andreas 1887
                    if (msg.length < strlen((char *)&msg.content))
1888
                    {
1889
                        mCmdBuffer.append((char *)&msg.content);
1890
                        break;
1891
                    }
1892
                    else if (mCmdBuffer.length() > 0)
1893
                    {
1894
                        mCmdBuffer.append((char *)&msg.content);
1895
                        size_t len = (mCmdBuffer.length() >= sizeof(msg.content)) ? (sizeof(msg.content)-1) : mCmdBuffer.length();
1896
                        strncpy((char *)&msg.content, mCmdBuffer.c_str(), len);
1897
                        msg.content[len] = 0;
1898
                    }
104 andreas 1899
 
412 andreas 1900
                    if (getCommand((char *)msg.content) == "^UTF" || bef.intern)  // This is already UTF8!
169 andreas 1901
                        com.assign((char *)msg.content);
1902
                    else
1903
                        com.assign(cp1250ToUTF8((char *)&msg.content));
11 andreas 1904
 
169 andreas 1905
                    parseCommand(bef.device1, msg.port, com);
1906
                    mCmdBuffer.clear();
1907
                }
1908
                break;
15 andreas 1909
 
169 andreas 1910
                case 0x0502:    // Blink message (contains date and time)
1911
                    com = "BLINK-" + to_string(bef.data.blinkMessage.hour) + ":";
1912
                    com += to_string(bef.data.blinkMessage.minute) + ":";
1913
                    com += to_string(bef.data.blinkMessage.second) + ",";
1914
                    com += to_string(bef.data.blinkMessage.year) + "-";
1915
                    com += to_string(bef.data.blinkMessage.month) + "-";
1916
                    com += to_string(bef.data.blinkMessage.day) + ",";
1917
                    com += to_string(bef.data.blinkMessage.weekday) + ",";
1918
                    com += ((bef.data.blinkMessage.LED & 0x0001) ? "ON" : "OFF");
1919
                    parseCommand(0, 0, com);
1920
                break;
11 andreas 1921
 
169 andreas 1922
                case 0x1000:	// Filetransfer
11 andreas 1923
                {
169 andreas 1924
                    amx::ANET_FILETRANSFER ftr = bef.data.filetransfer;
1925
 
1926
                    if (ftr.ftype == 0)
11 andreas 1927
                    {
169 andreas 1928
                        switch(ftr.function)
1929
                        {
1930
                            case 0x0100:	// Syncing directory
1931
                                com = "#FTR-SYNC:0:";
1932
                                com.append((char*)&ftr.data[0]);
1933
                                parseCommand(bef.device1, bef.port1, com);
1934
                            break;
11 andreas 1935
 
169 andreas 1936
                            case 0x0104:	// Delete file
1937
                                com = "#FTR-SYNC:"+to_string(bef.count)+":Deleting files ... ("+to_string(bef.count)+"%)";
1938
                                parseCommand(bef.device1, bef.port1, com);
1939
                            break;
11 andreas 1940
 
169 andreas 1941
                            case 0x0105:	// start filetransfer
1942
                                com = "#FTR-START";
1943
                                parseCommand(bef.device1, bef.port1, com);
1944
                            break;
1945
                        }
11 andreas 1946
                    }
169 andreas 1947
                    else
11 andreas 1948
                    {
169 andreas 1949
                        switch(ftr.function)
1950
                        {
1951
                            case 0x0003:	// Received part of file
1952
                            case 0x0004:	// End of file
1953
                                com = "#FTR-FTRPART:"+to_string(bef.count)+":"+to_string(ftr.info1);
1954
                                parseCommand(bef.device1, bef.port1, com);
1955
                            break;
11 andreas 1956
 
169 andreas 1957
                            case 0x0007:	// End of file transfer
1958
                            {
1959
                                com = "#FTR-END";
1960
                                parseCommand(bef.device1, bef.port1, com);
1961
                            }
1962
                            break;
1963
 
1964
                            case 0x0102:	// Receiving file
1965
                                com = "#FTR-FTRSTART:"+to_string(bef.count)+":"+to_string(ftr.info1)+":";
1966
                                com.append((char*)&ftr.data[0]);
1967
                                parseCommand(bef.device1, bef.port1, com);
1968
                            break;
11 andreas 1969
                        }
1970
                    }
1971
                }
169 andreas 1972
                break;
11 andreas 1973
            }
1974
        }
169 andreas 1975
 
1976
        std::this_thread::sleep_for(std::chrono::milliseconds(50));
11 andreas 1977
    }
1978
 
169 andreas 1979
    cmdLoop_busy = false;
11 andreas 1980
}
1981
 
26 andreas 1982
void TPageManager::deployCallbacks()
1983
{
1984
    DECL_TRACER("TPageManager::deployCallbacks()");
1985
 
1986
    PCHAIN_T *p = mPchain;
1987
 
1988
    while (p)
1989
    {
1990
        if (p->page)
1991
        {
1992
            if (_setBackground)
1993
                p->page->registerCallback(_setBackground);
1994
 
1995
            if (_callPlayVideo)
1996
                p->page->regCallPlayVideo(_callPlayVideo);
1997
        }
1998
 
1999
        p = p->next;
2000
    }
2001
 
2002
    SPCHAIN_T *sp = mSPchain;
2003
 
2004
    while (sp)
2005
    {
2006
        if (sp->page)
2007
        {
2008
            if (_setBackground)
2009
                sp->page->registerCallback(_setBackground);
2010
 
2011
            if (_callPlayVideo)
2012
                sp->page->regCallPlayVideo(_callPlayVideo);
2013
        }
2014
 
2015
        sp = sp->next;
2016
    }
2017
}
36 andreas 2018
 
2019
void TPageManager::regCallbackNetState(std::function<void (int)> callNetState, ulong handle)
2020
{
2021
    DECL_TRACER("TPageManager::regCallbackNetState(std::function<void (int)> callNetState, ulong handle)");
2022
 
2023
    if (handle == 0)
2024
        return;
2025
 
2026
    mNetCalls.insert(std::pair<int, std::function<void (int)> >(handle, callNetState));
2027
}
2028
 
2029
void TPageManager::unregCallbackNetState(ulong handle)
2030
{
2031
    DECL_TRACER("TPageManager::unregCallbackNetState(ulong handle)");
2032
 
83 andreas 2033
    if (mNetCalls.size() == 0)
2034
        return;
2035
 
300 andreas 2036
    std::map<int, std::function<void (int)> >::iterator iter = mNetCalls.find((int)handle);
36 andreas 2037
 
2038
    if (iter != mNetCalls.end())
2039
        mNetCalls.erase(iter);
2040
}
247 andreas 2041
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
251 andreas 2042
#ifdef Q_OS_ANDROID
38 andreas 2043
void TPageManager::regCallbackBatteryState(std::function<void (int, bool, int)> callBatteryState, ulong handle)
2044
{
2045
    DECL_TRACER("TPageManager::regCallbackBatteryState(std::function<void (int, bool, int)> callBatteryState, ulong handle)");
2046
 
2047
    if (handle == 0)
2048
        return;
2049
 
2050
    mBatteryCalls.insert(std::pair<int, std::function<void (int, bool, int)> >(handle, callBatteryState));
2051
}
247 andreas 2052
#endif
2053
#ifdef Q_OS_IOS
2054
void TPageManager::regCallbackBatteryState(std::function<void (int, int)> callBatteryState, ulong handle)
2055
{
2056
    DECL_TRACER("TPageManager::regCallbackBatteryState(std::function<void (int, int)> callBatteryState, ulong handle)");
38 andreas 2057
 
247 andreas 2058
    if (handle == 0)
2059
        return;
2060
 
2061
    mBatteryCalls.insert(std::pair<int, std::function<void (int, int)> >(handle, callBatteryState));
264 andreas 2062
#ifdef Q_OS_IOS
2063
    mLastBatteryLevel = TIOSBattery::getBatteryLeft();
2064
    mLastBatteryState = TIOSBattery::getBatteryState();
247 andreas 2065
 
264 andreas 2066
#endif
247 andreas 2067
    if (mLastBatteryLevel > 0 || mLastBatteryState > 0)
2068
        informBatteryStatus(mLastBatteryLevel, mLastBatteryState);
2069
}
2070
#endif
38 andreas 2071
void TPageManager::unregCallbackBatteryState(ulong handle)
2072
{
2073
    DECL_TRACER("TPageManager::unregCallbackBatteryState(ulong handle)");
2074
 
83 andreas 2075
    if (mBatteryCalls.size() == 0)
2076
        return;
247 andreas 2077
#ifdef Q_OS_ANDROID
38 andreas 2078
    std::map<int, std::function<void (int, bool, int)> >::iterator iter = mBatteryCalls.find(handle);
247 andreas 2079
#endif
2080
#ifdef Q_OS_IOS
300 andreas 2081
    std::map<int, std::function<void (int, int)> >::iterator iter = mBatteryCalls.find((int)handle);
247 andreas 2082
#endif
38 andreas 2083
    if (iter != mBatteryCalls.end())
2084
        mBatteryCalls.erase(iter);
2085
}
247 andreas 2086
#endif  // defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
11 andreas 2087
/*
2088
 * The following function must be called to start the "panel".
2089
 */
5 andreas 2090
bool TPageManager::run()
2091
{
2092
    DECL_TRACER("TPageManager::run()");
2093
 
2094
    if (mActualPage <= 0)
2095
        return false;
2096
 
154 andreas 2097
    TPage *pg = getPage(mActualPage);
2098
 
2099
    if (!pg || !_setPage || !mTSettings)
2100
        return false;
2101
 
14 andreas 2102
    surface_mutex.lock();
7 andreas 2103
    pg->setFonts(mFonts);
5 andreas 2104
    pg->registerCallback(_setBackground);
21 andreas 2105
    pg->regCallPlayVideo(_callPlayVideo);
5 andreas 2106
 
26 andreas 2107
    int width, height;
217 andreas 2108
    width = mTSettings->getWidth();
26 andreas 2109
    height = mTSettings->getHeight();
43 andreas 2110
#ifdef _SCALE_SKIA_
26 andreas 2111
    if (mScaleFactor != 1.0)
2112
    {
2113
        width = (int)((double)width * mScaleFactor);
2114
        height = (int)((double)height * mScaleFactor);
2115
    }
43 andreas 2116
#endif
26 andreas 2117
    _setPage((pg->getNumber() << 16) & 0xffff0000, width, height);
5 andreas 2118
    pg->show();
2119
 
2120
    TSubPage *subPg = pg->getFirstSubPage();
2121
 
2122
    while (subPg)
2123
    {
7 andreas 2124
        subPg->setFonts(mFonts);
2125
        subPg->registerCallback(_setBackground);
2126
        subPg->registerCallbackDB(_displayButton);
11 andreas 2127
        subPg->regCallDropSubPage(_callDropSubPage);
21 andreas 2128
        subPg->regCallPlayVideo(_callPlayVideo);
7 andreas 2129
 
5 andreas 2130
        if (_setSubPage)
6 andreas 2131
        {
2132
            MSG_DEBUG("Drawing page " << subPg->getNumber() << ": " << subPg->getName() << "...");
26 andreas 2133
            width = subPg->getWidth();
2134
            height = subPg->getHeight();
2135
            int left = subPg->getLeft();
2136
            int top = subPg->getTop();
43 andreas 2137
#ifdef _SCALE_SKIA_
26 andreas 2138
            if (mScaleFactor != 1.0)
2139
            {
2140
                width = (int)((double)width * mScaleFactor);
2141
                height = (int)((double)height * mScaleFactor);
2142
                left = (int)((double)left * mScaleFactor);
2143
                top = (int)((double)top * mScaleFactor);
2144
            }
43 andreas 2145
#endif
41 andreas 2146
            ANIMATION_t ani;
2147
            ani.showEffect = subPg->getShowEffect();
2148
            ani.showTime = subPg->getShowTime();
42 andreas 2149
            ani.hideEffect = subPg->getHideEffect();
2150
            ani.hideTime = subPg->getHideTime();
162 andreas 2151
 
2152
            subPg->setZOrder(pg->getNextZOrder());
418 andreas 2153
            _setSubPage(subPg->getHandle(), pg->getHandle(), left, top, width, height, ani, subPg->isModal());
6 andreas 2154
            subPg->show();
2155
        }
5 andreas 2156
 
2157
        subPg = pg->getNextSubPage();
2158
    }
2159
 
14 andreas 2160
    surface_mutex.unlock();
5 andreas 2161
    return true;
2162
}
2163
 
4 andreas 2164
TPage *TPageManager::getPage(int pageID)
2165
{
2166
    DECL_TRACER("TPageManager::getPage(int pageID)");
2167
 
209 andreas 2168
    if (pageID <= 0)
2169
        return nullptr;
2170
 
4 andreas 2171
    PCHAIN_T *p = mPchain;
2172
 
2173
    while (p)
2174
    {
349 andreas 2175
        if (p->page && p->page->getNumber() == pageID)
4 andreas 2176
            return p->page;
2177
 
2178
        p = p->next;
2179
    }
2180
 
2181
    return nullptr;
2182
}
2183
 
2184
TPage *TPageManager::getPage(const string& name)
2185
{
2186
    DECL_TRACER("TPageManager::getPage(const string& name)");
2187
 
349 andreas 2188
    if (name.empty())
2189
        return nullptr;
2190
 
4 andreas 2191
    PCHAIN_T *p = mPchain;
2192
 
2193
    while (p)
2194
    {
349 andreas 2195
        if (p->page && p->page->getName().compare(name) == 0)
4 andreas 2196
            return p->page;
2197
 
2198
        p = p->next;
2199
    }
2200
 
2201
    return nullptr;
2202
}
2203
 
209 andreas 2204
TPage *TPageManager::loadPage(PAGELIST_T& pl, bool *refresh)
15 andreas 2205
{
209 andreas 2206
    DECL_TRACER("TPageManager::loadPage(PAGELIST_T& pl, bool *refresh)");
15 andreas 2207
 
209 andreas 2208
    if (refresh)
2209
        *refresh = false;
2210
 
15 andreas 2211
    if (!pl.isValid)
2212
        return nullptr;
2213
 
2214
    TPage *pg = getPage(pl.pageID);
2215
 
2216
    if (!pg)
2217
    {
2218
        if (!readPage(pl.pageID))
2219
            return nullptr;
2220
 
2221
        pg = getPage(pl.pageID);
2222
 
2223
        if (!pg)
2224
        {
2225
            MSG_ERROR("Error loading page " << pl.pageID << ", " << pl.name << " from file " << pl.file << "!");
2226
            return nullptr;
2227
        }
209 andreas 2228
 
2229
        if (refresh)
213 andreas 2230
            *refresh = true;        // Indicate that the page was freshly loaded
15 andreas 2231
    }
2232
 
2233
    return pg;
2234
}
2235
 
209 andreas 2236
void TPageManager::reloadSystemPage(TPage *page)
2237
{
2238
    DECL_TRACER("TPageManager::reloadSystemPage(TPage *page)");
2239
 
2240
    if (!page)
2241
        return;
2242
 
2243
    vector<Button::TButton *> buttons = page->getAllButtons();
2244
    vector<Button::TButton *>::iterator iter;
210 andreas 2245
    TConfig::setTemporary(false);
209 andreas 2246
 
2247
    for (iter = buttons.begin(); iter != buttons.end(); ++iter)
2248
    {
2249
        Button::TButton *bt = *iter;
2250
 
2251
        if (bt->getAddressPort() == 0 && bt->getAddressChannel() > 0)
2252
        {
2253
            switch(bt->getAddressChannel())
2254
            {
2255
                case SYSTEM_ITEM_LOGLOGFILE:        bt->setTextOnly(TConfig::getLogFile(), -1); break;
2256
 
2257
                case SYSTEM_ITEM_NETLINX_IP:        bt->setTextOnly(TConfig::getController(), -1); break;
2258
                case SYSTEM_ITEM_NETLINX_PORT:      bt->setTextOnly(std::to_string(TConfig::getPort()), -1); break;
2259
                case SYSTEM_ITEM_NETLINX_CHANNEL:   bt->setTextOnly(std::to_string(TConfig::getChannel()), -1); break;
2260
                case SYSTEM_ITEM_NETLINX_PTYPE:     bt->setTextOnly(TConfig::getPanelType(), -1); break;
2261
                case SYSTEM_ITEM_FTPUSER:           bt->setTextOnly(TConfig::getFtpUser(), -1); break;
2262
                case SYSTEM_ITEM_FTPPASSWORD:       bt->setTextOnly(TConfig::getFtpPassword(), -1); break;
2263
                case SYSTEM_ITEM_FTPSURFACE:        bt->setTextOnly(TConfig::getFtpSurface(), -1); break;
210 andreas 2264
 
2265
                case SYSTEM_ITEM_SIPPROXY:          bt->setTextOnly(TConfig::getSIPproxy(), -1); break;
2266
                case SYSTEM_ITEM_SIPPORT:           bt->setTextOnly(std::to_string(TConfig::getSIPport()), -1); break;
2267
                case SYSTEM_ITEM_SIPSTUN:           bt->setTextOnly(TConfig::getSIPstun(), -1); break;
2268
                case SYSTEM_ITEM_SIPDOMAIN:         bt->setTextOnly(TConfig::getSIPdomain(), -1); break;
2269
                case SYSTEM_ITEM_SIPUSER:           bt->setTextOnly(TConfig::getSIPuser(), -1); break;
2270
                case SYSTEM_ITEM_SIPPASSWORD:       bt->setTextOnly(TConfig::getSIPpassword(), -1); break;
2271
 
2272
                case SYSTEM_ITEM_SYSTEMSOUND:       bt->setTextOnly(TConfig::getSystemSound(), -1); break;
2273
                case SYSTEM_ITEM_SINGLEBEEP:        bt->setTextOnly(TConfig::getSingleBeepSound(), -1); break;
2274
                case SYSTEM_ITEM_DOUBLEBEEP:        bt->setTextOnly(TConfig::getDoubleBeepSound(), -1); break;
209 andreas 2275
            }
2276
        }
210 andreas 2277
        else if (bt->getChannelPort() == 0 && bt->getChannelNumber() > 0)
2278
        {
2279
            switch(bt->getChannelNumber())
2280
            {
2281
                case SYSTEM_ITEM_DEBUGINFO:         bt->setActiveInstance(IS_LOG_INFO() ? 1 : 0); break;
2282
                case SYSTEM_ITEM_DEBUGWARNING:      bt->setActiveInstance(IS_LOG_WARNING() ? 1 : 0); break;
2283
                case SYSTEM_ITEM_DEBUGERROR:        bt->setActiveInstance(IS_LOG_ERROR() ? 1 : 0); break;
2284
                case SYSTEM_ITEM_DEBUGTRACE:        bt->setActiveInstance(IS_LOG_TRACE() ? 1 : 0); break;
2285
                case SYSTEM_ITEM_DEBUGDEBUG:        bt->setActiveInstance(IS_LOG_DEBUG() ? 1 : 0); break;
2286
                case SYSTEM_ITEM_DEBUGPROTOCOL:     bt->setActiveInstance(IS_LOG_PROTOCOL() ? 1 : 0); break;
2287
                case SYSTEM_ITEM_DEBUGALL:          bt->setActiveInstance(IS_LOG_ALL() ? 1 : 0); break;
2288
                case SYSTEM_ITEM_DEBUGLONG:         bt->setActiveInstance(TConfig::isLongFormat() ? 1 : 0); break;
2289
                case SYSTEM_ITEM_DEBUGPROFILE:      bt->setActiveInstance(TConfig::getProfiling() ? 1 : 0); break;
2290
 
2291
                case SYSTEM_ITEM_FTPPASSIVE:        bt->setActiveInstance(TConfig::getFtpPassive() ? 1 : 0); break;
2292
 
2293
                case SYSTEM_ITEM_SIPIPV4:           bt->setActiveInstance(TConfig::getSIPnetworkIPv4() ? 1 : 0); break;
2294
                case SYSTEM_ITEM_SIPIPV6:           bt->setActiveInstance(TConfig::getSIPnetworkIPv6() ? 1 : 0); break;
2295
                case SYSTEM_ITEM_SIPENABLE:         bt->setActiveInstance(TConfig::getSIPstatus() ? 1 : 0); break;
2296
                case SYSTEM_ITEM_SIPIPHONE:         bt->setActiveInstance(TConfig::getSIPiphone() ? 1 : 0); break;
2297
 
2298
                case SYSTEM_ITEM_SOUNDSWITCH:       bt->setActiveInstance(TConfig::getSystemSoundState() ? 1 : 0); break;
2299
 
2300
                case SYSTEM_ITEM_VIEWSCALEFIT:      bt->setActiveInstance(TConfig::getScale() ? 1 : 0); break;
2301
                case SYSTEM_ITEM_VIEWBANNER:        bt->setActiveInstance(TConfig::showBanner() ? 1 : 0); break;
2302
                case SYSTEM_ITEM_VIEWNOTOOLBAR:     bt->setActiveInstance(TConfig::getToolbarSuppress() ? 1 : 0); break;
2303
                case SYSTEM_ITEM_VIEWTOOLBAR:       bt->setActiveInstance(TConfig::getToolbarForce() ? 1 : 0); break;
2304
                case SYSTEM_ITEM_VIEWROTATE:        bt->setActiveInstance(TConfig::getRotationFixed() ? 1 : 0); break;
2305
            }
2306
        }
416 andreas 2307
        else if (bt->getLevelPort() == 0 && bt->getLevelChannel() > 0)
210 andreas 2308
        {
416 andreas 2309
            switch(bt->getLevelChannel())
210 andreas 2310
            {
2311
                case SYSTEM_ITEM_SYSVOLUME:         bt->drawBargraph(0, TConfig::getSystemVolume(), false); break;
2312
                case SYSTEM_ITEM_SYSGAIN:           bt->drawBargraph(0, TConfig::getSystemGain(), false); break;
2313
            }
2314
        }
209 andreas 2315
    }
2316
}
2317
 
198 andreas 2318
bool TPageManager::setPage(int PageID, bool forget)
15 andreas 2319
{
198 andreas 2320
    DECL_TRACER("TPageManager::setPage(int PageID, bool forget)");
15 andreas 2321
 
295 andreas 2322
    return _setPageDo(PageID, "", forget);
15 andreas 2323
}
2324
 
168 andreas 2325
bool TPageManager::setPage(const string& name, bool forget)
15 andreas 2326
{
190 andreas 2327
    DECL_TRACER("TPageManager::setPage(const string& name, bool forget)");
15 andreas 2328
 
295 andreas 2329
    return _setPageDo(0, name, forget);
15 andreas 2330
}
2331
 
295 andreas 2332
bool TPageManager::_setPageDo(int pageID, const string& name, bool forget)
2333
{
2334
    DECL_TRACER("TPageManager::_setPageDo(int pageID, const string& name, bool forget)");
2335
 
2336
    TPage *pg = nullptr;
2337
 
2338
    if (pageID > 0 && mActualPage == pageID)
343 andreas 2339
    {
2340
#if TESTMODE == 1
2341
        __success = true;
2342
        setScreenDone();
2343
#endif
295 andreas 2344
        return true;
343 andreas 2345
    }
295 andreas 2346
    else if (!name.empty())
2347
    {
2348
        pg = getPage(mActualPage);
2349
 
2350
        if (pg && pg->getName().compare(name) == 0)
343 andreas 2351
        {
2352
#if TESTMODE == 1
2353
            __success = true;
2354
            setScreenDone();
2355
#endif
295 andreas 2356
            return true;
343 andreas 2357
        }
295 andreas 2358
    }
2359
    else if (pageID > 0)
2360
        pg = getPage(mActualPage);
2361
    else
343 andreas 2362
    {
2363
#if TESTMODE == 1
2364
        setScreenDone();
2365
#endif
295 andreas 2366
        return false;
343 andreas 2367
    }
295 andreas 2368
 
2369
    // FIXME: Make this a vector array to hold a larger history!
2370
    if (!forget)
2371
        mPreviousPage = mActualPage;    // Necessary to be able to jump back to at least the last previous page
2372
 
2373
    if (pg)
2374
        pg->drop();
2375
 
2376
    mActualPage = 0;
2377
    PAGELIST_T listPg;
2378
 
2379
    if (pageID > 0)
2380
        listPg = findPage(pageID);
2381
    else
2382
        listPg = findPage(name);
2383
 
2384
    bool refresh = false;
2385
 
2386
    if ((pg = loadPage(listPg, &refresh)) == nullptr)
343 andreas 2387
    {
2388
#if TESTMODE == 1
2389
        setScreenDone();
2390
#endif
295 andreas 2391
        return false;
343 andreas 2392
    }
295 andreas 2393
 
2394
    mActualPage = pg->getNumber();
2395
 
2396
    if (mActualPage >= SYSTEM_PAGE_START && !refresh)
2397
        reloadSystemPage(pg);
2398
 
2399
    int width = (mActualPage >= SYSTEM_PAGE_START ? mSystemSettings->getWidth() : mTSettings->getWidth());
2400
    int height = (mActualPage >= SYSTEM_PAGE_START ? mSystemSettings->getHeight() : mTSettings->getHeight());
2401
 
2402
    if (_setPage)
2403
        _setPage((mActualPage << 16) & 0xffff0000, width, height);
2404
 
2405
    pg->show();
2406
    return true;
2407
}
2408
 
2409
 
4 andreas 2410
TSubPage *TPageManager::getSubPage(int pageID)
2411
{
2412
    DECL_TRACER("TPageManager::getSubPage(int pageID)");
2413
 
419 andreas 2414
    if (pageID < REGULAR_SUBPAGE_START)
2415
        return nullptr;
2416
 
4 andreas 2417
    SPCHAIN_T *p = mSPchain;
2418
 
2419
    while(p)
2420
    {
2421
        if (p->page->getNumber() == pageID)
2422
            return p->page;
2423
 
2424
        p = p->next;
2425
    }
2426
 
2427
    return nullptr;
2428
}
2429
 
2430
TSubPage *TPageManager::getSubPage(const std::string& name)
2431
{
2432
    DECL_TRACER("TPageManager::getSubPage(const std::string& name)");
2433
 
2434
    SPCHAIN_T *p = mSPchain;
2435
 
2436
    while (p)
2437
    {
2438
        if (p->page->getName().compare(name) == 0)
2439
            return p->page;
2440
 
2441
        p = p->next;
2442
    }
2443
 
146 andreas 2444
    MSG_DEBUG("Page " << name << " not found in cache.");
4 andreas 2445
    return nullptr;
2446
}
2447
 
96 andreas 2448
TSubPage *TPageManager::deliverSubPage(const string& name, TPage **pg)
2449
{
198 andreas 2450
    DECL_TRACER("TPageManager::deliverSubPage(const string& name, TPage **pg)");
96 andreas 2451
 
2452
    TPage *page = getActualPage();
2453
 
2454
    if (!page)
2455
    {
2456
        MSG_ERROR("No actual page loaded!");
2457
        return nullptr;
2458
    }
2459
 
2460
    if (pg)
2461
        *pg = page;
2462
 
2463
    TSubPage *subPage = getSubPage(name);
2464
 
2465
    if (!subPage)
2466
    {
2467
        if (!readSubPage(name))
2468
        {
2469
            MSG_ERROR("Error reading subpage " << name);
2470
            return nullptr;
2471
        }
2472
 
2473
        subPage = getSubPage(name);
2474
 
2475
        if (!subPage)
2476
        {
2477
            MSG_ERROR("Fatal: A page with name " << name << " does not exist!");
2478
            return nullptr;
2479
        }
350 andreas 2480
 
2481
        subPage->setParent(page->getHandle());
96 andreas 2482
    }
2483
 
2484
    return subPage;
2485
}
2486
 
198 andreas 2487
TSubPage *TPageManager::deliverSubPage(int number, TPage **pg)
2488
{
2489
    DECL_TRACER("TPageManager::deliverSubPage(int number, TPage **pg)");
2490
 
2491
    TPage *page = getActualPage();
2492
 
2493
    if (!page)
2494
    {
2495
        MSG_ERROR("No actual page loaded!");
2496
        return nullptr;
2497
    }
2498
 
2499
    if (pg)
2500
        *pg = page;
2501
 
2502
    TSubPage *subPage = getSubPage(number);
2503
 
2504
    if (!subPage)
2505
    {
2506
        if (!readSubPage(number))
2507
        {
2508
            MSG_ERROR("Error reading subpage " << number);
2509
            return nullptr;
2510
        }
2511
 
2512
        subPage = getSubPage(number);
2513
 
2514
        if (!subPage)
2515
        {
2516
            MSG_ERROR("Fatal: A page with name " << number << " does not exist!");
2517
            return nullptr;
2518
        }
350 andreas 2519
 
2520
        subPage->setParent(page->getHandle());
198 andreas 2521
    }
2522
 
2523
    return subPage;
2524
}
2525
 
3 andreas 2526
bool TPageManager::readPages()
2527
{
2528
    DECL_TRACER("TPageManager::readPages()");
2529
 
2530
    if (!mPageList)
2531
    {
2532
        MSG_ERROR("Page list is not initialized!");
2533
        TError::setError();
2534
        return false;
2535
    }
2536
 
2537
    // Read all pages
2538
    vector<PAGELIST_T> pageList = mPageList->getPagelist();
2539
 
83 andreas 2540
    if (pageList.size() > 0)
3 andreas 2541
    {
83 andreas 2542
        vector<PAGELIST_T>::iterator pgIter;
14 andreas 2543
 
118 andreas 2544
        for (pgIter = pageList.begin(); pgIter != pageList.end(); ++pgIter)
14 andreas 2545
        {
83 andreas 2546
            TPage *page = new TPage(pgIter->name+".xml");
14 andreas 2547
 
83 andreas 2548
            if (TError::isError())
2549
            {
2550
                delete page;
2551
                return false;
2552
            }
3 andreas 2553
 
83 andreas 2554
            page->setPalette(mPalette);
2555
            page->setFonts(mFonts);
2556
            page->registerCallback(_setBackground);
2557
            page->registerCallbackDB(_displayButton);
2558
            page->regCallPlayVideo(_callPlayVideo);
2559
 
2560
            if (!addPage(page))
2561
                return false;
2562
        }
3 andreas 2563
    }
2564
 
348 andreas 2565
    vector<SUBPAGELIST_T> subPageList = mPageList->getSubPageList();
3 andreas 2566
 
83 andreas 2567
    if (subPageList.size() > 0)
3 andreas 2568
    {
83 andreas 2569
        vector<SUBPAGELIST_T>::iterator spgIter;
14 andreas 2570
 
118 andreas 2571
        for (spgIter = subPageList.begin(); spgIter != subPageList.end(); ++spgIter)
14 andreas 2572
        {
83 andreas 2573
            TSubPage *page = new TSubPage(spgIter->name+".xml");
14 andreas 2574
 
83 andreas 2575
            if (TError::isError())
2576
            {
2577
                delete page;
2578
                return false;
2579
            }
3 andreas 2580
 
83 andreas 2581
            page->setPalette(mPalette);
2582
            page->setFonts(mFonts);
2583
            page->registerCallback(_setBackground);
2584
            page->registerCallbackDB(_displayButton);
2585
            page->regCallDropSubPage(_callDropSubPage);
2586
            page->regCallPlayVideo(_callPlayVideo);
2587
            page->setGroup(spgIter->group);
2588
 
2589
            if (!addSubPage(page))
2590
                return false;
2591
        }
3 andreas 2592
    }
2593
 
2594
    return true;
2595
}
2596
 
2597
bool TPageManager::readPage(const std::string& name)
2598
{
2599
    DECL_TRACER("TPageManager::readPage(const std::string& name)");
2600
 
2601
    PAGELIST_T page = findPage(name);
2602
 
206 andreas 2603
    if ((page.pageID <= 0 || page.pageID >= MAX_PAGE_ID) && page.pageID < SYSTEM_PAGE_START && page.pageID >= SYSTEM_SUBPAGE_START)
3 andreas 2604
    {
2605
        MSG_ERROR("Page " << name << " not found!");
2606
        return false;
2607
    }
2608
 
43 andreas 2609
    TPage *pg;
14 andreas 2610
 
43 andreas 2611
    if (name.compare("_progress") == 0)
2612
        pg = new TPage(name);
2613
    else
2614
        pg = new TPage(page.name+".xml");
2615
 
14 andreas 2616
    if (TError::isError())
2617
    {
2618
        delete pg;
2619
        return false;
2620
    }
2621
 
4 andreas 2622
    pg->setPalette(mPalette);
7 andreas 2623
    pg->setFonts(mFonts);
2624
    pg->registerCallback(_setBackground);
2625
    pg->registerCallbackDB(_displayButton);
21 andreas 2626
    pg->regCallPlayVideo(_callPlayVideo);
3 andreas 2627
 
2628
    if (!addPage(pg))
2629
        return false;
2630
 
2631
    return true;
2632
}
2633
 
2634
bool TPageManager::readPage(int ID)
2635
{
2636
    DECL_TRACER("TPageManager::readPage(int ID)");
2637
 
16 andreas 2638
    TError::clear();
3 andreas 2639
    PAGELIST_T page = findPage(ID);
2640
 
2641
    if (page.pageID <= 0)
2642
    {
2643
        MSG_ERROR("Page with ID " << ID << " not found!");
2644
        return false;
2645
    }
2646
 
43 andreas 2647
    TPage *pg;
14 andreas 2648
 
43 andreas 2649
    if (ID == 300)      // Progress page of system?
2650
        pg = new TPage("_progress");
2651
    else
2652
        pg = new TPage(page.name+".xml");
2653
 
14 andreas 2654
    if (TError::isError())
2655
    {
2656
        delete pg;
2657
        return false;
2658
    }
2659
 
4 andreas 2660
    pg->setPalette(mPalette);
7 andreas 2661
    pg->setFonts(mFonts);
2662
    pg->registerCallback(_setBackground);
2663
    pg->registerCallbackDB(_displayButton);
21 andreas 2664
    pg->regCallPlayVideo(_callPlayVideo);
3 andreas 2665
 
2666
    if (!addPage(pg))
2667
        return false;
2668
 
2669
    return true;
2670
}
2671
 
2672
bool TPageManager::readSubPage(const std::string& name)
2673
{
2674
    DECL_TRACER("TPageManager::readSubPage(const std::string& name)");
2675
 
16 andreas 2676
    TError::clear();
3 andreas 2677
    SUBPAGELIST_T page = findSubPage(name);
2678
 
206 andreas 2679
    if (page.pageID < MAX_PAGE_ID || (page.pageID >= SYSTEM_PAGE_START && page.pageID < SYSTEM_SUBPAGE_START))
3 andreas 2680
    {
2681
        MSG_ERROR("Subpage " << name << " not found!");
2682
        return false;
2683
    }
2684
 
14 andreas 2685
    if (haveSubPage(name))
2686
        return true;
2687
 
3 andreas 2688
    TSubPage *pg = new TSubPage(page.name+".xml");
14 andreas 2689
 
2690
    if (TError::isError())
2691
    {
2692
        delete pg;
2693
        return false;
2694
    }
2695
 
4 andreas 2696
    pg->setPalette(mPalette);
7 andreas 2697
    pg->setFonts(mFonts);
2698
    pg->registerCallback(_setBackground);
2699
    pg->registerCallbackDB(_displayButton);
11 andreas 2700
    pg->regCallDropSubPage(_callDropSubPage);
21 andreas 2701
    pg->regCallPlayVideo(_callPlayVideo);
11 andreas 2702
    pg->setGroup(page.group);
3 andreas 2703
 
2704
    if (!addSubPage(pg))
14 andreas 2705
    {
2706
        delete pg;
3 andreas 2707
        return false;
14 andreas 2708
    }
3 andreas 2709
 
2710
    return true;
2711
}
2712
 
2713
bool TPageManager::readSubPage(int ID)
2714
{
2715
    DECL_TRACER("TPageManager::readSubPage(int ID)");
2716
 
16 andreas 2717
    TError::clear();
3 andreas 2718
    SUBPAGELIST_T page = findSubPage(ID);
2719
 
154 andreas 2720
    if (page.pageID <= MAX_PAGE_ID)
3 andreas 2721
    {
2722
        MSG_ERROR("Subpage with ID " << ID << " not found!");
2723
        return false;
2724
    }
2725
 
2726
    TSubPage *pg = new TSubPage(page.name+".xml");
14 andreas 2727
 
2728
    if (TError::isError())
2729
    {
2730
        delete pg;
2731
        return false;
2732
    }
2733
 
4 andreas 2734
    pg->setPalette(mPalette);
7 andreas 2735
    pg->setFonts(mFonts);
2736
    pg->registerCallback(_setBackground);
2737
    pg->registerCallbackDB(_displayButton);
11 andreas 2738
    pg->regCallDropSubPage(_callDropSubPage);
21 andreas 2739
    pg->regCallPlayVideo(_callPlayVideo);
11 andreas 2740
    pg->setGroup(page.group);
3 andreas 2741
 
2742
    if (!addSubPage(pg))
2743
        return false;
2744
 
2745
    return true;
2746
}
2747
 
279 andreas 2748
vector<TSubPage *> TPageManager::createSubViewList(int id)
2749
{
2750
    DECL_TRACER("TPageManager::createSubViewList(int id)");
2751
 
2752
    vector<TSubPage *> subviews;
2753
 
2754
    if (id <= 0)
2755
        return subviews;
2756
 
2757
    if (!mPageList)
2758
    {
2759
        MSG_WARNING("Missing page list and because of this can't make a subview list!");
2760
        return subviews;
2761
    }
2762
 
2763
    SUBVIEWLIST_T slist = mPageList->findSubViewList(id);
2764
 
2765
    if (slist.id <= 0 || slist.items.empty())
2766
    {
2767
        if (slist.id <= 0)
2768
        {
2769
            MSG_WARNING("Found no subview list with ID " << id);
2770
        }
2771
        else
2772
        {
300 andreas 2773
            MSG_WARNING("Subview list " << id << " has no items!");
279 andreas 2774
        }
2775
 
2776
        return subviews;
2777
    }
2778
 
2779
    vector<SUBVIEWITEM_T>::iterator iter;
2780
 
2781
    for (iter = slist.items.begin(); iter != slist.items.end(); ++iter)
2782
    {
2783
        if (!haveSubPage(iter->pageID))
2784
        {
2785
            if (!readSubPage(iter->pageID))
2786
                return vector<TSubPage *>();
2787
        }
2788
 
284 andreas 2789
        TSubPage *pg = getSubPage(iter->pageID);
279 andreas 2790
 
2791
        if (pg)
2792
            subviews.push_back(pg);
284 andreas 2793
        else
2794
        {
2795
            MSG_DEBUG("No subpage with ID " << id);
2796
        }
279 andreas 2797
    }
2798
 
300 andreas 2799
    MSG_DEBUG("Found " << subviews.size() << " subview items.");
279 andreas 2800
    return subviews;
2801
}
2802
 
280 andreas 2803
void TPageManager::showSubViewList(int id, Button::TButton *bt)
279 andreas 2804
{
280 andreas 2805
    DECL_TRACER("TPageManager::showSubViewList(int id, Button::TButton *bt)");
279 andreas 2806
 
2807
    vector<TSubPage *> subviews = createSubViewList(id);
2808
 
303 andreas 2809
    if (subviews.empty() || !_addViewButtonItems || !bt)
284 andreas 2810
    {
2811
        MSG_DEBUG("Number views: " << subviews.size() << (_addViewButtonItems ? ", addView" : ", NO addView") << (_displayViewButton ? " display" : " NO display"));
279 andreas 2812
        return;
284 andreas 2813
    }
279 andreas 2814
 
293 andreas 2815
    ulong btHandle = bt->getHandle();
2816
    MSG_DEBUG("Working on button " << handleToString(btHandle) << " (" << bt->getName() << ") with " << subviews.size() << " pages.");
289 andreas 2817
    TBitmap bm = bt->getLastBitmap();
2818
    TColor::COLOR_T fillColor = TColor::getAMXColor(bt->getFillColor());
293 andreas 2819
    _displayViewButton(btHandle, bt->getParent(), bt->isSubViewVertical(), bm, bt->getWidth(), bt->getHeight(), bt->getLeftPosition(), bt->getTopPosition(), bt->getSubViewSpace(), fillColor);
280 andreas 2820
 
2821
    vector<PGSUBVIEWITEM_T> items;
2822
    PGSUBVIEWITEM_T svItem;
2823
    PGSUBVIEWATOM_T svAtom;
279 andreas 2824
    vector<TSubPage *>::iterator iter;
2825
 
2826
    for (iter = subviews.begin(); iter != subviews.end(); ++iter)
2827
    {
280 andreas 2828
        TSubPage *sub = *iter;
306 andreas 2829
        sub->setParent(btHandle);
279 andreas 2830
 
289 andreas 2831
        svItem.clear();
2832
        Button::TButton *button = sub->getFirstButton();
2833
        SkBitmap bitmap = sub->getBgImage();
280 andreas 2834
 
2835
        svItem.handle = sub->getHandle();
289 andreas 2836
        svItem.parent = btHandle;
280 andreas 2837
        svItem.width = sub->getWidth();
2838
        svItem.height = sub->getHeight();
281 andreas 2839
        svItem.bgcolor = TColor::getAMXColor(sub->getFillColor());
300 andreas 2840
        svItem.scrollbar = bt->getSubViewScrollbar();
2841
        svItem.scrollbarOffset = bt->getSubViewScrollbarOffset();
2842
        svItem.position = bt->getSubViewAnchor();
302 andreas 2843
        svItem.wrap = bt->getWrapSubViewPages();
280 andreas 2844
 
289 andreas 2845
        if (!bitmap.empty())
2846
            svItem.image.setBitmap((unsigned char *)bitmap.getPixels(), bitmap.info().width(), bitmap.info().height(), bitmap.info().bytesPerPixel());
280 andreas 2847
 
289 andreas 2848
        while (button)
280 andreas 2849
        {
300 andreas 2850
            button->drawButton(0, false, true);
289 andreas 2851
            svAtom.clear();
2852
            svAtom.handle = button->getHandle();
280 andreas 2853
            svAtom.parent = sub->getHandle();
289 andreas 2854
            svAtom.width = button->getWidth();
2855
            svAtom.height = button->getHeight();
2856
            svAtom.left = button->getLeftPosition();
2857
            svAtom.top = button->getTopPosition();
300 andreas 2858
            svAtom.bgcolor = TColor::getAMXColor(button->getFillColor(button->getActiveInstance()));
293 andreas 2859
            svAtom.bounding = button->getBounding();
289 andreas 2860
            Button::BITMAP_t bmap = button->getLastImage();
280 andreas 2861
 
289 andreas 2862
            if (bmap.buffer)
300 andreas 2863
                svAtom.image.setBitmap(bmap.buffer, bmap.width, bmap.height, (int)(bmap.rowBytes / bmap.width));
289 andreas 2864
 
280 andreas 2865
            svItem.atoms.push_back(svAtom);
289 andreas 2866
            button = sub->getNextButton();
280 andreas 2867
        }
2868
 
2869
        items.push_back(svItem);
279 andreas 2870
    }
281 andreas 2871
 
285 andreas 2872
    _addViewButtonItems(bt->getHandle(), items);
284 andreas 2873
 
2874
    if (_pageFinished)
306 andreas 2875
        _pageFinished(bt->getHandle());
279 andreas 2876
}
2877
 
300 andreas 2878
void TPageManager::updateSubViewItem(Button::TButton *bt)
2879
{
2880
    DECL_TRACER("TPageManager::updateSubViewItem(Button::TButton *bt)");
2881
 
303 andreas 2882
    if (!bt)
300 andreas 2883
        return;
2884
 
303 andreas 2885
    updview_mutex.lock();
2886
    mUpdateViews.push_back(bt);
2887
    updview_mutex.unlock();
2888
}
2889
 
2890
void TPageManager::_updateSubViewItem(Button::TButton *bt)
2891
{
2892
    DECL_TRACER("TPageManager::_updateSubViewItem(Button::TButton *bt)");
2893
 
2894
    if (!mPageList || !_updateViewButtonItem)
2895
        return;
2896
 
300 andreas 2897
    // The parent of this kind of button is always the button of type subview.
2898
    // If we take the parent handle and extract the page ID (upper 16 bits)
2899
    // we get the page ID of the subpage or page ID of the page the button is
2900
    // ordered to.
2901
    int pageID = (bt->getParent() >> 16) & 0x0000ffff;
306 andreas 2902
    ulong parent = 0;
300 andreas 2903
    Button::TButton *button = nullptr;
2904
    PGSUBVIEWITEM_T item;
2905
    PGSUBVIEWATOM_T atom;
2906
    SkBitmap bitmap;
2907
    TPage *pg = nullptr;
2908
    TSubPage *sub = nullptr;
2909
 
2910
    if (pageID < REGULAR_SUBPAGE_START)     // Is it a page?
2911
    {
2912
        pg = getPage(pageID);
2913
 
2914
        if (!pg)
2915
        {
2916
            MSG_WARNING("Invalid page " << pageID << "!");
2917
            return;
2918
        }
2919
 
2920
        button = pg->getFirstButton();
2921
        bitmap = pg->getBgImage();
2922
 
2923
        item.handle = pg->getHandle();
2924
        item.parent = bt->getParent();
2925
        item.width = pg->getWidth();
2926
        item.height = pg->getHeight();
2927
        item.bgcolor = TColor::getAMXColor(pg->getFillColor());
2928
    }
2929
    else
2930
    {
2931
        sub = getSubPage(pageID);
2932
 
2933
        if (!sub)
2934
        {
2935
            MSG_WARNING("Couldn't find the subpage " << pageID << "!");
2936
            return;
2937
        }
2938
 
306 andreas 2939
        parent = sub->getParent();
300 andreas 2940
        button = sub->getFirstButton();
2941
        bitmap = sub->getBgImage();
2942
 
2943
        item.handle = sub->getHandle();
2944
        item.parent = bt->getParent();
2945
        item.width = sub->getWidth();
2946
        item.height = sub->getHeight();
303 andreas 2947
        item.position = bt->getSubViewAnchor();
300 andreas 2948
        item.bgcolor = TColor::getAMXColor(sub->getFillColor());
2949
    }
2950
 
2951
 
2952
    if (!bitmap.empty())
2953
        item.image.setBitmap((unsigned char *)bitmap.getPixels(), bitmap.info().width(), bitmap.info().height(), bitmap.info().bytesPerPixel());
2954
 
2955
    while (button)
2956
    {
2957
        atom.clear();
2958
        atom.handle = button->getHandle();
303 andreas 2959
        atom.parent = item.handle;
300 andreas 2960
        atom.width = button->getWidth();
2961
        atom.height = button->getHeight();
2962
        atom.left = button->getLeftPosition();
2963
        atom.top = button->getTopPosition();
2964
        atom.bgcolor = TColor::getAMXColor(button->getFillColor(button->getActiveInstance()));
2965
        atom.bounding = button->getBounding();
2966
        Button::BITMAP_t bmap = button->getLastImage();
2967
 
2968
        if (bmap.buffer)
2969
            atom.image.setBitmap(bmap.buffer, bmap.width, bmap.height, (int)(bmap.rowBytes / bmap.width));
2970
 
2971
        item.atoms.push_back(atom);
2972
        button = (pg ? pg->getNextButton() : sub->getNextButton());
2973
    }
2974
 
306 andreas 2975
    _updateViewButtonItem(item, parent);
300 andreas 2976
}
2977
 
192 andreas 2978
void TPageManager::updateActualPage()
2979
{
2980
    DECL_TRACER("TPageManager::updateActualPage()");
2981
 
2982
    if (!mActualPage)
2983
        return;
2984
 
2985
    TPage *pg = getPage(mActualPage);
2986
    Button::TButton *bt = pg->getFirstButton();
2987
 
2988
    while (bt)
2989
    {
2990
        bt->refresh();
2991
        bt = pg->getNextButton();
2992
    }
2993
}
2994
 
2995
void TPageManager::updateSubpage(int ID)
2996
{
2997
    DECL_TRACER("TPageManager::updateSubpage(int ID)");
2998
 
2999
    TSubPage *pg = getSubPage(ID);
3000
 
3001
    if (!pg)
3002
        return;
3003
 
3004
    vector<Button::TButton *> blist = pg->getAllButtons();
3005
    vector<Button::TButton *>::iterator iter;
3006
 
3007
    if (blist.empty())
3008
        return;
3009
 
3010
    for (iter = blist.begin(); iter != blist.end(); ++iter)
3011
    {
3012
        Button::TButton *bt = *iter;
3013
        bt->refresh();
3014
    }
3015
}
3016
 
3017
void TPageManager::updateSubpage(const std::string &name)
3018
{
3019
    DECL_TRACER("TPageManager::updateSubpage(const std::string &name)");
3020
 
3021
    TSubPage *pg = getSubPage(name);
3022
 
3023
    if (!pg)
3024
        return;
3025
 
3026
    vector<Button::TButton *> blist = pg->getAllButtons();
3027
    vector<Button::TButton *>::iterator iter;
3028
 
3029
    if (blist.empty())
3030
        return;
3031
 
3032
    for (iter = blist.begin(); iter != blist.end(); ++iter)
3033
    {
3034
        Button::TButton *bt = *iter;
3035
        bt->refresh();
3036
    }
3037
}
3038
 
3 andreas 3039
/******************** Internal private methods *********************/
3040
 
3041
PAGELIST_T TPageManager::findPage(const std::string& name)
3042
{
3043
    DECL_TRACER("TPageManager::findPage(const std::string& name)");
3044
 
194 andreas 3045
    vector<PAGELIST_T> pageList;
3 andreas 3046
 
194 andreas 3047
    if (!mSetupActive)
3048
        pageList = mPageList->getPagelist();
3049
    else
3050
        pageList = mPageList->getSystemPagelist();
3051
 
83 andreas 3052
    if (pageList.size() > 0)
3 andreas 3053
    {
83 andreas 3054
        vector<PAGELIST_T>::iterator pgIter;
3055
 
118 andreas 3056
        for (pgIter = pageList.begin(); pgIter != pageList.end(); ++pgIter)
83 andreas 3057
        {
3058
            if (pgIter->name.compare(name) == 0)
3059
                return *pgIter;
3060
        }
3 andreas 3061
    }
3062
 
194 andreas 3063
    MSG_WARNING("Page " << name << " not found!");
3 andreas 3064
    return PAGELIST_T();
3065
}
3066
 
3067
PAGELIST_T TPageManager::findPage(int ID)
3068
{
3069
    DECL_TRACER("TPageManager::findPage(int ID)");
3070
 
206 andreas 3071
    vector<PAGELIST_T> pageList = (ID < SYSTEM_PAGE_START ? mPageList->getPagelist() : mPageList->getSystemPagelist());
3 andreas 3072
 
83 andreas 3073
    if (pageList.size() > 0)
3 andreas 3074
    {
83 andreas 3075
        vector<PAGELIST_T>::iterator pgIter;
3076
 
118 andreas 3077
        for (pgIter = pageList.begin(); pgIter != pageList.end(); ++pgIter)
83 andreas 3078
        {
3079
            if (pgIter->pageID == ID)
3080
                return *pgIter;
3081
        }
3 andreas 3082
    }
3083
 
3084
    return PAGELIST_T();
3085
}
3086
 
3087
SUBPAGELIST_T TPageManager::findSubPage(const std::string& name)
3088
{
3089
    DECL_TRACER("TPageManager::findSubPage(const std::string& name)");
3090
 
348 andreas 3091
    vector<SUBPAGELIST_T> pageList = (mSetupActive ? mPageList->getSystemSupPageList() : mPageList->getSubPageList());
3 andreas 3092
 
83 andreas 3093
    if (pageList.size() > 0)
3 andreas 3094
    {
83 andreas 3095
        vector<SUBPAGELIST_T>::iterator pgIter;
3096
 
118 andreas 3097
        for (pgIter = pageList.begin(); pgIter != pageList.end(); ++pgIter)
83 andreas 3098
        {
3099
            if (pgIter->name.compare(name) == 0)
3100
                return *pgIter;
3101
        }
3 andreas 3102
    }
3103
 
3104
    return SUBPAGELIST_T();
3105
}
3106
 
3107
SUBPAGELIST_T TPageManager::findSubPage(int ID)
3108
{
3109
    DECL_TRACER("TPageManager::findSubPage(int ID)");
3110
 
348 andreas 3111
    vector<SUBPAGELIST_T> pageList = (ID < SYSTEM_PAGE_START ? mPageList->getSubPageList() : mPageList->getSystemSupPageList());
3 andreas 3112
 
83 andreas 3113
    if (pageList.size() > 0)
3 andreas 3114
    {
83 andreas 3115
        vector<SUBPAGELIST_T>::iterator pgIter;
3116
 
118 andreas 3117
        for (pgIter = pageList.begin(); pgIter != pageList.end(); ++pgIter)
83 andreas 3118
        {
3119
            if (pgIter->pageID == ID)
3120
                return *pgIter;
3121
        }
3 andreas 3122
    }
3123
 
3124
    return SUBPAGELIST_T();
3125
}
3126
 
3127
bool TPageManager::addPage(TPage* pg)
3128
{
3129
    DECL_TRACER("TPageManager::addPage(TPage* pg)");
3130
 
3131
    if (!pg)
3132
    {
3133
        MSG_ERROR("Parameter is NULL!");
3134
        TError::setError();
3135
        return false;
3136
    }
3137
 
3138
    PCHAIN_T *chain = new PCHAIN_T;
3139
    chain->page = pg;
5 andreas 3140
    chain->next = nullptr;
3 andreas 3141
 
3142
    if (mPchain)
3143
    {
3144
        PCHAIN_T *p = mPchain;
3145
 
3146
        while (p->next)
3147
            p = p->next;
3148
 
3149
        p->next = chain;
3150
    }
3151
    else
14 andreas 3152
    {
3 andreas 3153
        mPchain = chain;
14 andreas 3154
        setPChain(mPchain);
3155
    }
3 andreas 3156
 
156 andreas 3157
//    MSG_DEBUG("Added page " << chain->page->getName());
3 andreas 3158
    return true;
3159
}
3160
 
3161
bool TPageManager::addSubPage(TSubPage* pg)
3162
{
3163
    DECL_TRACER("TPageManager::addSubPage(TSubPage* pg)");
3164
 
3165
    if (!pg)
3166
    {
3167
        MSG_ERROR("Parameter is NULL!");
3168
        TError::setError();
3169
        return false;
3170
    }
3171
 
14 andreas 3172
    if (haveSubPage(pg->getNumber()))
3173
    {
3174
        MSG_ERROR("Subpage " << pg->getNumber() << ", " << pg->getName() << " is already in chain!");
3175
        return false;
3176
    }
3177
 
3 andreas 3178
    SPCHAIN_T *chain = new SPCHAIN_T;
3179
    chain->page = pg;
5 andreas 3180
    chain->next = nullptr;
3 andreas 3181
 
3182
    if (mSPchain)
3183
    {
3184
        SPCHAIN_T *p = mSPchain;
3185
 
3186
        while (p->next)
3187
            p = p->next;
3188
 
3189
        p->next = chain;
3190
    }
3191
    else
14 andreas 3192
    {
3 andreas 3193
        mSPchain = chain;
14 andreas 3194
        setSPChain(mSPchain);
3195
    }
3 andreas 3196
 
3197
    return true;
3198
}
4 andreas 3199
 
11 andreas 3200
void TPageManager::dropAllPages()
3201
{
3202
    DECL_TRACER("TPageManager::dropAllPages()");
3203
 
3204
    PCHAIN_T *pg = mPchain;
3205
    PCHAIN_T *next = nullptr;
3206
 
3207
    while (pg)
3208
    {
3209
        next = pg->next;
3210
 
3211
        if (pg->page)
3212
        {
3213
            if (_callDropPage)
3214
                _callDropPage((pg->page->getNumber() << 16) & 0xffff0000);
3215
 
3216
            delete pg->page;
3217
        }
3218
 
3219
        delete pg;
3220
        pg = next;
3221
    }
14 andreas 3222
 
3223
    mPchain = nullptr;
3224
    setPChain(mPchain);
11 andreas 3225
}
3226
 
3227
void TPageManager::dropAllSubPages()
3228
{
3229
    DECL_TRACER("TPageManager::dropAllSubPages()");
3230
 
3231
    SPCHAIN_T *spg = mSPchain;
3232
    SPCHAIN_T *next;
3233
 
3234
    while (spg)
3235
    {
3236
        next = spg->next;
3237
 
3238
        if (spg->page)
3239
        {
3240
            if (_callDropSubPage)
350 andreas 3241
                _callDropSubPage((spg->page->getNumber() << 16) & 0xffff0000, spg->page->getParent());
11 andreas 3242
 
3243
            delete spg->page;
3244
        }
3245
 
3246
        delete spg;
3247
        spg = next;
3248
    }
14 andreas 3249
 
3250
    mSPchain = nullptr;
3251
    setSPChain(mSPchain);
11 andreas 3252
}
3253
 
44 andreas 3254
bool TPageManager::destroyAll()
3255
{
3256
    DECL_TRACER("TPageManager::destroyAll()");
3257
 
3258
    dropAllSubPages();
3259
    dropAllPages();
3260
    mActualPage = 0;
3261
    mPreviousPage = 0;
3262
    mActualGroupName.clear();
3263
 
3264
    if (mPageList)
3265
    {
3266
        delete mPageList;
3267
        mPageList = nullptr;
3268
    }
3269
 
3270
    if (mTSettings)
3271
    {
3272
        delete mTSettings;
3273
        mTSettings = nullptr;
3274
    }
3275
 
194 andreas 3276
    if (mSystemSettings)
3277
    {
3278
        delete mSystemSettings;
3279
        mSystemSettings = nullptr;
3280
    }
3281
 
44 andreas 3282
    if (mPalette)
3283
    {
3284
        delete mPalette;
3285
        mPalette = nullptr;
3286
    }
3287
 
3288
    if (mFonts)
3289
    {
3290
        delete mFonts;
3291
        mFonts = nullptr;
3292
    }
3293
 
3294
    if (mExternal)
3295
    {
3296
        delete mExternal;
3297
        mExternal = nullptr;
3298
    }
3299
 
3300
    if (gPrjResources)
3301
    {
3302
        delete gPrjResources;
3303
        gPrjResources = nullptr;
3304
    }
3305
 
3306
    if (gIcons)
3307
    {
3308
        delete gIcons;
3309
        gIcons = nullptr;
3310
    }
3311
 
3312
    if (TError::isError())
3313
        return false;
3314
 
3315
    return true;
3316
}
3317
 
150 andreas 3318
bool TPageManager::overlap(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2)
3319
{
3320
    DECL_TRACER("TPageManager::overlap(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2)");
3321
 
3322
    struct point
3323
    {
3324
        int x;
3325
        int y;
3326
    };
3327
 
3328
    struct point l1, r1, l2, r2;
3329
 
3330
    l1.x = x1;
3331
    l1.y = y1;
3332
    r1.x = x1 + w1;
3333
    r1.y = y1 + h1;
3334
 
3335
    l2.x = x2;
3336
    l2.y = y2;
3337
    r2.x = x2 + w2;
3338
    r2.y = y2 + h2;
3339
 
3340
    if (l1.x == r1.x || l1.y == r1.y || l2.x == r2.x || l2.y == r2.y)
3341
    {
3342
        // the line cannot have positive overlap
3343
        return false;
3344
    }
3345
 
183 andreas 3346
    return std::max(l1.x, l2.x) < std::min(r1.x, r2.x) &&
150 andreas 3347
           std::max(l1.y, l2.y) < std::min(r1.y, r2.y);
3348
}
3349
 
51 andreas 3350
Button::TButton *TPageManager::findButton(ulong handle)
3351
{
3352
    DECL_TRACER("TPageManager::findButton(ulong handle)");
3353
 
209 andreas 3354
    if (!handle)
3355
        return nullptr;
3356
 
51 andreas 3357
    TPage *pg = getPage(mActualPage);
3358
 
3359
    if (!pg)
3360
        return nullptr;
3361
 
3362
    vector<Button::TButton *> pgBtList = pg->getAllButtons();
3363
    vector<Button::TButton *>::iterator iter;
83 andreas 3364
 
3365
    if (pgBtList.size() > 0)
51 andreas 3366
    {
83 andreas 3367
        // First we look into the elements of the page
3368
        for (iter = pgBtList.begin(); iter != pgBtList.end(); ++iter)
3369
        {
3370
            Button::TButton *bt = *iter;
51 andreas 3371
 
83 andreas 3372
            if (bt->getHandle() == handle)
3373
                return bt;
3374
        }
51 andreas 3375
    }
3376
 
3377
    // We've not found the wanted element in the elements of the page. So
3378
    // we're looking at the elements of the subpages.
3379
    TSubPage *sp = pg->getFirstSubPage();
3380
 
3381
    if (!sp)
3382
        return nullptr;
3383
 
3384
    while (sp)
3385
    {
3386
        vector<Button::TButton *> spBtList = sp->getAllButtons();
3387
 
83 andreas 3388
        if (spBtList.size() > 0)
51 andreas 3389
        {
83 andreas 3390
            for (iter = spBtList.begin(); iter != spBtList.end(); ++iter)
3391
            {
3392
                Button::TButton *bt = *iter;
51 andreas 3393
 
83 andreas 3394
                if (bt->getHandle() == handle)
3395
                    return bt;
3396
            }
51 andreas 3397
        }
3398
 
3399
        sp = pg->getNextSubPage();
3400
    }
3401
 
3402
    return nullptr;
3403
}
3404
 
428 andreas 3405
/**
3406
 * @brief Find a bargraph
3407
 * The method can search for a bargraph on a particular page or subpage defined
3408
 * by \b parent. if no page or subpage defined, it searches on the actual page
3409
 * or subpage.
3410
 * If it finds a bargraph it returns the pointer to it. Otherwise a nullptr is
3411
 * returned.
3412
 *
3413
 * @param lp        The brgraph port number.
3414
 * @param lv        The bargraph code number.
3415
 * @param parent    The parent handle of the bargraph.
3416
 *
3417
 * @return If the wanted bargraph with the parent handle exists, the pointer to
3418
 * it is returned. Otherwise it return a \b nullptr.
3419
 */
427 andreas 3420
Button::TButton *TPageManager::findBargraph(int lp, int lv, ulong parent)
426 andreas 3421
{
427 andreas 3422
    DECL_TRACER("TPageManager::findBargraph(int lp, int lv, ulong parent)");
426 andreas 3423
 
428 andreas 3424
    int page = (parent >> 16) & 0x0000ffff;
3425
    vector<Button::TButton *>::iterator iter;
426 andreas 3426
 
428 andreas 3427
    if (!page)
3428
    {
3429
        page = mActualPage;
426 andreas 3430
 
428 andreas 3431
        if (!page)
3432
        {
3433
            MSG_WARNING("No valid active page!");
3434
            return nullptr;
3435
        }
3436
    }
426 andreas 3437
 
428 andreas 3438
    MSG_DEBUG("Searching for bargraph " << lp << ":" << lv << " on page " << page);
3439
 
427 andreas 3440
    if (page < REGULAR_SUBPAGE_START)
426 andreas 3441
    {
428 andreas 3442
        TPage *pg = getPage(mActualPage);
3443
 
3444
        if (!pg)
3445
            return nullptr;
3446
 
427 andreas 3447
        vector<Button::TButton *> pgBtList = pg->getAllButtons();
3448
        MSG_DEBUG("Found " << pgBtList.size() << " buttons.");
3449
 
3450
        if (pgBtList.size() > 0)
426 andreas 3451
        {
427 andreas 3452
            // First we look into the elements of the page
3453
            for (iter = pgBtList.begin(); iter != pgBtList.end(); ++iter)
3454
            {
3455
                Button::TButton *bt = *iter;
426 andreas 3456
 
427 andreas 3457
                if (bt->getButtonType() == BARGRAPH && bt->getLevelPort() == lp && bt->getLevelChannel() == lv && bt->getParent() == parent)
3458
                {
428 andreas 3459
                    MSG_DEBUG("Found bargraph LP:" << lp << ", LV:" << lv << " on page " << page);
427 andreas 3460
                    return bt;
3461
                }
3462
            }
426 andreas 3463
        }
427 andreas 3464
 
428 andreas 3465
        MSG_WARNING("No bargraph " << lp << ":" << lv << " on page " << page);
427 andreas 3466
        return nullptr;
426 andreas 3467
    }
3468
 
3469
    // We've not found the wanted element in the elements of the page. So
428 andreas 3470
    // we're looking at the elements of the subpage.
3471
    TSubPage *sp = getSubPage(page);
426 andreas 3472
 
3473
    if (!sp)
428 andreas 3474
    {
3475
        MSG_WARNING("Found no subpage " << page);
426 andreas 3476
        return nullptr;
428 andreas 3477
    }
426 andreas 3478
 
428 andreas 3479
    vector<Button::TButton *> spBtList = sp->getAllButtons();
3480
    MSG_DEBUG("Found " << spBtList.size() << " buttons.");
3481
 
3482
    if (spBtList.size() > 0)
426 andreas 3483
    {
428 andreas 3484
        for (iter = spBtList.begin(); iter != spBtList.end(); ++iter)
3485
        {
3486
            Button::TButton *bt = *iter;
426 andreas 3487
 
428 andreas 3488
            if (bt->getButtonType() == BARGRAPH && bt->getLevelPort() == lp && bt->getLevelChannel() == lv && bt->getParent() == parent)
426 andreas 3489
            {
428 andreas 3490
                MSG_DEBUG("Found bargraph LP:" << lp << ", LV:" << lv << " on subpage " << page);
3491
                return bt;
426 andreas 3492
            }
3493
        }
3494
    }
3495
 
428 andreas 3496
    MSG_WARNING("No bargraph " << lp << ":" << lv << " on subpage " << page);
426 andreas 3497
    return nullptr;
3498
}
3499
 
4 andreas 3500
TPage *TPageManager::getActualPage()
3501
{
168 andreas 3502
    DECL_TRACER("TPageManager::getActualPage()");
3503
 
4 andreas 3504
    return getPage(mActualPage);
3505
}
3506
 
3507
TSubPage *TPageManager::getFirstSubPage()
3508
{
3509
    DECL_TRACER("TPageManager::getFirstSubPage()");
168 andreas 3510
 
349 andreas 3511
    mLastSubPage = 0;
4 andreas 3512
    TPage *pg = getPage(mActualPage);
3513
 
3514
    if (!pg)
3515
        return nullptr;
3516
 
349 andreas 3517
    map<int, TSubPage *> sp = pg->getSortedSubpages(true);
3518
 
3519
    if (!sp.empty())
3520
    {
3521
        map<int, TSubPage *>::iterator iter = sp.begin();
3522
        mLastSubPage = iter->first;
3523
        return iter->second;
3524
    }
3525
 
3526
    return nullptr;
4 andreas 3527
}
3528
 
3529
TSubPage *TPageManager::getNextSubPage()
3530
{
3531
    DECL_TRACER("TPageManager::getNextSubPage()");
3532
 
3533
    TPage *pg = getPage(mActualPage);
3534
 
3535
    if (pg)
349 andreas 3536
    {
3537
        map<int, TSubPage *> sp = pg->getSortedSubpages();
4 andreas 3538
 
349 andreas 3539
        if (sp.empty())
3540
        {
3541
            mLastSubPage = 0;
3542
            return nullptr;
3543
        }
3544
        else
3545
        {
3546
            map<int, TSubPage *>::iterator iter = sp.find(mLastSubPage);
3547
 
3548
            if (iter != sp.end())
3549
            {
3550
                iter++;
3551
 
3552
                if (iter != sp.end())
3553
                {
3554
                    mLastSubPage = iter->first;
3555
                    return iter->second;
3556
                }
3557
            }
3558
        }
3559
    }
3560
 
3561
    mLastSubPage = 0;
4 andreas 3562
    return nullptr;
3563
}
10 andreas 3564
 
154 andreas 3565
TSubPage *TPageManager::getPrevSubPage()
3566
{
3567
    DECL_TRACER("TPageManager::getPrevSubPage()");
3568
 
3569
    TPage *pg = getPage(mActualPage);
3570
 
3571
    if (pg)
349 andreas 3572
    {
3573
        map<int, TSubPage *> sp = pg->getSortedSubpages();
154 andreas 3574
 
349 andreas 3575
        if (sp.empty())
3576
        {
3577
            mLastSubPage = 0;
3578
            return nullptr;
3579
        }
3580
        else
3581
        {
3582
            map<int, TSubPage *>::iterator iter = sp.find(mLastSubPage);
3583
 
3584
            if (iter != sp.end() && iter != sp.begin())
3585
            {
3586
                iter--;
3587
                mLastSubPage = iter->first;
3588
                return iter->second;
3589
            }
3590
 
3591
            MSG_DEBUG("Page " << mLastSubPage << " not found!");
3592
        }
3593
    }
3594
 
3595
    mLastSubPage = 0;
154 andreas 3596
    return nullptr;
3597
}
3598
 
3599
TSubPage *TPageManager::getLastSubPage()
3600
{
3601
    DECL_TRACER("TPageManager::getLastSubPage()");
3602
 
349 andreas 3603
    mLastSubPage = 0;
154 andreas 3604
    TPage *pg = getPage(mActualPage);
3605
 
3606
    if (pg)
3607
    {
349 andreas 3608
        map<int, TSubPage *> sp = pg->getSortedSubpages(true);
3609
 
3610
        if (sp.empty())
3611
            return nullptr;
3612
        else
3613
        {
3614
            map<int, TSubPage *>::iterator iter = sp.end();
3615
            iter--;
3616
            mLastSubPage = iter->first;
3617
            return iter->second;
3618
        }
154 andreas 3619
    }
3620
    else
3621
    {
3622
        MSG_WARNING("Actual page " << mActualPage << " not found!");
3623
    }
3624
 
3625
    return nullptr;
3626
}
3627
 
11 andreas 3628
TSubPage *TPageManager::getFirstSubPageGroup(const string& group)
3629
{
3630
    DECL_TRACER("TPageManager::getFirstSubPageGroup(const string& group)");
3631
 
14 andreas 3632
    if (group.empty())
3633
    {
3634
        MSG_WARNING("Empty group name is invalid. Ignoring it!");
3635
        mActualGroupName.clear();
3636
        mActualGroupPage = nullptr;
3637
        return nullptr;
3638
    }
3639
 
11 andreas 3640
    mActualGroupName = group;
3641
    TSubPage *pg = getFirstSubPage();
3642
 
3643
    while (pg)
3644
    {
14 andreas 3645
        MSG_DEBUG("Evaluating group " << pg->getGroupName() << " with " << group);
3646
 
11 andreas 3647
        if (pg->getGroupName().compare(group) == 0)
3648
        {
3649
            mActualGroupPage = pg;
3650
            return pg;
3651
        }
3652
 
3653
        pg = getNextSubPage();
3654
    }
3655
 
3656
    mActualGroupName.clear();
3657
    mActualGroupPage = nullptr;
3658
    return nullptr;
3659
}
3660
 
3661
TSubPage *TPageManager::getNextSubPageGroup()
3662
{
3663
    DECL_TRACER("TPageManager::getNextSubPageGroup()");
3664
 
3665
    if (mActualGroupName.empty())
3666
        return nullptr;
3667
 
3668
    TSubPage *pg = getFirstSubPage();
3669
    bool found = false;
3670
 
3671
    while (pg)
3672
    {
14 andreas 3673
        MSG_DEBUG("Evaluating group " << pg->getGroupName() << " with " << mActualGroupName);
3674
 
3675
        if (!found && pg == mActualGroupPage)
11 andreas 3676
        {
3677
            pg = getNextSubPage();
14 andreas 3678
            found = true;
11 andreas 3679
            continue;
3680
        }
3681
 
14 andreas 3682
        if (found && pg->getGroupName().compare(mActualGroupName) == 0)
11 andreas 3683
        {
3684
            mActualGroupPage = pg;
3685
            return pg;
3686
        }
3687
 
3688
        pg = getNextSubPage();
3689
    }
3690
 
3691
    mActualGroupName.clear();
3692
    mActualGroupPage = nullptr;
3693
    return nullptr;
3694
}
3695
 
3696
TSubPage *TPageManager::getNextSubPageGroup(const string& group, TSubPage* pg)
3697
{
3698
    DECL_TRACER("TPageManager::getNextSubPageGroup(const string& group, TSubPage* pg)");
3699
 
3700
    if (group.empty() || !pg)
3701
        return nullptr;
3702
 
3703
    TSubPage *page = getFirstSubPage();
3704
    bool found = false;
3705
 
3706
    while (page)
3707
    {
14 andreas 3708
        MSG_DEBUG("Evaluating group " << pg->getGroupName() << " with " << group);
3709
 
3710
        if (!found && pg == page)
11 andreas 3711
        {
3712
            page = getNextSubPage();
14 andreas 3713
            found = true;
11 andreas 3714
            continue;
3715
        }
3716
 
14 andreas 3717
        if (found && page->getGroupName().compare(group) == 0)
11 andreas 3718
            return page;
3719
 
3720
        page = getNextSubPage();
3721
    }
3722
 
3723
    return nullptr;
3724
}
3725
 
3726
TSubPage *TPageManager::getTopPage()
3727
{
3728
    DECL_TRACER("TPageManager::getTopPage()");
3729
 
3730
    // Scan for all occupied regions
3731
    vector<RECT_T> regions;
3732
 
3733
    TSubPage *pg = getFirstSubPage();
3734
 
3735
    while (pg)
3736
    {
3737
        RECT_T r = pg->getRegion();
3738
        regions.push_back(r);
3739
        pg = getNextSubPage();
3740
    }
3741
 
3742
    // Now scan all pages against all regions to find the top most
3743
    pg = getFirstSubPage();
3744
    TSubPage *top = nullptr;
3745
    int zPos = 0;
3746
 
3747
    while (pg)
3748
    {
3749
        RECT_T r = pg->getRegion();
3750
 
83 andreas 3751
        if (regions.size() > 0)
11 andreas 3752
        {
83 andreas 3753
            vector<RECT_T>::iterator iter;
3754
            int zo = 0;
11 andreas 3755
 
118 andreas 3756
            for (iter = regions.begin(); iter != regions.end(); ++iter)
83 andreas 3757
            {
3758
                if (doOverlap(*iter, r) && zPos > zo)
3759
                    top = pg;
3760
 
3761
                zo++;
3762
            }
11 andreas 3763
        }
3764
 
3765
        pg = getNextSubPage();
3766
        zPos++;
3767
    }
3768
 
3769
    return top;
3770
}
3771
 
3772
TSubPage *TPageManager::getCoordMatch(int x, int y)
3773
{
3774
    DECL_TRACER("TPageManager::getCoordMatch(int x, int y)");
3775
 
26 andreas 3776
    int realX = x;
3777
    int realY = y;
3778
 
11 andreas 3779
    // Reverse order of pages
154 andreas 3780
    TSubPage *pg = getLastSubPage();
11 andreas 3781
 
154 andreas 3782
    // Iterate in reverse order through array
11 andreas 3783
    while (pg)
3784
    {
154 andreas 3785
        if (!pg->isVisible() || pg->getZOrder() == ZORDER_INVALID)
151 andreas 3786
        {
154 andreas 3787
            pg = getPrevSubPage();
3788
            continue;
151 andreas 3789
        }
14 andreas 3790
 
154 andreas 3791
        MSG_DEBUG("Scanning subpage (Z: " << pg->getZOrder() << "): " << pg->getNumber() << ", " << pg->getName());
3792
        RECT_T r = pg->getRegion();
11 andreas 3793
 
154 andreas 3794
        if (r.left <= realX && (r.left + r.width) >= realX &&
3795
            r.top <= realY && (r.top + r.height) >= realY)
11 andreas 3796
        {
154 andreas 3797
            MSG_DEBUG("Click matches subpage " << pg->getNumber() << " (" << pg->getName() << ")");
3798
            return pg;
3799
        }
83 andreas 3800
 
154 andreas 3801
        pg = getPrevSubPage();
11 andreas 3802
    }
3803
 
3804
    return nullptr;
3805
}
3806
 
40 andreas 3807
Button::TButton *TPageManager::getCoordMatchPage(int x, int y)
3808
{
3809
    DECL_TRACER("TPageManager::getCoordMatchPage(int x, int y)");
3810
 
3811
    TPage *page = getActualPage();
3812
 
3813
    if (page)
3814
    {
150 andreas 3815
        Button::TButton *bt = page->getLastButton();
40 andreas 3816
 
3817
        while (bt)
3818
        {
150 andreas 3819
            bool clickable = bt->isClickable();
3820
            MSG_DEBUG("Button: " << bt->getButtonIndex() << ", l: " << bt->getLeftPosition() << ", t: " << bt->getTopPosition() << ", r: " << (bt->getLeftPosition() + bt->getWidth()) << ", b: " << (bt->getTopPosition() + bt->getHeight()) << ", x: " << x << ", y: " << y << ", " << (clickable ? "CLICKABLE" : "NOT CLICKABLE"));
40 andreas 3821
 
150 andreas 3822
            if (!clickable)
146 andreas 3823
            {
150 andreas 3824
                bt = page->getPreviousButton();
146 andreas 3825
                continue;
3826
            }
3827
 
40 andreas 3828
            if (bt->getLeftPosition() <= x && (bt->getLeftPosition() + bt->getWidth()) >= x &&
3829
                bt->getTopPosition() <= y && (bt->getTopPosition() + bt->getHeight()) >= y)
3830
            {
154 andreas 3831
                if (!bt->isClickable(x - bt->getLeftPosition(), y - bt->getTopPosition()))
3832
                {
3833
                    bt = page->getPreviousButton();
3834
                    continue;
3835
                }
3836
 
40 andreas 3837
                MSG_DEBUG("Click matches button " << bt->getButtonIndex() << " (" << bt->getButtonName() << ")");
3838
                return bt;
3839
            }
3840
 
150 andreas 3841
            bt = page->getPreviousButton();
40 andreas 3842
        }
3843
    }
3844
 
3845
    return nullptr;
3846
}
3847
 
11 andreas 3848
bool TPageManager::doOverlap(RECT_T r1, RECT_T r2)
3849
{
3850
    DECL_TRACER("TPageManager::doOverlap(RECT_T r1, RECT_T r2)");
3851
 
3852
    // If one rectangle is on left side of other
3853
    if (r1.left >= r2.left || r2.left >= r1.left)
3854
        return false;
3855
 
3856
    // If one rectangle is above other
3857
    if (r1.top <= r2.top || r2.top <= r1.top)
3858
        return false;
3859
 
3860
    return true;
3861
}
3862
 
14 andreas 3863
bool TPageManager::havePage(const string& name)
11 andreas 3864
{
14 andreas 3865
    DECL_TRACER("TPageManager::havePage(const string& name)");
11 andreas 3866
 
14 andreas 3867
    if (name.empty())
3868
        return false;
3869
 
3870
    PCHAIN_T *pg = mPchain;
3871
 
3872
    while (pg)
3873
    {
3874
        if (pg->page && pg->page->getName().compare(name) == 0)
3875
            return true;
3876
 
3877
        pg = pg->next;
3878
    }
3879
 
3880
    return false;
3881
}
3882
 
3883
bool TPageManager::haveSubPage(const string& name)
3884
{
3885
    DECL_TRACER("TPageManager::haveSubPage(const string& name)");
3886
 
3887
    if (name.empty())
3888
        return false;
3889
 
11 andreas 3890
    SPCHAIN_T *pg = mSPchain;
3891
 
3892
    while (pg)
3893
    {
14 andreas 3894
        if (pg->page && pg->page->getName().compare(name) == 0)
3895
        {
3896
            MSG_DEBUG("Subpage " << pg->page->getNumber() << ", " << name << " found.");
3897
            return true;
3898
        }
3899
 
3900
        pg = pg->next;
3901
    }
3902
 
3903
    MSG_DEBUG("Subpage " << name << " not found.");
3904
    return false;
3905
}
3906
 
3907
bool TPageManager::haveSubPage(int id)
3908
{
3909
    DECL_TRACER("TPageManager::haveSubPage(int id)");
3910
 
3911
    SPCHAIN_T *pg = mSPchain;
3912
 
3913
    while (pg)
3914
    {
3915
        if (pg->page && pg->page->getNumber() == id)
3916
        {
3917
            MSG_DEBUG("Subpage " << pg->page->getNumber() << ", " << pg->page->getName() << " found.");
3918
            return true;
3919
        }
3920
 
3921
        pg = pg->next;
3922
    }
3923
 
3924
    MSG_DEBUG("Subpage " << id << " not found.");
3925
    return false;
3926
}
3927
 
3928
bool TPageManager::haveSubPage(const string& page, const string& name)
3929
{
3930
    DECL_TRACER("TPageManager::haveSubPage(const string& page, const string& name)");
3931
 
3932
    TPage *pg = getPage(page);
3933
 
3934
    if (!pg)
3935
        return false;
3936
 
3937
    TSubPage *spg = pg->getFirstSubPage();
3938
 
3939
    while (spg)
3940
    {
3941
        if (spg->getName().compare(name) == 0)
3942
        {
3943
            MSG_DEBUG("Subpage " << spg->getNumber() << ", " << name << " found.");
3944
            return true;
3945
        }
3946
 
3947
        spg = pg->getNextSubPage();
3948
    }
3949
 
3950
    MSG_DEBUG("Subpage " << name << " not found on page " << page << ".");
3951
    return false;
3952
}
3953
 
3954
bool TPageManager::haveSubPage(const string& page, int id)
3955
{
3956
    DECL_TRACER("TPageManager::haveSubPage(const string& page, int id)");
3957
 
3958
    TPage *pg = getPage(page);
3959
 
3960
    if (!pg)
3961
        return false;
3962
 
3963
    TSubPage *spg = pg->getFirstSubPage();
3964
 
3965
    while (spg)
3966
    {
3967
        if (spg->getNumber() == id)
3968
        {
3969
            MSG_DEBUG("Subpage " << spg->getNumber() << ", " << spg->getName() << " found.");
3970
            return true;
3971
        }
3972
 
3973
        spg = pg->getNextSubPage();
3974
    }
3975
 
3976
    MSG_DEBUG("Subpage " << id << " on page " << page << " not found.");
3977
    return false;
3978
}
3979
 
3980
void TPageManager::closeGroup(const string& group)
3981
{
3982
    DECL_TRACER("TPageManager::closeGroup(const string& group)");
3983
 
3984
    SPCHAIN_T *pg = mSPchain;
3985
 
3986
    while (pg)
3987
    {
11 andreas 3988
        if (pg->page->getGroupName().compare(group) == 0 && pg->page->isVisible())
3989
        {
3990
            pg->page->regCallDropSubPage(_callDropSubPage);
3991
            pg->page->drop();
3992
            break;
3993
        }
3994
 
3995
        pg = pg->next;
3996
    }
3997
}
3998
 
14 andreas 3999
void TPageManager::showSubPage(const string& name)
4000
{
4001
    DECL_TRACER("TPageManager::showSubPage(const string& name)");
4002
 
4003
    if (name.empty())
349 andreas 4004
    {
4005
#if TESTMODE == 1
4006
        setScreenDone();
4007
#endif
14 andreas 4008
        return;
349 andreas 4009
    }
275 andreas 4010
 
152 andreas 4011
    TPage *page = nullptr;
4012
    TSubPage *pg = deliverSubPage(name, &page);
14 andreas 4013
 
96 andreas 4014
    if (!pg)
349 andreas 4015
    {
4016
#if TESTMODE == 1
4017
        setScreenDone();
4018
#endif
14 andreas 4019
        return;
349 andreas 4020
    }
14 andreas 4021
 
152 andreas 4022
    if (page)
350 andreas 4023
    {
4024
        pg->setParent(page->getHandle());
152 andreas 4025
        page->addSubPage(pg);
350 andreas 4026
    }
152 andreas 4027
 
14 andreas 4028
    string group = pg->getGroupName();
4029
 
4030
    if (!group.empty())
4031
    {
4032
        TSubPage *sub = getFirstSubPageGroup(group);
4033
 
4034
        while(sub)
4035
        {
4036
            if (sub->isVisible() && sub->getNumber() != pg->getNumber())
4037
                sub->drop();
4038
 
4039
            sub = getNextSubPageGroup(group, sub);
4040
        }
4041
    }
4042
 
150 andreas 4043
    if (pg->isVisible())
4044
    {
152 andreas 4045
        MSG_DEBUG("Page " << pg->getName() << " is already visible but maybe not on top.");
150 andreas 4046
 
4047
        TSubPage *sub = getFirstSubPage();
4048
        bool redraw = false;
4049
 
4050
        while (sub)
4051
        {
151 andreas 4052
            if (sub->isVisible() && pg->getZOrder() < sub->getZOrder() &&
4053
                overlap(sub->getLeft(), sub->getTop(), sub->getWidth(), sub->getHeight(),
150 andreas 4054
                pg->getLeft(), pg->getTop(), pg->getWidth(), pg->getHeight()))
4055
            {
4056
                MSG_DEBUG("Page " << sub->getName() << " is overlapping page " << pg->getName());
4057
                redraw = true;
4058
                break;
4059
            }
4060
 
4061
            sub = getNextSubPage();
4062
        }
4063
 
151 andreas 4064
        if (redraw && _toFront)
4065
        {
300 andreas 4066
            _toFront((uint)pg->getHandle());
151 andreas 4067
            pg->setZOrder(page->getNextZOrder());
349 andreas 4068
//            page->sortSubpages();
154 andreas 4069
            MSG_DEBUG("Setting new Z-order " << page->getActZOrder() << " on subpage " << pg->getName());
151 andreas 4070
        }
154 andreas 4071
        else if (redraw && !_toFront)
150 andreas 4072
            pg->drop();
4073
    }
4074
 
14 andreas 4075
    if (!pg->isVisible())
4076
    {
4077
        if (!page)
4078
        {
198 andreas 4079
            page = getPage(mActualPage);
4080
 
4081
            if (!page)
4082
            {
4083
                MSG_ERROR("No active page found! Internal error.");
4084
                return;
4085
            }
14 andreas 4086
        }
4087
 
4088
        if (!haveSubPage(pg->getNumber()) && !page->addSubPage(pg))
4089
            return;
4090
 
4091
        pg->setZOrder(page->getNextZOrder());
4092
 
4093
        if (_setSubPage)
26 andreas 4094
        {
4095
            int left = pg->getLeft();
4096
            int top = pg->getTop();
4097
            int width = pg->getWidth();
4098
            int height = pg->getHeight();
43 andreas 4099
#ifdef _SCALE_SKIA_
26 andreas 4100
            if (mScaleFactor != 1.0)
4101
            {
4102
                left = (int)((double)left * mScaleFactor);
4103
                top = (int)((double)top * mScaleFactor);
4104
                width = (int)((double)width * mScaleFactor);
4105
                height = (int)((double)height * mScaleFactor);
28 andreas 4106
                MSG_DEBUG("Scaled subpage: left=" << left << ", top=" << top << ", width=" << width << ", height=" << height);
26 andreas 4107
            }
43 andreas 4108
#endif
41 andreas 4109
            ANIMATION_t ani;
4110
            ani.showEffect = pg->getShowEffect();
4111
            ani.showTime = pg->getShowTime();
42 andreas 4112
            ani.hideEffect = pg->getHideEffect();
4113
            ani.hideTime = pg->getHideTime();
54 andreas 4114
            // Test for a timer on the page
4115
            if (pg->getTimeout() > 0)
4116
                pg->startTimer();
4117
 
418 andreas 4118
            _setSubPage(pg->getHandle(), page->getHandle(), left, top, width, height, ani, pg->isModal());
26 andreas 4119
        }
293 andreas 4120
 
4121
        pg->show();
14 andreas 4122
    }
4123
}
4124
 
198 andreas 4125
void TPageManager::showSubPage(int number, bool force)
4126
{
4127
    DECL_TRACER("TPageManager::showSubPage(int number, bool force)");
4128
 
4129
    if (number <= 0)
4130
        return;
4131
 
4132
    TPage *page = nullptr;
4133
    TSubPage *pg = deliverSubPage(number, &page);
4134
 
4135
    if (!pg)
4136
        return;
4137
 
4138
    if (page)
350 andreas 4139
    {
4140
        pg->setParent(page->getHandle());
198 andreas 4141
        page->addSubPage(pg);
350 andreas 4142
    }
198 andreas 4143
 
4144
    string group = pg->getGroupName();
4145
 
4146
    if (!group.empty())
4147
    {
4148
        TSubPage *sub = getFirstSubPageGroup(group);
4149
 
4150
        while(sub)
4151
        {
4152
            if (sub->isVisible() && sub->getNumber() != pg->getNumber())
4153
                sub->drop();
4154
 
4155
            sub = getNextSubPageGroup(group, sub);
4156
        }
4157
    }
4158
 
4159
    if (pg->isVisible() && !force)
4160
    {
4161
        MSG_DEBUG("Page " << pg->getName() << " is already visible but maybe not on top.");
4162
 
4163
        TSubPage *sub = getFirstSubPage();
4164
        bool redraw = false;
4165
 
4166
        while (sub)
4167
        {
4168
            if (sub->isVisible() && pg->getZOrder() < sub->getZOrder() &&
4169
                overlap(sub->getLeft(), sub->getTop(), sub->getWidth(), sub->getHeight(),
4170
                        pg->getLeft(), pg->getTop(), pg->getWidth(), pg->getHeight()))
4171
            {
4172
                MSG_DEBUG("Page " << sub->getName() << " is overlapping page " << pg->getName());
4173
                redraw = true;
4174
                break;
4175
            }
4176
 
4177
            sub = getNextSubPage();
4178
        }
4179
 
4180
        if (redraw && _toFront)
4181
        {
300 andreas 4182
            _toFront((uint)pg->getHandle());
198 andreas 4183
            pg->setZOrder(page->getNextZOrder());
4184
            page->sortSubpages();
4185
            MSG_DEBUG("Setting new Z-order " << page->getActZOrder() << " on subpage " << pg->getName());
4186
        }
4187
        else if (redraw && !_toFront)
4188
            pg->drop();
4189
    }
4190
 
4191
    if (!pg->isVisible() || force)
4192
    {
4193
        if (!page)
4194
        {
4195
            MSG_ERROR("No active page found! Internal error.");
4196
            return;
4197
        }
4198
 
4199
        if (!haveSubPage(pg->getNumber()) && !page->addSubPage(pg))
4200
            return;
4201
 
4202
        if (!pg->isVisible())
4203
            pg->setZOrder(page->getNextZOrder());
4204
 
4205
        if (_setSubPage)
4206
        {
4207
            int left = pg->getLeft();
4208
            int top = pg->getTop();
4209
            int width = pg->getWidth();
4210
            int height = pg->getHeight();
262 andreas 4211
#ifdef _SCALE_SKIA_
198 andreas 4212
            if (mScaleFactor != 1.0)
4213
            {
4214
                left = (int)((double)left * mScaleFactor);
4215
                top = (int)((double)top * mScaleFactor);
4216
                width = (int)((double)width * mScaleFactor);
4217
                height = (int)((double)height * mScaleFactor);
4218
                MSG_DEBUG("Scaled subpage: left=" << left << ", top=" << top << ", width=" << width << ", height=" << height);
4219
            }
262 andreas 4220
#endif
198 andreas 4221
            ANIMATION_t ani;
4222
            ani.showEffect = pg->getShowEffect();
4223
            ani.showTime = pg->getShowTime();
4224
            ani.hideEffect = pg->getHideEffect();
4225
            ani.hideTime = pg->getHideTime();
4226
            // Test for a timer on the page
4227
            if (pg->getTimeout() > 0)
4228
                pg->startTimer();
4229
 
418 andreas 4230
            _setSubPage(pg->getHandle(), page->getHandle(), left, top, width, height, ani, pg->isModal());
198 andreas 4231
        }
4232
    }
4233
 
4234
    pg->show();
4235
}
4236
 
14 andreas 4237
void TPageManager::hideSubPage(const string& name)
4238
{
4239
    DECL_TRACER("TPageManager::hideSubPage(const string& name)");
4240
 
4241
    if (name.empty())
335 andreas 4242
    {
4243
#if TESTMODE == 1
4244
        setScreenDone();
4245
#endif
14 andreas 4246
        return;
335 andreas 4247
    }
14 andreas 4248
 
4249
    TPage *page = getPage(mActualPage);
4250
 
4251
    if (!page)
4252
    {
4253
        MSG_ERROR("No active page found! Internal error.");
335 andreas 4254
#if TESTMODE == 1
4255
        setScreenDone();
4256
#endif
14 andreas 4257
        return;
4258
    }
4259
 
4260
    TSubPage *pg = getSubPage(name);
4261
 
4262
    if (pg)
4263
    {
4264
        pg->drop();
154 andreas 4265
        page->decZOrder();
14 andreas 4266
    }
4267
}
4268
 
299 andreas 4269
/**
4270
 * @brief TPageManager::runClickQueue - Processing mouse clicks
4271
 * The following method is starting a thread which tests a queue containing
4272
 * the mouse clicks. To not drain the CPU, it sleeps for a short time if there
4273
 * are no more events in the queue.
4274
 * If there is an entry in the queue, it copies it to a local struct and
4275
 * deletes it from the queue. It take always the oldest antry (first entry)
4276
 * and removes this entry from the queue until the queue is empty. This makes
4277
 * it to a FIFO (first in, first out).
4278
 * Depending on the state of the variable "coords" the method for mouse
4279
 * coordinate click is executed or the method for a handle.
4280
 * The thread runs as long as the variable "mClickQueueRun" is TRUE and the
4281
 * variable "prg_stopped" is FALSE.
4282
 */
4283
void TPageManager::runClickQueue()
4284
{
4285
    DECL_TRACER("TPageManager::runClickQueue()");
4286
 
4287
    if (mClickQueueRun)
4288
        return;
4289
 
4290
    mClickQueueRun = true;
4291
 
4292
    try
4293
    {
4294
        std::thread thr = std::thread([=] {
300 andreas 4295
            MSG_PROTOCOL("Thread \"TPageManager::runClickQueue()\" was started.");
4296
 
299 andreas 4297
            while (mClickQueueRun && !prg_stopped)
4298
            {
300 andreas 4299
                while (!mClickQueue.empty())
299 andreas 4300
                {
4301
#ifdef QT_DEBUG
300 andreas 4302
                    if (mClickQueue[0].coords)
4303
                        MSG_TRACE("TPageManager::runClickQueue() -- executing: _mouseEvent(" << mClickQueue[0].x << ", " << mClickQueue[0].y << ", " << (mClickQueue[0].pressed ? "TRUE" : "FALSE") << ")")
299 andreas 4304
                    else
300 andreas 4305
                        MSG_TRACE("TPageManager::runClickQueue() -- executing: _mouseEvent(" << handleToString(mClickQueue[0].handle) << ", " << (mClickQueue[0].pressed ? "TRUE" : "FALSE") << ")")
299 andreas 4306
#endif
409 andreas 4307
                    if (mClickQueue[0].eventType == _EVENT_MOUSE_CLICK)
4308
                    {
4309
                        if (mClickQueue[0].coords)
4310
                            _mouseEvent(mClickQueue[0].x, mClickQueue[0].y, mClickQueue[0].pressed);
4311
                        else
4312
                            _mouseEvent(mClickQueue[0].handle, mClickQueue[0].handle);
4313
                    }
4314
                    else  if (mClickQueue[0].eventType == _EVENT_MOUSE_MOVE)
4315
                        _mouseMoveEvent(mClickQueue[0].x, mClickQueue[0].y);
300 andreas 4316
 
299 andreas 4317
                    mClickQueue.erase(mClickQueue.begin()); // Remove first entry
4318
                }
4319
 
4320
                std::this_thread::sleep_for(std::chrono::microseconds(10));
4321
            }
4322
 
303 andreas 4323
            mClickQueueRun = false;
299 andreas 4324
            return;
4325
        });
4326
 
4327
        thr.detach();
4328
    }
4329
    catch (std::exception& e)
4330
    {
300 andreas 4331
        MSG_ERROR("Error starting a thread to handle the click queue: " << e.what());
299 andreas 4332
        mClickQueueRun = false;
4333
    }
4334
}
4335
 
303 andreas 4336
void TPageManager::runUpdateSubViewItem()
4337
{
4338
    DECL_TRACER("TPageManager::runUpdateSubViewItem()");
299 andreas 4339
 
303 andreas 4340
    if (mUpdateViewsRun)
4341
        return;
4342
 
4343
    mUpdateViewsRun = true;
4344
 
4345
    try
4346
    {
4347
        std::thread thr = std::thread([=] {
4348
            MSG_PROTOCOL("Thread \"TPageManager::runUpdateSubViewItem()\" was started.");
4349
 
4350
            while (mUpdateViewsRun && !prg_stopped)
4351
            {
4352
                while (!mUpdateViews.empty())
4353
                {
4354
                    _updateSubViewItem(mUpdateViews[0]);
4355
                    mUpdateViews.erase(mUpdateViews.begin()); // Remove first entry
4356
                }
4357
 
4358
                std::this_thread::sleep_for(std::chrono::microseconds(10));
4359
            }
4360
 
4361
            mUpdateViewsRun = false;
4362
            return;
4363
        });
4364
 
4365
        thr.detach();
4366
    }
4367
    catch (std::exception& e)
4368
    {
4369
        MSG_ERROR("Error starting a thread to handle the click queue: " << e.what());
4370
        mUpdateViewsRun = false;
4371
    }
4372
}
4373
 
11 andreas 4374
/*
4375
 * Catch the mouse presses and scan all pages and subpages for an element to
4376
 * receive the klick.
4377
 */
10 andreas 4378
void TPageManager::mouseEvent(int x, int y, bool pressed)
4379
{
4380
    DECL_TRACER("TPageManager::mouseEvent(int x, int y, bool pressed)");
4381
 
316 andreas 4382
    TTRYLOCK(click_mutex);
299 andreas 4383
 
4384
    _CLICK_QUEUE_t cq;
409 andreas 4385
    cq.eventType = _EVENT_MOUSE_CLICK;
299 andreas 4386
    cq.x = x;
4387
    cq.y = y;
4388
    cq.pressed = pressed;
4389
    cq.coords = true;
4390
    mClickQueue.push_back(cq);
334 andreas 4391
#if TESTMODE == 1
4392
    setScreenDone();
4393
#endif
299 andreas 4394
}
4395
 
409 andreas 4396
void TPageManager::mouseMoveEvent(int x, int y)
4397
{
4398
    DECL_TRACER("TPageManager::mouseMoveEvent(int x, int y)");
4399
 
4400
    TTRYLOCK(click_mutex);
4401
 
4402
    _CLICK_QUEUE_t cq;
4403
    cq.eventType = _EVENT_MOUSE_MOVE;
4404
    cq.x = x;
4405
    cq.y = y;
4406
    cq.coords = true;
4407
    mClickQueue.push_back(cq);
4408
#if TESTMODE == 1
4409
    setScreenDone();
4410
#endif
4411
}
4412
 
299 andreas 4413
void TPageManager::_mouseEvent(int x, int y, bool pressed)
4414
{
4415
    DECL_TRACER("TPageManager::_mouseEvent(int x, int y, bool pressed)");
4416
 
16 andreas 4417
    TError::clear();
334 andreas 4418
#if TESTMODE == 1
4419
    if (_gTestMode)
4420
        _gTestMode->setMouseClick(x, y, pressed);
4421
#endif
11 andreas 4422
    int realX = x - mFirstLeftPixel;
4423
    int realY = y - mFirstTopPixel;
263 andreas 4424
 
31 andreas 4425
    MSG_DEBUG("Mouse at " << realX << ", " << realY << ", state " << ((pressed) ? "PRESSED" : "RELEASED") << ", [ " << x << " | " << y << " ]");
43 andreas 4426
#ifdef _SCALE_SKIA_
100 andreas 4427
    if (mScaleFactor != 1.0 && mScaleFactor > 0.0)
26 andreas 4428
    {
4429
        realX = (int)((double)realX / mScaleFactor);
4430
        realY = (int)((double)realY / mScaleFactor);
31 andreas 4431
        MSG_DEBUG("Scaled coordinates: x=" << realX << ", y=" << realY);
26 andreas 4432
    }
43 andreas 4433
#endif
70 andreas 4434
 
154 andreas 4435
    TSubPage *subPage = nullptr;
11 andreas 4436
 
154 andreas 4437
    if (pressed)
4438
        subPage = getCoordMatch(realX, realY);
318 andreas 4439
    else if (mLastPagePush)
154 andreas 4440
        subPage = getSubPage(mLastPagePush);
4441
    else
4442
        subPage = getCoordMatch(realX, realY);
4443
 
11 andreas 4444
    if (!subPage)
14 andreas 4445
    {
146 andreas 4446
        Button::TButton *bt = getCoordMatchPage(realX, realY);
40 andreas 4447
 
4448
        if (bt)
4449
        {
4450
            MSG_DEBUG("Button on page " << bt->getButtonIndex() << ": size: left=" << bt->getLeftPosition() << ", top=" << bt->getTopPosition() << ", width=" << bt->getWidth() << ", height=" << bt->getHeight());
4451
            bt->doClick(x - bt->getLeftPosition(), y - bt->getTopPosition(), pressed);
4452
        }
4453
 
419 andreas 4454
        if (pressed)
4455
            mLastPagePush = getActualPageNumber();
4456
 
11 andreas 4457
        return;
14 andreas 4458
    }
11 andreas 4459
 
154 andreas 4460
    MSG_DEBUG("Subpage " << subPage->getNumber() << " [" << subPage->getName() << "]: size: left=" << subPage->getLeft() << ", top=" << subPage->getTop() << ", width=" << subPage->getWidth() << ", height=" << subPage->getHeight());
4461
 
4462
    if (pressed)
4463
        mLastPagePush = subPage->getNumber();
4464
    else
4465
        mLastPagePush = 0;
4466
 
11 andreas 4467
    subPage->doClick(realX - subPage->getLeft(), realY - subPage->getTop(), pressed);
10 andreas 4468
}
11 andreas 4469
 
409 andreas 4470
void TPageManager::_mouseMoveEvent(int x, int y)
4471
{
4472
    DECL_TRACER("TPageManager::_mouseMoveEvent(int x, int y)");
4473
 
4474
    int realX = x - mFirstLeftPixel;
4475
    int realY = y - mFirstTopPixel;
4476
 
4477
#ifdef _SCALE_SKIA_
4478
    if (mScaleFactor != 1.0 && mScaleFactor > 0.0)
4479
    {
4480
        realX = (int)((double)realX / mScaleFactor);
4481
        realY = (int)((double)realY / mScaleFactor);
4482
        MSG_DEBUG("Scaled coordinates: x=" << realX << ", y=" << realY);
4483
    }
4484
#endif
4485
 
4486
    TSubPage *subPage = nullptr;
4487
    subPage = getCoordMatch(realX, realY);
4488
 
4489
    if (!subPage)
4490
    {
4491
        Button::TButton *bt = getCoordMatchPage(realX, realY);
4492
 
416 andreas 4493
        if (bt)
4494
        {
4495
            if (bt->getButtonType() == BARGRAPH)
4496
                bt->moveBargraphLevel(realX - bt->getLeftPosition(), realY - bt->getTopPosition());
418 andreas 4497
            else if (bt->getButtonType() == JOYSTICK && !bt->getLevelFuction().empty())
416 andreas 4498
            {
4499
                bt->drawJoystick(realX - bt->getLeftPosition(), realY - bt->getTopPosition());
4500
                // Send the levels
4501
                bt->sendJoystickLevels();
4502
            }
4503
        }
409 andreas 4504
 
4505
        return;
4506
    }
4507
 
4508
    subPage->moveMouse(realX - subPage->getLeft(), realY - subPage->getTop());
4509
}
4510
 
289 andreas 4511
void TPageManager::mouseEvent(ulong handle, bool pressed)
4512
{
4513
    DECL_TRACER("TPageManager::mouseEvent(ulong handle, bool pressed)");
4514
 
320 andreas 4515
    if (!mClickQueue.empty() && mClickQueue.back().handle == handle && mClickQueue.back().pressed == pressed)
4516
        return;
4517
 
299 andreas 4518
    TLOCKER(click_mutex);
293 andreas 4519
 
299 andreas 4520
    _CLICK_QUEUE_t cq;
4521
    cq.handle = handle;
4522
    cq.pressed = pressed;
4523
    mClickQueue.push_back(cq);
4524
    MSG_DEBUG("Queued click for handle " << handleToString(cq.handle) << " state " << (cq.pressed ? "PRESSED" : "RELEASED"));
4525
}
4526
 
4527
void TPageManager::_mouseEvent(ulong handle, bool pressed)
4528
{
4529
    DECL_TRACER("TPageManager::_mouseEvent(ulong handle, bool pressed)");
4530
 
293 andreas 4531
    MSG_DEBUG("Doing click for handle " << handleToString(handle) << " state " << (pressed ? "PRESSED" : "RELEASED"));
4532
 
289 andreas 4533
    if (!handle)
4534
        return;
4535
 
4536
    int pageID = (handle >> 16) & 0x0000ffff;
4537
    int buttonID = (handle & 0x0000ffff);
4538
 
318 andreas 4539
    if (pageID < REGULAR_SUBPAGE_START || buttonID == 0)
289 andreas 4540
        return;
4541
 
4542
    TSubPage *subPage = getSubPage(pageID);
4543
 
4544
    if (subPage)
4545
    {
4546
        Button::TButton *bt = subPage->getButton(buttonID);
4547
 
4548
        if (bt)
4549
        {
318 andreas 4550
            MSG_DEBUG("Button on subpage " << pageID << ": " << buttonID);
289 andreas 4551
            bt->doClick(bt->getLeftPosition() + bt->getWidth() / 2, bt->getTopPosition() + bt->getHeight() / 2, pressed);
4552
        }
4553
    }
4554
}
4555
 
192 andreas 4556
void TPageManager::inputButtonFinished(ulong handle, const std::string &content)
4557
{
4558
    DECL_TRACER("TPageManager::inputButtonFinished(ulong handle, const std::string &content)");
4559
 
4560
    Button::TButton *bt = findButton(handle);
4561
 
4562
    if (!bt)
4563
    {
271 andreas 4564
        MSG_WARNING("Invalid button handle " << handleToString(handle));
192 andreas 4565
        return;
4566
    }
4567
 
4568
    bt->setTextOnly(content, -1);
4569
}
4570
 
309 andreas 4571
void TPageManager::inputCursorPositionChanged(ulong handle, int oldPos, int newPos)
4572
{
4573
    DECL_TRACER("TPageManager::inputCursorPositionChanged(ulong handle, int oldPos, int newPos)");
4574
 
4575
    Button::TButton *bt = findButton(handle);
4576
 
4577
    if (!bt)
4578
    {
4579
        MSG_WARNING("Invalid button handle " << handleToString(handle));
4580
        return;
4581
    }
4582
 
310 andreas 4583
    ulong pageID = (bt->getHandle() >> 16) & 0x0000ffff;
309 andreas 4584
 
4585
    if (pageID < REGULAR_SUBPAGE_START)
4586
    {
368 andreas 4587
        TPage *pg = getPage((int)pageID);
309 andreas 4588
 
4589
        if (!pg)
4590
            return;
4591
 
4592
        pg->setCursorPosition(handle, oldPos, newPos);
4593
    }
4594
    else
4595
    {
368 andreas 4596
        TSubPage *pg = getSubPage((int)pageID);
309 andreas 4597
 
4598
        if (!pg)
4599
            return;
4600
 
4601
        pg->setCursorPosition(handle, oldPos, newPos);
4602
    }
4603
}
4604
 
4605
void TPageManager::inputFocusChanged(ulong handle, bool in)
4606
{
4607
    DECL_TRACER("TPageManager::inputFocusChanged(ulong handle, bool in)");
4608
 
4609
    Button::TButton *bt = findButton(handle);
4610
 
4611
    if (!bt)
4612
    {
4613
        MSG_WARNING("Invalid button handle " << handleToString(handle));
4614
        return;
4615
    }
4616
 
310 andreas 4617
    ulong pageID = (bt->getHandle() >> 16) & 0x0000ffff;
4618
    MSG_DEBUG("Searching for page " << pageID);
309 andreas 4619
 
4620
    if (pageID < REGULAR_SUBPAGE_START)
4621
    {
368 andreas 4622
        TPage *pg = getPage((int)pageID);
309 andreas 4623
 
4624
        if (!pg)
4625
            return;
4626
 
4627
        pg->setInputFocus(handle, in);
4628
    }
4629
    else
4630
    {
368 andreas 4631
        TSubPage *pg = getSubPage((int)pageID);
309 andreas 4632
 
4633
        if (!pg)
4634
            return;
4635
 
4636
        pg->setInputFocus(handle, in);
4637
    }
4638
}
4639
 
208 andreas 4640
void TPageManager::setTextToButton(ulong handle, const string& txt, bool redraw)
51 andreas 4641
{
208 andreas 4642
    DECL_TRACER("TPageManager::setTextToButton(ulong handle, const string& txt, bool redraw)");
51 andreas 4643
 
4644
    // First we search for the button the handle points to
4645
    Button::TButton *button = findButton(handle);
4646
 
4647
    if (!button)
4648
    {
271 andreas 4649
        MSG_ERROR("No button with handle " << handleToString(handle) << " found!");
51 andreas 4650
        return;
4651
    }
4652
 
4653
    // Now we search for all buttons with the same channel and port number
4654
    vector<int> channels;
4655
    channels.push_back(button->getAddressChannel());
193 andreas 4656
    vector<TMap::MAP_T> map = findButtons(button->getAddressPort(), channels);
51 andreas 4657
 
4658
    if (TError::isError() || map.empty())
4659
        return;
4660
 
4661
    // Here we load all buttons found.
4662
    vector<Button::TButton *> buttons = collectButtons(map);
83 andreas 4663
 
4664
    if (buttons.size() > 0)
51 andreas 4665
    {
83 andreas 4666
        vector<Button::TButton *>::iterator mapIter;
4667
        // Finaly we iterate through all found buttons and set the text
118 andreas 4668
        for (mapIter = buttons.begin(); mapIter != buttons.end(); ++mapIter)
83 andreas 4669
        {
4670
            Button::TButton *bt = *mapIter;
51 andreas 4671
 
208 andreas 4672
            if (redraw)
4673
                bt->setText(txt, -1);
4674
            else
4675
                bt->setTextOnly(txt, -1);
83 andreas 4676
        }
51 andreas 4677
    }
4678
}
4679
 
193 andreas 4680
vector<Button::TButton *> TPageManager::collectButtons(vector<TMap::MAP_T>& map)
14 andreas 4681
{
193 andreas 4682
    DECL_TRACER("TPageManager::collectButtons(vector<TMap::MAP_T>& map)");
14 andreas 4683
 
4684
    vector<Button::TButton *> buttons;
83 andreas 4685
 
4686
    if (map.size() == 0)
4687
        return buttons;
4688
 
193 andreas 4689
    vector<TMap::MAP_T>::iterator iter;
14 andreas 4690
 
118 andreas 4691
    for (iter = map.begin(); iter != map.end(); ++iter)
14 andreas 4692
    {
209 andreas 4693
        if (iter->pg < REGULAR_SUBPAGE_START || (iter->pg >= SYSTEM_PAGE_START && iter->pg < SYSTEM_SUBPAGE_START))     // Main page?
14 andreas 4694
        {
4695
            TPage *page;
4696
 
4697
            if ((page = getPage(iter->pg)) == nullptr)
4698
            {
4699
                MSG_TRACE("Page " << iter->pg << ", " << iter->pn << " not found in memory. Reading it ...");
4700
 
4701
                if (!readPage(iter->pg))
4702
                    return buttons;
4703
 
4704
                page = getPage(iter->pg);
4705
            }
4706
 
4707
            Button::TButton *bt = page->getButton(iter->bt);
4708
 
4709
            if (bt)
4710
                buttons.push_back(bt);
4711
        }
4712
        else
4713
        {
4714
            TSubPage *subpage;
4715
 
4716
            if ((subpage = getSubPage(iter->pg)) == nullptr)
4717
            {
4718
                MSG_TRACE("Subpage " << iter->pg << ", " << iter->pn << " not found in memory. Reading it ...");
4719
 
4720
                if (!readSubPage(iter->pg))
4721
                    return buttons;
4722
 
4723
                subpage = getSubPage(iter->pg);
4724
                TPage *page = getActualPage();
4725
 
4726
                if (!page)
4727
                {
4728
                    MSG_ERROR("No actual page loaded!");
4729
                    return buttons;
4730
                }
4731
            }
4732
 
4733
            Button::TButton *bt = subpage->getButton(iter->bt);
4734
 
4735
            if (bt)
4736
                buttons.push_back(bt);
4737
        }
4738
    }
4739
 
4740
    return buttons;
4741
}
4742
 
11 andreas 4743
/****************************************************************************
36 andreas 4744
 * Calls from a Java activity. This is only available for Android OS.
4745
 ****************************************************************************/
182 andreas 4746
#ifdef Q_OS_ANDROID
36 andreas 4747
void TPageManager::initNetworkState()
4748
{
4749
    DECL_TRACER("TPageManager::initNetworkState()");
264 andreas 4750
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
36 andreas 4751
    QAndroidJniObject activity = QtAndroid::androidActivity();
4752
    QAndroidJniObject::callStaticMethod<void>("org/qtproject/theosys/NetworkStatus", "Init", "(Landroid/app/Activity;)V", activity.object());
4753
    activity.callStaticMethod<void>("org/qtproject/theosys/NetworkStatus", "InstallNetworkListener", "()V");
182 andreas 4754
#else
4755
    QJniObject activity = QNativeInterface::QAndroidApplication::context();
4756
    QJniObject::callStaticMethod<void>("org/qtproject/theosys/NetworkStatus", "Init", "(Landroid/app/Activity;)V", activity.object());
4757
    activity.callStaticMethod<void>("org/qtproject/theosys/NetworkStatus", "InstallNetworkListener", "()V");
4758
#endif
36 andreas 4759
}
4760
 
4761
void TPageManager::stopNetworkState()
4762
{
4763
    DECL_TRACER("TPageManager::stopNetworkState()");
264 andreas 4764
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
36 andreas 4765
    QAndroidJniObject::callStaticMethod<void>("org/qtproject/theosys/NetworkStatus", "destroyNetworkListener", "()V");
182 andreas 4766
#else
4767
    QJniObject::callStaticMethod<void>("org/qtproject/theosys/NetworkStatus", "destroyNetworkListener", "()V");
4768
#endif
36 andreas 4769
}
38 andreas 4770
 
4771
void TPageManager::initBatteryState()
4772
{
4773
    DECL_TRACER("TPageManager::initBatteryState()");
264 andreas 4774
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
38 andreas 4775
    QAndroidJniObject activity = QtAndroid::androidActivity();
4776
    QAndroidJniObject::callStaticMethod<void>("org/qtproject/theosys/BatteryState", "Init", "(Landroid/app/Activity;)V", activity.object());
182 andreas 4777
#else
4778
    QJniObject activity = QNativeInterface::QAndroidApplication::context();
4779
    QJniObject::callStaticMethod<void>("org/qtproject/theosys/BatteryState", "Init", "(Landroid/app/Activity;)V", activity.object());
4780
#endif
38 andreas 4781
    activity.callStaticMethod<void>("org/qtproject/theosys/BatteryState", "InstallBatteryListener", "()V");
4782
}
4783
 
61 andreas 4784
void TPageManager::initPhoneState()
4785
{
4786
    DECL_TRACER("TPageManager::initPhoneState()");
264 andreas 4787
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
61 andreas 4788
    QAndroidJniObject activity = QtAndroid::androidActivity();
4789
    QAndroidJniObject::callStaticMethod<void>("org/qtproject/theosys/PhoneCallState", "Init", "(Landroid/app/Activity;)V", activity.object());
182 andreas 4790
#else
4791
    QJniObject activity = QNativeInterface::QAndroidApplication::context();
4792
    QJniObject::callStaticMethod<void>("org/qtproject/theosys/PhoneCallState", "Init", "(Landroid/app/Activity;)V", activity.object());
4793
#endif
61 andreas 4794
    activity.callStaticMethod<void>("org/qtproject/theosys/PhoneCallState", "InstallPhoneListener", "()V");
4795
}
4796
 
38 andreas 4797
void TPageManager::stopBatteryState()
4798
{
4799
    DECL_TRACER("TPageManager::stopBatteryState()");
264 andreas 4800
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
38 andreas 4801
    QAndroidJniObject::callStaticMethod<void>("org/qtproject/theosys/BatteryState", "destroyBatteryListener", "()V");
182 andreas 4802
#else
4803
    QJniObject::callStaticMethod<void>("org/qtproject/theosys/BatteryState", "destroyBatteryListener", "()V");
4804
#endif
38 andreas 4805
}
4806
 
36 andreas 4807
void TPageManager::informTPanelNetwork(jboolean conn, jint level, jint type)
4808
{
250 andreas 4809
    DECL_TRACER("TPageManager::informTPanelNetwork(jboolean conn, jint level, jint type)");
36 andreas 4810
 
4811
    int l = 0;
4812
    string sType;
4813
 
4814
    switch (type)
4815
    {
4816
        case 1: sType = "Wifi"; break;
4817
        case 2: sType = "Mobile"; break;
4818
 
4819
        default:
4820
            sType = "Unknown"; break;
4821
    }
4822
 
4823
    if (conn)
4824
        l = level;
4825
 
93 andreas 4826
    if (mNetState && mNetState != type)     // Has the connection type changed?
4827
    {
4828
        if (gAmxNet)
4829
            gAmxNet->reconnect();
4830
    }
4831
 
4832
    mNetState = type;
4833
 
36 andreas 4834
    MSG_INFO("Connection status: " << (conn ? "Connected" : "Disconnected") << ", level: " << level << ", type: " << sType);
4835
 
83 andreas 4836
    if (mNetCalls.size() > 0)
36 andreas 4837
    {
83 andreas 4838
        std::map<int, std::function<void (int level)> >::iterator iter;
4839
 
4840
        for (iter = mNetCalls.begin(); iter != mNetCalls.end(); ++iter)
4841
            iter->second(l);
36 andreas 4842
    }
4843
}
38 andreas 4844
 
4845
void TPageManager::informBatteryStatus(jint level, jboolean charging, jint chargeType)
4846
{
4847
    DECL_TRACER("TPageManager::informBatteryStatus(jint level, jboolean charging, jint chargeType)");
4848
 
59 andreas 4849
    MSG_INFO("Battery status: level: " << level << ", " << (charging ? "Charging" : "not charging") << ", type: " << chargeType << ", Elements: " << mBatteryCalls.size());
38 andreas 4850
 
83 andreas 4851
    if (mBatteryCalls.size() > 0)
38 andreas 4852
    {
83 andreas 4853
        std::map<int, std::function<void (int, bool, int)> >::iterator iter;
4854
 
4855
        for (iter = mBatteryCalls.begin(); iter != mBatteryCalls.end(); ++iter)
4856
            iter->second(level, charging, chargeType);
38 andreas 4857
    }
4858
}
61 andreas 4859
 
4860
void TPageManager::informPhoneState(bool call, const string &pnumber)
4861
{
4862
    DECL_TRACER("TPageManager::informPhoneState(bool call, const string &pnumber)");
4863
 
4864
    MSG_INFO("Call state: " << (call ? "Call in progress" : "No call") << ", phone number: " << pnumber);
4865
 
4866
    if (!gAmxNet)
4867
    {
4868
        MSG_WARNING("The network manager for the AMX controller is not initialized!");
4869
        return;
4870
    }
4871
}
130 andreas 4872
 
4873
void TPageManager::initOrientation()
4874
{
4875
    DECL_TRACER("TPageManager::initOrientation()");
4876
 
131 andreas 4877
    int rotate = getSettings()->getRotate();
264 andreas 4878
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
130 andreas 4879
    QAndroidJniObject activity = QtAndroid::androidActivity();
131 andreas 4880
    QAndroidJniObject::callStaticMethod<void>("org/qtproject/theosys/Orientation", "Init", "(Landroid/app/Activity;I)V", activity.object(), rotate);
182 andreas 4881
#else
4882
    QJniObject activity = QNativeInterface::QAndroidApplication::context();
4883
    QJniObject::callStaticMethod<void>("org/qtproject/theosys/Orientation", "Init", "(Landroid/app/Activity;I)V", activity.object(), rotate);
4884
#endif
130 andreas 4885
    activity.callStaticMethod<void>("org/qtproject/theosys/Orientation", "InstallOrientationListener", "()V");
4886
}
255 andreas 4887
 
4888
void TPageManager::enterSetup()
4889
{
260 andreas 4890
    DECL_TRACER("TPageManager::enterSetup()");
264 andreas 4891
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
255 andreas 4892
    QAndroidJniObject activity = QtAndroid::androidActivity();
4893
    QAndroidJniObject::callStaticMethod<void>("org/qtproject/theosys/Settings", "callSettings", "(Landroid/app/Activity;)V", activity.object());
4894
#else
4895
    QJniObject activity = QNativeInterface::QAndroidApplication::context();
4896
    QJniObject::callStaticMethod<void>("org/qtproject/theosys/Settings", "callSettings", "(Landroid/app/Activity;)V", activity.object());
4897
#endif
4898
}
59 andreas 4899
#endif  // __ANDROID__
247 andreas 4900
#ifdef Q_OS_IOS
4901
void TPageManager::informBatteryStatus(int level, int state)
4902
{
4903
    DECL_TRACER("TPageManager::informBatteryStatus(int level, int state)");
36 andreas 4904
 
247 andreas 4905
    MSG_INFO("Battery status: level: " << level << ", " << state);
4906
 
4907
    if (mBatteryCalls.size() > 0)
4908
    {
4909
        std::map<int, std::function<void (int, int)> >::iterator iter;
4910
 
4911
        for (iter = mBatteryCalls.begin(); iter != mBatteryCalls.end(); ++iter)
4912
            iter->second(level, state);
4913
    }
4914
}
250 andreas 4915
 
4916
void TPageManager::informTPanelNetwork(bool conn, int level, int type)
4917
{
4918
    DECL_TRACER("TPageManager::informTPanelNetwork(bool conn, int level, int type)");
4919
 
4920
    int l = 0;
4921
    string sType;
4922
 
4923
    switch (type)
4924
    {
4925
        case 1: sType = "Ethernet"; break;
4926
        case 2: sType = "Mobile"; break;
4927
        case 3: sType = "WiFi"; break;
4928
        case 4: sType = "Bluetooth"; break;
4929
 
4930
        default:
4931
            sType = "Unknown"; break;
4932
    }
4933
 
4934
    if (conn)
4935
        l = level;
4936
 
4937
    if (mNetState && mNetState != type)     // Has the connection type changed?
4938
    {
4939
        if (gAmxNet)
4940
            gAmxNet->reconnect();
4941
    }
4942
 
4943
    mNetState = type;
4944
 
4945
    MSG_INFO("Connection status: " << (conn ? "Connected" : "Disconnected") << ", level: " << level << ", type: " << sType);
4946
 
4947
    if (mNetCalls.size() > 0)
4948
    {
4949
        std::map<int, std::function<void (int level)> >::iterator iter;
4950
 
4951
        for (iter = mNetCalls.begin(); iter != mNetCalls.end(); ++iter)
4952
            iter->second(l);
4953
    }
4954
}
4955
 
247 andreas 4956
#endif
4957
 
60 andreas 4958
void TPageManager::setButtonCallbacks(Button::TButton *bt)
4959
{
227 andreas 4960
    DECL_TRACER("TPageManager::setButtonCallbacks(Button::TButton *bt)");
4961
 
162 andreas 4962
    if (!bt)
4963
        return;
4964
 
60 andreas 4965
    bt->registerCallback(_displayButton);
4966
    bt->regCallPlayVideo(_callPlayVideo);
4967
    bt->setFonts(mFonts);
4968
    bt->setPalette(mPalette);
4969
}
4970
 
4971
void TPageManager::externalButton(extButtons_t bt, bool checked)
4972
{
4973
    DECL_TRACER("TPageManager::externalButton(extButtons_t bt)");
4974
 
4975
    if (!mExternal)
4976
        return;
4977
 
4978
    EXTBUTTON_t button = mExternal->getButton(bt);
4979
 
4980
    if (button.type == EXT_NOBUTTON)
4981
        return;
4982
 
4983
    if (button.cp && button.ch)
4984
    {
4985
        amx::ANET_SEND scmd;
4986
 
4987
        scmd.device = TConfig::getChannel();
4988
        scmd.port = button.cp;
4989
        scmd.channel = button.ch;
4990
 
4991
        if (checked)
4992
            scmd.MC = 0x0084;   // push button
134 andreas 4993
        else
4994
            scmd.MC = 0x0085;   // release button
60 andreas 4995
 
134 andreas 4996
        MSG_DEBUG("Sending to device <" << scmd.device << ":" << scmd.port << ":0> channel " << scmd.channel << " value 0x" << std::setw(2) << std::setfill('0') << std::hex << scmd.MC << " (" << (checked?"PUSH":"RELEASE") << ")");
60 andreas 4997
 
134 andreas 4998
        if (gAmxNet)
4999
            gAmxNet->sendCommand(scmd);
5000
        else
5001
        {
5002
            MSG_WARNING("Missing global class TAmxNet. Can't send a message!");
5003
        }
60 andreas 5004
    }
5005
}
5006
 
62 andreas 5007
void TPageManager::sendKeyboard(const std::string& text)
5008
{
5009
    DECL_TRACER("TPageManager::sendKeyboard(const std::string& text)");
5010
 
5011
    amx::ANET_SEND scmd;
5012
    scmd.port = 1;
5013
    scmd.channel = 0;
5014
    scmd.msg = UTF8ToCp1250(text);
5015
    scmd.MC = 0x008b;
5016
 
5017
    if (gAmxNet)
5018
        gAmxNet->sendCommand(scmd);
5019
    else
5020
        MSG_WARNING("Missing global class TAmxNet. Can't send message!");
5021
}
5022
 
5023
void TPageManager::sendKeypad(const std::string& text)
5024
{
5025
    DECL_TRACER("TPageManager::sendKeypad(const std::string& text)");
5026
 
269 andreas 5027
    sendKeyboard(text);
62 andreas 5028
}
5029
 
5030
void TPageManager::sendString(uint handle, const std::string& text)
5031
{
5032
    DECL_TRACER("TPageManager::sendString(uint handle, const std::string& text)");
5033
 
5034
    Button::TButton *bt = findButton(handle);
5035
 
5036
    if (!bt)
5037
    {
271 andreas 5038
        MSG_WARNING("Button " << handleToString(handle) << " not found!");
62 andreas 5039
        return;
5040
    }
5041
 
5042
    amx::ANET_SEND scmd;
5043
    scmd.port = bt->getAddressPort();
5044
    scmd.channel = bt->getAddressChannel();
5045
    scmd.msg = UTF8ToCp1250(text);
5046
    scmd.MC = 0x008b;
5047
 
5048
    if (gAmxNet)
5049
        gAmxNet->sendCommand(scmd);
5050
    else
5051
        MSG_WARNING("Missing global class TAmxNet. Can't send message!");
5052
}
5053
 
134 andreas 5054
void TPageManager::sendGlobalString(const string& text)
5055
{
5056
    DECL_TRACER("TPageManager::sendGlobalString(const string& text)");
5057
 
5058
    if (text.empty() || text.find("-") == string::npos)
5059
        return;
5060
 
5061
    amx::ANET_SEND scmd;
5062
    scmd.port = 1;
5063
    scmd.channel = 0;
5064
    scmd.msg = text;
5065
    scmd.MC = 0x008b;
5066
 
5067
    if (gAmxNet)
5068
        gAmxNet->sendCommand(scmd);
5069
    else
5070
        MSG_WARNING("Missing global class TAmxNet. Can't send message!");
5071
}
5072
 
147 andreas 5073
void TPageManager::sendCommandString(int port, const string& cmd)
5074
{
5075
    DECL_TRACER("TPageManager::sendGlobalString(const string& text)");
5076
 
5077
    if (cmd.empty())
5078
        return;
5079
 
5080
    amx::ANET_SEND scmd;
5081
    scmd.port = port;
5082
    scmd.channel = 0;
5083
    scmd.msg = cmd;
5084
    scmd.MC = 0x008c;
5085
 
5086
    if (gAmxNet)
5087
        gAmxNet->sendCommand(scmd);
5088
    else
5089
        MSG_WARNING("Missing global class TAmxNet. Can't send message!");
5090
}
5091
 
428 andreas 5092
void TPageManager::sendLevel(int lp, int lv, int level)
5093
{
5094
    DECL_TRACER("TPageManager::sendLevel(int lp, int lv, int level)");
5095
 
5096
    if (!lv)
5097
        return;
5098
 
5099
    amx::ANET_SEND scmd;
5100
    scmd.device = TConfig::getChannel();
5101
    scmd.port = lp;
5102
    scmd.channel = lv;
5103
    scmd.level = lv;
5104
    scmd.MC = 0x008a;
5105
    scmd.value = level;
5106
 
5107
    if (gAmxNet)
5108
        gAmxNet->sendCommand(scmd);
5109
    else
5110
        MSG_WARNING("Missing global class TAmxNet. Can't send message!");
5111
}
5112
 
5113
void TPageManager::sendInternalLevel(int lp, int lv, int level)
5114
{
5115
    DECL_TRACER("TPageManager::sendInternalLevel(int lp, int lv, int level)");
5116
 
5117
    amx::ANET_COMMAND cmd;
429 andreas 5118
    int channel = TConfig::getChannel();
5119
    int system = TConfig::getSystem();
5120
 
428 andreas 5121
    cmd.MC = 0x000a;
429 andreas 5122
    cmd.device1 = channel;
428 andreas 5123
    cmd.port1 = lp;
429 andreas 5124
    cmd.system = system;
5125
    cmd.data.message_value.system = system;
5126
    cmd.data.message_value.device = channel;
428 andreas 5127
    cmd.data.message_value.port = lp;           // Must be the address port of bargraph
5128
    cmd.data.message_value.value = lv;          // Must be the level channel of bargraph
5129
    cmd.data.message_value.type = DTSZ_UINT;    // unsigned integer
5130
    cmd.data.message_value.content.sinteger = level;
5131
    doCommand(cmd);
5132
}
5133
 
123 andreas 5134
void TPageManager::sendPHNcommand(const std::string& cmd)
5135
{
5136
    DECL_TRACER("TPageManager::sendPHNcommand(const std::string& cmd)");
5137
 
5138
    amx::ANET_SEND scmd;
144 andreas 5139
    scmd.port = mTSettings->getSettings().voipCommandPort;
123 andreas 5140
    scmd.channel = TConfig::getChannel();
5141
    scmd.msg = "^PHN-" + cmd;
127 andreas 5142
    scmd.MC = 0x008c;
5143
    MSG_DEBUG("Sending PHN command: ^PHN-" << cmd);
123 andreas 5144
 
5145
    if (gAmxNet)
5146
        gAmxNet->sendCommand(scmd);
5147
    else
5148
        MSG_WARNING("Missing global class TAmxNet. Can't send ^PHN command!");
5149
}
5150
 
111 andreas 5151
void TPageManager::sendKeyStroke(char key)
5152
{
5153
    DECL_TRACER("TPageManager::sendKeyStroke(char key)");
5154
 
5155
    if (!key)
5156
        return;
5157
 
5158
    char msg[2];
5159
    msg[0] = key;
5160
    msg[1] = 0;
5161
 
5162
    amx::ANET_SEND scmd;
5163
    scmd.port = 1;
5164
    scmd.channel = 0;
5165
    scmd.msg.assign(msg);
127 andreas 5166
    scmd.MC = 0x008c;
111 andreas 5167
 
5168
    if (gAmxNet)
5169
        gAmxNet->sendCommand(scmd);
5170
    else
5171
        MSG_WARNING("Missing global class TAmxNet. Can't send message!");
5172
}
5173
 
110 andreas 5174
/**
5175
 * Sending a custom event is identical in all cases. Because of this I
5176
 * implemented this method to send a custom event. This is called in all cases
5177
 * where a ?XXX command is received.
5178
 *
5179
 * @param value1    The instance of the button.
5180
 * @param value2    The value of a numeric request or the length of the string.
5181
 * @param value3    Always 0
5182
 * @param msg       In case of a string this contains the string.
5183
 * @param evType    This is the event type, a number between 1001 and 1099.
5184
 * @param cp        Channel port of button.
5185
 * @param cn        Channel number. of button.
5186
 *
5187
 * @return If all parameters are valid it returns TRUE.
5188
 */
5189
bool TPageManager::sendCustomEvent(int value1, int value2, int value3, const string& msg, int evType, int cp, int cn)
5190
{
5191
    DECL_TRACER("TPageManager::sendCustomEvent(int value1, int value2, int value3, const string& msg, int evType)");
5192
 
5193
    if (value1 < 1)
5194
        return false;
5195
 
5196
    amx::ANET_SEND scmd;
5197
    scmd.port = cp;
5198
    scmd.channel = cn;
5199
    scmd.ID = scmd.channel;
5200
    scmd.flag = 0;
5201
    scmd.type = evType;
5202
    scmd.value1 = value1;   // instance
5203
    scmd.value2 = value2;
5204
    scmd.value3 = value3;
5205
    scmd.msg = msg;
5206
 
5207
    if (!msg.empty())
5208
        scmd.dtype = 0x0001;// Char array
5209
 
5210
    scmd.MC = 0x008d;       // custom event
5211
 
5212
    if (gAmxNet)
5213
        gAmxNet->sendCommand(scmd);
5214
    else
5215
        MSG_WARNING("Missing global class TAmxNet. Can't send message!");
5216
 
5217
    return true;
5218
}
129 andreas 5219
#ifndef _NOSIP_
127 andreas 5220
string TPageManager::sipStateToString(TSIPClient::SIP_STATE_t s)
5221
{
5222
    DECL_TRACER("TPageManager::sipStateToString(TSIPClient::SIP_STATE_t s)");
5223
 
5224
    switch(s)
5225
    {
5226
        case TSIPClient::SIP_CONNECTED:     return "CONNECTED";
5227
        case TSIPClient::SIP_DISCONNECTED:  return "DISCONNECTED";
5228
        case TSIPClient::SIP_HOLD:          return "HOLD";
5229
        case TSIPClient::SIP_RINGING:       return "RINGING";
5230
        case TSIPClient::SIP_TRYING:        return "TRYING";
5231
 
5232
        default:
5233
            return "IDLE";
5234
    }
5235
 
5236
    return "IDLE";
5237
}
129 andreas 5238
#endif
134 andreas 5239
void TPageManager::sendOrientation()
5240
{
5241
    string ori;
5242
 
5243
    switch(mOrientation)
5244
    {
5245
        case O_PORTRAIT:            ori = "DeviceOrientationPortrait"; break;
5246
        case O_REVERSE_PORTRAIT:    ori = "DeviceOrientationPortraitUpsideDown"; break;
5247
        case O_LANDSCAPE:           ori = "DeviceOrientationLandscapeLeft"; break;
5248
        case O_REVERSE_LANDSCAPE:   ori = "DeviceOrientationLandscapeRight"; break;
5249
        case O_FACE_UP:             ori = "DeviceOrientationFaceUp"; break;
5250
        case O_FACE_DOWN:           ori = "DeviceOrientationFaceDown"; break;
5251
        default:
5252
            return;
5253
    }
5254
 
5255
    sendGlobalString("TPCACC-" + ori);
5256
}
5257
 
401 andreas 5258
void TPageManager::callSetPassword(ulong handle, const string& pw, int x, int y)
396 andreas 5259
{
401 andreas 5260
    DECL_TRACER("TPageManager::callSetPassword(ulong handle, const string& pw, int x, int y)");
396 andreas 5261
 
5262
    Button::TButton *bt = findButton(handle);
5263
 
5264
    if (!bt)
5265
    {
5266
        MSG_WARNING("callSetPassword: Button " << handleToString(handle) << " not found!");
5267
        return;
5268
    }
5269
 
5270
    string pass = pw;
5271
 
5272
    if (pass.empty())
5273
        pass = "\x01";
5274
 
5275
    bt->setPassword(pass);
401 andreas 5276
    bt->doClick(x, y, true);
5277
    bt->doClick(x, y, false);
396 andreas 5278
}
5279
 
431 andreas 5280
TButtonStates *TPageManager::addButtonState(BUTTONTYPE t, int rap, int rad, int rch, int rcp, int rlp, int rlv)
429 andreas 5281
{
431 andreas 5282
    DECL_TRACER("TPageManager::addButtonState(BUTTONTYPE t, int rap, int rad, int rch, int rcp, int rlp, int rlv)");
429 andreas 5283
 
431 andreas 5284
    TButtonStates *pbs = new TButtonStates(t, rap, rad, rch, rcp, rlp, rlv);
5285
    uint32_t id = pbs->getID();
5286
 
429 andreas 5287
    if (!mButtonStates.empty())
5288
    {
5289
        vector<TButtonStates *>::iterator iter;
5290
 
5291
        for (iter = mButtonStates.begin(); iter != mButtonStates.end(); ++iter)
5292
        {
5293
            TButtonStates *bs = *iter;
5294
 
431 andreas 5295
            if (bs->isButton(t, id))
5296
            {
5297
                delete pbs;
429 andreas 5298
                return bs;
431 andreas 5299
            }
429 andreas 5300
        }
5301
    }
5302
 
431 andreas 5303
    mButtonStates.push_back(pbs);
5304
    return pbs;
429 andreas 5305
}
5306
 
431 andreas 5307
TButtonStates *TPageManager::addButtonState(const TButtonStates& rbs)
429 andreas 5308
{
431 andreas 5309
    DECL_TRACER("TPageManager::addButtonState(const TButtonStates& rbs)");
429 andreas 5310
 
5311
    if (!mButtonStates.empty())
5312
    {
5313
        vector<TButtonStates *>::iterator iter;
431 andreas 5314
        TButtonStates bs = rbs;
5315
        BUTTONTYPE type = bs.getType();
5316
        uint32_t id = bs.getID();
429 andreas 5317
 
5318
        for (iter = mButtonStates.begin(); iter != mButtonStates.end(); ++iter)
5319
        {
5320
            TButtonStates *pbs = *iter;
5321
 
431 andreas 5322
            if (pbs->isButton(type, id))
429 andreas 5323
                return pbs;
5324
        }
5325
    }
5326
 
431 andreas 5327
    TButtonStates *pbs = new TButtonStates(rbs);
429 andreas 5328
    mButtonStates.push_back(pbs);
5329
    return pbs;
5330
}
5331
 
431 andreas 5332
TButtonStates *TPageManager::getButtonState(BUTTONTYPE t, int rap, int rad, int rch, int rcp, int rlp, int rlv)
429 andreas 5333
{
431 andreas 5334
    DECL_TRACER("TPageManager::getButtonState(BUTTONTYPE t, int rap, int rad, int rch, int rcp, int rlp, int rlv)");
429 andreas 5335
 
5336
    if (mButtonStates.empty())
5337
        return nullptr;
5338
 
5339
    vector<TButtonStates *>::iterator iter;
5340
    MSG_DEBUG("Found " << mButtonStates.size() << " button states.");
5341
 
5342
    for (iter = mButtonStates.begin(); iter != mButtonStates.end(); ++iter)
5343
    {
5344
        TButtonStates *bs = *iter;
5345
 
431 andreas 5346
        if (bs->isButton(t, rap, rad, rch, rcp, rlp, rlv))
429 andreas 5347
            return bs;
5348
    }
5349
 
5350
    return nullptr;
5351
}
5352
 
431 andreas 5353
TButtonStates *TPageManager::getButtonState(uint32_t id)
5354
{
5355
    DECL_TRACER("TPageManager::getButtonState(uint32_t id)");
5356
 
5357
    if (mButtonStates.empty())
5358
        return nullptr;
5359
 
5360
    vector<TButtonStates *>::iterator iter;
5361
    MSG_DEBUG("Found " << mButtonStates.size() << " button states.");
5362
 
5363
    for (iter = mButtonStates.begin(); iter != mButtonStates.end(); ++iter)
5364
    {
5365
        TButtonStates *bs = *iter;
5366
 
5367
        if (bs->isButton(id))
5368
            return bs;
5369
    }
5370
 
5371
    return nullptr;
5372
}
5373
 
5374
TButtonStates *TPageManager::getButtonState(BUTTONTYPE t, uint32_t id)
5375
{
5376
    DECL_TRACER("TPageManager::getButtonState(BUTTONTYPE t, uint32_t id)");
5377
 
5378
    if (mButtonStates.empty())
5379
        return nullptr;
5380
 
5381
    vector<TButtonStates *>::iterator iter;
5382
    MSG_DEBUG("Found " << mButtonStates.size() << " button states.");
5383
 
5384
    for (iter = mButtonStates.begin(); iter != mButtonStates.end(); ++iter)
5385
    {
5386
        TButtonStates *bs = *iter;
5387
 
5388
        if (bs->isButton(t, id))
5389
            return bs;
5390
    }
5391
 
5392
    return nullptr;
5393
}
5394
 
153 andreas 5395
void TPageManager::onSwipeEvent(TPageManager::SWIPES sw)
5396
{
5397
    DECL_TRACER("TPageManager::onSwipeEvent(TPageManager::SWIPES sw)");
5398
 
5399
    // Swipes are defined in "external".
5400
    if (!mExternal)
5401
        return;
5402
 
5403
    extButtons_t eBt;
5404
    string dbg;
5405
 
5406
    switch(sw)
5407
    {
5408
        case SW_LEFT:   eBt = EXT_GESTURE_LEFT; dbg.assign("LEFT"); break;
5409
        case SW_RIGHT:  eBt = EXT_GESTURE_RIGHT; dbg.assign("RIGHT"); break;
5410
        case SW_UP:     eBt = EXT_GESTURE_UP; dbg.assign("UP"); break;
5411
        case SW_DOWN:   eBt = EXT_GESTURE_DOWN; dbg.assign("DOWN"); break;
5412
 
5413
        default:
5414
            return;
5415
    }
5416
 
5417
    int pgNum = getActualPageNumber();
5418
    EXTBUTTON_t bt = mExternal->getButton(pgNum, eBt);
5419
 
5420
    if (bt.bi == 0)
5421
        return;
5422
 
5423
    MSG_DEBUG("Received swipe " << dbg << " event for page " << pgNum << " on button " << bt.bi << " \"" << bt.na << "\"");
5424
 
5425
    if (!bt.cm.empty() && bt.co == 0)           // Feed command to ourself?
5426
    {                                           // Yes, then feed it into command queue.
5427
        MSG_DEBUG("Button has a self feed command");
5428
 
5429
        int channel = TConfig::getChannel();
5430
        int system = TConfig::getSystem();
5431
 
5432
        amx::ANET_COMMAND cmd;
5433
        cmd.MC = 0x000c;
5434
        cmd.device1 = channel;
5435
        cmd.port1 = bt.ap;
5436
        cmd.system = system;
5437
        cmd.data.message_string.device = channel;
5438
        cmd.data.message_string.port = bt.ap;  // Must be the address port of button
5439
        cmd.data.message_string.system = system;
5440
        cmd.data.message_string.type = 1;   // 8 bit char string
5441
 
5442
        vector<string>::iterator iter;
5443
 
5444
        for (iter = bt.cm.begin(); iter != bt.cm.end(); ++iter)
5445
        {
5446
            cmd.data.message_string.length = iter->length();
5447
            memset(&cmd.data.message_string.content, 0, sizeof(cmd.data.message_string.content));
5448
            strncpy((char *)&cmd.data.message_string.content, iter->c_str(), sizeof(cmd.data.message_string.content));
5449
            doCommand(cmd);
5450
        }
5451
    }
5452
    else if (!bt.cm.empty())
5453
    {
5454
        MSG_DEBUG("Button sends a command on port " << bt.co);
5455
 
5456
        vector<string>::iterator iter;
5457
 
5458
        for (iter = bt.cm.begin(); iter != bt.cm.end(); ++iter)
5459
            sendCommandString(bt.co, *iter);
5460
    }
5461
}
5462
 
36 andreas 5463
/****************************************************************************
11 andreas 5464
 * The following functions implements one of the commands the panel accepts.
5465
 ****************************************************************************/
43 andreas 5466
 
5467
/**
5468
 * This is a special function handling the progress bars when the files of the
5469
 * panel are updated. Instead of simply displaying a ready page, it fakes one
5470
 * with the actual dimensions of the main page. This is possible, because we've
5471
 * always a main page even if the panel is started for the first time.
5472
 */
5473
void TPageManager::doFTR(int port, vector<int>& channels, vector<string>& pars)
23 andreas 5474
{
43 andreas 5475
    DECL_TRACER("TPageManager::doFTR(int, vector<int>&, vector<string>& pars)");
14 andreas 5476
 
23 andreas 5477
    if (pars.empty())
5478
    {
5479
        MSG_WARNING("Command #FTR needs at least 1 parameter! Ignoring command.");
5480
        return;
5481
    }
5482
 
96 andreas 5483
    if (TStreamError::checkFilter(HLOG_DEBUG))
23 andreas 5484
    {
96 andreas 5485
        for (size_t i = 0; i < pars.size(); i++)
5486
        {
5487
            MSG_DEBUG("[" << i << "]: " << pars.at(i));
5488
        }
23 andreas 5489
    }
43 andreas 5490
 
5491
    if (pars.at(0).compare("START") == 0)
5492
    {
5493
        // Here we have to drop all pages and subpages first and then display
5494
        // the faked page with the progress bars.
5495
        MSG_DEBUG("Starting file transfer ...");
5496
        doPPX(port, channels, pars);
5497
        TPage *pg = getPage("_progress");
5498
 
5499
        if (!pg)
5500
        {
5501
            if (!readPage("_progress"))
5502
            {
5503
                MSG_ERROR("Error creating the system page _progress!");
5504
                return;
5505
            }
5506
 
5507
            pg = getPage("_progress");
5508
 
5509
            if (!pg)
5510
            {
5511
                MSG_ERROR("Error getting system page _progress!");
5512
                return;
5513
            }
5514
        }
5515
 
5516
        pg->setFonts(mFonts);
5517
        pg->registerCallback(_setBackground);
5518
        pg->regCallPlayVideo(_callPlayVideo);
5519
 
5520
        if (!pg || !_setPage || !mTSettings)
5521
            return;
5522
 
5523
        int width, height;
217 andreas 5524
        width = mTSettings->getWidth();
43 andreas 5525
        height = mTSettings->getHeight();
5526
#ifdef _SCALE_SKIA_
5527
        if (mScaleFactor != 1.0)
5528
        {
5529
            width = (int)((double)width * mScaleFactor);
5530
            height = (int)((double)height * mScaleFactor);
5531
        }
5532
#endif
5533
        _setPage((pg->getNumber() << 16) & 0xffff0000, width, height);
5534
        pg->show();
5535
        MSG_DEBUG("Page _progress on screen");
5536
    }
5537
    else if (pars.at(0).compare("SYNC") == 0)
5538
    {
5539
        TPage *pg = getPage("_progress");
5540
 
5541
        if (!pg)
5542
        {
5543
            MSG_ERROR("Page _progress not found!");
5544
            return;
5545
        }
5546
 
5547
        Button::TButton *bt = pg->getButton(1);   // Line 1
5548
 
5549
        if (!bt)
5550
        {
5551
            MSG_ERROR("Button 160 of page _progress not found!");
5552
            return;
5553
        }
5554
 
5555
        bt->setText(pars.at(2), 0);
5556
        bt->show();
5557
    }
5558
    else if (pars.at(0).compare("FTRSTART") == 0)
5559
    {
5560
        TPage *pg = getPage("_progress");
5561
 
5562
        if (!pg)
5563
        {
5564
            MSG_ERROR("Page _progress not found!");
5565
            return;
5566
        }
5567
 
5568
        Button::TButton *bt1 = pg->getButton(1);   // Line 1
5569
        Button::TButton *bt2 = pg->getButton(2);   // Line 2
5570
        Button::TButton *bt3 = pg->getButton(3);   // Bargraph 1
5571
        Button::TButton *bt4 = pg->getButton(4);   // Bargraph 2
5572
 
5573
        if (!bt1 || !bt2 || !bt3 || !bt4)
5574
        {
5575
            MSG_ERROR("Buttons of page _progress not found!");
5576
            return;
5577
        }
5578
 
5579
        bt1->setText("Transfering files ...", 0);
5580
        bt1->show();
5581
        bt2->setText(pars.at(3), 0);
5582
        bt2->show();
5583
        bt3->drawBargraph(0, atoi(pars.at(1).c_str()), true);
5584
        bt4->drawBargraph(0, atoi(pars.at(2).c_str()), true);
5585
    }
5586
    else if (pars.at(0).compare("FTRPART") == 0)
5587
    {
5588
        TPage *pg = getPage("_progress");
5589
 
5590
        if (!pg)
5591
        {
5592
            MSG_ERROR("Page _progress not found!");
5593
            return;
5594
        }
5595
 
5596
        Button::TButton *bt = pg->getButton(4);   // Bargraph 2
5597
 
5598
        if (!bt)
5599
        {
5600
            MSG_ERROR("Buttons of page _progress not found!");
5601
            return;
5602
        }
5603
 
5604
        bt->drawBargraph(0, atoi(pars.at(2).c_str()), true);
5605
    }
5606
    else if (pars.at(0).compare("END") == 0)
5607
    {
5608
        MSG_TRACE("End of file transfer reached.");
44 andreas 5609
 
155 andreas 5610
        // To make sure the new surface will not be deleted and replaced by the
5611
        // default build in surface, we must delete the "virgin" marker first.
5612
        // This is a file called <project path>/.system.
5613
        string virgin = TConfig::getProjectPath() + "/.system";
5614
        remove(virgin.c_str());     // Because this file may not exist we don't care about the result code.
5615
 
44 andreas 5616
        if (_resetSurface)
5617
            _resetSurface();
5618
        else
5619
        {
5620
            MSG_WARNING("Missing callback function \"resetSurface\"!");
5621
        }
43 andreas 5622
    }
23 andreas 5623
}
5624
 
318 andreas 5625
void TPageManager::doLEVON(int, vector<int>&, vector<string>&)
5626
{
5627
    DECL_TRACER("TPageManager::doLEVON(int, vector<int>&, vector<string>&)");
5628
 
5629
    mLevelSend = true;
343 andreas 5630
#if TESTMODE == 1
5631
    __success = true;
5632
    setAllDone();
5633
#endif
318 andreas 5634
}
5635
 
5636
void TPageManager::doLEVOF(int, vector<int>&, vector<string>&)
5637
{
5638
    DECL_TRACER("TPageManager::doLEVOF(int, vector<int>&, vector<string>&)");
5639
 
5640
    mLevelSend = false;
343 andreas 5641
#if TESTMODE == 1
5642
    __success = true;
5643
    setAllDone();
5644
#endif
318 andreas 5645
}
5646
 
5647
void TPageManager::doRXON(int, vector<int>&, vector<string>&)
5648
{
5649
    DECL_TRACER("TPageManager::doRXON(int, vector<int>&, vector<string>&)");
5650
 
5651
    mRxOn = true;
343 andreas 5652
#if TESTMODE == 1
5653
    __success = true;
5654
    setAllDone();
5655
#endif
318 andreas 5656
}
5657
 
5658
void TPageManager::doRXOF(int, vector<int>&, vector<string>&)
5659
{
5660
    DECL_TRACER("TPageManager::doRXOF(int, vector<int>&, vector<string>&)");
5661
 
5662
    mRxOn = false;
343 andreas 5663
#if TESTMODE == 1
5664
    __success = true;
5665
    setAllDone();
5666
#endif
318 andreas 5667
}
5668
 
22 andreas 5669
void TPageManager::doON(int port, vector<int>&, vector<string>& pars)
14 andreas 5670
{
5671
    DECL_TRACER("TPageManager::doON(int port, vector<int>& channels, vector<string>& pars)");
5672
 
5673
    if (pars.empty())
5674
    {
5675
        MSG_WARNING("Command ON needs 1 parameter! Ignoring command.");
343 andreas 5676
#if TESTMODE == 1
5677
        setAllDone();
5678
#endif
14 andreas 5679
        return;
5680
    }
5681
 
16 andreas 5682
    TError::clear();
14 andreas 5683
    int c = atoi(pars[0].c_str());
5684
 
5685
    if (c <= 0)
5686
    {
5687
        MSG_WARNING("Invalid channel " << c << "! Ignoring command.");
343 andreas 5688
#if TESTMODE == 1
5689
        setAllDone();
5690
#endif
14 andreas 5691
        return;
5692
    }
5693
 
5694
    vector<int> chans = { c };
193 andreas 5695
    vector<TMap::MAP_T> map = findButtons(port, chans, TMap::TYPE_CM);
14 andreas 5696
 
5697
    if (TError::isError() || map.empty())
343 andreas 5698
    {
5699
#if TESTMODE == 1
5700
        setAllDone();
5701
#endif
14 andreas 5702
        return;
343 andreas 5703
    }
14 andreas 5704
 
5705
    vector<Button::TButton *> buttons = collectButtons(map);
5706
 
83 andreas 5707
    if (buttons.size() > 0)
14 andreas 5708
    {
83 andreas 5709
        vector<Button::TButton *>::iterator mapIter;
14 andreas 5710
 
118 andreas 5711
        for (mapIter = buttons.begin(); mapIter != buttons.end(); ++mapIter)
83 andreas 5712
        {
5713
            Button::TButton *bt = *mapIter;
5714
 
195 andreas 5715
            if (bt->getButtonType() == GENERAL)
343 andreas 5716
            {
83 andreas 5717
                bt->setActive(1);
343 andreas 5718
#if TESTMODE == 1
5719
                if (_gTestMode)
5720
                    _gTestMode->setResult(intToString(bt->getActiveInstance() + 1));
5721
#endif
5722
            }
83 andreas 5723
        }
14 andreas 5724
    }
343 andreas 5725
#if TESTMODE == 1
5726
    setDone();
5727
#endif
14 andreas 5728
}
5729
 
22 andreas 5730
void TPageManager::doOFF(int port, vector<int>&, vector<string>& pars)
14 andreas 5731
{
5732
    DECL_TRACER("TPageManager::doOFF(int port, vector<int>& channels, vector<string>& pars)");
5733
 
5734
    if (pars.empty())
5735
    {
5736
        MSG_WARNING("Command OFF needs 1 parameter! Ignoring command.");
343 andreas 5737
#if TESTMODE == 1
5738
        setAllDone();
5739
#endif
14 andreas 5740
        return;
5741
    }
5742
 
16 andreas 5743
    TError::clear();
14 andreas 5744
    int c = atoi(pars[0].c_str());
5745
 
5746
    if (c <= 0)
5747
    {
5748
        MSG_WARNING("Invalid channel " << c << "! Ignoring command.");
343 andreas 5749
#if TESTMODE == 1
5750
        setAllDone();
5751
#endif
14 andreas 5752
        return;
5753
    }
5754
 
5755
    vector<int> chans = { c };
193 andreas 5756
    vector<TMap::MAP_T> map = findButtons(port, chans, TMap::TYPE_CM);
14 andreas 5757
 
5758
    if (TError::isError() || map.empty())
5759
        return;
5760
 
5761
    vector<Button::TButton *> buttons = collectButtons(map);
5762
 
83 andreas 5763
    if (buttons.size() > 0)
14 andreas 5764
    {
83 andreas 5765
        vector<Button::TButton *>::iterator mapIter;
14 andreas 5766
 
118 andreas 5767
        for (mapIter = buttons.begin(); mapIter != buttons.end(); ++mapIter)
83 andreas 5768
        {
5769
            Button::TButton *bt = *mapIter;
5770
 
195 andreas 5771
            if (bt->getButtonType() == GENERAL)
83 andreas 5772
                bt->setActive(0);
343 andreas 5773
#if TESTMODE == 1
5774
                if (_gTestMode)
5775
                    _gTestMode->setResult(intToString(bt->getActiveInstance() + 1));
5776
#endif
83 andreas 5777
        }
14 andreas 5778
    }
343 andreas 5779
#if TESTMODE == 1
5780
    setDone();
5781
#endif
14 andreas 5782
}
5783
 
22 andreas 5784
void TPageManager::doLEVEL(int port, vector<int>&, vector<string>& pars)
15 andreas 5785
{
5786
    DECL_TRACER("TPageManager::doLEVEL(int port, vector<int>& channels, vector<string>& pars)");
5787
 
5788
    if (pars.size() < 2)
5789
    {
5790
        MSG_WARNING("Command LEVEL needs 2 parameters! Ignoring command.");
343 andreas 5791
#if TESTMODE == 1
5792
        setAllDone();
5793
#endif
15 andreas 5794
        return;
5795
    }
5796
 
16 andreas 5797
    TError::clear();
15 andreas 5798
    int c = atoi(pars[0].c_str());
5799
    int level = atoi(pars[1].c_str());
5800
 
5801
    if (c <= 0)
5802
    {
5803
        MSG_WARNING("Invalid channel " << c << "! Ignoring command.");
343 andreas 5804
#if TESTMODE == 1
5805
        setAllDone();
5806
#endif
15 andreas 5807
        return;
5808
    }
5809
 
5810
    vector<int> chans = { c };
193 andreas 5811
    vector<TMap::MAP_T> map = findBargraphs(port, chans);
15 andreas 5812
 
5813
    if (TError::isError() || map.empty())
5814
    {
5815
        MSG_WARNING("No bargraphs found!");
343 andreas 5816
#if TESTMODE == 1
5817
        setAllDone();
5818
#endif
15 andreas 5819
        return;
5820
    }
5821
 
5822
    vector<Button::TButton *> buttons = collectButtons(map);
5823
 
83 andreas 5824
    if (buttons.size() > 0)
15 andreas 5825
    {
429 andreas 5826
        MSG_DEBUG("Found " << buttons.size() << " buttons.");
83 andreas 5827
        vector<Button::TButton *>::iterator mapIter;
15 andreas 5828
 
118 andreas 5829
        for (mapIter = buttons.begin(); mapIter != buttons.end(); ++mapIter)
15 andreas 5830
        {
83 andreas 5831
            Button::TButton *bt = *mapIter;
429 andreas 5832
            MSG_DEBUG("Evaluating button " << handleToString(bt->getHandle()))
83 andreas 5833
 
418 andreas 5834
            if (bt->getButtonType() == BARGRAPH && bt->getLevelChannel() == c)
343 andreas 5835
            {
435 andreas 5836
                if (bt->isBargraphInverted())
5837
                    level = (bt->getRangeHigh() - bt->getRangeLow()) - level;
5838
 
83 andreas 5839
                bt->drawBargraph(bt->getActiveInstance(), level);
439 andreas 5840
                bt->sendBargraphLevel();
343 andreas 5841
#if TESTMODE == 1
5842
                if (_gTestMode)
5843
                    _gTestMode->setResult(intToString(bt->getLevelValue()));
5844
#endif
5845
            }
416 andreas 5846
            else if (bt->getButtonType() == JOYSTICK)
5847
            {
5848
                int x = (bt->getLevelChannel() == c ? level : bt->getLevelAxisX());
5849
                int y = (bt->getLevelChannel() == c ? bt->getLevelAxisY() : level);
418 andreas 5850
 
5851
                if (bt->isBargraphInverted())
435 andreas 5852
                    x = (bt->getRangeHigh() - bt->getRangeLow()) - x;
418 andreas 5853
 
5854
                if (bt->isJoystickAuxInverted())
435 andreas 5855
                    y = (bt->getRangeHigh() - bt->getRangeLow()) - y;
418 andreas 5856
 
416 andreas 5857
                bt->drawJoystick(x, y);
439 andreas 5858
                bt->sendJoystickLevels();
5859
#if TESTMODE == 1
5860
                if (_gTestMode)
5861
                {
5862
                    std::stringstream s;
5863
                    s << x << "|" << y;
5864
                    _gTestMode->setResult(s.str());
5865
                }
5866
#endif
416 andreas 5867
            }
418 andreas 5868
            else if (bt->getButtonType() == MULTISTATE_BARGRAPH && bt->getLevelChannel() == c)
83 andreas 5869
            {
5870
                int state = (int)((double)bt->getStateCount() / (double)(bt->getRangeHigh() - bt->getRangeLow()) * (double)level);
5871
                bt->setActive(state);
439 andreas 5872
                bt->sendBargraphLevel();
343 andreas 5873
#if TESTMODE == 1
5874
                if (_gTestMode)
5875
                    _gTestMode->setResult(intToString(bt->getActiveInstance()));
5876
#endif
83 andreas 5877
            }
15 andreas 5878
        }
5879
    }
429 andreas 5880
    else
5881
        MSG_DEBUG("No buttons found!");
5882
 
343 andreas 5883
#if TESTMODE == 1
5884
    setDone();
5885
#endif
15 andreas 5886
}
5887
 
22 andreas 5888
void TPageManager::doBLINK(int, vector<int>&, vector<string>& pars)
15 andreas 5889
{
5890
    DECL_TRACER("TPageManager::doBLINK(int port, vector<int>& channels, vector<string>& pars)");
5891
 
5892
    if (pars.size() < 4)
5893
    {
5894
        MSG_WARNING("Command BLINK expects 4 parameters! Command ignored.");
343 andreas 5895
#if TESTMODE == 1
5896
        setAllDone();
5897
#endif
15 andreas 5898
        return;
5899
    }
5900
 
16 andreas 5901
    TError::clear();
15 andreas 5902
    vector<int> sysButtons = { 141, 142, 143, 151, 152, 153, 154, 155, 156, 157, 158 };
193 andreas 5903
    vector<TMap::MAP_T> map = findButtons(0, sysButtons);
15 andreas 5904
 
5905
    if (TError::isError() || map.empty())
5906
    {
5907
        MSG_WARNING("No system buttons found.");
343 andreas 5908
#if TESTMODE == 1
5909
        setAllDone();
5910
#endif
15 andreas 5911
        return;
5912
    }
5913
 
5914
    vector<Button::TButton *> buttons = collectButtons(map);
5915
    vector<Button::TButton *>::iterator mapIter;
5916
 
5917
    for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
5918
    {
5919
        Button::TButton *bt = *mapIter;
5920
        bt->setActive(0);
343 andreas 5921
#if TESTMODE == 1
5922
                if (_gTestMode)
5923
                    _gTestMode->setResult(intToString(bt->getActiveInstance() + 1));
5924
#endif
15 andreas 5925
    }
343 andreas 5926
#if TESTMODE == 1
5927
    setDone();
5928
#endif
15 andreas 5929
}
5930
 
162 andreas 5931
/**
5932
 * Send the version of the panel to the NetLinx. This is the real application
5933
 * version.
5934
 */
127 andreas 5935
void TPageManager::doVER(int, vector<int>&, vector<string>&)
5936
{
5937
    DECL_TRACER("TPageManager::doVER(int, vector<int>&, vector<string>&)");
5938
 
5939
    amx::ANET_SEND scmd;
5940
    scmd.port = 1;
5941
    scmd.channel = 0;
5942
    scmd.msg.assign(string("^VER-")+VERSION_STRING());
5943
    scmd.MC = 0x008c;
5944
 
5945
    if (gAmxNet)
343 andreas 5946
    {
127 andreas 5947
        gAmxNet->sendCommand(scmd);
343 andreas 5948
#if TESTMODE == 1
5949
        __success = true;
347 andreas 5950
 
5951
        if (_gTestMode)
5952
            _gTestMode->setResult(VERSION_STRING());
343 andreas 5953
#endif
5954
    }
127 andreas 5955
    else
5956
        MSG_WARNING("Missing global class TAmxNet. Can't send message!");
343 andreas 5957
#if TESTMODE == 1
5958
    setAllDone();
5959
#endif
127 andreas 5960
}
5961
 
162 andreas 5962
/**
5963
 * Returns the user name used to connect to a SIP server. An empty string is
5964
 * returned if there is no user defined.
5965
 */
279 andreas 5966
#ifndef _NOSIP_
127 andreas 5967
void TPageManager::doWCN(int, vector<int>&, vector<string>&)
5968
{
5969
    DECL_TRACER("TPageManager::doWCN(int, vector<int>&, vector<string>&)");
5970
 
5971
    if (!TConfig::getSIPstatus())
343 andreas 5972
    {
5973
#if TESTMODE == 1
5974
        setAllDone();
5975
#endif
127 andreas 5976
        return;
343 andreas 5977
    }
127 andreas 5978
 
5979
    amx::ANET_SEND scmd;
5980
    scmd.port = 1;
5981
    scmd.channel = 0;
5982
    scmd.msg.assign("^WCN-" + TConfig::getSIPuser());
5983
    scmd.MC = 0x008c;
5984
 
5985
    if (gAmxNet)
343 andreas 5986
    {
127 andreas 5987
        gAmxNet->sendCommand(scmd);
343 andreas 5988
#if TESTMODE == 1
5989
        __success = true;
347 andreas 5990
 
5991
        if (_gTestMode)
5992
            _gTestMode->setResult(TConfig::getSIPuser());
343 andreas 5993
#endif
5994
    }
127 andreas 5995
    else
5996
        MSG_WARNING("Missing global class TAmxNet. Can't send message!");
343 andreas 5997
#if TESTMODE == 1
5998
        setAllDone();
5999
#endif
127 andreas 6000
}
279 andreas 6001
#endif
14 andreas 6002
/**
147 andreas 6003
 * Flip to specified page using the named animation.
6004
 * FIXME: Implement animation for pages.
6005
 */
6006
void TPageManager::doAFP(int, vector<int>&, vector<string>& pars)
6007
{
6008
    DECL_TRACER("TPageManager::doAFP(int, vector<int>&, vector<string>& pars)");
6009
 
6010
    if (pars.size() < 4)
6011
    {
6012
        MSG_ERROR("Less than 4 parameters!");
343 andreas 6013
#if TESTMODE == 1
6014
        setAllDone();
6015
#endif
147 andreas 6016
        return;
6017
    }
6018
 
6019
    TError::clear();
6020
    string pname = pars[0];
6021
//    string ani = pars[1];
6022
//    int origin = atoi(pars[2].c_str());
6023
//    int duration = atoi(pars[3].c_str());
6024
 
6025
    // FIXME: Animation of pages is currently not implemented.
6026
 
6027
    if (!pname.empty())
6028
        setPage(pname);
6029
    else if (mPreviousPage)
6030
        setPage(mPreviousPage);
343 andreas 6031
#if TESTMODE == 1
6032
    if (_gTestMode)
6033
        _gTestMode->setResult(getActualPage()->getName());
6034
 
6035
    setDone();
6036
#endif
147 andreas 6037
}
6038
 
6039
/**
14 andreas 6040
 * Add a specific popup page to a specified popup group if it does not already
6041
 * exist. If the new popup is added to a group which has a popup displayed on
6042
 * the current page along with the new pop-up, the displayed popup will be
6043
 * hidden and the new popup will be displayed.
6044
 */
22 andreas 6045
void TPageManager::doAPG(int, std::vector<int>&, std::vector<std::string>& pars)
11 andreas 6046
{
6047
    DECL_TRACER("TPageManager::doAPG(int port, std::vector<int>& channels, std::vector<std::string>& pars)");
6048
 
6049
    if (pars.size() < 2)
6050
    {
6051
        MSG_ERROR("Less than 2 parameters!");
343 andreas 6052
#if TESTMODE == 1
6053
        setAllDone();
6054
#endif
11 andreas 6055
        return;
6056
    }
6057
 
16 andreas 6058
    TError::clear();
11 andreas 6059
    closeGroup(pars[1]);
14 andreas 6060
 
96 andreas 6061
    TPage *page = nullptr;
6062
    TSubPage *subPage = deliverSubPage(pars[0], &page);
14 andreas 6063
 
11 andreas 6064
    if (!subPage)
6065
    {
6066
        MSG_ERROR("Subpage " << pars[0] << " couldn't either found or created!");
343 andreas 6067
#if TESTMODE == 1
6068
        setAllDone();
6069
#endif
11 andreas 6070
        return;
6071
    }
6072
 
162 andreas 6073
    if (!page)
6074
    {
6075
        MSG_ERROR("There seems to be no page for subpage " << pars[0]);
343 andreas 6076
#if TESTMODE == 1
6077
        setAllDone();
6078
#endif
162 andreas 6079
        return;
6080
    }
6081
 
152 andreas 6082
    page->addSubPage(subPage);
11 andreas 6083
    subPage->setGroup(pars[1]);
14 andreas 6084
    subPage->setZOrder(page->getNextZOrder());
152 andreas 6085
    MSG_DEBUG("Setting new Z-order " << page->getActZOrder() << " on page " << page->getName());
11 andreas 6086
    subPage->show();
343 andreas 6087
#if TESTMODE == 1
347 andreas 6088
    if (_gTestMode)
6089
        _gTestMode->setResult(subPage->getGroupName() + ":" + subPage->getName());
6090
 
343 andreas 6091
    setDone();
6092
#endif
11 andreas 6093
}
6094
 
14 andreas 6095
/**
6096
 * Clear all popup pages from specified popup group.
6097
 */
22 andreas 6098
void TPageManager::doCPG(int, std::vector<int>&, std::vector<std::string>& pars)
11 andreas 6099
{
6100
    DECL_TRACER("TPageManager::doCPG(int port, std::vector<int>& channels, std::vector<std::string>& pars)");
6101
 
6102
    if (pars.size() < 1)
6103
    {
6104
        MSG_ERROR("Expecting 1 parameter but got only 1!");
343 andreas 6105
#if TESTMODE == 1
6106
        setAllDone();
6107
#endif
11 andreas 6108
        return;
6109
    }
6110
 
16 andreas 6111
    TError::clear();
348 andreas 6112
    vector<SUBPAGELIST_T> pageList = mPageList->getSubPageList();
11 andreas 6113
 
83 andreas 6114
    if (pageList.size() > 0)
11 andreas 6115
    {
83 andreas 6116
        vector<SUBPAGELIST_T>::iterator pgIter;
6117
 
6118
        for (pgIter = pageList.begin(); pgIter != pageList.end(); pgIter++)
11 andreas 6119
        {
83 andreas 6120
            if (pgIter->group.compare(pars[0]) == 0)
6121
            {
6122
                pgIter->group.clear();
6123
                TSubPage *pg = getSubPage(pgIter->pageID);
11 andreas 6124
 
83 andreas 6125
                if (pg)
6126
                    pg->setGroup(pgIter->group);
343 andreas 6127
#if TESTMODE == 1
6128
                __success = true;
6129
#endif
83 andreas 6130
            }
11 andreas 6131
        }
6132
    }
343 andreas 6133
#if TESTMODE == 1
6134
    setDone();
6135
#endif
11 andreas 6136
}
6137
 
14 andreas 6138
/**
6139
 * Delete a specific popup page from specified popup group if it exists.
6140
 */
22 andreas 6141
void TPageManager::doDPG(int, std::vector<int>&, std::vector<std::string>& pars)
11 andreas 6142
{
6143
    DECL_TRACER("TPageManager::doDPG(int port, std::vector<int>& channels, std::vector<std::string>& pars)");
6144
 
6145
    if (pars.size() < 2)
6146
    {
6147
        MSG_ERROR("Less than 2 parameters!");
348 andreas 6148
#if TESTMODE == 1
6149
        setAllDone();
6150
#endif
11 andreas 6151
        return;
6152
    }
6153
 
16 andreas 6154
    TError::clear();
11 andreas 6155
    SUBPAGELIST_T listPg = findSubPage(pars[0]);
6156
 
6157
    if (!listPg.isValid)
348 andreas 6158
    {
6159
#if TESTMODE == 1
6160
        setAllDone();
6161
#endif
11 andreas 6162
        return;
348 andreas 6163
    }
11 andreas 6164
 
6165
    if (listPg.group.compare(pars[1]) == 0)
6166
    {
6167
        listPg.group.clear();
6168
        TSubPage *pg = getSubPage(listPg.pageID);
6169
 
6170
        if (pg)
6171
            pg->setGroup(listPg.group);
348 andreas 6172
#if TESTMODE == 1
6173
        __success = true;
6174
#endif
11 andreas 6175
    }
348 andreas 6176
#if TESTMODE == 1
6177
    setDone();
6178
#endif
11 andreas 6179
}
6180
 
14 andreas 6181
/**
15 andreas 6182
 * Set the hide effect for the specified popup page to the named hide effect.
6183
 */
22 andreas 6184
void TPageManager::doPHE(int, vector<int>&, vector<string>& pars)
15 andreas 6185
{
6186
    DECL_TRACER("TPageManager::doPHE(int port, vector<int>& channels, vector<string>& pars)");
6187
 
6188
    if (pars.size() < 2)
6189
    {
6190
        MSG_ERROR("Less than 2 parameters!");
348 andreas 6191
#if TESTMODE == 1
6192
        setAllDone();
6193
#endif
15 andreas 6194
        return;
6195
    }
6196
 
16 andreas 6197
    TError::clear();
96 andreas 6198
    TSubPage *pg = deliverSubPage(pars[0]);
15 andreas 6199
 
6200
    if (!pg)
348 andreas 6201
    {
6202
#if TESTMODE == 1
6203
        setAllDone();
6204
#endif
96 andreas 6205
        return;
348 andreas 6206
    }
15 andreas 6207
 
162 andreas 6208
    if (strCaseCompare(pars[1], "fade") == 0)
15 andreas 6209
        pg->setHideEffect(SE_FADE);
162 andreas 6210
    else if (strCaseCompare(pars[1], "slide to left") == 0)
15 andreas 6211
        pg->setHideEffect(SE_SLIDE_LEFT);
162 andreas 6212
    else if (strCaseCompare(pars[1], "slide to right") == 0)
15 andreas 6213
        pg->setHideEffect(SE_SLIDE_RIGHT);
162 andreas 6214
    else if (strCaseCompare(pars[1], "slide to top") == 0)
15 andreas 6215
        pg->setHideEffect(SE_SLIDE_TOP);
162 andreas 6216
    else if (strCaseCompare(pars[1], "slide to bottom") == 0)
15 andreas 6217
        pg->setHideEffect(SE_SLIDE_BOTTOM);
162 andreas 6218
    else if (strCaseCompare(pars[1], "slide to left fade") == 0)
15 andreas 6219
        pg->setHideEffect(SE_SLIDE_LEFT_FADE);
162 andreas 6220
    else if (strCaseCompare(pars[1], "slide to right fade") == 0)
15 andreas 6221
        pg->setHideEffect(SE_SLIDE_RIGHT_FADE);
162 andreas 6222
    else if (strCaseCompare(pars[1], "slide to top fade") == 0)
15 andreas 6223
        pg->setHideEffect(SE_SLIDE_TOP_FADE);
162 andreas 6224
    else if (strCaseCompare(pars[1], "slide to bottom fade") == 0)
15 andreas 6225
        pg->setHideEffect(SE_SLIDE_BOTTOM_FADE);
6226
    else
6227
        pg->setHideEffect(SE_NONE);
348 andreas 6228
#if TESTMODE == 1
6229
    if (_gTestMode)
6230
        _gTestMode->setResult(intToString(pg->getHideEffect()));
6231
 
6232
    __success = true;
6233
    setAllDone();
6234
#endif
15 andreas 6235
}
6236
 
6237
/**
6238
 * Set the hide effect position. Only 1 coordinate is ever needed for an effect;
6239
 * however, the command will specify both. This command sets the location at
6240
 * which the effect will end at.
6241
 */
22 andreas 6242
void TPageManager::doPHP(int, vector<int>&, vector<string>& pars)
15 andreas 6243
{
6244
    DECL_TRACER("TPageManager::doPHP(int port, vector<int>& channels, vector<string>& pars)");
6245
 
6246
    if (pars.size() < 2)
6247
    {
6248
        MSG_ERROR("Less than 2 parameters!");
348 andreas 6249
#if TESTMODE == 1
6250
        setAllDone();
6251
#endif
15 andreas 6252
        return;
6253
    }
6254
 
16 andreas 6255
    TError::clear();
15 andreas 6256
    size_t pos = pars[1].find(",");
6257
    int x, y;
6258
 
6259
    if (pos == string::npos)
6260
    {
6261
        x = atoi(pars[1].c_str());
6262
        y = 0;
6263
    }
6264
    else
6265
    {
6266
        x = atoi(pars[1].substr(0, pos).c_str());
6267
        y = atoi(pars[1].substr(pos+1).c_str());
6268
    }
6269
 
96 andreas 6270
    TSubPage *pg = deliverSubPage(pars[0]);
15 andreas 6271
 
6272
    if (!pg)
348 andreas 6273
    {
6274
#if TESTMODE == 1
6275
        setAllDone();
6276
#endif
96 andreas 6277
        return;
348 andreas 6278
    }
15 andreas 6279
 
6280
    pg->setHideEndPosition(x, y);
348 andreas 6281
#if TESTMODE == 1
6282
    if (_gTestMode)
6283
    {
6284
        int x, y;
6285
        pg->getHideEndPosition(&x, &y);
6286
        _gTestMode->setResult(intToString(x) + "," + intToString(y));
6287
    }
6288
 
6289
    __success = true;
6290
    setAllDone();
6291
#endif
15 andreas 6292
}
6293
 
6294
/**
6295
 * Set the hide effect time for the specified popup page.
6296
 */
22 andreas 6297
void TPageManager::doPHT(int, vector<int>&, vector<string>& pars)
15 andreas 6298
{
6299
    DECL_TRACER("TPageManager::doPHT(int port, vector<int>& channels, vector<string>& pars)");
6300
 
6301
    if (pars.size() < 2)
6302
    {
6303
        MSG_ERROR("Less than 2 parameters!");
348 andreas 6304
#if TESTMODE == 1
6305
        setAllDone();
6306
#endif
15 andreas 6307
        return;
6308
    }
6309
 
16 andreas 6310
    TError::clear();
96 andreas 6311
    TSubPage *pg = deliverSubPage(pars[0]);
15 andreas 6312
 
6313
    if (!pg)
348 andreas 6314
    {
6315
#if TESTMODE == 1
6316
        setAllDone();
6317
#endif
96 andreas 6318
        return;
348 andreas 6319
    }
15 andreas 6320
 
6321
    pg->setHideTime(atoi(pars[1].c_str()));
348 andreas 6322
#if TESTMODE == 1
6323
    if (_gTestMode)
6324
        _gTestMode->setResult(intToString(pg->getHideTime()));
6325
 
6326
    __success = true;
6327
    setAllDone();
6328
#endif
15 andreas 6329
}
6330
 
6331
/**
14 andreas 6332
 * Close all popups on a specified page. If the page name is empty, the current
6333
 * page is used. Same as the ’Clear Page’ command in TPDesign4.
6334
 */
22 andreas 6335
void TPageManager::doPPA(int, std::vector<int>&, std::vector<std::string>& pars)
11 andreas 6336
{
6337
    DECL_TRACER("TPageManager::doPPA(int port, std::vector<int>& channels, std::vector<std::string>& pars)");
6338
 
16 andreas 6339
    TError::clear();
11 andreas 6340
    TPage *pg;
6341
 
6342
    if (pars.size() == 0)
6343
        pg = getPage(mActualPage);
6344
    else
6345
        pg = getPage(pars[0]);
6346
 
6347
    if (!pg)
348 andreas 6348
    {
6349
#if TESTMODE == 1
6350
        setAllDone();
6351
#endif
11 andreas 6352
        return;
348 andreas 6353
    }
11 andreas 6354
 
12 andreas 6355
    pg->drop();
14 andreas 6356
    pg->resetZOrder();
348 andreas 6357
#if TESTMODE == 1
6358
    setDone();
6359
#endif
11 andreas 6360
}
6361
 
14 andreas 6362
/**
6363
 * Deactivate a specific popup page on either a specified page or the current
6364
 * page. If the page name is empty, the current page is used. If the popup page
6365
 * is part of a group, the whole group is deactivated. This command works in
6366
 * the same way as the ’Hide Popup’ command in TPDesign4.
6367
 */
22 andreas 6368
void TPageManager::doPPF(int, std::vector<int>&, std::vector<std::string>& pars)
12 andreas 6369
{
6370
    DECL_TRACER("TPageManager::doPPF(int port, std::vector<int>& channels, std::vector<std::string>& pars)");
6371
 
6372
    if (pars.size() < 1)
6373
    {
6374
        MSG_ERROR("At least 1 parameter is expected!");
349 andreas 6375
#if TESTMODE == 1
6376
        setAllDone();
6377
#endif
12 andreas 6378
        return;
6379
    }
6380
 
16 andreas 6381
    TError::clear();
14 andreas 6382
    hideSubPage(pars[0]);
335 andreas 6383
#if TESTMODE == 1
6384
    setDone();
6385
#endif
12 andreas 6386
}
6387
 
14 andreas 6388
/**
6389
 * Toggle a specific popup page on either a specified page or the current page.
6390
 * If the page name is empty, the current page is used. Toggling refers to the
6391
 * activating/deactivating (On/Off) of a popup page. This command works in the
6392
 * same way as the ’Toggle Popup’ command in TPDesign4.
6393
 */
22 andreas 6394
void TPageManager::doPPG(int, std::vector<int>&, std::vector<std::string>& pars)
12 andreas 6395
{
6396
    DECL_TRACER("TPageManager::doPPG(int port, std::vector<int>& channels, std::vector<std::string>& pars)");
14 andreas 6397
 
12 andreas 6398
    if (pars.size() < 1)
6399
    {
6400
        MSG_ERROR("At least 1 parameter is expected!");
349 andreas 6401
#if TESTMODE == 1
6402
        setAllDone();
6403
#endif
12 andreas 6404
        return;
6405
    }
6406
 
16 andreas 6407
    TError::clear();
14 andreas 6408
    TPage *page = getPage(mActualPage);
6409
 
6410
    if (!page)
6411
    {
6412
        MSG_ERROR("No active page found! Internal error.");
349 andreas 6413
#if TESTMODE == 1
6414
        setAllDone();
6415
#endif
14 andreas 6416
        return;
6417
    }
6418
 
12 andreas 6419
    TSubPage *pg = getSubPage(pars[0]);
14 andreas 6420
 
12 andreas 6421
    if (!pg)
349 andreas 6422
    {
6423
#if TESTMODE == 1
6424
        setAllDone();
6425
#endif
12 andreas 6426
        return;
349 andreas 6427
    }
14 andreas 6428
 
12 andreas 6429
    if (pg->isVisible())
6430
    {
6431
        pg->drop();
162 andreas 6432
        page->decZOrder();
349 andreas 6433
#if TESTMODE == 1
6434
        setDone();
6435
#endif
12 andreas 6436
        return;
6437
    }
6438
 
6439
    TSubPage *sub = getFirstSubPageGroup(pg->getGroupName());
14 andreas 6440
 
12 andreas 6441
    while(sub)
6442
    {
6443
        if (sub->getGroupName().compare(pg->getGroupName()) == 0 && sub->isVisible())
6444
            sub->drop();
14 andreas 6445
 
12 andreas 6446
        sub = getNextSubPageGroup(pg->getGroupName(), sub);
6447
    }
6448
 
152 andreas 6449
    pg->setZOrder(page->getNextZOrder());
6450
    MSG_DEBUG("Setting new Z-order " << page->getActZOrder() << " on page " << page->getName());
12 andreas 6451
    pg->show();
349 andreas 6452
#if TESTMODE == 1
6453
    setDone();
6454
#endif
12 andreas 6455
}
6456
 
14 andreas 6457
/**
6458
 * Kill refers to the deactivating (Off) of a popup window from all pages. If
6459
 * the pop-up page is part of a group, the whole group is deactivated. This
6460
 * command works in the same way as the 'Clear Group' command in TPDesign 4.
6461
 */
22 andreas 6462
void TPageManager::doPPK(int, std::vector<int>&, std::vector<std::string>& pars)
12 andreas 6463
{
6464
    DECL_TRACER("TPageManager::doPPK(int port, std::vector<int>& channels, std::vector<std::string>& pars)");
14 andreas 6465
 
12 andreas 6466
    if (pars.size() < 1)
6467
    {
6468
        MSG_ERROR("At least 1 parameter is expected!");
349 andreas 6469
#if TESTMODE == 1
6470
        setAllDone();
6471
#endif
12 andreas 6472
        return;
6473
    }
6474
 
16 andreas 6475
    TError::clear();
14 andreas 6476
    TPage *page = getPage(mActualPage);
6477
 
6478
    if (!page)
6479
    {
6480
        MSG_ERROR("No active page found! Internal error.");
349 andreas 6481
#if TESTMODE == 1
6482
        setAllDone();
6483
#endif
14 andreas 6484
        return;
6485
    }
6486
 
12 andreas 6487
    TSubPage *pg = getSubPage(pars[0]);
14 andreas 6488
 
12 andreas 6489
    if (pg)
14 andreas 6490
    {
6491
        pg->drop();
162 andreas 6492
        page->decZOrder();
14 andreas 6493
    }
349 andreas 6494
#if TESTMODE == 1
6495
        setDone();
6496
#endif
12 andreas 6497
}
6498
 
14 andreas 6499
/**
6500
 * Set the modality of a specific popup page to Modal or NonModal.
6501
 * A Modal popup page, when active, only allows you to use the buttons and
6502
 * features on that popup page. All other buttons on the panel page are
6503
 * inactivated.
6504
 */
22 andreas 6505
void TPageManager::doPPM(int, std::vector<int>&, std::vector<std::string>& pars)
12 andreas 6506
{
6507
    DECL_TRACER("TPageManager::doPPM(int port, std::vector<int>& channels, std::vector<std::string>& pars)");
14 andreas 6508
 
12 andreas 6509
    if (pars.size() < 2)
6510
    {
6511
        MSG_ERROR("Expecting 2 parameters!");
349 andreas 6512
#if TESTMODE == 1
6513
        setAllDone();
6514
#endif
12 andreas 6515
        return;
6516
    }
14 andreas 6517
 
16 andreas 6518
    TError::clear();
12 andreas 6519
    TSubPage *pg = getSubPage(pars[0]);
14 andreas 6520
 
12 andreas 6521
    if (pg)
6522
    {
162 andreas 6523
        if (pars[1] == "1" || strCaseCompare(pars[1], "modal") == 0)
12 andreas 6524
            pg->setModal(1);
6525
        else
6526
            pg->setModal(0);
349 andreas 6527
#if TESTMODE == 1
6528
        if (_gTestMode)
6529
            _gTestMode->setResult(pg->isModal() ? "TRUE" : "FALSE");
6530
#endif
12 andreas 6531
    }
349 andreas 6532
#if TESTMODE == 1
6533
        setAllDone();
6534
#endif
12 andreas 6535
}
6536
 
14 andreas 6537
/**
6538
 * Activate a specific popup page to launch on either a specified page or the
6539
 * current page. If the page name is empty, the current page is used. If the
6540
 * popup page is already on, do not re-draw it. This command works in the same
6541
 * way as the ’Show Popup’ command in TPDesign4.
6542
 */
22 andreas 6543
void TPageManager::doPPN(int, std::vector<int>&, std::vector<std::string>& pars)
12 andreas 6544
{
6545
    DECL_TRACER("TPageManager::doPPN(int port, std::vector<int>& channels, std::vector<std::string>& pars)");
6546
 
6547
    if (pars.size() < 1)
6548
    {
6549
        MSG_ERROR("At least 1 parameter is expected!");
349 andreas 6550
#if TESTMODE == 1
6551
        setAllDone();
6552
#endif
12 andreas 6553
        return;
6554
    }
6555
 
16 andreas 6556
    TError::clear();
14 andreas 6557
    showSubPage(pars[0]);
349 andreas 6558
#if TESTMODE == 1
6559
    setDone();
6560
#endif
12 andreas 6561
}
6562
 
14 andreas 6563
/**
15 andreas 6564
 * Set a specific popup page to timeout within a specified time. If timeout is
6565
 * empty, popup page will clear the timeout.
6566
 */
22 andreas 6567
void TPageManager::doPPT(int, vector<int>&, vector<string>& pars)
15 andreas 6568
{
6569
    DECL_TRACER("TPageManager::doPPT(int port, vector<int>& channels, vector<string>& pars)");
6570
 
6571
    if (pars.size() < 2)
6572
    {
6573
        MSG_ERROR("Expecting 2 parameters!");
351 andreas 6574
#if TESTMODE == 1
6575
        setAllDone();
6576
#endif
15 andreas 6577
        return;
6578
    }
6579
 
16 andreas 6580
    TError::clear();
96 andreas 6581
    TSubPage *pg = deliverSubPage(pars[0]);
15 andreas 6582
 
6583
    if (!pg)
351 andreas 6584
    {
6585
#if TESTMODE == 1
6586
        setAllDone();
6587
#endif
96 andreas 6588
        return;
351 andreas 6589
    }
15 andreas 6590
 
6591
    pg->setTimeout(atoi(pars[1].c_str()));
351 andreas 6592
#if TESTMODE == 1
6593
    if (_gTestMode)
6594
        _gTestMode->setResult(intToString(pg->getTimeout()));
6595
 
6596
    __success = true;
6597
    setAllDone();
6598
#endif
15 andreas 6599
}
6600
 
6601
/**
14 andreas 6602
 * Close all popups on all pages. This command works in the same way as the
6603
 * 'Clear All' command in TPDesign 4.
6604
 */
22 andreas 6605
void TPageManager::doPPX(int, std::vector<int>&, std::vector<std::string>&)
12 andreas 6606
{
6607
    DECL_TRACER("TPageManager::doPPX(int port, std::vector<int>& channels, std::vector<std::string>& pars)");
6608
 
16 andreas 6609
    TError::clear();
12 andreas 6610
    PCHAIN_T *chain = mPchain;
14 andreas 6611
 
12 andreas 6612
    while(chain)
6613
    {
6614
        TSubPage *sub = chain->page->getFirstSubPage();
14 andreas 6615
 
12 andreas 6616
        while (sub)
6617
        {
351 andreas 6618
            MSG_DEBUG("Dropping subpage " << sub->getNumber() << ", \"" << sub->getName() << "\".");
12 andreas 6619
            sub->drop();
6620
            sub = chain->page->getNextSubPage();
6621
        }
14 andreas 6622
 
12 andreas 6623
        chain = chain->next;
6624
    }
14 andreas 6625
 
6626
    TPage *page = getPage(mActualPage);
6627
 
6628
    if (!page)
6629
    {
6630
        MSG_ERROR("No active page found! Internal error.");
351 andreas 6631
#if TESTMODE == 1
6632
        setAllDone();
6633
#endif
14 andreas 6634
        return;
6635
    }
6636
 
6637
    page->resetZOrder();
351 andreas 6638
#if TESTMODE == 1
6639
    setDone();
6640
#endif
12 andreas 6641
}
6642
 
14 andreas 6643
/**
15 andreas 6644
 * Set the show effect for the specified popup page to the named show effect.
6645
 */
22 andreas 6646
void TPageManager::doPSE(int, vector<int>&, vector<string>& pars)
15 andreas 6647
{
6648
    DECL_TRACER("TPageManager::doPSE(int port, vector<int>& channels, vector<string>& pars)");
6649
 
6650
    if (pars.size() < 2)
6651
    {
6652
        MSG_ERROR("Less than 2 parameters!");
351 andreas 6653
#if TESTMODE == 1
6654
        setAllDone();
6655
#endif
15 andreas 6656
        return;
6657
    }
6658
 
16 andreas 6659
    TError::clear();
96 andreas 6660
    TSubPage *pg = deliverSubPage(pars[0]);
15 andreas 6661
 
6662
    if (!pg)
351 andreas 6663
    {
6664
#if TESTMODE == 1
6665
        setAllDone();
6666
#endif
96 andreas 6667
        return;
351 andreas 6668
    }
15 andreas 6669
 
162 andreas 6670
    if (strCaseCompare(pars[1], "fade") == 0)
15 andreas 6671
        pg->setShowEffect(SE_FADE);
162 andreas 6672
    else if (strCaseCompare(pars[1], "slide to left") == 0)
15 andreas 6673
        pg->setShowEffect(SE_SLIDE_LEFT);
162 andreas 6674
    else if (strCaseCompare(pars[1], "slide to right") == 0)
15 andreas 6675
        pg->setShowEffect(SE_SLIDE_RIGHT);
162 andreas 6676
    else if (strCaseCompare(pars[1], "slide to top") == 0)
15 andreas 6677
        pg->setShowEffect(SE_SLIDE_TOP);
162 andreas 6678
    else if (strCaseCompare(pars[1], "slide to bottom") == 0)
15 andreas 6679
        pg->setShowEffect(SE_SLIDE_BOTTOM);
162 andreas 6680
    else if (strCaseCompare(pars[1], "slide to left fade") == 0)
15 andreas 6681
        pg->setShowEffect(SE_SLIDE_LEFT_FADE);
162 andreas 6682
    else if (strCaseCompare(pars[1], "slide to right fade") == 0)
15 andreas 6683
        pg->setShowEffect(SE_SLIDE_RIGHT_FADE);
162 andreas 6684
    else if (strCaseCompare(pars[1], "slide to top fade") == 0)
15 andreas 6685
        pg->setShowEffect(SE_SLIDE_TOP_FADE);
162 andreas 6686
    else if (strCaseCompare(pars[1], "slide to bottom fade") == 0)
15 andreas 6687
        pg->setShowEffect(SE_SLIDE_BOTTOM_FADE);
6688
    else
6689
        pg->setShowEffect(SE_NONE);
351 andreas 6690
#if TESTMODE == 1
6691
    if (_gTestMode)
6692
        _gTestMode->setResult(intToString(pg->getShowEffect()));
6693
 
6694
    __success = true;
6695
    setAllDone();
6696
#endif
15 andreas 6697
}
6698
 
162 andreas 6699
/**
6700
 * Set the show effect position. Only 1 coordinate is ever needed for an effect;
6701
 * however, the command will specify both. This command sets the location at
6702
 * which the effect will begin.
6703
 */
22 andreas 6704
void TPageManager::doPSP(int, vector<int>&, vector<string>& pars)
15 andreas 6705
{
6706
    DECL_TRACER("TPageManager::doPSP(int port, vector<int>& channels, vector<string>& pars)");
6707
 
6708
    if (pars.size() < 2)
6709
    {
6710
        MSG_ERROR("Less than 2 parameters!");
351 andreas 6711
#if TESTMODE == 1
6712
        setAllDone();
6713
#endif
15 andreas 6714
        return;
6715
    }
6716
 
16 andreas 6717
    TError::clear();
15 andreas 6718
    size_t pos = pars[1].find(",");
6719
    int x, y;
6720
 
6721
    if (pos == string::npos)
6722
    {
6723
        x = atoi(pars[1].c_str());
6724
        y = 0;
6725
    }
6726
    else
6727
    {
6728
        x = atoi(pars[1].substr(0, pos).c_str());
6729
        y = atoi(pars[1].substr(pos+1).c_str());
6730
    }
6731
 
96 andreas 6732
    TSubPage *pg = deliverSubPage(pars[0]);
15 andreas 6733
 
6734
    if (!pg)
351 andreas 6735
    {
6736
#if TESTMODE == 1
6737
        setAllDone();
6738
#endif
96 andreas 6739
        return;
351 andreas 6740
    }
15 andreas 6741
 
6742
    pg->setShowEndPosition(x, y);
351 andreas 6743
#if TESTMODE == 1
6744
    pg->getShowEndPosition(&x, &y);
6745
 
6746
    if (_gTestMode)
6747
        _gTestMode->setResult(intToString(x) + "," + intToString(y));
6748
 
6749
    __success = true;
6750
    setAllDone();
6751
#endif
15 andreas 6752
}
6753
 
6754
/**
6755
 * Set the show effect time for the specified popup page.
6756
 */
22 andreas 6757
void TPageManager::doPST(int, vector<int>&, vector<string>& pars)
15 andreas 6758
{
6759
    DECL_TRACER("TPageManager::doPST(int port, vector<int>& channels, vector<string>& pars)");
6760
 
6761
    if (pars.size() < 2)
6762
    {
6763
        MSG_ERROR("Less than 2 parameters!");
351 andreas 6764
#if TESTMODE == 1
6765
        setAllDone();
6766
#endif
15 andreas 6767
        return;
6768
    }
6769
 
16 andreas 6770
    TError::clear();
96 andreas 6771
    TSubPage *pg = deliverSubPage(pars[0]);
15 andreas 6772
 
6773
    if (!pg)
351 andreas 6774
    {
6775
#if TESTMODE == 1
6776
        setAllDone();
6777
#endif
96 andreas 6778
        return;
351 andreas 6779
    }
15 andreas 6780
 
6781
    pg->setShowTime(atoi(pars[1].c_str()));
351 andreas 6782
#if TESTMODE == 1
6783
    if (_gTestMode)
6784
        _gTestMode->setResult(intToString(pg->getShowTime()));
6785
 
6786
    __success = 1;
6787
    setAllDone();
6788
#endif
15 andreas 6789
}
6790
 
6791
/**
14 andreas 6792
 * Flips to a page with a specified page name. If the page is currently active,
6793
 * it will not redraw the page.
6794
 */
22 andreas 6795
void TPageManager::doPAGE(int, std::vector<int>&, std::vector<std::string>& pars)
12 andreas 6796
{
6797
    DECL_TRACER("TPageManager::doPAGE(int port, std::vector<int>& channels, std::vector<std::string>& pars)");
14 andreas 6798
 
15 andreas 6799
    if (pars.empty())
6800
    {
6801
        MSG_WARNING("Got no page parameter!");
351 andreas 6802
#if TESTMODE == 1
6803
        setAllDone();
6804
#endif
15 andreas 6805
        return;
6806
    }
14 andreas 6807
 
16 andreas 6808
    TError::clear();
15 andreas 6809
    setPage(pars[0]);
351 andreas 6810
#if TESTMODE == 1
6811
    if (_gTestMode)
6812
        _gTestMode->setResult(intToString(getActualPageNumber()));
6813
 
6814
    setDone();
6815
#endif
15 andreas 6816
}
6817
 
6818
/**
38 andreas 6819
 * @brief TPageManager::doANI Run a button animation (in 1/10 second).
6820
 * Syntax:
6821
 *      ^ANI-<vt addr range>,<start state>,<end state>,<time>
6822
 * Variable:
6823
 *      variable text address range = 1 - 4000.
6824
 *      start state = Beginning of button state (0= current state).
6825
 *      end state = End of button state.
6826
 *      time = In 1/10 second intervals.
6827
 * Example:
6828
 *      SEND_COMMAND Panel,"'^ANI-500,1,25,100'"
6829
 * Runs a button animation at text range 500 from state 1 to state 25 for 10 seconds.
6830
 *
6831
 * @param port      The port number
6832
 * @param channels  The channels of the buttons
6833
 * @param pars      The parameters
6834
 */
6835
void TPageManager::doANI(int port, std::vector<int> &channels, std::vector<std::string> &pars)
6836
{
6837
    DECL_TRACER("TPageManager::doANI(int port, std::vector<int> &channels, std::vector<std::string> &pars)");
6838
 
6839
    if (pars.size() < 3)
6840
    {
6841
        MSG_ERROR("Expecting 3 parameters but got " << pars.size() << "! Ignoring command.");
6842
        return;
6843
    }
6844
 
6845
    TError::clear();
6846
    int stateStart = atoi(pars[0].c_str());
6847
    int endState = atoi(pars[1].c_str());
6848
    int runTime = atoi(pars[2].c_str());
6849
 
193 andreas 6850
    vector<TMap::MAP_T> map = findButtons(port, channels);
38 andreas 6851
 
6852
    if (TError::isError() || map.empty())
6853
        return;
6854
 
6855
    vector<Button::TButton *> buttons = collectButtons(map);
6856
 
83 andreas 6857
    if (buttons.size() > 0)
38 andreas 6858
    {
83 andreas 6859
        vector<Button::TButton *>::iterator mapIter;
6860
 
6861
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
6862
        {
6863
            Button::TButton *bt = *mapIter;
6864
            bt->startAnimation(stateStart, endState, runTime);
6865
        }
38 andreas 6866
    }
351 andreas 6867
#if TESTMODE == 1
6868
    if (_gTestMode)
6869
        _gTestMode->setResult(intToString(stateStart) + "," + intToString(endState) + "," + intToString(runTime));
6870
 
6871
    setDone();
6872
#endif
38 andreas 6873
}
6874
 
6875
/**
15 andreas 6876
 * Add page flip action to a button if it does not already exist.
6877
 */
6878
void TPageManager::doAPF(int port, vector<int>& channels, vector<string>& pars)
6879
{
6880
    DECL_TRACER("TPageManager::doAPF(int port, vector<int>& channels, vector<string>& pars)");
6881
 
6882
    if (pars.size() < 2)
6883
    {
6884
        MSG_ERROR("Expecting 2 parameters but got " << pars.size() << "! Ignoring command.");
351 andreas 6885
#if TESTMODE == 1
6886
        setAllDone();
6887
#endif
14 andreas 6888
        return;
15 andreas 6889
    }
14 andreas 6890
 
16 andreas 6891
    TError::clear();
15 andreas 6892
    string action = pars[0];
6893
    string pname = pars[1];
14 andreas 6894
 
193 andreas 6895
    vector<TMap::MAP_T> map = findButtons(port, channels);
14 andreas 6896
 
15 andreas 6897
    if (TError::isError() || map.empty())
351 andreas 6898
    {
6899
#if TESTMODE == 1
6900
        setAllDone();
6901
#endif
15 andreas 6902
        return;
351 andreas 6903
    }
15 andreas 6904
 
6905
    vector<Button::TButton *> buttons = collectButtons(map);
6906
 
83 andreas 6907
    if (buttons.size() > 0)
12 andreas 6908
    {
83 andreas 6909
        vector<Button::TButton *>::iterator mapIter;
6910
 
6911
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
6912
        {
6913
            Button::TButton *bt = *mapIter;
6914
            bt->addPushFunction(action, pname);
6915
        }
15 andreas 6916
    }
351 andreas 6917
#if TESTMODE == 1
6918
    if (_gTestMode)
6919
        _gTestMode->setResult(toUpper(action) + "," + toUpper(pname));
6920
 
6921
    __success = true;
6922
    setAllDone();
6923
#endif
15 andreas 6924
}
12 andreas 6925
 
15 andreas 6926
/**
43 andreas 6927
 * Append non-unicode text.
6928
 */
6929
void TPageManager::doBAT(int port, vector<int> &channels, vector<string> &pars)
6930
{
6931
    DECL_TRACER("TPageManager::doBAT(int port, vector<int> &channels, vector<string> &pars)");
6932
 
6933
    if (pars.size() < 1)
6934
    {
6935
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
330 andreas 6936
#if TESTMODE == 1
334 andreas 6937
        setAllDone();
330 andreas 6938
#endif
43 andreas 6939
        return;
6940
    }
6941
 
6942
    TError::clear();
6943
    int btState = atoi(pars[0].c_str());
6944
    string text;
6945
 
6946
    if (pars.size() > 1)
6947
        text = pars[1];
6948
 
193 andreas 6949
    vector<TMap::MAP_T> map = findButtons(port, channels);
43 andreas 6950
 
6951
    if (TError::isError() || map.empty())
330 andreas 6952
    {
6953
#if TESTMODE == 1
334 andreas 6954
        setAllDone();
330 andreas 6955
#endif
43 andreas 6956
        return;
330 andreas 6957
    }
43 andreas 6958
 
6959
    vector<Button::TButton *> buttons = collectButtons(map);
6960
 
162 andreas 6961
    if (buttons.empty())
330 andreas 6962
    {
6963
#if TESTMODE == 1
334 andreas 6964
        setAllDone();
330 andreas 6965
#endif
162 andreas 6966
        return;
330 andreas 6967
    }
162 andreas 6968
 
6969
    vector<Button::TButton *>::iterator mapIter;
6970
 
6971
    for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
43 andreas 6972
    {
162 andreas 6973
        Button::TButton *bt = *mapIter;
43 andreas 6974
 
331 andreas 6975
        bt->appendText(text, btState - 1);
330 andreas 6976
#if TESTMODE == 1
331 andreas 6977
        if (_gTestMode)
330 andreas 6978
        {
331 andreas 6979
            int st = (btState > 0 ? (btState - 1) : 0);
6980
            _gTestMode->setResult(bt->getText(st));
333 andreas 6981
        }
330 andreas 6982
 
331 andreas 6983
        __success = true;
330 andreas 6984
#endif
43 andreas 6985
    }
334 andreas 6986
#if TESTMODE == 1
6987
    setDone();
6988
#endif
43 andreas 6989
}
6990
 
6991
/**
60 andreas 6992
 * @brief Append unicode text. Same format as ^UNI.
6993
 * This command allows to set up to 50 characters of ASCII code. The unicode
6994
 * characters must be set as hex numbers.
6995
 */
6996
void TPageManager::doBAU(int port, vector<int>& channels, vector<string>& pars)
6997
{
6998
    DECL_TRACER("TPageManager::doBAU(int port, vector<int>& channels, vector<string>& pars)");
6999
 
7000
    if (pars.size() < 1)
7001
    {
7002
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
351 andreas 7003
#if TESTMODE == 1
7004
        setAllDone();
7005
#endif
60 andreas 7006
        return;
7007
    }
7008
 
7009
    TError::clear();
7010
    int btState = atoi(pars[0].c_str());
7011
    string text;
7012
    char ch[3];
7013
 
331 andreas 7014
    if (pars.size() > 1)
7015
        text = pars[1];
7016
 
7017
    if ((text.size() % 4) == 0)
60 andreas 7018
    {
162 andreas 7019
        try
60 andreas 7020
        {
162 andreas 7021
            text = pars[1];
331 andreas 7022
            MSG_DEBUG("Processing UTF16 string: " << text);
162 andreas 7023
            // Because the unicode characters are hex numbers, we scan the text
7024
            // and convert the hex numbers into real numbers.
7025
            size_t len = text.length();
7026
            bool inHex = false;
7027
            int lastChar = 0;
331 andreas 7028
            uint16_t *numstr = new uint16_t[len / 4];
162 andreas 7029
            int uniPos = 0;
331 andreas 7030
            int cntCount = 0;
60 andreas 7031
 
162 andreas 7032
            for (size_t i = 0; i < len; i++)
60 andreas 7033
            {
162 andreas 7034
                int c = text.at(i);
60 andreas 7035
 
162 andreas 7036
                if (!inHex && isHex(c))
7037
                {
7038
                    inHex = true;
7039
                    lastChar = c;
7040
                    continue;
7041
                }
7042
 
7043
                if (inHex && !isHex(c))
7044
                    break;
7045
 
7046
                if (inHex && isHex(c))
7047
                {
7048
                    ch[0] = lastChar;
7049
                    ch[1] = c;
7050
                    ch[2] = 0;
7051
                    uint16_t num = (uint16_t)strtol(ch, NULL, 16);
331 andreas 7052
 
7053
                    if ((cntCount % 2) != 0)
7054
                    {
7055
                        numstr[uniPos] |= num;
7056
                        uniPos++;
7057
                    }
7058
                    else
7059
                        numstr[uniPos] = (num << 8) & 0xff00;
7060
 
7061
                    cntCount++;
162 andreas 7062
                    inHex = false;
7063
 
7064
                    if (uniPos >= 50)
7065
                        break;
331 andreas 7066
                }
7067
            }
162 andreas 7068
 
331 andreas 7069
            text.clear();
7070
            // Here we make from the real numbers a UTF8 string
7071
            for (size_t i = 0; i < len / 4; ++i)
7072
            {
7073
                if (numstr[i] <= 0x00ff)
7074
                {
7075
                    ch[0] = numstr[i];
7076
                    ch[1] = 0;
7077
                    text.append(ch);
162 andreas 7078
                }
331 andreas 7079
                else
7080
                {
7081
                    ch[0] = (numstr[i] >> 8) & 0x00ff;
7082
                    ch[1] = numstr[i] & 0x00ff;
7083
                    ch[2] = 0;
7084
                    text.append(ch);
7085
                }
60 andreas 7086
            }
7087
 
331 andreas 7088
            delete[] numstr;
60 andreas 7089
        }
162 andreas 7090
        catch (std::exception const & e)
7091
        {
7092
            MSG_ERROR("Character conversion error: " << e.what());
351 andreas 7093
#if TESTMODE == 1
7094
            setAllDone();
7095
#endif
162 andreas 7096
            return;
7097
        }
60 andreas 7098
    }
331 andreas 7099
    else
7100
    {
7101
        MSG_WARNING("No or invalid UTF16 string: " << text);
351 andreas 7102
#if TESTMODE == 1
7103
        setAllDone();
7104
#endif
331 andreas 7105
        return;
7106
    }
60 andreas 7107
 
193 andreas 7108
    vector<TMap::MAP_T> map = findButtons(port, channels);
60 andreas 7109
 
7110
    if (TError::isError() || map.empty())
351 andreas 7111
    {
7112
#if TESTMODE == 1
7113
        setAllDone();
7114
#endif
60 andreas 7115
        return;
351 andreas 7116
    }
60 andreas 7117
 
7118
    vector<Button::TButton *> buttons = collectButtons(map);
7119
 
83 andreas 7120
    if (buttons.size() > 0)
60 andreas 7121
    {
83 andreas 7122
        vector<Button::TButton *>::iterator mapIter;
60 andreas 7123
 
83 andreas 7124
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
60 andreas 7125
        {
83 andreas 7126
            Button::TButton *bt = *mapIter;
60 andreas 7127
 
331 andreas 7128
            bt->appendText(text, btState - 1);
330 andreas 7129
#if TESTMODE == 1
331 andreas 7130
            if (_gTestMode)
7131
                _gTestMode->setResult(bt->getText(btState - 1));
330 andreas 7132
 
331 andreas 7133
            __success = true;
330 andreas 7134
#endif
60 andreas 7135
        }
7136
    }
330 andreas 7137
#if TESTMODE == 1
334 andreas 7138
    setDone();
330 andreas 7139
#endif
60 andreas 7140
}
7141
 
7142
/**
43 andreas 7143
 * @brief TPageManager::doBCB Set the border color.
7144
 * Set the border color to the specified color. Only if the specified border
7145
 * color is not the same as the current color.
7146
 * Note: Color can be assigned by color name (without spaces), number or
7147
 * R,G,B value (RRGGBB or RRGGBBAA).
7148
 */
7149
void TPageManager::doBCB(int port, vector<int> &channels, vector<string> &pars)
7150
{
7151
    DECL_TRACER("TPageManager::doBCB(int port, vector<int> &channels, vector<string> &pars)");
7152
 
7153
    if (pars.size() < 1)
7154
    {
7155
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
351 andreas 7156
#if TESTMODE == 1
7157
        setAllDone();
7158
#endif
43 andreas 7159
        return;
7160
    }
7161
 
7162
    TError::clear();
7163
    int btState = atoi(pars[0].c_str());
7164
    string color;
7165
 
7166
    if (pars.size() > 1)
7167
        color = pars[1];
7168
 
193 andreas 7169
    vector<TMap::MAP_T> map = findButtons(port, channels);
43 andreas 7170
 
7171
    if (TError::isError() || map.empty())
351 andreas 7172
    {
7173
#if TESTMODE == 1
7174
        setAllDone();
7175
#endif
43 andreas 7176
        return;
351 andreas 7177
    }
43 andreas 7178
 
7179
    vector<Button::TButton *> buttons = collectButtons(map);
7180
 
83 andreas 7181
    if (buttons.size() > 0)
43 andreas 7182
    {
83 andreas 7183
        vector<Button::TButton *>::iterator mapIter;
43 andreas 7184
 
83 andreas 7185
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
43 andreas 7186
        {
83 andreas 7187
            Button::TButton *bt = *mapIter;
351 andreas 7188
            bt->setBorderColor(color, btState - 1);
7189
#if TESTMODE == 1
7190
            if (_gTestMode)
7191
                _gTestMode->setResult(bt->getBorderColor(btState == 0 ? 0 : btState - 1));
7192
#endif
43 andreas 7193
        }
7194
    }
351 andreas 7195
#if TESTMODE == 1
7196
    setDone();
7197
#endif
43 andreas 7198
}
60 andreas 7199
 
351 andreas 7200
/*
7201
 * Get the border color and send it as a custom event.
7202
 */
82 andreas 7203
void TPageManager::getBCB(int port, vector<int> &channels, vector<string> &pars)
7204
{
7205
    DECL_TRACER("TPageManager::getBCB(int port, vector<int> &channels, vector<string> &pars)");
7206
 
7207
    if (pars.size() < 1)
7208
    {
7209
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
351 andreas 7210
#if TESTMODE == 1
7211
        setAllDone();
7212
#endif
82 andreas 7213
        return;
7214
    }
7215
 
7216
    TError::clear();
7217
    int btState = atoi(pars[0].c_str());
7218
    string color;
7219
 
193 andreas 7220
    vector<TMap::MAP_T> map = findButtons(port, channels);
82 andreas 7221
 
7222
    if (TError::isError() || map.empty())
351 andreas 7223
    {
7224
#if TESTMODE == 1
7225
        setAllDone();
7226
#endif
82 andreas 7227
        return;
351 andreas 7228
    }
82 andreas 7229
 
7230
    vector<Button::TButton *> buttons = collectButtons(map);
7231
 
351 andreas 7232
    if (buttons.empty())
82 andreas 7233
    {
351 andreas 7234
#if TESTMODE == 1
7235
        setAllDone();
7236
#endif
7237
        return;
7238
    }
82 andreas 7239
 
351 andreas 7240
    vector<Button::TButton *>::iterator iter;
7241
 
7242
    for (iter = buttons.begin(); iter != buttons.end(); ++iter)
7243
    {
7244
        Button::TButton *bt = *iter;
7245
 
110 andreas 7246
        if (btState == 0)       // All instances?
82 andreas 7247
        {
110 andreas 7248
            int bst = bt->getNumberInstances();
82 andreas 7249
 
110 andreas 7250
            for (int i = 0; i < bst; i++)
82 andreas 7251
            {
110 andreas 7252
                color = bt->getBorderColor(i);
82 andreas 7253
 
110 andreas 7254
                if (color.empty())
7255
                    continue;
83 andreas 7256
 
300 andreas 7257
                sendCustomEvent(i + 1, (int)color.length(), 0, color, 1011, bt->getChannelPort(), bt->getChannelNumber());
351 andreas 7258
#if TESTMODE == 1
7259
                __success = true;
7260
 
7261
                if (_gTestMode)
7262
                    _gTestMode->setResult(color);
7263
#endif
83 andreas 7264
            }
110 andreas 7265
        }
7266
        else
7267
        {
7268
            color = bt->getBorderColor(btState - 1);
83 andreas 7269
 
110 andreas 7270
            if (color.empty())
351 andreas 7271
                continue;
82 andreas 7272
 
300 andreas 7273
            sendCustomEvent(btState, (int)color.length(), 0, color, 1011, bt->getChannelPort(), bt->getChannelNumber());
351 andreas 7274
#if TESTMODE == 1
7275
            __success = true;
7276
 
7277
            if (_gTestMode)
7278
                _gTestMode->setResult(color);
7279
#endif
82 andreas 7280
        }
7281
    }
351 andreas 7282
#if TESTMODE == 1
7283
    setAllDone();
7284
#endif
82 andreas 7285
}
7286
 
43 andreas 7287
/**
60 andreas 7288
 * @brief Set the fill color to the specified color.
7289
 * Only if the specified fill color is not the same as the current color.
7290
 * Note: Color can be assigned by color name (without spaces), number or R,G,B value (RRGGBB or RRGGBBAA).
15 andreas 7291
 */
60 andreas 7292
void TPageManager::doBCF(int port, vector<int>& channels, vector<std::string>& pars)
15 andreas 7293
{
60 andreas 7294
    DECL_TRACER("TPageManager::doBCF(int port, vector<int>& channels, vector<std::string>& pars)");
15 andreas 7295
 
60 andreas 7296
    if (pars.size() < 1)
15 andreas 7297
    {
60 andreas 7298
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
351 andreas 7299
#if TESTMODE == 1
7300
        setAllDone();
7301
#endif
12 andreas 7302
        return;
7303
    }
14 andreas 7304
 
16 andreas 7305
    TError::clear();
15 andreas 7306
    int btState = atoi(pars[0].c_str());
60 andreas 7307
    string color;
14 andreas 7308
 
60 andreas 7309
    if (pars.size() > 1)
7310
        color = pars[1];
7311
 
193 andreas 7312
    vector<TMap::MAP_T> map = findButtons(port, channels);
15 andreas 7313
 
7314
    if (TError::isError() || map.empty())
351 andreas 7315
    {
7316
#if TESTMODE == 1
7317
        setAllDone();
7318
#endif
15 andreas 7319
        return;
351 andreas 7320
    }
15 andreas 7321
 
7322
    vector<Button::TButton *> buttons = collectButtons(map);
7323
 
83 andreas 7324
    if (buttons.size() > 0)
15 andreas 7325
    {
83 andreas 7326
        vector<Button::TButton *>::iterator mapIter;
15 andreas 7327
 
83 andreas 7328
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
15 andreas 7329
        {
83 andreas 7330
            Button::TButton *bt = *mapIter;
351 andreas 7331
            bt->setFillColor(color, btState - 1);
7332
#if TESTMODE == 1
7333
            if (_gTestMode)
7334
                _gTestMode->setResult(bt->getFillColor(btState == 0 ? 0 : btState - 1));
7335
#endif
15 andreas 7336
        }
7337
    }
351 andreas 7338
#if TESTMODE == 1
7339
    setDone();
7340
#endif
12 andreas 7341
}
7342
 
351 andreas 7343
/*
7344
 * Get the fill color and send it via a custom event to the NetLinx.
7345
 */
82 andreas 7346
void TPageManager::getBCF(int port, vector<int> &channels, vector<string> &pars)
7347
{
7348
    DECL_TRACER("TPageManager::getBCF(int port, vector<int> &channels, vector<string> &pars)");
7349
 
7350
    if (pars.size() < 1)
7351
    {
7352
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
351 andreas 7353
#if TESTMODE == 1
7354
        setAllDone();
7355
#endif
82 andreas 7356
        return;
7357
    }
7358
 
7359
    TError::clear();
7360
    int btState = atoi(pars[0].c_str());
7361
    string color;
7362
 
193 andreas 7363
    vector<TMap::MAP_T> map = findButtons(port, channels);
82 andreas 7364
 
7365
    if (TError::isError() || map.empty())
351 andreas 7366
    {
7367
#if TESTMODE == 1
7368
        setAllDone();
7369
#endif
82 andreas 7370
        return;
351 andreas 7371
    }
82 andreas 7372
 
7373
    vector<Button::TButton *> buttons = collectButtons(map);
7374
 
351 andreas 7375
    if (buttons.empty())
82 andreas 7376
    {
351 andreas 7377
#if TESTMODE == 1
7378
        setAllDone();
7379
#endif
7380
        return;
7381
    }
82 andreas 7382
 
351 andreas 7383
    vector<Button::TButton *>::iterator iter;
7384
 
7385
    for (iter = buttons.begin(); iter != buttons.end(); ++iter)
7386
    {
7387
        Button::TButton *bt = *iter;
7388
 
110 andreas 7389
        if (btState == 0)       // All instances?
82 andreas 7390
        {
110 andreas 7391
            int bst = bt->getNumberInstances();
82 andreas 7392
 
110 andreas 7393
            for (int i = 0; i < bst; i++)
82 andreas 7394
            {
110 andreas 7395
                color = bt->getFillColor(i);
82 andreas 7396
 
110 andreas 7397
                if (color.empty())
7398
                    continue;
82 andreas 7399
 
300 andreas 7400
                sendCustomEvent(i + 1, (int)color.length(), 0, color, 1012, bt->getChannelPort(), bt->getChannelNumber());
351 andreas 7401
#if TESTMODE == 1
7402
                __success = true;
7403
 
7404
                if (_gTestMode)
7405
                    _gTestMode->setResult(color);
7406
#endif
83 andreas 7407
            }
82 andreas 7408
        }
110 andreas 7409
        else
7410
        {
7411
            color = bt->getFillColor(btState-1);
351 andreas 7412
 
7413
            if (color.empty())
7414
                continue;
7415
 
300 andreas 7416
            sendCustomEvent(btState, (int)color.length(), 0, color, 1012, bt->getChannelPort(), bt->getChannelNumber());
351 andreas 7417
#if TESTMODE == 1
7418
            __success = true;
7419
 
7420
            if (_gTestMode)
7421
                _gTestMode->setResult(color);
7422
#endif
110 andreas 7423
        }
82 andreas 7424
    }
351 andreas 7425
#if TESTMODE == 1
7426
    setAllDone();
7427
#endif
82 andreas 7428
}
7429
 
60 andreas 7430
/**
7431
 * @brief Set the text color to the specified color.
7432
 * Only if the specified text color is not the same as the current color.
7433
 * Note: Color can be assigned by color name (without spaces), number or R,G,B value (RRGGBB or RRGGBBAA).
7434
 */
7435
void TPageManager::doBCT(int port, vector<int>& channels, vector<string>& pars)
18 andreas 7436
{
60 andreas 7437
    DECL_TRACER("TPageManager::doBCT(int port, vector<int>& channels, vector<string>& pars)");
7438
 
7439
    if (pars.size() < 1)
7440
    {
7441
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
351 andreas 7442
#if TESTMODE == 1
7443
        setAllDone();
7444
#endif
60 andreas 7445
        return;
7446
    }
7447
 
7448
    TError::clear();
7449
    int btState = atoi(pars[0].c_str());
7450
    string color;
7451
 
7452
    if (pars.size() > 1)
7453
        color = pars[1];
7454
 
193 andreas 7455
    vector<TMap::MAP_T> map = findButtons(port, channels);
60 andreas 7456
 
7457
    if (TError::isError() || map.empty())
351 andreas 7458
    {
7459
#if TESTMODE == 1
7460
        setAllDone();
7461
#endif
60 andreas 7462
        return;
351 andreas 7463
    }
60 andreas 7464
 
7465
    vector<Button::TButton *> buttons = collectButtons(map);
7466
 
83 andreas 7467
    if (buttons.size() > 0)
60 andreas 7468
    {
83 andreas 7469
        vector<Button::TButton *>::iterator mapIter;
60 andreas 7470
 
83 andreas 7471
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
60 andreas 7472
        {
83 andreas 7473
            Button::TButton *bt = *mapIter;
351 andreas 7474
            bt->setTextColor(color, btState - 1);
7475
#if TESTMODE == 1
7476
            if (_gTestMode)
7477
                _gTestMode->setResult(bt->getTextColor(btState == 0 ? 0 : btState - 1));
7478
#endif
60 andreas 7479
        }
7480
    }
351 andreas 7481
#if TESTMODE == 1
7482
    setDone();
7483
#endif
18 andreas 7484
}
7485
 
351 andreas 7486
/*
7487
 * Get the text color of a button and send it via a custom event to the NetLinx.
7488
 */
82 andreas 7489
void TPageManager::getBCT(int port, vector<int> &channels, vector<string> &pars)
7490
{
7491
    DECL_TRACER("TPageManager::getBCT(int port, vector<int> &channels, vector<string> &pars)");
7492
 
7493
    if (pars.size() < 1)
7494
    {
7495
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
351 andreas 7496
#if TESTMODE == 1
7497
        setAllDone();
7498
#endif
82 andreas 7499
        return;
7500
    }
7501
 
7502
    TError::clear();
7503
    int btState = atoi(pars[0].c_str());
7504
    string color;
7505
 
193 andreas 7506
    vector<TMap::MAP_T> map = findButtons(port, channels);
82 andreas 7507
 
7508
    if (TError::isError() || map.empty())
351 andreas 7509
    {
7510
#if TESTMODE == 1
7511
        setAllDone();
7512
#endif
82 andreas 7513
        return;
351 andreas 7514
    }
82 andreas 7515
 
7516
    vector<Button::TButton *> buttons = collectButtons(map);
7517
 
351 andreas 7518
    if (buttons.empty())
82 andreas 7519
    {
351 andreas 7520
#if TESTMODE == 1
7521
        setAllDone();
7522
#endif
7523
        return;
7524
    }
82 andreas 7525
 
351 andreas 7526
    vector<Button::TButton *>::iterator iter;
7527
 
7528
    for (iter = buttons.begin(); iter != buttons.end(); ++iter)
7529
    {
7530
        Button::TButton *bt = *iter;
7531
 
110 andreas 7532
        if (btState == 0)       // All instances?
82 andreas 7533
        {
110 andreas 7534
            int bst = bt->getNumberInstances();
82 andreas 7535
 
110 andreas 7536
            for (int i = 0; i < bst; i++)
82 andreas 7537
            {
110 andreas 7538
                color = bt->getTextColor(i);
82 andreas 7539
 
110 andreas 7540
                if (color.empty())
7541
                    continue;
82 andreas 7542
 
300 andreas 7543
                sendCustomEvent(i + 1, (int)color.length(), 0, color, 1013, bt->getChannelPort(), bt->getChannelNumber());
351 andreas 7544
#if TESTMODE == 1
7545
                __success = true;
7546
 
7547
                if (_gTestMode)
7548
                    _gTestMode->setResult(color);
7549
#endif
83 andreas 7550
            }
82 andreas 7551
        }
110 andreas 7552
        else
7553
        {
7554
            color = bt->getTextColor(btState - 1);
351 andreas 7555
 
7556
            if (color.empty())
7557
                continue;
7558
 
300 andreas 7559
            sendCustomEvent(btState, (int)color.length(), 0, color, 1013, bt->getChannelPort(), bt->getChannelNumber());
351 andreas 7560
#if TESTMODE == 1
7561
            __success = true;
7562
 
7563
            if (_gTestMode)
7564
                _gTestMode->setResult(color);
7565
#endif
110 andreas 7566
        }
82 andreas 7567
    }
351 andreas 7568
#if TESTMODE == 1
7569
    setAllDone();
7570
#endif
82 andreas 7571
}
7572
 
60 andreas 7573
/**
7574
 * Set the button draw order
7575
 * Determines what order each layer of the button is drawn.
7576
 */
7577
void TPageManager::doBDO(int port, vector<int>& channels, vector<std::string>& pars)
32 andreas 7578
{
60 andreas 7579
    DECL_TRACER("TPageManager::doBDO(int port, vector<int>& channels, vector<std::string>& pars)");
32 andreas 7580
 
60 andreas 7581
    if (pars.size() < 1)
7582
    {
7583
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
351 andreas 7584
#if TESTMODE == 1
7585
        setAllDone();
7586
#endif
32 andreas 7587
        return;
60 andreas 7588
    }
32 andreas 7589
 
60 andreas 7590
    TError::clear();
7591
    int btState = atoi(pars[0].c_str());
7592
    string order;
32 andreas 7593
 
60 andreas 7594
    if (pars.size() > 1)
7595
    {
7596
        string ord = pars[1];
7597
        // Convert the numbers into the expected draw order
7598
        for (size_t i = 0; i < ord.length(); i++)
7599
        {
7600
            if (ord.at(i) >= '1' && ord.at(i) <= '5')
7601
            {
7602
                char hv0[32];
7603
                snprintf(hv0, sizeof(hv0), "%02d", (int)(ord.at(i) - '0'));
7604
                order.append(hv0);
7605
            }
7606
            else
7607
            {
7608
                MSG_ERROR("Illegal order number " << ord.substr(i, 1) << "!");
7609
                return;
7610
            }
7611
        }
7612
 
7613
        if (order.length() != 10)
7614
        {
7615
            MSG_ERROR("Expected 5 order numbers but got " << (order.length() / 2)<< "!");
7616
            return;
7617
        }
7618
    }
7619
 
193 andreas 7620
    vector<TMap::MAP_T> map = findButtons(port, channels);
60 andreas 7621
 
7622
    if (TError::isError() || map.empty())
351 andreas 7623
    {
7624
#if TESTMODE == 1
7625
        setAllDone();
7626
#endif
32 andreas 7627
        return;
351 andreas 7628
    }
32 andreas 7629
 
60 andreas 7630
    vector<Button::TButton *> buttons = collectButtons(map);
7631
 
83 andreas 7632
    if (buttons.size() > 0)
32 andreas 7633
    {
83 andreas 7634
        vector<Button::TButton *>::iterator mapIter;
32 andreas 7635
 
83 andreas 7636
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
60 andreas 7637
        {
83 andreas 7638
            Button::TButton *bt = *mapIter;
351 andreas 7639
            bt->setDrawOrder(order, btState - 1);
7640
#if TESTMODE == 1
7641
            if (_gTestMode)
7642
                _gTestMode->setResult(bt->getDrawOrder(btState == 0 ? 0 : btState - 1));
7643
#endif
60 andreas 7644
        }
7645
    }
351 andreas 7646
#if TESTMODE == 1
7647
    setDone();
7648
#endif
60 andreas 7649
}
32 andreas 7650
 
60 andreas 7651
/**
7652
 * Set the feedback type of the button.
7653
 * ONLY works on General-type buttons.
7654
 */
7655
void TPageManager::doBFB(int port, vector<int>& channels, vector<std::string>& pars)
7656
{
7657
    DECL_TRACER("TPageManager::doBFB(int port, vector<int>& channels, vector<std::string>& pars)");
32 andreas 7658
 
60 andreas 7659
    if (pars.size() < 1)
7660
    {
7661
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
351 andreas 7662
#if TESTMODE == 1
7663
        setAllDone();
7664
#endif
60 andreas 7665
        return;
7666
    }
7667
 
7668
    TError::clear();
7669
    Button::FEEDBACK type = Button::FB_NONE;
7670
    string stype = pars[0];
7671
    vector<string> stypes = { "None", "Channel", "Invert", "On", "Momentary", "Blink" };
7672
    vector<string>::iterator iter;
7673
    int i = 0;
7674
 
7675
    for (iter = stypes.begin(); iter != stypes.end(); ++iter)
7676
    {
7677
        if (strCaseCompare(stype, *iter) == 0)
33 andreas 7678
        {
60 andreas 7679
            type = (Button::FEEDBACK)i;
7680
            break;
32 andreas 7681
        }
60 andreas 7682
 
7683
        i++;
32 andreas 7684
    }
7685
 
193 andreas 7686
    vector<TMap::MAP_T> map = findButtons(port, channels);
60 andreas 7687
 
7688
    if (TError::isError() || map.empty())
351 andreas 7689
    {
7690
#if TESTMODE == 1
7691
        setAllDone();
7692
#endif
60 andreas 7693
        return;
351 andreas 7694
    }
60 andreas 7695
 
7696
    vector<Button::TButton *> buttons = collectButtons(map);
7697
 
83 andreas 7698
    if (buttons.size() > 0)
60 andreas 7699
    {
83 andreas 7700
        vector<Button::TButton *>::iterator mapIter;
7701
 
7702
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
7703
        {
7704
            Button::TButton *bt = *mapIter;
7705
            bt->setFeedback(type);
351 andreas 7706
#if TESTMODE == 1
7707
            if (_gTestMode)
7708
                _gTestMode->setResult(intToString(bt->getFeedback()));
7709
#endif
83 andreas 7710
        }
60 andreas 7711
    }
335 andreas 7712
#if TESTMODE == 1
7713
    setDone();
7714
#endif
32 andreas 7715
}
7716
 
224 andreas 7717
/*
7718
 * Set the input mask for the specified address.
7719
 */
7720
void TPageManager::doBIM(int port, vector<int>& channels, vector<std::string>& pars)
7721
{
7722
    DECL_TRACER("TPageManager::doBIM(int port, vector<int>& channels, vector<std::string>& pars)");
7723
 
7724
    if (pars.size() < 1)
7725
    {
7726
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
351 andreas 7727
#if TESTMODE == 1
7728
        setAllDone();
7729
#endif
224 andreas 7730
        return;
7731
    }
7732
 
7733
    TError::clear();
7734
    string mask = pars[0];
7735
    vector<TMap::MAP_T> map = findButtons(port, channels);
7736
 
7737
    if (TError::isError() || map.empty())
351 andreas 7738
    {
7739
#if TESTMODE == 1
7740
        setAllDone();
7741
#endif
224 andreas 7742
        return;
351 andreas 7743
    }
224 andreas 7744
 
7745
    vector<Button::TButton *> buttons = collectButtons(map);
7746
 
7747
    if (buttons.size() > 0)
7748
    {
7749
        vector<Button::TButton *>::iterator mapIter;
7750
 
7751
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
7752
        {
7753
            Button::TButton *bt = *mapIter;
7754
            bt->setInputMask(mask);
351 andreas 7755
#if TESTMODE == 1
7756
            if (_gTestMode)
7757
                _gTestMode->setResult(bt->getInputMask());
7758
#endif
224 andreas 7759
        }
7760
    }
351 andreas 7761
#if TESTMODE == 1
7762
    setDone();
7763
#endif
224 andreas 7764
}
7765
 
351 andreas 7766
/**
7767
 * @brief Button copy command.
7768
 * Copy attributes of the source button to all the
7769
 * destination buttons. Note that the source is a single button state. Each
7770
 * state must be copied as a separate command. The <codes> section represents
7771
 * what attributes will be copied. All codes are 2 char pairs that can be
7772
 * separated by comma, space, percent or just ran together.
7773
 */
106 andreas 7774
void TPageManager::doBMC(int port, vector<int>& channels, vector<std::string>& pars)
7775
{
7776
    DECL_TRACER("TPageManager::doBMC(int port, vector<int>& channels, vector<std::string>& pars)");
7777
 
7778
    if (pars.size() < 5)
7779
    {
7780
        MSG_ERROR("Expecting 5 parameters but got " << pars.size() << ". Ignoring command.");
351 andreas 7781
#if TESTMODE == 1
7782
        setAllDone();
7783
#endif
106 andreas 7784
        return;
7785
    }
7786
 
7787
    TError::clear();
7788
    int btState = atoi(pars[0].c_str());
7789
    int src_port = atoi(pars[1].c_str());
7790
    int src_addr = atoi(pars[2].c_str());
7791
    int src_state = atoi(pars[3].c_str());
7792
    string src_codes = pars[4];
7793
    vector<int> src_channel;
7794
    src_channel.push_back(src_addr);
7795
 
193 andreas 7796
    vector<TMap::MAP_T> src_map = findButtons(src_port, src_channel);
106 andreas 7797
 
7798
    if (src_map.size() == 0)
7799
    {
7800
        MSG_WARNING("Button <" << TConfig::getChannel() << ":" << src_port << ":" << TConfig::getSystem() << ">:" << src_addr << " does not exist!");
351 andreas 7801
#if TESTMODE == 1
7802
        setAllDone();
7803
#endif
106 andreas 7804
        return;
7805
    }
7806
 
7807
    vector<Button::TButton *>src_buttons = collectButtons(src_map);
7808
 
7809
    if (src_buttons.size() == 0)
7810
    {
7811
        MSG_WARNING("Button <" << TConfig::getChannel() << ":" << src_port << ":" << TConfig::getSystem() << ">:" << src_addr << " does not exist!");
351 andreas 7812
#if TESTMODE == 1
7813
        setAllDone();
7814
#endif
106 andreas 7815
        return;
7816
    }
7817
 
7818
    if (src_buttons[0]->getNumberInstances() < src_state)
7819
    {
7820
        MSG_WARNING("Button <" << TConfig::getChannel() << ":" << src_port << ":" << TConfig::getSystem() << ">:" << src_addr << " has less then " << src_state << " elements.");
351 andreas 7821
#if TESTMODE == 1
7822
        setAllDone();
7823
#endif
106 andreas 7824
        return;
7825
    }
7826
 
7827
    if (src_state < 1)
7828
    {
7829
        MSG_WARNING("Button <" << TConfig::getChannel() << ":" << src_port << ":" << TConfig::getSystem() << ">:" << src_addr << " has invalid source state " << src_state << ".");
351 andreas 7830
#if TESTMODE == 1
7831
        setAllDone();
7832
#endif
106 andreas 7833
        return;
7834
    }
7835
 
7836
    src_state--;
7837
 
7838
    if (btState > 0)
7839
        btState--;
7840
 
193 andreas 7841
    vector<TMap::MAP_T> map = findButtons(port, channels);
106 andreas 7842
    vector<Button::TButton *> buttons = collectButtons(map);
7843
    //                        0     1     2     3     4     5     6     7
7844
    vector<string>codes = { "BM", "BR", "CB", "CF", "CT", "EC", "EF", "FT",
7845
                            "IC", "JB", "JI", "JT", "LN", "OP", "SO", "TX", // 8 - 15
7846
                            "VI", "WW" };   // 16, 17
7847
 
7848
    for (size_t ibuttons = 0; ibuttons < buttons.size(); ibuttons++)
7849
    {
7850
        vector<string>::iterator iter;
7851
        int idx = 0;
7852
 
7853
        for (iter = codes.begin(); iter != codes.end(); ++iter)
7854
        {
7855
            if (src_codes.find(*iter) != string::npos)
7856
            {
7857
                int j, x, y;
7858
 
7859
                switch(idx)
7860
                {
7861
                    case 0: buttons[ibuttons]->setBitmap(src_buttons[0]->getBitmapName(src_state), btState); break;
7862
                    case 1: buttons[ibuttons]->setBorderStyle(src_buttons[0]->getBorderStyle(src_state), btState); break;
7863
                    case 2: buttons[ibuttons]->setBorderColor(src_buttons[0]->getBorderColor(src_state), btState); break;
7864
                    case 3: buttons[ibuttons]->setFillColor(src_buttons[0]->getFillColor(src_state), btState); break;
7865
                    case 4: buttons[ibuttons]->setTextColor(src_buttons[0]->getTextColor(src_state), btState); break;
7866
                    case 5: buttons[ibuttons]->setTextEffectColor(src_buttons[0]->getTextEffectColor(src_state), btState); break;
7867
                    case 6: buttons[ibuttons]->setTextEffect(src_buttons[0]->getTextEffect(src_state), btState); break;
7868
                    case 7: buttons[ibuttons]->setFontIndex(src_buttons[0]->getFontIndex(src_state), btState); break;
110 andreas 7869
                    case 8: buttons[ibuttons]->setIcon(src_buttons[0]->getIconIndex(src_state), btState); break;
106 andreas 7870
 
7871
                    case 9:
7872
                        j = src_buttons[0]->getBitmapJustification(&x, &y, src_state);
7873
                        buttons[ibuttons]->setBitmapJustification(j, x, y, btState);
7874
                    break;
7875
 
7876
                    case 10:
7877
                        j = src_buttons[0]->getIconJustification(&x, &y, src_state);
7878
                        buttons[ibuttons]->setIconJustification(j, x, y, btState);
7879
                    break;
7880
 
7881
                    case 11:
7882
                        j = src_buttons[0]->getTextJustification(&x, &y, src_state);
7883
                        buttons[ibuttons]->setTextJustification(j, x, y, btState);
7884
                    break;
7885
 
7886
                    case 12: MSG_INFO("\"Lines of video removed\" not supported!"); break;
7887
                    case 13: buttons[ibuttons]->setOpacity(src_buttons[0]->getOpacity(src_state), btState); break;
7888
                    case 14: buttons[ibuttons]->setSound(src_buttons[0]->getSound(src_state), btState); break;
7889
                    case 15: buttons[ibuttons]->setText(src_buttons [0]->getText(src_state), btState); break;
7890
                    case 16: MSG_INFO("\"Video slot ID\" not supported!"); break;
7891
                    case 17: buttons[ibuttons]->setTextWordWrap(src_buttons[0]->getTextWordWrap(src_state), btState); break;
7892
                }
7893
            }
7894
 
7895
            idx++;
7896
        }
7897
    }
7898
}
7899
 
149 andreas 7900
void TPageManager::doBMF (int port, vector<int>& channels, vector<string>& pars)
7901
{
7902
    DECL_TRACER("TPageManager::doBMF (int port, vector<int>& channels, vector<string>& pars)");
7903
 
7904
    if (pars.size() < 2)
332 andreas 7905
    {
7906
        MSG_ERROR("Less then 2 parameters!");
7907
#if TESTMODE == 1
334 andreas 7908
        setAllDone();
332 andreas 7909
#endif
149 andreas 7910
        return;
332 andreas 7911
    }
149 andreas 7912
 
7913
    TError::clear();
7914
    int btState = atoi(pars[0].c_str()) - 1;
150 andreas 7915
    string commands;
149 andreas 7916
 
150 andreas 7917
    for (size_t i = 1; i < pars.size(); ++i)
7918
    {
7919
        if (i > 1)
7920
            commands += ",";
7921
 
7922
        commands += pars[i];
7923
    }
7924
 
193 andreas 7925
    vector<TMap::MAP_T> map = findButtons(port, channels);
149 andreas 7926
 
7927
    if (TError::isError() || map.empty())
332 andreas 7928
    {
7929
#if TESTMODE == 1
334 andreas 7930
        setAllDone();
332 andreas 7931
#endif
149 andreas 7932
        return;
332 andreas 7933
    }
149 andreas 7934
 
7935
    // Start of parsing the command line
162 andreas 7936
    // We splitt the command line into parts by searching for a percent (%) sign.
149 andreas 7937
    vector<string> parts = StrSplit(commands, "%");
7938
 
162 andreas 7939
    if (parts.empty())
332 andreas 7940
        parts.push_back(commands);
334 andreas 7941
 
149 andreas 7942
    // Search for all buttons who need to be updated
7943
    vector<Button::TButton *> buttons = collectButtons(map);
7944
 
7945
    if (buttons.size() > 0)
7946
    {
7947
        vector<Button::TButton *>::iterator mapIter;
7948
 
7949
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
7950
        {
7951
            Button::TButton *bt = *mapIter;
162 andreas 7952
 
7953
            if (!bt)
7954
            {
7955
                MSG_WARNING("Command ^BMF found an invalid pointer to a button!")
7956
                continue;
7957
            }
7958
 
149 andreas 7959
            // Iterate through commands and apply them to button
7960
            vector<string>::iterator iter;
7961
 
7962
            for (iter = parts.begin(); iter != parts.end(); ++iter)
7963
            {
7964
                char cmd = iter->at(0);
7965
                char cmd2;
7966
                string content;
7967
 
7968
                switch(cmd)
7969
                {
7970
                    case 'B':   // Border style
361 andreas 7971
                        if (iter->at(1) == ',')
7972
                            content = iter->substr(2);
7973
                        else
7974
                            content = iter->substr(1);
332 andreas 7975
 
7976
                        if (!content.empty() && isdigit(content[0]))
334 andreas 7977
                            bt->setBorderStyle(atoi(content.c_str()), btState);
332 andreas 7978
                        else
7979
                            bt->setBorderStyle(content, btState);
7980
#if TESTMODE == 1
7981
                        if (_gTestMode)
7982
                            _gTestMode->setResult(bt->getBorderStyle(btState < 0 ? 0 : btState));
7983
#endif
149 andreas 7984
                    break;
7985
 
7986
                    case 'C':   // Colors
7987
                        cmd2 = iter->at(1);
7988
                        content = iter->substr(2);
7989
 
7990
                        switch(cmd2)
7991
                        {
7992
                            case 'B':   // Border color
7993
                                bt->setBorderColor(content, btState);
332 andreas 7994
#if TESTMODE == 1
7995
                                if (_gTestMode)
7996
                                    _gTestMode->setResult(bt->getBorderColor(btState < 0 ? 0 : btState));
7997
#endif
149 andreas 7998
                            break;
7999
 
8000
                            case 'F':   // Fill color
8001
                                bt->setFillColor(content, btState);
332 andreas 8002
#if TESTMODE == 1
8003
                                if (_gTestMode)
8004
                                    _gTestMode->setResult(bt->getFillColor(btState < 0 ? 0 : btState));
8005
#endif
149 andreas 8006
                            break;
8007
 
8008
                            case 'T':   // Text color
8009
                                bt->setTextColor(content, btState);
332 andreas 8010
#if TESTMODE == 1
8011
                                if (_gTestMode)
8012
                                    _gTestMode->setResult(bt->getTextColor(btState < 0 ? 0 : btState));
8013
#endif
149 andreas 8014
                            break;
8015
                        }
8016
                    break;
8017
 
150 andreas 8018
                    case 'D':   // Draw order
8019
                        cmd2 = iter->at(1);
8020
                        content = iter->substr(2);
8021
 
8022
                        if (cmd2 == 'O')
332 andreas 8023
                        {
150 andreas 8024
                            bt->setDrawOrder(content, btState);
332 andreas 8025
#if TESTMODE == 1
8026
                            if (_gTestMode)
8027
                                _gTestMode->setResult(bt->getDrawOrder(btState < 0 ? 0 : btState));
8028
#endif
8029
                        }
150 andreas 8030
                    break;
8031
 
149 andreas 8032
                    case 'E':   // Text effect
8033
                        cmd2 = iter->at(1);
8034
                        content = iter->substr(2);
8035
 
8036
                        switch(cmd2)
8037
                        {
8038
                            case 'C':   // Text effect color
8039
                                bt->setTextEffectColor(content, btState);
332 andreas 8040
#if TESTMODE == 1
8041
                                if (_gTestMode)
8042
                                    _gTestMode->setResult(bt->getTextEffectColor(btState < 0 ? 0 : btState));
8043
#endif
149 andreas 8044
                            break;
8045
 
8046
                            case 'F':   // Text effect name
8047
                                bt->setTextEffectName(content, btState);
332 andreas 8048
#if TESTMODE == 1
8049
                                if (_gTestMode)
8050
                                    _gTestMode->setResult(bt->getTextEffectName(btState < 0 ? 0 : btState));
8051
#endif
149 andreas 8052
                            break;
8053
 
8054
                            case 'N':   // Enable/disable button
8055
                                bt->setEnable((content[0] == '1' ? true : false));
332 andreas 8056
#if TESTMODE == 1
8057
                                if (_gTestMode)
334 andreas 8058
                                {
332 andreas 8059
                                    _gTestMode->setResult(bt->isEnabled() ? "TRUE" : "FALSE");
334 andreas 8060
                                    __success = true;
8061
                                    setScreenDone();
8062
                                }
332 andreas 8063
#endif
149 andreas 8064
                            break;
8065
                        }
8066
                    break;
8067
 
8068
                    case 'F':   // Set font file name
361 andreas 8069
                        if (iter->at(1) == ',')
8070
                            content = iter->substr(2);
8071
                        else
8072
                            content = iter->substr(1);
150 andreas 8073
 
8074
                        if (!isdigit(content[0]))
334 andreas 8075
                            bt->setFontName(content, btState);
150 andreas 8076
                        else
8077
                            bt->setFontIndex(atoi(content.c_str()), btState);
334 andreas 8078
#if TESTMODE == 1
8079
                        if (_gTestMode)
8080
                            _gTestMode->setResult(intToString(bt->getFontIndex(btState < 0 ? 0 : btState)));
8081
#endif
149 andreas 8082
                    break;
8083
 
8084
                    case 'G':   // Bargraphs
8085
                        cmd2 = iter->at(1);
8086
                        content = iter->substr(2);
8087
 
8088
                        switch(cmd2)
8089
                        {
8090
                            case 'C':   // Bargraph slider color
8091
                                bt->setBargraphSliderColor(content);
8092
                            break;
8093
 
8094
                            case 'D':   // Ramp down time
387 andreas 8095
                                bt->setBargraphRampDownTime(atoi(content.c_str()));
149 andreas 8096
                            break;
8097
 
8098
                            case 'G':   // Drag increment
387 andreas 8099
                                bt->setBargraphDragIncrement(atoi(content.c_str()));
149 andreas 8100
                            break;
8101
 
8102
                            case 'H':   // Upper limit
8103
                                bt->setBargraphUpperLimit(atoi(content.c_str()));
8104
                            break;
8105
 
8106
                            case 'I':   // Invert/noninvert
387 andreas 8107
                                if (bt->getButtonType() == BARGRAPH || bt->getButtonType() == MULTISTATE_BARGRAPH)
8108
                                    bt->setBargraphInvert(atoi(content.c_str()) > 0 ? true : false);
149 andreas 8109
                            break;
8110
 
8111
                            case 'L':   // Lower limit
8112
                                bt->setBargraphLowerLimit(atoi(content.c_str()));
8113
                            break;
8114
 
8115
                            case 'N':   // Slider name
361 andreas 8116
                                bt->setBargraphSliderName(content);
149 andreas 8117
                            break;
8118
 
8119
                            case 'R':   // Repeat interval
8120
                                // FIXME: Add function to set repeat interval
8121
                            break;
8122
 
8123
                            case 'U':   // Ramp up time
387 andreas 8124
                                bt->setBargraphRampUpTime(atoi(content.c_str()));
149 andreas 8125
                            break;
8126
 
8127
                            case 'V':   // Bargraph value
387 andreas 8128
                                bt->setBargraphLevel(atoi(content.c_str()));
149 andreas 8129
                            break;
8130
                        }
8131
                    break;
8132
 
152 andreas 8133
                    case 'I':   // Set the icon
8134
                        content = iter->substr(1);
8135
                        bt->setIcon(atoi(content.c_str()), btState);
332 andreas 8136
#if TESTMODE == 1
8137
                        if (_gTestMode)
8138
                            _gTestMode->setResult(intToString(bt->getIconIndex()));
8139
#endif
152 andreas 8140
                    break;
8141
 
149 andreas 8142
                    case 'J':   // Set text justification
150 andreas 8143
                        cmd2 = iter->at(1);
8144
 
361 andreas 8145
                        if (cmd2 == ',')
150 andreas 8146
                        {
8147
                            content = iter->substr(1);
152 andreas 8148
                            int just = atoi(content.c_str());
8149
                            int x = 0, y = 0;
8150
 
8151
                            if (just == 0)
8152
                            {
8153
                                vector<string> coords = StrSplit(content, ",");
8154
 
8155
                                if (coords.size() >= 3)
8156
                                {
8157
                                    x = atoi(coords[1].c_str());
8158
                                    y = atoi(coords[2].c_str());
8159
                                }
8160
                            }
8161
 
8162
                            bt->setTextJustification(atoi(content.c_str()), x, y, btState);
334 andreas 8163
#if TESTMODE == 1
8164
                            if (_gTestMode)
8165
                            {
8166
                                just = bt->getTextJustification(&x, &y, btState < 0 ? 0 : btState);
8167
                                string s = intToString(just) + "," + intToString(x) + "," + intToString(y);
8168
                                _gTestMode->setResult(s);
8169
                            }
8170
#endif
150 andreas 8171
                        }
361 andreas 8172
                        else if (cmd2 == 'T' || cmd2 == 'B' || cmd2 == 'I')
150 andreas 8173
                        {
8174
                            content = iter->substr(2);
152 andreas 8175
                            int x = 0, y = 0;
8176
                            int just = atoi(content.c_str());
150 andreas 8177
 
152 andreas 8178
                            if (just == 0)
8179
                            {
8180
                                vector<string> coords = StrSplit(content, ",");
8181
 
8182
                                if (coords.size() >= 3)
8183
                                {
8184
                                    x = atoi(coords[1].c_str());
8185
                                    y = atoi(coords[2].c_str());
8186
                                }
8187
                            }
8188
 
150 andreas 8189
                            switch(cmd2)
8190
                            {
8191
                                case 'B':   // Alignment of bitmap
152 andreas 8192
                                    bt->setBitmapJustification(atoi(content.c_str()), x, y, btState);
334 andreas 8193
#if TESTMODE == 1
8194
                                    just = bt->getBitmapJustification(&x, &y, btState < 0 ? 0 : btState);
8195
#endif
150 andreas 8196
                                break;
8197
 
8198
                                case 'I':   // Alignment of icon
152 andreas 8199
                                    bt->setIconJustification(atoi(content.c_str()), x, y, btState);
334 andreas 8200
#if TESTMODE == 1
8201
                                    just = bt->getIconJustification(&x, &y, btState < 0 ? 0 : btState);
8202
#endif
150 andreas 8203
                                break;
8204
 
8205
                                case 'T':   // Alignment of text
152 andreas 8206
                                    bt->setTextJustification(atoi(content.c_str()), x, y, btState);
334 andreas 8207
#if TESTMODE == 1
8208
                                    just = bt->getTextJustification(&x, &y, btState < 0 ? 0 : btState);
8209
#endif
150 andreas 8210
                                break;
8211
                            }
334 andreas 8212
#if TESTMODE == 1
8213
                            if (_gTestMode)
8214
                            {
8215
                                string s = intToString(just) + "," + intToString(x) + "," + intToString(y);
8216
                                _gTestMode->setResult(s);
8217
                            }
8218
#endif
150 andreas 8219
                        }
8220
                    break;
8221
 
8222
                    case 'M':   // Text area
8223
                        cmd2 = iter->at(1);
8224
                        content = iter->substr(2);
8225
 
8226
                        switch(cmd2)
8227
                        {
152 andreas 8228
                            case 'I':   // Set mask image
8229
                                // FIXME: Add code for image mask
8230
                            break;
8231
 
150 andreas 8232
                            case 'K':   // Input mask of text area
8233
                                // FIXME: Add input mask
8234
                            break;
8235
 
8236
                            case 'L':   // Maximum length of text area
8237
                                // FIXME: Add code to set maximum length
8238
                            break;
8239
                        }
8240
                    break;
8241
 
8242
                    case 'O':   // Set feedback typ, opacity
8243
                        cmd2 = iter->at(1);
8244
 
8245
                        switch(cmd2)
8246
                        {
8247
                            case 'P':   // Set opacity
8248
                                bt->setOpacity(atoi(iter->substr(2).c_str()), btState);
8249
                            break;
8250
 
8251
                            case 'T':   // Set feedback type
8252
                                content = iter->substr(2);
8253
                                content = toUpper(content);
8254
 
8255
                                if (content == "NONE")
8256
                                    bt->setFeedback(Button::FB_NONE);
8257
                                else if (content == "CHANNEL")
8258
                                    bt->setFeedback(Button::FB_CHANNEL);
8259
                                else if (content == "INVERT")
8260
                                    bt->setFeedback(Button::FB_INV_CHANNEL);
8261
                                else if (content == "ON")
8262
                                    bt->setFeedback(Button::FB_ALWAYS_ON);
8263
                                else if (content == "MOMENTARY")
8264
                                    bt->setFeedback(Button::FB_MOMENTARY);
8265
                                else if (content == "BLINK")
8266
                                    bt->setFeedback(Button::FB_BLINK);
8267
                                else
8268
                                {
8269
                                    MSG_WARNING("Unknown feedback type " << content);
8270
                                }
335 andreas 8271
#if TESTMODE == 1
8272
                                if (_gTestMode)
8273
                                    _gTestMode->setResult(intToString(bt->getFeedback()));
8274
#endif
150 andreas 8275
                            break;
8276
 
8277
                            default:
8278
                                content = iter->substr(1);
8279
                                // FIXME: Add code to set the feedback type
8280
                        }
8281
                    break;
8282
 
152 andreas 8283
                    case 'P':   // Set picture/bitmap file name
8284
                        content = iter->substr(1);
165 andreas 8285
 
8286
                        if (content.find(".") == string::npos)  // If the image has no extension ...
8287
                        {                                       // we must find the image in the map
8288
                            string iname = findImage(content);
8289
 
8290
                            if (!iname.empty())
8291
                                content = iname;
8292
                        }
8293
 
152 andreas 8294
                        bt->setBitmap(content, btState);
8295
                    break;
8296
 
8297
                    case 'R':   // Set rectangle
8298
                    {
8299
                        content = iter->substr(1);
8300
                        vector<string> corners = StrSplit(content, ",");
8301
 
8302
                        if (corners.size() > 0)
8303
                        {
8304
                            vector<string>::iterator itcorn;
8305
                            int pos = 0;
8306
                            int left, top, right, bottom;
8307
                            left = top = right = bottom = 0;
8308
 
8309
                            for (itcorn = corners.begin(); itcorn != corners.end(); ++itcorn)
8310
                            {
8311
                                switch(pos)
8312
                                {
8313
                                    case 0: left   = atoi(itcorn->c_str()); break;
8314
                                    case 1: top    = atoi(itcorn->c_str()); break;
8315
                                    case 2: right  = atoi(itcorn->c_str()); break;
8316
                                    case 3: bottom = atoi(itcorn->c_str()); break;
8317
                                }
8318
 
8319
                                pos++;
8320
                            }
8321
 
8322
                            if (pos >= 4)
334 andreas 8323
                            {
152 andreas 8324
                                bt->setRectangle(left, top, right, bottom);
334 andreas 8325
                                bt->refresh();
8326
                            }
152 andreas 8327
                        }
334 andreas 8328
#if TESTMODE == 1
8329
                        if (_gTestMode)
8330
                        {
8331
                            int left, top, width, height;
8332
                            bt->getRectangle(&left, &top, &height, &width);
8333
                            string res(intToString(left) + "," + intToString(top) + "," + intToString(width) + "," + intToString(height));
8334
                            _gTestMode->setResult(res);
8335
                        }
8336
#endif
152 andreas 8337
                    }
8338
                    break;
8339
 
150 andreas 8340
                    case 'S':   // show/hide, style, sound
8341
                        cmd2 = iter->at(1);
8342
                        content = iter->substr(2);
8343
 
8344
                        switch(cmd2)
8345
                        {
8346
                            case 'F':   // Set focus of text area button
8347
                                // FIXME: Add code to set the focus of text area button
8348
                            break;
8349
 
8350
                            case 'M':   // Submit text
169 andreas 8351
                                if (content.find("|"))  // To be replaced by LF (0x0a)?
8352
                                {
8353
                                    size_t pos = 0;
8354
 
8355
                                    while ((pos = content.find("|")) != string::npos)
8356
                                        content = content.replace(pos, 1, "\n");
8357
                                }
8358
 
150 andreas 8359
                                bt->setText(content, btState);
8360
                            break;
8361
 
8362
                            case 'O':   // Sound
8363
                                bt->setSound(content, btState);
335 andreas 8364
#if TESTMODE == 1
8365
                                if (_gTestMode)
8366
                                    _gTestMode->setResult(bt->getSound(btState < 0 ? 0 : btState));
8367
#endif
150 andreas 8368
                            break;
8369
 
8370
                            case 'T':   // Button style
8371
                                // FIXME: Add code to set the button style
8372
                            break;
8373
 
8374
                            case 'W':   // Show / hide button
8375
                                if (content[0] == '0')
334 andreas 8376
                                    bt->hide(true);
150 andreas 8377
                                else
8378
                                    bt->show();
334 andreas 8379
#if TESTMODE == 1
8380
                                if (_gTestMode)
8381
                                    _gTestMode->setResult(bt->isVisible() ? "TRUE" : "FALSE");
8382
#endif
150 andreas 8383
                            break;
8384
                        }
8385
                    break;
8386
 
152 andreas 8387
                    case 'T':   // Set text
8388
                        content = iter->substr(1);
169 andreas 8389
 
8390
                        if (content.find("|"))  // To be replaced by LF (0x0a)?
8391
                        {
8392
                            size_t pos = 0;
8393
 
8394
                            while ((pos = content.find("|")) != string::npos)
8395
                                content = content.replace(pos, 1, "\n");
8396
                        }
8397
 
152 andreas 8398
                        bt->setText(content, btState);
334 andreas 8399
#if TESTMODE == 1
8400
                        if (_gTestMode)
8401
                            _gTestMode->setResult(bt->getText(btState < 0 ? 0 : btState));
8402
#endif
152 andreas 8403
                    break;
8404
 
150 andreas 8405
                    case 'U':   // Set the unicode text
8406
                        if (iter->at(1) == 'N')
8407
                        {
8408
                            content = iter->substr(2);
152 andreas 8409
                            string byte, text;
8410
                            size_t pos = 0;
8411
 
8412
                            while (pos < content.length())
8413
                            {
8414
                                byte = content.substr(pos, 2);
8415
                                char ch = (char)strtol(byte.c_str(), NULL, 16);
8416
                                text += ch;
8417
                                pos += 2;
8418
                            }
8419
 
169 andreas 8420
                            if (text.find("|"))  // To be replaced by LF (0x0a)?
8421
                            {
8422
                                size_t pos = 0;
8423
 
8424
                                while ((pos = text.find("|")) != string::npos)
8425
                                    text = text.replace(pos, 1, "\n");
8426
                            }
8427
 
152 andreas 8428
                            bt->setText(text, btState);
150 andreas 8429
                        }
8430
                    break;
8431
 
8432
                    case 'V':   // Video on / off
8433
                        cmd2 = iter->at(1);
8434
                        // Controlling a computer remotely is not supported.
8435
                        if (cmd2 != 'L' && cmd2 != 'N' && cmd2 != 'P')
8436
                        {
8437
                            content = iter->substr(2);
8438
                            // FIXME: Add code to switch video on or off
8439
                        }
8440
                    break;
8441
 
8442
                    case 'W':   // Word wrap
152 andreas 8443
                        if (iter->at(1) == 'W')
8444
                        {
8445
                            content = iter->substr(2);
8446
                            bt->setTextWordWrap(content[0] == '1' ? true : false, btState);
8447
                        }
149 andreas 8448
                    break;
8449
                }
8450
            }
8451
        }
8452
    }
332 andreas 8453
#if TESTMODE == 1
334 andreas 8454
    setDone();
332 andreas 8455
#endif
149 andreas 8456
}
8457
 
14 andreas 8458
/**
110 andreas 8459
 * Set the maximum length of the text area button. If this value is set to
8460
 * zero (0), the text area has no max length. The maximum length available is
8461
 * 2000. This is only for a Text area input button and not for a Text area input
8462
 * masking button.
8463
 */
8464
void TPageManager::doBML(int port, vector<int>& channels, vector<string>& pars)
8465
{
8466
    DECL_TRACER("TPageManager::doBML(int port, vector<int>& channels, vector<string>& pars)");
8467
 
8468
    if (pars.size() < 1)
8469
    {
8470
        MSG_ERROR("Expecting 1 parameter but got " << pars.size() << "! Ignoring command.");
8471
        return;
8472
    }
8473
 
8474
    TError::clear();
8475
    int maxLen = atoi(pars[0].c_str());
8476
 
8477
    if (maxLen < 0 || maxLen > 2000)
8478
    {
8479
        MSG_WARNING("Got illegal length of text area! [" << maxLen << "]");
8480
        return;
8481
    }
8482
 
193 andreas 8483
    vector<TMap::MAP_T> map = findButtons(port, channels);
110 andreas 8484
 
8485
    if (TError::isError() || map.empty())
8486
        return;
8487
 
8488
    vector<Button::TButton *> buttons = collectButtons(map);
8489
 
8490
    if (buttons.size() > 0)
8491
    {
8492
        vector<Button::TButton *>::iterator mapIter;
8493
 
8494
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
8495
        {
8496
            Button::TButton *bt = *mapIter;
8497
            bt->setTextMaxChars(maxLen);
8498
        }
8499
    }
8500
}
8501
 
8502
/**
60 andreas 8503
 * Assign a picture to those buttons with a defined address range.
8504
 */
8505
void TPageManager::doBMP(int port, vector<int>& channels, vector<string>& pars)
8506
{
8507
    DECL_TRACER("TPageManager::doBMP(int port, vector<int>& channels, vector<string>& pars)");
8508
 
8509
    if (pars.size() < 2)
8510
    {
8511
        MSG_ERROR("Expecting 2 parameters but got " << pars.size() << "! Ignoring command.");
8512
        return;
8513
    }
8514
 
8515
    TError::clear();
8516
    int btState = atoi(pars[0].c_str());
8517
    string bitmap = pars[1];
104 andreas 8518
    // If this is a G5 command, we may have up to 2 additional parameters.
8519
    int slot = -1, justify = -1, jx = 0, jy = 0;
60 andreas 8520
 
104 andreas 8521
    if (pars.size() > 2)
8522
    {
8523
        slot = atoi(pars[2].c_str());
8524
 
8525
        if (pars.size() >= 4)
8526
        {
8527
            justify = atoi(pars[4].c_str());
8528
 
8529
            if (justify == 0)
8530
            {
8531
                if (pars.size() >= 5)
8532
                    jx = atoi(pars[5].c_str());
8533
 
8534
                if (pars.size() >= 6)
8535
                    jy = atoi(pars[6].c_str());
8536
            }
8537
        }
8538
    }
8539
 
193 andreas 8540
    vector<TMap::MAP_T> map = findButtons(port, channels);
60 andreas 8541
 
8542
    if (TError::isError() || map.empty())
8543
        return;
8544
 
8545
    vector<Button::TButton *> buttons = collectButtons(map);
8546
 
83 andreas 8547
    if (buttons.size() > 0)
60 andreas 8548
    {
83 andreas 8549
        vector<Button::TButton *>::iterator mapIter;
60 andreas 8550
 
83 andreas 8551
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
60 andreas 8552
        {
83 andreas 8553
            Button::TButton *bt = *mapIter;
252 andreas 8554
//            setButtonCallbacks(bt);
60 andreas 8555
 
83 andreas 8556
            if (btState == 0)       // All instances?
8557
            {
8558
                int bst = bt->getNumberInstances();
96 andreas 8559
                MSG_DEBUG("Setting bitmap " << bitmap << " on all " << bst << " instances...");
83 andreas 8560
 
8561
                for (int i = 0; i < bst; i++)
104 andreas 8562
                {
8563
                    if (justify >= 0)
8564
                    {
8565
                        if (slot == 2)
8566
                            bt->setIconJustification(justify, jx, jy, i);
8567
                        else
106 andreas 8568
                            bt->setBitmapJustification(justify, jx, jy, i);
104 andreas 8569
                    }
8570
 
8571
                    if (slot >= 0)
8572
                    {
8573
                        switch(slot)
8574
                        {
8575
                            case 0: bt->setCameleon(bitmap, i); break;
8576
                            case 2: bt->setIcon(bitmap, i); break;  // On G4 we have no bitmap layer. Therefor we use layer 2 as icon layer.
8577
                            default:
8578
                                bt->setBitmap(bitmap, i);
8579
                        }
8580
                    }
8581
                    else
8582
                        bt->setBitmap(bitmap, i);
8583
                }
83 andreas 8584
            }
8585
            else
104 andreas 8586
            {
8587
                if (justify >= 0)
8588
                {
8589
                    if (slot == 2)
8590
                        bt->setIconJustification(justify, jx, jy, btState);
8591
                    else
106 andreas 8592
                        bt->setBitmapJustification(justify, jx, jy, btState);
104 andreas 8593
                }
8594
 
8595
                if (slot >= 0)
8596
                {
8597
                    switch(slot)
8598
                    {
8599
                        case 0: bt->setCameleon(bitmap, btState); break;
8600
                        case 2: bt->setIcon(bitmap, btState); break;      // On G4 we have no bitmap layer. Therefor we use layer 2 as icon layer.
8601
                        default:
8602
                            bt->setBitmap(bitmap, btState);
8603
                    }
8604
                }
8605
                else
8606
                    bt->setBitmap(bitmap, btState);
8607
            }
60 andreas 8608
        }
8609
    }
8610
}
8611
 
82 andreas 8612
void TPageManager::getBMP(int port, vector<int> &channels, vector<string> &pars)
8613
{
8614
    DECL_TRACER("TPageManager::getBMP(int port, vector<int> &channels, vector<string> &pars)");
8615
 
8616
    if (pars.size() < 1)
8617
    {
8618
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
8619
        return;
8620
    }
8621
 
8622
    TError::clear();
8623
    int btState = atoi(pars[0].c_str());
8624
    string bmp;
8625
 
193 andreas 8626
    vector<TMap::MAP_T> map = findButtons(port, channels);
82 andreas 8627
 
8628
    if (TError::isError() || map.empty())
8629
        return;
8630
 
8631
    vector<Button::TButton *> buttons = collectButtons(map);
8632
 
83 andreas 8633
    if (buttons.size() > 0)
82 andreas 8634
    {
110 andreas 8635
        Button::TButton *bt = buttons[0];
82 andreas 8636
 
110 andreas 8637
        if (btState == 0)       // All instances?
82 andreas 8638
        {
110 andreas 8639
            int bst = bt->getNumberInstances();
82 andreas 8640
 
110 andreas 8641
            for (int i = 0; i < bst; i++)
82 andreas 8642
            {
110 andreas 8643
                bmp = bt->getBitmapName(i);
82 andreas 8644
 
110 andreas 8645
                if (bmp.empty())
8646
                    continue;
82 andreas 8647
 
300 andreas 8648
                sendCustomEvent(i + 1, (int)bmp.length(), 0, bmp, 1002, bt->getChannelPort(), bt->getChannelNumber());
83 andreas 8649
            }
82 andreas 8650
        }
110 andreas 8651
        else
8652
        {
8653
            bmp = bt->getTextColor(btState-1);
300 andreas 8654
            sendCustomEvent(btState, (int)bmp.length(), 0, bmp, 1002, bt->getChannelPort(), bt->getChannelNumber());
110 andreas 8655
        }
82 andreas 8656
    }
8657
}
8658
 
60 andreas 8659
/**
16 andreas 8660
 * Set the button opacity. The button opacity can be specified as a decimal
8661
 * between 0 - 255, where zero (0) is invisible and 255 is opaque, or as a
8662
 * HEX code, as used in the color commands by preceding the HEX code with
8663
 * the # sign. In this case, #00 becomes invisible and #FF becomes opaque.
8664
 * If the opacity is set to zero (0), this does not make the button inactive,
8665
 * only invisible.
8666
 */
8667
void TPageManager::doBOP(int port, vector<int>& channels, vector<string>& pars)
8668
{
8669
    DECL_TRACER("TPageManager::doBOP(int port, vector<int>& channels, vector<string>& pars)");
8670
 
8671
    if (pars.size() < 2)
8672
    {
8673
        MSG_ERROR("Expecting 2 parameters but got " << pars.size() << "! Ignoring command.");
335 andreas 8674
#if TESTMODE == 1
8675
        setAllDone();
8676
#endif
16 andreas 8677
        return;
8678
    }
8679
 
8680
    TError::clear();
335 andreas 8681
    int btState = atoi(pars[0].c_str()) - 1;
16 andreas 8682
    int btOpacity = 0;
8683
 
8684
    if (pars[1].at(0) == '#')
8685
        btOpacity = (int)strtol(pars[1].substr(1).c_str(), NULL, 16);
8686
    else
8687
        btOpacity = atoi(pars[1].c_str());
8688
 
193 andreas 8689
    vector<TMap::MAP_T> map = findButtons(port, channels);
16 andreas 8690
 
8691
    if (TError::isError() || map.empty())
335 andreas 8692
    {
8693
#if TESTMODE == 1
8694
        setAllDone();
8695
#endif
16 andreas 8696
        return;
335 andreas 8697
    }
16 andreas 8698
 
8699
    vector<Button::TButton *> buttons = collectButtons(map);
8700
 
83 andreas 8701
    if (buttons.size() > 0)
16 andreas 8702
    {
83 andreas 8703
        vector<Button::TButton *>::iterator mapIter;
16 andreas 8704
 
83 andreas 8705
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
16 andreas 8706
        {
83 andreas 8707
            Button::TButton *bt = *mapIter;
335 andreas 8708
            bt->setOpacity(btOpacity, btState);
8709
#if TESTMODE == 1
8710
            if (_gTestMode)
8711
                _gTestMode->setResult(intToString(bt->getOpacity(btState < 0 ? 0 : btState)));
342 andreas 8712
#endif
16 andreas 8713
        }
8714
    }
335 andreas 8715
#if TESTMODE == 1
8716
    setDone();
8717
#endif
16 andreas 8718
}
8719
 
106 andreas 8720
void TPageManager::getBOP(int port, vector<int>& channels, vector<string>& pars)
8721
{
8722
    DECL_TRACER("TPageManager::getBOP(int port, vector<int>& channels, vector<string>& pars)");
8723
 
8724
    if (pars.size() < 1)
8725
    {
8726
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
8727
        return;
8728
    }
8729
 
8730
    TError::clear();
8731
    int btState = atoi(pars[0].c_str());
8732
 
193 andreas 8733
    vector<TMap::MAP_T> map = findButtons(port, channels);
106 andreas 8734
 
8735
    if (TError::isError() || map.empty())
8736
        return;
8737
 
8738
    vector<Button::TButton *> buttons = collectButtons(map);
8739
 
8740
    if (buttons.size() > 0)
8741
    {
110 andreas 8742
        Button::TButton *bt = buttons[0];
106 andreas 8743
 
110 andreas 8744
        if (btState == 0)       // All instances?
106 andreas 8745
        {
110 andreas 8746
            int bst = bt->getNumberInstances();
106 andreas 8747
 
110 andreas 8748
            for (int i = 0; i < bst; i++)
106 andreas 8749
            {
110 andreas 8750
                int oo = bt->getOpacity(i);
8751
                sendCustomEvent(i + 1, oo, 0, "", 1015, bt->getChannelPort(), bt->getChannelNumber());
106 andreas 8752
            }
8753
        }
110 andreas 8754
        else
8755
        {
8756
            int oo = bt->getOpacity(btState-1);
8757
            sendCustomEvent(btState, oo, 0, "", 1015, bt->getChannelPort(), bt->getChannelNumber());
8758
        }
106 andreas 8759
    }
8760
}
8761
 
60 andreas 8762
void TPageManager::doBOR(int port, vector<int>& channels, vector<string>& pars)
8763
{
8764
    DECL_TRACER("TPageManager::doBOR(int port, vector<int>& channels, vector<string>& pars)");
8765
 
8766
    if (pars.size() < 1)
8767
    {
8768
        MSG_ERROR("Expecting at least 1 parameter but got " << pars.size() << "! Ignoring command.");
335 andreas 8769
#if TESTMODE == 1
8770
        setAllDone();
8771
#endif
60 andreas 8772
        return;
8773
    }
8774
 
8775
    TError::clear();
8776
    // Numbers of styles from 0 to 41
8777
    string bor = pars[0];
8778
    string border = "None";
8779
    int ibor = -1;
336 andreas 8780
    Border::TIntBorder borders;
60 andreas 8781
 
8782
    if (bor.at(0) >= '0' && bor.at(0) <= '9')
336 andreas 8783
    {
60 andreas 8784
        ibor = atoi(bor.c_str());
8785
 
336 andreas 8786
        if (ibor >= 0 && ibor <= 41)
8787
            border = borders.getTP4BorderName(ibor);
8788
        else
60 andreas 8789
        {
336 andreas 8790
            MSG_WARNING("Invalid border style ID " << ibor);
8791
#if TESTMODE == 1
8792
            setAllDone();
8793
#endif
8794
            return;
8795
        }
60 andreas 8796
 
336 andreas 8797
        MSG_DEBUG("Id " << ibor << " is border " << border);
60 andreas 8798
    }
336 andreas 8799
    else
60 andreas 8800
    {
336 andreas 8801
        if (!borders.isTP4BorderValid(bor))
8802
        {
8803
            MSG_WARNING("Unknown border style " << bor);
335 andreas 8804
#if TESTMODE == 1
336 andreas 8805
            setAllDone();
335 andreas 8806
#endif
336 andreas 8807
            return;
8808
        }
60 andreas 8809
 
336 andreas 8810
        border = bor;
60 andreas 8811
    }
8812
 
193 andreas 8813
    vector<TMap::MAP_T> map = findButtons(port, channels);
60 andreas 8814
 
8815
    if (TError::isError() || map.empty())
335 andreas 8816
    {
8817
#if TESTMODE == 1
8818
        setAllDone();
8819
#endif
60 andreas 8820
        return;
335 andreas 8821
    }
60 andreas 8822
 
8823
    vector<Button::TButton *> buttons = collectButtons(map);
8824
 
83 andreas 8825
    if (buttons.size() > 0)
60 andreas 8826
    {
83 andreas 8827
        vector<Button::TButton *>::iterator mapIter;
8828
 
8829
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
8830
        {
8831
            Button::TButton *bt = *mapIter;
8832
            bt->setBorderStyle(border);
335 andreas 8833
#if TESTMODE == 1
8834
            if (_gTestMode)
8835
                _gTestMode->setResult(bt->getBorderStyle(0));
8836
#endif
83 andreas 8837
        }
60 andreas 8838
    }
335 andreas 8839
#if TESTMODE == 1
8840
    setDone();
8841
#endif
60 andreas 8842
}
8843
 
107 andreas 8844
void TPageManager::doBOS(int port, vector<int>& channels, vector<string>& pars)
8845
{
8846
    DECL_TRACER("TPageManager::doBOS(int port, vector<int>& channels, vector<string>& pars)");
8847
 
8848
    if (pars.size() < 2)
8849
    {
8850
        MSG_ERROR("Expecting at least 2 parameters but got " << pars.size() << "! Ignoring command.");
8851
        return;
8852
    }
8853
 
8854
    TError::clear();
8855
    int btState = atoi(pars[0].c_str());
8856
    int videoState = atoi(pars[1].c_str());
8857
 
193 andreas 8858
    vector<TMap::MAP_T> map = findButtons(port, channels);
107 andreas 8859
 
8860
    if (TError::isError() || map.empty())
8861
        return;
8862
 
8863
    vector<Button::TButton *> buttons = collectButtons(map);
8864
 
8865
    if (buttons.size() > 0)
8866
    {
8867
        vector<Button::TButton *>::iterator mapIter;
8868
 
8869
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
8870
        {
8871
            Button::TButton *bt = *mapIter;
8872
 
8873
            if (btState == 0)       // All instances?
8874
                bt->setDynamic(videoState);
8875
            else
8876
                bt->setDynamic(videoState, btState-1);
8877
        }
8878
    }
8879
}
8880
 
16 andreas 8881
/**
60 andreas 8882
 * Set the border of a button state/states.
8883
 * The border names are available through the TPDesign4 border-name drop-down
8884
 * list.
8885
 */
8886
void TPageManager::doBRD(int port, vector<int>& channels, vector<string>& pars)
8887
{
8888
    DECL_TRACER("TPageManager::doBRD(int port, vector<int>& channels, vector<string>& pars)");
8889
 
8890
    if (pars.size() < 1)
8891
    {
8892
        MSG_ERROR("Expecting at least 1 parameter but got " << pars.size() << "! Ignoring command.");
8893
        return;
8894
    }
8895
 
8896
    TError::clear();
8897
    int btState = atoi(pars[0].c_str());
8898
    string border = "None";
8899
 
8900
    if (pars.size() > 1)
8901
        border = pars[1];
8902
 
193 andreas 8903
    vector<TMap::MAP_T> map = findButtons(port, channels);
60 andreas 8904
 
8905
    if (TError::isError() || map.empty())
8906
        return;
8907
 
8908
    vector<Button::TButton *> buttons = collectButtons(map);
8909
 
83 andreas 8910
    if (buttons.size() > 0)
60 andreas 8911
    {
83 andreas 8912
        vector<Button::TButton *>::iterator mapIter;
60 andreas 8913
 
83 andreas 8914
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
60 andreas 8915
        {
83 andreas 8916
            Button::TButton *bt = *mapIter;
252 andreas 8917
//            setButtonCallbacks(bt);
60 andreas 8918
 
83 andreas 8919
            if (btState == 0)       // All instances?
8920
            {
8921
                int bst = bt->getNumberInstances();
8922
 
8923
                for (int i = 0; i < bst; i++)
106 andreas 8924
                    bt->setBorderStyle(border, i+1);
83 andreas 8925
            }
8926
            else
106 andreas 8927
                bt->setBorderStyle(border, btState);
60 andreas 8928
        }
8929
    }
8930
}
8931
 
107 andreas 8932
void TPageManager::getBRD(int port, vector<int>& channels, vector<string>& pars)
8933
{
8934
    DECL_TRACER("TPageManager::getBRD(int port, vector<int>& channels, vector<string>& pars)");
8935
 
8936
    if (pars.size() < 1)
8937
    {
8938
        MSG_ERROR("Expecting at least 1 parameter but got " << pars.size() << "! Ignoring command.");
8939
        return;
8940
    }
8941
 
8942
    TError::clear();
8943
    int btState = atoi(pars[0].c_str());
8944
 
193 andreas 8945
    vector<TMap::MAP_T> map = findButtons(port, channels);
107 andreas 8946
 
8947
    if (TError::isError() || map.empty())
8948
        return;
8949
 
8950
    vector<Button::TButton *> buttons = collectButtons(map);
8951
 
8952
    if (buttons.size() > 0)
8953
    {
110 andreas 8954
        Button::TButton *bt = buttons[0];
107 andreas 8955
 
110 andreas 8956
        if (btState == 0)       // All instances?
107 andreas 8957
        {
110 andreas 8958
            int bst = bt->getNumberInstances();
107 andreas 8959
 
110 andreas 8960
            for (int i = 0; i < bst; i++)
107 andreas 8961
            {
110 andreas 8962
                string bname = bt->getBorderStyle(i);
300 andreas 8963
                sendCustomEvent(i + 1, (int)bname.length(), 0, bname, 1014, bt->getChannelPort(), bt->getChannelNumber());
107 andreas 8964
            }
8965
        }
110 andreas 8966
        else
8967
        {
8968
            string bname = bt->getBorderStyle(btState-1);
300 andreas 8969
            sendCustomEvent(btState, (int)bname.length(), 0, bname, 1014, bt->getChannelPort(), bt->getChannelNumber());
110 andreas 8970
        }
107 andreas 8971
    }
8972
}
8973
 
60 andreas 8974
/**
16 andreas 8975
 * Set the button size and its position on the page.
8976
 */
8977
void TPageManager::doBSP(int port, vector<int>& channels, vector<string>& pars)
8978
{
8979
    DECL_TRACER("TPageManager::doBSP(int port, vector<int>& channels, vector<string>& pars)");
8980
 
8981
    if (pars.size() < 1)
8982
    {
8983
        MSG_ERROR("Expecting at least 1 parameter but got " << pars.size() << "! Ignoring command.");
341 andreas 8984
#if TESTMODE == 1
8985
        setAllDone();
8986
#endif
16 andreas 8987
        return;
8988
    }
8989
 
8990
    TError::clear();
8991
    bool bLeft = false, bTop = false, bRight = false, bBottom = false;
8992
    int x, y;
8993
 
83 andreas 8994
    if (pars.size() > 0)
16 andreas 8995
    {
83 andreas 8996
        vector<string>::iterator iter;
8997
 
8998
        for (iter = pars.begin(); iter != pars.end(); iter++)
8999
        {
9000
            if (iter->compare("left") == 0)
9001
                bLeft = true;
9002
            else if (iter->compare("top") == 0)
9003
                bTop = true;
9004
            else if (iter->compare("right") == 0)
9005
                bRight = true;
9006
            else if (iter->compare("bottom") == 0)
9007
                bBottom = true;
9008
        }
16 andreas 9009
    }
9010
 
193 andreas 9011
    vector<TMap::MAP_T> map = findButtons(port, channels);
16 andreas 9012
 
9013
    if (TError::isError() || map.empty())
9014
        return;
9015
 
9016
    vector<Button::TButton *> buttons = collectButtons(map);
409 andreas 9017
    x = y = 0;
16 andreas 9018
 
83 andreas 9019
    if (buttons.size() > 0)
16 andreas 9020
    {
83 andreas 9021
        vector<Button::TButton *>::iterator mapIter;
16 andreas 9022
 
83 andreas 9023
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
9024
        {
9025
            Button::TButton *bt = *mapIter;
16 andreas 9026
 
83 andreas 9027
            if (bLeft)
9028
                x = 0;
16 andreas 9029
 
83 andreas 9030
            if (bTop)
9031
                y = 0;
16 andreas 9032
 
341 andreas 9033
            if (bRight || bBottom)
16 andreas 9034
            {
83 andreas 9035
                ulong handle = bt->getHandle();
9036
                int parentID = (handle >> 16) & 0x0000ffff;
9037
                int pwidth = 0;
341 andreas 9038
                int pheight = 0;
16 andreas 9039
 
83 andreas 9040
                if (parentID < 500)
16 andreas 9041
                {
83 andreas 9042
                    TPage *pg = getPage(parentID);
9043
 
9044
                    if (!pg)
9045
                    {
9046
                        MSG_ERROR("Internal error: Page " << parentID << " not found!");
9047
                        return;
9048
                    }
9049
 
9050
                    pwidth = pg->getWidth();
341 andreas 9051
                    pheight = pg->getHeight();
16 andreas 9052
                }
83 andreas 9053
                else
9054
                {
9055
                    TSubPage *spg = getSubPage(parentID);
16 andreas 9056
 
83 andreas 9057
                    if (!spg)
9058
                    {
9059
                        MSG_ERROR("Internal error: Subpage " << parentID << " not found!");
9060
                        return;
9061
                    }
16 andreas 9062
 
83 andreas 9063
                    pwidth = spg->getWidth();
341 andreas 9064
                    pheight = spg->getHeight();
16 andreas 9065
                }
9066
 
341 andreas 9067
                if (bRight)
9068
                    x = pwidth - bt->getWidth();
9069
 
9070
                if (bBottom)
9071
                    y = pheight - bt->getHeight();
16 andreas 9072
            }
9073
 
341 andreas 9074
            bt->setLeftTop(x, y);
9075
#if TESTMODE == 1
9076
            if (_gTestMode)
83 andreas 9077
            {
341 andreas 9078
                int left = bt->getLeftPosition();
9079
                int top = bt->getTopPosition();
9080
                string res = intToString(left) + "," + intToString(top);
9081
                _gTestMode->setResult(res);
16 andreas 9082
            }
341 andreas 9083
#endif
16 andreas 9084
        }
9085
    }
341 andreas 9086
#if TESTMODE == 1
9087
    setDone();
9088
#endif
16 andreas 9089
}
9090
 
9091
/**
107 andreas 9092
 * Submit text for text area buttons. This command causes the text areas to
9093
 * send their text as strings to the NetLinx Master.
9094
 */
9095
void TPageManager::doBSM(int port, vector<int>& channels, vector<string>&)
9096
{
9097
    DECL_TRACER("TPageManager::doBSM(int port, vector<int>& channels, vector<string>& pars)");
9098
 
9099
    TError::clear();
193 andreas 9100
    vector<TMap::MAP_T> map = findButtons(port, channels);
107 andreas 9101
 
9102
    if (TError::isError() || map.empty())
341 andreas 9103
    {
9104
#if TESTMODE == 1
9105
        setAllDone();
9106
#endif
107 andreas 9107
        return;
341 andreas 9108
    }
107 andreas 9109
 
9110
    vector<Button::TButton *> buttons = collectButtons(map);
9111
 
9112
    if (buttons.size() > 0)
9113
    {
9114
        vector<Button::TButton *>::iterator mapIter;
9115
 
9116
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
9117
        {
9118
            Button::TButton *bt = *mapIter;
9119
 
195 andreas 9120
            if (bt->getButtonType() != TEXT_INPUT && bt->getButtonType() != GENERAL)
341 andreas 9121
            {
9122
#if TESTMODE == 1
9123
                setAllDone();
9124
#endif
107 andreas 9125
                return;
341 andreas 9126
            }
107 andreas 9127
 
9128
            amx::ANET_SEND scmd;
9129
            scmd.port = bt->getChannelPort();
9130
            scmd.channel = bt->getChannelNumber();
9131
            scmd.ID = scmd.channel;
9132
            scmd.msg = bt->getText(0);
9133
            scmd.MC = 0x008b;       // string value
9134
 
9135
            if (gAmxNet)
9136
                gAmxNet->sendCommand(scmd);
9137
            else
9138
                MSG_WARNING("Missing global class TAmxNet. Can't send message!");
9139
 
9140
        }
9141
    }
9142
}
9143
 
9144
/**
9145
 * Set the sound played when a button is pressed. If the sound name is blank
9146
 * the sound is then cleared. If the sound name is not matched, the button
9147
 * sound is not changed.
9148
 */
9149
void TPageManager::doBSO(int port, vector<int>& channels, vector<string>& pars)
9150
{
9151
    DECL_TRACER("TPageManager::doBSO(int port, vector<int>& channels, vector<string>& pars)");
9152
 
9153
    if (pars.size() < 2)
9154
    {
9155
        MSG_ERROR("Expecting 2 parameters but got " << pars.size() << "! Ignoring command.");
9156
        return;
9157
    }
9158
 
9159
    if (!gPrjResources)
9160
        return;
9161
 
9162
    TError::clear();
9163
    int btState = atoi(pars[0].c_str());
9164
    string sound = pars[1];
9165
 
9166
    if (!soundExist(sound))
9167
        return;
9168
 
193 andreas 9169
    vector<TMap::MAP_T> map = findButtons(port, channels);
107 andreas 9170
 
9171
    if (TError::isError() || map.empty())
9172
        return;
9173
 
9174
    vector<Button::TButton *> buttons = collectButtons(map);
9175
 
9176
    if (buttons.size() > 0)
9177
    {
9178
        vector<Button::TButton *>::iterator mapIter;
9179
 
9180
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
9181
        {
9182
            Button::TButton *bt = *mapIter;
9183
 
9184
            if (btState == 0)
9185
            {
9186
                int bst = bt->getNumberInstances();
9187
 
9188
                for (int i = 0; i < bst; i++)
9189
                    bt->setSound(sound, i);
9190
            }
9191
            else
9192
                bt->setSound(sound, btState-1);
9193
        }
9194
    }
9195
}
9196
 
9197
/**
16 andreas 9198
 * Set the button word wrap feature to those buttons with a defined address
9199
 * range. By default, word-wrap is Off.
9200
 */
9201
void TPageManager::doBWW(int port, vector<int>& channels, vector<string>& pars)
9202
{
9203
    DECL_TRACER("TPageManager::doBWW(int port, vector<int>& channels, vector<string>& pars)");
9204
 
9205
    if (pars.size() < 1)
9206
    {
9207
        MSG_ERROR("Expecting 1 parameter but got " << pars.size() << "! Ignoring command.");
9208
        return;
9209
    }
9210
 
9211
    TError::clear();
9212
    int btState = atoi(pars[0].c_str());
9213
 
193 andreas 9214
    vector<TMap::MAP_T> map = findButtons(port, channels);
16 andreas 9215
 
9216
    if (TError::isError() || map.empty())
9217
        return;
9218
 
9219
    vector<Button::TButton *> buttons = collectButtons(map);
9220
 
83 andreas 9221
    if (buttons.size() > 0)
16 andreas 9222
    {
83 andreas 9223
        vector<Button::TButton *>::iterator mapIter;
16 andreas 9224
 
83 andreas 9225
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
16 andreas 9226
        {
83 andreas 9227
            Button::TButton *bt = *mapIter;
252 andreas 9228
//            setButtonCallbacks(bt);
16 andreas 9229
 
83 andreas 9230
            if (btState == 0)       // All instances?
9231
            {
9232
                int bst = bt->getNumberInstances();
9233
                MSG_DEBUG("Setting word wrap on all " << bst << " instances...");
9234
 
9235
                for (int i = 0; i < bst; i++)
110 andreas 9236
                    bt->setTextWordWrap(true, i);
83 andreas 9237
            }
9238
            else
110 andreas 9239
                bt->setTextWordWrap(true, btState - 1);
16 andreas 9240
        }
9241
    }
9242
}
9243
 
108 andreas 9244
void TPageManager::getBWW(int port, vector<int>& channels, vector<string>& pars)
9245
{
9246
    DECL_TRACER("TPageManager::getBWW(int port, vector<int>& channels, vector<string>& pars)");
9247
 
9248
    if (pars.size() < 1)
9249
    {
9250
        MSG_ERROR("Expecting at least 1 parameter but got " << pars.size() << "! Ignoring command.");
9251
        return;
9252
    }
9253
 
9254
    TError::clear();
9255
    int btState = atoi(pars[0].c_str());
9256
 
193 andreas 9257
    vector<TMap::MAP_T> map = findButtons(port, channels);
108 andreas 9258
 
9259
    if (TError::isError() || map.empty())
9260
        return;
9261
 
9262
    vector<Button::TButton *> buttons = collectButtons(map);
9263
 
9264
    if (buttons.size() > 0)
9265
    {
110 andreas 9266
        Button::TButton *bt = buttons[0];
108 andreas 9267
 
110 andreas 9268
        if (btState == 0)       // All instances?
108 andreas 9269
        {
110 andreas 9270
            int bst = bt->getNumberInstances();
108 andreas 9271
 
110 andreas 9272
            for (int i = 0; i < bst; i++)
9273
                sendCustomEvent(i + 1, bt->getTextWordWrap(i), 0, "", 1010, bt->getChannelPort(), bt->getChannelNumber());
108 andreas 9274
        }
110 andreas 9275
        else
9276
            sendCustomEvent(btState, bt->getTextWordWrap(btState-1), 0, "", 1010, bt->getChannelPort(), bt->getChannelNumber());
108 andreas 9277
    }
9278
}
9279
 
16 andreas 9280
/**
9281
 * Clear all page flips from a button.
9282
 */
22 andreas 9283
void TPageManager::doCPF(int port, vector<int>& channels, vector<string>&)
16 andreas 9284
{
9285
    DECL_TRACER("TPageManager::doCPF(int port, vector<int>& channels, vector<string>& pars)");
9286
 
9287
    TError::clear();
193 andreas 9288
    vector<TMap::MAP_T> map = findButtons(port, channels);
16 andreas 9289
 
9290
    if (TError::isError() || map.empty())
9291
        return;
9292
 
9293
    vector<Button::TButton *> buttons = collectButtons(map);
9294
 
83 andreas 9295
    if (buttons.size() > 0)
16 andreas 9296
    {
83 andreas 9297
        vector<Button::TButton *>::iterator mapIter;
9298
 
9299
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
9300
        {
9301
            Button::TButton *bt = *mapIter;
252 andreas 9302
//            setButtonCallbacks(bt);
83 andreas 9303
            bt->clearPushFunctions();
9304
        }
16 andreas 9305
    }
9306
}
9307
 
9308
/**
9309
 * Delete page flips from button if it already exists.
9310
 */
9311
void TPageManager::doDPF(int port, vector<int>& channels, vector<string>& pars)
9312
{
9313
    DECL_TRACER("TPageManager::doDPF(int port, vector<int>& channels, vector<string>& pars)");
9314
 
9315
    if (pars.size() < 1)
9316
    {
9317
        MSG_ERROR("Expecting at least 1 parameter but got " << pars.size() << "! Ignoring command.");
9318
        return;
9319
    }
9320
 
9321
    TError::clear();
9322
    string action = pars[0];
9323
    string pname;
9324
 
9325
    if (pars.size() >= 2)
9326
    {
9327
        pname = pars[1];
9328
        vector<Button::TButton *> list;
9329
        // First we search for a subpage because this is more likely
9330
        TSubPage *spg = getSubPage(pname);
9331
 
9332
        if (spg)
9333
            list = spg->getButtons(port, channels[0]);
9334
        else    // Then for a page
9335
        {
9336
            TPage *pg = getPage(pname);
9337
 
9338
            if (pg)
9339
                list = pg->getButtons(port, channels[0]);
9340
            else
9341
            {
9342
                MSG_WARNING("The name " << pname << " doesn't name either a page or a subpage!");
9343
                return;
9344
            }
9345
        }
9346
 
9347
        if (list.empty())
9348
            return;
9349
 
9350
        vector<Button::TButton *>::iterator it;
9351
 
9352
        for (it = list.begin(); it != list.end(); it++)
9353
        {
9354
            Button::TButton *bt = *it;
252 andreas 9355
//            setButtonCallbacks(bt);
16 andreas 9356
            bt->clearPushFunction(action);
9357
        }
9358
 
9359
        return;
9360
    }
9361
 
9362
    // Here we don't have a page name
193 andreas 9363
    vector<TMap::MAP_T> map = findButtons(port, channels);
16 andreas 9364
 
9365
    if (TError::isError() || map.empty())
9366
        return;
9367
 
9368
    vector<Button::TButton *> buttons = collectButtons(map);
9369
 
83 andreas 9370
    if (buttons.size() > 0)
16 andreas 9371
    {
83 andreas 9372
        vector<Button::TButton *>::iterator mapIter;
9373
 
9374
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
9375
        {
9376
            Button::TButton *bt = *mapIter;
252 andreas 9377
//            setButtonCallbacks(bt);
83 andreas 9378
            bt->clearPushFunction(action);
9379
        }
16 andreas 9380
    }
9381
}
9382
 
9383
/**
9384
 * Enable or disable buttons with a set variable text range.
9385
 */
9386
void TPageManager::doENA(int port, vector<int>& channels, vector<string>& pars)
9387
{
9388
    DECL_TRACER("TPageManager::doENA(int port, vector<int>& channels, vector<string>& pars)");
9389
 
9390
    if (pars.empty())
9391
    {
9392
        MSG_ERROR("Expecting 1 parameter but got none! Ignoring command.");
341 andreas 9393
#if TESTMODE == 1
9394
        setAllDone();
9395
#endif
16 andreas 9396
        return;
9397
    }
9398
 
9399
    TError::clear();
9400
    int cvalue = atoi(pars[0].c_str());
9401
 
193 andreas 9402
    vector<TMap::MAP_T> map = findButtons(port, channels);
16 andreas 9403
 
9404
    if (TError::isError() || map.empty())
341 andreas 9405
    {
9406
#if TESTMODE == 1
9407
        setAllDone();
9408
#endif
16 andreas 9409
        return;
341 andreas 9410
    }
16 andreas 9411
 
9412
    vector<Button::TButton *> buttons = collectButtons(map);
9413
 
83 andreas 9414
    if (buttons.size() > 0)
16 andreas 9415
    {
83 andreas 9416
        vector<Button::TButton *>::iterator mapIter;
9417
 
9418
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
9419
        {
9420
            Button::TButton *bt = *mapIter;
9421
            bt->setEnable(((cvalue)?true:false));
341 andreas 9422
#if TESTMODE == 1
9423
            __success = true;
9424
 
9425
            if (_gTestMode)
9426
                _gTestMode->setResult(intToString(cvalue));
9427
#endif
83 andreas 9428
        }
16 andreas 9429
    }
341 andreas 9430
#if TESTMODE == 1
9431
    setAllDone();
9432
#endif
16 andreas 9433
}
9434
 
9435
/**
9436
 * Set a font to a specific Font ID value for those buttons with a defined
9437
 * address range. Font ID numbers are generated by the TPDesign4 programmers
9438
 * report.
9439
 */
9440
void TPageManager::doFON(int port, vector<int>& channels, vector<string>& pars)
9441
{
9442
    DECL_TRACER("TPageManager::doFON(int port, vector<int>& channels, vector<string>& pars)");
9443
 
9444
    if (pars.size() < 2)
9445
    {
9446
        MSG_ERROR("Expecting 2 parameters but got " << pars.size() << "! Ignoring command.");
342 andreas 9447
#if TESTMODE == 1
9448
        setAllDone();
9449
#endif
16 andreas 9450
        return;
9451
    }
9452
 
9453
    TError::clear();
342 andreas 9454
    int btState = atoi(pars[0].c_str()) - 1;
16 andreas 9455
    int fvalue = atoi(pars[1].c_str());
9456
 
193 andreas 9457
    vector<TMap::MAP_T> map = findButtons(port, channels);
16 andreas 9458
 
9459
    if (TError::isError() || map.empty())
9460
        return;
9461
 
9462
    vector<Button::TButton *> buttons = collectButtons(map);
9463
 
83 andreas 9464
    if (buttons.size() > 0)
16 andreas 9465
    {
83 andreas 9466
        vector<Button::TButton *>::iterator mapIter;
16 andreas 9467
 
83 andreas 9468
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
16 andreas 9469
        {
83 andreas 9470
            Button::TButton *bt = *mapIter;
342 andreas 9471
            bt->setFont(fvalue, btState);
9472
#if TESTMODE == 1
9473
            if (_gTestMode)
9474
                _gTestMode->setResult(intToString(bt->getFontIndex(btState < 0 ? 0 : btState)));
9475
#endif
16 andreas 9476
        }
9477
    }
342 andreas 9478
#if TESTMODE == 1
9479
    setDone();
9480
#endif
16 andreas 9481
}
9482
 
108 andreas 9483
void TPageManager::getFON(int port, vector<int>& channels, vector<string>& pars)
9484
{
9485
    DECL_TRACER("TPageManager::getFON(int port, vector<int>& channels, vector<string>& pars)");
9486
 
9487
    if (pars.size() < 1)
9488
    {
9489
        MSG_ERROR("Expecting at least 1 parameter but got " << pars.size() << "! Ignoring command.");
342 andreas 9490
#if TESTMODE == 1
9491
        setAllDone();
9492
#endif
108 andreas 9493
        return;
9494
    }
9495
 
9496
    TError::clear();
9497
    int btState = atoi(pars[0].c_str());
9498
 
193 andreas 9499
    vector<TMap::MAP_T> map = findButtons(port, channels);
108 andreas 9500
 
9501
    if (TError::isError() || map.empty())
342 andreas 9502
    {
9503
#if TESTMODE == 1
9504
        setAllDone();
9505
#endif
108 andreas 9506
        return;
342 andreas 9507
    }
108 andreas 9508
 
9509
    vector<Button::TButton *> buttons = collectButtons(map);
9510
 
9511
    if (buttons.size() > 0)
9512
    {
110 andreas 9513
        Button::TButton *bt = buttons[0];
108 andreas 9514
 
110 andreas 9515
        if (btState == 0)       // All instances?
108 andreas 9516
        {
110 andreas 9517
            int bst = bt->getNumberInstances();
108 andreas 9518
 
110 andreas 9519
            for (int i = 0; i < bst; i++)
9520
                sendCustomEvent(i + 1, bt->getFontIndex(i), 0, "", 1007, bt->getChannelPort(), bt->getChannelNumber());
108 andreas 9521
        }
110 andreas 9522
        else
9523
            sendCustomEvent(btState, bt->getFontIndex(btState - 1), 0, "", 1007, bt->getChannelPort(), bt->getChannelNumber());
342 andreas 9524
#if TESTMODE == 1
9525
        if (_gTestMode)
9526
            _gTestMode->setResult(intToString(bt->getFontIndex(btState < 0 ? 0 : btState)));
9527
#endif
108 andreas 9528
    }
342 andreas 9529
#if TESTMODE == 1
9530
    __success = true;
9531
    setAllDone();
9532
#endif
108 andreas 9533
}
9534
 
388 andreas 9535
void TPageManager::doGDI(int port, vector<int>& channels, vector<std::string>& pars)
9536
{
9537
    DECL_TRACER("TPageManager::doGDI(int port, vector<int>& channels, vector<std::string>& pars)");
9538
 
9539
    if (pars.size() < 1)
9540
    {
9541
        MSG_ERROR("Expecting 1 parameter but got " << pars.size() << "! Ignoring command.");
9542
        return;
9543
    }
9544
 
9545
    TError::clear();
9546
    int inc = atoi(pars[0].c_str());
9547
 
9548
    if (inc < 0)
9549
    {
9550
        MSG_ERROR("Invalid drag increment of " << inc << "!");
9551
        return;
9552
    }
9553
 
9554
    vector<TMap::MAP_T> map = findButtons(port, channels);
9555
 
9556
    if (TError::isError() || map.empty())
9557
        return;
9558
 
9559
    vector<Button::TButton *> buttons = collectButtons(map);
9560
 
9561
    if (buttons.size() > 0)
9562
    {
9563
        vector<Button::TButton *>::iterator mapIter;
9564
 
9565
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
9566
        {
9567
            Button::TButton *bt = *mapIter;
9568
            bt->setBargraphDragIncrement(inc);
9569
        }
9570
    }
9571
}
416 andreas 9572
/*
9573
 * Invert the joystick axis to move the origin to another corner.
9574
 */
9575
void TPageManager::doGIV(int port, vector<int>& channels, vector<std::string>& pars)
388 andreas 9576
{
416 andreas 9577
    DECL_TRACER("TPageManager::doGIV(int port, vector<int>& channels, vector<std::string>& pars)");
9578
 
9579
    if (pars.empty())
9580
        return;
9581
 
9582
    TError::clear();
9583
    int inv = atoi(pars[0].c_str());
9584
 
9585
    if (inv < 0 || inv > 3)
9586
    {
9587
        MSG_ERROR("Invalid invert type " << inv);
9588
        return;
9589
    }
9590
 
9591
    vector<TMap::MAP_T> map = findButtons(port, channels);
9592
 
9593
    if (TError::isError() || map.empty())
9594
        return;
9595
 
9596
    vector<Button::TButton *> buttons = collectButtons(map);
9597
 
9598
    if (buttons.size() > 0)
9599
    {
9600
        vector<Button::TButton *>::iterator mapIter;
9601
 
9602
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
9603
        {
9604
            Button::TButton *bt = *mapIter;
9605
            bt->setBargraphInvert(inv);
9606
        }
9607
    }
388 andreas 9608
}
416 andreas 9609
 
16 andreas 9610
/**
60 andreas 9611
 * Change the bargraph upper limit.
9612
 */
9613
void TPageManager::doGLH(int port, vector<int>& channels, vector<std::string>& pars)
9614
{
9615
    DECL_TRACER("TPageManager::doGLH(int port, vector<int>& channels, vector<std::string>& pars)");
9616
 
9617
    if (pars.size() < 1)
9618
    {
9619
        MSG_ERROR("Expecting 1 parameter but got " << pars.size() << "! Ignoring command.");
9620
        return;
9621
    }
9622
 
9623
    TError::clear();
9624
    int limit = atoi(pars[0].c_str());
9625
 
9626
    if (limit < 1)
9627
    {
9628
        MSG_ERROR("Invalid upper limit " << limit << "!");
9629
        return;
9630
    }
9631
 
193 andreas 9632
    vector<TMap::MAP_T> map = findButtons(port, channels);
60 andreas 9633
 
9634
    if (TError::isError() || map.empty())
9635
        return;
9636
 
9637
    vector<Button::TButton *> buttons = collectButtons(map);
9638
 
83 andreas 9639
    if (buttons.size() > 0)
60 andreas 9640
    {
83 andreas 9641
        vector<Button::TButton *>::iterator mapIter;
9642
 
9643
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
9644
        {
9645
            Button::TButton *bt = *mapIter;
9646
            bt->setBargraphUpperLimit(limit);
9647
        }
60 andreas 9648
    }
9649
}
9650
 
9651
/**
9652
 * Change the bargraph lower limit.
9653
 */
9654
void TPageManager::doGLL(int port, vector<int>& channels, vector<std::string>& pars)
9655
{
9656
    DECL_TRACER("TPageManager::doGLL(int port, vector<int>& channels, vector<std::string>& pars)");
9657
 
9658
    if (pars.size() < 1)
9659
    {
9660
        MSG_ERROR("Expecting 1 parameter but got " << pars.size() << "! Ignoring command.");
9661
        return;
9662
    }
9663
 
9664
    TError::clear();
9665
    int limit = atoi(pars[0].c_str());
9666
 
9667
    if (limit < 1)
9668
    {
9669
        MSG_ERROR("Invalid lower limit " << limit << "!");
9670
        return;
9671
    }
9672
 
193 andreas 9673
    vector<TMap::MAP_T> map = findButtons(port, channels);
60 andreas 9674
 
9675
    if (TError::isError() || map.empty())
9676
        return;
9677
 
9678
    vector<Button::TButton *> buttons = collectButtons(map);
9679
 
83 andreas 9680
    if (buttons.size() > 0)
60 andreas 9681
    {
83 andreas 9682
        vector<Button::TButton *>::iterator mapIter;
9683
 
9684
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
9685
        {
9686
            Button::TButton *bt = *mapIter;
9687
            bt->setBargraphLowerLimit(limit);
9688
        }
60 andreas 9689
    }
9690
}
9691
 
416 andreas 9692
/*
9693
 * Change the bargraph slider color or joystick cursor color.
9694
 */
108 andreas 9695
void TPageManager::doGSC(int port, vector<int>& channels, vector<string>& pars)
9696
{
9697
    DECL_TRACER("TPageManager::doGSC(int port, vector<int>& channels, vector<string>& pars)");
9698
 
9699
    if (pars.size() < 1)
9700
    {
9701
        MSG_ERROR("Expecting 1 parameter but got " << pars.size() << "! Ignoring command.");
9702
        return;
9703
    }
9704
 
9705
    TError::clear();
9706
    string color = pars[0];
193 andreas 9707
    vector<TMap::MAP_T> map = findButtons(port, channels);
108 andreas 9708
 
9709
    if (TError::isError() || map.empty())
9710
        return;
9711
 
9712
    vector<Button::TButton *> buttons = collectButtons(map);
9713
 
9714
    if (buttons.size() > 0)
9715
    {
9716
        vector<Button::TButton *>::iterator mapIter;
9717
 
9718
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
9719
        {
9720
            Button::TButton *bt = *mapIter;
9721
            bt->setBargraphSliderColor(color);
9722
        }
9723
    }
9724
}
9725
 
361 andreas 9726
/*
388 andreas 9727
 * Set bargraph ramp down time in 1/10 seconds.
9728
 */
9729
void TPageManager::doGRD(int port, vector<int>& channels, vector<string>& pars)
9730
{
9731
    DECL_TRACER("TPageManager::doGRD(int port, vector<int>& channels, vector<string>& pars)");
9732
 
9733
    if (pars.size() < 1)
9734
    {
9735
        MSG_ERROR("Expecting 1 parameter but got " << pars.size() << "! Ignoring command.");
9736
        return;
9737
    }
9738
 
9739
    TError::clear();
9740
    int t = atoi(pars[0].c_str());
9741
 
9742
    if (t < 0)
9743
    {
9744
        MSG_ERROR("Invalid ramp down time limit " << t << "!");
9745
        return;
9746
    }
9747
 
9748
    vector<TMap::MAP_T> map = findButtons(port, channels);
9749
 
9750
    if (TError::isError() || map.empty())
9751
        return;
9752
 
9753
    vector<Button::TButton *> buttons = collectButtons(map);
9754
 
9755
    if (buttons.size() > 0)
9756
    {
9757
        vector<Button::TButton *>::iterator mapIter;
9758
 
9759
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
9760
        {
9761
            Button::TButton *bt = *mapIter;
9762
            bt->setBargraphRampDownTime(t);
9763
        }
9764
    }
9765
}
9766
 
9767
/*
9768
 * Set bargraph ramp up time in 1/10 seconds.
9769
 */
9770
void TPageManager::doGRU(int port, vector<int>& channels, vector<string>& pars)
9771
{
9772
    DECL_TRACER("TPageManager::doGRU(int port, vector<int>& channels, vector<string>& pars)");
9773
 
9774
    if (pars.size() < 1)
9775
    {
9776
        MSG_ERROR("Expecting 1 parameter but got " << pars.size() << "! Ignoring command.");
9777
        return;
9778
    }
9779
 
9780
    TError::clear();
9781
    int t = atoi(pars[0].c_str());
9782
 
9783
    if (t < 0)
9784
    {
9785
        MSG_ERROR("Invalid ramp up time limit " << t << "!");
9786
        return;
9787
    }
9788
 
9789
    vector<TMap::MAP_T> map = findButtons(port, channels);
9790
 
9791
    if (TError::isError() || map.empty())
9792
        return;
9793
 
9794
    vector<Button::TButton *> buttons = collectButtons(map);
9795
 
9796
    if (buttons.size() > 0)
9797
    {
9798
        vector<Button::TButton *>::iterator mapIter;
9799
 
9800
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
9801
        {
9802
            Button::TButton *bt = *mapIter;
9803
            bt->setBargraphRampUpTime(t);
9804
        }
9805
    }
9806
}
9807
 
9808
/*
361 andreas 9809
 * Change the bargraph slider name or joystick cursor name.
9810
 */
9811
void TPageManager::doGSN(int port, vector<int>& channels, vector<string>& pars)
9812
{
9813
    DECL_TRACER("TPageManager::doGSN(int port, vector<int>& channels, vector<string>& pars)");
9814
 
9815
    if (pars.size() < 1)
9816
    {
9817
        MSG_ERROR("Expecting 1 parameter but got " << pars.size() << "! Ignoring command.");
9818
        return;
9819
    }
9820
 
9821
    TError::clear();
9822
    string name = pars[0];
9823
    vector<TMap::MAP_T> map = findButtons(port, channels);
9824
 
9825
    if (TError::isError() || map.empty())
9826
        return;
9827
 
9828
    vector<Button::TButton *> buttons = collectButtons(map);
9829
 
9830
    if (buttons.size() > 0)
9831
    {
9832
        vector<Button::TButton *>::iterator mapIter;
9833
 
9834
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
9835
        {
9836
            Button::TButton *bt = *mapIter;
9837
            bt->setBargraphSliderName(name);
9838
        }
9839
    }
9840
}
9841
 
60 andreas 9842
/**
14 andreas 9843
 * Set the icon to a button.
9844
 */
9845
void TPageManager::doICO(int port, vector<int>& channels, vector<string>& pars)
9846
{
9847
    DECL_TRACER("TPageManager::doICO(int port, vector<int>& channels, vector<string>& pars)");
9848
 
9849
    if (pars.size() < 2)
9850
    {
9851
        MSG_ERROR("Expecting 2 parameters but got " << pars.size() << "! Ignoring command.");
9852
        return;
9853
    }
9854
 
16 andreas 9855
    TError::clear();
14 andreas 9856
    int btState = atoi(pars[0].c_str());
9857
    int iconIdx = atoi(pars[1].c_str());
9858
 
193 andreas 9859
    vector<TMap::MAP_T> map = findButtons(port, channels);
14 andreas 9860
 
9861
    if (TError::isError() || map.empty())
9862
        return;
9863
 
9864
    vector<Button::TButton *> buttons = collectButtons(map);
9865
 
83 andreas 9866
    if (buttons.size() > 0)
14 andreas 9867
    {
83 andreas 9868
        vector<Button::TButton *>::iterator mapIter;
14 andreas 9869
 
83 andreas 9870
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
14 andreas 9871
        {
83 andreas 9872
            Button::TButton *bt = *mapIter;
14 andreas 9873
 
83 andreas 9874
            if (btState == 0)       // All instances?
14 andreas 9875
            {
316 andreas 9876
                if (iconIdx > 0)
9877
                    bt->setIcon(iconIdx, -1);
9878
                else
9879
                    bt->revokeIcon(-1);
14 andreas 9880
            }
83 andreas 9881
            else if (iconIdx > 0)
9882
                bt->setIcon(iconIdx, btState - 1);
9883
            else
9884
                bt->revokeIcon(btState - 1);
14 andreas 9885
        }
9886
    }
9887
}
9888
 
108 andreas 9889
void TPageManager::getICO(int port, vector<int>& channels, vector<string>& pars)
9890
{
9891
    DECL_TRACER("TPageManager::getICO(int port, vector<int>& channels, vector<string>& pars)");
9892
 
9893
    if (pars.size() < 1)
9894
    {
9895
        MSG_ERROR("Expecting at least 1 parameter but got " << pars.size() << "! Ignoring command.");
9896
        return;
9897
    }
9898
 
9899
    TError::clear();
9900
    int btState = atoi(pars[0].c_str());
9901
 
193 andreas 9902
    vector<TMap::MAP_T> map = findButtons(port, channels);
108 andreas 9903
 
9904
    if (TError::isError() || map.empty())
9905
        return;
9906
 
9907
    vector<Button::TButton *> buttons = collectButtons(map);
9908
 
9909
    if (buttons.size() > 0)
9910
    {
110 andreas 9911
        Button::TButton *bt = buttons[0];
108 andreas 9912
 
110 andreas 9913
        if (btState == 0)       // All instances?
108 andreas 9914
        {
110 andreas 9915
            int bst = bt->getNumberInstances();
108 andreas 9916
 
110 andreas 9917
            for (int i = 0; i < bst; i++)
9918
                sendCustomEvent(i + 1, bt->getIconIndex(i), 0, "", 1003, bt->getChannelPort(), bt->getChannelNumber());
108 andreas 9919
        }
110 andreas 9920
        else
9921
            sendCustomEvent(btState, bt->getIconIndex(btState - 1), 0, "", 1003, bt->getChannelPort(), bt->getChannelNumber());
108 andreas 9922
    }
9923
}
9924
 
14 andreas 9925
/**
108 andreas 9926
 * Set bitmap/picture alignment using a numeric keypad layout for those buttons
9927
 * with a defined address range. The alignment of 0 is followed by
9928
 * ',<left>,<top>'. The left and top coordinates are relative to the upper left
9929
 * corner of the button.
9930
 */
9931
void TPageManager::doJSB(int port, vector<int>& channels, vector<string>& pars)
9932
{
9933
    DECL_TRACER("TPageManager::doJSB(int port, vector<int>& channels, vector<string>& pars)");
9934
 
9935
    if (pars.size() < 2)
9936
    {
9937
        MSG_ERROR("Expecting at least 2 parameters but got less! Ignoring command.");
9938
        return;
9939
    }
9940
 
9941
    TError::clear();
9942
    int btState = atoi(pars[0].c_str());
9943
    int align = atoi(pars[1].c_str());
9944
    int x = 0, y = 0;
9945
 
9946
    if (!align && pars.size() >= 3)
9947
    {
9948
        x = atoi(pars[2].c_str());
9949
 
9950
        if (pars.size() >= 4)
9951
            y = atoi(pars[3].c_str());
9952
    }
9953
 
193 andreas 9954
    vector<TMap::MAP_T> map = findButtons(port, channels);
108 andreas 9955
 
9956
    if (TError::isError() || map.empty())
9957
        return;
9958
 
9959
    vector<Button::TButton *> buttons = collectButtons(map);
9960
 
9961
    if (buttons.size() > 0)
9962
    {
9963
        vector<Button::TButton *>::iterator mapIter;
9964
 
9965
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
9966
        {
9967
            Button::TButton *bt = *mapIter;
9968
 
9969
            if (btState == 0)
9970
                bt->setBitmapJustification(align, x, y, -1);
9971
            else
9972
                bt->setBitmapJustification(align, x, y, btState-1);
9973
        }
9974
    }
9975
}
9976
 
9977
void TPageManager::getJSB(int port, vector<int>& channels, vector<string>& pars)
9978
{
9979
    DECL_TRACER("TPageManager::getJSB(int port, vector<int>& channels, vector<string>& pars)");
9980
 
9981
    if (pars.size() < 1)
9982
    {
9983
        MSG_ERROR("Expecting at least 1 parameter but got " << pars.size() << "! Ignoring command.");
9984
        return;
9985
    }
9986
 
9987
    TError::clear();
9988
    int btState = atoi(pars[0].c_str());
9989
    int j, x, y;
9990
 
193 andreas 9991
    vector<TMap::MAP_T> map = findButtons(port, channels);
108 andreas 9992
 
9993
    if (TError::isError() || map.empty())
9994
        return;
9995
 
9996
    vector<Button::TButton *> buttons = collectButtons(map);
9997
 
9998
    if (buttons.size() > 0)
9999
    {
110 andreas 10000
        Button::TButton *bt = buttons[0];
108 andreas 10001
 
110 andreas 10002
        if (btState == 0)       // All instances?
108 andreas 10003
        {
110 andreas 10004
            int bst = bt->getNumberInstances();
108 andreas 10005
 
110 andreas 10006
            for (int i = 0; i < bst; i++)
108 andreas 10007
            {
110 andreas 10008
                j = bt->getBitmapJustification(&x, &y, i);
10009
                sendCustomEvent(i + 1, j, 0, "", 1005, bt->getChannelPort(), bt->getChannelNumber());
108 andreas 10010
            }
10011
        }
110 andreas 10012
        else
10013
        {
10014
            j = bt->getBitmapJustification(&x, &y, btState-1);
10015
            sendCustomEvent(btState, j, 0, "", 1005, bt->getChannelPort(), bt->getChannelNumber());
10016
        }
108 andreas 10017
    }
10018
}
10019
 
10020
/**
10021
 * Set icon alignment using a numeric keypad layout for those buttons with a
10022
 * defined address range. The alignment of 0 is followed by ',<left>,<top>'.
10023
 * The left and top coordinates are relative to the upper left corner of the
10024
 * button.
10025
 */
10026
void TPageManager::doJSI(int port, vector<int>& channels, vector<string>& pars)
10027
{
10028
    DECL_TRACER("TPageManager::doJSB(int port, vector<int>& channels, vector<string>& pars)");
10029
 
10030
    if (pars.size() < 2)
10031
    {
10032
        MSG_ERROR("Expecting at least 2 parameters but got less! Ignoring command.");
10033
        return;
10034
    }
10035
 
10036
    TError::clear();
10037
    int btState = atoi(pars[0].c_str());
10038
    int align = atoi(pars[1].c_str());
10039
    int x = 0, y = 0;
10040
 
10041
    if (!align && pars.size() >= 3)
10042
    {
10043
        x = atoi(pars[2].c_str());
10044
 
10045
        if (pars.size() >= 4)
10046
            y = atoi(pars[3].c_str());
10047
    }
10048
 
193 andreas 10049
    vector<TMap::MAP_T> map = findButtons(port, channels);
108 andreas 10050
 
10051
    if (TError::isError() || map.empty())
10052
        return;
10053
 
10054
    vector<Button::TButton *> buttons = collectButtons(map);
10055
 
10056
    if (buttons.size() > 0)
10057
    {
10058
        vector<Button::TButton *>::iterator mapIter;
10059
 
10060
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
10061
        {
10062
            Button::TButton *bt = *mapIter;
10063
 
10064
            if (btState == 0)
10065
                bt->setIconJustification(align, x, y, -1);
10066
            else
10067
                bt->setIconJustification(align, x, y, btState-1);
10068
        }
10069
    }
10070
}
10071
 
10072
void TPageManager::getJSI(int port, vector<int>& channels, vector<string>& pars)
10073
{
10074
    DECL_TRACER("TPageManager::getJSB(int port, vector<int>& channels, vector<string>& pars)");
10075
 
10076
    if (pars.size() < 1)
10077
    {
10078
        MSG_ERROR("Expecting at least 1 parameter but got " << pars.size() << "! Ignoring command.");
10079
        return;
10080
    }
10081
 
10082
    TError::clear();
10083
    int btState = atoi(pars[0].c_str());
10084
    int j, x, y;
10085
 
193 andreas 10086
    vector<TMap::MAP_T> map = findButtons(port, channels);
108 andreas 10087
 
10088
    if (TError::isError() || map.empty())
10089
        return;
10090
 
10091
    vector<Button::TButton *> buttons = collectButtons(map);
10092
 
10093
    if (buttons.size() > 0)
10094
    {
110 andreas 10095
        Button::TButton *bt = buttons[0];
108 andreas 10096
 
110 andreas 10097
        if (btState == 0)       // All instances?
108 andreas 10098
        {
110 andreas 10099
            int bst = bt->getNumberInstances();
108 andreas 10100
 
110 andreas 10101
            for (int i = 0; i < bst; i++)
108 andreas 10102
            {
110 andreas 10103
                j = bt->getIconJustification(&x, &y, i);
10104
                sendCustomEvent(i + 1, j, 0, "", 1006, bt->getChannelPort(), bt->getChannelNumber());
108 andreas 10105
            }
10106
        }
110 andreas 10107
        else
10108
        {
10109
            j = bt->getIconJustification(&x, &y, btState-1);
10110
            sendCustomEvent(btState, j, 0, "", 1006, bt->getChannelPort(), bt->getChannelNumber());
10111
        }
108 andreas 10112
    }
10113
}
10114
 
10115
void TPageManager::doJST(int port, vector<int>& channels, vector<string>& pars)
10116
{
10117
    DECL_TRACER("TPageManager::doJSB(int port, vector<int>& channels, vector<string>& pars)");
10118
 
10119
    if (pars.size() < 2)
10120
    {
10121
        MSG_ERROR("Expecting at least 2 parameters but got less! Ignoring command.");
10122
        return;
10123
    }
10124
 
10125
    TError::clear();
10126
    int btState = atoi(pars[0].c_str());
10127
    int align = atoi(pars[1].c_str());
10128
    int x = 0, y = 0;
10129
 
10130
    if (!align && pars.size() >= 3)
10131
    {
10132
        x = atoi(pars[2].c_str());
10133
 
10134
        if (pars.size() >= 4)
10135
            y = atoi(pars[3].c_str());
10136
    }
10137
 
193 andreas 10138
    vector<TMap::MAP_T> map = findButtons(port, channels);
108 andreas 10139
 
10140
    if (TError::isError() || map.empty())
10141
        return;
10142
 
10143
    vector<Button::TButton *> buttons = collectButtons(map);
10144
 
10145
    if (buttons.size() > 0)
10146
    {
10147
        vector<Button::TButton *>::iterator mapIter;
10148
 
10149
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
10150
        {
10151
            Button::TButton *bt = *mapIter;
10152
 
10153
            if (btState == 0)
10154
                bt->setTextJustification(align, x, y, -1);
10155
            else
10156
                bt->setTextJustification(align, x, y, btState-1);
10157
        }
10158
    }
10159
}
10160
 
10161
void TPageManager::getJST(int port, vector<int>& channels, vector<string>& pars)
10162
{
10163
    DECL_TRACER("TPageManager::getJSB(int port, vector<int>& channels, vector<string>& pars)");
10164
 
10165
    if (pars.size() < 1)
10166
    {
10167
        MSG_ERROR("Expecting at least 1 parameter but got " << pars.size() << "! Ignoring command.");
10168
        return;
10169
    }
10170
 
10171
    TError::clear();
10172
    int btState = atoi(pars[0].c_str());
10173
    int j, x, y;
10174
 
193 andreas 10175
    vector<TMap::MAP_T> map = findButtons(port, channels);
108 andreas 10176
 
10177
    if (TError::isError() || map.empty())
10178
        return;
10179
 
10180
    vector<Button::TButton *> buttons = collectButtons(map);
10181
 
10182
    if (buttons.size() > 0)
10183
    {
110 andreas 10184
        Button::TButton *bt = buttons[0];
108 andreas 10185
 
110 andreas 10186
        if (btState == 0)       // All instances?
108 andreas 10187
        {
110 andreas 10188
            int bst = bt->getNumberInstances();
108 andreas 10189
 
110 andreas 10190
            for (int i = 0; i < bst; i++)
108 andreas 10191
            {
110 andreas 10192
                j = bt->getTextJustification(&x, &y, i);
10193
                sendCustomEvent(i + 1, j, 0, "", 1004, bt->getChannelPort(), bt->getChannelNumber());
108 andreas 10194
            }
10195
        }
110 andreas 10196
        else
10197
        {
10198
            j = bt->getTextJustification(&x, &y, btState-1);
10199
            sendCustomEvent(btState, j, 0, "", 1004, bt->getChannelPort(), bt->getChannelNumber());
10200
        }
108 andreas 10201
    }
10202
}
10203
 
10204
/**
395 andreas 10205
 * @brief TPageManager::getMSP
10206
 * Sets the speed of a marquee line. Allowed range is from 1 to 10, where 10 is
10207
 * the fastest speed.
10208
 *
10209
 * @param port      The port number
10210
 * @param channels  The channels
10211
 * @param pars      Parameters
10212
 */
10213
void TPageManager::doMSP(int port, vector<int>& channels, vector<string>& pars)
10214
{
10215
    DECL_TRACER("TPageManager::getMSP(int port, vector<int>& channels, vector<string>& pars)");
10216
 
10217
    if (pars.size() < 2)
10218
    {
10219
        MSG_ERROR("Expecting at least 2 parameter but got less! Command ignored.");
10220
        return;
10221
    }
10222
 
10223
    TError::clear();
10224
    int btState = atoi(pars[0].c_str()) - 1;
10225
    int speed = atoi(pars[1].c_str());
10226
 
10227
    if (speed < 1 || speed > 10)
10228
    {
10229
        MSG_ERROR("Speed for marquee line is out of range!");
10230
        return;
10231
    }
10232
 
10233
    vector<TMap::MAP_T> map = findButtons(port, channels);
10234
 
10235
    if (TError::isError() || map.empty())
10236
        return;
10237
 
10238
    vector<Button::TButton *> buttons = collectButtons(map);
10239
 
10240
    if (buttons.size() > 0)
10241
    {
10242
        vector<Button::TButton *>::iterator iter;
10243
 
10244
        for (iter = buttons.begin(); iter != buttons.end(); ++iter)
10245
        {
10246
            Button::TButton *bt = buttons[0];
10247
            bt->setMarqueeSpeed(speed, btState);
10248
        }
10249
    }
10250
}
10251
 
10252
/**
16 andreas 10253
 * Show or hide a button with a set variable text range.
10254
 */
10255
void TPageManager::doSHO(int port, vector<int>& channels, vector<string>& pars)
10256
{
10257
    DECL_TRACER("TPageManager::doSHO(int port, vector<int>& channels, vector<string>& pars)");
10258
 
10259
    if (pars.empty())
10260
    {
10261
        MSG_ERROR("Expecting 1 parameter but got none! Ignoring command.");
10262
        return;
10263
    }
10264
 
10265
    TError::clear();
10266
    int cvalue = atoi(pars[0].c_str());
10267
 
193 andreas 10268
    vector<TMap::MAP_T> map = findButtons(port, channels);
16 andreas 10269
 
10270
    if (TError::isError() || map.empty())
10271
        return;
10272
 
10273
    vector<Button::TButton *> buttons = collectButtons(map);
10274
 
83 andreas 10275
    if (buttons.size() > 0)
16 andreas 10276
    {
83 andreas 10277
        vector<Button::TButton *>::iterator mapIter;
10278
 
10279
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
10280
        {
10281
            Button::TButton *bt = *mapIter;
318 andreas 10282
 
100 andreas 10283
            int pgID = (bt->getParent() >> 16) & 0x0000ffff;
10284
            bool pVisible = false;
10285
 
10286
            if (pgID < 500)
10287
            {
10288
                TPage *pg = getPage(pgID);
10289
 
10290
                if (pg && pg->isVisilble())
10291
                    pVisible = true;
10292
            }
10293
            else
10294
            {
10295
                TSubPage *pg = getSubPage(pgID);
10296
 
10297
                if (pg && pg->isVisible())
10298
                    pVisible = true;
10299
            }
10300
 
151 andreas 10301
            bool oldV = bt->isVisible();
10302
            bool visible = cvalue ? true : false;
10303
            MSG_DEBUG("Button " << bt->getButtonIndex() << ", \"" << bt->getButtonName() << "\" set " << (visible ? "VISIBLE" : "HIDDEN") << " (Previous: " << (oldV ? "VISIBLE" : "HIDDEN") << ")");
98 andreas 10304
 
151 andreas 10305
            if (visible != oldV)
100 andreas 10306
            {
151 andreas 10307
                bt->setVisible(visible);
100 andreas 10308
 
151 andreas 10309
                if (pVisible)
10310
                {
10311
                    setButtonCallbacks(bt);
10312
 
10313
                    if (_setVisible)
10314
                        _setVisible(bt->getHandle(), visible);
10315
                    else
10316
                        bt->refresh();
10317
                }
100 andreas 10318
            }
83 andreas 10319
        }
16 andreas 10320
    }
10321
}
10322
 
108 andreas 10323
void TPageManager::doTEC(int port, vector<int>& channels, vector<string>& pars)
10324
{
10325
    DECL_TRACER("TPageManager::doTEC(int port, vector<int>& channels, vector<string>& pars)");
10326
 
10327
    if (pars.size() < 2)
10328
    {
10329
        MSG_ERROR("Expecting at least 2 parameters but got less! Ignoring command.");
10330
        return;
10331
    }
10332
 
10333
    TError::clear();
10334
    int btState = atoi(pars[0].c_str());
10335
    string color = pars[1];
10336
 
193 andreas 10337
    vector<TMap::MAP_T> map = findButtons(port, channels);
108 andreas 10338
 
10339
    if (TError::isError() || map.empty())
10340
        return;
10341
 
10342
    vector<Button::TButton *> buttons = collectButtons(map);
10343
 
10344
    if (buttons.size() > 0)
10345
    {
10346
        vector<Button::TButton *>::iterator mapIter;
10347
 
10348
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
10349
        {
10350
            Button::TButton *bt = *mapIter;
10351
 
10352
            if (btState == 0)
10353
                bt->setTextEffectColor(color);
10354
            else
10355
                bt->setTextEffectColor(color, btState-1);
10356
        }
10357
    }
10358
}
10359
 
10360
void TPageManager::getTEC(int port, vector<int>& channels, vector<string>& pars)
10361
{
10362
    DECL_TRACER("TPageManager::getTEC(int port, vector<int>& channels, vector<string>& pars)");
10363
 
10364
    if (pars.size() < 1)
10365
    {
10366
        MSG_ERROR("Expecting at least 1 parameter but got " << pars.size() << "! Ignoring command.");
10367
        return;
10368
    }
10369
 
10370
    TError::clear();
10371
    int btState = atoi(pars[0].c_str());
10372
 
193 andreas 10373
    vector<TMap::MAP_T> map = findButtons(port, channels);
108 andreas 10374
 
10375
    if (TError::isError() || map.empty())
10376
        return;
10377
 
10378
    vector<Button::TButton *> buttons = collectButtons(map);
10379
 
10380
    if (buttons.size() > 0)
10381
    {
110 andreas 10382
        Button::TButton *bt = buttons[0];
10383
 
10384
        if (btState == 0)       // All instances?
10385
        {
10386
            int bst = bt->getNumberInstances();
10387
 
10388
            for (int i = 0; i < bst; i++)
10389
            {
10390
                string c = bt->getTextEffectColor(i);
300 andreas 10391
                sendCustomEvent(i + 1, (int)c.length(), 0, c, 1009, bt->getChannelPort(), bt->getChannelNumber());
110 andreas 10392
            }
10393
        }
10394
        else
10395
        {
10396
            string c = bt->getTextEffectColor(btState-1);
300 andreas 10397
            sendCustomEvent(btState, (int)c.length(), 0, c, 1009, bt->getChannelPort(), bt->getChannelNumber());
110 andreas 10398
        }
10399
    }
10400
}
10401
 
10402
void TPageManager::doTEF(int port, vector<int>& channels, vector<string>& pars)
10403
{
10404
    DECL_TRACER("TPageManager::doTEF(int port, vector<int>& channels, vector<string>& pars)");
10405
 
10406
    if (pars.size() < 2)
10407
    {
10408
        MSG_ERROR("Expecting at least 2 parameters but got less! Ignoring command.");
10409
        return;
10410
    }
10411
 
10412
    TError::clear();
10413
    int btState = atoi(pars[0].c_str());
10414
    string tef = pars[1];
10415
 
193 andreas 10416
    vector<TMap::MAP_T> map = findButtons(port, channels);
110 andreas 10417
 
10418
    if (TError::isError() || map.empty())
10419
        return;
10420
 
10421
    vector<Button::TButton *> buttons = collectButtons(map);
10422
 
10423
    if (buttons.size() > 0)
10424
    {
108 andreas 10425
        vector<Button::TButton *>::iterator mapIter;
10426
 
10427
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
10428
        {
10429
            Button::TButton *bt = *mapIter;
10430
 
110 andreas 10431
            if (btState == 0)
10432
                bt->setTextEffectName(tef);
10433
            else
10434
                bt->setTextEffectName(tef, btState-1);
10435
        }
10436
    }
10437
}
108 andreas 10438
 
110 andreas 10439
void TPageManager::getTEF(int port, vector<int>& channels, vector<string>& pars)
10440
{
10441
    DECL_TRACER("TPageManager::getTEF(int port, vector<int>& channels, vector<string>& pars)");
108 andreas 10442
 
110 andreas 10443
    if (pars.size() < 1)
10444
    {
10445
        MSG_ERROR("Expecting at least 1 parameter but got " << pars.size() << "! Ignoring command.");
10446
        return;
10447
    }
108 andreas 10448
 
110 andreas 10449
    TError::clear();
10450
    int btState = atoi(pars[0].c_str());
10451
 
193 andreas 10452
    vector<TMap::MAP_T> map = findButtons(port, channels);
110 andreas 10453
 
10454
    if (TError::isError() || map.empty())
10455
        return;
10456
 
10457
    vector<Button::TButton *> buttons = collectButtons(map);
10458
 
10459
    if (buttons.size() > 0)
10460
    {
10461
        Button::TButton *bt = buttons[0];
10462
 
10463
        if (btState == 0)       // All instances?
10464
        {
10465
            int bst = bt->getNumberInstances();
10466
 
10467
            for (int i = 0; i < bst; i++)
108 andreas 10468
            {
110 andreas 10469
                string c = bt->getTextEffectName(i);
300 andreas 10470
                sendCustomEvent(i + 1, (int)c.length(), 0, c, 1008, bt->getChannelPort(), bt->getChannelNumber());
108 andreas 10471
            }
10472
        }
110 andreas 10473
        else
10474
        {
10475
            string c = bt->getTextEffectName(btState-1);
300 andreas 10476
            sendCustomEvent(btState, (int)c.length(), 0, c, 1008, bt->getChannelPort(), bt->getChannelNumber());
110 andreas 10477
        }
108 andreas 10478
    }
10479
}
10480
 
16 andreas 10481
/**
14 andreas 10482
 * Assign a text string to those buttons with a defined address range.
10483
 * Sets Non-Unicode text.
10484
 */
10485
void TPageManager::doTXT(int port, vector<int>& channels, vector<string>& pars)
10486
{
10487
    DECL_TRACER("TPageManager::doTXT(int port, vector<int>& channels, vector<string>& pars)");
10488
 
10489
    if (pars.size() < 1)
10490
    {
10491
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
331 andreas 10492
#if TESTMODE == 1
334 andreas 10493
        setAllDone();
331 andreas 10494
#endif
14 andreas 10495
        return;
10496
    }
10497
 
16 andreas 10498
    TError::clear();
333 andreas 10499
    int btState = atoi(pars[0].c_str()) - 1;
14 andreas 10500
    string text;
10501
 
333 andreas 10502
    // Every comma (,) in the text produces a new parameter. Therefor we must
10503
    // concatenate this parameters together and insert the comma.
14 andreas 10504
    if (pars.size() > 1)
150 andreas 10505
    {
10506
        for (size_t i = 1; i < pars.size(); ++i)
10507
        {
10508
            if (i > 1)
10509
                text += ",";
14 andreas 10510
 
150 andreas 10511
            text += pars[i];
10512
        }
10513
    }
10514
 
193 andreas 10515
    vector<TMap::MAP_T> map = findButtons(port, channels);
14 andreas 10516
 
10517
    if (TError::isError() || map.empty())
331 andreas 10518
    {
10519
#if TESTMODE == 1
334 andreas 10520
        setAllDone();
331 andreas 10521
#endif
14 andreas 10522
        return;
331 andreas 10523
    }
14 andreas 10524
 
10525
    vector<Button::TButton *> buttons = collectButtons(map);
10526
 
83 andreas 10527
    if (buttons.size() > 0)
14 andreas 10528
    {
83 andreas 10529
        vector<Button::TButton *>::iterator mapIter;
14 andreas 10530
 
333 andreas 10531
        for (mapIter = buttons.begin(); mapIter != buttons.end(); ++mapIter)
14 andreas 10532
        {
83 andreas 10533
            Button::TButton *bt = *mapIter;
14 andreas 10534
 
252 andreas 10535
            if (!bt)
333 andreas 10536
                continue;
252 andreas 10537
 
333 andreas 10538
            bt->setText(text, btState);
331 andreas 10539
#if TESTMODE == 1
333 andreas 10540
            if (_gTestMode)
10541
                _gTestMode->setResult(bt->getText(btState < 0 ? 0 : btState));
331 andreas 10542
 
333 andreas 10543
            __success = true;
331 andreas 10544
#endif
14 andreas 10545
        }
10546
    }
331 andreas 10547
#if TESTMODE == 1
334 andreas 10548
    setDone();
331 andreas 10549
#endif
14 andreas 10550
}
21 andreas 10551
 
110 andreas 10552
void TPageManager::getTXT(int port, vector<int>& channels, vector<string>& pars)
10553
{
10554
    DECL_TRACER("TPageManager::getTXT(int port, vector<int>& channels, vector<string>& pars)");
10555
 
10556
    if (pars.size() < 1)
10557
    {
10558
        MSG_ERROR("Expecting at least 1 parameter but got " << pars.size() << "! Ignoring command.");
10559
        return;
10560
    }
10561
 
10562
    TError::clear();
10563
    int btState = atoi(pars[0].c_str());
10564
 
193 andreas 10565
    vector<TMap::MAP_T> map = findButtons(port, channels);
110 andreas 10566
 
10567
    if (TError::isError() || map.empty())
10568
        return;
10569
 
10570
    vector<Button::TButton *> buttons = collectButtons(map);
10571
 
10572
    if (buttons.size() > 0)
10573
    {
10574
        Button::TButton *bt = buttons[0];
10575
 
10576
        if (btState == 0)       // All instances?
10577
        {
10578
            int bst = bt->getNumberInstances();
10579
 
10580
            for (int i = 0; i < bst; i++)
10581
            {
10582
                string c = bt->getText(i);
300 andreas 10583
                sendCustomEvent(i + 1, (int)c.length(), 0, c, 1001, bt->getChannelPort(), bt->getChannelNumber());
333 andreas 10584
#if TESTMODE == 1
10585
                if (_gTestMode)
10586
                    _gTestMode->setResult(c);
10587
#endif
110 andreas 10588
            }
10589
        }
10590
        else
10591
        {
10592
            string c = bt->getText(btState-1);
300 andreas 10593
            sendCustomEvent(btState, (int)c.length(), 0, c, 1001, bt->getChannelPort(), bt->getChannelNumber());
333 andreas 10594
#if TESTMODE == 1
10595
            if (_gTestMode)
10596
                _gTestMode->setResult(c);
10597
#endif
110 andreas 10598
        }
10599
    }
334 andreas 10600
#if TESTMODE == 1
10601
    setAllDone();
10602
#endif
110 andreas 10603
}
10604
 
97 andreas 10605
/*
104 andreas 10606
 * Set button state legacy unicode text command.
10607
 *
10608
 * Set Unicode text in the legacy G4 format. For the ^UNI command, the Unicode
10609
 * text is sent as ASCII-HEX nibbles.
10610
 */
10611
void TPageManager::doUNI(int port, vector<int>& channels, vector<string>& pars)
10612
{
10613
    DECL_TRACER("TPageManager::doUNI(int port, vector<int>& channels, vector<string>& pars)");
10614
 
10615
    if (pars.size() < 1)
10616
    {
10617
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
331 andreas 10618
#if TESTMODE == 1
334 andreas 10619
        setAllDone();
331 andreas 10620
#endif
104 andreas 10621
        return;
10622
    }
10623
 
10624
    TError::clear();
333 andreas 10625
    int btState = atoi(pars[0].c_str()) - 1;
104 andreas 10626
    string text;
10627
 
361 andreas 10628
    // Unicode is the stadard character set used by Windows internally. It
10629
    // consists of 16 bit unsiged numbers. This can't be transported into a
10630
    // standard character string because a NULL byte means end of string.
10631
    // Therefor we must convert it to UFT-8.
104 andreas 10632
    if (pars.size() > 1)
10633
    {
10634
        string byte;
361 andreas 10635
        std::wstring uni;
104 andreas 10636
        size_t pos = 0;
10637
 
10638
        while (pos < pars[1].length())
10639
        {
361 andreas 10640
            byte = pars[1].substr(pos, 4);
10641
            wchar_t ch = (char)strtol(byte.c_str(), NULL, 16);
10642
            uni += ch;
10643
            pos += 4;
104 andreas 10644
        }
361 andreas 10645
 
10646
        text = UnicodeToUTF8(uni);
104 andreas 10647
    }
10648
 
193 andreas 10649
    vector<TMap::MAP_T> map = findButtons(port, channels);
104 andreas 10650
 
10651
    if (TError::isError() || map.empty())
331 andreas 10652
    {
10653
#if TESTMODE == 1
334 andreas 10654
        setAllDone();
331 andreas 10655
#endif
104 andreas 10656
        return;
331 andreas 10657
    }
104 andreas 10658
 
10659
    vector<Button::TButton *> buttons = collectButtons(map);
10660
 
10661
    if (buttons.size() > 0)
10662
    {
10663
        vector<Button::TButton *>::iterator mapIter;
10664
 
10665
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
10666
        {
10667
            Button::TButton *bt = *mapIter;
10668
 
331 andreas 10669
#if TESTMODE == 1
333 andreas 10670
            bool res = bt->setText(text, btState);
104 andreas 10671
 
333 andreas 10672
            if (_gTestMode)
10673
                _gTestMode->setResult(bt->getText(btState < 0 ? 0 : btState));
331 andreas 10674
 
333 andreas 10675
            __success = res;
10676
#else
10677
            bt->setText(text, btState);
331 andreas 10678
#endif
104 andreas 10679
        }
10680
    }
334 andreas 10681
#if TESTMODE == 1
10682
    setDone();
10683
#endif
104 andreas 10684
}
10685
 
10686
void TPageManager::doUTF(int port, vector<int>& channels, vector<string>& pars)
10687
{
10688
    DECL_TRACER("TPageManager::doTXT(int port, vector<int>& channels, vector<string>& pars)");
10689
 
10690
    if (pars.size() < 1)
10691
    {
10692
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
10693
        return;
10694
    }
10695
 
10696
    TError::clear();
10697
    int btState = atoi(pars[0].c_str());
10698
    string text;
10699
 
10700
    if (pars.size() > 1)
150 andreas 10701
    {
10702
        for (size_t i = 1; i < pars.size(); ++i)
10703
        {
10704
            if (i > 1)
10705
                text += ",";
104 andreas 10706
 
150 andreas 10707
            text += pars[i];
10708
        }
10709
    }
10710
 
193 andreas 10711
    vector<TMap::MAP_T> map = findButtons(port, channels);
104 andreas 10712
 
10713
    if (TError::isError() || map.empty())
10714
        return;
10715
 
10716
    vector<Button::TButton *> buttons = collectButtons(map);
10717
 
10718
    if (buttons.size() > 0)
10719
    {
10720
        vector<Button::TButton *>::iterator mapIter;
10721
 
10722
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
10723
        {
10724
            Button::TButton *bt = *mapIter;
10725
 
10726
            if (btState == 0)       // All instances?
10727
            {
10728
                int bst = bt->getNumberInstances();
10729
 
10730
                for (int i = 0; i < bst; i++)
10731
                    bt->setText(text, i);
10732
            }
10733
            else
10734
                bt->setText(text, btState - 1);
10735
        }
10736
    }
10737
}
111 andreas 10738
 
361 andreas 10739
/**
10740
 * Simulates a touch/release/pulse at the given coordinate. If the push event
10741
 * is less then 0 or grater than 2 the command is ignored. It is also ignored
10742
 * if the x and y coordinate is out of range. The range must be between 0 and
10743
 * the maximum with and height.
10744
 */
148 andreas 10745
void TPageManager::doVTP (int, vector<int>&, vector<string>& pars)
10746
{
10747
    DECL_TRACER("TPageManager::doVTP (int, vector<int>&, vector<string>& pars)");
10748
 
10749
    if (pars.size() < 3)
10750
    {
10751
        MSG_ERROR("Expected 3 parameters but got only " << pars.size() << " parameters!");
10752
        return;
10753
    }
10754
 
10755
    int pushType = atoi(pars[0].c_str());
10756
    int x = atoi(pars[1].c_str());
10757
    int y = atoi(pars[2].c_str());
10758
 
10759
    if (pushType < 0 || pushType > 2)
10760
    {
10761
        MSG_ERROR("Invalid push type " << pushType << ". Ignoring command!");
10762
        return;
10763
    }
10764
 
217 andreas 10765
    if (x < 0 || x > mTSettings->getWidth() || y < 0 || y > mTSettings->getHeight())
148 andreas 10766
    {
10767
        MSG_ERROR("Illegal coordinates " << x << " x " << y << ". Ignoring command!");
10768
        return;
10769
    }
10770
 
10771
    if (pushType == 0 || pushType == 2)
10772
        mouseEvent(x, y, true);
10773
 
10774
    if (pushType == 1 || pushType == 2)
10775
        mouseEvent(x, y, false);
10776
}
10777
 
400 andreas 10778
 
111 andreas 10779
/**
10780
 * Set the keyboard passthru.
10781
 */
10782
void TPageManager::doKPS(int, vector<int>&, vector<string>& pars)
10783
{
10784
    DECL_TRACER("TPageManager::doKPS(int, vector<int>&, vector<string>& pars)");
10785
 
10786
    if (pars.size() < 1)
10787
    {
10788
        MSG_ERROR("Got no parameter. Ignoring command!");
10789
        return;
10790
    }
10791
 
10792
    int state = atoi(pars[0].c_str());
10793
 
10794
    if (state == 0)
10795
        mPassThrough = false;
10796
    else if (state == 5)
10797
        mPassThrough = true;
10798
}
10799
 
400 andreas 10800
void TPageManager::doVKS(int, vector<int>&, vector<string>& pars)
111 andreas 10801
{
400 andreas 10802
    DECL_TRACER("TPageManager::doVKS(int, vector<int>&, vector<string>& pars)");
111 andreas 10803
 
10804
    if (pars.size() < 1)
10805
    {
10806
        MSG_ERROR("Got no parameter. Ignoring command!");
10807
        return;
10808
    }
10809
 
10810
    if (_sendVirtualKeys)
10811
        _sendVirtualKeys(pars[0]);
10812
}
10813
 
400 andreas 10814
void TPageManager::doLPB(int port, vector<int>& channels, vector<string>& pars)
10815
{
10816
    DECL_TRACER("TPageManager::doLPB(int port, vector<int>& channels, vector<string>& pars)");
10817
 
10818
    if (pars.size() < 1)
10819
        return;
10820
 
10821
    TError::clear();
10822
    string passwd = pars[0];
10823
    vector<TMap::MAP_T> map = findButtons(port, channels);
10824
 
10825
    if (TError::isError() || map.empty())
10826
        return;
10827
 
10828
    vector<Button::TButton *> buttons = collectButtons(map);
10829
 
10830
    if (buttons.size() > 0)
10831
    {
10832
        vector<Button::TButton *>::iterator mapIter;
10833
 
10834
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
10835
        {
10836
            Button::TButton *bt = *mapIter;
10837
            bt->setUserName(passwd);
10838
        }
10839
    }
10840
}
10841
 
401 andreas 10842
void TPageManager::doLPC(int, vector<int>&, vector<string>&)
400 andreas 10843
{
401 andreas 10844
    DECL_TRACER("TPageManager::doLPC(int, vector<int>&, vector<string>&)");
400 andreas 10845
 
10846
    TConfig::clearUserPasswords();
10847
}
10848
 
10849
void TPageManager::doLPR(int, vector<int>&, vector<string>& pars)
10850
{
10851
    DECL_TRACER("TPageManager::doLPR(int, vector<int>&, vector<string>& pars)");
10852
 
10853
    if (pars.size() < 1)
10854
        return;
10855
 
10856
    string user = pars[0];
10857
    TConfig::clearUserPassword(user);
10858
}
10859
 
10860
void TPageManager::doLPS(int, vector<int>&, vector<string>& pars)
10861
{
10862
    DECL_TRACER("TPageManager::doLPS(int, vector<int>&, vector<string>& pars)");
10863
 
10864
    if (pars.size() < 2)
10865
        return;
10866
 
10867
    string user = pars[0];
10868
    string password;
10869
 
10870
    // In case the password contains one or more comma (,), the password is
10871
    // splitted. The following loop concatenates the password into one. Because
10872
    // the comma is lost, we must add it again.
10873
    for (size_t i = 0; i < pars.size(); ++i)
10874
    {
10875
        if (i > 0)
10876
            password += ",";
10877
 
10878
        password += pars[i];
10879
    }
10880
 
10881
    TConfig::setUserPassword(user, password);
10882
}
10883
 
104 andreas 10884
/*
400 andreas 10885
 * Set the page flip password. @PWD sets the level 1 password only.
10886
 */
10887
void TPageManager::doAPWD(int, vector<int>&, vector<string>& pars)
10888
{
10889
    DECL_TRACER("TPageManager::doPWD(int port, vector<int>&, vector<string>& pars)");
10890
 
10891
    if (pars.size() < 1)
10892
    {
10893
        MSG_ERROR("Got less then 1 parameter!");
10894
        return;
10895
    }
10896
 
10897
    string password;
10898
    // In case the password contains one or more comma (,), the password is
10899
    // splitted. The following loop concatenates the password into one. Because
10900
    // the comma is lost, we must add it again.
10901
    for (size_t i = 0; i < pars.size(); ++i)
10902
    {
10903
        if (i > 0)
10904
            password += ",";
10905
 
10906
        password += pars[i];
10907
    }
10908
 
10909
    TConfig::savePassword1(password);
10910
}
10911
 
10912
/*
10913
 * Set the page flip password. Password level is required and must be 1 - 4
10914
 */
10915
void TPageManager::doPWD(int, vector<int>&, vector<string>& pars)
10916
{
10917
    DECL_TRACER("TPageManager::doPWD(int, vector<int>&, vector<string>& pars)");
10918
 
10919
    if (pars.size() < 2)
10920
    {
10921
        MSG_ERROR("Got less then 2 parameters!");
10922
        return;
10923
    }
10924
 
10925
    int pwIdx = atoi(pars[0].c_str());
10926
    string password;
10927
    // In case the password contains one or more comma (,), the password is
10928
    // splitted. The following loop concatenates the password into one. Because
10929
    // the comma is lost, we must add it again.
10930
    for (size_t i = 1; i < pars.size(); ++i)
10931
    {
10932
        if (i > 1)
10933
            password += ",";
10934
 
10935
        password += pars[i];
10936
    }
10937
 
10938
    switch(pwIdx)
10939
    {
10940
        case 1: TConfig::savePassword1(password); break;
10941
        case 2: TConfig::savePassword2(password); break;
10942
        case 3: TConfig::savePassword3(password); break;
10943
        case 4: TConfig::savePassword4(password); break;
10944
    }
10945
}
10946
 
10947
/*
97 andreas 10948
 * Set the bitmap of a button to use a particular resource.
10949
 * Syntax:
10950
 *    "'^BBR-<vt addr range>,<button states range>,<resource name>'"
10951
 * Variable:
10952
 *    variable text address range = 1 - 4000.
10953
 *    button states range = 1 - 256 for multi-state buttons (0 = All states, for General buttons 1 = Off state and 2 = On state).
10954
 *    resource name = 1 - 50 ASCII characters.
10955
 * Example:
10956
 *    SEND_COMMAND Panel,"'^BBR-700,1,Sports_Image'"
10957
 *    Sets the resource name of the button to ’Sports_Image’.
10958
 */
21 andreas 10959
void TPageManager::doBBR(int port, vector<int>& channels, vector<string>& pars)
10960
{
10961
    DECL_TRACER("TPageManager::doBBR(int port, vector<int>& channels, vector<string>& pars)");
10962
 
10963
    if (pars.size() < 2)
10964
    {
10965
        MSG_ERROR("Expecting 2 parameters but got none! Ignoring command.");
10966
        return;
10967
    }
10968
 
10969
    TError::clear();
10970
    int btState = atoi(pars[0].c_str());
10971
    string resName = pars[1];
10972
 
193 andreas 10973
    vector<TMap::MAP_T> map = findButtons(port, channels);
21 andreas 10974
 
10975
    if (TError::isError() || map.empty())
10976
        return;
10977
 
10978
    vector<Button::TButton *> buttons = collectButtons(map);
10979
 
83 andreas 10980
    if (buttons.size() > 0)
21 andreas 10981
    {
83 andreas 10982
        vector<Button::TButton *>::iterator mapIter;
21 andreas 10983
 
83 andreas 10984
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
21 andreas 10985
        {
83 andreas 10986
            Button::TButton *bt = *mapIter;
252 andreas 10987
//            setButtonCallbacks(bt);
21 andreas 10988
 
83 andreas 10989
            if (btState == 0)       // All instances?
10990
            {
10991
                int bst = bt->getNumberInstances();
10992
                MSG_DEBUG("Setting BBR on all " << bst << " instances...");
10993
 
10994
                for (int i = 0; i < bst; i++)
10995
                    bt->setResourceName(resName, i);
10996
            }
10997
            else
10998
                bt->setResourceName(resName, btState - 1);
97 andreas 10999
 
11000
            if (bt->isVisible())
11001
                bt->refresh();
99 andreas 11002
            else if (_setVisible)
11003
                _setVisible(bt->getHandle(), false);
21 andreas 11004
        }
11005
    }
11006
}
11007
 
97 andreas 11008
/*
11009
 * Add new resources
11010
 * Adds any and all resource parameters by sending embedded codes and data.
11011
 * Since the embedded codes are preceded by a '%' character, any '%' character
11012
 * contained in* the URL must be escaped with a second '%' character (see
11013
 * example).
11014
 * The file name field (indicated by a %F embedded code) may contain special
11015
 * escape sequences as shown in the ^RAF, ^RMF.
11016
 * Syntax:
11017
 *    "'^RAF-<resource name>,<data>'"
11018
 * Variables:
11019
 *    resource name = 1 - 50 ASCII characters.
11020
 *    data = Refers to the embedded codes, see the ^RAF, ^RMF.
11021
 * Example:
11022
 *    SEND_COMMAND Panel,"'^RAF-New Image,%P0%HAMX.COM%ALab/Test%%5Ffile%Ftest.jpg'"
11023
 *    Adds a new resource.
11024
 *    The resource name is ’New Image’
11025
 *    %P (protocol) is an HTTP
11026
 *    %H (host name) is AMX.COM
11027
 *    %A (file path) is Lab/Test_f ile
11028
 *    %F (file name) is test.jpg.
11029
 *    Note that the %%5F in the file path is actually encoded as %5F.
11030
 */
11031
void TPageManager::doRAF(int, vector<int>&, vector<string>& pars)
11032
{
11033
    DECL_TRACER("TPageManager::doRAF(int port, vector<int>& channels, vector<string>& pars)");
11034
 
11035
    if (pars.size() < 2)
11036
    {
11037
        MSG_ERROR("Expecting 2 parameters but got none! Ignoring command.");
11038
        return;
11039
    }
11040
 
11041
    string name = pars[0];
11042
    string data = pars[1];
11043
 
11044
    vector<string> parts = StrSplit(data, "%");
11045
    RESOURCE_T res;
11046
 
11047
    if (parts.size() > 0)
11048
    {
11049
        vector<string>::iterator sIter;
11050
 
11051
        for (sIter = parts.begin(); sIter != parts.end(); sIter++)
11052
        {
11053
            const char *s = sIter->c_str();
11054
            string ss = *sIter;
11055
            MSG_DEBUG("Parsing \"" << ss << "\" with token << " << ss[0]);
11056
 
11057
            switch(*s)
11058
            {
11059
                case 'P':
11060
                    if (*(s+1) == '0')
11061
                        res.protocol = "HTTP";
11062
                    else
11063
                        res.protocol = "FTP";
11064
                    break;
11065
 
11066
                case 'U': res.user = sIter->substr(1); break;
11067
                case 'S': res.password = sIter->substr(1); break;
11068
                case 'H': res.host = sIter->substr(1); break;
11069
                case 'F': res.file = sIter->substr(1); break;
11070
                case 'A': res.path = sIter->substr(1); break;
11071
                case 'R': res.refresh = atoi(sIter->substr(1).c_str()); break;
11072
 
11073
                default:
11074
                    MSG_WARNING("Option " << sIter->at(0) << " is currently not implemented!");
11075
            }
11076
        }
11077
 
11078
        if (gPrjResources)
11079
            gPrjResources->addResource(name, res.protocol, res.host, res.path, res.file, res.user, res.password, res.refresh);
11080
    }
11081
}
11082
 
111 andreas 11083
void TPageManager::doRFR(int, vector<int>&, vector<string>& pars)
97 andreas 11084
{
11085
    DECL_TRACER("TPageManager::doRFR(int port, vector<int>& channels, vector<string>& pars)");
11086
 
11087
    if (pars.size() < 1)
11088
    {
11089
        MSG_ERROR("Expecting 1 parameter but got none! Ignoring command.");
11090
        return;
11091
    }
11092
 
11093
    string name = pars[0];
193 andreas 11094
    vector<TMap::MAP_T> map = findButtonByName(name);
97 andreas 11095
 
11096
    if (TError::isError() || map.empty())
11097
        return;
11098
 
11099
    vector<Button::TButton *> buttons = collectButtons(map);
11100
 
11101
    if (buttons.size() > 0)
11102
    {
11103
        vector<Button::TButton *>::iterator mapIter;
11104
 
11105
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
11106
        {
11107
            Button::TButton *bt = *mapIter;
11108
 
11109
            if (bt->isVisible())
11110
            {
252 andreas 11111
//                setButtonCallbacks(bt);
97 andreas 11112
                bt->refresh();
11113
            }
11114
        }
11115
    }
11116
}
11117
 
11118
/*
11119
 * Modify an existing resource
11120
 *
11121
 * Modifies any and all resource parameters by sending embedded codes and data.
11122
 * Since the embedded codes are preceded by a '%' character, any '%' character
11123
 * contained in the URL must be escaped with a second '%' character (see
11124
 * example).
11125
 * The file name field (indicated by a %F embedded code) may contain special
11126
 * escape sequences as shown in the ^RAF.
11127
 *
11128
 * Syntax:
11129
 * "'^RMF-<resource name>,<data>'"
11130
 * Variables:
11131
 *   • resource name = 1 - 50 ASCII characters
11132
 *   • data = Refers to the embedded codes, see the ^RAF, ^RMF.
11133
 * Example:
11134
 *   SEND_COMMAND Panel,"'^RMF-Sports_Image,%ALab%%5FTest/Images%Ftest.jpg'"
11135
 * Changes the resource ’Sports_Image’ file name to ’test.jpg’ and the path to
11136
 * ’Lab_Test/Images’.
11137
 * Note that the %%5F in the file path is actually encoded as %5F.
11138
 */
22 andreas 11139
void TPageManager::doRMF(int, vector<int>&, vector<string>& pars)
21 andreas 11140
{
11141
    DECL_TRACER("TPageManager::doRMF(int port, vector<int>& channels, vector<string>& pars)");
11142
 
11143
    if (pars.size() < 2)
11144
    {
11145
        MSG_ERROR("Expecting 2 parameters but got none! Ignoring command.");
11146
        return;
11147
    }
11148
 
11149
    string name = pars[0];
11150
    string data = pars[1];
11151
 
11152
    vector<string> parts = StrSplit(data, "%");
11153
    RESOURCE_T res;
11154
 
83 andreas 11155
    if (parts.size() > 0)
21 andreas 11156
    {
83 andreas 11157
        vector<string>::iterator sIter;
21 andreas 11158
 
83 andreas 11159
        for (sIter = parts.begin(); sIter != parts.end(); sIter++)
21 andreas 11160
        {
83 andreas 11161
            const char *s = sIter->c_str();
11162
            string ss = *sIter;
11163
            MSG_DEBUG("Parsing \"" << ss << "\" with token << " << ss[0]);
21 andreas 11164
 
83 andreas 11165
            switch(*s)
11166
            {
11167
                case 'P':
11168
                    if (*(s+1) == '0')
11169
                        res.protocol = "HTTP";
11170
                    else
11171
                        res.protocol = "FTP";
11172
                break;
21 andreas 11173
 
83 andreas 11174
                case 'U': res.user = sIter->substr(1); break;
11175
                case 'S': res.password = sIter->substr(1); break;
11176
                case 'H': res.host = sIter->substr(1); break;
11177
                case 'F': res.file = sIter->substr(1); break;
11178
                case 'A': res.path = sIter->substr(1); break;
11179
                case 'R': res.refresh = atoi(sIter->substr(1).c_str()); break;
11180
 
11181
                default:
11182
                    MSG_WARNING("Option " << sIter->at(0) << " is currently not implemented!");
11183
            }
21 andreas 11184
        }
83 andreas 11185
 
11186
        if (gPrjResources)
11187
            gPrjResources->setResource(name, res.protocol, res.host, res.path, res.file, res.user, res.password, res.refresh);
21 andreas 11188
    }
11189
}
62 andreas 11190
 
11191
/**
111 andreas 11192
 * Change the refresh rate for a given resource.
11193
 */
11194
void TPageManager::doRSR(int, vector<int>&, vector<string>& pars)
11195
{
11196
    DECL_TRACER("TPageManager::doRSR(int, vector<int>&, vector<string>& pars)");
11197
 
11198
    if (pars.size() < 2)
11199
    {
11200
        MSG_ERROR("Expecting 2 parameters but got none! Ignoring command.");
11201
        return;
11202
    }
11203
 
11204
    string resName = pars[0];
11205
    int resRefresh = atoi(pars[1].c_str());
11206
 
11207
    if (!gPrjResources)
11208
    {
11209
        MSG_ERROR("Missing the resource module. Ignoring command!");
11210
        return;
11211
    }
11212
 
11213
    RESOURCE_T res = gPrjResources->findResource(resName);
11214
 
11215
    if (res.name.empty() || res.refresh == resRefresh)
11216
        return;
11217
 
11218
    gPrjResources->setResource(resName, res.protocol, res.host, res.path, res.file, res.user, res.password, resRefresh);
11219
}
11220
 
11221
/**
62 andreas 11222
 * @brief TPageManager::doAKB - Pop up the keyboard icon
11223
 * Pop up the keyboard icon and initialize the text string to that specified.
11224
 * Keyboard string is set to null on power up and is stored until power is lost.
11225
 * The Prompt Text is optional.
11226
 */
11227
void TPageManager::doAKB(int, vector<int>&, vector<string> &pars)
11228
{
11229
    DECL_TRACER("TPageManager::doAKB(int, vector<int>&, vector<string> &pars)");
11230
 
11231
    if (pars.size() < 1)
11232
    {
11233
        MSG_ERROR("Expecting 2 parameters but got only " << pars.size() << "! Ignoring command.");
11234
        return;
11235
    }
11236
 
11237
    string initText = pars[0];
11238
    string promptText;
11239
 
11240
    if (pars.size() > 1)
11241
        promptText = pars[1];
11242
 
63 andreas 11243
    if (initText.empty())
11244
        initText = mAkbText;
11245
    else
11246
        mAkbText = initText;
62 andreas 11247
 
11248
    if (_callKeyboard)
63 andreas 11249
        _callKeyboard(initText, promptText, false);
62 andreas 11250
}
11251
 
63 andreas 11252
/**
11253
 * Pop up the keyboard icon and initialize the text string to that
11254
 * specified.
11255
 */
62 andreas 11256
void TPageManager::doAKEYB(int port, vector<int>& channels, vector<string>& pars)
11257
{
11258
    DECL_TRACER("TPageManager::doAKEYB(int port, vector<int>& channels, vector<string>& pars)");
11259
 
11260
    doAKB(port, channels, pars);
11261
}
11262
 
63 andreas 11263
void TPageManager::doAKEYP(int port, std::vector<int>& channels, std::vector<std::string>& pars)
11264
{
11265
    DECL_TRACER("TPageManager::doAKEYP(int port, std::vector<int>& channels, std::vector<std::string>& pars)");
11266
 
11267
    doAKP(port, channels, pars);
11268
}
11269
 
62 andreas 11270
/**
63 andreas 11271
 * Remove keyboard or keypad that was displayed using 'AKEYB', 'AKEYP', 'PKEYP',
11272
 * @AKB, @AKP, @PKP, @EKP, or @TKP commands.
11273
 */
11274
void TPageManager::doAKEYR(int, vector<int>&, vector<string>&)
11275
{
11276
    DECL_TRACER("TPageManager::doAKEYR(int, vector<int>&, vector<string>&)");
11277
 
11278
    if (_callResetKeyboard)
11279
        _callResetKeyboard();
11280
}
11281
 
11282
/**
62 andreas 11283
 * @brief TPageManager::doAKP - Pop up the keypad icon
11284
 * Pop up the keypad icon and initialize the text string to that specified.
11285
 * Keypad string is set to null on power up and is stored until power is lost.
11286
 * The Prompt Text is optional.
11287
 */
11288
void TPageManager::doAKP(int, std::vector<int>&, std::vector<std::string> &pars)
11289
{
11290
    DECL_TRACER("TPageManager::doAKP(int, vector<int>&, vector<string> &pars)");
11291
 
11292
    if (pars.size() < 1)
11293
    {
11294
        MSG_ERROR("Expecting 2 parameters but got only " << pars.size() << "! Ignoring command.");
11295
        return;
11296
    }
11297
 
11298
    string initText = pars[0];
11299
    string promptText;
11300
 
11301
    if (pars.size() > 1)
11302
        promptText = pars[1];
11303
 
63 andreas 11304
    if (initText.empty())
11305
        initText = mAkpText;
11306
    else
11307
        mAkpText = initText;
62 andreas 11308
 
11309
    if (_callKeypad)
63 andreas 11310
        _callKeypad(initText, promptText, false);
62 andreas 11311
}
11312
 
63 andreas 11313
/**
11314
 * Remove keyboard or keypad that was displayed using 'AKEYB', 'AKEYP', 'PKEYP',
11315
 * @AKB, @AKP, @PKP, @EKP, or @TKP commands.
11316
 */
11317
void TPageManager::doAKR(int port, vector<int>& channels, vector<string>& pars)
62 andreas 11318
{
63 andreas 11319
    DECL_TRACER("TPageManager::doAKR(int, vector<int>&, vector<string>&)");
62 andreas 11320
 
63 andreas 11321
    doAKEYR(port, channels, pars);
62 andreas 11322
}
11323
 
108 andreas 11324
void TPageManager::doABEEP(int, std::vector<int>&, vector<string>&)
11325
{
11326
    DECL_TRACER("TPageManager::doBEEP(int, std::vector<int>&, vector<string>&)");
11327
 
11328
    if (!_playSound)
334 andreas 11329
    {
11330
#if TESTMODE == 1
11331
        setAllDone();
11332
#endif
108 andreas 11333
        return;
334 andreas 11334
    }
108 andreas 11335
 
11336
    string snd = TConfig::getSystemPath(TConfig::SOUNDS) + "/" + TConfig::getSingleBeepSound();
11337
    TValidateFile vf;
11338
 
326 andreas 11339
    if (vf.isValidFile(snd))
108 andreas 11340
        _playSound(snd);
326 andreas 11341
#if TESTMODE == 1
11342
    else
11343
    {
11344
        MSG_PROTOCOL("Sound file invalid!");
334 andreas 11345
        setAllDone();
326 andreas 11346
    }
11347
#endif
108 andreas 11348
}
11349
 
11350
void TPageManager::doADBEEP(int, std::vector<int>&, vector<string>&)
11351
{
11352
    DECL_TRACER("TPageManager::doDBEEP(int, std::vector<int>&, vector<string>&)");
11353
 
11354
    if (!_playSound)
11355
        return;
11356
 
11357
    string snd = TConfig::getSystemPath(TConfig::SOUNDS) + "/" + TConfig::getDoubleBeepSound();
11358
    TValidateFile vf;
11359
 
326 andreas 11360
    if (vf.isValidFile(snd))
108 andreas 11361
        _playSound(snd);
326 andreas 11362
#if TESTMODE == 1
11363
    else
11364
    {
11365
        MSG_PROTOCOL("Sound file invalid!");
334 andreas 11366
        setAllDone();
326 andreas 11367
    }
11368
#endif
108 andreas 11369
}
11370
 
71 andreas 11371
void TPageManager::doBEEP(int, std::vector<int>&, vector<string>&)
11372
{
11373
    DECL_TRACER("TPageManager::doBEEP(int, std::vector<int>&, vector<string>&)");
11374
 
11375
    if (!_playSound)
326 andreas 11376
    {
11377
#if TESTMODE == 1
11378
        MSG_PROTOCOL("Method \"playSound()\" not initialized!");
334 andreas 11379
        setAllDone();
326 andreas 11380
#endif
71 andreas 11381
        return;
326 andreas 11382
    }
71 andreas 11383
 
11384
    string snd = TConfig::getSystemPath(TConfig::SOUNDS) + "/" + TConfig::getSingleBeepSound();
11385
    TValidateFile vf;
108 andreas 11386
    TSystemSound sysSound(TConfig::getSystemPath(TConfig::SOUNDS));
71 andreas 11387
 
326 andreas 11388
    if (sysSound.getSystemSoundState() && vf.isValidFile(snd))
71 andreas 11389
        _playSound(snd);
326 andreas 11390
#if TESTMODE == 1
11391
    else
11392
    {
11393
        if (!sysSound.getSystemSoundState())
11394
        {
11395
            MSG_PROTOCOL("Sound state disabled!")
11396
        }
11397
        else
11398
        {
11399
            MSG_PROTOCOL("Sound file invalid!");
11400
        }
11401
 
334 andreas 11402
        setAllDone();
326 andreas 11403
    }
11404
#endif
71 andreas 11405
}
11406
 
11407
void TPageManager::doDBEEP(int, std::vector<int>&, vector<string>&)
11408
{
11409
    DECL_TRACER("TPageManager::doDBEEP(int, std::vector<int>&, vector<string>&)");
11410
 
11411
    if (!_playSound)
11412
        return;
11413
 
11414
    string snd = TConfig::getSystemPath(TConfig::SOUNDS) + "/" + TConfig::getDoubleBeepSound();
11415
    TValidateFile vf;
108 andreas 11416
    TSystemSound sysSound(TConfig::getSystemPath(TConfig::SOUNDS));
71 andreas 11417
 
326 andreas 11418
    if (sysSound.getSystemSoundState() && vf.isValidFile(snd))
71 andreas 11419
        _playSound(snd);
326 andreas 11420
#if TESTMODE == 1
11421
    else
11422
    {
11423
        if (!sysSound.getSystemSoundState())
11424
        {
11425
            MSG_PROTOCOL("Sound state disabled!")
11426
        }
11427
        else
11428
        {
11429
            MSG_PROTOCOL("Sound file invalid!");
11430
        }
11431
 
334 andreas 11432
        setAllDone();
326 andreas 11433
    }
11434
#endif
71 andreas 11435
}
11436
 
63 andreas 11437
/**
11438
 * @brief Pop up the keypad icon and initialize the text string to that specified.
11439
 * Keypad string is set to null on power up and is stored until power is lost.
11440
 * The Prompt Text is optional.
11441
 */
62 andreas 11442
void TPageManager::doEKP(int port, std::vector<int>& channels, std::vector<std::string>& pars)
11443
{
11444
    DECL_TRACER("TPageManager::doEKP(int port, std::vector<int>& channels, std::vector<std::string>& pars)");
11445
 
11446
    doAKP(port, channels, pars);
11447
}
63 andreas 11448
 
11449
/**
11450
 * @brief Present a private keyboard.
11451
 * Pops up the keyboard icon and initializes the text string to that specified.
11452
 * Keyboard displays a '*' instead of the letters typed. The Prompt Text is optional.
11453
 */
11454
void TPageManager::doPKB(int, vector<int>&, vector<string>& pars)
11455
{
11456
    DECL_TRACER("TPageManager::doPKB(int, vector<int>&, vector<string>& pars)");
11457
 
11458
    if (pars.size() < 1)
11459
    {
11460
        MSG_ERROR("Expecting 2 parameters but got only " << pars.size() << "! Ignoring command.");
11461
        return;
11462
    }
11463
 
11464
    string initText = pars[0];
11465
    string promptText;
11466
 
11467
    if (pars.size() > 1)
11468
        promptText = pars[1];
11469
 
11470
    if (_callKeyboard)
11471
        _callKeyboard(initText, promptText, true);
11472
}
11473
 
11474
/**
11475
 * @brief Present a private keypad.
11476
 * Pops up the keypad icon and initializes the text string to that specified.
11477
 * Keypad displays a '*' instead of the numbers typed. The Prompt Text is optional.
11478
 */
11479
void TPageManager::doPKP(int, vector<int>&, vector<string>& pars)
11480
{
11481
    DECL_TRACER("TPageManager::doPKP(int, vector<int>&, vector<string>& pars)");
11482
 
11483
    if (pars.size() < 1)
11484
    {
11485
        MSG_ERROR("Expecting 2 parameters but got only " << pars.size() << "! Ignoring command.");
11486
        return;
11487
    }
11488
 
11489
    string initText = pars[0];
11490
    string promptText;
11491
 
11492
    if (pars.size() > 1)
11493
        promptText = pars[1];
11494
 
11495
    if (_callKeypad)
11496
        _callKeypad(initText, promptText, true);
11497
}
11498
 
11499
/**
408 andreas 11500
 * @brief Reset protected password command
11501
 * This command is used to reset the protected setup password to the factory
11502
 * default value.
11503
 */
11504
void TPageManager::doRPP(int, vector<int>&, vector<string>&)
11505
{
11506
    DECL_TRACER("TPageManager::doRPP(int, vector<int>&, vector<string>&)");
11507
 
11508
    TConfig::savePassword1("1988");
11509
}
11510
 
11511
/**
64 andreas 11512
 * Send panel to SETUP page.
11513
 */
11514
void TPageManager::doSetup(int, vector<int>&, vector<string>&)
11515
{
11516
    DECL_TRACER("TPageManager::doSetup(int, vector<int>&, vector<string>&)");
11517
 
11518
    if (_callShowSetup)
11519
        _callShowSetup();
11520
}
11521
 
11522
/**
11523
 * Shut down the App
11524
 */
11525
void TPageManager::doShutdown(int, vector<int>&, vector<string>&)
11526
{
11527
    DECL_TRACER("TPageManager::doShutdown(int, vector<int>&, vector<string>&)");
11528
 
97 andreas 11529
    MSG_PROTOCOL("Received shutdown ...");
64 andreas 11530
#ifdef __ANDROID__
11531
    stopNetworkState();
11532
#endif
11533
    prg_stopped = true;
11534
    killed = true;
11535
 
11536
    if (_shutdown)
11537
        _shutdown();
11538
}
11539
 
82 andreas 11540
void TPageManager::doSOU(int, vector<int>&, vector<string>& pars)
11541
{
11542
    DECL_TRACER("TPageManager::doSOU(int, vector<int>&, vector<string>& pars)");
11543
 
11544
    if (pars.size() < 1)
11545
    {
11546
        MSG_ERROR("@SOU: Expecting a sound file as parameter! Ignoring command.");
11547
        return;
11548
    }
11549
 
11550
    if (!_playSound)
11551
    {
11552
        MSG_ERROR("@SOU: Missing sound module!");
11553
        return;
11554
    }
11555
 
165 andreas 11556
    if (pars[0].empty() || strCaseCompare(pars[0], "None") == 0)
11557
        return;
11558
 
82 andreas 11559
    _playSound(pars[0]);
11560
}
11561
 
326 andreas 11562
void TPageManager::doMUT(int, vector<int>&, vector<string>& pars)
11563
{
11564
    DECL_TRACER("TPageManager::doMUT(int, vector<int>&, vector<string>& pars)");
11565
 
11566
    if (pars.size() < 1)
11567
    {
11568
        MSG_ERROR("^MUT: Expecting a state parameter! Ignoring command.");
11569
        return;
11570
    }
11571
 
11572
    bool mute = 0;
11573
 
11574
    if (pars[0] == "0")
11575
        mute = false;
11576
    else
11577
        mute = true;
11578
 
11579
    TConfig::setMuteState(mute);
11580
#if TESTMODE == 1
327 andreas 11581
    if (_gTestMode)
11582
    {
11583
        bool st = TConfig::getMuteState();
11584
        _gTestMode->setResult(st ? "1" : "0");
11585
    }
11586
 
326 andreas 11587
    __success = true;
334 andreas 11588
    setAllDone();
326 andreas 11589
#endif
11590
}
11591
 
64 andreas 11592
/**
63 andreas 11593
 * @brief Present a telephone keypad.
11594
 * Pops up the keypad icon and initializes the text string to that specified.
11595
 * The Prompt Text is optional.
11596
 */
11597
void TPageManager::doTKP(int port, vector<int>& channels, vector<string>& pars)
11598
{
11599
    DECL_TRACER("TPageManager::doTKP(int port, vector<int>& channels, vector<string>& pars)");
11600
 
11601
    // TODO: Implement a real telefone keypad.
11602
    doAKP(port, channels, pars);
11603
}
11604
 
11605
/**
11606
 * Popup the virtual keyboard
11607
 */
123 andreas 11608
void TPageManager::doVKB(int port, vector<int>& channels, vector<string>& pars)
63 andreas 11609
{
123 andreas 11610
    DECL_TRACER("TPageManager::doVKB(int port, vector<int>& channels, vector<string>& pars)");
63 andreas 11611
 
11612
    doAKP(port, channels, pars);
11613
}
129 andreas 11614
#ifndef _NOSIP_
123 andreas 11615
void TPageManager::sendPHN(vector<string>& cmds)
11616
{
11617
    DECL_TRACER("TPageManager::sendPHN(const vector<string>& cmds)");
11618
 
11619
    vector<int> channels;
11620
    doPHN(-1, channels, cmds);
11621
}
11622
 
141 andreas 11623
void TPageManager::actPHN(vector<string>& cmds)
11624
{
11625
    DECL_TRACER("TPageManager::actPHN(const vector<string>& cmds)");
11626
 
11627
    vector<int> channels;
11628
    doPHN(1, channels, cmds);
11629
}
11630
 
140 andreas 11631
void TPageManager::phonePickup(int id)
11632
{
11633
    DECL_TRACER("TPageManager::phonePickup(int id)");
11634
 
11635
    if (id < 0 || id >= 4)
11636
        return;
11637
 
11638
    if (mSIPClient)
11639
        mSIPClient->pickup(id);
11640
}
11641
 
11642
void TPageManager::phoneHangup(int id)
11643
{
11644
    DECL_TRACER("TPageManager::phoneHangup(int id)");
11645
 
11646
    if (id < 0 || id >= 4)
11647
        return;
11648
 
11649
    if (mSIPClient)
11650
        mSIPClient->terminate(id);
11651
}
11652
 
123 andreas 11653
/**
11654
 * @brief Phone commands.
11655
 * The phone commands could come from the master or are send to the master.
11656
 * If the parameter \p port is less then 0 (zero) a command is send to the
11657
 * master. In any other case the command came from the mater.
125 andreas 11658
 *
11659
 * @param port  This is used to signal if the command was sent by the master
11660
 *              or generated from the panel. If ths is less then 0, then the
11661
 *              method was called because of an event happen in the panel.
11662
 *              If this is grater or equal 0, then the event is comming from
11663
 *              the master.
11664
 * @param pars  This are parameters. The first parameter defines the action
11665
 *              to be done. According to the command this parameter may have a
11666
 *              different number of arguments.
123 andreas 11667
 */
11668
void TPageManager::doPHN(int port, vector<int>&, vector<string>& pars)
11669
{
11670
    DECL_TRACER("TPageManager::doPHN(int port, vector<int>&, vector<string>& pars)");
11671
 
11672
    if (pars.size() < 1)
11673
    {
11674
        MSG_ERROR("Expecting at least 1 parameter but got none! Ignoring command.");
11675
        return;
11676
    }
11677
 
11678
    string sCommand;
11679
    string cmd = toUpper(pars[0]);
11680
 
11681
    // Master to panel
11682
    if (port >= 0)
11683
    {
11684
        if (!mSIPClient)
11685
        {
11686
            MSG_ERROR("SIP client class was not initialized!")
11687
            return;
11688
        }
11689
 
11690
        if (cmd == "ANSWER")
11691
        {
11692
            if (pars.size() >= 2)
11693
            {
124 andreas 11694
                int id = atoi(pars[1].c_str());
11695
 
11696
                if (mSIPClient->getSIPState(id) == TSIPClient::SIP_HOLD)
11697
                    mSIPClient->resume(id);
11698
                else
135 andreas 11699
                    mSIPClient->pickup(id);
123 andreas 11700
            }
11701
        }
11702
        else if (cmd == "AUTOANSWER")
11703
        {
11704
            if (pars.size() >= 2)
11705
            {
11706
                if (pars[1].at(0) == '0')
11707
                    mPHNautoanswer = false;
11708
                else
11709
                    mPHNautoanswer = true;
127 andreas 11710
 
11711
                vector<string> cmds;
11712
                cmds = { "AUTOANSWER", to_string(mPHNautoanswer ? 1 : 0) };
128 andreas 11713
                sendPHN(cmds);
123 andreas 11714
            }
11715
        }
11716
        else if (cmd == "CALL")     // Initiate a call
11717
        {
11718
            if (pars.size() >= 2)
127 andreas 11719
                mSIPClient->call(pars[1]);
123 andreas 11720
        }
11721
        else if (cmd == "DTMF")     // Send tone modified codes
11722
        {
127 andreas 11723
            if (pars.size() >= 2)
11724
                mSIPClient->sendDTMF(pars[1]);
123 andreas 11725
        }
11726
        else if (cmd == "HANGUP")   // terminate a call
11727
        {
124 andreas 11728
            if (pars.size() >= 2)
11729
            {
11730
                int id = atoi(pars[1].c_str());
11731
                mSIPClient->terminate(id);
11732
            }
123 andreas 11733
        }
11734
        else if (cmd == "HOLD")     // Hold the line
11735
        {
124 andreas 11736
            if (pars.size() >= 2)
11737
            {
11738
                int id = atoi(pars[1].c_str());
11739
                mSIPClient->hold(id);
11740
            }
123 andreas 11741
        }
128 andreas 11742
        else if (cmd == "LINESTATE") // State of all line
127 andreas 11743
        {
128 andreas 11744
            mSIPClient->sendLinestate();
127 andreas 11745
        }
123 andreas 11746
        else if (cmd == "PRIVACY")  // Set/unset "do not disturb"
11747
        {
128 andreas 11748
            if (pars.size() >= 2)
11749
            {
11750
                bool state = (pars[1].at(0) == '1' ? true : false);
11751
                mSIPClient->sendPrivate(state);
11752
            }
123 andreas 11753
        }
11754
        else if (cmd == "REDIAL")   // Redials the last number
11755
        {
128 andreas 11756
            mSIPClient->redial();
123 andreas 11757
        }
11758
        else if (cmd == "TRANSFER") // Transfer call to provided number
11759
        {
128 andreas 11760
            if (pars.size() >= 3)
11761
            {
11762
                int id = atoi(pars[1].c_str());
11763
                string num = pars[2];
11764
 
11765
                if (mSIPClient->transfer(id, num))
11766
                {
11767
                    vector<string> cmds;
11768
                    cmds.push_back("TRANSFERRED");
11769
                    sendPHN(cmds);
11770
                }
11771
            }
123 andreas 11772
        }
144 andreas 11773
        else if (cmd == "IM")
11774
        {
11775
            if (pars.size() < 3)
11776
                return;
11777
 
11778
            string to = pars[1];
11779
            string msg = pars[2];
11780
            string toUri;
11781
 
11782
            if (to.find("sip:") == string::npos)
11783
                toUri = "sip:";
11784
 
11785
            toUri += to;
11786
 
11787
            if (to.find("@") == string::npos)
11788
                toUri += "@" + TConfig::getSIPproxy();
11789
 
11790
            mSIPClient->sendIM(toUri, msg);
11791
        }
123 andreas 11792
        else if (cmd == "SETUP")    // Some temporary settings
11793
        {
11794
            if (pars.size() < 2)
11795
                return;
11796
 
11797
            if (pars[1] == "DOMAIN" && pars.size() >= 3)
11798
                TConfig::setSIPdomain(pars[2]);
11799
            else if (pars[1] == "DTMFDURATION")
11800
            {
138 andreas 11801
                unsigned int ms = atoi(pars[2].c_str());
11802
                mSIPClient->setDTMFduration(ms);
123 andreas 11803
            }
11804
            else if (pars[1] == "ENABLE")   // (re)register user
11805
            {
11806
                TConfig::setSIPstatus(true);
127 andreas 11807
                mSIPClient->cleanUp();
135 andreas 11808
                mSIPClient->init();
123 andreas 11809
            }
127 andreas 11810
            else if (pars[1] == "DOMAIN" && pars.size() >= 3)
11811
                TConfig::setSIPdomain(pars[2]);
123 andreas 11812
            else if (pars[1] == "PASSWORD" && pars.size() >= 3)
11813
                TConfig::setSIPpassword(pars[2]);
11814
            else if (pars[1] == "PORT" && pars.size() != 3)
11815
                TConfig::setSIPport(atoi(pars[2].c_str()));
11816
            else if (pars[1] == "PROXYADDR" && pars.size() >= 3)
11817
                TConfig::setSIPproxy(pars[2]);
11818
            else if (pars[1] == "STUNADDR" && pars.size() >= 3)
11819
                TConfig::setSIPstun(pars[2]);
11820
            else if (pars[1] == "USERNAME" && pars.size() >= 3)
11821
                TConfig::setSIPuser(pars[2]);
11822
        }
11823
        else
11824
        {
11825
            MSG_ERROR("Unknown command ^PHN-" << cmd << " ignored!");
11826
        }
11827
    }
11828
    else   // Panel to master
11829
    {
11830
        vector<string>::iterator iter;
11831
 
11832
        for (iter = pars.begin(); iter != pars.end(); ++iter)
11833
        {
11834
            if (!sCommand.empty())
11835
                sCommand += ",";
11836
 
11837
            sCommand += *iter;
11838
        }
11839
 
11840
        sendPHNcommand(sCommand);
11841
    }
11842
}
127 andreas 11843
 
11844
void TPageManager::getPHN(int, vector<int>&, vector<string>& pars)
11845
{
11846
    DECL_TRACER("TPageManager::getPHN(int, vector<int>&, vector<string>& pars)");
11847
 
11848
    if (pars.size() < 1)
11849
    {
11850
        MSG_ERROR("Invalid number of arguments!");
11851
        return;
11852
    }
11853
 
11854
    string cmd = pars[0];
11855
 
11856
    if (cmd == "AUTOANSWER")
11857
        sendPHNcommand(cmd + "," + (mPHNautoanswer ? "1" : "0"));
11858
    else if (cmd == "LINESTATE")
11859
    {
11860
        if (!mSIPClient)
11861
            return;
11862
 
138 andreas 11863
        mSIPClient->sendLinestate();
127 andreas 11864
    }
11865
    else if (cmd == "MSGWAITING")
11866
    {
144 andreas 11867
        size_t num = mSIPClient->getNumberMessages();
11868
        sendPHNcommand(cmd + "," + (num > 0 ? "1" : "0") + "," + std::to_string(num) + "0,0,0");
127 andreas 11869
    }
11870
    else if (cmd == "PRIVACY")
11871
    {
138 andreas 11872
        if (mSIPClient->getPrivate())
11873
            sendPHNcommand(cmd + ",1");
11874
        else
11875
            sendPHNcommand(cmd + ",0");
127 andreas 11876
    }
144 andreas 11877
    else if (cmd == "REDIAL")
11878
    {
11879
        if (pars.size() < 2)
11880
            return;
11881
 
11882
        sendPHNcommand(cmd + "," + pars[1]);
11883
    }
127 andreas 11884
    else
11885
    {
11886
        MSG_WARNING("Unknown command " << cmd << " found!");
11887
    }
11888
}
129 andreas 11889
#endif  // _NOSIP_
134 andreas 11890
 
300 andreas 11891
/*
318 andreas 11892
 *  Hide all subpages in a subpage viewer button.
11893
 */
11894
void TPageManager::doSHA(int port, vector<int> &channels, vector<string> &pars)
11895
{
11896
    DECL_TRACER("TPageManager::doSHA(int port, vector<int> &channels, vector<string> &pars)");
11897
 
343 andreas 11898
    Q_UNUSED(pars);
318 andreas 11899
    vector<TMap::MAP_T> map = findButtons(port, channels);
11900
 
11901
    if (TError::isError() || map.empty())
11902
        return;
11903
 
11904
    vector<Button::TButton *> buttons = collectButtons(map);
11905
 
11906
    if (!buttons.empty())
11907
    {
11908
        vector<Button::TButton *>::iterator mapIter;
11909
 
11910
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
11911
        {
11912
            Button::TButton *bt = *mapIter;
11913
 
11914
            if (_hideAllSubViewItems)
11915
                _hideAllSubViewItems(bt->getHandle());
11916
        }
11917
    }
11918
}
11919
 
11920
void TPageManager::doSHD(int port, vector<int>& channels, vector<string>& pars)
11921
{
11922
    DECL_TRACER("TPageManager::doSHD(int port, vector<int>& channels, vector<string>& pars)");
11923
 
11924
    if (pars.size() < 1)
11925
        return;
11926
 
11927
    string name = pars[0];
11928
 
11929
    vector<TMap::MAP_T> map = findButtons(port, channels);
11930
 
11931
    if (TError::isError() || map.empty())
11932
        return;
11933
 
11934
    vector<Button::TButton *> buttons = collectButtons(map);
11935
 
11936
    if (!buttons.empty())
11937
    {
11938
        vector<Button::TButton *>::iterator mapIter;
11939
 
11940
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
11941
        {
11942
            Button::TButton *bt = *mapIter;
11943
 
11944
            vector<TSubPage *> subviews = createSubViewList(bt->getSubViewID());
11945
 
11946
            if (subviews.empty())
11947
                continue;
11948
 
11949
            vector<TSubPage *>::iterator itSub;
11950
 
11951
            for (itSub = subviews.begin(); itSub != subviews.end(); ++itSub)
11952
            {
11953
                TSubPage *sub = *itSub;
11954
 
11955
                if (sub && sub->getName() == name)
11956
                {
11957
                    if (_hideSubViewItem)
11958
                        _hideSubViewItem(bt->getHandle(), sub->getHandle());
11959
 
11960
                    break;
11961
                }
11962
            }
11963
        }
11964
    }
11965
}
11966
 
11967
void TPageManager::doSPD(int port, vector<int>& channels, vector<string>& pars)
11968
{
11969
    DECL_TRACER("TPageManager::doSPD(int port, vector<int>& channel, vector<string>& pars)");
11970
 
11971
    if (pars.size() < 1)
11972
        return;
11973
 
11974
    TError::clear();
11975
    int padding = atoi(pars[0].c_str());
11976
 
11977
    if (padding < 0 || padding > 100)
11978
        return;
11979
 
11980
    vector<TMap::MAP_T> map = findButtons(port, channels);
11981
 
11982
    if (TError::isError() || map.empty())
11983
        return;
11984
 
11985
    vector<Button::TButton *> buttons = collectButtons(map);
11986
 
11987
    if (!buttons.empty())
11988
    {
11989
        vector<Button::TButton *>::iterator mapIter;
11990
 
11991
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
11992
        {
11993
            Button::TButton *bt = *mapIter;
11994
 
11995
            if (_setSubViewPadding)
11996
                _setSubViewPadding(bt->getHandle(), padding);
11997
        }
11998
    }
11999
}
12000
 
12001
/*
300 andreas 12002
 * This command will perform one of three different operations based on the following conditions:
12003
 * 1. If the named subpage is hidden in the set associated with the viewer button it will be shown in the anchor position.
12004
 * 2. If the named subpage is not present in the set it will be added to the set and shown in the anchor position.
12005
 * 3. If the named subpage is already present in the set and is not hidden then the viewer button will move it to the anchor
12006
 * position. The anchor position is the location on the subpage viewer button specified by its weighting. This will either be
12007
 * left, center or right for horizontal subpage viewer buttons or top, center or bottom for vertical subpage viewer buttons.
12008
 * Surrounding subpages are relocated on the viewer button as needed to accommodate the described operations
12009
 */
12010
void TPageManager::doSSH(int port, vector<int> &channels, vector<string> &pars)
12011
{
12012
    DECL_TRACER("TPageManager::doSSH(int port, vector<int> &channels, vector<string> &pars)");
12013
 
12014
    if (pars.size() < 1)
12015
    {
12016
        MSG_ERROR("Expecting 1 parameter but got none! Ignoring command.");
12017
        return;
12018
    }
12019
 
12020
    TError::clear();
12021
    string name = pars[0];
12022
    int position = 0;   // optional
12023
    int time = 0;       // optional
12024
 
12025
    if (pars.size() > 1)
12026
        position = atoi(pars[1].c_str());
12027
 
12028
    if (pars.size() > 2)
12029
        time = atoi(pars[2].c_str());
12030
 
12031
    vector<TMap::MAP_T> map = findButtons(port, channels);
12032
 
12033
    if (TError::isError() || map.empty())
12034
        return;
12035
 
12036
    vector<Button::TButton *> buttons = collectButtons(map);
12037
 
12038
    if (!buttons.empty())
12039
    {
12040
        vector<Button::TButton *>::iterator mapIter;
12041
 
12042
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
12043
        {
12044
            Button::TButton *bt = *mapIter;
12045
            vector<TSubPage *> subviews = createSubViewList(bt->getSubViewID());
12046
 
12047
            if (subviews.empty() || !bt)
12048
                continue;
12049
 
12050
            vector<TSubPage *>::iterator itSub;
12051
 
12052
            for (itSub = subviews.begin(); itSub != subviews.end(); ++itSub)
12053
            {
12054
                TSubPage *sub = *itSub;
12055
 
12056
                if (sub && sub->getName() == name)
12057
                {
12058
                    if (_showSubViewItem)
12059
                        _showSubViewItem(sub->getHandle(), bt->getHandle(), position, time);
12060
 
12061
                    break;
12062
                }
12063
            }
12064
        }
12065
    }
12066
}
12067
 
318 andreas 12068
void TPageManager::doSTG(int port, vector<int>& channels, vector<string>& pars)
12069
{
12070
    DECL_TRACER("TPageManager::doSTG(int port, vector<int>& channels, vector<string>& pars)");
12071
 
12072
    if (pars.empty())
12073
    {
12074
        MSG_ERROR("Expecting 1 parameter but got none! Ignoring command.");
12075
        return;
12076
    }
12077
 
12078
    TError::clear();
12079
    string name = pars[0];
12080
    int position = 0;   // optional
12081
    int time = 0;       // optional
12082
 
12083
    if (pars.size() > 1)
12084
        position = atoi(pars[1].c_str());
12085
 
12086
    if (pars.size() > 2)
12087
        time = atoi(pars[2].c_str());
12088
 
12089
    vector<TMap::MAP_T> map = findButtons(port, channels);
12090
 
12091
    if (TError::isError() || map.empty())
12092
        return;
12093
 
12094
    vector<Button::TButton *> buttons = collectButtons(map);
12095
 
12096
    if (!buttons.empty())
12097
    {
12098
        vector<Button::TButton *>::iterator mapIter;
12099
 
12100
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
12101
        {
12102
            Button::TButton *bt = *mapIter;
12103
            vector<TSubPage *> subviews = createSubViewList(bt->getSubViewID());
12104
 
12105
            if (subviews.empty() || !bt)
12106
                continue;
12107
 
12108
            vector<TSubPage *>::iterator itSub;
12109
 
12110
            for (itSub = subviews.begin(); itSub != subviews.end(); ++itSub)
12111
            {
12112
                TSubPage *sub = *itSub;
12113
 
12114
                if (sub && sub->getName() == name)
12115
                {
12116
                    if (_toggleSubViewItem)
12117
                        _toggleSubViewItem(sub->getHandle(), bt->getHandle(), position, time);
12118
 
12119
                    break;
12120
                }
12121
            }
12122
        }
12123
    }
12124
}
12125
 
227 andreas 12126
void TPageManager::doLVD(int port, vector<int> &channels, vector<string> &pars)
225 andreas 12127
{
227 andreas 12128
    DECL_TRACER("TPageManager::doLVD(int port, vector<int> &channels, vector<string> &pars)");
225 andreas 12129
 
12130
    if (pars.size() < 1)
12131
    {
12132
        MSG_ERROR("Expecting one parameter but got none! Ignoring command.");
12133
        return;
12134
    }
12135
 
12136
    TError::clear();
12137
    string source = pars[0];
12138
    vector<string> configs;
12139
 
12140
    if (pars.size() > 1)
12141
    {
12142
        for (size_t i = 1; i < pars.size(); ++i)
227 andreas 12143
        {
12144
            string low = toLower(pars[i]);
12145
 
12146
            if (low.find_first_of("user=") != string::npos ||
12147
                low.find_first_of("pass=") != string::npos ||
12148
                low.find_first_of("csv=")  != string::npos ||
12149
                low.find_first_of("has_headers=") != string::npos)
12150
            {
12151
                configs.push_back(pars[i]);
12152
            }
12153
        }
225 andreas 12154
    }
12155
 
12156
    vector<TMap::MAP_T> map = findButtons(port, channels);
12157
 
12158
    if (TError::isError() || map.empty())
12159
        return;
12160
 
12161
    vector<Button::TButton *> buttons = collectButtons(map);
12162
 
12163
    if (buttons.size() > 0)
12164
    {
12165
        vector<Button::TButton *>::iterator mapIter;
12166
 
12167
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
12168
        {
12169
            Button::TButton *bt = *mapIter;
12170
            bt->setListSource(source, configs);
12171
        }
12172
    }
12173
 
12174
}
12175
 
230 andreas 12176
void TPageManager::doLVE(int port, vector<int> &channels, vector<string> &pars)
12177
{
12178
    DECL_TRACER("TPageManager::doLVE(int port, vector<int> &channels, vector<string> &pars)");
12179
 
12180
    if (pars.size() < 1)
12181
    {
12182
        MSG_ERROR("Expecting one parameter but got none! Ignoring command.");
12183
        return;
12184
    }
12185
 
12186
    TError::clear();
12187
    int num = atoi(pars[0].c_str());
12188
 
12189
    vector<TMap::MAP_T> map = findButtons(port, channels);
12190
 
12191
    if (TError::isError() || map.empty())
12192
        return;
12193
 
12194
    vector<Button::TButton *> buttons = collectButtons(map);
12195
 
12196
    if (buttons.size() > 0)
12197
    {
12198
        vector<Button::TButton *>::iterator mapIter;
12199
 
12200
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
12201
        {
12202
            Button::TButton *bt = *mapIter;
12203
            bt->setListViewEventNumber(num);
12204
        }
12205
    }
12206
 
12207
}
12208
 
227 andreas 12209
void TPageManager::doLVF(int port, vector<int> &channels, vector<string> &pars)
12210
{
12211
    DECL_TRACER("TPageManager::doLVF(int port, vector<int> &channels, vector<string> &pars)");
12212
 
12213
    if (pars.size() < 1)
12214
    {
12215
        MSG_ERROR("Expecting one parameter but got none! Ignoring command.");
12216
        return;
12217
    }
12218
 
12219
    TError::clear();
12220
    string filter;
12221
 
12222
    vector<string>::iterator iter;
12223
 
12224
    for (iter = pars.begin(); iter != pars.end(); ++iter)
12225
    {
12226
        if (filter.length() > 0)
12227
            filter += ",";
12228
 
12229
        filter += *iter;
12230
    }
12231
 
12232
    vector<TMap::MAP_T> map = findButtons(port, channels);
12233
 
12234
    if (TError::isError() || map.empty())
12235
        return;
12236
 
12237
    vector<Button::TButton *> buttons = collectButtons(map);
12238
 
12239
    if (buttons.size() > 0)
12240
    {
12241
        vector<Button::TButton *>::iterator mapIter;
12242
 
12243
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
12244
        {
12245
            Button::TButton *bt = *mapIter;
12246
            bt->setListSourceFilter(filter);
12247
        }
12248
    }
12249
}
12250
 
230 andreas 12251
void TPageManager::doLVL(int port, vector<int> &channels, vector<string> &pars)
12252
{
12253
    DECL_TRACER("TPageManager::doLVL(int port, vector<int> &channels, vector<string> &pars)");
12254
 
12255
    if (pars.size() < 1)
12256
    {
12257
        MSG_ERROR("Expecting one parameter but got none! Ignoring command.");
12258
        return;
12259
    }
12260
 
12261
    TError::clear();
233 andreas 12262
    bool hasColumns = false;
230 andreas 12263
    int columns = 0;
233 andreas 12264
    bool hasLayout = false;
230 andreas 12265
    int layout = 0;
233 andreas 12266
    bool hasComponent = false;
12267
    int component = 0;
12268
    bool hasCellHeight = false;
12269
    bool cellHeightPercent = false;
12270
    int cellheight = 0;
12271
    bool hasP1 = false;
12272
    int p1 = 0;
12273
    bool hasP2 = false;
12274
    int p2 = 0;
12275
    bool hasFilter = false;
12276
    bool filter = false;
12277
    bool hasFilterHeight = false;
12278
    bool filterHeightPercent = false;
12279
    int filterheight = 0;
12280
    bool hasAlphaScroll = false;
12281
    bool alphascroll = false;
230 andreas 12282
 
12283
    vector<string>::iterator iter;
12284
 
12285
    for (iter = pars.begin(); iter != pars.end(); ++iter)
12286
    {
12287
        string low = toLower(*iter);
12288
 
12289
        if (low.find("columns=") != string::npos ||
12290
            low.find("nc=") != string::npos ||
12291
            low.find("numcol=") != string::npos)
12292
        {
12293
            size_t pos = low.find("=");
12294
            string sCols = low.substr(pos + 1);
12295
            columns = atoi(sCols.c_str());
233 andreas 12296
            hasColumns = true;
12297
        }
12298
        else if (low.find("c=") != string::npos || low.find("comp=") != string::npos)
12299
        {
12300
            size_t pos = low.find("=");
12301
            string sComp = low.substr(pos + 1);
12302
            component |= atoi(sComp.c_str());
12303
            hasComponent = true;
12304
        }
12305
        else if (low.find("l=") != string::npos || low.find("layout=") != string::npos)
12306
        {
12307
            size_t pos = low.find("=");
12308
            string sLay = low.substr(pos + 1);
12309
            layout = atoi(sLay.c_str());
12310
            hasLayout = true;
12311
        }
12312
        else if (low.find("ch=") != string::npos || low.find("cellheight=") != string::npos)
12313
        {
12314
            size_t pos = low.find("=");
12315
            string sCh = low.substr(pos + 1);
12316
            cellheight = atoi(sCh.c_str());
230 andreas 12317
 
233 andreas 12318
            if (low.find("%") != string::npos)
12319
                cellHeightPercent = true;
12320
 
12321
            hasCellHeight = true;
230 andreas 12322
        }
233 andreas 12323
        else if (low.find("p1=") != string::npos)
12324
        {
12325
            size_t pos = low.find("=");
12326
            string sP1 = low.substr(pos + 1);
12327
            p1 = atoi(sP1.c_str());
12328
            hasP1 = true;
12329
        }
12330
        else if (low.find("p2=") != string::npos)
12331
        {
12332
            size_t pos = low.find("=");
12333
            string sP2 = low.substr(pos + 1);
12334
            p2 = atoi(sP2.c_str());
12335
            hasP2 = true;
12336
        }
12337
        else if (low.find("f=") != string::npos || low.find("filter=") != string::npos)
12338
        {
12339
            size_t pos = low.find("=");
12340
            string sFilter = low.substr(pos + 1);
12341
            filter = isTrue(sFilter);
12342
            hasFilter = true;
12343
        }
12344
        else if (low.find("fh=") != string::npos || low.find("filterheight=") != string::npos)
12345
        {
12346
            size_t pos = low.find("=");
12347
            string sFilter = low.substr(pos + 1);
12348
            filterheight = atoi(sFilter.c_str());
12349
 
12350
            if (low.find("%") != string::npos)
12351
                filterHeightPercent = true;
12352
 
12353
            hasFilterHeight = true;
12354
        }
12355
        else if (low.find("as=") != string::npos || low.find("alphascroll=") != string::npos)
12356
        {
12357
            size_t pos = low.find("=");
12358
            string sAlpha = low.substr(pos + 1);
12359
            alphascroll = isTrue(sAlpha);
12360
            hasAlphaScroll = true;
12361
        }
230 andreas 12362
    }
12363
 
12364
    vector<TMap::MAP_T> map = findButtons(port, channels);
12365
 
12366
    if (TError::isError() || map.empty())
12367
        return;
12368
 
12369
    vector<Button::TButton *> buttons = collectButtons(map);
12370
 
12371
    if (buttons.size() > 0)
12372
    {
12373
        vector<Button::TButton *>::iterator mapIter;
12374
 
12375
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
12376
        {
12377
            Button::TButton *bt = *mapIter;
233 andreas 12378
 
12379
            if (hasColumns)         bt->setListViewColumns(columns);
12380
            if (hasComponent)       bt->setListViewComponent(component);
12381
            if (hasLayout)          bt->setListViewLayout(layout);
12382
            if (hasCellHeight)      bt->setListViewCellheight(cellheight, cellHeightPercent);
12383
            if (hasP1)              bt->setListViewP1(p1);
12384
            if (hasP2)              bt->setListViewP2(p2);
12385
            if (hasFilter)          bt->setListViewColumnFilter(filter);
12386
            if (hasFilterHeight)    bt->setListViewFilterHeight(filterheight, filterHeightPercent);
12387
            if (hasAlphaScroll)     bt->setListViewAlphaScroll(alphascroll);
230 andreas 12388
        }
12389
    }
12390
}
12391
 
233 andreas 12392
void TPageManager::doLVM(int port, vector<int> &channels, vector<string> &pars)
12393
{
12394
    DECL_TRACER("TPageManager::doLVM(int port, vector<int> &channels, vector<string> &pars)");
12395
 
12396
    if (pars.size() < 1)
12397
    {
12398
        MSG_ERROR("Expecting one parameter but got none! Ignoring command.");
12399
        return;
12400
    }
12401
 
12402
    TError::clear();
12403
    map<string,string> mapField;
12404
 
12405
    vector<string>::iterator iter;
12406
 
12407
    for (iter = pars.begin(); iter != pars.end(); ++iter)
12408
    {
12409
        string left, right;
12410
        size_t pos = 0;
12411
 
12412
        if ((pos = iter->find("=")) != string::npos)
12413
        {
12414
            string left = iter->substr(0, pos);
12415
            left = toLower(left);
12416
            string right = iter->substr(pos + 1);
12417
 
12418
            if (left == "t1" || left == "t2" || left == "i1")
12419
                mapField.insert(pair<string,string>(left, right));
12420
        }
12421
    }
12422
 
12423
    vector<TMap::MAP_T> map = findButtons(port, channels);
12424
 
12425
    if (TError::isError() || map.empty())
12426
        return;
12427
 
12428
    vector<Button::TButton *> buttons = collectButtons(map);
12429
 
12430
    if (buttons.size() > 0)
12431
    {
12432
        vector<Button::TButton *>::iterator mapIter;
12433
 
12434
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
12435
        {
12436
            Button::TButton *bt = *mapIter;
12437
            bt->setListViewFieldMap(mapField);
12438
        }
12439
    }
12440
}
12441
 
12442
void TPageManager::doLVN(int port, vector<int> &channels, vector<string> &pars)
12443
{
12444
    DECL_TRACER("TPageManager::doLVN(int port, vector<int> &channels, vector<string> &pars)");
12445
 
12446
    if (pars.size() < 1)
12447
    {
12448
        MSG_ERROR("Expecting one parameter but got none! Ignoring command.");
12449
        return;
12450
    }
12451
 
12452
    TError::clear();
12453
    string command = pars[0];
12454
    bool select = false;
12455
 
12456
    if (pars.size() > 1)
12457
    {
12458
        if (isTrue(pars[1]))
12459
            select = true;
12460
    }
12461
 
12462
    vector<TMap::MAP_T> map = findButtons(port, channels);
12463
 
12464
    if (TError::isError() || map.empty())
12465
        return;
12466
 
12467
    vector<Button::TButton *> buttons = collectButtons(map);
12468
 
12469
    if (buttons.size() > 0)
12470
    {
12471
        vector<Button::TButton *>::iterator mapIter;
12472
 
12473
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
12474
        {
12475
            Button::TButton *bt = *mapIter;
12476
            bt->listViewNavigate(command, select);
12477
        }
12478
    }
12479
}
12480
 
12481
void TPageManager::doLVR(int port, vector<int> &channels, vector<string> &pars)
12482
{
12483
    DECL_TRACER("TPageManager::doLVR(int port, vector<int> &channels, vector<string> &pars)");
12484
 
12485
    TError::clear();
12486
    int interval = -1;
12487
    bool force = false;
12488
 
12489
    if (pars.size() > 0)
12490
        interval = atoi(pars[0].c_str());
12491
 
12492
    if (pars.size() > 1)
12493
        force = isTrue(pars[1]);
12494
 
12495
    vector<TMap::MAP_T> map = findButtons(port, channels);
12496
 
12497
    if (TError::isError() || map.empty())
12498
        return;
12499
 
12500
    vector<Button::TButton *> buttons = collectButtons(map);
12501
 
12502
    if (buttons.size() > 0)
12503
    {
12504
        vector<Button::TButton *>::iterator mapIter;
12505
 
12506
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
12507
        {
12508
            Button::TButton *bt = *mapIter;
12509
            bt->listViewRefresh(interval, force);
12510
        }
12511
    }
12512
}
12513
 
12514
void TPageManager::doLVS(int port, vector<int> &channels, vector<string> &pars)
12515
{
12516
    DECL_TRACER("TPageManager::doLVS(int port, vector<int> &channels, vector<string> &pars)");
12517
 
12518
    TError::clear();
12519
    vector<string> sortColumns;
12520
    Button::LIST_SORT sort = Button::LIST_SORT_NONE;
12521
    string override;
12522
 
12523
    if (pars.size() > 0)
12524
    {
12525
        vector<string>::iterator iter;
12526
 
12527
        for (iter = pars.begin(); iter != pars.end(); ++iter)
12528
        {
12529
            if (iter->find(";") == string::npos)
12530
                sortColumns.push_back(*iter);
12531
            else
12532
            {
12533
                vector<string> parts = StrSplit(*iter, ";");
12534
                sortColumns.push_back(parts[0]);
12535
 
12536
                if (parts[1].find("a") != string::npos || parts[1].find("A") != string::npos)
12537
                    sort = Button::LIST_SORT_ASC;
12538
                else if (parts[1].find("d") != string::npos || parts[1].find("D") != string::npos)
12539
                    sort = Button::LIST_SORT_DESC;
12540
                else if (parts[1].find("*") != string::npos)
12541
                {
12542
                    if (parts.size() > 2 && !parts[2].empty())
12543
                    {
12544
                        override = parts[2];
12545
                        sort = Button::LIST_SORT_OVERRIDE;
12546
                    }
12547
                }
12548
                else if (parts[1].find("n") != string::npos || parts[1].find("N") != string::npos)
12549
                    sort = Button::LIST_SORT_NONE;
12550
            }
12551
        }
12552
    }
12553
 
12554
    vector<TMap::MAP_T> map = findButtons(port, channels);
12555
 
12556
    if (TError::isError() || map.empty())
12557
        return;
12558
 
12559
    vector<Button::TButton *> buttons = collectButtons(map);
12560
 
12561
    if (buttons.size() > 0)
12562
    {
12563
        vector<Button::TButton *>::iterator mapIter;
12564
 
12565
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
12566
        {
12567
            Button::TButton *bt = *mapIter;
12568
            bt->listViewSortData(sortColumns, sort, override);
12569
        }
12570
    }
12571
}
12572
 
134 andreas 12573
void TPageManager::doTPCCMD(int, vector<int>&, vector<string>& pars)
12574
{
12575
    DECL_TRACER("TPageManager::doTPCCMD(int, vector<int>&, vector<string>& pars)");
12576
 
12577
    if (pars.size() < 1)
12578
    {
12579
        MSG_ERROR("Too few arguments for TPCCMD!");
12580
        return;
12581
    }
12582
 
12583
    string cmd = pars[0];
12584
 
12585
    if (strCaseCompare(cmd, "LocalHost") == 0)
12586
    {
12587
        if (pars.size() < 2 || pars[1].empty())
12588
        {
12589
            MSG_ERROR("The command \"LocalHost\" requires an additional parameter!");
12590
            return;
12591
        }
12592
 
12593
        TConfig::saveController(pars[1]);
12594
    }
12595
    else if (strCaseCompare(cmd, "LocalPort") == 0)
12596
    {
12597
        if (pars.size() < 2 || pars[1].empty())
12598
        {
12599
            MSG_ERROR("The command \"LocalPort\" requires an additional parameter!");
12600
            return;
12601
        }
12602
 
12603
        int port = atoi(pars[1].c_str());
12604
 
12605
        if (port > 0 && port < 65536)
12606
            TConfig::savePort(port);
12607
        else
12608
        {
12609
            MSG_ERROR("Invalid network port " << port);
12610
        }
12611
    }
12612
    else if (strCaseCompare(cmd, "DeviceID") == 0)
12613
    {
12614
        if (pars.size() < 2 || pars[1].empty())
12615
        {
12616
            MSG_ERROR("The command \"DeviceID\" requires an additional parameter!");
12617
            return;
12618
        }
12619
 
12620
        int id = atoi(pars[1].c_str());
12621
 
12622
        if (id >= 10000 && id < 30000)
12623
            TConfig::setSystemChannel(id);
12624
    }
12625
    else if (strCaseCompare(cmd, "ApplyProfile") == 0)
12626
    {
12627
        // We restart the network connection only
12628
        if (gAmxNet)
12629
            gAmxNet->reconnect();
12630
    }
12631
    else if (strCaseCompare(cmd, "QueryDeviceInfo") == 0)
12632
    {
12633
        string info = "DEVICEINFO-TPANELID," + TConfig::getPanelType();
12634
        info += ";HOSTNAME,";
12635
        char hostname[HOST_NAME_MAX];
12636
 
12637
        if (gethostname(hostname, HOST_NAME_MAX) != 0)
12638
        {
12639
            MSG_ERROR("Can't get host name: " << strerror(errno));
12640
            return;
12641
        }
12642
 
12643
        info.append(hostname);
12644
        info += ";UUID," + TConfig::getUUID();
12645
        sendGlobalString(info);
12646
    }
12647
    else if (strCaseCompare(cmd, "LockRotation") == 0)
12648
    {
12649
        if (pars.size() < 2 || pars[1].empty())
12650
        {
12651
            MSG_ERROR("The command \"LockRotation\" requires an additional parameter!");
12652
            return;
12653
        }
12654
 
12655
        if (strCaseCompare(pars[1], "true") == 0)
12656
            TConfig::setRotationFixed(true);
12657
        else
12658
            TConfig::setRotationFixed(false);
12659
    }
12660
    else if (strCaseCompare(cmd, "ButtonHit") == 0)
12661
    {
12662
        if (pars.size() < 2 || pars[1].empty())
12663
        {
12664
            MSG_ERROR("The command \"ButtonHit\" requires an additional parameter!");
12665
            return;
12666
        }
12667
 
12668
        if (strCaseCompare(pars[1], "true") == 0)
12669
            TConfig::saveSystemSoundState(true);
12670
        else
12671
            TConfig::saveSystemSoundState(false);
12672
    }
12673
    else if (strCaseCompare(cmd, "ReprocessTP4") == 0)
12674
    {
12675
        if (_resetSurface)
12676
            _resetSurface();
12677
    }
12678
}
12679
 
12680
void TPageManager::doTPCACC(int, vector<int>&, vector<string>& pars)
12681
{
12682
    DECL_TRACER("TPageManager::doTPCACC(int, vector<int>&, vector<string>& pars)");
12683
 
12684
    if (pars.size() < 1)
12685
    {
12686
        MSG_ERROR("Too few arguments for TPCACC!");
12687
        return;
12688
    }
12689
 
12690
    string cmd = pars[0];
12691
 
12692
    if (strCaseCompare(cmd, "ENABLE") == 0)
12693
    {
12694
        mInformOrientation = true;
12695
        sendOrientation();
12696
    }
12697
    else if (strCaseCompare(cmd, "DISABLE") == 0)
12698
    {
12699
        mInformOrientation = false;
12700
    }
12701
    else if (strCaseCompare(cmd, "QUERY") == 0)
12702
    {
12703
        sendOrientation();
12704
    }
12705
}
153 andreas 12706
 
279 andreas 12707
#ifndef _NOSIP_
153 andreas 12708
void TPageManager::doTPCSIP(int, vector<int>&, vector<string>& pars)
12709
{
12710
    DECL_TRACER("TPageManager::doTPCSIP(int port, vector<int>& channels, vector<string>& pars)");
12711
 
12712
    if (pars.empty())
12713
        return;
12714
 
12715
    string cmd = toUpper(pars[0]);
12716
 
12717
    if (cmd == "SHOW" && _showPhoneDialog)
12718
        _showPhoneDialog(true);
12719
    else if (!_showPhoneDialog)
12720
    {
12721
        MSG_ERROR("There is no phone dialog registered!");
12722
    }
12723
}
279 andreas 12724
#endif