From 26d96ba5efe26bf4818d59b346b272a627cc239a Mon Sep 17 00:00:00 2001 From: Chris Frey Date: Tue, 1 Feb 2011 01:22:25 -0500 Subject: [PATCH] lib: added new common record function: GetDescription() GetDescription() returns a single line description for the record. Every record class is expected to have one. --- src/r_bookmark.cc | 5 +++++ src/r_bookmark.h | 3 ++- src/r_calendar.cc | 5 +++++ src/r_calendar.h | 3 ++- src/r_calllog.cc | 5 +++++ src/r_calllog.h | 3 ++- src/r_contact.cc | 5 +++++ src/r_contact.h | 3 ++- src/r_cstore.cc | 5 +++++ src/r_cstore.h | 3 ++- src/r_folder.cc | 10 +++++++++- src/r_folder.h | 4 +++- src/r_memo.cc | 4 ++++ src/r_memo.h | 3 ++- src/r_message_base.cc | 6 ++++++ src/r_message_base.h | 3 ++- src/r_servicebook.cc | 5 +++++ src/r_servicebook.h | 3 ++- src/r_sms.cc | 8 ++++++++ src/r_sms.h | 3 ++- src/r_task.cc | 5 +++++ src/r_task.h | 4 +++- src/r_timezone.cc | 12 +++++++++++- src/r_timezone.h | 4 +++- 24 files changed, 100 insertions(+), 14 deletions(-) diff --git a/src/r_bookmark.cc b/src/r_bookmark.cc index b9d7335c..b37e78bd 100644 --- a/src/r_bookmark.cc +++ b/src/r_bookmark.cc @@ -367,5 +367,10 @@ void Bookmark::Clear() Unknowns.clear(); } +std::string Bookmark::GetDescription() const +{ + return Name; +} + } // namespace Barry diff --git a/src/r_bookmark.h b/src/r_bookmark.h index 2a9fb9a8..485ef0ab 100644 --- a/src/r_bookmark.h +++ b/src/r_bookmark.h @@ -97,9 +97,10 @@ public: void ParseHeader(const Data &data, size_t &offset); void ParseFields(const Data &data, size_t &offset, const IConverter *ic = 0); + // operations (common among record classes void Clear(); - void Dump(std::ostream &os) const; + std::string GetDescription() const; // Sorting - use enough data to make the sorting as // consistent as possible diff --git a/src/r_calendar.cc b/src/r_calendar.cc index e196cc9d..063acbb1 100644 --- a/src/r_calendar.cc +++ b/src/r_calendar.cc @@ -402,6 +402,11 @@ void Calendar::Clear() Unknowns.clear(); } +std::string Calendar::GetDescription() const +{ + return Subject; +} + void Calendar::DumpSpecialFields(std::ostream &os) const { static const char *ClassTypes[] = { "Public", "Confidential", "Private" }; diff --git a/src/r_calendar.h b/src/r_calendar.h index 9f468920..dddba9b0 100644 --- a/src/r_calendar.h +++ b/src/r_calendar.h @@ -138,9 +138,10 @@ public: void BuildHeader(Data &data, size_t &offset) const; void BuildFields(Data &data, size_t &offset, const IConverter *ic = 0) const; + // operations (common among record classes) void Clear(); - void Dump(std::ostream &os) const; + std::string GetDescription() const; // sorting bool operator<(const Calendar &other) const; diff --git a/src/r_calllog.cc b/src/r_calllog.cc index fca04a38..d12a7e33 100644 --- a/src/r_calllog.cc +++ b/src/r_calllog.cc @@ -320,5 +320,10 @@ void CallLog::Clear() Unknowns.clear(); } +std::string CallLog::GetDescription() const +{ + return ContactName; +} + } // namespace Barry diff --git a/src/r_calllog.h b/src/r_calllog.h index 33b8ec1f..ae40b495 100644 --- a/src/r_calllog.h +++ b/src/r_calllog.h @@ -115,9 +115,10 @@ public: void ParseHeader(const Data &data, size_t &offset); void ParseFields(const Data &data, size_t &offset, const IConverter *ic = 0); + // operations (common among record classes) void Clear(); - void Dump(std::ostream &os) const; + std::string GetDescription() const; // Sorting bool operator<(const CallLog &other) const { return Timestamp < other.Timestamp; } diff --git a/src/r_contact.cc b/src/r_contact.cc index 683639f9..f4d2ae47 100644 --- a/src/r_contact.cc +++ b/src/r_contact.cc @@ -444,6 +444,11 @@ void Contact::Clear() m_FirstNameSeen = false; } +std::string Contact::GetDescription() const +{ + return GetFullName(); +} + // // GetFullName // diff --git a/src/r_contact.h b/src/r_contact.h index e1527ee4..8bd16796 100644 --- a/src/r_contact.h +++ b/src/r_contact.h @@ -155,9 +155,10 @@ public: void BuildHeader(Data &data, size_t &offset) const; void BuildFields(Data &data, size_t &offset, const IConverter *ic = 0) const; + // operations (common among record classes) void Clear(); // erase everything - void Dump(std::ostream &os) const; + std::string GetDescription() const; // Sorting - use enough data to make the sorting as // consistent as possible diff --git a/src/r_cstore.cc b/src/r_cstore.cc index 1aaec40e..1a616357 100644 --- a/src/r_cstore.cc +++ b/src/r_cstore.cc @@ -206,6 +206,11 @@ void ContentStore::Clear() FileSize = 0; } +std::string ContentStore::GetDescription() const +{ + return Filename; +} + void ContentStore::Dump(std::ostream &os) const { ios::fmtflags oldflags = os.setf(ios::left); diff --git a/src/r_cstore.h b/src/r_cstore.h index 8f212716..bf94fa95 100644 --- a/src/r_cstore.h +++ b/src/r_cstore.h @@ -80,9 +80,10 @@ public: ContentStore(); ~ContentStore(); - // operations + // operations (common among record classes) void Clear(); // erase everything void Dump(std::ostream &os) const; + std::string GetDescription() const; // Sorting - use enough data to make the sorting as // consistent as possible diff --git a/src/r_folder.cc b/src/r_folder.cc index d2d35a16..84bc5c88 100644 --- a/src/r_folder.cc +++ b/src/r_folder.cc @@ -27,7 +27,8 @@ #include "time.h" #include "debug.h" #include "iconv.h" -#include +#include +#include #include using namespace std; @@ -176,6 +177,13 @@ void Folder::Clear() Unknowns.clear(); } +std::string Folder::GetDescription() const +{ + ostringstream oss; + oss << Name << " (" << Level << ")"; + return oss.str(); +} + void Folder::Dump(std::ostream &os) const { static const char *FolderTypeString[] = { "Subtree", "Deleted", "Inbox", "Outbox", "Sent", "Other"}; diff --git a/src/r_folder.h b/src/r_folder.h index 4cb26811..c7e1b299 100644 --- a/src/r_folder.h +++ b/src/r_folder.h @@ -82,9 +82,11 @@ public: void ParseFields(const Data &data, size_t &offset, const IConverter *ic = 0); void BuildHeader(Data &data, size_t &offset) const; + // operations (common among record classes) void Clear(); - void Dump(std::ostream &os) const; + std::string GetDescription() const; + bool operator<(const Folder &other) const { return Name < other.Name; } // database name diff --git a/src/r_memo.cc b/src/r_memo.cc index 8b3b4363..505e5ccf 100644 --- a/src/r_memo.cc +++ b/src/r_memo.cc @@ -243,6 +243,10 @@ void Memo::Clear() Unknowns.clear(); } +std::string Memo::GetDescription() const +{ + return Title; +} } // namespace Barry diff --git a/src/r_memo.h b/src/r_memo.h index 0ddfe6e2..fc45f1cd 100644 --- a/src/r_memo.h +++ b/src/r_memo.h @@ -65,9 +65,10 @@ public: void BuildHeader(Data &data, size_t &offset) const; void BuildFields(Data &data, size_t &offset, const IConverter *ic = 0) const; + // operations (common among record classes) void Clear(); - void Dump(std::ostream &os) const; + std::string GetDescription() const; bool operator<(const Memo &other) const; diff --git a/src/r_message_base.cc b/src/r_message_base.cc index de1c5629..8679f2a2 100644 --- a/src/r_message_base.cc +++ b/src/r_message_base.cc @@ -323,6 +323,12 @@ void MessageBase::Clear() Unknowns.clear(); } +std::string MessageBase::GetDescription() const +{ + // FIXME - ponder a better description... + return Subject; +} + std::string MessageBase::SimpleFromAddress() const { if( From.size() ) { diff --git a/src/r_message_base.h b/src/r_message_base.h index b0bcd440..9c05241d 100644 --- a/src/r_message_base.h +++ b/src/r_message_base.h @@ -118,9 +118,10 @@ public: void BuildHeader(Data &data, size_t &offset) const; void BuildFields(Data &data, size_t &offset, const IConverter *ic = 0) const; + // operations (common among record classes) void Clear(); - void Dump(std::ostream &os) const; + std::string GetDescription() const; // sorting bool operator<(const MessageBase &other) const; diff --git a/src/r_servicebook.cc b/src/r_servicebook.cc index faa0dd0c..4df3c09b 100644 --- a/src/r_servicebook.cc +++ b/src/r_servicebook.cc @@ -417,6 +417,11 @@ void ServiceBook::Clear() Config.Clear(); } +std::string ServiceBook::GetDescription() const +{ + return Name; +} + inline void FormatStr(std::ostream &os, const char *name, const std::string &str) { if( str.size() ) { diff --git a/src/r_servicebook.h b/src/r_servicebook.h index 9b673fd9..bc980016 100644 --- a/src/r_servicebook.h +++ b/src/r_servicebook.h @@ -120,9 +120,10 @@ public: void BuildHeader(Data &data, size_t &offset) const; void BuildFields(Data &data, size_t &offset, const IConverter *ic = 0) const; + // operations (common among record classes) void Clear(); - void Dump(std::ostream &os) const; + std::string GetDescription() const; // sorting bool operator<(const ServiceBook &other) const; diff --git a/src/r_sms.cc b/src/r_sms.cc index 8144216e..63d0b87c 100644 --- a/src/r_sms.cc +++ b/src/r_sms.cc @@ -245,6 +245,14 @@ void Sms::Clear() Unknowns.clear(); } +std::string Sms::GetDescription() const +{ + if( Addresses.size() ) + return Addresses[0]; + else + return "Unknown destination"; +} + void Sms::Dump(std::ostream &os) const { diff --git a/src/r_sms.h b/src/r_sms.h index f434025f..409872ef 100644 --- a/src/r_sms.h +++ b/src/r_sms.h @@ -100,9 +100,10 @@ public: void ParseFields(const Data &data, size_t &offset, const IConverter *ic = 0); void BuildHeader(Data &data, size_t &offset) const; + // operations (common among record classes) void Clear(); - void Dump(std::ostream &os) const; + std::string GetDescription() const; static std::string ConvertGsmToUtf8(const std::string &); diff --git a/src/r_task.cc b/src/r_task.cc index 3f7cb7cd..584b60b9 100644 --- a/src/r_task.cc +++ b/src/r_task.cc @@ -345,6 +345,11 @@ void Task::Clear() Unknowns.clear(); } +std::string Task::GetDescription() const +{ + return Summary; +} + void Task::Dump(std::ostream &os) const { static const char *PriorityName[] = { "High", "Normal", "Low" }; diff --git a/src/r_task.h b/src/r_task.h index a74ec56d..3906136c 100644 --- a/src/r_task.h +++ b/src/r_task.h @@ -109,9 +109,11 @@ public: void BuildHeader(Data &data, size_t &offset) const; void BuildFields(Data &data, size_t &offset, const IConverter *ic = 0) const; + // operations (common among record classes) void Clear(); - void Dump(std::ostream &os) const; + std::string GetDescription() const; + bool operator<(const Task &other) const; // database name diff --git a/src/r_timezone.cc b/src/r_timezone.cc index f27be7b0..3bc472e2 100644 --- a/src/r_timezone.cc +++ b/src/r_timezone.cc @@ -27,7 +27,8 @@ #include "time.h" #include "iconv.h" #include "debug.h" -#include +#include +#include #include using namespace std; @@ -180,6 +181,15 @@ void Timezone::Clear() Unknowns.clear(); } +std::string Timezone::GetDescription() const +{ + ostringstream oss; + oss << TimeZoneName << " (" + << (Left ? "-" : "+") << dec << Offset << "." << OffsetFraction + << ")"; + return oss.str(); +} + void Timezone::Dump(std::ostream &os) const { static const char *month[] = { diff --git a/src/r_timezone.h b/src/r_timezone.h index 090442ab..5845b78a 100644 --- a/src/r_timezone.h +++ b/src/r_timezone.h @@ -72,9 +72,11 @@ public: void ParseFields(const Data &data, size_t &offset, const IConverter *ic = 0); void BuildHeader(Data &data, size_t &offset) const; + // operations (common among record classes) void Clear(); - void Dump(std::ostream &os) const; + std::string GetDescription() const; + bool operator<(const Timezone &other) const { return TimeZoneName < other.TimeZoneName; } // database name -- 2.11.4.GIT