home *** CD-ROM | disk | FTP | other *** search
- //
- // $Id: ScriptTranslationTable.cc,v 1.3 2000/06/10 00:19:53 sergey Exp $
- //
-
- #include <Pilot.h>
- #include "ScriptTranslationTable.h"
- #include "PrintCardPreferences.h"
- #include "DB/AddressAppInfo.h"
- #include "DB/AdresseRecord.h"
- #include "Util/Assert.h"
-
-
- // constants
-
- static const char* PHONE_LABEL_KEYWORD = "phoneLabel";
-
- // construction
-
- ScriptTranslationTable::ScriptTranslationTable(const DB::AddressAppInfo& addressAppInfo, const DB::AdresseRecord& address, const PrintCardPreferences& preferences):
- _addressAppInfo(addressAppInfo),
- _address(address),
- _preferences(preferences)
- {}
-
- // operations
-
- const char* ScriptTranslationTable::get(const char* keyword) const
- {
- assert(keyword != 0);
-
- if (_address.isEntry(keyword))
- {
- const char* value = _address.entry(keyword);
- if (value != 0)
- return value;
- }
- else
- {
- const char* value = getPhoneLabel(keyword);
- if (value != 0)
- return value;
-
- value = getPreference(keyword);
- if (value != 0)
- return value;
- }
-
- // Returns empty string instead of null,
- // translator will replace such keywords by empty strings
- return "";
- }
-
- // implementation
-
- const char* ScriptTranslationTable::getPhoneLabel(const char* keyword) const
- {
- // format of the keyword: phoneLabel1 .. phoneLabel5
- // where last digit is an index of the phone
-
- if (StrNCompare(keyword, PHONE_LABEL_KEYWORD, StrLen(PHONE_LABEL_KEYWORD)) == 0)
- return _addressAppInfo.phoneLabel(_address.phoneEntryLabel(getPhoneEntryIndex(keyword)));
-
- return 0;
- }
-
- int ScriptTranslationTable::getPhoneEntryIndex(const char* keyword) const
- {
- // labels are 1..5
- return StrAToI(keyword+StrLen(PHONE_LABEL_KEYWORD))-1;
- }
-
- const char* ScriptTranslationTable::getPreference(const char* keyword) const
- {
- if (StrCompare("frameHeight", keyword) == 0)
- return StrIToA(_numBuffer, _preferences.frameHeight());
-
- if (StrCompare("frameWidth", keyword) == 0)
- return StrIToA(_numBuffer, _preferences.frameWidth());
-
- if (StrCompare("frameMargin", keyword) == 0)
- return StrIToA(_numBuffer, _preferences.frameMargin());
-
- if (StrCompare("scaleX", keyword) == 0)
- return StrIToA(_numBuffer, _preferences.scaleX());
-
- if (StrCompare("scaleY", keyword) == 0)
- return StrIToA(_numBuffer, _preferences.scaleY());
-
- if (StrCompare("oneCopy", keyword) == 0)
- return _preferences.oneCopy()? "true" : "false";
-
- return 0;
- }
-