session.c 24.4 KB
Newer Older
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
/* Gnome panel: panel functionality
 * (C) 1997 the Free Software Foundation
 *
 * Authors:  George Lebl
 *           Federico Mena
 *           Miguel de Icaza
 */

#include <config.h>
#include <string.h>
#include <signal.h>
#include <gnome.h>
#include <gdk/gdkx.h>

#include "panel-include.h"

int config_sync_timeout = 0;
GList *applets_to_sync = NULL;
int panels_to_sync = FALSE;
int globals_to_sync = FALSE;
int need_complete_save = FALSE;

extern GArray *applets;
extern int applet_count;

extern GtkTooltips *panel_tooltips;

extern GnomeClient *client;

GlobalConfig global_config = {
		DEFAULT_AUTO_HIDE_STEP_SIZE,
		DEFAULT_EXPLICIT_HIDE_STEP_SIZE,
		DEFAULT_MINIMIZED_SIZE,
		DEFAULT_MINIMIZE_DELAY,
		TRUE, /*tooltips*/
36 37 38 39 40
		TRUE, /*show small icons*/
		TRUE, /*logout question*/
		PANEL_SWITCH_MOVE,
		FALSE, /*disable anims*/
		3 /*applet padding*/
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
	};

char *panel_cfg_path=NULL;
char *old_panel_cfg_path=NULL;

/*list of all panel widgets created*/
extern GList *panel_list;

/*a list of started extern applet child processes*/
extern GList * children;

/*send the tooltips state to all external applets*/
static void
send_tooltips_state(int enabled)
{
	GList *list;
	
	for(list = children;list!=NULL;list = g_list_next(list)) {
		AppletChild *child = list->data;
		AppletInfo *info = get_applet_info(child->applet_id);
		Extern *ext = info->data;
		g_assert(ext);
		/*if it's not set yet, don't send it, it will be sent when
		  the ior is discovered anyhow, so this would be redundant
		  anyway*/
		if(ext->ior)
			send_applet_tooltips_state(ext->ior,enabled);
	}
}

