2011-12-03 11:23:55 +01:00
|
|
|
/*
|
|
|
|
Copyright 2010-2011 Grégory Soutadé
|
|
|
|
|
|
|
|
This file is part of KissCount.
|
|
|
|
|
|
|
|
KissCount 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 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
KissCount is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with KissCount. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "SearchPanel.hpp"
|
|
|
|
|
|
|
|
SearchPanel::SearchPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, parent), _operations(0)
|
|
|
|
{
|
|
|
|
DEFAULT_FONT(font);
|
|
|
|
std::vector<Account>::iterator accountIt;
|
|
|
|
std::vector<Category>::iterator categoryIt;
|
|
|
|
|
|
|
|
QVBoxLayout *vbox = new QVBoxLayout;
|
|
|
|
QVBoxLayout *vbox2 = new QVBoxLayout;
|
|
|
|
QHBoxLayout *hbox = new QHBoxLayout;
|
|
|
|
|
|
|
|
setLayout(vbox);
|
|
|
|
|
|
|
|
_searchButton = new QPushButton(_("Search"));
|
|
|
|
|
|
|
|
connect(_searchButton, SIGNAL(clicked()), this, SLOT(OnButtonSearch()));
|
|
|
|
|
|
|
|
_banner = new SearchBanner(kiss, this, this, OnEnter);
|
|
|
|
|
|
|
|
vbox->addWidget(_banner);
|
|
|
|
vbox->addWidget(_searchButton);
|
|
|
|
|
|
|
|
_grid = new GridAccount(_kiss, this, false, false, true);
|
|
|
|
|
|
|
|
hbox->addWidget(_grid);
|
|
|
|
|
|
|
|
_changeAccountButton = new QPushButton(_("Change account"));
|
|
|
|
_changeCategoryButton = new QPushButton(_("Change category"));
|
|
|
|
_renameButton = new QPushButton(_("Rename"));
|
|
|
|
|
|
|
|
connect(_changeAccountButton, SIGNAL(clicked()), this, SLOT(OnButtonChangeAccount()));
|
|
|
|
connect(_changeCategoryButton, SIGNAL(clicked()), this, SLOT(OnButtonChangeCategory()));
|
|
|
|
connect(_renameButton, SIGNAL(clicked()), this, SLOT(OnButtonRename()));
|
|
|
|
|
|
|
|
vbox2->addWidget(_changeAccountButton);
|
|
|
|
vbox2->addWidget(_changeCategoryButton);
|
|
|
|
vbox2->addWidget(_renameButton);
|
|
|
|
|
|
|
|
hbox->addLayout(vbox2);
|
|
|
|
|
|
|
|
vbox->addLayout(hbox);
|
|
|
|
}
|
|
|
|
|
|
|
|
SearchPanel::~SearchPanel()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
KissPanel* SearchPanel::CreatePanel()
|
|
|
|
{
|
|
|
|
return new SearchPanel(_kiss, _wxUI);
|
|
|
|
}
|
|
|
|
|
|
|
|
QPushButton* SearchPanel::GetButton()
|
|
|
|
{
|
|
|
|
if (!_KissButton)
|
|
|
|
{
|
|
|
|
_KissButton = new QPushButton(QIcon(SEARCH_ICON), "", this);
|
|
|
|
_KissButton->setFixedSize(128, 128);
|
|
|
|
_KissButton->setIconSize(QSize(128, 128));
|
|
|
|
}
|
|
|
|
|
|
|
|
return _KissButton;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString SearchPanel::GetToolTip()
|
|
|
|
{
|
|
|
|
return _("Search");
|
|
|
|
}
|
|
|
|
|
|
|
|
void SearchPanel::OnEnter(void* caller)
|
|
|
|
{
|
|
|
|
SearchPanel* _this = (SearchPanel*) caller;
|
|
|
|
|
|
|
|
_this->OnButtonSearch();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SearchPanel::OnButtonSearch()
|
|
|
|
{
|
|
|
|
_operations = _banner->Search();
|
|
|
|
|
|
|
|
if (!_operations) return;
|
|
|
|
|
|
|
|
if (_operations->size() > 1)
|
|
|
|
QMessageBox::information(0, _("KissCount"), QString::number(_operations->size()) + _(" entries found"));
|
|
|
|
else if (_operations->size() == 1)
|
|
|
|
QMessageBox::information(0, _("KissCount"), _("1 entry found"));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QMessageBox::information(0, _("KissCount"), _("No entry found"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_grid->LoadOperations(_operations, 0, 0);
|
|
|
|
|
|
|
|
_wxUI->layout();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ChangeAccount(Operation* op, void** params)
|
|
|
|
{
|
|
|
|
int* account = (int*) params[0];
|
|
|
|
|
|
|
|
op->account = *account;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SearchPanel::OnButtonChangeAccount()
|
|
|
|
{
|
|
|
|
int i, a;
|
|
|
|
std::vector<int> rows;
|
|
|
|
User* user = _kiss->GetUser();
|
|
|
|
QStringList accounts;
|
|
|
|
std::vector<Operation>::iterator it;
|
|
|
|
int account;
|
|
|
|
void * params[] = {&account};
|
|
|
|
QString res;
|
|
|
|
|
|
|
|
if (!_operations) return;
|
|
|
|
|
|
|
|
_grid->GetSelectedOperations(&rows);
|
|
|
|
|
|
|
|
accounts << _("None");
|
|
|
|
for(i=0; i < user->GetAccountsNumber(); i++)
|
|
|
|
accounts << user->_accounts[i].name;
|
|
|
|
|
|
|
|
res = QInputDialog::getItem(this, "KissCount", _("Choose a new account"), accounts, 0, false);
|
|
|
|
|
2011-12-18 13:51:04 +01:00
|
|
|
if (!res.size()) return ;
|
2011-12-03 11:23:55 +01:00
|
|
|
a = (res.length()) ? accounts.indexOf(res) : 0;
|
|
|
|
account = (a) ? user->_accounts[a-1].id : 0;
|
|
|
|
|
|
|
|
_grid->MassUpdate(rows, true, ChangeAccount, params);
|
|
|
|
|
|
|
|
_wxUI->NeedReload();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ChangeCategory(Operation* op, void** params)
|
|
|
|
{
|
|
|
|
int* category = (int*) params[0];
|
|
|
|
bool* fix = (bool*) params[1];
|
|
|
|
|
|
|
|
op->category = *category;
|
|
|
|
op->fix_cost = * fix;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SearchPanel::OnButtonChangeCategory()
|
|
|
|
{
|
|
|
|
int i, a;
|
|
|
|
std::vector<int> rows;
|
|
|
|
User* user = _kiss->GetUser();
|
|
|
|
QStringList categories;
|
|
|
|
std::vector<Operation>::iterator it;
|
|
|
|
QString res;
|
|
|
|
int category;
|
|
|
|
bool fix;
|
|
|
|
void * params[] = {&category, &fix};
|
|
|
|
|
|
|
|
if (!_operations) return;
|
|
|
|
|
|
|
|
_grid->GetSelectedOperations(&rows);
|
|
|
|
|
|
|
|
categories << _("None");
|
|
|
|
for(i=0; i < user->GetCategoriesNumber(); i++)
|
|
|
|
categories << _(user->_categories[i].name.toStdString().c_str());
|
|
|
|
|
|
|
|
res = QInputDialog::getItem(this, "KissCount", _("Choose a new category"), categories, 0, false);
|
|
|
|
|
|
|
|
if (res.length())
|
|
|
|
{
|
|
|
|
a = categories.indexOf(res);
|
|
|
|
category = user->_categories[a-1].id ;
|
|
|
|
fix = user->_categories[a-1].fix_cost;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
category = 0;
|
|
|
|
fix = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
_grid->MassUpdate(rows, true, ChangeCategory, params);
|
|
|
|
|
|
|
|
_wxUI->NeedReload();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ChangeName(Operation* op, void** params)
|
|
|
|
{
|
|
|
|
QString* description = (QString*) params[0];
|
|
|
|
|
|
|
|
op->description = *description;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SearchPanel::OnButtonRename()
|
|
|
|
{
|
|
|
|
std::vector<int> rows;
|
|
|
|
std::vector<Operation>::iterator it;
|
|
|
|
QString description;
|
|
|
|
void * params[] = {&description};
|
|
|
|
|
|
|
|
if (!_operations) return;
|
|
|
|
|
|
|
|
_grid->GetSelectedOperations(&rows);
|
|
|
|
|
|
|
|
description = QInputDialog::getText(this, "", _("Enter a new description"));
|
|
|
|
if (!description.length()) return;
|
|
|
|
|
|
|
|
_grid->MassUpdate(rows, false, ChangeName, params);
|
|
|
|
|
|
|
|
_wxUI->NeedReload();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SearchPanel::OnShow()
|
|
|
|
{
|
|
|
|
_wxUI->setWindowTitle(_kiss->GetUser()->_name + " - " + _("Search"));
|
|
|
|
}
|
|
|
|
|
|
|
|
void SearchPanel::OnOperationModified()
|
|
|
|
{
|
|
|
|
_wxUI->NeedReload();
|
|
|
|
}
|