1 /***************************************************************************
2 * Copyright (C) 2005-09 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
24 # include <KActionCollection>
27 # include <KShortcutsDialog>
28 # include <KStatusBar>
32 #include "awaylogfilter.h"
33 #include "awaylogview.h"
35 #include "actioncollection.h"
36 #include "buffermodel.h"
37 #include "bufferview.h"
38 #include "bufferviewoverlay.h"
39 #include "bufferviewoverlayfilter.h"
40 #include "bufferwidget.h"
41 #include "channellistdlg.h"
42 #include "chatlinemodel.h"
43 #include "chatmonitorfilter.h"
44 #include "chatmonitorview.h"
47 #include "clientsyncer.h"
48 #include "clientbacklogmanager.h"
49 #include "clientbufferviewconfig.h"
50 #include "clientbufferviewmanager.h"
51 #include "coreinfodlg.h"
52 #include "coreconnectdlg.h"
53 #include "contextmenuactionprovider.h"
54 #include "debuglogwidget.h"
55 #include "debugmessagemodelfilter.h"
56 #include "iconloader.h"
57 #include "inputwidget.h"
58 #include "inputline.h"
59 #include "irclistmodel.h"
60 #include "ircconnectionwizard.h"
61 #include "jumpkeyhandler.h"
62 #include "msgprocessorstatuswidget.h"
63 #include "nicklistwidget.h"
64 #include "qtuiapplication.h"
65 #include "qtuimessageprocessor.h"
66 #include "qtuisettings.h"
67 #include "sessionsettings.h"
68 #include "settingsdlg.h"
69 #include "settingspagedlg.h"
70 #include "systemtray.h"
71 #include "toolbaractionprovider.h"
72 #include "topicwidget.h"
73 #include "verticaldock.h"
77 # include "desktopnotificationbackend.h"
80 # include "phononnotificationbackend.h"
82 # include "systraynotificationbackend.h"
83 # include "taskbarnotificationbackend.h"
85 # include "knotificationbackend.h"
88 #include "settingspages/aliasessettingspage.h"
89 #include "settingspages/appearancesettingspage.h"
90 #include "settingspages/backlogsettingspage.h"
91 #include "settingspages/bufferviewsettingspage.h"
92 #include "settingspages/chatmonitorsettingspage.h"
93 #include "settingspages/colorsettingspage.h"
94 #include "settingspages/generalsettingspage.h"
95 #include "settingspages/highlightsettingspage.h"
96 #include "settingspages/identitiessettingspage.h"
97 #include "settingspages/networkssettingspage.h"
98 #include "settingspages/notificationssettingspage.h"
100 MainWin::MainWin(QWidget *parent)
102 : KMainWindow(parent),
103 _kHelpMenu(new KHelpMenu(this, KGlobal::mainComponent().aboutData())),
105 : QMainWindow(parent),
107 coreLagLabel(new QLabel()),
108 sslLabel(new QLabel()),
109 msgProcessorStatusWidget(new MsgProcessorStatusWidget()),
113 QtUiSettings uiSettings;
114 QString style = uiSettings.value("Style", QString()).toString();
115 if(!style.isEmpty()) {
116 QApplication::setStyle(style);
119 QApplication::setQuitOnLastWindowClosed(false);
121 setWindowTitle("Quassel IRC");
122 setWindowIconText("Quassel IRC");
125 installEventFilter(new JumpKeyHandler(this));
127 QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
128 connect(app, SIGNAL(saveStateToSession(const QString&)), SLOT(saveStateToSession(const QString&)));
129 connect(app, SIGNAL(saveStateToSessionSettings(SessionSettings&)), SLOT(saveStateToSessionSettings(SessionSettings&)));
132 void MainWin::init() {
134 if(s.value("MainWinSize").isValid())
135 resize(s.value("MainWinSize").toSize());
137 resize(QSize(800, 500));
139 connect(QApplication::instance(), SIGNAL(aboutToQuit()), SLOT(saveLayout()));
140 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), SLOT(clientNetworkCreated(NetworkId)));
141 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId)));
142 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
143 SLOT(messagesInserted(const QModelIndex &, int, int)));
144 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
147 setDockNestingEnabled(true);
148 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
149 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
150 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
151 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
153 // Order is sometimes important
167 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
168 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
170 QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
173 QtUi::registerNotificationBackend(new DesktopNotificationBackend(this));
177 QtUi::registerNotificationBackend(new KNotificationBackend(this));
178 #endif /* HAVE_KDE */
180 // restore mainwin state
181 restoreState(s.value("MainWinState").toByteArray());
183 // restore locked state of docks
184 QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
186 setDisconnectedState(); // Disable menus and stuff
190 if(Quassel::runMode() != Quassel::Monolithic) {
191 showCoreConnectionDlg(true); // autoconnect if appropriate
197 MainWin::~MainWin() {
199 s.setValue("MainWinSize", size());
200 s.setValue("MainWinPos", pos());
201 s.setValue("MainWinState", saveState());
204 void MainWin::updateIcon() {
206 const int size = 128;
212 if(Client::isConnected())
213 icon = DesktopIcon("quassel", size);
215 icon = DesktopIcon("quassel_inactive", size);
217 qApp->setWindowIcon(icon);
220 void MainWin::setupActions() {
221 ActionCollection *coll = QtUi::actionCollection("General");
223 coll->addAction("ConnectCore", new Action(SmallIcon("network-connect"), tr("&Connect to Core..."), coll,
224 this, SLOT(showCoreConnectionDlg())));
225 coll->addAction("DisconnectCore", new Action(SmallIcon("network-disconnect"), tr("&Disconnect from Core"), coll,
226 Client::instance(), SLOT(disconnectFromCore())));
227 coll->addAction("CoreInfo", new Action(SmallIcon("help-about"), tr("Core &Info..."), coll,
228 this, SLOT(showCoreInfoDlg())));
229 coll->addAction("ConfigureNetworks", new Action(SmallIcon("configure"), tr("Configure &Networks..."), coll,
230 this, SLOT(on_actionConfigureNetworks_triggered())));
231 coll->addAction("Quit", new Action(SmallIcon("application-exit"), tr("&Quit"), coll,
232 qApp, SLOT(quit()), tr("Ctrl+Q")));
235 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Buffer Views..."), coll,
236 this, SLOT(on_actionConfigureViews_triggered())));
238 QAction *lockAct = coll->addAction("LockLayout", new Action(tr("&Lock Layout"), coll));
239 lockAct->setCheckable(true);
240 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockLayout_toggled(bool)));
242 coll->addAction("ToggleSearchBar", new Action(SmallIcon("edit-find"), tr("Show &Search Bar"), coll,
243 0, 0, QKeySequence::Find))->setCheckable(true);
244 coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll,
245 this, SLOT(showAwayLog())));
246 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
247 0, 0))->setCheckable(true);
250 coll->addAction("ConfigureQuassel", new Action(SmallIcon("configure"), tr("&Configure Quassel..."), coll,
251 this, SLOT(showSettingsDlg()), tr("F7")));
254 coll->addAction("AboutQuassel", new Action(SmallIcon("quassel"), tr("&About Quassel"), coll,
255 this, SLOT(showAboutDlg())));
256 coll->addAction("AboutQt", new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
257 qApp, SLOT(aboutQt())));
258 coll->addAction("DebugNetworkModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &NetworkModel"), coll,
259 this, SLOT(on_actionDebugNetworkModel_triggered())));
260 coll->addAction("DebugBufferViewOverlay", new Action(SmallIcon("tools-report-bug"), tr("Debug &BufferViewOverlay"), coll,
261 this, SLOT(on_actionDebugBufferViewOverlay_triggered())));
262 coll->addAction("DebugMessageModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &MessageModel"), coll,
263 this, SLOT(on_actionDebugMessageModel_triggered())));
264 coll->addAction("DebugLog", new Action(SmallIcon("tools-report-bug"), tr("Debug &Log"), coll,
265 this, SLOT(on_actionDebugLog_triggered())));
268 void MainWin::setupMenus() {
269 ActionCollection *coll = QtUi::actionCollection("General");
271 _fileMenu = menuBar()->addMenu(tr("&File"));
273 static const QStringList coreActions = QStringList()
274 << "ConnectCore" << "DisconnectCore" << "CoreInfo";
277 foreach(QString actionName, coreActions) {
278 coreAction = coll->action(actionName);
279 _fileMenu->addAction(coreAction);
280 flagRemoteCoreOnly(coreAction);
282 flagRemoteCoreOnly(_fileMenu->addSeparator());
284 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
285 _networksMenu->addAction(coll->action("ConfigureNetworks"));
286 _networksMenu->addSeparator();
287 _fileMenu->addSeparator();
288 _fileMenu->addAction(coll->action("Quit"));
290 _viewMenu = menuBar()->addMenu(tr("&View"));
291 _bufferViewsMenu = _viewMenu->addMenu(tr("&Buffer Views"));
292 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
293 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
294 _viewMenu->addSeparator();
295 _viewMenu->addAction(coll->action("ToggleSearchBar"));
297 coreAction = coll->action("ShowAwayLog");
298 flagRemoteCoreOnly(coreAction);
299 _viewMenu->addAction(coreAction);
301 _viewMenu->addAction(coll->action("ToggleStatusBar"));
302 _viewMenu->addSeparator();
303 _viewMenu->addAction(coll->action("LockLayout"));
305 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
307 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
308 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
310 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
312 _helpMenu = menuBar()->addMenu(tr("&Help"));
313 _helpMenu->addAction(coll->action("AboutQuassel"));
315 _helpMenu->addAction(coll->action("AboutQt"));
317 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
319 _helpMenu->addSeparator();
320 _helpDebugMenu = _helpMenu->addMenu(SmallIcon("tools-report-bug"), tr("Debug"));
321 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
322 _helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay"));
323 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
324 _helpDebugMenu->addAction(coll->action("DebugLog"));
327 void MainWin::setupBufferWidget() {
328 _bufferWidget = new BufferWidget(this);
329 _bufferWidget->setModel(Client::bufferModel());
330 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
331 setCentralWidget(_bufferWidget);
334 void MainWin::addBufferView(int bufferViewConfigId) {
335 addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
338 void MainWin::addBufferView(ClientBufferViewConfig *config) {
342 config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
343 BufferViewDock *dock = new BufferViewDock(config, this);
345 //create the view and initialize it's filter
346 BufferView *view = new BufferView(dock);
347 view->setFilteredModel(Client::bufferModel(), config);
348 view->installEventFilter(_inputWidget->inputLine()); // for key presses
351 Client::bufferModel()->synchronizeView(view);
353 dock->setWidget(view);
356 addDockWidget(Qt::LeftDockWidgetArea, dock);
357 _bufferViewsMenu->addAction(dock->toggleViewAction());
359 connect(dock->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(bufferViewToggled(bool)));
360 _bufferViews.append(dock);
363 void MainWin::removeBufferView(int bufferViewConfigId) {
365 BufferViewDock *dock;
366 foreach(QAction *action, _bufferViewsMenu->actions()) {
367 actionData = action->data();
368 if(!actionData.isValid())
371 dock = qobject_cast<BufferViewDock *>(action->parent());
372 if(dock && actionData.toInt() == bufferViewConfigId) {
373 removeAction(action);
379 void MainWin::bufferViewToggled(bool enabled) {
380 QAction *action = qobject_cast<QAction *>(sender());
382 BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
385 Client::bufferViewOverlay()->addView(dock->bufferViewId());
386 BufferViewConfig *config = dock->config();
387 if(config && config->isInitialized()) {
388 BufferIdList buffers;
389 if(config->networkId().isValid()) {
390 foreach(BufferId bufferId, config->bufferList()) {
391 if(Client::networkModel()->networkId(bufferId) == config->networkId())
394 foreach(BufferId bufferId, config->temporarilyRemovedBuffers().toList()) {
395 if(Client::networkModel()->networkId(bufferId) == config->networkId())
399 buffers = BufferIdList::fromSet(config->bufferList().toSet() + config->temporarilyRemovedBuffers());
401 Client::backlogManager()->checkForBacklog(buffers);
404 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
408 BufferView *MainWin::allBuffersView() const {
409 // "All Buffers" is always the first dock created
410 if(_bufferViews.count() > 0)
411 return _bufferViews[0]->bufferView();
415 void MainWin::showNotificationsDlg() {
416 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
420 void MainWin::on_actionConfigureNetworks_triggered() {
421 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
425 void MainWin::on_actionConfigureViews_triggered() {
426 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
430 void MainWin::on_actionLockLayout_toggled(bool lock) {
431 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
432 foreach(VerticalDock *dock, docks) {
433 dock->showTitle(!lock);
435 if(Client::bufferViewManager()) {
436 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
437 config->setLocked(lock);
440 QtUiSettings().setValue("LockLayout", lock);
443 void MainWin::setupNickWidget() {
445 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
446 nickDock->setObjectName("NickDock");
447 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
449 _nickListWidget = new NickListWidget(nickDock);
450 nickDock->setWidget(_nickListWidget);
452 addDockWidget(Qt::RightDockWidgetArea, nickDock);
453 _viewMenu->addAction(nickDock->toggleViewAction());
454 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
456 // See NickListDock::NickListDock();
457 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
459 // attach the NickListWidget to the BufferModel and the default selection
460 _nickListWidget->setModel(Client::bufferModel());
461 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
464 void MainWin::setupChatMonitor() {
465 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
466 dock->setObjectName("ChatMonitorDock");
468 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
469 ChatMonitorView *chatView = new ChatMonitorView(filter, this);
471 dock->setWidget(chatView);
474 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
475 _viewMenu->addAction(dock->toggleViewAction());
476 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
479 void MainWin::setupInputWidget() {
480 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
481 dock->setObjectName("InputDock");
483 _inputWidget = new InputWidget(dock);
484 dock->setWidget(_inputWidget);
486 addDockWidget(Qt::BottomDockWidgetArea, dock);
488 _viewMenu->addAction(dock->toggleViewAction());
489 dock->toggleViewAction()->setText(tr("Show Input Line"));
491 _inputWidget->setModel(Client::bufferModel());
492 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
494 _bufferWidget->setFocusProxy(_inputWidget);
496 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
499 void MainWin::setupTopicWidget() {
500 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
501 dock->setObjectName("TopicDock");
502 TopicWidget *topicwidget = new TopicWidget(dock);
504 dock->setWidget(topicwidget);
506 topicwidget->setModel(Client::bufferModel());
507 topicwidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
509 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
511 _viewMenu->addAction(dock->toggleViewAction());
512 dock->toggleViewAction()->setText(tr("Show Topic Line"));
515 void MainWin::setupTitleSetter() {
516 _titleSetter.setModel(Client::bufferModel());
517 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
520 void MainWin::setupStatusBar() {
521 // MessageProcessor progress
522 statusBar()->addPermanentWidget(msgProcessorStatusWidget);
525 updateLagIndicator();
526 statusBar()->addPermanentWidget(coreLagLabel);
527 coreLagLabel->hide();
528 connect(Client::signalProxy(), SIGNAL(lagUpdated(int)), this, SLOT(updateLagIndicator(int)));
531 sslLabel->setPixmap(QPixmap());
532 statusBar()->addPermanentWidget(sslLabel);
535 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
537 QtUiSettings uiSettings;
539 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
540 showStatusbar->setChecked(enabled);
541 enabled ? statusBar()->show() : statusBar()->hide();
543 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
544 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
547 void MainWin::saveStatusBarStatus(bool enabled) {
548 QtUiSettings uiSettings;
549 uiSettings.setValue("ShowStatusBar", enabled);
552 void MainWin::setupSystray() {
553 _systemTray = new SystemTray(this);
556 connect(systemTray(), SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(systrayActivated(QSystemTrayIcon::ActivationReason)));
561 void MainWin::setupToolBars() {
562 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
563 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
564 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
565 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
568 setUnifiedTitleAndToolBarOnMac(true);
570 _mainToolBar = addToolBar("Main Toolbar");
571 _mainToolBar->setObjectName("MainToolBar");
573 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
574 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
576 //_nickToolBar = addToolBar("User");
577 //_nickToolBar->setObjectName("NickToolBar");
578 //QtUi::toolBarActionProvider()->addActions(_nickToolBar, ToolBarActionProvider::NickToolBar);
581 _mainToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
582 //_nickToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
586 void MainWin::changeEvent(QEvent *event) {
587 if(event->type() == QEvent::WindowStateChange) {
588 if(windowState() & Qt::WindowMinimized) {
590 if(s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnMinimize").toBool()) {
598 void MainWin::connectedToCore() {
599 Q_CHECK_PTR(Client::bufferViewManager());
600 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
601 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
602 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
607 void MainWin::setConnectedState() {
608 ActionCollection *coll = QtUi::actionCollection("General");
610 coll->action("ConnectCore")->setEnabled(false);
611 coll->action("DisconnectCore")->setEnabled(true);
612 coll->action("CoreInfo")->setEnabled(true);
614 foreach(QAction *action, _fileMenu->actions()) {
615 if(isRemoteCoreOnly(action))
616 action->setVisible(!Client::internalCore());
619 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
620 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
621 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
622 if(!Client::internalCore()) {
623 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
624 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
625 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
628 // _viewMenu->setEnabled(true);
629 if(!Client::internalCore())
630 statusBar()->showMessage(tr("Connected to core."));
632 statusBar()->clearMessage();
634 if(Client::signalProxy()->isSecure()) {
635 sslLabel->setPixmap(SmallIcon("security-high"));
637 sslLabel->setPixmap(SmallIcon("security-low"));
640 sslLabel->setVisible(!Client::internalCore());
641 coreLagLabel->setVisible(!Client::internalCore());
643 systemTray()->setState(SystemTray::Active);
645 if(Client::networkIds().isEmpty()) {
646 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
651 void MainWin::loadLayout() {
653 int accountId = Client::currentCoreAccount().toInt();
654 restoreState(s.value(QString("MainWinState-%1").arg(accountId)).toByteArray(), accountId);
657 void MainWin::saveLayout() {
659 int accountId = Client::currentCoreAccount().toInt();
660 if(accountId > 0) s.setValue(QString("MainWinState-%1").arg(accountId) , saveState(accountId));
663 void MainWin::updateLagIndicator(int lag) {
664 QString text = tr("Core Lag: %1");
666 text = text.arg('-');
668 text = text.arg("%1 msec").arg(lag);
669 coreLagLabel->setText(text);
672 void MainWin::disconnectedFromCore() {
673 // save core specific layout and remove bufferviews;
676 BufferViewDock *dock;
677 foreach(QAction *action, _bufferViewsMenu->actions()) {
678 actionData = action->data();
679 if(!actionData.isValid())
682 dock = qobject_cast<BufferViewDock *>(action->parent());
683 if(dock && actionData.toInt() != -1) {
684 removeAction(action);
689 restoreState(s.value("MainWinState").toByteArray());
690 setDisconnectedState();
693 void MainWin::setDisconnectedState() {
694 ActionCollection *coll = QtUi::actionCollection("General");
695 //ui.menuCore->setEnabled(false);
696 coll->action("ConnectCore")->setEnabled(true);
697 coll->action("DisconnectCore")->setEnabled(false);
698 coll->action("CoreInfo")->setEnabled(false);
699 //_viewMenu->setEnabled(false);
700 statusBar()->showMessage(tr("Not connected to core."));
701 sslLabel->setPixmap(QPixmap());
703 updateLagIndicator();
704 coreLagLabel->hide();
705 if(msgProcessorStatusWidget)
706 msgProcessorStatusWidget->setProgress(0, 0);
708 systemTray()->setState(SystemTray::Inactive);
711 void MainWin::startInternalCore() {
712 ClientSyncer *syncer = new ClientSyncer();
713 Client::registerClientSyncer(syncer);
714 connect(syncer, SIGNAL(syncFinished()), syncer, SLOT(deleteLater()), Qt::QueuedConnection);
715 syncer->useInternalCore();
718 void MainWin::showCoreConnectionDlg(bool autoConnect) {
719 CoreConnectDlg(autoConnect, this).exec();
722 void MainWin::showChannelList(NetworkId netId) {
723 ChannelListDlg *channelListDlg = new ChannelListDlg();
725 if(!netId.isValid()) {
726 QAction *action = qobject_cast<QAction *>(sender());
728 netId = action->data().value<NetworkId>();
731 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
732 channelListDlg->setNetwork(netId);
733 channelListDlg->show();
736 void MainWin::showCoreInfoDlg() {
737 CoreInfoDlg(this).exec();
740 void MainWin::showAwayLog() {
743 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
744 _awayLog = new AwayLogView(filter, 0);
745 filter->setParent(_awayLog);
746 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
747 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
751 void MainWin::awayLogDestroyed() {
755 void MainWin::showSettingsDlg() {
756 SettingsDlg *dlg = new SettingsDlg();
758 //Category: Appearance
759 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg)); //General
760 dlg->registerSettingsPage(new ColorSettingsPage(dlg));
761 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
762 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
763 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
764 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
765 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
768 dlg->registerSettingsPage(new GeneralSettingsPage(dlg));
769 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
770 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
771 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
776 void MainWin::showAboutDlg() {
777 AboutDlg(this).exec();
781 void MainWin::showShortcutsDlg() {
782 KShortcutsDialog::configure(QtUi::actionCollection("General"), KShortcutsEditor::LetterShortcutsDisallowed);
786 void MainWin::closeEvent(QCloseEvent *event) {
788 QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
790 if(!app->aboutToQuit() && s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnClose").toBool()) {
791 toggleMinimizedToTray();
795 QApplication::quit();
799 void MainWin::systrayActivated(QSystemTrayIcon::ActivationReason activationReason) {
800 if(activationReason == QSystemTrayIcon::Trigger) {
801 toggleMinimizedToTray();
805 void MainWin::hideToTray() {
806 if(!systemTray()->isSystemTrayAvailable()) {
807 qWarning() << Q_FUNC_INFO << "was called with no SystemTray available!";
812 systemTray()->setIconVisible();
815 void MainWin::toggleMinimizedToTray() {
816 if(windowState() & Qt::WindowMinimized) {
818 setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
823 setWindowState((windowState() & ~Qt::WindowActive) | Qt::WindowMinimized);
828 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {
831 if(QApplication::activeWindow() != 0)
834 for(int i = start; i <= end; i++) {
835 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
837 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
840 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
841 if(flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self)) continue;
842 flags |= Message::Backlog; // we only want to trigger a highlight once!
843 Client::messageModel()->setData(idx, (int)flags, ChatLineModel::FlagsRole);
845 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
846 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
848 if(flags & Message::Highlight || bufType == BufferInfo::QueryBuffer) {
849 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
850 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
851 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
852 QtUi::invokeNotification(bufId, sender, contents);
857 bool MainWin::event(QEvent *event) {
858 if(event->type() == QEvent::WindowActivate)
859 QtUi::closeNotifications();
860 return QMainWindow::event(event);
863 void MainWin::clientNetworkCreated(NetworkId id) {
864 const Network *net = Client::network(id);
865 QAction *act = new QAction(net->networkName(), this);
866 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
867 act->setData(QVariant::fromValue<NetworkId>(id));
868 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
869 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
871 QAction *beforeAction = 0;
872 foreach(QAction *action, _networksMenu->actions()) {
873 if(!action->data().isValid()) // ignore stock actions
875 if(net->networkName().localeAwareCompare(action->text()) < 0) {
876 beforeAction = action;
880 _networksMenu->insertAction(beforeAction, act);
883 void MainWin::clientNetworkUpdated() {
884 const Network *net = qobject_cast<const Network *>(sender());
888 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
892 action->setText(net->networkName());
894 switch(net->connectionState()) {
895 case Network::Initialized:
896 action->setIcon(SmallIcon("network-connect"));
898 case Network::Disconnected:
899 action->setIcon(SmallIcon("network-disconnect"));
902 action->setIcon(SmallIcon("network-wired"));
906 void MainWin::clientNetworkRemoved(NetworkId id) {
907 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
911 action->deleteLater();
914 void MainWin::connectOrDisconnectFromNet() {
915 QAction *act = qobject_cast<QAction *>(sender());
917 const Network *net = Client::network(act->data().value<NetworkId>());
919 if(net->connectionState() == Network::Disconnected) net->requestConnect();
920 else net->requestDisconnect();
923 void MainWin::on_actionDebugNetworkModel_triggered() {
924 QTreeView *view = new QTreeView;
925 view->setAttribute(Qt::WA_DeleteOnClose);
926 view->setWindowTitle("Debug NetworkModel View");
927 view->setModel(Client::networkModel());
928 view->setColumnWidth(0, 250);
929 view->setColumnWidth(1, 250);
930 view->setColumnWidth(2, 80);
931 view->resize(610, 300);
935 void MainWin::on_actionDebugBufferViewOverlay_triggered() {
936 QTreeView *view = new QTreeView;
937 view->setAttribute(Qt::WA_DeleteOnClose);
938 view->setWindowTitle("Debug BufferViewOverlay View");
939 BufferViewOverlayFilter *filter = new BufferViewOverlayFilter(Client::bufferModel(), Client::bufferViewOverlay());
940 filter->setParent(view);
941 view->setModel(filter);
942 view->setColumnWidth(0, 250);
943 view->setColumnWidth(1, 250);
944 view->setColumnWidth(2, 80);
945 view->resize(610, 300);
949 void MainWin::on_actionDebugMessageModel_triggered() {
950 QTableView *view = new QTableView(0);
951 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
952 filter->setSourceModel(Client::messageModel());
953 view->setModel(filter);
954 view->setAttribute(Qt::WA_DeleteOnClose, true);
955 view->verticalHeader()->hide();
956 view->horizontalHeader()->setStretchLastSection(true);
960 void MainWin::on_actionDebugLog_triggered() {
961 DebugLogWidget *logWidget = new DebugLogWidget(0);
965 void MainWin::saveStateToSession(const QString &sessionId) {
967 SessionSettings s(sessionId);
969 s.setValue("MainWinSize", size());
970 s.setValue("MainWinPos", pos());
971 s.setValue("MainWinState", saveState());
974 void MainWin::saveStateToSessionSettings(SessionSettings & s)
976 s.setValue("MainWinSize", size());
977 s.setValue("MainWinPos", pos());
978 s.setValue("MainWinState", saveState());
981 void MainWin::showStatusBarMessage(const QString &message) {
982 statusBar()->showMessage(message, 10000);