void
apply_global_config(void)
{
74
	int i;
75 76 77 78 79 80
	panel_widget_change_global(global_config.explicit_hide_step_size,
				   global_config.auto_hide_step_size,
				   global_config.drawer_step_size,
				   global_config.minimized_size,
				   global_config.minimize_delay,
				   global_config.movement_type,
81 82
				   global_config.disable_animations,
				   global_config.applet_padding);
83 84 85 86 87 88
	if(global_config.tooltips_enabled)
		gtk_tooltips_enable(panel_tooltips);
	else
		gtk_tooltips_disable(panel_tooltips);
	set_show_small_icons();
	send_tooltips_state(global_config.tooltips_enabled);
89
	button_widget_tile_enable(global_config.tiles_enabled);
90 91 92 93 94 95
	for(i=0;i<LAST_TILE;i++) {
		button_widget_load_tile(i, global_config.tile_up[i],
					global_config.tile_down[i],
					global_config.tile_border[i],
					global_config.tile_depth[i]);
	}
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
/*shouldn't this be in gnome-dentry?? :)*/
static void
gnome_desktop_entry_save_no_sync (GnomeDesktopEntry *dentry)
{
	char *prefix;
	
	g_assert (dentry != NULL);
	g_assert (dentry->location != NULL);

	prefix = g_copy_strings ("=", dentry->location, "=/Desktop Entry", NULL);

	gnome_config_clean_section (prefix);

	prefix = g_copy_strings (prefix, "/", NULL);
	gnome_config_push_prefix (prefix);
	g_free (prefix);

	if (dentry->name)
		gnome_config_set_translated_string ("Name", dentry->name);

	if (dentry->comment)
		gnome_config_set_translated_string ("Comment", dentry->comment);

	if (dentry->exec)
		gnome_config_set_vector ("Exec", dentry->exec_length,
					 (const char * const *) dentry->exec);

	if (dentry->tryexec)
		gnome_config_set_string ("TryExec", dentry->tryexec);

	if (dentry->icon)
		gnome_config_set_string ("Icon", dentry->icon);

	if (dentry->geometry)
		gnome_config_set_string ("Geometry", dentry->geometry);
	
	if (dentry->docpath)
		gnome_config_set_string ("DocPath", dentry->docpath);

	gnome_config_set_bool ("Terminal", dentry->terminal);
	gnome_config_set_bool ("MultipleArgs", dentry->multiple_args);
	
	if (dentry->type)
		gnome_config_set_string ("Type", dentry->type);

	gnome_config_pop_prefix ();
}
145 146 147 148 149 150 151 152 153 154 155 156 157


static void
save_applet_configuration(int num)
{
	char           path[256];
	int            panel_num;
	PanelWidget   *panel;
	AppletData    *ad;
	AppletInfo    *info = get_applet_info(num);
	
	g_return_if_fail(info!=NULL);

158
	g_snprintf(path,256, "%sApplet_Config/Applet_%d/", panel_cfg_path, num+1);
159 160 161 162 163 164
	gnome_config_push_prefix(path);

	/*obviously no need for saving*/
	if(info->type==APPLET_EXTERN_PENDING ||
	   info->type==APPLET_EXTERN_RESERVED ||
	   info->type==APPLET_EMPTY) {
165
		gnome_config_set_string("id", EMPTY_ID);
166 167 168 169 170 171 172 173 174
		gnome_config_pop_prefix();
		return;
	}

	panel = gtk_object_get_data(GTK_OBJECT(info->widget),
				    PANEL_APPLET_PARENT_KEY);
	ad = gtk_object_get_data(GTK_OBJECT(info->widget),PANEL_APPLET_DATA);

	if((panel_num = g_list_index(panels,panel)) == -1) {
175
		gnome_config_set_string("id", EMPTY_ID);
176 177 178 179 180 181 182 183 184
		gnome_config_pop_prefix();
		return;
	}

	switch(info->type) {
	case APPLET_EXTERN:
		{
			char *globalcfg;
			Extern *ext = info->data;
185 186 187
/*this should no longer be needed on our side, we don't write anything
  to the applet's file and it doesn't write anything to ours*/
#if 0
188 189 190 191 192 193
			/*sync before the applet does it's stuff*/
			gnome_config_sync();
			/*I think this should be done at sync and also that
			  there should be some flocking ... but this works
			  for now*/
			gnome_config_drop_all();
194
#endif
195 196

			globalcfg = g_copy_strings(panel_cfg_path,
197
						   "Applet_All_Extern/",NULL);
198

199 200 201 202
			/*this is the file path we pass to the applet for it's
			  own config, this is a separate file, so that we */
			g_snprintf(path,256, "%sApplet_%d_Extern/",
				   panel_cfg_path, num+1);
203 204 205 206
			/*have the applet do it's own session saving*/
			if(send_applet_session_save(ext->ior,info->applet_id,
						    path, globalcfg)) {

207 208
				gnome_config_set_string("id", EXTERN_ID);
				gnome_config_set_string("execpath",
209
							ext->path);
210
				gnome_config_set_string("parameters",
211 212 213
							ext->params);
			} else {
				g_free(globalcfg);
214
				gnome_config_set_string("id", EMPTY_ID);
215 216 217 218 219 220 221 222 223 224 225
				gnome_config_pop_prefix();
				return;
			}
			g_free(globalcfg);
			break;
		}
	case APPLET_DRAWER: 
		{
			int i;
			Drawer *drawer = info->data;

226
			gnome_config_set_string("id", DRAWER_ID);
227 228 229 230

			i = g_list_index(panels,
					 DRAWER_WIDGET(drawer->drawer)->panel);
			if(i>=0)
231
				gnome_config_set_int("parameters",i);
232 233
			else
				g_warning("Drawer not associated with applet!");
234
			gnome_config_set_string("pixmap",
235
						drawer->pixmap);
236
			gnome_config_set_string("tooltip",
237 238 239 240 241 242
						drawer->tooltip);
			break;
		}
	case APPLET_SWALLOW:
		{
			Swallow *swallow = info->data;
243 244
			gnome_config_set_string("id", SWALLOW_ID);
			gnome_config_set_string("parameters",
245
						swallow->title);
246
			gnome_config_set_string("execpath",
247
						swallow->path);
248 249
			gnome_config_set_int("width",swallow->width);
			gnome_config_set_int("height",swallow->height);
250 251 252 253 254
			break;
		}
	case APPLET_MENU:
		{
			Menu *menu = info->data;
255 256
			gnome_config_set_string("id", MENU_ID);
			gnome_config_set_string("parameters",
257
						menu->path);
258
			gnome_config_set_int("main_menu_type",
259 260 261 262 263 264
					     menu->main_menu_type);
			break;
		}
	case APPLET_LAUNCHER:
		{
			Launcher *launcher = info->data;
265 266 267 268
			/*we set the .desktop to be in the panel config
			  dir*/
			g_snprintf(path,256, "%s/%sApplet_%d.desktop",
				   gnome_user_dir,panel_cfg_path, num+1);
269
			g_free(launcher->dentry->location);
270 271 272 273 274
			launcher->dentry->location = g_strdup(path);
			gnome_desktop_entry_save_no_sync(launcher->dentry);

			gnome_config_set_string("id", LAUNCHER_ID);
			gnome_config_set_string("parameters", path);
275 276 277
			break;
		}
	case APPLET_LOGOUT:
278
		gnome_config_set_string("id", LOGOUT_ID);
279
		break;
280 281
	default:
		g_assert_not_reached();
282
	}
283 284 285
	gnome_config_set_int("position", ad->pos);
	gnome_config_set_int("panel", panel_num);
	gnome_config_set_bool("right_stick",
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
			      panel_widget_is_applet_stuck(panel,
							   info->widget));
	gnome_config_pop_prefix();
}

static void
save_panel_configuration(gpointer data, gpointer user_data)
{
	char           path[256];
	char           buf[32];
	int           *num = user_data;
	PanelData     *pd = data;
	PanelWidget   *panel = get_def_panel_widget(pd->panel);

	g_snprintf(path,256, "%spanel/Panel_%d/", panel_cfg_path, (*num)++);
	gnome_config_clean_section(path);

	gnome_config_push_prefix (path);

	gnome_config_set_int("type",pd->type);
	
	switch(pd->type) {
	case SNAPPED_PANEL:
		{
		SnappedWidget *snapped = SNAPPED_WIDGET(pd->panel);
		gnome_config_set_int("pos", snapped->pos);
		gnome_config_set_int("mode", snapped->mode);
		gnome_config_set_int("state", snapped->state);
314 315
		gnome_config_set_bool("hidebuttons_enabled",
				      snapped->hidebuttons_enabled);
316 317 318 319 320 321 322 323 324 325 326 327 328
		break;
		}
	case CORNER_PANEL:
		{
		CornerWidget *corner = CORNER_WIDGET(pd->panel);
		gnome_config_set_int("pos", corner->pos);
		gnome_config_set_int("orient",panel->orient);
		gnome_config_set_int("state", corner->state);
		break;
		}
	case DRAWER_PANEL:
		{
		DrawerWidget *drawer = DRAWER_WIDGET(pd->panel);
329
		gnome_config_set_int("orient",drawer->orient);
330 331 332
		gnome_config_set_int("state", drawer->state);
		break;
		}
333 334
	default:
		g_assert_not_reached();
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437
	}
	gnome_config_set_bool("fit_pixmap_bg", panel->fit_pixmap_bg);

	gnome_config_set_string("backpixmap",
				panel->back_pixmap ? panel->back_pixmap : "");

	g_snprintf(buf, sizeof(buf), "#%02x%02x%02x",
		   (guint)panel->back_color.red/256,
		   (guint)panel->back_color.green/256,
		   (guint)panel->back_color.blue/256);
	gnome_config_set_string("backcolor", buf);

	gnome_config_set_int("back_type", panel->back_type);

	gnome_config_pop_prefix ();
}

static void
do_session_save(GnomeClient *client,
		int complete_sync,
		GList *sync_applets,
		int sync_panels,
		int sync_globals)
{
	int num;
	char *buf;
	char *session_id;
	int i;

	session_id = gnome_client_get_id (client);
	if(session_id) {
		char *new_args[3];

		g_free(panel_cfg_path);
		panel_cfg_path = g_copy_strings("/panel.d/Session-",session_id,
						"/",NULL);

		new_args[0] = (char *) gtk_object_get_data(GTK_OBJECT(client),
							   "argv0");
		new_args[1] = "--discard-session";
		new_args[2] = session_id;
		gnome_client_set_discard_command (client, 3, new_args);
	}
	
	printf("Saving to [%s]\n",panel_cfg_path);

	/*take out the trailing / then call the clean_file function,
	  otherwise it will make runaway directories*/
	buf = g_strdup(panel_cfg_path);
	if(buf && *buf)
		buf[strlen(buf)-1]='\0';
	gnome_config_clean_file(buf);
	g_free(buf);

	/*DEBUG*/printf("Saving session: 1"); fflush(stdout);
	if(complete_sync) {
		for(i=0;i<applet_count;i++)
			save_applet_configuration(i);
	} else {
		while(sync_applets) {
			save_applet_configuration(GPOINTER_TO_INT(sync_applets->data));
			sync_applets = g_list_remove_link(sync_applets,
							  sync_applets);
		}
	}
	/*DEBUG*/printf(" 2"); fflush(stdout);

	buf = g_copy_strings(panel_cfg_path,"panel/Config/",NULL);
	gnome_config_push_prefix (buf);
	g_free(buf);

	if(complete_sync)
		gnome_config_set_int ("applet_count", applet_count);
	/*DEBUG*/printf(" 3"); fflush(stdout);
	if(complete_sync || sync_panels) {
		num = 1;
		g_list_foreach(panel_list, save_panel_configuration,&num);
		gnome_config_set_int("panel_count",num-1);
	}
	/*DEBUG*/printf(" 4"); fflush(stdout);

	if(complete_sync || sync_globals) {
		/*global options*/
		gnome_config_set_int("auto_hide_step_size",
				     global_config.auto_hide_step_size);
		gnome_config_set_int("explicit_hide_step_size",
				     global_config.explicit_hide_step_size);
		gnome_config_set_int("drawer_step_size",
				     global_config.drawer_step_size);
		gnome_config_set_int("minimized_size",
				     global_config.minimized_size);
		gnome_config_set_int("minimize_delay",
				     global_config.minimize_delay);
		gnome_config_set_int("movement_type",
				     (int)global_config.movement_type);
		gnome_config_set_bool("tooltips_enabled",
				      global_config.tooltips_enabled);
		gnome_config_set_bool("show_small_icons",
				      global_config.show_small_icons);
		gnome_config_set_bool("prompt_for_logout",
				      global_config.prompt_for_logout);
		gnome_config_set_bool("disable_animations",
				      global_config.disable_animations);
438 439
		gnome_config_set_int("applet_padding",
				     global_config.applet_padding);
440 441
		gnome_config_set_bool("tiles_enabled",
				      global_config.tiles_enabled);
442 443 444 445 446 447 448 449 450 451 452
		for(i=0;i<LAST_TILE;i++) {
			char buf[256];
			g_snprintf(buf,256,"tile_up_%d",i);
			gnome_config_set_string(buf,global_config.tile_up[i]);
			g_snprintf(buf,256,"tile_down_%d",i);
			gnome_config_set_string(buf,global_config.tile_down[i]);
			g_snprintf(buf,256,"tile_border_%d",i);
			gnome_config_set_int(buf,global_config.tile_border[i]);
			g_snprintf(buf,256,"tile_depth_%d",i);
			gnome_config_set_int(buf,global_config.tile_depth[i]);
		}
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513
	}

	gnome_config_pop_prefix ();
	gnome_config_sync();
	
	/*DEBUG*/puts("");
}

void
panel_config_sync(void)
{
	if(need_complete_save ||
	   applets_to_sync ||
	   panels_to_sync ||
	   globals_to_sync) {
		do_session_save(client,need_complete_save,
				applets_to_sync,panels_to_sync,globals_to_sync);
		need_complete_save = FALSE;
		g_list_free(applets_to_sync);
		applets_to_sync = NULL;
		panels_to_sync = FALSE;
		globals_to_sync = FALSE;
	}
}


/* This is called when the session manager requests a shutdown.  It
   can also be run directly when we don't detect a session manager.
   We assume no interaction is done by the applets.  And we ignore the
   other arguments for now.  Yes, this is lame.  */
/* update: some SM stuff implemented but we still ignore most of the
   arguments now*/
int
panel_session_save (GnomeClient *client,
		    int phase,
		    GnomeSaveStyle save_style,
		    int is_shutdown,
		    GnomeInteractStyle interact_style,
		    int is_fast,
		    gpointer client_data)
{
	do_session_save(client,TRUE,NULL,FALSE,FALSE);
	/* Always successful.  */
	return TRUE;
}

int
panel_session_die (GnomeClient *client,
		   gpointer client_data)
{
	AppletInfo *info;
	int i;

	gtk_timeout_remove(config_sync_timeout);
  
	/*don't catch these any more*/
	signal(SIGCHLD, SIG_DFL);
	
	for(i=0,info=(AppletInfo *)applets->data;
	    i<applet_count;
	    i++,info++) {
514 515
		if(info->type == APPLET_EXTERN) {
			gtk_container_remove(GTK_CONTAINER(info->applet_widget->parent),
516
					     info->applet_widget);
517
		} else if(info->type == APPLET_SWALLOW) {
518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595
			Swallow *swallow = info->data;
			XKillClient(GDK_DISPLAY(),
				    GDK_WINDOW_XWINDOW(GTK_SOCKET(swallow->socket)->plug_window));
		}
	}
			
	
	/*clean up corba stuff*/
	panel_corba_clean_up();
	
	panel_corba_gtk_main_quit();
	return TRUE;
}

/*save ourselves*/
static int
panel_really_logout(GtkWidget *w, int button, gpointer data)
{
	GtkWidget **box=data;

	if(button==0) {
		if (! GNOME_CLIENT_CONNECTED (client)) {
			panel_session_save (client, 1, GNOME_SAVE_BOTH, 1,
					    GNOME_INTERACT_NONE, 0, NULL);
			panel_session_die (client, NULL);
		} else {
			/* We request a completely interactive, full,
			   slow shutdown.  */
			gnome_client_request_save (client, GNOME_SAVE_BOTH, 1,
						   GNOME_INTERACT_ANY, 0, 1);
		}
	}
	if(box)
		*box = NULL;

	return TRUE;
}

static int
panel_really_logout_destroy(GtkWidget *w, gpointer data)
{
	GtkWidget **box=data;
	if(box)
		*box = NULL;
	return FALSE;
}


static void
ask_next_time(GtkWidget *w,gpointer data)
{
	global_config.prompt_for_logout = GTK_TOGGLE_BUTTON(w)->active!=FALSE;
	
	globals_to_sync = TRUE;
}

/* the logout function */
void
panel_quit(void)
{
	static GtkWidget *box = NULL;
	GtkWidget *but = NULL;

	if(!global_config.prompt_for_logout) {
		panel_really_logout(NULL,0,NULL);
		return;
	}

	if(box) {
		gdk_window_raise(box->window);
		return;
	}

	box = gnome_message_box_new (_("Really log out?"),
				     GNOME_MESSAGE_BOX_QUESTION,
				     GNOME_STOCK_BUTTON_YES,
				     GNOME_STOCK_BUTTON_NO,
				     NULL);
596
	/*gtk_window_position(GTK_WINDOW(box), GTK_WIN_POS_CENTER);*/
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618
	gtk_window_set_policy(GTK_WINDOW(box), FALSE, FALSE, TRUE);

	gtk_signal_connect (GTK_OBJECT (box), "clicked",
		            GTK_SIGNAL_FUNC (panel_really_logout), &box);
	gtk_signal_connect (GTK_OBJECT (box), "destroy",
		            GTK_SIGNAL_FUNC (panel_really_logout_destroy),
			    &box);

	but = gtk_check_button_new_with_label(_("Ask next time"));
	gtk_widget_show(but);
	gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(box)->vbox),but,
		           FALSE, TRUE, GNOME_PAD_SMALL);
	gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(but),TRUE);
	gtk_signal_connect(GTK_OBJECT(but),"toggled",
			   GTK_SIGNAL_FUNC(ask_next_time),NULL);

	gtk_widget_show (box);
}

