[libgda] Reworked the tools/
- From: Vivien Malerba <vivien src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] Reworked the tools/
- Date: Sat, 20 Sep 2014 14:41:10 +0000 (UTC)
commit 22e4ec0c0b547118608546cd0b42ee584f20bb82
Author: Vivien Malerba <malerba gnome-db org>
Date: Sat Sep 20 16:33:45 2014 +0200
Reworked the tools/
configure.ac | 15 +-
control-center/gdaui-bar.c | 48 +
control-center/gdaui-bar.h | 21 +-
tests/multi-threading/dummy-object.c | 107 +-
tests/multi-threading/dummy-object.h | 1 +
tools/.gitignore | 1 +
tools/Makefile.am | 182 +-
tools/README | 6 +-
tools/base/Makefile.am | 25 +
.../tool-command.c => base/base-tool-command.c} | 109 +-
.../tool-command.h => base/base-tool-command.h} | 70 +-
.../{cmdtool/tool-decl.h => base/base-tool-decl.h} | 14 +-
.../tool-defines.h => base/base-tool-defines.h} | 12 +-
.../tool-errors.c => base/base-tool-errors.c} | 6 +-
.../tool-errors.h => base/base-tool-errors.h} | 14 +-
.../{cmdtool/tool-help.c => base/base-tool-help.c} | 321 +-
.../{cmdtool/tool-help.h => base/base-tool-help.h} | 12 +-
.../tool-input.c => base/base-tool-input.c} | 143 +-
.../tool-input.h => base/base-tool-input.h} | 29 +-
.../tool-output.c => base/base-tool-output.c} | 138 +-
.../tool-output.h => base/base-tool-output.h} | 35 +-
tools/{cmdtool/tool.h => base/base-tool.h} | 16 +-
tools/browser/.gitignore | 8 +-
tools/browser/Makefile.am | 194 +-
tools/browser/auth-dialog.c | 171 +-
tools/browser/auth-dialog.h | 11 +-
tools/browser/browser-connection-priv.h | 48 -
tools/browser/browser-connection.c | 1929 ------
tools/browser/browser-connection.h | 207 -
tools/browser/browser-connections-list.c | 117 +-
tools/browser/browser-connections-list.h | 5 +-
tools/browser/browser-page.h | 2 +-
tools/browser/browser-perspective.c | 139 +-
tools/browser/browser-perspective.h | 20 +-
tools/browser/browser-spinner.c | 76 -
tools/browser/browser-spinner.h | 29 -
tools/browser/browser-stock-icons.c | 97 -
tools/browser/browser-stock-icons.h | 47 -
tools/browser/browser-variable.c | 122 -
tools/browser/browser-variable.h | 54 -
tools/browser/browser-virtual-connection.h | 94 -
tools/browser/browser-window.c | 421 +-
tools/browser/browser-window.h | 14 +-
tools/browser/canvas-example.c | 168 -
tools/browser/canvas/Makefile.am | 43 -
tools/browser/canvas/browser-canvas-column.c | 330 --
tools/browser/canvas/browser-canvas-column.h | 64 -
tools/browser/canvas/browser-canvas-db-relations.c | 1041 ----
tools/browser/canvas/browser-canvas-db-relations.h | 68 -
tools/browser/canvas/browser-canvas-decl.h | 44 -
tools/browser/canvas/browser-canvas-fkey.c | 550 --
tools/browser/canvas/browser-canvas-fkey.h | 63 -
tools/browser/canvas/browser-canvas-item.c | 410 --
tools/browser/canvas/browser-canvas-item.h | 70 -
tools/browser/canvas/browser-canvas-print.c | 457 --
tools/browser/canvas/browser-canvas-print.h | 29 -
tools/browser/canvas/browser-canvas-table.c | 603 --
tools/browser/canvas/browser-canvas-table.h | 66 -
tools/browser/canvas/browser-canvas-text.c | 528 --
tools/browser/canvas/browser-canvas-text.h | 69 -
tools/browser/canvas/browser-canvas-utility.c | 747 ---
tools/browser/canvas/browser-canvas-utility.h | 50 -
tools/browser/canvas/browser-canvas.c | 1182 ----
tools/browser/canvas/browser-canvas.h | 87 -
tools/browser/common/Makefile.am | 60 -
tools/browser/common/import_encodings.xml | 315 -
tools/browser/connection-binding-properties.c | 144 +-
tools/browser/connection-binding-properties.h | 10 +-
tools/browser/data-manager/.gitignore | 1 +
tools/browser/data-manager/DataSourceEdition.dia | Bin 2492 -> 0 bytes
tools/browser/data-manager/Makefile.am | 40 +-
tools/browser/data-manager/analyser.c | 12 +-
tools/browser/data-manager/data-console.c | 117 +-
tools/browser/data-manager/data-console.h | 8 +-
.../browser/data-manager/data-favorite-selector.c | 112 +-
.../browser/data-manager/data-favorite-selector.h | 8 +-
.../data-manager/data-manager-perspective.c | 32 +-
tools/browser/data-manager/data-source-editor.c | 4 +-
tools/browser/data-manager/data-source-manager.c | 28 +-
tools/browser/data-manager/data-source-manager.h | 8 +-
tools/browser/data-manager/data-source.c | 78 +-
tools/browser/data-manager/data-source.h | 11 +-
tools/browser/data-manager/data-widget.c | 28 +-
tools/browser/data-manager/perspective-main.h | 4 +-
tools/browser/data-manager/ui-spec-editor.c | 12 +-
tools/browser/data-manager/ui-spec-editor.h | 2 +-
tools/browser/data-manager/xml-spec-editor.c | 16 +-
tools/browser/data-manager/xml-spec-editor.h | 4 +-
tools/browser/data/256x256/gda-browser-6.0.png | Bin 0 -> 41647 bytes
tools/browser/data/48x48/gda-browser-6.0.png | Bin 0 -> 4079 bytes
tools/browser/data/Makefile.am | 98 -
.../data/hicolor_actions_16x16_bookmark-view.png | Bin 474 -> 0 bytes
tools/browser/data/hicolor_actions_16x16_glade.png | Bin 527 -> 0 bytes
.../data/hicolor_actions_16x16_history-view.png | Bin 842 -> 0 bytes
.../data/hicolor_actions_22x22_bookmark-view.png | Bin 595 -> 0 bytes
tools/browser/data/hicolor_actions_22x22_form.png | Bin 286 -> 0 bytes
tools/browser/data/hicolor_actions_22x22_glade.png | Bin 1024 -> 0 bytes
tools/browser/data/hicolor_actions_22x22_grid.png | Bin 258 -> 0 bytes
.../data/hicolor_actions_22x22_history-view.png | Bin 1498 -> 0 bytes
.../data/hicolor_actions_24x24_bookmark-view.png | Bin 585 -> 0 bytes
tools/browser/data/hicolor_actions_24x24_glade.png | Bin 1050 -> 0 bytes
.../data/hicolor_actions_24x24_history-view.png | Bin 1511 -> 0 bytes
.../data/hicolor_actions_24x24_table-add.png | Bin 914 -> 0 bytes
.../hicolor_actions_24x24_transaction-begin.png | Bin 1046 -> 0 bytes
.../hicolor_actions_24x24_transaction-commit.png | Bin 1153 -> 0 bytes
.../hicolor_actions_24x24_transaction-rollback.png | Bin 904 -> 0 bytes
.../data/hicolor_actions_32x32_bookmark-view.png | Bin 934 -> 0 bytes
tools/browser/data/hicolor_actions_32x32_glade.png | Bin 1643 -> 0 bytes
.../data/hicolor_actions_32x32_history-view.png | Bin 2426 -> 0 bytes
.../data/hicolor_actions_32x32_ldap-entries.png | Bin 1322 -> 0 bytes
.../data/hicolor_actions_32x32_table-add.png | Bin 1916 -> 0 bytes
.../hicolor_actions_scalable_bookmark-view.svg | 355 --
.../data/hicolor_actions_scalable_glade.svg | 648 --
.../data/hicolor_actions_scalable_history-view.svg | 299 -
tools/browser/decl.h | 10 -
tools/browser/doc/.gitignore | 30 -
tools/browser/doc/Makefile.am | 97 -
tools/browser/doc/UILayout.png | Bin 92440 -> 0 bytes
tools/browser/doc/fdl-appendix.sgml | 1 -
tools/browser/doc/gda-browser-docs.sgml | 167 -
tools/browser/doc/gda-browser-sections.txt | 290 -
tools/browser/doc/gda-browser.types | 25 -
.../browser/dummy-perspective/dummy-perspective.c | 2 +
tools/browser/dummy-perspective/perspective-main.h | 4 +-
tools/browser/favorites-test.c | 257 -
tools/browser/{common => }/fk-declare.c | 41 +-
tools/browser/{common => }/fk-declare.h | 4 +-
tools/browser/gda-browser-6.0.png | 1 -
tools/browser/{common => }/gdaui-data-import.c | 0
tools/browser/{common => }/gdaui-data-import.h | 0
tools/browser/{common => }/gdaui-entry-import.c | 8 +-
tools/browser/{common => }/gdaui-entry-import.h | 0
tools/browser/help/.gitignore | 1 -
tools/browser/help/C/actions.page | 58 -
tools/browser/help/C/data-manager-perspective.page | 106 -
.../browser/help/C/data-manager-source-editor.page | 11 -
tools/browser/help/C/data-manager-xml-syntax.page | 168 -
tools/browser/help/C/declaredfk.page | 82 -
tools/browser/help/C/diagram.page | 33 -
tools/browser/help/C/features.page | 56 -
tools/browser/help/C/figures/action-1.png | Bin 111905 -> 0 bytes
tools/browser/help/C/figures/action-2.png | Bin 113038 -> 0 bytes
tools/browser/help/C/figures/action-3.png | Bin 25047 -> 0 bytes
tools/browser/help/C/figures/action-4.png | Bin 34122 -> 0 bytes
tools/browser/help/C/figures/cnc_open.png | Bin 52941 -> 0 bytes
tools/browser/help/C/figures/data-man-mode.png | Bin 1103 -> 0 bytes
tools/browser/help/C/figures/data-man-persp.png | Bin 105450 -> 0 bytes
.../browser/help/C/figures/data-man-uicompose.png | Bin 113705 -> 0 bytes
.../browser/help/C/figures/data-man-xmlcompose.png | Bin 76761 -> 0 bytes
tools/browser/help/C/figures/declaredfk-dialog.png | Bin 72957 -> 0 bytes
tools/browser/help/C/figures/declaredfk.png | Bin 23019 -> 0 bytes
tools/browser/help/C/figures/diagram.png | Bin 17249 -> 0 bytes
.../browser/help/C/figures/ldap-browser-persp.png | Bin 107744 -> 0 bytes
tools/browser/help/C/figures/ldap-classes.png | Bin 162544 -> 0 bytes
tools/browser/help/C/figures/ldap-search.png | Bin 104938 -> 0 bytes
.../browser/help/C/figures/ldap-table-mapping.png | Bin 83895 -> 0 bytes
tools/browser/help/C/figures/mainwin.png | Bin 67353 -> 0 bytes
tools/browser/help/C/figures/query-exec-persp.png | Bin 90062 -> 0 bytes
.../help/C/figures/schema-browser-persp.png | Bin 114471 -> 0 bytes
tools/browser/help/C/figures/table-insert-data.png | Bin 23450 -> 0 bytes
tools/browser/help/C/figures/trans-begin.png | Bin 1077 -> 0 bytes
tools/browser/help/C/figures/trans-commit.png | Bin 1158 -> 0 bytes
tools/browser/help/C/figures/trans-rollback.png | Bin 1019 -> 0 bytes
tools/browser/help/C/figures/virtual-cnc-2.png | Bin 35651 -> 0 bytes
tools/browser/help/C/figures/virtual-cnc-3.png | Bin 48960 -> 0 bytes
tools/browser/help/C/figures/virtual-cnc-4.png | Bin 102207 -> 0 bytes
tools/browser/help/C/figures/virtual-cnc-5.png | Bin 34537 -> 0 bytes
tools/browser/help/C/figures/virtual-cnc.png | Bin 27229 -> 0 bytes
tools/browser/help/C/general-ui.page | 36 -
tools/browser/help/C/index.page | 39 -
tools/browser/help/C/ldap-browser-perspective.page | 61 -
tools/browser/help/C/ldap-connections.page | 132 -
tools/browser/help/C/legal.xml | 9 -
.../help/C/query-execution-perspective.page | 111 -
.../browser/help/C/schema-browser-perspective.page | 50 -
tools/browser/help/C/sql-sqlite.page | 100 -
tools/browser/help/C/table-insert-data.page | 44 -
tools/browser/help/C/transactions.page | 30 -
tools/browser/help/C/variables.page | 41 -
tools/browser/help/C/virtual-connections.page | 140 -
tools/browser/help/Makefile.am | 56 -
tools/browser/help/cs/.gitignore | 2 -
tools/browser/help/cs/cs.po | 3183 ----------
tools/browser/help/de/.gitignore | 2 -
tools/browser/help/de/de.po | 2701 ---------
tools/browser/help/el/.gitignore | 2 -
tools/browser/help/es/.gitignore | 2 -
tools/browser/help/es/es.po | 3280 -----------
tools/browser/help/gl/.gitignore | 2 -
tools/browser/help/gl/gl.po | 1103 ----
tools/browser/help/id/.gitignore | 2 -
tools/browser/help/id/id.po | 3085 ----------
tools/browser/help/pt_BR/.gitignore | 2 -
tools/browser/help/pt_BR/pt_BR.po | 2079 -------
tools/browser/help/sl/.gitignore | 2 -
tools/browser/help/sl/sl.po | 1534 -----
tools/browser/help/zh_CN/.gitignore | 2 -
tools/browser/help/zh_CN/zh_CN.po | 2138 -------
tools/browser/ldap-browser/Makefile.am | 1 +
tools/browser/ldap-browser/class-properties.c | 27 +-
tools/browser/ldap-browser/class-properties.h | 4 +-
tools/browser/ldap-browser/classes-view.c | 19 +-
tools/browser/ldap-browser/classes-view.h | 4 +-
tools/browser/ldap-browser/entry-properties.c | 25 +-
tools/browser/ldap-browser/entry-properties.h | 4 +-
tools/browser/ldap-browser/filter-editor.c | 14 +-
tools/browser/ldap-browser/filter-editor.h | 4 +-
tools/browser/ldap-browser/hierarchy-view.c | 25 +-
tools/browser/ldap-browser/hierarchy-view.h | 4 +-
.../ldap-browser/ldap-browser-perspective.c | 49 +-
tools/browser/ldap-browser/ldap-classes-page.c | 45 +-
tools/browser/ldap-browser/ldap-classes-page.h | 4 +-
tools/browser/ldap-browser/ldap-entries-page.c | 45 +-
tools/browser/ldap-browser/ldap-entries-page.h | 4 +-
.../browser/ldap-browser/ldap-favorite-selector.c | 88 +-
.../browser/ldap-browser/ldap-favorite-selector.h | 6 +-
tools/browser/ldap-browser/ldap-search-page.c | 50 +-
tools/browser/ldap-browser/ldap-search-page.h | 4 +-
tools/browser/ldap-browser/mgr-ldap-classes.c | 33 +-
tools/browser/ldap-browser/mgr-ldap-classes.h | 4 +-
tools/browser/ldap-browser/mgr-ldap-entries.c | 21 +-
tools/browser/ldap-browser/mgr-ldap-entries.h | 4 +-
tools/browser/ldap-browser/perspective-main.h | 4 +-
tools/browser/ldap-browser/vtable-dialog.c | 16 +-
tools/browser/ldap-browser/vtable-dialog.h | 4 +-
tools/browser/login-dialog.c | 82 +-
tools/browser/login-dialog.h | 9 +-
tools/browser/main.c | 266 -
tools/browser/marshal.list | 3 +-
tools/browser/mgr-favorites.c | 101 +-
tools/browser/mgr-favorites.h | 7 +-
tools/browser/{common => }/objects-cloud.c | 14 +-
tools/browser/{common => }/objects-cloud.h | 11 +-
tools/browser/query-exec/.gitignore | 1 +
tools/browser/query-exec/Makefile.am | 3 +-
tools/browser/query-exec/perspective-main.c | 2 +-
tools/browser/query-exec/perspective-main.h | 4 +-
tools/browser/query-exec/query-console-page.c | 176 +-
tools/browser/query-exec/query-console-page.h | 6 +-
tools/browser/query-exec/query-editor.c | 44 +-
tools/browser/query-exec/query-exec-perspective.c | 37 +-
tools/browser/query-exec/query-favorite-selector.c | 129 +-
tools/browser/query-exec/query-favorite-selector.h | 8 +-
tools/browser/query-exec/query-result.c | 16 +-
tools/browser/query-exec/query-result.h | 2 +-
tools/browser/schema-browser/Makefile.am | 3 +
tools/browser/schema-browser/favorite-selector.c | 60 +-
tools/browser/schema-browser/favorite-selector.h | 15 +-
tools/browser/schema-browser/mgr-columns.c | 42 +-
tools/browser/schema-browser/mgr-columns.h | 6 +-
tools/browser/schema-browser/objects-index.c | 30 +-
tools/browser/schema-browser/objects-index.h | 6 +-
tools/browser/schema-browser/perspective-main.h | 4 +-
tools/browser/schema-browser/relations-diagram.c | 82 +-
tools/browser/schema-browser/relations-diagram.h | 6 +-
.../schema-browser/schema-browser-perspective.c | 42 +-
tools/browser/schema-browser/table-columns.c | 62 +-
tools/browser/schema-browser/table-info.c | 97 +-
tools/browser/schema-browser/table-info.h | 6 +-
tools/browser/schema-browser/table-preferences.c | 59 +-
tools/browser/schema-browser/table-relations.c | 20 +-
tools/browser/support.c | 617 --
tools/browser/support.h | 130 -
tools/browser/text-search.c | 14 +-
tools/browser/{common => }/ui-formgrid.c | 131 +-
tools/browser/{common => }/ui-formgrid.h | 8 +-
tools/browser/ui-support.c | 578 ++
tools/browser/ui-support.h | 108 +
tools/browser/{common => }/widget-overlay.c | 2 +
tools/browser/{common => }/widget-overlay.h | 0
tools/cmdtool/Makefile.am | 25 -
tools/command-exec.c | 935 ---
tools/command-exec.h | 51 -
tools/common/.gitignore | 1 +
tools/common/Makefile.am | 66 +
tools/{ => common}/html-doc.c | 0
tools/{ => common}/html-doc.h | 0
tools/{browser => }/common/marshal.list | 6 +-
tools/{gda-sql.c => common/t-app.c} | 6196 +++++++++-----------
tools/common/t-app.h | 110 +
tools/{config-info.c => common/t-config-info.c} | 40 +-
tools/common/t-config-info.h | 37 +
tools/common/t-connection.c | 2449 ++++++++
tools/common/t-connection.h | 218 +
tools/common/t-context.c | 659 +++
tools/common/t-context.h | 74 +
tools/{cmdtool/tool-help.h => common/t-decl.h} | 15 +-
tools/{cmdtool/tool-errors.c => common/t-errors.c} | 9 +-
.../browser-canvas-priv.h => common/t-errors.h} | 39 +-
.../t-favorites-actions.c} | 66 +-
.../t-favorites-actions.h} | 18 +-
tools/{tools-favorites.c => common/t-favorites.c} | 268 +-
tools/common/t-favorites.h | 130 +
tools/common/t-term-context.c | 612 ++
tools/common/t-term-context.h | 59 +
tools/common/t-utils.c | 209 +
.../browser-canvas-priv.h => common/t-utils.h} | 27 +-
.../t-virtual-connection.c} | 254 +-
tools/common/t-virtual-connection.h | 93 +
tools/common/t-web-context.c | 119 +
tools/common/t-web-context.h | 52 +
tools/{ => common}/web-server.c | 304 +-
tools/{ => common}/web-server.h | 5 +-
tools/config-info.h | 37 -
.../{browser/browser-res.rc => gda-browser-res.rc} | 0
tools/{browser => }/gda-browser.ico | Bin 9086 -> 9086 bytes
tools/gda-sql.h | 76 -
tools/gda-threader.c | 341 --
tools/gda-threader.h | 64 -
tools/irb.js.orig | 110 -
tools/jquery-ui.js | 18 -
tools/misc/Makefile.am | 61 +
tools/{ => misc}/gda-list-config.c | 0
tools/{ => misc}/gda-list-server-op.c | 0
tools/{ => misc}/gda-tree-mgr-xml.c | 0
tools/{ => misc}/gda-tree-mgr-xml.h | 0
tools/{ => misc}/information-schema-doc.c | 0
tools/{ => misc}/information-schema-types.c | 0
tools/mouseapp_2.js.orig | 913 ---
tools/mouseirb_2.js.orig | 179 -
.../{browser => resources}/gda-browser-action.png | Bin 656 -> 656 bytes
.../gda-browser-auth-big.png | Bin 6542 -> 6542 bytes
tools/{browser => resources}/gda-browser-auth.png | Bin 35000 -> 35000 bytes
.../gda-browser-bookmark.png | Bin 474 -> 474 bytes
.../gda-browser-column-fk.png | Bin 442 -> 442 bytes
.../gda-browser-column-fknn.png | Bin 473 -> 473 bytes
.../gda-browser-column-nn.png | Bin 449 -> 449 bytes
.../gda-browser-column-pk.png | Bin 560 -> 560 bytes
.../{browser => resources}/gda-browser-column.png | Bin 427 -> 427 bytes
.../gda-browser-connected-big.png | Bin 6476 -> 6476 bytes
.../gda-browser-connected.png | Bin 33239 -> 33239 bytes
.../{browser => resources}/gda-browser-diagram.png | Bin 229 -> 229 bytes
.../gda-browser-ldap-class-a.png | Bin 513 -> 513 bytes
.../gda-browser-ldap-class-s.png | Bin 394 -> 394 bytes
.../gda-browser-ldap-class-u.png | Bin 514 -> 514 bytes
.../gda-browser-ldap-class-x.png | Bin 506 -> 506 bytes
.../gda-browser-ldap-entry.png | Bin 560 -> 560 bytes
.../gda-browser-ldap-group.png | Bin 808 -> 808 bytes
.../gda-browser-ldap-organization.png | Bin 590 -> 590 bytes
.../gda-browser-ldap-person.png | Bin 796 -> 796 bytes
.../gda-browser-menu-ind.png | Bin 472 -> 472 bytes
.../gda-browser-non-connected-big.png | Bin 6865 -> 6865 bytes
.../gda-browser-non-connected.png | Bin 34582 -> 34582 bytes
tools/{browser => resources}/gda-browser-query.png | Bin 656 -> 656 bytes
.../gda-browser-reference.png | Bin 366 -> 366 bytes
.../{browser => resources}/gda-browser-schema.png | Bin 404 -> 404 bytes
tools/{browser => resources}/gda-browser-table.png | Bin 577 -> 577 bytes
tools/{browser => resources}/gda-browser-view.png | Bin 597 -> 597 bytes
tools/{browser => resources}/gda-browser.png | Bin 59869 -> 59869 bytes
tools/test_blob.sh | 67 -
tools/tool-utils.c | 59 -
tools/tool-utils.h | 44 -
tools/tools-favorites.h | 130 -
tools/tools-main.c | 569 ++
tools/tools.gresource.xml | 90 +
tools/{ => webdata}/cnc.js | 0
tools/{ => webdata}/gda-print.css | 0
tools/{ => webdata}/gda.css | 0
tools/{ => webdata}/irb.css | 0
tools/{ => webdata}/irb.js | 0
tools/{ => webdata}/jquery.js | 0
tools/{ => webdata}/md5.js | 0
tools/{ => webdata}/mouseapp_2.js | 0
tools/{ => webdata}/mouseirb_2.js | 0
364 files changed, 12264 insertions(+), 42876 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 3b385af..d090edb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1013,20 +1013,17 @@ control-center/Makefile
control-center/data/Makefile
tools/Makefile
tools/gda-sql-6.0.1:tools/gda-sql.1.in
-tools/cmdtool/Makefile
-tools/help/Makefile
-tools/help/C/Makefile
+tools/base/Makefile
tools/browser/Makefile
-tools/browser/data/Makefile
-tools/browser/common/Makefile
+tools/browser/dummy-perspective/Makefile
tools/browser/schema-browser/Makefile
tools/browser/query-exec/Makefile
tools/browser/data-manager/Makefile
tools/browser/ldap-browser/Makefile
-tools/browser/dummy-perspective/Makefile
-tools/browser/canvas/Makefile
-tools/browser/doc/Makefile
-tools/browser/help/Makefile
+tools/common/Makefile
+tools/misc/Makefile
+tools/help/Makefile
+tools/help/C/Makefile
testing/Makefile
tests/Makefile
tests/parser/Makefile
diff --git a/control-center/gdaui-bar.c b/control-center/gdaui-bar.c
index af42b96..a8d406e 100644
--- a/control-center/gdaui-bar.c
+++ b/control-center/gdaui-bar.c
@@ -399,6 +399,19 @@ gdaui_bar_set_icon_from_resource (GdauiBar *bar, const gchar *resource_name)
}
/**
+ * gdaui_bar_set_icon_from_pixbuf:
+ */
+void
+gdaui_bar_set_icon_from_pixbuf (GdauiBar *bar, GdkPixbuf *pixbuf)
+{
+ g_return_if_fail (GDAUI_IS_BAR (bar));
+ g_return_if_fail (!pixbuf || GDK_IS_PIXBUF (pixbuf));
+
+ gtk_image_set_from_pixbuf (GTK_IMAGE (bar->priv->icon), pixbuf);
+ gdaui_bar_set_show_icon (bar, TRUE);
+}
+
+/**
* gdaui_bar_set_show_icon
* @bar: a #GdauiBar widget.
* @show: whether to show the icon or not.
@@ -482,3 +495,38 @@ gdaui_bar_add_search_entry (GdauiBar *bar)
gtk_widget_show_all (vb);
return entry;
}
+
+/**
+ * gdaui_bar_add_button_from_icon_name:
+ * @bar: a #GdauiBar
+ * @icon_name: an icon name
+ *
+ * Returns: (transfer none): the created #GtkButton
+ */
+GtkWidget *
+gdaui_bar_add_button_from_icon_name (GdauiBar *bar, const gchar *icon_name)
+{
+ g_return_val_if_fail (GDAUI_IS_BAR (bar), NULL);
+
+ GtkWidget *vb, *button;
+
+ vb = gtk_button_box_new (GTK_ORIENTATION_VERTICAL);
+ gtk_button_box_set_layout (GTK_BUTTON_BOX (vb), GTK_BUTTONBOX_CENTER);
+ gtk_box_pack_start (GTK_BOX (bar->priv->action_area), vb, FALSE, FALSE, 0);
+
+ button = gtk_button_new_from_icon_name (icon_name, GTK_ICON_SIZE_SMALL_TOOLBAR);
+ gtk_box_pack_start (GTK_BOX (vb), button, FALSE, FALSE, 0);
+
+ /* CSS theming */
+ GtkStyleContext *context;
+ context = gtk_widget_get_style_context (vb);
+ gtk_style_context_add_provider (context, css_provider, G_MAXUINT);
+ gtk_style_context_add_class (context, "gdauibar_button");
+
+ context = gtk_widget_get_style_context (button);
+ gtk_style_context_add_provider (context, css_provider, G_MAXUINT);
+ gtk_style_context_add_class (context, "gdauibar_button");
+
+ gtk_widget_show_all (vb);
+ return button;
+}
diff --git a/control-center/gdaui-bar.h b/control-center/gdaui-bar.h
index 1350d60..6d6c410 100644
--- a/control-center/gdaui-bar.h
+++ b/control-center/gdaui-bar.h
@@ -52,15 +52,18 @@ struct _GdauiBarClass
GtkBoxClass parent_class;
};
-GType gdaui_bar_get_type (void) G_GNUC_CONST;
-GtkWidget *gdaui_bar_new (const gchar *text);
-const gchar *gdaui_bar_get_text (GdauiBar *bar);
-void gdaui_bar_set_text (GdauiBar *bar, const gchar *text);
-void gdaui_bar_set_icon_from_file (GdauiBar *bar, const gchar *file);
-void gdaui_bar_set_icon_from_resource(GdauiBar *bar, const gchar *resource_name);
-void gdaui_bar_set_show_icon (GdauiBar *bar, gboolean show);
-gboolean gdaui_bar_get_show_icon (GdauiBar *bar);
-GtkWidget *gdaui_bar_add_search_entry (GdauiBar *bar);
+GType gdaui_bar_get_type (void) G_GNUC_CONST;
+GtkWidget *gdaui_bar_new (const gchar *text);
+const gchar *gdaui_bar_get_text (GdauiBar *bar);
+void gdaui_bar_set_text (GdauiBar *bar, const gchar *text);
+void gdaui_bar_set_icon_from_file (GdauiBar *bar, const gchar *file);
+void gdaui_bar_set_icon_from_resource (GdauiBar *bar, const gchar *resource_name);
+void gdaui_bar_set_icon_from_pixbuf (GdauiBar *bar, GdkPixbuf *pixbuf);
+void gdaui_bar_set_show_icon (GdauiBar *bar, gboolean show);
+gboolean gdaui_bar_get_show_icon (GdauiBar *bar);
+
+GtkWidget *gdaui_bar_add_search_entry (GdauiBar *bar);
+GtkWidget *gdaui_bar_add_button_from_icon_name (GdauiBar *bar, const gchar *icon_name);
G_END_DECLS
diff --git a/tests/multi-threading/dummy-object.c b/tests/multi-threading/dummy-object.c
index c32495e..491f1cc 100644
--- a/tests/multi-threading/dummy-object.c
+++ b/tests/multi-threading/dummy-object.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2009 - 2014 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
*
* This program is free software; you can redistribute it and/or
@@ -35,10 +35,11 @@ enum
SIG0,
SIG1,
SIG2,
+ SIG3,
LAST_SIGNAL
};
-static gint dummy_object_signals[LAST_SIGNAL] = { 0, 0, 0 };
+static gint dummy_object_signals[LAST_SIGNAL] = { 0, 0, 0, 0 };
GType
dummy_object_get_type (void)
@@ -69,22 +70,22 @@ dummy_object_get_type (void)
return type;
}
-/* VOID:STRING,INT (gda-marshal.list:39) */
+/* VOID:INT,STRING (gda-marshal.list:39) */
#define g_marshal_value_peek_string(v) (char*) g_value_get_string (v)
#define g_marshal_value_peek_int(v) g_value_get_int (v)
static void
-local_marshal_VOID__STRING_INT (GClosure *closure,
+local_marshal_VOID__INT_STRING (GClosure *closure,
GValue *return_value G_GNUC_UNUSED,
guint n_param_values,
const GValue *param_values,
gpointer invocation_hint G_GNUC_UNUSED,
gpointer marshal_data)
{
- typedef void (*GMarshalFunc_VOID__STRING_INT) (gpointer data1,
- gpointer arg_1,
- gint arg_2,
+ typedef void (*GMarshalFunc_VOID__INT_STRING) (gpointer data1,
+ gint arg_1,
+ gpointer arg_2,
gpointer data2);
- register GMarshalFunc_VOID__STRING_INT callback;
+ register GMarshalFunc_VOID__INT_STRING callback;
register GCClosure *cc = (GCClosure*) closure;
register gpointer data1, data2;
@@ -100,14 +101,84 @@ local_marshal_VOID__STRING_INT (GClosure *closure,
data1 = g_value_peek_pointer (param_values + 0);
data2 = closure->data;
}
- callback = (GMarshalFunc_VOID__STRING_INT) (marshal_data ? marshal_data : cc->callback);
+ callback = (GMarshalFunc_VOID__INT_STRING) (marshal_data ? marshal_data : cc->callback);
callback (data1,
- g_marshal_value_peek_string (param_values + 1),
- g_marshal_value_peek_int (param_values + 2),
+ g_marshal_value_peek_int (param_values + 1),
+ g_marshal_value_peek_string (param_values + 2),
data2);
}
+/* STRING:STRING,INT (gda-marshal.list:43) */
+void
+_gda_marshal_STRING__STRING_INT (GClosure *closure,
+ GValue *return_value G_GNUC_UNUSED,
+ guint n_param_values,
+ const GValue *param_values,
+ gpointer invocation_hint G_GNUC_UNUSED,
+ gpointer marshal_data)
+{
+ typedef gchar* (*GMarshalFunc_STRING__STRING_INT) (gpointer data1,
+ gpointer arg_1,
+ gint arg_2,
+ gpointer data2);
+ register GMarshalFunc_STRING__STRING_INT callback;
+ register GCClosure *cc = (GCClosure*) closure;
+ register gpointer data1, data2;
+ gchar* v_return;
+
+ g_return_if_fail (return_value != NULL);
+ g_return_if_fail (n_param_values == 3);
+
+ if (G_CCLOSURE_SWAP_DATA (closure))
+ {
+ data1 = closure->data;
+ data2 = g_value_peek_pointer (param_values + 0);
+ }
+ else
+ {
+ data1 = g_value_peek_pointer (param_values + 0);
+ data2 = closure->data;
+ }
+ callback = (GMarshalFunc_STRING__STRING_INT) (marshal_data ? marshal_data : cc->callback);
+
+ v_return = callback (data1,
+ g_marshal_value_peek_string (param_values + 1),
+ g_marshal_value_peek_int (param_values + 2),
+ data2);
+
+ g_value_take_string (return_value, v_return);
+}
+
+static gboolean
+sig3_accumulator (G_GNUC_UNUSED GSignalInvocationHint *ihint,
+ GValue *return_accu,
+ const GValue *handler_return,
+ G_GNUC_UNUSED gpointer data)
+{
+ const gchar *rstr, *str;
+
+ rstr = g_value_get_string (handler_return);
+ str = g_value_get_string (return_accu);
+ if (str) {
+ if (rstr) {
+ gchar *tmp;
+ tmp = g_strdup_printf ("%s[]%s", rstr, str);
+ g_value_take_string (return_accu, tmp);
+ }
+ }
+ else
+ g_value_set_string (return_accu, rstr);
+
+ return TRUE; /* stop signal if error has been set */
+}
+
+gchar *
+m_sig3 (DummyObject *object, gchar *str, gint i)
+{
+ return NULL;
+}
+
static void
dummy_object_class_init (DummyObjectClass *class)
{
@@ -129,17 +200,25 @@ dummy_object_class_init (DummyObjectClass *class)
G_STRUCT_OFFSET (DummyObjectClass, sig1),
NULL, NULL,
g_cclosure_marshal_VOID__INT, G_TYPE_NONE, 1, G_TYPE_INT);
- dummy_object_signals[SIG1] =
+ dummy_object_signals[SIG2] =
g_signal_new ("sig2",
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (DummyObjectClass, sig1),
+ G_STRUCT_OFFSET (DummyObjectClass, sig2),
NULL, NULL,
- local_marshal_VOID__STRING_INT, G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_STRING);
+ local_marshal_VOID__INT_STRING, G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_STRING);
+ dummy_object_signals[SIG3] =
+ g_signal_new ("sig3",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (DummyObjectClass, sig3),
+ sig3_accumulator, NULL,
+ _gda_marshal_STRING__STRING_INT, G_TYPE_STRING, 2, G_TYPE_STRING, G_TYPE_INT);
class->sig1 = NULL;
class->sig0 = NULL;
class->sig2 = NULL;
+ class->sig3 = m_sig3;
}
static void
diff --git a/tests/multi-threading/dummy-object.h b/tests/multi-threading/dummy-object.h
index 67a346e..806bbac 100644
--- a/tests/multi-threading/dummy-object.h
+++ b/tests/multi-threading/dummy-object.h
@@ -46,6 +46,7 @@ struct _DummyObjectClass
void (*sig0) (DummyObject *object);
void (*sig1) (DummyObject *object, gint i);
void (*sig2) (DummyObject *object, gint i, gchar *str);
+ gchar *(*sig3) (DummyObject *object, gchar *str, gint i);
};
GType dummy_object_get_type (void) G_GNUC_CONST;
diff --git a/tools/.gitignore b/tools/.gitignore
index d7105b8..9bdefcb 100644
--- a/tools/.gitignore
+++ b/tools/.gitignore
@@ -1,4 +1,5 @@
gda-sql-6*
+gda-browser-6*
gda-list-config-6*
gda-list-server-op-6*
information-schema-doc
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 3b3cf5d..bdaa644 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -1,19 +1,18 @@
-if HAVE_UI
-BROWSER_DIR=browser
-endif
-
if LDAP
ldap_flags=-DHAVE_LDAP
+ldap_lib=browser/ldap-browser/libperspective.la
endif
-SUBDIRS = cmdtool $(BROWSER_DIR) help
+SUBDIRS = misc common base help
bin_PROGRAMS = \
- gda-list-config-6.0 \
- gda-sql-6.0 \
- gda-list-server-op-6.0
+ gda-sql-6.0
-noinst_PROGRAMS = information-schema-doc information-schema-types
+if HAVE_UI
+bin_PROGRAMS+=gda-browser-6.0
+SUBDIRS+=browser
+noinst_LTLIBRARIES = libbrowser.la
+endif
AM_CPPFLAGS = \
-I$(top_srcdir) \
@@ -23,49 +22,109 @@ AM_CPPFLAGS = \
-I$(top_srcdir)/libgda \
-I$(top_builddir)/libgda \
-I$(top_srcdir)/tools \
- -I$(top_srcdir)/tools/cmdtool \
+ -I$(top_srcdir)/tools/base \
+ -I$(top_srcdir)/tools/common \
$(ldap_flags) \
$(COREDEPS_CFLAGS) \
-DROOT_DIR=\""$(top_srcdir)"\"
-gda_list_config_6_0_SOURCES = \
- gda-list-config.c
-
-gda_list_config_6_0_LDADD = \
- $(top_builddir)/libgda/libgda-6.0.la \
- $(COREDEPS_LIBS)
-
gda_sql_6_0_SOURCES = \
- tool-utils.h \
- tool-utils.c \
- config-info.h \
- config-info.c \
- tools-favorites.h \
- tools-favorites.c \
- gda-sql.c \
- gda-sql.h \
- gda-threader.h \
- gda-threader.c \
- command-exec.h \
- command-exec.c \
- $(top_srcdir)/libgda/global.h \
- $(top_srcdir)/libgda/md5.h \
- $(top_srcdir)/libgda/md5c.c
+ tools-main.c
gda_sql_6_0_LDADD = \
- cmdtool/libcmdtool.la \
+ common/libcommon.la \
+ base/libbasetool.la \
$(top_builddir)/libgda/libgda-6.0.la \
$(COREDEPS_LIBS) \
$(READLINE_LIB) \
$(HISTORY_LIB)
if LIBSOUP
-gda_sql_6_0_SOURCES += web-server.h web-server.c html-doc.h html-doc.c
-AM_CPPFLAGS += $(LIBSOUP_CFLAGS)
gda_sql_6_0_LDADD += $(LIBSOUP_LIBS)
endif
+if HAVE_UI
+gda_browser_6_0_SOURCES = \
+ tools-main.c \
+ tools.gresources.c
+
+if PLATFORM_WIN32
+EXTRALDFLAGS=-mwindows
+gda_browser_6_0_SOURCES += gda-browser-res.rc
+else
+EXTRALDFLAGS=
+endif
+
+libbrowser_la_SOURCES=
+
+libbrowser_la_LIBADD = \
+ common/libcommonui.la \
+ base/libbasetool.la \
+ browser/libbrowsercore.la \
+ $(ldap_lib) \
+ browser/schema-browser/libperspective.la \
+ browser/dummy-perspective/libperspective.la \
+ browser/query-exec/libperspective.la \
+ browser/data-manager/libperspective.la
+
+gda_browser_6_0_CPPFLAGS = \
+ $(AM_CPPFLAGS) \
+ $(GTK_CFLAGS) \
+ $(GTKSOURCEVIEW_CFLAGS) \
+ $(MAC_INTEGRATION_CFLAGS) \
+ -DIS_BROWSER
+
+gda_browser_6_0_LDFLAGS = $(EXTRALDFLAGS)
+
+gda_browser_6_0_LDADD = \
+ libbrowser.la \
+ $(top_builddir)/libgda/libgda-6.0.la \
+ $(COREDEPS_LIBS) \
+ $(READLINE_LIB) \
+ $(HISTORY_LIB) \
+ $(top_builddir)/libgda-ui/internal/libgda-ui-internal.la \
+ $(top_builddir)/libgda-ui/libgda-ui-6.0.la \
+ $(GTK_LIBS) $(GTKSOURCEVIEW_LIBS) $(MAC_INTEGRATION_LIBS)
+
+if LIBSOUP
+gda_browser_6_0_LDADD += $(LIBSOUP_LIBS)
+endif
+endif
+# resources
+RESOURCES=\
+ resources/gda-browser-action.png \
+ resources/gda-browser-auth-big.png \
+ resources/gda-browser-auth.png \
+ resources/gda-browser-bookmark.png \
+ resources/gda-browser-column-fknn.png \
+ resources/gda-browser-column-fk.png \
+ resources/gda-browser-column-nn.png \
+ resources/gda-browser-column-pk.png \
+ resources/gda-browser-column.png \
+ resources/gda-browser-connected-big.png \
+ resources/gda-browser-connected.png \
+ resources/gda-browser-diagram.png \
+ resources/gda-browser-ldap-class-a.png \
+ resources/gda-browser-ldap-class-s.png \
+ resources/gda-browser-ldap-class-u.png \
+ resources/gda-browser-ldap-class-x.png \
+ resources/gda-browser-ldap-entry.png \
+ resources/gda-browser-ldap-group.png \
+ resources/gda-browser-ldap-organization.png \
+ resources/gda-browser-ldap-person.png \
+ resources/gda-browser-menu-ind.png \
+ resources/gda-browser-non-connected-big.png \
+ resources/gda-browser-non-connected.png \
+ resources/gda-browser.png \
+ resources/gda-browser-query.png \
+ resources/gda-browser-reference.png \
+ resources/gda-browser-schema.png \
+ resources/gda-browser-table.png \
+ resources/gda-browser-view.png
+
+tools.gresources.c: tools.gresource.xml $(RESOURCES)
+ $(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --target=$@ --sourcedir=resources --generate-source
$(srcdir)/tools.gresource.xml
# setenv() is in libiberty in mingw
if PLATFORM_WIN32
@@ -79,45 +138,26 @@ endif
gda-sql-res.o: gda-sql-res.rc
$(WINDRES) $^ -o $@
-gda_list_server_op_6_0_SOURCES = \
- gda-list-server-op.c \
- gda-tree-mgr-xml.c \
- gda-tree-mgr-xml.h
-
-gda_list_server_op_6_0_LDADD = \
- $(top_builddir)/libgda/libgda-6.0.la \
- $(COREDEPS_LIBS)
-
-
-information_schema_doc_SOURCES = \
- information-schema-doc.c
-
-information_schema_doc_LDADD = \
- $(top_builddir)/libgda/libgda-6.0.la \
- $(COREDEPS_LIBS)
-
-information_schema_types_SOURCES = \
- information-schema-types.c
-
-information_schema_types_LDADD = \
- $(top_builddir)/libgda/libgda-6.0.la \
- $(COREDEPS_LIBS)
+gda-browser-res.o: gda-browser-res.rc
+ $(WINDRES) $^ -o $@
webdatadir = $(datadir)/libgda-6.0/web
webdata_DATA = \
- cnc.js \
- md5.js \
- jquery.js \
- mouseapp_2.js \
- mouseirb_2.js \
- irb.js \
- gda.css \
- gda-print.css \
- irb.css
+ webdata/cnc.js \
+ webdata/md5.js \
+ webdata/jquery.js \
+ webdata/mouseapp_2.js \
+ webdata/mouseirb_2.js \
+ webdata/irb.js \
+ webdata/gda.css \
+ webdata/gda-print.css \
+ webdata/irb.css
EXTRA_DIST = \
gda-sql-res.rc \
gda-sql.ico \
+ gda-browser-res.rc \
+ gda-browser.ico \
$(webdata_DATA)
mans = \
@@ -157,13 +197,11 @@ endif
install-exec-hook:
if DEFAULT_BINARY
cd $(DESTDIR)$(bindir) \
- && rm -f gda-list-config$(EXEEXT) gda-sql$(EXEEXT) gda-list-server-op$(EXEEXT) \
- && $(LN_S) gda-list-config-6.0$(EXEEXT) gda-list-config$(EXEEXT) \
- && $(LN_S) gda-sql-6.0$(EXEEXT) gda-sql$(EXEEXT) \
- && $(LN_S) gda-list-server-op-6.0$(EXEEXT) gda-list-server-op$(EXEEXT)
+ && rm -f gda-sql$(EXEEXT) \
+ && $(LN_S) gda-sql-6.0$(EXEEXT) gda-sql$(EXEEXT)
endif
uninstall-local:
if DEFAULT_BINARY
- rm -f $(DESTDIR)$(bindir)/gda-list-config$(EXEEXT) $(DESTDIR)$(bindir)/gda-sql$(EXEEXT)
$(DESTDIR)$(bindir)/gda-list-server-op$(EXEEXT)
+ rm -f $(DESTDIR)$(bindir)/gda-sql$(EXEEXT)
endif
diff --git a/tools/README b/tools/README
index 2ab81f3..bda2beb 100644
--- a/tools/README
+++ b/tools/README
@@ -1,16 +1,16 @@
-gda-sql-5.0
+gda-sql-6.0
-----------
Console program to open connections to databases and execute SQL commands.
-gda-list-config-5.0
+gda-list-config-6.0
-------------------
Gives a list of installed database providers (along with all the parameters
they each accept when opening a connection, and a list of the configured DSN
(data source name).
-gda-list-server-op-5.0:
+gda-list-server-op-6.0:
-----------------------
Gives a list of named parameters expected, for each database provider and for
each type of server operation.
diff --git a/tools/base/Makefile.am b/tools/base/Makefile.am
new file mode 100644
index 0000000..ed84c4c
--- /dev/null
+++ b/tools/base/Makefile.am
@@ -0,0 +1,25 @@
+noinst_LTLIBRARIES = libbasetool.la
+
+AM_CPPFLAGS = \
+ -I$(top_srcdir) \
+ -I$(top_srcdir)/libgda \
+ -I$(top_builddir) \
+ -I$(top_builddir)/libgda \
+ $(COREDEPS_CFLAGS) \
+ $(COREDEPS_WFLAGS)
+
+
+libbasetool_la_SOURCES = \
+ base-tool.h \
+ base-tool-decl.h \
+ base-tool-defines.h \
+ base-tool-errors.h \
+ base-tool-errors.c \
+ base-tool-input.h \
+ base-tool-input.c \
+ base-tool-output.h \
+ base-tool-output.c \
+ base-tool-command.h \
+ base-tool-command.c \
+ base-tool-help.h \
+ base-tool-help.c
diff --git a/tools/cmdtool/tool-command.c b/tools/base/base-tool-command.c
similarity index 78%
rename from tools/cmdtool/tool-command.c
rename to tools/base/base-tool-command.c
index e2c08f8..19ee96e 100644
--- a/tools/cmdtool/tool-command.c
+++ b/tools/base/base-tool-command.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2012 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2012 - 2014 Vivien Malerba <malerba gnome-db org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -16,8 +16,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#include "tool-command.h"
-#include "tool-help.h"
+#include "base-tool-command.h"
+#include "base-tool-help.h"
+#include "base-tool-errors.h"
#include <glib/gi18n-lib.h>
struct _ToolCommandGroup {
@@ -25,25 +26,14 @@ struct _ToolCommandGroup {
GSList *group_ordered;
};
-/* module error */
-GQuark
-tool_command_error_quark (void)
-{
- static GQuark quark;
- if (!quark)
- quark = g_quark_from_static_string ("tool_command_error");
- return quark;
-}
-
-
/**
- * tool_command_result_new:
+ * base_tool_command_result_new:
* @type: a #ToolCommandResultType
*
* Returns: (transfer full): a new #ToolCommandResult
*/
ToolCommandResult *
-tool_command_result_new (GdaConnection *cnc, ToolCommandResultType type)
+base_tool_command_result_new (GdaConnection *cnc, ToolCommandResultType type)
{
ToolCommandResult *res;
res = g_new0 (ToolCommandResult, 1);
@@ -57,18 +47,18 @@ tool_command_result_new (GdaConnection *cnc, ToolCommandResultType type)
}
/**
- * tool_command_result_free:
+ * base_tool_command_result_free:
* @res: (allow-none): a #ToolCommandResult, or %NULL
*
* Frees any resource used by @res
*/
void
-tool_command_result_free (ToolCommandResult *res)
+base_tool_command_result_free (ToolCommandResult *res)
{
if (!res)
return;
switch (res->type) {
- case TOOL_COMMAND_RESULT_DATA_MODEL:
+ case BASE_TOOL_COMMAND_RESULT_DATA_MODEL:
if (res->u.model)
g_object_unref (res->u.model);
if (! res->was_in_transaction_before_exec &&
@@ -76,28 +66,36 @@ tool_command_result_free (ToolCommandResult *res)
gda_connection_get_transaction_status (res->cnc))
gda_connection_rollback_transaction (res->cnc, NULL, NULL);
break;
- case TOOL_COMMAND_RESULT_SET:
+ case BASE_TOOL_COMMAND_RESULT_SET:
if (res->u.set)
g_object_unref (res->u.set);
break;
- case TOOL_COMMAND_RESULT_TREE:
+ case BASE_TOOL_COMMAND_RESULT_TREE:
if (res->u.tree)
g_object_unref (res->u.tree);
break;
- case TOOL_COMMAND_RESULT_TXT:
- case TOOL_COMMAND_RESULT_TXT_STDOUT:
+ case BASE_TOOL_COMMAND_RESULT_TXT:
+ case BASE_TOOL_COMMAND_RESULT_TXT_STDOUT:
if (res->u.txt)
g_string_free (res->u.txt, TRUE);
break;
- case TOOL_COMMAND_RESULT_MULTIPLE: {
+ case BASE_TOOL_COMMAND_RESULT_MULTIPLE: {
GSList *list;
for (list = res->u.multiple_results; list; list = list->next)
- tool_command_result_free ((ToolCommandResult *) list->data);
+ base_tool_command_result_free ((ToolCommandResult *) list->data);
g_slist_free (res->u.multiple_results);
break;
}
+ case BASE_TOOL_COMMAND_RESULT_HELP:
+ if (res->u.xml_node)
+ xmlFreeNode (res->u.xml_node);
+ break;
+ case BASE_TOOL_COMMAND_RESULT_EXIT:
+ case BASE_TOOL_COMMAND_RESULT_EMPTY:
+ break;
default:
+ g_assert_not_reached ();
break;
}
if (res->cnc)
@@ -106,12 +104,12 @@ tool_command_result_free (ToolCommandResult *res)
}
/**
- * tool_command_group_new:
+ * base_tool_command_group_new:
*
* Returns: (transfer full): a new #ToolCommandGroup structure
*/
ToolCommandGroup *
-tool_command_group_new (void)
+base_tool_command_group_new (void)
{
ToolCommandGroup *group;
group = g_new0 (ToolCommandGroup, 1);
@@ -119,13 +117,13 @@ tool_command_group_new (void)
}
/**
- * tool_command_group_free:
+ * base_tool_command_group_free:
* @group: (allow-none) (transfer full): a #ToolCommandGroup pointer
*
* Frees any resource used by @group
*/
void
-tool_command_group_free (ToolCommandGroup *group)
+base_tool_command_group_free (ToolCommandGroup *group)
{
if (group) {
g_slist_free (group->name_ordered);
@@ -171,7 +169,7 @@ commands_compare_group (ToolCommand *a, ToolCommand *b)
}
/**
- * tool_command_group_add:
+ * base_tool_command_group_add:
* @group: a #ToolCommandGroup pointer
* @cmd: (transfer none): the command to add
*
@@ -181,7 +179,7 @@ commands_compare_group (ToolCommand *a, ToolCommand *b)
* @cmd is used as it is (i.e. not copied).
*/
void
-tool_command_group_add (ToolCommandGroup *group, ToolCommand *cmd)
+base_tool_command_group_add (ToolCommandGroup *group, ToolCommand *cmd)
{
g_return_if_fail (group);
g_return_if_fail (cmd);
@@ -194,7 +192,7 @@ tool_command_group_add (ToolCommandGroup *group, ToolCommand *cmd)
cmd->name = g_strndup (cmd->name_args, tmp - cmd->name_args);
}
- tool_command_group_remove (group, cmd->name);
+ base_tool_command_group_remove (group, cmd->name);
group->name_ordered = g_slist_insert_sorted (group->name_ordered, cmd,
(GCompareFunc) commands_compare_name);
@@ -203,14 +201,14 @@ tool_command_group_add (ToolCommandGroup *group, ToolCommand *cmd)
}
/**
- * tool_command_group_remove:
+ * base_tool_command_group_remove:
* @group: a #ToolCommandGroup pointer
* @name: the name of the command to remove
*
* Remove @cmd from @group. If @cmd is not in @group, then nothing is done.
*/
void
-tool_command_group_remove (ToolCommandGroup *group, const gchar *name)
+base_tool_command_group_remove (ToolCommandGroup *group, const gchar *name)
{
g_return_if_fail (group);
@@ -231,10 +229,10 @@ tool_command_group_remove (ToolCommandGroup *group, const gchar *name)
}
/**
- * tool_command_group_find:
+ * base_tool_command_group_find:
*/
ToolCommand *
-tool_command_group_find (ToolCommandGroup *group, const gchar *name, GError **error)
+base_tool_command_group_find (ToolCommandGroup *group, const gchar *name, GError **error)
{
ToolCommand *cmd = NULL;
GSList *list;
@@ -274,11 +272,11 @@ tool_command_group_find (ToolCommandGroup *group, const gchar *name, GError **er
if (!cmd &&
((*name == 'h') || (*name == 'H')))
- cmd = tool_command_group_find (group, "?", NULL);
+ cmd = base_tool_command_group_find (group, "?", NULL);
if (!cmd) {
- g_set_error (error, TOOL_COMMAND_ERROR,
- TOOL_COMMAND_COMMAND_NOT_FOUND_ERROR,
+ g_set_error (error, BASE_TOOL_ERROR,
+ BASE_TOOL_COMMAND_COMMAND_NOT_FOUND_ERROR,
_("Command '%s' not found"), name);
}
@@ -308,8 +306,8 @@ split_command_string (const gchar *cmde, guint *out_n_args, GError **error)
else if (*tmp == '\\') {
tmp++;
if (! *tmp) {
- g_set_error (error, TOOL_COMMAND_ERROR,
- TOOL_COMMAND_SYNTAX_ERROR,
+ g_set_error (error, BASE_TOOL_ERROR,
+ BASE_TOOL_COMMAND_SYNTAX_ERROR,
_("Syntax error after '\\'"));
goto onerror;
}
@@ -338,8 +336,8 @@ split_command_string (const gchar *cmde, guint *out_n_args, GError **error)
if (!*tmp) {
if (inquotes) {
- g_set_error (error, TOOL_COMMAND_ERROR,
- TOOL_COMMAND_SYNTAX_ERROR,
+ g_set_error (error, BASE_TOOL_ERROR,
+ BASE_TOOL_COMMAND_SYNTAX_ERROR,
_("Unbalanced usage of quotes"));
goto onerror;
}
@@ -385,9 +383,11 @@ split_command_string (const gchar *cmde, guint *out_n_args, GError **error)
}
/**
- * tool_command_group_execute:
+ * base_tool_command_group_execute:
* @group: a #ToolCommandGroup pointer
* @cmde: the command as a string (name + arguments)
+ * @limit_width: pass to %TRUE if, in case the command is a HELP command, the width must be limited by a
terminal's width
+ * @color_term: pass to %TRUE if, in case the command is a HELP command, the output will be for a terminal
color
* @user_data: (allow-none): a pointer
* @error: (allow-none): a place to store errors, or %NULL
*
@@ -396,15 +396,15 @@ split_command_string (const gchar *cmde, guint *out_n_args, GError **error)
* Returns: (transfer full): a new #ToolCommandResult result
*/
ToolCommandResult *
-tool_command_group_execute (ToolCommandGroup *group, const gchar *cmde,
- ToolOutputFormat format, gpointer user_data, GError **error)
+base_tool_command_group_execute (ToolCommandGroup *group, const gchar *cmde,
+ gpointer user_data, GError **error)
{
g_return_val_if_fail (group, NULL);
if (!cmde || !*cmde) {
ToolCommandResult *res;
res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_EMPTY;
+ res->type = BASE_TOOL_COMMAND_RESULT_EMPTY;
return res;
}
@@ -416,17 +416,14 @@ tool_command_group_execute (ToolCommandGroup *group, const gchar *cmde,
return NULL;
ToolCommandResult *res = NULL;
- GError *lerror = NULL;
- cmd = tool_command_group_find (group, args[0], &lerror);
+ cmd = base_tool_command_group_find (group, args[0], error);
if (!cmd) {
if (args[0] && ((*args[0] == 'h') || (*args[0] == '?'))) {
/* help requested */
- res = tool_help_get_command_help (group, args [1], format);
- g_clear_error (&lerror);
+ res = base_tool_help_get_command_help (group, args [1], error);
}
else {
g_strfreev (args);
- g_propagate_error (error, lerror);
return NULL;
}
}
@@ -442,7 +439,7 @@ tool_command_group_execute (ToolCommandGroup *group, const gchar *cmde,
}
/**
- * tool_command_get_all_commands:
+ * base_tool_command_get_all_commands:
* @group: a #ToolCommandGroup group of commands
*
* Get a list of all the commands (sorted by group) in @group
@@ -450,14 +447,14 @@ tool_command_group_execute (ToolCommandGroup *group, const gchar *cmde,
* Returns: (transfer none): a list of all the #ToolCommand commands
*/
GSList *
-tool_command_get_all_commands (ToolCommandGroup *group)
+base_tool_command_get_all_commands (ToolCommandGroup *group)
{
g_return_val_if_fail (group, NULL);
return group->group_ordered;
}
/**
- * tool_command_get_commands:
+ * base_tool_command_get_commands:
* @group: a #ToolCommandGroup group of commands
* @prefix: (allow-none): a prefix
*
@@ -466,7 +463,7 @@ tool_command_get_all_commands (ToolCommandGroup *group)
* Returns: (transfer container): a list of all the #ToolCommand commands, free using g_slist_free()
*/
GSList *
-tool_command_get_commands (ToolCommandGroup *group, const gchar *prefix)
+base_tool_command_get_commands (ToolCommandGroup *group, const gchar *prefix)
{
g_return_val_if_fail (group, NULL);
if (!prefix || !*prefix)
diff --git a/tools/cmdtool/tool-command.h b/tools/base/base-tool-command.h
similarity index 56%
rename from tools/cmdtool/tool-command.h
rename to tools/base/base-tool-command.h
index 150ee7d..caa29fc 100644
--- a/tools/cmdtool/tool-command.h
+++ b/tools/base/base-tool-command.h
@@ -16,15 +16,15 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#ifndef __TOOL_COMMAND__
-#define __TOOL_COMMAND__
+#ifndef __BASE_TOOL_COMMAND__
+#define __BASE_TOOL_COMMAND__
#include <stdio.h>
#include <glib.h>
#include <libgda.h>
-#include "tool-decl.h"
-#include "tool-output.h"
-#include "tool-input.h"
+#include "base-tool-decl.h"
+#include "base-tool-output.h"
+#include "base-tool-input.h"
/**
* ToolCommandResultType:
@@ -32,14 +32,15 @@
* Defines the type of result of a command result
*/
typedef enum {
- TOOL_COMMAND_RESULT_EMPTY,
- TOOL_COMMAND_RESULT_DATA_MODEL,
- TOOL_COMMAND_RESULT_SET,
- TOOL_COMMAND_RESULT_TREE,
- TOOL_COMMAND_RESULT_TXT,
- TOOL_COMMAND_RESULT_TXT_STDOUT,
- TOOL_COMMAND_RESULT_MULTIPLE,
- TOOL_COMMAND_RESULT_EXIT
+ BASE_TOOL_COMMAND_RESULT_EMPTY,
+ BASE_TOOL_COMMAND_RESULT_DATA_MODEL,
+ BASE_TOOL_COMMAND_RESULT_SET,
+ BASE_TOOL_COMMAND_RESULT_TREE,
+ BASE_TOOL_COMMAND_RESULT_TXT,
+ BASE_TOOL_COMMAND_RESULT_TXT_STDOUT,
+ BASE_TOOL_COMMAND_RESULT_MULTIPLE,
+ BASE_TOOL_COMMAND_RESULT_HELP,
+ BASE_TOOL_COMMAND_RESULT_EXIT
} ToolCommandResultType;
/**
@@ -56,19 +57,20 @@ struct _ToolCommandResult {
GdaSet *set;
GdaTree *tree;
GString *txt;
- GSList *multiple_results; /* for TOOL_COMMAND_RESULT_MULTIPLE */
+ GSList *multiple_results; /* for BASE_TOOL_COMMAND_RESULT_MULTIPLE */
+ xmlNodePtr xml_node; /* for BASE_TOOL_COMMAND_RESULT_HELP */
} u;
};
-ToolCommandResult *tool_command_result_new (GdaConnection *cnc, ToolCommandResultType type);
-void tool_command_result_free (ToolCommandResult *res);
+ToolCommandResult *base_tool_command_result_new (GdaConnection *cnc, ToolCommandResultType type);
+void base_tool_command_result_free (ToolCommandResult *res);
/**
* ToolCommandFunc:
* @command: the #ToolCommand to execute
* @argc: @argv's size
* @argv: the arguments (not including the command's name itself)
- * @user_data: (allow-none): a pointer to some use data, corresponds to the @user_data argument of
tool_command_group_execute()
+ * @user_data: (allow-none): a pointer to some use data, corresponds to the @user_data argument of
base_tool_command_group_execute()
* @error: (allow-none): a place to store errors
*
* Function defining a command's execution code
@@ -76,7 +78,7 @@ void tool_command_result_free (ToolCommandResult *res);
typedef ToolCommandResult *(*ToolCommandFunc) (ToolCommand *command, guint argc, const gchar **argv,
gpointer user_data, GError **error);
-typedef gchar** (*ToolCommandCompletionFunc) (const gchar *text);
+typedef gchar** (*ToolCommandToolInputCompletionFunc) (const gchar *text, gpointer user_data);
/**
* ToolCommand:
@@ -90,34 +92,24 @@ struct _ToolCommand {
gchar *name_args; /* without the '\' or '.', but with the name included */
gchar *description;
ToolCommandFunc command_func;
- ToolCommandCompletionFunc completion_func;
+ ToolCommandToolInputCompletionFunc completion_func;
+ gpointer completion_func_data;
};
-/* error reporting */
-extern GQuark tool_command_error_quark (void);
-#define TOOL_COMMAND_ERROR tool_command_error_quark ()
-
-typedef enum {
- TOOL_COMMAND_COMMAND_NOT_FOUND_ERROR,
- TOOL_COMMAND_SYNTAX_ERROR
-} CoolCommandError;
-
-
/**
* ToolCommandGroup:
*
* A coherent ser of commands
*/
-ToolCommandGroup *tool_command_group_new (void);
-void tool_command_group_free (ToolCommandGroup *group);
-void tool_command_group_add (ToolCommandGroup *group, ToolCommand *cmd);
-void tool_command_group_remove (ToolCommandGroup *group, const gchar *name);
-ToolCommand *tool_command_group_find (ToolCommandGroup *group, const gchar *name, GError **error);
-GSList *tool_command_get_all_commands (ToolCommandGroup *group);
-GSList *tool_command_get_commands (ToolCommandGroup *group, const gchar *prefix);
+ToolCommandGroup *base_tool_command_group_new (void);
+void base_tool_command_group_free (ToolCommandGroup *group);
+void base_tool_command_group_add (ToolCommandGroup *group, ToolCommand *cmd);
+void base_tool_command_group_remove (ToolCommandGroup *group, const gchar *name);
+ToolCommand *base_tool_command_group_find (ToolCommandGroup *group, const gchar *name, GError
**error);
+GSList *base_tool_command_get_all_commands (ToolCommandGroup *group);
+GSList *base_tool_command_get_commands (ToolCommandGroup *group, const gchar *prefix);
-ToolCommandResult *tool_command_group_execute (ToolCommandGroup *group, const gchar *cmde,
- ToolOutputFormat format,
- gpointer user_data, GError **error);
+ToolCommandResult *base_tool_command_group_execute (ToolCommandGroup *group, const gchar *cmde,
+ gpointer user_data, GError **error);
#endif
diff --git a/tools/cmdtool/tool-decl.h b/tools/base/base-tool-decl.h
similarity index 78%
rename from tools/cmdtool/tool-decl.h
rename to tools/base/base-tool-decl.h
index 888c1d1..88b9919 100644
--- a/tools/cmdtool/tool-decl.h
+++ b/tools/base/base-tool-decl.h
@@ -16,16 +16,16 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#ifndef __TOOL_DECL__
-#define __TOOL_DECL__
+#ifndef __BASE_TOOL_DECL__
+#define __BASE_TOOL_DECL__
typedef enum {
- TOOL_OUTPUT_FORMAT_DEFAULT = 1 << 0,
- TOOL_OUTPUT_FORMAT_HTML = 1 << 1,
- TOOL_OUTPUT_FORMAT_XML = 1 << 2,
- TOOL_OUTPUT_FORMAT_CSV = 1 << 3,
+ BASE_TOOL_OUTPUT_FORMAT_DEFAULT = 1 << 0,
+ BASE_TOOL_OUTPUT_FORMAT_HTML = 1 << 1,
+ BASE_TOOL_OUTPUT_FORMAT_XML = 1 << 2,
+ BASE_TOOL_OUTPUT_FORMAT_CSV = 1 << 3,
- TOOL_OUTPUT_FORMAT_COLOR_TERM = 1 << 8
+ BASE_TOOL_OUTPUT_FORMAT_COLOR_TERM = 1 << 8
} ToolOutputFormat;
typedef struct _ToolCommand ToolCommand;
diff --git a/tools/cmdtool/tool-defines.h b/tools/base/base-tool-defines.h
similarity index 77%
rename from tools/cmdtool/tool-defines.h
rename to tools/base/base-tool-defines.h
index e2235c4..a3a6a19 100644
--- a/tools/cmdtool/tool-defines.h
+++ b/tools/base/base-tool-defines.h
@@ -16,12 +16,12 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#ifndef __TOOL_DEFINES__
-#define __TOOL_DEFINES__
+#ifndef __BASE_TOOL_DEFINES__
+#define __BASE_TOOL_DEFINES__
-#define TOOL_NAME "GDA-SQL"
-#define TOOL_HISTORY_ENV_NAME "GDA_SQL_HISTFILE"
-#define TOOL_HISTORY_FILE "gdadsl_history"
-#define TOOL_NO_PAGER "GDA_NO_PAGER"
+#define BASE_TOOL_NAME "GDA-SQL"
+#define BASE_TOOL_HISTORY_ENV_NAME "GDA_SQL_HISTFILE"
+#define BASE_TOOL_HISTORY_FILE "gdadsl_history"
+#define BASE_TOOL_NO_PAGER "GDA_NO_PAGER"
#endif
diff --git a/tools/cmdtool/tool-errors.c b/tools/base/base-tool-errors.c
similarity index 87%
copy from tools/cmdtool/tool-errors.c
copy to tools/base/base-tool-errors.c
index fc4fc1a..1e5864e 100644
--- a/tools/cmdtool/tool-errors.c
+++ b/tools/base/base-tool-errors.c
@@ -16,15 +16,15 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#include "tool-errors.h"
+#include "base-tool-errors.h"
#include <glib/gi18n-lib.h>
/* module error */
GQuark
-tool_errors_quark (void)
+base_tool_errors_quark (void)
{
static GQuark quark;
if (!quark)
- quark = g_quark_from_static_string ("tool_errors");
+ quark = g_quark_from_static_string ("base_tool_errors");
return quark;
}
diff --git a/tools/cmdtool/tool-errors.h b/tools/base/base-tool-errors.h
similarity index 75%
rename from tools/cmdtool/tool-errors.h
rename to tools/base/base-tool-errors.h
index 4c35586..09d57a3 100644
--- a/tools/cmdtool/tool-errors.h
+++ b/tools/base/base-tool-errors.h
@@ -16,19 +16,21 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#ifndef __TOOL_ERRORS__
-#define __TOOL_ERRORS__
+#ifndef __BASE_TOOL_ERRORS__
+#define __BASE_TOOL_ERRORS__
#include <glib.h>
/*
* error reporting
*/
-extern GQuark tool_errors_quark (void);
-#define TOOL_ERRORS tool_errors_quark ()
+extern GQuark base_tool_errors_quark (void);
+#define BASE_TOOL_ERROR base_tool_errors_quark ()
typedef enum {
- TOOL_STORED_DATA_ERROR
-} ToolErrors;
+ BASE_TOOL_STORED_DATA_ERROR,
+ BASE_TOOL_COMMAND_COMMAND_NOT_FOUND_ERROR,
+ BASE_TOOL_COMMAND_SYNTAX_ERROR
+} ToolError;
#endif
diff --git a/tools/cmdtool/tool-help.c b/tools/base/base-tool-help.c
similarity index 58%
rename from tools/cmdtool/tool-help.c
rename to tools/base/base-tool-help.c
index 60cd3d8..fbb0797 100644
--- a/tools/cmdtool/tool-help.c
+++ b/tools/base/base-tool-help.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2012 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2012 - 2014 Vivien Malerba <malerba gnome-db org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -16,34 +16,14 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#include "tool-help.h"
-#include "tool-command.h"
-#include "tool-input.h"
+#include "base-tool-help.h"
+#include "base-tool-command.h"
+#include "base-tool-input.h"
#include <glib/gi18n-lib.h>
#include <libgda/binreloc/gda-binreloc.h>
static xmlDocPtr helpdoc = NULL;
-/**
- * tools_help_set_xml_file:
- *
- * Returns: %TRUE if file has been loaded
- */
-gboolean
-tool_help_set_xml_file (const gchar *file)
-{
- if (helpdoc) {
- xmlFreeDoc (helpdoc);
- helpdoc = NULL;
- }
- if (file) {
- helpdoc = xmlParseFile (file);
- return helpdoc ? TRUE : FALSE;
- }
- else
- return TRUE;
-}
-
/*
* Same as append_to_string but cuts strings which are too long
*/
@@ -214,23 +194,13 @@ append_to_string (GString *string, gchar *str, gint width, gint offset)
}
}
+/*
+ * @node must be a <command> tag
+ */
static gchar *
-help_xml_doc_to_string_command (xmlDocPtr helpdoc, const gchar *command_name, gint width, ToolOutputFormat
format)
+help_xml_doc_to_string_single_command (xmlNodePtr node, gint width, gboolean color_term)
{
- xmlNodePtr node;
- node = xmlDocGetRootElement (helpdoc);
- if (!node || !command_name || !*command_name)
- return NULL;
- for (node = node->children; node; node = node->next) {
- if (strcmp ((gchar*) node->name, "command"))
- continue;
- xmlChar *prop;
- prop = xmlGetProp (node, BAD_CAST "name");
- if (prop && !strcmp ((gchar*) prop, command_name))
- break;
- }
- if (!node)
- return NULL;
+ g_assert (!strcmp ((gchar*) node->name, "command"));
/* create output string */
GString *string;
@@ -241,7 +211,7 @@ help_xml_doc_to_string_command (xmlDocPtr helpdoc, const gchar *command_name, gi
data = xmlNodeGetContent (node);
if (data) {
append_to_string (string, (gchar*) data, width, 0);
- g_string_append (string, "\n\n");
+ g_string_append (string, "\n");
}
}
else if (!strcmp ((gchar*) node->name, "usage") || !strcmp ((gchar*) node->name, "example")) {
@@ -258,9 +228,9 @@ help_xml_doc_to_string_command (xmlDocPtr helpdoc, const gchar *command_name, gi
append_to_string (string, "> ", width, 3);
gchar *tmp;
tmp = g_strdup_printf ("%s%s%s",
- tool_output_color_s (TOOL_COLOR_BOLD,
format),
+ base_tool_output_color_s
(BASE_TOOL_COLOR_BOLD, color_term),
data,
- tool_output_color_s (TOOL_COLOR_RESET,
format));
+ base_tool_output_color_s
(BASE_TOOL_COLOR_RESET, color_term));
append_to_string (string, tmp, width, 3);
g_free (tmp);
g_string_append_c (string, '\n');
@@ -293,74 +263,68 @@ help_xml_doc_to_string_command (xmlDocPtr helpdoc, const gchar *command_name, gi
}
static gchar *
-help_xml_doc_to_string_section (xmlDocPtr helpdoc, const gchar *section_name, gint width)
+help_xml_doc_to_string_command (xmlNodePtr node, gint width, gboolean color_term)
{
- xmlNodePtr node;
- node = xmlDocGetRootElement (helpdoc);
- if (!node || !section_name || !*section_name)
- return NULL;
- for (node = node->children; node; node = node->next) {
- if (strcmp ((gchar*) node->name, "section"))
- continue;
- xmlChar *prop;
- prop = xmlGetProp (node, BAD_CAST "name");
- if (prop && strstr ((gchar*) prop, section_name))
- break;
- }
- if (!node)
- return NULL;
-
- /* create output string */
- GString *string;
- string = g_string_new ("");
- for (node = node->children; node; node = node->next) {
- xmlChar *data = NULL;
- if (!strcmp ((gchar*) node->name, "shortdescription")) {
- data = xmlNodeGetContent (node);
- if (data) {
- append_to_string (string, (gchar*) data, width, 0);
- g_string_append (string, "\n\n");
- }
- }
- else if (!strcmp ((gchar*) node->name, "usage") || !strcmp ((gchar*) node->name, "example")) {
- if (!strcmp ((gchar*) node->name, "example")) {
- append_to_string (string, _("Example"), width, 0);
- g_string_append (string, ":\n");
+ if (!strcmp ((gchar*) node->name, "command"))
+ return help_xml_doc_to_string_single_command (node, width, color_term);
+ else {
+ GString *string;
+ string = g_string_new ("");
+ for (node = node->children; node; node = node->next) {
+ if (!strcmp ((gchar*) node->name, "command")) {
+ gchar *tmp;
+ tmp = help_xml_doc_to_string_single_command (node, width, color_term);
+ g_string_append (string, tmp);
+ g_free (tmp);
}
- xmlNodePtr snode;
- for (snode = node->children; snode; snode = snode->next) {
- if (!strcmp ((gchar*) snode->name, "synopsis")) {
- data = xmlNodeGetContent (snode);
- if (data) {
- append_to_string (string, "> ", width, 3);
- append_to_string (string, (gchar*) data, width, 3);
- g_string_append_c (string, '\n');
- }
+ else if (!strcmp ((gchar*) node->name, "section")) {
+ xmlChar *section_name;
+ section_name = xmlGetProp (node, BAD_CAST "name");
+ if (width > 0) {
+ gint i, nb, remain;
+ nb = (width - g_utf8_strlen ((gchar*) section_name, -1) - 2) / 2;
+ remain = width - (2 * nb + 2 + g_utf8_strlen ((gchar*) section_name,
-1));
+ for (i = 0; i < nb; i++)
+ g_string_append_c (string, '=');
+ g_string_append_c (string, ' ');
+ append_to_string (string, (gchar*) section_name, width, 0);
+ g_string_append_c (string, ' ');
+ for (i = 0; i < nb + remain; i++)
+ g_string_append_c (string, '=');
+ g_string_append_c (string, '\n');
}
- else if (!strcmp ((gchar*) snode->name, "comment")) {
- data = xmlNodeGetContent (snode);
- if (data) {
- append_to_string (string, (gchar*) data, width, 3);
- g_string_append_c (string, '\n');
- }
+ else {
+ g_string_append (string, "=== ");
+ append_to_string (string, (gchar*) section_name, width, 0);
+ g_string_append (string, " ===\n");
}
- else if (!strcmp ((gchar*) snode->name, "raw")) {
- data = xmlNodeGetContent (snode);
- if (data) {
- append_raw_to_string (string, (gchar*) data, width, 3);
- g_string_append (string, "\n\n");
+
+ xmlNodePtr snode;
+ for (snode = node->children; snode; snode = snode->next) {
+ if (!strcmp ((gchar*) snode->name, "command")) {
+ gchar *tmp;
+ tmp = help_xml_doc_to_string_single_command (snode, width,
color_term);
+ g_string_append (string, tmp);
+ g_free (tmp);
}
+ if (snode->next)
+ g_string_append_c (string, '\n');
}
- if (data)
- xmlFree (data);
- data = NULL;
}
}
- if (data)
- xmlFree (data);
+ return g_string_free (string, FALSE);
}
+}
- return g_string_free (string, FALSE);
+/**
+ * base_tool_help_to_string:
+ *
+ * Returns: a new string
+ */
+gchar *
+base_tool_help_to_string (ToolCommandResult *help, gboolean limit_width, gboolean color_term)
+{
+ return help_xml_doc_to_string_command (help->u.xml_node, limit_width, color_term);
}
/**
@@ -396,121 +360,94 @@ load_help_doc (void)
/**
* tools_help_get_command_help:
+ *
+ * Note: the XML node in the help part will be:
+ * - either a <command> tag
+ * - either a <commands> tag including <command> tags
+ *
+ * Returns: (transfer full): a new ToolCommandResult of type BASE_TOOL_COMMAND_RESULT_HELP
*/
ToolCommandResult *
-tool_help_get_command_help (ToolCommandGroup *group, const gchar *command_name, ToolOutputFormat format)
+base_tool_help_get_command_help (ToolCommandGroup *group, const gchar *command_name, GError **error)
{
- ToolCommandResult *res;
- GSList *list;
- gchar *current_group = NULL;
- GString *string = g_string_new ("");
-#define NAMESIZE 18
-
- /* get term size */
- gint width = -1;
- if (format | TOOL_OUTPUT_FORMAT_DEFAULT)
- input_get_size (&width, NULL);
+ xmlNodePtr retnode = NULL;
- res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_TXT;
+ if (!helpdoc)
+ helpdoc = load_help_doc ();
if (command_name) {
ToolCommand *command = NULL;
- GError *lerror = NULL;
if ((*command_name == '.') || (*command_name == '\\'))
command_name = command_name + 1;
- command = tool_command_group_find (group, command_name, &lerror);
+ command = base_tool_command_group_find (group, command_name, error);
if (command) {
- if (!helpdoc)
- helpdoc = load_help_doc ();
-
gboolean done = FALSE;
if (helpdoc) {
- gchar *tmp;
- tmp = help_xml_doc_to_string_command (helpdoc, command_name, width, format);
- if (tmp) {
- g_string_append (string, tmp);
- g_free (tmp);
- done = TRUE;
+ xmlNodePtr node;
+ node = xmlDocGetRootElement (helpdoc);
+ if (node) {
+ for (node = node->children; node; node = node->next) {
+ if (strcmp ((gchar*) node->name, "command"))
+ continue;
+ xmlChar *prop;
+ prop = xmlGetProp (node, BAD_CAST "name");
+ if (prop && !strcmp ((gchar*) prop, command_name)) {
+ retnode = xmlCopyNode (node, 1);
+ done = TRUE;
+ break;
+ }
+ }
}
}
if (!done) {
- append_to_string (string, command->description, width, 0);
- g_string_append_printf (string, "\n\n%s:\n ", _("Usage"));
- tool_output_color_append_string (TOOL_COLOR_BOLD, format, string, ".");
- tool_output_color_append_string (TOOL_COLOR_BOLD, format, string,
command->name_args);
+ /* build XML tree */
+ xmlNodePtr top, node;
+ top = xmlNewNode (NULL, BAD_CAST "command");
+ xmlSetProp (top, BAD_CAST "name", BAD_CAST command->name);
+ node = xmlNewChild (top, NULL, BAD_CAST "shortdescription", BAD_CAST
command->description);
+ node = xmlNewChild (top, NULL, BAD_CAST "usage", NULL);
+ gchar *tmp;
+ tmp = g_strdup_printf (".%s", command->name_args);
+ node = xmlNewChild (node, NULL, BAD_CAST "synopsis", BAD_CAST tmp);
+ g_free (tmp);
+ retnode = top;
}
}
- else {
- g_string_append_printf (string, "%s", lerror->message);
- g_clear_error (&lerror);
- }
}
else {
- GSList *all_commands;
- all_commands = tool_command_get_all_commands (group);
+ GSList *all_commands, *list;
+ xmlNodePtr commands, section;
+ const gchar *current_section = NULL;
+ commands = xmlNewNode (NULL, BAD_CAST "commands");
+ retnode = commands;
+ all_commands = base_tool_command_get_all_commands (group);
for (list = all_commands; list; list = list->next) {
ToolCommand *command = (ToolCommand*) list->data;
- gint clen;
-
-#ifdef HAVE_LDAP
- if (g_str_has_prefix (command->name, "ldap") && cnc && !GDA_IS_LDAP_CONNECTION (cnc))
- continue;
-#endif
-
- if (!current_group || strcmp (current_group, command->group)) {
- current_group = command->group;
- if (list != all_commands)
- g_string_append_c (string, '\n');
- if (width > 0) {
- gint i, nb, remain;
- nb = (width - g_utf8_strlen (current_group, -1) - 2) / 2;
- remain = width - (2 * nb + 2 + g_utf8_strlen (current_group, -1));
- for (i = 0; i < nb; i++)
- g_string_append_c (string, '=');
- g_string_append_c (string, ' ');
- append_to_string (string, current_group, width, 0);
- g_string_append_c (string, ' ');
- for (i = 0; i < nb + remain; i++)
- g_string_append_c (string, '=');
- g_string_append_c (string, '\n');
- }
- else {
- g_string_append (string, "=== ");
- append_to_string (string, current_group, width, 0);
- g_string_append (string, " ===\n");
- }
-
- if (!helpdoc)
- helpdoc = load_help_doc ();
-
- if (helpdoc && command->group_id) {
- gchar *tmp;
- tmp = help_xml_doc_to_string_section (helpdoc, command->group_id,
width);
- if (tmp) {
- g_string_append (string, tmp);
- g_free (tmp);
- g_string_append_c (string, '\n');
- }
- }
+ if (!current_section || strcmp (current_section, command->group)) {
+ section = xmlNewChild (commands, NULL, BAD_CAST "section", NULL);
+ xmlSetProp (section, BAD_CAST "name", BAD_CAST command->group);
+ current_section = command->group;
}
- g_string_append (string, " ");
- tool_output_color_append_string (TOOL_COLOR_BOLD, format, string, ".");
- tool_output_color_append_string (TOOL_COLOR_BOLD, format, string, command->name);
- clen = g_utf8_strlen (command->name, -1);
- if (clen >= NAMESIZE)
- g_string_append_c (string, '\n');
- else {
- gint i, size;
- size = NAMESIZE - clen - 1;
- for (i = 0; i < size; i++)
- g_string_append_c (string, ' ');
- }
- append_to_string (string, command->description, width, NAMESIZE + 3);
- g_string_append_c (string, '\n');
+ xmlNodePtr top, node;
+ top = xmlNewChild (section, NULL, BAD_CAST "command", NULL);
+ xmlSetProp (top, BAD_CAST "name", BAD_CAST command->name);
+ node = xmlNewChild (top, NULL, BAD_CAST "shortdescription", BAD_CAST
command->description);
+ node = xmlNewChild (top, NULL, BAD_CAST "usage", NULL);
+ gchar *tmp;
+ tmp = g_strdup_printf (".%s", command->name_args);
+ node = xmlNewChild (node, NULL, BAD_CAST "synopsis", BAD_CAST tmp);
+ g_free (tmp);
}
}
- res->u.txt = string;
- return res;
+
+ if (retnode) {
+ ToolCommandResult *res = NULL;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = BASE_TOOL_COMMAND_RESULT_HELP;
+ res->u.xml_node = retnode;
+ return res;
+ }
+ else
+ return NULL;
}
diff --git a/tools/cmdtool/tool-help.h b/tools/base/base-tool-help.h
similarity index 66%
copy from tools/cmdtool/tool-help.h
copy to tools/base/base-tool-help.h
index 71c36d9..96004fc 100644
--- a/tools/cmdtool/tool-help.h
+++ b/tools/base/base-tool-help.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2012 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2012 - 2014 Vivien Malerba <malerba gnome-db org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -16,14 +16,14 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#ifndef __TOOL_HELP__
-#define __TOOL_HELP__
+#ifndef __BASE_TOOL_HELP__
+#define __BASE_TOOL_HELP__
#include <stdio.h>
#include <glib.h>
-#include "tool-command.h"
+#include "base-tool-command.h"
-gboolean tool_help_set_xml_file (const gchar *file);
-ToolCommandResult *tool_help_get_command_help (ToolCommandGroup *group, const gchar *command_name,
ToolOutputFormat format);
+ToolCommandResult *base_tool_help_get_command_help (ToolCommandGroup *group, const gchar *command_name,
GError **error);
+gchar *base_tool_help_to_string (ToolCommandResult *help, gboolean limit_width, gboolean
color_term);
#endif
diff --git a/tools/cmdtool/tool-input.c b/tools/base/base-tool-input.c
similarity index 73%
rename from tools/cmdtool/tool-input.c
rename to tools/base/base-tool-input.c
index f4beffd..ddb01ed 100644
--- a/tools/cmdtool/tool-input.c
+++ b/tools/base/base-tool-input.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2007 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2007 - 2014 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2010 David King <davidk openismus com>
*
* This program is free software; you can redistribute it and/or
@@ -17,9 +17,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#include "tool-errors.h"
-#include "tool-input.h"
-#include "tool-command.h"
+#include "base-tool-errors.h"
+#include "base-tool-input.h"
+#include "base-tool-command.h"
#include <glib/gi18n-lib.h>
#include <glib/gstdio.h>
#include <string.h>
@@ -27,19 +27,19 @@
#include <errno.h>
#include <unistd.h>
#ifndef G_OS_WIN32
-#include <sys/ioctl.h>
+ #include <sys/ioctl.h>
#endif
#define TO_IMPLEMENT g_print ("Implementation missing: %s() in %s line %d\n", __FUNCTION__,
__FILE__,__LINE__)
#ifdef HAVE_READLINE
-#include <readline/readline.h>
+ #include <readline/readline.h>
#endif
#ifdef HAVE_HISTORY
-#include <readline/history.h>
+ #include <readline/history.h>
#endif
-#include "tool-defines.h"
+#include "base-tool-defines.h"
#ifdef HAVE_HISTORY
static gboolean history_init_done = FALSE;
@@ -49,12 +49,12 @@ gchar *history_file = NULL;
static void init_history ();
/**
- * input_from_stream
+ * base_tool_input_from_stream
*
* returns: a new string read from @stream
*/
gchar *
-input_from_stream (FILE *stream)
+base_tool_input_from_stream (FILE *stream)
{
#define LINE_SIZE 65535
gchar line [LINE_SIZE];
@@ -71,15 +71,17 @@ input_from_stream (FILE *stream)
}
}
-static TreatLineFunc line_cb_func = NULL;
+static ToolInputTreatLineFunc line_cb_func = NULL;
static gpointer line_cb_func_data = NULL;
-static ComputePromptFunc line_prompt_func = NULL;
+static ToolInputComputePromptFunc line_prompt_func = NULL;
static GIOChannel *ioc = NULL;
static gboolean
chars_for_readline_cb (G_GNUC_UNUSED GIOChannel *ioc, G_GNUC_UNUSED GIOCondition condition,
G_GNUC_UNUSED gpointer data)
{
+ gboolean res = TRUE;
+
#ifdef HAVE_READLINE
rl_callback_read_char ();
#else
@@ -91,10 +93,13 @@ chars_for_readline_cb (G_GNUC_UNUSED GIOChannel *ioc, G_GNUC_UNUSED GIOCondition
switch (st) {
case G_IO_STATUS_NORMAL:
line [tpos] = 0;
- if (line_cb_func (line, line_cb_func_data) == TRUE) {
+ gboolean need_quit;
+ need_quit = line_cb_func (line, line_cb_func_data);
+ if (!need_quit) {
/* print prompt for next line */
g_print ("%s", line_prompt_func ());
}
+ res = !need_quit;
g_free (line);
break;
case G_IO_STATUS_ERROR:
@@ -104,34 +109,38 @@ chars_for_readline_cb (G_GNUC_UNUSED GIOChannel *ioc, G_GNUC_UNUSED GIOCondition
g_error_free (error);
break;
case G_IO_STATUS_EOF:
- /* send the Quit command */
- line_cb_func (".q", line_cb_func_data);
return FALSE;
break;
default:
break;
}
#endif
- return TRUE;
+ return res;
}
#ifdef HAVE_READLINE
static void
line_read_handler (char *line)
{
- line_cb_func (line, line_cb_func_data); /* we don't care about the return status */
+ gboolean need_quit;
+ need_quit = line_cb_func (line, line_cb_func_data); /* we don't care about the return status */
free (line);
- rl_set_prompt (line_prompt_func ());
+ if (need_quit)
+ base_tool_input_end ();
+ else
+ rl_set_prompt (line_prompt_func ());
}
#endif
/**
- * init_input
+ * base_tool_input_init:
+ * @context: a #GMainContext
*
* Initializes input
*/
void
-init_input (TreatLineFunc treat_line_func, ComputePromptFunc prompt_func, gpointer data)
+base_tool_input_init (GMainContext *context, ToolInputTreatLineFunc treat_line_func,
+ ToolInputComputePromptFunc prompt_func, gpointer data)
{
/* init readline related features */
line_cb_func = treat_line_func;
@@ -148,7 +157,11 @@ init_input (TreatLineFunc treat_line_func, ComputePromptFunc prompt_func, gpoint
#endif
if (!ioc) {
ioc = g_io_channel_unix_new (STDIN_FILENO);
- g_io_add_watch (ioc, G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL, (GIOFunc)
chars_for_readline_cb, NULL);
+ GSource *src;
+ src = g_io_create_watch (ioc, G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL);
+ g_source_set_callback (src, (GSourceFunc) chars_for_readline_cb, NULL, NULL);
+ g_source_attach (src, context);
+ g_source_unref (src);
}
/* init history */
@@ -162,12 +175,12 @@ init_input (TreatLineFunc treat_line_func, ComputePromptFunc prompt_func, gpoint
}
/**
- * end_input
+ * base_tool_input_end
*
- * Releases any data related to the input and allocated during init_input()
+ * Releases any data related to the input and allocated during base_tool_input_init()
*/
void
-end_input (void)
+base_tool_input_end (void)
{
#ifdef HAVE_READLINE
rl_callback_handler_remove ();
@@ -175,9 +188,11 @@ end_input (void)
if (ioc) {
g_io_channel_shutdown (ioc, TRUE, NULL);
g_io_channel_unref (ioc);
+ ioc = NULL;
}
}
+#ifdef HAVE_READLINE
static gsize
determine_max_prefix_len (gchar **array)
{
@@ -203,14 +218,16 @@ determine_max_prefix_len (gchar **array)
return max - 1;
}
+#endif
static ToolCommandGroup *user_defined_completion_group = NULL;
-static CompletionFunc user_defined_completion_func = NULL;
+static ToolInputCompletionFunc user_defined_completion_func = NULL;
+static gpointer user_defined_completion_func_data = NULL;
static gchar *user_defined_chars_to_ignore = NULL;
#ifdef HAVE_READLINE
static char **
-_tool_completion (const char *text, int start, int end)
+_base_tool_completion (const char *text, int start, int end)
{
GArray *array = NULL;
gchar *match, *prematch;
@@ -244,7 +261,7 @@ _tool_completion (const char *text, int start, int end)
if (!user_defined_chars_to_ignore || (start_char && user_defined_chars_to_ignore)) {
GSList *commands;
- commands = tool_command_get_commands (user_defined_completion_group, cmd_match);
+ commands = base_tool_command_get_commands (user_defined_completion_group, cmd_match);
if (commands) {
array = g_array_new (TRUE, FALSE, sizeof (gchar*));
GSList *list;
@@ -278,12 +295,13 @@ _tool_completion (const char *text, int start, int end)
}
}
}
- tc = tool_command_group_find (user_defined_completion_group, tmp, NULL);
+ tc = base_tool_command_group_find (user_defined_completion_group, tmp, NULL);
}
if (tc && tc->completion_func)
- vals = tc->completion_func (text);
+ vals = tc->completion_func (text, tc->completion_func_data);
else
- vals = user_defined_completion_func (text, rl_line_buffer, start, end);
+ vals = user_defined_completion_func (text, rl_line_buffer, start, end,
+ user_defined_completion_func_data);
if (vals) {
guint i;
@@ -326,41 +344,43 @@ _tool_completion (const char *text, int start, int end)
#endif /* HAVE_READLINE */
/**
- * tool_input_set_completion_func:
+ * base_tool_input_set_completion_func:
* @group: (allow-none): a #ToolCommandGroup, or %NULL
- * @func: (allow-none): a #CompletionFunc, or %NULL
+ * @func: (allow-none): a #ToolInputCompletionFunc, or %NULL
+ * @func_data: (allow-none): a pointer to pass when calling @func
* @start_chars_to_ignore: (allow-none): a list of characters to ignore at the beginning of commands
*
* Defines the completion function.
*/
void
-tool_input_set_completion_func (ToolCommandGroup *group, CompletionFunc func, gchar *start_chars_to_ignore)
+base_tool_input_set_completion_func (ToolCommandGroup *group, ToolInputCompletionFunc func, gpointer
func_data, gchar *start_chars_to_ignore)
{
user_defined_completion_group = group;
user_defined_completion_func = func;
+ user_defined_completion_func_data = func_data;
g_free (user_defined_chars_to_ignore);
user_defined_chars_to_ignore = start_chars_to_ignore ? g_strdup (start_chars_to_ignore) : NULL;
#ifdef HAVE_READLINE
if (group || func)
- rl_attempted_completion_function = _tool_completion;
+ rl_attempted_completion_function = _base_tool_completion;
else
rl_attempted_completion_function = NULL;
#endif
}
/*
- * input_get_size
+ * base_tool_input_get_size
*
* Get the size of the input term, if possible, otherwise returns -1
*/
void
-input_get_size (gint *width, gint *height)
+base_tool_input_get_size (gint *width, gint *height)
{
- int tty = fileno (stdin);
int cols = -1, rows = -1;
#ifdef TIOCGWINSZ
+ int tty = fileno (stdin);
struct winsize window_size;
if (ioctl (tty, TIOCGWINSZ, &window_size) == 0) {
cols = (int) window_size.ws_col;
@@ -381,6 +401,7 @@ input_get_size (gint *width, gint *height)
/*g_print ("Screen: %dx%d\n", cols, rows);*/
}
+#ifdef HAVE_HISTORY
static void
sanitize_env (gchar *str)
{
@@ -390,6 +411,7 @@ sanitize_env (gchar *str)
*ptr = '_';
}
}
+#endif
/**
* init_history
@@ -402,9 +424,9 @@ init_history ()
#ifdef HAVE_HISTORY
if (history_init_done)
return;
- if (getenv (TOOL_HISTORY_ENV_NAME)) {
+ if (getenv (BASE_TOOL_HISTORY_ENV_NAME)) {
const gchar *ename;
- ename = getenv (TOOL_HISTORY_ENV_NAME);
+ ename = getenv (BASE_TOOL_HISTORY_ENV_NAME);
if (!ename || !*ename || !strcmp (ename, "NO_HISTORY")) {
history_init_done = TRUE;
return;
@@ -418,11 +440,11 @@ init_history ()
cache_dir = g_build_filename (g_get_user_cache_dir (), "libgda", NULL);
#else
gchar *tmp;
- tmp = g_utf8_strdown (TOOL_NAME, -1);
+ tmp = g_utf8_strdown (BASE_TOOL_NAME, -1);
cache_dir = g_build_filename (g_get_user_cache_dir (), tmp, NULL);
g_free (tmp);
#endif
- history_file = g_build_filename (cache_dir, TOOL_HISTORY_FILE, NULL);
+ history_file = g_build_filename (cache_dir, BASE_TOOL_HISTORY_FILE, NULL);
if (!g_file_test (cache_dir, G_FILE_TEST_EXISTS)) {
if (g_mkdir_with_parents (cache_dir, 0700)) {
g_free (history_file);
@@ -440,10 +462,10 @@ init_history ()
}
/**
- * add_to_history
+ * base_tool_input_add_to_history
*/
void
-add_to_history (const gchar *txt)
+base_tool_input_add_to_history (const gchar *txt)
{
#ifdef HAVE_HISTORY
if (!history_init_done)
@@ -461,10 +483,10 @@ add_to_history (const gchar *txt)
}
/**
- * save_history
+ * base_tool_input_save_history
*/
gboolean
-save_history (const gchar *file, GError **error)
+base_tool_input_save_history (const gchar *file, GError **error)
{
#ifdef HAVE_HISTORY
int res;
@@ -474,7 +496,7 @@ save_history (const gchar *file, GError **error)
if (res == ENOENT)
res = write_history (file ? file : history_file);
if (res != 0) {
- g_set_error (error, TOOL_ERRORS, TOOL_STORED_DATA_ERROR,
+ g_set_error (error, BASE_TOOL_ERROR, BASE_TOOL_STORED_DATA_ERROR,
_("Could not save history file to '%s': %s"),
file ? file : history_file, strerror (errno));
return FALSE;
@@ -484,3 +506,32 @@ save_history (const gchar *file, GError **error)
#endif
return TRUE;
}
+
+#define MAX_HIST_FETCHED 200
+/**
+ * base_tool_input_get_history:
+ *
+ * Get the (at most 200) recent history commands
+ *
+ * Returns: (transfer full): a new string of the whole history
+ */
+gchar *
+base_tool_input_get_history (void)
+{
+ GString *string;
+ string = g_string_new ("");
+#ifdef HAVE_HISTORY
+ HIST_ENTRY **hist_array = history_list ();
+ if (hist_array) {
+ HIST_ENTRY *current;
+ gint index;
+ for (index = 0, current = *hist_array;
+ current && (index < MAX_HIST_FETCHED);
+ index++, current = hist_array [index]) {
+ g_string_append (string, current->line);
+ g_string_append_c (string, '\n');
+ }
+ }
+#endif
+ return g_string_free (string, FALSE);
+}
diff --git a/tools/cmdtool/tool-input.h b/tools/base/base-tool-input.h
similarity index 51%
rename from tools/cmdtool/tool-input.h
rename to tools/base/base-tool-input.h
index 8ce6ca4..3ae8b60 100644
--- a/tools/cmdtool/tool-input.h
+++ b/tools/base/base-tool-input.h
@@ -3,7 +3,7 @@
* Copyright (C) 2001 Reinhard Müller <reinhard src gnome org>
* Copyright (C) 2002 - 2003 Gonzalo Paniagua Javier <gonzalo src gnome org>
* Copyright (C) 2007 Baris Cicek <bcicek src gnome org>
- * Copyright (C) 2007 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2007 - 2014 Vivien Malerba <malerba gnome-db org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -20,28 +20,29 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#ifndef __TOOLS_INPUT__
-#define __TOOLS_INPUT__
+#ifndef __BASE_TOOL_INPUT__
+#define __BASE_TOOL_INPUT__
#include <stdio.h>
#include <glib.h>
#ifdef HAVE_READLINE
#include <readline/readline.h>
#endif
-#include "tool-decl.h"
+#include "base-tool-decl.h"
-typedef char **(*CompletionFunc) (const char *match, const char *line, int start, int end);
-typedef gboolean (*TreatLineFunc) (const gchar *, gpointer);
-typedef const char *(*ComputePromptFunc) (void);
+typedef char **(*ToolInputCompletionFunc) (const char *match, const char *line, int start, int end,
gpointer func_data);
+typedef gboolean (*ToolInputTreatLineFunc) (const gchar *, gpointer);
+typedef const char *(*ToolInputComputePromptFunc) (void);
-gchar *input_from_stream (FILE *stream);
+gchar *base_tool_input_from_stream (FILE *stream);
-void init_input (TreatLineFunc treat_line_func, ComputePromptFunc prompt_func, gpointer data);
-void input_get_size (gint *width, gint *height);
-void end_input (void);
+void base_tool_input_init (GMainContext *context, ToolInputTreatLineFunc treat_line_func,
ToolInputComputePromptFunc prompt_func, gpointer data);
+void base_tool_input_get_size (gint *width, gint *height);
+void base_tool_input_end (void);
-void add_to_history (const gchar *txt);
-gboolean save_history (const gchar *file, GError **error);
-void tool_input_set_completion_func (ToolCommandGroup *group, CompletionFunc func, gchar
*start_chars_to_ignore);
+void base_tool_input_add_to_history (const gchar *txt);
+gboolean base_tool_input_save_history (const gchar *file, GError **error);
+void base_tool_input_set_completion_func (ToolCommandGroup *group, ToolInputCompletionFunc func,
gpointer func_data, gchar *start_chars_to_ignore);
+gchar *base_tool_input_get_history (void);
#endif
diff --git a/tools/cmdtool/tool-output.c b/tools/base/base-tool-output.c
similarity index 85%
rename from tools/cmdtool/tool-output.c
rename to tools/base/base-tool-output.c
index 8feca5c..601b252 100644
--- a/tools/cmdtool/tool-output.c
+++ b/tools/base/base-tool-output.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2012 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2012 - 2014 Vivien Malerba <malerba gnome-db org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -16,8 +16,9 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#include "tool-defines.h"
-#include "tool-output.h"
+#include "base-tool-defines.h"
+#include "base-tool-output.h"
+#include "base-tool-help.h"
#include <glib/gi18n-lib.h>
#include <glib/gstdio.h>
#include <unistd.h>
@@ -60,17 +61,20 @@ make_options_set_from_string (const gchar *context, GdaSet *options)
return expopt;
}
-static gchar *
-data_model_to_string (GdaDataModel *model, ToolOutputFormat format, FILE *stream, GdaSet *options)
+/**
+ * base_tool_output_data_model_to_string:
+ */
+gchar *
+base_tool_output_data_model_to_string (GdaDataModel *model, ToolOutputFormat format, FILE *stream, GdaSet
*options)
{
if (!GDA_IS_DATA_MODEL (model))
return NULL;
- if (format & TOOL_OUTPUT_FORMAT_DEFAULT) {
+ if (format & BASE_TOOL_OUTPUT_FORMAT_DEFAULT) {
gchar *tmp;
GdaSet *local_options;
gint width;
- input_get_size (&width, NULL);
+ base_tool_input_get_size (&width, NULL);
local_options = gda_set_new_inline (6, "NAME", G_TYPE_BOOLEAN, TRUE,
"NULL_AS_EMPTY", G_TYPE_BOOLEAN, TRUE,
"MAX_WIDTH", G_TYPE_INT, width,
@@ -95,11 +99,11 @@ data_model_to_string (GdaDataModel *model, ToolOutputFormat format, FILE *stream
else
return tmp;
}
- else if (format & TOOL_OUTPUT_FORMAT_XML)
+ else if (format & BASE_TOOL_OUTPUT_FORMAT_XML)
return gda_data_model_export_to_string (model, GDA_DATA_MODEL_IO_DATA_ARRAY_XML,
NULL, 0,
NULL, 0, NULL);
- else if (format & TOOL_OUTPUT_FORMAT_CSV) {
+ else if (format & BASE_TOOL_OUTPUT_FORMAT_CSV) {
gchar *retval;
GdaSet *optexp;
optexp = make_options_set_from_string ("csv", options);
@@ -110,7 +114,7 @@ data_model_to_string (GdaDataModel *model, ToolOutputFormat format, FILE *stream
g_object_unref (optexp);
return retval;
}
- else if (format & TOOL_OUTPUT_FORMAT_HTML) {
+ else if (format & BASE_TOOL_OUTPUT_FORMAT_HTML) {
xmlBufferPtr buffer;
xmlNodePtr top, div, table, node, row_node, col_node, header, meta;
gint ncols, nrows, i, j;
@@ -428,15 +432,15 @@ tree_to_string (GdaTree *tree, ToolOutputFormat format, FILE *stream, GdaSet *op
if (!GDA_IS_TREE (tree))
return NULL;
- if (format & TOOL_OUTPUT_FORMAT_DEFAULT)
+ if (format & BASE_TOOL_OUTPUT_FORMAT_DEFAULT)
return tree_to_string_default (tree, stream, options);
- else if (format & TOOL_OUTPUT_FORMAT_XML) {
+ else if (format & BASE_TOOL_OUTPUT_FORMAT_XML) {
TO_IMPLEMENT;
}
- else if (format & TOOL_OUTPUT_FORMAT_CSV) {
+ else if (format & BASE_TOOL_OUTPUT_FORMAT_CSV) {
TO_IMPLEMENT;
}
- else if (format & TOOL_OUTPUT_FORMAT_HTML) {
+ else if (format & BASE_TOOL_OUTPUT_FORMAT_HTML) {
TO_IMPLEMENT;
}
else
@@ -447,7 +451,7 @@ tree_to_string (GdaTree *tree, ToolOutputFormat format, FILE *stream, GdaSet *op
/**
- * tool_output_result_to_string:
+ * base_tool_output_result_to_string:
* @res: a #ToolCommandResult
* @format: a #ToolOutputFormat format specification
* @stream: (allow-none): a stream which the returned string will be put to, or %NULL
@@ -458,21 +462,21 @@ tree_to_string (GdaTree *tree, ToolOutputFormat format, FILE *stream, GdaSet *op
* Returns: (transfer full): a new string
*/
gchar *
-tool_output_result_to_string (ToolCommandResult *res, ToolOutputFormat format,
- FILE *stream, GdaSet *options)
+base_tool_output_result_to_string (ToolCommandResult *res, ToolOutputFormat format,
+ FILE *stream, GdaSet *options)
{
switch (res->type) {
- case TOOL_COMMAND_RESULT_DATA_MODEL:
- return data_model_to_string (res->u.model, format, stream, options);
+ case BASE_TOOL_COMMAND_RESULT_DATA_MODEL:
+ return base_tool_output_data_model_to_string (res->u.model, format, stream, options);
- case TOOL_COMMAND_RESULT_SET: {
+ case BASE_TOOL_COMMAND_RESULT_SET: {
GSList *list;
GString *string;
xmlNodePtr node;
xmlBufferPtr buffer;
gchar *str;
- if (format & TOOL_OUTPUT_FORMAT_DEFAULT) {
+ if (format & BASE_TOOL_OUTPUT_FORMAT_DEFAULT) {
string = g_string_new ("");
for (list = res->u.set->holders; list; list = list->next) {
const GValue *value;
@@ -512,7 +516,7 @@ tool_output_result_to_string (ToolCommandResult *res, ToolOutputFormat format,
g_string_free (string, FALSE);
return str;
}
- else if (format & TOOL_OUTPUT_FORMAT_XML) {
+ else if (format & BASE_TOOL_OUTPUT_FORMAT_XML) {
buffer = xmlBufferCreate ();
node = xmlNewNode (NULL, BAD_CAST "parameters");
for (list = res->u.set->holders; list; list = list->next) {
@@ -533,7 +537,7 @@ tool_output_result_to_string (ToolCommandResult *res, ToolOutputFormat format,
xmlFreeNode (node);
return str;
}
- else if (format & TOOL_OUTPUT_FORMAT_HTML) {
+ else if (format & BASE_TOOL_OUTPUT_FORMAT_HTML) {
buffer = xmlBufferCreate ();
node = xmlNewNode (NULL, BAD_CAST "ul");
for (list = res->u.set->holders; list; list = list->next) {
@@ -554,7 +558,7 @@ tool_output_result_to_string (ToolCommandResult *res, ToolOutputFormat format,
xmlFreeNode (node);
return str;
}
- else if (format & TOOL_OUTPUT_FORMAT_CSV) {
+ else if (format & BASE_TOOL_OUTPUT_FORMAT_CSV) {
string = g_string_new ("");
for (list = res->u.set->holders; list; list = list->next) {
const GValue *value;
@@ -600,10 +604,10 @@ tool_output_result_to_string (ToolCommandResult *res, ToolOutputFormat format,
}
}
- case TOOL_COMMAND_RESULT_TREE: {
+ case BASE_TOOL_COMMAND_RESULT_TREE: {
GdaSet *options2, *merge = NULL;
- options2 = g_object_get_data ((GObject*) res->u.tree, "TOOL_OUTPUT_OPTIONS");
+ options2 = g_object_get_data ((GObject*) res->u.tree, "BASE_TOOL_OUTPUT_OPTIONS");
if (options && options2) {
merge = gda_set_copy (options2);
gda_set_merge_with_set (merge, options);
@@ -615,15 +619,15 @@ tool_output_result_to_string (ToolCommandResult *res, ToolOutputFormat format,
return tmp;
}
- case TOOL_COMMAND_RESULT_TXT: {
+ case BASE_TOOL_COMMAND_RESULT_TXT: {
xmlNodePtr node;
xmlBufferPtr buffer;
gchar *str;
- if ((format & TOOL_OUTPUT_FORMAT_DEFAULT) ||
- (format & TOOL_OUTPUT_FORMAT_CSV))
+ if ((format & BASE_TOOL_OUTPUT_FORMAT_DEFAULT) ||
+ (format & BASE_TOOL_OUTPUT_FORMAT_CSV))
return g_strdup (res->u.txt->str);
- else if (format & TOOL_OUTPUT_FORMAT_XML) {
+ else if (format & BASE_TOOL_OUTPUT_FORMAT_XML) {
buffer = xmlBufferCreate ();
node = xmlNewNode (NULL, BAD_CAST "txt");
xmlNodeSetContent (node, BAD_CAST res->u.txt->str);
@@ -633,7 +637,7 @@ tool_output_result_to_string (ToolCommandResult *res, ToolOutputFormat format,
xmlFreeNode (node);
return str;
}
- else if (format & TOOL_OUTPUT_FORMAT_HTML) {
+ else if (format & BASE_TOOL_OUTPUT_FORMAT_HTML) {
buffer = xmlBufferCreate ();
node = xmlNewNode (NULL, BAD_CAST "p");
xmlNodeSetContent (node, BAD_CAST res->u.txt->str);
@@ -649,10 +653,10 @@ tool_output_result_to_string (ToolCommandResult *res, ToolOutputFormat format,
}
}
- case TOOL_COMMAND_RESULT_EMPTY:
+ case BASE_TOOL_COMMAND_RESULT_EMPTY:
return g_strdup ("");
- case TOOL_COMMAND_RESULT_MULTIPLE: {
+ case BASE_TOOL_COMMAND_RESULT_MULTIPLE: {
GSList *list;
GString *string = NULL;
gchar *str;
@@ -661,7 +665,9 @@ tool_output_result_to_string (ToolCommandResult *res, ToolOutputFormat format,
ToolCommandResult *tres = (ToolCommandResult*) list->data;
gchar *tmp;
- tmp = tool_output_result_to_string (tres, format, stream, options);
+ tmp = base_tool_output_result_to_string (tres,
+ format & BASE_TOOL_OUTPUT_FORMAT_COLOR_TERM
? TRUE : FALSE,
+ stream, options);
if (!string)
string = g_string_new (tmp);
else {
@@ -678,8 +684,34 @@ tool_output_result_to_string (ToolCommandResult *res, ToolOutputFormat format,
str = g_strdup ("");
return str;
}
-
+
+ case BASE_TOOL_COMMAND_RESULT_HELP: {
+ if (format & BASE_TOOL_OUTPUT_FORMAT_XML) {
+ xmlBufferPtr buffer;
+ gchar *str;
+ buffer = xmlBufferCreate ();
+ xmlNodeDump (buffer, NULL, res->u.xml_node, 0, 1);
+ str = g_strdup ((gchar *) xmlBufferContent (buffer));
+ xmlBufferFree (buffer);
+ return str;
+ }
+ else if (format & BASE_TOOL_OUTPUT_FORMAT_HTML) {
+ TO_IMPLEMENT;
+ return NULL;
+ }
+ else {
+ gint width = -1;
+ gboolean term_color;
+ if (format & BASE_TOOL_OUTPUT_FORMAT_DEFAULT)
+ base_tool_input_get_size (&width, NULL);
+ term_color = format & BASE_TOOL_OUTPUT_FORMAT_COLOR_TERM ? TRUE : FALSE;
+ return base_tool_help_to_string (res, width, term_color);
+ }
+ break;
+ }
+
default:
+ g_assert_not_reached ();
return NULL;
}
}
@@ -709,14 +741,14 @@ check_shell_argument (const gchar *arg)
}
/**
- * tool_output_output_string:
+ * base_tool_output_output_string:
* @stream: (allow-none): an outout stream, or %NULL
* @str: a string
*
* "Outputs" @str to @stream, or to stdout if @stream is %NULL
*/
void
-tool_output_output_string (FILE *stream, const gchar *str)
+base_tool_output_output_string (FILE *stream, const gchar *str)
{
FILE *to_stream;
gboolean append_nl = FALSE;
@@ -728,7 +760,7 @@ tool_output_output_string (FILE *stream, const gchar *str)
if (force_no_pager < 0) {
/* still unset... */
- if (getenv (TOOL_NO_PAGER))
+ if (getenv (BASE_TOOL_NO_PAGER))
force_no_pager = 1;
else
force_no_pager = 0;
@@ -783,7 +815,7 @@ tool_output_output_string (FILE *stream, const gchar *str)
* color output handling
*/
gchar *
-tool_output_color_string (ToolColor color, ToolOutputFormat format, const char *fmt, ...)
+base_tool_output_color_string (ToolOutputColor color, gboolean color_term, const char *fmt, ...)
{
va_list argv;
gchar *tmp, *res;
@@ -791,46 +823,48 @@ tool_output_color_string (ToolColor color, ToolOutputFormat format, const char *
va_start (argv, fmt);
tmp = g_strdup_vprintf (fmt, argv);
va_end (argv);
- res = g_strdup_printf ("%s%s%s", tool_output_color_s (color, format), tmp, tool_output_color_s
(TOOL_COLOR_RESET, format));
+ res = g_strdup_printf ("%s%s%s", base_tool_output_color_s (color, color_term),
+ tmp,
+ base_tool_output_color_s (BASE_TOOL_COLOR_RESET, color_term));
g_free (tmp);
return res;
}
void
-tool_output_color_append_string (ToolColor color, ToolOutputFormat format, GString *string, const char *fmt,
...)
+base_tool_output_color_append_string (ToolOutputColor color, gboolean color_term, GString *string, const
char *fmt, ...)
{
va_list argv;
- g_string_append (string, tool_output_color_s (color, format));
+ g_string_append (string, base_tool_output_color_s (color, color_term));
va_start (argv, fmt);
g_string_append_vprintf (string, fmt, argv);
va_end (argv);
- g_string_append (string, tool_output_color_s (TOOL_COLOR_RESET, format));
+ g_string_append (string, base_tool_output_color_s (BASE_TOOL_COLOR_RESET, color_term));
}
void
-tool_output_color_print (ToolColor color, ToolOutputFormat format, const char *fmt, ...)
+base_tool_output_color_print (ToolOutputColor color, gboolean color_term, const char *fmt, ...)
{
va_list argv;
- g_print ("%s", tool_output_color_s (color, format));
+ g_print ("%s", base_tool_output_color_s (color, color_term));
va_start (argv, fmt);
g_vprintf (fmt, argv);
va_end (argv);
- g_print ("%s", tool_output_color_s (TOOL_COLOR_RESET, format));
+ g_print ("%s", base_tool_output_color_s (BASE_TOOL_COLOR_RESET, color_term));
}
const gchar *
-tool_output_color_s (ToolColor color, ToolOutputFormat format)
+base_tool_output_color_s (ToolOutputColor color, gboolean color_term)
{
#ifndef G_OS_WIN32
- if (format & TOOL_OUTPUT_FORMAT_COLOR_TERM) {
+ if (color_term) {
switch (color) {
- case TOOL_COLOR_NORMAL:
+ case BASE_TOOL_COLOR_NORMAL:
return "";
- case TOOL_COLOR_RESET:
+ case BASE_TOOL_COLOR_RESET:
return "\033[m";
- case TOOL_COLOR_BOLD:
+ case BASE_TOOL_COLOR_BOLD:
return "\033[1m";
- case TOOL_COLOR_RED:
+ case BASE_TOOL_COLOR_RED:
return "\033[31m";
default:
g_assert_not_reached();
diff --git a/tools/cmdtool/tool-output.h b/tools/base/base-tool-output.h
similarity index 50%
rename from tools/cmdtool/tool-output.h
rename to tools/base/base-tool-output.h
index cc12486..8a97ebd 100644
--- a/tools/cmdtool/tool-output.h
+++ b/tools/base/base-tool-output.h
@@ -3,7 +3,7 @@
* Copyright (C) 2001 Reinhard Müller <reinhard src gnome org>
* Copyright (C) 2002 - 2003 Gonzalo Paniagua Javier <gonzalo src gnome org>
* Copyright (C) 2007 Baris Cicek <bcicek src gnome org>
- * Copyright (C) 2007 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2007 - 2014 Vivien Malerba <malerba gnome-db org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -20,32 +20,33 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#ifndef __TOOL_OUTPUT__
-#define __TOOL_OUTPUT__
+#ifndef __BASE_TOOL_OUTPUT__
+#define __BASE_TOOL_OUTPUT__
#include <stdio.h>
#include <glib.h>
-#include "tool-decl.h"
-#include "tool-command.h"
+#include "base-tool-decl.h"
+#include "base-tool-command.h"
-gchar *tool_output_result_to_string (ToolCommandResult *res, ToolOutputFormat format,
- FILE *stream, GdaSet *options);
-void tool_output_output_string (FILE *output_stream, const gchar *str);
+gchar *base_tool_output_result_to_string (ToolCommandResult *res, ToolOutputFormat format,
+ FILE *stream, GdaSet *options);
+gchar *base_tool_output_data_model_to_string (GdaDataModel *model, ToolOutputFormat format, FILE *stream,
GdaSet *options);
+void base_tool_output_output_string (FILE *output_stream, const gchar *str);
/*
* color output handling
*/
typedef enum {
- TOOL_COLOR_NORMAL,
- TOOL_COLOR_RESET,
- TOOL_COLOR_BOLD,
- TOOL_COLOR_RED
-} ToolColor;
+ BASE_TOOL_COLOR_NORMAL,
+ BASE_TOOL_COLOR_RESET,
+ BASE_TOOL_COLOR_BOLD,
+ BASE_TOOL_COLOR_RED
+} ToolOutputColor;
-void tool_output_color_print (ToolColor color, ToolOutputFormat format, const char *fmt, ...);
-gchar *tool_output_color_string (ToolColor color, ToolOutputFormat format, const char *fmt, ...);
-void tool_output_color_append_string (ToolColor color, ToolOutputFormat format, GString *string,
const char *fmt, ...);
-const gchar *tool_output_color_s (ToolColor color, ToolOutputFormat format);
+void base_tool_output_color_print (ToolOutputColor color, gboolean color_term, const char *fmt, ...);
+gchar *base_tool_output_color_string (ToolOutputColor color, gboolean color_term, const char *fmt,
...);
+void base_tool_output_color_append_string (ToolOutputColor color, gboolean color_term, GString
*string, const char *fmt, ...);
+const gchar *base_tool_output_color_s (ToolOutputColor color, gboolean color_term);
#endif
diff --git a/tools/cmdtool/tool.h b/tools/base/base-tool.h
similarity index 82%
rename from tools/cmdtool/tool.h
rename to tools/base/base-tool.h
index eeb1de4..bd0b357 100644
--- a/tools/cmdtool/tool.h
+++ b/tools/base/base-tool.h
@@ -20,14 +20,14 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#ifndef __TOOL__
-#define __TOOL__
+#ifndef __BASE_TOOL__
+#define __BASE_TOOL__
-#include <tool-command.h>
-#include <tool-errors.h>
-#include <tool-input.h>
-#include <tool-output.h>
-#include <tool-defines.h>
-#include <tool-help.h>
+#include <base-tool-command.h>
+#include <base-tool-errors.h>
+#include <base-tool-input.h>
+#include <base-tool-output.h>
+#include <base-tool-defines.h>
+#include <base-tool-help.h>
#endif
diff --git a/tools/browser/.gitignore b/tools/browser/.gitignore
index 5cb2942..20d65fc 100644
--- a/tools/browser/.gitignore
+++ b/tools/browser/.gitignore
@@ -1,6 +1,2 @@
-gda-browser-6.0
-gda-browser-6.*.desktop
-canvas-example
-marshal.c
-marshal.h
-favorites-test
+marshal.[ch]
+
diff --git a/tools/browser/Makefile.am b/tools/browser/Makefile.am
index 3238ca7..fe03c36 100644
--- a/tools/browser/Makefile.am
+++ b/tools/browser/Makefile.am
@@ -1,21 +1,8 @@
-bin_PROGRAMS=gda-browser-6.0
-noinst_LTLIBRARIES = libbrowser.la
-
-SUBDIRS = data common schema-browser query-exec data-manager dummy-perspective
+noinst_LTLIBRARIES = libbrowsercore.la
+SUBDIRS = dummy-perspective schema-browser query-exec data-manager
if LDAP
-ldap_flags=-DHAVE_LDAP
-SUBDIRS+=ldap-browser
-LDAP_LDADD=$(top_builddir)/tools/browser/ldap-browser/libperspective.la
-endif
-
-if HAVE_GOOCANVAS
-SUBDIRS+=canvas
-noinst_PROGRAMS=canvas-example
-endif
-SUBDIRS+= . doc
-if HAVE_GDU
-SUBDIRS+=help
+SUBDIRS += ldap-browser
endif
AM_CPPFLAGS = \
@@ -24,6 +11,11 @@ AM_CPPFLAGS = \
-I$(top_srcdir)/libgda/sqlite \
-I$(top_builddir)/libgda/sqlite \
-I$(top_builddir) \
+ -I$(top_builddir)/libgda \
+ -I$(srcdir)/.. \
+ -I$(top_srcdir)/tools \
+ -I$(top_srcdir)/tools/base \
+ -I$(top_srcdir)/tools/common \
$(COREDEPS_CFLAGS) \
$(COREDEPS_WFLAGS) \
$(GTK_CFLAGS) \
@@ -36,168 +28,58 @@ AM_CPPFLAGS = \
$(ldap_flags)
marshal.h: marshal.list $(GLIB_GENMARSHAL)
- $(GLIB_GENMARSHAL) $< --header --prefix=_marshal > $@
+ $(GLIB_GENMARSHAL) $< --header --prefix=_common_marshal > $@
marshal.c: marshal.list $(GLIB_GENMARSHAL) marshal.h
- $(GLIB_GENMARSHAL) $< --body --prefix=_marshal > $@
+ $(GLIB_GENMARSHAL) $< --body --prefix=_common_marshal > $@
-libbrowser_la_SOURCES=\
- ../config-info.h \
- ../config-info.c \
- ../tool-utils.h \
- ../tool-utils.c \
- gdaui-bar.c \
- gdaui-bar.h \
+libbrowsercore_la_SOURCES=\
marshal.c \
marshal.h \
decl.h \
dnd.h \
dnd.c \
- auth-dialog.c \
+ ui-support.h \
+ ui-support.c \
auth-dialog.h \
- login-dialog.c \
+ auth-dialog.c \
login-dialog.h \
- support.c \
- support.h \
- browser-core.c \
- browser-core.h \
- browser-page.c \
- browser-page.h \
- browser-perspective.c \
+ login-dialog.c \
browser-perspective.h \
- browser-spinner.c \
- browser-spinner.h \
- browser-connection.c \
- browser-connection.h \
- browser-connection-priv.h \
- browser-variable.c \
- browser-variable.h \
- browser-virtual-connection.c \
- browser-virtual-connection.h \
- browser-window.c \
+ browser-perspective.c \
+ browser-page.h \
+ browser-page.c \
browser-window.h \
- browser-connections-list.c \
+ browser-window.c \
browser-connections-list.h \
- connection-binding-properties.c \
+ browser-connections-list.c \
connection-binding-properties.h \
+ connection-binding-properties.c \
+ gdaui-data-import.h \
+ gdaui-data-import.c \
+ gdaui-entry-import.h \
+ gdaui-entry-import.c \
+ objects-cloud.h \
+ objects-cloud.c \
+ fk-declare.h \
+ fk-declare.c \
+ gdaui-bar.h \
+ gdaui-bar.c \
mgr-favorites.h \
mgr-favorites.c \
- browser-stock-icons.c \
- browser-stock-icons.h \
- text-search.c \
- text-search.h
-
-gda_browser_6_0_SOURCES=\
- main.c
+ widget-overlay.h \
+ widget-overlay.c \
+ ui-formgrid.h \
+ ui-formgrid.c \
+ text-search.h \
+ text-search.c
$(OBJECTS): marshal.c marshal.h
-if PLATFORM_WIN32
-EXTRALDFLAGS=-mwindows
-gda_browser_6_0_SOURCES += browser-res.rc
-else
-EXTRALDFLAGS=
-endif
-
-if HAVE_GOOCANVAS
-CANVAS_LDADD=$(top_builddir)/tools/browser/canvas/libcanvas.la -lm
-endif
-
-.rc.o:
- $(WINDRES) $^ -o $@
-
-browser-res.o: browser-res.rc
- $(WINDRES) $^ -o $@
-
-gda_browser_6_0_LDFLAGS = $(EXTRALDFLAGS)
-gda_browser_6_0_LDADD=\
- schema-browser/libperspective.la \
- query-exec/libperspective.la \
- data-manager/libperspective.la \
- $(LDAP_LDADD) \
- libbrowser.la \
- $(top_builddir)/libgda-ui/internal/libgda-ui-internal.la \
- $(CANVAS_LDADD) \
- common/libcommon.la \
- $(top_builddir)/libgda/libgda-6.0.la \
- $(top_builddir)/libgda-ui/libgda-ui-6.0.la \
- $(COREDEPS_LIBS) $(GTK_LIBS) $(GTKSOURCEVIEW_LIBS) $(MAC_INTEGRATION_LIBS)
-
-
@INTLTOOL_DESKTOP_RULE@
desktopdir=$(datadir)/applications
Desktop_in_files = gda-browser-6.0.desktop.in
desktop_DATA = $(Desktop_in_files:.desktop.in=.desktop)
-# canvas example
-canvas_example_DEPENDENCIES = \
- libbrowser.la \
- canvas/libcanvas.la \
- common/libcommon.la
-
-canvas_example_SOURCES = \
- ../tool-utils.h \
- ../tool-utils.c \
- canvas-example.c \
- dnd.c \
- dnd.h
-
-canvas_example_LDFLAGS = $(EXTRALDFLAGS)
-canvas_example_CFLAGS = -DCANVAS_EXAMPLE
-canvas_example_LDADD=\
- $(CANVAS_LDADD) \
- libbrowser.la \
- $(top_builddir)/libgda-ui/internal/libgda-ui-internal.la \
- common/libcommon.la \
- $(top_builddir)/libgda/libgda-6.0.la \
- $(top_builddir)/libgda-ui/libgda-ui-6.0.la \
- $(COREDEPS_LIBS) $(GTK_LIBS)
-
-# icons
-iconsdir=$(datadir)/libgda-6.0/pixmaps
-icons_DATA= \
- gda-browser.png \
- gda-browser-auth.png \
- gda-browser-auth-big.png \
- gda-browser-connected.png \
- gda-browser-connected-big.png \
- gda-browser-non-connected.png \
- gda-browser-non-connected-big.png \
- gda-browser-bookmark.png \
- gda-browser-schema.png \
- gda-browser-table.png \
- gda-browser-column.png \
- gda-browser-column-fknn.png \
- gda-browser-column-fk.png \
- gda-browser-column-nn.png \
- gda-browser-column-pk.png \
- gda-browser-reference.png \
- gda-browser-diagram.png \
- gda-browser-query.png \
- gda-browser-action.png \
- gda-browser-menu-ind.png \
- gda-browser-ldap-entry.png \
- gda-browser-ldap-group.png \
- gda-browser-ldap-organization.png \
- gda-browser-ldap-person.png \
- gda-browser-ldap-class-a.png \
- gda-browser-ldap-class-s.png \
- gda-browser-ldap-class-x.png \
- gda-browser-ldap-class-u.png
-
-# app icon
-appiconsdir=$(datadir)/pixmaps
-appicons_DATA= \
- gda-browser-6.0.png
-
EXTRA_DIST = \
- marshal.list \
- browser-res.rc \
- gda-browser.ico \
- $(Desktop_in_files) $(icons_DATA) $(appicons_DATA)
-
-DISTCLEANFILES = $(desktop_DATA)
-
-CLEANFILES = \
- marshal.h \
- marshal.c
+ marshal.list
diff --git a/tools/browser/auth-dialog.c b/tools/browser/auth-dialog.c
index 9ee21d7..1093d5b 100644
--- a/tools/browser/auth-dialog.c
+++ b/tools/browser/auth-dialog.c
@@ -20,10 +20,8 @@
#include <glib/gi18n-lib.h>
#include <string.h>
-#include <libgda/binreloc/gda-binreloc.h>
#include "auth-dialog.h"
-#include "browser-spinner.h"
-#include "support.h"
+#include "ui-support.h"
/*
* Main static functions
@@ -36,12 +34,12 @@ static void auth_dialog_dispose (GObject *object);
static GObjectClass *parent_class = NULL;
typedef struct {
- AuthDialogConnection ext;
- GdaDsnInfo cncinfo;
- GtkWidget *auth_widget;
- GString *auth_string;
-
- guint jobid;
+ gchar *cnc_string;
+ TConnection *tcnc; /* ref held */
+ GError *cnc_open_error;
+ GdaDsnInfo cncinfo;
+ GtkWidget *auth_widget;
+ GString *auth_string;
} AuthData;
static void
@@ -52,14 +50,14 @@ auth_data_free (AuthData *ad)
g_free (ad->cncinfo.provider);
g_free (ad->cncinfo.cnc_string);
g_free (ad->cncinfo.auth_string);
- g_free (ad->ext.cnc_string);
+ g_free (ad->cnc_string);
if (ad->auth_string)
g_string_free (ad->auth_string, TRUE);
- if (ad->ext.cnc_open_error)
- g_error_free (ad->ext.cnc_open_error);
- if (ad->ext.cnc)
- g_object_unref (ad->ext.cnc);
+ if (ad->cnc_open_error)
+ g_error_free (ad->cnc_open_error);
+ if (ad->tcnc)
+ g_object_unref (ad->tcnc);
g_free (ad);
}
@@ -68,7 +66,6 @@ struct _AuthDialogPrivate
GSList *auth_list; /* list of AuthData pointers */
GtkWidget *spinner;
guint source_id; /* timer to check if connections have been opened */
- GMainLoop *loop; /* waiting loop */
};
/* module error */
@@ -121,16 +118,6 @@ auth_dialog_class_init (AuthDialogClass *class)
object_class->dispose = auth_dialog_dispose;
}
-/*
-static void
-auth_contents_changed_cb (GdauiAuth *auth, gboolean is_valid, AuthDialog *dialog)
-{
- gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT, is_valid);
- if (is_valid)
- gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
-}
-*/
-
static void
update_ad_auth (AuthData *ad)
{
@@ -195,33 +182,30 @@ static void
auth_dialog_init (AuthDialog *dialog)
{
GtkWidget *label, *hbox, *wid;
- char *markup, *str;
+ char *markup;
GtkWidget *dcontents;
dialog->priv = g_new0 (AuthDialogPrivate, 1);
gtk_dialog_add_buttons (GTK_DIALOG (dialog),
- GTK_STOCK_CONNECT,
- GTK_RESPONSE_ACCEPT,
- GTK_STOCK_CANCEL,
- GTK_RESPONSE_REJECT, NULL);
+ _("C_onnect"), GTK_RESPONSE_ACCEPT,
+ _("_Cancel"), GTK_RESPONSE_REJECT, NULL);
dcontents = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
gtk_box_set_spacing (GTK_BOX (dcontents), 5);
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT, TRUE);
- str = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, "pixmaps", "gda-browser-auth.png", NULL);
- gtk_window_set_icon_from_file (GTK_WINDOW (dialog), str, NULL);
- g_free (str);
+ GdkPixbuf *pix;
+ pix = gdk_pixbuf_new_from_resource ("/images/gda-browser-auth.png", NULL);
+ gtk_window_set_icon (GTK_WINDOW (dialog), pix);
+ g_object_unref (pix);
/* label and spinner */
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_container_set_border_width (GTK_CONTAINER (hbox), 10);
gtk_box_pack_start (GTK_BOX (dcontents), hbox, FALSE, FALSE, 0);
- str = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, "pixmaps", "gda-browser-auth-big.png",
NULL);
- wid = gtk_image_new_from_file (str);
- g_free (str);
+ wid = gtk_image_new_from_resource ("/images/gda-browser-auth-big.png");
gtk_box_pack_start (GTK_BOX (hbox), wid, FALSE, FALSE, 0);
label = gtk_label_new ("");
@@ -232,7 +216,7 @@ auth_dialog_init (AuthDialog *dialog)
gtk_misc_set_alignment (GTK_MISC (label), 0., -1);
gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 12);
- dialog->priv->spinner = browser_spinner_new ();
+ dialog->priv->spinner = gtk_spinner_new ();
gtk_box_pack_start (GTK_BOX (hbox), dialog->priv->spinner, FALSE, FALSE, 0);
gtk_widget_show_all (hbox);
@@ -260,8 +244,6 @@ auth_dialog_dispose (GObject *object)
}
if (dialog->priv->source_id)
g_source_remove (dialog->priv->source_id);
- if (dialog->priv->loop)
- g_main_loop_quit (dialog->priv->loop);
g_free (dialog->priv);
dialog->priv = NULL;
}
@@ -287,58 +269,26 @@ auth_dialog_new (GtkWindow *parent)
}
static void
-cnc_opened_cb (GdaConnection *cnc, guint job_id, gboolean result, GError *error, AuthDialog *dialog)
-{
- if (result) {
-#ifdef HAVE_LDAP
- if (cnc && GDA_IS_LDAP_CONNECTION (cnc)) {
- /* force classes init */
- gda_ldap_get_class_info (GDA_LDAP_CONNECTION (cnc), "top");
- }
-#endif
- }
-
- GSList *list;
- gboolean finished = TRUE;
- for (list = dialog->priv->auth_list; list; list = list->next) {
- AuthData *ad = (AuthData*) list->data;
-
- g_print ("%s (job => %u, result => %d)\n", __FUNCTION__, job_id, result);
- if (ad->jobid == job_id) {
- if (!result) {
- g_object_unref (ad->ext.cnc);
- ad->ext.cnc = NULL;
- if (error)
- ad->ext.cnc_open_error = g_error_copy (error);
- }
- ad->jobid = 0;
- }
- else if (ad->jobid)
- finished = FALSE;
- }
-}
-
-static void
real_connection_open (AuthDialog *dialog, AuthData *ad)
{
-#ifndef DUMMY
- GdaConnection *cnc;
- GdaDsnInfo *info = &(ad->cncinfo);
- if (info->name)
- ad->ext.cnc = gda_connection_new_from_dsn (info->name, ad->auth_string ? ad->auth_string->str
: NULL,
- GDA_CONNECTION_OPTIONS_AUTO_META_DATA,
- &(ad->ext.cnc_open_error));
- else
- ad->ext.cnc = gda_connection_new_from_string (info->provider, info->cnc_string,
- ad->auth_string ? ad->auth_string->str : NULL,
- GDA_CONNECTION_OPTIONS_AUTO_META_DATA,
- &(ad->ext.cnc_open_error));
- ad->jobid = gda_connection_open_async (ad->ext.cnc, (GdaConnectionOpenFunc*) cnc_opened_cb, dialog,
- &(ad->ext.cnc_open_error));
-#else /* DUMMY defined */
+#ifdef DUMMY
sleep (5);
- g_set_error (&(ad->ext.cnc_open_error), GDA_TOOLS_ERROR, TOOLS_INTERNAL_COMMAND_ERROR, "%s", "Dummy
error!");
+ g_set_error (&(ad->cnc_open_error), T_ERROR, TOOLS_INTERNAL_COMMAND_ERROR, "%s", "Dummy error!");
+ return;
#endif
+
+ TConnection *tcnc;
+ GdaDsnInfo *cncinfo = &(ad->cncinfo);
+ if (cncinfo->name)
+ ad->tcnc = t_connection_open (NULL, cncinfo->name, ad->auth_string ? ad->auth_string->str :
NULL, FALSE, &(ad->cnc_open_error));
+ else {
+ gchar *tmp;
+ tmp = g_strdup_printf ("%s://%s", cncinfo->provider, cncinfo->cnc_string);
+ ad->tcnc = t_connection_open (NULL, tmp, ad->auth_string ? ad->auth_string->str : NULL,
FALSE, &(ad->cnc_open_error));
+ g_free (tmp);
+ }
+ if (ad->tcnc)
+ ad->tcnc = g_object_ref (ad->tcnc);
}
static void
@@ -349,7 +299,7 @@ update_dialog_focus (AuthDialog *dialog)
for (list = dialog->priv->auth_list; list; list = list->next) {
AuthData *ad;
ad = (AuthData*) list->data;
- if (ad->auth_widget && !ad->ext.cnc &&
+ if (ad->auth_widget && !ad->tcnc &&
! gdaui_basic_form_is_valid (GDAUI_BASIC_FORM (ad->auth_widget))) {
allvalid = FALSE;
gtk_widget_grab_focus (ad->auth_widget);
@@ -400,7 +350,7 @@ auth_dialog_add_cnc_string (AuthDialog *dialog, const gchar *cnc_string, GError
GdaDsnInfo *info;
gchar *user, *pass, *real_cnc, *real_provider, *real_auth_string = NULL;
- /* if cnc string is a regular file, then use it with SQLite */
+ /* if cnc string is a regular file, then use it with SQLite or MSAccess */
if (g_file_test (cnc_string, G_FILE_TEST_IS_REGULAR)) {
gchar *path, *file, *e1, *e2;
const gchar *pname = "SQLite";
@@ -438,7 +388,7 @@ auth_dialog_add_cnc_string (AuthDialog *dialog, const gchar *cnc_string, GError
AuthData *ad;
ad = g_new0 (AuthData, 1);
- ad->ext.cnc_string = g_strdup (cnc_string);
+ ad->cnc_string = g_strdup (cnc_string);
ad->auth_string = NULL;
info = gda_config_get_dsn_info (real_cnc);
if (info && !real_provider) {
@@ -518,7 +468,7 @@ auth_dialog_add_cnc_string (AuthDialog *dialog, const gchar *cnc_string, GError
dcontents = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
label = gtk_label_new ("");
- tmp = g_strdup (ad->ext.cnc_string);
+ tmp = g_strdup (ad->cnc_string);
for (ptr = tmp; *ptr; ptr++) {
if (*ptr == ':') {
/* remove everything up to the '@' */
@@ -587,7 +537,6 @@ auth_dialog_run (AuthDialog *dialog)
gboolean allopened = FALSE;
g_return_val_if_fail (AUTH_IS_DIALOG (dialog), FALSE);
-
gtk_widget_show (GTK_WIDGET (dialog));
while (1) {
@@ -611,7 +560,7 @@ auth_dialog_run (AuthDialog *dialog)
result = GTK_RESPONSE_ACCEPT;
gtk_widget_show (dialog->priv->spinner);
- browser_spinner_start (BROWSER_SPINNER (dialog->priv->spinner));
+ gtk_spinner_start (GTK_SPINNER (dialog->priv->spinner));
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT, FALSE);
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_REJECT, FALSE);
@@ -620,7 +569,7 @@ auth_dialog_run (AuthDialog *dialog)
for (list = dialog->priv->auth_list; list; list = list->next) {
AuthData *ad;
ad = (AuthData *) list->data;
- if (ad->auth_widget && !ad->jobid) {
+ if (ad->auth_widget) {
GSList *plist;
GdaSet *set;
set = gdaui_basic_form_get_data_set (GDAUI_BASIC_FORM
(ad->auth_widget));
@@ -659,24 +608,17 @@ auth_dialog_run (AuthDialog *dialog)
}
}
- if (dialog->priv->source_id != 0) {
- dialog->priv->loop = g_main_loop_new (NULL, FALSE);
- g_main_loop_run (dialog->priv->loop);
- g_main_loop_unref (dialog->priv->loop);
- dialog->priv->loop = NULL;
- }
-
allopened = TRUE;
for (list = dialog->priv->auth_list; list; list = list->next) {
AuthData *ad;
ad = (AuthData *) list->data;
- if (ad->auth_widget && !ad->ext.cnc) {
- g_print ("ERROR: %s\n", ad->ext.cnc_open_error &&
ad->ext.cnc_open_error->message ?
- ad->ext.cnc_open_error->message : _("No detail"));
- browser_show_error (GTK_WINDOW (dialog), _("Could not open
connection:\n%s"),
- ad->ext.cnc_open_error &&
ad->ext.cnc_open_error->message ?
- ad->ext.cnc_open_error->message : _("No detail"));
+ if (ad->auth_widget && !ad->tcnc) {
+ g_print ("ERROR: %s\n", ad->cnc_open_error &&
ad->cnc_open_error->message ?
+ ad->cnc_open_error->message : _("No detail"));
+ ui_show_error (GTK_WINDOW (dialog), _("Could not open
connection:\n%s"),
+ ad->cnc_open_error && ad->cnc_open_error->message ?
+ ad->cnc_open_error->message : _("No detail"));
allopened = FALSE;
gtk_widget_set_sensitive (ad->auth_widget, TRUE);
}
@@ -689,7 +631,7 @@ auth_dialog_run (AuthDialog *dialog)
goto out;
}
- browser_spinner_stop (BROWSER_SPINNER (dialog->priv->spinner));
+ gtk_spinner_stop (GTK_SPINNER (dialog->priv->spinner));
gtk_widget_hide (dialog->priv->spinner);
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT, TRUE);
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_REJECT, TRUE);
@@ -698,16 +640,3 @@ auth_dialog_run (AuthDialog *dialog)
out:
return allopened;
}
-
-
-/**
- * auth_dialog_get_connections
- *
- * Returns: a list of pointers to AuthDialogConnection structures.
- */
-const GSList *
-auth_dialog_get_connections (AuthDialog *dialog)
-{
- g_return_val_if_fail (AUTH_IS_DIALOG (dialog), NULL);
- return dialog->priv->auth_list;
-}
diff --git a/tools/browser/auth-dialog.h b/tools/browser/auth-dialog.h
index 79a2af4..38a388f 100644
--- a/tools/browser/auth-dialog.h
+++ b/tools/browser/auth-dialog.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2009 - 2014 Vivien Malerba <malerba gnome-db org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -22,6 +22,7 @@
#include <libgda-ui/libgda-ui.h>
#include <gtk/gtk.h>
+#include <common/t-connection.h>
G_BEGIN_DECLS
@@ -56,20 +57,12 @@ struct _AuthDialogClass
GtkDialogClass parent_class;
};
-typedef struct {
- gchar *cnc_string;
- GdaConnection *cnc;
- GError *cnc_open_error;
-} AuthDialogConnection;
-
GType auth_dialog_get_type (void) G_GNUC_CONST;
AuthDialog *auth_dialog_new (GtkWindow *parent);
gboolean auth_dialog_add_cnc_string (AuthDialog *dialog, const gchar *cnc_string, GError
**error);
gboolean auth_dialog_run (AuthDialog *dialog);
-const GSList *auth_dialog_get_connections (AuthDialog *dialog);
-
G_END_DECLS
#endif
diff --git a/tools/browser/browser-connections-list.c b/tools/browser/browser-connections-list.c
index 33b9292..39f1ed0 100644
--- a/tools/browser/browser-connections-list.c
+++ b/tools/browser/browser-connections-list.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2009 - 2014 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2010 David King <davidk openismus com>
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
*
@@ -20,13 +20,11 @@
#include <string.h>
#include <glib/gi18n-lib.h>
-#include <libgda/binreloc/gda-binreloc.h>
#include "browser-connections-list.h"
-#include "browser-core.h"
+#include <common/t-app.h>
#include "browser-window.h"
-#include "browser-connection.h"
#include <libgda-ui/gdaui-login.h>
-#include "support.h"
+#include "ui-support.h"
#include "login-dialog.h"
/*
@@ -36,8 +34,8 @@ static void browser_connections_list_class_init (BrowserConnectionsListClass *kl
static void browser_connections_list_init (BrowserConnectionsList *stmt);
static void browser_connections_list_dispose (GObject *object);
-static void connection_added_cb (BrowserCore *bcore, BrowserConnection *bcnc, BrowserConnectionsList *clist);
-static void connection_removed_cb (BrowserCore *bcore, BrowserConnection *bcnc, BrowserConnectionsList
*clist);
+static void connection_added_cb (TApp *app, TConnection *tcnc, BrowserConnectionsList *clist);
+static void connection_removed_cb (TApp *app, TConnection *tcnc, BrowserConnectionsList *clist);
struct _BrowserConnectionsListPrivate
{
@@ -114,9 +112,9 @@ browser_connections_list_dispose (GObject *object)
if (clist->priv) {
if (clist->priv->cnc_added_sigid > 0)
- g_signal_handler_disconnect (browser_core_get (), clist->priv->cnc_added_sigid);
+ g_signal_handler_disconnect (t_app_get (), clist->priv->cnc_added_sigid);
if (clist->priv->cnc_removed_sigid > 0)
- g_signal_handler_disconnect (browser_core_get (), clist->priv->cnc_removed_sigid);
+ g_signal_handler_disconnect (t_app_get (), clist->priv->cnc_removed_sigid);
g_free (clist->priv);
clist->priv = NULL;
@@ -128,7 +126,7 @@ browser_connections_list_dispose (GObject *object)
enum
{
- COLUMN_BCNC,
+ COLUMN_TCNC,
NUM_COLUMNS
};
@@ -145,13 +143,13 @@ static void cell_name_data_func (G_GNUC_UNUSED GtkTreeViewColumn *tree_column,
GtkTreeIter *iter,
G_GNUC_UNUSED gpointer data)
{
- BrowserConnection *bcnc;
+ TConnection *tcnc;
gchar *str, *cncstr = NULL;
gchar *markup;
const GdaDsnInfo *cncinfo;
- gtk_tree_model_get (tree_model, iter, COLUMN_BCNC, &bcnc, -1);
- cncinfo = browser_connection_get_information (bcnc);
+ gtk_tree_model_get (tree_model, iter, COLUMN_TCNC, &tcnc, -1);
+ cncinfo = t_connection_get_information (tcnc);
if (cncinfo) {
if (cncinfo->name)
cncstr = g_strdup_printf (_("DSN: %s"), cncinfo->name);
@@ -159,7 +157,7 @@ static void cell_name_data_func (G_GNUC_UNUSED GtkTreeViewColumn *tree_column,
cncstr = g_strdup_printf (_("Provider: %s"), cncinfo->provider);
}
- markup = g_markup_escape_text (browser_connection_get_name (bcnc), -1);
+ markup = g_markup_escape_text (t_connection_get_name (tcnc), -1);
if (cncstr)
str = g_strdup_printf ("%s\n<small>%s</small>",
markup, cncstr);
@@ -170,7 +168,7 @@ static void cell_name_data_func (G_GNUC_UNUSED GtkTreeViewColumn *tree_column,
g_object_set ((GObject*) cell, "markup", str, NULL);
g_free (str);
- g_object_unref (bcnc);
+ g_object_unref (tcnc);
}
static void
@@ -178,13 +176,13 @@ selection_changed_cb (GtkTreeSelection *select, BrowserConnectionsList *clist)
{
GtkTreeModel *model;
GtkTreeIter iter;
- BrowserConnection *bcnc = NULL;
+ TConnection *tcnc = NULL;
const GdaDsnInfo *cncinfo = NULL;
if (gtk_tree_selection_get_selected (select, &model, &iter)) {
- gtk_tree_model_get (model, &iter, COLUMN_BCNC, &bcnc, -1);
- cncinfo = browser_connection_get_information (bcnc);
- g_object_unref (bcnc);
+ gtk_tree_model_get (model, &iter, COLUMN_TCNC, &tcnc, -1);
+ cncinfo = t_connection_get_information (tcnc);
+ g_object_unref (tcnc);
gtk_widget_set_sensitive (_clist->priv->close_cnc_button, TRUE);
}
@@ -216,9 +214,9 @@ selection_changed_cb (GtkTreeSelection *select, BrowserConnectionsList *clist)
"to this connection (favorites, descriptions, ...)"), NULL);
gda_set_add_holder (dset, holder);
g_object_unref (holder);
- if (bcnc) {
+ if (tcnc) {
const gchar *dict_file_name;
- dict_file_name = browser_connection_get_dictionary_file (bcnc);
+ dict_file_name = t_connection_get_dictionary_file (tcnc);
if (dict_file_name)
gda_set_set_holder_value (dset, NULL, "GDA_BROWSER_DICT_FILE",
@@ -279,10 +277,10 @@ connection_close_cb (G_GNUC_UNUSED GtkButton *button, BrowserConnectionsList *cl
select = gtk_tree_view_get_selection (clist->priv->treeview);
if (gtk_tree_selection_get_selected (select, &model, &iter)) {
- BrowserConnection *bcnc;
- gtk_tree_model_get (model, &iter, COLUMN_BCNC, &bcnc, -1);
- g_object_unref (bcnc);
- browser_connection_close (NULL, bcnc);
+ TConnection *tcnc;
+ gtk_tree_model_get (model, &iter, COLUMN_TCNC, &tcnc, -1);
+ g_object_unref (tcnc);
+ t_connection_close (tcnc);
}
}
@@ -290,25 +288,16 @@ static void
connection_new_cb (G_GNUC_UNUSED GtkButton *button, G_GNUC_UNUSED BrowserConnectionsList *clist)
{
LoginDialog *dialog;
- GdaConnection *cnc;
GError *error = NULL;
+
dialog = login_dialog_new (NULL);
-
- cnc = login_dialog_run (dialog, TRUE, &error);
- if (cnc) {
- BrowserConnection *bcnc;
- BrowserWindow *nbwin;
- bcnc = browser_connection_new (cnc);
- nbwin = browser_window_new (bcnc, NULL);
-
- browser_core_take_window (nbwin);
- browser_core_take_connection (bcnc);
- }
+ login_dialog_run_open_connection (dialog, TRUE, &error);
+ gtk_widget_destroy (GTK_WIDGET (dialog));
}
/**
* browser_connections_list_show
- * @current: (allow-none): a connection to select for displaed properties, or %NULL
+ * @current: (allow-none): a connection to select for displayed properties, or %NULL
*
* Creates a new #BrowserConnectionsList widget and displays it.
* Only one is created and shown (singleton)
@@ -316,7 +305,7 @@ connection_new_cb (G_GNUC_UNUSED GtkButton *button, G_GNUC_UNUSED BrowserConnect
* Returns: the new object
*/
void
-browser_connections_list_show (BrowserConnection *current)
+browser_connections_list_show (TConnection *current)
{
if (!_clist) {
GtkWidget *clist, *sw, *grid, *treeview, *label, *wid;
@@ -330,9 +319,10 @@ browser_connections_list_show (BrowserConnection *current)
g_signal_connect (G_OBJECT (clist), "delete-event",
G_CALLBACK (delete_event), NULL);
- str = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, "pixmaps",
"gda-browser-connected.png", NULL);
- gtk_window_set_icon_from_file (GTK_WINDOW (clist), str, NULL);
- g_free (str);
+ GdkPixbuf *icon;
+ icon = gdk_pixbuf_new_from_resource ("/images/gda-browser-connected.png", NULL);
+ gtk_window_set_icon (GTK_WINDOW (clist), icon);
+ g_object_unref (icon);
/* table layout */
grid = gtk_grid_new ();
@@ -346,9 +336,7 @@ browser_connections_list_show (BrowserConnection *current)
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
gtk_grid_attach (GTK_GRID (grid), hbox, 0, 0, 3, 1);
- str = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, "pixmaps",
"gda-browser-connected-big.png", NULL);
- wid = gtk_image_new_from_file (str);
- g_free (str);
+ wid = gtk_image_new_from_resource ("/images/gda-browser-connected-big.png");
gtk_box_pack_start (GTK_BOX (hbox), wid, FALSE, FALSE, 0);
wid = gtk_label_new ("");
@@ -405,9 +393,9 @@ browser_connections_list_show (BrowserConnection *current)
/* GtkTreeModel and view */
GtkListStore *store;
store = gtk_list_store_new (NUM_COLUMNS,
- BROWSER_TYPE_CONNECTION);
+ T_TYPE_CONNECTION);
- treeview = browser_make_tree_view (GTK_TREE_MODEL (store));
+ treeview = ui_make_tree_view (GTK_TREE_MODEL (store));
_clist->priv->treeview = GTK_TREE_VIEW (treeview);
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE);
gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (treeview), TRUE);
@@ -433,16 +421,14 @@ browser_connections_list_show (BrowserConnection *current)
/* initial filling */
- GSList *connections, *list;
- connections = browser_core_get_connections ();
- for (list = connections; list; list = list->next)
- connection_added_cb (browser_core_get(), BROWSER_CONNECTION (list->data),
+ GSList *list;
+ for (list = (GSList*) t_app_get_all_connections (); list; list = list->next)
+ connection_added_cb (t_app_get(), T_CONNECTION (list->data),
(BrowserConnectionsList*) clist);
- g_slist_free (connections);
- _clist->priv->cnc_added_sigid = g_signal_connect (browser_core_get (), "connection-added",
+ _clist->priv->cnc_added_sigid = g_signal_connect (t_app_get (), "connection-added",
G_CALLBACK (connection_added_cb), _clist);
- _clist->priv->cnc_removed_sigid = g_signal_connect (browser_core_get (), "connection-removed",
+ _clist->priv->cnc_removed_sigid = g_signal_connect (t_app_get (), "connection-removed",
G_CALLBACK (connection_removed_cb),
_clist);
gtk_widget_show_all (clist);
@@ -458,10 +444,10 @@ browser_connections_list_show (BrowserConnection *current)
model = gtk_tree_view_get_model (GTK_TREE_VIEW (_clist->priv->treeview));
if (gtk_tree_model_get_iter_first (model, &iter)) {
do {
- BrowserConnection *bcnc;
- gtk_tree_model_get (model, &iter, COLUMN_BCNC, &bcnc, -1);
- g_object_unref (bcnc);
- if (bcnc == current) {
+ TConnection *tcnc;
+ gtk_tree_model_get (model, &iter, COLUMN_TCNC, &tcnc, -1);
+ g_object_unref (tcnc);
+ if (tcnc == current) {
GtkTreeSelection *select;
select = gtk_tree_view_get_selection (GTK_TREE_VIEW
(_clist->priv->treeview));
gtk_tree_selection_select_iter (select, &iter);
@@ -484,19 +470,18 @@ browser_connections_list_show (BrowserConnection *current)
}
static void
-connection_added_cb (G_GNUC_UNUSED BrowserCore *bcore, BrowserConnection *bcnc, BrowserConnectionsList
*clist)
+connection_added_cb (G_GNUC_UNUSED TApp *app, TConnection *tcnc, BrowserConnectionsList *clist)
{
GtkListStore *store;
GtkTreeIter iter;
store = GTK_LIST_STORE (gtk_tree_view_get_model (clist->priv->treeview));
gtk_list_store_append (store, &iter);
- gtk_list_store_set (store, &iter,
- COLUMN_BCNC, bcnc, -1);
+ gtk_list_store_set (store, &iter, COLUMN_TCNC, tcnc, -1);
}
static void
-connection_removed_cb (G_GNUC_UNUSED BrowserCore *bcore, BrowserConnection *bcnc, BrowserConnectionsList
*clist)
+connection_removed_cb (G_GNUC_UNUSED TApp *app, TConnection *tcnc, BrowserConnectionsList *clist)
{
GtkTreeModel *model;
GtkTreeIter iter;
@@ -508,10 +493,10 @@ connection_removed_cb (G_GNUC_UNUSED BrowserCore *bcore, BrowserConnection *bcnc
g_assert (gtk_tree_model_get_iter_first (model, &iter));
do {
- BrowserConnection *mbcnc;
- gtk_tree_model_get (model, &iter, COLUMN_BCNC, &mbcnc, -1);
- g_object_unref (mbcnc);
- if (mbcnc == bcnc) {
+ TConnection *mtcnc;
+ gtk_tree_model_get (model, &iter, COLUMN_TCNC, &mtcnc, -1);
+ g_object_unref (mtcnc);
+ if (mtcnc == tcnc) {
is_selected_item = gtk_tree_selection_iter_is_selected (select, &iter);
gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
break;
diff --git a/tools/browser/browser-connections-list.h b/tools/browser/browser-connections-list.h
index 09a3061..9248e85 100644
--- a/tools/browser/browser-connections-list.h
+++ b/tools/browser/browser-connections-list.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2009 - 2014 Vivien Malerba <malerba gnome-db org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -22,6 +22,7 @@
#include <gtk/gtk.h>
#include "decl.h"
+#include <common/t-connection.h>
G_BEGIN_DECLS
@@ -48,7 +49,7 @@ struct _BrowserConnectionsListClass
};
GType browser_connections_list_get_type (void) G_GNUC_CONST;
-void browser_connections_list_show (BrowserConnection *current);
+void browser_connections_list_show (TConnection *current);
G_END_DECLS
diff --git a/tools/browser/browser-page.h b/tools/browser/browser-page.h
index fc046ee..aa67856 100644
--- a/tools/browser/browser-page.h
+++ b/tools/browser/browser-page.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2009 - 2014 Vivien Malerba <malerba gnome-db org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/tools/browser/browser-perspective.c b/tools/browser/browser-perspective.c
index 3bf8f1a..c375997 100644
--- a/tools/browser/browser-perspective.c
+++ b/tools/browser/browser-perspective.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 - 2013 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2009 - 2014 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2010 David King <davidk openismus com>
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
*
@@ -21,7 +21,14 @@
#include "browser-perspective.h"
#include "browser-page.h"
#include "browser-window.h"
-#include "support.h"
+#include "ui-support.h"
+#include <string.h>
+
+#include "schema-browser/perspective-main.h"
+#include "query-exec/perspective-main.h"
+#include "data-manager/perspective-main.h"
+#include "ldap-browser/perspective-main.h"
+#include "dummy-perspective/perspective-main.h"
static GRecMutex init_rmutex;
#define MUTEX_LOCK() g_rec_mutex_lock(&init_rmutex)
@@ -166,8 +173,7 @@ browser_perspective_get_window (BrowserPerspective *pers)
if (BROWSER_PERSPECTIVE_GET_CLASS (pers)->i_get_window)
return (BROWSER_PERSPECTIVE_GET_CLASS (pers)->i_get_window) (pers);
else
- return (BrowserWindow*) browser_find_parent_widget (GTK_WIDGET (pers),
- BROWSER_PERSPECTIVE_TYPE);
+ return (BrowserWindow*) ui_find_parent_widget (GTK_WIDGET (pers), BROWSER_PERSPECTIVE_TYPE);
}
static void nb_page_added_or_removed_cb (GtkNotebook *nb, GtkWidget *child, guint page_num,
@@ -288,3 +294,128 @@ adapt_notebook_for_fullscreen (BrowserPerspective *perspective)
showtabs = FALSE;
gtk_notebook_set_show_tabs (nb, showtabs);
}
+
+/*
+ * All perspectives information
+ */
+GSList *factories = NULL; /* list of PerspectiveFactory pointers, statically compiled */
+BrowserPerspectiveFactory *default_factory; /* used by default, no ref held on it */
+
+static void
+_factories_init (void)
+{
+ static gboolean init_done = FALSE;
+ if (G_LIKELY (init_done))
+ return;
+
+ /* initialize factories */
+ BrowserPerspectiveFactory *pers;
+
+ pers = schema_browser_perspective_get_factory ();
+ factories = g_slist_append (factories, pers);
+
+ pers = query_exec_perspective_get_factory ();
+ factories = g_slist_append (factories, pers);
+
+ pers = data_manager_perspective_get_factory ();
+ factories = g_slist_append (factories, pers);
+
+ pers = ldap_browser_perspective_get_factory ();
+ factories = g_slist_append (factories, pers);
+
+ pers = dummy_perspective_get_factory ();
+ factories = g_slist_append (factories, pers);
+
+ if (factories)
+ default_factory = BROWSER_PERSPECTIVE_FACTORY (factories->data);
+
+ init_done = TRUE;
+}
+
+/**
+ * browser_get_factory
+ * @factory: the name of the requested factory
+ *
+ * Get a pointer to a #BrowserPerspectiveFactory, from its name
+ *
+ * Returns: a pointer to the #BrowserPerspectiveFactory, or %NULL if not found
+ */
+BrowserPerspectiveFactory *
+browser_get_factory (const gchar *factory)
+{
+ GSList *list;
+ g_return_val_if_fail (factory, NULL);
+ _factories_init ();
+
+ for (list = factories; list; list = list->next) {
+ BrowserPerspectiveFactory *bpf = BROWSER_PERSPECTIVE_FACTORY (list->data);
+ if (!g_ascii_strcasecmp (bpf->perspective_name, factory))
+ return bpf;
+ }
+ return NULL;
+}
+
+/**
+ * browser_get_default_factory
+ *
+ * Get the default #BrowserPerspectiveFactory used when making new #BrowserWindow if none
+ * is provided when calling browser_window_new().
+ *
+ * Returns: the default #BrowserPerspectiveFactory
+ */
+BrowserPerspectiveFactory *
+browser_get_default_factory (void)
+{
+ _factories_init ();
+ return default_factory;
+}
+
+/**
+ * browser_set_default_factory
+ * @factory: the name of a #BrowserPerspectiveFactory
+ *
+ * Sets the default #BrowserPerspectiveFactory used when making new #BrowserWindow if none
+ * is provided when calling browser_window_new().
+ */
+void
+browser_set_default_factory (const gchar *factory)
+{
+ GSList *list;
+ gchar *lc2;
+
+ if (!factory)
+ return;
+
+ _factories_init ();
+
+ lc2 = g_utf8_strdown (factory, -1);
+ for (list = factories; list; list = list->next) {
+ BrowserPerspectiveFactory *fact = BROWSER_PERSPECTIVE_FACTORY (list->data);
+ gchar *lc1;
+ lc1 = g_utf8_strdown (fact->perspective_name, -1);
+
+ if (strstr (lc1, lc2)) {
+ default_factory = fact;
+ g_free (lc1);
+ break;
+ }
+
+ g_free (lc1);
+ }
+ g_free (lc2);
+}
+
+/**
+ * browser_get_factories
+ *
+ * Get a list of all the known Perspective factories
+ *
+ * Returns: a constant list which must not be altered
+ */
+const GSList *
+browser_get_factories (void)
+{
+ _factories_init ();
+
+ return factories;
+}
diff --git a/tools/browser/browser-perspective.h b/tools/browser/browser-perspective.h
index 7fcb457..319107d 100644
--- a/tools/browser/browser-perspective.h
+++ b/tools/browser/browser-perspective.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2009 - 2014 Vivien Malerba <malerba gnome-db org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -29,6 +29,9 @@ G_BEGIN_DECLS
#define IS_BROWSER_PERSPECTIVE(obj) (G_TYPE_CHECK_INSTANCE_TYPE (obj, BROWSER_PERSPECTIVE_TYPE))
#define BROWSER_PERSPECTIVE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), BROWSER_PERSPECTIVE_TYPE,
BrowserPerspectiveIface))
+typedef struct _BrowserPerspectiveIface BrowserPerspectiveIface;
+typedef struct _BrowserPerspective BrowserPerspective;
+
/* struct for the interface */
struct _BrowserPerspectiveIface {
GTypeInterface g_iface;
@@ -67,6 +70,21 @@ void browser_perspective_page_tab_label_change (BrowserPerspective *p
BrowserWindow *browser_perspective_get_window (BrowserPerspective *perspective);
void browser_perspective_declare_notebook (BrowserPerspective *perspective, GtkNotebook *nb);
+/*
+ * All perspectives information
+ */
+typedef struct {
+ const gchar *perspective_name;
+ const gchar *menu_shortcut;
+ BrowserPerspective *(*perspective_create) (BrowserWindow *);
+} BrowserPerspectiveFactory;
+#define BROWSER_PERSPECTIVE_FACTORY(x) ((BrowserPerspectiveFactory*)(x))
+
+BrowserPerspectiveFactory *browser_get_default_factory (void);
+BrowserPerspectiveFactory *browser_get_factory (const gchar *factory);
+void browser_set_default_factory (const gchar *factory);
+const GSList *browser_get_factories (void);
+
G_END_DECLS
#endif
diff --git a/tools/browser/browser-window.c b/tools/browser/browser-window.c
index 9219327..1724b3f 100644
--- a/tools/browser/browser-window.c
+++ b/tools/browser/browser-window.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2009 - 2014 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2010 David King <davidk openismus com>
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
*
@@ -21,17 +21,16 @@
#include <string.h>
#include <glib/gi18n-lib.h>
#include "browser-window.h"
-#include <libgda/binreloc/gda-binreloc.h>
#include "login-dialog.h"
-#include "browser-core.h"
-#include "support.h"
-#include "browser-perspective.h"
-#include "browser-connection.h"
+#include <common/t-app.h>
+#include <common/t-connection.h>
+#include "ui-support.h"
#include "browser-connections-list.h"
-#include "browser-spinner.h"
-#include "browser-stock-icons.h"
#include "connection-binding-properties.h"
#include <gdk/gdkkeysyms.h>
+#include <thread-wrapper/gda-connect.h>
+
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
/*
* structure representing a 'tab' in a window
@@ -40,18 +39,18 @@
* Each is owned by a BrowserWindow
*/
typedef struct {
- BrowserWindow *bwin; /* pointer to window the tab is in, no ref held here */
+ BrowserWindow *bwin; /* pointer to window the tab is in, no ref held here */
BrowserPerspectiveFactory *factory;
- gint page_number; /* in reference to bwin->perspectives_nb */
- BrowserPerspective *perspective_widget;
+ gint page_number; /* in reference to bwin->perspectives_nb */
+ BrowserPerspective *perspective_widget;
- GtkActionGroup *customized_actions;
- guint customized_merge_id;
- gchar *customized_ui;
+ GtkActionGroup *customized_actions;
+ guint customized_merge_id;
+ gchar *customized_ui;
} PerspectiveData;
#define PERSPECTIVE_DATA(x) ((PerspectiveData*)(x))
static PerspectiveData *perspective_data_new (BrowserWindow *bwin, BrowserPerspectiveFactory *factory);
-static void perspective_data_free (PerspectiveData *pers);
+static void perspective_data_free (PerspectiveData *pers);
/*
* Main static functions
@@ -62,12 +61,12 @@ static void browser_window_dispose (GObject *object);
static gboolean window_state_event (GtkWidget *widget, GdkEventWindowState *event);
static gboolean key_press_event (GtkWidget *widget, GdkEventKey *event);
-static void connection_busy_cb (BrowserConnection *bcnc, gboolean is_busy, gchar *reason, BrowserWindow
*bwin);
-static void connection_added_cb (BrowserCore *bcore, BrowserConnection *bcnc, BrowserWindow *bwin);
-static void connection_removed_cb (BrowserCore *bcore, BrowserConnection *bcnc, BrowserWindow *bwin);
+static void connection_added_cb (TApp *tapp, TConnection *tcnc, BrowserWindow *bwin);
+static void connection_removed_cb (TApp *tapp, TConnection *tcnc, BrowserWindow *bwin);
-static void transaction_status_changed_cb (BrowserConnection *bcnc, BrowserWindow *bwin);
+static void transaction_status_changed_cb (TConnection *tcnc, BrowserWindow *bwin);
+static void cnc_status_changed_cb (TConnection *tcnc, GdaConnectionStatus status, BrowserWindow *bwin);
enum {
@@ -82,7 +81,7 @@ static gint browser_window_signals[LAST_SIGNAL] = { 0 };
static GObjectClass *parent_class = NULL;
struct _BrowserWindowPrivate {
- BrowserConnection *bcnc;
+ TConnection *tcnc;
GtkNotebook *perspectives_nb; /* notebook used to switch between tabs, for the selector part */
GSList *perspectives; /* list of PerspectiveData pointers, owned here */
PerspectiveData *current_perspective;
@@ -93,14 +92,13 @@ struct _BrowserWindowPrivate {
gboolean toolbar_shown;
gboolean cursor_in_toolbar;
GtkWidget *spinner;
- guint spinner_timer;
GtkUIManager *ui_manager;
GtkActionGroup *agroup;
GtkActionGroup *perspectives_actions;
gboolean updating_transaction_status;
GtkToolbarStyle toolbar_style;
- GtkActionGroup *cnc_agroup; /* one GtkAction for each BrowserConnection */
+ GtkActionGroup *cnc_agroup; /* one GtkAction for each TConnection */
gulong cnc_added_sigid;
gulong cnc_removed_sigid;
@@ -113,6 +111,9 @@ struct _BrowserWindowPrivate {
gboolean fullscreen;
gulong fullscreen_motion_sig_id;
guint fullscreen_timer_id;
+
+ gulong cnc_status_sigid;
+ gulong trans_status_sigid;
};
GType
@@ -138,7 +139,7 @@ browser_window_get_type (void)
g_mutex_lock (®istering);
if (type == 0)
- type = g_type_register_static (GTK_TYPE_WINDOW, "BrowserWindow", &info, 0);
+ type = g_type_register_static (GTK_TYPE_APPLICATION_WINDOW, "BrowserWindow", &info,
0);
g_mutex_unlock (®istering);
}
return type;
@@ -171,7 +172,7 @@ static void
browser_window_init (BrowserWindow *bwin)
{
bwin->priv = g_new0 (BrowserWindowPrivate, 1);
- bwin->priv->bcnc = NULL;
+ bwin->priv->tcnc = NULL;
bwin->priv->perspectives_nb = NULL;
bwin->priv->perspectives = NULL;
bwin->priv->cnc_agroup = NULL;
@@ -181,7 +182,6 @@ browser_window_init (BrowserWindow *bwin)
bwin->priv->fullscreen = FALSE;
bwin->priv->fullscreen_motion_sig_id = 0;
bwin->priv->fullscreen_timer_id = 0;
- bwin->priv->spinner_timer = 0;
}
static void
@@ -189,21 +189,14 @@ browser_window_dispose (GObject *object)
{
BrowserWindow *bwin;
- g_return_if_fail (object != NULL);
g_return_if_fail (BROWSER_IS_WINDOW (object));
bwin = BROWSER_WINDOW (object);
if (bwin->priv) {
- GSList *connections, *list;
+ GSList *connections;
- if (bwin->priv->spinner_timer) {
- g_source_remove (bwin->priv->spinner_timer);
- bwin->priv->spinner_timer = 0;
- }
- connections = browser_core_get_connections ();
- for (list = connections; list; list = list->next)
- connection_removed_cb (browser_core_get(), BROWSER_CONNECTION (list->data), bwin);
- g_slist_free (connections);
+ for (connections = t_app_get_all_connections (); connections; connections = connections->next)
+ connection_removed_cb (t_app_get(), T_CONNECTION (connections->data), bwin);
if (bwin->priv->fullscreen_timer_id)
g_source_remove (bwin->priv->fullscreen_timer_id);
@@ -212,19 +205,18 @@ browser_window_dispose (GObject *object)
g_signal_handler_disconnect (bwin, bwin->priv->fullscreen_motion_sig_id);
if (bwin->priv->cnc_added_sigid > 0)
- g_signal_handler_disconnect (browser_core_get (), bwin->priv->cnc_added_sigid);
+ gda_signal_handler_disconnect (t_app_get (), bwin->priv->cnc_added_sigid);
if (bwin->priv->cnc_removed_sigid > 0)
- g_signal_handler_disconnect (browser_core_get (), bwin->priv->cnc_removed_sigid);
+ gda_signal_handler_disconnect (t_app_get (), bwin->priv->cnc_removed_sigid);
if (bwin->priv->ui_manager)
g_object_unref (bwin->priv->ui_manager);
if (bwin->priv->cnc_agroup)
g_object_unref (bwin->priv->cnc_agroup);
- if (bwin->priv->bcnc) {
- g_signal_handlers_disconnect_by_func (bwin->priv->bcnc,
- G_CALLBACK (transaction_status_changed_cb),
- bwin);
- g_object_unref (bwin->priv->bcnc);
+ if (bwin->priv->tcnc) {
+ gda_signal_handler_disconnect (bwin->priv->tcnc, bwin->priv->cnc_status_sigid);
+ gda_signal_handler_disconnect (bwin->priv->tcnc, bwin->priv->trans_status_sigid);
+ g_object_unref (bwin->priv->tcnc);
}
if (bwin->priv->perspectives) {
g_slist_foreach (bwin->priv->perspectives, (GFunc) perspective_data_free, NULL);
@@ -243,14 +235,6 @@ browser_window_dispose (GObject *object)
parent_class->dispose (object);
}
-
-static gboolean
-delete_event (G_GNUC_UNUSED GtkWidget *widget, G_GNUC_UNUSED GdkEvent *event, BrowserWindow *bwin)
-{
- browser_core_close_window (bwin);
- return TRUE;
-}
-
static void transaction_begin_cb (GtkAction *action, BrowserWindow *bwin);
static void transaction_commit_cb (GtkAction *action, BrowserWindow *bwin);
static void transaction_rollback_cb (GtkAction *action, BrowserWindow *bwin);
@@ -291,7 +275,7 @@ static const GtkActionEntry ui_actions[] = {
{ "Display", NULL, N_("_Display"), NULL, N_("Display"), NULL },
{ "Perspective", NULL, N_("_Perspective"), NULL, N_("Perspective"), NULL },
{ "Window", NULL, N_("_Window"), NULL, N_("Window"), NULL },
- { "WindowNew", STOCK_NEW_WINDOW, N_("_New Window"), "<control>N", N_("Open a new window for current
connection"), G_CALLBACK (window_new_cb)},
+ { "WindowNew", GTK_STOCK_MISSING_IMAGE /*STOCK_NEW_WINDOW*/, N_("_New Window"), "<control>N",
N_("Open a new window for current connection"), G_CALLBACK (window_new_cb)},
{ "WindowNewOthers", NULL, N_("New Window for _Connection"), NULL, N_("Open a new window for a
connection"), NULL},
{ "WindowClose", GTK_STOCK_CLOSE, N_("_Close"), NULL, N_("Close this window"), G_CALLBACK
(window_close_cb)},
{ "Help", NULL, N_("_Help"), NULL, N_("Help"), NULL },
@@ -299,11 +283,11 @@ static const GtkActionEntry ui_actions[] = {
#ifdef HAVE_GDU
{ "HelpManual", GTK_STOCK_HELP, N_("_Manual"), "F1", N_("Manual"), G_CALLBACK (manual_cb) },
#endif
- { "TransactionBegin", BROWSER_STOCK_BEGIN, N_("Begin"), NULL, N_("Begin a new transaction"),
+ { "TransactionBegin", GTK_STOCK_MISSING_IMAGE /*BROWSER_STOCK_BEGIN*/, N_("Begin transaction"), NULL,
N_("Begin a new transaction"),
G_CALLBACK (transaction_begin_cb)},
- { "TransactionCommit", BROWSER_STOCK_COMMIT, N_("Commit"), NULL, N_("Commit current transaction"),
+ { "TransactionCommit", GTK_STOCK_MISSING_IMAGE /*BROWSER_STOCK_COMMIT*/, N_("Commit transaction"),
NULL, N_("Commit current transaction"),
G_CALLBACK (transaction_commit_cb)},
- { "TransactionRollback", BROWSER_STOCK_ROLLBACK, N_("Rollback"), NULL, N_("Rollback current
transaction"),
+ { "TransactionRollback", GTK_STOCK_MISSING_IMAGE /*BROWSER_STOCK_ROLLBACK*/, N_("Rollback
transaction"), NULL, N_("Rollback current transaction"),
G_CALLBACK (transaction_rollback_cb)},
};
@@ -362,46 +346,42 @@ static const gchar *ui_actions_info =
/**
* browser_window_new
- * @bcnc: a #BrowserConnection
+ * @tcnc: a #TConnection, not %NULL
* @factory: a #BrowserPerspectiveFactory, may be %NULL
*
- * Creates a new #BrowserWindow window for the @bcnc connection, and displays it.
+ * Creates a new #BrowserWindow window for the @tcnc connection, and displays it.
* If @factory is not %NULL, then the new window will show the perspective corresponding
* to @factory. If it's %NULL, then the default #BrowserPerspectiveFactory will be used,
- * see browser_core_get_default_factory().
- *
- * Don't forget to call browser_core_take_window() to have the new window correctly
- * managed by the browser. Similarly, to close the window, use browser_core_close_window()
- * and not simply gtk_widget_destroy().
+ * see t_app_get_default_factory().
*
* Returns: the new object
*/
BrowserWindow*
-browser_window_new (BrowserConnection *bcnc, BrowserPerspectiveFactory *factory)
+browser_window_new (TConnection *tcnc, BrowserPerspectiveFactory *factory)
{
BrowserWindow *bwin;
- g_return_val_if_fail (BROWSER_IS_CONNECTION (bcnc), NULL);
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
- bwin = BROWSER_WINDOW (g_object_new (BROWSER_TYPE_WINDOW, NULL));
- bwin->priv->bcnc = g_object_ref (bcnc);
- g_signal_connect (bcnc, "transaction-status-changed",
- G_CALLBACK (transaction_status_changed_cb), bwin);
+ bwin = BROWSER_WINDOW (g_object_new (BROWSER_TYPE_WINDOW, "application", t_app_get(), NULL));
+ bwin->priv->tcnc = g_object_ref (tcnc);
+ bwin->priv->trans_status_sigid = gda_signal_connect (tcnc, "transaction-status-changed",
+ G_CALLBACK (transaction_status_changed_cb), bwin,
+ NULL, 0, NULL);
+ bwin->priv->cnc_status_sigid = gda_signal_connect (tcnc, "status-changed",
+ G_CALLBACK (cnc_status_changed_cb), bwin,
+ NULL, 0, NULL);
gchar *tmp;
- tmp = browser_connection_get_long_name (bcnc);
+ tmp = t_connection_get_long_name (tcnc);
gtk_window_set_title (GTK_WINDOW (bwin), tmp);
g_free (tmp);
gtk_window_set_default_size ((GtkWindow*) bwin, 900, 650);
- g_signal_connect (G_OBJECT (bwin), "delete-event",
- G_CALLBACK (delete_event), bwin);
+
/* icon */
GdkPixbuf *icon;
- gchar *path;
- path = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, "pixmaps", "gda-browser.png", NULL);
- icon = gdk_pixbuf_new_from_file (path, NULL);
- g_free (path);
+ icon = gdk_pixbuf_new_from_resource ("/images/gda-browser.png", NULL);
if (icon) {
gtk_window_set_icon (GTK_WINDOW (bwin), icon);
g_object_unref (icon);
@@ -425,7 +405,7 @@ browser_window_new (BrowserConnection *bcnc, BrowserPerspectiveFactory *factory)
bwin->priv->agroup = group;
gtk_action_group_add_actions (group, ui_actions, G_N_ELEMENTS (ui_actions), bwin);
gtk_action_group_add_toggle_actions (group, ui_toggle_actions, G_N_ELEMENTS (ui_toggle_actions),
bwin);
- if (browser_connection_is_virtual (bwin->priv->bcnc)) {
+ if (t_connection_is_virtual (bwin->priv->tcnc)) {
GtkAction *action;
action = gtk_action_group_get_action (bwin->priv->agroup, "TransactionBegin");
gtk_action_set_visible (action, FALSE);
@@ -434,7 +414,7 @@ browser_window_new (BrowserConnection *bcnc, BrowserPerspectiveFactory *factory)
action = gtk_action_group_get_action (bwin->priv->agroup, "TransactionRollback");
gtk_action_set_visible (action, FALSE);
}
- transaction_status_changed_cb (bwin->priv->bcnc, bwin);
+ transaction_status_changed_cb (bwin->priv->tcnc, bwin);
ui = gtk_ui_manager_new ();
gtk_ui_manager_insert_action_group (ui, group, 0);
@@ -476,8 +456,7 @@ browser_window_new (BrowserConnection *bcnc, BrowserPerspectiveFactory *factory)
gtk_toolbar_insert (GTK_TOOLBAR (toolbar), ti, -1);
gtk_widget_show (GTK_WIDGET (ti));
- spinner = browser_spinner_new ();
- browser_spinner_set_size ((BrowserSpinner*) spinner, GTK_ICON_SIZE_SMALL_TOOLBAR);
+ spinner = gtk_spinner_new ();
svbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
align = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
@@ -494,26 +473,25 @@ browser_window_new (BrowserConnection *bcnc, BrowserPerspectiveFactory *factory)
/* statusbar */
bwin->priv->statusbar = gtk_statusbar_new ();
- GSList *connections, *list;
+ GSList *list;
bwin->priv->cnc_agroup = gtk_action_group_new ("CncActions");
gtk_action_group_set_translation_domain (bwin->priv->cnc_agroup, GETTEXT_PACKAGE);
- connections = browser_core_get_connections ();
- for (list = connections; list; list = list->next)
- connection_added_cb (browser_core_get(), BROWSER_CONNECTION (list->data), bwin);
- g_slist_free (connections);
+ for (list = t_app_get_all_connections (); list; list = list->next)
+ connection_added_cb (t_app_get(), T_CONNECTION (list->data), bwin);
gtk_ui_manager_insert_action_group (bwin->priv->ui_manager, bwin->priv->cnc_agroup, 0);
- bwin->priv->cnc_added_sigid = g_signal_connect (browser_core_get (), "connection-added",
- G_CALLBACK (connection_added_cb), bwin);
- bwin->priv->cnc_removed_sigid = g_signal_connect (browser_core_get (), "connection-removed",
- G_CALLBACK (connection_removed_cb), bwin);
-
+ bwin->priv->cnc_added_sigid = gda_signal_connect (t_app_get (), "connection-added",
+ G_CALLBACK (connection_added_cb), bwin,
+ NULL, 0, NULL);
+ bwin->priv->cnc_removed_sigid = gda_signal_connect (t_app_get (), "connection-removed",
+ G_CALLBACK (connection_removed_cb), bwin,
+ NULL, 0, NULL);
/* create a PerspectiveData */
PerspectiveData *pers;
- if (! factory && browser_connection_is_ldap (bcnc))
- factory = browser_core_get_factory (_("LDAP browser"));
+ if (! factory && t_connection_is_ldap (tcnc))
+ factory = browser_get_factory (_("LDAP browser"));
pers = perspective_data_new (bwin, factory);
bwin->priv->perspectives = g_slist_prepend (bwin->priv->perspectives, pers);
GtkActionGroup *actions;
@@ -563,19 +541,19 @@ browser_window_new (BrowserConnection *bcnc, BrowserPerspectiveFactory *factory)
g_object_unref (agroup);
GtkAction *active_action = NULL;
- for (plist = browser_core_get_factories (); plist; plist = plist->next) {
+ for (plist = browser_get_factories (); plist; plist = plist->next) {
GtkAction *action;
const gchar *name;
name = BROWSER_PERSPECTIVE_FACTORY (plist->data)->perspective_name;
- if (!strcmp (name, _("LDAP browser")) && !browser_connection_is_ldap (bcnc))
+ if (!strcmp (name, _("LDAP browser")) && !t_connection_is_ldap (tcnc))
continue;
action = GTK_ACTION (gtk_radio_action_new (name, name, NULL, NULL, FALSE));
if (!active_action &&
((factory && (BROWSER_PERSPECTIVE_FACTORY (plist->data) == factory)) ||
- (!factory && (BROWSER_PERSPECTIVE_FACTORY (plist->data) ==
browser_core_get_default_factory ()))))
+ (!factory && (BROWSER_PERSPECTIVE_FACTORY (plist->data) == browser_get_default_factory
()))))
active_action = action;
if (BROWSER_PERSPECTIVE_FACTORY (plist->data)->menu_shortcut)
gtk_action_group_add_action_with_accel (agroup, action,
@@ -684,42 +662,35 @@ perspective_toggle_cb (GtkRadioAction *action, GtkRadioAction *current, BrowserW
g_object_unref (actions);
}
-static gboolean
-spinner_stop_timer (BrowserWindow *bwin)
-{
- browser_spinner_stop (BROWSER_SPINNER (bwin->priv->spinner));
- bwin->priv->spinner_timer = 0;
- return FALSE; /* remove timer */
-}
-
static void
-connection_busy_cb (BrowserConnection *bcnc, gboolean is_busy, gchar *reason, BrowserWindow *bwin)
+cnc_status_changed_cb (TConnection *tcnc, GdaConnectionStatus status, BrowserWindow *bwin)
{
GtkAction *action;
- if (bcnc == bwin->priv->bcnc) {
+ gchar *reason = "AAAA";
+ gboolean is_busy;
+ is_busy = (status == GDA_CONNECTION_STATUS_IDLE) ? FALSE : TRUE;
+
+ if (tcnc == bwin->priv->tcnc) {
/* @bcbc is @bwin's own connection */
- if (bwin->priv->spinner_timer) {
- g_source_remove (bwin->priv->spinner_timer);
- bwin->priv->spinner_timer = 0;
+ if (! is_busy) {
+ gtk_spinner_stop (GTK_SPINNER (bwin->priv->spinner));
+ gtk_widget_hide (GTK_WIDGET (bwin->priv->spinner));
+ gtk_widget_set_tooltip_text (bwin->priv->spinner, NULL);
+ gtk_statusbar_pop (GTK_STATUSBAR (bwin->priv->statusbar),
+ bwin->priv->cnc_statusbar_context);
}
- if (is_busy) {
- browser_spinner_start (BROWSER_SPINNER (bwin->priv->spinner));
+ else {
+ gtk_widget_show (GTK_WIDGET (bwin->priv->spinner));
+ gtk_spinner_start (GTK_SPINNER (bwin->priv->spinner));
gtk_widget_set_tooltip_text (bwin->priv->spinner, reason);
gtk_statusbar_push (GTK_STATUSBAR (bwin->priv->statusbar),
bwin->priv->cnc_statusbar_context,
reason);
}
- else {
- bwin->priv->spinner_timer = g_timeout_add (300,
- (GSourceFunc) spinner_stop_timer, bwin);
- gtk_widget_set_tooltip_text (bwin->priv->spinner, NULL);
- gtk_statusbar_pop (GTK_STATUSBAR (bwin->priv->statusbar),
- bwin->priv->cnc_statusbar_context);
- }
gboolean bsens = FALSE, csens = FALSE;
- if (!is_busy) {
- if (browser_connection_get_transaction_status (bcnc))
+ if (! is_busy) {
+ if (t_connection_get_transaction_status (tcnc))
csens = TRUE;
else
bsens = TRUE;
@@ -738,7 +709,7 @@ connection_busy_cb (BrowserConnection *bcnc, gboolean is_busy, gchar *reason, Br
}
gchar *cncname;
- cncname = browser_connection_get_long_name (bcnc);
+ cncname = t_connection_get_long_name (tcnc);
action = gtk_action_group_get_action (bwin->priv->cnc_agroup, cncname);
g_free (cncname);
if (action)
@@ -747,14 +718,14 @@ connection_busy_cb (BrowserConnection *bcnc, gboolean is_busy, gchar *reason, Br
/* update @bwin->priv->cnc_agroup and @bwin->priv->ui_manager */
static void
-connection_added_cb (G_GNUC_UNUSED BrowserCore *bcore, BrowserConnection *bcnc, BrowserWindow *bwin)
+connection_added_cb (G_GNUC_UNUSED TApp *tapp, TConnection *tcnc, BrowserWindow *bwin)
{
GtkAction *action;
gchar *cncname;
guint mid;
mid = gtk_ui_manager_new_merge_id (bwin->priv->ui_manager);
- cncname = browser_connection_get_long_name (bcnc);
+ cncname = t_connection_get_long_name (tcnc);
action = gtk_action_new (cncname, cncname, NULL, NULL);
gtk_action_group_add_action (bwin->priv->cnc_agroup, action);
guint *amid = g_new (guint, 1);
@@ -767,29 +738,21 @@ connection_added_cb (G_GNUC_UNUSED BrowserCore *bcore, BrowserConnection *bcnc,
g_free (cncname);
g_signal_connect (action, "activate",
G_CALLBACK (window_new_with_cnc_cb), bwin);
- g_object_set_data (G_OBJECT (action), "bcnc", bcnc);
- gtk_action_set_sensitive (action, ! browser_connection_is_busy (bcnc, NULL));
+ g_object_set_data (G_OBJECT (action), "tcnc", tcnc);
+ gtk_action_set_sensitive (action, ! t_connection_is_busy (tcnc, NULL));
g_object_unref (action);
-
- gchar *reason = NULL;
- if (browser_connection_is_busy (bcnc, &reason)) {
- connection_busy_cb (bcnc, TRUE, reason, bwin);
- g_free (reason);
- }
- g_signal_connect (bcnc, "busy",
- G_CALLBACK (connection_busy_cb), bwin);
}
/* update @bwin->priv->cnc_agroup and @bwin->priv->ui_manager */
static void
-connection_removed_cb (G_GNUC_UNUSED BrowserCore *bcore, BrowserConnection *bcnc, BrowserWindow *bwin)
+connection_removed_cb (G_GNUC_UNUSED TApp *tapp, TConnection *tcnc, BrowserWindow *bwin)
{
GtkAction *action;
gchar *path;
gchar *cncname;
guint *mid;
- cncname = browser_connection_get_long_name (bcnc);
+ cncname = t_connection_get_long_name (tcnc);
path = g_strdup_printf ("/MenuBar/Window/WindowNewOthers/CncList/%s", cncname);
g_free (cncname);
action = gtk_ui_manager_get_action (bwin->priv->ui_manager, path);
@@ -801,9 +764,6 @@ connection_removed_cb (G_GNUC_UNUSED BrowserCore *bcore, BrowserConnection *bcnc
gtk_ui_manager_remove_ui (bwin->priv->ui_manager, *mid);
gtk_action_group_remove_action (bwin->priv->cnc_agroup, action);
-
- g_signal_handlers_disconnect_by_func (bcnc,
- G_CALLBACK (connection_busy_cb), bwin);
}
static void
@@ -812,36 +772,24 @@ connection_close_cb (G_GNUC_UNUSED GtkAction *action, BrowserWindow *bwin)
/* confirmation dialog */
GtkWidget *dialog;
char *str;
- BrowserConnection *bcnc;
- bcnc = browser_window_get_connection (bwin);
+ TConnection *tcnc;
+ tcnc = browser_window_get_connection (bwin);
str = g_strdup_printf (_("Do you want to close the '%s' connection?"),
- browser_connection_get_name (bcnc));
+ t_connection_get_name (tcnc));
dialog = gtk_message_dialog_new_with_markup (GTK_WINDOW (bwin), GTK_DIALOG_MODAL,
GTK_MESSAGE_QUESTION,
GTK_BUTTONS_YES_NO,
"<b>%s</b>", str);
g_free (str);
- if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_YES) {
+ gboolean doclose;
+ doclose = (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_YES) ? TRUE : FALSE;
+ gtk_widget_destroy (dialog);
+ if (doclose) {
/* actual connection closing */
- browser_core_close_connection (bcnc);
-
- /* list all the windows using bwin's connection */
- GSList *list, *windows, *bwin_list = NULL;
-
- windows = browser_core_get_windows ();
- for (list = windows; list; list = list->next) {
- if (browser_window_get_connection (BROWSER_WINDOW (list->data)) == bcnc)
- bwin_list = g_slist_prepend (bwin_list, list->data);
- }
- g_slist_free (windows);
-
- for (list = bwin_list; list; list = list->next)
- delete_event (NULL, NULL, BROWSER_WINDOW (list->data));
- g_slist_free (bwin_list);
+ t_connection_close (tcnc);
}
- gtk_widget_destroy (dialog);
}
static void
@@ -851,7 +799,7 @@ quit_cb (G_GNUC_UNUSED GtkAction *action, BrowserWindow *bwin)
GtkWidget *dialog;
GSList *connections;
- connections = browser_core_get_connections ();
+ connections = t_app_get_all_connections ();
if (connections && connections->next)
dialog = gtk_message_dialog_new_with_markup (GTK_WINDOW (bwin), GTK_DIALOG_MODAL,
GTK_MESSAGE_QUESTION,
@@ -868,25 +816,15 @@ quit_cb (G_GNUC_UNUSED GtkAction *action, BrowserWindow *bwin)
_("the connection will be closed."));
- if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_YES) {
- /* actual connection closing */
- GSList *list;
- for (list = connections; list; list = list->next)
- browser_core_close_connection (BROWSER_CONNECTION (list->data));
-
- /* list all the windows using bwin's connection */
- GSList *windows;
- windows = browser_core_get_windows ();
- for (list = windows; list; list = list->next)
- delete_event (NULL, NULL, BROWSER_WINDOW (list->data));
- g_slist_free (windows);
- }
- g_slist_free (connections);
- gtk_widget_destroy (dialog);
+ gboolean doquit;
+ doquit = (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_YES) ? TRUE : FALSE;
+ gtk_widget_destroy (dialog);
+ if (doquit)
+ t_app_request_quit ();
}
static void
-transaction_status_changed_cb (BrowserConnection *bcnc, BrowserWindow *bwin)
+transaction_status_changed_cb (TConnection *tcnc, BrowserWindow *bwin)
{
if (!bwin->priv->agroup)
return;
@@ -894,7 +832,7 @@ transaction_status_changed_cb (BrowserConnection *bcnc, BrowserWindow *bwin)
GtkAction *action;
gboolean trans_started;
- trans_started = browser_connection_get_transaction_status (bcnc) ? TRUE : FALSE;
+ trans_started = t_connection_get_transaction_status (tcnc) ? TRUE : FALSE;
bwin->priv->updating_transaction_status = TRUE;
action = gtk_action_group_get_action (bwin->priv->agroup, "TransactionBegin");
@@ -914,10 +852,10 @@ transaction_begin_cb (G_GNUC_UNUSED GtkAction *action, BrowserWindow *bwin)
{
if (!bwin->priv->updating_transaction_status) {
GError *error = NULL;
- if (! browser_connection_begin (bwin->priv->bcnc, &error)) {
- browser_show_error (GTK_WINDOW (gtk_widget_get_toplevel ((GtkWidget*) bwin)),
- _("Error starting transaction: %s"),
- error && error->message ? error->message : _("No detail"));
+ if (! t_connection_begin (bwin->priv->tcnc, &error)) {
+ ui_show_error (GTK_WINDOW (gtk_widget_get_toplevel ((GtkWidget*) bwin)),
+ _("Error starting transaction: %s"),
+ error && error->message ? error->message : _("No detail"));
g_clear_error (&error);
}
}
@@ -928,10 +866,10 @@ transaction_commit_cb (G_GNUC_UNUSED GtkAction *action, BrowserWindow *bwin)
{
if (!bwin->priv->updating_transaction_status) {
GError *error = NULL;
- if (! browser_connection_commit (bwin->priv->bcnc, &error)) {
- browser_show_error (GTK_WINDOW (gtk_widget_get_toplevel ((GtkWidget*) bwin)),
- _("Error committing transaction: %s"),
- error && error->message ? error->message : _("No detail"));
+ if (! t_connection_commit (bwin->priv->tcnc, &error)) {
+ ui_show_error (GTK_WINDOW (gtk_widget_get_toplevel ((GtkWidget*) bwin)),
+ _("Error committing transaction: %s"),
+ error && error->message ? error->message : _("No detail"));
g_clear_error (&error);
}
}
@@ -942,10 +880,10 @@ transaction_rollback_cb (G_GNUC_UNUSED GtkAction *action, BrowserWindow *bwin)
{
if (!bwin->priv->updating_transaction_status) {
GError *error = NULL;
- if (! browser_connection_rollback (bwin->priv->bcnc, &error)) {
- browser_show_error (GTK_WINDOW (gtk_widget_get_toplevel ((GtkWidget*) bwin)),
- _("Error rolling back transaction: %s"),
- error && error->message ? error->message : _("No detail"));
+ if (! t_connection_rollback (bwin->priv->tcnc, &error)) {
+ ui_show_error (GTK_WINDOW (gtk_widget_get_toplevel ((GtkWidget*) bwin)),
+ _("Error rolling back transaction: %s"),
+ error && error->message ? error->message : _("No detail"));
g_clear_error (&error);
}
}
@@ -955,7 +893,7 @@ transaction_rollback_cb (G_GNUC_UNUSED GtkAction *action, BrowserWindow *bwin)
static void
window_close_cb (G_GNUC_UNUSED GtkAction *action, BrowserWindow *bwin)
{
- delete_event (NULL, NULL, bwin);
+ gtk_window_close (GTK_WINDOW (bwin));
}
static gboolean
@@ -1096,16 +1034,10 @@ window_state_event (GtkWidget *widget, GdkEventWindowState *event)
fullscreen = event->new_window_state & GDK_WINDOW_STATE_FULLSCREEN;
bwin->priv->fullscreen = fullscreen;
- if (fullscreen) {
+ if (fullscreen)
gtk_toolbar_set_style (GTK_TOOLBAR (wid), GTK_TOOLBAR_ICONS);
- browser_spinner_set_size (BROWSER_SPINNER (bwin->priv->spinner),
- GTK_ICON_SIZE_LARGE_TOOLBAR);
- }
- else {
+ else
gtk_toolbar_set_style (GTK_TOOLBAR (wid), bwin->priv->toolbar_style);
- browser_spinner_set_size (BROWSER_SPINNER (bwin->priv->spinner),
- GTK_ICON_SIZE_SMALL_TOOLBAR);
- }
wid = gtk_ui_manager_get_widget (bwin->priv->ui_manager, "/MenuBar");
if (fullscreen)
@@ -1122,41 +1054,43 @@ static void
window_new_cb (G_GNUC_UNUSED GtkAction *action, BrowserWindow *bwin)
{
BrowserWindow *nbwin;
- BrowserConnection *bcnc;
- bcnc = browser_window_get_connection (bwin);
- nbwin = browser_window_new (bcnc, NULL);
-
- browser_core_take_window (nbwin);
+ TConnection *tcnc;
+ tcnc = browser_window_get_connection (bwin);
+ nbwin = browser_window_new (tcnc, NULL);
+ gtk_widget_show (GTK_WIDGET (nbwin));
}
static void
window_new_with_cnc_cb (GtkAction *action, G_GNUC_UNUSED BrowserWindow *bwin)
{
BrowserWindow *nbwin;
- BrowserConnection *bcnc;
- bcnc = g_object_get_data (G_OBJECT (action), "bcnc");
- g_return_if_fail (BROWSER_IS_CONNECTION (bcnc));
-
- nbwin = browser_window_new (bcnc, NULL);
-
- browser_core_take_window (nbwin);
+ TConnection *tcnc;
+
+ tcnc = g_object_get_data (G_OBJECT (action), "tcnc");
+ g_return_if_fail (T_IS_CONNECTION (tcnc));
+ nbwin = browser_window_new (tcnc, NULL);
+ gtk_widget_show (GTK_WIDGET (nbwin));
}
static void
connection_open_cb (G_GNUC_UNUSED GtkAction *action, G_GNUC_UNUSED BrowserWindow *bwin)
{
- browser_connection_open (NULL);
+ LoginDialog *dialog;
+ dialog = login_dialog_new (NULL);
+
+ login_dialog_run_open_connection (dialog, TRUE, NULL);
+ gtk_widget_destroy (GTK_WIDGET (dialog));
}
static void
connection_properties_cb (G_GNUC_UNUSED GtkAction *action, BrowserWindow *bwin)
{
- if (BROWSER_IS_VIRTUAL_CONNECTION (bwin->priv->bcnc)) {
+ if (T_IS_VIRTUAL_CONNECTION (bwin->priv->tcnc)) {
GtkWidget *win;
- BrowserVirtualConnectionSpecs *specs;
+ TVirtualConnectionSpecs *specs;
gint res;
- g_object_get (G_OBJECT (bwin->priv->bcnc), "specs", &specs, NULL);
+ g_object_get (G_OBJECT (bwin->priv->tcnc), "specs", &specs, NULL);
win = connection_binding_properties_new_edit (specs); /* @specs is not modified */
gtk_window_set_transient_for (GTK_WINDOW (win), GTK_WINDOW (bwin));
gtk_widget_show (win);
@@ -1165,23 +1099,22 @@ connection_properties_cb (G_GNUC_UNUSED GtkAction *action, BrowserWindow *bwin)
gtk_widget_hide (win);
if (res == GTK_RESPONSE_OK) {
GError *error = NULL;
- if (!browser_virtual_connection_modify_specs (BROWSER_VIRTUAL_CONNECTION
(bwin->priv->bcnc),
- connection_binding_properties_get_specs
(CONNECTION_BINDING_PROPERTIES (win)),
- &error)) {
- browser_show_error ((GtkWindow*) bwin,
- _("Error updating bound connection: %s"),
- error && error->message ? error->message : _("No
detail"));
+ if (!t_virtual_connection_modify_specs (T_VIRTUAL_CONNECTION (bwin->priv->tcnc),
+ connection_binding_properties_get_specs
(CONNECTION_BINDING_PROPERTIES (win)),
+ &error)) {
+ ui_show_error ((GtkWindow*) bwin,
+ _("Error updating bound connection: %s"),
+ error && error->message ? error->message : _("No detail"));
g_clear_error (&error);
}
/* update meta store */
- browser_connection_update_meta_data (bwin->priv->bcnc);
+ t_connection_update_meta_data (bwin->priv->tcnc);
}
gtk_widget_destroy (win);
}
- else {
- browser_connections_list_show (bwin->priv->bcnc);
- }
+ else
+ browser_connections_list_show (bwin->priv->tcnc);
}
static void
@@ -1190,28 +1123,26 @@ connection_bind_cb (G_GNUC_UNUSED GtkAction *action, BrowserWindow *bwin)
GtkWidget *win;
gint res;
- win = connection_binding_properties_new_create (bwin->priv->bcnc);
+ win = connection_binding_properties_new_create (bwin->priv->tcnc);
gtk_window_set_transient_for (GTK_WINDOW (win), GTK_WINDOW (bwin));
gtk_widget_show (win);
res = gtk_dialog_run (GTK_DIALOG (win));
gtk_widget_hide (win);
if (res == GTK_RESPONSE_OK) {
- BrowserConnection *bcnc;
+ TConnection *tcnc;
GError *error = NULL;
- bcnc = browser_virtual_connection_new (connection_binding_properties_get_specs
- (CONNECTION_BINDING_PROPERTIES (win)), &error);
- if (bcnc) {
+ tcnc = t_virtual_connection_new (connection_binding_properties_get_specs
+ (CONNECTION_BINDING_PROPERTIES (win)), &error);
+ if (tcnc) {
BrowserWindow *bwin;
- bwin = browser_window_new (bcnc, NULL);
-
- browser_core_take_window (bwin);
- browser_core_take_connection (bcnc);
+ bwin = browser_window_new (tcnc, NULL);
+ gtk_widget_show (GTK_WIDGET (bwin));
}
else {
- browser_show_error ((GtkWindow*) bwin,
- _("Could not open binding connection: %s"),
- error && error->message ? error->message : _("No detail"));
+ ui_show_error ((GtkWindow*) bwin,
+ _("Could not open binding connection: %s"),
+ error && error->message ? error->message : _("No detail"));
g_clear_error (&error);
}
}
@@ -1221,13 +1152,13 @@ connection_bind_cb (G_GNUC_UNUSED GtkAction *action, BrowserWindow *bwin)
static void
connection_list_cb (G_GNUC_UNUSED GtkAction *action, BrowserWindow *bwin)
{
- browser_connections_list_show (bwin->priv->bcnc);
+ browser_connections_list_show (bwin->priv->tcnc);
}
static void
connection_meta_update_cb (G_GNUC_UNUSED GtkAction *action, BrowserWindow *bwin)
{
- browser_connection_update_meta_data (bwin->priv->bcnc);
+ t_connection_update_meta_data (bwin->priv->tcnc);
}
static void
@@ -1244,15 +1175,12 @@ about_cb (G_GNUC_UNUSED GtkAction *action, BrowserWindow *bwin)
};
const gchar *translator_credits = "";
- gchar *path;
- path = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, "pixmaps", "gda-browser.png", NULL);
- icon = gdk_pixbuf_new_from_file (path, NULL);
- g_free (path);
+ icon = gdk_pixbuf_new_from_resource ("/images/gda-browser.png", NULL);
dialog = gtk_about_dialog_new ();
gtk_about_dialog_set_program_name (GTK_ABOUT_DIALOG (dialog), _("Database browser"));
gtk_about_dialog_set_version (GTK_ABOUT_DIALOG (dialog), PACKAGE_VERSION);
- gtk_about_dialog_set_copyright (GTK_ABOUT_DIALOG (dialog), "(C) 2009 - 2011 GNOME Foundation");
+ gtk_about_dialog_set_copyright (GTK_ABOUT_DIALOG (dialog), "(C) 2009 - 2014 GNOME Foundation");
gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG (dialog), _("Database access services for the GNOME
Desktop"));
gtk_about_dialog_set_license (GTK_ABOUT_DIALOG (dialog), "GNU General Public License");
gtk_about_dialog_set_website (GTK_ABOUT_DIALOG (dialog), "http://www.gnome-db.org");
@@ -1265,13 +1193,14 @@ about_cb (G_GNUC_UNUSED GtkAction *action, BrowserWindow *bwin)
dialog);
gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (bwin));
gtk_widget_show (dialog);
+ g_object_unref (icon);
}
#ifdef HAVE_GDU
void
manual_cb (G_GNUC_UNUSED GtkAction *action, BrowserWindow *bwin)
{
- browser_show_help (GTK_WINDOW (bwin), NULL);
+ ui_show_help (GTK_WINDOW (bwin), NULL);
}
#endif
@@ -1280,13 +1209,13 @@ manual_cb (G_GNUC_UNUSED GtkAction *action, BrowserWindow *bwin)
* browser_window_get_connection
* @bwin: a #BrowserWindow
*
- * Returns: the #BrowserConnection used in @bwin
+ * Returns: the #TConnection used in @bwin
*/
-BrowserConnection *
+TConnection *
browser_window_get_connection (BrowserWindow *bwin)
{
g_return_val_if_fail (BROWSER_IS_WINDOW (bwin), NULL);
- return bwin->priv->bcnc;
+ return bwin->priv->tcnc;
}
@@ -1295,7 +1224,7 @@ browser_window_get_connection (BrowserWindow *bwin)
* @bwin: a #BrowserWindow in which the perspective will be
* @factory: (allow-none): a #BrowserPerspectiveFactory, or %NULL
*
- * Creates a new #PerspectiveData structure, it increases @bcnc's reference count.
+ * Creates a new #PerspectiveData structure, it increases @tcnc's reference count.
*
* Returns: a new #PerspectiveData
*/
@@ -1308,7 +1237,7 @@ perspective_data_new (BrowserWindow *bwin, BrowserPerspectiveFactory *factory)
pers->bwin = NULL;
pers->factory = factory;
if (!pers->factory)
- pers->factory = browser_core_get_default_factory ();
+ pers->factory = browser_get_default_factory ();
pers->page_number = -1;
g_assert (pers->factory);
pers->perspective_widget = g_object_ref (pers->factory->perspective_create (bwin));
@@ -1713,7 +1642,7 @@ browser_window_change_perspective (BrowserWindow *bwin, const gchar *perspective
current_pdata = bwin->priv->current_perspective;
- bpf = browser_core_get_factory (perspective);
+ bpf = browser_get_factory (perspective);
if (!bpf)
return NULL;
GList *actions, *list;
diff --git a/tools/browser/browser-window.h b/tools/browser/browser-window.h
index 9c59021..a1a2c2b 100644
--- a/tools/browser/browser-window.h
+++ b/tools/browser/browser-window.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2009 - 2014 Vivien Malerba <malerba gnome-db org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -22,7 +22,8 @@
#include <gtk/gtk.h>
#include "decl.h"
-#include "browser-connection.h"
+#include <common/t-connection.h>
+#include "browser-perspective.h"
G_BEGIN_DECLS
@@ -31,20 +32,21 @@ G_BEGIN_DECLS
#define BROWSER_WINDOW_CLASS(klass) G_TYPE_CHECK_CLASS_CAST (klass, browser_window_get_type (),
BrowserWindowClass)
#define BROWSER_IS_WINDOW(obj) G_TYPE_CHECK_INSTANCE_TYPE (obj, browser_window_get_type ())
+typedef struct _BrowserWindow BrowserWindow;
typedef struct _BrowserWindowClass BrowserWindowClass;
typedef struct _BrowserWindowPrivate BrowserWindowPrivate;
/* struct for the object's data */
struct _BrowserWindow
{
- GtkWindow object;
+ GtkApplicationWindow object;
BrowserWindowPrivate *priv;
};
/* struct for the object's class */
struct _BrowserWindowClass
{
- GtkWindowClass parent_class;
+ GtkApplicationWindowClass parent_class;
/* signals */
void (*fullscreen_changed) (BrowserWindow *bwin, gboolean fullscreen);
@@ -62,8 +64,8 @@ struct _BrowserWindowClass
*/
GType browser_window_get_type (void) G_GNUC_CONST;
-BrowserWindow *browser_window_new (BrowserConnection *bcnc,
BrowserPerspectiveFactory *factory);
-BrowserConnection *browser_window_get_connection (BrowserWindow *bwin);
+BrowserWindow *browser_window_new (TConnection *tcnc, BrowserPerspectiveFactory
*factory);
+TConnection *browser_window_get_connection (BrowserWindow *bwin);
guint browser_window_push_status (BrowserWindow *bwin, const gchar *context,
const gchar *text, gboolean auto_clear);
diff --git a/tools/browser/connection-binding-properties.c b/tools/browser/connection-binding-properties.c
index a3304f2..6f7fd58 100644
--- a/tools/browser/connection-binding-properties.c
+++ b/tools/browser/connection-binding-properties.c
@@ -21,12 +21,15 @@
#include <string.h>
#include <glib/gi18n-lib.h>
#include "connection-binding-properties.h"
-#include "browser-connection.h"
-#include "support.h"
+#include <common/t-app.h>
+#include <common/t-connection.h>
+#include <common/t-errors.h>
+#include "ui-support.h"
#include <libgda-ui/libgda-ui.h>
#include <libgda-ui/gdaui-plugin.h>
-#include "common/gdaui-entry-import.h"
-#include "../tool-utils.h"
+#include "gdaui-entry-import.h"
+//#include "../tool-utils.h"
+
/*
* Main static functions
@@ -41,7 +44,7 @@ static void update_display (ConnectionBindingProperties *cprop);
struct _ConnectionBindingPropertiesPrivate
{
- BrowserVirtualConnectionSpecs *specs;
+ TVirtualConnectionSpecs *specs;
GtkGrid *layout_grid;
GtkWidget *menu;
};
@@ -49,6 +52,13 @@ struct _ConnectionBindingPropertiesPrivate
/* get a pointer to the parents to be able to call their destructor */
static GObjectClass *parent_class = NULL;
+enum
+{
+ CNC_LIST_COLUMN_TCNC = 0,
+ CNC_LIST_COLUMN_NAME = 1,
+ CNC_LIST_NUM_COLUMNS
+};
+
GType
connection_binding_properties_get_type (void)
{
@@ -104,7 +114,7 @@ connection_binding_properties_dispose (GObject *object)
if (cprop->priv) {
if (cprop->priv->specs)
- browser_virtual_connection_specs_free (cprop->priv->specs);
+ t_virtual_connection_specs_free (cprop->priv->specs);
if (cprop->priv->menu)
gtk_widget_destroy (cprop->priv->menu);
g_free (cprop->priv);
@@ -119,35 +129,35 @@ connection_binding_properties_dispose (GObject *object)
static void
help_clicked_cb (GtkButton *button, G_GNUC_UNUSED ConnectionBindingProperties *cprop)
{
- browser_show_help ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) button),
- "virtual-connections");
+ ui_show_help ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) button),
+ "virtual-connections");
g_signal_stop_emission_by_name (button, "clicked");
}
#endif
/**
* connection_binding_properties_new_create
- * @bcnc: a #BrowserConnection
+ * @tcnc: a #TConnection
*
* Creates a new #ConnectionBindingProperties window. The window will allow a new
- * virtual connection to be opened using tables from @bcnc.
+ * virtual connection to be opened using tables from @tcnc.
*
* Returns: the new object
*/
GtkWidget *
-connection_binding_properties_new_create (BrowserConnection *bcnc)
+connection_binding_properties_new_create (TConnection *tcnc)
{
ConnectionBindingProperties *cprop;
- BrowserVirtualConnectionSpecs *specs;
- BrowserVirtualConnectionPart *part;
+ TVirtualConnectionSpecs *specs;
+ TVirtualConnectionPart *part;
- g_return_val_if_fail (BROWSER_IS_CONNECTION (bcnc), NULL);
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
- specs = g_new0 (BrowserVirtualConnectionSpecs, 1);
- part = g_new0 (BrowserVirtualConnectionPart, 1);
- part->part_type = BROWSER_VIRTUAL_CONNECTION_PART_CNC;
- part->u.cnc.table_schema = g_strdup (browser_connection_get_name (bcnc));
- part->u.cnc.source_cnc = g_object_ref (G_OBJECT (bcnc));
+ specs = g_new0 (TVirtualConnectionSpecs, 1);
+ part = g_new0 (TVirtualConnectionPart, 1);
+ part->part_type = T_VIRTUAL_CONNECTION_PART_CNC;
+ part->u.cnc.table_schema = g_strdup (t_connection_get_name (tcnc));
+ part->u.cnc.source_cnc = g_object_ref (G_OBJECT (tcnc));
specs->parts = g_slist_append (NULL, part);
cprop = CONNECTION_BINDING_PROPERTIES (g_object_new (CONNECTION_TYPE_BINDING_PROPERTIES, NULL));
@@ -158,10 +168,10 @@ connection_binding_properties_new_create (BrowserConnection *bcnc)
update_display (cprop);
gtk_widget_show (gtk_dialog_add_button (GTK_DIALOG (cprop), _("Create connection"), GTK_RESPONSE_OK));
- gtk_widget_show (gtk_dialog_add_button (GTK_DIALOG (cprop), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL));
+ gtk_widget_show (gtk_dialog_add_button (GTK_DIALOG (cprop), _("_Cancel"), GTK_RESPONSE_CANCEL));
#ifdef HAVE_GDU
GtkWidget *help_btn;
- help_btn = gtk_button_new_from_stock (GTK_STOCK_HELP);
+ help_btn = gtk_button_new_from_icon_name (_("_Help"), GTK_ICON_SIZE_DIALOG);
g_signal_connect (help_btn, "clicked",
G_CALLBACK (help_clicked_cb), cprop);
gtk_widget_show (help_btn);
@@ -173,28 +183,28 @@ connection_binding_properties_new_create (BrowserConnection *bcnc)
/**
* connection_binding_properties_new_edit
- * @specs: a #BrowserVirtualConnectionSpecs pointer
+ * @specs: a #TVirtualConnectionSpecs pointer
*
* Creates a new #ConnectionBindingProperties window, starting with a _copy_ of @specs
*
* Returns: the new object
*/
GtkWidget *
-connection_binding_properties_new_edit (const BrowserVirtualConnectionSpecs *specs)
+connection_binding_properties_new_edit (const TVirtualConnectionSpecs *specs)
{
ConnectionBindingProperties *cprop;
g_return_val_if_fail (specs, NULL);
cprop = CONNECTION_BINDING_PROPERTIES (g_object_new (CONNECTION_TYPE_BINDING_PROPERTIES, NULL));
- cprop->priv->specs = browser_virtual_connection_specs_copy (specs);
+ cprop->priv->specs = t_virtual_connection_specs_copy (specs);
gtk_window_set_title (GTK_WINDOW (cprop), _("Virtual connection's properties"));
create_layout (cprop);
update_display (cprop);
- gtk_widget_show (gtk_dialog_add_button (GTK_DIALOG (cprop), GTK_STOCK_APPLY, GTK_RESPONSE_OK));
- gtk_widget_show (gtk_dialog_add_button (GTK_DIALOG (cprop), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL));
+ gtk_widget_show (gtk_dialog_add_button (GTK_DIALOG (cprop), _("_Apply"), GTK_RESPONSE_OK));
+ gtk_widget_show (gtk_dialog_add_button (GTK_DIALOG (cprop), _("_Cancel"), GTK_RESPONSE_CANCEL));
return (GtkWidget*) cprop;
}
@@ -238,10 +248,10 @@ create_layout (ConnectionBindingProperties *cprop)
}
static void add_part_clicked_cb (GtkWidget *button, ConnectionBindingProperties *cprop);
-static void del_part_clicked_cb (GtkWidget *button, BrowserVirtualConnectionPart *part);
+static void del_part_clicked_cb (GtkWidget *button, TVirtualConnectionPart *part);
-static GtkWidget *create_part_for_model (ConnectionBindingProperties *cprop, BrowserVirtualConnectionPart
*part, BrowserVirtualConnectionModel *pm);
-static GtkWidget *create_part_for_cnc (ConnectionBindingProperties *cprop, BrowserVirtualConnectionPart
*part, BrowserVirtualConnectionCnc *cnc);
+static GtkWidget *create_part_for_model (ConnectionBindingProperties *cprop, TVirtualConnectionPart *part,
TVirtualConnectionModel *pm);
+static GtkWidget *create_part_for_cnc (ConnectionBindingProperties *cprop, TVirtualConnectionPart *part,
TVirtualConnectionCnc *cnc);
static void
update_display (ConnectionBindingProperties *cprop)
@@ -255,15 +265,15 @@ update_display (ConnectionBindingProperties *cprop)
if (cprop->priv->specs) {
GSList *list;
for (list = cprop->priv->specs->parts; list; list = list->next, top++) {
- BrowserVirtualConnectionPart *part;
+ TVirtualConnectionPart *part;
GtkWidget *display = NULL;
- part = (BrowserVirtualConnectionPart*) list->data;
+ part = (TVirtualConnectionPart*) list->data;
switch (part->part_type) {
- case BROWSER_VIRTUAL_CONNECTION_PART_MODEL:
+ case T_VIRTUAL_CONNECTION_PART_MODEL:
display = create_part_for_model (cprop, part, &(part->u.model));
break;
- case BROWSER_VIRTUAL_CONNECTION_PART_CNC:
+ case T_VIRTUAL_CONNECTION_PART_CNC:
display = create_part_for_cnc (cprop, part, &(part->u.cnc));
break;
default:
@@ -277,7 +287,7 @@ update_display (ConnectionBindingProperties *cprop)
/* bottom button to add a part */
GtkWidget *arrow, *button;
button = gtk_button_new ();
- label = browser_make_tab_label_with_stock (_("Add binding"), GTK_STOCK_ADD, FALSE, NULL);
+ label = ui_make_tab_label_with_icon (_("Add binding"), "list-add", FALSE, NULL);
gtk_container_add (GTK_CONTAINER (button), label);
arrow = gtk_arrow_new (GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
gtk_box_pack_start (GTK_BOX (label), arrow, FALSE, FALSE, 0);
@@ -294,21 +304,21 @@ update_display (ConnectionBindingProperties *cprop)
static void
add_part_mitem_cb (GtkMenuItem *mitem, ConnectionBindingProperties *cprop)
{
- BrowserVirtualConnectionType part_type;
- BrowserVirtualConnectionPart *part;
+ TVirtualConnectionType part_type;
+ TVirtualConnectionPart *part;
part_type = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (mitem), "part-type"));
- part = g_new0 (BrowserVirtualConnectionPart, 1);
+ part = g_new0 (TVirtualConnectionPart, 1);
part->part_type = part_type;
switch (part_type) {
- case BROWSER_VIRTUAL_CONNECTION_PART_MODEL: {
- BrowserVirtualConnectionModel *pm;
+ case T_VIRTUAL_CONNECTION_PART_MODEL: {
+ TVirtualConnectionModel *pm;
pm = &(part->u.model);
pm->table_name = g_strdup ("tab");
break;
}
- case BROWSER_VIRTUAL_CONNECTION_PART_CNC: {
- BrowserVirtualConnectionCnc *scnc;
+ case T_VIRTUAL_CONNECTION_PART_CNC: {
+ TVirtualConnectionCnc *scnc;
scnc = &(part->u.cnc);
scnc->table_schema = g_strdup ("sub");
break;
@@ -329,13 +339,13 @@ add_part_clicked_cb (G_GNUC_UNUSED GtkWidget *button, ConnectionBindingPropertie
menu = gtk_menu_new ();
entry = gtk_menu_item_new_with_label (_("Bind a connection"));
g_object_set_data (G_OBJECT (entry), "part-type",
- GINT_TO_POINTER (BROWSER_VIRTUAL_CONNECTION_PART_CNC));
+ GINT_TO_POINTER (T_VIRTUAL_CONNECTION_PART_CNC));
g_signal_connect (G_OBJECT (entry), "activate", G_CALLBACK (add_part_mitem_cb), cprop);
gtk_widget_show (entry);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), entry);
entry = gtk_menu_item_new_with_label (_("Bind a data set"));
g_object_set_data (G_OBJECT (entry), "part-type",
- GINT_TO_POINTER (BROWSER_VIRTUAL_CONNECTION_PART_MODEL));
+ GINT_TO_POINTER (T_VIRTUAL_CONNECTION_PART_MODEL));
g_signal_connect (G_OBJECT (entry), "activate", G_CALLBACK (add_part_mitem_cb), cprop);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), entry);
gtk_widget_show (entry);
@@ -348,18 +358,18 @@ add_part_clicked_cb (G_GNUC_UNUSED GtkWidget *button, ConnectionBindingPropertie
}
static void
-del_part_clicked_cb (GtkWidget *button, BrowserVirtualConnectionPart *part)
+del_part_clicked_cb (GtkWidget *button, TVirtualConnectionPart *part)
{
ConnectionBindingProperties *cprop;
cprop = g_object_get_data (G_OBJECT (button), "cprop");
cprop->priv->specs->parts = g_slist_remove (cprop->priv->specs->parts, part);
- browser_virtual_connection_part_free (part);
+ t_virtual_connection_part_free (part);
update_display (cprop);
}
static void
-part_for_model_holder_changed_cb (GdaSet *set, GdaHolder *holder, BrowserVirtualConnectionModel *pm)
+part_for_model_holder_changed_cb (GdaSet *set, GdaHolder *holder, TVirtualConnectionModel *pm)
{
const gchar *hid;
const GValue *value;
@@ -395,7 +405,7 @@ plugin_entry_import_create_func (G_GNUC_UNUSED GdaDataHandler *handler, GType ty
}
static GtkWidget *
-create_part_for_model (ConnectionBindingProperties *cprop, BrowserVirtualConnectionPart *part,
BrowserVirtualConnectionModel *pm)
+create_part_for_model (ConnectionBindingProperties *cprop, TVirtualConnectionPart *part,
TVirtualConnectionModel *pm)
{
GtkWidget *hbox, *vbox, *label, *button;
gchar *str;
@@ -422,8 +432,8 @@ create_part_for_model (ConnectionBindingProperties *cprop, BrowserVirtualConnect
g_free (str);
gtk_widget_set_tooltip_text (label, _("Import a data set and make it appear as a table"));
gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
- button = browser_make_small_button (FALSE, FALSE, NULL, GTK_STOCK_REMOVE,
- _("Remove this bind"));
+ button = ui_make_small_button (FALSE, FALSE, NULL, "list-remove",
+ _("Remove this bind"));
gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 10);
g_signal_connect (button, "clicked",
G_CALLBACK (del_part_clicked_cb), part);
@@ -458,7 +468,7 @@ create_part_for_model (ConnectionBindingProperties *cprop, BrowserVirtualConnect
static GError *
part_for_cnc_validate_holder_change_cb (G_GNUC_UNUSED GdaSet *set, GdaHolder *holder, GValue *new_value,
- G_GNUC_UNUSED BrowserVirtualConnectionCnc *cnc)
+ G_GNUC_UNUSED TVirtualConnectionCnc *cnc)
{
const gchar *hid;
@@ -472,7 +482,7 @@ part_for_cnc_validate_holder_change_cb (G_GNUC_UNUSED GdaSet *set, GdaHolder *ho
if (((ptr == str) && ! g_ascii_isalpha (*ptr)) ||
((ptr != str) && (*ptr != '_') && !g_ascii_isalnum (*ptr))) {
GError *error = NULL;
- g_set_error (&error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (&error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
"%s", _("Invalid schema name"));
return error;
}
@@ -484,7 +494,7 @@ part_for_cnc_validate_holder_change_cb (G_GNUC_UNUSED GdaSet *set, GdaHolder *ho
}
static void
-part_for_cnc_holder_changed_cb (GdaSet *set, GdaHolder *holder, BrowserVirtualConnectionCnc *cnc)
+part_for_cnc_holder_changed_cb (GdaSet *set, GdaHolder *holder, TVirtualConnectionCnc *cnc)
{
const gchar *hid;
const GValue *value;
@@ -513,7 +523,7 @@ part_for_cnc_holder_changed_cb (GdaSet *set, GdaHolder *holder, BrowserVirtualCo
}
static GtkWidget *
-create_part_for_cnc (ConnectionBindingProperties *cprop, BrowserVirtualConnectionPart *part,
BrowserVirtualConnectionCnc *cnc)
+create_part_for_cnc (ConnectionBindingProperties *cprop, TVirtualConnectionPart *part, TVirtualConnectionCnc
*cnc)
{
GtkWidget *hbox, *vbox, *label, *button;
gchar *str;
@@ -532,8 +542,8 @@ create_part_for_cnc (ConnectionBindingProperties *cprop, BrowserVirtualConnectio
"schema as a prefix"));
gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0);
- button = browser_make_small_button (FALSE, FALSE, NULL, GTK_STOCK_REMOVE,
- _("Remove this bind"));
+ button = ui_make_small_button (FALSE, FALSE, NULL, "list-remove",
+ _("Remove this bind"));
gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 10);
g_signal_connect (button, "clicked",
G_CALLBACK (del_part_clicked_cb), part);
@@ -546,16 +556,16 @@ create_part_for_cnc (ConnectionBindingProperties *cprop, BrowserVirtualConnectio
set = gda_set_new_inline (1,
"SCHEMA", G_TYPE_STRING, cnc->table_schema);
- holder = gda_holder_new (BROWSER_TYPE_CONNECTION);
+ holder = gda_holder_new (T_TYPE_CONNECTION);
g_object_set (holder, "id", "CNC", "name", "Connection", "not-null", TRUE, NULL);
g_assert (gda_set_add_holder (set, holder));
- g_value_set_object ((value = gda_value_new (BROWSER_TYPE_CONNECTION)), cnc->source_cnc);
+ g_value_set_object ((value = gda_value_new (T_TYPE_CONNECTION)), cnc->source_cnc);
g_assert (gda_holder_set_value (holder, value, NULL));
gda_value_free (value);
- g_assert (gda_holder_set_source_model (holder, browser_get_connections_list (),
- CNC_LIST_COLUMN_BCNC, NULL));
+ g_assert (gda_holder_set_source_model (holder, t_app_get_all_connections_m (),
+ CNC_LIST_COLUMN_TCNC, NULL));
g_object_unref (holder);
holder = gda_set_get_holder (set, "SCHEMA");
@@ -585,11 +595,11 @@ update_buttons_sensitiveness (ConnectionBindingProperties *cprop)
goto out;
for (list = cprop->priv->specs->parts; list; list = list->next) {
- BrowserVirtualConnectionPart *part;
- part = (BrowserVirtualConnectionPart*) list->data;
+ TVirtualConnectionPart *part;
+ part = (TVirtualConnectionPart*) list->data;
switch (part->part_type) {
- case BROWSER_VIRTUAL_CONNECTION_PART_MODEL: {
- BrowserVirtualConnectionModel *pm;
+ case T_VIRTUAL_CONNECTION_PART_MODEL: {
+ TVirtualConnectionModel *pm;
pm = &(part->u.model);
if (!pm->table_name || ! *pm->table_name || !pm->model)
goto out;
@@ -598,8 +608,8 @@ update_buttons_sensitiveness (ConnectionBindingProperties *cprop)
g_hash_table_insert (schemas_hash, pm->table_name, (gpointer) 0x01);
break;
}
- case BROWSER_VIRTUAL_CONNECTION_PART_CNC: {
- BrowserVirtualConnectionCnc *cnc;
+ case T_VIRTUAL_CONNECTION_PART_CNC: {
+ TVirtualConnectionCnc *cnc;
cnc = &(part->u.cnc);
if (! cnc->source_cnc || ! cnc->table_schema || ! *cnc->table_schema)
goto out;
@@ -623,9 +633,9 @@ update_buttons_sensitiveness (ConnectionBindingProperties *cprop)
* connection_binding_properties_get_specs
* @prop: a #ConnectionBindingProperties widget
*
- * Returns: a pointer to a read only #BrowserVirtualConnectionSpecs
+ * Returns: a pointer to a read only #TVirtualConnectionSpecs
*/
-const BrowserVirtualConnectionSpecs *
+const TVirtualConnectionSpecs *
connection_binding_properties_get_specs (ConnectionBindingProperties *prop)
{
g_return_val_if_fail (CONNECTION_IS_BINDING_PROPERTIES (prop), NULL);
diff --git a/tools/browser/connection-binding-properties.h b/tools/browser/connection-binding-properties.h
index 922bce0..c6508bb 100644
--- a/tools/browser/connection-binding-properties.h
+++ b/tools/browser/connection-binding-properties.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2009 - 2014 Vivien Malerba <malerba gnome-db org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -21,7 +21,7 @@
#define __CONNECTION_BINDING_PROPERTIES_H_
#include <gtk/gtk.h>
-#include "browser-virtual-connection.h"
+#include <common/t-virtual-connection.h>
#include "decl.h"
G_BEGIN_DECLS
@@ -49,11 +49,11 @@ struct _ConnectionBindingPropertiesClass
};
GType connection_binding_properties_get_type (void) G_GNUC_CONST;
-GtkWidget *connection_binding_properties_new_create (BrowserConnection *bcnc);
+GtkWidget *connection_binding_properties_new_create (TConnection *tcnc);
-GtkWidget *connection_binding_properties_new_edit (const BrowserVirtualConnectionSpecs
*specs);
+GtkWidget *connection_binding_properties_new_edit (const TVirtualConnectionSpecs *specs);
-const BrowserVirtualConnectionSpecs *connection_binding_properties_get_specs (ConnectionBindingProperties
*prop);
+const TVirtualConnectionSpecs *connection_binding_properties_get_specs (ConnectionBindingProperties *prop);
G_END_DECLS
diff --git a/tools/browser/data-manager/.gitignore b/tools/browser/data-manager/.gitignore
new file mode 100644
index 0000000..09dadef
--- /dev/null
+++ b/tools/browser/data-manager/.gitignore
@@ -0,0 +1 @@
+marshal.[ch]
diff --git a/tools/browser/data-manager/Makefile.am b/tools/browser/data-manager/Makefile.am
index a2bd6ca..33a21af 100644
--- a/tools/browser/data-manager/Makefile.am
+++ b/tools/browser/data-manager/Makefile.am
@@ -1,10 +1,12 @@
noinst_LTLIBRARIES = libperspective.la
AM_CPPFLAGS = \
+ -I$(top_srcdir)/tools \
-I$(top_srcdir)/tools/browser \
-I$(top_builddir) \
-I$(top_srcdir) \
-I$(top_srcdir)/libgda \
+ -I$(top_srcdir)/libgda/sqlite \
$(COREDEPS_CFLAGS) \
$(COREDEPS_WFLAGS) \
$(GTK_CFLAGS) \
@@ -17,36 +19,38 @@ marshal.c: marshal.list $(GLIB_GENMARSHAL) marshal.h
$(GLIB_GENMARSHAL) $< --body --prefix=_dm_marshal > $@
libperspective_la_SOURCES = \
+ marshal.c \
+ marshal.h \
analyser.c \
analyser.h \
- marshal.c \
- marshal.h \
- data-console.h \
data-console.c \
- data-source.h \
- data-source.c \
- data-widget.h \
- data-widget.c \
+ data-console.h \
data-favorite-selector.c \
data-favorite-selector.h \
+ data-manager-perspective.c \
+ data-manager-perspective.h \
+ data-source.c \
+ data-source-editor.c \
+ data-source-editor.h \
+ data-source.h \
+ data-source-manager.c \
+ data-source-manager.h \
+ data-widget.c \
+ data-widget.h \
perspective-main.c \
perspective-main.h \
- xml-spec-editor.c \
- xml-spec-editor.h \
ui-spec-editor.c \
ui-spec-editor.h \
- data-manager-perspective.h \
- data-manager-perspective.c \
- data-source-editor.h \
- data-source-editor.c \
- data-source-manager.h \
- data-source-manager.c
+ xml-spec-editor.c \
+ xml-spec-editor.h
+
$(OBJECTS): marshal.c marshal.h
EXTRA_DIST= \
- marshal.list
+ $(langspec_DATA) \
+ marshal.list
CLEANFILES = \
- marshal.h \
- marshal.c
+ marshal.h \
+ marshal.c
diff --git a/tools/browser/data-manager/analyser.c b/tools/browser/data-manager/analyser.c
index 33a0648..59c740b 100644
--- a/tools/browser/data-manager/analyser.c
+++ b/tools/browser/data-manager/analyser.c
@@ -43,13 +43,13 @@ data_manager_add_proposals_to_menu (GtkWidget *menu,
if (gda_statement_get_statement_type (stmt) == GDA_SQL_STATEMENT_SELECT) {
GSList *fields = NULL, *flist;
GdaSqlStatement *sql_statement;
- BrowserConnection *bcnc;
+ TConnection *tcnc;
GHashTable *hash; /* key = a menu string, value= 0x1 */
g_object_get (G_OBJECT (stmt), "structure", &sql_statement, NULL);
- bcnc = data_source_manager_get_browser_cnc (mgr);
- if (browser_connection_check_sql_statement_validify (bcnc, sql_statement, NULL))
+ tcnc = data_source_manager_get_browser_cnc (mgr);
+ if (t_connection_check_sql_statement_validify (tcnc, sql_statement, NULL))
fields = ((GdaSqlStatementSelect *) sql_statement->contents)->expr_list;
hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
@@ -257,11 +257,11 @@ add_data_source_mitem_activated_cb (GtkMenuItem *mitem, DataSourceManager *mgr)
DataSource *source;
GError *lerror = NULL;
xmlNodePtr sourcespec;
- BrowserConnection *bcnc;
+ TConnection *tcnc;
- bcnc = data_source_manager_get_browser_cnc (mgr);
+ tcnc = data_source_manager_get_browser_cnc (mgr);
sourcespec = (xmlNodePtr) g_object_get_data ((GObject*) mitem, "xml");
- source = data_source_new_from_xml_node (bcnc, sourcespec, &lerror);
+ source = data_source_new_from_xml_node (tcnc, sourcespec, &lerror);
if (source) {
data_source_manager_add_source (mgr, source);
g_object_unref (source);
diff --git a/tools/browser/data-manager/data-console.c b/tools/browser/data-manager/data-console.c
index 2b56292..6e8cb80 100644
--- a/tools/browser/data-manager/data-console.c
+++ b/tools/browser/data-manager/data-console.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2010 David King <davidk openismus com>
- * Copyright (C) 2010 - 2012 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2010 - 2014 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
*
* This program is free software; you can redistribute it and/or
@@ -25,12 +25,11 @@
#include "xml-spec-editor.h"
#include "ui-spec-editor.h"
#include "../dnd.h"
-#include "../support.h"
+#include "../ui-support.h"
#include "../gdaui-bar.h"
#include "../browser-window.h"
#include "../browser-page.h"
#include "../browser-perspective.h"
-#include "../browser-stock-icons.h"
#include <libgda-ui/internal/popup-container.h>
#include <libgda/sql-parser/gda-sql-parser.h>
#include <libgda-ui/libgda-ui.h>
@@ -38,6 +37,8 @@
#include <gdk/gdkkeysyms.h>
#include "analyser.h"
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+
#define MAIN_PAGE_EDITORS 0
#define MAIN_PAGE_DATA 1
@@ -54,7 +55,7 @@ struct _DataConsolePrivate {
GdauiBar *header;
LayoutType layout_type;
- BrowserConnection *bcnc;
+ TConnection *tcnc;
GtkWidget *main_notebook; /* 2 pages: MAIN_PAGE_EDITORS & MAIN_PAGE_DATA */
GtkWidget *editors_notebook; /* 2 pages: EDITOR_PAGE_XML & EDITOR_PAGE_UI */
@@ -194,8 +195,8 @@ data_console_dispose (GObject *object)
gtk_widget_destroy (dconsole->priv->params_form);
if (dconsole->priv->popup_container)
gtk_widget_destroy (dconsole->priv->popup_container);
- if (dconsole->priv->bcnc)
- g_object_unref (dconsole->priv->bcnc);
+ if (dconsole->priv->tcnc)
+ g_object_unref (dconsole->priv->tcnc);
if (dconsole->priv->agroup)
g_object_unref (dconsole->priv->agroup);
if (dconsole->priv->mgr) {
@@ -251,10 +252,10 @@ data_console_get_type (void)
* Returns: a new #GtkWidget
*/
GtkWidget *
-data_console_new_with_fav_id (BrowserConnection *bcnc, gint fav_id)
+data_console_new_with_fav_id (TConnection *tcnc, gint fav_id)
{
GtkWidget *dconsole;
- dconsole = data_console_new (bcnc);
+ dconsole = data_console_new (tcnc);
data_console_set_fav_id (DATA_CONSOLE (dconsole), fav_id, NULL);
return dconsole;
@@ -276,16 +277,16 @@ static void save_clicked_cb (GtkWidget *button, DataConsole *dconsole);
* Returns: a new #GtkWidget
*/
GtkWidget *
-data_console_new (BrowserConnection *bcnc)
+data_console_new (TConnection *tcnc)
{
DataConsole *dconsole;
- g_return_val_if_fail (BROWSER_IS_CONNECTION (bcnc), NULL);
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
dconsole = DATA_CONSOLE (g_object_new (DATA_CONSOLE_TYPE, NULL));
- dconsole->priv->bcnc = g_object_ref (bcnc);
- dconsole->priv->mgr = data_source_manager_new (bcnc);
+ dconsole->priv->tcnc = g_object_ref (tcnc);
+ dconsole->priv->mgr = data_source_manager_new (tcnc);
g_signal_connect (dconsole->priv->mgr, "list-changed",
G_CALLBACK (data_source_mgr_changed_cb), dconsole);
g_signal_connect (dconsole->priv->mgr, "source-changed",
@@ -305,7 +306,7 @@ data_console_new (BrowserConnection *bcnc)
gtk_widget_show (label);
dconsole->priv->header = GDAUI_BAR (label);
- wid = gdaui_bar_add_button_from_stock (GDAUI_BAR (label), GTK_STOCK_SAVE);
+ wid = gdaui_bar_add_button_from_icon_name (GDAUI_BAR (label), "document-save");
dconsole->priv->save_button = wid;
g_signal_connect (wid, "clicked",
@@ -383,41 +384,41 @@ data_console_new (BrowserConnection *bcnc)
gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_END);
gtk_box_pack_start (GTK_BOX (hbox), bbox, FALSE, FALSE, 5);
- button = browser_make_small_button (FALSE, FALSE, _("Reset"), GTK_STOCK_CLEAR,
- _("Reset the editor's\ncontents"));
+ button = ui_make_small_button (FALSE, FALSE, _("Reset"), "edit-clear",
+ _("Reset the editor's\ncontents"));
dconsole->priv->clear_xml_button = button;
gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0);
g_signal_connect (button, "clicked",
G_CALLBACK (editor_clear_clicked_cb), dconsole);
- button = browser_make_small_button (FALSE, TRUE, _("Add"), GTK_STOCK_ADD,
- _("Add a new data source"));
+ button = ui_make_small_button (FALSE, TRUE, _("Add"), "list-add",
+ _("Add a new data source"));
dconsole->priv->add_source_button = button;
gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0);
g_signal_connect (button, "clicked",
G_CALLBACK (add_source_clicked_cb), dconsole);
- button = browser_make_small_button (TRUE, FALSE, _("Variables"), NULL, _("Show variables needed"));
+ button = ui_make_small_button (TRUE, FALSE, _("Variables"), NULL, _("Show variables needed"));
gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0);
dconsole->priv->params_toggle = GTK_TOGGLE_BUTTON (button);
g_signal_connect (button, "toggled",
G_CALLBACK (variables_clicked_cb), dconsole);
- button = browser_make_small_button (FALSE, FALSE, _("Execute"), GTK_STOCK_EXECUTE, _("Execute
specified\n"
- "data manager"));
+ button = ui_make_small_button (FALSE, FALSE, _("Execute"), "system-run",
+ _("Execute specified\ndata manager"));
gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0);
g_signal_connect (button, "clicked",
G_CALLBACK (execute_clicked_cb), dconsole);
- button = browser_make_small_button (TRUE, FALSE, _("View XML"), NULL, _("View specifications\n"
- "as XML (advanced)"));
+ button = ui_make_small_button (TRUE, FALSE, _("View XML"), NULL,
+ _("View specifications\nas XML (advanced)"));
gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0);
spec_editor_toggled_cb (GTK_TOGGLE_BUTTON (button), dconsole);
g_signal_connect (button, "toggled",
G_CALLBACK (spec_editor_toggled_cb), dconsole);
#ifdef HAVE_GDU
- button = browser_make_small_button (FALSE, FALSE, _("Help"), GTK_STOCK_HELP, _("Help"));
+ button = ui_make_small_button (FALSE, FALSE, _("Help"), "help-browser", _("Help"));
gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0);
g_signal_connect (button, "clicked",
G_CALLBACK (help_clicked_cb), dconsole);
@@ -496,11 +497,11 @@ void
data_console_set_fav_id (DataConsole *dconsole, gint fav_id, GError **error)
{
g_return_if_fail (IS_DATA_CONSOLE (dconsole));
- ToolsFavoritesAttributes fav;
+ TFavoritesAttributes fav;
if ((fav_id >=0) &&
- gda_tools_favorites_get (browser_connection_get_favorites (dconsole->priv->bcnc),
- fav_id, &fav, error)) {
+ t_favorites_get (t_connection_get_favorites (dconsole->priv->tcnc),
+ fav_id, &fav, error)) {
gchar *str, *tmp;
tmp = g_markup_printf_escaped (_("'%s' data manager"), fav.name);
str = g_strdup_printf ("<b>%s</b>\n%s", _("Data manager"), tmp);
@@ -510,7 +511,7 @@ data_console_set_fav_id (DataConsole *dconsole, gint fav_id, GError **error)
dconsole->priv->fav_id = fav.id;
- gda_tools_favorites_reset_attributes (&fav);
+ t_favorites_reset_attributes (&fav);
}
else {
gchar *str;
@@ -538,34 +539,34 @@ real_save_clicked_cb (GtkWidget *button, DataConsole *dconsole)
str = xml_spec_editor_get_xml_text (XML_SPEC_EDITOR (dconsole->priv->xml_sped));
GError *lerror = NULL;
- ToolsFavorites *bfav;
- ToolsFavoritesAttributes fav;
-
- memset (&fav, 0, sizeof (ToolsFavoritesAttributes));
- fav.id = dconsole->priv->fav_id;
- fav.type = GDA_TOOLS_FAVORITES_DATA_MANAGERS;
- fav.name = gtk_editable_get_chars (GTK_EDITABLE (dconsole->priv->name_entry), 0, -1);
- if (!*fav.name) {
- g_free (fav.name);
- fav.name = g_strdup (_("Data manager"));
+ TFavorites *bfav;
+ TFavoritesAttributes favatt;
+
+ memset (&favatt, 0, sizeof (TFavoritesAttributes));
+ favatt.id = dconsole->priv->fav_id;
+ favatt.type = T_FAVORITES_DATA_MANAGERS;
+ favatt.name = gtk_editable_get_chars (GTK_EDITABLE (dconsole->priv->name_entry), 0, -1);
+ if (!*favatt.name) {
+ g_free (favatt.name);
+ favatt.name = g_strdup (_("Data manager"));
}
- fav.contents = str;
+ favatt.contents = str;
gtk_widget_hide (dconsole->priv->popup_container);
- bfav = browser_connection_get_favorites (dconsole->priv->bcnc);
- if (! gda_tools_favorites_add (bfav, 0, &fav, ORDER_KEY_DATA_MANAGERS, G_MAXINT, &lerror)) {
- browser_show_error ((GtkWindow*) gtk_widget_get_toplevel (button),
- "<b>%s:</b>\n%s",
- _("Could not save data manager"),
- lerror && lerror->message ? lerror->message : _("No detail"));
+ bfav = t_connection_get_favorites (dconsole->priv->tcnc);
+ if (! t_favorites_add (bfav, 0, &favatt, ORDER_KEY_DATA_MANAGERS, G_MAXINT, &lerror)) {
+ ui_show_error ((GtkWindow*) gtk_widget_get_toplevel (button),
+ "<b>%s:</b>\n%s",
+ _("Could not save data manager"),
+ lerror && lerror->message ? lerror->message : _("No detail"));
if (lerror)
g_error_free (lerror);
}
- data_console_set_fav_id (dconsole, fav.id, NULL);
+ data_console_set_fav_id (dconsole, favatt.id, NULL);
- g_free (fav.name);
+ g_free (favatt.name);
g_free (str);
}
@@ -592,11 +593,11 @@ save_clicked_cb (GtkWidget *button, DataConsole *dconsole)
gtk_box_pack_start (GTK_BOX (hbox), wid, FALSE, FALSE, 5);
dconsole->priv->name_entry = wid;
if (dconsole->priv->fav_id > 0) {
- ToolsFavoritesAttributes fav;
- if (gda_tools_favorites_get (browser_connection_get_favorites (dconsole->priv->bcnc),
- dconsole->priv->fav_id, &fav, NULL)) {
+ TFavoritesAttributes fav;
+ if (t_favorites_get (t_connection_get_favorites (dconsole->priv->tcnc),
+ dconsole->priv->fav_id, &fav, NULL)) {
gtk_entry_set_text (GTK_ENTRY (wid), fav.name);
- gda_tools_favorites_reset_attributes (&fav);
+ t_favorites_reset_attributes (&fav);
}
}
@@ -625,8 +626,8 @@ execute_clicked_cb (G_GNUC_UNUSED GtkButton *button, DataConsole *dconsole)
static void
help_clicked_cb (G_GNUC_UNUSED GtkButton *button, DataConsole *dconsole)
{
- browser_show_help ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) dconsole),
- "data-manager-perspective");
+ ui_show_help ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) dconsole),
+ "data-manager-perspective");
}
#endif
@@ -720,7 +721,7 @@ add_source_mitem_activated_cb (GtkMenuItem *mitem, DataConsole *dconsole)
table = (gchar*) g_object_get_data ((GObject*) mitem, "_table");
- source = data_source_new (dconsole->priv->bcnc, DATA_SOURCE_UNKNOWN);
+ source = data_source_new (dconsole->priv->tcnc, DATA_SOURCE_UNKNOWN);
list = (GSList*) data_source_manager_get_sources (dconsole->priv->mgr);
str = g_strdup_printf (_("source%d"), g_slist_length (list) + 1);
data_source_set_id (source, str);
@@ -750,7 +751,7 @@ add_source_clicked_cb (G_GNUC_UNUSED GtkButton *button, DataConsole *dconsole)
GdaMetaStruct *mstruct;
DataSource *current_source;
- mstruct = browser_connection_get_meta_struct (dconsole->priv->bcnc);
+ mstruct = t_connection_get_meta_struct (dconsole->priv->tcnc);
current_source = ui_spec_editor_get_selected_source (UI_SPEC_EDITOR (dconsole->priv->ui_sped));
/* remove customization, if any */
@@ -920,7 +921,7 @@ compose_mode_toggled_cb (G_GNUC_UNUSED GtkToggleAction *action, DataConsole *dco
}
static GtkToggleActionEntry ui_actions[] = {
- { "ComposeMode", BROWSER_STOCK_BUILDER, N_("_Toggle mode"), NULL, N_("Switch between compose and
execute modes"),
+ { "ComposeMode", NULL /*BROWSER_STOCK_BUILDER*/, N_("_Toggle mode"), NULL, N_("Switch between compose
and execute modes"),
G_CALLBACK (compose_mode_toggled_cb), TRUE},
};
static const gchar *ui_actions_console =
@@ -964,9 +965,9 @@ data_console_page_get_tab_label (BrowserPage *page, GtkWidget **out_close_button
const gchar *tab_name;
tab_name = _("Data manager");
- return browser_make_tab_label_with_stock (tab_name,
- STOCK_CONSOLE,
- out_close_button ? TRUE : FALSE, out_close_button);
+ return ui_make_tab_label_with_icon (tab_name,
+ NULL,
+ out_close_button ? TRUE : FALSE, out_close_button);
}
/**
diff --git a/tools/browser/data-manager/data-console.h b/tools/browser/data-manager/data-console.h
index efc1031..91bb8d2 100644
--- a/tools/browser/data-manager/data-console.h
+++ b/tools/browser/data-manager/data-console.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2010 - 2014 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
*
* This program is free software; you can redistribute it and/or
@@ -21,7 +21,7 @@
#define __DATA_CONSOLE_H__
#include <gtk/gtk.h>
-#include "../browser-connection.h"
+#include "common/t-connection.h"
G_BEGIN_DECLS
@@ -46,8 +46,8 @@ struct _DataConsoleClass {
GType data_console_get_type (void) G_GNUC_CONST;
-GtkWidget *data_console_new (BrowserConnection *bcnc);
-GtkWidget *data_console_new_with_fav_id (BrowserConnection *bcnc, gint fav_id);
+GtkWidget *data_console_new (TConnection *tcnc);
+GtkWidget *data_console_new_with_fav_id (TConnection *tcnc, gint fav_id);
void data_console_set_text (DataConsole *console, const gchar *text);
gchar *data_console_get_text (DataConsole *console);
gboolean data_console_is_unused (DataConsole *console);
diff --git a/tools/browser/data-manager/data-favorite-selector.c
b/tools/browser/data-manager/data-favorite-selector.c
index d472fd5..2e68ea3 100644
--- a/tools/browser/data-manager/data-favorite-selector.c
+++ b/tools/browser/data-manager/data-favorite-selector.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 - 2012 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2009 - 2014 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2010 David King <davidk openismus com>
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
*
@@ -26,7 +26,7 @@
#include "../mgr-favorites.h"
#include <libgda-ui/gdaui-tree-store.h>
#include "../dnd.h"
-#include "../support.h"
+#include "../ui-support.h"
#include "marshal.h"
#include "../gdaui-bar.h"
#include <gdk/gdkkeysyms.h>
@@ -44,8 +44,10 @@
#include <gtksourceview/gtksourcestylescheme.h>
#endif
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+
struct _DataFavoriteSelectorPrivate {
- BrowserConnection *bcnc;
+ TConnection *tcnc;
GdaTree *tree;
GtkWidget *treeview;
guint idle_update_favorites;
@@ -64,7 +66,7 @@ static void data_favorite_selector_init (DataFavoriteSelector *tsel,
DataFavoriteSelectorClass *klass);
static void data_favorite_selector_dispose (GObject *object);
-static void favorites_changed_cb (ToolsFavorites *bfav, DataFavoriteSelector *tsel);
+static void favorites_changed_cb (TFavorites *bfav, DataFavoriteSelector *tsel);
enum {
SELECTION_CHANGED,
@@ -133,10 +135,10 @@ data_favorite_selector_dispose (GObject *object)
if (tsel->priv->tree)
g_object_unref (tsel->priv->tree);
- if (tsel->priv->bcnc) {
- g_signal_handlers_disconnect_by_func (browser_connection_get_favorites
(tsel->priv->bcnc),
+ if (tsel->priv->tcnc) {
+ g_signal_handlers_disconnect_by_func (t_connection_get_favorites (tsel->priv->tcnc),
G_CALLBACK (favorites_changed_cb), tsel);
- g_object_unref (tsel->priv->bcnc);
+ g_object_unref (tsel->priv->tcnc);
}
if (tsel->priv->popup_properties)
@@ -187,18 +189,18 @@ key_press_event_cb (GtkTreeView *treeview, GdkEventKey *event, DataFavoriteSelec
select = gtk_tree_view_get_selection (treeview);
if (gtk_tree_selection_get_selected (select, &model, &iter)) {
- ToolsFavorites *bfav;
- ToolsFavoritesAttributes fav;
+ TFavorites *bfav;
+ TFavoritesAttributes favatt;
GError *lerror = NULL;
- memset (&fav, 0, sizeof (ToolsFavoritesAttributes));
+ memset (&favatt, 0, sizeof (TFavoritesAttributes));
gtk_tree_model_get (model, &iter,
- COLUMN_ID, &(fav.id), -1);
- bfav = browser_connection_get_favorites (tsel->priv->bcnc);
- if (!gda_tools_favorites_delete (bfav, 0, &fav, NULL)) {
- browser_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*)tsel),
- _("Could not remove favorite: %s"),
- lerror && lerror->message ? lerror->message : _("No
detail"));
+ COLUMN_ID, &(favatt.id), -1);
+ bfav = t_connection_get_favorites (tsel->priv->tcnc);
+ if (!t_favorites_delete (bfav, 0, &favatt, NULL)) {
+ ui_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*)tsel),
+ _("Could not remove favorite: %s"),
+ lerror && lerror->message ? lerror->message : _("No detail"));
if (lerror)
g_error_free (lerror);
}
@@ -235,33 +237,33 @@ selection_changed_cb (GtkTreeView *treeview, G_GNUC_UNUSED GtkTreePath *path,
static gboolean
prop_save_timeout (DataFavoriteSelector *tsel)
{
- ToolsFavorites *bfav;
- ToolsFavoritesAttributes fav;
+ TFavorites *bfav;
+ TFavoritesAttributes favatt;
GError *error = NULL;
- memset (&fav, 0, sizeof (ToolsFavoritesAttributes));
- fav.id = tsel->priv->properties_id;
- fav.type = GDA_TOOLS_FAVORITES_DATA_MANAGERS;
- fav.name = (gchar*) gtk_entry_get_text (GTK_ENTRY (tsel->priv->properties_name));
- fav.descr = NULL;
+ memset (&favatt, 0, sizeof (TFavoritesAttributes));
+ favatt.id = tsel->priv->properties_id;
+ favatt.type = T_FAVORITES_DATA_MANAGERS;
+ favatt.name = (gchar*) gtk_entry_get_text (GTK_ENTRY (tsel->priv->properties_name));
+ favatt.descr = NULL;
GtkTextBuffer *buffer;
GtkTextIter start, end;
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (tsel->priv->properties_text));
gtk_text_buffer_get_start_iter (buffer, &start);
gtk_text_buffer_get_end_iter (buffer, &end);
- fav.contents = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
+ favatt.contents = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
- bfav = browser_connection_get_favorites (tsel->priv->bcnc);
- if (! gda_tools_favorites_add (bfav, 0, &fav, ORDER_KEY_DATA_MANAGERS,
tsel->priv->properties_position, &error)) {
- browser_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) tsel),
- _("Could not add favorite: %s"),
- error && error->message ? error->message : _("No detail"));
+ bfav = t_connection_get_favorites (tsel->priv->tcnc);
+ if (! t_favorites_add (bfav, 0, &favatt, ORDER_KEY_DATA_MANAGERS, tsel->priv->properties_position,
&error)) {
+ ui_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) tsel),
+ _("Could not add favorite: %s"),
+ error && error->message ? error->message : _("No detail"));
if (error)
g_error_free (error);
}
- g_free (fav.contents);
+ g_free (favatt.contents);
tsel->priv->prop_save_timeout = 0;
return FALSE; /* remove timeout */
}
@@ -395,7 +397,7 @@ do_popup_menu (G_GNUC_UNUSED GtkWidget *widget, GdkEventButton *event, DataFavor
g_signal_connect (menu, "deactivate",
G_CALLBACK (gtk_widget_hide), NULL);
- mitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_PROPERTIES, NULL);
+ mitem = gtk_menu_item_new_with_label (_("_Properties"));
gtk_menu_shell_append (GTK_MENU_SHELL (menu), mitem);
gtk_widget_show (mitem);
g_signal_connect (mitem, "activate",
@@ -452,21 +454,21 @@ static gboolean tree_store_drag_get_cb (GdauiTreeStore *store, const gchar *path
* Returns: a new #GtkWidget
*/
GtkWidget *
-data_favorite_selector_new (BrowserConnection *bcnc)
+data_favorite_selector_new (TConnection *tcnc)
{
DataFavoriteSelector *tsel;
GdaTreeManager *manager;
- g_return_val_if_fail (BROWSER_IS_CONNECTION (bcnc), NULL);
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
tsel = DATA_FAVORITE_SELECTOR (g_object_new (DATA_FAVORITE_SELECTOR_TYPE, NULL));
- tsel->priv->bcnc = g_object_ref (bcnc);
- g_signal_connect (browser_connection_get_favorites (tsel->priv->bcnc), "favorites-changed",
+ tsel->priv->tcnc = g_object_ref (tcnc);
+ g_signal_connect (t_connection_get_favorites (tsel->priv->tcnc), "favorites-changed",
G_CALLBACK (favorites_changed_cb), tsel);
/* create tree managers */
tsel->priv->tree = gda_tree_new ();
- manager = mgr_favorites_new (bcnc, GDA_TOOLS_FAVORITES_DATA_MANAGERS, ORDER_KEY_DATA_MANAGERS);
+ manager = mgr_favorites_new (tcnc, T_FAVORITES_DATA_MANAGERS, ORDER_KEY_DATA_MANAGERS);
gda_tree_add_manager (tsel->priv->tree, manager);
g_object_unref (manager);
@@ -482,7 +484,7 @@ data_favorite_selector_new (BrowserConnection *bcnc)
str = g_strdup_printf ("<b>%s</b>", _("Saved"));
label = gdaui_bar_new (str);
g_free (str);
- gdaui_bar_set_icon_from_pixbuf (GDAUI_BAR (label), browser_get_pixbuf_icon (BROWSER_ICON_BOOKMARK));
+ gdaui_bar_set_icon_from_pixbuf (GDAUI_BAR (label), ui_get_pixbuf_icon (UI_ICON_BOOKMARK));
gtk_box_pack_start (GTK_BOX (tsel), label, FALSE, FALSE, 0);
gtk_widget_show (label);
@@ -499,7 +501,7 @@ data_favorite_selector_new (BrowserConnection *bcnc)
G_TYPE_UINT, MGR_FAVORITES_TYPE_ATT_NAME,
G_TYPE_INT, MGR_FAVORITES_ID_ATT_NAME,
G_TYPE_STRING, MGR_FAVORITES_NAME_ATT_NAME);
- treeview = browser_make_tree_view (model);
+ treeview = ui_make_tree_view (model);
tsel->priv->treeview = treeview;
g_object_unref (model);
@@ -591,39 +593,39 @@ static gboolean
tree_store_drag_drop_cb (G_GNUC_UNUSED GdauiTreeStore *store, const gchar *path,
GtkSelectionData *selection_data, DataFavoriteSelector *tsel)
{
- ToolsFavorites *bfav;
- ToolsFavoritesAttributes fav;
+ TFavorites *bfav;
+ TFavoritesAttributes favatt;
GError *error = NULL;
gint pos;
gboolean retval = TRUE;
gint id;
- bfav = browser_connection_get_favorites (tsel->priv->bcnc);
+ bfav = t_connection_get_favorites (tsel->priv->tcnc);
- id = gda_tools_favorites_find (bfav, 0, (gchar*) gtk_selection_data_get_data (selection_data),
- &fav, NULL);
+ id = t_favorites_find (bfav, 0, (gchar*) gtk_selection_data_get_data (selection_data),
+ &favatt, NULL);
if (id < 0) {
- memset (&fav, 0, sizeof (ToolsFavoritesAttributes));
- fav.id = -1;
- fav.type = GDA_TOOLS_FAVORITES_DATA_MANAGERS;
- fav.name = _("Unnamed data manager");
- fav.descr = NULL;
- fav.contents = (gchar*) gtk_selection_data_get_data (selection_data);
+ memset (&favatt, 0, sizeof (TFavoritesAttributes));
+ favatt.id = -1;
+ favatt.type = T_FAVORITES_DATA_MANAGERS;
+ favatt.name = _("Unnamed data manager");
+ favatt.descr = NULL;
+ favatt.contents = (gchar*) gtk_selection_data_get_data (selection_data);
}
pos = atoi (path);
/*g_print ("%s() path => %s, pos: %d\n", __FUNCTION__, path, pos);*/
- if (! gda_tools_favorites_add (bfav, 0, &fav, ORDER_KEY_DATA_MANAGERS, pos, &error)) {
- browser_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) tsel),
- _("Could not add favorite: %s"),
- error && error->message ? error->message : _("No detail"));
+ if (! t_favorites_add (bfav, 0, &favatt, ORDER_KEY_DATA_MANAGERS, pos, &error)) {
+ ui_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) tsel),
+ _("Could not add favorite: %s"),
+ error && error->message ? error->message : _("No detail"));
if (error)
g_error_free (error);
retval = FALSE;
}
if (id >= 0)
- gda_tools_favorites_reset_attributes (&fav);
+ t_favorites_reset_attributes (&favatt);
return retval;
}
@@ -664,7 +666,7 @@ tree_store_drag_get_cb (G_GNUC_UNUSED GdauiTreeStore *store, const gchar *path,
}
static void
-favorites_changed_cb (G_GNUC_UNUSED ToolsFavorites *bfav, DataFavoriteSelector *tsel)
+favorites_changed_cb (G_GNUC_UNUSED TFavorites *bfav, DataFavoriteSelector *tsel)
{
if (! gda_tree_update_all (tsel->priv->tree, NULL)) {
if (tsel->priv->idle_update_favorites == 0)
diff --git a/tools/browser/data-manager/data-favorite-selector.h
b/tools/browser/data-manager/data-favorite-selector.h
index d5067c7..1724850 100644
--- a/tools/browser/data-manager/data-favorite-selector.h
+++ b/tools/browser/data-manager/data-favorite-selector.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010 - 2012 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2010 - 2014 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
*
* This program is free software; you can redistribute it and/or
@@ -21,7 +21,7 @@
#define __DATA_FAVORITE_SELECTOR_H__
#include <gtk/gtk.h>
-#include "../browser-connection.h"
+#include "common/t-connection.h"
G_BEGIN_DECLS
@@ -44,12 +44,12 @@ struct _DataFavoriteSelectorClass {
GtkBoxClass parent_class;
void (*selection_changed) (DataFavoriteSelector *sel, gint fav_id,
- ToolsFavoritesType fav_type, const gchar *fav_contents);
+ TFavoritesType fav_type, const gchar *fav_contents);
};
GType data_favorite_selector_get_type (void) G_GNUC_CONST;
-GtkWidget *data_favorite_selector_new (BrowserConnection *bcnc);
+GtkWidget *data_favorite_selector_new (TConnection *tcnc);
G_END_DECLS
diff --git a/tools/browser/data-manager/data-manager-perspective.c
b/tools/browser/data-manager/data-manager-perspective.c
index 5896631..bc4938d 100644
--- a/tools/browser/data-manager/data-manager-perspective.c
+++ b/tools/browser/data-manager/data-manager-perspective.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2010 David King <davidk openismus com>
- * Copyright (C) 2010 - 2012 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2010 - 2014 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
*
* This program is free software; you can redistribute it and/or
@@ -26,6 +26,8 @@
#include "../browser-page.h"
#include "data-favorite-selector.h"
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+
/*
* Main static functions
*/
@@ -51,7 +53,7 @@ struct _DataManagerPerspectivePriv {
GtkWidget *favorites;
gboolean favorites_shown;
BrowserWindow *bwin;
- BrowserConnection *bcnc;
+ TConnection *tcnc;
};
GType
@@ -129,7 +131,7 @@ data_manager_perspective_init (DataManagerPerspective *perspective)
gtk_orientable_set_orientation (GTK_ORIENTABLE (perspective), GTK_ORIENTATION_VERTICAL);
}
-static void fav_selection_changed_cb (GtkWidget *widget, gint fav_id, ToolsFavoritesType fav_type,
+static void fav_selection_changed_cb (GtkWidget *widget, gint fav_id, TFavoritesType fav_type,
const gchar *selection, DataManagerPerspective *perspective);
static void close_button_clicked_cb (GtkWidget *wid, GtkWidget *page_widget);
@@ -142,7 +144,7 @@ static void close_button_clicked_cb (GtkWidget *wid, GtkWidget *page_widget);
BrowserPerspective *
data_manager_perspective_new (BrowserWindow *bwin)
{
- BrowserConnection *bcnc;
+ TConnection *tcnc;
BrowserPerspective *bpers;
DataManagerPerspective *perspective;
gboolean fav_supported;
@@ -150,15 +152,15 @@ data_manager_perspective_new (BrowserWindow *bwin)
bpers = (BrowserPerspective*) g_object_new (TYPE_DATA_MANAGER_PERSPECTIVE, NULL);
perspective = (DataManagerPerspective*) bpers;
perspective->priv->bwin = bwin;
- bcnc = browser_window_get_connection (bwin);
- perspective->priv->bcnc = g_object_ref (bcnc);
- fav_supported = browser_connection_get_favorites (bcnc) ? TRUE : FALSE;
+ tcnc = browser_window_get_connection (bwin);
+ perspective->priv->tcnc = g_object_ref (tcnc);
+ fav_supported = t_connection_get_favorites (tcnc) ? TRUE : FALSE;
/* contents */
GtkWidget *paned, *nb, *wid;
paned = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
if (fav_supported) {
- wid = data_favorite_selector_new (bcnc);
+ wid = data_favorite_selector_new (tcnc);
g_signal_connect (wid, "selection-changed",
G_CALLBACK (fav_selection_changed_cb), bpers);
gtk_paned_pack1 (GTK_PANED (paned), wid, FALSE, TRUE);
@@ -173,7 +175,7 @@ data_manager_perspective_new (BrowserWindow *bwin)
gtk_notebook_popup_enable (GTK_NOTEBOOK (nb));
GtkWidget *page, *tlabel, *button;
- page = data_console_new (bcnc);
+ page = data_console_new (tcnc);
tlabel = browser_page_get_tab_label (BROWSER_PAGE (page), &button);
g_signal_connect (button, "clicked",
G_CALLBACK (close_button_clicked_cb), page);
@@ -210,9 +212,9 @@ add_new_data_console (BrowserPerspective *bpers, gint fav_id)
perspective = DATA_MANAGER_PERSPECTIVE (bpers);
if (fav_id >= 0)
- page = data_console_new_with_fav_id (perspective->priv->bcnc, fav_id);
+ page = data_console_new_with_fav_id (perspective->priv->tcnc, fav_id);
else
- page = data_console_new (perspective->priv->bcnc);
+ page = data_console_new (perspective->priv->tcnc);
tlabel = browser_page_get_tab_label (BROWSER_PAGE (page), &button);
g_signal_connect (button, "clicked",
G_CALLBACK (close_button_clicked_cb), page);
@@ -231,7 +233,7 @@ add_new_data_console (BrowserPerspective *bpers, gint fav_id)
}
static void
-fav_selection_changed_cb (G_GNUC_UNUSED GtkWidget *widget, gint fav_id, ToolsFavoritesType fav_type,
+fav_selection_changed_cb (G_GNUC_UNUSED GtkWidget *widget, gint fav_id, TFavoritesType fav_type,
const gchar *selection, DataManagerPerspective *perspective)
{
/* find or create page for this favorite */
@@ -239,7 +241,7 @@ fav_selection_changed_cb (G_GNUC_UNUSED GtkWidget *widget, gint fav_id, ToolsFav
gint current_page, npages, i;
DataConsole *page_to_reuse = NULL;
- if (fav_type != GDA_TOOLS_FAVORITES_DATA_MANAGERS)
+ if (fav_type != T_FAVORITES_DATA_MANAGERS)
return;
/* change current page if possible */
@@ -295,8 +297,8 @@ data_manager_perspective_dispose (GObject *object)
perspective = DATA_MANAGER_PERSPECTIVE (object);
if (perspective->priv) {
browser_perspective_declare_notebook ((BrowserPerspective*) perspective, NULL);
- if (perspective->priv->bcnc)
- g_object_unref (perspective->priv->bcnc);
+ if (perspective->priv->tcnc)
+ g_object_unref (perspective->priv->tcnc);
g_free (perspective->priv);
perspective->priv = NULL;
diff --git a/tools/browser/data-manager/data-source-editor.c b/tools/browser/data-manager/data-source-editor.c
index 9ee2255..570a4f5 100644
--- a/tools/browser/data-manager/data-source-editor.c
+++ b/tools/browser/data-manager/data-source-editor.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2010 David King <davidk openismus com>
- * Copyright (C) 2010 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2010 - 2014 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
*
* This program is free software; you can redistribute it and/or
@@ -21,7 +21,7 @@
#include <string.h>
#include <glib/gi18n-lib.h>
#include "data-source-editor.h"
-#include "../common/widget-overlay.h"
+#include "../widget-overlay.h"
/* signals */
enum {
diff --git a/tools/browser/data-manager/data-source-manager.c
b/tools/browser/data-manager/data-source-manager.c
index 875b4e8..7cb0d68 100644
--- a/tools/browser/data-manager/data-source-manager.c
+++ b/tools/browser/data-manager/data-source-manager.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2010 David King <davidk openismus com>
- * Copyright (C) 2010 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2010 - 2014 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
*
* This program is free software; you can redistribute it and/or
@@ -20,8 +20,8 @@
#include <string.h>
#include <glib/gi18n-lib.h>
-#include "browser-connection.h"
-#include "support.h"
+#include "common/t-connection.h"
+#include "../ui-support.h"
#include "marshal.h"
#include <sql-parser/gda-sql-parser.h>
#include <libgda/gda-data-model-extra.h>
@@ -53,7 +53,7 @@ static void ensure_source_unique_id (DataSourceManager *mgr, DataSource *source)
static GObjectClass *parent_class = NULL;
struct _DataSourceManagerPrivate {
- BrowserConnection *bcnc;
+ TConnection *tcnc;
GSList *sources_list;
GdaSet *params; /* execution params */
gboolean emit_changes;
@@ -205,8 +205,8 @@ data_source_manager_dispose (GObject *object)
mgr->priv->sources_list = NULL;
}
- if (mgr->priv->bcnc)
- g_object_unref (mgr->priv->bcnc);
+ if (mgr->priv->tcnc)
+ g_object_unref (mgr->priv->tcnc);
g_free (mgr->priv);
mgr->priv = NULL;
@@ -218,20 +218,20 @@ data_source_manager_dispose (GObject *object)
/**
* data_source_manager_new
- * @bcnc:
+ * @tcnc:
*
* Creates a new #DataSourceManager object
*
* Returns: a new object
*/
DataSourceManager*
-data_source_manager_new (BrowserConnection *bcnc)
+data_source_manager_new (TConnection *tcnc)
{
DataSourceManager *mgr;
- g_return_val_if_fail (BROWSER_IS_CONNECTION (bcnc), NULL);
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
mgr = DATA_SOURCE_MANAGER (g_object_new (DATA_SOURCE_MANAGER_TYPE, NULL));
- mgr->priv->bcnc = g_object_ref (bcnc);
+ mgr->priv->tcnc = g_object_ref (tcnc);
return mgr;
}
@@ -421,7 +421,7 @@ compute_params (DataSourceManager *mgr)
{
/* cleanning process */
if (mgr->priv->params) {
- browser_connection_keep_variables (mgr->priv->bcnc, mgr->priv->params);
+ t_connection_keep_variables (mgr->priv->tcnc, mgr->priv->params);
g_object_unref (mgr->priv->params);
}
mgr->priv->params = NULL;
@@ -464,7 +464,7 @@ compute_params (DataSourceManager *mgr)
}
}
- browser_connection_load_variables (mgr->priv->bcnc, mgr->priv->params);
+ t_connection_load_variables (mgr->priv->tcnc, mgr->priv->params);
}
@@ -626,11 +626,11 @@ data_source_manager_destroy_sources_array (GArray *array)
* data_source_manager_get_browser_cnc
* @mgr:
*/
-BrowserConnection *
+TConnection *
data_source_manager_get_browser_cnc (DataSourceManager *mgr)
{
g_return_val_if_fail (IS_DATA_SOURCE_MANAGER (mgr), NULL);
- return mgr->priv->bcnc;
+ return mgr->priv->tcnc;
}
/**
diff --git a/tools/browser/data-manager/data-source-manager.h
b/tools/browser/data-manager/data-source-manager.h
index b01bb43..9a98eaf 100644
--- a/tools/browser/data-manager/data-source-manager.h
+++ b/tools/browser/data-manager/data-source-manager.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2010 - 2014 Vivien Malerba <malerba gnome-db org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -20,7 +20,7 @@
#ifndef __DATA_SOURCE_MANAGER_H_
#define __DATA_SOURCE_MANAGER_H_
-#include "../browser-connection.h"
+#include "common/t-connection.h"
#include "data-source.h"
G_BEGIN_DECLS
@@ -53,13 +53,13 @@ struct _DataSourceManagerClass
GType data_source_manager_get_type (void) G_GNUC_CONST;
-DataSourceManager *data_source_manager_new (BrowserConnection *bcnc);
+DataSourceManager *data_source_manager_new (TConnection *tcnc);
void data_source_manager_add_source (DataSourceManager *mgr, DataSource *source);
void data_source_manager_remove_source (DataSourceManager *mgr, DataSource *source);
void data_source_manager_replace_all (DataSourceManager *mgr, const GSList
*sources_list);
GdaSet *data_source_manager_get_params (DataSourceManager *mgr);
-BrowserConnection *data_source_manager_get_browser_cnc (DataSourceManager *mgr);
+TConnection *data_source_manager_get_browser_cnc (DataSourceManager *mgr);
GArray *data_source_manager_get_sources_array (DataSourceManager *mgr, GError **error);
void data_source_manager_destroy_sources_array (GArray *array);
diff --git a/tools/browser/data-manager/data-source.c b/tools/browser/data-manager/data-source.c
index ff0d9f5..4ebe882 100644
--- a/tools/browser/data-manager/data-source.c
+++ b/tools/browser/data-manager/data-source.c
@@ -2,7 +2,7 @@
* Copyright (C) 2010 Claude Paroz <claude 2xlibre net>
* Copyright (C) 2010 David King <davidk openismus com>
* Copyright (C) 2010 Murray Cumming <murrayc murrayc com>
- * Copyright (C) 2010 - 2012 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2010 - 2014 Vivien Malerba <malerba gnome-db org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -21,14 +21,16 @@
#include <string.h>
#include <glib/gi18n-lib.h>
-#include "browser-connection.h"
-#include "support.h"
+#include "../common/t-connection.h"
+#include "../ui-support.h"
#include "marshal.h"
#include <sql-parser/gda-sql-parser.h>
#include <libgda/gda-data-model-extra.h>
#include <libgda/gda-sql-builder.h>
-#include "../common/ui-formgrid.h"
-#include "../../tool-utils.h"
+#include "../ui-formgrid.h"
+#include "common/t-errors.h"
+
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#include "data-source.h"
#define DEFAULT_DATA_SOURCE_NAME "DataSource"
@@ -130,7 +132,7 @@ dependency_find (GSList *dep_list, const gchar *id, const gchar *table, gint siz
}
struct _DataSourcePrivate {
- BrowserConnection *bcnc;
+ TConnection *tcnc;
gchar *title;
gchar *impl_title;
gchar *id;
@@ -227,7 +229,7 @@ data_source_init (DataSource *source)
{
source->priv = g_new0 (DataSourcePrivate, 1);
source->priv->id = g_strdup (DEFAULT_DATA_SOURCE_NAME);
- source->priv->bcnc = NULL;
+ source->priv->tcnc = NULL;
source->priv->source_type = DATA_SOURCE_UNKNOWN;
source->priv->need_rerun = FALSE;
source->priv->exec_id = 0;
@@ -316,8 +318,8 @@ data_source_dispose (GObject *object)
source = DATA_SOURCE (object);
if (source->priv) {
- if (source->priv->bcnc)
- g_object_unref (source->priv->bcnc);
+ if (source->priv->tcnc)
+ g_object_unref (source->priv->tcnc);
data_source_reset (source);
g_free (source->priv->id);
g_free (source->priv->title);
@@ -336,20 +338,20 @@ static gboolean init_from_table_node (DataSource *source, xmlNodePtr node, GErro
/**
* data_source_new
- * @bcnc: a #BrowserConnection
+ * @tcnc: a #TConnection
* @type: the new data source's requested type
*
* Returns: a new #DataSource object
*/
DataSource *
-data_source_new (BrowserConnection *bcnc, DataSourceType type)
+data_source_new (TConnection *tcnc, DataSourceType type)
{
DataSource *source;
- g_return_val_if_fail (BROWSER_IS_CONNECTION (bcnc), NULL);
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
source = DATA_SOURCE (g_object_new (DATA_SOURCE_TYPE, NULL));
- source->priv->bcnc = g_object_ref (bcnc);
+ source->priv->tcnc = g_object_ref (tcnc);
source->priv->source_type = type;
return source;
@@ -357,7 +359,7 @@ data_source_new (BrowserConnection *bcnc, DataSourceType type)
/**
* data_source_new_from_xml_node
- * @bcnc: a #BrowserConnection
+ * @tcnc: a #TConnection
* @node:
* @error:
*
@@ -366,15 +368,15 @@ data_source_new (BrowserConnection *bcnc, DataSourceType type)
* Returns: a new object
*/
DataSource*
-data_source_new_from_xml_node (BrowserConnection *bcnc, xmlNodePtr node, GError **error)
+data_source_new_from_xml_node (TConnection *tcnc, xmlNodePtr node, GError **error)
{
DataSource *source;
- g_return_val_if_fail (BROWSER_IS_CONNECTION (bcnc), NULL);
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
g_return_val_if_fail (node, NULL);
source = DATA_SOURCE (g_object_new (DATA_SOURCE_TYPE, NULL));
- source->priv->bcnc = g_object_ref (bcnc);
+ source->priv->tcnc = g_object_ref (tcnc);
xmlChar *prop;
prop = xmlGetProp (node, BAD_CAST "title");
if (prop) {
@@ -399,7 +401,7 @@ data_source_new_from_xml_node (BrowserConnection *bcnc, xmlNodePtr node, GError
init_from_query (source, node);
}
else {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
/* Translators: Do not translate "table" nor "query" */
_("Node must be \"table\" or \"query\", and is \"%s\""), (gchar*)node->name);
g_object_unref (source);
@@ -431,16 +433,16 @@ get_meta_table (DataSource *source, const gchar *table_name, GError **error)
gchar **split;
gint len;
- mstruct = browser_connection_get_meta_struct (source->priv->bcnc);
+ mstruct = t_connection_get_meta_struct (source->priv->tcnc);
if (! mstruct) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_STORED_DATA_ERROR,
+ g_set_error (error, T_ERROR, T_STORED_DATA_ERROR,
"%s", _("Not ready"));
return NULL;
}
split = gda_sql_identifier_split (table_name);
if (! split) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
_("Malformed table name \"%s\""), table_name);
return NULL;
}
@@ -457,12 +459,12 @@ get_meta_table (DataSource *source, const gchar *table_name, GError **error)
if (vname[2]) gda_value_free (vname[2]);
if (! dbo) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (error, T_ERROR, T_INTERNAL_COMMAND_ERROR,
_("Could not find the \"%s\" table"), table_name);
return NULL;
}
if ((dbo->obj_type != GDA_META_DB_TABLE) && (dbo->obj_type != GDA_META_DB_VIEW)) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (error, T_ERROR, T_INTERNAL_COMMAND_ERROR,
_("The \"%s\" object is not a table"), table_name);
return NULL;
}
@@ -480,7 +482,7 @@ init_from_table_node (DataSource *source, xmlNodePtr node, GError **error)
#endif
tname = xmlGetProp (node, BAD_CAST "name");
if (!tname) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
/* Translators: Do not translate "name" */
"%s", _("Missing attribute \"name\" for table"));
return FALSE;
@@ -621,12 +623,12 @@ data_source_add_dependency (DataSource *source, const gchar *table,
}
}
if (!fk) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (error, T_ERROR, T_INTERNAL_COMMAND_ERROR,
_("Could not find any foreign key to \"%s\""), table);
return FALSE;
}
else if (fk->cols_nb <= 0) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (error, T_ERROR, T_INTERNAL_COMMAND_ERROR,
_("The fields involved in the foreign key to \"%s\" are not known"),
table);
return FALSE;
@@ -890,7 +892,7 @@ data_source_execute (DataSource *source, GError **error)
if (source->priv->init_error)
g_propagate_error (error, source->priv->init_error);
else
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
"%s", _("No SELECT statement to execute"));
}
@@ -898,15 +900,15 @@ data_source_execute (DataSource *source, GError **error)
if (source->priv->need_rerun) {
source->priv->need_rerun = FALSE;
g_signal_emit (source, data_source_signals [EXEC_STARTED], 0);
- browser_connection_rerun_select (source->priv->bcnc, source->priv->model, &lerror);
+ t_connection_rerun_select (source->priv->tcnc, source->priv->model, &lerror);
gda_data_model_dump (source->priv->model, NULL);
- g_signal_emit (source, data_source_signals [EXEC_FINISHED], lerror);
+ g_signal_emit (source, data_source_signals [EXEC_FINISHED], 0, lerror);
}
}
else {
GObject *result;
g_signal_emit (source, data_source_signals [EXEC_STARTED], 0);
- result = browser_connection_execute_statement (source->priv->bcnc,
+ result = t_connection_execute_statement (source->priv->tcnc,
source->priv->stmt,
source->priv->params,
GDA_STATEMENT_MODEL_RANDOM_ACCESS |
@@ -924,10 +926,10 @@ data_source_execute (DataSource *source, GError **error)
}
else {
g_object_unref (result);
- g_set_error (&lerror, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (&lerror, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
"%s", _("Statement to execute is not a selection statement"));
}
- g_signal_emit (source, data_source_signals [EXEC_FINISHED], lerror);
+ g_signal_emit (source, data_source_signals [EXEC_FINISHED], 0, lerror);
}
g_signal_emit (source, data_source_signals [EXEC_FINISHED], 0, lerror);
@@ -1084,7 +1086,7 @@ update_export_information (DataSource *source)
/* Get GdaSqlStatement */
GdaSqlStatement *sqlst;
g_object_get ((GObject*) source->priv->stmt, "structure", &sqlst, NULL);
- if (browser_connection_check_sql_statement_validify (source->priv->bcnc, sqlst, NULL))
+ if (t_connection_check_sql_statement_validify (source->priv->tcnc, sqlst, NULL))
g_object_set ((GObject*) source->priv->stmt, "structure", sqlst, NULL);
if (! sqlst)
return;
@@ -1170,7 +1172,7 @@ data_source_set_table (DataSource *source, const gchar *table, GError **error)
b = gda_sql_builder_new (GDA_SQL_STATEMENT_SELECT);
source->priv->builder = b;
if (! gda_sql_builder_select_add_target (b, table, NULL)) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (error, T_ERROR, T_INTERNAL_COMMAND_ERROR,
"%s", _("Could not build SELECT statement"));
return FALSE;
}
@@ -1227,7 +1229,7 @@ data_source_set_query (DataSource *source, const gchar *sql, GError **warning)
GdaSqlParser *parser;
const gchar *remain;
- parser = browser_connection_create_parser (source->priv->bcnc);
+ parser = t_connection_create_parser (source->priv->tcnc);
source->priv->stmt = gda_sql_parser_parse_string (parser, sql,
&remain, warning);
g_object_unref (parser);
@@ -1237,13 +1239,13 @@ data_source_set_query (DataSource *source, const gchar *sql, GError **warning)
}
if (remain)
- g_set_error (warning, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (warning, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
"%s", _("Multiple statements detected, only the first will be used"));
/* try to normalize the statement */
GdaSqlStatement *sqlst;
g_object_get ((GObject*) source->priv->stmt, "structure", &sqlst, NULL);
- if (browser_connection_normalize_sql_statement (source->priv->bcnc, sqlst, NULL))
+ if (t_connection_normalize_sql_statement (source->priv->tcnc, sqlst, NULL))
g_object_set ((GObject*) source->priv->stmt, "structure", sqlst, NULL);
gda_sql_statement_free (sqlst);
@@ -1299,7 +1301,7 @@ compute_import_params (DataSource *source)
#endif
}
- browser_connection_define_ui_plugins_for_stmt (source->priv->bcnc, source->priv->stmt,
+ t_connection_define_ui_plugins_for_stmt (source->priv->tcnc, source->priv->stmt,
source->priv->params);
g_signal_connect (source->priv->params, "holder-changed",
diff --git a/tools/browser/data-manager/data-source.h b/tools/browser/data-manager/data-source.h
index 4ec1d64..a9c67ae 100644
--- a/tools/browser/data-manager/data-source.h
+++ b/tools/browser/data-manager/data-source.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010 - 2012 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2010 - 2014 Vivien Malerba <malerba gnome-db org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -22,6 +22,7 @@
#include <libgda-ui/libgda-ui.h>
#include "decl.h"
+#include "common/t-connection.h"
G_BEGIN_DECLS
@@ -78,8 +79,8 @@ gboolean data_source_add_dependency (DataSource *source, const g
void data_source_set_query (DataSource *source, const gchar *sql, GError **warning);
/* other API */
-DataSource *data_source_new (BrowserConnection *bcnc, DataSourceType type);
-DataSource *data_source_new_from_xml_node (BrowserConnection *bcnc, xmlNodePtr node, GError
**error);
+DataSource *data_source_new (TConnection *tcnc, DataSourceType type);
+DataSource *data_source_new_from_xml_node (TConnection *tcnc, xmlNodePtr node, GError **error);
void data_source_set_params (DataSource *source, GdaSet *params);
xmlNodePtr data_source_to_xml_node (DataSource *source);
@@ -94,9 +95,9 @@ gboolean data_source_execution_going_on (DataSource *source);
GtkWidget *data_source_create_grid (DataSource *source);
/*
-DataSource *data_source_new_from_table (BrowserConnection *bcnc,
+DataSource *data_source_new_from_table (TConnection *tcnc,
const gchar *table_schema, const gchar *table_name);
-DataSource *data_source_new_from_select (BrowserConnection *bcnc, const gchar *select_sql);
+DataSource *data_source_new_from_select (TConnection *tcnc, const gchar *select_sql);
*/
void data_source_should_rerun (DataSource *source);
diff --git a/tools/browser/data-manager/data-widget.c b/tools/browser/data-manager/data-widget.c
index c645f59..2e7e2ea 100644
--- a/tools/browser/data-manager/data-widget.c
+++ b/tools/browser/data-manager/data-widget.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2010 David King <davidk openismus com>
- * Copyright (C) 2010 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2010 - 2014 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
*
* This program is free software; you can redistribute it and/or
@@ -21,11 +21,10 @@
#include <glib/gi18n-lib.h>
#include <string.h>
#include "data-widget.h"
-#include "../browser-connection.h"
-#include "../browser-spinner.h"
-#include "../common/ui-formgrid.h"
+#include "common/t-connection.h"
+#include "../ui-formgrid.h"
#include "../browser-window.h"
-#include "../support.h"
+#include "../ui-support.h"
#include "data-source-editor.h"
#include "analyser.h"
@@ -44,7 +43,7 @@ typedef struct {
gint edit_widget_page;
gint edit_widget_previous_page;
- BrowserSpinner *spinner;
+ GtkWidget *spinner;
guint spinner_show_timer_id;
GtkWidget *data_widget;
GtkWidget *error_widget;
@@ -236,7 +235,7 @@ create_or_reuse_part (DataWidget *dwid, DataSource *source, gboolean *out_reused
gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
gtk_box_pack_start (GTK_BOX (header), label, TRUE, TRUE, 0);
- image = gtk_image_new_from_pixbuf (browser_get_pixbuf_icon (BROWSER_ICON_MENU_INDICATOR));
+ image = gtk_image_new_from_pixbuf (ui_get_pixbuf_icon (UI_ICON_MENU_INDICATOR));
button = gtk_button_new ();
gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
gtk_button_set_focus_on_click (GTK_BUTTON (button), FALSE);
@@ -255,10 +254,9 @@ create_or_reuse_part (DataWidget *dwid, DataSource *source, gboolean *out_reused
gtk_notebook_set_show_tabs (GTK_NOTEBOOK (nb), FALSE);
part->nb = GTK_NOTEBOOK (nb);
- part->spinner = BROWSER_SPINNER (browser_spinner_new ());
- browser_spinner_set_size ((BrowserSpinner*) part->spinner, GTK_ICON_SIZE_LARGE_TOOLBAR);
+ part->spinner = gtk_spinner_new ();
page = gtk_alignment_new (0.5, 0.5, 0., 0.);
- gtk_container_add (GTK_CONTAINER (page), (GtkWidget*) part->spinner);
+ gtk_container_add (GTK_CONTAINER (page), part->spinner);
gtk_notebook_append_page (GTK_NOTEBOOK (nb), page, NULL);
part->data_widget = NULL;
@@ -625,7 +623,7 @@ static gboolean
source_exec_started_cb_timeout (DataPart *part)
{
gtk_notebook_set_current_page (part->nb, 0);
- browser_spinner_start (part->spinner);
+ gtk_spinner_start (GTK_SPINNER (part->spinner));
part->spinner_show_timer_id = 0;
return FALSE; /* remove timer */
}
@@ -700,7 +698,7 @@ source_exec_finished_cb (G_GNUC_UNUSED DataSource *source, GError *error, DataPa
part->spinner_show_timer_id = 0;
}
else
- browser_spinner_stop (part->spinner);
+ gtk_spinner_stop (GTK_SPINNER (part->spinner));
#ifdef GDA_DEBUG_NO
g_print ("==== Execution of source [%s] finished\n", data_source_get_title (part->source));
@@ -712,10 +710,10 @@ source_exec_finished_cb (G_GNUC_UNUSED DataSource *source, GError *error, DataPa
if (! part->data_widget) {
GtkWidget *cwid, *wid;
- BrowserConnection *bcnc;
- bcnc = browser_window_get_connection ((BrowserWindow*) gtk_widget_get_toplevel ((GtkWidget*)
part->dwid));
+ TConnection *tcnc;
+ tcnc = browser_window_get_connection ((BrowserWindow*) gtk_widget_get_toplevel ((GtkWidget*)
part->dwid));
cwid = (GtkWidget*) data_source_create_grid (part->source);
- ui_formgrid_handle_user_prefs (UI_FORMGRID (cwid), bcnc,
+ ui_formgrid_handle_user_prefs (UI_FORMGRID (cwid), tcnc,
data_source_get_statement (part->source));
g_signal_connect (cwid, "data-set-changed",
G_CALLBACK (formgrid_data_set_changed_cb), part);
diff --git a/tools/browser/data-manager/perspective-main.h b/tools/browser/data-manager/perspective-main.h
index b2ab811..5644641 100644
--- a/tools/browser/data-manager/perspective-main.h
+++ b/tools/browser/data-manager/perspective-main.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2009 - 2014 Vivien Malerba <malerba gnome-db org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -16,7 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#include "../decl.h"
+#include "../browser-perspective.h"
G_BEGIN_DECLS
diff --git a/tools/browser/data-manager/ui-spec-editor.c b/tools/browser/data-manager/ui-spec-editor.c
index ec787a9..c23c59c 100644
--- a/tools/browser/data-manager/ui-spec-editor.c
+++ b/tools/browser/data-manager/ui-spec-editor.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2010 David King <davidk openismus com>
- * Copyright (C) 2010 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2010 - 2014 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
*
* This program is free software; you can redistribute it and/or
@@ -23,7 +23,7 @@
#include "ui-spec-editor.h"
#include "data-source.h"
#include <libgda/libgda.h>
-#include "../support.h"
+#include "../ui-support.h"
#include "data-source-editor.h"
#include <gdk/gdkkeysyms.h>
@@ -108,10 +108,10 @@ cell_pixbuf_data_func (G_GNUC_UNUSED GtkTreeViewColumn *tree_column, GtkCellRend
stype = data_source_get_source_type (source);
switch (stype) {
case DATA_SOURCE_TABLE:
- g_object_set (cell, "pixbuf", browser_get_pixbuf_icon (BROWSER_ICON_TABLE), NULL);
+ g_object_set (cell, "pixbuf", ui_get_pixbuf_icon (UI_ICON_TABLE), NULL);
break;
case DATA_SOURCE_SELECT:
- g_object_set (cell, "pixbuf", browser_get_pixbuf_icon (BROWSER_ICON_QUERY), NULL);
+ g_object_set (cell, "pixbuf", ui_get_pixbuf_icon (UI_ICON_QUERY), NULL);
break;
default:
g_object_set (cell, "pixbuf", NULL, NULL);
@@ -161,7 +161,7 @@ do_popup_menu (G_GNUC_UNUSED GtkWidget *widget, GdkEventButton *event, UiSpecEdi
g_signal_connect (menu, "deactivate",
G_CALLBACK (gtk_widget_hide), NULL);
- mitem = gtk_image_menu_item_new_with_label (_("Remove"));
+ mitem = gtk_menu_item_new_with_label (_("Remove"));
gtk_menu_shell_append (GTK_MENU_SHELL (menu), mitem);
gtk_widget_show (mitem);
g_signal_connect (mitem, "activate",
@@ -255,7 +255,7 @@ ui_spec_editor_init (UiSpecEditor *sped, G_GNUC_UNUSED UiSpecEditorClass *klass)
sped->priv->sources_model = gtk_list_store_new (NUM_COLUMNS,
G_TYPE_POINTER);
- sped->priv->sources_tree = browser_make_tree_view (GTK_TREE_MODEL (sped->priv->sources_model));
+ sped->priv->sources_tree = ui_make_tree_view (GTK_TREE_MODEL (sped->priv->sources_model));
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (sped->priv->sources_tree), FALSE);
gtk_widget_set_size_request (sped->priv->sources_tree, 170, -1);
diff --git a/tools/browser/data-manager/ui-spec-editor.h b/tools/browser/data-manager/ui-spec-editor.h
index 010e227..54aeb45 100644
--- a/tools/browser/data-manager/ui-spec-editor.h
+++ b/tools/browser/data-manager/ui-spec-editor.h
@@ -21,7 +21,7 @@
#define __UI_SPEC_EDITOR_H__
#include <gtk/gtk.h>
-#include "../browser-connection.h"
+#include "common/t-connection.h"
#include "data-source-manager.h"
G_BEGIN_DECLS
diff --git a/tools/browser/data-manager/xml-spec-editor.c b/tools/browser/data-manager/xml-spec-editor.c
index f4b893a..5badffd 100644
--- a/tools/browser/data-manager/xml-spec-editor.c
+++ b/tools/browser/data-manager/xml-spec-editor.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2010 David King <davidk openismus com>
- * Copyright (C) 2010 - 2012 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2010 - 2014 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
*
* This program is free software; you can redistribute it and/or
@@ -23,9 +23,9 @@
#include "xml-spec-editor.h"
#include "data-source.h"
#include <libgda/libgda.h>
-#include "../support.h"
-#include "../../tool-utils.h"
+#include "../ui-support.h"
#include <libgda/gda-debug-macros.h>
+#include <common/t-errors.h>
#ifdef HAVE_GTKSOURCEVIEW
#ifdef GTK_DISABLE_SINGLE_INCLUDES
@@ -170,7 +170,7 @@ signal_editor_changed (XmlSpecEditor *sped)
if (!doc) {
TO_IMPLEMENT;
- g_set_error (&lerror, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (&lerror, T_ERROR, T_INTERNAL_COMMAND_ERROR,
"%s", _("Error parsing XML specifications"));
goto out;
}
@@ -184,19 +184,19 @@ signal_editor_changed (XmlSpecEditor *sped)
}
if (strcmp ((gchar*) node->name, "data")) {
- g_set_error (&lerror, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (&lerror, T_ERROR, T_INTERNAL_COMMAND_ERROR,
_("Expecting <%s> root node"), "data");
xmlFreeDoc (doc);
goto out;
}
- BrowserConnection *bcnc;
- bcnc = data_source_manager_get_browser_cnc (sped->priv->mgr);
+ TConnection *tcnc;
+ tcnc = data_source_manager_get_browser_cnc (sped->priv->mgr);
for (node = node->children; node; node = node->next) {
if (!strcmp ((gchar*) node->name, "table") ||
!strcmp ((gchar*) node->name, "query")) {
DataSource *source;
- source = data_source_new_from_xml_node (bcnc, node, &lerror);
+ source = data_source_new_from_xml_node (tcnc, node, &lerror);
if (!source) {
if (newlist) {
g_slist_foreach (newlist, (GFunc) g_object_unref, NULL);
diff --git a/tools/browser/data-manager/xml-spec-editor.h b/tools/browser/data-manager/xml-spec-editor.h
index 6d54ff4..e044207 100644
--- a/tools/browser/data-manager/xml-spec-editor.h
+++ b/tools/browser/data-manager/xml-spec-editor.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2010 - 2014 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
*
* This program is free software; you can redistribute it and/or
@@ -21,7 +21,7 @@
#define __XML_SPEC_EDITOR_H__
#include <gtk/gtk.h>
-#include "../browser-connection.h"
+#include "common/t-connection.h"
#include "data-source-manager.h"
G_BEGIN_DECLS
diff --git a/tools/browser/data/256x256/gda-browser-6.0.png b/tools/browser/data/256x256/gda-browser-6.0.png
new file mode 100644
index 0000000..7ebf74f
Binary files /dev/null and b/tools/browser/data/256x256/gda-browser-6.0.png differ
diff --git a/tools/browser/data/48x48/gda-browser-6.0.png b/tools/browser/data/48x48/gda-browser-6.0.png
new file mode 100644
index 0000000..1532e47
Binary files /dev/null and b/tools/browser/data/48x48/gda-browser-6.0.png differ
diff --git a/tools/browser/decl.h b/tools/browser/decl.h
index 56843fe..c9f99a9 100644
--- a/tools/browser/decl.h
+++ b/tools/browser/decl.h
@@ -21,10 +21,7 @@
G_BEGIN_DECLS
-typedef struct _BrowserCore BrowserCore;
-
typedef struct _BrowserVariable BrowserVariable;
-typedef struct _BrowserConnection BrowserConnection;
typedef struct _BrowserWindow BrowserWindow;
typedef struct _BrowserData BrowserData;
@@ -35,13 +32,6 @@ typedef struct _BrowserPerspective BrowserPerspective;
typedef struct _BrowserPageIface BrowserPageIface;
typedef struct _BrowserPage BrowserPage;
-typedef struct {
- const gchar *perspective_name;
- const gchar *menu_shortcut;
- BrowserPerspective *(*perspective_create) (BrowserWindow *);
-} BrowserPerspectiveFactory;
-#define BROWSER_PERSPECTIVE_FACTORY(x) ((BrowserPerspectiveFactory*)(x))
-
#define DEFAULT_FAVORITES_SIZE 150
#define DEFAULT_DATA_SELECT_LIMIT 500
diff --git a/tools/browser/dummy-perspective/dummy-perspective.c
b/tools/browser/dummy-perspective/dummy-perspective.c
index 17e5489..d55de9e 100644
--- a/tools/browser/dummy-perspective/dummy-perspective.c
+++ b/tools/browser/dummy-perspective/dummy-perspective.c
@@ -22,6 +22,8 @@
#include <glib/gi18n-lib.h>
#include "dummy-perspective.h"
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+
/*
* Main static functions
*/
diff --git a/tools/browser/dummy-perspective/perspective-main.h
b/tools/browser/dummy-perspective/perspective-main.h
index ec1ef19..787e4f9 100644
--- a/tools/browser/dummy-perspective/perspective-main.h
+++ b/tools/browser/dummy-perspective/perspective-main.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2009 - 2014 Vivien Malerba <malerba gnome-db org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -16,7 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#include "../decl.h"
+#include "../browser-perspective.h"
G_BEGIN_DECLS
diff --git a/tools/browser/common/fk-declare.c b/tools/browser/fk-declare.c
similarity index 95%
rename from tools/browser/common/fk-declare.c
rename to tools/browser/fk-declare.c
index b19ae0f..6209b7b 100644
--- a/tools/browser/common/fk-declare.c
+++ b/tools/browser/fk-declare.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2011 - 2012 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2011 - 2014 Vivien Malerba <malerba gnome-db org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -20,8 +20,8 @@
#include <string.h>
#include <sql-parser/gda-sql-parser.h>
#include "fk-declare.h"
-#include "../support.h"
-#include "../../tool-utils.h"
+#include "ui-support.h"
+#include <t-utils.h>
/*
* Main static functions
@@ -113,8 +113,7 @@ fk_declare_class_init (FkDeclareClass *class)
static void
help_clicked_cb (GtkButton *button, G_GNUC_UNUSED FkDeclare *declare)
{
- browser_show_help ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) button),
- "declared-fk");
+ ui_show_help ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) button), "declared-fk");
g_signal_stop_emission_by_name (button, "clicked");
}
#endif
@@ -126,14 +125,12 @@ fk_declare_init (FkDeclare *declare)
declare->priv->dialog_sensitive = FALSE;
gtk_dialog_add_buttons (GTK_DIALOG (declare),
- GTK_STOCK_ADD,
- GTK_RESPONSE_ACCEPT,
- GTK_STOCK_CANCEL,
- GTK_RESPONSE_REJECT,
+ _("_Add"), GTK_RESPONSE_ACCEPT,
+ _("_Cancel"), GTK_RESPONSE_REJECT,
NULL);
#ifdef HAVE_GDU
GtkWidget *help_btn;
- help_btn = gtk_button_new_from_stock (GTK_STOCK_HELP);
+ help_btn = gtk_button_new_from_icon_name ("help-browser", GTK_ICON_SIZE_DIALOG);
g_signal_connect (help_btn, "clicked",
G_CALLBACK (help_clicked_cb), declare);
gtk_widget_show (help_btn);
@@ -371,7 +368,7 @@ update_reference_column_choices (FkDeclare *decl)
GdaMetaTableColumn *col = (GdaMetaTableColumn*) list->data;
GdkPixbuf *pix;
gtk_list_store_append (lstore, &iter);
- pix = browser_get_pixbuf_icon (BROWSER_ICON_COLUMN);
+ pix = ui_get_pixbuf_icon (UI_ICON_COLUMN);
gtk_list_store_set (lstore, &iter,
MODEL_COLUMNS_COLUMN_PIXBUF, pix,
MODEL_COLUMNS_COLUMN_STRING, col->column_name,
@@ -449,7 +446,7 @@ create_tables_model (GdaMetaStruct *mstruct)
if (strcmp (dbo->obj_short_name, dbo->obj_full_name)) {
gtk_tree_store_prepend (tstore, &iter, NULL);
- pix = browser_get_pixbuf_icon (BROWSER_ICON_TABLE);
+ pix = ui_get_pixbuf_icon (UI_ICON_TABLE);
gtk_tree_store_set (tstore, &iter,
MODEL_TABLES_COLUMN_PIXBUF, pix,
MODEL_TABLES_COLUMN_STRING, dbo->obj_short_name,
@@ -465,7 +462,7 @@ create_tables_model (GdaMetaStruct *mstruct)
GtkTreePath *path;
GdkPixbuf *pix;
gtk_tree_store_append (tstore, &iter, NULL);
- pix = browser_get_pixbuf_icon (BROWSER_ICON_SCHEMA);
+ pix = ui_get_pixbuf_icon (UI_ICON_SCHEMA);
gtk_tree_store_set (tstore, &iter,
MODEL_TABLES_COLUMN_PIXBUF, pix,
MODEL_TABLES_COLUMN_STRING, dbo->obj_schema,
@@ -480,7 +477,7 @@ create_tables_model (GdaMetaStruct *mstruct)
g_assert (gtk_tree_model_get_iter ((GtkTreeModel*) tstore, &parent, path));
gtk_tree_path_free (path);
gtk_tree_store_prepend (tstore, &iter, &parent);
- pix = browser_get_pixbuf_icon (BROWSER_ICON_TABLE);
+ pix = ui_get_pixbuf_icon (UI_ICON_TABLE);
gtk_tree_store_set (tstore, &iter,
MODEL_TABLES_COLUMN_PIXBUF, pix,
MODEL_TABLES_COLUMN_STRING, dbo->obj_short_name,
@@ -556,7 +553,7 @@ fk_declare_write (FkDeclare *decl, BrowserWindow *bwin, GError **error)
g_return_val_if_fail (!bwin || BROWSER_IS_WINDOW (bwin), FALSE);
if (! decl->priv->dialog_sensitive) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
"%s", _("Missing information to declare foreign key"));
return FALSE;
}
@@ -600,9 +597,9 @@ fk_declare_write (FkDeclare *decl, BrowserWindow *bwin, GError **error)
g_free (ref_colnames);
if (retval && bwin) {
- BrowserConnection *bcnc;
- bcnc = browser_window_get_connection (bwin);
- browser_connection_meta_data_changed (bcnc);
+ TConnection *tcnc;
+ tcnc = browser_window_get_connection (bwin);
+ t_connection_meta_data_changed (tcnc);
}
g_object_unref (mstore);
@@ -638,7 +635,7 @@ fk_declare_undeclare (GdaMetaStruct *mstruct, BrowserWindow *bwin, GdaMetaTableF
!decl_fk->depend_on->obj_catalog ||
!decl_fk->depend_on->obj_schema ||
!decl_fk->depend_on->obj_name) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
"%s", _("Missing information to undeclare foreign key"));
return FALSE;
}
@@ -654,9 +651,9 @@ fk_declare_undeclare (GdaMetaStruct *mstruct, BrowserWindow *bwin, GdaMetaTableF
decl_fk->depend_on->obj_name,
error);
if (retval && bwin) {
- BrowserConnection *bcnc;
- bcnc = browser_window_get_connection (bwin);
- browser_connection_meta_data_changed (bcnc);
+ TConnection *tcnc;
+ tcnc = browser_window_get_connection (bwin);
+ t_connection_meta_data_changed (tcnc);
}
g_object_unref (mstore);
diff --git a/tools/browser/common/fk-declare.h b/tools/browser/fk-declare.h
similarity index 95%
rename from tools/browser/common/fk-declare.h
rename to tools/browser/fk-declare.h
index b4f1e22..4b4bc4d 100644
--- a/tools/browser/common/fk-declare.h
+++ b/tools/browser/fk-declare.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2011 - 2014 Vivien Malerba <malerba gnome-db org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -22,7 +22,7 @@
#include <libgda-ui/libgda-ui.h>
#include <gtk/gtk.h>
-#include "../browser-window.h"
+#include "browser-window.h"
G_BEGIN_DECLS
diff --git a/tools/browser/common/gdaui-data-import.c b/tools/browser/gdaui-data-import.c
similarity index 100%
rename from tools/browser/common/gdaui-data-import.c
rename to tools/browser/gdaui-data-import.c
diff --git a/tools/browser/common/gdaui-data-import.h b/tools/browser/gdaui-data-import.h
similarity index 100%
rename from tools/browser/common/gdaui-data-import.h
rename to tools/browser/gdaui-data-import.h
diff --git a/tools/browser/common/gdaui-entry-import.c b/tools/browser/gdaui-entry-import.c
similarity index 98%
rename from tools/browser/common/gdaui-entry-import.c
rename to tools/browser/gdaui-entry-import.c
index 259063f..0fcf442 100644
--- a/tools/browser/common/gdaui-entry-import.c
+++ b/tools/browser/gdaui-entry-import.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2009 - 2014 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2010 David King <davidk openismus com>
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
*
@@ -182,10 +182,8 @@ open_button_clicked_cb (GtkWidget *button, GdauiEntryImport *mgtxt)
dialog = gtk_dialog_new_with_buttons (_("Data set import from file"),
(GtkWindow*) gtk_widget_get_toplevel (button),
GTK_DIALOG_MODAL,
- GTK_STOCK_OK,
- GTK_RESPONSE_ACCEPT,
- GTK_STOCK_CANCEL,
- GTK_RESPONSE_REJECT,
+ _("_OK"), GTK_RESPONSE_ACCEPT,
+ _("_Cancel"), GTK_RESPONSE_REJECT,
NULL);
gtk_window_set_default_size (GTK_WINDOW (dialog), 620, 450);
wid = gdaui_data_import_new ();
diff --git a/tools/browser/common/gdaui-entry-import.h b/tools/browser/gdaui-entry-import.h
similarity index 100%
rename from tools/browser/common/gdaui-entry-import.h
rename to tools/browser/gdaui-entry-import.h
diff --git a/tools/browser/ldap-browser/Makefile.am b/tools/browser/ldap-browser/Makefile.am
index 92c6f1b..9c5cb3d 100644
--- a/tools/browser/ldap-browser/Makefile.am
+++ b/tools/browser/ldap-browser/Makefile.am
@@ -1,6 +1,7 @@
noinst_LTLIBRARIES = libperspective.la
AM_CPPFLAGS = \
+ -I$(top_srcdir)/tools \
-I$(top_srcdir)/tools/browser \
-I$(top_builddir) \
-I$(top_srcdir) \
diff --git a/tools/browser/ldap-browser/class-properties.c b/tools/browser/ldap-browser/class-properties.c
index 9844301..17ebebf 100644
--- a/tools/browser/ldap-browser/class-properties.c
+++ b/tools/browser/ldap-browser/class-properties.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
- * Copyright (C) 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2011 - 2014 Vivien Malerba <malerba gnome-db org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -23,9 +23,10 @@
#include "class-properties.h"
#include "marshal.h"
#include "../text-search.h"
+#include "../ui-support.h"
struct _ClassPropertiesPrivate {
- BrowserConnection *bcnc;
+ TConnection *tcnc;
GtkTextView *view;
GtkTextBuffer *text;
@@ -88,8 +89,8 @@ class_properties_dispose (GObject *object)
/* free memory */
if (cprop->priv) {
- if (cprop->priv->bcnc) {
- g_object_unref (cprop->priv->bcnc);
+ if (cprop->priv->tcnc) {
+ g_object_unref (cprop->priv->tcnc);
}
g_free (cprop->priv);
cprop->priv = NULL;
@@ -134,13 +135,13 @@ static void show_search_bar (ClassProperties *cprop);
* Returns: a new #GtkWidget
*/
GtkWidget *
-class_properties_new (BrowserConnection *bcnc)
+class_properties_new (TConnection *tcnc)
{
ClassProperties *cprop;
- g_return_val_if_fail (BROWSER_IS_CONNECTION (bcnc), NULL);
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
cprop = CLASS_PROPERTIES (g_object_new (CLASS_PROPERTIES_TYPE, NULL));
- cprop->priv->bcnc = g_object_ref (bcnc);
+ cprop->priv->tcnc = g_object_ref (tcnc);
GtkWidget *sw;
sw = gtk_scrolled_window_new (NULL, NULL);
@@ -401,9 +402,9 @@ class_properties_set_class (ClassProperties *cprop, const gchar *classname)
if (!classname || !*classname)
return;
- lcl = browser_connection_get_class_info (cprop->priv->bcnc, classname);
+ lcl = t_connection_get_class_info (cprop->priv->tcnc, classname);
if (!lcl) {
- browser_show_message (GTK_WINDOW (gtk_widget_get_toplevel ((GtkWidget*) cprop)),
+ ui_show_message (GTK_WINDOW (gtk_widget_get_toplevel ((GtkWidget*) cprop)),
"%s", _("Could not get information about LDAP class"));
return;
}
@@ -439,9 +440,9 @@ class_properties_set_class (ClassProperties *cprop, const gchar *classname)
"section", NULL);
gtk_text_buffer_insert (tbuffer, ¤t, "\n", 1);
- gtk_text_buffer_insert_pixbuf (tbuffer, ¤t, browser_get_pixbuf_for_ldap_class (lcl->kind));
+ gtk_text_buffer_insert_pixbuf (tbuffer, ¤t, ui_connection_ldap_icon_for_class_kind
(lcl->kind));
- kind = browser_get_kind_for_ldap_class (lcl->kind);
+ kind = ui_connection_ldap_class_kind_to_string (lcl->kind);
gtk_text_buffer_insert_with_tags_by_name (tbuffer, ¤t, " ", -1, "starter", NULL);
gtk_text_buffer_insert_with_tags_by_name (tbuffer, ¤t, kind, -1,
"data", NULL);
@@ -516,7 +517,7 @@ class_properties_set_class (ClassProperties *cprop, const gchar *classname)
GtkTextTag *tag;
olcl = (GdaLdapClass*) list->data;
gtk_text_buffer_insert_pixbuf (tbuffer, ¤t,
- browser_get_pixbuf_for_ldap_class (olcl->kind));
+ ui_connection_ldap_icon_for_class_kind (olcl->kind));
gtk_text_buffer_insert_with_tags_by_name (tbuffer, ¤t, " ", -1, "starter",
NULL);
tag = gtk_text_buffer_create_tag (tbuffer, NULL,
"foreground", "blue",
@@ -562,7 +563,7 @@ class_properties_set_class (ClassProperties *cprop, const gchar *classname)
olcl = (GdaLdapClass*) list->data;
gtk_text_buffer_insert_pixbuf (tbuffer, ¤t,
- browser_get_pixbuf_for_ldap_class (olcl->kind));
+ ui_connection_ldap_icon_for_class_kind (olcl->kind));
gtk_text_buffer_insert_with_tags_by_name (tbuffer, ¤t, " ", -1, "starter",
NULL);
tag = gtk_text_buffer_create_tag (tbuffer, NULL,
"foreground", "blue",
diff --git a/tools/browser/ldap-browser/class-properties.h b/tools/browser/ldap-browser/class-properties.h
index 99d3f9e..b38cf4c 100644
--- a/tools/browser/ldap-browser/class-properties.h
+++ b/tools/browser/ldap-browser/class-properties.h
@@ -20,7 +20,7 @@
#ifndef __CLASS_PROPERTIES_H__
#define __CLASS_PROPERTIES_H__
-#include "../browser-connection.h"
+#include "common/t-connection.h"
G_BEGIN_DECLS
@@ -48,7 +48,7 @@ struct _ClassPropertiesClass {
GType class_properties_get_type (void) G_GNUC_CONST;
-GtkWidget *class_properties_new (BrowserConnection *bcnc);
+GtkWidget *class_properties_new (TConnection *tcnc);
void class_properties_set_class (ClassProperties *eprop, const gchar *classname);
G_END_DECLS
diff --git a/tools/browser/ldap-browser/classes-view.c b/tools/browser/ldap-browser/classes-view.c
index 8710540..95c2424 100644
--- a/tools/browser/ldap-browser/classes-view.c
+++ b/tools/browser/ldap-browser/classes-view.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
- * Copyright (C) 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2011 - 2014 Vivien Malerba <malerba gnome-db org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -21,16 +21,15 @@
#include <string.h>
#include "classes-view.h"
#include "../dnd.h"
-#include "../support.h"
+#include "../ui-support.h"
#include "../gdaui-bar.h"
-#include "../browser-stock-icons.h"
#include <virtual/gda-ldap-connection.h>
#include "mgr-ldap-classes.h"
#include <libgda-ui/gdaui-tree-store.h>
#include <libgda/gda-debug-macros.h>
struct _ClassesViewPrivate {
- BrowserConnection *bcnc;
+ TConnection *tcnc;
GdaTree *classes_tree;
GdauiTreeStore *classes_store;
@@ -73,8 +72,8 @@ classes_view_dispose (GObject *object)
/* free memory */
if (eview->priv) {
- if (eview->priv->bcnc)
- g_object_unref (eview->priv->bcnc);
+ if (eview->priv->tcnc)
+ g_object_unref (eview->priv->tcnc);
if (eview->priv->classes_tree)
g_object_unref (eview->priv->classes_tree);
@@ -198,14 +197,14 @@ text_cell_data_func (G_GNUC_UNUSED GtkTreeViewColumn *tree_column, GtkCellRender
* Returns: a new #GtkWidget
*/
GtkWidget *
-classes_view_new (BrowserConnection *bcnc, const gchar *classname)
+classes_view_new (TConnection *tcnc, const gchar *classname)
{
ClassesView *eview;
- g_return_val_if_fail (BROWSER_IS_CONNECTION (bcnc), NULL);
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
eview = CLASSES_VIEW (g_object_new (CLASSES_VIEW_TYPE, NULL));
- eview->priv->bcnc = g_object_ref ((GObject*) bcnc);
+ eview->priv->tcnc = g_object_ref ((GObject*) tcnc);
g_signal_connect (eview, "drag-data-get",
G_CALLBACK (source_drag_data_get_cb), eview);
@@ -214,7 +213,7 @@ classes_view_new (BrowserConnection *bcnc, const gchar *classname)
GtkCellRenderer *renderer;
GtkTreeViewColumn *column;
eview->priv->classes_tree = gda_tree_new ();
- mgr = mgr_ldap_classes_new (eview->priv->bcnc, FALSE, NULL);
+ mgr = mgr_ldap_classes_new (eview->priv->tcnc, FALSE, NULL);
gda_tree_add_manager (eview->priv->classes_tree, mgr);
gda_tree_manager_add_manager (mgr, mgr);
gda_tree_update_all (eview->priv->classes_tree, NULL);
diff --git a/tools/browser/ldap-browser/classes-view.h b/tools/browser/ldap-browser/classes-view.h
index 9b27fc6..6470722 100644
--- a/tools/browser/ldap-browser/classes-view.h
+++ b/tools/browser/ldap-browser/classes-view.h
@@ -20,7 +20,7 @@
#define __CLASSES_VIEW_H__
#include <gtk/gtk.h>
-#include "../browser-connection.h"
+#include "common/t-connection.h"
G_BEGIN_DECLS
@@ -45,7 +45,7 @@ struct _ClassesViewClass {
GType classes_view_get_type (void) G_GNUC_CONST;
-GtkWidget *classes_view_new (BrowserConnection *bcnc, const gchar *classname);
+GtkWidget *classes_view_new (TConnection *tcnc, const gchar *classname);
const gchar *classes_view_get_current_class (ClassesView *classes_view);
void classes_view_set_current_class (ClassesView *classes_view, const gchar *classname);
diff --git a/tools/browser/ldap-browser/entry-properties.c b/tools/browser/ldap-browser/entry-properties.c
index 7ad1b6d..edbc14a 100644
--- a/tools/browser/ldap-browser/entry-properties.c
+++ b/tools/browser/ldap-browser/entry-properties.c
@@ -24,10 +24,13 @@
#include "marshal.h"
#include <time.h>
#include <libgda-ui/libgda-ui.h>
+#include "../ui-support.h"
#include "../text-search.h"
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+
struct _EntryPropertiesPrivate {
- BrowserConnection *bcnc;
+ TConnection *tcnc;
GtkTextView *view;
GtkTextBuffer *text;
@@ -104,8 +107,8 @@ entry_properties_dispose (GObject *object)
/* free memory */
if (eprop->priv) {
- if (eprop->priv->bcnc) {
- g_object_unref (eprop->priv->bcnc);
+ if (eprop->priv->tcnc) {
+ g_object_unref (eprop->priv->tcnc);
}
g_free (eprop->priv);
@@ -152,13 +155,13 @@ static void show_search_bar (EntryProperties *eprop);
* Returns: a new #GtkWidget
*/
GtkWidget *
-entry_properties_new (BrowserConnection *bcnc)
+entry_properties_new (TConnection *tcnc)
{
EntryProperties *eprop;
- g_return_val_if_fail (BROWSER_IS_CONNECTION (bcnc), NULL);
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
eprop = ENTRY_PROPERTIES (g_object_new (ENTRY_PROPERTIES_TYPE, NULL));
- eprop->priv->bcnc = g_object_ref (bcnc);
+ eprop->priv->tcnc = g_object_ref (tcnc);
GtkWidget *sw;
sw = gtk_scrolled_window_new (NULL, NULL);
@@ -239,7 +242,7 @@ data_save_cb (GtkWidget *mitem, EntryProperties *eprop)
bin = gda_value_get_binary (binvalue);
if (!bin || !g_file_set_contents (filename, (gchar*) bin->data,
bin->binary_length, &lerror)) {
- browser_show_error ((GtkWindow*) gtk_widget_get_toplevel (GTK_WIDGET (eprop)),
+ ui_show_error ((GtkWindow*) gtk_widget_get_toplevel (GTK_WIDGET (eprop)),
_("Could not save data: %s"),
lerror && lerror->message ? lerror->message : _("No detail"));
g_clear_error (&lerror);
@@ -747,7 +750,7 @@ entry_info_fetched_done (EntryProperties *eprop, GdaLdapEntry *entry)
{
GtkTextBuffer *tbuffer;
GtkTextIter start, end;
- BrowserConnection *bcnc = eprop->priv->bcnc;
+ TConnection *tcnc = eprop->priv->tcnc;
tbuffer = eprop->priv->text;
gtk_text_buffer_get_start_iter (tbuffer, &start);
@@ -771,7 +774,7 @@ entry_info_fetched_done (EntryProperties *eprop, GdaLdapEntry *entry)
/* other attributes */
const gchar *basedn;
GdaDataHandler *ts_dh = NULL;
- basedn = browser_connection_ldap_get_base_dn (bcnc);
+ basedn = t_connection_ldap_get_base_dn (tcnc);
for (i = 0; i < entry->nb_attributes; i++) {
GdaLdapAttribute *attr;
@@ -949,11 +952,11 @@ entry_properties_set_dn (EntryProperties *eprop, const gchar *dn)
if (dn && *dn) {
GdaLdapEntry *entry;
- entry = browser_connection_ldap_describe_entry (eprop->priv->bcnc, dn, NULL);
+ entry = t_connection_ldap_describe_entry (eprop->priv->tcnc, dn, NULL);
if (entry)
entry_info_fetched_done (eprop, entry);
else
- browser_show_message (GTK_WINDOW (gtk_widget_get_toplevel ((GtkWidget*) eprop)),
+ ui_show_message (GTK_WINDOW (gtk_widget_get_toplevel ((GtkWidget*) eprop)),
"%s", _("Could not get information about LDAP entry"));
}
}
diff --git a/tools/browser/ldap-browser/entry-properties.h b/tools/browser/ldap-browser/entry-properties.h
index abbbd10..0b503aa 100644
--- a/tools/browser/ldap-browser/entry-properties.h
+++ b/tools/browser/ldap-browser/entry-properties.h
@@ -20,7 +20,7 @@
#ifndef __ENTRY_PROPERTIES_H__
#define __ENTRY_PROPERTIES_H__
-#include "../browser-connection.h"
+#include "common/t-connection.h"
G_BEGIN_DECLS
@@ -49,7 +49,7 @@ struct _EntryPropertiesClass {
GType entry_properties_get_type (void) G_GNUC_CONST;
-GtkWidget *entry_properties_new (BrowserConnection *bcnc);
+GtkWidget *entry_properties_new (TConnection *tcnc);
void entry_properties_set_dn (EntryProperties *eprop, const gchar *dn);
G_END_DECLS
diff --git a/tools/browser/ldap-browser/filter-editor.c b/tools/browser/ldap-browser/filter-editor.c
index 3150755..52fd134 100644
--- a/tools/browser/ldap-browser/filter-editor.c
+++ b/tools/browser/ldap-browser/filter-editor.c
@@ -24,7 +24,7 @@
#include <libgda-ui/gdaui-data-selector.h>
struct _FilterEditorPrivate {
- BrowserConnection *bcnc;
+ TConnection *tcnc;
GtkWidget *base_dn;
GtkWidget *filter;
GtkWidget *attributes;
@@ -73,7 +73,7 @@ static void
filter_editor_init (FilterEditor *feditor, G_GNUC_UNUSED FilterEditorClass *klass)
{
feditor->priv = g_new0 (FilterEditorPrivate, 1);
- feditor->priv->bcnc = NULL;
+ feditor->priv->tcnc = NULL;
feditor->priv->default_scope = GDA_LDAP_SEARCH_SUBTREE;
gtk_orientable_set_orientation (GTK_ORIENTABLE (feditor), GTK_ORIENTATION_VERTICAL);
@@ -86,8 +86,8 @@ filter_editor_dispose (GObject *object)
/* free memory */
if (feditor->priv) {
- if (feditor->priv->bcnc)
- g_object_unref (feditor->priv->bcnc);
+ if (feditor->priv->tcnc)
+ g_object_unref (feditor->priv->tcnc);
g_free (feditor->priv);
feditor->priv = NULL;
}
@@ -131,7 +131,7 @@ activated_cb (G_GNUC_UNUSED GtkEntry *entry, FilterEditor *feditor)
* Returns: a new #GtkWidget
*/
GtkWidget *
-filter_editor_new (BrowserConnection *bcnc)
+filter_editor_new (TConnection *tcnc)
{
FilterEditor *feditor;
GtkWidget *grid, *label, *entry;
@@ -140,10 +140,10 @@ filter_editor_new (BrowserConnection *bcnc)
GValue *v1, *v2;
gfloat ya;
- g_return_val_if_fail (BROWSER_IS_CONNECTION (bcnc), NULL);
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
feditor = FILTER_EDITOR (g_object_new (FILTER_EDITOR_TYPE, NULL));
- feditor->priv->bcnc = g_object_ref ((GObject*) bcnc);
+ feditor->priv->tcnc = g_object_ref ((GObject*) tcnc);
grid = gtk_grid_new ();
gtk_grid_set_column_spacing (GTK_GRID (grid), 5);
diff --git a/tools/browser/ldap-browser/filter-editor.h b/tools/browser/ldap-browser/filter-editor.h
index 28df748..59eb7c8 100644
--- a/tools/browser/ldap-browser/filter-editor.h
+++ b/tools/browser/ldap-browser/filter-editor.h
@@ -22,7 +22,7 @@
#include <gtk/gtk.h>
#include <libgda/libgda.h>
-#include "../browser-connection.h"
+#include "common/t-connection.h"
G_BEGIN_DECLS
@@ -50,7 +50,7 @@ struct _FilterEditorClass {
GType filter_editor_get_type (void) G_GNUC_CONST;
-GtkWidget *filter_editor_new (BrowserConnection *bcnc);
+GtkWidget *filter_editor_new (TConnection *tcnc);
void filter_editor_clear (FilterEditor *fedit);
void filter_editor_set_settings (FilterEditor *fedit,
const gchar *base_dn, const gchar *filter,
diff --git a/tools/browser/ldap-browser/hierarchy-view.c b/tools/browser/ldap-browser/hierarchy-view.c
index 5e4be10..7418447 100644
--- a/tools/browser/ldap-browser/hierarchy-view.c
+++ b/tools/browser/ldap-browser/hierarchy-view.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
- * Copyright (C) 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2011 - 2014 Vivien Malerba <malerba gnome-db org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -21,16 +21,15 @@
#include <string.h>
#include "hierarchy-view.h"
#include "../dnd.h"
-#include "../support.h"
+#include "../ui-support.h"
#include "../gdaui-bar.h"
-#include "../browser-stock-icons.h"
#include <virtual/gda-ldap-connection.h>
#include "mgr-ldap-entries.h"
#include <libgda-ui/gdaui-tree-store.h>
#include <libgda/gda-debug-macros.h>
struct _HierarchyViewPrivate {
- BrowserConnection *bcnc;
+ TConnection *tcnc;
GdaTree *ldap_tree;
GdauiTreeStore *ldap_store;
@@ -77,8 +76,8 @@ hierarchy_view_dispose (GObject *object)
/* free memory */
if (eview->priv) {
- if (eview->priv->bcnc)
- g_object_unref (eview->priv->bcnc);
+ if (eview->priv->tcnc)
+ g_object_unref (eview->priv->tcnc);
if (eview->priv->ldap_tree)
g_object_unref (eview->priv->ldap_tree);
if (eview->priv->to_show) {
@@ -204,14 +203,14 @@ text_cell_data_func (G_GNUC_UNUSED GtkTreeViewColumn *tree_column, GtkCellRender
* Returns: a new #GtkWidget
*/
GtkWidget *
-hierarchy_view_new (BrowserConnection *bcnc, const gchar *dn)
+hierarchy_view_new (TConnection *tcnc, const gchar *dn)
{
HierarchyView *eview;
- g_return_val_if_fail (BROWSER_IS_CONNECTION (bcnc), NULL);
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
eview = HIERARCHY_VIEW (g_object_new (HIERARCHY_VIEW_TYPE, NULL));
- eview->priv->bcnc = g_object_ref ((GObject*) bcnc);
+ eview->priv->tcnc = g_object_ref ((GObject*) tcnc);
g_signal_connect (eview, "drag-data-get",
G_CALLBACK (source_drag_data_get_cb), eview);
@@ -220,7 +219,7 @@ hierarchy_view_new (BrowserConnection *bcnc, const gchar *dn)
GtkCellRenderer *renderer;
GtkTreeViewColumn *column;
eview->priv->ldap_tree = gda_tree_new ();
- mgr = mgr_ldap_entries_new (eview->priv->bcnc, NULL);
+ mgr = mgr_ldap_entries_new (eview->priv->tcnc, NULL);
gda_tree_add_manager (eview->priv->ldap_tree, mgr);
gda_tree_manager_add_manager (mgr, mgr);
gda_tree_update_children (eview->priv->ldap_tree, NULL, NULL);
@@ -267,7 +266,7 @@ hierarchy_view_new (BrowserConnection *bcnc, const gchar *dn)
const gchar *basedn;
GArray *array;
- basedn = browser_connection_ldap_get_base_dn (eview->priv->bcnc);
+ basedn = t_connection_ldap_get_base_dn (eview->priv->tcnc);
array = g_array_new (TRUE, FALSE, sizeof (gchar*));
make_dn_hierarchy (basedn, dn, array);
if (array->len > 0) {
@@ -518,7 +517,7 @@ go_to_row (HierarchyView *eview, GtkTreePath *path)
}
else {
/* DN not found! */
- browser_show_message (GTK_WINDOW (gtk_widget_get_toplevel ((GtkWidget*) eview)),
+ ui_show_message (GTK_WINDOW (gtk_widget_get_toplevel ((GtkWidget*) eview)),
_("Could not find LDAP entry with DN '%s'"), tofind);
goto out;
}
@@ -565,7 +564,7 @@ hierarchy_view_set_current_dn (HierarchyView *hierarchy_view, const gchar *dn)
hierarchy_view->priv->to_show = NULL;
}
- basedn = browser_connection_ldap_get_base_dn (hierarchy_view->priv->bcnc);
+ basedn = t_connection_ldap_get_base_dn (hierarchy_view->priv->tcnc);
array = g_array_new (TRUE, FALSE, sizeof (gchar*));
make_dn_hierarchy (basedn, dn, array);
if (array->len > 0) {
diff --git a/tools/browser/ldap-browser/hierarchy-view.h b/tools/browser/ldap-browser/hierarchy-view.h
index 44a9814..180755f 100644
--- a/tools/browser/ldap-browser/hierarchy-view.h
+++ b/tools/browser/ldap-browser/hierarchy-view.h
@@ -20,7 +20,7 @@
#define __HIERARCHY_VIEW_H__
#include <gtk/gtk.h>
-#include "../browser-connection.h"
+#include "common/t-connection.h"
G_BEGIN_DECLS
@@ -45,7 +45,7 @@ struct _HierarchyViewClass {
GType hierarchy_view_get_type (void) G_GNUC_CONST;
-GtkWidget *hierarchy_view_new (BrowserConnection *bcnc, const gchar *dn);
+GtkWidget *hierarchy_view_new (TConnection *tcnc, const gchar *dn);
const gchar *hierarchy_view_get_current_dn (HierarchyView *hierarchy_view, const gchar **out_current_cn);
void hierarchy_view_set_current_dn (HierarchyView *hierarchy_view, const gchar *dn);
diff --git a/tools/browser/ldap-browser/ldap-browser-perspective.c
b/tools/browser/ldap-browser/ldap-browser-perspective.c
index 334605a..9486583 100644
--- a/tools/browser/ldap-browser/ldap-browser-perspective.c
+++ b/tools/browser/ldap-browser/ldap-browser-perspective.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
- * Copyright (C) 2011 - 2012 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2011 - 2014 Vivien Malerba <malerba gnome-db org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -24,10 +24,11 @@
#include "ldap-entries-page.h"
#include "ldap-classes-page.h"
#include "ldap-search-page.h"
-#include "../support.h"
+#include "../ui-support.h"
#include "../browser-page.h"
#include "ldap-favorite-selector.h"
-#include "../browser-stock-icons.h"
+
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
/*
* Main static functions
@@ -127,7 +128,7 @@ close_button_clicked_cb (G_GNUC_UNUSED GtkWidget *wid, GtkWidget *page_widget)
gtk_widget_destroy (page_widget);
}
-static void fav_selection_changed_cb (GtkWidget *widget, gint fav_id, ToolsFavoritesType fav_type,
+static void fav_selection_changed_cb (GtkWidget *widget, gint fav_id, TFavoritesType fav_type,
const gchar *selection, LdapBrowserPerspective *bpers);
/**
* ldap_browser_perspective_new
@@ -137,7 +138,7 @@ static void fav_selection_changed_cb (GtkWidget *widget, gint fav_id, ToolsFavor
BrowserPerspective *
ldap_browser_perspective_new (BrowserWindow *bwin)
{
- BrowserConnection *bcnc;
+ TConnection *tcnc;
BrowserPerspective *bpers;
LdapBrowserPerspective *perspective;
@@ -148,9 +149,9 @@ ldap_browser_perspective_new (BrowserWindow *bwin)
/* contents */
GtkWidget *paned, *wid, *nb, *button, *tlabel;
- bcnc = browser_window_get_connection (bwin);
+ tcnc = browser_window_get_connection (bwin);
paned = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
- wid = ldap_favorite_selector_new (bcnc);
+ wid = ldap_favorite_selector_new (tcnc);
g_signal_connect (wid, "selection-changed",
G_CALLBACK (fav_selection_changed_cb), bpers);
gtk_paned_add1 (GTK_PANED (paned), wid);
@@ -163,7 +164,7 @@ ldap_browser_perspective_new (BrowserWindow *bwin)
gtk_notebook_set_scrollable (GTK_NOTEBOOK (nb), TRUE);
gtk_notebook_popup_enable (GTK_NOTEBOOK (nb));
- wid = ldap_entries_page_new (bcnc, NULL);
+ wid = ldap_entries_page_new (tcnc, NULL);
tlabel = browser_page_get_tab_label (BROWSER_PAGE (wid), &button);
g_signal_connect (button, "clicked",
G_CALLBACK (close_button_clicked_cb), wid);
@@ -185,13 +186,13 @@ ldap_browser_perspective_new (BrowserWindow *bwin)
static void
fav_selection_changed_cb (G_GNUC_UNUSED GtkWidget *widget, G_GNUC_UNUSED gint fav_id,
- ToolsFavoritesType fav_type,
+ TFavoritesType fav_type,
const gchar *selection, LdapBrowserPerspective *bpers)
{
- if (fav_type == GDA_TOOLS_FAVORITES_LDAP_DN) {
+ if (fav_type == T_FAVORITES_LDAP_DN) {
ldap_browser_perspective_display_ldap_entry (bpers, selection);
}
- if (fav_type == GDA_TOOLS_FAVORITES_LDAP_CLASS) {
+ if (fav_type == T_FAVORITES_LDAP_CLASS) {
ldap_browser_perspective_display_ldap_class (bpers, selection);
}
#ifdef GDA_DEBUG_NO
@@ -235,13 +236,13 @@ ldab_ldap_entries_page_add_cb (G_GNUC_UNUSED GtkAction *action, BrowserPerspecti
{
GtkWidget *page, *tlabel, *button;
LdapBrowserPerspective *perspective;
- BrowserConnection *bcnc;
+ TConnection *tcnc;
gint i;
perspective = LDAP_BROWSER_PERSPECTIVE (bpers);
- bcnc = browser_window_get_connection (perspective->priv->bwin);
+ tcnc = browser_window_get_connection (perspective->priv->bwin);
- page = ldap_entries_page_new (bcnc, NULL);
+ page = ldap_entries_page_new (tcnc, NULL);
gtk_widget_show (page);
tlabel = browser_page_get_tab_label (BROWSER_PAGE (page), &button);
g_signal_connect (button, "clicked",
@@ -265,13 +266,13 @@ ldab_ldap_classes_page_add_cb (G_GNUC_UNUSED GtkAction *action, BrowserPerspecti
{
GtkWidget *page, *tlabel, *button;
LdapBrowserPerspective *perspective;
- BrowserConnection *bcnc;
+ TConnection *tcnc;
gint i;
perspective = LDAP_BROWSER_PERSPECTIVE (bpers);
- bcnc = browser_window_get_connection (perspective->priv->bwin);
+ tcnc = browser_window_get_connection (perspective->priv->bwin);
- page = ldap_classes_page_new (bcnc, NULL);
+ page = ldap_classes_page_new (tcnc, NULL);
gtk_widget_show (page);
tlabel = browser_page_get_tab_label (BROWSER_PAGE (page), &button);
g_signal_connect (button, "clicked",
@@ -295,11 +296,11 @@ ldab_search_add_cb (G_GNUC_UNUSED GtkAction *action, BrowserPerspective *bpers)
{
GtkWidget *page, *tlabel, *button;
LdapBrowserPerspective *perspective;
- BrowserConnection *bcnc;
+ TConnection *tcnc;
gint i;
perspective = LDAP_BROWSER_PERSPECTIVE (bpers);
- bcnc = browser_window_get_connection (perspective->priv->bwin);
+ tcnc = browser_window_get_connection (perspective->priv->bwin);
i = gtk_notebook_get_current_page (GTK_NOTEBOOK (perspective->priv->notebook));
GtkWidget *child;
@@ -308,7 +309,7 @@ ldab_search_add_cb (G_GNUC_UNUSED GtkAction *action, BrowserPerspective *bpers)
if (IS_LDAP_ENTRIES_PAGE (child))
dn = ldap_entries_page_get_current_dn (LDAP_ENTRIES_PAGE (child));
- page = ldap_search_page_new (bcnc, dn);
+ page = ldap_search_page_new (tcnc, dn);
gtk_widget_show (page);
tlabel = browser_page_get_tab_label (BROWSER_PAGE (page), &button);
g_signal_connect (button, "clicked",
@@ -329,12 +330,12 @@ ldab_search_add_cb (G_GNUC_UNUSED GtkAction *action, BrowserPerspective *bpers)
static const GtkToggleActionEntry ui_toggle_actions [] =
{
- { "LdapToolsFavoritesShow", NULL, N_("_Show Favorites"), "F9", N_("Show or hide favorites"),
G_CALLBACK (favorites_toggle_cb), FALSE }
+ { "LdapTFavoritesShow", NULL, N_("_Show Favorites"), "F9", N_("Show or hide favorites"),
G_CALLBACK (favorites_toggle_cb), FALSE }
};
static GtkActionEntry ui_actions[] = {
{ "LDAP", NULL, N_("_LDAP"), NULL, N_("LDAP"), NULL },
- { "LdapLdapEntriesPageNew", BROWSER_STOCK_LDAP_ENTRIES, N_("_New LDAP Entries Browser"),
"<control>T", N_("Open a new LDAP entries browser"),
+ { "LdapLdapEntriesPageNew", /*BROWSER_STOCK_LDAP_ENTRIES*/ NULL, N_("_New LDAP Entries Browser"),
"<control>T", N_("Open a new LDAP entries browser"),
G_CALLBACK (ldab_ldap_entries_page_add_cb)},
{ "LdapLdapClassesPageNew", NULL, N_("_New LDAP Classes Browser"), "<control>C", N_("Open a new LDAP
classes browser"),
G_CALLBACK (ldab_ldap_classes_page_add_cb)},
@@ -346,7 +347,7 @@ static const gchar *ui_actions_info =
"<ui>"
" <menubar name='MenuBar'>"
" <menu name='Display' action='Display'>"
- " <menuitem name='LdapToolsFavoritesShow' action='LdapToolsFavoritesShow'/>"
+ " <menuitem name='LdapTFavoritesShow' action='LdapTFavoritesShow'/>"
" </menu>"
" <placeholder name='MenuExtension'>"
" <menu name='LDAP' action='LDAP'>"
@@ -374,7 +375,7 @@ ldap_browser_perspective_get_actions_group (BrowserPerspective *bpers)
gtk_action_group_add_toggle_actions (agroup, ui_toggle_actions, G_N_ELEMENTS (ui_toggle_actions),
bpers);
GtkAction *action;
- action = gtk_action_group_get_action (agroup, "LdapToolsFavoritesShow");
+ action = gtk_action_group_get_action (agroup, "LdapTFavoritesShow");
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
LDAP_BROWSER_PERSPECTIVE (bpers)->priv->favorites_shown);
diff --git a/tools/browser/ldap-browser/ldap-classes-page.c b/tools/browser/ldap-browser/ldap-classes-page.c
index 47a31b7..d4b7725 100644
--- a/tools/browser/ldap-browser/ldap-classes-page.c
+++ b/tools/browser/ldap-browser/ldap-classes-page.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
- * Copyright (C) 2011 - 2012 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2011 - 2014 Vivien Malerba <malerba gnome-db org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -23,17 +23,18 @@
#include "classes-view.h"
#include "class-properties.h"
#include "../dnd.h"
-#include "../support.h"
+#include "../ui-support.h"
#include "../gdaui-bar.h"
#include "../browser-page.h"
-#include "../browser-stock-icons.h"
#include "../browser-window.h"
-#include "../browser-connection.h"
+#include "common/t-connection.h"
#include <virtual/gda-ldap-connection.h>
#include "mgr-ldap-classes.h"
#include <libgda-ui/gdaui-tree-store.h>
#include <libgda/gda-debug-macros.h>
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+
typedef struct {
gchar *classname;
GtkTreeRowReference *reference;
@@ -48,7 +49,7 @@ history_item_free (HistoryItem *item)
}
struct _LdapClassesPagePrivate {
- BrowserConnection *bcnc;
+ TConnection *tcnc;
GtkWidget *classes_view;
GtkWidget *entry_props;
@@ -113,8 +114,8 @@ ldap_classes_page_dispose (GObject *object)
/* free memory */
if (ebrowser->priv) {
- if (ebrowser->priv->bcnc)
- g_object_unref (ebrowser->priv->bcnc);
+ if (ebrowser->priv->tcnc)
+ g_object_unref (ebrowser->priv->tcnc);
if (ebrowser->priv->agroup)
g_object_unref (ebrowser->priv->agroup);
if (ebrowser->priv->history_items) {
@@ -301,14 +302,14 @@ open_classname_requested_cb (G_GNUC_UNUSED ClassProperties *eprop, const gchar *
* Returns: a new #GtkWidget
*/
GtkWidget *
-ldap_classes_page_new (BrowserConnection *bcnc, const gchar *classname)
+ldap_classes_page_new (TConnection *tcnc, const gchar *classname)
{
LdapClassesPage *ebrowser;
- g_return_val_if_fail (BROWSER_IS_CONNECTION (bcnc), NULL);
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
ebrowser = LDAP_CLASSES_PAGE (g_object_new (LDAP_CLASSES_PAGE_TYPE, NULL));
- ebrowser->priv->bcnc = g_object_ref ((GObject*) bcnc);
+ ebrowser->priv->tcnc = g_object_ref ((GObject*) tcnc);
/* header */
GtkWidget *label;
@@ -342,7 +343,7 @@ ldap_classes_page_new (BrowserConnection *bcnc, const gchar *classname)
gtk_misc_set_alignment (GTK_MISC (label), 0., yalign);
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
- hview = classes_view_new (bcnc, NULL);
+ hview = classes_view_new (tcnc, NULL);
ebrowser->priv->classes_view = hview;
sw = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC,
@@ -370,7 +371,7 @@ ldap_classes_page_new (BrowserConnection *bcnc, const gchar *classname)
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
GtkWidget *props;
- props = class_properties_new (bcnc);
+ props = class_properties_new (tcnc);
gtk_box_pack_start (GTK_BOX (vbox), props, TRUE, TRUE, 0);
ebrowser->priv->entry_props = props;
g_signal_connect (props, "open-class",
@@ -413,21 +414,21 @@ ldap_classes_page_set_current_class (LdapClassesPage *ldap_classes_page, const g
static void
action_add_to_fav_cb (G_GNUC_UNUSED GtkAction *action, LdapClassesPage *ebrowser)
{
- ToolsFavorites *bfav;
- ToolsFavoritesAttributes fav;
+ TFavorites *bfav;
+ TFavoritesAttributes fav;
GError *error = NULL;
classes_view_get_current_class (CLASSES_VIEW (ebrowser->priv->classes_view));
- memset (&fav, 0, sizeof (ToolsFavoritesAttributes));
+ memset (&fav, 0, sizeof (TFavoritesAttributes));
fav.id = -1;
- fav.type = GDA_TOOLS_FAVORITES_LDAP_CLASS;
+ fav.type = T_FAVORITES_LDAP_CLASS;
fav.name = ldap_classes_page_to_selection (ebrowser);
fav.descr = NULL;
fav.contents = ldap_classes_page_to_selection (ebrowser);
- bfav = browser_connection_get_favorites (ebrowser->priv->bcnc);
- if (! gda_tools_favorites_add (bfav, 0, &fav, ORDER_KEY_LDAP, G_MAXINT, &error)) {
- browser_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) ebrowser),
+ bfav = t_connection_get_favorites (ebrowser->priv->tcnc);
+ if (! t_favorites_add (bfav, 0, &fav, ORDER_KEY_LDAP, G_MAXINT, &error)) {
+ ui_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) ebrowser),
_("Could not add favorite: %s"),
error && error->message ? error->message : _("No detail"));
if (error)
@@ -505,7 +506,7 @@ action_class_forward_cb (G_GNUC_UNUSED GtkAction *action, LdapClassesPage *ebrow
static GtkActionEntry ui_actions[] = {
{ "LDAP", NULL, N_("_LDAP"), NULL, N_("LDAP"), NULL },
- { "AddToFav", STOCK_ADD_BOOKMARK, N_("Add to _Favorites"), NULL, N_("Add class to favorites"),
+ { "AddToFav", /*STOCK_ADD_BOOKMARK*/ NULL, N_("Add to _Favorites"), NULL, N_("Add class to
favorites"),
G_CALLBACK (action_add_to_fav_cb)},
{ "DnBack", GTK_STOCK_GO_BACK, N_("Previous Class"), NULL, N_("Move back to previous LDAP class"),
G_CALLBACK (action_class_back_cb)},
@@ -569,9 +570,9 @@ ldap_classes_page_page_get_tab_label (BrowserPage *page, GtkWidget **out_close_b
const gchar *tab_name;
GdkPixbuf *classes_pixbuf;
- classes_pixbuf = browser_get_pixbuf_icon (BROWSER_ICON_LDAP_CLASS_STRUCTURAL);
+ classes_pixbuf = ui_get_pixbuf_icon (UI_ICON_LDAP_CLASS_STRUCTURAL);
tab_name = _("LDAP classes");
- return browser_make_tab_label_with_pixbuf (tab_name,
+ return ui_make_tab_label_with_pixbuf (tab_name,
classes_pixbuf,
out_close_button ? TRUE : FALSE, out_close_button);
}
diff --git a/tools/browser/ldap-browser/ldap-classes-page.h b/tools/browser/ldap-browser/ldap-classes-page.h
index 339975f..a6244bd 100644
--- a/tools/browser/ldap-browser/ldap-classes-page.h
+++ b/tools/browser/ldap-browser/ldap-classes-page.h
@@ -21,7 +21,7 @@
#define __LDAP_CLASSES_PAGE_H__
#include <gtk/gtk.h>
-#include "../browser-connection.h"
+#include "common/t-connection.h"
G_BEGIN_DECLS
@@ -46,7 +46,7 @@ struct _LdapClassesPageClass {
GType ldap_classes_page_get_type (void) G_GNUC_CONST;
-GtkWidget *ldap_classes_page_new (BrowserConnection *bcnc, const gchar *dn);
+GtkWidget *ldap_classes_page_new (TConnection *tcnc, const gchar *dn);
const gchar *ldap_classes_page_get_current_class (LdapClassesPage *ldap_classes_page);
void ldap_classes_page_set_current_class (LdapClassesPage *ldap_classes_page, const gchar
*classname);
diff --git a/tools/browser/ldap-browser/ldap-entries-page.c b/tools/browser/ldap-browser/ldap-entries-page.c
index 9b7e3d7..6fd015c 100644
--- a/tools/browser/ldap-browser/ldap-entries-page.c
+++ b/tools/browser/ldap-browser/ldap-entries-page.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
- * Copyright (C) 2011 - 2012 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2011 - 2014 Vivien Malerba <malerba gnome-db org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -23,18 +23,19 @@
#include "hierarchy-view.h"
#include "entry-properties.h"
#include "../dnd.h"
-#include "../support.h"
+#include "../ui-support.h"
#include "../gdaui-bar.h"
#include "../browser-page.h"
-#include "../browser-stock-icons.h"
#include "../browser-window.h"
-#include "../browser-connection.h"
+#include "common/t-connection.h"
#include <virtual/gda-ldap-connection.h>
#include "mgr-ldap-entries.h"
#include <libgda-ui/gdaui-tree-store.h>
#include "ldap-browser-perspective.h"
#include <libgda/gda-debug-macros.h>
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+
typedef struct {
gchar *dn;
GtkTreeRowReference *reference;
@@ -49,7 +50,7 @@ history_item_free (HistoryItem *item)
}
struct _LdapEntriesPagePrivate {
- BrowserConnection *bcnc;
+ TConnection *tcnc;
GtkWidget *entries_view;
GtkWidget *entry_props;
@@ -114,8 +115,8 @@ ldap_entries_page_dispose (GObject *object)
/* free memory */
if (ebrowser->priv) {
- if (ebrowser->priv->bcnc)
- g_object_unref (ebrowser->priv->bcnc);
+ if (ebrowser->priv->tcnc)
+ g_object_unref (ebrowser->priv->tcnc);
if (ebrowser->priv->agroup)
g_object_unref (ebrowser->priv->agroup);
if (ebrowser->priv->history_items) {
@@ -307,14 +308,14 @@ open_class_requested_cb (G_GNUC_UNUSED EntryProperties *eprop, const gchar *clas
* Returns: a new #GtkWidget
*/
GtkWidget *
-ldap_entries_page_new (BrowserConnection *bcnc, const gchar *dn)
+ldap_entries_page_new (TConnection *tcnc, const gchar *dn)
{
LdapEntriesPage *ebrowser;
- g_return_val_if_fail (BROWSER_IS_CONNECTION (bcnc), NULL);
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
ebrowser = LDAP_ENTRIES_PAGE (g_object_new (LDAP_ENTRIES_PAGE_TYPE, NULL));
- ebrowser->priv->bcnc = g_object_ref ((GObject*) bcnc);
+ ebrowser->priv->tcnc = g_object_ref ((GObject*) tcnc);
/* header */
GtkWidget *label;
@@ -348,7 +349,7 @@ ldap_entries_page_new (BrowserConnection *bcnc, const gchar *dn)
gtk_misc_set_alignment (GTK_MISC (label), 0., yalign);
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
- hview = hierarchy_view_new (bcnc, dn);
+ hview = hierarchy_view_new (tcnc, dn);
ebrowser->priv->entries_view = hview;
sw = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC,
@@ -376,7 +377,7 @@ ldap_entries_page_new (BrowserConnection *bcnc, const gchar *dn)
gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
GtkWidget *props;
- props = entry_properties_new (bcnc);
+ props = entry_properties_new (tcnc);
gtk_box_pack_start (GTK_BOX (vbox), props, TRUE, TRUE, 0);
ebrowser->priv->entry_props = props;
g_signal_connect (props, "open-dn",
@@ -418,22 +419,22 @@ ldap_entries_page_set_current_dn (LdapEntriesPage *ldap_entries_page, const gcha
static void
action_add_to_fav_cb (G_GNUC_UNUSED GtkAction *action, LdapEntriesPage *ebrowser)
{
- ToolsFavorites *bfav;
- ToolsFavoritesAttributes fav;
+ TFavorites *bfav;
+ TFavoritesAttributes fav;
GError *error = NULL;
const gchar *cn;
hierarchy_view_get_current_dn (HIERARCHY_VIEW (ebrowser->priv->entries_view), &cn);
- memset (&fav, 0, sizeof (ToolsFavoritesAttributes));
+ memset (&fav, 0, sizeof (TFavoritesAttributes));
fav.id = -1;
- fav.type = GDA_TOOLS_FAVORITES_LDAP_DN;
+ fav.type = T_FAVORITES_LDAP_DN;
fav.name = ldap_entries_page_to_selection (ebrowser);
fav.descr = (gchar*) cn;
fav.contents = ldap_entries_page_to_selection (ebrowser);
- bfav = browser_connection_get_favorites (ebrowser->priv->bcnc);
- if (! gda_tools_favorites_add (bfav, 0, &fav, ORDER_KEY_LDAP, G_MAXINT, &error)) {
- browser_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) ebrowser),
+ bfav = t_connection_get_favorites (ebrowser->priv->tcnc);
+ if (! t_favorites_add (bfav, 0, &fav, ORDER_KEY_LDAP, G_MAXINT, &error)) {
+ ui_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) ebrowser),
_("Could not add favorite: %s"),
error && error->message ? error->message : _("No detail"));
if (error)
@@ -511,7 +512,7 @@ action_dn_forward_cb (G_GNUC_UNUSED GtkAction *action, LdapEntriesPage *ebrowser
static GtkActionEntry ui_actions[] = {
{ "LDAP", NULL, N_("_LDAP"), NULL, N_("LDAP"), NULL },
- { "AddToFav", STOCK_ADD_BOOKMARK, N_("Add to _Favorites"), NULL, N_("Add entry to favorites"),
+ { "AddToFav", /*STOCK_ADD_BOOKMARK*/ NULL, N_("Add to _Favorites"), NULL, N_("Add entry to
favorites"),
G_CALLBACK (action_add_to_fav_cb)},
{ "DnBack", GTK_STOCK_GO_BACK, N_("Previous Entry"), NULL, N_("Move back to previous LDAP entry"),
G_CALLBACK (action_dn_back_cb)},
@@ -575,9 +576,9 @@ ldap_entries_page_page_get_tab_label (BrowserPage *page, GtkWidget **out_close_b
const gchar *tab_name;
GdkPixbuf *entries_pixbuf;
- entries_pixbuf = browser_get_pixbuf_icon (BROWSER_ICON_LDAP_ORGANIZATION);
+ entries_pixbuf = ui_get_pixbuf_icon (UI_ICON_LDAP_ORGANIZATION);
tab_name = _("LDAP entries");
- return browser_make_tab_label_with_pixbuf (tab_name,
+ return ui_make_tab_label_with_pixbuf (tab_name,
entries_pixbuf,
out_close_button ? TRUE : FALSE, out_close_button);
}
diff --git a/tools/browser/ldap-browser/ldap-entries-page.h b/tools/browser/ldap-browser/ldap-entries-page.h
index 5f95469..4e96682 100644
--- a/tools/browser/ldap-browser/ldap-entries-page.h
+++ b/tools/browser/ldap-browser/ldap-entries-page.h
@@ -21,7 +21,7 @@
#define __LDAP_ENTRIES_PAGE_H__
#include <gtk/gtk.h>
-#include "../browser-connection.h"
+#include "common/t-connection.h"
G_BEGIN_DECLS
@@ -46,7 +46,7 @@ struct _LdapEntriesPageClass {
GType ldap_entries_page_get_type (void) G_GNUC_CONST;
-GtkWidget *ldap_entries_page_new (BrowserConnection *bcnc, const gchar *dn);
+GtkWidget *ldap_entries_page_new (TConnection *tcnc, const gchar *dn);
const gchar *ldap_entries_page_get_current_dn (LdapEntriesPage *ldap_entries_page);
void ldap_entries_page_set_current_dn (LdapEntriesPage *ldap_entries_page, const gchar *dn);
diff --git a/tools/browser/ldap-browser/ldap-favorite-selector.c
b/tools/browser/ldap-browser/ldap-favorite-selector.c
index 7075d50..295b900 100644
--- a/tools/browser/ldap-browser/ldap-favorite-selector.c
+++ b/tools/browser/ldap-browser/ldap-favorite-selector.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
- * Copyright (C) 2011 - 2012 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2011 - 2014 Vivien Malerba <malerba gnome-db org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -25,14 +25,14 @@
#include "../mgr-favorites.h"
#include <libgda-ui/gdaui-tree-store.h>
#include "../dnd.h"
-#include "../support.h"
+#include "../ui-support.h"
#include "marshal.h"
#include "../gdaui-bar.h"
#include <gdk/gdkkeysyms.h>
#include <libgda-ui/internal/popup-container.h>
struct _LdapFavoriteSelectorPrivate {
- BrowserConnection *bcnc;
+ TConnection *tcnc;
GdaTree *tree;
GtkWidget *treeview;
guint idle_update_favorites;
@@ -51,7 +51,7 @@ static void ldap_favorite_selector_init (LdapFavoriteSelector *fsel,
LdapFavoriteSelectorClass *klass);
static void ldap_favorite_selector_dispose (GObject *object);
-static void favorites_changed_cb (ToolsFavorites *bfav, LdapFavoriteSelector *fsel);
+static void favorites_changed_cb (TFavorites *bfav, LdapFavoriteSelector *fsel);
enum {
SELECTION_CHANGED,
@@ -125,10 +125,10 @@ ldap_favorite_selector_dispose (GObject *object)
if (fsel->priv->tree)
g_object_unref (fsel->priv->tree);
- if (fsel->priv->bcnc) {
- g_signal_handlers_disconnect_by_func (browser_connection_get_favorites
(fsel->priv->bcnc),
+ if (fsel->priv->tcnc) {
+ g_signal_handlers_disconnect_by_func (t_connection_get_favorites (fsel->priv->tcnc),
G_CALLBACK (favorites_changed_cb), fsel);
- g_object_unref (fsel->priv->bcnc);
+ g_object_unref (fsel->priv->tcnc);
}
if (fsel->priv->popup_properties)
@@ -176,16 +176,16 @@ favorite_delete_selected (LdapFavoriteSelector *fsel)
select = gtk_tree_view_get_selection (GTK_TREE_VIEW (fsel->priv->treeview));
if (gtk_tree_selection_get_selected (select, &model, &iter)) {
- ToolsFavorites *bfav;
- ToolsFavoritesAttributes fav;
+ TFavorites *bfav;
+ TFavoritesAttributes fav;
GError *lerror = NULL;
- memset (&fav, 0, sizeof (ToolsFavoritesAttributes));
+ memset (&fav, 0, sizeof (TFavoritesAttributes));
gtk_tree_model_get (model, &iter,
COLUMN_ID, &(fav.id), -1);
- bfav = browser_connection_get_favorites (fsel->priv->bcnc);
- if (!gda_tools_favorites_delete (bfav, 0, &fav, NULL)) {
- browser_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*)fsel),
+ bfav = t_connection_get_favorites (fsel->priv->tcnc);
+ if (!t_favorites_delete (bfav, 0, &fav, NULL)) {
+ ui_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*)fsel),
_("Could not remove favorite: %s"),
lerror && lerror->message ? lerror->message : _("No detail"));
if (lerror)
@@ -217,7 +217,7 @@ selection_changed_cb (GtkTreeView *treeview, G_GNUC_UNUSED GtkTreePath *path,
if (gtk_tree_selection_get_selected (select, &model, &iter)) {
gchar *str;
gint fav_id;
- ToolsFavoritesType fav_type;
+ TFavoritesType fav_type;
gtk_tree_model_get (model, &iter,
COLUMN_ID, &fav_id,
COLUMN_FAVTYPE, &fav_type,
@@ -231,24 +231,24 @@ selection_changed_cb (GtkTreeView *treeview, G_GNUC_UNUSED GtkTreePath *path,
static gboolean
prop_save_timeout (LdapFavoriteSelector *fsel)
{
- ToolsFavorites *bfav;
- ToolsFavoritesAttributes fav;
+ TFavorites *bfav;
+ TFavoritesAttributes fav;
GError *error = NULL;
gboolean allok;
- bfav = browser_connection_get_favorites (fsel->priv->bcnc);
+ bfav = t_connection_get_favorites (fsel->priv->tcnc);
- memset (&fav, 0, sizeof (ToolsFavoritesAttributes));
+ memset (&fav, 0, sizeof (TFavoritesAttributes));
fav.id = fsel->priv->properties_id;
- fav.type = GDA_TOOLS_FAVORITES_LDAP_DN;
+ fav.type = T_FAVORITES_LDAP_DN;
fav.name = (gchar*) gtk_entry_get_text (GTK_ENTRY (fsel->priv->properties_name));
fav.descr = (gchar*) gtk_entry_get_text (GTK_ENTRY (fsel->priv->properties_descr));
fav.contents = (gchar*) gtk_entry_get_text (GTK_ENTRY (fsel->priv->properties_name));
- allok = gda_tools_favorites_add (bfav, 0, &fav, ORDER_KEY_LDAP,
+ allok = t_favorites_add (bfav, 0, &fav, ORDER_KEY_LDAP,
fsel->priv->properties_position, &error);
if (! allok) {
- browser_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) fsel),
+ ui_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) fsel),
_("Could not add favorite: %s"),
error && error->message ? error->message : _("No detail"));
if (error)
@@ -374,13 +374,13 @@ do_popup_menu (G_GNUC_UNUSED GtkWidget *widget, GdkEventButton *event, LdapFavor
g_signal_connect (menu, "deactivate",
G_CALLBACK (gtk_widget_hide), NULL);
- mitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_PROPERTIES, NULL);
+ mitem = gtk_menu_item_new_with_label (_("_Properties"));
gtk_menu_shell_append (GTK_MENU_SHELL (menu), mitem);
gtk_widget_show (mitem);
g_signal_connect (mitem, "activate",
G_CALLBACK (properties_activated_cb), fsel);
- mitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
+ mitem = gtk_menu_item_new_with_label (_("_Delete"));
gtk_menu_shell_append (GTK_MENU_SHELL (menu), mitem);
gtk_widget_show (mitem);
g_signal_connect (mitem, "activate",
@@ -435,33 +435,33 @@ static gboolean tree_store_drag_get_cb (GdauiTreeStore *store, const gchar *path
* Returns: a new #GtkWidget
*/
GtkWidget *
-ldap_favorite_selector_new (BrowserConnection *bcnc)
+ldap_favorite_selector_new (TConnection *tcnc)
{
LdapFavoriteSelector *fsel;
GdaTreeManager *manager;
gchar *signame;
- g_return_val_if_fail (BROWSER_IS_CONNECTION (bcnc), NULL);
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
fsel = LDAP_FAVORITE_SELECTOR (g_object_new (LDAP_FAVORITE_SELECTOR_TYPE, NULL));
- fsel->priv->bcnc = g_object_ref (bcnc);
+ fsel->priv->tcnc = g_object_ref (tcnc);
signame = g_strdup_printf ("favorites-changed::%s",
- gda_tools_favorites_type_to_string (GDA_TOOLS_FAVORITES_LDAP_DN));
- g_signal_connect (browser_connection_get_favorites (fsel->priv->bcnc), signame,
+ t_favorites_type_to_string (T_FAVORITES_LDAP_DN));
+ g_signal_connect (t_connection_get_favorites (fsel->priv->tcnc), signame,
G_CALLBACK (favorites_changed_cb), fsel);
g_free (signame);
signame = g_strdup_printf ("favorites-changed::%s",
- gda_tools_favorites_type_to_string (GDA_TOOLS_FAVORITES_LDAP_CLASS));
- g_signal_connect (browser_connection_get_favorites (fsel->priv->bcnc), signame,
+ t_favorites_type_to_string (T_FAVORITES_LDAP_CLASS));
+ g_signal_connect (t_connection_get_favorites (fsel->priv->tcnc), signame,
G_CALLBACK (favorites_changed_cb), fsel);
g_free (signame);
/* create tree managers */
fsel->priv->tree = gda_tree_new ();
- manager = mgr_favorites_new (bcnc, GDA_TOOLS_FAVORITES_LDAP_DN, ORDER_KEY_LDAP);
+ manager = mgr_favorites_new (tcnc, T_FAVORITES_LDAP_DN, ORDER_KEY_LDAP);
gda_tree_add_manager (fsel->priv->tree, manager);
g_object_unref (manager);
- manager = mgr_favorites_new (bcnc, GDA_TOOLS_FAVORITES_LDAP_CLASS, ORDER_KEY_LDAP);
+ manager = mgr_favorites_new (tcnc, T_FAVORITES_LDAP_CLASS, ORDER_KEY_LDAP);
gda_tree_add_manager (fsel->priv->tree, manager);
g_object_unref (manager);
@@ -477,7 +477,7 @@ ldap_favorite_selector_new (BrowserConnection *bcnc)
str = g_strdup_printf ("<b>%s</b>", _("Favorites"));
label = gdaui_bar_new (str);
g_free (str);
- gdaui_bar_set_icon_from_pixbuf (GDAUI_BAR (label), browser_get_pixbuf_icon (BROWSER_ICON_BOOKMARK));
+ gdaui_bar_set_icon_from_pixbuf (GDAUI_BAR (label), ui_get_pixbuf_icon (UI_ICON_BOOKMARK));
gtk_box_pack_start (GTK_BOX (fsel), label, FALSE, FALSE, 0);
gtk_widget_show (label);
@@ -496,7 +496,7 @@ ldap_favorite_selector_new (BrowserConnection *bcnc)
G_TYPE_STRING, "descr",
G_TYPE_UINT, MGR_FAVORITES_TYPE_ATT_NAME);
- treeview = browser_make_tree_view (model);
+ treeview = ui_make_tree_view (model);
fsel->priv->treeview = treeview;
g_object_unref (model);
@@ -572,20 +572,20 @@ static gboolean
tree_store_drag_drop_cb (G_GNUC_UNUSED GdauiTreeStore *store, const gchar *path,
GtkSelectionData *selection_ldap, LdapFavoriteSelector *fsel)
{
- ToolsFavorites *bfav;
- ToolsFavoritesAttributes fav;
+ TFavorites *bfav;
+ TFavoritesAttributes fav;
GError *error = NULL;
gint pos;
gboolean retval = TRUE;
gint id;
- bfav = browser_connection_get_favorites (fsel->priv->bcnc);
+ bfav = t_connection_get_favorites (fsel->priv->tcnc);
- id = gda_tools_favorites_find (bfav, 0, (gchar*) gtk_selection_data_get_data (selection_ldap),
+ id = t_favorites_find (bfav, 0, (gchar*) gtk_selection_data_get_data (selection_ldap),
&fav, NULL);
if (id < 0) {
- memset (&fav, 0, sizeof (ToolsFavoritesAttributes));
+ memset (&fav, 0, sizeof (TFavoritesAttributes));
fav.id = -1;
- fav.type = GDA_TOOLS_FAVORITES_LDAP_DN;
+ fav.type = T_FAVORITES_LDAP_DN;
fav.name = (gchar*) gtk_selection_data_get_data (selection_ldap);
fav.descr = NULL;
fav.contents = (gchar*) gtk_selection_data_get_data (selection_ldap);
@@ -594,8 +594,8 @@ tree_store_drag_drop_cb (G_GNUC_UNUSED GdauiTreeStore *store, const gchar *path,
pos = atoi (path);
/*g_print ("%s() path => %s, pos: %d\n", __FUNCTION__, path, pos);*/
- if (! gda_tools_favorites_add (bfav, 0, &fav, ORDER_KEY_LDAP, pos, &error)) {
- browser_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) fsel),
+ if (! t_favorites_add (bfav, 0, &fav, ORDER_KEY_LDAP, pos, &error)) {
+ ui_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) fsel),
_("Could not add favorite: %s"),
error && error->message ? error->message : _("No detail"));
if (error)
@@ -604,7 +604,7 @@ tree_store_drag_drop_cb (G_GNUC_UNUSED GdauiTreeStore *store, const gchar *path,
}
if (id >= 0)
- gda_tools_favorites_reset_attributes (&fav);
+ t_favorites_reset_attributes (&fav);
return retval;
}
@@ -645,7 +645,7 @@ tree_store_drag_get_cb (G_GNUC_UNUSED GdauiTreeStore *store, const gchar *path,
}
static void
-favorites_changed_cb (G_GNUC_UNUSED ToolsFavorites *bfav, LdapFavoriteSelector *fsel)
+favorites_changed_cb (G_GNUC_UNUSED TFavorites *bfav, LdapFavoriteSelector *fsel)
{
if (! gda_tree_update_all (fsel->priv->tree, NULL)) {
if (fsel->priv->idle_update_favorites == 0)
diff --git a/tools/browser/ldap-browser/ldap-favorite-selector.h
b/tools/browser/ldap-browser/ldap-favorite-selector.h
index 95bb519..478b235 100644
--- a/tools/browser/ldap-browser/ldap-favorite-selector.h
+++ b/tools/browser/ldap-browser/ldap-favorite-selector.h
@@ -21,7 +21,7 @@
#define __LDAP_FAVORITE_SELECTOR_H__
#include <gtk/gtk.h>
-#include "../browser-connection.h"
+#include "common/t-connection.h"
G_BEGIN_DECLS
@@ -44,12 +44,12 @@ struct _LdapFavoriteSelectorClass {
GtkBoxClass parent_class;
void (*selection_changed) (LdapFavoriteSelector *sel, gint fav_id,
- ToolsFavoritesType fav_type, const gchar *fav_contents);
+ TFavoritesType fav_type, const gchar *fav_contents);
};
GType ldap_favorite_selector_get_type (void) G_GNUC_CONST;
-GtkWidget *ldap_favorite_selector_new (BrowserConnection *bcnc);
+GtkWidget *ldap_favorite_selector_new (TConnection *tcnc);
G_END_DECLS
diff --git a/tools/browser/ldap-browser/ldap-search-page.c b/tools/browser/ldap-browser/ldap-search-page.c
index 4055c18..35e9c65 100644
--- a/tools/browser/ldap-browser/ldap-search-page.c
+++ b/tools/browser/ldap-browser/ldap-search-page.c
@@ -22,15 +22,17 @@
#include "ldap-search-page.h"
#include "filter-editor.h"
#include "../gdaui-bar.h"
+#include "../ui-support.h"
#include "../browser-page.h"
#include "../browser-window.h"
-#include "../browser-connection.h"
+#include "common/t-connection.h"
#include <virtual/gda-ldap-connection.h>
-#include <common/ui-formgrid.h>
-#include "../browser-stock-icons.h"
+#include "../ui-formgrid.h"
#include "vtable-dialog.h"
#include <libgda/gda-debug-macros.h>
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+
typedef struct {
gchar *base_dn;
gchar *filter;
@@ -51,7 +53,7 @@ history_item_free (HistoryItem *item)
}
struct _LdapSearchPagePrivate {
- BrowserConnection *bcnc;
+ TConnection *tcnc;
GtkWidget *search_entry;
GtkWidget *result_view;
@@ -116,8 +118,8 @@ ldap_search_page_dispose (GObject *object)
/* free memory */
if (epage->priv) {
- if (epage->priv->bcnc)
- g_object_unref (epage->priv->bcnc);
+ if (epage->priv->tcnc)
+ g_object_unref (epage->priv->tcnc);
if (epage->priv->agroup)
g_object_unref (epage->priv->agroup);
if (epage->priv->history_items) {
@@ -213,7 +215,7 @@ filter_exec_clicked_cb (G_GNUC_UNUSED GtkWidget *button, LdapSearchPage *epage)
&base_dn, &filter, &attributes, &scope);
GdaDataModel *model;
- model = browser_connection_ldap_search (epage->priv->bcnc,
+ model = t_connection_ldap_search (epage->priv->tcnc,
base_dn, filter,
attributes, scope, &lerror);
g_free (base_dn);
@@ -252,20 +254,20 @@ search_entry_activated_cb (G_GNUC_UNUSED FilterEditor *feditor, LdapSearchPage *
/**
* ldap_search_page_new:
- * @bcnc:
+ * @tcnc:
* @base_dn: the base DN to put in the search page by default
*
* Returns: a new #GtkWidget
*/
GtkWidget *
-ldap_search_page_new (BrowserConnection *bcnc, const gchar *base_dn)
+ldap_search_page_new (TConnection *tcnc, const gchar *base_dn)
{
LdapSearchPage *epage;
- g_return_val_if_fail (BROWSER_IS_CONNECTION (bcnc), NULL);
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
epage = LDAP_SEARCH_PAGE (g_object_new (LDAP_SEARCH_PAGE_TYPE, NULL));
- epage->priv->bcnc = g_object_ref ((GObject*) bcnc);
+ epage->priv->tcnc = g_object_ref ((GObject*) tcnc);
/* header */
GtkWidget *label;
@@ -292,9 +294,9 @@ ldap_search_page_new (BrowserConnection *bcnc, const gchar *base_dn)
hb = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_box_pack_start (GTK_BOX (epage), hb, FALSE, FALSE, 3);
- wid = filter_editor_new (bcnc);
+ wid = filter_editor_new (tcnc);
if (!base_dn)
- base_dn = browser_connection_ldap_get_base_dn (bcnc);
+ base_dn = t_connection_ldap_get_base_dn (tcnc);
filter_editor_set_settings (FILTER_EDITOR (wid), base_dn, NULL, NULL,
GDA_LDAP_SEARCH_SUBTREE);
gtk_box_pack_start (GTK_BOX (hb), wid, TRUE, TRUE, 0);
@@ -306,14 +308,14 @@ ldap_search_page_new (BrowserConnection *bcnc, const gchar *base_dn)
gtk_button_box_set_layout (GTK_BUTTON_BOX (bb), GTK_BUTTONBOX_END);
gtk_box_pack_start (GTK_BOX (hb), bb, FALSE, FALSE, 5);
- button = browser_make_small_button (FALSE, FALSE, _("Clear"),
- GTK_STOCK_CLEAR, _("Clear the search settings"));
+ button = ui_make_small_button (FALSE, FALSE, _("Clear"),
+ GTK_STOCK_CLEAR, _("Clear the search settings"));
gtk_box_pack_start (GTK_BOX (bb), button, TRUE, TRUE, 0);
g_signal_connect (button, "clicked",
G_CALLBACK (filter_clear_clicked_cb), epage);
- button = browser_make_small_button (FALSE, FALSE, _("Execute"),
- GTK_STOCK_EXECUTE, _("Execute LDAP search"));
+ button = ui_make_small_button (FALSE, FALSE, _("Execute"),
+ GTK_STOCK_EXECUTE, _("Execute LDAP search"));
gtk_box_pack_start (GTK_BOX (bb), button, TRUE, TRUE, 0);
g_signal_connect (button, "clicked",
G_CALLBACK (filter_exec_clicked_cb), epage);
@@ -349,7 +351,7 @@ action_define_as_table_cb (G_GNUC_UNUSED GtkAction *action, LdapSearchPage *epag
parent = (GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) epage);
- dlg = vtable_dialog_new (parent, epage->priv->bcnc);
+ dlg = vtable_dialog_new (parent, epage->priv->tcnc);
res = gtk_dialog_run (GTK_DIALOG (dlg));
gtk_widget_hide (dlg);
if (res == GTK_RESPONSE_OK) {
@@ -363,16 +365,16 @@ action_define_as_table_cb (G_GNUC_UNUSED GtkAction *action, LdapSearchPage *epag
tname = vtable_dialog_get_table_name (VTABLE_DIALOG (dlg));
replace = vtable_dialog_get_replace_if_exists (VTABLE_DIALOG (dlg));
if (replace)
- browser_connection_undeclare_table (epage->priv->bcnc, tname, NULL);
- if (! browser_connection_declare_table (epage->priv->bcnc, tname, base_dn, filter,
+ t_connection_undeclare_table (epage->priv->tcnc, tname, NULL);
+ if (! t_connection_declare_table (epage->priv->tcnc, tname, base_dn, filter,
attributes, scope, &lerror)) {
- browser_show_error (parent,
+ ui_show_error (parent,
_("Could not define virtual table for this LDAP search: %s"),
lerror && lerror->message ? lerror->message : _("No detail"));
g_clear_error (&lerror);
}
else
- browser_show_message (parent,
+ ui_show_message (parent,
_("Virtual table '%s' for this LDAP search has been defined"),
tname);
}
@@ -449,7 +451,7 @@ action_class_forward_cb (G_GNUC_UNUSED GtkAction *action, LdapSearchPage *epage)
*/
static GtkActionEntry ui_actions[] = {
{ "LDAP", NULL, N_("_LDAP"), NULL, N_("LDAP"), NULL },
- { "DefineAsTable", BROWSER_STOCK_TABLE_ADD, N_("Define as Table"), NULL, N_("Define search as a
virtual table"),
+ { "DefineAsTable", /*BROWSER_STOCK_TABLE_ADD*/ NULL, N_("Define as Table"), NULL, N_("Define search
as a virtual table"),
G_CALLBACK (action_define_as_table_cb)},
/*
{ "DnBack", GTK_STOCK_GO_BACK, N_("Previous class"), NULL, N_("Move back to previous LDAP class"),
@@ -524,7 +526,7 @@ ldap_search_page_page_get_tab_label (BrowserPage *page, GtkWidget **out_close_bu
search_pixbuf = gtk_widget_render_icon_pixbuf (GTK_WIDGET (page), GTK_STOCK_FIND, GTK_ICON_SIZE_MENU);
tab_name = _("LDAP search");
- return browser_make_tab_label_with_pixbuf (tab_name,
+ return ui_make_tab_label_with_pixbuf (tab_name,
search_pixbuf,
out_close_button ? TRUE : FALSE, out_close_button);
}
diff --git a/tools/browser/ldap-browser/ldap-search-page.h b/tools/browser/ldap-browser/ldap-search-page.h
index 8520318..92a0a1f 100644
--- a/tools/browser/ldap-browser/ldap-search-page.h
+++ b/tools/browser/ldap-browser/ldap-search-page.h
@@ -21,7 +21,7 @@
#define __LDAP_SEARCH_PAGE_H__
#include <gtk/gtk.h>
-#include "../browser-connection.h"
+#include "common/t-connection.h"
G_BEGIN_DECLS
@@ -46,7 +46,7 @@ struct _LdapSearchPageClass {
GType ldap_search_page_get_type (void) G_GNUC_CONST;
-GtkWidget *ldap_search_page_new (BrowserConnection *bcnc, const gchar *base_dn);
+GtkWidget *ldap_search_page_new (TConnection *tcnc, const gchar *base_dn);
G_END_DECLS
diff --git a/tools/browser/ldap-browser/mgr-ldap-classes.c b/tools/browser/ldap-browser/mgr-ldap-classes.c
index 6a2ea8b..7129105 100644
--- a/tools/browser/ldap-browser/mgr-ldap-classes.c
+++ b/tools/browser/ldap-browser/mgr-ldap-classes.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2011 - 2012 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2011 - 2014 Vivien Malerba <malerba gnome-db org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -21,9 +21,10 @@
#include "mgr-ldap-classes.h"
#include "gda-tree-node.h"
#include <sqlite/virtual/gda-ldap-connection.h>
+#include "../ui-support.h"
struct _MgrLdapClassesPriv {
- BrowserConnection *bcnc;
+ TConnection *tcnc;
gchar *class;
gboolean flat;
};
@@ -71,8 +72,8 @@ mgr_ldap_classes_dispose (GObject *object)
g_return_if_fail (MGR_IS_LDAP_CLASSES (mgr));
if (mgr->priv) {
- if (mgr->priv->bcnc)
- g_object_unref (mgr->priv->bcnc);
+ if (mgr->priv->tcnc)
+ g_object_unref (mgr->priv->tcnc);
g_free (mgr->priv->class);
g_free (mgr->priv);
mgr->priv = NULL;
@@ -126,14 +127,14 @@ mgr_ldap_classes_get_type (void)
* Returns: (transfer full): a new #GdaTreeManager object
*/
GdaTreeManager*
-mgr_ldap_classes_new (BrowserConnection *bcnc, gboolean flat, const gchar *classname)
+mgr_ldap_classes_new (TConnection *tcnc, gboolean flat, const gchar *classname)
{
MgrLdapClasses *mgr;
- g_return_val_if_fail (BROWSER_IS_CONNECTION (bcnc), NULL);
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
mgr = (MgrLdapClasses*) g_object_new (MGR_TYPE_LDAP_CLASSES, NULL);
- mgr->priv->bcnc = g_object_ref (bcnc);
+ mgr->priv->tcnc = g_object_ref (tcnc);
mgr->priv->flat = flat;
if (!flat) {
if (classname)
@@ -181,7 +182,7 @@ mgr_ldap_classes_update_children_nonflat (MgrLdapClasses *mgr, GdaTreeNode *node
GError **error)
{
gchar *real_class = NULL;
- if (!mgr->priv->bcnc) {
+ if (!mgr->priv->tcnc) {
g_set_error (error, GDA_TREE_MANAGER_ERROR, GDA_TREE_MANAGER_UNKNOWN_ERROR,
"%s", _("No LDAP connection specified"));
if (out_error)
@@ -207,14 +208,14 @@ mgr_ldap_classes_update_children_nonflat (MgrLdapClasses *mgr, GdaTreeNode *node
gboolean list_to_free = FALSE;
if (real_class) {
GdaLdapClass *lcl;
- lcl = browser_connection_get_class_info (mgr->priv->bcnc, real_class);
+ lcl = t_connection_get_class_info (mgr->priv->tcnc, real_class);
if (!lcl)
goto onerror;
classes_list = (GSList*) lcl->children;
}
else {
/* sort by kind */
- classes_list = g_slist_copy ((GSList*) browser_connection_get_top_classes (mgr->priv->bcnc));
+ classes_list = g_slist_copy ((GSList*) t_connection_get_top_classes (mgr->priv->tcnc));
classes_list = g_slist_sort (classes_list, (GCompareFunc) class_sort_func);
list_to_free = TRUE;
}
@@ -237,7 +238,7 @@ mgr_ldap_classes_update_children_nonflat (MgrLdapClasses *mgr, GdaTreeNode *node
gda_value_free (value);
/* icon */
- pixbuf = browser_get_pixbuf_for_ldap_class (sub->kind);
+ pixbuf = ui_connection_ldap_icon_for_class_kind (sub->kind);
value = gda_value_new (G_TYPE_OBJECT);
g_value_set_object (value, pixbuf);
gda_tree_node_set_node_attribute (snode, "icon", value, NULL);
@@ -269,7 +270,7 @@ mgr_ldap_classes_update_children_flat (MgrLdapClasses *mgr, GdaTreeNode *node,
gboolean *out_error,
GError **error)
{
- if (!mgr->priv->bcnc) {
+ if (!mgr->priv->tcnc) {
g_set_error (error, GDA_TREE_MANAGER_ERROR, GDA_TREE_MANAGER_UNKNOWN_ERROR,
"%s", _("No LDAP connection specified"));
if (out_error)
@@ -279,7 +280,7 @@ mgr_ldap_classes_update_children_flat (MgrLdapClasses *mgr, GdaTreeNode *node,
const GSList *top_classes_list;
GSList *list = NULL, *classes_list = NULL;
- top_classes_list = browser_connection_get_top_classes (mgr->priv->bcnc);
+ top_classes_list = t_connection_get_top_classes (mgr->priv->tcnc);
for (list = (GSList*) top_classes_list; list; list = list->next) {
GdaLdapClass *lcl;
lcl = (GdaLdapClass*) list->data;
@@ -300,7 +301,7 @@ mgr_ldap_classes_update_children_flat (MgrLdapClasses *mgr, GdaTreeNode *node,
if (kind != sub->kind) {
/* add extra node as separator */
const gchar *tmp;
- tmp = browser_get_kind_for_ldap_class (sub->kind);
+ tmp = ui_connection_ldap_class_kind_to_string (sub->kind);
snode = gda_tree_manager_create_node ((GdaTreeManager*) mgr, node, tmp);
list = g_slist_prepend (list, snode);
kind = sub->kind;
@@ -311,7 +312,7 @@ mgr_ldap_classes_update_children_flat (MgrLdapClasses *mgr, GdaTreeNode *node,
gda_value_free (value);
/* icon */
- pixbuf = browser_get_pixbuf_for_ldap_class (sub->kind);
+ pixbuf = ui_connection_ldap_icon_for_class_kind (sub->kind);
value = gda_value_new (G_TYPE_OBJECT);
g_value_set_object (value, pixbuf);
gda_tree_node_set_node_attribute (snode, "icon", value, NULL);
@@ -325,7 +326,7 @@ mgr_ldap_classes_update_children_flat (MgrLdapClasses *mgr, GdaTreeNode *node,
gda_value_free (value);
/* icon */
- pixbuf = browser_get_pixbuf_for_ldap_class (sub->kind);
+ pixbuf = ui_connection_ldap_icon_for_class_kind (sub->kind);
value = gda_value_new (G_TYPE_OBJECT);
g_value_set_object (value, pixbuf);
gda_tree_node_set_node_attribute (snode, "icon", value, NULL);
diff --git a/tools/browser/ldap-browser/mgr-ldap-classes.h b/tools/browser/ldap-browser/mgr-ldap-classes.h
index 9dd101d..9baf94c 100644
--- a/tools/browser/ldap-browser/mgr-ldap-classes.h
+++ b/tools/browser/ldap-browser/mgr-ldap-classes.h
@@ -19,7 +19,7 @@
#ifndef __MGR_LDAP_CLASSES_H__
#define __MGR_LDAP_CLASSES_H__
-#include "../browser-connection.h"
+#include "common/t-connection.h"
#include "gda-tree-manager.h"
G_BEGIN_DECLS
@@ -45,7 +45,7 @@ struct _MgrLdapClassesClass {
};
GType mgr_ldap_classes_get_type (void) G_GNUC_CONST;
-GdaTreeManager* mgr_ldap_classes_new (BrowserConnection *bcnc, gboolean flat, const gchar
*classname);
+GdaTreeManager* mgr_ldap_classes_new (TConnection *tcnc, gboolean flat, const gchar *classname);
G_END_DECLS
diff --git a/tools/browser/ldap-browser/mgr-ldap-entries.c b/tools/browser/ldap-browser/mgr-ldap-entries.c
index 4f192e8..1d83bef 100644
--- a/tools/browser/ldap-browser/mgr-ldap-entries.c
+++ b/tools/browser/ldap-browser/mgr-ldap-entries.c
@@ -21,9 +21,10 @@
#include <libgda/libgda.h>
#include "mgr-ldap-entries.h"
#include <libgda/gda-tree-node.h>
+#include "../ui-support.h"
struct _MgrLdapEntriesPriv {
- BrowserConnection *bcnc;
+ TConnection *tcnc;
gchar *dn;
};
@@ -71,8 +72,8 @@ mgr_ldap_entries_dispose (GObject *object)
g_return_if_fail (MGR_IS_LDAP_ENTRIES (mgr));
if (mgr->priv) {
- if (mgr->priv->bcnc)
- g_object_unref (mgr->priv->bcnc);
+ if (mgr->priv->tcnc)
+ g_object_unref (mgr->priv->tcnc);
g_free (mgr->priv->dn);
g_free (mgr->priv);
mgr->priv = NULL;
@@ -117,7 +118,7 @@ mgr_ldap_entries_get_type (void)
/**
* mgr_ldap_entries_new:
- * @cnc: a #BrowserConnection object
+ * @cnc: a #TConnection object
* @dn: (allow-none): a schema name or %NULL
*
* Creates a new #BrowserTreeManager object which will list the children of the LDAP entry which
Distinguished name
@@ -127,14 +128,14 @@ mgr_ldap_entries_get_type (void)
* Returns: (transfer full): a new #BrowserTreeManager object
*/
GdaTreeManager*
-mgr_ldap_entries_new (BrowserConnection *bcnc, const gchar *dn)
+mgr_ldap_entries_new (TConnection *tcnc, const gchar *dn)
{
MgrLdapEntries *mgr;
- g_return_val_if_fail (BROWSER_IS_CONNECTION (bcnc), NULL);
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
mgr = (MgrLdapEntries*) g_object_new (MGR_TYPE_LDAP_ENTRIES, NULL);
- mgr->priv->bcnc = g_object_ref (bcnc);
+ mgr->priv->tcnc = g_object_ref (tcnc);
if (dn)
mgr->priv->dn = g_strdup (dn);
@@ -172,7 +173,7 @@ mgr_ldap_entries_update_children (GdaTreeManager *manager, GdaTreeNode *node,
MgrLdapEntries *mgr = MGR_LDAP_ENTRIES (manager);
gchar *real_dn = NULL;
- g_return_val_if_fail (mgr->priv->bcnc, NULL);
+ g_return_val_if_fail (mgr->priv->tcnc, NULL);
if (mgr->priv->dn)
real_dn = g_strdup (mgr->priv->dn);
@@ -186,7 +187,7 @@ mgr_ldap_entries_update_children (GdaTreeManager *manager, GdaTreeNode *node,
GdaLdapEntry **entries;
gchar *attrs[] = {"objectClass", "cn", NULL};
- entries = browser_connection_ldap_get_entry_children (mgr->priv->bcnc, real_dn, attrs, error);
+ entries = t_connection_ldap_get_entry_children (mgr->priv->tcnc, real_dn, attrs, error);
if (entries) {
guint i;
@@ -238,7 +239,7 @@ mgr_ldap_entries_update_children (GdaTreeManager *manager, GdaTreeNode *node,
/* icon */
GdkPixbuf *pixbuf;
attr = g_hash_table_lookup (lentry->attributes_hash, "objectClass");
- pixbuf = browser_connection_ldap_icon_for_class (attr);
+ pixbuf = ui_connection_ldap_icon_for_class (attr);
dnv = gda_value_new (G_TYPE_OBJECT);
g_value_set_object (dnv, pixbuf);
diff --git a/tools/browser/ldap-browser/mgr-ldap-entries.h b/tools/browser/ldap-browser/mgr-ldap-entries.h
index f1ae34a..3014aaa 100644
--- a/tools/browser/ldap-browser/mgr-ldap-entries.h
+++ b/tools/browser/ldap-browser/mgr-ldap-entries.h
@@ -19,7 +19,7 @@
#ifndef __MGR_LDAP_ENTRIES_H__
#define __MGR_LDAP_ENTRIES_H__
-#include "../browser-connection.h"
+#include "common/t-connection.h"
#include <libgda/gda-tree-manager.h>
G_BEGIN_DECLS
@@ -45,7 +45,7 @@ struct _MgrLdapEntriesClass {
};
GType mgr_ldap_entries_get_type (void) G_GNUC_CONST;
-GdaTreeManager* mgr_ldap_entries_new (BrowserConnection *bcnc, const gchar *dn);
+GdaTreeManager* mgr_ldap_entries_new (TConnection *tcnc, const gchar *dn);
G_END_DECLS
diff --git a/tools/browser/ldap-browser/perspective-main.h b/tools/browser/ldap-browser/perspective-main.h
index 6bee66a..d94158a 100644
--- a/tools/browser/ldap-browser/perspective-main.h
+++ b/tools/browser/ldap-browser/perspective-main.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2009 - 2014 Vivien Malerba <malerba gnome-db org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -16,7 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#include "../decl.h"
+#include "../browser-perspective.h"
G_BEGIN_DECLS
diff --git a/tools/browser/ldap-browser/vtable-dialog.c b/tools/browser/ldap-browser/vtable-dialog.c
index 8ff4995..2e47392 100644
--- a/tools/browser/ldap-browser/vtable-dialog.c
+++ b/tools/browser/ldap-browser/vtable-dialog.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2011 - 2014 Vivien Malerba <malerba gnome-db org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -21,10 +21,12 @@
#include <gtk/gtk.h>
#include "vtable-dialog.h"
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+
#define SPACING 3
struct _VtableDialogPrivate {
- BrowserConnection *bcnc;
+ TConnection *tcnc;
GtkWidget *tname_entry;
GtkWidget *tname_replace;
};
@@ -63,8 +65,8 @@ vtable_dialog_dispose (GObject *object)
/* free memory */
if (dlg->priv) {
- if (dlg->priv->bcnc)
- g_object_unref (dlg->priv->bcnc);
+ if (dlg->priv->tcnc)
+ g_object_unref (dlg->priv->tcnc);
g_free (dlg->priv);
dlg->priv = NULL;
}
@@ -101,13 +103,13 @@ vtable_dialog_get_type (void)
* Returns: a new #GtkWidget
*/
GtkWidget *
-vtable_dialog_new (GtkWindow *parent, BrowserConnection *bcnc)
+vtable_dialog_new (GtkWindow *parent, TConnection *tcnc)
{
VtableDialog *dlg;
- g_return_val_if_fail (BROWSER_IS_CONNECTION (bcnc), NULL);
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
dlg = VTABLE_DIALOG (g_object_new (VTABLE_DIALOG_TYPE, NULL));
- dlg->priv->bcnc = g_object_ref (bcnc);
+ dlg->priv->tcnc = g_object_ref (tcnc);
if (parent)
gtk_window_set_transient_for (GTK_WINDOW (dlg), parent);
diff --git a/tools/browser/ldap-browser/vtable-dialog.h b/tools/browser/ldap-browser/vtable-dialog.h
index 5a2789e..3b56d01 100644
--- a/tools/browser/ldap-browser/vtable-dialog.h
+++ b/tools/browser/ldap-browser/vtable-dialog.h
@@ -19,7 +19,7 @@
#ifndef __VTABLE_DIALOG_H__
#define __VTABLE_DIALOG_H__
-#include "../browser-connection.h"
+#include "common/t-connection.h"
G_BEGIN_DECLS
@@ -44,7 +44,7 @@ struct _VtableDialogClass {
GType vtable_dialog_get_type (void) G_GNUC_CONST;
-GtkWidget *vtable_dialog_new (GtkWindow *parent, BrowserConnection *bcnc);
+GtkWidget *vtable_dialog_new (GtkWindow *parent, TConnection *tcnc);
const gchar *vtable_dialog_get_table_name (VtableDialog *dlg);
gboolean vtable_dialog_get_replace_if_exists (VtableDialog *dlg);
diff --git a/tools/browser/login-dialog.c b/tools/browser/login-dialog.c
index e1b470d..90640e9 100644
--- a/tools/browser/login-dialog.c
+++ b/tools/browser/login-dialog.c
@@ -19,10 +19,8 @@
*/
#include <glib/gi18n-lib.h>
-#include <libgda/binreloc/gda-binreloc.h>
#include "login-dialog.h"
-#include "browser-spinner.h"
-#include "support.h"
+#include "ui-support.h"
/*
* Main static functions
@@ -31,7 +29,7 @@ static void login_dialog_class_init (LoginDialogClass * class);
static void login_dialog_init (LoginDialog *dialog);
static void login_dialog_dispose (GObject *object);
-static GdaConnection *real_open_connection (const GdaDsnInfo *cncinfo, GError **error);
+static TConnection *real_open_connection (const GdaDsnInfo *cncinfo, GError **error);
/* get a pointer to the parents to be able to call their destructor */
static GObjectClass *parent_class = NULL;
@@ -104,33 +102,30 @@ static void
login_dialog_init (LoginDialog *dialog)
{
GtkWidget *label, *hbox, *wid;
- char *markup, *str;
+ char *markup;
GtkWidget *dcontents;
dcontents = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
dialog->priv = g_new0 (LoginDialogPrivate, 1);
gtk_dialog_add_buttons (GTK_DIALOG (dialog),
- GTK_STOCK_CONNECT,
- GTK_RESPONSE_ACCEPT,
- GTK_STOCK_CANCEL,
- GTK_RESPONSE_REJECT, NULL);
+ _("C_onnect"), GTK_RESPONSE_ACCEPT,
+ _("_Cancel"), GTK_RESPONSE_REJECT, NULL);
gtk_box_set_spacing (GTK_BOX (dcontents), 5);
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT, FALSE);
- str = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, "pixmaps",
"gda-browser-non-connected.png", NULL);
- gtk_window_set_icon_from_file (GTK_WINDOW (dialog), str, NULL);
- g_free (str);
+ GdkPixbuf *pix;
+ pix = gdk_pixbuf_new_from_resource ("/images/gda-browser-non-connected.png", NULL);
+ gtk_window_set_icon (GTK_WINDOW (dialog), pix);
+ g_object_unref (pix);
/* label and spinner */
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_container_set_border_width (GTK_CONTAINER (hbox), 10);
gtk_box_pack_start (GTK_BOX (dcontents), hbox, FALSE, FALSE, 0);
- str = gda_gbr_get_file_path (GDA_DATA_DIR, LIBGDA_ABI_NAME, "pixmaps",
"gda-browser-non-connected-big.png", NULL);
- wid = gtk_image_new_from_file (str);
- g_free (str);
+ wid = gtk_image_new_from_resource ("/images/gda-browser-non-connected-big.png");
gtk_box_pack_start (GTK_BOX (hbox), wid, FALSE, FALSE, 0);
label = gtk_label_new ("");
@@ -144,7 +139,7 @@ login_dialog_init (LoginDialog *dialog)
gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 12);
gtk_widget_show_all (hbox);
- dialog->priv->spinner = browser_spinner_new ();
+ dialog->priv->spinner = gtk_spinner_new ();
gtk_container_add (GTK_CONTAINER (hbox), dialog->priv->spinner);
/* login (not shown) */
@@ -177,7 +172,7 @@ login_dialog_dispose (GObject *object)
}
/**
- * login_dialog_new
+ * login_dialog_new:
*
* Creates a new dialog dialog
*
@@ -192,20 +187,20 @@ login_dialog_new (GtkWindow *parent)
}
/**
- * login_dialog_run
+ * login_dialog_run_open_connection:
* @dialog: a #GdaLogin object
* @retry: if set to %TRUE, then this method returns only when either a connection has been opened or the
* user gave up
* @error: a place to store errors, or %NULL
*
- * Displays the dialog and returns a new #GdaConnection, or %NULL
+ * Displays the dialog and returns a new #TConnection, or %NULL
*
- * Return: a new #GdaConnection, or %NULL
+ * Return: (transfer none): a new #TConnection, or %NULL
*/
-GdaConnection *
-login_dialog_run (LoginDialog *dialog, gboolean retry, GError **error)
+TConnection *
+login_dialog_run_open_connection (LoginDialog *dialog, gboolean retry, GError **error)
{
- GdaConnection *cnc = NULL;
+ TConnection *tcnc = NULL;
g_return_val_if_fail (LOGIN_IS_DIALOG (dialog), NULL);
@@ -215,7 +210,7 @@ login_dialog_run (LoginDialog *dialog, gboolean retry, GError **error)
result = gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_show (dialog->priv->spinner);
- browser_spinner_start (BROWSER_SPINNER (dialog->priv->spinner));
+ gtk_spinner_start (GTK_SPINNER (dialog->priv->spinner));
gtk_widget_set_sensitive (dialog->priv->login, FALSE);
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT, FALSE);
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_REJECT, FALSE);
@@ -225,14 +220,14 @@ login_dialog_run (LoginDialog *dialog, gboolean retry, GError **error)
GError *lerror = NULL;
info = gdaui_login_get_connection_information (GDAUI_LOGIN (dialog->priv->login));
- cnc = real_open_connection (info, &lerror);
- browser_spinner_stop (BROWSER_SPINNER (dialog->priv->spinner));
- if (cnc)
+ tcnc = real_open_connection (info, &lerror);
+ gtk_spinner_stop (GTK_SPINNER (dialog->priv->spinner));
+ if (tcnc)
goto out;
else {
if (retry) {
- browser_show_error (GTK_WINDOW (dialog), _("Could not open
connection:\n%s"),
- lerror && lerror->message ? lerror->message :
_("No detail"));
+ ui_show_error (GTK_WINDOW (dialog), _("Could not open
connection:\n%s"),
+ lerror && lerror->message ? lerror->message : _("No
detail"));
if (lerror)
g_error_free (lerror);
}
@@ -250,7 +245,7 @@ login_dialog_run (LoginDialog *dialog, gboolean retry, GError **error)
}
gtk_widget_set_sensitive (dialog->priv->login, TRUE);
- browser_spinner_stop (BROWSER_SPINNER (dialog->priv->spinner));
+ gtk_spinner_stop (GTK_SPINNER (dialog->priv->spinner));
gtk_widget_hide (dialog->priv->spinner);
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT, TRUE);
gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_REJECT, TRUE);
@@ -258,19 +253,19 @@ login_dialog_run (LoginDialog *dialog, gboolean retry, GError **error)
out:
gtk_widget_hide (GTK_WIDGET (dialog));
- return cnc;
+ return tcnc;
}
/**
- * real_open_connection
+ * real_open_connection:
* @cncinfo: a pointer to a #GdaDsnInfo, describing the connection to open
* @error:
*
* Opens a connection in a sub thread while running a main loop
*
- * Returns: a new #GdaConnection, or %NULL if an error occurred
+ * Returns: (transfer none): a new #TConnection, or %NULL if an error occurred
*/
-static GdaConnection *
+static TConnection *
real_open_connection (const GdaDsnInfo *cncinfo, GError **error)
{
#ifdef DUMMY
@@ -279,16 +274,15 @@ real_open_connection (const GdaDsnInfo *cncinfo, GError **error)
return NULL;
#endif
- GdaConnection *cnc;
+ TConnection *tcnc;
if (cncinfo->name)
- cnc = gda_connection_open_from_dsn (cncinfo->name, cncinfo->auth_string,
- GDA_CONNECTION_OPTIONS_AUTO_META_DATA,
- error);
- else
- cnc = gda_connection_open_from_string (cncinfo->provider, cncinfo->cnc_string,
- cncinfo->auth_string,
- GDA_CONNECTION_OPTIONS_AUTO_META_DATA,
- error);
+ tcnc = t_connection_open (NULL, cncinfo->name, cncinfo->auth_string, FALSE, error);
+ else {
+ gchar *tmp;
+ tmp = g_strdup_printf ("%s://%s", cncinfo->provider, cncinfo->cnc_string);
+ tcnc = t_connection_open (NULL, tmp, cncinfo->auth_string, FALSE, error);
+ g_free (tmp);
+ }
- return cnc;
+ return tcnc;
}
diff --git a/tools/browser/login-dialog.h b/tools/browser/login-dialog.h
index b259afa..e8f7a4e 100644
--- a/tools/browser/login-dialog.h
+++ b/tools/browser/login-dialog.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2009 - 2014 Vivien Malerba <malerba gnome-db org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -22,6 +22,7 @@
#include <libgda-ui/libgda-ui.h>
#include <gtk/gtk.h>
+#include <common/t-connection.h>
G_BEGIN_DECLS
@@ -56,9 +57,9 @@ struct _LoginDialogClass
GtkDialogClass parent_class;
};
-GType login_dialog_get_type (void) G_GNUC_CONST;
-LoginDialog *login_dialog_new (GtkWindow *parent);
-GdaConnection *login_dialog_run (LoginDialog *dialog, gboolean retry, GError **error);
+GType login_dialog_get_type (void) G_GNUC_CONST;
+LoginDialog *login_dialog_new (GtkWindow *parent);
+TConnection *login_dialog_run_open_connection (LoginDialog *dialog, gboolean retry, GError **error);
G_END_DECLS
diff --git a/tools/browser/marshal.list b/tools/browser/marshal.list
index 8dd613e..bb2ea0f 100644
--- a/tools/browser/marshal.list
+++ b/tools/browser/marshal.list
@@ -21,6 +21,5 @@
# OBJECT for GObject or derived types (GObject*)
# NONE deprecated alias for VOID
# BOOL deprecated alias for BOOLEAN
+VOID:ENUM,STRING
-VOID:BOOLEAN,STRING
-VOID:POINTER,POINTER,STRING,STRING
diff --git a/tools/browser/mgr-favorites.c b/tools/browser/mgr-favorites.c
index 9fe0102..af73e0d 100644
--- a/tools/browser/mgr-favorites.c
+++ b/tools/browser/mgr-favorites.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 - 2012 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2009 - 2014 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2010 David King <davidk openismus com>
*
* This program is free software; you can redistribute it and/or
@@ -22,7 +22,7 @@
#include <libgda/libgda.h>
#include <sql-parser/gda-sql-parser.h>
#include "mgr-favorites.h"
-#include "support.h"
+#include "ui-support.h"
#include <libgda/gda-debug-macros.h>
/* asynchronous (in idle loop) icon resolution */
@@ -39,12 +39,12 @@ icon_resolution_data_free (IconResolutionData *data)
}
struct _MgrFavoritesPriv {
- BrowserConnection *bcnc;
- ToolsFavoritesType fav_type;
- gint order_key;
+ TConnection *tcnc;
+ TFavoritesType fav_type;
+ gint order_key;
- GSList *icons_resol_list; /* list of IconResolutionData pointers */
- guint icons_resol_timer;
+ GSList *icons_resol_list; /* list of IconResolutionData pointers */
+ guint icons_resol_timer;
};
static void mgr_favorites_class_init (MgrFavoritesClass *klass);
@@ -91,7 +91,7 @@ mgr_favorites_class_init (MgrFavoritesClass *klass)
g_object_class_install_property (object_class, PROP_BROWSER_CNC,
g_param_spec_object ("browser-connection", NULL, "Connection to
use",
- BROWSER_TYPE_CONNECTION,
+ T_TYPE_CONNECTION,
G_PARAM_READABLE | G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY));
object_class->dispose = mgr_favorites_dispose;
}
@@ -108,8 +108,8 @@ mgr_favorites_dispose (GObject *object)
MgrFavorites *mgr = (MgrFavorites *) object;
if (mgr->priv) {
- if (mgr->priv->bcnc)
- g_object_unref (mgr->priv->bcnc);
+ if (mgr->priv->tcnc)
+ g_object_unref (mgr->priv->tcnc);
if (mgr->priv->icons_resol_timer) {
g_source_remove (mgr->priv->icons_resol_timer);
@@ -175,9 +175,9 @@ mgr_favorites_set_property (GObject *object,
if (mgr->priv) {
switch (param_id) {
case PROP_BROWSER_CNC:
- mgr->priv->bcnc = (BrowserConnection*) g_value_get_object (value);
- if (mgr->priv->bcnc)
- g_object_ref (mgr->priv->bcnc);
+ mgr->priv->tcnc = (TConnection*) g_value_get_object (value);
+ if (mgr->priv->tcnc)
+ g_object_ref (mgr->priv->tcnc);
break;
default:
@@ -199,7 +199,7 @@ mgr_favorites_get_property (GObject *object,
if (mgr->priv) {
switch (param_id) {
case PROP_BROWSER_CNC:
- g_value_set_object (value, mgr->priv->bcnc);
+ g_value_set_object (value, mgr->priv->tcnc);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
@@ -210,35 +210,35 @@ mgr_favorites_get_property (GObject *object,
/**
* mgr_favorites_new
- * @bcnc: a #BrowserConnection object
+ * @tcnc: a #TConnection object
* @type: the type of favorites to handle
- * @order_key: ordering key, see gda_tools_favorites_add()
+ * @order_key: ordering key, see t_favorites_add()
*
* Creates a new #GdaTreeManager object which will add one tree node for each favorite of the @type type
*
* Returns: a new #GdaTreeManager object
*/
GdaTreeManager*
-mgr_favorites_new (BrowserConnection *bcnc, ToolsFavoritesType type, gint order_key)
+mgr_favorites_new (TConnection *tcnc, TFavoritesType type, gint order_key)
{
MgrFavorites *mgr;
- g_return_val_if_fail (BROWSER_IS_CONNECTION (bcnc), NULL);
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
mgr = (MgrFavorites*) g_object_new (MGR_FAVORITES_TYPE,
- "browser-connection", bcnc, NULL);
+ "browser-connection", tcnc, NULL);
mgr->priv->fav_type = type;
mgr->priv->order_key = order_key;
return (GdaTreeManager*) mgr;
}
static gchar *
-create_summary_for_statement (BrowserConnection *bcnc, const gchar *sql)
+create_summary_for_statement (TConnection *tcnc, const gchar *sql)
{
GdaSqlParser *parser;
GString *string;
GdaBatch *batch;
- parser = browser_connection_create_parser (bcnc);
+ parser = t_connection_create_parser (tcnc);
string = g_string_new ("");
batch = gda_sql_parser_parse_string_as_batch (parser, sql, NULL, NULL);
@@ -364,7 +364,7 @@ mgr_favorites_update_children (GdaTreeManager *manager, GdaTreeNode *node, const
GHashTable *ehash = NULL;
GSList *fav_list;
GError *lerror = NULL;
- BrowserConnection *bcnc;
+ TConnection *tcnc;
if (out_error)
*out_error = FALSE;
@@ -372,15 +372,15 @@ mgr_favorites_update_children (GdaTreeManager *manager, GdaTreeNode *node, const
if (children_nodes)
ehash = hash_for_existing_nodes (children_nodes);
- bcnc = mgr->priv->bcnc;
- fav_list = gda_tools_favorites_list (browser_connection_get_favorites (bcnc),
- 0, mgr->priv->fav_type,
- mgr->priv->order_key, &lerror);
+ tcnc = mgr->priv->tcnc;
+ fav_list = t_favorites_list (t_connection_get_favorites (tcnc),
+ 0, mgr->priv->fav_type,
+ mgr->priv->order_key, &lerror);
if (fav_list) {
GSList *list;
gint pos;
for (list = fav_list, pos = 0; list; list = list->next, pos ++) {
- ToolsFavoritesAttributes *fav = (ToolsFavoritesAttributes *) list->data;
+ TFavoritesAttributes *fav = (TFavoritesAttributes *) list->data;
GdaTreeNode* snode = NULL;
GValue *av;
@@ -393,7 +393,7 @@ mgr_favorites_update_children (GdaTreeManager *manager, GdaTreeNode *node, const
g_object_ref (G_OBJECT (snode));
}
- if (fav->type == GDA_TOOLS_FAVORITES_TABLES) {
+ if (fav->type == T_FAVORITES_TABLES) {
if (!snode) {
GdaQuarkList *ql;
const gchar *fname = NULL;
@@ -430,7 +430,7 @@ mgr_favorites_update_children (GdaTreeManager *manager, GdaTreeNode *node, const
/* icon */
GdkPixbuf *pixbuf;
- pixbuf = browser_get_pixbuf_icon (BROWSER_ICON_TABLE);
+ pixbuf = ui_get_pixbuf_icon (UI_ICON_TABLE);
av = gda_value_new (G_TYPE_OBJECT);
g_value_set_object (av, pixbuf);
gda_tree_node_set_node_attribute (snode, "icon", av, NULL);
@@ -440,7 +440,7 @@ mgr_favorites_update_children (GdaTreeManager *manager, GdaTreeNode *node, const
gda_quark_list_free (ql);
}
}
- else if (fav->type == GDA_TOOLS_FAVORITES_DIAGRAMS) {
+ else if (fav->type == T_FAVORITES_DIAGRAMS) {
if (!snode) {
snode = gda_tree_manager_create_node (manager, node, NULL);
@@ -458,7 +458,7 @@ mgr_favorites_update_children (GdaTreeManager *manager, GdaTreeNode *node, const
/* icon */
GdkPixbuf *pixbuf;
- pixbuf = browser_get_pixbuf_icon (BROWSER_ICON_DIAGRAM);
+ pixbuf = ui_get_pixbuf_icon (UI_ICON_DIAGRAM);
av = gda_value_new (G_TYPE_OBJECT);
g_value_set_object (av, pixbuf);
gda_tree_node_set_node_attribute (snode, "icon", av, NULL);
@@ -476,7 +476,7 @@ mgr_favorites_update_children (GdaTreeManager *manager, GdaTreeNode *node, const
gda_tree_node_set_node_attribute (snode, "markup", av, NULL);
gda_value_free (av);
}
- else if (fav->type == GDA_TOOLS_FAVORITES_QUERIES) {
+ else if (fav->type == T_FAVORITES_QUERIES) {
if (!snode) {
snode = gda_tree_manager_create_node (manager, node, NULL);
@@ -497,28 +497,27 @@ mgr_favorites_update_children (GdaTreeManager *manager, GdaTreeNode *node, const
gboolean is_action = FALSE;
GSList *favlist;
GdkPixbuf *pixbuf;
- favlist = gda_tools_favorites_list (browser_connection_get_favorites (bcnc),
- 0, GDA_TOOLS_FAVORITES_ACTIONS,
- -1, NULL);
+ favlist = t_favorites_list (t_connection_get_favorites (tcnc),
+ 0, T_FAVORITES_ACTIONS, -1, NULL);
if (favlist) {
gchar *tmp;
tmp = g_strdup_printf ("QUERY%d", fav->id);
GSList *list;
for (list = favlist; list; list = list->next) {
- ToolsFavoritesAttributes *afav;
- afav = (ToolsFavoritesAttributes*) list->data;
+ TFavoritesAttributes *afav;
+ afav = (TFavoritesAttributes*) list->data;
if (!strcmp (afav->contents, tmp)) {
is_action = TRUE;
break;
}
}
g_free (tmp);
- gda_tools_favorites_free_list (favlist);
+ t_favorites_free_list (favlist);
}
if (is_action)
- pixbuf = browser_get_pixbuf_icon (BROWSER_ICON_ACTION);
+ pixbuf = ui_get_pixbuf_icon (UI_ICON_ACTION);
else
- pixbuf = browser_get_pixbuf_icon (BROWSER_ICON_QUERY);
+ pixbuf = ui_get_pixbuf_icon (UI_ICON_QUERY);
av = gda_value_new (G_TYPE_OBJECT);
g_value_set_object (av, pixbuf);
gda_tree_node_set_node_attribute (snode, "icon", av, NULL);
@@ -526,7 +525,7 @@ mgr_favorites_update_children (GdaTreeManager *manager, GdaTreeNode *node, const
/* summary */
g_value_take_string ((av = gda_value_new (G_TYPE_STRING)),
- create_summary_for_statement (bcnc, fav->contents));
+ create_summary_for_statement (tcnc, fav->contents));
gda_tree_node_set_node_attribute (snode, "summary", av, NULL);
gda_value_free (av);
@@ -542,7 +541,7 @@ mgr_favorites_update_children (GdaTreeManager *manager, GdaTreeNode *node, const
av, NULL);
gda_value_free (av);
}
- else if (fav->type == GDA_TOOLS_FAVORITES_DATA_MANAGERS) {
+ else if (fav->type == T_FAVORITES_DATA_MANAGERS) {
if (!snode) {
snode = gda_tree_manager_create_node (manager, node, NULL);
@@ -566,7 +565,7 @@ mgr_favorites_update_children (GdaTreeManager *manager, GdaTreeNode *node, const
/* icon */
GdkPixbuf *pixbuf;
- pixbuf = browser_get_pixbuf_icon (BROWSER_ICON_TABLE);
+ pixbuf = ui_get_pixbuf_icon (UI_ICON_TABLE);
av = gda_value_new (G_TYPE_OBJECT);
g_value_set_object (av, pixbuf);
gda_tree_node_set_node_attribute (snode, "icon", av, NULL);
@@ -586,7 +585,7 @@ mgr_favorites_update_children (GdaTreeManager *manager, GdaTreeNode *node, const
gda_value_free (av);
}
#ifdef HAVE_LDAP
- else if (fav->type == GDA_TOOLS_FAVORITES_LDAP_DN) {
+ else if (fav->type == T_FAVORITES_LDAP_DN) {
if (!snode) {
/* favorite ID */
snode = gda_tree_manager_create_node (manager, node, NULL);
@@ -599,7 +598,7 @@ mgr_favorites_update_children (GdaTreeManager *manager, GdaTreeNode *node, const
/* icon */
GdkPixbuf *pixbuf;
- pixbuf = browser_get_pixbuf_icon (BROWSER_ICON_LDAP_ENTRY);
+ pixbuf = ui_get_pixbuf_icon (UI_ICON_LDAP_ENTRY);
av = gda_value_new (G_TYPE_OBJECT);
g_value_set_object (av, pixbuf);
@@ -676,7 +675,7 @@ mgr_favorites_update_children (GdaTreeManager *manager, GdaTreeNode *node, const
av, NULL);
gda_value_free (av);
}
- else if (fav->type == GDA_TOOLS_FAVORITES_LDAP_CLASS) {
+ else if (fav->type == T_FAVORITES_LDAP_CLASS) {
if (!snode) {
/* favorite ID */
snode = gda_tree_manager_create_node (manager, node, NULL);
@@ -690,8 +689,8 @@ mgr_favorites_update_children (GdaTreeManager *manager, GdaTreeNode *node, const
/* icon */
GdkPixbuf *pixbuf;
GdaLdapClass *lcl;
- lcl = browser_connection_get_class_info (bcnc, fav->name);
- pixbuf = browser_get_pixbuf_for_ldap_class (lcl ? lcl->kind :
GDA_LDAP_CLASS_KIND_UNKNOWN);
+ lcl = t_connection_get_class_info (tcnc, fav->name);
+ pixbuf = ui_connection_ldap_icon_for_class_kind (lcl ? lcl->kind :
GDA_LDAP_CLASS_KIND_UNKNOWN);
av = gda_value_new (G_TYPE_OBJECT);
g_value_set_object (av, pixbuf);
gda_tree_node_set_node_attribute (snode, "icon", av, NULL);
@@ -744,7 +743,7 @@ mgr_favorites_update_children (GdaTreeManager *manager, GdaTreeNode *node, const
if (snode)
nodes_list = g_slist_prepend (nodes_list, snode);
}
- gda_tools_favorites_free_list (fav_list);
+ t_favorites_free_list (fav_list);
}
else if (lerror) {
if (out_error)
@@ -766,7 +765,7 @@ mgr_favorites_update_children (GdaTreeManager *manager, GdaTreeNode *node, const
gchar *str;
GValue *value;
- if (mgr->priv->fav_type & GDA_TOOLS_FAVORITES_TABLES) {
+ if (mgr->priv->fav_type & T_FAVORITES_TABLES) {
str = g_strdup_printf ("<i>%s</i>", _("No favorite:\ndrag item to\ndefine one"));
snode = gda_tree_manager_create_node (manager, node, str);
g_value_take_string ((value = gda_value_new (G_TYPE_STRING)), str);
@@ -794,7 +793,7 @@ icons_resol_cb (MgrFavorites *mgr)
mgr->priv->icons_resol_list);
GdkPixbuf *pixbuf;
- pixbuf = browser_connection_ldap_icon_for_dn (mgr->priv->bcnc, data->dn, NULL);
+ pixbuf = ui_connection_ldap_icon_for_dn (mgr->priv->tcnc, data->dn, NULL);
if (pixbuf) {
GValue *av;
av = gda_value_new (G_TYPE_OBJECT);
diff --git a/tools/browser/mgr-favorites.h b/tools/browser/mgr-favorites.h
index e9e7d47..bc9e716 100644
--- a/tools/browser/mgr-favorites.h
+++ b/tools/browser/mgr-favorites.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 - 2012 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2009 - 2014 Vivien Malerba <malerba gnome-db org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -20,7 +20,8 @@
#define ___MGR_FAVORITES_H__
#include <libgda/gda-tree-manager.h>
-#include "browser-connection.h"
+#include "common/t-connection.h"
+#include "common/t-favorites.h"
G_BEGIN_DECLS
@@ -52,7 +53,7 @@ struct _MgrFavoritesClass {
*/
GType mgr_favorites_get_type (void) G_GNUC_CONST;
-GdaTreeManager* mgr_favorites_new (BrowserConnection *bcnc, ToolsFavoritesType type,
+GdaTreeManager* mgr_favorites_new (TConnection *bcnc, TFavoritesType type,
gint order_key);
/* name of the attribute which stores the favorite name */
diff --git a/tools/browser/common/objects-cloud.c b/tools/browser/objects-cloud.c
similarity index 98%
rename from tools/browser/common/objects-cloud.c
rename to tools/browser/objects-cloud.c
index 0ca09e2..d74c41a 100644
--- a/tools/browser/common/objects-cloud.c
+++ b/tools/browser/objects-cloud.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2009 - 2014 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2010 David King <davidk openismus com>
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
*
@@ -24,9 +24,9 @@
#include <libgda/gda-tree.h>
#include "objects-cloud.h"
#include <libgda-ui/gdaui-tree-store.h>
-#include "../dnd.h"
-#include "../support.h"
-#include "../gdaui-bar.h"
+#include "dnd.h"
+#include "ui-support.h"
+#include "gdaui-bar.h"
#include "marshal.h"
#include <gdk/gdkkeysyms.h>
#include <libgda-ui/internal/popup-container.h>
@@ -177,7 +177,7 @@ update_display (ObjectsCloud *cloud)
gtk_text_buffer_get_end_iter (tbuffer, &end);
if (cloud->priv->show_schemas) {
gtk_text_buffer_insert_pixbuf (tbuffer, &end,
- browser_get_pixbuf_icon (BROWSER_ICON_TABLE));
+ ui_get_pixbuf_icon (UI_ICON_TABLE));
gtk_text_buffer_insert (tbuffer, &end, " ", 1);
}
gtk_text_buffer_add_mark (tbuffer, default_sd->mark, &end);
@@ -223,7 +223,7 @@ update_display (ObjectsCloud *cloud)
gtk_text_buffer_get_end_iter (tbuffer, &end);
gtk_text_buffer_insert (tbuffer, &end, "\n\n", 2);
gtk_text_buffer_insert_pixbuf (tbuffer, &end,
- browser_get_pixbuf_icon (BROWSER_ICON_TABLE));
+ ui_get_pixbuf_icon (UI_ICON_TABLE));
gtk_text_buffer_insert (tbuffer, &end, " ", 1);
gtk_text_buffer_add_mark (tbuffer, sd->mark, &end);
@@ -382,7 +382,7 @@ objects_cloud_new (GdaMetaStruct *mstruct, ObjectsCloudObjType type)
gtk_box_pack_start (GTK_BOX (cloud), sw, TRUE, TRUE, 0);
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
- gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (sw), vbox);
+ gtk_container_add (GTK_CONTAINER (sw), vbox);
cloud->priv->tview = gtk_text_view_new_with_buffer (cloud->priv->tbuffer);
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (cloud->priv->tview), GTK_WRAP_WORD);
diff --git a/tools/browser/common/objects-cloud.h b/tools/browser/objects-cloud.h
similarity index 81%
rename from tools/browser/common/objects-cloud.h
rename to tools/browser/objects-cloud.h
index 8f726b3..4d34f5f 100644
--- a/tools/browser/common/objects-cloud.h
+++ b/tools/browser/objects-cloud.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2009 - 2014 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
*
* This program is free software; you can redistribute it and/or
@@ -21,7 +21,6 @@
#define __OBJECTS_CLOUD_H__
#include <gtk/gtk.h>
-#include "../browser-connection.h"
G_BEGIN_DECLS
@@ -55,11 +54,11 @@ struct _ObjectsCloudClass {
GType objects_cloud_get_type (void) G_GNUC_CONST;
-GtkWidget *objects_cloud_new (GdaMetaStruct *mstruct, ObjectsCloudObjType type);
+GtkWidget *objects_cloud_new (GdaMetaStruct *mstruct, ObjectsCloudObjType type);
void objects_cloud_set_meta_struct (ObjectsCloud *cloud, GdaMetaStruct *mstruct);
-void objects_cloud_show_schemas (ObjectsCloud *cloud, gboolean show_schemas);
-void objects_cloud_filter (ObjectsCloud *cloud, const gchar *filter);
-GtkWidget *objects_cloud_create_filter (ObjectsCloud *cloud);
+void objects_cloud_show_schemas (ObjectsCloud *cloud, gboolean show_schemas);
+void objects_cloud_filter (ObjectsCloud *cloud, const gchar *filter);
+GtkWidget *objects_cloud_create_filter (ObjectsCloud *cloud);
G_END_DECLS
diff --git a/tools/browser/query-exec/.gitignore b/tools/browser/query-exec/.gitignore
new file mode 100644
index 0000000..ebe58c2
--- /dev/null
+++ b/tools/browser/query-exec/.gitignore
@@ -0,0 +1 @@
+marshal.[ch]
\ No newline at end of file
diff --git a/tools/browser/query-exec/Makefile.am b/tools/browser/query-exec/Makefile.am
index 2104d91..212cb9d 100644
--- a/tools/browser/query-exec/Makefile.am
+++ b/tools/browser/query-exec/Makefile.am
@@ -1,10 +1,12 @@
noinst_LTLIBRARIES = libperspective.la
AM_CPPFLAGS = \
+ -I$(top_srcdir)/tools \
-I$(top_srcdir)/tools/browser \
-I$(top_builddir) \
-I$(top_srcdir) \
-I$(top_srcdir)/libgda \
+ -I$(top_srcdir)/libgda/sqlite \
$(COREDEPS_CFLAGS) \
$(COREDEPS_WFLAGS) \
$(GTK_CFLAGS) \
@@ -38,7 +40,6 @@ EXTRA_DIST= \
$(langspec_DATA) \
marshal.list
-
CLEANFILES = \
marshal.h \
marshal.c
diff --git a/tools/browser/query-exec/perspective-main.c b/tools/browser/query-exec/perspective-main.c
index b9a06f0..e2aec5e 100644
--- a/tools/browser/query-exec/perspective-main.c
+++ b/tools/browser/query-exec/perspective-main.c
@@ -3,7 +3,7 @@
* Copyright (C) 2001 - 2002 Rodrigo Moya <rodrigo gnome-db org>
* Copyright (C) 2003 Danilo Schoeneberg <dj starfire-programming net>
* Copyright (C) 2003 Laurent Sansonetti <lrz gnome org>
- * Copyright (C) 2005 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2005 - 2014 Vivien Malerba <malerba gnome-db org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
diff --git a/tools/browser/query-exec/perspective-main.h b/tools/browser/query-exec/perspective-main.h
index 2a7a642..aec9329 100644
--- a/tools/browser/query-exec/perspective-main.h
+++ b/tools/browser/query-exec/perspective-main.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2009 - 2014 Vivien Malerba <malerba gnome-db org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -16,7 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#include "../decl.h"
+#include "../browser-perspective.h"
G_BEGIN_DECLS
diff --git a/tools/browser/query-exec/query-console-page.c b/tools/browser/query-exec/query-console-page.c
index 7992823..fddbc9b 100644
--- a/tools/browser/query-exec/query-console-page.c
+++ b/tools/browser/query-exec/query-console-page.c
@@ -22,12 +22,11 @@
#include <string.h>
#include "query-console-page.h"
#include "../dnd.h"
-#include "../support.h"
+#include "../ui-support.h"
#include "../gdaui-bar.h"
#include "query-exec-perspective.h"
#include "../browser-window.h"
#include "../browser-page.h"
-#include "../browser-stock-icons.h"
#include "query-editor.h"
#include "query-result.h"
#include <libgda-ui/internal/popup-container.h>
@@ -35,8 +34,10 @@
#include <libgda-ui/libgda-ui.h>
#include <libgda/gda-debug-macros.h>
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+
struct _QueryConsolePagePrivate {
- BrowserConnection *bcnc;
+ TConnection *tcnc;
GdaSqlParser *parser;
GtkActionGroup *agroup;
@@ -83,8 +84,8 @@ static GtkWidget *query_console_page_page_get_tab_label (BrowserPage *
static GObjectClass *parent_class = NULL;
/*
- * QueryConsolePage class implementation
- */
+* QueryConsolePage class implementation
+*/
static void
query_console_page_class_init (QueryConsolePageClass *klass)
@@ -132,7 +133,7 @@ query_console_page_init (QueryConsolePage *tconsole, G_GNUC_UNUSED QueryConsoleP
gtk_orientable_set_orientation (GTK_ORIENTABLE (tconsole), GTK_ORIENTATION_VERTICAL);
}
-static void connection_busy_cb (BrowserConnection *bcnc, gboolean is_busy,
+static void connection_busy_cb (TConnection *tcnc, gboolean is_busy,
gchar *reason, QueryConsolePage *tconsole);
static void
query_console_page_dispose (GObject *object)
@@ -141,10 +142,10 @@ query_console_page_dispose (GObject *object)
/* free memory */
if (tconsole->priv) {
- if (tconsole->priv->bcnc) {
- g_signal_handlers_disconnect_by_func (tconsole->priv->bcnc,
+ if (tconsole->priv->tcnc) {
+ g_signal_handlers_disconnect_by_func (tconsole->priv->tcnc,
G_CALLBACK (connection_busy_cb), tconsole);
- g_object_unref (tconsole->priv->bcnc);
+ g_object_unref (tconsole->priv->tcnc);
}
if (tconsole->priv->parser)
g_object_unref (tconsole->priv->parser);
@@ -217,15 +218,15 @@ static void rerun_requested_cb (QueryResult *qres, QueryEditorHistoryBatch *batc
* Returns: a new #GtkWidget
*/
GtkWidget *
-query_console_page_new (BrowserConnection *bcnc)
+query_console_page_new (TConnection *tcnc)
{
QueryConsolePage *tconsole;
- g_return_val_if_fail (BROWSER_IS_CONNECTION (bcnc), NULL);
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
tconsole = QUERY_CONSOLE_PAGE (g_object_new (QUERY_CONSOLE_PAGE_TYPE, NULL));
- tconsole->priv->bcnc = g_object_ref (bcnc);
+ tconsole->priv->tcnc = g_object_ref (tcnc);
/* header */
GtkWidget *label;
@@ -304,36 +305,37 @@ query_console_page_new (BrowserConnection *bcnc)
gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_END);
gtk_box_pack_start (GTK_BOX (hbox), bbox, FALSE, FALSE, 5);
- button = browser_make_small_button (FALSE, FALSE, _("Clear"),
- GTK_STOCK_CLEAR, _("Clear the editor's\ncontents"));
+ button = ui_make_small_button (FALSE, FALSE, _("Clear"),
+ "_Clear", _("Clear the editor's\ncontents"));
gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0);
g_signal_connect (button, "clicked",
G_CALLBACK (sql_clear_clicked_cb), tconsole);
- button = browser_make_small_button (TRUE, FALSE, _("Variables"), NULL,
- _("Show variables needed\nto execute SQL"));
+ button = ui_make_small_button (TRUE, FALSE, _("Variables"),
+ NULL, _("Show variables needed\nto execute SQL"));
gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0);
tconsole->priv->params_toggle = GTK_TOGGLE_BUTTON (button);
g_signal_connect (button, "toggled",
G_CALLBACK (sql_variables_clicked_cb), tconsole);
- button = browser_make_small_button (FALSE, FALSE, _("Execute"), GTK_STOCK_EXECUTE, _("Execute SQL in
editor"));
+ button = ui_make_small_button (FALSE, FALSE, _("Execute"),
+ "_Execute", _("Execute SQL in editor"));
tconsole->priv->exec_button = button;
gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0);
g_signal_connect (button, "clicked",
G_CALLBACK (sql_execute_clicked_cb), tconsole);
- button = browser_make_small_button (FALSE, FALSE, _("Indent"),
- GTK_STOCK_INDENT, _("Indent SQL in editor\n"
- "and make the code more readable\n"
- "(removes comments)"));
+ button = ui_make_small_button (FALSE, FALSE, _("Indent"),
+ NULL, _("Indent SQL in editor\n"
+ "and make the code more readable\n"
+ "(removes comments)"));
tconsole->priv->indent_button = button;
gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0);
g_signal_connect (button, "clicked",
G_CALLBACK (sql_indent_clicked_cb), tconsole);
- button = browser_make_small_button (FALSE, TRUE, _("Favorite"),
- STOCK_ADD_BOOKMARK, _("Add SQL to favorite"));
+ button = ui_make_small_button (FALSE, TRUE, _("Favorite"),
+ NULL, _("Add SQL to favorite"));
gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0);
g_signal_connect (button, "clicked",
G_CALLBACK (sql_favorite_clicked_cb), tconsole);
@@ -365,16 +367,16 @@ query_console_page_new (BrowserConnection *bcnc)
gtk_box_pack_start (GTK_BOX (vbox), bbox, FALSE, FALSE, 0);
gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_END);
- button = browser_make_small_button (FALSE, FALSE, _("Copy"), GTK_STOCK_COPY,
- _("Copy selected history\nto editor"));
+ button = ui_make_small_button (FALSE, FALSE, _("Copy"),
+ "_Copy", _("Copy selected history\nto editor"));
gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0);
g_signal_connect (button, "clicked",
G_CALLBACK (history_copy_clicked_cb), tconsole);
tconsole->priv->history_copy_button = button;
gtk_widget_set_sensitive (button, FALSE);
- button = browser_make_small_button (FALSE, FALSE, _("Clear"),
- GTK_STOCK_CLEAR, _("Clear history"));
+ button = ui_make_small_button (FALSE, FALSE, _("Clear"),
+ "_Clear", _("Clear history"));
gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0);
g_signal_connect (button, "clicked",
G_CALLBACK (history_clear_clicked_cb), tconsole);
@@ -404,18 +406,18 @@ query_console_page_new (BrowserConnection *bcnc)
/* busy connection handling */
gchar *reason = NULL;
- if (browser_connection_is_busy (tconsole->priv->bcnc, &reason)) {
- connection_busy_cb (tconsole->priv->bcnc, TRUE, reason, tconsole);
+ if (t_connection_is_busy (tconsole->priv->tcnc, &reason)) {
+ connection_busy_cb (tconsole->priv->tcnc, TRUE, reason, tconsole);
g_free (reason);
}
- g_signal_connect (tconsole->priv->bcnc, "busy",
+ g_signal_connect (tconsole->priv->tcnc, "busy",
G_CALLBACK (connection_busy_cb), tconsole);
return (GtkWidget*) tconsole;
}
static void
-connection_busy_cb (G_GNUC_UNUSED BrowserConnection *bcnc, gboolean is_busy, G_GNUC_UNUSED gchar *reason,
QueryConsolePage *tconsole)
+connection_busy_cb (G_GNUC_UNUSED TConnection *tcnc, gboolean is_busy, G_GNUC_UNUSED gchar *reason,
QueryConsolePage *tconsole)
{
gtk_widget_set_sensitive (tconsole->priv->exec_button, !is_busy);
gtk_widget_set_sensitive (tconsole->priv->indent_button, !is_busy);
@@ -500,7 +502,7 @@ compute_params (QueryConsolePage *tconsole)
GdaBatch *batch;
if (tconsole->priv->params) {
- browser_connection_keep_variables (tconsole->priv->bcnc, tconsole->priv->params);
+ t_connection_keep_variables (tconsole->priv->tcnc, tconsole->priv->params);
g_object_unref (tconsole->priv->params);
}
tconsole->priv->params = NULL;
@@ -511,7 +513,7 @@ compute_params (QueryConsolePage *tconsole)
}
if (!tconsole->priv->parser)
- tconsole->priv->parser = browser_connection_create_parser (tconsole->priv->bcnc);
+ tconsole->priv->parser = t_connection_create_parser (tconsole->priv->tcnc);
sql = query_editor_get_all_text (tconsole->priv->editor);
batch = gda_sql_parser_parse_string_as_batch (tconsole->priv->parser, sql, NULL, NULL);
@@ -522,9 +524,9 @@ compute_params (QueryConsolePage *tconsole)
if (gda_batch_get_parameters (batch, &(tconsole->priv->params), &error)) {
if (tconsole->priv->params) {
- browser_connection_define_ui_plugins_for_batch (tconsole->priv->bcnc,
- batch,
- tconsole->priv->params);
+ t_connection_define_ui_plugins_for_batch (tconsole->priv->tcnc,
+ batch,
+ tconsole->priv->params);
show_variables = TRUE;
tconsole->priv->params_form = gdaui_basic_form_new (tconsole->priv->params);
g_object_set ((GObject*) tconsole->priv->params_form,
@@ -546,7 +548,7 @@ compute_params (QueryConsolePage *tconsole)
gtk_widget_show (tconsole->priv->params_form);
g_object_unref (batch);
- browser_connection_load_variables (tconsole->priv->bcnc, tconsole->priv->params);
+ t_connection_load_variables (tconsole->priv->tcnc, tconsole->priv->params);
if (tconsole->priv->params && show_variables &&
gda_set_is_valid (tconsole->priv->params, NULL))
show_variables = FALSE;
@@ -606,7 +608,7 @@ sql_indent_clicked_cb (G_GNUC_UNUSED GtkButton *button, QueryConsolePage *tconso
GdaBatch *batch;
if (!tconsole->priv->parser)
- tconsole->priv->parser = browser_connection_create_parser (tconsole->priv->bcnc);
+ tconsole->priv->parser = t_connection_create_parser (tconsole->priv->tcnc);
sql = query_editor_get_all_text (tconsole->priv->editor);
batch = gda_sql_parser_parse_string_as_batch (tconsole->priv->parser, sql, NULL, NULL);
@@ -617,8 +619,8 @@ sql_indent_clicked_cb (G_GNUC_UNUSED GtkButton *button, QueryConsolePage *tconso
stmt_list = gda_batch_get_statements (batch);
string = g_string_new ("");
for (list = stmt_list; list; list = list->next) {
- sql = browser_connection_render_pretty_sql (tconsole->priv->bcnc,
- GDA_STATEMENT (list->data));
+ sql = t_connection_render_pretty_sql (tconsole->priv->tcnc,
+ GDA_STATEMENT (list->data));
if (!sql)
sql = gda_statement_to_sql (GDA_STATEMENT (list->data), NULL, NULL);
if (list != stmt_list)
@@ -641,7 +643,7 @@ static void
sql_favorite_clicked_cb (G_GNUC_UNUSED GtkButton *button, QueryConsolePage *tconsole)
{
GtkWidget *menu, *mitem;
- ToolsFavorites *bfav;
+ TFavorites *tfav;
if (tconsole->priv->favorites_menu)
gtk_widget_destroy (tconsole->priv->favorites_menu);
@@ -654,10 +656,10 @@ sql_favorite_clicked_cb (G_GNUC_UNUSED GtkButton *button, QueryConsolePage *tcon
gtk_widget_show (mitem);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), mitem);
- bfav = browser_connection_get_favorites (tconsole->priv->bcnc);
+ tfav = t_connection_get_favorites (tconsole->priv->tcnc);
if (tconsole->priv->fav_id >= 0) {
- ToolsFavoritesAttributes fav;
- if (gda_tools_favorites_get (bfav, tconsole->priv->fav_id, &fav, NULL)) {
+ TFavoritesAttributes fav;
+ if (t_favorites_get (tfav, tconsole->priv->fav_id, &fav, NULL)) {
gchar *str;
str = g_strdup_printf (_("Modify favorite '%s'"), fav.name);
mitem = gtk_menu_item_new_with_label (str);
@@ -670,12 +672,12 @@ sql_favorite_clicked_cb (G_GNUC_UNUSED GtkButton *button, QueryConsolePage *tcon
GINT_TO_POINTER (tconsole->priv->fav_id));
gtk_widget_show (mitem);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), mitem);
- gda_tools_favorites_reset_attributes (&fav);
+ t_favorites_reset_attributes (&fav);
}
}
GSList *allfav;
- allfav = gda_tools_favorites_list (bfav, 0, GDA_TOOLS_FAVORITES_QUERIES, ORDER_KEY_QUERIES, NULL);
+ allfav = t_favorites_list (tfav, 0, T_FAVORITES_QUERIES, ORDER_KEY_QUERIES, NULL);
if (allfav) {
GtkWidget *submenu;
GSList *list;
@@ -687,8 +689,8 @@ sql_favorite_clicked_cb (G_GNUC_UNUSED GtkButton *button, QueryConsolePage *tcon
submenu = gtk_menu_new ();
gtk_menu_item_set_submenu (GTK_MENU_ITEM (mitem), submenu);
for (list = allfav; list; list = list->next) {
- ToolsFavoritesAttributes *fav;
- fav = (ToolsFavoritesAttributes*) list->data;
+ TFavoritesAttributes *fav;
+ fav = (TFavoritesAttributes*) list->data;
if (fav->id == tconsole->priv->fav_id)
continue;
gchar *str;
@@ -704,7 +706,7 @@ sql_favorite_clicked_cb (G_GNUC_UNUSED GtkButton *button, QueryConsolePage *tcon
gtk_widget_show (mitem);
gtk_menu_shell_append (GTK_MENU_SHELL (submenu), mitem);
}
- gda_tools_favorites_free_list (allfav);
+ t_favorites_free_list (allfav);
}
gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
@@ -721,8 +723,8 @@ fav_form_name_activated_cb (G_GNUC_UNUSED GtkWidget *form, GtkWidget *dlg)
static void
sql_favorite_new_mitem_cb (G_GNUC_UNUSED GtkMenuItem *mitem, QueryConsolePage *tconsole)
{
- ToolsFavorites *bfav;
- ToolsFavoritesAttributes fav;
+ TFavorites *tfav;
+ TFavoritesAttributes fav;
GError *error = NULL;
GdaSet *set;
@@ -747,17 +749,17 @@ sql_favorite_new_mitem_cb (G_GNUC_UNUSED GtkMenuItem *mitem, QueryConsolePage *t
memset (&fav, 0, sizeof (fav));
fav.id = -1;
- fav.type = GDA_TOOLS_FAVORITES_QUERIES;
+ fav.type = T_FAVORITES_QUERIES;
fav.contents = query_editor_get_all_text (tconsole->priv->editor);
cvalue = gda_set_get_holder_value (set, _("Favorite's name"));
fav.name = (gchar*) g_value_get_string (cvalue);
- bfav = browser_connection_get_favorites (tconsole->priv->bcnc);
+ tfav = t_connection_get_favorites (tconsole->priv->tcnc);
- if (! gda_tools_favorites_add (bfav, 0, &fav, ORDER_KEY_QUERIES, G_MAXINT, &error)) {
- browser_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) tconsole),
- _("Could not add favorite: %s"),
- error && error->message ? error->message : _("No detail"));
+ if (! t_favorites_add (tfav, 0, &fav, ORDER_KEY_QUERIES, G_MAXINT, &error)) {
+ ui_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) tconsole),
+ _("Could not add favorite: %s"),
+ error && error->message ? error->message : _("No detail"));
if (error)
g_error_free (error);
}
@@ -772,22 +774,22 @@ sql_favorite_new_mitem_cb (G_GNUC_UNUSED GtkMenuItem *mitem, QueryConsolePage *t
static void
sql_favorite_modify_mitem_cb (G_GNUC_UNUSED GtkMenuItem *mitem, QueryConsolePage *tconsole)
{
- ToolsFavorites *bfav;
- ToolsFavoritesAttributes fav;
+ TFavorites *tfav;
+ TFavoritesAttributes fav;
GError *error = NULL;
memset (&fav, 0, sizeof (fav));
fav.id = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (mitem), "favid"));
- fav.type = GDA_TOOLS_FAVORITES_QUERIES;
+ fav.type = T_FAVORITES_QUERIES;
fav.contents = query_editor_get_all_text (tconsole->priv->editor);
fav.name = g_object_get_data (G_OBJECT (mitem), "favname");
- bfav = browser_connection_get_favorites (tconsole->priv->bcnc);
+ tfav = t_connection_get_favorites (tconsole->priv->tcnc);
- if (! gda_tools_favorites_add (bfav, 0, &fav, ORDER_KEY_QUERIES, G_MAXINT, &error)) {
- browser_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) tconsole),
- _("Could not add favorite: %s"),
- error && error->message ? error->message : _("No detail"));
+ if (! t_favorites_add (tfav, 0, &fav, ORDER_KEY_QUERIES, G_MAXINT, &error)) {
+ ui_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) tconsole),
+ _("Could not add favorite: %s"),
+ error && error->message ? error->message : _("No detail"));
if (error)
g_error_free (error);
}
@@ -930,21 +932,21 @@ actually_execute (QueryConsolePage *tconsole, const gchar *sql, GdaSet *params,
/* if a query is being executed, then show an error */
if (tconsole->priv->currently_executing) {
- browser_show_error (GTK_WINDOW (gtk_widget_get_toplevel ((GtkWidget*) tconsole)),
- _("A query is already being executed, "
- "to execute another query, open a new connection."));
+ ui_show_error (GTK_WINDOW (gtk_widget_get_toplevel ((GtkWidget*) tconsole)),
+ _("A query is already being executed, "
+ "to execute another query, open a new connection."));
return;
}
tconsole->priv->currently_executing = TRUE;
if (!tconsole->priv->parser)
- tconsole->priv->parser = browser_connection_create_parser (tconsole->priv->bcnc);
+ tconsole->priv->parser = t_connection_create_parser (tconsole->priv->tcnc);
batch = gda_sql_parser_parse_string_as_batch (tconsole->priv->parser, sql, &remain, &error);
if (!batch) {
- browser_show_error (GTK_WINDOW (gtk_widget_get_toplevel ((GtkWidget*) tconsole)),
- _("Error while parsing code: %s"),
- error && error->message ? error->message : _("No detail"));
+ ui_show_error (GTK_WINDOW (gtk_widget_get_toplevel ((GtkWidget*) tconsole)),
+ _("Error while parsing code: %s"),
+ error && error->message ? error->message : _("No detail"));
g_clear_error (&error);
return;
}
@@ -970,11 +972,11 @@ actually_execute (QueryConsolePage *tconsole, const gchar *sql, GdaSet *params,
GdaStatement *stmt;
GObject *result;
GError *lerror = NULL;
- within_transaction = browser_connection_get_transaction_status (tconsole->priv->bcnc) ? TRUE
: FALSE;
+ within_transaction = t_connection_get_transaction_status (tconsole->priv->tcnc) ? TRUE :
FALSE;
stmt = GDA_STATEMENT (list->data);
- result = browser_connection_execute_statement (tconsole->priv->bcnc, stmt, params,
- GDA_STATEMENT_MODEL_RANDOM_ACCESS,
- NULL, &lerror);
+ result = t_connection_execute_statement (tconsole->priv->tcnc, stmt, params,
+ GDA_STATEMENT_MODEL_RANDOM_ACCESS,
+ NULL, &lerror);
if (result) {
QueryEditorHistoryItem *history;
GdaSqlStatement *sqlst;
@@ -987,13 +989,14 @@ actually_execute (QueryConsolePage *tconsole, const gchar *sql, GdaSet *params,
}
else
history = query_editor_history_item_new (sqlst->sql, result, lerror);
+ g_object_unref (result);
gda_sql_statement_free (sqlst);
history->within_transaction = within_transaction;
/* display a message if a transaction has been started */
if (! history->within_transaction &&
- browser_connection_get_transaction_status (tconsole->priv->bcnc) &&
+ t_connection_get_transaction_status (tconsole->priv->tcnc) &&
gda_statement_get_statement_type (stmt) != GDA_SQL_STATEMENT_BEGIN) {
browser_window_show_notice_printf (BROWSER_WINDOW (gtk_widget_get_toplevel
((GtkWidget*) tconsole)),
GTK_MESSAGE_INFO,
@@ -1013,9 +1016,9 @@ actually_execute (QueryConsolePage *tconsole, const gchar *sql, GdaSet *params,
"QueryConsolePage", _("Statement executed"), TRUE);
}
else {
- browser_show_error (GTK_WINDOW (gtk_widget_get_toplevel ((GtkWidget*) tconsole)),
- _("Error executing query:\n%s"),
- lerror && lerror->message ? lerror->message : _("No detail"));
+ ui_show_error (GTK_WINDOW (gtk_widget_get_toplevel ((GtkWidget*) tconsole)),
+ _("Error executing query:\n%s"),
+ lerror && lerror->message ? lerror->message : _("No detail"));
g_clear_error (&lerror);
break;
}
@@ -1029,9 +1032,9 @@ rerun_requested_cb (QueryResult *qres, QueryEditorHistoryBatch *batch,
QueryEditorHistoryItem *item, QueryConsolePage *tconsole)
{
if (!batch || !item || !item->sql) {
- browser_show_error (GTK_WINDOW (gtk_widget_get_toplevel ((GtkWidget*) tconsole)),
- _("Internal error, please report error to "
- "http://bugzilla.gnome.org/ for the \"libgda\" product"));
+ ui_show_error (GTK_WINDOW (gtk_widget_get_toplevel ((GtkWidget*) tconsole)),
+ _("Internal error, please report error to "
+ "http://bugzilla.gnome.org/ for the \"libgda\" product"));
return;
}
@@ -1106,7 +1109,7 @@ query_console_page_page_get_actions_group (BrowserPage *page)
GtkAction *action;
action = gtk_action_group_get_action (tconsole->priv->agroup, "ExecuteQuery");
- gtk_action_set_sensitive (action, !browser_connection_is_busy (tconsole->priv->bcnc, NULL));
+ gtk_action_set_sensitive (action, !t_connection_is_busy (tconsole->priv->tcnc, NULL));
}
return g_object_ref (tconsole->priv->agroup);
}
@@ -1123,9 +1126,8 @@ query_console_page_page_get_tab_label (BrowserPage *page, GtkWidget **out_close_
const gchar *tab_name;
tab_name = _("Query editor");
- return browser_make_tab_label_with_stock (tab_name,
- STOCK_CONSOLE,
- out_close_button ? TRUE : FALSE, out_close_button);
+ return ui_make_tab_label_with_icon (tab_name, NULL/*STOCK_CONSOLE*/,
+ out_close_button ? TRUE : FALSE, out_close_button);
}
static void
diff --git a/tools/browser/query-exec/query-console-page.h b/tools/browser/query-exec/query-console-page.h
index 040de65..d06ba8b 100644
--- a/tools/browser/query-exec/query-console-page.h
+++ b/tools/browser/query-exec/query-console-page.h
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
- * Copyright (C) 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2011 - 2014 Vivien Malerba <malerba gnome-db org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -21,7 +21,7 @@
#define __QUERY_CONSOLE_PAGE_H__
#include <gtk/gtk.h>
-#include "../browser-connection.h"
+#include "../common/t-connection.h"
G_BEGIN_DECLS
@@ -46,7 +46,7 @@ struct _QueryConsolePageClass {
GType query_console_page_get_type (void) G_GNUC_CONST;
-GtkWidget *query_console_page_new (BrowserConnection *bcnc);
+GtkWidget *query_console_page_new (TConnection *tcnc);
void query_console_page_set_text (QueryConsolePage *console, const gchar *text, gint
fav_id);
G_END_DECLS
diff --git a/tools/browser/query-exec/query-editor.c b/tools/browser/query-exec/query-editor.c
index 11ca4b5..5f33b51 100644
--- a/tools/browser/query-exec/query-editor.c
+++ b/tools/browser/query-exec/query-editor.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2009 - 2014 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2010 David King <davidk openismus com>
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
*
@@ -34,11 +34,11 @@
#endif
#include "query-editor.h"
#include <binreloc/gda-binreloc.h>
-#include "../browser-connection.h"
+#include "../common/t-connection.h"
#include "../browser-window.h"
#include <libgda-ui/internal/popup-container.h>
-#include "../support.h"
-#include "../common/widget-overlay.h"
+#include "../ui-support.h"
+#include "../widget-overlay.h"
#define QUERY_EDITOR_LANGUAGE_SQL "gda-sql"
#define COLOR_ALTER_FACTOR 1.8
@@ -360,11 +360,11 @@ display_completions (QueryEditor *editor)
if (!str)
return;
- BrowserConnection *bcnc;
+ TConnection *tcnc;
gchar **compl;
- bcnc = browser_window_get_connection ((BrowserWindow*) gtk_widget_get_toplevel ((GtkWidget*) editor));
- compl = browser_connection_get_completions (bcnc, str, ptr - str, strlen (str));
+ tcnc = browser_window_get_connection ((BrowserWindow*) gtk_widget_get_toplevel ((GtkWidget*) editor));
+ compl = t_connection_get_completions (tcnc, str, ptr - str, strlen (str));
g_free (str);
if (compl) {
@@ -376,7 +376,7 @@ display_completions (QueryEditor *editor)
GtkWidget *popup, *sw;
model = gtk_list_store_new (1, G_TYPE_STRING);
- treeview = browser_make_tree_view (GTK_TREE_MODEL (model));
+ treeview = ui_make_tree_view (GTK_TREE_MODEL (model));
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE);
gtk_tree_view_set_grid_lines (GTK_TREE_VIEW (treeview),
GTK_TREE_VIEW_GRID_LINES_NONE);
gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)),
@@ -1900,7 +1900,7 @@ query_editor_history_batch_new (GTimeVal run_time, GdaSet *params)
qib->params = gda_set_copy (params);
#ifdef QUERY_EDITOR_DEBUG
- g_print ("\t%s() => %p\n", __FUNCTION__, qib);
+ g_print ("%s (%p)\n", __FUNCTION__, qib);
#endif
return qib;
}
@@ -1922,7 +1922,7 @@ query_editor_history_batch_unref (QueryEditorHistoryBatch *qib)
g_return_if_fail (qib);
qib->ref_count--;
#ifdef QUERY_EDITOR_DEBUG
- g_print ("%s (%p) ref count:%d\n", __FUNCTION__, qib, qib->ref_count);
+ g_print ("%s (%p)\n", __FUNCTION__, qib);
#endif
if (qib->ref_count <= 0) {
if (qib->hist_items) {
@@ -1932,15 +1932,11 @@ query_editor_history_batch_unref (QueryEditorHistoryBatch *qib)
if (qib->params)
g_object_unref (qib->params);
- g_free (qib);
#ifdef QUERY_EDITOR_DEBUG
- g_print ("\t%s() => %p\n", __FUNCTION__, qib);
+ g_print ("Freeing QueryEditorHistoryBatch (%p)\n", qib);
#endif
+ g_free (qib);
}
-#ifdef QUERY_EDITOR_DEBUG
- else
- g_print ("\tFAILED %s() => %p:%d\n", __FUNCTION__, qib, qib->ref_count);
-#endif
}
static void
@@ -1981,7 +1977,7 @@ query_editor_history_item_new (const gchar *sql, GObject *result, GError *error)
qih->exec_error = g_error_copy (error);
#ifdef QUERY_EDITOR_DEBUG
- g_print ("\t%s() => %p\n", __FUNCTION__, qih);
+ g_print ("%s() => %p\n", __FUNCTION__, qih);
#endif
return qih;
}
@@ -2003,7 +1999,7 @@ query_editor_history_item_unref (QueryEditorHistoryItem *qih)
g_return_if_fail (qih);
qih->ref_count--;
#ifdef QUERY_EDITOR_DEBUG
- g_print ("%s (%p) ref count:%d\n", __FUNCTION__, qih, qih->ref_count);
+ g_print ("%s (%p)\n", __FUNCTION__, qih);
#endif
if (qih->ref_count <= 0) {
g_free (qih->sql);
@@ -2011,15 +2007,12 @@ query_editor_history_item_unref (QueryEditorHistoryItem *qih)
g_object_unref (qih->result);
if (qih->exec_error)
g_error_free (qih->exec_error);
- g_free (qih);
#ifdef QUERY_EDITOR_DEBUG
- g_print ("\t%s() => %p\n", __FUNCTION__, qih);
+ g_print ("Freeing QueryEditorHistoryItem %p\n", qih);
#endif
+
+ g_free (qih);
}
-#ifdef QUERY_EDITOR_DEBUG
- else
- g_print ("\tFAILED %s() => %p:%d\n", __FUNCTION__, qih, qih->ref_count);
-#endif
}
/*
@@ -2061,5 +2054,8 @@ hist_item_data_unref (HistItemData *hdata)
if (hdata->tag)
g_object_unref (hdata->tag);
g_free (hdata);
+#ifdef QUERY_EDITOR_DEBUG
+ g_print ("HistItemData %p freed\n", hdata);
+#endif
}
}
diff --git a/tools/browser/query-exec/query-exec-perspective.c
b/tools/browser/query-exec/query-exec-perspective.c
index 5c38036..d9c74dc 100644
--- a/tools/browser/query-exec/query-exec-perspective.c
+++ b/tools/browser/query-exec/query-exec-perspective.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 - 2012 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2009 - 2014 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2010 David King <davidk openismus com>
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
*
@@ -24,12 +24,13 @@
#include "../browser-window.h"
#include "../browser-page.h"
#include "query-console-page.h"
-#include "../browser-stock-icons.h"
-#include "../support.h"
+#include "../ui-support.h"
#include "query-favorite-selector.h"
#include "query-editor.h"
#include <libgda/gda-debug-macros.h>
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+
/*
* Main static functions
*/
@@ -60,7 +61,7 @@ struct _QueryExecPerspectivePrivate {
GtkWidget *favorites;
gboolean favorites_shown;
BrowserWindow *bwin;
- BrowserConnection *bcnc;
+ TConnection *tcnc;
};
GType
@@ -137,7 +138,7 @@ query_exec_perspective_init (QueryExecPerspective *perspective)
gtk_orientable_set_orientation (GTK_ORIENTABLE (perspective), GTK_ORIENTATION_VERTICAL);
}
-static void fav_selection_changed_cb (GtkWidget *widget, gint fav_id, ToolsFavoritesType fav_type,
+static void fav_selection_changed_cb (GtkWidget *widget, gint fav_id, TFavoritesType fav_type,
const gchar *selection, QueryExecPerspective *perspective);
static void close_button_clicked_cb (GtkWidget *wid, GtkWidget *page_widget);
@@ -149,7 +150,7 @@ static void close_button_clicked_cb (GtkWidget *wid, GtkWidget *page_widget);
BrowserPerspective *
query_exec_perspective_new (BrowserWindow *bwin)
{
- BrowserConnection *bcnc;
+ TConnection *tcnc;
BrowserPerspective *bpers;
QueryExecPerspective *perspective;
gboolean fav_supported;
@@ -158,15 +159,15 @@ query_exec_perspective_new (BrowserWindow *bwin)
perspective = (QueryExecPerspective*) bpers;
perspective->priv->bwin = bwin;
- bcnc = browser_window_get_connection (bwin);
- perspective->priv->bcnc = g_object_ref (bcnc);
- fav_supported = browser_connection_get_favorites (bcnc) ? TRUE : FALSE;
+ tcnc = browser_window_get_connection (bwin);
+ perspective->priv->tcnc = g_object_ref (tcnc);
+ fav_supported = t_connection_get_favorites (tcnc) ? TRUE : FALSE;
/* contents */
GtkWidget *paned, *nb, *wid;
paned = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
if (fav_supported) {
- wid = query_favorite_selector_new (bcnc);
+ wid = query_favorite_selector_new (tcnc);
g_signal_connect (wid, "selection-changed",
G_CALLBACK (fav_selection_changed_cb), bpers);
gtk_paned_pack1 (GTK_PANED (paned), wid, FALSE, TRUE);
@@ -182,7 +183,7 @@ query_exec_perspective_new (BrowserWindow *bwin)
GtkWidget *page, *tlabel, *button;
- page = query_console_page_new (bcnc);
+ page = query_console_page_new (tcnc);
tlabel = browser_page_get_tab_label (BROWSER_PAGE (page), &button);
g_signal_connect (button, "clicked",
G_CALLBACK (close_button_clicked_cb), page);
@@ -211,7 +212,7 @@ query_exec_perspective_new (BrowserWindow *bwin)
static void
fav_selection_changed_cb (G_GNUC_UNUSED GtkWidget *widget, gint fav_id,
- G_GNUC_UNUSED ToolsFavoritesType fav_type, const gchar *selection,
+ G_GNUC_UNUSED TFavoritesType fav_type, const gchar *selection,
QueryExecPerspective *perspective)
{
GtkNotebook *nb;
@@ -252,8 +253,8 @@ query_exec_perspective_dispose (GObject *object)
perspective = QUERY_EXEC_PERSPECTIVE (object);
if (perspective->priv) {
browser_perspective_declare_notebook ((BrowserPerspective*) perspective, NULL);
- if (perspective->priv->bcnc)
- g_object_unref (perspective->priv->bcnc);
+ if (perspective->priv->tcnc)
+ g_object_unref (perspective->priv->tcnc);
g_free (perspective->priv);
perspective->priv = NULL;
@@ -268,13 +269,13 @@ query_exec_add_cb (G_GNUC_UNUSED GtkAction *action, BrowserPerspective *bpers)
{
GtkWidget *page, *tlabel, *button;
QueryExecPerspective *perspective;
- BrowserConnection *bcnc;
+ TConnection *tcnc;
gint i;
perspective = QUERY_EXEC_PERSPECTIVE (bpers);
- bcnc = perspective->priv->bcnc;
+ tcnc = perspective->priv->tcnc;
- page = query_console_page_new (bcnc);
+ page = query_console_page_new (tcnc);
gtk_widget_show (page);
tlabel = browser_page_get_tab_label (BROWSER_PAGE (page), &button);
g_signal_connect (button, "clicked",
@@ -316,7 +317,7 @@ static const GtkToggleActionEntry ui_toggle_actions [] =
static GtkActionEntry ui_actions[] = {
{ "QueryExecMenu", NULL, N_("_Query"), NULL, N_("Query"), NULL },
- { "QueryExecItem1", STOCK_CONSOLE, N_("_New Editor"), "<control>T", N_("Open a new query editor"),
+ { "QueryExecItem1", GTK_STOCK_MISSING_IMAGE, N_("_New Editor"), "<control>T", N_("Open a new query
editor"),
G_CALLBACK (query_exec_add_cb)},
};
diff --git a/tools/browser/query-exec/query-favorite-selector.c
b/tools/browser/query-exec/query-favorite-selector.c
index bca26ed..cf69975 100644
--- a/tools/browser/query-exec/query-favorite-selector.c
+++ b/tools/browser/query-exec/query-favorite-selector.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 - 2012 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2009 - 2014 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2010 David King <davidk openismus com>
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
*
@@ -26,7 +26,7 @@
#include "../mgr-favorites.h"
#include <libgda-ui/gdaui-tree-store.h>
#include "../dnd.h"
-#include "../support.h"
+#include "../ui-support.h"
#include "marshal.h"
#include "../gdaui-bar.h"
#include <gdk/gdkkeysyms.h>
@@ -34,7 +34,7 @@
#include "query-editor.h"
struct _QueryFavoriteSelectorPrivate {
- BrowserConnection *bcnc;
+ TConnection *tcnc;
GdaTree *tree;
GtkWidget *treeview;
guint idle_update_favorites;
@@ -54,7 +54,7 @@ static void query_favorite_selector_init (QueryFavoriteSelector *tsel,
QueryFavoriteSelectorClass *klass);
static void query_favorite_selector_dispose (GObject *object);
-static void favorites_changed_cb (ToolsFavorites *bfav, QueryFavoriteSelector *tsel);
+static void favorites_changed_cb (TFavorites *bfav, QueryFavoriteSelector *tsel);
enum {
SELECTION_CHANGED,
@@ -124,10 +124,10 @@ query_favorite_selector_dispose (GObject *object)
if (tsel->priv->tree)
g_object_unref (tsel->priv->tree);
- if (tsel->priv->bcnc) {
- g_signal_handlers_disconnect_by_func (browser_connection_get_favorites
(tsel->priv->bcnc),
+ if (tsel->priv->tcnc) {
+ g_signal_handlers_disconnect_by_func (t_connection_get_favorites (tsel->priv->tcnc),
G_CALLBACK (favorites_changed_cb), tsel);
- g_object_unref (tsel->priv->bcnc);
+ g_object_unref (tsel->priv->tcnc);
}
if (tsel->priv->popup_properties)
@@ -177,18 +177,18 @@ favorite_delete_selected (QueryFavoriteSelector *tsel)
select = gtk_tree_view_get_selection (GTK_TREE_VIEW (tsel->priv->treeview));
if (gtk_tree_selection_get_selected (select, &model, &iter)) {
- ToolsFavorites *bfav;
- ToolsFavoritesAttributes fav;
+ TFavorites *bfav;
+ TFavoritesAttributes fav;
GError *lerror = NULL;
- memset (&fav, 0, sizeof (ToolsFavoritesAttributes));
+ memset (&fav, 0, sizeof (TFavoritesAttributes));
gtk_tree_model_get (model, &iter,
COLUMN_ID, &(fav.id), -1);
- bfav = browser_connection_get_favorites (tsel->priv->bcnc);
- if (!gda_tools_favorites_delete (bfav, 0, &fav, NULL)) {
- browser_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*)tsel),
- _("Could not remove favorite: %s"),
- lerror && lerror->message ? lerror->message : _("No detail"));
+ bfav = t_connection_get_favorites (tsel->priv->tcnc);
+ if (! t_favorites_delete (bfav, 0, &fav, NULL)) {
+ ui_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*)tsel),
+ _("Could not remove favorite: %s"),
+ lerror && lerror->message ? lerror->message : _("No detail"));
if (lerror)
g_error_free (lerror);
}
@@ -197,9 +197,9 @@ favorite_delete_selected (QueryFavoriteSelector *tsel)
gint id;
gchar *tmp;
tmp = g_strdup_printf ("QUERY%d", fav.id);
- id = gda_tools_favorites_find (bfav, 0, tmp, &fav, NULL);
+ id = t_favorites_find (bfav, 0, tmp, &fav, NULL);
if (id >= 0) {
- gda_tools_favorites_delete (bfav, 0, &fav, NULL);
+ t_favorites_delete (bfav, 0, &fav, NULL);
/*g_print ("ACTION_DELETED %d: %s\n", fav.id, tmp);*/
}
g_free (tmp);
@@ -244,26 +244,26 @@ selection_changed_cb (GtkTreeView *treeview, G_GNUC_UNUSED GtkTreePath *path,
static gboolean
prop_save_timeout (QueryFavoriteSelector *tsel)
{
- ToolsFavorites *bfav;
- ToolsFavoritesAttributes fav;
+ TFavorites *bfav;
+ TFavoritesAttributes fav;
GError *error = NULL;
gboolean allok, actiondel = TRUE;
- bfav = browser_connection_get_favorites (tsel->priv->bcnc);
+ bfav = t_connection_get_favorites (tsel->priv->tcnc);
- memset (&fav, 0, sizeof (ToolsFavoritesAttributes));
+ memset (&fav, 0, sizeof (TFavoritesAttributes));
fav.id = tsel->priv->properties_id;
- fav.type = GDA_TOOLS_FAVORITES_QUERIES;
+ fav.type = T_FAVORITES_QUERIES;
fav.name = (gchar*) gtk_entry_get_text (GTK_ENTRY (tsel->priv->properties_name));
fav.descr = NULL;
fav.contents = query_editor_get_all_text (QUERY_EDITOR (tsel->priv->properties_text));
- allok = gda_tools_favorites_add (bfav, 0, &fav, ORDER_KEY_QUERIES,
- tsel->priv->properties_position, &error);
+ allok = t_favorites_add (bfav, 0, &fav, ORDER_KEY_QUERIES,
+ tsel->priv->properties_position, &error);
if (! allok) {
- browser_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) tsel),
- _("Could not add favorite: %s"),
- error && error->message ? error->message : _("No detail"));
+ ui_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) tsel),
+ _("Could not add favorite: %s"),
+ error && error->message ? error->message : _("No detail"));
if (error)
g_error_free (error);
}
@@ -275,16 +275,16 @@ prop_save_timeout (QueryFavoriteSelector *tsel)
is_action = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (tsel->priv->properties_action));
if (is_action) {
fav.id = -1;
- fav.type = GDA_TOOLS_FAVORITES_ACTIONS;
+ fav.type = T_FAVORITES_ACTIONS;
fav.name = (gchar*) gtk_entry_get_text (GTK_ENTRY (tsel->priv->properties_name));
fav.descr = NULL;
fav.contents = g_strdup_printf ("QUERY%d", qid);
- allok = gda_tools_favorites_add (bfav, 0, &fav, -1,
- tsel->priv->properties_position, &error);
+ allok = t_favorites_add (bfav, 0, &fav, -1,
+ tsel->priv->properties_position, &error);
if (! allok) {
- browser_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) tsel),
- _("Could not add action: %s"),
- error && error->message ? error->message : _("No
detail"));
+ ui_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) tsel),
+ _("Could not add action: %s"),
+ error && error->message ? error->message : _("No detail"));
if (error)
g_error_free (error);
}
@@ -300,9 +300,9 @@ prop_save_timeout (QueryFavoriteSelector *tsel)
gint id;
gchar *tmp;
tmp = g_strdup_printf ("QUERY%d", tsel->priv->properties_id);
- id = gda_tools_favorites_find (bfav, 0, tmp, &fav, NULL);
+ id = t_favorites_find (bfav, 0, tmp, &fav, NULL);
if (id >= 0) {
- gda_tools_favorites_delete (bfav, 0, &fav, NULL);
+ t_favorites_delete (bfav, 0, &fav, NULL);
/*g_print ("ACTION_DELETED %d: %s\n", fav.id, tmp);*/
}
g_free (tmp);
@@ -434,11 +434,11 @@ properties_activated_cb (GtkMenuItem *mitem, QueryFavoriteSelector *tsel)
if (tsel->priv->properties_id >= 0) {
gint id;
gchar *tmp;
- ToolsFavorites *bfav;
- ToolsFavoritesAttributes fav;
- bfav = browser_connection_get_favorites (tsel->priv->bcnc);
+ TFavorites *bfav;
+ TFavoritesAttributes fav;
+ bfav = t_connection_get_favorites (tsel->priv->tcnc);
tmp = g_strdup_printf ("QUERY%d", tsel->priv->properties_id);
- id = gda_tools_favorites_find (bfav, 0, tmp, &fav, NULL);
+ id = t_favorites_find (bfav, 0, tmp, &fav, NULL);
if (id >= 0) {
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
(tsel->priv->properties_action),
TRUE);
@@ -470,14 +470,19 @@ do_popup_menu (G_GNUC_UNUSED GtkWidget *widget, GdkEventButton *event, QueryFavo
menu = gtk_menu_new ();
g_signal_connect (menu, "deactivate",
G_CALLBACK (gtk_widget_hide), NULL);
-
- mitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_PROPERTIES, NULL);
+
+ GtkWidget *img;
+ img = gtk_image_new_from_icon_name ("document-properties", GTK_ICON_SIZE_MENU);
+ mitem = gtk_menu_item_new ();
+ gtk_container_add (GTK_CONTAINER (mitem), img);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), mitem);
gtk_widget_show (mitem);
g_signal_connect (mitem, "activate",
G_CALLBACK (properties_activated_cb), tsel);
- mitem = gtk_image_menu_item_new_from_stock (GTK_STOCK_DELETE, NULL);
+ img = gtk_image_new_from_icon_name ("edit-delete", GTK_ICON_SIZE_MENU);
+ mitem = gtk_menu_item_new ();
+ gtk_container_add (GTK_CONTAINER (mitem), img);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), mitem);
gtk_widget_show (mitem);
g_signal_connect (mitem, "activate",
@@ -533,21 +538,21 @@ static gboolean tree_store_drag_get_cb (GdauiTreeStore *store, const gchar *path
* Returns: a new #GtkWidget
*/
GtkWidget *
-query_favorite_selector_new (BrowserConnection *bcnc)
+query_favorite_selector_new (TConnection *tcnc)
{
QueryFavoriteSelector *tsel;
GdaTreeManager *manager;
- g_return_val_if_fail (BROWSER_IS_CONNECTION (bcnc), NULL);
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
tsel = QUERY_FAVORITE_SELECTOR (g_object_new (QUERY_FAVORITE_SELECTOR_TYPE, NULL));
- tsel->priv->bcnc = g_object_ref (bcnc);
- g_signal_connect (browser_connection_get_favorites (tsel->priv->bcnc), "favorites-changed",
+ tsel->priv->tcnc = g_object_ref (tcnc);
+ g_signal_connect (t_connection_get_favorites (tsel->priv->tcnc), "favorites-changed",
G_CALLBACK (favorites_changed_cb), tsel);
/* create tree managers */
tsel->priv->tree = gda_tree_new ();
- manager = mgr_favorites_new (bcnc, GDA_TOOLS_FAVORITES_QUERIES, ORDER_KEY_QUERIES);
+ manager = mgr_favorites_new (tcnc, T_FAVORITES_QUERIES, ORDER_KEY_QUERIES);
gda_tree_add_manager (tsel->priv->tree, manager);
g_object_unref (manager);
@@ -563,7 +568,7 @@ query_favorite_selector_new (BrowserConnection *bcnc)
str = g_strdup_printf ("<b>%s</b>", _("Favorites"));
label = gdaui_bar_new (str);
g_free (str);
- gdaui_bar_set_icon_from_pixbuf (GDAUI_BAR (label), browser_get_pixbuf_icon (BROWSER_ICON_BOOKMARK));
+ gdaui_bar_set_icon_from_resource (GDAUI_BAR (label), "/images/gda-browser-bookmark.png");
gtk_box_pack_start (GTK_BOX (tsel), label, FALSE, FALSE, 0);
gtk_widget_show (label);
@@ -581,7 +586,7 @@ query_favorite_selector_new (BrowserConnection *bcnc)
G_TYPE_INT, MGR_FAVORITES_ID_ATT_NAME,
G_TYPE_STRING, MGR_FAVORITES_NAME_ATT_NAME,
G_TYPE_STRING, "summary");
- treeview = browser_make_tree_view (model);
+ treeview = ui_make_tree_view (model);
tsel->priv->treeview = treeview;
g_object_unref (model);
@@ -679,20 +684,20 @@ static gboolean
tree_store_drag_drop_cb (G_GNUC_UNUSED GdauiTreeStore *store, const gchar *path,
GtkSelectionData *selection_data, QueryFavoriteSelector *tsel)
{
- ToolsFavorites *bfav;
- ToolsFavoritesAttributes fav;
+ TFavorites *bfav;
+ TFavoritesAttributes fav;
GError *error = NULL;
gint pos;
gboolean retval = TRUE;
gint id;
- bfav = browser_connection_get_favorites (tsel->priv->bcnc);
+ bfav = t_connection_get_favorites (tsel->priv->tcnc);
- id = gda_tools_favorites_find (bfav, 0, (gchar*) gtk_selection_data_get_data (selection_data),
- &fav, NULL);
+ id = t_favorites_find (bfav, 0, (gchar*) gtk_selection_data_get_data (selection_data),
+ &fav, NULL);
if (id < 0) {
- memset (&fav, 0, sizeof (ToolsFavoritesAttributes));
+ memset (&fav, 0, sizeof (TFavoritesAttributes));
fav.id = -1;
- fav.type = GDA_TOOLS_FAVORITES_QUERIES;
+ fav.type = T_FAVORITES_QUERIES;
fav.name = _("Unnamed query");
fav.descr = NULL;
fav.contents = (gchar*) gtk_selection_data_get_data (selection_data);
@@ -701,17 +706,17 @@ tree_store_drag_drop_cb (G_GNUC_UNUSED GdauiTreeStore *store, const gchar *path,
pos = atoi (path);
/*g_print ("%s() path => %s, pos: %d\n", __FUNCTION__, path, pos);*/
- if (! gda_tools_favorites_add (bfav, 0, &fav, ORDER_KEY_QUERIES, pos, &error)) {
- browser_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) tsel),
- _("Could not add favorite: %s"),
- error && error->message ? error->message : _("No detail"));
+ if (! t_favorites_add (bfav, 0, &fav, ORDER_KEY_QUERIES, pos, &error)) {
+ ui_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) tsel),
+ _("Could not add favorite: %s"),
+ error && error->message ? error->message : _("No detail"));
if (error)
g_error_free (error);
retval = FALSE;
}
if (id >= 0)
- gda_tools_favorites_reset_attributes (&fav);
+ t_favorites_reset_attributes (&fav);
return retval;
}
@@ -753,7 +758,7 @@ tree_store_drag_get_cb (G_GNUC_UNUSED GdauiTreeStore *store, const gchar *path,
}
static void
-favorites_changed_cb (G_GNUC_UNUSED ToolsFavorites *bfav, QueryFavoriteSelector *tsel)
+favorites_changed_cb (G_GNUC_UNUSED TFavorites *bfav, QueryFavoriteSelector *tsel)
{
if (! gda_tree_update_all (tsel->priv->tree, NULL)) {
if (tsel->priv->idle_update_favorites == 0)
diff --git a/tools/browser/query-exec/query-favorite-selector.h
b/tools/browser/query-exec/query-favorite-selector.h
index e8f9e4e..d536459 100644
--- a/tools/browser/query-exec/query-favorite-selector.h
+++ b/tools/browser/query-exec/query-favorite-selector.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 - 2012 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2009 - 2014 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
*
* This program is free software; you can redistribute it and/or
@@ -21,7 +21,7 @@
#define __QUERY_FAVORITE_SELECTOR_H__
#include <gtk/gtk.h>
-#include "../browser-connection.h"
+#include "../common/t-connection.h"
G_BEGIN_DECLS
@@ -44,12 +44,12 @@ struct _QueryFavoriteSelectorClass {
GtkBoxClass parent_class;
void (*selection_changed) (QueryFavoriteSelector *sel, gint fav_id,
- ToolsFavoritesType fav_type, const gchar *fav_contents);
+ TFavoritesType fav_type, const gchar *fav_contents);
};
GType query_favorite_selector_get_type (void) G_GNUC_CONST;
-GtkWidget *query_favorite_selector_new (BrowserConnection *bcnc);
+GtkWidget *query_favorite_selector_new (TConnection *tcnc);
G_END_DECLS
diff --git a/tools/browser/query-exec/query-result.c b/tools/browser/query-exec/query-result.c
index 8ea4a7f..b6eab38 100644
--- a/tools/browser/query-exec/query-result.c
+++ b/tools/browser/query-exec/query-result.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2009 - 2014 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2010 David King <davidk openismus com>
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
*
@@ -24,9 +24,11 @@
#include "../browser-window.h"
#include <libgda-ui/libgda-ui.h>
#include <libgda/sql-parser/gda-sql-parser.h>
-#include "../common/ui-formgrid.h"
+#include "../ui-formgrid.h"
#include "marshal.h"
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+
struct _QueryResultPrivate {
QueryEditor *history;
@@ -372,19 +374,19 @@ make_widget_for_data_model (GdaDataModel *model, QueryResult *qres, const gchar
grid = ui_formgrid_new (model, TRUE, GDAUI_DATA_PROXY_INFO_ROW_MODIFY_BUTTONS);
ui_formgrid_set_sample_size (UI_FORMGRID (grid), 300);
if (sql) {
- BrowserConnection *bcnc;
- bcnc = browser_window_get_connection ((BrowserWindow*) gtk_widget_get_toplevel ((GtkWidget*)
qres));
- if (!bcnc)
+ TConnection *tcnc;
+ tcnc = browser_window_get_connection ((BrowserWindow*) gtk_widget_get_toplevel ((GtkWidget*)
qres));
+ if (!tcnc)
goto out;
GdaSqlParser *parser;
GdaStatement *stmt;
- parser = browser_connection_create_parser (bcnc);
+ parser = t_connection_create_parser (tcnc);
stmt = gda_sql_parser_parse_string (parser, sql, NULL, NULL);
g_object_unref (parser);
if (!stmt)
goto out;
- ui_formgrid_handle_user_prefs (UI_FORMGRID (grid), bcnc, stmt);
+ ui_formgrid_handle_user_prefs (UI_FORMGRID (grid), tcnc, stmt);
g_object_unref (stmt);
GtkUIManager *uimanager;
diff --git a/tools/browser/query-exec/query-result.h b/tools/browser/query-exec/query-result.h
index 4bee856..01f7352 100644
--- a/tools/browser/query-exec/query-result.h
+++ b/tools/browser/query-exec/query-result.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2009 - 2014 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
*
* This program is free software; you can redistribute it and/or
diff --git a/tools/browser/schema-browser/Makefile.am b/tools/browser/schema-browser/Makefile.am
index d90749b..326f24e 100644
--- a/tools/browser/schema-browser/Makefile.am
+++ b/tools/browser/schema-browser/Makefile.am
@@ -5,6 +5,9 @@ ldap_flags=-DHAVE_LDAP
endif
AM_CPPFLAGS = \
+ -I$(top_srcdir)/tools \
+ -I$(top_srcdir)/tools/base \
+ -I$(top_srcdir)/tools/common \
-I$(top_srcdir)/tools/browser \
-I$(top_builddir) \
-I$(top_srcdir) \
diff --git a/tools/browser/schema-browser/favorite-selector.c
b/tools/browser/schema-browser/favorite-selector.c
index c696e87..18179b9 100644
--- a/tools/browser/schema-browser/favorite-selector.c
+++ b/tools/browser/schema-browser/favorite-selector.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 - 2012 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2009 - 2014 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2010 David King <davidk openismus com>
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
*
@@ -25,13 +25,13 @@
#include "../mgr-favorites.h"
#include <libgda-ui/gdaui-tree-store.h>
#include "../dnd.h"
-#include "../support.h"
+#include "../ui-support.h"
#include "marshal.h"
#include "../gdaui-bar.h"
#include <gdk/gdkkeysyms.h>
struct _FavoriteSelectorPrivate {
- BrowserConnection *bcnc;
+ TConnection *tcnc;
GdaTree *tree;
GtkWidget *treeview;
guint idle_update_favorites;
@@ -42,7 +42,7 @@ static void favorite_selector_init (FavoriteSelector *tsel,
FavoriteSelectorClass *klass);
static void favorite_selector_dispose (GObject *object);
-static void favorites_changed_cb (ToolsFavorites *bfav, FavoriteSelector *tsel);
+static void favorites_changed_cb (TFavorites *bfav, FavoriteSelector *tsel);
enum {
SELECTION_CHANGED,
@@ -109,10 +109,10 @@ favorite_selector_dispose (GObject *object)
if (tsel->priv->tree)
g_object_unref (tsel->priv->tree);
- if (tsel->priv->bcnc) {
- g_signal_handlers_disconnect_by_func (browser_connection_get_favorites
(tsel->priv->bcnc),
+ if (tsel->priv->tcnc) {
+ g_signal_handlers_disconnect_by_func (t_connection_get_favorites (tsel->priv->tcnc),
G_CALLBACK (favorites_changed_cb), tsel);
- g_object_unref (tsel->priv->bcnc);
+ g_object_unref (tsel->priv->tcnc);
}
g_free (tsel->priv);
@@ -156,18 +156,18 @@ key_press_event_cb (GtkTreeView *treeview, GdkEventKey *event, FavoriteSelector
select = gtk_tree_view_get_selection (treeview);
if (gtk_tree_selection_get_selected (select, &model, &iter)) {
- ToolsFavorites *bfav;
- ToolsFavoritesAttributes fav;
+ TFavorites *bfav;
+ TFavoritesAttributes fav;
GError *lerror = NULL;
- memset (&fav, 0, sizeof (ToolsFavoritesAttributes));
+ memset (&fav, 0, sizeof (TFavoritesAttributes));
gtk_tree_model_get (model, &iter,
COLUMN_ID, &(fav.id), -1);
- bfav = browser_connection_get_favorites (tsel->priv->bcnc);
- if (!gda_tools_favorites_delete (bfav, 0, &fav, NULL)) {
- browser_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*)tsel),
- _("Could not remove favorite: %s"),
- lerror && lerror->message ? lerror->message : _("No
detail"));
+ bfav = t_connection_get_favorites (tsel->priv->tcnc);
+ if (!t_favorites_delete (bfav, 0, &fav, NULL)) {
+ ui_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*)tsel),
+ _("Could not remove favorite: %s"),
+ lerror && lerror->message ? lerror->message : _("No detail"));
if (lerror)
g_error_free (lerror);
}
@@ -215,21 +215,21 @@ static gboolean tree_store_drag_get_cb (GdauiTreeStore *store, const gchar *path
* Returns: a new #GtkWidget
*/
GtkWidget *
-favorite_selector_new (BrowserConnection *bcnc)
+favorite_selector_new (TConnection *tcnc)
{
FavoriteSelector *tsel;
GdaTreeManager *manager;
- g_return_val_if_fail (BROWSER_IS_CONNECTION (bcnc), NULL);
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
tsel = FAVORITE_SELECTOR (g_object_new (FAVORITE_SELECTOR_TYPE, NULL));
- tsel->priv->bcnc = g_object_ref (bcnc);
- g_signal_connect (browser_connection_get_favorites (tsel->priv->bcnc), "favorites-changed",
+ tsel->priv->tcnc = g_object_ref (tcnc);
+ g_signal_connect (t_connection_get_favorites (tsel->priv->tcnc), "favorites-changed",
G_CALLBACK (favorites_changed_cb), tsel);
/* create tree managers */
tsel->priv->tree = gda_tree_new ();
- manager = mgr_favorites_new (bcnc, GDA_TOOLS_FAVORITES_TABLES | GDA_TOOLS_FAVORITES_DIAGRAMS,
+ manager = mgr_favorites_new (tcnc, T_FAVORITES_TABLES | T_FAVORITES_DIAGRAMS,
ORDER_KEY_SCHEMA);
gda_tree_add_manager (tsel->priv->tree, manager);
g_object_unref (manager);
@@ -245,7 +245,7 @@ favorite_selector_new (BrowserConnection *bcnc)
str = g_strdup_printf ("<b>%s</b>", _("Favorites"));
label = gdaui_bar_new (str);
g_free (str);
- gdaui_bar_set_icon_from_pixbuf (GDAUI_BAR (label), browser_get_pixbuf_icon (BROWSER_ICON_BOOKMARK));
+ gdaui_bar_set_icon_from_pixbuf (GDAUI_BAR (label), ui_get_pixbuf_icon (UI_ICON_BOOKMARK));
gtk_box_pack_start (GTK_BOX (tsel), label, FALSE, FALSE, 0);
gtk_widget_show (label);
@@ -261,7 +261,7 @@ favorite_selector_new (BrowserConnection *bcnc)
G_TYPE_STRING, MGR_FAVORITES_CONTENTS_ATT_NAME,
G_TYPE_UINT, MGR_FAVORITES_TYPE_ATT_NAME,
G_TYPE_INT, MGR_FAVORITES_ID_ATT_NAME);
- treeview = browser_make_tree_view (model);
+ treeview = ui_make_tree_view (model);
tsel->priv->treeview = treeview;
g_object_unref (model);
@@ -330,14 +330,14 @@ static gboolean
tree_store_drag_drop_cb (G_GNUC_UNUSED GdauiTreeStore *store, const gchar *path,
GtkSelectionData *selection_data, FavoriteSelector *tsel)
{
- ToolsFavorites *bfav;
- ToolsFavoritesAttributes fav;
+ TFavorites *bfav;
+ TFavoritesAttributes fav;
GError *error = NULL;
gint pos;
- memset (&fav, 0, sizeof (ToolsFavoritesAttributes));
+ memset (&fav, 0, sizeof (TFavoritesAttributes));
fav.id = -1;
- fav.type = GDA_TOOLS_FAVORITES_TABLES;
+ fav.type = T_FAVORITES_TABLES;
fav.name = NULL;
fav.descr = NULL;
fav.contents = (gchar*) gtk_selection_data_get_data (selection_data);
@@ -345,9 +345,9 @@ tree_store_drag_drop_cb (G_GNUC_UNUSED GdauiTreeStore *store, const gchar *path,
pos = atoi (path);
/*g_print ("%s() path => %s, pos: %d\n", __FUNCTION__, path, pos);*/
- bfav = browser_connection_get_favorites (tsel->priv->bcnc);
- if (! gda_tools_favorites_add (bfav, 0, &fav, ORDER_KEY_SCHEMA, pos, &error)) {
- browser_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) tsel),
+ bfav = t_connection_get_favorites (tsel->priv->tcnc);
+ if (! t_favorites_add (bfav, 0, &fav, ORDER_KEY_SCHEMA, pos, &error)) {
+ ui_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) tsel),
_("Could not add favorite: %s"),
error && error->message ? error->message : _("No detail"));
if (error)
@@ -394,7 +394,7 @@ tree_store_drag_get_cb (G_GNUC_UNUSED GdauiTreeStore *store, const gchar *path,
}
static void
-favorites_changed_cb (G_GNUC_UNUSED ToolsFavorites *bfav, FavoriteSelector *tsel)
+favorites_changed_cb (G_GNUC_UNUSED TFavorites *bfav, FavoriteSelector *tsel)
{
if (! gda_tree_update_all (tsel->priv->tree, NULL)) {
if (tsel->priv->idle_update_favorites == 0)
diff --git a/tools/browser/schema-browser/favorite-selector.h
b/tools/browser/schema-browser/favorite-selector.h
index 4ebb3a4..37f7947 100644
--- a/tools/browser/schema-browser/favorite-selector.h
+++ b/tools/browser/schema-browser/favorite-selector.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 - 2012 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2009 - 2014 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
*
* This program is free software; you can redistribute it and/or
@@ -21,7 +21,8 @@
#define __FAVORITE_SELECTOR_H__
#include <gtk/gtk.h>
-#include "../browser-connection.h"
+#include <t-connection.h>
+#include <t-favorites.h>
G_BEGIN_DECLS
@@ -36,20 +37,20 @@ typedef struct _FavoriteSelectorClass FavoriteSelectorClass;
typedef struct _FavoriteSelectorPrivate FavoriteSelectorPrivate;
struct _FavoriteSelector {
- GtkBox parent;
+ GtkBox parent;
FavoriteSelectorPrivate *priv;
};
struct _FavoriteSelectorClass {
- GtkBoxClass parent_class;
+ GtkBoxClass parent_class;
- void (*selection_changed) (FavoriteSelector *sel, gint fav_id,
- ToolsFavoritesType fav_type, const gchar *fav_contents);
+ void (*selection_changed) (FavoriteSelector *sel, gint fav_id,
+ TFavoritesType fav_type, const gchar *fav_contents);
};
GType favorite_selector_get_type (void) G_GNUC_CONST;
-GtkWidget *favorite_selector_new (BrowserConnection *bcnc);
+GtkWidget *favorite_selector_new (TConnection *tcnc);
G_END_DECLS
diff --git a/tools/browser/schema-browser/mgr-columns.c b/tools/browser/schema-browser/mgr-columns.c
index 74e9ce6..2d22827 100644
--- a/tools/browser/schema-browser/mgr-columns.c
+++ b/tools/browser/schema-browser/mgr-columns.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 - 2012 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2009 - 2014 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2010 David King <davidk openismus com>
*
* This program is free software; you can redistribute it and/or
@@ -21,10 +21,10 @@
#include <libgda/libgda.h>
#include <sql-parser/gda-sql-parser.h>
#include "mgr-columns.h"
-#include "support.h"
+#include "../ui-support.h"
struct _MgrColumnsPriv {
- BrowserConnection *bcnc;
+ TConnection *tcnc;
gchar *schema;
gchar *table_name;
};
@@ -73,7 +73,7 @@ mgr_columns_class_init (MgrColumnsClass *klass)
g_object_class_install_property (object_class, PROP_BROWSER_CNC,
g_param_spec_object ("browser-connection", NULL, "Connection to
use",
- BROWSER_TYPE_CONNECTION,
+ T_TYPE_CONNECTION,
G_PARAM_READABLE | G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY));
object_class->dispose = mgr_columns_dispose;
}
@@ -90,8 +90,8 @@ mgr_columns_dispose (GObject *object)
MgrColumns *mgr = (MgrColumns *) object;
if (mgr->priv) {
- if (mgr->priv->bcnc)
- g_object_unref (mgr->priv->bcnc);
+ if (mgr->priv->tcnc)
+ g_object_unref (mgr->priv->tcnc);
g_free (mgr->priv->schema);
g_free (mgr->priv->table_name);
@@ -157,9 +157,9 @@ mgr_columns_set_property (GObject *object,
if (mgr->priv) {
switch (param_id) {
case PROP_BROWSER_CNC:
- mgr->priv->bcnc = (BrowserConnection*) g_value_get_object (value);
- if (mgr->priv->bcnc)
- g_object_ref (mgr->priv->bcnc);
+ mgr->priv->tcnc = (TConnection*) g_value_get_object (value);
+ if (mgr->priv->tcnc)
+ g_object_ref (mgr->priv->tcnc);
break;
default:
@@ -181,7 +181,7 @@ mgr_columns_get_property (GObject *object,
if (mgr->priv) {
switch (param_id) {
case PROP_BROWSER_CNC:
- g_value_set_object (value, mgr->priv->bcnc);
+ g_value_set_object (value, mgr->priv->tcnc);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
@@ -192,7 +192,7 @@ mgr_columns_get_property (GObject *object,
/**
* mgr_columns_new
- * @bcnc: a #BrowserConnection object
+ * @tcnc: a #TConnection object
* @schema: the schema the table is in
* @name: the table's name
*
@@ -202,15 +202,15 @@ mgr_columns_get_property (GObject *object,
* Returns: a new #GdaTreeManager object
*/
GdaTreeManager*
-mgr_columns_new (BrowserConnection *bcnc, const gchar *schema, const gchar *table)
+mgr_columns_new (TConnection *tcnc, const gchar *schema, const gchar *table)
{
MgrColumns *mgr;
- g_return_val_if_fail (BROWSER_IS_CONNECTION (bcnc), NULL);
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
g_return_val_if_fail (schema, NULL);
g_return_val_if_fail (table, NULL);
mgr = (MgrColumns*) g_object_new (MGR_COLUMNS_TYPE,
- "browser-connection", bcnc, NULL);
+ "browser-connection", tcnc, NULL);
mgr->priv->schema = g_strdup (schema);
mgr->priv->table_name = g_strdup (table);
@@ -272,7 +272,7 @@ mgr_columns_update_children (GdaTreeManager *manager, GdaTreeNode *node, const G
ehash = hash_for_existing_nodes (children_nodes);
GdaMetaStruct *mstruct;
- mstruct = browser_connection_get_meta_struct (mgr->priv->bcnc);
+ mstruct = t_connection_get_meta_struct (mgr->priv->tcnc);
if (!mstruct) {
g_set_error (error, MGR_COLUMNS_ERROR, MGR_COLUMNS_NO_META_STRUCT,
"%s", _("Not ready"));
@@ -353,21 +353,21 @@ mgr_columns_update_children (GdaTreeManager *manager, GdaTreeNode *node, const G
gda_value_free (av);
/* icon */
- BrowserIconType type = BROWSER_ICON_COLUMN;
+ UiIconType type = UI_ICON_COLUMN;
GdkPixbuf *pixbuf;
gboolean is_fk = column_is_fk_part (dbo, index);
if (col->pkey)
- type = BROWSER_ICON_COLUMN_PK;
+ type = UI_ICON_COLUMN_PK;
else if (!col->nullok) {
if (is_fk)
- type = BROWSER_ICON_COLUMN_FK_NN;
+ type = UI_ICON_COLUMN_FK_NN;
else
- type = BROWSER_ICON_COLUMN_NN;
+ type = UI_ICON_COLUMN_NN;
}
else if (is_fk)
- type = BROWSER_ICON_COLUMN_FK;
+ type = UI_ICON_COLUMN_FK;
- pixbuf = browser_get_pixbuf_icon (type);
+ pixbuf = ui_get_pixbuf_icon (type);
av = gda_value_new (G_TYPE_OBJECT);
g_value_set_object (av, pixbuf);
gda_tree_node_set_node_attribute (snode, "icon", av, NULL);
diff --git a/tools/browser/schema-browser/mgr-columns.h b/tools/browser/schema-browser/mgr-columns.h
index c6f8f1b..5cdc6f6 100644
--- a/tools/browser/schema-browser/mgr-columns.h
+++ b/tools/browser/schema-browser/mgr-columns.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2009 - 2014 Vivien Malerba <malerba gnome-db org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -20,7 +20,7 @@
#define ___MGR_COLUMNS_H__
#include <libgda/gda-tree-manager.h>
-#include "browser-connection.h"
+#include "t-connection.h"
G_BEGIN_DECLS
@@ -55,7 +55,7 @@ struct _MgrColumnsClass {
};
GType mgr_columns_get_type (void) G_GNUC_CONST;
-GdaTreeManager* mgr_columns_new (BrowserConnection *bcnc, const gchar *schema, const
gchar *table);
+GdaTreeManager* mgr_columns_new (TConnection *tcnc, const gchar *schema, const gchar
*table);
#define MGR_COLUMNS_COL_NAME_ATT_NAME "markup"
#define MGR_COLUMNS_COL_TYPE_ATT_NAME "type"
diff --git a/tools/browser/schema-browser/objects-index.c b/tools/browser/schema-browser/objects-index.c
index 39bb99c..b31aa19 100644
--- a/tools/browser/schema-browser/objects-index.c
+++ b/tools/browser/schema-browser/objects-index.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 - 2012 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2009 - 2014 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2010 David King <davidk openismus com>
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
*
@@ -25,15 +25,15 @@
#include "objects-index.h"
#include <libgda-ui/gdaui-tree-store.h>
#include "../dnd.h"
-#include "../support.h"
+#include "../ui-support.h"
#include "../gdaui-bar.h"
#include "marshal.h"
#include <gdk/gdkkeysyms.h>
#include <libgda-ui/internal/popup-container.h>
-#include "../common/objects-cloud.h"
+#include "../objects-cloud.h"
struct _ObjectsIndexPrivate {
- BrowserConnection *bcnc;
+ TConnection *tcnc;
ObjectsCloud *cloud;
};
@@ -42,7 +42,7 @@ static void objects_index_init (ObjectsIndex *index,
ObjectsIndexClass *klass);
static void objects_index_dispose (GObject *object);
-static void meta_changed_cb (BrowserConnection *bcnc, GdaMetaStruct *mstruct, ObjectsIndex *index);
+static void meta_changed_cb (TConnection *tcnc, GdaMetaStruct *mstruct, ObjectsIndex *index);
enum {
SELECTION_CHANGED,
@@ -94,10 +94,10 @@ objects_index_dispose (GObject *object)
/* free memory */
if (index->priv) {
- if (index->priv->bcnc) {
- g_signal_handlers_disconnect_by_func (index->priv->bcnc,
+ if (index->priv->tcnc) {
+ g_signal_handlers_disconnect_by_func (index->priv->tcnc,
G_CALLBACK (meta_changed_cb), index);
- g_object_unref (index->priv->bcnc);
+ g_object_unref (index->priv->tcnc);
}
g_free (index->priv);
index->priv = NULL;
@@ -136,7 +136,7 @@ cloud_object_selected_cb (G_GNUC_UNUSED ObjectsCloud *sel, G_GNUC_UNUSED Objects
{
/* FIXME: adjust with sel->priv->type */
g_signal_emit (index, objects_index_signals [SELECTION_CHANGED], 0,
- GDA_TOOLS_FAVORITES_TABLES, sel_contents);
+ T_FAVORITES_TABLES, sel_contents);
}
static void
@@ -153,15 +153,15 @@ find_changed_cb (GtkEntry *entry, ObjectsIndex *index)
* Returns:
*/
GtkWidget *
-objects_index_new (BrowserConnection *bcnc)
+objects_index_new (TConnection *tcnc)
{
ObjectsIndex *index;
- g_return_val_if_fail (BROWSER_IS_CONNECTION (bcnc), NULL);
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
index = OBJECTS_INDEX (g_object_new (OBJECTS_INDEX_TYPE, NULL));
- index->priv->bcnc = g_object_ref (bcnc);
- g_signal_connect (index->priv->bcnc, "meta-changed",
+ index->priv->tcnc = g_object_ref (tcnc);
+ g_signal_connect (index->priv->tcnc, "meta-changed",
G_CALLBACK (meta_changed_cb), index);
/* header */
@@ -181,7 +181,7 @@ objects_index_new (BrowserConnection *bcnc)
/* cloud */
GdaMetaStruct *mstruct;
GtkWidget *cloud;
- mstruct = browser_connection_get_meta_struct (index->priv->bcnc);
+ mstruct = t_connection_get_meta_struct (index->priv->tcnc);
cloud = objects_cloud_new (mstruct, OBJECTS_CLOUD_TYPE_TABLE);
objects_cloud_show_schemas (OBJECTS_CLOUD (cloud), TRUE);
gtk_box_pack_start (GTK_BOX (index), cloud, TRUE, TRUE, 0);
@@ -199,7 +199,7 @@ objects_index_new (BrowserConnection *bcnc)
}
static void
-meta_changed_cb (G_GNUC_UNUSED BrowserConnection *bcnc, GdaMetaStruct *mstruct, ObjectsIndex *index)
+meta_changed_cb (G_GNUC_UNUSED TConnection *tcnc, GdaMetaStruct *mstruct, ObjectsIndex *index)
{
objects_cloud_set_meta_struct (index->priv->cloud, mstruct);
}
diff --git a/tools/browser/schema-browser/objects-index.h b/tools/browser/schema-browser/objects-index.h
index 4e71e38..b48a05f 100644
--- a/tools/browser/schema-browser/objects-index.h
+++ b/tools/browser/schema-browser/objects-index.h
@@ -21,7 +21,7 @@
#define __OBJECTS_INDEX_H__
#include <gtk/gtk.h>
-#include "../browser-connection.h"
+#include "common/t-connection.h"
G_BEGIN_DECLS
@@ -45,12 +45,12 @@ struct _ObjectsIndexClass {
/* signals */
void (*selection_changed) (ObjectsIndex *sel,
- ToolsFavoritesType fav_type, const gchar *fav_contents);
+ TFavoritesType fav_type, const gchar *fav_contents);
};
GType objects_index_get_type (void) G_GNUC_CONST;
-GtkWidget *objects_index_new (BrowserConnection *bcnc);
+GtkWidget *objects_index_new (TConnection *tcnc);
G_END_DECLS
diff --git a/tools/browser/schema-browser/perspective-main.h b/tools/browser/schema-browser/perspective-main.h
index a92ae14..8bd3e71 100644
--- a/tools/browser/schema-browser/perspective-main.h
+++ b/tools/browser/schema-browser/perspective-main.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2009 - 2014 Vivien Malerba <malerba gnome-db org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -16,7 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#include "../decl.h"
+#include "../browser-perspective.h"
G_BEGIN_DECLS
diff --git a/tools/browser/schema-browser/relations-diagram.c
b/tools/browser/schema-browser/relations-diagram.c
index 42cefc5..e28d3b6 100644
--- a/tools/browser/schema-browser/relations-diagram.c
+++ b/tools/browser/schema-browser/relations-diagram.c
@@ -30,10 +30,10 @@
#include "../browser-perspective.h"
#include "../browser-window.h"
#include "../data-manager/data-manager-perspective.h"
-#include "../../tool-utils.h"
+#include "../../base-tool-utils.h"
struct _RelationsDiagramPrivate {
- BrowserConnection *bcnc;
+ TConnection *tcnc;
gint fav_id; /* diagram's ID as a favorite, -1=>not a favorite */
GdauiBar *header;
@@ -63,8 +63,8 @@ static GtkActionGroup *relations_diagram_page_get_actions_group (BrowserPag
static const gchar *relations_diagram_page_get_actions_ui (BrowserPage *page);
static GtkWidget *relations_diagram_page_get_tab_label (BrowserPage *page, GtkWidget
**out_close_button);
-static void meta_changed_cb (BrowserConnection *bcnc, GdaMetaStruct *mstruct, RelationsDiagram *diagram);
-static void favorites_changed_cb (BrowserConnection *bcnc, RelationsDiagram *diagram);
+static void meta_changed_cb (TConnection *tcnc, GdaMetaStruct *mstruct, RelationsDiagram *diagram);
+static void favorites_changed_cb (TConnection *tcnc, RelationsDiagram *diagram);
static void relations_diagram_set_fav_id (RelationsDiagram *diagram, gint fav_id, GError **error);
/* properties */
@@ -118,12 +118,12 @@ relations_diagram_dispose (GObject *object)
/* free memory */
if (diagram->priv) {
- if (diagram->priv->bcnc) {
- g_signal_handlers_disconnect_by_func (diagram->priv->bcnc,
+ if (diagram->priv->tcnc) {
+ g_signal_handlers_disconnect_by_func (diagram->priv->tcnc,
G_CALLBACK (meta_changed_cb), diagram);
- g_signal_handlers_disconnect_by_func (diagram->priv->bcnc,
+ g_signal_handlers_disconnect_by_func (diagram->priv->tcnc,
G_CALLBACK (favorites_changed_cb), diagram);
- g_object_unref (diagram->priv->bcnc);
+ g_object_unref (diagram->priv->tcnc);
}
if (diagram->priv->popup_container)
@@ -197,13 +197,13 @@ relations_diagram_get_property (GObject *object,
}
static void
-meta_changed_cb (G_GNUC_UNUSED BrowserConnection *bcnc, GdaMetaStruct *mstruct, RelationsDiagram *diagram)
+meta_changed_cb (G_GNUC_UNUSED TConnection *tcnc, GdaMetaStruct *mstruct, RelationsDiagram *diagram)
{
g_object_set (G_OBJECT (diagram->priv->canvas), "meta-struct", mstruct, NULL);
}
static void
-favorites_changed_cb (G_GNUC_UNUSED BrowserConnection *bcnc, RelationsDiagram *diagram)
+favorites_changed_cb (G_GNUC_UNUSED TConnection *tcnc, RelationsDiagram *diagram)
{
if (diagram->priv->fav_id >= 0)
relations_diagram_set_fav_id (diagram, diagram->priv->fav_id, NULL);
@@ -220,12 +220,12 @@ real_save_clicked_cb (GtkWidget *button, RelationsDiagram *diagram)
str = browser_canvas_serialize_items (BROWSER_CANVAS (diagram->priv->canvas));
GError *lerror = NULL;
- ToolsFavorites *bfav;
- ToolsFavoritesAttributes fav;
+ TFavorites *bfav;
+ TFavoritesAttributes fav;
- memset (&fav, 0, sizeof (ToolsFavoritesAttributes));
+ memset (&fav, 0, sizeof (TFavoritesAttributes));
fav.id = diagram->priv->fav_id;
- fav.type = GDA_TOOLS_FAVORITES_DIAGRAMS;
+ fav.type = T_FAVORITES_DIAGRAMS;
fav.name = gtk_editable_get_chars (GTK_EDITABLE (diagram->priv->name_entry), 0, -1);
if (!*fav.name) {
g_free (fav.name);
@@ -235,9 +235,9 @@ real_save_clicked_cb (GtkWidget *button, RelationsDiagram *diagram)
gtk_widget_hide (diagram->priv->popup_container);
- bfav = browser_connection_get_favorites (diagram->priv->bcnc);
- if (! gda_tools_favorites_add (bfav, 0, &fav, ORDER_KEY_SCHEMA, G_MAXINT, &lerror)) {
- browser_show_error ((GtkWindow*) gtk_widget_get_toplevel (button),
+ bfav = t_connection_get_favorites (diagram->priv->tcnc);
+ if (! t_favorites_add (bfav, 0, &fav, ORDER_KEY_SCHEMA, G_MAXINT, &lerror)) {
+ ui_show_error ((GtkWindow*) gtk_widget_get_toplevel (button),
"<b>%s:</b>\n%s",
_("Could not save diagram"),
lerror && lerror->message ? lerror->message : _("No detail"));
@@ -274,11 +274,11 @@ save_clicked_cb (GtkWidget *button, RelationsDiagram *diagram)
gtk_box_pack_start (GTK_BOX (hbox), wid, FALSE, FALSE, 5);
diagram->priv->name_entry = wid;
if (diagram->priv->fav_id > 0) {
- ToolsFavoritesAttributes fav;
- if (gda_tools_favorites_get (browser_connection_get_favorites (diagram->priv->bcnc),
+ TFavoritesAttributes fav;
+ if (t_favorites_get (t_connection_get_favorites (diagram->priv->tcnc),
diagram->priv->fav_id, &fav, NULL)) {
gtk_entry_set_text (GTK_ENTRY (wid), fav.name);
- gda_tools_favorites_reset_attributes (&fav);
+ t_favorites_reset_attributes (&fav);
}
}
@@ -304,18 +304,18 @@ save_clicked_cb (GtkWidget *button, RelationsDiagram *diagram)
* Returns: a new #GtkWidget
*/
GtkWidget *
-relations_diagram_new (BrowserConnection *bcnc)
+relations_diagram_new (TConnection *tcnc)
{
RelationsDiagram *diagram;
- g_return_val_if_fail (BROWSER_IS_CONNECTION (bcnc), NULL);
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
diagram = RELATIONS_DIAGRAM (g_object_new (RELATIONS_DIAGRAM_TYPE, NULL));
- diagram->priv->bcnc = g_object_ref (bcnc);
- g_signal_connect (diagram->priv->bcnc, "meta-changed",
+ diagram->priv->tcnc = g_object_ref (tcnc);
+ g_signal_connect (diagram->priv->tcnc, "meta-changed",
G_CALLBACK (meta_changed_cb), diagram);
- g_signal_connect (bcnc, "favorites-changed",
+ g_signal_connect (tcnc, "favorites-changed",
G_CALLBACK (favorites_changed_cb), diagram);
@@ -347,34 +347,34 @@ relations_diagram_new (BrowserConnection *bcnc)
gtk_widget_show_all (wid);
GdaMetaStruct *mstruct;
- mstruct = browser_connection_get_meta_struct (diagram->priv->bcnc);
+ mstruct = t_connection_get_meta_struct (diagram->priv->tcnc);
if (mstruct)
- meta_changed_cb (diagram->priv->bcnc, mstruct, diagram);
+ meta_changed_cb (diagram->priv->tcnc, mstruct, diagram);
return (GtkWidget*) diagram;
}
GtkWidget *
-relations_diagram_new_with_fav_id (BrowserConnection *bcnc, gint fav_id, GError **error)
+relations_diagram_new_with_fav_id (TConnection *tcnc, gint fav_id, GError **error)
{
RelationsDiagram *diagram = NULL;
- ToolsFavoritesAttributes fav;
+ TFavoritesAttributes fav;
xmlDocPtr doc = NULL;
- if (! gda_tools_favorites_get (browser_connection_get_favorites (bcnc),
+ if (! t_favorites_get (t_connection_get_favorites (tcnc),
fav_id, &fav, error))
return FALSE;
doc = xmlParseDoc (BAD_CAST fav.contents);
if (!doc) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (error, T_ERROR, T_INTERNAL_COMMAND_ERROR,
"%s", _("Error parsing favorite's contents"));
goto out;
}
/* create diagram */
- diagram = RELATIONS_DIAGRAM (relations_diagram_new (bcnc));
+ diagram = RELATIONS_DIAGRAM (relations_diagram_new (tcnc));
if (!diagram)
goto out;
gchar *str, *tmp;
@@ -427,7 +427,7 @@ relations_diagram_new_with_fav_id (BrowserConnection *bcnc, gint fav_id, GError
xmlFree (schema);
if (name)
xmlFree (name);
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_STORED_DATA_ERROR,
+ g_set_error (error, T_ERROR, T_STORED_DATA_ERROR,
"%s", _("Missing table attribute in favorite's contents"));
gtk_widget_destroy ((GtkWidget*) diagram);
diagram = NULL;
@@ -437,7 +437,7 @@ relations_diagram_new_with_fav_id (BrowserConnection *bcnc, gint fav_id, GError
}
out:
- gda_tools_favorites_reset_attributes (&fav);
+ t_favorites_reset_attributes (&fav);
if (doc)
xmlFreeDoc (doc);
return (GtkWidget*) diagram;
@@ -452,10 +452,10 @@ static void
relations_diagram_set_fav_id (RelationsDiagram *diagram, gint fav_id, GError **error)
{
g_return_if_fail (IS_RELATIONS_DIAGRAM (diagram));
- ToolsFavoritesAttributes fav;
+ TFavoritesAttributes fav;
if ((fav_id >=0) &&
- gda_tools_favorites_get (browser_connection_get_favorites (diagram->priv->bcnc),
+ t_favorites_get (t_connection_get_favorites (diagram->priv->tcnc),
fav_id, &fav, error)) {
gchar *str, *tmp;
tmp = g_markup_printf_escaped (_("'%s' diagram"), fav.name);
@@ -466,7 +466,7 @@ relations_diagram_set_fav_id (RelationsDiagram *diagram, gint fav_id, GError **e
diagram->priv->fav_id = fav.id;
- gda_tools_favorites_reset_attributes (&fav);
+ t_favorites_reset_attributes (&fav);
}
else {
gchar *str;
@@ -555,17 +555,17 @@ relations_diagram_page_get_tab_label (BrowserPage *page, GtkWidget **out_close_b
diagram = RELATIONS_DIAGRAM (page);
if (diagram->priv->fav_id > 0) {
- ToolsFavoritesAttributes fav;
- if (gda_tools_favorites_get (browser_connection_get_favorites (diagram->priv->bcnc),
+ TFavoritesAttributes fav;
+ if (t_favorites_get (t_connection_get_favorites (diagram->priv->tcnc),
diagram->priv->fav_id, &fav, NULL)) {
tab_name = g_strdup (fav.name);
- gda_tools_favorites_reset_attributes (&fav);
+ t_favorites_reset_attributes (&fav);
}
}
if (!tab_name)
tab_name = g_strdup (_("Diagram"));
- table_pixbuf = browser_get_pixbuf_icon (BROWSER_ICON_DIAGRAM);
+ table_pixbuf = ui_get_pixbuf_icon (UI_ICON_DIAGRAM);
wid = browser_make_tab_label_with_pixbuf (tab_name,
table_pixbuf,
out_close_button ? TRUE : FALSE, out_close_button);
diff --git a/tools/browser/schema-browser/relations-diagram.h
b/tools/browser/schema-browser/relations-diagram.h
index d42f156..baa025d 100644
--- a/tools/browser/schema-browser/relations-diagram.h
+++ b/tools/browser/schema-browser/relations-diagram.h
@@ -21,7 +21,7 @@
#define __RELATIONS_DIAGRAM_H__
#include <gtk/gtk.h>
-#include "../browser-connection.h"
+#include "common/t-connection.h"
G_BEGIN_DECLS
@@ -45,8 +45,8 @@ struct _RelationsDiagramClass {
};
GType relations_diagram_get_type (void) G_GNUC_CONST;
-GtkWidget *relations_diagram_new (BrowserConnection *bcnc);
-GtkWidget *relations_diagram_new_with_fav_id (BrowserConnection *bcnc, gint fav_id, GError
**error);
+GtkWidget *relations_diagram_new (TConnection *tcnc);
+GtkWidget *relations_diagram_new_with_fav_id (TConnection *tcnc, gint fav_id, GError **error);
gint relations_diagram_get_fav_id (RelationsDiagram *diagram);
G_END_DECLS
diff --git a/tools/browser/schema-browser/schema-browser-perspective.c
b/tools/browser/schema-browser/schema-browser-perspective.c
index 0677413..8363faa 100644
--- a/tools/browser/schema-browser/schema-browser-perspective.c
+++ b/tools/browser/schema-browser/schema-browser-perspective.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 - 2012 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2009 - 2014 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2010 David King <davidk openismus com>
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
*
@@ -25,13 +25,15 @@
#include "objects-index.h"
#include "../browser-window.h"
#include "table-info.h"
-#include "../support.h"
+#include "../ui-support.h"
#include "../browser-page.h"
#ifdef HAVE_GOOCANVAS
#include "relations-diagram.h"
#endif
#include <libgda/gda-debug-macros.h>
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+
/*
* Main static functions
*/
@@ -124,9 +126,9 @@ schema_browser_perspective_init (SchemaBrowserPerspective *perspective)
gtk_orientable_set_orientation (GTK_ORIENTABLE (perspective), GTK_ORIENTATION_VERTICAL);
}
-static void fav_selection_changed_cb (GtkWidget *widget, gint fav_id, ToolsFavoritesType fav_type,
+static void fav_selection_changed_cb (GtkWidget *widget, gint fav_id, TFavoritesType fav_type,
const gchar *selection, SchemaBrowserPerspective *bpers);
-static void objects_index_selection_changed_cb (GtkWidget *widget, ToolsFavoritesType fav_type,
+static void objects_index_selection_changed_cb (GtkWidget *widget, TFavoritesType fav_type,
const gchar *selection, SchemaBrowserPerspective *bpers);
/**
* schema_browser_perspective_new
@@ -136,22 +138,22 @@ static void objects_index_selection_changed_cb (GtkWidget *widget, ToolsFavorite
BrowserPerspective *
schema_browser_perspective_new (BrowserWindow *bwin)
{
- BrowserConnection *bcnc;
+ TConnection *tcnc;
BrowserPerspective *bpers;
SchemaBrowserPerspective *perspective;
gboolean fav_supported;
bpers = (BrowserPerspective*) g_object_new (TYPE_SCHEMA_BROWSER_PERSPECTIVE, NULL);
perspective = (SchemaBrowserPerspective*) bpers;
- bcnc = browser_window_get_connection (bwin);
- fav_supported = browser_connection_get_favorites (bcnc) ? TRUE : FALSE;
+ tcnc = browser_window_get_connection (bwin);
+ fav_supported = t_connection_get_favorites (tcnc) ? TRUE : FALSE;
perspective->priv->bwin = bwin;
/* contents */
GtkWidget *paned, *wid, *nb;
paned = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
if (fav_supported) {
- wid = favorite_selector_new (bcnc);
+ wid = favorite_selector_new (tcnc);
g_signal_connect (wid, "selection-changed",
G_CALLBACK (fav_selection_changed_cb), bpers);
gtk_paned_add1 (GTK_PANED (paned), wid);
@@ -165,18 +167,16 @@ schema_browser_perspective_new (BrowserWindow *bwin)
gtk_notebook_set_scrollable (GTK_NOTEBOOK (nb), TRUE);
gtk_notebook_popup_enable (GTK_NOTEBOOK (nb));
- wid = objects_index_new (bcnc);
+ wid = objects_index_new (tcnc);
g_signal_connect (wid, "selection-changed",
G_CALLBACK (objects_index_selection_changed_cb), bpers);
gtk_notebook_append_page (GTK_NOTEBOOK (nb), wid,
- browser_make_tab_label_with_stock (_("Index"), GTK_STOCK_ABOUT, FALSE,
- NULL));
+ ui_make_tab_label_with_icon (_("Index"), "help-about", FALSE, NULL));
gtk_notebook_set_tab_reorderable (GTK_NOTEBOOK (nb), wid, TRUE);
gtk_notebook_set_group_name (GTK_NOTEBOOK (nb), "schema-browser");
gtk_notebook_set_menu_label (GTK_NOTEBOOK (nb), wid,
- browser_make_tab_label_with_stock (_("Index"), GTK_STOCK_ABOUT, FALSE,
- NULL));
+ ui_make_tab_label_with_icon (_("Index"), "help-about", FALSE, NULL));
gtk_box_pack_start (GTK_BOX (bpers), paned, TRUE, TRUE, 0);
gtk_widget_show_all (paned);
@@ -195,7 +195,7 @@ close_button_clicked_cb (G_GNUC_UNUSED GtkWidget *wid, GtkWidget *page_widget)
}
static void
-objects_index_selection_changed_cb (GtkWidget *widget, ToolsFavoritesType fav_type,
+objects_index_selection_changed_cb (GtkWidget *widget, TFavoritesType fav_type,
const gchar *selection, SchemaBrowserPerspective *bpers)
{
fav_selection_changed_cb (widget, -1, fav_type, selection, bpers);
@@ -203,10 +203,10 @@ objects_index_selection_changed_cb (GtkWidget *widget, ToolsFavoritesType fav_ty
static void
-fav_selection_changed_cb (G_GNUC_UNUSED GtkWidget *widget, gint fav_id, ToolsFavoritesType fav_type,
+fav_selection_changed_cb (G_GNUC_UNUSED GtkWidget *widget, gint fav_id, TFavoritesType fav_type,
const gchar *selection, SchemaBrowserPerspective *bpers)
{
- if (fav_type == GDA_TOOLS_FAVORITES_TABLES) {
+ if (fav_type == T_FAVORITES_TABLES) {
GdaQuarkList *ql;
const gchar *type;
const gchar *schema = NULL, *table = NULL, *short_name = NULL;
@@ -250,7 +250,7 @@ fav_selection_changed_cb (G_GNUC_UNUSED GtkWidget *widget, gint fav_id, ToolsFav
if (ql)
gda_quark_list_free (ql);
}
- else if (fav_type == GDA_TOOLS_FAVORITES_DIAGRAMS) {
+ else if (fav_type == T_FAVORITES_DIAGRAMS) {
#ifdef HAVE_GOOCANVAS
schema_browser_perspective_display_diagram (bpers, fav_id);
#else
@@ -306,7 +306,7 @@ favorites_toggle_cb (GtkToggleAction *action, BrowserPerspective *bpers)
static const GtkToggleActionEntry ui_toggle_actions [] =
{
- { "SchemaToolsFavoritesShow", NULL, N_("_Show Favorites"), "F9", N_("Show or hide favorites"),
G_CALLBACK (favorites_toggle_cb), FALSE }
+ { "SchemaTFavoritesShow", NULL, N_("_Show Favorites"), "F9", N_("Show or hide favorites"),
G_CALLBACK (favorites_toggle_cb), FALSE }
};
static GtkActionEntry ui_actions[] = {
@@ -321,7 +321,7 @@ static const gchar *ui_actions_info =
"<ui>"
" <menubar name='MenuBar'>"
" <menu name='Display' action='Display'>"
- " <menuitem name='SchemaToolsFavoritesShow' action='SchemaToolsFavoritesShow'/>"
+ " <menuitem name='SchemaTFavoritesShow' action='SchemaTFavoritesShow'/>"
" </menu>"
#ifdef HAVE_GOOCANVAS
" <placeholder name='MenuExtension'>"
@@ -348,7 +348,7 @@ schema_browser_perspective_get_actions_group (BrowserPerspective *perspective)
G_N_ELEMENTS (ui_toggle_actions),
bpers);
GtkAction *action;
- action = gtk_action_group_get_action (agroup, "SchemaToolsFavoritesShow");
+ action = gtk_action_group_get_action (agroup, "SchemaTFavoritesShow");
if (bpers->priv->favorites)
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
bpers->priv->favorites_shown);
@@ -414,7 +414,7 @@ schema_browser_perspective_display_diagram (SchemaBrowserPerspective *bpers, gin
diagram = relations_diagram_new_with_fav_id (browser_window_get_connection
(bpers->priv->bwin),
fav_id, &error);
if (! diagram) {
- browser_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) bpers),
+ ui_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) bpers),
error && error->message ? error->message :
_("Could not load diagram"));
g_clear_error (&error);
diff --git a/tools/browser/schema-browser/table-columns.c b/tools/browser/schema-browser/table-columns.c
index d778223..3e35b22 100644
--- a/tools/browser/schema-browser/table-columns.c
+++ b/tools/browser/schema-browser/table-columns.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2009 - 2014 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2010 David King <davidk openismus com>
* Copyright (C) 2011 Daniel Espinosa <esodan gmail com>
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
@@ -27,20 +27,20 @@
#include "table-info.h"
#include "table-columns.h"
#include <libgda-ui/gdaui-tree-store.h>
-#include "../tool-utils.h"
-#include "../support.h"
+#include <t-utils.h>
+#include "../ui-support.h"
#include "../gdaui-bar.h"
#include "mgr-columns.h"
#include "schema-browser-perspective.h"
#include "../browser-window.h"
-#include "../common/fk-declare.h"
+#include "../fk-declare.h"
#ifdef HAVE_LDAP
#include "../ldap-browser/ldap-browser-perspective.h"
#endif
#include <libgda/gda-debug-macros.h>
struct _TableColumnsPrivate {
- BrowserConnection *bcnc;
+ TConnection *tcnc;
TableInfo *tinfo;
GdaTree *columns_tree;
guint idle_update_columns;
@@ -60,7 +60,7 @@ static void table_columns_init (TableColumns *tcolumns, TableColumnsClass
static void table_columns_dispose (GObject *object);
static void table_columns_show_all (GtkWidget *widget);
-static void meta_changed_cb (BrowserConnection *bcnc, GdaMetaStruct *mstruct, TableColumns *tcolumns);
+static void meta_changed_cb (TConnection *tcnc, GdaMetaStruct *mstruct, TableColumns *tcolumns);
static GObjectClass *parent_class = NULL;
@@ -102,10 +102,10 @@ table_columns_dispose (GObject *object)
g_source_remove (tcolumns->priv->idle_update_columns);
if (tcolumns->priv->columns_tree)
g_object_unref (tcolumns->priv->columns_tree);
- if (tcolumns->priv->bcnc) {
- g_signal_handlers_disconnect_by_func (tcolumns->priv->bcnc,
+ if (tcolumns->priv->tcnc) {
+ g_signal_handlers_disconnect_by_func (tcolumns->priv->tcnc,
G_CALLBACK (meta_changed_cb), tcolumns);
- g_object_unref (tcolumns->priv->bcnc);
+ g_object_unref (tcolumns->priv->tcnc);
}
g_free (tcolumns->priv);
tcolumns->priv = NULL;
@@ -120,7 +120,7 @@ table_columns_show_all (GtkWidget *widget)
TableColumns *tcolumns = (TableColumns *) widget;
GTK_WIDGET_CLASS (parent_class)->show_all (widget);
#ifdef HAVE_LDAP
- if (browser_connection_is_ldap (tcolumns->priv->bcnc)) {
+ if (t_connection_is_ldap (tcolumns->priv->tcnc)) {
if (! tcolumns->priv->ldap_props_shown) {
gtk_widget_hide (tcolumns->priv->ldap_header);
gtk_widget_hide (tcolumns->priv->ldap_text);
@@ -180,14 +180,14 @@ static gboolean visibility_notify_event (GtkWidget *text_view, GdkEventVisibilit
static GSList *build_reverse_depend_list (GdaMetaStruct *mstruct, GdaMetaTable *mtable);
static void
-meta_changed_cb (G_GNUC_UNUSED BrowserConnection *bcnc, GdaMetaStruct *mstruct, TableColumns *tcolumns)
+meta_changed_cb (G_GNUC_UNUSED TConnection *tcnc, GdaMetaStruct *mstruct, TableColumns *tcolumns)
{
GtkTextBuffer *tbuffer;
GtkTextIter start, end;
/* cleanups */
#ifdef HAVE_LDAP
- if (browser_connection_is_ldap (tcolumns->priv->bcnc)) {
+ if (t_connection_is_ldap (tcolumns->priv->tcnc)) {
tbuffer = tcolumns->priv->ldap_def;
gtk_text_buffer_get_start_iter (tbuffer, &start);
gtk_text_buffer_get_end_iter (tbuffer, &end);
@@ -319,7 +319,7 @@ meta_changed_cb (G_GNUC_UNUSED BrowserConnection *bcnc, GdaMetaStruct *mstruct,
fk->fk_names_array [i], -1);
gtk_text_buffer_insert (tbuffer, ¤t, " ", -1);
gtk_text_buffer_insert_pixbuf (tbuffer, ¤t,
- browser_get_pixbuf_icon
(BROWSER_ICON_REFERENCE));
+ ui_get_pixbuf_icon
(UI_ICON_REFERENCE));
gtk_text_buffer_insert (tbuffer, ¤t, " ", -1);
gtk_text_buffer_insert (tbuffer, ¤t,
@@ -357,7 +357,7 @@ meta_changed_cb (G_GNUC_UNUSED BrowserConnection *bcnc, GdaMetaStruct *mstruct,
gtk_text_buffer_insert (tbuffer, ¤t, _("Policy on UPDATE"), -1);
gtk_text_buffer_insert (tbuffer, ¤t, ": ", -1);
gtk_text_buffer_insert (tbuffer, ¤t,
- gda_tools_utils_fk_policy_to_string (policy),
+ t_utils_fk_policy_to_string (policy),
-1);
}
policy = GDA_META_TABLE_FOREIGN_KEY_ON_DELETE_POLICY (fk);
@@ -367,7 +367,7 @@ meta_changed_cb (G_GNUC_UNUSED BrowserConnection *bcnc, GdaMetaStruct *mstruct,
gtk_text_buffer_insert (tbuffer, ¤t, _("Policy on DELETE"), -1);
gtk_text_buffer_insert (tbuffer, ¤t, ": ", -1);
gtk_text_buffer_insert (tbuffer, ¤t,
- gda_tools_utils_fk_policy_to_string (policy),
+ t_utils_fk_policy_to_string (policy),
-1);
}
@@ -378,7 +378,7 @@ meta_changed_cb (G_GNUC_UNUSED BrowserConnection *bcnc, GdaMetaStruct *mstruct,
GdaDataModel *model;
GError *error = NULL;
g_value_set_string ((catalog_v = gda_value_new (G_TYPE_STRING)), dbo->obj_catalog);
- model = gda_meta_store_extract (browser_connection_get_meta_store
(tcolumns->priv->bcnc),
+ model = gda_meta_store_extract (t_connection_get_meta_store (tcolumns->priv->tcnc),
"SELECT tc.constraint_name, k.column_name FROM
_key_column_usage k INNER JOIN _table_constraints tc ON (k.table_catalog=tc.table_catalog AND
k.table_schema=tc.table_schema AND k.table_name=tc.table_name AND k.constraint_name=tc.constraint_name) WHERE
tc.constraint_type='UNIQUE' AND k.table_catalog = ##catalog::string AND k.table_schema = ##schema::string AND
k.table_name = ##tname::string ORDER by k.ordinal_position", &error,
"catalog", catalog_v,
"schema", schema_v,
@@ -458,12 +458,12 @@ meta_changed_cb (G_GNUC_UNUSED BrowserConnection *bcnc, GdaMetaStruct *mstruct,
}
#ifdef HAVE_LDAP
- if (browser_connection_is_ldap (tcolumns->priv->bcnc)) {
+ if (t_connection_is_ldap (tcolumns->priv->tcnc)) {
const gchar *base_dn, *filter, *attributes, *scope_str;
GdaLdapSearchScope scope;
tbuffer = tcolumns->priv->ldap_def;
gtk_text_buffer_get_start_iter (tbuffer, ¤t);
- if (browser_connection_describe_table (tcolumns->priv->bcnc, dbo->obj_name,
+ if (t_connection_describe_table (tcolumns->priv->tcnc, dbo->obj_name,
&base_dn, &filter,
&attributes, &scope, NULL)) {
gtk_text_buffer_insert_with_tags_by_name (tbuffer, ¤t,
@@ -584,8 +584,8 @@ table_columns_new (TableInfo *tinfo)
tcolumns = TABLE_COLUMNS (g_object_new (TABLE_COLUMNS_TYPE, NULL));
tcolumns->priv->tinfo = tinfo;
- tcolumns->priv->bcnc = g_object_ref (table_info_get_connection (tinfo));
- g_signal_connect (tcolumns->priv->bcnc, "meta-changed",
+ tcolumns->priv->tcnc = g_object_ref (table_info_get_connection (tinfo));
+ g_signal_connect (tcolumns->priv->tcnc, "meta-changed",
G_CALLBACK (meta_changed_cb), tcolumns);
/* main container */
@@ -598,7 +598,7 @@ table_columns_new (TableInfo *tinfo)
* Columns
*/
tcolumns->priv->columns_tree = gda_tree_new ();
- manager = mgr_columns_new (tcolumns->priv->bcnc, table_info_get_table_schema (tinfo),
+ manager = mgr_columns_new (tcolumns->priv->tcnc, table_info_get_table_schema (tinfo),
table_info_get_table_name (tinfo));
gda_tree_add_manager (tcolumns->priv->columns_tree, manager);
g_object_unref (manager);
@@ -622,7 +622,7 @@ table_columns_new (TableInfo *tinfo)
G_TYPE_STRING, MGR_COLUMNS_COL_DEFAULT_ATT_NAME,
G_TYPE_OBJECT, "icon",
G_TYPE_STRING, MGR_COLUMNS_COL_DETAILS);
- treeview = browser_make_tree_view (model);
+ treeview = ui_make_tree_view (model);
g_object_unref (model);
/* Colum: Name */
@@ -683,7 +683,7 @@ table_columns_new (TableInfo *tinfo)
gtk_paned_pack2 (GTK_PANED (paned), vbox, TRUE, TRUE);
#ifdef HAVE_LDAP
- if (browser_connection_is_ldap (tcolumns->priv->bcnc)) {
+ if (t_connection_is_ldap (tcolumns->priv->tcnc)) {
GtkWidget *label;
gchar *str;
@@ -778,9 +778,9 @@ table_columns_new (TableInfo *tinfo)
* initial update
*/
GdaMetaStruct *mstruct;
- mstruct = browser_connection_get_meta_struct (tcolumns->priv->bcnc);
+ mstruct = t_connection_get_meta_struct (tcolumns->priv->tcnc);
if (mstruct)
- meta_changed_cb (tcolumns->priv->bcnc, mstruct, tcolumns);
+ meta_changed_cb (tcolumns->priv->tcnc, mstruct, tcolumns);
return (GtkWidget*) tcolumns;
}
@@ -903,7 +903,7 @@ follow_if_link (G_GNUC_UNUSED GtkWidget *text_view, GtkTextIter *iter, TableColu
fk_name = g_object_get_data (G_OBJECT (tag), "fk_name");
dn = g_object_get_data (G_OBJECT (tag), "dn");
- bpers = SCHEMA_BROWSER_PERSPECTIVE (browser_find_parent_widget (GTK_WIDGET (tcolumns),
+ bpers = SCHEMA_BROWSER_PERSPECTIVE (ui_find_parent_widget (GTK_WIDGET (tcolumns),
TYPE_SCHEMA_BROWSER_PERSPECTIVE));
if (table_name && table_schema && table_short_name && bpers) {
schema_browser_perspective_display_table_info (bpers,
@@ -920,13 +920,13 @@ follow_if_link (G_GNUC_UNUSED GtkWidget *text_view, GtkTextIter *iter, TableColu
table_name = table_info_get_table_name (tcolumns->priv->tinfo);
g_value_set_string ((v1 = gda_value_new (G_TYPE_STRING)), table_schema);
g_value_set_string ((v2 = gda_value_new (G_TYPE_STRING)), table_name);
- mstruct = browser_connection_get_meta_struct (tcolumns->priv->bcnc);
+ mstruct = t_connection_get_meta_struct (tcolumns->priv->tcnc);
dbo = gda_meta_struct_get_db_object (mstruct, NULL, v1, v2);
gda_value_free (v1);
gda_value_free (v2);
parent = gtk_widget_get_toplevel (GTK_WIDGET (tcolumns));
if (!dbo || (dbo->obj_type != GDA_META_DB_TABLE)) {
- browser_show_error ((GtkWindow*) parent,
+ ui_show_error ((GtkWindow*) parent,
_("Could not find table '%s.%s'"),
table_schema, table_name);
}
@@ -948,7 +948,7 @@ follow_if_link (G_GNUC_UNUSED GtkWidget *text_view, GtkTextIter *iter, TableColu
if (! fk_declare_undeclare (mstruct,
BROWSER_IS_WINDOW (parent) ?
BROWSER_WINDOW (parent) : NULL,
fk, &error)) {
- browser_show_error ((GtkWindow *) parent, _("Failed to
undeclare foreign key: %s"),
+ ui_show_error ((GtkWindow *) parent, _("Failed to undeclare
foreign key: %s"),
error && error->message ? error->message
: _("No detail"));
g_clear_error (&error);
}
@@ -957,11 +957,11 @@ follow_if_link (G_GNUC_UNUSED GtkWidget *text_view, GtkTextIter *iter, TableColu
GTK_MESSAGE_INFO, "fkdeclare",
_("Successfully undeclared
foreign key"));
else
- browser_show_message ((GtkWindow *) parent, "%s",
+ ui_show_message ((GtkWindow *) parent, "%s",
_("Successfully undeclared foreign
key"));
}
else
- browser_show_error ((GtkWindow*) parent,
+ ui_show_error ((GtkWindow*) parent,
_("Could not find declared foreign key '%s'"),
fk_name);
}
diff --git a/tools/browser/schema-browser/table-info.c b/tools/browser/schema-browser/table-info.c
index 0bfd706..5da9382 100644
--- a/tools/browser/schema-browser/table-info.c
+++ b/tools/browser/schema-browser/table-info.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 - 2012 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2009 - 2014 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2010 David King <davidk openismus com>
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
*
@@ -22,7 +22,7 @@
#include <string.h>
#include "table-info.h"
#include "../dnd.h"
-#include "../support.h"
+#include "../ui-support.h"
#include "../gdaui-bar.h"
#include "table-columns.h"
#include "table-preferences.h"
@@ -31,18 +31,19 @@
#endif
#include "schema-browser-perspective.h"
#include "../browser-page.h"
-#include "../browser-stock-icons.h"
#include "../browser-window.h"
#include "../data-manager/data-manager-perspective.h"
#include <libgda-ui/gdaui-enums.h>
#include <libgda-ui/gdaui-basic-form.h>
#include <libgda-ui/internal/popup-container.h>
#include <libgda/gda-data-model-extra.h>
-#include "../common/fk-declare.h"
+#include "../fk-declare.h"
#include <libgda/gda-debug-macros.h>
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+
struct _TableInfoPrivate {
- BrowserConnection *bcnc;
+ TConnection *tcnc;
gchar *schema;
gchar *table_name;
@@ -75,7 +76,7 @@ static GtkActionGroup *table_info_page_get_actions_group (BrowserPage *page
static const gchar *table_info_page_get_actions_ui (BrowserPage *page);
static GtkWidget *table_info_page_get_tab_label (BrowserPage *page, GtkWidget **out_close_button);
-static void meta_changed_cb (BrowserConnection *bcnc, GdaMetaStruct *mstruct, TableInfo *tinfo);
+static void meta_changed_cb (TConnection *tcnc, GdaMetaStruct *mstruct, TableInfo *tinfo);
/* properties */
enum {
@@ -133,10 +134,10 @@ table_info_dispose (GObject *object)
g_free (tinfo->priv->schema);
g_free (tinfo->priv->table_name);
g_free (tinfo->priv->table_short_name);
- if (tinfo->priv->bcnc) {
- g_signal_handlers_disconnect_by_func (tinfo->priv->bcnc,
+ if (tinfo->priv->tcnc) {
+ g_signal_handlers_disconnect_by_func (tinfo->priv->tcnc,
G_CALLBACK (meta_changed_cb), tinfo);
- g_object_unref (tinfo->priv->bcnc);
+ g_object_unref (tinfo->priv->tcnc);
}
g_free (tinfo->priv);
@@ -260,7 +261,7 @@ source_drag_data_get_cb (G_GNUC_UNUSED GtkWidget *widget, G_GNUC_UNUSED GdkDragC
}
static void
-meta_changed_cb (G_GNUC_UNUSED BrowserConnection *bcnc, GdaMetaStruct *mstruct, TableInfo *tinfo)
+meta_changed_cb (G_GNUC_UNUSED TConnection *tcnc, GdaMetaStruct *mstruct, TableInfo *tinfo)
{
GdaMetaDbObject *dbo;
GValue *schema_v = NULL, *name_v;
@@ -294,7 +295,7 @@ meta_changed_cb (G_GNUC_UNUSED BrowserConnection *bcnc, GdaMetaStruct *mstruct,
gtk_drag_source_set ((GtkWidget *) tinfo->priv->header, GDK_BUTTON1_MASK | GDK_BUTTON3_MASK,
dbo_table, G_N_ELEMENTS (dbo_table), GDK_ACTION_COPY);
gtk_drag_source_set_icon_pixbuf ((GtkWidget *) tinfo->priv->header,
- browser_get_pixbuf_icon (BROWSER_ICON_TABLE));
+ ui_get_pixbuf_icon (UI_ICON_TABLE));
g_signal_connect (tinfo->priv->header, "drag-data-get",
G_CALLBACK (source_drag_data_get_cb), tinfo);
}
@@ -308,19 +309,19 @@ meta_changed_cb (G_GNUC_UNUSED BrowserConnection *bcnc, GdaMetaStruct *mstruct,
* Returns: a new #GtkWidget
*/
GtkWidget *
-table_info_new (BrowserConnection *bcnc,
+table_info_new (TConnection *tcnc,
const gchar *schema, const gchar *table)
{
TableInfo *tinfo;
- g_return_val_if_fail (BROWSER_IS_CONNECTION (bcnc), NULL);
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
g_return_val_if_fail (schema, NULL);
g_return_val_if_fail (table, NULL);
tinfo = TABLE_INFO (g_object_new (TABLE_INFO_TYPE, NULL));
- tinfo->priv->bcnc = g_object_ref (bcnc);
- g_signal_connect (tinfo->priv->bcnc, "meta-changed",
+ tinfo->priv->tcnc = g_object_ref (tcnc);
+ g_signal_connect (tinfo->priv->tcnc, "meta-changed",
G_CALLBACK (meta_changed_cb), tinfo);
tinfo->priv->schema = g_strdup (schema);
tinfo->priv->table_name = g_strdup (table);
@@ -353,7 +354,7 @@ table_info_new (BrowserConnection *bcnc,
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_box_pack_start (GTK_BOX (hbox), gtk_label_new (""), TRUE, TRUE, 0);
- image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_DIALOG);
+ image = gtk_image_new_from_icon_name ("dialog-warning", GTK_ICON_SIZE_DIALOG);
gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 10);
label = gtk_label_new (_("Table not found. If you think this is an error,\n"
"please refresh the meta data from the database\n"
@@ -409,9 +410,9 @@ table_info_new (BrowserConnection *bcnc,
display_table_not_found_error (tinfo, TRUE);
GdaMetaStruct *mstruct;
- mstruct = browser_connection_get_meta_struct (tinfo->priv->bcnc);
+ mstruct = t_connection_get_meta_struct (tinfo->priv->tcnc);
if (mstruct)
- meta_changed_cb (tinfo->priv->bcnc, mstruct, tinfo);
+ meta_changed_cb (tinfo->priv->tcnc, mstruct, tinfo);
return (GtkWidget*) tinfo;
}
@@ -439,11 +440,11 @@ table_info_get_table_name (TableInfo *tinfo)
/**
* table_info_get_connection
*/
-BrowserConnection *
+TConnection *
table_info_get_connection (TableInfo *tinfo)
{
g_return_val_if_fail (IS_TABLE_INFO (tinfo), NULL);
- return tinfo->priv->bcnc;
+ return tinfo->priv->tcnc;
}
/*
@@ -452,20 +453,20 @@ table_info_get_connection (TableInfo *tinfo)
static void
action_add_to_fav_cb (G_GNUC_UNUSED GtkAction *action, TableInfo *tinfo)
{
- ToolsFavorites *bfav;
- ToolsFavoritesAttributes fav;
+ TFavorites *bfav;
+ TFavoritesAttributes fav;
GError *error = NULL;
- memset (&fav, 0, sizeof (ToolsFavoritesAttributes));
+ memset (&fav, 0, sizeof (TFavoritesAttributes));
fav.id = -1;
- fav.type = GDA_TOOLS_FAVORITES_TABLES;
+ fav.type = T_FAVORITES_TABLES;
fav.name = NULL;
fav.descr = NULL;
fav.contents = table_info_to_selection (tinfo);
- bfav = browser_connection_get_favorites (tinfo->priv->bcnc);
- if (! gda_tools_favorites_add (bfav, 0, &fav, ORDER_KEY_SCHEMA, G_MAXINT, &error)) {
- browser_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) tinfo),
+ bfav = t_connection_get_favorites (tinfo->priv->tcnc);
+ if (! t_favorites_add (bfav, 0, &fav, ORDER_KEY_SCHEMA, G_MAXINT, &error)) {
+ ui_show_error ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) tinfo),
_("Could not add favorite: %s"),
error && error->message ? error->message : _("No detail"));
if (error)
@@ -522,7 +523,7 @@ insert_response_cb (GtkWidget *dialog, gint response_id, TableInfo *tinfo)
params = g_object_get_data (G_OBJECT (dialog), "params");
GObject *result;
- result = browser_connection_execute_statement (tinfo->priv->bcnc,
+ result = t_connection_execute_statement (tinfo->priv->tcnc,
stmt, params,
GDA_STATEMENT_MODEL_RANDOM_ACCESS, NULL,
&lerror);
if (result) {
@@ -533,7 +534,7 @@ insert_response_cb (GtkWidget *dialog, gint response_id, TableInfo *tinfo)
g_object_unref (result);
}
else {
- browser_show_error (GTK_WINDOW (gtk_widget_get_toplevel ((GtkWidget*) tinfo)),
+ ui_show_error (GTK_WINDOW (gtk_widget_get_toplevel ((GtkWidget*) tinfo)),
_("Error executing query: %s"),
lerror && lerror->message ? lerror->message : _("No detail"));
g_clear_error (&lerror);
@@ -542,7 +543,7 @@ insert_response_cb (GtkWidget *dialog, gint response_id, TableInfo *tinfo)
}
#ifdef HAVE_GDU
else if (response_id == GTK_RESPONSE_HELP) {
- browser_show_help ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) tinfo),
+ ui_show_help ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) tinfo),
"table-insert-data");
}
#endif
@@ -645,7 +646,7 @@ action_insert_cb (G_GNUC_UNUSED GtkAction *action, TableInfo *tinfo)
if (fkdata->model && !fkdata->model_rerunning) {
GObject *result;
fkdata->model_rerunning = TRUE;
- result = browser_connection_execute_statement (tinfo->priv->bcnc,
+ result = t_connection_execute_statement (tinfo->priv->tcnc,
fkdata->stmt, NULL,
GDA_STATEMENT_MODEL_RANDOM_ACCESS, NULL,
NULL);
@@ -658,9 +659,9 @@ action_insert_cb (G_GNUC_UNUSED GtkAction *action, TableInfo *tinfo)
BrowserWindow *bwin;
GdaMetaStruct *mstruct;
bwin = (BrowserWindow*) gtk_widget_get_toplevel ((GtkWidget*) tinfo);
- mstruct = browser_connection_get_meta_struct (tinfo->priv->bcnc);
+ mstruct = t_connection_get_meta_struct (tinfo->priv->tcnc);
if (!mstruct) {
- browser_show_error (GTK_WINDOW (bwin), _("Meta data not yet available"));
+ ui_show_error (GTK_WINDOW (bwin), _("Meta data not yet available"));
return;
}
@@ -677,7 +678,7 @@ action_insert_cb (G_GNUC_UNUSED GtkAction *action, TableInfo *tinfo)
gda_value_free (v2);
if (! dbo) {
- browser_show_error (GTK_WINDOW (bwin), _("Can't find information about table"));
+ ui_show_error (GTK_WINDOW (bwin), _("Can't find information about table"));
return;
}
@@ -712,7 +713,7 @@ action_insert_cb (G_GNUC_UNUSED GtkAction *action, TableInfo *tinfo)
gchar *sql;
sql = gda_statement_to_sql (stmt, NULL, NULL);
- browser_show_error (GTK_WINDOW (bwin),
+ ui_show_error (GTK_WINDOW (bwin),
_("Internal error while building INSERT statement:\n%s"), sql);
g_free (sql);
g_object_unref (stmt);
@@ -729,9 +730,9 @@ action_insert_cb (G_GNUC_UNUSED GtkAction *action, TableInfo *tinfo)
const GValue *autoinc;
GdaHolder *holder;
- plugin = browser_connection_get_table_column_attribute (tinfo->priv->bcnc,
+ plugin = t_connection_get_table_column_attribute (tinfo->priv->tcnc,
mtable, col,
- BROWSER_CONNECTION_COLUMN_PLUGIN,
+ T_CONNECTION_COLUMN_PLUGIN,
NULL);
holder = gda_set_get_holder (params, col->column_name);
if (!holder)
@@ -792,7 +793,7 @@ action_insert_cb (G_GNUC_UNUSED GtkAction *action, TableInfo *tinfo)
g_value_set_string ((name_v = gda_value_new (G_TYPE_STRING)), rdbo->obj_name);
dbo = gda_meta_struct_get_db_object (mstruct, NULL, schema_v, name_v);
- cmodel = gda_meta_store_extract (browser_connection_get_meta_store (tinfo->priv->bcnc),
+ cmodel = gda_meta_store_extract (t_connection_get_meta_store (tinfo->priv->tcnc),
"SELECT tc.constraint_name, k.column_name FROM
_key_column_usage k INNER JOIN _table_constraints tc ON (k.table_catalog=tc.table_catalog AND
k.table_schema=tc.table_schema AND k.table_name=tc.table_name AND k.constraint_name=tc.constraint_name) WHERE
tc.constraint_type='UNIQUE' AND k.table_catalog = ##catalog::string AND k.table_schema = ##schema::string AND
k.table_name = ##tname::string ORDER by k.ordinal_position", &lerror,
"catalog", catalog_v,
"schema", schema_v,
@@ -862,7 +863,7 @@ action_insert_cb (G_GNUC_UNUSED GtkAction *action, TableInfo *tinfo)
fkdata->stmt = stmt;
GObject *result;
- result = browser_connection_execute_statement (tinfo->priv->bcnc, stmt, NULL,
+ result = t_connection_execute_statement (tinfo->priv->tcnc, stmt, NULL,
GDA_STATEMENT_MODEL_RANDOM_ACCESS,
NULL, NULL);
fkdata->insert_params = g_object_ref (params);
@@ -934,14 +935,14 @@ action_declarefk_cb (G_GNUC_UNUSED GtkAction *action, TableInfo *tinfo)
GValue *v1, *v2;
parent = (GtkWidget*) gtk_widget_get_toplevel ((GtkWidget*) tinfo);
- mstruct = browser_connection_get_meta_struct (tinfo->priv->bcnc);
+ mstruct = t_connection_get_meta_struct (tinfo->priv->tcnc);
g_value_set_string ((v1 = gda_value_new (G_TYPE_STRING)), tinfo->priv->schema);
g_value_set_string ((v2 = gda_value_new (G_TYPE_STRING)), tinfo->priv->table_name);
dbo = gda_meta_struct_get_db_object (mstruct, NULL, v1, v2);
gda_value_free (v1);
gda_value_free (v2);
if (!dbo || (dbo->obj_type != GDA_META_DB_TABLE)) {
- browser_show_error ((GtkWindow *) parent, _("Can't find information about table '%s'"),
+ ui_show_error ((GtkWindow *) parent, _("Can't find information about table '%s'"),
tinfo->priv->table_short_name);
return;
}
@@ -953,7 +954,7 @@ action_declarefk_cb (G_GNUC_UNUSED GtkAction *action, TableInfo *tinfo)
if (! fk_declare_write (FK_DECLARE (dlg),
BROWSER_IS_WINDOW (parent) ? BROWSER_WINDOW (parent) : NULL,
&error)) {
- browser_show_error ((GtkWindow *) parent, _("Failed to declare foreign key: %s"),
+ ui_show_error ((GtkWindow *) parent, _("Failed to declare foreign key: %s"),
error && error->message ? error->message : _("No detail"));
g_clear_error (&error);
}
@@ -962,7 +963,7 @@ action_declarefk_cb (G_GNUC_UNUSED GtkAction *action, TableInfo *tinfo)
GTK_MESSAGE_INFO, "fkdeclare",
_("Successfully declared foreign key"));
else
- browser_show_message ((GtkWindow *) parent, "%s",
+ ui_show_message ((GtkWindow *) parent, "%s",
_("Successfully declared foreign key"));
}
@@ -971,7 +972,7 @@ action_declarefk_cb (G_GNUC_UNUSED GtkAction *action, TableInfo *tinfo)
static GtkActionEntry ui_actions[] = {
{ "Table", NULL, N_("_Table"), NULL, N_("Table"), NULL },
- { "AddToFav", STOCK_ADD_BOOKMARK, N_("Add to _Favorites"), NULL, N_("Add table to favorites"),
+ { "AddToFav", NULL, N_("Add to _Favorites"), NULL, N_("Add table to favorites"),
G_CALLBACK (action_add_to_fav_cb)},
{ "ViewContents", GTK_STOCK_EDIT, N_("_Contents"), NULL, N_("View table's contents"),
G_CALLBACK (action_view_contents_cb)},
@@ -1026,9 +1027,9 @@ table_info_page_get_tab_label (BrowserPage *page, GtkWidget **out_close_button)
GdkPixbuf *table_pixbuf;
tinfo = TABLE_INFO (page);
- table_pixbuf = browser_get_pixbuf_icon (BROWSER_ICON_TABLE);
+ table_pixbuf = ui_get_pixbuf_icon (UI_ICON_TABLE);
tab_name = tinfo->priv->table_short_name ? tinfo->priv->table_short_name : tinfo->priv->table_name;
- return browser_make_tab_label_with_pixbuf (tab_name,
- table_pixbuf,
- out_close_button ? TRUE : FALSE, out_close_button);
+ return ui_make_tab_label_with_pixbuf (tab_name,
+ table_pixbuf,
+ out_close_button ? TRUE : FALSE, out_close_button);
}
diff --git a/tools/browser/schema-browser/table-info.h b/tools/browser/schema-browser/table-info.h
index c64b86b..e17cfc2 100644
--- a/tools/browser/schema-browser/table-info.h
+++ b/tools/browser/schema-browser/table-info.h
@@ -21,7 +21,7 @@
#define __TABLE_INFO_H__
#include <gtk/gtk.h>
-#include "../browser-connection.h"
+#include "common/t-connection.h"
G_BEGIN_DECLS
@@ -46,11 +46,11 @@ struct _TableInfoClass {
GType table_info_get_type (void) G_GNUC_CONST;
-GtkWidget *table_info_new (BrowserConnection *bcnc,
+GtkWidget *table_info_new (TConnection *tcnc,
const gchar *schema, const gchar *table);
const gchar *table_info_get_table_schema (TableInfo *table_info);
const gchar *table_info_get_table_name (TableInfo *table_info);
-BrowserConnection *table_info_get_connection (TableInfo *table_info);
+TConnection *table_info_get_connection (TableInfo *table_info);
G_END_DECLS
diff --git a/tools/browser/schema-browser/table-preferences.c
b/tools/browser/schema-browser/table-preferences.c
index 4d1f7fe..7721ca8 100644
--- a/tools/browser/schema-browser/table-preferences.c
+++ b/tools/browser/schema-browser/table-preferences.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2010 David King <davidk openismus com>
- * Copyright (C) 2010 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2010 - 2014 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
*
* This program is free software; you can redistribute it and/or
@@ -26,7 +26,7 @@
#include "table-info.h"
#include "table-preferences.h"
#include <libgda-ui/gdaui-tree-store.h>
-#include "../support.h"
+#include "../ui-support.h"
#include "../gdaui-bar.h"
#include "schema-browser-perspective.h"
#include "../query-exec/query-editor.h"
@@ -36,7 +36,7 @@
#include <libgda/gda-debug-macros.h>
struct _TablePreferencesPrivate {
- BrowserConnection *bcnc;
+ TConnection *tcnc;
TableInfo *tinfo;
GtkListStore *columns_store;
GtkTreeView *columns_treeview;
@@ -63,7 +63,7 @@ static void table_preferences_dispose (GObject *object);
static GtkWidget *create_column_properties (TablePreferences *tpref);
static void update_column_properties (TablePreferences *tpref);
-static void meta_changed_cb (BrowserConnection *bcnc, GdaMetaStruct *mstruct, TablePreferences
*tpreferences);
+static void meta_changed_cb (TConnection *tcnc, GdaMetaStruct *mstruct, TablePreferences *tpreferences);
static void plugins_combo_changed_cb (GtkComboBox *combo, TablePreferences *tpref);
static GObjectClass *parent_class = NULL;
@@ -105,10 +105,10 @@ table_preferences_dispose (GObject *object)
/* free memory */
if (tpref->priv) {
- if (tpref->priv->bcnc) {
- g_signal_handlers_disconnect_by_func (tpref->priv->bcnc,
+ if (tpref->priv->tcnc) {
+ g_signal_handlers_disconnect_by_func (tpref->priv->tcnc,
G_CALLBACK (meta_changed_cb), tpref);
- g_object_unref (tpref->priv->bcnc);
+ g_object_unref (tpref->priv->tcnc);
}
if (tpref->priv->columns_store)
@@ -156,7 +156,7 @@ enum
};
static void
-meta_changed_cb (G_GNUC_UNUSED BrowserConnection *bcnc, GdaMetaStruct *mstruct, TablePreferences *tpref)
+meta_changed_cb (G_GNUC_UNUSED TConnection *tcnc, GdaMetaStruct *mstruct, TablePreferences *tpref)
{
gtk_list_store_clear (tpref->priv->columns_store);
@@ -190,10 +190,10 @@ meta_changed_cb (G_GNUC_UNUSED BrowserConnection *bcnc, GdaMetaStruct *mstruct,
GtkTreeIter iter;
gchar *eprops;
GError *error = NULL;
- eprops = browser_connection_get_table_column_attribute (tpref->priv->bcnc,
+ eprops = t_connection_get_table_column_attribute (tpref->priv->tcnc,
tpref->priv->current_table,
column,
-
BROWSER_CONNECTION_COLUMN_PLUGIN,
+ T_CONNECTION_COLUMN_PLUGIN,
&error);
if (error) {
TO_IMPLEMENT; /* FIXME: add a notice somewhere in the UI */
@@ -213,7 +213,7 @@ meta_changed_cb (G_GNUC_UNUSED BrowserConnection *bcnc, GdaMetaStruct *mstruct,
}
static void
-table_column_pref_changed_cb (G_GNUC_UNUSED BrowserConnection *bcnc, G_GNUC_UNUSED GdaMetaTable *table,
+table_column_pref_changed_cb (G_GNUC_UNUSED TConnection *tcnc, G_GNUC_UNUSED GdaMetaTable *table,
GdaMetaTableColumn *column,
const gchar *attr_name, const gchar *value, TablePreferences *tpref)
{
@@ -222,7 +222,7 @@ table_column_pref_changed_cb (G_GNUC_UNUSED BrowserConnection *bcnc, G_GNUC_UNUS
gboolean valid;
GtkTreeModel *model;
- if (strcmp (attr_name, BROWSER_CONNECTION_COLUMN_PLUGIN))
+ if (strcmp (attr_name, T_CONNECTION_COLUMN_PLUGIN))
return;
model = GTK_TREE_MODEL (tpref->priv->columns_store);
@@ -313,22 +313,15 @@ table_preferences_new (TableInfo *tinfo)
tpref = TABLE_PREFERENCES (g_object_new (TABLE_PREFERENCES_TYPE, NULL));
tpref->priv->tinfo = tinfo;
- tpref->priv->bcnc = g_object_ref (table_info_get_connection (tinfo));
- g_signal_connect (tpref->priv->bcnc, "meta-changed",
+ tpref->priv->tcnc = g_object_ref (table_info_get_connection (tinfo));
+ g_signal_connect (tpref->priv->tcnc, "meta-changed",
G_CALLBACK (meta_changed_cb), tpref);
- g_signal_connect (tpref->priv->bcnc, "table-column-pref-changed",
+ g_signal_connect (tpref->priv->tcnc, "table-column-pref-changed",
G_CALLBACK (table_column_pref_changed_cb), tpref);
-
- /* top vbox */
- GtkWidget *top_vbox;
- top_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
- gtk_box_pack_start (GTK_BOX (tpref), top_vbox, TRUE, TRUE, 0);
- /* Field's display properties */
GtkWidget *grid;
-
grid = gtk_grid_new ();
- gtk_box_pack_start (GTK_BOX (top_vbox), grid, TRUE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (tpref), grid, TRUE, TRUE, 0);
gtk_grid_set_row_spacing (GTK_GRID (grid), 6);
gtk_grid_set_column_spacing (GTK_GRID (grid), 6);
gtk_container_set_border_width (GTK_CONTAINER (grid), 6);
@@ -355,7 +348,7 @@ table_preferences_new (TableInfo *tinfo)
tpref->priv->columns_store = gtk_list_store_new (NUM_COLUMNS,
G_TYPE_POINTER, G_TYPE_GTYPE,
G_TYPE_STRING);
- treeview = browser_make_tree_view (GTK_TREE_MODEL (tpref->priv->columns_store));
+ treeview = ui_make_tree_view (GTK_TREE_MODEL (tpref->priv->columns_store));
tpref->priv->columns_treeview = GTK_TREE_VIEW (treeview);
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE);
gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (treeview), TRUE);
@@ -391,15 +384,15 @@ table_preferences_new (TableInfo *tinfo)
gtk_grid_attach (GTK_GRID (grid), tpref->priv->field_props, 1, 1, 1, 1);
/* show all */
- gtk_widget_show_all (top_vbox);
+ gtk_widget_show_all (grid);
/*
* initial update
*/
GdaMetaStruct *mstruct;
- mstruct = browser_connection_get_meta_struct (tpref->priv->bcnc);
+ mstruct = t_connection_get_meta_struct (tpref->priv->tcnc);
if (mstruct)
- meta_changed_cb (tpref->priv->bcnc, mstruct, tpref);
+ meta_changed_cb (tpref->priv->tcnc, mstruct, tpref);
selection_changed_cb (select, tpref);
g_signal_connect (tpref->priv->columns_store, "row-changed",
@@ -556,10 +549,10 @@ update_column_properties (TablePreferences *tpref)
gchar *eprops;
GError *error = NULL;
tpref->priv->save_plugin_changes = FALSE;
- eprops = browser_connection_get_table_column_attribute (tpref->priv->bcnc,
+ eprops = t_connection_get_table_column_attribute (tpref->priv->tcnc,
tpref->priv->current_table,
tpref->priv->current_column,
- BROWSER_CONNECTION_COLUMN_PLUGIN, &error);
+ T_CONNECTION_COLUMN_PLUGIN, &error);
if (error) {
TO_IMPLEMENT; /* FIXME: add a notice somewhere in the UI */
g_warning ("Error: %s\n", error->message);
@@ -690,10 +683,10 @@ plugins_combo_changed_cb (GtkComboBox *combo, TablePreferences *tpref)
if (tpref->priv->save_plugin_changes &&
tpref->priv->current_table &&
tpref->priv->current_column &&
- ! browser_connection_set_table_column_attribute (tpref->priv->bcnc,
+ ! t_connection_set_table_column_attribute (tpref->priv->tcnc,
tpref->priv->current_table,
tpref->priv->current_column,
- BROWSER_CONNECTION_COLUMN_PLUGIN,
+ T_CONNECTION_COLUMN_PLUGIN,
plugin ? plugin->plugin_name : NULL,
&error)) {
TO_IMPLEMENT; /* FIXME: add a notice somewhere in the UI */
@@ -763,10 +756,10 @@ options_form_param_changed_cb (G_GNUC_UNUSED GdauiBasicForm *form, G_GNUC_UNUSED
G_CALLBACK (columns_model_row_changed_cb), tpref);
if (tpref->priv->current_table &&
tpref->priv->current_column &&
- ! browser_connection_set_table_column_attribute (tpref->priv->bcnc,
+ ! t_connection_set_table_column_attribute (tpref->priv->tcnc,
tpref->priv->current_table,
tpref->priv->current_column,
- BROWSER_CONNECTION_COLUMN_PLUGIN,
+ T_CONNECTION_COLUMN_PLUGIN,
plugin_all ? plugin_all->str : NULL,
&error)) {
TO_IMPLEMENT; /* FIXME: add a notice somewhere in the UI */
diff --git a/tools/browser/schema-browser/table-relations.c b/tools/browser/schema-browser/table-relations.c
index 44eb2c4..3dc1b1b 100644
--- a/tools/browser/schema-browser/table-relations.c
+++ b/tools/browser/schema-browser/table-relations.c
@@ -32,7 +32,7 @@
#include "../canvas/browser-canvas-db-relations.h"
struct _TableRelationsPrivate {
- BrowserConnection *bcnc;
+ TConnection *tcnc;
TableInfo *tinfo;
GtkWidget *canvas;
gboolean all_schemas;
@@ -42,7 +42,7 @@ static void table_relations_class_init (TableRelationsClass *klass);
static void table_relations_init (TableRelations *trels, TableRelationsClass *klass);
static void table_relations_dispose (GObject *object);
-static void meta_changed_cb (BrowserConnection *bcnc, GdaMetaStruct *mstruct, TableRelations *trels);
+static void meta_changed_cb (TConnection *tcnc, GdaMetaStruct *mstruct, TableRelations *trels);
static GObjectClass *parent_class = NULL;
@@ -78,10 +78,10 @@ table_relations_dispose (GObject *object)
/* free memory */
if (trels->priv) {
- if (trels->priv->bcnc) {
- g_signal_handlers_disconnect_by_func (trels->priv->bcnc,
+ if (trels->priv->tcnc) {
+ g_signal_handlers_disconnect_by_func (trels->priv->tcnc,
G_CALLBACK (meta_changed_cb), trels);
- g_object_unref (trels->priv->bcnc);
+ g_object_unref (trels->priv->tcnc);
}
g_free (trels->priv);
trels->priv = NULL;
@@ -114,7 +114,7 @@ table_relations_get_type (void)
}
static void
-meta_changed_cb (G_GNUC_UNUSED BrowserConnection *bcnc, GdaMetaStruct *mstruct, TableRelations *trels)
+meta_changed_cb (G_GNUC_UNUSED TConnection *tcnc, GdaMetaStruct *mstruct, TableRelations *trels)
{
GdaMetaDbObject *dbo;
GValue *tname, *tschema;
@@ -187,8 +187,8 @@ table_relations_new (TableInfo *tinfo)
trels = TABLE_RELATIONS (g_object_new (TABLE_RELATIONS_TYPE, NULL));
trels->priv->tinfo = tinfo;
- trels->priv->bcnc = g_object_ref (table_info_get_connection (tinfo));
- g_signal_connect (trels->priv->bcnc, "meta-changed",
+ trels->priv->tcnc = g_object_ref (table_info_get_connection (tinfo));
+ g_signal_connect (trels->priv->tcnc, "meta-changed",
G_CALLBACK (meta_changed_cb), trels);
/*
@@ -202,9 +202,9 @@ table_relations_new (TableInfo *tinfo)
* initial update
*/
GdaMetaStruct *mstruct;
- mstruct = browser_connection_get_meta_struct (trels->priv->bcnc);
+ mstruct = t_connection_get_meta_struct (trels->priv->tcnc);
if (mstruct)
- meta_changed_cb (trels->priv->bcnc, mstruct, trels);
+ meta_changed_cb (trels->priv->tcnc, mstruct, trels);
return (GtkWidget*) trels;
}
diff --git a/tools/browser/text-search.c b/tools/browser/text-search.c
index 92c8968..b18e002 100644
--- a/tools/browser/text-search.c
+++ b/tools/browser/text-search.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
- * Copyright (C) 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2011 - 2014 Vivien Malerba <malerba gnome-db org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -20,7 +20,9 @@
#include <glib/gi18n-lib.h>
#include <string.h>
#include "text-search.h"
-#include "support.h"
+#include "ui-support.h"
+
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
struct _TextSearchPrivate {
GtkTextView *view;
@@ -261,8 +263,8 @@ text_search_new (GtkTextView *view)
gtk_text_buffer_create_tag (tsearch->priv->text, "search",
"background", "yellow", NULL);
- wid = browser_make_small_button (FALSE, FALSE, NULL, GTK_STOCK_CLOSE,
- _("Hide search toolbar"));
+ wid = ui_make_small_button (FALSE, FALSE, NULL, GTK_STOCK_CLOSE,
+ _("Hide search toolbar"));
gtk_box_pack_start (GTK_BOX (tsearch), wid, FALSE, FALSE, 0);
g_signal_connect_swapped (wid, "clicked",
G_CALLBACK (hide_search_bar), tsearch);
@@ -277,12 +279,12 @@ text_search_new (GtkTextView *view)
g_signal_connect (wid, "changed",
G_CALLBACK (search_text_changed_cb), tsearch);
- wid = browser_make_small_button (FALSE, FALSE, NULL, GTK_STOCK_GO_BACK, NULL);
+ wid = ui_make_small_button (FALSE, FALSE, NULL, GTK_STOCK_GO_BACK, NULL);
gtk_box_pack_start (GTK_BOX (tsearch), wid, FALSE, FALSE, 0);
g_signal_connect (wid, "clicked",
G_CALLBACK (go_back_search_cb), tsearch);
- wid = browser_make_small_button (FALSE, FALSE, NULL, GTK_STOCK_GO_FORWARD, NULL);
+ wid = ui_make_small_button (FALSE, FALSE, NULL, GTK_STOCK_GO_FORWARD, NULL);
gtk_box_pack_start (GTK_BOX (tsearch), wid, FALSE, FALSE, 0);
g_signal_connect (wid, "clicked",
G_CALLBACK (go_forward_search_cb), tsearch);
diff --git a/tools/browser/common/ui-formgrid.c b/tools/browser/ui-formgrid.c
similarity index 91%
rename from tools/browser/common/ui-formgrid.c
rename to tools/browser/ui-formgrid.c
index 689c67c..1f172e4 100644
--- a/tools/browser/common/ui-formgrid.c
+++ b/tools/browser/ui-formgrid.c
@@ -25,16 +25,17 @@
#include <libgda-ui/gdaui-data-proxy.h>
#include <libgda-ui/gdaui-raw-form.h>
#include <libgda-ui/gdaui-data-selector.h>
-#include "../support.h"
-#include "../browser-window.h"
-#include "../browser-stock-icons.h"
+#include "ui-support.h"
+#include "browser-window.h"
#include "widget-overlay.h"
#include <libgda/gda-data-model-extra.h>
-#include "favorites-actions.h"
+#include "../common/t-favorites-actions.h"
+#undef HAVE_LDAP /* FIXME */
#ifdef HAVE_LDAP
-#include "../ldap-browser/ldap-browser-perspective.h"
+ #include "../ldap-browser/ldap-browser-perspective.h" FIXME
#endif
-#include "../../tool-utils.h"
+
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
static void ui_formgrid_class_init (UiFormGridClass * class);
static void ui_formgrid_init (UiFormGrid *wid);
@@ -49,7 +50,7 @@ static void ui_formgrid_get_property (GObject *object,
GValue *value,
GParamSpec *pspec);
static void ui_formgrid_show (GtkWidget *widget);
-static BrowserConnection *get_browser_connection (UiFormGrid *formgrid);
+static TConnection *get_t_connection (UiFormGrid *formgrid);
static void compute_modification_statements (UiFormGrid *formgrid, GdaDataModel *model);
#define GRID_FLAGS (GDAUI_DATA_PROXY_INFO_CURRENT_ROW | GDAUI_DATA_PROXY_INFO_CHUNCK_CHANGE_BUTTONS)
@@ -75,7 +76,7 @@ struct _UiFormGridPriv
gboolean autoupdate_possible;
GdauiDataProxyInfoFlag flags;
- BrowserConnection *bcnc;
+ TConnection *tcnc;
gboolean scroll_form;
/* modifications to the data */
@@ -183,8 +184,8 @@ ui_formgrid_dispose (GObject *object)
formgrid = UI_FORMGRID (object);
if (formgrid->priv) {
- if (formgrid->priv->bcnc)
- g_object_unref (formgrid->priv->bcnc);
+ if (formgrid->priv->tcnc)
+ g_object_unref (formgrid->priv->tcnc);
ModType mod;
for (mod = MOD_INSERT; mod < MOD_LAST; mod++) {
@@ -301,7 +302,7 @@ ui_formgrid_init (UiFormGrid *formgrid)
formgrid->priv->raw_grid = NULL;
formgrid->priv->info = NULL;
formgrid->priv->flags = GDAUI_DATA_PROXY_INFO_CURRENT_ROW | GDAUI_DATA_PROXY_INFO_ROW_MODIFY_BUTTONS;
- formgrid->priv->bcnc = NULL;
+ formgrid->priv->tcnc = NULL;
formgrid->priv->autoupdate = TRUE;
formgrid->priv->autoupdate_possible = FALSE;
formgrid->priv->scroll_form = FALSE;
@@ -362,7 +363,7 @@ ui_formgrid_init (UiFormGrid *formgrid)
action = GTK_ACTION (gtk_toggle_action_new ("FGToggle", "FGToggle",
_("Toggle between grid and form presentations"),
- BROWSER_STOCK_GRID));
+ GTK_STOCK_MISSING_IMAGE));
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE);
gtk_action_group_add_action (agroup, action);
g_signal_connect (G_OBJECT (action), "toggled",
@@ -447,7 +448,7 @@ form_grid_toggled_cb (GtkToggleAction *action, UiFormGrid *formgrid)
"data-proxy", formgrid->priv->raw_form,
"flags", formgrid->priv->flags | FORM_FLAGS, NULL);
- g_object_set (G_OBJECT (action), "stock-id", BROWSER_STOCK_FORM, NULL);
+ g_object_set (G_OBJECT (action), "stock-id", GTK_STOCK_MISSING_IMAGE, NULL);
}
else {
/* switch to grid view */
@@ -456,15 +457,15 @@ form_grid_toggled_cb (GtkToggleAction *action, UiFormGrid *formgrid)
"data-proxy", formgrid->priv->raw_grid,
"flags", formgrid->priv->flags | GRID_FLAGS, NULL);
- g_object_set (G_OBJECT (action), "stock-id", BROWSER_STOCK_GRID, NULL);
+ g_object_set (G_OBJECT (action), "stock-id", GTK_STOCK_MISSING_IMAGE, NULL);
}
}
-static BrowserConnection *
-get_browser_connection (UiFormGrid *formgrid)
+static TConnection *
+get_t_connection (UiFormGrid *formgrid)
{
- if (formgrid->priv->bcnc)
- return formgrid->priv->bcnc;
+ if (formgrid->priv->tcnc)
+ return formgrid->priv->tcnc;
else {
GtkWidget *toplevel;
@@ -488,18 +489,18 @@ form_grid_populate_popup_cb (GtkWidget *wid, GtkMenu *menu, UiFormGrid *formgrid
{
/* add actions to execute to menu */
GdaDataModelIter *iter;
- BrowserConnection *bcnc = NULL;
+ TConnection *tcnc = NULL;
- bcnc = get_browser_connection (formgrid);
- if (!bcnc)
+ tcnc = get_t_connection (formgrid);
+ if (!tcnc)
return;
iter = gdaui_data_selector_get_data_set (GDAUI_DATA_SELECTOR (formgrid->priv->raw_grid));
/* actions */
GSList *actions_list, *list;
- actions_list = gda_tools_favorites_get_actions (browser_connection_get_favorites (bcnc),
- bcnc, GDA_SET (iter));
+ actions_list = t_favorites_actions_get (t_connection_get_favorites (tcnc),
+ tcnc, GDA_SET (iter));
if (actions_list) {
GtkWidget *mitem, *submenu;
mitem = gtk_menu_item_new_with_label (_("Execute action"));
@@ -509,12 +510,12 @@ form_grid_populate_popup_cb (GtkWidget *wid, GtkMenu *menu, UiFormGrid *formgrid
submenu = gtk_menu_new ();
gtk_menu_item_set_submenu (GTK_MENU_ITEM (mitem), submenu);
for (list = actions_list; list; list = list->next) {
- ToolsFavoriteAction *act = (ToolsFavoriteAction*) list->data;
+ TFavoritesAction *act = (TFavoritesAction*) list->data;
mitem = gtk_menu_item_new_with_label (act->name);
gtk_widget_show (mitem);
gtk_menu_shell_append (GTK_MENU_SHELL (submenu), mitem);
g_object_set_data_full (G_OBJECT (mitem), "action", act,
- (GDestroyNotify) gda_tools_favorites_free_action);
+ (GDestroyNotify) t_favorites_action_free);
g_signal_connect (mitem, "activate",
G_CALLBACK (execute_action_mitem_cb), formgrid);
}
@@ -523,7 +524,7 @@ form_grid_populate_popup_cb (GtkWidget *wid, GtkMenu *menu, UiFormGrid *formgrid
#ifdef HAVE_LDAP
/* LDAP specific */
- if (browser_connection_is_ldap (bcnc)) {
+ if (t_connection_is_ldap (tcnc)) {
GdaHolder *dnh;
dnh = gda_set_get_holder (GDA_SET (iter), "dn");
if (dnh) {
@@ -600,7 +601,7 @@ zoom_grid_mitem_cb (GtkCheckMenuItem *checkmenuitem, UiFormGrid *formgrid)
}
typedef struct {
- BrowserConnection *bcnc; /* ref held */
+ TConnection *tcnc; /* ref held */
UiFormGrid *formgrid; /* ref held */
gchar *name;
GdaStatement *stmt; /* ref held */
@@ -615,7 +616,7 @@ static void action_executed_holder_changed_cb (G_GNUC_UNUSED GdaSet *params, G_G
static void
action_executed_data_free (ActionExecutedData *data)
{
- g_object_unref ((GObject*) data->bcnc);
+ g_object_unref ((GObject*) data->tcnc);
if (data->formgrid)
g_object_unref ((GObject*) data->formgrid);
g_free (data->name);
@@ -642,11 +643,11 @@ action_executed_holder_changed_cb (G_GNUC_UNUSED GdaSet *params, G_GNUC_UNUSED G
GError *error = NULL;
gda_data_model_freeze (aed->model);
- if (!browser_connection_rerun_select (aed->bcnc, aed->model, &error)) {
+ if (!t_connection_rerun_select (aed->tcnc, aed->model, &error)) {
GtkWidget *toplevel;
toplevel = gtk_widget_get_toplevel (GTK_WIDGET (aed->formgrid));
- browser_show_error (GTK_WINDOW (toplevel),
- _("Error executing query:\n%s"), error->message ? error->message : _("No
detail"));
+ ui_show_error (GTK_WINDOW (toplevel),
+ _("Error executing query:\n%s"), error->message ? error->message : _("No
detail"));
g_clear_error (&error);
gda_data_model_thaw (aed->model);
}
@@ -659,13 +660,13 @@ action_executed_holder_changed_cb (G_GNUC_UNUSED GdaSet *params, G_GNUC_UNUSED G
static void
execute_action_mitem_cb (GtkMenuItem *menuitem, UiFormGrid *formgrid)
{
- ToolsFavoriteAction *act;
+ TFavoritesAction *act;
GtkWidget *dlg;
gchar *tmp;
gint response;
GtkWidget *toplevel;
- act = (ToolsFavoriteAction*) g_object_get_data (G_OBJECT (menuitem), "action");
+ act = (TFavoritesAction*) g_object_get_data (G_OBJECT (menuitem), "action");
toplevel = gtk_widget_get_toplevel ((GtkWidget*) formgrid);
tmp = g_strdup_printf (_("Set or confirm the parameters to execute\n"
"action '%s'"), act->name);
@@ -677,13 +678,13 @@ execute_action_mitem_cb (GtkMenuItem *menuitem, UiFormGrid *formgrid)
gtk_widget_destroy (dlg);
if (response == GTK_RESPONSE_ACCEPT) {
GError *lerror = NULL;
- BrowserConnection *bcnc;
+ TConnection *tcnc;
- bcnc = get_browser_connection (formgrid);
- g_assert (bcnc);
+ tcnc = get_t_connection (formgrid);
+ g_assert (tcnc);
GObject *result;
- result = browser_connection_execute_statement (bcnc, act->stmt, act->params,
+ result = t_connection_execute_statement (tcnc, act->stmt, act->params,
GDA_STATEMENT_MODEL_RANDOM_ACCESS, NULL,
&lerror);
if (result && GDA_IS_DATA_MODEL (result)) {
@@ -705,12 +706,12 @@ execute_action_mitem_cb (GtkMenuItem *menuitem, UiFormGrid *formgrid)
fg = ui_formgrid_new (GDA_DATA_MODEL (result), TRUE,
GDAUI_DATA_PROXY_INFO_CURRENT_ROW);
- ui_formgrid_set_connection (UI_FORMGRID (fg), bcnc);
+ ui_formgrid_set_connection (UI_FORMGRID (fg), tcnc);
ActionExecutedData *aed;
aed = g_new0 (ActionExecutedData, 1);
aed->formgrid = g_object_ref (formgrid);
- aed->bcnc = g_object_ref (bcnc);
+ aed->tcnc = g_object_ref (tcnc);
if (act->name)
aed->name = g_strdup (act->name);
aed->stmt = g_object_ref (act->stmt);
@@ -751,14 +752,14 @@ execute_action_mitem_cb (GtkMenuItem *menuitem, UiFormGrid *formgrid)
"%s", _("Action successfully executed"));
}
else
- browser_show_message (GTK_WINDOW (toplevel),
- "%s", _("Action successfully executed"));
+ ui_show_message (GTK_WINDOW (toplevel),
+ "%s", _("Action successfully executed"));
g_object_unref (result);
}
else {
- browser_show_error (GTK_WINDOW (toplevel),
- _("Error executing query: %s"),
- lerror && lerror->message ? lerror->message : _("No detail"));
+ ui_show_error (GTK_WINDOW (toplevel),
+ _("Error executing query: %s"),
+ lerror && lerror->message ? lerror->message : _("No detail"));
g_clear_error (&lerror);
}
}
@@ -830,7 +831,7 @@ ui_formgrid_new (GdaDataModel *model, gboolean scroll_form, GdauiDataProxyInfoFl
}
static void
-handle_user_prefs_for_sql_statement (UiFormGrid *formgrid, BrowserConnection *bcnc,
+handle_user_prefs_for_sql_statement (UiFormGrid *formgrid, TConnection *tcnc,
GdaSqlStatement *sqlst)
{
g_assert (sqlst);
@@ -839,7 +840,7 @@ handle_user_prefs_for_sql_statement (UiFormGrid *formgrid, BrowserConnection *bc
GSList *list;
comp = (GdaSqlStatementCompound*) sqlst->contents;
for (list = comp->stmt_list; list; list = list->next)
- handle_user_prefs_for_sql_statement (formgrid, bcnc,
+ handle_user_prefs_for_sql_statement (formgrid, tcnc,
(GdaSqlStatement *) list->data);
}
else {
@@ -858,10 +859,10 @@ handle_user_prefs_for_sql_statement (UiFormGrid *formgrid, BrowserConnection *bc
continue;
gchar *plugin;
- plugin = browser_connection_get_table_column_attribute (bcnc,
+ plugin = t_connection_get_table_column_attribute (tcnc,
GDA_META_TABLE
(field->validity_meta_object),
field->validity_meta_table_column,
-
BROWSER_CONNECTION_COLUMN_PLUGIN, NULL);
+ T_CONNECTION_COLUMN_PLUGIN,
NULL);
if (!plugin)
continue;
@@ -881,20 +882,20 @@ handle_user_prefs_for_sql_statement (UiFormGrid *formgrid, BrowserConnection *bc
/**
* ui_formgrid_handle_user_prefs
* @formgrid: a #UiFormGrid widget
- * @bcnc: (allow-none): a #BrowserConnection, or %NULL to let @formgrid determine it itself
+ * @tcnc: (allow-none): a #TConnection, or %NULL to let @formgrid determine it itself
* @stmt: the #GdaStatement which has been executed to produce the #GdaDataModel displayed in @formgrid
*
* Takes into account the UI preferences of the user
*/
void
-ui_formgrid_handle_user_prefs (UiFormGrid *formgrid, BrowserConnection *bcnc, GdaStatement *stmt)
+ui_formgrid_handle_user_prefs (UiFormGrid *formgrid, TConnection *tcnc, GdaStatement *stmt)
{
g_return_if_fail (UI_IS_FORMGRID (formgrid));
- if (bcnc)
- g_return_if_fail (BROWSER_IS_CONNECTION (bcnc));
+ if (tcnc)
+ g_return_if_fail (T_IS_CONNECTION (tcnc));
else {
- bcnc = get_browser_connection (formgrid);
- if (!bcnc)
+ tcnc = get_t_connection (formgrid);
+ if (!tcnc)
return;
}
if (stmt)
@@ -910,13 +911,13 @@ ui_formgrid_handle_user_prefs (UiFormGrid *formgrid, BrowserConnection *bcnc, Gd
GError *lerror = NULL;
if (((sqlst->stmt_type != GDA_SQL_STATEMENT_SELECT) &&
(sqlst->stmt_type != GDA_SQL_STATEMENT_COMPOUND)) ||
- !browser_connection_normalize_sql_statement (bcnc, sqlst, &lerror)) {
+ !t_connection_normalize_sql_statement (tcnc, sqlst, &lerror)) {
if (lerror)
g_print ("[%s]\n", lerror->message);
goto out;
}
- handle_user_prefs_for_sql_statement (formgrid, bcnc, sqlst);
+ handle_user_prefs_for_sql_statement (formgrid, tcnc, sqlst);
out:
gda_sql_statement_free (sqlst);
}
@@ -1077,22 +1078,22 @@ ui_formgrid_get_grid_widget (UiFormGrid *formgrid)
/**
* ui_formgrid_set_connection
* @formgrid: a #UiFormGrid widget
- * @bcnc: (allow-none): a #BrowserConnection, or %NULL
+ * @tcnc: (allow-none): a #TConnection, or %NULL
*
- * Tells @formgrid to use @bcnc as connection when actions have to be executed
+ * Tells @formgrid to use @tcnc as connection when actions have to be executed
*/
void
-ui_formgrid_set_connection (UiFormGrid *formgrid, BrowserConnection *bcnc)
+ui_formgrid_set_connection (UiFormGrid *formgrid, TConnection *tcnc)
{
g_return_if_fail (UI_IS_FORMGRID (formgrid));
- g_return_if_fail (!bcnc || BROWSER_IS_CONNECTION (bcnc));
+ g_return_if_fail (!tcnc || T_IS_CONNECTION (tcnc));
- if (formgrid->priv->bcnc) {
- g_object_unref (formgrid->priv->bcnc);
- formgrid->priv->bcnc = NULL;
+ if (formgrid->priv->tcnc) {
+ g_object_unref (formgrid->priv->tcnc);
+ formgrid->priv->tcnc = NULL;
}
- if (bcnc)
- formgrid->priv->bcnc = g_object_ref (bcnc);
+ if (tcnc)
+ formgrid->priv->tcnc = g_object_ref (tcnc);
}
static void
diff --git a/tools/browser/common/ui-formgrid.h b/tools/browser/ui-formgrid.h
similarity index 94%
rename from tools/browser/common/ui-formgrid.h
rename to tools/browser/ui-formgrid.h
index 79e5c67..3ed87eb 100644
--- a/tools/browser/common/ui-formgrid.h
+++ b/tools/browser/ui-formgrid.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2010 - 2014 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
*
* This program is free software; you can redistribute it and/or
@@ -24,7 +24,7 @@
#include <libgda/gda-data-model.h>
#include <libgda-ui/gdaui-data-proxy-info.h>
#include <libgda-ui/gdaui-raw-grid.h>
-#include "../browser-connection.h"
+#include "../common/t-connection.h"
G_BEGIN_DECLS
@@ -66,7 +66,7 @@ GType ui_formgrid_get_type (void);
GtkWidget *ui_formgrid_new (GdaDataModel *model, gboolean scroll_form,
GdauiDataProxyInfoFlag flags);
-void ui_formgrid_handle_user_prefs (UiFormGrid *formgrid, BrowserConnection *bcnc,
+void ui_formgrid_handle_user_prefs (UiFormGrid *formgrid, TConnection *bcnc,
GdaStatement *stmt);
GArray *ui_formgrid_get_selection (UiFormGrid *formgrid);
@@ -75,7 +75,7 @@ GdaDataModelIter *ui_formgrid_get_grid_data_set (UiFormGrid *formgrid);
void ui_formgrid_set_sample_size (UiFormGrid *formgrid, gint sample_size);
GdauiRawGrid *ui_formgrid_get_grid_widget (UiFormGrid *formgrid);
-void ui_formgrid_set_connection (UiFormGrid *formgrid, BrowserConnection *bcnc);
+void ui_formgrid_set_connection (UiFormGrid *formgrid, TConnection *bcnc);
GtkUIManager *ui_formgrid_get_ui_manager (UiFormGrid *formgrid);
G_END_DECLS
diff --git a/tools/browser/ui-support.c b/tools/browser/ui-support.c
new file mode 100644
index 0000000..8782167
--- /dev/null
+++ b/tools/browser/ui-support.c
@@ -0,0 +1,578 @@
+/*
+ * Copyright (C) 2014 Vivien Malerba <malerba gnome-db org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include <string.h>
+#include <glib/gi18n-lib.h>
+#include "ui-support.h"
+#include <base/base-tool-decl.h>
+#include "browser-window.h"
+#include <libgda/binreloc/gda-binreloc.h>
+
+#ifdef HAVE_LDAP
+
+/**
+ * ui_connection_ldap_icon_for_class_kind:
+ * @kind: a #GdaLdapClassKind
+ *
+ * Returns: (transfer none): the correct icon, or %NULL if it could not be determined
+ */
+GdkPixbuf *
+ui_connection_ldap_icon_for_class_kind (GdaLdapClassKind kind)
+{
+ switch (kind) {
+ case GDA_LDAP_CLASS_KIND_ABSTRACT:
+ return ui_get_pixbuf_icon (UI_ICON_LDAP_CLASS_ABSTRACT);
+ case GDA_LDAP_CLASS_KIND_STRUTURAL:
+ return ui_get_pixbuf_icon (UI_ICON_LDAP_CLASS_STRUCTURAL);
+ case GDA_LDAP_CLASS_KIND_AUXILIARY:
+ return ui_get_pixbuf_icon (UI_ICON_LDAP_CLASS_AUXILIARY);
+ case GDA_LDAP_CLASS_KIND_UNKNOWN:
+ return ui_get_pixbuf_icon (UI_ICON_LDAP_CLASS_UNKNOWN);
+ default:
+ g_assert_not_reached ();
+ return NULL;
+ }
+}
+
+/**
+ * ui_connection_ldap_class_kind_to_string:
+ * @kind:
+ *
+ * Returns: (transfer none): a string
+ */
+const gchar *
+ui_connection_ldap_class_kind_to_string (GdaLdapClassKind kind)
+{
+ switch (kind) {
+ case GDA_LDAP_CLASS_KIND_ABSTRACT:
+ return _("Abstract");
+ case GDA_LDAP_CLASS_KIND_STRUTURAL:
+ return _("Structural");
+ case GDA_LDAP_CLASS_KIND_AUXILIARY:
+ return _("Auxilliary");
+ case GDA_LDAP_CLASS_KIND_UNKNOWN:
+ return _("Unknown");
+ default:
+ g_assert_not_reached ();
+ return NULL;
+ }
+}
+
+/**
+ * ui_connection_ldap_icon_for_class:
+ * @objectclass: objectClass attribute
+ *
+ * Returns: (transfer none): the correct icon, or %NULL if it could not be determined
+ */
+GdkPixbuf *
+ui_connection_ldap_icon_for_class (GdaLdapAttribute *objectclass)
+{
+ gint type = 0;
+ if (objectclass) {
+ guint i;
+ for (i = 0; i < objectclass->nb_values; i++) {
+ const gchar *class = g_value_get_string (objectclass->values[i]);
+ if (!class)
+ continue;
+ else if (!strcmp (class, "organization"))
+ type = MAX(type, 1);
+ else if (!strcmp (class, "groupOfNames") ||
+ !strcmp (class, "posixGroup"))
+ type = MAX(type, 2);
+ else if (!strcmp (class, "account") ||
+ !strcmp (class, "mailUser") ||
+ !strcmp (class, "organizationalPerson") ||
+ !strcmp (class, "person") ||
+ !strcmp (class, "pilotPerson") ||
+ !strcmp (class, "newPilotPerson") ||
+ !strcmp (class, "pkiUser") ||
+ !strcmp (class, "posixUser") ||
+ !strcmp (class, "posixAccount") ||
+ !strcmp (class, "residentalPerson") ||
+ !strcmp (class, "shadowAccount") ||
+ !strcmp (class, "strongAuthenticationUser") ||
+ !strcmp (class, "inetOrgPerson"))
+ type = MAX(type, 3);
+ }
+ }
+
+ switch (type) {
+ case 0:
+ return ui_get_pixbuf_icon (UI_ICON_LDAP_ENTRY);
+ case 1:
+ return ui_get_pixbuf_icon (UI_ICON_LDAP_ORGANIZATION);
+ case 2:
+ return ui_get_pixbuf_icon (UI_ICON_LDAP_GROUP);
+ case 3:
+ return ui_get_pixbuf_icon (UI_ICON_LDAP_PERSON);
+ default:
+ g_assert_not_reached ();
+ return NULL;
+ }
+}
+
+/**
+ * ui_connection_ldap_icon_for_dn:
+ * @tcnc: a #TConnection
+ * @dn: the DN of the entry
+ * @error: a place to store errors, or %NULL
+ *
+ * Determines the correct icon type for @dn based on which class it belongs to
+ *
+ * Returns: (transfer none): a #GdkPixbuf, or %NULL
+ */
+GdkPixbuf *
+ui_connection_ldap_icon_for_dn (TConnection *tcnc, const gchar *dn, GError **error)
+{
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
+ g_return_val_if_fail (t_connection_is_ldap (tcnc), NULL);
+ g_return_val_if_fail (dn && *dn, NULL);
+
+ GdaLdapEntry *lentry;
+ lentry = t_connection_ldap_describe_entry (tcnc, dn, error);
+ if (lentry) {
+ GdaLdapAttribute *attr;
+ attr = g_hash_table_lookup (lentry->attributes_hash, "objectClass");
+
+ GdkPixbuf *pixbuf;
+ pixbuf = ui_connection_ldap_icon_for_class (attr);
+ gda_ldap_entry_free (lentry);
+ return pixbuf;
+ }
+ else
+ return NULL;
+}
+
+#endif /* HAVE_LDAP */
+
+/**
+ * ui_show_error:
+ * @parent: a #GtkWindow
+ * @format: printf() style format string
+ * @...: arguments for @format
+ *
+ * Displays an error message until the user acknowledges it. I @parent is a #BrowserWindow, then
+ * the error message is displayed in the window if possible
+ */
+void
+ui_show_error (GtkWindow *parent, const gchar *format, ...)
+{
+ va_list args;
+ gchar sz[2048];
+ GtkWidget *dialog;
+ gchar *tmp;
+
+ /* build the message string */
+ va_start (args, format);
+ vsnprintf (sz, sizeof (sz), format, args);
+ va_end (args);
+
+ /*
+ FIXME
+ if (BROWSER_IS_WINDOW (parent)) {
+ browser_window_show_notice (BROWSER_WINDOW (parent), GTK_MESSAGE_ERROR,
+ NULL, sz);
+ return;
+ }
+ */
+
+ /* create the error message dialog */
+ dialog = gtk_message_dialog_new (parent,
+ GTK_DIALOG_DESTROY_WITH_PARENT |
+ GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE, NULL);
+ tmp = g_strdup_printf ("<span weight=\"bold\">%s</span>\n%s", _("Error:"), sz);
+ gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog), tmp);
+ g_free (tmp);
+
+ gtk_widget_show_all (dialog);
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+}
+
+/**
+ * ui_show_message:
+ * @parent: a #GtkWindow
+ * @format: printf() style format string
+ * @...: arguments for @format
+ *
+ * Displays an error message until the user aknowledges it. I @parent is a #BrowserWindow, then
+ * the error message is displayed in the window if possible
+ */
+void
+ui_show_message (GtkWindow *parent, const gchar *format, ...)
+{
+ va_list args;
+ gchar sz[2048];
+ GtkWidget *dialog;
+ gchar *tmp;
+
+ /* build the message string */
+ va_start (args, format);
+ vsnprintf (sz, sizeof (sz), format, args);
+ va_end (args);
+
+ if (BROWSER_IS_WINDOW (parent)) {
+ browser_window_show_notice (BROWSER_WINDOW (parent), GTK_MESSAGE_INFO,
+ NULL, sz);
+ return;
+ }
+
+ /* create the error message dialog */
+ dialog = gtk_message_dialog_new (parent,
+ GTK_DIALOG_DESTROY_WITH_PARENT |
+ GTK_DIALOG_MODAL, GTK_MESSAGE_INFO,
+ GTK_BUTTONS_CLOSE, NULL);
+ tmp = g_strdup_printf ("<span weight=\"bold\">%s</span>\n%s", _("Information:"), sz);
+ gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog), tmp);
+ g_free (tmp);
+
+ gtk_widget_show_all (dialog);
+ gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+}
+
+#ifdef HAVE_GDU
+/**
+ * ui_show_help:
+ * @current: a #GtkWidget
+ * @topic: the topic to show
+ */
+void
+ui_show_help (GtkWindow *parent, const gchar *topic)
+{
+ GdkScreen *screen;
+ GError *error = NULL;
+
+ const gchar *const *langs;
+ gchar *uri = NULL;
+ gint i;
+
+ langs = g_get_language_names ();
+ for (i = 0; langs[i]; i++) {
+ const gchar *lang;
+ lang = langs[i];
+ if (strchr (lang, '.'))
+ continue;
+
+ uri = gda_gbr_get_file_path (GDA_DATA_DIR, "gnome", "help", "gda-browser", lang, NULL);
+
+ /*g_print ("TST URI [%s]\n", uri);*/
+ if (g_file_test (uri, G_FILE_TEST_EXISTS)) {
+ /* terminate URI with a '/' for images to load properly,
+ * see http://mail.gnome.org/archives/gnome-doc-list/2009-August/msg00058.html
+ */
+ gchar *tmp;
+ if (topic)
+ tmp = g_strdup_printf ("%s/?%s", uri, topic);
+ else
+ tmp = g_strdup_printf ("%s/", uri);
+ g_free (uri);
+ uri = tmp;
+
+ break;
+ }
+ g_free (uri);
+ uri = NULL;
+ }
+ /*g_print ("URI [%s]\n", uri);*/
+ if (uri == NULL) {
+ ui_show_error (NULL, _("Unable to display help. Please make sure the "
+ "documentation package is installed."));
+ return;
+ }
+
+ gchar *ruri;
+
+ screen = gtk_widget_get_screen ((GtkWidget*) parent);
+ ruri = g_strdup_printf ("ghelp:%s", uri);
+ gtk_show_uri (screen, ruri, gtk_get_current_event_time (), &error);
+ g_free (ruri);
+
+ if (error) {
+ GtkWidget *d;
+ d = gtk_message_dialog_new (parent,
+ GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
+ "%s", _("Unable to open help file"));
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (d),
+ "%s", error->message);
+ g_signal_connect (d, "response", G_CALLBACK (gtk_widget_destroy), NULL);
+ gtk_window_present (GTK_WINDOW (d));
+
+ g_error_free (error);
+ }
+ else if (BROWSER_IS_WINDOW (parent))
+ browser_window_show_notice (BROWSER_WINDOW (parent), GTK_MESSAGE_INFO,
+ "show-help", _("Help is being loaded, please wait..."));
+ else
+ ui_show_message (parent, "%s", _("Help is being loaded, please wait..."));
+
+ g_free (uri);
+}
+#endif
+
+
+/**
+ * ui_find_parent_widget:
+ * @current: a #GtkWidget
+ * @requested_type: the requested type for the return value
+ *
+ * Finds the 1st parent widget of @current which is of the @requested_type type.
+ *
+ * Returns: a #GtkWidget of the requested type, or %NULL if non found
+ */
+GtkWidget *
+ui_find_parent_widget (GtkWidget *current, GType requested_type)
+{
+ GtkWidget *wid;
+ g_return_val_if_fail (GTK_IS_WIDGET (current), NULL);
+
+ for (wid = gtk_widget_get_parent (current); wid; wid = gtk_widget_get_parent (wid)) {
+ if (G_OBJECT_TYPE (wid) == requested_type)
+ return wid;
+ }
+ return NULL;
+}
+
+/**
+ * ui_make_tree_view:
+ * @model: a #GtkTreeModel
+ *
+ * Creates a #GtkTreeView which, when right clicked, selects the row underneath the mouse
+ * cursor.
+ *
+ * Returns: a new #GtkWidget
+ */
+GtkWidget *
+ui_make_tree_view (GtkTreeModel *model)
+{
+ GtkWidget *tv;
+ g_return_val_if_fail (GTK_IS_TREE_MODEL (model), NULL);
+ tv = gtk_tree_view_new_with_model (model);
+ gtk_widget_set_vexpand (GTK_WIDGET (tv), TRUE);
+
+ _gdaui_setup_right_click_selection_on_treeview (GTK_TREE_VIEW (tv));
+ return tv;
+}
+
+/**
+ * ui_make_small_button:
+ */
+GtkWidget *
+ui_make_small_button (gboolean is_toggle, gboolean with_arrow,
+ const gchar *label, const gchar *icon_name,
+ const gchar *tooltip)
+{
+ GtkWidget *button, *hbox = NULL;
+
+ if (is_toggle)
+ button = gtk_toggle_button_new ();
+ else
+ button = gtk_button_new ();
+ if ((label && icon_name) || with_arrow) {
+ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+ gtk_container_add (GTK_CONTAINER (button), hbox);
+ gtk_widget_show (hbox);
+ }
+
+ if (icon_name) {
+ GtkWidget *image;
+ image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
+ if (hbox)
+ gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
+ else
+ gtk_container_add (GTK_CONTAINER (button), image);
+ gtk_widget_show (image);
+ }
+ if (label) {
+ GtkWidget *wid;
+ wid = gtk_label_new (label);
+ gtk_misc_set_alignment (GTK_MISC (wid), 0., -1);
+ if (hbox)
+ gtk_box_pack_start (GTK_BOX (hbox), wid, FALSE, FALSE, 5);
+ else
+ gtk_container_add (GTK_CONTAINER (button), wid);
+ gtk_widget_show (wid);
+ }
+ if (with_arrow) {
+ GtkWidget *arrow;
+ arrow = gtk_arrow_new (GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
+ gtk_box_pack_start (GTK_BOX (hbox), arrow, TRUE, TRUE, 0);
+ gtk_misc_set_alignment (GTK_MISC (arrow), 1, .5);
+ gtk_widget_show (arrow);
+ }
+
+ if (tooltip)
+ gtk_widget_set_tooltip_text (button, tooltip);
+ return button;
+}
+
+static GtkWidget *
+_make_tab_label (const gchar *label,
+ GtkWidget *img, gboolean with_close,
+ GtkWidget **out_close_button)
+{
+ GtkWidget *hbox, *wid, *close_button, *image = NULL;
+ static GtkCssProvider *css_provider = NULL;
+
+ if (!css_provider) {
+ css_provider = gtk_css_provider_new ();
+ gtk_css_provider_load_from_data (css_provider,
+ "* {\n"
+ "-GtkWidget-focus-padding : 0;\n"
+ "-GtkWidget-focus-line-width : 0}",
+ -1, NULL);
+ }
+
+ if (out_close_button)
+ *out_close_button = NULL;
+
+ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+
+ if (img)
+ gtk_box_pack_start (GTK_BOX (hbox), img, FALSE, FALSE, 0);
+
+ wid = gtk_label_new (label);
+ gtk_label_set_single_line_mode (GTK_LABEL (wid), TRUE);
+ gtk_misc_set_alignment (GTK_MISC (wid), 0.0, 0.5);
+ gtk_misc_set_padding (GTK_MISC (wid), 0, 0);
+ gtk_box_pack_start (GTK_BOX (hbox), wid, TRUE, TRUE, 0);
+
+ if (with_close) {
+ image = gtk_image_new_from_icon_name ("window-close", GTK_ICON_SIZE_MENU);
+ close_button = gtk_button_new ();
+ gtk_button_set_relief (GTK_BUTTON (close_button), GTK_RELIEF_NONE);
+ gtk_button_set_focus_on_click (GTK_BUTTON (close_button), FALSE);
+ gtk_style_context_add_provider (gtk_widget_get_style_context ((GtkWidget*) close_button),
+ GTK_STYLE_PROVIDER (css_provider),
+ GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+
+ gtk_widget_set_tooltip_text (close_button, _("Close tab"));
+
+ gtk_container_add (GTK_CONTAINER (close_button), image);
+ gtk_container_set_border_width (GTK_CONTAINER (close_button), 0);
+ gtk_box_pack_start (GTK_BOX (hbox), close_button, FALSE, FALSE, 0);
+
+ if (out_close_button)
+ *out_close_button = close_button;
+ }
+
+ gtk_widget_show_all (hbox);
+ return hbox;
+}
+
+/**
+ * ui_make_tab_label_with_icon:
+ */
+GtkWidget *
+ui_make_tab_label_with_icon (const gchar *label,
+ const gchar *icon_name, gboolean with_close,
+ GtkWidget **out_close_button)
+{
+ GtkWidget *image = NULL;
+ if (icon_name)
+ image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
+
+ return _make_tab_label (label, image, with_close, out_close_button);
+}
+
+/**
+ * ui_make_tab_label_with_pixbuf:
+ */
+GtkWidget *
+ui_make_tab_label_with_pixbuf (const gchar *label,
+ GdkPixbuf *pixbuf, gboolean with_close,
+ GtkWidget **out_close_button)
+{
+ GtkWidget *image = NULL;
+ if (pixbuf)
+ image = gtk_image_new_from_pixbuf (pixbuf);
+ return _make_tab_label (label, image, with_close, out_close_button);
+}
+
+
+static const gchar *fnames[] = {
+ "-bookmark.png",
+ "-schema.png",
+ "-table.png",
+ "-column.png",
+ "-column-pk.png",
+ "-column-fk.png",
+ "-column-fknn.png",
+ "-column-nn.png",
+ "-reference.png",
+ "-diagram.png",
+ "-query.png",
+ "-action.png",
+
+ "-menu-ind.png",
+
+ "-ldap-entry.png",
+ "-ldap-group.png",
+ "-ldap-organization.png",
+ "-ldap-person.png",
+ "-ldap-class-s.png",
+ "-ldap-class-a.png",
+ "-ldap-class-x.png",
+ "-ldap-class-u.png",
+
+ /*
+ "-auth-big.png",
+ "-auth.png",
+
+ "-connected-big.png",
+ "-connected.png",
+
+ "-non-connected-big.png",
+ "-non-connected.png",
+ ".png",
+ "-view.png"
+ */
+};
+
+/**
+ * ui_get_pixbuf_icon:
+ * Returns: (transfer none): a #GkdPixbuf
+ */
+GdkPixbuf *
+ui_get_pixbuf_icon (UiIconType type)
+{
+ g_return_val_if_fail (type >= 0, NULL);
+ g_return_val_if_fail (type < UI_ICON_LAST, NULL);
+
+ static GdkPixbuf **pixbufs = NULL;
+
+ if (!pixbufs)
+ pixbufs = g_new0 (GdkPixbuf*, UI_ICON_LAST);
+
+ GdkPixbuf *pix;
+ pix = pixbufs [type];
+
+ if (pix)
+ return pix;
+ else {
+ gchar *tmp;
+ tmp = g_strdup_printf ("/images/gda-browser%s", fnames [type]);
+ pix = gdk_pixbuf_new_from_resource (tmp, NULL);
+ g_free (tmp);
+ pixbufs [type] = pix;
+
+ return pix;
+ }
+}
diff --git a/tools/browser/ui-support.h b/tools/browser/ui-support.h
new file mode 100644
index 0000000..4c75b57
--- /dev/null
+++ b/tools/browser/ui-support.h
@@ -0,0 +1,108 @@
+/*
+ * Copyright (C) 2009 - 2014 Vivien Malerba <malerba gnome-db org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __UI_SUPPORT_H_
+#define __UI_SUPPORT_H_
+
+#include <libgda/libgda.h>
+#include <gtk/gtk.h>
+#ifdef HAVE_LDAP
+ #include <libgda/sqlite/virtual/gda-ldap-connection.h>
+ #include <virtual/gda-ldap-connection.h>
+#endif /* HAVE_LDAP */
+#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <common/t-connection.h>
+#include <libgda-ui/internal/utility.h>
+
+G_BEGIN_DECLS
+
+#ifdef HAVE_LDAP
+GdkPixbuf *ui_connection_ldap_icon_for_dn (TConnection *tcnc, const gchar *dn, GError **error);
+GdkPixbuf *ui_connection_ldap_icon_for_class_kind (GdaLdapClassKind kind);
+GdkPixbuf *ui_connection_ldap_icon_for_class (GdaLdapAttribute *objectclass);
+const gchar *ui_connection_ldap_class_kind_to_string (GdaLdapClassKind kind);
+
+#endif /* HAVE_LDAP */
+
+void ui_show_error (GtkWindow *parent, const gchar *format, ...);
+void ui_show_message (GtkWindow *parent, const gchar *format, ...);
+#ifdef HAVE_GDU
+void ui_show_help (GtkWindow *parent, const gchar *topic);
+#endif
+
+GtkWidget *ui_find_parent_widget (GtkWidget *current, GType requested_type);
+GtkWidget *ui_make_tree_view (GtkTreeModel *model);
+
+
+GtkWidget *ui_make_small_button (gboolean is_toggle, gboolean with_arrow,
+ const gchar *label, const gchar *icon_name,
+ const gchar *tooltip);
+GtkWidget *ui_make_tab_label_with_icon (const gchar *label,
+ const gchar *icon_name, gboolean with_close,
+ GtkWidget **out_close_button);
+GtkWidget *ui_make_tab_label_with_pixbuf (const gchar *label,
+ GdkPixbuf *pixbuf, gboolean with_close,
+ GtkWidget **out_close_button);
+
+/*
+ * icons, see browser_get_pixbuf_icon() for the associated icons
+ */
+typedef enum {
+ UI_ICON_BOOKMARK,
+ UI_ICON_SCHEMA,
+ UI_ICON_TABLE,
+ UI_ICON_COLUMN,
+ UI_ICON_COLUMN_PK,
+ UI_ICON_COLUMN_FK,
+ UI_ICON_COLUMN_FK_NN,
+ UI_ICON_COLUMN_NN,
+ UI_ICON_REFERENCE,
+ UI_ICON_DIAGRAM,
+ UI_ICON_QUERY,
+ UI_ICON_ACTION,
+
+ UI_ICON_MENU_INDICATOR,
+
+ UI_ICON_LDAP_ENTRY,
+ UI_ICON_LDAP_GROUP,
+ UI_ICON_LDAP_ORGANIZATION,
+ UI_ICON_LDAP_PERSON,
+ UI_ICON_LDAP_CLASS_STRUCTURAL,
+ UI_ICON_LDAP_CLASS_ABSTRACT,
+ UI_ICON_LDAP_CLASS_AUXILIARY,
+ UI_ICON_LDAP_CLASS_UNKNOWN,
+
+ UI_ICON_LAST
+} UiIconType;
+
+GdkPixbuf *ui_get_pixbuf_icon (UiIconType type);
+
+#define VARIABLES_HELP _("<small>This area allows to give values to\n" \
+ "variables defined in the SQL code\n" \
+ "using the following syntax:\n" \
+ "<b><tt>##<variable name>::<type>[::null]</tt></b>\n" \
+ "For example:\n" \
+ "<span foreground=\"#4e9a06\"><b><tt>##id::int</tt></b></span>\n defines
<b>id</b> as a non NULL integer\n" \
+ "<span foreground=\"#4e9a06\"><b><tt>##age::string::null</tt></b></span>\n
defines <b>age</b> as a string\n\n" \
+ "Valid types are: <tt>string</tt>, <tt>boolean</tt>, <tt>int</tt>,\n" \
+ "<tt>date</tt>, <tt>time</tt>, <tt>timestamp</tt>, <tt>guint</tt>, <tt>blob</tt>
and\n" \
+ "<tt>binary</tt></small>")
+
+G_END_DECLS
+
+#endif
diff --git a/tools/browser/common/widget-overlay.c b/tools/browser/widget-overlay.c
similarity index 99%
rename from tools/browser/common/widget-overlay.c
rename to tools/browser/widget-overlay.c
index 46bcb35..2e12232 100644
--- a/tools/browser/common/widget-overlay.c
+++ b/tools/browser/widget-overlay.c
@@ -19,6 +19,8 @@
#include <stdarg.h>
#include <glib/gi18n-lib.h>
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+
#define SCALE_MIN .6
#define SCALE_MAX 1.
#define SCALE_MAX_SCALE 1.5
diff --git a/tools/browser/common/widget-overlay.h b/tools/browser/widget-overlay.h
similarity index 100%
rename from tools/browser/common/widget-overlay.h
rename to tools/browser/widget-overlay.h
diff --git a/tools/common/.gitignore b/tools/common/.gitignore
new file mode 100644
index 0000000..ebe58c2
--- /dev/null
+++ b/tools/common/.gitignore
@@ -0,0 +1 @@
+marshal.[ch]
\ No newline at end of file
diff --git a/tools/common/Makefile.am b/tools/common/Makefile.am
new file mode 100644
index 0000000..1f5e97c
--- /dev/null
+++ b/tools/common/Makefile.am
@@ -0,0 +1,66 @@
+noinst_LTLIBRARIES = libcommon.la
+
+AM_CPPFLAGS = \
+ -I$(top_srcdir) \
+ -I$(top_srcdir)/libgda \
+ -I$(top_builddir) \
+ -I$(top_builddir)/libgda \
+ -I$(top_builddir)/libgda/sqlite \
+ -I$(top_srcdir)/libgda/sqlite \
+ -I$(top_srcdir)/tools \
+ -I$(top_srcdir)/tools/base \
+ $(COREDEPS_CFLAGS) \
+ $(COREDEPS_WFLAGS) \
+ $(GTK_CFLAGS)
+
+marshal.h: marshal.list $(GLIB_GENMARSHAL)
+ $(GLIB_GENMARSHAL) $< --header --prefix=_marshal > $@
+marshal.c: marshal.list $(GLIB_GENMARSHAL) marshal.h
+ $(GLIB_GENMARSHAL) $< --body --prefix=_marshal > $@
+
+nonuisources = \
+ marshal.h \
+ marshal.c \
+ t-decl.h \
+ t-app.h \
+ t-app.c \
+ t-context.h \
+ t-context.c \
+ t-term-context.h \
+ t-term-context.c \
+ t-web-context.h \
+ t-web-context.c \
+ t-errors.h \
+ t-errors.c \
+ t-favorites.h \
+ t-favorites.c \
+ t-utils.h \
+ t-utils.c \
+ t-config-info.h \
+ t-config-info.c \
+ t-connection.h \
+ t-connection.c \
+ t-virtual-connection.h \
+ t-virtual-connection.c \
+ t-favorites-actions.h \
+ t-favorites-actions.c
+
+if LIBSOUP
+nonuisources += web-server.h web-server.c html-doc.h html-doc.c
+AM_CPPFLAGS += $(LIBSOUP_CFLAGS)
+endif
+
+libcommon_la_SOURCES = $(nonuisources)
+
+if HAVE_UI
+noinst_LTLIBRARIES += libcommonui.la
+
+libcommonui_la_CFLAGS = \
+ $(AM_CPPFLAGS) \
+ $(GTK_CFLAGS) \
+ -DHAVE_GTK_CLASSES
+
+libcommonui_la_SOURCES = \
+ $(nonuisources)
+
+endif
diff --git a/tools/html-doc.c b/tools/common/html-doc.c
similarity index 100%
rename from tools/html-doc.c
rename to tools/common/html-doc.c
diff --git a/tools/html-doc.h b/tools/common/html-doc.h
similarity index 100%
rename from tools/html-doc.h
rename to tools/common/html-doc.h
diff --git a/tools/browser/common/marshal.list b/tools/common/marshal.list
similarity index 94%
rename from tools/browser/common/marshal.list
rename to tools/common/marshal.list
index c4ac747..44aaa41 100644
--- a/tools/browser/common/marshal.list
+++ b/tools/common/marshal.list
@@ -21,5 +21,7 @@
# OBJECT for GObject or derived types (GObject*)
# NONE deprecated alias for VOID
# BOOL deprecated alias for BOOLEAN
-VOID:ENUM,STRING
-VOID:INT,ENUM,STRING
+
+VOID:BOOLEAN,STRING
+VOID:STRING
+VOID:POINTER,POINTER,STRING,STRING
diff --git a/tools/gda-sql.c b/tools/common/t-app.c
similarity index 52%
rename from tools/gda-sql.c
rename to tools/common/t-app.c
index db4fb92..9284e8b 100644
--- a/tools/gda-sql.c
+++ b/tools/common/t-app.c
@@ -1,10 +1,5 @@
/*
- * Copyright (C) 2007 - 2013 Vivien Malerba <malerba gnome-db org>
- * Copyright (C) 2008 Murray Cumming <murrayc murrayc com>
- * Copyright (C) 2008 Nathan <nbinont yahoo ca>
- * Copyright (C) 2009 Bas Driessen <bas driessen xobas com>
- * Copyright (C) 2010 David King <davidk openismus com>
- * Copyright (C) 2012 Daniel Mustieles <daniel mustieles gmail com>
+ * Copyright (C) 2014 Vivien Malerba <malerba gnome-db org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -21,1983 +16,921 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#include "tool.h"
-#include "tool-utils.h"
-#include "gda-sql.h"
-#include <virtual/libgda-virtual.h>
-#include <glib/gi18n-lib.h>
-#include <glib/gprintf.h>
-#include <string.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <glib/gstdio.h>
-#include "tool-input.h"
-#include "tool-output.h"
-#include "config-info.h"
-#include "command-exec.h"
+#include "t-app.h"
+#include "t-context.h"
+#include "t-term-context.h"
+#include "t-connection.h"
+#include "t-utils.h"
+#include "t-config-info.h"
+#include "web-server.h"
#include <unistd.h>
-#ifdef HAVE_TERMIOS_H
-#include <termios.h>
-#endif
#include <sys/types.h>
-#include <libgda/gda-quark-list.h>
-#include <libgda/gda-meta-struct.h>
+#ifndef G_OS_WIN32
+ #include <pwd.h>
+#endif
+#include <errno.h>
+#include <glib/gi18n-lib.h>
+#include <glib/gstdio.h>
+#include <base/base-tool-input.h>
+#include <sql-parser/gda-sql-parser.h>
+#include <virtual/libgda-virtual.h>
#include <libgda/gda-blob-op.h>
-#ifdef HAVE_LOCALE_H
-#include <locale.h>
+#ifdef HAVE_GTK_CLASSES
+ #include <browser/login-dialog.h>
+ #include <browser/auth-dialog.h>
+ #include <browser/browser-window.h>
#endif
-#ifndef G_OS_WIN32
-#include <signal.h>
-typedef void (*sighandler_t)(int);
-#include <pwd.h>
-#else
-#include <stdlib.h>
-#include <windows.h>
-#endif
+#define T_APP_LOCK(self) g_rec_mutex_lock(& ((TApp*)(self))->priv->rmutex)
+#define T_APP_UNLOCK(self) g_rec_mutex_unlock(& ((TApp*)(self))->priv->rmutex)
-#ifdef HAVE_READLINE
-#include <readline/readline.h>
-#endif
+/*
+ * Main static functions
+ */
+static void t_app_class_init (TAppClass *klass);
+static void t_app_init (TApp *app);
+static void t_app_dispose (GObject *object);
-#ifdef HAVE_LIBSOUP
-#include "web-server.h"
+#ifdef HAVE_GTK_CLASSES
+static void t_app_shutdown (GApplication *application);
#endif
-/* options */
-gboolean show_version = FALSE;
+/* get a pointer to the parents to be able to call their destructor */
+static GObjectClass *parent_class = NULL;
-gchar *single_command = NULL;
-gchar *commandsfile = NULL;
-gboolean interactive = FALSE;
+/* pointer to the singleton */
+TApp *global_t_app = NULL;
-gboolean list_configs = FALSE;
-gboolean list_providers = FALSE;
+/* signals */
+enum {
+ CNC_ADDED,
+ CNC_REMOVED,
+ QUIT_REQUESTED,
+ LAST_SIGNAL
+};
-gboolean list_data_files = FALSE;
-gchar *purge_data_files = NULL;
+static gint t_app_signals[LAST_SIGNAL] = { 0, 0, 0 };
+struct _TAppPrivate {
+ TAppFeatures features;
-gchar *outfile = NULL;
-gboolean has_threads;
+ /* if T_APP_TERM_CONSOLE is featured */
+ TContext *term_console;
-#ifdef HAVE_LIBSOUP
-gint http_port = -1;
-gchar *auth_token = NULL;
-#endif
+ /* if T_APP_T is featured */
-static GOptionEntry entries[] = {
- { "version", 'v', 0, G_OPTION_ARG_NONE, &show_version, "Show version information and exit", NULL },
- { "output-file", 'o', 0, G_OPTION_ARG_STRING, &outfile, "Output file", "output file"},
- { "command", 'C', 0, G_OPTION_ARG_STRING, &single_command, "Run only single command (SQL or
internal) and exit", "command" },
- { "commands-file", 'f', 0, G_OPTION_ARG_STRING, &commandsfile, "Execute commands from file, then
exit (except if -i specified)", "filename" },
- { "interactive", 'i', 0, G_OPTION_ARG_NONE, &interactive, "Keep the console opened after executing a
file (-f option)", NULL },
- { "list-dsn", 'l', 0, G_OPTION_ARG_NONE, &list_configs, "List configured data sources and exit",
NULL },
- { "list-providers", 'L', 0, G_OPTION_ARG_NONE, &list_providers, "List installed database providers
and exit", NULL },
+ /* if T_APP_WEB_SERVER is featured */
#ifdef HAVE_LIBSOUP
- { "http-port", 's', 0, G_OPTION_ARG_INT, &http_port, "Run embedded HTTP server on specified port",
"port" },
- { "http-token", 't', 0, G_OPTION_ARG_STRING, &auth_token, "Authentication token (required to
authenticate clients)", "token phrase" },
-#endif
- { "data-files-list", 0, 0, G_OPTION_ARG_NONE, &list_data_files, "List files used to hold information
related to each connection", NULL },
- { "data-files-purge", 0, 0, G_OPTION_ARG_STRING, &purge_data_files, "Remove some files used to hold
information related to each connection. Criteria has to be in 'all', 'non-dsn', or 'non-exist-dsn'",
"criteria"},
- { NULL, 0, 0, 0, NULL, NULL, NULL }
-};
-
-/* interruption handling */
-#ifndef G_OS_WIN32
-struct sigaction old_sigint_handler;
+ WebServer *server;
#endif
-static void sigint_handler (int sig_num);
-static void setup_sigint_handler (void);
-typedef enum {
- SIGINT_HANDLER_DISABLED = 0,
- SIGINT_HANDLER_PARTIAL_COMMAND,
-} SigintHandlerCode;
-static SigintHandlerCode sigint_handler_status = SIGINT_HANDLER_DISABLED;
-
-
-/* structure to hold program's data */
-typedef struct {
- SqlConsole *term_console;
- GSList *settings; /* list all the ConnectionSetting */
- ToolCommandGroup *limit_commands;
- ToolCommandGroup *all_commands;
-
- FILE *input_stream;
- GString *partial_command;
+ GRecMutex rmutex;
+ GSList *tcnc_list; /* list all the TConnection */
+ GSList *tcontext_list; /* list of all the TContext */
- GdaSet *options;
GHashTable *parameters; /* key = name, value = G_TYPE_STRING GdaHolder */
-#define LAST_DATA_MODEL_NAME "_"
+ GdaSet *options;
GHashTable *mem_data_models; /* key = name, value = the named GdaDataModel, ref# kept in hash table */
+};
-#ifdef HAVE_LIBSOUP
- WebServer *server;
-#endif
-} MainData;
-
-MainData *main_data;
-GString *prompt = NULL;
-GMainLoop *main_loop = NULL;
-gboolean exit_requested = FALSE;
-
-static ConnectionSetting *get_current_connection_settings (SqlConsole *console);
-static char **completion_func (const char *text, const gchar *line, int start, int end);
-static void compute_prompt (SqlConsole *console, GString *string, gboolean in_command,
- gboolean for_readline, ToolOutputFormat format);
-static gboolean set_output_file (const gchar *file, GError **error);
-static gboolean set_input_file (const gchar *file, GError **error);
-static gchar *data_model_to_string (SqlConsole *console, GdaDataModel *model);
-static void output_data_model (GdaDataModel *model);
-static void output_string (const gchar *str);
-static ConnectionSetting *open_connection (SqlConsole *console, const gchar *cnc_name, const gchar
*cnc_string,
- GError **error);
-static void connection_settings_free (ConnectionSetting *cs);
-
-static gboolean treat_line_func (const gchar *cmde, gboolean *out_cmde_exec_ok);
-static const char *prompt_func (void);
-
-static GdaSet *make_options_set_from_gdasql_options (const gchar *context);
-static void compute_term_color_attribute (void);
-
-
-/* commands manipulation */
-static void build_commands (MainData *md);
-static gboolean command_is_complete (const gchar *command);
-static ToolCommandResult *command_execute (SqlConsole *console,
- const gchar *command,
- GdaStatementModelUsage usage, GError **error);
-
-static void display_result (ToolCommandResult *res);
-
-int
-main (int argc, char *argv[])
+GType
+t_app_get_type (void)
{
- GOptionContext *context;
- GError *error = NULL;
- MainData *data;
- int exit_status = EXIT_SUCCESS;
- gboolean show_welcome = TRUE;
- GValue *value;
- GdaHolder *opt;
- prompt = g_string_new ("");
-
- context = g_option_context_new (_("[DSN|connection string]..."));
- g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
- g_option_context_set_ignore_unknown_options (context, TRUE);
- if (!g_option_context_parse (context, &argc, &argv, &error)) {
- g_fprintf (stderr, "Can't parse arguments: %s\n", error->message);
- return EXIT_FAILURE;
+ static GType type = 0;
+
+ if (G_UNLIKELY (type == 0)) {
+ static GMutex registering;
+ static const GTypeInfo info = {
+ sizeof (TAppClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) t_app_class_init,
+ NULL,
+ NULL,
+ sizeof (TApp),
+ 0,
+ (GInstanceInitFunc) t_app_init,
+ 0
+ };
+
+
+ g_mutex_lock (®istering);
+ if (type == 0) {
+#ifdef HAVE_GTK_CLASSES
+ type = g_type_register_static (GTK_TYPE_APPLICATION, "TApp", &info, 0);
+#else
+ type = g_type_register_static (G_TYPE_APPLICATION, "TApp", &info, 0);
+#endif
+ }
+ g_mutex_unlock (®istering);
}
- g_option_context_free (context);
-
- if (show_version) {
- g_print (_("GDA SQL console version " PACKAGE_VERSION "\n"));
- return 0;
- }
-
- g_setenv ("GDA_CONFIG_SYNCHRONOUS", "1", TRUE);
- setlocale (LC_ALL, "");
- gda_init ();
+ return type;
+}
- has_threads = g_thread_supported ();
- data = g_new0 (MainData, 1);
- data->options = gda_set_new_inline (3,
- "csv_names_on_first_line", G_TYPE_BOOLEAN, FALSE,
- "csv_quote", G_TYPE_STRING, "\"",
- "csv_separator", G_TYPE_STRING, ",");
-#ifdef HAVE_LDAP
-#define DEFAULT_LDAP_ATTRIBUTES "cn"
- opt = gda_holder_new_string ("ldap_dn", "dn");
- value = gda_value_new (G_TYPE_STRING);
- g_value_set_string (value, _("Defines how the DN column is handled for LDAP searched (among \"dn\",
\"rdn\" and \"none\")"));
- gda_holder_set_attribute (opt, GDA_ATTRIBUTE_DESCRIPTION, value, NULL);
- gda_set_add_holder (data->options, opt);
- g_object_unref (opt);
-
- opt = gda_holder_new_string ("ldap_attributes", DEFAULT_LDAP_ATTRIBUTES);
- g_value_set_string (value, _("Defines the LDAP attributes which are fetched by default by LDAP
commands"));
- gda_holder_set_attribute (opt, GDA_ATTRIBUTE_DESCRIPTION, value, NULL);
- gda_value_free (value);
- gda_set_add_holder (data->options, opt);
- g_object_unref (opt);
+static void
+t_app_class_init (TAppClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ parent_class = g_type_class_peek_parent (klass);
+
+ t_app_signals[CNC_ADDED] =
+ g_signal_new ("connection-added",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (TAppClass, connection_added),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, T_TYPE_CONNECTION);
+
+ t_app_signals[CNC_REMOVED] =
+ g_signal_new ("connection-removed",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (TAppClass, connection_removed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, T_TYPE_CONNECTION);
+
+ t_app_signals[QUIT_REQUESTED] =
+ g_signal_new ("quit-requested",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (TAppClass, quit_requested),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
+
+ klass->connection_added = NULL;
+ klass->connection_removed = NULL;
+ klass->quit_requested = NULL;
+
+#ifdef HAVE_GTK_CLASSES
+ GApplicationClass *application_class = G_APPLICATION_CLASS (klass);
+ application_class->shutdown = t_app_shutdown;
#endif
- value = gda_value_new (G_TYPE_STRING);
- g_value_set_string (value, _("Set to TRUE when the 1st line of a CSV file holds column names"));
- opt = gda_set_get_holder (data->options, "csv_names_on_first_line");
- gda_holder_set_attribute (opt, GDA_ATTRIBUTE_DESCRIPTION, value, NULL);
- g_value_set_string (value, "NAMES_ON_FIRST_LINE");
- gda_holder_set_attribute (opt, "csv", value, NULL);
-
- g_value_set_string (value, _("Quote character for CSV format"));
- opt = gda_set_get_holder (data->options, "csv_quote");
- gda_holder_set_attribute (opt, GDA_ATTRIBUTE_DESCRIPTION, value, NULL);
- g_value_set_string (value, "QUOTE");
- gda_holder_set_attribute (opt, "csv", value, NULL);
-
- g_value_set_string (value, _("Separator character for CSV format"));
- opt = gda_set_get_holder (data->options, "csv_separator");
- gda_holder_set_attribute (opt, GDA_ATTRIBUTE_DESCRIPTION, value, NULL);
- g_value_set_string (value, "SEPARATOR");
- gda_holder_set_attribute (opt, "csv", value, NULL);
- gda_value_free (value);
+ object_class->dispose = t_app_dispose;
+}
- data->parameters = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
- data->mem_data_models = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
- main_data = data;
-
- /* build internal command s list */
- build_commands (data);
- data->term_console = gda_sql_console_new ("TERM");
- data->term_console->command_group = main_data->all_commands;
- compute_term_color_attribute ();
-
- /* output file */
- if (outfile) {
- if (! set_output_file (outfile, &error)) {
- g_print ("Can't set output file as '%s': %s\n", outfile,
- error->message);
- exit_status = EXIT_FAILURE;
- goto cleanup;
- }
- }
+static void
+t_app_init (TApp *self)
+{
+ self->priv = g_new0 (TAppPrivate, 1);
+ g_rec_mutex_init (& self->priv->rmutex);
+}
- /* treat here lists of providers and defined DSN */
- if (list_providers) {
- if (argc == 2) {
- single_command = g_strdup_printf (".lp %s", argv[1]);
- argc = 1;
- show_welcome = FALSE;
- }
- else {
- GdaDataModel *model = config_info_list_all_providers ();
- output_data_model (model);
- g_object_unref (model);
- goto cleanup;
- }
- }
- if (list_configs) {
- if (argc == 2) {
- single_command = g_strdup_printf (".l %s", argv[1]);
- argc = 1;
- show_welcome = FALSE;
- }
- else {
- GdaDataModel *model = config_info_list_all_dsn ();
- output_data_model (model);
- g_object_unref (model);
- goto cleanup;
- }
- }
- if (list_data_files) {
- gchar *confdir;
- GdaDataModel *model;
+static void
+t_app_dispose (GObject *object)
+{
+ TApp *self;
- confdir = config_info_compute_dict_directory ();
- g_print (_("All files are in the directory: %s\n"), confdir);
- g_free (confdir);
- model = config_info_list_data_files (&error);
- if (model) {
- output_data_model (model);
- g_object_unref (model);
- }
- else
- g_print (_("Can't get the list of files used to store information about each
connection: %s\n"),
- error->message);
- goto cleanup;
- }
- if (purge_data_files) {
- gchar *tmp;
- tmp = config_info_purge_data_files (purge_data_files, &error);
- if (tmp) {
- output_string (tmp);
- g_free (tmp);
- }
- if (error)
- g_print (_("Error while purging files used to store information about each
connection: %s\n"),
- error->message);
- goto cleanup;
- }
-
- /* commands file */
- if (commandsfile) {
- if (! set_input_file (commandsfile, &error)) {
- g_print ("Can't read file '%s': %s\n", commandsfile,
- error->message);
- exit_status = EXIT_FAILURE;
- goto cleanup;
- }
- }
- else {
- /* check if stdin is a term */
- if (!isatty (fileno (stdin)))
- data->input_stream = stdin;
- }
+ g_return_if_fail (IS_T_APP (object));
- /* welcome message */
- if (show_welcome && !data->term_console->output_stream) {
-#ifdef G_OS_WIN32
- HANDLE wHnd;
- SMALL_RECT windowSize = {0, 0, 139, 49};
+ self = T_APP (object);
+ if (self->priv) {
+ while (self->priv->tcontext_list)
+ g_object_unref (G_OBJECT (self->priv->tcontext_list->data));
- wHnd = GetStdHandle(STD_OUTPUT_HANDLE);
+ while (self->priv->tcnc_list) {
+ TConnection *tcnc;
+ tcnc = T_CONNECTION (self->priv->tcnc_list->data);
+ self->priv->tcnc_list = g_slist_delete_link (self->priv->tcnc_list,
self->priv->tcnc_list);
+ g_signal_emit (self, t_app_signals[CNC_REMOVED], 0, tcnc);
+ g_object_unref (G_OBJECT (tcnc));
+ }
- SetConsoleTitle ("GDA SQL console, version " PACKAGE_VERSION);
- SetConsoleWindowInfo (wHnd, TRUE, &windowSize);
-#endif
- gchar *c1, *c2, *c3, *c4;
- tool_output_color_print (TOOL_COLOR_BOLD, main_data->term_console->output_format,
- _("Welcome to the GDA SQL console, version " PACKAGE_VERSION));
- g_print ("\n\n");
- c1 = tool_output_color_string (TOOL_COLOR_BOLD, main_data->term_console->output_format,
".copyright");
- c2 = tool_output_color_string (TOOL_COLOR_BOLD, main_data->term_console->output_format, ".?");
- c3 = tool_output_color_string (TOOL_COLOR_BOLD, main_data->term_console->output_format,
".help");
- c4 = tool_output_color_string (TOOL_COLOR_BOLD, main_data->term_console->output_format, ".q");
- g_print (_("Type: %s to show usage and distribution terms\n"
- " %s or %s for help with internal commands\n"
- " %s (or CTRL-D) to quit (the '.' can be replaced by a '\\')\n"
- " or any SQL query terminated by a semicolon\n\n"), c1, c2, c3, c4);
- g_free (c1);
- g_free (c2);
- g_free (c3);
- g_free (c4);
- }
-
- /* open connections if specified */
- gint i;
- for (i = 1; i < argc; i++) {
- /* open connection */
- ConnectionSetting *cs;
- GdaDsnInfo *info = NULL;
- gchar *str;
+ g_rec_mutex_clear (& self->priv->rmutex);
+ g_free (self->priv);
+ self->priv = NULL;
+ }
+ global_t_app = NULL;
- if (*argv[i] == '-')
- continue;
-#define SHEBANG "#!"
-#define SHEBANGLEN 2
-
- /* try to see if argv[i] corresponds to a file starting with SHEBANG */
- FILE *file;
- file = fopen (argv[i], "r");
- if (file) {
- char buffer [SHEBANGLEN + 1];
- size_t nread;
- nread = fread (buffer, 1, SHEBANGLEN, file);
- if (nread == SHEBANGLEN) {
- buffer [SHEBANGLEN] = 0;
- if (!strcmp (buffer, SHEBANG)) {
- if (! set_input_file (argv[i], &error)) {
- g_print ("Can't read file '%s': %s\n", commandsfile,
- error->message);
- exit_status = EXIT_FAILURE;
- fclose (file);
- goto cleanup;
- }
- fclose (file);
- continue;
- }
- }
- fclose (file);
- }
+ /* parent class */
+ parent_class->dispose (object);
- info = gda_config_get_dsn_info (argv[i]);
- if (info)
- str = g_strdup (info->name);
- else
- str = g_strdup_printf ("c%d", i-1);
- if (!data->term_console->output_stream) {
- gchar *params, *prov, *user;
- gda_connection_string_split (argv[i], ¶ms, &prov, &user, NULL);
- g_print (_("Opening connection '%s' for: "), str);
- if (prov)
- g_print ("%s://", prov);
- if (user)
- g_print ("%s@", user);
- if (params)
- g_print ("%s", params);
- g_print ("\n");
- g_free (params);
- g_free (prov);
- g_free (user);
- }
- cs = open_connection (data->term_console, str, argv[i], &error);
- config_info_modify_argv (argv[i]);
- g_free (str);
- if (!cs) {
- g_print (_("Can't open connection %d: %s\n"), i,
- error && error->message ? error->message : _("No detail"));
- exit_status = EXIT_FAILURE;
- goto cleanup;
- }
- }
- if (getenv ("GDA_SQL_CNC")) {
- ConnectionSetting *cs;
- gchar *str;
- const gchar *envstr = getenv ("GDA_SQL_CNC");
- str = g_strdup_printf ("c%d", i-1);
- if (!data->term_console->output_stream) {
- gchar *params, *prov, *user;
- gda_connection_string_split (envstr, ¶ms, &prov, &user, NULL);
- g_print (_("Opening connection '%s' (GDA_SQL_CNC environment variable): "), str);
- if (prov)
- g_print ("%s://", prov);
- if (user)
- g_print ("%s@", user);
- if (params)
- g_print ("%s", params);
- g_print ("\n");
- g_free (params);
- g_free (prov);
- g_free (user);
- }
- cs = open_connection (data->term_console, str, envstr, &error);
- g_free (str);
- if (!cs) {
- g_print (_("Can't open connection defined by GDA_SQL_CNC: %s\n"),
- error && error->message ? error->message : _("No detail"));
- exit_status = EXIT_FAILURE;
- goto cleanup;
- }
+}
+#ifdef HAVE_GTK_CLASSES
+static void
+t_app_shutdown (GApplication *application)
+{
+ GList *windows;
+ windows = gtk_application_get_windows (GTK_APPLICATION (application));
+ if (windows) {
+ GList *list;
+ windows = g_list_copy (windows);
+ for (list = windows; list; list = list->next)
+ gtk_widget_destroy (GTK_WIDGET (list->data));
+ g_list_free (windows);
}
-#ifdef HAVE_LIBSOUP
- /* start HTTP server if requested */
- if (http_port > 0) {
- main_data->server = web_server_new (http_port, auth_token);
- if (!main_data->server) {
- g_print (_("Can't run HTTP server on port %d\n"), http_port);
- exit_status = EXIT_FAILURE;
- goto cleanup;
- }
- }
+ G_APPLICATION_CLASS (parent_class)->shutdown (application);
+}
#endif
- /* process commands which need to be executed as specified by the command line args */
- if (single_command) {
- treat_line_func (single_command, NULL);
- if (!data->term_console->output_stream)
- g_print ("\n");
- goto cleanup;
- }
-
- if (data->input_stream) {
- gchar *cmde;
- for (;;) {
- cmde = input_from_stream (data->input_stream);
- if (cmde) {
- gboolean command_ok;
- treat_line_func (cmde, &command_ok);
- g_free (cmde);
- if (! command_ok)
- break;
- }
- else
- break;
- }
- if (interactive && !cmde && isatty (fileno (stdin)))
- set_input_file (NULL, NULL);
- else {
- if (!data->term_console->output_stream)
- g_print ("\n");
- goto cleanup;
- }
- }
-
- if (exit_requested)
- goto cleanup;
+static void build_commands (TApp *self, TAppFeatures features);
- /* set up interactive commands */
- setup_sigint_handler ();
- init_input ((TreatLineFunc) treat_line_func, prompt_func, NULL);
- tool_input_set_completion_func (data->term_console->command_group, completion_func, ".\\");
+/**
+ * t_app_setup:
+ * @features: a set of features which will be used by some consoles
+ *
+ * Sets up the unique #TApp object. Use the t_app_add_feature() to add more features
+ */
+void
+t_app_setup (TAppFeatures features)
+{
+ if (!global_t_app) {
+ global_t_app = g_object_new (T_APP_TYPE, "flags", G_APPLICATION_HANDLES_COMMAND_LINE |
G_APPLICATION_NON_UNIQUE, NULL);
+
+ /* options */
+ global_t_app->priv->options = gda_set_new_inline (3,
+ "csv_names_on_first_line", G_TYPE_BOOLEAN,
FALSE,
+ "csv_quote", G_TYPE_STRING, "\"",
+ "csv_separator", G_TYPE_STRING, ",");
+
+ GdaHolder *opt;
+ GValue *value;
+ value = gda_value_new (G_TYPE_STRING);
+ g_value_set_string (value, _("Set to TRUE when the 1st line of a CSV file holds column
names"));
+ opt = gda_set_get_holder (global_t_app->priv->options, "csv_names_on_first_line");
+ gda_holder_set_attribute (opt, GDA_ATTRIBUTE_DESCRIPTION, value, NULL);
+ g_value_set_string (value, "NAMES_ON_FIRST_LINE");
+ gda_holder_set_attribute (opt, "csv", value, NULL);
+
+ g_value_set_string (value, _("Quote character for CSV format"));
+ opt = gda_set_get_holder (global_t_app->priv->options, "csv_quote");
+ gda_holder_set_attribute (opt, GDA_ATTRIBUTE_DESCRIPTION, value, NULL);
+ g_value_set_string (value, "QUOTE");
+ gda_holder_set_attribute (opt, "csv", value, NULL);
+
+ g_value_set_string (value, _("Separator character for CSV format"));
+ opt = gda_set_get_holder (global_t_app->priv->options, "csv_separator");
+ gda_holder_set_attribute (opt, GDA_ATTRIBUTE_DESCRIPTION, value, NULL);
+ g_value_set_string (value, "SEPARATOR");
+ gda_holder_set_attribute (opt, "csv", value, NULL);
+ gda_value_free (value);
- /* run main loop */
- main_loop = g_main_loop_new (NULL, TRUE);
- g_main_loop_run (main_loop);
- g_main_loop_unref (main_loop);
+#ifdef HAVE_LDAP
+ opt = gda_holder_new_string ("ldap_dn", "dn");
+ value = gda_value_new (G_TYPE_STRING);
+ g_value_set_string (value, _("Defines how the DN column is handled for LDAP searched (among
\"dn\", \"rdn\" and \"none\")"));
+ gda_holder_set_attribute (opt, GDA_ATTRIBUTE_DESCRIPTION, value, NULL);
+ gda_set_add_holder (T_APP (global_t_app)->priv->options, opt);
+ g_object_unref (opt);
+
+ opt = gda_holder_new_string ("ldap_attributes", T_DEFAULT_LDAP_ATTRIBUTES);
+ g_value_set_string (value, _("Defines the LDAP attributes which are fetched by default by
LDAP commands"));
+ gda_holder_set_attribute (opt, GDA_ATTRIBUTE_DESCRIPTION, value, NULL);
+ gda_value_free (value);
+ gda_set_add_holder (T_APP (global_t_app)->priv->options, opt);
+ g_object_unref (opt);
+#endif
- cleanup:
- /* cleanups */
- g_slist_foreach (data->settings, (GFunc) connection_settings_free, NULL);
- set_input_file (NULL, NULL);
- set_output_file (NULL, NULL);
- end_input ();
+ global_t_app->priv->mem_data_models = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
g_object_unref);
- g_free (data);
+ /* parameters */
+ global_t_app->priv->parameters = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
g_object_unref);
- return exit_status;
-}
+ /* building commands lists */
+ build_commands (global_t_app, features);
-static void
-compute_term_color_attribute (void)
-{
- g_assert (main_data);
- main_data->term_console->output_format &= ~(TOOL_OUTPUT_FORMAT_COLOR_TERM);
- if (!main_data->term_console->output_stream || isatty (fileno
(main_data->term_console->output_stream))) {
- const gchar *term;
- main_data->term_console->output_format |= TOOL_OUTPUT_FORMAT_COLOR_TERM;
- term = g_getenv ("TERM");
- if (term && !strcmp (term, "dumb"))
- main_data->term_console->output_format ^= TOOL_OUTPUT_FORMAT_COLOR_TERM;
+ t_app_add_feature (features);
}
+ else
+ g_assert_not_reached ();
}
-static const char *
-prompt_func (void)
-{
- /* compute a new prompt */
- compute_prompt (NULL, prompt, main_data->partial_command == NULL ? FALSE : TRUE, TRUE,
- TOOL_OUTPUT_FORMAT_DEFAULT |
- (main_data->term_console->output_format & TOOL_OUTPUT_FORMAT_COLOR_TERM));
- return (char*) prompt->str;
-}
-
-/* @cmde is stolen here */
+#ifdef HAVE_GTK_CLASSES
static gboolean
-treat_line_func (const gchar *cmde, gboolean *out_cmde_exec_ok)
+idle_create_window (GApplication *app)
{
- gchar *loc_cmde = NULL;
+ GSList *cnclist;
+ cnclist = t_app_get_all_connections ();
+ g_assert (cnclist);
- if (out_cmde_exec_ok)
- *out_cmde_exec_ok = TRUE;
+ TConnection *tcnc;
+ tcnc = T_CONNECTION (cnclist->data);
- if (!cmde) {
- save_history (NULL, NULL);
- if (!main_data->term_console->output_stream)
- g_print ("\n");
- exit_requested = TRUE;
- goto exit;
- }
-
- loc_cmde = g_strdup (cmde);
- g_strchug (loc_cmde);
- if (*loc_cmde) {
- add_to_history (loc_cmde);
- if (!main_data->partial_command) {
- /* enable SIGINT handling */
- sigint_handler_status = SIGINT_HANDLER_PARTIAL_COMMAND;
- main_data->partial_command = g_string_new (loc_cmde);
- }
- else {
- g_string_append_c (main_data->partial_command, '\n');
- g_string_append (main_data->partial_command, loc_cmde);
- }
- if (command_is_complete (main_data->partial_command->str)) {
- /* execute command */
- ToolCommandResult *res;
- FILE *to_stream;
- GError *error = NULL;
-
- if ((*main_data->partial_command->str != '\\') && (*main_data->partial_command->str
!= '.')) {
- if (main_data->term_console->current) {
- if (!main_data->term_console->current->query_buffer)
- main_data->term_console->current->query_buffer = g_string_new
("");
- g_string_assign (main_data->term_console->current->query_buffer,
- main_data->partial_command->str);
- }
- }
-
- if (main_data->term_console->output_stream)
- to_stream = main_data->term_console->output_stream;
- else
- to_stream = stdout;
- res = command_execute (main_data->term_console, main_data->partial_command->str,
- GDA_STATEMENT_MODEL_RANDOM_ACCESS, &error);
-
- if (!res) {
- if (!error ||
- (error->domain != GDA_SQL_PARSER_ERROR) ||
- (error->code != GDA_SQL_PARSER_EMPTY_SQL_ERROR)) {
- g_fprintf (to_stream, "%sERROR:%s ",
- tool_output_color_s (TOOL_COLOR_RED,
main_data->term_console->output_format),
- tool_output_color_s (TOOL_COLOR_RESET,
main_data->term_console->output_format));
- g_fprintf (to_stream,
- "%s\n",
- error && error->message ? error->message : _("No detail"));
- if (out_cmde_exec_ok)
- *out_cmde_exec_ok = FALSE;
- }
- if (error) {
- g_error_free (error);
- error = NULL;
- }
- }
- else {
- display_result (res);
- if (res->type == TOOL_COMMAND_RESULT_EXIT) {
- tool_command_result_free (res);
- exit_requested = TRUE;
- goto exit;
- }
- tool_command_result_free (res);
- }
- g_string_free (main_data->partial_command, TRUE);
- main_data->partial_command = NULL;
-
- /* disable SIGINT handling */
- sigint_handler_status = SIGINT_HANDLER_DISABLED;
- }
- }
- g_free (loc_cmde);
- return TRUE;
-
- exit:
- g_free (loc_cmde);
- if (main_loop)
- g_main_loop_quit (main_loop);
- return FALSE;
-}
-
-static void
-display_result (ToolCommandResult *res)
-{
- switch (res->type) {
- case TOOL_COMMAND_RESULT_TXT_STDOUT:
- g_print ("%s", res->u.txt->str);
- if (res->u.txt->str [strlen (res->u.txt->str) - 1] != '\n')
- g_print ("\n");
- fflush (NULL);
- break;
- case TOOL_COMMAND_RESULT_EMPTY:
- break;
- case TOOL_COMMAND_RESULT_MULTIPLE: {
- GSList *list;
- for (list = res->u.multiple_results; list; list = list->next)
- display_result ((ToolCommandResult *) list->data);
- break;
- }
- case TOOL_COMMAND_RESULT_EXIT:
- break;
- default: {
- gchar *str;
- str = tool_output_result_to_string (res, main_data->term_console->output_format,
- main_data->term_console->output_stream,
- main_data->options);
- output_string (str);
- g_free (str);
- }
- }
-}
+ GtkWidget *bwin;
+ bwin = (GtkWidget*) browser_window_new (tcnc, NULL);
+ gtk_application_window_set_show_menubar (GTK_APPLICATION_WINDOW (bwin), FALSE);
+ gtk_window_set_default_size ((GtkWindow*) bwin, 640, 480);
+#define PRGNAME "Gda Browser"
+ gtk_window_set_title (GTK_WINDOW (bwin), PRGNAME);
-/*
- * SIGINT handling
- */
+ gtk_widget_show (bwin);
+ g_application_release (app); /* release now that the 1st window has been created, cf.
t_app_add_feature() where
+ * g_application_hold() is called */
-static void
-setup_sigint_handler (void)
-{
-#ifndef G_OS_WIN32
- struct sigaction sac;
- memset (&sac, 0, sizeof (sac));
- sigemptyset (&sac.sa_mask);
- sac.sa_handler = sigint_handler;
- sac.sa_flags = SA_RESTART;
- sigaction (SIGINT, &sac, &old_sigint_handler);
-#endif
-}
+ global_t_app->priv->features |= T_APP_BROWSER;
-#ifndef G_OS_WIN32
-static void
-sigint_handler (int sig_num)
-{
- if (sigint_handler_status == SIGINT_HANDLER_PARTIAL_COMMAND) {
- if (main_data->partial_command) {
- g_string_free (main_data->partial_command, TRUE);
- main_data->partial_command = NULL;
- sigint_handler_status = SIGINT_HANDLER_DISABLED;
- }
- /* show a new prompt */
- compute_prompt (NULL, prompt, FALSE, FALSE,
- TOOL_OUTPUT_FORMAT_DEFAULT |
- (main_data->term_console->output_format & TOOL_OUTPUT_FORMAT_COLOR_TERM));
- g_print ("\n%s", prompt->str);
- compute_prompt (NULL, prompt, FALSE, TRUE,
- TOOL_OUTPUT_FORMAT_DEFAULT |
- (main_data->term_console->output_format & TOOL_OUTPUT_FORMAT_COLOR_TERM));
- fflush (NULL);
- }
- else {
- g_print ("\n");
- exit (EXIT_SUCCESS);
- }
+ g_object_unref (G_OBJECT (global_t_app));
- if (old_sigint_handler.sa_handler)
- old_sigint_handler.sa_handler (sig_num);
+ return FALSE;
}
#endif
-/*
- * command_is_complete
+
+/**
+ * t_app_add_feature:
+ * @feature: a feature to add
*
- * Checks if @command can be executed, or if more data is required
+ * Changes the global application configuration to remove a feature
*/
-static gboolean
-command_is_complete (const gchar *command)
+void
+t_app_add_feature (TAppFeatures feature)
{
- if (!command || !(*command))
- return FALSE;
- if (single_command)
- return TRUE;
- if ((*command == '\\') || (*command == '.')) {
- /* internal command */
- return TRUE;
- }
- else if (*command == '#') {
- /* comment, to be ignored */
- return TRUE;
- }
- else {
- gint i, len;
- len = strlen (command);
- for (i = len - 1; i > 0; i--) {
- if ((command [i] != ' ') && (command [i] != '\n') && (command [i] != '\r'))
- break;
- }
- if (command [i] == ';')
- return TRUE;
- else
- return FALSE;
- }
-}
+ /* specific features */
+ if ((feature & T_APP_TERM_CONSOLE) &&
+ !(global_t_app->priv->features & T_APP_TERM_CONSOLE)) {
+ g_assert (! global_t_app->priv->term_console);
+ global_t_app->priv->term_console = T_CONTEXT (t_term_context_new ("TERM"));
+ t_utils_term_compute_color_attribute ();
-/*
- * command_execute
- */
-static ToolCommandResult *execute_sql_command (SqlConsole *console, const gchar *command,
- GdaStatementModelUsage usage,
- GError **error);
-static ToolCommandResult *
-command_execute (SqlConsole *console, const gchar *command, GdaStatementModelUsage usage, GError **error)
-{
- ConnectionSetting *cs;
+ g_application_hold (G_APPLICATION (global_t_app));
- g_assert (console);
- cs = get_current_connection_settings (console);
- if (!command || !(*command))
- return NULL;
- if ((*command == '\\') || (*command == '.'))
- return tool_command_group_execute (console->command_group, command + 1,
console->output_format,
- console, error);
+ global_t_app->priv->features |= T_APP_TERM_CONSOLE;
+ }
- else if (*command == '#') {
- /* nothing to do */
- ToolCommandResult *res;
- res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_EMPTY;
- return res;
+#ifdef HAVE_GTK_CLASSES
+ if (feature & T_APP_BROWSER) {
+ g_application_hold (G_APPLICATION (global_t_app)); /* up until the 1st window is created */
+ g_object_ref (G_OBJECT (global_t_app));
+ g_idle_add ((GSourceFunc) idle_create_window, global_t_app);
}
- else {
- if (!cs) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
- "%s", _("No connection specified"));
- return NULL;
- }
- if (!gda_connection_is_opened (cs->cnc)) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_CONNECTION_CLOSED_ERROR,
- "%s", _("Connection closed"));
- return NULL;
- }
-
- return execute_sql_command (console, command, usage, error);
- }
+#endif
+
+#ifdef HAVE_LIBSOUP
+ if (feature & T_APP_WEB_SERVER) {
+ TO_IMPLEMENT;
+ }
+#endif
}
-/*
- * execute_sql_command
+/**
+ * t_app_remove_feature:
+ * @feature: a feature to remove
*
- * Executes an SQL statement as understood by the DBMS
+ * Changes the global application configuration to remove a feature
*/
-static ToolCommandResult *
-execute_sql_command (SqlConsole *console, const gchar *command,
- GdaStatementModelUsage usage, GError **error)
+void
+t_app_remove_feature (TAppFeatures feature)
{
- ToolCommandResult *res = NULL;
- GdaBatch *batch;
- const GSList *stmt_list;
- GdaStatement *stmt;
- GdaSet *params;
- GObject *obj;
- const gchar *remain = NULL;
- ConnectionSetting *cs;
-
- cs = get_current_connection_settings (console);
- if (!cs) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
- "%s", _("No connection specified"));
- return NULL;
- }
+ if (feature & T_APP_TERM_CONSOLE) {
+ g_object_unref (global_t_app->priv->term_console);
+ global_t_app->priv->term_console = NULL;
- batch = gda_sql_parser_parse_string_as_batch (cs->parser, command, &remain, error);
- if (!batch)
- return NULL;
- if (remain) {
- g_object_unref (batch);
- return NULL;
- }
-
- stmt_list = gda_batch_get_statements (batch);
- if (!stmt_list) {
- g_object_unref (batch);
- return NULL;
- }
-
- if (stmt_list->next) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
- "%s", _("More than one SQL statement"));
- g_object_unref (batch);
- return NULL;
- }
-
- stmt = GDA_STATEMENT (stmt_list->data);
- g_object_ref (stmt);
- g_object_unref (batch);
-
- if (!gda_statement_get_parameters (stmt, ¶ms, error)) {
- g_object_unref (stmt);
- return NULL;
- }
-
- /* fill parameters with some defined parameters */
- if (params && params->holders) {
- GSList *list;
- for (list = params->holders; list; list = list->next) {
- GdaHolder *h = GDA_HOLDER (list->data);
- GdaHolder *h_in_data = g_hash_table_lookup (main_data->parameters, gda_holder_get_id
(h));
- if (h_in_data) {
- const GValue *cvalue;
- GValue *value;
-
- cvalue = gda_holder_get_value (h_in_data);
- if (cvalue && (G_VALUE_TYPE (cvalue) == gda_holder_get_g_type (h))) {
- if (!gda_holder_set_value (h, cvalue, error)) {
- g_free (res);
- res = NULL;
- goto cleanup;
- }
- }
- else if (cvalue && (G_VALUE_TYPE (cvalue) == GDA_TYPE_NULL)) {
- if (!gda_holder_set_value (h, cvalue, error)) {
- g_free (res);
- res = NULL;
- goto cleanup;
- }
- }
- else {
- gchar *str;
- str = gda_value_stringify (cvalue);
- value = gda_value_new_from_string (str, gda_holder_get_g_type (h));
- g_free (str);
- if (! value) {
- g_set_error (error, GDA_TOOLS_ERROR,
GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
- _("Could not interpret the '%s' parameter's
value"),
- gda_holder_get_id (h));
- g_free (res);
- res = NULL;
- goto cleanup;
- }
- else if (! gda_holder_take_value (h, value, error)) {
- gda_value_free (value);
- g_free (res);
- res = NULL;
- goto cleanup;
- }
- }
- }
- else {
- if (! gda_holder_is_valid (h)) {
- g_set_error (error, GDA_TOOLS_ERROR,
GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
- _("No internal parameter named '%s' required by query"),
- gda_holder_get_id (h));
- g_free (res);
- res = NULL;
- goto cleanup;
- }
- }
- }
+ global_t_app->priv->features &= ~T_APP_TERM_CONSOLE;
+ g_application_release (G_APPLICATION (global_t_app));
}
- res = g_new0 (ToolCommandResult, 1);
- res->was_in_transaction_before_exec = gda_connection_get_transaction_status (cs->cnc) ? TRUE : FALSE;
- res->cnc = g_object_ref (cs->cnc);
- obj = gda_connection_statement_execute (cs->cnc, stmt, params, usage, NULL, error);
- if (!obj) {
- g_free (res);
- res = NULL;
- }
- else {
- if (GDA_IS_DATA_MODEL (obj)) {
- res->type = TOOL_COMMAND_RESULT_DATA_MODEL;
- res->u.model = GDA_DATA_MODEL (obj);
- }
- else if (GDA_IS_SET (obj)) {
- res->type = TOOL_COMMAND_RESULT_SET;
- res->u.set = GDA_SET (obj);
- }
- else
- g_assert_not_reached ();
+ if (feature & T_APP_BROWSER) {
+ TO_IMPLEMENT;
+ global_t_app->priv->features &= ~T_APP_BROWSER;
}
- cleanup:
- g_object_unref (stmt);
- if (params)
- g_object_unref (params);
-
- return res;
+ if (global_t_app->priv->features == T_APP_NO_FEATURE)
+ t_app_request_quit ();
}
-static ConnectionSetting *
-get_current_connection_settings (SqlConsole *console)
+/**
+ * t_app_cleanup:
+ *
+ * Cleans up everything!
+ */
+void
+t_app_cleanup (void)
{
- if (console->current) {
- g_assert (g_slist_find (main_data->settings, console->current));
- return console->current;
- }
- else
- return NULL;
+ g_assert (global_t_app);
+ g_object_unref (global_t_app);
+ global_t_app = NULL;
}
/**
- * clears and modifies @string to hold a prompt.
+ * t_app_get:
+ *
+ * Obtain a pointer to the unique #TApp
+ *
+ * Returns: (transfer none): the pointer
*/
-static void
-compute_prompt (SqlConsole *console, GString *string, gboolean in_command, gboolean for_readline,
ToolOutputFormat format)
+TApp *
+t_app_get (void)
{
- gchar *prefix = NULL;
- ConnectionSetting *cs;
- g_assert (string);
- gchar suffix = '>';
-
- if (!console)
- console = main_data->term_console;
- g_string_set_size (string, 0);
-
- if (exit_requested)
- return;
-
- if (format & TOOL_OUTPUT_FORMAT_COLOR_TERM) {
- const gchar *color;
- color = tool_output_color_s (TOOL_COLOR_BOLD, format);
- if (color && *color) {
-#ifdef HAVE_READLINE
- if (for_readline)
- g_string_append_c (string, RL_PROMPT_START_IGNORE);
-#endif
- g_string_append (string, color);
-#ifdef HAVE_READLINE
- if (for_readline)
- g_string_append_c (string, RL_PROMPT_END_IGNORE);
-#endif
- }
- }
- cs = get_current_connection_settings (console);
- if (cs) {
- prefix = cs->name;
- if (cs->cnc) {
- GdaTransactionStatus *ts;
- ts = gda_connection_get_transaction_status (cs->cnc);
- if (ts)
- suffix='[';
- }
- }
- else
- prefix = "gda";
-
- if (in_command) {
- gint i, len;
- len = strlen (prefix);
- for (i = 0; i < len; i++)
- g_string_append_c (string, ' ');
- g_string_append_c (string, suffix);
- g_string_append_c (string, ' ');
- }
- else
- g_string_append_printf (string, "%s%c ", prefix, suffix);
-
- if (format & TOOL_OUTPUT_FORMAT_COLOR_TERM) {
- const gchar *color;
- color = tool_output_color_s (TOOL_COLOR_RESET, TOOL_OUTPUT_FORMAT_COLOR_TERM);
- if (color && *color) {
-#ifdef HAVE_READLINE
- if (for_readline)
- g_string_append_c (string, RL_PROMPT_START_IGNORE);
-#endif
- g_string_append (string, color);
-#ifdef HAVE_READLINE
- if (for_readline)
- g_string_append_c (string, RL_PROMPT_END_IGNORE);
-#endif
- }
- }
+ g_assert (global_t_app);
+ return global_t_app;
}
-/*
- * Check that the @arg string can safely be passed to a shell
- * to be executed, i.e. it does not contain dangerous things like "rm -rf *"
- */
-// coverity[ +tainted_string_sanitize_content : arg-0 ]
static gboolean
-check_shell_argument (const gchar *arg)
+end_requested (GApplication *app)
{
- const gchar *ptr;
- g_assert (arg);
-
- /* check for starting spaces */
- for (ptr = arg; *ptr == ' '; ptr++);
- if (!*ptr)
- return FALSE; /* only spaces is not allowed */
-
- /* check for the rest */
- for (; *ptr; ptr++) {
- if (! g_ascii_isalnum (*ptr) && (*ptr != G_DIR_SEPARATOR))
- return FALSE;
- }
- return TRUE;
+ g_application_quit (app);
+ return FALSE; /* remove idle */
}
-/*
- * Change the output file, set to %NULL to be back on stdout
+/**
+ * t_app_request_quit:
+ *
+ * Requests that the application quit; this function initiates the quiting sequence and returns.
*/
-static gboolean
-set_output_file (const gchar *file, GError **error)
+void
+t_app_request_quit (void)
{
- if (main_data->term_console->output_stream) {
- if (main_data->term_console->output_is_pipe) {
- pclose (main_data->term_console->output_stream);
-#ifndef G_OS_WIN32
- signal (SIGPIPE, SIG_DFL);
-#endif
- }
- else
- fclose (main_data->term_console->output_stream);
- main_data->term_console->output_stream = NULL;
- main_data->term_console->output_is_pipe = FALSE;
- }
-
- if (file) {
- gchar *copy = g_strdup (file);
- g_strchug (copy);
-
- if (*copy != '|') {
- /* output to a file */
- main_data->term_console->output_stream = g_fopen (copy, "w");
- if (!main_data->term_console->output_stream) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
- _("Can't open file '%s' for writing: %s\n"),
- copy,
- strerror (errno));
- g_free (copy);
- return FALSE;
- }
- main_data->term_console->output_is_pipe = FALSE;
- }
- else {
- /* output to a pipe */
- if (check_shell_argument (copy+1)) {
- main_data->term_console->output_stream = popen (copy+1, "w");
- if (!main_data->term_console->output_stream) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
- _("Can't open pipe '%s': %s"),
- copy,
- strerror (errno));
- g_free (copy);
- return FALSE;
- }
- }
- else {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
- _("Can't open pipe '%s': %s"),
- copy + 1,
- "program name must only contain alphanumeric characters");
- g_free (copy);
- return FALSE;
- }
-#ifndef G_OS_WIN32
- signal (SIGPIPE, SIG_IGN);
-#endif
- main_data->term_console->output_is_pipe = TRUE;
- }
- g_free (copy);
- }
+ g_assert (global_t_app);
- compute_term_color_attribute ();
- return TRUE;
+ g_signal_emit (global_t_app, t_app_signals[QUIT_REQUESTED], 0);
+ g_idle_add ((GSourceFunc) end_requested, G_APPLICATION (global_t_app));
}
-/*
- * Change the input file, set to %NULL to be back on stdin
+/**
+ * t_app_lock:
+ *
+ * Locks the global #TApp object for the current thread.
*/
-static gboolean
-set_input_file (const gchar *file, GError **error)
+void
+t_app_lock (void)
{
- if (main_data->input_stream) {
- fclose (main_data->input_stream);
- main_data->input_stream = NULL;
- }
-
- if (file) {
- if (*file == '~') {
- gchar *tmp;
- tmp = g_strdup_printf ("%s%s", g_get_home_dir (), file+1);
- main_data->input_stream = g_fopen (tmp, "r");
- g_free (tmp);
- }
- else
- main_data->input_stream = g_fopen (file, "r");
- if (!main_data->input_stream) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
- _("Can't open file '%s' for reading: %s\n"),
- file,
- strerror (errno));
- return FALSE;
- }
- }
-
- return TRUE;
+ g_assert (global_t_app);
+ T_APP_LOCK (global_t_app);
}
-static gboolean
-connection_name_is_valid (const gchar *name)
+/**
+ * t_app_unlock:
+ *
+ * Locks the global #TApp object for the current thread.
+ */
+void
+t_app_unlock (void)
{
- const gchar *ptr;
- if (!name || !*name)
- return FALSE;
- if (! g_ascii_isalpha (*name) && (*name != '_'))
- return FALSE;
- for (ptr = name; *ptr; ptr++)
- if (!g_ascii_isalnum (*ptr) && (*ptr != '_'))
- return FALSE;
- return TRUE;
+ g_assert (global_t_app);
+ T_APP_UNLOCK (global_t_app);
}
-static ConnectionSetting *
-find_connection_from_name (const gchar *name)
+static void
+conn_status_changed_cb (TConnection *tcnc, GdaConnectionStatus status, gpointer data)
{
- ConnectionSetting *cs = NULL;
- GSList *list;
- for (list = main_data->settings; list; list = list->next) {
- if (!strcmp (name, ((ConnectionSetting *) list->data)->name)) {
- cs = (ConnectionSetting *) list->data;
- break;
+ g_assert (global_t_app);
+
+ if (status == GDA_CONNECTION_STATUS_CLOSED) {
+ T_APP_LOCK (global_t_app);
+#ifdef HAVE_GTK_CLASSES
+ GList *windows;
+ windows = gtk_application_get_windows (GTK_APPLICATION (global_t_app));
+ if (windows) {
+ GList *list;
+ windows = g_list_copy (windows);
+ for (list = windows; list; list = list->next) {
+ if (browser_window_get_connection (BROWSER_WINDOW (list->data)) == tcnc)
+ gtk_widget_destroy (GTK_WIDGET (list->data));
+ }
+ g_list_free (windows);
+ }
+
+ if (! gtk_application_get_windows (GTK_APPLICATION (global_t_app))) {
+ /* call t_app_remove_feature when there are no more opened windows*/
+ t_app_remove_feature (T_APP_BROWSER);
}
+#endif
+
+ global_t_app->priv->tcnc_list = g_slist_remove (global_t_app->priv->tcnc_list, tcnc);
+ g_signal_emit (global_t_app, t_app_signals[CNC_REMOVED], 0, tcnc);
+ g_object_unref (tcnc);
+ T_APP_UNLOCK (global_t_app);
}
- return cs;
}
-typedef struct {
- ConnectionSetting *cs;
- gboolean cannot_lock;
- gboolean result;
- GError *error;
-} MetaUpdateData;
-
-static gpointer thread_start_update_meta_store (MetaUpdateData *data);
-static void thread_ok_cb_update_meta_store (GdaThreader *threader, guint job, MetaUpdateData *data);
-static void thread_cancelled_cb_update_meta_store (GdaThreader *threader, guint job, MetaUpdateData *data);
-static void conn_closed_cb (GdaConnection *cnc, gpointer data);
-
-static gchar* read_hidden_passwd ();
-static void user_password_needed (GdaDsnInfo *info, const gchar *real_provider,
- gboolean *out_need_username, gboolean *out_need_password,
- gboolean *out_need_password_if_user);
-
-/*
- * Open a connection
+/**
+ * t_app_add_tcnc:
+ * @tcnc: (transfer full): a #TConnection
+ *
+ * Make @self handle @tcnc. This function is thread-safe.
*/
-static ConnectionSetting*
-open_connection (SqlConsole *console, const gchar *cnc_name, const gchar *cnc_string, GError **error)
+void
+t_app_add_tcnc (TConnection *tcnc)
{
- GdaConnection *newcnc = NULL;
- ConnectionSetting *cs = NULL;
- gchar *real_cnc_string;
-
- g_assert (console);
+ g_return_if_fail (T_IS_CONNECTION (tcnc));
+ g_assert (global_t_app);
- if (cnc_name && ! connection_name_is_valid (cnc_name)) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
- _("Connection name '%s' is invalid"), cnc_name);
- return NULL;
- }
-
- GdaDsnInfo *info;
- gboolean need_user, need_pass, need_password_if_user;
- gchar *user, *pass, *real_cnc, *real_provider, *real_auth_string = NULL;
-
- /* if cnc string is a regular file, then use it with SQLite */
- if (g_file_test (cnc_string, G_FILE_TEST_IS_REGULAR)) {
- gchar *path, *file, *e1, *e2;
- const gchar *pname = "SQLite";
-
- path = g_path_get_dirname (cnc_string);
- file = g_path_get_basename (cnc_string);
- if (g_str_has_suffix (file, ".mdb")) {
- pname = "MSAccess";
- file [strlen (file) - 4] = 0;
- }
- else if (g_str_has_suffix (file, ".db"))
- file [strlen (file) - 3] = 0;
- e1 = gda_rfc1738_encode (path);
- e2 = gda_rfc1738_encode (file);
- g_free (path);
- g_free (file);
- real_cnc_string = g_strdup_printf ("%s://DB_DIR=%s;EXTRA_FUNCTIONS=TRUE;DB_NAME=%s", pname,
e1, e2);
- g_free (e1);
- g_free (e2);
- gda_connection_string_split (real_cnc_string, &real_cnc, &real_provider, &user, &pass);
- }
+ T_APP_LOCK (global_t_app);
+ if (g_slist_find (global_t_app->priv->tcnc_list, tcnc))
+ g_warning ("TConnection is already known to TApp!");
else {
- gda_connection_string_split (cnc_string, &real_cnc, &real_provider, &user, &pass);
- real_cnc_string = g_strdup (cnc_string);
+ global_t_app->priv->tcnc_list = g_slist_append (global_t_app->priv->tcnc_list, tcnc);
+ g_signal_connect (tcnc, "status-changed",
+ G_CALLBACK (conn_status_changed_cb), NULL);
+ g_signal_emit (global_t_app, t_app_signals[CNC_ADDED], 0, tcnc);
}
+ T_APP_UNLOCK (global_t_app);
+}
- info = gda_config_get_dsn_info (real_cnc);
- user_password_needed (info, real_provider, &need_user, &need_pass, &need_password_if_user);
-
- if (!real_cnc) {
- g_free (user);
- g_free (pass);
- g_free (real_provider);
- g_set_error (error, GDA_CONNECTION_ERROR, GDA_CONNECTION_DSN_NOT_FOUND_ERROR,
- _("Malformed connection string '%s'"), cnc_string);
- g_free (real_cnc_string);
- return NULL;
- }
+/**
+ * t_app_open_connections:
+ * @argc: the size of @argv
+ * @argv: an array of strings each representing a connection to open
+ * @error: a place to store errors, or %NULL
+ *
+ * Opens the connections:
+ * - listed in @argv
+ * - from the GDA_SQL_CNC environment variable
+ *
+ * Returns: %TRUE if all the connections have been opened
+ */
+gboolean
+t_app_open_connections (gint argc, const gchar *argv[], GError **error)
+{
+#ifdef HAVE_GTK_CLASSES
+ if (argc == 0) {
+ LoginDialog *dlg;
+ dlg = login_dialog_new (NULL);
+ TConnection *tcnc = NULL;
+ tcnc = login_dialog_run_open_connection (dlg, TRUE, error);
+ gtk_widget_destroy (GTK_WIDGET (dlg));
- if ((!user || !pass) && info && info->auth_string) {
- GdaQuarkList* ql;
- const gchar *tmp;
- ql = gda_quark_list_new_from_string (info->auth_string);
- if (!user) {
- tmp = gda_quark_list_find (ql, "USERNAME");
- if (tmp)
- user = g_strdup (tmp);
- }
- if (!pass) {
- tmp = gda_quark_list_find (ql, "PASSWORD");
- if (tmp)
- pass = g_strdup (tmp);
- }
- gda_quark_list_free (ql);
+ return tcnc ? TRUE : FALSE;
}
- if (need_user && ((user && !*user) || !user)) {
- gchar buf[80], *ptr;
- g_print (_("\tUsername for '%s': "), cnc_name);
- if (! fgets (buf, 80, stdin)) {
- g_free (real_cnc);
- g_free (user);
- g_free (pass);
- g_free (real_provider);
- g_set_error (error, GDA_CONNECTION_ERROR, GDA_CONNECTION_DSN_NOT_FOUND_ERROR,
- _("No username for '%s'"), cnc_string);
- g_free (real_cnc_string);
- return NULL;
- }
- for (ptr = buf; *ptr; ptr++) {
- if (*ptr == '\n') {
- *ptr = 0;
- break;
+ else {
+ AuthDialog *dlg;
+ dlg = auth_dialog_new (NULL);
+ gint i;
+ for (i = 0; i < argc; i++) {
+ if (! auth_dialog_add_cnc_string (AUTH_DIALOG (dlg), argv[i], error)) {
+ gtk_widget_destroy (GTK_WIDGET (dlg));
+ return FALSE;
}
}
- g_free (user);
- user = g_strdup (buf);
+ gboolean result;
+ result = auth_dialog_run (AUTH_DIALOG (dlg));
+ gtk_widget_destroy (GTK_WIDGET (dlg));
+ return result;
}
- if (user)
- need_pass = need_password_if_user;
- if (need_pass && ((pass && !*pass) || !pass)) {
- gchar *tmp;
- g_print (_("\tPassword for '%s': "), cnc_name);
- tmp = read_hidden_passwd ();
- g_print ("\n");
- if (! tmp) {
- g_free (real_cnc);
- g_free (user);
- g_free (pass);
- g_free (real_provider);
- g_set_error (error, GDA_CONNECTION_ERROR, GDA_CONNECTION_DSN_NOT_FOUND_ERROR,
- _("No password for '%s'"), cnc_string);
- g_free (real_cnc_string);
- return NULL;
- }
- g_free (pass);
- pass = tmp;
- }
-
- if (user || pass) {
- GString *string;
- string = g_string_new ("");
- if (user) {
- gchar *enc;
- enc = gda_rfc1738_encode (user);
- g_string_append_printf (string, "USERNAME=%s", enc);
- g_free (enc);
- }
- if (pass) {
- gchar *enc;
- enc = gda_rfc1738_encode (pass);
- if (user)
- g_string_append_c (string, ';');
- g_string_append_printf (string, "PASSWORD=%s", enc);
- g_free (enc);
- }
- real_auth_string = g_string_free (string, FALSE);
- }
-
- if (info && !real_provider)
- newcnc = gda_connection_open_from_dsn (real_cnc_string, real_auth_string,
- GDA_CONNECTION_OPTIONS_AUTO_META_DATA, error);
- else
- newcnc = gda_connection_open_from_string (NULL, real_cnc_string, real_auth_string,
- GDA_CONNECTION_OPTIONS_AUTO_META_DATA, error);
+#else
+ TContext *term_console;
+ FILE *ostream = NULL;
+ term_console = t_app_get_term_console ();
+ if (term_console)
+ ostream = t_context_get_output_stream (term_console, NULL);
- g_free (real_cnc_string);
- g_free (real_cnc);
- g_free (user);
- g_free (pass);
- g_free (real_provider);
- g_free (real_auth_string);
+ gint i;
+ for (i = 0; i < argc; i++) {
+ /* open connection */
+ TConnection *tcnc;
+ GdaDsnInfo *info = NULL;
+ gchar *str;
- if (newcnc) {
- gchar *dict_file_name = NULL;
- gchar *cnc_string;
- const gchar *rootname;
- gint i;
- g_object_set (G_OBJECT (newcnc), "execution-timer", TRUE, NULL);
- g_object_get (G_OBJECT (newcnc),
- "cnc-string", &cnc_string, NULL);
- dict_file_name = config_info_compute_dict_file_name (info, cnc_string);
- g_free (cnc_string);
-
- cs = g_new0 (ConnectionSetting, 1);
- if (cnc_name && *cnc_name)
- rootname = cnc_name;
+ /* Use argv[i] to open a connection */
+ info = gda_config_get_dsn_info (argv[i]);
+ if (info)
+ str = g_strdup (info->name);
else
- rootname = "c";
- if (gda_sql_get_connection (rootname)) {
- for (i = 0; ; i++) {
- gchar *tmp;
- tmp = g_strdup_printf ("%s%d", rootname, i);
- if (gda_sql_get_connection (tmp))
- g_free (tmp);
- else {
- cs->name = tmp;
- break;
- }
- }
+ str = g_strdup_printf ("c%d", i-1);
+ if (!ostream) {
+ gchar *params, *prov, *user;
+ gda_connection_string_split (argv[i], ¶ms, &prov, &user, NULL);
+ g_print (_("Opening connection '%s' for: "), str);
+ if (prov)
+ g_print ("%s://", prov);
+ if (user)
+ g_print ("%s@", user);
+ if (params)
+ g_print ("%s", params);
+ g_print ("\n");
+ g_free (params);
+ g_free (prov);
+ g_free (user);
}
+ tcnc = t_connection_open (str, argv[i], NULL, TRUE, error);
+ g_free (str);
+ if (tcnc)
+ t_context_set_connection (term_console, tcnc);
else
- cs->name = g_strdup (rootname);
- cs->parser = gda_connection_create_parser (newcnc);
- if (!cs->parser)
- cs->parser = gda_sql_parser_new ();
- cs->cnc = newcnc;
- cs->query_buffer = NULL;
- cs->threader = NULL;
- cs->meta_job_id = 0;
-
- main_data->settings = g_slist_append (main_data->settings, cs);
- console->current = cs;
-
- /* show date format */
- GDateDMY order[3];
- gchar sep;
- if (gda_connection_get_date_format (cs->cnc, &order[0], &order[1], &order[2], &sep, NULL)) {
- g_print (_("Date format for this connection will be: %s%c%s%c%s, where YYYY is the
year, MM the month and DD the day\n"),
- (order [0] == G_DATE_DAY) ? "DD" : ((order [0] == G_DATE_MONTH) ? "MM" :
"YYYY"), sep,
- (order [1] == G_DATE_DAY) ? "DD" : ((order [1] == G_DATE_MONTH) ? "MM" :
"YYYY"), sep,
- (order [2] == G_DATE_DAY) ? "DD" : ((order [2] == G_DATE_MONTH) ? "MM" :
"YYYY"));
- }
-
- /* dictionay related work */
- GdaMetaStore *store;
- gboolean update_store = FALSE;
-
- if (dict_file_name) {
- if (! g_file_test (dict_file_name, G_FILE_TEST_EXISTS))
- update_store = TRUE;
- store = gda_meta_store_new_with_file (dict_file_name);
- g_print (_("All the information related to the '%s' connection will be stored "
- "in the '%s' file\n"),
- cs->name, dict_file_name);
- }
- else {
- store = gda_meta_store_new (NULL);
- if (store)
- update_store = TRUE;
- }
-
- config_info_update_meta_store_properties (store, newcnc);
-
- g_object_set (G_OBJECT (cs->cnc), "meta-store", store, NULL);
- if (update_store) {
- GError *lerror = NULL;
-
- if (has_threads) {
- MetaUpdateData *thdata;
- cs->threader = (GdaThreader*) gda_threader_new ();
- thdata = g_new0 (MetaUpdateData, 1);
- thdata->cs = cs;
- thdata->cannot_lock = FALSE;
- cs->meta_job_id = gda_threader_start_thread (cs->threader,
- (GThreadFunc)
thread_start_update_meta_store,
- thdata,
- (GdaThreaderFunc)
thread_ok_cb_update_meta_store,
- (GdaThreaderFunc)
thread_cancelled_cb_update_meta_store,
- &lerror);
- if (cs->meta_job_id == 0) {
- if (!console->output_stream)
- g_print (_("Error getting meta data in background: %s\n"),
- lerror && lerror->message ? lerror->message : _("No
detail"));
- if (lerror)
- g_error_free (lerror);
- }
- }
- else {
- if (!console->output_stream) {
- g_print (_("Getting database schema information for connection '%s',
this may take some time... "),
- cs->name);
- fflush (stdout);
- }
-
- if (!gda_connection_update_meta_store (cs->cnc, NULL, &lerror)) {
- if (!console->output_stream)
- g_print (_("error: %s\n"),
- lerror && lerror->message ? lerror->message : _("No
detail"));
- if (lerror)
- g_error_free (lerror);
- }
- else
- if (!console->output_stream)
- g_print (_("Done.\n"));
- }
- }
- if (store)
- g_object_unref (store);
- g_free (dict_file_name);
- }
-
- if (cs) {
- g_signal_connect (cs->cnc, "conn-closed",
- G_CALLBACK (conn_closed_cb), NULL);
+ return FALSE;
}
- return cs;
+ return TRUE;
+#endif
}
-static void
-user_password_needed (GdaDsnInfo *info, const gchar *real_provider,
- gboolean *out_need_username, gboolean *out_need_password,
- gboolean *out_need_password_if_user)
+/**
+ * t_app_get_all_connections:
+ *
+ * This function is thread-safe.
+ *
+ * Returns: (transfer none) (element-type TConnection): a read-only list of all the #TConnection object
known to @self
+ */
+GSList *
+t_app_get_all_connections (void)
{
- GdaProviderInfo *pinfo = NULL;
- if (out_need_username)
- *out_need_username = FALSE;
- if (out_need_password)
- *out_need_password = FALSE;
- if (out_need_password_if_user)
- *out_need_password_if_user = FALSE;
-
- if (real_provider)
- pinfo = gda_config_get_provider_info (real_provider);
- else if (info)
- pinfo = gda_config_get_provider_info (info->provider);
-
- if (pinfo && pinfo->auth_params) {
- if (out_need_password) {
- GdaHolder *h;
- h = gda_set_get_holder (pinfo->auth_params, "PASSWORD");
- if (h && gda_holder_get_not_null (h))
- *out_need_password = TRUE;
- }
- if (out_need_username) {
- GdaHolder *h;
- h = gda_set_get_holder (pinfo->auth_params, "USERNAME");
- if (h && gda_holder_get_not_null (h))
- *out_need_username = TRUE;
- }
- if (out_need_password_if_user) {
- if (gda_set_get_holder (pinfo->auth_params, "PASSWORD") &&
- gda_set_get_holder (pinfo->auth_params, "USERNAME"))
- *out_need_password_if_user = TRUE;
- }
- }
+ g_assert (global_t_app);
+
+ GSList *retlist;
+ T_APP_LOCK (global_t_app);
+ retlist = global_t_app->priv->tcnc_list;
+ T_APP_UNLOCK (global_t_app);
+ return retlist;
}
-static gchar*
-read_hidden_passwd (void)
+static void
+model_connection_added_cb (G_GNUC_UNUSED TApp *tapp, TConnection *tcnc, GdaDataModel *model)
{
- gchar *p, password [100];
-
-#ifdef HAVE_TERMIOS_H
- int fail;
- struct termios termio;
-
- fail = tcgetattr (0, &termio);
- if (fail)
- return NULL;
-
- termio.c_lflag &= ~ECHO;
- fail = tcsetattr (0, TCSANOW, &termio);
- if (fail)
- return NULL;
-#else
-#ifdef G_OS_WIN32
- HANDLE t = NULL;
- LPDWORD t_orig = NULL;
-
- /* get a new handle to turn echo off */
- t_orig = (LPDWORD) malloc (sizeof (DWORD));
- t = GetStdHandle (STD_INPUT_HANDLE);
-
- /* save the old configuration first */
- GetConsoleMode (t, t_orig);
-
- /* set to the new mode */
- SetConsoleMode (t, ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT);
-#endif
-#endif
-
- p = fgets (password, sizeof (password) - 1, stdin);
-
-#ifdef HAVE_TERMIOS_H
- termio.c_lflag |= ECHO;
- tcsetattr (0, TCSANOW, &termio);
-#else
-#ifdef G_OS_WIN32
- SetConsoleMode (t, *t_orig);
- fflush (stdout);
- free (t_orig);
-#endif
-#endif
+ GList *values;
+ GValue *value;
- if (!p)
- return NULL;
+ g_value_set_string ((value = gda_value_new (G_TYPE_STRING)), t_connection_get_name (tcnc));
+ values = g_list_prepend (NULL, value);
+ g_value_set_object ((value = gda_value_new (T_TYPE_CONNECTION)), tcnc);
+ values = g_list_prepend (values, value);
- for (p = password; *p; p++) {
- if (*p == '\n') {
- *p = 0;
- break;
- }
- }
- p = g_strdup (password);
- memset (password, 0, sizeof (password));
+ g_assert (gda_data_model_append_values (model, values, NULL) >= 0);
- return p;
+ g_list_foreach (values, (GFunc) gda_value_free, NULL);
+ g_list_free (values);
}
-static gpointer
-thread_start_update_meta_store (MetaUpdateData *data)
+static void
+model_connection_removed_cb (G_GNUC_UNUSED TApp *tapp, TConnection *tcnc, GdaDataModel *model)
{
- /* test if the connection can be locked, which means that multiple threads can access it at the same
time.
- * If that is not possible, then quit the thread while positionning data->cannot_lock to TRUE so the
- * meta data update can be done while back in the main thread */
- if (gda_lockable_trylock (GDA_LOCKABLE (data->cs->cnc))) {
- gda_lockable_unlock (GDA_LOCKABLE (data->cs->cnc));
- data->result = gda_connection_update_meta_store (data->cs->cnc, NULL, &(data->error));
+ gint i, nrows;
+ nrows = gda_data_model_get_n_rows (model);
+ for (i = 0; i < nrows; i++) {
+ const GValue *value;
+ value = gda_data_model_get_value_at (model, 0, i, NULL);
+ g_assert (value);
+ if (g_value_get_object (value) == tcnc) {
+ g_assert (gda_data_model_remove_row (model, i, NULL));
+ break;
+ }
}
- else
- data->cannot_lock = TRUE;
- return NULL;
}
-
-static void
-thread_ok_cb_update_meta_store (G_GNUC_UNUSED GdaThreader *threader, G_GNUC_UNUSED guint job, MetaUpdateData
*data)
+/**
+ * t_app_get_all_connections_m:
+ *
+ * Creates a #GdaDataModel with 2 columns: T_TYPE_CONNECTION (#TConnection) and G_TYPE_STRING (connection's
name)
+ *
+ * Returns: (transfer none): a #GdaDataModel
+ */
+GdaDataModel *
+t_app_get_all_connections_m (void)
{
- data->cs->meta_job_id = 0;
- if (data->cannot_lock) {
- GError *lerror = NULL;
- if (!main_data->term_console->output_stream) {
- g_print (_("Getting database schema information for connection '%s', this may take
some time... "),
- data->cs->name);
- fflush (stdout);
- }
+ static GdaDataModel *model = NULL;
+ if (!model) {
+ model = gda_data_model_array_new_with_g_types (2,
+ T_TYPE_CONNECTION,
+ G_TYPE_STRING);
+ /* initial filling */
+ GSList *list;
+ for (list = t_app_get_all_connections (); list; list = list->next)
+ model_connection_added_cb (t_app_get(), T_CONNECTION (list->data), model);
- if (!gda_connection_update_meta_store (data->cs->cnc, NULL, &lerror)) {
- if (!main_data->term_console->output_stream)
- g_print (_("error: %s\n"),
- lerror && lerror->message ? lerror->message : _("No detail"));
- if (lerror)
- g_error_free (lerror);
- }
- else
- if (!main_data->term_console->output_stream)
- g_print (_("Done.\n"));
+ g_signal_connect (t_app_get (), "connection-added",
+ G_CALLBACK (model_connection_added_cb), model);
+ g_signal_connect (t_app_get (), "connection-removed",
+ G_CALLBACK (model_connection_removed_cb), model);
}
- if (data->error)
- g_error_free (data->error);
- g_free (data);
+ return model;
}
-static void
-thread_cancelled_cb_update_meta_store (G_GNUC_UNUSED GdaThreader *threader, G_GNUC_UNUSED guint job,
- MetaUpdateData *data)
+/**
+ * t_app_get_term_console:
+ *
+ * Returns: the term console, or %NULL if no term console exists
+ */
+TContext *
+t_app_get_term_console (void)
{
- data->cs->meta_job_id = 0;
- if (data->error)
- g_error_free (data->error);
- g_free (data);
+ g_assert (global_t_app);
+ return global_t_app->priv->term_console;
}
-/* free the connection settings */
-static void
-connection_settings_free (ConnectionSetting *cs)
+/**
+ * t_app_get_options:
+ *
+ * Returns: (transfer none): the options #GdaSet
+ */
+GdaSet *
+t_app_get_options (void)
{
- g_free (cs->name);
- if (cs->cnc) {
- g_signal_handlers_disconnect_by_func (cs->cnc,
- G_CALLBACK (conn_closed_cb), NULL);
- g_object_unref (cs->cnc);
- }
- if (cs->parser)
- g_object_unref (cs->parser);
- if (cs->query_buffer)
- g_string_free (cs->query_buffer, TRUE);
- if (cs->threader) {
- if (cs->meta_job_id)
- gda_threader_cancel (cs->threader, cs->meta_job_id);
- g_object_unref (cs->threader);
- }
- g_free (cs);
+ g_assert (global_t_app);
+ return global_t_app->priv->options;
}
-/*
- * Dumps the data model contents onto @data->output
+/**
+ * t_app_store_data_model:
+ * @model: (transfer none): a #GdaDataModel
+ * @name: (transfer none): the name to store it as
+ *
+ * Stores a #GdaDataModel, indexing it as @name
+ * If a data model with the same name already exists, then it is first removed
*/
-static void
-output_data_model (GdaDataModel *model)
+void
+t_app_store_data_model (GdaDataModel *model, const gchar *name)
{
- gchar *str;
- str = data_model_to_string (main_data->term_console, model);
- output_string (str);
- g_free (str);
+ g_assert (global_t_app);
+ g_return_if_fail (GDA_IS_DATA_MODEL (model));
+ g_return_if_fail (name && *name);
+
+ g_hash_table_insert (global_t_app->priv->mem_data_models, g_strdup (name), g_object_ref (model));
}
-static GdaSet *
-make_options_set_from_gdasql_options (const gchar *context)
+/**
+ * t_app_fetch_data_model:
+ * @name: a name
+ *
+ * Retreives a data model previously stored using t_app_store_data_model()
+ *
+ * Returns: (transfer none): the #GdaDataModel, or %NULL if not found
+ */
+GdaDataModel *
+t_app_fetch_data_model (const gchar *name)
{
- GdaSet *expopt = NULL;
- GSList *list, *nlist = NULL;
- for (list = main_data->options->holders; list; list = list->next) {
- GdaHolder *param = GDA_HOLDER (list->data);
- const GValue *cvalue;
- cvalue = gda_holder_get_attribute (param, context);
- if (!cvalue)
- continue;
+ g_assert (global_t_app);
+ g_return_val_if_fail (name && *name, NULL);
- GdaHolder *nparam;
- const GValue *cvalue2;
- cvalue2 = gda_holder_get_value (param);
- nparam = gda_holder_new (G_VALUE_TYPE (cvalue2));
- g_object_set ((GObject*) nparam, "id", g_value_get_string (cvalue), NULL);
- g_assert (gda_holder_set_value (nparam, cvalue2, NULL));
- nlist = g_slist_append (nlist, nparam);
- }
- if (nlist) {
- expopt = gda_set_new (nlist);
- g_slist_free (nlist);
- }
- return expopt;
+ return g_hash_table_lookup (global_t_app->priv->mem_data_models, name);
}
-static gchar *
-data_model_to_string (SqlConsole *console, GdaDataModel *model)
+/*
+ * _t_app_add_context:
+ * @console: (transfer full):
+ */
+void
+_t_app_add_context (TContext *console)
{
- static gboolean env_set = FALSE;
- ToolOutputFormat of;
-
- g_assert (console);
- if (!GDA_IS_DATA_MODEL (model))
- return NULL;
-
- g_hash_table_insert (main_data->mem_data_models, g_strdup (LAST_DATA_MODEL_NAME), g_object_ref
(model));
-
- if (!env_set) {
- if (! getenv ("GDA_DATA_MODEL_DUMP_TITLE"))
- g_setenv ("GDA_DATA_MODEL_DUMP_TITLE", "Yes", TRUE);
- if (! getenv ("GDA_DATA_MODEL_NULL_AS_EMPTY"))
- g_setenv ("GDA_DATA_MODEL_NULL_AS_EMPTY", "Yes", TRUE);
- if (! console->output_stream || isatty (fileno (console->output_stream))) {
- if (! getenv ("GDA_DATA_MODEL_DUMP_TRUNCATE"))
- g_setenv ("GDA_DATA_MODEL_DUMP_TRUNCATE", "-1", TRUE);
- }
- env_set = TRUE;
- }
-
- of = console->output_format;
- if (of & TOOL_OUTPUT_FORMAT_DEFAULT) {
- gchar *tmp;
- GdaSet *options;
- options = gda_set_new_inline (1, "MAX_WIDTH", G_TYPE_INT, -1);
- tmp = gda_data_model_export_to_string (model, GDA_DATA_MODEL_IO_TEXT_TABLE, NULL, 0, NULL, 0,
options);
- g_object_unref (options);
- if (GDA_IS_DATA_SELECT (model)) {
- gchar *tmp2, *tmp3;
- gdouble etime;
- g_object_get ((GObject*) model, "execution-delay", &etime, NULL);
- tmp2 = g_strdup_printf ("%s: %.03f s", _("Execution delay"), etime);
- tmp3 = g_strdup_printf ("%s\n%s", tmp, tmp2);
- g_free (tmp);
- g_free (tmp2);
- return tmp3;
- }
- else
- return tmp;
- }
- else if (of & TOOL_OUTPUT_FORMAT_XML)
- return gda_data_model_export_to_string (model, GDA_DATA_MODEL_IO_DATA_ARRAY_XML,
- NULL, 0,
- NULL, 0, NULL);
- else if (of & TOOL_OUTPUT_FORMAT_CSV) {
- gchar *retval;
- GdaSet *optexp;
- optexp = make_options_set_from_gdasql_options ("csv");
- retval = gda_data_model_export_to_string (model, GDA_DATA_MODEL_IO_TEXT_SEPARATED,
- NULL, 0,
- NULL, 0, optexp);
- if (optexp)
- g_object_unref (optexp);
- return retval;
- }
- else if (of & TOOL_OUTPUT_FORMAT_HTML) {
- xmlBufferPtr buffer;
- xmlNodePtr top, div, table, node, row_node, col_node, header, meta;
- gint ncols, nrows, i, j;
- gchar *str;
-
- top = xmlNewNode (NULL, BAD_CAST "html");
- header = xmlNewChild (top, NULL, BAD_CAST "head", NULL);
- meta = xmlNewChild (header, NULL, BAD_CAST "meta", NULL);
- xmlSetProp (meta, BAD_CAST "http-equiv", BAD_CAST "content-type");
- xmlSetProp (meta, BAD_CAST "content", BAD_CAST "text/html; charset=UTF-8");
- div = xmlNewChild (top, NULL, BAD_CAST "body", NULL);
- table = xmlNewChild (div, NULL, BAD_CAST "table", NULL);
- xmlSetProp (table, BAD_CAST "border", BAD_CAST "1");
-
- if (g_object_get_data (G_OBJECT (model), "name"))
- xmlNewTextChild (table, NULL, BAD_CAST "caption", g_object_get_data (G_OBJECT
(model), "name"));
-
- ncols = gda_data_model_get_n_columns (model);
- nrows = gda_data_model_get_n_rows (model);
-
- row_node = xmlNewChild (table, NULL, BAD_CAST "tr", NULL);
- for (j = 0; j < ncols; j++) {
- const gchar *cstr;
- cstr = gda_data_model_get_column_title (model, j);
- col_node = xmlNewTextChild (row_node, NULL, BAD_CAST "th", BAD_CAST cstr);
- xmlSetProp (col_node, BAD_CAST "align", BAD_CAST "center");
- }
-
- for (i = 0; i < nrows; i++) {
- row_node = xmlNewChild (table, NULL, BAD_CAST "tr", NULL);
- xmlSetProp (row_node, BAD_CAST "valign", BAD_CAST "top");
- for (j = 0; j < ncols; j++) {
- const GValue *value;
- value = gda_data_model_get_value_at (model, j, i, NULL);
- if (!value) {
- col_node = xmlNewChild (row_node, NULL, BAD_CAST "td", BAD_CAST
"ERROR");
- xmlSetProp (col_node, BAD_CAST "align", BAD_CAST "left");
- }
- else {
- str = gda_value_stringify (value);
- col_node = xmlNewTextChild (row_node, NULL, BAD_CAST "td", BAD_CAST
str);
- xmlSetProp (col_node, BAD_CAST "align", BAD_CAST "left");
- g_free (str);
- }
- }
- }
-
- node = xmlNewChild (div, NULL, BAD_CAST "p", NULL);
- str = g_strdup_printf (ngettext ("(%d row)", "(%d rows)", nrows), nrows);
- xmlNodeSetContent (node, BAD_CAST str);
- g_free (str);
+ g_assert (global_t_app);
+ g_return_if_fail (console);
- buffer = xmlBufferCreate ();
- xmlNodeDump (buffer, NULL, top, 0, 1);
- str = g_strdup ((gchar *) xmlBufferContent (buffer));
- xmlBufferFree (buffer);
- xmlFreeNode (top);
- return str;
- }
+ T_APP_LOCK (global_t_app);
+ if (g_slist_find (global_t_app->priv->tcontext_list, console))
+ g_warning ("TContext is already known to TApp!");
else
- TO_IMPLEMENT;
-
- return NULL;
+ global_t_app->priv->tcontext_list = g_slist_append (global_t_app->priv->tcontext_list,
console);
+ T_APP_UNLOCK (global_t_app);
}
-static void
-output_string (const gchar *str)
+void
+_t_app_remove_context (TContext *console)
{
- FILE *to_stream;
- gboolean append_nl = FALSE;
- gint length;
- static gint force_no_pager = -1;
-
- if (!str)
- return;
-
- if (force_no_pager < 0) {
- /* still unset... */
- if (getenv (TOOL_NO_PAGER))
- force_no_pager = 1;
- else
- force_no_pager = 0;
- }
+ g_assert (global_t_app);
+ g_return_if_fail (console);
- length = strlen (str);
- if (*str && (str[length - 1] != '\n'))
- append_nl = TRUE;
-
- if (main_data->term_console->output_stream)
- to_stream = main_data->term_console->output_stream;
+ T_APP_LOCK (global_t_app);
+ if (!g_slist_find (global_t_app->priv->tcontext_list, console))
+ g_warning ("TContext is not known to TApp!");
else
- to_stream = stdout;
+ global_t_app->priv->tcontext_list = g_slist_remove (global_t_app->priv->tcontext_list,
console);
+ T_APP_UNLOCK (global_t_app);
+}
- if (!force_no_pager && isatty (fileno (to_stream))) {
- /* use pager */
- FILE *pipe;
- const char *pager;
-#ifndef G_OS_WIN32
- sighandler_t phandler;
-#endif
- pager = getenv ("PAGER");
- if (!pager)
- pager = "more";
- if (!check_shell_argument (pager)) {
- g_warning ("Invalid PAGER value: must only contain alphanumeric characters");
- return;
- }
- else
- pipe = popen (pager, "w");
-#ifndef G_OS_WIN32
- phandler = signal (SIGPIPE, SIG_IGN);
-#endif
- if (append_nl)
- g_fprintf (pipe, "%s\n", str);
- else
- g_fprintf (pipe, "%s", str);
- pclose (pipe);
-#ifndef G_OS_WIN32
- signal (SIGPIPE, phandler);
-#endif
- }
- else {
- if (append_nl)
- g_fprintf (to_stream, "%s\n", str);
- else
- g_fprintf (to_stream, "%s", str);
+/**
+ * t_app_get_parameter:
+ * @name: the name of the parameter requested
+ *
+ * Get the #GValue of a parameter
+ *
+ * Returns: (transfer full): a new #GValue, or %NULL if the parameter has not been found
+ */
+GValue *
+t_app_get_parameter_value (const gchar *name)
+{
+ g_assert (global_t_app);
+ g_return_val_if_fail (name, NULL);
+
+ T_APP_LOCK (global_t_app);
+ GdaHolder *h;
+ GValue *value = NULL;
+ h = g_hash_table_lookup (global_t_app->priv->parameters, name);
+ if (h) {
+ const GValue *cvalue;
+ cvalue = gda_holder_get_value (h);
+ if (cvalue)
+ value = gda_value_copy (cvalue);
}
+ T_APP_UNLOCK (global_t_app);
+ return value;
}
+static ToolCommandResult *gda_internal_command_history (ToolCommand *command, guint argc, const gchar **argv,
+ TContext *console, GError **error);
+static ToolCommandResult *gda_internal_command_dict_sync (ToolCommand *command, guint argc, const gchar
**argv,
+ TContext *console, GError **error);
+static ToolCommandResult *gda_internal_command_list_tables (ToolCommand *command, guint argc, const gchar
**argv,
+ TContext *console, GError **error);
+static ToolCommandResult *gda_internal_command_list_views (ToolCommand *command, guint argc, const gchar
**argv,
+ TContext *console, GError **error);
+static ToolCommandResult *gda_internal_command_list_schemas (ToolCommand *command, guint argc, const gchar
**argv,
+ TContext *console, GError **error);
+static ToolCommandResult *gda_internal_command_detail (ToolCommand *command, guint argc, const gchar **argv,
+ TContext *console, GError **error);
+
static ToolCommandResult *extra_command_copyright (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error);
+ TContext *console, GError **error);
static ToolCommandResult *extra_command_option (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error);
+ TContext *console, GError **error);
static ToolCommandResult *extra_command_quit (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error);
+ TContext *console, GError **error);
static ToolCommandResult *extra_command_cd (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error);
+ TContext *console, GError **error);
static ToolCommandResult *extra_command_set_output (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error);
+ TContext *console, GError **error);
static ToolCommandResult *extra_command_set_output_format (ToolCommand *command, guint argc, const gchar
**argv,
- SqlConsole *console, GError **error);
+ TContext *console, GError **error);
static ToolCommandResult *extra_command_set_input (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error);
+ TContext *console, GError **error);
static ToolCommandResult *extra_command_echo (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error);
+ TContext *console, GError **error);
static ToolCommandResult *extra_command_qecho (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error);
+ TContext *console, GError **error);
static ToolCommandResult *extra_command_list_dsn (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error);
+ TContext *console, GError **error);
static ToolCommandResult *extra_command_create_dsn (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error);
+ TContext *console, GError **error);
static ToolCommandResult *extra_command_remove_dsn (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error);
+ TContext *console, GError **error);
static ToolCommandResult *extra_command_list_providers (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error);
+ TContext *console, GError **error);
static ToolCommandResult *extra_command_manage_cnc (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error);
-static gchar **extra_command_manage_cnc_compl (const gchar *text);
+ TContext *console, GError **error);
+static gchar **extra_command_manage_cnc_compl (const gchar *text, gpointer user_data);
static ToolCommandResult *extra_command_close_cnc (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error);
+ TContext *console, GError **error);
static ToolCommandResult *extra_command_bind_cnc (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error);
+ TContext *console, GError **error);
static ToolCommandResult *extra_command_edit_buffer (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error);
+ TContext *console, GError **error);
static ToolCommandResult *extra_command_reset_buffer (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error);
+ TContext *console, GError **error);
static ToolCommandResult *extra_command_show_buffer (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error);
+ TContext *console, GError **error);
static ToolCommandResult *extra_command_exec_buffer (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error);
+ TContext *console, GError **error);
static ToolCommandResult *extra_command_write_buffer (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error);
+ TContext *console, GError **error);
static ToolCommandResult *extra_command_query_buffer_to_dict (ToolCommand *command, guint argc, const gchar
**argv,
- SqlConsole *console, GError **error);
+ TContext *console, GError **error);
static ToolCommandResult *extra_command_query_buffer_from_dict (ToolCommand *command, guint argc, const
gchar **argv,
- SqlConsole *console, GError **error);
+ TContext *console, GError **error);
static ToolCommandResult *extra_command_query_buffer_list_dict (ToolCommand *command, guint argc, const
gchar **argv,
- SqlConsole *console, GError **error);
+ TContext *console, GError **error);
static ToolCommandResult *extra_command_query_buffer_delete_dict (ToolCommand *command, guint argc, const
gchar **argv,
- SqlConsole *console, GError **error);
+ TContext *console, GError **error);
static ToolCommandResult *extra_command_set (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error);
+ TContext *console, GError **error);
static ToolCommandResult *extra_command_unset (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error);
+ TContext *console, GError **error);
static ToolCommandResult *extra_command_data_sets_list (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error);
+ TContext *console, GError **error);
static ToolCommandResult *extra_command_data_set_move (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error);
+ TContext *console, GError **error);
static ToolCommandResult *extra_command_data_set_grep (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error);
+ TContext *console, GError **error);
static ToolCommandResult *extra_command_data_set_show (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error);
+ TContext *console, GError **error);
static ToolCommandResult *extra_command_data_set_rm (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error);
+ TContext *console, GError **error);
static ToolCommandResult *extra_command_data_set_import (ToolCommand *command, guint argc, const gchar
**argv,
- SqlConsole *console, GError **error);
+ TContext *console, GError **error);
static ToolCommandResult *extra_command_graph (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error);
+ TContext *console, GError **error);
#ifdef HAVE_LIBSOUP
static ToolCommandResult *extra_command_httpd (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error);
+ TContext *console, GError **error);
#endif
#ifdef NONE
static ToolCommandResult *extra_command_lo_update (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error);
+ TContext *console, GError **error);
#endif
static ToolCommandResult *extra_command_export (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error);
+ TContext *console, GError **error);
static ToolCommandResult *extra_command_set2 (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error);
+ TContext *console, GError **error);
static ToolCommandResult *extra_command_pivot (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error);
+ TContext *console, GError **error);
static ToolCommandResult *extra_command_declare_fk (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error);
+ TContext *console, GError **error);
static ToolCommandResult *extra_command_undeclare_fk (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error);
+ TContext *console, GError **error);
#ifdef HAVE_LDAP
static ToolCommandResult *extra_command_ldap_search (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error);
+ TContext *console, GError **error);
static ToolCommandResult *extra_command_ldap_descr (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error);
+ TContext *console, GError **error);
static ToolCommandResult *extra_command_ldap_mv (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error);
+ TContext *console, GError **error);
static ToolCommandResult *extra_command_ldap_mod (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error);
+ TContext *console, GError **error);
#endif
+/*
+ * Rem: there is a @self to allow TApp's reinitialization
+ */
static void
-build_commands (MainData *md)
+build_commands (TApp *self, TAppFeatures features)
{
- md->limit_commands = tool_command_group_new ();
- md->all_commands = tool_command_group_new ();
+ g_assert (self);
+#ifdef HAVE_LIBSOUP
+ self->web_commands = base_tool_command_group_new ();
+#endif
+ self->term_commands = base_tool_command_group_new ();
ToolCommand *c;
@@ -2006,8 +939,8 @@ build_commands (MainData *md)
c->group_id = NULL;
c->name = g_strdup_printf (_("%s [<FILE>]"), "s");
c->description = _("Show commands history, or save it to file");
- c->command_func = (ToolCommandFunc) gda_internal_command_history;
- tool_command_group_add (md->all_commands, c);
+ c->command_func = (ToolCommandFunc) gda_internal_command_history; /* only for term console */
+ base_tool_command_group_add (self->term_commands, c);
c = g_new0 (ToolCommand, 1);
c->group = _("Information");
@@ -2015,8 +948,10 @@ build_commands (MainData *md)
c->name = g_strdup_printf (_("%s [<META DATA TYPE>]"), "meta");
c->description = _("Force reading the database meta data (or part of the meta data, ex:\"tables\")");
c->command_func = (ToolCommandFunc) gda_internal_command_dict_sync;
- tool_command_group_add (md->limit_commands, c);
- tool_command_group_add (md->all_commands, c);
+#ifdef HAVE_LIBSOUP
+ base_tool_command_group_add (self->web_commands, c);
+#endif
+ base_tool_command_group_add (self->term_commands, c);
c = g_new0 (ToolCommand, 1);
c->group = _("Information");
@@ -2024,8 +959,10 @@ build_commands (MainData *md)
c->name = g_strdup_printf (_("%s <fkname> <tableA>(<colA>,...) <tableB>(<colB>,...)"), "fkdeclare");
c->description = _("Declare a new foreign key (not actually in database): tableA references tableB");
c->command_func = (ToolCommandFunc) extra_command_declare_fk;
- tool_command_group_add (md->limit_commands, c);
- tool_command_group_add (md->all_commands, c);
+#ifdef HAVE_LIBSOUP
+ base_tool_command_group_add (self->web_commands, c);
+#endif
+ base_tool_command_group_add (self->term_commands, c);
c = g_new0 (ToolCommand, 1);
c->group = _("Information");
@@ -2033,8 +970,10 @@ build_commands (MainData *md)
c->name = g_strdup_printf (_("%s <fkname> <tableA> <tableB>"), "fkundeclare");
c->description = _("Un-declare a foreign key (not actually in database)");
c->command_func = (ToolCommandFunc) extra_command_undeclare_fk;
- tool_command_group_add (md->limit_commands, c);
- tool_command_group_add (md->all_commands, c);
+#ifdef HAVE_LIBSOUP
+ base_tool_command_group_add (self->web_commands, c);
+#endif
+ base_tool_command_group_add (self->term_commands, c);
c = g_new0 (ToolCommand, 1);
c->group = _("Information");
@@ -2042,8 +981,10 @@ build_commands (MainData *md)
c->name = g_strdup_printf (_("%s [<TABLE>]"), "dt");
c->description = _("List all tables (or named table)");
c->command_func = (ToolCommandFunc) gda_internal_command_list_tables;
- tool_command_group_add (md->limit_commands, c);
- tool_command_group_add (md->all_commands, c);
+#ifdef HAVE_LIBSOUP
+ base_tool_command_group_add (self->web_commands, c);
+#endif
+ base_tool_command_group_add (self->term_commands, c);
c = g_new0 (ToolCommand, 1);
c->group = _("Information");
@@ -2051,8 +992,10 @@ build_commands (MainData *md)
c->name = g_strdup_printf (_("%s [<VIEW>]"), "dv");
c->description = _("List all views (or named view)");
c->command_func = (ToolCommandFunc) gda_internal_command_list_views;
- tool_command_group_add (md->limit_commands, c);
- tool_command_group_add (md->all_commands, c);
+#ifdef HAVE_LIBSOUP
+ base_tool_command_group_add (self->web_commands, c);
+#endif
+ base_tool_command_group_add (self->term_commands, c);
c = g_new0 (ToolCommand, 1);
c->group = _("Information");
@@ -2060,8 +1003,10 @@ build_commands (MainData *md)
c->name = g_strdup_printf (_("%s [<SCHEMA>]"), "dn");
c->description = _("List all schemas (or named schema)");
c->command_func = (ToolCommandFunc) gda_internal_command_list_schemas;
- tool_command_group_add (md->limit_commands, c);
- tool_command_group_add (md->all_commands, c);
+#ifdef HAVE_LIBSOUP
+ base_tool_command_group_add (self->web_commands, c);
+#endif
+ base_tool_command_group_add (self->term_commands, c);
c = g_new0 (ToolCommand, 1);
c->group = _("Information");
@@ -2069,16 +1014,18 @@ build_commands (MainData *md)
c->name = g_strdup_printf (_("%s [<OBJ_NAME>|<SCHEMA>.*]"), "d");
c->description = _("Describe object or full list of objects");
c->command_func = (ToolCommandFunc) gda_internal_command_detail;
- tool_command_group_add (md->limit_commands, c);
- tool_command_group_add (md->all_commands, c);
+#ifdef HAVE_LIBSOUP
+ base_tool_command_group_add (self->web_commands, c);
+#endif
+ base_tool_command_group_add (self->term_commands, c);
c = g_new0 (ToolCommand, 1);
c->group = _("Information");
c->group_id = NULL;
c->name = g_strdup_printf (_("%s [<TABLE1> [<TABLE2>...]]"), "graph");
c->description = _("Create a graph of all or the listed tables");
- c->command_func = (ToolCommandFunc) extra_command_graph;
- tool_command_group_add (md->all_commands, c);
+ c->command_func = (ToolCommandFunc) extra_command_graph; /* only for term console */
+ base_tool_command_group_add (self->term_commands, c);
#ifdef HAVE_LIBSOUP
c = g_new0 (ToolCommand, 1);
@@ -2087,7 +1034,7 @@ build_commands (MainData *md)
c->name = g_strdup_printf (_("%s [<port> [<authentication token>]]"), "http");
c->description = _("Start/stop embedded HTTP server (on given port or on 12345 by default)");
c->command_func = (ToolCommandFunc) extra_command_httpd;
- tool_command_group_add (md->all_commands, c);
+ base_tool_command_group_add (self->term_commands, c);
#endif
/* specific commands */
@@ -2098,8 +1045,11 @@ build_commands (MainData *md)
c->description = _("Opens a new connection or lists opened connections");
c->command_func = (ToolCommandFunc) extra_command_manage_cnc;
c->completion_func = extra_command_manage_cnc_compl;
- tool_command_group_add (md->limit_commands, c);
- tool_command_group_add (md->all_commands, c);
+ c->completion_func_data = self;
+#ifdef HAVE_LIBSOUP
+ base_tool_command_group_add (self->web_commands, c);
+#endif
+ base_tool_command_group_add (self->term_commands, c);
c = g_new0 (ToolCommand, 1);
c->group = _("General");
@@ -2107,8 +1057,10 @@ build_commands (MainData *md)
c->name = g_strdup_printf (_("%s [<CNC_NAME>]"), "close");
c->description = _("Close a connection");
c->command_func = (ToolCommandFunc) extra_command_close_cnc;
- tool_command_group_add (md->limit_commands, c);
- tool_command_group_add (md->all_commands, c);
+#ifdef HAVE_LIBSOUP
+ base_tool_command_group_add (self->web_commands, c);
+#endif
+ base_tool_command_group_add (self->term_commands, c);
c = g_new0 (ToolCommand, 1);
c->group = _("General");
@@ -2116,8 +1068,10 @@ build_commands (MainData *md)
c->name = g_strdup_printf (_("%s <CNC NAME> <OBJ NAME> [<OBJ NAME> ...]"), "bind");
c->description = _("Bind connections or datasets (<OBJ NAME>) into a single new one (allowing SQL
commands to be executed across multiple connections and/or datasets)");
c->command_func = (ToolCommandFunc) extra_command_bind_cnc;
- tool_command_group_add (md->limit_commands, c);
- tool_command_group_add (md->all_commands, c);
+#ifdef HAVE_LIBSOUP
+ base_tool_command_group_add (self->web_commands, c);
+#endif
+ base_tool_command_group_add (self->term_commands, c);
c = g_new0 (ToolCommand, 1);
c->group = _("DSN (data sources) management");
@@ -2125,8 +1079,10 @@ build_commands (MainData *md)
c->name = g_strdup_printf (_("%s [<DSN>]"), "l");
c->description = _("List all DSN (or named DSN's attributes)");
c->command_func = (ToolCommandFunc) extra_command_list_dsn;
- tool_command_group_add (md->limit_commands, c);
- tool_command_group_add (md->all_commands, c);
+#ifdef HAVE_LIBSOUP
+ base_tool_command_group_add (self->web_commands, c);
+#endif
+ base_tool_command_group_add (self->term_commands, c);
c = g_new0 (ToolCommand, 1);
c->group = _("DSN (data sources) management");
@@ -2134,8 +1090,10 @@ build_commands (MainData *md)
c->name = g_strdup_printf (_("%s <DSN_NAME> <DSN_DEFINITION> [<DESCRIPTION>]"), "lc");
c->description = _("Create (or modify) a DSN");
c->command_func = (ToolCommandFunc) extra_command_create_dsn;
- tool_command_group_add (md->limit_commands, c);
- tool_command_group_add (md->all_commands, c);
+#ifdef HAVE_LIBSOUP
+ base_tool_command_group_add (self->web_commands, c);
+#endif
+ base_tool_command_group_add (self->term_commands, c);
c = g_new0 (ToolCommand, 1);
c->group = _("DSN (data sources) management");
@@ -2143,33 +1101,37 @@ build_commands (MainData *md)
c->name = g_strdup_printf (_("%s <DSN_NAME> [<DSN_NAME>...]"), "lr");
c->description = _("Remove a DSN");
c->command_func = (ToolCommandFunc) extra_command_remove_dsn;
- tool_command_group_add (md->limit_commands, c);
- tool_command_group_add (md->all_commands, c);
+#ifdef HAVE_LIBSOUP
+ base_tool_command_group_add (self->web_commands, c);
+#endif
+ base_tool_command_group_add (self->term_commands, c);
c = g_new0 (ToolCommand, 1);
c->group = _("DSN (data sources) management");
c->group_id = NULL;
- c->name = g_strdup_printf (_("%s [<PROVIDER>]"), "lp");
+ c->name = g_strdup_printf (_("%s [<PROVIDER>]"), "L");
c->description = _("List all installed database providers (or named one's attributes)");
c->command_func = (ToolCommandFunc) extra_command_list_providers;
- tool_command_group_add (md->limit_commands, c);
- tool_command_group_add (md->all_commands, c);
+#ifdef HAVE_LIBSOUP
+ base_tool_command_group_add (self->web_commands, c);
+#endif
+ base_tool_command_group_add (self->term_commands, c);
c = g_new0 (ToolCommand, 1);
c->group = _("Input/Output");
c->group_id = NULL;
c->name = g_strdup_printf (_("%s <FILE>"), "i");
c->description = _("Execute commands from file");
- c->command_func = (ToolCommandFunc) extra_command_set_input;
- tool_command_group_add (md->all_commands, c);
+ c->command_func = (ToolCommandFunc) extra_command_set_input; /* only for term console */
+ base_tool_command_group_add (self->term_commands, c);
c = g_new0 (ToolCommand, 1);
c->group = _("Input/Output");
c->group_id = NULL;
c->name = g_strdup_printf (_("%s [<FILE>]"), "o");
c->description = _("Send output to a file or |pipe");
- c->command_func = (ToolCommandFunc) extra_command_set_output;
- tool_command_group_add (md->all_commands, c);
+ c->command_func = (ToolCommandFunc) extra_command_set_output; /* only for term console */
+ base_tool_command_group_add (self->term_commands, c);
c = g_new0 (ToolCommand, 1);
c->group = _("Input/Output");
@@ -2177,7 +1139,7 @@ build_commands (MainData *md)
c->name = g_strdup_printf (_("%s [<TEXT>]"), "echo");
c->description = _("Print TEXT or an empty line to standard output");
c->command_func = (ToolCommandFunc) extra_command_echo;
- tool_command_group_add (md->all_commands, c);
+ base_tool_command_group_add (self->term_commands, c);
c = g_new0 (ToolCommand, 1);
c->group = _("Input/Output");
@@ -2185,15 +1147,15 @@ build_commands (MainData *md)
c->name = g_strdup_printf (_("%s [<TEXT>]"), "qecho");
c->description = _("Send TEXT or an empty line to current output stream");
c->command_func = (ToolCommandFunc) extra_command_qecho;
- tool_command_group_add (md->all_commands, c);
+ base_tool_command_group_add (self->term_commands, c);
c = g_new0 (ToolCommand, 1);
c->group = _("General");
c->group_id = NULL;
c->name = "q";
c->description = _("Quit");
- c->command_func = (ToolCommandFunc) extra_command_quit;
- tool_command_group_add (md->all_commands, c);
+ c->command_func = (ToolCommandFunc) extra_command_quit; /* only for term console */
+ base_tool_command_group_add (self->term_commands, c);
c = g_new0 (ToolCommand, 1);
c->group = _("General");
@@ -2201,7 +1163,7 @@ build_commands (MainData *md)
c->name = g_strdup_printf (_("%s [<DIR>]"), "cd");
c->description = _("Change the current working directory");
c->command_func = (ToolCommandFunc) extra_command_cd;
- tool_command_group_add (md->all_commands, c);
+ base_tool_command_group_add (self->term_commands, c);
c = g_new0 (ToolCommand, 1);
c->group = _("General");
@@ -2209,8 +1171,10 @@ build_commands (MainData *md)
c->name = "copyright";
c->description = _("Show usage and distribution terms");
c->command_func = (ToolCommandFunc) extra_command_copyright;
- tool_command_group_add (md->limit_commands, c);
- tool_command_group_add (md->all_commands, c);
+#ifdef HAVE_LIBSOUP
+ base_tool_command_group_add (self->web_commands, c);
+#endif
+ base_tool_command_group_add (self->term_commands, c);
c = g_new0 (ToolCommand, 1);
c->group = _("General");
@@ -2218,48 +1182,50 @@ build_commands (MainData *md)
c->name = g_strdup_printf (_("%s [<NAME> [<VALUE>]]"), "option");
c->description = _("Set or show an option, or list all options ");
c->command_func = (ToolCommandFunc) extra_command_option;
- tool_command_group_add (md->limit_commands, c);
- tool_command_group_add (md->all_commands, c);
+#ifdef HAVE_LIBSOUP
+ base_tool_command_group_add (self->web_commands, c);
+#endif
+ base_tool_command_group_add (self->term_commands, c);
c = g_new0 (ToolCommand, 1);
c->group = _("Query buffer & query favorites");
c->group_id = NULL;
c->name = g_strdup_printf (_("%s [<FILE>]"), "e");
c->description = _("Edit the query buffer (or file) with external editor");
- c->command_func = (ToolCommandFunc) extra_command_edit_buffer;
- tool_command_group_add (md->all_commands, c);
+ c->command_func = (ToolCommandFunc) extra_command_edit_buffer; /* only for term console */
+ base_tool_command_group_add (self->term_commands, c);
c = g_new0 (ToolCommand, 1);
c->group = _("Query buffer & query favorites");
c->group_id = NULL;
c->name = g_strdup_printf (_("%s [<FILE>]"), "qr");
c->description = _("Reset the query buffer (or load file into query buffer)");
- c->command_func = (ToolCommandFunc) extra_command_reset_buffer;
- tool_command_group_add (md->all_commands, c);
+ c->command_func = (ToolCommandFunc) extra_command_reset_buffer; /* only for term console */
+ base_tool_command_group_add (self->term_commands, c);
c = g_new0 (ToolCommand, 1);
c->group = _("Query buffer & query favorites");
c->group_id = NULL;
c->name = "qp";
c->description = _("Show the contents of the query buffer");
- c->command_func = (ToolCommandFunc) extra_command_show_buffer;
- tool_command_group_add (md->all_commands, c);
+ c->command_func = (ToolCommandFunc) extra_command_show_buffer; /* only for term console */
+ base_tool_command_group_add (self->term_commands, c);
c = g_new0 (ToolCommand, 1);
c->group = _("Query buffer & query favorites");
c->group_id = NULL;
c->name = g_strdup_printf (_("%s [<FAVORITE_NAME>]"), "g");
c->description = _("Execute contents of query buffer, or execute specified query favorite");
- c->command_func = (ToolCommandFunc) extra_command_exec_buffer;
- tool_command_group_add (md->all_commands, c);
+ c->command_func = (ToolCommandFunc) extra_command_exec_buffer; /* only for term console */
+ base_tool_command_group_add (self->term_commands, c);
c = g_new0 (ToolCommand, 1);
c->group = _("Query buffer & query favorites");
c->group_id = NULL;
c->name = g_strdup_printf (_("%s <FILE>"), "qw");
c->description = _("Write query buffer to file");
- c->command_func = (ToolCommandFunc) extra_command_write_buffer;
- tool_command_group_add (md->all_commands, c);
+ c->command_func = (ToolCommandFunc) extra_command_write_buffer; /* only for term console */
+ base_tool_command_group_add (self->term_commands, c);
c = g_new0 (ToolCommand, 1);
c->group = _("Query buffer & query favorites");
@@ -2267,7 +1233,7 @@ build_commands (MainData *md)
c->name = g_strdup_printf (_("%s <FAVORITE_NAME>"), "qs");
c->description = _("Save query buffer as favorite");
c->command_func = (ToolCommandFunc) extra_command_query_buffer_to_dict;
- tool_command_group_add (md->all_commands, c);
+ base_tool_command_group_add (self->term_commands, c);
c = g_new0 (ToolCommand, 1);
c->group = _("Query buffer & query favorites");
@@ -2275,7 +1241,7 @@ build_commands (MainData *md)
c->name = g_strdup_printf (_("%s <FAVORITE_NAME>"), "ql");
c->description = _("Load a query favorite into query buffer");
c->command_func = (ToolCommandFunc) extra_command_query_buffer_from_dict;
- tool_command_group_add (md->all_commands, c);
+ base_tool_command_group_add (self->term_commands, c);
c = g_new0 (ToolCommand, 1);
c->group = _("Query buffer & query favorites");
@@ -2283,7 +1249,7 @@ build_commands (MainData *md)
c->name = g_strdup_printf (_("%s <FAVORITE_NAME>"), "qd");
c->description = _("Delete a query favorite");
c->command_func = (ToolCommandFunc) extra_command_query_buffer_delete_dict;
- tool_command_group_add (md->all_commands, c);
+ base_tool_command_group_add (self->term_commands, c);
c = g_new0 (ToolCommand, 1);
c->group = _("Query buffer & query favorites");
@@ -2291,7 +1257,7 @@ build_commands (MainData *md)
c->name = g_strdup_printf (_("%s"), "qa");
c->description = _("List all query favorites");
c->command_func = (ToolCommandFunc) extra_command_query_buffer_list_dict;
- tool_command_group_add (md->all_commands, c);
+ base_tool_command_group_add (self->term_commands, c);
c = g_new0 (ToolCommand, 1);
c->group = _("Input/Output");
@@ -2299,17 +1265,7 @@ build_commands (MainData *md)
c->name = "H [HTML|XML|CSV|DEFAULT]";
c->description = _("Set output format");
c->command_func = (ToolCommandFunc) extra_command_set_output_format;
- tool_command_group_add (md->all_commands, c);
-
- /*
- c = g_new0 (ToolCommand, 1);
- c->group = _("Query buffer & query favorites");
- c->group_id = NULL;
- c->name = g_strdup_printf (_("%s <FILE> <TABLE> <BLOB_COLUMN> <ROW_CONDITION>"), "lo_update");
- c->description = _("Import a blob into the database");
- c->command_func = (ToolCommandFunc) extra_command_lo_update;
- tool_command_group_add (md->all_commands, c);
- */
+ base_tool_command_group_add (self->term_commands, c);
c = g_new0 (ToolCommand, 1);
c->group = _("Query buffer & query favorites");
@@ -2317,7 +1273,7 @@ build_commands (MainData *md)
c->name = g_strdup_printf (_("%s [<NAME>|<TABLE> <COLUMN> <ROW_CONDITION>] <FILE>"), "export");
c->description = _("Export internal parameter or table's value to the FILE file");
c->command_func = (ToolCommandFunc) extra_command_export;
- tool_command_group_add (md->all_commands, c);
+ base_tool_command_group_add (self->term_commands, c);
c = g_new0 (ToolCommand, 1);
c->group = _("Execution context");
@@ -2325,8 +1281,10 @@ build_commands (MainData *md)
c->name = g_strdup_printf (_("%s [<NAME> [<VALUE>|_null_]]"), "set");
c->description = _("Set or show internal parameter, or list all if no parameter specified ");
c->command_func = (ToolCommandFunc) extra_command_set;
- tool_command_group_add (md->limit_commands, c);
- tool_command_group_add (md->all_commands, c);
+#ifdef HAVE_LIBSOUP
+ base_tool_command_group_add (self->web_commands, c);
+#endif
+ base_tool_command_group_add (self->term_commands, c);
c = g_new0 (ToolCommand, 1);
c->group = _("Execution context");
@@ -2334,8 +1292,10 @@ build_commands (MainData *md)
c->name = g_strdup_printf (_("%s [<NAME>]"), "unset");
c->description = _("Unset (delete) internal named parameter (or all parameters)");
c->command_func = (ToolCommandFunc) extra_command_unset;
- tool_command_group_add (md->limit_commands, c);
- tool_command_group_add (md->all_commands, c);
+#ifdef HAVE_LIBSOUP
+ base_tool_command_group_add (self->web_commands, c);
+#endif
+ base_tool_command_group_add (self->term_commands, c);
c = g_new0 (ToolCommand, 1);
c->group = _("Execution context");
@@ -2343,7 +1303,7 @@ build_commands (MainData *md)
c->name = g_strdup_printf (_("%s <NAME> [<FILE>|<TABLE> <COLUMN> <ROW_CONDITION>]"), "setex");
c->description = _("Set internal parameter as the contents of the FILE file or from an existing
table's value");
c->command_func = (ToolCommandFunc) extra_command_set2;
- tool_command_group_add (md->all_commands, c);
+ base_tool_command_group_add (self->term_commands, c);
c = g_new0 (ToolCommand, 1);
c->group = _("Execution context");
@@ -2352,7 +1312,7 @@ build_commands (MainData *md)
c->description = _("Performs a statistical analysis on the data from SELECT, "
"using ROW_FIELDS and COLUMN_FIELDS criteria and optionally DATA_FIELDS for the
data");
c->command_func = (ToolCommandFunc) extra_command_pivot;
- tool_command_group_add (md->all_commands, c);
+ base_tool_command_group_add (self->term_commands, c);
c = g_new0 (ToolCommand, 1);
c->group = _("Datasets' manipulations");
@@ -2360,8 +1320,10 @@ build_commands (MainData *md)
c->name = g_strdup_printf (_("%s"), "ds_list");
c->description = _("Lists all the datasets kept in memory for reference");
c->command_func = (ToolCommandFunc) extra_command_data_sets_list;
- tool_command_group_add (md->limit_commands, c);
- tool_command_group_add (md->all_commands, c);
+#ifdef HAVE_LIBSOUP
+ base_tool_command_group_add (self->web_commands, c);
+#endif
+ base_tool_command_group_add (self->term_commands, c);
c = g_new0 (ToolCommand, 1);
c->group = _("Datasets' manipulations");
@@ -2369,8 +1331,10 @@ build_commands (MainData *md)
c->name = g_strdup_printf (_("%s <DATASET NAME> <PATTERN>"), "ds_grep");
c->description = _("Show a dataset's contents where lines match a regular expression");
c->command_func = (ToolCommandFunc) extra_command_data_set_grep;
- tool_command_group_add (md->limit_commands, c);
- tool_command_group_add (md->all_commands, c);
+#ifdef HAVE_LIBSOUP
+ base_tool_command_group_add (self->web_commands, c);
+#endif
+ base_tool_command_group_add (self->term_commands, c);
c = g_new0 (ToolCommand, 1);
c->group = _("Datasets' manipulations");
@@ -2378,8 +1342,10 @@ build_commands (MainData *md)
c->name = g_strdup_printf (_("%s <DATASET NAME> [<COLUMN> [<COLUMN> ...]]"), "ds_show");
c->description = _("Show a dataset's contents, showing only the specified columns if any specified");
c->command_func = (ToolCommandFunc) extra_command_data_set_show;
- tool_command_group_add (md->limit_commands, c);
- tool_command_group_add (md->all_commands, c);
+#ifdef HAVE_LIBSOUP
+ base_tool_command_group_add (self->web_commands, c);
+#endif
+ base_tool_command_group_add (self->term_commands, c);
c = g_new0 (ToolCommand, 1);
c->group = _("Datasets' manipulations");
@@ -2387,8 +1353,10 @@ build_commands (MainData *md)
c->name = g_strdup_printf (_("%s <DATASET NAME> [<DATASET NAME> ...]"), "ds_rm");
c->description = _("Remove one or more datasets");
c->command_func = (ToolCommandFunc) extra_command_data_set_rm;
- tool_command_group_add (md->limit_commands, c);
- tool_command_group_add (md->all_commands, c);
+#ifdef HAVE_LIBSOUP
+ base_tool_command_group_add (self->web_commands, c);
+#endif
+ base_tool_command_group_add (self->term_commands, c);
c = g_new0 (ToolCommand, 1);
c->group = _("Datasets' manipulations");
@@ -2396,8 +1364,10 @@ build_commands (MainData *md)
c->name = g_strdup_printf (_("%s <DATASET NAME> <DATASET NAME>"), "ds_mv");
c->description = _("Rename a dataset, useful to rename the '_' dataset to keep it");
c->command_func = (ToolCommandFunc) extra_command_data_set_move;
- tool_command_group_add (md->limit_commands, c);
- tool_command_group_add (md->all_commands, c);
+#ifdef HAVE_LIBSOUP
+ base_tool_command_group_add (self->web_commands, c);
+#endif
+ base_tool_command_group_add (self->term_commands, c);
c = g_new0 (ToolCommand, 1);
c->group = _("Datasets' manipulations");
@@ -2405,8 +1375,10 @@ build_commands (MainData *md)
c->name = g_strdup_printf (_("%s CSV <FILE NAME>"), "ds_import");
c->description = _("Import a dataset from a file");
c->command_func = (ToolCommandFunc) extra_command_data_set_import;
- tool_command_group_add (md->limit_commands, c);
- tool_command_group_add (md->all_commands, c);
+#ifdef HAVE_LIBSOUP
+ base_tool_command_group_add (self->web_commands, c);
+#endif
+ base_tool_command_group_add (self->term_commands, c);
#ifdef HAVE_LDAP
c = g_new0 (ToolCommand, 1);
@@ -2415,7 +1387,7 @@ build_commands (MainData *md)
c->name = g_strdup_printf (_("%s <filter> [<base|onelevel|subtree> [<base DN>]]"), "ldap_search");
c->description = _("Search LDAP entries");
c->command_func = (ToolCommandFunc) extra_command_ldap_search;
- tool_command_group_add (md->all_commands, c);
+ base_tool_command_group_add (self->term_commands, c);
c = g_new0 (ToolCommand, 1);
c->group = _("LDAP");
@@ -2427,7 +1399,7 @@ build_commands (MainData *md)
"also shown, and if the \"unset\" 2nd parameter "
"is passed, then only non set attributes are shown.");
c->command_func = (ToolCommandFunc) extra_command_ldap_descr;
- tool_command_group_add (md->all_commands, c);
+ base_tool_command_group_add (self->term_commands, c);
c = g_new0 (ToolCommand, 1);
c->group = _("LDAP");
@@ -2435,7 +1407,7 @@ build_commands (MainData *md)
c->name = g_strdup_printf (_("%s <DN> <new DN>"), "ldap_mv");
c->description = _("Renames an LDAP entry");
c->command_func = (ToolCommandFunc) extra_command_ldap_mv;
- tool_command_group_add (md->all_commands, c);
+ base_tool_command_group_add (self->term_commands, c);
c = g_new0 (ToolCommand, 1);
c->group = _("LDAP");
@@ -2443,20 +1415,755 @@ build_commands (MainData *md)
c->name = g_strdup_printf (_("%s <DN> <OPERATION> [<ATTR>[=<VALUE>]] [<ATTR>=<VALUE> ...]"),
"ldap_mod");
c->description = _("Modifies an LDAP entry's attributes; <OPERATION> may be DELETE, REPLACE or ADD");
c->command_func = (ToolCommandFunc) extra_command_ldap_mod;
- tool_command_group_add (md->all_commands, c);
+ base_tool_command_group_add (self->term_commands, c);
#endif
}
+ToolCommandResult *
+gda_internal_command_history (ToolCommand *command, guint argc, const gchar **argv,
+ TContext *console, GError **error)
+{
+ ToolCommandResult *res;
+
+ g_assert (console);
+ g_assert (global_t_app);
+ g_assert (console == global_t_app->priv->term_console);
+
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = BASE_TOOL_COMMAND_RESULT_TXT;
+
+ GString *string;
+#ifdef HAVE_HISTORY
+ if (argv[0]) {
+ if (!base_tool_input_save_history (argv[0], error)) {
+ g_free (res);
+ res = NULL;
+ }
+ else
+ res->type = BASE_TOOL_COMMAND_RESULT_EMPTY;
+ }
+ else {
+ gchar *tmp;
+ tmp = base_tool_input_get_history ();
+ string = g_string_new (tmp);
+ g_free (tmp);
+ res->u.txt = string;
+ }
+#else
+ string = g_string_new (_("History is not supported"));
+ res->u.txt = string;
+#endif
+
+ return res;
+}
+
+ToolCommandResult *
+gda_internal_command_dict_sync (ToolCommand *command, guint argc, const gchar **argv,
+ TContext *console, GError **error)
+{
+ ToolCommandResult *res;
+
+ g_assert (console);
+ g_assert (global_t_app);
+
+ if (!t_context_get_connection (console)) {
+ g_set_error (error, T_ERROR, T_NO_CONNECTION_ERROR,
+ "%s", _("No current connection"));
+ return NULL;
+ }
+
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = BASE_TOOL_COMMAND_RESULT_EMPTY;
+
+ if (argv[0] && *argv[0]) {
+ GdaMetaContext context;
+ memset (&context, 0, sizeof (context));
+ if (*argv[0] == '_')
+ context.table_name = (gchar*) argv[0];
+ else
+ context.table_name = g_strdup_printf ("_%s", argv[0]);
+ if (!gda_connection_update_meta_store (t_connection_get_cnc (t_context_get_connection
(console)), &context, error)) {
+ g_free (res);
+ res = NULL;
+ }
+ if (*argv[0] != '_')
+ g_free (context.table_name);
+ }
+ else if (!gda_connection_update_meta_store (t_connection_get_cnc (t_context_get_connection
(console)), NULL, error)) {
+ g_free (res);
+ res = NULL;
+ }
+
+ return res;
+}
+
+ToolCommandResult *
+gda_internal_command_list_tables (ToolCommand *command, guint argc, const gchar **argv,
+ TContext *console, GError **error)
+{
+ ToolCommandResult *res;
+ GdaDataModel *model;
+
+ g_assert (console);
+ g_assert (global_t_app);
+
+ if (!t_context_get_connection (console)) {
+ g_set_error (error, T_ERROR, T_NO_CONNECTION_ERROR,
+ "%s", _("No current connection"));
+ return NULL;
+ }
+
+ if (argv[0] && *argv[0]) {
+ GValue *v;
+ const gchar *sql = "SELECT table_schema AS Schema, table_name AS Name, table_type as Type, "
+ "table_owner as Owner, table_comments as Description "
+ "FROM _tables WHERE table_short_name=##tname::string AND "
+ "table_type LIKE '%TABLE%' "
+ "ORDER BY table_schema, table_name";
+
+ gchar *tmp = gda_sql_identifier_prepare_for_compare (g_strdup (argv[0]));
+ g_value_take_string (v = gda_value_new (G_TYPE_STRING), tmp);
+ model = gda_meta_store_extract (gda_connection_get_meta_store (t_connection_get_cnc
(t_context_get_connection (console))),
+ sql, error, "tname", v, NULL);
+ gda_value_free (v);
+ }
+ else {
+ const gchar *sql = "SELECT table_schema AS Schema, table_name AS Name, table_type as Type, "
+ "table_owner as Owner, table_comments as Description "
+ "FROM _tables WHERE table_type LIKE '%TABLE%' "
+ "ORDER BY table_schema, table_name";
+ model = gda_meta_store_extract (gda_connection_get_meta_store (t_connection_get_cnc
(t_context_get_connection (console))),
+ sql, error);
+ }
+ if (!model)
+ return NULL;
+
+ g_object_set_data (G_OBJECT (model), "name", _("List of tables"));
+
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = BASE_TOOL_COMMAND_RESULT_DATA_MODEL;
+ res->u.model = model;
+
+ return res;
+}
+
+ToolCommandResult *
+gda_internal_command_list_views (ToolCommand *command, guint argc, const gchar **argv,
+ TContext *console, GError **error)
+{
+ ToolCommandResult *res;
+ GdaDataModel *model;
+
+ g_assert (console);
+ g_assert (global_t_app);
+
+ if (!t_context_get_connection (console)) {
+ g_set_error (error, T_ERROR, T_NO_CONNECTION_ERROR,
+ "%s", _("No current connection"));
+ return NULL;
+ }
+
+ if (argv[0] && *argv[0]) {
+ GValue *v;
+ const gchar *sql = "SELECT table_schema AS Schema, table_name AS Name, table_type as Type, "
+ "table_owner as Owner, table_comments as Description "
+ "FROM _tables WHERE table_short_name=##tname::string AND "
+ "table_type = 'VIEW' "
+ "ORDER BY table_schema, table_name";
+
+ g_value_set_string (v = gda_value_new (G_TYPE_STRING), argv[0]);
+ model = gda_meta_store_extract (gda_connection_get_meta_store (t_connection_get_cnc
(t_context_get_connection (console))),
+ sql, error, "tname", v, NULL);
+ gda_value_free (v);
+ }
+ else {
+ const gchar *sql = "SELECT table_schema AS Schema, table_name AS Name, table_type as Type, "
+ "table_owner as Owner, table_comments as Description "
+ "FROM _tables WHERE table_type='VIEW' "
+ "ORDER BY table_schema, table_name";
+ model = gda_meta_store_extract (gda_connection_get_meta_store (t_connection_get_cnc
(t_context_get_connection (console))),
+ sql, error);
+ }
+ if (!model)
+ return NULL;
+
+ g_object_set_data (G_OBJECT (model), "name", _("List of views"));
+
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = BASE_TOOL_COMMAND_RESULT_DATA_MODEL;
+ res->u.model = model;
+
+ return res;
+}
+
+ToolCommandResult *
+gda_internal_command_list_schemas (ToolCommand *command, guint argc, const gchar **argv,
+ TContext *console, GError **error)
+{
+ ToolCommandResult *res;
+ GdaDataModel *model;
+
+ g_assert (console);
+ g_assert (global_t_app);
+
+ if (!t_context_get_connection (console)) {
+ g_set_error (error, T_ERROR, T_NO_CONNECTION_ERROR,
+ "%s", _("No current connection"));
+ return NULL;
+ }
+
+ if (argv[0] && *argv[0]) {
+ GValue *v;
+ const gchar *sql = "SELECT schema_name AS Schema, schema_owner AS Owner, "
+ "CASE WHEN schema_internal THEN 'yes' ELSE 'no' END AS Internal "
+ "FROM _schemata WHERE schema_name=##sname::string "
+ "ORDER BY schema_name";
+
+ g_value_set_string (v = gda_value_new (G_TYPE_STRING), argv[0]);
+ model = gda_meta_store_extract (gda_connection_get_meta_store (t_connection_get_cnc
(t_context_get_connection (console))),
+ sql, error, "sname", v, NULL);
+ gda_value_free (v);
+ }
+ else {
+ const gchar *sql = "SELECT schema_name AS Schema, schema_owner AS Owner, "
+ "CASE WHEN schema_internal THEN 'yes' ELSE 'no' END AS Internal "
+ "FROM _schemata ORDER BY schema_name";
+ model = gda_meta_store_extract (gda_connection_get_meta_store (t_connection_get_cnc
(t_context_get_connection (console))),
+ sql, error);
+ }
+ if (!model)
+ return NULL;
+
+ g_object_set_data (G_OBJECT (model), "name", _("List of schemas"));
+
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = BASE_TOOL_COMMAND_RESULT_DATA_MODEL;
+ res->u.model = model;
+
+ return res;
+}
+
+GdaMetaStruct *
+gda_internal_command_build_meta_struct (GdaConnection *cnc, const gchar **argv, GError **error)
+{
+ GdaMetaStruct *mstruct;
+ gint index;
+ const gchar *arg;
+ GdaMetaStore *store;
+ GSList *objlist;
+
+ store = gda_connection_get_meta_store (cnc);
+ mstruct = gda_meta_struct_new (store, GDA_META_STRUCT_FEATURE_ALL);
+
+ if (!argv[0]) {
+ GSList *list;
+ /* use all tables or views visible by default */
+ if (!gda_meta_struct_complement_default (mstruct, error))
+ goto onerror;
+ list = gda_meta_struct_get_all_db_objects (mstruct);
+ if (!list) {
+ /* use all tables or views visible or not by default */
+ if (!gda_meta_struct_complement_all (mstruct, error))
+ goto onerror;
+ }
+ else
+ g_slist_free (list);
+ }
+
+ for (index = 0, arg = argv[0]; arg; index++, arg = argv[index]) {
+ GValue *v;
+ g_value_set_string (v = gda_value_new (G_TYPE_STRING), arg);
+
+ /* see if we have the form <schema_name>.*, to list all the objects in a given schema */
+ if (g_str_has_suffix (arg, ".*") && (*arg != '.')) {
+ gchar *str;
+
+ str = g_strdup (arg);
+ str[strlen (str) - 2] = 0;
+ g_value_take_string (v, str);
+
+ if (!gda_meta_struct_complement_schema (mstruct, NULL, v, error))
+ goto onerror;
+ }
+ else {
+ /* try to find it as a table or view */
+ if (g_str_has_suffix (arg, "=") && (*arg != '=')) {
+ GdaMetaDbObject *dbo;
+ gchar *str;
+ str = g_strdup (arg);
+ str[strlen (str) - 1] = 0;
+ g_value_take_string (v, str);
+ dbo = gda_meta_struct_complement (mstruct, GDA_META_DB_UNKNOWN,
+ NULL, NULL, v, error);
+ if (dbo)
+ gda_meta_struct_complement_depend (mstruct, dbo, error);
+ else
+ goto onerror;
+ }
+ else if (!gda_meta_struct_complement (mstruct, GDA_META_DB_UNKNOWN, NULL, NULL, v,
error))
+ goto onerror;
+ }
+ }
+
+ objlist = gda_meta_struct_get_all_db_objects (mstruct);
+ if (!objlist) {
+ g_set_error (error, T_ERROR, T_OBJECT_NOT_FOUND_ERROR,
+ "%s", _("No object found"));
+ goto onerror;
+ }
+ g_slist_free (objlist);
+ gda_meta_struct_sort_db_objects (mstruct, GDA_META_SORT_ALHAPETICAL, NULL);
+ return mstruct;
+
+ onerror:
+ g_object_unref (mstruct);
+ return NULL;
+}
+
+static void
+meta_table_column_foreach_attribute_func (const gchar *att_name, const GValue *value, GString **string)
+{
+ if (!strcmp (att_name, GDA_ATTRIBUTE_AUTO_INCREMENT) &&
+ (G_VALUE_TYPE (value) == G_TYPE_BOOLEAN) &&
+ g_value_get_boolean (value)) {
+ if (*string) {
+ g_string_append (*string, ", ");
+ g_string_append (*string, _("Auto increment"));
+ }
+ else
+ *string = g_string_new (_("Auto increment"));
+ }
+}
+
+ToolCommandResult *
+gda_internal_command_detail (ToolCommand *command, guint argc, const gchar **argv,
+ TContext *console, GError **error)
+{
+ ToolCommandResult *res;
+ GdaDataModel *model;
+
+ g_assert (console);
+ g_assert (global_t_app);
+
+ if (!t_context_get_connection (console)) {
+ g_set_error (error, T_ERROR, T_NO_CONNECTION_ERROR,
+ "%s", _("No current connection"));
+ return NULL;
+ }
+
+ if (!argv[0] || !*argv[0]) {
+ /* FIXME: include indexes and sequences when they are present in the information schema */
+ /* displays all tables, views, indexes and sequences which are "directly visible" */
+ const gchar *sql = "SELECT table_schema AS Schema, table_name AS Name, table_type as Type, "
+ "table_owner as Owner FROM _tables WHERE table_short_name = table_name "
+ "ORDER BY table_schema, table_name";
+ model = gda_meta_store_extract (gda_connection_get_meta_store (t_connection_get_cnc
(t_context_get_connection (console))),
+ sql, error, NULL);
+
+ if (model) {
+ /* if no row, then return all the objects from all the schemas */
+ if (gda_data_model_get_n_rows (model) == 0) {
+ g_object_unref (model);
+ sql = "SELECT table_schema AS Schema, table_name AS Name, table_type as Type,
"
+ "table_owner as Owner FROM _tables "
+ "ORDER BY table_schema, table_name";
+ model = gda_meta_store_extract (gda_connection_get_meta_store
(t_connection_get_cnc (t_context_get_connection (console))),
+ sql, error, NULL);
+ }
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = BASE_TOOL_COMMAND_RESULT_DATA_MODEL;
+ res->u.model = model;
+ }
+ else {
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = BASE_TOOL_COMMAND_RESULT_EMPTY;
+ }
+ return res;
+ }
+
+ GdaMetaStruct *mstruct;
+ GSList *dbo_list, *tmplist;
+ mstruct = gda_internal_command_build_meta_struct (t_connection_get_cnc (t_context_get_connection
(console)), argv, error);
+ if (!mstruct)
+ return NULL;
+
+ /* compute the number of known database objects */
+ gint nb_objects = 0;
+ tmplist = gda_meta_struct_get_all_db_objects (mstruct);
+ for (dbo_list = tmplist; dbo_list; dbo_list = dbo_list->next) {
+ GdaMetaDbObject *dbo = GDA_META_DB_OBJECT (dbo_list->data);
+ if (dbo->obj_type != GDA_META_DB_UNKNOWN)
+ nb_objects++;
+ }
+
+ /* if more than one object, then show a list */
+ if (nb_objects > 1) {
+ model = gda_data_model_array_new (4);
+ gda_data_model_set_column_title (model, 0, _("Schema"));
+ gda_data_model_set_column_title (model, 1, _("Name"));
+ gda_data_model_set_column_title (model, 2, _("Type"));
+ gda_data_model_set_column_title (model, 3, _("Owner"));
+ for (dbo_list = tmplist; dbo_list; dbo_list = dbo_list->next) {
+ GdaMetaDbObject *dbo = GDA_META_DB_OBJECT (dbo_list->data);
+ GList *values = NULL;
+ GValue *val;
+
+ if (dbo->obj_type == GDA_META_DB_UNKNOWN)
+ continue;
+
+ g_value_set_string ((val = gda_value_new (G_TYPE_STRING)), dbo->obj_schema);
+ values = g_list_append (values, val);
+ g_value_set_string ((val = gda_value_new (G_TYPE_STRING)), dbo->obj_name);
+ values = g_list_append (values, val);
+
+ val = gda_value_new (G_TYPE_STRING);
+ switch (dbo->obj_type) {
+ case GDA_META_DB_TABLE:
+ g_value_set_string (val, "TABLE");
+ break;
+ case GDA_META_DB_VIEW:
+ g_value_set_string (val, "VIEW");
+ break;
+ default:
+ g_value_set_string (val, "???");
+ TO_IMPLEMENT;
+ }
+ values = g_list_append (values, val);
+ if (dbo->obj_owner)
+ g_value_set_string ((val = gda_value_new (G_TYPE_STRING)), dbo->obj_owner);
+ else
+ g_value_set_string ((val = gda_value_new (G_TYPE_STRING)), "");
+ values = g_list_append (values, val);
+ gda_data_model_append_values (model, values, NULL);
+ g_list_foreach (values, (GFunc) gda_value_free, NULL);
+ g_list_free (values);
+ }
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = BASE_TOOL_COMMAND_RESULT_DATA_MODEL;
+ res->u.model = model;
+ g_slist_free (tmplist);
+ return res;
+ }
+ else if (nb_objects == 0) {
+ g_set_error (error, T_ERROR, T_OBJECT_NOT_FOUND_ERROR,
+ "%s", _("No object found"));
+ g_slist_free (tmplist);
+ return NULL;
+ }
+
+ /*
+ * Information about a single object
+ */
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = BASE_TOOL_COMMAND_RESULT_MULTIPLE;
+ res->u.multiple_results = NULL;
+ GdaMetaDbObject *dbo;
+
+ for (dbo_list = tmplist; dbo_list; dbo_list = dbo_list->next) {
+ dbo = GDA_META_DB_OBJECT (dbo_list->data);
+ if (dbo->obj_type == GDA_META_DB_UNKNOWN)
+ dbo = NULL;
+ else
+ break;
+ }
+ g_assert (dbo);
+ g_slist_free (tmplist);
+
+ if ((dbo->obj_type == GDA_META_DB_VIEW) || (dbo->obj_type == GDA_META_DB_TABLE)) {
+ ToolCommandResult *subres;
+ GdaMetaTable *mt = GDA_META_TABLE (dbo);
+
+ if (mt->columns) {
+ GSList *list;
+ model = gda_data_model_array_new (5);
+ gda_data_model_set_column_title (model, 0, _("Column"));
+ gda_data_model_set_column_title (model, 1, _("Type"));
+ gda_data_model_set_column_title (model, 2, _("Nullable"));
+ gda_data_model_set_column_title (model, 3, _("Default"));
+ gda_data_model_set_column_title (model, 4, _("Extra"));
+ if (dbo->obj_type == GDA_META_DB_VIEW)
+ g_object_set_data_full (G_OBJECT (model), "name",
+ g_strdup_printf (_("List of columns for view '%s'"),
+ dbo->obj_short_name), g_free);
+ else
+ g_object_set_data_full (G_OBJECT (model), "name",
+ g_strdup_printf (_("List of columns for table '%s'"),
+ dbo->obj_short_name), g_free);
+ for (list = mt->columns; list; list = list->next) {
+ GdaMetaTableColumn *tcol = GDA_META_TABLE_COLUMN (list->data);
+ GList *values = NULL;
+ GValue *val;
+ GString *string = NULL;
+
+ g_value_set_string ((val = gda_value_new (G_TYPE_STRING)), tcol->column_name);
+ values = g_list_append (values, val);
+ g_value_set_string ((val = gda_value_new (G_TYPE_STRING)), tcol->column_type);
+ values = g_list_append (values, val);
+ g_value_set_string ((val = gda_value_new (G_TYPE_STRING)), tcol->nullok ?
_("yes") : _("no"));
+ values = g_list_append (values, val);
+ g_value_set_string ((val = gda_value_new (G_TYPE_STRING)),
tcol->default_value);
+ values = g_list_append (values, val);
+
+ gda_meta_table_column_foreach_attribute (tcol,
+ (GdaAttributesManagerFunc)
meta_table_column_foreach_attribute_func, &string);
+ if (string) {
+ g_value_take_string ((val = gda_value_new (G_TYPE_STRING)),
string->str);
+ g_string_free (string, FALSE);
+ }
+ else
+ val = gda_value_new_null ();
+ values = g_list_append (values, val);
+
+ gda_data_model_append_values (model, values, NULL);
+ g_list_foreach (values, (GFunc) gda_value_free, NULL);
+ g_list_free (values);
+ }
+
+ subres = g_new0 (ToolCommandResult, 1);
+ subres->type = BASE_TOOL_COMMAND_RESULT_DATA_MODEL;
+ subres->u.model = model;
+ res->u.multiple_results = g_slist_append (res->u.multiple_results, subres);
+ }
+ else {
+ subres = g_new0 (ToolCommandResult, 1);
+ subres->type = BASE_TOOL_COMMAND_RESULT_TXT;
+ subres->u.txt = g_string_new ("");
+ if (dbo->obj_type == GDA_META_DB_VIEW)
+ g_string_append_printf (subres->u.txt,
+ _("Could not determine columns of view '%s'"),
+ dbo->obj_short_name);
+ else
+ g_string_append_printf (subres->u.txt,
+ _("Could not determine columns of table '%s'"),
+ dbo->obj_short_name);
+
+ res->u.multiple_results = g_slist_append (res->u.multiple_results, subres);
+ }
+
+ if (dbo->obj_type == GDA_META_DB_VIEW) {
+ /* VIEW specific */
+ GdaMetaView *mv = GDA_META_VIEW (dbo);
+
+ subres = g_new0 (ToolCommandResult, 1);
+ subres->type = BASE_TOOL_COMMAND_RESULT_TXT;
+ subres->u.txt = g_string_new ("");
+ g_string_append_printf (subres->u.txt, _("View definition: %s"), mv->view_def);
+ res->u.multiple_results = g_slist_append (res->u.multiple_results, subres);
+ }
+ else {
+ /* TABLE specific */
+ GValue *catalog, *schema, *name;
+ gint i, nrows;
+ const gchar *sql = "SELECT constraint_type, constraint_name "
+ "FROM _table_constraints WHERE table_catalog = ##tc::string "
+ "AND table_schema = ##ts::string AND table_name = ##tname::string "
+ "AND constraint_type != 'FOREIGN KEY' "
+ "ORDER BY constraint_type DESC, constraint_name";
+
+ g_value_set_string ((catalog = gda_value_new (G_TYPE_STRING)), dbo->obj_catalog);
+ g_value_set_string ((schema = gda_value_new (G_TYPE_STRING)), dbo->obj_schema);
+ g_value_set_string ((name = gda_value_new (G_TYPE_STRING)), dbo->obj_name);
+ model = gda_meta_store_extract (gda_connection_get_meta_store (t_connection_get_cnc
(t_context_get_connection (console))),
+ sql, error,
+ "tc", catalog, "ts", schema, "tname", name, NULL);
+ nrows = gda_data_model_get_n_rows (model);
+ for (i = 0; i < nrows; i++) {
+ GString *string = NULL;
+ const GValue *cvalue;
+ const gchar *str = NULL;
+
+ cvalue = gda_data_model_get_value_at (model, 0, i, error);
+ if (!cvalue) {
+ base_tool_command_result_free (res);
+ res = NULL;
+ goto out;
+ }
+ str = g_value_get_string (cvalue);
+ if (*str == 'P') {
+ /* primary key */
+ GdaDataModel *cols;
+ cvalue = gda_data_model_get_value_at (model, 1, i, error);
+ if (!cvalue) {
+ base_tool_command_result_free (res);
+ res = NULL;
+ goto out;
+ }
+ string = g_string_new (_("Primary key"));
+ g_string_append_printf (string, " '%s'", g_value_get_string (cvalue));
+ str = "SELECT column_name, ordinal_position "
+ "FROM _key_column_usage WHERE table_catalog = ##tc::string "
+ "AND table_schema = ##ts::string AND table_name =
##tname::string AND "
+ "constraint_name = ##cname::string "
+ "ORDER BY ordinal_position";
+
+ cols = gda_meta_store_extract (gda_connection_get_meta_store
(t_connection_get_cnc (t_context_get_connection (console))),
+ str, error,
+ "tc", catalog, "ts", schema, "tname",
name, "cname", cvalue,
+ NULL);
+ if (cols) {
+ gint j, cnrows;
+ cnrows = gda_data_model_get_n_rows (cols);
+ if (cnrows > 0) {
+ g_string_append (string, " (");
+ for (j = 0; j < cnrows; j++) {
+ if (j > 0)
+ g_string_append (string, ", ");
+ cvalue = gda_data_model_get_value_at (cols,
0, j, error);
+ if (!cvalue) {
+ base_tool_command_result_free (res);
+ res = NULL;
+ g_object_unref (cols);
+ g_string_free (string, TRUE);
+ goto out;
+ }
+ g_string_append (string, g_value_get_string
(cvalue));
+ }
+ g_string_append_c (string, ')');
+ }
+ g_object_unref (cols);
+ }
+ }
+ else if (*str == 'F') {
+ /* foreign key, not handled here */
+ }
+ else if (*str == 'U') {
+ /* Unique constraint */
+ GdaDataModel *cols;
+ cvalue = gda_data_model_get_value_at (model, 1, i, error);
+ if (!cvalue) {
+ base_tool_command_result_free (res);
+ res = NULL;
+ goto out;
+ }
+ string = g_string_new (_("Unique"));
+ g_string_append_printf (string, " '%s'", g_value_get_string (cvalue));
+ str = "SELECT column_name, ordinal_position "
+ "FROM _key_column_usage WHERE table_catalog = ##tc::string "
+ "AND table_schema = ##ts::string AND table_name =
##tname::string AND "
+ "constraint_name = ##cname::string "
+ "ORDER BY ordinal_position";
+
+ cols = gda_meta_store_extract (gda_connection_get_meta_store
(t_connection_get_cnc (t_context_get_connection (console))),
+ str, error,
+ "tc", catalog, "ts", schema, "tname",
name, "cname", cvalue,
+ NULL);
+ if (cols) {
+ gint j, cnrows;
+ cnrows = gda_data_model_get_n_rows (cols);
+ if (cnrows > 0) {
+ g_string_append (string, " (");
+ for (j = 0; j < cnrows; j++) {
+ if (j > 0)
+ g_string_append (string, ", ");
+ cvalue = gda_data_model_get_value_at (cols,
0, j, error);
+ if (!cvalue) {
+ base_tool_command_result_free (res);
+ res = NULL;
+ g_object_unref (cols);
+ g_string_free (string, TRUE);
+ goto out;
+ }
+ g_string_append (string, g_value_get_string
(cvalue));
+ }
+ g_string_append_c (string, ')');
+ }
+ g_object_unref (cols);
+ }
+ }
+
+ if (string) {
+ subres = g_new0 (ToolCommandResult, 1);
+ subres->type = BASE_TOOL_COMMAND_RESULT_TXT;
+ subres->u.txt = string;
+ res->u.multiple_results = g_slist_append (res->u.multiple_results,
subres);
+ }
+ }
+
+ gda_value_free (catalog);
+ gda_value_free (schema);
+ gda_value_free (name);
+
+ g_object_unref (model);
+
+ /* foreign key constraints */
+ GSList *list;
+ for (list = mt->fk_list; list; list = list->next) {
+ GString *string;
+ GdaMetaTableForeignKey *fk;
+ gint i;
+ fk = (GdaMetaTableForeignKey*) list->data;
+ if (GDA_META_TABLE_FOREIGN_KEY_IS_DECLARED (fk))
+ string = g_string_new (_("Declared foreign key"));
+ else
+ string = g_string_new (_("Foreign key"));
+ g_string_append_printf (string, " '%s' (", fk->fk_name);
+ for (i = 0; i < fk->cols_nb; i++) {
+ if (i != 0)
+ g_string_append (string, ", ");
+ g_string_append (string, fk->fk_names_array [i]);
+ }
+ g_string_append (string, ") ");
+ if (fk->depend_on->obj_short_name)
+ /* To translators: the term "references" is the verb
+ * "to reference" in the context of foreign keys where
+ * "table A REFERENCES table B" */
+ g_string_append_printf (string, _("references %s"),
+ fk->depend_on->obj_short_name);
+ else
+ /* To translators: the term "references" is the verb
+ * "to reference" in the context of foreign keys where
+ * "table A REFERENCES table B" */
+ g_string_append_printf (string, _("references %s.%s"),
+ fk->depend_on->obj_schema,
+ fk->depend_on->obj_name);
+ g_string_append (string, " (");
+ for (i = 0; i < fk->cols_nb; i++) {
+ if (i != 0)
+ g_string_append (string, ", ");
+ g_string_append (string, fk->ref_pk_names_array [i]);
+ }
+ g_string_append (string, ")");
+
+ g_string_append (string, "\n ");
+ g_string_append (string, _("Policy on UPDATE"));
+ g_string_append (string, ": ");
+ g_string_append (string, t_utils_fk_policy_to_string
(GDA_META_TABLE_FOREIGN_KEY_ON_UPDATE_POLICY (fk)));
+ g_string_append (string, "\n ");
+ g_string_append (string, _("Policy on DELETE"));
+ g_string_append (string, ": ");
+ g_string_append (string, t_utils_fk_policy_to_string
(GDA_META_TABLE_FOREIGN_KEY_ON_DELETE_POLICY (fk)));
+
+ subres = g_new0 (ToolCommandResult, 1);
+ subres->type = BASE_TOOL_COMMAND_RESULT_TXT;
+ subres->u.txt = string;
+ res->u.multiple_results = g_slist_append (res->u.multiple_results,
+ subres);
+ }
+
+ return res;
+ }
+ }
+ else
+ TO_IMPLEMENT;
+
+ out:
+ g_object_unref (mstruct);
+ return res;
+}
+
static ToolCommandResult *
extra_command_set_output (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error)
+ TContext *console, GError **error)
{
g_assert (console);
- if (set_output_file (argv[0], error)) {
+ g_assert (global_t_app);
+ g_assert (console == global_t_app->priv->term_console);
+
+ if (t_context_set_output_file (console, argv[0], error)) {
ToolCommandResult *res;
res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_EMPTY;
+ res->type = BASE_TOOL_COMMAND_RESULT_EMPTY;
return res;
}
else
@@ -2465,48 +2172,50 @@ extra_command_set_output (ToolCommand *command, guint argc, const gchar **argv,
static ToolCommandResult *
extra_command_set_output_format (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error)
+ TContext *console, GError **error)
{
ToolCommandResult *res = NULL;
const gchar *fmt = NULL;
g_assert (console);
+ g_assert (global_t_app);
+
if (argv[0] && *argv[0])
fmt = argv[0];
- console->output_format = TOOL_OUTPUT_FORMAT_DEFAULT;
+ t_context_set_output_format (console, BASE_TOOL_OUTPUT_FORMAT_DEFAULT);
if (fmt) {
if ((*fmt == 'X') || (*fmt == 'x'))
- console->output_format = TOOL_OUTPUT_FORMAT_XML;
+ t_context_set_output_format (console, BASE_TOOL_OUTPUT_FORMAT_XML);
else if ((*fmt == 'H') || (*fmt == 'h'))
- console->output_format = TOOL_OUTPUT_FORMAT_HTML;
+ t_context_set_output_format (console, BASE_TOOL_OUTPUT_FORMAT_HTML);
else if ((*fmt == 'D') || (*fmt == 'd'))
- console->output_format = TOOL_OUTPUT_FORMAT_DEFAULT;
+ t_context_set_output_format (console, BASE_TOOL_OUTPUT_FORMAT_DEFAULT);
else if ((*fmt == 'C') || (*fmt == 'c'))
- console->output_format = TOOL_OUTPUT_FORMAT_CSV;
+ t_context_set_output_format (console, BASE_TOOL_OUTPUT_FORMAT_CSV);
else {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
_("Unknown output format: '%s', reset to default"), fmt);
goto out;
}
}
- if (!console->output_stream) {
+ if (!t_context_get_output_stream (console, NULL)) {
res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_TXT_STDOUT;
+ res->type = BASE_TOOL_COMMAND_RESULT_TXT_STDOUT;
res->u.txt = g_string_new ("");
- switch (console->output_format) {
- case TOOL_OUTPUT_FORMAT_DEFAULT:
+ switch (t_context_get_output_format (console)) {
+ case BASE_TOOL_OUTPUT_FORMAT_DEFAULT:
g_string_assign (res->u.txt, ("Output format is default\n"));
break;
- case TOOL_OUTPUT_FORMAT_HTML:
+ case BASE_TOOL_OUTPUT_FORMAT_HTML:
g_string_assign (res->u.txt, ("Output format is HTML\n"));
break;
- case TOOL_OUTPUT_FORMAT_XML:
+ case BASE_TOOL_OUTPUT_FORMAT_XML:
g_string_assign (res->u.txt, ("Output format is XML\n"));
break;
- case TOOL_OUTPUT_FORMAT_CSV:
+ case BASE_TOOL_OUTPUT_FORMAT_CSV:
g_string_assign (res->u.txt, ("Output format is CSV\n"));
break;
default:
@@ -2515,56 +2224,209 @@ extra_command_set_output_format (ToolCommand *command, guint argc, const gchar *
}
else {
res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_EMPTY;
+ res->type = BASE_TOOL_COMMAND_RESULT_EMPTY;
}
out:
- compute_term_color_attribute ();
+ t_utils_term_compute_color_attribute ();
return res;
}
-static gboolean
-idle_read_input_stream (G_GNUC_UNUSED gpointer data)
+static ToolCommandResult *
+extra_command_copyright (ToolCommand *command, guint argc, const gchar **argv,
+ TContext *console, GError **error)
{
- if (main_data->input_stream) {
- gchar *cmde;
- cmde = input_from_stream (main_data->input_stream);
- if (cmde) {
- gboolean command_ok;
- treat_line_func (cmde, &command_ok);
- g_free (cmde);
- if (command_ok)
- return TRUE; /* potentially some more work to do from the stream */
- else
- goto stop;
+ ToolCommandResult *res;
+
+ g_assert (console);
+ g_assert (global_t_app);
+
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = BASE_TOOL_COMMAND_RESULT_TXT;
+ res->u.txt = g_string_new ("This program is free software; you can redistribute it and/or modify\n"
+ "it under the terms of the GNU General Public License as published by\n"
+ "the Free Software Foundation; either version 2 of the License, or\n"
+ "(at your option) any later version.\n\n"
+ "This program is distributed in the hope that it will be useful,\n"
+ "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
+ "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
+ "GNU General Public License for more details.\n");
+ return res;
+}
+
+static ToolCommandResult *
+extra_command_option (ToolCommand *command, guint argc, const gchar **argv,
+ TContext *console, GError **error)
+{
+ ToolCommandResult *res = NULL;
+ const gchar *oname = NULL;
+ const gchar *value = NULL;
+
+ g_assert (console);
+ g_assert (global_t_app);
+
+ if (argv[0] && *argv[0]) {
+ oname = argv[0];
+ if (argv[1] && *argv[1])
+ value = argv[1];
+ }
+
+ if (oname) {
+ GdaHolder *opt = gda_set_get_holder (global_t_app->priv->options, oname);
+ if (opt) {
+ if (value) {
+ if (! gda_holder_set_value_str (opt, NULL, value, error))
+ return NULL;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = BASE_TOOL_COMMAND_RESULT_EMPTY;
+ }
+ else {
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = BASE_TOOL_COMMAND_RESULT_SET;
+ res->u.set = gda_set_new (NULL);
+ gda_set_add_holder (res->u.set, gda_holder_copy (opt));
+ }
+ }
+ else {
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
+ _("No option named '%s'"), oname);
+ return NULL;
+ }
+ }
+ else {
+ /* list parameter's values */
+ GdaDataModel *model;
+ GSList *list;
+ model = gda_data_model_array_new_with_g_types (3, G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_STRING);
+ gda_data_model_set_column_title (model, 0, _("Name"));
+ gda_data_model_set_column_title (model, 1, _("Value"));
+ gda_data_model_set_column_title (model, 2, _("Description"));
+ g_object_set_data (G_OBJECT (model), "name", _("List of options"));
+ for (list = global_t_app->priv->options->holders; list; list = list->next) {
+ gint row;
+ gchar *str;
+ GValue *value;
+ GdaHolder *opt;
+ opt = GDA_HOLDER (list->data);
+ row = gda_data_model_append_row (model, NULL);
+
+ value = gda_value_new_from_string (gda_holder_get_id (opt), G_TYPE_STRING);
+ gda_data_model_set_value_at (model, 0, row, value, NULL);
+ gda_value_free (value);
+
+ str = gda_holder_get_value_str (opt, NULL);
+ value = gda_value_new_from_string (str ? str : "(NULL)", G_TYPE_STRING);
+ gda_data_model_set_value_at (model, 1, row, value, NULL);
+ gda_value_free (value);
+
+ value = (GValue*) gda_holder_get_attribute (opt, GDA_ATTRIBUTE_DESCRIPTION);
+ gda_data_model_set_value_at (model, 2, row, value, NULL);
+ }
+
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = BASE_TOOL_COMMAND_RESULT_DATA_MODEL;
+ res->u.model = model;
+ }
+
+ return res;
+}
+
+
+static ToolCommandResult *
+extra_command_quit (ToolCommand *command, guint argc, const gchar **argv,
+ TContext *console, GError **error)
+{
+ ToolCommandResult *res;
+
+ g_assert (console);
+ g_assert (global_t_app);
+
+ g_assert (console == global_t_app->priv->term_console);
+
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = BASE_TOOL_COMMAND_RESULT_EXIT;
+ return res;
+}
+
+static ToolCommandResult *
+extra_command_cd (ToolCommand *command, guint argc, const gchar **argv,
+ TContext *console, GError **error)
+{
+ const gchar *dir = NULL;
+#define DIR_LENGTH 256
+ static char start_dir[DIR_LENGTH];
+ static gboolean init_done = FALSE;
+
+ g_assert (console);
+ g_assert (global_t_app);
+
+ if (!init_done) {
+ init_done = TRUE;
+ memset (start_dir, 0, DIR_LENGTH);
+ if (getcwd (start_dir, DIR_LENGTH) != NULL) {
+ /* default to $HOME */
+#ifdef G_OS_WIN32
+ TO_IMPLEMENT;
+ strncpy (start_dir, "/", 2);
+#else
+ struct passwd *pw;
+
+ pw = getpwuid (geteuid ());
+ if (!pw) {
+ g_set_error (error, T_ERROR, T_INTERNAL_COMMAND_ERROR,
+ _("Could not get home directory: %s"), strerror (errno));
+ return NULL;
+ }
+ else {
+ gsize l = strlen (pw->pw_dir);
+ if (l > DIR_LENGTH - 1)
+ strncpy (start_dir, "/", 2);
+ else
+ strncpy (start_dir, pw->pw_dir, l + 1);
+ }
+#endif
}
- else
- goto stop;
}
- stop:
- compute_prompt (NULL, prompt, main_data->partial_command == NULL ? FALSE : TRUE, FALSE,
- TOOL_OUTPUT_FORMAT_DEFAULT |
- (main_data->term_console->output_format & TOOL_OUTPUT_FORMAT_COLOR_TERM));
- g_print ("\n%s", prompt->str);
- fflush (NULL);
- set_input_file (NULL, NULL);
- return FALSE; /* stop calling this function */
+ if (argv[0])
+ dir = argv[0];
+ else
+ dir = start_dir;
+
+ if (dir) {
+ if (chdir (dir) == 0) {
+ ToolCommandResult *res;
+
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = BASE_TOOL_COMMAND_RESULT_TXT_STDOUT;
+ res->u.txt = g_string_new ("");
+ g_string_append_printf (res->u.txt, _("Working directory is now: %s"), dir);
+ return res;
+ }
+ else
+ g_set_error (error, T_ERROR, T_INTERNAL_COMMAND_ERROR,
+ _("Could not change working directory to '%s': %s"),
+ dir, strerror (errno));
+ }
+
+ return NULL;
}
static ToolCommandResult *
extra_command_set_input (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error)
+ TContext *console, GError **error)
{
g_assert (console);
- if (set_input_file (argv[0], error)) {
+ g_assert (global_t_app);
+
+ g_assert (console == global_t_app->priv->term_console);
+
+ if (t_term_context_set_input_file (T_TERM_CONTEXT (console), argv[0], error)) {
ToolCommandResult *res;
- g_idle_add ((GSourceFunc) idle_read_input_stream, NULL);
-
res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_EMPTY;
+ res->type = BASE_TOOL_COMMAND_RESULT_EMPTY;
return res;
}
else
@@ -2573,46 +2435,54 @@ extra_command_set_input (ToolCommand *command, guint argc, const gchar **argv,
static ToolCommandResult *
extra_command_echo (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error)
+ TContext *console, GError **error)
{
ToolCommandResult *res;
+
+ g_assert (console);
+ g_assert (global_t_app);
res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_TXT_STDOUT;
+ res->type = BASE_TOOL_COMMAND_RESULT_TXT_STDOUT;
res->u.txt = g_string_new (argv[0]);
if (argv[0][strlen (argv[0]) - 1] != '\n')
g_string_append_c (res->u.txt, '\n');
return res;
}
+
static ToolCommandResult *
extra_command_qecho (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error)
+ TContext *console, GError **error)
{
ToolCommandResult *res;
- g_assert (console);
+ g_assert (console);
+ g_assert (global_t_app);
+
res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_TXT;
+ res->type = BASE_TOOL_COMMAND_RESULT_TXT;
res->u.txt = g_string_new (argv[0]);
return res;
}
static ToolCommandResult *
extra_command_list_dsn (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error)
+ G_GNUC_UNUSED TContext *console, GError **error)
{
ToolCommandResult *res;
GList *list = NULL;
GdaDataModel *dsn_list = NULL, *model = NULL;
+ g_assert (global_t_app);
+
if (argv[0]) {
/* details about a DSN */
GdaDataModel *model;
- model = config_info_detail_dsn (argv[0], error);
+ model = t_config_info_detail_dsn (argv[0], error);
if (model) {
res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_DATA_MODEL;
+ res->type = BASE_TOOL_COMMAND_RESULT_DATA_MODEL;
res->u.model = model;
return res;
}
@@ -2658,7 +2528,7 @@ extra_command_list_dsn (ToolCommand *command, guint argc, const gchar **argv,
}
res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_DATA_MODEL;
+ res->type = BASE_TOOL_COMMAND_RESULT_DATA_MODEL;
res->u.model = model;
g_object_unref (dsn_list);
@@ -2677,14 +2547,16 @@ extra_command_list_dsn (ToolCommand *command, guint argc, const gchar **argv,
static ToolCommandResult *
extra_command_create_dsn (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error)
+ G_GNUC_UNUSED TContext *console, GError **error)
{
ToolCommandResult *res = NULL;
GdaDsnInfo newdsn;
gchar *real_cnc, *real_provider, *user, *pass;
+ g_assert (global_t_app);
+
if (!argv[0] || !argv[1]) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
"%s", _("Missing arguments"));
return NULL;
}
@@ -2705,12 +2577,12 @@ extra_command_create_dsn (ToolCommand *command, guint argc, const gchar **argv,
newdsn.is_system = FALSE;
if (!newdsn.provider) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
"%s", _("Missing provider name"));
}
else if (gda_config_define_dsn (&newdsn, error)) {
res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_EMPTY;
+ res->type = BASE_TOOL_COMMAND_RESULT_EMPTY;
}
g_free (real_cnc);
@@ -2723,13 +2595,15 @@ extra_command_create_dsn (ToolCommand *command, guint argc, const gchar **argv,
static ToolCommandResult *
extra_command_remove_dsn (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error)
+ G_GNUC_UNUSED TContext *console, GError **error)
{
ToolCommandResult *res;
gint i;
+ g_assert (global_t_app);
+
if (!argv[0]) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
"%s", _("Missing DSN name"));
return NULL;
}
@@ -2739,25 +2613,27 @@ extra_command_remove_dsn (ToolCommand *command, guint argc, const gchar **argv,
}
res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_EMPTY;
+ res->type = BASE_TOOL_COMMAND_RESULT_EMPTY;
return res;
}
static ToolCommandResult *
extra_command_list_providers (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error)
+ G_GNUC_UNUSED TContext *console, GError **error)
{
ToolCommandResult *res;
GdaDataModel *model;
+ g_assert (global_t_app);
+
if (argv[0])
- model = config_info_detail_provider (argv[0], error);
+ model = t_config_info_detail_provider (argv[0], error);
else
- model = config_info_list_all_providers ();
+ model = t_config_info_list_all_providers ();
if (model) {
res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_DATA_MODEL;
+ res->type = BASE_TOOL_COMMAND_RESULT_DATA_MODEL;
res->u.model = model;
return res;
}
@@ -2773,8 +2649,10 @@ vconnection_hub_foreach_cb (G_GNUC_UNUSED GdaConnection *cnc, const gchar *ns, G
}
static gchar **
-extra_command_manage_cnc_compl (const gchar *text)
+extra_command_manage_cnc_compl (const gchar *text, gpointer user_data)
{
+ TApp *main_data = (TApp*) user_data;
+
GArray *array = NULL;
gsize len;
gint i, ndsn;
@@ -2796,13 +2674,13 @@ extra_command_manage_cnc_compl (const gchar *text)
/* complete with opened connections */
GSList *list;
- for (list = main_data->settings; list; list = list->next) {
- ConnectionSetting *cs = (ConnectionSetting *) list->data;
- if (!len || !strncmp (cs->name, text, len)) {
+ for (list = main_data->priv->tcnc_list; list; list = list->next) {
+ TConnection *tcnc = (TConnection *) list->data;
+ if (!len || !strncmp (t_connection_get_name (tcnc), text, len)) {
if (!array)
array = g_array_new (TRUE, FALSE, sizeof (gchar*));
gchar *tmp;
- tmp = g_strdup (cs->name);
+ tmp = g_strdup (t_connection_get_name (tcnc));
g_array_append_val (array, tmp);
}
}
@@ -2816,12 +2694,13 @@ extra_command_manage_cnc_compl (const gchar *text)
static
ToolCommandResult *
extra_command_manage_cnc (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error)
+ TContext *console, GError **error)
{
g_assert (console);
+ g_assert (global_t_app);
if (argc > 2) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
_("Too many arguments"));
return NULL;
}
@@ -2834,95 +2713,93 @@ extra_command_manage_cnc (ToolCommand *command, guint argc, const gchar **argv,
const gchar *dsn = NULL;
if (!argv[1]) {
/* try to switch to an existing connection */
- ConnectionSetting *cs;
+ TConnection *tcnc;
- cs = find_connection_from_name (argv[0]);
- if (cs) {
+ tcnc = t_connection_get_by_name (argv[0]);
+ if (tcnc) {
ToolCommandResult *res;
res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_EMPTY;
- console->current = cs;
+ res->type = BASE_TOOL_COMMAND_RESULT_EMPTY;
+ t_context_set_connection (console, tcnc);
return res;
}
else {
if (*argv [0] == '~') {
/* find connection for which we want the meta store's connection */
if (*(argv[0] + 1)) {
- cs = find_connection_from_name (argv[0] + 1);
- if (!cs) {
- g_set_error (error, GDA_TOOLS_ERROR,
- GDA_TOOLS_NO_CONNECTION_ERROR,
+ tcnc = t_connection_get_by_name (argv[0] + 1);
+ if (!tcnc) {
+ g_set_error (error, T_ERROR,
+ T_NO_CONNECTION_ERROR,
_("No connection named '%s' found"),
argv[0] + 1);
return NULL;
}
}
else
- cs = console->current;
+ tcnc = t_context_get_connection (console);
- if (!cs) {
- g_set_error (error, GDA_TOOLS_ERROR,
GDA_TOOLS_NO_CONNECTION_ERROR,
+ if (!tcnc) {
+ g_set_error (error, T_ERROR, T_NO_CONNECTION_ERROR,
"%s", _("No current connection"));
return NULL;
}
/* find if requested connection already exists */
- ConnectionSetting *ncs = NULL;
- if (* (cs->name) == '~')
- ncs = find_connection_from_name (console->current->name + 1);
+ TConnection *ntcnc = NULL;
+ if (* (t_connection_get_name (tcnc)) == '~')
+ ntcnc = t_connection_get_by_name (t_connection_get_name
(t_context_get_connection (console)) + 1);
else {
gchar *tmp;
- tmp = g_strdup_printf ("~%s", cs->name);
- ncs = find_connection_from_name (tmp);
+ tmp = g_strdup_printf ("~%s", t_connection_get_name (tcnc));
+ ntcnc = t_connection_get_by_name (tmp);
g_free (tmp);
}
- if (ncs) {
+ if (ntcnc) {
ToolCommandResult *res;
res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_EMPTY;
- console->current = ncs;
+ res->type = BASE_TOOL_COMMAND_RESULT_EMPTY;
+ t_context_set_connection (console, ntcnc);
return res;
}
/* open a new connection */
- ncs = g_new0 (ConnectionSetting, 1);
GdaMetaStore *store;
ToolCommandResult *res;
- ncs->name = g_strdup_printf ("~%s", cs->name);
- store = gda_connection_get_meta_store (cs->cnc);
- ncs->cnc = gda_meta_store_get_internal_connection (store);
- g_object_ref (ncs->cnc);
- ncs->parser = gda_connection_create_parser (ncs->cnc);
- if (!cs->parser)
- cs->parser = gda_sql_parser_new ();
- ncs->query_buffer = NULL;
- ncs->threader = NULL;
- ncs->meta_job_id = 0;
-
- main_data->settings = g_slist_append (main_data->settings, ncs);
- console->current = ncs;
+
+ store = gda_connection_get_meta_store (t_connection_get_cnc (tcnc));
+ ntcnc = t_connection_new (gda_meta_store_get_internal_connection
(store));
+ gchar *tmp;
+ tmp = g_strdup_printf ("~%s", t_connection_get_name (tcnc));
+ t_connection_set_name (ntcnc, tmp);
+ g_free (tmp);
+
+ t_context_set_connection (console, ntcnc);
GError *lerror = NULL;
- if (!console->output_stream) {
+ FILE *output_stream;
+ output_stream = t_context_get_output_stream (console, NULL);
+ if (!output_stream) {
g_print (_("Getting database schema information, "
"this may take some time... "));
fflush (stdout);
}
- if (!gda_connection_update_meta_store (ncs->cnc, NULL, &lerror)) {
- if (!console->output_stream)
+ if (!gda_connection_update_meta_store (t_connection_get_cnc (ntcnc),
+ NULL, &lerror)) {
+ if (!output_stream)
g_print (_("error: %s\n"),
lerror && lerror->message ? lerror->message
: _("No detail"));
if (lerror)
g_error_free (lerror);
}
else
- if (!console->output_stream)
+ if (!output_stream)
g_print (_("Done.\n"));
res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_EMPTY;
+ res->type = BASE_TOOL_COMMAND_RESULT_EMPTY;
return res;
}
@@ -2934,20 +2811,22 @@ extra_command_manage_cnc (ToolCommand *command, guint argc, const gchar **argv,
if (dsn) {
/* open a new connection */
- ConnectionSetting *cs;
+ TConnection *tcnc;
- cs = find_connection_from_name (argv[0]);
- if (cs) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ tcnc = t_connection_get_by_name (argv[0]);
+ if (tcnc) {
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
_("A connection named '%s' already exists"), argv[0]);
return NULL;
}
- cs = open_connection (console, argv[0], dsn, error);
- if (cs) {
+ tcnc = t_connection_open (argv[0], dsn, NULL, (console == t_app_get_term_console ())
? TRUE : FALSE, error);
+ if (tcnc) {
+ t_context_set_connection (console, tcnc);
+
ToolCommandResult *res;
res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_EMPTY;
+ res->type = BASE_TOOL_COMMAND_RESULT_EMPTY;
return res;
}
else
@@ -2962,9 +2841,9 @@ extra_command_manage_cnc (ToolCommand *command, guint argc, const gchar **argv,
GSList *list;
ToolCommandResult *res;
- if (! main_data->settings) {
+ if (! global_t_app->priv->tcnc_list) {
res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_TXT;
+ res->type = BASE_TOOL_COMMAND_RESULT_TXT;
res->u.txt = g_string_new (_("No opened connection"));
return res;
}
@@ -2980,8 +2859,8 @@ extra_command_manage_cnc (ToolCommand *command, guint argc, const gchar **argv,
gda_data_model_set_column_title (model, 3, _("Username"));
g_object_set_data (G_OBJECT (model), "name", _("List of opened connections"));
- for (list = main_data->settings; list; list = list->next) {
- ConnectionSetting *cs = (ConnectionSetting *) list->data;
+ for (list = global_t_app->priv->tcnc_list; list; list = list->next) {
+ TConnection *tcnc = (TConnection *) list->data;
GValue *value;
gint row;
const gchar *cstr;
@@ -2989,38 +2868,38 @@ extra_command_manage_cnc (ToolCommand *command, guint argc, const gchar **argv,
row = gda_data_model_append_row (model, NULL);
- value = gda_value_new_from_string (cs->name, G_TYPE_STRING);
+ value = gda_value_new_from_string (t_connection_get_name (tcnc), G_TYPE_STRING);
gda_data_model_set_value_at (model, 0, row, value, NULL);
gda_value_free (value);
- prov = gda_connection_get_provider (cs->cnc);
+ prov = gda_connection_get_provider (t_connection_get_cnc (tcnc));
if (GDA_IS_VPROVIDER_HUB (prov))
value = gda_value_new_from_string ("", G_TYPE_STRING);
else
- value = gda_value_new_from_string (gda_connection_get_provider_name
(cs->cnc), G_TYPE_STRING);
+ value = gda_value_new_from_string (gda_connection_get_provider_name
(t_connection_get_cnc (tcnc)), G_TYPE_STRING);
gda_data_model_set_value_at (model, 1, row, value, NULL);
gda_value_free (value);
if (GDA_IS_VPROVIDER_HUB (prov)) {
GString *string = g_string_new ("");
- gda_vconnection_hub_foreach (GDA_VCONNECTION_HUB (cs->cnc),
+ gda_vconnection_hub_foreach (GDA_VCONNECTION_HUB (t_connection_get_cnc
(tcnc)),
(GdaVConnectionHubFunc)
vconnection_hub_foreach_cb, string);
value = gda_value_new_from_string (string->str, G_TYPE_STRING);
g_string_free (string, TRUE);
}
else {
- cstr = gda_connection_get_dsn (cs->cnc);
+ cstr = gda_connection_get_dsn (t_connection_get_cnc (tcnc));
if (cstr)
value = gda_value_new_from_string (cstr, G_TYPE_STRING);
else
- value = gda_value_new_from_string (gda_connection_get_cnc_string
(cs->cnc), G_TYPE_STRING);
+ value = gda_value_new_from_string (gda_connection_get_cnc_string
(t_connection_get_cnc (tcnc)), G_TYPE_STRING);
}
gda_data_model_set_value_at (model, 2, row, value, NULL);
gda_value_free (value);
/* only get USERNAME from the the authentication string */
GdaQuarkList* ql;
- cstr = gda_connection_get_authentication (cs->cnc);
+ cstr = gda_connection_get_authentication (t_connection_get_cnc (tcnc));
ql = gda_quark_list_new_from_string (cstr);
cstr = gda_quark_list_find (ql, "USERNAME");
value = gda_value_new_from_string (cstr ? cstr : "", G_TYPE_STRING);
@@ -3030,115 +2909,90 @@ extra_command_manage_cnc (ToolCommand *command, guint argc, const gchar **argv,
}
res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_DATA_MODEL;
+ res->type = BASE_TOOL_COMMAND_RESULT_DATA_MODEL;
res->u.model = model;
return res;
}
}
-static void
-handle_close_cnc (SqlConsole *console, ConnectionSetting *cs, GdaConnection *cnc)
-{
- g_assert (console);
- if (!cs) {
- /* handle closed @cnc */
- GSList *list;
- for (list = main_data->settings; list; list = list->next) {
- if (((ConnectionSetting *) list->data)->cnc == cnc) {
- cs = (ConnectionSetting *) list->data;
- break;
- }
- }
- }
-
- if (console->current == cs) {
- gint index;
- ConnectionSetting *ncs = NULL;
- index = g_slist_index (main_data->settings, cs);
- if (index == 0)
- ncs = g_slist_nth_data (main_data->settings, index + 1);
- else
- ncs = g_slist_nth_data (main_data->settings, index - 1);
- console->current = ncs;
- }
- main_data->settings = g_slist_remove (main_data->settings, cs);
- connection_settings_free (cs);
-}
-
-static void
-conn_closed_cb (GdaConnection *cnc, G_GNUC_UNUSED gpointer data)
-{
- handle_close_cnc (NULL, NULL, cnc);
-}
-
static
ToolCommandResult *
extra_command_close_cnc (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error)
+ TContext *console, GError **error)
{
+ g_assert (console);
+ g_assert (global_t_app);
+
if (argc == 0) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
- _("No connection specified"));
- return NULL;
+ TConnection *tcnc = NULL;
+ tcnc = t_context_get_connection (console);
+ if (!tcnc) {
+ g_set_error (error, T_ERROR, T_NO_CONNECTION_ERROR,
+ _("No connection specified"));
+ return NULL;
+ }
+ else
+ t_connection_close (tcnc);
}
else {
guint i;
for (i = 0; i < argc; i++) {
- ConnectionSetting *cs = NULL;
+ TConnection *tcnc = NULL;
if (argv[i] && *argv[i])
- cs = find_connection_from_name (argv[0]);
- if (!cs) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
+ tcnc = t_connection_get_by_name (argv[0]);
+ if (!tcnc) {
+ g_set_error (error, T_ERROR, T_NO_CONNECTION_ERROR,
_("No connection named '%s' found"), argv[0]);
return NULL;
}
-
- handle_close_cnc (console, cs, NULL);
+ t_connection_close (tcnc);
}
}
ToolCommandResult *res;
res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_EMPTY;
+ res->type = BASE_TOOL_COMMAND_RESULT_EMPTY;
return res;
}
static ToolCommandResult *
extra_command_bind_cnc (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error)
+ TContext *console, GError **error)
{
- ConnectionSetting *cs = NULL;
+ TConnection *tcnc = NULL;
gint i, nargv = g_strv_length ((gchar **) argv);
static GdaVirtualProvider *vprovider = NULL;
GdaConnection *virtual;
GString *string;
g_assert (console);
+ g_assert (global_t_app);
+
if (nargv < 2) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
"%s", _("Missing required connection names"));
return NULL;
}
/* check for connections existance */
- cs = find_connection_from_name (argv[0]);
- if (cs) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ tcnc = t_connection_get_by_name (argv[0]);
+ if (tcnc) {
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
_("A connection named '%s' already exists"), argv[0]);
return NULL;
}
- if (! connection_name_is_valid (argv[0])) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ if (! t_connection_name_is_valid (argv[0])) {
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
_("Connection name '%s' is invalid"), argv[0]);
return NULL;
}
for (i = 1; i < nargv; i++) {
- cs = find_connection_from_name (argv[i]);
- if (!cs) {
+ tcnc = t_connection_get_by_name (argv[i]);
+ if (!tcnc) {
GdaDataModel *src;
- src = g_hash_table_lookup (main_data->mem_data_models, argv[i]);
+ src = g_hash_table_lookup (global_t_app->priv->mem_data_models, argv[i]);
if (!src) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
_("No connection or dataset named '%s' found"), argv[i]);
return NULL;
}
@@ -3152,7 +3006,7 @@ extra_command_bind_cnc (ToolCommand *command, guint argc, const gchar **argv,
virtual = gda_virtual_connection_open (vprovider, GDA_CONNECTION_OPTIONS_AUTO_META_DATA, NULL);
if (!virtual) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (error, T_ERROR, T_INTERNAL_COMMAND_ERROR,
"%s", _("Could not create virtual connection"));
return NULL;
}
@@ -3162,10 +3016,10 @@ extra_command_bind_cnc (ToolCommand *command, guint argc, const gchar **argv,
/* add existing connections to virtual connection */
string = g_string_new (_("Bound connections are as:"));
for (i = 1; i < nargv; i++) {
- cs = find_connection_from_name (argv[i]);
- if (cs) {
+ tcnc = t_connection_get_by_name (argv[i]);
+ if (tcnc) {
if (!gda_vconnection_hub_add (GDA_VCONNECTION_HUB (virtual),
- cs->cnc, argv[i], error)) {
+ t_connection_get_cnc (tcnc), argv[i], error)) {
g_object_unref (virtual);
g_string_free (string, TRUE);
return NULL;
@@ -3177,7 +3031,7 @@ extra_command_bind_cnc (ToolCommand *command, guint argc, const gchar **argv,
}
else {
GdaDataModel *src;
- src = g_hash_table_lookup (main_data->mem_data_models, argv[i]);
+ src = g_hash_table_lookup (global_t_app->priv->mem_data_models, argv[i]);
if (! gda_vconnection_data_model_add_model (GDA_VCONNECTION_DATA_MODEL (virtual),
src, argv[i], error)) {
g_object_unref (virtual);
@@ -3192,195 +3046,21 @@ extra_command_bind_cnc (ToolCommand *command, guint argc, const gchar **argv,
}
}
- cs = g_new0 (ConnectionSetting, 1);
- cs->name = g_strdup (argv[0]);
- cs->cnc = virtual;
- cs->parser = gda_connection_create_parser (virtual);
- cs->query_buffer = NULL;
- cs->threader = NULL;
- cs->meta_job_id = 0;
-
- main_data->settings = g_slist_append (main_data->settings, cs);
- console->current = cs;
+ tcnc = t_connection_new (virtual);
+ t_connection_set_name (tcnc, argv[0]);
+ t_context_set_connection (console, tcnc);
ToolCommandResult *res;
res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_TXT;
+ res->type = BASE_TOOL_COMMAND_RESULT_TXT;
res->u.txt = string;
return res;
}
static ToolCommandResult *
-extra_command_copyright (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error)
-{
- ToolCommandResult *res;
-
- res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_TXT;
- res->u.txt = g_string_new ("This program is free software; you can redistribute it and/or modify\n"
- "it under the terms of the GNU General Public License as published by\n"
- "the Free Software Foundation; either version 2 of the License, or\n"
- "(at your option) any later version.\n\n"
- "This program is distributed in the hope that it will be useful,\n"
- "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
- "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
- "GNU General Public License for more details.\n");
- return res;
-}
-
-static ToolCommandResult *
-extra_command_option (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error)
-{
- ToolCommandResult *res = NULL;
- const gchar *oname = NULL;
- const gchar *value = NULL;
-
- if (argv[0] && *argv[0]) {
- oname = argv[0];
- if (argv[1] && *argv[1])
- value = argv[1];
- }
-
- if (oname) {
- GdaHolder *opt = gda_set_get_holder (main_data->options, oname);
- if (opt) {
- if (value) {
- if (! gda_holder_set_value_str (opt, NULL, value, error))
- return NULL;
- res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_EMPTY;
- }
- else {
- res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_SET;
- res->u.set = gda_set_new (NULL);
- gda_set_add_holder (res->u.set, gda_holder_copy (opt));
- }
- }
- else {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
- _("No option named '%s'"), oname);
- return NULL;
- }
- }
- else {
- /* list parameter's values */
- GdaDataModel *model;
- GSList *list;
- model = gda_data_model_array_new_with_g_types (3, G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_STRING);
- gda_data_model_set_column_title (model, 0, _("Name"));
- gda_data_model_set_column_title (model, 1, _("Value"));
- gda_data_model_set_column_title (model, 2, _("Description"));
- g_object_set_data (G_OBJECT (model), "name", _("List of options"));
- for (list = main_data->options->holders; list; list = list->next) {
- gint row;
- gchar *str;
- GValue *value;
- GdaHolder *opt;
- opt = GDA_HOLDER (list->data);
- row = gda_data_model_append_row (model, NULL);
-
- value = gda_value_new_from_string (gda_holder_get_id (opt), G_TYPE_STRING);
- gda_data_model_set_value_at (model, 0, row, value, NULL);
- gda_value_free (value);
-
- str = gda_holder_get_value_str (opt, NULL);
- value = gda_value_new_from_string (str ? str : "(NULL)", G_TYPE_STRING);
- gda_data_model_set_value_at (model, 1, row, value, NULL);
- gda_value_free (value);
-
- value = (GValue*) gda_holder_get_attribute (opt, GDA_ATTRIBUTE_DESCRIPTION);
- gda_data_model_set_value_at (model, 2, row, value, NULL);
- }
-
- res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_DATA_MODEL;
- res->u.model = model;
- }
-
- return res;
-}
-
-static ToolCommandResult *
-extra_command_quit (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error)
-{
- ToolCommandResult *res;
-
- g_assert (console);
- res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_EXIT;
- return res;
-}
-
-static ToolCommandResult *
-extra_command_cd (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error)
-{
- const gchar *dir = NULL;
-#define DIR_LENGTH 256
- static char start_dir[DIR_LENGTH];
- static gboolean init_done = FALSE;
-
- g_assert (console);
- if (!init_done) {
- init_done = TRUE;
- memset (start_dir, 0, DIR_LENGTH);
- if (getcwd (start_dir, DIR_LENGTH) != NULL) {
- /* default to $HOME */
-#ifdef G_OS_WIN32
- TO_IMPLEMENT;
- strncpy (start_dir, "/", 2);
-#else
- struct passwd *pw;
-
- pw = getpwuid (geteuid ());
- if (!pw) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
- _("Could not get home directory: %s"), strerror (errno));
- return NULL;
- }
- else {
- gsize l = strlen (pw->pw_dir);
- if (l > DIR_LENGTH - 1)
- strncpy (start_dir, "/", 2);
- else
- strncpy (start_dir, pw->pw_dir, l + 1);
- }
-#endif
- }
- }
-
- if (argv[0])
- dir = argv[0];
- else
- dir = start_dir;
-
- if (dir) {
- if (chdir (dir) == 0) {
- ToolCommandResult *res;
-
- res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_TXT_STDOUT;
- res->u.txt = g_string_new ("");
- g_string_append_printf (res->u.txt, _("Working directory is now: %s"), dir);
- return res;
- }
- else
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
- _("Could not change working directory to '%s': %s"),
- dir, strerror (errno));
- }
-
- return NULL;
-}
-
-static ToolCommandResult *
extra_command_edit_buffer (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error)
+ TContext *console, GError **error)
{
gchar *filename = NULL;
static gchar *editor_name = NULL;
@@ -3388,15 +3068,16 @@ extra_command_edit_buffer (ToolCommand *command, guint argc, const gchar **argv,
gint systemres;
ToolCommandResult *res = NULL;
- if (!console->current) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
+ g_assert (console);
+ g_assert (global_t_app);
+ g_assert (console == global_t_app->priv->term_console);
+
+ if (!t_context_get_connection (console)) {
+ g_set_error (error, T_ERROR, T_NO_CONNECTION_ERROR,
"%s", _("No connection opened"));
goto end_of_command;
}
- if (!console->current->query_buffer)
- console->current->query_buffer = g_string_new ("");
-
if (argv[0] && *argv[0])
filename = (gchar *) argv[0];
else {
@@ -3405,13 +3086,19 @@ extra_command_edit_buffer (ToolCommand *command, guint argc, const gchar **argv,
fd = g_file_open_tmp (NULL, &filename, error);
if (fd < 0)
goto end_of_command;
- if (write (fd, console->current->query_buffer->str,
- console->current->query_buffer->len) != (gint)console->current->query_buffer->len)
{
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
- _("Could not write to temporary file '%s': %s"),
- filename, strerror (errno));
- close (fd);
- goto end_of_command;
+
+ const gchar *tmp;
+ tmp = t_connection_get_query_buffer (t_context_get_connection (console));
+ if (tmp) {
+ ssize_t len;
+ len = strlen (tmp);
+ if (write (fd, tmp, len) != len) {
+ g_set_error (error, T_ERROR, T_INTERNAL_COMMAND_ERROR,
+ _("Could not write to temporary file '%s': %s"),
+ filename, strerror (errno));
+ close (fd);
+ goto end_of_command;
+ }
}
close (fd);
}
@@ -3443,12 +3130,12 @@ extra_command_edit_buffer (ToolCommand *command, guint argc, const gchar **argv,
systemres = system (edit_command);
if (systemres == -1) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (error, T_ERROR, T_INTERNAL_COMMAND_ERROR,
_("could not start editor '%s'"), editor_name);
goto end_of_command;
}
else if (systemres == 127) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (error, T_ERROR, T_INTERNAL_COMMAND_ERROR,
"%s", _("Could not start /bin/sh"));
goto end_of_command;
}
@@ -3458,13 +3145,13 @@ extra_command_edit_buffer (ToolCommand *command, guint argc, const gchar **argv,
if (!g_file_get_contents (filename, &str, NULL, error))
goto end_of_command;
- g_string_assign (console->current->query_buffer, str);
+ t_connection_set_query_buffer (t_context_get_connection (console), str);
g_free (str);
}
}
res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_EMPTY;
+ res->type = BASE_TOOL_COMMAND_RESULT_EMPTY;
end_of_command:
@@ -3477,23 +3164,23 @@ extra_command_edit_buffer (ToolCommand *command, guint argc, const gchar **argv,
return res;
}
+
static ToolCommandResult *
extra_command_reset_buffer (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error)
+ TContext *console, GError **error)
{
ToolCommandResult *res = NULL;
- if (!console->current) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
+ g_assert (console);
+ g_assert (global_t_app);
+ g_assert (console == global_t_app->priv->term_console);
+
+ if (!t_context_get_connection (console)) {
+ g_set_error (error, T_ERROR, T_NO_CONNECTION_ERROR,
"%s", _("No connection opened"));
return NULL;
}
- if (!console->current->query_buffer)
- console->current->query_buffer = g_string_new ("");
- else
- g_string_assign (console->current->query_buffer, "");
-
if (argv[0]) {
const gchar *filename = NULL;
gchar *str;
@@ -3502,47 +3189,51 @@ extra_command_reset_buffer (ToolCommand *command, guint argc, const gchar **argv
if (!g_file_get_contents (filename, &str, NULL, error))
return NULL;
- g_string_assign (console->current->query_buffer, str);
+ t_connection_set_query_buffer (t_context_get_connection (console), str);
g_free (str);
}
res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_EMPTY;
+ res->type = BASE_TOOL_COMMAND_RESULT_EMPTY;
return res;
}
static ToolCommandResult *
extra_command_show_buffer (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error)
+ TContext *console, GError **error)
{
ToolCommandResult *res = NULL;
g_assert (console);
- if (!console->current) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
+ g_assert (global_t_app);
+ g_assert (console == global_t_app->priv->term_console);
+
+ if (!t_context_get_connection (console)) {
+ g_set_error (error, T_ERROR, T_NO_CONNECTION_ERROR,
"%s", _("No connection opened"));
return NULL;
}
- if (!console->current->query_buffer)
- console->current->query_buffer = g_string_new ("");
res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_TXT;
- res->u.txt = g_string_new (console->current->query_buffer->str);
+ res->type = BASE_TOOL_COMMAND_RESULT_TXT;
+ res->u.txt = g_string_new (t_connection_get_query_buffer (t_context_get_connection (console)));
return res;
}
static ToolCommandResult *
extra_command_exec_buffer (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error)
+ TContext *console, GError **error)
{
ToolCommandResult *res = NULL;
g_assert (console);
- if (!console->current) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
+ g_assert (global_t_app);
+ g_assert (console == global_t_app->priv->term_console);
+
+ if (!t_context_get_connection (console)) {
+ g_set_error (error, T_ERROR, T_NO_CONNECTION_ERROR,
"%s", _("No connection opened"));
return NULL;
}
@@ -3552,18 +3243,18 @@ extra_command_exec_buffer (ToolCommand *command, guint argc, const gchar **argv,
res = extra_command_query_buffer_from_dict (command, argc, argv, console, error);
if (!res)
return NULL;
- tool_command_result_free (res);
+ base_tool_command_result_free (res);
res = NULL;
}
- if (!console->current->query_buffer)
- console->current->query_buffer = g_string_new ("");
- if (*console->current->query_buffer->str != 0)
- res = command_execute (console, console->current->query_buffer->str,
- GDA_STATEMENT_MODEL_RANDOM_ACCESS, error);
+ const gchar *tmp;
+ tmp = t_connection_get_query_buffer (t_context_get_connection (console));
+ if (tmp && (*tmp != 0))
+ res = t_context_command_execute (console, tmp,
+ GDA_STATEMENT_MODEL_RANDOM_ACCESS, error);
else {
res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_EMPTY;
+ res->type = BASE_TOOL_COMMAND_RESULT_EMPTY;
}
return res;
@@ -3571,26 +3262,29 @@ extra_command_exec_buffer (ToolCommand *command, guint argc, const gchar **argv,
static ToolCommandResult *
extra_command_write_buffer (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error)
+ TContext *console, GError **error)
{
ToolCommandResult *res = NULL;
g_assert (console);
- if (!console->current) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
+ g_assert (global_t_app);
+ g_assert (console == global_t_app->priv->term_console);
+
+ if (!t_context_get_connection (console)) {
+ g_set_error (error, T_ERROR, T_NO_CONNECTION_ERROR,
"%s", _("No connection opened"));
return NULL;
}
- if (!console->current->query_buffer)
- console->current->query_buffer = g_string_new ("");
if (!argv[0])
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
"%s", _("Missing FILE to write to"));
else {
- if (g_file_set_contents (argv[0], console->current->query_buffer->str, -1, error)) {
+ const gchar *tmp;
+ tmp = t_connection_get_query_buffer (t_context_get_connection (console));
+ if (g_file_set_contents (argv[0], tmp ? tmp : "", -1, error)) {
res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_EMPTY;
+ res->type = BASE_TOOL_COMMAND_RESULT_EMPTY;
}
}
@@ -3607,14 +3301,16 @@ extra_command_write_buffer (ToolCommand *command, guint argc, const gchar **argv
static ToolCommandResult *
extra_command_query_buffer_list_dict (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error)
+ TContext *console, GError **error)
{
ToolCommandResult *res = NULL;
GdaDataModel *retmodel;
g_assert (console);
- if (!console->current) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
+ g_assert (global_t_app);
+
+ if (!t_context_get_connection (console)) {
+ g_set_error (error, T_ERROR, T_NO_CONNECTION_ERROR,
"%s", _("No connection opened"));
return NULL;
}
@@ -3626,23 +3322,20 @@ extra_command_query_buffer_list_dict (ToolCommand *command, guint argc, const gc
gda_data_model_set_column_title (retmodel, 2, _("SQL"));
GdaMetaStore *mstore;
- mstore = gda_connection_get_meta_store (console->current->cnc);
+ mstore = gda_connection_get_meta_store (t_connection_get_cnc (t_context_get_connection (console)));
- /* Use tools favorites */
- if (! console->current->favorites)
- console->current->favorites = gda_tools_favorites_new (mstore);
GSList *favlist, *list;
GError *lerror = NULL;
- favlist = gda_tools_favorites_list (console->current->favorites, 0, GDA_TOOLS_FAVORITES_QUERIES,
- ORDER_KEY_QUERIES, &lerror);
+ favlist = t_favorites_list (t_connection_get_favorites (t_context_get_connection (console)), 0,
T_FAVORITES_QUERIES,
+ ORDER_KEY_QUERIES, &lerror);
if (lerror) {
g_propagate_error (error, lerror);
g_object_unref (retmodel);
return NULL;
}
for (list = favlist; list; list = list->next) {
- ToolsFavoritesAttributes *att = (ToolsFavoritesAttributes*) list->data;
+ TFavoritesAttributes *att = (TFavoritesAttributes*) list->data;
gint i;
GValue *value = NULL;
i = gda_data_model_append_row (retmodel, error);
@@ -3661,18 +3354,18 @@ extra_command_query_buffer_list_dict (ToolCommand *command, guint argc, const gc
continue;
cleanloop:
gda_value_free (value);
- gda_tools_favorites_free_list (favlist);
+ t_favorites_free_list (favlist);
g_object_unref (retmodel);
return NULL;
}
if (favlist)
- gda_tools_favorites_free_list (favlist);
+ t_favorites_free_list (favlist);
/* Use query buffer which used to be stored differently in previous versions of GdaSql:
* in the "gda_sql_query_buffers" table */
GdaStatement *sel_stmt = NULL;
GdaDataModel *model;
- sel_stmt = gda_sql_parser_parse_string (console->current->parser,
+ sel_stmt = gda_sql_parser_parse_string (t_connection_get_parser (t_context_get_connection (console)),
QUERY_BUFFERS_TABLE_SELECT, NULL, NULL);
g_assert (sel_stmt);
GdaConnection *store_cnc;
@@ -3702,7 +3395,7 @@ extra_command_query_buffer_list_dict (ToolCommand *command, guint argc, const gc
}
res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_DATA_MODEL;
+ res->type = BASE_TOOL_COMMAND_RESULT_DATA_MODEL;
res->u.model = retmodel;
return res;
@@ -3710,56 +3403,52 @@ extra_command_query_buffer_list_dict (ToolCommand *command, guint argc, const gc
static ToolCommandResult *
extra_command_query_buffer_to_dict (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error)
+ TContext *console, GError **error)
{
ToolCommandResult *res = NULL;
g_assert (console);
- if (!console->current) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
+ g_assert (global_t_app);
+
+ if (!t_context_get_connection (console)) {
+ g_set_error (error, T_ERROR, T_NO_CONNECTION_ERROR,
"%s", _("No connection opened"));
return NULL;
}
- if (!console->current->query_buffer)
- console->current->query_buffer = g_string_new ("");
-
- if (*console->current->query_buffer->str != 0) {
+ const gchar *tmp;
+ tmp = t_connection_get_query_buffer (t_context_get_connection (console));
+ if (tmp && (*tmp != 0)) {
/* find a suitable name */
gchar *qname;
if (argv[0] && *argv[0])
qname = g_strdup ((gchar *) argv[0]);
else {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
"%s", _("Missing query buffer name"));
return NULL;
}
/* Use tools favorites */
- GdaMetaStore *mstore;
- mstore = gda_connection_get_meta_store (console->current->cnc);
- if (! console->current->favorites)
- console->current->favorites = gda_tools_favorites_new (mstore);
-
- ToolsFavoritesAttributes att;
+ TFavoritesAttributes att;
att.id = -1;
- att.type = GDA_TOOLS_FAVORITES_QUERIES;
+ att.type = T_FAVORITES_QUERIES;
att.name = qname;
att.descr = NULL;
- att.contents = console->current->query_buffer->str;
+ att.contents = (gchar*) tmp;
- if (! gda_tools_favorites_add (console->current->favorites, 0,
- &att, ORDER_KEY_QUERIES, G_MAXINT, error)) {
+ if (! t_favorites_add (t_connection_get_favorites (t_context_get_connection (console)), 0,
+ &att, ORDER_KEY_QUERIES, G_MAXINT, error)) {
g_free (qname);
return NULL;
}
g_free (qname);
res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_EMPTY;
+ res->type = BASE_TOOL_COMMAND_RESULT_EMPTY;
}
else
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (error, T_ERROR, T_INTERNAL_COMMAND_ERROR,
"%s", _("Query buffer is empty"));
return res;
@@ -3767,36 +3456,33 @@ extra_command_query_buffer_to_dict (ToolCommand *command, guint argc, const gcha
static ToolCommandResult *
extra_command_query_buffer_from_dict (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error)
+ TContext *console, GError **error)
{
ToolCommandResult *res = NULL;
g_assert (console);
- if (!console->current) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
+ g_assert (global_t_app);
+
+ if (!t_context_get_connection (console)) {
+ g_set_error (error, T_ERROR, T_NO_CONNECTION_ERROR,
"%s", _("No connection opened"));
return NULL;
}
- if (!console->current->query_buffer)
- console->current->query_buffer = g_string_new ("");
-
if (argv[0] && *argv[0]) {
/* Use tools favorites */
GdaMetaStore *mstore;
- mstore = gda_connection_get_meta_store (console->current->cnc);
- if (! console->current->favorites)
- console->current->favorites = gda_tools_favorites_new (mstore);
+ mstore = gda_connection_get_meta_store (t_connection_get_cnc (t_context_get_connection
(console)));
- ToolsFavoritesAttributes att;
+ TFavoritesAttributes att;
gint favid;
- favid = gda_tools_favorites_find_by_name (console->current->favorites, 0,
- GDA_TOOLS_FAVORITES_QUERIES,
- argv[0], &att, NULL);
+ favid = t_favorites_find_by_name (t_connection_get_favorites (t_context_get_connection
(console)), 0,
+ T_FAVORITES_QUERIES,
+ argv[0], &att, NULL);
if (favid >= 0) {
- g_string_assign (console->current->query_buffer, att.contents);
+ t_connection_set_query_buffer (t_context_get_connection (console), att.contents);
res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_EMPTY;
+ res->type = BASE_TOOL_COMMAND_RESULT_EMPTY;
}
else {
/* query retrieval */
@@ -3806,10 +3492,10 @@ extra_command_query_buffer_from_dict (ToolCommand *command, guint argc, const gc
const GValue *cvalue;
GError *lerror = NULL;
- g_set_error (&lerror, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (&lerror, T_ERROR, T_INTERNAL_COMMAND_ERROR,
"%s", _("Could not find favorite"));
if (!sel_stmt) {
- sel_stmt = gda_sql_parser_parse_string (console->current->parser,
+ sel_stmt = gda_sql_parser_parse_string (t_connection_get_parser
(t_context_get_connection (console)),
QUERY_BUFFERS_TABLE_SELECT_ONE, NULL,
NULL);
g_assert (sel_stmt);
g_assert (gda_statement_get_parameters (sel_stmt, &sel_params, NULL));
@@ -3830,15 +3516,15 @@ extra_command_query_buffer_from_dict (ToolCommand *command, guint argc, const gc
if ((gda_data_model_get_n_rows (model) == 1) &&
(cvalue = gda_data_model_get_value_at (model, 0, 0, NULL))) {
- g_string_assign (console->current->query_buffer, g_value_get_string (cvalue));
+ t_connection_set_query_buffer (t_context_get_connection (console),
g_value_get_string (cvalue));
res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_EMPTY;
+ res->type = BASE_TOOL_COMMAND_RESULT_EMPTY;
}
g_object_unref (model);
}
}
else
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
"%s", _("Missing query buffer name"));
return res;
@@ -3846,42 +3532,39 @@ extra_command_query_buffer_from_dict (ToolCommand *command, guint argc, const gc
static ToolCommandResult *
extra_command_query_buffer_delete_dict (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error)
+ TContext *console, GError **error)
{
ToolCommandResult *res = NULL;
g_assert (console);
- if (!console->current) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
+ g_assert (global_t_app);
+
+ if (!t_context_get_connection (console)) {
+ g_set_error (error, T_ERROR, T_NO_CONNECTION_ERROR,
"%s", _("No connection opened"));
return NULL;
}
- if (!console->current->query_buffer)
- console->current->query_buffer = g_string_new ("");
-
if (argv[0] && *argv[0]) {
/* Use tools favorites */
GdaMetaStore *mstore;
- mstore = gda_connection_get_meta_store (console->current->cnc);
- if (! console->current->favorites)
- console->current->favorites = gda_tools_favorites_new (mstore);
+ mstore = gda_connection_get_meta_store (t_connection_get_cnc (t_context_get_connection
(console)));
- ToolsFavoritesAttributes att;
+ TFavoritesAttributes att;
GError *lerror = NULL;
att.id = -1;
- att.type = GDA_TOOLS_FAVORITES_QUERIES;
+ att.type = T_FAVORITES_QUERIES;
att.name = (gchar*) argv[0];
att.descr = NULL;
att.contents = NULL;
- if (! gda_tools_favorites_delete (console->current->favorites, 0,
- &att, &lerror)) {
+ if (! t_favorites_delete (t_connection_get_favorites (t_context_get_connection (console)), 0,
+ &att, &lerror)) {
/* query retrieval */
static GdaStatement *del_stmt = NULL;
static GdaSet *del_params = NULL;
if (!del_stmt) {
- del_stmt = gda_sql_parser_parse_string (console->current->parser,
+ del_stmt = gda_sql_parser_parse_string (t_connection_get_parser
(t_context_get_connection (console)),
QUERY_BUFFERS_TABLE_DELETE, NULL,
NULL);
g_assert (del_stmt);
g_assert (gda_statement_get_parameters (del_stmt, &del_params, NULL));
@@ -3903,10 +3586,10 @@ extra_command_query_buffer_delete_dict (ToolCommand *command, guint argc, const
}
}
res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_EMPTY;
+ res->type = BASE_TOOL_COMMAND_RESULT_EMPTY;
}
else
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
"%s", _("Missing query buffer name"));
return res;
@@ -3915,15 +3598,17 @@ extra_command_query_buffer_delete_dict (ToolCommand *command, guint argc, const
static void foreach_param_set (const gchar *pname, GdaHolder *param, GdaDataModel *model);
static ToolCommandResult *
extra_command_set (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error)
+ TContext *console, GError **error)
{
ToolCommandResult *res = NULL;
const gchar *pname = NULL;
const gchar *value = NULL;
g_assert (console);
- if (!console->current) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
+ g_assert (global_t_app);
+
+ if (!t_context_get_connection (console)) {
+ g_set_error (error, T_ERROR, T_NO_CONNECTION_ERROR,
"%s", _("No current connection"));
return NULL;
}
@@ -3935,34 +3620,45 @@ extra_command_set (ToolCommand *command, guint argc, const gchar **argv,
}
if (pname) {
- GdaHolder *param = g_hash_table_lookup (main_data->parameters, pname);
+ T_APP_LOCK (global_t_app);
+ GdaHolder *param = g_hash_table_lookup (global_t_app->priv->parameters, pname);
if (param) {
if (value) {
/* set param's value */
if (!strcmp (value, "_null_")) {
- if (! gda_holder_set_value (param, NULL, error))
+ if (! gda_holder_set_value (param, NULL, error)) {
+ T_APP_UNLOCK (global_t_app);
return NULL;
+ }
}
else {
- GdaServerProvider *prov;
GdaDataHandler *dh;
GValue *gvalue;
- prov = gda_connection_get_provider (console->current->cnc);
- dh = gda_server_provider_get_data_handler_g_type (prov,
-
console->current->cnc,
-
gda_holder_get_g_type (param));
- gvalue = gda_data_handler_get_value_from_str (dh, value,
gda_holder_get_g_type (param));
- if (! gda_holder_take_value (param, gvalue, error))
+ if (t_context_get_connection (console)) {
+ GdaConnection *icnc;
+ GdaServerProvider *prov;
+ icnc = t_connection_get_cnc (t_context_get_connection
(console));
+ prov = gda_connection_get_provider (icnc);
+ dh = gda_server_provider_get_data_handler_g_type (prov, icnc,
+
gda_holder_get_g_type (param));
+ }
+ else
+ dh = gda_data_handler_get_default (gda_holder_get_g_type
(param));
+ gvalue = gda_data_handler_get_value_from_str (dh, value,
+ gda_holder_get_g_type
(param));
+ if (! gda_holder_take_value (param, gvalue, error)) {
+ T_APP_UNLOCK (global_t_app);
return NULL;
+ }
}
res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_EMPTY;
+ res->type = BASE_TOOL_COMMAND_RESULT_EMPTY;
}
else {
res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_SET;
+ res->type = BASE_TOOL_COMMAND_RESULT_SET;
res->u.set = gda_set_new (NULL);
gda_set_add_holder (res->u.set, gda_holder_copy (param));
}
@@ -3973,14 +3669,15 @@ extra_command_set (ToolCommand *command, guint argc, const gchar **argv,
if (!strcmp (value, "_null_"))
value = NULL;
param = gda_holder_new_string (pname, value);
- g_hash_table_insert (main_data->parameters, g_strdup (pname), param);
+ g_hash_table_insert (global_t_app->priv->parameters, g_strdup (pname), param);
res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_EMPTY;
+ res->type = BASE_TOOL_COMMAND_RESULT_EMPTY;
}
else
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
_("No parameter named '%s' defined"), pname);
}
+ T_APP_UNLOCK (global_t_app);
}
else {
/* list parameter's values */
@@ -3991,9 +3688,11 @@ extra_command_set (ToolCommand *command, guint argc, const gchar **argv,
gda_data_model_set_column_title (model, 0, _("Name"));
gda_data_model_set_column_title (model, 1, _("Value"));
g_object_set_data (G_OBJECT (model), "name", _("List of defined parameters"));
- g_hash_table_foreach (main_data->parameters, (GHFunc) foreach_param_set, model);
+ T_APP_LOCK (global_t_app);
+ g_hash_table_foreach (global_t_app->priv->parameters, (GHFunc) foreach_param_set, model);
+ T_APP_UNLOCK (global_t_app);
res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_DATA_MODEL;
+ res->type = BASE_TOOL_COMMAND_RESULT_DATA_MODEL;
res->u.model = model;
}
@@ -4018,22 +3717,62 @@ foreach_param_set (const gchar *pname, GdaHolder *param, GdaDataModel *model)
gda_value_free (value);
}
+static ToolCommandResult *
+extra_command_unset (ToolCommand *command, guint argc, const gchar **argv,
+ TContext *console, GError **error)
+{
+ ToolCommandResult *res = NULL;
+ const gchar *pname = NULL;
+
+ g_assert (console);
+ g_assert (global_t_app);
+
+ if (argv[0] && *argv[0])
+ pname = argv[0];
+
+ T_APP_LOCK (global_t_app);
+ if (pname) {
+ GdaHolder *param = g_hash_table_lookup (global_t_app->priv->parameters, pname);
+ if (param) {
+ g_hash_table_remove (global_t_app->priv->parameters, pname);
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = BASE_TOOL_COMMAND_RESULT_EMPTY;
+ }
+ else
+ g_set_error (error, T_ERROR, T_INTERNAL_COMMAND_ERROR,
+ _("No parameter named '%s' defined"), pname);
+ }
+ else {
+ g_hash_table_destroy (global_t_app->priv->parameters);
+ global_t_app->priv->parameters = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
g_object_unref);
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = BASE_TOOL_COMMAND_RESULT_EMPTY;
+ }
+ T_APP_UNLOCK (global_t_app);
+
+ return res;
+}
+
static void foreach_data_model (const gchar *name, GdaDataModel *keptmodel, GdaDataModel *model);
static ToolCommandResult *
extra_command_data_sets_list (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error)
+ TContext *console, GError **error)
{
ToolCommandResult *res = NULL;
GdaDataModel *model;
+
+ g_assert (console);
+ g_assert (global_t_app);
+
model = gda_data_model_array_new_with_g_types (2,
G_TYPE_STRING,
G_TYPE_STRING);
gda_data_model_set_column_title (model, 0, _("Name"));
gda_data_model_set_column_title (model, 1, _("dimensions (columns x rows)"));
g_object_set_data (G_OBJECT (model), "name", _("List of kept data"));
- g_hash_table_foreach (main_data->mem_data_models, (GHFunc) foreach_data_model, model);
+ g_hash_table_foreach (global_t_app->priv->mem_data_models, (GHFunc) foreach_data_model, model);
res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_DATA_MODEL;
+ res->type = BASE_TOOL_COMMAND_RESULT_DATA_MODEL;
res->u.model = model;
return res;
@@ -4060,21 +3799,66 @@ foreach_data_model (const gchar *name, GdaDataModel *keptmodel, GdaDataModel *mo
gda_value_free (value);
}
+
+static ToolCommandResult *
+extra_command_data_set_move (ToolCommand *command, guint argc, const gchar **argv,
+ TContext *console, GError **error)
+{
+ ToolCommandResult *res = NULL;
+ const gchar *old_name = NULL;
+ const gchar *new_name = NULL;
+
+ g_assert (console);
+ g_assert (global_t_app);
+
+ if (argv[0] && *argv[0]) {
+ old_name = argv[0];
+ if (argv[1] && *argv[1])
+ new_name = argv[1];
+ }
+ if (!old_name || !*old_name || !new_name || !*new_name) {
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
+ "%s", _("Missing argument"));
+ return NULL;
+ }
+
+ GdaDataModel *src;
+
+ src = g_hash_table_lookup (global_t_app->priv->mem_data_models, old_name);
+ if (!src) {
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
+ _("Could not find dataset named '%s'"), old_name);
+ return NULL;
+ }
+
+ g_hash_table_insert (global_t_app->priv->mem_data_models, g_strdup (new_name), g_object_ref (src));
+ if (strcmp (old_name, T_LAST_DATA_MODEL_NAME))
+ g_hash_table_remove (global_t_app->priv->mem_data_models, old_name);
+
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = BASE_TOOL_COMMAND_RESULT_EMPTY;
+
+ return res;
+}
+
static ToolCommandResult *
extra_command_data_set_grep (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error)
+ TContext *console, GError **error)
{
ToolCommandResult *res = NULL;
const gchar *model_name = NULL;
const gchar *pattern = NULL;
+ g_assert (console);
+ g_assert (global_t_app);
+
if (argv[0] && *argv[0]) {
model_name = argv[0];
if (argv[1] && *argv[1])
pattern = argv[1];
}
if (!model_name) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
"%s", _("Missing argument"));
return NULL;
}
@@ -4082,9 +3866,9 @@ extra_command_data_set_grep (ToolCommand *command, guint argc, const gchar **arg
GdaDataModel *src, *model;
gint nbfields, nbrows, i;
- src = g_hash_table_lookup (main_data->mem_data_models, model_name);
+ src = g_hash_table_lookup (global_t_app->priv->mem_data_models, model_name);
if (!src) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
_("Could not find dataset named '%s'"), model_name);
return NULL;
}
@@ -4177,7 +3961,7 @@ extra_command_data_set_grep (ToolCommand *command, guint argc, const gchar **arg
}
res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_DATA_MODEL;
+ res->type = BASE_TOOL_COMMAND_RESULT_DATA_MODEL;
res->u.model = model;
return res;
@@ -4185,24 +3969,27 @@ extra_command_data_set_grep (ToolCommand *command, guint argc, const gchar **arg
static ToolCommandResult *
extra_command_data_set_show (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error)
+ TContext *console, GError **error)
{
ToolCommandResult *res = NULL;
const gchar *model_name = NULL;
+ g_assert (console);
+ g_assert (global_t_app);
+
if (argv[0] && *argv[0])
model_name = argv[0];
if (!model_name) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
"%s", _("Missing argument"));
return NULL;
}
GdaDataModel *src;
- src = g_hash_table_lookup (main_data->mem_data_models, model_name);
+ src = g_hash_table_lookup (global_t_app->priv->mem_data_models, model_name);
if (!src) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
_("Could not find dataset named '%s'"), model_name);
return NULL;
}
@@ -4223,7 +4010,7 @@ extra_command_data_set_show (ToolCommand *command, guint argc, const gchar **arg
pos = (gint) li;
}
if (pos < 0) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
_("Could not identify column '%s'"), cname);
g_array_free (cols, TRUE);
return NULL;
@@ -4237,7 +4024,7 @@ extra_command_data_set_show (ToolCommand *command, guint argc, const gchar **arg
g_array_free (cols, TRUE);
if (model) {
res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_DATA_MODEL;
+ res->type = BASE_TOOL_COMMAND_RESULT_DATA_MODEL;
res->u.model = model;
}
else
@@ -4245,7 +4032,7 @@ extra_command_data_set_show (ToolCommand *command, guint argc, const gchar **arg
}
else {
res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_DATA_MODEL;
+ res->type = BASE_TOOL_COMMAND_RESULT_DATA_MODEL;
res->u.model = g_object_ref (src);
}
@@ -4254,46 +4041,79 @@ extra_command_data_set_show (ToolCommand *command, guint argc, const gchar **arg
static ToolCommandResult *
extra_command_data_set_rm (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error)
+ TContext *console, GError **error)
{
ToolCommandResult *res = NULL;
guint i;
+ g_assert (console);
+ g_assert (global_t_app);
+
if (!argv[0] || !(*argv[0])) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
"%s", _("Missing argument"));
return NULL;
}
for (i = 0; argv[i]; i++) {
GdaDataModel *src;
- src = g_hash_table_lookup (main_data->mem_data_models, argv[i]);
+ src = g_hash_table_lookup (global_t_app->priv->mem_data_models, argv[i]);
if (!src) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
_("Could not find dataset named '%s'"), argv[i]);
return NULL;
}
}
for (i = 0; argv[i]; i++)
- g_hash_table_remove (main_data->mem_data_models, argv[i]);
+ g_hash_table_remove (global_t_app->priv->mem_data_models, argv[i]);
res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_EMPTY;
+ res->type = BASE_TOOL_COMMAND_RESULT_EMPTY;
return res;
}
+static GdaSet *
+make_options_set_from_gdasql_options (const gchar *context)
+{
+ GdaSet *expopt = NULL;
+ GSList *list, *nlist = NULL;
+ for (list = global_t_app->priv->options->holders; list; list = list->next) {
+ GdaHolder *param = GDA_HOLDER (list->data);
+ const GValue *cvalue;
+ cvalue = gda_holder_get_attribute (param, context);
+ if (!cvalue)
+ continue;
+
+ GdaHolder *nparam;
+ const GValue *cvalue2;
+ cvalue2 = gda_holder_get_value (param);
+ nparam = gda_holder_new (G_VALUE_TYPE (cvalue2));
+ g_object_set ((GObject*) nparam, "id", g_value_get_string (cvalue), NULL);
+ g_assert (gda_holder_set_value (nparam, cvalue2, NULL));
+ nlist = g_slist_append (nlist, nparam);
+ }
+ if (nlist) {
+ expopt = gda_set_new (nlist);
+ g_slist_free (nlist);
+ }
+ return expopt;
+}
+
static ToolCommandResult *
extra_command_data_set_import (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error)
+ TContext *console, GError **error)
{
ToolCommandResult *res = NULL;
const gchar *type = NULL, *file_name = NULL;
+ g_assert (console);
+ g_assert (global_t_app);
+
if (argv[0] && *argv[0]) {
type = argv[0];
if (g_ascii_strcasecmp (type, "csv")) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
_("Unknown import format '%s'"), argv[0]);
return NULL;
}
@@ -4302,7 +4122,7 @@ extra_command_data_set_import (ToolCommand *command, guint argc, const gchar **a
}
if (!type || !file_name) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
"%s", _("Missing argument"));
return NULL;
}
@@ -4314,7 +4134,7 @@ extra_command_data_set_import (ToolCommand *command, guint argc, const gchar **a
if (impopt)
g_object_unref (impopt);
if (!model) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (error, T_ERROR, T_INTERNAL_COMMAND_ERROR,
_("Could not import file '%s'"), file_name);
return NULL;
}
@@ -4325,48 +4145,620 @@ extra_command_data_set_import (ToolCommand *command, guint argc, const gchar **a
return NULL;
}
- g_hash_table_insert (main_data->mem_data_models, g_strdup (LAST_DATA_MODEL_NAME), model);
+ g_hash_table_insert (global_t_app->priv->mem_data_models, g_strdup (T_LAST_DATA_MODEL_NAME), model);
res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_EMPTY;
+ res->type = BASE_TOOL_COMMAND_RESULT_EMPTY;
return res;
}
+#define DO_UNLINK(x) g_unlink(x)
+static void
+graph_func_child_died_cb (GPid pid, G_GNUC_UNUSED gint status, gchar *fname)
+{
+ DO_UNLINK (fname);
+ g_free (fname);
+ g_spawn_close_pid (pid);
+}
+
+static gchar *
+create_graph_from_meta_struct (G_GNUC_UNUSED GdaConnection *cnc, GdaMetaStruct *mstruct, GError **error)
+{
+#define FNAME "graph.dot"
+ gchar *graph;
+
+ graph = gda_meta_struct_dump_as_graph (mstruct, GDA_META_GRAPH_COLUMNS, error);
+ if (!graph)
+ return NULL;
+
+ /* do something with the graph */
+ gchar *result = NULL;
+ if (g_file_set_contents (FNAME, graph, -1, error)) {
+ const gchar *viewer;
+ const gchar *format;
+
+ viewer = g_getenv ("GDA_SQL_VIEWER_PNG");
+ if (viewer)
+ format = "png";
+ else {
+ viewer = g_getenv ("GDA_SQL_VIEWER_PDF");
+ if (viewer)
+ format = "pdf";
+ }
+ if (viewer) {
+ static gint counter = 0;
+ gchar *tmpname, *suffix;
+ gchar *argv[] = {"dot", NULL, "-o", NULL, FNAME, NULL};
+ guint eventid = 0;
+
+ suffix = g_strdup_printf (".gda_graph_tmp-%d", counter++);
+ tmpname = g_build_filename (g_get_tmp_dir (), suffix, NULL);
+ g_free (suffix);
+ argv[1] = g_strdup_printf ("-T%s", format);
+ argv[3] = tmpname;
+ if (g_spawn_sync (NULL, argv, NULL,
+ G_SPAWN_SEARCH_PATH | G_SPAWN_STDOUT_TO_DEV_NULL |
G_SPAWN_STDERR_TO_DEV_NULL,
+ NULL, NULL,
+ NULL, NULL, NULL, NULL)) {
+ gchar *vargv[3];
+ GPid pid;
+ vargv[0] = (gchar *) viewer;
+ vargv[1] = tmpname;
+ vargv[2] = NULL;
+ if (g_spawn_async (NULL, vargv, NULL,
+ G_SPAWN_SEARCH_PATH | G_SPAWN_STDOUT_TO_DEV_NULL |
+ G_SPAWN_STDERR_TO_DEV_NULL | G_SPAWN_DO_NOT_REAP_CHILD,
+ NULL, NULL,
+ &pid, NULL)) {
+ eventid = g_child_watch_add (pid, (GChildWatchFunc)
graph_func_child_died_cb,
+ tmpname);
+ }
+ }
+ if (eventid == 0) {
+ DO_UNLINK (tmpname);
+ g_free (tmpname);
+ }
+ g_free (argv[1]);
+ result = g_strdup_printf (_("Graph written to '%s'\n"), FNAME);
+ }
+ else
+ result = g_strdup_printf (_("Graph written to '%s'\n"
+ "Use 'dot' (from the GraphViz package) to create a
picture, for example:\n"
+ "\tdot -Tpng -o graph.png %s\n"
+ "Note: set the GDA_SQL_VIEWER_PNG or GDA_SQL_VIEWER_PDF
environment "
+ "variables to view the graph\n"), FNAME, FNAME);
+ }
+ g_free (graph);
+ return result;
+}
+
static ToolCommandResult *
-extra_command_data_set_move (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error)
+extra_command_graph (ToolCommand *command, guint argc, const gchar **argv,
+ TContext *console, GError **error)
+{
+ gchar *result;
+ GdaMetaStruct *mstruct;
+
+ g_assert (console);
+ g_assert (global_t_app);
+ g_assert (console == global_t_app->priv->term_console);
+
+ if (!t_context_get_connection (console)) {
+ g_set_error (error, T_ERROR, T_NO_CONNECTION_ERROR,
+ "%s", _("No current connection"));
+ return NULL;
+ }
+
+ GdaConnection *icnc;
+ icnc = t_connection_get_cnc (t_context_get_connection (console));
+ mstruct = gda_internal_command_build_meta_struct (icnc, argv, error);
+ if (!mstruct)
+ return NULL;
+
+ result = create_graph_from_meta_struct (icnc, mstruct, error);
+ g_object_unref (mstruct);
+ if (result) {
+ ToolCommandResult *res;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = BASE_TOOL_COMMAND_RESULT_TXT_STDOUT;
+ res->u.txt = g_string_new (result);
+ g_free (result);
+ return res;
+ }
+ else
+ return NULL;
+}
+
+#ifdef HAVE_LIBSOUP
+gboolean
+t_app_start_http_server (gint port, const gchar *auth_token, GError **error)
+{
+ gboolean retval = TRUE;
+ if (port > 0) {
+ global_t_app->priv->server = web_server_new (port, auth_token);
+ if (!global_t_app->priv->server) {
+ g_set_error (error, T_ERROR, T_INTERNAL_COMMAND_ERROR,
+ "%s", _("Could not start HTTPD server"));
+ retval = FALSE;
+ }
+ }
+ return retval;
+}
+
+static ToolCommandResult *
+extra_command_httpd (ToolCommand *command, guint argc, const gchar **argv,
+ TContext *console, GError **error)
{
ToolCommandResult *res = NULL;
- const gchar *old_name = NULL;
- const gchar *new_name = NULL;
- if (argv[0] && *argv[0]) {
- old_name = argv[0];
- if (argv[1] && *argv[1])
- new_name = argv[1];
+ g_assert (console);
+ g_assert (global_t_app);
+
+ if (global_t_app->priv->server) {
+ /* stop server */
+ g_object_unref (global_t_app->priv->server);
+ global_t_app->priv->server = NULL;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = BASE_TOOL_COMMAND_RESULT_TXT_STDOUT;
+ res->u.txt = g_string_new (_("HTTPD server stopped"));
}
- if (!old_name || !*old_name || !new_name || !*new_name) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
- "%s", _("Missing argument"));
+ else {
+ /* start new server */
+ gint port = 12345;
+ const gchar *auth_token = NULL;
+ if (argv[0] && *argv[0]) {
+ gchar *ptr;
+ port = (gint) strtol (argv[0], &ptr, 10);
+ if (ptr && *ptr)
+ port = -1;
+ if (argv[1] && *argv[1]) {
+ auth_token = argv[1];
+ }
+ }
+ if (port > 0) {
+ if (t_app_start_http_server (port, auth_token, error)) {
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = BASE_TOOL_COMMAND_RESULT_TXT_STDOUT;
+ res->u.txt = g_string_new (_("HTTPD server started"));
+ }
+ }
+ else
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
+ "%s", _("Invalid port specification"));
+ }
+
+ return res;
+}
+#endif
+
+static const GValue *
+get_table_value_at_cell (TContext *console, GError **error,
+ const gchar *table, const gchar *column, const gchar *row_cond,
+ GdaDataModel **out_model_of_value)
+{
+ const GValue *retval = NULL;
+
+ *out_model_of_value = NULL;
+
+ /* prepare executed statement */
+ gchar *sql;
+ gchar *rtable, *rcolumn;
+
+ GdaConnection *icnc;
+ icnc = t_connection_get_cnc (t_context_get_connection (console));
+ rtable = gda_sql_identifier_quote (table, icnc, NULL, FALSE, FALSE);
+ rcolumn = gda_sql_identifier_quote (column, icnc, NULL, FALSE, FALSE);
+ sql = g_strdup_printf ("SELECT %s FROM %s WHERE %s", rcolumn, rtable, row_cond);
+ g_free (rtable);
+ g_free (rcolumn);
+
+ GdaStatement *stmt;
+ const gchar *remain;
+ stmt = gda_sql_parser_parse_string (t_connection_get_parser (t_context_get_connection (console)),
sql, &remain, error);
+ if (!stmt) {
+ g_free (sql);
+ return NULL;
+ }
+ if (remain) {
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
+ "%s", _("Wrong row condition"));
+ g_free (sql);
return NULL;
}
+ g_object_unref (stmt);
- GdaDataModel *src;
+ /* execute statement */
+ ToolCommandResult *tmpres;
+ tmpres = t_context_command_execute (console, sql,
+ GDA_STATEMENT_MODEL_RANDOM_ACCESS, error);
+ g_free (sql);
+ if (!tmpres)
+ return NULL;
+ gboolean errorset = FALSE;
+ if (tmpres->type == BASE_TOOL_COMMAND_RESULT_DATA_MODEL) {
+ GdaDataModel *model;
+ model = tmpres->u.model;
+ if (gda_data_model_get_n_rows (model) == 1) {
+ retval = gda_data_model_get_value_at (model, 0, 0, error);
+ if (!retval)
+ errorset = TRUE;
+ else
+ *out_model_of_value = g_object_ref (model);
+ }
+ }
+ base_tool_command_result_free (tmpres);
- src = g_hash_table_lookup (main_data->mem_data_models, old_name);
- if (!src) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
- _("Could not find dataset named '%s'"), old_name);
+ if (!retval && !errorset)
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
+ "%s", _("No unique row identified"));
+
+ return retval;
+}
+
+static ToolCommandResult *
+extra_command_export (ToolCommand *command, guint argc, const gchar **argv,
+ TContext *console, GError **error)
+{
+ ToolCommandResult *res = NULL;
+
+ const gchar *pname = NULL;
+ const gchar *table = NULL;
+ const gchar *column = NULL;
+ const gchar *filename = NULL;
+ const gchar *row_cond = NULL;
+ gint whichargv = 0;
+
+ g_assert (console);
+ g_assert (global_t_app);
+
+ if (!t_context_get_connection (console)) {
+ g_set_error (error, T_ERROR, T_NO_CONNECTION_ERROR,
+ "%s", _("No current connection"));
+ return NULL;
+ }
+
+ if (argv[0] && *argv[0]) {
+ table = argv[0];
+ pname = argv[0];
+ if (argv[1] && *argv[1]) {
+ column = argv[1];
+ filename = argv[1];
+ if (argv[2] && *argv[2]) {
+ row_cond = argv[2];
+ if (argv[3] && *argv[3]) {
+ filename = argv[3];
+ if (argv [4]) {
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
+ "%s", _("Too many arguments"));
+ return NULL;
+ }
+ else
+ whichargv = 1;
+ }
+ }
+ else {
+ whichargv = 2;
+ }
+ }
+ }
+
+ const GValue *value = NULL;
+ GdaDataModel *model = NULL;
+
+ TApp *main_data;
+ main_data = T_APP (global_t_app);
+ T_APP_LOCK (main_data);
+
+ if (whichargv == 1)
+ value = get_table_value_at_cell (console, error, table, column,
+ row_cond, &model);
+ else if (whichargv == 2) {
+ GdaHolder *param = g_hash_table_lookup (global_t_app->priv->parameters, pname);
+ if (!pname)
+ g_set_error (error, T_ERROR, T_INTERNAL_COMMAND_ERROR,
+ _("No parameter named '%s' defined"), pname);
+ else
+ value = gda_holder_get_value (param);
+ }
+ else
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
+ "%s", _("Wrong number of arguments"));
+
+ if (value) {
+ /* to file through this blob */
+ gboolean done = FALSE;
+
+ if (G_VALUE_TYPE (value) == GDA_TYPE_BLOB) {
+ GValue *vblob = gda_value_new_blob_from_file (filename);
+ GdaBlob *tblob = (GdaBlob*) gda_value_get_blob (vblob);
+ const GdaBlob *fblob = gda_value_get_blob (value);
+ if (gda_blob_op_write (tblob->op, (GdaBlob*) fblob, 0) < 0)
+ g_set_error (error, T_ERROR, T_INTERNAL_COMMAND_ERROR,
+ "%s", _("Could not write file"));
+ else
+ done = TRUE;
+ gda_value_free (vblob);
+ }
+ else if (G_VALUE_TYPE (value) == GDA_TYPE_BINARY) {
+ GValue *vblob = gda_value_new_blob_from_file (filename);
+ GdaBlob *tblob = (GdaBlob*) gda_value_get_blob (vblob);
+ GdaBlob *fblob = g_new0 (GdaBlob, 1);
+ const GdaBinary *fbin = gda_value_get_binary (value);
+ ((GdaBinary *) fblob)->data = fbin->data;
+ ((GdaBinary *) fblob)->binary_length = fbin->binary_length;
+ if (gda_blob_op_write (tblob->op, (GdaBlob*) fblob, 0) < 0)
+ g_set_error (error, T_ERROR, T_INTERNAL_COMMAND_ERROR,
+ "%s", _("Could not write file"));
+ else
+ done = TRUE;
+ g_free (fblob);
+ gda_value_free (vblob);
+ }
+ else {
+ gchar *str;
+ str = gda_value_stringify (value);
+ if (g_file_set_contents (filename, str, -1, error))
+ done = TRUE;
+ g_free (str);
+ }
+
+ if (done) {
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = BASE_TOOL_COMMAND_RESULT_EMPTY;
+ }
+ }
+ if (model)
+ g_object_unref (model);
+ T_APP_UNLOCK (main_data);
+
+ return res;
+}
+
+static ToolCommandResult *
+extra_command_set2 (ToolCommand *command, guint argc, const gchar **argv,
+ TContext *console, GError **error)
+{
+ ToolCommandResult *res = NULL;
+ const gchar *pname = NULL;
+ const gchar *filename = NULL;
+ const gchar *table = NULL;
+ const gchar *column = NULL;
+ const gchar *row_cond = NULL;
+ gint whichargv = 0;
+
+ g_assert (console);
+ g_assert (global_t_app);
+
+ if (!t_context_get_connection (console)) {
+ g_set_error (error, T_ERROR, T_NO_CONNECTION_ERROR,
+ "%s", _("No current connection"));
+ return NULL;
+ }
+
+ if (argv[0] && *argv[0]) {
+ pname = argv[0];
+ if (argv[1] && *argv[1]) {
+ if (argv[2] && *argv[2]) {
+ table = argv[1];
+ column = argv[2];
+ if (argv[3] && *argv[3]) {
+ row_cond = argv[3];
+ if (argv [4]) {
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
+ "%s", _("Too many arguments"));
+ return NULL;
+ }
+ whichargv = 1;
+ }
+ }
+ else {
+ filename = argv[1];
+ whichargv = 2;
+ }
+ }
+ }
+
+ TApp *main_data;
+ main_data = T_APP (global_t_app);
+
+ if (whichargv == 1) {
+ /* param from an existing blob */
+ const GValue *value;
+ GdaDataModel *model = NULL;
+ value = get_table_value_at_cell (console, error, table,
+ column, row_cond, &model);
+ if (value) {
+ T_APP_LOCK (main_data);
+ GdaHolder *param = g_hash_table_lookup (global_t_app->priv->parameters, pname);
+ if (param)
+ g_hash_table_remove (global_t_app->priv->parameters, pname);
+
+ param = gda_holder_new (G_VALUE_TYPE (value));
+ g_assert (gda_holder_set_value (param, value, NULL));
+ g_hash_table_insert (global_t_app->priv->parameters, g_strdup (pname), param);
+ T_APP_UNLOCK (main_data);
+
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = BASE_TOOL_COMMAND_RESULT_EMPTY;
+ }
+ if (model)
+ g_object_unref (model);
+ }
+ else if (whichargv == 2) {
+ /* param from filename */
+ T_APP_LOCK (main_data);
+ GdaHolder *param = g_hash_table_lookup (global_t_app->priv->parameters, pname);
+ GValue *bvalue;
+ if (param)
+ g_hash_table_remove (global_t_app->priv->parameters, pname);
+
+ param = gda_holder_new (GDA_TYPE_BLOB);
+ bvalue = gda_value_new_blob_from_file (filename);
+ g_assert (gda_holder_take_value (param, bvalue, NULL));
+ g_hash_table_insert (global_t_app->priv->parameters, g_strdup (pname), param);
+ T_APP_UNLOCK (main_data);
+
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = BASE_TOOL_COMMAND_RESULT_EMPTY;
+ }
+ else
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
+ "%s", _("Wrong number of arguments"));
+
+ return res;
+}
+
+static ToolCommandResult *
+extra_command_pivot (ToolCommand *command, guint argc, const gchar **argv,
+ TContext *console, GError **error)
+{
+ ToolCommandResult *res = NULL;
+ TConnection *tcnc;
+
+ g_assert (console);
+ g_assert (global_t_app);
+
+ tcnc = t_context_get_connection (console);
+ if (!tcnc) {
+ g_set_error (error, T_ERROR, T_NO_CONNECTION_ERROR,
+ "%s", _("No connection specified"));
return NULL;
}
- g_hash_table_insert (main_data->mem_data_models, g_strdup (new_name), g_object_ref (src));
- if (strcmp (old_name, LAST_DATA_MODEL_NAME))
- g_hash_table_remove (main_data->mem_data_models, old_name);
+ const gchar *select = NULL;
+ const gchar *row_fields = NULL;
+ const gchar *column_fields = NULL;
- res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_EMPTY;
+ if (argv[0] && *argv[0]) {
+ select = argv[0];
+ if (argv[1] && *argv[1]) {
+ row_fields = argv [1];
+ if (argv[2] && *argv[2])
+ column_fields = argv[2];
+ }
+ }
+
+ if (!select) {
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
+ "%s", _("Missing data on which to operate"));
+ return NULL;
+ }
+ if (!row_fields) {
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
+ "%s", _("Missing row fields specifications"));
+ return NULL;
+ }
+ if (column_fields && !strcmp (column_fields, "-"))
+ column_fields = NULL;
+
+ /* execute SELECT */
+ gboolean was_in_trans;
+ ToolCommandResult *tmpres;
+
+ was_in_trans = gda_connection_get_transaction_status (t_connection_get_cnc (tcnc)) ? TRUE : FALSE;
+
+ tmpres = t_context_command_execute (console, select, GDA_STATEMENT_MODEL_CURSOR_FORWARD, error);
+ if (!tmpres)
+ return NULL;
+ if (tmpres->type != BASE_TOOL_COMMAND_RESULT_DATA_MODEL) {
+ base_tool_command_result_free (tmpres);
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
+ "%s", _("Wrong SELECT argument"));
+ return NULL;
+ }
+
+ GdaDataPivot *pivot;
+ gdouble etime = 0.;
+ //g_object_get ((GObject*) tmpres->u.model, "execution-delay", &etime, NULL);
+ pivot = (GdaDataPivot*) gda_data_pivot_new (tmpres->u.model);
+ base_tool_command_result_free (tmpres);
+
+ if (! gda_data_pivot_add_field (pivot, GDA_DATA_PIVOT_FIELD_ROW,
+ row_fields, NULL, error)) {
+ g_object_unref (pivot);
+ return NULL;
+ }
+
+ if (column_fields &&
+ ! gda_data_pivot_add_field (pivot, GDA_DATA_PIVOT_FIELD_COLUMN,
+ column_fields, NULL, error)) {
+ g_object_unref (pivot);
+ return NULL;
+ }
+
+ GTimer *timer;
+ timer = g_timer_new ();
+
+ gint i;
+ for (i = 3; argv[i] && *argv[i]; i++) {
+ const gchar *df = argv[i];
+ const gchar *alias = "count";
+ GdaDataPivotAggregate agg = GDA_DATA_PIVOT_COUNT;
+ if (*df == '[') {
+ const gchar *tmp;
+ for (tmp = df; *tmp && *tmp != ']'; tmp++);
+ if (!*tmp) {
+ g_timer_destroy (timer);
+ g_object_unref (pivot);
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
+ "%s", _("Wrong data field argument"));
+ return NULL;
+ }
+ df++;
+ if (! g_ascii_strncasecmp (df, "sum", 3) && (df[3] == ']')) {
+ agg = GDA_DATA_PIVOT_SUM;
+ alias = "sum";
+ }
+ else if (! g_ascii_strncasecmp (df, "avg", 3) && (df[3] == ']')) {
+ agg = GDA_DATA_PIVOT_AVG;
+ alias = "avg";
+ }
+ else if (! g_ascii_strncasecmp (df, "max", 3) && (df[3] == ']')) {
+ agg = GDA_DATA_PIVOT_MAX;
+ alias = "max";
+ }
+ else if (! g_ascii_strncasecmp (df, "min", 3) && (df[3] == ']')) {
+ agg = GDA_DATA_PIVOT_MIN;
+ alias = "min";
+ }
+ else if (! g_ascii_strncasecmp (df, "count", 5) && (df[5] == ']')) {
+ agg = GDA_DATA_PIVOT_COUNT;
+ alias = "count";
+ }
+ else {
+ g_timer_destroy (timer);
+ g_object_unref (pivot);
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
+ "%s", _("Wrong data field argument"));
+ return NULL;
+ }
+ df = tmp+1;
+ }
+ gchar *tmp;
+ tmp = g_strdup_printf ("%s_%s", alias, df);
+ if (! gda_data_pivot_add_data (pivot, agg, df, tmp, error)) {
+ g_free (tmp);
+ g_timer_destroy (timer);
+ g_object_unref (pivot);
+ return NULL;
+ }
+ g_free (tmp);
+ }
+
+ if (! gda_data_pivot_populate (pivot, error)) {
+ g_timer_destroy (timer);
+ g_object_unref (pivot);
+ return NULL;
+ }
+ etime += g_timer_elapsed (timer, NULL);
+ g_timer_destroy (timer);
+ //g_object_set (pivot, "execution-delay", etime, NULL);
+
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = BASE_TOOL_COMMAND_RESULT_DATA_MODEL;
+ res->was_in_transaction_before_exec = was_in_trans;
+ res->u.model = (GdaDataModel*) pivot;
return res;
}
@@ -4385,13 +4777,13 @@ fk_decl_data_free (FkDeclData *data)
g_free (data->table);
g_free (data->ref_table);
if (data->columns) {
- gint i;
+ guint i;
for (i = 0; i < data->columns->len; i++)
g_free (g_array_index (data->columns, gchar*, i));
g_array_free (data->columns, TRUE);
}
if (data->ref_columns) {
- gint i;
+ guint i;
for (i = 0; i < data->ref_columns->len; i++)
g_free (g_array_index (data->ref_columns, gchar*, i));
g_array_free (data->ref_columns, TRUE);
@@ -4408,7 +4800,7 @@ parse_fk_decl_spec (const gchar *spec, gboolean columns_required, GError **error
gchar *ptr, *dspec, *start, *subptr, *substart;
if (!spec || !*spec) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
"%s", _("Missing foreign key declaration specification"));
return NULL;
}
@@ -4525,7 +4917,7 @@ parse_fk_decl_spec (const gchar *spec, gboolean columns_required, GError **error
onerror:
fk_decl_data_free (decldata);
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
"%s", _("Malformed foreign key declaration specification"));
return NULL;
}
@@ -4557,22 +4949,25 @@ fk_decl_analyse_table_name (const gchar *table, GdaMetaStore *mstore,
g_strfreev (id_array);
}
else {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
_("Malformed table name specification '%s'"), table);
return FALSE;
}
return TRUE;
}
+
static ToolCommandResult *
extra_command_declare_fk (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error)
+ TContext *console, GError **error)
{
ToolCommandResult *res = NULL;
g_assert (console);
- if (!console->current) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
+ g_assert (global_t_app);
+
+ if (!t_context_get_connection (console)) {
+ g_set_error (error, T_ERROR, T_NO_CONNECTION_ERROR,
"%s", _("No connection opened"));
return NULL;
}
@@ -4583,7 +4978,7 @@ extra_command_declare_fk (ToolCommand *command, guint argc, const gchar **argv,
gchar *catalog = NULL, *schema = NULL, *table = NULL;
gchar *ref_catalog = NULL, *ref_schema = NULL, *ref_table = NULL;
- mstore = gda_connection_get_meta_store (console->current->cnc);
+ mstore = gda_connection_get_meta_store (t_connection_get_cnc (t_context_get_connection
(console)));
if (! (decldata = parse_fk_decl_spec (argv[0], TRUE, error)))
return NULL;
@@ -4615,7 +5010,7 @@ extra_command_declare_fk (ToolCommand *command, guint argc, const gchar **argv,
#endif
gchar **colnames, **ref_colnames;
- gint l;
+ guint l;
gboolean allok;
colnames = g_new0 (gchar *, decldata->columns->len);
ref_colnames = g_new0 (gchar *, decldata->columns->len);
@@ -4642,24 +5037,26 @@ extra_command_declare_fk (ToolCommand *command, guint argc, const gchar **argv,
if (allok) {
res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_EMPTY;
+ res->type = BASE_TOOL_COMMAND_RESULT_EMPTY;
}
}
else
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
"%s", _("Missing foreign key name argument"));
return res;
}
static ToolCommandResult *
extra_command_undeclare_fk (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error)
+ TContext *console, GError **error)
{
ToolCommandResult *res = NULL;
g_assert (console);
- if (!console->current) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
+ g_assert (global_t_app);
+
+ if (!t_context_get_connection (console)) {
+ g_set_error (error, T_ERROR, T_NO_CONNECTION_ERROR,
"%s", _("No connection opened"));
return NULL;
}
@@ -4670,7 +5067,7 @@ extra_command_undeclare_fk (ToolCommand *command, guint argc, const gchar **argv
gchar *catalog = NULL, *schema = NULL, *table = NULL;
gchar *ref_catalog = NULL, *ref_schema = NULL, *ref_table = NULL;
- mstore = gda_connection_get_meta_store (console->current->cnc);
+ mstore = gda_connection_get_meta_store (t_connection_get_cnc (t_context_get_connection
(console)));
if (! (decldata = parse_fk_decl_spec (argv[0], FALSE, error)))
return NULL;
@@ -4717,325 +5114,36 @@ extra_command_undeclare_fk (ToolCommand *command, guint argc, const gchar **argv
if (allok) {
res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_EMPTY;
+ res->type = BASE_TOOL_COMMAND_RESULT_EMPTY;
}
}
else
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
"%s", _("Missing foreign key name argument"));
return res;
}
-static const GValue *
-get_table_value_at_cell (SqlConsole *console, GError **error,
- const gchar *table, const gchar *column, const gchar *row_cond,
- GdaDataModel **out_model_of_value)
-{
- const GValue *retval = NULL;
-
- *out_model_of_value = NULL;
-
- /* prepare executed statement */
- gchar *sql;
- gchar *rtable, *rcolumn;
-
- rtable = gda_sql_identifier_quote (table, console->current->cnc, NULL, FALSE, FALSE);
- rcolumn = gda_sql_identifier_quote (column, console->current->cnc, NULL, FALSE, FALSE);
- sql = g_strdup_printf ("SELECT %s FROM %s WHERE %s", rcolumn, rtable, row_cond);
- g_free (rtable);
- g_free (rcolumn);
-
- GdaStatement *stmt;
- const gchar *remain;
- stmt = gda_sql_parser_parse_string (console->current->parser, sql, &remain, error);
- if (!stmt) {
- g_free (sql);
- return NULL;
- }
- if (remain) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
- "%s", _("Wrong row condition"));
- g_free (sql);
- return NULL;
- }
- g_object_unref (stmt);
-
- /* execute statement */
- ToolCommandResult *tmpres;
- tmpres = execute_sql_command (NULL, sql, GDA_STATEMENT_MODEL_RANDOM_ACCESS, error);
- g_free (sql);
- if (!tmpres)
- return NULL;
- gboolean errorset = FALSE;
- if (tmpres->type == TOOL_COMMAND_RESULT_DATA_MODEL) {
- GdaDataModel *model;
- model = tmpres->u.model;
- if (gda_data_model_get_n_rows (model) == 1) {
- retval = gda_data_model_get_value_at (model, 0, 0, error);
- if (!retval)
- errorset = TRUE;
- else
- *out_model_of_value = g_object_ref (model);
- }
- }
- tool_command_result_free (tmpres);
-
- if (!retval && !errorset)
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
- "%s", _("No unique row identified"));
-
- return retval;
-}
-
-static ToolCommandResult *
-extra_command_set2 (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error)
-{
- ToolCommandResult *res = NULL;
- const gchar *pname = NULL;
- const gchar *filename = NULL;
- const gchar *table = NULL;
- const gchar *column = NULL;
- const gchar *row_cond = NULL;
- gint whichargv = 0;
-
- if (!console->current) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
- "%s", _("No current connection"));
- return NULL;
- }
-
- if (argv[0] && *argv[0]) {
- pname = argv[0];
- if (argv[1] && *argv[1]) {
- if (argv[2] && *argv[2]) {
- table = argv[1];
- column = argv[2];
- if (argv[3] && *argv[3]) {
- row_cond = argv[3];
- if (argv [4]) {
- g_set_error (error, GDA_TOOLS_ERROR,
GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
- "%s", _("Too many arguments"));
- return NULL;
- }
- whichargv = 1;
- }
- }
- else {
- filename = argv[1];
- whichargv = 2;
- }
- }
- }
-
- if (whichargv == 1) {
- /* param from an existing blob */
- const GValue *value;
- GdaDataModel *model = NULL;
- value = get_table_value_at_cell (console, error, table,
- column, row_cond, &model);
- if (value) {
- GdaHolder *param = g_hash_table_lookup (main_data->parameters, pname);
- if (param)
- g_hash_table_remove (main_data->parameters, pname);
-
- param = gda_holder_new (G_VALUE_TYPE (value));
- g_assert (gda_holder_set_value (param, value, NULL));
- g_hash_table_insert (main_data->parameters, g_strdup (pname), param);
- res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_EMPTY;
- }
- if (model)
- g_object_unref (model);
- }
- else if (whichargv == 2) {
- /* param from filename */
- GdaHolder *param = g_hash_table_lookup (main_data->parameters, pname);
- GValue *bvalue;
- if (param)
- g_hash_table_remove (main_data->parameters, pname);
-
- param = gda_holder_new (GDA_TYPE_BLOB);
- bvalue = gda_value_new_blob_from_file (filename);
- g_assert (gda_holder_take_value (param, bvalue, NULL));
- g_hash_table_insert (main_data->parameters, g_strdup (pname), param);
- res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_EMPTY;
- }
- else
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
- "%s", _("Wrong number of arguments"));
-
- return res;
-}
-
-static ToolCommandResult *
-extra_command_pivot (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error)
-{
- ToolCommandResult *res = NULL;
- ConnectionSetting *cs;
- cs = get_current_connection_settings (console);
- if (!cs) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
- "%s", _("No connection specified"));
- return NULL;
- }
-
- const gchar *select = NULL;
- const gchar *row_fields = NULL;
- const gchar *column_fields = NULL;
-
- if (argv[0] && *argv[0]) {
- select = argv[0];
- if (argv[1] && *argv[1]) {
- row_fields = argv [1];
- if (argv[2] && *argv[2])
- column_fields = argv[2];
- }
- }
-
- if (!select) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
- "%s", _("Missing data on which to operate"));
- return NULL;
- }
- if (!row_fields) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
- "%s", _("Missing row fields specifications"));
- return NULL;
- }
- if (column_fields && !strcmp (column_fields, "-"))
- column_fields = NULL;
-
- /* execute SELECT */
- gboolean was_in_trans;
- ToolCommandResult *tmpres;
-
- was_in_trans = gda_connection_get_transaction_status (cs->cnc) ? TRUE : FALSE;
-
- tmpres = command_execute (console, select, GDA_STATEMENT_MODEL_CURSOR_FORWARD, error);
- if (!tmpres)
- return NULL;
- if (tmpres->type != TOOL_COMMAND_RESULT_DATA_MODEL) {
- tool_command_result_free (tmpres);
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
- "%s", _("Wrong SELECT argument"));
- return NULL;
- }
-
- GdaDataPivot *pivot;
- gdouble etime = 0.;
- //g_object_get ((GObject*) tmpres->u.model, "execution-delay", &etime, NULL);
- pivot = (GdaDataPivot*) gda_data_pivot_new (tmpres->u.model);
- tool_command_result_free (tmpres);
-
- if (! gda_data_pivot_add_field (pivot, GDA_DATA_PIVOT_FIELD_ROW,
- row_fields, NULL, error)) {
- g_object_unref (pivot);
- return NULL;
- }
-
- if (column_fields &&
- ! gda_data_pivot_add_field (pivot, GDA_DATA_PIVOT_FIELD_COLUMN,
- column_fields, NULL, error)) {
- g_object_unref (pivot);
- return NULL;
- }
-
- GTimer *timer;
- timer = g_timer_new ();
-
- gint i;
- for (i = 3; argv[i] && *argv[i]; i++) {
- const gchar *df = argv[i];
- const gchar *alias = "count";
- GdaDataPivotAggregate agg = GDA_DATA_PIVOT_COUNT;
- if (*df == '[') {
- const gchar *tmp;
- for (tmp = df; *tmp && *tmp != ']'; tmp++);
- if (!*tmp) {
- g_timer_destroy (timer);
- g_object_unref (pivot);
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
- "%s", _("Wrong data field argument"));
- return NULL;
- }
- df++;
- if (! g_ascii_strncasecmp (df, "sum", 3) && (df[3] == ']')) {
- agg = GDA_DATA_PIVOT_SUM;
- alias = "sum";
- }
- else if (! g_ascii_strncasecmp (df, "avg", 3) && (df[3] == ']')) {
- agg = GDA_DATA_PIVOT_AVG;
- alias = "avg";
- }
- else if (! g_ascii_strncasecmp (df, "max", 3) && (df[3] == ']')) {
- agg = GDA_DATA_PIVOT_MAX;
- alias = "max";
- }
- else if (! g_ascii_strncasecmp (df, "min", 3) && (df[3] == ']')) {
- agg = GDA_DATA_PIVOT_MIN;
- alias = "min";
- }
- else if (! g_ascii_strncasecmp (df, "count", 5) && (df[5] == ']')) {
- agg = GDA_DATA_PIVOT_COUNT;
- alias = "count";
- }
- else {
- g_timer_destroy (timer);
- g_object_unref (pivot);
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
- "%s", _("Wrong data field argument"));
- return NULL;
- }
- df = tmp+1;
- }
- gchar *tmp;
- tmp = g_strdup_printf ("%s_%s", alias, df);
- if (! gda_data_pivot_add_data (pivot, agg, df, tmp, error)) {
- g_free (tmp);
- g_timer_destroy (timer);
- g_object_unref (pivot);
- return NULL;
- }
- g_free (tmp);
- }
-
- if (! gda_data_pivot_populate (pivot, error)) {
- g_timer_destroy (timer);
- g_object_unref (pivot);
- return NULL;
- }
-
- etime += g_timer_elapsed (timer, NULL);
- g_timer_destroy (timer);
- //g_object_set (pivot, "execution-delay", etime, NULL);
-
- res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_DATA_MODEL;
- res->was_in_transaction_before_exec = was_in_trans;
- res->u.model = (GdaDataModel*) pivot;
- return res;
-}
-
#ifdef HAVE_LDAP
static ToolCommandResult *
extra_command_ldap_search (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error)
+ TContext *console, GError **error)
{
ToolCommandResult *res = NULL;
- ConnectionSetting *cs;
+ TConnection *tcnc;
GdaDataModel *model, *wrapper;
- cs = get_current_connection_settings (console);
- if (!cs) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
+
+ g_assert (console);
+ g_assert (global_t_app);
+
+ tcnc = t_context_get_connection (console);
+ if (!tcnc) {
+ g_set_error (error, T_ERROR, T_NO_CONNECTION_ERROR,
"%s", _("No connection specified"));
return NULL;
}
- if (! GDA_IS_LDAP_CONNECTION (cs->cnc)) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
+ if (! GDA_IS_LDAP_CONNECTION (t_connection_get_cnc (tcnc))) {
+ g_set_error (error, T_ERROR, T_INTERNAL_COMMAND_ERROR,
"%s", _("Connection is not an LDAP connection"));
return NULL;
}
@@ -5057,7 +5165,7 @@ extra_command_ldap_search (ToolCommand *command, guint argc, const gchar **argv,
else if (!g_ascii_strcasecmp (scope, "subtree"))
lscope = GDA_LDAP_SEARCH_SUBTREE;
else {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
_("Unknown search scope '%s'"), scope);
return NULL;
}
@@ -5067,7 +5175,7 @@ extra_command_ldap_search (ToolCommand *command, guint argc, const gchar **argv,
}
if (!filter) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
"%s", _("Missing filter which to operate"));
return NULL;
}
@@ -5077,12 +5185,12 @@ extra_command_ldap_search (ToolCommand *command, guint argc, const gchar **argv,
GdaHolder *param;
const gchar *ldap_attributes;
- ldap_attributes = g_value_get_string (gda_set_get_holder_value (main_data->options,
"ldap_attributes"));
- model = gda_data_model_ldap_new (cs->cnc, base_dn, lfilter ? lfilter : filter,
- ldap_attributes ? ldap_attributes : DEFAULT_LDAP_ATTRIBUTES,
+ ldap_attributes = g_value_get_string (gda_set_get_holder_value (global_t_app->priv->options,
"ldap_attributes"));
+ model = gda_data_model_ldap_new (t_connection_get_cnc (tcnc), base_dn, lfilter ? lfilter : filter,
+ ldap_attributes ? ldap_attributes : T_DEFAULT_LDAP_ATTRIBUTES,
lscope);
g_free (lfilter);
- param = gda_set_get_holder (main_data->options, "ldap_dn");
+ param = gda_set_get_holder (global_t_app->priv->options, "ldap_dn");
wrapper = gda_data_access_wrapper_new (model);
g_object_unref (model);
@@ -5113,26 +5221,30 @@ extra_command_ldap_search (ToolCommand *command, guint argc, const gchar **argv,
}
res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_DATA_MODEL;
+ res->type = BASE_TOOL_COMMAND_RESULT_DATA_MODEL;
res->u.model = wrapper;
return res;
}
static ToolCommandResult *
extra_command_ldap_mv (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error)
+ TContext *console, GError **error)
{
ToolCommandResult *res = NULL;
- ConnectionSetting *cs;
- cs = get_current_connection_settings (console);
- if (!cs) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
+ TConnection *tcnc;
+
+ g_assert (console);
+ g_assert (global_t_app);
+
+ tcnc = t_context_get_connection (console);
+ if (!tcnc) {
+ g_set_error (error, T_ERROR, T_NO_CONNECTION_ERROR,
"%s", _("No connection specified"));
return NULL;
}
- if (! GDA_IS_LDAP_CONNECTION (cs->cnc)) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
+ if (! GDA_IS_LDAP_CONNECTION (t_connection_get_cnc (tcnc))) {
+ g_set_error (error, T_ERROR, T_INTERNAL_COMMAND_ERROR,
"%s", _("Connection is not an LDAP connection"));
return NULL;
}
@@ -5147,14 +5259,14 @@ extra_command_ldap_mv (ToolCommand *command, guint argc, const gchar **argv,
}
if (!current_dn || !new_dn) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
"%s", _("Missing current DN or new DN specification"));
return NULL;
}
- if (gda_ldap_rename_entry (GDA_LDAP_CONNECTION (cs->cnc), current_dn, new_dn, error)) {
+ if (gda_ldap_rename_entry (GDA_LDAP_CONNECTION (t_connection_get_cnc (tcnc)), current_dn, new_dn,
error)) {
res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_EMPTY;
+ res->type = BASE_TOOL_COMMAND_RESULT_EMPTY;
return res;
}
else
@@ -5213,19 +5325,23 @@ parse_ldap_attr (const gchar *spec, gboolean value_req,
static ToolCommandResult *
extra_command_ldap_mod (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error)
+ TContext *console, GError **error)
{
ToolCommandResult *res = NULL;
- ConnectionSetting *cs;
- cs = get_current_connection_settings (console);
- if (!cs) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
+ TConnection *tcnc;
+
+ g_assert (console);
+ g_assert (global_t_app);
+
+ tcnc = t_context_get_connection (console);
+ if (!tcnc) {
+ g_set_error (error, T_ERROR, T_NO_CONNECTION_ERROR,
"%s", _("No connection specified"));
return NULL;
}
- if (! GDA_IS_LDAP_CONNECTION (cs->cnc)) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
+ if (! GDA_IS_LDAP_CONNECTION (t_connection_get_cnc (tcnc))) {
+ g_set_error (error, T_ERROR, T_INTERNAL_COMMAND_ERROR,
"%s", _("Connection is not an LDAP connection"));
return NULL;
}
@@ -5240,12 +5356,12 @@ extra_command_ldap_mod (ToolCommand *command, guint argc, const gchar **argv,
}
if (!dn) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
"%s", _("Missing DN of LDAP entry"));
return NULL;
}
if (!op) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
"%s", _("Missing operation to perform on LDAP entry's attributes"));
return NULL;
}
@@ -5257,7 +5373,7 @@ extra_command_ldap_mod (ToolCommand *command, guint argc, const gchar **argv,
else if (! g_ascii_strncasecmp (op, "ADD", 3))
optype = GDA_LDAP_MODIFICATION_ATTR_ADD;
else {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
_("Unknown operation '%s' to perform on LDAP entry's attributes"), op);
return NULL;
}
@@ -5278,15 +5394,15 @@ extra_command_ldap_mod (ToolCommand *command, guint argc, const gchar **argv,
gda_value_free (att_value);
}
else {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
_("Wrong attribute value specification '%s'"), argv[i]);
return NULL;
}
}
- if (gda_ldap_modify_entry (GDA_LDAP_CONNECTION (cs->cnc), optype, entry, NULL, error)) {
+ if (gda_ldap_modify_entry (GDA_LDAP_CONNECTION (t_connection_get_cnc (tcnc)), optype, entry, NULL,
error)) {
res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_EMPTY;
+ res->type = BASE_TOOL_COMMAND_RESULT_EMPTY;
}
gda_ldap_entry_free (entry);
return res;
@@ -5307,20 +5423,23 @@ att_row_cmp (AttRow *r1, AttRow *r2)
static ToolCommandResult *
extra_command_ldap_descr (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error)
+ TContext *console, GError **error)
{
ToolCommandResult *res = NULL;
+ TConnection *tcnc;
+
+ g_assert (console);
+ g_assert (global_t_app);
- ConnectionSetting *cs;
- cs = get_current_connection_settings (console);
- if (!cs) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
+ tcnc = t_context_get_connection (console);
+ if (!tcnc) {
+ g_set_error (error, T_ERROR, T_NO_CONNECTION_ERROR,
"%s", _("No connection specified"));
return NULL;
}
- if (! GDA_IS_LDAP_CONNECTION (cs->cnc)) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
+ if (! GDA_IS_LDAP_CONNECTION (t_connection_get_cnc (tcnc))) {
+ g_set_error (error, T_ERROR, T_INTERNAL_COMMAND_ERROR,
"%s", _("Connection is not an LDAP connection"));
return NULL;
}
@@ -5334,7 +5453,7 @@ extra_command_ldap_descr (ToolCommand *command, guint argc, const gchar **argv,
*/
if (!argv[0] || !*argv[0]) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
"%s", _("Missing DN (Distinguished name) argument"));
return NULL;
}
@@ -5347,7 +5466,7 @@ extra_command_ldap_descr (ToolCommand *command, guint argc, const gchar **argv,
else if (!g_ascii_strcasecmp (argv [1], "set"))
options = 3;
else {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
_("Unknown '%s' argument"), argv[1]);
return NULL;
}
@@ -5355,10 +5474,10 @@ extra_command_ldap_descr (ToolCommand *command, guint argc, const gchar **argv,
GdaLdapEntry *entry;
GdaDataModel *model;
- entry = gda_ldap_describe_entry (GDA_LDAP_CONNECTION (cs->cnc), dn, error);
+ entry = gda_ldap_describe_entry (GDA_LDAP_CONNECTION (t_connection_get_cnc (tcnc)), dn, error);
if (!entry) {
if (error && !*error)
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (error, T_ERROR, T_INTERNAL_COMMAND_ERROR,
_("Could not find entry with DN '%s'"), dn);
return NULL;
}
@@ -5374,7 +5493,8 @@ extra_command_ldap_descr (ToolCommand *command, guint argc, const gchar **argv,
/* parse attributes to use */
const gchar *ldap_attributes;
- ldap_attributes = g_value_get_string (gda_set_get_holder_value (main_data->options,
"ldap_attributes"));
+ ldap_attributes = g_value_get_string (gda_set_get_holder_value (global_t_app->priv->options,
+ "ldap_attributes"));
if ((options == 0) && ldap_attributes) {
gchar **array;
guint i;
@@ -5427,7 +5547,7 @@ extra_command_ldap_descr (ToolCommand *command, guint argc, const gchar **argv,
/* 2nd pass: use the class's attributes */
GSList *attrs_list, *list;
- attrs_list = gda_ldap_entry_get_attributes_list (GDA_LDAP_CONNECTION (cs->cnc), entry);
+ attrs_list = gda_ldap_entry_get_attributes_list (GDA_LDAP_CONNECTION (t_connection_get_cnc (tcnc)),
entry);
for (list = attrs_list; list; list = list->next) {
GdaLdapAttributeDefinition *def;
def = (GdaLdapAttributeDefinition*) list->data;
@@ -5503,544 +5623,10 @@ extra_command_ldap_descr (ToolCommand *command, guint argc, const gchar **argv,
gda_ldap_entry_free (entry);
res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_DATA_MODEL;
+ res->type = BASE_TOOL_COMMAND_RESULT_DATA_MODEL;
res->u.model = model;
return res;
}
#endif /* HAVE_LDAP */
-
-static ToolCommandResult *
-extra_command_export (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error)
-{
- ToolCommandResult *res = NULL;
-
- const gchar *pname = NULL;
- const gchar *table = NULL;
- const gchar *column = NULL;
- const gchar *filename = NULL;
- const gchar *row_cond = NULL;
- gint whichargv = 0;
-
- if (!console->current) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
- "%s", _("No current connection"));
- return NULL;
- }
-
- if (argv[0] && *argv[0]) {
- table = argv[0];
- pname = argv[0];
- if (argv[1] && *argv[1]) {
- column = argv[1];
- filename = argv[1];
- if (argv[2] && *argv[2]) {
- row_cond = argv[2];
- if (argv[3] && *argv[3]) {
- filename = argv[3];
- if (argv [4]) {
- g_set_error (error, GDA_TOOLS_ERROR,
GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
- "%s", _("Too many arguments"));
- return NULL;
- }
- else
- whichargv = 1;
- }
- }
- else {
- whichargv = 2;
- }
- }
- }
-
- const GValue *value = NULL;
- GdaDataModel *model = NULL;
-
- if (whichargv == 1)
- value = get_table_value_at_cell (console, error, table, column,
- row_cond, &model);
- else if (whichargv == 2) {
- GdaHolder *param = g_hash_table_lookup (main_data->parameters, pname);
- if (!pname)
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
- _("No parameter named '%s' defined"), pname);
- else
- value = gda_holder_get_value (param);
- }
- else
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
- "%s", _("Wrong number of arguments"));
-
- if (value) {
- /* to file through this blob */
- gboolean done = FALSE;
-
- if (G_VALUE_TYPE (value) == GDA_TYPE_BLOB) {
- GValue *vblob = gda_value_new_blob_from_file (filename);
- GdaBlob *tblob = (GdaBlob*) gda_value_get_blob (vblob);
- const GdaBlob *fblob = gda_value_get_blob (value);
- if (gda_blob_op_write (tblob->op, (GdaBlob*) fblob, 0) < 0)
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
- "%s", _("Could not write file"));
- else
- done = TRUE;
- gda_value_free (vblob);
- }
- else if (G_VALUE_TYPE (value) == GDA_TYPE_BINARY) {
- GValue *vblob = gda_value_new_blob_from_file (filename);
- GdaBlob *tblob = (GdaBlob*) gda_value_get_blob (vblob);
- GdaBlob *fblob = g_new0 (GdaBlob, 1);
- const GdaBinary *fbin = gda_value_get_binary (value);
- ((GdaBinary *) fblob)->data = fbin->data;
- ((GdaBinary *) fblob)->binary_length = fbin->binary_length;
- if (gda_blob_op_write (tblob->op, (GdaBlob*) fblob, 0) < 0)
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
- "%s", _("Could not write file"));
- else
- done = TRUE;
- g_free (fblob);
- gda_value_free (vblob);
- }
- else {
- gchar *str;
- str = gda_value_stringify (value);
- if (g_file_set_contents (filename, str, -1, error))
- done = TRUE;
- g_free (str);
- }
-
- if (done) {
- res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_EMPTY;
- }
- }
- if (model)
- g_object_unref (model);
-
-
- return res;
-}
-
-
-static ToolCommandResult *
-extra_command_unset (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error)
-{
- ToolCommandResult *res = NULL;
- const gchar *pname = NULL;
-
- if (argv[0] && *argv[0])
- pname = argv[0];
-
- if (pname) {
- GdaHolder *param = g_hash_table_lookup (main_data->parameters, pname);
- if (param) {
- g_hash_table_remove (main_data->parameters, pname);
- res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_EMPTY;
- }
- else
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
- _("No parameter named '%s' defined"), pname);
- }
- else {
- g_hash_table_destroy (main_data->parameters);
- main_data->parameters = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
g_object_unref);
- res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_EMPTY;
- }
-
- return res;
-}
-
-#define DO_UNLINK(x) g_unlink(x)
-static void
-graph_func_child_died_cb (GPid pid, G_GNUC_UNUSED gint status, gchar *fname)
-{
- DO_UNLINK (fname);
- g_free (fname);
- g_spawn_close_pid (pid);
-}
-
-static gchar *
-create_graph_from_meta_struct (G_GNUC_UNUSED GdaConnection *cnc, GdaMetaStruct *mstruct, GError **error)
-{
-#define FNAME "graph.dot"
- gchar *graph;
-
- graph = gda_meta_struct_dump_as_graph (mstruct, GDA_META_GRAPH_COLUMNS, error);
- if (!graph)
- return NULL;
-
- /* do something with the graph */
- gchar *result = NULL;
- if (g_file_set_contents (FNAME, graph, -1, error)) {
- const gchar *viewer;
- const gchar *format;
-
- viewer = g_getenv ("GDA_SQL_VIEWER_PNG");
- if (viewer)
- format = "png";
- else {
- viewer = g_getenv ("GDA_SQL_VIEWER_PDF");
- if (viewer)
- format = "pdf";
- }
- if (viewer) {
- static gint counter = 0;
- gchar *tmpname, *suffix;
- gchar *argv[] = {"dot", NULL, "-o", NULL, FNAME, NULL};
- guint eventid = 0;
-
- suffix = g_strdup_printf (".gda_graph_tmp-%d", counter++);
- tmpname = g_build_filename (g_get_tmp_dir (), suffix, NULL);
- g_free (suffix);
- argv[1] = g_strdup_printf ("-T%s", format);
- argv[3] = tmpname;
- if (g_spawn_sync (NULL, argv, NULL,
- G_SPAWN_SEARCH_PATH | G_SPAWN_STDOUT_TO_DEV_NULL |
G_SPAWN_STDERR_TO_DEV_NULL,
- NULL, NULL,
- NULL, NULL, NULL, NULL)) {
- gchar *vargv[3];
- GPid pid;
- vargv[0] = (gchar *) viewer;
- vargv[1] = tmpname;
- vargv[2] = NULL;
- if (g_spawn_async (NULL, vargv, NULL,
- G_SPAWN_SEARCH_PATH | G_SPAWN_STDOUT_TO_DEV_NULL |
- G_SPAWN_STDERR_TO_DEV_NULL | G_SPAWN_DO_NOT_REAP_CHILD,
- NULL, NULL,
- &pid, NULL)) {
- eventid = g_child_watch_add (pid, (GChildWatchFunc)
graph_func_child_died_cb,
- tmpname);
- }
- }
- if (eventid == 0) {
- DO_UNLINK (tmpname);
- g_free (tmpname);
- }
- g_free (argv[1]);
- result = g_strdup_printf (_("Graph written to '%s'\n"), FNAME);
- }
- else
- result = g_strdup_printf (_("Graph written to '%s'\n"
- "Use 'dot' (from the GraphViz package) to create a
picture, for example:\n"
- "\tdot -Tpng -o graph.png %s\n"
- "Note: set the GDA_SQL_VIEWER_PNG or GDA_SQL_VIEWER_PDF
environment "
- "variables to view the graph\n"), FNAME, FNAME);
- }
- g_free (graph);
- return result;
-}
-
-static ToolCommandResult *
-extra_command_graph (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error)
-{
- gchar *result;
- GdaMetaStruct *mstruct;
-
- g_assert (console);
- if (!console->current) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
- "%s", _("No current connection"));
- return NULL;
- }
-
- mstruct = gda_internal_command_build_meta_struct (console->current->cnc, argv, error);
- if (!mstruct)
- return NULL;
-
- result = create_graph_from_meta_struct (console->current->cnc, mstruct, error);
- g_object_unref (mstruct);
- if (result) {
- ToolCommandResult *res;
- res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_TXT_STDOUT;
- res->u.txt = g_string_new (result);
- g_free (result);
- return res;
- }
- else
- return NULL;
-}
-
-
-
-#ifdef HAVE_LIBSOUP
-static ToolCommandResult *
-extra_command_httpd (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error)
-{
- ToolCommandResult *res = NULL;
-
- if (main_data->server) {
- /* stop server */
- g_object_unref (main_data->server);
- main_data->server = NULL;
- res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_TXT_STDOUT;
- res->u.txt = g_string_new (_("HTTPD server stopped"));
- }
- else {
- /* start new server */
- gint port = 12345;
- const gchar *auth_token = NULL;
- if (argv[0] && *argv[0]) {
- gchar *ptr;
- port = (gint) strtol (argv[0], &ptr, 10);
- if (ptr && *ptr)
- port = -1;
- if (argv[1] && *argv[1]) {
- auth_token = argv[1];
- }
- }
- if (port > 0) {
- main_data->server = web_server_new (port, auth_token);
- if (!main_data->server)
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
- "%s", _("Could not start HTTPD server"));
- else {
- res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_TXT_STDOUT;
- res->u.txt = g_string_new (_("HTTPD server started"));
- }
- }
- else
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
- "%s", _("Invalid port specification"));
- }
-
- return res;
-}
-#endif
-
-#ifdef NONE
-static ToolCommandResult *
-extra_command_lo_update (ToolCommand *command, guint argc, const gchar **argv,
- SqlConsole *console, GError **error)
-{
- ToolCommandResult *res;
-
- const gchar *table = NULL;
- const gchar *blob_col = NULL;
- const gchar *filename = NULL;
- const gchar *row_cond = NULL;
-
- if (!cnc) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_NO_CONNECTION_ERROR,
- "%s", _("No current connection"));
- return NULL;
- }
-
- if (argv[0] && *argv[0]) {
- filename = argv[0];
- if (argv[1] && *argv[1]) {
- table = argv[1];
- if (argv[2] && *argv[2]) {
- blob_col = argv[2];
- if (argv[3] && *argv[3]) {
- row_cond = argv[3];
- if (argv [4]) {
- g_set_error (error, GDA_TOOLS_ERROR,
GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
- "%s", _("Too many arguments"));
- return NULL;
- }
- }
- }
- }
- }
- if (!row_cond) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
- "%s", _("Missing arguments"));
- return NULL;
- }
-
- g_print ("file: #%s#\n", filename);
- g_print ("table: #%s#\n", table);
- g_print ("col: #%s#\n", blob_col);
- g_print ("cond: #%s#\n", row_cond);
- TO_IMPLEMENT;
-
- /* prepare executed statement */
- gchar *sql;
- gchar *rtable, *rblob_col;
-
- rtable = gda_sql_identifier_quote (table, cnc, NULL, FALSE, FALSE);
- rblob_col = gda_sql_identifier_quote (blob_col, cnc, NULL, FALSE, FALSE);
- sql = g_strdup_printf ("UPDATE %s SET %s = ##blob::GdaBlob WHERE %s", rtable, rblob_col, row_cond);
- g_free (rtable);
- g_free (rblob_col);
-
- GdaStatement *stmt;
- const gchar *remain;
- stmt = gda_sql_parser_parse_string (console->current->parser, sql, &remain, error);
- g_free (sql);
- if (!stmt)
- return NULL;
- if (remain) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
- "%s", _("Wrong row condition"));
- return NULL;
- }
-
- /* prepare execution environment */
- GdaSet *params;
- GdaHolder *h;
- GValue *blob;
-
- if (!gda_statement_get_parameters (stmt, ¶ms, error)) {
- g_object_unref (stmt);
- return NULL;
- }
-
- h = gda_set_get_holder (params, "blob");
- g_assert (h);
- blob = gda_value_new_blob_from_file (filename);
- if (!gda_holder_take_value (h, blob, error)) {
- gda_value_free (blob);
- g_object_unref (params);
- g_object_unref (stmt);
- return NULL;
- }
-
- /* execute statement */
- gint nrows;
- nrows = gda_connection_statement_execute_non_select (cnc, stmt, params, NULL, error);
- g_object_unref (params);
- g_object_unref (stmt);
- if (nrows == -1)
- return NULL;
-
- res = g_new0 (ToolCommandResult, 1);
- res->type = TOOL_COMMAND_RESULT_EMPTY;
- return res;
-}
-#endif
-
-
-static char **
-completion_func (G_GNUC_UNUSED const char *text, const gchar *line, int start, int end)
-{
- ConnectionSetting *cs = main_data->term_console->current;
- char **array;
- gchar **gda_compl;
- gint i, nb_compl;
-
- if (!cs)
- return NULL;
- gda_compl = gda_completion_list_get (cs->cnc, line, start, end);
- if (!gda_compl)
- return NULL;
-
- for (nb_compl = 0; gda_compl[nb_compl]; nb_compl++);
-
- array = malloc (sizeof (char*) * (nb_compl + 1));
- for (i = 0; i < nb_compl; i++) {
- char *str;
- gchar *gstr;
- gint l;
-
- gstr = gda_compl[i];
- l = strlen (gstr) + 1;
- str = malloc (sizeof (char) * l);
- memcpy (str, gstr, l);
- array[i] = str;
- }
- array[i] = NULL;
- g_strfreev (gda_compl);
- return array;
-}
-
-
-const GSList *
-gda_sql_get_all_connections (void)
-{
- return main_data->settings;
-}
-
-const ConnectionSetting *
-gda_sql_get_connection (const gchar *name)
-{
- return find_connection_from_name (name);
-}
-
-const ConnectionSetting *
-gda_sql_get_current_connection (void)
-{
- return main_data->term_console->current;
-}
-
-gchar *
-gda_sql_console_execute (SqlConsole *console, const gchar *command, GError **error, ToolOutputFormat format)
-{
- gchar *loc_cmde = NULL;
- gchar *retstr = NULL;
-
- g_assert (console);
- loc_cmde = g_strdup (command);
- g_strchug (loc_cmde);
- if (*loc_cmde) {
- if (command_is_complete (loc_cmde)) {
- /* execute command */
- ToolCommandResult *res;
-
- res = command_execute (console, loc_cmde,
- GDA_STATEMENT_MODEL_RANDOM_ACCESS, error);
-
- if (res) {
- ToolOutputFormat of = console->output_format;
- if (res->type == TOOL_COMMAND_RESULT_DATA_MODEL)
- console->output_format = TOOL_OUTPUT_FORMAT_HTML;
-
- retstr = tool_output_result_to_string (res, format, console->output_stream,
- main_data->options);
- console->output_format = of;
- tool_command_result_free (res);
- }
- }
- else {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_COMMAND_ARGUMENTS_ERROR,
- "%s", _("Command is incomplete"));
- }
- }
- g_free (loc_cmde);
-
- return retstr;
-}
-
-SqlConsole *
-gda_sql_console_new (const gchar *id)
-{
- SqlConsole *c;
-
- c = g_new0 (SqlConsole, 1);
- c->output_format = TOOL_OUTPUT_FORMAT_DEFAULT;
- if (id)
- c->id = g_strdup (id);
- if (main_data->term_console)
- c->current = main_data->term_console->current;
- c->command_group = main_data->limit_commands; /* limit to a subset of all commands */
- c->output_stream = NULL;
- return c;
-}
-
-void
-gda_sql_console_free (SqlConsole *console)
-{
- g_free (console->id);
- g_free (console);
-}
-
-gchar *
-gda_sql_console_compute_prompt (SqlConsole *console, ToolOutputFormat format)
-{
- GString *string;
-
- string = g_string_new ("");
- compute_prompt (console, string, FALSE, TRUE, format);
-
- return g_string_free (string, FALSE);
-}
diff --git a/tools/common/t-app.h b/tools/common/t-app.h
new file mode 100644
index 0000000..2917438
--- /dev/null
+++ b/tools/common/t-app.h
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2014 Vivien Malerba <malerba gnome-db org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __T_APP__
+#define __T_APP__
+
+#include <glib.h>
+#include <gio/gio.h>
+#include "t-connection.h"
+#include "t-decl.h"
+#include "base-tool.h"
+#include "t-errors.h"
+#include "web-server.h"
+#ifdef HAVE_GTK_CLASSES
+ #include <gtk/gtk.h>
+#endif
+
+#define T_APP_TYPE (t_app_get_type())
+#define T_APP(obj) G_TYPE_CHECK_INSTANCE_CAST (obj, t_app_get_type(), TApp)
+#define T_APP_CLASS(klass) G_TYPE_CHECK_CLASS_CAST (klass, t_app_get_type (), TAppClass)
+#define IS_T_APP(obj) G_TYPE_CHECK_INSTANCE_TYPE (obj, t_app_get_type ())
+
+typedef struct _TAppClass TAppClass;
+typedef struct _TAppPrivate TAppPrivate;
+typedef GSList *(*TAppInitFactories) (void);
+
+/* struct for the object's data */
+struct _TApp
+{
+#ifdef HAVE_GTK_CLASSES
+ GtkApplication parent;
+#else
+ GApplication parent;
+#endif
+ TAppPrivate *priv;
+
+ ToolCommandGroup *term_commands;
+#ifdef HAVE_LIBSOUP
+ ToolCommandGroup *web_commands;
+#endif
+
+};
+
+/* struct for the object's class */
+struct _TAppClass
+{
+#ifdef HAVE_GTK_CLASSES
+ GtkApplicationClass parent_class;
+#else
+ GApplicationClass parent_class;
+#endif
+
+ /* signals */
+ void (*connection_added) (TApp *self, TConnection *tcnc);
+ void (*connection_removed) (TApp *self, TConnection *tcnc);
+ void (*quit_requested) (TApp *self);
+};
+
+typedef enum {
+ T_APP_NO_FEATURE = 0,
+ T_APP_TERM_CONSOLE = 1 << 0,
+ T_APP_BROWSER = 1 << 1,
+ T_APP_WEB_SERVER = 1 << 2,
+} TAppFeatures;
+
+void t_app_setup (TAppFeatures features);
+void t_app_add_feature (TAppFeatures feature);
+void t_app_remove_feature (TAppFeatures feature);
+
+void t_app_cleanup (void);
+TApp *t_app_get (void);
+void t_app_request_quit (void);
+
+void t_app_lock (void);
+void t_app_unlock (void);
+
+gboolean t_app_open_connections (gint argc, const gchar *argv[], GError **error);
+
+GSList *t_app_get_all_connections (void);
+GdaDataModel *t_app_get_all_connections_m (void);
+
+void t_app_add_tcnc (TConnection *tcnc);
+GValue *t_app_get_parameter_value (const gchar *name);
+TContext *t_app_get_term_console (void);
+GdaSet *t_app_get_options (void);
+gboolean t_app_start_http_server (gint port, const gchar *auth_token, GError **error);
+
+void t_app_store_data_model (GdaDataModel *model, const gchar *name);
+GdaDataModel *t_app_fetch_data_model (const gchar *name);
+
+/* internal API */
+void _t_app_add_context (TContext *console);
+void _t_app_remove_context (TContext *console);
+
+#endif
diff --git a/tools/config-info.c b/tools/common/t-config-info.c
similarity index 94%
rename from tools/config-info.c
rename to tools/common/t-config-info.c
index 5e7e14f..8e6193a 100644
--- a/tools/config-info.c
+++ b/tools/common/t-config-info.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010 - 2012 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2010 - 2014 Vivien Malerba <malerba gnome-db org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -16,8 +16,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#include "config-info.h"
-#include "tool-utils.h"
+#include "t-config-info.h"
+#include "t-errors.h"
#include <glib/gi18n-lib.h>
#include <glib/gstdio.h>
@@ -25,7 +25,7 @@
* Replace @argvi's contents with the connection name
*/
void
-config_info_modify_argv (char *argvi)
+t_config_info_modify_argv (char *argvi)
{
GString *string;
gchar *prov, *cncparams, *user, *pass;
@@ -50,13 +50,13 @@ config_info_modify_argv (char *argvi)
}
GdaDataModel *
-config_info_list_all_dsn (void)
+t_config_info_list_all_dsn (void)
{
return gda_config_list_dsn ();
}
GdaDataModel *
-config_info_list_all_providers (void)
+t_config_info_list_all_providers (void)
{
GdaDataModel *prov_list, *model;
gint i, nrows;
@@ -100,12 +100,12 @@ config_info_list_all_providers (void)
}
GdaDataModel *
-config_info_detail_provider (const gchar *provider, GError **error)
+t_config_info_detail_provider (const gchar *provider, GError **error)
{
GdaProviderInfo *pinfo;
pinfo = gda_config_get_provider_info (provider);
if (! pinfo) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_PROVIDER_NOT_FOUND_ERROR,
+ g_set_error (error, T_ERROR, T_PROVIDER_NOT_FOUND_ERROR,
_("Could not find provider '%s'"), provider);
return NULL;
}
@@ -268,13 +268,13 @@ ql_foreach_cb (const gchar *name, const gchar *value, GString *string)
}
GdaDataModel *
-config_info_detail_dsn (const gchar *dsn, GError **error)
+t_config_info_detail_dsn (const gchar *dsn, GError **error)
{
GdaDsnInfo *info = NULL;
if (dsn && *dsn)
info = gda_config_get_dsn_info (dsn);
if (!info) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_DSN_NOT_FOUND_ERROR,
+ g_set_error (error, T_ERROR, T_DSN_NOT_FOUND_ERROR,
_("Could not find data source '%s'"), dsn);
return NULL;
}
@@ -406,7 +406,7 @@ config_info_detail_dsn (const gchar *dsn, GError **error)
}
GdaDataModel *
-config_info_list_data_files (GError **error)
+t_config_info_list_data_files (GError **error)
{
const gchar *name;
gchar *confdir;
@@ -414,7 +414,7 @@ config_info_list_data_files (GError **error)
GDir *dir;
/* open directory */
- confdir = config_info_compute_dict_directory ();
+ confdir = t_config_info_compute_dict_directory ();
dir = g_dir_open (confdir, 0, error);
if (!dir) {
g_free (confdir);
@@ -532,7 +532,7 @@ parse_criteria (const gchar *criteria)
}
gchar *
-config_info_purge_data_files (const gchar *criteria, GError **error)
+t_config_info_purge_data_files (const gchar *criteria, GError **error)
{
PurgeCriteria cri = PURGE_UNKNOWN;
GString *string = NULL;
@@ -551,7 +551,7 @@ config_info_purge_data_files (const gchar *criteria, GError **error)
}
g_strfreev (array);
if (cri == PURGE_UNKNOWN) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_PURGE_ERROR,
+ g_set_error (error, T_ERROR, T_PURGE_ERROR,
_("Unknown criteria '%s'"), criteria);
return NULL;
}
@@ -562,7 +562,7 @@ config_info_purge_data_files (const gchar *criteria, GError **error)
GString *errstring = NULL;
/* open directory */
- confdir = config_info_compute_dict_directory ();
+ confdir = t_config_info_compute_dict_directory ();
dir = g_dir_open (confdir, 0, error);
if (!dir) {
g_free (confdir);
@@ -631,7 +631,7 @@ config_info_purge_data_files (const gchar *criteria, GError **error)
g_dir_close (dir);
if (errstring) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_PURGE_ERROR,
+ g_set_error (error, T_ERROR, T_PURGE_ERROR,
"%s", errstring->str);
g_string_free (errstring, TRUE);
}
@@ -648,7 +648,7 @@ config_info_purge_data_files (const gchar *criteria, GError **error)
gchar *
-config_info_compute_dict_directory (void)
+t_config_info_compute_dict_directory (void)
{
gchar *confdir;
@@ -671,12 +671,12 @@ compute_dict_file_name_foreach_cb (const gchar *key, G_GNUC_UNUSED const gchar *
}
gchar *
-config_info_compute_dict_file_name (GdaDsnInfo *info, const gchar *cnc_string)
+t_config_info_compute_dict_file_name (GdaDsnInfo *info, const gchar *cnc_string)
{
gchar *filename = NULL;
gchar *confdir;
- confdir = config_info_compute_dict_directory ();
+ confdir = t_config_info_compute_dict_directory ();
if (info) {
filename = g_strdup_printf ("%s%sgda-sql-%s.db",
confdir, G_DIR_SEPARATOR_S,
@@ -721,7 +721,7 @@ config_info_compute_dict_file_name (GdaDsnInfo *info, const gchar *cnc_string)
}
void
-config_info_update_meta_store_properties (GdaMetaStore *mstore, GdaConnection *rel_cnc)
+t_config_info_update_meta_store_properties (GdaMetaStore *mstore, GdaConnection *rel_cnc)
{
GDate *date;
GValue *dvalue;
diff --git a/tools/common/t-config-info.h b/tools/common/t-config-info.h
new file mode 100644
index 0000000..4260e32
--- /dev/null
+++ b/tools/common/t-config-info.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2009 - 2014 Vivien Malerba <malerba gnome-db org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __T_CONFIG_INFO__
+#define __T_CONFIG_INFO__
+
+#include <libgda/libgda.h>
+
+void t_config_info_modify_argv (char *argvi);
+
+gchar *t_config_info_compute_dict_directory (void);
+gchar *t_config_info_compute_dict_file_name (GdaDsnInfo *info, const gchar *cnc_string);
+void t_config_info_update_meta_store_properties (GdaMetaStore *mstore, GdaConnection *rel_cnc);
+
+GdaDataModel *t_config_info_list_all_dsn (void);
+GdaDataModel *t_config_info_list_all_providers (void);
+GdaDataModel *t_config_info_detail_provider (const gchar *provider, GError **error);
+GdaDataModel *t_config_info_detail_dsn (const gchar *dsn, GError **error);
+GdaDataModel *t_config_info_list_data_files (GError **error);
+gchar *t_config_info_purge_data_files (const gchar *criteria, GError **error);
+
+#endif
diff --git a/tools/common/t-connection.c b/tools/common/t-connection.c
new file mode 100644
index 0000000..a26ab23
--- /dev/null
+++ b/tools/common/t-connection.c
@@ -0,0 +1,2449 @@
+/*
+ * Copyright (C) 2009 - 2014 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2010 David King <davidk openismus com>
+ * Copyright (C) 2010 Murray Cumming <murrayc murrayc com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include <string.h>
+#include <glib/gi18n-lib.h>
+#include "t-errors.h"
+#include "t-connection.h"
+#include "t-app.h"
+#include "t-context.h"
+#include "marshal.h"
+#include <sql-parser/gda-sql-parser.h>
+#include <libgda/gda-sql-builder.h>
+#include <libgda-ui/gdaui-enums.h>
+#include "t-config-info.h"
+#include "t-virtual-connection.h"
+#include <virtual/gda-virtual-connection.h>
+#include <libgda/gda-debug-macros.h>
+#include <libgda/gda-enum-types.h>
+#ifdef G_OS_WIN32
+ #include "windows.h"
+#else
+ #include <termios.h>
+#endif
+#include <unistd.h>
+
+#define CHECK_RESULTS_SHORT_TIMER 200
+#define CHECK_RESULTS_LONG_TIMER 2
+
+struct _TConnectionPrivate {
+ GHashTable *executed_statements; /* key = guint exec ID, value = a StatementResult pointer */
+
+ gulong meta_store_signal;
+ gulong transaction_status_signal;
+
+ gchar *name;
+ gchar *query_buffer;
+ GdaConnection *cnc;
+ gchar *dict_file_name;
+ GdaSqlParser *parser;
+
+ GdaDsnInfo dsn_info;
+ GdaMetaStruct *mstruct;
+
+ TFavorites *bfav;
+
+ gboolean busy;
+ gchar *busy_reason;
+
+ GdaConnection *store_cnc;
+
+ GdaSet *variables;
+};
+
+
+/* signals */
+enum {
+ BUSY,
+ STATUS_CHANGED,
+ META_CHANGED,
+ FAV_CHANGED,
+ TRANSACTION_STATUS_CHANGED,
+ TABLE_COLUMN_PREF_CHANGED,
+ NOTICE,
+ LAST_SIGNAL
+};
+
+gint t_connection_signals [LAST_SIGNAL] = { 0, 0, 0, 0, 0, 0, 0 };
+
+/*
+ * Main static functions
+ */
+static void t_connection_class_init (TConnectionClass *klass);
+static void t_connection_init (TConnection *tcnc);
+static void t_connection_dispose (GObject *object);
+static void t_connection_set_property (GObject *object,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void t_connection_get_property (GObject *object,
+ guint param_id,
+ GValue *value,
+ GParamSpec *pspec);
+/* get a pointer to the parents to be able to call their destructor */
+static GObjectClass *parent_class = NULL;
+
+/* properties */
+enum {
+ PROP_0,
+ PROP_GDA_CNC
+};
+
+GType
+t_connection_get_type (void)
+{
+ static GType type = 0;
+
+ if (G_UNLIKELY (type == 0)) {
+ static GMutex registering;
+ static const GTypeInfo info = {
+ sizeof (TConnectionClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) t_connection_class_init,
+ NULL,
+ NULL,
+ sizeof (TConnection),
+ 0,
+ (GInstanceInitFunc) t_connection_init,
+ 0
+ };
+
+
+ g_mutex_lock (®istering);
+ if (type == 0)
+ type = g_type_register_static (G_TYPE_OBJECT, "TConnection", &info, 0);
+ g_mutex_unlock (®istering);
+ }
+ return type;
+}
+
+static void
+t_connection_class_init (TConnectionClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ parent_class = g_type_class_peek_parent (klass);
+
+ t_connection_signals [BUSY] =
+ g_signal_new ("busy",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (TConnectionClass, busy),
+ NULL, NULL,
+ _marshal_VOID__BOOLEAN_STRING, G_TYPE_NONE,
+ 2, G_TYPE_BOOLEAN, G_TYPE_STRING);
+ t_connection_signals [META_CHANGED] =
+ g_signal_new ("meta-changed",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (TConnectionClass, meta_changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE,
+ 1, GDA_TYPE_META_STRUCT);
+ t_connection_signals [STATUS_CHANGED] =
+ g_signal_new ("status-changed",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (TConnectionClass, status_changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__ENUM, G_TYPE_NONE,
+ 1, GDA_TYPE_CONNECTION_STATUS);
+ t_connection_signals [FAV_CHANGED] =
+ g_signal_new ("favorites-changed",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (TConnectionClass, favorites_changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID, G_TYPE_NONE,
+ 0);
+ t_connection_signals [TRANSACTION_STATUS_CHANGED] =
+ g_signal_new ("transaction-status-changed",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (TConnectionClass, transaction_status_changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID, G_TYPE_NONE,
+ 0);
+ t_connection_signals [TABLE_COLUMN_PREF_CHANGED] =
+ g_signal_new ("table-column-pref-changed",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (TConnectionClass, table_column_pref_changed),
+ NULL, NULL,
+ _marshal_VOID__POINTER_POINTER_STRING_STRING, G_TYPE_NONE,
+ 4, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_STRING, G_TYPE_STRING);
+ t_connection_signals [NOTICE] =
+ g_signal_new ("notice",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (TConnectionClass, notice),
+ NULL, NULL,
+ _marshal_VOID__STRING, G_TYPE_NONE,
+ 1, G_TYPE_STRING);
+
+ klass->busy = NULL;
+ klass->meta_changed = NULL;
+ klass->favorites_changed = NULL;
+ klass->transaction_status_changed = NULL;
+ klass->table_column_pref_changed = NULL;
+
+ /* Properties */
+ object_class->set_property = t_connection_set_property;
+ object_class->get_property = t_connection_get_property;
+ g_object_class_install_property (object_class, PROP_GDA_CNC,
+ g_param_spec_object ("gda-connection", NULL, "Connection to use",
+ GDA_TYPE_CONNECTION,
+ G_PARAM_WRITABLE |
+ G_PARAM_CONSTRUCT_ONLY));
+
+ object_class->dispose = t_connection_dispose;
+}
+
+static void
+t_connection_init (TConnection *tcnc)
+{
+ static guint index = 1;
+ tcnc->priv = g_new0 (TConnectionPrivate, 1);
+ tcnc->priv->executed_statements = NULL;
+
+ tcnc->priv->name = g_strdup_printf (_("c%u"), index++);
+ tcnc->priv->cnc = NULL;
+ tcnc->priv->parser = NULL;
+ tcnc->priv->variables = NULL;
+ memset (&(tcnc->priv->dsn_info), 0, sizeof (GdaDsnInfo));
+ tcnc->priv->mstruct = NULL;
+
+ tcnc->priv->meta_store_signal = 0;
+ tcnc->priv->transaction_status_signal = 0;
+
+ tcnc->priv->bfav = NULL;
+
+ tcnc->priv->store_cnc = NULL;
+
+ tcnc->priv->variables = NULL;
+ tcnc->priv->query_buffer = NULL;
+}
+
+static void
+transaction_status_changed_cb (GdaConnection *cnc, TConnection *tcnc)
+{
+ g_object_ref (tcnc);
+ g_signal_emit (tcnc, t_connection_signals [TRANSACTION_STATUS_CHANGED], 0);
+ g_object_unref (tcnc);
+}
+
+/*
+ * executed in main thread
+ */
+static void
+meta_changed_cb (G_GNUC_UNUSED GdaMetaStore *store, G_GNUC_UNUSED const GSList *changes, TConnection *tcnc)
+{
+ GError *error = NULL;
+ GdaMetaStruct *mstruct;
+
+ mstruct = gda_meta_struct_new (gda_connection_get_meta_store (tcnc->priv->cnc),
+ GDA_META_STRUCT_FEATURE_ALL);
+
+ t_connection_set_busy_state (tcnc, TRUE, _("Analysing database schema"));
+
+ gboolean compl;
+ compl = gda_meta_struct_complement_all (mstruct, &error);
+
+ t_connection_set_busy_state (tcnc, FALSE, NULL);
+
+ if (compl) {
+ if (tcnc->priv->mstruct)
+ g_object_unref (tcnc->priv->mstruct);
+ tcnc->priv->mstruct = mstruct;
+
+#ifdef GDA_DEBUG_NO
+ GSList *all, *list;
+ g_print ("%s() %p:\n", __FUNCTION__, tcnc->priv->mstruct);
+ all = gda_meta_struct_get_all_db_objects (tcnc->priv->mstruct);
+ for (list = all; list; list = list->next) {
+ GdaMetaDbObject *dbo = (GdaMetaDbObject *) list->data;
+ g_print ("DBO, Type %d: short=>[%s] schema=>[%s] full=>[%s]\n", dbo->obj_type,
+ dbo->obj_short_name, dbo->obj_schema, dbo->obj_full_name);
+ }
+ g_slist_free (all);
+#endif
+ }
+ else {
+ g_object_unref (mstruct);
+ gchar *tmp;
+ tmp = g_strdup_printf (_("Error while fetching meta data from the connection: %s"),
+ error->message ? error->message : _("No detail"));
+ g_clear_error (&error);
+ g_signal_emit (tcnc, t_connection_signals [NOTICE], 0, tmp);
+ g_free (tmp);
+ }
+}
+
+/**
+ * t_connection_meta_data_changed
+ * @tcnc: a #TConnection
+ *
+ * Call this function if the meta data has been changed directly (ie. for example after
+ * declaring or undeclaring a foreign key). This call creates a new #GdaMetaStruct internally used.
+ */
+void
+t_connection_meta_data_changed (TConnection *tcnc)
+{
+ g_return_if_fail (T_IS_CONNECTION (tcnc));
+ meta_changed_cb (NULL, NULL, tcnc);
+}
+
+/*
+ * executed in tcnc->priv->wrapper's thread
+ */
+static gboolean
+have_meta_store_ready (TConnection *tcnc, GError **error)
+{
+ gchar *dict_file_name = NULL;
+ gboolean update_store = FALSE;
+ GdaMetaStore *store;
+ gchar *cnc_string, *cnc_info;
+
+ g_object_get (G_OBJECT (tcnc->priv->cnc),
+ "dsn", &cnc_info,
+ "cnc-string", &cnc_string, NULL);
+ dict_file_name = t_config_info_compute_dict_file_name (cnc_info ? gda_config_get_dsn_info (cnc_info)
: NULL,
+ cnc_string);
+ g_free (cnc_string);
+ if (dict_file_name) {
+ if (T_IS_VIRTUAL_CONNECTION (tcnc))
+ /* force meta store update in case of virtual connection */
+ update_store = TRUE;
+ else if (! g_file_test (dict_file_name, G_FILE_TEST_EXISTS))
+ update_store = TRUE;
+ store = gda_meta_store_new_with_file (dict_file_name);
+ }
+ else {
+ store = gda_meta_store_new (NULL);
+ if (store)
+ update_store = TRUE;
+ }
+ t_config_info_update_meta_store_properties (store, tcnc->priv->cnc);
+
+ tcnc->priv->dict_file_name = dict_file_name;
+ g_object_set (G_OBJECT (tcnc->priv->cnc), "meta-store", store, NULL);
+ if (update_store) {
+ gboolean retval;
+ GdaMetaContext context = {"_tables", 0, NULL, NULL};
+ retval = gda_connection_update_meta_store (tcnc->priv->cnc, &context, error);
+ if (!retval) {
+ g_object_unref (store);
+ return FALSE;
+ }
+ }
+
+ gboolean retval = TRUE;
+ GdaMetaStruct *mstruct;
+ mstruct = gda_meta_struct_new (store, GDA_META_STRUCT_FEATURE_ALL);
+ tcnc->priv->mstruct = mstruct;
+ retval = gda_meta_struct_complement_all (mstruct, error);
+
+#ifdef GDA_DEBUG_NO
+ GSList *all, *list;
+ g_print ("%s() %p:\n", __FUNCTION__, tcnc->priv->mstruct);
+ all = gda_meta_struct_get_all_db_objects (tcnc->priv->mstruct);
+ for (list = all; list; list = list->next) {
+ GdaMetaDbObject *dbo = (GdaMetaDbObject *) list->data;
+ g_print ("DBO, Type %d: short=>[%s] schema=>[%s] full=>[%s]\n", dbo->obj_type,
+ dbo->obj_short_name, dbo->obj_schema, dbo->obj_full_name);
+ }
+ g_slist_free (all);
+#endif
+ g_object_unref (store);
+ return retval;
+}
+
+static void
+cnc_status_changed_cb (GdaConnection *cnc, GdaConnectionStatus status, TConnection *tcnc)
+{
+ g_object_ref (tcnc);
+ g_signal_emit (tcnc, t_connection_signals [STATUS_CHANGED], 0, status);
+ g_object_unref (tcnc);
+}
+
+static void
+t_connection_set_property (GObject *object,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ TConnection *tcnc;
+
+ tcnc = T_CONNECTION (object);
+ if (tcnc->priv) {
+ switch (param_id) {
+ case PROP_GDA_CNC:
+ tcnc->priv->cnc = (GdaConnection*) g_value_get_object (value);
+ if (!tcnc->priv->cnc)
+ return;
+
+ /*g_print ("TConnection %p [%s], wrapper %p, GdaConnection %p\n",
+ tcnc, tcnc->priv->name, tcnc->priv->wrapper, tcnc->priv->cnc);*/
+ g_object_ref (tcnc->priv->cnc);
+ g_object_set (G_OBJECT (tcnc->priv->cnc), "execution-timer", TRUE, NULL);
+ g_signal_connect (tcnc->priv->cnc, "status-changed",
+ G_CALLBACK (cnc_status_changed_cb), tcnc);
+ TO_IMPLEMENT;
+ /*
+ tcnc->priv->transaction_status_signal =
+ gda_thread_wrapper_connect_raw (tcnc->priv->wrapper,
+ tcnc->priv->cnc,
+ "transaction-status-changed",
+ FALSE, FALSE,
+ (GdaThreadWrapperCallback) transaction_status_changed_cb,
+ tcnc);
+ */
+
+
+ /* meta store, open it in a sub thread to avoid locking the GTK thread */
+ GError *lerror = NULL;
+ if (! have_meta_store_ready (tcnc, &lerror)) {
+ gchar *tmp;
+ tmp = g_strdup_printf (_("Error while fetching meta data from the connection:
%s"),
+ lerror->message ? lerror->message : _("No detail"));
+ g_clear_error (&lerror);
+ g_signal_emit (tcnc, t_connection_signals [NOTICE], 0, tmp);
+ g_free (tmp);
+ }
+ TO_IMPLEMENT;
+ /*
+ g_object_get (G_OBJECT (tcnc->priv->cnc), "meta-store", &store, NULL);
+ tcnc->priv->meta_store_signal =
+ gda_thread_wrapper_connect_raw (tcnc->priv->wrapper, store, "meta-changed",
+ FALSE, FALSE,
+ (GdaThreadWrapperCallback) meta_changed_cb,
+ tcnc);
+ g_object_unref (store);
+ */
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ break;
+ }
+ }
+}
+
+
+
+static void
+t_connection_get_property (GObject *object,
+ guint param_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ TConnection *tcnc;
+
+ tcnc = T_CONNECTION (object);
+ if (tcnc->priv) {
+ switch (param_id) {
+ case PROP_GDA_CNC:
+ g_value_set_object (value, tcnc->priv->cnc);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ break;
+ }
+ }
+}
+
+static void
+clear_dsn_info (TConnection *tcnc)
+{
+ g_free (tcnc->priv->dsn_info.name);
+ tcnc->priv->dsn_info.name = NULL;
+
+ g_free (tcnc->priv->dsn_info.provider);
+ tcnc->priv->dsn_info.provider = NULL;
+
+ g_free (tcnc->priv->dsn_info.description);
+ tcnc->priv->dsn_info.description = NULL;
+
+ g_free (tcnc->priv->dsn_info.cnc_string);
+ tcnc->priv->dsn_info.cnc_string = NULL;
+
+ g_free (tcnc->priv->dsn_info.auth_string);
+ tcnc->priv->dsn_info.auth_string = NULL;
+}
+
+static void
+fav_changed_cb (G_GNUC_UNUSED TFavorites *bfav, TConnection *tcnc)
+{
+ g_signal_emit (tcnc, t_connection_signals [FAV_CHANGED], 0);
+}
+
+static void
+t_connection_dispose (GObject *object)
+{
+ TConnection *tcnc;
+
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (T_IS_CONNECTION (object));
+
+ tcnc = T_CONNECTION (object);
+ if (tcnc->priv) {
+ if (tcnc->priv->variables)
+ g_object_unref (tcnc->priv->variables);
+
+ if (tcnc->priv->store_cnc)
+ g_object_unref (tcnc->priv->store_cnc);
+
+ if (tcnc->priv->executed_statements)
+ g_hash_table_destroy (tcnc->priv->executed_statements);
+
+ clear_dsn_info (tcnc);
+
+ g_free (tcnc->priv->dict_file_name);
+ tcnc->priv->dict_file_name = NULL;
+
+ TO_IMPLEMENT;
+ /*
+ if (tcnc->priv->meta_store_signal)
+ gda_thread_wrapper_disconnect (tcnc->priv->wrapper,
+ tcnc->priv->meta_store_signal);
+ if (tcnc->priv->transaction_status_signal)
+ gda_thread_wrapper_disconnect (tcnc->priv->wrapper,
+ tcnc->priv->transaction_status_signal);
+ */
+
+ g_free (tcnc->priv->name);
+ tcnc->priv->name = NULL;
+
+ if (tcnc->priv->mstruct) {
+ g_object_unref (tcnc->priv->mstruct);
+ tcnc->priv->mstruct = NULL;
+ }
+
+ if (tcnc->priv->cnc) {
+ g_signal_handlers_disconnect_by_func (tcnc->priv->cnc,
+ G_CALLBACK (cnc_status_changed_cb), tcnc);
+ g_object_unref (tcnc->priv->cnc);
+ tcnc->priv->cnc = NULL;
+ }
+
+ if (tcnc->priv->parser) {
+ g_object_unref (tcnc->priv->parser);
+ tcnc->priv->parser = NULL;
+ }
+
+ if (tcnc->priv->bfav) {
+ g_signal_handlers_disconnect_by_func (tcnc->priv->bfav,
+ G_CALLBACK (fav_changed_cb), tcnc);
+ g_object_unref (tcnc->priv->bfav);
+ tcnc->priv->bfav = NULL;
+ }
+
+ g_free (tcnc->priv->query_buffer);
+
+ t_connection_set_busy_state (tcnc, FALSE, NULL);
+
+ g_free (tcnc->priv);
+ tcnc->priv = NULL;
+ /*g_print ("=== Disposed TConnection %p\n", tcnc);*/
+ }
+
+ /* parent class */
+ parent_class->dispose (object);
+}
+
+static void
+user_password_needed (GdaDsnInfo *info, const gchar *real_provider,
+ gboolean *out_need_username, gboolean *out_need_password,
+ gboolean *out_need_password_if_user)
+{
+ GdaProviderInfo *pinfo = NULL;
+ if (out_need_username)
+ *out_need_username = FALSE;
+ if (out_need_password)
+ *out_need_password = FALSE;
+ if (out_need_password_if_user)
+ *out_need_password_if_user = FALSE;
+
+ if (real_provider)
+ pinfo = gda_config_get_provider_info (real_provider);
+ else if (info)
+ pinfo = gda_config_get_provider_info (info->provider);
+
+ if (pinfo && pinfo->auth_params) {
+ if (out_need_password) {
+ GdaHolder *h;
+ h = gda_set_get_holder (pinfo->auth_params, "PASSWORD");
+ if (h && gda_holder_get_not_null (h))
+ *out_need_password = TRUE;
+ }
+ if (out_need_username) {
+ GdaHolder *h;
+ h = gda_set_get_holder (pinfo->auth_params, "USERNAME");
+ if (h && gda_holder_get_not_null (h))
+ *out_need_username = TRUE;
+ }
+ if (out_need_password_if_user) {
+ if (gda_set_get_holder (pinfo->auth_params, "PASSWORD") &&
+ gda_set_get_holder (pinfo->auth_params, "USERNAME"))
+ *out_need_password_if_user = TRUE;
+ }
+ }
+}
+
+static gchar*
+read_hidden_passwd (void)
+{
+ gchar *p, password [100];
+
+#ifdef HAVE_TERMIOS_H
+ int fail;
+ struct termios termio;
+
+ fail = tcgetattr (0, &termio);
+ if (fail)
+ return NULL;
+
+ termio.c_lflag &= ~ECHO;
+ fail = tcsetattr (0, TCSANOW, &termio);
+ if (fail)
+ return NULL;
+#else
+#ifdef G_OS_WIN32
+ HANDLE t = NULL;
+ LPDWORD t_orig = NULL;
+
+ /* get a new handle to turn echo off */
+ t_orig = (LPDWORD) malloc (sizeof (DWORD));
+ t = GetStdHandle (STD_INPUT_HANDLE);
+
+ /* save the old configuration first */
+ GetConsoleMode (t, t_orig);
+
+ /* set to the new mode */
+ SetConsoleMode (t, ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT);
+#endif
+#endif
+ p = fgets (password, sizeof (password) - 1, stdin);
+
+#ifdef HAVE_TERMIOS_H
+ termio.c_lflag |= ECHO;
+ tcsetattr (0, TCSANOW, &termio);
+#else
+#ifdef G_OS_WIN32
+ SetConsoleMode (t, *t_orig);
+ fflush (stdout);
+ free (t_orig);
+#endif
+#endif
+
+ if (!p)
+ return NULL;
+
+ for (p = password; *p; p++) {
+ if (*p == '\n') {
+ *p = 0;
+ break;
+ }
+ }
+ p = g_strdup (password);
+ memset (password, 0, sizeof (password));
+
+ return p;
+}
+
+/**
+ * t_connection_name_is_valid:
+ * @name: a name to ckeck
+ *
+ * Returns: %TRUE if @name is considered valid
+ */
+gboolean
+t_connection_name_is_valid (const gchar *name)
+{
+ const gchar *ptr;
+ if (!name || !*name)
+ return FALSE;
+ if (! g_ascii_isalpha (*name) && (*name != '_'))
+ return FALSE;
+ for (ptr = name; *ptr; ptr++)
+ if (!g_ascii_isalnum (*ptr) && (*ptr != '_'))
+ return FALSE;
+ return TRUE;
+}
+
+
+/**
+ * t_connection_open:
+ * @cnc_name: (allow-none): a name to give to the new connection, or %NULL (a new name is automatically
chosen)
+ * @cnc_string: a connection string, or DSN name
+ * @auth_string: (allow-none): an authentication string, or %NULL
+ * @use_term: if %TRUE, then standard stdin and stdout are used to read and display missing information
(username or password)
+ * @error: (allow-none): a place to store errors, or %NULL
+ *
+ * Open a connection.
+ *
+ * Returns: (transfer none): a #TConnection, or %NULL on error
+ */
+TConnection *
+t_connection_open (const gchar *cnc_name, const gchar *cnc_string, const gchar *auth_string, gboolean
use_term, GError **error)
+{
+ GdaConnection *newcnc = NULL;
+ TConnection *tcnc = NULL;
+
+ if (cnc_name && ! t_connection_name_is_valid (cnc_name)) {
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
+ _("Connection name '%s' is invalid"), cnc_name);
+ return NULL;
+ }
+
+ GdaDsnInfo *info;
+ gboolean need_user, need_pass, need_password_if_user;
+ gchar *user, *pass, *real_cnc, *real_provider, *real_auth_string = NULL;
+ gchar *real_cnc_string, *real_cnc_to_split;
+
+ /* if cnc string is a regular file, then use it with SQLite or MSAccess */
+ if (g_file_test (cnc_string, G_FILE_TEST_IS_REGULAR)) {
+ gchar *path, *file, *e1, *e2;
+ const gchar *pname = "SQLite";
+
+ path = g_path_get_dirname (cnc_string);
+ file = g_path_get_basename (cnc_string);
+ if (g_str_has_suffix (file, ".mdb")) {
+ pname = "MSAccess";
+ file [strlen (file) - 4] = 0;
+ }
+ else if (g_str_has_suffix (file, ".db"))
+ file [strlen (file) - 3] = 0;
+ e1 = gda_rfc1738_encode (path);
+ e2 = gda_rfc1738_encode (file);
+ g_free (path);
+ g_free (file);
+ real_cnc_string = g_strdup_printf ("%s://DB_DIR=%s;EXTRA_FUNCTIONS=TRUE;DB_NAME=%s", pname,
e1, e2);
+ g_free (e1);
+ g_free (e2);
+ }
+ else
+ real_cnc_string = g_strdup (cnc_string);
+
+ if (auth_string)
+ real_cnc_to_split = g_strdup_printf ("%s;%s", real_cnc_string, auth_string);
+ else
+ real_cnc_to_split = g_strdup (real_cnc_string);
+ gda_connection_string_split (real_cnc_to_split, &real_cnc, &real_provider, &user, &pass);
+ g_free (real_cnc_to_split);
+ real_cnc_to_split = NULL;
+
+ info = gda_config_get_dsn_info (real_cnc);
+ user_password_needed (info, real_provider, &need_user, &need_pass, &need_password_if_user);
+
+ if (!real_cnc) {
+ g_free (user);
+ g_free (pass);
+ g_free (real_provider);
+ g_set_error (error, GDA_CONNECTION_ERROR, GDA_CONNECTION_DSN_NOT_FOUND_ERROR,
+ _("Malformed connection string '%s'"), cnc_string);
+ g_free (real_cnc_string);
+ return NULL;
+ }
+
+ if ((!user || !pass) && info && info->auth_string) {
+ GdaQuarkList* ql;
+ const gchar *tmp;
+ ql = gda_quark_list_new_from_string (info->auth_string);
+ if (!user) {
+ tmp = gda_quark_list_find (ql, "USERNAME");
+ if (tmp)
+ user = g_strdup (tmp);
+ }
+ if (!pass) {
+ tmp = gda_quark_list_find (ql, "PASSWORD");
+ if (tmp)
+ pass = g_strdup (tmp);
+ }
+ gda_quark_list_free (ql);
+ }
+ if (need_user && ((user && !*user) || !user)) {
+ if (use_term) {
+ gchar buf[80], *ptr;
+ g_print (_("\tUsername for '%s': "), cnc_name);
+ if (! fgets (buf, 80, stdin)) {
+ g_free (real_cnc);
+ g_free (user);
+ g_free (pass);
+ g_free (real_provider);
+ g_set_error (error, GDA_CONNECTION_ERROR, GDA_CONNECTION_DSN_NOT_FOUND_ERROR,
+ _("No username for '%s'"), cnc_string);
+ g_free (real_cnc_string);
+ return NULL;
+ }
+ for (ptr = buf; *ptr; ptr++) {
+ if (*ptr == '\n') {
+ *ptr = 0;
+ break;
+ }
+ }
+ g_free (user);
+ user = g_strdup (buf);
+ }
+ else {
+ g_set_error (error, GDA_CONNECTION_ERROR, GDA_CONNECTION_DSN_NOT_FOUND_ERROR,
+ _("No username for '%s'"), cnc_string);
+ g_free (real_cnc_string);
+ }
+ }
+ if (user)
+ need_pass = need_password_if_user;
+ if (need_pass && ((pass && !*pass) || !pass)) {
+ if (use_term) {
+ gchar *tmp;
+ g_print (_("\tPassword for '%s': "), cnc_name);
+ tmp = read_hidden_passwd ();
+ g_print ("\n");
+ if (! tmp) {
+ g_free (real_cnc);
+ g_free (user);
+ g_free (pass);
+ g_free (real_provider);
+ g_set_error (error, GDA_CONNECTION_ERROR, GDA_CONNECTION_DSN_NOT_FOUND_ERROR,
+ _("No password for '%s'"), cnc_string);
+ g_free (real_cnc_string);
+ return NULL;
+ }
+ g_free (pass);
+ pass = tmp;
+ }
+ else {
+ g_set_error (error, GDA_CONNECTION_ERROR, GDA_CONNECTION_DSN_NOT_FOUND_ERROR,
+ _("No password for '%s'"), cnc_string);
+ g_free (real_cnc_string);
+ return NULL;
+ }
+ }
+
+ if (user || pass) {
+ GString *string;
+ string = g_string_new ("");
+ if (user) {
+ gchar *enc;
+ enc = gda_rfc1738_encode (user);
+ g_string_append_printf (string, "USERNAME=%s", enc);
+ g_free (enc);
+ }
+ if (pass) {
+ gchar *enc;
+ enc = gda_rfc1738_encode (pass);
+ if (user)
+ g_string_append_c (string, ';');
+ g_string_append_printf (string, "PASSWORD=%s", enc);
+ g_free (enc);
+ }
+ real_auth_string = g_string_free (string, FALSE);
+ }
+
+ if (info && !real_provider)
+ newcnc = gda_connection_open_from_dsn (real_cnc_string, real_auth_string,
+ GDA_CONNECTION_OPTIONS_AUTO_META_DATA, error);
+ else
+ newcnc = gda_connection_open_from_string (NULL, real_cnc_string, real_auth_string,
+ GDA_CONNECTION_OPTIONS_AUTO_META_DATA, error);
+
+ g_free (real_cnc_string);
+ g_free (real_cnc);
+ g_free (user);
+ g_free (pass);
+ g_free (real_provider);
+ g_free (real_auth_string);
+
+ if (newcnc) {
+ gchar *dict_file_name = NULL;
+ gchar *cnc_string;
+ const gchar *rootname;
+ gint i;
+ g_object_set (G_OBJECT (newcnc), "execution-timer", TRUE, NULL);
+ g_object_set (newcnc, "execution-slowdown", 2000000, NULL);
+ g_object_get (G_OBJECT (newcnc),
+ "cnc-string", &cnc_string, NULL);
+ dict_file_name = t_config_info_compute_dict_file_name (info, cnc_string);
+ g_free (cnc_string);
+
+ tcnc = t_connection_new (newcnc);
+ g_object_unref (newcnc);
+
+ if (cnc_name && *cnc_name)
+ rootname = cnc_name;
+ else
+ rootname = "c";
+ if (t_connection_get_by_name (rootname)) {
+ for (i = 1; ; i++) {
+ gchar *tmp;
+ tmp = g_strdup_printf ("%s%d", rootname, i);
+ if (t_connection_get_by_name (tmp))
+ g_free (tmp);
+ else {
+ t_connection_set_name (tcnc, tmp);
+ g_free (tmp);
+ break;
+ }
+ }
+ }
+ else
+ t_connection_set_name (tcnc, rootname);
+
+ /* show date format */
+ GDateDMY order[3];
+ gchar sep;
+ if (gda_connection_get_date_format (t_connection_get_cnc (tcnc), &order[0], &order[1],
&order[2], &sep, NULL)) {
+ g_print (_("Date format for this connection will be: %s%c%s%c%s, where YYYY is the
year, MM the month and DD the day\n"),
+ (order [0] == G_DATE_DAY) ? "DD" : ((order [0] == G_DATE_MONTH) ? "MM" :
"YYYY"), sep,
+ (order [1] == G_DATE_DAY) ? "DD" : ((order [1] == G_DATE_MONTH) ? "MM" :
"YYYY"), sep,
+ (order [2] == G_DATE_DAY) ? "DD" : ((order [2] == G_DATE_MONTH) ? "MM" :
"YYYY"));
+ }
+
+ /* dictionay related work */
+ GdaMetaStore *store;
+ gboolean update_store = FALSE;
+
+ if (dict_file_name) {
+ if (! g_file_test (dict_file_name, G_FILE_TEST_EXISTS))
+ update_store = TRUE;
+ store = gda_meta_store_new_with_file (dict_file_name);
+ g_print (_("All the information related to the '%s' connection will be stored "
+ "in the '%s' file\n"),
+ t_connection_get_name (tcnc), dict_file_name);
+ }
+ else {
+ store = gda_meta_store_new (NULL);
+ if (store)
+ update_store = TRUE;
+ }
+
+ t_config_info_update_meta_store_properties (store, newcnc);
+
+ g_object_set (G_OBJECT (t_connection_get_cnc (tcnc)), "meta-store", store, NULL);
+
+ if (update_store) {
+ FILE *ostream = NULL;
+ if (use_term) {
+ ostream = t_context_get_output_stream (t_app_get_term_console (), NULL);
+ if (!ostream) {
+ g_print (_("Getting database schema information for connection '%s',
this may take some time... "),
+ t_connection_get_name (tcnc));
+ fflush (stdout);
+ }
+ }
+
+ GError *lerror = NULL;
+ if (!gda_connection_update_meta_store (t_connection_get_cnc (tcnc), NULL, &lerror)) {
+ if (use_term && !ostream)
+ g_print (_("error: %s\n"),
+ lerror && lerror->message ? lerror->message : _("No
detail"));
+ if (lerror)
+ g_error_free (lerror);
+ }
+ else
+ if (use_term && !ostream)
+ g_print (_("Done.\n"));
+ }
+
+ if (store)
+ g_object_unref (store);
+ g_free (dict_file_name);
+ }
+
+ return tcnc;
+}
+
+/**
+ * t_connection_new
+ * @cnc: a #GdaConnection
+ *
+ * Creates a new #TConnection object wrapping @cnc. The browser_core_take_connection() method
+ * must be called on the new object to mahe it managed by the browser.
+ *
+ * To close the new connection, use t_connection_close().
+ *
+ * Returns: (transfer none): a new object
+ */
+TConnection*
+t_connection_new (GdaConnection *cnc)
+{
+ TConnection *tcnc;
+ g_return_val_if_fail (GDA_IS_CONNECTION (cnc), NULL);
+
+ tcnc = T_CONNECTION (g_object_new (T_TYPE_CONNECTION, "gda-connection", cnc, NULL));
+ t_app_add_tcnc (tcnc);
+ /*g_print ("=== created TCnc %p\n", tcnc);*/
+
+ return tcnc;
+}
+
+/**
+ * t_connection_close:
+ * @tcnc: a #TConnection
+ *
+ * Closes @tcnc. This leads to the @tcnc object being destroyed
+ */
+void
+t_connection_close (TConnection *tcnc)
+{
+ g_return_if_fail (T_IS_CONNECTION (tcnc));
+ gda_connection_close (tcnc->priv->cnc, NULL);
+}
+
+/**
+ * t_connection_get_by_name:
+ * @main_data: a #TApp
+ * @name: a connection's name
+ *
+ * Find a TConnection using its name, the TConnection must be referenced in @main_data
+ *
+ * Returns: (transfer none): the requested #TConnection, or %NULL
+ */
+TConnection *
+t_connection_get_by_name (const gchar *name)
+{
+ g_return_val_if_fail (name, NULL);
+
+ TConnection *tcnc = NULL;
+ const GSList *list;
+ for (list = t_app_get_all_connections (); list; list = list->next) {
+ if (!strcmp (name, t_connection_get_name (T_CONNECTION (list->data)))) {
+ tcnc = (TConnection *) list->data;
+ break;
+ }
+ }
+ return tcnc;
+}
+
+/**
+ * t_connection_get_cnc:
+ * @tcnc: a #TConnection
+ *
+ * Returns: @tcnc's internal #GdaConnection
+ */
+GdaConnection *
+t_connection_get_cnc (TConnection *tcnc)
+{
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
+ return tcnc->priv->cnc;
+}
+
+/**
+ * t_connection_set_name:
+ * @tcnc: a #TConnection
+ * @name: a new name, not %NULL and not empty
+ *
+ * Set @tcnc's name
+ */
+void
+t_connection_set_name (TConnection *tcnc, const gchar *name)
+{
+ g_return_if_fail (T_IS_CONNECTION (tcnc));
+ g_return_if_fail (name && *name);
+ g_free (tcnc->priv->name);
+ tcnc->priv->name = g_strdup (name);
+}
+
+/**
+ * t_connection_get_name
+ * @tcnc: a #TConnection
+ *
+ * Returns: @tcnc's name
+ */
+const gchar *
+t_connection_get_name (TConnection *tcnc)
+{
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
+ return tcnc->priv->name;
+}
+
+/**
+ * t_connection_get_long_name:
+ * @tcnc: a #TConnection
+ *
+ * Get the "long" name of @tcnc
+ *
+ * Returns: a new string
+ */
+gchar *
+t_connection_get_long_name (TConnection *tcnc)
+{
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
+ const gchar *cncname;
+ const GdaDsnInfo *dsn;
+ GString *title;
+
+ dsn = t_connection_get_information (tcnc);
+ cncname = t_connection_get_name (tcnc);
+ title = g_string_new (_("Connection"));
+ g_string_append (title, " ");
+ g_string_append_printf (title, "'%s'", cncname ? cncname : _("unnamed"));
+ if (dsn) {
+ if (dsn->name)
+ g_string_append_printf (title, ", %s '%s'", _("data source"), dsn->name);
+ if (dsn->provider)
+ g_string_append_printf (title, " (%s)", dsn->provider);
+ }
+ return g_string_free (title, FALSE);
+}
+
+/**
+ * t_connection_get_information
+ * @tcnc: a #TConnection
+ *
+ * Get some information about the connection
+ *
+ * Returns: a pointer to the associated #GdaDsnInfo
+ */
+const GdaDsnInfo *
+t_connection_get_information (TConnection *tcnc)
+{
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
+
+ clear_dsn_info (tcnc);
+ if (!tcnc->priv->cnc)
+ return NULL;
+
+ if (gda_connection_get_provider_name (tcnc->priv->cnc))
+ tcnc->priv->dsn_info.provider = g_strdup (gda_connection_get_provider_name (tcnc->priv->cnc));
+ if (gda_connection_get_dsn (tcnc->priv->cnc)) {
+ tcnc->priv->dsn_info.name = g_strdup (gda_connection_get_dsn (tcnc->priv->cnc));
+ if (! tcnc->priv->dsn_info.provider) {
+ GdaDsnInfo *cinfo;
+ cinfo = gda_config_get_dsn_info (tcnc->priv->dsn_info.name);
+ if (cinfo && cinfo->provider)
+ tcnc->priv->dsn_info.provider = g_strdup (cinfo->provider);
+ }
+ }
+ if (gda_connection_get_cnc_string (tcnc->priv->cnc))
+ tcnc->priv->dsn_info.cnc_string = g_strdup (gda_connection_get_cnc_string (tcnc->priv->cnc));
+ if (gda_connection_get_authentication (tcnc->priv->cnc))
+ tcnc->priv->dsn_info.auth_string = g_strdup (gda_connection_get_authentication
(tcnc->priv->cnc));
+
+ return &(tcnc->priv->dsn_info);
+}
+
+/**
+ * t_connection_is_virtual
+ * @tcnc: a #TConnection
+ *
+ * Tells if @tcnc is a virtual connection or not
+ *
+ * Returns: %TRUE if @tcnc is a virtual connection
+ */
+gboolean
+t_connection_is_virtual (TConnection *tcnc)
+{
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), FALSE);
+ if (GDA_IS_VIRTUAL_CONNECTION (tcnc->priv->cnc))
+ return TRUE;
+ else
+ return FALSE;
+}
+
+/**
+ * t_connection_is_busy
+ * @tcnc: a #TConnection
+ * @out_reason: a pointer to store a copy of the reason @tcnc is busy (will be set
+ * to %NULL if @tcnc is not busy), or %NULL
+ *
+ * Tells if @tcnc is currently busy or not.
+ *
+ * Returns: %TRUE if @tcnc is busy
+ */
+gboolean
+t_connection_is_busy (TConnection *tcnc, gchar **out_reason)
+{
+ if (out_reason)
+ *out_reason = NULL;
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), FALSE);
+
+ if (out_reason && tcnc->priv->busy_reason)
+ *out_reason = g_strdup (tcnc->priv->busy_reason);
+
+ return tcnc->priv->busy;
+}
+
+/**
+ * t_connection_update_meta_data
+ * @tcnc: a #TConnection
+ *
+ * Make @tcnc update its meta store in the background.
+ */
+void
+t_connection_update_meta_data (TConnection *tcnc)
+{
+ g_return_if_fail (T_IS_CONNECTION (tcnc));
+
+ t_connection_set_busy_state (tcnc, TRUE, _("Getting database schema information"));
+
+ GdaMetaContext context = {"_tables", 0, NULL, NULL};
+ gboolean result;
+ GError *error = NULL;
+ result = gda_connection_update_meta_store (tcnc->priv->cnc, &context, &error);
+
+ t_connection_set_busy_state (tcnc, FALSE, NULL);
+
+ if (!result) {
+ gchar *tmp;
+ tmp = g_strdup_printf (_("Error while fetching meta data from the connection: %s"),
+ error->message ? error->message : _("No detail"));
+ g_clear_error (&error);
+ g_signal_emit (tcnc, t_connection_signals [NOTICE], 0, tmp);
+ g_free (tmp);
+ }
+}
+
+/**
+ * t_connection_get_meta_struct
+ * @tcnc: a #TConnection
+ *
+ * Get the #GdaMetaStruct maintained up to date by @tcnc.
+ *
+ * Returns: a #GdaMetaStruct, the caller does not have any reference to it.
+ */
+GdaMetaStruct *
+t_connection_get_meta_struct (TConnection *tcnc)
+{
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
+ return tcnc->priv->mstruct;
+}
+
+/**
+ * t_connection_get_meta_store
+ * @tcnc: a #TConnection
+ *
+ * Returns: @tcnc's #GdaMetaStore, the caller does not have any reference to it.
+ */
+GdaMetaStore *
+t_connection_get_meta_store (TConnection *tcnc)
+{
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
+ return gda_connection_get_meta_store (tcnc->priv->cnc);
+}
+
+/**
+ * t_connection_get_dictionary_file
+ * @tcnc: a #TConnection
+ *
+ * Returns: the dictionary file name used by @tcnc, or %NULL
+ */
+const gchar *
+t_connection_get_dictionary_file (TConnection *tcnc)
+{
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
+ return tcnc->priv->dict_file_name;
+}
+
+/**
+ * t_connection_get_transaction_status
+ * @tcnc: a #TConnection
+ *
+ * Retuns: the #GdaTransactionStatus of the connection, or %NULL
+ */
+GdaTransactionStatus *
+t_connection_get_transaction_status (TConnection *tcnc)
+{
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
+ return gda_connection_get_transaction_status (tcnc->priv->cnc);
+}
+
+/**
+ * t_connection_begin
+ * @tcnc: a #TConnection
+ * @error: a place to store errors, or %NULL
+ *
+ * Begins a transaction
+ */
+gboolean
+t_connection_begin (TConnection *tcnc, GError **error)
+{
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), FALSE);
+ return gda_connection_begin_transaction (tcnc->priv->cnc, NULL,
+ GDA_TRANSACTION_ISOLATION_UNKNOWN, error);
+}
+
+/**
+ * t_connection_commit
+ * @tcnc: a #TConnection
+ * @error: a place to store errors, or %NULL
+ *
+ * Commits a transaction
+ */
+gboolean
+t_connection_commit (TConnection *tcnc, GError **error)
+{
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), FALSE);
+ return gda_connection_commit_transaction (tcnc->priv->cnc, NULL, error);
+}
+
+/**
+ * t_connection_rollback
+ * @tcnc: a #TConnection
+ * @error: a place to store errors, or %NULL
+ *
+ * Rolls back a transaction
+ */
+gboolean
+t_connection_rollback (TConnection *tcnc, GError **error)
+{
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), FALSE);
+ return gda_connection_rollback_transaction (tcnc->priv->cnc, NULL, error);
+}
+
+/**
+ * t_connection_get_favorites
+ * @tcnc: a #TConnection
+ *
+ * Get @tcnc's favorites handler
+ *
+ * Returns: (transfer none): the #TFavorites used by @tcnc
+ */
+TFavorites *
+t_connection_get_favorites (TConnection *tcnc)
+{
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
+ if (!tcnc->priv->bfav && !T_IS_VIRTUAL_CONNECTION (tcnc)) {
+ tcnc->priv->bfav = t_favorites_new (gda_connection_get_meta_store (tcnc->priv->cnc));
+ g_signal_connect (tcnc->priv->bfav, "favorites-changed",
+ G_CALLBACK (fav_changed_cb), tcnc);
+ }
+ return tcnc->priv->bfav;
+}
+
+/**
+ * t_connection_get_completions
+ * @tcnc: a #TConnection
+ * @sql:
+ * @start:
+ * @end:
+ *
+ * See gda_completion_list_get()
+ *
+ * Returns: a new array of strings, or NULL (use g_strfreev() to free the returned array)
+ */
+gchar **
+t_connection_get_completions (TConnection *tcnc, const gchar *sql,
+ gint start, gint end)
+{
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
+ return gda_completion_list_get (tcnc->priv->cnc, sql, start, end);
+}
+
+
+/**
+ * t_connection_get_parser:
+ * @tcnc: a #TConnection
+ *
+ * Get the #GdaSqlParser object for @tcnc
+ *
+ * Returns: (transfer none): a #GdaSqlParser
+ */
+GdaSqlParser *
+t_connection_get_parser (TConnection *tcnc)
+{
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
+ if (!tcnc->priv->parser)
+ tcnc->priv->parser = t_connection_create_parser (tcnc);
+
+ return tcnc->priv->parser;
+}
+
+/**
+ * t_connection_create_parser:
+ * @tcnc: a #TConnection
+ *
+ * Create a new #GdaSqlParser object for @tcnc
+ *
+ * Returns: (transfer full): a new #GdaSqlParser
+ */
+GdaSqlParser *
+t_connection_create_parser (TConnection *tcnc)
+{
+ GdaSqlParser *parser;
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
+
+ parser = gda_connection_create_parser (tcnc->priv->cnc);
+ if (!parser)
+ parser = gda_sql_parser_new ();
+ return parser;
+}
+
+/**
+ * t_connection_render_pretty_sql
+ * @tcnc: a #TConnection
+ * @stmt: a #GdaStatement
+ *
+ * Renders @stmt as SQL well indented
+ *
+ * Returns: a new string
+ */
+gchar *
+t_connection_render_pretty_sql (TConnection *tcnc, GdaStatement *stmt)
+{
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
+ g_return_val_if_fail (GDA_IS_STATEMENT (stmt), NULL);
+
+ return gda_statement_to_sql_extended (stmt, tcnc->priv->cnc, NULL,
+ GDA_STATEMENT_SQL_PRETTY |
+ GDA_STATEMENT_SQL_PARAMS_SHORT,
+ NULL, NULL);
+}
+
+/**
+ * t_connection_execute_statement
+ * @tcnc: a #TConnection
+ * @stmt: a #GdaStatement
+ * @params: a #GdaSet as parameters, or %NULL
+ * @model_usage: how the returned data model (if any) will be used
+ * @last_insert_row: (allow-none): a place to store a new GdaSet object which contains the values of the
last inserted row, or %NULL.
+ * @error: a place to store errors, or %NULL
+ *
+ * Executes @stmt by @tcnc.
+ *
+ * Returns: (transfer full): a #GObject, or %NULL if an error occurred
+ */
+GObject *
+t_connection_execute_statement (TConnection *tcnc,
+ GdaStatement *stmt,
+ GdaSet *params,
+ GdaStatementModelUsage model_usage,
+ GdaSet **last_insert_row,
+ GError **error)
+{
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
+ g_return_val_if_fail (GDA_IS_STATEMENT (stmt), NULL);
+ g_return_val_if_fail (!params || GDA_IS_SET (params), NULL);
+
+ GObject *obj;
+ obj = gda_connection_statement_execute (tcnc->priv->cnc, stmt, params, model_usage,
+ last_insert_row, error);
+ if (obj) {
+ if (GDA_IS_DATA_MODEL (obj))
+ /* force loading of rows if necessary */
+ gda_data_model_get_n_rows ((GdaDataModel*) obj);
+ else if (last_insert_row)
+ g_object_set_data (obj, "__tcnc_last_inserted_row", last_insert_row);
+ }
+ return obj;
+}
+
+/**
+ * t_connection_rerun_select
+ * @tcnc: a #TConnection object
+ * @model: a #GdaDataModel, which has to ba a #GdaDataSelect
+ * @error: a place to store errors, or %NULL
+ *
+ * Re-execute @model
+ *
+ * Returns: %TRUE if no error occurred
+ */
+gboolean
+t_connection_rerun_select (TConnection *tcnc,
+ GdaDataModel *model,
+ GError **error)
+{
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), FALSE);
+ g_return_val_if_fail (GDA_IS_DATA_SELECT (model), FALSE);
+
+ return gda_data_select_rerun (GDA_DATA_SELECT (model), error);
+}
+
+/**
+ * t_connection_normalize_sql_statement
+ * @tcnc: a #TConnection
+ * @sqlst: a #GdaSqlStatement
+ * @error: a place to store errors, or %NULL
+ *
+ * See gda_sql_statement_normalize().
+ *
+ * Returns: %TRUE if no error occurred
+ */
+gboolean
+t_connection_normalize_sql_statement (TConnection *tcnc,
+ GdaSqlStatement *sqlst, GError **error)
+{
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), FALSE);
+
+ return gda_sql_statement_normalize (sqlst, tcnc->priv->cnc, error);
+}
+
+/**
+ * t_connection_check_sql_statement_validify
+ */
+gboolean
+t_connection_check_sql_statement_validify (TConnection *tcnc,
+ GdaSqlStatement *sqlst, GError **error)
+{
+ g_return_val_if_fail (sqlst, FALSE);
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), FALSE);
+
+ /* check the structure first */
+ if (!gda_sql_statement_check_structure (sqlst, error))
+ return FALSE;
+
+ return gda_sql_statement_check_validity_m (sqlst, tcnc->priv->mstruct, error);
+}
+
+
+
+/*
+ * DOES emit the "busy" signal
+ */
+void
+t_connection_set_busy_state (TConnection *tcnc, gboolean busy, const gchar *busy_reason)
+{
+ if (busy && !busy_reason)
+ g_warning ("Connection busy, but no reason provided");
+
+ if (tcnc->priv->busy_reason) {
+ g_free (tcnc->priv->busy_reason);
+ tcnc->priv->busy_reason = NULL;
+ }
+
+ tcnc->priv->busy = busy;
+ if (busy_reason)
+ tcnc->priv->busy_reason = g_strdup (busy_reason);
+
+ g_signal_emit (tcnc, t_connection_signals [BUSY], 0, busy, busy_reason);
+}
+
+/*
+ *
+ * Preferences
+ *
+ */
+#define DBTABLE_PREFERENCES_TABLE_NAME "gda_sql_dbtable_preferences"
+#define DBTABLE_PREFERENCES_TABLE_DESC \
+ "<table name=\"" DBTABLE_PREFERENCES_TABLE_NAME "\"> " \
+ " <column name=\"table_schema\" pkey=\"TRUE\"/>" \
+ " <column name=\"table_name\" pkey=\"TRUE\"/>" \
+ " <column name=\"table_column\" nullok=\"TRUE\" pkey=\"TRUE\"/>" \
+ " <column name=\"att_name\"/>" \
+ " <column name=\"att_value\"/>" \
+ "</table>"
+
+static gboolean
+meta_store_addons_init (TConnection *tcnc, GError **error)
+{
+ GError *lerror = NULL;
+ GdaMetaStore *store;
+
+ if (!tcnc->priv->cnc) {
+ g_set_error (error, T_ERROR, T_STORED_DATA_ERROR,
+ "%s", _("Connection not yet opened"));
+ return FALSE;
+ }
+ store = gda_connection_get_meta_store (tcnc->priv->cnc);
+ if (!gda_meta_store_schema_add_custom_object (store, DBTABLE_PREFERENCES_TABLE_DESC, &lerror)) {
+ g_set_error (error, T_ERROR, T_STORED_DATA_ERROR,
+ "%s", _("Can't initialize dictionary to store table preferences"));
+ g_warning ("Can't initialize dictionary to store dbtable_preferences :%s",
+ lerror && lerror->message ? lerror->message : "No detail");
+ if (lerror)
+ g_error_free (lerror);
+ return FALSE;
+ }
+
+ tcnc->priv->store_cnc = g_object_ref (gda_meta_store_get_internal_connection (store));
+ return TRUE;
+}
+
+
+/**
+ * t_connection_set_table_column_attribute
+ * @tcnc:
+ * @dbo:
+ * @column:
+ * @attr_name: attribute name, not %NULL
+ * @value: value to set, or %NULL to unset
+ * @error:
+ *
+ *
+ * Returns: %TRUE if no error occurred
+ */
+gboolean
+t_connection_set_table_column_attribute (TConnection *tcnc,
+ GdaMetaTable *table,
+ GdaMetaTableColumn *column,
+ const gchar *attr_name,
+ const gchar *value, GError **error)
+{
+ GdaConnection *store_cnc;
+
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), FALSE);
+ g_return_val_if_fail (table, FALSE);
+ g_return_val_if_fail (column, FALSE);
+ g_return_val_if_fail (attr_name, FALSE);
+
+ if (! tcnc->priv->store_cnc &&
+ ! meta_store_addons_init (tcnc, error))
+ return FALSE;
+
+ store_cnc = tcnc->priv->store_cnc;
+ if (! gda_lockable_trylock (GDA_LOCKABLE (store_cnc))) {
+ g_set_error (error, T_ERROR, T_STORED_DATA_ERROR,
+ "%s", _("Can't initialize transaction to access favorites"));
+ return FALSE;
+ }
+ /* begin a transaction */
+ if (! gda_connection_begin_transaction (store_cnc, NULL, GDA_TRANSACTION_ISOLATION_UNKNOWN, NULL)) {
+ g_set_error (error, T_ERROR, T_STORED_DATA_ERROR,
+ "%s", _("Can't initialize transaction to access favorites"));
+ gda_lockable_unlock (GDA_LOCKABLE (store_cnc));
+ return FALSE;
+ }
+
+ /* delete existing attribute */
+ GdaStatement *stmt;
+ GdaSqlBuilder *builder;
+ GdaSet *params;
+ GdaSqlBuilderId op_ids[4];
+ GdaMetaDbObject *dbo = (GdaMetaDbObject *) table;
+
+ params = gda_set_new_inline (5, "schema", G_TYPE_STRING, dbo->obj_schema,
+ "name", G_TYPE_STRING, dbo->obj_name,
+ "column", G_TYPE_STRING, column->column_name,
+ "attname", G_TYPE_STRING, attr_name,
+ "attvalue", G_TYPE_STRING, value);
+
+ builder = gda_sql_builder_new (GDA_SQL_STATEMENT_DELETE);
+ gda_sql_builder_set_table (builder, DBTABLE_PREFERENCES_TABLE_NAME);
+ op_ids[0] = gda_sql_builder_add_cond (builder, GDA_SQL_OPERATOR_TYPE_EQ,
+ gda_sql_builder_add_id (builder, "table_schema"),
+ gda_sql_builder_add_param (builder, "schema", G_TYPE_STRING,
+ FALSE), 0);
+ op_ids[1] = gda_sql_builder_add_cond (builder, GDA_SQL_OPERATOR_TYPE_EQ,
+ gda_sql_builder_add_id (builder, "table_name"),
+ gda_sql_builder_add_param (builder, "name", G_TYPE_STRING,
+ FALSE), 0);
+ op_ids[2] = gda_sql_builder_add_cond (builder, GDA_SQL_OPERATOR_TYPE_EQ,
+ gda_sql_builder_add_id (builder, "table_column"),
+ gda_sql_builder_add_param (builder, "column", G_TYPE_STRING,
+ FALSE), 0);
+ op_ids[3] = gda_sql_builder_add_cond (builder, GDA_SQL_OPERATOR_TYPE_EQ,
+ gda_sql_builder_add_id (builder, "att_name"),
+ gda_sql_builder_add_param (builder, "attname", G_TYPE_STRING,
+ FALSE), 0);
+ gda_sql_builder_set_where (builder,
+ gda_sql_builder_add_cond_v (builder, GDA_SQL_OPERATOR_TYPE_AND,
+ op_ids, 4));
+ stmt = gda_sql_builder_get_statement (builder, error);
+ g_object_unref (G_OBJECT (builder));
+ if (!stmt)
+ goto err;
+ if (gda_connection_statement_execute_non_select (store_cnc, stmt, params, NULL, error) == -1) {
+ g_object_unref (stmt);
+ goto err;
+ }
+ g_object_unref (stmt);
+
+ /* insert new attribute if necessary */
+ if (value) {
+ builder = gda_sql_builder_new (GDA_SQL_STATEMENT_INSERT);
+ gda_sql_builder_set_table (builder, DBTABLE_PREFERENCES_TABLE_NAME);
+ gda_sql_builder_add_field_value_id (builder,
+ gda_sql_builder_add_id (builder, "table_schema"),
+ gda_sql_builder_add_param (builder, "schema",
G_TYPE_STRING, FALSE));
+ gda_sql_builder_add_field_value_id (builder,
+ gda_sql_builder_add_id (builder, "table_name"),
+ gda_sql_builder_add_param (builder, "name",
G_TYPE_STRING, FALSE));
+ gda_sql_builder_add_field_value_id (builder,
+ gda_sql_builder_add_id (builder, "table_column"),
+ gda_sql_builder_add_param (builder, "column",
G_TYPE_STRING, FALSE));
+ gda_sql_builder_add_field_value_id (builder,
+ gda_sql_builder_add_id (builder, "att_name"),
+ gda_sql_builder_add_param (builder, "attname",
G_TYPE_STRING, FALSE));
+ gda_sql_builder_add_field_value_id (builder,
+ gda_sql_builder_add_id (builder, "att_value"),
+ gda_sql_builder_add_param (builder, "attvalue",
G_TYPE_STRING, FALSE));
+ stmt = gda_sql_builder_get_statement (builder, error);
+ g_object_unref (G_OBJECT (builder));
+ if (!stmt)
+ goto err;
+ if (gda_connection_statement_execute_non_select (store_cnc, stmt, params, NULL, error) == -1)
{
+ g_object_unref (stmt);
+ goto err;
+ }
+ g_object_unref (stmt);
+ }
+
+ if (! gda_connection_commit_transaction (store_cnc, NULL, NULL)) {
+ g_set_error (error, T_ERROR, T_STORED_DATA_ERROR,
+ "%s", _("Can't commit transaction to access favorites"));
+ goto err;
+ }
+
+ g_object_unref (params);
+ gda_lockable_unlock (GDA_LOCKABLE (store_cnc));
+ /*
+ g_print ("%s(table=>%s, column=>%s, value=>%s)\n", __FUNCTION__, GDA_META_DB_OBJECT
(table)->obj_full_name,
+ column->column_name, value);
+ */
+ g_signal_emit (tcnc, t_connection_signals [TABLE_COLUMN_PREF_CHANGED], 0,
+ table, column, attr_name, value);
+
+ return TRUE;
+
+ err:
+ g_object_unref (params);
+ gda_lockable_unlock (GDA_LOCKABLE (store_cnc));
+ gda_connection_rollback_transaction (store_cnc, NULL, NULL);
+ return FALSE;
+}
+
+/**
+ * t_connection_get_table_column_attribute
+ * @tcnc:
+ * @dbo:
+ * @column: may be %NULL
+ * @attr_name: attribute name, not %NULL
+ * @error:
+ *
+ *
+ * Returns: the requested attribute (as a new string), or %NULL if not set or if an error occurred
+ */
+gchar *
+t_connection_get_table_column_attribute (TConnection *tcnc,
+ GdaMetaTable *table,
+ GdaMetaTableColumn *column,
+ const gchar *attr_name,
+ GError **error)
+{
+ GdaConnection *store_cnc;
+ gchar *retval = NULL;
+
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), FALSE);
+ g_return_val_if_fail (table, FALSE);
+ g_return_val_if_fail (column, FALSE);
+ g_return_val_if_fail (attr_name, FALSE);
+
+ if (! tcnc->priv->store_cnc &&
+ ! meta_store_addons_init (tcnc, error))
+ return FALSE;
+
+ store_cnc = tcnc->priv->store_cnc;
+ if (! gda_lockable_trylock (GDA_LOCKABLE (store_cnc))) {
+ g_set_error (error, T_ERROR, T_STORED_DATA_ERROR,
+ "%s", _("Can't initialize transaction to access favorites"));
+ return FALSE;
+ }
+
+ /* SELECT */
+ GdaStatement *stmt;
+ GdaSqlBuilder *builder;
+ GdaSet *params;
+ GdaSqlBuilderId op_ids[4];
+ GdaDataModel *model = NULL;
+ const GValue *cvalue;
+ GdaMetaDbObject *dbo = (GdaMetaDbObject *) table;
+
+ params = gda_set_new_inline (4, "schema", G_TYPE_STRING, dbo->obj_schema,
+ "name", G_TYPE_STRING, dbo->obj_name,
+ "column", G_TYPE_STRING, column->column_name,
+ "attname", G_TYPE_STRING, attr_name);
+
+ builder = gda_sql_builder_new (GDA_SQL_STATEMENT_SELECT);
+ gda_sql_builder_select_add_target_id (builder,
+ gda_sql_builder_add_id (builder,
DBTABLE_PREFERENCES_TABLE_NAME),
+ NULL);
+ gda_sql_builder_select_add_field (builder, "att_value", NULL, NULL);
+ op_ids[0] = gda_sql_builder_add_cond (builder, GDA_SQL_OPERATOR_TYPE_EQ,
+ gda_sql_builder_add_id (builder, "table_schema"),
+ gda_sql_builder_add_param (builder, "schema", G_TYPE_STRING,
+ FALSE), 0);
+ op_ids[1] = gda_sql_builder_add_cond (builder, GDA_SQL_OPERATOR_TYPE_EQ,
+ gda_sql_builder_add_id (builder, "table_name"),
+ gda_sql_builder_add_param (builder, "name", G_TYPE_STRING,
+ FALSE), 0);
+ op_ids[2] = gda_sql_builder_add_cond (builder, GDA_SQL_OPERATOR_TYPE_EQ,
+ gda_sql_builder_add_id (builder, "table_column"),
+ gda_sql_builder_add_param (builder, "column", G_TYPE_STRING,
+ FALSE), 0);
+ op_ids[3] = gda_sql_builder_add_cond (builder, GDA_SQL_OPERATOR_TYPE_EQ,
+ gda_sql_builder_add_id (builder, "att_name"),
+ gda_sql_builder_add_param (builder, "attname", G_TYPE_STRING,
+ FALSE), 0);
+ gda_sql_builder_set_where (builder,
+ gda_sql_builder_add_cond_v (builder, GDA_SQL_OPERATOR_TYPE_AND,
+ op_ids, 4));
+ stmt = gda_sql_builder_get_statement (builder, error);
+ g_object_unref (G_OBJECT (builder));
+ if (!stmt)
+ goto out;
+
+ model = gda_connection_statement_execute_select (store_cnc, stmt, params, error);
+ g_object_unref (stmt);
+ if (!model)
+ goto out;
+
+ /*gda_data_model_dump (model, NULL);*/
+ if (gda_data_model_get_n_rows (model) == 0)
+ goto out;
+
+ cvalue = gda_data_model_get_value_at (model, 0, 0, error);
+ if (cvalue)
+ retval = g_value_dup_string (cvalue);
+
+ out:
+ if (model)
+ g_object_unref (model);
+ g_object_unref (params);
+ gda_lockable_unlock (GDA_LOCKABLE (store_cnc));
+
+ return retval;
+}
+
+/**
+ * t_connection_define_ui_plugins_for_batch
+ * @tcnc: a #TConnection object
+ * @batch: a #GdaBatch
+ * @params: a #GdaSet (usually created with gda_batch_get_parameters())
+ *
+ * Calls t_connection_define_ui_plugins_for_stmt() for each statement in @batch
+ */
+void
+t_connection_define_ui_plugins_for_batch (TConnection *tcnc, GdaBatch *batch, GdaSet *params)
+{
+ g_return_if_fail (T_IS_CONNECTION (tcnc));
+ g_return_if_fail (GDA_IS_BATCH (batch));
+ if (!params)
+ return;
+ g_return_if_fail (GDA_IS_SET (params));
+
+ const GSList *list;
+ for (list = gda_batch_get_statements (batch); list; list = list->next)
+ t_connection_define_ui_plugins_for_stmt (tcnc, GDA_STATEMENT (list->data), params);
+}
+
+/* remark: the current ABI leaves no room to add a
+ * validity check to the GdaSqlExpr structure, and the following test
+ * should be done in gda_sql_expr_check_validity() once the GdaSqlExpr
+ * has the capacity to hold the information (ie. when ABI is broken)
+ *
+ * The code here is a modification from the gda_sql_select_field_check_validity()
+ * adapted for the GdaSqlExpr.
+ */
+static gboolean
+_gda_sql_expr_check_validity (GdaSqlExpr *expr, GdaMetaStruct *mstruct,
+ GdaMetaDbObject **out_validity_meta_object,
+ GdaMetaTableColumn **out_validity_meta_table_column, GError **error)
+{
+ GdaMetaDbObject *dbo = NULL;
+ const gchar *field_name;
+
+ *out_validity_meta_object = NULL;
+ *out_validity_meta_table_column = NULL;
+
+ if (! expr->value || (G_VALUE_TYPE (expr->value) != G_TYPE_STRING))
+ return TRUE;
+ field_name = g_value_get_string (expr->value);
+
+
+ GdaSqlAnyPart *any;
+ GdaMetaTableColumn *tcol = NULL;
+ GValue value;
+
+ memset (&value, 0, sizeof (GValue));
+ for (any = GDA_SQL_ANY_PART(expr)->parent;
+ any && (any->type != GDA_SQL_ANY_STMT_SELECT) && (any->type != GDA_SQL_ANY_STMT_DELETE) &&
+ (any->type != GDA_SQL_ANY_STMT_UPDATE);
+ any = any->parent);
+ if (!any) {
+ /* not in a structure which can be analysed */
+ return TRUE;
+ }
+
+ switch (any->type) {
+ case GDA_SQL_ANY_STMT_SELECT: {
+ /* go through all the SELECT's targets to see if
+ * there is a table with the corresponding field */
+ GSList *targets;
+ if (((GdaSqlStatementSelect *)any)->from) {
+ for (targets = ((GdaSqlStatementSelect *)any)->from->targets;
+ targets;
+ targets = targets->next) {
+ GdaSqlSelectTarget *target = (GdaSqlSelectTarget *) targets->data;
+ if (!target->validity_meta_object /*&&
+ * commented out in the current context
because
+ *
t_connection_check_sql_statement_validify() has already been
+ * called, will need to be re-added when
movind to the
+ * gda-statement-struct.c file.
+ *
+ * !gda_sql_select_target_check_validity
(target, data, error)*/)
+ return FALSE;
+
+ g_value_set_string (g_value_init (&value, G_TYPE_STRING), field_name);
+ tcol = gda_meta_struct_get_table_column (mstruct,
+ GDA_META_TABLE
(target->validity_meta_object),
+ &value);
+ g_value_unset (&value);
+ if (tcol) {
+ /* found a candidate */
+ if (dbo) {
+ g_set_error (error, GDA_SQL_ERROR, GDA_SQL_VALIDATION_ERROR,
+ _("Could not identify table for field '%s'"),
field_name);
+ return FALSE;
+ }
+ dbo = target->validity_meta_object;
+ }
+ }
+ }
+ break;
+ }
+ case GDA_SQL_ANY_STMT_UPDATE: {
+ GdaSqlTable *table;
+ table = ((GdaSqlStatementUpdate *)any)->table;
+ if (!table || !table->validity_meta_object /* ||
+ * commented out in the current context because
+ * t_connection_check_sql_statement_validify() has
already been
+ * called, will need to be re-added when movind to
the
+ * gda-statement-struct.c file.
+ *
+ * !gda_sql_select_target_check_validity (target,
data, error)*/)
+ return FALSE;
+ dbo = table->validity_meta_object;
+ g_value_set_string (g_value_init (&value, G_TYPE_STRING), field_name);
+ tcol = gda_meta_struct_get_table_column (mstruct,
+ GDA_META_TABLE (table->validity_meta_object),
+ &value);
+ g_value_unset (&value);
+ break;
+ }
+ case GDA_SQL_ANY_STMT_DELETE: {
+ GdaSqlTable *table;
+ table = ((GdaSqlStatementDelete *)any)->table;
+ if (!table || !table->validity_meta_object /* ||
+ * commented out in the current context because
+ * t_connection_check_sql_statement_validify() has
already been
+ * called, will need to be re-added when movind to
the
+ * gda-statement-struct.c file.
+ *
+ * !gda_sql_select_target_check_validity (target,
data, error)*/)
+ return FALSE;
+ dbo = table->validity_meta_object;
+ g_value_set_string (g_value_init (&value, G_TYPE_STRING), field_name);
+ tcol = gda_meta_struct_get_table_column (mstruct,
+ GDA_META_TABLE (table->validity_meta_object),
+ &value);
+ g_value_unset (&value);
+ break;
+ }
+ default:
+ g_assert_not_reached ();
+ break;
+ }
+
+ if (!dbo) {
+ g_set_error (error, GDA_SQL_ERROR, GDA_SQL_VALIDATION_ERROR,
+ _("Could not identify table for field '%s'"), field_name);
+ return FALSE;
+ }
+ *out_validity_meta_object = dbo;
+ *out_validity_meta_table_column = tcol;
+ return TRUE;
+}
+
+typedef struct {
+ TConnection *tcnc;
+ GdaSet *params;
+} ParamsData;
+
+/*
+ *
+ * In this function we try to find for which table's column a parameter is and use
+ * preferences to set the GdaHolder's plugin attribute
+ */
+static gboolean
+foreach_ui_plugins_for_params (GdaSqlAnyPart *part, ParamsData *data, G_GNUC_UNUSED GError **error)
+{
+ if (part->type != GDA_SQL_ANY_EXPR)
+ return TRUE;
+ GdaSqlExpr *expr = (GdaSqlExpr*) part;
+ if (!expr->param_spec)
+ return TRUE;
+
+ GdaHolder *holder;
+ holder = gda_set_get_holder (data->params, expr->param_spec->name);
+ if (! holder)
+ return TRUE;
+
+ GdaSqlAnyPart *uppart;
+ gchar *plugin = NULL;
+ uppart = part->parent;
+ if (!uppart)
+ return TRUE;
+ else if (uppart->type == GDA_SQL_ANY_SQL_OPERATION) {
+ GdaSqlOperation *op = (GdaSqlOperation*) uppart;
+ /* look into condition */
+ GSList *list;
+ for (list = op->operands; list; list = list->next) {
+ GdaSqlExpr *oexpr = (GdaSqlExpr*) list->data;
+ if (oexpr == expr)
+ continue;
+
+ GdaMetaDbObject *validity_meta_object;
+ GdaMetaTableColumn *validity_meta_table_column;
+ if (_gda_sql_expr_check_validity (oexpr,
+ t_connection_get_meta_struct (data->tcnc),
+ &validity_meta_object,
+ &validity_meta_table_column, NULL)) {
+ plugin = t_connection_get_table_column_attribute (data->tcnc,
+ GDA_META_TABLE
(validity_meta_object),
+ validity_meta_table_column,
+ T_CONNECTION_COLUMN_PLUGIN,
NULL);
+ break;
+ }
+ }
+ }
+ else if (uppart->type == GDA_SQL_ANY_STMT_UPDATE) {
+ GdaSqlStatementUpdate *upd = (GdaSqlStatementUpdate*) uppart;
+ GdaSqlField *field;
+ field = g_slist_nth_data (upd->fields_list, g_slist_index (upd->expr_list, expr));
+ if (field)
+ plugin = t_connection_get_table_column_attribute (data->tcnc,
+ GDA_META_TABLE
(upd->table->validity_meta_object),
+ field->validity_meta_table_column,
+ T_CONNECTION_COLUMN_PLUGIN, NULL);
+ }
+ else if (uppart->type == GDA_SQL_ANY_STMT_INSERT) {
+ GdaSqlStatementInsert *ins = (GdaSqlStatementInsert*) uppart;
+ GdaSqlField *field;
+ gint expr_index = -1;
+ GSList *slist;
+ GdaMetaTableColumn *column = NULL;
+ for (slist = ins->values_list; slist; slist = slist->next) {
+ expr_index = g_slist_index ((GSList*) slist->data, expr);
+ if (expr_index >= 0)
+ break;
+ }
+ if (expr_index >= 0) {
+ field = g_slist_nth_data (ins->fields_list, expr_index);
+ if (field)
+ column = field->validity_meta_table_column;
+ else {
+ /* no field specified => take the table's fields */
+ GdaMetaTable *mtable = GDA_META_TABLE (ins->table->validity_meta_object);
+ column = g_slist_nth_data (mtable->columns, expr_index);
+ }
+ }
+ if (column)
+ plugin = t_connection_get_table_column_attribute (data->tcnc,
+ GDA_META_TABLE
(ins->table->validity_meta_object),
+ column,
+ T_CONNECTION_COLUMN_PLUGIN, NULL);
+ }
+
+ if (plugin) {
+ /*g_print ("Using plugin [%s]\n", plugin);*/
+ GValue *value;
+ g_value_take_string ((value = gda_value_new (G_TYPE_STRING)), plugin);
+ gda_holder_set_attribute_static (holder, GDAUI_ATTRIBUTE_PLUGIN, value);
+ gda_value_free (value);
+ }
+
+ return TRUE;
+}
+
+/**
+ * t_connection_define_ui_plugins_for_stmt
+ * @tcnc: a #TConnection object
+ * @stmt: a #GdaStatement
+ * @params: a #GdaSet (usually created with gda_statement_get_parameters())
+ *
+ * Analyses @stmt and assign plugins to each #GdaHolder in @params according to the preferences stored
+ * for each table's field, defined at some point using t_connection_set_table_column_attribute().
+ */
+void
+t_connection_define_ui_plugins_for_stmt (TConnection *tcnc, GdaStatement *stmt, GdaSet *params)
+{
+ g_return_if_fail (T_IS_CONNECTION (tcnc));
+ g_return_if_fail (GDA_IS_STATEMENT (stmt));
+ if (!params)
+ return;
+ g_return_if_fail (GDA_IS_SET (params));
+
+ GdaSqlStatement *sqlst;
+ GdaSqlAnyPart *rootpart;
+ g_object_get ((GObject*) stmt, "structure", &sqlst, NULL);
+ g_return_if_fail (sqlst);
+ switch (sqlst->stmt_type) {
+ case GDA_SQL_STATEMENT_INSERT:
+ case GDA_SQL_STATEMENT_UPDATE:
+ case GDA_SQL_STATEMENT_DELETE:
+ case GDA_SQL_STATEMENT_SELECT:
+ case GDA_SQL_STATEMENT_COMPOUND:
+ rootpart = (GdaSqlAnyPart*) sqlst->contents;
+ break;
+ default:
+ rootpart = NULL;
+ break;
+ }
+ GError *lerror = NULL;
+ if (!rootpart || !t_connection_check_sql_statement_validify (tcnc, sqlst, &lerror)) {
+ /*g_print ("ERROR: %s\n", lerror && lerror->message ? lerror->message : "No detail");*/
+ g_clear_error (&lerror);
+ gda_sql_statement_free (sqlst);
+ return;
+ }
+
+ ParamsData data;
+ data.params = params;
+ data.tcnc = tcnc;
+ gda_sql_any_part_foreach (rootpart, (GdaSqlForeachFunc) foreach_ui_plugins_for_params,
+ &data, NULL);
+
+ gda_sql_statement_free (sqlst);
+
+ /* REM: we also need to handle FK tables to propose a drop down list of possible values */
+}
+
+/**
+ * t_connection_keep_variables
+ * @tcnc: a #TConnection object
+ * @set: a #GdaSet containing variables for which a copy has to be done
+ *
+ * Makes a copy of the variables in @set and keep them in @tcnc. Retreive them
+ * using t_connection_load_variables()
+ */
+void
+t_connection_keep_variables (TConnection *tcnc, GdaSet *set)
+{
+ g_return_if_fail (T_IS_CONNECTION (tcnc));
+ if (!set)
+ return;
+ g_return_if_fail (GDA_IS_SET (set));
+
+ if (! tcnc->priv->variables) {
+ tcnc->priv->variables = gda_set_copy (set);
+ return;
+ }
+
+ GSList *list;
+ for (list = set->holders; list; list = list->next) {
+ GdaHolder *nh, *eh;
+ nh = GDA_HOLDER (list->data);
+ eh = gda_set_get_holder (tcnc->priv->variables, gda_holder_get_id (nh));
+ if (eh) {
+ if (gda_holder_get_g_type (nh) == gda_holder_get_g_type (eh)) {
+ const GValue *cvalue;
+ cvalue = gda_holder_get_value (nh);
+ gda_holder_set_value (eh, cvalue, NULL);
+ }
+ else {
+ gda_set_remove_holder (tcnc->priv->variables, eh);
+ eh = gda_holder_copy (nh);
+ gda_set_add_holder (tcnc->priv->variables, eh);
+ g_object_unref (eh);
+ }
+ }
+ else {
+ eh = gda_holder_copy (nh);
+ gda_set_add_holder (tcnc->priv->variables, eh);
+ g_object_unref (eh);
+ }
+ }
+}
+
+/**
+ * t_connection_load_variables
+ * @tcnc: a #TConnection object
+ * @set: a #GdaSet which will in the end contain (if any) variables stored in @tcnc
+ *
+ * For each #GdaHolder in @set, set the value if one is available in @tcnc.
+ */
+void
+t_connection_load_variables (TConnection *tcnc, GdaSet *set)
+{
+ g_return_if_fail (T_IS_CONNECTION (tcnc));
+ if (!set)
+ return;
+ g_return_if_fail (GDA_IS_SET (set));
+
+ if (! tcnc->priv->variables)
+ return;
+
+ GSList *list;
+ for (list = set->holders; list; list = list->next) {
+ GdaHolder *nh, *eh;
+ nh = GDA_HOLDER (list->data);
+ eh = gda_set_get_holder (tcnc->priv->variables, gda_holder_get_id (nh));
+ if (eh) {
+ if (gda_holder_get_g_type (nh) == gda_holder_get_g_type (eh)) {
+ const GValue *cvalue;
+ cvalue = gda_holder_get_value (eh);
+ gda_holder_set_value (nh, cvalue, NULL);
+ }
+ else if (g_value_type_transformable (gda_holder_get_g_type (eh),
+ gda_holder_get_g_type (nh))) {
+ const GValue *evalue;
+ GValue *nvalue;
+ evalue = gda_holder_get_value (eh);
+ nvalue = gda_value_new (gda_holder_get_g_type (nh));
+ if (g_value_transform (evalue, nvalue))
+ gda_holder_take_value (nh, nvalue, NULL);
+ else
+ gda_value_free (nvalue);
+ }
+ }
+ }
+}
+
+/**
+ * t_connection_is_ldap:
+ * @tcnc: a #TConnection
+ *
+ * Returns: %TRUE if @tcnc proxies an LDAP connection
+ */
+gboolean
+t_connection_is_ldap (TConnection *tcnc)
+{
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), FALSE);
+
+#ifdef HAVE_LDAP
+ return GDA_IS_LDAP_CONNECTION (tcnc->priv->cnc) ? TRUE : FALSE;
+#endif
+ return FALSE;
+}
+
+#ifdef HAVE_LDAP
+
+/**
+ * t_connection_ldap_search:
+ *
+ * Executes an LDAP search. Wrapper around gda_data_model_ldap_new()
+ *
+ * Returns: (transfer full): a new #GdaDataModel, or %NULL on error
+ */
+GdaDataModel *
+t_connection_ldap_search (TConnection *tcnc,
+ const gchar *base_dn, const gchar *filter,
+ const gchar *attributes, GdaLdapSearchScope scope,
+ GError **error)
+{
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
+ g_return_val_if_fail (GDA_IS_LDAP_CONNECTION (tcnc->priv->cnc), NULL);
+
+ GdaDataModel *model;
+ model = (GdaDataModel*) gda_data_model_ldap_new_with_config (GDA_CONNECTION (tcnc->priv->cnc),
base_dn,
+ filter, attributes, scope);
+ if (!model) {
+ g_set_error (error, T_ERROR, T_INTERNAL_COMMAND_ERROR,
+ "%s", _("Could not execute LDAP search"));
+ return NULL;
+ }
+ else {
+ GdaDataModel *wrapped;
+ wrapped = gda_data_access_wrapper_new (model);
+ g_object_unref (model);
+ /* force loading all the LDAP entries in memory to avoid
+ * having the GTK thread lock on LDAP searches */
+ gda_data_model_get_n_rows (wrapped);
+ return wrapped;
+ }
+}
+
+/**
+ * t_connection_ldap_describe_entry:
+ * @tcnc: a #TConnection
+ * @dn: the DN of the entry to describe
+ * @callback: the callback to execute with the results
+ * @cb_data: a pointer to pass to @callback
+ * @error: a place to store errors, or %NULL
+ *
+ * Wrapper around gda_ldap_describe_entry().
+ *
+ * Returns: (transfer full): a new #GdaLdapEntry, or %NULL
+ */
+GdaLdapEntry *
+t_connection_ldap_describe_entry (TConnection *tcnc, const gchar *dn, GError **error)
+{
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), 0);
+ g_return_val_if_fail (GDA_IS_LDAP_CONNECTION (tcnc->priv->cnc), 0);
+
+ return gda_ldap_describe_entry (GDA_LDAP_CONNECTION (tcnc->priv->cnc), dn, error);
+}
+
+/**
+ * t_connection_ldap_get_entry_children:
+ * @tcnc: a #TConnection
+ * @dn: the DN of the entry to get children from
+ * @callback: the callback to execute with the results
+ * @cb_data: a pointer to pass to @callback
+ * @error: a place to store errors, or %NULL
+ *
+ * Wrapper around gda_ldap_get_entry_children().
+ *
+ * Returns: (transfer full): a %NULL terminated array of #GdaLdapEntry pointers, or %NULL if an error
occurred
+ */
+GdaLdapEntry **
+t_connection_ldap_get_entry_children (TConnection *tcnc, const gchar *dn,
+ gchar **attributes, GError **error)
+{
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), 0);
+ g_return_val_if_fail (GDA_IS_LDAP_CONNECTION (tcnc->priv->cnc), 0);
+
+ return gda_ldap_get_entry_children (GDA_LDAP_CONNECTION (tcnc->priv->cnc), dn, attributes, error);
+}
+
+/**
+ * t_connection_ldap_get_base_dn:
+ * @tcnc: a #TConnection
+ *
+ * wrapper for gda_ldap_connection_get_base_dn()
+ *
+ * Returns: the base DN or %NULL
+ */
+const gchar *
+t_connection_ldap_get_base_dn (TConnection *tcnc)
+{
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
+ g_return_val_if_fail (GDA_IS_LDAP_CONNECTION (tcnc->priv->cnc), NULL);
+
+ return gda_ldap_connection_get_base_dn (GDA_LDAP_CONNECTION (tcnc->priv->cnc));
+}
+
+/**
+ * t_connection_describe_table:
+ * @tcnc: a #TConnection
+ * @table_name: a table name, not %NULL
+ * @out_base_dn: (allow-none) (transfer none): a place to store the LDAP search base DN, or %NULL
+ * @out_filter: (allow-none) (transfer none): a place to store the LDAP search filter, or %NULL
+ * @out_attributes: (allow-none) (transfer none): a place to store the LDAP search attributes, or %NULL
+ * @out_scope: (allow-none) (transfer none): a place to store the LDAP search scope, or %NULL
+ * @error: a place to store errors, or %NULL
+ */
+gboolean
+t_connection_describe_table (TConnection *tcnc, const gchar *table_name,
+ const gchar **out_base_dn, const gchar **out_filter,
+ const gchar **out_attributes,
+ GdaLdapSearchScope *out_scope, GError **error)
+{
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), FALSE);
+ g_return_val_if_fail (t_connection_is_ldap (tcnc), FALSE);
+ g_return_val_if_fail (table_name && *table_name, FALSE);
+
+ return gda_ldap_connection_describe_table (GDA_LDAP_CONNECTION (tcnc->priv->cnc),
+ table_name, out_base_dn, out_filter,
+ out_attributes, out_scope, error);
+}
+
+/**
+ * t_connection_get_class_info:
+ * @tcnc: a #TConnection
+ * @classname: a class name
+ *
+ * proxy for gda_ldap_get_class_info.
+ */
+GdaLdapClass *
+t_connection_get_class_info (TConnection *tcnc, const gchar *classname)
+{
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
+ g_return_val_if_fail (t_connection_is_ldap (tcnc), NULL);
+
+ return gda_ldap_get_class_info (GDA_LDAP_CONNECTION (tcnc->priv->cnc), classname);
+}
+
+/**
+ * t_connection_get_top_classes:
+ * @tcnc: a #TConnection
+ *
+ * proxy for gda_ldap_get_top_classes.
+ */
+const GSList *
+t_connection_get_top_classes (TConnection *tcnc)
+{
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
+ g_return_val_if_fail (t_connection_is_ldap (tcnc), NULL);
+
+ return gda_ldap_get_top_classes (GDA_LDAP_CONNECTION (tcnc->priv->cnc));
+}
+
+/**
+ * t_connection_declare_table:
+ * @tcnc: a #TConnection
+ *
+ * Wrapper around gda_ldap_connection_declare_table()
+ */
+gboolean
+t_connection_declare_table (TConnection *tcnc,
+ const gchar *table_name,
+ const gchar *base_dn,
+ const gchar *filter,
+ const gchar *attributes,
+ GdaLdapSearchScope scope,
+ GError **error)
+{
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), FALSE);
+ g_return_val_if_fail (t_connection_is_ldap (tcnc), FALSE);
+
+ return gda_ldap_connection_declare_table (GDA_LDAP_CONNECTION (tcnc->priv->cnc),
+ table_name, base_dn, filter,
+ attributes, scope, error);
+}
+
+/**
+ * t_connection_undeclare_table:
+ * @tcnc: a #TConnection
+ *
+ * Wrapper around gda_ldap_connection_undeclare_table()
+ */
+gboolean
+t_connection_undeclare_table (TConnection *tcnc,
+ const gchar *table_name,
+ GError **error)
+{
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), FALSE);
+ g_return_val_if_fail (t_connection_is_ldap (tcnc), FALSE);
+
+ return gda_ldap_connection_undeclare_table (GDA_LDAP_CONNECTION (tcnc->priv->cnc),
+ table_name, error);
+}
+
+#endif /* HAVE_LDAP */
+
+/**
+ * t_connection_set_query_buffer:
+ * @tcnc: a #TConnection
+ * @sql: (allow-none): a string, or %NULL
+ *
+ * Set @tcnc's associated query buffer
+ */
+void
+t_connection_set_query_buffer (TConnection *tcnc, const gchar *sql)
+{
+ g_return_if_fail (T_IS_CONNECTION (tcnc));
+ g_free (tcnc->priv->query_buffer);
+ tcnc->priv->query_buffer = sql ? g_strdup (sql) : NULL;
+}
+
+/**
+ * t_connection_get_query_buffer:
+ * @tcnc: a #TConnection
+ *
+ * Get @tcnc's associated query buffer.
+ *
+ * Returns: the query buffer
+ */
+const gchar *
+t_connection_get_query_buffer (TConnection *tcnc)
+{
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
+ return tcnc->priv->query_buffer;
+}
diff --git a/tools/common/t-connection.h b/tools/common/t-connection.h
new file mode 100644
index 0000000..e3586c9
--- /dev/null
+++ b/tools/common/t-connection.h
@@ -0,0 +1,218 @@
+/*
+ * Copyright (C) 2009 - 2014 Vivien Malerba <malerba gnome-db org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __T_CONNECTION_H_
+#define __T_CONNECTION_H_
+
+#include <libgda/libgda.h>
+#include "t-favorites.h"
+#include "t-decl.h"
+#ifdef HAVE_LDAP
+#include <libgda/sqlite/virtual/gda-ldap-connection.h>
+#endif
+
+G_BEGIN_DECLS
+
+#define T_TYPE_CONNECTION (t_connection_get_type())
+#define T_CONNECTION(obj) G_TYPE_CHECK_INSTANCE_CAST (obj, t_connection_get_type(), TConnection)
+#define T_CONNECTION_CLASS(klass) G_TYPE_CHECK_CLASS_CAST (klass, t_connection_get_type (),
TConnectionClass)
+#define T_IS_CONNECTION(obj) G_TYPE_CHECK_INSTANCE_TYPE (obj, t_connection_get_type ())
+
+typedef struct _TConnection TConnection;
+typedef struct _TConnectionClass TConnectionClass;
+typedef struct _TConnectionPrivate TConnectionPrivate;
+
+/* struct for the object's data */
+struct _TConnection
+{
+ GObject object;
+ TConnectionPrivate *priv;
+};
+
+/* struct for the object's class */
+struct _TConnectionClass
+{
+ GObjectClass parent_class;
+
+ /* signals */
+ void (*busy) (TConnection *tcnc, gboolean is_busy, const gchar *reason);
+ void (*status_changed) (TConnection *tcnc, GdaConnectionStatus status);
+ void (*meta_changed) (TConnection *tcnc, GdaMetaStruct *mstruct);
+ void (*favorites_changed) (TConnection *tcnc);
+ void (*transaction_status_changed) (TConnection *tcnc);
+ void (*table_column_pref_changed) (TConnection *tcnc, GdaMetaTable *table,
+ GdaMetaTableColumn *column,
+ const gchar *attr_name, const gchar *value);
+ void (*notice) (TConnection *tcnc, const gchar *notice);
+};
+
+/**
+ * SECTION:t-connection
+ * @short_description: An opened connection
+ * @title: TConnection
+ * @stability: Stable
+ * @see_also:
+ *
+ * The #TConnection object wraps a #GdaConnection with some
+ * additionnal features. The wrapped #GdaConnection is only accessible from within
+ * the #TConnection object, so to use a connection, you have to use the
+ * #TConnection's methods.
+ */
+
+gboolean t_connection_name_is_valid (const gchar *name);
+GType t_connection_get_type (void) G_GNUC_CONST;
+
+TConnection *t_connection_open (const gchar *cnc_name, const gchar *cnc_string,
const gchar *auth_string,
+ gboolean use_term, GError **error);
+void t_connection_close (TConnection *tcnc);
+TConnection *t_connection_new (GdaConnection *cnc);
+TConnection *t_connection_get_by_name (const gchar *name);
+GdaConnection *t_connection_get_cnc (TConnection *tcnc);
+void t_connection_set_name (TConnection *tcnc, const gchar *name);
+const gchar *t_connection_get_name (TConnection *tcnc);
+gchar *t_connection_get_long_name (TConnection *tcnc);
+const GdaDsnInfo *t_connection_get_information (TConnection *tcnc);
+
+gboolean t_connection_is_busy (TConnection *tcnc, gchar **out_reason);
+gboolean t_connection_is_virtual (TConnection *tcnc);
+void t_connection_update_meta_data (TConnection *tcnc);
+void t_connection_meta_data_changed (TConnection *tcnc);
+GdaMetaStruct *t_connection_get_meta_struct (TConnection *tcnc);
+GdaMetaStore *t_connection_get_meta_store (TConnection *tcnc);
+const gchar *t_connection_get_dictionary_file (TConnection *tcnc);
+
+TFavorites *t_connection_get_favorites (TConnection *tcnc);
+
+gchar **t_connection_get_completions (TConnection *tcnc, const gchar *sql,
+ gint start, gint end);
+
+void t_connection_set_query_buffer (TConnection *tcnc, const gchar *sql);
+const gchar *t_connection_get_query_buffer (TConnection *tcnc);
+
+/**
+ * TConnectionJobCallback:
+ * @tcnc: the #TConnection
+ * @out_result: the execution result
+ * @data: a pointer passed when calling the execution function such as t_connection_ldap_describe_entry()
+ * @error: the error returned, if any
+ *
+ * Callback function called when a job (not a statement execution job) is finished.
+ * the out_result is not used by the TConnection anymore after this function has been
+ * called, so you need to keep it or free it.
+ *
+ * @error should not be modified.
+ */
+typedef void (*TConnectionJobCallback) (TConnection *tcnc,
+ gpointer out_result, gpointer data, GError *error);
+#define T_CONNECTION_JOB_CALLBACK(x) ((TConnectionJobCallback)(x))
+void t_connection_job_cancel (TConnection *tcnc, guint job_id);
+
+/*
+ * statements's manipulations
+ */
+GdaSqlParser *t_connection_get_parser (TConnection *tcnc);
+GdaSqlParser *t_connection_create_parser (TConnection *tcnc);
+gchar *t_connection_render_pretty_sql (TConnection *tcnc,
+ GdaStatement *stmt);
+GObject *t_connection_execute_statement (TConnection *tcnc,
+ GdaStatement *stmt,
+ GdaSet *params,
+ GdaStatementModelUsage model_usage,
+ GdaSet **last_insert_row,
+ GError **error);
+gboolean t_connection_rerun_select (TConnection *tcnc,
+ GdaDataModel *model,
+ GError **error);
+void t_connection_set_busy_state (TConnection *bcnc, gboolean busy, const gchar *busy_reason);
+gboolean t_connection_normalize_sql_statement(TConnection *tcnc,
+ GdaSqlStatement *sqlst, GError **error);
+gboolean t_connection_check_sql_statement_validify (TConnection *tcnc,
+ GdaSqlStatement *sqlst, GError **error);
+
+/*
+ * transactions
+ */
+GdaTransactionStatus *t_connection_get_transaction_status (TConnection *tcnc);
+gboolean t_connection_begin (TConnection *tcnc, GError **error);
+gboolean t_connection_commit (TConnection *tcnc, GError **error);
+gboolean t_connection_rollback (TConnection *tcnc, GError **error);
+
+/*
+ * preferences
+ */
+#define T_CONNECTION_COLUMN_PLUGIN "PLUGIN"
+gboolean t_connection_set_table_column_attribute (TConnection *tcnc,
+ GdaMetaTable *table,
+ GdaMetaTableColumn *column,
+ const gchar *attr_name,
+ const gchar *value, GError **error);
+gchar *t_connection_get_table_column_attribute (TConnection *tcnc,
+ GdaMetaTable *table,
+ GdaMetaTableColumn *column,
+ const gchar *attr_name,
+ GError **error);
+
+void t_connection_define_ui_plugins_for_batch(TConnection *tcnc,
+ GdaBatch *batch, GdaSet *params);
+void t_connection_define_ui_plugins_for_stmt (TConnection *tcnc,
+ GdaStatement *stmt, GdaSet *params);
+
+/*
+ * Variables used at various places and for which a copy of the last recent value
+ * is stored in the TConnection object
+ */
+void t_connection_keep_variables (TConnection *tcnc, GdaSet *set);
+void t_connection_load_variables (TConnection *tcnc, GdaSet *set);
+
+/*
+ * LDAP
+ */
+gboolean t_connection_is_ldap (TConnection *tcnc);
+#ifdef HAVE_LDAP
+const gchar *t_connection_ldap_get_base_dn (TConnection *tcnc);
+GdaDataModel *t_connection_ldap_search (TConnection *tcnc,
+ const gchar *base_dn, const gchar *filter,
+ const gchar *attributes, GdaLdapSearchScope scope,
+ GError **error);
+GdaLdapEntry *t_connection_ldap_describe_entry (TConnection *tcnc, const gchar *dn, GError **error);
+GdaLdapEntry **t_connection_ldap_get_entry_children (TConnection *tcnc, const gchar *dn,
+ gchar **attributes, GError **error);
+gboolean t_connection_describe_table (TConnection *tcnc, const gchar *table_name,
+ const gchar **out_base_dn, const gchar **out_filter,
+ const gchar **out_attributes,
+ GdaLdapSearchScope *out_scope, GError **error);
+
+GdaLdapClass *t_connection_get_class_info (TConnection *tcnc, const gchar *classname);
+const GSList *t_connection_get_top_classes (TConnection *tcnc);
+
+gboolean t_connection_declare_table (TConnection *tcnc,
+ const gchar *table_name,
+ const gchar *base_dn,
+ const gchar *filter,
+ const gchar *attributes,
+ GdaLdapSearchScope scope,
+ GError **error);
+gboolean t_connection_undeclare_table (TConnection *tcnc,
+ const gchar *table_name,
+ GError **error);
+
+#endif
+
+G_END_DECLS
+
+#endif
diff --git a/tools/common/t-context.c b/tools/common/t-context.c
new file mode 100644
index 0000000..34873e8
--- /dev/null
+++ b/tools/common/t-context.c
@@ -0,0 +1,659 @@
+/*
+ * Copyright (C) 2014 Vivien Malerba <malerba gnome-db org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "t-context.h"
+#include "t-utils.h"
+#include "t-app.h"
+#include <glib/gi18n-lib.h>
+#include <sql-parser/gda-sql-parser.h>
+#include <glib/gstdio.h>
+#include <errno.h>
+
+/*
+ * Main static functions
+ */
+static void t_context_class_init (TContextClass *klass);
+static void t_context_init (TContext *self);
+static void t_context_dispose (GObject *object);
+static void t_context_set_property (GObject *object,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec);
+static void t_context_get_property (GObject *object,
+ guint param_id,
+ GValue *value,
+ GParamSpec *pspec);
+
+
+/* get a pointer to the parents to be able to call their destructor */
+static GObjectClass *parent_class = NULL;
+
+/* properties */
+enum
+{
+ PROP_0,
+ PROP_ID
+};
+
+struct _TContextPrivate {
+ gchar *id;
+ TConnection *current; /* ref held */
+
+ ToolOutputFormat output_format;
+ FILE *output_stream;
+ gboolean output_is_pipe;
+
+ GTimeVal last_time_used;
+ ToolCommandGroup *command_group;
+
+ gulong sigid;
+};
+
+GType
+t_context_get_type (void)
+{
+ static GType type = 0;
+
+ if (G_UNLIKELY (type == 0)) {
+ static GMutex registering;
+ static const GTypeInfo info = {
+ sizeof (TContextClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) t_context_class_init,
+ NULL,
+ NULL,
+ sizeof (TContext),
+ 0,
+ (GInstanceInitFunc) t_context_init,
+ 0
+ };
+
+
+ g_mutex_lock (®istering);
+ if (type == 0)
+ type = g_type_register_static (G_TYPE_OBJECT, "TContext", &info, 0);
+ g_mutex_unlock (®istering);
+ }
+ return type;
+}
+
+static void
+t_context_class_init (TContextClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ parent_class = g_type_class_peek_parent (klass);
+
+ klass->run = NULL;
+
+ /* Properties */
+ object_class->set_property = t_context_set_property;
+ object_class->get_property = t_context_get_property;
+
+ g_object_class_install_property (object_class, PROP_ID,
+ g_param_spec_string ("id", NULL, NULL, NULL,
+ (G_PARAM_READABLE | G_PARAM_WRITABLE)));
+
+ object_class->dispose = t_context_dispose;
+}
+
+static void
+t_context_init (TContext *self)
+{
+ self->priv = g_new0 (TContextPrivate, 1);
+ self->priv->output_format = BASE_TOOL_OUTPUT_FORMAT_DEFAULT;
+ self->priv->sigid = 0;
+
+ TContext *tcon;
+ tcon = t_app_get_term_console ();
+ if (tcon)
+ t_context_set_connection (self, tcon->priv->current);
+
+ self->priv->output_stream = NULL;
+ _t_app_add_context (self);
+}
+
+static void
+t_context_dispose (GObject *object)
+{
+ TContext *console = T_CONTEXT (object);
+
+ if (console->priv) {
+ _t_app_remove_context (console);
+ t_context_set_connection (console, NULL);
+
+ g_free (console->priv->id);
+
+ if (console->priv->output_stream) {
+ if (console->priv->output_is_pipe) {
+ pclose (console->priv->output_stream);
+#ifndef G_OS_WIN32
+ signal (SIGPIPE, SIG_DFL);
+#endif
+ }
+ else
+ fclose (console->priv->output_stream);
+ console->priv->output_stream = NULL;
+ console->priv->output_is_pipe = FALSE;
+ }
+ g_free (console->priv);
+ console->priv = NULL;
+ }
+
+ /* parent class */
+ parent_class->dispose (object);
+}
+
+static void
+t_context_set_property (GObject *object,
+ guint param_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ TContext *console;
+ console = T_CONTEXT (object);
+ if (console->priv) {
+ switch (param_id) {
+ case PROP_ID:
+ g_free (console->priv->id);
+ console->priv->id = NULL;
+ if (g_value_get_string (value))
+ console->priv->id = g_value_dup_string (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ break;
+ }
+ }
+}
+
+static void
+t_context_get_property (GObject *object,
+ guint param_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ TContext *console;
+ console = T_CONTEXT (object);
+ if (console->priv) {
+ switch (param_id) {
+ case PROP_ID:
+ g_value_set_string (value, console->priv->id);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+ break;
+ }
+ }
+}
+
+/*
+ * This function is the one in which @console is run, and it blocks in this function until it finishes
+ */
+static gpointer
+t_context_run_thread (TContext *console)
+{
+ TContextClass *klass;
+ klass = T_CONTEXT_CLASS (G_OBJECT_GET_CLASS (console));
+ g_assert (klass->run);
+ klass->run (console);
+
+ return NULL;
+}
+
+/**
+ * t_context_run:
+ * @console: a #TContext
+ *
+ * NB: the execution is done in a sub thread, and the caller thread has to call g_thread_join()
+ * on the returned thread.
+ *
+ * Returns: the #GThread in which the execution takes place
+ */
+GThread *
+t_context_run (TContext *console)
+{
+ g_return_val_if_fail (console, NULL);
+
+ TContextClass *klass;
+ klass = T_CONTEXT_CLASS (G_OBJECT_GET_CLASS (console));
+ if (!klass->run) {
+ g_warning ("TContext does not implement the run() virtual method!");
+ return NULL;
+ }
+
+ GThread *th;
+ gchar *name;
+ name = g_strdup_printf ("Console%p", console);
+ th = g_thread_new (name, (GThreadFunc) t_context_run_thread, console);
+ g_free (name);
+ return th;
+}
+
+static ToolCommandResult *
+t_context_execute_sql_command (TContext *console, const gchar *command,
+ GdaStatementModelUsage usage,
+ GError **error)
+{
+ ToolCommandResult *res = NULL;
+ GdaBatch *batch;
+ const GSList *stmt_list;
+ GdaStatement *stmt;
+ GdaSet *params;
+ GObject *obj;
+ const gchar *remain = NULL;
+ TConnection *tcnc;
+
+ g_assert (T_IS_CONTEXT (console));
+
+ tcnc = console->priv->current;
+ if (!tcnc) {
+ g_set_error (error, T_ERROR, T_NO_CONNECTION_ERROR,
+ "%s", _("No connection specified"));
+ return NULL;
+ }
+
+ batch = gda_sql_parser_parse_string_as_batch (t_connection_get_parser (tcnc), command, &remain,
error);
+ if (!batch)
+ return NULL;
+ if (remain) {
+ g_object_unref (batch);
+ return NULL;
+ }
+
+ stmt_list = gda_batch_get_statements (batch);
+ if (!stmt_list) {
+ g_object_unref (batch);
+ return NULL;
+ }
+
+ if (stmt_list->next) {
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
+ "%s", _("More than one SQL statement"));
+ g_object_unref (batch);
+ return NULL;
+ }
+
+ stmt = GDA_STATEMENT (stmt_list->data);
+ g_object_ref (stmt);
+ g_object_unref (batch);
+
+ if (!gda_statement_get_parameters (stmt, ¶ms, error)) {
+ g_object_unref (stmt);
+ return NULL;
+ }
+
+ /* fill parameters with some defined parameters */
+ if (params && params->holders) {
+ GSList *list;
+ for (list = params->holders; list; list = list->next) {
+ GdaHolder *h = GDA_HOLDER (list->data);
+ GValue *value;
+ value = t_app_get_parameter_value (gda_holder_get_id (h));
+ if (value) {
+ if ((G_VALUE_TYPE (value) == gda_holder_get_g_type (h)) ||
+ (G_VALUE_TYPE (value) == GDA_TYPE_NULL)) {
+ if (!gda_holder_take_value (h, value, error)) {
+ g_free (res);
+ res = NULL;
+ goto cleanup;
+ }
+ }
+ else {
+ gchar *str;
+ str = gda_value_stringify (value);
+ gda_value_free (value);
+ value = gda_value_new_from_string (str, gda_holder_get_g_type (h));
+ g_free (str);
+ if (! value) {
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
+ _("Could not interpret the '%s' parameter's
value"),
+ gda_holder_get_id (h));
+ g_free (res);
+ res = NULL;
+ goto cleanup;
+ }
+ else if (! gda_holder_take_value (h, value, error)) {
+ g_free (res);
+ res = NULL;
+ goto cleanup;
+ }
+ }
+ }
+ else {
+ if (! gda_holder_is_valid (h)) {
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
+ _("No internal parameter named '%s' required by query"),
+ gda_holder_get_id (h));
+ g_free (res);
+ res = NULL;
+ goto cleanup;
+ }
+ }
+ }
+ }
+
+ res = g_new0 (ToolCommandResult, 1);
+ res->was_in_transaction_before_exec =
+ gda_connection_get_transaction_status (t_connection_get_cnc (tcnc)) ? TRUE : FALSE;
+ res->cnc = g_object_ref (t_connection_get_cnc (tcnc));
+ obj = gda_connection_statement_execute (t_connection_get_cnc (tcnc), stmt, params, usage, NULL,
error);
+ if (!obj) {
+ g_free (res);
+ res = NULL;
+ }
+ else {
+ if (GDA_IS_DATA_MODEL (obj)) {
+ res->type = BASE_TOOL_COMMAND_RESULT_DATA_MODEL;
+ res->u.model = GDA_DATA_MODEL (obj);
+ }
+ else if (GDA_IS_SET (obj)) {
+ res->type = BASE_TOOL_COMMAND_RESULT_SET;
+ res->u.set = GDA_SET (obj);
+ }
+ else
+ g_assert_not_reached ();
+ }
+
+ cleanup:
+ g_object_unref (stmt);
+ if (params)
+ g_object_unref (params);
+
+ return res;
+}
+
+ToolCommandResult *
+t_context_command_execute (TContext *console, const gchar *command,
+ GdaStatementModelUsage usage, GError **error)
+{
+ TConnection *tcnc;
+
+ g_return_val_if_fail (T_IS_CONTEXT (console), NULL);
+ tcnc = console->priv->current;
+
+ if (!command || !(*command))
+ return NULL;
+
+ if ((*command == '\\') || (*command == '.'))
+ return base_tool_command_group_execute (console->priv->command_group, command + 1,
+ console, error);
+
+ else if (*command == '#') {
+ /* nothing to do */
+ ToolCommandResult *res;
+ res = g_new0 (ToolCommandResult, 1);
+ res->type = BASE_TOOL_COMMAND_RESULT_EMPTY;
+ return res;
+ }
+ else {
+ if (!tcnc) {
+ g_set_error (error, T_ERROR, T_NO_CONNECTION_ERROR,
+ "%s", _("No connection specified"));
+ return NULL;
+ }
+ if (!gda_connection_is_opened (t_connection_get_cnc (tcnc))) {
+ g_set_error (error, T_ERROR, T_CONNECTION_CLOSED_ERROR,
+ "%s", _("Connection closed"));
+ return NULL;
+ }
+
+ return t_context_execute_sql_command (console, command, usage, error);
+ }
+}
+
+/**
+ * t_context_get_id:
+ * @console: a #TContext object
+ *
+ * Returns: (transfer none): the console's ID
+ */
+const gchar *
+t_context_get_id (TContext *console)
+{
+ g_return_val_if_fail (T_IS_CONTEXT (console), NULL);
+ return console->priv->id;
+}
+
+/**
+ * t_context_set_command_group:
+ * @console: a #TContext object
+ * @group: (allow-none) (transfer none): a #ToolCommandGroup
+ *
+ * Defines @console's commands group
+ */
+void
+t_context_set_command_group (TContext *console, ToolCommandGroup *group)
+{
+ g_return_val_if_fail (T_IS_CONTEXT (console), NULL);
+ console->priv->command_group = group;
+}
+
+/**
+ * t_context_get_command_group:
+ * @console: a #TContext object
+ *
+ * Returns: (transfer none): the console's group of available commands
+ */
+ToolCommandGroup *
+t_context_get_command_group (TContext *console)
+{
+ g_return_val_if_fail (T_IS_CONTEXT (console), NULL);
+ return console->priv->command_group;
+}
+
+/**
+ * t_context_get_output_format:
+ * @console: a #TContext
+ *
+ * Returns: the output format for the context
+ */
+ToolOutputFormat
+t_context_get_output_format (TContext *console)
+{
+ g_return_val_if_fail (T_IS_CONTEXT (console), BASE_TOOL_OUTPUT_FORMAT_DEFAULT);
+ return console->priv->output_format;
+}
+
+/**
+ * t_context_get_output_format:
+ * @console: a #TContext
+ * @format: the format
+ *
+ * Defines the context's output format
+ */
+void
+t_context_set_output_format (TContext *console, ToolOutputFormat format)
+{
+ g_return_if_fail (T_IS_CONTEXT (console));
+
+ console->priv->output_format = format;
+}
+
+/**
+ * t_context_get_output_stream:
+ * @console: a #TContext
+ * @out_is_pipe: (allow-none): a place to store information about the stream being a pipe or not, or %NULL
+ *
+ * Returns: the current output stream, or %NULL if none defined (i.e. stdout)
+ */
+FILE *
+t_context_get_output_stream (TContext *console, gboolean *out_is_pipe)
+{
+ g_return_val_if_fail (T_IS_CONTEXT (console), NULL);
+ if (out_is_pipe)
+ *out_is_pipe = console->priv->output_is_pipe;
+ return console->priv->output_stream;
+}
+
+/**
+ * t_context_set_output_file:
+ * @console: a #TContext
+ * @file: (allow-none): a string representing the output string, or %NULL (i.e. stdout)
+ * @error: (allow-none): a place to store errors, or %NULL
+ *
+ * Note: the "| cmd" is an accepted notation to pipe the outpit stream to another program
+ *
+ * Sets @console's output stream
+ *
+ * Returns: %TRUE if no error occurred
+ */
+gboolean
+t_context_set_output_file (TContext *console, const gchar *file, GError **error)
+{
+ g_return_val_if_fail (T_IS_CONTEXT (console), FALSE);
+
+ if (console->priv->output_stream) {
+ if (console->priv->output_is_pipe) {
+ pclose (console->priv->output_stream);
+#ifndef G_OS_WIN32
+ signal (SIGPIPE, SIG_DFL);
+#endif
+ }
+ else
+ fclose (console->priv->output_stream);
+ console->priv->output_stream = NULL;
+ console->priv->output_is_pipe = FALSE;
+ }
+
+ if (file) {
+ gchar *copy = g_strdup (file);
+ g_strchug (copy);
+
+ if (*copy != '|') {
+ /* output to a file */
+ console->priv->output_stream = g_fopen (copy, "w");
+ if (!console->priv->output_stream) {
+ g_set_error (error, T_ERROR, T_INTERNAL_COMMAND_ERROR,
+ _("Can't open file '%s' for writing: %s\n"),
+ copy,
+ strerror (errno));
+ g_free (copy);
+ return FALSE;
+ }
+ console->priv->output_is_pipe = FALSE;
+ }
+ else {
+ /* output to a pipe */
+ if (t_utils_check_shell_argument (copy+1)) {
+ console->priv->output_stream = popen (copy+1, "w");
+ if (!console->priv->output_stream) {
+ g_set_error (error, T_ERROR, T_INTERNAL_COMMAND_ERROR,
+ _("Can't open pipe '%s': %s"),
+ copy,
+ strerror (errno));
+ g_free (copy);
+ return FALSE;
+ }
+ }
+ else {
+ g_set_error (error, T_ERROR, T_INTERNAL_COMMAND_ERROR,
+ _("Can't open pipe '%s': %s"),
+ copy + 1,
+ "program name must only contain alphanumeric characters");
+ g_free (copy);
+ return FALSE;
+ }
+#ifndef G_OS_WIN32
+ signal (SIGPIPE, SIG_IGN);
+#endif
+ console->priv->output_is_pipe = TRUE;
+ }
+ g_free (copy);
+ }
+
+ t_utils_term_compute_color_attribute ();
+ return TRUE;
+}
+
+/**
+ * t_context_get_connection:
+ * @console: a #TContext
+ *
+ * Returns: (transfer none): the connection currently used by @console
+ */
+TConnection *
+t_context_get_connection (TContext *console)
+{
+ g_return_val_if_fail (T_IS_CONTEXT (console), NULL);
+ return console->priv->current;
+}
+
+static void
+t_connection_status_changed_cb (TConnection *tcnc, GdaConnectionStatus status, TContext *console)
+{
+ if (status == GDA_CONNECTION_STATUS_CLOSED) {
+ gint index;
+ TConnection *ntcnc = NULL;
+ const GSList *tcnc_list;
+ tcnc_list = t_app_get_all_connections ();
+ index = g_slist_index ((GSList*) tcnc_list, tcnc);
+ if (index == 0)
+ ntcnc = g_slist_nth_data ((GSList*) tcnc_list, index + 1);
+ else
+ ntcnc = g_slist_nth_data ((GSList*) tcnc_list, index - 1);
+ t_context_set_connection (console, ntcnc);
+ }
+}
+
+/**
+ * t_context_set_connection:
+ * @console: a #TContext
+ * @tcnc: (allow-none): the #TConnection to use, or %NULL
+ *
+ * Defines the connection used by @context
+ */
+void
+t_context_set_connection (TContext *console, TConnection *tcnc)
+{
+ g_return_if_fail (T_IS_CONTEXT (console));
+ g_return_if_fail (!tcnc || T_IS_CONNECTION (tcnc));
+
+ if (console->priv->current == tcnc)
+ return;
+
+ if (console->priv->current) {
+ if (console->priv->sigid) {
+ g_signal_handler_disconnect (console->priv->current, console->priv->sigid);
+ console->priv->sigid = 0;
+ }
+
+ g_object_unref (console->priv->current);
+ console->priv->current = NULL;
+ }
+ if (tcnc) {
+ console->priv->current = g_object_ref (tcnc);
+ console->priv->sigid = g_signal_connect (tcnc, "status-changed",
+ G_CALLBACK (t_connection_status_changed_cb),
console);
+ }
+}
+
+/**
+ * t_context_get_last_time_used:
+ * @console: a #TContext
+ *
+ * Get a pointer to the #GTimeVal representing the last time @console was used
+ *
+ * Returns: (transfer none): a #GTimeVal pointer
+ */
+GTimeVal *
+t_context_get_last_time_used (TContext *console)
+{
+ g_return_val_if_fail (T_IS_CONTEXT (console), NULL);
+ return & (console->priv->last_time_used);
+}
diff --git a/tools/common/t-context.h b/tools/common/t-context.h
new file mode 100644
index 0000000..901d2e8
--- /dev/null
+++ b/tools/common/t-context.h
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2014 Vivien Malerba <malerba gnome-db org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __T_CONTEXT__
+#define __T_CONTEXT__
+
+#include <glib.h>
+#include "t-connection.h"
+#include "base/base-tool.h"
+#include "t-errors.h"
+
+/*
+ * Object representing a context using a connection (AKA a console)
+ */
+#define T_TYPE_CONTEXT (t_context_get_type())
+#define T_CONTEXT(obj) G_TYPE_CHECK_INSTANCE_CAST (obj, t_context_get_type(), TContext)
+#define T_CONTEXT_CLASS(klass) G_TYPE_CHECK_CLASS_CAST (klass, t_context_get_type (), TContextClass)
+#define T_IS_CONTEXT(obj) G_TYPE_CHECK_INSTANCE_TYPE (obj, t_context_get_type ())
+
+typedef struct _TContextClass TContextClass;
+typedef struct _TContextPrivate TContextPrivate;
+
+/* struct for the object's data */
+struct _TContext
+{
+ GObject object;
+ TContextPrivate *priv;
+};
+
+/* struct for the object's class */
+struct _TContextClass
+{
+ GObjectClass parent_class;
+ void (*run) (TContext *self);
+};
+
+GType t_context_get_type (void);
+
+GThread *t_context_run (TContext *console);
+
+ToolCommandResult *t_context_command_execute (TContext *console, const gchar *command,
+ GdaStatementModelUsage usage, GError **error);
+
+const gchar *t_context_get_id (TContext *console);
+void t_context_set_command_group (TContext *console, ToolCommandGroup *group);
+ToolCommandGroup *t_context_get_command_group (TContext *console);
+
+void t_context_set_output_format (TContext *console, ToolOutputFormat format);
+ToolOutputFormat t_context_get_output_format (TContext *console);
+
+gboolean t_context_set_output_file (TContext *console, const gchar *file, GError **error);
+FILE *t_context_get_output_stream (TContext *console, gboolean *out_is_pipe);
+
+void t_context_set_connection (TContext *console, TConnection *tcnc);
+TConnection *t_context_get_connection (TContext *console);
+
+GTimeVal *t_context_get_last_time_used (TContext *console);
+
+#endif
diff --git a/tools/cmdtool/tool-help.h b/tools/common/t-decl.h
similarity index 67%
rename from tools/cmdtool/tool-help.h
rename to tools/common/t-decl.h
index 71c36d9..c10368d 100644
--- a/tools/cmdtool/tool-help.h
+++ b/tools/common/t-decl.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2012 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2014 Vivien Malerba <malerba gnome-db org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -16,14 +16,13 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#ifndef __TOOL_HELP__
-#define __TOOL_HELP__
+#ifndef __T_DECL__
+#define __T_DECL__
-#include <stdio.h>
-#include <glib.h>
-#include "tool-command.h"
+typedef struct _TApp TApp;
+typedef struct _TContext TContext;
-gboolean tool_help_set_xml_file (const gchar *file);
-ToolCommandResult *tool_help_get_command_help (ToolCommandGroup *group, const gchar *command_name,
ToolOutputFormat format);
+#define T_DEFAULT_LDAP_ATTRIBUTES "cn"
+#define T_LAST_DATA_MODEL_NAME "_"
#endif
diff --git a/tools/cmdtool/tool-errors.c b/tools/common/t-errors.c
similarity index 80%
rename from tools/cmdtool/tool-errors.c
rename to tools/common/t-errors.c
index fc4fc1a..47e6f03 100644
--- a/tools/cmdtool/tool-errors.c
+++ b/tools/common/t-errors.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2012 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2014 Vivien Malerba <malerba gnome-db org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -16,15 +16,14 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#include "tool-errors.h"
-#include <glib/gi18n-lib.h>
+#include "t-errors.h"
/* module error */
GQuark
-tool_errors_quark (void)
+t_error_quark (void)
{
static GQuark quark;
if (!quark)
- quark = g_quark_from_static_string ("tool_errors");
+ quark = g_quark_from_static_string ("t_error");
return quark;
}
diff --git a/tools/browser/canvas/browser-canvas-priv.h b/tools/common/t-errors.h
similarity index 61%
copy from tools/browser/canvas/browser-canvas-priv.h
copy to tools/common/t-errors.h
index 41681e5..333936b 100644
--- a/tools/browser/canvas/browser-canvas-priv.h
+++ b/tools/common/t-errors.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2014 Vivien Malerba <malerba gnome-db org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -16,24 +16,27 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#ifndef __BROWSER_CANVAS_PRIV__
-#define __BROWSER_CANVAS_PRIV__
+#ifndef __T_ERRORS__
+#define __T_ERRORS__
-#include <goocanvas.h>
-#include "browser-canvas-decl.h"
+#include <glib.h>
-G_BEGIN_DECLS
-
-struct _BrowserCanvasPrivate
-{
- GooCanvas *goocanvas;
- GSList *items; /* BrowserCanvasItem objects, non ordered */
-
- gboolean canvas_moving;
-
- BrowserCanvasItem *current_selected_item;
-};
-
-G_END_DECLS
+/*
+ * error reporting
+ */
+extern GQuark t_error_quark (void);
+#define T_ERROR t_error_quark ()
+
+typedef enum {
+ T_NO_CONNECTION_ERROR,
+ T_CONNECTION_CLOSED_ERROR,
+ T_INTERNAL_COMMAND_ERROR,
+ T_COMMAND_ARGUMENTS_ERROR,
+ T_OBJECT_NOT_FOUND_ERROR,
+ T_PROVIDER_NOT_FOUND_ERROR,
+ T_DSN_NOT_FOUND_ERROR,
+ T_STORED_DATA_ERROR,
+ T_PURGE_ERROR
+} TError;
#endif
diff --git a/tools/browser/common/favorites-actions.c b/tools/common/t-favorites-actions.c
similarity index 65%
rename from tools/browser/common/favorites-actions.c
rename to tools/common/t-favorites-actions.c
index 2a3b701..dea8c4b 100644
--- a/tools/browser/common/favorites-actions.c
+++ b/tools/common/t-favorites-actions.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2012 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2012 - 2014 Vivien Malerba <malerba gnome-db org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -18,49 +18,49 @@
#include <string.h>
#include <glib/gi18n-lib.h>
-#include "favorites-actions.h"
-#include "../browser-connection.h"
+#include "t-favorites-actions.h"
+#include "t-connection.h"
#include <libgda/gda-sql-builder.h>
#include <sql-parser/gda-sql-parser.h>
static gint
-actions_sort_func (ToolsFavoriteAction *act1, ToolsFavoriteAction *act2)
+actions_sort_func (TFavoritesAction *act1, TFavoritesAction *act2)
{
return act2->nb_bound - act1->nb_bound;
}
/**
- * gda_tools_favorites_get_actions
- * @bfav: a #ToolsFavorites
- * @bcnc: a #BrowserConnection
+ * t_favorites_actions_get
+ * @bfav: a #TFavorites
+ * @tcnc: a #TConnection
* @set: a #GdaSet
*
- * Get a list of #ToolsFavoriteAction which can be executed with the data in @set.
+ * Get a list of #TFavoritesAction which can be executed with the data in @set.
*
- * Returns: a new list of #ToolsFavoriteAction, free list with gda_tools_favorites_free_actions()
+ * Returns: a new list of #TFavoritesAction, free list with t_favorites_action_frees()
*/
GSList *
-gda_tools_favorites_get_actions (ToolsFavorites *bfav, BrowserConnection *bcnc, GdaSet *set)
+t_favorites_actions_get (TFavorites *bfav, TConnection *tcnc, GdaSet *set)
{
GSList *fav_list, *list, *retlist = NULL;
- g_return_val_if_fail (GDA_TOOLS_IS_FAVORITES (bfav), NULL);
- g_return_val_if_fail (BROWSER_IS_CONNECTION (bcnc), NULL);
+ g_return_val_if_fail (T_IS_FAVORITES (bfav), NULL);
+ g_return_val_if_fail (T_IS_CONNECTION (tcnc), NULL);
g_return_val_if_fail (!set || GDA_IS_SET (set), NULL);
- fav_list = gda_tools_favorites_list (bfav, 0, GDA_TOOLS_FAVORITES_ACTIONS, -1, NULL);
+ fav_list = t_favorites_list (bfav, 0, T_FAVORITES_ACTIONS, -1, NULL);
if (! fav_list)
return NULL;
for (list = fav_list; list; list = list->next) {
- ToolsFavoritesAttributes *fa = (ToolsFavoritesAttributes*) list->data;
- ToolsFavoritesAttributes qfa;
+ TFavoritesAttributes *fa = (TFavoritesAttributes*) list->data;
+ TFavoritesAttributes qfa;
if (! g_str_has_prefix (fa->contents, "QUERY")) {
g_warning ("Malformed action contents '%s', please report error to "
"http://bugzilla.gnome.org/ for the \"libgda\" product",
fa->contents);
continue;
}
- if (gda_tools_favorites_get (bfav, atoi (fa->contents + 5), &qfa, NULL)) {
+ if (t_favorites_get (bfav, atoi (fa->contents + 5), &qfa, NULL)) {
GdaSet *params;
GSList *plist;
GdaBatch *batch;
@@ -70,11 +70,11 @@ gda_tools_favorites_get_actions (ToolsFavorites *bfav, BrowserConnection *bcnc,
const GSList *stmt_list;
gint nb_bound = 0;
- parser = browser_connection_create_parser (bcnc);
+ parser = t_connection_create_parser (tcnc);
batch = gda_sql_parser_parse_string_as_batch (parser, qfa.contents, &remain, NULL);
g_object_unref (parser);
if (!batch) {
- gda_tools_favorites_reset_attributes (&qfa);
+ t_favorites_reset_attributes (&qfa);
continue;
}
stmt_list = gda_batch_get_statements (batch);
@@ -88,16 +88,16 @@ gda_tools_favorites_get_actions (ToolsFavorites *bfav, BrowserConnection *bcnc,
}
g_object_unref (batch);
if (!stmt || plist) {
- gda_tools_favorites_reset_attributes (&qfa);
+ t_favorites_reset_attributes (&qfa);
continue;
}
if (! gda_statement_get_parameters (stmt, ¶ms, NULL) || !params) {
g_object_unref (stmt);
- gda_tools_favorites_reset_attributes (&qfa);
+ t_favorites_reset_attributes (&qfa);
continue;
}
- browser_connection_define_ui_plugins_for_stmt (bcnc, stmt, params);
+ t_connection_define_ui_plugins_for_stmt (tcnc, stmt, params);
for (plist = params->holders; plist; plist = plist->next) {
/* try to find holder in @set */
@@ -112,8 +112,8 @@ gda_tools_favorites_get_actions (ToolsFavorites *bfav, BrowserConnection *bcnc,
if (nb_bound > 0) {
/* at least 1 holder was found=> keep the action */
- ToolsFavoriteAction *act;
- act = g_new0 (ToolsFavoriteAction, 1);
+ TFavoritesAction *act;
+ act = g_new0 (TFavoritesAction, 1);
retlist = g_slist_insert_sorted (retlist, act,
(GCompareFunc) actions_sort_func);
act->params = g_object_ref (params);
@@ -129,22 +129,22 @@ gda_tools_favorites_get_actions (ToolsFavorites *bfav, BrowserConnection *bcnc,
g_object_unref (stmt);
g_object_unref (params);
- gda_tools_favorites_reset_attributes (&qfa);
+ t_favorites_reset_attributes (&qfa);
}
}
- gda_tools_favorites_free_list (fav_list);
+ t_favorites_free_list (fav_list);
return retlist;
}
/**
- * gda_tools_favorites_free_action
- * @action: (allow-none): a #ToolsFavoriteAction, or %NULL
+ * t_favorites_action_free
+ * @action: (allow-none): a #TFavoritesAction, or %NULL
*
* Frees @action
*/
void
-gda_tools_favorites_free_action (ToolsFavoriteAction *action)
+t_favorites_action_free (TFavoritesAction *action)
{
if (! action)
return;
@@ -157,19 +157,19 @@ gda_tools_favorites_free_action (ToolsFavoriteAction *action)
}
/**
- * gda_tools_favorites_free_actions_list
- * @actions_list: (allow-none): a list of #ToolsFavoriteAction, or %NULL
+ * t_favorites_actions_list_free
+ * @actions_list: (allow-none): a list of #TFavoritesAction, or %NULL
*
- * Free a list of #ToolsFavoriteAction (frees the list and each #ToolsFavoriteAction)
+ * Free a list of #TFavoritesAction (frees the list and each #TFavoritesAction)
*/
void
-gda_tools_favorites_free_actions_list (GSList *actions_list)
+t_favorites_actions_list_free (GSList *actions_list)
{
GSList *list;
if (!actions_list)
return;
for (list = actions_list; list; list = list->next)
- gda_tools_favorites_free_action ((ToolsFavoriteAction*) list->data);
+ t_favorites_action_free ((TFavoritesAction*) list->data);
g_slist_free (actions_list);
}
diff --git a/tools/browser/common/favorites-actions.h b/tools/common/t-favorites-actions.h
similarity index 69%
rename from tools/browser/common/favorites-actions.h
rename to tools/common/t-favorites-actions.h
index 282d71f..6d5a85b 100644
--- a/tools/browser/common/favorites-actions.h
+++ b/tools/common/t-favorites-actions.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 - 2012 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2009 - 2014 Vivien Malerba <malerba gnome-db org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -17,12 +17,12 @@
*/
-#ifndef __FAVORITES_H_
-#define __FAVORITES_H_
+#ifndef __FAVORITES_ACTIONS_H_
+#define __FAVORITES_ACTIONS_H_
#include <libgda/libgda.h>
-#include "../decl.h"
-#include "../../tools-favorites.h"
+#include "t-connection.h"
+#include "t-favorites.h"
G_BEGIN_DECLS
@@ -33,11 +33,11 @@ typedef struct {
GdaSet *params;
gint nb_bound; /* number of GdaHolders in @params which are bound
* to another GdaHolder */
-} ToolsFavoriteAction;
+} TFavoritesAction;
-GSList *gda_tools_favorites_get_actions (ToolsFavorites *bfav, BrowserConnection *bcnc, GdaSet
*set);
-void gda_tools_favorites_free_action (ToolsFavoriteAction *action);
-void gda_tools_favorites_free_actions_list (GSList *actions_list);
+GSList *t_favorites_actions_get (TFavorites *bfav, TConnection *tcnc, GdaSet *set);
+void t_favorites_action_free (TFavoritesAction *action);
+void t_favorites_actions_list_free (GSList *actions_list);
G_END_DECLS
diff --git a/tools/tools-favorites.c b/tools/common/t-favorites.c
similarity index 82%
rename from tools/tools-favorites.c
rename to tools/common/t-favorites.c
index bb17d23..f92e185 100644
--- a/tools/tools-favorites.c
+++ b/tools/common/t-favorites.c
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2009 - 2010 Murray Cumming <murrayc murrayc com>
- * Copyright (C) 2009 - 2012 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2009 - 2014 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2010 David King <davidk openismus com>
*
* This program is free software; you can redistribute it and/or
@@ -20,12 +20,12 @@
#include <string.h>
#include <glib/gi18n-lib.h>
-#include "tools-favorites.h"
-#include "tool-utils.h"
+#include "t-favorites.h"
+#include "t-errors.h"
#include <libgda/gda-sql-builder.h>
#include <sql-parser/gda-sql-parser.h>
-struct _ToolsFavoritesPrivate {
+struct _TFavoritesPrivate {
GdaMetaStore *store;
GdaConnection *store_cnc;
};
@@ -34,9 +34,9 @@ struct _ToolsFavoritesPrivate {
/*
* Main static functions
*/
-static void gda_tools_favorites_class_init (ToolsFavoritesClass *klass);
-static void gda_tools_favorites_init (ToolsFavorites *bfav);
-static void gda_tools_favorites_dispose (GObject *object);
+static void t_favorites_class_init (TFavoritesClass *klass);
+static void t_favorites_init (TFavorites *bfav);
+static void t_favorites_dispose (GObject *object);
/* get a pointer to the parents to be able to call their destructor */
static GObjectClass *parent_class = NULL;
@@ -47,74 +47,74 @@ enum {
LAST_SIGNAL
};
-gint gda_tools_favorites_signals [LAST_SIGNAL] = { 0 };
+gint t_favorites_signals [LAST_SIGNAL] = { 0 };
GType
-gda_tools_favorites_get_type (void)
+t_favorites_get_type (void)
{
static GType type = 0;
if (G_UNLIKELY (type == 0)) {
static GMutex registering;
static const GTypeInfo info = {
- sizeof (ToolsFavoritesClass),
+ sizeof (TFavoritesClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
- (GClassInitFunc) gda_tools_favorites_class_init,
+ (GClassInitFunc) t_favorites_class_init,
NULL,
NULL,
- sizeof (ToolsFavorites),
+ sizeof (TFavorites),
0,
- (GInstanceInitFunc) gda_tools_favorites_init,
+ (GInstanceInitFunc) t_favorites_init,
0
};
g_mutex_lock (®istering);
if (type == 0)
- type = g_type_register_static (G_TYPE_OBJECT, "ToolsFavorites", &info, 0);
+ type = g_type_register_static (G_TYPE_OBJECT, "TFavorites", &info, 0);
g_mutex_unlock (®istering);
}
return type;
}
static void
-gda_tools_favorites_class_init (ToolsFavoritesClass *klass)
+t_favorites_class_init (TFavoritesClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
- gda_tools_favorites_signals [FAV_CHANGED] =
+ t_favorites_signals [FAV_CHANGED] =
g_signal_new ("favorites-changed",
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_FIRST | G_SIGNAL_DETAILED,
- G_STRUCT_OFFSET (ToolsFavoritesClass, favorites_changed),
+ G_STRUCT_OFFSET (TFavoritesClass, favorites_changed),
NULL, NULL,
g_cclosure_marshal_VOID__VOID, G_TYPE_NONE,
0);
klass->favorites_changed = NULL;
- object_class->dispose = gda_tools_favorites_dispose;
+ object_class->dispose = t_favorites_dispose;
}
static void
-gda_tools_favorites_init (ToolsFavorites *bfav)
+t_favorites_init (TFavorites *bfav)
{
- bfav->priv = g_new0 (ToolsFavoritesPrivate, 1);
+ bfav->priv = g_new0 (TFavoritesPrivate, 1);
bfav->priv->store = NULL;
bfav->priv->store_cnc = NULL;
}
static void
-gda_tools_favorites_dispose (GObject *object)
+t_favorites_dispose (GObject *object)
{
- ToolsFavorites *bfav;
+ TFavorites *bfav;
g_return_if_fail (object != NULL);
- g_return_if_fail (GDA_TOOLS_IS_FAVORITES (object));
+ g_return_if_fail (T_IS_FAVORITES (object));
- bfav = GDA_TOOLS_FAVORITES (object);
+ bfav = T_FAVORITES (object);
if (bfav->priv) {
if (bfav->priv->store)
g_object_unref (bfav->priv->store);
@@ -130,20 +130,20 @@ gda_tools_favorites_dispose (GObject *object)
}
/**
- * gda_tools_favorites_new
+ * t_favorites_new
*
- * Creates a new #ToolsFavorites object
+ * Creates a new #TFavorites object
*
* Returns: the new object
*/
-ToolsFavorites*
-gda_tools_favorites_new (GdaMetaStore *store)
+TFavorites*
+t_favorites_new (GdaMetaStore *store)
{
- ToolsFavorites *bfav;
+ TFavorites *bfav;
g_return_val_if_fail (GDA_IS_META_STORE (store), NULL);
- bfav = GDA_TOOLS_FAVORITES (g_object_new (GDA_TOOLS_TYPE_FAVORITES, NULL));
+ bfav = T_FAVORITES (g_object_new (T_TYPE_FAVORITES, NULL));
bfav->priv->store = g_object_ref (store);
return bfav;
@@ -173,14 +173,14 @@ gda_tools_favorites_new (GdaMetaStore *store)
"</table>"
static gboolean
-meta_store_addons_init (ToolsFavorites *bfav, GError **error)
+meta_store_addons_init (TFavorites *bfav, GError **error)
{
GError *lerror = NULL;
if (bfav->priv->store_cnc)
return TRUE;
if (!gda_meta_store_schema_add_custom_object (bfav->priv->store, FAVORITES_TABLE_DESC, &lerror)) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_STORED_DATA_ERROR,
+ g_set_error (error, T_ERROR, T_STORED_DATA_ERROR,
"%s", _("Can't initialize dictionary to store favorites"));
g_warning ("Can't initialize dictionary to store favorites :%s",
lerror && lerror->message ? lerror->message : "No detail");
@@ -189,7 +189,7 @@ meta_store_addons_init (ToolsFavorites *bfav, GError **error)
return FALSE;
}
if (!gda_meta_store_schema_add_custom_object (bfav->priv->store, FAVORDER_TABLE_DESC, &lerror)) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_STORED_DATA_ERROR,
+ g_set_error (error, T_ERROR, T_STORED_DATA_ERROR,
"%s", _("Can't initialize dictionary to store favorites"));
g_warning ("Can't initialize dictionary to store favorites :%s",
lerror && lerror->message ? lerror->message : "No detail");
@@ -203,28 +203,28 @@ meta_store_addons_init (ToolsFavorites *bfav, GError **error)
}
/**
- * gda_tools_favorites_type_to_string:
- * @type: a #ToolsFavoritesType
+ * t_favorites_type_to_string:
+ * @type: a #TFavoritesType
*
* Returns: a string representing @type
*/
const gchar *
-gda_tools_favorites_type_to_string (ToolsFavoritesType type)
+t_favorites_type_to_string (TFavoritesType type)
{
switch (type) {
- case GDA_TOOLS_FAVORITES_TABLES:
+ case T_FAVORITES_TABLES:
return "TABLE";
- case GDA_TOOLS_FAVORITES_DIAGRAMS:
+ case T_FAVORITES_DIAGRAMS:
return "DIAGRAM";
- case GDA_TOOLS_FAVORITES_QUERIES:
+ case T_FAVORITES_QUERIES:
return "QUERY";
- case GDA_TOOLS_FAVORITES_DATA_MANAGERS:
+ case T_FAVORITES_DATA_MANAGERS:
return "DATAMAN";
- case GDA_TOOLS_FAVORITES_ACTIONS:
+ case T_FAVORITES_ACTIONS:
return "ACTION";
- case GDA_TOOLS_FAVORITES_LDAP_DN:
+ case T_FAVORITES_LDAP_DN:
return "LDAP_DN";
- case GDA_TOOLS_FAVORITES_LDAP_CLASS:
+ case T_FAVORITES_LDAP_CLASS:
return "LDAP_CLASS";
default:
g_warning ("Unknown type of favorite");
@@ -233,26 +233,26 @@ gda_tools_favorites_type_to_string (ToolsFavoritesType type)
return "";
}
-static ToolsFavoritesType
+static TFavoritesType
favorite_string_to_type (const gchar *str)
{
if (*str == 'T')
- return GDA_TOOLS_FAVORITES_TABLES;
+ return T_FAVORITES_TABLES;
else if (*str == 'D') {
if (str[1] == 'I')
- return GDA_TOOLS_FAVORITES_DIAGRAMS;
+ return T_FAVORITES_DIAGRAMS;
else
- return GDA_TOOLS_FAVORITES_DATA_MANAGERS;
+ return T_FAVORITES_DATA_MANAGERS;
}
else if (*str == 'Q')
- return GDA_TOOLS_FAVORITES_QUERIES;
+ return T_FAVORITES_QUERIES;
else if (*str == 'A')
- return GDA_TOOLS_FAVORITES_ACTIONS;
+ return T_FAVORITES_ACTIONS;
else if (*str == 'L') {
if (strlen (str) == 7)
- return GDA_TOOLS_FAVORITES_LDAP_DN;
+ return T_FAVORITES_LDAP_DN;
else
- return GDA_TOOLS_FAVORITES_LDAP_CLASS;
+ return T_FAVORITES_LDAP_CLASS;
}
else
g_warning ("Unknown type '%s' of favorite", str);
@@ -260,7 +260,7 @@ favorite_string_to_type (const gchar *str)
}
static gint
-find_favorite_position (ToolsFavorites *bfav, gint fav_id, gint order_key)
+find_favorite_position (TFavorites *bfav, gint fav_id, gint order_key)
{
GdaSqlBuilder *b;
GdaStatement *stmt;
@@ -312,8 +312,8 @@ find_favorite_position (ToolsFavorites *bfav, gint fav_id, gint order_key)
}
static gint
-find_favorite_by_name (ToolsFavorites *bfav, guint session_id, const gchar *name, ToolsFavoritesType type,
- ToolsFavoritesAttributes *out_existing_fav, GError **error)
+find_favorite_by_name (TFavorites *bfav, guint session_id, const gchar *name, TFavoritesType type,
+ TFavoritesAttributes *out_existing_fav, GError **error)
{
GdaSqlBuilder *b;
GdaStatement *stmt;
@@ -322,7 +322,7 @@ find_favorite_by_name (ToolsFavorites *bfav, guint session_id, const gchar *name
gint favid = -1;
if (out_existing_fav)
- memset (out_existing_fav, 0, sizeof (ToolsFavoritesAttributes));
+ memset (out_existing_fav, 0, sizeof (TFavoritesAttributes));
g_return_val_if_fail (name, -1);
b = gda_sql_builder_new (GDA_SQL_STATEMENT_SELECT);
@@ -355,7 +355,7 @@ find_favorite_by_name (ToolsFavorites *bfav, guint session_id, const gchar *name
return -1;
params = gda_set_new_inline (3,
"session", G_TYPE_INT, session_id,
- "type", G_TYPE_STRING, gda_tools_favorites_type_to_string (type),
+ "type", G_TYPE_STRING, t_favorites_type_to_string (type),
"name", G_TYPE_STRING, name);
model = gda_connection_statement_execute_select (bfav->priv->store_cnc, stmt, params, error);
g_object_unref (stmt);
@@ -393,12 +393,12 @@ find_favorite_by_name (ToolsFavorites *bfav, guint session_id, const gchar *name
*
* Returns: the ID or -1 if not found (and sets ERROR).
*
- * if @out_existing_fav is not %NULL, then its attributes are set, use gda_tools_favorites_reset_attributes()
+ * if @out_existing_fav is not %NULL, then its attributes are set, use t_favorites_reset_attributes()
* to free.
*/
static gint
-find_favorite (ToolsFavorites *bfav, guint session_id, gint id, const gchar *contents,
- ToolsFavoritesAttributes *out_existing_fav, GError **error)
+find_favorite (TFavorites *bfav, guint session_id, gint id, const gchar *contents,
+ TFavoritesAttributes *out_existing_fav, GError **error)
{
GdaSqlBuilder *b;
GdaStatement *stmt;
@@ -407,7 +407,7 @@ find_favorite (ToolsFavorites *bfav, guint session_id, gint id, const gchar *con
gint favid = -1;
if (out_existing_fav)
- memset (out_existing_fav, 0, sizeof (ToolsFavoritesAttributes));
+ memset (out_existing_fav, 0, sizeof (TFavoritesAttributes));
g_return_val_if_fail ((id >= 0) || contents, -1);
b = gda_sql_builder_new (GDA_SQL_STATEMENT_SELECT);
@@ -488,7 +488,7 @@ find_favorite (ToolsFavorites *bfav, guint session_id, gint id, const gchar *con
* Reorders the favorites for @order_key, making sure @id is at position @new_pos
*/
static gboolean
-favorites_reorder (ToolsFavorites *bfav, gint order_key, gint id, gint new_pos, GError **error)
+favorites_reorder (TFavorites *bfav, gint order_key, gint id, gint new_pos, GError **error)
{
GdaSqlBuilder *b;
GdaStatement *stmt;
@@ -583,10 +583,10 @@ favorites_reorder (ToolsFavorites *bfav, gint order_key, gint id, gint new_pos,
}
/**
- * gda_tools_favorites_add
- * @bfav: a #ToolsFavorites object
+ * t_favorites_add
+ * @bfav: a #TFavorites object
* @session_id: session ID (0)
- * @fav: a pointer to a #ToolsFavoritesAttributes structure
+ * @fav: a pointer to a #TFavoritesAttributes structure
* @order_key: ordering key or -1 for none
* @pos: position (ignored if @order_key < 0)
* @error: a place to store errors, or %NULL
@@ -605,17 +605,17 @@ favorites_reorder (ToolsFavorites *bfav, gint order_key, gint id, gint new_pos,
* if @order_key is negative, then no ordering is done and @pos is ignored.
*/
gboolean
-gda_tools_favorites_add (ToolsFavorites *bfav, guint session_id,
- ToolsFavoritesAttributes *fav,
+t_favorites_add (TFavorites *bfav, guint session_id,
+ TFavoritesAttributes *fav,
gint order_key, gint pos,
GError **error)
{
GdaConnection *store_cnc;
GdaSet *params = NULL;
gint favid = -1;
- ToolsFavoritesAttributes efav; /* existing favorite */
+ TFavoritesAttributes efav; /* existing favorite */
- g_return_val_if_fail (GDA_TOOLS_IS_FAVORITES (bfav), FALSE);
+ g_return_val_if_fail (T_IS_FAVORITES (bfav), FALSE);
g_return_val_if_fail (fav, FALSE);
g_return_val_if_fail (fav->contents, FALSE);
@@ -624,13 +624,13 @@ gda_tools_favorites_add (ToolsFavorites *bfav, guint session_id,
store_cnc = bfav->priv->store_cnc;
if (! gda_lockable_trylock (GDA_LOCKABLE (store_cnc))) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_STORED_DATA_ERROR,
+ g_set_error (error, T_ERROR, T_STORED_DATA_ERROR,
"%s", _("Can't initialize transaction to access favorites"));
return FALSE;
}
/* begin a transaction */
if (! gda_connection_begin_transaction (store_cnc, NULL, GDA_TRANSACTION_ISOLATION_UNKNOWN, NULL)) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_STORED_DATA_ERROR,
+ g_set_error (error, T_ERROR, T_STORED_DATA_ERROR,
"%s", _("Can't initialize transaction to access favorites"));
gda_lockable_unlock (GDA_LOCKABLE (store_cnc));
return FALSE;
@@ -648,7 +648,7 @@ gda_tools_favorites_add (ToolsFavorites *bfav, guint session_id,
params = gda_set_new_inline (8,
"session", G_TYPE_INT, session_id,
"id", G_TYPE_INT, fav->id,
- "type", G_TYPE_STRING, gda_tools_favorites_type_to_string (rtype),
+ "type", G_TYPE_STRING, t_favorites_type_to_string (rtype),
"name", G_TYPE_STRING, fav->name ? fav->name : efav.name,
"contents", G_TYPE_STRING, fav->contents,
"rank", G_TYPE_INT, pos,
@@ -739,7 +739,7 @@ gda_tools_favorites_add (ToolsFavorites *bfav, guint session_id,
g_object_unref (stmt);
fav->id = favid;
}
- gda_tools_favorites_reset_attributes (&efav);
+ t_favorites_reset_attributes (&efav);
if (order_key >= 0) {
GdaSqlBuilder *builder;
@@ -803,7 +803,7 @@ gda_tools_favorites_add (ToolsFavorites *bfav, guint session_id,
}
if (! gda_connection_commit_transaction (store_cnc, NULL, NULL)) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_STORED_DATA_ERROR,
+ g_set_error (error, T_ERROR, T_STORED_DATA_ERROR,
"%s", _("Can't commit transaction to access favorites"));
goto err;
}
@@ -811,8 +811,8 @@ gda_tools_favorites_add (ToolsFavorites *bfav, guint session_id,
if (params)
g_object_unref (params);
gda_lockable_unlock (GDA_LOCKABLE (store_cnc));
- g_signal_emit (bfav, gda_tools_favorites_signals [FAV_CHANGED],
- g_quark_from_string (gda_tools_favorites_type_to_string (rtype)));
+ g_signal_emit (bfav, t_favorites_signals [FAV_CHANGED],
+ g_quark_from_string (t_favorites_type_to_string (rtype)));
return TRUE;
err:
@@ -824,44 +824,44 @@ gda_tools_favorites_add (ToolsFavorites *bfav, guint session_id,
}
/**
- * gda_tools_favorites_free_list
- * @fav_list: a list of #ToolsFavoritesAttributes
+ * t_favorites_free_list
+ * @fav_list: a list of #TFavoritesAttributes
*
- * Frees all the #ToolsFavoritesAttributes of the @fav_list list, and frees the list
+ * Frees all the #TFavoritesAttributes of the @fav_list list, and frees the list
* itself.
*/
void
-gda_tools_favorites_free_list (GSList *fav_list)
+t_favorites_free_list (GSList *fav_list)
{
GSList *list;
if (!fav_list)
return;
for (list = fav_list; list; list = list->next) {
- ToolsFavoritesAttributes *fav = (ToolsFavoritesAttributes*) list->data;
- gda_tools_favorites_reset_attributes (fav);
+ TFavoritesAttributes *fav = (TFavoritesAttributes*) list->data;
+ t_favorites_reset_attributes (fav);
g_free (fav);
}
g_slist_free (fav_list);
}
/**
- * gda_tools_favorites_reset_attributes
- * @fav: a pointer to a #ToolsFavoritesAttributes
+ * t_favorites_reset_attributes
+ * @fav: a pointer to a #TFavoritesAttributes
*
* Resets @fav with empty attributes; it does not free @fav.
*/
void
-gda_tools_favorites_reset_attributes (ToolsFavoritesAttributes *fav)
+t_favorites_reset_attributes (TFavoritesAttributes *fav)
{
g_free (fav->name);
g_free (fav->descr);
g_free (fav->contents);
- memset (fav, 0, sizeof (ToolsFavoritesAttributes));
+ memset (fav, 0, sizeof (TFavoritesAttributes));
}
/**
- * gda_tools_favorites_list
- * @bfav: a #ToolsFavorites
+ * t_favorites_list
+ * @bfav: a #TFavorites
* @session_id: 0 for now
* @type: filter the type of attributes to be listed
* @order_key: a key to order the listed favorites, such as #ORDER_KEY_SCHEMA
@@ -869,11 +869,11 @@ gda_tools_favorites_reset_attributes (ToolsFavoritesAttributes *fav)
*
* Extract some favorites.
*
- * Returns: a new list of #ToolsFavoritesAttributes pointers. The list has to
- * be freed using gda_tools_favorites_free_list()
+ * Returns: a new list of #TFavoritesAttributes pointers. The list has to
+ * be freed using t_favorites_free_list()
*/
GSList *
-gda_tools_favorites_list (ToolsFavorites *bfav, guint session_id, ToolsFavoritesType type,
+t_favorites_list (TFavorites *bfav, guint session_id, TFavoritesType type,
gint order_key, GError **error)
{
GdaSqlBuilder *b;
@@ -885,10 +885,10 @@ gda_tools_favorites_list (ToolsFavorites *bfav, guint session_id, ToolsFavorites
guint and_cond_ids [3];
int and_cond_size = 0;
- guint or_cond_ids [GDA_TOOLS_FAVORITES_NB_TYPES];
+ guint or_cond_ids [T_FAVORITES_NB_TYPES];
int or_cond_size = 0;
- g_return_val_if_fail (GDA_TOOLS_IS_FAVORITES (bfav), NULL);
+ g_return_val_if_fail (T_IS_FAVORITES (bfav), NULL);
g_return_val_if_fail ((type != 0) || (order_key >= 0), NULL);
if (! meta_store_addons_init (bfav, error))
@@ -931,10 +931,10 @@ gda_tools_favorites_list (ToolsFavorites *bfav, guint session_id, ToolsFavorites
gint i;
gint flag;
- for (i = 0, flag = 1; i < GDA_TOOLS_FAVORITES_NB_TYPES; i++, flag <<= 1) {
+ for (i = 0, flag = 1; i < T_FAVORITES_NB_TYPES; i++, flag <<= 1) {
if (type & flag) {
gchar *str;
- str = g_strdup_printf ("'%s'", gda_tools_favorites_type_to_string (flag));
+ str = g_strdup_printf ("'%s'", t_favorites_type_to_string (flag));
or_cond_ids [or_cond_size] = gda_sql_builder_add_cond (b, GDA_SQL_OPERATOR_TYPE_EQ,
gda_sql_builder_add_id (b,
"fav.type"),
gda_sql_builder_add_id (b,
str),
@@ -998,8 +998,8 @@ gda_tools_favorites_list (ToolsFavorites *bfav, guint session_id, ToolsFavorites
if (type)
id = gda_data_model_get_value_at (model, 4, i, error);
if (id) {
- ToolsFavoritesAttributes *fav;
- fav = g_new0 (ToolsFavoritesAttributes, 1);
+ TFavoritesAttributes *fav;
+ fav = g_new0 (TFavoritesAttributes, 1);
fav->id = g_value_get_int (id);
fav->type = favorite_string_to_type (g_value_get_string (type));
if (G_VALUE_TYPE (descr) == G_TYPE_STRING)
@@ -1010,7 +1010,7 @@ gda_tools_favorites_list (ToolsFavorites *bfav, guint session_id, ToolsFavorites
fav_list = g_slist_prepend (fav_list, fav);
}
else {
- gda_tools_favorites_free_list (fav_list);
+ t_favorites_free_list (fav_list);
fav_list = NULL;
goto out;
}
@@ -1027,10 +1027,10 @@ gda_tools_favorites_list (ToolsFavorites *bfav, guint session_id, ToolsFavorites
/**
- * gda_tools_favorites_delete
- * @bfav: a #ToolsFavorites
+ * t_favorites_delete
+ * @bfav: a #TFavorites
* @session_id: 0 for now
- * @fav: a pointer to a #ToolsFavoritesAttributes definning which favorite to delete
+ * @fav: a pointer to a #TFavoritesAttributes definning which favorite to delete
* @error: a place to store errors, or %NULL
*
* Delete a favorite
@@ -1038,33 +1038,33 @@ gda_tools_favorites_list (ToolsFavorites *bfav, guint session_id, ToolsFavorites
* Returns: %TRUE if no error occurred.
*/
gboolean
-gda_tools_favorites_delete (ToolsFavorites *bfav, guint session_id,
- ToolsFavoritesAttributes *fav, GError **error)
+t_favorites_delete (TFavorites *bfav, guint session_id,
+ TFavoritesAttributes *fav, GError **error)
{
GdaSqlBuilder *b;
GdaSet *params = NULL;
GdaStatement *stmt;
gboolean retval = FALSE;
gint favid = -1;
- ToolsFavoritesAttributes efav;
+ TFavoritesAttributes efav;
- g_return_val_if_fail (GDA_TOOLS_IS_FAVORITES (bfav), FALSE);
+ g_return_val_if_fail (T_IS_FAVORITES (bfav), FALSE);
g_return_val_if_fail (fav, FALSE);
g_return_val_if_fail ((fav->id >= 0) || fav->contents || fav->name , FALSE);
- memset (&efav, 0, sizeof (ToolsFavoritesAttributes));
+ memset (&efav, 0, sizeof (TFavoritesAttributes));
if (! meta_store_addons_init (bfav, error))
return FALSE;
if (! gda_lockable_trylock (GDA_LOCKABLE (bfav->priv->store_cnc))) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_STORED_DATA_ERROR,
+ g_set_error (error, T_ERROR, T_STORED_DATA_ERROR,
"%s", _("Can't initialize transaction to access favorites"));
return FALSE;
}
/* begin a transaction */
if (! gda_connection_begin_transaction (bfav->priv->store_cnc, NULL,
GDA_TRANSACTION_ISOLATION_UNKNOWN, NULL)) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_STORED_DATA_ERROR,
+ g_set_error (error, T_ERROR, T_STORED_DATA_ERROR,
"%s", _("Can't initialize transaction to access favorites"));
gda_lockable_unlock (GDA_LOCKABLE (bfav->priv->store_cnc));
return FALSE;
@@ -1087,7 +1087,7 @@ gda_tools_favorites_delete (ToolsFavorites *bfav, guint session_id,
}
}
if (favid < 0) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_INTERNAL_COMMAND_ERROR,
+ g_set_error (error, T_ERROR, T_INTERNAL_COMMAND_ERROR,
"%s", _("Could not find favorite"));
goto out;
}
@@ -1132,7 +1132,7 @@ gda_tools_favorites_delete (ToolsFavorites *bfav, guint session_id,
g_object_unref (stmt);
if (! gda_connection_commit_transaction (bfav->priv->store_cnc, NULL, NULL)) {
- g_set_error (error, GDA_TOOLS_ERROR, GDA_TOOLS_STORED_DATA_ERROR,
+ g_set_error (error, T_ERROR, T_STORED_DATA_ERROR,
"%s", _("Can't commit transaction to access favorites"));
goto out;
}
@@ -1144,9 +1144,9 @@ gda_tools_favorites_delete (ToolsFavorites *bfav, guint session_id,
gda_lockable_unlock (GDA_LOCKABLE (bfav->priv->store_cnc));
if (retval)
- g_signal_emit (bfav, gda_tools_favorites_signals [FAV_CHANGED],
- g_quark_from_string (gda_tools_favorites_type_to_string (efav.type)));
- gda_tools_favorites_reset_attributes (&efav);
+ g_signal_emit (bfav, t_favorites_signals [FAV_CHANGED],
+ g_quark_from_string (t_favorites_type_to_string (efav.type)));
+ t_favorites_reset_attributes (&efav);
if (params)
g_object_unref (G_OBJECT (params));
@@ -1154,23 +1154,23 @@ gda_tools_favorites_delete (ToolsFavorites *bfav, guint session_id,
}
/**
- * gda_tools_favorites_find
- * @bfav: a #ToolsFavorites
+ * t_favorites_find
+ * @bfav: a #TFavorites
* @session_id: 0 for now
* @contents: the favorite's contents
- * @out_fav: (allow-none): a #ToolsFavoritesAttributes to be filled with the favorite's attributes, or %NULL
+ * @out_fav: (allow-none): a #TFavoritesAttributes to be filled with the favorite's attributes, or %NULL
* @error: a place to store errors, or %NULL
*
* Get all the information about a favorite from its id: fills the @out_fav
- * pointed structure. Use gda_tools_favorites_reset_attributes() to reset @out_fav's contents.
+ * pointed structure. Use t_favorites_reset_attributes() to reset @out_fav's contents.
*
* Retuns: the requested's favorite ID, or -1 if not found
*/
gint
-gda_tools_favorites_find (ToolsFavorites *bfav, guint session_id, const gchar *contents,
- ToolsFavoritesAttributes *out_fav, GError **error)
+t_favorites_find (TFavorites *bfav, guint session_id, const gchar *contents,
+ TFavoritesAttributes *out_fav, GError **error)
{
- g_return_val_if_fail (GDA_TOOLS_IS_FAVORITES (bfav), -1);
+ g_return_val_if_fail (T_IS_FAVORITES (bfav), -1);
g_return_val_if_fail (contents, -1);
if (! meta_store_addons_init (bfav, error))
@@ -1179,24 +1179,24 @@ gda_tools_favorites_find (ToolsFavorites *bfav, guint session_id, const gchar *c
}
/**
- * gda_tools_favorites_find_by_name:
- * @bfav: a #ToolsFavorites
+ * t_favorites_find_by_name:
+ * @bfav: a #TFavorites
* @session_id: 0 for now
* @type: the favorite's type
* @name: the favorite's name
- * @out_fav: (allow-none): a #ToolsFavoritesAttributes to be filled with the favorite's attributes, or %NULL
+ * @out_fav: (allow-none): a #TFavoritesAttributes to be filled with the favorite's attributes, or %NULL
* @error: a place to store errors, or %NULL
*
* Get all the information about a favorite from its id: fills the @out_fav
- * pointed structure. Use gda_tools_favorites_reset_attributes() to reset @out_fav's contents.
+ * pointed structure. Use t_favorites_reset_attributes() to reset @out_fav's contents.
*
* Retuns: the requested's favorite ID, or -1 if not found
*/
gint
-gda_tools_favorites_find_by_name (ToolsFavorites *bfav, guint session_id, ToolsFavoritesType type, const
gchar *name,
- ToolsFavoritesAttributes *out_fav, GError **error)
+t_favorites_find_by_name (TFavorites *bfav, guint session_id, TFavoritesType type, const gchar *name,
+ TFavoritesAttributes *out_fav, GError **error)
{
- g_return_val_if_fail (GDA_TOOLS_IS_FAVORITES (bfav), -1);
+ g_return_val_if_fail (T_IS_FAVORITES (bfav), -1);
g_return_val_if_fail (name, -1);
if (! meta_store_addons_init (bfav, error))
@@ -1207,20 +1207,20 @@ gda_tools_favorites_find_by_name (ToolsFavorites *bfav, guint session_id, ToolsF
/**
- * gda_tools_favorites_get
- * @bfav: a #ToolsFavorites
+ * t_favorites_get
+ * @bfav: a #TFavorites
* @fav_id: the favorite's ID
- * @out_fav: a #ToolsFavoritesAttributes to be filled with the favorite's attributes
+ * @out_fav: a #TFavoritesAttributes to be filled with the favorite's attributes
* @error: a place to store errors, or %NULL
*
* Get all the information about a favorite from its id: fills the @out_fav
- * pointed structure. Use gda_tools_favorites_reset_attributes() to reset @out_fav's contents.
+ * pointed structure. Use t_favorites_reset_attributes() to reset @out_fav's contents.
*
* Retuns: %TRUE if no error occurred.
*/
gboolean
-gda_tools_favorites_get (ToolsFavorites *bfav, gint fav_id,
- ToolsFavoritesAttributes *out_fav, GError **error)
+t_favorites_get (TFavorites *bfav, gint fav_id,
+ TFavoritesAttributes *out_fav, GError **error)
{
GdaSqlBuilder *b;
GdaStatement *stmt;
@@ -1228,11 +1228,11 @@ gda_tools_favorites_get (ToolsFavorites *bfav, gint fav_id,
GdaDataModel *model;
gboolean retval = FALSE;
- g_return_val_if_fail (GDA_TOOLS_IS_FAVORITES (bfav), FALSE);
+ g_return_val_if_fail (T_IS_FAVORITES (bfav), FALSE);
g_return_val_if_fail (out_fav, FALSE);
g_return_val_if_fail (fav_id >= 0, FALSE);
- memset (out_fav, 0, sizeof (ToolsFavoritesAttributes));
+ memset (out_fav, 0, sizeof (TFavoritesAttributes));
b = gda_sql_builder_new (GDA_SQL_STATEMENT_SELECT);
gda_sql_builder_add_field_value_id (b,
diff --git a/tools/common/t-favorites.h b/tools/common/t-favorites.h
new file mode 100644
index 0000000..ef6aaf0
--- /dev/null
+++ b/tools/common/t-favorites.h
@@ -0,0 +1,130 @@
+/*
+ * Copyright (C) 2012 Vivien Malerba <malerba gnome-db org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+
+#ifndef __T_FAVORITES_H_
+#define __T_FAVORITES_H_
+
+#include <libgda/libgda.h>
+
+G_BEGIN_DECLS
+
+#define T_TYPE_FAVORITES (t_favorites_get_type())
+#define T_FAVORITES(obj) G_TYPE_CHECK_INSTANCE_CAST (obj, t_favorites_get_type(), TFavorites)
+#define T_FAVORITES_CLASS(klass) G_TYPE_CHECK_CLASS_CAST (klass, t_favorites_get_type (), TFavoritesClass)
+#define T_IS_FAVORITES(obj) G_TYPE_CHECK_INSTANCE_TYPE (obj, t_favorites_get_type ())
+
+typedef struct _TFavorites TFavorites;
+typedef struct _TFavoritesClass TFavoritesClass;
+typedef struct _TFavoritesPrivate TFavoritesPrivate;
+
+/**
+ * TFavoritesType:
+ * @T_FAVORITES_TABLES: a database's table favorite
+ * @T_FAVORITES_DIAGRAMS: a diagram favorite
+ * @T_FAVORITES_QUERIES:
+ * @T_FAVORITES_DATA_MANAGERS:
+ * @T_FAVORITES_ACTIONS:
+ *
+ * Enum to identify favorite's types.
+ */
+typedef enum {
+ T_FAVORITES_TABLES = 1 << 0,
+ T_FAVORITES_DIAGRAMS = 1 << 1,
+ T_FAVORITES_QUERIES = 1 << 2,
+ T_FAVORITES_DATA_MANAGERS = 1 << 3,
+ T_FAVORITES_ACTIONS = 1 << 4,
+ T_FAVORITES_LDAP_DN = 1 << 5,
+ T_FAVORITES_LDAP_CLASS = 1 << 6
+} TFavoritesType;
+#define T_FAVORITES_NB_TYPES 7
+
+#define ORDER_KEY_SCHEMA 1
+#define ORDER_KEY_QUERIES 2
+#define ORDER_KEY_DATA_MANAGERS 3
+#define ORDER_KEY_LDAP 4
+
+/**
+ * TFavoritesAttributes:
+ * @id: the favorite ID, or <0 if not saved
+ * @type: the favorite's type
+ * @name: the favorite's name
+ * @descr: the favorite's description
+ * @contents: the favorite's contents, depending on the favorite type
+ */
+typedef struct {
+ gint id;
+ TFavoritesType type;
+ gchar *name;
+ gchar *descr;
+ gchar *contents;
+} TFavoritesAttributes;
+
+/* struct for the object's data */
+struct _TFavorites
+{
+ GObject object;
+ TFavoritesPrivate *priv;
+};
+
+/* struct for the object's class */
+struct _TFavoritesClass
+{
+ GObjectClass parent_class;
+
+ void (*favorites_changed) (TFavorites *bfav);
+};
+
+/**
+ * SECTION:tools-favorites
+ * @short_description: Favorites management
+ * @title: TFavorites
+ * @stability: Stable
+ * @see_also:
+ *
+ * Each connection uses a single #TFavorites object to manage its favorites,
+ * see gda_tools_connection_get_favorites().
+ */
+
+GType t_favorites_get_type (void) G_GNUC_CONST;
+
+TFavorites *t_favorites_new (GdaMetaStore *store);
+const gchar *t_favorites_type_to_string (TFavoritesType type);
+gboolean t_favorites_add (TFavorites *bfav, guint session_id,
+ TFavoritesAttributes *fav,
+ gint order_key, gint pos,
+ GError **error);
+GSList *t_favorites_list (TFavorites *bfav, guint session_id,
+ TFavoritesType type, gint order_key, GError **error);
+
+gboolean t_favorites_delete (TFavorites *bfav, guint session_id,
+ TFavoritesAttributes *fav, GError **error);
+void t_favorites_free_list (GSList *fav_list);
+void t_favorites_reset_attributes (TFavoritesAttributes *fav);
+
+gint t_favorites_find (TFavorites *bfav, guint session_id, const gchar *contents,
+ TFavoritesAttributes *out_fav, GError **error);
+gint t_favorites_find_by_name (TFavorites *bfav, guint session_id,
+ TFavoritesType type, const gchar *name,
+ TFavoritesAttributes *out_fav, GError **error);
+gboolean t_favorites_get (TFavorites *bfav, gint fav_id,
+ TFavoritesAttributes *out_fav, GError **error);
+
+G_END_DECLS
+
+#endif
diff --git a/tools/common/t-term-context.c b/tools/common/t-term-context.c
new file mode 100644
index 0000000..77c1c20
--- /dev/null
+++ b/tools/common/t-term-context.c
@@ -0,0 +1,612 @@
+/*
+ * Copyright (C) 2014 Vivien Malerba <malerba gnome-db org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "t-term-context.h"
+#include "t-utils.h"
+#include "t-app.h"
+#include <glib/gi18n-lib.h>
+#include <sql-parser/gda-sql-parser.h>
+#include <glib/gstdio.h>
+#include <errno.h>
+#include <thread-wrapper/gda-connect.h>
+
+/*
+ * Main static functions
+ */
+static void t_term_context_class_init (TTermContextClass *klass);
+static void t_term_context_init (TTermContext *self);
+static void t_term_context_dispose (GObject *object);
+static void t_term_context_run (TContext *self);
+
+/* get a pointer to the parents to be able to call their destructor */
+static GObjectClass *parent_class = NULL;
+
+struct _TTermContextPrivate {
+ FILE *input_stream;
+ GString *partial_command;
+ gboolean interactive;
+
+ GMainLoop *main_loop; /* used when t_context_run() has been called (no ref is held here, only on the
stack) */
+ gulong exit_sig_id;
+};
+
+GType
+t_term_context_get_type (void)
+{
+ static GType type = 0;
+
+ if (G_UNLIKELY (type == 0)) {
+ static GMutex registering;
+ static const GTypeInfo info = {
+ sizeof (TTermContextClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) t_term_context_class_init,
+ NULL,
+ NULL,
+ sizeof (TTermContext),
+ 0,
+ (GInstanceInitFunc) t_term_context_init,
+ 0
+ };
+
+
+ g_mutex_lock (®istering);
+ if (type == 0)
+ type = g_type_register_static (T_TYPE_CONTEXT, "TTermContext", &info, 0);
+ g_mutex_unlock (®istering);
+ }
+ return type;
+}
+
+static void
+t_term_context_class_init (TTermContextClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ parent_class = g_type_class_peek_parent (klass);
+
+ T_CONTEXT_CLASS (klass)->run = t_term_context_run;
+ object_class->dispose = t_term_context_dispose;
+}
+
+static void
+t_term_context_init (TTermContext *self)
+{
+ self->priv = g_new0 (TTermContextPrivate, 1);
+ self->priv->interactive = FALSE;
+ self->priv->exit_sig_id = 0;
+}
+
+static void
+t_term_context_dispose (GObject *object)
+{
+ TTermContext *console = T_TERM_CONTEXT (object);
+
+ if (console->priv) {
+ if (console->priv->exit_sig_id > 0)
+ gda_signal_handler_disconnect (t_app_get (), console->priv->exit_sig_id);
+ t_term_context_set_input_stream (console, NULL);
+ if (console->priv->main_loop)
+ g_main_loop_quit (console->priv->main_loop);
+ g_free (console->priv);
+ console->priv = NULL;
+ }
+
+ /* parent class */
+ parent_class->dispose (object);
+}
+
+
+/* TERM console functions */
+static const char *prompt_func (void);
+static void setup_sigint_handler (void);
+static gboolean treat_line_func (const gchar *cmde, gboolean *out_exec_command_ok);
+static char **completion_func (const char *text, const gchar *line, int start, int end, gpointer data);
+static void compute_prompt (TTermContext *console, GString *string, gboolean in_command,
+ gboolean for_readline, ToolOutputFormat format);
+
+
+/**
+ * t_term_context_new:
+ *
+ * Returns: (transfer none): a new #TTermContext
+ */
+TTermContext *
+t_term_context_new (const gchar *id)
+{
+ TApp *main_data;
+ main_data = t_app_get ();
+
+ TTermContext *console;
+ console = g_object_new (T_TYPE_TERM_CONTEXT, "id", id, NULL);
+
+ t_context_set_command_group (T_CONTEXT (console), main_data->term_commands);
+
+ return console;
+}
+
+/**
+ * t_term_context_set_interactive:
+ * @console: a #TTermContext
+ * @interactive:
+ *
+ *
+ */
+void
+t_term_context_set_interactive (TTermContext *term_console, gboolean interactive)
+{
+ g_return_if_fail (T_IS_TERM_CONTEXT (term_console));
+ term_console->priv->interactive = interactive;
+}
+
+/*
+ * SIGINT handling
+ */
+#ifndef G_OS_WIN32
+struct sigaction old_sigint_handler;
+static void sigint_handler (int sig_num);
+typedef enum {
+ SIGINT_HANDLER_DISABLED = 0,
+ SIGINT_HANDLER_PARTIAL_COMMAND,
+} SigintHandlerCode;
+static SigintHandlerCode sigint_handler_status = SIGINT_HANDLER_DISABLED;
+
+static void
+sigint_handler (int sig_num)
+{
+ TTermContext *term_console;
+ term_console = T_TERM_CONTEXT (t_app_get_term_console ());
+ if (sigint_handler_status == SIGINT_HANDLER_PARTIAL_COMMAND) {
+ if (term_console->priv->partial_command) {
+ g_string_free (term_console->priv->partial_command, TRUE);
+ term_console->priv->partial_command = NULL;
+ /* disable SIGINT handling */
+ sigint_handler_status = SIGINT_HANDLER_DISABLED;
+ }
+ /* show a new prompt */
+ gchar *tmp;
+ tmp = t_utils_compute_prompt (T_CONTEXT (term_console), FALSE, FALSE,
+ BASE_TOOL_OUTPUT_FORMAT_DEFAULT |
+ (t_context_get_output_format (T_CONTEXT (term_console)) &
+ BASE_TOOL_OUTPUT_FORMAT_COLOR_TERM));
+ g_print ("\n%s", tmp);
+ g_free (tmp);
+ tmp = t_utils_compute_prompt (T_CONTEXT (term_console), FALSE, TRUE,
+ BASE_TOOL_OUTPUT_FORMAT_DEFAULT |
+ (t_context_get_output_format (T_CONTEXT (term_console)) &
+ BASE_TOOL_OUTPUT_FORMAT_COLOR_TERM));
+ g_free (tmp);
+ fflush (NULL);
+ }
+ else {
+ g_print ("\n");
+ exit (EXIT_SUCCESS);
+ }
+
+ if (old_sigint_handler.sa_handler)
+ old_sigint_handler.sa_handler (sig_num);
+}
+#endif /* G_OS_WIN32 */
+
+static void
+setup_sigint_handler (void)
+{
+#ifndef G_OS_WIN32
+ struct sigaction sac;
+ memset (&sac, 0, sizeof (sac));
+ sigemptyset (&sac.sa_mask);
+ sac.sa_handler = sigint_handler;
+ sac.sa_flags = SA_RESTART;
+ sigaction (SIGINT, &sac, &old_sigint_handler);
+#endif
+}
+
+
+static void
+display_result (TApp *main_data, ToolCommandResult *res)
+{
+ switch (res->type) {
+ case BASE_TOOL_COMMAND_RESULT_TXT_STDOUT:
+ g_print ("%s", res->u.txt->str);
+ if (res->u.txt->str [strlen (res->u.txt->str) - 1] != '\n')
+ g_print ("\n");
+ fflush (NULL);
+ break;
+ case BASE_TOOL_COMMAND_RESULT_EMPTY:
+ break;
+ case BASE_TOOL_COMMAND_RESULT_MULTIPLE: {
+ GSList *list;
+ for (list = res->u.multiple_results; list; list = list->next)
+ display_result (main_data, (ToolCommandResult *) list->data);
+ break;
+ }
+ case BASE_TOOL_COMMAND_RESULT_EXIT:
+ break;
+ default: {
+ gchar *str;
+ FILE *ostream;
+ ToolOutputFormat oformat;
+ ostream = t_context_get_output_stream (t_app_get_term_console (), NULL);
+ oformat = t_context_get_output_format (t_app_get_term_console ());
+ str = base_tool_output_result_to_string (res, oformat, ostream, t_app_get_options ());
+ base_tool_output_output_string (ostream, str);
+ g_free (str);
+ }
+ }
+}
+
+typedef struct {
+ gboolean single_line; /* set to TRUE to force considering the line as complete */
+ gboolean exec_command_ok;
+} TermLineData;
+
+/*
+ * Returns: %TRUE if exit has been requested
+ */
+static gboolean
+term_treat_line (TTermContext *term_console, const gchar *cmde, TermLineData *ldata)
+{
+ TApp *main_data = t_app_get ();
+ g_assert (main_data);
+
+ ldata->exec_command_ok = TRUE;
+
+ FILE *ostream;
+ ostream = t_context_get_output_stream (T_CONTEXT (term_console), NULL);
+
+ if (!cmde) {
+ base_tool_input_save_history (NULL, NULL);
+ if (!ostream)
+ g_print ("\n");
+ if (term_console->priv->main_loop)
+ g_main_loop_quit (term_console->priv->main_loop);
+ return TRUE;
+ }
+
+ gchar *loc_cmde = NULL;
+ loc_cmde = g_strdup (cmde);
+ g_strchug (loc_cmde);
+ if (*loc_cmde) {
+ if (*loc_cmde == '#') {
+ g_free (loc_cmde);
+ return FALSE;
+ }
+
+ base_tool_input_add_to_history (loc_cmde);
+ if (!term_console->priv->partial_command) {
+#ifndef G_OS_WIN32
+ /* enable SIGINT handling */
+ sigint_handler_status = SIGINT_HANDLER_PARTIAL_COMMAND;
+#endif
+ term_console->priv->partial_command = g_string_new (loc_cmde);
+ }
+ else {
+ g_string_append_c (term_console->priv->partial_command, '\n');
+ g_string_append (term_console->priv->partial_command, loc_cmde);
+ }
+ if (ldata->single_line || t_utils_command_is_complete
(term_console->priv->partial_command->str)) {
+ /* execute command */
+ ToolCommandResult *res;
+ FILE *to_stream;
+ GError *error = NULL;
+
+ if ((*term_console->priv->partial_command->str != '\\') &&
+ (*term_console->priv->partial_command->str != '.')) {
+ TConnection *tcnc;
+ tcnc = t_context_get_connection (T_CONTEXT (term_console));
+ if (tcnc)
+ t_connection_set_query_buffer (tcnc,
+
term_console->priv->partial_command->str);
+ }
+
+ if (ostream)
+ to_stream = ostream;
+ else
+ to_stream = stdout;
+ res = t_context_command_execute (T_CONTEXT (term_console),
+ term_console->priv->partial_command->str,
+ GDA_STATEMENT_MODEL_RANDOM_ACCESS, &error);
+
+ if (!res) {
+ if (!error ||
+ (error->domain != GDA_SQL_PARSER_ERROR) ||
+ (error->code != GDA_SQL_PARSER_EMPTY_SQL_ERROR)) {
+ ToolOutputFormat oformat;
+ oformat = t_context_get_output_format (T_CONTEXT (term_console));
+ g_fprintf (to_stream, "%sERROR:%s ",
+ base_tool_output_color_s (BASE_TOOL_COLOR_RED, oformat),
+ base_tool_output_color_s (BASE_TOOL_COLOR_RESET, oformat));
+ g_fprintf (to_stream,
+ "%s\n",
+ error && error->message ? error->message : _("No detail"));
+ ldata->exec_command_ok = FALSE;
+ }
+ if (error) {
+ g_error_free (error);
+ error = NULL;
+ }
+ }
+ else {
+ display_result (main_data, res);
+ if (res->type == BASE_TOOL_COMMAND_RESULT_EXIT) {
+ base_tool_command_result_free (res);
+ t_app_request_quit ();
+ if (term_console->priv->main_loop)
+ g_main_loop_quit (term_console->priv->main_loop);
+ g_free (loc_cmde);
+ return TRUE;
+ }
+ base_tool_command_result_free (res);
+ }
+ g_string_free (term_console->priv->partial_command, TRUE);
+ term_console->priv->partial_command = NULL;
+
+#ifndef G_OS_WIN32
+ /* disable SIGINT handling */
+ sigint_handler_status = SIGINT_HANDLER_DISABLED;
+#endif
+ }
+ }
+
+ g_free (loc_cmde);
+ return FALSE;
+}
+
+static const char *
+prompt_func (void)
+{
+ /* compute a new prompt */
+ ToolOutputFormat oformat;
+ oformat = t_context_get_output_format (t_app_get_term_console ());
+
+ static GString *prompt = NULL;
+ if (!prompt)
+ prompt = g_string_new ("");
+
+ TTermContext *term_console;
+ term_console = T_TERM_CONTEXT (t_app_get_term_console ());
+
+ compute_prompt (NULL, prompt, term_console->priv->partial_command == NULL ? FALSE : TRUE, TRUE,
+ BASE_TOOL_OUTPUT_FORMAT_DEFAULT |
+ (oformat & BASE_TOOL_OUTPUT_FORMAT_COLOR_TERM));
+ return (char*) prompt->str;
+}
+
+/* @cmde is stolen here */
+static gboolean
+treat_line_func (const gchar *cmde, gboolean *out_exec_command_ok)
+{
+ gboolean res;
+ TermLineData ldata;
+ ldata.single_line = FALSE;
+ res = term_treat_line (T_TERM_CONTEXT (t_app_get_term_console ()), cmde, &ldata);
+ if (out_exec_command_ok)
+ *out_exec_command_ok = ldata.exec_command_ok;
+ return res;
+}
+
+/**
+ * clears and modifies @string to hold a prompt.
+ */
+static void
+compute_prompt (TTermContext *console, GString *string, gboolean in_command, gboolean for_readline,
ToolOutputFormat format)
+{
+ g_string_set_size (string, 0);
+ if (!console)
+ console = T_TERM_CONTEXT (t_app_get_term_console ());
+
+ gchar *tmp;
+ tmp = t_utils_compute_prompt (T_CONTEXT (console), in_command, for_readline, format);
+ g_string_prepend (string, tmp);
+ g_free (tmp);
+}
+
+static char **
+completion_func (G_GNUC_UNUSED const char *text, const gchar *line, int start, int end, gpointer data)
+{
+ TConnection *tcnc;
+ char **array;
+ gchar **gda_compl;
+ gint i, nb_compl;
+
+ tcnc = t_context_get_connection (t_app_get_term_console ());
+ if (!tcnc)
+ return NULL;
+ gda_compl = gda_completion_list_get (t_connection_get_cnc (tcnc), line, start, end);
+ if (!gda_compl)
+ return NULL;
+
+ for (nb_compl = 0; gda_compl[nb_compl]; nb_compl++);
+
+ array = malloc (sizeof (char*) * (nb_compl + 1));
+ for (i = 0; i < nb_compl; i++) {
+ char *str;
+ gchar *gstr;
+ gint l;
+
+ gstr = gda_compl[i];
+ l = strlen (gstr) + 1;
+ str = malloc (sizeof (char) * l);
+ memcpy (str, gstr, l);
+ array[i] = str;
+ }
+ array[i] = NULL;
+ g_strfreev (gda_compl);
+ return array;
+}
+
+/**
+ * t_term_context_set_input_file:
+ *
+ * Change the input file, set to %NULL to be back on stdin
+ */
+gboolean
+t_term_context_set_input_file (TTermContext *term_console, const gchar *file, GError **error)
+{
+ g_return_val_if_fail (T_IS_TERM_CONTEXT (term_console), FALSE);
+ if (term_console->priv->input_stream) {
+ fclose (term_console->priv->input_stream);
+ term_console->priv->input_stream = NULL;
+ }
+
+ if (file) {
+ if (*file == '~') {
+ gchar *tmp;
+ tmp = g_strdup_printf ("%s%s", g_get_home_dir (), file+1);
+ term_console->priv->input_stream = g_fopen (tmp, "r");
+ g_free (tmp);
+ }
+ else
+ term_console->priv->input_stream = g_fopen (file, "r");
+ if (!term_console->priv->input_stream) {
+ g_set_error (error, T_ERROR, T_INTERNAL_COMMAND_ERROR,
+ _("Can't open file '%s' for reading: %s\n"),
+ file,
+ strerror (errno));
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+}
+
+/**
+ * t_term_context_set_input_stream:
+ *
+ * Defines the input stream
+ */
+void
+t_term_context_set_input_stream (TTermContext *term_console, FILE *stream)
+{
+ g_return_if_fail (T_IS_TERM_CONTEXT (term_console));
+ if (term_console->priv->input_stream) {
+ if (term_console->priv->input_stream == stream)
+ return;
+ fclose (term_console->priv->input_stream);
+ term_console->priv->input_stream = NULL;
+ }
+ if (stream)
+ term_console->priv->input_stream = stream;
+}
+
+/**
+ * t_term_context_get_input_stream:
+ *
+ * Returns: the input stream, or %NULL
+ */
+FILE *
+t_term_context_get_input_stream (TTermContext *term_console)
+{
+ g_return_val_if_fail (T_IS_TERM_CONTEXT (term_console), NULL);
+ return term_console->priv->input_stream;
+}
+
+
+/**
+ * t_term_context_treat_single_line:
+ */
+void
+t_term_context_treat_single_line (TTermContext *term_console, const gchar *cmde)
+{
+ g_return_if_fail (T_IS_TERM_CONTEXT (term_console));
+ g_return_if_fail (cmde && *cmde);
+
+ TermLineData ld;
+ ld.single_line = TRUE;
+ ld.exec_command_ok = FALSE;
+
+ term_treat_line (term_console, cmde, &ld);
+}
+
+static void
+quit_requested_cb (TApp *app, TContext *self)
+{
+ g_print ("TERM quit_requested_cb ()\n");
+ g_main_loop_quit (T_TERM_CONTEXT (self)->priv->main_loop);
+}
+
+static void
+t_term_context_run (TContext *self)
+{
+ FILE *istream;
+ TTermContext *term_console = T_TERM_CONTEXT (self);
+ gboolean interactive;
+ interactive = term_console->priv->interactive;
+ istream = term_console->priv->input_stream;
+ if (istream) {
+ gchar *cmde;
+ for (cmde = base_tool_input_from_stream (istream);
+ cmde;
+ cmde = base_tool_input_from_stream (istream)) {
+ TermLineData ld;
+ ld.single_line = FALSE;
+ ld.exec_command_ok = FALSE;
+
+ gboolean exit_req = FALSE;
+ if (term_treat_line (term_console, cmde, &ld)) {
+ exit_req = TRUE;
+ interactive = FALSE;
+ }
+ g_free (cmde);
+ if (! ld.exec_command_ok)
+ exit_req = TRUE;
+ if (exit_req)
+ break;
+ }
+ t_term_context_set_input_stream (term_console, NULL);
+ interactive = FALSE; /* can't have this if the input stream has been closed! */
+ }
+ else
+ interactive = TRUE;
+
+ if (interactive) {
+ setup_sigint_handler ();
+
+ GMainContext *context;
+ context = g_main_context_new ();
+ g_main_context_acquire (context);
+
+ base_tool_input_init (context, (ToolInputTreatLineFunc) treat_line_func, prompt_func, NULL);
+ base_tool_input_set_completion_func (t_context_get_command_group (T_CONTEXT (self)),
+ completion_func, t_app_get (), ".\\");
+
+ term_console->priv->exit_sig_id = gda_signal_connect (t_app_get (), "quit-requested",
+ G_CALLBACK (quit_requested_cb), self,
+ NULL, 0, context);
+
+ GMainLoop *main_loop;
+ main_loop = g_main_loop_new (context, TRUE);
+ term_console->priv->main_loop = main_loop;
+ g_main_loop_run (main_loop);
+ g_print ("term console's main loop stopped, th=%p\n", g_thread_self());
+ term_console->priv->main_loop = NULL;
+ g_main_loop_unref (main_loop);
+ g_main_context_unref (context);
+
+ base_tool_input_end ();
+ }
+
+ fflush (NULL);
+
+ if (term_console->priv->exit_sig_id > 0) {
+ gda_signal_handler_disconnect (t_app_get (), term_console->priv->exit_sig_id);
+ term_console->priv->exit_sig_id = 0;
+ }
+
+ t_app_remove_feature (T_APP_TERM_CONSOLE);
+}
diff --git a/tools/common/t-term-context.h b/tools/common/t-term-context.h
new file mode 100644
index 0000000..adac83a
--- /dev/null
+++ b/tools/common/t-term-context.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2014 Vivien Malerba <malerba gnome-db org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __T_TERM_CONTEXT__
+#define __T_TERM_CONTEXT__
+
+#include <glib.h>
+#include "t-context.h"
+
+/*
+ * Object representing a context using a connection (AKA a console)
+ */
+#define T_TYPE_TERM_CONTEXT (t_term_context_get_type())
+#define T_TERM_CONTEXT(obj) G_TYPE_CHECK_INSTANCE_CAST (obj, t_term_context_get_type(),
TTermContext)
+#define T_TERM_CONTEXT_CLASS(klass) G_TYPE_CHECK_CLASS_CAST (klass, t_term_context_get_type (),
TTermContextClass)
+#define T_IS_TERM_CONTEXT(obj) G_TYPE_CHECK_INSTANCE_TYPE (obj, t_term_context_get_type ())
+
+typedef struct _TTermContextClass TTermContextClass;
+typedef struct _TTermContextPrivate TTermContextPrivate;
+
+/* struct for the object's data */
+typedef struct
+{
+ TContext object;
+ TTermContextPrivate *priv;
+} TTermContext;
+
+/* struct for the object's class */
+struct _TTermContextClass
+{
+ TContextClass parent_class;
+};
+
+GType t_term_context_get_type (void);
+
+TTermContext *t_term_context_new (const gchar *id);
+
+void t_term_context_set_interactive (TTermContext *term_console, gboolean interactive);
+gboolean t_term_context_set_input_file (TTermContext *term_console, const gchar *filename, GError
**error);
+void t_term_context_set_input_stream (TTermContext *term_console, FILE *stream);
+FILE *t_term_context_get_input_stream (TTermContext *term_console);
+void t_term_context_treat_single_line (TTermContext *term_console, const gchar *cmde);
+
+#endif
diff --git a/tools/common/t-utils.c b/tools/common/t-utils.c
new file mode 100644
index 0000000..198686f
--- /dev/null
+++ b/tools/common/t-utils.c
@@ -0,0 +1,209 @@
+/*
+ * Copyright (C) 2011 - 2014 Vivien Malerba <malerba gnome-db org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "t-utils.h"
+#include "t-app.h"
+#include <glib/gi18n-lib.h>
+#include <unistd.h>
+#include <sql-parser/gda-sql-parser.h>
+#include <glib/gstdio.h>
+#include <errno.h>
+
+/**
+ * t_utils_fk_policy_to_string
+ * @policy: a #GdaMetaForeignKeyPolicy
+ *
+ * Returns: the human readable version of @policy
+ */
+const gchar *
+t_utils_fk_policy_to_string (GdaMetaForeignKeyPolicy policy)
+{
+ switch (policy) {
+ default:
+ g_assert_not_reached ();
+ case GDA_META_FOREIGN_KEY_UNKNOWN:
+ return _("Unknown");
+ case GDA_META_FOREIGN_KEY_NONE:
+ return _("not enforced");
+ case GDA_META_FOREIGN_KEY_NO_ACTION:
+ return _("stop with error");
+ case GDA_META_FOREIGN_KEY_RESTRICT:
+ return _("stop with error, not deferrable");
+ case GDA_META_FOREIGN_KEY_CASCADE:
+ return _("cascade changes");
+ case GDA_META_FOREIGN_KEY_SET_NULL:
+ return _("set to NULL");
+ case GDA_META_FOREIGN_KEY_SET_DEFAULT:
+ return _("set to default value");
+ }
+}
+
+/**
+ * t_utils_compute_prompt:
+ *
+ * Returns: (transfer full): the prompt
+ */
+gchar *
+t_utils_compute_prompt (TContext *console, gboolean in_command, gboolean for_readline, ToolOutputFormat
format)
+{
+ g_return_val_if_fail (T_IS_CONTEXT (console), NULL);
+
+ const gchar *prefix = NULL;
+ TConnection *tcnc;
+ GString *string;
+ gchar suffix = '>';
+
+ string = g_string_new ("");
+
+ if (format & BASE_TOOL_OUTPUT_FORMAT_COLOR_TERM) {
+ const gchar *color;
+ color = base_tool_output_color_s (BASE_TOOL_COLOR_BOLD, format);
+ if (color && *color) {
+#ifdef HAVE_READLINE
+ if (for_readline)
+ g_string_append_c (string, RL_PROMPT_START_IGNORE);
+#endif
+ g_string_append (string, color);
+#ifdef HAVE_READLINE
+ if (for_readline)
+ g_string_append_c (string, RL_PROMPT_END_IGNORE);
+#endif
+ }
+ }
+ tcnc = t_context_get_connection (console);
+ if (tcnc) {
+ prefix = t_connection_get_name (tcnc);
+ if (t_connection_get_cnc (tcnc)) {
+ GdaTransactionStatus *ts;
+ ts = gda_connection_get_transaction_status (t_connection_get_cnc (tcnc));
+ if (ts)
+ suffix='[';
+ }
+ }
+ else
+ prefix = "gda";
+
+ if (in_command) {
+ gint i, len;
+ len = strlen (prefix);
+ for (i = 0; i < len; i++)
+ g_string_append_c (string, ' ');
+ g_string_append_c (string, suffix);
+ g_string_append_c (string, ' ');
+ }
+ else
+ g_string_append_printf (string, "%s%c ", prefix, suffix);
+
+ if (format & BASE_TOOL_OUTPUT_FORMAT_COLOR_TERM) {
+ const gchar *color;
+ color = base_tool_output_color_s (BASE_TOOL_COLOR_RESET, BASE_TOOL_OUTPUT_FORMAT_COLOR_TERM);
+ if (color && *color) {
+#ifdef HAVE_READLINE
+ if (for_readline)
+ g_string_append_c (string, RL_PROMPT_START_IGNORE);
+#endif
+ g_string_append (string, color);
+#ifdef HAVE_READLINE
+ if (for_readline)
+ g_string_append_c (string, RL_PROMPT_END_IGNORE);
+#endif
+ }
+ }
+
+ return g_string_free (string, FALSE);
+}
+
+/**
+ * t_utils_command_is_complete:
+ */
+gboolean
+t_utils_command_is_complete (const gchar *command)
+{
+ if (!command || !(*command))
+ return FALSE;
+ if ((*command == '\\') || (*command == '.')) {
+ /* internal command */
+ return TRUE;
+ }
+ else if (*command == '#') {
+ /* comment, to be ignored */
+ return TRUE;
+ }
+ else {
+ gint i, len;
+ len = strlen (command);
+ for (i = len - 1; i > 0; i--) {
+ if ((command [i] != ' ') && (command [i] != '\n') && (command [i] != '\r'))
+ break;
+ }
+ if (command [i] == ';')
+ return TRUE;
+ else
+ return FALSE;
+ }
+}
+
+/**
+ * t_utils_check_shell_argument:
+ *
+ * Check that the @arg string can safely be passed to a shell
+ * to be executed, i.e. it does not contain dangerous things like "rm -rf *"
+ */
+// coverity[ +tainted_string_sanitize_content : arg-0 ]
+gboolean
+t_utils_check_shell_argument (const gchar *arg)
+{
+ const gchar *ptr;
+ g_assert (arg);
+
+ /* check for starting spaces */
+ for (ptr = arg; *ptr == ' '; ptr++);
+ if (!*ptr)
+ return FALSE; /* only spaces is not allowed */
+
+ /* check for the rest */
+ for (; *ptr; ptr++) {
+ if (! g_ascii_isalnum (*ptr) && (*ptr != G_DIR_SEPARATOR))
+ return FALSE;
+ }
+ return TRUE;
+}
+
+/**
+ * t_utils_term_compute_color_attribute:
+ */
+void
+t_utils_term_compute_color_attribute ()
+{
+ ToolOutputFormat oformat;
+ oformat = t_context_get_output_format (t_app_get_term_console ());
+ oformat &= ~(BASE_TOOL_OUTPUT_FORMAT_COLOR_TERM);
+
+ FILE *ostream;
+ ostream = t_context_get_output_stream (t_app_get_term_console (), NULL);
+ if (!ostream || isatty (fileno (ostream))) {
+ const gchar *term;
+ oformat |= BASE_TOOL_OUTPUT_FORMAT_COLOR_TERM;
+ term = g_getenv ("TERM");
+ if (term && !strcmp (term, "dumb"))
+ oformat ^= BASE_TOOL_OUTPUT_FORMAT_COLOR_TERM;
+ }
+
+ t_context_set_output_format (t_app_get_term_console (), oformat);
+}
+
diff --git a/tools/browser/canvas/browser-canvas-priv.h b/tools/common/t-utils.h
similarity index 56%
rename from tools/browser/canvas/browser-canvas-priv.h
rename to tools/common/t-utils.h
index 41681e5..fc671a4 100644
--- a/tools/browser/canvas/browser-canvas-priv.h
+++ b/tools/common/t-utils.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2014 Vivien Malerba <malerba gnome-db org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -16,24 +16,19 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-#ifndef __BROWSER_CANVAS_PRIV__
-#define __BROWSER_CANVAS_PRIV__
+#ifndef __T_UTILS__
+#define __T_UTILS__
-#include <goocanvas.h>
-#include "browser-canvas-decl.h"
+#include <libgda/libgda.h>
+#include "t-context.h"
+#include <base/base-tool-decl.h>
-G_BEGIN_DECLS
+const gchar *t_utils_fk_policy_to_string (GdaMetaForeignKeyPolicy policy);
+gchar *t_utils_compute_prompt (TContext *console, gboolean in_command, gboolean for_readline,
ToolOutputFormat format);
+gboolean t_utils_command_is_complete (const gchar *command);
-struct _BrowserCanvasPrivate
-{
- GooCanvas *goocanvas;
- GSList *items; /* BrowserCanvasItem objects, non ordered */
+gboolean t_utils_check_shell_argument (const gchar *arg);
- gboolean canvas_moving;
-
- BrowserCanvasItem *current_selected_item;
-};
-
-G_END_DECLS
+void t_utils_term_compute_color_attribute (void);
#endif
diff --git a/tools/browser/browser-virtual-connection.c b/tools/common/t-virtual-connection.c
similarity index 53%
rename from tools/browser/browser-virtual-connection.c
rename to tools/common/t-virtual-connection.c
index 380f1e2..3220b4c 100644
--- a/tools/browser/browser-virtual-connection.c
+++ b/tools/common/t-virtual-connection.c
@@ -19,30 +19,30 @@
#include <string.h>
#include <glib/gi18n-lib.h>
-#include "browser-virtual-connection.h"
-#include "browser-connection-priv.h"
+#include "t-virtual-connection.h"
+#include <base/base-tool-decl.h>
#include <virtual/libgda-virtual.h>
-#include "../tool-utils.h"
+#include "t-utils.h"
+#include "t-app.h"
/*
* Main static functions
*/
-static void browser_virtual_connection_class_init (BrowserVirtualConnectionClass *klass);
-static void browser_virtual_connection_init (BrowserVirtualConnection *stmt);
-static void browser_virtual_connection_dispose (GObject *object);
-static void browser_virtual_connection_set_property (GObject *object,
+static void t_virtual_connection_class_init (TVirtualConnectionClass *klass);
+static void t_virtual_connection_init (TVirtualConnection *stmt);
+static void t_virtual_connection_dispose (GObject *object);
+static void t_virtual_connection_set_property (GObject *object,
guint param_id,
const GValue *value,
GParamSpec *pspec);
-static void browser_virtual_connection_get_property (GObject *object,
+static void t_virtual_connection_get_property (GObject *object,
guint param_id,
GValue *value,
GParamSpec *pspec);
-struct _BrowserVirtualConnectionPrivate
+struct _TVirtualConnectionPrivate
{
- GtkTable *layout_table;
- BrowserVirtualConnectionSpecs *specs;
+ TVirtualConnectionSpecs *specs;
};
/* get a pointer to the parents to be able to call their destructor */
@@ -55,62 +55,62 @@ enum {
};
GType
-browser_virtual_connection_get_type (void)
+t_virtual_connection_get_type (void)
{
static GType type = 0;
if (G_UNLIKELY (type == 0)) {
static GMutex registering;
static const GTypeInfo info = {
- sizeof (BrowserVirtualConnectionClass),
+ sizeof (TVirtualConnectionClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
- (GClassInitFunc) browser_virtual_connection_class_init,
+ (GClassInitFunc) t_virtual_connection_class_init,
NULL,
NULL,
- sizeof (BrowserVirtualConnection),
+ sizeof (TVirtualConnection),
0,
- (GInstanceInitFunc) browser_virtual_connection_init,
+ (GInstanceInitFunc) t_virtual_connection_init,
0
};
g_mutex_lock (®istering);
if (type == 0)
- type = g_type_register_static (BROWSER_TYPE_CONNECTION, "BrowserVirtualConnection",
&info, 0);
+ type = g_type_register_static (T_TYPE_CONNECTION, "TVirtualConnection", &info, 0);
g_mutex_unlock (®istering);
}
return type;
}
static void
-source_cnc_busy_cb (G_GNUC_UNUSED BrowserConnection *bcnc, gboolean is_busy,
- G_GNUC_UNUSED const gchar *reason, BrowserConnection *virtual)
+source_cnc_busy_cb (G_GNUC_UNUSED TConnection *bcnc, gboolean is_busy,
+ G_GNUC_UNUSED const gchar *reason, TConnection *virtual)
{
- if (browser_connection_is_busy (virtual, NULL) != is_busy)
+ if (t_connection_is_busy (virtual, NULL) != is_busy)
g_signal_emit_by_name (virtual, "busy", is_busy,
is_busy ? _("Bound connection is used") : NULL);
}
static void
-m_busy (BrowserConnection *bcnc, gboolean is_busy, const gchar *reason)
+m_busy (TConnection *bcnc, gboolean is_busy, const gchar *reason)
{
/*
* declare all the source connections as busy
*/
GSList *list;
- if (! BROWSER_VIRTUAL_CONNECTION (bcnc)->priv->specs)
+ if (! T_VIRTUAL_CONNECTION (bcnc)->priv->specs)
return;
- for (list = BROWSER_VIRTUAL_CONNECTION (bcnc)->priv->specs->parts; list; list = list->next) {
- BrowserVirtualConnectionPart *part;
- part = (BrowserVirtualConnectionPart*) list->data;
- if (part->part_type == BROWSER_VIRTUAL_CONNECTION_PART_CNC) {
- BrowserVirtualConnectionCnc *cnc;
+ for (list = T_VIRTUAL_CONNECTION (bcnc)->priv->specs->parts; list; list = list->next) {
+ TVirtualConnectionPart *part;
+ part = (TVirtualConnectionPart*) list->data;
+ if (part->part_type == T_VIRTUAL_CONNECTION_PART_CNC) {
+ TVirtualConnectionCnc *cnc;
cnc = &(part->u.cnc);
g_signal_handlers_block_by_func (cnc->source_cnc,
G_CALLBACK (source_cnc_busy_cb),
bcnc);
- if (browser_connection_is_busy (cnc->source_cnc, NULL) != is_busy)
+ if (t_connection_is_busy (cnc->source_cnc, NULL) != is_busy)
g_signal_emit_by_name (cnc->source_cnc, "busy", is_busy,
is_busy ? _("Virtual connection using this connection is busy") : NULL);
g_signal_handlers_unblock_by_func (cnc->source_cnc,
@@ -119,59 +119,59 @@ m_busy (BrowserConnection *bcnc, gboolean is_busy, const gchar *reason)
}
}
- BROWSER_CONNECTION_CLASS (parent_class)->busy (bcnc, is_busy, reason);
+ T_CONNECTION_CLASS (parent_class)->busy (bcnc, is_busy, reason);
}
static void
-browser_virtual_connection_class_init (BrowserVirtualConnectionClass * klass)
+t_virtual_connection_class_init (TVirtualConnectionClass * klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
- BROWSER_CONNECTION_CLASS (klass)->busy = m_busy;
+ T_CONNECTION_CLASS (klass)->busy = m_busy;
/* Properties */
- object_class->set_property = browser_virtual_connection_set_property;
- object_class->get_property = browser_virtual_connection_get_property;
+ object_class->set_property = t_virtual_connection_set_property;
+ object_class->get_property = t_virtual_connection_get_property;
g_object_class_install_property (object_class, PROP_SPECS,
g_param_spec_pointer ("specs", NULL,
- "Specifications as a
BrowserVirtualConnectionSpecs pointer",
+ "Specifications as a TVirtualConnectionSpecs
pointer",
G_PARAM_READABLE | G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY));
- object_class->dispose = browser_virtual_connection_dispose;
+ object_class->dispose = t_virtual_connection_dispose;
}
static void
-browser_virtual_connection_init (BrowserVirtualConnection *bcnc)
+t_virtual_connection_init (TVirtualConnection *bcnc)
{
- bcnc->priv = g_new0 (BrowserVirtualConnectionPrivate, 1);
+ bcnc->priv = g_new0 (TVirtualConnectionPrivate, 1);
}
static void
-browser_virtual_connection_dispose (GObject *object)
+t_virtual_connection_dispose (GObject *object)
{
- BrowserVirtualConnection *bcnc;
+ TVirtualConnection *bcnc;
g_return_if_fail (object != NULL);
- g_return_if_fail (BROWSER_IS_VIRTUAL_CONNECTION (object));
+ g_return_if_fail (T_IS_VIRTUAL_CONNECTION (object));
- bcnc = BROWSER_VIRTUAL_CONNECTION (object);
+ bcnc = T_VIRTUAL_CONNECTION (object);
if (bcnc->priv) {
if (bcnc->priv->specs) {
GSList *list;
for (list = bcnc->priv->specs->parts; list; list = list->next) {
- BrowserVirtualConnectionPart *part;
- part = (BrowserVirtualConnectionPart*) list->data;
- if (part->part_type == BROWSER_VIRTUAL_CONNECTION_PART_CNC) {
- BrowserVirtualConnectionCnc *cnc;
+ TVirtualConnectionPart *part;
+ part = (TVirtualConnectionPart*) list->data;
+ if (part->part_type == T_VIRTUAL_CONNECTION_PART_CNC) {
+ TVirtualConnectionCnc *cnc;
cnc = &(part->u.cnc);
g_signal_handlers_disconnect_by_func (cnc->source_cnc,
G_CALLBACK (source_cnc_busy_cb),
bcnc);
}
}
- browser_virtual_connection_specs_free (bcnc->priv->specs);
+ t_virtual_connection_specs_free (bcnc->priv->specs);
}
g_free (bcnc->priv);
@@ -183,24 +183,24 @@ browser_virtual_connection_dispose (GObject *object)
}
static void
-browser_virtual_connection_set_property (GObject *object,
+t_virtual_connection_set_property (GObject *object,
guint param_id,
const GValue *value,
GParamSpec *pspec)
{
- BrowserVirtualConnection *bcnc;
+ TVirtualConnection *bcnc;
- bcnc = BROWSER_VIRTUAL_CONNECTION (object);
+ bcnc = T_VIRTUAL_CONNECTION (object);
if (bcnc->priv) {
switch (param_id) {
case PROP_SPECS:
- bcnc->priv->specs = browser_virtual_connection_specs_copy (g_value_get_pointer
(value));
+ bcnc->priv->specs = t_virtual_connection_specs_copy (g_value_get_pointer (value));
GSList *list;
for (list = bcnc->priv->specs->parts; list; list = list->next) {
- BrowserVirtualConnectionPart *part;
- part = (BrowserVirtualConnectionPart*) list->data;
- if (part->part_type == BROWSER_VIRTUAL_CONNECTION_PART_CNC) {
- BrowserVirtualConnectionCnc *cnc;
+ TVirtualConnectionPart *part;
+ part = (TVirtualConnectionPart*) list->data;
+ if (part->part_type == T_VIRTUAL_CONNECTION_PART_CNC) {
+ TVirtualConnectionCnc *cnc;
cnc = &(part->u.cnc);
g_signal_connect (cnc->source_cnc, "busy",
G_CALLBACK (source_cnc_busy_cb), bcnc);
@@ -216,14 +216,14 @@ browser_virtual_connection_set_property (GObject *object,
}
static void
-browser_virtual_connection_get_property (GObject *object,
+t_virtual_connection_get_property (GObject *object,
guint param_id,
GValue *value,
GParamSpec *pspec)
{
- BrowserVirtualConnection *bcnc;
+ TVirtualConnection *bcnc;
- bcnc = BROWSER_VIRTUAL_CONNECTION (object);
+ bcnc = T_VIRTUAL_CONNECTION (object);
if (bcnc->priv) {
switch (param_id) {
case PROP_SPECS:
@@ -237,16 +237,16 @@ browser_virtual_connection_get_property (GObject *object,
}
/**
- * browser_virtual_connection_new
+ * t_virtual_connection_new
* @specs: the specifications of the virtual connection's contents
* @error: a place to store errors, or %NULL
*
- * Creates a new #BrowserVirtualConnection connection.
+ * Creates a new #TVirtualConnection connection.
*
- * Returns: the new connection
+ * Returns: (transfert none): the new connection
*/
-BrowserConnection *
-browser_virtual_connection_new (const BrowserVirtualConnectionSpecs *specs, GError **error)
+TConnection *
+t_virtual_connection_new (const TVirtualConnectionSpecs *specs, GError **error)
{
#ifdef DUMMY
sleep (5);
@@ -266,11 +266,11 @@ browser_virtual_connection_new (const BrowserVirtualConnectionSpecs *specs, GErr
/* add parts to connection as specified by @specs */
GSList *list;
for (list = specs->parts; list; list = list->next) {
- BrowserVirtualConnectionPart *part;
- part = (BrowserVirtualConnectionPart*) list->data;
+ TVirtualConnectionPart *part;
+ part = (TVirtualConnectionPart*) list->data;
switch (part->part_type) {
- case BROWSER_VIRTUAL_CONNECTION_PART_MODEL: {
- BrowserVirtualConnectionModel *pm;
+ case T_VIRTUAL_CONNECTION_PART_MODEL: {
+ TVirtualConnectionModel *pm;
pm = &(part->u.model);
if (! gda_vconnection_data_model_add_model (GDA_VCONNECTION_DATA_MODEL (virtual),
pm->model, pm->table_name, error)) {
@@ -279,11 +279,11 @@ browser_virtual_connection_new (const BrowserVirtualConnectionSpecs *specs, GErr
}
break;
}
- case BROWSER_VIRTUAL_CONNECTION_PART_CNC: {
- BrowserVirtualConnectionCnc *scnc;
+ case T_VIRTUAL_CONNECTION_PART_CNC: {
+ TVirtualConnectionCnc *scnc;
scnc = &(part->u.cnc);
if (!gda_vconnection_hub_add (GDA_VCONNECTION_HUB (virtual),
- scnc->source_cnc->priv->cnc,
+ t_connection_get_cnc (scnc->source_cnc),
scnc->table_schema, error)) {
g_object_unref (virtual);
return NULL;
@@ -295,53 +295,57 @@ browser_virtual_connection_new (const BrowserVirtualConnectionSpecs *specs, GErr
}
}
- /* create the BrowserConnection object */
+ /* create the TConnection object */
if (virtual) {
- BrowserConnection *nbcnc;
- nbcnc = g_object_new (BROWSER_TYPE_VIRTUAL_CONNECTION, "specs", specs,
+ TConnection *ntcnc;
+ ntcnc = g_object_new (T_TYPE_VIRTUAL_CONNECTION, "specs", specs,
"gda-connection", virtual, NULL);
g_object_unref (virtual);
- return nbcnc;
+ t_app_add_tcnc (ntcnc);
+ return ntcnc;
}
else
return NULL;
}
/**
- * browser_virtual_connection_modify_specs
- * @bcnc: a #BrowserVirtualConnection connection
- * @new_specs: a pointer to a #BrowserVirtualConnectionSpecs for the new specs
+ * t_virtual_connection_modify_specs
+ * @bcnc: a #TVirtualConnection connection
+ * @new_specs: a pointer to a #TVirtualConnectionSpecs for the new specs
* @error: a place to store errors, or %NULL
*
* Returns: %TRUE if no error occurred
*/
gboolean
-browser_virtual_connection_modify_specs (BrowserVirtualConnection *bcnc,
- const BrowserVirtualConnectionSpecs *new_specs, GError **error)
+t_virtual_connection_modify_specs (TVirtualConnection *bcnc,
+ const TVirtualConnectionSpecs *new_specs, GError **error)
{
- g_return_val_if_fail (BROWSER_IS_VIRTUAL_CONNECTION (bcnc), FALSE);
+ g_return_val_if_fail (T_IS_VIRTUAL_CONNECTION (bcnc), FALSE);
g_return_val_if_fail (new_specs, FALSE);
/* undo the current specs */
GSList *list;
GdaConnection *cnc;
- cnc = g_object_get_data (G_OBJECT (BROWSER_CONNECTION (bcnc)->priv->cnc), "gda-virtual-connection");
+ cnc = g_object_get_data (G_OBJECT (t_connection_get_cnc (T_CONNECTION (bcnc))),
+ "gda-virtual-connection");
+ TO_IMPLEMENT;
for (list = bcnc->priv->specs->parts; list; list = bcnc->priv->specs->parts) {
- BrowserVirtualConnectionPart *part;
- part = (BrowserVirtualConnectionPart*) list->data;
+ TVirtualConnectionPart *part;
+ part = (TVirtualConnectionPart*) list->data;
switch (part->part_type) {
- case BROWSER_VIRTUAL_CONNECTION_PART_MODEL: {
- BrowserVirtualConnectionModel *pm;
+ case T_VIRTUAL_CONNECTION_PART_MODEL: {
+ TVirtualConnectionModel *pm;
pm = &(part->u.model);
if (! gda_vconnection_data_model_remove (GDA_VCONNECTION_DATA_MODEL (cnc),
pm->table_name, error))
return FALSE;
break;
}
- case BROWSER_VIRTUAL_CONNECTION_PART_CNC: {
- BrowserVirtualConnectionCnc *scnc;
+ case T_VIRTUAL_CONNECTION_PART_CNC: {
+ TVirtualConnectionCnc *scnc;
scnc = &(part->u.cnc);
- if (!gda_vconnection_hub_remove (GDA_VCONNECTION_HUB (cnc),
scnc->source_cnc->priv->cnc,
+ if (!gda_vconnection_hub_remove (GDA_VCONNECTION_HUB (cnc),
+ t_connection_get_cnc (scnc->source_cnc),
error))
return FALSE;
break;
@@ -351,30 +355,30 @@ browser_virtual_connection_modify_specs (BrowserVirtualConnection *bcnc,
}
/* get rid of @part */
- browser_virtual_connection_part_free (part);
+ t_virtual_connection_part_free (part);
bcnc->priv->specs->parts = g_slist_remove (bcnc->priv->specs->parts, part);
}
/* apply the new specs */
- browser_virtual_connection_specs_free (bcnc->priv->specs);
- bcnc->priv->specs = g_new0 (BrowserVirtualConnectionSpecs, 1);
+ t_virtual_connection_specs_free (bcnc->priv->specs);
+ bcnc->priv->specs = g_new0 (TVirtualConnectionSpecs, 1);
for (list = new_specs->parts; list; list = list->next) {
- BrowserVirtualConnectionPart *part;
- part = (BrowserVirtualConnectionPart*) list->data;
+ TVirtualConnectionPart *part;
+ part = (TVirtualConnectionPart*) list->data;
switch (part->part_type) {
- case BROWSER_VIRTUAL_CONNECTION_PART_MODEL: {
- BrowserVirtualConnectionModel *pm;
+ case T_VIRTUAL_CONNECTION_PART_MODEL: {
+ TVirtualConnectionModel *pm;
pm = &(part->u.model);
if (! gda_vconnection_data_model_add_model (GDA_VCONNECTION_DATA_MODEL (cnc),
pm->model, pm->table_name, error))
return FALSE;
break;
}
- case BROWSER_VIRTUAL_CONNECTION_PART_CNC: {
- BrowserVirtualConnectionCnc *scnc;
+ case T_VIRTUAL_CONNECTION_PART_CNC: {
+ TVirtualConnectionCnc *scnc;
scnc = &(part->u.cnc);
- if (!gda_vconnection_hub_add (GDA_VCONNECTION_HUB (cnc), scnc->source_cnc->priv->cnc,
+ if (!gda_vconnection_hub_add (GDA_VCONNECTION_HUB (cnc), t_connection_get_cnc
(scnc->source_cnc),
scnc->table_schema, error))
return FALSE;
break;
@@ -385,7 +389,7 @@ browser_virtual_connection_modify_specs (BrowserVirtualConnection *bcnc,
/* add @part to bcnc->priv->specs */
bcnc->priv->specs->parts = g_slist_append (bcnc->priv->specs->parts,
- browser_virtual_connection_part_copy (part));
+ t_virtual_connection_part_copy (part));
}
return TRUE;
@@ -397,21 +401,21 @@ browser_virtual_connection_modify_specs (BrowserVirtualConnection *bcnc,
*/
/**
- * browser_virtual_connection_part_copy
+ * t_virtual_connection_part_copy
*/
-BrowserVirtualConnectionPart *
-browser_virtual_connection_part_copy (const BrowserVirtualConnectionPart *part)
+TVirtualConnectionPart *
+t_virtual_connection_part_copy (const TVirtualConnectionPart *part)
{
- BrowserVirtualConnectionPart *npart;
+ TVirtualConnectionPart *npart;
g_return_val_if_fail (part, NULL);
- npart = g_new0 (BrowserVirtualConnectionPart, 1);
+ npart = g_new0 (TVirtualConnectionPart, 1);
npart->part_type = part->part_type;
switch (part->part_type) {
- case BROWSER_VIRTUAL_CONNECTION_PART_MODEL: {
- const BrowserVirtualConnectionModel *spm;
- BrowserVirtualConnectionModel *npm;
+ case T_VIRTUAL_CONNECTION_PART_MODEL: {
+ const TVirtualConnectionModel *spm;
+ TVirtualConnectionModel *npm;
spm = &(part->u.model);
npm = &(npart->u.model);
if (spm->table_name)
@@ -420,9 +424,9 @@ browser_virtual_connection_part_copy (const BrowserVirtualConnectionPart *part)
npm->model = g_object_ref (G_OBJECT (spm->model));
break;
}
- case BROWSER_VIRTUAL_CONNECTION_PART_CNC: {
- const BrowserVirtualConnectionCnc *scnc;
- BrowserVirtualConnectionCnc *ncnc;
+ case T_VIRTUAL_CONNECTION_PART_CNC: {
+ const TVirtualConnectionCnc *scnc;
+ TVirtualConnectionCnc *ncnc;
scnc = &(part->u.cnc);
ncnc = &(npart->u.cnc);
if (scnc->table_schema)
@@ -439,25 +443,25 @@ browser_virtual_connection_part_copy (const BrowserVirtualConnectionPart *part)
}
/**
- * browser_virtual_connection_part_free
+ * t_virtual_connection_part_free
*/
void
-browser_virtual_connection_part_free (BrowserVirtualConnectionPart *part)
+t_virtual_connection_part_free (TVirtualConnectionPart *part)
{
if (!part)
return;
switch (part->part_type) {
- case BROWSER_VIRTUAL_CONNECTION_PART_MODEL: {
- BrowserVirtualConnectionModel *pm;
+ case T_VIRTUAL_CONNECTION_PART_MODEL: {
+ TVirtualConnectionModel *pm;
pm = &(part->u.model);
g_free (pm->table_name);
if (pm->model)
g_object_unref (pm->model);
break;
}
- case BROWSER_VIRTUAL_CONNECTION_PART_CNC: {
- BrowserVirtualConnectionCnc *cnc;
+ case T_VIRTUAL_CONNECTION_PART_CNC: {
+ TVirtualConnectionCnc *cnc;
cnc = &(part->u.cnc);
g_free (cnc->table_schema);
if (cnc->source_cnc)
@@ -470,20 +474,20 @@ browser_virtual_connection_part_free (BrowserVirtualConnectionPart *part)
}
/**
- * browser_virtual_connection_specs_copy
+ * t_virtual_connection_specs_copy
*/
-BrowserVirtualConnectionSpecs *
-browser_virtual_connection_specs_copy (const BrowserVirtualConnectionSpecs *specs)
+TVirtualConnectionSpecs *
+t_virtual_connection_specs_copy (const TVirtualConnectionSpecs *specs)
{
- BrowserVirtualConnectionSpecs *ns;
+ TVirtualConnectionSpecs *ns;
GSList *list;
g_return_val_if_fail (specs, NULL);
- ns = g_new0 (BrowserVirtualConnectionSpecs, 1);
+ ns = g_new0 (TVirtualConnectionSpecs, 1);
for (list = specs->parts; list; list = list->next) {
- BrowserVirtualConnectionPart *npart;
- npart = browser_virtual_connection_part_copy ((BrowserVirtualConnectionPart*) list->data);
+ TVirtualConnectionPart *npart;
+ npart = t_virtual_connection_part_copy ((TVirtualConnectionPart*) list->data);
ns->parts = g_slist_prepend (ns->parts, npart);
}
ns->parts = g_slist_reverse (ns->parts);
@@ -492,14 +496,14 @@ browser_virtual_connection_specs_copy (const BrowserVirtualConnectionSpecs *spec
}
/**
- * browser_virtual_connection_specs_free
+ * t_virtual_connection_specs_free
*/
void
-browser_virtual_connection_specs_free (BrowserVirtualConnectionSpecs *specs)
+t_virtual_connection_specs_free (TVirtualConnectionSpecs *specs)
{
if (!specs)
return;
- g_slist_foreach (specs->parts, (GFunc) browser_virtual_connection_part_free, NULL);
+ g_slist_foreach (specs->parts, (GFunc) t_virtual_connection_part_free, NULL);
g_slist_free (specs->parts);
g_free (specs);
}
diff --git a/tools/common/t-virtual-connection.h b/tools/common/t-virtual-connection.h
new file mode 100644
index 0000000..9d9d44f
--- /dev/null
+++ b/tools/common/t-virtual-connection.h
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2009 - 2014 Vivien Malerba <malerba gnome-db org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+
+#ifndef __T_VIRTUAL_CONNECTION_H_
+#define __T_VIRTUAL_CONNECTION_H_
+
+#include "t-connection.h"
+
+G_BEGIN_DECLS
+
+#define T_TYPE_VIRTUAL_CONNECTION (t_virtual_connection_get_type())
+#define T_VIRTUAL_CONNECTION(obj) G_TYPE_CHECK_INSTANCE_CAST (obj, t_virtual_connection_get_type(),
TVirtualConnection)
+#define T_VIRTUAL_CONNECTION_CLASS(klass) G_TYPE_CHECK_CLASS_CAST (klass, t_virtual_connection_get_type (),
TVirtualConnectionClass)
+#define T_IS_VIRTUAL_CONNECTION(obj) G_TYPE_CHECK_INSTANCE_TYPE (obj, t_virtual_connection_get_type ())
+
+typedef struct _TVirtualConnection TVirtualConnection;
+typedef struct _TVirtualConnectionPrivate TVirtualConnectionPrivate;
+typedef struct _TVirtualConnectionClass TVirtualConnectionClass;
+
+/* struct for the object's data */
+struct _TVirtualConnection
+{
+ TConnection object;
+ TVirtualConnectionPrivate *priv;
+};
+
+/* struct for the object's class */
+struct _TVirtualConnectionClass
+{
+ TConnectionClass parent_class;
+};
+
+/* parts types */
+typedef enum {
+ T_VIRTUAL_CONNECTION_PART_MODEL,
+ T_VIRTUAL_CONNECTION_PART_CNC,
+} TVirtualConnectionType;
+
+/* part: a table from a GdaDataModel */
+typedef struct {
+ gchar *table_name;
+ GdaDataModel *model;
+} TVirtualConnectionModel;
+
+/* part: tables from a TConnection */
+typedef struct {
+ gchar *table_schema;
+ TConnection *source_cnc;
+} TVirtualConnectionCnc;
+
+/* generic part */
+typedef struct {
+ TVirtualConnectionType part_type;
+ union {
+ TVirtualConnectionModel model;
+ TVirtualConnectionCnc cnc;
+ } u;
+} TVirtualConnectionPart;
+TVirtualConnectionPart *t_virtual_connection_part_copy (const TVirtualConnectionPart *part);
+void t_virtual_connection_part_free (TVirtualConnectionPart *part);
+
+/* specs */
+typedef struct {
+ GSList *parts;
+} TVirtualConnectionSpecs;
+TVirtualConnectionSpecs *t_virtual_connection_specs_copy (const TVirtualConnectionSpecs *specs);
+void t_virtual_connection_specs_free (TVirtualConnectionSpecs *specs);
+
+GType t_virtual_connection_get_type (void) G_GNUC_CONST;
+TConnection *t_virtual_connection_new (const TVirtualConnectionSpecs *specs,
+ GError **error);
+gboolean t_virtual_connection_modify_specs (TVirtualConnection *bcnc,
+ const TVirtualConnectionSpecs *new_specs,
+ GError **error);
+G_END_DECLS
+
+#endif
diff --git a/tools/common/t-web-context.c b/tools/common/t-web-context.c
new file mode 100644
index 0000000..9c433c2
--- /dev/null
+++ b/tools/common/t-web-context.c
@@ -0,0 +1,119 @@
+/*
+ * Copyright (C) 2014 Vivien Malerba <malerba gnome-db org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "t-web-context.h"
+#include "t-utils.h"
+#include "t-app.h"
+#include <glib/gi18n-lib.h>
+#include <sql-parser/gda-sql-parser.h>
+#include <glib/gstdio.h>
+#include <errno.h>
+
+/*
+ * Main static functions
+ */
+static void t_web_context_class_init (TWebContextClass *klass);
+static void t_web_context_init (TWebContext *bcore);
+static void t_web_context_dispose (GObject *object);
+
+/* get a pointer to the parents to be able to call their destructor */
+static GObjectClass *parent_class = NULL;
+
+struct _TWebContextPrivate {
+ gint dummy;
+};
+
+GType
+t_web_context_get_type (void)
+{
+ static GType type = 0;
+
+ if (G_UNLIKELY (type == 0)) {
+ static GMutex registering;
+ static const GTypeInfo info = {
+ sizeof (TWebContextClass),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) t_web_context_class_init,
+ NULL,
+ NULL,
+ sizeof (TWebContext),
+ 0,
+ (GInstanceInitFunc) t_web_context_init,
+ 0
+ };
+
+
+ g_mutex_lock (®istering);
+ if (type == 0)
+ type = g_type_register_static (T_TYPE_CONTEXT, "TWebContext", &info, 0);
+ g_mutex_unlock (®istering);
+ }
+ return type;
+}
+
+static void
+t_web_context_class_init (TWebContextClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ parent_class = g_type_class_peek_parent (klass);
+
+ object_class->dispose = t_web_context_dispose;
+}
+
+static void
+t_web_context_init (TWebContext *self)
+{
+ self->priv = g_new0 (TWebContextPrivate, 1);
+}
+
+static void
+t_web_context_dispose (GObject *object)
+{
+ TWebContext *console = T_WEB_CONTEXT (object);
+
+ if (console->priv) {
+ g_free (console->priv);
+ console->priv = NULL;
+ }
+
+ /* parent class */
+ parent_class->dispose (object);
+}
+
+
+
+/**
+ * t_web_context_new:
+ *
+ * Returns: (transfer none): a new #TWebContext
+ */
+TWebContext *
+t_web_context_new (const gchar *id)
+{
+ TWebContext *console = NULL;
+#ifdef HAVE_LIBSOUP
+ TApp *main_data;
+ main_data = t_app_get ();
+
+ console = g_object_new (T_TYPE_WEB_CONTEXT, "id", id, NULL);
+
+ t_context_set_command_group (T_CONTEXT (console), main_data->web_commands);
+#endif
+ return console;
+}
diff --git a/tools/common/t-web-context.h b/tools/common/t-web-context.h
new file mode 100644
index 0000000..b9b1e4a
--- /dev/null
+++ b/tools/common/t-web-context.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2014 Vivien Malerba <malerba gnome-db org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __T_WEB_CONTEXT__
+#define __T_WEB_CONTEXT__
+
+#include <glib.h>
+#include "t-context.h"
+
+/*
+ * Object representing a context using a connection (AKA a console)
+ */
+#define T_TYPE_WEB_CONTEXT (t_web_context_get_type())
+#define T_WEB_CONTEXT(obj) G_TYPE_CHECK_INSTANCE_CAST (obj, t_web_context_get_type(), TWebContext)
+#define T_WEB_CONTEXT_CLASS(klass) G_TYPE_CHECK_CLASS_CAST (klass, t_web_context_get_type (),
TWebContextClass)
+#define T_IS_WEB_CONTEXT(obj) G_TYPE_CHECK_INSTANCE_TYPE (obj, t_web_context_get_type ())
+
+typedef struct _TWebContextClass TWebContextClass;
+typedef struct _TWebContextPrivate TWebContextPrivate;
+
+/* struct for the object's data */
+typedef struct
+{
+ TContext object;
+ TWebContextPrivate *priv;
+} TWebContext;
+
+/* struct for the object's class */
+struct _TWebContextClass
+{
+ TContextClass parent_class;
+};
+
+GType t_web_context_get_type (void);
+TWebContext *t_web_context_new (const gchar *id);
+
+#endif
diff --git a/tools/web-server.c b/tools/common/web-server.c
similarity index 89%
rename from tools/web-server.c
rename to tools/common/web-server.c
index a27a7c1..31b104c 100644
--- a/tools/web-server.c
+++ b/tools/common/web-server.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008 - 2012 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2008 - 2014 Vivien Malerba <malerba gnome-db org>
* Copyright (C) 2009 Bas Driessen <bas driessen xobas com>
* Copyright (C) 2010 David King <davidk openismus com>
*
@@ -28,10 +28,10 @@
#include <libsoup/soup.h>
#include "html-doc.h"
#include <libgda/binreloc/gda-binreloc.h>
-
-/* Use the RSA reference implementation included in the RFC-1321, http://www.freesoft.org/CIE/RFC/1321/ */
-#include "global.h"
-#include "md5.h"
+#include "common/t-web-context.h"
+#include "common/t-utils.h"
+#include "common/t-connection.h"
+#include "t-app.h"
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
@@ -64,7 +64,7 @@ struct _WebServerPrivate
GArray *cookies; /* array of TimedString representing the currently valid authentication cookie
values */
guint auth_timer;
- GSList *terminals_list; /* list of SqlConsole */
+ GSList *terminals_list; /* list of TContext */
guint term_timer;
};
@@ -177,10 +177,10 @@ static gboolean get_file (WebServer *server, SoupMessage *msg, const char *path,
static void get_root (WebServer *server, SoupMessage *msg);
static void get_for_console (WebServer *server, SoupMessage *msg);
static gboolean get_for_cnc (WebServer *webserver, SoupMessage *msg,
- const ConnectionSetting *cs, gchar **extra, GError **error);
+ TConnection *tcnc, gchar **extra, GError **error);
static gboolean get_auth (WebServer *server, SoupMessage *msg, GHashTable *query);
static gboolean get_post_for_irb (WebServer *webserver, SoupMessage *msg,
- const ConnectionSetting *cs, GHashTable *query, GError **error);
+ TConnection *tcnc, GHashTable *query, GError **error);
static void get_for_cnclist (WebServer *webserver, SoupMessage *msg, gboolean is_authenticated);
@@ -277,12 +277,12 @@ server_callback (G_GNUC_UNUSED SoupServer *server, SoupMessage *msg,
array = g_strsplit (path, "/", 0);
if (array) {
- const ConnectionSetting *cs;
- cs = gda_sql_get_connection (array[0]);
+ TConnection *tcnc;
+ tcnc = t_connection_get_by_name (array[0]);
- if (cs) {
+ if (tcnc) {
if (msg->method == SOUP_METHOD_GET) {
- ok = get_for_cnc (webserver, msg, cs, array[1] ? &(array[1]) : NULL,
&error);
+ ok = get_for_cnc (webserver, msg, tcnc, array[1] ? &(array[1]) :
NULL, &error);
done = TRUE;
}
}
@@ -291,7 +291,7 @@ server_callback (G_GNUC_UNUSED SoupServer *server, SoupMessage *msg,
done = TRUE;
}
else if (!strcmp (path, "~irb")) {
- ok = get_post_for_irb (webserver, msg, cs, query, &error);
+ ok = get_post_for_irb (webserver, msg, tcnc, query, &error);
done = TRUE;
}
else if (!strcmp (path, "~cnclist")) {
@@ -331,8 +331,8 @@ server_callback (G_GNUC_UNUSED SoupServer *server, SoupMessage *msg,
}
/**
- * web_server_new
- * @type: the #GType requested
+ * web_server_new:
+ * @port: the port to listen on
* @auth_token: (allow-none): the authentication token, or %NULL
*
* Creates a new server of type @type
@@ -423,7 +423,7 @@ web_server_finalize (GObject * object)
g_array_free (server->priv->cookies, TRUE);
if (server->priv->terminals_list) {
- g_slist_foreach (server->priv->terminals_list, (GFunc) gda_sql_console_free, NULL);
+ g_slist_foreach (server->priv->terminals_list, (GFunc) g_object_unref, NULL);
g_slist_free (server->priv->terminals_list);
}
g_free (server->priv);
@@ -438,7 +438,7 @@ web_server_finalize (GObject * object)
* Server GET/POST methods
*
*/
-static HtmlDoc *create_new_htmldoc (WebServer *webserver, const ConnectionSetting *cs);
+static HtmlDoc *create_new_htmldoc (WebServer *webserver, TConnection *tcnc);
static void get_variables (SoupMessage *msg, GHashTable *query, ...);
/*
@@ -485,74 +485,6 @@ get_file (G_GNUC_UNUSED WebServer *server, SoupMessage *msg, const char *path, G
return TRUE;
}
-#define PAD_LEN 64 /* PAD length */
-#define SIG_LEN 16 /* MD5 digest length */
-/*
- * From RFC 2104
- */
-static void
-hmac_md5 (uint8_t* text, /* pointer to data stream */
- int text_len, /* length of data stream */
- uint8_t* key, /* pointer to authentication key */
- int key_len, /* length of authentication key */
- uint8_t *hmac) /* returned hmac-md5 */
-{
- MD5_CTX md5c;
- uint8_t k_ipad[PAD_LEN]; /* inner padding - key XORd with ipad */
- uint8_t k_opad[PAD_LEN]; /* outer padding - key XORd with opad */
- uint8_t keysig[SIG_LEN];
- int i;
-
- /* if key is longer than PAD length, reset it to key=MD5(key) */
- if (key_len > PAD_LEN) {
- MD5_CTX md5key;
-
- MD5Init (&md5key);
- MD5Update (&md5key, key, key_len);
- MD5Final (keysig, &md5key);
-
- key = keysig;
- key_len = SIG_LEN;
- }
-
- /*
- * the HMAC_MD5 transform looks like:
- *
- * MD5(Key XOR opad, MD5(Key XOR ipad, text))
- *
- * where Key is an n byte key
- * ipad is the byte 0x36 repeated 64 times
-
- * opad is the byte 0x5c repeated 64 times
- * and text is the data being protected
- */
-
- /* Zero pads and store key */
- memset (k_ipad, 0, PAD_LEN);
- memcpy (k_ipad, key, key_len);
- memcpy (k_opad, k_ipad, PAD_LEN);
-
- /* XOR key with ipad and opad values */
- for (i=0; i<PAD_LEN; i++) {
- k_ipad[i] ^= 0x36;
- k_opad[i] ^= 0x5c;
- }
-
- /* perform inner MD5 */
- MD5Init (&md5c); /* start inner hash */
- MD5Update (&md5c, k_ipad, PAD_LEN); /* hash inner pad */
- MD5Update (&md5c, text, text_len); /* hash text */
- MD5Final (hmac, &md5c); /* store inner hash */
-
- /* perform outer MD5 */
- MD5Init (&md5c); /* start outer hash */
- MD5Update (&md5c, k_opad, PAD_LEN); /* hash outer pad */
- MD5Update (&md5c, hmac, SIG_LEN); /* hash inner hash */
- MD5Final (hmac, &md5c); /* store results */
-}
-
-
-
/*
* Creates a login form
*
@@ -583,17 +515,13 @@ get_auth (WebServer *server, SoupMessage *msg, GHashTable *query)
gsize n;
for (n = 0; n < server->priv->challenges->len; n++) {
TimedString *ts = g_array_index (server->priv->challenges, TimedString *, n);
- uint8_t hmac[16];
- GString *md5str;
- gint i;
+ gchar *md5str;
- hmac_md5 ((uint8_t *) ts->string, strlen (ts->string),
- (uint8_t *) server->priv->token, strlen (server->priv->token), hmac);
- md5str = g_string_new ("");
- for (i = 0; i < 16; i++)
- g_string_append_printf (md5str, "%02x", hmac[i]);
+ md5str = g_compute_hmac_for_string (G_CHECKSUM_MD5,
+ server->priv->token, strlen (server->priv->token),
+ ts->string, -1);
- if (!strcmp (md5str->str, token)) {
+ if (!strcmp (md5str, token)) {
/* forge a new location change message */
GString *cook;
gchar *tmp;
@@ -610,12 +538,12 @@ get_auth (WebServer *server, SoupMessage *msg, GHashTable *query)
/*soup_message_set_status (msg, SOUP_STATUS_TEMPORARY_REDIRECT);
soup_message_headers_append (msg->response_headers, "Location", "/");*/
- g_string_free (md5str, TRUE);
+ g_free (md5str);
g_free (token);
return TRUE;
}
- g_string_free (md5str, TRUE);
+ g_free (md5str);
}
g_free (token);
@@ -624,7 +552,7 @@ get_auth (WebServer *server, SoupMessage *msg, GHashTable *query)
/* Add javascript */
xmlNodePtr form, node;
- node = xmlNewChild (hdoc->head, NULL, BAD_CAST "script", BAD_CAST "");
+ node = xmlNewChild (hdoc->head, NULL, BAD_CAST "script", BAD_CAST " ");
xmlSetProp (node, BAD_CAST "type", BAD_CAST "text/javascript");
xmlSetProp (node, BAD_CAST "src", BAD_CAST "/md5.js");
@@ -670,19 +598,19 @@ get_root (WebServer *server, SoupMessage *msg)
gsize size;
const GSList *list;
- list = gda_sql_get_all_connections ();
+ list = t_app_get_all_connections ();
if (list && !list->next) {
/* only 1 connection => go to this one */
- ConnectionSetting *cs = (ConnectionSetting*) list->data;
+ TConnection *tcnc = (TConnection*) list->data;
soup_message_set_status (msg, SOUP_STATUS_TEMPORARY_REDIRECT);
- soup_message_headers_append (msg->response_headers, "Location", cs->name);
+ soup_message_headers_append (msg->response_headers, "Location", t_connection_get_name (tcnc));
return;
}
else if (list) {
/* more than one connection, redirect to the current one */
- const ConnectionSetting *cs = gda_sql_get_current_connection ();
+ TConnection *tcnc = t_context_get_connection (t_app_get_term_console ());
soup_message_set_status (msg, SOUP_STATUS_TEMPORARY_REDIRECT);
- soup_message_headers_append (msg->response_headers, "Location", cs->name);
+ soup_message_headers_append (msg->response_headers, "Location", t_connection_get_name (tcnc));
return;
}
@@ -699,7 +627,7 @@ get_root (WebServer *server, SoupMessage *msg)
}
static xmlNodePtr
-cnc_ul (gboolean is_authenticated)
+cnc_ul (WebServer *server, gboolean is_authenticated)
{
xmlNodePtr ul, li, a;
const GSList *clist, *list;
@@ -707,7 +635,7 @@ cnc_ul (gboolean is_authenticated)
/* other connections in the sidebar */
if (is_authenticated)
- list = gda_sql_get_all_connections ();
+ list = t_app_get_all_connections ();
else
list = NULL;
ul = xmlNewNode (NULL, BAD_CAST "ul");
@@ -724,11 +652,11 @@ cnc_ul (gboolean is_authenticated)
else {
for (clist = list; clist; clist = clist->next) {
gchar *tmp;
- ConnectionSetting *cs2 = (ConnectionSetting*) clist->data;
+ TConnection *tcnc2 = (TConnection*) clist->data;
li = xmlNewChild (ul, NULL, BAD_CAST "li", NULL);
- a = xmlNewChild (li, NULL, BAD_CAST "a", BAD_CAST cs2->name);
- tmp = gda_rfc1738_encode (cs2->name);
+ a = xmlNewChild (li, NULL, BAD_CAST "a", BAD_CAST t_connection_get_name (tcnc2));
+ tmp = gda_rfc1738_encode (t_connection_get_name (tcnc2));
str = g_strdup_printf ("/%s", tmp);
g_free (tmp);
xmlSetProp (a, BAD_CAST "href", BAD_CAST str);
@@ -739,12 +667,12 @@ cnc_ul (gboolean is_authenticated)
}
static void
-get_for_cnclist (G_GNUC_UNUSED WebServer *webserver, SoupMessage *msg, gboolean is_authenticated)
+get_for_cnclist (WebServer *webserver, SoupMessage *msg, gboolean is_authenticated)
{
xmlNodePtr ul;
SoupBuffer *buffer;
- ul = cnc_ul (is_authenticated);
+ ul = cnc_ul (webserver, is_authenticated);
soup_message_headers_replace (msg->response_headers,
"Content-Type", "text/html");
@@ -790,15 +718,15 @@ get_for_console (WebServer *server, SoupMessage *msg)
xmlSetProp (div, BAD_CAST "id", BAD_CAST "irb_input");
xmlSetProp (div, BAD_CAST "autocomplete", BAD_CAST "off");
- node = xmlNewChild (hdoc->head, NULL, BAD_CAST "script", BAD_CAST "");
+ node = xmlNewChild (hdoc->head, NULL, BAD_CAST "script", BAD_CAST " ");
xmlSetProp (node, BAD_CAST "type", BAD_CAST "text/javascript");
xmlSetProp (node, BAD_CAST "src", BAD_CAST "/jquery.js");
- node = xmlNewChild (hdoc->head, NULL, BAD_CAST "script", BAD_CAST "");
+ node = xmlNewChild (hdoc->head, NULL, BAD_CAST "script", BAD_CAST " ");
xmlSetProp (node, BAD_CAST "type", BAD_CAST "text/javascript");
xmlSetProp (node, BAD_CAST "src", BAD_CAST "/jquery-ui.js");
- node = xmlNewChild (hdoc->head, NULL, BAD_CAST "script", BAD_CAST "");
+ node = xmlNewChild (hdoc->head, NULL, BAD_CAST "script", BAD_CAST " ");
xmlSetProp (node, BAD_CAST "type", BAD_CAST "text/javascript");
xmlSetProp (node, BAD_CAST "src", BAD_CAST "/mouseapp_2.js");
@@ -806,11 +734,11 @@ get_for_console (WebServer *server, SoupMessage *msg)
xmlSetProp (node, BAD_CAST "type", BAD_CAST "text/javascript");
xmlSetProp (node, BAD_CAST "src", BAD_CAST "/mouseirb_2.js");
- node = xmlNewChild (hdoc->head, NULL, BAD_CAST "script", BAD_CAST "");
+ node = xmlNewChild (hdoc->head, NULL, BAD_CAST "script", BAD_CAST " ");
xmlSetProp (node, BAD_CAST "type", BAD_CAST "text/javascript");
xmlSetProp (node, BAD_CAST "src", BAD_CAST "/irb.js");
- node = xmlNewChild (hdoc->head, NULL, BAD_CAST "script", BAD_CAST "");
+ node = xmlNewChild (hdoc->head, NULL, BAD_CAST "script", BAD_CAST " ");
xmlSetProp (node, BAD_CAST "type", BAD_CAST "text/javascript");
xmlSetProp (node, BAD_CAST "src", BAD_CAST "/cnc.js");
@@ -830,21 +758,21 @@ get_for_console (WebServer *server, SoupMessage *msg)
soup_message_set_status (msg, SOUP_STATUS_OK);
}
-static gboolean compute_all_objects_content (HtmlDoc *hdoc, const ConnectionSetting *cs,
+static gboolean compute_all_objects_content (HtmlDoc *hdoc, TConnection *tcnc,
const gchar *human_obj_type,
const gchar *human_obj_type_in_schema,
const gchar *table_name,
const gchar *obj_prefix,
const gchar *filter,
GError **error);
-static gboolean compute_all_triggers_content (HtmlDoc *hdoc, const ConnectionSetting *cs, GError **error);
-static gboolean compute_object_content (HtmlDoc *hdoc, WebServer *webserver, const ConnectionSetting *cs,
+static gboolean compute_all_triggers_content (HtmlDoc *hdoc, TConnection *tcnc, GError **error);
+static gboolean compute_object_content (HtmlDoc *hdoc, WebServer *webserver, TConnection *tcnc,
const gchar *schema, const gchar *name, GError **error);
/*
* GET method for a connection
*/
static gboolean
-get_for_cnc (WebServer *webserver, SoupMessage *msg, const ConnectionSetting *cs, gchar **extra, GError
**error)
+get_for_cnc (WebServer *webserver, SoupMessage *msg, TConnection *tcnc, gchar **extra, GError **error)
{
gboolean retval = FALSE;
HtmlDoc *hdoc;
@@ -852,28 +780,28 @@ get_for_cnc (WebServer *webserver, SoupMessage *msg, const ConnectionSetting *cs
SoupBuffer *buffer;
gsize size;
- hdoc = create_new_htmldoc (webserver, cs);
+ hdoc = create_new_htmldoc (webserver, tcnc);
if (!extra || !strcmp (extra[0], "~tables")) {
- if (! compute_all_objects_content (hdoc, cs,
+ if (! compute_all_objects_content (hdoc, tcnc,
_("Tables"), _("Tables in the '%s' schema"),
"_tables", "table", "table_type LIKE \"%TABLE%\"", error))
goto onerror;
}
else if (!strcmp (extra[0], "~views")) {
- if (! compute_all_objects_content (hdoc, cs,
+ if (! compute_all_objects_content (hdoc, tcnc,
_("Views"), _("Views in the '%s' schema"),
"_tables", "table", "table_type LIKE \"%VIEW%\"", error))
goto onerror;
}
else if (!strcmp (extra[0], "~triggers")) {
- if (! compute_all_triggers_content (hdoc, cs, error))
+ if (! compute_all_triggers_content (hdoc, tcnc, error))
goto onerror;
}
else {
/* extra [0] has to be a schema */
if (extra [1]) {
- if (! compute_object_content (hdoc, webserver, cs, extra [0], extra [1], error))
+ if (! compute_object_content (hdoc, webserver, tcnc, extra [0], extra [1], error))
goto onerror;
}
else
@@ -909,10 +837,10 @@ meta_table_column_foreach_attribute_func (const gchar *att_name, const GValue *v
}
}
-static gchar *meta_struct_dump_as_graph (const ConnectionSetting *cs, GdaMetaStruct *mstruct,
+static gchar *meta_struct_dump_as_graph (TConnection *tcnc, GdaMetaStruct *mstruct,
GdaMetaDbObject *central_dbo, GError **error);
static gboolean
-compute_table_details (const ConnectionSetting *cs, HtmlDoc *hdoc, WebServer *webserver,
+compute_table_details (TConnection *tcnc, HtmlDoc *hdoc, WebServer *webserver,
GdaMetaStruct *mstruct, GdaMetaDbObject *dbo, GError **error)
{
gchar *tmp;
@@ -1017,7 +945,7 @@ compute_table_details (const ConnectionSetting *cs, HtmlDoc *hdoc, WebServer *we
/* create a graph */
gchar *graph, *tmp_filename = NULL;
xmlNodePtr map_node = NULL;
- graph = meta_struct_dump_as_graph (cs, mstruct, dbo, NULL);
+ graph = meta_struct_dump_as_graph (tcnc, mstruct, dbo, NULL);
if (graph) {
gchar *dotname, *suffix;
static gint counter = 0;
@@ -1124,7 +1052,7 @@ compute_table_details (const ConnectionSetting *cs, HtmlDoc *hdoc, WebServer *we
* Returns: a new string, or %NULL if an error occurred.
*/
static gchar *
-meta_struct_dump_as_graph (const ConnectionSetting *cs, GdaMetaStruct *mstruct, GdaMetaDbObject
*central_dbo,
+meta_struct_dump_as_graph (TConnection *tcnc, GdaMetaStruct *mstruct, GdaMetaDbObject *central_dbo,
G_GNUC_UNUSED GError **error)
{
GString *string;
@@ -1133,7 +1061,7 @@ meta_struct_dump_as_graph (const ConnectionSetting *cs, GdaMetaStruct *mstruct,
g_return_val_if_fail (GDA_IS_META_STRUCT (mstruct), NULL);
- rfc_cnc_name = gda_rfc1738_encode (cs->name);
+ rfc_cnc_name = gda_rfc1738_encode (t_connection_get_name (tcnc));
string = g_string_new ("digraph G {\nrankdir = LR;\ndpi = 70;\nfontname = Helvetica;\nnode [shape =
plaintext];\n");
GSList *dbo_list, *list;
@@ -1269,7 +1197,7 @@ meta_struct_dump_as_graph (const ConnectionSetting *cs, GdaMetaStruct *mstruct,
}
static gboolean
-compute_view_details (G_GNUC_UNUSED const ConnectionSetting *cs, HtmlDoc *hdoc,
+compute_view_details (G_GNUC_UNUSED TConnection *tcnc, HtmlDoc *hdoc,
G_GNUC_UNUSED GdaMetaStruct *mstruct, GdaMetaDbObject *dbo,
G_GNUC_UNUSED GError **error)
{
@@ -1290,7 +1218,7 @@ compute_view_details (G_GNUC_UNUSED const ConnectionSetting *cs, HtmlDoc *hdoc,
* Returns: TRUE if the object was really a trigger
*/
static gboolean
-compute_trigger_content (HtmlDoc *hdoc, G_GNUC_UNUSED WebServer *webserver, const ConnectionSetting *cs,
+compute_trigger_content (HtmlDoc *hdoc, G_GNUC_UNUSED WebServer *webserver, TConnection *tcnc,
const gchar *schema, const gchar *name, GError **error)
{
GdaMetaStore *store;
@@ -1300,7 +1228,7 @@ compute_trigger_content (HtmlDoc *hdoc, G_GNUC_UNUSED WebServer *webserver, cons
gint i, nrows;
xmlNodePtr code, div = NULL, sdiv, ul, li;
- store = gda_connection_get_meta_store (cs->cnc);
+ store = gda_connection_get_meta_store (t_connection_get_cnc (tcnc));
g_value_set_string ((v0 = gda_value_new (G_TYPE_STRING)), schema);
g_value_set_string ((v1 = gda_value_new (G_TYPE_STRING)), name);
model = gda_meta_store_extract (store, "SELECT trigger_short_name, action_statement,
event_manipulation, "
@@ -1393,7 +1321,7 @@ compute_trigger_content (HtmlDoc *hdoc, G_GNUC_UNUSED WebServer *webserver, cons
* Give details about a database object
*/
static gboolean
-compute_object_content (HtmlDoc *hdoc, WebServer *webserver, const ConnectionSetting *cs,
+compute_object_content (HtmlDoc *hdoc, WebServer *webserver, TConnection *tcnc,
const gchar *schema, const gchar *name, GError **error)
{
GdaMetaStruct *mstruct;
@@ -1402,17 +1330,17 @@ compute_object_content (HtmlDoc *hdoc, WebServer *webserver, const ConnectionSet
gboolean retval;
g_value_take_string ((v0 = gda_value_new (G_TYPE_STRING)),
- gda_sql_identifier_quote (schema, cs->cnc, NULL, FALSE, FALSE));
+ gda_sql_identifier_quote (schema, t_connection_get_cnc (tcnc), NULL, FALSE,
FALSE));
g_value_take_string ((v1 = gda_value_new (G_TYPE_STRING)),
- gda_sql_identifier_quote (name, cs->cnc, NULL, FALSE, FALSE));
+ gda_sql_identifier_quote (name, t_connection_get_cnc (tcnc), NULL, FALSE,
FALSE));
- mstruct = gda_meta_struct_new (gda_connection_get_meta_store (cs->cnc),
+ mstruct = gda_meta_struct_new (gda_connection_get_meta_store (t_connection_get_cnc (tcnc)),
GDA_META_STRUCT_FEATURE_ALL);
dbo = gda_meta_struct_complement (mstruct, GDA_META_DB_UNKNOWN, NULL, v0, v1, error);
gda_value_free (v0);
gda_value_free (v1);
if (!dbo) {
- if (compute_trigger_content (hdoc, webserver, cs, schema, name, error))
+ if (compute_trigger_content (hdoc, webserver, tcnc, schema, name, error))
return TRUE;
TO_IMPLEMENT;
return FALSE;
@@ -1420,12 +1348,12 @@ compute_object_content (HtmlDoc *hdoc, WebServer *webserver, const ConnectionSet
switch (dbo->obj_type) {
case GDA_META_DB_TABLE:
- retval = compute_table_details (cs, hdoc, webserver, mstruct, dbo, error);
+ retval = compute_table_details (tcnc, hdoc, webserver, mstruct, dbo, error);
break;
case GDA_META_DB_VIEW:
- retval = compute_table_details (cs, hdoc, webserver, mstruct, dbo, error);
+ retval = compute_table_details (tcnc, hdoc, webserver, mstruct, dbo, error);
if (retval)
- retval = compute_view_details (cs, hdoc, mstruct, dbo, error);
+ retval = compute_view_details (tcnc, hdoc, mstruct, dbo, error);
break;
default:
TO_IMPLEMENT;
@@ -1439,7 +1367,7 @@ compute_object_content (HtmlDoc *hdoc, WebServer *webserver, const ConnectionSet
* Lists all objects of a type (tables, view, ...)
*/
static gboolean
-compute_all_objects_content (HtmlDoc *hdoc, const ConnectionSetting *cs,
+compute_all_objects_content (HtmlDoc *hdoc, TConnection *tcnc,
const gchar *human_obj_type,
const gchar *human_obj_type_in_schema,
const gchar *table_name,
@@ -1457,9 +1385,9 @@ compute_all_objects_content (HtmlDoc *hdoc, const ConnectionSetting *cs,
xmlNodePtr ul, li, a, div = NULL;
gboolean content_added = FALSE;
- rfc_cnc_name = gda_rfc1738_encode (cs->name);
+ rfc_cnc_name = gda_rfc1738_encode (t_connection_get_name (tcnc));
- store = gda_connection_get_meta_store (cs->cnc);
+ store = gda_connection_get_meta_store (t_connection_get_cnc (tcnc));
/* objects directly accessible */
if (filter)
@@ -1583,7 +1511,7 @@ compute_all_objects_content (HtmlDoc *hdoc, const ConnectionSetting *cs,
* Lists all objects of a type (tables, view, ...)
*/
static gboolean
-compute_all_triggers_content (HtmlDoc *hdoc, const ConnectionSetting *cs, GError **error)
+compute_all_triggers_content (HtmlDoc *hdoc, TConnection *tcnc, GError **error)
{
gboolean retval = FALSE;
gchar *rfc_cnc_name;
@@ -1594,9 +1522,9 @@ compute_all_triggers_content (HtmlDoc *hdoc, const ConnectionSetting *cs, GError
xmlNodePtr sul, li, a, div = NULL, sdiv = NULL;
gboolean content_added = FALSE;
- rfc_cnc_name = gda_rfc1738_encode (cs->name);
+ rfc_cnc_name = gda_rfc1738_encode (t_connection_get_name (tcnc));
- store = gda_connection_get_meta_store (cs->cnc);
+ store = gda_connection_get_meta_store (t_connection_get_cnc (tcnc));
model = gda_meta_store_extract (store, "SELECT trigger_schema, trigger_name, event_manipulation, "
"event_object_schema, event_object_table FROM _triggers WHERE "
@@ -1831,7 +1759,7 @@ get_cookies (SoupMessage *msg, ...)
va_list ap;
gchar *name;
- cookies = soup_message_headers_get (msg->request_headers, "Cookie");
+ cookies = soup_message_headers_get_list (msg->request_headers, "Cookie");
ql = gda_quark_list_new_from_string (cookies);
va_start (ap, msg);
@@ -1850,7 +1778,7 @@ get_cookies (SoupMessage *msg, ...)
}
static HtmlDoc*
-create_new_htmldoc (G_GNUC_UNUSED WebServer *webserver, const ConnectionSetting *cs)
+create_new_htmldoc (WebServer *webserver, TConnection *tcnc)
{
HtmlDoc *hdoc;
gchar *str;
@@ -1859,8 +1787,8 @@ create_new_htmldoc (G_GNUC_UNUSED WebServer *webserver, const ConnectionSetting
xmlNodePtr ul, li, a;
- if (cs) {
- str = g_strdup_printf (_("Database information for '%s'"), cs->name);
+ if (tcnc) {
+ str = g_strdup_printf (_("Database information for '%s'"), t_connection_get_name (tcnc));
hdoc = html_doc_new (str);
g_free (str);
}
@@ -1868,12 +1796,12 @@ create_new_htmldoc (G_GNUC_UNUSED WebServer *webserver, const ConnectionSetting
hdoc = html_doc_new (_("Database information"));
/* other connections in the sidebar */
- ul = cnc_ul (TRUE);
+ ul = cnc_ul (webserver, TRUE);
xmlAddChild (hdoc->sidebar, ul);
/* list all database object's types for which information can be obtained */
- if (cs) {
- rfc_cnc_name = gda_rfc1738_encode (cs->name);
+ if (tcnc) {
+ rfc_cnc_name = gda_rfc1738_encode (t_connection_get_name (tcnc));
ul = xmlNewChild (hdoc->sidebar, NULL, BAD_CAST "ul", BAD_CAST _("Objects"));
li = xmlNewChild (ul, NULL, BAD_CAST "li", NULL);
a = xmlNewChild (li, NULL, BAD_CAST "a", BAD_CAST _("Tables"));
@@ -1910,12 +1838,14 @@ delete_consoles (WebServer *server)
g_get_current_time (&tv);
for (list = server->priv->terminals_list; list; ) {
- SqlConsole *con = (SqlConsole *) list->data;
- if (con->last_time_used.tv_sec + 600 < tv.tv_sec) {
+ TContext *console = (TContext *) list->data;
+ GTimeVal *lastused;
+ lastused = t_context_get_last_time_used (console);
+ if (lastused->tv_sec + 600 < tv.tv_sec) {
GSList *n = list->next;
server->priv->terminals_list = g_slist_delete_link (server->priv->terminals_list,
list);
list = n;
- gda_sql_console_free (con);
+ g_object_unref (G_OBJECT (console));
}
else
list = list->next;
@@ -1928,12 +1858,46 @@ delete_consoles (WebServer *server)
return TRUE;
}
+static gchar *
+gda_sql_console_execute (WebServer *server, TContext *console, const gchar *command, GError **error,
ToolOutputFormat format)
+{
+ gchar *loc_cmde = NULL;
+ gchar *retstr = NULL;
+
+ g_assert (console);
+ loc_cmde = g_strdup (command);
+ g_strchug (loc_cmde);
+ if (*loc_cmde) {
+ if (t_utils_command_is_complete (loc_cmde)) {
+ /* execute command */
+ ToolCommandResult *res;
+
+ res = t_context_command_execute (console, loc_cmde,
+ GDA_STATEMENT_MODEL_RANDOM_ACCESS, error);
+
+ if (res) {
+ retstr = base_tool_output_result_to_string (res, format,
+ t_context_get_output_stream
(console, NULL),
+ t_app_get_options ());
+ base_tool_command_result_free (res);
+ }
+ }
+ else {
+ g_set_error (error, T_ERROR, T_COMMAND_ARGUMENTS_ERROR,
+ "%s", _("Command is incomplete"));
+ }
+ }
+ g_free (loc_cmde);
+
+ return retstr;
+}
+
/*
* GET/POST method for IRB
*/
static gboolean
-get_post_for_irb (WebServer *webserver, SoupMessage *msg, G_GNUC_UNUSED const ConnectionSetting *cs,
+get_post_for_irb (WebServer *webserver, SoupMessage *msg, G_GNUC_UNUSED TConnection *tcnc,
GHashTable *query, G_GNUC_UNUSED GError **error)
{
gboolean retval = FALSE;
@@ -1944,7 +1908,7 @@ get_post_for_irb (WebServer *webserver, SoupMessage *msg, G_GNUC_UNUSED const Co
gchar *cmd;
gchar *cid;
- SqlConsole *console = NULL;
+ TContext *console = NULL;
/* fetch variables */
get_variables (msg, query, "cmd", &cmd, "cid", &cid, NULL);
@@ -1954,8 +1918,10 @@ get_post_for_irb (WebServer *webserver, SoupMessage *msg, G_GNUC_UNUSED const Co
if (cid) {
GSList *list;
for (list = webserver->priv->terminals_list; list; list = list->next) {
- if (((SqlConsole*) list->data)->id && !strcmp (((SqlConsole*) list->data)->id, cid)) {
- console = (SqlConsole*) list->data;
+ const gchar *id;
+ id = t_context_get_id (T_CONTEXT (list->data));
+ if (id && !strcmp (id, cid)) {
+ console = (TContext*) list->data;
break;
}
}
@@ -1965,16 +1931,18 @@ get_post_for_irb (WebServer *webserver, SoupMessage *msg, G_GNUC_UNUSED const Co
if (!cid || !strcmp (cid, "none")) {
gchar *str;
str = g_strdup_printf ("console%d", counter++);
- console = gda_sql_console_new (str);
+ console = T_CONTEXT (t_web_context_new (str));
g_free (str);
}
else {
- console = gda_sql_console_new (cid);
+ console = T_CONTEXT (t_web_context_new (cid));
}
webserver->priv->terminals_list = g_slist_prepend (webserver->priv->terminals_list,
console);
- g_get_current_time (&(console->last_time_used));
+ GTimeVal *lastused;
+ lastused = t_context_get_last_time_used (console);
+ g_get_current_time (lastused);
if (!webserver->priv->term_timer)
webserver->priv->term_timer = g_timeout_add_seconds (5, (GSourceFunc) delete_consoles,
webserver);
@@ -1994,8 +1962,8 @@ get_post_for_irb (WebServer *webserver, SoupMessage *msg, G_GNUC_UNUSED const Co
topnode = xmlNewDocNode (doc, NULL, BAD_CAST "result", NULL);
xmlDocSetRootElement (doc, topnode);
- xmlNewChild (topnode, NULL, BAD_CAST "cid", BAD_CAST (console->id));
- tmp = gda_sql_console_compute_prompt (console, TOOL_OUTPUT_FORMAT_HTML);
+ xmlNewChild (topnode, NULL, BAD_CAST "cid", BAD_CAST (t_context_get_id (console)));
+ tmp = t_utils_compute_prompt (console, FALSE, TRUE, BASE_TOOL_OUTPUT_FORMAT_HTML);
xmlNewChild (topnode, NULL, BAD_CAST "prompt", BAD_CAST tmp);
g_free (tmp);
@@ -2007,7 +1975,9 @@ get_post_for_irb (WebServer *webserver, SoupMessage *msg, G_GNUC_UNUSED const Co
}
/* create response */
- g_get_current_time (&(console->last_time_used));
+ GTimeVal *lastused;
+ lastused = t_context_get_last_time_used (console);
+ g_get_current_time (lastused);
cmd = g_strstrip (cmd);
if (*cmd) {
xmlDocPtr doc;
@@ -2019,7 +1989,7 @@ get_post_for_irb (WebServer *webserver, SoupMessage *msg, G_GNUC_UNUSED const Co
topnode = xmlNewDocNode (doc, NULL, BAD_CAST "result", NULL);
xmlDocSetRootElement (doc, topnode);
- tmp = gda_sql_console_execute (console, cmd, &lerror, TOOL_OUTPUT_FORMAT_HTML);
+ tmp = gda_sql_console_execute (webserver, console, cmd, &lerror,
BASE_TOOL_OUTPUT_FORMAT_HTML);
if (!tmp)
tmp = g_strdup_printf (_("Error: %s"),
lerror && lerror->message ? lerror->message : _("No
detail"));
@@ -2029,7 +1999,7 @@ get_post_for_irb (WebServer *webserver, SoupMessage *msg, G_GNUC_UNUSED const Co
xmlNewChild (topnode, NULL, BAD_CAST "cmde", BAD_CAST tmp);
g_free (tmp);
- tmp = gda_sql_console_compute_prompt (console, TOOL_OUTPUT_FORMAT_HTML);
+ tmp = t_utils_compute_prompt (console, FALSE, TRUE, BASE_TOOL_OUTPUT_FORMAT_HTML);
xmlNewChild (topnode, NULL, BAD_CAST "prompt", BAD_CAST tmp);
g_free (tmp);
diff --git a/tools/web-server.h b/tools/common/web-server.h
similarity index 94%
rename from tools/web-server.h
rename to tools/common/web-server.h
index 1490c13..5721abf 100644
--- a/tools/web-server.h
+++ b/tools/common/web-server.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2008 - 2014 Vivien Malerba <malerba gnome-db org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -20,7 +20,8 @@
#ifndef __WEB_SERVER_H_
#define __WEB_SERVER_H_
-#include "gda-sql.h"
+#include <glib-object.h>
+#include <common/t-decl.h>
G_BEGIN_DECLS
diff --git a/tools/browser/browser-res.rc b/tools/gda-browser-res.rc
similarity index 100%
rename from tools/browser/browser-res.rc
rename to tools/gda-browser-res.rc
diff --git a/tools/misc/Makefile.am b/tools/misc/Makefile.am
new file mode 100644
index 0000000..a661e20
--- /dev/null
+++ b/tools/misc/Makefile.am
@@ -0,0 +1,61 @@
+bin_PROGRAMS = \
+ gda-list-config-6.0 \
+ gda-list-server-op-6.0
+
+
+noinst_PROGRAMS = information-schema-doc information-schema-types
+
+AM_CPPFLAGS = \
+ -I$(top_srcdir) \
+ -I$(top_builddir) \
+ -I$(top_srcdir)/libgda/sqlite \
+ -I$(top_builddir)/libgda/sqlite \
+ -I$(top_srcdir)/libgda \
+ -I$(top_builddir)/libgda \
+ $(ldap_flags) \
+ $(COREDEPS_CFLAGS) \
+ -DROOT_DIR=\""$(top_srcdir)"\"
+
+gda_list_config_6_0_SOURCES = \
+ gda-list-config.c
+
+gda_list_config_6_0_LDADD = \
+ $(top_builddir)/libgda/libgda-6.0.la \
+ $(COREDEPS_LIBS)
+
+gda_list_server_op_6_0_SOURCES = \
+ gda-list-server-op.c \
+ gda-tree-mgr-xml.c \
+ gda-tree-mgr-xml.h
+
+gda_list_server_op_6_0_LDADD = \
+ $(top_builddir)/libgda/libgda-6.0.la \
+ $(COREDEPS_LIBS)
+
+information_schema_doc_SOURCES = \
+ information-schema-doc.c
+
+information_schema_doc_LDADD = \
+ $(top_builddir)/libgda/libgda-6.0.la \
+ $(COREDEPS_LIBS)
+
+information_schema_types_SOURCES = \
+ information-schema-types.c
+
+information_schema_types_LDADD = \
+ $(top_builddir)/libgda/libgda-6.0.la \
+ $(COREDEPS_LIBS)
+
+
+install-exec-hook:
+if DEFAULT_BINARY
+ cd $(DESTDIR)$(bindir) \
+ && rm -f gda-list-config$(EXEEXT) gda-list-server-op$(EXEEXT) \
+ && $(LN_S) gda-list-config-6.0$(EXEEXT) gda-list-config$(EXEEXT) \
+ && $(LN_S) gda-list-server-op-6.0$(EXEEXT) gda-list-server-op$(EXEEXT)
+endif
+
+uninstall-local:
+if DEFAULT_BINARY
+ rm -f $(DESTDIR)$(bindir)/gda-list-config$(EXEEXT) $(DESTDIR)$(bindir)/gda-list-server-op$(EXEEXT)
+endif
diff --git a/tools/gda-list-config.c b/tools/misc/gda-list-config.c
similarity index 100%
rename from tools/gda-list-config.c
rename to tools/misc/gda-list-config.c
diff --git a/tools/gda-list-server-op.c b/tools/misc/gda-list-server-op.c
similarity index 100%
rename from tools/gda-list-server-op.c
rename to tools/misc/gda-list-server-op.c
diff --git a/tools/gda-tree-mgr-xml.c b/tools/misc/gda-tree-mgr-xml.c
similarity index 100%
rename from tools/gda-tree-mgr-xml.c
rename to tools/misc/gda-tree-mgr-xml.c
diff --git a/tools/gda-tree-mgr-xml.h b/tools/misc/gda-tree-mgr-xml.h
similarity index 100%
rename from tools/gda-tree-mgr-xml.h
rename to tools/misc/gda-tree-mgr-xml.h
diff --git a/tools/information-schema-doc.c b/tools/misc/information-schema-doc.c
similarity index 100%
rename from tools/information-schema-doc.c
rename to tools/misc/information-schema-doc.c
diff --git a/tools/information-schema-types.c b/tools/misc/information-schema-types.c
similarity index 100%
rename from tools/information-schema-types.c
rename to tools/misc/information-schema-types.c
diff --git a/tools/tools-main.c b/tools/tools-main.c
new file mode 100644
index 0000000..5ac11a0
--- /dev/null
+++ b/tools/tools-main.c
@@ -0,0 +1,569 @@
+/*
+ * Copyright (C) 2007 - 2014 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2008 Murray Cumming <murrayc murrayc com>
+ * Copyright (C) 2008 Nathan <nbinont yahoo ca>
+ * Copyright (C) 2009 Bas Driessen <bas driessen xobas com>
+ * Copyright (C) 2010 David King <davidk openismus com>
+ * Copyright (C) 2012 Daniel Mustieles <daniel mustieles gmail com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include <virtual/libgda-virtual.h>
+#include <glib/gi18n-lib.h>
+#include <glib/gprintf.h>
+#include <string.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <glib/gstdio.h>
+#include "base/base-tool-input.h"
+#include "base/base-tool-output.h"
+#include "common/t-app.h"
+#include "common/t-utils.h"
+#include "common/t-config-info.h"
+#include "common/t-term-context.h"
+#include <unistd.h>
+#ifdef HAVE_TERMIOS_H
+#include <termios.h>
+#endif
+#include <sys/types.h>
+#include <libgda/gda-quark-list.h>
+#include <libgda/gda-meta-struct.h>
+#include <libgda/gda-blob-op.h>
+#include <thread-wrapper/gda-connect.h>
+#include <sql-parser/gda-sql-parser.h>
+#ifdef HAVE_LOCALE_H
+ #include <locale.h>
+#endif
+
+#ifndef G_OS_WIN32
+ #include <signal.h>
+ typedef void (*sighandler_t)(int);
+ #include <pwd.h>
+#else
+ #include <stdlib.h>
+ #include <windows.h>
+#endif
+
+#ifdef HAVE_READLINE
+ #include <readline/readline.h>
+#endif
+
+#ifdef HAVE_LIBSOUP
+ #include "web-server.h"
+#endif
+
+#ifdef IS_BROWSER
+ #include <libgda-ui/libgda-ui.h>
+ #include <browser/browser-window.h>
+#endif
+
+/* options */
+gboolean show_version = FALSE;
+
+gchar *single_command = NULL;
+gchar *commandsfile = NULL;
+gboolean interactive = FALSE;
+
+gboolean list_configs = FALSE;
+gboolean list_providers = FALSE;
+
+gboolean list_data_files = FALSE;
+gchar *purge_data_files = NULL;
+
+gchar *outfile = NULL;
+#ifdef IS_BROWSER
+ gchar *perspective = NULL;
+#endif
+
+#ifdef HAVE_LIBSOUP
+gint http_port = -1;
+gchar *auth_token = NULL;
+#endif
+
+static GOptionEntry entries[] = {
+ { "version", 'v', 0, G_OPTION_ARG_NONE, &show_version, "Show version information and exit", NULL },
+ { "output-file", 'o', 0, G_OPTION_ARG_STRING, &outfile, "Output file", "output file"},
+ { "command", 'C', 0, G_OPTION_ARG_STRING, &single_command, "Run only single command (SQL or
internal) and exit", "command" },
+ { "commands-file", 'f', 0, G_OPTION_ARG_STRING, &commandsfile, "Execute commands from file, then
exit (except if -i specified)", "filename" },
+ { "interactive", 'i', 0, G_OPTION_ARG_NONE, &interactive, "Keep the console opened", NULL },
+ { "list-dsn", 'l', 0, G_OPTION_ARG_NONE, &list_configs, "List configured data sources and exit",
NULL },
+ { "list-providers", 'L', 0, G_OPTION_ARG_NONE, &list_providers, "List installed database providers
and exit", NULL },
+#ifdef HAVE_LIBSOUP
+ { "http-port", 's', 0, G_OPTION_ARG_INT, &http_port, "Run embedded HTTP server on specified port",
"port" },
+ { "http-token", 't', 0, G_OPTION_ARG_STRING, &auth_token, "Authentication token (required to
authenticate clients)", "token phrase" },
+#endif
+ { "data-files-list", 0, 0, G_OPTION_ARG_NONE, &list_data_files, "List files used to hold information
related to each connection", NULL },
+ { "data-files-purge", 0, 0, G_OPTION_ARG_STRING, &purge_data_files, "Remove some files used to hold
information related to each connection. Criteria has to be in 'all', 'non-dsn', or 'non-exist-dsn'",
"criteria"},
+#ifdef IS_BROWSER
+ { "perspective", 'p', 0, G_OPTION_ARG_STRING, &perspective, "Perspective", "default perspective "
+ "to use when opening windows"},
+#endif
+ { NULL, 0, 0, 0, NULL, NULL, NULL }
+};
+
+
+static void output_data_model (TContext *console, GdaDataModel *model);
+
+static gboolean
+ticker (G_GNUC_UNUSED gpointer data)
+{
+ static int pos=0;
+ char cursor[4]={'/','-','\\','|'};
+ printf("%c\b", cursor[pos]);
+ fflush(stdout);
+ pos = (pos+1) % 4;
+ return G_SOURCE_CONTINUE;
+}
+
+static void
+cnc_status_changed_cb (TConnection *tcnc, GdaConnectionStatus status, gpointer data)
+{
+ TContext *term_console;
+ term_console = t_app_get_term_console ();
+ if (!term_console || (t_context_get_connection (term_console) != tcnc))
+ return;
+
+#ifdef DEBUG_NO
+ gchar *status_str[] = {
+ "CLOSED",
+ "OPENING",
+ "IDLE",
+ "BUSY"
+ };
+ g_print ("Status is now %s\n", status_str [status]);
+#endif
+ static guint source_id = 0;
+ static GMutex mutex;
+ g_mutex_lock (&mutex);
+ if (status == GDA_CONNECTION_STATUS_BUSY) {
+ if (source_id == 0)
+ source_id = g_timeout_add (100, (GSourceFunc) ticker, NULL);
+ }
+ else if (source_id > 0) {
+ g_source_remove (source_id);
+ source_id = 0;
+ }
+ g_mutex_unlock (&mutex);
+}
+
+static void
+free_strings_array (GArray *array)
+{
+ guint i;
+ for (i = 0; i < array->len; i++) {
+ gchar *str;
+ str = g_array_index (array, gchar*, i);
+ g_free (str);
+ }
+ g_array_free (array, TRUE);
+}
+
+static void
+cnc_added_cb (TApp *app, TConnection *tcnc)
+{
+ gda_signal_connect (tcnc, "status-changed",
+ G_CALLBACK (cnc_status_changed_cb), NULL,
+ NULL, 0, NULL);
+
+}
+
+GThread *term_console_thread = NULL;
+static int
+command_line (GApplication *application, GApplicationCommandLine *cmdline)
+{
+ gchar **argv;
+ int argc;
+ argv = g_application_command_line_get_arguments (cmdline, &argc);
+
+ GOptionContext *context;
+ GError *error = NULL;
+ int exit_status = EXIT_SUCCESS;
+ gboolean is_interactive = TRUE; /* final interactivity status */
+#ifdef IS_BROWSER
+ is_interactive = FALSE;
+#else
+ t_app_add_feature (T_APP_TERM_CONSOLE);
+#endif
+
+ /* options parsing */
+ context = g_option_context_new (_("[DSN|connection string]..."));
+ g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
+ g_option_context_set_ignore_unknown_options (context, TRUE);
+ if (!g_option_context_parse (context, &argc, &argv, &error)) {
+ g_fprintf (stderr, "Can't parse arguments: %s\n", error->message);
+ exit_status = EXIT_FAILURE;
+ goto out;
+ }
+ g_option_context_free (context);
+
+ if (show_version) {
+ g_application_command_line_print (cmdline, _("GDA SQL console version " PACKAGE_VERSION
"\n"));
+ goto out;
+ }
+
+ /* compute final interactivity status */
+ if (interactive)
+ is_interactive = TRUE;
+ if (list_providers ||
+ list_configs ||
+ list_data_files ||
+ purge_data_files)
+ is_interactive = FALSE;
+ if (is_interactive)
+ t_app_add_feature (T_APP_TERM_CONSOLE);
+
+ TContext *term_console;
+ FILE *ostream = NULL;
+ term_console = t_app_get_term_console ();
+ if (term_console) {
+ t_term_context_set_interactive (T_TERM_CONTEXT (term_console), is_interactive);
+
+ /* output file */
+ if (outfile) {
+ if (! t_context_set_output_file (term_console, outfile, &error)) {
+ g_print ("Can't set output file as '%s': %s\n", outfile,
+ error->message);
+ exit_status = EXIT_FAILURE;
+ goto out;
+ }
+ }
+
+ ostream = t_context_get_output_stream (term_console, NULL);
+ }
+
+ /* welcome message */
+ if (is_interactive && !ostream) {
+#ifdef G_OS_WIN32
+ HANDLE wHnd;
+ SMALL_RECT windowSize = {0, 0, 139, 49};
+
+ wHnd = GetStdHandle(STD_OUTPUT_HANDLE);
+
+ SetConsoleTitle ("GDA SQL console, version " PACKAGE_VERSION);
+ SetConsoleWindowInfo (wHnd, TRUE, &windowSize);
+#endif
+ gchar *c1, *c2, *c3, *c4;
+ ToolOutputFormat oformat = BASE_TOOL_OUTPUT_FORMAT_DEFAULT;
+ if (term_console)
+ oformat = t_context_get_output_format (term_console);
+
+#ifdef IS_BROWSER
+ #define PRGNAME "Gda Browser"
+#else
+ #define PRGNAME "Gda SQL"
+#endif
+ base_tool_output_color_print (BASE_TOOL_COLOR_BOLD, oformat,
+ _("Welcome to the " PRGNAME " console, version "
PACKAGE_VERSION));
+ g_print ("\n\n");
+ c1 = base_tool_output_color_string (BASE_TOOL_COLOR_BOLD, oformat, ".copyright");
+ c2 = base_tool_output_color_string (BASE_TOOL_COLOR_BOLD, oformat, ".?");
+ c3 = base_tool_output_color_string (BASE_TOOL_COLOR_BOLD, oformat, ".help");
+ c4 = base_tool_output_color_string (BASE_TOOL_COLOR_BOLD, oformat, ".q");
+ g_print (_("Type: %s to show usage and distribution terms\n"
+ " %s or %s for help with internal commands\n"
+ " %s (or CTRL-D) to quit (the '.' can be replaced by a '\\')\n"
+ " or any SQL query terminated by a semicolon\n\n"), c1, c2, c3, c4);
+ g_free (c1);
+ g_free (c2);
+ g_free (c3);
+ g_free (c4);
+ }
+
+ /* Handle command line options to display some information */
+ if (list_providers) {
+ if (argc == 2) {
+ single_command = g_strdup_printf (".L %s", argv[1]);
+ argc = 1;
+ }
+ else {
+ GdaDataModel *model = t_config_info_list_all_providers ();
+ output_data_model (term_console, model);
+ g_object_unref (model);
+ }
+ }
+ if (list_configs) {
+ if (argc == 2) {
+ single_command = g_strdup_printf (".l %s", argv[1]);
+ argc = 1;
+ }
+ else {
+ GdaDataModel *model = t_config_info_list_all_dsn ();
+ output_data_model (term_console, model);
+ g_object_unref (model);
+ }
+ }
+ if (list_data_files) {
+ gchar *confdir;
+ GdaDataModel *model;
+
+ confdir = t_config_info_compute_dict_directory ();
+ g_print (_("All files are in the directory: %s\n"), confdir);
+ g_free (confdir);
+ model = t_config_info_list_data_files (&error);
+ if (model) {
+ output_data_model (term_console, model);
+ g_object_unref (model);
+ }
+ else
+ g_print (_("Can't get the list of files used to store information about each
connection: %s\n"),
+ error->message);
+ }
+
+ if (purge_data_files) {
+ gchar *tmp;
+ tmp = t_config_info_purge_data_files (purge_data_files, &error);
+ if (tmp) {
+ base_tool_output_output_string (ostream, tmp);
+ g_free (tmp);
+ }
+ if (error)
+ g_print (_("Error while purging files used to store information about each
connection: %s\n"),
+ error->message);
+ }
+
+ if (term_console) {
+ /* commands file */
+ if (commandsfile) {
+ if (! t_term_context_set_input_file (T_TERM_CONTEXT (term_console), commandsfile,
&error)) {
+ g_print ("Can't read file '%s': %s\n", commandsfile,
+ error->message);
+ exit_status = EXIT_FAILURE;
+ goto out;
+ }
+ }
+ else {
+ /* check if stdin is a term */
+ if (!isatty (fileno (stdin)))
+ t_term_context_set_input_stream (T_TERM_CONTEXT (term_console), stdin);
+ }
+ }
+
+ /* recreating an argv[] array, one entry per connection to open, and we don't want to include there
+ * any SHEBANG command file */
+ GArray *array;
+ array = g_array_new (FALSE, FALSE, sizeof (gchar *));
+#define SHEBANG "#!"
+#define SHEBANGLEN 2
+ gint i = 0;
+ gboolean has_sh_arg = FALSE;
+ for (i = 1; i < argc; i++) { /* we don't want argv[0] which is the program name */
+ /* Check if argv[i] corresponds to a file starting with SHEBANG */
+ FILE *file;
+ gboolean arg_is_cncname = TRUE;
+ file = fopen (argv[i], "r");
+ if (file) {
+ char buffer [SHEBANGLEN + 1];
+ size_t nread;
+ nread = fread (buffer, 1, SHEBANGLEN, file);
+ if (nread == SHEBANGLEN) {
+ buffer [SHEBANGLEN] = 0;
+ if (!strcmp (buffer, SHEBANG)) {
+ if (has_sh_arg) {
+ g_print (_("More than one file to execute\n"));
+ exit_status = EXIT_FAILURE;
+ fclose (file);
+ free_strings_array (array);
+ goto out;
+ }
+
+ if (! t_term_context_set_input_file (T_TERM_CONTEXT (term_console),
+ argv[i], &error)) {
+ g_print (_("Can't read file '%s': %s\n"), commandsfile,
+ error->message);
+ exit_status = EXIT_FAILURE;
+ fclose (file);
+ free_strings_array (array);
+ goto out;
+ }
+ fclose (file);
+ has_sh_arg = TRUE;
+ arg_is_cncname = FALSE;
+ }
+ }
+ fclose (file);
+ }
+
+ if (arg_is_cncname) {
+ gchar *tmp;
+ tmp = g_strdup (argv[i]);
+ g_array_append_val (array, tmp);
+ t_config_info_modify_argv (argv[i]);
+ }
+ }
+
+ if (getenv ("GDA_SQL_CNC")) {
+ const gchar *cncname;
+ cncname = getenv ("GDA_SQL_CNC");
+ g_array_append_val (array, cncname);
+ }
+
+ gda_signal_connect (application, "connection-added",
+ G_CALLBACK (cnc_added_cb), NULL,
+ NULL, 0, NULL);
+
+ /* open connections if specified */
+ if (! t_app_open_connections (array->len, (const gchar **) array->data, &error)) {
+ g_print (_("Error opening connection: %s\n"), error && error->message ? error->message :
_("No detail"));
+ g_clear_error (&error);
+ exit_status = EXIT_FAILURE;
+ free_strings_array (array);
+ goto out;
+ }
+
+ if (term_console) {
+ GSList *cnclist;
+ cnclist = (GSList*) t_app_get_all_connections ();
+ if (cnclist) {
+ cnclist = g_slist_last (cnclist);
+ t_context_set_connection (term_console, T_CONNECTION (cnclist->data));
+ }
+ }
+
+ free_strings_array (array);
+ array = NULL;
+
+#ifdef HAVE_LIBSOUP
+ /* start HTTP server if requested */
+ /* FIXME: create a new TContext for that web server in another thread */
+ if (http_port > 0) {
+ GError *lerror = NULL;
+ if (! t_app_start_http_server (http_port, auth_token, &lerror)) {
+ g_print (_("Can't run HTTP server on port %d: %s\n"),
+ http_port, lerror && lerror->message ? lerror->message : _("No detail"));
+ exit_status = EXIT_FAILURE;
+ goto out;
+ }
+ }
+#endif
+
+ /* process commands which need to be executed as specified by the command line args */
+ if (single_command) {
+ is_interactive = FALSE;
+ t_term_context_treat_single_line (T_TERM_CONTEXT (term_console), single_command);
+ if (!ostream)
+ g_print ("\n");
+ }
+
+ if (term_console)
+ term_console_thread = t_context_run (term_console);
+
+#ifdef IS_BROWSER
+ GtkBuilder *builder;
+ builder = gtk_builder_new ();
+ gtk_builder_add_from_string (builder,
+ "<interface>"
+ " <menu id='app-menu'>"
+ " <section>"
+ " <item>"
+ " <attribute name='label' translatable='yes'>_New
Window</attribute>"
+ " <attribute name='action'>app.new</attribute>"
+ " <attribute name='accel'><Primary>n</attribute>"
+ " </item>"
+ " </section>"
+ " <section>"
+ " <item>"
+ " <attribute name='label' translatable='yes'>_About
Bloatpad</attribute>"
+ " <attribute name='action'>app.about</attribute>"
+ " </item>"
+ " </section>"
+ " <section>"
+ " <item>"
+ " <attribute name='label' translatable='yes'>_Quit</attribute>"
+ " <attribute name='action'>app.quit</attribute>"
+ " <attribute name='accel'><Primary>q</attribute>"
+ " </item>"
+ " </section>"
+ " </menu>"
+ " <menu id='menubar'>"
+ " <submenu label='_Edit'>"
+ " <item label='_Copy' action='win.copy'/>"
+ " <item label='_Paste' action='win.paste'/>"
+ " </submenu>"
+ " </menu>"
+ "</interface>", -1, NULL);
+ gtk_application_set_app_menu (GTK_APPLICATION (t_app_get ()),
+ G_MENU_MODEL (gtk_builder_get_object (builder, "app-menu")));
+ gtk_application_set_menubar (GTK_APPLICATION (t_app_get ()),
+ G_MENU_MODEL (gtk_builder_get_object (builder, "menubar")));
+ g_object_unref (builder);
+
+ t_app_add_feature (T_APP_BROWSER);
+#endif
+
+ out:
+ g_strfreev (argv);
+ return exit_status;
+}
+
+int
+main (int argc, char *argv[])
+{
+ g_setenv ("GDA_CONFIG_SYNCHRONOUS", "1", TRUE);
+ setlocale (LC_ALL, "");
+ gda_init ();
+
+ GMainContext *mcontext;
+ mcontext = g_main_context_ref_thread_default ();
+ g_main_context_acquire (mcontext); /* the current thread owns the default GMainContext */
+ gda_connection_set_main_context (NULL, NULL, mcontext);
+ g_main_context_unref (mcontext);
+
+#ifdef IS_BROWSER
+ gtk_init (&argc, &argv);
+ gdaui_init ();
+
+ #ifdef HAVE_MAC_INTEGRATION
+ theApp = g_object_new (GTK_TYPE_OSX_APPLICATION, NULL);
+ #endif
+#endif
+
+ g_set_application_name ("Bloatpad");
+
+ /* TApp initialization */
+ GApplication *app;
+ t_app_setup (T_APP_NO_FEATURE);
+ app = G_APPLICATION (t_app_get ());
+
+ g_application_set_inactivity_timeout (app, 0);
+ g_signal_connect (app, "command-line", G_CALLBACK (command_line), NULL);
+
+ g_application_run (app, argc, argv);
+
+ /* cleanups */
+ if (term_console_thread)
+ g_thread_join (term_console_thread);
+ t_app_cleanup ();
+
+ return EXIT_SUCCESS;
+}
+
+/*
+ * Dumps the data model contents onto @data->output
+ */
+static void
+output_data_model (TContext *console, GdaDataModel *model)
+{
+ gchar *str;
+ FILE *ostream;
+ ToolOutputFormat oformat;
+ ostream = t_context_get_output_stream (console, NULL);
+ oformat = t_context_get_output_format (console);
+ str = base_tool_output_data_model_to_string (model, oformat, ostream, t_app_get_options ());
+ base_tool_output_output_string (ostream, str);
+ g_free (str);
+ t_app_store_data_model (model, T_LAST_DATA_MODEL_NAME);
+}
diff --git a/tools/tools.gresource.xml b/tools/tools.gresource.xml
new file mode 100644
index 0000000..f856e1a
--- /dev/null
+++ b/tools/tools.gresource.xml
@@ -0,0 +1,90 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+ <gresource prefix="/images">
+ <file compressed="no">gda-browser-action.png</file>
+ </gresource>
+ <gresource prefix="/images">
+ <file compressed="no">gda-browser-auth-big.png</file>
+ </gresource>
+ <gresource prefix="/images">
+ <file compressed="no">gda-browser-auth.png</file>
+ </gresource>
+ <gresource prefix="/images">
+ <file compressed="no">gda-browser-bookmark.png</file>
+ </gresource>
+ <gresource prefix="/images">
+ <file compressed="no">gda-browser-column-fknn.png</file>
+ </gresource>
+ <gresource prefix="/images">
+ <file compressed="no">gda-browser-column-fk.png</file>
+ </gresource>
+ <gresource prefix="/images">
+ <file compressed="no">gda-browser-column-nn.png</file>
+ </gresource>
+ <gresource prefix="/images">
+ <file compressed="no">gda-browser-column-pk.png</file>
+ </gresource>
+ <gresource prefix="/images">
+ <file compressed="no">gda-browser-column.png</file>
+ </gresource>
+ <gresource prefix="/images">
+ <file compressed="no">gda-browser-connected-big.png</file>
+ </gresource>
+ <gresource prefix="/images">
+ <file compressed="no">gda-browser-connected.png</file>
+ </gresource>
+ <gresource prefix="/images">
+ <file compressed="no">gda-browser-diagram.png</file>
+ </gresource>
+ <gresource prefix="/images">
+ <file compressed="no">gda-browser-ldap-class-a.png</file>
+ </gresource>
+ <gresource prefix="/images">
+ <file compressed="no">gda-browser-ldap-class-s.png</file>
+ </gresource>
+ <gresource prefix="/images">
+ <file compressed="no">gda-browser-ldap-class-u.png</file>
+ </gresource>
+ <gresource prefix="/images">
+ <file compressed="no">gda-browser-ldap-class-x.png</file>
+ </gresource>
+ <gresource prefix="/images">
+ <file compressed="no">gda-browser-ldap-entry.png</file>
+ </gresource>
+ <gresource prefix="/images">
+ <file compressed="no">gda-browser-ldap-group.png</file>
+ </gresource>
+ <gresource prefix="/images">
+ <file compressed="no">gda-browser-ldap-organization.png</file>
+ </gresource>
+ <gresource prefix="/images">
+ <file compressed="no">gda-browser-ldap-person.png</file>
+ </gresource>
+ <gresource prefix="/images">
+ <file compressed="no">gda-browser-menu-ind.png</file>
+ </gresource>
+ <gresource prefix="/images">
+ <file compressed="no">gda-browser-non-connected-big.png</file>
+ </gresource>
+ <gresource prefix="/images">
+ <file compressed="no">gda-browser-non-connected.png</file>
+ </gresource>
+ <gresource prefix="/images">
+ <file compressed="no">gda-browser.png</file>
+ </gresource>
+ <gresource prefix="/images">
+ <file compressed="no">gda-browser-query.png</file>
+ </gresource>
+ <gresource prefix="/images">
+ <file compressed="no">gda-browser-reference.png</file>
+ </gresource>
+ <gresource prefix="/images">
+ <file compressed="no">gda-browser-schema.png</file>
+ </gresource>
+ <gresource prefix="/images">
+ <file compressed="no">gda-browser-table.png</file>
+ </gresource>
+ <gresource prefix="/images">
+ <file compressed="no">gda-browser-view.png</file>
+ </gresource>
+</gresources>
diff --git a/tools/cnc.js b/tools/webdata/cnc.js
similarity index 100%
rename from tools/cnc.js
rename to tools/webdata/cnc.js
diff --git a/tools/gda-print.css b/tools/webdata/gda-print.css
similarity index 100%
rename from tools/gda-print.css
rename to tools/webdata/gda-print.css
diff --git a/tools/gda.css b/tools/webdata/gda.css
similarity index 100%
rename from tools/gda.css
rename to tools/webdata/gda.css
diff --git a/tools/irb.css b/tools/webdata/irb.css
similarity index 100%
rename from tools/irb.css
rename to tools/webdata/irb.css
diff --git a/tools/irb.js b/tools/webdata/irb.js
old mode 100755
new mode 100644
similarity index 100%
rename from tools/irb.js
rename to tools/webdata/irb.js
diff --git a/tools/jquery.js b/tools/webdata/jquery.js
similarity index 100%
rename from tools/jquery.js
rename to tools/webdata/jquery.js
diff --git a/tools/md5.js b/tools/webdata/md5.js
similarity index 100%
rename from tools/md5.js
rename to tools/webdata/md5.js
diff --git a/tools/mouseapp_2.js b/tools/webdata/mouseapp_2.js
old mode 100755
new mode 100644
similarity index 100%
rename from tools/mouseapp_2.js
rename to tools/webdata/mouseapp_2.js
diff --git a/tools/mouseirb_2.js b/tools/webdata/mouseirb_2.js
old mode 100755
new mode 100644
similarity index 100%
rename from tools/mouseirb_2.js
rename to tools/webdata/mouseirb_2.js
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]