commit 1f06b62d1edd48c61d5d5636cd75b9d80ea967e3
Author: Rick Scott <rwscott@users.sourceforge.net>
Date: Sun Apr 14 13:27:47 2013 -0400
Go one step farther to prevent mistakes such as invalid values being stored and used.
The original patch, bff155970773, changed the category type from a string
to an enum to help avoid mistakes in the future. It however meant that a
couple of string arrays, and some static int's (added later to fix the fix),
_must_ be kept in sync. This just changes the type of future mistakes.
This defines the category type in one place only.
diff --git a/mythtv/libs/libmyth/programinfo.cpp b/mythtv/libs/libmyth/programinfo.cpp
index 968a85c..d834bb6 100644
|
a
|
b
|
static void set_flag(uint32_t &flags, int flag_to_set, bool is_set)
|
| 83 | 83 | |
| 84 | 84 | QString myth_category_type_to_string(ProgramInfo::CategoryType category_type) |
| 85 | 85 | { |
| 86 | | static int NUM_CAT_TYPES = 5; |
| 87 | | static const char *cattype[] = |
| 88 | | { "", "movie", "series", "sports", "tvshow", }; |
| | 86 | #define CATEGORY_TYPE_ITEM(name, ...) \ |
| | 87 | case ProgramInfo::kCategory##name: return(QString(#name).toLower()); break; |
| 89 | 88 | |
| 90 | | if ((category_type > ProgramInfo::kCategoryNone) && |
| 91 | | ((int)category_type < NUM_CAT_TYPES)) |
| 92 | | return QString(cattype[category_type]); |
| 93 | | |
| 94 | | return ""; |
| | 89 | switch (category_type) |
| | 90 | { |
| | 91 | CATEGORY_TYPE_LIST |
| | 92 | default: |
| | 93 | return(QString("")); |
| | 94 | break; |
| | 95 | } |
| | 96 | #undef CATEGORY_TYPE_ITEM |
| 95 | 97 | } |
| 96 | 98 | |
| 97 | 99 | ProgramInfo::CategoryType string_to_myth_category_type(const QString &category_type) |
| 98 | 100 | { |
| 99 | | static int NUM_CAT_TYPES = 5; |
| 100 | | static const char *cattype[] = |
| 101 | | { "", "movie", "series", "sports", "tvshow", }; |
| | 101 | #define CATEGORY_TYPE_ITEM(name, ...) \ |
| | 102 | if (category_type == QString(#name).toLower()) \ |
| | 103 | return(ProgramInfo::kCategory##name); \ |
| | 104 | else |
| 102 | 105 | |
| 103 | | for (uint i = 1; i < NUM_CAT_TYPES; i++) |
| 104 | | if (category_type == cattype[i]) |
| 105 | | return (ProgramInfo::CategoryType) i; |
| 106 | | return ProgramInfo::kCategoryNone; |
| | 106 | CATEGORY_TYPE_LIST |
| | 107 | { |
| | 108 | return(ProgramInfo::kCategoryNone); |
| | 109 | } |
| | 110 | #undef CATEGORY_TYPE_ITEM |
| 107 | 111 | } |
| 108 | 112 | |
| 109 | 113 | /** \fn ProgramInfo::ProgramInfo(void) |
diff --git a/mythtv/libs/libmyth/programinfo.h b/mythtv/libs/libmyth/programinfo.h
index 6e8e263..cb1d827 100644
|
a
|
b
|
class MSqlQuery;
|
| 69 | 69 | class ProgramInfoUpdater; |
| 70 | 70 | class PMapDBReplacement; |
| 71 | 71 | |
| | 72 | #define CATEGORY_TYPE_LIST \ |
| | 73 | CATEGORY_TYPE_ITEM(None) \ |
| | 74 | CATEGORY_TYPE_ITEM(Movie) \ |
| | 75 | CATEGORY_TYPE_ITEM(Series) \ |
| | 76 | CATEGORY_TYPE_ITEM(Sports) \ |
| | 77 | CATEGORY_TYPE_ITEM(TVShow) |
| | 78 | |
| 72 | 79 | class MPUBLIC ProgramInfo |
| 73 | 80 | { |
| 74 | 81 | friend int pginfo_init_statics(void); |
| 75 | 82 | public: |
| 76 | | enum CategoryType { kCategoryNone, kCategoryMovie, kCategorySeries, |
| 77 | | kCategorySports, kCategoryTVShow }; |
| | 83 | #define CATEGORY_TYPE_ITEM(name, ...) kCategory##name, |
| | 84 | enum CategoryType { |
| | 85 | CATEGORY_TYPE_LIST |
| | 86 | }; |
| | 87 | #undef CATEGORY_TYPE_ITEM |
| 78 | 88 | |
| 79 | 89 | /// Null constructor |
| 80 | 90 | ProgramInfo(void); |