Refactored controller to work with GtkActionGroup

Refactored the company view controller to work with
GtkActionGroups. This controller will serve as an
example for the other views.
This commit is contained in:
Edward Hennessy 2012-03-11 11:52:46 -07:00
parent d4ff9b8b41
commit e2f0455786
24 changed files with 3493 additions and 56 deletions

View File

@ -25,6 +25,7 @@ pkgdata_DATA = \
xmldir = $(pkgdatadir)/xml
xml_DATA = \
gparts.xml \
gparts-ui.xml \
gsymview.xml
# Would like to move common files into a library, but the dynamically loadable
@ -68,7 +69,7 @@ gparts_SOURCES = \
miscui-action-controller.c \
miscui-action-model.c
gparts_CFLAGS = $(AM_CFLAGS) $(GMODULE_CFLAGS) $(GTK_CFLAGS)
gparts_LDADD = $(GMODULE_LIBS) $(GTK_LIBS) libgeom.la libmisc.la libsch.la libschgui.la libscmcfg.la
gparts_LDADD = $(GMODULE_LIBS) $(GTK_LIBS) libgeom.la libgpform.la libgpview.la libmisc.la libsch.la libschgui.la libscmcfg.la
#gparts_DEPENDENCIES = $(MYSQL_LDADD) $(POSTGRESQL_LDADD) $(SQLITE_LDADD)
@ -100,6 +101,7 @@ noinst_LTLIBRARIES = \
libgeom.la \
libgpdata.la \
libgpform.la \
libgpview.la \
libmisc.la \
libmiscgui.la \
libsch.la \
@ -253,6 +255,21 @@ libgpdata_la_SOURCES = \
libgpdata_la_CFLAGS = -Wall $(AM_CFLAGS) $(GLIB_CFLAGS) $(LIBXML_CFLAGS)
libgpdata_la_LIBADD = $(GLIB_LIBS) $(LIBXML_LIBS) libmisc.la
#
# This library contains UI elements for views.
#
libgpview_la_SOURCES = \
gpview-company-ctrl.c \
gpview-company-view.c \
gpview-factory.c \
gpview-result-adapter.c \
gpview-symbol-view.c \
gpview-view-interface.c
libgpview_la_CFLAGS = -Wall $(AM_CFLAGS) $(GTK_CFLAGS)
libgpview_la_LIBADD = $(GTK_LIBS) libmisc.la libgpform.la
#
# This library contains UI elements for data entry.
#

View File

