-
Notifications
You must be signed in to change notification settings - Fork 37
/
controlbox.cpp
executable file
·3387 lines (2944 loc) · 147 KB
/
controlbox.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
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**************************** controlbox.cpp ***************************
Code to manage the primary user interface to include the QDialog the
user interfaces with and the system tray icon.
Copyright (C) 2013-2023
by: Andrew J. Bibb
License: MIT
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"),to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
***********************************************************************/
/**********************************************************************
* NOTE TO PEOPLE HACKING ON THE CODE
*
* Prior to 2015.11.12 text returned by connman was translated and then
* stored in the various maps. After that date the code was revised so
* that text is stored in the maps exactly as connman returns it and
* is then translated when it needs to be displayed.
*
***********************************************************************/
# include <QDBusArgument>
# include <QTableWidget>
# include <QTableWidgetItem>
# include <QFileInfo>
# include <QFile>
# include <QWhatsThis>
# include <QMenu>
# include <QPixmap>
# include <QMessageBox>
# include <QCloseEvent>
# include <QKeyEvent>
# include <QToolTip>
# include <QTableWidgetSelectionRange>
# include <QProcess>
# include <QProcessEnvironment>
# include <QLocale>
# include <QColorDialog>
# include <QPainter>
# include <QImage>
# if QT_VERSION < 0x060000
# include <QDesktopWidget>
# endif
# include <QInputDialog>
# include <QDateTime>
# include "../resource.h"
# include "./controlbox.h"
# include "./code/scrollbox/scrollbox.h"
# include "./code/peditor/peditor.h"
# include "./code/provisioning/prov_ed.h"
# include "./code/vpn_prov_ed/vpn_ed.h"
# include "./code/vpn_create/vpn_create.h"
# include "./code/trstring/tr_strings.h"
# include "./code/shared/shared.h"
// headers for system logging
# include <stdio.h>
# include <unistd.h>
# include <syslog.h>
# define DBUS_PATH "/"
# define DBUS_CON_SERVICE "net.connman"
# define DBUS_VPN_SERVICE "net.connman.vpn"
# define DBUS_CON_MANAGER "net.connman.Manager"
# define DBUS_VPN_MANAGER "net.connman.vpn.Manager"
# define VPN_PATH "/var/lib/connman-vpn"
// Custom push button, used in the technology box for powered on/off
// This is really a single use button, after it is clicked all idButtons
// are deleted and recreated. Once is is clicked disable the button.
idButton::idButton(QWidget* parent, const QDBusObjectPath& id) :
QFrame(parent)
{
// margins
const int m_left = 5;
const int m_top = 0;
const int m_right = 5;
const int m_bottom = 0;
// create the button
button = new QToolButton(this);
button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
obj_id = id;
button->setCheckable(true);
button->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
connect (button, SIGNAL(clicked(bool)), this, SLOT(buttonClicked(bool)));
// create the box
QHBoxLayout* layout = new QHBoxLayout(this);
layout->setContentsMargins(m_left, m_top, m_right, m_bottom);
layout->setAlignment(Qt::AlignCenter);
layout->addWidget(button, 0);
return;
}
void idButton::buttonClicked(bool checked)
{
this->setDisabled(true);
emit clickedID (obj_id.path(), checked);
return;
}
// main GUI element
ControlBox::ControlBox(const QCommandLineParser& parser, QWidget *parent)
: QDialog(parent)
{
// set the Locale (probably not necessary since the default is the system one anyway)
QLocale::setDefault(QLocale::system() );
// setup the user interface
ui.setupUi(this);
// set the window title
setWindowTitle(TranslateStrings::cmtr("connman system tray"));
// data members
q16_errors = CMST::No_Errors;
properties_map.clear();
services_list.clear();
technologies_list.clear();
wifi_list.clear();
peer_list.clear();
vpn_list.clear();
agent = new ConnmanAgent(this);
vpnagent = new ConnmanVPNAgent(this);
counter = new ConnmanCounter(this);
trayiconmenu = new QMenu(this);
tech_submenu = new QMenu(tr("Technologies"), this);
info_submenu = new QMenu(tr("Service Details"), this);
wifi_submenu = new QMenu(tr("WiFi Connections"), this);
vpn_submenu = new QMenu(tr("VPN Connections"), this);
mvsrv_menu = new QMenu(this);
settings = new QSettings(ORG, APP, this);
notifyclient = NULL;
onlineobjectpath.clear();
pendingobjectpath.clear();
socketserver = new QLocalServer(this);
socketserver->removeServer(SOCKET_NAME); // remove any files that may have been left after a crash
socketserver->listen(SOCKET_NAME);
trayiconbackground = QColor();
trayicon = new QSystemTrayIcon(this);
f_connmanversion = 0.0;
gened = NULL;
proc = NULL;
iconman = new IconManager(this);
b_userinitiated = false;
iconscale = 1.0;
// set a stylesheet on the tab widget - used to hide disabled tabs
QFile f0(":/stylesheets/stylesheets/tabwidget.qss");
if (f0.open(QIODevice::ReadOnly | QIODevice::Text)) {
QString qss = QString(f0.readAll());
f0.close();
ui.tabWidget->setStyleSheet(qss);
}
// set a stylesheet on the offlinemode toolbutton. Until 2017.12 this
// was a label to display a pixmap. It is now a QToolButton, but I want the
// picture to show the current state (transmitting or airplane), not the
// state that will happen if you push the button, for instance typical
// play/pause behavior in a media player. If I advertise this is a button
// I'll get complaints that the pictures are backwards, so hide that fact
// by making it look like a label with the stylesheet.
QFile f1(":/stylesheets/stylesheets/airplane.qss");
if (f1.open(QIODevice::ReadOnly | QIODevice::Text)) {
QString qss = QString(f1.readAll());
f1.close();
ui.toolButton_offlinemode->setStyleSheet(qss);
}
ui.toolButton_offlinemode->setIconSize(ui.toolButton_offlinemode->icon().actualSize(QSize(16,16) *= iconscale) );
// Read saved settings which will set the ui controls in the preferences tab.
this->readSettings();
// Set the iconmanager color
iconman->setIconColor(QColor(ui.lineEdit_colorize->text()) );
// Constructor scope bool, set to true if we are using start options
bool b_so = (! parser.isSet("bypass-start-options") && ui.checkBox_usestartoptions->isChecked() );
// Enable or disable preferences group box (changed via ui signal/slot after the constructor)
ui.groupBox_startoptions->setEnabled(ui.checkBox_usestartoptions->isChecked());
// Restore window if retain_state is checked and we have not bypassed it on the command line
if (! parser.isSet("bypass-restore-state") && settings->value("CheckBoxes/retain_state").toBool() ) {
settings->beginGroup("MainWindow");
resize(settings->value("size", QSize(700, 550)).toSize() );
move(settings->value("pos", QPoint(200, 200)).toPoint() );
ui.splitter01->restoreState(settings->value("splitter_01").toByteArray() );
ui.tabWidget->setCurrentIndex(settings->value("current_page").toInt() );
settings->endGroup();
}
// Make sure the controlbox will fit onto small screens (& resize to sizeHint() for HiDPI screens)
# if QT_VERSION < 0x060000
QSize sz_target = (qApp->desktop()->availableGeometry(this)).size();
# else
QSize sz_target = qApp->primaryScreen()->availableGeometry().size();
# endif
QSize sz_source = this->sizeHint();
if (sz_source.width() > sz_target.width() || sz_source.height() > sz_target.height() ) {
sz_source.scale(sz_target.width() - 100, sz_target.height() - 100, Qt::KeepAspectRatio); // keep min. 100 pixels around dialog
resize(sz_source);
move((sz_target.width() - this->width()) / 2, (sz_target.height() - this->height()) / 2); // re-center if needed
}
// set a flag if we sent a commandline option to log the connman inputrequest
agent->setLogInputRequest(parser.isSet("log-input-request"));
vpnagent->setLogInputRequest(parser.isSet("log-input-request"));
QDir d(IPT_REQ_LOG_PATH);
d.mkpath(IPT_REQ_LOG_PATH);
if (d.exists(IPT_REQ_LOG_FILE)) d.remove(IPT_REQ_LOG_FILE);
// Set icon theme if provided on the command line or in the settings
if (parser.isSet("icon-theme") ) {
if (parser.value("icon-theme").isEmpty() ) {
if (QIcon::themeName() == "hicolor") QIcon::setThemeName(INTERNAL_THEME);
} // if
else QIcon::setThemeName(parser.value("icon-theme") );
} // if parser is set
else {
if (b_so && ui.checkBox_systemicontheme->isChecked() ) {
if (ui.comboBox_icontheme->currentText().isEmpty() ) {
if (QIcon::themeName() == "hicolor") QIcon::setThemeName(INTERNAL_THEME);
} // if
else QIcon::setThemeName(ui.comboBox_icontheme->currentText() );
} // if
else QIcon::setThemeName(INTERNAL_THEME);
} // else parser not set
// Set icon scale if provided on the command line or in the settings
// Min and Max limits are defined in the UI
if (parser.isSet("icon-scale") ) {
bool ok;
iconscale = parser.value("icon-scale").toFloat(&ok);
if (! ok) iconscale = 1.0;
if (iconscale < ui.doubleSpinBox_iconscale->minimum()) iconscale = ui.doubleSpinBox_iconscale->minimum();
if (iconscale > ui.doubleSpinBox_iconscale->maximum()) iconscale = ui.doubleSpinBox_iconscale->maximum();
} // parser is set
else if (b_so && ui.checkBox_iconscale->isChecked() ) {
iconscale = ui.doubleSpinBox_iconscale->value();
}
// Set the window icon. If an icon was installed to /usr/share/icons/hicolor/48x48/apps
// use that, otherwise use a freedesktop.org named one
if (QFile::exists("/usr/share/icons/hicolor/48x48/apps/cmst.png") )
this->setWindowIcon(QIcon("/usr/share/icons/hicolor/48x48/apps/cmst.png") );
else
this->setWindowIcon(QIcon::fromTheme("preferences-system-network") );
// Set the whatsthis icons and scale
ui.toolButton_whatsthis->setIcon(iconman->getIcon("whats_this"));
agent->setWhatsThisIcon(iconman->getIcon("whats_this"));
vpnagent->setWhatsThisIcon(iconman->getIcon("whats_this"));
ui.toolButton_whatsthis->setIconSize(ui.toolButton_whatsthis->icon().actualSize(QSize(16,16) *= iconscale) );
agent->setIconSize(iconscale);
vpnagent->setIconSize(iconscale);
// Fake transparency
if (parser.isSet("fake-transparency") ) {
bool ok;
trayiconbackground = QColor(parser.value("fake-transparency").toUInt(&ok, 16) );
if (! ok) trayiconbackground = QColor();
} // if parser set
else
if (b_so && ui.checkBox_faketransparency->isChecked() ) {
trayiconbackground = QColor(ui.lineEdit_faketransparency->text() );
} // if
else trayiconbackground = QColor();
// set counter update params from command line options if available otherwise
// default params specified in main.cpp are used. Set a minimum value for
// each to maintain program response.
uint minval = ui.spinBox_counterkb->minimum();
uint setval = 0;
if (parser.isSet("counter-update-kb") ) {
bool ok;
setval = parser.value("counter-update-kb").toUInt(&ok, 10);
if (! ok) setval = minval;
} // if parser set
else if (b_so && ui.checkBox_counterkb->isChecked() ) {
setval = ui.spinBox_counterkb->value();
} // else if
counter_accuracy = setval > minval ? setval : minval; // number of kb for counter updates
minval = ui.spinBox_counterrate->minimum();
setval = 0;
if (parser.isSet("counter-update-rate") ) {
bool ok;
setval = parser.value("counter-update-rate").toUInt(&ok, 10);
if (! ok) setval = minval;
} // if parser set
else if (b_so && ui.checkBox_counterseconds->isChecked() ) {
setval = ui.spinBox_counterrate->value();
}
counter_period = setval > minval ? setval : minval; // number of seconds for counter updates
// Hide the minimize button requested
if (parser.isSet("disable-minimize") ? true : (b_so && ui.checkBox_disableminimized->isChecked()) )
ui.pushButton_minimize->hide();
// operate on settings not dealt with elsewhere
ui.pushButton_provisioning_editor->setVisible(ui.checkBox_advanced->isChecked() );
ui.pushButton_vpn_editor->setVisible(ui.checkBox_advanced->isChecked() );
ui.groupBox_process->setVisible(ui.checkBox_advanced->isChecked() );
enableRunOnStartup(ui.checkBox_runonstartup->isChecked() );
// Create the notifyclient.
notifyclient = new NotifyClient(this);
// Try to connect to the notify client. Make four tries; first immediately, then
// at 1/2 second, 2 seconds and finally at 8 seconds. This only makes the connection
// the decision to use it or not is made in the function
this->connectNotifyClient();
QTimer::singleShot(500, this, SLOT(connectNotifyClient()));
QTimer::singleShot(2 * 1000, this, SLOT(connectNotifyClient()));
QTimer::singleShot(8 * 1000, this, SLOT(connectNotifyClient()));
// setup the dbus interface to connman.manager
con_manager = NULL;
vpn_manager = NULL;
if (! QDBusConnection::systemBus().isConnected() ) logErrors(CMST::Err_No_DBus);
else {
con_manager = new QDBusInterface(DBUS_CON_SERVICE, DBUS_PATH, DBUS_CON_MANAGER, QDBusConnection::systemBus(), this);
if (! con_manager->isValid() ) logErrors(CMST::Err_Invalid_Con_Iface);
else {
// Access connman.manager to retrieve the data
// Reset the getXX errors
q16_errors &= ~CMST::Err_Properties;
q16_errors &= ~CMST::Err_Technologies;
q16_errors &= ~CMST::Err_Services;
if (! getTechnologies() ) logErrors(CMST::Err_Technologies);
else {
// connect technology signals to slots
for (int i = 0; i < technologies_list.size(); ++i) {
QDBusConnection::systemBus().connect(DBUS_CON_SERVICE, technologies_list.at(i).objpath.path(), "net.connman.Technology", "PropertyChanged", this, SLOT(dbsTechnologyPropertyChanged(QString, QDBusVariant, QDBusMessage)));
} // for
} //else
if (! getServices() ) logErrors(CMST::Err_Services);
else {
// connect service signals to slots
for (int i = 0; i < services_list.size(); ++i) {
QDBusConnection::systemBus().connect(DBUS_CON_SERVICE, services_list.at(i).objpath.path(), "net.connman.Service", "PropertyChanged", this, SLOT(dbsServicePropertyChanged(QString, QDBusVariant, QDBusMessage)));
} // for
} // else
if (! getProperties() ) logErrors(CMST::Err_Properties);
// register the agent
shared::processReply(con_manager->call(QDBus::AutoDetect, "RegisterAgent", QVariant::fromValue(QDBusObjectPath(AGENT_OBJECT))) );
// if counters are enabled connect signal to slot and register the counter
if (parser.isSet("enable-counters") ? true : (b_so && ui.checkBox_enablecounters->isChecked()) ) {
QList<QVariant> vlist_counter;
vlist_counter.clear();
vlist_counter << QVariant::fromValue(QDBusObjectPath(CNTR_OBJECT)) << counter_accuracy << counter_period;
QDBusMessage reply = con_manager->callWithArgumentList(QDBus::AutoDetect, "RegisterCounter", vlist_counter);
if (shared::processReply(reply) == QDBusMessage::ReplyMessage)
connect(counter, SIGNAL(usageUpdated(QDBusObjectPath, QString, QString)), this, SLOT(counterUpdated(QDBusObjectPath, QString, QString)));
} // enable counters
else {
ui.tabWidget->setTabEnabled(ui.tabWidget->indexOf(ui.Counters), false);
}
// connect some dbus signals to our slots
QDBusConnection::systemBus().connect(DBUS_CON_SERVICE, DBUS_PATH, DBUS_CON_MANAGER, "PropertyChanged", this, SLOT(dbsPropertyChanged(QString, QDBusVariant)));
QDBusConnection::systemBus().connect(DBUS_CON_SERVICE, DBUS_PATH, DBUS_CON_MANAGER, "ServicesChanged", this, SLOT(dbsServicesChanged(QList<QVariant>, QList<QDBusObjectPath>, QDBusMessage)));
QDBusConnection::systemBus().connect(DBUS_CON_SERVICE, DBUS_PATH, DBUS_CON_MANAGER, "PeersChanged", this, SLOT(dbsPeersChanged(QList<QVariant>, QList<QDBusObjectPath>, QDBusMessage)));
QDBusConnection::systemBus().connect(DBUS_CON_SERVICE, DBUS_PATH, DBUS_CON_MANAGER, "TechnologyAdded", this, SLOT(dbsTechnologyAdded(QDBusObjectPath, QVariantMap)));
QDBusConnection::systemBus().connect(DBUS_CON_SERVICE, DBUS_PATH, DBUS_CON_MANAGER, "TechnologyRemoved", this, SLOT(dbsTechnologyRemoved(QDBusObjectPath)));
// clear the counters if selected
this->clearCounters();
// find the connman version we are running
findConnmanVersion();
// VPN manager. Disable vpn options if commandline or option is set
if (parser.isSet("disable-vpn") ? true : (b_so && ui.checkBox_disablevpn->isChecked()) ) {
ui.tabWidget->setTabEnabled(ui.tabWidget->indexOf(ui.VPN), false);
ui.pushButton_vpn_editor->setDisabled(true);
ui.checkBox_killswitch->setDisabled(true);
} // if parser set
else {
vpn_manager = new QDBusInterface(DBUS_VPN_SERVICE, DBUS_PATH, DBUS_VPN_MANAGER, QDBusConnection::systemBus(), this);
if (! vpn_manager->isValid() ) {
ui.tabWidget->setTabEnabled(ui.tabWidget->indexOf(ui.VPN), false);
ui.pushButton_vpn_editor->setDisabled(true);
ui.checkBox_killswitch->setDisabled(true);
logErrors(CMST::Err_Invalid_VPN_Iface);
}
else {
ui.tabWidget->setTabEnabled(ui.tabWidget->indexOf(ui.VPN), true);
ui.pushButton_vpn_editor->setEnabled(true);
ui.checkBox_killswitch->setEnabled(true);
shared::processReply(vpn_manager->call(QDBus::AutoDetect, "RegisterAgent", QVariant::fromValue(QDBusObjectPath(VPN_AGENT_OBJECT))) );
} // else enable vpn widgets, register agent, connect signals
} // else vpn_manager is valid
} // else have valid connection
} // else have connected systemBus
// add actions to groups
minMaxGroup = new QActionGroup(this);
minimizeAction = new QAction(tr("Mi&nimize"), this);
maximizeAction = new QAction(tr("Ma&ximize"), this);
minMaxGroup->addAction(minimizeAction);
minMaxGroup->addAction(maximizeAction);
exitAction = new QAction(tr("&Exit"), this);
moveGroup = new QActionGroup(this);
moveGroup->addAction(ui.actionMove_Before);
moveGroup->addAction(ui.actionMove_After);
colorGroup = new QActionGroup(this);
colorizeAction = new QAction(iconman->getIcon("caret-up"), tr("&Colorize"), this);
colorGroup->addAction(colorizeAction);
ui.lineEdit_colorize->addAction(colorizeAction, QLineEdit::TrailingPosition);
faketranspAction = new QAction(iconman->getIcon("caret-up"), tr("&Transparency"), this);
colorGroup->addAction(faketranspAction);
ui.lineEdit_faketransparency->addAction(faketranspAction, QLineEdit::TrailingPosition);
// connect signals and slots - actions and action groups
connect(minMaxGroup, SIGNAL(triggered(QAction*)), this, SLOT(minMaxWindow(QAction*)));
connect(tech_submenu, SIGNAL(triggered(QAction*)), this, SLOT(techSubmenuTriggered(QAction*)));
connect(info_submenu, SIGNAL(triggered(QAction*)), this, SLOT(infoSubmenuTriggered(QAction*)));
connect(wifi_submenu, SIGNAL(triggered(QAction*)), this, SLOT(wifiSubmenuTriggered(QAction*)));
connect(vpn_submenu, SIGNAL(triggered(QAction*)), this, SLOT(vpnSubmenuTriggered(QAction*)));
connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
connect(moveGroup, SIGNAL(triggered(QAction*)), this, SLOT(moveButtonPressed(QAction*)));
connect(mvsrv_menu, SIGNAL(triggered(QAction*)), this, SLOT(moveService(QAction*)));
connect(ui.actionRescan, SIGNAL (triggered()), this, SLOT(scanWiFi()));
connect(ui.actionIDPass, SIGNAL (triggered()), this, SLOT(wifiIDPass()));
connect(ui.actionOffline_Mode, SIGNAL(toggled(bool)), this, SLOT(toggleOfflineMode(bool)));
connect(colorGroup, SIGNAL(triggered(QAction*)), this, SLOT(callColorDialog(QAction*)));
// connect signals and slots - ui elements
connect(ui.toolButton_whatsthis, SIGNAL(clicked()), this, SLOT(showWhatsThis()));
connect(ui.comboBox_service, SIGNAL(currentIndexChanged(int)), this, SLOT(getServiceDetails(int)));
connect(ui.pushButton_exit, SIGNAL(clicked()), exitAction, SLOT(trigger()));
connect(ui.pushButton_minimize, SIGNAL(clicked()), minimizeAction, SLOT(trigger()));
connect(ui.pushButton_connect, SIGNAL(clicked()), this, SLOT(connectPressed()));
connect(ui.pushButton_vpn_connect, SIGNAL(clicked()), this, SLOT(connectPressed()));
connect(ui.pushButton_disconnect, SIGNAL(clicked()), this, SLOT(disconnectPressed()));
connect(ui.pushButton_vpn_disconnect, SIGNAL(clicked()), this, SLOT(disconnectPressed()));
connect(ui.pushButton_remove, SIGNAL(clicked()), this, SLOT(removePressed()));
connect(ui.pushButton_createvpn, SIGNAL(clicked()), this, SLOT(createVPN()));
connect(ui.pushButton_removevpn, SIGNAL(clicked()), this, SLOT(removeVPN()));
connect(ui.pushButton_edit, SIGNAL(clicked()), this, SLOT(editPressed()));
connect(ui.pushButton_aboutCMST, SIGNAL(clicked()), this, SLOT(aboutCMST()));
connect(ui.pushButton_aboutIconSet, SIGNAL(clicked()), this, SLOT(aboutIconSet()));
connect(ui.pushButton_aboutOtherArt, SIGNAL(clicked()), this, SLOT(aboutOtherArt()));
connect(ui.pushButton_aboutQT, SIGNAL(clicked()), qApp, SLOT(aboutQt()));
connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(cleanUp()));
connect(ui.pushButton_license, SIGNAL(clicked()), this, SLOT(showLicense()));
connect(ui.pushButton_change_log, SIGNAL(clicked()), this, SLOT(showChangeLog()));
connect(ui.tableWidget_services, SIGNAL (cellClicked(int, int)), this, SLOT(enableMoveButtons(int, int)));
connect(ui.checkBox_hidecnxn, SIGNAL (toggled(bool)), this, SLOT(updateDisplayWidgets()));
connect(ui.checkBox_hidetethering, SIGNAL (toggled(bool)), this, SLOT(updateDisplayWidgets()));
connect(ui.checkBox_systemtraynotifications, SIGNAL (clicked(bool)), this, SLOT(trayNotifications(bool)));
connect(ui.checkBox_notifydaemon, SIGNAL (clicked(bool)), this, SLOT(daemonNotifications(bool)));
connect(ui.checkBox_hideIconFull, SIGNAL(clicked(bool)), this, SLOT(iconFullHide(bool)));
connect(ui.checkBox_hideIconAuto, SIGNAL(clicked(bool)), this, SLOT(iconPartialHide(bool)));
connect(ui.pushButton_configuration, SIGNAL (clicked()), this, SLOT(configureService()));
connect(ui.pushButton_provisioning_editor, SIGNAL (clicked()), this, SLOT(provisionService()));
connect(ui.pushButton_vpn_editor, SIGNAL (clicked()), this, SLOT(provisionService()));
connect(socketserver, SIGNAL(newConnection()), this, SLOT(socketConnectionDetected()));
connect(ui.checkBox_runonstartup, SIGNAL(toggled(bool)), this, SLOT(enableRunOnStartup(bool)));
connect(ui.lineEdit_colorize, SIGNAL(textChanged(const QString&)), this, SLOT(iconColorChanged(const QString&)));
connect(ui.checkBox_enablesystemtraytooltips, SIGNAL(clicked()), this, SLOT(updateDisplayWidgets()));
connect(ui.pushButton_IDPass, SIGNAL(clicked()), this, SLOT(wifiIDPass()));
// Install an event filter on all child widgets. Used to control
// tooltip visibility
QList<QWidget*> childlist = ui.tabWidget->findChildren<QWidget*>();
for (int i = 0; i < childlist.count(); ++i) {
childlist.at(i)->installEventFilter(this);
}
// Tray icon - disable it if we specifiy that option on the commandline or in
// the settings, otherwise set a singleshot timer to create the tray icon.
if (parser.isSet("disable-tray-icon") ? true : (b_so && ui.checkBox_disabletrayicon->isChecked()) ) {
trayicon = NULL;
ui.checkBox_hideIconFull->setDisabled(true);
ui.checkBox_hideIconAuto->setDisabled(true);
this->updateDisplayWidgets();
qApp->setQuitOnLastWindowClosed(true); // not running systemtray icon so normal close
this->showNormal(); // no place to minimize to, so showMaximized
} // if
else {
const short mintrigger = 100; // Minimum time (milliseconds) to wait before starting the tray icon. We advertise zero, but not really.
int timeout = 0;
if (parser.isSet("wait-time") ) {
bool ok; timeout = parser.value("wait-time").toInt(&ok, 10);
if (! ok) timeout = 0;
} // if parser set
else if (b_so && ui.checkBox_waittime->isChecked() ) {
timeout = ui.spinBox_waittime->value();
}
timeout *= 1000;
if (timeout < mintrigger) timeout = mintrigger;
if (parser.isSet("minimized") ? true : (b_so && ui.checkBox_startminimized->isChecked()) ) {
QTimer::singleShot(timeout, this, SLOT(createSystemTrayIcon()) );
} // if showMinimized
else {
this->showNormal();
QTimer::singleShot(timeout, this, SLOT(createSystemTrayIcon()) );
} // else showNormal
} // else
}
////////////////////////////////////////////////// Public Functions //////////////////////////////////
////////////////////////////////////////////////// Public Slots //////////////////////////////////////
//
// slot to display an about box for this program
void ControlBox::aboutCMST()
{
QMessageBox::about(this, tr("About %1").arg(TranslateStrings::cmtr("cmst")),
tr("<center>%1 is a program to interface with the Connman daemon and to provide a system tray control."
"<br><center>Version <b>%2</b>"
"<center>Release date: %3"
"<center>Copyright c %4<center>by"
"<center>Andrew J. Bibb"
"<center>Vermont, USA"
"<br><center><b>Translations:</b>"
"<center>Jianfeng Zhang (Chinese)"
"<center>sqozz (German)"
"<center>Ilya Shestopalov (Russian)"
"<center>Heimen Stoffels (Dutch)"
"<center> Yaşar Çiv (Turkish)"
"<br><center><b>Build Information:</b>"
"<center>Compiled using QT version %5"
"<center>Connman version %6")
.arg(TranslateStrings::cmtr("cmst"))
.arg(VERSION)
.arg(RELEASE_DATE)
.arg(COPYRIGHT_DATE)
.arg(QT_VERSION_STR)
.arg(f_connmanversion, 0,'f', 2) );
}
//
// slot to display an about box for the icons we used
void ControlBox::aboutIconSet()
{
QMessageBox::about(this, tr("About AwOken"),
tr("<center>This program uses the <b>AwOken</b> icon set version 2.5"
"<br><br>Released under the"
"<br>Creative Commons"
"<br>Attribution-Share Alike 3.0"
"<br>Unported License"
"<br><a href=\"url\">http://creativecommons.org/licenses/by-sa/3.0/legalcode</a>"
) );
}
//
// slot to display an about box for the icons we used
void ControlBox::aboutOtherArt()
{
QMessageBox::about(this, tr("About Other Artwork"),
tr("<center>This program uses artwork from <b>Freepik</b> obtained from www.flaticon.com:"
"<br><br>Released under the Flaticon Basic License"
"<br><br><b>Artwork files:</b>"
"<li>radio.png</li>"
"<li>basic-plane.png</li>"
) );
}
//
// slot to display the program license
void ControlBox::showLicense()
{
QString s = readResourceText(":/text/text/license.txt");
if ( s.isEmpty() ) s.append(tr("%1 license is the MIT (Expat) license.").arg(TranslateStrings::cmtr("cmst")));
QMessageBox::about(this, tr("License"), s);
}
//
// slot to display the change log of the program
void ControlBox::showChangeLog()
{
QString s = readResourceText(":/text/text/changelog.txt");
if ( s.isEmpty() ) s.append(tr("%1 change log is not available.").arg(TranslateStrings::cmtr("cmst")));
ScrollBox::execScrollBox(tr("ChangeLog"), s, this);
}
////////////////////////////////////////////Private Slots ////////////////////////////////////////////
//
// Slot to update all of our display widgets
void ControlBox::updateDisplayWidgets()
{
// each assemble function will check q16_errors to make sure it can
// get the information it needs. Only check for major errors since we
// can't run the assemble functions if there are.
if ( ((q16_errors & CMST::Err_No_DBus) | (q16_errors & CMST::Err_Invalid_Con_Iface)) == 0x00 ) {
// rebuild our pages if the UI is visible and not minimized
if (this->isVisible() && ! this->isMinimized() ) {
this->assembleTabStatus();
this->assembleTabDetails();
this->assembleTabWireless();
this->assembleTabVPN();
this->assembleTabCounters();
this->assembleTabPreferences();
} // if visible
if (trayicon != NULL ) {
this->assembleTrayIcon();
bool b_dtaware = qApp->desktopSettingsAware();
qApp->setDesktopSettingsAware(false);
if (QSystemTrayIcon::isSystemTrayAvailable() ) {
ui.checkBox_hideIconFull->setEnabled(true);
ui.checkBox_hideIconAuto->setEnabled(true);
if (ui.checkBox_hideIconFull->isChecked() )
trayicon->setVisible(false);
else {
if (ui.checkBox_hideIconAuto->isChecked() && ((properties_map.value("State").toString() == "online") || (properties_map.value("State").toString() == "ready")) )
trayicon->setVisible(false);
else
trayicon->setVisible(true);
} //
} // if systemTrayAvailable
else {
ui.checkBox_hideIconFull->setDisabled(true);
ui.checkBox_hideIconAuto->setDisabled(true);
trayicon->setVisible(true); // visible needs to be true in case a tray becomes available later
} // else no systemTrayAvailable
qApp->setDesktopSettingsAware(b_dtaware);
} // if trayicon not NULL
ui.pushButton_movebefore->setEnabled(false);
ui.pushButton_moveafter->setEnabled(false);
} // if there were no major errors
return;
}
//
// Slot to move the selected service before or after another service.
// Called when an item in mvsrv_menu is selected. QAction act is the
// action selected.
void ControlBox::moveService(QAction* act)
{
// See if act belongs to a service
QString ss;
QDBusObjectPath targetobj;
for (int i = 0; i < services_list.size(); ++i) {
ss = getNickName(services_list.at(i).objpath);
// the items in mvsrv_menu are in the same order as services_list
if (ss == act->text() ) {
targetobj = QDBusObjectPath(services_list.at(i).objpath.path());
break;
} // if
} // for
// make sure we got a targetobject, if not most likely cancel pressed
if (targetobj.path().isEmpty()) return;
// get enough information from tableWidget_services to identify the source object
QList<QTableWidgetItem*> list;
list.clear();
list = ui.tableWidget_services->selectedItems();
if (list.isEmpty() ) return;
// set user initiated flag (for vpn kill switch)
b_userinitiated = true;
// apply the movebefore or moveafter message to the source object
QDBusInterface* iface_serv = new QDBusInterface(DBUS_CON_SERVICE, services_list.at(list.at(0)->row()).objpath.path(), "net.connman.Service", QDBusConnection::systemBus(), this);
if (iface_serv->isValid() ) {
if (mvsrv_menu->title() == ui.actionMove_Before->text()) {
shared::processReply(iface_serv->call(QDBus::AutoDetect, "MoveBefore", QVariant::fromValue(targetobj)) );
}
else {
shared::processReply(iface_serv->call(QDBus::AutoDetect, "MoveAfter", QVariant::fromValue(targetobj)) );
} // else
} // iface_srv is valid
// clean up
iface_serv->deleteLater();
return;
}
//
// Slot called if the movebefore or moveafter button was pressed
void ControlBox::moveButtonPressed(QAction* act)
{
mvsrv_menu->setTitle(act->text());
mvsrv_menu->popup(QCursor::pos());
return;
}
//
// Slot to enable the movebefore and moveafter buttons, and to prepare the poupup menu
// Called when a cell is clicked in ui.tableWidget_services
void ControlBox::enableMoveButtons(int row, int col)
{
(void)col;
// variables
bool b_validsource = false;
bool b_validtarget = false;
// create the menu to show if a user selects one of the buttons
mvsrv_menu->clear();
for (int i = 0; i < services_list.size(); ++i) {
QAction* act = mvsrv_menu->addAction(getNickName(services_list.at(i).objpath) );
// inspect the service, can only move if service is favorite, ready or online
// vpn services can be moved (I was wrong thinking they could not), see https://01.org/jira/browse/CM-620
// 2021.05.08 - on further consideration moving vpn services is not a good idea, disable the ability to do so
if (services_list.at(i).objmap.value("Favorite").toBool() &&
(services_list.at(i).objmap.value("Type").toString() != "vpn") &&
(services_list.at(i).objmap.value("State").toString() == "online" || services_list.at(i).objmap.value("State").toString() == "ready") ) {
if (i == row) {
act->setDisabled(true); // can't move onto itself
b_validsource = true;
}
else {
act->setEnabled(true);
b_validtarget = true;
} // else
} // if
else
act->setDisabled(true);
} // for loop
// add a cancel option
mvsrv_menu->addSeparator();
mvsrv_menu->addAction(tr("Cancel"));
// enable the buttons if source and target both valid
ui.pushButton_movebefore->setEnabled(b_validsource && b_validtarget);
ui.pushButton_moveafter->setEnabled(b_validsource && b_validtarget);
return;
}
//
// Slot to update the service label when this->counter is updated. Other labels in page 4 receive signals directly
void ControlBox::counterUpdated(const QDBusObjectPath& qdb_objpath, const QString& home_label, const QString& roam_label)
{
// Don't update the counter if qdb_objpath is not the online service
if (! qdb_objpath.path().contains(onlineobjectpath) ) return;
// Set the labels in page 4
if (! qdb_objpath.path().isEmpty() ) {
QMap<QString,QVariant> map;
for (int i =0; i < services_list.size(); ++i) {
if (services_list.at(i).objpath == qdb_objpath) {
map = services_list.at(i).objmap;
break;
} // if
} // for
ui.label_counter_service_name->setText(tr("<b>Service:</b> %1").arg(getNickName(qdb_objpath)) );
ui.label_home_counter->setText(home_label);
ui.label_roam_counter->setText(roam_label);
}
else
ui.label_counter_service_name->setText(tr("<b>Service:</b> %1").arg(tr("Unable to determine service")) );
return;
}
//
// Slot to connect a wifi or vpn service. Called when ui.pushButton_connect
// or ui.pushButton_vpn_connect is pressed.
// For VPN's this connects the service, not the vpnconnection. It appears that connman_vpn takes
// the vpnconnections and creates one service for each. The vpnconnection part could be connected by
// using vpn connection interface, but not really worth it since connman automatically creates a
// a service for us.
void ControlBox::connectPressed()
{
// Process wifi or vpn depending on who sent the signal
QTableWidget* qtw = NULL;
if (sender() == ui.pushButton_connect) qtw = ui.tableWidget_wifi;
else if (sender() == ui.pushButton_vpn_connect) qtw = ui.tableWidget_vpn;
else return;
// If there is only one row select it
if (qtw->rowCount() == 1 ) {
QTableWidgetSelectionRange qtwsr = QTableWidgetSelectionRange(0, 0, 0, qtw->columnCount() - 1);
qtw->setRangeSelected(qtwsr, true);
}
// If no row is selected then return
QList<QTableWidgetItem*> list;
list.clear();
list = qtw->selectedItems();
if (list.isEmpty() ) {
QMessageBox::information(this, tr("No Services Selected"),
tr("You need to select a service before pressing the connect button.") );
return;
}
// set the manual flag (for vpn kill switch)
b_userinitiated = true;
//Because of single selection mode list can only have 0 or 1 items in it.
if (qtw == ui.tableWidget_wifi) pendingobjectpath = wifi_list.at(list.at(0)->row()).objpath.path();
else if (qtw == ui.tableWidget_vpn) pendingobjectpath = vpn_list.at(list.at(0)->row()).objpath.path();
else pendingobjectpath.clear();
// execute external program if specified
if (! ui.lineEdit_beforeconnect->text().isEmpty() ) {
if (list.at(0)->text() == ui.comboBox_beforeconnectserviceslist->currentText() ) {
QString text = ui.lineEdit_beforeconnect->text();
text = text.simplified();
QStringList args = text.split(' ');
QString cmd = args.first();
args.removeFirst();
if (ui.checkBox_modifyservicefile->isChecked()) {
gened = new GEN_Editor(this);
gened->editInPlace(ui.comboBox_beforeconnectservicefile->currentText(), cmd, args);
connect (gened, SIGNAL(finished(int)), this, SLOT(requestConnection()));
} // program does require a root helper
else {
proc = new QProcess(this);
proc->start(cmd, args);
connect (proc, SIGNAL(finished(int)), this, SLOT(requestConnection()));
} // program does not require root helper
} // if selected service matches the one to modify
} // if there is a command to execute
// else request the connection now
else requestConnection();
return;
}
//
// Slot to actually request a connection via DBUS. Called from the connectPressed() slot
void ControlBox::requestConnection()
{
// if we got here because a finished() signal fired delete the object that did it
if (proc) delete proc;
if (gened) delete gened;
// data member
QDBusInterface* iface_serv = NULL;
iface_serv = new QDBusInterface(DBUS_CON_SERVICE, pendingobjectpath, "net.connman.Service", QDBusConnection::systemBus(), this);
iface_serv->setTimeout(5); // need a short timeout to get the Agent
QDBusMessage reply = iface_serv->call(QDBus::AutoDetect, "Connect");
if (reply.errorName() != "org.freedesktop.DBus.Error.NoReply") shared::processReply(reply);
iface_serv->deleteLater();
return;
}
//
// Slot to disconnect a wifi or VPN service. Called when ui.pushButton_disconnect
// or ui.pushBotton_vpn_disconnect is pressed
void ControlBox::disconnectPressed()
{
// Process wifi or vpn depending on who sent the signal
QTableWidget* qtw = NULL;
if (sender() == ui.pushButton_disconnect) qtw = ui.tableWidget_wifi;
else if (sender() == ui.pushButton_vpn_disconnect) qtw = ui.tableWidget_vpn;
else return;
// If there is no item is selected run through the list looking for
// services in "online" or "ready" state. If more than one is found
// break as we will have to use the one currently selected.
int cntr_connected = 0;
int row_connected = -1;
if (qtw->selectedItems().isEmpty() ) {
int itemcount = 0;
QMap<QString,QVariant> map;
if (qtw == ui.tableWidget_wifi) itemcount = wifi_list.size();
else if (qtw == ui.tableWidget_vpn) itemcount = vpn_list.size();
else return; // line is not really needed
for (int row = 0; row < itemcount; ++row) {
if (qtw == ui.tableWidget_wifi) map = wifi_list.at(row).objmap;
else if (qtw == ui.tableWidget_vpn) map = vpn_list.at(row).objmap;
else return; // line is not really needed
if (map.value("State").toString() == "online" || map.value("State").toString() == "ready" ) {
++cntr_connected;
row_connected = row;
}
if (cntr_connected > 1 ) break;
} // for
// Nothing selected, online or ready so return now
if (cntr_connected == 0) return;
// If only one entry is connected or online, select it
if (cntr_connected == 1 ) {
QTableWidgetSelectionRange qtwsr = QTableWidgetSelectionRange(row_connected, 0, row_connected, qtw->columnCount() - 1);
qtw->setRangeSelected(qtwsr, true);
} // cntr_connected == 1
} // if there are no currently selected items
// If no row selected return
QList<QTableWidgetItem*> list;
list.clear();
list = qtw->selectedItems();
if (list.isEmpty() ) {
QMessageBox::information(this, tr("No Services Selected"),
tr("You need to select a service before pressing the disconnect button.") );
return;
}
// set user initiated flag (for vpn kill switch)
b_userinitiated = true;
// Send the disconnect message to the service. TableWidget only allows single selection so list can only have 0 or 1 elments
QDBusInterface* iface_serv = NULL;
if (qtw == ui.tableWidget_wifi)
iface_serv = new QDBusInterface(DBUS_CON_SERVICE, wifi_list.at(list.at(0)->row()).objpath.path(), "net.connman.Service", QDBusConnection::systemBus(), this);
else if (qtw == ui.tableWidget_vpn)
iface_serv = new QDBusInterface(DBUS_CON_SERVICE, vpn_list.at(list.at(0)->row()).objpath.path(), "net.connman.Service", QDBusConnection::systemBus(), this);
else return; // this line really not needed
shared::processReply(iface_serv->call(QDBus::AutoDetect, "Disconnect") );
iface_serv->deleteLater();
return;
}
//
// Slot to remove (unset the Favorite property, clear passphrase if one exists) of a Wifi service
// Called when ui.pushButton_remove is pressed
void ControlBox::removePressed()
{
// If there is only one row select it
if (ui.tableWidget_wifi->rowCount() == 1 ) {
QTableWidgetSelectionRange qtwsr = QTableWidgetSelectionRange(0, 0, 0, ui.tableWidget_wifi->columnCount() - 1);
ui.tableWidget_wifi->setRangeSelected(qtwsr, true);
}
// If no row is selected then return
QList<QTableWidgetItem*> list;
list.clear();
list = ui.tableWidget_wifi->selectedItems();
if (list.isEmpty() ) {
QMessageBox::information(this, tr("No Services Selected"),
tr("You need to select a Wifi service before pressing the remove button.") );
return;
}
// calling Remove() on hidden or provisioned services will cause an error, so simply return now without executing the method.
QMap<QString,QVariant> map = wifi_list.at(list.at(0)->row()).objmap;
if(map.value("Name").toString().isEmpty() || map.value("Immutable").toBool() ) return;
// send the Remove message to the service
QDBusInterface* iface_serv = new QDBusInterface(DBUS_CON_SERVICE, wifi_list.at(list.at(0)->row()).objpath.path(), "net.connman.Service", QDBusConnection::systemBus(), this);
QDBusMessage reply = iface_serv->call(QDBus::AutoDetect, "Remove");
shared::processReply(reply);
iface_serv->deleteLater();
return;
}
//
// Slot to edit a Wifi service. Note that Connman does not provide a way to retrieve or edit a passphrase. Adding something like this is insecure as we don't know
// anything about the permissions the CMST user has. The best we can do issue a remove call then a connect call.
void ControlBox::editPressed()
{
// If there is only one row select it
if (ui.tableWidget_wifi->rowCount() == 1 ) {
QTableWidgetSelectionRange qtwsr = QTableWidgetSelectionRange(0, 0, 0, ui.tableWidget_wifi->columnCount() - 1);
ui.tableWidget_wifi->setRangeSelected(qtwsr, true);
}
// if no row selected return