1 /* 2 * Copyright 2013, Rene Gollent, rene@gollent.com. 3 * Distributed under the terms of the MIT License. 4 */ 5 #include "TeamFileManagerSettings.h" 6 7 TeamFileManagerSettings::TeamFileManagerSettings() 8 : 9 fValues() 10 { 11 } 12 13 14 TeamFileManagerSettings::~TeamFileManagerSettings() 15 { 16 } 17 18 19 TeamFileManagerSettings& 20 TeamFileManagerSettings::operator=(const TeamFileManagerSettings& other) 21 { 22 fValues = other.fValues; 23 24 return *this; 25 } 26 27 28 const char* 29 TeamFileManagerSettings::ID() const 30 { 31 return "FileManager"; 32 } 33 34 35 status_t 36 TeamFileManagerSettings::SetTo(const BMessage& archive) 37 { 38 try { 39 fValues = archive; 40 } catch (...) { 41 return B_NO_MEMORY; 42 } 43 44 return B_OK; 45 } 46 47 48 status_t 49 TeamFileManagerSettings::WriteTo(BMessage& archive) const 50 { 51 try { 52 archive = fValues; 53 } catch (...) { 54 return B_NO_MEMORY; 55 } 56 57 return B_OK; 58 } 59 60 61 int32 62 TeamFileManagerSettings::CountSourceMappings() const 63 { 64 type_code type; 65 int32 count = 0; 66 67 if (fValues.GetInfo("source:mapping", &type, &count) == B_OK) 68 return count; 69 70 return 0; 71 } 72 73 74 status_t 75 TeamFileManagerSettings::AddSourceMapping(const BString& sourcePath, 76 const BString& locatedPath) 77 { 78 BMessage mapping; 79 if (mapping.AddString("source:path", sourcePath) != B_OK 80 || mapping.AddString("source:locatedpath", locatedPath) != B_OK 81 || fValues.AddMessage("source:mapping", &mapping) != B_OK) { 82 return B_NO_MEMORY; 83 } 84 85 return B_OK; 86 } 87 88 89 status_t 90 TeamFileManagerSettings::RemoveSourceMappingAt(int32 index) 91 { 92 return fValues.RemoveData("source:mapping", index); 93 } 94 95 96 status_t 97 TeamFileManagerSettings::GetSourceMappingAt(int32 index, BString& sourcePath, 98 BString& locatedPath) 99 { 100 BMessage mapping; 101 status_t error = fValues.FindMessage("source:mapping", index, &mapping); 102 if (error != B_OK) 103 return error; 104 105 error = mapping.FindString("source:path", &sourcePath); 106 if (error != B_OK) 107 return error; 108 109 return mapping.FindString("source:locatedpath", &locatedPath); 110 } 111 112 113 TeamFileManagerSettings* 114 TeamFileManagerSettings::Clone() const 115 { 116 TeamFileManagerSettings* settings = new(std::nothrow) 117 TeamFileManagerSettings(); 118 119 if (settings == NULL) 120 return NULL; 121 122 if (settings->SetTo(fValues) != B_OK) { 123 delete settings; 124 return NULL; 125 } 126 127 return settings; 128 } 129