1 /*
2 * Copyright 2013, Rene Gollent, rene@gollent.com.
3 * Distributed under the terms of the MIT License.
4 */
5 #include "TeamFileManagerSettings.h"
6
TeamFileManagerSettings()7 TeamFileManagerSettings::TeamFileManagerSettings()
8 :
9 fValues()
10 {
11 }
12
13
~TeamFileManagerSettings()14 TeamFileManagerSettings::~TeamFileManagerSettings()
15 {
16 }
17
18
19 TeamFileManagerSettings&
operator =(const TeamFileManagerSettings & other)20 TeamFileManagerSettings::operator=(const TeamFileManagerSettings& other)
21 {
22 fValues = other.fValues;
23
24 return *this;
25 }
26
27
28 const char*
ID() const29 TeamFileManagerSettings::ID() const
30 {
31 return "FileManager";
32 }
33
34
35 status_t
SetTo(const BMessage & archive)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
WriteTo(BMessage & archive) const49 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
CountSourceMappings() const62 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
AddSourceMapping(const BString & sourcePath,const BString & locatedPath)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
RemoveSourceMappingAt(int32 index)90 TeamFileManagerSettings::RemoveSourceMappingAt(int32 index)
91 {
92 return fValues.RemoveData("source:mapping", index);
93 }
94
95
96 status_t
GetSourceMappingAt(int32 index,BString & sourcePath,BString & locatedPath)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*
Clone() const114 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