2
smssendprovider.cpp - SMS Plugin
4
Copyright (c) 2003 by Richard LƤrkƤng <nouseforaname@home.se>
5
Copyright (c) 2003 by Gav Wood <gav@kde.org>
7
*************************************************************************
9
* This program is free software; you can redistribute it and/or modify *
10
* it under the terms of the GNU General Public License as published by *
11
* the Free Software Foundation; either version 2 of the License, or *
12
* (at your option) any later version. *
14
*************************************************************************
17
#include "smssendprovider.h"
20
#include <QTextStream>
23
#include <kconfigbase.h>
24
#include <k3process.h>
25
#include <klineedit.h>
26
#include <kmessagebox.h>
30
#include "kopeteaccount.h"
31
#include "kopeteuiglobal.h"
33
#include "smsprotocol.h"
34
#include "smscontact.h"
36
SMSSendProvider::SMSSendProvider(const QString& providerName, const QString& prefixValue, Kopete::Account* account, QObject* parent)
37
: QObject( parent ), m_account(account)
39
kWarning( 14160 ) << "this = " << this << ", m_account = " << m_account << " (should be ok if zero!!)";
41
provider = providerName;
48
QString file = prefix + "/share/smssend/" + provider + ".sms";
50
if (f.open(QIODevice::ReadOnly))
53
QString group = QString("SMSSend-%1").arg(provider);
54
bool exactNumberMatch = false;
55
QStringList numberWords;
56
numberWords.append("Tel");
57
numberWords.append("Number");
58
numberWords.append("number");
59
numberWords.append("TelNum");
60
numberWords.append("Recipient");
61
numberWords.append("Tel1");
62
numberWords.append("To");
63
numberWords.append("nummer");
64
numberWords.append("telefone");
65
numberWords.append("ToPhone");
69
QString s = t.readLine();
72
QStringList args = s.split(':');
73
QStringList options = args[0].split(' ');
75
names.append(options[0].replace(0,1,""));
78
for(int i = 1; i < options.count(); i++)
79
if(options[i] == "Hidden")
83
isHiddens.append(hidden);
85
// Strip trailing whitespace in the end
86
// and '%' in the beginning
87
args[0] = args[0].simplified().mid(1);
89
descriptions.append(args[1]);
91
values.append(m_account->configGroup()->readEntry(QString("%1:%2").arg(group).arg(names[names.count()-1]),
96
if( args[0].contains("Message") || args[0].contains("message")
97
|| args[0].contains("message") || args[0].contains("nachricht")
98
|| args[0].contains("Msg") || args[0].contains("Mensagem") )
100
for( int i = 0; i < options.count(); i++)
102
if (options[i].contains("Size="))
104
QString option = options[i];
105
option.replace(0,5,"");
106
m_maxSize = option.toInt();
109
messagePos = names.count()-1;
111
else if (!exactNumberMatch)
113
for (QStringList::Iterator it=numberWords.begin(); it != numberWords.end(); ++it)
115
if (args[0].contains(*it))
117
telPos = names.count() - 1;
120
// kDebug(14160) << "Exact match for " << args[0];
121
exactNumberMatch = true;
123
// kDebug(14160) << "args[0] (" << args[0] << ") contains " << *it;
132
if ( messagePos == -1 || telPos == -1 )
141
SMSSendProvider::~SMSSendProvider()
143
kWarning( 14160 ) << "this = " << this;
146
void SMSSendProvider::setAccount(Kopete::Account *account)
151
QString SMSSendProvider::name(int i)
153
if ( telPos == i || messagePos == i)
159
const QString& SMSSendProvider::value(int i)
164
const QString& SMSSendProvider::description(int i)
166
return descriptions[i];
169
bool SMSSendProvider::isHidden(int i) const
174
void SMSSendProvider::save(const QList<KLineEdit*>& args)
176
kDebug( 14160 ) << "m_account = " << m_account << " (should be non-zero!!)";
177
if (!m_account) return; // prevent crash in worst case
179
QString group = QString("SMSSend-%1").arg(provider);
182
for (int i=0; i < args.count(); i++)
184
if (telPos == namesI || messagePos == namesI)
186
// kDebug(14160) << "Skipping pos " << namesI;
188
if (telPos == namesI || messagePos == namesI)
190
// kDebug(14160) << "Skipping pos " << namesI;
195
// kDebug(14160) << "saving " << args.at(i) << " to " << names[namesI];
196
if (!args.at(i)->text().isEmpty())
197
{ values[namesI] = args.at(i)->text();
198
m_account->configGroup()->writeEntry(QString("%1:%2").arg(group).arg(names[namesI]), values[namesI]);
204
int SMSSendProvider::count()
206
return names.count();
209
void SMSSendProvider::send(const Kopete::Message& msg)
211
if ( canSend == false )
213
if ( messagePos == -1 )
216
KMessageBox::error(Kopete::UI::Global::mainWidget(), i18n("Could not determine which argument should contain the message."),
217
i18n("Could Not Send Message"));
224
KMessageBox::error(Kopete::UI::Global::mainWidget(), i18n("Could not determine which argument should contain the number."),
225
i18n("Could Not Send Message"));
232
QString message = msg.plainBody();
233
QString nr = dynamic_cast<SMSContact *>(msg.to().first())->qualifiedNumber();
235
if (canSend == false)
238
values[messagePos] = message;
241
K3Process* p = new K3Process;
243
kWarning( 14160 ) << "Executing " << QString("%1/bin/smssend").arg(prefix) << " \"" << provider << "\" " << values.join("\" \"") << "\"";
245
*p << QString("%1/bin/smssend").arg(prefix) << provider << values;
248
connect( p, SIGNAL(processExited(K3Process*)), this, SLOT(slotSendFinished(K3Process*)));
249
connect( p, SIGNAL(receivedStdout(K3Process*,char*,int)), this, SLOT(slotReceivedOutput(K3Process*,char*,int)));
250
// connect( p, SIGNAL(receivedStderr(K3Process*,char*,int)), this, SLOT(slotReceivedOutput(K3Process*,char*,int)));
252
p->start(K3Process::NotifyOnExit, K3Process::AllOutput);
255
void SMSSendProvider::slotSendFinished(K3Process *p)
257
kWarning( 14160 ) << "this = " << this << ", es = " << p->exitStatus() << ", p = " << p << " (should be non-zero!!)";
258
if (p->exitStatus() == 0)
259
emit messageSent(m_msg);
261
emit messageNotSent(m_msg, QString::fromLatin1(output));
266
void SMSSendProvider::slotReceivedOutput(K3Process *, char *buffer, int buflen)
268
// QStringList lines = QStringList::split("\n", QString::fromLocal8Bit(buffer, buflen));
269
// for (QStringList::Iterator it = lines.begin(); it != lines.end(); ++it)
270
for(int i = 0; i < buflen; i++)
272
kWarning( 14160 ) << " output now = " << output;
275
int SMSSendProvider::maxSize()
280
#include "smssendprovider.moc"
283
* c-indentation-style: k&r
285
* indent-tabs-mode: t
288
// vim: set noet ts=4 sts=4 sw=4: