PageRenderTime 22ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/task-2.0.0/src/legacy.cpp

#
C++ | 214 lines | 147 code | 27 blank | 40 comment | 47 complexity | f14363ff7b10a6c342173c043f2be47c MD5 | raw file
  1. ////////////////////////////////////////////////////////////////////////////////
  2. // taskwarrior - a command line task list manager.
  3. //
  4. // Copyright 2006-2012, Paul Beckingham, Federico Hernandez.
  5. //
  6. // Permission is hereby granted, free of charge, to any person obtaining a copy
  7. // of this software and associated documentation files (the "Software"), to deal
  8. // in the Software without restriction, including without limitation the rights
  9. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. // copies of the Software, and to permit persons to whom the Software is
  11. // furnished to do so, subject to the following conditions:
  12. //
  13. // The above copyright notice and this permission notice shall be included
  14. // in all copies or substantial portions of the Software.
  15. //
  16. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  17. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. // SOFTWARE.
  23. //
  24. // http://www.opensource.org/licenses/mit-license.php
  25. //
  26. ////////////////////////////////////////////////////////////////////////////////
  27. #define L10N // Localization complete.
  28. #include <sstream>
  29. #include <Context.h>
  30. #include <text.h>
  31. #include <i18n.h>
  32. extern Context context;
  33. ////////////////////////////////////////////////////////////////////////////////
  34. void legacyAttributeCheck (const std::string& name)
  35. {
  36. // Legacy checks.
  37. if (name == "fg" || name == "bg")
  38. context.footnote (format (STRING_LEGACY_FEATURE, name));
  39. }
  40. ////////////////////////////////////////////////////////////////////////////////
  41. void legacyColumnMap (std::string& name)
  42. {
  43. // One-time initialization, on demand.
  44. static std::map <std::string, std::string> legacyMap;
  45. if (! legacyMap.size ())
  46. {
  47. legacyMap["priority_long"] = "priority.long"; // Deprecated.
  48. legacyMap["entry_time"] = "entry"; // Deprecated.
  49. legacyMap["start_time"] = "start"; // Deprecated.
  50. legacyMap["end_time"] = "end"; // Deprecated.
  51. legacyMap["countdown"] = "due.countdown"; // Deprecated.
  52. legacyMap["countdown_compact"] = "due.countdown"; // Deprecated.
  53. legacyMap["age"] = "entry.age"; // Deprecated.
  54. legacyMap["age_compact"] = "entry.age"; // Deprecated.
  55. legacyMap["active"] = "start.active"; // Deprecated.
  56. legacyMap["recurrence_indicator"] = "recur.indicator"; // Deprecated.
  57. legacyMap["tag_indicator"] = "tags.indicator"; // Deprecated.
  58. legacyMap["description_only"] = "description.desc"; // Deprecated.
  59. }
  60. // If a legacy column was used, complain about it, but modify it anyway.
  61. std::map <std::string, std::string>::iterator found = legacyMap.find (name);
  62. if (found != legacyMap.end ())
  63. {
  64. context.footnote (format (STRING_CMD_CUSTOM_OLD_FIELD, name, found->second));
  65. name = found->second;
  66. }
  67. }
  68. ////////////////////////////////////////////////////////////////////////////////
  69. void legacySortColumnMap (std::string& name)
  70. {
  71. // One-time initialization, on demand.
  72. static std::map <std::string, std::string> legacyMap;
  73. if (! legacyMap.size ())
  74. {
  75. legacyMap["priority_long"] = "priority"; // Deprecated
  76. legacyMap["entry_time"] = "entry"; // Deprecated
  77. legacyMap["start_time"] = "start"; // Deprecated
  78. legacyMap["end_time"] = "end"; // Deprecated
  79. legacyMap["countdown"] = "due"; // Deprecated
  80. legacyMap["countdown_compact"] = "due"; // Deprecated
  81. legacyMap["age"] = "entry"; // Deprecated
  82. legacyMap["age_compact"] = "entry"; // Deprecated
  83. legacyMap["active"] = "start"; // Deprecated
  84. legacyMap["recurrence_indicator"] = "recur"; // Deprecated
  85. legacyMap["tag_indicator"] = "tags"; // Deprecated
  86. legacyMap["description_only"] = "description"; // Deprecated
  87. }
  88. // If a legacy column was used, complain about it, but modify it anyway.
  89. std::map <std::string, std::string>::iterator found = legacyMap.find (name);
  90. if (found != legacyMap.end ())
  91. {
  92. context.footnote (format (STRING_CMD_CUSTOM_OLD_SORT, name, found->second));
  93. name = found->second;
  94. }
  95. }
  96. ////////////////////////////////////////////////////////////////////////////////
  97. std::string legacyCheckForDeprecatedColor ()
  98. {
  99. std::vector <std::string> deprecated;
  100. std::map <std::string, std::string>::const_iterator it;
  101. for (it = context.config.begin (); it != context.config.end (); ++it)
  102. {
  103. if (it->first.find ("color.") != std::string::npos)
  104. {
  105. std::string value = context.config.get (it->first);
  106. if (value.find ("_") != std::string::npos)
  107. deprecated.push_back (it->first);
  108. }
  109. }
  110. std::stringstream out;
  111. if (deprecated.size ())
  112. {
  113. out << STRING_CONFIG_DEPRECATED_US
  114. << "\n";
  115. std::vector <std::string>::iterator it2;
  116. for (it2 = deprecated.begin (); it2 != deprecated.end (); ++it2)
  117. out << " " << *it2 << "=" << context.config.get (*it2) << "\n";
  118. out << "\n";
  119. }
  120. return out.str ();
  121. }
  122. ////////////////////////////////////////////////////////////////////////////////
  123. std::string legacyCheckForDeprecatedVariables ()
  124. {
  125. std::vector <std::string> deprecated;
  126. std::map <std::string, std::string>::const_iterator it;
  127. for (it = context.config.begin (); it != context.config.end (); ++it)
  128. {
  129. // report.*.limit
  130. if (it->first.length () > 13 &&
  131. it->first.substr (0, 7) == "report." &&
  132. it->first.substr (it->first.length () - 6) == ".limit")
  133. deprecated.push_back (it->first);
  134. // report.*.annotaitons
  135. if (it->first.length () > 19 &&
  136. it->first.substr (0, 7) == "report." &&
  137. it->first.substr (it->first.length () - 12) == ".annotations")
  138. deprecated.push_back (it->first);
  139. if (it->first == "echo.command" ||
  140. it->first == "edit.verbose" ||
  141. it->first == "next" ||
  142. it->first == "annotations" ||
  143. it->first == "export.ical.class")
  144. deprecated.push_back (it->first);
  145. }
  146. std::stringstream out;
  147. if (deprecated.size ())
  148. {
  149. out << STRING_CONFIG_DEPRECATED_VAR
  150. << "\n";
  151. std::vector <std::string>::iterator it2;
  152. for (it2 = deprecated.begin (); it2 != deprecated.end (); ++it2)
  153. out << " " << *it2 << "\n";
  154. out << "\n";
  155. }
  156. return out.str ();
  157. }
  158. ////////////////////////////////////////////////////////////////////////////////
  159. std::string legacyCheckForDeprecatedColumns ()
  160. {
  161. std::vector <std::string> deprecated;
  162. std::map <std::string, std::string>::const_iterator it;
  163. for (it = context.config.begin (); it != context.config.end (); ++it)
  164. {
  165. if (it->first.find ("report") == 0)
  166. {
  167. std::string value = context.config.get (it->first);
  168. if (value.find ("entry_time") != std::string::npos ||
  169. value.find ("start_time") != std::string::npos ||
  170. value.find ("end_time") != std::string::npos)
  171. deprecated.push_back (it->first);
  172. }
  173. }
  174. std::stringstream out;
  175. out << "\n";
  176. if (deprecated.size ())
  177. {
  178. out << STRING_CONFIG_DEPRECATED_COL
  179. << "\n";
  180. std::vector <std::string>::iterator it2;
  181. for (it2 = deprecated.begin (); it2 != deprecated.end (); ++it2)
  182. out << " " << *it2 << "=" << context.config.get (*it2) << "\n";
  183. out << "\n";
  184. }
  185. return out.str ();
  186. }
  187. ////////////////////////////////////////////////////////////////////////////////