# kabc Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | 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 ), mNumber( number )
    00036 {
    00037   init();
    00038 }
    00039
    00040 PhoneNumber::~PhoneNumber()
    00041 {
    00042 }
    00043
    00044 void PhoneNumber::init()
    00045 {
    00046   mId = KApplication::randomString(8);
    00047 }
    00048
    00049 bool PhoneNumber::operator==( const PhoneNumber &p ) const
    00050 {
    00051   if ( mNumber != p.mNumber ) return false;
    00052   if ( mType != p.mType ) return false;
    00053
    00054   return true;
    00055 }
    00056
    00057 bool PhoneNumber::operator!=( const PhoneNumber &p ) const
    00058 {
    00059   return !( p == *this );
    00060 }
    00061
    00062 void PhoneNumber::setId( const QString &id )
    00063 {
    00064   mId = id;
    00065 }
    00066
    00067 QString PhoneNumber::id() const
    00068 {
    00069   return mId;
    00070 }
    00071
    00072 void PhoneNumber::setNumber( const QString &number )
    00073 {
    00074   mNumber = number;
    00075 }
    00076
    00077 QString PhoneNumber::number() const
    00078 {
    00079   return mNumber;
    00080 }
    00081
    00082 void PhoneNumber::setType( int type )
    00083 {
    00084   mType = type;
    00085 }
    00086
    00087 int PhoneNumber::type() const
    00088 {
    00089   return mType;
    00090 }
    00091
    00092 QString PhoneNumber::typeLabel() const
    00093 {
    00094   QString label;
    00095   bool first = true;
    00096
    00097   TypeList list = typeList();
    00098
    00099   TypeList::Iterator it;
    00100   for ( it = list.begin(); it != list.end(); ++it ) {
    00101     if ( ( type() & (*it) ) && ( (*it) != Pref ) ) {
    00102       label.append( ( first ? "" : "/" ) + typeLabel( *it ) );
    00103       if ( first )
    00104         first = false;
    00105     }
    00106   }
    00107
    00108   return label;
    00109 }
    00110
    00111 QString PhoneNumber::label() const
    00112 {
    00113   return typeLabel( type() );
    00114 }
    00115
    00116 PhoneNumber::TypeList PhoneNumber::typeList()
    00117 {
    00118   TypeList list;
    00119
    00120   list << Home << Work << Msg << Pref << Voice << Fax << Cell << Video
    00121        << Bbs << Modem << Car << Isdn << Pcs << Pager;
    00122
    00123   return list;
    00124 }
    00125
    00126 QString PhoneNumber::label( int type )
    00127 {
    00128   return typeLabel( type );
    00129 }
    00130
    00131 QString PhoneNumber::typeLabel( int type )
    00132 {
    00133   switch ( type ) {
    00134     case Home:
    00135       return i18n("Home phone", "Home");
    00136       break;
    00137     case Work:
    00138       return i18n("Work phone", "Work");
    00139       break;
    00140     case Msg:
    00141       return i18n("Messenger");
    00142       break;
    00143     case Pref:
    00144       return i18n("Preferred Number");
    00145       break;
    00146     case Voice:
    00147       return i18n("Voice");
    00148       break;
    00149     case Fax:
    00150       return i18n("Fax");
    00151       break;
    00152     case Cell:
    00153       return i18n("Mobile Phone", "Mobile" );
    00154       break;
    00155     case Video:
    00156       return i18n("Video");
    00157       break;
    00158     case Bbs:
    00159       return i18n("Mailbox");
    00160       break;
    00161     case Modem:
    00162       return i18n("Modem");
    00163       break;
    00164     case Car:
    00165       return i18n("Car Phone", "Car" );
    00166       break;
    00167     case Isdn:
    00168       return i18n("ISDN");
    00169       break;
    00170     case Pcs:
    00171       return i18n("PCS");
    00172       break;
    00173     case Pager:
    00174       return i18n("Pager");
    00175       break;
    00176     case Home | Fax:
    00177       return i18n("Home Fax");
    00178       break;
    00179     case Work | Fax:
    00180       return i18n("Work Fax");
    00181       break;
    00182     default:
    00183       return i18n("Other");
    00184   }
    00185 }
    00186
    00187 QDataStream &KABC::operator<<( QDataStream &s, const PhoneNumber &phone )
    00188 {
    00189     return s << phone.mId << phone.mType << phone.mNumber;
    00190 }
    00191
    00192 QDataStream &KABC::operator>>( QDataStream &s, PhoneNumber &phone )
    00193 {
    00194     s >> phone.mId >> phone.mType >> phone.mNumber;
    00195
    00196     return s;
    00197 }

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:29:20 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001