/* 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 . */ #include "ExportPanel.h" enum {EXPORT_ID=1, SEARCH_ID, GRID_ID}; BEGIN_EVENT_TABLE(ExportPanel, wxPanel) EVT_BUTTON(EXPORT_ID, ExportPanel::OnButtonExport) EVT_BUTTON(SEARCH_ID, ExportPanel::OnButtonSearch) EVT_SHOW(ExportPanel::OnShow) END_EVENT_TABLE() ExportPanel::ExportPanel(KissCount* kiss, wxUI *parent) : KissPanel(kiss, parent), _operations(0) { DEFAULT_FONT(font); std::vector::iterator accountIt; std::vector::iterator categoryIt; wxDateTime firstOfMonth; wxRect rect = wxDisplay().GetGeometry(); wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL); wxBoxSizer *vbox2 = new wxBoxSizer(wxVERTICAL); wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL); SetSizer(vbox); _searchButton = new wxButton(this, SEARCH_ID, _("Search")); _banner = new SearchBanner(kiss, this, this, OnEnter); vbox->Add(_banner, 0, wxGROW|wxALL, 5); vbox->Add(_searchButton, 0, wxALL, 5); _grid = new GridAccount(_kiss, this, GRID_ID, false, false, false); hbox->Add(_grid, 0, wxGROW|wxALL, 5); _exportButton = new wxButton(this, EXPORT_ID, _("Export")); vbox2->Add(_exportButton, wxALL, 15); hbox->Add(vbox2, 0, wxALL, 15); vbox->Add(hbox, 0, wxGROW|wxALL, 5); Fit(); SetMinSize(wxSize(rect.width-rect.x-15, rect.height-rect.y-128-25)); SetMaxSize(wxSize(rect.width-rect.x-15, rect.height-rect.y-128-25)); SetScrollbars(10, 10, 100/10, 100/10); } ExportPanel::~ExportPanel() { } KissPanel* ExportPanel::CreatePanel() { return new ExportPanel(_kiss, _wxUI); } wxBitmapButton* ExportPanel::GetButton(int id) { if (!_KissButton) _KissButton = new wxBitmapButton(_wxUI, id, wxBitmap(wxT(EXPORT_ICON), wxBITMAP_TYPE_PNG), wxDefaultPosition, wxSize(128, 128)); return _KissButton; } wxString ExportPanel::GetToolTip() { return _("Export"); } void ExportPanel::OnEnter(void* caller, wxCommandEvent& event) { ExportPanel* _this = (ExportPanel*) caller; _this->OnButtonExport(event); } void ExportPanel::OnButtonSearch(wxCommandEvent& event) { _operations = _banner->Search(); if (!_operations) return; if (_operations->size() > 1) wxMessageBox(wxString::Format(wxT("%d"), _operations->size()) + _(" entries found"), wxT("KissCount"), wxICON_INFORMATION | wxOK); else if (_operations->size() == 1) wxMessageBox(_("1 entry found"), wxT("KissCount"), wxICON_INFORMATION | wxOK); else { wxMessageBox(_("No entry found"), wxT("KissCount"), wxICON_INFORMATION | wxOK); return; } _grid->LoadOperations(_operations, 0, 0); _wxUI->Layout(); } void ExportPanel::OnButtonExport(wxCommandEvent& event) { if (!_operations || !_operations->size()) { wxMessageBox(_("No operation to save"), wxT("Error"), wxICON_ERROR | wxOK); return; } wxFileDialog saveFileDialog(this, _("Save as"), wxT(""), wxT(""), _kiss->GetExportEngineExtensions(), wxFD_SAVE|wxFD_OVERWRITE_PROMPT); if (saveFileDialog.ShowModal() == wxID_CANCEL) return; _exportEngine = _kiss->GetExportEngine(saveFileDialog.GetPath()); if (!_exportEngine) { wxMessageBox(_("Any engine can process this file !"), wxT("KissCount"), wxICON_INFORMATION | wxOK); return ; } if (_exportEngine->SaveFile(_operations)) wxMessageBox(_("Operations successfuly saved"), wxT("KissCount"), wxICON_INFORMATION | wxOK); else wxMessageBox(_("Failed to save operations"), wxT("Error"), wxICON_ERROR | wxOK); } void ExportPanel::OnShow(wxShowEvent& event) { _wxUI->SetTitle(_("KissCount - Export")); }