@ -24,6 +24,7 @@
#include <dlfcn.h>
#include "gpartsui.h"
#include "gpview.h"
#include "scmcfg-config.h"
@ -47,6 +48,14 @@ struct _GPartsPrivate
GPartsController *current_controller;
GPViewCompanyView *company_view;
GPViewCompanyView *symbol_view;
GtkWidget *current_view;
GPViewCompanyCtrl *company_ctrl;
/* A temporary measure to map GtkNotebook pages to their respective
* GPartsControllers.
*/
@ -90,7 +99,7 @@ static void
gparts_destroy_cb(GtkWidget* widget, gpointer data);
static void
gparts_switch_page_cb(GtkNotebook *notebook, GtkNotebookPage *page, gint page_no, gpointer user_data);
gparts_switch_page_cb(GtkNotebook *notebook, gpointer unused, gint page_no, gpointer user_data);
@ -195,7 +204,6 @@ gparts_instance_init(GTypeInstance* instance, gpointer g_class)
privat->builder = gtk_builder_new();
path = g_build_filename(datadir, "xml", "gparts.xml", NULL);
g_free(datadir);
status = gtk_builder_add_from_file(
privat->builder,
@ -210,6 +218,18 @@ gparts_instance_init(GTypeInstance* instance, gpointer g_class)
g_error( error->message ) ;
}
GtkUIManager *ui_manager = GTK_UI_MANAGER(gtk_builder_get_object(privat->builder, "uimanager"));
privat->company_ctrl = gpview_company_ctrl_new_with_manager(ui_manager);
path = g_build_filename(datadir, "xml", "gparts-ui.xml", NULL);
g_free(datadir);
gtk_ui_manager_add_ui_from_file(ui_manager, path, NULL);
g_free(path);
gtk_ui_manager_ensure_update(ui_manager);
gtk_builder_connect_signals(privat->builder, NULL);
GtkWidget *widget = GTK_WIDGET(gtk_builder_get_object(privat->builder, "main"));
@ -388,12 +408,13 @@ gparts_instance_init(GTypeInstance* instance, gpointer g_class)
NULL
);
privat->kludge[0] = g_object_new(
privat->kludge[0] = NULL; /*g_object_new(
GPARTSUI_TYPE_COMPANY_CONTROLLER,
"company-model", privat->company_model,
"company-view", gtk_builder_get_object(privat->builder, "companies-view"),
NULL
);
);*/
privat->kludge[2] = g_object_new(
GPARTSUI_TYPE_DOCUMENT_CONTROLLER,
@ -422,9 +443,48 @@ gparts_instance_init(GTypeInstance* instance, gpointer g_class)
GTK_NOTEBOOK(gtk_builder_get_object(privat->builder, "notebook"))
);
privat->company_view = gpview_company_view_new_with_controller(privat->company_ctrl);
privat->symbol_view = gpview_symbol_view_new();
gtk_notebook_prepend_page(
privat->notebook,
privat->company_view,
gtk_label_new("Companies")
);
gtk_notebook_append_page(
privat->notebook,
privat->symbol_view,
gtk_label_new("Symbols")
);
g_object_bind_property(
privat->database_model,
"database",
privat->company_view,
"database",
G_BINDING_DEFAULT
);
g_object_bind_property(
privat->database_model,
"database",
privat->symbol_view,
"database",
G_BINDING_DEFAULT
);
g_object_bind_property(
privat->database_model,
"database",
privat->company_ctrl,
"database",
G_BINDING_DEFAULT
);
gparts_set_current_controller(GPARTS(instance), privat->kludge[0]);
gtk_widget_show(widget);
gtk_widget_show_all(widget);
}
static void
@ -532,18 +592,43 @@ gparts_set_notebook(GParts *gparts, GtkNotebook *notebook)
}
}
static void
gparts_switch_page_cb(GtkNotebook *notebook, GtkNotebookPage *page, gint page_no, gpointer user_data)
gparts_switch_page_cb(GtkNotebook *notebook, gpointer unused, gint page_no, gpointer user_data)
{
GPartsPrivate *privat = GPARTS_GET_PRIVATE(user_data);
if (privat != NULL)
{
g_debug("Switch page %d", page_no);
gparts_set_current_controller(GPARTS(user_data), privat->kludge[page_no]);
if (page_no >= 0)
{
GtkWidget *widget = gtk_notebook_get_nth_page(notebook, page_no);
if (GPVIEW_IS_VIEW_INTERFACE(widget))
{
gpview_view_interface_activate(GPVIEW_VIEW_INTERFACE(widget));
}
else if (GPVIEW_IS_VIEW_INTERFACE(privat->current_view))
{
gpview_view_interface_deactivate(GPVIEW_VIEW_INTERFACE(privat->current_view));
}
privat->current_view = widget;
}
else
{
if (GPVIEW_IS_VIEW_INTERFACE(privat->current_view))
{
gpview_view_interface_deactivate(GPVIEW_VIEW_INTERFACE(privat->current_view));
}
privat->current_view = NULL;
}
}
}
int main(int argc, char* argv[])
{

23
src/gparts-ui.xml Normal file
View File

@ -0,0 +1,23 @@
<?xml version="1.0"?>
<ui>
<menubar name="main_menu">
<menu name="entity" action="entity">
<menu name="entity-create" action="entity-create">
<menuitem name="company-create" action="company-create"/>
<menuitem name="symbol-create" action="symbol-create"/>
</menu>
<menuitem name="company-edit" action="company-edit"/>
<menuitem name="symbol-edit" action="symbol-edit"/>
<menuitem name="company-delete" action="company-delete"/>
<menuitem name="symbol-delete" action="symbol-delete"/>
<menuitem name="company-visit" action="company-visit"/>
</menu>
</menubar>
<toolbar name="main_toolbar">
<toolitem action="company-create"/>
<toolitem action="company-delete"/>
<toolitem action="company-edit"/>
<separator/>
<toolitem action="company-visit"/>
</toolbar>
</ui>

View File

@ -3,6 +3,40 @@
<object class="GtkUIManager" id="uimanager">
<child>
<object class="GtkActionGroup" id="main_action_group">
<child>
<object class="GtkAction" id="entity">
<property name="name">entity</property>
<property name="label">_Entity</property>
</object>
</child>
<child>
<object class="GtkAction" id="entity-create">
<property name="name">entity-create</property>
<property name="label">_New...</property>
</object>
</child>
<child>
<object class="GtkAction" id="symbol-create">
<property name="name">symbol-create</property>
<property name="label">Create Symbol</property>
</object>
</child>
<child>
<object class="GtkAction" id="symbol-edit">
<property name="name">symbol-edit</property>
<property name="label">Edit Symbol</property>
</object>
</child>
<child>
<object class="GtkAction" id="symbol-delete">
<property name="name">symbol-delete</property>
<property name="label">Delete Symbol</property>
</object>
</child>
<child>
<object class="GtkAction" id="database">
<property name="name">database</property>
@ -147,12 +181,6 @@
<property name="label">Open Webpage</property>
</object>
</child>
<child>
<object class="GtkAction" id="tools-open-document">
<property name="name">tools-open-document</property>
<property name="label">Open Document</property>
</object>
</child>
</object>
</child>
@ -182,22 +210,12 @@
<menuitem action="view-edit"/>
<menuitem action="view-customize"/>
</menu>
<menu action="tools">
<menuitem action="tools-open-website"/>
<menuitem action="tools-open-webpage"/>
<menuitem action="tools-open-document"/>
</menu>
</menubar>
<toolbar name="main_toolbar">
<toolitem action="database-connect"/>
<toolitem action="edit-copy"/>
<toolitem action="view-refresh"/>
<separator/>
<toolitem action="edit-insert"/>
<toolitem action="edit-delete"/>
<toolitem action="edit-edit"/>
<separator/>
<toolitem action="tools-open-website"/>
</toolbar>
</ui>
</object>
@ -235,6 +253,7 @@
<!-- A window for browsing all the companies in the library -->
<!--
<child>
<object class="GtkScrolledWindow" id="companies-scrolled">
<property name="visible">TRUE</property>
@ -254,7 +273,7 @@
<property name="label">Companies</property>
</object>
</child>
-->
<!-- A window for browsing all the devices in the library -->
@ -466,7 +485,7 @@
<!-- A window for browsing all the symbols in the library -->
<!--
<child>
<object class="GtkVPaned" id="symbols-window-vpaned-1">
<property name="visible">TRUE</property>
@ -517,6 +536,7 @@
<property name="label">Symbols</property>
</object>
</child>
-->
</object>

672
src/gpview-company-ctrl.c Normal file
View File

@ -0,0 +1,672 @@
/* gEDA - GPL Electronic Design Automation
* gparts - gEDA Parts Manager
* Copyright (C) 2012 Edward C. Hennessy
* Copyright (C) 2012 gEDA Contributors (see ChangeLog for details)
*
* 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 USA
*/
/*! \file gpview-company-ctrl.c
*/
#include <glib.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include "gparts.h"
#include "gpform.h"
#include "gpview.h"
#define GPVIEW_COMPANY_CTRL_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj),GPVIEW_TYPE_COMPANY_CTRL,GPViewCompanyCtrlPrivate))
enum
{
GPVIEW_COMPANY_CTRL_CURRENT_VIEW = 1,
GPVIEW_COMPANY_CTRL_DATABASE,
GPVIEW_COMPANY_CTRL_UI_MANAGER
};
typedef struct _GPViewCompanyCtrlPrivate GPViewCompanyCtrlPrivate;
struct _GPViewCompanyCtrlPrivate
{
GtkActionGroup *action_group[3];
GPartsDatabase *database;
GPViewCompanyView *current_view;
GtkUIManager *ui_manager;
GPFormFactory *form_factory;
};
static void
gpview_company_ctrl_class_init(gpointer g_class, gpointer g_class_data);
static void
gpview_company_ctrl_create_cb(GtkAction *action, GPViewCompanyCtrl *ctrl);
static void
gpview_company_ctrl_delete_cb(GtkAction *action, GPViewCompanyCtrl *ctrl);
static void
gpview_company_ctrl_dispose(GObject *object);
static void
gpview_company_ctrl_edit_cb(GtkAction *action, GPViewCompanyCtrl *ctrl);
static void
gpview_company_ctrl_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
static void
gpview_company_ctrl_init(GTypeInstance *instance, gpointer g_class);
static void
gpview_company_ctrl_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
static void
gpview_company_ctrl_update_0_cb(GObject *unused, GParamSpec *pspec, GPViewCompanyCtrl *ctrl);
static void
gpview_company_ctrl_update_1_cb(GObject *unused, GParamSpec *pspec, GPViewCompanyCtrl *ctrl);
static void
gpview_company_ctrl_update_2_cb(GObject *unused, GParamSpec *pspec, GPViewCompanyCtrl *ctrl);
static void
gpview_company_ctrl_visit_cb(GtkAction *action, GPViewCompanyCtrl *ctrl);
static const GtkActionEntry gpview_company_ctrl_actions_0[] =
{
{
"company-create",
GTK_STOCK_ADD,
"New Company",
NULL,
"New Company",
G_CALLBACK(gpview_company_ctrl_create_cb)
},
};
static const GtkActionEntry gpview_company_ctrl_actions_1[] =
{
{
"company-edit",
GTK_STOCK_EDIT,
"Edit Company",
NULL,
"Edit Company",
G_CALLBACK(gpview_company_ctrl_edit_cb)
},
{
"company-delete",
GTK_STOCK_REMOVE,
"Delete Company",
NULL,
"Delete Company",
G_CALLBACK(gpview_company_ctrl_delete_cb)
}
};
static const GtkActionEntry gpview_company_ctrl_actions_2[] =
{
{
"company-visit",
GTK_STOCK_HOME,
"Visit Company Website",
NULL,
"Visit Company Website",
G_CALLBACK(gpview_company_ctrl_visit_cb)
}
};
static void
gpview_company_ctrl_class_init(gpointer g_class, gpointer g_class_data)
{
GObjectClass *klasse = G_OBJECT_CLASS(g_class);
g_type_class_add_private(g_class, sizeof(GPViewCompanyCtrlPrivate));
klasse->dispose = gpview_company_ctrl_dispose;
klasse->get_property = gpview_company_ctrl_get_property;
klasse->set_property = gpview_company_ctrl_set_property;
g_object_class_install_property(
klasse,
GPVIEW_COMPANY_CTRL_CURRENT_VIEW,
g_param_spec_object(
"current-view",
"Current View",
"Current View",
GPVIEW_TYPE_COMPANY_VIEW,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS
)
);
g_object_class_install_property(
klasse,
GPVIEW_COMPANY_CTRL_DATABASE,
g_param_spec_object(
"database",
"Database",
"Database",
GPARTS_TYPE_DATABASE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS
)
);
g_object_class_install_property(
klasse,
GPVIEW_COMPANY_CTRL_UI_MANAGER,
g_param_spec_object(
"ui-manager",
"UI Manager",
"UI Manager",
GTK_TYPE_UI_MANAGER,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS
)
);
}
static void
gpview_company_ctrl_create_cb(GtkAction *action, GPViewCompanyCtrl *ctrl)
{
GPViewCompanyCtrlPrivate *privat = GPVIEW_COMPANY_CTRL_GET_PRIVATE(ctrl);
if (privat != NULL)
{
GPFormUIDialog *dialog;
dialog = gpform_factory_create_form(privat->form_factory, "company-add.xml");
if (dialog != NULL)
{
gtk_widget_show_all(GTK_WIDGET(dialog));
gint result = gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_hide(GTK_WIDGET(dialog));
}
}
}
static void
gpview_company_ctrl_dispose(GObject *object)
{
GPViewCompanyCtrlPrivate *privat = GPVIEW_COMPANY_CTRL_GET_PRIVATE(object);
if (privat != NULL)
{
if (privat->database != NULL)
{
g_object_unref(privat->database);
}
}
misc_object_chain_dispose(object);
}
static void
gpview_company_ctrl_delete_cb(GtkAction *action, GPViewCompanyCtrl *ctrl)
{
GPViewCompanyCtrlPrivate *privat = GPVIEW_COMPANY_CTRL_GET_PRIVATE(ctrl);
if (privat != NULL)
{
GPFormUIDialog *dialog;
dialog = gpform_factory_create_form(privat->form_factory, "company-delete.xml");
if (dialog != NULL)
{
gtk_widget_show_all(GTK_WIDGET(dialog));
gint result = gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_hide(GTK_WIDGET(dialog));
}
}
}
static void
gpview_company_ctrl_edit_cb(GtkAction *action, GPViewCompanyCtrl *ctrl)
{
g_debug("Edit Company");
}
static void
gpview_company_ctrl_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
{
GPViewCompanyCtrlPrivate *privat = GPVIEW_COMPANY_CTRL_GET_PRIVATE(object);
if (privat != NULL)
{
switch (property_id)
{
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
}
}
}
GType
gpview_company_ctrl_get_type(void)
{
static GType type = G_TYPE_INVALID;
if (type == G_TYPE_INVALID)
{
static const GTypeInfo tinfo = {
sizeof(GPViewCompanyCtrlClass), /* class_size */
NULL, /* base_init */
NULL, /* base_finalize */
gpview_company_ctrl_class_init, /* class_init */
NULL, /* class_finalize */
NULL, /* class_data */
sizeof(GPViewCompanyCtrl), /* instance_size */
0, /* n_preallocs */
gpview_company_ctrl_init, /* instance_init */
NULL /* value_table */
};
static const GInterfaceInfo iinfo = {
NULL, /* interface_init */
NULL, /* interface_finalize */
NULL /* interface_data */
};
type = g_type_register_static(
G_TYPE_OBJECT,
"GPViewCompanyCtrl",
&tinfo,
0
);
g_type_add_interface_static(type, GTK_TYPE_BUILDABLE, &iinfo);
}
return type;
}
static void
gpview_company_ctrl_init(GTypeInstance *instance, gpointer g_class)
{
GPViewCompanyCtrlPrivate *privat = GPVIEW_COMPANY_CTRL_GET_PRIVATE(instance);
if (privat != NULL)
{
privat->action_group[0] = gtk_action_group_new("company-action-group-0");
gtk_action_group_add_actions(
privat->action_group[0],
gpview_company_ctrl_actions_0,
G_N_ELEMENTS(gpview_company_ctrl_actions_0),
instance
);
g_signal_connect(
GPVIEW_COMPANY_CTRL(instance),
"notify::database",
G_CALLBACK(gpview_company_ctrl_update_0_cb),
GPVIEW_COMPANY_CTRL(instance)
);
privat->action_group[1] = gtk_action_group_new("company-action-group-1");
gtk_action_group_add_actions(
privat->action_group[1],
gpview_company_ctrl_actions_1,
G_N_ELEMENTS(gpview_company_ctrl_actions_1),
instance
);
g_signal_connect(
GPVIEW_COMPANY_CTRL(instance),
"notify::current-view",
G_CALLBACK(gpview_company_ctrl_update_1_cb),
GPVIEW_COMPANY_CTRL(instance)
);
g_signal_connect(
GPVIEW_COMPANY_CTRL(instance),
"notify::database",
G_CALLBACK(gpview_company_ctrl_update_1_cb),
GPVIEW_COMPANY_CTRL(instance)
);
privat->action_group[2] = gtk_action_group_new("company-action-group-2");
gtk_action_group_add_actions(
privat->action_group[2],
gpview_company_ctrl_actions_2,
G_N_ELEMENTS(gpview_company_ctrl_actions_2),
instance
);
g_signal_connect(
GPVIEW_COMPANY_CTRL(instance),
"notify::current-view",
G_CALLBACK(gpview_company_ctrl_update_2_cb),
GPVIEW_COMPANY_CTRL(instance)
);
g_object_notify(G_OBJECT(instance), "current-view");
g_object_notify(G_OBJECT(instance), "database");
privat->form_factory = gpform_factory_new();
}
}
GPViewCompanyCtrl*
gpview_company_ctrl_new(void)
{
return GPVIEW_COMPANY_CTRL(g_object_new(GPVIEW_TYPE_COMPANY_CTRL, NULL));
}
GPViewCompanyCtrl*
gpview_company_ctrl_new_with_manager(GtkUIManager *manager)
{
return GPVIEW_COMPANY_CTRL(g_object_new(
GPVIEW_TYPE_COMPANY_CTRL,
"ui-manager", manager,
NULL
));
}
void
gpview_company_ctrl_set_current_view(GPViewCompanyCtrl *ctrl, GPViewCompanyView *view)
{
GPViewCompanyCtrlPrivate *privat = GPVIEW_COMPANY_CTRL_GET_PRIVATE(ctrl);
if (privat != NULL)
{
if (privat->current_view != NULL)
{
g_signal_handlers_disconnect_by_func(
privat->current_view,
G_CALLBACK(gpview_company_ctrl_update_2_cb),
ctrl
);
g_object_unref(privat->current_view);
}
privat->current_view = view;
if (privat->current_view != NULL)
{
g_object_ref(privat->current_view);
g_signal_connect(
privat->current_view,
"notify::websites",
G_CALLBACK(gpview_company_ctrl_update_2_cb),
ctrl
);
}
g_object_notify(G_OBJECT(ctrl), "current-view");
}
}
void
gpview_company_ctrl_set_database(GPViewCompanyCtrl *ctrl, GPartsDatabase *database)
{
GPViewCompanyCtrlPrivate *privat = GPVIEW_COMPANY_CTRL_GET_PRIVATE(ctrl);
if (privat != NULL)
{
if (privat->database != NULL)
{
g_signal_handlers_disconnect_by_func(
privat->database,
G_CALLBACK(gpview_company_ctrl_update_1_cb),
ctrl
);
g_signal_handlers_disconnect_by_func(
privat->database,
G_CALLBACK(gpview_company_ctrl_update_0_cb),
ctrl
);
g_object_unref(privat->database);
}
privat->database = database;
if (privat->database != NULL)
{
g_object_ref(privat->database);
g_signal_connect(
privat->database,
"notify::connected",
G_CALLBACK(gpview_company_ctrl_update_0_cb),
ctrl
);
g_signal_connect(
privat->database,
"notify::connected",
G_CALLBACK(gpview_company_ctrl_update_1_cb),
ctrl
);
}
g_object_notify(G_OBJECT(ctrl), "database");
}
}
static void
gpview_company_ctrl_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
{
GPViewCompanyCtrl *view = GPVIEW_COMPANY_CTRL(object);
if (view != NULL)
{
switch (property_id)
{
case GPVIEW_COMPANY_CTRL_CURRENT_VIEW:
gpview_company_ctrl_set_current_view(view, g_value_get_object(value));
break;
case GPVIEW_COMPANY_CTRL_DATABASE:
gpview_company_ctrl_set_database(view, g_value_get_object(value));
break;
case GPVIEW_COMPANY_CTRL_UI_MANAGER:
gpview_company_ctrl_set_ui_manager(view, g_value_get_object(value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
}
}
}
void
gpview_company_ctrl_set_ui_manager(GPViewCompanyCtrl *ctrl, GtkUIManager *ui_manager)
{
GPViewCompanyCtrlPrivate *privat = GPVIEW_COMPANY_CTRL_GET_PRIVATE(ctrl);
if (privat != NULL)
{
if (privat->ui_manager != NULL)
{
gtk_ui_manager_remove_action_group(
privat->ui_manager,
privat->action_group[2]
);
gtk_ui_manager_remove_action_group(
privat->ui_manager,
privat->action_group[1]
);
gtk_ui_manager_remove_action_group(
privat->ui_manager,
privat->action_group[0]
);
g_object_unref(privat->ui_manager);
}
privat->ui_manager = ui_manager;
if (privat->ui_manager != NULL)
{
g_object_ref(privat->ui_manager);
gtk_ui_manager_insert_action_group(
privat->ui_manager,
privat->action_group[0],
0
);
gtk_ui_manager_insert_action_group(
privat->ui_manager,
privat->action_group[1],
0
);
gtk_ui_manager_insert_action_group(
privat->ui_manager,
privat->action_group[2],
0
);
}
g_object_notify(G_OBJECT(ctrl), "ui-manager");
}
}
static void
gpview_company_ctrl_update_0_cb(GObject *unused, GParamSpec *pspec, GPViewCompanyCtrl *ctrl)
{
GPViewCompanyCtrlPrivate *privat = GPVIEW_COMPANY_CTRL_GET_PRIVATE(ctrl);
if (privat != NULL)
{
gtk_action_group_set_sensitive(
privat->action_group[0],
gparts_database_connected(privat->database)
);
}
}
static void
gpview_company_ctrl_update_1_cb(GObject *unused, GParamSpec *pspec, GPViewCompanyCtrl *ctrl)
{
GPViewCompanyCtrlPrivate *privat = GPVIEW_COMPANY_CTRL_GET_PRIVATE(ctrl);
if (privat != NULL)
{
gboolean visible = (privat->current_view != NULL);
gboolean sensitive = visible && gparts_database_connected(privat->database);
gtk_action_group_set_sensitive(
privat->action_group[1],
sensitive
);
gtk_action_group_set_visible(
privat->action_group[1],
visible
);
}
}
static void
gpview_company_ctrl_update_2_cb(GObject *unused, GParamSpec *pspec, GPViewCompanyCtrl *ctrl)
{
GPViewCompanyCtrlPrivate *privat = GPVIEW_COMPANY_CTRL_GET_PRIVATE(ctrl);
if (privat != NULL)
{
gboolean visible = (privat->current_view != NULL);
GStrv websites = gpview_company_view_get_websites(privat->current_view);
gboolean sensitive = visible && (websites != NULL) && (g_strv_length(websites) > 0);
g_strfreev(websites);
gtk_action_group_set_sensitive(
privat->action_group[2],
sensitive
);
gtk_action_group_set_visible(
privat->action_group[2],
visible
);
}
}
/* This function sends "failed to create drawable" to the terminal. It
* is caused by gnome-open.
*/
static void
gpview_company_ctrl_visit_cb(GtkAction *action, GPViewCompanyCtrl *ctrl)
{
GPViewCompanyCtrlPrivate *privat = GPVIEW_COMPANY_CTRL_GET_PRIVATE(ctrl);
if (privat != NULL)
{
GStrv websites = gpview_company_view_get_websites(privat->current_view);
if (websites != NULL)
{
GString *command = g_string_new(NULL);
gchar **temp = websites;
while (*temp != NULL)
{
g_string_printf(
command,
"gnome-open %s",
*temp++
);
g_debug("Command line: %s", command->str);
g_spawn_command_line_async(command->str, NULL);
}
g_string_free(command, TRUE);
g_strfreev(websites);
}
}
}

58
src/gpview-company-ctrl.h Normal file
View File

@ -0,0 +1,58 @@
/* gEDA - GPL Electronic Design Automation
* gparts - gEDA Parts Manager
* Copyright (C) 2012 Edward C. Hennessy
* Copyright (C) 2012 gEDA Contributors (see ChangeLog for details)
*
* 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 USA
*/
/*! \file gpview-company-view.h
*/
#define GPVIEW_TYPE_COMPANY_CTRL (gpview_company_ctrl_get_type())
#define GPVIEW_COMPANY_CTRL(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GPVIEW_TYPE_COMPANY_CTRL,GPViewCompanyCtrl))
#define GPVIEW_COMPANY_CTRL_CLASS(cls) (G_TYPE_CHECK_CLASS_CAST((cls),GPVIEW_TYPE_COMPANY_CTRL,GPViewCompanyCtrlClass))
#define GPVIEW_IS_COMPANY_CTRL(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GPVIEW_TYPE_COMPANY_CTRL))
#define GPVIEW_IS_COMPANY_CTRL_CLASS(cls) (G_TYPE_CHECK_CLASS_TYPE((cls),GPVIEW_TYPE_COMPANY_CTRL))
#define GPVIEW_COMPANY_CTRL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj),GPVIEW_TYPE_COMPANY_CTRL,GPViewCompanyCtrlClass))
/*! \extends GObject */
struct _GPViewCompanyCtrl
{
GObject parent;
};
/*! \private */
struct _GPViewCompanyCtrlClass
{
GObjectClass parent;
};
/*! \private */
GType
gpview_company_ctrl_get_type(void);
GPViewCompanyCtrl*
gpview_company_ctrl_new(void);
GPViewCompanyCtrl*
gpview_company_ctrl_new_with_manager(GtkUIManager *manager);
void
gpview_company_ctrl_set_current_view(GPViewCompanyCtrl *ctrl, GPViewCompanyView *view);
void
gpview_company_ctrl_set_ui_manager(GPViewCompanyCtrl *view, GtkUIManager *ui_manager);

545
src/gpview-company-view.c Normal file
View File

@ -0,0 +1,545 @@
/* gEDA - GPL Electronic Design Automation
* gparts - gEDA Parts Manager
* Copyright (C) 2012 Edward C. Hennessy
* Copyright (C) 2012 gEDA Contributors (see ChangeLog for details)
*
* 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 USA
*/
/*! \file gpview-company-view.c
*/
#include <glib.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include "gparts.h"
#include "gpview.h"
#define GPVIEW_COMPANY_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj),GPVIEW_TYPE_COMPANY_VIEW,GPViewCompanyViewPrivate))
enum
{
GPVIEW_COMPANY_VIEW_COMPANY_ID = 1,
GPVIEW_COMPANY_VIEW_CONTROLLER,
GPVIEW_COMPANY_VIEW_DATABASE,
GPVIEW_COMPANY_VIEW_RESULT,
GPVIEW_COMPANY_VIEW_WEBSITES
};
typedef struct _GPViewCompanyViewPrivate GPViewCompanyViewPrivate;
struct _GPViewCompanyViewPrivate
{
GPViewResultAdapter *adapter;
GPViewCompanyCtrl *controller;
GPartsDatabase *database;
GPartsDatabaseResult *result;
GtkTreeSelection *selection;
GtkTreeView *tree_view;
};
static void
gpview_company_view_activate(GPViewViewInterface *widget);
static void
gpview_company_view_changed_cb(GtkTreeSelection *selection, GPViewCompanyView *view);
static void
gpview_company_view_class_init(gpointer g_class, gpointer g_class_data);
static void
gpview_company_view_deactivate(GPViewViewInterface *widget);
static void
gpview_company_view_dispose(GObject *object);
static void
gpview_company_view_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
static void
gpview_company_view_init(GTypeInstance *instance, gpointer g_class);
static void
gpview_company_view_init_view_interface(gpointer iface, gpointer user_data);
static void
gpview_company_view_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
static void
gpview_company_view_set_result(GPViewCompanyView *view, GPartsDatabaseResult *result);
static void
gpview_company_view_update_cb(GObject *unused, GParamSpec *pspec, GPViewCompanyView *view);
static void
gpview_company_view_activate(GPViewViewInterface *widget)
{
GPViewCompanyView *view = GPVIEW_COMPANY_VIEW(widget);
if (view == NULL)
{
g_critical("Unable to obatain an instance from GPViewViewInterface");
}
else
{
GPViewCompanyViewPrivate *privat = GPVIEW_COMPANY_VIEW_GET_PRIVATE(view);
if (privat == NULL)
{
g_critical("Unable to obtain private data for a GPViewCompanyView");
}
else if (privat->controller == NULL)
{
g_critical("UPViewCompanyView has a NULL controller");
}
else
{
gpview_company_ctrl_set_current_view(privat->controller, view);
}
}
}
static void
gpview_company_view_changed_cb(GtkTreeSelection *selection, GPViewCompanyView *view)
{
if (view != NULL)
{
g_object_notify(G_OBJECT(view), "company-id");
g_object_notify(G_OBJECT(view), "websites");
}
}
static void
gpview_company_view_class_init(gpointer g_class, gpointer g_class_data)
{
GObjectClass *klasse = G_OBJECT_CLASS(g_class);
g_type_class_add_private(g_class, sizeof(GPViewCompanyViewPrivate));
klasse->dispose = gpview_company_view_dispose;
klasse->get_property = gpview_company_view_get_property;
klasse->set_property = gpview_company_view_set_property;
g_object_class_install_property(
klasse,
GPVIEW_COMPANY_VIEW_COMPANY_ID,
g_param_spec_string(
"company-id",
"Company ID",
"Company ID",
NULL,
G_PARAM_LAX_VALIDATION | G_PARAM_READABLE | G_PARAM_STATIC_STRINGS
)
);
g_object_class_install_property(
klasse,
GPVIEW_COMPANY_VIEW_CONTROLLER,
g_param_spec_object(
"controller",
"Controller",
"Controller",
GPVIEW_TYPE_COMPANY_CTRL,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS
)
);
g_object_class_install_property(
klasse,
GPVIEW_COMPANY_VIEW_DATABASE,
g_param_spec_object(
"database",
"Database",
"Database",
GPARTS_TYPE_DATABASE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS
)
);
g_object_class_install_property(
klasse,
GPVIEW_COMPANY_VIEW_RESULT,
g_param_spec_object(
"result",
"Database Result",
"Database Result",
GPARTS_TYPE_DATABASE_RESULT,
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS
)
);
g_object_class_install_property(
klasse,
GPVIEW_COMPANY_VIEW_WEBSITES,
g_param_spec_string(
"websites",
"Websites",
"Websites",
NULL,
G_PARAM_LAX_VALIDATION | G_PARAM_READABLE | G_PARAM_STATIC_STRINGS
)
);
}
static void
gpview_company_view_deactivate(GPViewViewInterface *widget)
{
GPViewCompanyView *view = GPVIEW_COMPANY_VIEW(widget);
if (view == NULL)
{
g_critical("Unable to obatain an instance from GPViewViewInterface");
}
else
{
GPViewCompanyViewPrivate *privat = GPVIEW_COMPANY_VIEW_GET_PRIVATE(view);
if (privat == NULL)
{
g_critical("Unable to obtain private data for a GPViewCompanyView");
}
else if (privat->controller == NULL)
{
g_critical("UPViewCompanyView has a NULL controller");
}
else
{
gpview_company_ctrl_set_current_view(privat->controller, NULL);
}
}
}
static void
gpview_company_view_dispose(GObject *object)
{
GPViewCompanyViewPrivate *privat = GPVIEW_COMPANY_VIEW_GET_PRIVATE(object);
if (privat != NULL)
{
if (privat->database != NULL)
{
g_object_unref(privat->database);
}
}
misc_object_chain_dispose(object);
}
static void
gpview_company_view_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
{
GPViewCompanyViewPrivate *privat = GPVIEW_COMPANY_VIEW_GET_PRIVATE(object);
if (privat != NULL)
{
switch (property_id)
{
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
}
}
}
GType
gpview_company_view_get_type(void)
{
static GType type = G_TYPE_INVALID;
if (type == G_TYPE_INVALID)
{
static const GTypeInfo tinfo = {
sizeof(GPViewCompanyViewClass), /* class_size */
NULL, /* base_init */
NULL, /* base_finalize */
gpview_company_view_class_init, /* class_init */
NULL, /* class_finalize */
NULL, /* class_data */
sizeof(GPViewCompanyView), /* instance_size */
0, /* n_preallocs */
gpview_company_view_init, /* instance_init */
NULL /* value_table */
};
static const GInterfaceInfo iinfo = {
gpview_company_view_init_view_interface, /* interface_init */
NULL, /* interface_finalize */
NULL /* interface_data */
};
type = g_type_register_static(
GTK_TYPE_SCROLLED_WINDOW,
"GPViewCompanyView",
&tinfo,
0
);
g_type_add_interface_static(type, GPVIEW_TYPE_VIEW_INTERFACE, &iinfo);
}
return type;
}
GStrv
gpview_company_view_get_websites(GPViewCompanyCtrl *ctrl)
{
GPViewCompanyViewPrivate *privat = GPVIEW_COMPANY_VIEW_GET_PRIVATE(ctrl);
GStrv websites = NULL;
if (privat != NULL)
{
gint index;
if (gpview_result_adapter_get_column_index(privat->adapter, "Website", &index))
{
websites = gpview_result_adapter_get_fields(privat->adapter, privat->selection, index);
}
}
return websites;
}
static void
gpview_company_view_init(GTypeInstance *instance, gpointer g_class)
{
GPViewCompanyViewPrivate *privat = GPVIEW_COMPANY_VIEW_GET_PRIVATE(instance);
if (privat != NULL)
{
privat->tree_view = (GtkTreeView*) gtk_tree_view_new();
gtk_scrolled_window_set_policy(
GTK_SCROLLED_WINDOW(instance),
GTK_POLICY_AUTOMATIC, /* hscrollbar_policy */
GTK_POLICY_AUTOMATIC /* vscrollbar_policy */
);
gtk_container_add(
GTK_CONTAINER(instance),
GTK_WIDGET(privat->tree_view)
);
privat->selection = gtk_tree_view_get_selection(privat->tree_view);
gtk_tree_selection_set_mode(
privat->selection,
GTK_SELECTION_MULTIPLE
);
g_signal_connect(
privat->selection,
"changed",
G_CALLBACK(gpview_company_view_changed_cb),
instance
);
g_signal_connect(
instance,
"notify::database",
G_CALLBACK(gpview_company_view_update_cb),
instance
);
}
}
static void
gpview_company_view_init_view_interface(gpointer iface, gpointer user_data)
{
GPViewViewInterface *iface2 = (GPViewViewInterface*) iface;
iface2->activate = gpview_company_view_activate;
iface2->deactivate = gpview_company_view_deactivate;
}
GPViewCompanyView*
gpview_company_view_new()
{
return GPVIEW_COMPANY_VIEW(g_object_new(GPVIEW_TYPE_COMPANY_VIEW, NULL));
}
GPViewCompanyView*
gpview_company_view_new_with_controller(GPViewCompanyCtrl *ctrl)
{
return GPVIEW_COMPANY_VIEW(g_object_new(
GPVIEW_TYPE_COMPANY_VIEW,
"controller", ctrl,
NULL
));
}
void
gpview_company_view_set_controller(GPViewCompanyView *view, GPViewCompanyCtrl *ctrl)
{
GPViewCompanyViewPrivate *privat = GPVIEW_COMPANY_VIEW_GET_PRIVATE(view);
if (privat != NULL)
{
if (privat->controller != NULL)
{
//g_signal_handlers_disconnect_by_func(
// privat->database,
// G_CALLBACK(gpview_company_view_notify_connected_cb),
// view
// );
g_object_unref(privat->controller);
}
privat->controller = ctrl;
if (privat->controller != NULL)
{
g_object_ref(privat->controller);
//g_signal_connect(
// privat->database,
// "notify::connected",
// G_CALLBACK(gpview_company_view_notify_connected_cb),
// view
// );
}
g_object_notify(G_OBJECT(view), "controller");
}
}
void
gpview_company_view_set_database(GPViewCompanyView *view, GPartsDatabase *database)
{
GPViewCompanyViewPrivate *privat = GPVIEW_COMPANY_VIEW_GET_PRIVATE(view);
if (privat != NULL)
{
if (privat->database != NULL)
{
g_signal_handlers_disconnect_by_func(
privat->database,
G_CALLBACK(gpview_company_view_update_cb),
view
);
g_object_unref(privat->database);
}
privat->database = database;
if (privat->database != NULL)
{
g_object_ref(privat->database);
g_signal_connect(
privat->database,
"notify::connected",
G_CALLBACK(gpview_company_view_update_cb),
view
);
}
g_object_notify(G_OBJECT(view), "database");
}
}
static void
gpview_company_view_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
{
GPViewCompanyView *view = GPVIEW_COMPANY_VIEW(object);
if (view != NULL)
{
switch (property_id)
{
case GPVIEW_COMPANY_VIEW_CONTROLLER:
gpview_company_view_set_controller(view, g_value_get_object(value));
break;
case GPVIEW_COMPANY_VIEW_DATABASE:
gpview_company_view_set_database(view, g_value_get_object(value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
}
}
}
static void
gpview_company_view_set_result(GPViewCompanyView *view, GPartsDatabaseResult *result)
{
GPViewCompanyViewPrivate *privat = GPVIEW_COMPANY_VIEW_GET_PRIVATE(view);
if (privat != NULL)
{
if (privat->adapter != NULL)
{
g_object_unref(privat->adapter);
}
if (privat->result != NULL)
{
g_object_unref(privat->result);
}
privat->adapter = NULL;
privat->result = result;
if (privat->result != NULL)
{
g_object_ref(privat->result);
privat->adapter = gpview_result_adapter_new(privat->result);
if (privat->adapter != NULL)
{
gpview_result_adapter_adjust_columns(privat->adapter, privat->tree_view);
}
gtk_tree_view_set_model(privat->tree_view, GTK_TREE_MODEL(privat->adapter));
}
g_object_notify(G_OBJECT(view), "company-id");
g_object_notify(G_OBJECT(view), "result");
g_object_notify(G_OBJECT(view), "websites");
}
}
static void
gpview_company_view_update_cb(GObject *unused, GParamSpec *pspec, GPViewCompanyView *view)
{
GPViewCompanyViewPrivate *privat = GPVIEW_COMPANY_VIEW_GET_PRIVATE(view);
if (privat != NULL)
{
if (privat->database != NULL)
{
GPartsDatabaseResult *result;
result = gparts_database_query(privat->database, "SELECT * FROM CompanyV", NULL);
gpview_company_view_set_result(view, result);
if (result != NULL)
{
g_object_unref(G_OBJECT(result));
}
}
}
}

60
src/gpview-company-view.h Normal file
View File

@ -0,0 +1,60 @@
/* gEDA - GPL Electronic Design Automation
* gparts - gEDA Parts Manager
* Copyright (C) 2012 Edward C. Hennessy
* Copyright (C) 2012 gEDA Contributors (see ChangeLog for details)
*
* 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 USA
*/
/*! \file gpview-company-view.h
*/
#define GPVIEW_TYPE_COMPANY_VIEW (gpview_company_view_get_type())
#define GPVIEW_COMPANY_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GPVIEW_TYPE_COMPANY_VIEW,GPViewCompanyView))
#define GPVIEW_COMPANY_VIEW_CLASS(cls) (G_TYPE_CHECK_CLASS_CAST((cls),GPVIEW_TYPE_COMPANY_VIEW,GPViewCompanyViewClass))
#define GPVIEW_IS_COMPANY_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GPVIEW_TYPE_COMPANY_VIEW))
#define GPVIEW_IS_COMPANY_VIEW_CLASS(cls) (G_TYPE_CHECK_CLASS_TYPE((cls),GPVIEW_TYPE_COMPANY_VIEW))
#define GPVIEW_COMPANY_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj),GPVIEW_TYPE_COMPANY_VIEW,GPViewCompanyViewClass))
/*! \extends GtkContainer */
struct _GPViewCompanyView
{
GtkScrolledWindow parent;
};
/*! \private */
struct _GPViewCompanyViewClass
{
GtkScrolledWindowClass parent;
};
/*! \private */
GType
gpview_company_view_get_type(void);
/*
*/
GStrv
gpview_company_view_get_websites(GPViewCompanyCtrl *ctrl);
GPViewCompanyView*
gpview_company_view_new(void);
GPViewCompanyView*
gpview_company_view_new_with_controller(GPViewCompanyCtrl *ctrl);
void
gpview_company_view_set_controller(GPViewCompanyView *view, GPViewCompanyCtrl *ctrl);

195
src/gpview-factory.c Normal file
View File

@ -0,0 +1,195 @@
/* gEDA - GPL Electronic Design Automation
* gparts - gEDA Parts Manager
* Copyright (C) 2012 Edward C. Hennessy
* Copyright (C) 2012 gEDA Contributors (see ChangeLog for details)
*
* 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 USA
*/
/*! \file gpview-factory.c
*/
#include <glib.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include "gparts.h"
#include "gpview.h"
#define GPVIEW_FACTORY_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj),GPVIEW_TYPE_FACTORY,GPViewFactoryPrivate))
enum
{
GPVIEW_FACTORY_DATABASE = 1,
};
typedef struct _GPViewFactoryPrivate GPViewFactoryPrivate;
struct _GPViewFactoryPrivate
{
GPartsDatabase *database;
};
static void
gpview_factory_class_init(gpointer g_class, gpointer g_class_data);
static void
gpview_factory_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
static void
gpview_factory_init(GTypeInstance *instance, gpointer g_class);
static void
gpview_factory_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
static void
gpview_factory_class_init(gpointer g_class, gpointer g_class_data)
{
GObjectClass *klasse = G_OBJECT_CLASS(g_class);
g_type_class_add_private(g_class, sizeof(GPViewFactoryPrivate));
klasse->get_property = gpview_factory_get_property;
klasse->set_property = gpview_factory_set_property;
g_object_class_install_property(
klasse,
GPVIEW_FACTORY_DATABASE,
g_param_spec_object(
"database",
"Database",
"Database",
GPARTS_TYPE_DATABASE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS
)
);
}
GPViewCompanyView*
gpview_factory_create_company_view(GPViewFactory *factory)
{
GPViewCompanyView *view = gpview_company_view_new();
return view;
}
static void
gpview_factory_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
{
GPViewFactoryPrivate *privat = GPVIEW_FACTORY_GET_PRIVATE(object);
if (privat != NULL)
{
switch (property_id)
{
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
}
}
}
GType
gpview_factory_get_type(void)
{
static GType type = G_TYPE_INVALID;
if (type == G_TYPE_INVALID)
{
static const GTypeInfo tinfo = {
sizeof(GPViewFactoryClass), /* class_size */
NULL, /* base_init */
NULL, /* base_finalize */
gpview_factory_class_init, /* class_init */
NULL, /* class_finalize */
NULL, /* class_data */
sizeof(GPViewFactory), /* instance_size */
0, /* n_preallocs */
gpview_factory_init, /* instance_init */
NULL /* value_table */
};
type = g_type_register_static(
G_TYPE_OBJECT,
"GPViewFactory",
&tinfo,
0
);
}
return type;
}
static void
gpview_factory_init(GTypeInstance *instance, gpointer g_class)
{
GPViewFactoryPrivate *privat = GPVIEW_FACTORY_GET_PRIVATE(instance);
if (privat != NULL)
{
}
}
GPViewFactory*
gpview_factory_new()
{
return (GPViewFactory*) g_object_new(GPVIEW_TYPE_FACTORY, NULL);
}
void
gpview_factory_set_database(GPViewFactory *view, GPartsDatabase *database)
{
GPViewFactoryPrivate *privat = GPVIEW_FACTORY_GET_PRIVATE(view);
g_debug("set_database");
if (privat != NULL)
{
if (privat->database != NULL)
{
g_object_unref(privat->database);
}
privat->database = database;
if (privat->database != NULL)
{
g_object_unref(privat->database);
}
g_object_notify(G_OBJECT(view), "database");
}
}
static void
gpview_factory_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
{
GPViewFactory *view = GPVIEW_FACTORY(object);
if (view != NULL)
{
switch (property_id)
{
case GPVIEW_FACTORY_DATABASE:
gpview_factory_set_database(view, g_value_get_object(value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
}
}
}

52
src/gpview-factory.h Normal file
View File

@ -0,0 +1,52 @@
/* gEDA - GPL Electronic Design Automation
* gparts - gEDA Parts Manager
* Copyright (C) 2012 Edward C. Hennessy
* Copyright (C) 2012 gEDA Contributors (see ChangeLog for details)
*
* 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 USA
*/
/*! \file gpview-factory.h
*/
#define GPVIEW_TYPE_FACTORY (gpview_factory_get_type())
#define GPVIEW_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GPVIEW_TYPE_FACTORY,GPViewFactory))
#define GPVIEW_FACTORY_CLASS(cls) (G_TYPE_CHECK_CLASS_CAST((cls),GPVIEW_TYPE_FACTORY,GPViewFactoryClass))
#define GPVIEW_IS_FACTORY(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GPVIEW_TYPE_FACTORY))
#define GPVIEW_IS_FACTORY_CLASS(cls) (G_TYPE_CHECK_CLASS_TYPE((cls),GPVIEW_TYPE_FACTORY))
#define GPVIEW_FACTORY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj),GPVIEW_TYPE_FACTORY,GPViewFactoryClass))
/*! \extends GObject */
struct _GPViewFactory
{
GObject parent;
};
/*! \private */
struct _GPViewFactoryClass
{
GObjectClass parent;
};
/*! \private */
GType
gpview_factory_get_type(void);
GPViewCompanyView*
gpview_factory_create_company_view(GPViewFactory *factory);
GPViewFactory*
gpview_factory_new();

45
src/gpview-forward.h Normal file
View File

@ -0,0 +1,45 @@
/* gEDA - GPL Electronic Design Automation
* gparts - gEDA Parts Manager
* Copyright (C) 2012 Edward C. Hennessy
* Copyright (C) 2012 gEDA Contributors (see ChangeLog for details)
*
* 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 USA
*/
/*! \file gpview-forward.h
*
* \brief Forward declarations
*
* This file contains all typedefs for structures related to GObjects in the
* parts manager view package.
*/
typedef struct _GPViewCompanyCtrl GPViewCompanyCtrl;
typedef struct _GPViewCompanyCtrlClass GPViewCompanyCtrlClass;
typedef struct _GPViewCompanyView GPViewCompanyView;
typedef struct _GPViewCompanyViewClass GPViewCompanyViewClass;
typedef struct _GPViewFactory GPViewFactory;
typedef struct _GPViewFactoryClass GPViewFactoryClass;
typedef struct _GPViewResultAdapter GPViewResultAdapter;
typedef struct _GPViewResultAdapterClass GPViewResultAdapterClass;
typedef struct _GPViewSymbolView GPViewSymbolView;
typedef struct _GPViewSymbolViewClass GPViewSymbolViewClass;
typedef struct _GPViewViewInterface GPViewViewInterface;

888
src/gpview-result-adapter.c Normal file
View File

@ -0,0 +1,888 @@
/* gEDA - GPL Electronic Design Automation
* gparts - gEDA Parts Manager
* Copyright (C) 2010 Edward C. Hennessy
* Copyright (C) 2010 gEDA Contributors (see ChangeLog for details)
*
* 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 USA
*/
/*! \file gpview-result-adapter.c
*/
#include "gparts.h"
#include "gpview.h"
#define GPVIEW_RESULT_ADAPTER_GET_PRIVATE(object) G_TYPE_INSTANCE_GET_PRIVATE(object,GPVIEW_TYPE_RESULT_ADAPTER,GPViewResultAdapterPrivate)
enum
{
GPVIEW_RESULT_ADAPTER_PROPID_RESULT = 1
};
typedef struct _GPViewResultAdapterGetFieldsProcData GPViewResultAdapterGetFieldsProcData;
typedef struct _GPViewResultAdapterPrivate GPViewResultAdapterPrivate;
struct _GPViewResultAdapterPrivate
{
GPartsDatabaseResult *result;
gint stamp;
};
struct _GPViewResultAdapterGetFieldsProcData
{
const GPViewResultAdapter *adapter;
GPtrArray *array;
gint index;
};
static void
gpview_result_adapter_class_init(gpointer g_class, gpointer g_class_data);
static void
gpview_result_adapter_dispose(GObject *object);
static void
gpview_result_adapter_finalize(GObject *object);
static GType
gpview_result_adapter_get_column_type(GtkTreeModel *tree_adapter, gint index);
static void
gpview_result_adapter_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
static GtkTreeModelFlags
gpview_result_adapter_get_flags(GtkTreeModel *tree_adapter);
static gboolean
gpview_result_adapter_get_iter(GtkTreeModel *tree_adapter, GtkTreeIter *iter, GtkTreePath *path);
static gint
gpview_result_adapter_get_n_columns(GtkTreeModel *tree_adapter);
static GtkTreePath*
gpview_result_adapter_get_path(GtkTreeModel *tree_adapter, GtkTreeIter *iter);
static void
gpview_result_adapter_get_value(GtkTreeModel *tree_adapter, GtkTreeIter *iter, gint column, GValue *value);
static void
gpview_result_adapter_instance_init(GTypeInstance *instance, gpointer g_class);
/*static*/ gboolean
gpview_result_adapter_iter_children(GtkTreeModel *tree_adapter, GtkTreeIter *iter, GtkTreeIter *parent);
static gboolean
gpview_result_adapter_iter_has_child(GtkTreeModel *tree_adapter, GtkTreeIter *iter);
static gboolean
gpview_result_adapter_iter_next(GtkTreeModel *tree_adapter, GtkTreeIter *iter);
static gint
gpview_result_adapter_iter_n_children(GtkTreeModel *tree_adapter, GtkTreeIter *iter);
static gboolean
gpview_result_adapter_iter_nth_child(GtkTreeModel *tree_adapter, GtkTreeIter *iter, GtkTreeIter *parent, gint n);
static gboolean
gpview_result_adapter_iter_parent(GtkTreeModel *tree_adapter, GtkTreeIter *iter, GtkTreeIter *child);
static void
gpview_result_adapter_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
static void
gpview_result_adapter_set_result(GPViewResultAdapter *adapter, GPartsDatabaseResult *result);
static void
gpview_result_adapter_tree_adapter_init(GtkTreeModelIface *iface);
static void
gpview_result_adapter_get_fields_proc(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer user_data);
static void
gpview_result_adapter_class_init(gpointer g_class, gpointer g_class_data)
{
GObjectClass* object_class = G_OBJECT_CLASS(g_class);
g_type_class_add_private(
g_class,
sizeof(GPViewResultAdapterPrivate)
);
object_class->dispose = gpview_result_adapter_dispose;
object_class->finalize = gpview_result_adapter_finalize;
object_class->get_property = gpview_result_adapter_get_property;
object_class->set_property = gpview_result_adapter_set_property;
g_object_class_install_property(
object_class,
GPVIEW_RESULT_ADAPTER_PROPID_RESULT,
g_param_spec_object(
"result",
"Database Result",
"Database Result",
GPARTS_TYPE_DATABASE_RESULT,
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS
)
);
}
static void
gpview_result_adapter_dispose(GObject *object)
{
gpview_result_adapter_set_result(GPVIEW_RESULT_ADAPTER(object), NULL);
misc_object_chain_dispose(object);
}
static void
gpview_result_adapter_finalize(GObject *object)
{
misc_object_chain_finalize(object);
}
gboolean
gpview_result_adapter_get_column_index(GPViewResultAdapter *result_adapter, const gchar *name, gint *index)
{
gboolean success;
if (result_adapter != NULL)
{
GPViewResultAdapterPrivate *privat = GPVIEW_RESULT_ADAPTER_GET_PRIVATE(result_adapter);
if (privat != NULL)
{
success = gparts_database_result_get_column_index(privat->result, name, index);
}
}
return success;
}
/*! \brief Gets the GType of a given column.
*
* \param [in] tree_adapter The GPViewResultAdapter.
* \param [in] index The zero based index of the column.
* \return The column's GType.
*/
static GType
gpview_result_adapter_get_column_type(GtkTreeModel *tree_adapter, gint index)
{
GPViewResultAdapterPrivate *privat = GPVIEW_RESULT_ADAPTER_GET_PRIVATE(tree_adapter);
GType type = G_TYPE_INVALID;
if (privat != NULL)
{
type = gparts_database_result_get_column_type(privat->result, index);
}
return type;
}
gchar*
gpview_result_adapter_get_field(GPViewResultAdapter *model, GtkTreeIter *iter, const gchar *name)
{
GPViewResultAdapterPrivate *privat = GPVIEW_RESULT_ADAPTER_GET_PRIVATE(model);
gchar *result = NULL;
if ((privat != NULL) && (privat->result != NULL))
{
gint index;
gboolean success;
success = gparts_database_result_get_column_index(privat->result, name, &index);
if (success)
{
gboolean error = FALSE;
GString *buffer = g_string_sized_new(10);
GValue value = {0};
gparts_database_result_get_field_value(
privat->result,
GPOINTER_TO_UINT(iter->user_data),
index,
&value
);
if(G_IS_VALUE(&value))
{
if (G_VALUE_HOLDS_STRING(&value))
{
g_string_printf(buffer, "%s", g_value_get_string(&value));
}
else if (G_VALUE_HOLDS_DOUBLE(&value))
{
g_string_printf(buffer, "%f", g_value_get_double(&value));
}
else if (G_VALUE_HOLDS_INT(&value))
{
g_string_printf(buffer, "%d", g_value_get_int(&value));
}
else if (g_value_type_transformable(G_VALUE_TYPE(&value), G_TYPE_STRING))
{
GValue temp = {0};
g_value_init(&temp, G_TYPE_STRING);
g_value_transform(&value, &temp);
g_string_printf(buffer, "%s", g_value_get_string(&temp));
g_value_unset(&temp);
}
else
{
error = TRUE;
}
result = g_string_free(buffer, error);
}
}
}
return result;
}
GStrv
gpview_result_adapter_get_fields(const GPViewResultAdapter *adapter, GtkTreeSelection *selection, gint index)
{
GStrv fields = NULL;
if (selection != NULL)
{
GPViewResultAdapterGetFieldsProcData data;
data.adapter = adapter;
data.array = NULL;
data.index = index;
gtk_tree_selection_selected_foreach(selection, gpview_result_adapter_get_fields_proc, &data);
if (data.array != NULL)
{
if (data.array->len > 0)
{
g_ptr_array_add(data.array, NULL);
fields = (GStrv) g_ptr_array_free(data.array, FALSE);
}
else
{
g_ptr_array_free(data.array, TRUE);
}
}
}
return fields;
}
static void
gpview_result_adapter_get_fields_proc(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer user_data)
{
GPViewResultAdapterGetFieldsProcData *data = (GPViewResultAdapterGetFieldsProcData*) user_data;
if (data != NULL)
{
GPViewResultAdapterPrivate *privat = GPVIEW_RESULT_ADAPTER_GET_PRIVATE(data->adapter);
if (privat != NULL)
{
GValue value = {0};
gparts_database_result_get_field_value(
privat->result,
GPOINTER_TO_UINT(iter->user_data),
data->index,
&value
);
if(G_IS_VALUE(&value))
{
GString *buffer = g_string_sized_new(10);
gboolean error = FALSE;
if (G_VALUE_HOLDS_STRING(&value))
{
g_string_printf(buffer, "%s", g_value_get_string(&value));
}
else if (G_VALUE_HOLDS_DOUBLE(&value))
{
g_string_printf(buffer, "%f", g_value_get_double(&value));
}
else if (G_VALUE_HOLDS_INT(&value))
{
g_string_printf(buffer, "%d", g_value_get_int(&value));
}
else if (g_value_type_transformable(G_VALUE_TYPE(&value), G_TYPE_STRING))
{
GValue temp = {0};
g_value_init(&temp, G_TYPE_STRING);
g_value_transform(&value, &temp);
g_string_printf(buffer, "%s", g_value_get_string(&temp));
g_value_unset(&temp);
}
else
{
error = TRUE;
}
if (!error)
{
if (buffer->str[0] != '\0')
{
if (data->array == NULL)
{
data->array = g_ptr_array_new();
}
g_ptr_array_add(data->array, g_string_free(buffer, FALSE));
}
else
{
g_string_free(buffer, TRUE);
}
}
else
{
g_string_free(buffer, TRUE);
}
}
}
}
}
/*! \brief
*
*
*
*
*/
static void
gpview_result_adapter_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
{
GPViewResultAdapterPrivate *privat = GPVIEW_RESULT_ADAPTER_GET_PRIVATE(object);
if (privat != NULL)
{
switch ( property_id )
{
case GPVIEW_RESULT_ADAPTER_PROPID_RESULT:
g_value_set_object(value, privat->result);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
}
}
}
/*! \brief Gets this model's GtkTreeModelFlags.
*
* \param [in] tree_adapter The GPViewResultAdapter.
* \return This model's GtkTreeModelFlags.
*/
static GtkTreeModelFlags
gpview_result_adapter_get_flags(GtkTreeModel *tree_adapter)
{
return GTK_TREE_MODEL_LIST_ONLY;
}
/*! \brief Converts a tree path to a tree iterator.
*
* This function will fail if the path does not refer to a valid node in the
* tree model.
*
* \param [in] tree_adapter The GPViewResultAdapter
* \param [out] iter If successful, a GtkTreeIter. Invalid if unsuccessful.
* \param [in] path The GtkTreePath to convert to a GtkTreeIter.
* \return TRUE if successful and iter is valid. FALSE if otherwise and the
* iter will not be valid.
*/
static gboolean
gpview_result_adapter_get_iter(GtkTreeModel *tree_adapter, GtkTreeIter *iter, GtkTreePath *path)
{
GPViewResultAdapterPrivate *private = GPVIEW_RESULT_ADAPTER_GET_PRIVATE(tree_adapter);
gint index = gtk_tree_path_get_indices(path)[0];
guint rows = gparts_database_result_get_row_count(private->result);
if (index < rows)
{
iter->stamp = private->stamp;
iter->user_data = GUINT_TO_POINTER(index);
return TRUE;
}
return FALSE;
}
/*! \brief Returns the number of columns in the tree model.
*
* \param [in] tree_adapter The GPViewResultAdapter.
* \param [in] tree_adapter The given tree model.
* \return The number of columns in the tree model.
*/
static gint
gpview_result_adapter_get_n_columns(GtkTreeModel *tree_adapter)
{
GPViewResultAdapterPrivate *private = GPVIEW_RESULT_ADAPTER_GET_PRIVATE(tree_adapter);
return gparts_database_result_get_column_count(private->result);
}
/*! \brief Converts a GtkTreeIter to a GtkTreePath.
*
* \param [in] tree_adapter The GPViewResultAdapter.
* \param [in] iter The iterator to convert to a tree path.
* \return A GtkTreePath that refers to the same node as the iterator.
*/
static GtkTreePath*
gpview_result_adapter_get_path(GtkTreeModel *tree_adapter, GtkTreeIter *iter)
{
GPViewResultAdapterPrivate *private = GPVIEW_RESULT_ADAPTER_GET_PRIVATE(tree_adapter);
g_assert(iter != NULL);
g_assert(iter->stamp == private->stamp);
GtkTreePath *tree_path = gtk_tree_path_new();
gtk_tree_path_append_index(tree_path, GPOINTER_TO_INT(iter->user_data));
return tree_path;
}
/*! \brief Register this class's GType.
*
* \return The GType of this class.
*/
GType
gpview_result_adapter_get_type( void )
{
static GType type = 0;
if ( type == 0 )
{
static const GTypeInfo tinfo = {
sizeof(GPViewResultAdapterClass),
NULL,
NULL,
gpview_result_adapter_class_init,
NULL,
NULL,
sizeof(GPViewResultAdapter),
0,
gpview_result_adapter_instance_init,
NULL
};
static const GInterfaceInfo iinfo = {
(GInterfaceInitFunc) gpview_result_adapter_tree_adapter_init,
NULL,
NULL
};
type = g_type_register_static(
G_TYPE_OBJECT,
"gpview-result-adapter",
&tinfo,
0
);
g_type_add_interface_static(
type,
GTK_TYPE_TREE_MODEL,
&iinfo
);
}
return type;
}
/*! \brief Get a value from the tree model.
*
* This function turns invalid values into blanks. So, an invalid column or
* row will still result in a valid GValue.
*
* \param [in] tree_adapter The GPViewResultAdapter.
* \param [in] iter An iterator referencing the value's row.
* \param [in] column A zero based index of the value's column.
* \param [out] value The value of the cell as a GValue.
*/
static void
gpview_result_adapter_get_value(GtkTreeModel *tree_adapter, GtkTreeIter *iter, gint column, GValue *value)
{
GPViewResultAdapterPrivate *private = GPVIEW_RESULT_ADAPTER_GET_PRIVATE(tree_adapter);
g_assert(iter != NULL);
g_assert(iter->stamp == private->stamp);
gparts_database_result_get_field_value(
private->result,
GPOINTER_TO_UINT(iter->user_data),
column,
value
);
/* Turn uninitialized values into blanks */
if (!G_IS_VALUE(value))
{
g_value_init(value, G_TYPE_STRING);
}
}
/*! \brief Initialize instance data.
*
* \param instance
* \param g_class
*/
static void
gpview_result_adapter_instance_init(GTypeInstance* instance, gpointer g_class)
{
GPViewResultAdapterPrivate *privat = GPVIEW_RESULT_ADAPTER_GET_PRIVATE(instance);
if (privat != NULL)
{
privat->stamp = g_random_int();
}
}
/*! \brief Gets an iterator to a list's first child.
*
* If the parent is NULL, this function gets an iterator to the first node in
* the root list. Since this model does not implement trees, all other cases
* return FALSE.
*
* \param [in] tree_adapter The GPViewResultAdapter.
* \param [out] iter If successful, the first child of parent.
* \param [in] parent The parent node.
* \retval TRUE if successful and iter is valid.
* \retval FALSE if otherwise and the iter will not be valid.
*/
/*static*/ gboolean
gpview_result_adapter_iter_children(GtkTreeModel *tree_adapter, GtkTreeIter *iter, GtkTreeIter *parent)
{
gboolean success = FALSE;
if (parent == NULL)
{
GPViewResultAdapterPrivate *privat = GPVIEW_RESULT_ADAPTER_GET_PRIVATE(tree_adapter);
if (privat != NULL)
{
iter->stamp = privat->stamp;
iter->user_data = GINT_TO_POINTER(0);
success = TRUE;
}
}
return success;
}
/*! \brief Determines if a node has children.
*
* Since this model only handles lists, this function always returns FALSE.
*
* \param [in] tree_adapter Unused.
* \param [out] iter Unused.
* \return FALSE, always.
*/
static gboolean
gpview_result_adapter_iter_has_child(GtkTreeModel *tree_adapter, GtkTreeIter *iter)
{
return FALSE;
}
/*! \brief Get the next node in sequence.
*
* \param [in] tree_adapter The GPViewResultAdapter.
* \param [in,out] iter The node on entry. If successful, the next node.
* \return TRUE if successful and iter is valid. FALSE if otherwise and the
* iter will not be valid.
*/
static gboolean
gpview_result_adapter_iter_next(GtkTreeModel *tree_adapter, GtkTreeIter *iter)
{
guint new_position;
guint old_position;
GPViewResultAdapterPrivate *private = GPVIEW_RESULT_ADAPTER_GET_PRIVATE(tree_adapter);
g_assert(iter != NULL);
g_assert(iter->stamp == private->stamp);
old_position = GPOINTER_TO_UINT(iter->user_data);
new_position = old_position + 1;
if (new_position > old_position)
{
guint rows = gparts_database_result_get_row_count(private->result);
if (new_position < rows)
{
iter->user_data = GUINT_TO_POINTER(new_position);
return TRUE;
}
}
return FALSE;
}
/*! \brief Returns the number of children a node contains.
*
* Since this model only handles lists, this function returns 0.
*
* \param [in] tree_adapter The GPViewResultAdapter.
* \param [in] iter The given node.
* \return The number of iter's children.
*/
static gint
gpview_result_adapter_iter_n_children(GtkTreeModel *tree_adapter, GtkTreeIter *iter)
{
gint rows = 0;
if (iter == NULL)
{
GPViewResultAdapterPrivate *privat = GPVIEW_RESULT_ADAPTER_GET_PRIVATE(tree_adapter);
if (privat != NULL)
{
rows = gparts_database_result_get_row_count(privat->result);
}
}
return rows;
}
/*! \brief Gets an iterator to a node's nth child.
*
* If the parent is NULL, this function gets an iterator to the nth node in
* the root list. Since this model only implements lists, in all other cases,
* this function returns FALSE.
*
* \param [in] tree_adapter The GPViewResultAdapter.
* \param [out] iter If successful, the nth child of the parent node.
* \param [in] parent The parent node.
* \param [in] n The zero based index of the child node.
* \return TRUE if successful and iter is valid. FALSE if otherwise and the
* iter will not be valid.
*/
static gboolean
gpview_result_adapter_iter_nth_child(GtkTreeModel *tree_adapter, GtkTreeIter *iter, GtkTreeIter *parent, gint n)
{
gboolean success = FALSE;
g_assert(iter != NULL);
if (parent == NULL)
{
GPViewResultAdapterPrivate *privat = GPVIEW_RESULT_ADAPTER_GET_PRIVATE(tree_adapter);
if (privat != NULL)
{
guint rows = gparts_database_result_get_row_count(privat->result);
if (n < rows)
{
iter->stamp = privat->stamp;
iter->user_data = GINT_TO_POINTER(n);
success = TRUE;
}
}
}
return success;
}
/*! \brief Obtains the parent node of a child node.
*
* Since this model only implements lists, this function always returns FALSE.
*
* \param [in] tree_adapter The GPViewResultAdapter.
* \param [out] iter If successful, the parent node.
* \param [in] child The child node.
* \return TRUE if successful and iter is valid. FALSE if otherwise and the
* iter will not be valid.
*/
static gboolean
gpview_result_adapter_iter_parent(GtkTreeModel *tree_adapter, GtkTreeIter *iter, GtkTreeIter *child)
{
return FALSE;
}
GPViewResultAdapter*
gpview_result_adapter_new(GPartsDatabaseResult *result)
{
return GPVIEW_RESULT_ADAPTER(g_object_new(
GPVIEW_TYPE_RESULT_ADAPTER,
"result", result,
NULL
));
}
void
gpview_result_adapter_adjust_columns(const GPViewResultAdapter *adapter, GtkTreeView *view)
{
GPViewResultAdapterPrivate *privat = GPVIEW_RESULT_ADAPTER_GET_PRIVATE(adapter);
if (privat != NULL)
{
gint columns;
GtkTreeViewColumn *column;
gint index;
GValue value = {0};
columns = gparts_database_result_get_column_count(privat->result);
g_value_init(&value, G_TYPE_STRING);
for(index=0; index<columns; index++)
{
GList *list;
column = gtk_tree_view_get_column(view, index);
if (column == NULL)
{
GtkCellRenderer *renderer = gtk_cell_renderer_text_new();
column = gtk_tree_view_column_new();
g_object_set(
column,
"resizable", TRUE,
"reorderable", TRUE,
"sizing", GTK_TREE_VIEW_COLUMN_GROW_ONLY,
NULL
);
gtk_tree_view_column_pack_start(column, renderer, TRUE);
gtk_tree_view_column_add_attribute(column, renderer, "text", index);
gtk_tree_view_append_column(view, column);
}
list = gtk_tree_view_column_get_cell_renderers(column);
if (list != NULL)
{
GList *node = g_list_first(list);
while (node != NULL)
{
GType type = gparts_database_result_get_column_type(privat->result, index);
if (type == G_TYPE_STRING)
{
g_object_set(G_OBJECT(node->data), "xalign", 0.0, NULL );
}
else
{
g_object_set(G_OBJECT(node->data), "xalign", 1.0, NULL );
}
node = g_list_next(node);
}
}
g_list_free(list);
gparts_database_result_get_column_value(privat->result, index, &value);
g_object_set_property(G_OBJECT(column), "title", &value);
}
g_value_unset(&value);
/* Delete any additional columns */
column = gtk_tree_view_get_column(view, columns);
while (column != NULL)
{
gtk_tree_view_remove_column(view, column);
column = gtk_tree_view_get_column(view, columns);
}
}
}
static void
gpview_result_adapter_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
{
switch ( property_id )
{
case GPVIEW_RESULT_ADAPTER_PROPID_RESULT:
gpview_result_adapter_set_result(GPVIEW_RESULT_ADAPTER(object), GPARTS_DATABASE_RESULT(g_value_get_object(value)));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
}
}
static void
gpview_result_adapter_set_result(GPViewResultAdapter *adapter, GPartsDatabaseResult *result)
{
GPViewResultAdapterPrivate *privat = GPVIEW_RESULT_ADAPTER_GET_PRIVATE(adapter);
if (privat != NULL)
{
if (privat->result != NULL)
{
g_object_unref(privat->result);
}
privat->result = result;
if (privat->result != NULL)
{
g_object_ref(privat->result);
}
g_object_notify(G_OBJECT(adapter), "result");
}
}
/*! \brief Initialize the tree model interface.
*
* \param [in] iface A pointer to the tree model interface.
*/
static void
gpview_result_adapter_tree_adapter_init(GtkTreeModelIface *iface)
{
if (iface != NULL)
{
iface->get_flags = gpview_result_adapter_get_flags;
iface->get_n_columns = gpview_result_adapter_get_n_columns;
iface->get_column_type = gpview_result_adapter_get_column_type;
iface->get_iter = gpview_result_adapter_get_iter;
iface->get_path = gpview_result_adapter_get_path;
iface->get_value = gpview_result_adapter_get_value;
iface->iter_next = gpview_result_adapter_iter_next;
iface->iter_children = gpview_result_adapter_iter_children;
iface->iter_has_child = gpview_result_adapter_iter_has_child;
iface->iter_n_children = gpview_result_adapter_iter_n_children;
iface->iter_nth_child = gpview_result_adapter_iter_nth_child;
iface->iter_parent = gpview_result_adapter_iter_parent;
}
}

View File

@ -0,0 +1,87 @@
/* gEDA - GPL Electronic Design Automation
* gparts - gEDA Parts Manager
* Copyright (C) 2010 Edward C. Hennessy
* Copyright (C) 2010 gEDA Contributors (see ChangeLog for details)
*
* 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 USA
*/
/*! \file gpview-result-adapter.h
*/
#define GPVIEW_TYPE_RESULT_ADAPTER (gpview_result_adapter_get_type())
#define GPVIEW_RESULT_ADAPTER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GPVIEW_TYPE_RESULT_ADAPTER,GPViewResultAdapter))
#define GPVIEW_RESULT_ADAPTER_CLASS(cls) (G_TYPE_CHECK_CLASS_CAST((cls),GPVIEW_TYPE_RESULT_ADAPTER,GPViewResultAdapterClass))
#define GPVIEW_IS_RESULT_ADAPTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GPVIEW_TYPE_RESULT_ADAPTER))
#define GPVIEW_IS_RESULT_ADAPTER_CLASS(cls) (G_TYPE_CHECK_CLASS_TYPE((cls),GPVIEW_TYPE_RESULT_ADAPTER))
#define GPVIEW_RESULT_ADAPTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj),GPVIEW_TYPE_RESULT_ADAPTER,GPViewResultAdapterClass))
struct _GPViewResultAdapter
{
GObject parent;
};
/*! \private */
struct _GPViewResultAdapterClass
{
GObjectClass parent;
};
/*! \private */
GType
gpview_result_adapter_get_type(void);
/*! \brief Adjust the GtkTreeView's columns to match this adapter's.
*
* \public
* \memberof _GPViewResultAdapter
*
* \param [in] adapter
* \param [in,out] view
*/
void
gpview_result_adapter_adjust_columns(const GPViewResultAdapter *adapter, GtkTreeView *view);
/*! \brief Get the index of a column, given the name
*
* \param [in] adapter
* \param [in] name
* \param [out] index
* \retval TRUE
* \retval FALSE
*/
gboolean
gpview_result_adapter_get_column_index(GPViewResultAdapter *adapter, const gchar *name, gint *index);
GStrv
gpview_result_adapter_get_fields(const GPViewResultAdapter *adapter, GtkTreeSelection *selection, gint index);
/*! \brief Get the database result
*
* \param [in] adapter
* \return
*/
GPartsDatabaseResult*
gpview_result_adapter_get_result(const GPViewResultAdapter *adapter);
/*! \brief Create a new adapter
*
* \param [in] result
* \return
*/
GPViewResultAdapter*
gpview_result_adapter_new(GPartsDatabaseResult *result);

367
src/gpview-symbol-view.c Normal file
View File

@ -0,0 +1,367 @@
/* gEDA - GPL Electronic Design Automation
* gparts - gEDA Parts Manager
* Copyright (C) 2012 Edward C. Hennessy
* Copyright (C) 2012 gEDA Contributors (see ChangeLog for details)
*
* 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 USA
*/
/*! \file gpview-symbol-view.c
*/
#include <glib.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include "gparts.h"
#include "gpview.h"
#include "schgui.h"
#define GPVIEW_SYMBOL_VIEW_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj),GPVIEW_TYPE_SYMBOL_VIEW,GPViewSymbolViewPrivate))
enum
{
GPVIEW_SYMBOL_VIEW_DATABASE = 1,
};
typedef struct _GPViewSymbolViewPrivate GPViewSymbolViewPrivate;
struct _GPViewSymbolViewPrivate
{
GPartsDatabase *database;
GPartsDatabaseResult *result;
SchGUIDrawingView *drawing_view;
GtkTreeView *symbol_view;
};
static void
gpview_symbol_view_activate(GPViewViewInterface *widget);
static void
gpview_symbol_view_class_init(gpointer g_class, gpointer g_class_data);
static void
gpview_symbol_view_deactivate(GPViewViewInterface *widget);
static void
gpview_symbol_view_dispose(GObject *object);
static void
gpview_symbol_view_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
static void
gpview_symbol_view_init(GTypeInstance *instance, gpointer g_class);
static void
gpview_symbol_view_init_view_interface(gpointer iface, gpointer user_data);
static void
gpview_symbol_view_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
static void
gpview_symbol_view_notify_connected_cb(GPartsDatabase *database, GParamSpec *param, GPViewSymbolView *view);
static void
gpview_symbol_view_activate(GPViewViewInterface *widget)
{
GPViewSymbolView *view = GPVIEW_SYMBOL_VIEW(widget);
if (view == NULL)
{
g_critical("Unable to");
}
else
{
g_debug("Activate");
}
}
static void
gpview_symbol_view_class_init(gpointer g_class, gpointer g_class_data)
{
GObjectClass *klasse = G_OBJECT_CLASS(g_class);
g_type_class_add_private(g_class, sizeof(GPViewSymbolViewPrivate));
klasse->dispose = gpview_symbol_view_dispose;
klasse->get_property = gpview_symbol_view_get_property;
klasse->set_property = gpview_symbol_view_set_property;
g_object_class_install_property(
klasse,
GPVIEW_SYMBOL_VIEW_DATABASE,
g_param_spec_object(
"database",
"Database",
"Database",
GPARTS_TYPE_DATABASE,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS
)
);
}
static void
gpview_symbol_view_deactivate(GPViewViewInterface *widget)
{
GPViewSymbolView *view = GPVIEW_SYMBOL_VIEW(widget);
if (view == NULL)
{
g_critical("Unable to");
}
else
{
g_debug("Dectivate");
}
}
static void
gpview_symbol_view_dispose(GObject *object)
{
GPViewSymbolViewPrivate *privat = GPVIEW_SYMBOL_VIEW_GET_PRIVATE(object);
if (privat != NULL)
{
if (privat->database != NULL)
{
g_object_unref(privat->database);
}
}
misc_object_chain_dispose(object);
}
static void
gpview_symbol_view_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
{
GPViewSymbolViewPrivate *privat = GPVIEW_SYMBOL_VIEW_GET_PRIVATE(object);
if (privat != NULL)
{
switch (property_id)
{
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
}
}
}
GType
gpview_symbol_view_get_type(void)
{
static GType type = G_TYPE_INVALID;
if (type == G_TYPE_INVALID)
{
static const GTypeInfo tinfo = {
sizeof(GPViewSymbolViewClass), /* class_size */
NULL, /* base_init */
NULL, /* base_finalize */
gpview_symbol_view_class_init, /* class_init */
NULL, /* class_finalize */
NULL, /* class_data */
sizeof(GPViewSymbolView), /* instance_size */
0, /* n_preallocs */
gpview_symbol_view_init, /* instance_init */
NULL /* value_table */
};
static const GInterfaceInfo iinfo = {
gpview_symbol_view_init_view_interface, /* interface_init */
NULL, /* interface_finalize */
NULL /* interface_data */
};
type = g_type_register_static(
GTK_TYPE_HPANED,
"GPViewSymbolView",
&tinfo,
0
);
g_type_add_interface_static(type, GPVIEW_TYPE_VIEW_INTERFACE, &iinfo);
}
return type;
}
static void
gpview_symbol_view_init(GTypeInstance *instance, gpointer g_class)
{
GPViewSymbolViewPrivate *privat = GPVIEW_SYMBOL_VIEW_GET_PRIVATE(instance);
if (privat != NULL)
{
GtkWidget *scrolled;
privat->symbol_view = (GtkTreeView*) gtk_tree_view_new();
scrolled = gtk_scrolled_window_new(
NULL, /* hadjustment */
NULL /* vadjustment */
);
gtk_scrolled_window_set_policy(
GTK_SCROLLED_WINDOW(scrolled),
GTK_POLICY_AUTOMATIC, /* hscrollbar_policy */
GTK_POLICY_AUTOMATIC /* vscrollbar_policy */
);
gtk_container_add(
GTK_CONTAINER(scrolled),
GTK_WIDGET(privat->symbol_view)
);
gtk_container_add(
GTK_CONTAINER(instance),
GTK_WIDGET(scrolled)
);
privat->drawing_view = schgui_drawing_view_new();
gtk_container_add(
GTK_CONTAINER(instance),
GTK_WIDGET(privat->drawing_view)
);
}
}
static void
gpview_symbol_view_init_view_interface(gpointer iface, gpointer user_data)
{
GPViewViewInterface *iface2 = (GPViewViewInterface*) iface;
if (iface2 == NULL)
{
}
else
{
iface2->activate = gpview_symbol_view_activate;
iface2->deactivate = gpview_symbol_view_deactivate;
}
}
GPViewSymbolView*
gpview_symbol_view_new()
{
return (GPViewSymbolView*) g_object_new(GPVIEW_TYPE_SYMBOL_VIEW, NULL);
}
static void
gpview_symbol_view_notify_connected_cb(GPartsDatabase *database, GParamSpec *param, GPViewSymbolView *view)
{
gpview_symbol_view_refresh(view);
}
void
gpview_symbol_view_refresh(GPViewSymbolView *view)
{
GPViewSymbolViewPrivate *privat = GPVIEW_SYMBOL_VIEW_GET_PRIVATE(view);
g_debug("gpview_symbol_view_refresh");
if (privat != NULL)
{
if (privat->result != NULL)
{
g_object_unref(privat->result);
privat->result = NULL;
}
if (privat->database != NULL)
{
GPViewResultAdapter *model = NULL;
privat->result = gparts_database_query(privat->database, "SELECT * FROM SymbolV", NULL);
if (privat->result != NULL)
{
model = gpview_result_adapter_new(privat->result);
}
if (model != NULL)
{
gpview_result_adapter_adjust_columns(model, privat->symbol_view);
}
gtk_tree_view_set_model(privat->symbol_view, GTK_TREE_MODEL(model));
}
}
}
void
gpview_symbol_view_set_database(GPViewSymbolView *view, GPartsDatabase *database)
{
GPViewSymbolViewPrivate *privat = GPVIEW_SYMBOL_VIEW_GET_PRIVATE(view);
g_debug("set_database");
if (privat != NULL)
{
if (privat->database != NULL)
{
g_signal_handlers_disconnect_by_func(
privat->database,
G_CALLBACK(gpview_symbol_view_notify_connected_cb),
view
);
g_object_unref(privat->database);
}
privat->database = database;
if (privat->database != NULL)
{
g_object_unref(privat->database);
g_signal_connect(
privat->database,
"notify::connected",
G_CALLBACK(gpview_symbol_view_notify_connected_cb),
view
);
}
g_object_notify(G_OBJECT(view), "database");
gpview_symbol_view_refresh(view);
}
}
static void
gpview_symbol_view_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec)
{
GPViewSymbolView *view = GPVIEW_SYMBOL_VIEW(object);
if (view != NULL)
{
switch (property_id)
{
case GPVIEW_SYMBOL_VIEW_DATABASE:
gpview_symbol_view_set_database(view, g_value_get_object(value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
}
}
}

52
src/gpview-symbol-view.h Normal file
View File

@ -0,0 +1,52 @@
/* gEDA - GPL Electronic Design Automation
* gparts - gEDA Parts Manager
* Copyright (C) 2012 Edward C. Hennessy
* Copyright (C) 2012 gEDA Contributors (see ChangeLog for details)
*
* 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 USA
*/
/*! \file gpview-symbol-view.h
*/
#define GPVIEW_TYPE_SYMBOL_VIEW (gpview_symbol_view_get_type())
#define GPVIEW_SYMBOL_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GPVIEW_TYPE_SYMBOL_VIEW,GPViewSymbolView))
#define GPVIEW_SYMBOL_VIEW_CLASS(cls) (G_TYPE_CHECK_CLASS_CAST((cls),GPVIEW_TYPE_SYMBOL_VIEW,GPViewSymbolViewClass))
#define GPVIEW_IS_SYMBOL_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GPVIEW_TYPE_SYMBOL_VIEW))
#define GPVIEW_IS_SYMBOL_VIEW_CLASS(cls) (G_TYPE_CHECK_CLASS_TYPE((cls),GPVIEW_TYPE_SYMBOL_VIEW))
#define GPVIEW_SYMBOL_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj),GPVIEW_TYPE_SYMBOL_VIEW,GPViewSymbolViewClass))
/*! \extends GtkContainer */
struct _GPViewSymbolView
{
GtkHPaned parent;
};
/*! \private */
struct _GPViewSymbolViewClass
{
GtkHPanedClass parent;
};
/*! \private */
GType
gpview_symbol_view_get_type(void);
GPViewSymbolView*
gpview_symbol_view_new();
void
gpview_symbol_view_refresh(GPViewSymbolView *view);

101
src/gpview-view-interface.c Normal file
View File

@ -0,0 +1,101 @@
/* gEDA - GPL Electronic Design Automation
* gparts - gEDA Parts Manager
* Copyright (C) 2011 Edward C. Hennessy
* Copyright (C) 2011 gEDA Contributors (see ChangeLog for details)
*
* 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 USA
*/
/*! \file gpview-view-interface.c
*/
#include <glib.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include "gparts.h"
#include "gpview.h"
GType
gpview_view_interface_get_type(void)
{
static GType type = G_TYPE_INVALID;
if (type == G_TYPE_INVALID)
{
static const GTypeInfo tinfo = {
sizeof(GPViewViewInterface), /* class_size */
NULL, /* base_init */
NULL, /* base_finalize */
NULL, /* class_init */
NULL, /* class_finalize */
NULL, /* class_data */
0, /* instance_size */
0, /* n_preallocs */
NULL, /* instance_init */
NULL /* value_table */
};
type = g_type_register_static(
G_TYPE_INTERFACE,
"GPViewViewInterface",
&tinfo,
0
);
}
return type;
}
void
gpview_view_interface_activate(GPViewViewInterface *widget)
{
GPViewViewInterface *iface = GPVIEW_VIEW_INTERFACE_GET_INTERFACE(widget);
if (iface == NULL)
{
g_critical("Unable to get GPViewViewInterface from parameter");
}
else if (iface->activate == NULL)
{
g_critical("GPViewViewInterface contains NULL activate() function pointer");
}
else
{
iface->activate(widget);
}
}
void
gpview_view_interface_deactivate(GPViewViewInterface *widget)
{
GPViewViewInterface *iface = GPVIEW_VIEW_INTERFACE_GET_INTERFACE(widget);
if (iface == NULL)
{
g_critical("Unable to get GPViewViewInterface from parameter");
}
else if (iface->deactivate == NULL)
{
g_critical("GPViewViewInterface contains NULL deactivate() function pointer");
}
else
{
iface->deactivate(widget);
}
}

View File

@ -0,0 +1,48 @@
/* gEDA - GPL Electronic Design Automation
* gparts - gEDA Parts Manager
* Copyright (C) 2012 Edward C. Hennessy
* Copyright (C) 2012 gEDA Contributors (see ChangeLog for details)
*
* 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 USA
*/
/*! \file gpview-view-interface.h
*/
#define GPVIEW_TYPE_VIEW_INTERFACE (gpview_view_interface_get_type())
#define GPVIEW_VIEW_INTERFACE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GPVIEW_TYPE_VIEW_INTERFACE,GPViewViewInterface))
#define GPVIEW_IS_VIEW_INTERFACE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GPVIEW_TYPE_VIEW_INTERFACE))
#define GPVIEW_VIEW_INTERFACE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE((obj),GPVIEW_TYPE_VIEW_INTERFACE,GPViewViewInterface))
/*! \private
*/
struct _GPViewViewInterface
{
GTypeInterface parent;
void (*activate)(GPViewViewInterface *widget);
void (*deactivate)(GPViewViewInterface *widget);
};
/*! \private */
GType
gpview_view_interface_get_type(void);
void
gpview_view_interface_activate(GPViewViewInterface *widget);
void
gpview_view_interface_deactivate(GPViewViewInterface *widget);

37
src/gpview.h Normal file
View File

@ -0,0 +1,37 @@
/* gEDA - GPL Electronic Design Automation
* gparts - gEDA Parts Manager
* Copyright (C) 2012 Edward C. Hennessy
* Copyright (C) 2012 gEDA Contributors (see ChangeLog for details)
*
* 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 USA
*/
/*! \defgroup gpview Parts Manager Views
*/
/*! \file gpview.h
*/
#include <gtk/gtk.h>
#include "gpview-forward.h"
#include "gpview-company-ctrl.h"
#include "gpview-company-view.h"
#include "gpview-factory.h"
#include "gpview-result-adapter.h"
#include "gpview-symbol-view.h"
#include "gpview-view-interface.h"

View File

@ -222,6 +222,8 @@ schgui_clipboard_get_cb(GtkClipboard *clipboard, GtkSelectionData *data, guint i
sch_drawing_write(privat->drawing, ostream);
g_debug("Get clipboard target: %d", info);
switch (info)
{
case 1:

View File

@ -365,6 +365,12 @@ schgui_drawing_view_init(GTypeInstance *instance, gpointer g_class)
);
}
SchGUIDrawingView*
schgui_drawing_view_new(void)
{
return SCHGUI_DRAWING_VIEW(g_object_new(SCHGUI_TYPE_DRAWING_VIEW, NULL));
}
static void
schgui_drawing_view_set_background_color(SchGUIDrawingView *widget, GdkColor *color)
{

View File

@ -44,6 +44,9 @@ struct _SchGUIDrawingViewClass
GType
schgui_drawing_view_get_type(void);
SchGUIDrawingView*
schgui_drawing_view_new(void);
/*! \brief Get the configuration for this view
*
* \public

View File

@ -355,6 +355,8 @@ scmcfg_config_init_inner(void* data)
char *configdir;
char *datadir;
SCM scm1;
scm_dynwind_begin(0);
configdir = scmcfg_dirs_find_geda_config();
@ -369,6 +371,22 @@ scmcfg_config_init_inner(void* data)
scm_c_define("geda-rc-path", scm_from_locale_string(configdir));
scm_c_define("path-sep", scm_from_locale_string(G_DIR_SEPARATOR_S));
g_debug("Here");
scm1 = scm_c_lookup("%load-path");
g_debug("Here");
scm_variable_set_x(
scm1,
scm_cons(
scm_from_locale_string(g_build_filename(datadir,"scheme")),
scm_variable_ref(scm1)
)
);
g_debug("Here");
#include "scmcfg-config.x"
scm_dynwind_end();
@ -409,28 +427,6 @@ scmcfg_config_load_inner(void* data)
g_free(pathname);
}
if (loaded == SCM_BOOL_F)
{
loaded = scm_internal_catch(
SCM_BOOL_T,
scmcfg_config_load_inner_body,
"/usr/local/share/gEDA/system-gafrc",
scmcfg_config_load_inner_handler,
NULL
);
}
if (loaded == SCM_BOOL_F)
{
loaded = scm_internal_catch(
SCM_BOOL_T,
scmcfg_config_load_inner_body,
"/usr/local/gEDA/system-gafrc",
scmcfg_config_load_inner_handler,
NULL
);
}
if (loaded == SCM_BOOL_F)
{
g_warning("Unable to locate a system-gafrc");
@ -475,6 +471,8 @@ scmcfg_config_load_inner(void* data)
static SCM
scmcfg_config_load_inner_body(void *data)
{
g_debug("Before Load %s", (char*) data);
scm_c_primitive_load((char*) data);
g_debug("Loaded %s", (char*) data);
@ -485,10 +483,7 @@ scmcfg_config_load_inner_body(void *data)
static SCM
scmcfg_config_load_inner_handler(void *data, SCM key, SCM args)
{
scm_write_line(
args,
scm_current_output_port()
);
scm_handle_by_message(NULL, key, args);
return SCM_BOOL_F;
}

View File

@ -6,6 +6,7 @@ xmldir = $(pkgdatadir)/xml/forms
xml_DATA = \
company-add.xml \
company-delete.xml \
diode-add.xml \
footprint-add.xml \
package-add.xml

View File

@ -0,0 +1,78 @@
<?xml version="1.0"?>
<!-- -->
<!-- -->
<!-- -->
<!-- -->
<!-- -->
<!-- The dialog must be GPFormUIDialog and its id must be main. -->
<!-- -->
<!-- -->
<!-- The named entity "&omega;" does not work, use "&#x03A9;" instead. -->
<!-- -->
<interface>
<object class="GPFormUIDialog" id="main">
<property name="title">Delete Company</property>
<child internal-child="action_area">
<object class="GtkHButtonBox" id="button-box">
<child>
<object class="GtkButton" id="button-cancel">
<property name="label">gtk-cancel</property>
<property name="use-stock">TRUE</property>
</object>
</child>
<child>
<object class="GtkButton" id="button-help">
<property name="label">gtk-help</property>
<property name="use-stock">TRUE</property>
</object>
</child>
<child>
<object class="GtkButton" id="button-ok">
<property name="label">gtk-ok</property>
<property name="use-stock">TRUE</property>
</object>
</child>
</object>
</child>
<child internal-child="vbox">
<object class="GtkVBox" id="vbox">
<child>
<object class="GtkLabel" id="label-1">
<property name="label">Are you sure you want to delete the company?</property>
<property name="xalign">0.0</property>
<property name="xpad">10</property>
<property name="ypad">10</property>
</object>
</child>
<child>
<object class="GtkLabel" id="label-2">
<property name="label">COMPANY NAME</property>
<property name="xalign">0.5</property>
<property name="xpad">10</property>
<property name="ypad">10</property>
</object>
</child>
<child>
<object class="GtkLabel" id="label-3">
<property name="label">Deleting a company will also delete all parts associated with the company.</property>
<property name="xalign">0.0</property>
<property name="xpad">10</property>
<property name="ypad">10</property>
</object>
</child>
</object>
</child>
<action-widgets>
<action-widget response="-6">button-cancel</action-widget>
<action-widget response="-11">button-help</action-widget>
<action-widget response="-5">button-ok</action-widget>
</action-widgets>
</object>
</interface>