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

implemented a way for applets to find their absolute executable path

Fri Mar 20 00:10:12 1998  George Lebl  <jirka@5z.com>

        * applet-lib.{cc,h}: implemented a way for applets
          to find their absolute executable path
parent 0c8cd0fb
Fri Mar 20 00:10:12 1998 George Lebl <jirka@5z.com>
* applet-lib.{cc,h}: implemented a way for applets
to find their absolute executable path
Thu Mar 19 18:21:45 1998 Tom Tromey <tromey@cygnus.com>
* mico-parse.cc (parse_mico_arg): Allocate two arguments for every
......
Fri Mar 20 00:10:12 1998 George Lebl <jirka@5z.com>
* applet-lib.{cc,h}: implemented a way for applets
to find their absolute executable path
Thu Mar 19 18:21:45 1998 Tom Tromey <tromey@cygnus.com>
* mico-parse.cc (parse_mico_arg): Allocate two arguments for every
......
......@@ -7,6 +7,7 @@
#include "applet-lib.h"
#include "panel-widget.h"
#include "mico-parse.h"
#include <fcntl.h>
#define APPLET_EVENT_MASK (GDK_BUTTON_PRESS_MASK | \
GDK_BUTTON_RELEASE_MASK | \
......@@ -398,3 +399,69 @@ move_grab_remove (GtkWidget *applet)
gdk_pointer_ungrab(GDK_CURRENT_TIME);
gtk_grab_remove(applet);
}
/* this function might be a slight overkill, but it should work
perfect, hopefully it should be 100% buffer overrun safe too*/
char *
get_which_output(char *argv0)
{
char buf[PATH_MAX+2];
int cmdsize=100;
char *cmdbuf;
int i;
int fd[2];
if(!argv0)
return NULL;
if(*argv0 == '/')
return g_strdup(argv0);
if(strchr(argv0,'/')) {
char *curpath = getcwd(NULL,0);
char *outbuf;
if(!curpath)
return NULL;
outbuf = g_copy_strings(curpath,"/",argv0,NULL);
free(curpath);
realpath(outbuf,buf);
return g_strdup(buf);
}
if(pipe(fd) == -1)
return NULL;
/*dynamically reallocates cmdbuf until the command fits*/
for(;;) {
cmdbuf = (char *)g_malloc(cmdsize);
if(g_snprintf(cmdbuf, cmdsize, "sh -c 'which %s > /dev/fd/%d'",
argv0,fd[1])>-1)
break;
g_free(cmdbuf);
cmdsize*=2;
}
system(cmdbuf);
g_free(cmdbuf);
i=read(fd[0],buf,PATH_MAX+1);
close(fd[0]);
close(fd[1]);
if(i <= 0)
return NULL;
buf[i]='\0';
if(buf[i-1]=='\n')
buf[i-1]='\0';
if(buf[0]=='\0')
return NULL;
return g_strdup(buf);
}
......@@ -24,6 +24,8 @@ void applet_corba_gtk_main (char *str);
void move_grab_add (GtkWidget *applet);
void move_grab_remove (GtkWidget *applet);
char * get_which_output(char *argv0);
END_GNOME_DECLS
#endif
......@@ -547,13 +547,11 @@ main(int argc, char **argv)
but it will reserve a spot for us on the correct place, and
this is the string that we identify as when we ask for the
spot*/
if(argv[0][0] == '/')
myinvoc = g_copy_strings("#",argv[0],NULL);
else {
mypath = getcwd(NULL,0);
myinvoc = g_copy_strings("#",mypath,"/",argv[0],NULL);
free(mypath);
}
mypath = get_which_output(argv[0]);
if(!mypath)
return 1;
myinvoc = g_copy_strings("#",mypath,NULL);
free(mypath);
launcher_corba_gtk_main ("IDL:GNOME/Launcher:1.0");
......
......@@ -6,15 +6,13 @@
#include "panel.h"
#include "mico-parse.h"
#define APPLET_ID "Logout"
GtkWidget *plug;
int applet_id=-1;
int applet_id = (-1);
void
change_orient(int id, int orient)
{
PanelOrientType o = (PanelOrientType)orient;
PanelOrientType o = (PanelOrientType) orient;
}
void
......@@ -32,98 +30,86 @@ quit_logout(gpointer data)
void
shutdown_applet(int id)
{
gtk_widget_destroy(plug);
gtk_idle_add(quit_logout,NULL);
gtk_widget_destroy(plug);
gtk_idle_add(quit_logout, NULL);
}
static void
logout(void)
{
gnome_panel_quit();
gnome_panel_quit();
}
static GtkWidget *
create_logout_widget (void)
create_logout_widget(void)
{
GtkWidget *button;
GtkWidget *pixmap;
char *pixmap_name;
pixmap_name=gnome_unconditional_pixmap_file("gnome-term-night.xpm");
if(!pixmap_name)
button = gtk_button_new_with_label (_("Log out"));
else {
button = gtk_button_new ();
pixmap = gnome_pixmap_new_from_file (pixmap_name);
g_free(pixmap_name);
gtk_container_add(GTK_CONTAINER(button),pixmap);
gtk_widget_show(pixmap);
gtk_widget_set_usize (button, pixmap->requisition.width,
pixmap->requisition.height);
}
gtk_signal_connect (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (logout), NULL);
return button;
GtkWidget *button;
GtkWidget *pixmap;
char *pixmap_name;
pixmap_name = gnome_unconditional_pixmap_file("gnome-term-night.xpm");
if (!pixmap_name)
button = gtk_button_new_with_label(_("Log out"));
else {
button = gtk_button_new();
pixmap = gnome_pixmap_new_from_file(pixmap_name);
g_free(pixmap_name);
gtk_container_add(GTK_CONTAINER(button), pixmap);
gtk_widget_show(pixmap);
gtk_widget_set_usize(button, pixmap->requisition.width,
pixmap->requisition.height);
}
gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(logout), NULL);
return button;
}
int
main(int argc, char *argv[])
{
GtkWidget *logout;
char *result;
char *cfgpath;
char *globcfgpath;
guint32 winid;
panel_corba_register_arguments ();
gnome_init("logout_applet", NULL, argc, argv, 0, NULL);
if(!gnome_panel_applet_init_corba ())
{
fprintf(stderr, "Could not communicate with the panel\n");
exit(1);
}
{
char *mypath, *myinvoc;
if(argv[0][0] == '/')
myinvoc = g_strdup(argv[0]);
else
{
mypath = getcwd(NULL, 0);
myinvoc = g_copy_strings(mypath, "/", argv[0], NULL);
free(mypath);
}
result = gnome_panel_applet_request_id (myinvoc, &applet_id,
&cfgpath,&globcfgpath,
&winid);
if(result)
g_error("Could not talk to the panel: %s\n", result);
g_free(myinvoc);
}
g_free(cfgpath); /* We should load up config data first... */
g_free(globcfgpath);
plug = gtk_plug_new(winid);
logout = create_logout_widget();
gtk_widget_show(logout);
gtk_container_add(GTK_CONTAINER(plug), logout);
gtk_widget_show(plug);
result = gnome_panel_applet_register(plug, applet_id);
if (result)
g_error("Could not talk to the Panel: %s\n", result);
applet_corba_gtk_main ("IDL:GNOME/Applet:1.0");
return 0;
GtkWidget *logout;
char *result;
char *cfgpath;
char *globcfgpath;
guint32 winid;
char *myinvoc;
myinvoc = get_which_output(argv[0]);
if(!myinvoc)
return 1;
panel_corba_register_arguments();
gnome_init("logout_applet", NULL, argc, argv, 0, NULL);
if (!gnome_panel_applet_init_corba())
g_error(stderr, "Could not communicate with the panel\n");
result = gnome_panel_applet_request_id(myinvoc, &applet_id,
&cfgpath, &globcfgpath,
&winid);
if (result)
g_error("Could not talk to the panel: %s\n", result);
g_free(myinvoc);
g_free(cfgpath); /* We should load up config data first... */
g_free(globcfgpath);
plug = gtk_plug_new(winid);
logout = create_logout_widget();
gtk_widget_show(logout);
gtk_container_add(GTK_CONTAINER(plug), logout);
gtk_widget_show(plug);
result = gnome_panel_applet_register(plug, applet_id);
if (result)
g_error("Could not talk to the Panel: %s\n", result);
applet_corba_gtk_main("IDL:GNOME/Applet:1.0");
return 0;
}
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