comparison filestates.cpp @ 336:4229b6a8e9c6

Merge
author Chris Cannam
date Mon, 14 Mar 2011 10:00:29 +0000
parents ea62eb083ed4
children 4cd753e083cc
comparison
equal deleted inserted replaced
335:aa852b477e4d 336:4229b6a8e9c6
61 } 61 }
62 62
63 QStringList *FileStates::stateToBucket(State s) 63 QStringList *FileStates::stateToBucket(State s)
64 { 64 {
65 switch (s) { 65 switch (s) {
66 case Clean: return &m_clean; // not implemented yet 66 case Clean: return &m_clean;
67 case Modified: return &m_modified; 67 case Modified: return &m_modified;
68 case Added: return &m_added; 68 case Added: return &m_added;
69 case Unknown: return &m_unknown; 69 case Unknown: return &m_unknown;
70 case Removed: return &m_removed; 70 case Removed: return &m_removed;
71 case Missing: return &m_missing; 71 case Missing: return &m_missing;
110 << " added, " << m_removed.size() << " removed, " << m_missing.size() 110 << " added, " << m_removed.size() << " removed, " << m_missing.size()
111 << " missing, " << m_inConflict.size() << " in conflict, " 111 << " missing, " << m_inConflict.size() << " in conflict, "
112 << m_unknown.size() << " unknown" << endl; 112 << m_unknown.size() << " unknown" << endl;
113 } 113 }
114 114
115 QStringList FileStates::getFilesInState(State s) const 115 QStringList FileStates::filesInState(State s) const
116 { 116 {
117 QStringList *sl = const_cast<FileStates *>(this)->stateToBucket(s); 117 QStringList *sl = const_cast<FileStates *>(this)->stateToBucket(s);
118 if (sl) return *sl; 118 if (sl) return *sl;
119 else return QStringList(); 119 else return QStringList();
120 } 120 }
121 121
122 FileStates::State FileStates::getStateOfFile(QString file) const 122 bool FileStates::isInState(QString file, State s) const
123 {
124 return filesInState(s).contains(file);
125 }
126
127 FileStates::State FileStates::stateOf(QString file) const
123 { 128 {
124 if (m_stateMap.contains(file)) { 129 if (m_stateMap.contains(file)) {
125 return m_stateMap[file]; 130 return m_stateMap[file];
126 } 131 }
127 DEBUG << "FileStates: WARNING: getStateOfFile: file " 132 DEBUG << "FileStates: WARNING: getStateOfFile: file "
129 << "but unknown to us is not supposed to be the same " 134 << "but unknown to us is not supposed to be the same "
130 << "thing as unknown state..." 135 << "thing as unknown state..."
131 << endl; 136 << endl;
132 return Unknown; 137 return Unknown;
133 } 138 }
139
140 FileStates::Activities FileStates::activitiesSupportedBy(State s)
141 {
142 Activities a;
143
144 switch (s) {
145
146 case Modified:
147 a << Annotate << Diff << Commit << Revert << Remove;
148 break;
149
150 case Added:
151 a << Commit << Revert << Remove;
152 break;
153
154 case Removed:
155 a << Commit << Revert << Add;
156 break;
157
158 case InConflict:
159 a << Annotate << Diff << RedoMerge << MarkResolved << Revert;
160 break;
161
162 case Missing:
163 a << Revert << Remove;
164 break;
165
166 case Unknown:
167 a << Add << Ignore;
168 break;
169
170 case Clean:
171 a << Annotate << Remove;
172 break;
173
174 case Ignored:
175 a << UnIgnore;
176 break;
177 }
178
179 return a;
180 }
181
182 bool FileStates::supportsActivity(State s, Activity a)
183 {
184 return activitiesSupportedBy(s).contains(a);
185 }
186
187 int FileStates::activityGroup(Activity a)
188 {
189 switch (a) {
190 case Annotate: case Diff: return 0;
191 case Commit: case Revert: return 1;
192 case Add: case Remove: return 2;
193 case RedoMerge: case MarkResolved: return 3;
194 case Ignore: case UnIgnore: return 4;
195 }
196 return 0;
197 }
198
199 bool FileStates::supportsActivity(QString file, Activity a) const
200 {
201 return supportsActivity(stateOf(file), a);
202 }
203
204 QStringList FileStates::filesSupportingActivity(Activity a) const
205 {
206 QStringList f;
207 for (int i = int(FirstState); i <= int(LastState); ++i) {
208 State s = (State)i;
209 if (supportsActivity(s, a)) {
210 f << filesInState(s);
211 }
212 }
213 return f;
214 }
215
216 FileStates::Activities FileStates::activitiesSupportedBy(QString file) const
217 {
218 return activitiesSupportedBy(stateOf(file));
219 }
220