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);
343 andreas 5840
#if TESTMODE == 1
5841
                if (_gTestMode)
5842
                    _gTestMode->setResult(intToString(bt->getLevelValue()));
5843
#endif
5844
            }
416 andreas 5845
            else if (bt->getButtonType() == JOYSTICK)
5846
            {
5847
                int x = (bt->getLevelChannel() == c ? level : bt->getLevelAxisX());
5848
                int y = (bt->getLevelChannel() == c ? bt->getLevelAxisY() : level);
418 andreas 5849
 
5850
                if (bt->isBargraphInverted())
435 andreas 5851
                    x = (bt->getRangeHigh() - bt->getRangeLow()) - x;
418 andreas 5852
 
5853
                if (bt->isJoystickAuxInverted())
435 andreas 5854
                    y = (bt->getRangeHigh() - bt->getRangeLow()) - y;
418 andreas 5855
 
416 andreas 5856
                bt->drawJoystick(x, y);
5857
            }
418 andreas 5858
            else if (bt->getButtonType() == MULTISTATE_BARGRAPH && bt->getLevelChannel() == c)
83 andreas 5859
            {
5860
                int state = (int)((double)bt->getStateCount() / (double)(bt->getRangeHigh() - bt->getRangeLow()) * (double)level);
5861
                bt->setActive(state);
343 andreas 5862
#if TESTMODE == 1
5863
                if (_gTestMode)
5864
                    _gTestMode->setResult(intToString(bt->getActiveInstance()));
5865
#endif
83 andreas 5866
            }
15 andreas 5867
        }
5868
    }
429 andreas 5869
    else
5870
        MSG_DEBUG("No buttons found!");
5871
 
343 andreas 5872
#if TESTMODE == 1
5873
    setDone();
5874
#endif
15 andreas 5875
}
5876
 
22 andreas 5877
void TPageManager::doBLINK(int, vector<int>&, vector<string>& pars)
15 andreas 5878
{
5879
    DECL_TRACER("TPageManager::doBLINK(int port, vector<int>& channels, vector<string>& pars)");
5880
 
5881
    if (pars.size() < 4)
5882
    {
5883
        MSG_WARNING("Command BLINK expects 4 parameters! Command ignored.");
343 andreas 5884
#if TESTMODE == 1
5885
        setAllDone();
5886
#endif
15 andreas 5887
        return;
5888
    }
5889
 
16 andreas 5890
    TError::clear();
15 andreas 5891
    vector<int> sysButtons = { 141, 142, 143, 151, 152, 153, 154, 155, 156, 157, 158 };
193 andreas 5892
    vector<TMap::MAP_T> map = findButtons(0, sysButtons);
15 andreas 5893
 
5894
    if (TError::isError() || map.empty())
5895
    {
5896
        MSG_WARNING("No system buttons found.");
343 andreas 5897
#if TESTMODE == 1
5898
        setAllDone();
5899
#endif
15 andreas 5900
        return;
5901
    }
5902
 
5903
    vector<Button::TButton *> buttons = collectButtons(map);
5904
    vector<Button::TButton *>::iterator mapIter;
5905
 
5906
    for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
5907
    {
5908
        Button::TButton *bt = *mapIter;
5909
        bt->setActive(0);
343 andreas 5910
#if TESTMODE == 1
5911
                if (_gTestMode)
5912
                    _gTestMode->setResult(intToString(bt->getActiveInstance() + 1));
5913
#endif
15 andreas 5914
    }
343 andreas 5915
#if TESTMODE == 1
5916
    setDone();
5917
#endif
15 andreas 5918
}
5919
 
162 andreas 5920
/**
5921
 * Send the version of the panel to the NetLinx. This is the real application
5922
 * version.
5923
 */
127 andreas 5924
void TPageManager::doVER(int, vector<int>&, vector<string>&)
5925
{
5926
    DECL_TRACER("TPageManager::doVER(int, vector<int>&, vector<string>&)");
5927
 
5928
    amx::ANET_SEND scmd;
5929
    scmd.port = 1;
5930
    scmd.channel = 0;
5931
    scmd.msg.assign(string("^VER-")+VERSION_STRING());
5932
    scmd.MC = 0x008c;
5933
 
5934
    if (gAmxNet)
343 andreas 5935
    {
127 andreas 5936
        gAmxNet->sendCommand(scmd);
343 andreas 5937
#if TESTMODE == 1
5938
        __success = true;
347 andreas 5939
 
5940
        if (_gTestMode)
5941
            _gTestMode->setResult(VERSION_STRING());
343 andreas 5942
#endif
5943
    }
127 andreas 5944
    else
5945
        MSG_WARNING("Missing global class TAmxNet. Can't send message!");
343 andreas 5946
#if TESTMODE == 1
5947
    setAllDone();
5948
#endif
127 andreas 5949
}
5950
 
162 andreas 5951
/**
5952
 * Returns the user name used to connect to a SIP server. An empty string is
5953
 * returned if there is no user defined.
5954
 */
279 andreas 5955
#ifndef _NOSIP_
127 andreas 5956
void TPageManager::doWCN(int, vector<int>&, vector<string>&)
5957
{
5958
    DECL_TRACER("TPageManager::doWCN(int, vector<int>&, vector<string>&)");
5959
 
5960
    if (!TConfig::getSIPstatus())
343 andreas 5961
    {
5962
#if TESTMODE == 1
5963
        setAllDone();
5964
#endif
127 andreas 5965
        return;
343 andreas 5966
    }
127 andreas 5967
 
5968
    amx::ANET_SEND scmd;
5969
    scmd.port = 1;
5970
    scmd.channel = 0;
5971
    scmd.msg.assign("^WCN-" + TConfig::getSIPuser());
5972
    scmd.MC = 0x008c;
5973
 
5974
    if (gAmxNet)
343 andreas 5975
    {
127 andreas 5976
        gAmxNet->sendCommand(scmd);
343 andreas 5977
#if TESTMODE == 1
5978
        __success = true;
347 andreas 5979
 
5980
        if (_gTestMode)
5981
            _gTestMode->setResult(TConfig::getSIPuser());
343 andreas 5982
#endif
5983
    }
127 andreas 5984
    else
5985
        MSG_WARNING("Missing global class TAmxNet. Can't send message!");
343 andreas 5986
#if TESTMODE == 1
5987
        setAllDone();
5988
#endif
127 andreas 5989
}
279 andreas 5990
#endif
14 andreas 5991
/**
147 andreas 5992
 * Flip to specified page using the named animation.
5993
 * FIXME: Implement animation for pages.
5994
 */
5995
void TPageManager::doAFP(int, vector<int>&, vector<string>& pars)
5996
{
5997
    DECL_TRACER("TPageManager::doAFP(int, vector<int>&, vector<string>& pars)");
5998
 
5999
    if (pars.size() < 4)
6000
    {
6001
        MSG_ERROR("Less than 4 parameters!");
343 andreas 6002
#if TESTMODE == 1
6003
        setAllDone();
6004
#endif
147 andreas 6005
        return;
6006
    }
6007
 
6008
    TError::clear();
6009
    string pname = pars[0];
6010
//    string ani = pars[1];
6011
//    int origin = atoi(pars[2].c_str());
6012
//    int duration = atoi(pars[3].c_str());
6013
 
6014
    // FIXME: Animation of pages is currently not implemented.
6015
 
6016
    if (!pname.empty())
6017
        setPage(pname);
6018
    else if (mPreviousPage)
6019
        setPage(mPreviousPage);
343 andreas 6020
#if TESTMODE == 1
6021
    if (_gTestMode)
6022
        _gTestMode->setResult(getActualPage()->getName());
6023
 
6024
    setDone();
6025
#endif
147 andreas 6026
}
6027
 
6028
/**
14 andreas 6029
 * Add a specific popup page to a specified popup group if it does not already
6030
 * exist. If the new popup is added to a group which has a popup displayed on
6031
 * the current page along with the new pop-up, the displayed popup will be
6032
 * hidden and the new popup will be displayed.
6033
 */
22 andreas 6034
void TPageManager::doAPG(int, std::vector<int>&, std::vector<std::string>& pars)
11 andreas 6035
{
6036
    DECL_TRACER("TPageManager::doAPG(int port, std::vector<int>& channels, std::vector<std::string>& pars)");
6037
 
6038
    if (pars.size() < 2)
6039
    {
6040
        MSG_ERROR("Less than 2 parameters!");
343 andreas 6041
#if TESTMODE == 1
6042
        setAllDone();
6043
#endif
11 andreas 6044
        return;
6045
    }
6046
 
16 andreas 6047
    TError::clear();
11 andreas 6048
    closeGroup(pars[1]);
14 andreas 6049
 
96 andreas 6050
    TPage *page = nullptr;
6051
    TSubPage *subPage = deliverSubPage(pars[0], &page);
14 andreas 6052
 
11 andreas 6053
    if (!subPage)
6054
    {
6055
        MSG_ERROR("Subpage " << pars[0] << " couldn't either found or created!");
343 andreas 6056
#if TESTMODE == 1
6057
        setAllDone();
6058
#endif
11 andreas 6059
        return;
6060
    }
6061
 
162 andreas 6062
    if (!page)
6063
    {
6064
        MSG_ERROR("There seems to be no page for subpage " << pars[0]);
343 andreas 6065
#if TESTMODE == 1
6066
        setAllDone();
6067
#endif
162 andreas 6068
        return;
6069
    }
6070
 
152 andreas 6071
    page->addSubPage(subPage);
11 andreas 6072
    subPage->setGroup(pars[1]);
14 andreas 6073
    subPage->setZOrder(page->getNextZOrder());
152 andreas 6074
    MSG_DEBUG("Setting new Z-order " << page->getActZOrder() << " on page " << page->getName());
11 andreas 6075
    subPage->show();
343 andreas 6076
#if TESTMODE == 1
347 andreas 6077
    if (_gTestMode)
6078
        _gTestMode->setResult(subPage->getGroupName() + ":" + subPage->getName());
6079
 
343 andreas 6080
    setDone();
6081
#endif
11 andreas 6082
}
6083
 
14 andreas 6084
/**
6085
 * Clear all popup pages from specified popup group.
6086
 */
22 andreas 6087
void TPageManager::doCPG(int, std::vector<int>&, std::vector<std::string>& pars)
11 andreas 6088
{
6089
    DECL_TRACER("TPageManager::doCPG(int port, std::vector<int>& channels, std::vector<std::string>& pars)");
6090
 
6091
    if (pars.size() < 1)
6092
    {
6093
        MSG_ERROR("Expecting 1 parameter but got only 1!");
343 andreas 6094
#if TESTMODE == 1
6095
        setAllDone();
6096
#endif
11 andreas 6097
        return;
6098
    }
6099
 
16 andreas 6100
    TError::clear();
348 andreas 6101
    vector<SUBPAGELIST_T> pageList = mPageList->getSubPageList();
11 andreas 6102
 
83 andreas 6103
    if (pageList.size() > 0)
11 andreas 6104
    {
83 andreas 6105
        vector<SUBPAGELIST_T>::iterator pgIter;
6106
 
6107
        for (pgIter = pageList.begin(); pgIter != pageList.end(); pgIter++)
11 andreas 6108
        {
83 andreas 6109
            if (pgIter->group.compare(pars[0]) == 0)
6110
            {
6111
                pgIter->group.clear();
6112
                TSubPage *pg = getSubPage(pgIter->pageID);
11 andreas 6113
 
83 andreas 6114
                if (pg)
6115
                    pg->setGroup(pgIter->group);
343 andreas 6116
#if TESTMODE == 1
6117
                __success = true;
6118
#endif
83 andreas 6119
            }
11 andreas 6120
        }
6121
    }
343 andreas 6122
#if TESTMODE == 1
6123
    setDone();
6124
#endif
11 andreas 6125
}
6126
 
14 andreas 6127
/**
6128
 * Delete a specific popup page from specified popup group if it exists.
6129
 */
22 andreas 6130
void TPageManager::doDPG(int, std::vector<int>&, std::vector<std::string>& pars)
11 andreas 6131
{
6132
    DECL_TRACER("TPageManager::doDPG(int port, std::vector<int>& channels, std::vector<std::string>& pars)");
6133
 
6134
    if (pars.size() < 2)
6135
    {
6136
        MSG_ERROR("Less than 2 parameters!");
348 andreas 6137
#if TESTMODE == 1
6138
        setAllDone();
6139
#endif
11 andreas 6140
        return;
6141
    }
6142
 
16 andreas 6143
    TError::clear();
11 andreas 6144
    SUBPAGELIST_T listPg = findSubPage(pars[0]);
6145
 
6146
    if (!listPg.isValid)
348 andreas 6147
    {
6148
#if TESTMODE == 1
6149
        setAllDone();
6150
#endif
11 andreas 6151
        return;
348 andreas 6152
    }
11 andreas 6153
 
6154
    if (listPg.group.compare(pars[1]) == 0)
6155
    {
6156
        listPg.group.clear();
6157
        TSubPage *pg = getSubPage(listPg.pageID);
6158
 
6159
        if (pg)
6160
            pg->setGroup(listPg.group);
348 andreas 6161
#if TESTMODE == 1
6162
        __success = true;
6163
#endif
11 andreas 6164
    }
348 andreas 6165
#if TESTMODE == 1
6166
    setDone();
6167
#endif
11 andreas 6168
}
6169
 
14 andreas 6170
/**
15 andreas 6171
 * Set the hide effect for the specified popup page to the named hide effect.
6172
 */
22 andreas 6173
void TPageManager::doPHE(int, vector<int>&, vector<string>& pars)
15 andreas 6174
{
6175
    DECL_TRACER("TPageManager::doPHE(int port, vector<int>& channels, vector<string>& pars)");
6176
 
6177
    if (pars.size() < 2)
6178
    {
6179
        MSG_ERROR("Less than 2 parameters!");
348 andreas 6180
#if TESTMODE == 1
6181
        setAllDone();
6182
#endif
15 andreas 6183
        return;
6184
    }
6185
 
16 andreas 6186
    TError::clear();
96 andreas 6187
    TSubPage *pg = deliverSubPage(pars[0]);
15 andreas 6188
 
6189
    if (!pg)
348 andreas 6190
    {
6191
#if TESTMODE == 1
6192
        setAllDone();
6193
#endif
96 andreas 6194
        return;
348 andreas 6195
    }
15 andreas 6196
 
162 andreas 6197
    if (strCaseCompare(pars[1], "fade") == 0)
15 andreas 6198
        pg->setHideEffect(SE_FADE);
162 andreas 6199
    else if (strCaseCompare(pars[1], "slide to left") == 0)
15 andreas 6200
        pg->setHideEffect(SE_SLIDE_LEFT);
162 andreas 6201
    else if (strCaseCompare(pars[1], "slide to right") == 0)
15 andreas 6202
        pg->setHideEffect(SE_SLIDE_RIGHT);
162 andreas 6203
    else if (strCaseCompare(pars[1], "slide to top") == 0)
15 andreas 6204
        pg->setHideEffect(SE_SLIDE_TOP);
162 andreas 6205
    else if (strCaseCompare(pars[1], "slide to bottom") == 0)
15 andreas 6206
        pg->setHideEffect(SE_SLIDE_BOTTOM);
162 andreas 6207
    else if (strCaseCompare(pars[1], "slide to left fade") == 0)
15 andreas 6208
        pg->setHideEffect(SE_SLIDE_LEFT_FADE);
162 andreas 6209
    else if (strCaseCompare(pars[1], "slide to right fade") == 0)
15 andreas 6210
        pg->setHideEffect(SE_SLIDE_RIGHT_FADE);
162 andreas 6211
    else if (strCaseCompare(pars[1], "slide to top fade") == 0)
15 andreas 6212
        pg->setHideEffect(SE_SLIDE_TOP_FADE);
162 andreas 6213
    else if (strCaseCompare(pars[1], "slide to bottom fade") == 0)
15 andreas 6214
        pg->setHideEffect(SE_SLIDE_BOTTOM_FADE);
6215
    else
6216
        pg->setHideEffect(SE_NONE);
348 andreas 6217
#if TESTMODE == 1
6218
    if (_gTestMode)
6219
        _gTestMode->setResult(intToString(pg->getHideEffect()));
6220
 
6221
    __success = true;
6222
    setAllDone();
6223
#endif
15 andreas 6224
}
6225
 
6226
/**
6227
 * Set the hide effect position. Only 1 coordinate is ever needed for an effect;
6228
 * however, the command will specify both. This command sets the location at
6229
 * which the effect will end at.
6230
 */
22 andreas 6231
void TPageManager::doPHP(int, vector<int>&, vector<string>& pars)
15 andreas 6232
{
6233
    DECL_TRACER("TPageManager::doPHP(int port, vector<int>& channels, vector<string>& pars)");
6234
 
6235
    if (pars.size() < 2)
6236
    {
6237
        MSG_ERROR("Less than 2 parameters!");
348 andreas 6238
#if TESTMODE == 1
6239
        setAllDone();
6240
#endif
15 andreas 6241
        return;
6242
    }
6243
 
16 andreas 6244
    TError::clear();
15 andreas 6245
    size_t pos = pars[1].find(",");
6246
    int x, y;
6247
 
6248
    if (pos == string::npos)
6249
    {
6250
        x = atoi(pars[1].c_str());
6251
        y = 0;
6252
    }
6253
    else
6254
    {
6255
        x = atoi(pars[1].substr(0, pos).c_str());
6256
        y = atoi(pars[1].substr(pos+1).c_str());
6257
    }
6258
 
96 andreas 6259
    TSubPage *pg = deliverSubPage(pars[0]);
15 andreas 6260
 
6261
    if (!pg)
348 andreas 6262
    {
6263
#if TESTMODE == 1
6264
        setAllDone();
6265
#endif
96 andreas 6266
        return;
348 andreas 6267
    }
15 andreas 6268
 
6269
    pg->setHideEndPosition(x, y);
348 andreas 6270
#if TESTMODE == 1
6271
    if (_gTestMode)
6272
    {
6273
        int x, y;
6274
        pg->getHideEndPosition(&x, &y);
6275
        _gTestMode->setResult(intToString(x) + "," + intToString(y));
6276
    }
6277
 
6278
    __success = true;
6279
    setAllDone();
6280
#endif
15 andreas 6281
}
6282
 
6283
/**
6284
 * Set the hide effect time for the specified popup page.
6285
 */
22 andreas 6286
void TPageManager::doPHT(int, vector<int>&, vector<string>& pars)
15 andreas 6287
{
6288
    DECL_TRACER("TPageManager::doPHT(int port, vector<int>& channels, vector<string>& pars)");
6289
 
6290
    if (pars.size() < 2)
6291
    {
6292
        MSG_ERROR("Less than 2 parameters!");
348 andreas 6293
#if TESTMODE == 1
6294
        setAllDone();
6295
#endif
15 andreas 6296
        return;
6297
    }
6298
 
16 andreas 6299
    TError::clear();
96 andreas 6300
    TSubPage *pg = deliverSubPage(pars[0]);
15 andreas 6301
 
6302
    if (!pg)
348 andreas 6303
    {
6304
#if TESTMODE == 1
6305
        setAllDone();
6306
#endif
96 andreas 6307
        return;
348 andreas 6308
    }
15 andreas 6309
 
6310
    pg->setHideTime(atoi(pars[1].c_str()));
348 andreas 6311
#if TESTMODE == 1
6312
    if (_gTestMode)
6313
        _gTestMode->setResult(intToString(pg->getHideTime()));
6314
 
6315
    __success = true;
6316
    setAllDone();
6317
#endif
15 andreas 6318
}
6319
 
6320
/**
14 andreas 6321
 * Close all popups on a specified page. If the page name is empty, the current
6322
 * page is used. Same as the ’Clear Page’ command in TPDesign4.
6323
 */
22 andreas 6324
void TPageManager::doPPA(int, std::vector<int>&, std::vector<std::string>& pars)
11 andreas 6325
{
6326
    DECL_TRACER("TPageManager::doPPA(int port, std::vector<int>& channels, std::vector<std::string>& pars)");
6327
 
16 andreas 6328
    TError::clear();
11 andreas 6329
    TPage *pg;
6330
 
6331
    if (pars.size() == 0)
6332
        pg = getPage(mActualPage);
6333
    else
6334
        pg = getPage(pars[0]);
6335
 
6336
    if (!pg)
348 andreas 6337
    {
6338
#if TESTMODE == 1
6339
        setAllDone();
6340
#endif
11 andreas 6341
        return;
348 andreas 6342
    }
11 andreas 6343
 
12 andreas 6344
    pg->drop();
14 andreas 6345
    pg->resetZOrder();
348 andreas 6346
#if TESTMODE == 1
6347
    setDone();
6348
#endif
11 andreas 6349
}
6350
 
14 andreas 6351
/**
6352
 * Deactivate a specific popup page on either a specified page or the current
6353
 * page. If the page name is empty, the current page is used. If the popup page
6354
 * is part of a group, the whole group is deactivated. This command works in
6355
 * the same way as the ’Hide Popup’ command in TPDesign4.
6356
 */
22 andreas 6357
void TPageManager::doPPF(int, std::vector<int>&, std::vector<std::string>& pars)
12 andreas 6358
{
6359
    DECL_TRACER("TPageManager::doPPF(int port, std::vector<int>& channels, std::vector<std::string>& pars)");
6360
 
6361
    if (pars.size() < 1)
6362
    {
6363
        MSG_ERROR("At least 1 parameter is expected!");
349 andreas 6364
#if TESTMODE == 1
6365
        setAllDone();
6366
#endif
12 andreas 6367
        return;
6368
    }
6369
 
16 andreas 6370
    TError::clear();
14 andreas 6371
    hideSubPage(pars[0]);
335 andreas 6372
#if TESTMODE == 1
6373
    setDone();
6374
#endif
12 andreas 6375
}
6376
 
14 andreas 6377
/**
6378
 * Toggle a specific popup page on either a specified page or the current page.
6379
 * If the page name is empty, the current page is used. Toggling refers to the
6380
 * activating/deactivating (On/Off) of a popup page. This command works in the
6381
 * same way as the ’Toggle Popup’ command in TPDesign4.
6382
 */
22 andreas 6383
void TPageManager::doPPG(int, std::vector<int>&, std::vector<std::string>& pars)
12 andreas 6384
{
6385
    DECL_TRACER("TPageManager::doPPG(int port, std::vector<int>& channels, std::vector<std::string>& pars)");
14 andreas 6386
 
12 andreas 6387
    if (pars.size() < 1)
6388
    {
6389
        MSG_ERROR("At least 1 parameter is expected!");
349 andreas 6390
#if TESTMODE == 1
6391
        setAllDone();
6392
#endif
12 andreas 6393
        return;
6394
    }
6395
 
16 andreas 6396
    TError::clear();
14 andreas 6397
    TPage *page = getPage(mActualPage);
6398
 
6399
    if (!page)
6400
    {
6401
        MSG_ERROR("No active page found! Internal error.");
349 andreas 6402
#if TESTMODE == 1
6403
        setAllDone();
6404
#endif
14 andreas 6405
        return;
6406
    }
6407
 
12 andreas 6408
    TSubPage *pg = getSubPage(pars[0]);
14 andreas 6409
 
12 andreas 6410
    if (!pg)
349 andreas 6411
    {
6412
#if TESTMODE == 1
6413
        setAllDone();
6414
#endif
12 andreas 6415
        return;
349 andreas 6416
    }
14 andreas 6417
 
12 andreas 6418
    if (pg->isVisible())
6419
    {
6420
        pg->drop();
162 andreas 6421
        page->decZOrder();
349 andreas 6422
#if TESTMODE == 1
6423
        setDone();
6424
#endif
12 andreas 6425
        return;
6426
    }
6427
 
6428
    TSubPage *sub = getFirstSubPageGroup(pg->getGroupName());
14 andreas 6429
 
12 andreas 6430
    while(sub)
6431
    {
6432
        if (sub->getGroupName().compare(pg->getGroupName()) == 0 && sub->isVisible())
6433
            sub->drop();
14 andreas 6434
 
12 andreas 6435
        sub = getNextSubPageGroup(pg->getGroupName(), sub);
6436
    }
6437
 
152 andreas 6438
    pg->setZOrder(page->getNextZOrder());
6439
    MSG_DEBUG("Setting new Z-order " << page->getActZOrder() << " on page " << page->getName());
12 andreas 6440
    pg->show();
349 andreas 6441
#if TESTMODE == 1
6442
    setDone();
6443
#endif
12 andreas 6444
}
6445
 
14 andreas 6446
/**
6447
 * Kill refers to the deactivating (Off) of a popup window from all pages. If
6448
 * the pop-up page is part of a group, the whole group is deactivated. This
6449
 * command works in the same way as the 'Clear Group' command in TPDesign 4.
6450
 */
22 andreas 6451
void TPageManager::doPPK(int, std::vector<int>&, std::vector<std::string>& pars)
12 andreas 6452
{
6453
    DECL_TRACER("TPageManager::doPPK(int port, std::vector<int>& channels, std::vector<std::string>& pars)");
14 andreas 6454
 
12 andreas 6455
    if (pars.size() < 1)
6456
    {
6457
        MSG_ERROR("At least 1 parameter is expected!");
349 andreas 6458
#if TESTMODE == 1
6459
        setAllDone();
6460
#endif
12 andreas 6461
        return;
6462
    }
6463
 
16 andreas 6464
    TError::clear();
14 andreas 6465
    TPage *page = getPage(mActualPage);
6466
 
6467
    if (!page)
6468
    {
6469
        MSG_ERROR("No active page found! Internal error.");
349 andreas 6470
#if TESTMODE == 1
6471
        setAllDone();
6472
#endif
14 andreas 6473
        return;
6474
    }
6475
 
12 andreas 6476
    TSubPage *pg = getSubPage(pars[0]);
14 andreas 6477
 
12 andreas 6478
    if (pg)
14 andreas 6479
    {
6480
        pg->drop();
162 andreas 6481
        page->decZOrder();
14 andreas 6482
    }
349 andreas 6483
#if TESTMODE == 1
6484
        setDone();
6485
#endif
12 andreas 6486
}
6487
 
14 andreas 6488
/**
6489
 * Set the modality of a specific popup page to Modal or NonModal.
6490
 * A Modal popup page, when active, only allows you to use the buttons and
6491
 * features on that popup page. All other buttons on the panel page are
6492
 * inactivated.
6493
 */
22 andreas 6494
void TPageManager::doPPM(int, std::vector<int>&, std::vector<std::string>& pars)
12 andreas 6495
{
6496
    DECL_TRACER("TPageManager::doPPM(int port, std::vector<int>& channels, std::vector<std::string>& pars)");
14 andreas 6497
 
12 andreas 6498
    if (pars.size() < 2)
6499
    {
6500
        MSG_ERROR("Expecting 2 parameters!");
349 andreas 6501
#if TESTMODE == 1
6502
        setAllDone();
6503
#endif
12 andreas 6504
        return;
6505
    }
14 andreas 6506
 
16 andreas 6507
    TError::clear();
12 andreas 6508
    TSubPage *pg = getSubPage(pars[0]);
14 andreas 6509
 
12 andreas 6510
    if (pg)
6511
    {
162 andreas 6512
        if (pars[1] == "1" || strCaseCompare(pars[1], "modal") == 0)
12 andreas 6513
            pg->setModal(1);
6514
        else
6515
            pg->setModal(0);
349 andreas 6516
#if TESTMODE == 1
6517
        if (_gTestMode)
6518
            _gTestMode->setResult(pg->isModal() ? "TRUE" : "FALSE");
6519
#endif
12 andreas 6520
    }
349 andreas 6521
#if TESTMODE == 1
6522
        setAllDone();
6523
#endif
12 andreas 6524
}
6525
 
14 andreas 6526
/**
6527
 * Activate a specific popup page to launch on either a specified page or the
6528
 * current page. If the page name is empty, the current page is used. If the
6529
 * popup page is already on, do not re-draw it. This command works in the same
6530
 * way as the ’Show Popup’ command in TPDesign4.
6531
 */
22 andreas 6532
void TPageManager::doPPN(int, std::vector<int>&, std::vector<std::string>& pars)
12 andreas 6533
{
6534
    DECL_TRACER("TPageManager::doPPN(int port, std::vector<int>& channels, std::vector<std::string>& pars)");
6535
 
6536
    if (pars.size() < 1)
6537
    {
6538
        MSG_ERROR("At least 1 parameter is expected!");
349 andreas 6539
#if TESTMODE == 1
6540
        setAllDone();
6541
#endif
12 andreas 6542
        return;
6543
    }
6544
 
16 andreas 6545
    TError::clear();
14 andreas 6546
    showSubPage(pars[0]);
349 andreas 6547
#if TESTMODE == 1
6548
    setDone();
6549
#endif
12 andreas 6550
}
6551
 
14 andreas 6552
/**
15 andreas 6553
 * Set a specific popup page to timeout within a specified time. If timeout is
6554
 * empty, popup page will clear the timeout.
6555
 */
22 andreas 6556
void TPageManager::doPPT(int, vector<int>&, vector<string>& pars)
15 andreas 6557
{
6558
    DECL_TRACER("TPageManager::doPPT(int port, vector<int>& channels, vector<string>& pars)");
6559
 
6560
    if (pars.size() < 2)
6561
    {
6562
        MSG_ERROR("Expecting 2 parameters!");
351 andreas 6563
#if TESTMODE == 1
6564
        setAllDone();
6565
#endif
15 andreas 6566
        return;
6567
    }
6568
 
16 andreas 6569
    TError::clear();
96 andreas 6570
    TSubPage *pg = deliverSubPage(pars[0]);
15 andreas 6571
 
6572
    if (!pg)
351 andreas 6573
    {
6574
#if TESTMODE == 1
6575
        setAllDone();
6576
#endif
96 andreas 6577
        return;
351 andreas 6578
    }
15 andreas 6579
 
6580
    pg->setTimeout(atoi(pars[1].c_str()));
351 andreas 6581
#if TESTMODE == 1
6582
    if (_gTestMode)
6583
        _gTestMode->setResult(intToString(pg->getTimeout()));
6584
 
6585
    __success = true;
6586
    setAllDone();
6587
#endif
15 andreas 6588
}
6589
 
6590
/**
14 andreas 6591
 * Close all popups on all pages. This command works in the same way as the
6592
 * 'Clear All' command in TPDesign 4.
6593
 */
22 andreas 6594
void TPageManager::doPPX(int, std::vector<int>&, std::vector<std::string>&)
12 andreas 6595
{
6596
    DECL_TRACER("TPageManager::doPPX(int port, std::vector<int>& channels, std::vector<std::string>& pars)");
6597
 
16 andreas 6598
    TError::clear();
12 andreas 6599
    PCHAIN_T *chain = mPchain;
14 andreas 6600
 
12 andreas 6601
    while(chain)
6602
    {
6603
        TSubPage *sub = chain->page->getFirstSubPage();
14 andreas 6604
 
12 andreas 6605
        while (sub)
6606
        {
351 andreas 6607
            MSG_DEBUG("Dropping subpage " << sub->getNumber() << ", \"" << sub->getName() << "\".");
12 andreas 6608
            sub->drop();
6609
            sub = chain->page->getNextSubPage();
6610
        }
14 andreas 6611
 
12 andreas 6612
        chain = chain->next;
6613
    }
14 andreas 6614
 
6615
    TPage *page = getPage(mActualPage);
6616
 
6617
    if (!page)
6618
    {
6619
        MSG_ERROR("No active page found! Internal error.");
351 andreas 6620
#if TESTMODE == 1
6621
        setAllDone();
6622
#endif
14 andreas 6623
        return;
6624
    }
6625
 
6626
    page->resetZOrder();
351 andreas 6627
#if TESTMODE == 1
6628
    setDone();
6629
#endif
12 andreas 6630
}
6631
 
14 andreas 6632
/**
15 andreas 6633
 * Set the show effect for the specified popup page to the named show effect.
6634
 */
