~ubuntu-branches/ubuntu/quantal/mysql-workbench/quantal

« back to all changes in this revision

Viewing changes to backend/wbpublic/grtdb/db_object_master_filter.cpp

  • Committer: Package Import Robot
  • Author(s): Dmitry Smirnov
  • Date: 2012-03-01 21:57:30 UTC
  • Revision ID: package-import@ubuntu.com-20120301215730-o7y8av8y38n162ro
Tags: upstream-5.2.38+dfsg
ImportĀ upstreamĀ versionĀ 5.2.38+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
 
3
 *
 
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
 
7
 * License.
 
8
 * 
 
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.
 
13
 * 
 
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
 
17
 * 02110-1301  USA
 
18
 */
 
19
#include "stdafx.h"
 
20
#include "db_object_master_filter.h"
 
21
#include "db_object_filter.h"
 
22
 
 
23
using namespace bec;
 
24
 
 
25
DBObjectMasterFilterBE::DBObjectMasterFilterBE(GRTManager *grtm)
 
26
  : _grtm(grtm)
 
27
{
 
28
  grt::GRT *grt= _grtm->get_grt();
 
29
 
 
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);
 
40
}
 
41
 
 
42
 
 
43
void DBObjectMasterFilterBE::add_filter(DBObjectFilterBE *filter)
 
44
{
 
45
  _filters.push_back(filter);
 
46
}
 
47
 
 
48
 
 
49
void DBObjectMasterFilterBE::remove_all_filters()
 
50
{
 
51
  _filters.clear();
 
52
}
 
53
 
 
54
 
 
55
void DBObjectMasterFilterBE::add_stored_filter_set(const std::string &name, std::list<std::string> &names)
 
56
{
 
57
  if (_filters.empty())
 
58
    return;
 
59
 
 
60
  grt::GRT *grt= _grtm->get_grt();
 
61
 
 
62
  grt::DictRef stored_filter_sets(grt);
 
63
  _stored_master_filter_sets.set(name, stored_filter_sets);
 
64
 
 
65
  {
 
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);
 
72
  }
 
73
 
 
74
  grt->serialize(_stored_master_filter_sets, _stored_master_filter_sets_filepath);
 
75
}
 
76
 
 
77
 
 
78
void DBObjectMasterFilterBE::remove_stored_filter_set(int index)
 
79
{
 
80
  /*QQQ
 
81
  std::string key;
 
82
  grt::DictRef filter_set_names;
 
83
  if (!_stored_master_filter_sets.get_by_index(index, key, filter_set_names))
 
84
    return;
 
85
  _stored_master_filter_sets.remove(key);
 
86
 
 
87
  _grtm->get_grt()->serialize(_stored_master_filter_sets, _stored_master_filter_sets_filepath);
 
88
  */
 
89
  throw std::logic_error("needs update");
 
90
}
 
91
 
 
92
 
 
93
void DBObjectMasterFilterBE::load_stored_filter_set(int index, std::list<int> &indexes)
 
94
{
 
95
  throw std::logic_error("needs update");
 
96
  /*QQQ
 
97
  if (_filters.empty())
 
98
    return;
 
99
  
 
100
  grt::GRT *grt= _grtm->get_grt();
 
101
 
 
102
  std::string key;
 
103
  grt::DictRef filter_set_indexes(grt);
 
104
 
 
105
  _stored_master_filter_sets.get_by_index(index, key, filter_set_indexes);
 
106
 
 
107
  for (std::vector<DBObjectFilterBE *>::iterator f= _filters.begin(), f_end= _filters.end(); f != f_end; ++f)
 
108
  {
 
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);
 
113
 
 
114
    indexes.push_back(index);
 
115
  }
 
116
  */
 
117
}
 
118
 
 
119
 
 
120
void DBObjectMasterFilterBE::load_stored_filter_set_list(std::list<std::string> &names)
 
121
{
 
122
  ///*QQQ
 
123
  std::string key;
 
124
  grt::DictRef stored_filter_sets;
 
125
 
 
126
  //for (size_t n= 0, count= _stored_master_filter_sets.count(); n < count; ++n)
 
127
  //{
 
128
  //  _stored_master_filter_sets.get_by_index(n, key, stored_filter_sets);
 
129
  //  names.push_back(key);
 
130
  //}
 
131
 
 
132
  for (grt::DictRef::const_iterator it= _stored_master_filter_sets.begin();
 
133
    it != _stored_master_filter_sets.end(); it++)
 
134
  {
 
135
    names.push_back(it->second.repr());
 
136
  }
 
137
 
 
138
  names.push_back(std::string()); // empty value, denoting empty filter set
 
139
  //*/
 
140
  //throw std::logic_error("needs update");
 
141
}