1 
2 ///////////////////////////////////////////////////////////
3 //                                                       //
4 //                         SAGA                          //
5 //                                                       //
6 //      System for Automated Geoscientific Analyses      //
7 //                                                       //
8 //                    User Interface                     //
9 //                                                       //
10 //                    Program: SAGA                      //
11 //                                                       //
12 //-------------------------------------------------------//
13 //                                                       //
14 //                  data_source_pgsql.h                  //
15 //                                                       //
16 //          Copyright (C) 2013 by Olaf Conrad            //
17 //                                                       //
18 //-------------------------------------------------------//
19 //                                                       //
20 // This file is part of 'SAGA - System for Automated     //
21 // Geoscientific Analyses'. SAGA is free software; you   //
22 // can redistribute it and/or modify it under the terms  //
23 // of the GNU General Public License as published by the //
24 // Free Software Foundation, either version 2 of the     //
25 // License, or (at your option) any later version.       //
26 //                                                       //
27 // SAGA is distributed in the hope that it will be       //
28 // useful, but WITHOUT ANY WARRANTY; without even the    //
29 // implied warranty of MERCHANTABILITY or FITNESS FOR A  //
30 // PARTICULAR PURPOSE. See the GNU General Public        //
31 // License for more details.                             //
32 //                                                       //
33 // You should have received a copy of the GNU General    //
34 // Public License along with this program; if not, see   //
35 // <http://www.gnu.org/licenses/>.                       //
36 //                                                       //
37 //-------------------------------------------------------//
38 //                                                       //
39 //    contact:    Olaf Conrad                            //
40 //                Institute of Geography                 //
41 //                University of Hamburg                  //
42 //                Germany                                //
43 //                                                       //
44 //    e-mail:     oconrad@saga-gis.org                   //
45 //                                                       //
46 ///////////////////////////////////////////////////////////
47 
48 //---------------------------------------------------------
49 #ifndef _HEADER_INCLUDED__SAGA_GUI__data_source_pgsql__H
50 #define _HEADER_INCLUDED__SAGA_GUI__data_source_pgsql__H
51 
52 
53 ///////////////////////////////////////////////////////////
54 //														 //
55 //														 //
56 //														 //
57 ///////////////////////////////////////////////////////////
58 
59 //---------------------------------------------------------
60 #include <wx/treectrl.h>
61 
62 
63 ///////////////////////////////////////////////////////////
64 //														 //
65 //														 //
66 //														 //
67 ///////////////////////////////////////////////////////////
68 
69 //---------------------------------------------------------
70 bool	PGSQL_Connect			(const CSG_String &Host, const CSG_String &Port, const CSG_String &DBName);
71 bool	PGSQL_is_Connected		(const CSG_String &Host, const CSG_String &Port, const CSG_String &DBName);
72 bool	PGSQL_is_Connected		(const CSG_String &Server);
73 
74 bool	PGSQL_has_Connections	(double vPostGIS = 0.0);
75 bool	PGSQL_Get_Connections	(CSG_Strings &Servers, double vPostGIS = 0.0);
76 
77 bool	PGSQL_Save_Table		(CSG_Table  *pTable);
78 bool	PGSQL_Save_Shapes		(CSG_Shapes *pShapes);
79 bool	PGSQL_Save_Grid			(CSG_Grid   *pGrid);
80 bool	PGSQL_Save_Grids		(CSG_Grids  *pGrids);
81 
82 
83 ///////////////////////////////////////////////////////////
84 //														 //
85 //														 //
86 //														 //
87 ///////////////////////////////////////////////////////////
88 
89 //---------------------------------------------------------
90 class CData_Source_PgSQL : public wxTreeCtrl
91 {
92 public:
93 	CData_Source_PgSQL(wxWindow *pParent);
94 	virtual ~CData_Source_PgSQL(void);
95 
96 	void						Autoconnect			(void);
97 
98 	void						Update_Sources		(void);
99 	void						Update_Source		(const wxString &Server, const wxString &Username = "", const wxString &Password = "");
100 
101 
102 private:
103 
104 	long						m_Wait4Response;
105 
106 
107 	void						On_Item_Activated	(wxTreeEvent &event);
108 	void						On_Item_RClick		(wxTreeEvent &event);
109 	void						On_Item_Menu		(wxTreeEvent &event);
110 
111 	void						On_Refresh			(wxCommandEvent &event);
112 	void						On_Source_Create	(wxCommandEvent &event);
113 	void						On_Source_Drop		(wxCommandEvent &event);
114 	void						On_Source_Open		(wxCommandEvent &event);
115 	void						On_Source_Close		(wxCommandEvent &event);
116 	void						On_Sources_Close	(wxCommandEvent &event);
117 	void						On_Source_Delete	(wxCommandEvent &event);
118 	void						On_Table_Open		(wxCommandEvent &event);
119 	void						On_Table_From_Query	(wxCommandEvent &event);
120 	void						On_Table_Rename		(wxCommandEvent &event);
121 	void						On_Table_Info		(wxCommandEvent &event);
122 	void						On_Table_Drop		(wxCommandEvent &event);
123 
124 	bool						Source_Create		(const wxTreeItemId &Item);
125 	bool						Source_Drop			(const wxTreeItemId &Item);
126 	bool						Source_Open			(class CData_Source_PgSQL_Data *pData, bool bDialog);
127 	void						Source_Open			(const wxTreeItemId &Item);
128 	void						Source_Close		(const wxTreeItemId &Item, bool bDelete);
129 	void						Sources_Close		(void);
130 	void						Table_Open			(const wxTreeItemId &Item);
131 	void						Table_From_Query	(const wxTreeItemId &Item);
132 	void						Table_Rename		(const wxTreeItemId &Item);
133 	void						Table_Info			(const wxTreeItemId &Item);
134 	void						Table_Drop			(const wxTreeItemId &Item);
135 
136 	wxTreeItemId				Get_Server_Item		(const wxString &Server, bool bCreate);
137 	wxTreeItemId				Find_Source			(const wxString &Server);
138 	void						Update_Item			(const wxTreeItemId &Item);
139 	void						Update_Sources		(const wxTreeItemId &Root);
140 	void						Update_Source		(const wxTreeItemId &Item);
141 	void						Append_Table		(const wxTreeItemId &Parent, const SG_Char *Name, int Type, int Image);
142 
143 
144 	//-----------------------------------------------------
145 	DECLARE_EVENT_TABLE()
146 };
147 
148 
149 ///////////////////////////////////////////////////////////
150 //														 //
151 //														 //
152 //														 //
153 ///////////////////////////////////////////////////////////
154 
155 //---------------------------------------------------------
156 #endif // #ifndef _HEADER_INCLUDED__SAGA_GUI__data_source_pgsql__H
157