22 andreas 6635
void TPageManager::doPSE(int, vector<int>&, vector<string>& pars)
15 andreas 6636
{
6637
    DECL_TRACER("TPageManager::doPSE(int port, vector<int>& channels, vector<string>& pars)");
6638
 
6639
    if (pars.size() < 2)
6640
    {
6641
        MSG_ERROR("Less than 2 parameters!");
351 andreas 6642
#if TESTMODE == 1
6643
        setAllDone();
6644
#endif
15 andreas 6645
        return;
6646
    }
6647
 
16 andreas 6648
    TError::clear();
96 andreas 6649
    TSubPage *pg = deliverSubPage(pars[0]);
15 andreas 6650
 
6651
    if (!pg)
351 andreas 6652
    {
6653
#if TESTMODE == 1
6654
        setAllDone();
6655
#endif
96 andreas 6656
        return;
351 andreas 6657
    }
15 andreas 6658
 
162 andreas 6659
    if (strCaseCompare(pars[1], "fade") == 0)
15 andreas 6660
        pg->setShowEffect(SE_FADE);
162 andreas 6661
    else if (strCaseCompare(pars[1], "slide to left") == 0)
15 andreas 6662
        pg->setShowEffect(SE_SLIDE_LEFT);
162 andreas 6663
    else if (strCaseCompare(pars[1], "slide to right") == 0)
15 andreas 6664
        pg->setShowEffect(SE_SLIDE_RIGHT);
162 andreas 6665
    else if (strCaseCompare(pars[1], "slide to top") == 0)
15 andreas 6666
        pg->setShowEffect(SE_SLIDE_TOP);
162 andreas 6667
    else if (strCaseCompare(pars[1], "slide to bottom") == 0)
15 andreas 6668
        pg->setShowEffect(SE_SLIDE_BOTTOM);
162 andreas 6669
    else if (strCaseCompare(pars[1], "slide to left fade") == 0)
15 andreas 6670
        pg->setShowEffect(SE_SLIDE_LEFT_FADE);
162 andreas 6671
    else if (strCaseCompare(pars[1], "slide to right fade") == 0)
15 andreas 6672
        pg->setShowEffect(SE_SLIDE_RIGHT_FADE);
162 andreas 6673
    else if (strCaseCompare(pars[1], "slide to top fade") == 0)
15 andreas 6674
        pg->setShowEffect(SE_SLIDE_TOP_FADE);
162 andreas 6675
    else if (strCaseCompare(pars[1], "slide to bottom fade") == 0)
15 andreas 6676
        pg->setShowEffect(SE_SLIDE_BOTTOM_FADE);
6677
    else
6678
        pg->setShowEffect(SE_NONE);
351 andreas 6679
#if TESTMODE == 1
6680
    if (_gTestMode)
6681
        _gTestMode->setResult(intToString(pg->getShowEffect()));
6682
 
6683
    __success = true;
6684
    setAllDone();
6685
#endif
15 andreas 6686
}
6687
 
162 andreas 6688
/**
6689
 * Set the show effect position. Only 1 coordinate is ever needed for an effect;
6690
 * however, the command will specify both. This command sets the location at
6691
 * which the effect will begin.
6692
 */
22 andreas 6693
void TPageManager::doPSP(int, vector<int>&, vector<string>& pars)
15 andreas 6694
{
6695
    DECL_TRACER("TPageManager::doPSP(int port, vector<int>& channels, vector<string>& pars)");
6696
 
6697
    if (pars.size() < 2)
6698
    {
6699
        MSG_ERROR("Less than 2 parameters!");
351 andreas 6700
#if TESTMODE == 1
6701
        setAllDone();
6702
#endif
15 andreas 6703
        return;
6704
    }
6705
 
16 andreas 6706
    TError::clear();
15 andreas 6707
    size_t pos = pars[1].find(",");
6708
    int x, y;
6709
 
6710
    if (pos == string::npos)
6711
    {
6712
        x = atoi(pars[1].c_str());
6713
        y = 0;
6714
    }
6715
    else
6716
    {
6717
        x = atoi(pars[1].substr(0, pos).c_str());
6718
        y = atoi(pars[1].substr(pos+1).c_str());
6719
    }
6720
 
96 andreas 6721
    TSubPage *pg = deliverSubPage(pars[0]);
15 andreas 6722
 
6723
    if (!pg)
351 andreas 6724
    {
6725
#if TESTMODE == 1
6726
        setAllDone();
6727
#endif
96 andreas 6728
        return;
351 andreas 6729
    }
15 andreas 6730
 
6731
    pg->setShowEndPosition(x, y);
351 andreas 6732
#if TESTMODE == 1
6733
    pg->getShowEndPosition(&x, &y);
6734
 
6735
    if (_gTestMode)
6736
        _gTestMode->setResult(intToString(x) + "," + intToString(y));
6737
 
6738
    __success = true;
6739
    setAllDone();
6740
#endif
15 andreas 6741
}
6742
 
6743
/**
6744
 * Set the show effect time for the specified popup page.
6745
 */
22 andreas 6746
void TPageManager::doPST(int, vector<int>&, vector<string>& pars)
15 andreas 6747
{
6748
    DECL_TRACER("TPageManager::doPST(int port, vector<int>& channels, vector<string>& pars)");
6749
 
6750
    if (pars.size() < 2)
6751
    {
6752
        MSG_ERROR("Less than 2 parameters!");
351 andreas 6753
#if TESTMODE == 1
6754
        setAllDone();
6755
#endif
15 andreas 6756
        return;
6757
    }
6758
 
16 andreas 6759
    TError::clear();
96 andreas 6760
    TSubPage *pg = deliverSubPage(pars[0]);
15 andreas 6761
 
6762
    if (!pg)
351 andreas 6763
    {
6764
#if TESTMODE == 1
6765
        setAllDone();
6766
#endif
96 andreas 6767
        return;
351 andreas 6768
    }
15 andreas 6769
 
6770
    pg->setShowTime(atoi(pars[1].c_str()));
351 andreas 6771
#if TESTMODE == 1
6772
    if (_gTestMode)
6773
        _gTestMode->setResult(intToString(pg->getShowTime()));
6774
 
6775
    __success = 1;
6776
    setAllDone();
6777
#endif
15 andreas 6778
}
6779
 
6780
/**
14 andreas 6781
 * Flips to a page with a specified page name. If the page is currently active,
6782
 * it will not redraw the page.
6783
 */
22 andreas 6784
void TPageManager::doPAGE(int, std::vector<int>&, std::vector<std::string>& pars)
12 andreas 6785
{
6786
    DECL_TRACER("TPageManager::doPAGE(int port, std::vector<int>& channels, std::vector<std::string>& pars)");
14 andreas 6787
 
15 andreas 6788
    if (pars.empty())
6789
    {
6790
        MSG_WARNING("Got no page parameter!");
351 andreas 6791
#if TESTMODE == 1
6792
        setAllDone();
6793
#endif
15 andreas 6794
        return;
6795
    }
14 andreas 6796
 
16 andreas 6797
    TError::clear();
15 andreas 6798
    setPage(pars[0]);
351 andreas 6799
#if TESTMODE == 1
6800
    if (_gTestMode)
6801
        _gTestMode->setResult(intToString(getActualPageNumber()));
6802
 
6803
    setDone();
6804
#endif
15 andreas 6805
}
6806
 
6807
/**
38 andreas 6808
 * @brief TPageManager::doANI Run a button animation (in 1/10 second).
6809
 * Syntax:
6810
 *      ^ANI-<vt addr range>,<start state>,<end state>,<time>
6811
 * Variable:
6812
 *      variable text address range = 1 - 4000.
6813
 *      start state = Beginning of button state (0= current state).
6814
 *      end state = End of button state.
6815
 *      time = In 1/10 second intervals.
6816
 * Example:
6817
 *      SEND_COMMAND Panel,"'^ANI-500,1,25,100'"
6818
 * Runs a button animation at text range 500 from state 1 to state 25 for 10 seconds.
6819
 *
6820
 * @param port      The port number
6821
 * @param channels  The channels of the buttons
6822
 * @param pars      The parameters
6823
 */
6824
void TPageManager::doANI(int port, std::vector<int> &channels, std::vector<std::string> &pars)
6825
{
6826
    DECL_TRACER("TPageManager::doANI(int port, std::vector<int> &channels, std::vector<std::string> &pars)");
6827
 
6828
    if (pars.size() < 3)
6829
    {
6830
        MSG_ERROR("Expecting 3 parameters but got " << pars.size() << "! Ignoring command.");
6831
        return;
6832
    }
6833
 
6834
    TError::clear();
6835
    int stateStart = atoi(pars[0].c_str());
6836
    int endState = atoi(pars[1].c_str());
6837
    int runTime = atoi(pars[2].c_str());
6838
 
193 andreas 6839
    vector<TMap::MAP_T> map = findButtons(port, channels);
38 andreas 6840
 
6841
    if (TError::isError() || map.empty())
6842
        return;
6843
 
6844
    vector<Button::TButton *> buttons = collectButtons(map);
6845
 
83 andreas 6846
    if (buttons.size() > 0)
38 andreas 6847
    {
83 andreas 6848
        vector<Button::TButton *>::iterator mapIter;
6849
 
6850
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
6851
        {
6852
            Button::TButton *bt = *mapIter;
6853
            bt->startAnimation(stateStart, endState, runTime);
6854
        }
38 andreas 6855
    }
351 andreas 6856
#if TESTMODE == 1
6857
    if (_gTestMode)
6858
        _gTestMode->setResult(intToString(stateStart) + "," + intToString(endState) + "," + intToString(runTime));
6859
 
6860
    setDone();
6861
#endif
38 andreas 6862
}
6863
 
6864
/**
15 andreas 6865
 * Add page flip action to a button if it does not already exist.
6866
 */
6867
void TPageManager::doAPF(int port, vector<int>& channels, vector<string>& pars)
6868
{
6869
    DECL_TRACER("TPageManager::doAPF(int port, vector<int>& channels, vector<string>& pars)");
6870
 
6871
    if (pars.size() < 2)
6872
    {
6873
        MSG_ERROR("Expecting 2 parameters but got " << pars.size() << "! Ignoring command.");
351 andreas 6874
#if TESTMODE == 1
6875
        setAllDone();
6876
#endif
14 andreas 6877
        return;
15 andreas 6878
    }
14 andreas 6879
 
16 andreas 6880
    TError::clear();
15 andreas 6881
    string action = pars[0];
6882
    string pname = pars[1];
14 andreas 6883
 
193 andreas 6884
    vector<TMap::MAP_T> map = findButtons(port, channels);
14 andreas 6885
 
15 andreas 6886
    if (TError::isError() || map.empty())
351 andreas 6887
    {
6888
#if TESTMODE == 1
6889
        setAllDone();
6890
#endif
15 andreas 6891
        return;
351 andreas 6892
    }
15 andreas 6893
 
6894
    vector<Button::TButton *> buttons = collectButtons(map);
6895
 
83 andreas 6896
    if (buttons.size() > 0)
12 andreas 6897
    {
83 andreas 6898
        vector<Button::TButton *>::iterator mapIter;
6899
 
6900
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
6901
        {
6902
            Button::TButton *bt = *mapIter;
6903
            bt->addPushFunction(action, pname);
6904
        }
15 andreas 6905
    }
351 andreas 6906
#if TESTMODE == 1
6907
    if (_gTestMode)
6908
        _gTestMode->setResult(toUpper(action) + "," + toUpper(pname));
6909
 
6910
    __success = true;
6911
    setAllDone();
6912
#endif
15 andreas 6913
}
12 andreas 6914
 
15 andreas 6915
/**
43 andreas 6916
 * Append non-unicode text.
6917
 */
6918
void TPageManager::doBAT(int port, vector<int> &channels, vector<string> &pars)
6919
{
6920
    DECL_TRACER("TPageManager::doBAT(int port, vector<int> &channels, vector<string> &pars)");
6921
 
6922
    if (pars.size() < 1)
6923
    {
6924
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
330 andreas 6925
#if TESTMODE == 1
334 andreas 6926
        setAllDone();
330 andreas 6927
#endif
43 andreas 6928
        return;
6929
    }
6930
 
6931
    TError::clear();
6932
    int btState = atoi(pars[0].c_str());
6933
    string text;
6934
 
6935
    if (pars.size() > 1)
6936
        text = pars[1];
6937
 
193 andreas 6938
    vector<TMap::MAP_T> map = findButtons(port, channels);
43 andreas 6939
 
6940
    if (TError::isError() || map.empty())
330 andreas 6941
    {
6942
#if TESTMODE == 1
334 andreas 6943
        setAllDone();
330 andreas 6944
#endif
43 andreas 6945
        return;
330 andreas 6946
    }
43 andreas 6947
 
6948
    vector<Button::TButton *> buttons = collectButtons(map);
6949
 
162 andreas 6950
    if (buttons.empty())
330 andreas 6951
    {
6952
#if TESTMODE == 1
334 andreas 6953
        setAllDone();
330 andreas 6954
#endif
162 andreas 6955
        return;
330 andreas 6956
    }
162 andreas 6957
 
6958
    vector<Button::TButton *>::iterator mapIter;
6959
 
6960
    for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
43 andreas 6961
    {
162 andreas 6962
        Button::TButton *bt = *mapIter;
43 andreas 6963
 
331 andreas 6964
        bt->appendText(text, btState - 1);
330 andreas 6965
#if TESTMODE == 1
331 andreas 6966
        if (_gTestMode)
330 andreas 6967
        {
331 andreas 6968
            int st = (btState > 0 ? (btState - 1) : 0);
6969
            _gTestMode->setResult(bt->getText(st));
333 andreas 6970
        }
330 andreas 6971
 
331 andreas 6972
        __success = true;
330 andreas 6973
#endif
43 andreas 6974
    }
334 andreas 6975
#if TESTMODE == 1
6976
    setDone();
6977
#endif
43 andreas 6978
}
6979
 
6980
/**
60 andreas 6981
 * @brief Append unicode text. Same format as ^UNI.
6982
 * This command allows to set up to 50 characters of ASCII code. The unicode
6983
 * characters must be set as hex numbers.
6984
 */
6985
void TPageManager::doBAU(int port, vector<int>& channels, vector<string>& pars)
6986
{
6987
    DECL_TRACER("TPageManager::doBAU(int port, vector<int>& channels, vector<string>& pars)");
6988
 
6989
    if (pars.size() < 1)
6990
    {
6991
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
351 andreas 6992
#if TESTMODE == 1
6993
        setAllDone();
6994
#endif
60 andreas 6995
        return;
6996
    }
6997
 
6998
    TError::clear();
6999
    int btState = atoi(pars[0].c_str());
7000
    string text;
7001
    char ch[3];
7002
 
331 andreas 7003
    if (pars.size() > 1)
7004
        text = pars[1];
7005
 
7006
    if ((text.size() % 4) == 0)
60 andreas 7007
    {
162 andreas 7008
        try
60 andreas 7009
        {
162 andreas 7010
            text = pars[1];
331 andreas 7011
            MSG_DEBUG("Processing UTF16 string: " << text);
162 andreas 7012
            // Because the unicode characters are hex numbers, we scan the text
7013
            // and convert the hex numbers into real numbers.
7014
            size_t len = text.length();
7015
            bool inHex = false;
7016
            int lastChar = 0;
331 andreas 7017
            uint16_t *numstr = new uint16_t[len / 4];
162 andreas 7018
            int uniPos = 0;
331 andreas 7019
            int cntCount = 0;
60 andreas 7020
 
162 andreas 7021
            for (size_t i = 0; i < len; i++)
60 andreas 7022
            {
162 andreas 7023
                int c = text.at(i);
60 andreas 7024
 
162 andreas 7025
                if (!inHex && isHex(c))
7026
                {
7027
                    inHex = true;
7028
                    lastChar = c;
7029
                    continue;
7030
                }
7031
 
7032
                if (inHex && !isHex(c))
7033
                    break;
7034
 
7035
                if (inHex && isHex(c))
7036
                {
7037
                    ch[0] = lastChar;
7038
                    ch[1] = c;
7039
                    ch[2] = 0;
7040
                    uint16_t num = (uint16_t)strtol(ch, NULL, 16);
331 andreas 7041
 
7042
                    if ((cntCount % 2) != 0)
7043
                    {
7044
                        numstr[uniPos] |= num;
7045
                        uniPos++;
7046
                    }
7047
                    else
7048
                        numstr[uniPos] = (num << 8) & 0xff00;
7049
 
7050
                    cntCount++;
162 andreas 7051
                    inHex = false;
7052
 
7053
                    if (uniPos >= 50)
7054
                        break;
331 andreas 7055
                }
7056
            }
162 andreas 7057
 
331 andreas 7058
            text.clear();
7059
            // Here we make from the real numbers a UTF8 string
7060
            for (size_t i = 0; i < len / 4; ++i)
7061
            {
7062
                if (numstr[i] <= 0x00ff)
7063
                {
7064
                    ch[0] = numstr[i];
7065
                    ch[1] = 0;
7066
                    text.append(ch);
162 andreas 7067
                }
331 andreas 7068
                else
7069
                {
7070
                    ch[0] = (numstr[i] >> 8) & 0x00ff;
7071
                    ch[1] = numstr[i] & 0x00ff;
7072
                    ch[2] = 0;
7073
                    text.append(ch);
7074
                }
60 andreas 7075
            }
7076
 
331 andreas 7077
            delete[] numstr;
60 andreas 7078
        }
162 andreas 7079
        catch (std::exception const & e)
7080
        {
7081
            MSG_ERROR("Character conversion error: " << e.what());
351 andreas 7082
#if TESTMODE == 1
7083
            setAllDone();
7084
#endif
162 andreas 7085
            return;
7086
        }
60 andreas 7087
    }
331 andreas 7088
    else
7089
    {
7090
        MSG_WARNING("No or invalid UTF16 string: " << text);
351 andreas 7091
#if TESTMODE == 1
7092
        setAllDone();
7093
#endif
331 andreas 7094
        return;
7095
    }
60 andreas 7096
 
193 andreas 7097
    vector<TMap::MAP_T> map = findButtons(port, channels);
60 andreas 7098
 
7099
    if (TError::isError() || map.empty())
351 andreas 7100
    {
7101
#if TESTMODE == 1
7102
        setAllDone();
7103
#endif
60 andreas 7104
        return;
351 andreas 7105
    }
60 andreas 7106
 
7107
    vector<Button::TButton *> buttons = collectButtons(map);
7108
 
83 andreas 7109
    if (buttons.size() > 0)
60 andreas 7110
    {
83 andreas 7111
        vector<Button::TButton *>::iterator mapIter;
60 andreas 7112
 
83 andreas 7113
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
60 andreas 7114
        {
83 andreas 7115
            Button::TButton *bt = *mapIter;
60 andreas 7116
 
331 andreas 7117
            bt->appendText(text, btState - 1);
330 andreas 7118
#if TESTMODE == 1
331 andreas 7119
            if (_gTestMode)
7120
                _gTestMode->setResult(bt->getText(btState - 1));
330 andreas 7121
 
331 andreas 7122
            __success = true;
330 andreas 7123
#endif
60 andreas 7124
        }
7125
    }
330 andreas 7126
#if TESTMODE == 1
334 andreas 7127
    setDone();
330 andreas 7128
#endif
60 andreas 7129
}
7130
 
7131
/**
43 andreas 7132
 * @brief TPageManager::doBCB Set the border color.
7133
 * Set the border color to the specified color. Only if the specified border
7134
 * color is not the same as the current color.
7135
 * Note: Color can be assigned by color name (without spaces), number or
7136
 * R,G,B value (RRGGBB or RRGGBBAA).
7137
 */
7138
void TPageManager::doBCB(int port, vector<int> &channels, vector<string> &pars)
7139
{
7140
    DECL_TRACER("TPageManager::doBCB(int port, vector<int> &channels, vector<string> &pars)");
7141
 
7142
    if (pars.size() < 1)
7143
    {
7144
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
351 andreas 7145
#if TESTMODE == 1
7146
        setAllDone();
7147
#endif
43 andreas 7148
        return;
7149
    }
7150
 
7151
    TError::clear();
7152
    int btState = atoi(pars[0].c_str());
7153
    string color;
7154
 
7155
    if (pars.size() > 1)
7156
        color = pars[1];
7157
 
193 andreas 7158
    vector<TMap::MAP_T> map = findButtons(port, channels);
43 andreas 7159
 
7160
    if (TError::isError() || map.empty())
351 andreas 7161
    {
7162
#if TESTMODE == 1
7163
        setAllDone();
7164
#endif
43 andreas 7165
        return;
351 andreas 7166
    }
43 andreas 7167
 
7168
    vector<Button::TButton *> buttons = collectButtons(map);
7169
 
83 andreas 7170
    if (buttons.size() > 0)
43 andreas 7171
    {
83 andreas 7172
        vector<Button::TButton *>::iterator mapIter;
43 andreas 7173
 
83 andreas 7174
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
43 andreas 7175
        {
83 andreas 7176
            Button::TButton *bt = *mapIter;
351 andreas 7177
            bt->setBorderColor(color, btState - 1);
7178
#if TESTMODE == 1
7179
            if (_gTestMode)
7180
                _gTestMode->setResult(bt->getBorderColor(btState == 0 ? 0 : btState - 1));
7181
#endif
43 andreas 7182
        }
7183
    }
351 andreas 7184
#if TESTMODE == 1
7185
    setDone();
7186
#endif
43 andreas 7187
}
60 andreas 7188
 
351 andreas 7189
/*
7190
 * Get the border color and send it as a custom event.
7191
 */
82 andreas 7192
void TPageManager::getBCB(int port, vector<int> &channels, vector<string> &pars)
7193
{
7194
    DECL_TRACER("TPageManager::getBCB(int port, vector<int> &channels, vector<string> &pars)");
7195
 
7196
    if (pars.size() < 1)
7197
    {
7198
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
351 andreas 7199
#if TESTMODE == 1
7200
        setAllDone();
7201
#endif
82 andreas 7202
        return;
7203
    }
7204
 
7205
    TError::clear();
7206
    int btState = atoi(pars[0].c_str());
7207
    string color;
7208
 
193 andreas 7209
    vector<TMap::MAP_T> map = findButtons(port, channels);
82 andreas 7210
 
7211
    if (TError::isError() || map.empty())
351 andreas 7212
    {
7213
#if TESTMODE == 1
7214
        setAllDone();
7215
#endif
82 andreas 7216
        return;
351 andreas 7217
    }
82 andreas 7218
 
7219
    vector<Button::TButton *> buttons = collectButtons(map);
7220
 
351 andreas 7221
    if (buttons.empty())
82 andreas 7222
    {
351 andreas 7223
#if TESTMODE == 1
7224
        setAllDone();
7225
#endif
7226
        return;
7227
    }
82 andreas 7228
 
351 andreas 7229
    vector<Button::TButton *>::iterator iter;
7230
 
7231
    for (iter = buttons.begin(); iter != buttons.end(); ++iter)
7232
    {
7233
        Button::TButton *bt = *iter;
7234
 
110 andreas 7235
        if (btState == 0)       // All instances?
82 andreas 7236
        {
110 andreas 7237
            int bst = bt->getNumberInstances();
82 andreas 7238
 
110 andreas 7239
            for (int i = 0; i < bst; i++)
82 andreas 7240
            {
110 andreas 7241
                color = bt->getBorderColor(i);
82 andreas 7242
 
110 andreas 7243
                if (color.empty())
7244
                    continue;
83 andreas 7245
 
300 andreas 7246
                sendCustomEvent(i + 1, (int)color.length(), 0, color, 1011, bt->getChannelPort(), bt->getChannelNumber());
351 andreas 7247
#if TESTMODE == 1
7248
                __success = true;
7249
 
7250
                if (_gTestMode)
7251
                    _gTestMode->setResult(color);
7252
#endif
83 andreas 7253
            }
110 andreas 7254
        }
7255
        else
7256
        {
7257
            color = bt->getBorderColor(btState - 1);
83 andreas 7258
 
110 andreas 7259
            if (color.empty())
351 andreas 7260
                continue;
82 andreas 7261
 
300 andreas 7262
            sendCustomEvent(btState, (int)color.length(), 0, color, 1011, bt->getChannelPort(), bt->getChannelNumber());
351 andreas 7263
#if TESTMODE == 1
7264
            __success = true;
7265
 
7266
            if (_gTestMode)
7267
                _gTestMode->setResult(color);
7268
#endif
82 andreas 7269
        }
7270
    }
351 andreas 7271
#if TESTMODE == 1
7272
    setAllDone();
7273
#endif
82 andreas 7274
}
7275
 
43 andreas 7276
/**
60 andreas 7277
 * @brief Set the fill color to the specified color.
7278
 * Only if the specified fill color is not the same as the current color.
7279
 * Note: Color can be assigned by color name (without spaces), number or R,G,B value (RRGGBB or RRGGBBAA).
15 andreas 7280
 */
60 andreas 7281
void TPageManager::doBCF(int port, vector<int>& channels, vector<std::string>& pars)
15 andreas 7282
{
60 andreas 7283
    DECL_TRACER("TPageManager::doBCF(int port, vector<int>& channels, vector<std::string>& pars)");
15 andreas 7284
 
60 andreas 7285
    if (pars.size() < 1)
15 andreas 7286
    {
60 andreas 7287
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
351 andreas 7288
#if TESTMODE == 1
7289
        setAllDone();
7290
#endif
12 andreas 7291
        return;
7292
    }
14 andreas 7293
 
16 andreas 7294
    TError::clear();
15 andreas 7295
    int btState = atoi(pars[0].c_str());
60 andreas 7296
    string color;
14 andreas 7297
 
60 andreas 7298
    if (pars.size() > 1)
7299
        color = pars[1];
7300
 
193 andreas 7301
    vector<TMap::MAP_T> map = findButtons(port, channels);
15 andreas 7302
 
7303
    if (TError::isError() || map.empty())
351 andreas 7304
    {
7305
#if TESTMODE == 1
7306
        setAllDone();
7307
#endif
15 andreas 7308
        return;
351 andreas 7309
    }
15 andreas 7310
 
7311
    vector<Button::TButton *> buttons = collectButtons(map);
7312
 
83 andreas 7313
    if (buttons.size() > 0)
15 andreas 7314
    {
83 andreas 7315
        vector<Button::TButton *>::iterator mapIter;
15 andreas 7316
 
83 andreas 7317
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
15 andreas 7318
        {
83 andreas 7319
            Button::TButton *bt = *mapIter;
351 andreas 7320
            bt->setFillColor(color, btState - 1);
7321
#if TESTMODE == 1
7322
            if (_gTestMode)
7323
                _gTestMode->setResult(bt->getFillColor(btState == 0 ? 0 : btState - 1));
7324
#endif
15 andreas 7325
        }
7326
    }
351 andreas 7327
#if TESTMODE == 1
7328
    setDone();
7329
#endif
12 andreas 7330
}
7331
 
351 andreas 7332
/*
7333
 * Get the fill color and send it via a custom event to the NetLinx.
7334
 */
82 andreas 7335
void TPageManager::getBCF(int port, vector<int> &channels, vector<string> &pars)
7336
{
7337
    DECL_TRACER("TPageManager::getBCF(int port, vector<int> &channels, vector<string> &pars)");
7338
 
7339
    if (pars.size() < 1)
7340
    {
7341
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
351 andreas 7342
#if TESTMODE == 1
7343
        setAllDone();
7344
#endif
82 andreas 7345
        return;
7346
    }
7347
 
7348
    TError::clear();
7349
    int btState = atoi(pars[0].c_str());
7350
    string color;
7351
 
193 andreas 7352
    vector<TMap::MAP_T> map = findButtons(port, channels);
82 andreas 7353
 
7354
    if (TError::isError() || map.empty())
351 andreas 7355
    {
7356
#if TESTMODE == 1
7357
        setAllDone();
7358
#endif
82 andreas 7359
        return;
351 andreas 7360
    }
82 andreas 7361
 
7362
    vector<Button::TButton *> buttons = collectButtons(map);
7363
 
351 andreas 7364
    if (buttons.empty())
82 andreas 7365
    {
351 andreas 7366
#if TESTMODE == 1
7367
        setAllDone();
7368
#endif
7369
        return;
7370
    }
82 andreas 7371
 
351 andreas 7372
    vector<Button::TButton *>::iterator iter;
7373
 
7374
    for (iter = buttons.begin(); iter != buttons.end(); ++iter)
7375
    {
7376
        Button::TButton *bt = *iter;
7377
 
110 andreas 7378
        if (btState == 0)       // All instances?
82 andreas 7379
        {
110 andreas 7380
            int bst = bt->getNumberInstances();
82 andreas 7381
 
110 andreas 7382
            for (int i = 0; i < bst; i++)
82 andreas 7383
            {
110 andreas 7384
                color = bt->getFillColor(i);
82 andreas 7385
 
110 andreas 7386
                if (color.empty())
7387
                    continue;
82 andreas 7388
 
300 andreas 7389
                sendCustomEvent(i + 1, (int)color.length(), 0, color, 1012, bt->getChannelPort(), bt->getChannelNumber());
351 andreas 7390
#if TESTMODE == 1
7391
                __success = true;
7392
 
7393
                if (_gTestMode)
7394
                    _gTestMode->setResult(color);
7395
#endif
83 andreas 7396
            }
82 andreas 7397
        }
110 andreas 7398
        else
7399
        {
7400
            color = bt->getFillColor(btState-1);
351 andreas 7401
 
7402
            if (color.empty())
7403
                continue;
7404
 
300 andreas 7405
            sendCustomEvent(btState, (int)color.length(), 0, color, 1012, bt->getChannelPort(), bt->getChannelNumber());
351 andreas 7406
#if TESTMODE == 1
7407
            __success = true;
7408
 
7409
            if (_gTestMode)
7410
                _gTestMode->setResult(color);
7411
#endif
110 andreas 7412
        }
82 andreas 7413
    }
351 andreas 7414
#if TESTMODE == 1
7415
    setAllDone();
7416
#endif
82 andreas 7417
}
7418
 
60 andreas 7419
/**
7420
 * @brief Set the text color to the specified color.
7421
 * Only if the specified text color is not the same as the current color.
7422
 * Note: Color can be assigned by color name (without spaces), number or R,G,B value (RRGGBB or RRGGBBAA).
7423
 */
7424
void TPageManager::doBCT(int port, vector<int>& channels, vector<string>& pars)
18 andreas 7425
{
60 andreas 7426
    DECL_TRACER("TPageManager::doBCT(int port, vector<int>& channels, vector<string>& pars)");
7427
 
7428
    if (pars.size() < 1)
7429
    {
7430
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
351 andreas 7431
#if TESTMODE == 1
7432
        setAllDone();
7433
#endif
60 andreas 7434
        return;
7435
    }
7436
 
7437
    TError::clear();
7438
    int btState = atoi(pars[0].c_str());
7439
    string color;
7440
 
7441
    if (pars.size() > 1)
7442
        color = pars[1];
7443
 
193 andreas 7444
    vector<TMap::MAP_T> map = findButtons(port, channels);
60 andreas 7445
 
7446
    if (TError::isError() || map.empty())
351 andreas 7447
    {
7448
#if TESTMODE == 1
7449
        setAllDone();
7450
#endif
60 andreas 7451
        return;
351 andreas 7452
    }
60 andreas 7453
 
7454
    vector<Button::TButton *> buttons = collectButtons(map);
7455
 
83 andreas 7456
    if (buttons.size() > 0)
60 andreas 7457
    {
83 andreas 7458
        vector<Button::TButton *>::iterator mapIter;
60 andreas 7459
 
83 andreas 7460
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
60 andreas 7461
        {
83 andreas 7462
            Button::TButton *bt = *mapIter;
351 andreas 7463
            bt->setTextColor(color, btState - 1);
7464
#if TESTMODE == 1
7465
            if (_gTestMode)
7466
                _gTestMode->setResult(bt->getTextColor(btState == 0 ? 0 : btState - 1));
7467
#endif
60 andreas 7468
        }
7469
    }
351 andreas 7470
#if TESTMODE == 1
7471
    setDone();
7472
#endif
18 andreas 7473
}
7474
 
351 andreas 7475
/*
7476
 * Get the text color of a button and send it via a custom event to the NetLinx.
7477
 */