static void
load_default_applets(void)
{
619 620 621
	load_menu_applet(NULL,0, panels->data, 0);
	load_extern_applet("gen_util_applet","--clock",NULL,
			   panels->data,INT_MAX/2/*right flush*/);
622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639
	/*we laoded default applets, so we didn't find the config or
	  something else was wrong, so do complete save when next syncing*/
	need_complete_save = TRUE;
}

void
init_user_applets(void)
{
	char  buf[256];
	int   count,num;	

	g_snprintf(buf,256,"%spanel/Config/applet_count=0",old_panel_cfg_path);
	count=gnome_config_get_int(buf);
	for(num=1;num<=count;num++) {
		char *applet_name;
		int   pos=0,panel_num;
		PanelWidget *panel;

640
		g_snprintf(buf,256, "%sApplet_Config/Applet_%d/",
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677
			   old_panel_cfg_path, num);
		gnome_config_push_prefix(buf);
		applet_name = gnome_config_get_string("id=Unknown");
		
		if(strcmp(applet_name,EMPTY_ID)==0) {
			g_free(applet_name);
			gnome_config_pop_prefix();
			continue;
		} else if(strcmp(applet_name,"Unknown")==0) {
			g_warning("Unknown applet type!");
			g_free(applet_name);
			gnome_config_pop_prefix();
			continue;
		}

		g_snprintf(buf,256,"position=%d", 0);
		pos = gnome_config_get_int(buf);
		panel_num = gnome_config_get_int("panel=0");
		{
			GList *list = g_list_nth(panels,panel_num);
			if(!list) {
				g_warning("Can't find panel, "
					  "putting applet on the first one");
				panel = panels->data;
			} else
				panel = list->data;
		}
		
		/*if we are to right stick this, make the number large, 
		 INT_MAX/2 should allways be large enough */
		pos += gnome_config_get_bool("right_stick=false")?INT_MAX/2:0;
		
		if(strcmp(applet_name,EXTERN_ID) == 0) {
			char *path = gnome_config_get_string("execpath=");
			char *params = gnome_config_get_string("parameters=");
			/*this is the config path to be passed to the applet
			  when it loads*/
678
			g_snprintf(buf,256,"%sApplet_%d_Extern/",
679
				   old_panel_cfg_path,num);
680
			load_extern_applet(path,params,buf,panel,pos);
681 682 683 684
			g_free(path);
			g_free(params);
		} else if(strcmp(applet_name,LAUNCHER_ID) == 0) { 
			char *params = gnome_config_get_string("parameters=");
685
			load_launcher_applet(params,panel,pos);
686 687
			g_free(params);
		} else if(strcmp(applet_name,LOGOUT_ID) == 0) { 
688
			load_logout_applet(panel,pos);
689 690 691 692 693
		} else if(strcmp(applet_name,SWALLOW_ID) == 0) {
			char *path = gnome_config_get_string("execpath=");
			char *params = gnome_config_get_string("parameters=");
			int width = gnome_config_get_int("width=0");
			int height = gnome_config_get_int("height=0");
694
			load_swallow_applet(path,params,width,height,panel,pos);
695 696 697 698 699 700
			g_free(path);
			g_free(params);
		} else if(strcmp(applet_name,MENU_ID) == 0) {
			char *params = gnome_config_get_string("parameters=");
			int main_menu_type =
				gnome_config_get_int("main_menu_type=0");
701
			load_menu_applet(params,main_menu_type,panel,pos);
702 703 704 705 706
			g_free(params);
		} else if(strcmp(applet_name,DRAWER_ID) == 0) {
			char *params = gnome_config_get_string("parameters=");
			char *pixmap = gnome_config_get_string("pixmap=");
			char *tooltip = gnome_config_get_string("tooltip=");
707
			load_drawer_applet(params,pixmap,tooltip,panel,pos);
708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734
			g_free(params);
			g_free(pixmap);
			g_free(tooltip);
		} else
			g_warning("Unknown applet type!");
		gnome_config_pop_prefix();
	}
}

