-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbrowserwindow.cpp
754 lines (625 loc) · 25.7 KB
/
browserwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
// Copyright (c) 2019 Rumen G.Bogdanovski & David Hulse
// All rights reserved.
//
// You can use this software under the terms of 'INDIGO Astronomy
// open-source license' (see LICENSE.md).
//
// THIS SOFTWARE IS PROVIDED BY THE AUTHORS 'AS IS' AND ANY EXPRESS
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QSplitter>
#include <QTreeView>
#include <QMenuBar>
#include <QIcon>
#include <QScrollArea>
#include <QMessageBox>
#include <QActionGroup>
#include <QFileDialog>
#include <sys/time.h>
#include "browserwindow.h"
#include "qservicemodel.h"
#include "propertymodel.h"
#include "indigoclient.h"
#include "qindigoproperty.h"
#include "qindigoservers.h"
#include "blobpreview.h"
#include "logger.h"
#include "conf.h"
#include "version.h"
void write_conf();
BrowserWindow::BrowserWindow(QWidget *parent) : QMainWindow(parent) {
setWindowTitle(tr("INDIGO Control Panel"));
resize(1024, 768);
QIcon icon(":resource/appicon.png");
this->setWindowIcon(icon);
QFile f(":resource/control_panel.qss");
f.open(QFile::ReadOnly | QFile::Text);
QTextStream ts(&f);
this->setStyleSheet(ts.readAll());
f.close();
current_path = new SelectionPath();
mIndigoServers = new QIndigoServers(this);
// Set central widget of window
QWidget *central = new QWidget;
setCentralWidget(central);
// Set the root layout to be a VBox
QVBoxLayout *rootLayout = new QVBoxLayout;
rootLayout->setSpacing(0);
rootLayout->setContentsMargins(0, 0, 0, 0);
rootLayout->setSizeConstraint(QLayout::SetMinimumSize);
central->setLayout(rootLayout);
// Create log viewer
mLog = new QTextEdit;
mLog->setReadOnly(true);
// Create menubar
QMenuBar *menu_bar = new QMenuBar;
QMenu *menu = new QMenu("&File");
QAction *act;
act = menu->addAction(tr("&Manage services"));
connect(act, &QAction::triggered, this, &BrowserWindow::on_servers_act);
menu->addSeparator();
act = menu->addAction(tr("&Load Device ACL..."));
connect(act, &QAction::triggered, this, &BrowserWindow::on_acl_load_act);
act = menu->addAction(tr("&Append to Device ACL..."));
connect(act, &QAction::triggered, this, &BrowserWindow::on_acl_append_act);
act = menu->addAction(tr("&Save Device ACL As..."));
connect(act, &QAction::triggered, this, &BrowserWindow::on_acl_save_act);
act = menu->addAction(tr("&Clear Device ACL"));
connect(act, &QAction::triggered, this, &BrowserWindow::on_acl_clear_act);
menu->addSeparator();
act = menu->addAction(tr("&Exit"));
connect(act, &QAction::triggered, this, &BrowserWindow::on_exit_act);
menu_bar->addMenu(menu);
menu = new QMenu("&Edit");
act = menu->addAction(tr("Clear &messages"));
connect(act, &QAction::triggered, mLog, &QTextEdit::clear);
menu_bar->addMenu(menu);
menu = new QMenu("&Settings");
act = menu->addAction(tr("Enable &BLOBs"));
act->setCheckable(true);
act->setChecked(conf.blobs_enabled);
connect(act, &QAction::toggled, this, &BrowserWindow::on_blobs_changed);
act = menu->addAction(tr("&Auto connect new services"));
act->setCheckable(true);
act->setChecked(conf.auto_connect);
connect(act, &QAction::toggled, this, &BrowserWindow::on_bonjour_changed);
act = menu->addAction(tr("&Use host suffix"));
act->setCheckable(true);
act->setChecked(conf.indigo_use_host_suffix);
connect(act, &QAction::toggled, this, &BrowserWindow::on_use_suffix_changed);
act = menu->addAction(tr("Use property state &icons"));
act->setCheckable(true);
act->setChecked(conf.use_state_icons);
connect(act, &QAction::toggled, this, &BrowserWindow::on_use_state_icons_changed);
act = menu->addAction(tr("Use &locale specific decimal separator"));
act->setCheckable(true);
act->setChecked(conf.use_system_locale);
connect(act, &QAction::toggled, this, &BrowserWindow::on_use_system_locale_changed);
menu->addSeparator();
QActionGroup *stretch_group = new QActionGroup(this);
stretch_group->setExclusive(true);
act = menu->addAction("Preview Levels Stretch: N&one");
act->setCheckable(true);
if (conf.preview_stretch_level == STRETCH_NONE) act->setChecked(true);
connect(act, &QAction::triggered, this, &BrowserWindow::on_no_stretch);
stretch_group->addAction(act);
act = menu->addAction("Preview Levels Stretch: &Normal");
act->setCheckable(true);
if (conf.preview_stretch_level == STRETCH_NORMAL) act->setChecked(true);
connect(act, &QAction::triggered, this, &BrowserWindow::on_normal_stretch);
stretch_group->addAction(act);
act = menu->addAction("Preview Levels Stretch: &Hard");
act->setCheckable(true);
if (conf.preview_stretch_level == STRETCH_HARD) act->setChecked(true);
connect(act, &QAction::triggered, this, &BrowserWindow::on_hard_stretch);
stretch_group->addAction(act);
menu->addSeparator();
QActionGroup *log_group = new QActionGroup(this);
log_group->setExclusive(true);
act = menu->addAction("Log &Error");
act->setCheckable(true);
if (conf.indigo_log_level == INDIGO_LOG_ERROR) act->setChecked(true);
connect(act, &QAction::triggered, this, &BrowserWindow::on_log_error);
log_group->addAction(act);
act = menu->addAction("Log &Info");
act->setCheckable(true);
if (conf.indigo_log_level == INDIGO_LOG_INFO) act->setChecked(true);
connect(act, &QAction::triggered, this, &BrowserWindow::on_log_info);
log_group->addAction(act);
act = menu->addAction("Log &Debug");
act->setCheckable(true);
if (conf.indigo_log_level == INDIGO_LOG_DEBUG) act->setChecked(true);
connect(act, &QAction::triggered, this, &BrowserWindow::on_log_debug);
log_group->addAction(act);
act = menu->addAction("Log &Trace");
act->setCheckable(true);
if (conf.indigo_log_level == INDIGO_LOG_TRACE) act->setChecked(true);
connect(act, &QAction::triggered, this, &BrowserWindow::on_log_trace);
log_group->addAction(act);
menu_bar->addMenu(menu);
menu = new QMenu("&Help");
act = menu->addAction(tr("&About"));
connect(act, &QAction::triggered, this, &BrowserWindow::on_about_act);
menu_bar->addMenu(menu);
rootLayout->addWidget(menu_bar);
// Create properties viewing area
QWidget *view = new QWidget;
QVBoxLayout *propertyLayout = new QVBoxLayout;
propertyLayout->setSpacing(5);
propertyLayout->setContentsMargins(5, 5, 5, 5);
propertyLayout->setSizeConstraint(QLayout::SetMinimumSize);
view->setLayout(propertyLayout);
rootLayout->addWidget(view);
mProperties = new QTreeView;
QWidget *form_panel = new QWidget();
mFormLayout = new QVBoxLayout();
mFormLayout->setSpacing(0);
mFormLayout->setContentsMargins(1, 0, 0, 0);
//mFormLayout->setMargin(0);
form_panel->setLayout(mFormLayout);
QWidget *selection_panel = new QWidget();
QVBoxLayout *selection_layout = new QVBoxLayout();
selection_layout->setSpacing(0);
selection_layout->setContentsMargins(0, 0, 1, 0);
//selection_layout->setMargin(0);
selection_panel->setLayout(selection_layout);
selection_layout->addWidget(mProperties);
mSelectionLine = new QLabel();
mSelectionLine->setObjectName("SELECTION_TEXT");
mScrollArea = new QScrollArea();
mScrollArea->setObjectName("PROPERTY_AREA");
mScrollArea->setWidgetResizable(true);
mScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
mScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
mFormLayout->addWidget(mSelectionLine);
mFormLayout->addWidget(mScrollArea);
mScrollArea->setMinimumWidth(PROPERTY_AREA_MIN_WIDTH);
QSplitter* hSplitter = new QSplitter;
hSplitter->addWidget(selection_panel);
hSplitter->addWidget(form_panel);
hSplitter->setStretchFactor(0, 45);
hSplitter->setStretchFactor(2, 55);
propertyLayout->addWidget(hSplitter, 85);
propertyLayout->addWidget(mLog, 15);
mServiceModel = &QServiceModel::instance();
mServiceModel->enable_auto_connect(conf.auto_connect);
mPropertyModel = new PropertyModel();
mProperties->setHeaderHidden(true);
mProperties->setModel(mPropertyModel);
connect(mServiceModel, &QServiceModel::serviceAdded, mIndigoServers, &QIndigoServers::onAddService);
connect(mServiceModel, &QServiceModel::serviceRemoved, mIndigoServers, &QIndigoServers::onRemoveService);
connect(mServiceModel, &QServiceModel::serviceConnectionChange, mIndigoServers, &QIndigoServers::onConnectionChange);
connect(mIndigoServers, &QIndigoServers::requestConnect, mServiceModel, &QServiceModel::onRequestConnect);
connect(mIndigoServers, &QIndigoServers::requestDisconnect, mServiceModel, &QServiceModel::onRequestDisconnect);
connect(mIndigoServers, &QIndigoServers::requestAddManualService, mServiceModel, &QServiceModel::onRequestAddManualService);
connect(mIndigoServers, &QIndigoServers::requestRemoveManualService, mServiceModel, &QServiceModel::onRequestRemoveManualService);
connect(mIndigoServers, &QIndigoServers::requestSaveServices, mServiceModel, &QServiceModel::onRequestSaveServices);
// NOTE: logging should be before update and delete of properties as they release the copy!!!
connect(&IndigoClient::instance(), &IndigoClient::property_defined, this, &BrowserWindow::on_message_sent);
connect(&IndigoClient::instance(), &IndigoClient::property_changed, this, &BrowserWindow::on_message_sent);
connect(&IndigoClient::instance(), &IndigoClient::property_deleted, this, &BrowserWindow::on_message_sent);
connect(&IndigoClient::instance(), &IndigoClient::message_sent, this, &BrowserWindow::on_message_sent);
connect(&IndigoClient::instance(), &IndigoClient::create_preview, this, &BrowserWindow::on_create_preview, Qt::BlockingQueuedConnection);
connect(&IndigoClient::instance(), &IndigoClient::obsolete_preview, this, &BrowserWindow::on_obsolete_preview, Qt::BlockingQueuedConnection);
connect(&IndigoClient::instance(), &IndigoClient::remove_preview, this, &BrowserWindow::on_remove_preview, Qt::BlockingQueuedConnection);
connect(&IndigoClient::instance(), &IndigoClient::no_preview, this, &BrowserWindow::on_remove_preview, Qt::BlockingQueuedConnection);
connect(&IndigoClient::instance(), &IndigoClient::property_defined, mPropertyModel, &PropertyModel::define_property, Qt::BlockingQueuedConnection);
connect(&IndigoClient::instance(), &IndigoClient::property_changed, mPropertyModel, &PropertyModel::update_property, Qt::BlockingQueuedConnection);
connect(&IndigoClient::instance(), &IndigoClient::property_deleted, mPropertyModel, &PropertyModel::delete_property, Qt::BlockingQueuedConnection);
connect(mPropertyModel, &PropertyModel::property_defined, this, &BrowserWindow::on_property_define);
connect(mPropertyModel, &PropertyModel::property_deleted, this, &BrowserWindow::on_property_delete);
connect(&Logger::instance(), &Logger::do_log, this, &BrowserWindow::on_window_log);
connect(mProperties->selectionModel(), &QItemSelectionModel::selectionChanged, this, &BrowserWindow::on_selection_changed);
connect(this, &BrowserWindow::enable_blobs, mPropertyModel, &PropertyModel::enable_blobs);
connect(this, &BrowserWindow::rebuild_blob_previews, mPropertyModel, &PropertyModel::rebuild_blob_previews);
preview_cache.set_stretch_level(conf.preview_stretch_level);
// Start up the client
IndigoClient::instance().enable_blobs(conf.blobs_enabled);
IndigoClient::instance().start("INDIGO Control Panel");
// load manually configured services
mServiceModel->loadManualServices();
}
BrowserWindow::~BrowserWindow () {
indigo_debug("CALLED: %s\n", __FUNCTION__);
delete mLog;
delete mProperties;
delete mSelectionLine;
delete mFormLayout;
delete mIndigoServers;
delete mServiceModel;
delete mPropertyModel;
delete current_path;
}
void BrowserWindow::on_create_preview(indigo_property *property, indigo_item *item){
preview_cache.create(property, item);
}
void BrowserWindow::on_obsolete_preview(indigo_property *property, indigo_item *item){
preview_cache.obsolete(property, item);
}
void BrowserWindow::on_remove_preview(indigo_property *property, indigo_item *item){
preview_cache.remove(property, item);
}
void BrowserWindow::on_message_sent(indigo_property* property, char *message) {
on_window_log(property, message);
free(message);
}
void BrowserWindow::on_window_log(indigo_property* property, char *message) {
char timestamp[16];
char log_line[512];
struct timeval tmnow;
if (!message) return;
gettimeofday(&tmnow, NULL);
#if defined(INDIGO_WINDOWS)
struct tm *lt;
time_t rawtime;
lt = localtime((const time_t *) &(tmnow.tv_sec));
if (lt == NULL) {
time(&rawtime);
lt = localtime(&rawtime);
}
strftime(timestamp, sizeof(log_line), "%H:%M:%S", lt);
#else
strftime(timestamp, sizeof(log_line), "%H:%M:%S", localtime((const time_t *) &tmnow.tv_sec));
#endif
snprintf(timestamp + 8, sizeof(timestamp) - 8, ".%03ld", tmnow.tv_usec/1000);
if (property) {
switch (property->state) {
case INDIGO_ALERT_STATE:
mLog->setTextColor(QColor::fromRgb(224, 0, 0));
break;
case INDIGO_BUSY_STATE:
mLog->setTextColor(QColor::fromRgb(255, 165, 0));
break;
default:
mLog->setTextColor(Qt::white);
break;
}
snprintf(log_line, 512, "%s %s.%s: %s", timestamp, property->device, property->name, message);
} else {
QString msg(message);
if (
(
msg.contains("fail", Qt::CaseInsensitive)
) || ( /* match "error" but not polar alignment error messages */
msg.contains("error", Qt::CaseInsensitive) &&
!msg.contains("Polar error:") &&
!msg.contains("adjustment knob", Qt::CaseInsensitive)
)
) {
mLog->setTextColor(QColor::fromRgb(224, 0, 0));
} else if (msg.contains("warn", Qt::CaseInsensitive)) {
mLog->setTextColor(QColor::fromRgb(255, 165, 0));
} else {
mLog->setTextColor(Qt::white);
}
snprintf(log_line, 512, "%s %s", timestamp, message);
}
indigo_log("[message] %s\n", log_line);
mLog->append(log_line);
mLog->verticalScrollBar()->setValue(mLog->verticalScrollBar()->maximum());
}
void BrowserWindow::on_property_define(indigo_property* property, char *message) {
property_define_delete(property, message, false);
}
void BrowserWindow::on_property_delete(indigo_property* property, char *message) {
property_define_delete(property, message, true);
}
void BrowserWindow::property_define_delete(indigo_property* property, char *message, bool action_deleted) {
Q_UNUSED(message);
if (current_path->type == TREE_NODE_ROOT) return;
if (current_path->type == TREE_NODE_PROPERTY) {
/* We can not have selected property to be defined -> so just clean window */
if (!strcmp(current_path->property, property->name) &&
!strcmp(current_path->device, property->device) &&
!strcmp(current_path->group, property->group)) {
if (action_deleted) {
indigo_debug("SELECTED PROPERTY deleted\n");
clear_window();
}
return;
}
} else if (current_path->type == TREE_NODE_GROUP) {
/* If we have deleted or defined property update group window */
if (!strcmp(current_path->device, property->device) &&
!strcmp(current_path->group, property->group)) {
indigo_debug("PROPERTY IN GROUP defined/deleted\n");
clear_window();
repaint_property_window(current_path->node);
return;
}
}
if (!strcmp(property->name,"")) {
if (current_path->type == TREE_NODE_PROPERTY) {
if (!strcmp(current_path->device, property->device)) {
indigo_debug("SELECTED DEVICE deleted (Peoperty selected)\n");
current_path->ClearSelection();
clear_window();
return;
}
} else if (current_path->type == TREE_NODE_GROUP) {
if (!strcmp(current_path->device, property->device)) {
indigo_debug("SELECTED DEVICE deleted (Group selected)\n");
current_path->ClearSelection();
clear_window();
return;
}
}
}
}
void BrowserWindow::clear_window() {
indigo_debug("CLEAR_WINDOW!\n");
mSelectionLine->setText("");
delete mScrollArea;
mScrollArea = new QScrollArea();
mScrollArea->setObjectName("PROPERTY_AREA");
mScrollArea->setWidgetResizable(true);
mScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
mScrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
mFormLayout->addWidget(mScrollArea);
mScrollArea->setMinimumWidth(600);
}
void BrowserWindow::repaint_property_window(TreeNode* node) {
char selected_str[PATH_LEN] = "";
if (node != nullptr && node->node_type == TREE_NODE_PROPERTY) {
indigo_debug( "SELECTION CHANGED current_node->node_type == TREE_NODE_PROPERTY\n");
snprintf(selected_str, PATH_LEN, "%s . %s", current_path->device, current_path->property);
mSelectionLine->setText(selected_str);
PropertyNode* p = reinterpret_cast<PropertyNode*>(node);
QIndigoProperty* ip = new QIndigoProperty(p->property);
QWidget* ppanel = new QWidget();
QVBoxLayout* playout = new QVBoxLayout;
playout->setSpacing(10);
playout->setContentsMargins(10, 10, 10, 10);
playout->setSizeConstraint(QLayout::SetMinimumSize);
ppanel->setLayout(playout);
playout->addWidget(ip);
mScrollArea->setWidget(ppanel);
ppanel->show();
// Connect to update signals coming from indigo bus
connect(mPropertyModel, &PropertyModel::property_updated, ip, &QIndigoProperty::property_update);
} else if (node != nullptr && node->node_type == TREE_NODE_GROUP) {
indigo_debug("SELECTION CHANGED node->node_type == TREE_NODE_GROUP\n");
GroupNode* g = reinterpret_cast<GroupNode*>(node);
QWidget* ppanel = new QWidget();
QVBoxLayout* playout = new QVBoxLayout;
playout->setSpacing(10);
playout->setContentsMargins(10, 10, 10, 10);
playout->setSizeConstraint(QLayout::SetMinimumSize);
ppanel->setLayout(playout);
snprintf(selected_str, PATH_LEN, "%s . %s", current_path->device, current_path->group);
mSelectionLine->setText(selected_str);
// Iterate properties
for (int i = 0; i < g->children.count; i++) {
PropertyNode* p = g->children.nodes[i];
QIndigoProperty* ip = new QIndigoProperty(p->property);
playout->addWidget(ip);
connect(mPropertyModel, &PropertyModel::property_updated, ip, &QIndigoProperty::property_update);
}
playout->addStretch(); // Fill the vertical space available
mScrollArea->setWidget(ppanel);
mScrollArea->setWidgetResizable(true);
ppanel->show();
} else if (node != nullptr && node->node_type == TREE_NODE_DEVICE) {
indigo_debug("SELECTION CHANGED node->node_type == TREE_NODE_DEVICE\n");
DeviceNode* d = reinterpret_cast<DeviceNode*>(node);
// Iterate Groups and find "Main" and select it
for (int i = 0; i < d->children.count; i++) {
GroupNode* g = d->children.nodes[i];
if (!strcmp(g->name(), "Main")) {
current_path->select(g);
repaint_property_window(current_path->node);
return;
}
}
// There is no "Main" goroup
indigo_debug("No \"Main\" group, clearing window.\n");
clear_window();
snprintf(selected_str, PATH_LEN, "%s", current_path->device);
mSelectionLine->setText(selected_str);
}
}
void BrowserWindow::on_selection_changed(const QItemSelection &selected, const QItemSelection &) {
if (mPropertyModel->no_repaint_flag) return;
indigo_debug( "SELECTION CHANGED\n");
// Deal with the outgoing selection
if (current_path->type != TREE_NODE_ROOT) {
indigo_debug("SELECTION CHANGED no current node\n");
clear_window();
}
if (selected.indexes().empty()) {
indigo_debug("SELECTION CHANGED selected.indexes().empty()\n");
current_path->select(nullptr);
clear_window();
return;
}
QModelIndex s = selected.indexes().front();
current_path->select(static_cast<TreeNode*>(s.internalPointer()));
if (current_path->node != nullptr) {
indigo_debug("SELECTION CHANGED current_node->node_type == %d\n", current_path->node->node_type);
clear_window();
}
repaint_property_window(current_path->node);
}
void BrowserWindow::on_servers_act() {
mIndigoServers->show();
}
void BrowserWindow::on_exit_act() {
QApplication::quit();
}
void BrowserWindow::on_blobs_changed(bool status) {
conf.blobs_enabled = status;
IndigoClient::instance().enable_blobs(status);
emit(enable_blobs(status));
if(status) on_window_log(NULL, "BLOBs enabled");
else on_window_log(NULL, "BLOBs disabled");
write_conf();
indigo_debug("%s\n", __FUNCTION__);
}
void BrowserWindow::on_bonjour_changed(bool status) {
conf.auto_connect = status;
mServiceModel->enable_auto_connect(conf.auto_connect);
write_conf();
indigo_debug("%s\n", __FUNCTION__);
}
void BrowserWindow::on_use_suffix_changed(bool status) {
conf.indigo_use_host_suffix = status;
write_conf();
indigo_debug("%s\n", __FUNCTION__);
}
void BrowserWindow::on_use_state_icons_changed(bool status) {
conf.use_state_icons = status;
write_conf();
mProperties->repaint();
repaint_property_window(current_path->node);
indigo_debug("%s\n", __FUNCTION__);
}
void BrowserWindow::on_use_system_locale_changed(bool status) {
conf.use_system_locale = status;
write_conf();
if (conf.use_system_locale){
on_window_log(nullptr, "Locale specific decimal separator will be used on next application start");
} else {
on_window_log(nullptr, "Dot decimal separator will be used on next application start");
}
indigo_debug("%s\n", __FUNCTION__);
}
void BrowserWindow::on_no_stretch() {
conf.preview_stretch_level = STRETCH_NONE;
preview_cache.set_stretch_level(conf.preview_stretch_level);
emit(rebuild_blob_previews());
repaint_property_window(current_path->node);
write_conf();
indigo_error("%s\n", __FUNCTION__);
}
void BrowserWindow::on_normal_stretch() {
conf.preview_stretch_level = STRETCH_NORMAL;
preview_cache.set_stretch_level(conf.preview_stretch_level);
emit(rebuild_blob_previews());
repaint_property_window(current_path->node);
write_conf();
indigo_error("%s\n", __FUNCTION__);
}
void BrowserWindow::on_hard_stretch() {
conf.preview_stretch_level = STRETCH_HARD;
preview_cache.set_stretch_level(conf.preview_stretch_level);
emit(rebuild_blob_previews());
repaint_property_window(current_path->node);
write_conf();
indigo_error("%s\n", __FUNCTION__);
}
void BrowserWindow::on_log_error() {
conf.indigo_log_level = INDIGO_LOG_ERROR;
indigo_set_log_level(conf.indigo_log_level);
write_conf();
indigo_error("%s\n", __FUNCTION__);
}
void BrowserWindow::on_log_info() {
indigo_debug("%s\n", __FUNCTION__);
conf.indigo_log_level = INDIGO_LOG_INFO;
indigo_set_log_level(conf.indigo_log_level);
write_conf();
}
void BrowserWindow::on_log_debug() {
indigo_debug("%s\n", __FUNCTION__);
conf.indigo_log_level = INDIGO_LOG_DEBUG;
indigo_set_log_level(conf.indigo_log_level);
write_conf();
}
void BrowserWindow::on_log_trace() {
indigo_debug("%s\n", __FUNCTION__);
conf.indigo_log_level = INDIGO_LOG_TRACE;
indigo_set_log_level(conf.indigo_log_level);
write_conf();
}
void BrowserWindow::on_acl_load_act() {
QString filter = "INDIGO Device Access Control (*.idac);; All files (*)";
QString file_name = QFileDialog::getOpenFileName(this, "Load Device ACL...", QDir::currentPath(), filter);
if (!file_name.isNull()) {
char fname[PATH_MAX];
strcpy(fname, file_name.toStdString().c_str());
char message[PATH_MAX];
indigo_clear_device_tokens();
if (indigo_load_device_tokens_from_file(fname)) {
snprintf(message, PATH_MAX, "Current device ACL cleared, new device ACL loaded from '%s'", fname);
} else {
snprintf(message, PATH_MAX, "Current device ACL cleared but failed to load device ACL from '%s'", fname);
}
on_window_log(NULL, message);
}
indigo_debug("%s\n", __FUNCTION__);
}
void BrowserWindow::on_acl_append_act() {
QString filter = "INDIGO Device Access Control (*.idac);; All files (*)";
QString file_name = QFileDialog::getOpenFileName(this, "Append to device ACL...", QDir::currentPath(), filter);
if (!file_name.isNull()) {
char fname[PATH_MAX];
strcpy(fname, file_name.toStdString().c_str());
char message[PATH_MAX];
if (indigo_load_device_tokens_from_file(fname)) {
snprintf(message, PATH_MAX, "Appended to device ACL from '%s'", fname);
} else {
snprintf(message, PATH_MAX, "Failed to append to device ACL form '%s'", fname);
}
on_window_log(NULL, message);
}
indigo_debug("%s\n", __FUNCTION__);
}
void BrowserWindow::on_acl_save_act() {
QString filter = "INDIGO Device Access Control (*.idac);; All files (*)";
QString file_name = QFileDialog::getSaveFileName(this, "Save device ACL As...", QDir::currentPath(), filter);
if (!file_name.isNull()) {
char fname[PATH_MAX];
strcpy(fname, file_name.toStdString().c_str());
char message[PATH_MAX];
if (indigo_save_device_tokens_to_file(fname)) {
snprintf(message, PATH_MAX, "Device ACL saved as '%s'", fname);
} else {
snprintf(message, PATH_MAX, "Failed to save device ACL as '%s'", fname);
}
on_window_log(NULL, message);
}
indigo_debug("%s\n", __FUNCTION__);
}
void BrowserWindow::on_acl_clear_act() {
indigo_clear_device_tokens();
on_window_log(NULL, "Device ACL cleared");
indigo_debug("%s\n", __FUNCTION__);
}
void BrowserWindow::on_about_act() {
int major, minor, build;
indigo_get_version(&major, &minor, &build);
char indigo_version[50];
sprintf(indigo_version, "%d.%d-%3d", major, minor, build);
QMessageBox msgBox(this);
int platform_bits = sizeof(void*) * 8;
QPixmap pixmap(":resource/indigo_logo.png");
msgBox.setWindowTitle("About INDIGO Panel");
msgBox.setTextFormat(Qt::RichText);
msgBox.setIconPixmap(pixmap.scaledToWidth(96, Qt::SmoothTransformation));
msgBox.setText(
"<b>INDIGO Control Panel</b><br>"
"Version "
PANEL_VERSION
" (" + QString::number(platform_bits) + "bit) <br>"
"<br>INDIGO framework version " + QString(indigo_version) + "<br>"
"<br>"
"Authors:<br>"
"Rumen G.Bogdanovski<br>"
"David Hulse<br><br>"
"You can use this software under the terms of <b>INDIGO Astronomy open-source license</b><br><br>"
"Copyright ©2019-" + YEAR_NOW + ", The INDIGO Initiative.<br>"
"<a href='http://www.indigo-astronomy.org'>http://www.indigo-astronomy.org</a>"
);
msgBox.exec();
indigo_debug("%s\n", __FUNCTION__);
}