X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fqtui%2Fmainwin.cpp;h=027f7de0b931eb6f7531ff5cc6ce1cd6ca33ba11;hp=c1af8b0fd11a50d6140cb8c64c7191a52784a2b9;hb=e561e02a8d2f1f009559d17c7b1c66cb6f4e2a5a;hpb=665faa937a52fc6175741292737c4a52875b4f75 diff --git a/src/qtui/mainwin.cpp b/src/qtui/mainwin.cpp index c1af8b0f..027f7de0 100644 --- a/src/qtui/mainwin.cpp +++ b/src/qtui/mainwin.cpp @@ -20,12 +20,13 @@ #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 "chatmonitorfilter.h" +#include "chatview.h" #include "client.h" #include "clientbacklogmanager.h" #include "coreinfodlg.h" @@ -45,11 +46,10 @@ #include "qtuisettings.h" #include "jumpkeyhandler.h" -#include "uisettings.h" - #include "selectionmodelsynchronizer.h" #include "mappedselectionmodel.h" +#include "settingspages/aliasessettingspage.h" #include "settingspages/appearancesettingspage.h" #include "settingspages/bufferviewsettingspage.h" #include "settingspages/colorsettingspage.h" @@ -58,16 +58,16 @@ #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" - MainWin::MainWin(QtUi *_gui, QWidget *parent) : QMainWindow(parent), gui(_gui), + coreLagLabel(new QLabel()), sslLabel(new QLabel()), _titleSetter(this), systray(new QSystemTrayIcon(this)), @@ -82,12 +82,12 @@ MainWin::MainWin(QtUi *_gui, QWidget *parent) { 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); @@ -99,6 +99,15 @@ MainWin::MainWin(QtUi *_gui, QWidget *parent) installEventFilter(new JumpKeyHandler(this)); +#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 } void MainWin::init() { @@ -142,9 +151,9 @@ void MainWin::init() { // 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 @@ -196,7 +205,7 @@ void MainWin::addBufferView(BufferViewConfig *config) { view->show(); connect(&view->showChannelList, SIGNAL(triggered()), this, SLOT(showChannelList())); - + Client::bufferModel()->synchronizeView(view); dock->setWidget(view); @@ -232,6 +241,8 @@ void MainWin::setupSettingsDlg() { //Category: Behaviour settingsDlg->registerSettingsPage(new GeneralSettingsPage(settingsDlg)); settingsDlg->registerSettingsPage(new HighlightSettingsPage(settingsDlg)); + settingsDlg->registerSettingsPage(new AliasesSettingsPage(settingsDlg)); + settingsDlg->registerSettingsPage(new NotificationsSettingsPage(settingsDlg)); //Category: General settingsDlg->registerSettingsPage(new IdentitiesSettingsPage(settingsDlg)); settingsDlg->registerSettingsPage(new NetworksSettingsPage(settingsDlg)); @@ -276,26 +287,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); + ChatView *chatView = new ChatView(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() { @@ -332,6 +334,12 @@ void MainWin::setupTopicWidget() { } void MainWin::setupStatusBar() { + // Core Lag: + updateLagIndicator(0); + statusBar()->addPermanentWidget(coreLagLabel); + connect(Client::signalProxy(), SIGNAL(lagUpdated(int)), this, SLOT(updateLagIndicator(int))); + + // SSL indicator connect(Client::instance(), SIGNAL(securedConnection()), this, SLOT(securedConnection())); sslLabel->setPixmap(QPixmap()); statusBar()->addPermanentWidget(sslLabel); @@ -406,7 +414,7 @@ void MainWin::connectedToCore() { 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); } @@ -440,6 +448,11 @@ void MainWin::saveLayout() { if(accountId > 0) s.setValue(QString("MainWinState-%1").arg(accountId) , saveState(accountId)); } +void MainWin::updateLagIndicator(int lag) { + coreLagLabel->setText(QString("Core Lag: %1 msec").arg(lag)); +} + + void MainWin::securedConnection() { // todo: make status bar entry sslLabel->setPixmap(QPixmap::fromImage(QImage(":/16x16/status/ssl"))); @@ -579,16 +592,21 @@ void MainWin::receiveMessage(const Message &msg) { UiSettings uiSettings; -#ifndef SPUTDEV - if(uiSettings.value("DisplayPopupMessages", QVariant(true)).toBool()) { - // FIXME don't invoke style engine for this! - QString text = QtUi::style()->styleString(Message::mircToInternal(msg.contents())).plainText; - displayTrayIconMessage(title, text); - } -#endif - if(uiSettings.value("AnimateTrayIcon", QVariant(true)).toBool()) { - QApplication::alert(this); - setTrayIconActivity(true); + 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()) { + // FIXME don't invoke style engine for this! + QString text = QtUi::style()->styleString(msg.contents()).plainText; + 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); + } } } } @@ -599,6 +617,60 @@ 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 + ); + + 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(); + + // qDebug() << "ID: " << notificationId << " Time: " << QTime::currentTime().toString(); +} + + +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) { + 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); } @@ -673,7 +745,7 @@ void MainWin::clientNetworkRemoved(NetworkId id) { QAction *action = findChild(QString("NetworkAction-%1").arg(id.toInt())); if(!action) return; - + action->deleteLater(); } @@ -686,3 +758,16 @@ 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(); +}