Kitlist  1.1.0
service.hpp
Go to the documentation of this file.
1 /*
2 
3  This file is part of Kitlist, a program to maintain a simple list
4  of items and assign items to one or more categories.
5 
6  Copyright (C) 2008,2009 Frank Dean
7 
8  Kitlist is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  Kitlist is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with Kitlist. If not, see <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #ifndef SERVICE_H
24 #define SERVICE_H 1
25 
26 #include "kitlistdao.hpp"
27 #include "kitmodel.hpp"
28 #include "xmldao.hpp"
29 #include <glibmm/ustring.h>
30 
31 
38 class Service {
39  protected:
43  long get_next_item_id();
44  long get_next_category_id();
45  public:
46  Service(KitListDao& dao);
47  ~Service();
48  ModelItem* find_item(long id);
49  ModelCategory* find_category(long cat_id);
50  void copy_items(const ModelItemContainer& items, long cat_id);
51  Item* create_item(long cat_id);
52  bool delete_item(long id);
53  bool delete_category(long cat_id);
55  bool is_model_dirty() { return m_model ? m_model->is_dirty() : false; }
56  void set_model_dirty(bool flag = true);
63  virtual bool filter(bool checked) { return m_model->filter(checked); }
64  void create_default_model();
65  void open_as_xml(const Glib::ustring& filename);
66  void save();
67  void save_as_xml(const Glib::ustring& filename);
68  bool update_item(long id, const std::string description, bool checked);
69  ItemContainer* get_items(long cat_id = -1);
70  ItemContainer* get_filtered_items(long cat_id = -1);
73  virtual void show_all() { m_model->show_all(); }
75  virtual void show_checked_only() { m_model->show_checked_only(); }
77  virtual void show_unchecked_only() { m_model->show_unchecked_only(); }
78  virtual void select_items(ModelItemContainer* items, bool checked = true);
79  virtual void toggle_selected_items(ModelItemContainer* items);
80  virtual bool require_filename() { return m_dao.require_filename(); }
81 
82 };
83 
84 
85 #endif // SERVICE_H
virtual bool filter(bool checked)
Applies the current filter.
Definition: kitmodel.cpp:446
ModelCategory * find_category(long cat_id)
Definition: service.cpp:133
Category * create_category()
Creates a new category.
Definition: service.cpp:220
Represents a Category combined with GuiState attributes.
Definition: kitmodel.hpp:94
virtual void select_items(ModelItemContainer *items, bool checked=true)
Checks or unchecks all the passed items.
Definition: service.cpp:238
std::vector< Item * > ItemContainer
Definition: item.hpp:91
virtual void show_unchecked_only()
Sets the filter to show only unchecked items.
Definition: service.hpp:77
virtual void show_checked_only()
Sets the filter to show only checked items.
Definition: service.hpp:75
virtual bool require_filename()
Indicates whether the implementation of the data model requires a filename.
Definition: kitlistdao.hpp:225
virtual void show_unchecked_only()
Sets the filter to show only unchecked items.
Definition: kitmodel.hpp:183
virtual void show_checked_only()
Sets the filter to show only checked items.
Definition: kitmodel.hpp:181
~Service()
Definition: service.cpp:49
void open_as_xml(const Glib::ustring &filename)
Loads a new data model from the named XML document.
Definition: service.cpp:70
Service(KitListDao &dao)
Loads the data model from the persistence store.
Definition: service.cpp:44
virtual void show_all()
Removes filter. All items are shown.
Definition: kitmodel.hpp:179
ItemContainer * get_items(long cat_id=-1)
Returns a list of items.
Definition: service.cpp:305
std::vector< ModelItem * > ModelItemContainer
Definition: kitmodel.hpp:81
Item * create_item(long cat_id)
Creates a new ModelItem and associates it with the specified category.
Definition: service.cpp:159
bool delete_category(long cat_id)
Flags a category as deleted.
Definition: service.cpp:200
KitModel * load_model()
Loads the data model from the persistence store.
Definition: service.cpp:58
Defines the methods that an implementation of this class must implement.
Definition: kitlistdao.hpp:46
Represents an Item.
Definition: item.hpp:37
void save_as_xml(const Glib::ustring &filename)
Saves the model&#39;s state to an XML document.
Definition: service.cpp:111
CategoryContainer * get_categories()
Returns a list of all categories.
Definition: service.cpp:354
bool update_item(long id, const std::string description, bool checked)
Updates the attributes of an item.
Definition: service.cpp:282
void save()
Definition: service.cpp:98
Represents a Category.
Definition: category.hpp:37
Represents an Item combined with GuiState attributes.
Definition: kitmodel.hpp:60
Holds a rich graph of objects representing the application&#39;s data model.
Definition: kitmodel.hpp:135
virtual void toggle_selected_items(ModelItemContainer *items)
Toggles the checked state of all the passed items.
Definition: service.cpp:252
void copy_items(const ModelItemContainer &items, long cat_id)
Copies items to the specified category.
Definition: service.cpp:144
bool delete_item(long id)
Flags an item as deleted.
Definition: service.cpp:180
bool is_model_dirty()
Definition: service.hpp:55
virtual bool is_dirty()
Definition: kitmodel.hpp:177
ItemContainer * get_filtered_items(long cat_id=-1)
Returns a list of items, applying the current filter.
Definition: service.cpp:331
std::vector< Category * > CategoryContainer
Definition: category.hpp:84
virtual bool require_filename()
Definition: service.hpp:80
void set_model_dirty(bool flag=true)
Definition: service.cpp:264
KitListDao & m_dao
Reference to the perisitence data access object.
Definition: service.hpp:40
void create_default_model()
Creates a default model.
Definition: service.cpp:83
ModelItem * find_item(long id)
Definition: service.cpp:125
long get_next_item_id()
Definition: service.cpp:364
virtual bool filter(bool checked)
Applies the current filter.
Definition: service.hpp:63
Business/service layer implementation.
Definition: service.hpp:38
long get_next_category_id()
Definition: service.cpp:372
virtual void show_all()
Removes filter. All items are shown.
Definition: service.hpp:73
KitModel * m_model
The application&#39;s data model.
Definition: service.hpp:41

Copyright 2008-2021 Frank Dean