Subversion Repositories tpanel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 andreas 1
/*
269 andreas 2
 * Copyright (C) 2020 to 2023 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.
103 andreas 1005
//    REG_CMD(doGDV, "^GDV");     // 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.
64 andreas 1066
    REG_CMD(doSetup, "SETUP");  // Send panel to SETUP page.
104 andreas 1067
    REG_CMD(doSetup, "^STP");   // G5: Open setup page.
64 andreas 1068
    REG_CMD(doShutdown, "SHUTDOWN");// Shut down the App
82 andreas 1069
    REG_CMD(doSOU, "@SOU");     // Play a sound file.
104 andreas 1070
    REG_CMD(doSOU, "^SOU");     // G5: Play a sound file.
326 andreas 1071
    REG_CMD(doMUT, "^MUT");     // G5: Panel Volume Mute
63 andreas 1072
    REG_CMD(doTKP, "@TKP");     // Present a telephone keypad.
104 andreas 1073
    REG_CMD(doTKP, "^TKP");     // G5: Bring up a telephone keypad.
63 andreas 1074
    REG_CMD(doTKP, "@VKB");     // Present a virtual keyboard
104 andreas 1075
    REG_CMD(doTKP, "^VKB");     // G5: Bring up a virtual keyboard.
129 andreas 1076
#ifndef _NOSIP_
103 andreas 1077
    // Here the SIP commands will take place
123 andreas 1078
    REG_CMD(doPHN, "^PHN");     // SIP commands
127 andreas 1079
    REG_CMD(getPHN, "?PHN");    // SIP state commands
129 andreas 1080
#endif
300 andreas 1081
    // SubView commands
1082
//    REG_CMD(doEPR, "^EPR");     // Execute Push on Release.
1083
//    REG_CMD(doSCE, "^SCE");     // Configures subpage custom events.
1084
//    REG_CMD(doSDR, "^SDR");     // Enabling subpage dynamic reordering.
318 andreas 1085
    REG_CMD(doSHA, "^SHA");     // Subpage Hide All Command
1086
    REG_CMD(doSHD, "^SHD");     // Hides subpage
1087
    REG_CMD(doSPD, "^SPD");     //  Set the padding between subpages on a subpage viewer button
300 andreas 1088
    REG_CMD(doSSH, "^SSH");     // Subpage show command.
318 andreas 1089
    REG_CMD(doSTG, "^STG");     // Subpage toggle command
300 andreas 1090
 
225 andreas 1091
    // ListView commands (G5)
1092
    REG_CMD(doLVD, "^LVD");     // G5: Set Listview Data Source
230 andreas 1093
    REG_CMD(doLVE, "^LVE");     // G5: Set ListView custom event number
227 andreas 1094
    REG_CMD(doLVF, "^LVF");     // G5: Listview Filter
230 andreas 1095
    REG_CMD(doLVL, "^LVL");     // G5: ListView layout
233 andreas 1096
    REG_CMD(doLVM, "^LVM");     // G5: ListView map fields
1097
    REG_CMD(doLVN, "^LVN");     // G5: ListView navigate
1098
    REG_CMD(doLVR, "^LVR");     // G5: ListView refresh data
1099
    REG_CMD(doLVS, "^LVS");     // G5: ListView sort data
225 andreas 1100
 
103 andreas 1101
    // State commands
14 andreas 1102
    REG_CMD(doON, "ON");
1103
    REG_CMD(doOFF, "OFF");
15 andreas 1104
    REG_CMD(doLEVEL, "LEVEL");
1105
    REG_CMD(doBLINK, "BLINK");
127 andreas 1106
    REG_CMD(doVER, "^VER?");    // Return version string to master
279 andreas 1107
#ifndef _NOSIP_
127 andreas 1108
    REG_CMD(doWCN, "^WCN?");    // Return SIP phone number
279 andreas 1109
#endif
134 andreas 1110
    // TPControl commands
1111
    REG_CMD(doTPCCMD, "TPCCMD");    // Profile related options
1112
    REG_CMD(doTPCACC, "TPCACC");    // Device orientation
279 andreas 1113
#ifndef _NOSIP_
153 andreas 1114
    REG_CMD(doTPCSIP, "TPCSIP");    // Show the built in SIP phone
279 andreas 1115
#endif
134 andreas 1116
    // Virtual internal commands
26 andreas 1117
    REG_CMD(doFTR, "#FTR");     // File transfer (virtual internal command)
23 andreas 1118
 
123 andreas 1119
    // At least we must add the SIP client
129 andreas 1120
#ifndef _NOSIP_
127 andreas 1121
    mSIPClient = new TSIPClient;
123 andreas 1122
 
1123
    if (TError::isError())
1124
    {
1125
        MSG_ERROR("Error initializing the SIP client!");
1126
        TConfig::setSIPstatus(false);
1127
    }
129 andreas 1128
#endif
88 andreas 1129
    TError::clear();
299 andreas 1130
    runClickQueue();
303 andreas 1131
    runUpdateSubViewItem();
3 andreas 1132
}
1133
 
1134
TPageManager::~TPageManager()
1135
{
1136
    DECL_TRACER("TPageManager::~TPageManager()");
129 andreas 1137
#ifndef _NOSIP_
127 andreas 1138
    if (mSIPClient)
1139
    {
1140
        delete mSIPClient;
1141
        mSIPClient = nullptr;
1142
    }
129 andreas 1143
#endif
3 andreas 1144
    PCHAIN_T *p = mPchain;
1145
    PCHAIN_T *next = nullptr;
37 andreas 1146
#ifdef __ANDROID__
36 andreas 1147
    stopNetworkState();
37 andreas 1148
#endif
3 andreas 1149
    try
1150
    {
1151
        while (p)
1152
        {
1153
            next = p->next;
1154
 
1155
            if (p->page)
1156
                delete p->page;
1157
 
1158
            delete p;
1159
            p = next;
1160
        }
1161
 
1162
        SPCHAIN_T *sp = mSPchain;
1163
        SPCHAIN_T *snext = nullptr;
1164
 
1165
        while (sp)
1166
        {
1167
            snext = sp->next;
1168
 
1169
            if (sp->page)
1170
                delete sp->page;
1171
 
1172
            delete sp;
5 andreas 1173
            sp = snext;
3 andreas 1174
        }
1175
 
1176
        mPchain = nullptr;
1177
        mSPchain = nullptr;
14 andreas 1178
        setPChain(mPchain);
1179
        setSPChain(mSPchain);
3 andreas 1180
 
13 andreas 1181
        if (mAmxNet)
1182
        {
1183
            delete mAmxNet;
1184
            mAmxNet = nullptr;
1185
        }
1186
 
3 andreas 1187
        if (mTSettings)
1188
        {
1189
            delete mTSettings;
1190
            mTSettings = nullptr;
1191
        }
1192
 
1193
        if (mPageList)
1194
        {
1195
            delete mPageList;
1196
            mPageList = nullptr;
1197
        }
5 andreas 1198
 
1199
        if (mPalette)
1200
        {
1201
            delete mPalette;
1202
            mPalette = nullptr;
1203
        }
7 andreas 1204
 
1205
        if (mFonts)
1206
        {
1207
            delete mFonts;
1208
            mFonts = nullptr;
1209
        }
8 andreas 1210
 
1211
        if (gIcons)
1212
        {
1213
            delete gIcons;
1214
            gIcons = nullptr;
1215
        }
1216
 
1217
        if (gPrjResources)
1218
        {
1219
            delete gPrjResources;
1220
            gPrjResources = nullptr;
1221
        }
40 andreas 1222
 
33 andreas 1223
        if (mExternal)
1224
        {
1225
            delete mExternal;
1226
            mExternal = nullptr;
1227
        }
3 andreas 1228
    }
1229
    catch (std::exception& e)
1230
    {
1231
        MSG_ERROR("Memory error: " << e.what());
1232
    }
90 andreas 1233
 
1234
    gPageManager = nullptr;
3 andreas 1235
}
1236
 
11 andreas 1237
void TPageManager::initialize()
1238
{
1239
    DECL_TRACER("TPageManager::initialize()");
1240
 
14 andreas 1241
    surface_mutex.lock();
11 andreas 1242
    dropAllSubPages();
1243
    dropAllPages();
1244
 
186 andreas 1245
    string projectPath = TConfig::getProjectPath();
1246
 
1247
    if (!fs::exists(projectPath + "/prj.xma"))
1248
        projectPath += "/__system";
1249
 
90 andreas 1250
    if (mAmxNet && mAmxNet->isConnected())
1251
        mAmxNet->close();
88 andreas 1252
 
11 andreas 1253
    if (mTSettings)
1254
        mTSettings->loadSettings();
1255
    else
186 andreas 1256
        mTSettings = new TSettings(projectPath);
11 andreas 1257
 
1258
    if (TError::isError())
14 andreas 1259
    {
1260
        surface_mutex.unlock();
11 andreas 1261
        return;
14 andreas 1262
    }
11 andreas 1263
 
178 andreas 1264
    // Set the panel type from the project information
1265
    TConfig::savePanelType(mTSettings->getPanelType());
1266
 
88 andreas 1267
    if (gPrjResources)
1268
        delete gPrjResources;
11 andreas 1269
 
88 andreas 1270
    gPrjResources = new TPrjResources(mTSettings->getResourcesList());
11 andreas 1271
 
88 andreas 1272
    if (mPalette)
1273
        delete mPalette;
1274
 
1275
    mPalette = new TPalette();
1276
 
11 andreas 1277
    vector<PALETTE_SETUP> pal = mTSettings->getSettings().palettes;
1278
 
83 andreas 1279
    if (pal.size() > 0)
1280
    {
1281
        vector<PALETTE_SETUP>::iterator iterPal;
11 andreas 1282
 
118 andreas 1283
        for (iterPal = pal.begin(); iterPal != pal.end(); ++iterPal)
83 andreas 1284
            mPalette->initialize(iterPal->file);
1285
    }
1286
 
11 andreas 1287
    if (!TError::isError())
1288
        TColor::setPalette(mPalette);
1289
 
88 andreas 1290
    if (mFonts)
1291
        delete mFonts;
11 andreas 1292
 
88 andreas 1293
    mFonts = new TFont();
1294
 
11 andreas 1295
    if (TError::isError())
1296
    {
1297
        MSG_ERROR("Initializing fonts was not successfull!");
14 andreas 1298
        surface_mutex.unlock();
11 andreas 1299
        return;
1300
    }
1301
 
88 andreas 1302
    if (gIcons)
1303
        delete gIcons;
11 andreas 1304
 
88 andreas 1305
    gIcons = new TIcons();
1306
 
11 andreas 1307
    if (TError::isError())
1308
    {
1309
        MSG_ERROR("Initializing icons was not successfull!");
14 andreas 1310
        surface_mutex.unlock();
11 andreas 1311
        return;
1312
    }
1313
 
88 andreas 1314
    if (mPageList)
1315
        delete mPageList;
11 andreas 1316
 
88 andreas 1317
    mPageList = new TPageList();
11 andreas 1318
 
88 andreas 1319
    if (mExternal)
1320
        delete mExternal;
1321
 
1322
    mExternal = new TExternal();
1323
 
11 andreas 1324
    PAGELIST_T page;
1325
 
1326
    if (!mTSettings->getSettings().powerUpPage.empty())
1327
    {
88 andreas 1328
        if (readPage(mTSettings->getSettings().powerUpPage))
14 andreas 1329
        {
88 andreas 1330
            MSG_TRACE("Found power up page " << mTSettings->getSettings().powerUpPage);
1331
            page = findPage(mTSettings->getSettings().powerUpPage);
1332
            mActualPage = page.pageID;
14 andreas 1333
        }
11 andreas 1334
    }
1335
 
1336
    TPage *pg = getPage(mActualPage);
1337
 
1338
    vector<string> popups = mTSettings->getSettings().powerUpPopup;
1339
 
83 andreas 1340
    if (popups.size() > 0)
11 andreas 1341
    {
83 andreas 1342
        vector<string>::iterator iter;
1343
 
118 andreas 1344
        for (iter = popups.begin(); iter != popups.end(); ++iter)
14 andreas 1345
        {
88 andreas 1346
            if (readSubPage(*iter))
83 andreas 1347
            {
88 andreas 1348
                MSG_TRACE("Found power up popup " << *iter);
11 andreas 1349
 
88 andreas 1350
                if (pg)
1351
                {
1352
                    TSubPage *spage = getSubPage(*iter);
350 andreas 1353
                    spage->setParent(pg->getHandle());
88 andreas 1354
                    pg->addSubPage(spage);
1355
                }
83 andreas 1356
            }
11 andreas 1357
        }
1358
    }
1359
 
88 andreas 1360
    // Here we initialize the system resources like borders, cursors, sliders, ...
1361
    if (mSystemDraw)
1362
        delete mSystemDraw;
1363
 
1364
    mSystemDraw = new TSystemDraw(TConfig::getSystemPath(TConfig::BASE));
1365
 
1366
    TError::clear();        // Clear all errors who may be occured until here
1367
 
11 andreas 1368
    // Start the thread
92 andreas 1369
    startComm();
1370
 
1371
    surface_mutex.unlock();
1372
}
1373
 
1374
bool TPageManager::startComm()
1375
{
1376
    DECL_TRACER("TPageManager::startComm()");
1377
 
1378
    if (mAmxNet && mAmxNet->isNetRun())
1379
        return true;
1380
 
1381
    try
11 andreas 1382
    {
92 andreas 1383
        if (!mAmxNet)
13 andreas 1384
        {
92 andreas 1385
            if (_netRunning)
13 andreas 1386
            {
92 andreas 1387
                // Wait until previous connection thread ended
1388
                while (_netRunning)
1389
                    std::this_thread::sleep_for(std::chrono::milliseconds(100));
13 andreas 1390
            }
14 andreas 1391
 
92 andreas 1392
            mAmxNet = new amx::TAmxNet();
1393
            mAmxNet->setCallback(bind(&TPageManager::doCommand, this, std::placeholders::_1));
1394
            mAmxNet->setPanelID(TConfig::getChannel());
134 andreas 1395
            mAmxNet->setSerialNum(V_SERIAL);
13 andreas 1396
        }
90 andreas 1397
 
1398
        if (!mAmxNet->isNetRun())
1399
            mAmxNet->Run();
85 andreas 1400
    }
92 andreas 1401
    catch (std::exception& e)
1402
    {
1403
        MSG_ERROR("Error starting the AmxNet thread: " << e.what());
1404
        return false;
1405
    }
14 andreas 1406
 
92 andreas 1407
    return true;
11 andreas 1408
}
1409
 
38 andreas 1410
void TPageManager::startUp()
1411
{
1412
    DECL_TRACER("TPageManager::startUp()");
1413
 
44 andreas 1414
    if (mAmxNet)
90 andreas 1415
    {
1416
        MSG_WARNING("Communication with controller already initialized!");
44 andreas 1417
        return;
90 andreas 1418
    }
44 andreas 1419
 
92 andreas 1420
    if (!startComm())
1421
        return;
90 andreas 1422
 
38 andreas 1423
#ifdef __ANDROID__
130 andreas 1424
    initOrientation();
38 andreas 1425
    initNetworkState();
1426
#endif
1427
}
89 andreas 1428
 
1429
void TPageManager::reset()
1430
{
1431
    DECL_TRACER("TPageManager::reset()");
1432
 
100 andreas 1433
    // Freshly initialize everything.
89 andreas 1434
    initialize();
1435
}
1436
 
169 andreas 1437
void TPageManager::runCommands()
1438
{
1439
    DECL_TRACER("TPageManager::runCommands()");
1440
 
1441
    if (mBusy || cmdLoop_busy)
1442
        return;
1443
 
1444
    try
1445
    {
1446
        mThreadCommand = std::thread([=] { this->commandLoop(); });
1447
        mThreadCommand.detach();
1448
    }
1449
    catch (std::exception& e)
1450
    {
1451
        MSG_ERROR("Error starting thread for command loop: " << e.what());
1452
        _netRunning = false;
1453
    }
1454
}
1455
 
197 andreas 1456
void TPageManager::showSetup()
1457
{
1458
    DECL_TRACER("TPageManager::showSetup()");
251 andreas 1459
#ifdef Q_OS_ANDROID
260 andreas 1460
    // Scan Netlinx for TP4 files and update the list of setup.
1461
    if (TConfig::getController().compare("0.0.0.0") != 0)
1462
    {
1463
        if (_startWait)
1464
            _startWait(string("Please wait while I try to load the list of surface files from Netlinx (") + TConfig::getController() + ")");
1465
 
1466
        TTPInit tpinit;
1467
        std::vector<TTPInit::FILELIST_t> fileList;
1468
        tpinit.setPath(TConfig::getProjectPath());
1469
        fileList = tpinit.getFileList(".tp4");
1470
 
1471
        if (fileList.size() > 0)
1472
        {
1473
            vector<TTPInit::FILELIST_t>::iterator iter;
264 andreas 1474
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
260 andreas 1475
            QAndroidJniObject::callStaticMethod<void>("org/qtproject/theosys/Settings", "clearSurfaces");
1476
#else
1477
            QJniObject::callStaticMethod<void>("org/qtproject/theosys/Settings", "clearSurfaces");
1478
#endif
1479
            for (iter = fileList.begin(); iter != fileList.end(); ++iter)
1480
            {
264 andreas 1481
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
260 andreas 1482
                QAndroidJniObject str = QAndroidJniObject::fromString(iter->fname.c_str());
1483
                QAndroidJniObject::callStaticMethod<void>("org/qtproject/theosys/Settings", "addSurface", "(Ljava/lang/String;)V", str.object<jstring>());
1484
#else
1485
                QJniObject str = QJniObject::fromString(iter->fname.c_str());
1486
                QJniObject::callStaticMethod<void>("org/qtproject/theosys/Settings", "addSurface", "(Ljava/lang/String;)V", str.object<jstring>());
1487
#endif
1488
            }
1489
        }
1490
 
1491
        if (_stopWait)
1492
            _stopWait();
1493
    }
1494
 
367 andreas 1495
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
1496
    QAndroidJniObject::callStaticMethod<void>("org/qtproject/theosys/Settings", "setLogLevel", "(Ljava/lang/Integer;)V", TConfig::getLogLevelBits());
383 andreas 1497
    QAndroidJniObject strPath = QAndroidJniObject::fromString(TConfig::getLogFile().c_str());
385 andreas 1498
    QAndroidJniObject::callStaticMethod<void>("org/qtproject/theosys/Settings", "setLogEnableFile", "(Z)V", TConfig::getLogFileEnabled());
383 andreas 1499
    QAndroidJniObject::callStaticMethod<void>("org/qtproject/theosys/Settings", "setLogPath", "(Ljava/lang/String;)V", strPath.object<jstring>());
406 andreas 1500
 
1501
    QAndroidJniObject pw1 = QAndroidJniObject::fromString(TConfig::getPassword1().c_str());
1502
    QAndroidJniObject pw2 = QAndroidJniObject::fromString(TConfig::getPassword2().c_str());
1503
    QAndroidJniObject pw3 = QAndroidJniObject::fromString(TConfig::getPassword3().c_str());
1504
    QAndroidJniObject pw4 = QAndroidJniObject::fromString(TConfig::getPassword4().c_str());
1505
    QAndroidJniObject::callStaticMethod<void>("org/qtproject/theosys/Settings", "setPassword", "(ILjava/lang/String;)V", 1, pw1.object<jstring>());
1506
    QAndroidJniObject::callStaticMethod<void>("org/qtproject/theosys/Settings", "setPassword", "(ILjava/lang/String;)V", 2, pw2.object<jstring>());
1507
    QAndroidJniObject::callStaticMethod<void>("org/qtproject/theosys/Settings", "setPassword", "(ILjava/lang/String;)V", 3, pw3.object<jstring>());
1508
    QAndroidJniObject::callStaticMethod<void>("org/qtproject/theosys/Settings", "setPassword", "(ILjava/lang/String;)V", 4, pw4.object<jstring>());
367 andreas 1509
#else
1510
    QJniObject::callStaticMethod<void>("org/qtproject/theosys/Settings", "setLogLevel", "(I)V", TConfig::getLogLevelBits());
385 andreas 1511
    QJniObject::callStaticMethod<void>("org/qtproject/theosys/Settings", "setLogEnableFile", "(I)V", (TConfig::getLogFileEnabled() ? 1 : 0));
383 andreas 1512
    QJniObject strPath = QJniObject::fromString(TConfig::getLogFile().c_str());
1513
    QJniObject::callStaticMethod<void>("org/qtproject/theosys/Settings", "setLogPath", "(Ljava/lang/String;)V", strPath.object<jstring>());
397 andreas 1514
 
1515
    QJniObject pw1 = QJniObject::fromString(TConfig::getPassword1().c_str());
1516
    QJniObject pw2 = QJniObject::fromString(TConfig::getPassword2().c_str());
1517
    QJniObject pw3 = QJniObject::fromString(TConfig::getPassword3().c_str());
1518
    QJniObject pw4 = QJniObject::fromString(TConfig::getPassword4().c_str());
1519
    QJniObject::callStaticMethod<void>("org/qtproject/theosys/Settings", "setPassword", "(ILjava/lang/String;)V", 1, pw1.object<jstring>());
1520
    QJniObject::callStaticMethod<void>("org/qtproject/theosys/Settings", "setPassword", "(ILjava/lang/String;)V", 2, pw2.object<jstring>());
1521
    QJniObject::callStaticMethod<void>("org/qtproject/theosys/Settings", "setPassword", "(ILjava/lang/String;)V", 3, pw3.object<jstring>());
1522
    QJniObject::callStaticMethod<void>("org/qtproject/theosys/Settings", "setPassword", "(ILjava/lang/String;)V", 4, pw4.object<jstring>());
367 andreas 1523
#endif
1524
 
255 andreas 1525
    enterSetup();
250 andreas 1526
#else
1527
        if (_callShowSetup)
1528
            _callShowSetup();
1529
#endif
197 andreas 1530
}
1531
 
1532
void TPageManager::hideSetup()
1533
{
1534
    DECL_TRACER("TPageManager::hideSetup()");
1535
 
206 andreas 1536
    if (!mSetupActive || mSavedPage >= SYSTEM_PAGE_START)
197 andreas 1537
        return;
1538
 
198 andreas 1539
    mSetupActive = false;
197 andreas 1540
 
198 andreas 1541
    if (!mSavedPage)
1542
    {
1543
        string sPage = mTSettings->getPowerUpPage();
197 andreas 1544
 
198 andreas 1545
        if (!setPage(sPage, true))
1546
            setPage(1, true);
197 andreas 1547
 
1548
        return;
1549
    }
1550
 
198 andreas 1551
    setPage(mSavedPage, true);
213 andreas 1552
    MSG_PROTOCOL("Activated page: " << mSavedPage);
197 andreas 1553
 
198 andreas 1554
    if (mSavedSubpages.size() > 0)
197 andreas 1555
    {
198 andreas 1556
        vector<int>::iterator iter;
197 andreas 1557
 
198 andreas 1558
        for (iter = mSavedSubpages.begin(); iter != mSavedSubpages.end(); ++iter)
1559
        {
1560
            showSubPage(*iter);
213 andreas 1561
            MSG_PROTOCOL("Activated subpage: " << *iter);
198 andreas 1562
        }
217 andreas 1563
 
1564
        mSavedSubpages.clear();
197 andreas 1565
    }
1566
}
1567
 
205 andreas 1568
int TPageManager::getSelectedRow(ulong handle)
1569
{
1570
    DECL_TRACER("TPageManager::getSelectedRow(ulong handle)");
1571
 
300 andreas 1572
    int nPage = (handle >> 16) & 0x0000ffff;
205 andreas 1573
 
206 andreas 1574
    if ((nPage && TPage::isRegularPage(nPage)) || TPage::isSystemPage(nPage)) // Do we have a page?
205 andreas 1575
    {                                                   // Yes, then look on page
1576
        TPage *pg = getPage(nPage);
1577
 
1578
        if (!pg)
1579
            return -1;
1580
 
1581
        return pg->getSelectedRow(handle);
1582
    }
206 andreas 1583
    else if (TPage::isRegularSubPage(nPage) || TPage::isSystemSubPage(nPage))
205 andreas 1584
    {
1585
        TSubPage *subPg = getSubPage(nPage);
1586
 
1587
        if (!subPg)
1588
            return -1;
1589
 
1590
        return subPg->getSelectedRow(handle);
1591
    }
1592
 
271 andreas 1593
    MSG_WARNING("Invalid handle " << handleToString(handle) << " detected!");
205 andreas 1594
    return -1;
1595
}
1596
 
1597
string TPageManager::getSelectedItem(ulong handle)
1598
{
1599
    DECL_TRACER("TPageManager::getSelectedItem(ulong handle)");
1600
 
300 andreas 1601
    int nPage = (handle >> 16) & 0x0000ffff;
205 andreas 1602
 
206 andreas 1603
    if ((nPage && TPage::isRegularPage(nPage)) || TPage::isSystemPage(nPage)) // Do we have a page?
205 andreas 1604
    {                                                   // Yes, then look on page
1605
        TPage *pg = getPage(nPage);
1606
 
1607
        if (!pg)
1608
            return string();
1609
 
1610
        return pg->getSelectedItem(handle);
1611
    }
206 andreas 1612
    else if (TPage::isRegularSubPage(nPage) || TPage::isSystemSubPage(nPage))
205 andreas 1613
    {
1614
        TSubPage *subPg = getSubPage(nPage);
1615
 
1616
        if (!subPg)
1617
            return string();
1618
 
1619
        return subPg->getSelectedItem(handle);
1620
    }
1621
 
271 andreas 1622
    MSG_WARNING("Invalid handle " << handleToString(handle) << " detected!");
205 andreas 1623
    return string();
1624
}
1625
 
206 andreas 1626
void TPageManager::setSelectedRow(ulong handle, int row, const std::string& text)
205 andreas 1627
{
1628
    DECL_TRACER("TPageManager::setSelectedRow(ulong handle, int row)");
1629
 
300 andreas 1630
    int nPage = (handle >> 16) & 0x0000ffff;
205 andreas 1631
 
206 andreas 1632
    if (TPage::isRegularPage(nPage) || TPage::isSystemPage(nPage)) // Do we have a page?
205 andreas 1633
    {                                                   // Yes, then look on page
1634
        TPage *pg = getPage(nPage);
1635
 
1636
        if (!pg)
1637
            return;
1638
 
1639
        pg->setSelectedRow(handle, row);
1640
    }
206 andreas 1641
    else if (TPage::isRegularSubPage(nPage) || TPage::isSystemSubPage(nPage))   // Do we have a subpage?
1642
    {                                                   // Yes, then look on subpage
205 andreas 1643
        TSubPage *subPg = getSubPage(nPage);
1644
 
1645
        if (!subPg)
1646
            return;
1647
 
1648
        subPg->setSelectedRow(handle, row);
206 andreas 1649
        // Check if this is a system list. If so we must set the selected
1650
        // text to the input line or "label".
1651
        TPage *mainPage = nullptr;
1652
 
1653
        if (nPage >= SYSTEM_SUBPAGE_START)  // System subpage?
1654
        {
1655
            switch(nPage)
1656
            {
1657
                case SYSTEM_SUBPAGE_SYSTEMSOUND:
1658
                case SYSTEM_SUBPAGE_SINGLEBEEP:
1659
                case SYSTEM_SUBPAGE_DOUBLEBEEP:
1660
                    mainPage = getPage(SYSTEM_PAGE_SOUND);
1661
                break;
1662
 
1663
                case SYSTEM_SUBPAGE_SURFACE:
1664
                    mainPage = getPage(SYSTEM_PAGE_CONTROLLER);
1665
                break;
1666
            }
1667
        }
1668
 
1669
        if (mainPage)
1670
        {
1671
            if (nPage == SYSTEM_SUBPAGE_SYSTEMSOUND)  // System sound beep
1672
            {
1673
                Button::TButton *bt = mainPage->getButton(SYSTEM_PAGE_SOUND_TXSYSSOUND);
1674
 
1675
                if (bt)
1676
                {
1677
                    bt->setText(text, -1);
1678
                    TConfig::setTemporary(true);
1679
                    TConfig::saveSystemSoundFile(text);
1680
                }
1681
            }
1682
            else if (nPage == SYSTEM_SUBPAGE_SINGLEBEEP) // System sound single beep
1683
            {
1684
                Button::TButton *bt = mainPage->getButton(SYSTEM_PAGE_SOUND_TXSINGLEBEEP);
1685
 
1686
                if (bt)
1687
                {
1688
                    bt->setText(text, -1);
1689
                    TConfig::setTemporary(true);
1690
                    TConfig::saveSingleBeepFile(text);
1691
                }
1692
            }
1693
            else if (nPage == SYSTEM_SUBPAGE_DOUBLEBEEP) // System sound double beep
1694
            {
1695
                Button::TButton *bt = mainPage->getButton(SYSTEM_PAGE_SOUND_TXDOUBLEBEEP);
1696
 
1697
                if (bt)
1698
                {
1699
                    bt->setText(text, -1);
1700
                    TConfig::setTemporary(true);
1701
                    TConfig::saveDoubleBeepFile(text);
1702
                }
1703
            }
1704
            else if (nPage == SYSTEM_SUBPAGE_SURFACE)   // System TP4 files (surface files)
1705
            {
1706
                Button::TButton *bt = mainPage->getButton(SYSTEM_PAGE_CTRL_SURFACE);
1707
 
1708
                if (bt)
1709
                {
1710
                    MSG_DEBUG("Setting text: " << text);
1711
                    bt->setText(text, -1);
1712
                    TConfig::setTemporary(true);
1713
                    TConfig::saveFtpSurface(text);
1714
                }
1715
            }
1716
 
1717
            // Close the list subpage
1718
            subPg->drop();
1719
        }
205 andreas 1720
    }
1721
}
1722
 
383 andreas 1723
void TPageManager::redrawObject(ulong handle)
1724
{
1725
    DECL_TRACER("TPageManager::redrawObject(ulong handle)");
1726
 
1727
    int pnumber = (int)((handle >> 16) & 0x0000ffff);
1728
    int btnumber = (int)(handle & 0x0000ffff);
1729
 
1730
    if (pnumber < REGULAR_SUBPAGE_START)    // Is it a page?
1731
    {
1732
        TPage *page = getPage(pnumber);
1733
 
1734
        if (!page)
1735
        {
1736
            MSG_WARNING("Page " << pnumber << " not found!");
1737
            return;
1738
        }
1739
 
1740
        if (!page->isVisilble())
1741
            return;
1742
 
1743
        if (btnumber == 0)
1744
        {
1745
            page->show();
1746
            return;
1747
        }
1748
 
1749
        Button::TButton *button = page->getButton(btnumber);
1750
 
1751
        if (!button)
1752
        {
1753
            MSG_WARNING("Button " << btnumber << " on page " << pnumber << " not found!");
1754
            return;
1755
        }
1756
 
1757
        button->showLastButton();
1758
    }
1759
    else if (pnumber >= REGULAR_SUBPAGE_START && pnumber < SYSTEM_PAGE_START)
1760
    {
1761
        TSubPage *spage = getSubPage(pnumber);
1762
 
1763
        if (!spage)
1764
        {
1765
            MSG_WARNING("Subpage " << pnumber << " not found!");
1766
            return;
1767
        }
1768
 
1769
        if (!spage->isVisible())
1770
            return;
1771
 
1772
        if (btnumber == 0)
1773
        {
1774
            spage->show();
1775
            return;
1776
        }
1777
 
1778
        Button::TButton *button = spage->getButton(btnumber);
1779
 
1780
        if (!button)
1781
        {
1782
            MSG_WARNING("Button " << btnumber << " on subpage " << pnumber << " not found!");
1783
            return;
1784
        }
1785
 
1786
        button->showLastButton();
1787
    }
1788
    else
1789
    {
1790
        MSG_WARNING("System pages are not handled by redraw method! Ignoring page " << pnumber << ".");
1791
    }
1792
}
1793
 
198 andreas 1794
#ifdef _SCALE_SKIA_
197 andreas 1795
void TPageManager::setSetupScaleFactor(double scale, double sw, double sh)
1796
{
1797
    DECL_TRACER("TPageManager::setSetupScaleFactor(double scale, double sw, double sh)");
1798
 
1799
    mScaleSystem = scale;
1800
    mScaleSystemWidth = sw;
1801
    mScaleSystemHeight = sh;
1802
}
198 andreas 1803
#endif
197 andreas 1804
 
11 andreas 1805
/*
1806
 * The following method is called by the class TAmxNet whenever an event from
169 andreas 1807
 * the Netlinx occured.
11 andreas 1808
 */
1809
void TPageManager::doCommand(const amx::ANET_COMMAND& cmd)
1810
{
1811
    DECL_TRACER("TPageManager::doCommand(const amx::ANET_COMMAND& cmd)");
1812
 
169 andreas 1813
    if (!cmdLoop_busy)
1814
        runCommands();
1815
 
11 andreas 1816
    mCommands.push_back(cmd);
169 andreas 1817
}
11 andreas 1818
 
169 andreas 1819
void TPageManager::commandLoop()
1820
{
1821
    DECL_TRACER("TPageManager::commandLoop()");
1822
 
1823
    if (mBusy || cmdLoop_busy)
11 andreas 1824
        return;
1825
 
169 andreas 1826
    mBusy = cmdLoop_busy = true;
11 andreas 1827
    string com;
1828
 
169 andreas 1829
    while (cmdLoop_busy && !killed && !_restart_)
11 andreas 1830
    {
169 andreas 1831
        while (mCommands.size() > 0)
11 andreas 1832
        {
169 andreas 1833
            amx::ANET_COMMAND bef = mCommands.at(0);
1834
            mCommands.erase(mCommands.begin());
11 andreas 1835
 
169 andreas 1836
            switch (bef.MC)
1837
            {
1838
                case 0x0006:
1839
                case 0x0018:	// feedback channel on
1840
                    com.assign("ON-");
1841
                    com.append(to_string(bef.data.chan_state.channel));
1842
                    parseCommand(bef.device1, bef.data.chan_state.port, com);
1843
                break;
11 andreas 1844
 
169 andreas 1845
                case 0x0007:
1846
                case 0x0019:	// feedback channel off
1847
                    com.assign("OFF-");
1848
                    com.append(to_string(bef.data.chan_state.channel));
1849
                    parseCommand(bef.device1, bef.data.chan_state.port, com);
1850
                break;
11 andreas 1851
 
169 andreas 1852
                case 0x000a:	// level value change
1853
                    com = "LEVEL-";
1854
                    com += to_string(bef.data.message_value.value);
1855
                    com += ",";
11 andreas 1856
 
169 andreas 1857
                    switch (bef.data.message_value.type)
1858
                    {
1859
                        case 0x10: com += to_string(bef.data.message_value.content.byte); break;
1860
                        case 0x11: com += to_string(bef.data.message_value.content.ch); break;
1861
                        case 0x20: com += to_string(bef.data.message_value.content.integer); break;
1862
                        case 0x21: com += to_string(bef.data.message_value.content.sinteger); break;
1863
                        case 0x40: com += to_string(bef.data.message_value.content.dword); break;
1864
                        case 0x41: com += to_string(bef.data.message_value.content.sdword); break;
1865
                        case 0x4f: com += to_string(bef.data.message_value.content.fvalue); break;
1866
                        case 0x8f: com += to_string(bef.data.message_value.content.dvalue); break;
1867
                    }
11 andreas 1868
 
169 andreas 1869
                    parseCommand(bef.device1, bef.data.message_value.port, com);
1870
                break;
11 andreas 1871
 
169 andreas 1872
                case 0x000c:	// Command string
11 andreas 1873
                {
169 andreas 1874
                    amx::ANET_MSG_STRING msg = bef.data.message_string;
11 andreas 1875
 
169 andreas 1876
                    if (msg.length < strlen((char *)&msg.content))
1877
                    {
1878
                        mCmdBuffer.append((char *)&msg.content);
1879
                        break;
1880
                    }
1881
                    else if (mCmdBuffer.length() > 0)
1882
                    {
1883
                        mCmdBuffer.append((char *)&msg.content);
1884
                        size_t len = (mCmdBuffer.length() >= sizeof(msg.content)) ? (sizeof(msg.content)-1) : mCmdBuffer.length();
1885
                        strncpy((char *)&msg.content, mCmdBuffer.c_str(), len);
1886
                        msg.content[len] = 0;
1887
                    }
104 andreas 1888
 
169 andreas 1889
                    if (getCommand((char *)msg.content) == "^UTF")  // This is already UTF8!
1890
                        com.assign((char *)msg.content);
1891
                    else
1892
                        com.assign(cp1250ToUTF8((char *)&msg.content));
11 andreas 1893
 
169 andreas 1894
                    parseCommand(bef.device1, msg.port, com);
1895
                    mCmdBuffer.clear();
1896
                }
1897
                break;
15 andreas 1898
 
169 andreas 1899
                case 0x0502:    // Blink message (contains date and time)
1900
                    com = "BLINK-" + to_string(bef.data.blinkMessage.hour) + ":";
1901
                    com += to_string(bef.data.blinkMessage.minute) + ":";
1902
                    com += to_string(bef.data.blinkMessage.second) + ",";
1903
                    com += to_string(bef.data.blinkMessage.year) + "-";
1904
                    com += to_string(bef.data.blinkMessage.month) + "-";
1905
                    com += to_string(bef.data.blinkMessage.day) + ",";
1906
                    com += to_string(bef.data.blinkMessage.weekday) + ",";
1907
                    com += ((bef.data.blinkMessage.LED & 0x0001) ? "ON" : "OFF");
1908
                    parseCommand(0, 0, com);
1909
                break;
11 andreas 1910
 
169 andreas 1911
                case 0x1000:	// Filetransfer
11 andreas 1912
                {
169 andreas 1913
                    amx::ANET_FILETRANSFER ftr = bef.data.filetransfer;
1914
 
1915
                    if (ftr.ftype == 0)
11 andreas 1916
                    {
169 andreas 1917
                        switch(ftr.function)
1918
                        {
1919
                            case 0x0100:	// Syncing directory
1920
                                com = "#FTR-SYNC:0:";
1921
                                com.append((char*)&ftr.data[0]);
1922
                                parseCommand(bef.device1, bef.port1, com);
1923
                            break;
11 andreas 1924
 
169 andreas 1925
                            case 0x0104:	// Delete file
1926
                                com = "#FTR-SYNC:"+to_string(bef.count)+":Deleting files ... ("+to_string(bef.count)+"%)";
1927
                                parseCommand(bef.device1, bef.port1, com);
1928
                            break;
11 andreas 1929
 
169 andreas 1930
                            case 0x0105:	// start filetransfer
1931
                                com = "#FTR-START";
1932
                                parseCommand(bef.device1, bef.port1, com);
1933
                            break;
1934
                        }
11 andreas 1935
                    }
169 andreas 1936
                    else
11 andreas 1937
                    {
169 andreas 1938
                        switch(ftr.function)
1939
                        {
1940
                            case 0x0003:	// Received part of file
1941
                            case 0x0004:	// End of file
1942
                                com = "#FTR-FTRPART:"+to_string(bef.count)+":"+to_string(ftr.info1);
1943
                                parseCommand(bef.device1, bef.port1, com);
1944
                            break;
11 andreas 1945
 
169 andreas 1946
                            case 0x0007:	// End of file transfer
1947
                            {
1948
                                com = "#FTR-END";
1949
                                parseCommand(bef.device1, bef.port1, com);
1950
                            }
1951
                            break;
1952
 
1953
                            case 0x0102:	// Receiving file
1954
                                com = "#FTR-FTRSTART:"+to_string(bef.count)+":"+to_string(ftr.info1)+":";
1955
                                com.append((char*)&ftr.data[0]);
1956
                                parseCommand(bef.device1, bef.port1, com);
1957
                            break;
11 andreas 1958
                        }
1959
                    }
1960
                }
169 andreas 1961
                break;
11 andreas 1962
            }
1963
        }
169 andreas 1964
 
1965
        std::this_thread::sleep_for(std::chrono::milliseconds(50));
11 andreas 1966
    }
1967
 
1968
    mBusy = false;
169 andreas 1969
    cmdLoop_busy = false;
11 andreas 1970
}
1971
 
26 andreas 1972
void TPageManager::deployCallbacks()
1973
{
1974
    DECL_TRACER("TPageManager::deployCallbacks()");
1975
 
1976
    PCHAIN_T *p = mPchain;
1977
 
1978
    while (p)
1979
    {
1980
        if (p->page)
1981
        {
1982
            if (_setBackground)
1983
                p->page->registerCallback(_setBackground);
1984
 
1985
            if (_callPlayVideo)
1986
                p->page->regCallPlayVideo(_callPlayVideo);
1987
        }
1988
 
1989
        p = p->next;
1990
    }
1991
 
1992
    SPCHAIN_T *sp = mSPchain;
1993
 
1994
    while (sp)
1995
    {
1996
        if (sp->page)
1997
        {
1998
            if (_setBackground)
1999
                sp->page->registerCallback(_setBackground);
2000
 
2001
            if (_callPlayVideo)
2002
                sp->page->regCallPlayVideo(_callPlayVideo);
2003
        }
2004
 
2005
        sp = sp->next;
2006
    }
2007
}
36 andreas 2008
 
2009
void TPageManager::regCallbackNetState(std::function<void (int)> callNetState, ulong handle)
2010
{
2011
    DECL_TRACER("TPageManager::regCallbackNetState(std::function<void (int)> callNetState, ulong handle)");
2012
 
2013
    if (handle == 0)
2014
        return;
2015
 
2016
    mNetCalls.insert(std::pair<int, std::function<void (int)> >(handle, callNetState));
2017
}
2018
 
2019
void TPageManager::unregCallbackNetState(ulong handle)
2020
{
2021
    DECL_TRACER("TPageManager::unregCallbackNetState(ulong handle)");
2022
 
83 andreas 2023
    if (mNetCalls.size() == 0)
2024
        return;
2025
 
300 andreas 2026
    std::map<int, std::function<void (int)> >::iterator iter = mNetCalls.find((int)handle);
36 andreas 2027
 
2028
    if (iter != mNetCalls.end())
2029
        mNetCalls.erase(iter);
2030
}
247 andreas 2031
#if defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
251 andreas 2032
#ifdef Q_OS_ANDROID
38 andreas 2033
void TPageManager::regCallbackBatteryState(std::function<void (int, bool, int)> callBatteryState, ulong handle)
2034
{
2035
    DECL_TRACER("TPageManager::regCallbackBatteryState(std::function<void (int, bool, int)> callBatteryState, ulong handle)");
2036
 
2037
    if (handle == 0)
2038
        return;
2039
 
2040
    mBatteryCalls.insert(std::pair<int, std::function<void (int, bool, int)> >(handle, callBatteryState));
2041
}
247 andreas 2042
#endif
2043
#ifdef Q_OS_IOS
2044
void TPageManager::regCallbackBatteryState(std::function<void (int, int)> callBatteryState, ulong handle)
2045
{
2046
    DECL_TRACER("TPageManager::regCallbackBatteryState(std::function<void (int, int)> callBatteryState, ulong handle)");
38 andreas 2047
 
247 andreas 2048
    if (handle == 0)
2049
        return;
2050
 
2051
    mBatteryCalls.insert(std::pair<int, std::function<void (int, int)> >(handle, callBatteryState));
264 andreas 2052
#ifdef Q_OS_IOS
2053
    mLastBatteryLevel = TIOSBattery::getBatteryLeft();
2054
    mLastBatteryState = TIOSBattery::getBatteryState();
247 andreas 2055
 
264 andreas 2056
#endif
247 andreas 2057
    if (mLastBatteryLevel > 0 || mLastBatteryState > 0)
2058
        informBatteryStatus(mLastBatteryLevel, mLastBatteryState);
2059
}
2060
#endif
38 andreas 2061
void TPageManager::unregCallbackBatteryState(ulong handle)
2062
{
2063
    DECL_TRACER("TPageManager::unregCallbackBatteryState(ulong handle)");
2064
 
83 andreas 2065
    if (mBatteryCalls.size() == 0)
2066
        return;
247 andreas 2067
#ifdef Q_OS_ANDROID
38 andreas 2068
    std::map<int, std::function<void (int, bool, int)> >::iterator iter = mBatteryCalls.find(handle);
247 andreas 2069
#endif
2070
#ifdef Q_OS_IOS
300 andreas 2071
    std::map<int, std::function<void (int, int)> >::iterator iter = mBatteryCalls.find((int)handle);
247 andreas 2072
#endif
38 andreas 2073
    if (iter != mBatteryCalls.end())
2074
        mBatteryCalls.erase(iter);
2075
}
247 andreas 2076
#endif  // defined(Q_OS_ANDROID) || defined(Q_OS_IOS)
11 andreas 2077
/*
2078
 * The following function must be called to start the "panel".
2079
 */
5 andreas 2080
bool TPageManager::run()
2081
{
2082
    DECL_TRACER("TPageManager::run()");
2083
 
2084
    if (mActualPage <= 0)
2085
        return false;
2086
 
154 andreas 2087
    TPage *pg = getPage(mActualPage);
2088
 
2089
    if (!pg || !_setPage || !mTSettings)
2090
        return false;
2091
 
14 andreas 2092
    surface_mutex.lock();
7 andreas 2093
    pg->setFonts(mFonts);
5 andreas 2094
    pg->registerCallback(_setBackground);
21 andreas 2095
    pg->regCallPlayVideo(_callPlayVideo);
5 andreas 2096
 
26 andreas 2097
    int width, height;
217 andreas 2098
    width = mTSettings->getWidth();
26 andreas 2099
    height = mTSettings->getHeight();
43 andreas 2100
#ifdef _SCALE_SKIA_
26 andreas 2101
    if (mScaleFactor != 1.0)
2102
    {
2103
        width = (int)((double)width * mScaleFactor);
2104
        height = (int)((double)height * mScaleFactor);
2105
    }
43 andreas 2106
#endif
26 andreas 2107
    _setPage((pg->getNumber() << 16) & 0xffff0000, width, height);
5 andreas 2108
    pg->show();
2109
 
2110
    TSubPage *subPg = pg->getFirstSubPage();
2111
 
2112
    while (subPg)
2113
    {
7 andreas 2114
        subPg->setFonts(mFonts);
2115
        subPg->registerCallback(_setBackground);
2116
        subPg->registerCallbackDB(_displayButton);
11 andreas 2117
        subPg->regCallDropSubPage(_callDropSubPage);
21 andreas 2118
        subPg->regCallPlayVideo(_callPlayVideo);
7 andreas 2119
 
5 andreas 2120
        if (_setSubPage)
6 andreas 2121
        {
2122
            MSG_DEBUG("Drawing page " << subPg->getNumber() << ": " << subPg->getName() << "...");
26 andreas 2123
            width = subPg->getWidth();
2124
            height = subPg->getHeight();
2125
            int left = subPg->getLeft();
2126
            int top = subPg->getTop();
43 andreas 2127
#ifdef _SCALE_SKIA_
26 andreas 2128
            if (mScaleFactor != 1.0)
2129
            {
2130
                width = (int)((double)width * mScaleFactor);
2131
                height = (int)((double)height * mScaleFactor);
2132
                left = (int)((double)left * mScaleFactor);
2133
                top = (int)((double)top * mScaleFactor);
2134
            }
43 andreas 2135
#endif
41 andreas 2136
            ANIMATION_t ani;
2137
            ani.showEffect = subPg->getShowEffect();
2138
            ani.showTime = subPg->getShowTime();
42 andreas 2139
            ani.hideEffect = subPg->getHideEffect();
2140
            ani.hideTime = subPg->getHideTime();
162 andreas 2141
 
2142
            subPg->setZOrder(pg->getNextZOrder());
217 andreas 2143
            _setSubPage(subPg->getHandle(), pg->getHandle(), left, top, width, height, ani);
6 andreas 2144
            subPg->show();
2145
        }
5 andreas 2146
 
2147
        subPg = pg->getNextSubPage();
2148
    }
2149
 
14 andreas 2150
    surface_mutex.unlock();
5 andreas 2151
    return true;
2152
}
2153
 
4 andreas 2154
TPage *TPageManager::getPage(int pageID)
2155
{
2156
    DECL_TRACER("TPageManager::getPage(int pageID)");
2157
 
209 andreas 2158
    if (pageID <= 0)
2159
        return nullptr;
2160
 
4 andreas 2161
    PCHAIN_T *p = mPchain;
2162
 
2163
    while (p)
2164
    {
349 andreas 2165
        if (p->page && p->page->getNumber() == pageID)
4 andreas 2166
            return p->page;
2167
 
2168
        p = p->next;
2169
    }
2170
 
2171
    return nullptr;
2172
}
2173
 
2174
TPage *TPageManager::getPage(const string& name)
2175
{
2176
    DECL_TRACER("TPageManager::getPage(const string& name)");
2177
 
349 andreas 2178
    if (name.empty())
2179
        return nullptr;
2180
 
4 andreas 2181
    PCHAIN_T *p = mPchain;
2182
 
2183
    while (p)
2184
    {
349 andreas 2185
        if (p->page && p->page->getName().compare(name) == 0)
4 andreas 2186
            return p->page;
2187
 
2188
        p = p->next;
2189
    }
2190
 
2191
    return nullptr;
2192
}
2193
 
209 andreas 2194
TPage *TPageManager::loadPage(PAGELIST_T& pl, bool *refresh)
15 andreas 2195
{
209 andreas 2196
    DECL_TRACER("TPageManager::loadPage(PAGELIST_T& pl, bool *refresh)");
15 andreas 2197
 
209 andreas 2198
    if (refresh)
2199
        *refresh = false;
2200
 
15 andreas 2201
    if (!pl.isValid)
2202
        return nullptr;
2203
 
2204
    TPage *pg = getPage(pl.pageID);
2205
 
2206
    if (!pg)
2207
    {
2208
        if (!readPage(pl.pageID))
2209
            return nullptr;
2210
 
2211
        pg = getPage(pl.pageID);
2212
 
2213
        if (!pg)
2214
        {
2215
            MSG_ERROR("Error loading page " << pl.pageID << ", " << pl.name << " from file " << pl.file << "!");
2216
            return nullptr;
2217
        }
209 andreas 2218
 
2219
        if (refresh)
213 andreas 2220
            *refresh = true;        // Indicate that the page was freshly loaded
15 andreas 2221
    }
2222
 
2223
    return pg;
2224
}
2225
 
209 andreas 2226
void TPageManager::reloadSystemPage(TPage *page)
2227
{
2228
    DECL_TRACER("TPageManager::reloadSystemPage(TPage *page)");
2229
 
2230
    if (!page)
2231
        return;
2232
 
2233
    vector<Button::TButton *> buttons = page->getAllButtons();
2234
    vector<Button::TButton *>::iterator iter;
210 andreas 2235
    TConfig::setTemporary(false);
209 andreas 2236
 
2237
    for (iter = buttons.begin(); iter != buttons.end(); ++iter)
2238
    {
2239
        Button::TButton *bt = *iter;
2240
 
2241
        if (bt->getAddressPort() == 0 && bt->getAddressChannel() > 0)
2242
        {
2243
            switch(bt->getAddressChannel())
2244
            {
2245
                case SYSTEM_ITEM_LOGLOGFILE:        bt->setTextOnly(TConfig::getLogFile(), -1); break;
2246
 
2247
                case SYSTEM_ITEM_NETLINX_IP:        bt->setTextOnly(TConfig::getController(), -1); break;
2248
                case SYSTEM_ITEM_NETLINX_PORT:      bt->setTextOnly(std::to_string(TConfig::getPort()), -1); break;
2249
                case SYSTEM_ITEM_NETLINX_CHANNEL:   bt->setTextOnly(std::to_string(TConfig::getChannel()), -1); break;
2250
                case SYSTEM_ITEM_NETLINX_PTYPE:     bt->setTextOnly(TConfig::getPanelType(), -1); break;
2251
                case SYSTEM_ITEM_FTPUSER:           bt->setTextOnly(TConfig::getFtpUser(), -1); break;
2252
                case SYSTEM_ITEM_FTPPASSWORD:       bt->setTextOnly(TConfig::getFtpPassword(), -1); break;
2253
                case SYSTEM_ITEM_FTPSURFACE:        bt->setTextOnly(TConfig::getFtpSurface(), -1); break;
210 andreas 2254
 
2255
                case SYSTEM_ITEM_SIPPROXY:          bt->setTextOnly(TConfig::getSIPproxy(), -1); break;
2256
                case SYSTEM_ITEM_SIPPORT:           bt->setTextOnly(std::to_string(TConfig::getSIPport()), -1); break;
2257
                case SYSTEM_ITEM_SIPSTUN:           bt->setTextOnly(TConfig::getSIPstun(), -1); break;
2258
                case SYSTEM_ITEM_SIPDOMAIN:         bt->setTextOnly(TConfig::getSIPdomain(), -1); break;
2259
                case SYSTEM_ITEM_SIPUSER:           bt->setTextOnly(TConfig::getSIPuser(), -1); break;
2260
                case SYSTEM_ITEM_SIPPASSWORD:       bt->setTextOnly(TConfig::getSIPpassword(), -1); break;
2261
 
2262
                case SYSTEM_ITEM_SYSTEMSOUND:       bt->setTextOnly(TConfig::getSystemSound(), -1); break;
2263
                case SYSTEM_ITEM_SINGLEBEEP:        bt->setTextOnly(TConfig::getSingleBeepSound(), -1); break;
2264
                case SYSTEM_ITEM_DOUBLEBEEP:        bt->setTextOnly(TConfig::getDoubleBeepSound(), -1); break;
209 andreas 2265
            }
2266
        }
210 andreas 2267
        else if (bt->getChannelPort() == 0 && bt->getChannelNumber() > 0)
2268
        {
2269
            switch(bt->getChannelNumber())
2270
            {
2271
                case SYSTEM_ITEM_DEBUGINFO:         bt->setActiveInstance(IS_LOG_INFO() ? 1 : 0); break;
2272
                case SYSTEM_ITEM_DEBUGWARNING:      bt->setActiveInstance(IS_LOG_WARNING() ? 1 : 0); break;
2273
                case SYSTEM_ITEM_DEBUGERROR:        bt->setActiveInstance(IS_LOG_ERROR() ? 1 : 0); break;
2274
                case SYSTEM_ITEM_DEBUGTRACE:        bt->setActiveInstance(IS_LOG_TRACE() ? 1 : 0); break;
2275
                case SYSTEM_ITEM_DEBUGDEBUG:        bt->setActiveInstance(IS_LOG_DEBUG() ? 1 : 0); break;
2276
                case SYSTEM_ITEM_DEBUGPROTOCOL:     bt->setActiveInstance(IS_LOG_PROTOCOL() ? 1 : 0); break;
2277
                case SYSTEM_ITEM_DEBUGALL:          bt->setActiveInstance(IS_LOG_ALL() ? 1 : 0); break;
2278
                case SYSTEM_ITEM_DEBUGLONG:         bt->setActiveInstance(TConfig::isLongFormat() ? 1 : 0); break;
2279
                case SYSTEM_ITEM_DEBUGPROFILE:      bt->setActiveInstance(TConfig::getProfiling() ? 1 : 0); break;
2280
 
2281
                case SYSTEM_ITEM_FTPPASSIVE:        bt->setActiveInstance(TConfig::getFtpPassive() ? 1 : 0); break;
2282
 
2283
                case SYSTEM_ITEM_SIPIPV4:           bt->setActiveInstance(TConfig::getSIPnetworkIPv4() ? 1 : 0); break;
2284
                case SYSTEM_ITEM_SIPIPV6:           bt->setActiveInstance(TConfig::getSIPnetworkIPv6() ? 1 : 0); break;
2285
                case SYSTEM_ITEM_SIPENABLE:         bt->setActiveInstance(TConfig::getSIPstatus() ? 1 : 0); break;
2286
                case SYSTEM_ITEM_SIPIPHONE:         bt->setActiveInstance(TConfig::getSIPiphone() ? 1 : 0); break;
2287
 
2288
                case SYSTEM_ITEM_SOUNDSWITCH:       bt->setActiveInstance(TConfig::getSystemSoundState() ? 1 : 0); break;
2289
 
2290
                case SYSTEM_ITEM_VIEWSCALEFIT:      bt->setActiveInstance(TConfig::getScale() ? 1 : 0); break;
2291
                case SYSTEM_ITEM_VIEWBANNER:        bt->setActiveInstance(TConfig::showBanner() ? 1 : 0); break;
2292
                case SYSTEM_ITEM_VIEWNOTOOLBAR:     bt->setActiveInstance(TConfig::getToolbarSuppress() ? 1 : 0); break;
2293
                case SYSTEM_ITEM_VIEWTOOLBAR:       bt->setActiveInstance(TConfig::getToolbarForce() ? 1 : 0); break;
2294
                case SYSTEM_ITEM_VIEWROTATE:        bt->setActiveInstance(TConfig::getRotationFixed() ? 1 : 0); break;
2295
            }
2296
        }
2297
        else if (bt->getLevelPort() == 0 && bt->getLevelValue() > 0)
2298
        {
2299
            switch(bt->getLevelValue())
2300
            {
2301
                case SYSTEM_ITEM_SYSVOLUME:         bt->drawBargraph(0, TConfig::getSystemVolume(), false); break;
2302
                case SYSTEM_ITEM_SYSGAIN:           bt->drawBargraph(0, TConfig::getSystemGain(), false); break;
2303
            }
2304
        }
209 andreas 2305
    }
2306
}
2307
 
198 andreas 2308
bool TPageManager::setPage(int PageID, bool forget)
15 andreas 2309
{
198 andreas 2310
    DECL_TRACER("TPageManager::setPage(int PageID, bool forget)");
15 andreas 2311
 
295 andreas 2312
    return _setPageDo(PageID, "", forget);
15 andreas 2313
}
2314
 
168 andreas 2315
bool TPageManager::setPage(const string& name, bool forget)
15 andreas 2316
{
190 andreas 2317
    DECL_TRACER("TPageManager::setPage(const string& name, bool forget)");
15 andreas 2318
 
295 andreas 2319
    return _setPageDo(0, name, forget);
15 andreas 2320
}
2321
 
295 andreas 2322
bool TPageManager::_setPageDo(int pageID, const string& name, bool forget)
2323
{
2324
    DECL_TRACER("TPageManager::_setPageDo(int pageID, const string& name, bool forget)");
2325
 
2326
    TPage *pg = nullptr;
2327
 
2328
    if (pageID > 0 && mActualPage == pageID)
343 andreas 2329
    {
2330
#if TESTMODE == 1
2331
        __success = true;
2332
        setScreenDone();
2333
#endif
295 andreas 2334
        return true;
343 andreas 2335
    }
295 andreas 2336
    else if (!name.empty())
2337
    {
2338
        pg = getPage(mActualPage);
2339
 
2340
        if (pg && pg->getName().compare(name) == 0)
343 andreas 2341
        {
2342
#if TESTMODE == 1
2343
            __success = true;
2344
            setScreenDone();
2345
#endif
295 andreas 2346
            return true;
343 andreas 2347
        }
295 andreas 2348
    }
2349
    else if (pageID > 0)
2350
        pg = getPage(mActualPage);
2351
    else
343 andreas 2352
    {
2353
#if TESTMODE == 1
2354
        setScreenDone();
2355
#endif
295 andreas 2356
        return false;
343 andreas 2357
    }
295 andreas 2358
 
2359
    // FIXME: Make this a vector array to hold a larger history!
2360
    if (!forget)
2361
        mPreviousPage = mActualPage;    // Necessary to be able to jump back to at least the last previous page
2362
 
2363
    if (pg)
2364
        pg->drop();
2365
 
2366
    mActualPage = 0;
2367
    PAGELIST_T listPg;
2368
 
2369
    if (pageID > 0)
2370
        listPg = findPage(pageID);
2371
    else
2372
        listPg = findPage(name);
2373
 
2374
    bool refresh = false;
2375
 
2376
    if ((pg = loadPage(listPg, &refresh)) == nullptr)
343 andreas 2377
    {
2378
#if TESTMODE == 1
2379
        setScreenDone();
2380
#endif
295 andreas 2381
        return false;
343 andreas 2382
    }
295 andreas 2383
 
2384
    mActualPage = pg->getNumber();
2385
 
2386
    if (mActualPage >= SYSTEM_PAGE_START && !refresh)
2387
        reloadSystemPage(pg);
2388
 
2389
    int width = (mActualPage >= SYSTEM_PAGE_START ? mSystemSettings->getWidth() : mTSettings->getWidth());
2390
    int height = (mActualPage >= SYSTEM_PAGE_START ? mSystemSettings->getHeight() : mTSettings->getHeight());
2391
 
2392
    if (_setPage)
2393
        _setPage((mActualPage << 16) & 0xffff0000, width, height);
2394
 
2395
    pg->show();
2396
    return true;
2397
}
2398
 
2399
 
4 andreas 2400
TSubPage *TPageManager::getSubPage(int pageID)
2401
{
2402
    DECL_TRACER("TPageManager::getSubPage(int pageID)");
2403
 
2404
    SPCHAIN_T *p = mSPchain;
2405
 
2406
    while(p)
2407
    {
2408
        if (p->page->getNumber() == pageID)
2409
            return p->page;
2410
 
2411
        p = p->next;
2412
    }
2413
 
2414
    return nullptr;
2415
}
2416
 
2417
TSubPage *TPageManager::getSubPage(const std::string& name)
2418
{
2419
    DECL_TRACER("TPageManager::getSubPage(const std::string& name)");
2420
 
2421
    SPCHAIN_T *p = mSPchain;
2422
 
2423
    while (p)
2424
    {
2425
        if (p->page->getName().compare(name) == 0)
2426
            return p->page;
2427
 
2428
        p = p->next;
2429
    }
2430
 
146 andreas 2431
    MSG_DEBUG("Page " << name << " not found in cache.");
4 andreas 2432
    return nullptr;
2433
}
2434
 
96 andreas 2435
TSubPage *TPageManager::deliverSubPage(const string& name, TPage **pg)
2436
{
198 andreas 2437
    DECL_TRACER("TPageManager::deliverSubPage(const string& name, TPage **pg)");
96 andreas 2438
 
2439
    TPage *page = getActualPage();
2440
 
2441
    if (!page)
2442
    {
2443
        MSG_ERROR("No actual page loaded!");
2444
        return nullptr;
2445
    }
2446
 
2447
    if (pg)
2448
        *pg = page;
2449
 
2450
    TSubPage *subPage = getSubPage(name);
2451
 
2452
    if (!subPage)
2453
    {
2454
        if (!readSubPage(name))
2455
        {
2456
            MSG_ERROR("Error reading subpage " << name);
2457
            return nullptr;
2458
        }
2459
 
2460
        subPage = getSubPage(name);
2461
 
2462
        if (!subPage)
2463
        {
2464
            MSG_ERROR("Fatal: A page with name " << name << " does not exist!");
2465
            return nullptr;
2466
        }
350 andreas 2467
 
2468
        subPage->setParent(page->getHandle());
96 andreas 2469
    }
2470
 
2471
    return subPage;
2472
}
2473
 
198 andreas 2474
TSubPage *TPageManager::deliverSubPage(int number, TPage **pg)
2475
{
2476
    DECL_TRACER("TPageManager::deliverSubPage(int number, TPage **pg)");
2477
 
2478
    TPage *page = getActualPage();
2479
 
2480
    if (!page)
2481
    {
2482
        MSG_ERROR("No actual page loaded!");
2483
        return nullptr;
2484
    }
2485
 
2486
    if (pg)
2487
        *pg = page;
2488
 
2489
    TSubPage *subPage = getSubPage(number);
2490
 
2491
    if (!subPage)
2492
    {
2493
        if (!readSubPage(number))
2494
        {
2495
            MSG_ERROR("Error reading subpage " << number);
2496
            return nullptr;
2497
        }
2498
 
2499
        subPage = getSubPage(number);
2500
 
2501
        if (!subPage)
2502
        {
2503
            MSG_ERROR("Fatal: A page with name " << number << " does not exist!");
2504
            return nullptr;
2505
        }
350 andreas 2506
 
2507
        subPage->setParent(page->getHandle());
198 andreas 2508
    }
2509
 
2510
    return subPage;
2511
}
2512
 
3 andreas 2513
bool TPageManager::readPages()
2514
{
2515
    DECL_TRACER("TPageManager::readPages()");
2516
 
2517
    if (!mPageList)
2518
    {
2519
        MSG_ERROR("Page list is not initialized!");
2520
        TError::setError();
2521
        return false;
2522
    }
2523
 
2524
    // Read all pages
2525
    vector<PAGELIST_T> pageList = mPageList->getPagelist();
2526
 
83 andreas 2527
    if (pageList.size() > 0)
3 andreas 2528
    {
83 andreas 2529
        vector<PAGELIST_T>::iterator pgIter;
14 andreas 2530
 
118 andreas 2531
        for (pgIter = pageList.begin(); pgIter != pageList.end(); ++pgIter)
14 andreas 2532
        {
83 andreas 2533
            TPage *page = new TPage(pgIter->name+".xml");
14 andreas 2534
 
83 andreas 2535
            if (TError::isError())
2536
            {
2537
                delete page;
2538
                return false;
2539
            }
3 andreas 2540
 
83 andreas 2541
            page->setPalette(mPalette);
2542
            page->setFonts(mFonts);
2543
            page->registerCallback(_setBackground);
2544
            page->registerCallbackDB(_displayButton);
2545
            page->regCallPlayVideo(_callPlayVideo);
2546
 
2547
            if (!addPage(page))
2548
                return false;
2549
        }
3 andreas 2550
    }
2551
 
348 andreas 2552
    vector<SUBPAGELIST_T> subPageList = mPageList->getSubPageList();
3 andreas 2553
 
83 andreas 2554
    if (subPageList.size() > 0)
3 andreas 2555
    {
83 andreas 2556
        vector<SUBPAGELIST_T>::iterator spgIter;
14 andreas 2557
 
118 andreas 2558
        for (spgIter = subPageList.begin(); spgIter != subPageList.end(); ++spgIter)
14 andreas 2559
        {
83 andreas 2560
            TSubPage *page = new TSubPage(spgIter->name+".xml");
14 andreas 2561
 
83 andreas 2562
            if (TError::isError())
2563
            {
2564
                delete page;
2565
                return false;
2566
            }
3 andreas 2567
 
83 andreas 2568
            page->setPalette(mPalette);
2569
            page->setFonts(mFonts);
2570
            page->registerCallback(_setBackground);
2571
            page->registerCallbackDB(_displayButton);
2572
            page->regCallDropSubPage(_callDropSubPage);
2573
            page->regCallPlayVideo(_callPlayVideo);
2574
            page->setGroup(spgIter->group);
2575
 
2576
            if (!addSubPage(page))
2577
                return false;
2578
        }
3 andreas 2579
    }
2580
 
2581
    return true;
2582
}
2583
 
2584
bool TPageManager::readPage(const std::string& name)
2585
{
2586
    DECL_TRACER("TPageManager::readPage(const std::string& name)");
2587
 
2588
    PAGELIST_T page = findPage(name);
2589
 
206 andreas 2590
    if ((page.pageID <= 0 || page.pageID >= MAX_PAGE_ID) && page.pageID < SYSTEM_PAGE_START && page.pageID >= SYSTEM_SUBPAGE_START)
3 andreas 2591
    {
2592
        MSG_ERROR("Page " << name << " not found!");
2593
        return false;
2594
    }
2595
 
43 andreas 2596
    TPage *pg;
14 andreas 2597
 
43 andreas 2598
    if (name.compare("_progress") == 0)
2599
        pg = new TPage(name);
2600
    else
2601
        pg = new TPage(page.name+".xml");
2602
 
14 andreas 2603
    if (TError::isError())
2604
    {
2605
        delete pg;
2606
        return false;
2607
    }
2608
 
4 andreas 2609
    pg->setPalette(mPalette);
7 andreas 2610
    pg->setFonts(mFonts);
2611
    pg->registerCallback(_setBackground);
2612
    pg->registerCallbackDB(_displayButton);
21 andreas 2613
    pg->regCallPlayVideo(_callPlayVideo);
3 andreas 2614
 
2615
    if (!addPage(pg))
2616
        return false;
2617
 
2618
    return true;
2619
}
2620
 
2621
bool TPageManager::readPage(int ID)
2622
{
2623
    DECL_TRACER("TPageManager::readPage(int ID)");
2624
 
16 andreas 2625
    TError::clear();
3 andreas 2626
    PAGELIST_T page = findPage(ID);
2627
 
2628
    if (page.pageID <= 0)
2629
    {
2630
        MSG_ERROR("Page with ID " << ID << " not found!");
2631
        return false;
2632
    }
2633
 
43 andreas 2634
    TPage *pg;
14 andreas 2635
 
43 andreas 2636
    if (ID == 300)      // Progress page of system?
2637
        pg = new TPage("_progress");
2638
    else
2639
        pg = new TPage(page.name+".xml");
2640
 
14 andreas 2641
    if (TError::isError())
2642
    {
2643
        delete pg;
2644
        return false;
2645
    }
2646
 
4 andreas 2647
    pg->setPalette(mPalette);
7 andreas 2648
    pg->setFonts(mFonts);
2649
    pg->registerCallback(_setBackground);
2650
    pg->registerCallbackDB(_displayButton);
21 andreas 2651
    pg->regCallPlayVideo(_callPlayVideo);
3 andreas 2652
 
2653
    if (!addPage(pg))
2654
        return false;
2655
 
2656
    return true;
2657
}
2658
 
2659
bool TPageManager::readSubPage(const std::string& name)
2660
{
2661
    DECL_TRACER("TPageManager::readSubPage(const std::string& name)");
2662
 
16 andreas 2663
    TError::clear();
3 andreas 2664
    SUBPAGELIST_T page = findSubPage(name);
2665
 
206 andreas 2666
    if (page.pageID < MAX_PAGE_ID || (page.pageID >= SYSTEM_PAGE_START && page.pageID < SYSTEM_SUBPAGE_START))
3 andreas 2667
    {
2668
        MSG_ERROR("Subpage " << name << " not found!");
2669
        return false;
2670
    }
2671
 
14 andreas 2672
    if (haveSubPage(name))
2673
        return true;
2674
 
3 andreas 2675
    TSubPage *pg = new TSubPage(page.name+".xml");
14 andreas 2676
 
2677
    if (TError::isError())
2678
    {
2679
        delete pg;
2680
        return false;
2681
    }
2682
 
4 andreas 2683
    pg->setPalette(mPalette);
7 andreas 2684
    pg->setFonts(mFonts);
2685
    pg->registerCallback(_setBackground);
2686
    pg->registerCallbackDB(_displayButton);
11 andreas 2687
    pg->regCallDropSubPage(_callDropSubPage);
21 andreas 2688
    pg->regCallPlayVideo(_callPlayVideo);
11 andreas 2689
    pg->setGroup(page.group);
3 andreas 2690
 
2691
    if (!addSubPage(pg))
14 andreas 2692
    {
2693
        delete pg;
3 andreas 2694
        return false;
14 andreas 2695
    }
3 andreas 2696
 
2697
    return true;
2698
}
2699
 
2700
bool TPageManager::readSubPage(int ID)
2701
{
2702
    DECL_TRACER("TPageManager::readSubPage(int ID)");
2703
 
16 andreas 2704
    TError::clear();
3 andreas 2705
    SUBPAGELIST_T page = findSubPage(ID);
2706
 
154 andreas 2707
    if (page.pageID <= MAX_PAGE_ID)
3 andreas 2708
    {
2709
        MSG_ERROR("Subpage with ID " << ID << " not found!");
2710
        return false;
2711
    }
2712
 
2713
    TSubPage *pg = new TSubPage(page.name+".xml");
14 andreas 2714
 
2715
    if (TError::isError())
2716
    {
2717
        delete pg;
2718
        return false;
2719
    }
2720
 
4 andreas 2721
    pg->setPalette(mPalette);
7 andreas 2722
    pg->setFonts(mFonts);
2723
    pg->registerCallback(_setBackground);
2724
    pg->registerCallbackDB(_displayButton);
11 andreas 2725
    pg->regCallDropSubPage(_callDropSubPage);
21 andreas 2726
    pg->regCallPlayVideo(_callPlayVideo);
11 andreas 2727
    pg->setGroup(page.group);
3 andreas 2728
 
2729
    if (!addSubPage(pg))
2730
        return false;
2731
 
2732
    return true;
2733
}
2734
 
279 andreas 2735
vector<TSubPage *> TPageManager::createSubViewList(int id)
2736
{
2737
    DECL_TRACER("TPageManager::createSubViewList(int id)");
2738
 
2739
    vector<TSubPage *> subviews;
2740
 
2741
    if (id <= 0)
2742
        return subviews;
2743
 
2744
    if (!mPageList)
2745
    {
2746
        MSG_WARNING("Missing page list and because of this can't make a subview list!");
2747
        return subviews;
2748
    }
2749
 
2750
    SUBVIEWLIST_T slist = mPageList->findSubViewList(id);
2751
 
2752
    if (slist.id <= 0 || slist.items.empty())
2753
    {
2754
        if (slist.id <= 0)
2755
        {
2756
            MSG_WARNING("Found no subview list with ID " << id);
2757
        }
2758
        else
2759
        {
300 andreas 2760
            MSG_WARNING("Subview list " << id << " has no items!");
279 andreas 2761
        }
2762
 
2763
        return subviews;
2764
    }
2765
 
2766
    vector<SUBVIEWITEM_T>::iterator iter;
2767
 
2768
    for (iter = slist.items.begin(); iter != slist.items.end(); ++iter)
2769
    {
2770
        if (!haveSubPage(iter->pageID))
2771
        {
2772
            if (!readSubPage(iter->pageID))
2773
                return vector<TSubPage *>();
2774
        }
2775
 
284 andreas 2776
        TSubPage *pg = getSubPage(iter->pageID);
279 andreas 2777
 
2778
        if (pg)
2779
            subviews.push_back(pg);
284 andreas 2780
        else
2781
        {
2782
            MSG_DEBUG("No subpage with ID " << id);
2783
        }
279 andreas 2784
    }
2785
 
300 andreas 2786
    MSG_DEBUG("Found " << subviews.size() << " subview items.");
279 andreas 2787
    return subviews;
2788
}
2789
 
280 andreas 2790
void TPageManager::showSubViewList(int id, Button::TButton *bt)
279 andreas 2791
{
280 andreas 2792
    DECL_TRACER("TPageManager::showSubViewList(int id, Button::TButton *bt)");
279 andreas 2793
 
2794
    vector<TSubPage *> subviews = createSubViewList(id);
2795
 
303 andreas 2796
    if (subviews.empty() || !_addViewButtonItems || !bt)
284 andreas 2797
    {
2798
        MSG_DEBUG("Number views: " << subviews.size() << (_addViewButtonItems ? ", addView" : ", NO addView") << (_displayViewButton ? " display" : " NO display"));
279 andreas 2799
        return;
284 andreas 2800
    }
279 andreas 2801
 
293 andreas 2802
    ulong btHandle = bt->getHandle();
2803
    MSG_DEBUG("Working on button " << handleToString(btHandle) << " (" << bt->getName() << ") with " << subviews.size() << " pages.");
289 andreas 2804
    TBitmap bm = bt->getLastBitmap();
2805
    TColor::COLOR_T fillColor = TColor::getAMXColor(bt->getFillColor());
293 andreas 2806
    _displayViewButton(btHandle, bt->getParent(), bt->isSubViewVertical(), bm, bt->getWidth(), bt->getHeight(), bt->getLeftPosition(), bt->getTopPosition(), bt->getSubViewSpace(), fillColor);
280 andreas 2807
 
2808
    vector<PGSUBVIEWITEM_T> items;
2809
    PGSUBVIEWITEM_T svItem;
2810
    PGSUBVIEWATOM_T svAtom;
279 andreas 2811
    vector<TSubPage *>::iterator iter;
2812
 
2813
    for (iter = subviews.begin(); iter != subviews.end(); ++iter)
2814
    {
280 andreas 2815
        TSubPage *sub = *iter;
306 andreas 2816
        sub->setParent(btHandle);
279 andreas 2817
 
289 andreas 2818
        svItem.clear();
2819
        Button::TButton *button = sub->getFirstButton();
2820
        SkBitmap bitmap = sub->getBgImage();
280 andreas 2821
 
2822
        svItem.handle = sub->getHandle();
289 andreas 2823
        svItem.parent = btHandle;
280 andreas 2824
        svItem.width = sub->getWidth();
2825
        svItem.height = sub->getHeight();
281 andreas 2826
        svItem.bgcolor = TColor::getAMXColor(sub->getFillColor());
300 andreas 2827
        svItem.scrollbar = bt->getSubViewScrollbar();
2828
        svItem.scrollbarOffset = bt->getSubViewScrollbarOffset();
2829
        svItem.position = bt->getSubViewAnchor();
302 andreas 2830
        svItem.wrap = bt->getWrapSubViewPages();
280 andreas 2831
 
289 andreas 2832
        if (!bitmap.empty())
2833
            svItem.image.setBitmap((unsigned char *)bitmap.getPixels(), bitmap.info().width(), bitmap.info().height(), bitmap.info().bytesPerPixel());
280 andreas 2834
 
289 andreas 2835
        while (button)
280 andreas 2836
        {
300 andreas 2837
            button->drawButton(0, false, true);
289 andreas 2838
            svAtom.clear();
2839
            svAtom.handle = button->getHandle();
280 andreas 2840
            svAtom.parent = sub->getHandle();
289 andreas 2841
            svAtom.width = button->getWidth();
2842
            svAtom.height = button->getHeight();
2843
            svAtom.left = button->getLeftPosition();
2844
            svAtom.top = button->getTopPosition();
300 andreas 2845
            svAtom.bgcolor = TColor::getAMXColor(button->getFillColor(button->getActiveInstance()));
293 andreas 2846
            svAtom.bounding = button->getBounding();
289 andreas 2847
            Button::BITMAP_t bmap = button->getLastImage();
280 andreas 2848
 
289 andreas 2849
            if (bmap.buffer)
300 andreas 2850
                svAtom.image.setBitmap(bmap.buffer, bmap.width, bmap.height, (int)(bmap.rowBytes / bmap.width));
289 andreas 2851
 
280 andreas 2852
            svItem.atoms.push_back(svAtom);
289 andreas 2853
            button = sub->getNextButton();
280 andreas 2854
        }
2855
 
2856
        items.push_back(svItem);
279 andreas 2857
    }
281 andreas 2858
 
285 andreas 2859
    _addViewButtonItems(bt->getHandle(), items);
284 andreas 2860
 
2861
    if (_pageFinished)
306 andreas 2862
        _pageFinished(bt->getHandle());
279 andreas 2863
}
2864
 
300 andreas 2865
void TPageManager::updateSubViewItem(Button::TButton *bt)
2866
{
2867
    DECL_TRACER("TPageManager::updateSubViewItem(Button::TButton *bt)");
2868
 
303 andreas 2869
    if (!bt)
300 andreas 2870
        return;
2871
 
303 andreas 2872
    updview_mutex.lock();
2873
    mUpdateViews.push_back(bt);
2874
    updview_mutex.unlock();
2875
}
2876
 
2877
void TPageManager::_updateSubViewItem(Button::TButton *bt)
2878
{
2879
    DECL_TRACER("TPageManager::_updateSubViewItem(Button::TButton *bt)");
2880
 
2881
    if (!mPageList || !_updateViewButtonItem)
2882
        return;
2883
 
300 andreas 2884
    // The parent of this kind of button is always the button of type subview.
2885
    // If we take the parent handle and extract the page ID (upper 16 bits)
2886
    // we get the page ID of the subpage or page ID of the page the button is
2887
    // ordered to.
2888
    int pageID = (bt->getParent() >> 16) & 0x0000ffff;
306 andreas 2889
    ulong parent = 0;
300 andreas 2890
    Button::TButton *button = nullptr;
2891
    PGSUBVIEWITEM_T item;
2892
    PGSUBVIEWATOM_T atom;
2893
    SkBitmap bitmap;
2894
    TPage *pg = nullptr;
2895
    TSubPage *sub = nullptr;
2896
 
2897
    if (pageID < REGULAR_SUBPAGE_START)     // Is it a page?
2898
    {
2899
        pg = getPage(pageID);
2900
 
2901
        if (!pg)
2902
        {
2903
            MSG_WARNING("Invalid page " << pageID << "!");
2904
            return;
2905
        }
2906
 
2907
        button = pg->getFirstButton();
2908
        bitmap = pg->getBgImage();
2909
 
2910
        item.handle = pg->getHandle();
2911
        item.parent = bt->getParent();
2912
        item.width = pg->getWidth();
2913
        item.height = pg->getHeight();
2914
        item.bgcolor = TColor::getAMXColor(pg->getFillColor());
2915
    }
2916
    else
2917
    {
2918
        sub = getSubPage(pageID);
2919
 
2920
        if (!sub)
2921
        {
2922
            MSG_WARNING("Couldn't find the subpage " << pageID << "!");
2923
            return;
2924
        }
2925
 
306 andreas 2926
        parent = sub->getParent();
300 andreas 2927
        button = sub->getFirstButton();
2928
        bitmap = sub->getBgImage();
2929
 
2930
        item.handle = sub->getHandle();
2931
        item.parent = bt->getParent();
2932
        item.width = sub->getWidth();
2933
        item.height = sub->getHeight();
303 andreas 2934
        item.position = bt->getSubViewAnchor();
300 andreas 2935
        item.bgcolor = TColor::getAMXColor(sub->getFillColor());
2936
    }
2937
 
2938
 
2939
    if (!bitmap.empty())
2940
        item.image.setBitmap((unsigned char *)bitmap.getPixels(), bitmap.info().width(), bitmap.info().height(), bitmap.info().bytesPerPixel());
2941
 
2942
    while (button)
2943
    {
2944
        atom.clear();
2945
        atom.handle = button->getHandle();
303 andreas 2946
        atom.parent = item.handle;
300 andreas 2947
        atom.width = button->getWidth();
2948
        atom.height = button->getHeight();
2949
        atom.left = button->getLeftPosition();
2950
        atom.top = button->getTopPosition();
2951
        atom.bgcolor = TColor::getAMXColor(button->getFillColor(button->getActiveInstance()));
2952
        atom.bounding = button->getBounding();
2953
        Button::BITMAP_t bmap = button->getLastImage();
2954
 
2955
        if (bmap.buffer)
2956
            atom.image.setBitmap(bmap.buffer, bmap.width, bmap.height, (int)(bmap.rowBytes / bmap.width));
2957
 
2958
        item.atoms.push_back(atom);
2959
        button = (pg ? pg->getNextButton() : sub->getNextButton());
2960
    }
2961
 
306 andreas 2962
    _updateViewButtonItem(item, parent);
300 andreas 2963
}
2964
 
192 andreas 2965
void TPageManager::updateActualPage()
2966
{
2967
    DECL_TRACER("TPageManager::updateActualPage()");
2968
 
2969
    if (!mActualPage)
2970
        return;
2971
 
2972
    TPage *pg = getPage(mActualPage);
2973
    Button::TButton *bt = pg->getFirstButton();
2974
 
2975
    while (bt)
2976
    {
2977
        bt->refresh();
2978
        bt = pg->getNextButton();
2979
    }
2980
}
2981
 
2982
void TPageManager::updateSubpage(int ID)
2983
{
2984
    DECL_TRACER("TPageManager::updateSubpage(int ID)");
2985
 
2986
    TSubPage *pg = getSubPage(ID);
2987
 
2988
    if (!pg)
2989
        return;
2990
 
2991
    vector<Button::TButton *> blist = pg->getAllButtons();
2992
    vector<Button::TButton *>::iterator iter;
2993
 
2994
    if (blist.empty())
2995
        return;
2996
 
2997
    for (iter = blist.begin(); iter != blist.end(); ++iter)
2998
    {
2999
        Button::TButton *bt = *iter;
3000
        bt->refresh();
3001
    }
3002
}
3003
 
3004
void TPageManager::updateSubpage(const std::string &name)
3005
{
3006
    DECL_TRACER("TPageManager::updateSubpage(const std::string &name)");
3007
 
3008
    TSubPage *pg = getSubPage(name);
3009
 
3010
    if (!pg)
3011
        return;
3012
 
3013
    vector<Button::TButton *> blist = pg->getAllButtons();
3014
    vector<Button::TButton *>::iterator iter;
3015
 
3016
    if (blist.empty())
3017
        return;
3018
 
3019
    for (iter = blist.begin(); iter != blist.end(); ++iter)
3020
    {
3021
        Button::TButton *bt = *iter;
3022
        bt->refresh();
3023
    }
3024
}
3025
 
3 andreas 3026
/******************** Internal private methods *********************/
3027
 
3028
PAGELIST_T TPageManager::findPage(const std::string& name)
3029
{
3030
    DECL_TRACER("TPageManager::findPage(const std::string& name)");
3031
 
194 andreas 3032
    vector<PAGELIST_T> pageList;
3 andreas 3033
 
194 andreas 3034
    if (!mSetupActive)
3035
        pageList = mPageList->getPagelist();
3036
    else
3037
        pageList = mPageList->getSystemPagelist();
3038
 
83 andreas 3039
    if (pageList.size() > 0)
3 andreas 3040
    {
83 andreas 3041
        vector<PAGELIST_T>::iterator pgIter;
3042
 
118 andreas 3043
        for (pgIter = pageList.begin(); pgIter != pageList.end(); ++pgIter)
83 andreas 3044
        {
3045
            if (pgIter->name.compare(name) == 0)
3046
                return *pgIter;
3047
        }
3 andreas 3048
    }
3049
 
194 andreas 3050
    MSG_WARNING("Page " << name << " not found!");
3 andreas 3051
    return PAGELIST_T();
3052
}
3053
 
3054
PAGELIST_T TPageManager::findPage(int ID)
3055
{
3056
    DECL_TRACER("TPageManager::findPage(int ID)");
3057
 
206 andreas 3058
    vector<PAGELIST_T> pageList = (ID < SYSTEM_PAGE_START ? mPageList->getPagelist() : mPageList->getSystemPagelist());
3 andreas 3059
 
83 andreas 3060
    if (pageList.size() > 0)
3 andreas 3061
    {
83 andreas 3062
        vector<PAGELIST_T>::iterator pgIter;
3063
 
118 andreas 3064
        for (pgIter = pageList.begin(); pgIter != pageList.end(); ++pgIter)
83 andreas 3065
        {
3066
            if (pgIter->pageID == ID)
3067
                return *pgIter;
3068
        }
3 andreas 3069
    }
3070
 
3071
    return PAGELIST_T();
3072
}
3073
 
3074
SUBPAGELIST_T TPageManager::findSubPage(const std::string& name)
3075
{
3076
    DECL_TRACER("TPageManager::findSubPage(const std::string& name)");
3077
 
348 andreas 3078
    vector<SUBPAGELIST_T> pageList = (mSetupActive ? mPageList->getSystemSupPageList() : mPageList->getSubPageList());
3 andreas 3079
 
83 andreas 3080
    if (pageList.size() > 0)
3 andreas 3081
    {
83 andreas 3082
        vector<SUBPAGELIST_T>::iterator pgIter;
3083
 
118 andreas 3084
        for (pgIter = pageList.begin(); pgIter != pageList.end(); ++pgIter)
83 andreas 3085
        {
3086
            if (pgIter->name.compare(name) == 0)
3087
                return *pgIter;
3088
        }
3 andreas 3089
    }
3090
 
3091
    return SUBPAGELIST_T();
3092
}
3093
 
3094
SUBPAGELIST_T TPageManager::findSubPage(int ID)
3095
{
3096
    DECL_TRACER("TPageManager::findSubPage(int ID)");
3097
 
348 andreas 3098
    vector<SUBPAGELIST_T> pageList = (ID < SYSTEM_PAGE_START ? mPageList->getSubPageList() : mPageList->getSystemSupPageList());
3 andreas 3099
 
83 andreas 3100
    if (pageList.size() > 0)
3 andreas 3101
    {
83 andreas 3102
        vector<SUBPAGELIST_T>::iterator pgIter;
3103
 
118 andreas 3104
        for (pgIter = pageList.begin(); pgIter != pageList.end(); ++pgIter)
83 andreas 3105
        {
3106
            if (pgIter->pageID == ID)
3107
                return *pgIter;
3108
        }
3 andreas 3109
    }
3110
 
3111
    return SUBPAGELIST_T();
3112
}
3113
 
3114
bool TPageManager::addPage(TPage* pg)
3115
{
3116
    DECL_TRACER("TPageManager::addPage(TPage* pg)");
3117
 
3118
    if (!pg)
3119
    {
3120
        MSG_ERROR("Parameter is NULL!");
3121
        TError::setError();
3122
        return false;
3123
    }
3124
 
3125
    PCHAIN_T *chain = new PCHAIN_T;
3126
    chain->page = pg;
5 andreas 3127
    chain->next = nullptr;
3 andreas 3128
 
3129
    if (mPchain)
3130
    {
3131
        PCHAIN_T *p = mPchain;
3132
 
3133
        while (p->next)
3134
            p = p->next;
3135
 
3136
        p->next = chain;
3137
    }
3138
    else
14 andreas 3139
    {
3 andreas 3140
        mPchain = chain;
14 andreas 3141
        setPChain(mPchain);
3142
    }
3 andreas 3143
 
156 andreas 3144
//    MSG_DEBUG("Added page " << chain->page->getName());
3 andreas 3145
    return true;
3146
}
3147
 
3148
bool TPageManager::addSubPage(TSubPage* pg)
3149
{
3150
    DECL_TRACER("TPageManager::addSubPage(TSubPage* pg)");
3151
 
3152
    if (!pg)
3153
    {
3154
        MSG_ERROR("Parameter is NULL!");
3155
        TError::setError();
3156
        return false;
3157
    }
3158
 
14 andreas 3159
    if (haveSubPage(pg->getNumber()))
3160
    {
3161
        MSG_ERROR("Subpage " << pg->getNumber() << ", " << pg->getName() << " is already in chain!");
3162
        return false;
3163
    }
3164
 
3 andreas 3165
    SPCHAIN_T *chain = new SPCHAIN_T;
3166
    chain->page = pg;
5 andreas 3167
    chain->next = nullptr;
3 andreas 3168
 
3169
    if (mSPchain)
3170
    {
3171
        SPCHAIN_T *p = mSPchain;
3172
 
3173
        while (p->next)
3174
            p = p->next;
3175
 
3176
        p->next = chain;
3177
    }
3178
    else
14 andreas 3179
    {
3 andreas 3180
        mSPchain = chain;
14 andreas 3181
        setSPChain(mSPchain);
3182
    }
3 andreas 3183
 
3184
    return true;
3185
}
4 andreas 3186
 
11 andreas 3187
void TPageManager::dropAllPages()
3188
{
3189
    DECL_TRACER("TPageManager::dropAllPages()");
3190
 
3191
    PCHAIN_T *pg = mPchain;
3192
    PCHAIN_T *next = nullptr;
3193
 
3194
    while (pg)
3195
    {
3196
        next = pg->next;
3197
 
3198
        if (pg->page)
3199
        {
3200
            if (_callDropPage)
3201
                _callDropPage((pg->page->getNumber() << 16) & 0xffff0000);
3202
 
3203
            delete pg->page;
3204
        }
3205
 
3206
        delete pg;
3207
        pg = next;
3208
    }
14 andreas 3209
 
3210
    mPchain = nullptr;
3211
    setPChain(mPchain);
11 andreas 3212
}
3213
 
3214
void TPageManager::dropAllSubPages()
3215
{
3216
    DECL_TRACER("TPageManager::dropAllSubPages()");
3217
 
3218
    SPCHAIN_T *spg = mSPchain;
3219
    SPCHAIN_T *next;
3220
 
3221
    while (spg)
3222
    {
3223
        next = spg->next;
3224
 
3225
        if (spg->page)
3226
        {
3227
            if (_callDropSubPage)
350 andreas 3228
                _callDropSubPage((spg->page->getNumber() << 16) & 0xffff0000, spg->page->getParent());
11 andreas 3229
 
3230
            delete spg->page;
3231
        }
3232
 
3233
        delete spg;
3234
        spg = next;
3235
    }
14 andreas 3236
 
3237
    mSPchain = nullptr;
3238
    setSPChain(mSPchain);
11 andreas 3239
}
3240
 
44 andreas 3241
bool TPageManager::destroyAll()
3242
{
3243
    DECL_TRACER("TPageManager::destroyAll()");
3244
 
3245
    dropAllSubPages();
3246
    dropAllPages();
3247
    mActualPage = 0;
3248
    mPreviousPage = 0;
3249
    mActualGroupName.clear();
3250
 
3251
    if (mPageList)
3252
    {
3253
        delete mPageList;
3254
        mPageList = nullptr;
3255
    }
3256
 
3257
    if (mTSettings)
3258
    {
3259
        delete mTSettings;
3260
        mTSettings = nullptr;
3261
    }
3262
 
194 andreas 3263
    if (mSystemSettings)
3264
    {
3265
        delete mSystemSettings;
3266
        mSystemSettings = nullptr;
3267
    }
3268
 
44 andreas 3269
    if (mPalette)
3270
    {
3271
        delete mPalette;
3272
        mPalette = nullptr;
3273
    }
3274
 
3275
    if (mFonts)
3276
    {
3277
        delete mFonts;
3278
        mFonts = nullptr;
3279
    }
3280
 
3281
    if (mExternal)
3282
    {
3283
        delete mExternal;
3284
        mExternal = nullptr;
3285
    }
3286
 
3287
    if (gPrjResources)
3288
    {
3289
        delete gPrjResources;
3290
        gPrjResources = nullptr;
3291
    }
3292
 
3293
    if (gIcons)
3294
    {
3295
        delete gIcons;
3296
        gIcons = nullptr;
3297
    }
3298
 
3299
    if (TError::isError())
3300
        return false;
3301
 
3302
    return true;
3303
}
3304
 
150 andreas 3305
bool TPageManager::overlap(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2)
3306
{
3307
    DECL_TRACER("TPageManager::overlap(int x1, int y1, int w1, int h1, int x2, int y2, int w2, int h2)");
3308
 
3309
    struct point
3310
    {
3311
        int x;
3312
        int y;
3313
    };
3314
 
3315
    struct point l1, r1, l2, r2;
3316
 
3317
    l1.x = x1;
3318
    l1.y = y1;
3319
    r1.x = x1 + w1;
3320
    r1.y = y1 + h1;
3321
 
3322
    l2.x = x2;
3323
    l2.y = y2;
3324
    r2.x = x2 + w2;
3325
    r2.y = y2 + h2;
3326
 
3327
    if (l1.x == r1.x || l1.y == r1.y || l2.x == r2.x || l2.y == r2.y)
3328
    {
3329
        // the line cannot have positive overlap
3330
        return false;
3331
    }
3332
 
183 andreas 3333
    return std::max(l1.x, l2.x) < std::min(r1.x, r2.x) &&
150 andreas 3334
           std::max(l1.y, l2.y) < std::min(r1.y, r2.y);
3335
}
3336
 
51 andreas 3337
Button::TButton *TPageManager::findButton(ulong handle)
3338
{
3339
    DECL_TRACER("TPageManager::findButton(ulong handle)");
3340
 
209 andreas 3341
    if (!handle)
3342
        return nullptr;
3343
 
51 andreas 3344
    TPage *pg = getPage(mActualPage);
3345
 
3346
    if (!pg)
3347
        return nullptr;
3348
 
3349
    vector<Button::TButton *> pgBtList = pg->getAllButtons();
3350
    vector<Button::TButton *>::iterator iter;
83 andreas 3351
 
3352
    if (pgBtList.size() > 0)
51 andreas 3353
    {
83 andreas 3354
        // First we look into the elements of the page
3355
        for (iter = pgBtList.begin(); iter != pgBtList.end(); ++iter)
3356
        {
3357
            Button::TButton *bt = *iter;
51 andreas 3358
 
83 andreas 3359
            if (bt->getHandle() == handle)
3360
                return bt;
3361
        }
51 andreas 3362
    }
3363
 
3364
    // We've not found the wanted element in the elements of the page. So
3365
    // we're looking at the elements of the subpages.
3366
    TSubPage *sp = pg->getFirstSubPage();
3367
 
3368
    if (!sp)
3369
        return nullptr;
3370
 
3371
    while (sp)
3372
    {
3373
        vector<Button::TButton *> spBtList = sp->getAllButtons();
3374
 
83 andreas 3375
        if (spBtList.size() > 0)
51 andreas 3376
        {
83 andreas 3377
            for (iter = spBtList.begin(); iter != spBtList.end(); ++iter)
3378
            {
3379
                Button::TButton *bt = *iter;
51 andreas 3380
 
83 andreas 3381
                if (bt->getHandle() == handle)
3382
                    return bt;
3383
            }
51 andreas 3384
        }
3385
 
3386
        sp = pg->getNextSubPage();
3387
    }
3388
 
3389
    return nullptr;
3390
}
3391
 
4 andreas 3392
TPage *TPageManager::getActualPage()
3393
{
168 andreas 3394
    DECL_TRACER("TPageManager::getActualPage()");
3395
 
4 andreas 3396
    return getPage(mActualPage);
3397
}
3398
 
3399
TSubPage *TPageManager::getFirstSubPage()
3400
{
3401
    DECL_TRACER("TPageManager::getFirstSubPage()");
168 andreas 3402
 
349 andreas 3403
    mLastSubPage = 0;
4 andreas 3404
    TPage *pg = getPage(mActualPage);
3405
 
3406
    if (!pg)
3407
        return nullptr;
3408
 
349 andreas 3409
    map<int, TSubPage *> sp = pg->getSortedSubpages(true);
3410
 
3411
    if (!sp.empty())
3412
    {
3413
        map<int, TSubPage *>::iterator iter = sp.begin();
3414
        mLastSubPage = iter->first;
3415
        return iter->second;
3416
    }
3417
 
3418
    return nullptr;
4 andreas 3419
}
3420
 
3421
TSubPage *TPageManager::getNextSubPage()
3422
{
3423
    DECL_TRACER("TPageManager::getNextSubPage()");
3424
 
3425
    TPage *pg = getPage(mActualPage);
3426
 
3427
    if (pg)
349 andreas 3428
    {
3429
        map<int, TSubPage *> sp = pg->getSortedSubpages();
4 andreas 3430
 
349 andreas 3431
        if (sp.empty())
3432
        {
3433
            mLastSubPage = 0;
3434
            return nullptr;
3435
        }
3436
        else
3437
        {
3438
            map<int, TSubPage *>::iterator iter = sp.find(mLastSubPage);
3439
 
3440
            if (iter != sp.end())
3441
            {
3442
                iter++;
3443
 
3444
                if (iter != sp.end())
3445
                {
3446
                    mLastSubPage = iter->first;
3447
                    return iter->second;
3448
                }
3449
            }
3450
        }
3451
    }
3452
 
3453
    mLastSubPage = 0;
4 andreas 3454
    return nullptr;
3455
}
10 andreas 3456
 
154 andreas 3457
TSubPage *TPageManager::getPrevSubPage()
3458
{
3459
    DECL_TRACER("TPageManager::getPrevSubPage()");
3460
 
3461
    TPage *pg = getPage(mActualPage);
3462
 
3463
    if (pg)
349 andreas 3464
    {
3465
        map<int, TSubPage *> sp = pg->getSortedSubpages();
154 andreas 3466
 
349 andreas 3467
        if (sp.empty())
3468
        {
3469
            mLastSubPage = 0;
3470
            return nullptr;
3471
        }
3472
        else
3473
        {
3474
            map<int, TSubPage *>::iterator iter = sp.find(mLastSubPage);
3475
 
3476
            if (iter != sp.end() && iter != sp.begin())
3477
            {
3478
                iter--;
3479
                mLastSubPage = iter->first;
3480
                return iter->second;
3481
            }
3482
 
3483
            MSG_DEBUG("Page " << mLastSubPage << " not found!");
3484
        }
3485
    }
3486
 
3487
    mLastSubPage = 0;
154 andreas 3488
    return nullptr;
3489
}
3490
 
3491
TSubPage *TPageManager::getLastSubPage()
3492
{
3493
    DECL_TRACER("TPageManager::getLastSubPage()");
3494
 
349 andreas 3495
    mLastSubPage = 0;
154 andreas 3496
    TPage *pg = getPage(mActualPage);
3497
 
3498
    if (pg)
3499
    {
349 andreas 3500
        map<int, TSubPage *> sp = pg->getSortedSubpages(true);
3501
 
3502
        if (sp.empty())
3503
            return nullptr;
3504
        else
3505
        {
3506
            map<int, TSubPage *>::iterator iter = sp.end();
3507
            iter--;
3508
            mLastSubPage = iter->first;
3509
            return iter->second;
3510
        }
154 andreas 3511
    }
3512
    else
3513
    {
3514
        MSG_WARNING("Actual page " << mActualPage << " not found!");
3515
    }
3516
 
3517
    return nullptr;
3518
}
3519
 
11 andreas 3520
TSubPage *TPageManager::getFirstSubPageGroup(const string& group)
3521
{
3522
    DECL_TRACER("TPageManager::getFirstSubPageGroup(const string& group)");
3523
 
14 andreas 3524
    if (group.empty())
3525
    {
3526
        MSG_WARNING("Empty group name is invalid. Ignoring it!");
3527
        mActualGroupName.clear();
3528
        mActualGroupPage = nullptr;
3529
        return nullptr;
3530
    }
3531
 
11 andreas 3532
    mActualGroupName = group;
3533
    TSubPage *pg = getFirstSubPage();
3534
 
3535
    while (pg)
3536
    {
14 andreas 3537
        MSG_DEBUG("Evaluating group " << pg->getGroupName() << " with " << group);
3538
 
11 andreas 3539
        if (pg->getGroupName().compare(group) == 0)
3540
        {
3541
            mActualGroupPage = pg;
3542
            return pg;
3543
        }
3544
 
3545
        pg = getNextSubPage();
3546
    }
3547
 
3548
    mActualGroupName.clear();
3549
    mActualGroupPage = nullptr;
3550
    return nullptr;
3551
}
3552
 
3553
TSubPage *TPageManager::getNextSubPageGroup()
3554
{
3555
    DECL_TRACER("TPageManager::getNextSubPageGroup()");
3556
 
3557
    if (mActualGroupName.empty())
3558
        return nullptr;
3559
 
3560
    TSubPage *pg = getFirstSubPage();
3561
    bool found = false;
3562
 
3563
    while (pg)
3564
    {
14 andreas 3565
        MSG_DEBUG("Evaluating group " << pg->getGroupName() << " with " << mActualGroupName);
3566
 
3567
        if (!found && pg == mActualGroupPage)
11 andreas 3568
        {
3569
            pg = getNextSubPage();
14 andreas 3570
            found = true;
11 andreas 3571
            continue;
3572
        }
3573
 
14 andreas 3574
        if (found && pg->getGroupName().compare(mActualGroupName) == 0)
11 andreas 3575
        {
3576
            mActualGroupPage = pg;
3577
            return pg;
3578
        }
3579
 
3580
        pg = getNextSubPage();
3581
    }
3582
 
3583
    mActualGroupName.clear();
3584
    mActualGroupPage = nullptr;
3585
    return nullptr;
3586
}
3587
 
3588
TSubPage *TPageManager::getNextSubPageGroup(const string& group, TSubPage* pg)
3589
{
3590
    DECL_TRACER("TPageManager::getNextSubPageGroup(const string& group, TSubPage* pg)");
3591
 
3592
    if (group.empty() || !pg)
3593
        return nullptr;
3594
 
3595
    TSubPage *page = getFirstSubPage();
3596
    bool found = false;
3597
 
3598
    while (page)
3599
    {
14 andreas 3600
        MSG_DEBUG("Evaluating group " << pg->getGroupName() << " with " << group);
3601
 
3602
        if (!found && pg == page)
11 andreas 3603
        {
3604
            page = getNextSubPage();
14 andreas 3605
            found = true;
11 andreas 3606
            continue;
3607
        }
3608
 
14 andreas 3609
        if (found && page->getGroupName().compare(group) == 0)
11 andreas 3610
            return page;
3611
 
3612
        page = getNextSubPage();
3613
    }
3614
 
3615
    return nullptr;
3616
}
3617
 
3618
TSubPage *TPageManager::getTopPage()
3619
{
3620
    DECL_TRACER("TPageManager::getTopPage()");
3621
 
3622
    // Scan for all occupied regions
3623
    vector<RECT_T> regions;
3624
 
3625
    TSubPage *pg = getFirstSubPage();
3626
 
3627
    while (pg)
3628
    {
3629
        RECT_T r = pg->getRegion();
3630
        regions.push_back(r);
3631
        pg = getNextSubPage();
3632
    }
3633
 
3634
    // Now scan all pages against all regions to find the top most
3635
    pg = getFirstSubPage();
3636
    TSubPage *top = nullptr;
3637
    int zPos = 0;
3638
 
3639
    while (pg)
3640
    {
3641
        RECT_T r = pg->getRegion();
3642
 
83 andreas 3643
        if (regions.size() > 0)
11 andreas 3644
        {
83 andreas 3645
            vector<RECT_T>::iterator iter;
3646
            int zo = 0;
11 andreas 3647
 
118 andreas 3648
            for (iter = regions.begin(); iter != regions.end(); ++iter)
83 andreas 3649
            {
3650
                if (doOverlap(*iter, r) && zPos > zo)
3651
                    top = pg;
3652
 
3653
                zo++;
3654
            }
11 andreas 3655
        }
3656
 
3657
        pg = getNextSubPage();
3658
        zPos++;
3659
    }
3660
 
3661
    return top;
3662
}
3663
 
3664
TSubPage *TPageManager::getCoordMatch(int x, int y)
3665
{
3666
    DECL_TRACER("TPageManager::getCoordMatch(int x, int y)");
3667
 
26 andreas 3668
    int realX = x;
3669
    int realY = y;
3670
 
11 andreas 3671
    // Reverse order of pages
154 andreas 3672
    TSubPage *pg = getLastSubPage();
11 andreas 3673
 
154 andreas 3674
    // Iterate in reverse order through array
11 andreas 3675
    while (pg)
3676
    {
154 andreas 3677
        if (!pg->isVisible() || pg->getZOrder() == ZORDER_INVALID)
151 andreas 3678
        {
154 andreas 3679
            pg = getPrevSubPage();
3680
            continue;
151 andreas 3681
        }
14 andreas 3682
 
154 andreas 3683
        MSG_DEBUG("Scanning subpage (Z: " << pg->getZOrder() << "): " << pg->getNumber() << ", " << pg->getName());
3684
        RECT_T r = pg->getRegion();
11 andreas 3685
 
154 andreas 3686
        if (r.left <= realX && (r.left + r.width) >= realX &&
3687
            r.top <= realY && (r.top + r.height) >= realY)
11 andreas 3688
        {
154 andreas 3689
            MSG_DEBUG("Click matches subpage " << pg->getNumber() << " (" << pg->getName() << ")");
3690
            return pg;
3691
        }
83 andreas 3692
 
154 andreas 3693
        pg = getPrevSubPage();
11 andreas 3694
    }
3695
 
3696
    return nullptr;
3697
}
3698
 
40 andreas 3699
Button::TButton *TPageManager::getCoordMatchPage(int x, int y)
3700
{
3701
    DECL_TRACER("TPageManager::getCoordMatchPage(int x, int y)");
3702
 
3703
    TPage *page = getActualPage();
3704
 
3705
    if (page)
3706
    {
150 andreas 3707
        Button::TButton *bt = page->getLastButton();
40 andreas 3708
 
3709
        while (bt)
3710
        {
150 andreas 3711
            bool clickable = bt->isClickable();
3712
            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 3713
 
150 andreas 3714
            if (!clickable)
146 andreas 3715
            {
150 andreas 3716
                bt = page->getPreviousButton();
146 andreas 3717
                continue;
3718
            }
3719
 
40 andreas 3720
            if (bt->getLeftPosition() <= x && (bt->getLeftPosition() + bt->getWidth()) >= x &&
3721
                bt->getTopPosition() <= y && (bt->getTopPosition() + bt->getHeight()) >= y)
3722
            {
154 andreas 3723
                if (!bt->isClickable(x - bt->getLeftPosition(), y - bt->getTopPosition()))
3724
                {
3725
                    bt = page->getPreviousButton();
3726
                    continue;
3727
                }
3728
 
40 andreas 3729
                MSG_DEBUG("Click matches button " << bt->getButtonIndex() << " (" << bt->getButtonName() << ")");
3730
                return bt;
3731
            }
3732
 
150 andreas 3733
            bt = page->getPreviousButton();
40 andreas 3734
        }
3735
    }
3736
 
3737
    return nullptr;
3738
}
3739
 
11 andreas 3740
bool TPageManager::doOverlap(RECT_T r1, RECT_T r2)
3741
{
3742
    DECL_TRACER("TPageManager::doOverlap(RECT_T r1, RECT_T r2)");
3743
 
3744
    // If one rectangle is on left side of other
3745
    if (r1.left >= r2.left || r2.left >= r1.left)
3746
        return false;
3747
 
3748
    // If one rectangle is above other
3749
    if (r1.top <= r2.top || r2.top <= r1.top)
3750
        return false;
3751
 
3752
    return true;
3753
}
3754
 
14 andreas 3755
bool TPageManager::havePage(const string& name)
11 andreas 3756
{
14 andreas 3757
    DECL_TRACER("TPageManager::havePage(const string& name)");
11 andreas 3758
 
14 andreas 3759
    if (name.empty())
3760
        return false;
3761
 
3762
    PCHAIN_T *pg = mPchain;
3763
 
3764
    while (pg)
3765
    {
3766
        if (pg->page && pg->page->getName().compare(name) == 0)
3767
            return true;
3768
 
3769
        pg = pg->next;
3770
    }
3771
 
3772
    return false;
3773
}
3774
 
3775
bool TPageManager::haveSubPage(const string& name)
3776
{
3777
    DECL_TRACER("TPageManager::haveSubPage(const string& name)");
3778
 
3779
    if (name.empty())
3780
        return false;
3781
 
11 andreas 3782
    SPCHAIN_T *pg = mSPchain;
3783
 
3784
    while (pg)
3785
    {
14 andreas 3786
        if (pg->page && pg->page->getName().compare(name) == 0)
3787
        {
3788
            MSG_DEBUG("Subpage " << pg->page->getNumber() << ", " << name << " found.");
3789
            return true;
3790
        }
3791
 
3792
        pg = pg->next;
3793
    }
3794
 
3795
    MSG_DEBUG("Subpage " << name << " not found.");
3796
    return false;
3797
}
3798
 
3799
bool TPageManager::haveSubPage(int id)
3800
{
3801
    DECL_TRACER("TPageManager::haveSubPage(int id)");
3802
 
3803
    SPCHAIN_T *pg = mSPchain;
3804
 
3805
    while (pg)
3806
    {
3807
        if (pg->page && pg->page->getNumber() == id)
3808
        {
3809
            MSG_DEBUG("Subpage " << pg->page->getNumber() << ", " << pg->page->getName() << " found.");
3810
            return true;
3811
        }
3812
 
3813
        pg = pg->next;
3814
    }
3815
 
3816
    MSG_DEBUG("Subpage " << id << " not found.");
3817
    return false;
3818
}
3819
 
3820
bool TPageManager::haveSubPage(const string& page, const string& name)
3821
{
3822
    DECL_TRACER("TPageManager::haveSubPage(const string& page, const string& name)");
3823
 
3824
    TPage *pg = getPage(page);
3825
 
3826
    if (!pg)
3827
        return false;
3828
 
3829
    TSubPage *spg = pg->getFirstSubPage();
3830
 
3831
    while (spg)
3832
    {
3833
        if (spg->getName().compare(name) == 0)
3834
        {
3835
            MSG_DEBUG("Subpage " << spg->getNumber() << ", " << name << " found.");
3836
            return true;
3837
        }
3838
 
3839
        spg = pg->getNextSubPage();
3840
    }
3841
 
3842
    MSG_DEBUG("Subpage " << name << " not found on page " << page << ".");
3843
    return false;
3844
}
3845
 
3846
bool TPageManager::haveSubPage(const string& page, int id)
3847
{
3848
    DECL_TRACER("TPageManager::haveSubPage(const string& page, int id)");
3849
 
3850
    TPage *pg = getPage(page);
3851
 
3852
    if (!pg)
3853
        return false;
3854
 
3855
    TSubPage *spg = pg->getFirstSubPage();
3856
 
3857
    while (spg)
3858
    {
3859
        if (spg->getNumber() == id)
3860
        {
3861
            MSG_DEBUG("Subpage " << spg->getNumber() << ", " << spg->getName() << " found.");
3862
            return true;
3863
        }
3864
 
3865
        spg = pg->getNextSubPage();
3866
    }
3867
 
3868
    MSG_DEBUG("Subpage " << id << " on page " << page << " not found.");
3869
    return false;
3870
}
3871
 
3872
void TPageManager::closeGroup(const string& group)
3873
{
3874
    DECL_TRACER("TPageManager::closeGroup(const string& group)");
3875
 
3876
    SPCHAIN_T *pg = mSPchain;
3877
 
3878
    while (pg)
3879
    {
11 andreas 3880
        if (pg->page->getGroupName().compare(group) == 0 && pg->page->isVisible())
3881
        {
3882
            pg->page->regCallDropSubPage(_callDropSubPage);
3883
            pg->page->drop();
3884
            break;
3885
        }
3886
 
3887
        pg = pg->next;
3888
    }
3889
}
3890
 
14 andreas 3891
void TPageManager::showSubPage(const string& name)
3892
{
3893
    DECL_TRACER("TPageManager::showSubPage(const string& name)");
3894
 
3895
    if (name.empty())
349 andreas 3896
    {
3897
#if TESTMODE == 1
3898
        setScreenDone();
3899
#endif
14 andreas 3900
        return;
349 andreas 3901
    }
275 andreas 3902
 
152 andreas 3903
    TPage *page = nullptr;
3904
    TSubPage *pg = deliverSubPage(name, &page);
14 andreas 3905
 
96 andreas 3906
    if (!pg)
349 andreas 3907
    {
3908
#if TESTMODE == 1
3909
        setScreenDone();
3910
#endif
14 andreas 3911
        return;
349 andreas 3912
    }
14 andreas 3913
 
152 andreas 3914
    if (page)
350 andreas 3915
    {
3916
        pg->setParent(page->getHandle());
152 andreas 3917
        page->addSubPage(pg);
350 andreas 3918
    }
152 andreas 3919
 
14 andreas 3920
    string group = pg->getGroupName();
3921
 
3922
    if (!group.empty())
3923
    {
3924
        TSubPage *sub = getFirstSubPageGroup(group);
3925
 
3926
        while(sub)
3927
        {
3928
            if (sub->isVisible() && sub->getNumber() != pg->getNumber())
3929
                sub->drop();
3930
 
3931
            sub = getNextSubPageGroup(group, sub);
3932
        }
3933
    }
3934
 
150 andreas 3935
    if (pg->isVisible())
3936
    {
152 andreas 3937
        MSG_DEBUG("Page " << pg->getName() << " is already visible but maybe not on top.");
150 andreas 3938
 
3939
        TSubPage *sub = getFirstSubPage();
3940
        bool redraw = false;
3941
 
3942
        while (sub)
3943
        {
151 andreas 3944
            if (sub->isVisible() && pg->getZOrder() < sub->getZOrder() &&
3945
                overlap(sub->getLeft(), sub->getTop(), sub->getWidth(), sub->getHeight(),
150 andreas 3946
                pg->getLeft(), pg->getTop(), pg->getWidth(), pg->getHeight()))
3947
            {
3948
                MSG_DEBUG("Page " << sub->getName() << " is overlapping page " << pg->getName());
3949
                redraw = true;
3950
                break;
3951
            }
3952
 
3953
            sub = getNextSubPage();
3954
        }
3955
 
151 andreas 3956
        if (redraw && _toFront)
3957
        {
300 andreas 3958
            _toFront((uint)pg->getHandle());
151 andreas 3959
            pg->setZOrder(page->getNextZOrder());
349 andreas 3960
//            page->sortSubpages();
154 andreas 3961
            MSG_DEBUG("Setting new Z-order " << page->getActZOrder() << " on subpage " << pg->getName());
151 andreas 3962
        }
154 andreas 3963
        else if (redraw && !_toFront)
150 andreas 3964
            pg->drop();
3965
    }
3966
 
14 andreas 3967
    if (!pg->isVisible())
3968
    {
3969
        if (!page)
3970
        {
198 andreas 3971
            page = getPage(mActualPage);
3972
 
3973
            if (!page)
3974
            {
3975
                MSG_ERROR("No active page found! Internal error.");
3976
                return;
3977
            }
14 andreas 3978
        }
3979
 
3980
        if (!haveSubPage(pg->getNumber()) && !page->addSubPage(pg))
3981
            return;
3982
 
3983
        pg->setZOrder(page->getNextZOrder());
3984
 
3985
        if (_setSubPage)
26 andreas 3986
        {
3987
            int left = pg->getLeft();
3988
            int top = pg->getTop();
3989
            int width = pg->getWidth();
3990
            int height = pg->getHeight();
43 andreas 3991
#ifdef _SCALE_SKIA_
26 andreas 3992
            if (mScaleFactor != 1.0)
3993
            {
3994
                left = (int)((double)left * mScaleFactor);
3995
                top = (int)((double)top * mScaleFactor);
3996
                width = (int)((double)width * mScaleFactor);
3997
                height = (int)((double)height * mScaleFactor);
28 andreas 3998
                MSG_DEBUG("Scaled subpage: left=" << left << ", top=" << top << ", width=" << width << ", height=" << height);
26 andreas 3999
            }
43 andreas 4000
#endif
41 andreas 4001
            ANIMATION_t ani;
4002
            ani.showEffect = pg->getShowEffect();
4003
            ani.showTime = pg->getShowTime();
42 andreas 4004
            ani.hideEffect = pg->getHideEffect();
4005
            ani.hideTime = pg->getHideTime();
54 andreas 4006
            // Test for a timer on the page
4007
            if (pg->getTimeout() > 0)
4008
                pg->startTimer();
4009
 
217 andreas 4010
            _setSubPage(pg->getHandle(), page->getHandle(), left, top, width, height, ani);
26 andreas 4011
        }
293 andreas 4012
 
4013
        pg->show();
14 andreas 4014
    }
4015
}
4016
 
198 andreas 4017
void TPageManager::showSubPage(int number, bool force)
4018
{
4019
    DECL_TRACER("TPageManager::showSubPage(int number, bool force)");
4020
 
4021
    if (number <= 0)
4022
        return;
4023
 
4024
    TPage *page = nullptr;
4025
    TSubPage *pg = deliverSubPage(number, &page);
4026
 
4027
    if (!pg)
4028
        return;
4029
 
4030
    if (page)
350 andreas 4031
    {
4032
        pg->setParent(page->getHandle());
198 andreas 4033
        page->addSubPage(pg);
350 andreas 4034
    }
198 andreas 4035
 
4036
    string group = pg->getGroupName();
4037
 
4038
    if (!group.empty())
4039
    {
4040
        TSubPage *sub = getFirstSubPageGroup(group);
4041
 
4042
        while(sub)
4043
        {
4044
            if (sub->isVisible() && sub->getNumber() != pg->getNumber())
4045
                sub->drop();
4046
 
4047
            sub = getNextSubPageGroup(group, sub);
4048
        }
4049
    }
4050
 
4051
    if (pg->isVisible() && !force)
4052
    {
4053
        MSG_DEBUG("Page " << pg->getName() << " is already visible but maybe not on top.");
4054
 
4055
        TSubPage *sub = getFirstSubPage();
4056
        bool redraw = false;
4057
 
4058
        while (sub)
4059
        {
4060
            if (sub->isVisible() && pg->getZOrder() < sub->getZOrder() &&
4061
                overlap(sub->getLeft(), sub->getTop(), sub->getWidth(), sub->getHeight(),
4062
                        pg->getLeft(), pg->getTop(), pg->getWidth(), pg->getHeight()))
4063
            {
4064
                MSG_DEBUG("Page " << sub->getName() << " is overlapping page " << pg->getName());
4065
                redraw = true;
4066
                break;
4067
            }
4068
 
4069
            sub = getNextSubPage();
4070
        }
4071
 
4072
        if (redraw && _toFront)
4073
        {
300 andreas 4074
            _toFront((uint)pg->getHandle());
198 andreas 4075
            pg->setZOrder(page->getNextZOrder());
4076
            page->sortSubpages();
4077
            MSG_DEBUG("Setting new Z-order " << page->getActZOrder() << " on subpage " << pg->getName());
4078
        }
4079
        else if (redraw && !_toFront)
4080
            pg->drop();
4081
    }
4082
 
4083
    if (!pg->isVisible() || force)
4084
    {
4085
        if (!page)
4086
        {
4087
            MSG_ERROR("No active page found! Internal error.");
4088
            return;
4089
        }
4090
 
4091
        if (!haveSubPage(pg->getNumber()) && !page->addSubPage(pg))
4092
            return;
4093
 
4094
        if (!pg->isVisible())
4095
            pg->setZOrder(page->getNextZOrder());
4096
 
4097
        if (_setSubPage)
4098
        {
4099
            int left = pg->getLeft();
4100
            int top = pg->getTop();
4101
            int width = pg->getWidth();
4102
            int height = pg->getHeight();
262 andreas 4103
#ifdef _SCALE_SKIA_
198 andreas 4104
            if (mScaleFactor != 1.0)
4105
            {
4106
                left = (int)((double)left * mScaleFactor);
4107
                top = (int)((double)top * mScaleFactor);
4108
                width = (int)((double)width * mScaleFactor);
4109
                height = (int)((double)height * mScaleFactor);
4110
                MSG_DEBUG("Scaled subpage: left=" << left << ", top=" << top << ", width=" << width << ", height=" << height);
4111
            }
262 andreas 4112
#endif
198 andreas 4113
            ANIMATION_t ani;
4114
            ani.showEffect = pg->getShowEffect();
4115
            ani.showTime = pg->getShowTime();
4116
            ani.hideEffect = pg->getHideEffect();
4117
            ani.hideTime = pg->getHideTime();
4118
            // Test for a timer on the page
4119
            if (pg->getTimeout() > 0)
4120
                pg->startTimer();
4121
 
217 andreas 4122
            _setSubPage(pg->getHandle(), page->getHandle(), left, top, width, height, ani);
198 andreas 4123
        }
4124
    }
4125
 
4126
    pg->show();
4127
}
4128
 
14 andreas 4129
void TPageManager::hideSubPage(const string& name)
4130
{
4131
    DECL_TRACER("TPageManager::hideSubPage(const string& name)");
4132
 
4133
    if (name.empty())
335 andreas 4134
    {
4135
#if TESTMODE == 1
4136
        setScreenDone();
4137
#endif
14 andreas 4138
        return;
335 andreas 4139
    }
14 andreas 4140
 
4141
    TPage *page = getPage(mActualPage);
4142
 
4143
    if (!page)
4144
    {
4145
        MSG_ERROR("No active page found! Internal error.");
335 andreas 4146
#if TESTMODE == 1
4147
        setScreenDone();
4148
#endif
14 andreas 4149
        return;
4150
    }
4151
 
4152
    TSubPage *pg = getSubPage(name);
4153
 
4154
    if (pg)
4155
    {
4156
        pg->drop();
154 andreas 4157
        page->decZOrder();
14 andreas 4158
    }
4159
}
4160
 
299 andreas 4161
/**
4162
 * @brief TPageManager::runClickQueue - Processing mouse clicks
4163
 * The following method is starting a thread which tests a queue containing
4164
 * the mouse clicks. To not drain the CPU, it sleeps for a short time if there
4165
 * are no more events in the queue.
4166
 * If there is an entry in the queue, it copies it to a local struct and
4167
 * deletes it from the queue. It take always the oldest antry (first entry)
4168
 * and removes this entry from the queue until the queue is empty. This makes
4169
 * it to a FIFO (first in, first out).
4170
 * Depending on the state of the variable "coords" the method for mouse
4171
 * coordinate click is executed or the method for a handle.
4172
 * The thread runs as long as the variable "mClickQueueRun" is TRUE and the
4173
 * variable "prg_stopped" is FALSE.
4174
 */
4175
void TPageManager::runClickQueue()
4176
{
4177
    DECL_TRACER("TPageManager::runClickQueue()");
4178
 
4179
    if (mClickQueueRun)
4180
        return;
4181
 
4182
    mClickQueueRun = true;
4183
 
4184
    try
4185
    {
4186
        std::thread thr = std::thread([=] {
300 andreas 4187
            MSG_PROTOCOL("Thread \"TPageManager::runClickQueue()\" was started.");
4188
 
299 andreas 4189
            while (mClickQueueRun && !prg_stopped)
4190
            {
300 andreas 4191
                while (!mClickQueue.empty())
299 andreas 4192
                {
4193
#ifdef QT_DEBUG
300 andreas 4194
                    if (mClickQueue[0].coords)
4195
                        MSG_TRACE("TPageManager::runClickQueue() -- executing: _mouseEvent(" << mClickQueue[0].x << ", " << mClickQueue[0].y << ", " << (mClickQueue[0].pressed ? "TRUE" : "FALSE") << ")")
299 andreas 4196
                    else
300 andreas 4197
                        MSG_TRACE("TPageManager::runClickQueue() -- executing: _mouseEvent(" << handleToString(mClickQueue[0].handle) << ", " << (mClickQueue[0].pressed ? "TRUE" : "FALSE") << ")")
299 andreas 4198
#endif
300 andreas 4199
                    if (mClickQueue[0].coords)
4200
                        _mouseEvent(mClickQueue[0].x, mClickQueue[0].y, mClickQueue[0].pressed);
4201
                    else
4202
                        _mouseEvent(mClickQueue[0].handle, mClickQueue[0].handle);
4203
 
299 andreas 4204
                    mClickQueue.erase(mClickQueue.begin()); // Remove first entry
4205
                }
4206
 
4207
                std::this_thread::sleep_for(std::chrono::microseconds(10));
4208
            }
4209
 
303 andreas 4210
            mClickQueueRun = false;
299 andreas 4211
            return;
4212
        });
4213
 
4214
        thr.detach();
4215
    }
4216
    catch (std::exception& e)
4217
    {
300 andreas 4218
        MSG_ERROR("Error starting a thread to handle the click queue: " << e.what());
299 andreas 4219
        mClickQueueRun = false;
4220
    }
4221
}
4222
 
303 andreas 4223
void TPageManager::runUpdateSubViewItem()
4224
{
4225
    DECL_TRACER("TPageManager::runUpdateSubViewItem()");
299 andreas 4226
 
303 andreas 4227
    if (mUpdateViewsRun)
4228
        return;
4229
 
4230
    mUpdateViewsRun = true;
4231
 
4232
    try
4233
    {
4234
        std::thread thr = std::thread([=] {
4235
            MSG_PROTOCOL("Thread \"TPageManager::runUpdateSubViewItem()\" was started.");
4236
 
4237
            while (mUpdateViewsRun && !prg_stopped)
4238
            {
4239
                while (!mUpdateViews.empty())
4240
                {
4241
                    _updateSubViewItem(mUpdateViews[0]);
4242
                    mUpdateViews.erase(mUpdateViews.begin()); // Remove first entry
4243
                }
4244
 
4245
                std::this_thread::sleep_for(std::chrono::microseconds(10));
4246
            }
4247
 
4248
            mUpdateViewsRun = false;
4249
            return;
4250
        });
4251
 
4252
        thr.detach();
4253
    }
4254
    catch (std::exception& e)
4255
    {
4256
        MSG_ERROR("Error starting a thread to handle the click queue: " << e.what());
4257
        mUpdateViewsRun = false;
4258
    }
4259
}
4260
 
11 andreas 4261
/*
4262
 * Catch the mouse presses and scan all pages and subpages for an element to
4263
 * receive the klick.
4264
 */
10 andreas 4265
void TPageManager::mouseEvent(int x, int y, bool pressed)
4266
{
4267
    DECL_TRACER("TPageManager::mouseEvent(int x, int y, bool pressed)");
4268
 
316 andreas 4269
    TTRYLOCK(click_mutex);
299 andreas 4270
 
4271
    _CLICK_QUEUE_t cq;
4272
    cq.x = x;
4273
    cq.y = y;
4274
    cq.pressed = pressed;
4275
    cq.coords = true;
4276
    mClickQueue.push_back(cq);
334 andreas 4277
#if TESTMODE == 1
4278
    setScreenDone();
4279
#endif
299 andreas 4280
}
4281
 
4282
void TPageManager::_mouseEvent(int x, int y, bool pressed)
4283
{
4284
    DECL_TRACER("TPageManager::_mouseEvent(int x, int y, bool pressed)");
4285
 
16 andreas 4286
    TError::clear();
334 andreas 4287
#if TESTMODE == 1
4288
    if (_gTestMode)
4289
        _gTestMode->setMouseClick(x, y, pressed);
4290
#endif
11 andreas 4291
    int realX = x - mFirstLeftPixel;
4292
    int realY = y - mFirstTopPixel;
263 andreas 4293
 
31 andreas 4294
    MSG_DEBUG("Mouse at " << realX << ", " << realY << ", state " << ((pressed) ? "PRESSED" : "RELEASED") << ", [ " << x << " | " << y << " ]");
43 andreas 4295
#ifdef _SCALE_SKIA_
100 andreas 4296
    if (mScaleFactor != 1.0 && mScaleFactor > 0.0)
26 andreas 4297
    {
4298
        realX = (int)((double)realX / mScaleFactor);
4299
        realY = (int)((double)realY / mScaleFactor);
31 andreas 4300
        MSG_DEBUG("Scaled coordinates: x=" << realX << ", y=" << realY);
26 andreas 4301
    }
43 andreas 4302
#endif
70 andreas 4303
 
154 andreas 4304
    TSubPage *subPage = nullptr;
11 andreas 4305
 
154 andreas 4306
    if (pressed)
4307
        subPage = getCoordMatch(realX, realY);
318 andreas 4308
    else if (mLastPagePush)
154 andreas 4309
        subPage = getSubPage(mLastPagePush);
4310
    else
4311
        subPage = getCoordMatch(realX, realY);
4312
 
11 andreas 4313
    if (!subPage)
14 andreas 4314
    {
146 andreas 4315
        Button::TButton *bt = getCoordMatchPage(realX, realY);
40 andreas 4316
 
4317
        if (bt)
4318
        {
4319
            MSG_DEBUG("Button on page " << bt->getButtonIndex() << ": size: left=" << bt->getLeftPosition() << ", top=" << bt->getTopPosition() << ", width=" << bt->getWidth() << ", height=" << bt->getHeight());
4320
            bt->doClick(x - bt->getLeftPosition(), y - bt->getTopPosition(), pressed);
4321
        }
4322
 
11 andreas 4323
        return;
14 andreas 4324
    }
11 andreas 4325
 
154 andreas 4326
    MSG_DEBUG("Subpage " << subPage->getNumber() << " [" << subPage->getName() << "]: size: left=" << subPage->getLeft() << ", top=" << subPage->getTop() << ", width=" << subPage->getWidth() << ", height=" << subPage->getHeight());
4327
 
4328
    if (pressed)
4329
        mLastPagePush = subPage->getNumber();
4330
    else
4331
        mLastPagePush = 0;
4332
 
11 andreas 4333
    subPage->doClick(realX - subPage->getLeft(), realY - subPage->getTop(), pressed);
10 andreas 4334
}
11 andreas 4335
 
289 andreas 4336
void TPageManager::mouseEvent(ulong handle, bool pressed)
4337
{
4338
    DECL_TRACER("TPageManager::mouseEvent(ulong handle, bool pressed)");
4339
 
320 andreas 4340
    if (!mClickQueue.empty() && mClickQueue.back().handle == handle && mClickQueue.back().pressed == pressed)
4341
        return;
4342
 
299 andreas 4343
    TLOCKER(click_mutex);
293 andreas 4344
 
299 andreas 4345
    _CLICK_QUEUE_t cq;
4346
    cq.handle = handle;
4347
    cq.pressed = pressed;
4348
    mClickQueue.push_back(cq);
4349
    MSG_DEBUG("Queued click for handle " << handleToString(cq.handle) << " state " << (cq.pressed ? "PRESSED" : "RELEASED"));
4350
}
4351
 
4352
void TPageManager::_mouseEvent(ulong handle, bool pressed)
4353
{
4354
    DECL_TRACER("TPageManager::_mouseEvent(ulong handle, bool pressed)");
4355
 
293 andreas 4356
    MSG_DEBUG("Doing click for handle " << handleToString(handle) << " state " << (pressed ? "PRESSED" : "RELEASED"));
4357
 
289 andreas 4358
    if (!handle)
4359
        return;
4360
 
4361
    int pageID = (handle >> 16) & 0x0000ffff;
4362
    int buttonID = (handle & 0x0000ffff);
4363
 
318 andreas 4364
    if (pageID < REGULAR_SUBPAGE_START || buttonID == 0)
289 andreas 4365
        return;
4366
 
4367
    TSubPage *subPage = getSubPage(pageID);
4368
 
4369
    if (subPage)
4370
    {
4371
        Button::TButton *bt = subPage->getButton(buttonID);
4372
 
4373
        if (bt)
4374
        {
318 andreas 4375
            MSG_DEBUG("Button on subpage " << pageID << ": " << buttonID);
289 andreas 4376
            bt->doClick(bt->getLeftPosition() + bt->getWidth() / 2, bt->getTopPosition() + bt->getHeight() / 2, pressed);
4377
        }
4378
    }
4379
}
4380
 
192 andreas 4381
void TPageManager::inputButtonFinished(ulong handle, const std::string &content)
4382
{
4383
    DECL_TRACER("TPageManager::inputButtonFinished(ulong handle, const std::string &content)");
4384
 
4385
    Button::TButton *bt = findButton(handle);
4386
 
4387
    if (!bt)
4388
    {
271 andreas 4389
        MSG_WARNING("Invalid button handle " << handleToString(handle));
192 andreas 4390
        return;
4391
    }
4392
 
4393
    bt->setTextOnly(content, -1);
4394
}
4395
 
309 andreas 4396
void TPageManager::inputCursorPositionChanged(ulong handle, int oldPos, int newPos)
4397
{
4398
    DECL_TRACER("TPageManager::inputCursorPositionChanged(ulong handle, int oldPos, int newPos)");
4399
 
4400
    Button::TButton *bt = findButton(handle);
4401
 
4402
    if (!bt)
4403
    {
4404
        MSG_WARNING("Invalid button handle " << handleToString(handle));
4405
        return;
4406
    }
4407
 
310 andreas 4408
    ulong pageID = (bt->getHandle() >> 16) & 0x0000ffff;
309 andreas 4409
 
4410
    if (pageID < REGULAR_SUBPAGE_START)
4411
    {
368 andreas 4412
        TPage *pg = getPage((int)pageID);
309 andreas 4413
 
4414
        if (!pg)
4415
            return;
4416
 
4417
        pg->setCursorPosition(handle, oldPos, newPos);
4418
    }
4419
    else
4420
    {
368 andreas 4421
        TSubPage *pg = getSubPage((int)pageID);
309 andreas 4422
 
4423
        if (!pg)
4424
            return;
4425
 
4426
        pg->setCursorPosition(handle, oldPos, newPos);
4427
    }
4428
}
4429
 
4430
void TPageManager::inputFocusChanged(ulong handle, bool in)
4431
{
4432
    DECL_TRACER("TPageManager::inputFocusChanged(ulong handle, bool in)");
4433
 
4434
    Button::TButton *bt = findButton(handle);
4435
 
4436
    if (!bt)
4437
    {
4438
        MSG_WARNING("Invalid button handle " << handleToString(handle));
4439
        return;
4440
    }
4441
 
310 andreas 4442
    ulong pageID = (bt->getHandle() >> 16) & 0x0000ffff;
4443
    MSG_DEBUG("Searching for page " << pageID);
309 andreas 4444
 
4445
    if (pageID < REGULAR_SUBPAGE_START)
4446
    {
368 andreas 4447
        TPage *pg = getPage((int)pageID);
309 andreas 4448
 
4449
        if (!pg)
4450
            return;
4451
 
4452
        pg->setInputFocus(handle, in);
4453
    }
4454
    else
4455
    {
368 andreas 4456
        TSubPage *pg = getSubPage((int)pageID);
309 andreas 4457
 
4458
        if (!pg)
4459
            return;
4460
 
4461
        pg->setInputFocus(handle, in);
4462
    }
4463
}
4464
 
208 andreas 4465
void TPageManager::setTextToButton(ulong handle, const string& txt, bool redraw)
51 andreas 4466
{
208 andreas 4467
    DECL_TRACER("TPageManager::setTextToButton(ulong handle, const string& txt, bool redraw)");
51 andreas 4468
 
4469
    // First we search for the button the handle points to
4470
    Button::TButton *button = findButton(handle);
4471
 
4472
    if (!button)
4473
    {
271 andreas 4474
        MSG_ERROR("No button with handle " << handleToString(handle) << " found!");
51 andreas 4475
        return;
4476
    }
4477
 
4478
    // Now we search for all buttons with the same channel and port number
4479
    vector<int> channels;
4480
    channels.push_back(button->getAddressChannel());
193 andreas 4481
    vector<TMap::MAP_T> map = findButtons(button->getAddressPort(), channels);
51 andreas 4482
 
4483
    if (TError::isError() || map.empty())
4484
        return;
4485
 
4486
    // Here we load all buttons found.
4487
    vector<Button::TButton *> buttons = collectButtons(map);
83 andreas 4488
 
4489
    if (buttons.size() > 0)
51 andreas 4490
    {
83 andreas 4491
        vector<Button::TButton *>::iterator mapIter;
4492
        // Finaly we iterate through all found buttons and set the text
118 andreas 4493
        for (mapIter = buttons.begin(); mapIter != buttons.end(); ++mapIter)
83 andreas 4494
        {
4495
            Button::TButton *bt = *mapIter;
51 andreas 4496
 
208 andreas 4497
            if (redraw)
4498
                bt->setText(txt, -1);
4499
            else
4500
                bt->setTextOnly(txt, -1);
83 andreas 4501
        }
51 andreas 4502
    }
4503
}
4504
 
193 andreas 4505
vector<Button::TButton *> TPageManager::collectButtons(vector<TMap::MAP_T>& map)
14 andreas 4506
{
193 andreas 4507
    DECL_TRACER("TPageManager::collectButtons(vector<TMap::MAP_T>& map)");
14 andreas 4508
 
4509
    vector<Button::TButton *> buttons;
83 andreas 4510
 
4511
    if (map.size() == 0)
4512
        return buttons;
4513
 
193 andreas 4514
    vector<TMap::MAP_T>::iterator iter;
14 andreas 4515
 
118 andreas 4516
    for (iter = map.begin(); iter != map.end(); ++iter)
14 andreas 4517
    {
209 andreas 4518
        if (iter->pg < REGULAR_SUBPAGE_START || (iter->pg >= SYSTEM_PAGE_START && iter->pg < SYSTEM_SUBPAGE_START))     // Main page?
14 andreas 4519
        {
4520
            TPage *page;
4521
 
4522
            if ((page = getPage(iter->pg)) == nullptr)
4523
            {
4524
                MSG_TRACE("Page " << iter->pg << ", " << iter->pn << " not found in memory. Reading it ...");
4525
 
4526
                if (!readPage(iter->pg))
4527
                    return buttons;
4528
 
4529
                page = getPage(iter->pg);
4530
            }
4531
 
4532
            Button::TButton *bt = page->getButton(iter->bt);
4533
 
4534
            if (bt)
4535
                buttons.push_back(bt);
4536
        }
4537
        else
4538
        {
4539
            TSubPage *subpage;
4540
 
4541
            if ((subpage = getSubPage(iter->pg)) == nullptr)
4542
            {
4543
                MSG_TRACE("Subpage " << iter->pg << ", " << iter->pn << " not found in memory. Reading it ...");
4544
 
4545
                if (!readSubPage(iter->pg))
4546
                    return buttons;
4547
 
4548
                subpage = getSubPage(iter->pg);
4549
                TPage *page = getActualPage();
4550
 
4551
                if (!page)
4552
                {
4553
                    MSG_ERROR("No actual page loaded!");
4554
                    return buttons;
4555
                }
4556
            }
4557
 
4558
            Button::TButton *bt = subpage->getButton(iter->bt);
4559
 
4560
            if (bt)
4561
                buttons.push_back(bt);
4562
        }
4563
    }
4564
 
4565
    return buttons;
4566
}
4567
 
11 andreas 4568
/****************************************************************************
36 andreas 4569
 * Calls from a Java activity. This is only available for Android OS.
4570
 ****************************************************************************/
182 andreas 4571
#ifdef Q_OS_ANDROID
36 andreas 4572
void TPageManager::initNetworkState()
4573
{
4574
    DECL_TRACER("TPageManager::initNetworkState()");
264 andreas 4575
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
36 andreas 4576
    QAndroidJniObject activity = QtAndroid::androidActivity();
4577
    QAndroidJniObject::callStaticMethod<void>("org/qtproject/theosys/NetworkStatus", "Init", "(Landroid/app/Activity;)V", activity.object());
4578
    activity.callStaticMethod<void>("org/qtproject/theosys/NetworkStatus", "InstallNetworkListener", "()V");
182 andreas 4579
#else
4580
    QJniObject activity = QNativeInterface::QAndroidApplication::context();
4581
    QJniObject::callStaticMethod<void>("org/qtproject/theosys/NetworkStatus", "Init", "(Landroid/app/Activity;)V", activity.object());
4582
    activity.callStaticMethod<void>("org/qtproject/theosys/NetworkStatus", "InstallNetworkListener", "()V");
4583
#endif
36 andreas 4584
}
4585
 
4586
void TPageManager::stopNetworkState()
4587
{
4588
    DECL_TRACER("TPageManager::stopNetworkState()");
264 andreas 4589
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
36 andreas 4590
    QAndroidJniObject::callStaticMethod<void>("org/qtproject/theosys/NetworkStatus", "destroyNetworkListener", "()V");
182 andreas 4591
#else
4592
    QJniObject::callStaticMethod<void>("org/qtproject/theosys/NetworkStatus", "destroyNetworkListener", "()V");
4593
#endif
36 andreas 4594
}
38 andreas 4595
 
4596
void TPageManager::initBatteryState()
4597
{
4598
    DECL_TRACER("TPageManager::initBatteryState()");
264 andreas 4599
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
38 andreas 4600
    QAndroidJniObject activity = QtAndroid::androidActivity();
4601
    QAndroidJniObject::callStaticMethod<void>("org/qtproject/theosys/BatteryState", "Init", "(Landroid/app/Activity;)V", activity.object());
182 andreas 4602
#else
4603
    QJniObject activity = QNativeInterface::QAndroidApplication::context();
4604
    QJniObject::callStaticMethod<void>("org/qtproject/theosys/BatteryState", "Init", "(Landroid/app/Activity;)V", activity.object());
4605
#endif
38 andreas 4606
    activity.callStaticMethod<void>("org/qtproject/theosys/BatteryState", "InstallBatteryListener", "()V");
4607
}
4608
 
61 andreas 4609
void TPageManager::initPhoneState()
4610
{
4611
    DECL_TRACER("TPageManager::initPhoneState()");
264 andreas 4612
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
61 andreas 4613
    QAndroidJniObject activity = QtAndroid::androidActivity();
4614
    QAndroidJniObject::callStaticMethod<void>("org/qtproject/theosys/PhoneCallState", "Init", "(Landroid/app/Activity;)V", activity.object());
182 andreas 4615
#else
4616
    QJniObject activity = QNativeInterface::QAndroidApplication::context();
4617
    QJniObject::callStaticMethod<void>("org/qtproject/theosys/PhoneCallState", "Init", "(Landroid/app/Activity;)V", activity.object());
4618
#endif
61 andreas 4619
    activity.callStaticMethod<void>("org/qtproject/theosys/PhoneCallState", "InstallPhoneListener", "()V");
4620
}
4621
 
38 andreas 4622
void TPageManager::stopBatteryState()
4623
{
4624
    DECL_TRACER("TPageManager::stopBatteryState()");
264 andreas 4625
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
38 andreas 4626
    QAndroidJniObject::callStaticMethod<void>("org/qtproject/theosys/BatteryState", "destroyBatteryListener", "()V");
182 andreas 4627
#else
4628
    QJniObject::callStaticMethod<void>("org/qtproject/theosys/BatteryState", "destroyBatteryListener", "()V");
4629
#endif
38 andreas 4630
}
4631
 
36 andreas 4632
void TPageManager::informTPanelNetwork(jboolean conn, jint level, jint type)
4633
{
250 andreas 4634
    DECL_TRACER("TPageManager::informTPanelNetwork(jboolean conn, jint level, jint type)");
36 andreas 4635
 
4636
    int l = 0;
4637
    string sType;
4638
 
4639
    switch (type)
4640
    {
4641
        case 1: sType = "Wifi"; break;
4642
        case 2: sType = "Mobile"; break;
4643
 
4644
        default:
4645
            sType = "Unknown"; break;
4646
    }
4647
 
4648
    if (conn)
4649
        l = level;
4650
 
93 andreas 4651
    if (mNetState && mNetState != type)     // Has the connection type changed?
4652
    {
4653
        if (gAmxNet)
4654
            gAmxNet->reconnect();
4655
    }
4656
 
4657
    mNetState = type;
4658
 
36 andreas 4659
    MSG_INFO("Connection status: " << (conn ? "Connected" : "Disconnected") << ", level: " << level << ", type: " << sType);
4660
 
83 andreas 4661
    if (mNetCalls.size() > 0)
36 andreas 4662
    {
83 andreas 4663
        std::map<int, std::function<void (int level)> >::iterator iter;
4664
 
4665
        for (iter = mNetCalls.begin(); iter != mNetCalls.end(); ++iter)
4666
            iter->second(l);
36 andreas 4667
    }
4668
}
38 andreas 4669
 
4670
void TPageManager::informBatteryStatus(jint level, jboolean charging, jint chargeType)
4671
{
4672
    DECL_TRACER("TPageManager::informBatteryStatus(jint level, jboolean charging, jint chargeType)");
4673
 
59 andreas 4674
    MSG_INFO("Battery status: level: " << level << ", " << (charging ? "Charging" : "not charging") << ", type: " << chargeType << ", Elements: " << mBatteryCalls.size());
38 andreas 4675
 
83 andreas 4676
    if (mBatteryCalls.size() > 0)
38 andreas 4677
    {
83 andreas 4678
        std::map<int, std::function<void (int, bool, int)> >::iterator iter;
4679
 
4680
        for (iter = mBatteryCalls.begin(); iter != mBatteryCalls.end(); ++iter)
4681
            iter->second(level, charging, chargeType);
38 andreas 4682
    }
4683
}
61 andreas 4684
 
4685
void TPageManager::informPhoneState(bool call, const string &pnumber)
4686
{
4687
    DECL_TRACER("TPageManager::informPhoneState(bool call, const string &pnumber)");
4688
 
4689
    MSG_INFO("Call state: " << (call ? "Call in progress" : "No call") << ", phone number: " << pnumber);
4690
 
4691
    if (!gAmxNet)
4692
    {
4693
        MSG_WARNING("The network manager for the AMX controller is not initialized!");
4694
        return;
4695
    }
4696
}
130 andreas 4697
 
4698
void TPageManager::initOrientation()
4699
{
4700
    DECL_TRACER("TPageManager::initOrientation()");
4701
 
131 andreas 4702
    int rotate = getSettings()->getRotate();
264 andreas 4703
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
130 andreas 4704
    QAndroidJniObject activity = QtAndroid::androidActivity();
131 andreas 4705
    QAndroidJniObject::callStaticMethod<void>("org/qtproject/theosys/Orientation", "Init", "(Landroid/app/Activity;I)V", activity.object(), rotate);
182 andreas 4706
#else
4707
    QJniObject activity = QNativeInterface::QAndroidApplication::context();
4708
    QJniObject::callStaticMethod<void>("org/qtproject/theosys/Orientation", "Init", "(Landroid/app/Activity;I)V", activity.object(), rotate);
4709
#endif
130 andreas 4710
    activity.callStaticMethod<void>("org/qtproject/theosys/Orientation", "InstallOrientationListener", "()V");
4711
}
255 andreas 4712
 
4713
void TPageManager::enterSetup()
4714
{
260 andreas 4715
    DECL_TRACER("TPageManager::enterSetup()");
264 andreas 4716
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
255 andreas 4717
    QAndroidJniObject activity = QtAndroid::androidActivity();
4718
    QAndroidJniObject::callStaticMethod<void>("org/qtproject/theosys/Settings", "callSettings", "(Landroid/app/Activity;)V", activity.object());
4719
#else
4720
    QJniObject activity = QNativeInterface::QAndroidApplication::context();
4721
    QJniObject::callStaticMethod<void>("org/qtproject/theosys/Settings", "callSettings", "(Landroid/app/Activity;)V", activity.object());
4722
#endif
4723
}
59 andreas 4724
#endif  // __ANDROID__
247 andreas 4725
#ifdef Q_OS_IOS
4726
void TPageManager::informBatteryStatus(int level, int state)
4727
{
4728
    DECL_TRACER("TPageManager::informBatteryStatus(int level, int state)");
36 andreas 4729
 
247 andreas 4730
    MSG_INFO("Battery status: level: " << level << ", " << state);
4731
 
4732
    if (mBatteryCalls.size() > 0)
4733
    {
4734
        std::map<int, std::function<void (int, int)> >::iterator iter;
4735
 
4736
        for (iter = mBatteryCalls.begin(); iter != mBatteryCalls.end(); ++iter)
4737
            iter->second(level, state);
4738
    }
4739
}
250 andreas 4740
 
4741
void TPageManager::informTPanelNetwork(bool conn, int level, int type)
4742
{
4743
    DECL_TRACER("TPageManager::informTPanelNetwork(bool conn, int level, int type)");
4744
 
4745
    int l = 0;
4746
    string sType;
4747
 
4748
    switch (type)
4749
    {
4750
        case 1: sType = "Ethernet"; break;
4751
        case 2: sType = "Mobile"; break;
4752
        case 3: sType = "WiFi"; break;
4753
        case 4: sType = "Bluetooth"; break;
4754
 
4755
        default:
4756
            sType = "Unknown"; break;
4757
    }
4758
 
4759
    if (conn)
4760
        l = level;
4761
 
4762
    if (mNetState && mNetState != type)     // Has the connection type changed?
4763
    {
4764
        if (gAmxNet)
4765
            gAmxNet->reconnect();
4766
    }
4767
 
4768
    mNetState = type;
4769
 
4770
    MSG_INFO("Connection status: " << (conn ? "Connected" : "Disconnected") << ", level: " << level << ", type: " << sType);
4771
 
4772
    if (mNetCalls.size() > 0)
4773
    {
4774
        std::map<int, std::function<void (int level)> >::iterator iter;
4775
 
4776
        for (iter = mNetCalls.begin(); iter != mNetCalls.end(); ++iter)
4777
            iter->second(l);
4778
    }
4779
}
4780
 
247 andreas 4781
#endif
4782
 
60 andreas 4783
void TPageManager::setButtonCallbacks(Button::TButton *bt)
4784
{
227 andreas 4785
    DECL_TRACER("TPageManager::setButtonCallbacks(Button::TButton *bt)");
4786
 
162 andreas 4787
    if (!bt)
4788
        return;
4789
 
60 andreas 4790
    bt->registerCallback(_displayButton);
4791
    bt->regCallPlayVideo(_callPlayVideo);
4792
    bt->setFonts(mFonts);
4793
    bt->setPalette(mPalette);
4794
}
4795
 
4796
void TPageManager::externalButton(extButtons_t bt, bool checked)
4797
{
4798
    DECL_TRACER("TPageManager::externalButton(extButtons_t bt)");
4799
 
4800
    if (!mExternal)
4801
        return;
4802
 
4803
    EXTBUTTON_t button = mExternal->getButton(bt);
4804
 
4805
    if (button.type == EXT_NOBUTTON)
4806
        return;
4807
 
4808
    if (button.cp && button.ch)
4809
    {
4810
        amx::ANET_SEND scmd;
4811
 
4812
        scmd.device = TConfig::getChannel();
4813
        scmd.port = button.cp;
4814
        scmd.channel = button.ch;
4815
 
4816
        if (checked)
4817
            scmd.MC = 0x0084;   // push button
134 andreas 4818
        else
4819
            scmd.MC = 0x0085;   // release button
60 andreas 4820
 
134 andreas 4821
        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 4822
 
134 andreas 4823
        if (gAmxNet)
4824
            gAmxNet->sendCommand(scmd);
4825
        else
4826
        {
4827
            MSG_WARNING("Missing global class TAmxNet. Can't send a message!");
4828
        }
60 andreas 4829
    }
4830
}
4831
 
62 andreas 4832
void TPageManager::sendKeyboard(const std::string& text)
4833
{
4834
    DECL_TRACER("TPageManager::sendKeyboard(const std::string& text)");
4835
 
4836
    amx::ANET_SEND scmd;
4837
    scmd.port = 1;
4838
    scmd.channel = 0;
4839
    scmd.msg = UTF8ToCp1250(text);
4840
    scmd.MC = 0x008b;
4841
 
4842
    if (gAmxNet)
4843
        gAmxNet->sendCommand(scmd);
4844
    else
4845
        MSG_WARNING("Missing global class TAmxNet. Can't send message!");
4846
}
4847
 
4848
void TPageManager::sendKeypad(const std::string& text)
4849
{
4850
    DECL_TRACER("TPageManager::sendKeypad(const std::string& text)");
4851
 
269 andreas 4852
    sendKeyboard(text);
62 andreas 4853
}
4854
 
4855
void TPageManager::sendString(uint handle, const std::string& text)
4856
{
4857
    DECL_TRACER("TPageManager::sendString(uint handle, const std::string& text)");
4858
 
4859
    Button::TButton *bt = findButton(handle);
4860
 
4861
    if (!bt)
4862
    {
271 andreas 4863
        MSG_WARNING("Button " << handleToString(handle) << " not found!");
62 andreas 4864
        return;
4865
    }
4866
 
4867
    amx::ANET_SEND scmd;
4868
    scmd.port = bt->getAddressPort();
4869
    scmd.channel = bt->getAddressChannel();
4870
    scmd.msg = UTF8ToCp1250(text);
4871
    scmd.MC = 0x008b;
4872
 
4873
    if (gAmxNet)
4874
        gAmxNet->sendCommand(scmd);
4875
    else
4876
        MSG_WARNING("Missing global class TAmxNet. Can't send message!");
4877
}
4878
 
134 andreas 4879
void TPageManager::sendGlobalString(const string& text)
4880
{
4881
    DECL_TRACER("TPageManager::sendGlobalString(const string& text)");
4882
 
4883
    if (text.empty() || text.find("-") == string::npos)
4884
        return;
4885
 
4886
    amx::ANET_SEND scmd;
4887
    scmd.port = 1;
4888
    scmd.channel = 0;
4889
    scmd.msg = text;
4890
    scmd.MC = 0x008b;
4891
 
4892
    if (gAmxNet)
4893
        gAmxNet->sendCommand(scmd);
4894
    else
4895
        MSG_WARNING("Missing global class TAmxNet. Can't send message!");
4896
}
4897
 
147 andreas 4898
void TPageManager::sendCommandString(int port, const string& cmd)
4899
{
4900
    DECL_TRACER("TPageManager::sendGlobalString(const string& text)");
4901
 
4902
    if (cmd.empty())
4903
        return;
4904
 
4905
    amx::ANET_SEND scmd;
4906
    scmd.port = port;
4907
    scmd.channel = 0;
4908
    scmd.msg = cmd;
4909
    scmd.MC = 0x008c;
4910
 
4911
    if (gAmxNet)
4912
        gAmxNet->sendCommand(scmd);
4913
    else
4914
        MSG_WARNING("Missing global class TAmxNet. Can't send message!");
4915
}
4916
 
123 andreas 4917
void TPageManager::sendPHNcommand(const std::string& cmd)
4918
{
4919
    DECL_TRACER("TPageManager::sendPHNcommand(const std::string& cmd)");
4920
 
4921
    amx::ANET_SEND scmd;
144 andreas 4922
    scmd.port = mTSettings->getSettings().voipCommandPort;
123 andreas 4923
    scmd.channel = TConfig::getChannel();
4924
    scmd.msg = "^PHN-" + cmd;
127 andreas 4925
    scmd.MC = 0x008c;
4926
    MSG_DEBUG("Sending PHN command: ^PHN-" << cmd);
123 andreas 4927
 
4928
    if (gAmxNet)
4929
        gAmxNet->sendCommand(scmd);
4930
    else
4931
        MSG_WARNING("Missing global class TAmxNet. Can't send ^PHN command!");
4932
}
4933
 
111 andreas 4934
void TPageManager::sendKeyStroke(char key)
4935
{
4936
    DECL_TRACER("TPageManager::sendKeyStroke(char key)");
4937
 
4938
    if (!key)
4939
        return;
4940
 
4941
    char msg[2];
4942
    msg[0] = key;
4943
    msg[1] = 0;
4944
 
4945
    amx::ANET_SEND scmd;
4946
    scmd.port = 1;
4947
    scmd.channel = 0;
4948
    scmd.msg.assign(msg);
127 andreas 4949
    scmd.MC = 0x008c;
111 andreas 4950
 
4951
    if (gAmxNet)
4952
        gAmxNet->sendCommand(scmd);
4953
    else
4954
        MSG_WARNING("Missing global class TAmxNet. Can't send message!");
4955
}
4956
 
110 andreas 4957
/**
4958
 * Sending a custom event is identical in all cases. Because of this I
4959
 * implemented this method to send a custom event. This is called in all cases
4960
 * where a ?XXX command is received.
4961
 *
4962
 * @param value1    The instance of the button.
4963
 * @param value2    The value of a numeric request or the length of the string.
4964
 * @param value3    Always 0
4965
 * @param msg       In case of a string this contains the string.
4966
 * @param evType    This is the event type, a number between 1001 and 1099.
4967
 * @param cp        Channel port of button.
4968
 * @param cn        Channel number. of button.
4969
 *
4970
 * @return If all parameters are valid it returns TRUE.
4971
 */
4972
bool TPageManager::sendCustomEvent(int value1, int value2, int value3, const string& msg, int evType, int cp, int cn)
4973
{
4974
    DECL_TRACER("TPageManager::sendCustomEvent(int value1, int value2, int value3, const string& msg, int evType)");
4975
 
4976
    if (value1 < 1)
4977
        return false;
4978
 
4979
    amx::ANET_SEND scmd;
4980
    scmd.port = cp;
4981
    scmd.channel = cn;
4982
    scmd.ID = scmd.channel;
4983
    scmd.flag = 0;
4984
    scmd.type = evType;
4985
    scmd.value1 = value1;   // instance
4986
    scmd.value2 = value2;
4987
    scmd.value3 = value3;
4988
    scmd.msg = msg;
4989
 
4990
    if (!msg.empty())
4991
        scmd.dtype = 0x0001;// Char array
4992
 
4993
    scmd.MC = 0x008d;       // custom event
4994
 
4995
    if (gAmxNet)
4996
        gAmxNet->sendCommand(scmd);
4997
    else
4998
        MSG_WARNING("Missing global class TAmxNet. Can't send message!");
4999
 
5000
    return true;
5001
}
129 andreas 5002
#ifndef _NOSIP_
127 andreas 5003
string TPageManager::sipStateToString(TSIPClient::SIP_STATE_t s)
5004
{
5005
    DECL_TRACER("TPageManager::sipStateToString(TSIPClient::SIP_STATE_t s)");
5006
 
5007
    switch(s)
5008
    {
5009
        case TSIPClient::SIP_CONNECTED:     return "CONNECTED";
5010
        case TSIPClient::SIP_DISCONNECTED:  return "DISCONNECTED";
5011
        case TSIPClient::SIP_HOLD:          return "HOLD";
5012
        case TSIPClient::SIP_RINGING:       return "RINGING";
5013
        case TSIPClient::SIP_TRYING:        return "TRYING";
5014
 
5015
        default:
5016
            return "IDLE";
5017
    }
5018
 
5019
    return "IDLE";
5020
}
129 andreas 5021
#endif
134 andreas 5022
void TPageManager::sendOrientation()
5023
{
5024
    string ori;
5025
 
5026
    switch(mOrientation)
5027
    {
5028
        case O_PORTRAIT:            ori = "DeviceOrientationPortrait"; break;
5029
        case O_REVERSE_PORTRAIT:    ori = "DeviceOrientationPortraitUpsideDown"; break;
5030
        case O_LANDSCAPE:           ori = "DeviceOrientationLandscapeLeft"; break;
5031
        case O_REVERSE_LANDSCAPE:   ori = "DeviceOrientationLandscapeRight"; break;
5032
        case O_FACE_UP:             ori = "DeviceOrientationFaceUp"; break;
5033
        case O_FACE_DOWN:           ori = "DeviceOrientationFaceDown"; break;
5034
        default:
5035
            return;
5036
    }
5037
 
5038
    sendGlobalString("TPCACC-" + ori);
5039
}
5040
 
401 andreas 5041
void TPageManager::callSetPassword(ulong handle, const string& pw, int x, int y)
396 andreas 5042
{
401 andreas 5043
    DECL_TRACER("TPageManager::callSetPassword(ulong handle, const string& pw, int x, int y)");
396 andreas 5044
 
5045
    Button::TButton *bt = findButton(handle);
5046
 
5047
    if (!bt)
5048
    {
5049
        MSG_WARNING("callSetPassword: Button " << handleToString(handle) << " not found!");
5050
        return;
5051
    }
5052
 
5053
    string pass = pw;
5054
 
5055
    if (pass.empty())
5056
        pass = "\x01";
5057
 
5058
    bt->setPassword(pass);
401 andreas 5059
    bt->doClick(x, y, true);
5060
    bt->doClick(x, y, false);
396 andreas 5061
}
5062
 
153 andreas 5063
void TPageManager::onSwipeEvent(TPageManager::SWIPES sw)
5064
{
5065
    DECL_TRACER("TPageManager::onSwipeEvent(TPageManager::SWIPES sw)");
5066
 
5067
    // Swipes are defined in "external".
5068
    if (!mExternal)
5069
        return;
5070
 
5071
    extButtons_t eBt;
5072
    string dbg;
5073
 
5074
    switch(sw)
5075
    {
5076
        case SW_LEFT:   eBt = EXT_GESTURE_LEFT; dbg.assign("LEFT"); break;
5077
        case SW_RIGHT:  eBt = EXT_GESTURE_RIGHT; dbg.assign("RIGHT"); break;
5078
        case SW_UP:     eBt = EXT_GESTURE_UP; dbg.assign("UP"); break;
5079
        case SW_DOWN:   eBt = EXT_GESTURE_DOWN; dbg.assign("DOWN"); break;
5080
 
5081
        default:
5082
            return;
5083
    }
5084
 
5085
    int pgNum = getActualPageNumber();
5086
    EXTBUTTON_t bt = mExternal->getButton(pgNum, eBt);
5087
 
5088
    if (bt.bi == 0)
5089
        return;
5090
 
5091
    MSG_DEBUG("Received swipe " << dbg << " event for page " << pgNum << " on button " << bt.bi << " \"" << bt.na << "\"");
5092
 
5093
    if (!bt.cm.empty() && bt.co == 0)           // Feed command to ourself?
5094
    {                                           // Yes, then feed it into command queue.
5095
        MSG_DEBUG("Button has a self feed command");
5096
 
5097
        int channel = TConfig::getChannel();
5098
        int system = TConfig::getSystem();
5099
 
5100
        amx::ANET_COMMAND cmd;
5101
        cmd.MC = 0x000c;
5102
        cmd.device1 = channel;
5103
        cmd.port1 = bt.ap;
5104
        cmd.system = system;
5105
        cmd.data.message_string.device = channel;
5106
        cmd.data.message_string.port = bt.ap;  // Must be the address port of button
5107
        cmd.data.message_string.system = system;
5108
        cmd.data.message_string.type = 1;   // 8 bit char string
5109
 
5110
        vector<string>::iterator iter;
5111
 
5112
        for (iter = bt.cm.begin(); iter != bt.cm.end(); ++iter)
5113
        {
5114
            cmd.data.message_string.length = iter->length();
5115
            memset(&cmd.data.message_string.content, 0, sizeof(cmd.data.message_string.content));
5116
            strncpy((char *)&cmd.data.message_string.content, iter->c_str(), sizeof(cmd.data.message_string.content));
5117
            doCommand(cmd);
5118
        }
5119
    }
5120
    else if (!bt.cm.empty())
5121
    {
5122
        MSG_DEBUG("Button sends a command on port " << bt.co);
5123
 
5124
        vector<string>::iterator iter;
5125
 
5126
        for (iter = bt.cm.begin(); iter != bt.cm.end(); ++iter)
5127
            sendCommandString(bt.co, *iter);
5128
    }
5129
}
5130
 
36 andreas 5131
/****************************************************************************
11 andreas 5132
 * The following functions implements one of the commands the panel accepts.
5133
 ****************************************************************************/
43 andreas 5134
 
5135
/**
5136
 * This is a special function handling the progress bars when the files of the
5137
 * panel are updated. Instead of simply displaying a ready page, it fakes one
5138
 * with the actual dimensions of the main page. This is possible, because we've
5139
 * always a main page even if the panel is started for the first time.
5140
 */
5141
void TPageManager::doFTR(int port, vector<int>& channels, vector<string>& pars)
23 andreas 5142
{
43 andreas 5143
    DECL_TRACER("TPageManager::doFTR(int, vector<int>&, vector<string>& pars)");
14 andreas 5144
 
23 andreas 5145
    if (pars.empty())
5146
    {
5147
        MSG_WARNING("Command #FTR needs at least 1 parameter! Ignoring command.");
5148
        return;
5149
    }
5150
 
96 andreas 5151
    if (TStreamError::checkFilter(HLOG_DEBUG))
23 andreas 5152
    {
96 andreas 5153
        for (size_t i = 0; i < pars.size(); i++)
5154
        {
5155
            MSG_DEBUG("[" << i << "]: " << pars.at(i));
5156
        }
23 andreas 5157
    }
43 andreas 5158
 
5159
    if (pars.at(0).compare("START") == 0)
5160
    {
5161
        // Here we have to drop all pages and subpages first and then display
5162
        // the faked page with the progress bars.
5163
        MSG_DEBUG("Starting file transfer ...");
5164
        doPPX(port, channels, pars);
5165
        TPage *pg = getPage("_progress");
5166
 
5167
        if (!pg)
5168
        {
5169
            if (!readPage("_progress"))
5170
            {
5171
                MSG_ERROR("Error creating the system page _progress!");
5172
                return;
5173
            }
5174
 
5175
            pg = getPage("_progress");
5176
 
5177
            if (!pg)
5178
            {
5179
                MSG_ERROR("Error getting system page _progress!");
5180
                return;
5181
            }
5182
        }
5183
 
5184
        pg->setFonts(mFonts);
5185
        pg->registerCallback(_setBackground);
5186
        pg->regCallPlayVideo(_callPlayVideo);
5187
 
5188
        if (!pg || !_setPage || !mTSettings)
5189
            return;
5190
 
5191
        int width, height;
217 andreas 5192
        width = mTSettings->getWidth();
43 andreas 5193
        height = mTSettings->getHeight();
5194
#ifdef _SCALE_SKIA_
5195
        if (mScaleFactor != 1.0)
5196
        {
5197
            width = (int)((double)width * mScaleFactor);
5198
            height = (int)((double)height * mScaleFactor);
5199
        }
5200
#endif
5201
        _setPage((pg->getNumber() << 16) & 0xffff0000, width, height);
5202
        pg->show();
5203
        MSG_DEBUG("Page _progress on screen");
5204
    }
5205
    else if (pars.at(0).compare("SYNC") == 0)
5206
    {
5207
        TPage *pg = getPage("_progress");
5208
 
5209
        if (!pg)
5210
        {
5211
            MSG_ERROR("Page _progress not found!");
5212
            return;
5213
        }
5214
 
5215
        Button::TButton *bt = pg->getButton(1);   // Line 1
5216
 
5217
        if (!bt)
5218
        {
5219
            MSG_ERROR("Button 160 of page _progress not found!");
5220
            return;
5221
        }
5222
 
5223
        bt->setText(pars.at(2), 0);
5224
        bt->show();
5225
    }
5226
    else if (pars.at(0).compare("FTRSTART") == 0)
5227
    {
5228
        TPage *pg = getPage("_progress");
5229
 
5230
        if (!pg)
5231
        {
5232
            MSG_ERROR("Page _progress not found!");
5233
            return;
5234
        }
5235
 
5236
        Button::TButton *bt1 = pg->getButton(1);   // Line 1
5237
        Button::TButton *bt2 = pg->getButton(2);   // Line 2
5238
        Button::TButton *bt3 = pg->getButton(3);   // Bargraph 1
5239
        Button::TButton *bt4 = pg->getButton(4);   // Bargraph 2
5240
 
5241
        if (!bt1 || !bt2 || !bt3 || !bt4)
5242
        {
5243
            MSG_ERROR("Buttons of page _progress not found!");
5244
            return;
5245
        }
5246
 
5247
        bt1->setText("Transfering files ...", 0);
5248
        bt1->show();
5249
        bt2->setText(pars.at(3), 0);
5250
        bt2->show();
5251
        bt3->drawBargraph(0, atoi(pars.at(1).c_str()), true);
5252
        bt4->drawBargraph(0, atoi(pars.at(2).c_str()), true);
5253
    }
5254
    else if (pars.at(0).compare("FTRPART") == 0)
5255
    {
5256
        TPage *pg = getPage("_progress");
5257
 
5258
        if (!pg)
5259
        {
5260
            MSG_ERROR("Page _progress not found!");
5261
            return;
5262
        }
5263
 
5264
        Button::TButton *bt = pg->getButton(4);   // Bargraph 2
5265
 
5266
        if (!bt)
5267
        {
5268
            MSG_ERROR("Buttons of page _progress not found!");
5269
            return;
5270
        }
5271
 
5272
        bt->drawBargraph(0, atoi(pars.at(2).c_str()), true);
5273
    }
5274
    else if (pars.at(0).compare("END") == 0)
5275
    {
5276
        MSG_TRACE("End of file transfer reached.");
44 andreas 5277
 
155 andreas 5278
        // To make sure the new surface will not be deleted and replaced by the
5279
        // default build in surface, we must delete the "virgin" marker first.
5280
        // This is a file called <project path>/.system.
5281
        string virgin = TConfig::getProjectPath() + "/.system";
5282
        remove(virgin.c_str());     // Because this file may not exist we don't care about the result code.
5283
 
44 andreas 5284
        if (_resetSurface)
5285
            _resetSurface();
5286
        else
5287
        {
5288
            MSG_WARNING("Missing callback function \"resetSurface\"!");
5289
        }
43 andreas 5290
    }
23 andreas 5291
}
5292
 
318 andreas 5293
void TPageManager::doLEVON(int, vector<int>&, vector<string>&)
5294
{
5295
    DECL_TRACER("TPageManager::doLEVON(int, vector<int>&, vector<string>&)");
5296
 
5297
    mLevelSend = true;
343 andreas 5298
#if TESTMODE == 1
5299
    __success = true;
5300
    setAllDone();
5301
#endif
318 andreas 5302
}
5303
 
5304
void TPageManager::doLEVOF(int, vector<int>&, vector<string>&)
5305
{
5306
    DECL_TRACER("TPageManager::doLEVOF(int, vector<int>&, vector<string>&)");
5307
 
5308
    mLevelSend = false;
343 andreas 5309
#if TESTMODE == 1
5310
    __success = true;
5311
    setAllDone();
5312
#endif
318 andreas 5313
}
5314
 
5315
void TPageManager::doRXON(int, vector<int>&, vector<string>&)
5316
{
5317
    DECL_TRACER("TPageManager::doRXON(int, vector<int>&, vector<string>&)");
5318
 
5319
    mRxOn = true;
343 andreas 5320
#if TESTMODE == 1
5321
    __success = true;
5322
    setAllDone();
5323
#endif
318 andreas 5324
}
5325
 
5326
void TPageManager::doRXOF(int, vector<int>&, vector<string>&)
5327
{
5328
    DECL_TRACER("TPageManager::doRXOF(int, vector<int>&, vector<string>&)");
5329
 
5330
    mRxOn = false;
343 andreas 5331
#if TESTMODE == 1
5332
    __success = true;
5333
    setAllDone();
5334
#endif
318 andreas 5335
}
5336
 
22 andreas 5337
void TPageManager::doON(int port, vector<int>&, vector<string>& pars)
14 andreas 5338
{
5339
    DECL_TRACER("TPageManager::doON(int port, vector<int>& channels, vector<string>& pars)");
5340
 
5341
    if (pars.empty())
5342
    {
5343
        MSG_WARNING("Command ON needs 1 parameter! Ignoring command.");
343 andreas 5344
#if TESTMODE == 1
5345
        setAllDone();
5346
#endif
14 andreas 5347
        return;
5348
    }
5349
 
16 andreas 5350
    TError::clear();
14 andreas 5351
    int c = atoi(pars[0].c_str());
5352
 
5353
    if (c <= 0)
5354
    {
5355
        MSG_WARNING("Invalid channel " << c << "! Ignoring command.");
343 andreas 5356
#if TESTMODE == 1
5357
        setAllDone();
5358
#endif
14 andreas 5359
        return;
5360
    }
5361
 
5362
    vector<int> chans = { c };
193 andreas 5363
    vector<TMap::MAP_T> map = findButtons(port, chans, TMap::TYPE_CM);
14 andreas 5364
 
5365
    if (TError::isError() || map.empty())
343 andreas 5366
    {
5367
#if TESTMODE == 1
5368
        setAllDone();
5369
#endif
14 andreas 5370
        return;
343 andreas 5371
    }
14 andreas 5372
 
5373
    vector<Button::TButton *> buttons = collectButtons(map);
5374
 
83 andreas 5375
    if (buttons.size() > 0)
14 andreas 5376
    {
83 andreas 5377
        vector<Button::TButton *>::iterator mapIter;
14 andreas 5378
 
118 andreas 5379
        for (mapIter = buttons.begin(); mapIter != buttons.end(); ++mapIter)
83 andreas 5380
        {
5381
            Button::TButton *bt = *mapIter;
5382
 
195 andreas 5383
            if (bt->getButtonType() == GENERAL)
343 andreas 5384
            {
83 andreas 5385
                bt->setActive(1);
343 andreas 5386
#if TESTMODE == 1
5387
                if (_gTestMode)
5388
                    _gTestMode->setResult(intToString(bt->getActiveInstance() + 1));
5389
#endif
5390
            }
83 andreas 5391
        }
14 andreas 5392
    }
343 andreas 5393
#if TESTMODE == 1
5394
    setDone();
5395
#endif
14 andreas 5396
}
5397
 
22 andreas 5398
void TPageManager::doOFF(int port, vector<int>&, vector<string>& pars)
14 andreas 5399
{
5400
    DECL_TRACER("TPageManager::doOFF(int port, vector<int>& channels, vector<string>& pars)");
5401
 
5402
    if (pars.empty())
5403
    {
5404
        MSG_WARNING("Command OFF needs 1 parameter! Ignoring command.");
343 andreas 5405
#if TESTMODE == 1
5406
        setAllDone();
5407
#endif
14 andreas 5408
        return;
5409
    }
5410
 
16 andreas 5411
    TError::clear();
14 andreas 5412
    int c = atoi(pars[0].c_str());
5413
 
5414
    if (c <= 0)
5415
    {
5416
        MSG_WARNING("Invalid channel " << c << "! Ignoring command.");
343 andreas 5417
#if TESTMODE == 1
5418
        setAllDone();
5419
#endif
14 andreas 5420
        return;
5421
    }
5422
 
5423
    vector<int> chans = { c };
193 andreas 5424
    vector<TMap::MAP_T> map = findButtons(port, chans, TMap::TYPE_CM);
14 andreas 5425
 
5426
    if (TError::isError() || map.empty())
5427
        return;
5428
 
5429
    vector<Button::TButton *> buttons = collectButtons(map);
5430
 
83 andreas 5431
    if (buttons.size() > 0)
14 andreas 5432
    {
83 andreas 5433
        vector<Button::TButton *>::iterator mapIter;
14 andreas 5434
 
118 andreas 5435
        for (mapIter = buttons.begin(); mapIter != buttons.end(); ++mapIter)
83 andreas 5436
        {
5437
            Button::TButton *bt = *mapIter;
5438
 
195 andreas 5439
            if (bt->getButtonType() == GENERAL)
83 andreas 5440
                bt->setActive(0);
343 andreas 5441
#if TESTMODE == 1
5442
                if (_gTestMode)
5443
                    _gTestMode->setResult(intToString(bt->getActiveInstance() + 1));
5444
#endif
83 andreas 5445
        }
14 andreas 5446
    }
343 andreas 5447
#if TESTMODE == 1
5448
    setDone();
5449
#endif
14 andreas 5450
}
5451
 
22 andreas 5452
void TPageManager::doLEVEL(int port, vector<int>&, vector<string>& pars)
15 andreas 5453
{
5454
    DECL_TRACER("TPageManager::doLEVEL(int port, vector<int>& channels, vector<string>& pars)");
5455
 
5456
    if (pars.size() < 2)
5457
    {
5458
        MSG_WARNING("Command LEVEL needs 2 parameters! Ignoring command.");
343 andreas 5459
#if TESTMODE == 1
5460
        setAllDone();
5461
#endif
15 andreas 5462
        return;
5463
    }
5464
 
16 andreas 5465
    TError::clear();
15 andreas 5466
    int c = atoi(pars[0].c_str());
5467
    int level = atoi(pars[1].c_str());
5468
 
5469
    if (c <= 0)
5470
    {
5471
        MSG_WARNING("Invalid channel " << c << "! Ignoring command.");
343 andreas 5472
#if TESTMODE == 1
5473
        setAllDone();
5474
#endif
15 andreas 5475
        return;
5476
    }
5477
 
5478
    vector<int> chans = { c };
193 andreas 5479
    vector<TMap::MAP_T> map = findBargraphs(port, chans);
15 andreas 5480
 
5481
    if (TError::isError() || map.empty())
5482
    {
5483
        MSG_WARNING("No bargraphs found!");
343 andreas 5484
#if TESTMODE == 1
5485
        setAllDone();
5486
#endif
15 andreas 5487
        return;
5488
    }
5489
 
5490
    vector<Button::TButton *> buttons = collectButtons(map);
5491
 
83 andreas 5492
    if (buttons.size() > 0)
15 andreas 5493
    {
83 andreas 5494
        vector<Button::TButton *>::iterator mapIter;
15 andreas 5495
 
118 andreas 5496
        for (mapIter = buttons.begin(); mapIter != buttons.end(); ++mapIter)
15 andreas 5497
        {
83 andreas 5498
            Button::TButton *bt = *mapIter;
5499
 
195 andreas 5500
            if (bt->getButtonType() == BARGRAPH)
343 andreas 5501
            {
83 andreas 5502
                bt->drawBargraph(bt->getActiveInstance(), level);
343 andreas 5503
#if TESTMODE == 1
5504
                if (_gTestMode)
5505
                    _gTestMode->setResult(intToString(bt->getLevelValue()));
5506
#endif
5507
            }
195 andreas 5508
            else if (bt->getButtonType() == MULTISTATE_BARGRAPH)
83 andreas 5509
            {
5510
                int state = (int)((double)bt->getStateCount() / (double)(bt->getRangeHigh() - bt->getRangeLow()) * (double)level);
5511
                bt->setActive(state);
343 andreas 5512
#if TESTMODE == 1
5513
                if (_gTestMode)
5514
                    _gTestMode->setResult(intToString(bt->getActiveInstance()));
5515
#endif
83 andreas 5516
            }
15 andreas 5517
        }
5518
    }
343 andreas 5519
#if TESTMODE == 1
5520
    setDone();
5521
#endif
15 andreas 5522
}
5523
 
22 andreas 5524
void TPageManager::doBLINK(int, vector<int>&, vector<string>& pars)
15 andreas 5525
{
5526
    DECL_TRACER("TPageManager::doBLINK(int port, vector<int>& channels, vector<string>& pars)");
5527
 
5528
    if (pars.size() < 4)
5529
    {
5530
        MSG_WARNING("Command BLINK expects 4 parameters! Command ignored.");
343 andreas 5531
#if TESTMODE == 1
5532
        setAllDone();
5533
#endif
15 andreas 5534
        return;
5535
    }
5536
 
16 andreas 5537
    TError::clear();
15 andreas 5538
    vector<int> sysButtons = { 141, 142, 143, 151, 152, 153, 154, 155, 156, 157, 158 };
193 andreas 5539
    vector<TMap::MAP_T> map = findButtons(0, sysButtons);
15 andreas 5540
 
5541
    if (TError::isError() || map.empty())
5542
    {
5543
        MSG_WARNING("No system buttons found.");
343 andreas 5544
#if TESTMODE == 1
5545
        setAllDone();
5546
#endif
15 andreas 5547
        return;
5548
    }
5549
 
5550
    vector<Button::TButton *> buttons = collectButtons(map);
5551
    vector<Button::TButton *>::iterator mapIter;
5552
 
5553
    for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
5554
    {
5555
        Button::TButton *bt = *mapIter;
5556
        bt->setActive(0);
343 andreas 5557
#if TESTMODE == 1
5558
                if (_gTestMode)
5559
                    _gTestMode->setResult(intToString(bt->getActiveInstance() + 1));
5560
#endif
15 andreas 5561
    }
343 andreas 5562
#if TESTMODE == 1
5563
    setDone();
5564
#endif
15 andreas 5565
}
5566
 
162 andreas 5567
/**
5568
 * Send the version of the panel to the NetLinx. This is the real application
5569
 * version.
5570
 */
127 andreas 5571
void TPageManager::doVER(int, vector<int>&, vector<string>&)
5572
{
5573
    DECL_TRACER("TPageManager::doVER(int, vector<int>&, vector<string>&)");
5574
 
5575
    amx::ANET_SEND scmd;
5576
    scmd.port = 1;
5577
    scmd.channel = 0;
5578
    scmd.msg.assign(string("^VER-")+VERSION_STRING());
5579
    scmd.MC = 0x008c;
5580
 
5581
    if (gAmxNet)
343 andreas 5582
    {
127 andreas 5583
        gAmxNet->sendCommand(scmd);
343 andreas 5584
#if TESTMODE == 1
5585
        __success = true;
347 andreas 5586
 
5587
        if (_gTestMode)
5588
            _gTestMode->setResult(VERSION_STRING());
343 andreas 5589
#endif
5590
    }
127 andreas 5591
    else
5592
        MSG_WARNING("Missing global class TAmxNet. Can't send message!");
343 andreas 5593
#if TESTMODE == 1
5594
    setAllDone();
5595
#endif
127 andreas 5596
}
5597
 
162 andreas 5598
/**
5599
 * Returns the user name used to connect to a SIP server. An empty string is
5600
 * returned if there is no user defined.
5601
 */
279 andreas 5602
#ifndef _NOSIP_
127 andreas 5603
void TPageManager::doWCN(int, vector<int>&, vector<string>&)
5604
{
5605
    DECL_TRACER("TPageManager::doWCN(int, vector<int>&, vector<string>&)");
5606
 
5607
    if (!TConfig::getSIPstatus())
343 andreas 5608
    {
5609
#if TESTMODE == 1
5610
        setAllDone();
5611
#endif
127 andreas 5612
        return;
343 andreas 5613
    }
127 andreas 5614
 
5615
    amx::ANET_SEND scmd;
5616
    scmd.port = 1;
5617
    scmd.channel = 0;
5618
    scmd.msg.assign("^WCN-" + TConfig::getSIPuser());
5619
    scmd.MC = 0x008c;
5620
 
5621
    if (gAmxNet)
343 andreas 5622
    {
127 andreas 5623
        gAmxNet->sendCommand(scmd);
343 andreas 5624
#if TESTMODE == 1
5625
        __success = true;
347 andreas 5626
 
5627
        if (_gTestMode)
5628
            _gTestMode->setResult(TConfig::getSIPuser());
343 andreas 5629
#endif
5630
    }
127 andreas 5631
    else
5632
        MSG_WARNING("Missing global class TAmxNet. Can't send message!");
343 andreas 5633
#if TESTMODE == 1
5634
        setAllDone();
5635
#endif
127 andreas 5636
}
279 andreas 5637
#endif
14 andreas 5638
/**
147 andreas 5639
 * Flip to specified page using the named animation.
5640
 * FIXME: Implement animation for pages.
5641
 */
5642
void TPageManager::doAFP(int, vector<int>&, vector<string>& pars)
5643
{
5644
    DECL_TRACER("TPageManager::doAFP(int, vector<int>&, vector<string>& pars)");
5645
 
5646
    if (pars.size() < 4)
5647
    {
5648
        MSG_ERROR("Less than 4 parameters!");
343 andreas 5649
#if TESTMODE == 1
5650
        setAllDone();
5651
#endif
147 andreas 5652
        return;
5653
    }
5654
 
5655
    TError::clear();
5656
    string pname = pars[0];
5657
//    string ani = pars[1];
5658
//    int origin = atoi(pars[2].c_str());
5659
//    int duration = atoi(pars[3].c_str());
5660
 
5661
    // FIXME: Animation of pages is currently not implemented.
5662
 
5663
    if (!pname.empty())
5664
        setPage(pname);
5665
    else if (mPreviousPage)
5666
        setPage(mPreviousPage);
343 andreas 5667
#if TESTMODE == 1
5668
    if (_gTestMode)
5669
        _gTestMode->setResult(getActualPage()->getName());
5670
 
5671
    setDone();
5672
#endif
147 andreas 5673
}
5674
 
5675
/**
14 andreas 5676
 * Add a specific popup page to a specified popup group if it does not already
5677
 * exist. If the new popup is added to a group which has a popup displayed on
5678
 * the current page along with the new pop-up, the displayed popup will be
5679
 * hidden and the new popup will be displayed.
5680
 */
22 andreas 5681
void TPageManager::doAPG(int, std::vector<int>&, std::vector<std::string>& pars)
11 andreas 5682
{
5683
    DECL_TRACER("TPageManager::doAPG(int port, std::vector<int>& channels, std::vector<std::string>& pars)");
5684
 
5685
    if (pars.size() < 2)
5686
    {
5687
        MSG_ERROR("Less than 2 parameters!");
343 andreas 5688
#if TESTMODE == 1
5689
        setAllDone();
5690
#endif
11 andreas 5691
        return;
5692
    }
5693
 
16 andreas 5694
    TError::clear();
11 andreas 5695
    closeGroup(pars[1]);
14 andreas 5696
 
96 andreas 5697
    TPage *page = nullptr;
5698
    TSubPage *subPage = deliverSubPage(pars[0], &page);
14 andreas 5699
 
11 andreas 5700
    if (!subPage)
5701
    {
5702
        MSG_ERROR("Subpage " << pars[0] << " couldn't either found or created!");
343 andreas 5703
#if TESTMODE == 1
5704
        setAllDone();
5705
#endif
11 andreas 5706
        return;
5707
    }
5708
 
162 andreas 5709
    if (!page)
5710
    {
5711
        MSG_ERROR("There seems to be no page for subpage " << pars[0]);
343 andreas 5712
#if TESTMODE == 1
5713
        setAllDone();
5714
#endif
162 andreas 5715
        return;
5716
    }
5717
 
152 andreas 5718
    page->addSubPage(subPage);
11 andreas 5719
    subPage->setGroup(pars[1]);
14 andreas 5720
    subPage->setZOrder(page->getNextZOrder());
152 andreas 5721
    MSG_DEBUG("Setting new Z-order " << page->getActZOrder() << " on page " << page->getName());
11 andreas 5722
    subPage->show();
343 andreas 5723
#if TESTMODE == 1
347 andreas 5724
    if (_gTestMode)
5725
        _gTestMode->setResult(subPage->getGroupName() + ":" + subPage->getName());
5726
 
343 andreas 5727
    setDone();
5728
#endif
11 andreas 5729
}
5730
 
14 andreas 5731
/**
5732
 * Clear all popup pages from specified popup group.
5733
 */
22 andreas 5734
void TPageManager::doCPG(int, std::vector<int>&, std::vector<std::string>& pars)
11 andreas 5735
{
5736
    DECL_TRACER("TPageManager::doCPG(int port, std::vector<int>& channels, std::vector<std::string>& pars)");
5737
 
5738
    if (pars.size() < 1)
5739
    {
5740
        MSG_ERROR("Expecting 1 parameter but got only 1!");
343 andreas 5741
#if TESTMODE == 1
5742
        setAllDone();
5743
#endif
11 andreas 5744
        return;
5745
    }
5746
 
16 andreas 5747
    TError::clear();
348 andreas 5748
    vector<SUBPAGELIST_T> pageList = mPageList->getSubPageList();
11 andreas 5749
 
83 andreas 5750
    if (pageList.size() > 0)
11 andreas 5751
    {
83 andreas 5752
        vector<SUBPAGELIST_T>::iterator pgIter;
5753
 
5754
        for (pgIter = pageList.begin(); pgIter != pageList.end(); pgIter++)
11 andreas 5755
        {
83 andreas 5756
            if (pgIter->group.compare(pars[0]) == 0)
5757
            {
5758
                pgIter->group.clear();
5759
                TSubPage *pg = getSubPage(pgIter->pageID);
11 andreas 5760
 
83 andreas 5761
                if (pg)
5762
                    pg->setGroup(pgIter->group);
343 andreas 5763
#if TESTMODE == 1
5764
                __success = true;
5765
#endif
83 andreas 5766
            }
11 andreas 5767
        }
5768
    }
343 andreas 5769
#if TESTMODE == 1
5770
    setDone();
5771
#endif
11 andreas 5772
}
5773
 
14 andreas 5774
/**
5775
 * Delete a specific popup page from specified popup group if it exists.
5776
 */
22 andreas 5777
void TPageManager::doDPG(int, std::vector<int>&, std::vector<std::string>& pars)
11 andreas 5778
{
5779
    DECL_TRACER("TPageManager::doDPG(int port, std::vector<int>& channels, std::vector<std::string>& pars)");
5780
 
5781
    if (pars.size() < 2)
5782
    {
5783
        MSG_ERROR("Less than 2 parameters!");
348 andreas 5784
#if TESTMODE == 1
5785
        setAllDone();
5786
#endif
11 andreas 5787
        return;
5788
    }
5789
 
16 andreas 5790
    TError::clear();
11 andreas 5791
    SUBPAGELIST_T listPg = findSubPage(pars[0]);
5792
 
5793
    if (!listPg.isValid)
348 andreas 5794
    {
5795
#if TESTMODE == 1
5796
        setAllDone();
5797
#endif
11 andreas 5798
        return;
348 andreas 5799
    }
11 andreas 5800
 
5801
    if (listPg.group.compare(pars[1]) == 0)
5802
    {
5803
        listPg.group.clear();
5804
        TSubPage *pg = getSubPage(listPg.pageID);
5805
 
5806
        if (pg)
5807
            pg->setGroup(listPg.group);
348 andreas 5808
#if TESTMODE == 1
5809
        __success = true;
5810
#endif
11 andreas 5811
    }
348 andreas 5812
#if TESTMODE == 1
5813
    setDone();
5814
#endif
11 andreas 5815
}
5816
 
14 andreas 5817
/**
15 andreas 5818
 * Set the hide effect for the specified popup page to the named hide effect.
5819
 */
22 andreas 5820
void TPageManager::doPHE(int, vector<int>&, vector<string>& pars)
15 andreas 5821
{
5822
    DECL_TRACER("TPageManager::doPHE(int port, vector<int>& channels, vector<string>& pars)");
5823
 
5824
    if (pars.size() < 2)
5825
    {
5826
        MSG_ERROR("Less than 2 parameters!");
348 andreas 5827
#if TESTMODE == 1
5828
        setAllDone();
5829
#endif
15 andreas 5830
        return;
5831
    }
5832
 
16 andreas 5833
    TError::clear();
96 andreas 5834
    TSubPage *pg = deliverSubPage(pars[0]);
15 andreas 5835
 
5836
    if (!pg)
348 andreas 5837
    {
5838
#if TESTMODE == 1
5839
        setAllDone();
5840
#endif
96 andreas 5841
        return;
348 andreas 5842
    }
15 andreas 5843
 
162 andreas 5844
    if (strCaseCompare(pars[1], "fade") == 0)
15 andreas 5845
        pg->setHideEffect(SE_FADE);
162 andreas 5846
    else if (strCaseCompare(pars[1], "slide to left") == 0)
15 andreas 5847
        pg->setHideEffect(SE_SLIDE_LEFT);
162 andreas 5848
    else if (strCaseCompare(pars[1], "slide to right") == 0)
15 andreas 5849
        pg->setHideEffect(SE_SLIDE_RIGHT);
162 andreas 5850
    else if (strCaseCompare(pars[1], "slide to top") == 0)
15 andreas 5851
        pg->setHideEffect(SE_SLIDE_TOP);
162 andreas 5852
    else if (strCaseCompare(pars[1], "slide to bottom") == 0)
15 andreas 5853
        pg->setHideEffect(SE_SLIDE_BOTTOM);
162 andreas 5854
    else if (strCaseCompare(pars[1], "slide to left fade") == 0)
15 andreas 5855
        pg->setHideEffect(SE_SLIDE_LEFT_FADE);
162 andreas 5856
    else if (strCaseCompare(pars[1], "slide to right fade") == 0)
15 andreas 5857
        pg->setHideEffect(SE_SLIDE_RIGHT_FADE);
162 andreas 5858
    else if (strCaseCompare(pars[1], "slide to top fade") == 0)
15 andreas 5859
        pg->setHideEffect(SE_SLIDE_TOP_FADE);
162 andreas 5860
    else if (strCaseCompare(pars[1], "slide to bottom fade") == 0)
15 andreas 5861
        pg->setHideEffect(SE_SLIDE_BOTTOM_FADE);
5862
    else
5863
        pg->setHideEffect(SE_NONE);
348 andreas 5864
#if TESTMODE == 1
5865
    if (_gTestMode)
5866
        _gTestMode->setResult(intToString(pg->getHideEffect()));
5867
 
5868
    __success = true;
5869
    setAllDone();
5870
#endif
15 andreas 5871
}
5872
 
5873
/**
5874
 * Set the hide effect position. Only 1 coordinate is ever needed for an effect;
5875
 * however, the command will specify both. This command sets the location at
5876
 * which the effect will end at.
5877
 */
22 andreas 5878
void TPageManager::doPHP(int, vector<int>&, vector<string>& pars)
15 andreas 5879
{
5880
    DECL_TRACER("TPageManager::doPHP(int port, vector<int>& channels, vector<string>& pars)");
5881
 
5882
    if (pars.size() < 2)
5883
    {
5884
        MSG_ERROR("Less than 2 parameters!");
348 andreas 5885
#if TESTMODE == 1
5886
        setAllDone();
5887
#endif
15 andreas 5888
        return;
5889
    }
5890
 
16 andreas 5891
    TError::clear();
15 andreas 5892
    size_t pos = pars[1].find(",");
5893
    int x, y;
5894
 
5895
    if (pos == string::npos)
5896
    {
5897
        x = atoi(pars[1].c_str());
5898
        y = 0;
5899
    }
5900
    else
5901
    {
5902
        x = atoi(pars[1].substr(0, pos).c_str());
5903
        y = atoi(pars[1].substr(pos+1).c_str());
5904
    }
5905
 
96 andreas 5906
    TSubPage *pg = deliverSubPage(pars[0]);
15 andreas 5907
 
5908
    if (!pg)
348 andreas 5909
    {
5910
#if TESTMODE == 1
5911
        setAllDone();
5912
#endif
96 andreas 5913
        return;
348 andreas 5914
    }
15 andreas 5915
 
5916
    pg->setHideEndPosition(x, y);
348 andreas 5917
#if TESTMODE == 1
5918
    if (_gTestMode)
5919
    {
5920
        int x, y;
5921
        pg->getHideEndPosition(&x, &y);
5922
        _gTestMode->setResult(intToString(x) + "," + intToString(y));
5923
    }
5924
 
5925
    __success = true;
5926
    setAllDone();
5927
#endif
15 andreas 5928
}
5929
 
5930
/**
5931
 * Set the hide effect time for the specified popup page.
5932
 */
22 andreas 5933
void TPageManager::doPHT(int, vector<int>&, vector<string>& pars)
15 andreas 5934
{
5935
    DECL_TRACER("TPageManager::doPHT(int port, vector<int>& channels, vector<string>& pars)");
5936
 
5937
    if (pars.size() < 2)
5938
    {
5939
        MSG_ERROR("Less than 2 parameters!");
348 andreas 5940
#if TESTMODE == 1
5941
        setAllDone();
5942
#endif
15 andreas 5943
        return;
5944
    }
5945
 
16 andreas 5946
    TError::clear();
96 andreas 5947
    TSubPage *pg = deliverSubPage(pars[0]);
15 andreas 5948
 
5949
    if (!pg)
348 andreas 5950
    {
5951
#if TESTMODE == 1
5952
        setAllDone();
5953
#endif
96 andreas 5954
        return;
348 andreas 5955
    }
15 andreas 5956
 
5957
    pg->setHideTime(atoi(pars[1].c_str()));
348 andreas 5958
#if TESTMODE == 1
5959
    if (_gTestMode)
5960
        _gTestMode->setResult(intToString(pg->getHideTime()));
5961
 
5962
    __success = true;
5963
    setAllDone();
5964
#endif
15 andreas 5965
}
5966
 
5967
/**
14 andreas 5968
 * Close all popups on a specified page. If the page name is empty, the current
5969
 * page is used. Same as the ’Clear Page’ command in TPDesign4.
5970
 */
22 andreas 5971
void TPageManager::doPPA(int, std::vector<int>&, std::vector<std::string>& pars)
11 andreas 5972
{
5973
    DECL_TRACER("TPageManager::doPPA(int port, std::vector<int>& channels, std::vector<std::string>& pars)");
5974
 
16 andreas 5975
    TError::clear();
11 andreas 5976
    TPage *pg;
5977
 
5978
    if (pars.size() == 0)
5979
        pg = getPage(mActualPage);
5980
    else
5981
        pg = getPage(pars[0]);
5982
 
5983
    if (!pg)
348 andreas 5984
    {
5985
#if TESTMODE == 1
5986
        setAllDone();
5987
#endif
11 andreas 5988
        return;
348 andreas 5989
    }
11 andreas 5990
 
12 andreas 5991
    pg->drop();
14 andreas 5992
    pg->resetZOrder();
348 andreas 5993
#if TESTMODE == 1
5994
    setDone();
5995
#endif
11 andreas 5996
}
5997
 
14 andreas 5998
/**
5999
 * Deactivate a specific popup page on either a specified page or the current
6000
 * page. If the page name is empty, the current page is used. If the popup page
6001
 * is part of a group, the whole group is deactivated. This command works in
6002
 * the same way as the ’Hide Popup’ command in TPDesign4.
6003
 */
22 andreas 6004
void TPageManager::doPPF(int, std::vector<int>&, std::vector<std::string>& pars)
12 andreas 6005
{
6006
    DECL_TRACER("TPageManager::doPPF(int port, std::vector<int>& channels, std::vector<std::string>& pars)");
6007
 
6008
    if (pars.size() < 1)
6009
    {
6010
        MSG_ERROR("At least 1 parameter is expected!");
349 andreas 6011
#if TESTMODE == 1
6012
        setAllDone();
6013
#endif
12 andreas 6014
        return;
6015
    }
6016
 
16 andreas 6017
    TError::clear();
14 andreas 6018
    hideSubPage(pars[0]);
335 andreas 6019
#if TESTMODE == 1
6020
    setDone();
6021
#endif
12 andreas 6022
}
6023
 
14 andreas 6024
/**
6025
 * Toggle a specific popup page on either a specified page or the current page.
6026
 * If the page name is empty, the current page is used. Toggling refers to the
6027
 * activating/deactivating (On/Off) of a popup page. This command works in the
6028
 * same way as the ’Toggle Popup’ command in TPDesign4.
6029
 */
22 andreas 6030
void TPageManager::doPPG(int, std::vector<int>&, std::vector<std::string>& pars)
12 andreas 6031
{
6032
    DECL_TRACER("TPageManager::doPPG(int port, std::vector<int>& channels, std::vector<std::string>& pars)");
14 andreas 6033
 
12 andreas 6034
    if (pars.size() < 1)
6035
    {
6036
        MSG_ERROR("At least 1 parameter is expected!");
349 andreas 6037
#if TESTMODE == 1
6038
        setAllDone();
6039
#endif
12 andreas 6040
        return;
6041
    }
6042
 
16 andreas 6043
    TError::clear();
14 andreas 6044
    TPage *page = getPage(mActualPage);
6045
 
6046
    if (!page)
6047
    {
6048
        MSG_ERROR("No active page found! Internal error.");
349 andreas 6049
#if TESTMODE == 1
6050
        setAllDone();
6051
#endif
14 andreas 6052
        return;
6053
    }
6054
 
12 andreas 6055
    TSubPage *pg = getSubPage(pars[0]);
14 andreas 6056
 
12 andreas 6057
    if (!pg)
349 andreas 6058
    {
6059
#if TESTMODE == 1
6060
        setAllDone();
6061
#endif
12 andreas 6062
        return;
349 andreas 6063
    }
14 andreas 6064
 
12 andreas 6065
    if (pg->isVisible())
6066
    {
6067
        pg->drop();
162 andreas 6068
        page->decZOrder();
349 andreas 6069
#if TESTMODE == 1
6070
        setDone();
6071
#endif
12 andreas 6072
        return;
6073
    }
6074
 
6075
    TSubPage *sub = getFirstSubPageGroup(pg->getGroupName());
14 andreas 6076
 
12 andreas 6077
    while(sub)
6078
    {
6079
        if (sub->getGroupName().compare(pg->getGroupName()) == 0 && sub->isVisible())
6080
            sub->drop();
14 andreas 6081
 
12 andreas 6082
        sub = getNextSubPageGroup(pg->getGroupName(), sub);
6083
    }
6084
 
152 andreas 6085
    pg->setZOrder(page->getNextZOrder());
6086
    MSG_DEBUG("Setting new Z-order " << page->getActZOrder() << " on page " << page->getName());
12 andreas 6087
    pg->show();
349 andreas 6088
#if TESTMODE == 1
6089
    setDone();
6090
#endif
12 andreas 6091
}
6092
 
14 andreas 6093
/**
6094
 * Kill refers to the deactivating (Off) of a popup window from all pages. If
6095
 * the pop-up page is part of a group, the whole group is deactivated. This
6096
 * command works in the same way as the 'Clear Group' command in TPDesign 4.
6097
 */
22 andreas 6098
void TPageManager::doPPK(int, std::vector<int>&, std::vector<std::string>& pars)
12 andreas 6099
{
6100
    DECL_TRACER("TPageManager::doPPK(int port, std::vector<int>& channels, std::vector<std::string>& pars)");
14 andreas 6101
 
12 andreas 6102
    if (pars.size() < 1)
6103
    {
6104
        MSG_ERROR("At least 1 parameter is expected!");
349 andreas 6105
#if TESTMODE == 1
6106
        setAllDone();
6107
#endif
12 andreas 6108
        return;
6109
    }
6110
 
16 andreas 6111
    TError::clear();
14 andreas 6112
    TPage *page = getPage(mActualPage);
6113
 
6114
    if (!page)
6115
    {
6116
        MSG_ERROR("No active page found! Internal error.");
349 andreas 6117
#if TESTMODE == 1
6118
        setAllDone();
6119
#endif
14 andreas 6120
        return;
6121
    }
6122
 
12 andreas 6123
    TSubPage *pg = getSubPage(pars[0]);
14 andreas 6124
 
12 andreas 6125
    if (pg)
14 andreas 6126
    {
6127
        pg->drop();
162 andreas 6128
        page->decZOrder();
14 andreas 6129
    }
349 andreas 6130
#if TESTMODE == 1
6131
        setDone();
6132
#endif
12 andreas 6133
}
6134
 
14 andreas 6135
/**
6136
 * Set the modality of a specific popup page to Modal or NonModal.
6137
 * A Modal popup page, when active, only allows you to use the buttons and
6138
 * features on that popup page. All other buttons on the panel page are
6139
 * inactivated.
6140
 */
22 andreas 6141
void TPageManager::doPPM(int, std::vector<int>&, std::vector<std::string>& pars)
12 andreas 6142
{
6143
    DECL_TRACER("TPageManager::doPPM(int port, std::vector<int>& channels, std::vector<std::string>& pars)");
14 andreas 6144
 
12 andreas 6145
    if (pars.size() < 2)
6146
    {
6147
        MSG_ERROR("Expecting 2 parameters!");
349 andreas 6148
#if TESTMODE == 1
6149
        setAllDone();
6150
#endif
12 andreas 6151
        return;
6152
    }
14 andreas 6153
 
16 andreas 6154
    TError::clear();
12 andreas 6155
    TSubPage *pg = getSubPage(pars[0]);
14 andreas 6156
 
12 andreas 6157
    if (pg)
6158
    {
162 andreas 6159
        if (pars[1] == "1" || strCaseCompare(pars[1], "modal") == 0)
12 andreas 6160
            pg->setModal(1);
6161
        else
6162
            pg->setModal(0);
349 andreas 6163
#if TESTMODE == 1
6164
        if (_gTestMode)
6165
            _gTestMode->setResult(pg->isModal() ? "TRUE" : "FALSE");
6166
#endif
12 andreas 6167
    }
349 andreas 6168
#if TESTMODE == 1
6169
        setAllDone();
6170
#endif
12 andreas 6171
}
6172
 
14 andreas 6173
/**
6174
 * Activate a specific popup page to launch on either a specified page or the
6175
 * current page. If the page name is empty, the current page is used. If the
6176
 * popup page is already on, do not re-draw it. This command works in the same
6177
 * way as the ’Show Popup’ command in TPDesign4.
6178
 */
22 andreas 6179
void TPageManager::doPPN(int, std::vector<int>&, std::vector<std::string>& pars)
12 andreas 6180
{
6181
    DECL_TRACER("TPageManager::doPPN(int port, std::vector<int>& channels, std::vector<std::string>& pars)");
6182
 
6183
    if (pars.size() < 1)
6184
    {
6185
        MSG_ERROR("At least 1 parameter is expected!");
349 andreas 6186
#if TESTMODE == 1
6187
        setAllDone();
6188
#endif
12 andreas 6189
        return;
6190
    }
6191
 
16 andreas 6192
    TError::clear();
14 andreas 6193
    showSubPage(pars[0]);
349 andreas 6194
#if TESTMODE == 1
6195
    setDone();
6196
#endif
12 andreas 6197
}
6198
 
14 andreas 6199
/**
15 andreas 6200
 * Set a specific popup page to timeout within a specified time. If timeout is
6201
 * empty, popup page will clear the timeout.
6202
 */
22 andreas 6203
void TPageManager::doPPT(int, vector<int>&, vector<string>& pars)
15 andreas 6204
{
6205
    DECL_TRACER("TPageManager::doPPT(int port, vector<int>& channels, vector<string>& pars)");
6206
 
6207
    if (pars.size() < 2)
6208
    {
6209
        MSG_ERROR("Expecting 2 parameters!");
351 andreas 6210
#if TESTMODE == 1
6211
        setAllDone();
6212
#endif
15 andreas 6213
        return;
6214
    }
6215
 
16 andreas 6216
    TError::clear();
96 andreas 6217
    TSubPage *pg = deliverSubPage(pars[0]);
15 andreas 6218
 
6219
    if (!pg)
351 andreas 6220
    {
6221
#if TESTMODE == 1
6222
        setAllDone();
6223
#endif
96 andreas 6224
        return;
351 andreas 6225
    }
15 andreas 6226
 
6227
    pg->setTimeout(atoi(pars[1].c_str()));
351 andreas 6228
#if TESTMODE == 1
6229
    if (_gTestMode)
6230
        _gTestMode->setResult(intToString(pg->getTimeout()));
6231
 
6232
    __success = true;
6233
    setAllDone();
6234
#endif
15 andreas 6235
}
6236
 
6237
/**
14 andreas 6238
 * Close all popups on all pages. This command works in the same way as the
6239
 * 'Clear All' command in TPDesign 4.
6240
 */
22 andreas 6241
void TPageManager::doPPX(int, std::vector<int>&, std::vector<std::string>&)
12 andreas 6242
{
6243
    DECL_TRACER("TPageManager::doPPX(int port, std::vector<int>& channels, std::vector<std::string>& pars)");
6244
 
16 andreas 6245
    TError::clear();
12 andreas 6246
    PCHAIN_T *chain = mPchain;
14 andreas 6247
 
12 andreas 6248
    while(chain)
6249
    {
6250
        TSubPage *sub = chain->page->getFirstSubPage();
14 andreas 6251
 
12 andreas 6252
        while (sub)
6253
        {
351 andreas 6254
            MSG_DEBUG("Dropping subpage " << sub->getNumber() << ", \"" << sub->getName() << "\".");
12 andreas 6255
            sub->drop();
6256
            sub = chain->page->getNextSubPage();
6257
        }
14 andreas 6258
 
12 andreas 6259
        chain = chain->next;
6260
    }
14 andreas 6261
 
6262
    TPage *page = getPage(mActualPage);
6263
 
6264
    if (!page)
6265
    {
6266
        MSG_ERROR("No active page found! Internal error.");
351 andreas 6267
#if TESTMODE == 1
6268
        setAllDone();
6269
#endif
14 andreas 6270
        return;
6271
    }
6272
 
6273
    page->resetZOrder();
351 andreas 6274
#if TESTMODE == 1
6275
    setDone();
6276
#endif
12 andreas 6277
}
6278
 
14 andreas 6279
/**
15 andreas 6280
 * Set the show effect for the specified popup page to the named show effect.
6281
 */
22 andreas 6282
void TPageManager::doPSE(int, vector<int>&, vector<string>& pars)
15 andreas 6283
{
6284
    DECL_TRACER("TPageManager::doPSE(int port, vector<int>& channels, vector<string>& pars)");
6285
 
6286
    if (pars.size() < 2)
6287
    {
6288
        MSG_ERROR("Less than 2 parameters!");
351 andreas 6289
#if TESTMODE == 1
6290
        setAllDone();
6291
#endif
15 andreas 6292
        return;
6293
    }
6294
 
16 andreas 6295
    TError::clear();
96 andreas 6296
    TSubPage *pg = deliverSubPage(pars[0]);
15 andreas 6297
 
6298
    if (!pg)
351 andreas 6299
    {
6300
#if TESTMODE == 1
6301
        setAllDone();
6302
#endif
96 andreas 6303
        return;
351 andreas 6304
    }
15 andreas 6305
 
162 andreas 6306
    if (strCaseCompare(pars[1], "fade") == 0)
15 andreas 6307
        pg->setShowEffect(SE_FADE);
162 andreas 6308
    else if (strCaseCompare(pars[1], "slide to left") == 0)
15 andreas 6309
        pg->setShowEffect(SE_SLIDE_LEFT);
162 andreas 6310
    else if (strCaseCompare(pars[1], "slide to right") == 0)
15 andreas 6311
        pg->setShowEffect(SE_SLIDE_RIGHT);
162 andreas 6312
    else if (strCaseCompare(pars[1], "slide to top") == 0)
15 andreas 6313
        pg->setShowEffect(SE_SLIDE_TOP);
162 andreas 6314
    else if (strCaseCompare(pars[1], "slide to bottom") == 0)
15 andreas 6315
        pg->setShowEffect(SE_SLIDE_BOTTOM);
162 andreas 6316
    else if (strCaseCompare(pars[1], "slide to left fade") == 0)
15 andreas 6317
        pg->setShowEffect(SE_SLIDE_LEFT_FADE);
162 andreas 6318
    else if (strCaseCompare(pars[1], "slide to right fade") == 0)
15 andreas 6319
        pg->setShowEffect(SE_SLIDE_RIGHT_FADE);
162 andreas 6320
    else if (strCaseCompare(pars[1], "slide to top fade") == 0)
15 andreas 6321
        pg->setShowEffect(SE_SLIDE_TOP_FADE);
162 andreas 6322
    else if (strCaseCompare(pars[1], "slide to bottom fade") == 0)
15 andreas 6323
        pg->setShowEffect(SE_SLIDE_BOTTOM_FADE);
6324
    else
6325
        pg->setShowEffect(SE_NONE);
351 andreas 6326
#if TESTMODE == 1
6327
    if (_gTestMode)
6328
        _gTestMode->setResult(intToString(pg->getShowEffect()));
6329
 
6330
    __success = true;
6331
    setAllDone();
6332
#endif
15 andreas 6333
}
6334
 
162 andreas 6335
/**
6336
 * Set the show effect position. Only 1 coordinate is ever needed for an effect;
6337
 * however, the command will specify both. This command sets the location at
6338
 * which the effect will begin.
6339
 */
22 andreas 6340
void TPageManager::doPSP(int, vector<int>&, vector<string>& pars)
15 andreas 6341
{
6342
    DECL_TRACER("TPageManager::doPSP(int port, vector<int>& channels, vector<string>& pars)");
6343
 
6344
    if (pars.size() < 2)
6345
    {
6346
        MSG_ERROR("Less than 2 parameters!");
351 andreas 6347
#if TESTMODE == 1
6348
        setAllDone();
6349
#endif
15 andreas 6350
        return;
6351
    }
6352
 
16 andreas 6353
    TError::clear();
15 andreas 6354
    size_t pos = pars[1].find(",");
6355
    int x, y;
6356
 
6357
    if (pos == string::npos)
6358
    {
6359
        x = atoi(pars[1].c_str());
6360
        y = 0;
6361
    }
6362
    else
6363
    {
6364
        x = atoi(pars[1].substr(0, pos).c_str());
6365
        y = atoi(pars[1].substr(pos+1).c_str());
6366
    }
6367
 
96 andreas 6368
    TSubPage *pg = deliverSubPage(pars[0]);
15 andreas 6369
 
6370
    if (!pg)
351 andreas 6371
    {
6372
#if TESTMODE == 1
6373
        setAllDone();
6374
#endif
96 andreas 6375
        return;
351 andreas 6376
    }
15 andreas 6377
 
6378
    pg->setShowEndPosition(x, y);
351 andreas 6379
#if TESTMODE == 1
6380
    pg->getShowEndPosition(&x, &y);
6381
 
6382
    if (_gTestMode)
6383
        _gTestMode->setResult(intToString(x) + "," + intToString(y));
6384
 
6385
    __success = true;
6386
    setAllDone();
6387
#endif
15 andreas 6388
}
6389
 
6390
/**
6391
 * Set the show effect time for the specified popup page.
6392
 */
22 andreas 6393
void TPageManager::doPST(int, vector<int>&, vector<string>& pars)
15 andreas 6394
{
6395
    DECL_TRACER("TPageManager::doPST(int port, vector<int>& channels, vector<string>& pars)");
6396
 
6397
    if (pars.size() < 2)
6398
    {
6399
        MSG_ERROR("Less than 2 parameters!");
351 andreas 6400
#if TESTMODE == 1
6401
        setAllDone();
6402
#endif
15 andreas 6403
        return;
6404
    }
6405
 
16 andreas 6406
    TError::clear();
96 andreas 6407
    TSubPage *pg = deliverSubPage(pars[0]);
15 andreas 6408
 
6409
    if (!pg)
351 andreas 6410
    {
6411
#if TESTMODE == 1
6412
        setAllDone();
6413
#endif
96 andreas 6414
        return;
351 andreas 6415
    }
15 andreas 6416
 
6417
    pg->setShowTime(atoi(pars[1].c_str()));
351 andreas 6418
#if TESTMODE == 1
6419
    if (_gTestMode)
6420
        _gTestMode->setResult(intToString(pg->getShowTime()));
6421
 
6422
    __success = 1;
6423
    setAllDone();
6424
#endif
15 andreas 6425
}
6426
 
6427
/**
14 andreas 6428
 * Flips to a page with a specified page name. If the page is currently active,
6429
 * it will not redraw the page.
6430
 */
22 andreas 6431
void TPageManager::doPAGE(int, std::vector<int>&, std::vector<std::string>& pars)
12 andreas 6432
{
6433
    DECL_TRACER("TPageManager::doPAGE(int port, std::vector<int>& channels, std::vector<std::string>& pars)");
14 andreas 6434
 
15 andreas 6435
    if (pars.empty())
6436
    {
6437
        MSG_WARNING("Got no page parameter!");
351 andreas 6438
#if TESTMODE == 1
6439
        setAllDone();
6440
#endif
15 andreas 6441
        return;
6442
    }
14 andreas 6443
 
16 andreas 6444
    TError::clear();
15 andreas 6445
    setPage(pars[0]);
351 andreas 6446
#if TESTMODE == 1
6447
    if (_gTestMode)
6448
        _gTestMode->setResult(intToString(getActualPageNumber()));
6449
 
6450
    setDone();
6451
#endif
15 andreas 6452
}
6453
 
6454
/**
38 andreas 6455
 * @brief TPageManager::doANI Run a button animation (in 1/10 second).
6456
 * Syntax:
6457
 *      ^ANI-<vt addr range>,<start state>,<end state>,<time>
6458
 * Variable:
6459
 *      variable text address range = 1 - 4000.
6460
 *      start state = Beginning of button state (0= current state).
6461
 *      end state = End of button state.
6462
 *      time = In 1/10 second intervals.
6463
 * Example:
6464
 *      SEND_COMMAND Panel,"'^ANI-500,1,25,100'"
6465
 * Runs a button animation at text range 500 from state 1 to state 25 for 10 seconds.
6466
 *
6467
 * @param port      The port number
6468
 * @param channels  The channels of the buttons
6469
 * @param pars      The parameters
6470
 */
6471
void TPageManager::doANI(int port, std::vector<int> &channels, std::vector<std::string> &pars)
6472
{
6473
    DECL_TRACER("TPageManager::doANI(int port, std::vector<int> &channels, std::vector<std::string> &pars)");
6474
 
6475
    if (pars.size() < 3)
6476
    {
6477
        MSG_ERROR("Expecting 3 parameters but got " << pars.size() << "! Ignoring command.");
6478
        return;
6479
    }
6480
 
6481
    TError::clear();
6482
    int stateStart = atoi(pars[0].c_str());
6483
    int endState = atoi(pars[1].c_str());
6484
    int runTime = atoi(pars[2].c_str());
6485
 
193 andreas 6486
    vector<TMap::MAP_T> map = findButtons(port, channels);
38 andreas 6487
 
6488
    if (TError::isError() || map.empty())
6489
        return;
6490
 
6491
    vector<Button::TButton *> buttons = collectButtons(map);
6492
 
83 andreas 6493
    if (buttons.size() > 0)
38 andreas 6494
    {
83 andreas 6495
        vector<Button::TButton *>::iterator mapIter;
6496
 
6497
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
6498
        {
6499
            Button::TButton *bt = *mapIter;
6500
            bt->startAnimation(stateStart, endState, runTime);
6501
        }
38 andreas 6502
    }
351 andreas 6503
#if TESTMODE == 1
6504
    if (_gTestMode)
6505
        _gTestMode->setResult(intToString(stateStart) + "," + intToString(endState) + "," + intToString(runTime));
6506
 
6507
    setDone();
6508
#endif
38 andreas 6509
}
6510
 
6511
/**
15 andreas 6512
 * Add page flip action to a button if it does not already exist.
6513
 */
6514
void TPageManager::doAPF(int port, vector<int>& channels, vector<string>& pars)
6515
{
6516
    DECL_TRACER("TPageManager::doAPF(int port, vector<int>& channels, vector<string>& pars)");
6517
 
6518
    if (pars.size() < 2)
6519
    {
6520
        MSG_ERROR("Expecting 2 parameters but got " << pars.size() << "! Ignoring command.");
351 andreas 6521
#if TESTMODE == 1
6522
        setAllDone();
6523
#endif
14 andreas 6524
        return;
15 andreas 6525
    }
14 andreas 6526
 
16 andreas 6527
    TError::clear();
15 andreas 6528
    string action = pars[0];
6529
    string pname = pars[1];
14 andreas 6530
 
193 andreas 6531
    vector<TMap::MAP_T> map = findButtons(port, channels);
14 andreas 6532
 
15 andreas 6533
    if (TError::isError() || map.empty())
351 andreas 6534
    {
6535
#if TESTMODE == 1
6536
        setAllDone();
6537
#endif
15 andreas 6538
        return;
351 andreas 6539
    }
15 andreas 6540
 
6541
    vector<Button::TButton *> buttons = collectButtons(map);
6542
 
83 andreas 6543
    if (buttons.size() > 0)
12 andreas 6544
    {
83 andreas 6545
        vector<Button::TButton *>::iterator mapIter;
6546
 
6547
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
6548
        {
6549
            Button::TButton *bt = *mapIter;
6550
            bt->addPushFunction(action, pname);
6551
        }
15 andreas 6552
    }
351 andreas 6553
#if TESTMODE == 1
6554
    if (_gTestMode)
6555
        _gTestMode->setResult(toUpper(action) + "," + toUpper(pname));
6556
 
6557
    __success = true;
6558
    setAllDone();
6559
#endif
15 andreas 6560
}
12 andreas 6561
 
15 andreas 6562
/**
43 andreas 6563
 * Append non-unicode text.
6564
 */
6565
void TPageManager::doBAT(int port, vector<int> &channels, vector<string> &pars)
6566
{
6567
    DECL_TRACER("TPageManager::doBAT(int port, vector<int> &channels, vector<string> &pars)");
6568
 
6569
    if (pars.size() < 1)
6570
    {
6571
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
330 andreas 6572
#if TESTMODE == 1
334 andreas 6573
        setAllDone();
330 andreas 6574
#endif
43 andreas 6575
        return;
6576
    }
6577
 
6578
    TError::clear();
6579
    int btState = atoi(pars[0].c_str());
6580
    string text;
6581
 
6582
    if (pars.size() > 1)
6583
        text = pars[1];
6584
 
193 andreas 6585
    vector<TMap::MAP_T> map = findButtons(port, channels);
43 andreas 6586
 
6587
    if (TError::isError() || map.empty())
330 andreas 6588
    {
6589
#if TESTMODE == 1
334 andreas 6590
        setAllDone();
330 andreas 6591
#endif
43 andreas 6592
        return;
330 andreas 6593
    }
43 andreas 6594
 
6595
    vector<Button::TButton *> buttons = collectButtons(map);
6596
 
162 andreas 6597
    if (buttons.empty())
330 andreas 6598
    {
6599
#if TESTMODE == 1
334 andreas 6600
        setAllDone();
330 andreas 6601
#endif
162 andreas 6602
        return;
330 andreas 6603
    }
162 andreas 6604
 
6605
    vector<Button::TButton *>::iterator mapIter;
6606
 
6607
    for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
43 andreas 6608
    {
162 andreas 6609
        Button::TButton *bt = *mapIter;
43 andreas 6610
 
331 andreas 6611
        bt->appendText(text, btState - 1);
330 andreas 6612
#if TESTMODE == 1
331 andreas 6613
        if (_gTestMode)
330 andreas 6614
        {
331 andreas 6615
            int st = (btState > 0 ? (btState - 1) : 0);
6616
            _gTestMode->setResult(bt->getText(st));
333 andreas 6617
        }
330 andreas 6618
 
331 andreas 6619
        __success = true;
330 andreas 6620
#endif
43 andreas 6621
    }
334 andreas 6622
#if TESTMODE == 1
6623
    setDone();
6624
#endif
43 andreas 6625
}
6626
 
6627
/**
60 andreas 6628
 * @brief Append unicode text. Same format as ^UNI.
6629
 * This command allows to set up to 50 characters of ASCII code. The unicode
6630
 * characters must be set as hex numbers.
6631
 */
6632
void TPageManager::doBAU(int port, vector<int>& channels, vector<string>& pars)
6633
{
6634
    DECL_TRACER("TPageManager::doBAU(int port, vector<int>& channels, vector<string>& pars)");
6635
 
6636
    if (pars.size() < 1)
6637
    {
6638
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
351 andreas 6639
#if TESTMODE == 1
6640
        setAllDone();
6641
#endif
60 andreas 6642
        return;
6643
    }
6644
 
6645
    TError::clear();
6646
    int btState = atoi(pars[0].c_str());
6647
    string text;
6648
    char ch[3];
6649
 
331 andreas 6650
    if (pars.size() > 1)
6651
        text = pars[1];
6652
 
6653
    if ((text.size() % 4) == 0)
60 andreas 6654
    {
162 andreas 6655
        try
60 andreas 6656
        {
162 andreas 6657
            text = pars[1];
331 andreas 6658
            MSG_DEBUG("Processing UTF16 string: " << text);
162 andreas 6659
            // Because the unicode characters are hex numbers, we scan the text
6660
            // and convert the hex numbers into real numbers.
6661
            size_t len = text.length();
6662
            bool inHex = false;
6663
            int lastChar = 0;
331 andreas 6664
            uint16_t *numstr = new uint16_t[len / 4];
162 andreas 6665
            int uniPos = 0;
331 andreas 6666
            int cntCount = 0;
60 andreas 6667
 
162 andreas 6668
            for (size_t i = 0; i < len; i++)
60 andreas 6669
            {
162 andreas 6670
                int c = text.at(i);
60 andreas 6671
 
162 andreas 6672
                if (!inHex && isHex(c))
6673
                {
6674
                    inHex = true;
6675
                    lastChar = c;
6676
                    continue;
6677
                }
6678
 
6679
                if (inHex && !isHex(c))
6680
                    break;
6681
 
6682
                if (inHex && isHex(c))
6683
                {
6684
                    ch[0] = lastChar;
6685
                    ch[1] = c;
6686
                    ch[2] = 0;
6687
                    uint16_t num = (uint16_t)strtol(ch, NULL, 16);
331 andreas 6688
 
6689
                    if ((cntCount % 2) != 0)
6690
                    {
6691
                        numstr[uniPos] |= num;
6692
                        uniPos++;
6693
                    }
6694
                    else
6695
                        numstr[uniPos] = (num << 8) & 0xff00;
6696
 
6697
                    cntCount++;
162 andreas 6698
                    inHex = false;
6699
 
6700
                    if (uniPos >= 50)
6701
                        break;
331 andreas 6702
                }
6703
            }
162 andreas 6704
 
331 andreas 6705
            text.clear();
6706
            // Here we make from the real numbers a UTF8 string
6707
            for (size_t i = 0; i < len / 4; ++i)
6708
            {
6709
                if (numstr[i] <= 0x00ff)
6710
                {
6711
                    ch[0] = numstr[i];
6712
                    ch[1] = 0;
6713
                    text.append(ch);
162 andreas 6714
                }
331 andreas 6715
                else
6716
                {
6717
                    ch[0] = (numstr[i] >> 8) & 0x00ff;
6718
                    ch[1] = numstr[i] & 0x00ff;
6719
                    ch[2] = 0;
6720
                    text.append(ch);
6721
                }
60 andreas 6722
            }
6723
 
331 andreas 6724
            delete[] numstr;
60 andreas 6725
        }
162 andreas 6726
        catch (std::exception const & e)
6727
        {
6728
            MSG_ERROR("Character conversion error: " << e.what());
351 andreas 6729
#if TESTMODE == 1
6730
            setAllDone();
6731
#endif
162 andreas 6732
            return;
6733
        }
60 andreas 6734
    }
331 andreas 6735
    else
6736
    {
6737
        MSG_WARNING("No or invalid UTF16 string: " << text);
351 andreas 6738
#if TESTMODE == 1
6739
        setAllDone();
6740
#endif
331 andreas 6741
        return;
6742
    }
60 andreas 6743
 
193 andreas 6744
    vector<TMap::MAP_T> map = findButtons(port, channels);
60 andreas 6745
 
6746
    if (TError::isError() || map.empty())
351 andreas 6747
    {
6748
#if TESTMODE == 1
6749
        setAllDone();
6750
#endif
60 andreas 6751
        return;
351 andreas 6752
    }
60 andreas 6753
 
6754
    vector<Button::TButton *> buttons = collectButtons(map);
6755
 
83 andreas 6756
    if (buttons.size() > 0)
60 andreas 6757
    {
83 andreas 6758
        vector<Button::TButton *>::iterator mapIter;
60 andreas 6759
 
83 andreas 6760
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
60 andreas 6761
        {
83 andreas 6762
            Button::TButton *bt = *mapIter;
60 andreas 6763
 
331 andreas 6764
            bt->appendText(text, btState - 1);
330 andreas 6765
#if TESTMODE == 1
331 andreas 6766
            if (_gTestMode)
6767
                _gTestMode->setResult(bt->getText(btState - 1));
330 andreas 6768
 
331 andreas 6769
            __success = true;
330 andreas 6770
#endif
60 andreas 6771
        }
6772
    }
330 andreas 6773
#if TESTMODE == 1
334 andreas 6774
    setDone();
330 andreas 6775
#endif
60 andreas 6776
}
6777
 
6778
/**
43 andreas 6779
 * @brief TPageManager::doBCB Set the border color.
6780
 * Set the border color to the specified color. Only if the specified border
6781
 * color is not the same as the current color.
6782
 * Note: Color can be assigned by color name (without spaces), number or
6783
 * R,G,B value (RRGGBB or RRGGBBAA).
6784
 */
6785
void TPageManager::doBCB(int port, vector<int> &channels, vector<string> &pars)
6786
{
6787
    DECL_TRACER("TPageManager::doBCB(int port, vector<int> &channels, vector<string> &pars)");
6788
 
6789
    if (pars.size() < 1)
6790
    {
6791
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
351 andreas 6792
#if TESTMODE == 1
6793
        setAllDone();
6794
#endif
43 andreas 6795
        return;
6796
    }
6797
 
6798
    TError::clear();
6799
    int btState = atoi(pars[0].c_str());
6800
    string color;
6801
 
6802
    if (pars.size() > 1)
6803
        color = pars[1];
6804
 
193 andreas 6805
    vector<TMap::MAP_T> map = findButtons(port, channels);
43 andreas 6806
 
6807
    if (TError::isError() || map.empty())
351 andreas 6808
    {
6809
#if TESTMODE == 1
6810
        setAllDone();
6811
#endif
43 andreas 6812
        return;
351 andreas 6813
    }
43 andreas 6814
 
6815
    vector<Button::TButton *> buttons = collectButtons(map);
6816
 
83 andreas 6817
    if (buttons.size() > 0)
43 andreas 6818
    {
83 andreas 6819
        vector<Button::TButton *>::iterator mapIter;
43 andreas 6820
 
83 andreas 6821
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
43 andreas 6822
        {
83 andreas 6823
            Button::TButton *bt = *mapIter;
351 andreas 6824
            bt->setBorderColor(color, btState - 1);
6825
#if TESTMODE == 1
6826
            if (_gTestMode)
6827
                _gTestMode->setResult(bt->getBorderColor(btState == 0 ? 0 : btState - 1));
6828
#endif
43 andreas 6829
        }
6830
    }
351 andreas 6831
#if TESTMODE == 1
6832
    setDone();
6833
#endif
43 andreas 6834
}
60 andreas 6835
 
351 andreas 6836
/*
6837
 * Get the border color and send it as a custom event.
6838
 */
82 andreas 6839
void TPageManager::getBCB(int port, vector<int> &channels, vector<string> &pars)
6840
{
6841
    DECL_TRACER("TPageManager::getBCB(int port, vector<int> &channels, vector<string> &pars)");
6842
 
6843
    if (pars.size() < 1)
6844
    {
6845
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
351 andreas 6846
#if TESTMODE == 1
6847
        setAllDone();
6848
#endif
82 andreas 6849
        return;
6850
    }
6851
 
6852
    TError::clear();
6853
    int btState = atoi(pars[0].c_str());
6854
    string color;
6855
 
193 andreas 6856
    vector<TMap::MAP_T> map = findButtons(port, channels);
82 andreas 6857
 
6858
    if (TError::isError() || map.empty())
351 andreas 6859
    {
6860
#if TESTMODE == 1
6861
        setAllDone();
6862
#endif
82 andreas 6863
        return;
351 andreas 6864
    }
82 andreas 6865
 
6866
    vector<Button::TButton *> buttons = collectButtons(map);
6867
 
351 andreas 6868
    if (buttons.empty())
82 andreas 6869
    {
351 andreas 6870
#if TESTMODE == 1
6871
        setAllDone();
6872
#endif
6873
        return;
6874
    }
82 andreas 6875
 
351 andreas 6876
    vector<Button::TButton *>::iterator iter;
6877
 
6878
    for (iter = buttons.begin(); iter != buttons.end(); ++iter)
6879
    {
6880
        Button::TButton *bt = *iter;
6881
 
110 andreas 6882
        if (btState == 0)       // All instances?
82 andreas 6883
        {
110 andreas 6884
            int bst = bt->getNumberInstances();
82 andreas 6885
 
110 andreas 6886
            for (int i = 0; i < bst; i++)
82 andreas 6887
            {
110 andreas 6888
                color = bt->getBorderColor(i);
82 andreas 6889
 
110 andreas 6890
                if (color.empty())
6891
                    continue;
83 andreas 6892
 
300 andreas 6893
                sendCustomEvent(i + 1, (int)color.length(), 0, color, 1011, bt->getChannelPort(), bt->getChannelNumber());
351 andreas 6894
#if TESTMODE == 1
6895
                __success = true;
6896
 
6897
                if (_gTestMode)
6898
                    _gTestMode->setResult(color);
6899
#endif
83 andreas 6900
            }
110 andreas 6901
        }
6902
        else
6903
        {
6904
            color = bt->getBorderColor(btState - 1);
83 andreas 6905
 
110 andreas 6906
            if (color.empty())
351 andreas 6907
                continue;
82 andreas 6908
 
300 andreas 6909
            sendCustomEvent(btState, (int)color.length(), 0, color, 1011, bt->getChannelPort(), bt->getChannelNumber());
351 andreas 6910
#if TESTMODE == 1
6911
            __success = true;
6912
 
6913
            if (_gTestMode)
6914
                _gTestMode->setResult(color);
6915
#endif
82 andreas 6916
        }
6917
    }
351 andreas 6918
#if TESTMODE == 1
6919
    setAllDone();
6920
#endif
82 andreas 6921
}
6922
 
43 andreas 6923
/**
60 andreas 6924
 * @brief Set the fill color to the specified color.
6925
 * Only if the specified fill color is not the same as the current color.
6926
 * Note: Color can be assigned by color name (without spaces), number or R,G,B value (RRGGBB or RRGGBBAA).
15 andreas 6927
 */
60 andreas 6928
void TPageManager::doBCF(int port, vector<int>& channels, vector<std::string>& pars)
15 andreas 6929
{
60 andreas 6930
    DECL_TRACER("TPageManager::doBCF(int port, vector<int>& channels, vector<std::string>& pars)");
15 andreas 6931
 
60 andreas 6932
    if (pars.size() < 1)
15 andreas 6933
    {
60 andreas 6934
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
351 andreas 6935
#if TESTMODE == 1
6936
        setAllDone();
6937
#endif
12 andreas 6938
        return;
6939
    }
14 andreas 6940
 
16 andreas 6941
    TError::clear();
15 andreas 6942
    int btState = atoi(pars[0].c_str());
60 andreas 6943
    string color;
14 andreas 6944
 
60 andreas 6945
    if (pars.size() > 1)
6946
        color = pars[1];
6947
 
193 andreas 6948
    vector<TMap::MAP_T> map = findButtons(port, channels);
15 andreas 6949
 
6950
    if (TError::isError() || map.empty())
351 andreas 6951
    {
6952
#if TESTMODE == 1
6953
        setAllDone();
6954
#endif
15 andreas 6955
        return;
351 andreas 6956
    }
15 andreas 6957
 
6958
    vector<Button::TButton *> buttons = collectButtons(map);
6959
 
83 andreas 6960
    if (buttons.size() > 0)
15 andreas 6961
    {
83 andreas 6962
        vector<Button::TButton *>::iterator mapIter;
15 andreas 6963
 
83 andreas 6964
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
15 andreas 6965
        {
83 andreas 6966
            Button::TButton *bt = *mapIter;
351 andreas 6967
            bt->setFillColor(color, btState - 1);
6968
#if TESTMODE == 1
6969
            if (_gTestMode)
6970
                _gTestMode->setResult(bt->getFillColor(btState == 0 ? 0 : btState - 1));
6971
#endif
15 andreas 6972
        }
6973
    }
351 andreas 6974
#if TESTMODE == 1
6975
    setDone();
6976
#endif
12 andreas 6977
}
6978
 
351 andreas 6979
/*
6980
 * Get the fill color and send it via a custom event to the NetLinx.
6981
 */
82 andreas 6982
void TPageManager::getBCF(int port, vector<int> &channels, vector<string> &pars)
6983
{
6984
    DECL_TRACER("TPageManager::getBCF(int port, vector<int> &channels, vector<string> &pars)");
6985
 
6986
    if (pars.size() < 1)
6987
    {
6988
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
351 andreas 6989
#if TESTMODE == 1
6990
        setAllDone();
6991
#endif
82 andreas 6992
        return;
6993
    }
6994
 
6995
    TError::clear();
6996
    int btState = atoi(pars[0].c_str());
6997
    string color;
6998
 
193 andreas 6999
    vector<TMap::MAP_T> map = findButtons(port, channels);
82 andreas 7000
 
7001
    if (TError::isError() || map.empty())
351 andreas 7002
    {
7003
#if TESTMODE == 1
7004
        setAllDone();
7005
#endif
82 andreas 7006
        return;
351 andreas 7007
    }
82 andreas 7008
 
7009
    vector<Button::TButton *> buttons = collectButtons(map);
7010
 
351 andreas 7011
    if (buttons.empty())
82 andreas 7012
    {
351 andreas 7013
#if TESTMODE == 1
7014
        setAllDone();
7015
#endif
7016
        return;
7017
    }
82 andreas 7018
 
351 andreas 7019
    vector<Button::TButton *>::iterator iter;
7020
 
7021
    for (iter = buttons.begin(); iter != buttons.end(); ++iter)
7022
    {
7023
        Button::TButton *bt = *iter;
7024
 
110 andreas 7025
        if (btState == 0)       // All instances?
82 andreas 7026
        {
110 andreas 7027
            int bst = bt->getNumberInstances();
82 andreas 7028
 
110 andreas 7029
            for (int i = 0; i < bst; i++)
82 andreas 7030
            {
110 andreas 7031
                color = bt->getFillColor(i);
82 andreas 7032
 
110 andreas 7033
                if (color.empty())
7034
                    continue;
82 andreas 7035
 
300 andreas 7036
                sendCustomEvent(i + 1, (int)color.length(), 0, color, 1012, bt->getChannelPort(), bt->getChannelNumber());
351 andreas 7037
#if TESTMODE == 1
7038
                __success = true;
7039
 
7040
                if (_gTestMode)
7041
                    _gTestMode->setResult(color);
7042
#endif
83 andreas 7043
            }
82 andreas 7044
        }
110 andreas 7045
        else
7046
        {
7047
            color = bt->getFillColor(btState-1);
351 andreas 7048
 
7049
            if (color.empty())
7050
                continue;
7051
 
300 andreas 7052
            sendCustomEvent(btState, (int)color.length(), 0, color, 1012, bt->getChannelPort(), bt->getChannelNumber());
351 andreas 7053
#if TESTMODE == 1
7054
            __success = true;
7055
 
7056
            if (_gTestMode)
7057
                _gTestMode->setResult(color);
7058
#endif
110 andreas 7059
        }
82 andreas 7060
    }
351 andreas 7061
#if TESTMODE == 1
7062
    setAllDone();
7063
#endif
82 andreas 7064
}
7065
 
60 andreas 7066
/**
7067
 * @brief Set the text color to the specified color.
7068
 * Only if the specified text color is not the same as the current color.
7069
 * Note: Color can be assigned by color name (without spaces), number or R,G,B value (RRGGBB or RRGGBBAA).
7070
 */
7071
void TPageManager::doBCT(int port, vector<int>& channels, vector<string>& pars)
18 andreas 7072
{
60 andreas 7073
    DECL_TRACER("TPageManager::doBCT(int port, vector<int>& channels, vector<string>& pars)");
7074
 
7075
    if (pars.size() < 1)
7076
    {
7077
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
351 andreas 7078
#if TESTMODE == 1
7079
        setAllDone();
7080
#endif
60 andreas 7081
        return;
7082
    }
7083
 
7084
    TError::clear();
7085
    int btState = atoi(pars[0].c_str());
7086
    string color;
7087
 
7088
    if (pars.size() > 1)
7089
        color = pars[1];
7090
 
193 andreas 7091
    vector<TMap::MAP_T> map = findButtons(port, channels);
60 andreas 7092
 
7093
    if (TError::isError() || map.empty())
351 andreas 7094
    {
7095
#if TESTMODE == 1
7096
        setAllDone();
7097
#endif
60 andreas 7098
        return;
351 andreas 7099
    }
60 andreas 7100
 
7101
    vector<Button::TButton *> buttons = collectButtons(map);
7102
 
83 andreas 7103
    if (buttons.size() > 0)
60 andreas 7104
    {
83 andreas 7105
        vector<Button::TButton *>::iterator mapIter;
60 andreas 7106
 
83 andreas 7107
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
60 andreas 7108
        {
83 andreas 7109
            Button::TButton *bt = *mapIter;
351 andreas 7110
            bt->setTextColor(color, btState - 1);
7111
#if TESTMODE == 1
7112
            if (_gTestMode)
7113
                _gTestMode->setResult(bt->getTextColor(btState == 0 ? 0 : btState - 1));
7114
#endif
60 andreas 7115
        }
7116
    }
351 andreas 7117
#if TESTMODE == 1
7118
    setDone();
7119
#endif
18 andreas 7120
}
7121
 
351 andreas 7122
/*
7123
 * Get the text color of a button and send it via a custom event to the NetLinx.
7124
 */
82 andreas 7125
void TPageManager::getBCT(int port, vector<int> &channels, vector<string> &pars)
7126
{
7127
    DECL_TRACER("TPageManager::getBCT(int port, vector<int> &channels, vector<string> &pars)");
7128
 
7129
    if (pars.size() < 1)
7130
    {
7131
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
351 andreas 7132
#if TESTMODE == 1
7133
        setAllDone();
7134
#endif
82 andreas 7135
        return;
7136
    }
7137
 
7138
    TError::clear();
7139
    int btState = atoi(pars[0].c_str());
7140
    string color;
7141
 
193 andreas 7142
    vector<TMap::MAP_T> map = findButtons(port, channels);
82 andreas 7143
 
7144
    if (TError::isError() || map.empty())
351 andreas 7145
    {
7146
#if TESTMODE == 1
7147
        setAllDone();
7148
#endif
82 andreas 7149
        return;
351 andreas 7150
    }
82 andreas 7151
 
7152
    vector<Button::TButton *> buttons = collectButtons(map);
7153
 
351 andreas 7154
    if (buttons.empty())
82 andreas 7155
    {
351 andreas 7156
#if TESTMODE == 1
7157
        setAllDone();
7158
#endif
7159
        return;
7160
    }
82 andreas 7161
 
351 andreas 7162
    vector<Button::TButton *>::iterator iter;
7163
 
7164
    for (iter = buttons.begin(); iter != buttons.end(); ++iter)
7165
    {
7166
        Button::TButton *bt = *iter;
7167
 
110 andreas 7168
        if (btState == 0)       // All instances?
82 andreas 7169
        {
110 andreas 7170
            int bst = bt->getNumberInstances();
82 andreas 7171
 
110 andreas 7172
            for (int i = 0; i < bst; i++)
82 andreas 7173
            {
110 andreas 7174
                color = bt->getTextColor(i);
82 andreas 7175
 
110 andreas 7176
                if (color.empty())
7177
                    continue;
82 andreas 7178
 
300 andreas 7179
                sendCustomEvent(i + 1, (int)color.length(), 0, color, 1013, bt->getChannelPort(), bt->getChannelNumber());
351 andreas 7180
#if TESTMODE == 1
7181
                __success = true;
7182
 
7183
                if (_gTestMode)
7184
                    _gTestMode->setResult(color);
7185
#endif
83 andreas 7186
            }
82 andreas 7187
        }
110 andreas 7188
        else
7189
        {
7190
            color = bt->getTextColor(btState - 1);
351 andreas 7191
 
7192
            if (color.empty())
7193
                continue;
7194
 
300 andreas 7195
            sendCustomEvent(btState, (int)color.length(), 0, color, 1013, bt->getChannelPort(), bt->getChannelNumber());
351 andreas 7196
#if TESTMODE == 1
7197
            __success = true;
7198
 
7199
            if (_gTestMode)
7200
                _gTestMode->setResult(color);
7201
#endif
110 andreas 7202
        }
82 andreas 7203
    }
351 andreas 7204
#if TESTMODE == 1
7205
    setAllDone();
7206
#endif
82 andreas 7207
}
7208
 
60 andreas 7209
/**
7210
 * Set the button draw order
7211
 * Determines what order each layer of the button is drawn.
7212
 */
7213
void TPageManager::doBDO(int port, vector<int>& channels, vector<std::string>& pars)
32 andreas 7214
{
60 andreas 7215
    DECL_TRACER("TPageManager::doBDO(int port, vector<int>& channels, vector<std::string>& pars)");
32 andreas 7216
 
60 andreas 7217
    if (pars.size() < 1)
7218
    {
7219
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
351 andreas 7220
#if TESTMODE == 1
7221
        setAllDone();
7222
#endif
32 andreas 7223
        return;
60 andreas 7224
    }
32 andreas 7225
 
60 andreas 7226
    TError::clear();
7227
    int btState = atoi(pars[0].c_str());
7228
    string order;
32 andreas 7229
 
60 andreas 7230
    if (pars.size() > 1)
7231
    {
7232
        string ord = pars[1];
7233
        // Convert the numbers into the expected draw order
7234
        for (size_t i = 0; i < ord.length(); i++)
7235
        {
7236
            if (ord.at(i) >= '1' && ord.at(i) <= '5')
7237
            {
7238
                char hv0[32];
7239
                snprintf(hv0, sizeof(hv0), "%02d", (int)(ord.at(i) - '0'));
7240
                order.append(hv0);
7241
            }
7242
            else
7243
            {
7244
                MSG_ERROR("Illegal order number " << ord.substr(i, 1) << "!");
7245
                return;
7246
            }
7247
        }
7248
 
7249
        if (order.length() != 10)
7250
        {
7251
            MSG_ERROR("Expected 5 order numbers but got " << (order.length() / 2)<< "!");
7252
            return;
7253
        }
7254
    }
7255
 
193 andreas 7256
    vector<TMap::MAP_T> map = findButtons(port, channels);
60 andreas 7257
 
7258
    if (TError::isError() || map.empty())
351 andreas 7259
    {
7260
#if TESTMODE == 1
7261
        setAllDone();
7262
#endif
32 andreas 7263
        return;
351 andreas 7264
    }
32 andreas 7265
 
60 andreas 7266
    vector<Button::TButton *> buttons = collectButtons(map);
7267
 
83 andreas 7268
    if (buttons.size() > 0)
32 andreas 7269
    {
83 andreas 7270
        vector<Button::TButton *>::iterator mapIter;
32 andreas 7271
 
83 andreas 7272
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
60 andreas 7273
        {
83 andreas 7274
            Button::TButton *bt = *mapIter;
351 andreas 7275
            bt->setDrawOrder(order, btState - 1);
7276
#if TESTMODE == 1
7277
            if (_gTestMode)
7278
                _gTestMode->setResult(bt->getDrawOrder(btState == 0 ? 0 : btState - 1));
7279
#endif
60 andreas 7280
        }
7281
    }
351 andreas 7282
#if TESTMODE == 1
7283
    setDone();
7284
#endif
60 andreas 7285
}
32 andreas 7286
 
60 andreas 7287
/**
7288
 * Set the feedback type of the button.
7289
 * ONLY works on General-type buttons.
7290
 */
7291
void TPageManager::doBFB(int port, vector<int>& channels, vector<std::string>& pars)
7292
{
7293
    DECL_TRACER("TPageManager::doBFB(int port, vector<int>& channels, vector<std::string>& pars)");
32 andreas 7294
 
60 andreas 7295
    if (pars.size() < 1)
7296
    {
7297
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
351 andreas 7298
#if TESTMODE == 1
7299
        setAllDone();
7300
#endif
60 andreas 7301
        return;
7302
    }
7303
 
7304
    TError::clear();
7305
    Button::FEEDBACK type = Button::FB_NONE;
7306
    string stype = pars[0];
7307
    vector<string> stypes = { "None", "Channel", "Invert", "On", "Momentary", "Blink" };
7308
    vector<string>::iterator iter;
7309
    int i = 0;
7310
 
7311
    for (iter = stypes.begin(); iter != stypes.end(); ++iter)
7312
    {
7313
        if (strCaseCompare(stype, *iter) == 0)
33 andreas 7314
        {
60 andreas 7315
            type = (Button::FEEDBACK)i;
7316
            break;
32 andreas 7317
        }
60 andreas 7318
 
7319
        i++;
32 andreas 7320
    }
7321
 
193 andreas 7322
    vector<TMap::MAP_T> map = findButtons(port, channels);
60 andreas 7323
 
7324
    if (TError::isError() || map.empty())
351 andreas 7325
    {
7326
#if TESTMODE == 1
7327
        setAllDone();
7328
#endif
60 andreas 7329
        return;
351 andreas 7330
    }
60 andreas 7331
 
7332
    vector<Button::TButton *> buttons = collectButtons(map);
7333
 
83 andreas 7334
    if (buttons.size() > 0)
60 andreas 7335
    {
83 andreas 7336
        vector<Button::TButton *>::iterator mapIter;
7337
 
7338
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
7339
        {
7340
            Button::TButton *bt = *mapIter;
7341
            bt->setFeedback(type);
351 andreas 7342
#if TESTMODE == 1
7343
            if (_gTestMode)
7344
                _gTestMode->setResult(intToString(bt->getFeedback()));
7345
#endif
83 andreas 7346
        }
60 andreas 7347
    }
335 andreas 7348
#if TESTMODE == 1
7349
    setDone();
7350
#endif
32 andreas 7351
}
7352
 
224 andreas 7353
/*
7354
 * Set the input mask for the specified address.
7355
 */
7356
void TPageManager::doBIM(int port, vector<int>& channels, vector<std::string>& pars)
7357
{
7358
    DECL_TRACER("TPageManager::doBIM(int port, vector<int>& channels, vector<std::string>& pars)");
7359
 
7360
    if (pars.size() < 1)
7361
    {
7362
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
351 andreas 7363
#if TESTMODE == 1
7364
        setAllDone();
7365
#endif
224 andreas 7366
        return;
7367
    }
7368
 
7369
    TError::clear();
7370
    string mask = pars[0];
7371
    vector<TMap::MAP_T> map = findButtons(port, channels);
7372
 
7373
    if (TError::isError() || map.empty())
351 andreas 7374
    {
7375
#if TESTMODE == 1
7376
        setAllDone();
7377
#endif
224 andreas 7378
        return;
351 andreas 7379
    }
224 andreas 7380
 
7381
    vector<Button::TButton *> buttons = collectButtons(map);
7382
 
7383
    if (buttons.size() > 0)
7384
    {
7385
        vector<Button::TButton *>::iterator mapIter;
7386
 
7387
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
7388
        {
7389
            Button::TButton *bt = *mapIter;
7390
            bt->setInputMask(mask);
351 andreas 7391
#if TESTMODE == 1
7392
            if (_gTestMode)
7393
                _gTestMode->setResult(bt->getInputMask());
7394
#endif
224 andreas 7395
        }
7396
    }
351 andreas 7397
#if TESTMODE == 1
7398
    setDone();
7399
#endif
224 andreas 7400
}
7401
 
351 andreas 7402
/**
7403
 * @brief Button copy command.
7404
 * Copy attributes of the source button to all the
7405
 * destination buttons. Note that the source is a single button state. Each
7406
 * state must be copied as a separate command. The <codes> section represents
7407
 * what attributes will be copied. All codes are 2 char pairs that can be
7408
 * separated by comma, space, percent or just ran together.
7409
 */
106 andreas 7410
void TPageManager::doBMC(int port, vector<int>& channels, vector<std::string>& pars)
7411
{
7412
    DECL_TRACER("TPageManager::doBMC(int port, vector<int>& channels, vector<std::string>& pars)");
7413
 
7414
    if (pars.size() < 5)
7415
    {
7416
        MSG_ERROR("Expecting 5 parameters but got " << pars.size() << ". Ignoring command.");
351 andreas 7417
#if TESTMODE == 1
7418
        setAllDone();
7419
#endif
106 andreas 7420
        return;
7421
    }
7422
 
7423
    TError::clear();
7424
    int btState = atoi(pars[0].c_str());
7425
    int src_port = atoi(pars[1].c_str());
7426
    int src_addr = atoi(pars[2].c_str());
7427
    int src_state = atoi(pars[3].c_str());
7428
    string src_codes = pars[4];
7429
    vector<int> src_channel;
7430
    src_channel.push_back(src_addr);
7431
 
193 andreas 7432
    vector<TMap::MAP_T> src_map = findButtons(src_port, src_channel);
106 andreas 7433
 
7434
    if (src_map.size() == 0)
7435
    {
7436
        MSG_WARNING("Button <" << TConfig::getChannel() << ":" << src_port << ":" << TConfig::getSystem() << ">:" << src_addr << " does not exist!");
351 andreas 7437
#if TESTMODE == 1
7438
        setAllDone();
7439
#endif
106 andreas 7440
        return;
7441
    }
7442
 
7443
    vector<Button::TButton *>src_buttons = collectButtons(src_map);
7444
 
7445
    if (src_buttons.size() == 0)
7446
    {
7447
        MSG_WARNING("Button <" << TConfig::getChannel() << ":" << src_port << ":" << TConfig::getSystem() << ">:" << src_addr << " does not exist!");
351 andreas 7448
#if TESTMODE == 1
7449
        setAllDone();
7450
#endif
106 andreas 7451
        return;
7452
    }
7453
 
7454
    if (src_buttons[0]->getNumberInstances() < src_state)
7455
    {
7456
        MSG_WARNING("Button <" << TConfig::getChannel() << ":" << src_port << ":" << TConfig::getSystem() << ">:" << src_addr << " has less then " << src_state << " elements.");
351 andreas 7457
#if TESTMODE == 1
7458
        setAllDone();
7459
#endif
106 andreas 7460
        return;
7461
    }
7462
 
7463
    if (src_state < 1)
7464
    {
7465
        MSG_WARNING("Button <" << TConfig::getChannel() << ":" << src_port << ":" << TConfig::getSystem() << ">:" << src_addr << " has invalid source state " << src_state << ".");
351 andreas 7466
#if TESTMODE == 1
7467
        setAllDone();
7468
#endif
106 andreas 7469
        return;
7470
    }
7471
 
7472
    src_state--;
7473
 
7474
    if (btState > 0)
7475
        btState--;
7476
 
193 andreas 7477
    vector<TMap::MAP_T> map = findButtons(port, channels);
106 andreas 7478
    vector<Button::TButton *> buttons = collectButtons(map);
7479
    //                        0     1     2     3     4     5     6     7
7480
    vector<string>codes = { "BM", "BR", "CB", "CF", "CT", "EC", "EF", "FT",
7481
                            "IC", "JB", "JI", "JT", "LN", "OP", "SO", "TX", // 8 - 15
7482
                            "VI", "WW" };   // 16, 17
7483
 
7484
    for (size_t ibuttons = 0; ibuttons < buttons.size(); ibuttons++)
7485
    {
7486
        vector<string>::iterator iter;
7487
        int idx = 0;
7488
 
7489
        for (iter = codes.begin(); iter != codes.end(); ++iter)
7490
        {
7491
            if (src_codes.find(*iter) != string::npos)
7492
            {
7493
                int j, x, y;
7494
 
7495
                switch(idx)
7496
                {
7497
                    case 0: buttons[ibuttons]->setBitmap(src_buttons[0]->getBitmapName(src_state), btState); break;
7498
                    case 1: buttons[ibuttons]->setBorderStyle(src_buttons[0]->getBorderStyle(src_state), btState); break;
7499
                    case 2: buttons[ibuttons]->setBorderColor(src_buttons[0]->getBorderColor(src_state), btState); break;
7500
                    case 3: buttons[ibuttons]->setFillColor(src_buttons[0]->getFillColor(src_state), btState); break;
7501
                    case 4: buttons[ibuttons]->setTextColor(src_buttons[0]->getTextColor(src_state), btState); break;
7502
                    case 5: buttons[ibuttons]->setTextEffectColor(src_buttons[0]->getTextEffectColor(src_state), btState); break;
7503
                    case 6: buttons[ibuttons]->setTextEffect(src_buttons[0]->getTextEffect(src_state), btState); break;
7504
                    case 7: buttons[ibuttons]->setFontIndex(src_buttons[0]->getFontIndex(src_state), btState); break;
110 andreas 7505
                    case 8: buttons[ibuttons]->setIcon(src_buttons[0]->getIconIndex(src_state), btState); break;
106 andreas 7506
 
7507
                    case 9:
7508
                        j = src_buttons[0]->getBitmapJustification(&x, &y, src_state);
7509
                        buttons[ibuttons]->setBitmapJustification(j, x, y, btState);
7510
                    break;
7511
 
7512
                    case 10:
7513
                        j = src_buttons[0]->getIconJustification(&x, &y, src_state);
7514
                        buttons[ibuttons]->setIconJustification(j, x, y, btState);
7515
                    break;
7516
 
7517
                    case 11:
7518
                        j = src_buttons[0]->getTextJustification(&x, &y, src_state);
7519
                        buttons[ibuttons]->setTextJustification(j, x, y, btState);
7520
                    break;
7521
 
7522
                    case 12: MSG_INFO("\"Lines of video removed\" not supported!"); break;
7523
                    case 13: buttons[ibuttons]->setOpacity(src_buttons[0]->getOpacity(src_state), btState); break;
7524
                    case 14: buttons[ibuttons]->setSound(src_buttons[0]->getSound(src_state), btState); break;
7525
                    case 15: buttons[ibuttons]->setText(src_buttons [0]->getText(src_state), btState); break;
7526
                    case 16: MSG_INFO("\"Video slot ID\" not supported!"); break;
7527
                    case 17: buttons[ibuttons]->setTextWordWrap(src_buttons[0]->getTextWordWrap(src_state), btState); break;
7528
                }
7529
            }
7530
 
7531
            idx++;
7532
        }
7533
    }
7534
}
7535
 
149 andreas 7536
void TPageManager::doBMF (int port, vector<int>& channels, vector<string>& pars)
7537
{
7538
    DECL_TRACER("TPageManager::doBMF (int port, vector<int>& channels, vector<string>& pars)");
7539
 
7540
    if (pars.size() < 2)
332 andreas 7541
    {
7542
        MSG_ERROR("Less then 2 parameters!");
7543
#if TESTMODE == 1
334 andreas 7544
        setAllDone();
332 andreas 7545
#endif
149 andreas 7546
        return;
332 andreas 7547
    }
149 andreas 7548
 
7549
    TError::clear();
7550
    int btState = atoi(pars[0].c_str()) - 1;
150 andreas 7551
    string commands;
149 andreas 7552
 
150 andreas 7553
    for (size_t i = 1; i < pars.size(); ++i)
7554
    {
7555
        if (i > 1)
7556
            commands += ",";
7557
 
7558
        commands += pars[i];
7559
    }
7560
 
193 andreas 7561
    vector<TMap::MAP_T> map = findButtons(port, channels);
149 andreas 7562
 
7563
    if (TError::isError() || map.empty())
332 andreas 7564
    {
7565
#if TESTMODE == 1
334 andreas 7566
        setAllDone();
332 andreas 7567
#endif
149 andreas 7568
        return;
332 andreas 7569
    }
149 andreas 7570
 
7571
    // Start of parsing the command line
162 andreas 7572
    // We splitt the command line into parts by searching for a percent (%) sign.
149 andreas 7573
    vector<string> parts = StrSplit(commands, "%");
7574
 
162 andreas 7575
    if (parts.empty())
332 andreas 7576
        parts.push_back(commands);
334 andreas 7577
 
149 andreas 7578
    // Search for all buttons who need to be updated
7579
    vector<Button::TButton *> buttons = collectButtons(map);
7580
 
7581
    if (buttons.size() > 0)
7582
    {
7583
        vector<Button::TButton *>::iterator mapIter;
7584
 
7585
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
7586
        {
7587
            Button::TButton *bt = *mapIter;
162 andreas 7588
 
7589
            if (!bt)
7590
            {
7591
                MSG_WARNING("Command ^BMF found an invalid pointer to a button!")
7592
                continue;
7593
            }
7594
 
149 andreas 7595
            // Iterate through commands and apply them to button
7596
            vector<string>::iterator iter;
7597
 
7598
            for (iter = parts.begin(); iter != parts.end(); ++iter)
7599
            {
7600
                char cmd = iter->at(0);
7601
                char cmd2;
7602
                string content;
7603
 
7604
                switch(cmd)
7605
                {
7606
                    case 'B':   // Border style
361 andreas 7607
                        if (iter->at(1) == ',')
7608
                            content = iter->substr(2);
7609
                        else
7610
                            content = iter->substr(1);
332 andreas 7611
 
7612
                        if (!content.empty() && isdigit(content[0]))
334 andreas 7613
                            bt->setBorderStyle(atoi(content.c_str()), btState);
332 andreas 7614
                        else
7615
                            bt->setBorderStyle(content, btState);
7616
#if TESTMODE == 1
7617
                        if (_gTestMode)
7618
                            _gTestMode->setResult(bt->getBorderStyle(btState < 0 ? 0 : btState));
7619
#endif
149 andreas 7620
                    break;
7621
 
7622
                    case 'C':   // Colors
7623
                        cmd2 = iter->at(1);
7624
                        content = iter->substr(2);
7625
 
7626
                        switch(cmd2)
7627
                        {
7628
                            case 'B':   // Border color
7629
                                bt->setBorderColor(content, btState);
332 andreas 7630
#if TESTMODE == 1
7631
                                if (_gTestMode)
7632
                                    _gTestMode->setResult(bt->getBorderColor(btState < 0 ? 0 : btState));
7633
#endif
149 andreas 7634
                            break;
7635
 
7636
                            case 'F':   // Fill color
7637
                                bt->setFillColor(content, btState);
332 andreas 7638
#if TESTMODE == 1
7639
                                if (_gTestMode)
7640
                                    _gTestMode->setResult(bt->getFillColor(btState < 0 ? 0 : btState));
7641
#endif
149 andreas 7642
                            break;
7643
 
7644
                            case 'T':   // Text color
7645
                                bt->setTextColor(content, btState);
332 andreas 7646
#if TESTMODE == 1
7647
                                if (_gTestMode)
7648
                                    _gTestMode->setResult(bt->getTextColor(btState < 0 ? 0 : btState));
7649
#endif
149 andreas 7650
                            break;
7651
                        }
7652
                    break;
7653
 
150 andreas 7654
                    case 'D':   // Draw order
7655
                        cmd2 = iter->at(1);
7656
                        content = iter->substr(2);
7657
 
7658
                        if (cmd2 == 'O')
332 andreas 7659
                        {
150 andreas 7660
                            bt->setDrawOrder(content, btState);
332 andreas 7661
#if TESTMODE == 1
7662
                            if (_gTestMode)
7663
                                _gTestMode->setResult(bt->getDrawOrder(btState < 0 ? 0 : btState));
7664
#endif
7665
                        }
150 andreas 7666
                    break;
7667
 
149 andreas 7668
                    case 'E':   // Text effect
7669
                        cmd2 = iter->at(1);
7670
                        content = iter->substr(2);
7671
 
7672
                        switch(cmd2)
7673
                        {
7674
                            case 'C':   // Text effect color
7675
                                bt->setTextEffectColor(content, btState);
332 andreas 7676
#if TESTMODE == 1
7677
                                if (_gTestMode)
7678
                                    _gTestMode->setResult(bt->getTextEffectColor(btState < 0 ? 0 : btState));
7679
#endif
149 andreas 7680
                            break;
7681
 
7682
                            case 'F':   // Text effect name
7683
                                bt->setTextEffectName(content, btState);
332 andreas 7684
#if TESTMODE == 1
7685
                                if (_gTestMode)
7686
                                    _gTestMode->setResult(bt->getTextEffectName(btState < 0 ? 0 : btState));
7687
#endif
149 andreas 7688
                            break;
7689
 
7690
                            case 'N':   // Enable/disable button
7691
                                bt->setEnable((content[0] == '1' ? true : false));
332 andreas 7692
#if TESTMODE == 1
7693
                                if (_gTestMode)
334 andreas 7694
                                {
332 andreas 7695
                                    _gTestMode->setResult(bt->isEnabled() ? "TRUE" : "FALSE");
334 andreas 7696
                                    __success = true;
7697
                                    setScreenDone();
7698
                                }
332 andreas 7699
#endif
149 andreas 7700
                            break;
7701
                        }
7702
                    break;
7703
 
7704
                    case 'F':   // Set font file name
361 andreas 7705
                        if (iter->at(1) == ',')
7706
                            content = iter->substr(2);
7707
                        else
7708
                            content = iter->substr(1);
150 andreas 7709
 
7710
                        if (!isdigit(content[0]))
334 andreas 7711
                            bt->setFontName(content, btState);
150 andreas 7712
                        else
7713
                            bt->setFontIndex(atoi(content.c_str()), btState);
334 andreas 7714
#if TESTMODE == 1
7715
                        if (_gTestMode)
7716
                            _gTestMode->setResult(intToString(bt->getFontIndex(btState < 0 ? 0 : btState)));
7717
#endif
149 andreas 7718
                    break;
7719
 
7720
                    case 'G':   // Bargraphs
7721
                        cmd2 = iter->at(1);
7722
                        content = iter->substr(2);
7723
 
7724
                        switch(cmd2)
7725
                        {
7726
                            case 'C':   // Bargraph slider color
7727
                                bt->setBargraphSliderColor(content);
7728
                            break;
7729
 
7730
                            case 'D':   // Ramp down time
387 andreas 7731
                                bt->setBargraphRampDownTime(atoi(content.c_str()));
149 andreas 7732
                            break;
7733
 
7734
                            case 'G':   // Drag increment
387 andreas 7735
                                bt->setBargraphDragIncrement(atoi(content.c_str()));
149 andreas 7736
                            break;
7737
 
7738
                            case 'H':   // Upper limit
7739
                                bt->setBargraphUpperLimit(atoi(content.c_str()));
7740
                            break;
7741
 
7742
                            case 'I':   // Invert/noninvert
387 andreas 7743
                                if (bt->getButtonType() == BARGRAPH || bt->getButtonType() == MULTISTATE_BARGRAPH)
7744
                                    bt->setBargraphInvert(atoi(content.c_str()) > 0 ? true : false);
149 andreas 7745
                            break;
7746
 
7747
                            case 'L':   // Lower limit
7748
                                bt->setBargraphLowerLimit(atoi(content.c_str()));
7749
                            break;
7750
 
7751
                            case 'N':   // Slider name
361 andreas 7752
                                bt->setBargraphSliderName(content);
149 andreas 7753
                            break;
7754
 
7755
                            case 'R':   // Repeat interval
7756
                                // FIXME: Add function to set repeat interval
7757
                            break;
7758
 
7759
                            case 'U':   // Ramp up time
387 andreas 7760
                                bt->setBargraphRampUpTime(atoi(content.c_str()));
149 andreas 7761
                            break;
7762
 
7763
                            case 'V':   // Bargraph value
387 andreas 7764
                                bt->setBargraphLevel(atoi(content.c_str()));
149 andreas 7765
                            break;
7766
                        }
7767
                    break;
7768
 
152 andreas 7769
                    case 'I':   // Set the icon
7770
                        content = iter->substr(1);
7771
                        bt->setIcon(atoi(content.c_str()), btState);
332 andreas 7772
#if TESTMODE == 1
7773
                        if (_gTestMode)
7774
                            _gTestMode->setResult(intToString(bt->getIconIndex()));
7775
#endif
152 andreas 7776
                    break;
7777
 
149 andreas 7778
                    case 'J':   // Set text justification
150 andreas 7779
                        cmd2 = iter->at(1);
7780
 
361 andreas 7781
                        if (cmd2 == ',')
150 andreas 7782
                        {
7783
                            content = iter->substr(1);
152 andreas 7784
                            int just = atoi(content.c_str());
7785
                            int x = 0, y = 0;
7786
 
7787
                            if (just == 0)
7788
                            {
7789
                                vector<string> coords = StrSplit(content, ",");
7790
 
7791
                                if (coords.size() >= 3)
7792
                                {
7793
                                    x = atoi(coords[1].c_str());
7794
                                    y = atoi(coords[2].c_str());
7795
                                }
7796
                            }
7797
 
7798
                            bt->setTextJustification(atoi(content.c_str()), x, y, btState);
334 andreas 7799
#if TESTMODE == 1
7800
                            if (_gTestMode)
7801
                            {
7802
                                just = bt->getTextJustification(&x, &y, btState < 0 ? 0 : btState);
7803
                                string s = intToString(just) + "," + intToString(x) + "," + intToString(y);
7804
                                _gTestMode->setResult(s);
7805
                            }
7806
#endif
150 andreas 7807
                        }
361 andreas 7808
                        else if (cmd2 == 'T' || cmd2 == 'B' || cmd2 == 'I')
150 andreas 7809
                        {
7810
                            content = iter->substr(2);
152 andreas 7811
                            int x = 0, y = 0;
7812
                            int just = atoi(content.c_str());
150 andreas 7813
 
152 andreas 7814
                            if (just == 0)
7815
                            {
7816
                                vector<string> coords = StrSplit(content, ",");
7817
 
7818
                                if (coords.size() >= 3)
7819
                                {
7820
                                    x = atoi(coords[1].c_str());
7821
                                    y = atoi(coords[2].c_str());
7822
                                }
7823
                            }
7824
 
150 andreas 7825
                            switch(cmd2)
7826
                            {
7827
                                case 'B':   // Alignment of bitmap
152 andreas 7828
                                    bt->setBitmapJustification(atoi(content.c_str()), x, y, btState);
334 andreas 7829
#if TESTMODE == 1
7830
                                    just = bt->getBitmapJustification(&x, &y, btState < 0 ? 0 : btState);
7831
#endif
150 andreas 7832
                                break;
7833
 
7834
                                case 'I':   // Alignment of icon
152 andreas 7835
                                    bt->setIconJustification(atoi(content.c_str()), x, y, btState);
334 andreas 7836
#if TESTMODE == 1
7837
                                    just = bt->getIconJustification(&x, &y, btState < 0 ? 0 : btState);
7838
#endif
150 andreas 7839
                                break;
7840
 
7841
                                case 'T':   // Alignment of text
152 andreas 7842
                                    bt->setTextJustification(atoi(content.c_str()), x, y, btState);
334 andreas 7843
#if TESTMODE == 1
7844
                                    just = bt->getTextJustification(&x, &y, btState < 0 ? 0 : btState);
7845
#endif
150 andreas 7846
                                break;
7847
                            }
334 andreas 7848
#if TESTMODE == 1
7849
                            if (_gTestMode)
7850
                            {
7851
                                string s = intToString(just) + "," + intToString(x) + "," + intToString(y);
7852
                                _gTestMode->setResult(s);
7853
                            }
7854
#endif
150 andreas 7855
                        }
7856
                    break;
7857
 
7858
                    case 'M':   // Text area
7859
                        cmd2 = iter->at(1);
7860
                        content = iter->substr(2);
7861
 
7862
                        switch(cmd2)
7863
                        {
152 andreas 7864
                            case 'I':   // Set mask image
7865
                                // FIXME: Add code for image mask
7866
                            break;
7867
 
150 andreas 7868
                            case 'K':   // Input mask of text area
7869
                                // FIXME: Add input mask
7870
                            break;
7871
 
7872
                            case 'L':   // Maximum length of text area
7873
                                // FIXME: Add code to set maximum length
7874
                            break;
7875
                        }
7876
                    break;
7877
 
7878
                    case 'O':   // Set feedback typ, opacity
7879
                        cmd2 = iter->at(1);
7880
 
7881
                        switch(cmd2)
7882
                        {
7883
                            case 'P':   // Set opacity
7884
                                bt->setOpacity(atoi(iter->substr(2).c_str()), btState);
7885
                            break;
7886
 
7887
                            case 'T':   // Set feedback type
7888
                                content = iter->substr(2);
7889
                                content = toUpper(content);
7890
 
7891
                                if (content == "NONE")
7892
                                    bt->setFeedback(Button::FB_NONE);
7893
                                else if (content == "CHANNEL")
7894
                                    bt->setFeedback(Button::FB_CHANNEL);
7895
                                else if (content == "INVERT")
7896
                                    bt->setFeedback(Button::FB_INV_CHANNEL);
7897
                                else if (content == "ON")
7898
                                    bt->setFeedback(Button::FB_ALWAYS_ON);
7899
                                else if (content == "MOMENTARY")
7900
                                    bt->setFeedback(Button::FB_MOMENTARY);
7901
                                else if (content == "BLINK")
7902
                                    bt->setFeedback(Button::FB_BLINK);
7903
                                else
7904
                                {
7905
                                    MSG_WARNING("Unknown feedback type " << content);
7906
                                }
335 andreas 7907
#if TESTMODE == 1
7908
                                if (_gTestMode)
7909
                                    _gTestMode->setResult(intToString(bt->getFeedback()));
7910
#endif
150 andreas 7911
                            break;
7912
 
7913
                            default:
7914
                                content = iter->substr(1);
7915
                                // FIXME: Add code to set the feedback type
7916
                        }
7917
                    break;
7918
 
152 andreas 7919
                    case 'P':   // Set picture/bitmap file name
7920
                        content = iter->substr(1);
165 andreas 7921
 
7922
                        if (content.find(".") == string::npos)  // If the image has no extension ...
7923
                        {                                       // we must find the image in the map
7924
                            string iname = findImage(content);
7925
 
7926
                            if (!iname.empty())
7927
                                content = iname;
7928
                        }
7929
 
152 andreas 7930
                        bt->setBitmap(content, btState);
7931
                    break;
7932
 
7933
                    case 'R':   // Set rectangle
7934
                    {
7935
                        content = iter->substr(1);
7936
                        vector<string> corners = StrSplit(content, ",");
7937
 
7938
                        if (corners.size() > 0)
7939
                        {
7940
                            vector<string>::iterator itcorn;
7941
                            int pos = 0;
7942
                            int left, top, right, bottom;
7943
                            left = top = right = bottom = 0;
7944
 
7945
                            for (itcorn = corners.begin(); itcorn != corners.end(); ++itcorn)
7946
                            {
7947
                                switch(pos)
7948
                                {
7949
                                    case 0: left   = atoi(itcorn->c_str()); break;
7950
                                    case 1: top    = atoi(itcorn->c_str()); break;
7951
                                    case 2: right  = atoi(itcorn->c_str()); break;
7952
                                    case 3: bottom = atoi(itcorn->c_str()); break;
7953
                                }
7954
 
7955
                                pos++;
7956
                            }
7957
 
7958
                            if (pos >= 4)
334 andreas 7959
                            {
152 andreas 7960
                                bt->setRectangle(left, top, right, bottom);
334 andreas 7961
                                bt->refresh();
7962
                            }
152 andreas 7963
                        }
334 andreas 7964
#if TESTMODE == 1
7965
                        if (_gTestMode)
7966
                        {
7967
                            int left, top, width, height;
7968
                            bt->getRectangle(&left, &top, &height, &width);
7969
                            string res(intToString(left) + "," + intToString(top) + "," + intToString(width) + "," + intToString(height));
7970
                            _gTestMode->setResult(res);
7971
                        }
7972
#endif
152 andreas 7973
                    }
7974
                    break;
7975
 
150 andreas 7976
                    case 'S':   // show/hide, style, sound
7977
                        cmd2 = iter->at(1);
7978
                        content = iter->substr(2);
7979
 
7980
                        switch(cmd2)
7981
                        {
7982
                            case 'F':   // Set focus of text area button
7983
                                // FIXME: Add code to set the focus of text area button
7984
                            break;
7985
 
7986
                            case 'M':   // Submit text
169 andreas 7987
                                if (content.find("|"))  // To be replaced by LF (0x0a)?
7988
                                {
7989
                                    size_t pos = 0;
7990
 
7991
                                    while ((pos = content.find("|")) != string::npos)
7992
                                        content = content.replace(pos, 1, "\n");
7993
                                }
7994
 
150 andreas 7995
                                bt->setText(content, btState);
7996
                            break;
7997
 
7998
                            case 'O':   // Sound
7999
                                bt->setSound(content, btState);
335 andreas 8000
#if TESTMODE == 1
8001
                                if (_gTestMode)
8002
                                    _gTestMode->setResult(bt->getSound(btState < 0 ? 0 : btState));
8003
#endif
150 andreas 8004
                            break;
8005
 
8006
                            case 'T':   // Button style
8007
                                // FIXME: Add code to set the button style
8008
                            break;
8009
 
8010
                            case 'W':   // Show / hide button
8011
                                if (content[0] == '0')
334 andreas 8012
                                    bt->hide(true);
150 andreas 8013
                                else
8014
                                    bt->show();
334 andreas 8015
#if TESTMODE == 1
8016
                                if (_gTestMode)
8017
                                    _gTestMode->setResult(bt->isVisible() ? "TRUE" : "FALSE");
8018
#endif
150 andreas 8019
                            break;
8020
                        }
8021
                    break;
8022
 
152 andreas 8023
                    case 'T':   // Set text
8024
                        content = iter->substr(1);
169 andreas 8025
 
8026
                        if (content.find("|"))  // To be replaced by LF (0x0a)?
8027
                        {
8028
                            size_t pos = 0;
8029
 
8030
                            while ((pos = content.find("|")) != string::npos)
8031
                                content = content.replace(pos, 1, "\n");
8032
                        }
8033
 
152 andreas 8034
                        bt->setText(content, btState);
334 andreas 8035
#if TESTMODE == 1
8036
                        if (_gTestMode)
8037
                            _gTestMode->setResult(bt->getText(btState < 0 ? 0 : btState));
8038
#endif
152 andreas 8039
                    break;
8040
 
150 andreas 8041
                    case 'U':   // Set the unicode text
8042
                        if (iter->at(1) == 'N')
8043
                        {
8044
                            content = iter->substr(2);
152 andreas 8045
                            string byte, text;
8046
                            size_t pos = 0;
8047
 
8048
                            while (pos < content.length())
8049
                            {
8050
                                byte = content.substr(pos, 2);
8051
                                char ch = (char)strtol(byte.c_str(), NULL, 16);
8052
                                text += ch;
8053
                                pos += 2;
8054
                            }
8055
 
169 andreas 8056
                            if (text.find("|"))  // To be replaced by LF (0x0a)?
8057
                            {
8058
                                size_t pos = 0;
8059
 
8060
                                while ((pos = text.find("|")) != string::npos)
8061
                                    text = text.replace(pos, 1, "\n");
8062
                            }
8063
 
152 andreas 8064
                            bt->setText(text, btState);
150 andreas 8065
                        }
8066
                    break;
8067
 
8068
                    case 'V':   // Video on / off
8069
                        cmd2 = iter->at(1);
8070
                        // Controlling a computer remotely is not supported.
8071
                        if (cmd2 != 'L' && cmd2 != 'N' && cmd2 != 'P')
8072
                        {
8073
                            content = iter->substr(2);
8074
                            // FIXME: Add code to switch video on or off
8075
                        }
8076
                    break;
8077
 
8078
                    case 'W':   // Word wrap
152 andreas 8079
                        if (iter->at(1) == 'W')
8080
                        {
8081
                            content = iter->substr(2);
8082
                            bt->setTextWordWrap(content[0] == '1' ? true : false, btState);
8083
                        }
149 andreas 8084
                    break;
8085
                }
8086
            }
8087
        }
8088
    }
332 andreas 8089
#if TESTMODE == 1
334 andreas 8090
    setDone();
332 andreas 8091
#endif
149 andreas 8092
}
8093
 
14 andreas 8094
/**
110 andreas 8095
 * Set the maximum length of the text area button. If this value is set to
8096
 * zero (0), the text area has no max length. The maximum length available is
8097
 * 2000. This is only for a Text area input button and not for a Text area input
8098
 * masking button.
8099
 */
8100
void TPageManager::doBML(int port, vector<int>& channels, vector<string>& pars)
8101
{
8102
    DECL_TRACER("TPageManager::doBML(int port, vector<int>& channels, vector<string>& pars)");
8103
 
8104
    if (pars.size() < 1)
8105
    {
8106
        MSG_ERROR("Expecting 1 parameter but got " << pars.size() << "! Ignoring command.");
8107
        return;
8108
    }
8109
 
8110
    TError::clear();
8111
    int maxLen = atoi(pars[0].c_str());
8112
 
8113
    if (maxLen < 0 || maxLen > 2000)
8114
    {
8115
        MSG_WARNING("Got illegal length of text area! [" << maxLen << "]");
8116
        return;
8117
    }
8118
 
193 andreas 8119
    vector<TMap::MAP_T> map = findButtons(port, channels);
110 andreas 8120
 
8121
    if (TError::isError() || map.empty())
8122
        return;
8123
 
8124
    vector<Button::TButton *> buttons = collectButtons(map);
8125
 
8126
    if (buttons.size() > 0)
8127
    {
8128
        vector<Button::TButton *>::iterator mapIter;
8129
 
8130
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
8131
        {
8132
            Button::TButton *bt = *mapIter;
8133
            bt->setTextMaxChars(maxLen);
8134
        }
8135
    }
8136
}
8137
 
8138
/**
60 andreas 8139
 * Assign a picture to those buttons with a defined address range.
8140
 */
8141
void TPageManager::doBMP(int port, vector<int>& channels, vector<string>& pars)
8142
{
8143
    DECL_TRACER("TPageManager::doBMP(int port, vector<int>& channels, vector<string>& pars)");
8144
 
8145
    if (pars.size() < 2)
8146
    {
8147
        MSG_ERROR("Expecting 2 parameters but got " << pars.size() << "! Ignoring command.");
8148
        return;
8149
    }
8150
 
8151
    TError::clear();
8152
    int btState = atoi(pars[0].c_str());
8153
    string bitmap = pars[1];
104 andreas 8154
    // If this is a G5 command, we may have up to 2 additional parameters.
8155
    int slot = -1, justify = -1, jx = 0, jy = 0;
60 andreas 8156
 
104 andreas 8157
    if (pars.size() > 2)
8158
    {
8159
        slot = atoi(pars[2].c_str());
8160
 
8161
        if (pars.size() >= 4)
8162
        {
8163
            justify = atoi(pars[4].c_str());
8164
 
8165
            if (justify == 0)
8166
            {
8167
                if (pars.size() >= 5)
8168
                    jx = atoi(pars[5].c_str());
8169
 
8170
                if (pars.size() >= 6)
8171
                    jy = atoi(pars[6].c_str());
8172
            }
8173
        }
8174
    }
8175
 
193 andreas 8176
    vector<TMap::MAP_T> map = findButtons(port, channels);
60 andreas 8177
 
8178
    if (TError::isError() || map.empty())
8179
        return;
8180
 
8181
    vector<Button::TButton *> buttons = collectButtons(map);
8182
 
83 andreas 8183
    if (buttons.size() > 0)
60 andreas 8184
    {
83 andreas 8185
        vector<Button::TButton *>::iterator mapIter;
60 andreas 8186
 
83 andreas 8187
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
60 andreas 8188
        {
83 andreas 8189
            Button::TButton *bt = *mapIter;
252 andreas 8190
//            setButtonCallbacks(bt);
60 andreas 8191
 
83 andreas 8192
            if (btState == 0)       // All instances?
8193
            {
8194
                int bst = bt->getNumberInstances();
96 andreas 8195
                MSG_DEBUG("Setting bitmap " << bitmap << " on all " << bst << " instances...");
83 andreas 8196
 
8197
                for (int i = 0; i < bst; i++)
104 andreas 8198
                {
8199
                    if (justify >= 0)
8200
                    {
8201
                        if (slot == 2)
8202
                            bt->setIconJustification(justify, jx, jy, i);
8203
                        else
106 andreas 8204
                            bt->setBitmapJustification(justify, jx, jy, i);
104 andreas 8205
                    }
8206
 
8207
                    if (slot >= 0)
8208
                    {
8209
                        switch(slot)
8210
                        {
8211
                            case 0: bt->setCameleon(bitmap, i); break;
8212
                            case 2: bt->setIcon(bitmap, i); break;  // On G4 we have no bitmap layer. Therefor we use layer 2 as icon layer.
8213
                            default:
8214
                                bt->setBitmap(bitmap, i);
8215
                        }
8216
                    }
8217
                    else
8218
                        bt->setBitmap(bitmap, i);
8219
                }
83 andreas 8220
            }
8221
            else
104 andreas 8222
            {
8223
                if (justify >= 0)
8224
                {
8225
                    if (slot == 2)
8226
                        bt->setIconJustification(justify, jx, jy, btState);
8227
                    else
106 andreas 8228
                        bt->setBitmapJustification(justify, jx, jy, btState);
104 andreas 8229
                }
8230
 
8231
                if (slot >= 0)
8232
                {
8233
                    switch(slot)
8234
                    {
8235
                        case 0: bt->setCameleon(bitmap, btState); break;
8236
                        case 2: bt->setIcon(bitmap, btState); break;      // On G4 we have no bitmap layer. Therefor we use layer 2 as icon layer.
8237
                        default:
8238
                            bt->setBitmap(bitmap, btState);
8239
                    }
8240
                }
8241
                else
8242
                    bt->setBitmap(bitmap, btState);
8243
            }
60 andreas 8244
        }
8245
    }
8246
}
8247
 
82 andreas 8248
void TPageManager::getBMP(int port, vector<int> &channels, vector<string> &pars)
8249
{
8250
    DECL_TRACER("TPageManager::getBMP(int port, vector<int> &channels, vector<string> &pars)");
8251
 
8252
    if (pars.size() < 1)
8253
    {
8254
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
8255
        return;
8256
    }
8257
 
8258
    TError::clear();
8259
    int btState = atoi(pars[0].c_str());
8260
    string bmp;
8261
 
193 andreas 8262
    vector<TMap::MAP_T> map = findButtons(port, channels);
82 andreas 8263
 
8264
    if (TError::isError() || map.empty())
8265
        return;
8266
 
8267
    vector<Button::TButton *> buttons = collectButtons(map);
8268
 
83 andreas 8269
    if (buttons.size() > 0)
82 andreas 8270
    {
110 andreas 8271
        Button::TButton *bt = buttons[0];
82 andreas 8272
 
110 andreas 8273
        if (btState == 0)       // All instances?
82 andreas 8274
        {
110 andreas 8275
            int bst = bt->getNumberInstances();
82 andreas 8276
 
110 andreas 8277
            for (int i = 0; i < bst; i++)
82 andreas 8278
            {
110 andreas 8279
                bmp = bt->getBitmapName(i);
82 andreas 8280
 
110 andreas 8281
                if (bmp.empty())
8282
                    continue;
82 andreas 8283
 
300 andreas 8284
                sendCustomEvent(i + 1, (int)bmp.length(), 0, bmp, 1002, bt->getChannelPort(), bt->getChannelNumber());
83 andreas 8285
            }
82 andreas 8286
        }
110 andreas 8287
        else
8288
        {
8289
            bmp = bt->getTextColor(btState-1);
300 andreas 8290
            sendCustomEvent(btState, (int)bmp.length(), 0, bmp, 1002, bt->getChannelPort(), bt->getChannelNumber());
110 andreas 8291
        }
82 andreas 8292
    }
8293
}
8294
 
60 andreas 8295
/**
16 andreas 8296
 * Set the button opacity. The button opacity can be specified as a decimal
8297
 * between 0 - 255, where zero (0) is invisible and 255 is opaque, or as a
8298
 * HEX code, as used in the color commands by preceding the HEX code with
8299
 * the # sign. In this case, #00 becomes invisible and #FF becomes opaque.
8300
 * If the opacity is set to zero (0), this does not make the button inactive,
8301
 * only invisible.
8302
 */
8303
void TPageManager::doBOP(int port, vector<int>& channels, vector<string>& pars)
8304
{
8305
    DECL_TRACER("TPageManager::doBOP(int port, vector<int>& channels, vector<string>& pars)");
8306
 
8307
    if (pars.size() < 2)
8308
    {
8309
        MSG_ERROR("Expecting 2 parameters but got " << pars.size() << "! Ignoring command.");
335 andreas 8310
#if TESTMODE == 1
8311
        setAllDone();
8312
#endif
16 andreas 8313
        return;
8314
    }
8315
 
8316
    TError::clear();
335 andreas 8317
    int btState = atoi(pars[0].c_str()) - 1;
16 andreas 8318
    int btOpacity = 0;
8319
 
8320
    if (pars[1].at(0) == '#')
8321
        btOpacity = (int)strtol(pars[1].substr(1).c_str(), NULL, 16);
8322
    else
8323
        btOpacity = atoi(pars[1].c_str());
8324
 
193 andreas 8325
    vector<TMap::MAP_T> map = findButtons(port, channels);
16 andreas 8326
 
8327
    if (TError::isError() || map.empty())
335 andreas 8328
    {
8329
#if TESTMODE == 1
8330
        setAllDone();
8331
#endif
16 andreas 8332
        return;
335 andreas 8333
    }
16 andreas 8334
 
8335
    vector<Button::TButton *> buttons = collectButtons(map);
8336
 
83 andreas 8337
    if (buttons.size() > 0)
16 andreas 8338
    {
83 andreas 8339
        vector<Button::TButton *>::iterator mapIter;
16 andreas 8340
 
83 andreas 8341
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
16 andreas 8342
        {
83 andreas 8343
            Button::TButton *bt = *mapIter;
335 andreas 8344
            bt->setOpacity(btOpacity, btState);
8345
#if TESTMODE == 1
8346
            if (_gTestMode)
8347
                _gTestMode->setResult(intToString(bt->getOpacity(btState < 0 ? 0 : btState)));
342 andreas 8348
#endif
16 andreas 8349
        }
8350
    }
335 andreas 8351
#if TESTMODE == 1
8352
    setDone();
8353
#endif
16 andreas 8354
}
8355
 
106 andreas 8356
void TPageManager::getBOP(int port, vector<int>& channels, vector<string>& pars)
8357
{
8358
    DECL_TRACER("TPageManager::getBOP(int port, vector<int>& channels, vector<string>& pars)");
8359
 
8360
    if (pars.size() < 1)
8361
    {
8362
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
8363
        return;
8364
    }
8365
 
8366
    TError::clear();
8367
    int btState = atoi(pars[0].c_str());
8368
 
193 andreas 8369
    vector<TMap::MAP_T> map = findButtons(port, channels);
106 andreas 8370
 
8371
    if (TError::isError() || map.empty())
8372
        return;
8373
 
8374
    vector<Button::TButton *> buttons = collectButtons(map);
8375
 
8376
    if (buttons.size() > 0)
8377
    {
110 andreas 8378
        Button::TButton *bt = buttons[0];
106 andreas 8379
 
110 andreas 8380
        if (btState == 0)       // All instances?
106 andreas 8381
        {
110 andreas 8382
            int bst = bt->getNumberInstances();
106 andreas 8383
 
110 andreas 8384
            for (int i = 0; i < bst; i++)
106 andreas 8385
            {
110 andreas 8386
                int oo = bt->getOpacity(i);
8387
                sendCustomEvent(i + 1, oo, 0, "", 1015, bt->getChannelPort(), bt->getChannelNumber());
106 andreas 8388
            }
8389
        }
110 andreas 8390
        else
8391
        {
8392
            int oo = bt->getOpacity(btState-1);
8393
            sendCustomEvent(btState, oo, 0, "", 1015, bt->getChannelPort(), bt->getChannelNumber());
8394
        }
106 andreas 8395
    }
8396
}
8397
 
60 andreas 8398
void TPageManager::doBOR(int port, vector<int>& channels, vector<string>& pars)
8399
{
8400
    DECL_TRACER("TPageManager::doBOR(int port, vector<int>& channels, vector<string>& pars)");
8401
 
8402
    if (pars.size() < 1)
8403
    {
8404
        MSG_ERROR("Expecting at least 1 parameter but got " << pars.size() << "! Ignoring command.");
335 andreas 8405
#if TESTMODE == 1
8406
        setAllDone();
8407
#endif
60 andreas 8408
        return;
8409
    }
8410
 
8411
    TError::clear();
8412
    // Numbers of styles from 0 to 41
8413
    string bor = pars[0];
8414
    string border = "None";
8415
    int ibor = -1;
336 andreas 8416
    Border::TIntBorder borders;
60 andreas 8417
 
8418
    if (bor.at(0) >= '0' && bor.at(0) <= '9')
336 andreas 8419
    {
60 andreas 8420
        ibor = atoi(bor.c_str());
8421
 
336 andreas 8422
        if (ibor >= 0 && ibor <= 41)
8423
            border = borders.getTP4BorderName(ibor);
8424
        else
60 andreas 8425
        {
336 andreas 8426
            MSG_WARNING("Invalid border style ID " << ibor);
8427
#if TESTMODE == 1
8428
            setAllDone();
8429
#endif
8430
            return;
8431
        }
60 andreas 8432
 
336 andreas 8433
        MSG_DEBUG("Id " << ibor << " is border " << border);
60 andreas 8434
    }
336 andreas 8435
    else
60 andreas 8436
    {
336 andreas 8437
        if (!borders.isTP4BorderValid(bor))
8438
        {
8439
            MSG_WARNING("Unknown border style " << bor);
335 andreas 8440
#if TESTMODE == 1
336 andreas 8441
            setAllDone();
335 andreas 8442
#endif
336 andreas 8443
            return;
8444
        }
60 andreas 8445
 
336 andreas 8446
        border = bor;
60 andreas 8447
    }
8448
 
193 andreas 8449
    vector<TMap::MAP_T> map = findButtons(port, channels);
60 andreas 8450
 
8451
    if (TError::isError() || map.empty())
335 andreas 8452
    {
8453
#if TESTMODE == 1
8454
        setAllDone();
8455
#endif
60 andreas 8456
        return;
335 andreas 8457
    }
60 andreas 8458
 
8459
    vector<Button::TButton *> buttons = collectButtons(map);
8460
 
83 andreas 8461
    if (buttons.size() > 0)
60 andreas 8462
    {
83 andreas 8463
        vector<Button::TButton *>::iterator mapIter;
8464
 
8465
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
8466
        {
8467
            Button::TButton *bt = *mapIter;
8468
            bt->setBorderStyle(border);
335 andreas 8469
#if TESTMODE == 1
8470
            if (_gTestMode)
8471
                _gTestMode->setResult(bt->getBorderStyle(0));
8472
#endif
83 andreas 8473
        }
60 andreas 8474
    }
335 andreas 8475
#if TESTMODE == 1
8476
    setDone();
8477
#endif
60 andreas 8478
}
8479
 
107 andreas 8480
void TPageManager::doBOS(int port, vector<int>& channels, vector<string>& pars)
8481
{
8482
    DECL_TRACER("TPageManager::doBOS(int port, vector<int>& channels, vector<string>& pars)");
8483
 
8484
    if (pars.size() < 2)
8485
    {
8486
        MSG_ERROR("Expecting at least 2 parameters but got " << pars.size() << "! Ignoring command.");
8487
        return;
8488
    }
8489
 
8490
    TError::clear();
8491
    int btState = atoi(pars[0].c_str());
8492
    int videoState = atoi(pars[1].c_str());
8493
 
193 andreas 8494
    vector<TMap::MAP_T> map = findButtons(port, channels);
107 andreas 8495
 
8496
    if (TError::isError() || map.empty())
8497
        return;
8498
 
8499
    vector<Button::TButton *> buttons = collectButtons(map);
8500
 
8501
    if (buttons.size() > 0)
8502
    {
8503
        vector<Button::TButton *>::iterator mapIter;
8504
 
8505
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
8506
        {
8507
            Button::TButton *bt = *mapIter;
8508
 
8509
            if (btState == 0)       // All instances?
8510
                bt->setDynamic(videoState);
8511
            else
8512
                bt->setDynamic(videoState, btState-1);
8513
        }
8514
    }
8515
}
8516
 
16 andreas 8517
/**
60 andreas 8518
 * Set the border of a button state/states.
8519
 * The border names are available through the TPDesign4 border-name drop-down
8520
 * list.
8521
 */
8522
void TPageManager::doBRD(int port, vector<int>& channels, vector<string>& pars)
8523
{
8524
    DECL_TRACER("TPageManager::doBRD(int port, vector<int>& channels, vector<string>& pars)");
8525
 
8526
    if (pars.size() < 1)
8527
    {
8528
        MSG_ERROR("Expecting at least 1 parameter but got " << pars.size() << "! Ignoring command.");
8529
        return;
8530
    }
8531
 
8532
    TError::clear();
8533
    int btState = atoi(pars[0].c_str());
8534
    string border = "None";
8535
 
8536
    if (pars.size() > 1)
8537
        border = pars[1];
8538
 
193 andreas 8539
    vector<TMap::MAP_T> map = findButtons(port, channels);
60 andreas 8540
 
8541
    if (TError::isError() || map.empty())
8542
        return;
8543
 
8544
    vector<Button::TButton *> buttons = collectButtons(map);
8545
 
83 andreas 8546
    if (buttons.size() > 0)
60 andreas 8547
    {
83 andreas 8548
        vector<Button::TButton *>::iterator mapIter;
60 andreas 8549
 
83 andreas 8550
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
60 andreas 8551
        {
83 andreas 8552
            Button::TButton *bt = *mapIter;
252 andreas 8553
//            setButtonCallbacks(bt);
60 andreas 8554
 
83 andreas 8555
            if (btState == 0)       // All instances?
8556
            {
8557
                int bst = bt->getNumberInstances();
8558
 
8559
                for (int i = 0; i < bst; i++)
106 andreas 8560
                    bt->setBorderStyle(border, i+1);
83 andreas 8561
            }
8562
            else
106 andreas 8563
                bt->setBorderStyle(border, btState);
60 andreas 8564
        }
8565
    }
8566
}
8567
 
107 andreas 8568
void TPageManager::getBRD(int port, vector<int>& channels, vector<string>& pars)
8569
{
8570
    DECL_TRACER("TPageManager::getBRD(int port, vector<int>& channels, vector<string>& pars)");
8571
 
8572
    if (pars.size() < 1)
8573
    {
8574
        MSG_ERROR("Expecting at least 1 parameter but got " << pars.size() << "! Ignoring command.");
8575
        return;
8576
    }
8577
 
8578
    TError::clear();
8579
    int btState = atoi(pars[0].c_str());
8580
 
193 andreas 8581
    vector<TMap::MAP_T> map = findButtons(port, channels);
107 andreas 8582
 
8583
    if (TError::isError() || map.empty())
8584
        return;
8585
 
8586
    vector<Button::TButton *> buttons = collectButtons(map);
8587
 
8588
    if (buttons.size() > 0)
8589
    {
110 andreas 8590
        Button::TButton *bt = buttons[0];
107 andreas 8591
 
110 andreas 8592
        if (btState == 0)       // All instances?
107 andreas 8593
        {
110 andreas 8594
            int bst = bt->getNumberInstances();
107 andreas 8595
 
110 andreas 8596
            for (int i = 0; i < bst; i++)
107 andreas 8597
            {
110 andreas 8598
                string bname = bt->getBorderStyle(i);
300 andreas 8599
                sendCustomEvent(i + 1, (int)bname.length(), 0, bname, 1014, bt->getChannelPort(), bt->getChannelNumber());
107 andreas 8600
            }
8601
        }
110 andreas 8602
        else
8603
        {
8604
            string bname = bt->getBorderStyle(btState-1);
300 andreas 8605
            sendCustomEvent(btState, (int)bname.length(), 0, bname, 1014, bt->getChannelPort(), bt->getChannelNumber());
110 andreas 8606
        }
107 andreas 8607
    }
8608
}
8609
 
60 andreas 8610
/**
16 andreas 8611
 * Set the button size and its position on the page.
8612
 */
8613
void TPageManager::doBSP(int port, vector<int>& channels, vector<string>& pars)
8614
{
8615
    DECL_TRACER("TPageManager::doBSP(int port, vector<int>& channels, vector<string>& pars)");
8616
 
8617
    if (pars.size() < 1)
8618
    {
8619
        MSG_ERROR("Expecting at least 1 parameter but got " << pars.size() << "! Ignoring command.");
341 andreas 8620
#if TESTMODE == 1
8621
        setAllDone();
8622
#endif
16 andreas 8623
        return;
8624
    }
8625
 
8626
    TError::clear();
8627
    bool bLeft = false, bTop = false, bRight = false, bBottom = false;
8628
    int x, y;
8629
 
83 andreas 8630
    if (pars.size() > 0)
16 andreas 8631
    {
83 andreas 8632
        vector<string>::iterator iter;
8633
 
8634
        for (iter = pars.begin(); iter != pars.end(); iter++)
8635
        {
8636
            if (iter->compare("left") == 0)
8637
                bLeft = true;
8638
            else if (iter->compare("top") == 0)
8639
                bTop = true;
8640
            else if (iter->compare("right") == 0)
8641
                bRight = true;
8642
            else if (iter->compare("bottom") == 0)
8643
                bBottom = true;
8644
        }
16 andreas 8645
    }
8646
 
193 andreas 8647
    vector<TMap::MAP_T> map = findButtons(port, channels);
16 andreas 8648
 
8649
    if (TError::isError() || map.empty())
8650
        return;
8651
 
8652
    vector<Button::TButton *> buttons = collectButtons(map);
8653
 
83 andreas 8654
    if (buttons.size() > 0)
16 andreas 8655
    {
83 andreas 8656
        vector<Button::TButton *>::iterator mapIter;
16 andreas 8657
 
83 andreas 8658
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
8659
        {
8660
            Button::TButton *bt = *mapIter;
341 andreas 8661
//            setButtonCallbacks(bt);
16 andreas 8662
 
83 andreas 8663
            if (bLeft)
8664
                x = 0;
16 andreas 8665
 
83 andreas 8666
            if (bTop)
8667
                y = 0;
16 andreas 8668
 
341 andreas 8669
            if (bRight || bBottom)
16 andreas 8670
            {
83 andreas 8671
                ulong handle = bt->getHandle();
8672
                int parentID = (handle >> 16) & 0x0000ffff;
8673
                int pwidth = 0;
341 andreas 8674
                int pheight = 0;
16 andreas 8675
 
83 andreas 8676
                if (parentID < 500)
16 andreas 8677
                {
83 andreas 8678
                    TPage *pg = getPage(parentID);
8679
 
8680
                    if (!pg)
8681
                    {
8682
                        MSG_ERROR("Internal error: Page " << parentID << " not found!");
8683
                        return;
8684
                    }
8685
 
8686
                    pwidth = pg->getWidth();
341 andreas 8687
                    pheight = pg->getHeight();
16 andreas 8688
                }
83 andreas 8689
                else
8690
                {
8691
                    TSubPage *spg = getSubPage(parentID);
16 andreas 8692
 
83 andreas 8693
                    if (!spg)
8694
                    {
8695
                        MSG_ERROR("Internal error: Subpage " << parentID << " not found!");
8696
                        return;
8697
                    }
16 andreas 8698
 
83 andreas 8699
                    pwidth = spg->getWidth();
341 andreas 8700
                    pheight = spg->getHeight();
16 andreas 8701
                }
8702
 
341 andreas 8703
                if (bRight)
8704
                    x = pwidth - bt->getWidth();
8705
 
8706
                if (bBottom)
8707
                    y = pheight - bt->getHeight();
16 andreas 8708
            }
8709
 
341 andreas 8710
            bt->setLeftTop(x, y);
8711
#if TESTMODE == 1
8712
            if (_gTestMode)
83 andreas 8713
            {
341 andreas 8714
                int left = bt->getLeftPosition();
8715
                int top = bt->getTopPosition();
8716
                string res = intToString(left) + "," + intToString(top);
8717
                _gTestMode->setResult(res);
16 andreas 8718
            }
341 andreas 8719
#endif
16 andreas 8720
        }
8721
    }
341 andreas 8722
#if TESTMODE == 1
8723
    setDone();
8724
#endif
16 andreas 8725
}
8726
 
8727
/**
107 andreas 8728
 * Submit text for text area buttons. This command causes the text areas to
8729
 * send their text as strings to the NetLinx Master.
8730
 */
8731
void TPageManager::doBSM(int port, vector<int>& channels, vector<string>&)
8732
{
8733
    DECL_TRACER("TPageManager::doBSM(int port, vector<int>& channels, vector<string>& pars)");
8734
 
8735
    TError::clear();
193 andreas 8736
    vector<TMap::MAP_T> map = findButtons(port, channels);
107 andreas 8737
 
8738
    if (TError::isError() || map.empty())
341 andreas 8739
    {
8740
#if TESTMODE == 1
8741
        setAllDone();
8742
#endif
107 andreas 8743
        return;
341 andreas 8744
    }
107 andreas 8745
 
8746
    vector<Button::TButton *> buttons = collectButtons(map);
8747
 
8748
    if (buttons.size() > 0)
8749
    {
8750
        vector<Button::TButton *>::iterator mapIter;
8751
 
8752
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
8753
        {
8754
            Button::TButton *bt = *mapIter;
8755
 
195 andreas 8756
            if (bt->getButtonType() != TEXT_INPUT && bt->getButtonType() != GENERAL)
341 andreas 8757
            {
8758
#if TESTMODE == 1
8759
                setAllDone();
8760
#endif
107 andreas 8761
                return;
341 andreas 8762
            }
107 andreas 8763
 
8764
            amx::ANET_SEND scmd;
8765
            scmd.port = bt->getChannelPort();
8766
            scmd.channel = bt->getChannelNumber();
8767
            scmd.ID = scmd.channel;
8768
            scmd.msg = bt->getText(0);
8769
            scmd.MC = 0x008b;       // string value
8770
 
8771
            if (gAmxNet)
8772
                gAmxNet->sendCommand(scmd);
8773
            else
8774
                MSG_WARNING("Missing global class TAmxNet. Can't send message!");
8775
 
8776
        }
8777
    }
8778
}
8779
 
8780
/**
8781
 * Set the sound played when a button is pressed. If the sound name is blank
8782
 * the sound is then cleared. If the sound name is not matched, the button
8783
 * sound is not changed.
8784
 */
8785
void TPageManager::doBSO(int port, vector<int>& channels, vector<string>& pars)
8786
{
8787
    DECL_TRACER("TPageManager::doBSO(int port, vector<int>& channels, vector<string>& pars)");
8788
 
8789
    if (pars.size() < 2)
8790
    {
8791
        MSG_ERROR("Expecting 2 parameters but got " << pars.size() << "! Ignoring command.");
8792
        return;
8793
    }
8794
 
8795
    if (!gPrjResources)
8796
        return;
8797
 
8798
    TError::clear();
8799
    int btState = atoi(pars[0].c_str());
8800
    string sound = pars[1];
8801
 
8802
    if (!soundExist(sound))
8803
        return;
8804
 
193 andreas 8805
    vector<TMap::MAP_T> map = findButtons(port, channels);
107 andreas 8806
 
8807
    if (TError::isError() || map.empty())
8808
        return;
8809
 
8810
    vector<Button::TButton *> buttons = collectButtons(map);
8811
 
8812
    if (buttons.size() > 0)
8813
    {
8814
        vector<Button::TButton *>::iterator mapIter;
8815
 
8816
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
8817
        {
8818
            Button::TButton *bt = *mapIter;
8819
 
8820
            if (btState == 0)
8821
            {
8822
                int bst = bt->getNumberInstances();
8823
 
8824
                for (int i = 0; i < bst; i++)
8825
                    bt->setSound(sound, i);
8826
            }
8827
            else
8828
                bt->setSound(sound, btState-1);
8829
        }
8830
    }
8831
}
8832
 
8833
/**
16 andreas 8834
 * Set the button word wrap feature to those buttons with a defined address
8835
 * range. By default, word-wrap is Off.
8836
 */
8837
void TPageManager::doBWW(int port, vector<int>& channels, vector<string>& pars)
8838
{
8839
    DECL_TRACER("TPageManager::doBWW(int port, vector<int>& channels, vector<string>& pars)");
8840
 
8841
    if (pars.size() < 1)
8842
    {
8843
        MSG_ERROR("Expecting 1 parameter but got " << pars.size() << "! Ignoring command.");
8844
        return;
8845
    }
8846
 
8847
    TError::clear();
8848
    int btState = atoi(pars[0].c_str());
8849
 
193 andreas 8850
    vector<TMap::MAP_T> map = findButtons(port, channels);
16 andreas 8851
 
8852
    if (TError::isError() || map.empty())
8853
        return;
8854
 
8855
    vector<Button::TButton *> buttons = collectButtons(map);
8856
 
83 andreas 8857
    if (buttons.size() > 0)
16 andreas 8858
    {
83 andreas 8859
        vector<Button::TButton *>::iterator mapIter;
16 andreas 8860
 
83 andreas 8861
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
16 andreas 8862
        {
83 andreas 8863
            Button::TButton *bt = *mapIter;
252 andreas 8864
//            setButtonCallbacks(bt);
16 andreas 8865
 
83 andreas 8866
            if (btState == 0)       // All instances?
8867
            {
8868
                int bst = bt->getNumberInstances();
8869
                MSG_DEBUG("Setting word wrap on all " << bst << " instances...");
8870
 
8871
                for (int i = 0; i < bst; i++)
110 andreas 8872
                    bt->setTextWordWrap(true, i);
83 andreas 8873
            }
8874
            else
110 andreas 8875
                bt->setTextWordWrap(true, btState - 1);
16 andreas 8876
        }
8877
    }
8878
}
8879
 
108 andreas 8880
void TPageManager::getBWW(int port, vector<int>& channels, vector<string>& pars)
8881
{
8882
    DECL_TRACER("TPageManager::getBWW(int port, vector<int>& channels, vector<string>& pars)");
8883
 
8884
    if (pars.size() < 1)
8885
    {
8886
        MSG_ERROR("Expecting at least 1 parameter but got " << pars.size() << "! Ignoring command.");
8887
        return;
8888
    }
8889
 
8890
    TError::clear();
8891
    int btState = atoi(pars[0].c_str());
8892
 
193 andreas 8893
    vector<TMap::MAP_T> map = findButtons(port, channels);
108 andreas 8894
 
8895
    if (TError::isError() || map.empty())
8896
        return;
8897
 
8898
    vector<Button::TButton *> buttons = collectButtons(map);
8899
 
8900
    if (buttons.size() > 0)
8901
    {
110 andreas 8902
        Button::TButton *bt = buttons[0];
108 andreas 8903
 
110 andreas 8904
        if (btState == 0)       // All instances?
108 andreas 8905
        {
110 andreas 8906
            int bst = bt->getNumberInstances();
108 andreas 8907
 
110 andreas 8908
            for (int i = 0; i < bst; i++)
8909
                sendCustomEvent(i + 1, bt->getTextWordWrap(i), 0, "", 1010, bt->getChannelPort(), bt->getChannelNumber());
108 andreas 8910
        }
110 andreas 8911
        else
8912
            sendCustomEvent(btState, bt->getTextWordWrap(btState-1), 0, "", 1010, bt->getChannelPort(), bt->getChannelNumber());
108 andreas 8913
    }
8914
}
8915
 
16 andreas 8916
/**
8917
 * Clear all page flips from a button.
8918
 */
22 andreas 8919
void TPageManager::doCPF(int port, vector<int>& channels, vector<string>&)
16 andreas 8920
{
8921
    DECL_TRACER("TPageManager::doCPF(int port, vector<int>& channels, vector<string>& pars)");
8922
 
8923
    TError::clear();
193 andreas 8924
    vector<TMap::MAP_T> map = findButtons(port, channels);
16 andreas 8925
 
8926
    if (TError::isError() || map.empty())
8927
        return;
8928
 
8929
    vector<Button::TButton *> buttons = collectButtons(map);
8930
 
83 andreas 8931
    if (buttons.size() > 0)
16 andreas 8932
    {
83 andreas 8933
        vector<Button::TButton *>::iterator mapIter;
8934
 
8935
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
8936
        {
8937
            Button::TButton *bt = *mapIter;
252 andreas 8938
//            setButtonCallbacks(bt);
83 andreas 8939
            bt->clearPushFunctions();
8940
        }
16 andreas 8941
    }
8942
}
8943
 
8944
/**
8945
 * Delete page flips from button if it already exists.
8946
 */
8947
void TPageManager::doDPF(int port, vector<int>& channels, vector<string>& pars)
8948
{
8949
    DECL_TRACER("TPageManager::doDPF(int port, vector<int>& channels, vector<string>& pars)");
8950
 
8951
    if (pars.size() < 1)
8952
    {
8953
        MSG_ERROR("Expecting at least 1 parameter but got " << pars.size() << "! Ignoring command.");
8954
        return;
8955
    }
8956
 
8957
    TError::clear();
8958
    string action = pars[0];
8959
    string pname;
8960
 
8961
    if (pars.size() >= 2)
8962
    {
8963
        pname = pars[1];
8964
        vector<Button::TButton *> list;
8965
        // First we search for a subpage because this is more likely
8966
        TSubPage *spg = getSubPage(pname);
8967
 
8968
        if (spg)
8969
            list = spg->getButtons(port, channels[0]);
8970
        else    // Then for a page
8971
        {
8972
            TPage *pg = getPage(pname);
8973
 
8974
            if (pg)
8975
                list = pg->getButtons(port, channels[0]);
8976
            else
8977
            {
8978
                MSG_WARNING("The name " << pname << " doesn't name either a page or a subpage!");
8979
                return;
8980
            }
8981
        }
8982
 
8983
        if (list.empty())
8984
            return;
8985
 
8986
        vector<Button::TButton *>::iterator it;
8987
 
8988
        for (it = list.begin(); it != list.end(); it++)
8989
        {
8990
            Button::TButton *bt = *it;
252 andreas 8991
//            setButtonCallbacks(bt);
16 andreas 8992
            bt->clearPushFunction(action);
8993
        }
8994
 
8995
        return;
8996
    }
8997
 
8998
    // Here we don't have a page name
193 andreas 8999
    vector<TMap::MAP_T> map = findButtons(port, channels);
16 andreas 9000
 
9001
    if (TError::isError() || map.empty())
9002
        return;
9003
 
9004
    vector<Button::TButton *> buttons = collectButtons(map);
9005
 
83 andreas 9006
    if (buttons.size() > 0)
16 andreas 9007
    {
83 andreas 9008
        vector<Button::TButton *>::iterator mapIter;
9009
 
9010
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
9011
        {
9012
            Button::TButton *bt = *mapIter;
252 andreas 9013
//            setButtonCallbacks(bt);
83 andreas 9014
            bt->clearPushFunction(action);
9015
        }
16 andreas 9016
    }
9017
}
9018
 
9019
/**
9020
 * Enable or disable buttons with a set variable text range.
9021
 */
9022
void TPageManager::doENA(int port, vector<int>& channels, vector<string>& pars)
9023
{
9024
    DECL_TRACER("TPageManager::doENA(int port, vector<int>& channels, vector<string>& pars)");
9025
 
9026
    if (pars.empty())
9027
    {
9028
        MSG_ERROR("Expecting 1 parameter but got none! Ignoring command.");
341 andreas 9029
#if TESTMODE == 1
9030
        setAllDone();
9031
#endif
16 andreas 9032
        return;
9033
    }
9034
 
9035
    TError::clear();
9036
    int cvalue = atoi(pars[0].c_str());
9037
 
193 andreas 9038
    vector<TMap::MAP_T> map = findButtons(port, channels);
16 andreas 9039
 
9040
    if (TError::isError() || map.empty())
341 andreas 9041
    {
9042
#if TESTMODE == 1
9043
        setAllDone();
9044
#endif
16 andreas 9045
        return;
341 andreas 9046
    }
16 andreas 9047
 
9048
    vector<Button::TButton *> buttons = collectButtons(map);
9049
 
83 andreas 9050
    if (buttons.size() > 0)
16 andreas 9051
    {
83 andreas 9052
        vector<Button::TButton *>::iterator mapIter;
9053
 
9054
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
9055
        {
9056
            Button::TButton *bt = *mapIter;
9057
            bt->setEnable(((cvalue)?true:false));
341 andreas 9058
#if TESTMODE == 1
9059
            __success = true;
9060
 
9061
            if (_gTestMode)
9062
                _gTestMode->setResult(intToString(cvalue));
9063
#endif
83 andreas 9064
        }
16 andreas 9065
    }
341 andreas 9066
#if TESTMODE == 1
9067
    setAllDone();
9068
#endif
16 andreas 9069
}
9070
 
9071
/**
9072
 * Set a font to a specific Font ID value for those buttons with a defined
9073
 * address range. Font ID numbers are generated by the TPDesign4 programmers
9074
 * report.
9075
 */
9076
void TPageManager::doFON(int port, vector<int>& channels, vector<string>& pars)
9077
{
9078
    DECL_TRACER("TPageManager::doFON(int port, vector<int>& channels, vector<string>& pars)");
9079
 
9080
    if (pars.size() < 2)
9081
    {
9082
        MSG_ERROR("Expecting 2 parameters but got " << pars.size() << "! Ignoring command.");
342 andreas 9083
#if TESTMODE == 1
9084
        setAllDone();
9085
#endif
16 andreas 9086
        return;
9087
    }
9088
 
9089
    TError::clear();
342 andreas 9090
    int btState = atoi(pars[0].c_str()) - 1;
16 andreas 9091
    int fvalue = atoi(pars[1].c_str());
9092
 
193 andreas 9093
    vector<TMap::MAP_T> map = findButtons(port, channels);
16 andreas 9094
 
9095
    if (TError::isError() || map.empty())
9096
        return;
9097
 
9098
    vector<Button::TButton *> buttons = collectButtons(map);
9099
 
83 andreas 9100
    if (buttons.size() > 0)
16 andreas 9101
    {
83 andreas 9102
        vector<Button::TButton *>::iterator mapIter;
16 andreas 9103
 
83 andreas 9104
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
16 andreas 9105
        {
83 andreas 9106
            Button::TButton *bt = *mapIter;
342 andreas 9107
            bt->setFont(fvalue, btState);
9108
#if TESTMODE == 1
9109
            if (_gTestMode)
9110
                _gTestMode->setResult(intToString(bt->getFontIndex(btState < 0 ? 0 : btState)));
9111
#endif
16 andreas 9112
        }
9113
    }
342 andreas 9114
#if TESTMODE == 1
9115
    setDone();
9116
#endif
16 andreas 9117
}
9118
 
108 andreas 9119
void TPageManager::getFON(int port, vector<int>& channels, vector<string>& pars)
9120
{
9121
    DECL_TRACER("TPageManager::getFON(int port, vector<int>& channels, vector<string>& pars)");
9122
 
9123
    if (pars.size() < 1)
9124
    {
9125
        MSG_ERROR("Expecting at least 1 parameter but got " << pars.size() << "! Ignoring command.");
342 andreas 9126
#if TESTMODE == 1
9127
        setAllDone();
9128
#endif
108 andreas 9129
        return;
9130
    }
9131
 
9132
    TError::clear();
9133
    int btState = atoi(pars[0].c_str());
9134
 
193 andreas 9135
    vector<TMap::MAP_T> map = findButtons(port, channels);
108 andreas 9136
 
9137
    if (TError::isError() || map.empty())
342 andreas 9138
    {
9139
#if TESTMODE == 1
9140
        setAllDone();
9141
#endif
108 andreas 9142
        return;
342 andreas 9143
    }
108 andreas 9144
 
9145
    vector<Button::TButton *> buttons = collectButtons(map);
9146
 
9147
    if (buttons.size() > 0)
9148
    {
110 andreas 9149
        Button::TButton *bt = buttons[0];
108 andreas 9150
 
110 andreas 9151
        if (btState == 0)       // All instances?
108 andreas 9152
        {
110 andreas 9153
            int bst = bt->getNumberInstances();
108 andreas 9154
 
110 andreas 9155
            for (int i = 0; i < bst; i++)
9156
                sendCustomEvent(i + 1, bt->getFontIndex(i), 0, "", 1007, bt->getChannelPort(), bt->getChannelNumber());
108 andreas 9157
        }
110 andreas 9158
        else
9159
            sendCustomEvent(btState, bt->getFontIndex(btState - 1), 0, "", 1007, bt->getChannelPort(), bt->getChannelNumber());
342 andreas 9160
#if TESTMODE == 1
9161
        if (_gTestMode)
9162
            _gTestMode->setResult(intToString(bt->getFontIndex(btState < 0 ? 0 : btState)));
9163
#endif
108 andreas 9164
    }
342 andreas 9165
#if TESTMODE == 1
9166
    __success = true;
9167
    setAllDone();
9168
#endif
108 andreas 9169
}
9170
 
388 andreas 9171
void TPageManager::doGDI(int port, vector<int>& channels, vector<std::string>& pars)
9172
{
9173
    DECL_TRACER("TPageManager::doGDI(int port, vector<int>& channels, vector<std::string>& pars)");
9174
 
9175
    if (pars.size() < 1)
9176
    {
9177
        MSG_ERROR("Expecting 1 parameter but got " << pars.size() << "! Ignoring command.");
9178
        return;
9179
    }
9180
 
9181
    TError::clear();
9182
    int inc = atoi(pars[0].c_str());
9183
 
9184
    if (inc < 0)
9185
    {
9186
        MSG_ERROR("Invalid drag increment of " << inc << "!");
9187
        return;
9188
    }
9189
 
9190
    vector<TMap::MAP_T> map = findButtons(port, channels);
9191
 
9192
    if (TError::isError() || map.empty())
9193
        return;
9194
 
9195
    vector<Button::TButton *> buttons = collectButtons(map);
9196
 
9197
    if (buttons.size() > 0)
9198
    {
9199
        vector<Button::TButton *>::iterator mapIter;
9200
 
9201
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
9202
        {
9203
            Button::TButton *bt = *mapIter;
9204
            bt->setBargraphDragIncrement(inc);
9205
        }
9206
    }
9207
}
9208
/* Currently not implemented
9209
void TPageManager::doGDV(int port, vector<int>& channels, vector<std::string>& pars)
9210
{
9211
    DECL_TRACER("TPageManager::doGDV(int port, vector<int>& channels, vector<std::string>& pars)");
9212
}
9213
*/
16 andreas 9214
/**
60 andreas 9215
 * Change the bargraph upper limit.
9216
 */
9217
void TPageManager::doGLH(int port, vector<int>& channels, vector<std::string>& pars)
9218
{
9219
    DECL_TRACER("TPageManager::doGLH(int port, vector<int>& channels, vector<std::string>& pars)");
9220
 
9221
    if (pars.size() < 1)
9222
    {
9223
        MSG_ERROR("Expecting 1 parameter but got " << pars.size() << "! Ignoring command.");
9224
        return;
9225
    }
9226
 
9227
    TError::clear();
9228
    int limit = atoi(pars[0].c_str());
9229
 
9230
    if (limit < 1)
9231
    {
9232
        MSG_ERROR("Invalid upper limit " << limit << "!");
9233
        return;
9234
    }
9235
 
193 andreas 9236
    vector<TMap::MAP_T> map = findButtons(port, channels);
60 andreas 9237
 
9238
    if (TError::isError() || map.empty())
9239
        return;
9240
 
9241
    vector<Button::TButton *> buttons = collectButtons(map);
9242
 
83 andreas 9243
    if (buttons.size() > 0)
60 andreas 9244
    {
83 andreas 9245
        vector<Button::TButton *>::iterator mapIter;
9246
 
9247
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
9248
        {
9249
            Button::TButton *bt = *mapIter;
252 andreas 9250
//            setButtonCallbacks(bt);
83 andreas 9251
            bt->setBargraphUpperLimit(limit);
9252
        }
60 andreas 9253
    }
9254
}
9255
 
9256
/**
9257
 * Change the bargraph lower limit.
9258
 */
9259
void TPageManager::doGLL(int port, vector<int>& channels, vector<std::string>& pars)
9260
{
9261
    DECL_TRACER("TPageManager::doGLL(int port, vector<int>& channels, vector<std::string>& pars)");
9262
 
9263
    if (pars.size() < 1)
9264
    {
9265
        MSG_ERROR("Expecting 1 parameter but got " << pars.size() << "! Ignoring command.");
9266
        return;
9267
    }
9268
 
9269
    TError::clear();
9270
    int limit = atoi(pars[0].c_str());
9271
 
9272
    if (limit < 1)
9273
    {
9274
        MSG_ERROR("Invalid lower limit " << limit << "!");
9275
        return;
9276
    }
9277
 
193 andreas 9278
    vector<TMap::MAP_T> map = findButtons(port, channels);
60 andreas 9279
 
9280
    if (TError::isError() || map.empty())
9281
        return;
9282
 
9283
    vector<Button::TButton *> buttons = collectButtons(map);
9284
 
83 andreas 9285
    if (buttons.size() > 0)
60 andreas 9286
    {
83 andreas 9287
        vector<Button::TButton *>::iterator mapIter;
9288
 
9289
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
9290
        {
9291
            Button::TButton *bt = *mapIter;
252 andreas 9292
//            setButtonCallbacks(bt);
83 andreas 9293
            bt->setBargraphLowerLimit(limit);
9294
        }
60 andreas 9295
    }
9296
}
9297
 
108 andreas 9298
void TPageManager::doGSC(int port, vector<int>& channels, vector<string>& pars)
9299
{
9300
    DECL_TRACER("TPageManager::doGSC(int port, vector<int>& channels, vector<string>& pars)");
9301
 
9302
    if (pars.size() < 1)
9303
    {
9304
        MSG_ERROR("Expecting 1 parameter but got " << pars.size() << "! Ignoring command.");
9305
        return;
9306
    }
9307
 
9308
    TError::clear();
9309
    string color = pars[0];
193 andreas 9310
    vector<TMap::MAP_T> map = findButtons(port, channels);
108 andreas 9311
 
9312
    if (TError::isError() || map.empty())
9313
        return;
9314
 
9315
    vector<Button::TButton *> buttons = collectButtons(map);
9316
 
9317
    if (buttons.size() > 0)
9318
    {
9319
        vector<Button::TButton *>::iterator mapIter;
9320
 
9321
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
9322
        {
9323
            Button::TButton *bt = *mapIter;
9324
            bt->setBargraphSliderColor(color);
9325
        }
9326
    }
9327
}
9328
 
361 andreas 9329
/*
388 andreas 9330
 * Set bargraph ramp down time in 1/10 seconds.
9331
 */
9332
void TPageManager::doGRD(int port, vector<int>& channels, vector<string>& pars)
9333
{
9334
    DECL_TRACER("TPageManager::doGRD(int port, vector<int>& channels, vector<string>& pars)");
9335
 
9336
    if (pars.size() < 1)
9337
    {
9338
        MSG_ERROR("Expecting 1 parameter but got " << pars.size() << "! Ignoring command.");
9339
        return;
9340
    }
9341
 
9342
    TError::clear();
9343
    int t = atoi(pars[0].c_str());
9344
 
9345
    if (t < 0)
9346
    {
9347
        MSG_ERROR("Invalid ramp down time limit " << t << "!");
9348
        return;
9349
    }
9350
 
9351
    vector<TMap::MAP_T> map = findButtons(port, channels);
9352
 
9353
    if (TError::isError() || map.empty())
9354
        return;
9355
 
9356
    vector<Button::TButton *> buttons = collectButtons(map);
9357
 
9358
    if (buttons.size() > 0)
9359
    {
9360
        vector<Button::TButton *>::iterator mapIter;
9361
 
9362
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
9363
        {
9364
            Button::TButton *bt = *mapIter;
9365
            bt->setBargraphRampDownTime(t);
9366
        }
9367
    }
9368
}
9369
 
9370
/*
9371
 * Set bargraph ramp up time in 1/10 seconds.
9372
 */
9373
void TPageManager::doGRU(int port, vector<int>& channels, vector<string>& pars)
9374
{
9375
    DECL_TRACER("TPageManager::doGRU(int port, vector<int>& channels, vector<string>& pars)");
9376
 
9377
    if (pars.size() < 1)
9378
    {
9379
        MSG_ERROR("Expecting 1 parameter but got " << pars.size() << "! Ignoring command.");
9380
        return;
9381
    }
9382
 
9383
    TError::clear();
9384
    int t = atoi(pars[0].c_str());
9385
 
9386
    if (t < 0)
9387
    {
9388
        MSG_ERROR("Invalid ramp up time limit " << t << "!");
9389
        return;
9390
    }
9391
 
9392
    vector<TMap::MAP_T> map = findButtons(port, channels);
9393
 
9394
    if (TError::isError() || map.empty())
9395
        return;
9396
 
9397
    vector<Button::TButton *> buttons = collectButtons(map);
9398
 
9399
    if (buttons.size() > 0)
9400
    {
9401
        vector<Button::TButton *>::iterator mapIter;
9402
 
9403
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
9404
        {
9405
            Button::TButton *bt = *mapIter;
9406
            bt->setBargraphRampUpTime(t);
9407
        }
9408
    }
9409
}
9410
 
9411
/*
361 andreas 9412
 * Change the bargraph slider name or joystick cursor name.
9413
 */
9414
void TPageManager::doGSN(int port, vector<int>& channels, vector<string>& pars)
9415
{
9416
    DECL_TRACER("TPageManager::doGSN(int port, vector<int>& channels, vector<string>& pars)");
9417
 
9418
    if (pars.size() < 1)
9419
    {
9420
        MSG_ERROR("Expecting 1 parameter but got " << pars.size() << "! Ignoring command.");
9421
        return;
9422
    }
9423
 
9424
    TError::clear();
9425
    string name = pars[0];
9426
    vector<TMap::MAP_T> map = findButtons(port, channels);
9427
 
9428
    if (TError::isError() || map.empty())
9429
        return;
9430
 
9431
    vector<Button::TButton *> buttons = collectButtons(map);
9432
 
9433
    if (buttons.size() > 0)
9434
    {
9435
        vector<Button::TButton *>::iterator mapIter;
9436
 
9437
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
9438
        {
9439
            Button::TButton *bt = *mapIter;
9440
            bt->setBargraphSliderName(name);
9441
        }
9442
    }
9443
}
9444
 
60 andreas 9445
/**
14 andreas 9446
 * Set the icon to a button.
9447
 */
9448
void TPageManager::doICO(int port, vector<int>& channels, vector<string>& pars)
9449
{
9450
    DECL_TRACER("TPageManager::doICO(int port, vector<int>& channels, vector<string>& pars)");
9451
 
9452
    if (pars.size() < 2)
9453
    {
9454
        MSG_ERROR("Expecting 2 parameters but got " << pars.size() << "! Ignoring command.");
9455
        return;
9456
    }
9457
 
16 andreas 9458
    TError::clear();
14 andreas 9459
    int btState = atoi(pars[0].c_str());
9460
    int iconIdx = atoi(pars[1].c_str());
9461
 
193 andreas 9462
    vector<TMap::MAP_T> map = findButtons(port, channels);
14 andreas 9463
 
9464
    if (TError::isError() || map.empty())
9465
        return;
9466
 
9467
    vector<Button::TButton *> buttons = collectButtons(map);
9468
 
83 andreas 9469
    if (buttons.size() > 0)
14 andreas 9470
    {
83 andreas 9471
        vector<Button::TButton *>::iterator mapIter;
14 andreas 9472
 
83 andreas 9473
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
14 andreas 9474
        {
83 andreas 9475
            Button::TButton *bt = *mapIter;
14 andreas 9476
 
83 andreas 9477
            if (btState == 0)       // All instances?
14 andreas 9478
            {
316 andreas 9479
                if (iconIdx > 0)
9480
                    bt->setIcon(iconIdx, -1);
9481
                else
9482
                    bt->revokeIcon(-1);
14 andreas 9483
            }
83 andreas 9484
            else if (iconIdx > 0)
9485
                bt->setIcon(iconIdx, btState - 1);
9486
            else
9487
                bt->revokeIcon(btState - 1);
14 andreas 9488
        }
9489
    }
9490
}
9491
 
108 andreas 9492
void TPageManager::getICO(int port, vector<int>& channels, vector<string>& pars)
9493
{
9494
    DECL_TRACER("TPageManager::getICO(int port, vector<int>& channels, vector<string>& pars)");
9495
 
9496
    if (pars.size() < 1)
9497
    {
9498
        MSG_ERROR("Expecting at least 1 parameter but got " << pars.size() << "! Ignoring command.");
9499
        return;
9500
    }
9501
 
9502
    TError::clear();
9503
    int btState = atoi(pars[0].c_str());
9504
 
193 andreas 9505
    vector<TMap::MAP_T> map = findButtons(port, channels);
108 andreas 9506
 
9507
    if (TError::isError() || map.empty())
9508
        return;
9509
 
9510
    vector<Button::TButton *> buttons = collectButtons(map);
9511
 
9512
    if (buttons.size() > 0)
9513
    {
110 andreas 9514
        Button::TButton *bt = buttons[0];
108 andreas 9515
 
110 andreas 9516
        if (btState == 0)       // All instances?
108 andreas 9517
        {
110 andreas 9518
            int bst = bt->getNumberInstances();
108 andreas 9519
 
110 andreas 9520
            for (int i = 0; i < bst; i++)
9521
                sendCustomEvent(i + 1, bt->getIconIndex(i), 0, "", 1003, bt->getChannelPort(), bt->getChannelNumber());
108 andreas 9522
        }
110 andreas 9523
        else
9524
            sendCustomEvent(btState, bt->getIconIndex(btState - 1), 0, "", 1003, bt->getChannelPort(), bt->getChannelNumber());
108 andreas 9525
    }
9526
}
9527
 
14 andreas 9528
/**
108 andreas 9529
 * Set bitmap/picture alignment using a numeric keypad layout for those buttons
9530
 * with a defined address range. The alignment of 0 is followed by
9531
 * ',<left>,<top>'. The left and top coordinates are relative to the upper left
9532
 * corner of the button.
9533
 */
9534
void TPageManager::doJSB(int port, vector<int>& channels, vector<string>& pars)
9535
{
9536
    DECL_TRACER("TPageManager::doJSB(int port, vector<int>& channels, vector<string>& pars)");
9537
 
9538
    if (pars.size() < 2)
9539
    {
9540
        MSG_ERROR("Expecting at least 2 parameters but got less! Ignoring command.");
9541
        return;
9542
    }
9543
 
9544
    TError::clear();
9545
    int btState = atoi(pars[0].c_str());
9546
    int align = atoi(pars[1].c_str());
9547
    int x = 0, y = 0;
9548
 
9549
    if (!align && pars.size() >= 3)
9550
    {
9551
        x = atoi(pars[2].c_str());
9552
 
9553
        if (pars.size() >= 4)
9554
            y = atoi(pars[3].c_str());
9555
    }
9556
 
193 andreas 9557
    vector<TMap::MAP_T> map = findButtons(port, channels);
108 andreas 9558
 
9559
    if (TError::isError() || map.empty())
9560
        return;
9561
 
9562
    vector<Button::TButton *> buttons = collectButtons(map);
9563
 
9564
    if (buttons.size() > 0)
9565
    {
9566
        vector<Button::TButton *>::iterator mapIter;
9567
 
9568
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
9569
        {
9570
            Button::TButton *bt = *mapIter;
9571
 
9572
            if (btState == 0)
9573
                bt->setBitmapJustification(align, x, y, -1);
9574
            else
9575
                bt->setBitmapJustification(align, x, y, btState-1);
9576
        }
9577
    }
9578
}
9579
 
9580
void TPageManager::getJSB(int port, vector<int>& channels, vector<string>& pars)
9581
{
9582
    DECL_TRACER("TPageManager::getJSB(int port, vector<int>& channels, vector<string>& pars)");
9583
 
9584
    if (pars.size() < 1)
9585
    {
9586
        MSG_ERROR("Expecting at least 1 parameter but got " << pars.size() << "! Ignoring command.");
9587
        return;
9588
    }
9589
 
9590
    TError::clear();
9591
    int btState = atoi(pars[0].c_str());
9592
    int j, x, y;
9593
 
193 andreas 9594
    vector<TMap::MAP_T> map = findButtons(port, channels);
108 andreas 9595
 
9596
    if (TError::isError() || map.empty())
9597
        return;
9598
 
9599
    vector<Button::TButton *> buttons = collectButtons(map);
9600
 
9601
    if (buttons.size() > 0)
9602
    {
110 andreas 9603
        Button::TButton *bt = buttons[0];
108 andreas 9604
 
110 andreas 9605
        if (btState == 0)       // All instances?
108 andreas 9606
        {
110 andreas 9607
            int bst = bt->getNumberInstances();
108 andreas 9608
 
110 andreas 9609
            for (int i = 0; i < bst; i++)
108 andreas 9610
            {
110 andreas 9611
                j = bt->getBitmapJustification(&x, &y, i);
9612
                sendCustomEvent(i + 1, j, 0, "", 1005, bt->getChannelPort(), bt->getChannelNumber());
108 andreas 9613
            }
9614
        }
110 andreas 9615
        else
9616
        {
9617
            j = bt->getBitmapJustification(&x, &y, btState-1);
9618
            sendCustomEvent(btState, j, 0, "", 1005, bt->getChannelPort(), bt->getChannelNumber());
9619
        }
108 andreas 9620
    }
9621
}
9622
 
9623
/**
9624
 * Set icon alignment using a numeric keypad layout for those buttons with a
9625
 * defined address range. The alignment of 0 is followed by ',<left>,<top>'.
9626
 * The left and top coordinates are relative to the upper left corner of the
9627
 * button.
9628
 */
9629
void TPageManager::doJSI(int port, vector<int>& channels, vector<string>& pars)
9630
{
9631
    DECL_TRACER("TPageManager::doJSB(int port, vector<int>& channels, vector<string>& pars)");
9632
 
9633
    if (pars.size() < 2)
9634
    {
9635
        MSG_ERROR("Expecting at least 2 parameters but got less! Ignoring command.");
9636
        return;
9637
    }
9638
 
9639
    TError::clear();
9640
    int btState = atoi(pars[0].c_str());
9641
    int align = atoi(pars[1].c_str());
9642
    int x = 0, y = 0;
9643
 
9644
    if (!align && pars.size() >= 3)
9645
    {
9646
        x = atoi(pars[2].c_str());
9647
 
9648
        if (pars.size() >= 4)
9649
            y = atoi(pars[3].c_str());
9650
    }
9651
 
193 andreas 9652
    vector<TMap::MAP_T> map = findButtons(port, channels);
108 andreas 9653
 
9654
    if (TError::isError() || map.empty())
9655
        return;
9656
 
9657
    vector<Button::TButton *> buttons = collectButtons(map);
9658
 
9659
    if (buttons.size() > 0)
9660
    {
9661
        vector<Button::TButton *>::iterator mapIter;
9662
 
9663
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
9664
        {
9665
            Button::TButton *bt = *mapIter;
9666
 
9667
            if (btState == 0)
9668
                bt->setIconJustification(align, x, y, -1);
9669
            else
9670
                bt->setIconJustification(align, x, y, btState-1);
9671
        }
9672
    }
9673
}
9674
 
9675
void TPageManager::getJSI(int port, vector<int>& channels, vector<string>& pars)
9676
{
9677
    DECL_TRACER("TPageManager::getJSB(int port, vector<int>& channels, vector<string>& pars)");
9678
 
9679
    if (pars.size() < 1)
9680
    {
9681
        MSG_ERROR("Expecting at least 1 parameter but got " << pars.size() << "! Ignoring command.");
9682
        return;
9683
    }
9684
 
9685
    TError::clear();
9686
    int btState = atoi(pars[0].c_str());
9687
    int j, x, y;
9688
 
193 andreas 9689
    vector<TMap::MAP_T> map = findButtons(port, channels);
108 andreas 9690
 
9691
    if (TError::isError() || map.empty())
9692
        return;
9693
 
9694
    vector<Button::TButton *> buttons = collectButtons(map);
9695
 
9696
    if (buttons.size() > 0)
9697
    {
110 andreas 9698
        Button::TButton *bt = buttons[0];
108 andreas 9699
 
110 andreas 9700
        if (btState == 0)       // All instances?
108 andreas 9701
        {
110 andreas 9702
            int bst = bt->getNumberInstances();
108 andreas 9703
 
110 andreas 9704
            for (int i = 0; i < bst; i++)
108 andreas 9705
            {
110 andreas 9706
                j = bt->getIconJustification(&x, &y, i);
9707
                sendCustomEvent(i + 1, j, 0, "", 1006, bt->getChannelPort(), bt->getChannelNumber());
108 andreas 9708
            }
9709
        }
110 andreas 9710
        else
9711
        {
9712
            j = bt->getIconJustification(&x, &y, btState-1);
9713
            sendCustomEvent(btState, j, 0, "", 1006, bt->getChannelPort(), bt->getChannelNumber());
9714
        }
108 andreas 9715
    }
9716
}
9717
 
9718
void TPageManager::doJST(int port, vector<int>& channels, vector<string>& pars)
9719
{
9720
    DECL_TRACER("TPageManager::doJSB(int port, vector<int>& channels, vector<string>& pars)");
9721
 
9722
    if (pars.size() < 2)
9723
    {
9724
        MSG_ERROR("Expecting at least 2 parameters but got less! Ignoring command.");
9725
        return;
9726
    }
9727
 
9728
    TError::clear();
9729
    int btState = atoi(pars[0].c_str());
9730
    int align = atoi(pars[1].c_str());
9731
    int x = 0, y = 0;
9732
 
9733
    if (!align && pars.size() >= 3)
9734
    {
9735
        x = atoi(pars[2].c_str());
9736
 
9737
        if (pars.size() >= 4)
9738
            y = atoi(pars[3].c_str());
9739
    }
9740
 
193 andreas 9741
    vector<TMap::MAP_T> map = findButtons(port, channels);
108 andreas 9742
 
9743
    if (TError::isError() || map.empty())
9744
        return;
9745
 
9746
    vector<Button::TButton *> buttons = collectButtons(map);
9747
 
9748
    if (buttons.size() > 0)
9749
    {
9750
        vector<Button::TButton *>::iterator mapIter;
9751
 
9752
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
9753
        {
9754
            Button::TButton *bt = *mapIter;
9755
 
9756
            if (btState == 0)
9757
                bt->setTextJustification(align, x, y, -1);
9758
            else
9759
                bt->setTextJustification(align, x, y, btState-1);
9760
        }
9761
    }
9762
}
9763
 
9764
void TPageManager::getJST(int port, vector<int>& channels, vector<string>& pars)
9765
{
9766
    DECL_TRACER("TPageManager::getJSB(int port, vector<int>& channels, vector<string>& pars)");
9767
 
9768
    if (pars.size() < 1)
9769
    {
9770
        MSG_ERROR("Expecting at least 1 parameter but got " << pars.size() << "! Ignoring command.");
9771
        return;
9772
    }
9773
 
9774
    TError::clear();
9775
    int btState = atoi(pars[0].c_str());
9776
    int j, x, y;
9777
 
193 andreas 9778
    vector<TMap::MAP_T> map = findButtons(port, channels);
108 andreas 9779
 
9780
    if (TError::isError() || map.empty())
9781
        return;
9782
 
9783
    vector<Button::TButton *> buttons = collectButtons(map);
9784
 
9785
    if (buttons.size() > 0)
9786
    {
110 andreas 9787
        Button::TButton *bt = buttons[0];
108 andreas 9788
 
110 andreas 9789
        if (btState == 0)       // All instances?
108 andreas 9790
        {
110 andreas 9791
            int bst = bt->getNumberInstances();
108 andreas 9792
 
110 andreas 9793
            for (int i = 0; i < bst; i++)
108 andreas 9794
            {
110 andreas 9795
                j = bt->getTextJustification(&x, &y, i);
9796
                sendCustomEvent(i + 1, j, 0, "", 1004, bt->getChannelPort(), bt->getChannelNumber());
108 andreas 9797
            }
9798
        }
110 andreas 9799
        else
9800
        {
9801
            j = bt->getTextJustification(&x, &y, btState-1);
9802
            sendCustomEvent(btState, j, 0, "", 1004, bt->getChannelPort(), bt->getChannelNumber());
9803
        }
108 andreas 9804
    }
9805
}
9806
 
9807
/**
395 andreas 9808
 * @brief TPageManager::getMSP
9809
 * Sets the speed of a marquee line. Allowed range is from 1 to 10, where 10 is
9810
 * the fastest speed.
9811
 *
9812
 * @param port      The port number
9813
 * @param channels  The channels
9814
 * @param pars      Parameters
9815
 */
9816
void TPageManager::doMSP(int port, vector<int>& channels, vector<string>& pars)
9817
{
9818
    DECL_TRACER("TPageManager::getMSP(int port, vector<int>& channels, vector<string>& pars)");
9819
 
9820
    if (pars.size() < 2)
9821
    {
9822
        MSG_ERROR("Expecting at least 2 parameter but got less! Command ignored.");
9823
        return;
9824
    }
9825
 
9826
    TError::clear();
9827
    int btState = atoi(pars[0].c_str()) - 1;
9828
    int speed = atoi(pars[1].c_str());
9829
 
9830
    if (speed < 1 || speed > 10)
9831
    {
9832
        MSG_ERROR("Speed for marquee line is out of range!");
9833
        return;
9834
    }
9835
 
9836
    vector<TMap::MAP_T> map = findButtons(port, channels);
9837
 
9838
    if (TError::isError() || map.empty())
9839
        return;
9840
 
9841
    vector<Button::TButton *> buttons = collectButtons(map);
9842
 
9843
    if (buttons.size() > 0)
9844
    {
9845
        vector<Button::TButton *>::iterator iter;
9846
 
9847
        for (iter = buttons.begin(); iter != buttons.end(); ++iter)
9848
        {
9849
            Button::TButton *bt = buttons[0];
9850
            bt->setMarqueeSpeed(speed, btState);
9851
        }
9852
    }
9853
}
9854
 
9855
/**
16 andreas 9856
 * Show or hide a button with a set variable text range.
9857
 */
9858
void TPageManager::doSHO(int port, vector<int>& channels, vector<string>& pars)
9859
{
9860
    DECL_TRACER("TPageManager::doSHO(int port, vector<int>& channels, vector<string>& pars)");
9861
 
9862
    if (pars.empty())
9863
    {
9864
        MSG_ERROR("Expecting 1 parameter but got none! Ignoring command.");
9865
        return;
9866
    }
9867
 
9868
    TError::clear();
9869
    int cvalue = atoi(pars[0].c_str());
9870
 
193 andreas 9871
    vector<TMap::MAP_T> map = findButtons(port, channels);
16 andreas 9872
 
9873
    if (TError::isError() || map.empty())
9874
        return;
9875
 
9876
    vector<Button::TButton *> buttons = collectButtons(map);
9877
 
83 andreas 9878
    if (buttons.size() > 0)
16 andreas 9879
    {
83 andreas 9880
        vector<Button::TButton *>::iterator mapIter;
9881
 
9882
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
9883
        {
9884
            Button::TButton *bt = *mapIter;
318 andreas 9885
 
100 andreas 9886
            int pgID = (bt->getParent() >> 16) & 0x0000ffff;
9887
            bool pVisible = false;
9888
 
9889
            if (pgID < 500)
9890
            {
9891
                TPage *pg = getPage(pgID);
9892
 
9893
                if (pg && pg->isVisilble())
9894
                    pVisible = true;
9895
            }
9896
            else
9897
            {
9898
                TSubPage *pg = getSubPage(pgID);
9899
 
9900
                if (pg && pg->isVisible())
9901
                    pVisible = true;
9902
            }
9903
 
151 andreas 9904
            bool oldV = bt->isVisible();
9905
            bool visible = cvalue ? true : false;
9906
            MSG_DEBUG("Button " << bt->getButtonIndex() << ", \"" << bt->getButtonName() << "\" set " << (visible ? "VISIBLE" : "HIDDEN") << " (Previous: " << (oldV ? "VISIBLE" : "HIDDEN") << ")");
98 andreas 9907
 
151 andreas 9908
            if (visible != oldV)
100 andreas 9909
            {
151 andreas 9910
                bt->setVisible(visible);
100 andreas 9911
 
151 andreas 9912
                if (pVisible)
9913
                {
9914
                    setButtonCallbacks(bt);
9915
 
9916
                    if (_setVisible)
9917
                        _setVisible(bt->getHandle(), visible);
9918
                    else
9919
                        bt->refresh();
9920
                }
100 andreas 9921
            }
83 andreas 9922
        }
16 andreas 9923
    }
9924
}
9925
 
108 andreas 9926
void TPageManager::doTEC(int port, vector<int>& channels, vector<string>& pars)
9927
{
9928
    DECL_TRACER("TPageManager::doTEC(int port, vector<int>& channels, vector<string>& pars)");
9929
 
9930
    if (pars.size() < 2)
9931
    {
9932
        MSG_ERROR("Expecting at least 2 parameters but got less! Ignoring command.");
9933
        return;
9934
    }
9935
 
9936
    TError::clear();
9937
    int btState = atoi(pars[0].c_str());
9938
    string color = pars[1];
9939
 
193 andreas 9940
    vector<TMap::MAP_T> map = findButtons(port, channels);
108 andreas 9941
 
9942
    if (TError::isError() || map.empty())
9943
        return;
9944
 
9945
    vector<Button::TButton *> buttons = collectButtons(map);
9946
 
9947
    if (buttons.size() > 0)
9948
    {
9949
        vector<Button::TButton *>::iterator mapIter;
9950
 
9951
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
9952
        {
9953
            Button::TButton *bt = *mapIter;
9954
 
9955
            if (btState == 0)
9956
                bt->setTextEffectColor(color);
9957
            else
9958
                bt->setTextEffectColor(color, btState-1);
9959
        }
9960
    }
9961
}
9962
 
9963
void TPageManager::getTEC(int port, vector<int>& channels, vector<string>& pars)
9964
{
9965
    DECL_TRACER("TPageManager::getTEC(int port, vector<int>& channels, vector<string>& pars)");
9966
 
9967
    if (pars.size() < 1)
9968
    {
9969
        MSG_ERROR("Expecting at least 1 parameter but got " << pars.size() << "! Ignoring command.");
9970
        return;
9971
    }
9972
 
9973
    TError::clear();
9974
    int btState = atoi(pars[0].c_str());
9975
 
193 andreas 9976
    vector<TMap::MAP_T> map = findButtons(port, channels);
108 andreas 9977
 
9978
    if (TError::isError() || map.empty())
9979
        return;
9980
 
9981
    vector<Button::TButton *> buttons = collectButtons(map);
9982
 
9983
    if (buttons.size() > 0)
9984
    {
110 andreas 9985
        Button::TButton *bt = buttons[0];
9986
 
9987
        if (btState == 0)       // All instances?
9988
        {
9989
            int bst = bt->getNumberInstances();
9990
 
9991
            for (int i = 0; i < bst; i++)
9992
            {
9993
                string c = bt->getTextEffectColor(i);
300 andreas 9994
                sendCustomEvent(i + 1, (int)c.length(), 0, c, 1009, bt->getChannelPort(), bt->getChannelNumber());
110 andreas 9995
            }
9996
        }
9997
        else
9998
        {
9999
            string c = bt->getTextEffectColor(btState-1);
300 andreas 10000
            sendCustomEvent(btState, (int)c.length(), 0, c, 1009, bt->getChannelPort(), bt->getChannelNumber());
110 andreas 10001
        }
10002
    }
10003
}
10004
 
10005
void TPageManager::doTEF(int port, vector<int>& channels, vector<string>& pars)
10006
{
10007
    DECL_TRACER("TPageManager::doTEF(int port, vector<int>& channels, vector<string>& pars)");
10008
 
10009
    if (pars.size() < 2)
10010
    {
10011
        MSG_ERROR("Expecting at least 2 parameters but got less! Ignoring command.");
10012
        return;
10013
    }
10014
 
10015
    TError::clear();
10016
    int btState = atoi(pars[0].c_str());
10017
    string tef = pars[1];
10018
 
193 andreas 10019
    vector<TMap::MAP_T> map = findButtons(port, channels);
110 andreas 10020
 
10021
    if (TError::isError() || map.empty())
10022
        return;
10023
 
10024
    vector<Button::TButton *> buttons = collectButtons(map);
10025
 
10026
    if (buttons.size() > 0)
10027
    {
108 andreas 10028
        vector<Button::TButton *>::iterator mapIter;
10029
 
10030
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
10031
        {
10032
            Button::TButton *bt = *mapIter;
10033
 
110 andreas 10034
            if (btState == 0)
10035
                bt->setTextEffectName(tef);
10036
            else
10037
                bt->setTextEffectName(tef, btState-1);
10038
        }
10039
    }
10040
}
108 andreas 10041
 
110 andreas 10042
void TPageManager::getTEF(int port, vector<int>& channels, vector<string>& pars)
10043
{
10044
    DECL_TRACER("TPageManager::getTEF(int port, vector<int>& channels, vector<string>& pars)");
108 andreas 10045
 
110 andreas 10046
    if (pars.size() < 1)
10047
    {
10048
        MSG_ERROR("Expecting at least 1 parameter but got " << pars.size() << "! Ignoring command.");
10049
        return;
10050
    }
108 andreas 10051
 
110 andreas 10052
    TError::clear();
10053
    int btState = atoi(pars[0].c_str());
10054
 
193 andreas 10055
    vector<TMap::MAP_T> map = findButtons(port, channels);
110 andreas 10056
 
10057
    if (TError::isError() || map.empty())
10058
        return;
10059
 
10060
    vector<Button::TButton *> buttons = collectButtons(map);
10061
 
10062
    if (buttons.size() > 0)
10063
    {
10064
        Button::TButton *bt = buttons[0];
10065
 
10066
        if (btState == 0)       // All instances?
10067
        {
10068
            int bst = bt->getNumberInstances();
10069
 
10070
            for (int i = 0; i < bst; i++)
108 andreas 10071
            {
110 andreas 10072
                string c = bt->getTextEffectName(i);
300 andreas 10073
                sendCustomEvent(i + 1, (int)c.length(), 0, c, 1008, bt->getChannelPort(), bt->getChannelNumber());
108 andreas 10074
            }
10075
        }
110 andreas 10076
        else
10077
        {
10078
            string c = bt->getTextEffectName(btState-1);
300 andreas 10079
            sendCustomEvent(btState, (int)c.length(), 0, c, 1008, bt->getChannelPort(), bt->getChannelNumber());
110 andreas 10080
        }
108 andreas 10081
    }
10082
}
10083
 
16 andreas 10084
/**
14 andreas 10085
 * Assign a text string to those buttons with a defined address range.
10086
 * Sets Non-Unicode text.
10087
 */
10088
void TPageManager::doTXT(int port, vector<int>& channels, vector<string>& pars)
10089
{
10090
    DECL_TRACER("TPageManager::doTXT(int port, vector<int>& channels, vector<string>& pars)");
10091
 
10092
    if (pars.size() < 1)
10093
    {
10094
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
331 andreas 10095
#if TESTMODE == 1
334 andreas 10096
        setAllDone();
331 andreas 10097
#endif
14 andreas 10098
        return;
10099
    }
10100
 
16 andreas 10101
    TError::clear();
333 andreas 10102
    int btState = atoi(pars[0].c_str()) - 1;
14 andreas 10103
    string text;
10104
 
333 andreas 10105
    // Every comma (,) in the text produces a new parameter. Therefor we must
10106
    // concatenate this parameters together and insert the comma.
14 andreas 10107
    if (pars.size() > 1)
150 andreas 10108
    {
10109
        for (size_t i = 1; i < pars.size(); ++i)
10110
        {
10111
            if (i > 1)
10112
                text += ",";
14 andreas 10113
 
150 andreas 10114
            text += pars[i];
10115
        }
10116
    }
10117
 
193 andreas 10118
    vector<TMap::MAP_T> map = findButtons(port, channels);
14 andreas 10119
 
10120
    if (TError::isError() || map.empty())
331 andreas 10121
    {
10122
#if TESTMODE == 1
334 andreas 10123
        setAllDone();
331 andreas 10124
#endif
14 andreas 10125
        return;
331 andreas 10126
    }
14 andreas 10127
 
10128
    vector<Button::TButton *> buttons = collectButtons(map);
10129
 
83 andreas 10130
    if (buttons.size() > 0)
14 andreas 10131
    {
83 andreas 10132
        vector<Button::TButton *>::iterator mapIter;
14 andreas 10133
 
333 andreas 10134
        for (mapIter = buttons.begin(); mapIter != buttons.end(); ++mapIter)
14 andreas 10135
        {
83 andreas 10136
            Button::TButton *bt = *mapIter;
14 andreas 10137
 
252 andreas 10138
            if (!bt)
333 andreas 10139
                continue;
252 andreas 10140
 
333 andreas 10141
            bt->setText(text, btState);
331 andreas 10142
#if TESTMODE == 1
333 andreas 10143
            if (_gTestMode)
10144
                _gTestMode->setResult(bt->getText(btState < 0 ? 0 : btState));
331 andreas 10145
 
333 andreas 10146
            __success = true;
331 andreas 10147
#endif
14 andreas 10148
        }
10149
    }
331 andreas 10150
#if TESTMODE == 1
334 andreas 10151
    setDone();
331 andreas 10152
#endif
14 andreas 10153
}
21 andreas 10154
 
110 andreas 10155
void TPageManager::getTXT(int port, vector<int>& channels, vector<string>& pars)
10156
{
10157
    DECL_TRACER("TPageManager::getTXT(int port, vector<int>& channels, vector<string>& pars)");
10158
 
10159
    if (pars.size() < 1)
10160
    {
10161
        MSG_ERROR("Expecting at least 1 parameter but got " << pars.size() << "! Ignoring command.");
10162
        return;
10163
    }
10164
 
10165
    TError::clear();
10166
    int btState = atoi(pars[0].c_str());
10167
 
193 andreas 10168
    vector<TMap::MAP_T> map = findButtons(port, channels);
110 andreas 10169
 
10170
    if (TError::isError() || map.empty())
10171
        return;
10172
 
10173
    vector<Button::TButton *> buttons = collectButtons(map);
10174
 
10175
    if (buttons.size() > 0)
10176
    {
10177
        Button::TButton *bt = buttons[0];
10178
 
10179
        if (btState == 0)       // All instances?
10180
        {
10181
            int bst = bt->getNumberInstances();
10182
 
10183
            for (int i = 0; i < bst; i++)
10184
            {
10185
                string c = bt->getText(i);
300 andreas 10186
                sendCustomEvent(i + 1, (int)c.length(), 0, c, 1001, bt->getChannelPort(), bt->getChannelNumber());
333 andreas 10187
#if TESTMODE == 1
10188
                if (_gTestMode)
10189
                    _gTestMode->setResult(c);
10190
#endif
110 andreas 10191
            }
10192
        }
10193
        else
10194
        {
10195
            string c = bt->getText(btState-1);
300 andreas 10196
            sendCustomEvent(btState, (int)c.length(), 0, c, 1001, bt->getChannelPort(), bt->getChannelNumber());
333 andreas 10197
#if TESTMODE == 1
10198
            if (_gTestMode)
10199
                _gTestMode->setResult(c);
10200
#endif
110 andreas 10201
        }
10202
    }
334 andreas 10203
#if TESTMODE == 1
10204
    setAllDone();
10205
#endif
110 andreas 10206
}
10207
 
97 andreas 10208
/*
104 andreas 10209
 * Set button state legacy unicode text command.
10210
 *
10211
 * Set Unicode text in the legacy G4 format. For the ^UNI command, the Unicode
10212
 * text is sent as ASCII-HEX nibbles.
10213
 */
10214
void TPageManager::doUNI(int port, vector<int>& channels, vector<string>& pars)
10215
{
10216
    DECL_TRACER("TPageManager::doUNI(int port, vector<int>& channels, vector<string>& pars)");
10217
 
10218
    if (pars.size() < 1)
10219
    {
10220
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
331 andreas 10221
#if TESTMODE == 1
334 andreas 10222
        setAllDone();
331 andreas 10223
#endif
104 andreas 10224
        return;
10225
    }
10226
 
10227
    TError::clear();
333 andreas 10228
    int btState = atoi(pars[0].c_str()) - 1;
104 andreas 10229
    string text;
10230
 
361 andreas 10231
    // Unicode is the stadard character set used by Windows internally. It
10232
    // consists of 16 bit unsiged numbers. This can't be transported into a
10233
    // standard character string because a NULL byte means end of string.
10234
    // Therefor we must convert it to UFT-8.
104 andreas 10235
    if (pars.size() > 1)
10236
    {
10237
        string byte;
361 andreas 10238
        std::wstring uni;
104 andreas 10239
        size_t pos = 0;
10240
 
10241
        while (pos < pars[1].length())
10242
        {
361 andreas 10243
            byte = pars[1].substr(pos, 4);
10244
            wchar_t ch = (char)strtol(byte.c_str(), NULL, 16);
10245
            uni += ch;
10246
            pos += 4;
104 andreas 10247
        }
361 andreas 10248
 
10249
        text = UnicodeToUTF8(uni);
104 andreas 10250
    }
10251
 
193 andreas 10252
    vector<TMap::MAP_T> map = findButtons(port, channels);
104 andreas 10253
 
10254
    if (TError::isError() || map.empty())
331 andreas 10255
    {
10256
#if TESTMODE == 1
334 andreas 10257
        setAllDone();
331 andreas 10258
#endif
104 andreas 10259
        return;
331 andreas 10260
    }
104 andreas 10261
 
10262
    vector<Button::TButton *> buttons = collectButtons(map);
10263
 
10264
    if (buttons.size() > 0)
10265
    {
10266
        vector<Button::TButton *>::iterator mapIter;
10267
 
10268
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
10269
        {
10270
            Button::TButton *bt = *mapIter;
10271
 
331 andreas 10272
#if TESTMODE == 1
333 andreas 10273
            bool res = bt->setText(text, btState);
104 andreas 10274
 
333 andreas 10275
            if (_gTestMode)
10276
                _gTestMode->setResult(bt->getText(btState < 0 ? 0 : btState));
331 andreas 10277
 
333 andreas 10278
            __success = res;
10279
#else
10280
            bt->setText(text, btState);
331 andreas 10281
#endif
104 andreas 10282
        }
10283
    }
334 andreas 10284
#if TESTMODE == 1
10285
    setDone();
10286
#endif
104 andreas 10287
}
10288
 
10289
void TPageManager::doUTF(int port, vector<int>& channels, vector<string>& pars)
10290
{
10291
    DECL_TRACER("TPageManager::doTXT(int port, vector<int>& channels, vector<string>& pars)");
10292
 
10293
    if (pars.size() < 1)
10294
    {
10295
        MSG_ERROR("Expecting 1 parameters but got none! Ignoring command.");
10296
        return;
10297
    }
10298
 
10299
    TError::clear();
10300
    int btState = atoi(pars[0].c_str());
10301
    string text;
10302
 
10303
    if (pars.size() > 1)
150 andreas 10304
    {
10305
        for (size_t i = 1; i < pars.size(); ++i)
10306
        {
10307
            if (i > 1)
10308
                text += ",";
104 andreas 10309
 
150 andreas 10310
            text += pars[i];
10311
        }
10312
    }
10313
 
193 andreas 10314
    vector<TMap::MAP_T> map = findButtons(port, channels);
104 andreas 10315
 
10316
    if (TError::isError() || map.empty())
10317
        return;
10318
 
10319
    vector<Button::TButton *> buttons = collectButtons(map);
10320
 
10321
    if (buttons.size() > 0)
10322
    {
10323
        vector<Button::TButton *>::iterator mapIter;
10324
 
10325
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
10326
        {
10327
            Button::TButton *bt = *mapIter;
10328
 
10329
            if (btState == 0)       // All instances?
10330
            {
10331
                int bst = bt->getNumberInstances();
10332
 
10333
                for (int i = 0; i < bst; i++)
10334
                    bt->setText(text, i);
10335
            }
10336
            else
10337
                bt->setText(text, btState - 1);
10338
        }
10339
    }
10340
}
111 andreas 10341
 
361 andreas 10342
/**
10343
 * Simulates a touch/release/pulse at the given coordinate. If the push event
10344
 * is less then 0 or grater than 2 the command is ignored. It is also ignored
10345
 * if the x and y coordinate is out of range. The range must be between 0 and
10346
 * the maximum with and height.
10347
 */
148 andreas 10348
void TPageManager::doVTP (int, vector<int>&, vector<string>& pars)
10349
{
10350
    DECL_TRACER("TPageManager::doVTP (int, vector<int>&, vector<string>& pars)");
10351
 
10352
    if (pars.size() < 3)
10353
    {
10354
        MSG_ERROR("Expected 3 parameters but got only " << pars.size() << " parameters!");
10355
        return;
10356
    }
10357
 
10358
    int pushType = atoi(pars[0].c_str());
10359
    int x = atoi(pars[1].c_str());
10360
    int y = atoi(pars[2].c_str());
10361
 
10362
    if (pushType < 0 || pushType > 2)
10363
    {
10364
        MSG_ERROR("Invalid push type " << pushType << ". Ignoring command!");
10365
        return;
10366
    }
10367
 
217 andreas 10368
    if (x < 0 || x > mTSettings->getWidth() || y < 0 || y > mTSettings->getHeight())
148 andreas 10369
    {
10370
        MSG_ERROR("Illegal coordinates " << x << " x " << y << ". Ignoring command!");
10371
        return;
10372
    }
10373
 
10374
    if (pushType == 0 || pushType == 2)
10375
        mouseEvent(x, y, true);
10376
 
10377
    if (pushType == 1 || pushType == 2)
10378
        mouseEvent(x, y, false);
10379
}
10380
 
400 andreas 10381
 
111 andreas 10382
/**
10383
 * Set the keyboard passthru.
10384
 */
10385
void TPageManager::doKPS(int, vector<int>&, vector<string>& pars)
10386
{
10387
    DECL_TRACER("TPageManager::doKPS(int, vector<int>&, vector<string>& pars)");
10388
 
10389
    if (pars.size() < 1)
10390
    {
10391
        MSG_ERROR("Got no parameter. Ignoring command!");
10392
        return;
10393
    }
10394
 
10395
    int state = atoi(pars[0].c_str());
10396
 
10397
    if (state == 0)
10398
        mPassThrough = false;
10399
    else if (state == 5)
10400
        mPassThrough = true;
10401
}
10402
 
400 andreas 10403
void TPageManager::doVKS(int, vector<int>&, vector<string>& pars)
111 andreas 10404
{
400 andreas 10405
    DECL_TRACER("TPageManager::doVKS(int, vector<int>&, vector<string>& pars)");
111 andreas 10406
 
10407
    if (pars.size() < 1)
10408
    {
10409
        MSG_ERROR("Got no parameter. Ignoring command!");
10410
        return;
10411
    }
10412
 
10413
    if (_sendVirtualKeys)
10414
        _sendVirtualKeys(pars[0]);
10415
}
10416
 
400 andreas 10417
void TPageManager::doLPB(int port, vector<int>& channels, vector<string>& pars)
10418
{
10419
    DECL_TRACER("TPageManager::doLPB(int port, vector<int>& channels, vector<string>& pars)");
10420
 
10421
    if (pars.size() < 1)
10422
        return;
10423
 
10424
    TError::clear();
10425
    string passwd = pars[0];
10426
    vector<TMap::MAP_T> map = findButtons(port, channels);
10427
 
10428
    if (TError::isError() || map.empty())
10429
        return;
10430
 
10431
    vector<Button::TButton *> buttons = collectButtons(map);
10432
 
10433
    if (buttons.size() > 0)
10434
    {
10435
        vector<Button::TButton *>::iterator mapIter;
10436
 
10437
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
10438
        {
10439
            Button::TButton *bt = *mapIter;
10440
            bt->setUserName(passwd);
10441
        }
10442
    }
10443
}
10444
 
401 andreas 10445
void TPageManager::doLPC(int, vector<int>&, vector<string>&)
400 andreas 10446
{
401 andreas 10447
    DECL_TRACER("TPageManager::doLPC(int, vector<int>&, vector<string>&)");
400 andreas 10448
 
10449
    TConfig::clearUserPasswords();
10450
}
10451
 
10452
void TPageManager::doLPR(int, vector<int>&, vector<string>& pars)
10453
{
10454
    DECL_TRACER("TPageManager::doLPR(int, vector<int>&, vector<string>& pars)");
10455
 
10456
    if (pars.size() < 1)
10457
        return;
10458
 
10459
    string user = pars[0];
10460
    TConfig::clearUserPassword(user);
10461
}
10462
 
10463
void TPageManager::doLPS(int, vector<int>&, vector<string>& pars)
10464
{
10465
    DECL_TRACER("TPageManager::doLPS(int, vector<int>&, vector<string>& pars)");
10466
 
10467
    if (pars.size() < 2)
10468
        return;
10469
 
10470
    string user = pars[0];
10471
    string password;
10472
 
10473
    // In case the password contains one or more comma (,), the password is
10474
    // splitted. The following loop concatenates the password into one. Because
10475
    // the comma is lost, we must add it again.
10476
    for (size_t i = 0; i < pars.size(); ++i)
10477
    {
10478
        if (i > 0)
10479
            password += ",";
10480
 
10481
        password += pars[i];
10482
    }
10483
 
10484
    TConfig::setUserPassword(user, password);
10485
}
10486
 
104 andreas 10487
/*
400 andreas 10488
 * Set the page flip password. @PWD sets the level 1 password only.
10489
 */
10490
void TPageManager::doAPWD(int, vector<int>&, vector<string>& pars)
10491
{
10492
    DECL_TRACER("TPageManager::doPWD(int port, vector<int>&, vector<string>& pars)");
10493
 
10494
    if (pars.size() < 1)
10495
    {
10496
        MSG_ERROR("Got less then 1 parameter!");
10497
        return;
10498
    }
10499
 
10500
    string password;
10501
    // In case the password contains one or more comma (,), the password is
10502
    // splitted. The following loop concatenates the password into one. Because
10503
    // the comma is lost, we must add it again.
10504
    for (size_t i = 0; i < pars.size(); ++i)
10505
    {
10506
        if (i > 0)
10507
            password += ",";
10508
 
10509
        password += pars[i];
10510
    }
10511
 
10512
    TConfig::savePassword1(password);
10513
}
10514
 
10515
/*
10516
 * Set the page flip password. Password level is required and must be 1 - 4
10517
 */
10518
void TPageManager::doPWD(int, vector<int>&, vector<string>& pars)
10519
{
10520
    DECL_TRACER("TPageManager::doPWD(int, vector<int>&, vector<string>& pars)");
10521
 
10522
    if (pars.size() < 2)
10523
    {
10524
        MSG_ERROR("Got less then 2 parameters!");
10525
        return;
10526
    }
10527
 
10528
    int pwIdx = atoi(pars[0].c_str());
10529
    string password;
10530
    // In case the password contains one or more comma (,), the password is
10531
    // splitted. The following loop concatenates the password into one. Because
10532
    // the comma is lost, we must add it again.
10533
    for (size_t i = 1; i < pars.size(); ++i)
10534
    {
10535
        if (i > 1)
10536
            password += ",";
10537
 
10538
        password += pars[i];
10539
    }
10540
 
10541
    switch(pwIdx)
10542
    {
10543
        case 1: TConfig::savePassword1(password); break;
10544
        case 2: TConfig::savePassword2(password); break;
10545
        case 3: TConfig::savePassword3(password); break;
10546
        case 4: TConfig::savePassword4(password); break;
10547
    }
10548
}
10549
 
10550
/*
97 andreas 10551
 * Set the bitmap of a button to use a particular resource.
10552
 * Syntax:
10553
 *    "'^BBR-<vt addr range>,<button states range>,<resource name>'"
10554
 * Variable:
10555
 *    variable text address range = 1 - 4000.
10556
 *    button states range = 1 - 256 for multi-state buttons (0 = All states, for General buttons 1 = Off state and 2 = On state).
10557
 *    resource name = 1 - 50 ASCII characters.
10558
 * Example:
10559
 *    SEND_COMMAND Panel,"'^BBR-700,1,Sports_Image'"
10560
 *    Sets the resource name of the button to ’Sports_Image’.
10561
 */
21 andreas 10562
void TPageManager::doBBR(int port, vector<int>& channels, vector<string>& pars)
10563
{
10564
    DECL_TRACER("TPageManager::doBBR(int port, vector<int>& channels, vector<string>& pars)");
10565
 
10566
    if (pars.size() < 2)
10567
    {
10568
        MSG_ERROR("Expecting 2 parameters but got none! Ignoring command.");
10569
        return;
10570
    }
10571
 
10572
    TError::clear();
10573
    int btState = atoi(pars[0].c_str());
10574
    string resName = pars[1];
10575
 
193 andreas 10576
    vector<TMap::MAP_T> map = findButtons(port, channels);
21 andreas 10577
 
10578
    if (TError::isError() || map.empty())
10579
        return;
10580
 
10581
    vector<Button::TButton *> buttons = collectButtons(map);
10582
 
83 andreas 10583
    if (buttons.size() > 0)
21 andreas 10584
    {
83 andreas 10585
        vector<Button::TButton *>::iterator mapIter;
21 andreas 10586
 
83 andreas 10587
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
21 andreas 10588
        {
83 andreas 10589
            Button::TButton *bt = *mapIter;
252 andreas 10590
//            setButtonCallbacks(bt);
21 andreas 10591
 
83 andreas 10592
            if (btState == 0)       // All instances?
10593
            {
10594
                int bst = bt->getNumberInstances();
10595
                MSG_DEBUG("Setting BBR on all " << bst << " instances...");
10596
 
10597
                for (int i = 0; i < bst; i++)
10598
                    bt->setResourceName(resName, i);
10599
            }
10600
            else
10601
                bt->setResourceName(resName, btState - 1);
97 andreas 10602
 
10603
            if (bt->isVisible())
10604
                bt->refresh();
99 andreas 10605
            else if (_setVisible)
10606
                _setVisible(bt->getHandle(), false);
21 andreas 10607
        }
10608
    }
10609
}
10610
 
97 andreas 10611
/*
10612
 * Add new resources
10613
 * Adds any and all resource parameters by sending embedded codes and data.
10614
 * Since the embedded codes are preceded by a '%' character, any '%' character
10615
 * contained in* the URL must be escaped with a second '%' character (see
10616
 * example).
10617
 * The file name field (indicated by a %F embedded code) may contain special
10618
 * escape sequences as shown in the ^RAF, ^RMF.
10619
 * Syntax:
10620
 *    "'^RAF-<resource name>,<data>'"
10621
 * Variables:
10622
 *    resource name = 1 - 50 ASCII characters.
10623
 *    data = Refers to the embedded codes, see the ^RAF, ^RMF.
10624
 * Example:
10625
 *    SEND_COMMAND Panel,"'^RAF-New Image,%P0%HAMX.COM%ALab/Test%%5Ffile%Ftest.jpg'"
10626
 *    Adds a new resource.
10627
 *    The resource name is ’New Image’
10628
 *    %P (protocol) is an HTTP
10629
 *    %H (host name) is AMX.COM
10630
 *    %A (file path) is Lab/Test_f ile
10631
 *    %F (file name) is test.jpg.
10632
 *    Note that the %%5F in the file path is actually encoded as %5F.
10633
 */
10634
void TPageManager::doRAF(int, vector<int>&, vector<string>& pars)
10635
{
10636
    DECL_TRACER("TPageManager::doRAF(int port, vector<int>& channels, vector<string>& pars)");
10637
 
10638
    if (pars.size() < 2)
10639
    {
10640
        MSG_ERROR("Expecting 2 parameters but got none! Ignoring command.");
10641
        return;
10642
    }
10643
 
10644
    string name = pars[0];
10645
    string data = pars[1];
10646
 
10647
    vector<string> parts = StrSplit(data, "%");
10648
    RESOURCE_T res;
10649
 
10650
    if (parts.size() > 0)
10651
    {
10652
        vector<string>::iterator sIter;
10653
 
10654
        for (sIter = parts.begin(); sIter != parts.end(); sIter++)
10655
        {
10656
            const char *s = sIter->c_str();
10657
            string ss = *sIter;
10658
            MSG_DEBUG("Parsing \"" << ss << "\" with token << " << ss[0]);
10659
 
10660
            switch(*s)
10661
            {
10662
                case 'P':
10663
                    if (*(s+1) == '0')
10664
                        res.protocol = "HTTP";
10665
                    else
10666
                        res.protocol = "FTP";
10667
                    break;
10668
 
10669
                case 'U': res.user = sIter->substr(1); break;
10670
                case 'S': res.password = sIter->substr(1); break;
10671
                case 'H': res.host = sIter->substr(1); break;
10672
                case 'F': res.file = sIter->substr(1); break;
10673
                case 'A': res.path = sIter->substr(1); break;
10674
                case 'R': res.refresh = atoi(sIter->substr(1).c_str()); break;
10675
 
10676
                default:
10677
                    MSG_WARNING("Option " << sIter->at(0) << " is currently not implemented!");
10678
            }
10679
        }
10680
 
10681
        if (gPrjResources)
10682
            gPrjResources->addResource(name, res.protocol, res.host, res.path, res.file, res.user, res.password, res.refresh);
10683
    }
10684
}
10685
 
111 andreas 10686
void TPageManager::doRFR(int, vector<int>&, vector<string>& pars)
97 andreas 10687
{
10688
    DECL_TRACER("TPageManager::doRFR(int port, vector<int>& channels, vector<string>& pars)");
10689
 
10690
    if (pars.size() < 1)
10691
    {
10692
        MSG_ERROR("Expecting 1 parameter but got none! Ignoring command.");
10693
        return;
10694
    }
10695
 
10696
    string name = pars[0];
193 andreas 10697
    vector<TMap::MAP_T> map = findButtonByName(name);
97 andreas 10698
 
10699
    if (TError::isError() || map.empty())
10700
        return;
10701
 
10702
    vector<Button::TButton *> buttons = collectButtons(map);
10703
 
10704
    if (buttons.size() > 0)
10705
    {
10706
        vector<Button::TButton *>::iterator mapIter;
10707
 
10708
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
10709
        {
10710
            Button::TButton *bt = *mapIter;
10711
 
10712
            if (bt->isVisible())
10713
            {
252 andreas 10714
//                setButtonCallbacks(bt);
97 andreas 10715
                bt->refresh();
10716
            }
10717
        }
10718
    }
10719
}
10720
 
10721
/*
10722
 * Modify an existing resource
10723
 *
10724
 * Modifies any and all resource parameters by sending embedded codes and data.
10725
 * Since the embedded codes are preceded by a '%' character, any '%' character
10726
 * contained in the URL must be escaped with a second '%' character (see
10727
 * example).
10728
 * The file name field (indicated by a %F embedded code) may contain special
10729
 * escape sequences as shown in the ^RAF.
10730
 *
10731
 * Syntax:
10732
 * "'^RMF-<resource name>,<data>'"
10733
 * Variables:
10734
 *   • resource name = 1 - 50 ASCII characters
10735
 *   • data = Refers to the embedded codes, see the ^RAF, ^RMF.
10736
 * Example:
10737
 *   SEND_COMMAND Panel,"'^RMF-Sports_Image,%ALab%%5FTest/Images%Ftest.jpg'"
10738
 * Changes the resource ’Sports_Image’ file name to ’test.jpg’ and the path to
10739
 * ’Lab_Test/Images’.
10740
 * Note that the %%5F in the file path is actually encoded as %5F.
10741
 */
22 andreas 10742
void TPageManager::doRMF(int, vector<int>&, vector<string>& pars)
21 andreas 10743
{
10744
    DECL_TRACER("TPageManager::doRMF(int port, vector<int>& channels, vector<string>& pars)");
10745
 
10746
    if (pars.size() < 2)
10747
    {
10748
        MSG_ERROR("Expecting 2 parameters but got none! Ignoring command.");
10749
        return;
10750
    }
10751
 
10752
    string name = pars[0];
10753
    string data = pars[1];
10754
 
10755
    vector<string> parts = StrSplit(data, "%");
10756
    RESOURCE_T res;
10757
 
83 andreas 10758
    if (parts.size() > 0)
21 andreas 10759
    {
83 andreas 10760
        vector<string>::iterator sIter;
21 andreas 10761
 
83 andreas 10762
        for (sIter = parts.begin(); sIter != parts.end(); sIter++)
21 andreas 10763
        {
83 andreas 10764
            const char *s = sIter->c_str();
10765
            string ss = *sIter;
10766
            MSG_DEBUG("Parsing \"" << ss << "\" with token << " << ss[0]);
21 andreas 10767
 
83 andreas 10768
            switch(*s)
10769
            {
10770
                case 'P':
10771
                    if (*(s+1) == '0')
10772
                        res.protocol = "HTTP";
10773
                    else
10774
                        res.protocol = "FTP";
10775
                break;
21 andreas 10776
 
83 andreas 10777
                case 'U': res.user = sIter->substr(1); break;
10778
                case 'S': res.password = sIter->substr(1); break;
10779
                case 'H': res.host = sIter->substr(1); break;
10780
                case 'F': res.file = sIter->substr(1); break;
10781
                case 'A': res.path = sIter->substr(1); break;
10782
                case 'R': res.refresh = atoi(sIter->substr(1).c_str()); break;
10783
 
10784
                default:
10785
                    MSG_WARNING("Option " << sIter->at(0) << " is currently not implemented!");
10786
            }
21 andreas 10787
        }
83 andreas 10788
 
10789
        if (gPrjResources)
10790
            gPrjResources->setResource(name, res.protocol, res.host, res.path, res.file, res.user, res.password, res.refresh);
21 andreas 10791
    }
10792
}
62 andreas 10793
 
10794
/**
111 andreas 10795
 * Change the refresh rate for a given resource.
10796
 */
10797
void TPageManager::doRSR(int, vector<int>&, vector<string>& pars)
10798
{
10799
    DECL_TRACER("TPageManager::doRSR(int, vector<int>&, vector<string>& pars)");
10800
 
10801
    if (pars.size() < 2)
10802
    {
10803
        MSG_ERROR("Expecting 2 parameters but got none! Ignoring command.");
10804
        return;
10805
    }
10806
 
10807
    string resName = pars[0];
10808
    int resRefresh = atoi(pars[1].c_str());
10809
 
10810
    if (!gPrjResources)
10811
    {
10812
        MSG_ERROR("Missing the resource module. Ignoring command!");
10813
        return;
10814
    }
10815
 
10816
    RESOURCE_T res = gPrjResources->findResource(resName);
10817
 
10818
    if (res.name.empty() || res.refresh == resRefresh)
10819
        return;
10820
 
10821
    gPrjResources->setResource(resName, res.protocol, res.host, res.path, res.file, res.user, res.password, resRefresh);
10822
}
10823
 
10824
/**
62 andreas 10825
 * @brief TPageManager::doAKB - Pop up the keyboard icon
10826
 * Pop up the keyboard icon and initialize the text string to that specified.
10827
 * Keyboard string is set to null on power up and is stored until power is lost.
10828
 * The Prompt Text is optional.
10829
 */
10830
void TPageManager::doAKB(int, vector<int>&, vector<string> &pars)
10831
{
10832
    DECL_TRACER("TPageManager::doAKB(int, vector<int>&, vector<string> &pars)");
10833
 
10834
    if (pars.size() < 1)
10835
    {
10836
        MSG_ERROR("Expecting 2 parameters but got only " << pars.size() << "! Ignoring command.");
10837
        return;
10838
    }
10839
 
10840
    string initText = pars[0];
10841
    string promptText;
10842
 
10843
    if (pars.size() > 1)
10844
        promptText = pars[1];
10845
 
63 andreas 10846
    if (initText.empty())
10847
        initText = mAkbText;
10848
    else
10849
        mAkbText = initText;
62 andreas 10850
 
10851
    if (_callKeyboard)
63 andreas 10852
        _callKeyboard(initText, promptText, false);
62 andreas 10853
}
10854
 
63 andreas 10855
/**
10856
 * Pop up the keyboard icon and initialize the text string to that
10857
 * specified.
10858
 */
62 andreas 10859
void TPageManager::doAKEYB(int port, vector<int>& channels, vector<string>& pars)
10860
{
10861
    DECL_TRACER("TPageManager::doAKEYB(int port, vector<int>& channels, vector<string>& pars)");
10862
 
10863
    doAKB(port, channels, pars);
10864
}
10865
 
63 andreas 10866
void TPageManager::doAKEYP(int port, std::vector<int>& channels, std::vector<std::string>& pars)
10867
{
10868
    DECL_TRACER("TPageManager::doAKEYP(int port, std::vector<int>& channels, std::vector<std::string>& pars)");
10869
 
10870
    doAKP(port, channels, pars);
10871
}
10872
 
62 andreas 10873
/**
63 andreas 10874
 * Remove keyboard or keypad that was displayed using 'AKEYB', 'AKEYP', 'PKEYP',
10875
 * @AKB, @AKP, @PKP, @EKP, or @TKP commands.
10876
 */
10877
void TPageManager::doAKEYR(int, vector<int>&, vector<string>&)
10878
{
10879
    DECL_TRACER("TPageManager::doAKEYR(int, vector<int>&, vector<string>&)");
10880
 
10881
    if (_callResetKeyboard)
10882
        _callResetKeyboard();
10883
}
10884
 
10885
/**
62 andreas 10886
 * @brief TPageManager::doAKP - Pop up the keypad icon
10887
 * Pop up the keypad icon and initialize the text string to that specified.
10888
 * Keypad string is set to null on power up and is stored until power is lost.
10889
 * The Prompt Text is optional.
10890
 */
10891
void TPageManager::doAKP(int, std::vector<int>&, std::vector<std::string> &pars)
10892
{
10893
    DECL_TRACER("TPageManager::doAKP(int, vector<int>&, vector<string> &pars)");
10894
 
10895
    if (pars.size() < 1)
10896
    {
10897
        MSG_ERROR("Expecting 2 parameters but got only " << pars.size() << "! Ignoring command.");
10898
        return;
10899
    }
10900
 
10901
    string initText = pars[0];
10902
    string promptText;
10903
 
10904
    if (pars.size() > 1)
10905
        promptText = pars[1];
10906
 
63 andreas 10907
    if (initText.empty())
10908
        initText = mAkpText;
10909
    else
10910
        mAkpText = initText;
62 andreas 10911
 
10912
    if (_callKeypad)
63 andreas 10913
        _callKeypad(initText, promptText, false);
62 andreas 10914
}
10915
 
63 andreas 10916
/**
10917
 * Remove keyboard or keypad that was displayed using 'AKEYB', 'AKEYP', 'PKEYP',
10918
 * @AKB, @AKP, @PKP, @EKP, or @TKP commands.
10919
 */
10920
void TPageManager::doAKR(int port, vector<int>& channels, vector<string>& pars)
62 andreas 10921
{
63 andreas 10922
    DECL_TRACER("TPageManager::doAKR(int, vector<int>&, vector<string>&)");
62 andreas 10923
 
63 andreas 10924
    doAKEYR(port, channels, pars);
62 andreas 10925
}
10926
 
108 andreas 10927
void TPageManager::doABEEP(int, std::vector<int>&, vector<string>&)
10928
{
10929
    DECL_TRACER("TPageManager::doBEEP(int, std::vector<int>&, vector<string>&)");
10930
 
10931
    if (!_playSound)
334 andreas 10932
    {
10933
#if TESTMODE == 1
10934
        setAllDone();
10935
#endif
108 andreas 10936
        return;
334 andreas 10937
    }
108 andreas 10938
 
10939
    string snd = TConfig::getSystemPath(TConfig::SOUNDS) + "/" + TConfig::getSingleBeepSound();
10940
    TValidateFile vf;
10941
 
326 andreas 10942
    if (vf.isValidFile(snd))
108 andreas 10943
        _playSound(snd);
326 andreas 10944
#if TESTMODE == 1
10945
    else
10946
    {
10947
        MSG_PROTOCOL("Sound file invalid!");
334 andreas 10948
        setAllDone();
326 andreas 10949
    }
10950
#endif
108 andreas 10951
}
10952
 
10953
void TPageManager::doADBEEP(int, std::vector<int>&, vector<string>&)
10954
{
10955
    DECL_TRACER("TPageManager::doDBEEP(int, std::vector<int>&, vector<string>&)");
10956
 
10957
    if (!_playSound)
10958
        return;
10959
 
10960
    string snd = TConfig::getSystemPath(TConfig::SOUNDS) + "/" + TConfig::getDoubleBeepSound();
10961
    TValidateFile vf;
10962
 
326 andreas 10963
    if (vf.isValidFile(snd))
108 andreas 10964
        _playSound(snd);
326 andreas 10965
#if TESTMODE == 1
10966
    else
10967
    {
10968
        MSG_PROTOCOL("Sound file invalid!");
334 andreas 10969
        setAllDone();
326 andreas 10970
    }
10971
#endif
108 andreas 10972
}
10973
 
71 andreas 10974
void TPageManager::doBEEP(int, std::vector<int>&, vector<string>&)
10975
{
10976
    DECL_TRACER("TPageManager::doBEEP(int, std::vector<int>&, vector<string>&)");
10977
 
10978
    if (!_playSound)
326 andreas 10979
    {
10980
#if TESTMODE == 1
10981
        MSG_PROTOCOL("Method \"playSound()\" not initialized!");
334 andreas 10982
        setAllDone();
326 andreas 10983
#endif
71 andreas 10984
        return;
326 andreas 10985
    }
71 andreas 10986
 
10987
    string snd = TConfig::getSystemPath(TConfig::SOUNDS) + "/" + TConfig::getSingleBeepSound();
10988
    TValidateFile vf;
108 andreas 10989
    TSystemSound sysSound(TConfig::getSystemPath(TConfig::SOUNDS));
71 andreas 10990
 
326 andreas 10991
    if (sysSound.getSystemSoundState() && vf.isValidFile(snd))
71 andreas 10992
        _playSound(snd);
326 andreas 10993
#if TESTMODE == 1
10994
    else
10995
    {
10996
        if (!sysSound.getSystemSoundState())
10997
        {
10998
            MSG_PROTOCOL("Sound state disabled!")
10999
        }
11000
        else
11001
        {
11002
            MSG_PROTOCOL("Sound file invalid!");
11003
        }
11004
 
334 andreas 11005
        setAllDone();
326 andreas 11006
    }
11007
#endif
71 andreas 11008
}
11009
 
11010
void TPageManager::doDBEEP(int, std::vector<int>&, vector<string>&)
11011
{
11012
    DECL_TRACER("TPageManager::doDBEEP(int, std::vector<int>&, vector<string>&)");
11013
 
11014
    if (!_playSound)
11015
        return;
11016
 
11017
    string snd = TConfig::getSystemPath(TConfig::SOUNDS) + "/" + TConfig::getDoubleBeepSound();
11018
    TValidateFile vf;
108 andreas 11019
    TSystemSound sysSound(TConfig::getSystemPath(TConfig::SOUNDS));
71 andreas 11020
 
326 andreas 11021
    if (sysSound.getSystemSoundState() && vf.isValidFile(snd))
71 andreas 11022
        _playSound(snd);
326 andreas 11023
#if TESTMODE == 1
11024
    else
11025
    {
11026
        if (!sysSound.getSystemSoundState())
11027
        {
11028
            MSG_PROTOCOL("Sound state disabled!")
11029
        }
11030
        else
11031
        {
11032
            MSG_PROTOCOL("Sound file invalid!");
11033
        }
11034
 
334 andreas 11035
        setAllDone();
326 andreas 11036
    }
11037
#endif
71 andreas 11038
}
11039
 
63 andreas 11040
/**
11041
 * @brief Pop up the keypad icon and initialize the text string to that specified.
11042
 * Keypad string is set to null on power up and is stored until power is lost.
11043
 * The Prompt Text is optional.
11044
 */
62 andreas 11045
void TPageManager::doEKP(int port, std::vector<int>& channels, std::vector<std::string>& pars)
11046
{
11047
    DECL_TRACER("TPageManager::doEKP(int port, std::vector<int>& channels, std::vector<std::string>& pars)");
11048
 
11049
    doAKP(port, channels, pars);
11050
}
63 andreas 11051
 
11052
/**
11053
 * @brief Present a private keyboard.
11054
 * Pops up the keyboard icon and initializes the text string to that specified.
11055
 * Keyboard displays a '*' instead of the letters typed. The Prompt Text is optional.
11056
 */
11057
void TPageManager::doPKB(int, vector<int>&, vector<string>& pars)
11058
{
11059
    DECL_TRACER("TPageManager::doPKB(int, vector<int>&, vector<string>& pars)");
11060
 
11061
    if (pars.size() < 1)
11062
    {
11063
        MSG_ERROR("Expecting 2 parameters but got only " << pars.size() << "! Ignoring command.");
11064
        return;
11065
    }
11066
 
11067
    string initText = pars[0];
11068
    string promptText;
11069
 
11070
    if (pars.size() > 1)
11071
        promptText = pars[1];
11072
 
11073
    if (_callKeyboard)
11074
        _callKeyboard(initText, promptText, true);
11075
}
11076
 
11077
/**
11078
 * @brief Present a private keypad.
11079
 * Pops up the keypad icon and initializes the text string to that specified.
11080
 * Keypad displays a '*' instead of the numbers typed. The Prompt Text is optional.
11081
 */
11082
void TPageManager::doPKP(int, vector<int>&, vector<string>& pars)
11083
{
11084
    DECL_TRACER("TPageManager::doPKP(int, vector<int>&, vector<string>& pars)");
11085
 
11086
    if (pars.size() < 1)
11087
    {
11088
        MSG_ERROR("Expecting 2 parameters but got only " << pars.size() << "! Ignoring command.");
11089
        return;
11090
    }
11091
 
11092
    string initText = pars[0];
11093
    string promptText;
11094
 
11095
    if (pars.size() > 1)
11096
        promptText = pars[1];
11097
 
11098
    if (_callKeypad)
11099
        _callKeypad(initText, promptText, true);
11100
}
11101
 
11102
/**
64 andreas 11103
 * Send panel to SETUP page.
11104
 */
11105
void TPageManager::doSetup(int, vector<int>&, vector<string>&)
11106
{
11107
    DECL_TRACER("TPageManager::doSetup(int, vector<int>&, vector<string>&)");
11108
 
11109
    if (_callShowSetup)
11110
        _callShowSetup();
11111
}
11112
 
11113
/**
11114
 * Shut down the App
11115
 */
11116
void TPageManager::doShutdown(int, vector<int>&, vector<string>&)
11117
{
11118
    DECL_TRACER("TPageManager::doShutdown(int, vector<int>&, vector<string>&)");
11119
 
97 andreas 11120
    MSG_PROTOCOL("Received shutdown ...");
64 andreas 11121
#ifdef __ANDROID__
11122
    stopNetworkState();
11123
#endif
11124
    prg_stopped = true;
11125
    killed = true;
11126
 
11127
    if (_shutdown)
11128
        _shutdown();
11129
}
11130
 
82 andreas 11131
void TPageManager::doSOU(int, vector<int>&, vector<string>& pars)
11132
{
11133
    DECL_TRACER("TPageManager::doSOU(int, vector<int>&, vector<string>& pars)");
11134
 
11135
    if (pars.size() < 1)
11136
    {
11137
        MSG_ERROR("@SOU: Expecting a sound file as parameter! Ignoring command.");
11138
        return;
11139
    }
11140
 
11141
    if (!_playSound)
11142
    {
11143
        MSG_ERROR("@SOU: Missing sound module!");
11144
        return;
11145
    }
11146
 
165 andreas 11147
    if (pars[0].empty() || strCaseCompare(pars[0], "None") == 0)
11148
        return;
11149
 
82 andreas 11150
    _playSound(pars[0]);
11151
}
11152
 
326 andreas 11153
void TPageManager::doMUT(int, vector<int>&, vector<string>& pars)
11154
{
11155
    DECL_TRACER("TPageManager::doMUT(int, vector<int>&, vector<string>& pars)");
11156
 
11157
    if (pars.size() < 1)
11158
    {
11159
        MSG_ERROR("^MUT: Expecting a state parameter! Ignoring command.");
11160
        return;
11161
    }
11162
 
11163
    bool mute = 0;
11164
 
11165
    if (pars[0] == "0")
11166
        mute = false;
11167
    else
11168
        mute = true;
11169
 
11170
    TConfig::setMuteState(mute);
11171
#if TESTMODE == 1
327 andreas 11172
    if (_gTestMode)
11173
    {
11174
        bool st = TConfig::getMuteState();
11175
        _gTestMode->setResult(st ? "1" : "0");
11176
    }
11177
 
326 andreas 11178
    __success = true;
334 andreas 11179
    setAllDone();
326 andreas 11180
#endif
11181
}
11182
 
64 andreas 11183
/**
63 andreas 11184
 * @brief Present a telephone keypad.
11185
 * Pops up the keypad icon and initializes the text string to that specified.
11186
 * The Prompt Text is optional.
11187
 */
11188
void TPageManager::doTKP(int port, vector<int>& channels, vector<string>& pars)
11189
{
11190
    DECL_TRACER("TPageManager::doTKP(int port, vector<int>& channels, vector<string>& pars)");
11191
 
11192
    // TODO: Implement a real telefone keypad.
11193
    doAKP(port, channels, pars);
11194
}
11195
 
11196
/**
11197
 * Popup the virtual keyboard
11198
 */
123 andreas 11199
void TPageManager::doVKB(int port, vector<int>& channels, vector<string>& pars)
63 andreas 11200
{
123 andreas 11201
    DECL_TRACER("TPageManager::doVKB(int port, vector<int>& channels, vector<string>& pars)");
63 andreas 11202
 
11203
    doAKP(port, channels, pars);
11204
}
129 andreas 11205
#ifndef _NOSIP_
123 andreas 11206
void TPageManager::sendPHN(vector<string>& cmds)
11207
{
11208
    DECL_TRACER("TPageManager::sendPHN(const vector<string>& cmds)");
11209
 
11210
    vector<int> channels;
11211
    doPHN(-1, channels, cmds);
11212
}
11213
 
141 andreas 11214
void TPageManager::actPHN(vector<string>& cmds)
11215
{
11216
    DECL_TRACER("TPageManager::actPHN(const vector<string>& cmds)");
11217
 
11218
    vector<int> channels;
11219
    doPHN(1, channels, cmds);
11220
}
11221
 
140 andreas 11222
void TPageManager::phonePickup(int id)
11223
{
11224
    DECL_TRACER("TPageManager::phonePickup(int id)");
11225
 
11226
    if (id < 0 || id >= 4)
11227
        return;
11228
 
11229
    if (mSIPClient)
11230
        mSIPClient->pickup(id);
11231
}
11232
 
11233
void TPageManager::phoneHangup(int id)
11234
{
11235
    DECL_TRACER("TPageManager::phoneHangup(int id)");
11236
 
11237
    if (id < 0 || id >= 4)
11238
        return;
11239
 
11240
    if (mSIPClient)
11241
        mSIPClient->terminate(id);
11242
}
11243
 
123 andreas 11244
/**
11245
 * @brief Phone commands.
11246
 * The phone commands could come from the master or are send to the master.
11247
 * If the parameter \p port is less then 0 (zero) a command is send to the
11248
 * master. In any other case the command came from the mater.
125 andreas 11249
 *
11250
 * @param port  This is used to signal if the command was sent by the master
11251
 *              or generated from the panel. If ths is less then 0, then the
11252
 *              method was called because of an event happen in the panel.
11253
 *              If this is grater or equal 0, then the event is comming from
11254
 *              the master.
11255
 * @param pars  This are parameters. The first parameter defines the action
11256
 *              to be done. According to the command this parameter may have a
11257
 *              different number of arguments.
123 andreas 11258
 */
11259
void TPageManager::doPHN(int port, vector<int>&, vector<string>& pars)
11260
{
11261
    DECL_TRACER("TPageManager::doPHN(int port, vector<int>&, vector<string>& pars)");
11262
 
11263
    if (pars.size() < 1)
11264
    {
11265
        MSG_ERROR("Expecting at least 1 parameter but got none! Ignoring command.");
11266
        return;
11267
    }
11268
 
11269
    string sCommand;
11270
    string cmd = toUpper(pars[0]);
11271
 
11272
    // Master to panel
11273
    if (port >= 0)
11274
    {
11275
        if (!mSIPClient)
11276
        {
11277
            MSG_ERROR("SIP client class was not initialized!")
11278
            return;
11279
        }
11280
 
11281
        if (cmd == "ANSWER")
11282
        {
11283
            if (pars.size() >= 2)
11284
            {
124 andreas 11285
                int id = atoi(pars[1].c_str());
11286
 
11287
                if (mSIPClient->getSIPState(id) == TSIPClient::SIP_HOLD)
11288
                    mSIPClient->resume(id);
11289
                else
135 andreas 11290
                    mSIPClient->pickup(id);
123 andreas 11291
            }
11292
        }
11293
        else if (cmd == "AUTOANSWER")
11294
        {
11295
            if (pars.size() >= 2)
11296
            {
11297
                if (pars[1].at(0) == '0')
11298
                    mPHNautoanswer = false;
11299
                else
11300
                    mPHNautoanswer = true;
127 andreas 11301
 
11302
                vector<string> cmds;
11303
                cmds = { "AUTOANSWER", to_string(mPHNautoanswer ? 1 : 0) };
128 andreas 11304
                sendPHN(cmds);
123 andreas 11305
            }
11306
        }
11307
        else if (cmd == "CALL")     // Initiate a call
11308
        {
11309
            if (pars.size() >= 2)
127 andreas 11310
                mSIPClient->call(pars[1]);
123 andreas 11311
        }
11312
        else if (cmd == "DTMF")     // Send tone modified codes
11313
        {
127 andreas 11314
            if (pars.size() >= 2)
11315
                mSIPClient->sendDTMF(pars[1]);
123 andreas 11316
        }
11317
        else if (cmd == "HANGUP")   // terminate a call
11318
        {
124 andreas 11319
            if (pars.size() >= 2)
11320
            {
11321
                int id = atoi(pars[1].c_str());
11322
                mSIPClient->terminate(id);
11323
            }
123 andreas 11324
        }
11325
        else if (cmd == "HOLD")     // Hold the line
11326
        {
124 andreas 11327
            if (pars.size() >= 2)
11328
            {
11329
                int id = atoi(pars[1].c_str());
11330
                mSIPClient->hold(id);
11331
            }
123 andreas 11332
        }
128 andreas 11333
        else if (cmd == "LINESTATE") // State of all line
127 andreas 11334
        {
128 andreas 11335
            mSIPClient->sendLinestate();
127 andreas 11336
        }
123 andreas 11337
        else if (cmd == "PRIVACY")  // Set/unset "do not disturb"
11338
        {
128 andreas 11339
            if (pars.size() >= 2)
11340
            {
11341
                bool state = (pars[1].at(0) == '1' ? true : false);
11342
                mSIPClient->sendPrivate(state);
11343
            }
123 andreas 11344
        }
11345
        else if (cmd == "REDIAL")   // Redials the last number
11346
        {
128 andreas 11347
            mSIPClient->redial();
123 andreas 11348
        }
11349
        else if (cmd == "TRANSFER") // Transfer call to provided number
11350
        {
128 andreas 11351
            if (pars.size() >= 3)
11352
            {
11353
                int id = atoi(pars[1].c_str());
11354
                string num = pars[2];
11355
 
11356
                if (mSIPClient->transfer(id, num))
11357
                {
11358
                    vector<string> cmds;
11359
                    cmds.push_back("TRANSFERRED");
11360
                    sendPHN(cmds);
11361
                }
11362
            }
123 andreas 11363
        }
144 andreas 11364
        else if (cmd == "IM")
11365
        {
11366
            if (pars.size() < 3)
11367
                return;
11368
 
11369
            string to = pars[1];
11370
            string msg = pars[2];
11371
            string toUri;
11372
 
11373
            if (to.find("sip:") == string::npos)
11374
                toUri = "sip:";
11375
 
11376
            toUri += to;
11377
 
11378
            if (to.find("@") == string::npos)
11379
                toUri += "@" + TConfig::getSIPproxy();
11380
 
11381
            mSIPClient->sendIM(toUri, msg);
11382
        }
123 andreas 11383
        else if (cmd == "SETUP")    // Some temporary settings
11384
        {
11385
            if (pars.size() < 2)
11386
                return;
11387
 
11388
            if (pars[1] == "DOMAIN" && pars.size() >= 3)
11389
                TConfig::setSIPdomain(pars[2]);
11390
            else if (pars[1] == "DTMFDURATION")
11391
            {
138 andreas 11392
                unsigned int ms = atoi(pars[2].c_str());
11393
                mSIPClient->setDTMFduration(ms);
123 andreas 11394
            }
11395
            else if (pars[1] == "ENABLE")   // (re)register user
11396
            {
11397
                TConfig::setSIPstatus(true);
127 andreas 11398
                mSIPClient->cleanUp();
135 andreas 11399
                mSIPClient->init();
123 andreas 11400
            }
127 andreas 11401
            else if (pars[1] == "DOMAIN" && pars.size() >= 3)
11402
                TConfig::setSIPdomain(pars[2]);
123 andreas 11403
            else if (pars[1] == "PASSWORD" && pars.size() >= 3)
11404
                TConfig::setSIPpassword(pars[2]);
11405
            else if (pars[1] == "PORT" && pars.size() != 3)
11406
                TConfig::setSIPport(atoi(pars[2].c_str()));
11407
            else if (pars[1] == "PROXYADDR" && pars.size() >= 3)
11408
                TConfig::setSIPproxy(pars[2]);
11409
            else if (pars[1] == "STUNADDR" && pars.size() >= 3)
11410
                TConfig::setSIPstun(pars[2]);
11411
            else if (pars[1] == "USERNAME" && pars.size() >= 3)
11412
                TConfig::setSIPuser(pars[2]);
11413
        }
11414
        else
11415
        {
11416
            MSG_ERROR("Unknown command ^PHN-" << cmd << " ignored!");
11417
        }
11418
    }
11419
    else   // Panel to master
11420
    {
11421
        vector<string>::iterator iter;
11422
 
11423
        for (iter = pars.begin(); iter != pars.end(); ++iter)
11424
        {
11425
            if (!sCommand.empty())
11426
                sCommand += ",";
11427
 
11428
            sCommand += *iter;
11429
        }
11430
 
11431
        sendPHNcommand(sCommand);
11432
    }
11433
}
127 andreas 11434
 
11435
void TPageManager::getPHN(int, vector<int>&, vector<string>& pars)
11436
{
11437
    DECL_TRACER("TPageManager::getPHN(int, vector<int>&, vector<string>& pars)");
11438
 
11439
    if (pars.size() < 1)
11440
    {
11441
        MSG_ERROR("Invalid number of arguments!");
11442
        return;
11443
    }
11444
 
11445
    string cmd = pars[0];
11446
 
11447
    if (cmd == "AUTOANSWER")
11448
        sendPHNcommand(cmd + "," + (mPHNautoanswer ? "1" : "0"));
11449
    else if (cmd == "LINESTATE")
11450
    {
11451
        if (!mSIPClient)
11452
            return;
11453
 
138 andreas 11454
        mSIPClient->sendLinestate();
127 andreas 11455
    }
11456
    else if (cmd == "MSGWAITING")
11457
    {
144 andreas 11458
        size_t num = mSIPClient->getNumberMessages();
11459
        sendPHNcommand(cmd + "," + (num > 0 ? "1" : "0") + "," + std::to_string(num) + "0,0,0");
127 andreas 11460
    }
11461
    else if (cmd == "PRIVACY")
11462
    {
138 andreas 11463
        if (mSIPClient->getPrivate())
11464
            sendPHNcommand(cmd + ",1");
11465
        else
11466
            sendPHNcommand(cmd + ",0");
127 andreas 11467
    }
144 andreas 11468
    else if (cmd == "REDIAL")
11469
    {
11470
        if (pars.size() < 2)
11471
            return;
11472
 
11473
        sendPHNcommand(cmd + "," + pars[1]);
11474
    }
127 andreas 11475
    else
11476
    {
11477
        MSG_WARNING("Unknown command " << cmd << " found!");
11478
    }
11479
}
129 andreas 11480
#endif  // _NOSIP_
134 andreas 11481
 
300 andreas 11482
/*
318 andreas 11483
 *  Hide all subpages in a subpage viewer button.
11484
 */
11485
void TPageManager::doSHA(int port, vector<int> &channels, vector<string> &pars)
11486
{
11487
    DECL_TRACER("TPageManager::doSHA(int port, vector<int> &channels, vector<string> &pars)");
11488
 
343 andreas 11489
    Q_UNUSED(pars);
318 andreas 11490
    vector<TMap::MAP_T> map = findButtons(port, channels);
11491
 
11492
    if (TError::isError() || map.empty())
11493
        return;
11494
 
11495
    vector<Button::TButton *> buttons = collectButtons(map);
11496
 
11497
    if (!buttons.empty())
11498
    {
11499
        vector<Button::TButton *>::iterator mapIter;
11500
 
11501
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
11502
        {
11503
            Button::TButton *bt = *mapIter;
11504
 
11505
            if (_hideAllSubViewItems)
11506
                _hideAllSubViewItems(bt->getHandle());
11507
        }
11508
    }
11509
}
11510
 
11511
void TPageManager::doSHD(int port, vector<int>& channels, vector<string>& pars)
11512
{
11513
    DECL_TRACER("TPageManager::doSHD(int port, vector<int>& channels, vector<string>& pars)");
11514
 
11515
    if (pars.size() < 1)
11516
        return;
11517
 
11518
    string name = pars[0];
11519
 
11520
    vector<TMap::MAP_T> map = findButtons(port, channels);
11521
 
11522
    if (TError::isError() || map.empty())
11523
        return;
11524
 
11525
    vector<Button::TButton *> buttons = collectButtons(map);
11526
 
11527
    if (!buttons.empty())
11528
    {
11529
        vector<Button::TButton *>::iterator mapIter;
11530
 
11531
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
11532
        {
11533
            Button::TButton *bt = *mapIter;
11534
 
11535
            vector<TSubPage *> subviews = createSubViewList(bt->getSubViewID());
11536
 
11537
            if (subviews.empty())
11538
                continue;
11539
 
11540
            vector<TSubPage *>::iterator itSub;
11541
 
11542
            for (itSub = subviews.begin(); itSub != subviews.end(); ++itSub)
11543
            {
11544
                TSubPage *sub = *itSub;
11545
 
11546
                if (sub && sub->getName() == name)
11547
                {
11548
                    if (_hideSubViewItem)
11549
                        _hideSubViewItem(bt->getHandle(), sub->getHandle());
11550
 
11551
                    break;
11552
                }
11553
            }
11554
        }
11555
    }
11556
}
11557
 
11558
void TPageManager::doSPD(int port, vector<int>& channels, vector<string>& pars)
11559
{
11560
    DECL_TRACER("TPageManager::doSPD(int port, vector<int>& channel, vector<string>& pars)");
11561
 
11562
    if (pars.size() < 1)
11563
        return;
11564
 
11565
    TError::clear();
11566
    int padding = atoi(pars[0].c_str());
11567
 
11568
    if (padding < 0 || padding > 100)
11569
        return;
11570
 
11571
    vector<TMap::MAP_T> map = findButtons(port, channels);
11572
 
11573
    if (TError::isError() || map.empty())
11574
        return;
11575
 
11576
    vector<Button::TButton *> buttons = collectButtons(map);
11577
 
11578
    if (!buttons.empty())
11579
    {
11580
        vector<Button::TButton *>::iterator mapIter;
11581
 
11582
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
11583
        {
11584
            Button::TButton *bt = *mapIter;
11585
 
11586
            if (_setSubViewPadding)
11587
                _setSubViewPadding(bt->getHandle(), padding);
11588
        }
11589
    }
11590
}
11591
 
11592
/*
300 andreas 11593
 * This command will perform one of three different operations based on the following conditions:
11594
 * 1. If the named subpage is hidden in the set associated with the viewer button it will be shown in the anchor position.
11595
 * 2. If the named subpage is not present in the set it will be added to the set and shown in the anchor position.
11596
 * 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
11597
 * position. The anchor position is the location on the subpage viewer button specified by its weighting. This will either be
11598
 * left, center or right for horizontal subpage viewer buttons or top, center or bottom for vertical subpage viewer buttons.
11599
 * Surrounding subpages are relocated on the viewer button as needed to accommodate the described operations
11600
 */
11601
void TPageManager::doSSH(int port, vector<int> &channels, vector<string> &pars)
11602
{
11603
    DECL_TRACER("TPageManager::doSSH(int port, vector<int> &channels, vector<string> &pars)");
11604
 
11605
    if (pars.size() < 1)
11606
    {
11607
        MSG_ERROR("Expecting 1 parameter but got none! Ignoring command.");
11608
        return;
11609
    }
11610
 
11611
    TError::clear();
11612
    string name = pars[0];
11613
    int position = 0;   // optional
11614
    int time = 0;       // optional
11615
 
11616
    if (pars.size() > 1)
11617
        position = atoi(pars[1].c_str());
11618
 
11619
    if (pars.size() > 2)
11620
        time = atoi(pars[2].c_str());
11621
 
11622
    vector<TMap::MAP_T> map = findButtons(port, channels);
11623
 
11624
    if (TError::isError() || map.empty())
11625
        return;
11626
 
11627
    vector<Button::TButton *> buttons = collectButtons(map);
11628
 
11629
    if (!buttons.empty())
11630
    {
11631
        vector<Button::TButton *>::iterator mapIter;
11632
 
11633
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
11634
        {
11635
            Button::TButton *bt = *mapIter;
11636
            vector<TSubPage *> subviews = createSubViewList(bt->getSubViewID());
11637
 
11638
            if (subviews.empty() || !bt)
11639
                continue;
11640
 
11641
            vector<TSubPage *>::iterator itSub;
11642
 
11643
            for (itSub = subviews.begin(); itSub != subviews.end(); ++itSub)
11644
            {
11645
                TSubPage *sub = *itSub;
11646
 
11647
                if (sub && sub->getName() == name)
11648
                {
11649
                    if (_showSubViewItem)
11650
                        _showSubViewItem(sub->getHandle(), bt->getHandle(), position, time);
11651
 
11652
                    break;
11653
                }
11654
            }
11655
        }
11656
    }
11657
}
11658
 
318 andreas 11659
void TPageManager::doSTG(int port, vector<int>& channels, vector<string>& pars)
11660
{
11661
    DECL_TRACER("TPageManager::doSTG(int port, vector<int>& channels, vector<string>& pars)");
11662
 
11663
    if (pars.empty())
11664
    {
11665
        MSG_ERROR("Expecting 1 parameter but got none! Ignoring command.");
11666
        return;
11667
    }
11668
 
11669
    TError::clear();
11670
    string name = pars[0];
11671
    int position = 0;   // optional
11672
    int time = 0;       // optional
11673
 
11674
    if (pars.size() > 1)
11675
        position = atoi(pars[1].c_str());
11676
 
11677
    if (pars.size() > 2)
11678
        time = atoi(pars[2].c_str());
11679
 
11680
    vector<TMap::MAP_T> map = findButtons(port, channels);
11681
 
11682
    if (TError::isError() || map.empty())
11683
        return;
11684
 
11685
    vector<Button::TButton *> buttons = collectButtons(map);
11686
 
11687
    if (!buttons.empty())
11688
    {
11689
        vector<Button::TButton *>::iterator mapIter;
11690
 
11691
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
11692
        {
11693
            Button::TButton *bt = *mapIter;
11694
            vector<TSubPage *> subviews = createSubViewList(bt->getSubViewID());
11695
 
11696
            if (subviews.empty() || !bt)
11697
                continue;
11698
 
11699
            vector<TSubPage *>::iterator itSub;
11700
 
11701
            for (itSub = subviews.begin(); itSub != subviews.end(); ++itSub)
11702
            {
11703
                TSubPage *sub = *itSub;
11704
 
11705
                if (sub && sub->getName() == name)
11706
                {
11707
                    if (_toggleSubViewItem)
11708
                        _toggleSubViewItem(sub->getHandle(), bt->getHandle(), position, time);
11709
 
11710
                    break;
11711
                }
11712
            }
11713
        }
11714
    }
11715
}
11716
 
227 andreas 11717
void TPageManager::doLVD(int port, vector<int> &channels, vector<string> &pars)
225 andreas 11718
{
227 andreas 11719
    DECL_TRACER("TPageManager::doLVD(int port, vector<int> &channels, vector<string> &pars)");
225 andreas 11720
 
11721
    if (pars.size() < 1)
11722
    {
11723
        MSG_ERROR("Expecting one parameter but got none! Ignoring command.");
11724
        return;
11725
    }
11726
 
11727
    TError::clear();
11728
    string source = pars[0];
11729
    vector<string> configs;
11730
 
11731
    if (pars.size() > 1)
11732
    {
11733
        for (size_t i = 1; i < pars.size(); ++i)
227 andreas 11734
        {
11735
            string low = toLower(pars[i]);
11736
 
11737
            if (low.find_first_of("user=") != string::npos ||
11738
                low.find_first_of("pass=") != string::npos ||
11739
                low.find_first_of("csv=")  != string::npos ||
11740
                low.find_first_of("has_headers=") != string::npos)
11741
            {
11742
                configs.push_back(pars[i]);
11743
            }
11744
        }
225 andreas 11745
    }
11746
 
11747
    vector<TMap::MAP_T> map = findButtons(port, channels);
11748
 
11749
    if (TError::isError() || map.empty())
11750
        return;
11751
 
11752
    vector<Button::TButton *> buttons = collectButtons(map);
11753
 
11754
    if (buttons.size() > 0)
11755
    {
11756
        vector<Button::TButton *>::iterator mapIter;
11757
 
11758
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
11759
        {
11760
            Button::TButton *bt = *mapIter;
11761
            bt->setListSource(source, configs);
11762
        }
11763
    }
11764
 
11765
}
11766
 
230 andreas 11767
void TPageManager::doLVE(int port, vector<int> &channels, vector<string> &pars)
11768
{
11769
    DECL_TRACER("TPageManager::doLVE(int port, vector<int> &channels, vector<string> &pars)");
11770
 
11771
    if (pars.size() < 1)
11772
    {
11773
        MSG_ERROR("Expecting one parameter but got none! Ignoring command.");
11774
        return;
11775
    }
11776
 
11777
    TError::clear();
11778
    int num = atoi(pars[0].c_str());
11779
 
11780
    vector<TMap::MAP_T> map = findButtons(port, channels);
11781
 
11782
    if (TError::isError() || map.empty())
11783
        return;
11784
 
11785
    vector<Button::TButton *> buttons = collectButtons(map);
11786
 
11787
    if (buttons.size() > 0)
11788
    {
11789
        vector<Button::TButton *>::iterator mapIter;
11790
 
11791
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
11792
        {
11793
            Button::TButton *bt = *mapIter;
11794
            bt->setListViewEventNumber(num);
11795
        }
11796
    }
11797
 
11798
}
11799
 
227 andreas 11800
void TPageManager::doLVF(int port, vector<int> &channels, vector<string> &pars)
11801
{
11802
    DECL_TRACER("TPageManager::doLVF(int port, vector<int> &channels, vector<string> &pars)");
11803
 
11804
    if (pars.size() < 1)
11805
    {
11806
        MSG_ERROR("Expecting one parameter but got none! Ignoring command.");
11807
        return;
11808
    }
11809
 
11810
    TError::clear();
11811
    string filter;
11812
 
11813
    vector<string>::iterator iter;
11814
 
11815
    for (iter = pars.begin(); iter != pars.end(); ++iter)
11816
    {
11817
        if (filter.length() > 0)
11818
            filter += ",";
11819
 
11820
        filter += *iter;
11821
    }
11822
 
11823
    vector<TMap::MAP_T> map = findButtons(port, channels);
11824
 
11825
    if (TError::isError() || map.empty())
11826
        return;
11827
 
11828
    vector<Button::TButton *> buttons = collectButtons(map);
11829
 
11830
    if (buttons.size() > 0)
11831
    {
11832
        vector<Button::TButton *>::iterator mapIter;
11833
 
11834
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
11835
        {
11836
            Button::TButton *bt = *mapIter;
11837
            bt->setListSourceFilter(filter);
11838
        }
11839
    }
11840
}
11841
 
230 andreas 11842
void TPageManager::doLVL(int port, vector<int> &channels, vector<string> &pars)
11843
{
11844
    DECL_TRACER("TPageManager::doLVL(int port, vector<int> &channels, vector<string> &pars)");
11845
 
11846
    if (pars.size() < 1)
11847
    {
11848
        MSG_ERROR("Expecting one parameter but got none! Ignoring command.");
11849
        return;
11850
    }
11851
 
11852
    TError::clear();
233 andreas 11853
    bool hasColumns = false;
230 andreas 11854
    int columns = 0;
233 andreas 11855
    bool hasLayout = false;
230 andreas 11856
    int layout = 0;
233 andreas 11857
    bool hasComponent = false;
11858
    int component = 0;
11859
    bool hasCellHeight = false;
11860
    bool cellHeightPercent = false;
11861
    int cellheight = 0;
11862
    bool hasP1 = false;
11863
    int p1 = 0;
11864
    bool hasP2 = false;
11865
    int p2 = 0;
11866
    bool hasFilter = false;
11867
    bool filter = false;
11868
    bool hasFilterHeight = false;
11869
    bool filterHeightPercent = false;
11870
    int filterheight = 0;
11871
    bool hasAlphaScroll = false;
11872
    bool alphascroll = false;
230 andreas 11873
 
11874
    vector<string>::iterator iter;
11875
 
11876
    for (iter = pars.begin(); iter != pars.end(); ++iter)
11877
    {
11878
        string low = toLower(*iter);
11879
 
11880
        if (low.find("columns=") != string::npos ||
11881
            low.find("nc=") != string::npos ||
11882
            low.find("numcol=") != string::npos)
11883
        {
11884
            size_t pos = low.find("=");
11885
            string sCols = low.substr(pos + 1);
11886
            columns = atoi(sCols.c_str());
233 andreas 11887
            hasColumns = true;
11888
        }
11889
        else if (low.find("c=") != string::npos || low.find("comp=") != string::npos)
11890
        {
11891
            size_t pos = low.find("=");
11892
            string sComp = low.substr(pos + 1);
11893
            component |= atoi(sComp.c_str());
11894
            hasComponent = true;
11895
        }
11896
        else if (low.find("l=") != string::npos || low.find("layout=") != string::npos)
11897
        {
11898
            size_t pos = low.find("=");
11899
            string sLay = low.substr(pos + 1);
11900
            layout = atoi(sLay.c_str());
11901
            hasLayout = true;
11902
        }
11903
        else if (low.find("ch=") != string::npos || low.find("cellheight=") != string::npos)
11904
        {
11905
            size_t pos = low.find("=");
11906
            string sCh = low.substr(pos + 1);
11907
            cellheight = atoi(sCh.c_str());
230 andreas 11908
 
233 andreas 11909
            if (low.find("%") != string::npos)
11910
                cellHeightPercent = true;
11911
 
11912
            hasCellHeight = true;
230 andreas 11913
        }
233 andreas 11914
        else if (low.find("p1=") != string::npos)
11915
        {
11916
            size_t pos = low.find("=");
11917
            string sP1 = low.substr(pos + 1);
11918
            p1 = atoi(sP1.c_str());
11919
            hasP1 = true;
11920
        }
11921
        else if (low.find("p2=") != string::npos)
11922
        {
11923
            size_t pos = low.find("=");
11924
            string sP2 = low.substr(pos + 1);
11925
            p2 = atoi(sP2.c_str());
11926
            hasP2 = true;
11927
        }
11928
        else if (low.find("f=") != string::npos || low.find("filter=") != string::npos)
11929
        {
11930
            size_t pos = low.find("=");
11931
            string sFilter = low.substr(pos + 1);
11932
            filter = isTrue(sFilter);
11933
            hasFilter = true;
11934
        }
11935
        else if (low.find("fh=") != string::npos || low.find("filterheight=") != string::npos)
11936
        {
11937
            size_t pos = low.find("=");
11938
            string sFilter = low.substr(pos + 1);
11939
            filterheight = atoi(sFilter.c_str());
11940
 
11941
            if (low.find("%") != string::npos)
11942
                filterHeightPercent = true;
11943
 
11944
            hasFilterHeight = true;
11945
        }
11946
        else if (low.find("as=") != string::npos || low.find("alphascroll=") != string::npos)
11947
        {
11948
            size_t pos = low.find("=");
11949
            string sAlpha = low.substr(pos + 1);
11950
            alphascroll = isTrue(sAlpha);
11951
            hasAlphaScroll = true;
11952
        }
230 andreas 11953
    }
11954
 
11955
    vector<TMap::MAP_T> map = findButtons(port, channels);
11956
 
11957
    if (TError::isError() || map.empty())
11958
        return;
11959
 
11960
    vector<Button::TButton *> buttons = collectButtons(map);
11961
 
11962
    if (buttons.size() > 0)
11963
    {
11964
        vector<Button::TButton *>::iterator mapIter;
11965
 
11966
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
11967
        {
11968
            Button::TButton *bt = *mapIter;
233 andreas 11969
 
11970
            if (hasColumns)         bt->setListViewColumns(columns);
11971
            if (hasComponent)       bt->setListViewComponent(component);
11972
            if (hasLayout)          bt->setListViewLayout(layout);
11973
            if (hasCellHeight)      bt->setListViewCellheight(cellheight, cellHeightPercent);
11974
            if (hasP1)              bt->setListViewP1(p1);
11975
            if (hasP2)              bt->setListViewP2(p2);
11976
            if (hasFilter)          bt->setListViewColumnFilter(filter);
11977
            if (hasFilterHeight)    bt->setListViewFilterHeight(filterheight, filterHeightPercent);
11978
            if (hasAlphaScroll)     bt->setListViewAlphaScroll(alphascroll);
230 andreas 11979
        }
11980
    }
11981
}
11982
 
233 andreas 11983
void TPageManager::doLVM(int port, vector<int> &channels, vector<string> &pars)
11984
{
11985
    DECL_TRACER("TPageManager::doLVM(int port, vector<int> &channels, vector<string> &pars)");
11986
 
11987
    if (pars.size() < 1)
11988
    {
11989
        MSG_ERROR("Expecting one parameter but got none! Ignoring command.");
11990
        return;
11991
    }
11992
 
11993
    TError::clear();
11994
    map<string,string> mapField;
11995
 
11996
    vector<string>::iterator iter;
11997
 
11998
    for (iter = pars.begin(); iter != pars.end(); ++iter)
11999
    {
12000
        string left, right;
12001
        size_t pos = 0;
12002
 
12003
        if ((pos = iter->find("=")) != string::npos)
12004
        {
12005
            string left = iter->substr(0, pos);
12006
            left = toLower(left);
12007
            string right = iter->substr(pos + 1);
12008
 
12009
            if (left == "t1" || left == "t2" || left == "i1")
12010
                mapField.insert(pair<string,string>(left, right));
12011
        }
12012
    }
12013
 
12014
    vector<TMap::MAP_T> map = findButtons(port, channels);
12015
 
12016
    if (TError::isError() || map.empty())
12017
        return;
12018
 
12019
    vector<Button::TButton *> buttons = collectButtons(map);
12020
 
12021
    if (buttons.size() > 0)
12022
    {
12023
        vector<Button::TButton *>::iterator mapIter;
12024
 
12025
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
12026
        {
12027
            Button::TButton *bt = *mapIter;
12028
            bt->setListViewFieldMap(mapField);
12029
        }
12030
    }
12031
}
12032
 
12033
void TPageManager::doLVN(int port, vector<int> &channels, vector<string> &pars)
12034
{
12035
    DECL_TRACER("TPageManager::doLVN(int port, vector<int> &channels, vector<string> &pars)");
12036
 
12037
    if (pars.size() < 1)
12038
    {
12039
        MSG_ERROR("Expecting one parameter but got none! Ignoring command.");
12040
        return;
12041
    }
12042
 
12043
    TError::clear();
12044
    string command = pars[0];
12045
    bool select = false;
12046
 
12047
    if (pars.size() > 1)
12048
    {
12049
        if (isTrue(pars[1]))
12050
            select = true;
12051
    }
12052
 
12053
    vector<TMap::MAP_T> map = findButtons(port, channels);
12054
 
12055
    if (TError::isError() || map.empty())
12056
        return;
12057
 
12058
    vector<Button::TButton *> buttons = collectButtons(map);
12059
 
12060
    if (buttons.size() > 0)
12061
    {
12062
        vector<Button::TButton *>::iterator mapIter;
12063
 
12064
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
12065
        {
12066
            Button::TButton *bt = *mapIter;
12067
            bt->listViewNavigate(command, select);
12068
        }
12069
    }
12070
}
12071
 
12072
void TPageManager::doLVR(int port, vector<int> &channels, vector<string> &pars)
12073
{
12074
    DECL_TRACER("TPageManager::doLVR(int port, vector<int> &channels, vector<string> &pars)");
12075
 
12076
    TError::clear();
12077
    int interval = -1;
12078
    bool force = false;
12079
 
12080
    if (pars.size() > 0)
12081
        interval = atoi(pars[0].c_str());
12082
 
12083
    if (pars.size() > 1)
12084
        force = isTrue(pars[1]);
12085
 
12086
    vector<TMap::MAP_T> map = findButtons(port, channels);
12087
 
12088
    if (TError::isError() || map.empty())
12089
        return;
12090
 
12091
    vector<Button::TButton *> buttons = collectButtons(map);
12092
 
12093
    if (buttons.size() > 0)
12094
    {
12095
        vector<Button::TButton *>::iterator mapIter;
12096
 
12097
        for (mapIter = buttons.begin(); mapIter != buttons.end(); mapIter++)
12098
        {
12099
            Button::TButton *bt = *mapIter;
12100
            bt->listViewRefresh(interval, force);
12101
        }
12102
    }
12103
}
12104
 
12105
void TPageManager::doLVS(int port, vector<int> &channels, vector<string> &pars)
12106
{
12107
    DECL_TRACER("TPageManager::doLVS(int port, vector<int> &channels, vector<string> &pars)");
12108
 
12109
    TError::clear();
12110
    vector<string> sortColumns;
12111
    Button::LIST_SORT sort = Button::LIST_SORT_NONE;
12112
    string override;
12113
 
12114
    if (pars.size() > 0)
12115
    {
12116
        vector<string>::iterator iter;
12117
 
12118
        for (iter = pars.begin(); iter != pars.end(); ++iter)
12119
        {
12120
            if (iter->find(";") == string::npos)
12121
                sortColumns.push_back(*iter);
12122
            else
12123
            {
12124
                vector<string> parts = StrSplit(*iter, ";");
12125
                sortColumns.push_back(parts[0]);
12126
 
12127
                if (parts[1].find("a") != string::npos || parts[1].find("A") != string::npos)
12128
                    sort = Button::LIST_SORT_ASC;
12129
                else if (parts[1].find("d") != string::npos || parts[1].find("D") != string::npos)
12130
                    sort = Button::LIST_SORT_DESC;
12131
                else if (parts[1].find("*") != string::npos)
12132
                {
12133
                    if (parts.size() > 2 && !parts[2].empty())
12134
                    {
12135
                        override = parts[2];
12136
                        sort = Button::LIST_SORT_OVERRIDE;
12137
                    }
12138
                }
12139
                else if (parts[1].find("n") != string::npos || parts[1].find("N") != string::npos)
12140
                    sort = Button::LIST_SORT_NONE;
12141
            }
12142
        }
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->listViewSortData(sortColumns, sort, override);
12160
        }
12161
    }
12162
}
12163
 
134 andreas 12164
void TPageManager::doTPCCMD(int, vector<int>&, vector<string>& pars)
12165
{
12166
    DECL_TRACER("TPageManager::doTPCCMD(int, vector<int>&, vector<string>& pars)");
12167
 
12168
    if (pars.size() < 1)
12169
    {
12170
        MSG_ERROR("Too few arguments for TPCCMD!");
12171
        return;
12172
    }
12173
 
12174
    string cmd = pars[0];
12175
 
12176
    if (strCaseCompare(cmd, "LocalHost") == 0)
12177
    {
12178
        if (pars.size() < 2 || pars[1].empty())
12179
        {
12180
            MSG_ERROR("The command \"LocalHost\" requires an additional parameter!");
12181
            return;
12182
        }
12183
 
12184
        TConfig::saveController(pars[1]);
12185
    }
12186
    else if (strCaseCompare(cmd, "LocalPort") == 0)
12187
    {
12188
        if (pars.size() < 2 || pars[1].empty())
12189
        {
12190
            MSG_ERROR("The command \"LocalPort\" requires an additional parameter!");
12191
            return;
12192
        }
12193
 
12194
        int port = atoi(pars[1].c_str());
12195
 
12196
        if (port > 0 && port < 65536)
12197
            TConfig::savePort(port);
12198
        else
12199
        {
12200
            MSG_ERROR("Invalid network port " << port);
12201
        }
12202
    }
12203
    else if (strCaseCompare(cmd, "DeviceID") == 0)
12204
    {
12205
        if (pars.size() < 2 || pars[1].empty())
12206
        {
12207
            MSG_ERROR("The command \"DeviceID\" requires an additional parameter!");
12208
            return;
12209
        }
12210
 
12211
        int id = atoi(pars[1].c_str());
12212
 
12213
        if (id >= 10000 && id < 30000)
12214
            TConfig::setSystemChannel(id);
12215
    }
12216
    else if (strCaseCompare(cmd, "ApplyProfile") == 0)
12217
    {
12218
        // We restart the network connection only
12219
        if (gAmxNet)
12220
            gAmxNet->reconnect();
12221
    }
12222
    else if (strCaseCompare(cmd, "QueryDeviceInfo") == 0)
12223
    {
12224
        string info = "DEVICEINFO-TPANELID," + TConfig::getPanelType();
12225
        info += ";HOSTNAME,";
12226
        char hostname[HOST_NAME_MAX];
12227
 
12228
        if (gethostname(hostname, HOST_NAME_MAX) != 0)
12229
        {
12230
            MSG_ERROR("Can't get host name: " << strerror(errno));
12231
            return;
12232
        }
12233
 
12234
        info.append(hostname);
12235
        info += ";UUID," + TConfig::getUUID();
12236
        sendGlobalString(info);
12237
    }
12238
    else if (strCaseCompare(cmd, "LockRotation") == 0)
12239
    {
12240
        if (pars.size() < 2 || pars[1].empty())
12241
        {
12242
            MSG_ERROR("The command \"LockRotation\" requires an additional parameter!");
12243
            return;
12244
        }
12245
 
12246
        if (strCaseCompare(pars[1], "true") == 0)
12247
            TConfig::setRotationFixed(true);
12248
        else
12249
            TConfig::setRotationFixed(false);
12250
    }
12251
    else if (strCaseCompare(cmd, "ButtonHit") == 0)
12252
    {
12253
        if (pars.size() < 2 || pars[1].empty())
12254
        {
12255
            MSG_ERROR("The command \"ButtonHit\" requires an additional parameter!");
12256
            return;
12257
        }
12258
 
12259
        if (strCaseCompare(pars[1], "true") == 0)
12260
            TConfig::saveSystemSoundState(true);
12261
        else
12262
            TConfig::saveSystemSoundState(false);
12263
    }
12264
    else if (strCaseCompare(cmd, "ReprocessTP4") == 0)
12265
    {
12266
        if (_resetSurface)
12267
            _resetSurface();
12268
    }
12269
}
12270
 
12271
void TPageManager::doTPCACC(int, vector<int>&, vector<string>& pars)
12272
{
12273
    DECL_TRACER("TPageManager::doTPCACC(int, vector<int>&, vector<string>& pars)");
12274
 
12275
    if (pars.size() < 1)
12276
    {
12277
        MSG_ERROR("Too few arguments for TPCACC!");
12278
        return;
12279
    }
12280
 
12281
    string cmd = pars[0];
12282
 
12283
    if (strCaseCompare(cmd, "ENABLE") == 0)
12284
    {
12285
        mInformOrientation = true;
12286
        sendOrientation();
12287
    }
12288
    else if (strCaseCompare(cmd, "DISABLE") == 0)
12289
    {
12290
        mInformOrientation = false;
12291
    }
12292
    else if (strCaseCompare(cmd, "QUERY") == 0)
12293
    {
12294
        sendOrientation();
12295
    }
12296
}
153 andreas 12297
 
279 andreas 12298
#ifndef _NOSIP_
153 andreas 12299
void TPageManager::doTPCSIP(int, vector<int>&, vector<string>& pars)
12300
{
12301
    DECL_TRACER("TPageManager::doTPCSIP(int port, vector<int>& channels, vector<string>& pars)");
12302
 
12303
    if (pars.empty())
12304
        return;
12305
 
12306
    string cmd = toUpper(pars[0]);
12307
 
12308
    if (cmd == "SHOW" && _showPhoneDialog)
12309
        _showPhoneDialog(true);
12310
    else if (!_showPhoneDialog)
12311
    {
12312
        MSG_ERROR("There is no phone dialog registered!");
12313
    }
12314
}
279 andreas 12315
#endif