1 /***************************************************************************
2 * Copyright (C) 2005-2010 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>
29 # include <KToggleFullScreenAction>
31 # include <KWindowSystem>
39 #include "awaylogfilter.h"
40 #include "awaylogview.h"
42 #include "actioncollection.h"
43 #include "bufferhotlistfilter.h"
44 #include "buffermodel.h"
45 #include "bufferview.h"
46 #include "bufferviewoverlay.h"
47 #include "bufferviewoverlayfilter.h"
48 #include "bufferwidget.h"
49 #include "channellistdlg.h"
50 #include "chatlinemodel.h"
51 #include "chatmonitorfilter.h"
52 #include "chatmonitorview.h"
55 #include "clientbacklogmanager.h"
56 #include "clientbufferviewconfig.h"
57 #include "clientbufferviewmanager.h"
58 #include "clientignorelistmanager.h"
59 #include "coreconfigwizard.h"
60 #include "coreconnectdlg.h"
61 #include "coreconnection.h"
62 #include "coreconnectionstatuswidget.h"
63 #include "coreinfodlg.h"
64 #include "contextmenuactionprovider.h"
65 #include "debugbufferviewoverlay.h"
66 #include "debuglogwidget.h"
67 #include "debugmessagemodelfilter.h"
68 #include "flatproxymodel.h"
69 #include "iconloader.h"
70 #include "inputwidget.h"
71 #include "irclistmodel.h"
72 #include "ircconnectionwizard.h"
73 #include "legacysystemtray.h"
74 #include "msgprocessorstatuswidget.h"
75 #include "nicklistwidget.h"
76 #include "qtuiapplication.h"
77 #include "qtuimessageprocessor.h"
78 #include "qtuisettings.h"
79 #include "qtuistyle.h"
80 #include "settingsdlg.h"
81 #include "settingspagedlg.h"
82 #include "statusnotifieritem.h"
83 #include "toolbaractionprovider.h"
84 #include "topicwidget.h"
85 #include "verticaldock.h"
89 # include "phononnotificationbackend.h"
91 # include "systraynotificationbackend.h"
92 # include "taskbarnotificationbackend.h"
94 # include "knotificationbackend.h"
98 # include "sslinfodlg.h"
101 #ifdef HAVE_INDICATEQT
102 #include "indicatornotificationbackend.h"
105 #include "settingspages/aliasessettingspage.h"
106 #include "settingspages/appearancesettingspage.h"
107 #include "settingspages/backlogsettingspage.h"
108 #include "settingspages/bufferviewsettingspage.h"
109 #include "settingspages/chatmonitorsettingspage.h"
110 #include "settingspages/chatviewsettingspage.h"
111 #include "settingspages/connectionsettingspage.h"
112 #include "settingspages/coreaccountsettingspage.h"
113 #include "settingspages/coreconnectionsettingspage.h"
114 #include "settingspages/highlightsettingspage.h"
115 #include "settingspages/identitiessettingspage.h"
116 #include "settingspages/ignorelistsettingspage.h"
117 #include "settingspages/inputwidgetsettingspage.h"
118 #include "settingspages/itemviewsettingspage.h"
119 #include "settingspages/networkssettingspage.h"
120 #include "settingspages/notificationssettingspage.h"
121 #include "settingspages/topicwidgetsettingspage.h"
124 # include "settingspages/shortcutssettingspage.h"
127 MainWin::MainWin(QWidget *parent)
129 : KMainWindow(parent),
130 _kHelpMenu(new KHelpMenu(this, KGlobal::mainComponent().aboutData())),
132 : QMainWindow(parent),
134 _msgProcessorStatusWidget(new MsgProcessorStatusWidget(this)),
135 _coreConnectionStatusWidget(new CoreConnectionStatusWidget(Client::coreConnection(), this)),
138 _layoutLoaded(false),
139 _activeBufferViewIndex(-1)
141 setAttribute(Qt::WA_DeleteOnClose, false); // we delete the mainwin manually
143 QtUiSettings uiSettings;
144 QString style = uiSettings.value("Style", QString()).toString();
145 if(!style.isEmpty()) {
146 QApplication::setStyle(style);
149 QApplication::setQuitOnLastWindowClosed(false);
151 setWindowTitle("Quassel IRC");
152 setWindowIconText("Quassel IRC");
156 void MainWin::init() {
157 connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), SLOT(clientNetworkCreated(NetworkId)));
158 connect(Client::instance(), SIGNAL(networkRemoved(NetworkId)), SLOT(clientNetworkRemoved(NetworkId)));
159 connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)),
160 SLOT(messagesInserted(const QModelIndex &, int, int)));
161 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showChannelList(NetworkId)), SLOT(showChannelList(NetworkId)));
162 connect(GraphicalUi::contextMenuActionProvider(), SIGNAL(showIgnoreList(QString)), SLOT(showIgnoreList(QString)));
164 connect(Client::coreConnection(), SIGNAL(startCoreSetup(QVariantList)), SLOT(showCoreConfigWizard(QVariantList)));
165 connect(Client::coreConnection(), SIGNAL(connectionErrorPopup(QString)), SLOT(handleCoreConnectionError(QString)));
166 connect(Client::coreConnection(), SIGNAL(userAuthenticationRequired(CoreAccount *, bool *, QString)), SLOT(userAuthenticationRequired(CoreAccount *, bool *, QString)));
167 connect(Client::coreConnection(), SIGNAL(handleNoSslInClient(bool*)), SLOT(handleNoSslInClient(bool *)));
168 connect(Client::coreConnection(), SIGNAL(handleNoSslInCore(bool*)), SLOT(handleNoSslInCore(bool *)));
170 connect(Client::coreConnection(), SIGNAL(handleSslErrors(const QSslSocket *, bool *, bool *)), SLOT(handleSslErrors(const QSslSocket *, bool *, bool *)));
174 setDockNestingEnabled(true);
175 setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
176 setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
177 setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
178 setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
180 // Order is sometimes important
197 QtUi::registerNotificationBackend(new PhononNotificationBackend(this));
199 # ifndef QT_NO_SYSTEMTRAYICON
200 QtUi::registerNotificationBackend(new SystrayNotificationBackend(this));
203 QtUi::registerNotificationBackend(new TaskbarNotificationBackend(this));
206 QtUi::registerNotificationBackend(new KNotificationBackend(this));
207 #endif /* HAVE_KDE */
209 #ifdef HAVE_INDICATEQT
210 QtUi::registerNotificationBackend(new IndicatorNotificationBackend(this));
213 // we assume that at this point, all configurable actions are defined!
214 QtUi::loadShortcuts();
216 connect(bufferWidget(), SIGNAL(currentChanged(BufferId)), SLOT(currentBufferChanged(BufferId)));
218 setDisconnectedState(); // Disable menus and stuff
221 setAutoSaveSettings();
224 // restore mainwin state
226 restoreStateFromSettings(s);
228 // restore locked state of docks
229 QtUi::actionCollection("General")->action("LockLayout")->setChecked(s.value("LockLayout", false).toBool());
231 CoreConnection *conn = Client::coreConnection();
232 if(!conn->connectToCore()) {
233 // No autoconnect selected (or no accounts)
234 showCoreConnectionDlg();
238 MainWin::~MainWin() {
242 void MainWin::quit() {
244 saveStateToSettings(s);
246 QApplication::quit();
249 void MainWin::saveStateToSettings(UiSettings &s) {
250 s.setValue("MainWinSize", _normalSize);
251 s.setValue("MainWinPos", _normalPos);
252 s.setValue("MainWinState", saveState());
253 s.setValue("MainWinGeometry", saveGeometry());
254 s.setValue("MainWinMinimized", isMinimized());
255 s.setValue("MainWinMaximized", isMaximized());
256 s.setValue("MainWinHidden", !isVisible());
257 BufferId lastBufId = Client::bufferModel()->currentBuffer();
258 if(lastBufId.isValid())
259 s.setValue("LastUsedBufferId", lastBufId.toInt());
262 saveAutoSaveSettings();
266 void MainWin::restoreStateFromSettings(UiSettings &s) {
267 _normalSize = s.value("MainWinSize", size()).toSize();
268 _normalPos = s.value("MainWinPos", pos()).toPoint();
269 bool maximized = s.value("MainWinMaximized", false).toBool();
272 restoreGeometry(s.value("MainWinGeometry").toByteArray());
275 // restoreGeometry() fails if the windows was maximized, so we resize and position explicitly
280 restoreState(s.value("MainWinState").toByteArray());
286 if(s.value("MainWinHidden").toBool() && QtUi::haveSystemTray())
287 QtUi::hideMainWidget();
288 else if(s.value("MainWinMinimized").toBool())
296 void MainWin::updateIcon() {
298 const int size = 128;
304 if(Client::isConnected())
305 icon = DesktopIcon("quassel", size);
307 icon = DesktopIcon("quassel_inactive", size);
309 qApp->setWindowIcon(icon);
312 void MainWin::setupActions() {
313 ActionCollection *coll = QtUi::actionCollection("General", tr("General"));
315 coll->addAction("ConnectCore", new Action(SmallIcon("network-connect"), tr("&Connect to Core..."), coll,
316 this, SLOT(showCoreConnectionDlg())));
317 coll->addAction("DisconnectCore", new Action(SmallIcon("network-disconnect"), tr("&Disconnect from Core"), coll,
318 Client::instance(), SLOT(disconnectFromCore())));
319 coll->addAction("CoreInfo", new Action(SmallIcon("help-about"), tr("Core &Info..."), coll,
320 this, SLOT(showCoreInfoDlg())));
321 coll->addAction("ConfigureNetworks", new Action(SmallIcon("configure"), tr("Configure &Networks..."), coll,
322 this, SLOT(on_actionConfigureNetworks_triggered())));
323 // FIXME: use QKeySequence::Quit once we depend on Qt 4.6
324 coll->addAction("Quit", new Action(SmallIcon("application-exit"), tr("&Quit"), coll,
325 this, SLOT(quit()), Qt::CTRL + Qt::Key_Q));
328 coll->addAction("ConfigureBufferViews", new Action(tr("&Configure Chat Lists..."), coll,
329 this, SLOT(on_actionConfigureViews_triggered())));
331 QAction *lockAct = coll->addAction("LockLayout", new Action(tr("&Lock Layout"), coll));
332 lockAct->setCheckable(true);
333 connect(lockAct, SIGNAL(toggled(bool)), SLOT(on_actionLockLayout_toggled(bool)));
335 coll->addAction("ToggleSearchBar", new Action(SmallIcon("edit-find"), tr("Show &Search Bar"), coll,
336 0, 0, QKeySequence::Find))->setCheckable(true);
337 coll->addAction("ShowAwayLog", new Action(tr("Show Away Log"), coll,
338 this, SLOT(showAwayLog())));
339 coll->addAction("ToggleMenuBar", new Action(SmallIcon("show-menu"), tr("Show &Menubar"), coll,
340 0, 0, QKeySequence(Qt::CTRL + Qt::Key_M)))->setCheckable(true);
342 coll->addAction("ToggleStatusBar", new Action(tr("Show Status &Bar"), coll,
343 0, 0))->setCheckable(true);
346 QAction *fullScreenAct = KStandardAction::fullScreen(this, SLOT(toggleFullscreen()), this, coll);
348 QAction *fullScreenAct = new Action(SmallIcon("view-fullscreen"), tr("&Full Screen Mode"), coll,
349 this, SLOT(toggleFullscreen()), QKeySequence(Qt::Key_F11));
350 fullScreenAct->setCheckable(true);
352 coll->addAction("ToggleFullscreen", fullScreenAct);
355 QAction *configureShortcutsAct = new Action(SmallIcon("configure-shortcuts"), tr("Configure &Shortcuts..."), coll,
356 this, SLOT(showShortcutsDlg()));
357 configureShortcutsAct->setMenuRole(QAction::NoRole);
358 coll->addAction("ConfigureShortcuts", configureShortcutsAct);
361 QAction *configureQuasselAct = new Action(SmallIcon("configure"), tr("&Configure Quassel..."), coll,
362 this, SLOT(showSettingsDlg()));
363 configureQuasselAct->setMenuRole(QAction::PreferencesRole);
365 QAction *configureQuasselAct = new Action(SmallIcon("configure"), tr("&Configure Quassel..."), coll,
366 this, SLOT(showSettingsDlg()), QKeySequence(Qt::Key_F7));
368 coll->addAction("ConfigureQuassel", configureQuasselAct);
371 QAction *aboutQuasselAct = new Action(SmallIcon("quassel"), tr("&About Quassel"), coll,
372 this, SLOT(showAboutDlg()));
373 aboutQuasselAct->setMenuRole(QAction::AboutRole);
374 coll->addAction("AboutQuassel", aboutQuasselAct);
376 QAction *aboutQtAct = new Action(QIcon(":/pics/qt-logo.png"), tr("About &Qt"), coll,
377 qApp, SLOT(aboutQt()));
378 aboutQtAct->setMenuRole(QAction::AboutQtRole);
379 coll->addAction("AboutQt", aboutQtAct);
380 coll->addAction("DebugNetworkModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &NetworkModel"), coll,
381 this, SLOT(on_actionDebugNetworkModel_triggered())));
382 coll->addAction("DebugBufferViewOverlay", new Action(SmallIcon("tools-report-bug"), tr("Debug &BufferViewOverlay"), coll,
383 this, SLOT(on_actionDebugBufferViewOverlay_triggered())));
384 coll->addAction("DebugMessageModel", new Action(SmallIcon("tools-report-bug"), tr("Debug &MessageModel"), coll,
385 this, SLOT(on_actionDebugMessageModel_triggered())));
386 coll->addAction("DebugHotList", new Action(SmallIcon("tools-report-bug"), tr("Debug &HotList"), coll,
387 this, SLOT(on_actionDebugHotList_triggered())));
388 coll->addAction("DebugLog", new Action(SmallIcon("tools-report-bug"), tr("Debug &Log"), coll,
389 this, SLOT(on_actionDebugLog_triggered())));
390 coll->addAction("ReloadStyle", new Action(SmallIcon("view-refresh"), tr("Reload Stylesheet"), coll,
391 QtUi::style(), SLOT(reload()), QKeySequence::Refresh));
394 coll = QtUi::actionCollection("Navigation", tr("Navigation"));
396 coll->addAction("JumpHotBuffer", new Action(tr("Jump to hot chat"), coll,
397 this, SLOT(on_jumpHotBuffer_triggered()), QKeySequence(Qt::META + Qt::Key_A)));
401 const int bindModifier = Qt::ControlModifier | Qt::AltModifier;
402 const int jumpModifier = Qt::ControlModifier;
404 const int bindModifier = Qt::ControlModifier;
405 const int jumpModifier = Qt::AltModifier;
408 coll->addAction("BindJumpKey0", new Action(tr("Set Quick Access #0"), coll, this, SLOT(bindJumpKey()),
409 QKeySequence(bindModifier + Qt::Key_0)))->setProperty("Index", 0);
410 coll->addAction("BindJumpKey1", new Action(tr("Set Quick Access #1"), coll, this, SLOT(bindJumpKey()),
411 QKeySequence(bindModifier + Qt::Key_1)))->setProperty("Index", 1);
412 coll->addAction("BindJumpKey2", new Action(tr("Set Quick Access #2"), coll, this, SLOT(bindJumpKey()),
413 QKeySequence(bindModifier + Qt::Key_2)))->setProperty("Index", 2);
414 coll->addAction("BindJumpKey3", new Action(tr("Set Quick Access #3"), coll, this, SLOT(bindJumpKey()),
415 QKeySequence(bindModifier + Qt::Key_3)))->setProperty("Index", 3);
416 coll->addAction("BindJumpKey4", new Action(tr("Set Quick Access #4"), coll, this, SLOT(bindJumpKey()),
417 QKeySequence(bindModifier + Qt::Key_4)))->setProperty("Index", 4);
418 coll->addAction("BindJumpKey5", new Action(tr("Set Quick Access #5"), coll, this, SLOT(bindJumpKey()),
419 QKeySequence(bindModifier + Qt::Key_5)))->setProperty("Index", 5);
420 coll->addAction("BindJumpKey6", new Action(tr("Set Quick Access #6"), coll, this, SLOT(bindJumpKey()),
421 QKeySequence(bindModifier + Qt::Key_6)))->setProperty("Index", 6);
422 coll->addAction("BindJumpKey7", new Action(tr("Set Quick Access #7"), coll, this, SLOT(bindJumpKey()),
423 QKeySequence(bindModifier + Qt::Key_7)))->setProperty("Index", 7);
424 coll->addAction("BindJumpKey8", new Action(tr("Set Quick Access #8"), coll, this, SLOT(bindJumpKey()),
425 QKeySequence(bindModifier + Qt::Key_8)))->setProperty("Index", 8);
426 coll->addAction("BindJumpKey9", new Action(tr("Set Quick Access #9"), coll, this, SLOT(bindJumpKey()),
427 QKeySequence(bindModifier + Qt::Key_9)))->setProperty("Index", 9);
429 coll->addAction("JumpKey0", new Action(tr("Quick Access #0"), coll, this, SLOT(onJumpKey()),
430 QKeySequence(jumpModifier + Qt::Key_0)))->setProperty("Index", 0);
431 coll->addAction("JumpKey1", new Action(tr("Quick Access #1"), coll, this, SLOT(onJumpKey()),
432 QKeySequence(jumpModifier + Qt::Key_1)))->setProperty("Index", 1);
433 coll->addAction("JumpKey2", new Action(tr("Quick Access #2"), coll, this, SLOT(onJumpKey()),
434 QKeySequence(jumpModifier + Qt::Key_2)))->setProperty("Index", 2);
435 coll->addAction("JumpKey3", new Action(tr("Quick Access #3"), coll, this, SLOT(onJumpKey()),
436 QKeySequence(jumpModifier + Qt::Key_3)))->setProperty("Index", 3);
437 coll->addAction("JumpKey4", new Action(tr("Quick Access #4"), coll, this, SLOT(onJumpKey()),
438 QKeySequence(jumpModifier + Qt::Key_4)))->setProperty("Index", 4);
439 coll->addAction("JumpKey5", new Action(tr("Quick Access #5"), coll, this, SLOT(onJumpKey()),
440 QKeySequence(jumpModifier + Qt::Key_5)))->setProperty("Index", 5);
441 coll->addAction("JumpKey6", new Action(tr("Quick Access #6"), coll, this, SLOT(onJumpKey()),
442 QKeySequence(jumpModifier + Qt::Key_6)))->setProperty("Index", 6);
443 coll->addAction("JumpKey7", new Action(tr("Quick Access #7"), coll, this, SLOT(onJumpKey()),
444 QKeySequence(jumpModifier + Qt::Key_7)))->setProperty("Index", 7);
445 coll->addAction("JumpKey8", new Action(tr("Quick Access #8"), coll, this, SLOT(onJumpKey()),
446 QKeySequence(jumpModifier + Qt::Key_8)))->setProperty("Index", 8);
447 coll->addAction("JumpKey9", new Action(tr("Quick Access #9"), coll, this, SLOT(onJumpKey()),
448 QKeySequence(jumpModifier + Qt::Key_9)))->setProperty("Index", 9);
451 coll->addAction("NextBufferView", new Action(SmallIcon("go-next-view"), tr("Activate Next Chat List"), coll,
452 this, SLOT(nextBufferView()), QKeySequence(QKeySequence::Forward)));
453 coll->addAction("PreviousBufferView", new Action(SmallIcon("go-previous-view"), tr("Activate Previous Chat List"), coll,
454 this, SLOT(previousBufferView()), QKeySequence::Back));
455 coll->addAction("NextBuffer", new Action(SmallIcon("go-down"), tr("Go to Next Chat"), coll,
456 this, SLOT(nextBuffer()), QKeySequence(Qt::ALT + Qt::Key_Down)));
457 coll->addAction("PreviousBuffer", new Action(SmallIcon("go-up"), tr("Go to Previous Chat"), coll,
458 this, SLOT(previousBuffer()), QKeySequence(Qt::ALT + Qt::Key_Up)));
461 void MainWin::setupMenus() {
462 ActionCollection *coll = QtUi::actionCollection("General");
464 _fileMenu = menuBar()->addMenu(tr("&File"));
466 static const QStringList coreActions = QStringList()
467 << "ConnectCore" << "DisconnectCore" << "CoreInfo";
470 foreach(QString actionName, coreActions) {
471 coreAction = coll->action(actionName);
472 _fileMenu->addAction(coreAction);
473 flagRemoteCoreOnly(coreAction);
475 flagRemoteCoreOnly(_fileMenu->addSeparator());
477 _networksMenu = _fileMenu->addMenu(tr("&Networks"));
478 _networksMenu->addAction(coll->action("ConfigureNetworks"));
479 _networksMenu->addSeparator();
480 _fileMenu->addSeparator();
481 _fileMenu->addAction(coll->action("Quit"));
483 _viewMenu = menuBar()->addMenu(tr("&View"));
484 _bufferViewsMenu = _viewMenu->addMenu(tr("&Chat Lists"));
485 _bufferViewsMenu->addAction(coll->action("ConfigureBufferViews"));
486 _toolbarMenu = _viewMenu->addMenu(tr("&Toolbars"));
487 _viewMenu->addSeparator();
489 _viewMenu->addAction(coll->action("ToggleMenuBar"));
490 _viewMenu->addAction(coll->action("ToggleStatusBar"));
491 _viewMenu->addAction(coll->action("ToggleSearchBar"));
493 coreAction = coll->action("ShowAwayLog");
494 flagRemoteCoreOnly(coreAction);
495 _viewMenu->addAction(coreAction);
497 _viewMenu->addSeparator();
498 _viewMenu->addAction(coll->action("LockLayout"));
500 _settingsMenu = menuBar()->addMenu(tr("&Settings"));
502 _settingsMenu->addAction(KStandardAction::configureNotifications(this, SLOT(showNotificationsDlg()), this));
503 _settingsMenu->addAction(KStandardAction::keyBindings(this, SLOT(showShortcutsDlg()), this));
505 _settingsMenu->addAction(coll->action("ConfigureShortcuts"));
507 _settingsMenu->addAction(coll->action("ConfigureQuassel"));
509 _helpMenu = menuBar()->addMenu(tr("&Help"));
510 _helpMenu->addAction(coll->action("AboutQuassel"));
512 _helpMenu->addAction(coll->action("AboutQt"));
514 _helpMenu->addAction(KStandardAction::aboutKDE(_kHelpMenu, SLOT(aboutKDE()), this));
516 _helpMenu->addSeparator();
517 _helpDebugMenu = _helpMenu->addMenu(SmallIcon("tools-report-bug"), tr("Debug"));
518 _helpDebugMenu->addAction(coll->action("DebugNetworkModel"));
519 _helpDebugMenu->addAction(coll->action("DebugBufferViewOverlay"));
520 _helpDebugMenu->addAction(coll->action("DebugMessageModel"));
521 _helpDebugMenu->addAction(coll->action("DebugHotList"));
522 _helpDebugMenu->addAction(coll->action("DebugLog"));
523 _helpDebugMenu->addSeparator();
524 _helpDebugMenu->addAction(coll->action("ReloadStyle"));
527 QAction *showMenuBar = QtUi::actionCollection("General")->action("ToggleMenuBar");
529 QtUiSettings uiSettings;
530 bool enabled = uiSettings.value("ShowMenuBar", QVariant(true)).toBool();
531 showMenuBar->setChecked(enabled);
532 enabled ? menuBar()->show() : menuBar()->hide();
534 connect(showMenuBar, SIGNAL(toggled(bool)), menuBar(), SLOT(setVisible(bool)));
535 connect(showMenuBar, SIGNAL(toggled(bool)), this, SLOT(saveMenuBarStatus(bool)));
538 void MainWin::setupBufferWidget() {
539 _bufferWidget = new BufferWidget(this);
540 _bufferWidget->setModel(Client::bufferModel());
541 _bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
542 setCentralWidget(_bufferWidget);
545 void MainWin::addBufferView(int bufferViewConfigId) {
546 addBufferView(Client::bufferViewManager()->clientBufferViewConfig(bufferViewConfigId));
549 void MainWin::addBufferView(ClientBufferViewConfig *config) {
553 config->setLocked(QtUiSettings().value("LockLayout", false).toBool());
554 BufferViewDock *dock = new BufferViewDock(config, this);
556 //create the view and initialize it's filter
557 BufferView *view = new BufferView(dock);
558 view->setFilteredModel(Client::bufferModel(), config);
559 view->installEventFilter(_inputWidget); // for key presses
561 Client::bufferModel()->synchronizeView(view);
563 dock->setWidget(view);
564 dock->setVisible(_layoutLoaded); // don't show before state has been restored
566 addDockWidget(Qt::LeftDockWidgetArea, dock);
567 _bufferViewsMenu->addAction(dock->toggleViewAction());
569 connect(dock->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(bufferViewToggled(bool)));
570 connect(dock, SIGNAL(visibilityChanged(bool)), SLOT(bufferViewVisibilityChanged(bool)));
571 _bufferViews.append(dock);
573 if(!activeBufferView())
577 void MainWin::removeBufferView(int bufferViewConfigId) {
579 BufferViewDock *dock;
580 foreach(QAction *action, _bufferViewsMenu->actions()) {
581 actionData = action->data();
582 if(!actionData.isValid())
585 dock = qobject_cast<BufferViewDock *>(action->parent());
586 if(dock && actionData.toInt() == bufferViewConfigId) {
587 removeAction(action);
588 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
589 _bufferViews.removeAll(dock);
591 if(dock->isActive()) {
592 dock->setActive(false);
593 _activeBufferViewIndex = -1;
602 void MainWin::bufferViewToggled(bool enabled) {
603 if(!enabled && !isVisible()) {
604 // hiding the mainwindow triggers a toggle of the bufferview (which pretty much sucks big time)
605 // since this isn't our fault and we can't do anything about it, we suppress the resulting calls
608 QAction *action = qobject_cast<QAction *>(sender());
610 BufferViewDock *dock = qobject_cast<BufferViewDock *>(action->parent());
613 // Make sure we don't toggle backlog fetch for a view we've already removed
614 if(!_bufferViews.contains(dock))
618 Client::bufferViewOverlay()->addView(dock->bufferViewId());
620 Client::bufferViewOverlay()->removeView(dock->bufferViewId());
623 void MainWin::bufferViewVisibilityChanged(bool visible) {
625 BufferViewDock *dock = qobject_cast<BufferViewDock *>(sender());
627 if((!dock->isHidden() && !activeBufferView()) || (dock->isHidden() && dock->isActive()))
631 BufferView *MainWin::allBuffersView() const {
632 // "All Buffers" is always the first dock created
633 if(_bufferViews.count() > 0)
634 return _bufferViews[0]->bufferView();
638 BufferView *MainWin::activeBufferView() const {
639 if(_activeBufferViewIndex < 0 || _activeBufferViewIndex >= _bufferViews.count())
641 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
642 return dock->isActive() ? qobject_cast<BufferView*>(dock->widget()) : 0;
645 void MainWin::changeActiveBufferView(int bufferViewId) {
649 BufferView *current = activeBufferView();
651 qobject_cast<BufferViewDock*>(current->parent())->setActive(false);
652 _activeBufferViewIndex = -1;
655 for(int i = 0; i < _bufferViews.count(); i++) {
656 BufferViewDock *dock = _bufferViews.at(i);
657 if(dock->bufferViewId() == bufferViewId && !dock->isHidden()) {
658 _activeBufferViewIndex = i;
659 dock->setActive(true);
664 nextBufferView(); // fallback
667 void MainWin::changeActiveBufferView(bool backwards) {
668 BufferView *current = activeBufferView();
670 qobject_cast<BufferViewDock*>(current->parent())->setActive(false);
672 if(!_bufferViews.count())
675 int c = _bufferViews.count();
676 while(c--) { // yes, this will reactivate the current active one if all others fail
678 if(--_activeBufferViewIndex < 0)
679 _activeBufferViewIndex = _bufferViews.count()-1;
681 if(++_activeBufferViewIndex >= _bufferViews.count())
682 _activeBufferViewIndex = 0;
685 BufferViewDock *dock = _bufferViews.at(_activeBufferViewIndex);
689 dock->setActive(true);
693 _activeBufferViewIndex = -1;
696 void MainWin::nextBufferView() {
697 changeActiveBufferView(false);
700 void MainWin::previousBufferView() {
701 changeActiveBufferView(true);
704 void MainWin::nextBuffer() {
705 BufferView *view = activeBufferView();
710 void MainWin::previousBuffer() {
711 BufferView *view = activeBufferView();
713 view->previousBuffer();
716 void MainWin::showNotificationsDlg() {
717 SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
721 void MainWin::on_actionConfigureNetworks_triggered() {
722 SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
726 void MainWin::on_actionConfigureViews_triggered() {
727 SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
731 void MainWin::on_actionLockLayout_toggled(bool lock) {
732 QList<VerticalDock *> docks = findChildren<VerticalDock *>();
733 foreach(VerticalDock *dock, docks) {
734 dock->showTitle(!lock);
736 if(Client::bufferViewManager()) {
737 foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
738 config->setLocked(lock);
741 QtUiSettings().setValue("LockLayout", lock);
744 void MainWin::setupNickWidget() {
746 NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
747 nickDock->setObjectName("NickDock");
748 nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
750 _nickListWidget = new NickListWidget(nickDock);
751 nickDock->setWidget(_nickListWidget);
753 addDockWidget(Qt::RightDockWidgetArea, nickDock);
754 _viewMenu->addAction(nickDock->toggleViewAction());
755 nickDock->toggleViewAction()->setText(tr("Show Nick List"));
757 // See NickListDock::NickListDock();
758 // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
760 // attach the NickListWidget to the BufferModel and the default selection
761 _nickListWidget->setModel(Client::bufferModel());
762 _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
765 void MainWin::setupChatMonitor() {
766 VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
767 dock->setObjectName("ChatMonitorDock");
769 ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
770 _chatMonitorView = new ChatMonitorView(filter, this);
771 _chatMonitorView->setFocusProxy(_inputWidget);
772 _chatMonitorView->show();
773 dock->setWidget(_chatMonitorView);
776 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
777 _viewMenu->addAction(dock->toggleViewAction());
778 dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
781 void MainWin::setupInputWidget() {
782 VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
783 dock->setObjectName("InputDock");
785 _inputWidget = new InputWidget(dock);
786 dock->setWidget(_inputWidget);
788 addDockWidget(Qt::BottomDockWidgetArea, dock);
790 _viewMenu->addAction(dock->toggleViewAction());
791 dock->toggleViewAction()->setText(tr("Show Input Line"));
793 _inputWidget->setModel(Client::bufferModel());
794 _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
796 _bufferWidget->setFocusProxy(_inputWidget);
798 _inputWidget->inputLine()->installEventFilter(_bufferWidget);
800 connect(_topicWidget, SIGNAL(switchedPlain()), _bufferWidget, SLOT(setFocus()));
803 void MainWin::setupTopicWidget() {
804 VerticalDock *dock = new VerticalDock(tr("Topic"), this);
805 dock->setObjectName("TopicDock");
806 _topicWidget = new TopicWidget(dock);
808 dock->setWidget(_topicWidget);
810 _topicWidget->setModel(Client::bufferModel());
811 _topicWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
813 addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
815 _viewMenu->addAction(dock->toggleViewAction());
816 dock->toggleViewAction()->setText(tr("Show Topic Line"));
819 void MainWin::setupViewMenuTail() {
820 _viewMenu->addSeparator();
821 _viewMenu->addAction(QtUi::actionCollection("General")->action("ToggleFullscreen"));
824 void MainWin::setupTitleSetter() {
825 _titleSetter.setModel(Client::bufferModel());
826 _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
829 void MainWin::setupStatusBar() {
830 // MessageProcessor progress
831 statusBar()->addPermanentWidget(_msgProcessorStatusWidget);
834 _coreConnectionStatusWidget->update();
835 statusBar()->addPermanentWidget(_coreConnectionStatusWidget);
837 QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
839 QtUiSettings uiSettings;
841 bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
842 showStatusbar->setChecked(enabled);
843 enabled ? statusBar()->show() : statusBar()->hide();
845 connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
846 connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
848 connect(Client::coreConnection(), SIGNAL(connectionMsg(QString)), statusBar(), SLOT(showMessage(QString)));
851 void MainWin::setupHotList() {
852 FlatProxyModel *flatProxy = new FlatProxyModel(this);
853 flatProxy->setSourceModel(Client::bufferModel());
854 _bufferHotList = new BufferHotListFilter(flatProxy);
857 void MainWin::saveMenuBarStatus(bool enabled) {
858 QtUiSettings uiSettings;
859 uiSettings.setValue("ShowMenuBar", enabled);
862 void MainWin::saveStatusBarStatus(bool enabled) {
863 QtUiSettings uiSettings;
864 uiSettings.setValue("ShowStatusBar", enabled);
867 void MainWin::setupSystray() {
869 _systemTray = new StatusNotifierItem(this);
870 #elif !defined QT_NO_SYSTEMTRAYICON
871 _systemTray = new LegacySystemTray(this);
873 _systemTray = new SystemTray(this); // dummy
878 void MainWin::setupToolBars() {
879 connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
880 QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
881 connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
882 QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
885 setUnifiedTitleAndToolBarOnMac(true);
889 _mainToolBar = new KToolBar("MainToolBar", this, Qt::TopToolBarArea, false, true, true);
891 _mainToolBar = new QToolBar(this);
892 _mainToolBar->setObjectName("MainToolBar");
894 _mainToolBar->setWindowTitle(tr("Main Toolbar"));
895 addToolBar(_mainToolBar);
897 QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
898 _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
901 void MainWin::connectedToCore() {
902 Q_CHECK_PTR(Client::bufferViewManager());
903 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
904 connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
905 connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
910 void MainWin::setConnectedState() {
911 ActionCollection *coll = QtUi::actionCollection("General");
913 coll->action("ConnectCore")->setEnabled(false);
914 coll->action("DisconnectCore")->setEnabled(true);
915 coll->action("CoreInfo")->setEnabled(true);
917 foreach(QAction *action, _fileMenu->actions()) {
918 if(isRemoteCoreOnly(action))
919 action->setVisible(!Client::internalCore());
922 disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
923 disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
924 disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
925 if(!Client::internalCore()) {
926 connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
927 connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
928 connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
931 // _viewMenu->setEnabled(true);
932 if(!Client::internalCore())
933 statusBar()->showMessage(tr("Connected to core."));
935 statusBar()->clearMessage();
937 _coreConnectionStatusWidget->setVisible(!Client::internalCore());
939 systemTray()->setState(SystemTray::Active);
941 if(Client::networkIds().isEmpty()) {
942 IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
946 // Monolithic always preselects last used buffer - Client only if the connection died
947 if(Client::coreConnection()->wasReconnect() || Quassel::runMode() == Quassel::Monolithic) {
949 BufferId lastUsedBufferId(s.value("LastUsedBufferId").toInt());
950 if(lastUsedBufferId.isValid())
951 Client::bufferModel()->switchToBuffer(lastUsedBufferId);
956 void MainWin::loadLayout() {
958 int accountId = Client::currentCoreAccount().accountId().toInt();
959 QByteArray state = s.value(QString("MainWinState-%1").arg(accountId)).toByteArray();
960 if(state.isEmpty()) {
961 foreach(BufferViewDock *view, _bufferViews)
963 _layoutLoaded = true;
967 restoreState(state, accountId);
968 int bufferViewId = s.value(QString("ActiveBufferView-%1").arg(accountId), -1).toInt();
969 if(bufferViewId >= 0)
970 changeActiveBufferView(bufferViewId);
972 _layoutLoaded = true;
975 void MainWin::saveLayout() {
977 int accountId = _bufferViews.count()? Client::currentCoreAccount().accountId().toInt() : 0; // only save if we still have a layout!
979 s.setValue(QString("MainWinState-%1").arg(accountId) , saveState(accountId));
980 BufferView *view = activeBufferView();
981 s.setValue(QString("ActiveBufferView-%1").arg(accountId), view ? view->config()->bufferViewId() : -1);
985 void MainWin::disconnectedFromCore() {
986 // save core specific layout and remove bufferviews;
988 _layoutLoaded = false;
991 BufferViewDock *dock;
992 foreach(QAction *action, _bufferViewsMenu->actions()) {
993 actionData = action->data();
994 if(!actionData.isValid())
997 dock = qobject_cast<BufferViewDock *>(action->parent());
998 if(dock && actionData.toInt() != -1) {
999 removeAction(action);
1000 _bufferViews.removeAll(dock);
1001 dock->deleteLater();
1005 // store last active buffer
1007 BufferId lastBufId = _bufferWidget->currentBuffer();
1008 if(lastBufId.isValid()) {
1009 s.setValue("LastUsedBufferId", lastBufId.toInt());
1010 // clear the current selection
1011 Client::bufferModel()->standardSelectionModel()->clearSelection();
1013 restoreState(s.value("MainWinState").toByteArray());
1014 setDisconnectedState();
1017 void MainWin::setDisconnectedState() {
1018 ActionCollection *coll = QtUi::actionCollection("General");
1019 //ui.menuCore->setEnabled(false);
1020 coll->action("ConnectCore")->setEnabled(true);
1021 coll->action("DisconnectCore")->setEnabled(false);
1022 coll->action("CoreInfo")->setEnabled(false);
1023 //_viewMenu->setEnabled(false);
1024 statusBar()->showMessage(tr("Not connected to core."));
1025 if(_msgProcessorStatusWidget)
1026 _msgProcessorStatusWidget->setProgress(0, 0);
1028 systemTray()->setState(SystemTray::Passive);
1031 void MainWin::userAuthenticationRequired(CoreAccount *account, bool *valid, const QString &errorMessage) {
1032 Q_UNUSED(errorMessage)
1033 CoreConnectAuthDlg dlg(account, this);
1034 *valid = (dlg.exec() == QDialog::Accepted);
1037 void MainWin::handleNoSslInClient(bool *accepted) {
1038 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your client does not support SSL encryption</b>"),
1039 QMessageBox::Ignore|QMessageBox::Cancel, this);
1040 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1041 box.setDefaultButton(QMessageBox::Ignore);
1042 *accepted = box.exec() == QMessageBox::Ignore;
1045 void MainWin::handleNoSslInCore(bool *accepted) {
1046 QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your core does not support SSL encryption</b>"),
1047 QMessageBox::Ignore|QMessageBox::Cancel, this);
1048 box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
1049 box.setDefaultButton(QMessageBox::Ignore);
1050 *accepted = box.exec() == QMessageBox::Ignore;
1056 void MainWin::handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently) {
1057 QString errorString = "<ul>";
1058 foreach(const QSslError error, socket->sslErrors())
1059 errorString += QString("<li>%1</li>").arg(error.errorString());
1060 errorString += "</ul>";
1062 QMessageBox box(QMessageBox::Warning,
1063 tr("Untrusted Security Certificate"),
1064 tr("<b>The SSL certificate provided by the core at %1 is untrusted for the following reasons:</b>").arg(socket->peerName()),
1065 QMessageBox::Cancel, this);
1066 box.setInformativeText(errorString);
1067 box.addButton(tr("Continue"), QMessageBox::AcceptRole);
1068 box.setDefaultButton(box.addButton(tr("Show Certificate"), QMessageBox::HelpRole));
1070 QMessageBox::ButtonRole role;
1073 role = box.buttonRole(box.clickedButton());
1074 if(role == QMessageBox::HelpRole) {
1075 SslInfoDlg dlg(socket, this);
1078 } while(role == QMessageBox::HelpRole);
1080 *accepted = role == QMessageBox::AcceptRole;
1082 QMessageBox box2(QMessageBox::Warning,
1083 tr("Untrusted Security Certificate"),
1084 tr("Would you like to accept this certificate forever without being prompted?"),
1086 box2.setDefaultButton(box2.addButton(tr("Current Session Only"), QMessageBox::NoRole));
1087 box2.addButton(tr("Forever"), QMessageBox::YesRole);
1089 *permanently = box2.buttonRole(box2.clickedButton()) == QMessageBox::YesRole;
1093 #endif /* HAVE_SSL */
1095 void MainWin::handleCoreConnectionError(const QString &error) {
1096 QMessageBox::critical(this, tr("Core Connection Error"), error, QMessageBox::Ok);
1099 void MainWin::showCoreConnectionDlg() {
1100 CoreConnectDlg dlg(this);
1101 if(dlg.exec() == QDialog::Accepted) {
1102 AccountId accId = dlg.selectedAccount();
1104 Client::coreConnection()->connectToCore(accId);
1108 void MainWin::showCoreConfigWizard(const QVariantList &backends) {
1109 CoreConfigWizard *wizard = new CoreConfigWizard(Client::coreConnection(), backends, this);
1114 void MainWin::showChannelList(NetworkId netId) {
1115 ChannelListDlg *channelListDlg = new ChannelListDlg();
1117 if(!netId.isValid()) {
1118 QAction *action = qobject_cast<QAction *>(sender());
1120 netId = action->data().value<NetworkId>();
1123 channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
1124 channelListDlg->setNetwork(netId);
1125 channelListDlg->show();
1128 void MainWin::showIgnoreList(QString newRule) {
1129 SettingsPageDlg dlg(new IgnoreListSettingsPage(this), this);
1130 // prepare config dialog for new rule
1131 if(!newRule.isEmpty())
1132 qobject_cast<IgnoreListSettingsPage *>(dlg.currentPage())->editIgnoreRule(newRule);
1136 void MainWin::showCoreInfoDlg() {
1137 CoreInfoDlg(this).exec();
1140 void MainWin::showAwayLog() {
1143 AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
1144 _awayLog = new AwayLogView(filter, 0);
1145 filter->setParent(_awayLog);
1146 connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
1147 _awayLog->setAttribute(Qt::WA_DeleteOnClose);
1151 void MainWin::awayLogDestroyed() {
1155 void MainWin::showSettingsDlg() {
1156 SettingsDlg *dlg = new SettingsDlg();
1158 //Category: Interface
1159 dlg->registerSettingsPage(new AppearanceSettingsPage(dlg));
1160 dlg->registerSettingsPage(new ChatViewSettingsPage(dlg));
1161 dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
1162 dlg->registerSettingsPage(new ItemViewSettingsPage(dlg));
1163 dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
1164 dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg));
1165 dlg->registerSettingsPage(new TopicWidgetSettingsPage(dlg));
1166 dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
1167 dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
1168 dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
1171 dlg->registerSettingsPage(new ConnectionSettingsPage(dlg));
1172 dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
1173 dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
1174 dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
1175 dlg->registerSettingsPage(new IgnoreListSettingsPage(dlg));
1177 // Category: Remote Cores
1178 if(Quassel::runMode() != Quassel::Monolithic) {
1179 dlg->registerSettingsPage(new CoreAccountSettingsPage(dlg));
1180 dlg->registerSettingsPage(new CoreConnectionSettingsPage(dlg));
1186 void MainWin::showAboutDlg() {
1187 AboutDlg(this).exec();
1190 void MainWin::showShortcutsDlg() {
1192 KShortcutsDialog dlg(KShortcutsEditor::AllActions, KShortcutsEditor::LetterShortcutsDisallowed, this);
1193 foreach(KActionCollection *coll, QtUi::actionCollections())
1194 dlg.addCollection(coll, coll->property("Category").toString());
1197 SettingsPageDlg dlg(new ShortcutsSettingsPage(QtUi::actionCollections(), this), this);
1202 void MainWin::toggleFullscreen() {
1209 /********************************************************************************************************/
1211 bool MainWin::event(QEvent *event) {
1212 if(event->type() == QEvent::WindowActivate) {
1213 BufferId buffer = Client::bufferModel()->currentBuffer();
1214 if(buffer.isValid())
1215 Client::instance()->markBufferAsRead(buffer);
1217 return QMainWindow::event(event);
1220 void MainWin::moveEvent(QMoveEvent *event) {
1221 if(!(windowState() & Qt::WindowMaximized))
1222 _normalPos = event->pos();
1224 QMainWindow::moveEvent(event);
1227 void MainWin::resizeEvent(QResizeEvent *event) {
1228 if(!(windowState() & Qt::WindowMaximized))
1229 _normalSize = event->size();
1231 QMainWindow::resizeEvent(event);
1234 void MainWin::closeEvent(QCloseEvent *event) {
1236 QtUiApplication* app = qobject_cast<QtUiApplication*> qApp;
1238 if(!app->isAboutToQuit() && QtUi::haveSystemTray() && s.value("MinimizeOnClose").toBool()) {
1239 QtUi::hideMainWidget();
1247 void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) {
1250 bool hasFocus = QApplication::activeWindow() != 0;
1252 for(int i = start; i <= end; i++) {
1253 QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn);
1254 if(!idx.isValid()) {
1255 qDebug() << "MainWin::messagesInserted(): Invalid model index!";
1258 Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt();
1259 if(flags.testFlag(Message::Backlog) || flags.testFlag(Message::Self))
1262 BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value<BufferId>();
1263 BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId);
1265 if(hasFocus && bufId == Client::bufferModel()->currentBuffer())
1268 if((flags & Message::Highlight || bufType == BufferInfo::QueryBuffer)
1269 && !(Client::ignoreListManager() && Client::ignoreListManager()->match(idx.data(MessageModel::MessageRole).value<Message>(),
1270 Client::networkModel()->networkName(bufId))))
1272 QModelIndex senderIdx = Client::messageModel()->index(i, ChatLineModel::SenderColumn);
1273 QString sender = senderIdx.data(ChatLineModel::EditRole).toString();
1274 QString contents = idx.data(ChatLineModel::DisplayRole).toString();
1275 AbstractNotificationBackend::NotificationType type;
1277 if(bufType == BufferInfo::QueryBuffer && !hasFocus)
1278 type = AbstractNotificationBackend::PrivMsg;
1279 else if(bufType == BufferInfo::QueryBuffer && hasFocus)
1280 type = AbstractNotificationBackend::PrivMsgFocused;
1281 else if(flags & Message::Highlight && !hasFocus)
1282 type = AbstractNotificationBackend::Highlight;
1284 type = AbstractNotificationBackend::HighlightFocused;
1286 QtUi::instance()->invokeNotification(bufId, type, sender, contents);
1291 void MainWin::currentBufferChanged(BufferId buffer) {
1292 if(buffer.isValid())
1293 Client::instance()->markBufferAsRead(buffer);
1296 void MainWin::clientNetworkCreated(NetworkId id) {
1297 const Network *net = Client::network(id);
1298 QAction *act = new QAction(net->networkName(), this);
1299 act->setObjectName(QString("NetworkAction-%1").arg(id.toInt()));
1300 act->setData(QVariant::fromValue<NetworkId>(id));
1301 connect(net, SIGNAL(updatedRemotely()), this, SLOT(clientNetworkUpdated()));
1302 connect(act, SIGNAL(triggered()), this, SLOT(connectOrDisconnectFromNet()));
1304 QAction *beforeAction = 0;
1305 foreach(QAction *action, _networksMenu->actions()) {
1306 if(!action->data().isValid()) // ignore stock actions
1308 if(net->networkName().localeAwareCompare(action->text()) < 0) {
1309 beforeAction = action;
1313 _networksMenu->insertAction(beforeAction, act);
1316 void MainWin::clientNetworkUpdated() {
1317 const Network *net = qobject_cast<const Network *>(sender());
1321 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(net->networkId().toInt()));
1325 action->setText(net->networkName());
1327 switch(net->connectionState()) {
1328 case Network::Initialized:
1329 action->setIcon(SmallIcon("network-connect"));
1330 // if we have no currently selected buffer, jump to the first connecting statusbuffer
1331 if(!bufferWidget()->currentBuffer().isValid()) {
1332 QModelIndex idx = Client::networkModel()->networkIndex(net->networkId());
1334 BufferId statusBufferId = idx.data(NetworkModel::BufferIdRole).value<BufferId>();
1335 Client::bufferModel()->switchToBuffer(statusBufferId);
1339 case Network::Disconnected:
1340 action->setIcon(SmallIcon("network-disconnect"));
1343 action->setIcon(SmallIcon("network-wired"));
1347 void MainWin::clientNetworkRemoved(NetworkId id) {
1348 QAction *action = findChild<QAction *>(QString("NetworkAction-%1").arg(id.toInt()));
1352 action->deleteLater();
1355 void MainWin::connectOrDisconnectFromNet() {
1356 QAction *act = qobject_cast<QAction *>(sender());
1358 const Network *net = Client::network(act->data().value<NetworkId>());
1360 if(net->connectionState() == Network::Disconnected) net->requestConnect();
1361 else net->requestDisconnect();
1364 void MainWin::on_jumpHotBuffer_triggered() {
1365 if(!_bufferHotList->rowCount())
1368 QModelIndex topIndex = _bufferHotList->index(0, 0);
1369 BufferId bufferId = _bufferHotList->data(topIndex, NetworkModel::BufferIdRole).value<BufferId>();
1370 Client::bufferModel()->switchToBuffer(bufferId);
1373 void MainWin::onJumpKey() {
1374 QAction *action = qobject_cast<QAction *>(sender());
1375 if(!action || !Client::bufferModel())
1377 int idx = action->property("Index").toInt();
1379 if(_jumpKeyMap.isEmpty())
1380 _jumpKeyMap = CoreAccountSettings().jumpKeyMap();
1382 if(!_jumpKeyMap.contains(idx))
1385 BufferId buffer = _jumpKeyMap.value(idx);
1386 if(buffer.isValid())
1387 Client::bufferModel()->switchToBuffer(buffer);
1391 void MainWin::bindJumpKey() {
1392 QAction *action = qobject_cast<QAction *>(sender());
1393 if(!action || !Client::bufferModel())
1395 int idx = action->property("Index").toInt();
1397 _jumpKeyMap[idx] = Client::bufferModel()->currentBuffer();
1398 CoreAccountSettings().setJumpKeyMap(_jumpKeyMap);
1401 void MainWin::on_actionDebugNetworkModel_triggered() {
1402 QTreeView *view = new QTreeView;
1403 view->setAttribute(Qt::WA_DeleteOnClose);
1404 view->setWindowTitle("Debug NetworkModel View");
1405 view->setModel(Client::networkModel());
1406 view->setColumnWidth(0, 250);
1407 view->setColumnWidth(1, 250);
1408 view->setColumnWidth(2, 80);
1409 view->resize(610, 300);
1413 void MainWin::on_actionDebugHotList_triggered() {
1414 QTreeView *view = new QTreeView;
1415 view->setAttribute(Qt::WA_DeleteOnClose);
1416 view->setModel(_bufferHotList);
1420 void MainWin::on_actionDebugBufferViewOverlay_triggered() {
1421 DebugBufferViewOverlay *overlay = new DebugBufferViewOverlay(0);
1422 overlay->setAttribute(Qt::WA_DeleteOnClose);
1426 void MainWin::on_actionDebugMessageModel_triggered() {
1427 QTableView *view = new QTableView(0);
1428 DebugMessageModelFilter *filter = new DebugMessageModelFilter(view);
1429 filter->setSourceModel(Client::messageModel());
1430 view->setModel(filter);
1431 view->setAttribute(Qt::WA_DeleteOnClose, true);
1432 view->verticalHeader()->hide();
1433 view->horizontalHeader()->setStretchLastSection(true);
1437 void MainWin::on_actionDebugLog_triggered() {
1438 DebugLogWidget *logWidget = new DebugLogWidget(0);
1442 void MainWin::showStatusBarMessage(const QString &message) {
1443 statusBar()->showMessage(message, 10000);