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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
|
/* *************************************************************************
* copyright: (C) 2003 Richard L�k�g <[email protected]> *
* copyright: (C) 2003 Gav Wood <[email protected]> *
*************************************************************************
*/
/* *************************************************************************
* *
* 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 <tqcombobox.h>
#include <tqvgroupbox.h>
#include <tqlayout.h>
#include <tqlabel.h>
#include <tqtooltip.h>
#include <tdeconfigbase.h>
#include <klineedit.h>
#include <tdelocale.h>
#include <kurlrequester.h>
#include <tdemessagebox.h>
#include <kdebug.h>
#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;
TQString provider = m_account->configGroup()->readEntry("SMSSend:ProviderName", TQString());
if (provider.length() < 1)
{
KMessageBox::error(Kopete::UI::Global::mainWidget(), i18n("No provider configured."), i18n("Could Not Send Message"));
return;
}
TQString prefix = m_account->configGroup()->readEntry("SMSSend:Prefix", TQString());
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);
TQObject::connect( m_provider, TQ_SIGNAL(messageSent(const Kopete::Message &)), this, TQ_SIGNAL(messageSent(const Kopete::Message &)));
TQObject::connect( m_provider, TQ_SIGNAL(messageNotSent(const Kopete::Message &, const TQString &)), this, TQ_SIGNAL(messageNotSent(const Kopete::Message &, const TQString &)));
m_provider->send(msg);
}
void SMSSend::setWidgetContainer(TQWidget* parent, TQGridLayout* 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);
TQString prefix = TQString();
if (m_account)
prefix = m_account->configGroup()->readEntry("SMSSend:Prefix", TQString());
if (prefix.isNull())
{
TQDir d("/usr/share/smssend");
if (d.exists())
{
prefix = "/usr";
}
d = "/usr/local/share/smssend";
if (d.exists())
{
prefix="/usr/local";
}
else
{
prefix="/usr";
}
}
TQObject::connect (prefWidget->program, TQ_SIGNAL(textChanged(const TQString &)),
this, TQ_SLOT(loadProviders(const TQString&)));
prefWidget->program->setURL(prefix);
TQObject::connect(prefWidget->provider, TQ_SIGNAL(activated(const TQString &)),
this, TQ_SLOT(setOptions(const TQString &)));
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 TQString &prefix)
{
kdWarning( 14160 ) << k_funcinfo << "m_account = " << m_account << " (should be ok if zero)" << endl;
TQStringList p;
prefWidget->provider->clear();
TQDir d(prefix + "/share/smssend");
if (!d.exists())
{
setOptions(TQString());
return;
}
p = d.entryList("*.sms");
d = TQDir::homeDirPath()+"/.smssend/";
TQStringList tmp(d.entryList("*.sms"));
for (TQStringList::Iterator it = tmp.begin(); it != tmp.end(); ++it)
p.prepend(*it);
for (TQStringList::iterator it = p.begin(); it != p.end(); ++it)
(*it).truncate((*it).length()-4);
prefWidget->provider->insertStringList(p);
bool found = false;
if (m_account)
{ TQString pName = m_account->configGroup()->readEntry("SMSSend:ProviderName", TQString());
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 TQString& 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())
{
TQLabel *l = new TQLabel(m_parent);
l->setText("&" + m_provider->name(i) + ":");
TQToolTip::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(TQLineEdit::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;
TQString pName = m_account->configGroup()->readEntry("SMSSend:ProviderName", TQString());
if (pName.length() < 1)
return 160;
TQString prefix = m_account->configGroup()->readEntry("SMSSend:Prefix", TQString());
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 TQString& SMSSend::description()
{
TQString url = "http://zekiller.skytech.org/smssend_en.php";
m_description = i18n("<qt>SMSSend is a program for sending SMS through gateways on the web. It can be found on <a href=\"%1\">%2</a></qt>").arg(url).arg(url);
return m_description;
}
#include "smssend.moc"
|