diff --git a/src/CBLocale.h b/src/CBLocale.h index 96cf91e..df8469a 100644 --- a/src/CBLocale.h +++ b/src/CBLocale.h @@ -30,10 +30,6 @@ class Locale { status_t StringToDate(const char* instring, time_t& date); void NumberToCurrency(const Fixed& number, BString& string); - void SetDateFormat(const date_format& format); - - date_format DateFormat(void) const { return fDateFormat; } - void SetCurrencySymbol(const char* symbol); const char* CurrencySymbol(void) const { return fCurrencySymbol.String(); } @@ -54,10 +50,6 @@ class Locale { uint8 CurrencyDecimalPlace(void) const { return fCurrencyDecimalPlace; } - void SetDateSeparator(const char* symbol); - - const char* DateSeparator(void) const { return fDateSeparator.String(); } - void SetDST(const bool& value); bool UseDST(void) const { return fUseDST; } @@ -69,14 +61,10 @@ class Locale { status_t ConstructDateStringMDY(const char* in, BString& out); status_t ConstructDateStringDMY(const char* in, BString& out); - // Like BeFinancial, we just use two different date formats: mmddyyyy (0) and - // ddmmyyyy (1) - date_format fDateFormat; BString fCurrencySymbol; bool fPrefixSymbol; BString fCurrencySeparator; BString fCurrencyDecimal; - BString fDateSeparator; uint8 fCurrencyDecimalPlace; bool fUseDST; }; @@ -86,7 +74,6 @@ void ShowBug(const char* string); void GetVersionString(BString& string); void CapitalizeEachWord(BString& string); const char* GetCurrencyOnlyMask(void); -const char* GetDateOnlyMask(void); void IllegalCharsToEntities(BString* string); #endif diff --git a/src/Database.cpp b/src/Database.cpp index 7ca2260..a47f723 100644 --- a/src/Database.cpp +++ b/src/Database.cpp @@ -558,11 +558,11 @@ Database::SetAccountLocale(const uint32& accountid, const Locale& data) command << accountid << ";"; CppSQLite3Query query = DBQuery(command.String(), "Database::SetAccountLocale:find accountid"); + // Todo: remove table columns for date format if (query.eof()) { - command << "insert into accountlocale values(" << accountid << ",'" - << (data.DateFormat() == DATE_DMY ? "ddmmyyyy" : "mmddyyyy") << "','" - << data.DateSeparator() << "','" << data.CurrencySymbol() << "','" - << data.CurrencySeparator() << "','" << data.CurrencyDecimal() << "','" + command << "insert into accountlocale values(" << accountid << ",'ddmmyyyy','/','" + << data.CurrencySymbol() << "','" << data.CurrencySeparator() << "','" + << data.CurrencyDecimal() << "','" << (data.IsCurrencySymbolPrefix() ? "true" : "false") << "');"; DBCommand(command.String(), "Database::SetAccountLocale:insert into accountlocale"); UNLOCK; @@ -572,13 +572,12 @@ Database::SetAccountLocale(const uint32& accountid, const Locale& data) query.finalize(); // This already has the locale data in the table, so we'll just update it and return - command << "update accountlocale set dateformat = '" - << (data.DateFormat() == 1 ? "ddmmyyyy" : "mmddyyyy") - << "' where accountid = " << accountid << ";"; + command << "update accountlocale set dateformat = 'ddmmyyyy' where accountid = " << accountid + << ";"; DBCommand(command.String(), "Database::SetAccountLocale:update dateformat"); - command << "update accountlocale set dateseparator = '" << data.DateSeparator() - << "' where accountid = " << accountid << ";"; + command << "update accountlocale set dateseparator = '/' where accountid = " << accountid + << ";"; DBCommand(command.String(), "Database::SetAccountLocale:update dateseparator"); command << "update accountlocale set currencysymbol = '" << data.CurrencySymbol() @@ -615,8 +614,6 @@ Database::LocaleForAccount(const uint32& id) } BString temp = query.getStringField(1); - locale.SetDateFormat((temp.Compare("ddmmyyyy") == 0) ? DATE_DMY : DATE_MDY); - locale.SetDateSeparator(query.getStringField(2)); locale.SetCurrencySymbol(query.getStringField(3)); locale.SetCurrencySeparator(query.getStringField(4)); locale.SetCurrencyDecimal(query.getStringField(5)); @@ -633,13 +630,6 @@ Database::SetDefaultLocale(const Locale& data) BString command; // This already has the locale data in the table, so we'll just update it and return - command << "update defaultlocale set dateformat = '" - << (data.DateFormat() == DATE_MDY ? "mmddyyyy" : "ddmmyyyy") << "';"; - DBCommand(command.String(), "Database::SetAccountLocale:update dateformat"); - - command << "update defaultlocale set dateseparator = '" << data.DateSeparator() << "';"; - DBCommand(command.String(), "Database::SetAccountLocale:update dateseparator"); - command << "update defaultlocale set currencysymbol = '" << data.CurrencySymbol() << "';"; DBCommand(command.String(), "Database::SetAccountLocale:update currencysymbol"); @@ -672,8 +662,6 @@ Database::GetDefaultLocale(void) } BString temp = query.getStringField(0); - locale.SetDateFormat((temp.Compare("ddmmyyyy") == 0) ? DATE_DMY : DATE_MDY); - locale.SetDateSeparator(query.getStringField(1)); locale.SetCurrencySymbol(query.getStringField(2)); locale.SetCurrencySeparator(query.getStringField(3)); locale.SetCurrencyDecimal(query.getStringField(4)); diff --git a/src/DateBox.cpp b/src/DateBox.cpp index 9ae0f80..913b779 100644 --- a/src/DateBox.cpp +++ b/src/DateBox.cpp @@ -62,14 +62,6 @@ DateBoxFilter::KeyFilter(const int32& key, const int32& mod) box->TextView()->SelectAll(); TextControl()->Invoke(); return B_SKIP_MESSAGE; - } else if (keystring == "-") { - if (strlen(box->Text()) > 0) - box->fCurrentDate = DecrementDateByDay(box->fCurrentDate); - gDefaultLocale.DateToString(box->fCurrentDate, string); - box->SetText(string.String()); - box->TextView()->SelectAll(); - TextControl()->Invoke(); - return B_SKIP_MESSAGE; } else if (key == B_PAGE_UP) { if (strlen(box->Text()) > 0) { if (mod & B_SHIFT_KEY) @@ -106,9 +98,8 @@ DateBox::DateBox(const char* name, const char* label, const char* text, BMessage SetFilter(new DateBoxFilter(this)); fCurrentDate = GetCurrentDate(); - const char date_disallowed[] = - "`~!@#$%^&*()_=QWERTYUIOP{[}]|\\ASDFGHJKL;:'\"" - "ZXCVBNM,.<>?qwertyuiopasdfghjklzxcvbnm"; + const char date_disallowed[] = "`~!@#$%^&*()_=QWERTYUIOP{[}]|\\ASDFGHJKL;:'\"" + "ZXCVBNM,<>?qwertyuiopasdfghjklzxcvbnm"; int32 i = 0; while (date_disallowed[i]) { TextView()->DisallowChar(date_disallowed[i]); diff --git a/src/Locale.cpp b/src/Locale.cpp index b5f8bd8..6154184 100644 --- a/src/Locale.cpp +++ b/src/Locale.cpp @@ -1,5 +1,8 @@ +#include "App.h" +#include "CBLocale.h" #include #include +#include #include #include #include @@ -10,8 +13,6 @@ #include #include #include -#include "App.h" -#include "CBLocale.h" #undef B_TRANSLATION_CONTEXT #define B_TRANSLATION_CONTEXT "Locale" @@ -33,11 +34,12 @@ Locale::operator!=(const Locale& other) const bool Locale::operator==(const Locale& other) const { - if (fDateFormat != other.fDateFormat || fCurrencySymbol != other.fCurrencySymbol || - fPrefixSymbol != other.fPrefixSymbol || fCurrencySeparator != other.fCurrencySeparator || - fCurrencyDecimal != other.fCurrencyDecimal || fDateSeparator != other.fDateSeparator || - fCurrencyDecimalPlace != other.fCurrencyDecimalPlace || fUseDST != other.fUseDST) + if (fCurrencySymbol != other.fCurrencySymbol || fPrefixSymbol != other.fPrefixSymbol + || fCurrencySeparator != other.fCurrencySeparator + || fCurrencyDecimal != other.fCurrencyDecimal + || fCurrencyDecimalPlace != other.fCurrencyDecimalPlace || fUseDST != other.fUseDST) { return false; + } return true; } @@ -46,15 +48,11 @@ Locale::Flatten(BFile* file) { BString str("\t\n"); - if (fDateFormat == DATE_MDY) - str << "\t\t\n"; - else - str << "\t\t\n"; + str << "\t\t\n"; str << "\t\t\n"; str << "\t\t\n"; str << "\t\t\n"; - str << "\t\t\n"; if (!fPrefixSymbol) str << "\t\t\n"; @@ -157,565 +155,30 @@ Locale::PremultipliedStringToCurrency(const char* string, Fixed& amount) status_t Locale::DateToString(time_t date, BString& string) { - char buffer[10]; - struct tm* timestruct = localtime(&date); - BString datestr; - - if (fDateFormat == DATE_MDY) - strftime(buffer, 10, "%m", timestruct); - else if (fDateFormat == DATE_DMY) - strftime(buffer, 10, "%d", timestruct); - - datestr += buffer; - datestr += fDateSeparator; - if (fDateFormat == DATE_MDY) - strftime(buffer, 10, "%d", timestruct); - else if (fDateFormat == DATE_DMY) - strftime(buffer, 10, "%m", timestruct); - - datestr += buffer; - datestr += fDateSeparator; - strftime(buffer, 10, "%Y", timestruct); - datestr += buffer; - string = datestr; - - return B_OK; -} - -status_t -Locale::ConstructDateStringDMY(const char* in, BString& out) -{ - // This constructs a proper date string given a list of numbers - if (!in) - return B_ERROR; - - int32 length = strlen(in); - int num = 0, num2 = 0; - char charstring[3]; - charstring[1] = '\0'; - charstring[2] = '\0'; - - switch (length) { - case 2: // DM - { - out = in; - out.Insert(fDateSeparator, 1); - break; - } - case 3: - case 5: - case 7: - { - // DDM - 0: 0-3, 1: 0-9 (0-1 if digit 0 == 3), 2: 1-9 - // DMM - 0: 1-9, 1: 0-1, 2: 0-9 (0-2 if digit 1 == 1) - // DDMYYYY - see above + year - // DMMYYYY - see above + year - bool ddm = false; - charstring[0] = in[0]; - num = atoi(charstring); - - if (num > 3) - ddm = false; - else if (num < 1) - ddm = true; - else { - // [1-3]xx. - charstring[0] = in[1]; - num2 = atoi(charstring); - - if (num == 3) { - if (num2 > 1) - ddm = false; - else - ddm = true; - } else if (num2 > 1) - ddm = true; - else if (num2 == 0) { - // Although we can't say for sure, it's unlikely that the user entered a leading - // zero for the month. - ddm = true; - } else { - // [1-2][0-1]x. - charstring[0] = in[2]; - num = atoi(charstring); - - if (num == 0) - ddm = false; - else if (num > 2) - ddm = true; - else { - // Getting this far means that [1-2]1[1-2] or stuff like 1/12, 2/12, 11/2, - // or 21/2 As a result, we will choose the earlier result - ddm. - ddm = true; - } - } - } - - out = in; - if (ddm) - out.Insert(fDateSeparator, 2); - else - out.Insert(fDateSeparator, 1); - break; - } - case 4: - { - // DDMM - 0: 0-3, 1: 0-9 (0-1, if digit 0 is 3), 2: 0-1, 3: 0-9 - // DMYY - 0: 1-9, 1: 1-9, 2-3: 0-9 - bool ddmm = false; - charstring[0] = in[0]; - num = atoi(charstring); - - if (num > 3) - ddmm = false; - else if (num == 0) - ddmm = true; - else { - charstring[0] = in[1]; - num2 = atoi(charstring); - - if (num == 3) { - if (num2 > 1) - ddmm = false; - else - ddmm = true; - } else if (num2 == 0) - ddmm = true; - else { - // [1-2][1-2]xx - charstring[0] = in[2]; - num = atoi(charstring); - - // at this point, it's tough to figure which, but it's more likely that - // if digit 2 is 0 or 9, it's a year and DDMM otherwise - if (num == 0 || num == 9) - ddmm = false; - else - ddmm = true; - } - } - - out = in; - if (ddmm) - out.Insert(fDateSeparator, 2); - else { - out.Insert(fDateSeparator, 1); - out.Insert(fDateSeparator, 2); - } - - break; - } - case 6: - { - // DDMMYY - 0: 0-3, 1: 0-9 (0-1 if digit 0 == 3), 2: 0-1, 3: 0-9 (0-2 if digit 2 == 1), - // 4-5: 0-9 - // DMYYYY - 0: 1-9, 1: 1-9, 2-5: 0-9 - bool ddmm = false; - charstring[0] = in[0]; - num = atoi(charstring); - - if (num == 0) - ddmm = false; - else { - charstring[0] = in[1]; - num2 = atoi(charstring); - - if (num == 3) { - if (num2 > 1) - ddmm = false; - else if (num2 == 0) - ddmm = true; - else { - // We're in one of those "can't really tell" places, but we can - // guess based on the the next two numbers. If they are '19' or '20', - // we'll go with dmyyyy. - if ((in[2] == '1' && in[3] == '9') || (in[2] == '2' && in[3] == '0')) { - ddmm = false; - } else - ddmm = true; - } - } else { - // Getting this far, we know that [1-9][1-9]xxxx - charstring[0] = in[2]; - num = atoi(charstring); - if (num > 1) - ddmm = false; - else { - charstring[0] = in[3]; - num2 = atoi(charstring); - - if (num == 1) { - if (num2 > 2) - ddmm = false; - else - ddmm = true; - } else { - // At this point, we have [1-9][1-9]0xxx. We'll check to see if - // digit 3 is 0, but if it happens to be nonzero, it's a little - // hard to definitively know which the user meant. Of course, it - // is probably ddmmyy format. - if (num2 == 0) - ddmm = false; - else - ddmm = true; - } - } - } - } - - out = in; - if (ddmm) { - out.Insert(fDateSeparator, 2); - out.Insert(fDateSeparator, 5); - } else { - out.Insert(fDateSeparator, 1); - out.Insert(fDateSeparator, 3); - } - break; - } - case 8: // DDMMYYYY. Simple to handle - { - out = in; - out.Insert(fDateSeparator, 2); - out.Insert(fDateSeparator, 5); - break; - } - default: - { - return B_ERROR; - break; - } - } - return B_OK; -} - -status_t -Locale::ConstructDateStringMDY(const char* in, BString& out) -{ - // This constructs a proper date string given a list of numbers - if (!in) - return B_ERROR; - - int32 length = strlen(in); - - /* - Possible date formats (with numbers only): - - M, D - almost impossible to differentiate. Not supported - DD - impossible to differentiate from MD. Not supported. - - MD - all dates acceptable. Very easy. - - MDD - 0: 1-9, 1: 1-3, 2: 0-9 (0-1 when digit 1 is 3) - MMD - 0: 0-1, 1: 0-2, 2: 1-9 - - MMDD - 0: 0-1, 1: 0-2, 3: 1-3, 4: 0-9 - MDYY - 0: 1-9, 1: 1-9, 3: 0-9, 4: 0-9 - - MDDYY - MMDYY - - MMDDYY - MDYYYY - - MDDYYYY - MMDYYYY - - MMDDYYYY - */ - int num = 0; - char charstring[3]; - charstring[1] = '\0'; - charstring[2] = '\0'; - - out = in; - - switch (length) { - case 2: // MD - { - out.Insert(fDateSeparator, 1); - break; - } - case 3: // MDD, MMD. Overlap when [1][1-2][0-9]. When there is overlap, assume the earlier - // date. - case 5: // MDDYY, MMDYY - case 7: // MMDYYYY, MDDYYYY - { - // MDD - 0: 1-9, 1: 1-3, 2: 0-9 (0-1 if digit 1 == 3) - // MMD - 0: 0-1, 1: 0-9 (1-9 if digit 0 == 0), 2: 0-9 - bool mdd = false; - charstring[0] = in[0]; - num = atoi(charstring); - - if (num > 1) - mdd = true; - else if (num < 1) - mdd = false; - else { - // So far, the first digit is a one, so it could be either. - charstring[0] = in[1]; - num = atoi(charstring); - - if (num == 0) - mdd = false; - else if (num == 3) - mdd = true; - else { - // We got this far, so there is no possible way to know for sure which it is. - // Possible dates: 1/1x, 1/2x, 11/x, 12/x - // As a result, we will choose the earlier date, which means mdd=true. - mdd = true; - } - } - - if (mdd) - out.Insert(fDateSeparator, 1); - else - out.Insert(fDateSeparator, 2); - - break; - } - case 4: // MDYY, MMDD - { - // MMDD - 0: 0-1, 1: 0-2, 3: 1-3, 4: 0-9 (0-1 if digit 3 == 3) - // MDYY - 0: 1-9, 1: 1-9, 3: 0-9, 4: 0-9 - bool mdyy = false; - - charstring[0] = in[0]; - num = atoi(charstring); - - if (num > 1) - mdyy = true; - else if (num == 0) - mdyy = false; - else { - // First number = 1 - charstring[0] = in[1]; - num = atoi(charstring); - - if (num > 2) - mdyy = true; - else if (num == 0) - mdyy = false; - else { - // Second number is 1 or 2. - charstring[0] = in[2]; - num = atoi(charstring); - if (num == 0 || num > 3) - mdyy = true; - else if (num == 3) { - // Date is 1[1,2]3x. Chances are that we can't tell, but if x>1, it's mdyy. - charstring[0] = in[3]; - num = atoi(charstring); - if (num > 1) - mdyy = true; - else { - // Getting this far means we can't tell. Date is in format 1[1,2]3[0,1] - // This means we have no idea. Considering the liklihood that the user - // is entering a date in the year 1930 or 1931 is relatively small, we - // choose mmdd - mdyy = false; - } - } else { - // Getting this far means we can't tell. Date is in format 1[1,2][1,2]x - // Example dates: 1124 could be either 1/1/24 or 11/24. Just as above, the - // user probably means MM/DD because of when this code is written. - mdyy = false; - } - } - } - - if (mdyy) { - out.Insert(fDateSeparator, 1); - out.Insert(fDateSeparator, 3); - } else - out.Insert(fDateSeparator, 2); - break; - } - case 6: // MDYYYY, MMDDYY - { - // MDYYYY - 0: 1-9, 1: 1-9, 2-5: 0-9 - // MMDDYY - 0: 0-1, 1: 0-9 (1-9 if digit 0 == 0), 2: 0-3, 3: 0-9 (0-1 if digit 2 == 3), - // 4-5: 0-9 - bool mmddyy = false; - charstring[0] = in[0]; - num = atoi(charstring); - - if (num > 1) - mmddyy = false; - else { - // [0-1]xxxxx - charstring[0] = in[1]; - num = atoi(charstring); - - if (num == 0) - mmddyy = true; - else { - // At this point we're dealing with 01xxxx or 11xxxx. We need to see if digits 2 - // & 3 are a date. - charstring[0] = in[2]; - num = atoi(charstring); - if (num > 3) - mmddyy = false; - else if (num == 3) { - // Either 013xxx or 113xxx. If digit 3 > 1, then it's mdyyyy - charstring[0] = in[3]; - num = atoi(charstring); - if (num > 1) - mmddyy = false; - else - mmddyy = true; - } else if (num == 0) { - // It's *much* less likely that the user will type in a year with a leading - // zero, so choose mmddyy - mmddyy = true; - } else { - // 01[1-2]xxx or 11[1-2]xxx. At this point, it's not possible to tell for - // sure which it is, but probability points to x119xx or x120xx if it's a - // year. Otherwise, we'll assume mmddyy - charstring[0] = in[3]; - uint8 num2 = atoi(charstring); - if (num == 1) { - if (num2 == 9) - mmddyy = false; - else - mmddyy = true; - } else if (num == 2) { - if (num2 == 0) - mmddyy = false; - else - mmddyy = true; - } else - mmddyy = true; - } - } - } - - if (mmddyy) { - out.Insert(fDateSeparator, 2); - out.Insert(fDateSeparator, 5); - } else { - out.Insert(fDateSeparator, 1); - out.Insert(fDateSeparator, 4); - } - break; - } - case 8: // MMDDYYYY. Simple to handle - { - out = in; - out.Insert(fDateSeparator, 2); - out.Insert(fDateSeparator, 5); - break; - } - default: // M, D, other unsupported lengths - { - return B_ERROR; - break; - } - } - - return B_OK; + BDateFormat dateFormatter; + return dateFormatter.Format(string, date, B_SHORT_DATE_FORMAT); } status_t Locale::StringToDate(const char* instring, time_t& date) { - // Input recognized for MM/DD/YY: - // 1) MM/DD - // 2) MM/DD/YYYY - // 3) MM/DD//YY - // 4) M/D/YY - // 5) M/DD/YYYY - - if (!instring || (fDateFormat != DATE_MDY && fDateFormat != DATE_DMY)) + if (instring == NULL) return B_BAD_VALUE; - BString monthstr, daystr, yearstr, string = instring; - int32 index; - if (fDateFormat == DATE_MDY) { - monthstr = string; - index = monthstr.FindFirst(fDateSeparator); - if (index < 0) { - ConstructDateStringMDY(instring, string); - monthstr = string; - index = monthstr.FindFirst(fDateSeparator); - if (index < 0) - return index; - } + BDateFormat dateFormatter; + BDate parseDate; + BDateTime dateTime; + BDateTime now = BDateTime::CurrentDateTime(B_LOCAL_TIME); - monthstr.Truncate(index); - - daystr = string.String() + index + 1; - index = daystr.FindFirst(fDateSeparator); - if (index < 0) { - // This probably means that the user didn't tack the year - // onto the end. Check to see if there are 1 or 2 characters - // beyond the point of the last separator. If so, then chances are - // that it is a valid date using the current year. - if (daystr.CountChars() != 1 && daystr.CountChars() != 2) - return B_ERROR; - yearstr = ""; - } else { - daystr.Truncate(index); - yearstr = daystr.String() + index + 1; - } - } else { - daystr = string; - index = daystr.FindFirst(fDateSeparator); - if (index < 0) { - ConstructDateStringDMY(instring, string); - monthstr = string; - index = monthstr.FindFirst(fDateSeparator); - if (index < 0) - return index; - } + if (dateFormatter.Parse(instring, B_SHORT_DATE_FORMAT, parseDate) == B_OK) + dateTime.SetDate(parseDate); - daystr.Truncate(index); - - monthstr = string.String() + index + 1; - index = monthstr.FindFirst(fDateSeparator); - if (index < 0) { - // This probably means that the user didn't tack the year - // onto the end. Check to see if there are 1 or 2 characters - // beyond the point of the last separator. If so, then chances are - // that it is a valid date using the current year. - if (monthstr.CountChars() != 1 && monthstr.CountChars() != 2) - return B_ERROR; - yearstr = ""; - } else { - yearstr = monthstr.String() + index + 1; - monthstr.Truncate(index); - } - } - - struct tm timestruct; - - time_t rawtime; - time(&rawtime); - timestruct = *localtime(&rawtime); - - if (yearstr.Length() > 0) { - if (yearstr.CountChars() <= 2) { - timestruct.tm_year = atoi(yearstr.String()); - if (timestruct.tm_year < 10) - timestruct.tm_year += 100; - } else - timestruct.tm_year = atoi(yearstr.String()) - 1900; - } - timestruct.tm_sec = 1; - timestruct.tm_min = 1; - timestruct.tm_hour = 1; - timestruct.tm_mon = atoi(monthstr.String()) - 1; - timestruct.tm_mday = atoi(daystr.String()); - timestruct.tm_isdst = (fUseDST) ? 1 : 0; - time_t datestruct = mktime(×truct); - - if (datestruct == -1) { - // debugger("Error handling for StringToDate unimplemented"); - return B_ERROR; - } + // Use current date if date is 1/1/70, parse failed + if (dateTime.Time_t() <= 14400) + date = now.Time_t(); + else + date = dateTime.Time_t(); - date = datestruct; return B_OK; } @@ -743,16 +206,15 @@ Locale::NumberToCurrency(const Fixed& number, BString& string) void Locale::SetDefaults(void) { - fDateFormat = DATE_MDY; fCurrencySymbol = "$"; fPrefixSymbol = true; fCurrencySeparator = ","; fCurrencyDecimal = "."; - fDateSeparator = "/"; fCurrencyDecimalPlace = 2; fUseDST = false; } + void ShowAlert(const char* header, const char* message, alert_type type) { @@ -879,11 +341,6 @@ CapitalizeEachWord(BString& string) string.UnlockBuffer(); } -void -Locale::SetDateFormat(const date_format& format) -{ - fDateFormat = format; -} void Locale::SetCurrencySymbol(const char* symbol) @@ -918,12 +375,6 @@ Locale::SetCurrencyDecimalPlace(const uint8& place) fCurrencyDecimalPlace = place; } -void -Locale::SetDateSeparator(const char* symbol) -{ - if (symbol) - fDateSeparator = symbol; -} void Locale::SetDST(const bool& value) @@ -939,11 +390,6 @@ GetCurrencyOnlyMask(void) "à¡™∞ô¶•«»–≠œ∑鮆øπ‘¬å∫∂ƒ©Ωfi∆◊æäñ≈ç√ßñµ…÷"; } -const char* -GetDateOnlyMask(void) -{ - return "`~!@#$%^&*()_=QWERTYUIOP{[}]|\\ASDFGHJKL;:'\"ZXCVBNM,.<>?qwertyuiopasdfghjklzxcvbnm"; -} void IllegalCharsToEntities(BString* string) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 9951eec..655aefe 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -30,8 +30,6 @@ #include "ScheduleAddWindow.h" #include "ScheduleListWindow.h" #include "ScheduledExecutor.h" -#include "StringView.h" -#include "TextControl.h" #include "TransactionEditWindow.h" #include "TransferWindow.h" diff --git a/src/NetWorthReport.cpp b/src/NetWorthReport.cpp index 939f10a..0a6d06d 100644 --- a/src/NetWorthReport.cpp +++ b/src/NetWorthReport.cpp @@ -8,6 +8,7 @@ #include "TimeSupport.h" #include +#include #undef B_TRANSLATION_CONTEXT @@ -64,16 +65,9 @@ ReportWindow::ComputeNetWorth(void) char rowtitle[128]; struct tm* timestruct = localtime(&subtotal_start); - BString formatstring; - if (gCurrentLocale.DateFormat() == DATE_MDY) { - formatstring << "%m" << gCurrentLocale.DateSeparator() << "%d" - << gCurrentLocale.DateSeparator() << "%Y"; - } else { - formatstring << "%d" << gCurrentLocale.DateSeparator() << "%m" - << gCurrentLocale.DateSeparator() << "%Y"; - } - strftime(rowtitle, 128, formatstring.String(), timestruct); - accountgrid.SetRowTitle(subtotal_index, rowtitle); + BString datestring; + gDefaultLocale.DateToString(subtotal_start, datestring); + accountgrid.SetRowTitle(subtotal_index, datestring); int length = strlen(rowtitle); if (length > longestnamelength) { diff --git a/src/PrefWindow.cpp b/src/PrefWindow.cpp index 07e7895..085430e 100644 --- a/src/PrefWindow.cpp +++ b/src/PrefWindow.cpp @@ -19,10 +19,6 @@ // PrefView enum { - M_DMY_FORMAT = 'dmyf', - M_MDY_FORMAT, - M_NEW_DATE_SEPARATOR, - M_NEW_CURRENCY_SYMBOL, M_NEW_CURRENCY_SEPARATOR, M_NEW_CURRENCY_DECIMAL, @@ -44,12 +40,9 @@ PrefWindow::PrefWindow(const BRect& frame) font.SetSize(font.Size() * 1.2f); fLabel->SetFont(&font); - fDatePrefView = new DatePrefView("dateview", &gDefaultLocale); - fCurrencyPrefView = new CurrencyPrefView("dateview", &gDefaultLocale); - fOK = new BButton("okbutton", B_TRANSLATE("Cancel"), new BMessage(M_EDIT_OPTIONS)); - fOK->SetLabel(B_TRANSLATE("OK")); + fOK = new BButton("okbutton", B_TRANSLATE("OK"), new BMessage(M_EDIT_OPTIONS)); BButton* cancel = new BButton("cancelbutton", B_TRANSLATE("Cancel"), new BMessage(B_QUIT_REQUESTED)); @@ -64,7 +57,6 @@ PrefWindow::PrefWindow(const BRect& frame) .Add(fLabel) .AddGlue() .End() - .Add(fDatePrefView) .Add(fCurrencyPrefView) .AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING) .AddGlue() @@ -73,8 +65,8 @@ PrefWindow::PrefWindow(const BRect& frame) .End() .End(); // clang on - - CenterIn(Frame()); + ResizeToPreferred(); + CenterIn(frame); } void @@ -84,7 +76,6 @@ PrefWindow::MessageReceived(BMessage* msg) case M_EDIT_OPTIONS: { Locale temp = gDefaultLocale; - fDatePrefView->GetSettings(temp); fCurrencyPrefView->GetSettings(temp); if (temp != gDefaultLocale) { @@ -102,121 +93,11 @@ PrefWindow::MessageReceived(BMessage* msg) } } -DatePrefView::DatePrefView(const char* name, Locale* locale, const int32& flags) - : BView(name, flags) -{ - BString temp; - SetViewUIColor(B_PANEL_BACKGROUND_COLOR); - - if (locale) - fLocale = *locale; - else - fLocale = gDefaultLocale; - - fDateBox = new BBox("DateBox"); - - BString datestr; - fLocale.DateToString(640180800, datestr); - temp = ""; - temp.SetToFormat(B_TRANSLATE("Date format: %s"), datestr.String()); - fDateBox->SetLabel(temp.String()); - - temp = ""; - temp.SetToFormat(B_TRANSLATE("Month, Day, Year")); - fDateMDY = new BRadioButton("mdybutton", temp.String(), new BMessage(M_MDY_FORMAT)); - - temp = ""; - temp.SetToFormat(B_TRANSLATE("Day, Month, Year")); - fDateDMY = new BRadioButton("dmybutton", temp.String(), new BMessage(M_DMY_FORMAT)); - if (fLocale.DateFormat() == DATE_MDY) - fDateMDY->SetValue(B_CONTROL_ON); - else - fDateDMY->SetValue(B_CONTROL_ON); - - fDateSeparatorBox = new AutoTextControl("datesep", B_TRANSLATE("Separator:"), - fLocale.DateSeparator(), new BMessage(M_NEW_DATE_SEPARATOR)); - fDateSeparatorBox->SetDivider(StringWidth(temp.String()) + 5); - fDateSeparatorBox->SetCharacterLimit(2); - - // clang off - BLayoutBuilder::Group<>(fDateBox, B_VERTICAL, 0.0f) - .SetInsets( - B_USE_DEFAULT_SPACING, B_USE_BIG_SPACING, B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING) - .Add(fDateMDY) - .Add(fDateDMY) - .AddGroup(B_HORIZONTAL) - .Add(fDateSeparatorBox) - .AddGlue() - .End() - .End(); - - BLayoutBuilder::Group<>(this, B_VERTICAL).Add(fDateBox).End(); - // clang on -} - -void -DatePrefView::AttachedToWindow(void) -{ - fDateMDY->SetTarget(this); - fDateDMY->SetTarget(this); - fDateSeparatorBox->SetTarget(this); -} - -void -DatePrefView::MessageReceived(BMessage* msg) -{ - switch (msg->what) { - case M_DMY_FORMAT: - { - fLocale.SetDateFormat(DATE_DMY); - UpdateDateLabel(); - break; - } - case M_MDY_FORMAT: - { - fLocale.SetDateFormat(DATE_MDY); - UpdateDateLabel(); - break; - } - case M_NEW_DATE_SEPARATOR: - { - if (strlen(fDateSeparatorBox->Text()) < 1) - break; - - fLocale.SetDateSeparator(fDateSeparatorBox->Text()); - UpdateDateLabel(); - break; - } - default: - BView::MessageReceived(msg); - break; - } -} - -void -DatePrefView::UpdateDateLabel(void) -{ - BString temp, label; - fLocale.DateToString(640180800, temp); - label.SetToFormat(B_TRANSLATE("Date format: %s"), temp.String()); - fDateBox->SetLabel(label.String()); -} - -void -DatePrefView::GetSettings(Locale& locale) -{ - if (strlen(fDateSeparatorBox->Text()) > 0) - locale.SetDateSeparator(fDateSeparatorBox->Text()); - locale.SetDateFormat((fDateDMY->Value() == B_CONTROL_ON) ? DATE_DMY : DATE_MDY); -} - - CurrencyPrefView::CurrencyPrefView(const char* name, Locale* locale, const int32& flags) : BView(name, flags), fSampleAmount((long)12345678, true) { BString temp; - SetViewUIColor(B_PANEL_BACKGROUND_COLOR); if (locale) fLocale = *locale; @@ -224,6 +105,7 @@ CurrencyPrefView::CurrencyPrefView(const char* name, Locale* locale, const int32 fLocale = gDefaultLocale; fCurrencyBox = new BBox("CurrencyBox"); + BString curstr; fLocale.CurrencyToString(fSampleAmount, curstr); temp.SetToFormat(B_TRANSLATE("Currency format: %s"), curstr.String()); diff --git a/src/PrefWindow.h b/src/PrefWindow.h index 2483ba5..b2fd683 100644 --- a/src/PrefWindow.h +++ b/src/PrefWindow.h @@ -25,30 +25,11 @@ class PrefWindow : public BWindow { void MessageReceived(BMessage* msg); private: - DatePrefView* fDatePrefView; CurrencyPrefView* fCurrencyPrefView; BButton* fOK; BStringView* fLabel; }; -class DatePrefView : public BView { -public: - DatePrefView(const char* name, Locale* locale = NULL, const int32& flags = B_WILL_DRAW); - void AttachedToWindow(void); - void MessageReceived(BMessage* msg); - - void GetSettings(Locale& locale); - -private: - void UpdateDateLabel(void); - - BBox* fDateBox; - BRadioButton *fDateMDY, *fDateDMY; - AutoTextControl* fDateSeparatorBox; - - Locale fLocale; -}; - class CurrencyPrefView : public BView { public: CurrencyPrefView(const char* name, Locale* locale = NULL, const int32& flags = B_WILL_DRAW);