Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

[040794]: RUEList.cpp Maximize Restore History

Download this file

RUEList.cpp    275 lines (221 with data), 6.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
/// \file RUEList.cpp
//-----------------------------------------------------------------------------
#include "PasswordSafe.h"
#include "ThisMfcApp.h"
#include "RUEList.h"
#include "corelib/PWScore.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//-----------------------------------------------------------------------------
// Constructors
CRUEList::CRUEList() : m_core(app.m_core), m_maxentries(0)
{
}
CRUEList::~CRUEList()
{
}
//-----------------------------------------------------------------------------
// Accessors
bool
CRUEList::SetMax(const int &newmax)
{
if (newmax < 0) return false;
m_maxentries = newmax;
int numentries = m_RUEList.GetCount();
if (newmax > numentries) return true;
for (int i = numentries; i > newmax; i--)
m_RUEList.RemoveTail();
return true;
}
int
CRUEList::GetMax() const
{
return m_maxentries;
}
int
CRUEList::GetCount() const
{
return m_RUEList.GetCount();
}
bool
CRUEList::GetAllMenuItemStrings(CList<CMyString, CMyString&> &ListofAllMenuStrings) const
{
CMyString itemstring;
POSITION ruel_pos = m_RUEList.GetHeadPosition();
bool retval = false;
while (ruel_pos != NULL) {
const RUEntry m_ruentry = m_RUEList.GetNext(ruel_pos);
POSITION pw_listpos = m_core.Find(m_ruentry.RUEuuid);
if (pw_listpos == NULL) {
itemstring = _T("");
} else {
const CItemData &ci = m_core.GetEntryAt(pw_listpos);
CMyString group = ci.GetGroup();
CMyString title = ci.GetTitle();
CMyString user = ci.GetUser();
if (group.IsEmpty())
group = _T("*");
if (title.IsEmpty())
title = _T("*");
if (user.IsEmpty())
user = _T("*");
itemstring = MRE_FS + group + MRE_FS + title + MRE_FS + user + MRE_FS;
}
ListofAllMenuStrings.AddTail(itemstring);
retval = true;
}
return retval;
}
bool
CRUEList::GetMenuItemString(const int &index, CMyString &itemstring) const
{
if (m_RUEList.GetCount() == 0 || index > m_RUEList.GetCount()) {
itemstring = _T("");
return false;
}
POSITION re_listpos = m_RUEList.FindIndex(index);
RUEntry m_ruentry = m_RUEList.GetAt(re_listpos);
POSITION pw_listpos = m_core.Find(m_ruentry.RUEuuid);
if (pw_listpos == NULL) {
itemstring = _T("");
return false;
}
const CItemData ci = m_core.GetEntryAt(pw_listpos);
CMyString group = ci.GetGroup();
CMyString title = ci.GetTitle();
CMyString user = ci.GetUser();
if (group.IsEmpty())
group = _T("*");
if (title.IsEmpty())
title = _T("*");
if (user.IsEmpty())
user = _T("*");
itemstring = MRE_FS + group + MRE_FS + title + MRE_FS + user + MRE_FS;
return true;
}
bool
CRUEList::GetMenuItemString(const uuid_array_t &RUEuuid, CMyString &itemstring) const
{
if (m_RUEList.GetCount() == 0) {
itemstring = _T("");
return false;
}
POSITION pw_listpos = m_core.Find(RUEuuid);
if (pw_listpos == NULL) {
itemstring = _T("");
return false;
}
const CItemData ci = m_core.GetEntryAt(pw_listpos);
CMyString group = ci.GetGroup();
CMyString title = ci.GetTitle();
CMyString user = ci.GetUser();
if (group.IsEmpty())
group = _T("*");
if (title.IsEmpty())
title = _T("*");
if (user.IsEmpty())
user = _T("*");
itemstring = MRE_FS + group + MRE_FS + title + MRE_FS + user + MRE_FS;
return true;
}
void
CRUEList::ClearEntries()
{
m_RUEList.RemoveAll();
}
bool
CRUEList::AddRUEntry(const uuid_array_t &RUEuuid)
{
if (m_maxentries == 0) return false;
RUEntry re_newEntry;
memcpy(re_newEntry.RUEuuid, RUEuuid, sizeof(uuid_array_t));
POSITION re_listpos = m_RUEList.GetHeadPosition();
while (re_listpos != NULL) {
const RUEntry &re_FoundEntry = m_RUEList.GetAt(re_listpos);
if (memcmp(re_FoundEntry.RUEuuid, re_newEntry.RUEuuid, sizeof(uuid_array_t)) == 0)
break; // found it already there
else
m_RUEList.GetNext(re_listpos);
}
if (re_listpos == NULL) {
if (m_RUEList.GetCount() == m_maxentries) // if already maxed out - delete oldest entry
m_RUEList.RemoveTail();
m_RUEList.AddHead(re_newEntry); // put it at the top
} else {
m_RUEList.RemoveAt(re_listpos); // take it out
m_RUEList.AddHead(re_newEntry); // put it at the top
}
return true;
}
bool
CRUEList::DeleteRUEntry(const int &index)
{
if ((m_maxentries == 0) ||
(m_RUEList.GetCount() == 0) ||
(index > (m_maxentries - 1)) ||
(index < 0) ||
(index > (m_RUEList.GetCount() - 1))) return false;
POSITION re_listpos = m_RUEList.FindIndex(index);
ASSERT(re_listpos != NULL);
m_RUEList.RemoveAt(re_listpos);
return true;
}
bool
CRUEList::DeleteRUEntry(const uuid_array_t &RUEuuid)
{
if ((m_maxentries == 0) ||
(m_RUEList.GetCount() == 0)) return false;
POSITION re_listpos = m_RUEList.GetHeadPosition();
RUEntry re_oldEntry;
memcpy(re_oldEntry.RUEuuid, RUEuuid, sizeof(uuid_array_t));
while (re_listpos != NULL) {
const RUEntry &re_FoundEntry = m_RUEList.GetAt(re_listpos);
if (memcmp(re_FoundEntry.RUEuuid, re_oldEntry.RUEuuid, sizeof(uuid_array_t)) == 0) {
m_RUEList.RemoveAt(re_listpos);
break;
}
else
m_RUEList.GetNext(re_listpos);
}
return true;
}
bool
CRUEList::GetPWEntry(const int &index, CItemData &ci)
{
if ((m_maxentries == 0) ||
(m_RUEList.GetCount() == 0) ||
(index > (m_maxentries - 1)) ||
(index < 0) ||
(index > (m_RUEList.GetCount() - 1))) return false;
POSITION re_listpos = m_RUEList.FindIndex(index);
ASSERT(re_listpos != NULL);
const RUEntry &re_FoundEntry = m_RUEList.GetAt(re_listpos);
POSITION pw_listpos = m_core.Find(re_FoundEntry.RUEuuid);
if (pw_listpos == NULL) {
// Entry does not exist anymore!
m_RUEList.RemoveAt(re_listpos);
AfxMessageBox(_T("Cannot process as this entry has been deleted from the open database."));
}
if (pw_listpos == NULL)
return false;
ci = m_core.GetEntryAt(pw_listpos);
return true;
}
CRUEList&
CRUEList::operator=(const CRUEList &that)
{
if (this != &that) {
m_maxentries = that.m_maxentries;
POSITION that_pos = that.m_RUEList.GetHeadPosition();
while (that_pos != NULL) {
RUEntry ruentry = that.m_RUEList.GetNext(that_pos);
m_RUEList.AddTail(ruentry);
}
}
return *this;
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------