mico-glue.cc 5.58 KB
Newer Older
Arturo Espinosa's avatar
Arturo Espinosa committed
1 2 3 4 5 6
#include <iostream.h>
#include <mico/gtkmico.h>
#include <mico/naming.h>
#include <gnome.h>
#include "mico-glue.h"
#include "gnome-panel.h"
7
#include "panel.h"
8
#include "mico-parse.h"
Tom Tromey's avatar
Tom Tromey committed
9

Arturo Espinosa's avatar
Arturo Espinosa committed
10 11 12 13 14 15 16 17
/* This implements the server-side of the gnome-panel.idl
 * specification Currently there is no way to create new CORBA
 * "instances" of the panel, as there is only one panel running on the
 * screen.
 * */
   
class Panel_impl : virtual public GNOME::Panel_skel {
public:
18
	CORBA::Short applet_request_id (const char *path,
19
					char *&cfgpath,
20 21
					char *&globcfgpath,
					CORBA::ULong &wid) {
22 23
		char *cfg=NULL;
		char *globcfg=NULL;
24
		int id;
25 26 27 28
		guint32 winid;

		id = ::applet_request_id (path,&cfg,&globcfg,&winid);
		wid = winid;
29

30 31 32 33 34 35 36 37 38 39
		if(cfg) {
			cfgpath = CORBA::string_dup(cfg);
			g_free(cfg);
		} else 
			cfgpath = CORBA::string_dup("");
		if(globcfg) {
			globcfgpath = CORBA::string_dup(globcfg);
			g_free(globcfg);
		} else
			globcfgpath = CORBA::string_dup("");
40
		return id;
41
	}
42 43 44
	void applet_register (const char *ior, CORBA::Short id) {
		::applet_register(ior, id);
	}
45
	void applet_abort_id (CORBA::Short id) {
46
		::applet_abort_id (id);
47 48 49 50 51 52 53 54 55 56 57
	}
	void applet_request_glob_cfg (char *&globcfgpath) {
		char *globcfg=NULL;

		::applet_request_glob_cfg (&globcfg);
		if(globcfg) {
			globcfgpath = CORBA::string_dup(globcfg);
			g_free(globcfg);
		} else
			globcfgpath = CORBA::string_dup("");
	}
58 59 60 61 62 63
	CORBA::Short applet_get_panel (CORBA::Short id) {
		return ::applet_get_panel (id);
	}
	CORBA::Short applet_get_pos (CORBA::Short id) {
		return ::applet_get_pos (id);
	}
64 65 66
	void applet_show_menu (CORBA::Short id) {
		::applet_show_menu (id);
	}
67 68 69 70 71
	void applet_drag_start (CORBA::Short id) {
		::applet_drag_start (id);
	}
	void applet_drag_stop (CORBA::Short id) {
		::applet_drag_stop (id);
72 73
	}
	void applet_remove_from_panel (CORBA::Short id) {
74
		printf ("APPLET_REMOVE_FROM_PANEL not implemented!\n");
75
		/*FIXME:  */
Arturo Espinosa's avatar
Arturo Espinosa committed
76
	}
77
        void applet_add_callback (CORBA::Short id,
78 79
				  const char *callback_name,
				  const char *menuitem_text) {
80 81 82
		::applet_add_callback(id,
				      (char *)callback_name,
				      (char *)menuitem_text);
83
	}
84 85 86 87 88 89
	void applet_add_tooltip (CORBA::Short id, const char *tooltip) {
		/*FIXME*/
	}
	void applet_remove_tooltip (CORBA::Short id) {
		/*FIXME*/
	}
90 91
	void quit(void) {
		::panel_quit();
92
	}
Arturo Espinosa's avatar
Arturo Espinosa committed
93 94
};

95 96 97
CORBA::ORB_ptr orb_ptr;
CORBA::BOA_ptr boa_ptr;

