Commit 8d7150ac authored by Jiri (George) Lebl's avatar Jiri (George) Lebl Committed by George Lebl

fixed up a lot of the old mess with applets, and fixed hopefully all the

Thu May 21 03:44:21 1998  George Lebl  <jirka@5z.com>

        * applet-lib.(cc|h),applet-widghet.[ch],main.c,panel.[ch],menu.c:
          fixed up a lot of the old mess with applets, and fixed hopefully
          all the dorestart hacks since we do sequential starting of
          applets and that has nice properties in terms of multiple
          applet support and makes the code cleaner
parent 3111d923
Thu May 21 03:44:21 1998 George Lebl <jirka@5z.com>
* applet-lib.(cc|h),applet-widghet.[ch],main.c,panel.[ch],menu.c:
fixed up a lot of the old mess with applets, and fixed hopefully
all the dorestart hacks since we do sequential starting of
applets and that has nice properties in terms of multiple
applet support and makes the code cleaner
Thu May 21 01:19:51 1998 George Lebl <jirka@5z.com>
* applet-widget.[ch]: better new function names and using
......
Thu May 21 03:44:21 1998 George Lebl <jirka@5z.com>
* applet-lib.(cc|h),applet-widghet.[ch],main.c,panel.[ch],menu.c:
fixed up a lot of the old mess with applets, and fixed hopefully
all the dorestart hacks since we do sequential starting of
applets and that has nice properties in terms of multiple
applet support and makes the code cleaner
Thu May 21 01:19:51 1998 George Lebl <jirka@5z.com>
* applet-widget.[ch]: better new function names and using
......
......@@ -22,7 +22,6 @@
#include "cookie.h"
#define APPLET_EVENT_MASK (GDK_BUTTON_PRESS_MASK | \
......@@ -58,9 +57,7 @@ int _gnome_applet_start_new_applet(const char *params);
END_GNOME_DECLS
class Applet_impl : virtual public GNOME::Applet_skel {
GtkWidget *the_widget;
public:
Applet_impl (GtkWidget *widget) { the_widget = widget; };
void change_orient (const char *ccookie, CORBA::Short applet_id,
CORBA::Short orient) {
CHECK_COOKIE ();
......@@ -370,15 +367,10 @@ char *
gnome_panel_applet_register (GtkWidget *widget, int applet_id)
{
char *result;
char *ior;
/* Create an applet object, I do pass the widget parameter to the
* constructor object to have a way of sort out to which object
* implementation the panel is talking to us about (ie, if an applet
* can implement various instances of some object, like say a bunch
* of "Swallow" applets
*/
GNOME::Applet_ptr applet = new Applet_impl (widget);
static char *ior=NULL;
/*the applet implementation, it's only created once*/
static GNOME::Applet_ptr applet = new Applet_impl ();
/* Now a way to find out the CORBA impl from the widget */
gtk_object_set_data (GTK_OBJECT (widget), "CORBA_object", applet);
......
......@@ -15,11 +15,12 @@ typedef gint (*AppletWidgetSaveSignal) (GtkObject * object,
char *globcfgpath,
gpointer data);
static GList *applet_widgets=NULL;
static gint applet_count=0;
static GList *applet_widgets = NULL;
static gint applet_count = 0;
static GtkPlugClass *parent_class;
guint
applet_widget_get_type ()
{
......@@ -185,6 +186,10 @@ applet_widget_new_param_multi(gchar *argv0, gchar *param, gint multi)
char *myinvoc;
gint applet_id;
/*keep track if we already initted corba or not, so that we can
safely start new applets*/
static gint do_corba_init = TRUE;
myinvoc = get_full_path(argv0);
if(!myinvoc)
return 0;
......@@ -192,9 +197,11 @@ applet_widget_new_param_multi(gchar *argv0, gchar *param, gint multi)
if(!param)
param="";
if (!gnome_panel_applet_init_corba())
if (do_corba_init && !gnome_panel_applet_init_corba())
g_error("Could not communicate with the panel\n");
do_corba_init = FALSE;
result = gnome_panel_applet_request_id(myinvoc, param,multi?FALSE:TRUE,
&applet_id,
&cfgpath, &globcfgpath,
......@@ -281,8 +288,7 @@ _gnome_applet_change_orient(int applet_id, int orient)
applet = applet_widget_get_by_id(applet_id);
if(applet) {
gtk_signal_emit(GTK_OBJECT(applet),
applet_widget_signals[
CHANGE_ORIENT_SIGNAL],
applet_widget_signals[CHANGE_ORIENT_SIGNAL],
o);
}
}
......@@ -325,7 +331,7 @@ _gnome_applet_start_new_applet(const char *param)
if(applet) {
gtk_signal_emit(GTK_OBJECT(applet),
applet_widget_signals[SESSION_SAVE_SIGNAL],
applet_widget_signals[START_NEW_APPLET_SIGNAL],
param);
}
}
......
......@@ -54,7 +54,6 @@ struct _LoadApplet {
gchar *id_str;
gchar *path;
gchar *params;
gint dorestart;
gint pos;
gint panel;
gchar *cfgpath;
......@@ -125,7 +124,7 @@ static struct argp parser =
/*needed for drawers*/
static void panel_setup(PanelWidget *panel);
static void really_exec_prog(gint applet_id, gchar *path, gchar *param);
static gint really_exec_prog(gint applet_id, gchar *path, gchar *param);
static void exec_queue_start_next(void);
static gint
......@@ -137,56 +136,73 @@ exec_queue_timeout(gpointer data)
return FALSE;
}
static void
static gint
really_exec_prog(gint applet_id, gchar *path, gchar *param)
{
/*this applet is dumb and wants us to start it :)*/
AppletChild *child;
child = g_new(AppletChild,1);
child->pid = fork();
if(child->pid < 0)
g_error("Can't fork!");
if(child->pid == 0) {
if(strlen(param)>0)
execl(path,path,param,NULL);
else
execl(path,path,NULL);
g_error("Can't execl!");
}
/*check if this is an applet which is a multi applet and
has something already loaded*/
if(mulapp_is_in_queue(path)) {
puts("multi applet, just contacting existing applet");
mulapp_load_or_add_to_queue(path,param);
return TRUE;
} else {
AppletChild *child;
child = g_new(AppletChild,1);
child->pid = fork();
if(child->pid < 0)
g_error("Can't fork!");
if(child->pid == 0) {
if(strlen(param)>0)
execl(path,path,param,NULL);
else
execl(path,path,NULL);
g_error("Can't execl!");
}
printf("started applet, pid: %d\n",child->pid);
child->applet_id = applet_id;
printf("started applet, pid: %d\n",child->pid);
children = g_list_prepend(children,child);
child->applet_id = applet_id;
children = g_list_prepend(children,child);
current_exec = applet_id;
current_exec = applet_id;
cur_timeout = gtk_timeout_add(30*100,exec_queue_timeout,NULL);
/*wait 60 seconds before timing out*/
cur_timeout = gtk_timeout_add(60*100,exec_queue_timeout,NULL);
return FALSE;
}
}
/*start the next item in the exec queue*/
static void
exec_queue_start_next(void)
{
ExecQueue *eq;
gint ret;
current_exec = -1;
if(cur_timeout>0)
gtk_timeout_remove(cur_timeout);
cur_timeout=0;
if(!exec_queue)
return;
do {
if(!exec_queue)
return;
eq = exec_queue->data;
eq = exec_queue->data;
really_exec_prog(eq->applet_id, eq->path, eq->param);
g_free(eq->path);
if(eq->param) g_free(eq->param);
g_free(eq);
ret = really_exec_prog(eq->applet_id, eq->path, eq->param);
g_free(eq->path);
if(eq->param) g_free(eq->param);
g_free(eq);
exec_queue = g_list_remove_link(exec_queue,exec_queue);
exec_queue = g_list_remove_link(exec_queue,exec_queue);
/*repeat while we are doing applets that do not require a wait
(second invocations of multi applets)*/
} while(ret);
}
void
......@@ -216,7 +232,7 @@ exec_prog(gint applet_id, gchar *path, gchar *param)
static void
queue_load_applet(gchar *id_str, gchar *path, gchar *params, gint dorestart,
queue_load_applet(gchar *id_str, gchar *path, gchar *params,
gint pos, gint panel, gchar *cfgpath)
{
LoadApplet *l;
......@@ -226,7 +242,6 @@ queue_load_applet(gchar *id_str, gchar *path, gchar *params, gint dorestart,
if(path) l->path=g_strdup(path);
else l->path = NULL;
l->params=g_strdup(params);
l->dorestart=dorestart;
l->pos=pos;
l->panel=panel;
l->cfgpath=g_strdup(cfgpath);
......@@ -249,7 +264,7 @@ monitor_drawers(GtkWidget *w, gpointer data)
void
load_applet(gchar *id_str, gchar *path, gchar *params, gint dorestart,
load_applet(gchar *id_str, gchar *path, gchar *params,
gint pos, gint panel, gchar *cfgpath)
{
if(strcmp(id_str,EXTERN_ID) == 0) {
......@@ -272,7 +287,7 @@ load_applet(gchar *id_str, gchar *path, gchar *params, gint dorestart,
p = g_copy_strings(cfgpath,"path=",NULL);
fullpath = gnome_config_get_string(p);
g_free(p);
load_applet(LAUNCHER_ID,NULL,fullpath,TRUE,pos,panel,
load_applet(LAUNCHER_ID,NULL,fullpath,pos,panel,
cfgpath);
g_free(fullpath);
return;
......@@ -287,25 +302,17 @@ load_applet(gchar *id_str, gchar *path, gchar *params, gint dorestart,
fullpath = g_strdup(path);
if(reserve_applet_spot (id_str, fullpath,params, dorestart,
if(reserve_applet_spot (id_str, fullpath,params,
panel, pos, cfgpath,
APPLET_EXTERN_PENDING)==0) {
g_warning("Whoops! for some reason we can't add "
"to the panel");
g_free(fullpath);
return;
}
/*'#' marks an applet that will take care of starting
itself but wants us to reserve a spot for it*/
if(!dorestart) {
if(mulapp_is_in_queue(fullpath)) {
mulapp_load_or_add_to_queue(fullpath,param);
g_free(fullpath);
return;
} else {
mulapp_add_to_queue(fullpath);
}
}
if(path[0]!='#')
exec_prog(applet_count-1,fullpath,param);
......@@ -317,6 +324,9 @@ load_applet(gchar *id_str, gchar *path, gchar *params, gint dorestart,
register_toy(menu->button,menu->menu,menu,MENU_ID,NULL,params,
pos,panel,NULL,APPLET_MENU);
/*we count the main menus so that we can dis-allow
deleting of the last one*/
if(!params || strcmp(params,".")==0)
main_menu_count++;
} else if(strcmp(id_str,LAUNCHER_ID) == 0) {
......@@ -415,7 +425,7 @@ load_queued_applets(void)
for(list = load_queue;list!=NULL;list=g_list_next(list)) {
LoadApplet *l=list->data;
load_applet(l->id_str,l->path,l->params,l->dorestart,
load_applet(l->id_str,l->path,l->params,
l->pos,l->panel,l->cfgpath);
g_free(l->id_str);
if(l->path) g_free(l->path);
......@@ -441,9 +451,9 @@ add_forbidden_to_panels(void)
static void
load_default_applets(void)
{
queue_load_applet(MENU_ID, NULL, ".", TRUE,
queue_load_applet(MENU_ID, NULL, ".",
PANEL_UNKNOWN_APPLET_POSITION, 0,NULL);
queue_load_applet(EXTERN_ID, "clock_applet", "", TRUE,
queue_load_applet(EXTERN_ID, "clock_applet", "",
PANEL_UNKNOWN_APPLET_POSITION,0,NULL);
}
......@@ -456,7 +466,6 @@ init_user_applets(void)
int pos=0,panel;
char buf[256];
int count,num;
gint dorestart;
g_snprintf(buf,256,"%sConfig/applet_count=0",old_panel_cfg_path);
count=gnome_config_get_int(buf);
......@@ -471,11 +480,9 @@ init_user_applets(void)
if(strcmp(applet_name,"Extern")==0) {
applet_path = gnome_config_get_string("parameters=");
applet_params = gnome_config_get_string("parameters2=");
dorestart = gnome_config_get_bool("dorestart=true");
} else {
applet_path = NULL;
applet_params = gnome_config_get_string("parameters=");
dorestart = TRUE;
}
g_snprintf(buf,256,"position=%d",
......@@ -487,7 +494,7 @@ init_user_applets(void)
loads*/
g_snprintf(buf,256,"%sApplet_%d/",old_panel_cfg_path,num);
queue_load_applet(applet_name, applet_path, applet_params,
dorestart, pos, panel, buf);
pos, panel, buf);
gnome_config_pop_prefix();
......
......@@ -140,9 +140,9 @@ free_string (GtkWidget *widget, void *data)
}
static gint
add_to_panel (char *applet, char *path, char *arg, gint dorestart)
add_to_panel (char *applet, char *path, char *arg)
{
load_applet(applet,path,arg,dorestart,
load_applet(applet,path,arg,
PANEL_UNKNOWN_APPLET_POSITION,0,NULL);
return TRUE;
}
......@@ -152,13 +152,13 @@ add_app_to_panel (GtkWidget *widget, void *data)
{
GnomeDesktopEntry *ii = data;
return add_to_panel (LAUNCHER_ID, NULL, ii->location,TRUE);
return add_to_panel (LAUNCHER_ID, NULL, ii->location);
}
static gint
add_dir_to_panel (GtkWidget *widget, void *data)
{
return add_to_panel (MENU_ID, NULL, data,TRUE);
return add_to_panel (MENU_ID, NULL, data);
}
......@@ -169,7 +169,6 @@ add_applet (GtkWidget *w, gpointer data)
char *path;
char *param;
gint r;
gint dorestart;
path = ii->exec[0];
......@@ -179,12 +178,8 @@ add_applet (GtkWidget *w, gpointer data)
param = gnome_string_joinv (" ", ii->exec + 1);
else
param = NULL;
if(mulapp_is_in_queue(path))
dorestart = FALSE;
else
dorestart = TRUE;
r = add_to_panel(EXTERN_ID,path,param,dorestart);
r = add_to_panel(EXTERN_ID,path,param);
if(param) g_free(param);
return r;
......@@ -408,7 +403,7 @@ panel_configure (GtkWidget *widget, void *data)
static void
add_applet_to_panel_data(GtkWidget *widget, gpointer data)
{
add_to_panel((char *)data, NULL, NULL,TRUE);
add_to_panel((char *)data, NULL, NULL);
}
static gint
......@@ -418,8 +413,7 @@ act_really_add_swallow(GtkWidget *w, gpointer data)
GtkWidget *d = gtk_object_get_user_data(GTK_OBJECT(entry));
gtk_widget_hide(d);
add_to_panel(SWALLOW_ID, NULL, gtk_entry_get_text(GTK_ENTRY(entry)),
TRUE);
add_to_panel(SWALLOW_ID, NULL, gtk_entry_get_text(GTK_ENTRY(entry)));
return TRUE;
}
......@@ -432,7 +426,7 @@ really_add_swallow(GtkWidget *d,gint button, gpointer data)
gtk_widget_hide(d);
if(button == 0)
add_to_panel(SWALLOW_ID, NULL,
gtk_entry_get_text(GTK_ENTRY(entry)),TRUE);
gtk_entry_get_text(GTK_ENTRY(entry)));
return TRUE;
}
......
......@@ -77,7 +77,7 @@ mulapp_remove_emptyfrom_queue(void)
GList *list;
for(list=multiple_applet_load_queue;list!=NULL;list=g_list_next(list)){
MultiLoadQueue *mq = list->data;
if(is_applet_running(mq->path)) {
if(!is_applet_running(mq->path)) {
multiple_applet_load_queue =
g_list_remove_link(multiple_applet_load_queue,
list);
......@@ -153,10 +153,11 @@ mulapp_add_ior_and_free_queue(const gchar *path, const gchar *ior)
MultiLoadQueue *mq = list->data;
if(strcmp(mq->path,path)==0) {
GList *li;
if(mq->ior)
g_warning("What? An IOR existed before, this "
"is most likely a bug!");
mq->ior = g_strdup(ior);
if(mq->ior && strcmp(mq->ior,ior)!=0)
g_warning("What? there already was an applet "
"before with different IOR?");
else
mq->ior = g_strdup(ior);
if(!mq->params)
return;
for(li=mq->params;li!=NULL;li=g_list_next(li)) {
......@@ -267,12 +268,6 @@ save_applet_configuration(AppletInfo *info, gint *num)
fullpath = g_copy_strings(path,"parameters2",NULL);
gnome_config_set_string(fullpath, info->params);
g_free(fullpath);
/*we use the data field to store if we should or
should not restart the applet*/
fullpath = g_copy_strings(path,"dorestart",NULL);
gnome_config_set_bool(fullpath, info->data!=0);
g_free(fullpath);
} else
(*num)--;
} else {
......@@ -957,15 +952,14 @@ applet_request_id (const char *path, const char *param,
*globcfgpath = g_strdup(old_panel_cfg_path);
info->type = APPLET_EXTERN_RESERVED;
*winid=GDK_WINDOW_XWINDOW(info->applet_widget->window);
info->data = ITOP(dorestart);
if(!dorestart &&!mulapp_is_in_queue(path))
mulapp_add_to_queue(path);
if(!dorestart && !mulapp_is_in_queue(path))
mulapp_add_to_queue(path);
return i;
}
}
*winid = reserve_applet_spot (EXTERN_ID, path, param, dorestart, 0, 0,
*winid = reserve_applet_spot (EXTERN_ID, path, param, 0, 0,
NULL, APPLET_EXTERN_RESERVED);
if(*winid == 0) {
*globcfgpath = NULL;
......@@ -976,9 +970,8 @@ applet_request_id (const char *path, const char *param,
*globcfgpath = g_strdup(old_panel_cfg_path);
info = get_applet_info(applet_count-1);
info->data = ITOP(dorestart);
if(!dorestart &&!mulapp_is_in_queue(path))
mulapp_add_to_queue(path);
if(!dorestart && !mulapp_is_in_queue(path))
mulapp_add_to_queue(path);
return i;
}
......@@ -1020,7 +1013,7 @@ applet_register (const char * ior, int applet_id)
only*/
guint32
reserve_applet_spot (const char *id_str, const char *path, const char *param,
gint dorestart, int panel, int pos, char *cfgpath,
int panel, int pos, char *cfgpath,
AppletType type)
{
GtkWidget *socket;
......@@ -1033,7 +1026,7 @@ reserve_applet_spot (const char *id_str, const char *path, const char *param,
/*we save the ior in the id field of the appletinfo and the
path in the path field*/
if(!register_toy(socket,NULL,(gpointer)(dorestart?1L:0L),
if(!register_toy(socket,NULL,NULL,
g_strdup(id_str),g_strdup(path),
g_strdup(param), pos,panel,cfgpath, type)) {
g_warning("Couldn't add applet");
......@@ -1055,7 +1048,7 @@ panel_add_main_menu(GtkWidget *w, gpointer data)
PanelWidget *panel = data;
gint panel_num = find_panel(panel);
load_applet(MENU_ID,NULL,NULL,TRUE,PANEL_UNKNOWN_APPLET_POSITION,
load_applet(MENU_ID,NULL,NULL,PANEL_UNKNOWN_APPLET_POSITION,
panel_num!=-1?panel_num:0,NULL);
return TRUE;
......
......@@ -119,7 +119,7 @@ int applet_request_id (const char *path, const char *param,
void applet_register (const char * ior, int applet_id);
void applet_request_glob_cfg (char **globcfgpath);
guint32 reserve_applet_spot (const char *id_str, const char *path,
const char *param, gint dorestart,
const char *param,
int panel, int pos, char *cfgpath,
AppletType type);
void applet_abort_id(gint applet_id);
......@@ -151,7 +151,7 @@ void exec_queue_done(gint applet_id);
extern char *cookie;
/*this is in main.c*/
void load_applet(char *id, char *path, char *params, int dorestart,
void load_applet(char *id, char *path, char *params,
int pos, int panel, char *cfgpath);
void orientation_change(gint applet_id, PanelWidget *panel);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment