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
|
/*
smpppdcspreferences.cpp
Copyright (c) 2004-2006 by Heiko Schaefer <heiko@rangun.de>
Kopete (c) 2002-2006 by the Kopete developers <kopete-devel@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; version 2 of the License. *
* *
*************************************************************************
*/
#include <tqlayout.h>
#include <tqregexp.h>
#include <tqradiobutton.h>
#include <klistview.h>
#include <klineedit.h>
#include <knuminput.h>
#include <kgenericfactory.h>
#include "kopeteaccount.h"
#include "kopeteprotocol.h"
#include "kopeteaccountmanager.h"
#include "smpppdlocationwidget.h"
#include "smpppdcspreferences.h"
#include "smpppdcsprefsimpl.h"
#include "smpppdcsconfig.h"
typedef KGenericFactory<SMPPPDCSPreferences> SMPPPDCSPreferencesFactory;
K_EXPORT_COMPONENT_FACTORY(kcm_kopete_smpppdcs, SMPPPDCSPreferencesFactory("kcm_kopete_smpppdcs"))
SMPPPDCSPreferences::SMPPPDCSPreferences(TQWidget * parent, const char * /* name */, const TQStringList& args)
: TDECModule(SMPPPDCSPreferencesFactory::instance(), parent, args), m_ui(NULL) {
Kopete::AccountManager * manager = Kopete::AccountManager::self();
(new TQVBoxLayout(this))->setAutoAdd(true);
m_ui = new SMPPPDCSPrefs(this);
for(TQPtrListIterator<Kopete::Account> it(manager->accounts()); it.current(); ++it)
{
TQString protoName;
TQRegExp rex("(.*)Protocol");
if(rex.search((*it)->protocol()->pluginId()) > -1) {
protoName = rex.cap(1);
} else {
protoName = (*it)->protocol()->pluginId();
}
if(it.current()->inherits("Kopete::ManagedConnectionAccount")) {
protoName += TQString(", %1").arg(i18n("connection status is managed by Kopete"));
}
TQCheckListItem * cli = new TQCheckListItem(m_ui->accountList,
(*it)->accountId() + " (" + protoName + ")", TQCheckListItem::CheckBox);
cli->setPixmap(0, (*it)->accountIcon());
m_accountMapOld[cli->text(0)] = AccountPrivMap(FALSE, (*it)->protocol()->pluginId() + "_" + (*it)->accountId());
m_accountMapCur[cli->text(0)] = AccountPrivMap(FALSE, (*it)->protocol()->pluginId() + "_" + (*it)->accountId());;
m_ui->accountList->insertItem(cli);
}
connect(m_ui->accountList, TQT_SIGNAL(clicked(TQListViewItem *)), this, TQT_SLOT(listClicked(TQListViewItem *)));
// connect for modified
connect(m_ui->useNetstat, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotModified()));
connect(m_ui->useSmpppd, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotModified()));
connect(m_ui->SMPPPDLocation->server, TQT_SIGNAL(textChanged(const TQString&)), this, TQT_SLOT(slotModified()));
connect(m_ui->SMPPPDLocation->port, TQT_SIGNAL(valueChanged(int)), this, TQT_SLOT(slotModified()));
connect(m_ui->SMPPPDLocation->Password, TQT_SIGNAL(textChanged(const TQString&)), this, TQT_SLOT(slotModified()));
load();
}
SMPPPDCSPreferences::~SMPPPDCSPreferences() {
delete m_ui;
}
void SMPPPDCSPreferences::listClicked(TQListViewItem * item)
{
TQCheckListItem * cli = dynamic_cast<TQCheckListItem *>(item);
if(cli->isOn() != m_accountMapCur[cli->text(0)].m_on) {
AccountMap::iterator itOld = m_accountMapOld.begin();
AccountMap::iterator itCur;
bool change = FALSE;
for(itCur = m_accountMapCur.begin(); itCur != m_accountMapCur.end(); ++itCur, ++itOld) {
if((*itCur).m_on != (*itOld).m_on){
change = TRUE;
break;
}
}
emit TDECModule::changed(change);
}
m_accountMapCur[cli->text(0)].m_on = cli->isOn();
}
void SMPPPDCSPreferences::defaults()
{
TQListViewItemIterator it(m_ui->accountList);
while(it.current()) {
TQCheckListItem * cli = dynamic_cast<TQCheckListItem *>(it.current());
cli->setOn(FALSE);
++it;
}
SMPPPDCSConfig::self()->setDefaults();
m_ui->useNetstat->setChecked(SMPPPDCSConfig::self()->useNetstat());
m_ui->useSmpppd->setChecked(SMPPPDCSConfig::self()->useSmpppd());
m_ui->SMPPPDLocation->server->setText(SMPPPDCSConfig::self()->server());
m_ui->SMPPPDLocation->port->setValue(SMPPPDCSConfig::self()->port());
m_ui->SMPPPDLocation->Password->setText(SMPPPDCSConfig::self()->password());
}
void SMPPPDCSPreferences::load()
{
SMPPPDCSConfig::self()->readConfig();
static TQString rexStr = "^(.*) \\((.*)\\)";
TQRegExp rex(rexStr);
TQStringList list = SMPPPDCSConfig::self()->ignoredAccounts();
TQListViewItemIterator it(m_ui->accountList);
while(it.current()) {
TQCheckListItem * cli = dynamic_cast<TQCheckListItem *>(it.current());
if(rex.search(cli->text(0)) > -1) {
bool isOn = list.contains(rex.cap(2) + "Protocol_" + rex.cap(1));
// m_accountMapOld[cli->text(0)].m_on = isOn;
m_accountMapCur[cli->text(0)].m_on = isOn;
cli->setOn(isOn);
}
++it;
}
m_ui->useNetstat->setChecked(SMPPPDCSConfig::self()->useNetstat());
m_ui->useSmpppd->setChecked(SMPPPDCSConfig::self()->useSmpppd());
m_ui->SMPPPDLocation->server->setText(SMPPPDCSConfig::self()->server());
m_ui->SMPPPDLocation->port->setValue(SMPPPDCSConfig::self()->port());
m_ui->SMPPPDLocation->Password->setText(SMPPPDCSConfig::self()->password());
emit TDECModule::changed(false);
}
void SMPPPDCSPreferences::save()
{
TQStringList list;
TQListViewItemIterator it(m_ui->accountList);
while(it.current()) {
TQCheckListItem * cli = dynamic_cast<TQCheckListItem *>(it.current());
if(cli->isOn()) {
list.append(m_accountMapCur[cli->text(0)].m_id);
}
++it;
}
SMPPPDCSConfig::self()->setIgnoredAccounts(list);
SMPPPDCSConfig::self()->setUseNetstat(m_ui->useNetstat->isChecked());
SMPPPDCSConfig::self()->setUseSmpppd(m_ui->useSmpppd->isChecked());
SMPPPDCSConfig::self()->setServer(m_ui->SMPPPDLocation->server->text());
SMPPPDCSConfig::self()->setPort(m_ui->SMPPPDLocation->port->value());
SMPPPDCSConfig::self()->setPassword(m_ui->SMPPPDLocation->Password->text());
SMPPPDCSConfig::self()->writeConfig();
emit TDECModule::changed(false);
}
void SMPPPDCSPreferences::slotModified() {
emit TDECModule::changed(true);
}
#include "smpppdcspreferences.moc"
|