~ubuntu-branches/ubuntu/saucy/quassel/saucy-proposed

« back to all changes in this revision

Viewing changes to src/qtui/mainwin.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-02-17 12:49:50 UTC
  • mto: This revision was merged to the branch mainline in revision 59.
  • Revision ID: james.westby@ubuntu.com-20100217124950-v9hajw5d2xa6fszn
Tags: upstream-0.6~beta1
ImportĀ upstreamĀ versionĀ 0.6~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
#include "chatmonitorview.h"
52
52
#include "chatview.h"
53
53
#include "client.h"
54
 
#include "clientsyncer.h"
55
54
#include "clientbacklogmanager.h"
56
55
#include "clientbufferviewconfig.h"
57
56
#include "clientbufferviewmanager.h"
58
57
#include "clientignorelistmanager.h"
 
58
#include "coreconfigwizard.h"
 
59
#include "coreconnectdlg.h"
 
60
#include "coreconnection.h"
 
61
#include "coreconnectionstatuswidget.h"
59
62
#include "coreinfodlg.h"
60
 
#include "coreconnectdlg.h"
61
63
#include "contextmenuactionprovider.h"
62
64
#include "debugbufferviewoverlay.h"
63
65
#include "debuglogwidget.h"
68
70
#include "irclistmodel.h"
69
71
#include "ircconnectionwizard.h"
70
72
#include "jumpkeyhandler.h"
 
73
#include "legacysystemtray.h"
71
74
#include "msgprocessorstatuswidget.h"
72
75
#include "nicklistwidget.h"
73
76
#include "qtuiapplication.h"
76
79
#include "qtuistyle.h"
77
80
#include "settingsdlg.h"
78
81
#include "settingspagedlg.h"
79
 
#include "systemtray.h"
 
82
#include "statusnotifieritem.h"
80
83
#include "toolbaractionprovider.h"
81
84
#include "topicwidget.h"
82
85
#include "verticaldock.h"
94
97
#  include "knotificationbackend.h"
95
98
#endif /* HAVE_KDE */
96
99
 
 
100
#ifdef HAVE_SSL
 
101
#  include "sslinfodlg.h"
 
102
#endif
 
103
 
97
104
#ifdef HAVE_INDICATEQT
98
105
  #include "indicatornotificationbackend.h"
99
106
#endif
105
112
#include "settingspages/chatmonitorsettingspage.h"
106
113
#include "settingspages/chatviewsettingspage.h"
107
114
#include "settingspages/connectionsettingspage.h"
108
 
#include "settingspages/generalsettingspage.h"
 
115
#include "settingspages/coreaccountsettingspage.h"
 
116
#include "settingspages/coreconnectionsettingspage.h"
109
117
#include "settingspages/highlightsettingspage.h"
110
118
#include "settingspages/identitiessettingspage.h"
111
119
#include "settingspages/ignorelistsettingspage.h"
122
130
#else
123
131
  : QMainWindow(parent),
124
132
#endif
125
 
    coreLagLabel(new QLabel()),
126
 
    sslLabel(new QLabel()),
127
 
    msgProcessorStatusWidget(new MsgProcessorStatusWidget()),
 
133
    _msgProcessorStatusWidget(new MsgProcessorStatusWidget(this)),
 
134
    _coreConnectionStatusWidget(new CoreConnectionStatusWidget(Client::coreConnection(), this)),
128
135
    _titleSetter(this),
129
136
    _awayLog(0),
130
137
    _layoutLoaded(false)
131
138
{
132
 
#ifdef Q_WS_WIN
133
 
  dwTickCount = 0;
134
 
#endif
135
 
 
136
139
  QtUiSettings uiSettings;
137
140
  QString style = uiSettings.value("Style", QString()).toString();
138
141
  if(!style.isEmpty()) {
156
159
  connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
157
160
  connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showIgnoreList(QString)), SLOT(showIgnoreList(QString)));
