kpilot Library API Documentation

addressEditor.cc

00001 // -*- C++ -*-
00002 /* addressEditor.cc     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., 59 Temple Place, Suite 330, Boston, 
00023 ** MA 02111-1307, 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 static const char *addressEditor_id =
00055     "$Id: addressEditor.cc,v 1.14 2003/10/10 02:04:51 zelenko Exp $";
00056 
00057 AddressEditor::AddressEditor(PilotAddress * p,
00058     struct AddressAppInfo *appInfo,
00059     QWidget * parent,
00060     const char *name) :
00061     KDialogBase(KDialogBase::Plain,
00062         i18n("Address Editor"),
00063         Ok | Cancel, Cancel,
00064         parent, name, false /* non-modal */ ),
00065     fDeleteOnCancel(p == 0L), 
00066     fAddress(p), 
00067     fAppInfo(appInfo)
00068 {
00069     FUNCTIONSETUP;
00070 
00071     initLayout();
00072     fillFields();
00073 
00074     connect(parent, SIGNAL(recordChanged(PilotAddress *)),
00075         this, SLOT(updateRecord(PilotAddress *)));
00076 
00077     (void) addressEditor_id;
00078 }
00079 
00080 AddressEditor::~AddressEditor()
00081 {
00082     FUNCTIONSETUP;
00083 
00084     if (fDeleteOnCancel && fAddress)
00085     {
00086 #ifdef DEBUG
00087         DEBUGKPILOT << fname
00088             << ": Deleting private address record." << endl;
00089 #endif
00090 
00091         delete fAddress;
00092 
00093         fAddress = 0L;
00094     }
00095 
00096 #ifdef DEBUG
00097     DEBUGKPILOT << fname << ": Help! I'm deleting!" << endl;
00098 #endif
00099 }
00100 
00101 
00102 
00103 /*
00104  * Return phone label from AddressAppInfo + some sanity checking
00105  */
00106 QString AddressEditor::phoneLabelText(PilotAddress * addr, int i)
00107 {
00108     FUNCTIONSETUP;
00109 
00110     QString ret(i18n("Phone"));
00111     char *s;
00112     int idx = i;
00113 
00114     if (addr)
00115         idx = addr->getPhoneLabelIndex(i);
00116 
00117     if (idx >= 0 && idx < 8)    // hard-coded, no constant in pi-address.h
00118     {
00119         if ((s = fAppInfo->phoneLabels[idx]))
00120         {
00121             ret = s;
00122             ret += CSL1(":");
00123         }
00124     }
00125 
00126     return ret;
00127 }
00128 
00129 
00130 
00131 void AddressEditor::fillFields()
00132 {
00133     FUNCTIONSETUP;
00134 
00135     if (fAddress == 0L)
00136     {
00137         fAddress = new PilotAddress(*fAppInfo);
00138         fDeleteOnCancel = true;
00139     }
00140 
00141     // phone labels
00142     for (int i = 0; i < 5; i++)
00143         m_phoneLabel[i]->setText(phoneLabelText(fAddress, i));
00144 
00145     // fields
00146     fLastNameField->setText(fAddress->getField(entryLastname));
00147     fFirstNameField->setText(fAddress->getField(entryFirstname));
00148     fCompanyField->setText(fAddress->getField(entryCompany));
00149     fPhoneField[0]->setText(fAddress->getField(entryPhone1));
00150     fPhoneField[1]->setText(fAddress->getField(entryPhone2));
00151     fPhoneField[2]->setText(fAddress->getField(entryPhone3));
00152     fPhoneField[3]->setText(fAddress->getField(entryPhone4));
00153     fPhoneField[4]->setText(fAddress->getField(entryPhone5));
00154     fAddressField->setText(fAddress->getField(entryAddress));
00155     fCityField->setText(fAddress->getField(entryCity));
00156     fStateField->setText(fAddress->getField(entryState));
00157     fZipField->setText(fAddress->getField(entryZip));
00158     fCountryField->setText(fAddress->getField(entryCountry));
00159     fTitleField->setText(fAddress->getField(entryTitle));
00160     fCustom1Field->setText(fAddress->getField(entryCustom1));
00161     fCustom2Field->setText(fAddress->getField(entryCustom2));
00162     fCustom3Field->setText(fAddress->getField(entryCustom3));
00163     fCustom4Field->setText(fAddress->getField(entryCustom4));
00164 }
00165 
00166 
00167 
00168 
00169 #define MakeField(text,field,row,column) \
00170                 t=new QLabel(text,p); \
00171         field = new QLineEdit(p); \
00172                 field->setMinimumWidth(20*SPACING); \
00173         t->setBuddy(field); \
00174         grid->addWidget(t,row,column); \
00175         grid->addWidget(field,row,column+1);
00176 
00177 #define MakeFieldL(text,label,field,row,column) \
00178                 label = new QLabel(text,p); \
00179         field = new QLineEdit(p); \
00180                 field->setMinimumWidth(20*SPACING); \
00181         label->setBuddy(field); \
00182         grid->addWidget(label,row,column); \
00183         grid->addWidget(field,row,column+1);
00184 
00185 void AddressEditor::initLayout()
00186 {
00187     FUNCTIONSETUP;
00188 
00189     QFrame *p = plainPage();
00190     QGridLayout *grid = new QGridLayout(p, 10, 5, 0, SPACING);
00191 
00192     QLabel *t;
00193 
00194     MakeField(i18n("Last name:"), fLastNameField, 0, 0);
00195     MakeField(i18n("First name:"), fFirstNameField, 1, 0);
00196     MakeField(i18n("Title:"), fTitleField, 2, 0);
00197     MakeField(i18n("Company:"), fCompanyField, 3, 0);
00198 
00199     for (int i = 0; i < 5; i++)
00200     {
00201         MakeFieldL(phoneLabelText(NULL, 0),
00202             m_phoneLabel[i], fPhoneField[i], 4 + i, 0);
00203     }
00204 
00205     MakeField(i18n("Address:"), fAddressField, 0, 4);
00206     MakeField(i18n("City:"), fCityField, 1, 4);
00207     MakeField(i18n("State:"), fStateField, 2, 4);
00208     MakeField(i18n("Zip code:"), fZipField, 3, 4);
00209     MakeField(i18n("Country:"), fCountryField, 4, 4);
00210     MakeField(i18n("Custom 1:"), fCustom1Field, 5, 4);
00211     MakeField(i18n("Custom 2:"), fCustom2Field, 6, 4);
00212     MakeField(i18n("Custom 3:"), fCustom3Field, 7, 4);
00213     MakeField(i18n("Custom 4:"), fCustom4Field, 8, 4);
00214 
00215     grid->addRowSpacing(9, SPACING);
00216     grid->addColSpacing(2, SPACING);
00217     grid->setRowStretch(9, 100);
00218     grid->setColStretch(2, 50);
00219 }
00220 
00221 /* slot */ void AddressEditor::slotCancel()
00222 {
00223     FUNCTIONSETUP;
00224 
00225     if (fDeleteOnCancel && fAddress)
00226     {
00227         delete fAddress;
00228 
00229         fAddress = 0L;
00230     }
00231     KDialogBase::slotCancel();
00232 }
00233 
00234 /* slot */ void AddressEditor::slotOk()
00235 {
00236     FUNCTIONSETUP;
00237 
00238     // Commit changes here
00239     fAddress->setField(entryLastname, fLastNameField->text());
00240     fAddress->setField(entryFirstname, fFirstNameField->text());
00241     fAddress->setField(entryCompany, fCompanyField->text());
00242     fAddress->setField(entryPhone1, fPhoneField[0]->text());
00243     fAddress->setField(entryPhone2, fPhoneField[1]->text());
00244     fAddress->setField(entryPhone3, fPhoneField[2]->text());
00245     fAddress->setField(entryPhone4, fPhoneField[3]->text());
00246     fAddress->setField(entryPhone5, fPhoneField[4]->text());
00247     fAddress->setField(entryAddress, fAddressField->text());
00248     fAddress->setField(entryCity, fCityField->text());
00249     fAddress->setField(entryState, fStateField->text());
00250     fAddress->setField(entryZip, fZipField->text());
00251     fAddress->setField(entryCountry, fCountryField->text());
00252     fAddress->setField(entryTitle, fTitleField->text());
00253     fAddress->setField(entryCustom1, fCustom1Field->text());
00254     fAddress->setField(entryCustom2, fCustom2Field->text());
00255     fAddress->setField(entryCustom3, fCustom3Field->text());
00256     fAddress->setField(entryCustom4, fCustom4Field->text());
00257 
00258     emit(recordChangeComplete(fAddress));
00259     KDialogBase::slotOk();
00260 }
00261 
00262 /* slot */ void AddressEditor::updateRecord(PilotAddress * p)
00263 {
00264     FUNCTIONSETUP;
00265     if (p != fAddress)
00266     {
00267         // Not meant for me
00268         //
00269         //
00270         return;
00271     }
00272 
00273     if (p->isDeleted())
00274     {
00275         delayedDestruct();
00276         return;
00277     }
00278     else
00279     {
00280         fillFields();
00281     }
00282 }
00283 
KDE Logo
This file is part of the documentation for kpilot Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat May 1 11:36:46 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003