X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fmainwin.cpp;h=caecd84ae986d80b1f053b5f4557758e7a10316e;hp=7d22ac6f89f1fc486cfdf794fa8b26bbf17b4724;hb=85b55cf023c96f4dbd61ec415a15214f99e281b3;hpb=5931bed270b86e110480561a2bf665dc59747280 diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index 7d22ac6f..caecd84a 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -20,16 +20,23 @@ #include "mainwin.h" #include "aboutdlg.h" -#include "chatwidget.h" #include "bufferview.h" #include "bufferviewconfig.h" #include "bufferviewfilter.h" #include "bufferviewmanager.h" #include "channellistdlg.h" +#include "chatlinemodel.h" +#include "chatmonitorfilter.h" +#include "chatmonitorview.h" +#include "chatview.h" +#include "chatviewsearchbar.h" #include "client.h" #include "clientbacklogmanager.h" #include "coreinfodlg.h" #include "coreconnectdlg.h" +#include "msgprocessorstatuswidget.h" +#include "qtuimessageprocessor.h" +#include "qtuiapplication.h" #include "networkmodel.h" #include "buffermodel.h" #include "nicklistwidget.h" @@ -41,11 +48,9 @@ #include "irclistmodel.h" #include "verticaldock.h" #include "uisettings.h" -#include "util.h" #include "qtuisettings.h" #include "jumpkeyhandler.h" - -#include "uisettings.h" +#include "sessionsettings.h" #include "selectionmodelsynchronizer.h" #include "mappedselectionmodel.h" @@ -59,44 +64,33 @@ #include "settingspages/highlightsettingspage.h" #include "settingspages/identitiessettingspage.h" #include "settingspages/networkssettingspage.h" +#include "settingspages/notificationssettingspage.h" - -#include "debugconsole.h" #include "global.h" #include "qtuistyle.h" -#include "desktopnotifications.h" - - -MainWin::MainWin(QtUi *_gui, QWidget *parent) +MainWin::MainWin(QWidget *parent) : QMainWindow(parent), - gui(_gui), coreLagLabel(new QLabel()), sslLabel(new QLabel()), + msgProcessorStatusWidget(new MsgProcessorStatusWidget()), + _titleSetter(this), systray(new QSystemTrayIcon(this)), + activeTrayIcon(":/icons/quassel-icon-active.png"), onlineTrayIcon(":/icons/quassel-icon.png"), offlineTrayIcon(":/icons/quassel-icon-offline.png"), trayIconActive(false), - timer(new QTimer(this)), - channelListDlg(new ChannelListDlg(this)), - settingsDlg(new SettingsDlg(this)), - debugConsole(new DebugConsole(this)), - desktopNotifications(new org::freedesktop::Notifications( - "org.freedesktop.Notifications", - "/org/freedesktop/Notifications", - QDBusConnection::sessionBus(), this)), - notificationId(0) + + timer(new QTimer(this)) { UiSettings uiSettings; - loadTranslation(uiSettings.value("Locale", QLocale::system()).value()); - QString style = uiSettings.value("Style", QString("")).toString(); if(style != "") { QApplication::setStyle(style); } - + ui.setupUi(this); setWindowTitle("Quassel IRC"); setWindowIcon(offlineTrayIcon); @@ -108,14 +102,18 @@ MainWin::MainWin(QtUi *_gui, QWidget *parent) installEventFilter(new JumpKeyHandler(this)); - UiSettings uiSettings; - QString style = uiSettings.value("Style", QString("")).toString(); - if(style != "") { - QApplication::setStyle(style); - } - +#ifdef HAVE_DBUS + desktopNotifications = new org::freedesktop::Notifications( + "org.freedesktop.Notifications", + "/org/freedesktop/Notifications", + QDBusConnection::sessionBus(), this); + notificationId = 0; connect(desktopNotifications, SIGNAL(NotificationClosed(uint, uint)), this, SLOT(desktopNotificationClosed(uint, uint))); connect(desktopNotifications, SIGNAL(ActionInvoked(uint, const QString&)), this, SLOT(desktopNotificationInvoked(uint, const QString&))); +#endif + QtUiApplication* app = qobject_cast qApp; + connect(app, SIGNAL(saveStateToSession(const QString&)), this, SLOT(saveStateToSession(const QString&))); + connect(app, SIGNAL(saveStateToSessionSettings(SessionSettings&)), this, SLOT(saveStateToSessionSettings(SessionSettings&))); } void MainWin::init() { @@ -125,8 +123,6 @@ void MainWin::init() { else resize(QSize(800, 500)); - Client::signalProxy()->attachSignal(this, SIGNAL(requestBacklog(BufferInfo, QVariant, QVariant))); - connect(QApplication::instance(), SIGNAL(aboutToQuit()), this, SLOT(saveLayout())); connect(Client::instance(), SIGNAL(networkCreated(NetworkId)), this, SLOT(clientNetworkCreated(NetworkId))); @@ -154,14 +150,11 @@ void MainWin::init() { setupStatusBar(); setupSystray(); - setupSettingsDlg(); - // restore mainwin state restoreState(s.value("MainWinState").toByteArray()); - // restore locked state of docks + // restore locked state of docks ui.actionLockDockPositions->setChecked(s.value("LockDocks", false).toBool()); - setDisconnectedState(); // Disable menus and stuff showCoreConnectionDlg(true); // autoconnect if appropriate @@ -169,6 +162,7 @@ void MainWin::init() { // attach the BufferWidget to the BufferModel and the default selection ui.bufferWidget->setModel(Client::bufferModel()); ui.bufferWidget->setSelectionModel(Client::bufferModel()->standardSelectionModel()); + ui.menuViews->addAction(ui.bufferWidget->searchBar()->toggleViewAction()); _titleSetter.setModel(Client::bufferModel()); _titleSetter.setSelectionModel(Client::bufferModel()->standardSelectionModel()); @@ -187,7 +181,6 @@ void MainWin::setupMenus() { connect(ui.actionCoreInfo, SIGNAL(triggered()), this, SLOT(showCoreInfoDlg())); connect(ui.actionQuit, SIGNAL(triggered()), QCoreApplication::instance(), SLOT(quit())); connect(ui.actionSettingsDlg, SIGNAL(triggered()), this, SLOT(showSettingsDlg())); - // connect(ui.actionDebug_Console, SIGNAL(triggered()), this, SLOT(showDebugConsole())); connect(ui.actionAboutQuassel, SIGNAL(triggered()), this, SLOT(showAboutDlg())); connect(ui.actionAboutQt, SIGNAL(triggered()), QApplication::instance(), SLOT(aboutQt())); } @@ -213,7 +206,7 @@ void MainWin::addBufferView(BufferViewConfig *config) { view->show(); connect(&view->showChannelList, SIGNAL(triggered()), this, SLOT(showChannelList())); - + Client::bufferModel()->synchronizeView(view); dock->setWidget(view); @@ -241,21 +234,6 @@ void MainWin::removeBufferView(int bufferViewConfigId) { } } -void MainWin::setupSettingsDlg() { - //Category: Appearance - settingsDlg->registerSettingsPage(new ColorSettingsPage(settingsDlg)); - settingsDlg->registerSettingsPage(new FontsSettingsPage(settingsDlg)); - settingsDlg->registerSettingsPage(new AppearanceSettingsPage(settingsDlg)); //General - //Category: Behaviour - settingsDlg->registerSettingsPage(new GeneralSettingsPage(settingsDlg)); - settingsDlg->registerSettingsPage(new HighlightSettingsPage(settingsDlg)); - settingsDlg->registerSettingsPage(new AliasesSettingsPage(settingsDlg)); - //Category: General - settingsDlg->registerSettingsPage(new IdentitiesSettingsPage(settingsDlg)); - settingsDlg->registerSettingsPage(new NetworksSettingsPage(settingsDlg)); - settingsDlg->registerSettingsPage(new BufferViewSettingsPage(settingsDlg)); -} - void MainWin::on_actionEditNetworks_triggered() { SettingsPageDlg dlg(new NetworksSettingsPage(this), this); dlg.exec(); @@ -294,26 +272,17 @@ void MainWin::setupNickWidget() { } void MainWin::setupChatMonitor() { -#ifndef SPUTDEV VerticalDock *dock = new VerticalDock(tr("Chat Monitor"), this); dock->setObjectName("ChatMonitorDock"); - ChatWidget *chatWidget = new ChatWidget(0, this); - chatWidget->show(); - dock->setWidget(chatWidget); + ChatMonitorFilter *filter = new ChatMonitorFilter(Client::messageModel(), this); + ChatMonitorView *chatView = new ChatMonitorView(filter, this); + chatView->show(); + dock->setWidget(chatView); dock->show(); - Buffer *buf = Client::monitorBuffer(); - if(!buf) - return; - - chatWidget->setContents(buf->contents()); - connect(buf, SIGNAL(msgAppended(AbstractUiMsg *)), chatWidget, SLOT(appendMsg(AbstractUiMsg *))); - connect(buf, SIGNAL(msgPrepended(AbstractUiMsg *)), chatWidget, SLOT(prependMsg(AbstractUiMsg *))); - addDockWidget(Qt::TopDockWidgetArea, dock, Qt::Vertical); ui.menuViews->addAction(dock->toggleViewAction()); -#endif /* SPUTDEV */ } void MainWin::setupInputWidget() { @@ -337,7 +306,6 @@ void MainWin::setupTopicWidget() { VerticalDock *dock = new VerticalDock(tr("Topic"), this); dock->setObjectName("TopicDock"); TopicWidget *topicwidget = new TopicWidget(dock); - connect(topicwidget, SIGNAL(topicChanged(const QString &)), this, SLOT(changeTopic(const QString &))); dock->setWidget(topicwidget); @@ -350,6 +318,10 @@ void MainWin::setupTopicWidget() { } void MainWin::setupStatusBar() { + // MessageProcessor progress + statusBar()->addPermanentWidget(msgProcessorStatusWidget); + connect(Client::messageProcessor(), SIGNAL(progressUpdated(int, int)), msgProcessorStatusWidget, SLOT(setProgress(int, int))); + // Core Lag: updateLagIndicator(0); statusBar()->addPermanentWidget(coreLagLabel); @@ -381,7 +353,8 @@ void MainWin::saveStatusBarStatus(bool enabled) { void MainWin::setupSystray() { connect(timer, SIGNAL(timeout()), this, SLOT(makeTrayIconBlink())); - connect(Client::instance(), SIGNAL(messageReceived(const Message &)), this, SLOT(receiveMessage(const Message &))); + connect(Client::messageModel(), SIGNAL(rowsInserted(const QModelIndex &, int, int)), + this, SLOT(messagesInserted(const QModelIndex &, int, int))); systrayMenu = new QMenu(this); systrayMenu->addAction(ui.actionAboutQuassel); @@ -417,23 +390,13 @@ void MainWin::changeEvent(QEvent *event) { } } -// FIXME this should be made prettier... -void MainWin::changeTopic(const QString &topic) { - BufferId id = ui.bufferWidget->currentBuffer(); - if(!id.isValid()) return; - Buffer *buffer = Client::buffer(id); - if(buffer) Client::userInput(buffer->bufferInfo(), QString("/topic %1").arg(topic)); -} - 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())); - foreach(BufferInfo id, Client::allBufferInfos()) { - Client::backlogManager()->requestBacklog(id.bufferId(), 500, -1); - } + Client::backlogManager()->requestInitialBacklog(); setConnectedState(); } @@ -465,7 +428,7 @@ void MainWin::saveLayout() { } void MainWin::updateLagIndicator(int lag) { - coreLagLabel->setText(QString("Core Lag: %1 msec").arg(lag)); + coreLagLabel->setText(QString(tr("Core Lag: %1 msec")).arg(lag)); } @@ -510,43 +473,49 @@ void MainWin::setDisconnectedState() { } void MainWin::showCoreConnectionDlg(bool autoConnect) { - coreConnectDlg = new CoreConnectDlg(this, autoConnect); - connect(coreConnectDlg, SIGNAL(finished(int)), this, SLOT(coreConnectionDlgFinished(int))); - coreConnectDlg->setModal(true); - coreConnectDlg->show(); -} - -void MainWin::coreConnectionDlgFinished(int /*code*/) { - coreConnectDlg->close(); - //exit(1); + CoreConnectDlg(autoConnect, this).exec(); } void MainWin::showChannelList(NetworkId netId) { + ChannelListDlg *channelListDlg = new ChannelListDlg(); + if(!netId.isValid()) { QAction *action = qobject_cast(sender()); if(action) netId = action->data().value(); } + + channelListDlg->setAttribute(Qt::WA_DeleteOnClose); channelListDlg->setNetwork(netId); channelListDlg->show(); } void MainWin::showCoreInfoDlg() { - CoreInfoDlg dlg(this); - dlg.exec(); + CoreInfoDlg(this).exec(); } void MainWin::showSettingsDlg() { - settingsDlg->show(); -} + SettingsDlg *dlg = new SettingsDlg(); -void MainWin::showDebugConsole() { - debugConsole->show(); + //Category: Appearance + dlg->registerSettingsPage(new ColorSettingsPage(dlg)); + dlg->registerSettingsPage(new FontsSettingsPage(dlg)); + dlg->registerSettingsPage(new AppearanceSettingsPage(dlg)); //General + //Category: Behaviour + dlg->registerSettingsPage(new GeneralSettingsPage(dlg)); + dlg->registerSettingsPage(new HighlightSettingsPage(dlg)); + dlg->registerSettingsPage(new AliasesSettingsPage(dlg)); + dlg->registerSettingsPage(new NotificationsSettingsPage(dlg)); + //Category: General + dlg->registerSettingsPage(new IdentitiesSettingsPage(dlg)); + dlg->registerSettingsPage(new NetworksSettingsPage(dlg)); + dlg->registerSettingsPage(new BufferViewSettingsPage(dlg)); + + dlg->show(); } void MainWin::showAboutDlg() { - AboutDlg dlg(this); - dlg.exec(); + AboutDlg(this).exec(); } void MainWin::closeEvent(QCloseEvent *event) { @@ -592,35 +561,47 @@ void MainWin::toggleVisibility() { } } -void MainWin::receiveMessage(const Message &msg) { +void MainWin::messagesInserted(const QModelIndex &parent, int start, int end) { + Q_UNUSED(parent); + if(QApplication::activeWindow() != 0) return; - if(msg.flags() & Message::Highlight || msg.bufferInfo().type() == BufferInfo::QueryBuffer) { - QString title = msg.bufferInfo().bufferName();; - if(msg.bufferInfo().type() != BufferInfo::QueryBuffer) { - QString sender = msg.sender(); - int i = sender.indexOf("!"); - if(i != -1) - sender = sender.left(i); - title += QString(" - %1").arg(sender); - } - - UiSettings uiSettings; - -#ifndef SPUTDEV - bool displayBubble = uiSettings.value("NotificationBubble", QVariant(true)).toBool(); - bool displayDesktop = uiSettings.value("NotificationDesktop", QVariant(true)).toBool(); - if(displayBubble || displayDesktop) { - // FIXME don't invoke style engine for this! - QString text = QtUi::style()->styleString(Message::mircToInternal(msg.contents())).plainText; - if (displayBubble) displayTrayIconMessage(title, text); - if (displayDesktop) sendDesktopNotification(title, text); + for(int i = start; i <= end; i++) { + QModelIndex idx = Client::messageModel()->index(i, ChatLineModel::ContentsColumn); + if(!idx.isValid()) { + qDebug() << "MainWin::messagesInserted(): Invalid model index!"; + continue; } -#endif - if(uiSettings.value("AnimateTrayIcon", QVariant(true)).toBool()) { - QApplication::alert(this); - setTrayIconActivity(true); + Message::Flags flags = (Message::Flags)idx.data(ChatLineModel::FlagsRole).toInt(); + if(flags.testFlag(Message::Backlog)) continue; + flags |= Message::Backlog; // we only want to trigger a highlight once! + Client::messageModel()->setData(idx, (int)flags, ChatLineModel::FlagsRole); + + BufferId bufId = idx.data(ChatLineModel::BufferIdRole).value(); + BufferInfo::Type bufType = Client::networkModel()->bufferType(bufId); + + if(flags & Message::Highlight || bufType == BufferInfo::QueryBuffer) { + QString title = Client::networkModel()->networkName(bufId) + " - " + Client::networkModel()->bufferName(bufId); + + // FIXME Don't instantiate this for every highlight... + UiSettings uiSettings; + + bool displayBubble = uiSettings.value("NotificationBubble", QVariant(true)).toBool(); + bool displayDesktop = uiSettings.value("NotificationDesktop", QVariant(true)).toBool(); + if(displayBubble || displayDesktop) { + if(uiSettings.value("DisplayPopupMessages", QVariant(true)).toBool()) { + QString text = idx.data(ChatLineModel::DisplayRole).toString(); + if(displayBubble) displayTrayIconMessage(title, text); +# ifdef HAVE_DBUS + if(displayDesktop) sendDesktopNotification(title, text); +# endif + } + if(uiSettings.value("AnimateTrayIcon", QVariant(true)).toBool()) { + QApplication::alert(this); + setTrayIconActivity(true); + } + } } } } @@ -631,58 +612,59 @@ bool MainWin::event(QEvent *event) { return QMainWindow::event(event); } +#ifdef HAVE_DBUS /* Using the notification-daemon from Freedesktop's Galago project http://www.galago-project.org/specs/notification/0.9/x408.html#command-notify */ -void MainWin::sendDesktopNotification(const QString &title, const QString &message) -{ - QStringList actions; - QMap hints; - UiSettings uiSettings; - - hints["x"] = uiSettings.value("NotificationDesktopHintX", QVariant(0)).toInt(); // Standard hint: x location for the popup to show up - hints["y"] = uiSettings.value("NotificationDesktopHintY", QVariant(0)).toInt(); // Standard hint: y location for the popup to show up - - actions << "click" << "Click Me!"; - - QDBusReply reply = desktopNotifications->Notify( - "Quassel", // Application name - notificationId, // ID of previous notification to replace - "", // Icon to display - title, // Summary / Header of the message to display - QString("%1: %2:\n%3").arg(QTime::currentTime().toString()).arg(title).arg(message), // Body of the message to display - actions, // Actions from which the user may choose - hints, // Hints to the server displaying the message - uiSettings.value("NotificationDesktopTimeout", QVariant(5000)).toInt() // Timeout in milliseconds - ); +void MainWin::sendDesktopNotification(const QString &title, const QString &message) { + QStringList actions; + QMap hints; + UiSettings uiSettings; - if (!reply.isValid()) - { - /* ERROR */ - qDebug() << "Error on sending notification..."; - return; - } + hints["x"] = uiSettings.value("NotificationDesktopHintX", QVariant(0)).toInt(); // Standard hint: x location for the popup to show up + hints["y"] = uiSettings.value("NotificationDesktopHintY", QVariant(0)).toInt(); // Standard hint: y location for the popup to show up + + actions << "click" << "Click Me!"; + + QDBusReply reply = desktopNotifications->Notify( + "Quassel", // Application name + notificationId, // ID of previous notification to replace + "", // Icon to display + title, // Summary / Header of the message to display + QString("%1: %2:\n%3").arg(QTime::currentTime().toString()).arg(title).arg(message), // Body of the message to display + actions, // Actions from which the user may choose + hints, // Hints to the server displaying the message + uiSettings.value("NotificationDesktopTimeout", QVariant(5000)).toInt() // Timeout in milliseconds + ); + + if(!reply.isValid()) { + /* ERROR */ + // could also happen if no notification service runs, so... whatever :) + //qDebug() << "Error on sending notification..." << reply.error(); + return; + } - notificationId = reply.value(); + notificationId = reply.value(); - qDebug() << "ID: " << notificationId << " Time: " << QTime::currentTime().toString(); + // qDebug() << "ID: " << notificationId << " Time: " << QTime::currentTime().toString(); } -void MainWin::desktopNotificationClosed(uint id, uint reason) -{ - qDebug() << "OID: " << notificationId << " ID: " << id << " Reason: " << reason << " Time: " << QTime::currentTime().toString(); - notificationId = 0; +void MainWin::desktopNotificationClosed(uint id, uint reason) { + Q_UNUSED(id); Q_UNUSED(reason); + // qDebug() << "OID: " << notificationId << " ID: " << id << " Reason: " << reason << " Time: " << QTime::currentTime().toString(); + notificationId = 0; } -void MainWin::desktopNotificationInvoked(uint id, const QString & action) -{ - qDebug() << "OID: " << notificationId << " ID: " << id << " Action: " << action << " Time: " << QTime::currentTime().toString(); +void MainWin::desktopNotificationInvoked(uint id, const QString & action) { + Q_UNUSED(id); Q_UNUSED(action); + // qDebug() << "OID: " << notificationId << " ID: " << id << " Action: " << action << " Time: " << QTime::currentTime().toString(); } +#endif /* HAVE_DBUS */ void MainWin::displayTrayIconMessage(const QString &title, const QString &message) { systray->showMessage(title, message); @@ -758,7 +740,7 @@ void MainWin::clientNetworkRemoved(NetworkId id) { QAction *action = findChild(QString("NetworkAction-%1").arg(id.toInt())); if(!action) return; - + action->deleteLater(); } @@ -771,3 +753,32 @@ void MainWin::connectOrDisconnectFromNet() { else net->requestDisconnect(); } + + +void MainWin::on_actionDebugNetworkModel_triggered(bool) { + QTreeView *view = new QTreeView; + view->setAttribute(Qt::WA_DeleteOnClose); + view->setWindowTitle("Debug NetworkModel View"); + view->setModel(Client::networkModel()); + view->setColumnWidth(0, 250); + view->setColumnWidth(1, 250); + view->setColumnWidth(2, 80); + view->resize(610, 300); + view->show(); +} + +void MainWin::saveStateToSession(const QString &sessionId) { + return; + SessionSettings s(sessionId); + + s.setValue("MainWinSize", size()); + s.setValue("MainWinPos", pos()); + s.setValue("MainWinState", saveState()); +} + +void MainWin::saveStateToSessionSettings(SessionSettings & s) +{ + s.setValue("MainWinSize", size()); + s.setValue("MainWinPos", pos()); + s.setValue("MainWinState", saveState()); +}