158
161
 
 
162
  connect(Client::coreConnection(), SIGNAL(startCoreSetup(QVariantList)), SLOT(showCoreConfigWizard(QVariantList)));
 
163
  connect(Client::coreConnection(), SIGNAL(connectionErrorPopup(QString)), SLOT(handleCoreConnectionError(QString)));
 
164
  connect(Client::coreConnection(), SIGNAL(userAuthenticationRequired(CoreAccount *, bool *, QString)), SLOT(userAuthenticationRequired(CoreAccount *, bool *, QString)));
 
165
  connect(Client::coreConnection(), SIGNAL(handleNoSslInClient(bool*)), SLOT(handleNoSslInClient(bool *)));
 
166
  connect(Client::coreConnection(), SIGNAL(handleNoSslInCore(bool*)), SLOT(handleNoSslInCore(bool *)));
 
167
#ifdef HAVE_SSL
 
168
  connect(Client::coreConnection(), SIGNAL(handleSslErrors(const QSslSocket *, bool *, bool *)), SLOT(handleSslErrors(const QSslSocket *, bool *, bool *)));
 
169
#endif
 
170
 
159
171
  // Setup Dock Areas
160
172
  setDockNestingEnabled(true);
161
173
  setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
168
180
  setupBufferWidget();
169
181
  setupMenus();
170
182
  setupTopicWidget();
171
 
  setupChatMonitor();
172
183
  setupNickWidget();
173
184
  setupInputWidget();
 
185
  setupChatMonitor();
174
186
  setupStatusBar();
175
187
  setupToolBars();
176
188
  setupSystray();
179
191
 
180
192
#ifndef HAVE_KDE
181
193
  QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
 
194
#  ifndef QT_NO_SYSTEMTRAYICON
182
195
  QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
 
196
#  endif
183
197
#  ifdef HAVE_PHONON
184
198
  QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
185
199
#  endif
210
224
  // restore locked state of docks
211
225
  QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
212
226
 
213
 
  if(Quassel::runMode() != Quassel::Monolithic) {
214
 
    showCoreConnectionDlg(true); // autoconnect if appropriate
215
 
  } else {
216
 
    startInternalCore();
 
227
  CoreConnection *conn = Client::coreConnection();
 
228
  if(!conn->connectToCore()) {
 
229
    // No autoconnect selected (or no accounts)
 
230
    showCoreConnectionDlg();
217
231
  }
218
232
}
219
233
 
262
276
  move(_normalPos);
263
277
#endif
264
278
 
265
 
  if(s.value("MainWinHidden").toBool())
266
 
    hideToTray();
 
279
  if(s.value("MainWinHidden").toBool() && QtUi::haveSystemTray())
 
280
    QtUi::hideMainWidget();
267
281
  else if(s.value("MainWinMinimized").toBool())
268
282
    showMinimized();
269
283
  else if(maximized)
311
325
  connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockLayout_toggled(bool)));
312
326
 
313
327
  coll->addAction("ToggleSearchBar", new Action(SmallIcon("edit-find"), tr("Show &Search Bar"), coll,
314
 
                                                0, 0, QKeySequence::Find))->setCheckable(true);
 
328
                                                0, 0, QKeySequence::Find))->setCheckable(true);
315
329
  coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll,
316
 
                                            this, SLOT(showAwayLog())));
 
330
                                            this, SLOT(showAwayLog())));
317
331
  coll->addAction("ToggleMenuBar", new Action(SmallIcon("show-menu"), tr("Show &Menubar"), coll,
318
332
                                                0, 0, tr("Ctrl+M")))->setCheckable(true);
319
333
 
570
584
  dock->setObjectName("ChatMonitorDock");
571
585
 
572
586
  ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
573
 
  ChatMonitorView *chatView = new ChatMonitorView(filter, this);
574
 
  chatView->show();
575
 
  dock->setWidget(chatView);
 
587
  _chatMonitorView = new ChatMonitorView(filter, this);
 
