/*
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 .
*/
#include "ExportPanel.hpp"
ExportPanel::ExportPanel(KissCount* kiss, wxUI *parent, bool lowResolution) :
KissPanel(kiss, parent, lowResolution), _operations(0)
{
DEFAULT_FONT(font);
std::vector::iterator accountIt;
std::vector::iterator categoryIt;
QVBoxLayout *vbox = new QVBoxLayout;
QVBoxLayout *vbox2 = new QVBoxLayout;
QHBoxLayout *hbox = new QHBoxLayout;
_icons[KissPanel::LOW_RES_ICON] = EXPORT_LOW_ICON;
_icons[KissPanel::HIGH_RES_ICON] = EXPORT_ICON;
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, 2);
}
ExportPanel::~ExportPanel()
{
}
KissPanel* ExportPanel::CreatePanel()
{
return new ExportPanel(_kiss, _wxUI, _lowResolution);
}
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;
}
_kiss->setOverrideCursor(QCursor(Qt::WaitCursor));
_wxUI->setEnabled(false);
_wxUI->repaint();
_grid->LoadOperations(_operations, 0, 0);
_wxUI->setEnabled(true);
_kiss->setOverrideCursor(QCursor(Qt::ArrowCursor));
layout();
}
void ExportPanel::OnButtonExport()
{
QString path, filter;
if (!_operations || !_operations->size())
{
QMessageBox::critical(0, _("Error"), _("No operation to save"));
return;
}
path = QFileDialog::getSaveFileName(0, _("Save as"), "", _kiss->GetExportEngineExtensions(), &filter);
if (path.size() == 0)
return;
_exportEngine = _kiss->GetExportEngine(path, filter);
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"));
}