summaryrefslogtreecommitdiffstats
path: root/kpilot/addressEditor.cc
blob: c9e4f9b3d0b55ae3ae30caea8c8ef83f9f5b939a (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
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
/* KPilot
**
** Copyright (C) 2000 by Dan Pilone
**
** This is a dialog window that edits one single address record.
*/

/*
** 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.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program in a file called COPYING; if not, write to
** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
** MA 02110-1301, USA.
*/

/*
** Bug reports and questions can be sent to kde-pim@kde.org
*/


#ifndef _KPILOT_OPTIONS_H
#include "options.h"
#endif

#ifndef TQLINEEDIT_H
#include <tqlineedit.h>
#endif
#ifndef TQLAYOUT_H
#include <tqlayout.h>
#endif
#ifndef TQLABEL_H
#include <tqlabel.h>
#endif
#ifndef _KDEBUG_H
#include <kdebug.h>
#endif

#ifndef _KPILOT_PILOTADDRESS_H
#include "pilotAddress.h"
#endif

#include "addressEditor.moc"


AddressEditor::AddressEditor(PilotAddress * p,
	PilotAddressInfo *appInfo,
	TQWidget * parent,
	const char *name) :
	KDialogBase(KDialogBase::Plain,
		i18n("Address Editor"),
		Ok | Cancel, Cancel,
		parent, name, false /* non-modal */ ),
	fDeleteOnCancel(p == 0L),
	fAddress(p),
	fAppInfo(appInfo)
{
	FUNCTIONSETUP;

	initLayout();
	fillFields();

	connect(parent, TQT_SIGNAL(recordChanged(PilotAddress *)),
		this, TQT_SLOT(updateRecord(PilotAddress *)));

}

AddressEditor::~AddressEditor()
{
	FUNCTIONSETUP;

	if (fDeleteOnCancel && fAddress)
	{
#ifdef DEBUG
		DEBUGKPILOT << fname
			<< ": Deleting private address record." << endl;
#endif

		delete fAddress;

		fAddress = 0L;
	}

#ifdef DEBUG
	DEBUGKPILOT << fname << ": Help! I'm deleting!" << endl;
#endif
}



/*
 * Return phone label from AddressAppInfo + some sanity checking
 */
TQString AddressEditor::phoneLabelText(PilotAddress * addr, const PhoneSlot &i)
{
	FUNCTIONSETUP;
	if (!addr)
	{
		return i18n("Phone");
	}

	PilotAddressInfo::EPhoneType idx = addr->getPhoneType(i);
	TQString ret = fAppInfo->phoneLabel(idx) + CSL1(":");

	return ret;
}



void AddressEditor::fillFields()
{
	FUNCTIONSETUP;

	if (fAddress == 0L)
	{
		fAddress = new PilotAddress();
		fDeleteOnCancel = true;
	}

	// phone labels
	unsigned int index = 0;
	for ( PhoneSlot i = PhoneSlot::begin(); i.isValid(); ++i,++index )
	{
		m_phoneLabel[index]->setText(phoneLabelText(fAddress, i));
		fPhoneField[index]->setText(fAddress->getField(i));
	}

	// fields
	fLastNameField->setText(fAddress->getField(entryLastname));
	fFirstNameField->setText(fAddress->getField(entryFirstname));
	fCompanyField->setText(fAddress->getField(entryCompany));
	fAddressField->setText(fAddress->getField(entryAddress));
	fCityField->setText(fAddress->getField(entryCity));
	fStateField->setText(fAddress->getField(entryState));
	fZipField->setText(fAddress->getField(entryZip));
	fCountryField->setText(fAddress->getField(entryCountry));
	fTitleField->setText(fAddress->getField(entryTitle));
	fCustom1Field->setText(fAddress->getField(entryCustom1));
	fCustom2Field->setText(fAddress->getField(entryCustom2));
	fCustom3Field->setText(fAddress->getField(entryCustom3));
	fCustom4Field->setText(fAddress->getField(entryCustom4));
}




#define MakeField(text,field,row,column) \
		t=new TQLabel(text,p); \
		field = new TQLineEdit(p); \
		field->setMinimumWidth(20*SPACING); \
		t->setBuddy(field); \
		grid->addWidget(t,row,column); \
		grid->addWidget(field,row,column+1);

#define MakeFieldL(text,label,field,row,column) \
		label = new TQLabel(text,p); \
		field = new TQLineEdit(p); \
		field->setMinimumWidth(20*SPACING); \
		label->setBuddy(field); \
		grid->addWidget(label,row,column); \
		grid->addWidget(field,row,column+1);

void AddressEditor::initLayout()
{
	FUNCTIONSETUP;

	TQFrame *p = plainPage();
	TQGridLayout *grid = new TQGridLayout(p, 10, 5, 0, SPACING);

	TQLabel *t;

	MakeField(i18n("Last name:"), fLastNameField, 0, 0);
	MakeField(i18n("First name:"), fFirstNameField, 1, 0);
	MakeField(i18n("Title:"), fTitleField, 2, 0);
	MakeField(i18n("Company:"), fCompanyField, 3, 0);

	PhoneSlot slot = PhoneSlot::begin();
	for (int i = 0; slot.isValid(); ++i,++slot)
	{
		MakeFieldL(phoneLabelText(NULL, slot),
			m_phoneLabel[i], fPhoneField[i], 4 + i, 0);
	}

	MakeField(i18n("Address:"), fAddressField, 0, 4);
	MakeField(i18n("City:"), fCityField, 1, 4);
	MakeField(i18n("State:"), fStateField, 2, 4);
	MakeField(i18n("Zip code:"), fZipField, 3, 4);
	MakeField(i18n("Country:"), fCountryField, 4, 4);
	MakeField(i18n("Custom 1:"), fCustom1Field, 5, 4);
	MakeField(i18n("Custom 2:"), fCustom2Field, 6, 4);
	MakeField(i18n("Custom 3:"), fCustom3Field, 7, 4);
	MakeField(i18n("Custom 4:"), fCustom4Field, 8, 4);

	grid->addRowSpacing(9, SPACING);
	grid->addColSpacing(2, SPACING);
	grid->setRowStretch(9, 100);
	grid->setColStretch(2, 50);
}

/* slot */ void AddressEditor::slotCancel()
{
	FUNCTIONSETUP;

	if (fDeleteOnCancel && fAddress)
	{
		delete fAddress;

		fAddress = 0L;
	}
	KDialogBase::slotCancel();
}

/* slot */ void AddressEditor::slotOk()
{
	FUNCTIONSETUP;

	// Commit changes here
	fAddress->setField(entryLastname, fLastNameField->text());
	fAddress->setField(entryFirstname, fFirstNameField->text());
	fAddress->setField(entryCompany, fCompanyField->text());
	fAddress->setField(entryPhone1, fPhoneField[0]->text());
	fAddress->setField(entryPhone2, fPhoneField[1]->text());
	fAddress->setField(entryPhone3, fPhoneField[2]->text());
	fAddress->setField(entryPhone4, fPhoneField[3]->text());
	fAddress->setField(entryPhone5, fPhoneField[4]->text());
	fAddress->setField(entryAddress, fAddressField->text());
	fAddress->setField(entryCity, fCityField->text());
	fAddress->setField(entryState, fStateField->text());
	fAddress->setField(entryZip, fZipField->text());
	fAddress->setField(entryCountry, fCountryField->text());
	fAddress->setField(entryTitle, fTitleField->text());
	fAddress->setField(entryCustom1, fCustom1Field->text());
	fAddress->setField(entryCustom2, fCustom2Field->text());
	fAddress->setField(entryCustom3, fCustom3Field->text());
	fAddress->setField(entryCustom4, fCustom4Field->text());

	emit(recordChangeComplete(fAddress));
	KDialogBase::slotOk();
}

/* slot */ void AddressEditor::updateRecord(PilotAddress * p)
{
	FUNCTIONSETUP;
	if (p != fAddress)
	{
		// Not meant for me
		//
		//
		return;
	}

	if (p->isDeleted())
	{
		delayedDestruct();
		return;
	}
	else
	{
		fillFields();
	}
}