588
  _chatMonitorView->setFocusProxy(_inputWidget);
 
589
  _chatMonitorView->show();
 
590
  dock->setWidget(_chatMonitorView);
576
591
  dock->hide();
577
592
 
578
593
  addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
598
613
  _bufferWidget->setFocusProxy(_inputWidget);
599
614
 
600
615
  _inputWidget->inputLine()->installEventFilter(_bufferWidget);
 
616
 
 
617
  connect(_topicWidget, SIGNAL(switchedPlain()), _bufferWidget, SLOT(setFocus()));
601
618
}
602
619
 
603
620
void MainWin::setupTopicWidget() {
604
621
  VerticalDock *dock = new VerticalDock(tr("Topic"), this);
605
622
  dock->setObjectName("TopicDock");
606
 
  TopicWidget *topicwidget = new TopicWidget(dock);
607
 
 
608
 
  dock->setWidget(topicwidget);
609
 
 
610
 
  topicwidget->setModel(Client::bufferModel());
611
 
  topicwidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
 
623
  _topicWidget = new TopicWidget(dock);
 
624
 
 
625
  dock->setWidget(_topicWidget);
 
626
 
 
627
  _topicWidget->setModel(Client::bufferModel());
 
628
  _topicWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
612
629
 
613
630
  addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
614
631
 
623
640
 
624
641
void MainWin::setupStatusBar() {
625
642
  // MessageProcessor progress
626
 
  statusBar()->addPermanentWidget(msgProcessorStatusWidget);
627
 
 
628
 
  // Core Lag:
629
 
  updateLagIndicator();
630
 
  statusBar()->addPermanentWidget(coreLagLabel);
631
 
  coreLagLabel->hide();
632
 
  connect(Client::signalProxy(), SIGNAL(lagUpdated(int)), this, SLOT(updateLagIndicator(int)));
633
 
 
634
 
  // SSL indicator
635
 
  sslLabel->setPixmap(QPixmap());
636
 
  statusBar()->addPermanentWidget(sslLabel);
637
 
  sslLabel->hide();
 
643
  statusBar()->addPermanentWidget(_msgProcessorStatusWidget);
 
644
 
 
645
  // Connection state
 
646
  _coreConnectionStatusWidget->update();
 
647
  statusBar()->addPermanentWidget(_coreConnectionStatusWidget);
638
648
 
639
649
  QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
640
650
 
646
656
 
647
657
  connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
648
658
  connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
 
659
 
 
660
  connect(Client::coreConnection(), SIGNAL(connectionMsg(QString)), statusBar(), SLOT(showMessage(QString)));
649
661
}
650
662
 
651
663
void MainWin::setupHotList() {
665
677
}
666
678
 
667
679
void MainWin::setupSystray() {
668
 
  _systemTray = new SystemTray(this);
 
680
#ifdef HAVE_DBUS
 
681
  _systemTray = new StatusNotifierItem(this);
 
682
#elif !defined QT_NO_SYSTEMTRAYICON
 
683
  _systemTray = new LegacySystemTray(this);
 
684
#else
 
685
  _systemTray = new SystemTray(this); // dummy
 
686
#endif
 
687
  _systemTray->init();
669
688
}
670
689
 
671
690
void MainWin::setupToolBars() {
712
731
      action->setVisible(!Client::internalCore());
713
732
  }
714
733
 
715
 
  disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
 
734
  disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
716
735
  disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
717
736
  disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
718
737
  if(!Client::internalCore()) {
719
 
    connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
 
738
    connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
720
739
    connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
721
740
    connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
722
741
  }
727
746
  else
728
747
    statusBar()->clearMessage();
729
748
 
730
 
  if(Client::signalProxy()->isSecure()) {
731
 
    sslLabel->setPixmap(SmallIcon("security-high"));
732
 
  } else {
733
 
    sslLabel->setPixmap(SmallIcon("security-low"));
734
 
  }
735
 
 
736
 
  sslLabel->setVisible(!Client::internalCore());
737
 
  coreLagLabel->setVisible(!Client::internalCore());
 
749
  _coreConnectionStatusWidget->setVisible(!Client::internalCore());
738
750
  updateIcon();
739
751
  systemTray()->setState(SystemTray::Active);
740
752
 
746
758
 
747
759
void MainWin::loadLayout() {
748
760
  QtUiSettings s;
749
 
  int accountId = Client::currentCoreAccount().toInt();
 
761
  int accountId = Client::currentCoreAccount().accountId().toInt();
750
762
  QByteArray state = s.value(QString("MainWinState-%1").arg(accountId)).toByteArray();
751
763
  if(state.isEmpty()) {
752
764
    // Make sure that the default bufferview is shown
761
773
 
762
774
void MainWin::saveLayout() {
763
775
  QtUiSettings s;
764
 
  int accountId = Client::currentCoreAccount().toInt();
 
776
  int accountId = Client::currentCoreAccount().accountId().toInt();
765
777
  if(accountId > 0) s.setValue(QString("MainWinState-%1").arg(accountId) , saveState(accountId));
766
778
}
767
779
 
768
 
void MainWin::updateLagIndicator(int lag) {
769
 
  QString text = tr("Core Lag: %1");
770
 
  if(lag == -1)
771
 
    text = text.arg('-');
772
 
  else
773
 
    text = text.arg("%1 msec").arg(lag);
774
 
  coreLagLabel->setText(text);
775
 
}
776
 
 
777
780
void MainWin::disconnectedFromCore() {
778
781
  // save core specific layout and remove bufferviews;
779
782
  saveLayout();
808
811
  coll->action("CoreInfo")->setEnabled(false);
809
812
  //_viewMenu->setEnabled(false);
810
813
  statusBar()->showMessage(tr("Not connected to core."));
811
 
  sslLabel->setPixmap(QPixmap());
812
 
  sslLabel->hide();
813
 
  updateLagIndicator();
814
 
  coreLagLabel->hide();
815
 
  if(msgProcessorStatusWidget)
816
 
    msgProcessorStatusWidget->setProgress(0, 0);
 
814
  if(_msgProcessorStatusWidget)
 
815
    _msgProcessorStatusWidget->setProgress(0, 0);
817
816
  updateIcon();
818
 
  systemTray()->setState(SystemTray::Inactive);
819
 
}
820
 
 
821
 
void MainWin::startInternalCore() {
822
 
  ClientSyncer *syncer = new ClientSyncer();
823
 
  Client::registerClientSyncer(syncer);
824
 
  connect(syncer, SIGNAL(syncFinished()), syncer, SLOT(deleteLater()), Qt::QueuedConnection);
825
 
  syncer->useInternalCore();
826
 
}
827
 
 
828
 
void MainWin::showCoreConnectionDlg(bool autoConnect) {
829
 
  CoreConnectDlg(autoConnect, this).exec();
 
817
  systemTray()->setState(SystemTray::Passive);
 
818
}
 
819
 
 
820
void MainWin::userAuthenticationRequired(CoreAccount *account, bool *valid, const QString &errorMessage) {
 
821
  Q_UNUSED(errorMessage)
 
822
  CoreConnectAuthDlg dlg(account, this);
 
823
  *valid = (dlg.exec() == QDialog::Accepted);
 
824
}
 
825
 
 
826
void MainWin::handleNoSslInClient(bool *accepted) {
 
827
  QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your client does not support SSL encryption</b>"),
 
828
                  QMessageBox::Ignore|QMessageBox::Cancel, this);
 
829
  box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
 
830
  box.setDefaultButton(QMessageBox::Ignore);
 
831
  *accepted = box.exec() == QMessageBox::Ignore;
 
832
}
 
833
 
 
834
void MainWin::handleNoSslInCore(bool *accepted) {
 
835
  QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your core does not support SSL encryption</b>"),
 
836
                  QMessageBox::Ignore|QMessageBox::Cancel, this);
 
837
  box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
 
838
  box.setDefaultButton(QMessageBox::Ignore);
 
839
  *accepted = box.exec() == QMessageBox::Ignore;
 
840
 
 
841
}
 
842
 
 
843
#ifdef HAVE_SSL
 
844
 
 
845
void MainWin::handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently) {
 
846
  QString errorString = "<ul>";
 
847
  foreach(const QSslError error, socket->sslErrors())
 
848
    errorString += QString("<li>%1</li>").arg(error.errorString());
 
849
  errorString += "</ul>";
 
850
 
 
851
  QMessageBox box(QMessageBox::Warning,
 
852
                  tr("Untrusted Security Certificate"),
 
853
                  tr("<b>The SSL certificate provided by the core at %1 is untrusted for the following reasons:</b>").arg(socket->peerName()),
 
854
                  QMessageBox::Cancel, this);
 
855
  box.setInformativeText(errorString);
 
856
  box.addButton(tr("Continue"), QMessageBox::AcceptRole);
 
857
  box.setDefaultButton(box.addButton(tr("Show Certificate"), QMessageBox::HelpRole));
 
858
 
 
859
  QMessageBox::ButtonRole role;
 
860
  do {
 
861
    box.exec();
 
862
    role = box.buttonRole(box.clickedButton());
 
863
    if(role == QMessageBox::HelpRole) {
 
864
      SslInfoDlg dlg(socket, this);
 
865
      dlg.exec();
 
866
    }
 
867
  } while(role == QMessageBox::HelpRole);
 
868
 
 
869
  *accepted = role == QMessageBox::AcceptRole;
 
870
  if(*accepted) {
 
871
    QMessageBox box2(QMessageBox::Warning,
 
872
                     tr("Untrusted Security Certificate"),
 
873
                     tr("Would you like to accept this certificate forever without being prompted?"),
 
874
                     0, this);
 
875
    box2.setDefaultButton(box2.addButton(tr("Current Session Only"), QMessageBox::NoRole));
 
876
    box2.addButton(tr("Forever"), QMessageBox::YesRole);
 
877
    box2.exec();
 
878
    *permanently =  box2.buttonRole(box2.clickedButton()) == QMessageBox::YesRole;
 
879
  }
 
880
}
 