Arturo Espinosa's avatar
Arturo Espinosa committed
98
void
99
panel_corba_gtk_main (char *service_name)
Arturo Espinosa's avatar
Arturo Espinosa committed
100 101 102 103 104
{
	GNOME::Panel_ptr acc = new Panel_impl ();
	char hostname [4096];
	char *name;

Tom Tromey's avatar
Tom Tromey committed
105
	panel_initialize_corba (&orb_ptr, &boa_ptr);
106

Arturo Espinosa's avatar
Arturo Espinosa committed
107 108 109 110 111 112 113
	gethostname (hostname, sizeof (hostname));
	if (hostname [0] == 0)
		strcpy (hostname, "unknown-host");

	name = g_copy_strings ("/CORBA-servers/Panel-", hostname, 
			       "/DISPLAY-", getenv ("DISPLAY"), NULL);

114
	gnome_config_set_string (name, orb_ptr->object_to_string (acc));
Arturo Espinosa's avatar
Arturo Espinosa committed
115 116 117
	gnome_config_sync ();
	g_free (name);
	
118 119
	orb_ptr->dispatcher (new GtkDispatcher ());
	boa_ptr->impl_is_ready (CORBA::ImplementationDef::_nil());
Arturo Espinosa's avatar
Arturo Espinosa committed
120 121
}

122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
int
panel_corba_call_launcher(const char *path)
{
	char *name;
	char *iior;
	char hostname [1024];
	
	gethostname (hostname, sizeof (hostname));
	if (hostname [0] == 0)
		strcpy (hostname, "unknown-host");

	name = g_copy_strings ("/CORBA-servers/Launcher-", hostname, 
			       "/DISPLAY-", getenv ("DISPLAY"), NULL);

	iior = gnome_config_get_string (name);
	g_free (name);
	
	if (!iior)
140
		return FALSE;
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
	CORBA::Object_var obj = orb_ptr->string_to_object (iior);
	GNOME::Launcher_var launcher_client = GNOME::Launcher::_narrow (obj);

	try {
		launcher_client->start_new_launcher(path);
	} catch( ... ) {
		return FALSE;
	}
	
	return TRUE;
}

int
panel_corba_restart_launchers(void)
{
	char *name;
	char *iior;
	char hostname [1024];
	
	gethostname (hostname, sizeof (hostname));
	if (hostname [0] == 0)
		strcpy (hostname, "unknown-host");

	name = g_copy_strings ("/CORBA-servers/Launcher-", hostname, 
			       "/DISPLAY-", getenv ("DISPLAY"), NULL);

	iior = gnome_config_get_string (name);
	g_free (name);
	
	if (!iior)
		return FALSE;
173

174 175 176
	CORBA::Object_var obj = orb_ptr->string_to_object (iior);
	GNOME::Launcher_var launcher_client = GNOME::Launcher::_narrow (obj);

177 178 179 180 181
	try {
		launcher_client->restart_all_launchers();
	} catch( ... ) {
		return FALSE;
	}
182
	
183
	return TRUE;
184 185
}

186
void
187 188
send_applet_session_save (const char *ior, int id, const char *cfgpath,
			  const char *globcfgpath)
189 190 191 192 193 194
{
	/* Use the ior that was sent to us to get an Applet CORBA object */
	CORBA::Object_var obj = orb_ptr->string_to_object (ior);
	GNOME::Applet_var applet = GNOME::Applet::_narrow (obj);

	/* Now, use corba to invoke the routine in the panel */
195
	applet->session_save(id,cfgpath,globcfgpath);
196 197 198
}

void
199
send_applet_shutdown_applet (const char *ior, int id)
200 201 202 203 204 205
{
	/* Use the ior that was sent to us to get an Applet CORBA object */
	CORBA::Object_var obj = orb_ptr->string_to_object (ior);
	GNOME::Applet_var applet = GNOME::Applet::_narrow (obj);

	/* Now, use corba to invoke the routine in the panel */
206
	applet->shutdown_applet(id);
207 208 209 210
}

void
send_applet_change_orient (const char *ior, int id, int orient)
211 212
{
	/* Use the ior that was sent to us to get an Applet CORBA object */
213
	CORBA::Object_var obj = orb_ptr->string_to_object (ior);
214 215 216
	GNOME::Applet_var applet = GNOME::Applet::_narrow (obj);

	/* Now, use corba to invoke the routine in the panel */
217
	applet->change_orient(id,orient);
218
}
219 220 221 222

void
send_applet_do_callback (const char *ior, int id, char *callback_name)
{
223 224 225 226 227 228
	/* Use the ior that was sent to us to get an Applet CORBA object */
	CORBA::Object_var obj = orb_ptr->string_to_object (ior);
	GNOME::Applet_var applet = GNOME::Applet::_narrow (obj);

	/* Now, use corba to invoke the routine in the panel */
	applet->do_callback(id, callback_name);
229
}