00001 /* 00002 00003 This file is part of Kitlist, a program to maintain a simple list 00004 of items and assign items to one or more categories. 00005 00006 Copyright (C) 2008,2009 Frank Dean 00007 00008 Kitlist is free software: you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundation, either version 3 of the License, or 00011 (at your option) any later version. 00012 00013 Kitlist is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with Kitlist. If not, see <http://www.gnu.org/licenses/>. 00020 00021 */ 00022 00023 #ifndef SERVICE_H 00024 #define SERVICE_H 1 00025 00026 #include "kitlistdao.hpp" 00027 #include "kitmodel.hpp" 00028 #include "xmldao.hpp" 00029 #include <glibmm/ustring.h> 00030 00031 00038 class Service { 00039 protected: 00040 KitListDao& m_dao; 00041 KitModel* m_model; 00042 KitModel* load_model(); 00043 long get_next_item_id(); 00044 long get_next_category_id(); 00045 public: 00046 Service(KitListDao& dao); 00047 ~Service(); 00048 ModelItem* find_item(long id); 00049 ModelCategory* find_category(long cat_id); 00050 void copy_items(const ModelItemContainer& items, long cat_id); 00051 Item* create_item(long cat_id); 00052 bool delete_item(long id); 00053 bool delete_category(long cat_id); 00054 Category* create_category(); 00055 bool is_model_dirty() { return m_model ? m_model->is_dirty() : false; } 00056 void set_model_dirty(bool flag = true); 00063 virtual bool filter(bool checked) { return m_model->filter(checked); } 00064 void create_default_model(); 00065 void open_as_xml(const Glib::ustring& filename); 00066 void save(); 00067 void save_as_xml(const Glib::ustring& filename); 00068 bool update_item(long id, const std::string description, bool checked); 00069 ItemContainer* get_items(long cat_id = -1); 00070 ItemContainer* get_filtered_items(long cat_id = -1); 00071 CategoryContainer* get_categories(); 00073 virtual void show_all() { m_model->show_all(); } 00075 virtual void show_checked_only() { m_model->show_checked_only(); } 00077 virtual void show_unchecked_only() { m_model->show_unchecked_only(); } 00078 virtual void select_items(ModelItemContainer* items, bool checked = true); 00079 virtual void toggle_selected_items(ModelItemContainer* items); 00080 virtual bool require_filename() { return m_dao.require_filename(); } 00081 00082 }; 00083 00084 00085 #endif // SERVICE_H