881
 
 
882
#endif /* HAVE_SSL */
 
883
 
 
884
void MainWin::handleCoreConnectionError(const QString &error) {
 
885
  QMessageBox::critical(this, tr("Core Connection Error"), error, QMessageBox::Ok);
 
886
}
 
887
 
 
888
void MainWin::showCoreConnectionDlg() {
 
889
  CoreConnectDlg dlg(this);
 
890
  if(dlg.exec() == QDialog::Accepted) {
 
891
    AccountId accId = dlg.selectedAccount();
 
892
    if(accId.isValid())
 
893
      Client::coreConnection()->connectToCore(accId);
 
894
  }
 
895
}
 
896
 
 
897
void MainWin::showCoreConfigWizard(const QVariantList &backends) {
 
898
  CoreConfigWizard *wizard = new CoreConfigWizard(Client::coreConnection(), backends, this);
 
899
 
 
900
  wizard->show();
830
901
}
831
902
 
832
903
void MainWin::showChannelList(NetworkId netId) {
876
947
  //Category: Interface
877
948
  dlg->registerSettingsPage(new AppearanceSettingsPage(dlg));
878
949
  dlg->registerSettingsPage(new ChatViewSettingsPage(dlg));
 
950
  dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
879
951
  dlg->registerSettingsPage(new ItemViewSettingsPage(dlg));
 
952
  dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
880
953
  dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg));
