# kabc Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# phonenumber.cpp

    00001 /*
    00002     This file is part of libkabc.
    00003     Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
    00004
    00005     This library is free software; you can redistribute it and/or
    00006     modify it under the terms of the GNU Library General Public
    00007     License as published by the Free Software Foundation; either
    00008     version 2 of the License, or (at your option) any later version.
    00009
    00010     This library is distributed in the hope that it will be useful,
    00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00013     Library General Public License for more details.
    00014
    00015     You should have received a copy of the GNU Library General Public License
    00016     along with this library; see the file COPYING.LIB.  If not, write to
    00017     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00018     Boston, MA 02111-1307, USA.
    00019 */
    00020
    00021 #include <kapplication.h>
    00022 #include <klocale.h>
    00023
    00024 #include "phonenumber.h"
    00025
    00026 using namespace KABC;
    00027
    00028 PhoneNumber::PhoneNumber() :
    00029   mType( Home )
    00030 {
    00031   init();
    00032 }
    00033
    00034 PhoneNumber::PhoneNumber( const QString &number, int type ) :
    00035   mType( type )
    00036 {
    00037   init();
    00038
    00039   validateNumber( number );
    00040 }
    00041
    00042 PhoneNumber::~PhoneNumber()
    00043 {
    00044 }
    00045
    00046 void PhoneNumber::init()
    00047 {
    00048   mId = KApplication::randomString( 8 );
    00049 }
    00050
    00051 void PhoneNumber::validateNumber( const QString &number )
    00052 {
    00053   mNumber = number;
    00054
    00055   // remove line breaks
    00056   mNumber = mNumber.replace( '\n', "" );
    00057   mNumber = mNumber.replace( '\r', "" );
    00058 }
    00059
    00060 bool PhoneNumber::operator==( const PhoneNumber &p ) const
    00061 {
    00062   if ( mNumber != p.mNumber ) return false;
    00063   if ( mType != p.mType ) return false;
    00064
    00065   return true;
    00066 }
    00067
    00068 bool PhoneNumber::operator!=( const PhoneNumber &p ) const
    00069 {
    00070   return !( p == *this );
    00071 }
    00072
    00073 void PhoneNumber::setId( const QString &id )
    00074 {
    00075   mId = id;
    00076 }
    00077
    00078 QString PhoneNumber::id() const
    00079 {
    00080   return mId;
    00081 }
    00082
    00083 void PhoneNumber::setNumber( const QString &number )
    00084 {
    00085   validateNumber( number );
    00086 }
    00087
    00088 QString PhoneNumber::number() const
    00089 {
    00090   return mNumber;
    00091 }
    00092
    00093 void PhoneNumber::setType( int type )
    00094 {
    00095   mType = type;
    00096 }
    00097
    00098 int PhoneNumber::type() const
    00099 {
    00100   return mType;
    00101 }
    00102
    00103 QString PhoneNumber::typeLabel() const
    00104 {
    00105   QString label;
    00106   bool first = true;
    00107
    00108   const TypeList list = typeList();
    00109
    00110   TypeList::ConstIterator it;
    00111   for ( it = list.begin(); it != list.end(); ++it ) {
    00112     if ( ( type() & (*it) ) && ( (*it) != Pref ) ) {
    00113       label.append( ( first ? "" : "/" ) + typeLabel( *it ) );
    00114       if ( first )
    00115         first = false;
    00116     }
    00117   }
    00118
    00119   return label;
    00120 }
    00121
    00122 QString PhoneNumber::label() const
    00123 {
    00124   return typeLabel( type() );
    00125 }
    00126
    00127 PhoneNumber::TypeList PhoneNumber::typeList()
    00128 {
    00129   static TypeList list;
    00130
    00131   if ( list.isEmpty() ) {
    00132     list << Home << Work << Msg << Pref << Voice << Fax << Cell << Video
    00133          << Bbs << Modem << Car << Isdn << Pcs << Pager;
    00134   }
    00135
    00136   return list;
    00137 }
    00138
    00139 QString PhoneNumber::label( int type )
    00140 {
    00141   return typeLabel( type );
    00142 }
    00143
    00144 QString PhoneNumber::typeLabel( int type )
    00145 {
    00146   if ( type & Pref )
    00147     return i18n( "Preferred phone", "Preferred" );
    00148
    00149   switch ( type ) {
    00150     case Home:
    00151       return i18n("Home phone", "Home");
    00152       break;
    00153     case Work:
    00154       return i18n("Work phone", "Work");
    00155       break;
    00156     case Msg:
    00157       return i18n("Messenger");
    00158       break;
    00159     case Pref:
    00160       return i18n("Preferred Number");
    00161       break;
    00162     case Voice:
    00163       return i18n("Voice");
    00164       break;
    00165     case Fax:
    00166       return i18n("Fax");
    00167       break;
    00168     case Cell:
    00169       return i18n("Mobile Phone", "Mobile" );
    00170       break;
    00171     case Video:
    00172       return i18n("Video");
    00173       break;
    00174     case Bbs:
    00175       return i18n("Mailbox");
    00176       break;
    00177     case Modem:
    00178       return i18n("Modem");
    00179       break;
    00180     case Car:
    00181       return i18n("Car Phone", "Car" );
    00182       break;
    00183     case Isdn:
    00184       return i18n("ISDN");
    00185       break;
    00186     case Pcs:
    00187       return i18n("PCS");
    00188       break;
    00189     case Pager:
    00190       return i18n("Pager");
    00191       break;
    00192     case Home | Fax:
    00193       return i18n("Home Fax");
    00194       break;
    00195     case Work | Fax:
    00196       return i18n("Work Fax");
    00197       break;
    00198     default:
    00199       return i18n("Other");
    00200   }
    00201 }
    00202
    00203 QDataStream &KABC::operator<<( QDataStream &s, const PhoneNumber &phone )
    00204 {
    00205     return s << phone.mId << phone.mType << phone.mNumber;
    00206 }
    00207
    00208 QDataStream &KABC::operator>>( QDataStream &s, PhoneNumber &phone )
    00209 {
    00210     s >> phone.mId >> phone.mType >> phone.mNumber;
    00211
    00212     return s;
    00213 }

This file is part of the documentation for kabc Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:31:30 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003