summaryrefslogtreecommitdiff
path: root/components/services/inventory/eazel-inventory.c
blob: 377490e2487deda6ed2468c6e8c31973f5b4e5e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: 8; c-basic-offset: 8 -*- */

/*
 * Copyright (C) 2001 Eazel, Inc.
 *
 * Nautilus 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.
 *
 * Nautilus 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., 675 Mass Ave, Cambridge, MA 02139, USA.
 */


#include <config.h>
#include "eazel-inventory.h"

#include "eazel-inventory-upload-callback.h"
#include "eazel-inventory-service-interface.h"
#include <libnautilus-extensions/nautilus-gtk-macros.h>
#include <bonobo/bonobo-object-client.h>

#define EAZEL_INVENTORY_IID "OAFIID:trilobite_inventory_service:eaae1152-1551-43d5-a764-52274131a9d5"

struct EazelInventoryDetails {
        Trilobite_Eazel_Inventory corba_inventory;
};


static void eazel_inventory_initialize_class (EazelInventoryClass *klass);
static void eazel_inventory_initialize       (EazelInventory      *factory);
static void eazel_inventory_destroy          (GtkObject                            *object);


NAUTILUS_DEFINE_CLASS_BOILERPLATE (EazelInventory, eazel_inventory, GTK_TYPE_OBJECT)

static void
eazel_inventory_initialize_class  (EazelInventoryClass *klass)
{
	GtkObjectClass *object_class;
	
	object_class = (GtkObjectClass*) klass;
	object_class->destroy = eazel_inventory_destroy;
}

static void
eazel_inventory_initialize (EazelInventory *factory)
{
	BonoboObjectClient *object_client;

	factory->details = g_new0 (EazelInventoryDetails, 1);

	object_client = bonobo_object_activate (EAZEL_INVENTORY_IID, 0);
	if (object_client != NULL) {
		factory->details->corba_inventory = bonobo_object_query_interface 
			(BONOBO_OBJECT (object_client), "IDL:Trilobite/Eazel/Inventory:1.0");
		bonobo_object_unref (BONOBO_OBJECT (object_client)); 
	}
}


static EazelInventory *global_eazel_inventory = NULL;

static void
eazel_inventory_destroy (GtkObject *object)
{
        EazelInventory *inventory;

	inventory = EAZEL_INVENTORY (object);

	if (inventory->details->corba_inventory != CORBA_OBJECT_NIL) {
		bonobo_object_release_unref (inventory->details->corba_inventory, NULL);
	}

	g_free (inventory->details);

	global_eazel_inventory = NULL;
}


EazelInventory *
eazel_inventory_get (void)
{
	if (global_eazel_inventory == NULL) {
		global_eazel_inventory = EAZEL_INVENTORY
			(gtk_object_new (EAZEL_TYPE_INVENTORY, NULL));
 		gtk_object_ref (GTK_OBJECT (global_eazel_inventory));
		gtk_object_sink (GTK_OBJECT (global_eazel_inventory));
		if (global_eazel_inventory->details->corba_inventory == CORBA_OBJECT_NIL) {
		         gtk_object_unref (GTK_OBJECT (global_eazel_inventory));
		         global_eazel_inventory = NULL;
		}
	} else {
 		gtk_object_ref (GTK_OBJECT (global_eazel_inventory));
	}



	return global_eazel_inventory;
}

gboolean
eazel_inventory_get_enabled (EazelInventory *inventory)
{
	gboolean enabled;
	CORBA_Environment ev;

	CORBA_exception_init (&ev);
	enabled = Trilobite_Eazel_Inventory__get_enabled (inventory->details->corba_inventory,
							  &ev);
	CORBA_exception_free (&ev);
							  
	return enabled;
}

void
eazel_inventory_set_enabled (EazelInventory *inventory,
			     gboolean        enabled)
{
	CORBA_Environment ev;

	CORBA_exception_init (&ev);
	Trilobite_Eazel_Inventory__set_enabled (inventory->details->corba_inventory,
						enabled,
						&ev);
	CORBA_exception_free (&ev);
}


char *
eazel_inventory_get_machine_id (EazelInventory *inventory)
{
	CORBA_char *corba_id;
	gchar *g_id;
	CORBA_Environment ev;

	CORBA_exception_init (&ev);
	corba_id = Trilobite_Eazel_Inventory__get_machine_id (inventory->details->corba_inventory,
							      &ev);
	CORBA_exception_free (&ev);
							  
	g_id = g_strdup (corba_id);
	CORBA_free (corba_id);
	
	return g_id;
}


void
eazel_inventory_upload (EazelInventory *inventory,
			EazelInventoryDoneCallback done_callback,
			gpointer callback_data)
{
	EazelInventoryUploadCallback *callback;
	Trilobite_Eazel_InventoryUploadCallback corba_callback;
	CORBA_Environment ev;

	callback = eazel_inventory_upload_callback_new (inventory,
							done_callback,
							callback_data);

	corba_callback = bonobo_object_corba_objref (BONOBO_OBJECT (callback));

	CORBA_exception_init (&ev);
	Trilobite_Eazel_Inventory_upload (inventory->details->corba_inventory,
					  corba_callback,
					  &ev);
	CORBA_Object_release (corba_callback, &ev);
	CORBA_exception_free (&ev);
}