~ubuntu-branches/ubuntu/precise/glom/precise-updates

« back to all changes in this revision

Viewing changes to glom/libglom/document/document.h

  • Committer: Bazaar Package Importer
  • Author(s): Chris Coulson
  • Date: 2009-10-09 16:50:36 UTC
  • mfrom: (1.1.42 upstream)
  • Revision ID: james.westby@ubuntu.com-20091009165036-orinvwmohk838xxl
Tags: 1.12.2-0ubuntu1
* New upstream version:
  - FFE LP: #391664
* debian/control:
  - Bump python-gnome2-extras-dev build-dep to >= 2.25.3.
  - Bump libgdamm3.0-dev build-dep to libgdamm4.0-dev >= 3.99.14.
  - Change libgda3-dev build-dep to libgda-4.0-dev.
  - Change libgda3-postgres dependency to libgda-4.0-postgres.
  - Bump libgtkmm-2.4-dev build-dep to >= 2.14.
  - Add build-dep on libgconfmm-2.6-dev.
  - Bump libgoocanvasmm-dev build-dep to >= 0.14.0.
  - Remove build-dep on libbakery-2.6-dev.
  - Bump postgresql-8.3 dependency to postgresql-8.4.
  - Change scrollkeeper build-dep to rarian-compat.
  - Rename libglom{0,-dev} -> libglom-1.12-{0,dev}. Upstream include
    APIVER in the library name now.
* debian/rules:
  - Update --with-postgres-utils configure flag to point to the new
    path.
  - Drop deprecated --disable-scrollkeeper configure flag.
  - Update DEB_SHLIBDEPS_INCLUDE with new libglom-1.12-0 package name.
  - Don't include /usr/share/cdbs/1/rules/simple-patchsys.mk - there
    are currently no patches.
* debian/libglom-1.12-0.install:
  - Updated for new version.
* debian/libglom-1.12-dev.install:
  - Install pc and header files.
* debian/glom-doc.install:
  - Updated for new version.
* debian/glom.install:
  - Updated for new version.
