Commit b577b960 authored by Murray Cumming's avatar Murray Cumming Committed by Murray Cumming
Browse files

Moved data_structure, document, and part of python_embed directories into

2006-04-28  Murray Cumming  <murrayc@murrayc.com>

        * configure.in:
        * glom/Makefile.am:
        * po/POTFILES.in:
        * many files: Moved data_structure, document, and part of python_embed directories
        into libglom, so that the glom python module does not need to use symbols in the
        glom executable, because this is not allowed in cygwin, using --no-undefined.
        In future, this can be used as public API to make the document/database structure
        available to separate utilities and a web UI.
parent 0b67b77f
2006-04-28 Murray Cumming <murrayc@murrayc.com>
* configure.in:
* glom/Makefile.am:
* po/POTFILES.in:
* many files: Moved data_structure, document, and part of python_embed directories
into libglom, so that the glom python module does not need to use symbols in the
glom executable, because this is not allowed in cygwin, using --no-undefined.
In future, this can be used as public API to make the document/database structure
available to separate utilities and a web UI.
2006-04-27 Murray Cumming <murrayc@murrayc.com>
* glom/data_structure/field.cc: get_type_name_ui(): Actually return
......
......@@ -36,6 +36,8 @@ AC_LANG_CPLUSPLUS
# Checks for libraries
# We need libgnome only for gnome_help_display().:
PKG_CHECK_MODULES(GLOM, bakery-2.4 >= 2.3.18 gtkmm-2.4 >= 2.6.1 gthread-2.0 gnome-vfsmm-2.6 >= 2.11.1 libgnomecanvasmm-2.6 >= 2.10.0 libxslt >= 1.1.10 pygda-1.2 pygtk-2.0 >= 2.6.0 libgnome-2.0 >= 2.6.0 iso-codes libgdamm-2.0 >= 1.3.7 )
GLOM_LIBS+=" --no-undefined"
AC_SUBST(GLOM_CFLAGS)
AC_SUBST(GLOM_LIBS)
......@@ -64,10 +66,12 @@ AC_OUTPUT(Makefile \
docs/Makefile \
docs/user-guide/Makefile \
glom/Makefile \
glom/data_structure/Makefile \
glom/data_structure/layout/Makefile \
glom/data_structure/layout/report_parts/Makefile \
glom/document/Makefile \
glom/libglom/Makefile \
glom/libglom/data_structure/Makefile \
glom/libglom/data_structure/layout/Makefile \
glom/libglom/data_structure/layout/report_parts/Makefile \
glom/libglom/document/Makefile \
glom/libglom/python_embed/Makefile \
glom/layout_item_dialogs/Makefile \
glom/mode_data/Makefile \
glom/mode_design/Makefile \
......
SUBDIRS = data_structure document mode_data mode_design mode_find navigation utility_widgets layout_item_dialogs python_embed relationships_overview reports translation
SUBDIRS = libglom mode_data mode_design mode_find navigation utility_widgets layout_item_dialogs python_embed relationships_overview reports translation
gladedir = $(datadir)/glom/glade/
glomxsltdir = $(datadir)/glom/xslt/
......@@ -7,7 +7,7 @@ glom_icon_dir = $(datadir)/icons/hicolor/48x48/apps
# We define GLOM_GLADEDIR so that we can get the installed .glade file at runtime.
# We define PREFIX, SYSCONFDIR, LIBDIR, and DATADIR for the GNOME_PROGRAM_STANDARD_PROPERTIES macro.
INCLUDES = $(GLOM_CFLAGS) $(PYTHON_INCLUDES) \
INCLUDES = -I@top_srcdir@/ $(GLOM_CFLAGS) $(PYTHON_INCLUDES) \
-DGLOM_GLADEDIR=\""$(gladedir)/"\" \
-DLOCALEDIR=\""$(datadir)/locale"\" \
-DPREFIX=\""$(prefix)"\" \
......@@ -24,7 +24,6 @@ noinst_PROGRAMS = test_pyembed
glom_SOURCES = main.cc \
application.cc application.h \
appstate.cc appstate.h \
base_db.h base_db.cc \
box_db.h box_db.cc \
box_db_table.h box_db_table.cc \
......@@ -32,23 +31,16 @@ glom_SOURCES = main.cc \
frame_glom.h frame_glom.cc \
notebook_glom.h notebook_glom.cc \
combobox_relationship.h combobox_relationship.cc \
connectionpool.h connectionpool.cc \
dialog_connection.h dialog_connection.cc \
dialog_invalid_data.h dialog_invalid_data.cc \
dialog_new_database.h dialog_new_database.cc \
dialog_database_preferences.h dialog_database_preferences.cc \
dialog_progress_creating.h dialog_progress_creating.cc \
filechooser_export.h filechooser_export.cc \
sharedptr.h \
standard_table_prefs_fields.h \
box_reports.h box_reports.cc \
utils.h utils.cc
xsl_utils.h xsl_utils.cc
glom_LDADD = document/libdocument.a \
reports/libreports.a \
data_structure/libdata_structure.a \
data_structure/layout/libdata_structure_layout.a \
data_structure/layout/report_parts/libdata_structure_layout_reportparts.a \
glom_LDADD = reports/libreports.a \
mode_data/libmode_data.a \
mode_find/libmode_find.a \
mode_design/libmode_design.a \
......@@ -61,14 +53,14 @@ glom_LDADD = document/libdocument.a \
utility_widgets/adddel/eggcolumnchooser/libutility_widgets_adddel_eggcolumnchooserdialog.a \
utility_widgets/db_adddel/libutility_widgets_db_adddel.a \
utility_widgets/libutility_widgets.a \
data_structure/libdata_structure.a \
relationships_overview/librelationshipsoverview.a \
translation/libtranslation.a \
data_structure/layout/libdata_structure_layout.a \
python_embed/libpython_embed.a \
python_embed/python_module/glom.la \
$(top_builddir)/glom/libglom/libglom.la \
$(GLOM_LIBS) $(PYTHON_LDFLAGS) -lutil
#python_embed/python_module/glom.la
# python_embed/boost/config/libpython_embed_boost_config.a
# python_embed/boost/python/libpython_embed_boost_python.a
# python_embed/boost/python/detail/libpython_embed_boost_python_detail.a
......
......@@ -23,7 +23,7 @@
#include "dialog_progress_creating.h"
#include "translation/dialog_change_language.h"
#include "translation/window_translations.h"
#include "utils.h"
#include <glom/libglom/utils.h>
#include <libgnome/gnome-help.h> //For gnome_help_display
#include "config.h" //For VERSION.
#include <cstdio>
......
/* Glom
*
* Copyright (C) 2001-2004 Murray Cumming
*
* 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., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "appstate.h"
AppState::AppState()
: m_userlevel(USERLEVEL_DEVELOPER)
{
}
AppState::~AppState()
{
}
AppState::userlevels AppState::get_userlevel() const
{
return m_userlevel;
}
void AppState::set_userlevel(userlevels value)
{
if(m_userlevel != value)
{
m_userlevel = value;
//Tell the UI to respond accordingly:
m_signal_userlevel_changed.emit(value);
}
}
AppState::type_signal_userlevel_changed AppState::signal_userlevel_changed()
{
return m_signal_userlevel_changed;
}
void AppState::emit_userlevel_changed()
{
m_signal_userlevel_changed.emit(m_userlevel);
}
/* Glom
*
* Copyright (C) 2001-2004 Murray Cumming
*
* 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., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef GLOM_APPSTATE_H
#define GLOM_APPSTATE_H
#include <glibmm.h>
/** There is one instance per document.
* This is for storing volatile application state.
* It is not for configuration that should be the same after the application is closed and restarted - use gconf for that.
*/
class AppState
{
public:
AppState();
virtual ~AppState();
enum userlevels
{
USERLEVEL_OPERATOR,
USERLEVEL_DEVELOPER
};
/** Returns whether we are in developer mode.
* Some functionality will be deactivated when not in developer mode.
*/
virtual userlevels get_userlevel() const;
/** This will cause the userlevel_changed signal to be emitted.
*/
virtual void set_userlevel(userlevels value);
/// Use this to set the initial UI state:
virtual void emit_userlevel_changed();
typedef sigc::signal<void, userlevels> type_signal_userlevel_changed;
/// The user interface should handle this signal and alter itself accordingly.
type_signal_userlevel_changed signal_userlevel_changed();
protected:
userlevels m_userlevel;
type_signal_userlevel_changed m_signal_userlevel_changed;
};
#endif //GLOM_APPSTATE_H
......@@ -20,7 +20,7 @@
#include "box_db.h"
#include "application.h" //App_Glom.
#include "appstate.h"
#include <glom/libglom/appstate.h>
//#include <libgnomeui/gnome-app-helper.h>
#include <sstream> //For stringstream
......
......@@ -24,9 +24,9 @@
#include "gtkmm.h"
#include "utility_widgets/adddel/adddel_withbuttons.h"
#include "document/document_glom.h"
#include "connectionpool.h"
#include "appstate.h"
#include <glom/libglom/document/document_glom.h>
#include <glom/libglom/connectionpool.h>
#include <glom/libglom/appstate.h>
#include "base_db.h"
#include <bakery/Utilities/BusyCursor.h>
#include <libglademm.h>
......
......@@ -19,7 +19,7 @@
*/
#include "box_db_table.h"
#include "data_structure/glomconversions.h"
#include <glom/libglom/data_structure/glomconversions.h>
#include "python_embed/glom_python.h"
#include <sstream>
......
......@@ -23,7 +23,7 @@
#define BOX_DB_TABLE_H
#include "box_db.h"
#include "data_structure/field.h"
#include <glom/libglom/data_structure/field.h>
#include <algorithm> //find_if used in various places.
......
......@@ -22,7 +22,7 @@
#define BOX_REPORTS_H
#include "box_db_table.h"
#include "data_structure/report.h"
#include <glom/libglom/data_structure/report.h>
class Box_Reports : public Box_DB_Table
......
......@@ -23,9 +23,9 @@
#include <gtkmm/combobox.h>
#include <libglademm.h>
#include "data_structure/relationship.h"
#include "document/document_glom.h"
#include "sharedptr.h"
#include <glom/libglom/data_structure/relationship.h>
#include <glom/libglom/document/document_glom.h>
#include <glom/libglom/sharedptr.h>
#include <gtkmm/treestore.h>
......
/* Glom
*
* Copyright (C) 2001-2004 Murray Cumming
*
* 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., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "connectionpool.h"
#include <gtkmm/messagedialog.h>
#include <bakery/bakery.h>
#include <glibmm/i18n.h>
ExceptionConnection::ExceptionConnection(failure_type failure)
: m_failure_type(failure)
{
}
ExceptionConnection::~ExceptionConnection() throw()
{
}
const char* ExceptionConnection::what() const throw()
{
return "Glom database connection failed.";
}
ExceptionConnection::failure_type ExceptionConnection::get_failure_type() const
{
return m_failure_type;
}
SharedConnection::SharedConnection()
{
}
SharedConnection::SharedConnection(const Glib::RefPtr<Gnome::Gda::Connection>& gda_connection)
: m_gda_connection(gda_connection)
{
}
SharedConnection::~SharedConnection()
{
if(m_gda_connection)
m_signal_finished.emit();
}
Glib::RefPtr<Gnome::Gda::Connection> SharedConnection::get_gda_connection()
{
return m_gda_connection;
}
Glib::RefPtr<const Gnome::Gda::Connection> SharedConnection::get_gda_connection() const
{
return m_gda_connection;
}
SharedConnection::type_signal_finished SharedConnection::signal_finished()
{
return m_signal_finished;
}
void SharedConnection::close()
{
if(m_gda_connection)
m_gda_connection.clear();
//Tell the connection pool that we have finished with this connection.
//It might want to close it, or keep it open if somebody else is using it.
//It might even give it to someone else while it is waiting for that other person to finish with it.
m_signal_finished.emit();
}
//init_db_details static data:
ConnectionPool* ConnectionPool::m_instance = 0;
ConnectionPool::ConnectionPool()
: m_sharedconnection_refcount(0),
m_ready_to_connect(false),
m_pFieldTypes(0)
{
}
ConnectionPool::~ConnectionPool()
{
if(m_pFieldTypes)
{
delete m_pFieldTypes;
m_pFieldTypes = 0;
}
}
//static
ConnectionPool* ConnectionPool::get_instance()
{
//TODO: Synchronize this for threads?
if(m_instance)
return m_instance;
else
{
m_instance = new ConnectionPool(); //TODO: Does it matter that this is never deleted?
return m_instance;
}
}
bool ConnectionPool::get_ready_to_connect() const
{
return m_ready_to_connect;
}
void ConnectionPool::set_ready_to_connect(bool val)
{
m_ready_to_connect = val;
}
//static:
sharedptr<SharedConnection> ConnectionPool::get_and_connect()
{
sharedptr<SharedConnection> result(0);
ConnectionPool* connection_pool = ConnectionPool::get_instance();
if(connection_pool)
{
result = connection_pool->connect();
}
return result;
}
sharedptr<SharedConnection> ConnectionPool::connect()
{
if(get_ready_to_connect())
{
//If the connection is already open (because it is being used by somebody):
if(m_refGdaConnection)
{
sharedptr<SharedConnection> sharedConnection( new SharedConnection(m_refGdaConnection) );
//Ask for notification when the SharedConnection has been finished with:
sharedConnection->signal_finished().connect( sigc::mem_fun(*this, &ConnectionPool::on_sharedconnection_finished) );
//Remember that somebody is using it:
m_sharedconnection_refcount++;
return sharedConnection;
}
else
{
//Create a new connection:
m_GdaClient = Gnome::Gda::Client::create();
//We must specify _some_ database even when we just want to create a database.
//This _might_ be different on some systems. I hope not. murrayc
const Glib::ustring default_database = "template1";
if(m_GdaClient)
{
//m_GdaDataSourceInfo = Gnome::Gda::DataSourceInfo(); //init_db_details it.
//m_GdaDataSourceInfo->
Glib::ustring cnc_string = "HOST=" + get_host() + ";USER=" + m_user + ";PASSWORD=" + m_password;
if(!m_database.empty())
cnc_string += (";DATABASE=" + m_database);
else
cnc_string += (";DATABASE=" + default_database);
//std::cout << "connecting: cnc string: " << cnc_string << std::endl;
std::cout << "Glom: connecting." << std::endl;
//*m_refGdaConnection = m_GdaClient->open_connection(m_GdaDataSourceInfo.get_name(), m_GdaDataSourceInfo.get_username(), m_GdaDataSourceInfo.get_password() );
//m_refGdaConnection.clear(); //Make sure any previous connection is really forgotten.
m_refGdaConnection = m_GdaClient->open_connection_from_string("PostgreSQL", cnc_string);
if(m_refGdaConnection)
{
//g_warning("ConnectionPool: connection opened");
//Create the fieldtypes member if it has not already been done:
if(!m_pFieldTypes)
m_pFieldTypes = new FieldTypes(m_refGdaConnection);
//Enforce ISO formats in the communication:
m_refGdaConnection->execute_single_command("SET DATESTYLE = 'ISO'");
//Open the database, if one has been specified:
/* This does not seem to work in libgda's postgres provider, so we specify it in the cnc_string instead:
std::cout << " database = " << m_database << std::endl;
if(!m_database.empty())
m_refGdaConnection->change_database(m_database);
*/
//Get postgres version:
Glib::RefPtr<Gnome::Gda::DataModel> data_model = m_refGdaConnection->execute_single_command("SELECT version()");
if(data_model && data_model->get_n_rows() && data_model->get_n_columns())
{
Gnome::Gda::Value value = data_model->get_value_at(0, 0);
if(value.get_value_type() == Gnome::Gda::VALUE_TYPE_STRING)
{
const Glib::ustring version_text = value.get_string();
//This seems to have the format "PostgreSQL 7.4.11 on i486-pc-linux"
const Glib::ustring namePart = "PostgreSQL ";
const Glib::ustring::size_type posName = version_text.find(namePart);
if(posName != Glib::ustring::npos)
{
const Glib::ustring versionPart = version_text.substr(namePart.size());
char* end = 0;
m_postgres_server_version = strtof(versionPart.c_str(), &end);
}
}
}
std::cout << " Postgres Server version: " << get_postgres_server_version() << std::endl;
return connect(); //Call this method recursively. This time m_refGdaConnection exists.
}
else
{
std::cout << "ConnectionPool::connect() Attempt to connect to database failed: " << m_database << std::endl;
bool bJustDatabaseMissing = false;
if(!m_database.empty())
{
std::cout << " ConnectionPool::connect() Attempting to connect without specifying the database." << std::endl;
//If the connection failed while looking for a database,
//then try connecting without the database:
Glib::ustring cnc_string = "HOST=" + get_host() + ";USER=" + m_user + ";PASSWORD=" + m_password;
cnc_string += (";DATABASE=" + default_database);
//std::cout << "connecting: cnc string: " << cnc_string << std::endl;
std::cout << "Glom: connecting." << std::endl;
Glib::RefPtr<Gnome::Gda::Connection> gda_connection = m_GdaClient->open_connection_from_string("PostgreSQL", cnc_string);
if(gda_connection) //If we could connect without specifying the database.
bJustDatabaseMissing = true;
else
{
std::cerr << " ConnectionPool::connect() connection also failed when not specifying database." << std::endl;
}
}
g_warning("ConnectionPool::connect() throwing exception.");
if(bJustDatabaseMissing)
std::cout << " (Connection succeeds, but not to the specific database: " << m_database << std::endl;
else
std::cerr << " (Could not connect even to the default database: " << default_database << std::endl;
//handle_error(true /* cerr only */);
throw ExceptionConnection(bJustDatabaseMissing ? ExceptionConnection::FAILURE_NO_DATABASE : ExceptionConnection::FAILURE_NO_SERVER);
}
}
}
}
else
{
//g_warning("ConnectionPool::connect(): not ready to connect.");
}
return sharedptr<SharedConnection>(0);
}
void ConnectionPool::set_host(const Glib::ustring& value)
{
m_host = value;
}
void ConnectionPool::set_user(const Glib::ustring& value)
{
m_user = value;
}
void ConnectionPool::set_password(const Glib::ustring& value)
{
m_password = value;
}
void ConnectionPool::set_database(const Glib::ustring& value)
{
m_database = value;
}
Glib::ustring ConnectionPool::get_host() const
{
return m_host;
}
Glib::ustring ConnectionPool::get_user() const
{
return m_user;
}
Glib::ustring ConnectionPool::get_password() const
{
return m_password;
}
Glib::ustring ConnectionPool::get_database() const
{
return m_database;
}
const FieldTypes* ConnectionPool::get_field_types() const
{
return m_pFieldTypes;
}