+ changeActiveBufferView(true);
+}
+
+
+void MainWin::nextBuffer()
+{
+ BufferView *view = activeBufferView();
+ if (view)
+ view->nextBuffer();
+}
+
+
+void MainWin::previousBuffer()
+{
+ BufferView *view = activeBufferView();
+ if (view)
+ view->previousBuffer();
+}
+
+
+void MainWin::hideCurrentBuffer()
+{
+ BufferView *view = activeBufferView();
+ if (view)
+ view->hideCurrentBuffer();
+}
+
+
+void MainWin::showNotificationsDlg()
+{
+ SettingsPageDlg dlg(new NotificationsSettingsPage(this), this);
+ dlg.exec();
+}
+
+
+void MainWin::on_actionConfigureNetworks_triggered()
+{
+ SettingsPageDlg dlg(new NetworksSettingsPage(this), this);
+ dlg.exec();
+}
+
+
+void MainWin::on_actionConfigureViews_triggered()
+{
+ SettingsPageDlg dlg(new BufferViewSettingsPage(this), this);
+ dlg.exec();
+}
+
+
+void MainWin::on_actionLockLayout_toggled(bool lock)
+{
+ QList<VerticalDock *> docks = findChildren<VerticalDock *>();
+ foreach(VerticalDock *dock, docks) {
+ dock->showTitle(!lock);
+ }
+ if (Client::bufferViewManager()) {
+ foreach(ClientBufferViewConfig *config, Client::bufferViewManager()->clientBufferViewConfigs()) {
+ config->setLocked(lock);
+ }
+ }
+ QtUiSettings().setValue("LockLayout", lock);
+}
+
+
+void MainWin::setupNickWidget()
+{
+ // create nick dock
+ NickListDock *nickDock = new NickListDock(tr("Nicks"), this);
+ nickDock->setObjectName("NickDock");
+ nickDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
+
+ _nickListWidget = new NickListWidget(nickDock);
+ nickDock->setWidget(_nickListWidget);
+
+ addDockWidget(Qt::RightDockWidgetArea, nickDock);
+ _viewMenu->addAction(nickDock->toggleViewAction());
+ nickDock->toggleViewAction()->setText(tr("Show Nick List"));
+
+ // See NickListDock::NickListDock();
+ // connect(nickDock->toggleViewAction(), SIGNAL(triggered(bool)), nickListWidget, SLOT(showWidget(bool)));
+
+ // attach the NickListWidget to the BufferModel and the default selection
+ _nickListWidget->setModel(Client::bufferModel());
+ _nickListWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
+}
+
+
+void MainWin::setupChatMonitor()
+{
+ VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this);
+ dock->setObjectName("ChatMonitorDock");
+
+ ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this);
+ _chatMonitorView = new ChatMonitorView(filter, this);
+ _chatMonitorView->setFocusProxy(_inputWidget);
+ _chatMonitorView->show();
+ dock->setWidget(_chatMonitorView);
+ dock->hide();
+
+ addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
+ _viewMenu->addAction(dock->toggleViewAction());
+ dock->toggleViewAction()->setText(tr("Show Chat Monitor"));
+}
+
+
+void MainWin::setupInputWidget()
+{
+ VerticalDock *dock = new VerticalDock(tr("Inputline"), this);
+ dock->setObjectName("InputDock");
+
+ _inputWidget = new InputWidget(dock);
+ dock->setWidget(_inputWidget);
+
+ addDockWidget(Qt::BottomDockWidgetArea, dock);
+
+ _viewMenu->addAction(dock->toggleViewAction());
+ dock->toggleViewAction()->setText(tr("Show Input Line"));
+
+ _inputWidget->setModel(Client::bufferModel());
+ _inputWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
+
+ _bufferWidget->setFocusProxy(_inputWidget);
+
+ _inputWidget->inputLine()->installEventFilter(_bufferWidget);
+
+ connect(_topicWidget, SIGNAL(switchedPlain()), _bufferWidget, SLOT(setFocus()));
+}
+
+
+void MainWin::setupTopicWidget()
+{
+ VerticalDock *dock = new VerticalDock(tr("Topic"), this);
+ dock->setObjectName("TopicDock");
+ _topicWidget = new TopicWidget(dock);
+
+ dock->setWidget(_topicWidget);
+
+ _topicWidget->setModel(Client::bufferModel());
+ _topicWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel());
+
+ addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical);
+
+ _viewMenu->addAction(dock->toggleViewAction());
+ dock->toggleViewAction()->setText(tr("Show Topic Line"));
+}
+
+
+void MainWin::setupViewMenuTail()
+{
+ _viewMenu->addSeparator();
+ _viewMenu->addAction(QtUi::actionCollection("General")->action("ToggleFullscreen"));
+}
+
+
+void MainWin::setupTitleSetter()
+{
+ _titleSetter.setModel(Client::bufferModel());
+ _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel());
+}
+
+
+void MainWin::setupStatusBar()
+{
+ // MessageProcessor progress
+ statusBar()->addPermanentWidget(_msgProcessorStatusWidget);
+
+ // Connection state
+ _coreConnectionStatusWidget->update();
+ statusBar()->addPermanentWidget(_coreConnectionStatusWidget);
+
+ QAction *showStatusbar = QtUi::actionCollection("General")->action("ToggleStatusBar");
+
+ QtUiSettings uiSettings;
+
+ bool enabled = uiSettings.value("ShowStatusBar", QVariant(true)).toBool();
+ showStatusbar->setChecked(enabled);
+ enabled ? statusBar()->show() : statusBar()->hide();
+
+ connect(showStatusbar, SIGNAL(toggled(bool)), statusBar(), SLOT(setVisible(bool)));
+ connect(showStatusbar, SIGNAL(toggled(bool)), this, SLOT(saveStatusBarStatus(bool)));
+
+ connect(Client::coreConnection(), SIGNAL(connectionMsg(QString)), statusBar(), SLOT(showMessage(QString)));
+}
+
+
+void MainWin::setupHotList()
+{
+ FlatProxyModel *flatProxy = new FlatProxyModel(this);
+ flatProxy->setSourceModel(Client::bufferModel());
+ _bufferHotList = new BufferHotListFilter(flatProxy);
+}
+
+
+void MainWin::saveMenuBarStatus(bool enabled)
+{
+ QtUiSettings uiSettings;
+ uiSettings.setValue("ShowMenuBar", enabled);
+}
+
+
+void MainWin::saveStatusBarStatus(bool enabled)
+{
+ QtUiSettings uiSettings;
+ uiSettings.setValue("ShowStatusBar", enabled);
+}
+
+
+void MainWin::setupSystray()
+{
+#ifdef HAVE_DBUS
+ _systemTray = new StatusNotifierItem(this);
+#elif !defined QT_NO_SYSTEMTRAYICON
+ _systemTray = new LegacySystemTray(this);
+#else
+ _systemTray = new SystemTray(this); // dummy
+#endif
+ _systemTray->init();
+}
+
+
+void MainWin::setupToolBars()
+{
+ connect(_bufferWidget, SIGNAL(currentChanged(QModelIndex)),
+ QtUi::toolBarActionProvider(), SLOT(currentBufferChanged(QModelIndex)));
+ connect(_nickListWidget, SIGNAL(nickSelectionChanged(QModelIndexList)),
+ QtUi::toolBarActionProvider(), SLOT(nickSelectionChanged(QModelIndexList)));
+
+#ifdef Q_WS_MAC
+ setUnifiedTitleAndToolBarOnMac(true);
+#endif
+
+#ifdef HAVE_KDE
+ _mainToolBar = new KToolBar("MainToolBar", this, Qt::TopToolBarArea, false, true, true);
+#else
+ _mainToolBar = new QToolBar(this);
+ _mainToolBar->setObjectName("MainToolBar");
+#endif
+ _mainToolBar->setWindowTitle(tr("Main Toolbar"));
+ addToolBar(_mainToolBar);
+
+ QtUi::toolBarActionProvider()->addActions(_mainToolBar, ToolBarActionProvider::MainToolBar);
+ _toolbarMenu->addAction(_mainToolBar->toggleViewAction());
+}
+
+
+void MainWin::connectedToCore()
+{
+ Q_CHECK_PTR(Client::bufferViewManager());
+ connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigAdded(int)), this, SLOT(addBufferView(int)));
+ connect(Client::bufferViewManager(), SIGNAL(bufferViewConfigDeleted(int)), this, SLOT(removeBufferView(int)));
+ connect(Client::bufferViewManager(), SIGNAL(initDone()), this, SLOT(loadLayout()));
+
+ setConnectedState();
+}
+
+
+void MainWin::setConnectedState()
+{
+ ActionCollection *coll = QtUi::actionCollection("General");
+
+ coll->action("ConnectCore")->setEnabled(false);
+ coll->action("DisconnectCore")->setEnabled(true);
+ coll->action("CoreInfo")->setEnabled(true);
+
+ foreach(QAction *action, _fileMenu->actions()) {
+ if (isRemoteCoreOnly(action))
+ action->setVisible(!Client::internalCore());
+ }
+
+ disconnect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
+ disconnect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
+ disconnect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
+ if (!Client::internalCore()) {
+ connect(Client::backlogManager(), SIGNAL(updateProgress(int, int)), _msgProcessorStatusWidget, SLOT(setProgress(int, int)));
+ connect(Client::backlogManager(), SIGNAL(messagesRequested(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
+ connect(Client::backlogManager(), SIGNAL(messagesProcessed(const QString &)), this, SLOT(showStatusBarMessage(const QString &)));
+ }
+
+ // _viewMenu->setEnabled(true);
+ if (!Client::internalCore())
+ statusBar()->showMessage(tr("Connected to core."));
+ else
+ statusBar()->clearMessage();
+
+ _coreConnectionStatusWidget->setVisible(!Client::internalCore());
+ updateIcon();
+ systemTray()->setState(SystemTray::Active);
+
+ if (Client::networkIds().isEmpty()) {
+ IrcConnectionWizard *wizard = new IrcConnectionWizard(this, Qt::Sheet);
+ wizard->show();
+ }
+ else {
+ // Monolithic always preselects last used buffer - Client only if the connection died
+ if (Client::coreConnection()->wasReconnect() || Quassel::runMode() == Quassel::Monolithic) {
+ QtUiSettings s;
+ BufferId lastUsedBufferId(s.value("LastUsedBufferId").toInt());
+ if (lastUsedBufferId.isValid())
+ Client::bufferModel()->switchToBuffer(lastUsedBufferId);
+ }
+ }
+}
+
+
+void MainWin::loadLayout()
+{
+ QtUiSettings s;
+ int accountId = Client::currentCoreAccount().accountId().toInt();
+ QByteArray state = s.value(QString("MainWinState-%1").arg(accountId)).toByteArray();
+ if (state.isEmpty()) {
+ foreach(BufferViewDock *view, _bufferViews)
+ view->show();
+ _layoutLoaded = true;
+ return;
+ }
+
+ restoreState(state, accountId);
+ int bufferViewId = s.value(QString("ActiveBufferView-%1").arg(accountId), -1).toInt();
+ if (bufferViewId >= 0)
+ changeActiveBufferView(bufferViewId);
+
+ _layoutLoaded = true;
+}
+
+
+void MainWin::saveLayout()
+{
+ QtUiSettings s;
+ int accountId = _bufferViews.count() ? Client::currentCoreAccount().accountId().toInt() : 0; // only save if we still have a layout!
+ if (accountId > 0) {
+ s.setValue(QString("MainWinState-%1").arg(accountId), saveState(accountId));
+ BufferView *view = activeBufferView();
+ s.setValue(QString("ActiveBufferView-%1").arg(accountId), view ? view->config()->bufferViewId() : -1);
+ }
+}
+
+
+void MainWin::disconnectedFromCore()
+{
+ // save core specific layout and remove bufferviews;
+ saveLayout();
+ _layoutLoaded = false;
+
+ QVariant actionData;
+ BufferViewDock *dock;
+ foreach(QAction *action, _bufferViewsMenu->actions()) {
+ actionData = action->data();
+ if (!actionData.isValid())
+ continue;
+
+ dock = qobject_cast<BufferViewDock *>(action->parent());
+ if (dock && actionData.toInt() != -1) {
+ removeAction(action);
+ _bufferViews.removeAll(dock);
+ dock->deleteLater();
+ }
+ }
+
+ // store last active buffer
+ QtUiSettings s;
+ BufferId lastBufId = _bufferWidget->currentBuffer();
+ if (lastBufId.isValid()) {
+ s.setValue("LastUsedBufferId", lastBufId.toInt());
+ // clear the current selection
+ Client::bufferModel()->standardSelectionModel()->clearSelection();
+ }
+ restoreState(s.value("MainWinState").toByteArray());
+ setDisconnectedState();
+}
+
+
+void MainWin::setDisconnectedState()
+{
+ ActionCollection *coll = QtUi::actionCollection("General");
+ //ui.menuCore->setEnabled(false);
+ coll->action("ConnectCore")->setEnabled(true);
+ coll->action("DisconnectCore")->setEnabled(false);
+ coll->action("CoreInfo")->setEnabled(false);
+ //_viewMenu->setEnabled(false);
+ statusBar()->showMessage(tr("Not connected to core."));
+ if (_msgProcessorStatusWidget)
+ _msgProcessorStatusWidget->setProgress(0, 0);
+ updateIcon();
+ systemTray()->setState(SystemTray::Passive);
+}
+
+
+void MainWin::userAuthenticationRequired(CoreAccount *account, bool *valid, const QString &errorMessage)
+{
+ Q_UNUSED(errorMessage)
+ CoreConnectAuthDlg dlg(account, this);
+ *valid = (dlg.exec() == QDialog::Accepted);
+}
+
+
+void MainWin::handleNoSslInClient(bool *accepted)
+{
+ QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your client does not support SSL encryption</b>"),
+ QMessageBox::Ignore|QMessageBox::Cancel, this);
+ box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
+ box.setDefaultButton(QMessageBox::Ignore);
+ *accepted = box.exec() == QMessageBox::Ignore;
+}
+
+
+void MainWin::handleNoSslInCore(bool *accepted)
+{
+ QMessageBox box(QMessageBox::Warning, tr("Unencrypted Connection"), tr("<b>Your core does not support SSL encryption</b>"),
+ QMessageBox::Ignore|QMessageBox::Cancel, this);
+ box.setInformativeText(tr("Sensitive data, like passwords, will be transmitted unencrypted to your Quassel core."));
+ box.setDefaultButton(QMessageBox::Ignore);
+ *accepted = box.exec() == QMessageBox::Ignore;
+}
+
+
+#ifdef HAVE_SSL
+
+void MainWin::handleSslErrors(const QSslSocket *socket, bool *accepted, bool *permanently)
+{
+ QString errorString = "<ul>";
+ foreach(const QSslError error, socket->sslErrors())
+ errorString += QString("<li>%1</li>").arg(error.errorString());
+ errorString += "</ul>";
+
+ QMessageBox box(QMessageBox::Warning,
+ tr("Untrusted Security Certificate"),
+ tr("<b>The SSL certificate provided by the core at %1 is untrusted for the following reasons:</b>").arg(socket->peerName()),
+ QMessageBox::Cancel, this);
+ box.setInformativeText(errorString);
+ box.addButton(tr("Continue"), QMessageBox::AcceptRole);
+ box.setDefaultButton(box.addButton(tr("Show Certificate"), QMessageBox::HelpRole));
+
+ QMessageBox::ButtonRole role;
+ do {
+ box.exec();
+ role = box.buttonRole(box.clickedButton());
+ if (role == QMessageBox::HelpRole) {
+ SslInfoDlg dlg(socket, this);
+ dlg.exec();
+ }
+ }
+ while (role == QMessageBox::HelpRole);
+
+ *accepted = role == QMessageBox::AcceptRole;
+ if (*accepted) {
+ QMessageBox box2(QMessageBox::Warning,
+ tr("Untrusted Security Certificate"),
+ tr("Would you like to accept this certificate forever without being prompted?"),
+ 0, this);
+ box2.setDefaultButton(box2.addButton(tr("Current Session Only"), QMessageBox::NoRole));
+ box2.addButton(tr("Forever"), QMessageBox::YesRole);
+ box2.exec();
+ *permanently = box2.buttonRole(box2.clickedButton()) == QMessageBox::YesRole;
+ }
+}
+
+
+#endif /* HAVE_SSL */
+
+void MainWin::handleCoreConnectionError(const QString &error)
+{
+ QMessageBox::critical(this, tr("Core Connection Error"), error, QMessageBox::Ok);
+}
+
+
+void MainWin::showCoreConnectionDlg()
+{
+ CoreConnectDlg dlg(this);
+ if (dlg.exec() == QDialog::Accepted) {
+ AccountId accId = dlg.selectedAccount();
+ if (accId.isValid())
+ Client::coreConnection()->connectToCore(accId);
+ }
+}
+
+
+void MainWin::showCoreConfigWizard(const QVariantList &backends)
+{
+ CoreConfigWizard *wizard = new CoreConfigWizard(Client::coreConnection(), backends, this);
+
+ wizard->show();
+}
+
+
+void MainWin::showChannelList(NetworkId netId)
+{
+ ChannelListDlg *channelListDlg = new ChannelListDlg();
+
+ if (!netId.isValid()) {
+ QAction *action = qobject_cast<QAction *>(sender());
+ if (action)
+ netId = action->data().value<NetworkId>();
+ }
+
+ channelListDlg->setAttribute(Qt::WA_DeleteOnClose);
+ channelListDlg->setNetwork(netId);
+ channelListDlg->show();
+}
+
+
+void MainWin::showIgnoreList(QString newRule)
+{
+ SettingsPageDlg dlg(new IgnoreListSettingsPage(this), this);
+ // prepare config dialog for new rule
+ if (!newRule.isEmpty())
+ qobject_cast<IgnoreListSettingsPage *>(dlg.currentPage())->editIgnoreRule(newRule);
+ dlg.exec();
+}
+
+
+void MainWin::showCoreInfoDlg()
+{
+ CoreInfoDlg(this).exec();
+}
+
+
+void MainWin::showAwayLog()
+{
+ if (_awayLog)
+ return;
+ AwayLogFilter *filter = new AwayLogFilter(Client::messageModel());
+ _awayLog = new AwayLogView(filter, 0);
+ filter->setParent(_awayLog);
+ connect(_awayLog, SIGNAL(destroyed()), this, SLOT(awayLogDestroyed()));
+ _awayLog->setAttribute(Qt::WA_DeleteOnClose);
+ _awayLog->show();
+}
+
+
+void MainWin::awayLogDestroyed()
+{
+ _awayLog = 0;
+}
+
+
+void MainWin::showSettingsDlg()
+{
+ SettingsDlg *dlg = new SettingsDlg();
+
+ //Category: Interface
+ dlg->registerSettingsPage(new AppearanceSettingsPage(dlg));
+ dlg->registerSettingsPage(new ChatViewSettingsPage(dlg));
+ dlg->registerSettingsPage(new ChatMonitorSettingsPage(dlg));
+ dlg->registerSettingsPage(new ItemViewSettingsPage(dlg));
+ dlg->registerSettingsPage(new BufferViewSettingsPage(dlg));
+ dlg->registerSettingsPage(new InputWidgetSettingsPage(dlg));
+ dlg->registerSettingsPage(new TopicWidgetSettingsPage(dlg));
+ dlg->registerSettingsPage(new HighlightSettingsPage(dlg));
+ dlg->registerSettingsPage(new NotificationsSettingsPage(dlg));
+ dlg->registerSettingsPage(new BacklogSettingsPage(dlg));
+
+ //Category: IRC
+ dlg->registerSettingsPage(new ConnectionSettingsPage(dlg));
+ dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg));
+ dlg->registerSettingsPage(new NetworksSettingsPage(dlg));
+ dlg->registerSettingsPage(new AliasesSettingsPage(dlg));
+ dlg->registerSettingsPage(new IgnoreListSettingsPage(dlg));
+
+ // Category: Remote Cores
+ if (Quassel::runMode() != Quassel::Monolithic) {
+ dlg->registerSettingsPage(new CoreAccountSettingsPage(dlg));
+ dlg->registerSettingsPage(new CoreConnectionSettingsPage(dlg));
+ }
+
+ dlg->show();