kpilot/kpilot

addressEditor.cc

00001 // -*- C++ -*-
00002 /* KPilot
00003 **
00004 ** Copyright (C) 2000 by Dan Pilone
00005 **
00006 ** This is a dialog window that edits one single address record.
00007 */
00008 
00009 /*
00010 ** This program is free software; you can redistribute it and/or modify
00011 ** it under the terms of the GNU General Public License as published by
00012 ** the Free Software Foundation; either version 2 of the License, or
00013 ** (at your option) any later version.
00014 **
00015 ** This program is distributed in the hope that it will be useful,
00016 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00018 ** GNU General Public License for more details.
00019 **
00020 ** You should have received a copy of the GNU General Public License
00021 ** along with this program in a file called COPYING; if not, write to
00022 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00023 ** MA 02110-1301, USA.
00024 */
00025 
00026 /*
00027 ** Bug reports and questions can be sent to kde-pim@kde.org
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 /* non-modal */ ),
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  * Return phone label from AddressAppInfo + some sanity checking
00102  */
00103 QString AddressEditor::phoneLabelText(PilotAddress * addr, int i)
00104 {
00105     FUNCTIONSETUP;
00106 
00107     QString ret(i18n("Phone"));
00108     char *s;
00109     int idx = i;
00110 
00111     if (addr)
00112         idx = addr->getPhoneLabelIndex(i);
00113 
00114     if (idx >= 0 && idx < 8)    // hard-coded, no constant in pi-address.h
00115     {
00116         if ((s = fAppInfo->info()->phoneLabels[idx]))
00117         {
00118             ret = s;
00119             ret += CSL1(":");
00120         }
00121     }
00122 
00123     return ret;
00124 }
00125 
00126 
00127 
00128 void AddressEditor::fillFields()
00129 {
00130     FUNCTIONSETUP;
00131 
00132     if (fAddress == 0L)
00133     {
00134         fAddress = new PilotAddress(fAppInfo);
00135         fDeleteOnCancel = true;
00136     }
00137 
00138     // phone labels
00139     for (int i = 0; i < 5; i++)
00140         m_phoneLabel[i]->setText(phoneLabelText(fAddress, i));
00141 
00142     // fields
00143     fLastNameField->setText(fAddress->getField(entryLastname));
00144     fFirstNameField->setText(fAddress->getField(entryFirstname));
00145     fCompanyField->setText(fAddress->getField(entryCompany));
00146     fPhoneField[0]->setText(fAddress->getField(entryPhone1));
00147     fPhoneField[1]->setText(fAddress->getField(entryPhone2));
00148     fPhoneField[2]->setText(fAddress->getField(entryPhone3));
00149     fPhoneField[3]->setText(fAddress->getField(entryPhone4));
00150     fPhoneField[4]->setText(fAddress->getField(entryPhone5));
00151     fAddressField->setText(fAddress->getField(entryAddress));
00152     fCityField->setText(fAddress->getField(entryCity));
00153     fStateField->setText(fAddress->getField(entryState));
00154     fZipField->setText(fAddress->getField(entryZip));
00155     fCountryField->setText(fAddress->getField(entryCountry));
00156     fTitleField->setText(fAddress->getField(entryTitle));
00157     fCustom1Field->setText(fAddress->getField(entryCustom1));
00158     fCustom2Field->setText(fAddress->getField(entryCustom2));
00159     fCustom3Field->setText(fAddress->getField(entryCustom3));
00160     fCustom4Field->setText(fAddress->getField(entryCustom4));
00161 }
00162 
00163 
00164 
00165 
00166 #define MakeField(text,field,row,column) \
00167         t=new QLabel(text,p); \
00168         field = new QLineEdit(p); \
00169         field->setMinimumWidth(20*SPACING); \
00170         t->setBuddy(field); \
00171         grid->addWidget(t,row,column); \
00172         grid->addWidget(field,row,column+1);
00173 
00174 #define MakeFieldL(text,label,field,row,column) \
00175         label = new QLabel(text,p); \
00176         field = new QLineEdit(p); \
00177         field->setMinimumWidth(20*SPACING); \
00178         label->setBuddy(field); \
00179         grid->addWidget(label,row,column); \
00180         grid->addWidget(field,row,column+1);
00181 
00182 void AddressEditor::initLayout()
00183 {
00184     FUNCTIONSETUP;
00185 
00186     QFrame *p = plainPage();
00187     QGridLayout *grid = new QGridLayout(p, 10, 5, 0, SPACING);
00188 
00189     QLabel *t;
00190 
00191     MakeField(i18n("Last name:"), fLastNameField, 0, 0);
00192     MakeField(i18n("First name:"), fFirstNameField, 1, 0);
00193     MakeField(i18n("Title:"), fTitleField, 2, 0);
00194     MakeField(i18n("Company:"), fCompanyField, 3, 0);
00195 
00196     for (int i = 0; i < 5; i++)
00197     {
00198         MakeFieldL(phoneLabelText(NULL, 0),
00199             m_phoneLabel[i], fPhoneField[i], 4 + i, 0);
00200     }
00201 
00202     MakeField(i18n("Address:"), fAddressField, 0, 4);
00203     MakeField(i18n("City:"), fCityField, 1, 4);
00204     MakeField(i18n("State:"), fStateField, 2, 4);
00205     MakeField(i18n("Zip code:"), fZipField, 3, 4);
00206     MakeField(i18n("Country:"), fCountryField, 4, 4);
00207     MakeField(i18n("Custom 1:"), fCustom1Field, 5, 4);
00208     MakeField(i18n("Custom 2:"), fCustom2Field, 6, 4);
00209     MakeField(i18n("Custom 3:"), fCustom3Field, 7, 4);
00210     MakeField(i18n("Custom 4:"), fCustom4Field, 8, 4);
00211 
00212     grid->addRowSpacing(9, SPACING);
00213     grid->addColSpacing(2, SPACING);
00214     grid->setRowStretch(9, 100);
00215     grid->setColStretch(2, 50);
00216 }
00217 
00218 /* slot */ void AddressEditor::slotCancel()
00219 {
00220     FUNCTIONSETUP;
00221 
00222     if (fDeleteOnCancel && fAddress)
00223     {
00224         delete fAddress;
00225 
00226         fAddress = 0L;
00227     }
00228     KDialogBase::slotCancel();
00229 }
00230 
00231 /* slot */ void AddressEditor::slotOk()
00232 {
00233     FUNCTIONSETUP;
00234 
00235     // Commit changes here
00236     fAddress->setField(entryLastname, fLastNameField->text());
00237     fAddress->setField(entryFirstname, fFirstNameField->text());
00238     fAddress->setField(entryCompany, fCompanyField->text());
00239     fAddress->setField(entryPhone1, fPhoneField[0]->text());
00240     fAddress->setField(entryPhone2, fPhoneField[1]->text());
00241     fAddress->setField(entryPhone3, fPhoneField[2]->text());
00242     fAddress->setField(entryPhone4, fPhoneField[3]->text());
00243     fAddress->setField(entryPhone5, fPhoneField[4]->text());
00244     fAddress->setField(entryAddress, fAddressField->text());
00245     fAddress->setField(entryCity, fCityField->text());
00246     fAddress->setField(entryState, fStateField->text());
00247     fAddress->setField(entryZip, fZipField->text());
00248     fAddress->setField(entryCountry, fCountryField->text());
00249     fAddress->setField(entryTitle, fTitleField->text());
00250     fAddress->setField(entryCustom1, fCustom1Field->text());
00251     fAddress->setField(entryCustom2, fCustom2Field->text());
00252     fAddress->setField(entryCustom3, fCustom3Field->text());
00253     fAddress->setField(entryCustom4, fCustom4Field->text());
00254 
00255     emit(recordChangeComplete(fAddress));
00256     KDialogBase::slotOk();
00257 }
00258 
00259 /* slot */ void AddressEditor::updateRecord(PilotAddress * p)
00260 {
00261     FUNCTIONSETUP;
00262     if (p != fAddress)
00263     {
00264         // Not meant for me
00265         //
00266         //
00267         return;
00268     }
00269 
00270     if (p->isDeleted())
00271     {
00272         delayedDestruct();
00273         return;
00274     }
00275     else
00276     {
00277         fillFields();
00278     }
00279 }
00280 
KDE Home | KDE Accessibility Home | Description of Access Keys