TDE core libraries
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

phonenumber.cpp 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*
  2. This file is part of libtdeabc.
  3. Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public
  6. License as published by the Free Software Foundation; either
  7. version 2 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public License
  13. along with this library; see the file COPYING.LIB. If not, write to
  14. the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  15. Boston, MA 02110-1301, USA.
  16. */
  17. #include <tdeapplication.h>
  18. #include <tdelocale.h>
  19. #include "phonenumber.h"
  20. using namespace TDEABC;
  21. PhoneNumber::PhoneNumber() :
  22. mType( Home )
  23. {
  24. init();
  25. }
  26. PhoneNumber::PhoneNumber( const TQString &number, int type ) :
  27. mType( type )
  28. {
  29. init();
  30. validateNumber( number );
  31. }
  32. PhoneNumber::~PhoneNumber()
  33. {
  34. }
  35. void PhoneNumber::init()
  36. {
  37. mId = TDEApplication::randomString( 8 );
  38. }
  39. void PhoneNumber::validateNumber( const TQString &number )
  40. {
  41. mNumber = number;
  42. // remove line breaks
  43. mNumber = mNumber.replace( '\n', "" );
  44. mNumber = mNumber.replace( '\r', "" );
  45. }
  46. bool PhoneNumber::operator==( const PhoneNumber &p ) const
  47. {
  48. if ( mNumber != p.mNumber ) return false;
  49. if ( mType != p.mType ) return false;
  50. return true;
  51. }
  52. bool PhoneNumber::operator!=( const PhoneNumber &p ) const
  53. {
  54. return !( p == *this );
  55. }
  56. void PhoneNumber::setId( const TQString &id )
  57. {
  58. mId = id;
  59. }
  60. TQString PhoneNumber::id() const
  61. {
  62. return mId;
  63. }
  64. void PhoneNumber::setNumber( const TQString &number )
  65. {
  66. validateNumber( number );
  67. }
  68. TQString PhoneNumber::number() const
  69. {
  70. return mNumber;
  71. }
  72. void PhoneNumber::setType( int type )
  73. {
  74. mType = type;
  75. }
  76. int PhoneNumber::type() const
  77. {
  78. return mType;
  79. }
  80. TQString PhoneNumber::typeLabel() const
  81. {
  82. TQString label;
  83. bool first = true;
  84. const TypeList list = typeList();
  85. TypeList::ConstIterator it;
  86. for ( it = list.begin(); it != list.end(); ++it ) {
  87. if ( ( type() & (*it) ) && ( (*it) != Pref ) ) {
  88. label.append( ( first ? "" : "/" ) + typeLabel( *it ) );
  89. if ( first )
  90. first = false;
  91. }
  92. }
  93. return label;
  94. }
  95. TQString PhoneNumber::label() const
  96. {
  97. return typeLabel( type() );
  98. }
  99. PhoneNumber::TypeList PhoneNumber::typeList()
  100. {
  101. static TypeList list;
  102. if ( list.isEmpty() ) {
  103. list << Home << Work << Msg << Pref << Voice << Fax << Cell << Video
  104. << Bbs << Modem << Car << Isdn << Pcs << Pager;
  105. }
  106. return list;
  107. }
  108. TQString PhoneNumber::label( int type )
  109. {
  110. return typeLabel( type );
  111. }
  112. TQString PhoneNumber::typeLabel( int type )
  113. {
  114. if ( type & Pref )
  115. return i18n( "Preferred phone", "Preferred" );
  116. switch ( type ) {
  117. case Home:
  118. return i18n("Home phone", "Home");
  119. break;
  120. case Work:
  121. return i18n("Work phone", "Work");
  122. break;
  123. case Msg:
  124. return i18n("Messenger");
  125. break;
  126. case Pref:
  127. return i18n("Preferred Number");
  128. break;
  129. case Voice:
  130. return i18n("Voice");
  131. break;
  132. case Fax:
  133. return i18n("Fax");
  134. break;
  135. case Cell:
  136. return i18n("Mobile Phone", "Mobile" );
  137. break;
  138. case Video:
  139. return i18n("Video");
  140. break;
  141. case Bbs:
  142. return i18n("Mailbox");
  143. break;
  144. case Modem:
  145. return i18n("Modem");
  146. break;
  147. case Car:
  148. return i18n("Car Phone", "Car" );
  149. break;
  150. case Isdn:
  151. return i18n("ISDN");
  152. break;
  153. case Pcs:
  154. return i18n("PCS");
  155. break;
  156. case Pager:
  157. return i18n("Pager");
  158. break;
  159. case Home | Fax:
  160. return i18n("Home Fax");
  161. break;
  162. case Work | Fax:
  163. return i18n("Work Fax");
  164. break;
  165. default:
  166. return i18n("Other");
  167. }
  168. }
  169. TQDataStream &TDEABC::operator<<( TQDataStream &s, const PhoneNumber &phone )
  170. {
  171. return s << phone.mId << phone.mType << phone.mNumber;
  172. }
  173. TQDataStream &TDEABC::operator>>( TQDataStream &s, PhoneNumber &phone )
  174. {
  175. s >> phone.mId >> phone.mType >> phone.mNumber;
  176. return s;
  177. }