void
init_user_panels(void)
{
	char  buf[256];
	int   count,num;	
	GtkWidget *panel;

	g_snprintf(buf,256,"%spanel/Config/panel_count=0",old_panel_cfg_path);
	count=gnome_config_get_int(buf);

	/*load a default snapped panel on the bottom of the screen,
	  it is required to have at least one panel for this all
	  to work, so this is the way we find out if there was no
	  config from last time*/
	if(count<=0)  {
		panel = snapped_widget_new(SNAPPED_BOTTOM,
					   SNAPPED_EXPLICIT_HIDE,
					   SNAPPED_SHOWN,
735
					   TRUE,
736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783
					   PANEL_BACK_NONE,
					   NULL,
					   TRUE,
					   NULL);
		panel_setup(panel);
		gtk_widget_show(panel);

		/*load up default applets on the default panel*/
		load_default_applets();

		return;
	}

	for(num=1;num<=count;num++) {
		PanelType type;
		PanelBackType back_type;
		char *back_pixmap, *color;
		GdkColor back_color = {0,0,0,1};
		int fit_pixmap_bg;

		g_snprintf(buf,256,"%spanel/Panel_%d/", old_panel_cfg_path, num);
		gnome_config_push_prefix (buf);
		
		back_pixmap = gnome_config_get_string ("backpixmap=");
		if (back_pixmap && *back_pixmap == '\0') {
			g_free(back_pixmap);
			back_pixmap = NULL;
		}

		color = gnome_config_get_string("backcolor=#ffffff");
		if(color && *color)
			gdk_color_parse(color, &back_color);

		g_snprintf(buf,256,"back_type=%d",PANEL_BACK_NONE);
		back_type=gnome_config_get_int(buf);
		fit_pixmap_bg = gnome_config_get_bool ("fit_pixmap_bg=TRUE");

		/*now for type specific config*/

		g_snprintf(buf,256,"type=%d", SNAPPED_PANEL);
		type = gnome_config_get_int(buf);

		switch(type) {
		case SNAPPED_PANEL:
			{
				SnappedPos pos;
				SnappedMode mode;
				SnappedState state;
784
				int hidebuttons_enabled;
785 786 787 788 789 790 791 792 793

				g_snprintf(buf,256,"pos=%d", SNAPPED_BOTTOM);
				pos=gnome_config_get_int(buf);

				g_snprintf(buf,256,"mode=%d", SNAPPED_EXPLICIT_HIDE);
				mode=gnome_config_get_int(buf);

				g_snprintf(buf,256,"state=%d", SNAPPED_SHOWN);
				state=gnome_config_get_int(buf);
794 795 796 797

				hidebuttons_enabled =
					gnome_config_get_bool("hidebuttons_enabled=TRUE");

798 799 800
				panel = snapped_widget_new(pos,
							   mode,
							   state,
801
							   hidebuttons_enabled,
802 803 804 805 806 807 808 809 810
							   back_type,
							   back_pixmap,
							   fit_pixmap_bg,
							   &back_color);
				break;
			}
		case DRAWER_PANEL:
			{
				DrawerState state;
811
				PanelOrientType orient;
812 813 814 815

				g_snprintf(buf,256,"state=%d", DRAWER_SHOWN);
				state=gnome_config_get_int(buf);

816
				g_snprintf(buf,256,"orient=%d", ORIENT_UP);
817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861
				orient=gnome_config_get_int(buf);

				panel = drawer_widget_new(orient,
							  state,
							  back_type,
							  back_pixmap,
							  fit_pixmap_bg,
							  &back_color);
				break;
			}
		case CORNER_PANEL:
			{
				CornerPos pos;
				PanelOrientation orient;
				CornerState state;
				
				g_snprintf(buf,256,"pos=%d", CORNER_NE);
				pos=gnome_config_get_int(buf);

				g_snprintf(buf,256,"orient=%d",
					   PANEL_HORIZONTAL);
				orient=gnome_config_get_int(buf);

				g_snprintf(buf,256,"state=%d", CORNER_SHOWN);
				state=gnome_config_get_int(buf);
				
				panel = corner_widget_new(pos,
							  orient,
							  state,
							  back_type,
							  back_pixmap,
							  fit_pixmap_bg,
							  &back_color);
				break;
			}
		default: break;
		}

		gnome_config_pop_prefix ();
		
		g_free(color);
		g_free(back_pixmap);

		panel_setup(panel);

862
		gtk_widget_show(panel);
863 864 865 866 867 868 869
	}
}

