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 "bufferviewmanager.h"
39 #include "bufferwidget.h"
40 #include "channellistdlg.h"
41 #include "chatlinemodel.h"
42 #include "chatmonitorfilter.h"
43 #include "chatmonitorview.h"
46 #include "clientsyncer.h"
47 #include "clientbacklogmanager.h"
48 #include "coreinfodlg.h"
49 #include "coreconnectdlg.h"
50 #include "contextmenuactionprovider.h"
51 #include "debuglogwidget.h"
52 #include "debugmessagemodelfilter.h"
53 #include "iconloader.h"
54 #include "inputwidget.h"
55 #include "inputline.h"
56 #include "irclistmodel.h"
57 #include "jumpkeyhandler.h"
58 #include "msgprocessorstatuswidget.h"
59 #include "nicklistwidget.h"
60 #include "qtuiapplication.h"
61 #include "qtuimessageprocessor.h"
62 #include "qtuisettings.h"
63 #include "sessionsettings.h"
64 #include "settingsdlg.h"
65 #include "settingspagedlg.h"
66 #include "topicwidget.h"
67 #include "verticaldock.h"
71 # include "desktopnotificationbackend.h"
74 # include "phononnotificationbackend.h"
76 # include "systraynotificationbackend.h"
77 # include "taskbarnotificationbackend.h"
79 # include "knotificationbackend.h"
82 #include "settingspages/aliasessettingspage.h"
83 #include "settingspages/appearancesettingspage.h"
84 #include "settingspages/backlogsettingspage.h"
85 #include "settingspages/bufferviewsettingspage.h"
86 #include "settingspages/chatmonitorsettingspage.h"
87 #include "settingspages/colorsettingspage.h"
88 #include "settingspages/fontssettingspage.h"
89 #include "settingspages/generalsettingspage.h"
90 #include "settingspages/highlightsettingspage.h"
91 #include "settingspages/identitiessettingspage.h"
92 #include "settingspages/networkssettingspage.h"
93 #include "settingspages/notificationssettingspage.h"
95 MainWin::MainWin(QWidget *parent)
97 : KMainWindow(parent),
98 _kHelpMenu(new KHelpMenu(this, KGlobal::mainComponent().aboutData())),
100 : QMainWindow(parent),
102 coreLagLabel(new QLabel()),
103 sslLabel(new QLabel()),
104 msgProcessorStatusWidget(new MsgProcessorStatusWidget()),
106 _trayIcon(new QSystemTrayIcon(this)),
109 QtUiSettings uiSettings;
110 QString style = uiSettings.value("Style", QString()).toString();
111 if(!style.isEmpty()) {
112 QApplication::setStyle(style);
115 QApplication::setQuitOnLastWindowClosed(false);
117 setWindowTitle("Quassel IRC");
118 setWindowIconText("Quassel IRC");
121 installEventFilter(new JumpKeyHandler(this));
123 QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
124 connect(app, SIGNAL(saveStateToSession(const QString&)), SLOT(saveStateToSession(const QString&)));
125 connect(app, SIGNAL(saveStateToSessionSettings(SessionSettings&)), SLOT(saveStateToSessionSettings(SessionSettings&)));
128 void MainWin::init() {
130 if(s.value("MainWinSize").isValid())
131 resize(s.value("MainWinSize").toSize());
133 resize(QSize(800, 500));
135 connect(QApplication::instance(), SIGNAL(aboutToQuit()), SLOT(saveLayout()));
136 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), SLOT(clientNetworkCreated(NetworkId)));
137 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId)));
138 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
141 setDockNestingEnabled(true);
142 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
143 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
144 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
145 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
147 // Order is sometimes important
160 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
161 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
163 QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
166 QtUi::registerNotificationBackend(new DesktopNotificationBackend(this));
170 QtUi::registerNotificationBackend(new KNotificationBackend(this));
171 #endif /* HAVE_KDE */
173 // restore mainwin state
174 restoreState(s.value("MainWinState").toByteArray());
176 // restore locked state of docks
177 QtUi::actionCollection("General")->action("LockDockPositions")->setChecked(s.value("LockDocks", false).toBool());
179 setDisconnectedState(); // Disable menus and stuff
182 if(Quassel::runMode() != Quassel::Monolithic) {
183 showCoreConnectionDlg(true); // autoconnect if appropriate
189 MainWin::~MainWin() {
191 s.setValue("MainWinSize", size());
192 s.setValue("MainWinPos", pos());
193 s.setValue("MainWinState", saveState());
196 void MainWin::updateIcon() {
198 if(Client::isConnected())
199 icon = DesktopIcon("quassel", IconLoader::SizeEnormous);
201 icon = DesktopIcon("quassel_disconnected", IconLoader::SizeEnormous);
203 qApp->setWindowIcon(icon);
204 systemTrayIcon()->setIcon(icon);
207 void MainWin::setupActions() {
208 ActionCollection *coll = QtUi::actionCollection("General");
210 coll->addAction("ConnectCore", new Action(SmallIcon("network-connect"), tr("&Connect to Core..."), coll,
211 this, SLOT(showCoreConnectionDlg())));
212 coll->addAction("DisconnectCore", new Action(SmallIcon("network-disconnect"), tr("&Disconnect from Core"), coll,
213 Client::instance(), SLOT(disconnectFromCore())));
214 coll->addAction("CoreInfo", new Action(SmallIcon("help-about"), tr("Core &Info..."), coll,
215 this, SLOT(showCoreInfoDlg())));
216 coll->addAction("ConfigureNetworks", new Action(SmallIcon("configure"), tr("Configure &Networks..."), coll,
217 this, SLOT(on_actionConfigureNetworks_triggered())));
218 coll->addAction("Quit", new Action(SmallIcon("application-exit"), tr("&Quit"), coll,
219 qApp, SLOT(quit()), tr("Ctrl+Q")));
222 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Buffer Views..."), coll,
223 this, SLOT(on_actionConfigureViews_triggered())));
224 QAction *lockAct = coll->addAction("LockDockPositions", new Action(tr("&Lock Dock Positions"), coll));
225 lockAct->setCheckable(true);
226 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockDockPositions_toggled(bool)));
228 coll->addAction("ToggleSearchBar", new Action(SmallIcon("edit-find"), tr("Show &Search Bar"), coll,
229 0, 0, tr("Ctrl+F")))->setCheckable(true);
230 coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll,
231 this, SLOT(showAwayLog())));
232 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
233 0, 0))->setCheckable(true);
236 coll->addAction("ConfigureQuassel", new Action(SmallIcon("configure"), tr("&Configure Quassel..."), coll,
237 this, SLOT(showSettingsDlg()), tr("F7")));
240 coll->addAction("AboutQuassel", new Action(SmallIcon("quassel"), tr("&About Quassel"), coll,
241 this, SLOT(showAboutDlg())));
242 coll->addAction("AboutQt", new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
243 qApp, SLOT(aboutQt())));
244 coll->addAction("DebugNetworkModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &NetworkModel"), coll,
245 this, SLOT(on_actionDebugNetworkModel_triggered())));
246 coll->addAction("DebugMessageModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &MessageModel"), coll,
247 this, SLOT(on_actionDebugMessageModel_triggered())));
248 coll->addAction("DebugLog", new Action(SmallIcon("tools-report-bug"), tr("Debug &Log"), coll,
249 this, SLOT(on_actionDebugLog_triggered())));
252 void MainWin::setupMenus() {
253 ActionCollection *coll = QtUi::actionCollection("General");
255 _fileMenu = menuBar()->addMenu(tr("&File"));
257 static const QStringList coreActions = QStringList()
258 << "ConnectCore" << "DisconnectCore" << "CoreInfo";
261 foreach(QString actionName, coreActions) {
262 coreAction = coll->action(actionName);
263 _fileMenu->addAction(coreAction);
264 flagRemoteCoreOnly(coreAction);
266 flagRemoteCoreOnly(_fileMenu->addSeparator());
268 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
269 _networksMenu->addAction(coll->action("ConfigureNetworks"));
270 _networksMenu->addSeparator();
271 _fileMenu->addSeparator();
272 _fileMenu->addAction(coll->action("Quit"));
274 _viewMenu = menuBar()->addMenu(tr("&View"));
275 _bufferViewsMenu = _viewMenu->addMenu(tr("&Buffer Views"));
276 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
277 _viewMenu->addSeparator();
278 _viewMenu->addAction(coll->action("ToggleSearchBar"));
280 coreAction = coll->action("ShowAwayLog");
281 flagRemoteCoreOnly(coreAction);
282 _viewMenu->addAction(coreAction);
284 _viewMenu->addAction(coll->action("ToggleStatusBar"));
285 _viewMenu->addSeparator();
286 _viewMenu->addAction(coll->action("LockDockPositions"));
288 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
290 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
291 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
293 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
295 _helpMenu = menuBar()->addMenu(tr("&Help"));
296 _helpMenu->addAction(coll->action("AboutQuassel"));
298 _helpMenu->addAction(coll->action("AboutQt"));
300 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
302 _helpMenu->addSeparator();
303 _helpDebugMenu = _helpMenu->addMenu(SmallIcon("tools-report-bug"), tr("Debug"));
304 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
305 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
306 _helpDebugMenu->addAction(coll->action("DebugLog"));
309 void MainWin::setupBufferWidget() {
310 _bufferWidget = new BufferWidget(this);
311 _bufferWidget->setModel(Client::bufferModel());
312 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
313 setCentralWidget(_bufferWidget);
316 void MainWin::addBufferView(int bufferViewConfigId) {
317 addBufferView(Client::bufferViewManager()->bufferViewConfig(bufferViewConfigId));
320 void MainWin::addBufferView(BufferViewConfig *config) {
324 BufferViewDock *dock = new BufferViewDock(config, this);
326 //create the view and initialize it's filter
327 BufferView *view = new BufferView(dock);
328 view->setFilteredModel(Client::bufferModel(), config);
329 view->installEventFilter(_inputWidget->inputLine()); // for key presses
332 Client::bufferModel()->synchronizeView(view);
334 dock->setWidget(view);
337 addDockWidget(Qt::LeftDockWidgetArea, dock);
338 _bufferViewsMenu->addAction(dock->toggleViewAction());
340 _bufferViews.append(dock);
343 void MainWin::removeBufferView(int bufferViewConfigId) {
345 BufferViewDock *dock;
346 foreach(QAction *action, _bufferViewsMenu->actions()) {
347 actionData = action->data();
348 if(!actionData.isValid())
351 dock = qobject_cast<BufferViewDock *>(action->parent());
352 if(dock && actionData.toInt() == bufferViewConfigId) {
353 removeAction(action);
359 BufferView *MainWin::allBuffersView() const {
360 // "All Buffers" is always the first dock created
361 if(_bufferViews.count() > 0)
362 return _bufferViews[0]->bufferView();
366 void MainWin::showNotificationsDlg() {
367 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
371 void MainWin::on_actionConfigureNetworks_triggered() {
372 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
376 void MainWin::on_actionConfigureViews_triggered() {
377 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
381 void MainWin::on_actionLockDockPositions_toggled(bool lock) {
382 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
383 foreach(VerticalDock *dock, docks) {
384 dock->showTitle(!lock);
386 QtUiSettings().setValue("LockDocks", lock);
389 void MainWin::setupNickWidget() {
391 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
392 nickDock->setObjectName("NickDock");
393 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
395 _nickListWidget = new NickListWidget(nickDock);
396 nickDock->setWidget(_nickListWidget);
398 addDockWidget(Qt::RightDockWidgetArea, nickDock);
399 _viewMenu->addAction(nickDock->toggleViewAction());
400 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
401 nickDock->toggleViewAction()->setIcon(SmallIcon("view-sidetree"));
402 // See NickListDock::NickListDock();
403 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
405 // attach the NickListWidget to the BufferModel and the default selection
406 _nickListWidget->setModel(Client::bufferModel());
407 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
410 void MainWin::setupChatMonitor() {
411 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
412 dock->setObjectName("ChatMonitorDock");
414 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
415 ChatMonitorView *chatView = new ChatMonitorView(filter, this);
417 dock->setWidget(chatView);
420 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
421 _viewMenu->addAction(dock->toggleViewAction());
422 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
425 void MainWin::setupInputWidget() {
426 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
427 dock->setObjectName("InputDock");
429 _inputWidget = new InputWidget(dock);
430 dock->setWidget(_inputWidget);
432 addDockWidget(Qt::BottomDockWidgetArea, dock);
434 _viewMenu->addAction(dock->toggleViewAction());
435 dock->toggleViewAction()->setText(tr("Show Input Line"));
437 _inputWidget->setModel(Client::bufferModel());
438 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
440 _bufferWidget->setFocusProxy(_inputWidget);
442 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
445 void MainWin::setupTopicWidget() {
446 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
447 dock->setObjectName("TopicDock");
448 TopicWidget *topicwidget = new TopicWidget(dock);
450 dock->setWidget(topicwidget);
452 topicwidget->setModel(Client::bufferModel());
453 topicwidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
455 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
457 _viewMenu->addAction(dock->toggleViewAction());
458 dock->toggleViewAction()->setText(tr("Show Topic Line"));
461 void MainWin::setupTitleSetter() {
462 _titleSetter.setModel(Client::bufferModel());
463 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
466 void MainWin::setupStatusBar() {
467 // MessageProcessor progress
468 statusBar()->addPermanentWidget(msgProcessorStatusWidget);
471 updateLagIndicator();
472 statusBar()->addPermanentWidget(coreLagLabel);
473 coreLagLabel->hide();
474 connect(Client::signalProxy(), SIGNAL(lagUpdated(int)), this, SLOT(updateLagIndicator(int)));
477 sslLabel->setPixmap(QPixmap());
478 statusBar()->addPermanentWidget(sslLabel);
481 _viewMenu->addSeparator();
482 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
484 QtUiSettings uiSettings;
486 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
487 showStatusbar->setChecked(enabled);
488 enabled ? statusBar()->show() : statusBar()->hide();
490 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
491 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
494 void MainWin::saveStatusBarStatus(bool enabled) {
495 QtUiSettings uiSettings;
496 uiSettings.setValue("ShowStatusBar", enabled);
499 void MainWin::setupSystray() {
500 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
501 SLOT(messagesInserted(const QModelIndex &, int, int)));
503 ActionCollection *coll = QtUi::actionCollection("General");
504 systrayMenu = new QMenu(this);
505 systrayMenu->addAction(coll->action("ConnectCore"));
506 systrayMenu->addAction(coll->action("DisconnectCore"));
507 systrayMenu->addAction(coll->action("CoreInfo"));
508 systrayMenu->addSeparator();
509 systrayMenu->addAction(coll->action("Quit"));
511 systemTrayIcon()->setContextMenu(systrayMenu);
514 if(s.value("UseSystemTrayIcon", QVariant(true)).toBool()) {
515 systemTrayIcon()->show();
519 connect(systemTrayIcon(), SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(systrayActivated(QSystemTrayIcon::ActivationReason)));
523 void MainWin::changeEvent(QEvent *event) {
524 if(event->type() == QEvent::WindowStateChange) {
525 if(windowState() & Qt::WindowMinimized) {
527 if(s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnMinimize").toBool()) {
535 void MainWin::connectedToCore() {
536 Q_CHECK_PTR(Client::bufferViewManager());
537 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
538 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
539 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
544 void MainWin::setConnectedState() {
545 ActionCollection *coll = QtUi::actionCollection("General");
547 coll->action("ConnectCore")->setEnabled(false);
548 coll->action("DisconnectCore")->setEnabled(true);
549 coll->action("CoreInfo")->setEnabled(true);
551 foreach(QAction *action, _fileMenu->actions()) {
552 if(isRemoteCoreOnly(action))
553 action->setVisible(!Client::internalCore());
556 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
557 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
558 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
559 if(!Client::internalCore()) {
560 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int)));
561 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
562 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
565 // _viewMenu->setEnabled(true);
566 if(!Client::internalCore())
567 statusBar()->showMessage(tr("Connected to core."));
569 if(Client::signalProxy()->isSecure()) {
570 sslLabel->setPixmap(SmallIcon("security-high"));
572 sslLabel->setPixmap(SmallIcon("security-low"));
575 sslLabel->setVisible(!Client::internalCore());
576 coreLagLabel->setVisible(!Client::internalCore());
580 void MainWin::loadLayout() {
582 int accountId = Client::currentCoreAccount().toInt();
583 restoreState(s.value(QString("MainWinState-%1").arg(accountId)).toByteArray(), accountId);
586 void MainWin::saveLayout() {
588 int accountId = Client::currentCoreAccount().toInt();
589 if(accountId > 0) s.setValue(QString("MainWinState-%1").arg(accountId) , saveState(accountId));
592 void MainWin::updateLagIndicator(int lag) {
593 QString text = tr("Core Lag: %1");
595 text = text.arg('-');
597 text = text.arg("%1 msec").arg(lag);
598 coreLagLabel->setText(text);
601 void MainWin::disconnectedFromCore() {
602 // save core specific layout and remove bufferviews;
605 BufferViewDock *dock;
606 foreach(QAction *action, _bufferViewsMenu->actions()) {
607 actionData = action->data();
608 if(!actionData.isValid())
611 dock = qobject_cast<BufferViewDock *>(action->parent());
612 if(dock && actionData.toInt() != -1) {
613 removeAction(action);
618 restoreState(s.value("MainWinState").toByteArray());
619 setDisconnectedState();
622 void MainWin::setDisconnectedState() {
623 ActionCollection *coll = QtUi::actionCollection("General");
624 //ui.menuCore->setEnabled(false);
625 coll->action("ConnectCore")->setEnabled(true);
626 coll->action("DisconnectCore")->setEnabled(false);
627 coll->action("CoreInfo")->setEnabled(false);
628 //_viewMenu->setEnabled(false);
629 statusBar()->showMessage(tr("Not connected to core."));
630 sslLabel->setPixmap(QPixmap());
632 updateLagIndicator();
633 coreLagLabel->hide();
637 void MainWin::startInternalCore() {
638 ClientSyncer *syncer = new ClientSyncer();
639 Client::registerClientSyncer(syncer);
640 connect(syncer, SIGNAL(syncFinished()), syncer, SLOT(deleteLater()), Qt::QueuedConnection);
641 syncer->useInternalCore();
644 void MainWin::showCoreConnectionDlg(bool autoConnect) {
645 CoreConnectDlg(autoConnect, this).exec();
648 void MainWin::showChannelList(NetworkId netId) {
649 ChannelListDlg *channelListDlg = new ChannelListDlg();
651 if(!netId.isValid()) {
652 QAction *action = qobject_cast<QAction *>(sender());
654 netId = action->data().value<NetworkId>();
657 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
658 channelListDlg->setNetwork(netId);
659 channelListDlg->show();
662 void MainWin::showCoreInfoDlg() {
663 CoreInfoDlg(this).exec();
666 void MainWin::showAwayLog() {
669 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
670 _awayLog = new AwayLogView(filter, 0);
671 filter->setParent(_awayLog);
672 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
673 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
677 void MainWin::awayLogDestroyed() {
681 void MainWin::showSettingsDlg() {
682 SettingsDlg *dlg = new SettingsDlg();
684 //Category: Appearance
685 dlg->registerSettingsPage(new ColorSettingsPage(dlg));
686 dlg->registerSettingsPage(new FontsSettingsPage(dlg));
687 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg)); //General
688 //Category: Behaviour
689 dlg->registerSettingsPage(new GeneralSettingsPage(dlg));
690 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
691 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
692 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
693 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
694 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
696 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
697 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
698 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
703 void MainWin::showAboutDlg() {
704 AboutDlg(this).exec();
708 void MainWin::showShortcutsDlg() {
709 KShortcutsDialog::configure(QtUi::actionCollection("General"), KShortcutsEditor::LetterShortcutsDisallowed);
713 void MainWin::closeEvent(QCloseEvent *event) {
715 QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
717 if(!app->aboutToQuit() && s.value("UseSystemTrayIcon").toBool() && s.value("MinimizeOnClose").toBool()) {
718 toggleMinimizedToTray();
722 QApplication::quit();
726 void MainWin::systrayActivated(QSystemTrayIcon::ActivationReason activationReason) {
727 if(activationReason == QSystemTrayIcon::Trigger) {
728 toggleMinimizedToTray();
732 void MainWin::hideToTray() {
733 if(!systemTrayIcon()->isSystemTrayAvailable()) {
734 qWarning() << Q_FUNC_INFO << "was called with no SystemTray available!";
740 systemTrayIcon()->show();
743 void MainWin::toggleMinimizedToTray() {
744 if(windowState() & Qt::WindowMinimized) {
746 setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
750 setWindowState((windowState() & ~Qt::WindowActive) | Qt::WindowMinimized);
755 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {
758 if(QApplication::activeWindow() != 0)
761 for(int i = start; i <= end; i++) {
762 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
764 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
767 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
768 if(flags.testFlag(Message::Backlog)) continue;
769 flags |= Message::Backlog; // we only want to trigger a highlight once!
770 Client::messageModel()->setData(idx, (int)flags, ChatLineModel::FlagsRole);
772 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
773 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
775 if(flags & Message::Highlight || bufType == BufferInfo::QueryBuffer) {
776 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
777 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
778 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
779 QtUi::invokeNotification(bufId, sender, contents);
784 bool MainWin::event(QEvent *event) {
785 if(event->type() == QEvent::WindowActivate)
786 QtUi::closeNotifications();
787 return QMainWindow::event(event);
790 void MainWin::clientNetworkCreated(NetworkId id) {
791 const Network *net = Client::network(id);
792 QAction *act = new QAction(net->networkName(), this);
793 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
794 act->setData(QVariant::fromValue<NetworkId>(id));
795 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
796 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
798 QAction *beforeAction = 0;
799 foreach(QAction *action, _networksMenu->actions()) {
800 if(!action->data().isValid()) // ignore stock actions
802 if(net->networkName().localeAwareCompare(action->text()) < 0) {
803 beforeAction = action;
807 _networksMenu->insertAction(beforeAction, act);
810 void MainWin::clientNetworkUpdated() {
811 const Network *net = qobject_cast<const Network *>(sender());
815 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
819 action->setText(net->networkName());
821 switch(net->connectionState()) {
822 case Network::Initialized:
823 action->setIcon(SmallIcon("network-connect"));
825 case Network::Disconnected:
826 action->setIcon(SmallIcon("network-disconnect"));
829 action->setIcon(SmallIcon("network-wired"));
833 void MainWin::clientNetworkRemoved(NetworkId id) {
834 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
838 action->deleteLater();
841 void MainWin::connectOrDisconnectFromNet() {
842 QAction *act = qobject_cast<QAction *>(sender());
844 const Network *net = Client::network(act->data().value<NetworkId>());
846 if(net->connectionState() == Network::Disconnected) net->requestConnect();
847 else net->requestDisconnect();
850 void MainWin::on_actionDebugNetworkModel_triggered() {
851 QTreeView *view = new QTreeView;
852 view->setAttribute(Qt::WA_DeleteOnClose);
853 view->setWindowTitle("Debug NetworkModel View");
854 view->setModel(Client::networkModel());
855 view->setColumnWidth(0, 250);
856 view->setColumnWidth(1, 250);
857 view->setColumnWidth(2, 80);
858 view->resize(610, 300);
862 void MainWin::on_actionDebugMessageModel_triggered() {
863 QTableView *view = new QTableView(0);
864 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
865 filter->setSourceModel(Client::messageModel());
866 view->setModel(filter);
867 view->setAttribute(Qt::WA_DeleteOnClose, true);
868 view->verticalHeader()->hide();
869 view->horizontalHeader()->setStretchLastSection(true);
873 void MainWin::on_actionDebugLog_triggered() {
874 DebugLogWidget *logWidget = new DebugLogWidget(0);
878 void MainWin::saveStateToSession(const QString &sessionId) {
880 SessionSettings s(sessionId);
882 s.setValue("MainWinSize", size());
883 s.setValue("MainWinPos", pos());
884 s.setValue("MainWinState", saveState());
887 void MainWin::saveStateToSessionSettings(SessionSettings & s)
889 s.setValue("MainWinSize", size());
890 s.setValue("MainWinPos", pos());
891 s.setValue("MainWinState", saveState());
894 void MainWin::showStatusBarMessage(const QString &message) {
895 statusBar()->showMessage(message, 10000);