82 andreas 7478
void TPageManager::getBCT(int port, vector<int> &channels, vector<string> &pars)
7479
{
7480
    DECL_TRACER("TPageManager::getBCT(int port, vector<int> &channels, vector<string> &pars)");
7481
 
7482
    if (pars.size() < 1)
7483
    {
7484
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
351 andreas 7485
#if TESTMODE == 1
7486
        setAllDone();
7487
#endif
82 andreas 7488
        return;
7489
    }
7490
 
7491
    TError::clear();
7492
    int btState = atoi(pars[0].c_str());
7493
    string color;
7494
 
193 andreas 7495
    vector<TMap::MAP_T> map = findButtons(port, channels);
82 andreas 7496
 
7497
    if (TError::isError() || map.empty())
351 andreas 7498
    {
7499
#if TESTMODE == 1
7500
        setAllDone();
7501
#endif
82 andreas 7502
        return;
351 andreas 7503
    }
82 andreas 7504
 
7505
    vector<Button::TButton *> buttons = collectButtons(map);
7506
 
351 andreas 7507
    if (buttons.empty())
82 andreas 7508
    {
351 andreas 7509
#if TESTMODE == 1
7510
        setAllDone();
7511
#endif
7512
        return;
7513
    }
82 andreas 7514
 
351 andreas 7515
    vector<Button::TButton *>::iterator iter;
7516
 
7517
    for (iter = buttons.begin(); iter != buttons.end(); ++iter)
7518
    {
7519
        Button::TButton *bt = *iter;
7520
 
110 andreas 7521
        if (btState == 0)       // All instances?
82 andreas 7522
        {
110 andreas 7523
            int bst = bt->getNumberInstances();
82 andreas 7524
 
110 andreas 7525
            for (int i = 0; i < bst; i++)
82 andreas 7526
            {
110 andreas 7527
                color = bt->getTextColor(i);
82 andreas 7528
 
110 andreas 7529
                if (color.empty())
7530
                    continue;
82 andreas 7531
 
300 andreas 7532
                sendCustomEvent(i + 1, (int)color.length(), 0, color, 1013, bt->getChannelPort(), bt->getChannelNumber());
351 andreas 7533
#if TESTMODE == 1
7534
                __success = true;
7535
 
7536
                if (_gTestMode)
7537
                    _gTestMode->setResult(color);
7538
#endif
83 andreas 7539
            }
82 andreas 7540
        }
110 andreas 7541
        else
7542
        {
7543
            color = bt->getTextColor(btState - 1);
351 andreas 7544
 
7545
            if (color.empty())
7546
                continue;
7547
 
300 andreas 7548
            sendCustomEvent(btState, (int)color.length(), 0, color, 1013, bt->getChannelPort(), bt->getChannelNumber());
351 andreas 7549
#if TESTMODE == 1
7550
            __success = true;
7551
 
7552
            if (_gTestMode)
7553
                _gTestMode->setResult(color);
7554
#endif
110 andreas 7555
        }
82 andreas 7556
    }
351 andreas 7557
#if TESTMODE == 1
7558
    setAllDone();
7559
#endif
82 andreas 7560
}
7561
 
60 andreas 7562
/**
7563
 * Set the button draw order
7564
 * Determines what order each layer of the button is drawn.
7565
 */
7566
void TPageManager::doBDO(int port, vector<int>& channels, vector<std::string>& pars)
32 andreas 7567
{
60 andreas 7568
    DECL_TRACER("TPageManager::doBDO(int port, vector<int>& channels, vector<std::string>& pars)");
32 andreas 7569
 
60 andreas 7570
    if (pars.size() < 1)
7571
    {
7572
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
351 andreas 7573
#if TESTMODE == 1
7574
        setAllDone();
7575
#endif
32 andreas 7576
        return;
60 andreas 7577
    }
32 andreas 7578
 
60 andreas 7579
    TError::clear();
7580
    int btState = atoi(pars[0].c_str());
7581
    string order;
32 andreas 7582
 
60 andreas 7583
    if (pars.size() > 1)
7584
    {
7585
        string ord = pars[1];
7586
        // Convert the numbers into the expected draw order
7587
        for (size_t i = 0; i < ord.length(); i++)
7588
        {
7589
            if (ord.at(i) >= '1' && ord.at(i) <= '5')
7590
            {
7591
                char hv0[32];
7592
                snprintf(hv0, sizeof(hv0), "%02d", (int)(ord.at(i) - '0'));
7593
                order.append(hv0);
7594
            }
7595
            else
7596
            {
7597
                MSG_ERROR("Illegal order number " << ord.substr(i, 1) << "!");
7598
                return;
7599
            }
7600
        }
7601
 
7602
        if (order.length() != 10)
7603
        {
7604
            MSG_ERROR("Expected 5 order numbers but got " << (order.length() / 2)<< "!");
7605
            return;
7606
        }
7607
    }
7608
 
193 andreas 7609
    vector<TMap::MAP_T> map = findButtons(port, channels);
60 andreas 7610
 
7611
    if (TError::isError() || map.empty())
351 andreas 7612
    {
7613
#if TESTMODE == 1
7614
        setAllDone();
7615
#endif
32 andreas 7616
        return;
351 andreas 7617
    }
32 andreas 7618
 
60 andreas 7619
    vector<Button::TButton *> buttons = collectButtons(map);
7620
 
83 andreas 7621
    if (buttons.size() > 0)
32 andreas 7622
    {
83 andreas 7623
        vector<Button::TButton *>::iterator mapIter;
32 andreas 7624
 
83 andreas 7625
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
60 andreas 7626
        {
83 andreas 7627
            Button::TButton *bt = *mapIter;
351 andreas 7628
            bt->setDrawOrder(order, btState - 1);
7629
#if TESTMODE == 1
7630
            if (_gTestMode)
7631
                _gTestMode->setResult(bt->getDrawOrder(btState == 0 ? 0 : btState - 1));
7632
#endif
60 andreas 7633
        }
7634
    }
351 andreas 7635
#if TESTMODE == 1
7636
    setDone();
7637
#endif
60 andreas 7638
}
32 andreas 7639
 
60 andreas 7640
/**
7641
 * Set the feedback type of the button.
7642
 * ONLY works on General-type buttons.
7643
 */
7644
void TPageManager::doBFB(int port, vector<int>& channels, vector<std::string>& pars)
7645
{
7646
    DECL_TRACER("TPageManager::doBFB(int port, vector<int>& channels, vector<std::string>& pars)");
32 andreas 7647
 
60 andreas 7648
    if (pars.size() < 1)
7649
    {
7650
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
351 andreas 7651
#if TESTMODE == 1
7652
        setAllDone();
7653
#endif
60 andreas 7654
        return;
7655
    }
7656
 
7657
    TError::clear();
7658
    Button::FEEDBACK type = Button::FB_NONE;
7659
    string stype = pars[0];
7660
    vector<string> stypes = { "None", "Channel", "Invert", "On", "Momentary", "Blink" };
7661
    vector<string>::iterator iter;
7662
    int i = 0;
7663
 
7664
    for (iter = stypes.begin(); iter != stypes.end(); ++iter)
7665
    {
7666
        if (strCaseCompare(stype, *iter) == 0)
33 andreas 7667
        {
60 andreas 7668
            type = (Button::FEEDBACK)i;
7669
            break;
32 andreas 7670
        }
60 andreas 7671
 
7672
        i++;
32 andreas 7673
    }
7674
 
193 andreas 7675
    vector<TMap::MAP_T> map = findButtons(port, channels);
60 andreas 7676
 
7677
    if (TError::isError() || map.empty())
351 andreas 7678
    {
7679
#if TESTMODE == 1
7680
        setAllDone();
7681
#endif
60 andreas 7682
        return;
351 andreas 7683
    }
60 andreas 7684
 
7685
    vector<Button::TButton *> buttons = collectButtons(map);
7686
 
83 andreas 7687
    if (buttons.size() > 0)
60 andreas 7688
    {
83 andreas 7689
        vector<Button::TButton *>::iterator mapIter;
7690
 
7691
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
7692
        {
7693
            Button::TButton *bt = *mapIter;
7694
            bt->setFeedback(type);
351 andreas 7695
#if TESTMODE == 1
7696
            if (_gTestMode)
7697
                _gTestMode->setResult(intToString(bt->getFeedback()));
7698
#endif
83 andreas 7699
        }
60 andreas 7700
    }
335 andreas 7701
#if TESTMODE == 1
7702
    setDone();
7703
#endif
32 andreas 7704
}
7705
 
224 andreas 7706
/*
7707
 * Set the input mask for the specified address.
7708
 */
7709
void TPageManager::doBIM(int port, vector<int>& channels, vector<std::string>& pars)
7710
{
7711
    DECL_TRACER("TPageManager::doBIM(int port, vector<int>& channels, vector<std::string>& pars)");
7712
 
7713
    if (pars.size() < 1)
7714
    {
7715
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
351 andreas 7716
#if TESTMODE == 1
7717
        setAllDone();
7718
#endif
224 andreas 7719
        return;
7720
    }
7721
 
7722
    TError::clear();
7723
    string mask = pars[0];
7724
    vector<TMap::MAP_T> map = findButtons(port, channels);
7725
 
7726
    if (TError::isError() || map.empty())
351 andreas 7727
    {
7728
#if TESTMODE == 1
7729
        setAllDone();
7730
#endif
224 andreas 7731
        return;
351 andreas 7732
    }
224 andreas 7733
 
7734
    vector<Button::TButton *> buttons = collectButtons(map);
7735
 
7736
    if (buttons.size() > 0)
7737
    {
7738
        vector<Button::TButton *>::iterator mapIter;
7739
 
7740
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
7741
        {
7742
            Button::TButton *bt = *mapIter;
7743
            bt->setInputMask(mask);
351 andreas 7744
#if TESTMODE == 1
7745
            if (_gTestMode)
7746
                _gTestMode->setResult(bt->getInputMask());
7747
#endif
224 andreas 7748
        }
7749
    }
351 andreas 7750
#if TESTMODE == 1
7751
    setDone();
7752
#endif
224 andreas 7753
}
7754
 
351 andreas 7755
/**
7756
 * @brief Button copy command.
7757
 * Copy attributes of the source button to all the
7758
 * destination buttons. Note that the source is a single button state. Each
7759
 * state must be copied as a separate command. The <codes> section represents
7760
 * what attributes will be copied. All codes are 2 char pairs that can be
7761
 * separated by comma, space, percent or just ran together.
7762
 */
