Intial support for the org.freedesktop.Notifications DBus interface (very basic).
[quassel.git] / src / qtui / mainwin.cpp
index 9b73d55..4c3f16b 100644 (file)
@@ -41,6 +41,7 @@
 #include "irclistmodel.h"
 #include "verticaldock.h"
 #include "uisettings.h"
+#include "util.h"
 #include "qtuisettings.h"
 #include "jumpkeyhandler.h"
 
@@ -49,6 +50,7 @@
 #include "selectionmodelsynchronizer.h"
 #include "mappedselectionmodel.h"
 
+#include "settingspages/aliasessettingspage.h"
 #include "settingspages/appearancesettingspage.h"
 #include "settingspages/bufferviewsettingspage.h"
 #include "settingspages/colorsettingspage.h"
 #include "global.h"
 #include "qtuistyle.h"
 
+#include <Qt/QtDBus>
+
 
 MainWin::MainWin(QtUi *_gui, QWidget *parent)
   : QMainWindow(parent),
     gui(_gui),
+    coreLagLabel(new QLabel()),
     sslLabel(new QLabel()),
     _titleSetter(this),
     systray(new QSystemTrayIcon(this)),
@@ -79,6 +84,14 @@ MainWin::MainWin(QtUi *_gui, QWidget *parent)
     settingsDlg(new SettingsDlg(this)),
     debugConsole(new DebugConsole(this))
 {
+  UiSettings uiSettings;
+  loadTranslation(uiSettings.value("Locale", QLocale::system()).value<QLocale>());
+  
+  QString style = uiSettings.value("Style", QString("")).toString();
+  if(style != "") {
+    QApplication::setStyle(style);
+  }
+  
   ui.setupUi(this);
   setWindowTitle("Quassel IRC");
   setWindowIcon(offlineTrayIcon);
@@ -90,11 +103,6 @@ MainWin::MainWin(QtUi *_gui, QWidget *parent)
 
   installEventFilter(new JumpKeyHandler(this));
 
-  UiSettings uiSettings;
-  QString style = uiSettings.value("Style", QString("")).toString();
-  if(style != "") {
-    QApplication::setStyle(style);
-  }
 }
 
 void MainWin::init() {
@@ -228,6 +236,7 @@ void MainWin::setupSettingsDlg() {
   //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));
@@ -328,6 +337,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);
@@ -402,7 +417,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);
   }
@@ -436,6 +451,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")));
@@ -580,6 +600,7 @@ void MainWin::receiveMessage(const Message &msg) {
       // FIXME don't invoke style engine for this!
       QString text = QtUi::style()->styleString(Message::mircToInternal(msg.contents())).plainText;
       displayTrayIconMessage(title, text);
+         sendDesktopNotification(title, text);
     }
 #endif
     if(uiSettings.value("AnimateTrayIcon", QVariant(true)).toBool()) {
@@ -595,6 +616,33 @@ bool MainWin::event(QEvent *event) {
   return QMainWindow::event(event);
 }
 
+
+/*
+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<QString, QVariant> hints;
+       QDBusMessage msg = QDBusMessage::createMethodCall("org.freedesktop.Notifications", "/org/freedesktop/Notifications", "", "Notify");
+
+       hints["x"] = 100; // Standard hint: x location for the popup to show up
+       hints["y"] = 100; // Standard hint: y location for the popup to show up
+
+       msg << "Quassel"; // Application name
+       msg << quint32(0); // ID of previous notification to replace
+       msg << ""; // Icon to display
+       msg << "Quassel: " + title; // Summary / Header of the message to display
+       msg << message; // Body of the message to display
+       msg << actions; // Actions from which the user may choose
+       msg << hints; // Hints to the server displaying the message
+       msg << qint32(10000); // Timeout in milliseconds
+
+       (void)QDBusConnection::sessionBus().call(msg); // Would return a message containing the id of this notification
+}
+
+
 void MainWin::displayTrayIconMessage(const QString &title, const QString &message) {
   systray->showMessage(title, message);
 }