881
954
  dlg->registerSettingsPage(new TopicWidgetSettingsPage(dlg));
882
955
  dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
883
956
  dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
884
957
  dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
885
 
  dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
886
 
  dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
887
958
 
888
 
  //Category: Misc
889
 
  dlg->registerSettingsPage(new GeneralSettingsPage(dlg));
 
959
  //Category: IRC
890
960
  dlg->registerSettingsPage(new ConnectionSettingsPage(dlg));
891
961
  dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
892
962
  dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
893
963
  dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
894
964
  dlg->registerSettingsPage(new IgnoreListSettingsPage(dlg));
895
965
 
 
966
  // Category: Remote Cores
 
967
  if(Quassel::runMode() != Quassel::Monolithic) {
 
968
    dlg->registerSettingsPage(new CoreAccountSettingsPage(dlg));
 
969
    dlg->registerSettingsPage(new CoreConnectionSettingsPage(dlg));
 
970
  }
 
971
 
896
972
  dlg->show();
897
973
}
898
974
 
935
1011
  QtUiSettings s;
936
1012
  QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
937
1013
  Q_ASSERT(app);
938
 
  if(!app->isAboutToQuit() && s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnClose").toBool()) {
939
 
    hideToTray();
 
1014
  if(!app->isAboutToQuit() && QtUi::haveSystemTray() && s.value("MinimizeOnClose").toBool()) {
 
1015
    QtUi::hideMainWidget();
940
1016
    event->ignore();
941
1017
  } else {
942
1018
    event->accept();
944
1020
  }
945
1021
}
946
1022
 
