00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef _KPILOT_OPTIONS_H
00032 #include "options.h"
00033 #endif
00034
00035 #ifndef QLINEEDIT_H
00036 #include <qlineedit.h>
00037 #endif
00038 #ifndef QLAYOUT_H
00039 #include <qlayout.h>
00040 #endif
00041 #ifndef QLABEL_H
00042 #include <qlabel.h>
00043 #endif
00044 #ifndef _KDEBUG_H
00045 #include <kdebug.h>
00046 #endif
00047
00048 #ifndef _KPILOT_PILOTADDRESS_H
00049 #include "pilotAddress.h"
00050 #endif
00051
00052 #include "addressEditor.moc"
00053
00054
00055 AddressEditor::AddressEditor(PilotAddress * p,
00056 PilotAddressInfo *appInfo,
00057 QWidget * parent,
00058 const char *name) :
00059 KDialogBase(KDialogBase::Plain,
00060 i18n("Address Editor"),
00061 Ok | Cancel, Cancel,
00062 parent, name, false ),
00063 fDeleteOnCancel(p == 0L),
00064 fAddress(p),
00065 fAppInfo(appInfo)
00066 {
00067 FUNCTIONSETUP;
00068
00069 initLayout();
00070 fillFields();
00071
00072 connect(parent, SIGNAL(recordChanged(PilotAddress *)),
00073 this, SLOT(updateRecord(PilotAddress *)));
00074
00075 }
00076
00077 AddressEditor::~AddressEditor()
00078 {
00079 FUNCTIONSETUP;
00080
00081 if (fDeleteOnCancel && fAddress)
00082 {
00083 #ifdef DEBUG
00084 DEBUGKPILOT << fname
00085 << ": Deleting private address record." << endl;
00086 #endif
00087
00088 delete fAddress;
00089
00090 fAddress = 0L;
00091 }
00092
00093 #ifdef DEBUG
00094 DEBUGKPILOT << fname << ": Help! I'm deleting!" << endl;
00095 #endif
00096 }
00097
00098
00099
00100
00101
00102
00103 QString AddressEditor::phoneLabelText(PilotAddress * addr, const PhoneSlot &i)
00104 {
00105 FUNCTIONSETUP;
00106 if (!addr)
00107 {
00108 return i18n("Phone");
00109 }
00110
00111 PilotAddressInfo::EPhoneType idx = addr->getPhoneType(i);
00112 QString ret = fAppInfo->phoneLabel(idx) + CSL1(":");
00113
00114 return ret;
00115 }
00116
00117
00118
00119 void AddressEditor::fillFields()
00120 {
00121 FUNCTIONSETUP;
00122
00123 if (fAddress == 0L)
00124 {
00125 fAddress = new PilotAddress();
00126 fDeleteOnCancel = true;
00127 }
00128
00129
00130 unsigned int index = 0;
00131 for ( PhoneSlot i = PhoneSlot::begin(); i.isValid(); ++i,++index )
00132 {
00133 m_phoneLabel[index]->setText(phoneLabelText(fAddress, i));
00134 fPhoneField[index]->setText(fAddress->getField(i));
00135 }
00136
00137
00138 fLastNameField->setText(fAddress->getField(entryLastname));
00139 fFirstNameField->setText(fAddress->getField(entryFirstname));
00140 fCompanyField->setText(fAddress->getField(entryCompany));
00141 fAddressField->setText(fAddress->getField(entryAddress));
00142 fCityField->setText(fAddress->getField(entryCity));
00143 fStateField->setText(fAddress->getField(entryState));
00144 fZipField->setText(fAddress->getField(entryZip));
00145 fCountryField->setText(fAddress->getField(entryCountry));
00146 fTitleField->setText(fAddress->getField(entryTitle));
00147 fCustom1Field->setText(fAddress->getField(entryCustom1));
00148 fCustom2Field->setText(fAddress->getField(entryCustom2));
00149 fCustom3Field->setText(fAddress->getField(entryCustom3));
00150 fCustom4Field->setText(fAddress->getField(entryCustom4));
00151 }
00152
00153
00154
00155
00156 #define MakeField(text,field,row,column) \
00157 t=new QLabel(text,p); \
00158 field = new QLineEdit(p); \
00159 field->setMinimumWidth(20*SPACING); \
00160 t->setBuddy(field); \
00161 grid->addWidget(t,row,column); \
00162 grid->addWidget(field,row,column+1);
00163
00164 #define MakeFieldL(text,label,field,row,column) \
00165 label = new QLabel(text,p); \
00166 field = new QLineEdit(p); \
00167 field->setMinimumWidth(20*SPACING); \
00168 label->setBuddy(field); \
00169 grid->addWidget(label,row,column); \
00170 grid->addWidget(field,row,column+1);
00171
00172 void AddressEditor::initLayout()
00173 {
00174 FUNCTIONSETUP;
00175
00176 QFrame *p = plainPage();
00177 QGridLayout *grid = new QGridLayout(p, 10, 5, 0, SPACING);
00178
00179 QLabel *t;
00180
00181 MakeField(i18n("Last name:"), fLastNameField, 0, 0);
00182 MakeField(i18n("First name:"), fFirstNameField, 1, 0);
00183 MakeField(i18n("Title:"), fTitleField, 2, 0);
00184 MakeField(i18n("Company:"), fCompanyField, 3, 0);
00185
00186 PhoneSlot slot = PhoneSlot::begin();
00187 for (int i = 0; slot.isValid(); ++i,++slot)
00188 {
00189 MakeFieldL(phoneLabelText(NULL, slot),
00190 m_phoneLabel[i], fPhoneField[i], 4 + i, 0);
00191 }
00192
00193 MakeField(i18n("Address:"), fAddressField, 0, 4);
00194 MakeField(i18n("City:"), fCityField, 1, 4);
00195 MakeField(i18n("State:"), fStateField, 2, 4);
00196 MakeField(i18n("Zip code:"), fZipField, 3, 4);
00197 MakeField(i18n("Country:"), fCountryField, 4, 4);
00198 MakeField(i18n("Custom 1:"), fCustom1Field, 5, 4);
00199 MakeField(i18n("Custom 2:"), fCustom2Field, 6, 4);
00200 MakeField(i18n("Custom 3:"), fCustom3Field, 7, 4);
00201 MakeField(i18n("Custom 4:"), fCustom4Field, 8, 4);
00202
00203 grid->addRowSpacing(9, SPACING);
00204 grid->addColSpacing(2, SPACING);
00205 grid->setRowStretch(9, 100);
00206 grid->setColStretch(2, 50);
00207 }
00208
00209 void AddressEditor::slotCancel()
00210 {
00211 FUNCTIONSETUP;
00212
00213 if (fDeleteOnCancel && fAddress)
00214 {
00215 delete fAddress;
00216
00217 fAddress = 0L;
00218 }
00219 KDialogBase::slotCancel();
00220 }
00221
00222 void AddressEditor::slotOk()
00223 {
00224 FUNCTIONSETUP;
00225
00226
00227 fAddress->setField(entryLastname, fLastNameField->text());
00228 fAddress->setField(entryFirstname, fFirstNameField->text());
00229 fAddress->setField(entryCompany, fCompanyField->text());
00230 fAddress->setField(entryPhone1, fPhoneField[0]->text());
00231 fAddress->setField(entryPhone2, fPhoneField[1]->text());
00232 fAddress->setField(entryPhone3, fPhoneField[2]->text());
00233 fAddress->setField(entryPhone4, fPhoneField[3]->text());
00234 fAddress->setField(entryPhone5, fPhoneField[4]->text());
00235 fAddress->setField(entryAddress, fAddressField->text());
00236 fAddress->setField(entryCity, fCityField->text());
00237 fAddress->setField(entryState, fStateField->text());
00238 fAddress->setField(entryZip, fZipField->text());
00239 fAddress->setField(entryCountry, fCountryField->text());
00240 fAddress->setField(entryTitle, fTitleField->text());
00241 fAddress->setField(entryCustom1, fCustom1Field->text());
00242 fAddress->setField(entryCustom2, fCustom2Field->text());
00243 fAddress->setField(entryCustom3, fCustom3Field->text());
00244 fAddress->setField(entryCustom4, fCustom4Field->text());
00245
00246 emit(recordChangeComplete(fAddress));
00247 KDialogBase::slotOk();
00248 }
00249
00250 void AddressEditor::updateRecord(PilotAddress * p)
00251 {
00252 FUNCTIONSETUP;
00253 if (p != fAddress)
00254 {
00255
00256
00257
00258 return;
00259 }
00260
00261 if (p->isDeleted())
00262 {
00263 delayedDestruct();
00264 return;
00265 }
00266 else
00267 {
00268 fillFields();
00269 }
00270 }
00271