use of com.keepassdroid.database.PwEntry in project KeePassDX by Kunzisoft.
the class DeleteEntry method testDelete.
public void testDelete() {
Database db;
Context ctx = getContext();
try {
db = TestData.GetDb(ctx, ASSET, PASSWORD, KEYFILE, FILENAME);
} catch (Exception e) {
assertTrue("Failed to open database: " + e.getMessage(), false);
return;
}
PwDatabaseV3 pm = (PwDatabaseV3) db.pm;
PwGroup group1 = getGroup(pm, GROUP1_NAME);
assertNotNull("Could not find group1", group1);
// Delete the group
DeleteGroup task = new DeleteGroup(db, group1, null, true);
task.run();
// Verify the entries were deleted
PwEntry entry1 = getEntry(pm, ENTRY1_NAME);
assertNull("Entry 1 was not removed", entry1);
PwEntry entry2 = getEntry(pm, ENTRY2_NAME);
assertNull("Entry 2 was not removed", entry2);
// Verify the entries were removed from the search index
SearchDbHelper dbHelp = new SearchDbHelper(ctx);
PwGroup results1 = dbHelp.search(db, ENTRY1_NAME);
PwGroup results2 = dbHelp.search(db, ENTRY2_NAME);
assertEquals("Entry1 was not removed from the search results", 0, results1.numbersOfChildEntries());
assertEquals("Entry2 was not removed from the search results", 0, results2.numbersOfChildEntries());
// Verify the group was deleted
group1 = getGroup(pm, GROUP1_NAME);
assertNull("Group 1 was not removed.", group1);
}
use of com.keepassdroid.database.PwEntry in project KeePassDX by Kunzisoft.
the class SprEngineV4 method findRefTarget.
public TargetResult findRefTarget(String fullRef, SprContextV4 ctx) {
if (fullRef == null) {
return null;
}
fullRef = fullRef.toUpperCase(Locale.ENGLISH);
if (!fullRef.startsWith(STR_REF_START) || !fullRef.endsWith(STR_REF_END)) {
return null;
}
String ref = fullRef.substring(STR_REF_START.length(), fullRef.length() - STR_REF_START.length() - STR_REF_END.length());
if (ref.length() <= 4) {
return null;
}
if (ref.charAt(1) != '@') {
return null;
}
if (ref.charAt(3) != ':') {
return null;
}
char scan = Character.MIN_VALUE;
char wanted = Character.MIN_VALUE;
scan = Character.toUpperCase(ref.charAt(2));
wanted = Character.toUpperCase(ref.charAt(0));
SearchParametersV4 sp = new SearchParametersV4();
sp.setupNone();
sp.searchString = ref.substring(4);
if (scan == 'T') {
sp.searchInTitles = true;
} else if (scan == 'U') {
sp.searchInUserNames = true;
} else if (scan == 'A') {
sp.searchInUrls = true;
} else if (scan == 'P') {
sp.searchInPasswords = true;
} else if (scan == 'N') {
sp.searchInNotes = true;
} else if (scan == 'I') {
sp.searchInUUIDs = true;
} else if (scan == 'O') {
sp.searchInOther = true;
} else {
return null;
}
List<PwEntry> list = new ArrayList<PwEntry>();
ctx.db.rootGroup.searchEntries(sp, list);
if (list.size() > 0) {
return new TargetResult((PwEntryV4) list.get(0), wanted);
}
return null;
}
use of com.keepassdroid.database.PwEntry in project KeePassDX by Kunzisoft.
the class SearchDbHelper method search.
public PwGroup search(Database db, String qStr) {
PwDatabase pm = db.pm;
PwGroup group;
if (pm instanceof PwDatabaseV3) {
group = new PwGroupV3();
} else if (pm instanceof PwDatabaseV4) {
group = new PwGroupV4();
} else {
Log.d("SearchDbHelper", "Tried to search with unknown db");
return null;
}
group.setName(mCtx.getString(R.string.search_results));
group.setEntries(new ArrayList<>());
// Search all entries
Locale loc = Locale.getDefault();
qStr = qStr.toLowerCase(loc);
boolean isOmitBackup = omitBackup();
Queue<PwGroup> worklist = new LinkedList<PwGroup>();
if (pm.rootGroup != null) {
worklist.add(pm.rootGroup);
}
while (worklist.size() != 0) {
PwGroup top = worklist.remove();
if (pm.isGroupSearchable(top, isOmitBackup)) {
for (PwEntry entry : top.getChildEntries()) {
processEntries(entry, group.getChildEntries(), qStr, loc);
}
for (PwGroup childGroup : top.getChildGroups()) {
if (childGroup != null) {
worklist.add(childGroup);
}
}
}
}
return group;
}
use of com.keepassdroid.database.PwEntry in project KeePassDX by Kunzisoft.
the class DeleteGroup method run.
@Override
public void run() {
PwDatabase pm = mDb.pm;
PwGroup parent = mGroup.getParent();
// Remove Group from parent
boolean recycle = pm.canRecycle(mGroup);
if (recycle) {
pm.recycle(mGroup);
} else {
// TODO tests
// Remove child entries
List<PwEntry> childEnt = new ArrayList<>(mGroup.getChildEntries());
for (int i = 0; i < childEnt.size(); i++) {
DeleteEntry task = new DeleteEntry(mContext, mDb, childEnt.get(i), null, true);
task.run();
}
// Remove child groups
List<PwGroup> childGrp = new ArrayList<>(mGroup.getChildGroups());
for (int i = 0; i < childGrp.size(); i++) {
DeleteGroup task = new DeleteGroup(mContext, mDb, childGrp.get(i), null, true);
task.run();
}
pm.deleteGroup(mGroup);
// Remove from PwDatabaseV3
// TODO ENcapsulate
mDb.pm.getGroups().remove(mGroup);
}
// Save
mFinish = new AfterDelete(mFinish, parent, mGroup, recycle);
// Commit Database
SaveDB save = new SaveDB(mContext, mDb, mFinish, mDontSave);
save.run();
}
use of com.keepassdroid.database.PwEntry in project KeePassDX by Kunzisoft.
the class EntryEditActivity method populateNewEntry.
protected PwEntry populateNewEntry() {
PwDatabase db = App.getDB().pm;
PwEntry newEntry = mEntry.clone();
newEntry.startToDecodeReference(db);
newEntry.createBackup(db);
newEntry.setLastAccessTime(new PwDate());
newEntry.setLastModificationTime(new PwDate());
newEntry.setTitle(entryTitleView.getText().toString());
if (mSelectedIconID != -1)
// or TODO icon factory newEntry.setIcon(App.getDB().pm.iconFactory.getIcon(mSelectedIconID));
newEntry.setIcon(new PwIconStandard(mSelectedIconID));
else {
if (mIsNew) {
newEntry.setIcon(App.getDB().pm.iconFactory.getIcon(0));
} else {
// Keep previous icon, if no new one was selected
newEntry.setIcon(mEntry.getIconStandard());
}
}
newEntry.setUrl(entryUrlView.getText().toString());
newEntry.setUsername(entryUserNameView.getText().toString());
newEntry.setNotes(entryCommentView.getText().toString());
newEntry.setPassword(entryPasswordView.getText().toString());
if (newEntry.allowExtraFields()) {
// Delete all new standard strings
newEntry.removeExtraFields();
// Add extra fields from views
for (int i = 0; i < entryExtraFieldsContainer.getChildCount(); i++) {
EntryEditNewField view = (EntryEditNewField) entryExtraFieldsContainer.getChildAt(i);
String key = view.getLabel();
String value = view.getValue();
boolean protect = view.isProtected();
newEntry.addField(key, new ProtectedString(protect, value));
}
}
newEntry.endToDecodeReference(db);
return newEntry;
}
Aggregations