From 531d8015dc64daebd412b1891c0e8c938ebe2efa Mon Sep 17 00:00:00 2001 From: Andrey Esin Date: Wed, 20 Oct 2010 20:53:04 +0000 Subject: [PATCH] - Adding config dialog - Adding simple scan for launched messengers. - Some small fixes svn path=/trunk/playground/network/choqok/; revision=1187950 --- plugins/imstatus/CMakeLists.txt | 26 ++++++-- plugins/imstatus/choqok_imstatus_config.desktop | 10 ++++ plugins/imstatus/imqdbus.cpp | 41 +++++++++++-- plugins/imstatus/imqdbus.h | 3 + plugins/imstatus/imstatus.cpp | 4 +- plugins/imstatus/imstatusconfig.cpp | 80 +++++++++++++++++++++++++ plugins/imstatus/imstatusconfig.h | 48 +++++++++++++++ plugins/imstatus/imstatusprefs.ui | 51 ++++++++++++++++ plugins/imstatus/imstatussettings.kcfg | 12 ++++ plugins/imstatus/imstatussettings.kcfgc | 10 ++++ 10 files changed, 273 insertions(+), 12 deletions(-) create mode 100644 plugins/imstatus/choqok_imstatus_config.desktop create mode 100644 plugins/imstatus/imstatusconfig.cpp create mode 100644 plugins/imstatus/imstatusconfig.h create mode 100644 plugins/imstatus/imstatusprefs.ui create mode 100644 plugins/imstatus/imstatussettings.kcfg create mode 100644 plugins/imstatus/imstatussettings.kcfgc diff --git a/plugins/imstatus/CMakeLists.txt b/plugins/imstatus/CMakeLists.txt index c824a79..9929772 100644 --- a/plugins/imstatus/CMakeLists.txt +++ b/plugins/imstatus/CMakeLists.txt @@ -5,10 +5,10 @@ ${CHOQOK_INCLUDES} ########### next target ############### -set( choqok_imstatus_PART_SRCS -imstatus.cpp -imqdbus.cpp ) +set( choqok_imstatus_PART_SRCS imqdbus.cpp +imstatus.cpp ) +kde4_add_kcfg_files(choqok_imstatus_PART_SRCS imstatussettings.kcfgc ) kde4_add_plugin(choqok_imstatus ${choqok_imstatus_PART_SRCS}) @@ -16,5 +16,23 @@ target_link_libraries(choqok_imstatus ${KDE4_KIO_LIBS} choqok) install(TARGETS choqok_imstatus DESTINATION ${PLUGIN_INSTALL_DIR}) -install( FILES choqok_imstatus.desktop +########### next target ############### + +set( kcm_choqok_imstatus_PART_SRCS imqdbus.cpp +imstatusconfig.cpp ) + +kde4_add_ui_files(kcm_choqok_imstatus_PART_SRCS imstatusprefs.ui ) + +kde4_add_kcfg_files(kcm_choqok_imstatus_PART_SRCS imstatussettings.kcfgc ) + +kde4_add_plugin(kcm_choqok_imstatus ${kcm_choqok_imstatus_PART_SRCS}) + +target_link_libraries(kcm_choqok_imstatus ${KDE4_KDEUI_LIBS}) + +install(TARGETS kcm_choqok_imstatus DESTINATION ${PLUGIN_INSTALL_DIR}) + +########### next target ############### + +install( FILES imstatussettings.kcfg DESTINATION ${KCFG_INSTALL_DIR}) +install( FILES choqok_imstatus_config.desktop choqok_imstatus.desktop DESTINATION ${SERVICES_INSTALL_DIR}) diff --git a/plugins/imstatus/choqok_imstatus_config.desktop b/plugins/imstatus/choqok_imstatus_config.desktop new file mode 100644 index 0000000..fd62554 --- /dev/null +++ b/plugins/imstatus/choqok_imstatus_config.desktop @@ -0,0 +1,10 @@ +[Desktop Entry] +Icon=kaboodle +Type=Service +X-KDE-ServiceTypes=KCModule +X-KDE-Library=kcm_choqok_imstatus +X-KDE-FactoryName=kcm_choqok_imstatus +X-KDE-ParentApp=choqok_imstatus +X-KDE-ParentComponents=choqok_imstatus +Name=IMStatus +Comment=Sets status of your instant messanger as your status in micro-blog. diff --git a/plugins/imstatus/imqdbus.cpp b/plugins/imstatus/imqdbus.cpp index f06b65e..3ed1b49 100644 --- a/plugins/imstatus/imqdbus.cpp +++ b/plugins/imstatus/imqdbus.cpp @@ -26,11 +26,17 @@ #include #include #include +#include #include IMQDBus::IMQDBus( const QString im, const QString msg ) { + /* + TODO: + - Pidgin + - qutIM + */ if ( im == "Kopete" ) useKopete( msg ); if ( im == "Psi" ) usePsi( msg ); if ( im == "Skype" ) useSkype( msg ); @@ -44,8 +50,10 @@ void IMQDBus::useKopete(QString status) args.append( QVariant( status ) ); msg.setArguments( args ); QDBusMessage rep = QDBusConnection::sessionBus().call( msg ); - if ( rep.type() == QDBusMessage::ErrorMessage) + if ( rep.type() == QDBusMessage::ErrorMessage){ qDebug() << "ERROR" << rep.errorMessage(); + return; + } } void IMQDBus::usePsi(QString status) @@ -53,11 +61,13 @@ void IMQDBus::usePsi(QString status) QDBusMessage msg = QDBusMessage::createMethodCall( "org.psi-im.Psi", "/Main", "org.psi_im.Psi.Main", "setStatus" ); QList args; args.append( QVariant( QString( "online" ) ) ); - args.append( QVariant( QString( "status" ) ) ); + args.append( QVariant( status ) ); msg.setArguments( args ); QDBusMessage rep = QDBusConnection::sessionBus().call( msg ); - if ( rep.type() == QDBusMessage::ErrorMessage) + if ( rep.type() == QDBusMessage::ErrorMessage){ qDebug() << "ERROR" << rep.errorMessage(); + return; + } } void IMQDBus::useSkype(QString status) @@ -67,23 +77,42 @@ void IMQDBus::useSkype(QString status) args.append( QVariant( QString( "NAME Choqok" ) ) ); msg.setArguments( args ); QDBusMessage rep = QDBusConnection::sessionBus().call( msg ); - if ( rep.type() == QDBusMessage::ErrorMessage) + if ( rep.type() == QDBusMessage::ErrorMessage){ qDebug() << "ERROR" << rep.errorMessage(); + return; + } args.clear(); args.append( QVariant( QString( "PROTOCOL 7" ) ) ); msg.setArguments( args ); rep = QDBusConnection::sessionBus().call( msg ); - if ( rep.type() == QDBusMessage::ErrorMessage) + if ( rep.type() == QDBusMessage::ErrorMessage){ qDebug() << "ERROR" << rep.errorMessage(); + return; + } args.clear(); args.append( QVariant( QString( "SET PROFILE MOOD_TEXT %1" ).arg(status) ) ); msg.setArguments( args ); rep = QDBusConnection::sessionBus().call( msg ); - if ( rep.type() == QDBusMessage::ErrorMessage) + if ( rep.type() == QDBusMessage::ErrorMessage){ qDebug() << "ERROR" << rep.errorMessage(); + return; + } } IMQDBus::~IMQDBus() {} + + +QStringList IMQDBus::scanForIMs() +{ + QStringList ims; + if (QDBusConnection::sessionBus().interface()->isServiceRegistered("com.Skype.API").value()) + ims << "Skype"; + if (QDBusConnection::sessionBus().interface()->isServiceRegistered("org.psi-im.Psi").value()) + ims << "Psi"; + if (QDBusConnection::sessionBus().interface()->isServiceRegistered("org.kde.kopete").value()) + ims << "Kopete"; + return ims; +} diff --git a/plugins/imstatus/imqdbus.h b/plugins/imstatus/imqdbus.h index 3256e26..10f7cf6 100644 --- a/plugins/imstatus/imqdbus.h +++ b/plugins/imstatus/imqdbus.h @@ -35,6 +35,9 @@ class IMQDBus void usePsi(QString status); void useKopete(QString status); void useSkype(QString status); + QString currentIMstr; + + static QStringList scanForIMs(); }; #endif // IMQDBUS_H diff --git a/plugins/imstatus/imstatus.cpp b/plugins/imstatus/imstatus.cpp index 319f8b7..a1a91bd 100644 --- a/plugins/imstatus/imstatus.cpp +++ b/plugins/imstatus/imstatus.cpp @@ -31,6 +31,7 @@ #include #include #include +#include "imstatussettings.h" #include @@ -62,7 +63,6 @@ void IMStatus::slotIMStatus( Choqok::JobResult res, const QString &newStatus ) if ( res == Choqok::Success) { //IMQDBus im( "Kopete", newStatus ); //IMQDBus im( "Psi", newStatus ); - IMQDBus im( "Skype", newStatus ); - + IMQDBus im( "Skype", newStatus ); } } diff --git a/plugins/imstatus/imstatusconfig.cpp b/plugins/imstatus/imstatusconfig.cpp new file mode 100644 index 0000000..1328a88 --- /dev/null +++ b/plugins/imstatus/imstatusconfig.cpp @@ -0,0 +1,80 @@ +/* + This file is part of Choqok, the KDE micro-blogging client + + Copyright (C) 2009-2010 Mehrdad Momeny + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of + the License or (at your option) version 3 or any later version + accepted by the membership of KDE e.V. (or its successor approved + by the membership of KDE e.V.), which shall act as a proxy + defined in Section 14 of version 3 of the license. + + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see http://www.gnu.org/licenses/ + +*/ + +#include "imstatusconfig.h" +#include +#include +#include +#include "imstatussettings.h" +#include +#include +#include "imqdbus.h" + +K_PLUGIN_FACTORY( IMStatusConfigFactory, registerPlugin < IMStatusConfig > (); ) +K_EXPORT_PLUGIN( IMStatusConfigFactory( "kcm_choqok_imstatus" ) ) + +IMStatusConfig::IMStatusConfig(QWidget* parent, const QVariantList& args): + KCModule( IMStatusConfigFactory::componentData(), parent, args) +{ + QVBoxLayout *layout = new QVBoxLayout(this); + QWidget *wd = new QWidget(this); + wd->setObjectName("mIMStatusCtl"); + ui.setupUi(wd); + addConfig( IMStatusSettings::self(), wd ); + layout->addWidget(wd); + setButtons(KCModule::Apply | KCModule::Default); + connect( ui.cfg_clientList, SIGNAL(currentIndexChanged(int)), SLOT(emitChanged()) ); + + ui.cfg_clientList->addItems(IMQDBus::scanForIMs()); +} + +IMStatusConfig::~IMStatusConfig() +{ + +} + +void IMStatusConfig::defaults() +{ + KCModule::defaults(); +} + +void IMStatusConfig::load() +{ + kDebug(); + KCModule::load(); +} + +void IMStatusConfig::save() +{ + kDebug(); + KCModule::save(); +} + +void IMStatusConfig::emitChanged() +{ + emit changed(true); + //disconnect( ui.kcfg_templateString, SIGNAL(textChanged()), this, SLOT(emitChanged()) ); +} + +#include "imstatusconfig.moc" diff --git a/plugins/imstatus/imstatusconfig.h b/plugins/imstatus/imstatusconfig.h new file mode 100644 index 0000000..2e1210c --- /dev/null +++ b/plugins/imstatus/imstatusconfig.h @@ -0,0 +1,48 @@ +/* + This file is part of Choqok, the KDE micro-blogging client + + Copyright (C) 2009-2010 Mehrdad Momeny + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of + the License or (at your option) version 3 or any later version + accepted by the membership of KDE e.V. (or its successor approved + by the membership of KDE e.V.), which shall act as a proxy + defined in Section 14 of version 3 of the license. + + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see http://www.gnu.org/licenses/ + +*/ + +#ifndef IMSTATUSCONFIG_H +#define IMSTATUSCONFIG_H + +#include +#include "ui_imstatusprefs.h" + +class IMStatusConfig : public KCModule +{ + Q_OBJECT +public: + IMStatusConfig(QWidget* parent, const QVariantList& args); + ~IMStatusConfig(); + + virtual void save(); + virtual void load(); + virtual void defaults(); + +protected slots: + void emitChanged(); +private: + Ui_IMStatusPrefsBase ui; +}; + +#endif // IMSTATUSCONFIG_H diff --git a/plugins/imstatus/imstatusprefs.ui b/plugins/imstatus/imstatusprefs.ui new file mode 100644 index 0000000..48fbb34 --- /dev/null +++ b/plugins/imstatus/imstatusprefs.ui @@ -0,0 +1,51 @@ + + + IMStatusPrefsBase + + + + 0 + 0 + 400 + 221 + + + + + + + + + + Instant Messanger: + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + Status templtate + + + + + + + + diff --git a/plugins/imstatus/imstatussettings.kcfg b/plugins/imstatus/imstatussettings.kcfg new file mode 100644 index 0000000..6201e8d --- /dev/null +++ b/plugins/imstatus/imstatussettings.kcfg @@ -0,0 +1,12 @@ + + + + + + + + + diff --git a/plugins/imstatus/imstatussettings.kcfgc b/plugins/imstatus/imstatussettings.kcfgc new file mode 100644 index 0000000..c362189 --- /dev/null +++ b/plugins/imstatus/imstatussettings.kcfgc @@ -0,0 +1,10 @@ +# Code generation options for kconfig_compiler +File=imstatussettings.kcfg +ClassName=IMStatusSettings +Inherits=KConfigSkeleton +ItemAccessors=true +Singleton=true +Mutators=true +MemberVariables=private +GlobalEnums=false +IncludeFiles=klocale.h -- 2.1.4