2
* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License as
6
* published by the Free Software Foundation; version 2 of the
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20
#include "db_object_master_filter.h"
21
#include "db_object_filter.h"
25
DBObjectMasterFilterBE::DBObjectMasterFilterBE(GRTManager *grtm)
28
grt::GRT *grt= _grtm->get_grt();
30
// load stored filter sets
31
grt::DictRef opt= grt::DictRef::cast_from(grt->get("/wb/options/options"));
32
_stored_master_filter_sets_filepath
33
.append(_grtm->get_user_datadir())
34
.append("/stored_master_filter_sets.xml");
35
if (g_file_test(_stored_master_filter_sets_filepath.c_str(), G_FILE_TEST_EXISTS))
36
_stored_master_filter_sets= grt::DictRef::cast_from(
37
grt->unserialize(_stored_master_filter_sets_filepath));
38
if (!_stored_master_filter_sets.is_valid())
39
_stored_master_filter_sets= grt::DictRef(grt);
43
void DBObjectMasterFilterBE::add_filter(DBObjectFilterBE *filter)
45
_filters.push_back(filter);
49
void DBObjectMasterFilterBE::remove_all_filters()
55
void DBObjectMasterFilterBE::add_stored_filter_set(const std::string &name, std::list<std::string> &names)
60
grt::GRT *grt= _grtm->get_grt();
62
grt::DictRef stored_filter_sets(grt);
63
_stored_master_filter_sets.set(name, stored_filter_sets);
66
std::list<std::string>::iterator i= names.begin();
67
std::list<std::string>::iterator i_end= names.end();
68
std::vector<DBObjectFilterBE *>::iterator f= _filters.begin();
69
std::vector<DBObjectFilterBE *>::iterator f_end= _filters.end();
70
for (; f != f_end && i != i_end; ++f, ++i)
71
stored_filter_sets.gset((*f)->get_full_type_name(), *i);
74
grt->serialize(_stored_master_filter_sets, _stored_master_filter_sets_filepath);
78
void DBObjectMasterFilterBE::remove_stored_filter_set(int index)
82
grt::DictRef filter_set_names;
83
if (!_stored_master_filter_sets.get_by_index(index, key, filter_set_names))
85
_stored_master_filter_sets.remove(key);
87
_grtm->get_grt()->serialize(_stored_master_filter_sets, _stored_master_filter_sets_filepath);
89
throw std::logic_error("needs update");
93
void DBObjectMasterFilterBE::load_stored_filter_set(int index, std::list<int> &indexes)
95
throw std::logic_error("needs update");
100
grt::GRT *grt= _grtm->get_grt();
103
grt::DictRef filter_set_indexes(grt);
105
_stored_master_filter_sets.get_by_index(index, key, filter_set_indexes);
107
for (std::vector<DBObjectFilterBE *>::iterator f= _filters.begin(), f_end= _filters.end(); f != f_end; ++f)
109
std::string name= filter_set_indexes.get_string((*f)->get_full_type_name());
110
DBObjectFilterBE *filter= *f;
111
int index= filter->stored_filter_set_index(name);
112
filter->load_stored_filter_set(index);
114
indexes.push_back(index);
120
void DBObjectMasterFilterBE::load_stored_filter_set_list(std::list<std::string> &names)
124
grt::DictRef stored_filter_sets;
126
//for (size_t n= 0, count= _stored_master_filter_sets.count(); n < count; ++n)
128
// _stored_master_filter_sets.get_by_index(n, key, stored_filter_sets);
129
// names.push_back(key);
132
for (grt::DictRef::const_iterator it= _stored_master_filter_sets.begin();
133
it != _stored_master_filter_sets.end(); it++)
135
names.push_back(it->second.repr());
138
names.push_back(std::string()); // empty value, denoting empty filter set
140
//throw std::logic_error("needs update");