947
 
void MainWin::changeEvent(QEvent *event) {
948
 
#ifdef Q_WS_WIN
949
 
  if(event->type() == QEvent::ActivationChange)
950
 
    dwTickCount = GetTickCount();  // needed for toggleMinimizedToTray()
951
 
#endif
952
 
 
953
 
  QMainWindow::changeEvent(event);
954
 
}
955
 
 
956
 
void MainWin::hideToTray() {
957
 
  if(!systemTray()->isSystemTrayAvailable()) {
958
 
    qWarning() << Q_FUNC_INFO << "was called with no SystemTray available!";
959
 
    return;
960
 
  }
961
 
  hide();
962
 
  systemTray()->setIconVisible();
963
 
}
964
 
 
965
 
void MainWin::toggleMinimizedToTray() {
966
 
#ifdef Q_WS_WIN
967
 
  // the problem is that we lose focus when the systray icon is activated
968
 
  // and we don't know the former active window
969
 
  // therefore we watch for activation event and use our stopwatch :)
970
 
  // courtesy: KSystemTrayIcon
971
 
  if(GetTickCount() - dwTickCount >= 300)
972
 
    // we weren't active in the last 300ms -> activate
973
 
    forceActivated();
974
 
  else
975
 
    hideToTray();
976
 
 
977
 
#else
978
 
 
979
 
  if(!isVisible() || isMinimized())
980
 
    // restore
981
 
    forceActivated();
982
 
  else
983
 
    hideToTray();
984
 
 
985
 
#endif
986
 
}
987
 
 
988
 
void MainWin::forceActivated() {
989
 
#ifdef HAVE_KDE
990
 
  show();
991
 
  KWindowSystem::forceActiveWindow(winId());
992
 
#else
993
 
 
994
 
#ifdef Q_WS_X11
995
 
  // Bypass focus stealing prevention
996
 
  QX11Info::setAppUserTime(QX11Info::appTime());
997
 
#endif
998
 
 
999
 
  if(windowState() & Qt::WindowMinimized) {
1000
 
    // restore
1001
 
    setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
1002
 
  }
1003
 
 
1004
 
  // this does not actually work on all platforms... and causes more evil than good
1005
 
  // move(frameGeometry().topLeft()); // avoid placement policies
1006
 
  show();
1007
 
  raise();
1008
 
  activateWindow();
1009
 
#endif /* HAVE_KDE */
1010
 
}
1011
 
 
1012
1023
void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {
1013
1024
  Q_UNUSED(parent);
1014
1025