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
|
/***************************************************************************
kmymoneyaccountcompletion.cpp - description
-------------------
begin : Mon Apr 26 2004
copyright : (C) 2000-2004 by Michael Edwardes
email : [email protected]
Javier Campos Morales <[email protected]>
Felix Rodriguez <[email protected]>
John C <[email protected]>
Thomas Baumgart <[email protected]>
Kevin Tambascio <[email protected]>
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
// ----------------------------------------------------------------------------
// QT Includes
#include <tqapplication.h>
#include <tqregexp.h>
// ----------------------------------------------------------------------------
// KDE Includes
#include <tdelistview.h>
// ----------------------------------------------------------------------------
// Project Includes
#include "kmymoneyaccountcompletion.h"
#include <kmymoney/mymoneyfile.h>
kMyMoneyAccountCompletion::kMyMoneyAccountCompletion(TQWidget *parent, const char *name ) :
kMyMoneyCompletion(parent, name)
{
delete m_selector;
m_selector = new kMyMoneyAccountSelector(this, 0, 0, false);
m_selector->listView()->setFocusProxy(this);
#ifndef KMM_DESIGNER
// Default is to show all accounts
// FIXME We should leave this also to the caller
AccountSet set;
set.addAccountGroup(MyMoneyAccount::Asset);
set.addAccountGroup(MyMoneyAccount::Liability);
set.addAccountGroup(MyMoneyAccount::Income);
set.addAccountGroup(MyMoneyAccount::Expense);
set.load(selector());
#endif
connectSignals(m_selector, m_selector->listView());
}
kMyMoneyAccountCompletion::~kMyMoneyAccountCompletion()
{
}
void kMyMoneyAccountCompletion::slotMakeCompletion(const TQString& txt)
{
// if(txt.isEmpty() || txt.length() == 0)
// return;
int cnt = 0;
if(txt.contains(MyMoneyFile::AccountSeperator) == 0) {
m_lastCompletion = TQRegExp(TQRegExp::escape(txt.stripWhiteSpace()), false);
cnt = selector()->slotMakeCompletion(m_lastCompletion);
} else {
TQStringList parts = TQStringList::split(MyMoneyFile::AccountSeperator, txt);
TQString pattern("^");
TQStringList::iterator it;
for(it = parts.begin(); it != parts.end(); ++it) {
if(pattern.length() > 1)
pattern += MyMoneyFile::AccountSeperator;
pattern += TQRegExp::escape(TQString(*it).stripWhiteSpace()) + ".*";
}
pattern += "$";
m_lastCompletion = TQRegExp(pattern, false);
cnt = selector()->slotMakeCompletion(m_lastCompletion);
// if we don't have a match, we try it again, but this time
// we add a wildcard for the top level
if(cnt == 0) {
pattern = pattern.insert(1, TQString(".*")+MyMoneyFile::AccountSeperator);
m_lastCompletion = TQRegExp(pattern, false);
cnt = selector()->slotMakeCompletion(m_lastCompletion);
}
}
if(m_parent && m_parent->isVisible() && !isVisible() && cnt)
show(false);
else {
if(cnt != 0) {
adjustSize();
} else {
hide();
}
}
}
#include "kmymoneyaccountcompletion.moc"
|