void
load_up_globals(void)
{
	char buf[256];
870 871
	char *tile_def[]={"normal","purple","green"};
	int i;
872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909

	/*set up global options*/
	
	g_snprintf(buf,256,"%spanel/Config/",old_panel_cfg_path);
	gnome_config_push_prefix(buf);

	global_config.tooltips_enabled =
		gnome_config_get_bool("tooltips_enabled=TRUE");

	global_config.show_small_icons =
		gnome_config_get_bool("show_small_icons=TRUE");
		
	global_config.prompt_for_logout =
		gnome_config_get_bool("prompt_for_logout=TRUE");

	global_config.disable_animations =
		gnome_config_get_bool("disable_animations=FALSE");
		
	g_snprintf(buf,256,"auto_hide_step_size=%d",
		   DEFAULT_AUTO_HIDE_STEP_SIZE);
	global_config.auto_hide_step_size=gnome_config_get_int(buf);
		
	g_snprintf(buf,256,"explicit_hide_step_size=%d",
		   DEFAULT_EXPLICIT_HIDE_STEP_SIZE);
	global_config.explicit_hide_step_size=gnome_config_get_int(buf);
		
	g_snprintf(buf,256,"drawer_step_size=%d",
		   DEFAULT_DRAWER_STEP_SIZE);
	global_config.drawer_step_size=gnome_config_get_int(buf);
		
	g_snprintf(buf,256,"minimize_delay=%d", DEFAULT_MINIMIZE_DELAY);
	global_config.minimize_delay=gnome_config_get_int(buf);
		
	g_snprintf(buf,256,"minimized_size=%d", DEFAULT_MINIMIZED_SIZE);
	global_config.minimized_size=gnome_config_get_int(buf);
		
	g_snprintf(buf,256,"movement_type=%d", PANEL_SWITCH_MOVE);
	global_config.movement_type=gnome_config_get_int(buf);
910 911

	global_config.applet_padding=gnome_config_get_int("applet_padding=3");
912 913 914

	global_config.tiles_enabled =
		gnome_config_get_bool("tiles_enabled=TRUE");
915 916 917 918 919 920 921 922 923 924 925 926 927 928 929
	
	for(i=0;i<LAST_TILE;i++) {
		g_free(global_config.tile_up[i]);
		g_snprintf(buf,256,"tile_up_%d=tile-%s-up.png",i,tile_def[i]);
		global_config.tile_up[i] = gnome_config_get_string(buf);

		g_free(global_config.tile_down[i]);
		g_snprintf(buf,256,"tile_down_%d=tile-%s-down.png",i,tile_def[i]);
		global_config.tile_down[i] = gnome_config_get_string(buf);

		g_snprintf(buf,256,"tile_border_%d=2",i);
		global_config.tile_border[i] = gnome_config_get_int(buf);
		g_snprintf(buf,256,"tile_depth_%d=2",i);
		global_config.tile_depth[i] = gnome_config_get_int(buf);
	}
930 931 932 933 934
		
	gnome_config_pop_prefix();

	apply_global_config();
}