X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fmainwin.cpp;h=6867d060d879fd670f153118616202d351dcdc28;hp=df444319ffa8ab9e4047bceccf853dd0d8dcd81b;hb=6f442c275cc5a2d5f1084ac2ceca5f1ffce1d024;hpb=f02f6649c32133a86183197740d316f41f268109 diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index df444319..6867d060 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -28,6 +28,10 @@ # include #endif +#ifdef Q_WS_X11 +# include +#endif + #include "aboutdlg.h" #include "awaylogfilter.h" #include "awaylogview.h" @@ -55,6 +59,7 @@ #include "inputwidget.h" #include "inputline.h" #include "irclistmodel.h" +#include "ircconnectionwizard.h" #include "jumpkeyhandler.h" #include "msgprocessorstatuswidget.h" #include "nicklistwidget.h" @@ -88,7 +93,6 @@ #include "settingspages/bufferviewsettingspage.h" #include "settingspages/chatmonitorsettingspage.h" #include "settingspages/colorsettingspage.h" -#include "settingspages/fontssettingspage.h" #include "settingspages/generalsettingspage.h" #include "settingspages/highlightsettingspage.h" #include "settingspages/identitiessettingspage.h" @@ -108,6 +112,10 @@ MainWin::MainWin(QWidget *parent) _titleSetter(this), _awayLog(0) { +#ifdef Q_WS_WIN + dwTickCount = 0; +#endif + QtUiSettings uiSettings; QString style = uiSettings.value("Style", QString()).toString(); if(!style.isEmpty()) { @@ -516,11 +524,6 @@ void MainWin::saveStatusBarStatus(bool enabled) { void MainWin::setupSystray() { _systemTray = new SystemTray(this); - -#ifndef Q_WS_MAC - connect(systemTray(), SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(systrayActivated(QSystemTrayIcon::ActivationReason))); -#endif - } void MainWin::setupToolBars() { @@ -548,18 +551,6 @@ void MainWin::setupToolBars() { #endif } -void MainWin::changeEvent(QEvent *event) { - if(event->type() == QEvent::WindowStateChange) { - if(windowState() & Qt::WindowMinimized) { - QtUiSettings s; - if(s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnMinimize").toBool()) { - hideToTray(); - event->accept(); - } - } - } -} - void MainWin::connectedToCore() { Q_CHECK_PTR(Client::bufferViewManager()); connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int))); @@ -606,6 +597,11 @@ void MainWin::setConnectedState() { coreLagLabel->setVisible(!Client::internalCore()); updateIcon(); systemTray()->setState(SystemTray::Active); + + if(Client::networkIds().isEmpty()) { + IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet); + wizard->show(); + } } void MainWin::loadLayout() { @@ -716,20 +712,19 @@ void MainWin::showSettingsDlg() { SettingsDlg *dlg = new SettingsDlg(); //Category: Appearance - dlg->registerSettingsPage(new ColorSettingsPage(dlg)); - dlg->registerSettingsPage(new FontsSettingsPage(dlg)); dlg->registerSettingsPage(new AppearanceSettingsPage(dlg)); //General - //Category: Behaviour - dlg->registerSettingsPage(new GeneralSettingsPage(dlg)); - dlg->registerSettingsPage(new BacklogSettingsPage(dlg)); + dlg->registerSettingsPage(new ColorSettingsPage(dlg)); dlg->registerSettingsPage(new HighlightSettingsPage(dlg)); - dlg->registerSettingsPage(new AliasesSettingsPage(dlg)); dlg->registerSettingsPage(new NotificationsSettingsPage(dlg)); + dlg->registerSettingsPage(new BacklogSettingsPage(dlg)); + dlg->registerSettingsPage(new BufferViewSettingsPage(dlg)); dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg)); - //Category: General + + //Category: Misc + dlg->registerSettingsPage(new GeneralSettingsPage(dlg)); dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg)); dlg->registerSettingsPage(new NetworksSettingsPage(dlg)); - dlg->registerSettingsPage(new BufferViewSettingsPage(dlg)); + dlg->registerSettingsPage(new AliasesSettingsPage(dlg)); dlg->show(); } @@ -757,10 +752,30 @@ void MainWin::closeEvent(QCloseEvent *event) { } } -void MainWin::systrayActivated(QSystemTrayIcon::ActivationReason activationReason) { - if(activationReason == QSystemTrayIcon::Trigger) { - toggleMinimizedToTray(); +bool MainWin::event(QEvent *event) { + if(event->type() == QEvent::WindowActivate) + QtUi::closeNotifications(); + return QMainWindow::event(event); +} + +void MainWin::changeEvent(QEvent *event) { + if(event->type() == QEvent::WindowStateChange) { + if(windowState() & Qt::WindowMinimized) { + QtUiSettings s; + if(s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnMinimize").toBool()) { + hideToTray(); + event->accept(); + return; + } + } } + +#ifdef Q_WS_WIN + else if(event->type() == QEvent::ActivationChange) + dwTickCount = GetTickCount(); // needed for toggleMinimizedToTray() +#endif + + event->ignore(); } void MainWin::hideToTray() { @@ -768,22 +783,48 @@ void MainWin::hideToTray() { qWarning() << Q_FUNC_INFO << "was called with no SystemTray available!"; return; } - clearFocus(); hide(); systemTray()->setIconVisible(); } void MainWin::toggleMinimizedToTray() { +#ifdef Q_WS_WIN + // the problem is that we lose focus when the systray icon is activated + // and we don't know the former active window + // therefore we watch for activation event and use our stopwatch :) + // courtesy: KSystemTrayIcon + if(GetTickCount() - dwTickCount >= 300) + // we weren't active in the last 300ms -> activate + forceActivated(); + else + hideToTray(); + +#else + + if(!isVisible() || isMinimized()) + // restore + forceActivated(); + else + hideToTray(); + +#endif +} + +void MainWin::forceActivated() { +#ifdef Q_WS_X11 + // Bypass focus stealing prevention + QX11Info::setAppUserTime(QX11Info::appTime()); +#endif + if(windowState() & Qt::WindowMinimized) { // restore setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive); - show(); - activateWindow(); - raise(); - } else { - setWindowState((windowState() & ~Qt::WindowActive) | Qt::WindowMinimized); - hideToTray(); } + + move(frameGeometry().topLeft()); // avoid placement policies + show(); + raise(); + activateWindow(); } void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) { @@ -815,12 +856,6 @@ void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) { } } -bool MainWin::event(QEvent *event) { - if(event->type() == QEvent::WindowActivate) - QtUi::closeNotifications(); - return QMainWindow::event(event); -} - void MainWin::clientNetworkCreated(NetworkId id) { const Network *net = Client::network(id); QAction *act = new QAction(net->networkName(), this);