summaryrefslogtreecommitdiffstats
path: root/kopete/protocols/sms/smseditaccountwidget.cpp
blob: e8a358d10bd888c1eece4f711b6eb7c6933081bf (plain)
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
/*  *************************************************************************
    *   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 <tqvgroupbox.h>
#include <tqlayout.h>
#include <tqcombobox.h>
#include <tqpushbutton.h>
#include <tqlineedit.h>
#include <tqcheckbox.h>
#include <tqradiobutton.h>

#include <tdeconfigbase.h>
#include <tdelocale.h>
#include <tdemessagebox.h>
#include <krestrictedline.h>

#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, TQWidget *parent, const char */*name*/)
	: TQWidget(parent), KopeteEditAccountWidget(account)
{
	TQVBoxLayout *l = new TQVBoxLayout(this, TQBoxLayout::Down);
	preferencesDialog = new smsActPrefsUI(this);
	l->addWidget(preferencesDialog);

	service = 0L;
	configWidget = 0L;
	middleFrameLayout = 0L;

	m_protocol = protocol;

	TQString 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", TQString());
		preferencesDialog->subEnable->setChecked(account->configGroup()->readBoolEntry("SubEnable", false));
		preferencesDialog->subCode->setText(account->configGroup()->readEntry("SubCode", TQString()));
		preferencesDialog->ifMessageTooLong->setCurrentItem(SMSMsgAction(account->configGroup()->readNumEntry("MsgAction", 0)));
	}

	preferencesDialog->serviceName->insertStringList(ServiceLoader::services());

	connect (preferencesDialog->serviceName, TQT_SIGNAL(activated(const TQString &)),
		this, TQT_SLOT(setServicePreferences(const TQString &)));
	connect (preferencesDialog->descButton, TQT_SIGNAL(clicked()),
		this, TQT_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());
	
	TDEConfigGroup *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 TQString& serviceName)
{
	delete service;
	delete configWidget;

	service = ServiceLoader::loadService(serviceName, account());

	if (service == 0L)
		return;

	connect (this, TQT_SIGNAL(saved()), service, TQT_SLOT(savePreferences()));

	delete middleFrameLayout;
	middleFrameLayout = new TQGridLayout(preferencesDialog->middleFrame, 1, 2, 0, 6, "middleFrameLayout");
	service->setWidgetContainer(preferencesDialog->middleFrame, middleFrameLayout);
}

void SMSEditAccountWidget::showDescription()
{
	SMSService* s = ServiceLoader::loadService(preferencesDialog->serviceName->currentText(), 0L);

	TQString 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: