home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 Mobile / Chip_Mobile_2001.iso / palm / business / printcar / printcar.exe / src / ScriptTranslationTable.cc < prev    next >
C/C++ Source or Header  |  2000-06-10  |  3KB  |  94 lines

  1. //
  2. //  $Id: ScriptTranslationTable.cc,v 1.3 2000/06/10 00:19:53 sergey Exp $
  3. //
  4.  
  5. #include <Pilot.h>
  6. #include "ScriptTranslationTable.h"
  7. #include "PrintCardPreferences.h"
  8. #include "DB/AddressAppInfo.h"
  9. #include "DB/AdresseRecord.h"
  10. #include "Util/Assert.h"
  11.  
  12.  
  13. // constants
  14.  
  15. static const char* PHONE_LABEL_KEYWORD  = "phoneLabel";
  16.  
  17. // construction
  18.  
  19. ScriptTranslationTable::ScriptTranslationTable(const DB::AddressAppInfo& addressAppInfo, const DB::AdresseRecord& address, const PrintCardPreferences& preferences):
  20.     _addressAppInfo(addressAppInfo),
  21.     _address(address),
  22.     _preferences(preferences)
  23. {}
  24.  
  25. // operations
  26.  
  27. const char* ScriptTranslationTable::get(const char* keyword) const
  28. {
  29.     assert(keyword != 0);
  30.  
  31.     if (_address.isEntry(keyword))
  32.     {
  33.         const char* value = _address.entry(keyword);
  34.         if (value != 0)
  35.             return value;
  36.     }
  37.     else
  38.     {
  39.         const char* value = getPhoneLabel(keyword);
  40.         if (value != 0)
  41.             return value;
  42.  
  43.         value = getPreference(keyword);
  44.         if (value != 0)
  45.             return value;
  46.     }
  47.  
  48.     // Returns empty string instead of null,
  49.     // translator will replace such keywords by empty strings
  50.     return "";
  51. }
  52.  
  53. // implementation
  54.  
  55. const char* ScriptTranslationTable::getPhoneLabel(const char* keyword) const
  56. {
  57.     // format of the keyword:  phoneLabel1 .. phoneLabel5
  58.     // where last digit is an index of the phone
  59.  
  60.     if (StrNCompare(keyword, PHONE_LABEL_KEYWORD, StrLen(PHONE_LABEL_KEYWORD)) == 0)
  61.         return _addressAppInfo.phoneLabel(_address.phoneEntryLabel(getPhoneEntryIndex(keyword)));
  62.  
  63.     return 0;
  64. }
  65.  
  66. int ScriptTranslationTable::getPhoneEntryIndex(const char* keyword) const
  67. {
  68.     // labels are 1..5
  69.     return StrAToI(keyword+StrLen(PHONE_LABEL_KEYWORD))-1;
  70. }
  71.  
  72. const char* ScriptTranslationTable::getPreference(const char* keyword) const
  73. {
  74.     if (StrCompare("frameHeight", keyword) == 0)
  75.         return StrIToA(_numBuffer, _preferences.frameHeight());
  76.  
  77.     if (StrCompare("frameWidth", keyword) == 0)
  78.         return StrIToA(_numBuffer, _preferences.frameWidth());
  79.  
  80.     if (StrCompare("frameMargin", keyword) == 0)
  81.         return StrIToA(_numBuffer, _preferences.frameMargin());
  82.  
  83.     if (StrCompare("scaleX", keyword) == 0)
  84.         return StrIToA(_numBuffer, _preferences.scaleX());
  85.  
  86.     if (StrCompare("scaleY", keyword) == 0)
  87.         return StrIToA(_numBuffer, _preferences.scaleY());
  88.  
  89.     if (StrCompare("oneCopy", keyword) == 0)
  90.         return _preferences.oneCopy()? "true" : "false";
  91.  
  92.     return 0;
  93. }
  94.