From bcb704366cb5e333a626c18c308c7e0448a8e69f Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdenetwork@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- kopete/protocols/sms/Makefile.am | 21 + kopete/protocols/sms/icons/Makefile.am | 3 + .../protocols/sms/icons/cr128-app-sms_protocol.png | Bin 0 -> 14177 bytes .../protocols/sms/icons/cr16-app-sms_protocol.png | Bin 0 -> 1039 bytes .../protocols/sms/icons/cr32-app-sms_protocol.png | Bin 0 -> 2760 bytes .../protocols/sms/icons/cr48-app-sms_protocol.png | Bin 0 -> 5024 bytes .../protocols/sms/icons/cr64-app-sms_protocol.png | Bin 0 -> 7219 bytes kopete/protocols/sms/kopete_sms.desktop | 81 ++++ kopete/protocols/sms/serviceloader.cpp | 74 ++++ kopete/protocols/sms/serviceloader.h | 42 ++ kopete/protocols/sms/services/Makefile.am | 18 + kopete/protocols/sms/services/gsmlib.cpp | 462 +++++++++++++++++++++ kopete/protocols/sms/services/gsmlib.h | 151 +++++++ kopete/protocols/sms/services/gsmlibprefs.ui | 100 +++++ .../protocols/sms/services/kopete_unix_serial.cpp | 445 ++++++++++++++++++++ kopete/protocols/sms/services/kopete_unix_serial.h | 70 ++++ kopete/protocols/sms/services/smsclient.cpp | 192 +++++++++ kopete/protocols/sms/services/smsclient.h | 65 +++ kopete/protocols/sms/services/smsclientprefs.ui | 135 ++++++ kopete/protocols/sms/services/smssend.cpp | 254 +++++++++++ kopete/protocols/sms/services/smssend.h | 66 +++ kopete/protocols/sms/services/smssendprefs.ui | 188 +++++++++ kopete/protocols/sms/services/smssendprovider.cpp | 288 +++++++++++++ kopete/protocols/sms/services/smssendprovider.h | 82 ++++ kopete/protocols/sms/smsaccount.cpp | 202 +++++++++ kopete/protocols/sms/smsaccount.h | 79 ++++ kopete/protocols/sms/smsaddcontactpage.cpp | 65 +++ kopete/protocols/sms/smsaddcontactpage.h | 50 +++ kopete/protocols/sms/smscontact.cpp | 142 +++++++ kopete/protocols/sms/smscontact.h | 74 ++++ kopete/protocols/sms/smseditaccountwidget.cpp | 147 +++++++ kopete/protocols/sms/smseditaccountwidget.h | 64 +++ kopete/protocols/sms/smsprotocol.cpp | 97 +++++ kopete/protocols/sms/smsprotocol.h | 71 ++++ kopete/protocols/sms/smsservice.cpp | 63 +++ kopete/protocols/sms/smsservice.h | 83 ++++ kopete/protocols/sms/smsuserpreferences.cpp | 63 +++ kopete/protocols/sms/smsuserpreferences.h | 44 ++ kopete/protocols/sms/ui/Makefile.am | 8 + kopete/protocols/sms/ui/empty.cpp | 0 kopete/protocols/sms/ui/smsactprefs.ui | 435 +++++++++++++++++++ kopete/protocols/sms/ui/smsadd.ui | 143 +++++++ kopete/protocols/sms/ui/smsuserprefs.ui | 118 ++++++ 43 files changed, 4685 insertions(+) create mode 100644 kopete/protocols/sms/Makefile.am create mode 100644 kopete/protocols/sms/icons/Makefile.am create mode 100644 kopete/protocols/sms/icons/cr128-app-sms_protocol.png create mode 100644 kopete/protocols/sms/icons/cr16-app-sms_protocol.png create mode 100644 kopete/protocols/sms/icons/cr32-app-sms_protocol.png create mode 100644 kopete/protocols/sms/icons/cr48-app-sms_protocol.png create mode 100644 kopete/protocols/sms/icons/cr64-app-sms_protocol.png create mode 100644 kopete/protocols/sms/kopete_sms.desktop create mode 100644 kopete/protocols/sms/serviceloader.cpp create mode 100644 kopete/protocols/sms/serviceloader.h create mode 100644 kopete/protocols/sms/services/Makefile.am create mode 100644 kopete/protocols/sms/services/gsmlib.cpp create mode 100644 kopete/protocols/sms/services/gsmlib.h create mode 100644 kopete/protocols/sms/services/gsmlibprefs.ui create mode 100644 kopete/protocols/sms/services/kopete_unix_serial.cpp create mode 100644 kopete/protocols/sms/services/kopete_unix_serial.h create mode 100644 kopete/protocols/sms/services/smsclient.cpp create mode 100644 kopete/protocols/sms/services/smsclient.h create mode 100644 kopete/protocols/sms/services/smsclientprefs.ui create mode 100644 kopete/protocols/sms/services/smssend.cpp create mode 100644 kopete/protocols/sms/services/smssend.h create mode 100644 kopete/protocols/sms/services/smssendprefs.ui create mode 100644 kopete/protocols/sms/services/smssendprovider.cpp create mode 100644 kopete/protocols/sms/services/smssendprovider.h create mode 100644 kopete/protocols/sms/smsaccount.cpp create mode 100644 kopete/protocols/sms/smsaccount.h create mode 100644 kopete/protocols/sms/smsaddcontactpage.cpp create mode 100644 kopete/protocols/sms/smsaddcontactpage.h create mode 100644 kopete/protocols/sms/smscontact.cpp create mode 100644 kopete/protocols/sms/smscontact.h create mode 100644 kopete/protocols/sms/smseditaccountwidget.cpp create mode 100644 kopete/protocols/sms/smseditaccountwidget.h create mode 100644 kopete/protocols/sms/smsprotocol.cpp create mode 100644 kopete/protocols/sms/smsprotocol.h create mode 100644 kopete/protocols/sms/smsservice.cpp create mode 100644 kopete/protocols/sms/smsservice.h create mode 100644 kopete/protocols/sms/smsuserpreferences.cpp create mode 100644 kopete/protocols/sms/smsuserpreferences.h create mode 100644 kopete/protocols/sms/ui/Makefile.am create mode 100644 kopete/protocols/sms/ui/empty.cpp create mode 100644 kopete/protocols/sms/ui/smsactprefs.ui create mode 100644 kopete/protocols/sms/ui/smsadd.ui create mode 100644 kopete/protocols/sms/ui/smsuserprefs.ui (limited to 'kopete/protocols/sms') diff --git a/kopete/protocols/sms/Makefile.am b/kopete/protocols/sms/Makefile.am new file mode 100644 index 00000000..6a42aebc --- /dev/null +++ b/kopete/protocols/sms/Makefile.am @@ -0,0 +1,21 @@ +METASOURCES = AUTO +SUBDIRS = ui services icons +AM_CPPFLAGS = -I$(srcdir)/ui \ + -I./ui \ + -I$(srcdir)/services \ + -I./services \ + $(KOPETE_INCLUDES) \ + $(all_includes) + +kde_module_LTLIBRARIES = kopete_sms.la + +kopete_sms_la_SOURCES = smsaddcontactpage.cpp smscontact.cpp smseditaccountwidget.cpp \ + smsprotocol.cpp serviceloader.cpp smsservice.cpp smsuserpreferences.cpp \ + smsaccount.cpp +kopete_sms_la_LDFLAGS = -no-undefined -module $(KDE_PLUGIN) $(all_libraries) +kopete_sms_la_LIBADD = ./ui/libkopetesmsui.la \ + ./services/libkopetesmsservices.la \ + ../../libkopete/libkopete.la $(LIB_KIO) + +service_DATA = kopete_sms.desktop +servicedir = $(kde_servicesdir) diff --git a/kopete/protocols/sms/icons/Makefile.am b/kopete/protocols/sms/icons/Makefile.am new file mode 100644 index 00000000..224eb420 --- /dev/null +++ b/kopete/protocols/sms/icons/Makefile.am @@ -0,0 +1,3 @@ +kopeteicondir = $(kde_datadir)/kopete/icons +kopeteicon_ICON = AUTO + diff --git a/kopete/protocols/sms/icons/cr128-app-sms_protocol.png b/kopete/protocols/sms/icons/cr128-app-sms_protocol.png new file mode 100644 index 00000000..732327e2 Binary files /dev/null and b/kopete/protocols/sms/icons/cr128-app-sms_protocol.png differ diff --git a/kopete/protocols/sms/icons/cr16-app-sms_protocol.png b/kopete/protocols/sms/icons/cr16-app-sms_protocol.png new file mode 100644 index 00000000..3bfa3627 Binary files /dev/null and b/kopete/protocols/sms/icons/cr16-app-sms_protocol.png differ diff --git a/kopete/protocols/sms/icons/cr32-app-sms_protocol.png b/kopete/protocols/sms/icons/cr32-app-sms_protocol.png new file mode 100644 index 00000000..16110804 Binary files /dev/null and b/kopete/protocols/sms/icons/cr32-app-sms_protocol.png differ diff --git a/kopete/protocols/sms/icons/cr48-app-sms_protocol.png b/kopete/protocols/sms/icons/cr48-app-sms_protocol.png new file mode 100644 index 00000000..82049813 Binary files /dev/null and b/kopete/protocols/sms/icons/cr48-app-sms_protocol.png differ diff --git a/kopete/protocols/sms/icons/cr64-app-sms_protocol.png b/kopete/protocols/sms/icons/cr64-app-sms_protocol.png new file mode 100644 index 00000000..527771f7 Binary files /dev/null and b/kopete/protocols/sms/icons/cr64-app-sms_protocol.png differ diff --git a/kopete/protocols/sms/kopete_sms.desktop b/kopete/protocols/sms/kopete_sms.desktop new file mode 100644 index 00000000..783aa416 --- /dev/null +++ b/kopete/protocols/sms/kopete_sms.desktop @@ -0,0 +1,81 @@ +[Desktop Entry] +Type=Service +X-Kopete-Version=1000900 +Icon=sms_protocol +ServiceTypes=Kopete/Protocol +X-Kopete-Messaging-Protocol=messaging/sms +X-KDE-Library=kopete_sms +X-KDE-PluginInfo-Author=Richard Lärkäng +X-KDE-PluginInfo-Email=richard@goteborg.utfors.se +X-KDE-PluginInfo-Name=kopete_sms +X-KDE-PluginInfo-Version=0.8.0 +X-KDE-PluginInfo-Website=http://kopete.kde.org +X-KDE-PluginInfo-Category=Protocols +X-KDE-PluginInfo-Depends= +X-KDE-PluginInfo-License=GPL +X-KDE-PluginInfo-EnabledByDefault=false +Name=SMS +Name[bn]=এস-এম-এস +Name[fa]=خدمت پیام کوتاه +Name[hi]=एसएमएस +Name[km]=សេវា​សារ​ខ្លីៗ +Name[ne]=एस एम एस +Name[zh_CN]=短信息 +Comment=Protocol to send SMS messages +Comment[ar]=سيرسل البروتوكول رسالة عن طريق خدمة الرسائل القصيرة +Comment[be]=Пратакол адпраўлення паведамленняў SMS +Comment[bg]=Протокол за изпращане на SMS съобщения +Comment[bn]=এস-এম-এস বার্তা পাঠাতে প্রোটোকল +Comment[br]=Komenad evit kas kemennadoù SMS +Comment[bs]=Protokol za slanje SMS poruka +Comment[ca]=Protocol per a enviar missatges SMS +Comment[cs]=Protokol k odesílání SMS zpráv +Comment[cy]=Protocol i anfon negeseuon SMS +Comment[da]=Protokol til at sende SMS-beskeder +Comment[de]=Protokoll zur Versendung von SMS-Nachrichten +Comment[el]=Πρωτόκολλο για αποστολή μηνυμάτων SMS +Comment[es]=Protocolo de envío de SMS +Comment[et]=Protokoll SMS-ide saatmiseks +Comment[eu]=SMS mezuak bidaltzeko protokoloa +Comment[fa]=قرارداد برای ارسال پیامهای کوتاه +Comment[fi]=Yhteyskäytäntö SMS-viestien lähettämiseen +Comment[fr]=Protocole pour envoyer des SMS +Comment[ga]=Prótacal chun teachtaireachtaí SMS a sheoladh +Comment[gl]=Protocolo para enviar mansaxes SMS +Comment[he]=פרוטוקול שליחת הודעות SMS +Comment[hi]=से जुड़ने का प्रोटोकॉल +Comment[hr]=Protokol za slanje SMS poruka +Comment[hu]=Protokoll SMS üzenetek küldéséhez +Comment[is]=Samskiptamáti til að senda SMS skilaboð +Comment[it]=Protocollo per inviare messaggi SMS +Comment[ja]=SMS メッセージを送るプロトコル +Comment[ka]=SMS შეტყობინებების გაგზავნის ოქმი +Comment[kk]=SMS хабарларын жіберу протоколы +Comment[km]=ពិធីការ​ដើម្បី​ផ្ញើ​សារ​ខ្លីៗ +Comment[lt]=Protokolas SMS žinučių siuntimui +Comment[mk]=Протокол за испраќање на SMS-пораки +Comment[nb]=Protokoll for å sende SMS-meldinger +Comment[nds]=Protokoll för't Sennen vun SMS-Narichten +Comment[ne]=एस एम एस सन्देश पठाउने प्रोटोकल +Comment[nl]=Protocol voor verzenden van SMS-berichten +Comment[nn]=Protokoll for å senda SMS-meldingar +Comment[pl]=Protokół wysyłania wiadomości SMS +Comment[pt]=Protocolo para enviar mensagens SMS +Comment[pt_BR]=Protocolo para o envio de mensagens SMS +Comment[ro]=Protocol de trimis mesaje SMS +Comment[ru]=Протокол отправки сообщений SMS +Comment[sk]=Protokol pre posielanie správ SMS +Comment[sl]=Protokol za pošiljanje SMS sporočil +Comment[sr]=Протокол за слање SMS порука +Comment[sr@Latn]=Protokol za slanje SMS poruka +Comment[sv]=Protokoll för att skicka SMS-meddelanden +Comment[ta]=SMS செய்தி அனுப்ப விதிமுறை +Comment[tg]=Қарордод барои фиристодани SMS пайёмҳо +Comment[tr]=SMS mesajları gönderme iletişim kuralı +Comment[uk]=Протокол для відсилання SMS повідомлень +Comment[uz]=SMS xabarlarni joʻnatish uchun protokol +Comment[uz@cyrillic]=SMS хабарларни жўнатиш учун протокол +Comment[wa]=Protocole po-z evoyî des messaedje SMS +Comment[zh_CN]=发送短信息的协议 +Comment[zh_HK]=用來發送 SMS 訊息的通訊協定 +Comment[zh_TW]=送 SMS 訊息的協定 diff --git a/kopete/protocols/sms/serviceloader.cpp b/kopete/protocols/sms/serviceloader.cpp new file mode 100644 index 00000000..8a64a6c0 --- /dev/null +++ b/kopete/protocols/sms/serviceloader.cpp @@ -0,0 +1,74 @@ +/* ************************************************************************* + * copyright: (C) 2003 Richard Lrkng * + * copyright: (C) 2003 Gav Wood * + ************************************************************************* +*/ + +/* ************************************************************************* + * * + * 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) any later version. * + * * + ************************************************************************* +*/ + +#include "config.h" + +#include +#include +#include + +#include "serviceloader.h" +#include "smssend.h" +#include "smsclient.h" +#ifdef INCLUDE_SMSGSM +# include "gsmlib.h" +#endif +#include "kopeteuiglobal.h" + +SMSService* ServiceLoader::loadService(const QString& name, Kopete::Account* account) +{ + kdWarning( 14160 ) << k_funcinfo << endl; + + SMSService* s; + if (name == "SMSSend") + s = new SMSSend(account); + else if (name == "SMSClient") + s = new SMSClient(account); +#ifdef INCLUDE_SMSGSM + else if (name == "GSMLib") + s = new GSMLib(account); +#endif + else + { + KMessageBox::sorry(Kopete::UI::Global::mainWidget(), i18n("Could not load service %1.").arg(name), + i18n("Error Loading Service")); + s = 0L; + } + + return s; +} + +QStringList ServiceLoader::services() +{ + QStringList toReturn; + toReturn.append("SMSSend"); + toReturn.append("SMSClient"); +#ifdef INCLUDE_SMSGSM + toReturn.append("GSMLib"); +#endif + return toReturn; +} + + +/* + * Local variables: + * c-indentation-style: k&r + * c-basic-offset: 8 + * indent-tabs-mode: t + * End: + */ +// vim: set noet ts=4 sts=4 sw=4: + diff --git a/kopete/protocols/sms/serviceloader.h b/kopete/protocols/sms/serviceloader.h new file mode 100644 index 00000000..fe29ebcc --- /dev/null +++ b/kopete/protocols/sms/serviceloader.h @@ -0,0 +1,42 @@ +/* ************************************************************************* + * copyright: (C) 2003 Richard Lrkng * + * copyright: (C) 2003 Gav Wood * + ************************************************************************* +*/ + +/* ************************************************************************* + * * + * 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) any later version. * + * * + ************************************************************************* +*/ + +#ifndef SERVICELOADER_H +#define SERVICELOADER_H + +#include "smsservice.h" +#include +#include + +class SMSContact; + +class ServiceLoader +{ +public: + static SMSService* loadService(const QString& name, Kopete::Account* account); + static QStringList services(); +} ; + +#endif //SERVICELOADER_H +/* + * Local variables: + * c-indentation-style: k&r + * c-basic-offset: 8 + * indent-tabs-mode: t + * End: + */ +// vim: set noet ts=4 sts=4 sw=4: + diff --git a/kopete/protocols/sms/services/Makefile.am b/kopete/protocols/sms/services/Makefile.am new file mode 100644 index 00000000..e21f1505 --- /dev/null +++ b/kopete/protocols/sms/services/Makefile.am @@ -0,0 +1,18 @@ +METASOURCES = AUTO +AM_CPPFLAGS = $(KOPETE_INCLUDES) \ + -I$(srcdir)/.. \ + -I.. \ + $(all_includes) + +KDE_CXXFLAGS = $(USE_EXCEPTIONS) + +noinst_LTLIBRARIES = libkopetesmsservices.la + + +libkopetesmsservices_la_SOURCES = smssend.cpp smssendprefs.ui smssendprovider.cpp \ + smsclient.cpp smsclientprefs.ui gsmlib.cpp gsmlibprefs.ui kopete_unix_serial.cpp + +if include_smsgsm +libkopetesmsservices_la_LIBADD = -lgsmme +endif + diff --git a/kopete/protocols/sms/services/gsmlib.cpp b/kopete/protocols/sms/services/gsmlib.cpp new file mode 100644 index 00000000..e9b0542b --- /dev/null +++ b/kopete/protocols/sms/services/gsmlib.cpp @@ -0,0 +1,462 @@ +/* ************************************************************************* + * copyright: (C) 2005 Justin Huff * + ************************************************************************* +*/ + +/* ************************************************************************* + * * + * 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) any later version. * + * * + ************************************************************************* +*/ +#include "config.h" +#ifdef INCLUDE_SMSGSM + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "kopeteaccount.h" +#include "kopeteuiglobal.h" +#include "kopetemetacontact.h" +#include "kopetecontactlist.h" +#include "kopetechatsessionmanager.h" + +#include "gsmlib.h" +#include "gsmlibprefs.h" +#include "smsprotocol.h" +#include "smscontact.h" + +#include "kopete_unix_serial.h" + +///////////////////////////////////////////////////////////////////// +#define GSMLIB_EVENT_ID 245 +GSMLibEvent::GSMLibEvent(SubType t) : QCustomEvent(QEvent::User+GSMLIB_EVENT_ID) +{ + setSubType(t); +} + +GSMLibEvent::SubType GSMLibEvent::subType() +{ + return m_subType; +} + +void GSMLibEvent::setSubType(GSMLibEvent::SubType t) +{ + m_subType = t; +} + +///////////////////////////////////////////////////////////////////// +GSMLibThread::GSMLibThread(QString dev, GSMLib* parent) +{ + m_device = dev; + m_parent = parent; + m_run = true; + m_MeTa = NULL; +} + +GSMLibThread::~GSMLibThread() +{ + m_run = false; +} + +void GSMLibThread::stop() +{ + m_run = false; + kdDebug( 14160 ) << "Waiting from GSMLibThread to die"<Reason = QString("GSMLib: Not Connected"); + e->Message = msg; + QApplication::postEvent(m_parent, e); + } +} + + +bool GSMLibThread::doConnect() +{ + // open the port and ME/TA + try + { + kdDebug( 14160 ) << "Connecting to: '"< port = new gsmlib::KopeteUnixSerialPort(m_device.latin1(), 9600, gsmlib::DEFAULT_INIT_STRING, false); + + kdDebug( 14160 ) << "Port created"<getSMSStore(dummy1, dummy2, receiveStoreName ); + m_MeTa->setSMSStore(receiveStoreName, 3); + + m_MeTa->setMessageService(1); + + // switch on SMS routing + m_MeTa->setSMSRoutingToTA(true, false, false, true); + + m_MeTa->setEventHandler(this); + QApplication::postEvent(m_parent, new GSMLibEvent(GSMLibEvent::CONNECTED)); + return true; + } + catch(gsmlib::GsmException &e) + { + kdWarning( 14160 ) << k_funcinfo<< e.what()<waitEvent(&timeoutVal); + + MessageList::iterator it; + for( it=m_newMessages.begin(); it!=m_newMessages.end(); it++) + { + IncomingMessage m = *it; + + // Do we need to fetch it from the ME? + if( m.Message.isnull() ) + { + gsmlib::SMSStoreRef store = m_MeTa->getSMSStore(m.StoreName.latin1()); + store->setCaching(false); + + m.Message = (*store.getptr())[m.Index].message(); + store->erase(store->begin() + m.Index); + } + + GSMLibEvent* e = new GSMLibEvent( GSMLibEvent::NEW_MESSAGE ); + e->Text = m.Message->userData().c_str(); + e->Number = m.Message->address().toString().c_str(); + + QApplication::postEvent(m_parent, e); + + } + m_newMessages.clear(); + } + catch(gsmlib::GsmException &e) + { + kdWarning( 14160 ) << k_funcinfo<< e.what()<Reason = QString("GSMLib: Not Connected"); + e->Message = msg; + QApplication::postEvent(m_parent, e); + } + + QString message = msg.plainBody(); + QString nr = msg.to().first()->contactId(); + + // send SMS + try + { + gsmlib::Ref submitSMS = new gsmlib::SMSSubmitMessage(); + gsmlib::Address destAddr( nr.latin1() ); + submitSMS->setDestinationAddress(destAddr); + m_MeTa->sendSMSs(submitSMS, message.latin1(), true); + + GSMLibEvent* e = new GSMLibEvent( GSMLibEvent::MSG_SENT ); + e->Message = msg; + QApplication::postEvent(m_parent, e); + } + catch(gsmlib::GsmException &e) + { + GSMLibEvent* ev = new GSMLibEvent( GSMLibEvent::MSG_NOT_SENT ); + ev->Reason = QString("GSMLib: ") + e.what(); + ev->Message = msg; + QApplication::postEvent(m_parent, ev); + } +} + +///////////////////////////////////////////////////////////////////// + +GSMLib::GSMLib(Kopete::Account* account) + : SMSService(account) +{ + prefWidget = 0L; + m_thread = NULL; + + loadConfig(); +} + +GSMLib::~GSMLib() +{ + disconnect(); +} + +void GSMLib::saveConfig() +{ + if( m_account != NULL ) + { + KConfigGroup* c = m_account->configGroup(); + + c->writeEntry(QString("%1:%2").arg("GSMLib").arg("Device"), m_device); + } +} + +void GSMLib::loadConfig() +{ + m_device = "/dev/bluetooth/rfcomm0"; + if( m_account != NULL ) + { + QString temp; + KConfigGroup* c = m_account->configGroup(); + + temp = c->readEntry(QString("%1:%2").arg("GSMLib").arg("Device"), QString::null); + if( temp != QString::null ) + m_device = temp; + } +} + +void GSMLib::connect() +{ + + m_thread = new GSMLibThread(m_device, this); + m_thread->start(); + +} + +void GSMLib::disconnect() +{ + kdDebug( 14160 ) << k_funcinfo <stop(); + delete m_thread; + m_thread = NULL; + emit disconnected(); + } + +} + +void GSMLib::setWidgetContainer(QWidget* parent, QGridLayout* layout) +{ + m_parent = parent; + m_layout = layout; + QWidget *configWidget = configureWidget(parent); + layout->addMultiCellWidget(configWidget, 0, 1, 0, 1); + configWidget->show(); +} + +void GSMLib::send(const Kopete::Message& msg) +{ + m_thread->send(msg); +} + +QWidget* GSMLib::configureWidget(QWidget* parent) +{ + + if (prefWidget == 0L) + prefWidget = new GSMLibPrefsUI(parent); + + loadConfig(); + prefWidget->device->setURL(m_device); + + return prefWidget; +} + +void GSMLib::savePreferences() +{ + if( prefWidget ) + { + m_device = prefWidget->device->url(); + } + saveConfig(); +} + +int GSMLib::maxSize() +{ + return 160; +} + +void GSMLib::customEvent(QCustomEvent* e) +{ + if( e->type() != QEvent::User+GSMLIB_EVENT_ID ) + return; + + if( m_account == NULL ) + return; + + GSMLibEvent* ge = (GSMLibEvent*)e; + + kdDebug( 14160 ) << "Got event "<subType()<subType() ) + { + case GSMLibEvent::CONNECTED: + emit connected(); + break; + case GSMLibEvent::DISCONNECTED: + disconnect(); + break; + case GSMLibEvent::MSG_SENT: + emit messageSent(ge->Message); + break; + case GSMLibEvent::MSG_NOT_SENT: + emit messageNotSent(ge->Message, ge->Reason); + break; + case GSMLibEvent::NEW_MESSAGE: + { + QString nr = ge->Number; + QString text = ge->Text; + + // Locate a contact + SMSContact* contact = static_cast( m_account->contacts().find( nr )); + if ( contact==NULL ) + { + // No contact found, make a new one + Kopete::MetaContact* metaContact = new Kopete::MetaContact (); + metaContact->setTemporary ( true ); + contact = new SMSContact(m_account, nr, nr, metaContact ); + Kopete::ContactList::self ()->addMetaContact( metaContact ); + contact->setOnlineStatus( SMSProtocol::protocol()->SMSOnline ); + } + + // Deliver the msg + Kopete::Message msg( contact, m_account->myself(), text, Kopete::Message::Inbound, Kopete::Message::RichText ); + contact->manager(Kopete::Contact::CanCreate)->appendMessage( msg ); + break; + } + } +} + + + + +const QString& GSMLib::description() +{ + QString url = "http://www.pxh.de/fs/gsmlib/"; + m_description = i18n("GSMLib is a library (and utilities) for sending SMS via a GSM device. The program can be found on %1").arg(url).arg(url); + return m_description; +} + +#include "gsmlib.moc" + +#endif +/* + * Local variables: + * c-indentation-style: k&r + * c-basic-offset: 8 + * indent-tabs-mode: t + * End: + */ +// vim: set noet ts=4 sts=4 sw=4: + diff --git a/kopete/protocols/sms/services/gsmlib.h b/kopete/protocols/sms/services/gsmlib.h new file mode 100644 index 00000000..fa9ef1d2 --- /dev/null +++ b/kopete/protocols/sms/services/gsmlib.h @@ -0,0 +1,151 @@ +/* ************************************************************************* + * copyright: (C) 2005 Justin Huff * + ************************************************************************* +*/ + +/* ************************************************************************* + * * + * 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) any later version. * + * * + ************************************************************************* +*/ + +#ifndef GSMLIB_H_039562406 +#define GSMLIB_H_039562406 + +#include "config.h" +#ifdef INCLUDE_SMSGSM + +#include + +#include +#include +#include +#include +#include + +#include "smsservice.h" +#include "kopetemessage.h" + +#include +#include +#include +#include +#include +#include + +class GSMLibPrefsUI; +class SMSContact; +class QListViewItem; +class KProcess; +class GSMLibThread; + +class GSMLib : public SMSService +{ + Q_OBJECT +public: + GSMLib(Kopete::Account* account); + ~GSMLib(); + + void send(const Kopete::Message& msg); + void setWidgetContainer(QWidget* parent, QGridLayout* container); + + int maxSize(); + const QString& description(); + +public slots: + void savePreferences(); + virtual void connect(); + virtual void disconnect(); + +//signals: +// void messageSent(const Kopete::Message &); +protected: + virtual void customEvent(QCustomEvent* e); + + QWidget* configureWidget(QWidget* parent); + void saveConfig(); + void loadConfig(); + + GSMLibPrefsUI* prefWidget; + QStringList output; + + QString m_device; + + QString m_description; + + GSMLibThread* m_thread; + +} ; + + +/// Custom event for async-events +class GSMLibEvent : public QCustomEvent +{ +public: + enum SubType { CONNECTED, DISCONNECTED, NEW_MESSAGE, MSG_SENT, MSG_NOT_SENT }; + + GSMLibEvent(SubType t); + + SubType subType(); + void setSubType(SubType t); + + QString Text; + QString Number; + + QString Reason; + + Kopete::Message Message; +protected: + SubType m_subType; +}; + +/// Thread to deal with GsmLib's blocking +class GSMLibThread : public QThread, gsmlib::GsmEvent +{ +public: + GSMLibThread(QString dev, GSMLib* parent); + virtual ~GSMLibThread(); + + virtual void run(); + void stop(); + void send(const Kopete::Message& msg); +protected: + bool doConnect(); + void pollForMessages(); + void sendMessageQueue(); + void sendMessage(const Kopete::Message& msg); + void SMSReception(gsmlib::SMSMessageRef newMessage, SMSMessageType messageType); + void SMSReceptionIndication(std::string storeName, unsigned int index, SMSMessageType messageType); + + GSMLib* m_parent; + QString m_device; + + gsmlib::MeTa* m_MeTa; + + bool m_run; + + struct IncomingMessage + { + int Index; + QString StoreName; + gsmlib::SMSMessageRef Message; + GsmEvent::SMSMessageType Type; + + IncomingMessage() : Index(-1) + {} + }; + + typedef QValueList MessageList; + MessageList m_newMessages; + + typedef QValueList KopeteMessageList; + KopeteMessageList m_outMessages; + QMutex m_outMessagesMutex; +}; + +#endif +#endif //GSMLIB_H_039562406 diff --git a/kopete/protocols/sms/services/gsmlibprefs.ui b/kopete/protocols/sms/services/gsmlibprefs.ui new file mode 100644 index 00000000..108f6326 --- /dev/null +++ b/kopete/protocols/sms/services/gsmlibprefs.ui @@ -0,0 +1,100 @@ + +GSMLibPrefsUI + + + GSMLibPrefsUI + + + + 0 + 0 + 375 + 168 + + + + + unnamed + + + 0 + + + + spacer16 + + + Horizontal + + + Expanding + + + + 321 + 16 + + + + + + textLabel8 + + + + 1 + + + + GSMLib Settings + + + + + line14 + + + HLine + + + Sunken + + + Horizontal + + + + + layout13 + + + + unnamed + + + + textLabel1 + + + Device: + + + program + + + + + device + + + + + + + + + kurlrequester.h + klineedit.h + kpushbutton.h + + diff --git a/kopete/protocols/sms/services/kopete_unix_serial.cpp b/kopete/protocols/sms/services/kopete_unix_serial.cpp new file mode 100644 index 00000000..b694ab22 --- /dev/null +++ b/kopete/protocols/sms/services/kopete_unix_serial.cpp @@ -0,0 +1,445 @@ +// ************************************************************************* +// * Taken from the GSM TA/ME library +// * +// * File: gsm_unix_port.cc +// * +// * Purpose: UNIX serial port implementation with extras +// * +// * Original Author: Peter Hofmann (software@pxh.de) +// * Modified by: Justin Huff (jjhuff@mspin.net) +// * +// * Created: 10.5.1999 +// ************************************************************************* +#include "config.h" +#ifdef INCLUDE_SMSGSM + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "kopete_unix_serial.h" + +using namespace std; +using namespace gsmlib; + +static const int holdoff[] = {2000000, 1000000, 400000}; +static const int holdoffArraySize = sizeof(holdoff)/sizeof(int); + +// alarm handling for socket read/write +// the timerMtx is necessary since several threads cannot use the +// timer indepently of each other + +static pthread_mutex_t timerMtx = PTHREAD_MUTEX_INITIALIZER; +#define pthread_mutex_lock(x) +#define pthread_mutex_unlock(x) + +// for non-GNU systems, define alarm() +#ifndef HAVE_ALARM +unsigned int alarm(unsigned int seconds) +{ + struct itimerval old, newt; + newt.it_interval.tv_usec = 0; + newt.it_interval.tv_sec = 0; + newt.it_value.tv_usec = 0; + newt.it_value.tv_sec = (long int)seconds; + if (setitimer(ITIMER_REAL, &newt, &old) < 0) + return 0; + else + return old.it_value.tv_sec; +} +#endif + +// this routine is called in case of a timeout +static void catchAlarm(int) +{ + // do nothing +} + +// start timer +static void startTimer() +{ + pthread_mutex_lock(&timerMtx); + struct sigaction newAction; + newAction.sa_handler = catchAlarm; + newAction.sa_flags = 0; + sigaction(SIGALRM, &newAction, NULL); + alarm(1); +} + +// reset timer +static void stopTimer() +{ + alarm(0); + sigaction(SIGALRM, NULL, NULL); + pthread_mutex_unlock(&timerMtx); +} + +// KopeteUnixSerialPort members + +void KopeteUnixSerialPort::throwModemException(string message) throw(GsmException) +{ + ostringstream os; + os << message << " (errno: " << errno << "/" << strerror(errno) << ")"; + throw GsmException(os.str(), OSError, errno); +} + +void KopeteUnixSerialPort::putBack(unsigned char c) +{ + assert(_oldChar == -1); + _oldChar = c; +} + +int KopeteUnixSerialPort::readByte() throw(GsmException) +{ + if (_oldChar != -1) + { + int result = _oldChar; + _oldChar = -1; + return result; + } + + unsigned char c; + int timeElapsed = 0; + struct timeval oneSecond; + bool readDone = false; + + while (! readDone && timeElapsed < _timeoutVal) + { + if (interrupted()) + throwModemException("interrupted when reading from TA"); + + // setup fd_set data structure for select() + fd_set fdSet; + oneSecond.tv_sec = 1; + oneSecond.tv_usec = 0; + FD_ZERO(&fdSet); + FD_SET(_fd, &fdSet); + + switch (select(FD_SETSIZE, &fdSet, NULL, NULL, &oneSecond)) + { + case 1: + { + int res = read(_fd, &c, 1); + if (res != 1) + throwModemException("end of file when reading from TA"); + else + readDone = true; + break; + } + case 0: + ++timeElapsed; + break; + default: + if (errno != EINTR) + throwModemException("reading from TA"); + break; + } + } + if (! readDone) + throwModemException("timeout when reading from TA"); + +#ifndef NDEBUG + if (debugLevel() >= 2) + { + // some useful debugging code + if (c == LF) + cerr << ""; + else if (c == CR) + cerr << ""; + else cerr << "<'" << (char) c << "'>"; + cerr.flush(); + } +#endif + return c; +} + +KopeteUnixSerialPort::KopeteUnixSerialPort(string device, speed_t lineSpeed, + string initString, bool swHandshake) + throw(GsmException) : + _oldChar(-1), _timeoutVal(TIMEOUT_SECS) +{ + _readNotifier = NULL; + + struct termios t; + + // open device + _fd = open(device.c_str(), O_RDWR | O_NOCTTY | O_NONBLOCK); + if (_fd == -1) + throwModemException("opening device"); + + // switch off non-blocking mode + int fdFlags; + if ((fdFlags = fcntl(_fd, F_GETFL)) == -1) + { + close(_fd); + throwModemException("getting file status flags failed"); + } + fdFlags &= ~O_NONBLOCK; + if (fcntl(_fd, F_SETFL, fdFlags) == -1) + { + close(_fd); + throwModemException("switching of non-blocking mode failed"); + } + + // Set the close on exec flag + if ((fdFlags = fcntl(_fd, F_GETFD)) == -1) + { + close(_fd); + throwModemException("getting file status flags failed"); + } + fdFlags |= FD_CLOEXEC; + if (fcntl(_fd, F_SETFD, fdFlags) == -1) + { + close(_fd); + throwModemException("switching of non-blocking mode failed"); + } + + long int saveTimeoutVal = _timeoutVal; + _timeoutVal = 3; + int initTries = holdoffArraySize; + while (initTries-- > 0) + { + // flush all pending output + tcflush(_fd, TCOFLUSH); + + // toggle DTR to reset modem + int mctl = TIOCM_DTR; + if (ioctl(_fd, TIOCMBIC, &mctl) < 0 && errno != ENOTTY) + { + close(_fd); + throwModemException("clearing DTR failed"); + } + // the waiting time for DTR toggling is increased with each loop + usleep(holdoff[initTries]); + if (ioctl(_fd, TIOCMBIS, &mctl) < 0 && errno != ENOTTY) + { + close(_fd); + throwModemException("setting DTR failed"); + } + // get line modes + if (tcgetattr(_fd, &t) < 0) + { + close(_fd); + throwModemException("tcgetattr device"); + } + + // set line speed + cfsetispeed(&t, lineSpeed); + cfsetospeed(&t, lineSpeed); + + // set the device to a sane state + t.c_iflag |= IGNPAR | (swHandshake ? IXON | IXOFF : 0); + t.c_iflag &= ~(INPCK | ISTRIP | IMAXBEL | + (swHandshake ? 0 : IXON | IXOFF) + | IXANY | IGNCR | ICRNL | IMAXBEL | INLCR | IGNBRK); + t.c_oflag &= ~(OPOST); + // be careful, only touch "known" flags + t.c_cflag &= ~(CSIZE | CSTOPB | PARENB | PARODD | + (swHandshake ? CRTSCTS : 0 )); + t.c_cflag |= CS8 | CREAD | HUPCL | (swHandshake ? 0 : CRTSCTS) | CLOCAL; + t.c_lflag &= ~(ECHO | ECHOE | ECHOPRT | ECHOK | ECHOKE | ECHONL | + ECHOCTL | ISIG | IEXTEN | TOSTOP | FLUSHO | ICANON); + t.c_lflag |= NOFLSH; + t.c_cc[VMIN] = 1; + t.c_cc[VTIME] = 0; + + t.c_cc[VSUSP] = 0; + + // write back + if(tcsetattr (_fd, TCSANOW, &t) < 0) + { + close(_fd); + throwModemException("tcsetattr device"); + } + // the waiting time for writing to the ME/TA is increased with each loop + usleep(holdoff[initTries]); + + // flush all pending input + tcflush(_fd, TCIFLUSH); + + try + { + // reset modem + putLine("ATZ"); + bool foundOK = false; + int readTries = 5; + while (readTries-- > 0) + { + // for the first call getLine() waits only 3 seconds + // because of _timeoutVal = 3 + string s = getLine(); + if (s.find("OK") != string::npos || + s.find("CABLE: GSM") != string::npos) + { + foundOK = true; + readTries = 0; // found OK, exit loop + } + else if (s.find("ERROR") != string::npos) + readTries = 0; // error, exit loop + } + + // set getLine/putLine timeout back to old value + _timeoutVal = saveTimeoutVal; + + if (foundOK) + { + // init modem + readTries = 5; + putLine("AT" + initString); + while (readTries-- > 0) + { + string s = getLine(); + if (s.find("OK") != string::npos || + s.find("CABLE: GSM") != string::npos) + { + _readNotifier = new QSocketNotifier(_fd, QSocketNotifier::Read); + connect( _readNotifier, SIGNAL(activated(int)), this, SIGNAL(activated())); + return; // found OK, return + } + } + } + } + catch (GsmException &e) + { + _timeoutVal = saveTimeoutVal; + if (initTries == 0) + { + close(_fd); + throw e; + } + } + } + // no response after 3 tries + close(_fd); + throwModemException("reset modem failed"); +} + +string KopeteUnixSerialPort::getLine() throw(GsmException) +{ + string result; + int c; + while ((c = readByte()) >= 0) + { + while (c == CR) + { + c = readByte(); + } + if (c == LF) + break; + result += c; + } + +#ifndef NDEBUG + if (debugLevel() >= 1) + cerr << "<-- " << result << endl; +#endif + + return result; +} + +void KopeteUnixSerialPort::putLine(string line, + bool carriageReturn) throw(GsmException) +{ +#ifndef NDEBUG + if (debugLevel() >= 1) + cerr << "--> " << line << endl; +#endif + + if (carriageReturn) line += CR; + const char *l = line.c_str(); + + int timeElapsed = 0; + struct timeval oneSecond; + + ssize_t bytesWritten = 0; + while (bytesWritten < (ssize_t)line.length() && timeElapsed < _timeoutVal) + { + if (interrupted()) + throwModemException("interrupted when writing to TA"); + + // setup fd_set data structure for select() + fd_set fdSet; + oneSecond.tv_sec = 1; + oneSecond.tv_usec = 0; + FD_ZERO(&fdSet); + FD_SET(_fd, &fdSet); + + switch (select(FD_SETSIZE, NULL, &fdSet, NULL, &oneSecond)) + { + case 1: + { + ssize_t bw = write(_fd, l + bytesWritten, line.length() - bytesWritten); + if (bw < 0) + throwModemException("writing to TA"); + bytesWritten += bw; + break; + } + case 0: + ++timeElapsed; + break; + default: + if (errno != EINTR) + throwModemException("writing to TA"); + break; + } + } + + while (timeElapsed < _timeoutVal) + { + if (interrupted()) + throwModemException("interrupted when writing to TA"); + ::startTimer(); + int res = tcdrain(_fd); // wait for output to be read by TA + ::stopTimer(); + if (res == 0) + break; + else + { + assert(errno == EINTR); + ++timeElapsed; + } + } + if (timeElapsed >= _timeoutVal) + throwModemException("timeout when writing to TA"); + + // echo CR LF must be removed by higher layer functions in gsm_at because + // in order to properly handle unsolicited result codes from the ME/TA +} + +bool KopeteUnixSerialPort::wait(GsmTime timeout) throw(GsmException) +{ + fd_set fds; + FD_ZERO(&fds); + FD_SET(_fd, &fds); + return select(FD_SETSIZE, &fds, NULL, NULL, timeout) != 0; +} + +// set timeout for read or write in seconds. +void KopeteUnixSerialPort::setTimeOut(unsigned int timeout) +{ + _timeoutVal = timeout; +} + +KopeteUnixSerialPort::~KopeteUnixSerialPort() +{ + delete _readNotifier; + _readNotifier = NULL; + if (_fd != -1) + close(_fd); +} + +#include "kopete_unix_serial.moc" + +#endif diff --git a/kopete/protocols/sms/services/kopete_unix_serial.h b/kopete/protocols/sms/services/kopete_unix_serial.h new file mode 100644 index 00000000..0248556b --- /dev/null +++ b/kopete/protocols/sms/services/kopete_unix_serial.h @@ -0,0 +1,70 @@ +// ************************************************************************* +// * Taken from the GSM TA/ME library +// * +// * File: gsm_unix_port.h +// * +// * Purpose: UNIX serial port implementation with extras +// * +// * Original Author: Peter Hofmann (software@pxh.de) +// * Modified by: Justin Huff (jjhuff@mspin.net) +// * +// * Created: 4.5.1999 +// ************************************************************************* + +#ifndef GSM_UNIX_SERIAL_KOPETE_H +#define GSM_UNIX_SERIAL_KOPETE_H + +#include "config.h" +#ifdef INCLUDE_SMSGSM + +#include +#include +#include +#include +#include +#include + +#include + +class QSocketNotifier; +namespace gsmlib +{ + +class KopeteUnixSerialPort : public QObject, public Port +{ + Q_OBJECT; + +protected: + int _fd; // file descriptor for device + int _oldChar; // character set by putBack() (-1 == none) + long int _timeoutVal; // timeout for getLine/readByte + + QSocketNotifier* _readNotifier; + + // throw GsmException include UNIX errno + void throwModemException(std::string message) throw(GsmException); + +public: + // create Port given the UNIX device name + KopeteUnixSerialPort(std::string device, speed_t lineSpeed = DEFAULT_BAUD_RATE, + std::string initString = DEFAULT_INIT_STRING, + bool swHandshake = false) + throw(GsmException); + virtual ~KopeteUnixSerialPort(); + + // inherited from Port + void putBack(unsigned char c); + int readByte() throw(GsmException); + std::string getLine() throw(GsmException); + void putLine(std::string line, + bool carriageReturn = true) throw(GsmException); + bool wait(GsmTime timeout) throw(GsmException); + void setTimeOut(unsigned int timeout); + +signals: + void activated(); +}; + +} +#endif +#endif // GSM_UNIX_SERIAL_KOPETE_H diff --git a/kopete/protocols/sms/services/smsclient.cpp b/kopete/protocols/sms/services/smsclient.cpp new file mode 100644 index 00000000..96c04818 --- /dev/null +++ b/kopete/protocols/sms/services/smsclient.cpp @@ -0,0 +1,192 @@ +/* ************************************************************************* + * copyright: (C) 2003 Richard Lrkng * + * copyright: (C) 2003 Gav Wood * + ************************************************************************* +*/ + +/* ************************************************************************* + * * + * 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) any later version. * + * * + ************************************************************************* +*/ + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "kopeteaccount.h" +#include "kopeteuiglobal.h" + +#include "smsclient.h" +#include "smsclientprefs.h" +#include "smsprotocol.h" + +SMSClient::SMSClient(Kopete::Account* account) + : SMSService(account) +{ + prefWidget = 0L; +} + +SMSClient::~SMSClient() +{ +} + +void SMSClient::setWidgetContainer(QWidget* parent, QGridLayout* layout) +{ + kdWarning( 14160 ) << k_funcinfo << "ml: " << layout << ", " << "mp: " << parent << endl; + m_parent = parent; + m_layout = layout; + QWidget *configWidget = configureWidget(parent); + layout->addMultiCellWidget(configWidget, 0, 1, 0, 1); + configWidget->show(); +} + +void SMSClient::send(const Kopete::Message& msg) +{ + kdWarning( 14160 ) << k_funcinfo << "m_account = " << m_account << " (should be non-zero!!)" << endl; + if (!m_account) return; + + m_msg = msg; + + KConfigGroup* c = m_account->configGroup(); + QString provider = c->readEntry(QString("%1:%2").arg("SMSClient").arg("ProviderName"), QString::null); + + if (provider.isNull()) + { + KMessageBox::error(Kopete::UI::Global::mainWidget(), i18n("No provider configured"), i18n("Could Not Send Message")); + return; + } + + QString programName = c->readEntry(QString("%1:%2").arg("SMSClient").arg("ProgramName"). QString::null); + if (programName.isNull()) + programName = "/usr/bin/sms_client"; + + KProcess* p = new KProcess; + + QString message = msg.plainBody(); + QString nr = msg.to().first()->contactId(); + + *p << programName; + *p << provider + ":" + nr; + *p << message; + + QObject::connect(p, SIGNAL(processExited(KProcess *)), this, SLOT(slotSendFinished(KProcess*))); + QObject::connect(p, SIGNAL(receivedStdout(KProcess*, char*, int)), this, SLOT(slotReceivedOutput(KProcess*, char*, int))); + QObject::connect(p, SIGNAL(receivedStderr(KProcess*, char*, int)), this, SLOT(slotReceivedOutput(KProcess*, char*, int))); + + p->start(KProcess::Block, KProcess::AllOutput); +} + +QWidget* SMSClient::configureWidget(QWidget* parent) +{ + kdWarning( 14160 ) << k_funcinfo << "m_account = " << m_account << " (should be ok if zero!!)" << endl; + + if (prefWidget == 0L) + prefWidget = new SMSClientPrefsUI(parent); + + prefWidget->configDir->setMode(KFile::Directory); + QString configDir; + if (m_account) + configDir = m_account->configGroup()->readEntry(QString("%1:%2").arg("SMSClient").arg("ConfigDir"), QString::null); + if (configDir.isNull()) + configDir = "/etc/sms"; + prefWidget->configDir->setURL(configDir); + + QString programName; + if (m_account) + programName = m_account->configGroup()->readEntry(QString("%1:%2").arg("SMSClient").arg("ProgramName"), + QString::null); + if (programName.isNull()) + programName = "/usr/bin/sms_client"; + prefWidget->program->setURL(programName); + + prefWidget->provider->insertStringList(providers()); + + if (m_account) + { + QString pName = m_account->configGroup()->readEntry(QString("%1:%2").arg("SMSClient").arg("ProviderName")); + for (int i=0; i < prefWidget->provider->count(); i++) + { + if (prefWidget->provider->text(i) == pName) + { + prefWidget->provider->setCurrentItem(i); + break; + } + } + } + + return prefWidget; +} + +void SMSClient::savePreferences() +{ + kdWarning( 14160 ) << k_funcinfo << "m_account = " << m_account << " (should be work if zero!!)" << endl; + + if (prefWidget != 0L && m_account != 0L) + { + KConfigGroup* c = m_account->configGroup(); + + c->writeEntry(QString("%1:%2").arg("SMSClient").arg("ProgramName"), prefWidget->program->url()); + c->writeEntry(QString("%1:%2").arg("SMSClient").arg("ConfigDir"), prefWidget->configDir->url()); + c->writeEntry(QString("%1:%2").arg("SMSClient").arg("ProviderName"), prefWidget->provider->currentText()); + } +} + +QStringList SMSClient::providers() +{ + QStringList p; + + QDir d; + d.setPath(QString("%1/services/").arg(prefWidget->configDir->url())); + p += d.entryList("*", QDir::Files); + + return p; +} + +void SMSClient::slotReceivedOutput(KProcess*, char *buffer, int buflen) +{ + QStringList lines = QStringList::split("\n", QString::fromLocal8Bit(buffer, buflen)); + for (QStringList::Iterator it = lines.begin(); it != lines.end(); ++it) + output.append(*it); +} + +void SMSClient::slotSendFinished(KProcess* p) +{ + if (p->exitStatus() == 0) + emit messageSent(m_msg); + else + emit messageNotSent(m_msg, output.join("\n")); +} + +int SMSClient::maxSize() +{ + return 160; +} + +const QString& SMSClient::description() +{ + QString url = "http://www.smsclient.org"; + m_description = i18n("SMSClient is a program for sending SMS with the modem. The program can be found on %1").arg(url).arg(url); + return m_description; +} + +#include "smsclient.moc" +/* + * Local variables: + * c-indentation-style: k&r + * c-basic-offset: 8 + * indent-tabs-mode: t + * End: + */ +// vim: set noet ts=4 sts=4 sw=4: + diff --git a/kopete/protocols/sms/services/smsclient.h b/kopete/protocols/sms/services/smsclient.h new file mode 100644 index 00000000..bc260228 --- /dev/null +++ b/kopete/protocols/sms/services/smsclient.h @@ -0,0 +1,65 @@ +/* ************************************************************************* + * copyright: (C) 2003 Richard Lrkng * + * copyright: (C) 2003 Gav Wood * + ************************************************************************* +*/ + +/* ************************************************************************* + * * + * 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) any later version. * + * * + ************************************************************************* +*/ + +#ifndef SMSCLIENT_H +#define SMSCLIENT_H + +#include "smsservice.h" +#include "kopetemessage.h" + +#include +#include + +class SMSClientPrefsUI; +class SMSContact; +class QListViewItem; +class KProcess; + +class SMSClient : public SMSService +{ + Q_OBJECT +public: + SMSClient(Kopete::Account* account); + ~SMSClient(); + + void send(const Kopete::Message& msg); + void setWidgetContainer(QWidget* parent, QGridLayout* container); + + int maxSize(); + const QString& description(); + +public slots: + void savePreferences(); + +private slots: + void slotReceivedOutput(KProcess*, char *buffer, int buflen); + void slotSendFinished(KProcess* p); +signals: + void messageSent(const Kopete::Message &); + +private: + QWidget* configureWidget(QWidget* parent); + + SMSClientPrefsUI* prefWidget; + QStringList providers(); + QStringList output; + + Kopete::Message m_msg; + + QString m_description; +} ; + +#endif //SMSCLIENT_H diff --git a/kopete/protocols/sms/services/smsclientprefs.ui b/kopete/protocols/sms/services/smsclientprefs.ui new file mode 100644 index 00000000..363081e3 --- /dev/null +++ b/kopete/protocols/sms/services/smsclientprefs.ui @@ -0,0 +1,135 @@ + +SMSClientPrefsUI + + + SMSClientPrefsUI + + + + 0 + 0 + 375 + 168 + + + + + unnamed + + + 0 + + + + spacer16 + + + Horizontal + + + Expanding + + + + 321 + 16 + + + + + + textLabel8 + + + + 1 + + + + SMSClient Settings + + + + + line14 + + + HLine + + + Sunken + + + Horizontal + + + + + layout13 + + + + unnamed + + + + textLabel1 + + + SMSClient &program: + + + program + + + + + textLabel3 + + + Pro&vider: + + + provider + + + + + program + + + + + configDir + + + + + provider + + + + + textLabel2 + + + SMSClient &config path: + + + configDir + + + + + + + + + kurlrequester.h + klineedit.h + kpushbutton.h + kurlrequester.h + klineedit.h + kpushbutton.h + + diff --git a/kopete/protocols/sms/services/smssend.cpp b/kopete/protocols/sms/services/smssend.cpp new file mode 100644 index 00000000..f3ea258c --- /dev/null +++ b/kopete/protocols/sms/services/smssend.cpp @@ -0,0 +1,254 @@ +/* ************************************************************************* + * copyright: (C) 2003 Richard L�k�g * + * copyright: (C) 2003 Gav Wood * + ************************************************************************* +*/ + +/* ************************************************************************* + * * + * 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) any later version. * + * * + ************************************************************************* +*/ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "kopeteaccount.h" +#include "kopeteuiglobal.h" + +#include "smssend.h" +#include "smssendprefs.h" +#include "smssendprovider.h" +#include "smsprotocol.h" + +SMSSend::SMSSend(Kopete::Account* account) + : SMSService(account) +{ + kdWarning( 14160 ) << k_funcinfo << " this = " << this << endl; + prefWidget = 0L; + m_provider = 0L; +} + +SMSSend::~SMSSend() +{ +} + +void SMSSend::send(const Kopete::Message& msg) +{ + kdWarning( 14160 ) << k_funcinfo << "m_account = " << m_account << " (should be non-zero!!)" << endl; + QString provider = m_account->configGroup()->readEntry("SMSSend:ProviderName", QString::null); + + if (provider.length() < 1) + { + KMessageBox::error(Kopete::UI::Global::mainWidget(), i18n("No provider configured."), i18n("Could Not Send Message")); + return; + } + + QString prefix = m_account->configGroup()->readEntry("SMSSend:Prefix", QString::null); + if (prefix.isNull()) + { + KMessageBox::error(Kopete::UI::Global::mainWidget(), i18n("No prefix set for SMSSend, please change it in the configuration dialog."), i18n("No Prefix")); + return; + } + + m_provider = new SMSSendProvider(provider, prefix, m_account, this); + + QObject::connect( m_provider, SIGNAL(messageSent(const Kopete::Message &)), this, SIGNAL(messageSent(const Kopete::Message &))); + QObject::connect( m_provider, SIGNAL(messageNotSent(const Kopete::Message &, const QString &)), this, SIGNAL(messageNotSent(const Kopete::Message &, const QString &))); + + m_provider->send(msg); +} + +void SMSSend::setWidgetContainer(QWidget* parent, QGridLayout* layout) +{ + kdWarning( 14160 ) << k_funcinfo << "ml: " << layout << ", " << "mp: " << parent << endl; + m_parent = parent; + m_layout = layout; + + // could end up being deleted twice?? + delete prefWidget; + prefWidget = new SMSSendPrefsUI(parent); + layout->addMultiCellWidget(prefWidget, 0, 1, 0, 1); + + prefWidget->program->setMode(KFile::Directory); + + QString prefix = QString::null; + + if (m_account) + prefix = m_account->configGroup()->readEntry("SMSSend:Prefix", QString::null); + if (prefix.isNull()) + { + QDir d("/usr/share/smssend"); + if (d.exists()) + { + prefix = "/usr"; + } + d = "/usr/local/share/smssend"; + if (d.exists()) + { + prefix="/usr/local"; + } + else + { + prefix="/usr"; + } + } + + QObject::connect (prefWidget->program, SIGNAL(textChanged(const QString &)), + this, SLOT(loadProviders(const QString&))); + + prefWidget->program->setURL(prefix); + + QObject::connect(prefWidget->provider, SIGNAL(activated(const QString &)), + this, SLOT(setOptions(const QString &))); + + prefWidget->show(); +} + +void SMSSend::savePreferences() +{ + if (prefWidget != 0L && m_account != 0L && m_provider != 0L ) + { + m_account->configGroup()->writeEntry("SMSSend:Prefix", prefWidget->program->url()); + m_account->configGroup()->writeEntry("SMSSend:ProviderName", prefWidget->provider->currentText()); + m_provider->save(args); + } +} + +void SMSSend::loadProviders(const QString &prefix) +{ + kdWarning( 14160 ) << k_funcinfo << "m_account = " << m_account << " (should be ok if zero)" << endl; + + QStringList p; + + prefWidget->provider->clear(); + + QDir d(prefix + "/share/smssend"); + if (!d.exists()) + { + setOptions(QString::null); + return; + } + + p = d.entryList("*.sms"); + + d = QDir::homeDirPath()+"/.smssend/"; + + QStringList tmp(d.entryList("*.sms")); + + for (QStringList::Iterator it = tmp.begin(); it != tmp.end(); ++it) + p.prepend(*it); + + for (QStringList::iterator it = p.begin(); it != p.end(); ++it) + (*it).truncate((*it).length()-4); + + prefWidget->provider->insertStringList(p); + + bool found = false; + if (m_account) + { QString pName = m_account->configGroup()->readEntry("SMSSend:ProviderName", QString::null); + for (int i=0; i < prefWidget->provider->count(); i++) + { + if (prefWidget->provider->text(i) == pName) + { + found=true; + prefWidget->provider->setCurrentItem(i); + setOptions(pName); + break; + } + } + } + if (!found) + setOptions(prefWidget->provider->currentText()); +} + +void SMSSend::setOptions(const QString& name) +{ + kdWarning( 14160 ) << k_funcinfo << "m_account = " << m_account << " (should be ok if zero!!)" << endl; + if(!prefWidget) return; // sanity check + + prefWidget->providerLabel->setText(i18n("%1 Settings").arg(name)); + + labels.setAutoDelete(true); + labels.clear(); + args.setAutoDelete(true); + args.clear(); + + if (m_provider) delete m_provider; + m_provider = new SMSSendProvider(name, prefWidget->program->url(), m_account, this); + + for (int i=0; i < m_provider->count(); i++) + { + if (!m_provider->name(i).isNull()) + { + QLabel *l = new QLabel(m_parent); + l->setText("&" + m_provider->name(i) + ":"); + QToolTip::add(l, m_provider->description(i)); + m_layout->addWidget(l, i+2, 0); + KLineEdit *e = new KLineEdit(m_parent); + e->setText(m_provider->value(i)); + m_layout->addWidget(e, i+2, 1); + args.append(e); + labels.append(l); + l->setBuddy(e); + if(m_provider->isHidden(i)) + e->setEchoMode(QLineEdit::Password); + e->show(); + l->show(); + } + } +} +void SMSSend::setAccount(Kopete::Account* account) +{ + m_provider->setAccount(account); + SMSService::setAccount(account); +} + +int SMSSend::maxSize() +{ + kdWarning( 14160 ) << k_funcinfo << "m_account = " << m_account << " (should be non-zero!!)" << endl; + + QString pName = m_account->configGroup()->readEntry("SMSSend:ProviderName", QString::null); + if (pName.length() < 1) + return 160; + QString prefix = m_account->configGroup()->readEntry("SMSSend:Prefix", QString::null); + if (prefix.isNull()) + prefix = "/usr"; + // quick sanity check + if (m_provider) delete m_provider; + m_provider = new SMSSendProvider(pName, prefix, m_account, this); + return m_provider->maxSize(); +} + +const QString& SMSSend::description() +{ + QString url = "http://zekiller.skytech.org/smssend_en.php"; + m_description = i18n("SMSSend is a program for sending SMS through gateways on the web. It can be found on %2").arg(url).arg(url); + return m_description; +} + + +#include "smssend.moc" +/* + * Local variables: + * c-indentation-style: k&r + * c-basic-offset: 8 + * indent-tabs-mode: t + * End: + */ +// vim: set noet ts=4 sts=4 sw=4: + diff --git a/kopete/protocols/sms/services/smssend.h b/kopete/protocols/sms/services/smssend.h new file mode 100644 index 00000000..556a21ea --- /dev/null +++ b/kopete/protocols/sms/services/smssend.h @@ -0,0 +1,66 @@ +/* ************************************************************************* + * copyright: (C) 2003 Richard Lrkng * + * copyright: (C) 2003 Gav Wood * + ************************************************************************* +*/ + +/* ************************************************************************* + * * + * 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) any later version. * + * * + ************************************************************************* +*/ + +#ifndef SMSSEND_H +#define SMSSEND_H + +#include +#include +#include + +#include + +#include "smsservice.h" + +class SMSSendProvider; +class SMSSendPrefsUI; +class QListViewItem; +class QGridLayout; + +class SMSSend : public SMSService +{ + Q_OBJECT +public: + SMSSend(Kopete::Account* account); + ~SMSSend(); + + virtual void setAccount(Kopete::Account* account); + + void send(const Kopete::Message& msg); + void setWidgetContainer(QWidget* parent, QGridLayout* container); + + int maxSize(); + const QString& description(); + +public slots: + void savePreferences(); + +private slots: + void setOptions(const QString& name); + void loadProviders(const QString& prefix); +//signals: +// void messageSent(const Kopete::Message&); + +private: + QGridLayout *settingsBoxLayout; + SMSSendProvider* m_provider; + SMSSendPrefsUI* prefWidget; + QPtrList args; + QPtrList labels; + QString m_description; +} ; + +#endif //SMSSEND_H diff --git a/kopete/protocols/sms/services/smssendprefs.ui b/kopete/protocols/sms/services/smssendprefs.ui new file mode 100644 index 00000000..faf3a306 --- /dev/null +++ b/kopete/protocols/sms/services/smssendprefs.ui @@ -0,0 +1,188 @@ + +SMSSendPrefsUI + + + SMSSendPrefsUI + + + + 0 + 0 + 338 + 195 + + + + + unnamed + + + 0 + + + + spacer14 + + + Horizontal + + + Expanding + + + + 311 + 16 + + + + + + textLabel7_2 + + + + 1 + + + + SMSSend Options + + + + + line6_2 + + + HLine + + + Sunken + + + Horizontal + + + + + layout12 + + + + unnamed + + + + provider + + + + + program + + + + 7 + 4 + 0 + 0 + + + + + + textLabel2 + + + + 5 + 4 + 0 + 0 + + + + Pro&vider: + + + provider + + + + + textLabel1 + + + + 5 + 4 + 0 + 0 + + + + SMSSend prefi&x: + + + program + + + + + + + spacer15 + + + Horizontal + + + Expanding + + + + 351 + 16 + + + + + + providerLabel + + + + 1 + + + + Provider Options + + + + + line6 + + + HLine + + + Sunken + + + Horizontal + + + + + + program + provider + + + + kurlrequester.h + klineedit.h + kpushbutton.h + + diff --git a/kopete/protocols/sms/services/smssendprovider.cpp b/kopete/protocols/sms/services/smssendprovider.cpp new file mode 100644 index 00000000..82827aab --- /dev/null +++ b/kopete/protocols/sms/services/smssendprovider.cpp @@ -0,0 +1,288 @@ +/* ************************************************************************* + * copyright: (C) 2003 Richard Lrkng * + * copyright: (C) 2003 Gav Wood * + ************************************************************************* +*/ + +/* ************************************************************************* + * * + * 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) any later version. * + * * + ************************************************************************* +*/ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "kopeteaccount.h" +#include "kopeteuiglobal.h" + +#include "smssendprovider.h" +#include "smsprotocol.h" +#include "smscontact.h" + +SMSSendProvider::SMSSendProvider(const QString& providerName, const QString& prefixValue, Kopete::Account* account, QObject* parent, const char *name) + : QObject( parent, name ), m_account(account) +{ + kdWarning( 14160 ) << k_funcinfo << "this = " << this << ", m_account = " << m_account << " (should be ok if zero!!)" << endl; + + provider = providerName; + prefix = prefixValue; + m_maxSize = 160; + + messagePos = -1; + telPos = -1; + + QString file = prefix + "/share/smssend/" + provider + ".sms"; + QFile f(file); + if (f.open(IO_ReadOnly)) + { + QTextStream t(&f); + QString group = QString("SMSSend-%1").arg(provider); + bool exactNumberMatch = false; + QStringList numberWords; + numberWords.append("Tel"); + numberWords.append("Number"); + numberWords.append("number"); + numberWords.append("TelNum"); + numberWords.append("Recipient"); + numberWords.append("Tel1"); + numberWords.append("To"); + numberWords.append("nummer"); + numberWords.append("telefone"); + numberWords.append("ToPhone"); + + while( !t.eof()) + { + QString s = t.readLine(); + if( s[0] == '%') + { + QStringList args = QStringList::split(':',s); + QStringList options = QStringList::split(' ', args[0]); + + names.append(options[0].replace(0,1,"")); + + bool hidden = false; + for(unsigned i = 1; i < options.count(); i++) + if(options[i] == "Hidden") + { hidden = true; + break; + } + isHiddens.append(hidden); + + // Strip trailing whitespace in the end + // and '%' in the beginning + args[0] = args[0].simplifyWhiteSpace().mid(1); + + descriptions.append(args[1]); + if (m_account) + values.append(m_account->configGroup()->readEntry(QString("%1:%2").arg(group).arg(names[names.count()-1]), + QString::null)); + else + values.append(""); + + if( args[0].contains("Message") || args[0].contains("message") + || args[0].contains("message") || args[0].contains("nachricht") + || args[0].contains("Msg") || args[0].contains("Mensagem") ) + { + for( unsigned i = 0; i < options.count(); i++) + { + if (options[i].contains("Size=")) + { + QString option = options[i]; + option.replace(0,5,""); + m_maxSize = option.toInt(); + } + } + messagePos = names.count()-1; + } + else if (!exactNumberMatch) + { + for (QStringList::Iterator it=numberWords.begin(); it != numberWords.end(); ++it) + { + if (args[0].contains(*it)) + { + telPos = names.count() - 1; + if (args[0] == *it) + { +// kdDebug(14160) << "Exact match for " << args[0] << endl; + exactNumberMatch = true; + } +// kdDebug(14160) << "args[0] (" << args[0] << ") contains " << *it << endl; + } + } + } + } + } + } + f.close(); + + if ( messagePos == -1 || telPos == -1 ) + { + canSend = false; + return; + } + + canSend = true; +} + +SMSSendProvider::~SMSSendProvider() +{ + kdWarning( 14160 ) << k_funcinfo << "this = " << this << endl; +} + +void SMSSendProvider::setAccount(Kopete::Account *account) +{ + m_account = account; +} + +const QString& SMSSendProvider::name(int i) +{ + if ( telPos == i || messagePos == i) + return QString::null; + else + return names[i]; +} + +const QString& SMSSendProvider::value(int i) +{ + return values[i]; +} + +const QString& SMSSendProvider::description(int i) +{ + return descriptions[i]; +} + +const bool SMSSendProvider::isHidden(int i) +{ + return isHiddens[i]; +} + +void SMSSendProvider::save(QPtrList& args) +{ + kdDebug( 14160 ) << k_funcinfo << "m_account = " << m_account << " (should be non-zero!!)" << endl; + if (!m_account) return; // prevent crash in worst case + + QString group = QString("SMSSend-%1").arg(provider); + int namesI=0; + + for (unsigned i=0; i < args.count(); i++) + { + if (telPos == namesI || messagePos == namesI) + { +// kdDebug(14160) << k_funcinfo << "Skipping pos " << namesI << endl; + namesI++; + if (telPos == namesI || messagePos == namesI) + { +// kdDebug(14160) << k_funcinfo << "Skipping pos " << namesI << endl; + namesI++; + } + } + +// kdDebug(14160) << k_funcinfo << "saving " << args.at(i) << " to " << names[namesI] << endl; + if (!args.at(i)->text().isEmpty()) + { values[namesI] = args.at(i)->text(); + m_account->configGroup()->writeEntry(QString("%1:%2").arg(group).arg(names[namesI]), values[namesI]); + } + namesI++; + } +} + +int SMSSendProvider::count() +{ + return names.count(); +} + +void SMSSendProvider::send(const Kopete::Message& msg) +{ + if ( canSend == false ) + { + if ( messagePos == -1 ) + { + canSend = false; + KMessageBox::error(Kopete::UI::Global::mainWidget(), i18n("Could not determine which argument which should contain the message."), + i18n("Could Not Send Message")); + return; + } + if ( telPos == -1 ) + { + canSend = false; + + KMessageBox::error(Kopete::UI::Global::mainWidget(), i18n("Could not determine which argument which should contain the number."), + i18n("Could Not Send Message")); + return; + } + } + + m_msg = msg; + + QString message = msg.plainBody(); + QString nr = dynamic_cast(msg.to().first())->qualifiedNumber(); + + if (canSend = false) + return; + + values[messagePos] = message; + values[telPos] = nr; + + KProcess* p = new KProcess; + + kdWarning( 14160 ) << "Executing " << QString("%1/bin/smssend").arg(prefix) << " \"" << provider << "\" " << values.join("\" \"") << "\"" << endl; + + *p << QString("%1/bin/smssend").arg(prefix) << provider << values; + + output = ""; + connect( p, SIGNAL(processExited(KProcess *)), this, SLOT(slotSendFinished(KProcess *))); + connect( p, SIGNAL(receivedStdout(KProcess *, char *, int)), this, SLOT(slotReceivedOutput(KProcess *, char *, int))); +// connect( p, SIGNAL(receivedStderr(KProcess *, char *, int)), this, SLOT(slotReceivedOutput(KProcess *, char *, int))); + + p->start(KProcess::NotifyOnExit, KProcess::AllOutput); +} + +void SMSSendProvider::slotSendFinished(KProcess *p) +{ + kdWarning( 14160 ) << k_funcinfo << "this = " << this << ", es = " << p->exitStatus() << ", p = " << p << " (should be non-zero!!)" << endl; + if (p->exitStatus() == 0) + emit messageSent(m_msg); + else + emit messageNotSent(m_msg, QString().setLatin1(output)); + + p->deleteLater(); +} + +void SMSSendProvider::slotReceivedOutput(KProcess *, char *buffer, int buflen) +{ +// QStringList lines = QStringList::split("\n", QString::fromLocal8Bit(buffer, buflen)); +// for (QStringList::Iterator it = lines.begin(); it != lines.end(); ++it) + for(int i = 0; i < buflen; i++) + output += buffer[i]; + kdWarning( 14160 ) << k_funcinfo << " output now = " << output << endl; +} + +int SMSSendProvider::maxSize() +{ + return m_maxSize; +} + +#include "smssendprovider.moc" +/* + * Local variables: + * c-indentation-style: k&r + * c-basic-offset: 8 + * indent-tabs-mode: t + * End: + */ +// vim: set noet ts=4 sts=4 sw=4: + diff --git a/kopete/protocols/sms/services/smssendprovider.h b/kopete/protocols/sms/services/smssendprovider.h new file mode 100644 index 00000000..8560be15 --- /dev/null +++ b/kopete/protocols/sms/services/smssendprovider.h @@ -0,0 +1,82 @@ +/* ************************************************************************* + * copyright: (C) 2003 Richard Lrkng * + * copyright: (C) 2003 Gav Wood * + ************************************************************************* +*/ + +/* ************************************************************************* + * * + * 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) any later version. * + * * + ************************************************************************* +*/ + +#ifndef SMSSENDPROVIDER_H +#define SMSSENDPROVIDER_H + +#include +#include +#include +#include +#include + +#include + +#include "kopetemessage.h" + +#include "smsaccount.h" + +class KProcess; +namespace Kopete { class Account; } +class SMSContact; + +class SMSSendProvider : public QObject +{ + Q_OBJECT +public: + SMSSendProvider(const QString& providerName, const QString& prefixValue, Kopete::Account* account, QObject* parent = 0, const char* name = 0); + ~SMSSendProvider(); + + void setAccount(Kopete::Account *account); + + int count(); + const QString& name(int i); + const QString& value(int i); + const QString& description(int i); + const bool isHidden(int i); + + void save(QPtrList& args); + void send(const Kopete::Message& msg); + + int maxSize(); +private slots: + void slotReceivedOutput(KProcess*, char *buffer, int buflen); + void slotSendFinished(KProcess*); +private: + QStringList names; + QStringList descriptions; + QStringList values; + QValueList isHiddens; + + int messagePos; + int telPos; + int m_maxSize; + + QString provider; + QString prefix; + QCString output; + + Kopete::Account* m_account; + + Kopete::Message m_msg; + + bool canSend; +signals: + void messageSent(const Kopete::Message& msg); + void messageNotSent(const Kopete::Message& msg, const QString &error); +} ; + +#endif //SMSSENDPROVIDER_H diff --git a/kopete/protocols/sms/smsaccount.cpp b/kopete/protocols/sms/smsaccount.cpp new file mode 100644 index 00000000..5a13dca2 --- /dev/null +++ b/kopete/protocols/sms/smsaccount.cpp @@ -0,0 +1,202 @@ +/* ************************************************************************* + * copyright: (C) 2003 Richard L�k�g * + * copyright: (C) 2003 Gav Wood * + ************************************************************************* +*/ + +/* ************************************************************************* + * * + * 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) any later version. * + * * + ************************************************************************* +*/ + +#undef KDE_NO_COMPAT + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "kopeteuiglobal.h" + +#include "serviceloader.h" + +#include "smsaccount.h" +#include "smsprotocol.h" +#include "smscontact.h" + +SMSAccount::SMSAccount( SMSProtocol *parent, const QString &accountID, const char *name ) + : Kopete::Account( parent, accountID, name ) +{ + setMyself( new SMSContact(this, accountID, accountID, Kopete::ContactList::self()->myself()) ); + loadConfig(); + myself()->setOnlineStatus( SMSProtocol::protocol()->SMSOffline ); + + QString sName = configGroup()->readEntry("ServiceName", QString::null); + theService = ServiceLoader::loadService(sName, this); + + if( theService ) + { + QObject::connect (theService, SIGNAL(messageSent(const Kopete::Message &)), + this, SLOT(slotSendingSuccess(const Kopete::Message &))); + QObject::connect (theService, SIGNAL(messageNotSent(const Kopete::Message &, const QString &)), + this, SLOT(slotSendingFailure(const Kopete::Message &, const QString &))); + QObject::connect (theService, SIGNAL(connected()), this, SLOT(slotConnected())); + QObject::connect (theService, SIGNAL(disconnected()), this, SLOT(slotDisconnected())); + } + +} + +SMSAccount::~SMSAccount() +{ + delete theService; + theService = NULL; +} + +void SMSAccount::loadConfig() +{ + theSubEnable = configGroup()->readBoolEntry("SubEnable", false); + theSubCode = configGroup()->readEntry("SubCode", QString::null); + theLongMsgAction = (SMSMsgAction)configGroup()->readNumEntry("MsgAction", 0); +} + +void SMSAccount::translateNumber(QString &theNumber) +{ + if(theNumber[0] == QChar('0') && theSubEnable) + theNumber.replace(0, 1, theSubCode); +} + +const bool SMSAccount::splitNowMsgTooLong(int msgLength) +{ + if( theService == NULL ) + return false; + + int max = theService->maxSize(); + if(theLongMsgAction == ACT_CANCEL) return false; + if(theLongMsgAction == ACT_SPLIT) return true; + if(KMessageBox::questionYesNo(Kopete::UI::Global::mainWidget(), i18n("This message is longer than the maximum length (%1). Should it be divided to %2 messages?").arg(max).arg(msgLength / max + 1), + i18n("Message Too Long"), i18n("Divide"), i18n("Do Not Divide")) == KMessageBox::Yes) + return true; + else + return false; +} + +void SMSAccount::setAway( bool /*away*/, const QString &) +{ +} + +void SMSAccount::connect(const Kopete::OnlineStatus&) +{ + myself()->setOnlineStatus( SMSProtocol::protocol()->SMSConnecting ); + if( theService ) + theService->connect(); +} + +void SMSAccount::slotConnected() +{ + myself()->setOnlineStatus( SMSProtocol::protocol()->SMSOnline ); + setAllContactsStatus( SMSProtocol::protocol()->SMSOnline ); +} + +void SMSAccount::disconnect() +{ + if( theService ) + theService->disconnect(); +} + +void SMSAccount::slotDisconnected() +{ + myself()->setOnlineStatus( SMSProtocol::protocol()->SMSOffline ); + setAllContactsStatus( SMSProtocol::protocol()->SMSOffline ); +} + +void SMSAccount::slotSendMessage(Kopete::Message &msg) +{ + kdWarning( 14160 ) << k_funcinfo << " this = " << this << endl; + + if(theService == 0L) + return; + + int msgLength = msg.plainBody().length(); + + if( theService->maxSize() == -1 ) + { + theService->send(msg); + } + else if( theService->maxSize() < msgLength ) + { + if( splitNowMsgTooLong(msgLength) ) + { + for (int i=0; i < msgLength / theService->maxSize() + 1; i++) + { + QString text = msg.plainBody(); + text = text.mid( theService->maxSize() * i, theService->maxSize() ); + Kopete::Message m( msg.from(), msg.to(), text, Kopete::Message::Outbound); + + theService->send(m); + } + } + else + slotSendingFailure(msg, i18n("Message too long.")); + } + else + { + theService->send(msg); + } + +} + +void SMSAccount::slotSendingSuccess(const Kopete::Message &msg) +{ + SMSContact* c = dynamic_cast(msg.to().first()); + if( c ) + c->slotSendingSuccess(msg); +} + +void SMSAccount::slotSendingFailure(const Kopete::Message &msg, const QString &error) +{ + SMSContact* c = dynamic_cast(msg.to().first()); + if( c ) + c->slotSendingFailure(msg, error); +} + +bool SMSAccount::createContact( const QString &contactId, + Kopete::MetaContact * parentContact ) +{ + if (new SMSContact(this, contactId, parentContact->displayName(), parentContact)) + return true; + else + return false; +} + +KActionMenu* SMSAccount::actionMenu() +{ + KActionMenu *theActionMenu = Kopete::Account::actionMenu(); + return theActionMenu; +} + +void SMSAccount::setOnlineStatus( const Kopete::OnlineStatus & status , const QString &reason) +{ + if ( myself()->onlineStatus().status() == Kopete::OnlineStatus::Offline && status.status() == Kopete::OnlineStatus::Online ) + connect(); + else if ( myself()->onlineStatus().status() != Kopete::OnlineStatus::Offline && status.status() == Kopete::OnlineStatus::Offline ) + disconnect(); + else if ( myself()->onlineStatus().status() != Kopete::OnlineStatus::Offline && status.status() == Kopete::OnlineStatus::Away ) + setAway( true, reason ); +} + +SMSService* SMSAccount::service() +{ + return theService; +} + +#include "smsaccount.moc" diff --git a/kopete/protocols/sms/smsaccount.h b/kopete/protocols/sms/smsaccount.h new file mode 100644 index 00000000..2547fe6c --- /dev/null +++ b/kopete/protocols/sms/smsaccount.h @@ -0,0 +1,79 @@ +/* ************************************************************************* + * copyright: (C) 2003 Richard Lrkng * + * copyright: (C) 2003 Gav Wood * + ************************************************************************* +*/ + +/* ************************************************************************* + * * + * 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) any later version. * + * * + ************************************************************************* +*/ + +#ifndef SMSACCOUNT_H +#define SMSACCOUNT_H + +#include "kopeteaccount.h" + +class KActionMenu; +class SMSProtocol; +class SMSContact; +class SMSService; +class KProcess; + +enum SMSMsgAction { ACT_ASK = 0, ACT_CANCEL, ACT_SPLIT }; + +class SMSAccount : public Kopete::Account +{ + Q_OBJECT + +public: + SMSAccount( SMSProtocol *parent, const QString &accountID, const char *name = 0L ); + ~SMSAccount(); + + virtual KActionMenu* actionMenu(); // Per-protocol actions for the systray and the status bar + + virtual void setAway( bool away, const QString & ); + + void translateNumber(QString &theNumber); + + /** + * Checks to see if the message should be split or not, in case it is too long. + * + * Only ever call in case of message being too long - may result in user interaction. + */ + const bool splitNowMsgTooLong(int msgLength); + + SMSService* service(); + +public slots: + void loadConfig(); + void setOnlineStatus( const Kopete::OnlineStatus& status , const QString &reason = QString::null); + +public slots: + virtual void connect(const Kopete::OnlineStatus& initial= Kopete::OnlineStatus()); + virtual void disconnect(); + virtual void slotSendMessage(Kopete::Message &msg); + +protected slots: + virtual void slotSendingSuccess(const Kopete::Message &msg); + virtual void slotSendingFailure(const Kopete::Message &msg, const QString &error); + virtual void slotConnected(); + virtual void slotDisconnected(); + + +protected: + bool createContact(const QString &contactId, Kopete::MetaContact *parentContact); + +private: + bool theSubEnable; + QString theSubCode; + SMSMsgAction theLongMsgAction; + SMSService* theService; +}; + +#endif diff --git a/kopete/protocols/sms/smsaddcontactpage.cpp b/kopete/protocols/sms/smsaddcontactpage.cpp new file mode 100644 index 00000000..55921b49 --- /dev/null +++ b/kopete/protocols/sms/smsaddcontactpage.cpp @@ -0,0 +1,65 @@ +/* ************************************************************************* + * copyright: (C) 2003 Richard Lrkng * + ************************************************************************* +*/ + +/* ************************************************************************* + * * + * 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) any later version. * + * * + ************************************************************************* +*/ + +#include "smsadd.h" +#include "smsaddcontactpage.h" +#include "kopeteaccount.h" + +#include +#include + + + +SMSAddContactPage::SMSAddContactPage(QWidget *parent, const char *name ) + : AddContactPage(parent,name) +{ + (new QVBoxLayout(this))->setAutoAdd(true); + smsdata = new smsAddUI(this); +} + +SMSAddContactPage::~SMSAddContactPage() +{ + +} + +bool SMSAddContactPage::apply(Kopete::Account* a, Kopete::MetaContact* m) +{ + if ( validateData() ) + { + QString nr = smsdata->addNr->text(); + QString name = smsdata->addName->text(); + + return a->addContact( nr, m, Kopete::Account::ChangeKABC ); + } + + return false; +} + + +bool SMSAddContactPage::validateData() +{ + return true; +} + +#include "smsaddcontactpage.moc" +/* + * Local variables: + * c-indentation-style: k&r + * c-basic-offset: 8 + * indent-tabs-mode: t + * End: + */ +// vim: set noet ts=4 sts=4 sw=4: + diff --git a/kopete/protocols/sms/smsaddcontactpage.h b/kopete/protocols/sms/smsaddcontactpage.h new file mode 100644 index 00000000..37843bc9 --- /dev/null +++ b/kopete/protocols/sms/smsaddcontactpage.h @@ -0,0 +1,50 @@ +/* ************************************************************************* + * copyright: (C) 2003 Richard Lrkng * + ************************************************************************* +*/ + +/* ************************************************************************* + * * + * 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) any later version. * + * * + ************************************************************************* +*/ + +#ifndef SMSADDCONTACTPAGE_H +#define SMSADDCONTACTPAGE_H + +#include +#include +#include + +class smsAddUI; +class SMSProtocol; + +class SMSAddContactPage : public AddContactPage +{ + Q_OBJECT +public: + SMSAddContactPage(QWidget *parent=0, const char *name=0); + ~SMSAddContactPage(); + smsAddUI *smsdata; + virtual bool validateData(); + virtual bool apply( Kopete::Account*, Kopete::MetaContact* ); +}; + + +#endif + + + +/* + * Local variables: + * c-indentation-style: k&r + * c-basic-offset: 8 + * indent-tabs-mode: t + * End: + */ +// vim: set noet ts=4 sts=4 sw=4: + diff --git a/kopete/protocols/sms/smscontact.cpp b/kopete/protocols/sms/smscontact.cpp new file mode 100644 index 00000000..d220b380 --- /dev/null +++ b/kopete/protocols/sms/smscontact.cpp @@ -0,0 +1,142 @@ +/* ************************************************************************* + * copyright: (C) 2003 Richard Lrkng * + * copyright: (C) 2003 Gav Wood * + ************************************************************************* +*/ + +/* ************************************************************************* + * * + * 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) any later version. * + * * + ************************************************************************* +*/ + +#undef KDE_NO_COMPAT +#include +#include +#include +#include +#include + +#include "kopetechatsessionmanager.h" +#include "kopeteaccount.h" +#include "kopeteuiglobal.h" + +#include "smscontact.h" +#include "smsprotocol.h" +#include "smsservice.h" +#include "smsaccount.h" +#include "smsuserpreferences.h" + +SMSContact::SMSContact( Kopete::Account* _account, const QString &phoneNumber, + const QString &displayName, Kopete::MetaContact *parent ) +: Kopete::Contact( _account, phoneNumber, parent ), m_phoneNumber( phoneNumber ) +{ +// kdWarning( 14160 ) << k_funcinfo << " this = " << this << ", phone = " << phoneNumber << endl; + setNickName( displayName ); + + m_msgManager = 0L; + m_actionPrefs = 0L; + + if( account()->isConnected() ) + setOnlineStatus( SMSProtocol::protocol()->SMSOnline ); +} + +void SMSContact::slotSendingSuccess(const Kopete::Message &msg) +{ + manager(Kopete::Contact::CanCreate)->messageSucceeded(); + manager(Kopete::Contact::CanCreate)->appendMessage((Kopete::Message &)msg); +} + +void SMSContact::slotSendingFailure(const Kopete::Message &/*msg*/, const QString &error) +{ + KMessageBox::detailedError(Kopete::UI::Global::mainWidget(), i18n("Something went wrong when sending message."), error, + i18n("Could Not Send Message")); +// manager()->messageFailed(); + // TODO: swap for failed as above. show it anyway for now to allow closing of window. + manager(Kopete::Contact::CanCreate)->messageSucceeded(); +} + +void SMSContact::serialize( QMap &serializedData, + QMap & /* addressBookData */ ) +{ + // Contact id and display name are already set for us + if (m_phoneNumber != contactId()) + serializedData[ "contactId" ] = m_phoneNumber; +} + +Kopete::ChatSession* SMSContact::manager( Kopete::Contact::CanCreateFlags canCreate ) +{ + if ( m_msgManager || canCreate != Kopete::Contact::CanCreate ) + { + return m_msgManager; + } + else + { + QPtrList contacts; + contacts.append(this); + m_msgManager = Kopete::ChatSessionManager::self()->create(account()->myself(), contacts, protocol()); + connect(m_msgManager, SIGNAL(messageSent(Kopete::Message&, Kopete::ChatSession*)), + account(), SLOT(slotSendMessage(Kopete::Message&))); + connect(m_msgManager, SIGNAL(destroyed()), this, SLOT(slotChatSessionDestroyed())); + return m_msgManager; + } +} + +void SMSContact::slotChatSessionDestroyed() +{ + m_msgManager = 0L; +} + + +void SMSContact::slotUserInfo() +{ +} + +void SMSContact::deleteContact() +{ + deleteLater(); +} + +const QString SMSContact::qualifiedNumber() +{ + QString number = m_phoneNumber; + dynamic_cast(account())->translateNumber(number); + return number; +} + +const QString &SMSContact::phoneNumber() +{ + return m_phoneNumber; +} + +void SMSContact::setPhoneNumber( const QString phoneNumber ) +{ + deleteLater(); + new SMSContact(account(), phoneNumber, nickName(), metaContact()); +} + +QPtrList* SMSContact::customContextMenuActions() +{ + QPtrList *m_actionCollection = new QPtrList(); + if( !m_actionPrefs ) + m_actionPrefs = new KAction(i18n("&Contact Settings"), 0, this, SLOT(userPrefs()), this, "userPrefs"); + + m_actionCollection->append( m_actionPrefs ); + + return m_actionCollection; +} + +void SMSContact::userPrefs() +{ + SMSUserPreferences* p = new SMSUserPreferences( this ); + p->show(); +} + +#include "smscontact.moc" + +// vim: set noet ts=4 sts=4 sw=4: + diff --git a/kopete/protocols/sms/smscontact.h b/kopete/protocols/sms/smscontact.h new file mode 100644 index 00000000..b47d2bd9 --- /dev/null +++ b/kopete/protocols/sms/smscontact.h @@ -0,0 +1,74 @@ +/* ************************************************************************* + * copyright: (C) 2003 Richard Lrkng * + * copyright: (C) 2003 Gav Wood * + ************************************************************************* +*/ + +/* ************************************************************************* + * * + * 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) any later version. * + * * + ************************************************************************* +*/ + +#ifndef SMSCONTACT_H +#define SMSCONTACT_H + +#include "kopetecontact.h" +#include "kopetemessage.h" + +#include + +class SMSAccount; +namespace Kopete { class ChatSession; } +namespace Kopete { class MetaContact; } + +class KActionCollection; +class KAction; + +class SMSContact : public Kopete::Contact +{ + Q_OBJECT +public: + SMSContact( Kopete::Account* _account, const QString &phoneNumber, + const QString &displayName, Kopete::MetaContact *parent ); + + QPtrList* customContextMenuActions(); + + const QString &phoneNumber(); + void setPhoneNumber( const QString phoneNumber ); + const QString qualifiedNumber(); + + /** + * Serialize contact + */ + virtual void serialize( QMap &serializedData, + QMap &addressBookData ); + + Kopete::ChatSession* manager( Kopete::Contact::CanCreateFlags canCreate = Kopete::Contact::CanCreate ); + +public slots: + virtual void slotUserInfo(); + virtual void deleteContact(); + void slotSendingSuccess(const Kopete::Message &msg); + void slotSendingFailure(const Kopete::Message &msg, const QString &error); + +private slots: + void userPrefs(); + void slotChatSessionDestroyed(); + +private: + KAction* m_actionPrefs; + + QString m_phoneNumber; + + Kopete::ChatSession* m_msgManager; +}; + +#endif + +// vim: set noet ts=4 sts=4 sw=4: + diff --git a/kopete/protocols/sms/smseditaccountwidget.cpp b/kopete/protocols/sms/smseditaccountwidget.cpp new file mode 100644 index 00000000..b74c24f4 --- /dev/null +++ b/kopete/protocols/sms/smseditaccountwidget.cpp @@ -0,0 +1,147 @@ +/* ************************************************************************* + * copyright: (C) 2003 Richard Lrkng * + * copyright: (C) 2003 Gav Wood * + ************************************************************************* +*/ + +/* ************************************************************************* + * * + * 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) any later version. * + * * + ************************************************************************* +*/ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "kopeteuiglobal.h" + +#include "smseditaccountwidget.h" +#include "smsactprefs.h" +#include "serviceloader.h" +#include "smsprotocol.h" +#include "smsaccount.h" + +SMSEditAccountWidget::SMSEditAccountWidget(SMSProtocol *protocol, Kopete::Account *account, QWidget *parent, const char */*name*/) + : QWidget(parent), KopeteEditAccountWidget(account) +{ + QVBoxLayout *l = new QVBoxLayout(this, QBoxLayout::Down); + preferencesDialog = new smsActPrefsUI(this); + l->addWidget(preferencesDialog); + + service = 0L; + configWidget = 0L; + middleFrameLayout = 0L; + + m_protocol = protocol; + + QString sName; + if (account) + { + preferencesDialog->accountId->setText(account->accountId()); + //Disable changing the account ID for now + //FIXME: Remove this when we can safely change the account ID (Matt) + preferencesDialog->accountId->setDisabled(true); + sName = account->configGroup()->readEntry("ServiceName", QString::null); + preferencesDialog->subEnable->setChecked(account->configGroup()->readBoolEntry("SubEnable", false)); + preferencesDialog->subCode->setText(account->configGroup()->readEntry("SubCode", QString::null)); + preferencesDialog->ifMessageTooLong->setCurrentItem(SMSMsgAction(account->configGroup()->readNumEntry("MsgAction", 0))); + } + + preferencesDialog->serviceName->insertStringList(ServiceLoader::services()); + + connect (preferencesDialog->serviceName, SIGNAL(activated(const QString &)), + this, SLOT(setServicePreferences(const QString &))); + connect (preferencesDialog->descButton, SIGNAL(clicked()), + this, SLOT(showDescription())); + + + for (int i=0; i < preferencesDialog->serviceName->count(); i++) + { + if (preferencesDialog->serviceName->text(i) == sName) + { + preferencesDialog->serviceName->setCurrentItem(i); + break; + } + } + setServicePreferences(preferencesDialog->serviceName->currentText()); +} + +SMSEditAccountWidget::~SMSEditAccountWidget() +{ + delete service; +} + +bool SMSEditAccountWidget::validateData() +{ + return true; +} + +Kopete::Account* SMSEditAccountWidget::apply() +{ + if (!account()) + setAccount( new SMSAccount( m_protocol, preferencesDialog->accountId->text() ) ); + + if (service) + service->setAccount(account()); + + KConfigGroup *c = account()->configGroup(); + c->writeEntry("ServiceName", preferencesDialog->serviceName->currentText()); + c->writeEntry("SubEnable", preferencesDialog->subEnable->isChecked() ? "true" : "false"); + c->writeEntry("SubCode", preferencesDialog->subCode->text()); + c->writeEntry("MsgAction", preferencesDialog->ifMessageTooLong->currentItem()); + + emit saved(); + return account(); +} + +void SMSEditAccountWidget::setServicePreferences(const QString& serviceName) +{ + delete service; + delete configWidget; + + service = ServiceLoader::loadService(serviceName, account()); + + if (service == 0L) + return; + + connect (this, SIGNAL(saved()), service, SLOT(savePreferences())); + + delete middleFrameLayout; + middleFrameLayout = new QGridLayout(preferencesDialog->middleFrame, 1, 2, 0, 6, "middleFrameLayout"); + service->setWidgetContainer(preferencesDialog->middleFrame, middleFrameLayout); +} + +void SMSEditAccountWidget::showDescription() +{ + SMSService* s = ServiceLoader::loadService(preferencesDialog->serviceName->currentText(), 0L); + + QString d = s->description(); + + KMessageBox::information(Kopete::UI::Global::mainWidget(), d, i18n("Description")); +} + +#include "smseditaccountwidget.moc" + +/* + * Local variables: + * c-indentation-style: k&r + * c-basic-offset: 8 + * indent-tabs-mode: t + * End: + */ +// vim: set noet ts=4 sts=4 sw=4: + diff --git a/kopete/protocols/sms/smseditaccountwidget.h b/kopete/protocols/sms/smseditaccountwidget.h new file mode 100644 index 00000000..eaf83d42 --- /dev/null +++ b/kopete/protocols/sms/smseditaccountwidget.h @@ -0,0 +1,64 @@ +/* ************************************************************************* + * copyright: (C) 2003 Richard Lrkng * + * copyright: (C) 2003 Gav Wood * + ************************************************************************* +*/ + +/* ************************************************************************* + * * + * 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) any later version. * + * * + ************************************************************************* +*/ + +#ifndef SMSEDITACCOUNTWIDGET_H +#define SMSEDITACCOUNTWIDGET_H + +#include +#include "editaccountwidget.h" + +class SMSProtocol; +class SMSService; +class smsActPrefsUI; +namespace Kopete { class Account; } +class QGridLayout; + +class SMSEditAccountWidget : public QWidget, public KopeteEditAccountWidget +{ + Q_OBJECT +public: + SMSEditAccountWidget(SMSProtocol *protocol, Kopete::Account *theAccount, QWidget *parent = 0, const char *name = 0); + ~SMSEditAccountWidget(); + + bool validateData(); + Kopete::Account* apply(); +public slots: + void setServicePreferences(const QString& serviceName); + void showDescription(); +protected: + smsActPrefsUI *preferencesDialog; + QWidget *configWidget; + SMSService *service; + SMSProtocol *m_protocol; + QGridLayout *middleFrameLayout; + +signals: + void saved(); +}; + +#endif + + + +/* + * Local variables: + * c-indentation-style: k&r + * c-basic-offset: 8 + * indent-tabs-mode: t + * End: + */ +// vim: set noet ts=4 sts=4 sw=4: + diff --git a/kopete/protocols/sms/smsprotocol.cpp b/kopete/protocols/sms/smsprotocol.cpp new file mode 100644 index 00000000..6b6cd838 --- /dev/null +++ b/kopete/protocols/sms/smsprotocol.cpp @@ -0,0 +1,97 @@ +/* ************************************************************************* + * copyright: (C) 2003 Richard Lrkng * + * copyright: (C) 2003 Gav Wood * + ************************************************************************* +*/ + +/* ************************************************************************* + * * + * 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) any later version. * + * * + ************************************************************************* +*/ + +#include +#include +#include +#include + +#include "kopeteaccountmanager.h" +#include "kopeteonlinestatusmanager.h" +#include "smsprotocol.h" +#include "smseditaccountwidget.h" +#include "smscontact.h" +#include "smsaddcontactpage.h" +#include "smsaccount.h" + +typedef KGenericFactory SMSProtocolFactory; +K_EXPORT_COMPONENT_FACTORY( kopete_sms, SMSProtocolFactory( "kopete_sms" ) ) + +SMSProtocol* SMSProtocol::s_protocol = 0L; + +SMSProtocol::SMSProtocol(QObject *parent, const char *name, const QStringList &/*args*/) +: Kopete::Protocol( SMSProtocolFactory::instance(), parent, name ), + SMSOnline( Kopete::OnlineStatus::Online, 25, this, 0, QString::null, i18n( "Online" ), i18n( "Online" ), Kopete::OnlineStatusManager::Online ), + SMSConnecting( Kopete::OnlineStatus::Connecting,2, this, 3, QString::null, i18n( "Connecting" ) ), + SMSOffline( Kopete::OnlineStatus::Offline, 0, this, 2, QString::null, i18n( "Offline" ), i18n( "Offline" ), Kopete::OnlineStatusManager::Offline ) +{ + if (s_protocol) + kdWarning( 14160 ) << k_funcinfo << "s_protocol already defined!" << endl; + else + s_protocol = this; + + addAddressBookField("messaging/sms", Kopete::Plugin::MakeIndexField); +} + +SMSProtocol::~SMSProtocol() +{ + s_protocol = 0L; +} + +AddContactPage *SMSProtocol::createAddContactWidget(QWidget *parent, Kopete::Account */*i*/) +{ + return new SMSAddContactPage(parent); +} + +KopeteEditAccountWidget* SMSProtocol::createEditAccountWidget(Kopete::Account *account, QWidget *parent) +{ + return new SMSEditAccountWidget(this, account, parent); +} + +SMSProtocol* SMSProtocol::protocol() +{ + return s_protocol; +} + +Kopete::Contact *SMSProtocol::deserializeContact(Kopete::MetaContact *metaContact, + const QMap &serializedData, + const QMap &/* addressBookData */) +{ + QString contactId = serializedData["contactId"]; + QString accountId = serializedData["accountId"]; + QString displayName = serializedData["displayName"]; + + QDict accounts=Kopete::AccountManager::self()->accounts(this); + + Kopete::Account *account = accounts[accountId]; + if (!account) + { + kdDebug(14160) << "Account doesn't exist, skipping" << endl; + return 0; + } + + return new SMSContact(account, contactId, displayName, metaContact); +} + +Kopete::Account* SMSProtocol::createNewAccount(const QString &accountId) +{ + return new SMSAccount(this, accountId); +} + +#include "smsprotocol.moc" + +// vim: set noet ts=4 sts=4 sw=4: + diff --git a/kopete/protocols/sms/smsprotocol.h b/kopete/protocols/sms/smsprotocol.h new file mode 100644 index 00000000..1d4aaa40 --- /dev/null +++ b/kopete/protocols/sms/smsprotocol.h @@ -0,0 +1,71 @@ +/* ************************************************************************* + * copyright: (C) 2003 Richard Lrkng * + * copyright: (C) 2003 Gav Wood * + ************************************************************************* +*/ + +/* ************************************************************************* + * * + * 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) any later version. * + * * + ************************************************************************* +*/ + +#ifndef SMSPROTOCOL_H +#define SMSPROTOCOL_H + +#include +#include +#include +#include +#include +#include + +#include "kopeteprotocol.h" +#include "kopeteonlinestatus.h" +#include "kopetecontact.h" + +class KAction; +class KActionMenu; + +namespace Kopete { class Contact; } +namespace Kopete { class MetaContact; } +namespace Kopete { class Message; } +namespace Kopete { class ChatSession; } +class SMSContact; + +class SMSProtocol : public Kopete::Protocol +{ + Q_OBJECT + +public: + SMSProtocol(QObject *parent, const char *name, const QStringList &args); + ~SMSProtocol(); + + static SMSProtocol *protocol(); + + /** + * Deserialize contact data + */ + virtual Kopete::Contact *deserializeContact(Kopete::MetaContact *metaContact, + const QMap &serializedData, const QMap &addressBookData ); + + virtual AddContactPage *createAddContactWidget(QWidget *parent , Kopete::Account *i); + virtual KopeteEditAccountWidget *createEditAccountWidget(Kopete::Account *account, QWidget *parent); + virtual Kopete::Account *createNewAccount(const QString &accountId); + + const Kopete::OnlineStatus SMSOnline; + const Kopete::OnlineStatus SMSOffline; + const Kopete::OnlineStatus SMSConnecting; + +private: + static SMSProtocol *s_protocol; +}; + +#endif + +// vim: set noet ts=4 sts=4 sw=4: + diff --git a/kopete/protocols/sms/smsservice.cpp b/kopete/protocols/sms/smsservice.cpp new file mode 100644 index 00000000..81b46533 --- /dev/null +++ b/kopete/protocols/sms/smsservice.cpp @@ -0,0 +1,63 @@ +/* ************************************************************************* + * copyright: (C) 2003 Richard Lrkng * + * copyright: (C) 2003 Gav Wood * + ************************************************************************* +*/ + +/* ************************************************************************* + * * + * 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) any later version. * + * * + ************************************************************************* +*/ + +#include + +#include + +#include "smsservice.h" + +SMSService::SMSService(Kopete::Account* account) + : QObject(), m_account(account) +{ +} + +SMSService::~SMSService() +{ + +} + +void SMSService::setAccount(Kopete::Account* account) +{ + if(!m_account) + m_account = account; + if(account) + savePreferences(); +} + +// The Default impl simply flips a signal back +void SMSService::connect() +{ + emit connected(); +} + +// The Default impl simply flips a signal back +void SMSService::disconnect() +{ + emit disconnected(); +} + +/* + * Local variables: + * c-indentation-style: k&r + * c-basic-offset: 8 + * indent-tabs-mode: t + * End: + */ +// vim: set noet ts=4 sts=4 sw=4: + + +#include "smsservice.moc" diff --git a/kopete/protocols/sms/smsservice.h b/kopete/protocols/sms/smsservice.h new file mode 100644 index 00000000..f1c04470 --- /dev/null +++ b/kopete/protocols/sms/smsservice.h @@ -0,0 +1,83 @@ +/* ************************************************************************* + * copyright: (C) 2003 Richard Lrkng * + * copyright: (C) 2003 Gav Wood * + ************************************************************************* +*/ + +/* ************************************************************************* + * * + * 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) any later version. * + * * + ************************************************************************* +*/ + +#ifndef SMSSERVICE_H +#define SMSSERVICE_H + +#include +#include +#include + +#include "kopetemessage.h" + +class SMSContact; +namespace Kopete { class Account; } +class QGridLayout; +class QWidget; + +class SMSService : public QObject +{ + Q_OBJECT +public: + SMSService(Kopete::Account* account = 0); + virtual ~SMSService(); + + /** + * Reimplement to do extra stuff when the account is dynamically changed + * (other than just changing m_account). + * + * Don't forget to call SMSService::setAccount(...) after you've finished. + */ + virtual void setAccount(Kopete::Account* account); + + /** + * Called when the settings widget has a place to be. @param parent is the + * settings widget's parent and @param layout is the 2xn grid layout it may + * use. + */ + virtual void setWidgetContainer(QWidget* parent, QGridLayout* layout) = 0; + + virtual void send(const Kopete::Message& msg) = 0; + virtual int maxSize() = 0; + virtual const QString& description() = 0; + +public slots: + virtual void savePreferences() = 0; + virtual void connect(); + virtual void disconnect(); + +signals: + void messageSent(const Kopete::Message &); + void messageNotSent(const Kopete::Message &, const QString &); + void connected(); + void disconnected(); + +protected: + Kopete::Account* m_account; + QGridLayout* m_layout; + QWidget* m_parent; +}; + +#endif //SMSSERVICE_H +/* + * Local variables: + * c-indentation-style: k&r + * c-basic-offset: 8 + * indent-tabs-mode: t + * End: + */ +// vim: set noet ts=4 sts=4 sw=4: + diff --git a/kopete/protocols/sms/smsuserpreferences.cpp b/kopete/protocols/sms/smsuserpreferences.cpp new file mode 100644 index 00000000..89677080 --- /dev/null +++ b/kopete/protocols/sms/smsuserpreferences.cpp @@ -0,0 +1,63 @@ +/* ************************************************************************* + * copyright: (C) 2003 Richard Lrkng * + * copyright: (C) 2003 Gav Wood * + ************************************************************************* +*/ + +/* ************************************************************************* + * * + * 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) any later version. * + * * + ************************************************************************* +*/ + +#include + +#include +#include + +#include "smsuserpreferences.h" +#include "smsuserprefs.h" +#include "smscontact.h" + +SMSUserPreferences::SMSUserPreferences( SMSContact* contact ) + : KDialogBase( 0L, "userPrefs", true, i18n("User Preferences"), Ok|Cancel, Ok, true ) +{ + m_contact = contact; + topWidget = makeVBoxMainWidget(); + userPrefs = new SMSUserPrefsUI( topWidget ); + + userPrefs->telNumber->setText(m_contact->phoneNumber()); + userPrefs->title->setText(m_contact->nickName()); +} + +SMSUserPreferences::~SMSUserPreferences() +{ + +} + +void SMSUserPreferences::slotOk() +{ + if (userPrefs->telNumber->text() != m_contact->phoneNumber()) + m_contact->setPhoneNumber(userPrefs->telNumber->text()); + slotCancel(); +} + +void SMSUserPreferences::slotCancel() +{ + deleteLater(); +} + +#include "smsuserpreferences.moc" +/* + * Local variables: + * c-indentation-style: k&r + * c-basic-offset: 8 + * indent-tabs-mode: t + * End: + */ +// vim: set noet ts=4 sts=4 sw=4: + diff --git a/kopete/protocols/sms/smsuserpreferences.h b/kopete/protocols/sms/smsuserpreferences.h new file mode 100644 index 00000000..29fb6dd2 --- /dev/null +++ b/kopete/protocols/sms/smsuserpreferences.h @@ -0,0 +1,44 @@ +/* ************************************************************************* + * copyright: (C) 2003 Richard Lrkng * + * copyright: (C) 2003 Gav Wood * + ************************************************************************* +*/ + +/* ************************************************************************* + * * + * 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) any later version. * + * * + ************************************************************************* +*/ + +#ifndef SMSUSERPREFERENCES_H +#define SMSUSERPREFERENCES_H + +#include +#include + +class SMSPreferencesBase; +class SMSUserPrefsUI; +class SMSContact; + +class SMSUserPreferences : public KDialogBase +{ + Q_OBJECT +public: + SMSUserPreferences(SMSContact* contact); + ~SMSUserPreferences(); +private: + SMSPreferencesBase* prefBase; + SMSUserPrefsUI* userPrefs; + QVBox* topWidget; + + SMSContact* m_contact; +public slots: + void slotOk(); + void slotCancel(); +} ; + +#endif //SMSUSERPREFERENCES_H diff --git a/kopete/protocols/sms/ui/Makefile.am b/kopete/protocols/sms/ui/Makefile.am new file mode 100644 index 00000000..660aa359 --- /dev/null +++ b/kopete/protocols/sms/ui/Makefile.am @@ -0,0 +1,8 @@ +METASOURCES = AUTO +AM_CPPFLAGS = $(KOPETE_INCLUDES) \ + -I$(srcdir)/.. \ + $(all_includes) + +noinst_LTLIBRARIES = libkopetesmsui.la + +libkopetesmsui_la_SOURCES = smsadd.ui smsactprefs.ui smsuserprefs.ui empty.cpp diff --git a/kopete/protocols/sms/ui/empty.cpp b/kopete/protocols/sms/ui/empty.cpp new file mode 100644 index 00000000..e69de29b diff --git a/kopete/protocols/sms/ui/smsactprefs.ui b/kopete/protocols/sms/ui/smsactprefs.ui new file mode 100644 index 00000000..62e53800 --- /dev/null +++ b/kopete/protocols/sms/ui/smsactprefs.ui @@ -0,0 +1,435 @@ + +smsActPrefsUI +Richard Lärkäng + + + smsActPrefsUI + + + + 0 + 0 + 465 + 437 + + + + + 5 + 5 + 0 + 0 + + + + Account Preferences - SMS + + + + unnamed + + + 0 + + + 0 + + + + middleFrame + + + StyledPanel + + + Raised + + + 0 + + + + + tabWidget9 + + + + tab + + + B&asic Setup + + + + unnamed + + + + groupBox61 + + + Account Information + + + + unnamed + + + + textLabel2 + + + &Account name: + + + accountId + + + A unique name for this SMS account. + + + A unique name for this SMS account. + + + + + textLabel1 + + + &SMS delivery service: + + + serviceName + + + The delivery service that you would like to use. + + + The delivery service that you would like to use. Note that you will need to have this software installed prior to using this account. + + + + + accountId + + + A unique name for this SMS account. + + + + + layout35 + + + + unnamed + + + + serviceName + + + + 7 + 5 + 0 + 0 + + + + The delivery service that you would like to use. + + + The delivery service that you would like to use. Note that you will need to have this software installed prior to using this account. + + + + + descButton + + + &Description + + + Description of the SMS delivery service. + + + Description of the SMS delivery service, including download locations. + + + + + + + + + groupBox22 + + + Information + + + + unnamed + + + + textLabel12 + + + + 3 + 1 + 0 + 0 + + + + To use SMS, you will need an account with a delivery service. + + + WordBreak|AlignTop + + + + + + + spacer25 + + + Vertical + + + Expanding + + + + 20 + 181 + + + + + + + + tab + + + A&ccount Preferences + + + + unnamed + + + + groupBox62 + + + Messaging Preferences + + + + unnamed + + + + layout119 + + + + unnamed + + + + textLabel2_2 + + + If the message is too &long: + + + ifMessageTooLong + + + What should happen if you type a message that is too long to fit in a single SMS message. + + + What should happen if you type a message that is too long to fit in a single SMS message. You can either choose to break it up into smaller messages automatically, cancel the message from being sent entirely, or have Kopete prompt you each time you enter a message that is too long. + + + + + + Prompt (recommended) + + + + + Break Into Multiple + + + + + Cancel Sending + + + + ifMessageTooLong + + + What should happen if you type a message that is too long to fit in a single SMS message. + + + What should happen if you type a message that is too long to fit in a single SMS message. You can either choose to break it up into smaller messages automatically, cancel the message from being sent entirely, or have Kopete prompt you each time you enter a message that is too long. + + + + + + + subEnable + + + &Enable phone number internationalization + + + Check if you would like to enable phone number internationalization. + + + Check if you would like to enable phone number internationalization. Without this option, you will only be able to use SMS for accounts within your country. + + + + + layout56 + + + + unnamed + + + + textLabel2_3 + + + false + + + + 5 + 5 + 1 + 0 + + + + Substitute leading &zero with code: + + + subCode + + + What you would like to substitute a leading zero with. + + + What you would like to substitute a leading zero with. + + + + + subCode + + + false + + + + 5 + 0 + 0 + 0 + + + + + + + + 1234567890+ + + + What you would like to substitute a leading zero with. + + + What you would like to substitute a leading zero with. + + + + + + + + + spacer27 + + + Vertical + + + Expanding + + + + 20 + 20 + + + + + + + + + labelStatusMessage + + + + + + AlignCenter + + + + + + + subEnable + toggled(bool) + textLabel2_3 + setEnabled(bool) + + + subEnable + toggled(bool) + subCode + setEnabled(bool) + + + + tabWidget9 + accountId + serviceName + descButton + ifMessageTooLong + subEnable + subCode + + + knuminput.h + + + + krestrictedline.h + + diff --git a/kopete/protocols/sms/ui/smsadd.ui b/kopete/protocols/sms/ui/smsadd.ui new file mode 100644 index 00000000..0ee71281 --- /dev/null +++ b/kopete/protocols/sms/ui/smsadd.ui @@ -0,0 +1,143 @@ + +smsAddUI + + + smsAddUI + + + + 0 + 0 + 397 + 347 + + + + + 5 + 5 + 0 + 0 + + + + + unnamed + + + 0 + + + 6 + + + + layout35 + + + + unnamed + + + + layout33 + + + + unnamed + + + + textLabel1 + + + &Telephone number: + + + addNr + + + The telephone number of the contact you would like to add. + + + The telephone number of the contact you would like to add. This should be a number with SMS service available. + + + + + textLabel1_2 + + + Contact na&me: + + + addName + + + A unique name for this SMS account. + + + A unique name for this SMS account. + + + + + + + layout34 + + + + unnamed + + + + addNr + + + The telephone number of the contact you would like to add. + + + The telephone number of the contact you would like to add. This should be a number with SMS service available. + + + + + addName + + + A unique name for this SMS account. + + + A unique name for this SMS account. + + + + + + + + + spacer9 + + + Vertical + + + Expanding + + + + 31 + 170 + + + + + + + addNr + addName + + + diff --git a/kopete/protocols/sms/ui/smsuserprefs.ui b/kopete/protocols/sms/ui/smsuserprefs.ui new file mode 100644 index 00000000..8a912792 --- /dev/null +++ b/kopete/protocols/sms/ui/smsuserprefs.ui @@ -0,0 +1,118 @@ + +SMSUserPrefsUI + + + SMSUserPrefsUI + + + + 0 + 0 + 252 + 144 + + + + + 5 + 5 + 0 + 0 + + + + + unnamed + + + 0 + + + + title + + + + 1 + + + + Some One + + + + + line10 + + + HLine + + + Sunken + + + Horizontal + + + + + layout11 + + + + unnamed + + + + textLabel3 + + + &Telephone number: + + + telNumber + + + The telephone number of the contact. + + + The telephone number of the contact. This should be a number with SMS service available. + + + + + telNumber + + + The telephone number of the contact. + + + The telephone number of the contact. This should be a number with SMS service available. + + + + + + + spacer11 + + + Vertical + + + Expanding + + + + 20 + 40 + + + + + + + + klineedit.h + + -- cgit v1.2.1