2012-02-11 14:34:29 +01:00
|
|
|
/*
|
|
|
|
Copyright 2010-2012 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 "ExportPanel.hpp"
|
|
|
|
|
|
|
|
ExportPanel::ExportPanel(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);
|
|
|
|
|
|
|
|
_exportButton = new QPushButton(_("Export"));
|
|
|
|
|
|
|
|
connect(_exportButton, SIGNAL(clicked()), this, SLOT(OnButtonExport()));
|
|
|
|
|
|
|
|
vbox2->addWidget(_exportButton);
|
|
|
|
|
|
|
|
hbox->addLayout(vbox2);
|
|
|
|
|
|
|
|
vbox->addLayout(hbox);
|
|
|
|
}
|
|
|
|
|
|
|
|
ExportPanel::~ExportPanel()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
KissPanel* ExportPanel::CreatePanel()
|
|
|
|
{
|
|
|
|
return new ExportPanel(_kiss, _wxUI);
|
|
|
|
}
|
|
|
|
|
|
|
|
QPushButton* ExportPanel::GetButton()
|
|
|
|
{
|
|
|
|
if (!_KissButton)
|
|
|
|
{
|
|
|
|
_KissButton = new QPushButton(QIcon(EXPORT_ICON), "", this);
|
|
|
|
_KissButton->setFixedSize(128, 128);
|
|
|
|
_KissButton->setIconSize(QSize(128, 128));
|
|
|
|
}
|
|
|
|
|
|
|
|
return _KissButton;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString ExportPanel::GetToolTip()
|
|
|
|
{
|
|
|
|
return _("Export");
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExportPanel::OnEnter(void* caller)
|
|
|
|
{
|
|
|
|
ExportPanel* _this = (ExportPanel*) caller;
|
|
|
|
|
|
|
|
_this->OnButtonExport();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExportPanel::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);
|
|
|
|
|
|
|
|
layout();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExportPanel::OnButtonExport()
|
|
|
|
{
|
2012-02-12 10:20:02 +01:00
|
|
|
QString path, filter;
|
2012-02-11 14:34:29 +01:00
|
|
|
|
|
|
|
if (!_operations || !_operations->size())
|
|
|
|
{
|
|
|
|
QMessageBox::critical(0, _("Error"), _("No operation to save"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-12 10:20:02 +01:00
|
|
|
path = QFileDialog::getSaveFileName(0, _("Save as"), "", _kiss->GetExportEngineExtensions(), &filter);
|
2012-02-11 14:34:29 +01:00
|
|
|
|
|
|
|
if (path.size() == 0)
|
|
|
|
return;
|
|
|
|
|
2012-02-12 10:20:02 +01:00
|
|
|
_exportEngine = _kiss->GetExportEngine(path, filter);
|
2012-02-11 14:34:29 +01:00
|
|
|
|
|
|
|
if (!_exportEngine)
|
|
|
|
{
|
|
|
|
QMessageBox::critical(0, _("Error"), _("Any engine can process this file !"));
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_exportEngine->SaveFile(_operations))
|
|
|
|
QMessageBox::information(0, _("KissCount"), _("Operations successfuly saved"));
|
|
|
|
else
|
|
|
|
QMessageBox::critical(0, _("Error"), _("Failed to save operations"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExportPanel::OnShow()
|
|
|
|
{
|
|
|
|
_wxUI->setWindowTitle(_("KissCount - Export"));
|
|
|
|
}
|