1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
/* *************************************************************************
* copyright: (C) 2003 Richard Lärkäng <nouseforaname@home.se> *
* copyright: (C) 2003 Gav Wood <gav@kde.org> *
*************************************************************************
*/
/* *************************************************************************
* *
* 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 <qcombobox.h>
#include <qlayout.h>
#include <klocale.h>
#include <kurlrequester.h>
#include <kmessagebox.h>
#include <kprocess.h>
#include <kdebug.h>
#include <kconfigbase.h>
#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("<qt>SMSClient is a program for sending SMS with the modem. The program can be found on <a href=\"%1\">%1</a></qt>").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:
|