summaryrefslogtreecommitdiffabout
path: root/pwmanager/pwmanager/findwndimpl.cpp
blob: fec1a6ab7fbef529eafbcb79985329959a4d5e64 (plain)
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
/***************************************************************************
 *                                                                         *
 *   copyright (C) 2003 by Michael Buesch                                  *
 *   email: mbuesch@freenet.de                                             *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License version 2        *
 *   as published by the Free Software Foundation.                         *
 *                                                                         *
 ***************************************************************************/

/***************************************************************************
 * copyright (C) 2004 by Ulf Schenk
 * This file is originaly based on version 1.0.1 of pwmanager
 * and was modified to run on embedded devices that run microkde
 *
 * $Id$
 **************************************************************************/  

#include "findwndimpl.h"
#include "pwmexception.h"
#include "pwmdoc.h"
#include "pwmview.h"

#include <qradiobutton.h>
#include <qlineedit.h>
#include <qcheckbox.h>

#include <kmessagebox.h>
#include <klocale.h>

FindWndImpl::FindWndImpl(PwMView * _parent)
 : findWnd()
{
	parent = _parent;
	fAt = 0;
	refVal = 0;
	currFoundPos = -1;
	numEntries = parent->document()->numEntries(parent->getCurrentCategory());
	connect(this, SIGNAL(foundAt(int)), parent, SLOT(selAt(int)));
}

FindWndImpl::~FindWndImpl()
{
}

void FindWndImpl::findButton_slot()
{
	if (findLineEdit->text() == "")
		return;
	static vector<unsigned int> foundPositions;
	PwMDoc *doc = parent->document();

	if (currFoundPos < 0) {
		bool unlockedTempoary = false;
		foundPositions.clear();
		PwMDataItem findThis;
		unsigned int searchIn = 0;

		if (descRadioButton->isChecked()) {
			searchIn = SEARCH_IN_DESC;
			findThis.desc = findLineEdit->text().latin1();
		} else if (nameRadioButton->isChecked()) {
			searchIn = SEARCH_IN_NAME;
			findThis.name = findLineEdit->text().latin1();
		} else if (pwRadioButton->isChecked()) {
			searchIn = SEARCH_IN_PW;
			findThis.pw = findLineEdit->text().latin1();
		} else if (commentRadioButton->isChecked()) {
			searchIn = SEARCH_IN_COMMENT;
			findThis.comment = findLineEdit->text().latin1();
		} else if (urlRadioButton->isChecked()) {
			searchIn = SEARCH_IN_URL;
			findThis.url = findLineEdit->text().latin1();
		} else if (launcherRadioButton->isChecked()) {
			searchIn = SEARCH_IN_LAUNCHER;
			findThis.launcher = findLineEdit->text().latin1();
		}

		if (pwRadioButton->isChecked()) {
			if (!doc->unlockAll_tempoary())
				return;
			unlockedTempoary = true;
		}
		doc->findEntry(parent->getCurrentCategory(), findThis,
			       searchIn, &foundPositions, false,
			       caseSensCheckBox->isChecked(),
			       exactCheckBox->isChecked(),
			       true);
		if (unlockedTempoary) {
			doc->unlockAll_tempoary(true);
		}

		if (!foundPositions.size()) {
			KMessageBox::information(this,
						 i18n("No entry found."),
						 i18n("not found"));
			return;
		}
		currFoundPos = 0;
	}

	int lvp = doc->getListViewPos(parent->getCurrentCategory(),
				      foundPositions[currFoundPos++]);
	emit foundAt(numEntries - 1 - lvp);

	if (currFoundPos + 1 > static_cast<int>(foundPositions.size()))
		currFoundPos = 0;
}

void FindWndImpl::closeButton_slot()
{
	done(0);
}

void FindWndImpl::selectionChanged_slot()
{
	fAt = 0;
	refVal = 0;
	currFoundPos = -1;
}

#ifndef PWM_EMBEDDED
#include "findwndimpl.moc"
#endif