/
MainWindow.cpp
2945 lines (2458 loc) · 83.5 KB
/
MainWindow.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
/* Copyright (C) 2005-2011, Thorvald Natvig <thorvald@natvig.com>
Copyright (C) 2009-2011, Stefan Hacker <dd0t@users.sourceforge.net>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
- Neither the name of the Mumble Developers nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``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 FOUNDATION OR
CONTRIBUTORS 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 "mumble_pch.hpp"
#include "MainWindow.h"
#include "About.h"
#include "ACL.h"
#include "ACLEditor.h"
#include "AudioInput.h"
#include "AudioStats.h"
#include "AudioWizard.h"
#include "BanEditor.h"
#include "CELTCodec.h"
#include "Cert.h"
#include "Channel.h"
#include "Connection.h"
#include "ConnectDialog.h"
#include "Database.h"
#include "Global.h"
#include "GlobalShortcut.h"
#include "Log.h"
#include "Net.h"
#include "NetworkConfig.h"
#include "Overlay.h"
#include "Plugins.h"
#include "PTTButtonWidget.h"
#include "ServerHandler.h"
#include "TextMessage.h"
#include "Tokens.h"
#include "User.h"
#include "UserEdit.h"
#include "UserInformation.h"
#include "UserModel.h"
#include "VersionCheck.h"
#include "ViewCert.h"
#include "VoiceRecorderDialog.h"
#include "../SignalCurry.h"
#include "Settings.h"
#ifdef Q_OS_WIN
#include "TaskList.h"
#endif
#ifdef USE_COCOA
#include "ConfigDialog_macx.h"
#endif
MessageBoxEvent::MessageBoxEvent(QString m) : QEvent(static_cast<QEvent::Type>(MB_QEVENT)) {
msg = m;
}
OpenURLEvent::OpenURLEvent(QUrl u) : QEvent(static_cast<QEvent::Type>(OU_QEVENT)) {
url = u;
}
const QString MainWindow::defaultStyleSheet = QLatin1String(".log-channel{text-decoration:none;}.log-user{text-decoration:none;}p{margin:0;}");
MainWindow::MainWindow(QWidget *p) : QMainWindow(p) {
qiIconMuteSelf.addFile(QLatin1String("skin:muted_self.svg"));
qiIconMuteServer.addFile(QLatin1String("skin:muted_server.svg"));
qiIconMuteSuppressed.addFile(QLatin1String("skin:muted_suppressed.svg"));
qiIconDeafSelf.addFile(QLatin1String("skin:deafened_self.svg"));
qiIconDeafServer.addFile(QLatin1String("skin:deafened_server.svg"));
qiTalkingOff.addFile(QLatin1String("skin:talking_off.svg"));
qiTalkingOn.addFile(QLatin1String("skin:talking_on.svg"));
qiTalkingShout.addFile(QLatin1String("skin:talking_alt.svg"));
qiTalkingWhisper.addFile(QLatin1String("skin:talking_whisper.svg"));
#ifdef Q_OS_MAC
if (QFile::exists(QLatin1String("skin:mumble.icns")))
qiIcon.addFile(QLatin1String("skin:mumble.icns"));
else
qiIcon.addFile(QLatin1String("skin:mumble.svg"));
#else
{
QSvgRenderer svg(QLatin1String("skin:mumble.svg"));
QPixmap original(512,512);
original.fill(Qt::transparent);
QPainter painter(&original);
painter.setRenderHint(QPainter::Antialiasing);
painter.setRenderHint(QPainter::TextAntialiasing);
painter.setRenderHint(QPainter::SmoothPixmapTransform);
painter.setRenderHint(QPainter::HighQualityAntialiasing);
svg.render(&painter);
for (int sz=8;sz<=256;sz+=8)
qiIcon.addPixmap(original.scaled(sz,sz, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
}
// Set application icon except on MacOSX, where the window-icon
// shown in the title-bar usually serves as a draggable version of the
// current open document (i.e. you can copy the open document anywhere
// simply by dragging this icon).
qApp->setWindowIcon(qiIcon);
// Set the icon on the MainWindow directly. This fixes the icon not
// being set on the MainWindow in certain environments (Ex: GTK+).
setWindowIcon(qiIcon);
#endif
#ifdef Q_OS_WIN
uiNewHardware = 1;
#endif
bSuppressAskOnQuit = false;
bAutoUnmute = false;
Channel::add(0, tr("Root"));
aclEdit = NULL;
banEdit = NULL;
userEdit = NULL;
tokenEdit = NULL;
voiceRecorderDialog = NULL;
qwPTTButtonWidget = NULL;
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
cuContextUser = QWeakPointer<ClientUser>();
cContextChannel = QWeakPointer<Channel>();
#endif
qtReconnect = new QTimer(this);
qtReconnect->setInterval(10000);
qtReconnect->setSingleShot(true);
qtReconnect->setObjectName(QLatin1String("Reconnect"));
qmUser = new QMenu(tr("&User"), this);
qmChannel = new QMenu(tr("&Channel"), this);
createActions();
setupUi(this);
setupGui();
connect(qmUser, SIGNAL(aboutToShow()), this, SLOT(qmUser_aboutToShow()));
connect(qmChannel, SIGNAL(aboutToShow()), this, SLOT(qmChannel_aboutToShow()));
connect(qteChat, SIGNAL(entered(QString)), this, SLOT(sendChatbarMessage(QString)));
// Fix context of all actions.
QList<QAction *> qla = findChildren<QAction *>();
foreach(QAction *a, qla)
a->setShortcutContext(Qt::ApplicationShortcut);
on_qmServer_aboutToShow();
on_qmSelf_aboutToShow();
qmChannel_aboutToShow();
qmUser_aboutToShow();
on_qmConfig_aboutToShow();
setOnTop(g.s.aotbAlwaysOnTop == Settings::OnTopAlways ||
(g.s.bMinimalView && g.s.aotbAlwaysOnTop == Settings::OnTopInMinimal) ||
(!g.s.bMinimalView && g.s.aotbAlwaysOnTop == Settings::OnTopInNormal));
#ifdef NO_UPDATE_CHECK
delete qaHelpVersionCheck;
#endif
}
void MainWindow::createActions() {
int idx = 1;
gsPushTalk=new GlobalShortcut(this, idx++, tr("Push-to-Talk", "Global Shortcut"), false);
gsPushTalk->setObjectName(QLatin1String("PushToTalk"));
gsPushTalk->qsToolTip = tr("Push and hold this button to send voice.", "Global Shortcut");
gsPushTalk->qsWhatsThis = tr("This configures the push-to-talk button, and as long as you hold this button down, you will transmit voice.", "Global Shortcut");
gsResetAudio=new GlobalShortcut(this, idx++, tr("Reset Audio Processor", "Global Shortcut"));
gsResetAudio->setObjectName(QLatin1String("ResetAudio"));
gsMuteSelf=new GlobalShortcut(this, idx++, tr("Mute Self", "Global Shortcut"), false, 0);
gsMuteSelf->setObjectName(QLatin1String("gsMuteSelf"));
gsMuteSelf->qsToolTip = tr("Set self-mute status.", "Global Shortcut");
gsMuteSelf->qsWhatsThis = tr("This will set or toggle your muted status. If you turn this off, you will also disable self-deafen.", "Global Shortcut");
gsDeafSelf=new GlobalShortcut(this, idx++, tr("Deafen Self", "Global Shortcut"), false, 0);
gsDeafSelf->setObjectName(QLatin1String("gsDeafSelf"));
gsDeafSelf->qsToolTip = tr("Set self-deafen status.", "Global Shortcut");
gsDeafSelf->qsWhatsThis = tr("This will set or toggle your deafened status. If you turn this on, you will also enable self-mute.", "Global Shortcut");
gsUnlink=new GlobalShortcut(this, idx++, tr("Unlink Plugin", "Global Shortcut"));
gsUnlink->setObjectName(QLatin1String("UnlinkPlugin"));
gsPushMute=new GlobalShortcut(this, idx++, tr("Push-to-Mute", "Global Shortcut"));
gsPushMute->setObjectName(QLatin1String("PushToMute"));
gsJoinChannel=new GlobalShortcut(this, idx++, tr("Join Channel", "Global Shortcut"));
gsJoinChannel->setObjectName(QLatin1String("MetaChannel"));
gsJoinChannel->qsToolTip = tr("Use in conjunction with Whisper to.", "Global Shortcut");
gsHideChannel=new GlobalShortcut(this, idx++, tr("Hide Channel when Filtering", "Global Shortcut"));
gsHideChannel->setObjectName(QLatin1String("HideChannel"));
gsHideChannel->qsToolTip = tr("Mark the channel to be hidden when Filtering is active. Use in conjunction with Whisper to.", "Global Shortcut");
gsToggleOverlay=new GlobalShortcut(this, idx++, tr("Toggle Overlay", "Global Shortcut"), false);
gsToggleOverlay->setObjectName(QLatin1String("ToggleOverlay"));
gsToggleOverlay->qsToolTip = tr("Toggle state of in-game overlay.", "Global Shortcut");
gsToggleOverlay->qsWhatsThis = tr("This will switch the states of the in-game overlay.", "Global Shortcut");
connect(gsToggleOverlay, SIGNAL(down(QVariant)), g.o, SLOT(toggleShow()));
gsMinimal=new GlobalShortcut(this, idx++, tr("Toggle Minimal", "Global Shortcut"));
gsMinimal->setObjectName(QLatin1String("ToggleMinimal"));
gsVolumeUp=new GlobalShortcut(this, idx++, tr("Volume Up (+10%)", "Global Shortcut"));
gsVolumeUp->setObjectName(QLatin1String("VolumeUp"));
gsVolumeDown=new GlobalShortcut(this, idx++, tr("Volume Down (-10%)", "Global Shortcut"));
gsVolumeDown->setObjectName(QLatin1String("VolumeDown"));
qstiIcon = new QSystemTrayIcon(qiIcon, this);
qstiIcon->setToolTip(tr("Mumble -- %1").arg(QLatin1String(MUMBLE_RELEASE)));
qstiIcon->setObjectName(QLatin1String("Icon"));
gsWhisper = new GlobalShortcut(this, idx++, tr("Whisper/Shout"), false, QVariant::fromValue(ShortcutTarget()));
gsWhisper->setObjectName(QLatin1String("gsWhisper"));
gsLinkChannel=new GlobalShortcut(this, idx++, tr("Link Channel", "Global Shortcut"));
gsLinkChannel->setObjectName(QLatin1String("MetaLink"));
gsLinkChannel->qsToolTip = tr("Use in conjunction with Whisper to.", "Global Shortcut");
gsCycleTransmitMode=new GlobalShortcut(this, idx++, tr("Cycle Transmit Mode", "Global Shortcut"));
gsCycleTransmitMode->setObjectName(QLatin1String("gsCycleTransmitMode"));
gsChannelFilter=new GlobalShortcut(this, idx++, tr("Channel Filter", "Global Shortcut"), false, 0);
gsChannelFilter->setObjectName(QLatin1String("gsChannelFilter"));
#ifndef Q_OS_MAC
qstiIcon->show();
#endif
}
void MainWindow::setupGui() {
setWindowTitle(tr("Mumble -- %1").arg(QLatin1String(MUMBLE_RELEASE)));
setCentralWidget(qtvUsers);
setAcceptDrops(true);
#ifdef Q_OS_MAC
QMenu *qmWindow = new QMenu(tr("&Window"), this);
menubar->insertMenu(qmHelp->menuAction(), qmWindow);
qmWindow->addAction(tr("Minimize"), this, SLOT(showMinimized()), QKeySequence(tr("Ctrl+M")));
qtvUsers->setAttribute(Qt::WA_MacShowFocusRect, false);
qteChat->setAttribute(Qt::WA_MacShowFocusRect, false);
qteChat->setFrameShape(QFrame::NoFrame);
qteLog->setFrameStyle(QFrame::NoFrame);
#endif
LogDocument *ld = new LogDocument(qteLog);
qteLog->setDocument(ld);
qteLog->document()->setMaximumBlockCount(g.s.iMaxLogBlocks);
qteLog->document()->setDefaultStyleSheet(qApp->styleSheet());
pmModel = new UserModel(qtvUsers);
qtvUsers->setModel(pmModel);
qtvUsers->setRowHidden(0, QModelIndex(), true);
qtvUsers->ensurePolished();
qaAudioMute->setChecked(g.s.bMute);
qaAudioDeaf->setChecked(g.s.bDeaf);
qaAudioTTS->setChecked(g.s.bTTS);
qaFilterToggle->setChecked(g.s.bFilterActive);
qaHelpWhatsThis->setShortcuts(QKeySequence::WhatsThis);
qaConfigMinimal->setChecked(g.s.bMinimalView);
qaConfigHideFrame->setChecked(g.s.bHideFrame);
connect(gsResetAudio, SIGNAL(down(QVariant)), qaAudioReset, SLOT(trigger()));
connect(gsUnlink, SIGNAL(down(QVariant)), qaAudioUnlink, SLOT(trigger()));
connect(gsMinimal, SIGNAL(down(QVariant)), qaConfigMinimal, SLOT(trigger()));
dtbLogDockTitle = new DockTitleBar();
qdwLog->setTitleBarWidget(dtbLogDockTitle);
foreach(QWidget *w, qdwLog->findChildren<QWidget *>()) {
w->installEventFilter(dtbLogDockTitle);
w->setMouseTracking(true);
}
dtbChatDockTitle = new DockTitleBar();
qdwChat->setTitleBarWidget(dtbChatDockTitle);
qdwChat->installEventFilter(dtbChatDockTitle);
qteChat->setDefaultText(tr("<center>Not connected</center>"), true);
qteChat->setEnabled(false);
setShowDockTitleBars(g.s.wlWindowLayout == Settings::LayoutCustom);
#ifdef USE_COCOA
// Workaround for QTBUG-3116 -- using a unified toolbar on Mac OS X
// and using restoreGeometry before the window has updated its frameStrut
// causes the MainWindow to jump around on screen on launch. Workaround
// is to call show() to update the frameStrut and set the windowOpacity to
// 0 to hide any graphical glitches that occur when we add stuff to the
// window.
setWindowOpacity(0.0f);
show();
#endif
connect(qtvUsers->selectionModel(),
SIGNAL(currentChanged(const QModelIndex &, const QModelIndex &)),
SLOT(qtvUserCurrentChanged(const QModelIndex &, const QModelIndex &)));
#ifndef Q_OS_MAC
setupView(false);
#endif
if (g.s.bMinimalView && ! g.s.qbaMinimalViewGeometry.isNull())
restoreGeometry(g.s.qbaMinimalViewGeometry);
else if (! g.s.bMinimalView && ! g.s.qbaMainWindowGeometry.isNull())
restoreGeometry(g.s.qbaMainWindowGeometry);
Settings::WindowLayout wlTmp = g.s.wlWindowLayout;
if (g.s.bMinimalView && ! g.s.qbaMinimalViewState.isNull())
restoreState(g.s.qbaMinimalViewState);
else if (! g.s.bMinimalView && ! g.s.qbaMainWindowState.isNull())
restoreState(g.s.qbaMainWindowState);
g.s.wlWindowLayout = wlTmp;
setupView(false);
qmTray = new QMenu(this);
connect(qmTray, SIGNAL(aboutToShow()), this, SLOT(trayAboutToShow()));
trayAboutToShow();
qstiIcon->setContextMenu(qmTray);
updateTrayIcon();
updateTransmitModeIcons();
#ifdef USE_COCOA
setWindowOpacity(1.0f);
#if QT_VERSION < 0x040700
// Process pending events. This is done to force the unified
// toolbar to show up as soon as possible (and not wait until
// we are back into the Cocoa mainloop)
qApp->processEvents();
#endif
#endif
}
// Sets whether or not to show the title bars on the MainWindow's
// dock widgets.
void MainWindow::setShowDockTitleBars(bool doShow) {
dtbLogDockTitle->setEnabled(doShow);
dtbChatDockTitle->setEnabled(doShow);
}
MainWindow::~MainWindow() {
delete qwPTTButtonWidget;
delete qdwLog->titleBarWidget();
delete pmModel;
delete qtvUsers;
delete Channel::get(0);
}
void MainWindow::msgBox(QString msg) {
MessageBoxEvent *mbe=new MessageBoxEvent(msg);
QApplication::postEvent(this, mbe);
}
#ifdef Q_OS_WIN
bool MainWindow::winEvent(MSG *msg, long *) {
if (msg->message == WM_DEVICECHANGE && msg->wParam == DBT_DEVNODES_CHANGED)
uiNewHardware++;
else if (msg->message == WM_ACTIVATE && msg->wParam == WA_INACTIVE)
tInactive.restart();
return false;
}
#endif
void MainWindow::closeEvent(QCloseEvent *e) {
#ifndef Q_OS_MAC
ServerHandlerPtr sh = g.sh;
if (sh && sh->isRunning() && g.s.bAskOnQuit && !bSuppressAskOnQuit) {
QMessageBox mb(QMessageBox::Warning, QLatin1String("Mumble"), tr("Mumble is currently connected to a server. Do you want to Close or Minimize it?"), QMessageBox::NoButton, this);
QPushButton *qpbClose = mb.addButton(tr("Close"), QMessageBox::YesRole);
QPushButton *qpbMinimize = mb.addButton(tr("Minimize"), QMessageBox::NoRole);
mb.setDefaultButton(qpbMinimize);
mb.setEscapeButton(qpbMinimize);
mb.exec();
if (mb.clickedButton() != qpbClose) {
showMinimized();
e->ignore();
return;
}
}
sh.reset();
#endif
g.uiSession = 0;
g.pPermissions = ChanACL::None;
if (g.s.bMinimalView) {
g.s.qbaMinimalViewGeometry = saveGeometry();
g.s.qbaMinimalViewState = saveState();
} else {
g.s.qbaMainWindowGeometry = saveGeometry();
g.s.qbaMainWindowState = saveState();
g.s.qbaHeaderState = qtvUsers->header()->saveState();
}
if (qwPTTButtonWidget) {
qwPTTButtonWidget->close();
qwPTTButtonWidget->deleteLater();
qwPTTButtonWidget = NULL;
}
g.bQuit = true;
QMainWindow::closeEvent(e);
qApp->quit();
}
void MainWindow::hideEvent(QHideEvent *e) {
if (g.ocIntercept) {
QMetaObject::invokeMethod(g.ocIntercept, "hideGui", Qt::QueuedConnection);
e->ignore();
return;
}
#ifndef Q_OS_MAC
#ifdef Q_OS_UNIX
if (! qApp->activeModalWidget() && ! qApp->activePopupWidget())
#endif
if (g.s.bHideInTray && qstiIcon->isSystemTrayAvailable() && e->spontaneous())
QMetaObject::invokeMethod(this, "hide", Qt::QueuedConnection);
QMainWindow::hideEvent(e);
#endif
}
void MainWindow::showEvent(QShowEvent *e) {
#ifndef Q_OS_MAC
#ifdef Q_OS_UNIX
if (! qApp->activeModalWidget() && ! qApp->activePopupWidget())
#endif
if (g.s.bHideInTray && qstiIcon->isSystemTrayAvailable() && e->spontaneous())
QMetaObject::invokeMethod(this, "show", Qt::QueuedConnection);
#endif
QMainWindow::showEvent(e);
}
void MainWindow::updateTrayIcon() {
ClientUser *p=ClientUser::get(g.uiSession);
if (g.s.bDeaf) {
qstiIcon->setIcon(qiIconDeafSelf);
} else if (p && p->bDeaf) {
qstiIcon->setIcon(qiIconDeafServer);
} else if (g.s.bMute) {
qstiIcon->setIcon(qiIconMuteSelf);
} else if (p && p->bMute) {
qstiIcon->setIcon(qiIconMuteServer);
} else if (p && p->bSuppress) {
qstiIcon->setIcon(qiIconMuteSuppressed);
} else if (p && g.s.bStateInTray) {
switch (p->tsState) {
case Settings::Talking:
qstiIcon->setIcon(qiTalkingOn);
break;
case Settings::Whispering:
qstiIcon->setIcon(qiTalkingWhisper);
break;
case Settings::Shouting:
qstiIcon->setIcon(qiTalkingShout);
break;
case Settings::Passive:
default:
qstiIcon->setIcon(qiTalkingOff);
break;
}
} else {
qstiIcon->setIcon(qiIcon);
}
}
void MainWindow::updateTransmitModeIcons() {
switch (g.s.atTransmit)
{
case Settings::Continous:
qaSetTransmitModeContinous->setChecked(true);
qaSetTransmitModePushToTalk->setChecked(false);
qaSetTransmitModeVAD->setChecked(false);
return;
case Settings::VAD:
qaSetTransmitModeContinous->setChecked(false);
qaSetTransmitModePushToTalk->setChecked(false);
qaSetTransmitModeVAD->setChecked(true);
return;
case Settings::PushToTalk:
qaSetTransmitModeContinous->setChecked(false);
qaSetTransmitModePushToTalk->setChecked(true);
qaSetTransmitModeVAD->setChecked(false);
return;
}
}
Channel *MainWindow::getContextMenuChannel() {
if (cContextChannel)
return cContextChannel.data();
return NULL;
}
ClientUser *MainWindow::getContextMenuUser() {
if (cuContextUser)
return cuContextUser.data();
return NULL;
}
bool MainWindow::handleSpecialContextMenu(const QUrl &url, const QPoint &pos_, bool focus) {
if (url.scheme() == QString::fromLatin1("clientid")) {
bool ok = false;
QString x(url.host());
if (x.length() == 40) {
ClientUser *cu = pmModel->getUser(x);
if (cu) {
cuContextUser = cu;
ok = true;
}
} else {
QByteArray qbaServerDigest = QByteArray::fromBase64(url.path().remove(0, 1).toLatin1());
cuContextUser = ClientUser::get(url.host().toInt(&ok, 10));
ServerHandlerPtr sh = g.sh;
ok = ok && sh && (qbaServerDigest == sh->qbaDigest);
}
if (ok && cuContextUser) {
if (focus) {
qtvUsers->setCurrentIndex(pmModel->index(cuContextUser.data()));
qteChat->setFocus();
} else {
qpContextPosition = QPoint();
qmUser->exec(pos_, NULL);
}
}
cuContextUser.clear();
} else if (url.scheme() == QString::fromLatin1("channelid")) {
bool ok;
QByteArray qbaServerDigest = QByteArray::fromBase64(url.path().remove(0, 1).toLatin1());
cContextChannel = Channel::get(url.host().toInt(&ok, 10));
ServerHandlerPtr sh = g.sh;
ok = ok && sh && (qbaServerDigest == sh->qbaDigest);
if (ok) {
if (focus) {
qtvUsers->setCurrentIndex(pmModel->index(cContextChannel.data()));
qteChat->setFocus();
} else {
qpContextPosition = QPoint();
qmChannel->exec(pos_, NULL);
}
}
cContextChannel.clear();
} else {
return false;
}
return true;
}
void MainWindow::on_qtvUsers_customContextMenuRequested(const QPoint &mpos) {
QModelIndex idx = qtvUsers->indexAt(mpos);
if (! idx.isValid())
idx = qtvUsers->currentIndex();
else
qtvUsers->setCurrentIndex(idx);
ClientUser *p = pmModel->getUser(idx);
qpContextPosition = mpos;
if (p) {
cuContextUser.clear();
qmUser->exec(qtvUsers->mapToGlobal(mpos), qaUserMute);
cuContextUser.clear();
} else {
cContextChannel.clear();
qmChannel->exec(qtvUsers->mapToGlobal(mpos), NULL);
cContextChannel.clear();
}
qpContextPosition = QPoint();
}
void MainWindow::on_qteLog_customContextMenuRequested(const QPoint &mpos) {
QString link = qteLog->anchorAt(mpos);
if (! link.isEmpty()) {
QUrl l(link);
if (handleSpecialContextMenu(l, qteLog->mapToGlobal(mpos)))
return;
}
QPoint contentPosition = QPoint(QApplication::isRightToLeft() ? (qteLog->horizontalScrollBar()->maximum() - qteLog->horizontalScrollBar()->value()) : qteLog->horizontalScrollBar()->value(), qteLog->verticalScrollBar()->value());
QMenu *menu = qteLog->createStandardContextMenu(mpos + contentPosition);
menu->addSeparator();
menu->addAction(tr("Clear"), qteLog, SLOT(clear(void)));
menu->exec(qteLog->mapToGlobal(mpos));
delete menu;
}
static void recreateServerHandler() {
ServerHandlerPtr sh = g.sh;
if (sh && sh->isRunning()) {
g.mw->on_qaServerDisconnect_triggered();
sh->disconnect();
sh->wait();
QCoreApplication::instance()->processEvents();
}
g.sh.reset();
while (sh && ! sh.unique())
QThread::yieldCurrentThread();
sh.reset();
sh = ServerHandlerPtr(new ServerHandler());
sh->moveToThread(sh.get());
g.sh = sh;
g.mw->connect(sh.get(), SIGNAL(connected()), g.mw, SLOT(serverConnected()));
g.mw->connect(sh.get(), SIGNAL(disconnected(QAbstractSocket::SocketError, QString)), g.mw, SLOT(serverDisconnected(QAbstractSocket::SocketError, QString)));
}
void MainWindow::openUrl(const QUrl &url) {
g.l->log(Log::Information, tr("Opening URL %1").arg(url.toString()));
if (url.scheme() == QLatin1String("file")) {
QFile f(url.toLocalFile());
if (! f.exists() || ! f.open(QIODevice::ReadOnly)) {
g.l->log(Log::Warning, tr("File does not exist"));
return;
}
f.close();
QSettings *qs = new QSettings(f.fileName(), QSettings::IniFormat);
qs->setIniCodec("UTF-8");
if (qs->status() != QSettings::NoError) {
g.l->log(Log::Warning, tr("File is not a configuration file."));
} else {
qSwap(qs, g.qs);
g.s.load();
qSwap(qs, g.qs);
g.l->log(Log::Warning, tr("Settings merged from file."));
}
delete qs;
return;
}
if (url.scheme() != QLatin1String("mumble")) {
g.l->log(Log::Warning, tr("URL scheme is not 'mumble'"));
return;
}
int major, minor, patch;
int thismajor, thisminor, thispatch;
MumbleVersion::get(&thismajor, &thisminor, &thispatch);
// With no version parameter given assume the link refers to our version
major = 1;
minor = 2;
patch = 0;
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
QUrlQuery query(url);
QString version = query.queryItemValue(QLatin1String("version"));
#else
QString version = url.queryItemValue(QLatin1String("version"));
#endif
MumbleVersion::get(&major, &minor, &patch, version);
if ((major < 1) || // No pre 1.2.0
(major == 1 && minor <= 1) ||
(major > thismajor) || // No future version
(major == thismajor && minor > thisminor) ||
(major == thismajor && minor == thisminor && patch > thispatch)) {
g.l->log(Log::Warning, tr("This version of Mumble can't handle URLs for Mumble version %1.%2.%3").arg(major).arg(minor).arg(patch));
return;
}
QString host = url.host();
unsigned short port = static_cast<unsigned short>(url.port(DEFAULT_MUMBLE_PORT));
QString user = url.userName();
QString pw = url.password();
qsDesiredChannel = url.path();
QString name;
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
if (query.hasQueryItem(QLatin1String("title")))
name = query.queryItemValue(QLatin1String("title"));
#else
if (url.hasQueryItem(QLatin1String("title")))
name = url.queryItemValue(QLatin1String("title"));
#endif
if (g.sh && g.sh->isRunning()) {
QString oHost, oUser, oPw;
unsigned short oport;
g.sh->getConnectionInfo(oHost, oport, oUser, oPw);
if ((user.isEmpty() || (user == oUser)) &&
(host.isEmpty() || ((host == oHost) && (port == oport)))) {
findDesiredChannel();
return;
}
}
Database::fuzzyMatch(name, user, pw, host, port);
if (user.isEmpty()) {
bool ok;
user = QInputDialog::getText(this, tr("Connecting to %1").arg(url.toString()), tr("Enter username"), QLineEdit::Normal, g.s.qsUsername, &ok);
if (! ok || user.isEmpty())
return;
g.s.qsUsername = user;
}
if (name.isEmpty())
name = QString::fromLatin1("%1@%2").arg(user).arg(host);
recreateServerHandler();
g.s.qsLastServer = name;
rtLast = MumbleProto::Reject_RejectType_None;
qaServerDisconnect->setEnabled(true);
g.l->log(Log::Information, tr("Connecting to server %1.").arg(Log::msgColor(host, Log::Server)));
g.sh->setConnectionInfo(host, port, user, pw);
g.sh->start(QThread::TimeCriticalPriority);
}
/**
* This function tries to join a desired channel on connect. It gets called
* directly after server syncronization is completed.
* @see void MainWindow::msgServerSync(const MumbleProto::ServerSync &msg)
*/
void MainWindow::findDesiredChannel() {
bool found = false;
QStringList qlChans = qsDesiredChannel.split(QLatin1String("/"));
Channel *chan = Channel::get(0);
QString str = QString();
while (chan && qlChans.count() > 0) {
QString elem = qlChans.takeFirst().toLower();
if (elem.isEmpty())
continue;
if (str.isNull())
str = elem;
else
str = str + QLatin1String("/") + elem;
foreach(Channel *c, chan->qlChannels) {
if (c->qsName.toLower() == str) {
str = QString();
found = true;
chan = c;
break;
}
}
}
if (found) {
if (chan != ClientUser::get(g.uiSession)->cChannel) {
g.sh->joinChannel(chan->iId);
}
qtvUsers->setCurrentIndex(pmModel->index(chan));
} else if (g.uiSession) {
qtvUsers->setCurrentIndex(pmModel->index(ClientUser::get(g.uiSession)->cChannel));
}
updateMenuPermissions();
}
void MainWindow::setOnTop(bool top) {
Qt::WindowFlags wf = windowFlags();
if (wf.testFlag(Qt::WindowStaysOnTopHint) != top) {
if (top)
wf |= Qt::WindowStaysOnTopHint;
else
wf &= ~Qt::WindowStaysOnTopHint;
setWindowFlags(wf);
show();
}
}
void MainWindow::setupView(bool toggle_minimize) {
bool showit = ! g.s.bMinimalView;
// Update window layout
Settings::WindowLayout wlTmp = g.s.wlWindowLayout;
switch (wlTmp) {
case Settings::LayoutClassic:
removeDockWidget(qdwLog);
addDockWidget(Qt::LeftDockWidgetArea, qdwLog);
qdwLog->show();
splitDockWidget(qdwLog, qdwChat, Qt::Vertical);
qdwChat->show();
break;
case Settings::LayoutStacked:
removeDockWidget(qdwLog);
addDockWidget(Qt::BottomDockWidgetArea, qdwLog);
qdwLog->show();
splitDockWidget(qdwLog, qdwChat, Qt::Vertical);
qdwChat->show();
break;
case Settings::LayoutHybrid:
removeDockWidget(qdwLog);
removeDockWidget(qdwChat);
addDockWidget(Qt::LeftDockWidgetArea, qdwLog);
qdwLog->show();
addDockWidget(Qt::BottomDockWidgetArea, qdwChat);
qdwChat->show();
break;
default:
wlTmp = Settings::LayoutCustom;
break;
}
qteChat->updateGeometry();
g.s.wlWindowLayout = wlTmp;
QRect geom = frameGeometry();
if (toggle_minimize) {
if (! showit) {
g.s.qbaMainWindowGeometry = saveGeometry();
g.s.qbaMainWindowState = saveState();
g.s.qbaHeaderState = qtvUsers->header()->saveState();
} else {
g.s.qbaMinimalViewGeometry = saveGeometry();
g.s.qbaMinimalViewState = saveState();
}
}
Qt::WindowFlags f = Qt::Window;
if (!showit && g.s.bHideFrame)
f = Qt::Window | Qt::FramelessWindowHint;
#ifndef Q_OS_MAC
else if (!showit)
f = Qt::Tool;
#else
f |= Qt::MacWindowToolBarButtonHint | Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint;
#endif
if (g.s.aotbAlwaysOnTop == Settings::OnTopAlways ||
(g.s.bMinimalView && g.s.aotbAlwaysOnTop == Settings::OnTopInMinimal) ||
(!g.s.bMinimalView && g.s.aotbAlwaysOnTop == Settings::OnTopInNormal))
f |= Qt::WindowStaysOnTopHint;
if (! graphicsProxyWidget())
setWindowFlags(f);
if (g.s.bShowContextMenuInMenuBar) {
bool found = false;
foreach(QAction *a, menuBar()->actions()) {
if (a == qmUser->menuAction()) {
found = true;
break;
}
}
if (!found) {
menuBar()->insertMenu(qmConfig->menuAction(), qmUser);
menuBar()->insertMenu(qmConfig->menuAction(), qmChannel);
}
} else {
menuBar()->removeAction(qmUser->menuAction());
menuBar()->removeAction(qmChannel->menuAction());
}
if (! showit) {
qdwLog->setVisible(showit);
qdwChat->setVisible(showit);
qtIconToolbar->setVisible(showit);
}
menuBar()->setVisible(showit);
if (toggle_minimize) {
if (! showit) {
if (! g.s.qbaMinimalViewGeometry.isNull())
restoreGeometry(g.s.qbaMinimalViewGeometry);
if (! g.s.qbaMinimalViewState.isNull())
restoreState(g.s.qbaMinimalViewState);
} else {
if (! g.s.qbaMainWindowGeometry.isNull())
restoreGeometry(g.s.qbaMainWindowGeometry);
if (! g.s.qbaMainWindowState.isNull())
restoreState(g.s.qbaMainWindowState);
}
} else {
QRect newgeom = frameGeometry();
resize(geometry().width()-newgeom.width()+geom.width(),
geometry().height()-newgeom.height()+geom.height());
move(geom.x(), geom.y());
}
show();
activateWindow();
// If activated show the PTT window
if (g.s.bShowPTTButtonWindow && g.s.atTransmit == Settings::PushToTalk) {
if (qwPTTButtonWidget) {
qwPTTButtonWidget->show();
} else {
qwPTTButtonWidget = new PTTButtonWidget();
qwPTTButtonWidget->show();
connect(qwPTTButtonWidget, SIGNAL(triggered(bool,QVariant)), SLOT(on_PushToTalk_triggered(bool,QVariant)));
}
} else {
if (qwPTTButtonWidget) {
qwPTTButtonWidget->deleteLater();
qwPTTButtonWidget = NULL;
}
}
}
void MainWindow::on_qaServerConnect_triggered(bool autoconnect) {
ConnectDialog *cd = new ConnectDialog(this, autoconnect);
int res = cd->exec();
if (cd->qsServer.isEmpty() || (cd->usPort==0) || cd->qsUsername.isEmpty())
res = QDialog::Rejected;
if (res == QDialog::Accepted) {
recreateServerHandler();
qsDesiredChannel = QString();
rtLast = MumbleProto::Reject_RejectType_None;
qaServerDisconnect->setEnabled(true);
g.l->log(Log::Information, tr("Connecting to server %1.").arg(Log::msgColor(cd->qsServer, Log::Server)));
g.sh->setConnectionInfo(cd->qsServer, cd->usPort, cd->qsUsername, cd->qsPassword);
g.sh->start(QThread::TimeCriticalPriority);
}
delete cd;
}
void MainWindow::on_Reconnect_timeout() {
if (g.sh->isRunning())
return;
g.l->log(Log::Information, tr("Reconnecting."));
g.sh->start(QThread::TimeCriticalPriority);
}
void MainWindow::on_qmSelf_aboutToShow() {
ClientUser *user = ClientUser::get(g.uiSession);
qaServerTexture->setEnabled(user != NULL);
qaSelfComment->setEnabled(user != NULL);
qaServerTextureRemove->setEnabled(user && ! user->qbaTextureHash.isEmpty());
qaSelfRegister->setEnabled(user && (user->iId < 0) && ! user->qsHash.isEmpty() && (g.pPermissions & (ChanACL::SelfRegister | ChanACL::Write)));
if (g.sh && g.sh->uiVersion >= 0x010203) {
qaSelfPrioritySpeaker->setEnabled(user && g.pPermissions & (ChanACL::Write | ChanACL::MuteDeafen));
qaSelfPrioritySpeaker->setChecked(user && user->bPrioritySpeaker);
} else {
qaSelfPrioritySpeaker->setEnabled(false);
qaSelfPrioritySpeaker->setChecked(false);
}
}
void MainWindow::on_qaSelfComment_triggered() {
ClientUser *p = ClientUser::get(g.uiSession);
if (!p)
return;
if (! p->qbaCommentHash.isEmpty() && p->qsComment.isEmpty()) {
p->qsComment = QString::fromUtf8(Database::blob(p->qbaCommentHash));
if (p->qsComment.isEmpty()) {
pmModel->uiSessionComment = ~(p->uiSession);
MumbleProto::RequestBlob mprb;
mprb.add_session_comment(p->uiSession);
g.sh->sendMessage(mprb);
return;
}
}
unsigned int session = p->uiSession;
::TextMessage *texm = new ::TextMessage(this, tr("Change your comment"));
texm->rteMessage->setText(p->qsComment);
int res = texm->exec();
p = ClientUser::get(session);