From kde-commits Fri Aug 20 19:18:54 2010 From: Christian Weilbach Date: Fri, 20 Aug 2010 19:18:54 +0000 To: kde-commits Subject: KDE/kdeplasma-addons/applets/incomingmsg Message-Id: <20100820191854.340BDAC855 () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=128233190228963 SVN commit 1166081 by weilbach: Patch from Ruslan Nigmatullin for qutIM support and some cleanups. M +1 -0 AUTHORS M +2 -0 ChangeLog M +1 -1 README M +126 -4 incomingmsg.cpp M +13 -4 incomingmsg.h M +25 -6 widget.ui --- trunk/KDE/kdeplasma-addons/applets/incomingmsg/AUTHORS #1166080:1166081 @@ -1 +1,2 @@ Created by Christian Weilbach +qutIM support added by Ruslan Nigmatullin --- trunk/KDE/kdeplasma-addons/applets/incomingmsg/ChangeLog #1166080:1166081 @@ -1,2 +1,4 @@ v 0.01 * First usable release. +v 0.02 +* Added qutIM support --- trunk/KDE/kdeplasma-addons/applets/incomingmsg/README #1166080:1166081 @@ -7,5 +7,5 @@ It uses DBus and only adds information for apps that are running (it checks for the dbus interface). At the moment sadly only kmail notifies over DBus for new messages. -Hopefully Kopete can be added soon. +Also qutIM notifies about count of unreaded messages. Hack on it as you like. --- trunk/KDE/kdeplasma-addons/applets/incomingmsg/incomingmsg.cpp #1166080:1166081 @@ -1,5 +1,6 @@ /* - * Copyright (C) 2008 Christian Weilbach + * Copyright (C) 2008-2010 Christian Weilbach + * Copyright (C) 2010 Ruslan Nigmatullin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License version 2 as @@ -53,10 +54,12 @@ mXChatLabel(0), mXChatIconLabel(0), mKopeteLabel(0), mKopeteIconLabel(0), mPidginLabel(0), mPidginIconLabel(0), + mQutIMLabel(0), mQutIMIconLabel(0), mErrorLabel(0), mLayout(0), mEvolutionLayout(0), mKMailLayout(0), mXChatLayout(0), mKopeteLayout(0), - mPidginLayout(0) + mPidginLayout(0), mQutIMLayout(0), + mQutIUnreadCount(0) { // this will get us the standard applet background, for free! setBackgroundHints(DefaultBackground); @@ -80,6 +83,10 @@ delete mPidginLayout; delete mPidginIconLabel; delete mPidginLabel; + + delete mQutIMLayout; + delete mQutIMIconLabel; + delete mQutIMLabel; } void IncomingMsg::init() @@ -91,6 +98,7 @@ mShowXChat = cg.readEntry("showXChat", true); mShowKopete = cg.readEntry("showKopete", true); mShowPidgin = cg.readEntry("showPidgin", true); + mShowQutIM = cg.readEntry("showQutIM", true); initLayout(); } @@ -289,6 +297,71 @@ } } +void IncomingMsg::initQutIMLayout() +{ + if (mShowQutIM) { + QDBusInterface qutimDBusTest("org.qutim", "/ChatLayer", "org.qutim.ChatLayer"); + QDBusReply > sessionsReply = qutimDBusTest.call("sessions"); + if (!sessionsReply.isValid()) + kDebug() << "qutIM DBus interface test error: " << sessionsReply.error(); + else { + QList sessions = sessionsReply.value(); + for (int i = 0; i < sessions.size(); i++) { + QDBusInterface qutimSession("org.qutim", sessions.at(i).path(), + "org.freedesktop.DBus.Properties"); + QDBusMessage msg = qutimSession.call("Get", "org.qutim.ChatSession", "unread"); + slotNewQutIM(msg, sessions.at(i).path()); + } + QDBusConnection mDBus = QDBusConnection::sessionBus(); + if (!mDBus.connect("org.qutim", QString(), + "org.qutim.ChatSession", "unreadChanged", + this, SLOT(slotNewQutIM(QDBusMessage)))) + kDebug() << "Could not connect to qutIM on DBus."; + else { + mQutIMLayout = new QGraphicsLinearLayout(Qt::Horizontal); + mQutIMLabel = new Plasma::Label(this); + mQutIMIconLabel = new Plasma::Label(this); + mQutIMIconLabel->setMinimumWidth(32); + mQutIMIconLabel->setMinimumHeight(32); + + updateQutIMStatus(false); + + mQutIMLayout->addItem(mQutIMIconLabel); + mQutIMLayout->addItem(mQutIMLabel); + mQutIMLayout->setAlignment(mQutIMLabel, Qt::AlignLeft); + + mLayout->addItem(mQutIMLayout); + } + } + } +} + +void IncomingMsg::updateQutIMStatus(bool saveIcon) +{ + if (!saveIcon) { + KIcon icon("qutim"); + if (mQutIUnreadCount == 0) { + KIconEffect effect; + mQutIMIconLabel->nativeWidget()->setPixmap( + effect.apply(icon.pixmap(32, 32), KIconEffect::ToGray, 1, QColor(), QColor(), true) + ); + } else { + mQutIMIconLabel->nativeWidget()->setPixmap(icon.pixmap(32, 32)); + } + } + if (mQutIUnreadCount > 0) { + kDebug() << i18np("You have new qutIM message.", + "You have new %1 qutIM messages.", + mQutIUnreadCount); + mQutIMLabel->setText(i18np("You have new qutIM message.", + "You have new %1 qutIM messages.", + mQutIUnreadCount)); + } else { + kDebug() << i18n("No new qutIM messages."); + mQutIMLabel->setText(i18n("No new qutIM messages.")); + } +} + void IncomingMsg::clearLayout() { delete mKMailLayout; @@ -319,6 +392,15 @@ delete mPidginLabel; mPidginLabel = NULL; + delete mQutIMLayout; + mQutIMLayout = NULL; + delete mQutIMIconLabel; + mQutIMIconLabel = NULL; + delete mQutIMLabel; + mQutIMLabel = NULL; + mQutIMUnread.clear(); + mQutIUnreadCount = 0; + delete mErrorLabel; mErrorLabel = NULL; } @@ -332,12 +414,13 @@ initXChatLayout(); initKopeteLayout(); initPidginLayout(); + initQutIMLayout(); if (!mLayout->count()) { mErrorLabel = new Plasma::Label(); - mErrorLabel->setText(i18n("No running messaging apps found. Supported apps are %1, %2, %3, %4.", + mErrorLabel->setText(i18n("No running messaging apps found. Supported apps are %1, %2, %3, %4, %5.", QString("KMail"), QString("XChat"), QString("Kopete"), - QString("Pidgin"))); + QString("Pidgin"), QString("qutIM"))); mLayout->addItem(mErrorLabel); } @@ -354,6 +437,7 @@ ui.showXChat->setChecked(cg.readEntry("showXChat", true)); ui.showKopete->setChecked(cg.readEntry("showKopete", true)); ui.showPidgin->setChecked(cg.readEntry("showPidgin", true)); + ui.showQutIM->setChecked(cg.readEntry("showQutIM", true)); connect(dialog, SIGNAL(applyClicked()), this, SLOT(configAccepted())); connect(dialog, SIGNAL(okClicked()), this, SLOT(configAccepted())); @@ -368,12 +452,14 @@ mShowXChat = ui.showXChat->isChecked(); mShowKopete = ui.showKopete->isChecked(); mShowPidgin = ui.showPidgin->isChecked(); + mShowQutIM = ui.showQutIM->isChecked(); KConfigGroup cg = config(); cg.writeEntry("showKMail", ui.showKMail->isChecked()); cg.writeEntry("showXChat", ui.showXChat->isChecked()); cg.writeEntry("showKopete", ui.showKopete->isChecked()); cg.writeEntry("showPidgin", ui.showPidgin->isChecked()); + cg.writeEntry("showQutIM", ui.showQutIM->isChecked()); clearLayout(); initLayout(); @@ -400,6 +486,42 @@ mXChatLabel->setText(i18n("You have new XChat messages.")); } +void IncomingMsg::slotNewQutIM(const QDBusMessage &msg, QString path) +{ + if (path.isNull()) + path = msg.path(); + bool hasUnread = mQutIUnreadCount > 0; + QVariant var = msg.arguments().value(0); + if (var.canConvert()) + var = var.value().variant(); + int currentCount = mQutIMUnread.value(path, 0); + int count = 0; + const QDBusArgument arg = qvariant_cast(var); + // Parse aa{sv} value + arg.beginArray(); + while (!arg.atEnd()) { + arg.beginMap(); + while (!arg.atEnd()) { + QString key; + QVariant value; + arg.beginMapEntry(); + arg >> key >> value; + arg.endMapEntry(); + } + arg.endMap(); + count++; + } + arg.endArray(); + mQutIUnreadCount -= currentCount; + mQutIUnreadCount += count; + if (count > 0) + mQutIMUnread.insert(path, count); + else + mQutIMUnread.remove(path); + if (mQutIMLayout) + updateQutIMStatus(hasUnread == (mQutIUnreadCount > 0)); +} + void IncomingMsg::slotNewKopeteIM(const QString& contactId) { QDBusInterface kopeteDBusTest("org.kde.kopete", "/Kopete", "org.kde.Kopete"); --- trunk/KDE/kdeplasma-addons/applets/incomingmsg/incomingmsg.h #1166080:1166081 @@ -1,5 +1,6 @@ /* - * Copyright (C) 2008 Christian Weilbach + * Copyright (C) 2008-2010 Christian Weilbach + * Copyright (C) 2010 Ruslan Nigmatullin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License version 2 as @@ -29,6 +30,7 @@ #include "ui_widget.h" class QGraphicsLinearLayout; +class QDBusObjectPath; namespace Plasma { @@ -53,6 +55,7 @@ void initXChatLayout(); void initKopeteLayout(); void initPidginLayout(); + void initQutIMLayout(); protected slots: void configAccepted(); @@ -60,19 +63,24 @@ private: void clearLayout(); void initLayout(); + void updateQutIMStatus(bool saveIcon); // text labels Plasma::Label *mEvolutionLabel, *mEvolutionIconLabel, *mKMailLabel, *mKMailIconLabel, *mXChatLabel, *mXChatIconLabel, *mKopeteLabel, *mKopeteIconLabel, - *mPidginLabel, *mPidginIconLabel, *mErrorLabel; + *mPidginLabel, *mPidginIconLabel, *mQutIMLabel, + *mQutIMIconLabel, *mErrorLabel; QGraphicsLinearLayout *mLayout, *mEvolutionLayout, *mKMailLayout, *mXChatLayout, *mKopeteLayout, - *mPidginLayout; + *mPidginLayout, *mQutIMLayout; - bool mShowKMail, mShowXChat, mShowKopete, mShowPidgin; + bool mShowKMail, mShowXChat, mShowKopete, mShowPidgin, mShowQutIM; + QHash mQutIMUnread; + int mQutIUnreadCount; + Ui::incomingmsgConfig ui; private slots: @@ -81,6 +89,7 @@ void slotNewPidginIM(); void slotNewKopeteIM(const QString&); void slotNewXChatIM(); + void slotNewQutIM(const QDBusMessage &msg, QString path = QString()); }; // This is the command that links your applet to the .desktop file --- trunk/KDE/kdeplasma-addons/applets/incomingmsg/widget.ui #1166080:1166081 @@ -1,6 +1,15 @@ + incomingmsgConfig + + + 0 + 0 + 284 + 175 + + @@ -28,7 +37,7 @@ - + 0 0 @@ -44,7 +53,7 @@ - + 0 0 @@ -60,7 +69,7 @@ - + 0 0 @@ -73,10 +82,10 @@ - + - + 0 0 @@ -89,7 +98,7 @@ - + Qt::Vertical @@ -102,6 +111,16 @@ + + + + qutIM + + + true + + +