Licence.vala 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using Invercargill;
  2. namespace Usm {
  3. public enum LicenceCategory {
  4. PROPRIETARY = 0,
  5. SOURCE_AVAILABLE = 1,
  6. OPEN_SOURCE = 2,
  7. LIBRE = 3;
  8. public static LicenceCategory from_string(string str) throws ManifestError {
  9. switch (str) {
  10. case "libre":
  11. return LicenceCategory.LIBRE;
  12. case "open-source":
  13. return LicenceCategory.OPEN_SOURCE;
  14. case "source-available":
  15. return LicenceCategory.SOURCE_AVAILABLE;
  16. case "proprietary":
  17. return LicenceCategory.PROPRIETARY;
  18. default:
  19. throw new ManifestError.INVALID_LICENCE_CATEGORY(@"Unknown licence category \"$str\".");
  20. }
  21. }
  22. public string to_string() {
  23. switch (this) {
  24. case LicenceCategory.LIBRE:
  25. return "libre";
  26. case LicenceCategory.OPEN_SOURCE:
  27. return "open-source";
  28. case LicenceCategory.SOURCE_AVAILABLE:
  29. return "source-available";
  30. case LicenceCategory.PROPRIETARY:
  31. return "proprietary";
  32. default:
  33. assert_not_reached();
  34. }
  35. }
  36. }
  37. public class Licence {
  38. public string name { get; set; }
  39. public LicenceCategory category { get; set; }
  40. public string text_path { get; set; }
  41. public static PropertyMapper<Licence> get_mapper() {
  42. return once<PropertyMapper<Licence>>(() => new PropertyMapperBuilder<Licence>()
  43. .map<string>("name", o => o.name, (o, v) => o.name = v)
  44. .map<string>("category", o => o.category.to_string(), (o, v) => o.category = LicenceCategory.from_string(v))
  45. .map<string>("text", o => o.text_path, (o, v) => o.text_path = v)
  46. .set_constructor(() => new Licence())
  47. .build());
  48. }
  49. }
  50. }