106 andreas 7763
void TPageManager::doBMC(int port, vector<int>& channels, vector<std::string>& pars)
7764
{
7765
    DECL_TRACER("TPageManager::doBMC(int port, vector<int>& channels, vector<std::string>& pars)");
7766
 
7767
    if (pars.size() < 5)
7768
    {
7769
        MSG_ERROR("Expecting 5 parameters but got " << pars.size() << ". Ignoring command.");
351 andreas 7770
#if TESTMODE == 1
7771
        setAllDone();
7772
#endif
106 andreas 7773
        return;
7774
    }
7775
 
7776
    TError::clear();
7777
    int btState = atoi(pars[0].c_str());
7778
    int src_port = atoi(pars[1].c_str());
7779
    int src_addr = atoi(pars[2].c_str());
7780
    int src_state = atoi(pars[3].c_str());
7781
    string src_codes = pars[4];
7782
    vector<int> src_channel;
7783
    src_channel.push_back(src_addr);
7784
 
193 andreas 7785
    vector<TMap::MAP_T> src_map = findButtons(src_port, src_channel);
106 andreas 7786
 
7787
    if (src_map.size() == 0)
7788
    {
7789
        MSG_WARNING("Button <" << TConfig::getChannel() << ":" << src_port << ":" << TConfig::getSystem() << ">:" << src_addr << " does not exist!");
351 andreas 7790
#if TESTMODE == 1
7791
        setAllDone();
7792
#endif
106 andreas 7793
        return;
7794
    }
7795
 
7796
    vector<Button::TButton *>src_buttons = collectButtons(src_map);
7797
 
7798
    if (src_buttons.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
    if (src_buttons[0]->getNumberInstances() < src_state)
7808
    {
7809
        MSG_WARNING("Button <" << TConfig::getChannel() << ":" << src_port << ":" << TConfig::getSystem() << ">:" << src_addr << " has less then " << src_state << " elements.");
351 andreas 7810
#if TESTMODE == 1
7811
        setAllDone();
7812
#endif
106 andreas 7813
        return;
7814
    }
7815
 
7816
    if (src_state < 1)
7817
    {
7818
        MSG_WARNING("Button <" << TConfig::getChannel() << ":" << src_port << ":" << TConfig::getSystem() << ">:" << src_addr << " has invalid source state " << src_state << ".");
351 andreas 7819
#if TESTMODE == 1
7820
        setAllDone();
7821
#endif
106 andreas 7822
        return;
7823
    }
7824
 
7825
    src_state--;
7826
 
7827
    if (btState > 0)
7828
        btState--;
7829
 
193 andreas 7830
    vector<TMap::MAP_T> map = findButtons(port, channels);
106 andreas 7831
    vector<Button::TButton *> buttons = collectButtons(map);
7832
    //                        0     1     2     3     4     5     6     7
7833
    vector<string>codes = { "BM", "BR", "CB", "CF", "CT", "EC", "EF", "FT",
7834
                            "IC", "JB", "JI", "JT", "LN", "OP", "SO", "TX", // 8 - 15
7835
                            "VI", "WW" };   // 16, 17
7836
 
7837
    for (size_t ibuttons = 0; ibuttons < buttons.size(); ibuttons++)
7838
    {
7839
        vector<string>::iterator iter;
7840
        int idx = 0;
7841
 
7842
        for (iter = codes.begin(); iter != codes.end(); ++iter)
7843
        {
7844
            if (src_codes.find(*iter) != string::npos)
7845
            {
7846
                int j, x, y;
7847
 
7848
                switch(idx)
7849
                {
7850
                    case 0: buttons[ibuttons]->setBitmap(src_buttons[0]->getBitmapName(src_state), btState); break;
7851
                    case 1: buttons[ibuttons]->setBorderStyle(src_buttons[0]->getBorderStyle(src_state), btState); break;
7852
                    case 2: buttons[ibuttons]->setBorderColor(src_buttons[0]->getBorderColor(src_state), btState); break;
7853
                    case 3: buttons[ibuttons]->setFillColor(src_buttons[0]->getFillColor(src_state), btState); break;
7854
                    case 4: buttons[ibuttons]->setTextColor(src_buttons[0]->getTextColor(src_state), btState); break;
7855
                    case 5: buttons[ibuttons]->setTextEffectColor(src_buttons[0]->getTextEffectColor(src_state), btState); break;
7856
                    case 6: buttons[ibuttons]->setTextEffect(src_buttons[0]->getTextEffect(src_state), btState); break;
7857
                    case 7: buttons[ibuttons]->setFontIndex(src_buttons[0]->getFontIndex(src_state), btState); break;
110 andreas 7858
                    case 8: buttons[ibuttons]->setIcon(src_buttons[0]->getIconIndex(src_state), btState); break;
106 andreas 7859
 
7860
                    case 9:
7861
                        j = src_buttons[0]->getBitmapJustification(&x, &y, src_state);
7862
                        buttons[ibuttons]->setBitmapJustification(j, x, y, btState);
7863
                    break;
7864
 
7865
                    case 10:
7866
                        j = src_buttons[0]->getIconJustification(&x, &y, src_state);
7867
                        buttons[ibuttons]->setIconJustification(j, x, y, btState);
7868
                    break;
7869
 
7870
                    case 11:
7871
                        j = src_buttons[0]->getTextJustification(&x, &y, src_state);
7872
                        buttons[ibuttons]->setTextJustification(j, x, y, btState);
7873
                    break;
7874
 
7875
                    case 12: MSG_INFO("\"Lines of video removed\" not supported!"); break;
7876
                    case 13: buttons[ibuttons]->setOpacity(src_buttons[0]->getOpacity(src_state), btState); break;
7877
                    case 14: buttons[ibuttons]->setSound(src_buttons[0]->getSound(src_state), btState); break;
7878
                    case 15: buttons[ibuttons]->setText(src_buttons [0]->getText(src_state), btState); break;
7879
                    case 16: MSG_INFO("\"Video slot ID\" not supported!"); break;
7880
                    case 17: buttons[ibuttons]->setTextWordWrap(src_buttons[0]->getTextWordWrap(src_state), btState); break;
7881
                }
7882
            }
7883
 
7884
            idx++;
7885
        }
7886
    }
7887
}
7888
 
149 andreas 7889
void TPageManager::doBMF (int port, vector<int>& channels, vector<string>& pars)
7890
{
7891
    DECL_TRACER("TPageManager::doBMF (int port, vector<int>& channels, vector<string>& pars)");
7892
 
7893
    if (pars.size() < 2)
332 andreas 7894
    {
7895
        MSG_ERROR("Less then 2 parameters!");
7896
#if TESTMODE == 1
334 andreas 7897
        setAllDone();
332 andreas 7898
#endif
149 andreas 7899
        return;
332 andreas 7900
    }
149 andreas 7901
 
7902
    TError::clear();
7903
    int btState = atoi(pars[0].c_str()) - 1;
150 andreas 7904
    string commands;
149 andreas 7905
 
150 andreas 7906
    for (size_t i = 1; i < pars.size(); ++i)
7907
    {
7908
        if (i > 1)
7909
            commands += ",";
7910
 
7911
        commands += pars[i];
7912
    }
7913
 
193 andreas 7914
    vector<TMap::MAP_T> map = findButtons(port, channels);
149 andreas 7915
 
7916
    if (TError::isError() || map.empty())
332 andreas 7917
    {
7918
#if TESTMODE == 1
334 andreas 7919
        setAllDone();
332 andreas 7920
#endif
149 andreas 7921
        return;
332 andreas 7922
    }
149 andreas 7923
 
7924
    // Start of parsing the command line
162 andreas 7925
    // We splitt the command line into parts by searching for a percent (%) sign.
149 andreas 7926
    vector<string> parts = StrSplit(commands, "%");
7927
 
162 andreas 7928
    if (parts.empty())
332 andreas 7929
        parts.push_back(commands);
334 andreas 7930
 
149 andreas 7931
    // Search for all buttons who need to be updated
7932
    vector<Button::TButton *> buttons = collectButtons(map);
7933
 
7934
    if (buttons.size() > 0)
7935
    {
7936
        vector<Button::TButton *>::iterator mapIter;
7937
 
7938
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
7939
        {
7940
            Button::TButton *bt = *mapIter;
162 andreas 7941
 
7942
            if (!bt)
7943
            {
7944
                MSG_WARNING("Command ^BMF found an invalid pointer to a button!")
7945
                continue;
7946
            }
7947
 
149 andreas 7948
            // Iterate through commands and apply them to button
7949
            vector<string>::iterator iter;
7950
 
7951
            for (iter = parts.begin(); iter != parts.end(); ++iter)
7952
            {
7953
                char cmd = iter->at(0);
7954
                char cmd2;
7955
                string content;
7956
 
7957
                switch(cmd)
7958
                {
7959
                    case 'B':   // Border style
361 andreas 7960
                        if (iter->at(1) == ',')
7961
                            content = iter->substr(2);
7962
                        else
7963
                            content = iter->substr(1);
332 andreas 7964
 
7965
                        if (!content.empty() && isdigit(content[0]))
334 andreas 7966
                            bt->setBorderStyle(atoi(content.c_str()), btState);
332 andreas 7967
                        else
7968
                            bt->setBorderStyle(content, btState);
7969
#if TESTMODE == 1
7970
                        if (_gTestMode)
7971
                            _gTestMode->setResult(bt->getBorderStyle(btState < 0 ? 0 : btState));
7972
#endif
149 andreas 7973
                    break;
7974
 
7975
                    case 'C':   // Colors
7976
                        cmd2 = iter->at(1);
7977
                        content = iter->substr(2);
7978
 
7979
                        switch(cmd2)
7980
                        {
7981
                            case 'B':   // Border color
7982
                                bt->setBorderColor(content, btState);
332 andreas 7983
#if TESTMODE == 1
7984
                                if (_gTestMode)
7985
                                    _gTestMode->setResult(bt->getBorderColor(btState < 0 ? 0 : btState));
7986
#endif
149 andreas 7987
                            break;
7988
 
7989
                            case 'F':   // Fill color
7990
                                bt->setFillColor(content, btState);
332 andreas 7991
#if TESTMODE == 1
7992
                                if (_gTestMode)
7993
                                    _gTestMode->setResult(bt->getFillColor(btState < 0 ? 0 : btState));
7994
#endif
149 andreas 7995
                            break;
7996
 
7997
                            case 'T':   // Text color
7998
                                bt->setTextColor(content, btState);
332 andreas 7999
#if TESTMODE == 1
8000
                                if (_gTestMode)
8001
                                    _gTestMode->setResult(bt->getTextColor(btState < 0 ? 0 : btState));
8002
#endif
149 andreas 8003
                            break;
8004
                        }
8005
                    break;
8006
 
150 andreas 8007
                    case 'D':   // Draw order
8008
                        cmd2 = iter->at(1);
8009
                        content = iter->substr(2);
8010
 
8011
                        if (cmd2 == 'O')
332 andreas 8012
                        {
150 andreas 8013
                            bt->setDrawOrder(content, btState);
332 andreas 8014
#if TESTMODE == 1
8015
                            if (_gTestMode)
8016
                                _gTestMode->setResult(bt->getDrawOrder(btState < 0 ? 0 : btState));
8017
#endif
8018
                        }
150 andreas 8019
                    break;
8020
 
149 andreas 8021
                    case 'E':   // Text effect
8022
                        cmd2 = iter->at(1);
8023
                        content = iter->substr(2);
8024
 
8025
                        switch(cmd2)
8026
                        {
8027
                            case 'C':   // Text effect color
8028
                                bt->setTextEffectColor(content, btState);
332 andreas 8029
#if TESTMODE == 1
8030
                                if (_gTestMode)
8031
                                    _gTestMode->setResult(bt->getTextEffectColor(btState < 0 ? 0 : btState));
8032
#endif
149 andreas 8033
                            break;
8034
 
8035
                            case 'F':   // Text effect name
8036
                                bt->setTextEffectName(content, btState);
332 andreas 8037
#if TESTMODE == 1
8038
                                if (_gTestMode)
8039
                                    _gTestMode->setResult(bt->getTextEffectName(btState < 0 ? 0 : btState));
8040
#endif
149 andreas 8041
                            break;
8042
 
8043
                            case 'N':   // Enable/disable button
8044
                                bt->setEnable((content[0] == '1' ? true : false));
332 andreas 8045
#if TESTMODE == 1
8046
                                if (_gTestMode)
334 andreas 8047
                                {
332 andreas 8048
                                    _gTestMode->setResult(bt->isEnabled() ? "TRUE" : "FALSE");
334 andreas 8049
                                    __success = true;
8050
                                    setScreenDone();
8051
                                }
332 andreas 8052
#endif
149 andreas 8053
                            break;
8054
                        }
8055
                    break;
8056
 
8057
                    case 'F':   // Set font file name
361 andreas 8058
                        if (iter->at(1) == ',')
8059
                            content = iter->substr(2);
8060
                        else
8061
                            content = iter->substr(1);
150 andreas 8062
 
8063
                        if (!isdigit(content[0]))
334 andreas 8064
                            bt->setFontName(content, btState);
150 andreas 8065
                        else
8066
                            bt->setFontIndex(atoi(content.c_str()), btState);
334 andreas 8067
#if TESTMODE == 1
8068
                        if (_gTestMode)
8069
                            _gTestMode->setResult(intToString(bt->getFontIndex(btState < 0 ? 0 : btState)));
8070
#endif
149 andreas 8071
                    break;
8072
 
8073
                    case 'G':   // Bargraphs
8074
                        cmd2 = iter->at(1);
8075
                        content = iter->substr(2);
8076
 
8077
                        switch(cmd2)
8078
                        {
8079
                            case 'C':   // Bargraph slider color
8080
                                bt->setBargraphSliderColor(content);
8081
                            break;
8082
 
8083
                            case 'D':   // Ramp down time
387 andreas 8084
                                bt->setBargraphRampDownTime(atoi(content.c_str()));
149 andreas 8085
                            break;
8086
 
8087
                            case 'G':   // Drag increment
387 andreas 8088
                                bt->setBargraphDragIncrement(atoi(content.c_str()));
149 andreas 8089
                            break;
8090
 
8091
                            case 'H':   // Upper limit
8092
                                bt->setBargraphUpperLimit(atoi(content.c_str()));
8093
                            break;
8094
 
8095
                            case 'I':   // Invert/noninvert
387 andreas 8096
                                if (bt->getButtonType() == BARGRAPH || bt->getButtonType() == MULTISTATE_BARGRAPH)
8097
                                    bt->setBargraphInvert(atoi(content.c_str()) > 0 ? true : false);
149 andreas 8098
                            break;
8099
 
8100
                            case 'L':   // Lower limit
8101
                                bt->setBargraphLowerLimit(atoi(content.c_str()));
8102
                            break;
8103
 
8104
                            case 'N':   // Slider name
361 andreas 8105
                                bt->setBargraphSliderName(content);
149 andreas 8106
                            break;
8107
 
8108
                            case 'R':   // Repeat interval
8109
                                // FIXME: Add function to set repeat interval
8110
                            break;
8111
 
8112
                            case 'U':   // Ramp up time
387 andreas 8113
                                bt->setBargraphRampUpTime(atoi(content.c_str()));
149 andreas 8114
                            break;
8115
 
8116
                            case 'V':   // Bargraph value
387 andreas 8117
                                bt->setBargraphLevel(atoi(content.c_str()));
149 andreas 8118
                            break;
8119
                        }
8120
                    break;
8121
 
152 andreas 8122
                    case 'I':   // Set the icon
8123
                        content = iter->substr(1);
8124
                        bt->setIcon(atoi(content.c_str()), btState);
332 andreas 8125
#if TESTMODE == 1
8126
                        if (_gTestMode)
8127
                            _gTestMode->setResult(intToString(bt->getIconIndex()));
8128
#endif
152 andreas 8129
                    break;
8130
 
149 andreas 8131
                    case 'J':   // Set text justification
150 andreas 8132
                        cmd2 = iter->at(1);
8133
 
361 andreas 8134
                        if (cmd2 == ',')
150 andreas 8135
                        {
8136
                            content = iter->substr(1);
152 andreas 8137
                            int just = atoi(content.c_str());
8138
                            int x = 0, y = 0;
8139
 
8140
                            if (just == 0)
8141
                            {
8142
                                vector<string> coords = StrSplit(content, ",");
8143
 
8144
                                if (coords.size() >= 3)
8145
                                {
8146
                                    x = atoi(coords[1].c_str());
8147
                                    y = atoi(coords[2].c_str());
8148
                                }
8149
                            }
8150
 
8151
                            bt->setTextJustification(atoi(content.c_str()), x, y, btState);
334 andreas 8152
#if TESTMODE == 1
8153
                            if (_gTestMode)
8154
                            {
8155
                                just = bt->getTextJustification(&x, &y, btState < 0 ? 0 : btState);
8156
                                string s = intToString(just) + "," + intToString(x) + "," + intToString(y);
8157
                                _gTestMode->setResult(s);
8158
                            }
8159
#endif
150 andreas 8160
                        }
361 andreas 8161
                        else if (cmd2 == 'T' || cmd2 == 'B' || cmd2 == 'I')
150 andreas 8162
                        {
8163
                            content = iter->substr(2);
152 andreas 8164
                            int x = 0, y = 0;
8165
                            int just = atoi(content.c_str());
150 andreas 8166
 
152 andreas 8167
                            if (just == 0)
8168
                            {
8169
                                vector<string> coords = StrSplit(content, ",");
8170
 
8171
                                if (coords.size() >= 3)
8172
                                {
8173
                                    x = atoi(coords[1].c_str());
8174
                                    y = atoi(coords[2].c_str());
8175
                                }
8176
                            }
8177
 
150 andreas 8178
                            switch(cmd2)
8179
                            {
8180
                                case 'B':   // Alignment of bitmap
152 andreas 8181
                                    bt->setBitmapJustification(atoi(content.c_str()), x, y, btState);
334 andreas 8182
#if TESTMODE == 1
8183
                                    just = bt->getBitmapJustification(&x, &y, btState < 0 ? 0 : btState);
8184
#endif
150 andreas 8185
                                break;
8186
 
8187
                                case 'I':   // Alignment of icon
152 andreas 8188
                                    bt->setIconJustification(atoi(content.c_str()), x, y, btState);
334 andreas 8189
#if TESTMODE == 1
8190
                                    just = bt->getIconJustification(&x, &y, btState < 0 ? 0 : btState);
8191
#endif
150 andreas 8192
                                break;
8193
 
8194
                                case 'T':   // Alignment of text
152 andreas 8195
                                    bt->setTextJustification(atoi(content.c_str()), x, y, btState);
334 andreas 8196
#if TESTMODE == 1
8197
                                    just = bt->getTextJustification(&x, &y, btState < 0 ? 0 : btState);
8198
#endif
150 andreas 8199
                                break;
8200
                            }
334 andreas 8201
#if TESTMODE == 1
8202
                            if (_gTestMode)
8203
                            {
8204
                                string s = intToString(just) + "," + intToString(x) + "," + intToString(y);
8205
                                _gTestMode->setResult(s);
8206
                            }
8207
#endif
150 andreas 8208
                        }
8209
                    break;
8210
 
8211
                    case 'M':   // Text area
8212
                        cmd2 = iter->at(1);
8213
                        content = iter->substr(2);
8214
 
8215
                        switch(cmd2)
8216
                        {
152 andreas 8217
                            case 'I':   // Set mask image
8218
                                // FIXME: Add code for image mask
8219
                            break;
8220
 
150 andreas 8221
                            case 'K':   // Input mask of text area
8222
                                // FIXME: Add input mask
8223
                            break;
8224
 
8225
                            case 'L':   // Maximum length of text area
8226
                                // FIXME: Add code to set maximum length
8227
                            break;
8228
                        }
8229
                    break;
8230
 
8231
                    case 'O':   // Set feedback typ, opacity
8232
                        cmd2 = iter->at(1);
8233
 
8234
                        switch(cmd2)
8235
                        {
8236
                            case 'P':   // Set opacity
8237
                                bt->setOpacity(atoi(iter->substr(2).c_str()), btState);
8238
                            break;
8239
 
8240
                            case 'T':   // Set feedback type
8241
                                content = iter->substr(2);
8242
                                content = toUpper(content);
8243
 
8244
                                if (content == "NONE")
8245
                                    bt->setFeedback(Button::FB_NONE);
8246
                                else if (content == "CHANNEL")
8247
                                    bt->setFeedback(Button::FB_CHANNEL);
8248
                                else if (content == "INVERT")
8249
                                    bt->setFeedback(Button::FB_INV_CHANNEL);
8250
                                else if (content == "ON")
8251
                                    bt->setFeedback(Button::FB_ALWAYS_ON);
8252
                                else if (content == "MOMENTARY")
8253
                                    bt->setFeedback(Button::FB_MOMENTARY);
8254
                                else if (content == "BLINK")
8255
                                    bt->setFeedback(Button::FB_BLINK);
8256
                                else
8257
                                {
8258
                                    MSG_WARNING("Unknown feedback type " << content);
8259
                                }
335 andreas 8260
#if TESTMODE == 1
8261
                                if (_gTestMode)
8262
                                    _gTestMode->setResult(intToString(bt->getFeedback()));
8263
#endif
150 andreas 8264
                            break;
8265
 
8266
                            default:
8267
                                content = iter->substr(1);
8268
                                // FIXME: Add code to set the feedback type
8269
                        }
8270
                    break;
8271
 
152 andreas 8272
                    case 'P':   // Set picture/bitmap file name
8273
                        content = iter->substr(1);
165 andreas 8274
 
8275
                        if (content.find(".") == string::npos)  // If the image has no extension ...
8276
                        {                                       // we must find the image in the map
8277
                            string iname = findImage(content);
8278
 
8279
                            if (!iname.empty())
8280
                                content = iname;
8281
                        }
8282
 
152 andreas 8283
                        bt->setBitmap(content, btState);
8284
                    break;
8285
 
8286
                    case 'R':   // Set rectangle
8287
                    {
8288
                        content = iter->substr(1);
8289
                        vector<string> corners = StrSplit(content, ",");
8290
 
8291
                        if (corners.size() > 0)
8292
                        {
8293
                            vector<string>::iterator itcorn;
8294
                            int pos = 0;
8295
                            int left, top, right, bottom;
8296
                            left = top = right = bottom = 0;
8297
 
8298
                            for (itcorn = corners.begin(); itcorn != corners.end(); ++itcorn)
8299
                            {
8300
                                switch(pos)
8301
                                {
8302
                                    case 0: left   = atoi(itcorn->c_str()); break;
8303
                                    case 1: top    = atoi(itcorn->c_str()); break;
8304
                                    case 2: right  = atoi(itcorn->c_str()); break;
8305
                                    case 3: bottom = atoi(itcorn->c_str()); break;
8306
                                }
8307
 
8308
                                pos++;
8309
                            }
8310
 
8311
                            if (pos >= 4)
334 andreas 8312
                            {
152 andreas 8313
                                bt->setRectangle(left, top, right, bottom);
334 andreas 8314
                                bt->refresh();
8315
                            }
152 andreas 8316
                        }
334 andreas 8317
#if TESTMODE == 1
8318
                        if (_gTestMode)
8319
                        {
8320
                            int left, top, width, height;
8321
                            bt->getRectangle(&left, &top, &height, &width);
8322
                            string res(intToString(left) + "," + intToString(top) + "," + intToString(width) + "," + intToString(height));
8323
                            _gTestMode->setResult(res);
8324
                        }
8325
#endif
152 andreas 8326
                    }
8327
                    break;
8328
 
150 andreas 8329
                    case 'S':   // show/hide, style, sound
8330
                        cmd2 = iter->at(1);
8331
                        content = iter->substr(2);
8332
 
8333
                        switch(cmd2)
8334
                        {
8335
                            case 'F':   // Set focus of text area button
8336
                                // FIXME: Add code to set the focus of text area button
8337
                            break;
8338
 
8339
                            case 'M':   // Submit text
169 andreas 8340
                                if (content.find("|"))  // To be replaced by LF (0x0a)?
8341
                                {
8342
                                    size_t pos = 0;
8343
 
8344
                                    while ((pos = content.find("|")) != string::npos)
8345
                                        content = content.replace(pos, 1, "\n");
8346
                                }
8347
 
150 andreas 8348
                                bt->setText(content, btState);
8349
                            break;
8350
 
8351
                            case 'O':   // Sound
8352
                                bt->setSound(content, btState);
335 andreas 8353
#if TESTMODE == 1
8354
                                if (_gTestMode)
8355
                                    _gTestMode->setResult(bt->getSound(btState < 0 ? 0 : btState));
8356
#endif
150 andreas 8357
                            break;
8358
 
8359
                            case 'T':   // Button style
8360
                                // FIXME: Add code to set the button style
8361
                            break;
8362
 
8363
                            case 'W':   // Show / hide button
8364
                                if (content[0] == '0')
334 andreas 8365
                                    bt->hide(true);
150 andreas 8366
                                else
8367
                                    bt->show();
334 andreas 8368
#if TESTMODE == 1
8369
                                if (_gTestMode)
8370
                                    _gTestMode->setResult(bt->isVisible() ? "TRUE" : "FALSE");
8371
#endif
150 andreas 8372
                            break;
8373
                        }
8374
                    break;
8375
 
152 andreas 8376
                    case 'T':   // Set text
8377
                        content = iter->substr(1);
169 andreas 8378
 
8379
                        if (content.find("|"))  // To be replaced by LF (0x0a)?
8380
                        {
8381
                            size_t pos = 0;
8382
 
8383
                            while ((pos = content.find("|")) != string::npos)
8384
                                content = content.replace(pos, 1, "\n");
8385
                        }
8386
 
152 andreas 8387
                        bt->setText(content, btState);
334 andreas 8388
#if TESTMODE == 1
8389
                        if (_gTestMode)
8390
                            _gTestMode->setResult(bt->getText(btState < 0 ? 0 : btState));
8391
#endif
152 andreas 8392
                    break;
8393
 
150 andreas 8394
                    case 'U':   // Set the unicode text
8395
                        if (iter->at(1) == 'N')
8396
                        {
8397
                            content = iter->substr(2);
152 andreas 8398
                            string byte, text;
8399
                            size_t pos = 0;
8400
 
8401
                            while (pos < content.length())
8402
                            {
8403
                                byte = content.substr(pos, 2);
8404
                                char ch = (char)strtol(byte.c_str(), NULL, 16);
8405
                                text += ch;
8406
                                pos += 2;
8407
                            }
8408
 
169 andreas 8409
                            if (text.find("|"))  // To be replaced by LF (0x0a)?
8410
                            {
8411
                                size_t pos = 0;
8412
 
8413
                                while ((pos = text.find("|")) != string::npos)
8414
                                    text = text.replace(pos, 1, "\n");
8415
                            }
8416
 
152 andreas 8417
                            bt->setText(text, btState);
150 andreas 8418
                        }
8419
                    break;
8420
 
8421
                    case 'V':   // Video on / off
8422
                        cmd2 = iter->at(1);
8423
                        // Controlling a computer remotely is not supported.
8424
                        if (cmd2 != 'L' && cmd2 != 'N' && cmd2 != 'P')
8425
                        {
8426
                            content = iter->substr(2);
8427
                            // FIXME: Add code to switch video on or off
8428
                        }
8429
                    break;
8430
 
8431
                    case 'W':   // Word wrap
152 andreas 8432
                        if (iter->at(1) == 'W')
8433
                        {
8434
                            content = iter->substr(2);
8435
                            bt->setTextWordWrap(content[0] == '1' ? true : false, btState);
8436
                        }
149 andreas 8437
                    break;
8438
                }
8439
            }
8440
        }
8441
    }
332 andreas 8442
#if TESTMODE == 1
334 andreas 8443
    setDone();
332 andreas 8444
#endif
149 andreas 8445
}
8446
 
14 andreas 8447
/**
110 andreas 8448
 * Set the maximum length of the text area button. If this value is set to
8449
 * zero (0), the text area has no max length. The maximum length available is
8450
 * 2000. This is only for a Text area input button and not for a Text area input
8451
 * masking button.
8452
 */
8453
void TPageManager::doBML(int port, vector<int>& channels, vector<string>& pars)
8454
{
8455
    DECL_TRACER("TPageManager::doBML(int port, vector<int>& channels, vector<string>& pars)");
8456
 
8457
    if (pars.size() < 1)
8458
    {
8459
        MSG_ERROR("Expecting 1 parameter but got " << pars.size() << "! Ignoring command.");
8460
        return;
8461
    }
8462
 
8463
    TError::clear();
8464
    int maxLen = atoi(pars[0].c_str());
8465
 
8466
    if (maxLen < 0 || maxLen > 2000)
8467
    {
8468
        MSG_WARNING("Got illegal length of text area! [" << maxLen << "]");
8469
        return;
8470
    }
8471
 
193 andreas 8472
    vector<TMap::MAP_T> map = findButtons(port, channels);
110 andreas 8473
 
8474
    if (TError::isError() || map.empty())
8475
        return;
8476
 
8477
    vector<Button::TButton *> buttons = collectButtons(map);
8478
 
8479
    if (buttons.size() > 0)
8480
    {
8481
        vector<Button::TButton *>::iterator mapIter;
8482
 
8483
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
8484
        {
8485
            Button::TButton *bt = *mapIter;
8486
            bt->setTextMaxChars(maxLen);
8487
        }
8488
    }
8489
}
8490
 
8491
/**
60 andreas 8492
 * Assign a picture to those buttons with a defined address range.
8493
 */
8494
void TPageManager::doBMP(int port, vector<int>& channels, vector<string>& pars)
8495
{
8496
    DECL_TRACER("TPageManager::doBMP(int port, vector<int>& channels, vector<string>& pars)");
8497
 
8498
    if (pars.size() < 2)
8499
    {
8500
        MSG_ERROR("Expecting 2 parameters but got " << pars.size() << "! Ignoring command.");
8501
        return;
8502
    }
8503
 
8504
    TError::clear();
8505
    int btState = atoi(pars[0].c_str());
8506
    string bitmap = pars[1];
104 andreas 8507
    // If this is a G5 command, we may have up to 2 additional parameters.
8508
    int slot = -1, justify = -1, jx = 0, jy = 0;
60 andreas 8509
 
104 andreas 8510
    if (pars.size() > 2)
8511
    {
8512
        slot = atoi(pars[2].c_str());
8513
 
8514
        if (pars.size() >= 4)
8515
        {
8516
            justify = atoi(pars[4].c_str());
8517
 
8518
            if (justify == 0)
8519
            {
8520
                if (pars.size() >= 5)
8521
                    jx = atoi(pars[5].c_str());
8522
 
8523
                if (pars.size() >= 6)
8524
                    jy = atoi(pars[6].c_str());
8525
            }
8526
        }
8527
    }
8528
 
193 andreas 8529
    vector<TMap::MAP_T> map = findButtons(port, channels);
60 andreas 8530
 
8531
    if (TError::isError() || map.empty())
8532
        return;
8533
 
8534
    vector<Button::TButton *> buttons = collectButtons(map);
8535
 
83 andreas 8536
    if (buttons.size() > 0)
60 andreas 8537
    {
83 andreas 8538
        vector<Button::TButton *>::iterator mapIter;
60 andreas 8539
 
83 andreas 8540
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
60 andreas 8541
        {
83 andreas 8542
            Button::TButton *bt = *mapIter;
252 andreas 8543
//            setButtonCallbacks(bt);
60 andreas 8544
 
83 andreas 8545
            if (btState == 0)       // All instances?
8546
            {
8547
                int bst = bt->getNumberInstances();
96 andreas 8548
                MSG_DEBUG("Setting bitmap " << bitmap << " on all " << bst << " instances...");
83 andreas 8549
 
8550
                for (int i = 0; i < bst; i++)
104 andreas 8551
                {
8552
                    if (justify >= 0)
8553
                    {
8554
                        if (slot == 2)
8555
                            bt->setIconJustification(justify, jx, jy, i);
8556
                        else
106 andreas 8557
                            bt->setBitmapJustification(justify, jx, jy, i);
104 andreas 8558
                    }
8559
 
8560
                    if (slot >= 0)
8561
                    {
8562
                        switch(slot)
8563
                        {
8564
                            case 0: bt->setCameleon(bitmap, i); break;
8565
                            case 2: bt->setIcon(bitmap, i); break;  // On G4 we have no bitmap layer. Therefor we use layer 2 as icon layer.
8566
                            default:
8567
                                bt->setBitmap(bitmap, i);
8568
                        }
8569
                    }
8570
                    else
8571
                        bt->setBitmap(bitmap, i);
8572
                }
83 andreas 8573
            }
8574
            else
104 andreas 8575
            {
8576
                if (justify >= 0)
8577
                {
8578
                    if (slot == 2)
8579
                        bt->setIconJustification(justify, jx, jy, btState);
8580
                    else
106 andreas 8581
                        bt->setBitmapJustification(justify, jx, jy, btState);
104 andreas 8582
                }
8583
 
8584
                if (slot >= 0)
8585
                {
8586
                    switch(slot)
8587
                    {
8588
                        case 0: bt->setCameleon(bitmap, btState); break;
8589
                        case 2: bt->setIcon(bitmap, btState); break;      // On G4 we have no bitmap layer. Therefor we use layer 2 as icon layer.
8590
                        default:
8591
                            bt->setBitmap(bitmap, btState);
8592
                    }
8593
                }
8594
                else
8595
                    bt->setBitmap(bitmap, btState);
8596
            }
60 andreas 8597
        }
8598
    }
8599
}
8600
 
82 andreas 8601
void TPageManager::getBMP(int port, vector<int> &channels, vector<string> &pars)
8602
{
8603
    DECL_TRACER("TPageManager::getBMP(int port, vector<int> &channels, vector<string> &pars)");
8604
 
8605
    if (pars.size() < 1)
8606
    {
8607
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
8608
        return;
8609
    }
8610
 
8611
    TError::clear();
8612
    int btState = atoi(pars[0].c_str());
8613
    string bmp;
8614
 
193 andreas 8615
    vector<TMap::MAP_T> map = findButtons(port, channels);
82 andreas 8616
 
8617
    if (TError::isError() || map.empty())
8618
        return;
8619
 
8620
    vector<Button::TButton *> buttons = collectButtons(map);
8621
 
83 andreas 8622
    if (buttons.size() > 0)
82 andreas 8623
    {
110 andreas 8624
        Button::TButton *bt = buttons[0];
82 andreas 8625
 
110 andreas 8626
        if (btState == 0)       // All instances?
82 andreas 8627
        {
110 andreas 8628
            int bst = bt->getNumberInstances();
82 andreas 8629
 
110 andreas 8630
            for (int i = 0; i < bst; i++)
82 andreas 8631
            {
110 andreas 8632
                bmp = bt->getBitmapName(i);
82 andreas 8633
 
110 andreas 8634
                if (bmp.empty())
8635
                    continue;
82 andreas 8636
 
300 andreas 8637
                sendCustomEvent(i + 1, (int)bmp.length(), 0, bmp, 1002, bt->getChannelPort(), bt->getChannelNumber());
83 andreas 8638
            }
82 andreas 8639
        }
110 andreas 8640
        else
8641
        {
8642
            bmp = bt->getTextColor(btState-1);
300 andreas 8643
            sendCustomEvent(btState, (int)bmp.length(), 0, bmp, 1002, bt->getChannelPort(), bt->getChannelNumber());
110 andreas 8644
        }
82 andreas 8645
    }
8646
}
8647
 
60 andreas 8648
/**
16 andreas 8649
 * Set the button opacity. The button opacity can be specified as a decimal
8650
 * between 0 - 255, where zero (0) is invisible and 255 is opaque, or as a
8651
 * HEX code, as used in the color commands by preceding the HEX code with
8652
 * the # sign. In this case, #00 becomes invisible and #FF becomes opaque.
8653
 * If the opacity is set to zero (0), this does not make the button inactive,
8654
 * only invisible.
8655
 */
8656
void TPageManager::doBOP(int port, vector<int>& channels, vector<string>& pars)
8657
{
8658
    DECL_TRACER("TPageManager::doBOP(int port, vector<int>& channels, vector<string>& pars)");
8659
 
8660
    if (pars.size() < 2)
8661
    {
8662
        MSG_ERROR("Expecting 2 parameters but got " << pars.size() << "! Ignoring command.");
335 andreas 8663
#if TESTMODE == 1
8664
        setAllDone();
8665
#endif
16 andreas 8666
        return;
8667
    }
8668
 
8669
    TError::clear();
335 andreas 8670
    int btState = atoi(pars[0].c_str()) - 1;
16 andreas 8671
    int btOpacity = 0;
8672
 
8673
    if (pars[1].at(0) == '#')
8674
        btOpacity = (int)strtol(pars[1].substr(1).c_str(), NULL, 16);
8675
    else
8676
        btOpacity = atoi(pars[1].c_str());
8677
 
193 andreas 8678
    vector<TMap::MAP_T> map = findButtons(port, channels);
16 andreas 8679
 
8680
    if (TError::isError() || map.empty())
335 andreas 8681
    {
8682
#if TESTMODE == 1
8683
        setAllDone();
8684
#endif
16 andreas 8685
        return;
335 andreas 8686
    }
16 andreas 8687
 
8688
    vector<Button::TButton *> buttons = collectButtons(map);
8689
 
83 andreas 8690
    if (buttons.size() > 0)
16 andreas 8691
    {
83 andreas 8692
        vector<Button::TButton *>::iterator mapIter;
16 andreas 8693
 
83 andreas 8694
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
16 andreas 8695
        {
83 andreas 8696
            Button::TButton *bt = *mapIter;
335 andreas 8697
            bt->setOpacity(btOpacity, btState);
8698
#if TESTMODE == 1
8699
            if (_gTestMode)
8700
                _gTestMode->setResult(intToString(bt->getOpacity(btState < 0 ? 0 : btState)));
342 andreas 8701
#endif
16 andreas 8702
        }
8703
    }
335 andreas 8704
#if TESTMODE == 1
8705
    setDone();
8706
#endif
16 andreas 8707
}
8708
 
106 andreas 8709
void TPageManager::getBOP(int port, vector<int>& channels, vector<string>& pars)
8710
{
8711
    DECL_TRACER("TPageManager::getBOP(int port, vector<int>& channels, vector<string>& pars)");
8712
 
8713
    if (pars.size() < 1)
8714
    {
8715
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
8716
        return;
8717
    }
8718
 
8719
    TError::clear();
8720
    int btState = atoi(pars[0].c_str());
8721
 
193 andreas 8722
    vector<TMap::MAP_T> map = findButtons(port, channels);
106 andreas 8723
 
8724
    if (TError::isError() || map.empty())
8725
        return;
8726
 
8727
    vector<Button::TButton *> buttons = collectButtons(map);
8728
 
8729
    if (buttons.size() > 0)
8730
    {
110 andreas 8731
        Button::TButton *bt = buttons[0];
106 andreas 8732
 
110 andreas 8733
        if (btState == 0)       // All instances?
106 andreas 8734
        {
110 andreas 8735
            int bst = bt->getNumberInstances();
106 andreas 8736
 
110 andreas 8737
            for (int i = 0; i < bst; i++)
106 andreas 8738
            {
110 andreas 8739
                int oo = bt->getOpacity(i);
8740
                sendCustomEvent(i + 1, oo, 0, "", 1015, bt->getChannelPort(), bt->getChannelNumber());
106 andreas 8741
            }
8742
        }
110 andreas 8743
        else
8744
        {
8745
            int oo = bt->getOpacity(btState-1);
8746
            sendCustomEvent(btState, oo, 0, "", 1015, bt->getChannelPort(), bt->getChannelNumber());
8747
        }
106 andreas 8748
    }
8749
}
8750
 
60 andreas 8751
void TPageManager::doBOR(int port, vector<int>& channels, vector<string>& pars)
8752
{
8753
    DECL_TRACER("TPageManager::doBOR(int port, vector<int>& channels, vector<string>& pars)");
8754
 
8755
    if (pars.size() < 1)
8756
    {
8757
        MSG_ERROR("Expecting at least 1 parameter but got " << pars.size() << "! Ignoring command.");
335 andreas 8758
#if TESTMODE == 1
8759
        setAllDone();
8760
#endif
60 andreas 8761
        return;
8762
    }
8763
 
8764
    TError::clear();
8765
    // Numbers of styles from 0 to 41
8766
    string bor = pars[0];
8767
    string border = "None";
8768
    int ibor = -1;
336 andreas 8769
    Border::TIntBorder borders;
60 andreas 8770
 
8771
    if (bor.at(0) >= '0' && bor.at(0) <= '9')
336 andreas 8772
    {
60 andreas 8773
        ibor = atoi(bor.c_str());
8774
 
336 andreas 8775
        if (ibor >= 0 && ibor <= 41)
8776
            border = borders.getTP4BorderName(ibor);
8777
        else
60 andreas 8778
        {
336 andreas 8779
            MSG_WARNING("Invalid border style ID " << ibor);
8780
#if TESTMODE == 1
8781
            setAllDone();
8782
#endif
8783
            return;
8784
        }
60 andreas 8785
 
336 andreas 8786
        MSG_DEBUG("Id " << ibor << " is border " << border);
60 andreas 8787
    }
336 andreas 8788
    else
60 andreas 8789
    {
336 andreas 8790
        if (!borders.isTP4BorderValid(bor))
8791
        {
8792
            MSG_WARNING("Unknown border style " << bor);
335 andreas 8793
#if TESTMODE == 1
336 andreas 8794
            setAllDone();
335 andreas 8795
#endif
336 andreas 8796
            return;
8797
        }
60 andreas 8798
 
336 andreas 8799
        border = bor;
60 andreas 8800
    }
8801
 
193 andreas 8802
    vector<TMap::MAP_T> map = findButtons(port, channels);
60 andreas 8803
 
8804
    if (TError::isError() || map.empty())
335 andreas 8805
    {
8806
#if TESTMODE == 1
8807
        setAllDone();
8808
#endif
60 andreas 8809
        return;
335 andreas 8810
    }
60 andreas 8811
 
8812
    vector<Button::TButton *> buttons = collectButtons(map);
8813
 
83 andreas 8814
    if (buttons.size() > 0)
60 andreas 8815
    {
83 andreas 8816
        vector<Button::TButton *>::iterator mapIter;
8817
 
8818
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
8819
        {
8820
            Button::TButton *bt = *mapIter;
8821
            bt->setBorderStyle(border);
335 andreas 8822
#if TESTMODE == 1
8823
            if (_gTestMode)
8824
                _gTestMode->setResult(bt->getBorderStyle(0));
8825
#endif
83 andreas 8826
        }
60 andreas 8827
    }
335 andreas 8828
#if TESTMODE == 1
8829
    setDone();
8830
#endif
60 andreas 8831
}
8832
 
107 andreas 8833
void TPageManager::doBOS(int port, vector<int>& channels, vector<string>& pars)
8834
{
8835
    DECL_TRACER("TPageManager::doBOS(int port, vector<int>& channels, vector<string>& pars)");
8836
 
8837
    if (pars.size() < 2)
8838
    {
8839
        MSG_ERROR("Expecting at least 2 parameters but got " << pars.size() << "! Ignoring command.");
8840
        return;
8841
    }
8842
 
8843
    TError::clear();
8844
    int btState = atoi(pars[0].c_str());
8845
    int videoState = atoi(pars[1].c_str());
8846
 
193 andreas 8847
    vector<TMap::MAP_T> map = findButtons(port, channels);
107 andreas 8848
 
8849
    if (TError::isError() || map.empty())
8850
        return;
8851
 
8852
    vector<Button::TButton *> buttons = collectButtons(map);
8853
 
8854
    if (buttons.size() > 0)
8855
    {
8856
        vector<Button::TButton *>::iterator mapIter;
8857
 
8858
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
8859
        {
8860
            Button::TButton *bt = *mapIter;
8861
 
8862
            if (btState == 0)       // All instances?
8863
                bt->setDynamic(videoState);
8864
            else
8865
                bt->setDynamic(videoState, btState-1);
8866
        }
8867
    }
8868
}
8869
 
16 andreas 8870
/**
60 andreas 8871
 * Set the border of a button state/states.
8872
 * The border names are available through the TPDesign4 border-name drop-down
8873
 * list.
8874
 */
8875
void TPageManager::doBRD(int port, vector<int>& channels, vector<string>& pars)
8876
{
8877
    DECL_TRACER("TPageManager::doBRD(int port, vector<int>& channels, vector<string>& pars)");
8878
 
8879
    if (pars.size() < 1)
8880
    {
8881
        MSG_ERROR("Expecting at least 1 parameter but got " << pars.size() << "! Ignoring command.");
8882
        return;
8883
    }
8884
 
8885
    TError::clear();
8886
    int btState = atoi(pars[0].c_str());
8887
    string border = "None";
8888
 
8889
    if (pars.size() > 1)
8890
        border = pars[1];
8891
 
193 andreas 8892
    vector<TMap::MAP_T> map = findButtons(port, channels);
60 andreas 8893
 
8894
    if (TError::isError() || map.empty())
8895
        return;
8896
 
8897
    vector<Button::TButton *> buttons = collectButtons(map);
8898
 
83 andreas 8899
    if (buttons.size() > 0)
60 andreas 8900
    {
83 andreas 8901
        vector<Button::TButton *>::iterator mapIter;
60 andreas 8902
 
83 andreas 8903
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
60 andreas 8904
        {
83 andreas 8905
            Button::TButton *bt = *mapIter;
252 andreas 8906
//            setButtonCallbacks(bt);
60 andreas 8907
 
83 andreas 8908
            if (btState == 0)       // All instances?
8909
            {
8910
                int bst = bt->getNumberInstances();
8911
 
8912
                for (int i = 0; i < bst; i++)
106 andreas 8913
                    bt->setBorderStyle(border, i+1);
83 andreas 8914
            }
8915
            else
106 andreas 8916
                bt->setBorderStyle(border, btState);
60 andreas 8917
        }
8918
    }
8919
}
8920
 
107 andreas 8921
void TPageManager::getBRD(int port, vector<int>& channels, vector<string>& pars)
8922
{
8923
    DECL_TRACER("TPageManager::getBRD(int port, vector<int>& channels, vector<string>& pars)");
8924
 
8925
    if (pars.size() < 1)
8926
    {
8927
        MSG_ERROR("Expecting at least 1 parameter but got " << pars.size() << "! Ignoring command.");
8928
        return;
8929
    }
8930
 
8931
    TError::clear();
8932
    int btState = atoi(pars[0].c_str());
8933
 
193 andreas 8934
    vector<TMap::MAP_T> map = findButtons(port, channels);
107 andreas 8935
 
8936
    if (TError::isError() || map.empty())
8937
        return;
8938
 
8939
    vector<Button::TButton *> buttons = collectButtons(map);
8940
 
8941
    if (buttons.size() > 0)
8942
    {
110 andreas 8943
        Button::TButton *bt = buttons[0];
107 andreas 8944
 
110 andreas 8945
        if (btState == 0)       // All instances?
107 andreas 8946
        {
110 andreas 8947
            int bst = bt->getNumberInstances();
107 andreas 8948
 
110 andreas 8949
            for (int i = 0; i < bst; i++)
107 andreas 8950
            {
110 andreas 8951
                string bname = bt->getBorderStyle(i);
300 andreas 8952
                sendCustomEvent(i + 1, (int)bname.length(), 0, bname, 1014, bt->getChannelPort(), bt->getChannelNumber());
107 andreas 8953
            }
8954
        }
110 andreas 8955
        else
8956
        {
8957
            string bname = bt->getBorderStyle(btState-1);
300 andreas 8958
            sendCustomEvent(btState, (int)bname.length(), 0, bname, 1014, bt->getChannelPort(), bt->getChannelNumber());
110 andreas 8959
        }
107 andreas 8960
    }
8961
}
8962
 
60 andreas 8963
/**
16 andreas 8964
 * Set the button size and its position on the page.
8965
 */
8966
void TPageManager::doBSP(int port, vector<int>& channels, vector<string>& pars)
8967
{
8968
    DECL_TRACER("TPageManager::doBSP(int port, vector<int>& channels, vector<string>& pars)");
8969
 
8970
    if (pars.size() < 1)
8971
    {
8972
        MSG_ERROR("Expecting at least 1 parameter but got " << pars.size() << "! Ignoring command.");
341 andreas 8973
#if TESTMODE == 1
8974
        setAllDone();
8975
#endif
16 andreas 8976
        return;
8977
    }
8978
 
8979
    TError::clear();
8980
    bool bLeft = false, bTop = false, bRight = false, bBottom = false;
8981
    int x, y;
8982
 
83 andreas 8983
    if (pars.size() > 0)
16 andreas 8984
    {
83 andreas 8985
        vector<string>::iterator iter;
8986
 
8987
        for (iter = pars.begin(); iter != pars.end(); iter++)
8988
        {
8989
            if (iter->compare("left") == 0)
8990
                bLeft = true;
8991
            else if (iter->compare("top") == 0)
8992
                bTop = true;
8993
            else if (iter->compare("right") == 0)
8994
                bRight = true;
8995
            else if (iter->compare("bottom") == 0)
8996
                bBottom = true;
8997
        }
16 andreas 8998
    }
8999
 
193 andreas 9000
    vector<TMap::MAP_T> map = findButtons(port, channels);
16 andreas 9001
 
9002
    if (TError::isError() || map.empty())
9003
        return;
9004
 
9005
    vector<Button::TButton *> buttons = collectButtons(map);
409 andreas 9006
    x = y = 0;
16 andreas 9007
 
83 andreas 9008
    if (buttons.size() > 0)
16 andreas 9009
    {
83 andreas 9010
        vector<Button::TButton *>::iterator mapIter;
16 andreas 9011
 
83 andreas 9012
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
9013
        {
9014
            Button::TButton *bt = *mapIter;
16 andreas 9015
 
83 andreas 9016
            if (bLeft)
9017
                x = 0;
16 andreas 9018
 
83 andreas 9019
            if (bTop)
9020
                y = 0;
16 andreas 9021
 
341 andreas 9022
            if (bRight || bBottom)
16 andreas 9023
            {
83 andreas 9024
                ulong handle = bt->getHandle();
9025
                int parentID = (handle >> 16) & 0x0000ffff;
9026
                int pwidth = 0;
341 andreas 9027
                int pheight = 0;
16 andreas 9028
 
83 andreas 9029
                if (parentID < 500)
16 andreas 9030
                {
83 andreas 9031
                    TPage *pg = getPage(parentID);
9032
 
9033
                    if (!pg)
9034
                    {
9035
                        MSG_ERROR("Internal error: Page " << parentID << " not found!");
9036
                        return;
9037
                    }
9038
 
9039
                    pwidth = pg->getWidth();
341 andreas 9040
                    pheight = pg->getHeight();
16 andreas 9041
                }
83 andreas 9042
                else
9043
                {
9044
                    TSubPage *spg = getSubPage(parentID);
16 andreas 9045
 
83 andreas 9046
                    if (!spg)
9047
                    {
9048
                        MSG_ERROR("Internal error: Subpage " << parentID << " not found!");
9049
                        return;
9050
                    }
16 andreas 9051
 
83 andreas 9052
                    pwidth = spg->getWidth();
341 andreas 9053
                    pheight = spg->getHeight();
16 andreas 9054
                }
9055
 
341 andreas 9056
                if (bRight)
9057
                    x = pwidth - bt->getWidth();
9058
 
9059
                if (bBottom)
9060
                    y = pheight - bt->getHeight();
16 andreas 9061
            }
9062
 
341 andreas 9063
            bt->setLeftTop(x, y);
9064
#if TESTMODE == 1
9065
            if (_gTestMode)
83 andreas 9066
            {
341 andreas 9067
                int left = bt->getLeftPosition();
9068
                int top = bt->getTopPosition();
9069
                string res = intToString(left) + "," + intToString(top);
9070
                _gTestMode->setResult(res);
16 andreas 9071
            }
341 andreas 9072
#endif
16 andreas 9073
        }
9074
    }
341 andreas 9075
#if TESTMODE == 1
9076
    setDone();
9077
#endif
16 andreas 9078
}
9079
 
9080
/**
107 andreas 9081
 * Submit text for text area buttons. This command causes the text areas to
9082
 * send their text as strings to the NetLinx Master.
9083
 */
9084
void TPageManager::doBSM(int port, vector<int>& channels, vector<string>&)
9085
{
9086
    DECL_TRACER("TPageManager::doBSM(int port, vector<int>& channels, vector<string>& pars)");
9087
 
9088
    TError::clear();
193 andreas 9089
    vector<TMap::MAP_T> map = findButtons(port, channels);
107 andreas 9090
 
9091
    if (TError::isError() || map.empty())
341 andreas 9092
    {
9093
#if TESTMODE == 1
9094
        setAllDone();
9095
#endif
107 andreas 9096
        return;
341 andreas 9097
    }
107 andreas 9098
 
9099
    vector<Button::TButton *> buttons = collectButtons(map);
9100
 
9101
    if (buttons.size() > 0)
9102
    {
9103
        vector<Button::TButton *>::iterator mapIter;
9104
 
9105
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
9106
        {
9107
            Button::TButton *bt = *mapIter;
9108
 
195 andreas 9109
            if (bt->getButtonType() != TEXT_INPUT && bt->getButtonType() != GENERAL)
341 andreas 9110
            {
9111
#if TESTMODE == 1
9112
                setAllDone();
9113
#endif
107 andreas 9114
                return;
341 andreas 9115
            }
107 andreas 9116
 
9117
            amx::ANET_SEND scmd;
9118
            scmd.port = bt->getChannelPort();
9119
            scmd.channel = bt->getChannelNumber();
9120
            scmd.ID = scmd.channel;
9121
            scmd.msg = bt->getText(0);
9122
            scmd.MC = 0x008b;       // string value
9123
 
9124
            if (gAmxNet)
9125
                gAmxNet->sendCommand(scmd);
9126
            else
9127
                MSG_WARNING("Missing global class TAmxNet. Can't send message!");
9128
 
9129
        }
9130
    }
9131
}
9132
 
9133
/**
9134
 * Set the sound played when a button is pressed. If the sound name is blank
9135
 * the sound is then cleared. If the sound name is not matched, the button
9136
 * sound is not changed.
9137
 */
9138
void TPageManager::doBSO(int port, vector<int>& channels, vector<string>& pars)
9139
{
9140
    DECL_TRACER("TPageManager::doBSO(int port, vector<int>& channels, vector<string>& pars)");
9141
 
9142
    if (pars.size() < 2)
9143
    {
9144
        MSG_ERROR("Expecting 2 parameters but got " << pars.size() << "! Ignoring command.");
9145
        return;
9146
    }
9147
 
9148
    if (!gPrjResources)
9149
        return;
9150
 
9151
    TError::clear();
9152
    int btState = atoi(pars[0].c_str());
9153
    string sound = pars[1];
9154
 
9155
    if (!soundExist(sound))
9156
        return;
9157
 
193 andreas 9158
    vector<TMap::MAP_T> map = findButtons(port, channels);
107 andreas 9159
 
9160
    if (TError::isError() || map.empty())
9161
        return;
9162
 
9163
    vector<Button::TButton *> buttons = collectButtons(map);
9164
 
9165
    if (buttons.size() > 0)
9166
    {
9167
        vector<Button::TButton *>::iterator mapIter;
9168
 
9169
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
9170
        {
9171
            Button::TButton *bt = *mapIter;
9172
 
9173
            if (btState == 0)
9174
            {
9175
                int bst = bt->getNumberInstances();
9176
 
9177
                for (int i = 0; i < bst; i++)
9178
                    bt->setSound(sound, i);
9179
            }
9180
            else
9181
                bt->setSound(sound, btState-1);
9182
        }
9183
    }
9184
}
9185
 
9186
/**
16 andreas 9187
 * Set the button word wrap feature to those buttons with a defined address
9188
 * range. By default, word-wrap is Off.
9189
 */
9190
void TPageManager::doBWW(int port, vector<int>& channels, vector<string>& pars)
9191
{
9192
    DECL_TRACER("TPageManager::doBWW(int port, vector<int>& channels, vector<string>& pars)");
9193
 
9194
    if (pars.size() < 1)
9195
    {
9196
        MSG_ERROR("Expecting 1 parameter but got " << pars.size() << "! Ignoring command.");
9197
        return;
9198
    }
9199
 
9200
    TError::clear();
9201
    int btState = atoi(pars[0].c_str());
9202
 
193 andreas 9203
    vector<TMap::MAP_T> map = findButtons(port, channels);
16 andreas 9204
 
9205
    if (TError::isError() || map.empty())
9206
        return;
9207
 
9208
    vector<Button::TButton *> buttons = collectButtons(map);
9209
 
83 andreas 9210
    if (buttons.size() > 0)
16 andreas 9211
    {
83 andreas 9212
        vector<Button::TButton *>::iterator mapIter;
16 andreas 9213
 
83 andreas 9214
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
16 andreas 9215
        {
83 andreas 9216
            Button::TButton *bt = *mapIter;
252 andreas 9217
//            setButtonCallbacks(bt);
16 andreas 9218
 
83 andreas 9219
            if (btState == 0)       // All instances?
9220
            {
9221
                int bst = bt->getNumberInstances();
9222
                MSG_DEBUG("Setting word wrap on all " << bst << " instances...");
9223
 
9224
                for (int i = 0; i < bst; i++)
110 andreas 9225
                    bt->setTextWordWrap(true, i);
83 andreas 9226
            }
9227
            else
110 andreas 9228
                bt->setTextWordWrap(true, btState - 1);
16 andreas 9229
        }
9230
    }
9231
}
9232
 
108 andreas 9233
void TPageManager::getBWW(int port, vector<int>& channels, vector<string>& pars)
9234
{
9235
    DECL_TRACER("TPageManager::getBWW(int port, vector<int>& channels, vector<string>& pars)");
9236
 
9237
    if (pars.size() < 1)
9238
    {
9239
        MSG_ERROR("Expecting at least 1 parameter but got " << pars.size() << "! Ignoring command.");
9240
        return;
9241
    }
9242
 
9243
    TError::clear();
9244
    int btState = atoi(pars[0].c_str());
9245
 
193 andreas 9246
    vector<TMap::MAP_T> map = findButtons(port, channels);
108 andreas 9247
 
9248
    if (TError::isError() || map.empty())
9249
        return;
9250
 
9251
    vector<Button::TButton *> buttons = collectButtons(map);
9252
 
9253
    if (buttons.size() > 0)
9254
    {
110 andreas 9255
        Button::TButton *bt = buttons[0];
108 andreas 9256
 
110 andreas 9257
        if (btState == 0)       // All instances?
108 andreas 9258
        {
110 andreas 9259
            int bst = bt->getNumberInstances();
108 andreas 9260
 
110 andreas 9261
            for (int i = 0; i < bst; i++)
9262
                sendCustomEvent(i + 1, bt->getTextWordWrap(i), 0, "", 1010, bt->getChannelPort(), bt->getChannelNumber());
108 andreas 9263
        }
110 andreas 9264
        else
9265
            sendCustomEvent(btState, bt->getTextWordWrap(btState-1), 0, "", 1010, bt->getChannelPort(), bt->getChannelNumber());
108 andreas 9266
    }
9267
}
9268
 
16 andreas 9269
/**
9270
 * Clear all page flips from a button.
9271
 */
22 andreas 9272
void TPageManager::doCPF(int port, vector<int>& channels, vector<string>&)
16 andreas 9273
{
9274
    DECL_TRACER("TPageManager::doCPF(int port, vector<int>& channels, vector<string>& pars)");
9275
 
9276
    TError::clear();
193 andreas 9277
    vector<TMap::MAP_T> map = findButtons(port, channels);
16 andreas 9278
 
9279
    if (TError::isError() || map.empty())
9280
        return;
9281
 
9282
    vector<Button::TButton *> buttons = collectButtons(map);
9283
 
83 andreas 9284
    if (buttons.size() > 0)
16 andreas 9285
    {
83 andreas 9286
        vector<Button::TButton *>::iterator mapIter;
9287
 
9288
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
9289
        {
9290
            Button::TButton *bt = *mapIter;
252 andreas 9291
//            setButtonCallbacks(bt);
83 andreas 9292
            bt->clearPushFunctions();
9293
        }
16 andreas 9294
    }
9295
}
9296
 
9297
/**
9298
 * Delete page flips from button if it already exists.
9299
 */
9300
void TPageManager::doDPF(int port, vector<int>& channels, vector<string>& pars)
9301
{
9302
    DECL_TRACER("TPageManager::doDPF(int port, vector<int>& channels, vector<string>& pars)");
9303
 
9304
    if (pars.size() < 1)
9305
    {
9306
        MSG_ERROR("Expecting at least 1 parameter but got " << pars.size() << "! Ignoring command.");
9307
        return;
9308
    }
9309
 
9310
    TError::clear();
9311
    string action = pars[0];
9312
    string pname;
9313
 
9314
    if (pars.size() >= 2)
9315
    {
9316
        pname = pars[1];
9317
        vector<Button::TButton *> list;
9318
        // First we search for a subpage because this is more likely
9319
        TSubPage *spg = getSubPage(pname);
9320
 
9321
        if (spg)
9322
            list = spg->getButtons(port, channels[0]);
9323
        else    // Then for a page
9324
        {
9325
            TPage *pg = getPage(pname);
9326
 
9327
            if (pg)
9328
                list = pg->getButtons(port, channels[0]);
9329
            else
9330
            {
9331
                MSG_WARNING("The name " << pname << " doesn't name either a page or a subpage!");
9332
                return;
9333
            }
9334
        }
9335
 
9336
        if (list.empty())
9337
            return;
9338
 
9339
        vector<Button::TButton *>::iterator it;
9340
 
9341
        for (it = list.begin(); it != list.end(); it++)
9342
        {
9343
            Button::TButton *bt = *it;
252 andreas 9344
//            setButtonCallbacks(bt);
16 andreas 9345
            bt->clearPushFunction(action);
9346
        }
9347
 
9348
        return;
9349
    }
9350
 
9351
    // Here we don't have a page name
193 andreas 9352
    vector<TMap::MAP_T> map = findButtons(port, channels);
16 andreas 9353
 
9354
    if (TError::isError() || map.empty())
9355
        return;
9356
 
9357
    vector<Button::TButton *> buttons = collectButtons(map);
9358
 
83 andreas 9359
    if (buttons.size() > 0)
16 andreas 9360
    {
83 andreas 9361
        vector<Button::TButton *>::iterator mapIter;
9362
 
9363
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
9364
        {
9365
            Button::TButton *bt = *mapIter;
252 andreas 9366
//            setButtonCallbacks(bt);
83 andreas 9367
            bt->clearPushFunction(action);
9368
        }
16 andreas 9369
    }
9370
}
9371
 
9372
/**
9373
 * Enable or disable buttons with a set variable text range.
9374
 */
9375
void TPageManager::doENA(int port, vector<int>& channels, vector<string>& pars)
9376
{
9377
    DECL_TRACER("TPageManager::doENA(int port, vector<int>& channels, vector<string>& pars)");
9378
 
9379
    if (pars.empty())
9380
    {
9381
        MSG_ERROR("Expecting 1 parameter but got none! Ignoring command.");
341 andreas 9382
#if TESTMODE == 1
9383
        setAllDone();
9384
#endif
16 andreas 9385
        return;
9386
    }
9387
 
9388
    TError::clear();
9389
    int cvalue = atoi(pars[0].c_str());
9390
 
193 andreas 9391
    vector<TMap::MAP_T> map = findButtons(port, channels);
16 andreas 9392
 
9393
    if (TError::isError() || map.empty())
341 andreas 9394
    {
9395
#if TESTMODE == 1
9396
        setAllDone();
9397
#endif
16 andreas 9398
        return;
341 andreas 9399
    }
16 andreas 9400
 
9401
    vector<Button::TButton *> buttons = collectButtons(map);
9402
 
83 andreas 9403
    if (buttons.size() > 0)
16 andreas 9404
    {
83 andreas 9405
        vector<Button::TButton *>::iterator mapIter;
9406
 
9407
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
9408
        {
9409
            Button::TButton *bt = *mapIter;
9410
            bt->setEnable(((cvalue)?true:false));
341 andreas 9411
#if TESTMODE == 1
9412
            __success = true;
9413
 
9414
            if (_gTestMode)
9415
                _gTestMode->setResult(intToString(cvalue));
9416
#endif
83 andreas 9417
        }
16 andreas 9418
    }
341 andreas 9419
#if TESTMODE == 1
9420
    setAllDone();
9421
#endif
16 andreas 9422
}
9423
 
9424
/**
9425
 * Set a font to a specific Font ID value for those buttons with a defined
9426
 * address range. Font ID numbers are generated by the TPDesign4 programmers
9427
 * report.
9428
 */
9429
void TPageManager::doFON(int port, vector<int>& channels, vector<string>& pars)
9430
{
9431
    DECL_TRACER("TPageManager::doFON(int port, vector<int>& channels, vector<string>& pars)");
9432
 
9433
    if (pars.size() < 2)
9434
    {
9435
        MSG_ERROR("Expecting 2 parameters but got " << pars.size() << "! Ignoring command.");
342 andreas 9436
#if TESTMODE == 1
9437
        setAllDone();
9438
#endif
16 andreas 9439
        return;
9440
    }
9441
 
9442
    TError::clear();
342 andreas 9443
    int btState = atoi(pars[0].c_str()) - 1;
16 andreas 9444
    int fvalue = atoi(pars[1].c_str());
9445
 
193 andreas 9446
    vector<TMap::MAP_T> map = findButtons(port, channels);
16 andreas 9447
 
9448
    if (TError::isError() || map.empty())
9449
        return;
9450
 
9451
    vector<Button::TButton *> buttons = collectButtons(map);
9452
 
83 andreas 9453
    if (buttons.size() > 0)
16 andreas 9454
    {
83 andreas 9455
        vector<Button::TButton *>::iterator mapIter;
16 andreas 9456
 
83 andreas 9457
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
16 andreas 9458
        {
83 andreas 9459
            Button::TButton *bt = *mapIter;
342 andreas 9460
            bt->setFont(fvalue, btState);
9461
#if TESTMODE == 1
9462
            if (_gTestMode)
9463
                _gTestMode->setResult(intToString(bt->getFontIndex(btState < 0 ? 0 : btState)));
9464
#endif
16 andreas 9465
        }
9466
    }
342 andreas 9467
#if TESTMODE == 1
9468
    setDone();
9469
#endif
16 andreas 9470
}
9471
 
108 andreas 9472
void TPageManager::getFON(int port, vector<int>& channels, vector<string>& pars)
9473
{
9474
    DECL_TRACER("TPageManager::getFON(int port, vector<int>& channels, vector<string>& pars)");
9475
 
9476
    if (pars.size() < 1)
9477
    {
9478
        MSG_ERROR("Expecting at least 1 parameter but got " << pars.size() << "! Ignoring command.");
342 andreas 9479
#if TESTMODE == 1
9480
        setAllDone();
9481
#endif
108 andreas 9482
        return;
9483
    }
9484
 
9485
    TError::clear();
9486
    int btState = atoi(pars[0].c_str());
9487
 
193 andreas 9488
    vector<TMap::MAP_T> map = findButtons(port, channels);
108 andreas 9489
 
9490
    if (TError::isError() || map.empty())
342 andreas 9491
    {
9492
#if TESTMODE == 1
9493
        setAllDone();
9494
#endif
108 andreas 9495
        return;
342 andreas 9496
    }
108 andreas 9497
 
9498
    vector<Button::TButton *> buttons = collectButtons(map);
9499
 
9500
    if (buttons.size() > 0)
9501
    {
110 andreas 9502
        Button::TButton *bt = buttons[0];
108 andreas 9503
 
110 andreas 9504
        if (btState == 0)       // All instances?
108 andreas 9505
        {
110 andreas 9506
            int bst = bt->getNumberInstances();
108 andreas 9507
 
110 andreas 9508
            for (int i = 0; i < bst; i++)
9509
                sendCustomEvent(i + 1, bt->getFontIndex(i), 0, "", 1007, bt->getChannelPort(), bt->getChannelNumber());
108 andreas 9510
        }
110 andreas 9511
        else
9512
            sendCustomEvent(btState, bt->getFontIndex(btState - 1), 0, "", 1007, bt->getChannelPort(), bt->getChannelNumber());
342 andreas 9513
#if TESTMODE == 1
9514
        if (_gTestMode)
9515
            _gTestMode->setResult(intToString(bt->getFontIndex(btState < 0 ? 0 : btState)));
9516
#endif
108 andreas 9517
    }
342 andreas 9518
#if TESTMODE == 1
9519
    __success = true;
9520
    setAllDone();
9521
#endif
108 andreas 9522
}
9523
 
388 andreas 9524
void TPageManager::doGDI(int port, vector<int>& channels, vector<std::string>& pars)
9525
{
9526
    DECL_TRACER("TPageManager::doGDI(int port, vector<int>& channels, vector<std::string>& pars)");
9527
 
9528
    if (pars.size() < 1)
9529
    {
9530
        MSG_ERROR("Expecting 1 parameter but got " << pars.size() << "! Ignoring command.");
9531
        return;
9532
    }
9533
 
9534
    TError::clear();
9535
    int inc = atoi(pars[0].c_str());
9536
 
9537
    if (inc < 0)
9538
    {
9539
        MSG_ERROR("Invalid drag increment of " << inc << "!");
9540
        return;
9541
    }
9542
 
9543
    vector<TMap::MAP_T> map = findButtons(port, channels);
9544
 
9545
    if (TError::isError() || map.empty())
9546
        return;
9547
 
9548
    vector<Button::TButton *> buttons = collectButtons(map);
9549
 
9550
    if (buttons.size() > 0)
9551
    {
9552
        vector<Button::TButton *>::iterator mapIter;
9553
 
9554
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
9555
        {
9556
            Button::TButton *bt = *mapIter;
9557
            bt->setBargraphDragIncrement(inc);
9558
        }
9559
    }
9560
}
416 andreas 9561
/*
9562
 * Invert the joystick axis to move the origin to another corner.
9563
 */
9564
void TPageManager::doGIV(int port, vector<int>& channels, vector<std::string>& pars)
388 andreas 9565
{
416 andreas 9566
    DECL_TRACER("TPageManager::doGIV(int port, vector<int>& channels, vector<std::string>& pars)");
9567
 
9568
    if (pars.empty())
9569
        return;
9570
 
9571
    TError::clear();
9572
    int inv = atoi(pars[0].c_str());
9573
 
9574
    if (inv < 0 || inv > 3)
9575
    {
9576
        MSG_ERROR("Invalid invert type " << inv);
9577
        return;
9578
    }
9579
 
9580
    vector<TMap::MAP_T> map = findButtons(port, channels);
9581
 
9582
    if (TError::isError() || map.empty())
9583
        return;
9584
 
9585
    vector<Button::TButton *> buttons = collectButtons(map);
9586
 
9587
    if (buttons.size() > 0)
9588
    {
9589
        vector<Button::TButton *>::iterator mapIter;
9590
 
9591
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
9592
        {
9593
            Button::TButton *bt = *mapIter;
9594
            bt->setBargraphInvert(inv);
9595
        }
9596
    }
388 andreas 9597
}
416 andreas 9598
 
16 andreas 9599
/**
60 andreas 9600
 * Change the bargraph upper limit.
9601
 */
9602
void TPageManager::doGLH(int port, vector<int>& channels, vector<std::string>& pars)
9603
{
9604
    DECL_TRACER("TPageManager::doGLH(int port, vector<int>& channels, vector<std::string>& pars)");
9605
 
9606
    if (pars.size() < 1)
9607
    {
9608
        MSG_ERROR("Expecting 1 parameter but got " << pars.size() << "! Ignoring command.");
9609
        return;
9610
    }
9611
 
9612
    TError::clear();
9613
    int limit = atoi(pars[0].c_str());
9614
 
9615
    if (limit < 1)
9616
    {
9617
        MSG_ERROR("Invalid upper limit " << limit << "!");
9618
        return;
9619
    }
9620
 
193 andreas 9621
    vector<TMap::MAP_T> map = findButtons(port, channels);
60 andreas 9622
 
9623
    if (TError::isError() || map.empty())
9624
        return;
9625
 
9626
    vector<Button::TButton *> buttons = collectButtons(map);
9627
 
83 andreas 9628
    if (buttons.size() > 0)
60 andreas 9629
    {
83 andreas 9630
        vector<Button::TButton *>::iterator mapIter;
9631
 
9632
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
9633
        {
9634
            Button::TButton *bt = *mapIter;
9635
            bt->setBargraphUpperLimit(limit);
9636
        }
60 andreas 9637
    }
9638
}
9639
 
9640
/**
9641
 * Change the bargraph lower limit.
9642
 */
9643
void TPageManager::doGLL(int port, vector<int>& channels, vector<std::string>& pars)
9644
{
9645
    DECL_TRACER("TPageManager::doGLL(int port, vector<int>& channels, vector<std::string>& pars)");
9646
 
9647
    if (pars.size() < 1)
9648
    {
9649
        MSG_ERROR("Expecting 1 parameter but got " << pars.size() << "! Ignoring command.");
9650
        return;
9651
    }
9652
 
9653
    TError::clear();
9654
    int limit = atoi(pars[0].c_str());
9655
 
9656
    if (limit < 1)
9657
    {
9658
        MSG_ERROR("Invalid lower limit " << limit << "!");
9659
        return;
9660
    }
9661
 
193 andreas 9662
    vector<TMap::MAP_T> map = findButtons(port, channels);
60 andreas 9663
 
9664
    if (TError::isError() || map.empty())
9665
        return;
9666
 
9667
    vector<Button::TButton *> buttons = collectButtons(map);
9668
 
83 andreas 9669
    if (buttons.size() > 0)
60 andreas 9670
    {
83 andreas 9671
        vector<Button::TButton *>::iterator mapIter;
9672
 
9673
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
9674
        {
9675
            Button::TButton *bt = *mapIter;
9676
            bt->setBargraphLowerLimit(limit);
9677
        }
60 andreas 9678
    }
9679
}
9680
 
416 andreas 9681
/*
9682
 * Change the bargraph slider color or joystick cursor color.
9683
 */
108 andreas 9684
void TPageManager::doGSC(int port, vector<int>& channels, vector<string>& pars)
9685
{
9686
    DECL_TRACER("TPageManager::doGSC(int port, vector<int>& channels, vector<string>& pars)");
9687
 
9688
    if (pars.size() < 1)
9689
    {
9690
        MSG_ERROR("Expecting 1 parameter but got " << pars.size() << "! Ignoring command.");
9691
        return;
9692
    }
9693
 
9694
    TError::clear();
9695
    string color = pars[0];
193 andreas 9696
    vector<TMap::MAP_T> map = findButtons(port, channels);
108 andreas 9697
 
9698
    if (TError::isError() || map.empty())
9699
        return;
9700
 
9701
    vector<Button::TButton *> buttons = collectButtons(map);
9702
 
9703
    if (buttons.size() > 0)
9704
    {
9705
        vector<Button::TButton *>::iterator mapIter;
9706
 
9707
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
9708
        {
9709
            Button::TButton *bt = *mapIter;
9710
            bt->setBargraphSliderColor(color);
9711
        }
9712
    }
9713
}
9714
 
361 andreas 9715
/*
388 andreas 9716
 * Set bargraph ramp down time in 1/10 seconds.
9717
 */
9718
void TPageManager::doGRD(int port, vector<int>& channels, vector<string>& pars)
9719
{
9720
    DECL_TRACER("TPageManager::doGRD(int port, vector<int>& channels, vector<string>& pars)");
9721
 
9722
    if (pars.size() < 1)
9723
    {
9724
        MSG_ERROR("Expecting 1 parameter but got " << pars.size() << "! Ignoring command.");
9725
        return;
9726
    }
9727
 
9728
    TError::clear();
9729
    int t = atoi(pars[0].c_str());
9730
 
9731
    if (t < 0)
9732
    {
9733
        MSG_ERROR("Invalid ramp down time limit " << t << "!");
9734
        return;
9735
    }
9736
 
9737
    vector<TMap::MAP_T> map = findButtons(port, channels);
9738
 
9739
    if (TError::isError() || map.empty())
9740
        return;
9741
 
9742
    vector<Button::TButton *> buttons = collectButtons(map);
9743
 
9744
    if (buttons.size() > 0)
9745
    {
9746
        vector<Button::TButton *>::iterator mapIter;
9747
 
9748
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
9749
        {
9750
            Button::TButton *bt = *mapIter;
9751
            bt->setBargraphRampDownTime(t);
9752
        }
9753
    }
9754
}
9755
 
9756
/*
9757
 * Set bargraph ramp up time in 1/10 seconds.
9758
 */
9759
void TPageManager::doGRU(int port, vector<int>& channels, vector<string>& pars)
9760
{
9761
    DECL_TRACER("TPageManager::doGRU(int port, vector<int>& channels, vector<string>& pars)");
9762
 
9763
    if (pars.size() < 1)
9764
    {
9765
        MSG_ERROR("Expecting 1 parameter but got " << pars.size() << "! Ignoring command.");
9766
        return;
9767
    }
9768
 
9769
    TError::clear();
9770
    int t = atoi(pars[0].c_str());
9771
 
9772
    if (t < 0)
9773
    {
9774
        MSG_ERROR("Invalid ramp up time limit " << t << "!");
9775
        return;
9776
    }
9777
 
9778
    vector<TMap::MAP_T> map = findButtons(port, channels);
9779
 
9780
    if (TError::isError() || map.empty())
9781
        return;
9782
 
9783
    vector<Button::TButton *> buttons = collectButtons(map);
9784
 
9785
    if (buttons.size() > 0)
9786
    {
9787
        vector<Button::TButton *>::iterator mapIter;
9788
 
9789
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
9790
        {
9791
            Button::TButton *bt = *mapIter;
9792
            bt->setBargraphRampUpTime(t);
9793
        }
9794
    }
9795
}
9796
 
9797
/*
361 andreas 9798
 * Change the bargraph slider name or joystick cursor name.
9799
 */
9800
void TPageManager::doGSN(int port, vector<int>& channels, vector<string>& pars)
9801
{
9802
    DECL_TRACER("TPageManager::doGSN(int port, vector<int>& channels, vector<string>& pars)");
9803
 
9804
    if (pars.size() < 1)
9805
    {
9806
        MSG_ERROR("Expecting 1 parameter but got " << pars.size() << "! Ignoring command.");
9807
        return;
9808
    }
9809
 
9810
    TError::clear();
9811
    string name = pars[0];
9812
    vector<TMap::MAP_T> map = findButtons(port, channels);
9813
 
9814
    if (TError::isError() || map.empty())
9815
        return;
9816
 
9817
    vector<Button::TButton *> buttons = collectButtons(map);
9818
 
9819
    if (buttons.size() > 0)
9820
    {
9821
        vector<Button::TButton *>::iterator mapIter;
9822
 
9823
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
9824
        {
9825
            Button::TButton *bt = *mapIter;
9826
            bt->setBargraphSliderName(name);
9827
        }
9828
    }
9829
}
9830
 
60 andreas 9831
/**
14 andreas 9832
 * Set the icon to a button.
9833
 */
9834
void TPageManager::doICO(int port, vector<int>& channels, vector<string>& pars)
9835
{
9836
    DECL_TRACER("TPageManager::doICO(int port, vector<int>& channels, vector<string>& pars)");
9837
 
9838
    if (pars.size() < 2)
9839
    {
9840
        MSG_ERROR("Expecting 2 parameters but got " << pars.size() << "! Ignoring command.");
9841
        return;
9842
    }
9843
 
16 andreas 9844
    TError::clear();
14 andreas 9845
    int btState = atoi(pars[0].c_str());
9846
    int iconIdx = atoi(pars[1].c_str());
9847
 
193 andreas 9848
    vector<TMap::MAP_T> map = findButtons(port, channels);
14 andreas 9849
 
9850
    if (TError::isError() || map.empty())
9851
        return;
9852
 
9853
    vector<Button::TButton *> buttons = collectButtons(map);
9854
 
83 andreas 9855
    if (buttons.size() > 0)
14 andreas 9856
    {
83 andreas 9857
        vector<Button::TButton *>::iterator mapIter;
14 andreas 9858
 
83 andreas 9859
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
14 andreas 9860
        {
83 andreas 9861
            Button::TButton *bt = *mapIter;
14 andreas 9862
 
83 andreas 9863
            if (btState == 0)       // All instances?
14 andreas 9864
            {
316 andreas 9865
                if (iconIdx > 0)
9866
                    bt->setIcon(iconIdx, -1);
9867
                else
9868
                    bt->revokeIcon(-1);
14 andreas 9869
            }
83 andreas 9870
            else if (iconIdx > 0)
9871
                bt->setIcon(iconIdx, btState - 1);
9872
            else
9873
                bt->revokeIcon(btState - 1);
14 andreas 9874
        }
9875
    }
9876
}
9877
 
108 andreas 9878
void TPageManager::getICO(int port, vector<int>& channels, vector<string>& pars)
9879
{
9880
    DECL_TRACER("TPageManager::getICO(int port, vector<int>& channels, vector<string>& pars)");
9881
 
9882
    if (pars.size() < 1)
9883
    {
9884
        MSG_ERROR("Expecting at least 1 parameter but got " << pars.size() << "! Ignoring command.");
9885
        return;
9886
    }
9887
 
9888
    TError::clear();
9889
    int btState = atoi(pars[0].c_str());
9890
 
193 andreas 9891
    vector<TMap::MAP_T> map = findButtons(port, channels);
108 andreas 9892
 
9893
    if (TError::isError() || map.empty())
9894
        return;
9895
 
9896
    vector<Button::TButton *> buttons = collectButtons(map);
9897
 
9898
    if (buttons.size() > 0)
9899
    {
110 andreas 9900
        Button::TButton *bt = buttons[0];
108 andreas 9901
 
110 andreas 9902
        if (btState == 0)       // All instances?
108 andreas 9903
        {
110 andreas 9904
            int bst = bt->getNumberInstances();
108 andreas 9905
 
110 andreas 9906
            for (int i = 0; i < bst; i++)
9907
                sendCustomEvent(i + 1, bt->getIconIndex(i), 0, "", 1003, bt->getChannelPort(), bt->getChannelNumber());
108 andreas 9908
        }
110 andreas 9909
        else
9910
            sendCustomEvent(btState, bt->getIconIndex(btState - 1), 0, "", 1003, bt->getChannelPort(), bt->getChannelNumber());
108 andreas 9911
    }
9912
}
9913
 
14 andreas 9914
/**
108 andreas 9915
 * Set bitmap/picture alignment using a numeric keypad layout for those buttons
9916
 * with a defined address range. The alignment of 0 is followed by
9917
 * ',<left>,<top>'. The left and top coordinates are relative to the upper left
9918
 * corner of the button.
9919
 */
9920
void TPageManager::doJSB(int port, vector<int>& channels, vector<string>& pars)
9921
{
9922
    DECL_TRACER("TPageManager::doJSB(int port, vector<int>& channels, vector<string>& pars)");
9923
 
9924
    if (pars.size() < 2)
9925
    {
9926
        MSG_ERROR("Expecting at least 2 parameters but got less! Ignoring command.");
9927
        return;
9928
    }
9929
 
9930
    TError::clear();
9931
    int btState = atoi(pars[0].c_str());
9932
    int align = atoi(pars[1].c_str());
9933
    int x = 0, y = 0;
9934
 
9935
    if (!align && pars.size() >= 3)
9936
    {
9937
        x = atoi(pars[2].c_str());
9938
 
9939
        if (pars.size() >= 4)
9940
            y = atoi(pars[3].c_str());
9941
    }
9942
 
193 andreas 9943
    vector<TMap::MAP_T> map = findButtons(port, channels);
108 andreas 9944
 
9945
    if (TError::isError() || map.empty())
9946
        return;
9947
 
9948
    vector<Button::TButton *> buttons = collectButtons(map);
9949
 
9950
    if (buttons.size() > 0)
9951
    {
9952
        vector<Button::TButton *>::iterator mapIter;
9953
 
9954
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
9955
        {
9956
            Button::TButton *bt = *mapIter;
9957
 
9958
            if (btState == 0)
9959
                bt->setBitmapJustification(align, x, y, -1);
9960
            else
9961
                bt->setBitmapJustification(align, x, y, btState-1);
9962
        }
9963
    }
9964
}
9965
 
9966
void TPageManager::getJSB(int port, vector<int>& channels, vector<string>& pars)
9967
{
9968
    DECL_TRACER("TPageManager::getJSB(int port, vector<int>& channels, vector<string>& pars)");
9969
 
9970
    if (pars.size() < 1)
9971
    {
9972
        MSG_ERROR("Expecting at least 1 parameter but got " << pars.size() << "! Ignoring command.");
9973
        return;
9974
    }
9975
 
9976
    TError::clear();
9977
    int btState = atoi(pars[0].c_str());
9978
    int j, x, y;
9979
 
193 andreas 9980
    vector<TMap::MAP_T> map = findButtons(port, channels);
108 andreas 9981
 
9982
    if (TError::isError() || map.empty())
9983
        return;
9984
 
9985
    vector<Button::TButton *> buttons = collectButtons(map);
9986
 
9987
    if (buttons.size() > 0)
9988
    {
110 andreas 9989
        Button::TButton *bt = buttons[0];
108 andreas 9990
 
110 andreas 9991
        if (btState == 0)       // All instances?
108 andreas 9992
        {
110 andreas 9993
            int bst = bt->getNumberInstances();
108 andreas 9994
 
110 andreas 9995
            for (int i = 0; i < bst; i++)
108 andreas 9996
            {
110 andreas 9997
                j = bt->getBitmapJustification(&x, &y, i);
9998
                sendCustomEvent(i + 1, j, 0, "", 1005, bt->getChannelPort(), bt->getChannelNumber());
108 andreas 9999
            }
10000
        }
110 andreas 10001
        else
10002
        {
10003
            j = bt->getBitmapJustification(&x, &y, btState-1);
10004
            sendCustomEvent(btState, j, 0, "", 1005, bt->getChannelPort(), bt->getChannelNumber());
10005
        }
108 andreas 10006
    }
10007
}
10008
 
10009
/**
10010
 * Set icon alignment using a numeric keypad layout for those buttons with a
10011
 * defined address range. The alignment of 0 is followed by ',<left>,<top>'.
10012
 * The left and top coordinates are relative to the upper left corner of the
10013
 * button.
10014
 */
10015
void TPageManager::doJSI(int port, vector<int>& channels, vector<string>& pars)
10016
{
10017
    DECL_TRACER("TPageManager::doJSB(int port, vector<int>& channels, vector<string>& pars)");
10018
 
10019
    if (pars.size() < 2)
10020
    {
10021
        MSG_ERROR("Expecting at least 2 parameters but got less! Ignoring command.");
10022
        return;
10023
    }
10024
 
10025
    TError::clear();
10026
    int btState = atoi(pars[0].c_str());
10027
    int align = atoi(pars[1].c_str());
10028
    int x = 0, y = 0;
10029
 
10030
    if (!align && pars.size() >= 3)
10031
    {
10032
        x = atoi(pars[2].c_str());
10033
 
10034
        if (pars.size() >= 4)
10035
            y = atoi(pars[3].c_str());
10036
    }
10037
 
193 andreas 10038
    vector<TMap::MAP_T> map = findButtons(port, channels);
108 andreas 10039
 
10040
    if (TError::isError() || map.empty())
10041
        return;
10042
 
10043
    vector<Button::TButton *> buttons = collectButtons(map);
10044
 
10045
    if (buttons.size() > 0)
10046
    {
10047
        vector<Button::TButton *>::iterator mapIter;
10048
 
10049
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
10050
        {
10051
            Button::TButton *bt = *mapIter;
10052
 
10053
            if (btState == 0)
10054
                bt->setIconJustification(align, x, y, -1);
10055
            else
10056
                bt->setIconJustification(align, x, y, btState-1);
10057
        }
10058
    }
10059
}
10060
 
10061
void TPageManager::getJSI(int port, vector<int>& channels, vector<string>& pars)
10062
{
10063
    DECL_TRACER("TPageManager::getJSB(int port, vector<int>& channels, vector<string>& pars)");
10064
 
10065
    if (pars.size() < 1)
10066
    {
10067
        MSG_ERROR("Expecting at least 1 parameter but got " << pars.size() << "! Ignoring command.");
10068
        return;
10069
    }
10070
 
10071
    TError::clear();
10072
    int btState = atoi(pars[0].c_str());
10073
    int j, x, y;
10074
 
193 andreas 10075
    vector<TMap::MAP_T> map = findButtons(port, channels);
108 andreas 10076
 
10077
    if (TError::isError() || map.empty())
10078
        return;
10079
 
10080
    vector<Button::TButton *> buttons = collectButtons(map);
10081
 
10082
    if (buttons.size() > 0)
10083
    {
110 andreas 10084
        Button::TButton *bt = buttons[0];
108 andreas 10085
 
110 andreas 10086
        if (btState == 0)       // All instances?
108 andreas 10087
        {
110 andreas 10088
            int bst = bt->getNumberInstances();
108 andreas 10089
 
110 andreas 10090
            for (int i = 0; i < bst; i++)
108 andreas 10091
            {
110 andreas 10092
                j = bt->getIconJustification(&x, &y, i);
10093
                sendCustomEvent(i + 1, j, 0, "", 1006, bt->getChannelPort(), bt->getChannelNumber());
108 andreas 10094
            }
10095
        }
110 andreas 10096
        else
10097
        {
10098
            j = bt->getIconJustification(&x, &y, btState-1);
10099
            sendCustomEvent(btState, j, 0, "", 1006, bt->getChannelPort(), bt->getChannelNumber());
10100
        }
108 andreas 10101
    }
10102
}
10103
 
10104
void TPageManager::doJST(int port, vector<int>& channels, vector<string>& pars)
10105
{
10106
    DECL_TRACER("TPageManager::doJSB(int port, vector<int>& channels, vector<string>& pars)");
10107
 
10108
    if (pars.size() < 2)
10109
    {
10110
        MSG_ERROR("Expecting at least 2 parameters but got less! Ignoring command.");
10111
        return;
10112
    }
10113
 
10114
    TError::clear();
10115
    int btState = atoi(pars[0].c_str());
10116
    int align = atoi(pars[1].c_str());
10117
    int x = 0, y = 0;
10118
 
10119
    if (!align && pars.size() >= 3)
10120
    {
10121
        x = atoi(pars[2].c_str());
10122
 
10123
        if (pars.size() >= 4)
10124
            y = atoi(pars[3].c_str());
10125
    }
10126
 
193 andreas 10127
    vector<TMap::MAP_T> map = findButtons(port, channels);
108 andreas 10128
 
10129
    if (TError::isError() || map.empty())
10130
        return;
10131
 
10132
    vector<Button::TButton *> buttons = collectButtons(map);
10133
 
10134
    if (buttons.size() > 0)
10135
    {
10136
        vector<Button::TButton *>::iterator mapIter;
10137
 
10138
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
10139
        {
10140
            Button::TButton *bt = *mapIter;
10141
 
10142
            if (btState == 0)
10143
                bt->setTextJustification(align, x, y, -1);
10144
            else
10145
                bt->setTextJustification(align, x, y, btState-1);
10146
        }
10147
    }
10148
}
10149
 
10150
void TPageManager::getJST(int port, vector<int>& channels, vector<string>& pars)
10151
{
10152
    DECL_TRACER("TPageManager::getJSB(int port, vector<int>& channels, vector<string>& pars)");
10153
 
10154
    if (pars.size() < 1)
10155
    {
10156
        MSG_ERROR("Expecting at least 1 parameter but got " << pars.size() << "! Ignoring command.");
10157
        return;
10158
    }
10159
 
10160
    TError::clear();
10161
    int btState = atoi(pars[0].c_str());
10162
    int j, x, y;
10163
 
193 andreas 10164
    vector<TMap::MAP_T> map = findButtons(port, channels);
108 andreas 10165
 
10166
    if (TError::isError() || map.empty())
10167
        return;
10168
 
10169
    vector<Button::TButton *> buttons = collectButtons(map);
10170
 
10171
    if (buttons.size() > 0)
10172
    {
110 andreas 10173
        Button::TButton *bt = buttons[0];
108 andreas 10174
 
110 andreas 10175
        if (btState == 0)       // All instances?
108 andreas 10176
        {
110 andreas 10177
            int bst = bt->getNumberInstances();
108 andreas 10178
 
110 andreas 10179
            for (int i = 0; i < bst; i++)
108 andreas 10180
            {
110 andreas 10181
                j = bt->getTextJustification(&x, &y, i);
10182
                sendCustomEvent(i + 1, j, 0, "", 1004, bt->getChannelPort(), bt->getChannelNumber());
108 andreas 10183
            }
10184
        }
110 andreas 10185
        else
10186
        {
10187
            j = bt->getTextJustification(&x, &y, btState-1);
10188
            sendCustomEvent(btState, j, 0, "", 1004, bt->getChannelPort(), bt->getChannelNumber());
10189
        }
108 andreas 10190
    }
10191
}
10192
 
10193
/**
395 andreas 10194
 * @brief TPageManager::getMSP
10195
 * Sets the speed of a marquee line. Allowed range is from 1 to 10, where 10 is
10196
 * the fastest speed.
10197
 *
10198
 * @param port      The port number
10199
 * @param channels  The channels
10200
 * @param pars      Parameters
10201
 */
10202
void TPageManager::doMSP(int port, vector<int>& channels, vector<string>& pars)
10203
{
10204
    DECL_TRACER("TPageManager::getMSP(int port, vector<int>& channels, vector<string>& pars)");
10205
 
10206
    if (pars.size() < 2)
10207
    {
10208
        MSG_ERROR("Expecting at least 2 parameter but got less! Command ignored.");
10209
        return;
10210
    }
10211
 
10212
    TError::clear();
10213
    int btState = atoi(pars[0].c_str()) - 1;
10214
    int speed = atoi(pars[1].c_str());
10215
 
10216
    if (speed < 1 || speed > 10)
10217
    {
10218
        MSG_ERROR("Speed for marquee line is out of range!");
10219
        return;
10220
    }
10221
 
10222
    vector<TMap::MAP_T> map = findButtons(port, channels);
10223
 
10224
    if (TError::isError() || map.empty())
10225
        return;
10226
 
10227
    vector<Button::TButton *> buttons = collectButtons(map);
10228
 
10229
    if (buttons.size() > 0)
10230
    {
10231
        vector<Button::TButton *>::iterator iter;
10232
 
10233
        for (iter = buttons.begin(); iter != buttons.end(); ++iter)
10234
        {
10235
            Button::TButton *bt = buttons[0];
10236
            bt->setMarqueeSpeed(speed, btState);
10237
        }
10238
    }
10239
}
10240
 
10241
/**
16 andreas 10242
 * Show or hide a button with a set variable text range.
10243
 */
10244
void TPageManager::doSHO(int port, vector<int>& channels, vector<string>& pars)
10245
{
10246
    DECL_TRACER("TPageManager::doSHO(int port, vector<int>& channels, vector<string>& pars)");
10247
 
10248
    if (pars.empty())
10249
    {
10250
        MSG_ERROR("Expecting 1 parameter but got none! Ignoring command.");
10251
        return;
10252
    }
10253
 
10254
    TError::clear();
10255
    int cvalue = atoi(pars[0].c_str());
10256
 
193 andreas 10257
    vector<TMap::MAP_T> map = findButtons(port, channels);
16 andreas 10258
 
10259
    if (TError::isError() || map.empty())
10260
        return;
10261
 
10262
    vector<Button::TButton *> buttons = collectButtons(map);
10263
 
83 andreas 10264
    if (buttons.size() > 0)
16 andreas 10265
    {
83 andreas 10266
        vector<Button::TButton *>::iterator mapIter;
10267
 
10268
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
10269
        {
10270
            Button::TButton *bt = *mapIter;
318 andreas 10271
 
100 andreas 10272
            int pgID = (bt->getParent() >> 16) & 0x0000ffff;
10273
            bool pVisible = false;
10274
 
10275
            if (pgID < 500)
10276
            {
10277
                TPage *pg = getPage(pgID);
10278
 
10279
                if (pg && pg->isVisilble())
10280
                    pVisible = true;
10281
            }
10282
            else
10283
            {
10284
                TSubPage *pg = getSubPage(pgID);
10285
 
10286
                if (pg && pg->isVisible())
10287
                    pVisible = true;
10288
            }
10289
 
151 andreas 10290
            bool oldV = bt->isVisible();
10291
            bool visible = cvalue ? true : false;
10292
            MSG_DEBUG("Button " << bt->getButtonIndex() << ", \"" << bt->getButtonName() << "\" set " << (visible ? "VISIBLE" : "HIDDEN") << " (Previous: " << (oldV ? "VISIBLE" : "HIDDEN") << ")");
98 andreas 10293
 
151 andreas 10294
            if (visible != oldV)
100 andreas 10295
            {
151 andreas 10296
                bt->setVisible(visible);
100 andreas 10297
 
151 andreas 10298
                if (pVisible)
10299
                {
10300
                    setButtonCallbacks(bt);
10301
 
10302
                    if (_setVisible)
10303
                        _setVisible(bt->getHandle(), visible);
10304
                    else
10305
                        bt->refresh();
10306
                }
100 andreas 10307
            }
83 andreas 10308
        }
16 andreas 10309
    }
10310
}
10311
 
108 andreas 10312
void TPageManager::doTEC(int port, vector<int>& channels, vector<string>& pars)
10313
{
10314
    DECL_TRACER("TPageManager::doTEC(int port, vector<int>& channels, vector<string>& pars)");
10315
 
10316
    if (pars.size() < 2)
10317
    {
10318
        MSG_ERROR("Expecting at least 2 parameters but got less! Ignoring command.");
10319
        return;
10320
    }
10321
 
10322
    TError::clear();
10323
    int btState = atoi(pars[0].c_str());
10324
    string color = pars[1];
10325
 
193 andreas 10326
    vector<TMap::MAP_T> map = findButtons(port, channels);
108 andreas 10327
 
10328
    if (TError::isError() || map.empty())
10329
        return;
10330
 
10331
    vector<Button::TButton *> buttons = collectButtons(map);
10332
 
10333
    if (buttons.size() > 0)
10334
    {
10335
        vector<Button::TButton *>::iterator mapIter;
10336
 
10337
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
10338
        {
10339
            Button::TButton *bt = *mapIter;
10340
 
10341
            if (btState == 0)
10342
                bt->setTextEffectColor(color);
10343
            else
10344
                bt->setTextEffectColor(color, btState-1);
10345
        }
10346
    }
10347
}
10348
 
10349
void TPageManager::getTEC(int port, vector<int>& channels, vector<string>& pars)
10350
{
10351
    DECL_TRACER("TPageManager::getTEC(int port, vector<int>& channels, vector<string>& pars)");
10352
 
10353
    if (pars.size() < 1)
10354
    {
10355
        MSG_ERROR("Expecting at least 1 parameter but got " << pars.size() << "! Ignoring command.");
10356
        return;
10357
    }
10358
 
10359
    TError::clear();
10360
    int btState = atoi(pars[0].c_str());
10361
 
193 andreas 10362
    vector<TMap::MAP_T> map = findButtons(port, channels);
108 andreas 10363
 
10364
    if (TError::isError() || map.empty())
10365
        return;
10366
 
10367
    vector<Button::TButton *> buttons = collectButtons(map);
10368
 
10369
    if (buttons.size() > 0)
10370
    {
110 andreas 10371
        Button::TButton *bt = buttons[0];
10372
 
10373
        if (btState == 0)       // All instances?
10374
        {
10375
            int bst = bt->getNumberInstances();
10376
 
10377
            for (int i = 0; i < bst; i++)
10378
            {
10379
                string c = bt->getTextEffectColor(i);
300 andreas 10380
                sendCustomEvent(i + 1, (int)c.length(), 0, c, 1009, bt->getChannelPort(), bt->getChannelNumber());
110 andreas 10381
            }
10382
        }
10383
        else
10384
        {
10385
            string c = bt->getTextEffectColor(btState-1);
300 andreas 10386
            sendCustomEvent(btState, (int)c.length(), 0, c, 1009, bt->getChannelPort(), bt->getChannelNumber());
110 andreas 10387
        }
10388
    }
10389
}
10390
 
10391
void TPageManager::doTEF(int port, vector<int>& channels, vector<string>& pars)
10392
{
10393
    DECL_TRACER("TPageManager::doTEF(int port, vector<int>& channels, vector<string>& pars)");
10394
 
10395
    if (pars.size() < 2)
10396
    {
10397
        MSG_ERROR("Expecting at least 2 parameters but got less! Ignoring command.");
10398
        return;
10399
    }
10400
 
10401
    TError::clear();
10402
    int btState = atoi(pars[0].c_str());
10403
    string tef = pars[1];
10404
 
193 andreas 10405
    vector<TMap::MAP_T> map = findButtons(port, channels);
110 andreas 10406
 
10407
    if (TError::isError() || map.empty())
10408
        return;
10409
 
10410
    vector<Button::TButton *> buttons = collectButtons(map);
10411
 
10412
    if (buttons.size() > 0)
10413
    {
108 andreas 10414
        vector<Button::TButton *>::iterator mapIter;
10415
 
10416
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
10417
        {
10418
            Button::TButton *bt = *mapIter;
10419
 
110 andreas 10420
            if (btState == 0)
10421
                bt->setTextEffectName(tef);
10422
            else
10423
                bt->setTextEffectName(tef, btState-1);
10424
        }
10425
    }
10426
}
108 andreas 10427
 
110 andreas 10428
void TPageManager::getTEF(int port, vector<int>& channels, vector<string>& pars)
10429
{
10430
    DECL_TRACER("TPageManager::getTEF(int port, vector<int>& channels, vector<string>& pars)");
108 andreas 10431
 
110 andreas 10432
    if (pars.size() < 1)
10433
    {
10434
        MSG_ERROR("Expecting at least 1 parameter but got " << pars.size() << "! Ignoring command.");
10435
        return;
10436
    }
108 andreas 10437
 
110 andreas 10438
    TError::clear();
10439
    int btState = atoi(pars[0].c_str());
10440
 
193 andreas 10441
    vector<TMap::MAP_T> map = findButtons(port, channels);
110 andreas 10442
 
10443
    if (TError::isError() || map.empty())
10444
        return;
10445
 
10446
    vector<Button::TButton *> buttons = collectButtons(map);
10447
 
10448
    if (buttons.size() > 0)
10449
    {
10450
        Button::TButton *bt = buttons[0];
10451
 
10452
        if (btState == 0)       // All instances?
10453
        {
10454
            int bst = bt->getNumberInstances();
10455
 
10456
            for (int i = 0; i < bst; i++)
108 andreas 10457
            {
110 andreas 10458
                string c = bt->getTextEffectName(i);
300 andreas 10459
                sendCustomEvent(i + 1, (int)c.length(), 0, c, 1008, bt->getChannelPort(), bt->getChannelNumber());
108 andreas 10460
            }
10461
        }
110 andreas 10462
        else
10463
        {
10464
            string c = bt->getTextEffectName(btState-1);
300 andreas 10465
            sendCustomEvent(btState, (int)c.length(), 0, c, 1008, bt->getChannelPort(), bt->getChannelNumber());
110 andreas 10466
        }
108 andreas 10467
    }
10468
}
10469
 
16 andreas 10470
/**
14 andreas 10471
 * Assign a text string to those buttons with a defined address range.
10472
 * Sets Non-Unicode text.
10473
 */
10474
void TPageManager::doTXT(int port, vector<int>& channels, vector<string>& pars)
10475
{
10476
    DECL_TRACER("TPageManager::doTXT(int port, vector<int>& channels, vector<string>& pars)");
10477
 
10478
    if (pars.size() < 1)
10479
    {
10480
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
331 andreas 10481
#if TESTMODE == 1
334 andreas 10482
        setAllDone();
331 andreas 10483
#endif
14 andreas 10484
        return;
10485
    }
10486
 
16 andreas 10487
    TError::clear();
333 andreas 10488
    int btState = atoi(pars[0].c_str()) - 1;
14 andreas 10489
    string text;
10490
 
333 andreas 10491
    // Every comma (,) in the text produces a new parameter. Therefor we must
10492
    // concatenate this parameters together and insert the comma.
14 andreas 10493
    if (pars.size() > 1)
150 andreas 10494
    {
10495
        for (size_t i = 1; i < pars.size(); ++i)
10496
        {
10497
            if (i > 1)
10498
                text += ",";
14 andreas 10499
 
150 andreas 10500
            text += pars[i];
10501
        }
10502
    }
10503
 
193 andreas 10504
    vector<TMap::MAP_T> map = findButtons(port, channels);
14 andreas 10505
 
10506
    if (TError::isError() || map.empty())
331 andreas 10507
    {
10508
#if TESTMODE == 1
334 andreas 10509
        setAllDone();
331 andreas 10510
#endif
14 andreas 10511
        return;
331 andreas 10512
    }
14 andreas 10513
 
10514
    vector<Button::TButton *> buttons = collectButtons(map);
10515
 
83 andreas 10516
    if (buttons.size() > 0)
14 andreas 10517
    {
83 andreas 10518
        vector<Button::TButton *>::iterator mapIter;
14 andreas 10519
 
333 andreas 10520
        for (mapIter = buttons.begin(); mapIter != buttons.end(); ++mapIter)
14 andreas 10521
        {
83 andreas 10522
            Button::TButton *bt = *mapIter;
14 andreas 10523
 
252 andreas 10524
            if (!bt)
333 andreas 10525
                continue;
252 andreas 10526
 
333 andreas 10527
            bt->setText(text, btState);
331 andreas 10528
#if TESTMODE == 1
333 andreas 10529
            if (_gTestMode)
10530
                _gTestMode->setResult(bt->getText(btState < 0 ? 0 : btState));
331 andreas 10531
 
333 andreas 10532
            __success = true;
331 andreas 10533
#endif
14 andreas 10534
        }
10535
    }
331 andreas 10536
#if TESTMODE == 1
334 andreas 10537
    setDone();
331 andreas 10538
#endif
14 andreas 10539
}
21 andreas 10540
 
110 andreas 10541
void TPageManager::getTXT(int port, vector<int>& channels, vector<string>& pars)
10542
{
10543
    DECL_TRACER("TPageManager::getTXT(int port, vector<int>& channels, vector<string>& pars)");
10544
 
10545
    if (pars.size() < 1)
10546
    {
10547
        MSG_ERROR("Expecting at least 1 parameter but got " << pars.size() << "! Ignoring command.");
10548
        return;
10549
    }
10550
 
10551
    TError::clear();
10552
    int btState = atoi(pars[0].c_str());
10553
 
193 andreas 10554
    vector<TMap::MAP_T> map = findButtons(port, channels);
110 andreas 10555
 
10556
    if (TError::isError() || map.empty())
10557
        return;
10558
 
10559
    vector<Button::TButton *> buttons = collectButtons(map);
10560
 
10561
    if (buttons.size() > 0)
10562
    {
10563
        Button::TButton *bt = buttons[0];
10564
 
10565
        if (btState == 0)       // All instances?
10566
        {
10567
            int bst = bt->getNumberInstances();
10568
 
10569
            for (int i = 0; i < bst; i++)
10570
            {
10571
                string c = bt->getText(i);
300 andreas 10572
                sendCustomEvent(i + 1, (int)c.length(), 0, c, 1001, bt->getChannelPort(), bt->getChannelNumber());
333 andreas 10573
#if TESTMODE == 1
10574
                if (_gTestMode)
10575
                    _gTestMode->setResult(c);
10576
#endif
110 andreas 10577
            }
10578
        }
10579
        else
10580
        {
10581
            string c = bt->getText(btState-1);
300 andreas 10582
            sendCustomEvent(btState, (int)c.length(), 0, c, 1001, bt->getChannelPort(), bt->getChannelNumber());
333 andreas 10583
#if TESTMODE == 1
10584
            if (_gTestMode)
10585
                _gTestMode->setResult(c);
10586
#endif
110 andreas 10587
        }
10588
    }
334 andreas 10589
#if TESTMODE == 1
10590
    setAllDone();
10591
#endif
110 andreas 10592
}
10593
 
97 andreas 10594
/*
104 andreas 10595
 * Set button state legacy unicode text command.
10596
 *
10597
 * Set Unicode text in the legacy G4 format. For the ^UNI command, the Unicode
10598
 * text is sent as ASCII-HEX nibbles.
10599
 */
10600
void TPageManager::doUNI(int port, vector<int>& channels, vector<string>& pars)
10601
{
10602
    DECL_TRACER("TPageManager::doUNI(int port, vector<int>& channels, vector<string>& pars)");
10603
 
10604
    if (pars.size() < 1)
10605
    {
10606
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
331 andreas 10607
#if TESTMODE == 1
334 andreas 10608
        setAllDone();
331 andreas 10609
#endif
104 andreas 10610
        return;
10611
    }
10612
 
10613
    TError::clear();
333 andreas 10614
    int btState = atoi(pars[0].c_str()) - 1;
104 andreas 10615
    string text;
10616
 
361 andreas 10617
    // Unicode is the stadard character set used by Windows internally. It
10618
    // consists of 16 bit unsiged numbers. This can't be transported into a
10619
    // standard character string because a NULL byte means end of string.
10620
    // Therefor we must convert it to UFT-8.
104 andreas 10621
    if (pars.size() > 1)
10622
    {
10623
        string byte;
361 andreas 10624
        std::wstring uni;
104 andreas 10625
        size_t pos = 0;
10626
 
10627
        while (pos < pars[1].length())
10628
        {
361 andreas 10629
            byte = pars[1].substr(pos, 4);
10630
            wchar_t ch = (char)strtol(byte.c_str(), NULL, 16);
10631
            uni += ch;
10632
            pos += 4;
104 andreas 10633
        }
361 andreas 10634
 
10635
        text = UnicodeToUTF8(uni);
104 andreas 10636
    }
10637
 
193 andreas 10638
    vector<TMap::MAP_T> map = findButtons(port, channels);
104 andreas 10639
 
10640
    if (TError::isError() || map.empty())
331 andreas 10641
    {
10642
#if TESTMODE == 1
334 andreas 10643
        setAllDone();
331 andreas 10644
#endif
104 andreas 10645
        return;
331 andreas 10646
    }
104 andreas 10647
 
10648
    vector<Button::TButton *> buttons = collectButtons(map);
10649
 
10650
    if (buttons.size() > 0)
10651
    {
10652
        vector<Button::TButton *>::iterator mapIter;
10653
 
10654
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
10655
        {
10656
            Button::TButton *bt = *mapIter;
10657
 
331 andreas 10658
#if TESTMODE == 1
333 andreas 10659
            bool res = bt->setText(text, btState);
104 andreas 10660
 
333 andreas 10661
            if (_gTestMode)
10662
                _gTestMode->setResult(bt->getText(btState < 0 ? 0 : btState));
331 andreas 10663
 
333 andreas 10664
            __success = res;
10665
#else
10666
            bt->setText(text, btState);
331 andreas 10667
#endif
104 andreas 10668
        }
10669
    }
334 andreas 10670
#if TESTMODE == 1
10671
    setDone();
10672
#endif
104 andreas 10673
}
10674
 
10675
void TPageManager::doUTF(int port, vector<int>& channels, vector<string>& pars)
10676
{
10677
    DECL_TRACER("TPageManager::doTXT(int port, vector<int>& channels, vector<string>& pars)");
10678
 
10679
    if (pars.size() < 1)
10680
    {
10681
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
10682
        return;
10683
    }
10684
 
10685
    TError::clear();
10686
    int btState = atoi(pars[0].c_str());
10687
    string text;
10688
 
10689
    if (pars.size() > 1)
150 andreas 10690
    {
10691
        for (size_t i = 1; i < pars.size(); ++i)
10692
        {
10693
            if (i > 1)
10694
                text += ",";
104 andreas 10695
 
150 andreas 10696
            text += pars[i];
10697
        }
10698
    }
10699
 
193 andreas 10700
    vector<TMap::MAP_T> map = findButtons(port, channels);
104 andreas 10701
 
10702
    if (TError::isError() || map.empty())
10703
        return;
10704
 
10705
    vector<Button::TButton *> buttons = collectButtons(map);
10706
 
10707
    if (buttons.size() > 0)
10708
    {
10709
        vector<Button::TButton *>::iterator mapIter;
10710
 
10711
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
10712
        {
10713
            Button::TButton *bt = *mapIter;
10714
 
10715
            if (btState == 0)       // All instances?
10716
            {
10717
                int bst = bt->getNumberInstances();
10718
 
10719
                for (int i = 0; i < bst; i++)
10720
                    bt->setText(text, i);
10721
            }
10722
            else
10723
                bt->setText(text, btState - 1);
10724
        }
10725
    }
10726
}
111 andreas 10727
 
361 andreas 10728
/**
10729
 * Simulates a touch/release/pulse at the given coordinate. If the push event
10730
 * is less then 0 or grater than 2 the command is ignored. It is also ignored
10731
 * if the x and y coordinate is out of range. The range must be between 0 and
10732
 * the maximum with and height.
10733
 */
148 andreas 10734
void TPageManager::doVTP (int, vector<int>&, vector<string>& pars)
10735
{
10736
    DECL_TRACER("TPageManager::doVTP (int, vector<int>&, vector<string>& pars)");
10737
 
10738
    if (pars.size() < 3)
10739
    {
10740
        MSG_ERROR("Expected 3 parameters but got only " << pars.size() << " parameters!");
10741
        return;
10742
    }
10743
 
10744
    int pushType = atoi(pars[0].c_str());
10745
    int x = atoi(pars[1].c_str());
10746
    int y = atoi(pars[2].c_str());
10747
 
10748
    if (pushType < 0 || pushType > 2)
10749
    {
10750
        MSG_ERROR("Invalid push type " << pushType << ". Ignoring command!");
10751
        return;
10752
    }
10753
 
217 andreas 10754
    if (x < 0 || x > mTSettings->getWidth() || y < 0 || y > mTSettings->getHeight())
148 andreas 10755
    {
10756
        MSG_ERROR("Illegal coordinates " << x << " x " << y << ". Ignoring command!");
10757
        return;
10758
    }
10759
 
10760
    if (pushType == 0 || pushType == 2)
10761
        mouseEvent(x, y, true);
10762
 
10763
    if (pushType == 1 || pushType == 2)
10764
        mouseEvent(x, y, false);
10765
}
10766
 
400 andreas 10767
 
111 andreas 10768
/**
10769
 * Set the keyboard passthru.
10770
 */
10771
void TPageManager::doKPS(int, vector<int>&, vector<string>& pars)
10772
{
10773
    DECL_TRACER("TPageManager::doKPS(int, vector<int>&, vector<string>& pars)");
10774
 
10775
    if (pars.size() < 1)
10776
    {
10777
        MSG_ERROR("Got no parameter. Ignoring command!");
10778
        return;
10779
    }
10780
 
10781
    int state = atoi(pars[0].c_str());
10782
 
10783
    if (state == 0)
10784
        mPassThrough = false;
10785
    else if (state == 5)
10786
        mPassThrough = true;
10787
}
10788
 
400 andreas 10789
void TPageManager::doVKS(int, vector<int>&, vector<string>& pars)
111 andreas 10790
{
400 andreas 10791
    DECL_TRACER("TPageManager::doVKS(int, vector<int>&, vector<string>& pars)");
111 andreas 10792
 
10793
    if (pars.size() < 1)
10794
    {
10795
        MSG_ERROR("Got no parameter. Ignoring command!");
10796
        return;
10797
    }
10798
 
10799
    if (_sendVirtualKeys)
10800
        _sendVirtualKeys(pars[0]);
10801
}
10802
 
400 andreas 10803
void TPageManager::doLPB(int port, vector<int>& channels, vector<string>& pars)
10804
{
10805
    DECL_TRACER("TPageManager::doLPB(int port, vector<int>& channels, vector<string>& pars)");
10806
 
10807
    if (pars.size() < 1)
10808
        return;
10809
 
10810
    TError::clear();
10811
    string passwd = pars[0];
10812
    vector<TMap::MAP_T> map = findButtons(port, channels);
10813
 
10814
    if (TError::isError() || map.empty())
10815
        return;
10816
 
10817
    vector<Button::TButton *> buttons = collectButtons(map);
10818
 
10819
    if (buttons.size() > 0)
10820
    {
10821
        vector<Button::TButton *>::iterator mapIter;
10822
 
10823
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
10824
        {
10825
            Button::TButton *bt = *mapIter;
10826
            bt->setUserName(passwd);
10827
        }
10828
    }
10829
}
10830
 
401 andreas 10831
void TPageManager::doLPC(int, vector<int>&, vector<string>&)
400 andreas 10832
{
401 andreas 10833
    DECL_TRACER("TPageManager::doLPC(int, vector<int>&, vector<string>&)");
400 andreas 10834
 
10835
    TConfig::clearUserPasswords();
10836
}
10837
 
10838
void TPageManager::doLPR(int, vector<int>&, vector<string>& pars)
10839
{
10840
    DECL_TRACER("TPageManager::doLPR(int, vector<int>&, vector<string>& pars)");
10841
 
10842
    if (pars.size() < 1)
10843
        return;
10844
 
10845
    string user = pars[0];
10846
    TConfig::clearUserPassword(user);
10847
}
10848
 
10849
void TPageManager::doLPS(int, vector<int>&, vector<string>& pars)
10850
{
10851
    DECL_TRACER("TPageManager::doLPS(int, vector<int>&, vector<string>& pars)");
10852
 
10853
    if (pars.size() < 2)
10854
        return;
10855
 
10856
    string user = pars[0];
10857
    string password;
10858
 
10859
    // In case the password contains one or more comma (,), the password is
10860
    // splitted. The following loop concatenates the password into one. Because
10861
    // the comma is lost, we must add it again.
10862
    for (size_t i = 0; i < pars.size(); ++i)
10863
    {
10864
        if (i > 0)
10865
            password += ",";
10866
 
10867
        password += pars[i];
10868
    }
10869
 
10870
    TConfig::setUserPassword(user, password);
10871
}
10872
 
104 andreas 10873
/*
400 andreas 10874
 * Set the page flip password. @PWD sets the level 1 password only.
10875
 */
10876
void TPageManager::doAPWD(int, vector<int>&, vector<string>& pars)
10877
{
10878
    DECL_TRACER("TPageManager::doPWD(int port, vector<int>&, vector<string>& pars)");
10879
 
10880
    if (pars.size() < 1)
10881
    {
10882
        MSG_ERROR("Got less then 1 parameter!");
10883
        return;
10884
    }
10885
 
10886
    string password;
10887
    // In case the password contains one or more comma (,), the password is
10888
    // splitted. The following loop concatenates the password into one. Because
10889
    // the comma is lost, we must add it again.
10890
    for (size_t i = 0; i < pars.size(); ++i)
10891
    {
10892
        if (i > 0)
10893
            password += ",";
10894
 
10895
        password += pars[i];
10896
    }
10897
 
10898
    TConfig::savePassword1(password);
10899
}
10900
 
10901
/*
10902
 * Set the page flip password. Password level is required and must be 1 - 4
10903
 */
10904
void TPageManager::doPWD(int, vector<int>&, vector<string>& pars)
10905
{
10906
    DECL_TRACER("TPageManager::doPWD(int, vector<int>&, vector<string>& pars)");
10907
 
10908
    if (pars.size() < 2)
10909
    {
10910
        MSG_ERROR("Got less then 2 parameters!");
10911
        return;
10912
    }
10913
 
10914
    int pwIdx = atoi(pars[0].c_str());
10915
    string password;
10916
    // In case the password contains one or more comma (,), the password is
10917
    // splitted. The following loop concatenates the password into one. Because
10918
    // the comma is lost, we must add it again.
10919
    for (size_t i = 1; i < pars.size(); ++i)
10920
    {
10921
        if (i > 1)
10922
            password += ",";
10923
 
10924
        password += pars[i];
10925
    }
10926
 
10927
    switch(pwIdx)
10928
    {
10929
        case 1: TConfig::savePassword1(password); break;
10930
        case 2: TConfig::savePassword2(password); break;
10931
        case 3: TConfig::savePassword3(password); break;
10932
        case 4: TConfig::savePassword4(password); break;
10933
    }
10934
}
10935
 
10936
/*
97 andreas 10937
 * Set the bitmap of a button to use a particular resource.
10938
 * Syntax:
10939
 *    "'^BBR-<vt addr range>,<button states range>,<resource name>'"
10940
 * Variable:
10941
 *    variable text address range = 1 - 4000.
10942
 *    button states range = 1 - 256 for multi-state buttons (0 = All states, for General buttons 1 = Off state and 2 = On state).
10943
 *    resource name = 1 - 50 ASCII characters.
10944
 * Example:
10945
 *    SEND_COMMAND Panel,"'^BBR-700,1,Sports_Image'"
10946
 *    Sets the resource name of the button to ’Sports_Image’.
10947
 */
21 andreas 10948
void TPageManager::doBBR(int port, vector<int>& channels, vector<string>& pars)
10949
{
10950
    DECL_TRACER("TPageManager::doBBR(int port, vector<int>& channels, vector<string>& pars)");
10951
 
10952
    if (pars.size() < 2)
10953
    {
10954
        MSG_ERROR("Expecting 2 parameters but got none! Ignoring command.");
10955
        return;
10956
    }
10957
 
10958
    TError::clear();
10959
    int btState = atoi(pars[0].c_str());
10960
    string resName = pars[1];
10961
 
193 andreas 10962
    vector<TMap::MAP_T> map = findButtons(port, channels);
21 andreas 10963
 
10964
    if (TError::isError() || map.empty())
10965
        return;
10966
 
10967
    vector<Button::TButton *> buttons = collectButtons(map);
10968
 
83 andreas 10969
    if (buttons.size() > 0)
21 andreas 10970
    {
83 andreas 10971
        vector<Button::TButton *>::iterator mapIter;
21 andreas 10972
 
83 andreas 10973
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
21 andreas 10974
        {
83 andreas 10975
            Button::TButton *bt = *mapIter;
252 andreas 10976
//            setButtonCallbacks(bt);
21 andreas 10977
 
83 andreas 10978
            if (btState == 0)       // All instances?
10979
            {
10980
                int bst = bt->getNumberInstances();
10981
                MSG_DEBUG("Setting BBR on all " << bst << " instances...");
10982
 
10983
                for (int i = 0; i < bst; i++)
10984
                    bt->setResourceName(resName, i);
10985
            }
10986
            else
10987
                bt->setResourceName(resName, btState - 1);
97 andreas 10988
 
10989
            if (bt->isVisible())
10990
                bt->refresh();
99 andreas 10991
            else if (_setVisible)
10992
                _setVisible(bt->getHandle(), false);
21 andreas 10993
        }
10994
    }
10995
}
10996
 
97 andreas 10997
/*
10998
 * Add new resources
10999
 * Adds any and all resource parameters by sending embedded codes and data.
11000
 * Since the embedded codes are preceded by a '%' character, any '%' character
11001
 * contained in* the URL must be escaped with a second '%' character (see
11002
 * example).
11003
 * The file name field (indicated by a %F embedded code) may contain special
11004
 * escape sequences as shown in the ^RAF, ^RMF.
11005
 * Syntax:
11006
 *    "'^RAF-<resource name>,<data>'"
11007
 * Variables:
11008
 *    resource name = 1 - 50 ASCII characters.
11009
 *    data = Refers to the embedded codes, see the ^RAF, ^RMF.
11010
 * Example:
11011
 *    SEND_COMMAND Panel,"'^RAF-New Image,%P0%HAMX.COM%ALab/Test%%5Ffile%Ftest.jpg'"
11012
 *    Adds a new resource.
11013
 *    The resource name is ’New Image’
11014
 *    %P (protocol) is an HTTP
11015
 *    %H (host name) is AMX.COM
11016
 *    %A (file path) is Lab/Test_f ile
11017
 *    %F (file name) is test.jpg.
11018
 *    Note that the %%5F in the file path is actually encoded as %5F.
11019
 */
11020
void TPageManager::doRAF(int, vector<int>&, vector<string>& pars)
11021
{
11022
    DECL_TRACER("TPageManager::doRAF(int port, vector<int>& channels, vector<string>& pars)");
11023
 
11024
    if (pars.size() < 2)
11025
    {
11026
        MSG_ERROR("Expecting 2 parameters but got none! Ignoring command.");
11027
        return;
11028
    }
11029
 
11030
    string name = pars[0];
11031
    string data = pars[1];
11032
 
11033
    vector<string> parts = StrSplit(data, "%");
11034
    RESOURCE_T res;
11035
 
11036
    if (parts.size() > 0)
11037
    {
11038
        vector<string>::iterator sIter;
11039
 
11040
        for (sIter = parts.begin(); sIter != parts.end(); sIter++)
11041
        {
11042
            const char *s = sIter->c_str();
11043
            string ss = *sIter;
11044
            MSG_DEBUG("Parsing \"" << ss << "\" with token << " << ss[0]);
11045
 
11046
            switch(*s)
11047
            {
11048
                case 'P':
11049
                    if (*(s+1) == '0')
11050
                        res.protocol = "HTTP";
11051
                    else
11052
                        res.protocol = "FTP";
11053
                    break;
11054
 
11055
                case 'U': res.user = sIter->substr(1); break;
11056
                case 'S': res.password = sIter->substr(1); break;
11057
                case 'H': res.host = sIter->substr(1); break;
11058
                case 'F': res.file = sIter->substr(1); break;
11059
                case 'A': res.path = sIter->substr(1); break;
11060
                case 'R': res.refresh = atoi(sIter->substr(1).c_str()); break;
11061
 
11062
                default:
11063
                    MSG_WARNING("Option " << sIter->at(0) << " is currently not implemented!");
11064
            }
11065
        }
11066
 
11067
        if (gPrjResources)
11068
            gPrjResources->addResource(name, res.protocol, res.host, res.path, res.file, res.user, res.password, res.refresh);
11069
    }
11070
}
11071
 
111 andreas 11072
void TPageManager::doRFR(int, vector<int>&, vector<string>& pars)
97 andreas 11073
{
11074
    DECL_TRACER("TPageManager::doRFR(int port, vector<int>& channels, vector<string>& pars)");
11075
 
11076
    if (pars.size() < 1)
11077
    {
11078
        MSG_ERROR("Expecting 1 parameter but got none! Ignoring command.");
11079
        return;
11080
    }
11081
 
11082
    string name = pars[0];
193 andreas 11083
    vector<TMap::MAP_T> map = findButtonByName(name);
97 andreas 11084
 
11085
    if (TError::isError() || map.empty())
11086
        return;
11087
 
11088
    vector<Button::TButton *> buttons = collectButtons(map);
11089
 
11090
    if (buttons.size() > 0)
11091
    {
11092
        vector<Button::TButton *>::iterator mapIter;
11093
 
11094
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
11095
        {
11096
            Button::TButton *bt = *mapIter;
11097
 
11098
            if (bt->isVisible())
11099
            {
252 andreas 11100
//                setButtonCallbacks(bt);
97 andreas 11101
                bt->refresh();
11102
            }
11103
        }
11104
    }
11105
}
11106
 
11107
/*
11108
 * Modify an existing resource
11109
 *
11110
 * Modifies any and all resource parameters by sending embedded codes and data.
11111
 * Since the embedded codes are preceded by a '%' character, any '%' character
11112
 * contained in the URL must be escaped with a second '%' character (see
11113
 * example).
11114
 * The file name field (indicated by a %F embedded code) may contain special
11115
 * escape sequences as shown in the ^RAF.
11116
 *
11117
 * Syntax:
11118
 * "'^RMF-<resource name>,<data>'"
11119
 * Variables:
11120
 *   • resource name = 1 - 50 ASCII characters
11121
 *   • data = Refers to the embedded codes, see the ^RAF, ^RMF.
11122
 * Example:
11123
 *   SEND_COMMAND Panel,"'^RMF-Sports_Image,%ALab%%5FTest/Images%Ftest.jpg'"
11124
 * Changes the resource ’Sports_Image’ file name to ’test.jpg’ and the path to
11125
 * ’Lab_Test/Images’.
11126
 * Note that the %%5F in the file path is actually encoded as %5F.
11127
 */
22 andreas 11128
void TPageManager::doRMF(int, vector<int>&, vector<string>& pars)
21 andreas 11129
{
11130
    DECL_TRACER("TPageManager::doRMF(int port, vector<int>& channels, vector<string>& pars)");
11131
 
11132
    if (pars.size() < 2)
11133
    {
11134
        MSG_ERROR("Expecting 2 parameters but got none! Ignoring command.");
11135
        return;
11136
    }
11137
 
11138
    string name = pars[0];
11139
    string data = pars[1];
11140
 
11141
    vector<string> parts = StrSplit(data, "%");
11142
    RESOURCE_T res;
11143
 
83 andreas 11144
    if (parts.size() > 0)
21 andreas 11145
    {
83 andreas 11146
        vector<string>::iterator sIter;
21 andreas 11147
 
83 andreas 11148
        for (sIter = parts.begin(); sIter != parts.end(); sIter++)
21 andreas 11149
        {
83 andreas 11150
            const char *s = sIter->c_str();
11151
            string ss = *sIter;
11152
            MSG_DEBUG("Parsing \"" << ss << "\" with token << " << ss[0]);
21 andreas 11153
 
83 andreas 11154
            switch(*s)
11155
            {
11156
                case 'P':
11157
                    if (*(s+1) == '0')
11158
                        res.protocol = "HTTP";
11159
                    else
11160
                        res.protocol = "FTP";
11161
                break;
21 andreas 11162
 
83 andreas 11163
                case 'U': res.user = sIter->substr(1); break;
11164
                case 'S': res.password = sIter->substr(1); break;
11165
                case 'H': res.host = sIter->substr(1); break;
11166
                case 'F': res.file = sIter->substr(1); break;
11167
                case 'A': res.path = sIter->substr(1); break;
11168
                case 'R': res.refresh = atoi(sIter->substr(1).c_str()); break;
11169
 
11170
                default:
11171
                    MSG_WARNING("Option " << sIter->at(0) << " is currently not implemented!");
11172
            }
21 andreas 11173
        }
83 andreas 11174
 
11175
        if (gPrjResources)
11176
            gPrjResources->setResource(name, res.protocol, res.host, res.path, res.file, res.user, res.password, res.refresh);
21 andreas 11177
    }
11178
}
62 andreas 11179
 
11180
/**
111 andreas 11181
 * Change the refresh rate for a given resource.
11182
 */
11183
void TPageManager::doRSR(int, vector<int>&, vector<string>& pars)
11184
{
11185
    DECL_TRACER("TPageManager::doRSR(int, vector<int>&, vector<string>& pars)");
11186
 
11187
    if (pars.size() < 2)
11188
    {
11189
        MSG_ERROR("Expecting 2 parameters but got none! Ignoring command.");
11190
        return;
11191
    }
11192
 
11193
    string resName = pars[0];
11194
    int resRefresh = atoi(pars[1].c_str());
11195
 
11196
    if (!gPrjResources)
11197
    {
11198
        MSG_ERROR("Missing the resource module. Ignoring command!");
11199
        return;
11200
    }
11201
 
11202
    RESOURCE_T res = gPrjResources->findResource(resName);
11203
 
11204
    if (res.name.empty() || res.refresh == resRefresh)
11205
        return;
11206
 
11207
    gPrjResources->setResource(resName, res.protocol, res.host, res.path, res.file, res.user, res.password, resRefresh);
11208
}
11209
 
11210
/**
62 andreas 11211
 * @brief TPageManager::doAKB - Pop up the keyboard icon
11212
 * Pop up the keyboard icon and initialize the text string to that specified.
11213
 * Keyboard string is set to null on power up and is stored until power is lost.
11214
 * The Prompt Text is optional.
11215
 */
11216
void TPageManager::doAKB(int, vector<int>&, vector<string> &pars)
11217
{
11218
    DECL_TRACER("TPageManager::doAKB(int, vector<int>&, vector<string> &pars)");
11219
 
11220
    if (pars.size() < 1)
11221
    {
11222
        MSG_ERROR("Expecting 2 parameters but got only " << pars.size() << "! Ignoring command.");
11223
        return;
11224
    }
11225
 
11226
    string initText = pars[0];
11227
    string promptText;
11228
 
11229
    if (pars.size() > 1)
11230
        promptText = pars[1];
11231
 
63 andreas 11232
    if (initText.empty())
11233
        initText = mAkbText;
11234
    else
11235
        mAkbText = initText;
62 andreas 11236
 
11237
    if (_callKeyboard)
63 andreas 11238
        _callKeyboard(initText, promptText, false);
62 andreas 11239
}
11240
 
63 andreas 11241
/**
11242
 * Pop up the keyboard icon and initialize the text string to that
11243
 * specified.
11244
 */
62 andreas 11245
void TPageManager::doAKEYB(int port, vector<int>& channels, vector<string>& pars)
11246
{
11247
    DECL_TRACER("TPageManager::doAKEYB(int port, vector<int>& channels, vector<string>& pars)");
11248
 
11249
    doAKB(port, channels, pars);
11250
}
11251
 
63 andreas 11252
void TPageManager::doAKEYP(int port, std::vector<int>& channels, std::vector<std::string>& pars)
11253
{
11254
    DECL_TRACER("TPageManager::doAKEYP(int port, std::vector<int>& channels, std::vector<std::string>& pars)");
11255
 
11256
    doAKP(port, channels, pars);
11257
}
11258
 
62 andreas 11259
/**
63 andreas 11260
 * Remove keyboard or keypad that was displayed using 'AKEYB', 'AKEYP', 'PKEYP',
11261
 * @AKB, @AKP, @PKP, @EKP, or @TKP commands.
11262
 */
11263
void TPageManager::doAKEYR(int, vector<int>&, vector<string>&)
11264
{
11265
    DECL_TRACER("TPageManager::doAKEYR(int, vector<int>&, vector<string>&)");
11266
 
11267
    if (_callResetKeyboard)
11268
        _callResetKeyboard();
11269
}
11270
 
11271
/**
62 andreas 11272
 * @brief TPageManager::doAKP - Pop up the keypad icon
11273
 * Pop up the keypad icon and initialize the text string to that specified.
11274
 * Keypad string is set to null on power up and is stored until power is lost.
11275
 * The Prompt Text is optional.
11276
 */
11277
void TPageManager::doAKP(int, std::vector<int>&, std::vector<std::string> &pars)
11278
{
11279
    DECL_TRACER("TPageManager::doAKP(int, vector<int>&, vector<string> &pars)");
11280
 
11281
    if (pars.size() < 1)
11282
    {
11283
        MSG_ERROR("Expecting 2 parameters but got only " << pars.size() << "! Ignoring command.");
11284
        return;
11285
    }
11286
 
11287
    string initText = pars[0];
11288
    string promptText;
11289
 
11290
    if (pars.size() > 1)
11291
        promptText = pars[1];
11292
 
63 andreas 11293
    if (initText.empty())
11294
        initText = mAkpText;
11295
    else
11296
        mAkpText = initText;
62 andreas 11297
 
11298
    if (_callKeypad)
63 andreas 11299
        _callKeypad(initText, promptText, false);
62 andreas 11300
}
11301
 
63 andreas 11302
/**
11303
 * Remove keyboard or keypad that was displayed using 'AKEYB', 'AKEYP', 'PKEYP',
11304
 * @AKB, @AKP, @PKP, @EKP, or @TKP commands.
11305
 */
11306
void TPageManager::doAKR(int port, vector<int>& channels, vector<string>& pars)
62 andreas 11307
{
63 andreas 11308
    DECL_TRACER("TPageManager::doAKR(int, vector<int>&, vector<string>&)");
62 andreas 11309
 
63 andreas 11310
    doAKEYR(port, channels, pars);
62 andreas 11311
}
11312
 
108 andreas 11313
void TPageManager::doABEEP(int, std::vector<int>&, vector<string>&)
11314
{
11315
    DECL_TRACER("TPageManager::doBEEP(int, std::vector<int>&, vector<string>&)");
11316
 
11317
    if (!_playSound)
334 andreas 11318
    {
11319
#if TESTMODE == 1
11320
        setAllDone();
11321
#endif
108 andreas 11322
        return;
334 andreas 11323
    }
108 andreas 11324
 
11325
    string snd = TConfig::getSystemPath(TConfig::SOUNDS) + "/" + TConfig::getSingleBeepSound();
11326
    TValidateFile vf;
11327
 
326 andreas 11328
    if (vf.isValidFile(snd))
108 andreas 11329
        _playSound(snd);
326 andreas 11330
#if TESTMODE == 1
11331
    else
11332
    {
11333
        MSG_PROTOCOL("Sound file invalid!");
334 andreas 11334
        setAllDone();
326 andreas 11335
    }
11336
#endif
108 andreas 11337
}
11338
 
11339
void TPageManager::doADBEEP(int, std::vector<int>&, vector<string>&)
11340
{
11341
    DECL_TRACER("TPageManager::doDBEEP(int, std::vector<int>&, vector<string>&)");
11342
 
11343
    if (!_playSound)
11344
        return;
11345
 
11346
    string snd = TConfig::getSystemPath(TConfig::SOUNDS) + "/" + TConfig::getDoubleBeepSound();
11347
    TValidateFile vf;
11348
 
326 andreas 11349
    if (vf.isValidFile(snd))
108 andreas 11350
        _playSound(snd);
326 andreas 11351
#if TESTMODE == 1
11352
    else
11353
    {
11354
        MSG_PROTOCOL("Sound file invalid!");
334 andreas 11355
        setAllDone();
326 andreas 11356
    }
11357
#endif
108 andreas 11358
}
11359
 
71 andreas 11360
void TPageManager::doBEEP(int, std::vector<int>&, vector<string>&)
11361
{
11362
    DECL_TRACER("TPageManager::doBEEP(int, std::vector<int>&, vector<string>&)");
11363
 
11364
    if (!_playSound)
326 andreas 11365
    {
11366
#if TESTMODE == 1
11367
        MSG_PROTOCOL("Method \"playSound()\" not initialized!");
334 andreas 11368
        setAllDone();
326 andreas 11369
#endif
71 andreas 11370
        return;
326 andreas 11371
    }
71 andreas 11372
 
11373
    string snd = TConfig::getSystemPath(TConfig::SOUNDS) + "/" + TConfig::getSingleBeepSound();
11374
    TValidateFile vf;
108 andreas 11375
    TSystemSound sysSound(TConfig::getSystemPath(TConfig::SOUNDS));
71 andreas 11376
 
326 andreas 11377
    if (sysSound.getSystemSoundState() && vf.isValidFile(snd))
71 andreas 11378
        _playSound(snd);
326 andreas 11379
#if TESTMODE == 1
11380
    else
11381
    {
11382
        if (!sysSound.getSystemSoundState())
11383
        {
11384
            MSG_PROTOCOL("Sound state disabled!")
11385
        }
11386
        else
11387
        {
11388
            MSG_PROTOCOL("Sound file invalid!");
11389
        }
11390
 
334 andreas 11391
        setAllDone();
326 andreas 11392
    }
11393
#endif
71 andreas 11394
}
11395
 
11396
void TPageManager::doDBEEP(int, std::vector<int>&, vector<string>&)
11397
{
11398
    DECL_TRACER("TPageManager::doDBEEP(int, std::vector<int>&, vector<string>&)");
11399
 
11400
    if (!_playSound)
11401
        return;
11402
 
11403
    string snd = TConfig::getSystemPath(TConfig::SOUNDS) + "/" + TConfig::getDoubleBeepSound();
11404
    TValidateFile vf;
108 andreas 11405
    TSystemSound sysSound(TConfig::getSystemPath(TConfig::SOUNDS));
71 andreas 11406
 
326 andreas 11407
    if (sysSound.getSystemSoundState() && vf.isValidFile(snd))
71 andreas 11408
        _playSound(snd);
326 andreas 11409
#if TESTMODE == 1
11410
    else
11411
    {
11412
        if (!sysSound.getSystemSoundState())
11413
        {
11414
            MSG_PROTOCOL("Sound state disabled!")
11415
        }
11416
        else
11417
        {
11418
            MSG_PROTOCOL("Sound file invalid!");
11419
        }
11420
 
334 andreas 11421
        setAllDone();
326 andreas 11422
    }
11423
#endif
71 andreas 11424
}
11425
 
63 andreas 11426
/**
11427
 * @brief Pop up the keypad icon and initialize the text string to that specified.
11428
 * Keypad string is set to null on power up and is stored until power is lost.
11429
 * The Prompt Text is optional.
11430
 */
62 andreas 11431
void TPageManager::doEKP(int port, std::vector<int>& channels, std::vector<std::string>& pars)
11432
{
11433
    DECL_TRACER("TPageManager::doEKP(int port, std::vector<int>& channels, std::vector<std::string>& pars)");
11434
 
11435
    doAKP(port, channels, pars);
11436
}
63 andreas 11437
 
11438
/**
11439
 * @brief Present a private keyboard.
11440
 * Pops up the keyboard icon and initializes the text string to that specified.
11441
 * Keyboard displays a '*' instead of the letters typed. The Prompt Text is optional.
11442
 */
11443
void TPageManager::doPKB(int, vector<int>&, vector<string>& pars)
11444
{
11445
    DECL_TRACER("TPageManager::doPKB(int, vector<int>&, vector<string>& pars)");
11446
 
11447
    if (pars.size() < 1)
11448
    {
11449
        MSG_ERROR("Expecting 2 parameters but got only " << pars.size() << "! Ignoring command.");
11450
        return;
11451
    }
11452
 
11453
    string initText = pars[0];
11454
    string promptText;
11455
 
11456
    if (pars.size() > 1)
11457
        promptText = pars[1];
11458
 
11459
    if (_callKeyboard)
11460
        _callKeyboard(initText, promptText, true);
11461
}
11462
 
11463
/**
11464
 * @brief Present a private keypad.
11465
 * Pops up the keypad icon and initializes the text string to that specified.
11466
 * Keypad displays a '*' instead of the numbers typed. The Prompt Text is optional.
11467
 */
11468
void TPageManager::doPKP(int, vector<int>&, vector<string>& pars)
11469
{
11470
    DECL_TRACER("TPageManager::doPKP(int, vector<int>&, vector<string>& pars)");
11471
 
11472
    if (pars.size() < 1)
11473
    {
11474
        MSG_ERROR("Expecting 2 parameters but got only " << pars.size() << "! Ignoring command.");
11475
        return;
11476
    }
11477
 
11478
    string initText = pars[0];
11479
    string promptText;
11480
 
11481
    if (pars.size() > 1)
11482
        promptText = pars[1];
11483
 
11484
    if (_callKeypad)
11485
        _callKeypad(initText, promptText, true);
11486
}
11487
 
11488
/**
408 andreas 11489
 * @brief Reset protected password command
11490
 * This command is used to reset the protected setup password to the factory
11491
 * default value.
11492
 */
11493
void TPageManager::doRPP(int, vector<int>&, vector<string>&)
11494
{
11495
    DECL_TRACER("TPageManager::doRPP(int, vector<int>&, vector<string>&)");
11496
 
11497
    TConfig::savePassword1("1988");
11498
}
11499
 
11500
/**
64 andreas 11501
 * Send panel to SETUP page.
11502
 */
11503
void TPageManager::doSetup(int, vector<int>&, vector<string>&)
11504
{
11505
    DECL_TRACER("TPageManager::doSetup(int, vector<int>&, vector<string>&)");
11506
 
11507
    if (_callShowSetup)
11508
        _callShowSetup();
11509
}
11510
 
11511
/**
11512
 * Shut down the App
11513
 */
11514
void TPageManager::doShutdown(int, vector<int>&, vector<string>&)
11515
{
11516
    DECL_TRACER("TPageManager::doShutdown(int, vector<int>&, vector<string>&)");
11517
 
97 andreas 11518
    MSG_PROTOCOL("Received shutdown ...");
64 andreas 11519
#ifdef __ANDROID__
11520
    stopNetworkState();
11521
#endif
11522
    prg_stopped = true;
11523
    killed = true;
11524
 
11525
    if (_shutdown)
11526
        _shutdown();
11527
}
11528
 
82 andreas 11529
void TPageManager::doSOU(int, vector<int>&, vector<string>& pars)
11530
{
11531
    DECL_TRACER("TPageManager::doSOU(int, vector<int>&, vector<string>& pars)");
11532
 
11533
    if (pars.size() < 1)
11534
    {
11535
        MSG_ERROR("@SOU: Expecting a sound file as parameter! Ignoring command.");
11536
        return;
11537
    }
11538
 
11539
    if (!_playSound)
11540
    {
11541
        MSG_ERROR("@SOU: Missing sound module!");
11542
        return;
11543
    }
11544
 
165 andreas 11545
    if (pars[0].empty() || strCaseCompare(pars[0], "None") == 0)
11546
        return;
11547
 
82 andreas 11548
    _playSound(pars[0]);
11549
}
11550
 
326 andreas 11551
void TPageManager::doMUT(int, vector<int>&, vector<string>& pars)
11552
{
11553
    DECL_TRACER("TPageManager::doMUT(int, vector<int>&, vector<string>& pars)");
11554
 
11555
    if (pars.size() < 1)
11556
    {
11557
        MSG_ERROR("^MUT: Expecting a state parameter! Ignoring command.");
11558
        return;
11559
    }
11560
 
11561
    bool mute = 0;
11562
 
11563
    if (pars[0] == "0")
11564
        mute = false;
11565
    else
11566
        mute = true;
11567
 
11568
    TConfig::setMuteState(mute);
11569
#if TESTMODE == 1
327 andreas 11570
    if (_gTestMode)
11571
    {
11572
        bool st = TConfig::getMuteState();
11573
        _gTestMode->setResult(st ? "1" : "0");
11574
    }
11575
 
326 andreas 11576
    __success = true;
334 andreas 11577
    setAllDone();
326 andreas 11578
#endif
11579
}
11580
 
64 andreas 11581
/**
63 andreas 11582
 * @brief Present a telephone keypad.
11583
 * Pops up the keypad icon and initializes the text string to that specified.
11584
 * The Prompt Text is optional.
11585
 */
11586
void TPageManager::doTKP(int port, vector<int>& channels, vector<string>& pars)
11587
{
11588
    DECL_TRACER("TPageManager::doTKP(int port, vector<int>& channels, vector<string>& pars)");
11589
 
11590
    // TODO: Implement a real telefone keypad.
11591
    doAKP(port, channels, pars);
11592
}
11593
 
11594
/**
11595
 * Popup the virtual keyboard
11596
 */
123 andreas 11597
void TPageManager::doVKB(int port, vector<int>& channels, vector<string>& pars)
63 andreas 11598
{
123 andreas 11599
    DECL_TRACER("TPageManager::doVKB(int port, vector<int>& channels, vector<string>& pars)");
63 andreas 11600
 
11601
    doAKP(port, channels, pars);
11602
}
129 andreas 11603
#ifndef _NOSIP_
123 andreas 11604
void TPageManager::sendPHN(vector<string>& cmds)
11605
{
11606
    DECL_TRACER("TPageManager::sendPHN(const vector<string>& cmds)");
11607
 
11608
    vector<int> channels;
11609
    doPHN(-1, channels, cmds);
11610
}
11611
 
141 andreas 11612
void TPageManager::actPHN(vector<string>& cmds)
11613
{
11614
    DECL_TRACER("TPageManager::actPHN(const vector<string>& cmds)");
11615
 
11616
    vector<int> channels;
11617
    doPHN(1, channels, cmds);
11618
}
11619
 
140 andreas 11620
void TPageManager::phonePickup(int id)
11621
{
11622
    DECL_TRACER("TPageManager::phonePickup(int id)");
11623
 
11624
    if (id < 0 || id >= 4)
11625
        return;
11626
 
11627
    if (mSIPClient)
11628
        mSIPClient->pickup(id);
11629
}
11630
 
11631
void TPageManager::phoneHangup(int id)
11632
{
11633
    DECL_TRACER("TPageManager::phoneHangup(int id)");
11634
 
11635
    if (id < 0 || id >= 4)
11636
        return;
11637
 
11638
    if (mSIPClient)
11639
        mSIPClient->terminate(id);
11640
}
11641
 
123 andreas 11642
/**
11643
 * @brief Phone commands.
11644
 * The phone commands could come from the master or are send to the master.
11645
 * If the parameter \p port is less then 0 (zero) a command is send to the
11646
 * master. In any other case the command came from the mater.
125 andreas 11647
 *
11648
 * @param port  This is used to signal if the command was sent by the master
11649
 *              or generated from the panel. If ths is less then 0, then the
11650
 *              method was called because of an event happen in the panel.
11651
 *              If this is grater or equal 0, then the event is comming from
11652
 *              the master.
11653
 * @param pars  This are parameters. The first parameter defines the action
11654
 *              to be done. According to the command this parameter may have a
11655
 *              different number of arguments.
123 andreas 11656
 */
11657
void TPageManager::doPHN(int port, vector<int>&, vector<string>& pars)
11658
{
11659
    DECL_TRACER("TPageManager::doPHN(int port, vector<int>&, vector<string>& pars)");
11660
 
11661
    if (pars.size() < 1)
11662
    {
11663
        MSG_ERROR("Expecting at least 1 parameter but got none! Ignoring command.");
11664
        return;
11665
    }
11666
 
11667
    string sCommand;
11668
    string cmd = toUpper(pars[0]);
11669
 
11670
    // Master to panel
11671
    if (port >= 0)
11672
    {
11673
        if (!mSIPClient)
11674
        {
11675
            MSG_ERROR("SIP client class was not initialized!")
11676
            return;
11677
        }
11678
 
11679
        if (cmd == "ANSWER")
11680
        {
11681
            if (pars.size() >= 2)
11682
            {
124 andreas 11683
                int id = atoi(pars[1].c_str());
11684
 
11685
                if (mSIPClient->getSIPState(id) == TSIPClient::SIP_HOLD)
11686
                    mSIPClient->resume(id);
11687
                else
135 andreas 11688
                    mSIPClient->pickup(id);
123 andreas 11689
            }
11690
        }
11691
        else if (cmd == "AUTOANSWER")
11692
        {
11693
            if (pars.size() >= 2)
11694
            {
11695
                if (pars[1].at(0) == '0')
11696
                    mPHNautoanswer = false;
11697
                else
11698
                    mPHNautoanswer = true;
127 andreas 11699
 
11700
                vector<string> cmds;
11701
                cmds = { "AUTOANSWER", to_string(mPHNautoanswer ? 1 : 0) };
128 andreas 11702
                sendPHN(cmds);
123 andreas 11703
            }
11704
        }
11705
        else if (cmd == "CALL")     // Initiate a call
11706
        {
11707
            if (pars.size() >= 2)
127 andreas 11708
                mSIPClient->call(pars[1]);
123 andreas 11709
        }
11710
        else if (cmd == "DTMF")     // Send tone modified codes
11711
        {
127 andreas 11712
            if (pars.size() >= 2)
11713
                mSIPClient->sendDTMF(pars[1]);
123 andreas 11714
        }
11715
        else if (cmd == "HANGUP")   // terminate a call
11716
        {
124 andreas 11717
            if (pars.size() >= 2)
11718
            {
11719
                int id = atoi(pars[1].c_str());
11720
                mSIPClient->terminate(id);
11721
            }
123 andreas 11722
        }
11723
        else if (cmd == "HOLD")     // Hold the line
11724
        {
124 andreas 11725
            if (pars.size() >= 2)
11726
            {
11727
                int id = atoi(pars[1].c_str());
11728
                mSIPClient->hold(id);
11729
            }
123 andreas 11730
        }
128 andreas 11731
        else if (cmd == "LINESTATE") // State of all line
127 andreas 11732
        {
128 andreas 11733
            mSIPClient->sendLinestate();
127 andreas 11734
        }
123 andreas 11735
        else if (cmd == "PRIVACY")  // Set/unset "do not disturb"
11736
        {
128 andreas 11737
            if (pars.size() >= 2)
11738
            {
11739
                bool state = (pars[1].at(0) == '1' ? true : false);
11740
                mSIPClient->sendPrivate(state);
11741
            }
123 andreas 11742
        }
11743
        else if (cmd == "REDIAL")   // Redials the last number
11744
        {
128 andreas 11745
            mSIPClient->redial();
123 andreas 11746
        }
11747
        else if (cmd == "TRANSFER") // Transfer call to provided number
11748
        {
128 andreas 11749
            if (pars.size() >= 3)
11750
            {
11751
                int id = atoi(pars[1].c_str());
11752
                string num = pars[2];
11753
 
11754
                if (mSIPClient->transfer(id, num))
11755
                {
11756
                    vector<string> cmds;
11757
                    cmds.push_back("TRANSFERRED");
11758
                    sendPHN(cmds);
11759
                }
11760
            }
123 andreas 11761
        }
144 andreas 11762
        else if (cmd == "IM")
11763
        {
11764
            if (pars.size() < 3)
11765
                return;
11766
 
11767
            string to = pars[1];
11768
            string msg = pars[2];
11769
            string toUri;
11770
 
11771
            if (to.find("sip:") == string::npos)
11772
                toUri = "sip:";
11773
 
11774
            toUri += to;
11775
 
11776
            if (to.find("@") == string::npos)
11777
                toUri += "@" + TConfig::getSIPproxy();
11778
 
11779
            mSIPClient->sendIM(toUri, msg);
11780
        }
123 andreas 11781
        else if (cmd == "SETUP")    // Some temporary settings
11782
        {
11783
            if (pars.size() < 2)
11784
                return;
11785
 
11786
            if (pars[1] == "DOMAIN" && pars.size() >= 3)
11787
                TConfig::setSIPdomain(pars[2]);
11788
            else if (pars[1] == "DTMFDURATION")
11789
            {
138 andreas 11790
                unsigned int ms = atoi(pars[2].c_str());
11791
                mSIPClient->setDTMFduration(ms);
123 andreas 11792
            }
11793
            else if (pars[1] == "ENABLE")   // (re)register user
11794
            {
11795
                TConfig::setSIPstatus(true);
127 andreas 11796
                mSIPClient->cleanUp();
135 andreas 11797
                mSIPClient->init();
123 andreas 11798
            }
127 andreas 11799
            else if (pars[1] == "DOMAIN" && pars.size() >= 3)
11800
                TConfig::setSIPdomain(pars[2]);
123 andreas 11801
            else if (pars[1] == "PASSWORD" && pars.size() >= 3)
11802
                TConfig::setSIPpassword(pars[2]);
11803
            else if (pars[1] == "PORT" && pars.size() != 3)
11804
                TConfig::setSIPport(atoi(pars[2].c_str()));
11805
            else if (pars[1] == "PROXYADDR" && pars.size() >= 3)
11806
                TConfig::setSIPproxy(pars[2]);
11807
            else if (pars[1] == "STUNADDR" && pars.size() >= 3)
11808
                TConfig::setSIPstun(pars[2]);
11809
            else if (pars[1] == "USERNAME" && pars.size() >= 3)
11810
                TConfig::setSIPuser(pars[2]);
11811
        }
11812
        else
11813
        {
11814
            MSG_ERROR("Unknown command ^PHN-" << cmd << " ignored!");
11815
        }
11816
    }
11817
    else   // Panel to master
11818
    {
11819
        vector<string>::iterator iter;
11820
 
11821
        for (iter = pars.begin(); iter != pars.end(); ++iter)
11822
        {
11823
            if (!sCommand.empty())
11824
                sCommand += ",";
11825
 
11826
            sCommand += *iter;
11827
        }
11828
 
11829
        sendPHNcommand(sCommand);
11830
    }
11831
}
127 andreas 11832
 
11833
void TPageManager::getPHN(int, vector<int>&, vector<string>& pars)
11834
{
11835
    DECL_TRACER("TPageManager::getPHN(int, vector<int>&, vector<string>& pars)");
11836
 
11837
    if (pars.size() < 1)
11838
    {
11839
        MSG_ERROR("Invalid number of arguments!");
11840
        return;
11841
    }
11842
 
11843
    string cmd = pars[0];
11844
 
11845
    if (cmd == "AUTOANSWER")
11846
        sendPHNcommand(cmd + "," + (mPHNautoanswer ? "1" : "0"));
11847
    else if (cmd == "LINESTATE")
11848
    {
11849
        if (!mSIPClient)
11850
            return;
11851
 
138 andreas 11852
        mSIPClient->sendLinestate();
127 andreas 11853
    }
11854
    else if (cmd == "MSGWAITING")
11855
    {
144 andreas 11856
        size_t num = mSIPClient->getNumberMessages();
11857
        sendPHNcommand(cmd + "," + (num > 0 ? "1" : "0") + "," + std::to_string(num) + "0,0,0");
127 andreas 11858
    }
11859
    else if (cmd == "PRIVACY")
11860
    {
138 andreas 11861
        if (mSIPClient->getPrivate())
11862
            sendPHNcommand(cmd + ",1");
11863
        else
11864
            sendPHNcommand(cmd + ",0");
127 andreas 11865
    }
144 andreas 11866
    else if (cmd == "REDIAL")
11867
    {
11868
        if (pars.size() < 2)
11869
            return;
11870
 
11871
        sendPHNcommand(cmd + "," + pars[1]);
11872
    }
127 andreas 11873
    else
11874
    {
11875
        MSG_WARNING("Unknown command " << cmd << " found!");
11876
    }
11877
}
129 andreas 11878
#endif  // _NOSIP_
134 andreas 11879
 
300 andreas 11880
/*
318 andreas 11881
 *  Hide all subpages in a subpage viewer button.
11882
 */
11883
void TPageManager::doSHA(int port, vector<int> &channels, vector<string> &pars)
11884
{
11885
    DECL_TRACER("TPageManager::doSHA(int port, vector<int> &channels, vector<string> &pars)");
11886
 
343 andreas 11887
    Q_UNUSED(pars);
318 andreas 11888
    vector<TMap::MAP_T> map = findButtons(port, channels);
11889
 
11890
    if (TError::isError() || map.empty())
11891
        return;
11892
 
11893
    vector<Button::TButton *> buttons = collectButtons(map);
11894
 
11895
    if (!buttons.empty())
11896
    {
11897
        vector<Button::TButton *>::iterator mapIter;
11898
 
11899
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
11900
        {
11901
            Button::TButton *bt = *mapIter;
11902
 
11903
            if (_hideAllSubViewItems)
11904
                _hideAllSubViewItems(bt->getHandle());
11905
        }
11906
    }
11907
}
11908
 
11909
void TPageManager::doSHD(int port, vector<int>& channels, vector<string>& pars)
11910
{
11911
    DECL_TRACER("TPageManager::doSHD(int port, vector<int>& channels, vector<string>& pars)");
11912
 
11913
    if (pars.size() < 1)
11914
        return;
11915
 
11916
    string name = pars[0];
11917
 
11918
    vector<TMap::MAP_T> map = findButtons(port, channels);
11919
 
11920
    if (TError::isError() || map.empty())
11921
        return;
11922
 
11923
    vector<Button::TButton *> buttons = collectButtons(map);
11924
 
11925
    if (!buttons.empty())
11926
    {
11927
        vector<Button::TButton *>::iterator mapIter;
11928
 
11929
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
11930
        {
11931
            Button::TButton *bt = *mapIter;
11932
 
11933
            vector<TSubPage *> subviews = createSubViewList(bt->getSubViewID());
11934
 
11935
            if (subviews.empty())
11936
                continue;
11937
 
11938
            vector<TSubPage *>::iterator itSub;
11939
 
11940
            for (itSub = subviews.begin(); itSub != subviews.end(); ++itSub)
11941
            {
11942
                TSubPage *sub = *itSub;
11943
 
11944
                if (sub && sub->getName() == name)
11945
                {
11946
                    if (_hideSubViewItem)
11947
                        _hideSubViewItem(bt->getHandle(), sub->getHandle());
11948
 
11949
                    break;
11950
                }
11951
            }
11952
        }
11953
    }
11954
}
11955
 
11956
void TPageManager::doSPD(int port, vector<int>& channels, vector<string>& pars)
11957
{
11958
    DECL_TRACER("TPageManager::doSPD(int port, vector<int>& channel, vector<string>& pars)");
11959
 
11960
    if (pars.size() < 1)
11961
        return;
11962
 
11963
    TError::clear();
11964
    int padding = atoi(pars[0].c_str());
11965
 
11966
    if (padding < 0 || padding > 100)
11967
        return;
11968
 
11969
    vector<TMap::MAP_T> map = findButtons(port, channels);
11970
 
11971
    if (TError::isError() || map.empty())
11972
        return;
11973
 
11974
    vector<Button::TButton *> buttons = collectButtons(map);
11975
 
11976
    if (!buttons.empty())
11977
    {
11978
        vector<Button::TButton *>::iterator mapIter;
11979
 
11980
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
11981
        {
11982
            Button::TButton *bt = *mapIter;
11983
 
11984
            if (_setSubViewPadding)
11985
                _setSubViewPadding(bt->getHandle(), padding);
11986
        }
11987
    }
11988
}
11989
 
11990
/*
300 andreas 11991
 * This command will perform one of three different operations based on the following conditions:
11992
 * 1. If the named subpage is hidden in the set associated with the viewer button it will be shown in the anchor position.
11993
 * 2. If the named subpage is not present in the set it will be added to the set and shown in the anchor position.
11994
 * 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
11995
 * position. The anchor position is the location on the subpage viewer button specified by its weighting. This will either be
11996
 * left, center or right for horizontal subpage viewer buttons or top, center or bottom for vertical subpage viewer buttons.
11997
 * Surrounding subpages are relocated on the viewer button as needed to accommodate the described operations
11998
 */
11999
void TPageManager::doSSH(int port, vector<int> &channels, vector<string> &pars)
12000
{
12001
    DECL_TRACER("TPageManager::doSSH(int port, vector<int> &channels, vector<string> &pars)");
12002
 
12003
    if (pars.size() < 1)
12004
    {
12005
        MSG_ERROR("Expecting 1 parameter but got none! Ignoring command.");
12006
        return;
12007
    }
12008
 
12009
    TError::clear();
12010
    string name = pars[0];
12011
    int position = 0;   // optional
12012
    int time = 0;       // optional
12013
 
12014
    if (pars.size() > 1)
12015
        position = atoi(pars[1].c_str());
12016
 
12017
    if (pars.size() > 2)
12018
        time = atoi(pars[2].c_str());
12019
 
12020
    vector<TMap::MAP_T> map = findButtons(port, channels);
12021
 
12022
    if (TError::isError() || map.empty())
12023
        return;
12024
 
12025
    vector<Button::TButton *> buttons = collectButtons(map);
12026
 
12027
    if (!buttons.empty())
12028
    {
12029
        vector<Button::TButton *>::iterator mapIter;
12030
 
12031
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
12032
        {
12033
            Button::TButton *bt = *mapIter;
12034
            vector<TSubPage *> subviews = createSubViewList(bt->getSubViewID());
12035
 
12036
            if (subviews.empty() || !bt)
12037
                continue;
12038
 
12039
            vector<TSubPage *>::iterator itSub;
12040
 
12041
            for (itSub = subviews.begin(); itSub != subviews.end(); ++itSub)
12042
            {
12043
                TSubPage *sub = *itSub;
12044
 
12045
                if (sub && sub->getName() == name)
12046
                {
12047
                    if (_showSubViewItem)
12048
                        _showSubViewItem(sub->getHandle(), bt->getHandle(), position, time);
12049
 
12050
                    break;
12051
                }
12052
            }
12053
        }
12054
    }
12055
}
12056
 
318 andreas 12057
void TPageManager::doSTG(int port, vector<int>& channels, vector<string>& pars)
12058
{
12059
    DECL_TRACER("TPageManager::doSTG(int port, vector<int>& channels, vector<string>& pars)");
12060
 
12061
    if (pars.empty())
12062
    {
12063
        MSG_ERROR("Expecting 1 parameter but got none! Ignoring command.");
12064
        return;
12065
    }
12066
 
12067
    TError::clear();
12068
    string name = pars[0];
12069
    int position = 0;   // optional
12070
    int time = 0;       // optional
12071
 
12072
    if (pars.size() > 1)
12073
        position = atoi(pars[1].c_str());
12074
 
12075
    if (pars.size() > 2)
12076
        time = atoi(pars[2].c_str());
12077
 
12078
    vector<TMap::MAP_T> map = findButtons(port, channels);
12079
 
12080
    if (TError::isError() || map.empty())
12081
        return;
12082
 
12083
    vector<Button::TButton *> buttons = collectButtons(map);
12084
 
12085
    if (!buttons.empty())
12086
    {
12087
        vector<Button::TButton *>::iterator mapIter;
12088
 
12089
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
12090
        {
12091
            Button::TButton *bt = *mapIter;
12092
            vector<TSubPage *> subviews = createSubViewList(bt->getSubViewID());
12093
 
12094
            if (subviews.empty() || !bt)
12095
                continue;
12096
 
12097
            vector<TSubPage *>::iterator itSub;
12098
 
12099
            for (itSub = subviews.begin(); itSub != subviews.end(); ++itSub)
12100
            {
12101
                TSubPage *sub = *itSub;
12102
 
12103
                if (sub && sub->getName() == name)
12104
                {
12105
                    if (_toggleSubViewItem)
12106
                        _toggleSubViewItem(sub->getHandle(), bt->getHandle(), position, time);
12107
 
12108
                    break;
12109
                }
12110
            }
12111
        }
12112
    }
12113
}
12114
 
227 andreas 12115
void TPageManager::doLVD(int port, vector<int> &channels, vector<string> &pars)
225 andreas 12116
{
227 andreas 12117
    DECL_TRACER("TPageManager::doLVD(int port, vector<int> &channels, vector<string> &pars)");
225 andreas 12118
 
12119
    if (pars.size() < 1)
12120
    {
12121
        MSG_ERROR("Expecting one parameter but got none! Ignoring command.");
12122
        return;
12123
    }
12124
 
12125
    TError::clear();
12126
    string source = pars[0];
12127
    vector<string> configs;
12128
 
12129
    if (pars.size() > 1)
12130
    {
12131
        for (size_t i = 1; i < pars.size(); ++i)
227 andreas 12132
        {
12133
            string low = toLower(pars[i]);
12134
 
12135
            if (low.find_first_of("user=") != string::npos ||
12136
                low.find_first_of("pass=") != string::npos ||
12137
                low.find_first_of("csv=")  != string::npos ||
12138
                low.find_first_of("has_headers=") != string::npos)
12139
            {
12140
                configs.push_back(pars[i]);
12141
            }
12142
        }
225 andreas 12143
    }
12144
 
12145
    vector<TMap::MAP_T> map = findButtons(port, channels);
12146
 
12147
    if (TError::isError() || map.empty())
12148
        return;
12149
 
12150
    vector<Button::TButton *> buttons = collectButtons(map);
12151
 
12152
    if (buttons.size() > 0)
12153
    {
12154
        vector<Button::TButton *>::iterator mapIter;
12155
 
12156
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
12157
        {
12158
            Button::TButton *bt = *mapIter;
12159
            bt->setListSource(source, configs);
12160
        }
12161
    }
12162
 
12163
}
12164
 
230 andreas 12165
void TPageManager::doLVE(int port, vector<int> &channels, vector<string> &pars)
12166
{
12167
    DECL_TRACER("TPageManager::doLVE(int port, vector<int> &channels, vector<string> &pars)");
12168
 
12169
    if (pars.size() < 1)
12170
    {
12171
        MSG_ERROR("Expecting one parameter but got none! Ignoring command.");
12172
        return;
12173
    }
12174
 
12175
    TError::clear();
12176
    int num = atoi(pars[0].c_str());
12177
 
12178
    vector<TMap::MAP_T> map = findButtons(port, channels);
12179
 
12180
    if (TError::isError() || map.empty())
12181
        return;
12182
 
12183
    vector<Button::TButton *> buttons = collectButtons(map);
12184
 
12185
    if (buttons.size() > 0)
12186
    {
12187
        vector<Button::TButton *>::iterator mapIter;
12188
 
12189
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
12190
        {
12191
            Button::TButton *bt = *mapIter;
12192
            bt->setListViewEventNumber(num);
12193
        }
12194
    }
12195
 
12196
}
12197
 
227 andreas 12198
void TPageManager::doLVF(int port, vector<int> &channels, vector<string> &pars)
12199
{
12200
    DECL_TRACER("TPageManager::doLVF(int port, vector<int> &channels, vector<string> &pars)");
12201
 
12202
    if (pars.size() < 1)
12203
    {
12204
        MSG_ERROR("Expecting one parameter but got none! Ignoring command.");
12205
        return;
12206
    }
12207
 
12208
    TError::clear();
12209
    string filter;
12210
 
12211
    vector<string>::iterator iter;
12212
 
12213
    for (iter = pars.begin(); iter != pars.end(); ++iter)
12214
    {
12215
        if (filter.length() > 0)
12216
            filter += ",";
12217
 
12218
        filter += *iter;
12219
    }
12220
 
12221
    vector<TMap::MAP_T> map = findButtons(port, channels);
12222
 
12223
    if (TError::isError() || map.empty())
12224
        return;
12225
 
12226
    vector<Button::TButton *> buttons = collectButtons(map);
12227
 
12228
    if (buttons.size() > 0)
12229
    {
12230
        vector<Button::TButton *>::iterator mapIter;
12231
 
12232
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
12233
        {
12234
            Button::TButton *bt = *mapIter;
12235
            bt->setListSourceFilter(filter);
12236
        }
12237
    }
12238
}
12239
 
230 andreas 12240
void TPageManager::doLVL(int port, vector<int> &channels, vector<string> &pars)
12241
{
12242
    DECL_TRACER("TPageManager::doLVL(int port, vector<int> &channels, vector<string> &pars)");
12243
 
12244
    if (pars.size() < 1)
12245
    {
12246
        MSG_ERROR("Expecting one parameter but got none! Ignoring command.");
12247
        return;
12248
    }
12249
 
12250
    TError::clear();
233 andreas 12251
    bool hasColumns = false;
230 andreas 12252
    int columns = 0;
233 andreas 12253
    bool hasLayout = false;
230 andreas 12254
    int layout = 0;
233 andreas 12255
    bool hasComponent = false;
12256
    int component = 0;
12257
    bool hasCellHeight = false;
12258
    bool cellHeightPercent = false;
12259
    int cellheight = 0;
12260
    bool hasP1 = false;
12261
    int p1 = 0;
12262
    bool hasP2 = false;
12263
    int p2 = 0;
12264
    bool hasFilter = false;
12265
    bool filter = false;
12266
    bool hasFilterHeight = false;
12267
    bool filterHeightPercent = false;
12268
    int filterheight = 0;
12269
    bool hasAlphaScroll = false;
12270
    bool alphascroll = false;
230 andreas 12271
 
12272
    vector<string>::iterator iter;
12273
 
12274
    for (iter = pars.begin(); iter != pars.end(); ++iter)
12275
    {
12276
        string low = toLower(*iter);
12277
 
12278
        if (low.find("columns=") != string::npos ||
12279
            low.find("nc=") != string::npos ||
12280
            low.find("numcol=") != string::npos)
12281
        {
12282
            size_t pos = low.find("=");
12283
            string sCols = low.substr(pos + 1);
12284
            columns = atoi(sCols.c_str());
233 andreas 12285
            hasColumns = true;
12286
        }
12287
        else if (low.find("c=") != string::npos || low.find("comp=") != string::npos)
12288
        {
12289
            size_t pos = low.find("=");
12290
            string sComp = low.substr(pos + 1);
12291
            component |= atoi(sComp.c_str());
12292
            hasComponent = true;
12293
        }
12294
        else if (low.find("l=") != string::npos || low.find("layout=") != string::npos)
12295
        {
12296
            size_t pos = low.find("=");
12297
            string sLay = low.substr(pos + 1);
12298
            layout = atoi(sLay.c_str());
12299
            hasLayout = true;
12300
        }
12301
        else if (low.find("ch=") != string::npos || low.find("cellheight=") != string::npos)
12302
        {
12303
            size_t pos = low.find("=");
12304
            string sCh = low.substr(pos + 1);
12305
            cellheight = atoi(sCh.c_str());
230 andreas 12306
 
233 andreas 12307
            if (low.find("%") != string::npos)
12308
                cellHeightPercent = true;
12309
 
12310
            hasCellHeight = true;
230 andreas 12311
        }
233 andreas 12312
        else if (low.find("p1=") != string::npos)
12313
        {
12314
            size_t pos = low.find("=");
12315
            string sP1 = low.substr(pos + 1);
12316
            p1 = atoi(sP1.c_str());
12317
            hasP1 = true;
12318
        }
12319
        else if (low.find("p2=") != string::npos)
12320
        {
12321
            size_t pos = low.find("=");
12322
            string sP2 = low.substr(pos + 1);
12323
            p2 = atoi(sP2.c_str());
12324
            hasP2 = true;
12325
        }
12326
        else if (low.find("f=") != string::npos || low.find("filter=") != string::npos)
12327
        {
12328
            size_t pos = low.find("=");
12329
            string sFilter = low.substr(pos + 1);
12330
            filter = isTrue(sFilter);
12331
            hasFilter = true;
12332
        }
12333
        else if (low.find("fh=") != string::npos || low.find("filterheight=") != string::npos)
12334
        {
12335
            size_t pos = low.find("=");
12336
            string sFilter = low.substr(pos + 1);
12337
            filterheight = atoi(sFilter.c_str());
12338
 
12339
            if (low.find("%") != string::npos)
12340
                filterHeightPercent = true;
12341
 
12342
            hasFilterHeight = true;
12343
        }
12344
        else if (low.find("as=") != string::npos || low.find("alphascroll=") != string::npos)
12345
        {
12346
            size_t pos = low.find("=");
12347
            string sAlpha = low.substr(pos + 1);
12348
            alphascroll = isTrue(sAlpha);
12349
            hasAlphaScroll = true;
12350
        }
230 andreas 12351
    }
12352
 
12353
    vector<TMap::MAP_T> map = findButtons(port, channels);
12354
 
12355
    if (TError::isError() || map.empty())
12356
        return;
12357
 
12358
    vector<Button::TButton *> buttons = collectButtons(map);
12359
 
12360
    if (buttons.size() > 0)
12361
    {
12362
        vector<Button::TButton *>::iterator mapIter;
12363
 
12364
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
12365
        {
12366
            Button::TButton *bt = *mapIter;
233 andreas 12367
 
12368
            if (hasColumns)         bt->setListViewColumns(columns);
12369
            if (hasComponent)       bt->setListViewComponent(component);
12370
            if (hasLayout)          bt->setListViewLayout(layout);
12371
            if (hasCellHeight)      bt->setListViewCellheight(cellheight, cellHeightPercent);
12372
            if (hasP1)              bt->setListViewP1(p1);
12373
            if (hasP2)              bt->setListViewP2(p2);
12374
            if (hasFilter)          bt->setListViewColumnFilter(filter);
12375
            if (hasFilterHeight)    bt->setListViewFilterHeight(filterheight, filterHeightPercent);
12376
            if (hasAlphaScroll)     bt->setListViewAlphaScroll(alphascroll);
230 andreas 12377
        }
12378
    }
12379
}
12380
 
233 andreas 12381
void TPageManager::doLVM(int port, vector<int> &channels, vector<string> &pars)
12382
{
12383
    DECL_TRACER("TPageManager::doLVM(int port, vector<int> &channels, vector<string> &pars)");
12384
 
12385
    if (pars.size() < 1)
12386
    {
12387
        MSG_ERROR("Expecting one parameter but got none! Ignoring command.");
12388
        return;
12389
    }
12390
 
12391
    TError::clear();
12392
    map<string,string> mapField;
12393
 
12394
    vector<string>::iterator iter;
12395
 
12396
    for (iter = pars.begin(); iter != pars.end(); ++iter)
12397
    {
12398
        string left, right;
12399
        size_t pos = 0;
12400
 
12401
        if ((pos = iter->find("=")) != string::npos)
12402
        {
12403
            string left = iter->substr(0, pos);
12404
            left = toLower(left);
12405
            string right = iter->substr(pos + 1);
12406
 
12407
            if (left == "t1" || left == "t2" || left == "i1")
12408
                mapField.insert(pair<string,string>(left, right));
12409
        }
12410
    }
12411
 
12412
    vector<TMap::MAP_T> map = findButtons(port, channels);
12413
 
12414
    if (TError::isError() || map.empty())
12415
        return;
12416
 
12417
    vector<Button::TButton *> buttons = collectButtons(map);
12418
 
12419
    if (buttons.size() > 0)
12420
    {
12421
        vector<Button::TButton *>::iterator mapIter;
12422
 
12423
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
12424
        {
12425
            Button::TButton *bt = *mapIter;
12426
            bt->setListViewFieldMap(mapField);
12427
        }
12428
    }
12429
}
12430
 
12431
void TPageManager::doLVN(int port, vector<int> &channels, vector<string> &pars)
12432
{
12433
    DECL_TRACER("TPageManager::doLVN(int port, vector<int> &channels, vector<string> &pars)");
12434
 
12435
    if (pars.size() < 1)
12436
    {
12437
        MSG_ERROR("Expecting one parameter but got none! Ignoring command.");
12438
        return;
12439
    }
12440
 
12441
    TError::clear();
12442
    string command = pars[0];
12443
    bool select = false;
12444
 
12445
    if (pars.size() > 1)
12446
    {
12447
        if (isTrue(pars[1]))
12448
            select = true;
12449
    }
12450
 
12451
    vector<TMap::MAP_T> map = findButtons(port, channels);
12452
 
12453
    if (TError::isError() || map.empty())
12454
        return;
12455
 
12456
    vector<Button::TButton *> buttons = collectButtons(map);
12457
 
12458
    if (buttons.size() > 0)
12459
    {
12460
        vector<Button::TButton *>::iterator mapIter;
12461
 
12462
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
12463
        {
12464
            Button::TButton *bt = *mapIter;
12465
            bt->listViewNavigate(command, select);
12466
        }
12467
    }
12468
}
12469
 
12470
void TPageManager::doLVR(int port, vector<int> &channels, vector<string> &pars)
12471
{
12472
    DECL_TRACER("TPageManager::doLVR(int port, vector<int> &channels, vector<string> &pars)");
12473
 
12474
    TError::clear();
12475
    int interval = -1;
12476
    bool force = false;
12477
 
12478
    if (pars.size() > 0)
12479
        interval = atoi(pars[0].c_str());
12480
 
12481
    if (pars.size() > 1)
12482
        force = isTrue(pars[1]);
12483
 
12484
    vector<TMap::MAP_T> map = findButtons(port, channels);
12485
 
12486
    if (TError::isError() || map.empty())
12487
        return;
12488
 
12489
    vector<Button::TButton *> buttons = collectButtons(map);
12490
 
12491
    if (buttons.size() > 0)
12492
    {
12493
        vector<Button::TButton *>::iterator mapIter;
12494
 
12495
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
12496
        {
12497
            Button::TButton *bt = *mapIter;
12498
            bt->listViewRefresh(interval, force);
12499
        }
12500
    }
12501
}
12502
 
12503
void TPageManager::doLVS(int port, vector<int> &channels, vector<string> &pars)
12504
{
12505
    DECL_TRACER("TPageManager::doLVS(int port, vector<int> &channels, vector<string> &pars)");
12506
 
12507
    TError::clear();
12508
    vector<string> sortColumns;
12509
    Button::LIST_SORT sort = Button::LIST_SORT_NONE;
12510
    string override;
12511
 
12512
    if (pars.size() > 0)
12513
    {
12514
        vector<string>::iterator iter;
12515
 
12516
        for (iter = pars.begin(); iter != pars.end(); ++iter)
12517
        {
12518
            if (iter->find(";") == string::npos)
12519
                sortColumns.push_back(*iter);
12520
            else
12521
            {
12522
                vector<string> parts = StrSplit(*iter, ";");
12523
                sortColumns.push_back(parts[0]);
12524
 
12525
                if (parts[1].find("a") != string::npos || parts[1].find("A") != string::npos)
12526
                    sort = Button::LIST_SORT_ASC;
12527
                else if (parts[1].find("d") != string::npos || parts[1].find("D") != string::npos)
12528
                    sort = Button::LIST_SORT_DESC;
12529
                else if (parts[1].find("*") != string::npos)
12530
                {
12531
                    if (parts.size() > 2 && !parts[2].empty())
12532
                    {
12533
                        override = parts[2];
12534
                        sort = Button::LIST_SORT_OVERRIDE;
12535
                    }
12536
                }
12537
                else if (parts[1].find("n") != string::npos || parts[1].find("N") != string::npos)
12538
                    sort = Button::LIST_SORT_NONE;
12539
            }
12540
        }
12541
    }
12542
 
12543
    vector<TMap::MAP_T> map = findButtons(port, channels);
12544
 
12545
    if (TError::isError() || map.empty())
12546
        return;
12547
 
12548
    vector<Button::TButton *> buttons = collectButtons(map);
12549
 
12550
    if (buttons.size() > 0)
12551
    {
12552
        vector<Button::TButton *>::iterator mapIter;
12553
 
12554
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
12555
        {
12556
            Button::TButton *bt = *mapIter;
12557
            bt->listViewSortData(sortColumns, sort, override);
12558
        }
12559
    }
12560
}
12561
 
134 andreas 12562
void TPageManager::doTPCCMD(int, vector<int>&, vector<string>& pars)
12563
{
12564
    DECL_TRACER("TPageManager::doTPCCMD(int, vector<int>&, vector<string>& pars)");
12565
 
12566
    if (pars.size() < 1)
12567
    {
12568
        MSG_ERROR("Too few arguments for TPCCMD!");
12569
        return;
12570
    }
12571
 
12572
    string cmd = pars[0];
12573
 
12574
    if (strCaseCompare(cmd, "LocalHost") == 0)
12575
    {
12576
        if (pars.size() < 2 || pars[1].empty())
12577
        {
12578
            MSG_ERROR("The command \"LocalHost\" requires an additional parameter!");
12579
            return;
12580
        }
12581
 
12582
        TConfig::saveController(pars[1]);
12583
    }
12584
    else if (strCaseCompare(cmd, "LocalPort") == 0)
12585
    {
12586
        if (pars.size() < 2 || pars[1].empty())
12587
        {
12588
            MSG_ERROR("The command \"LocalPort\" requires an additional parameter!");
12589
            return;
12590
        }
12591
 
12592
        int port = atoi(pars[1].c_str());
12593
 
12594
        if (port > 0 && port < 65536)
12595
            TConfig::savePort(port);
12596
        else
12597
        {
12598
            MSG_ERROR("Invalid network port " << port);
12599
        }
12600
    }
12601
    else if (strCaseCompare(cmd, "DeviceID") == 0)
12602
    {
12603
        if (pars.size() < 2 || pars[1].empty())
12604
        {
12605
            MSG_ERROR("The command \"DeviceID\" requires an additional parameter!");
12606
            return;
12607
        }
12608
 
12609
        int id = atoi(pars[1].c_str());
12610
 
12611
        if (id >= 10000 && id < 30000)
12612
            TConfig::setSystemChannel(id);
12613
    }
12614
    else if (strCaseCompare(cmd, "ApplyProfile") == 0)
12615
    {
12616
        // We restart the network connection only
12617
        if (gAmxNet)
12618
            gAmxNet->reconnect();
12619
    }
12620
    else if (strCaseCompare(cmd, "QueryDeviceInfo") == 0)
12621
    {
12622
        string info = "DEVICEINFO-TPANELID," + TConfig::getPanelType();
12623
        info += ";HOSTNAME,";
12624
        char hostname[HOST_NAME_MAX];
12625
 
12626
        if (gethostname(hostname, HOST_NAME_MAX) != 0)
12627
        {
12628
            MSG_ERROR("Can't get host name: " << strerror(errno));
12629
            return;
12630
        }
12631
 
12632
        info.append(hostname);
12633
        info += ";UUID," + TConfig::getUUID();
12634
        sendGlobalString(info);
12635
    }
12636
    else if (strCaseCompare(cmd, "LockRotation") == 0)
12637
    {
12638
        if (pars.size() < 2 || pars[1].empty())
12639
        {
12640
            MSG_ERROR("The command \"LockRotation\" requires an additional parameter!");
12641
            return;
12642
        }
12643
 
12644
        if (strCaseCompare(pars[1], "true") == 0)
12645
            TConfig::setRotationFixed(true);
12646
        else
12647
            TConfig::setRotationFixed(false);
12648
    }
12649
    else if (strCaseCompare(cmd, "ButtonHit") == 0)
12650
    {
12651
        if (pars.size() < 2 || pars[1].empty())
12652
        {
12653
            MSG_ERROR("The command \"ButtonHit\" requires an additional parameter!");
12654
            return;
12655
        }
12656
 
12657
        if (strCaseCompare(pars[1], "true") == 0)
12658
            TConfig::saveSystemSoundState(true);
12659
        else
12660
            TConfig::saveSystemSoundState(false);
12661
    }
12662
    else if (strCaseCompare(cmd, "ReprocessTP4") == 0)
12663
    {
12664
        if (_resetSurface)
12665
            _resetSurface();
12666
    }
12667
}
12668
 
12669
void TPageManager::doTPCACC(int, vector<int>&, vector<string>& pars)
12670
{
12671
    DECL_TRACER("TPageManager::doTPCACC(int, vector<int>&, vector<string>& pars)");
12672
 
12673
    if (pars.size() < 1)
12674
    {
12675
        MSG_ERROR("Too few arguments for TPCACC!");
12676
        return;
12677
    }
12678
 
12679
    string cmd = pars[0];
12680
 
12681
    if (strCaseCompare(cmd, "ENABLE") == 0)
12682
    {
12683
        mInformOrientation = true;
12684
        sendOrientation();
12685
    }
12686
    else if (strCaseCompare(cmd, "DISABLE") == 0)
12687
    {
12688
        mInformOrientation = false;
12689
    }
12690
    else if (strCaseCompare(cmd, "QUERY") == 0)
12691
    {
12692
        sendOrientation();
12693
    }
12694
}
153 andreas 12695
 
279 andreas 12696
#ifndef _NOSIP_
153 andreas 12697
void TPageManager::doTPCSIP(int, vector<int>&, vector<string>& pars)
12698
{
12699
    DECL_TRACER("TPageManager::doTPCSIP(int port, vector<int>& channels, vector<string>& pars)");
12700
 
12701
    if (pars.empty())
12702
        return;
12703
 
12704
    string cmd = toUpper(pars[0]);
12705
 
12706
    if (cmd == "SHOW" && _showPhoneDialog)
12707
        _showPhoneDialog(true);
12708
    else if (!_showPhoneDialog)
12709
    {
12710
        MSG_ERROR("There is no phone dialog registered!");
12711
    }
12712
}
279 andreas 12713
#endif