* Fix debian/watch.
* Dropped obsolete 10-distro-install-postgres-change.patch.
* Built against latest libgoocanvasmm (LP: #428445).
* Also closes LP: #230007, LP: #393229, LP: #393231, LP: #394507,
  LP: #394887, LP: #394894, LP: #397409, LP: #381563.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Glom
 
2
 *
 
3
 * Copyright (C) 2001-2009 Murray Cumming
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or
 
6
 * modify it under the terms of the GNU General Public License as
 
7
 * published by the Free Software Foundation; either version 2 of the
 
8
 * License, or (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful, but
 
11
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
 * General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public
 
16
 * License along with this program; if not, write to the
 
17
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
18
 * Boston, MA 02111-1307, USA.
 
19
 */
 
20
 
 
21
#ifndef DOCUMENT_GLOM_H
 
22
#define DOCUMENT_GLOM_H
 
23
 
 
24
#include <libglom/libglom_config.h>
 
25
 
 
26
#include <libglom/document/bakery/document_xml.h>
 
27
#include <libglom/data_structure/relationship.h>
 
28
#include <libglom/data_structure/field.h>
 
29
#include <libglom/data_structure/layout/layoutgroup.h>
 
30
#include <libglom/data_structure/layout/layoutitem_notebook.h>
 
31
#include <libglom/data_structure/layout/layoutitem_portal.h>
 
32
#include <libglom/data_structure/layout/layoutitem_button.h>
 
33
#include <libglom/data_structure/layout/layoutitem_text.h>
 
34
#include <libglom/data_structure/layout/layoutitem_image.h>
 
35
#include <libglom/data_structure/tableinfo.h>
 
36
#include <libglom/data_structure/groupinfo.h>
 
37
#include <libglom/data_structure/report.h>
 
38
#include <libglom/data_structure/print_layout.h>
 
39
#include <libglom/data_structure/foundset.h>
 
40
#include <libglom/appstate.h>
 
41
#include <vector>
 
42
#include <map>
 
43
#include <limits> // for numeric_limits
 
44
 
 
45
namespace Gtk
 
46
{
 
47
class Window;
 
48
}
 
49
 
 
50
namespace Glom
 
51
{
 
52
 
 
53
class Document : public GlomBakery::Document_XML
 
54
{
 
55
public: 
 
56
  Document();
 
57
  virtual ~Document();
 
58
 
 
59
  virtual void set_modified(bool value = true);
 
60
 
 
61
  virtual void set_file_uri(const Glib::ustring& file_uri, bool bEnforceFileExtension = false);
 
62
 
 
63
  /* Loads data from disk, using the URI (set with set_file_uri()) then asks the View to update itself.
 
64
   * bool indicates success.
 
65
   * This is just here so the SWIG Java API generator does not need to wrap methods from the base classes.
 
66
   */
 
67
  bool load(int& failure_code);
 
68
  
 
69
  
 
70
  /** Whether the document was opened from another networked glom instance, 
 
71
   * instead of via a URI.
 
72
   */
 
73
  void set_opened_from_browse(bool val = true);
 
74
  bool get_opened_from_browse() const;
 
75
 
 
76
  /** The document usually saves itself when you call set_modified().
 
77
   * Pass false to this function to prevent that temporarily.
 
78
   * The document will be saved, if necessary, after you call this function with true.
 
79
   */
 
80
  void set_allow_autosave(bool value = true);
 
81
 
 
82
  bool get_is_example_file() const;
 
83
  void set_is_example_file(bool value = true);
 
84
 
 
85
  /* Get version of the document format used for this document.
 
86
   *  This can increase when the file has been re-saved.
 
87
   *  See get_latest_known_document_format_version().
 
88
   *  Old versions of the application cannot open documents with a newer document format,
 
89
   *  so saving with a version of the application that has a newer document format will 
 
90
   *  make it impossible to open the document in a version of the application with an older document format.
 
91
   */  
 
92
  guint get_document_format_version();
 
93
 
 
94
  static guint get_latest_known_document_format_version();
 
95
 
 
96
  /// How the database is hosted.
 
97
  enum HostingMode
 
98
  {
 
99
    HOSTING_MODE_POSTGRES_CENTRAL, /*!< The database is hosted on an external postgresql server. */
 
100
    HOSTING_MODE_POSTGRES_SELF, /*!< A new postgres database process is spawned that hosts the data. */
 
101
    HOSTING_MODE_SQLITE, /*!< A sqlite database file is used. */
 
102
    HOSTING_MODE_DEFAULT = HOSTING_MODE_POSTGRES_SELF /*!- Arbitrary default. */
 
103
  };
 
104
 
 
105
  /** Set the hosting mode of the database. 
 
106
   */
 
107
  void set_hosting_mode(HostingMode mode);
 
108
 
 
109
  /** This returns how the database is hosted.
 
110
   */
 
111
  HostingMode get_hosting_mode() const;
 
112
 
 
113
  /** Whether the database (and document) is shared over the network.
 
114
   * This setting is saved in the file, allowing the database to be 
 
115
   * shared immediately after opening the document.
 
116
   * @param shared true if the database should be shared.
 
117
   */
 
118
  void set_network_shared(bool shared = true);
 
119
 
 
120
  /** See set_network_shared().
 
121
   * @result true if the database is (or should be) shared over the network.
 
122
   */
 
123
  bool get_network_shared() const;
 
124
 
 
125
  void set_connection_server(const Glib::ustring& strVal);
 
126
  void set_connection_database(const Glib::ustring& strVal);
 
127
  void set_connection_port(int port_number);
 
128
  void set_connection_try_other_ports(bool val);
 
129
 
 
130
 /** Temporarily set a username in the document.
 
131
   * Note that this is not saved in the document's file.
 
132
   *
 
133
   * TODO: Remove this, and just store it in ConnectionPool?
 
134
   */
 
135
  void set_connection_user(const Glib::ustring& strVal);
 
136
 
 
137
  /** If the database should be hosted, this provides the 
 
138
    * path to the directory that contains all the files needed to do that.
 
139
    * This is usually a specifically-named directory at the same level as the .glom file. 
 
140
    * If the database is a sqlite database, this specifies the directory in
 
141
    * which the database file is in.
 
142
    */   
 
143
  std::string get_connection_self_hosted_directory_uri() const;
 
144
 
 
145
  Glib::ustring get_connection_server() const;
 
146
  Glib::ustring get_connection_database() const;
 
147
  int get_connection_port() const;
 
148
  bool get_connection_try_other_ports() const;
 
149
 
 
150
  /** Retrieve a username previously set in the document.
 
151
   * Note that this is not saved in the document's file.
 
152
   *
 
153
   * TODO: Remove this, and just store it in ConnectionPool?
 
154
   */
 
155
  Glib::ustring get_connection_user() const;
 
156
 
 
157
  /** Set the language/locale used by original titles.
 
158
   * Title translations are translations of the text in this language.
 
159
   * @param locale: For instance, "en_US.UTF-8".
 
160
   */
 
161
  void set_translation_original_locale(const Glib::ustring& locale);
 
162
 
 
163
  /** Get the language/locale used by original titles.
 
164
   * Title translations are translations of the text in this language.
 
165
   */
 
166
  Glib::ustring get_translation_original_locale() const;
 
167
 
 
168
  typedef std::vector< sharedptr<Relationship> > type_vec_relationships;
 
169
  type_vec_relationships get_relationships(const Glib::ustring& table_name, bool plus_system_prefs = false) const;
 
170
  void set_relationships(const Glib::ustring& table_name, const type_vec_relationships& vecRelationships);
 
171
 
 
172
  sharedptr<Relationship> get_relationship(const Glib::ustring& table_name, const Glib::ustring& relationship_name) const;
 
173
  void set_relationship(const Glib::ustring& table_name, const sharedptr<Relationship>& relationship);
 
174
 
 
175
  void remove_relationship(const sharedptr<const Relationship>& relationship);
 
176
 
 
177
  /** Returns whether the relationship's to-field is a primary key  or unique field, meaning
 
178
   * that there can be only one related record for each value of the from-field.
 
179
   */
 
180
  bool get_relationship_is_to_one(const Glib::ustring& table_name, const Glib::ustring& relationship_name) const;
 
181
 
 
182
  /** Returns whether the field is the from-field in a to-one relationship.
 
183
   * @see get_relationship_is_to_one(). Ignores hidden tables.
 
184
   */
 
185
  sharedptr<Relationship> get_field_used_in_relationship_to_one(const Glib::ustring& table_name, const sharedptr<const LayoutItem_Field>& layout_field) const;
 
186
 
 
187
  typedef std::vector< sharedptr<Field> > type_vec_fields;
 
188
  type_vec_fields get_table_fields(const Glib::ustring& table_name) const;
 
189
  void set_table_fields(const Glib::ustring& table_name, const type_vec_fields& vecFields);
 
190
 
 
191
  sharedptr<Field> get_field(const Glib::ustring& table_name, const Glib::ustring& strFieldName) const;
 
192
 
 
193
  /** Use this after removing a field from a table,
 
194
   * so that it is not used anymore in relationships, layouts, reports, etc.
 
195
   */
 
196
  void remove_field(const Glib::ustring& table_name, const Glib::ustring& field_name);
 
197
 
 
198
 
 
199
  typedef std::vector< sharedptr<LayoutGroup> > type_list_layout_groups;
 
200
 
 
201
  /** Get the layout groups for a layout.
 
202
   * @param layout_name The name of the layout, such as list or details.
 
203
   * @param parent_table_name The name of the table for which this layout should appear.
 
204
   * @param layout_platform The platform for which this layout should be used. Possible values are an empty string (meaning normal platforms) or "maemo" meaning "normal". 
 
205
   * @result A list of layout groups at the top-level of the requested layout.
 
206
   */
 
207
  type_list_layout_groups get_data_layout_groups(const Glib::ustring& layout_name, const Glib::ustring& parent_table_name, const Glib::ustring& layout_platform = Glib::ustring()) const;
 
208
 
 
209
  /** Discover whether there are any fields in the layout.
 
210
   * @param layout_name The name of the layout, such as list or details.
 
211
   * @param parent_table_name The name of the table for which this layout should appear.
 
212
   * @param layout_platform The platform for which this layout should be used. Possible values are an empty string (meaning normal platforms) or "maemo" meaning "normal". 
 
213
   * @result true if there is at least one field in the layout group or its sub groups.
 
214
   */
 
215
  bool get_data_layout_groups_have_any_fields(const Glib::ustring& layout_name, const Glib::ustring& parent_table_name, const Glib::ustring& layout_platform = Glib::ustring()) const;
 
216
 
 
217
  /** Set the layout groups for a layout.
 
218
   * @param layout_name The name of the layout, such as list or details.
 
219
   * @param parent_table_name The name of the table for which this layout should appear.
 
220
   * @param layout_platform The platform for which this layout should be used. Possible values are an empty string (meaning normal platforms) or "maemo" meaning "normal". 
 
221
   * @param groups A list of layout groups at the top-level of the requested layout.
 
222
   */
 
223
  void set_data_layout_groups(const Glib::ustring& layout_name, const Glib::ustring& parent_table_name, const Glib::ustring& layout_platform, const type_list_layout_groups& groups);
 
224
 
 
225
  /**
 
226
   * @para The layout_name, such as "details", "list".
 
227
   * @para parent_table_name The name of the table on whose layout the layout appears.
 
228
   * @param layout_platform The platform for which this layout should be used. Possible values are an empty string (meaning normal platforms) or "maemo" meaning "normal". 
 
229
   */
 
230
  type_list_layout_groups get_data_layout_groups_plus_new_fields(const Glib::ustring& layout_name, const Glib::ustring& parent_table_name, const Glib::ustring& layout_platform = Glib::ustring()) const;
 
231
 
 
232
  type_list_layout_groups get_data_layout_groups_default(const Glib::ustring& layout_name, const Glib::ustring& parent_table_name, const Glib::ustring& layout_platform = Glib::ustring()) const;
 
233
 
 
234
  typedef std::list< sharedptr<TranslatableItem> > type_list_translatables;
 
235
  type_list_translatables get_translatable_layout_items(const Glib::ustring& table_name);
 
236
  type_list_translatables get_translatable_report_items(const Glib::ustring& table_name, const Glib::ustring& report_title);
 
237
 
 
238
  void fill_layout_field_details(const Glib::ustring& parent_table_name, const sharedptr<LayoutGroup>& layout_group) const;
 
239
  void fill_layout_field_details(const Glib::ustring& parent_table_name, type_list_layout_groups& groups) const;
 
240
 
 
241
 
 
242
 
 
243
  ///When a field name is changed, change it in the relationships, layouts, reports, and fields data:
 
244
  void change_field_name(const Glib::ustring& table_name, const Glib::ustring& strFieldNameOld, const Glib::ustring& strFieldNameNew);
 
245
 
 
246
  ///When a table name is changed, change it in the relationships and tables data:
 
247
  void change_table_name(const Glib::ustring& table_name_old, const Glib::ustring& table_name_new);
 
248
 
 
249
  ///When a relationship name is changed, change it in layouts and reports:
 
250
  void change_relationship_name(const Glib::ustring& table_name, const Glib::ustring& name, const Glib::ustring& name_new);
 
251
 
 
252
  typedef std::list< sharedptr<TableInfo> > type_listTableInfo;
 
253
  type_listTableInfo get_tables(bool plus_system_prefs = false) const;
 
254
  std::vector<Glib::ustring> get_table_names(bool plus_system_prefs = false) const;
 
255
 
 
256
  void set_tables(const type_listTableInfo& tables);
 
257
 
 
258
  sharedptr<TableInfo> get_table(const Glib::ustring& table_name) const;
 
259
  void add_table(const  sharedptr<TableInfo>& table_name);
 
260
 
 
261
  /** Use this after DROPing the table.
 
262
   * It removes information about the table, including fields and layouts,
 
263
   * and any place that parts of the table are used.
 
264
   */
 
265
  void remove_table(const Glib::ustring& table_name);
 
266
 
 
267
  bool get_table_is_known(const Glib::ustring& table_name) const;
 
268
  bool get_table_is_hidden(const Glib::ustring& table_name) const;
 
269
 
 
270
  Glib::ustring get_table_title(const Glib::ustring& table_name) const;
 
271
  void set_table_title(const Glib::ustring& table_name, const Glib::ustring& value);
 
272
 
 
273
  typedef std::vector< Gnome::Gda::Value > type_row_data;
 
274
  typedef std::vector< type_row_data > type_example_rows;
 
275
 
 
276
  /** Save example data into the document, for use when creating the example database on the server.
 
277
   * Don't use this for large amounts of data.
 
278
   * @param table_name The table that should contain this example data.
 
279
   * @param rows Each row is separated by a newline. Each line has comma-separated field values, in SQL format.
 
280
   */
 
281
  void set_table_example_data(const Glib::ustring& table_name, const type_example_rows& rows);
 
282
 
 
283
  type_example_rows get_table_example_data(const Glib::ustring& table_name) const;
 
284
 
 
285
  virtual Glib::ustring get_name() const; //override.
 
286
 
 
287
  Glib::ustring get_default_table() const;
 
288
  Glib::ustring get_first_table() const;
 
289
 
 
290
  Glib::ustring get_database_title() const;
 
291
  void set_database_title(const Glib::ustring& title);
 
292
 
 
293
  std::vector<Glib::ustring> get_library_module_names() const;
 
294
  void set_library_module(const Glib::ustring& name, const Glib::ustring& script);
 
295
  Glib::ustring get_library_module(const Glib::ustring& name) const;
 
296
  void remove_library_module(const Glib::ustring& name);
 
297
 
 
298
  /// These are only used when recreating a database from an example file. The actualy access-control is on the server, of course.
 
299
  typedef std::list<GroupInfo> type_list_groups;
 
300
  type_list_groups get_groups() const;
 
301
 
 
302
  /// This adds the group if necessary.
 
303
  void set_group(GroupInfo& group);
 
304
 
 
305
  void remove_group(const Glib::ustring& group_name);
 
306
 
 
307
 
 
308
  typedef std::list<Glib::ustring> type_listReports;
 
309
  type_listReports get_report_names(const Glib::ustring& table_name) const;
 
310
  void remove_all_reports(const Glib::ustring& table_name);
 
311
 
 
312
  void set_report(const Glib::ustring& table_name, const sharedptr<Report>& report);
 
313
  sharedptr<Report> get_report(const Glib::ustring& table_name, const Glib::ustring& report_name) const;
 
314
  void remove_report(const Glib::ustring& table_name, const Glib::ustring& report_name);
 
315
 
 
316
  //Print Layouts are precisely positioned layouts for printing to a printer:
 
317
  typedef std::list<Glib::ustring> type_listPrintLayouts;
 
318
  type_listPrintLayouts get_print_layout_names(const Glib::ustring& table_name) const;
 
319
  void remove_all_print_layouts(const Glib::ustring& table_name);
 
320
  void set_print_layout(const Glib::ustring& table_name, const sharedptr<PrintLayout>& print_layout);
 
321
  sharedptr<PrintLayout> get_print_layout(const Glib::ustring& table_name, const Glib::ustring& print_layout_name) const;
 
322
  void remove_print_layout(const Glib::ustring& table_name, const Glib::ustring& print_layout_name);
 
323
 
 
324
  void set_layout_record_viewed(const Glib::ustring& table_name, const Glib::ustring& layout_name, const Gnome::Gda::Value& primary_key_value);
 
325
  void forget_layout_record_viewed(const Glib::ustring& table_name);
 
326
  Gnome::Gda::Value get_layout_record_viewed(const Glib::ustring& table_name, const Glib::ustring& layout_name) const;
 
327
 
 
328
  //TODO: Rename set_layout_current() and set_criteria_current().
 
329
 
 
330
  /** Temporarily save (but not in the document) the last-viewed layout for the table,
 
331
   * so we can show the same layout when navigating back to this table later.
 
332
   * 
 
333
   * @param table_name The table.
 
334
   * @param layout_name The layout name, such as "list" or "details".
 
335
   */
 
336
  void set_layout_current(const Glib::ustring& table_name, const Glib::ustring& layout_name);
 
337
 
 
338
  /** Temporarily save (but not in the document) the last-viewed criteria for the table,
 
339
   * so we can show the same criteria (sort order, where clause) when navigating back to this table later.
 
340
   * 
 
341
   * @param table_name The table.
 
342
   * @param found_set Additional information about the last use of that layout, such as the sort order or where clause.
 
343
   */
 
344
  void set_criteria_current(const Glib::ustring& table_name,const FoundSet& found_set);
 
345
 
 
346
  Glib::ustring get_layout_current(const Glib::ustring& table_name) const;
 
347
 
 
348
  FoundSet get_criteria_current(const Glib::ustring& table_name) const;
 
349
 
 
350
#ifndef SWIG //Hide this API from swig.
 
351
  // Used by Relationship Overview dialog to preserve table locations accross instantiations:
 
352
    
 
353
  /** Retrieve the x and y coordinates for the given table position in the relationship overview dialog.
 
354
   * 
 
355
   * @param table_name The name of the table to query.
 
356
   * @param x The x coordinate of the table position.
 
357
   * @param y The y coordinate of the table position.
 
358
   * @return false if the table does not have any position for this table.
 
359
   */
 
360
  bool get_table_overview_position( const Glib::ustring& table_name, float &x, float &y ) const;
 
361
    
 
362
  /** Set the position of a table in the relationship overview dialog.
 
363
   * 
 
364
   * @param table_name The name of the table to modify.
 
365
   * @param x The x coordinate of the table position.
 
366
   * @param y The y coordinate of the table position.
 
367
   */
 
368
  void set_table_overview_position( const Glib::ustring& utable_name, float x, float y );
 
369
    
 
370
  enum userLevelReason
 
371
  {
 
372
    USER_LEVEL_REASON_UNKNOWN,
 
373
    USER_LEVEL_REASON_FILE_READ_ONLY,
 
374
    USER_LEVEL_REASON_DATABASE_ACCESS_LEVEL,
 
375
    USER_LEVEL_REASON_OPENED_FROM_BROWSE
 
376
  };
 
377
 
 
378
  /**
 
379
   * @param reason The reason that the user is not a developer, if he is not.
 
380
   * @result Whether the user is a developer.
 
381
   */
 
382
  AppState::userlevels get_userlevel(userLevelReason& reason) const;
 
383
 
 
384
  AppState::userlevels get_userlevel() const;
 
385
 
 
386
  /** This is transitory information, not saved to disk.
 
387
   */
 
388
  bool set_userlevel(AppState::userlevels userlevel);
 
389
 
 
390
  typedef sigc::signal<void, AppState::userlevels> type_signal_userlevel_changed;
 
391
  type_signal_userlevel_changed signal_userlevel_changed();
 
392
 
 
393
  //TODO: This is a rather indirect way for application.cc to request the UI to update for the userlevel.
 
394
  void emit_userlevel_changed();
 
395
#endif //SWIG
 
396
 
 
397
  /** This is transitory information, not saved to disk.
 
398
   */
 
399
  Glib::ustring get_active_layout_platform() const;
 
400
 
 
401
  /** This is transitory information, not saved to disk.
 
402
   */
 
403
  void set_active_layout_platform(const Glib::ustring& layout_platform = Glib::ustring());
 
404
 
 
405
  /** Change any non-maemo layouts so their groups never have multiple columns, 
 
406
   * because this could never be displayed on the Maemo screen.
 
407
   * This allows layouts to be shown fairly sanely on Maemo even if no custom 
 
408
   * maemo layout was defined.
 
409
   * This does not save the change to disk.
 
410
   */
 
411
  void maemo_restrict_layouts_to_single_column();
 
412
 
 
413
#ifndef SWIG //Hide this API from swig.
 
414
  Glib::ustring build_and_get_contents() const;
 
415
 
 
416
protected:
 
417
 
 
418
 
 
419
  //TODO: Remove this:
 
420
  friend class ReportBuilder;
 
421
 
 
422
  ///If value is equal to the default then no attribute will be set, to save text space in the XML file.
 
423
  static void set_node_attribute_value_as_decimal(xmlpp::Element* node, const Glib::ustring& strAttributeName, guint value, guint value_default = 0);
 
424
  
 
425
  // This is required by the report builder, so it cannot be disabled
 
426
  // in client only mode
 
427
  static void set_node_attribute_value_as_decimal_double(xmlpp::Element* node, const Glib::ustring& strAttributeName, double value);
 
428
#endif //SWIG
 
429
 
 
430
#ifndef SWIG
 
431
public:
 
432
  static sharedptr<TableInfo> create_table_system_preferences();
 
433
  static sharedptr<TableInfo> create_table_system_preferences(type_vec_fields& fields);
 
434
  static sharedptr<Relationship> create_relationship_system_preferences(const Glib::ustring& table_name);
 
435
  static bool get_relationship_is_system_properties(const sharedptr<const Relationship>& relationship);
 
436
#endif //SWIG
 
437
 
 
438
  /// Failure codes that could be returned by load_after()
 
439
  enum load_failure_codes
 
440
  {
 
441
    // The error codes must start at 1, so do that here:
 
442
    LOAD_FAILURE_CODE_FILE_VERSION_TOO_NEW = 1
 
443
  };
 
444
 
 
445
private:
 
446
  //Overrides:
 
447
 
 
448
  virtual bool save_before();
 
449
  void save_before_layout_group(xmlpp::Element* node, const sharedptr<const LayoutGroup>& group, bool with_print_layout_positions = false);
 
450
  void save_before_sort_by(xmlpp::Element* node, const LayoutItem_GroupBy::type_list_sort_fields& list_fields);
 
451
  void save_before_layout_item_usesrelationship(xmlpp::Element* nodeItem, const sharedptr<const UsesRelationship>& item);
 
452
  void save_before_layout_item_field(xmlpp::Element* nodeItem, const sharedptr<const LayoutItem_Field>& item);
 
453
  void save_before_layout_item_formatting(xmlpp::Element* nodeItem, const FieldFormatting& format, Field::glom_field_type field_type = Field::TYPE_INVALID);
 
454
 
 
455
  void save_before_translations(xmlpp::Element* nodeItem, const TranslatableItem& item);
 
456
  void save_before_print_layout_position(xmlpp::Element* nodeItem, const sharedptr<const LayoutItem>& item);
 
457
 
 
458
  void save_changes();
 
459
 
 
460
  virtual bool load_after(int& failure_code);
 
461
  void load_after_layout_group(const xmlpp::Element* node, const Glib::ustring& table_name, const sharedptr<LayoutGroup>& group, bool with_print_layout_positions = false);
 
462
  void load_after_sort_by(const xmlpp::Element* node, const Glib::ustring& table_name, LayoutItem_GroupBy::type_list_sort_fields& list_fields);
 
463
  void load_after_layout_item_usesrelationship(const xmlpp::Element* element, const Glib::ustring& table_name, const sharedptr<UsesRelationship>& item);
 
464
  void load_after_layout_item_field(const xmlpp::Element* element, const Glib::ustring& table_name, const sharedptr<LayoutItem_Field>& item);
 
465
  void load_after_layout_item_formatting(const xmlpp::Element* element, FieldFormatting& format, Field::glom_field_type field_type = Field::TYPE_INVALID, const Glib::ustring& table_name = Glib::ustring(), const Glib::ustring& field_name = Glib::ustring());
 
466
 
 
467
  void load_after_translations(const xmlpp::Element* element, TranslatableItem& item);
 
468
  void load_after_print_layout_position(const xmlpp::Element* nodeItem, const sharedptr<LayoutItem>& item);
 
469
 
 
470
  void on_app_state_userlevel_changed(AppState::userlevels userlevel);
 
471
 
 
472
  void fill_translatable_layout_items(const sharedptr<LayoutGroup>& group, type_list_translatables& the_list);
 
473
 
 
474
 
 
475
  /// If the attribute is not there, then the default will be returned.
 
476
  static bool get_node_attribute_value_as_bool(const xmlpp::Element* node, const Glib::ustring& strAttributeName, bool value_default = false);
 
477
  static guint get_node_attribute_value_as_decimal(const xmlpp::Element* node, const Glib::ustring& strAttributeName, guint value_default = 0);
 
478
  static double get_node_attribute_value_as_decimal_double(const xmlpp::Element* node, const Glib::ustring& strAttributeName);
 
479
  static float get_node_attribute_value_as_float(const xmlpp::Element* node, const Glib::ustring& strAttributeName);
 
480
 
 
481
  static void set_node_attribute_value_as_bool(xmlpp::Element* node, const Glib::ustring& strAttributeName, bool value = true, bool value_default = false);
 
482
  static void set_node_attribute_value_as_float( xmlpp::Element* node, const Glib::ustring& strAttributeName, float value );
 
483
  static void set_node_attribute_value_as_value(xmlpp::Element* node, const Glib::ustring& strAttributeName, const Gnome::Gda::Value& value, Field::glom_field_type field_type);
 
484
  static void set_node_text_child_as_value(xmlpp::Element* node, const Gnome::Gda::Value& value, Field::glom_field_type field_type);
 
485
 
 
486
  static Gnome::Gda::Value get_node_attribute_value_as_value(const xmlpp::Element* node, const Glib::ustring& strAttributeName, Field::glom_field_type field_type);
 
487
  static Gnome::Gda::Value get_node_text_child_as_value(const xmlpp::Element* node, Field::glom_field_type field_type);
 
488
 
 
489
  Glib::ustring get_child_text_node(const xmlpp::Element* node, const Glib::ustring& child_node_name) const;
 
490
  void set_child_text_node(xmlpp::Element* node, const Glib::ustring& child_node_name, const Glib::ustring& text);
 
491
 
 
492
  ///A recursive helper function.
 
493
  static void maemo_restrict_layouts_to_single_column_group(const sharedptr<LayoutGroup>& layout_group);
 
494
  
 
495
  AppState m_app_state;
 
496
  type_signal_userlevel_changed m_signal_userlevel_changed;
 
497
 
 
498
  HostingMode m_hosting_mode;
 
499
  bool m_network_shared;
 
500
 
 
501
  Glib::ustring m_connection_server, m_connection_database;
 
502
  Glib::ustring m_connection_user; //Don't save the user.
 
503
  int m_connection_port; //0 means any port. Ignored when self-hosting (which may use a different port each time).
 
504
  bool m_connection_try_other_ports; //Set to false for self-hosted or browsed-from-network documents.
 
505
 
 
506
  class LayoutInfo
 
507
  {
 
508
  public:
 
509
    Glib::ustring m_layout_name;
 
510
    Glib::ustring m_layout_platform; //Empty string (meaning normal platforms), or "maemo", or something else.
 
511
    Glib::ustring m_parent_table;
 
512
 
 
513
    type_list_layout_groups m_layout_groups;
 
514
  };
 
515
 
 
516
  class DocumentTableInfo
 
517
  {
 
518
  public:
 
519
    DocumentTableInfo()
 
520
      : m_overviewx ( std::numeric_limits<float>::infinity () ),
 
521
        m_overviewy ( std::numeric_limits<float>::infinity () )
 
522
    {
 
523
      m_info = sharedptr<TableInfo>(new TableInfo()); //Avoid a null sharedptr.
 
524
    }
 
525
 
 
526
    //TODO: Avoid the use of this:
 
527
    DocumentTableInfo(const DocumentTableInfo& src)
 
528
      : m_info(src.m_info),
 
529
        m_fields(src.m_fields),
 
530
        m_relationships(src.m_relationships),
 
531
        m_layouts(src.m_layouts),
 
532
        m_reports(src.m_reports),
 
533
        m_print_layouts(src.m_print_layouts),
 
534
        m_example_rows(src.m_example_rows),
 
535
        m_map_current_record(src.m_map_current_record),
 
536
        m_layout_current(src.m_layout_current),
 
537
        m_foundset_current(src.m_foundset_current),
 
538
        m_overviewx(src.m_overviewx),
 
539
        m_overviewy(src.m_overviewy)
 
540
    {
 
541
    }
 
542
 
 
543
    //TODO: Avoid the use of this:
 
544
    DocumentTableInfo& operator=(const DocumentTableInfo& src)
 
545
    {
 
546
      m_info = src.m_info;
 
547
      m_fields = src.m_fields;
 
548
      m_relationships = src.m_relationships;
 
549
      m_layouts = src.m_layouts;
 
550
      m_reports = src.m_reports;
 
551
      m_print_layouts = src.m_print_layouts;
 
552
      m_example_rows = src.m_example_rows;
 
553
      m_map_current_record = src.m_map_current_record;
 
554
      m_layout_current = src.m_layout_current;
 
555
      m_foundset_current = src.m_foundset_current;
 
556
      m_overviewx = src.m_overviewx;
 
557
      m_overviewy = src.m_overviewy;
 
558
 
 
559
      return *this;
 
560
    }
 
561
 
 
562
    sharedptr<TableInfo> m_info;
 
563
 
 
564
    type_vec_fields m_fields;
 
565
    type_vec_relationships m_relationships;
 
566
 
 
567
    typedef std::list< LayoutInfo > type_layouts;
 
568
    type_layouts m_layouts;
 
569
 
 
570
    typedef std::map< Glib::ustring, sharedptr<Report> > type_reports; //map of report names to reports
 
571
    type_reports m_reports;
 
572
 
 
573
    typedef std::map< Glib::ustring, sharedptr<PrintLayout> > type_print_layouts; //map of print layout names to print layouts
 
574
    type_print_layouts m_print_layouts;
 
575
 
 
576
    //Example data, used when creating a database from an example.
 
577
    type_example_rows m_example_rows;
 
578
 
 
579
    //Per-session, not saved in document:
 
580
    typedef std::map<Glib::ustring, Gnome::Gda::Value> type_map_layout_primarykeys;
 
581
    type_map_layout_primarykeys m_map_current_record; //The record last viewed in each layout.
 
582
    Glib::ustring m_layout_current;
 
583
    FoundSet m_foundset_current;
 
584
    
 
585
    float m_overviewx, m_overviewy;
 
586
  };
 
587
 
 
588
  DocumentTableInfo& get_table_info_with_add(const Glib::ustring& table_name);
 
589
 
 
590
  typedef std::map<Glib::ustring, DocumentTableInfo> type_tables;
 
591
  type_tables m_tables;
 
592
 
 
593
 
 
594
  //User groups:
 
595
  typedef std::map<Glib::ustring, GroupInfo> type_map_groups;
 
596
  type_map_groups m_groups;
 
597
 
 
598
  Glib::ustring m_database_title;
 
599
  Glib::ustring m_translation_original_locale;
 
600
 
 
601
  typedef std::map<Glib::ustring, Glib::ustring> type_map_library_scripts;
 
602
  type_map_library_scripts m_map_library_scripts;
 
603
 
 
604
  bool m_block_cache_update; //For efficiency.
 
605
  bool m_block_modified_set;
 
606
  bool m_allow_auto_save;
 
607
  bool m_is_example;
 
608
  guint m_document_format_version;
 
609
 
 
610
  bool m_opened_from_browse;
 
611
 
 
612
  Glib::ustring m_active_layout_platform; //empty (means normal), or "maemo".
 
613
};
 
614
 
 
615
} //namespace Glom
 
616
 
 
617
#endif //DOCUMENT_GLOM_H