Commit 894228f1 authored by Elliot Lee's avatar Elliot Lee

OK, libpanel_applet builds, clock_applet builds, panel builds, but the rest is...

OK, libpanel_applet builds, clock_applet builds, panel builds, but the rest is left broken as an incentive to fix it quickly :) I started on logout.c, feel free to finish it or convert some of the other applets
parent 67eaa11c
......@@ -5,14 +5,13 @@ test:
#SUBDIRS = menu mailcheck clock launcher batmon netwatch logout \
# @PROGRAMS_PANEL_CDPLAYER@
SUBDIRS = clock @PROGRAMS_PANEL_CDPLAYER@
SUBDIRS = @PROGRAMS_PANEL_CDPLAYER@ batmon mailcheck netwatch
INCLUDES = \
-DGNOMELOCALEDIR=\""$(datadir)/locale"\" \
-I$(includedir)
bin_PROGRAMS = panel clock_applet
lib_LTLIBRARIES = libpanel_applet.la
bin_PROGRAMS = panel clock_applet launcher_applet logout_applet
CORBA_SOURCES = \
gnome-panel.cc \
......@@ -21,14 +20,15 @@ CORBA_SOURCES = \
MICO_VERS = 2.0.3
MICO_LIBS = -lmicocoss$(MICO_VERS) -lmicoaux$(MICO_VERS) -lmico$(MICO_VERS)
lib_LTLIBRARIES = libpanel_applet.la
libpanel_applet_la_SOURCES = \
applet-lib.cc \
applet-widget.c \
$(CORBA_SOURCES)
libpanel_appletinclude_HEADERS = \
applet-lib.h \
applet-widget.h
#libpanel_appletinclude_HEADERS = applet-lib.h \
# applet-widget.h
libpanel_applet_la_LDFLAGS = -version-info 0:0:0 -rpath $(libdir)
libpanel_applet_la_LIBADD = $(MICO_LIBS) -lm $(DL_LIB)
......@@ -67,7 +67,17 @@ panel_LDADD = $(GNOME_LIBDIR) $(MICO_LIBS) -lXt $(GNOMEUI_LIBS) $(INTLLIBS)
clock_applet_SOURCES = \
clock.c
clock_applet_LDADD = -lpanel_applet $(GNOME_LIBDIR) $(MICO_LIBS) -lXt $(GNOMEUI_LIBS) $(INTLLIBS)
clock_applet_LDADD = libpanel_applet.la $(GNOME_LIBDIR) $(MICO_LIBS) -lXt $(GNOMEUI_LIBS) $(INTLLIBS)
launcher_applet_SOURCES = \
launcher.c
launcher_applet_LDADD = libpanel_applet.la $(GNOME_LIBDIR) $(MICO_LIBS) -lXt $(GNOMEUI_LIBS) $(INTLLIBS)
logout_applet_SOURCES = \
logout.c
logout_applet_LDADD = libpanel_applet.la $(GNOME_LIBDIR) $(MICO_LIBS) -lXt $(GNOMEUI_LIBS) $(INTLLIBS)
data_DATA = panelrc
......
......@@ -7,6 +7,10 @@ char *gnome_panel_prepare_and_transfer (GtkWidget *widget, char *path, int *id,
int panel, int pos);
int gnome_panel_applet_init_corba (int *argc, char ***argv);
void applet_corba_gtk_main (char *str);
/* This is defined by the applet, not the library */
void do_callback (short id,
const char *callback_name);
END_GNOME_DECLS
#endif
/*
* GNOME time/date display module.
* (C) 1997 The Free Software Foundation
*
* Authors: Miguel de Icaza
* Federico Mena
*
* Feel free to implement new look and feels :-)
*/
#include <stdio.h>
#ifdef HAVE_LIBINTL
# include <libintl.h>
#endif
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
#include <string.h>
#include <time.h>
#include <gnome.h>
#include <gdk/gdkx.h>
#include "applet-lib.h"
#include "applet-widget.h"
#include "panel.h"
#define CLOCK_DATA "clock_data"
typedef void (*ClockUpdateFunc) (GtkWidget *clock, time_t current_time);
GtkWidget *aw;
int applet_id=-1; /*this is our id we use to comunicate with the panel*/
typedef struct {
int timeout;
ClockUpdateFunc update_func;
} ClockData;
typedef struct {
GtkWidget *date;
GtkWidget *time;
} ComputerClock;
static void
free_data(GtkWidget *widget, gpointer data)
{
g_free(data);
}
void
do_callback(short id,
const char *callback_name)
{
printf("Not doing callback %s\n", callback_name);
}
static int
clock_timeout_callback (gpointer data)
{
time_t current_time;
GtkWidget *clock;
ClockData *cd;
time (&current_time);
clock = data;
cd = gtk_object_get_data(GTK_OBJECT(clock), CLOCK_DATA);
(*cd->update_func) (clock, current_time);
return 1;
}
static void
computer_clock_update_func(GtkWidget *clock, time_t current_time)
{
ComputerClock *cc;
char *strtime;
char date[20], hour[20];
cc = gtk_object_get_user_data(GTK_OBJECT(clock));
strtime = ctime (&current_time);
strncpy (date, strtime, 10);
date[10] = '\0';
gtk_label_set (GTK_LABEL (cc->date), date);
strtime += 11;
strncpy (hour, strtime, 5);
hour[5] = '\0';
gtk_label_set (GTK_LABEL (cc->time), hour);
}
static void
create_computer_clock_widget(GtkWidget **clock, ClockUpdateFunc *update_func)
{
GtkWidget *frame;
GtkWidget *align;
GtkWidget *vbox;
ComputerClock *cc;
frame = gtk_frame_new(NULL);
gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_ETCHED_IN);
gtk_widget_show(frame);
align = gtk_alignment_new(0.5, 0.5, 0.0, 0.0);
gtk_container_border_width(GTK_CONTAINER(align), 4);
gtk_container_add(GTK_CONTAINER(frame), align);
gtk_widget_show(align);
vbox = gtk_vbox_new(FALSE, FALSE);
gtk_container_add(GTK_CONTAINER(align), vbox);
gtk_widget_show(vbox);
cc = g_new(ComputerClock, 1);
cc->date = gtk_label_new("");
cc->time = gtk_label_new("");
gtk_box_pack_start_defaults(GTK_BOX(vbox), cc->date);
gtk_box_pack_start_defaults(GTK_BOX(vbox), cc->time);
gtk_widget_show(cc->date);
gtk_widget_show(cc->time);
gtk_object_set_user_data(GTK_OBJECT(frame), cc);
gtk_signal_connect(GTK_OBJECT(frame), "destroy",
(GtkSignalFunc) free_data,
cc);
*clock = frame;
*update_func = computer_clock_update_func;
}
static void
destroy_clock (GtkWidget *widget, void *data)
{
ClockData *cd;
cd = gtk_object_get_data(GTK_OBJECT(widget), CLOCK_DATA);
gtk_timeout_remove (cd->timeout);
g_free(cd);
}
static GtkWidget *
create_clock_widget (GtkWidget *window)
{
ClockData *cd;
GtkWidget *clock;
time_t current_time;
cd = g_new(ClockData, 1);
/*FIXME: different clock types here*/
create_computer_clock_widget(&clock, &cd->update_func);
/* Install timeout handler */
cd->timeout = gtk_timeout_add(3000, clock_timeout_callback, clock);
gtk_object_set_data(GTK_OBJECT(clock), CLOCK_DATA, cd);
gtk_signal_connect(GTK_OBJECT(clock), "destroy",
(GtkSignalFunc) destroy_clock,
NULL);
/* Call the clock's update function so that it paints its first state */
time(&current_time);
(*cd->update_func) (clock, current_time);
return clock;
}
/*these are commands sent over corba:*/
void
change_orient(int id, int orient)
{
PanelOrientType o = (PanelOrientType)orient;
puts("CHANGE_ORIENT");
}
void
session_save(int id, int panel, int pos)
{
/*FIXME: save the position*/
puts("SESSION_SAVE");
}
static gint
applet_die(gpointer data)
{
exit(0);
}
void
shutdown_applet(int id)
{
puts("SHUTDOWN_APPLET");
/*kill our window*/
gtk_widget_unref(aw);
gtk_timeout_add(100,applet_die,NULL);
}
int
main(int argc, char **argv)
{
GtkWidget *clock;
char *result;
gnome_init("clock_applet", &argc, &argv);
if (!gnome_panel_applet_init_corba (&argc, &argv)){
fprintf (stderr, "Could not comunicate with the panel\n");
exit (1);
}
aw = applet_widget_new ();
clock = create_clock_widget (GTK_WIDGET(aw));
gtk_widget_show(clock);
applet_widget_add (APPLET_WIDGET (aw), clock);
gtk_widget_show (aw);
/*FIXME: do session saving, find out panel and pos from the panel
so we can restore them on the next startup*/
result = gnome_panel_prepare_and_transfer(aw,argv[0],&applet_id,0,0);
printf ("Done\n");
if (result){
printf ("Could not talk to the Panel: %s\n", result);
exit (1);
}
applet_corba_gtk_main ("IDL:GNOME/Applet:1.0");
return 0;
}
/*
* GNOME panel launcher module.
* (C) 1997 The Free Software Foundation
*
* Authors: Miguel de Icaza
* Federico Mena
*/
#include <config.h>
#include <stdio.h>
#include <sys/stat.h>
#include <dlfcn.h>
#include <unistd.h>
#include <dirent.h>
#include <string.h>
#include "gnome.h"
#include "panel.h"
#define APPLET_ID "Launcher"
static PanelCmdFunc panel_cmd_func;
gpointer applet_cmd_func(AppletCommand *cmd);
static char *default_app_pixmap;
typedef struct {
GtkWidget *button;
gint signal_click_tag;
GnomeDesktopEntry *dentry;
char *params;
} Launcher;
typedef struct {
GtkWidget *dialog;
GtkWidget *name_entry;
GtkWidget *comment_entry;
GtkWidget *execute_entry;
GtkWidget *icon_entry;
GtkWidget *documentation_entry;
GtkWidget *terminal_toggle;
/*information about this launcher*/
Launcher *launcher;
GnomeDesktopEntry *dentry;
} Properties;
static void
free_user_data(GtkWidget *widget, gpointer data)
{
Launcher *launcher = gtk_object_get_user_data(GTK_OBJECT(widget));
g_free(launcher->params);
gnome_desktop_entry_free(launcher->dentry);
g_free(launcher);
}
static void
launch (GtkWidget *widget, void *data)
{
GnomeDesktopEntry *item = data;
gnome_desktop_entry_launch (item);
}
static Launcher *
create_launcher (GtkWidget *window, char *parameters)
{
GtkWidget *pixmap;
GnomeDesktopEntry *dentry;
Launcher *launcher;
if (!default_app_pixmap)
default_app_pixmap = gnome_pixmap_file ("gnome-unknown.xpm");
if (*parameters == '/')
dentry = gnome_desktop_entry_load (parameters);
else {
char *apps_par, *entry, *extension;
if (strstr (parameters, ".desktop"))
extension = NULL;
else
extension = ".desktop";
apps_par = g_copy_strings ("apps/", parameters, extension, NULL);
entry = gnome_datadir_file (apps_par);
g_free (apps_par);
if (!entry)
return NULL;
dentry = gnome_desktop_entry_load (entry);
g_free (entry);
}
if (!dentry)
return NULL; /*button is null*/
launcher = g_new(Launcher,1);
launcher->button = gtk_button_new ();
pixmap = gnome_pixmap_new_from_file (dentry->opaque_icon);
if (!pixmap)
pixmap = gnome_pixmap_new_from_file (dentry->transparent_icon);
if (!pixmap) {
if (default_app_pixmap)
pixmap = gnome_pixmap_new_from_file (default_app_pixmap);
else
pixmap = gtk_label_new ("App");
}
gtk_container_add (GTK_CONTAINER(launcher->button), pixmap);
gtk_widget_show (pixmap);
gtk_widget_set_usize (launcher->button, pixmap->requisition.width,
pixmap->requisition.height);
gtk_widget_show (launcher->button);
launcher->signal_click_tag = gtk_signal_connect (GTK_OBJECT(launcher->button), "clicked",
(GtkSignalFunc) launch,
dentry);
gtk_object_set_user_data(GTK_OBJECT(launcher->button), launcher);
/* The .desktop path is stored in the params field */
launcher->params = g_strdup(parameters);
launcher->dentry = dentry;
gtk_signal_connect(GTK_OBJECT(launcher->button), "destroy",
(GtkSignalFunc) free_user_data,
NULL);
return launcher;
}
static GtkWidget *
create_text_entry(GtkWidget *table, int row, char *label, char *text)
{
GtkWidget *wlabel;
GtkWidget *entry;
wlabel = gtk_label_new(label);
gtk_misc_set_alignment(GTK_MISC(wlabel), 0.0, 0.5);
gtk_table_attach(GTK_TABLE(table), wlabel,
0, 1, row, row + 1,
GTK_EXPAND | GTK_FILL | GTK_SHRINK,
GTK_FILL | GTK_SHRINK,
0, 0);
gtk_widget_show(wlabel);
entry = gtk_entry_new();
if (text)
gtk_entry_set_text(GTK_ENTRY(entry), text);
gtk_table_attach(GTK_TABLE(table), entry,
1, 2, row, row + 1,
GTK_EXPAND | GTK_FILL | GTK_SHRINK,
GTK_FILL | GTK_SHRINK,
0, 0);
gtk_widget_show(entry);
return entry;
}
static void
check_dentry_save(GnomeDesktopEntry *dentry)
{
FILE *file;
char *pruned;
char *new_name;
char *appsdir;
file = fopen(dentry->location, "w");
if (file) {
fclose(file);
return;
}
pruned = strrchr(dentry->location, '/');
if (pruned)
pruned++; /* skip over slash */
else
pruned = dentry->location;
appsdir = gnome_util_home_file ("apps");
mkdir (appsdir, 0755);
new_name = g_concat_dir_and_file(appsdir, pruned);
g_free(dentry->location);
dentry->location = new_name;
}
#define free_and_nullify(x) { g_free(x); x = NULL; }
static void
properties_ok_callback(GtkWidget *widget, gpointer data)
{
PanelCommand cmd;
Properties *prop;
GnomeDesktopEntry *dentry;
GtkWidget *pixmap;
prop = data;
dentry = prop->dentry;
free_and_nullify(dentry->name);
free_and_nullify(dentry->comment);
free_and_nullify(dentry->exec);
free_and_nullify(dentry->tryexec);
free_and_nullify(dentry->icon_base);
free_and_nullify(dentry->docpath);
free_and_nullify(dentry->type);
dentry->name = g_strdup(gtk_entry_get_text(GTK_ENTRY(prop->name_entry)));
dentry->comment = g_strdup(gtk_entry_get_text(GTK_ENTRY(prop->comment_entry)));
dentry->exec = g_strdup(gtk_entry_get_text(GTK_ENTRY(prop->execute_entry)));
dentry->icon_base = g_strdup(gtk_entry_get_text(GTK_ENTRY(prop->icon_entry)));
dentry->docpath = g_strdup(gtk_entry_get_text(GTK_ENTRY(prop->documentation_entry)));
dentry->type = g_strdup("Application"); /* FIXME: should handle more cases */
dentry->terminal = GTK_TOGGLE_BUTTON(prop->terminal_toggle)->active;
check_dentry_save(dentry);
gnome_desktop_entry_save(dentry);
dentry=gnome_desktop_entry_load(dentry->location);
gnome_desktop_entry_free(prop->dentry);
prop->dentry = dentry;
/* FIXME: should update the button and pixmap */
g_free(prop->launcher->params);
prop->launcher->params=g_strdup(dentry->location);
cmd.cmd = PANEL_CMD_SET_TOOLTIP;
cmd.params.set_tooltip.applet = prop->launcher->button;
cmd.params.set_tooltip.tooltip = dentry->comment;
(*panel_cmd_func) (&cmd);
pixmap=GTK_BUTTON(prop->launcher->button)->child;
gtk_container_remove(GTK_CONTAINER(prop->launcher->button),pixmap);
gtk_widget_destroy(pixmap);
pixmap = gnome_pixmap_new_from_file (dentry->opaque_icon);
if (!pixmap)
pixmap = gnome_pixmap_new_from_file (dentry->transparent_icon);
if (!pixmap) {
if (default_app_pixmap)
pixmap = gnome_pixmap_new_from_file (default_app_pixmap);
else
pixmap = gtk_label_new (_("App"));
}
gtk_container_add (GTK_CONTAINER(prop->launcher->button), pixmap);
gtk_widget_show(pixmap);
gtk_widget_set_usize (prop->launcher->button, pixmap->requisition.width,
pixmap->requisition.height);
gtk_signal_disconnect(GTK_OBJECT(prop->launcher->button),
prop->launcher->signal_click_tag);
prop->launcher->signal_click_tag = gtk_signal_connect (GTK_OBJECT(prop->launcher->button), "clicked",
(GtkSignalFunc) launch,
dentry);
/*replace the dentry in launcher structure with the new one */
gnome_desktop_entry_free(prop->launcher->dentry);
prop->launcher->dentry=dentry;
}
#undef free_and_nullify
static void
properties_cancel_callback(GtkWidget *widget, gpointer data)
{
Properties *prop;
prop = data;
gnome_desktop_entry_free(prop->dentry);
gtk_widget_destroy(prop->dialog);
g_free(prop);
}
static GtkWidget *
create_properties_dialog(GnomeDesktopEntry *dentry, Launcher *launcher)
{
Properties *prop;
GtkWidget *dialog;
GtkWidget *table;
GtkWidget *button;
GtkWidget *toggle;
prop = g_new(Properties, 1);
prop->dentry = dentry;
prop->launcher = launcher;
prop->dialog = dialog = gtk_dialog_new();
gtk_window_set_title(GTK_WINDOW(dialog), _("Launcher properties"));
gtk_window_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER);
gtk_window_set_policy(GTK_WINDOW(dialog), FALSE, FALSE, TRUE);
table = gtk_table_new(6, 2, FALSE);
gtk_container_border_width(GTK_CONTAINER(table), 4);
gtk_table_set_col_spacings(GTK_TABLE(table), 6);
gtk_table_set_row_spacings(GTK_TABLE(table), 2);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), table, FALSE, FALSE, 0);
gtk_widget_show(table);
prop->name_entry = create_text_entry(table, 0, _("Name"), dentry->name);
prop->comment_entry = create_text_entry(table, 1, _("Comment"), dentry->comment);
prop->execute_entry = create_text_entry(table, 2, _("Execute"), dentry->exec);
prop->icon_entry = create_text_entry(table, 3, _("Icon"), dentry->icon_base);
prop->documentation_entry = create_text_entry(table, 4, _("Documentation"), dentry->docpath);
prop->terminal_toggle = toggle =
gtk_check_button_new_with_label(_("Run inside terminal"));
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(toggle),
dentry->terminal ? TRUE : FALSE);
gtk_table_attach(GTK_TABLE(table), toggle,
0, 2, 4, 5,
GTK_EXPAND | GTK_FILL | GTK_SHRINK,
GTK_FILL | GTK_SHRINK,
0, 0);
gtk_widget_show(toggle);
button = gtk_button_new_with_label(_("Close"));
gtk_signal_connect(GTK_OBJECT(button), "clicked",
(GtkSignalFunc) properties_cancel_callback,
prop);
gtk_box_pack_end(GTK_BOX(GTK_DIALOG(dialog)->action_area), button, TRUE, TRUE, 0);
gtk_widget_show(button);
gtk_container_border_width(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area), 4);
button = gtk_button_new_with_label(_("Apply"));
gtk_signal_connect(GTK_OBJECT(button), "clicked",
(GtkSignalFunc) properties_ok_callback,
prop);
gtk_box_pack_end(GTK_BOX(GTK_DIALOG(dialog)->action_area), button, TRUE, TRUE, 0);
gtk_widget_show(button);
gtk_signal_connect(GTK_OBJECT(dialog), "delete_event",
(GtkSignalFunc) properties_cancel_callback,
prop);
return dialog;
}
static void
properties(GtkWidget *widget)
{
GnomeDesktopEntry *dentry;
char *path;
GtkWidget *dialog;
Launcher *launcher;
launcher = gtk_object_get_user_data(GTK_OBJECT(widget));
path = launcher->params;
dentry = gnome_desktop_entry_load(path);
if (!dentry) {
fprintf(stderr,
"launcher properties: oops, gnome_desktop_entry_load() returned NULL\n"
" on \"%s\"\n", path);
return;
}
dialog = create_properties_dialog(dentry,launcher);
gtk_widget_show(dialog);
}
static void
create_instance (PanelWidget *panel, char *params, int pos)
{
Launcher *launcher;
PanelCommand cmd;
GnomeDesktopEntry *dentry;
launcher = create_launcher (GTK_WIDGET(panel), params);
if (!launcher)
return;
cmd.cmd = PANEL_CMD_REGISTER_TOY;
cmd.params.register_toy.applet = launcher->button;
cmd.params.register_toy.id = APPLET_ID;
cmd.params.register_toy.pos = pos;
cmd.params.register_toy.flags = APPLET_HAS_PROPERTIES;
(*panel_cmd_func) (&cmd);
dentry = gnome_desktop_entry_load(launcher->params);
cmd.cmd = PANEL_CMD_SET_TOOLTIP;
cmd.params.set_tooltip.applet = launcher->button;
cmd.params.set_tooltip.tooltip = dentry->comment;
(*panel_cmd_func) (&cmd);
}
gpointer
applet_cmd_func(AppletCommand *cmd)
{
Launcher *launcher;
g_assert(cmd != NULL);
switch (cmd->cmd) {
case APPLET_CMD_QUERY:
return APPLET_ID;
case APPLET_CMD_INIT_MODULE:
panel_cmd_func = cmd->params.init_module.cmd_func;
break;
case APPLET_CMD_DESTROY_MODULE:
break;
case APPLET_CMD_GET_DEFAULT_PARAMS:
fprintf(stderr, "Launcher: APPLET_CMD_GET_DEFAULT_PARAMS not yet supported\n");