Commit dcc00e21 authored by George Lebl's avatar George Lebl

Removed old files (DL stuff) and the clock applet is in clock/ now

- George
parent 99f6e16a
#ifndef APPLET_CMDS_H
#define APPLET_CMDS_H
#include "panel_cmds.h"
#include "panel-widget.h"
#include "panel.h"
BEGIN_GNOME_DECLS
typedef enum {
APPLET_CMD_QUERY,
APPLET_CMD_INIT_MODULE,
APPLET_CMD_DESTROY_MODULE,
APPLET_CMD_GET_DEFAULT_PARAMS,
APPLET_CMD_CREATE_INSTANCE,
APPLET_CMD_GET_INSTANCE_PARAMS,
APPLET_CMD_ORIENTATION_CHANGE_NOTIFY,
APPLET_CMD_PROPERTIES
} AppletCommandType;
typedef struct {
AppletCommandType cmd;
PanelWidget *panel;
GtkWidget *applet;
union {
/* Init module parameters */
struct {
PanelCmdFunc cmd_func;
} init_module;
/* Create instance parameters */
struct {
char *params;
int pos;
int panel;
} create_instance;
/* Orientation change notify parameters */
struct {
PanelSnapped snapped;
PanelOrientation orient;
} orientation_change_notify;
} params;
} AppletCommand;
typedef gpointer (*AppletCmdFunc) (AppletCommand *cmd);
END_GNOME_DECLS
#endif
/* Gnome panel: dynamic linking and handling of applet library files
* (C) 1997 the Free Software Foundation
*
* Authors: Federico Mena
* Miguel de Icaza
*/
#include <sys/stat.h>
#include <sys/types.h>
#include <dirent.h>
#include <string.h>
#include <unistd.h>
#include "gnome.h"
#include "applet_files.h"
#define APPLET_CMD_FUNC_NAME "applet_cmd_func"
GHashTable *applet_files_ht;
static AppletFile *
applet_file_new(GnomeLibHandle *dl_handle, char *filename, AppletCmdFunc cmd_func)
{
AppletFile *af;
af = g_new(AppletFile, 1);
af->dl_handle = dl_handle;
af->filename = filename;
af->cmd_func = cmd_func;
return af;
}
static void
applet_file_destroy(gpointer key, gpointer value, gpointer user_data)
{
AppletFile *af;
af = value;
gnome_dl_unload(af->dl_handle);
g_free(af->filename);
g_free(af);
}
static GnomeFuncHandle *
get_dl_func(GnomeLibHandle *handle, char *name)
{
GnomeFuncHandle *func;
const char *error;
func = gnome_dl_findsym(name, handle);
if ((error = gnome_dl_error()) != NULL) {
fprintf(stderr, "get_dl_func: %s (func is %s)\n", error,
name);
g_assert(error == NULL);
}
return func;
}
static void
init_applet_file(char *filename)
{
GnomeLibHandle *handle;
const char *error;
char *id;
AppletCmdFunc cmd_func;
AppletCommand cmd;
AppletFile *af;
handle = gnome_dl_load(filename, GNOME_DL_BIND_LAZY);
if (!handle) {
error = gnome_dl_error();
fprintf(stderr, "init_applet_file: %s\n", error);
return;
}
cmd_func = (AppletCmdFunc) get_dl_func(handle, APPLET_CMD_FUNC_NAME);
cmd.cmd = APPLET_CMD_QUERY;
id = (*cmd_func) (&cmd);
if (!id) {
fprintf(stderr, "init_applet_file: APPLET_CMD_QUERY on %s returned a NULL identifier\n", filename);
return;
}
af = applet_file_new(handle, g_strdup(filename), cmd_func);
g_hash_table_insert(applet_files_ht, id, af);
}
void
applet_files_init(void)
{
char *dirname;
DIR *dir;
struct dirent *dent;
char *filename;
struct stat filestat;
int len;
applet_files_ht = g_hash_table_new(g_str_hash, g_str_equal);
dirname = gnome_unconditional_libdir_file("."); /* Get libdir name */
dir = opendir(dirname);
if (!dir)
return;
while ((dent = readdir(dir)) != NULL) {
/* We only want stuff of the form "libpanel_*.so" */
if (strncmp(dent->d_name, "libpanel_", 9) != 0)
continue;
len = strlen(dent->d_name); /* Cannot be less than 9, because of above */
if (strcmp(dent->d_name + (len - 3), ".so") != 0)
continue;
filename = g_concat_dir_and_file(dirname, dent->d_name);
if ((stat(filename, &filestat) == 0) &&
S_ISREG(filestat.st_mode))
init_applet_file(filename);
g_free(filename);
}
closedir(dir);
g_free(dirname);
}
void
applet_files_destroy(void)
{
g_hash_table_foreach(applet_files_ht, applet_file_destroy, NULL);
g_hash_table_destroy(applet_files_ht);
}
AppletCmdFunc
get_applet_cmd_func(char *id)
{
AppletFile *af;
af = g_hash_table_lookup(applet_files_ht, id);
if (!af)
return NULL;
else
return af->cmd_func;
}
#ifndef APPLET_FILE_H
#define APPLET_FILE_H
#include "gnome.h"
#include "applet_cmds.h"
BEGIN_GNOME_DECLS
typedef struct {
GnomeLibHandle *dl_handle;
char *filename;
AppletCmdFunc cmd_func;
} AppletFile;
extern GHashTable *applet_files_ht;
void applet_files_init(void);
void applet_files_destroy(void);
AppletCmdFunc get_applet_cmd_func(char *id);
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);
}
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;
}
#ifndef PANEL_CMDS_H
#define PANEL_CMDS_H
BEGIN_GNOME_DECLS
/*
typedef enum {
APPLET_HAS_PROPERTIES = 1L << 0
} AppletFlags;
*/
typedef enum {
PANEL_CMD_QUIT,
PANEL_CMD_GET_APPLET_TYPES,
PANEL_CMD_GET_APPLET_CMD_FUNC,
PANEL_CMD_CREATE_APPLET,
PANEL_CMD_REGISTER_TOY,
PANEL_CMD_CREATE_DRAWER,
PANEL_CMD_SET_TOOLTIP,
PANEL_CMD_PROPERTIES
} PanelCommandType;
typedef struct {
PanelCommandType cmd;
union {
/* Get applet command function parameters */
struct {
char *id;
} get_applet_cmd_func;
/* Create applet parameters */
struct {
char *id;
char *params;
int pos;
int panel;
} create_applet;
/* Register toy parameters */
struct {
GtkWidget *applet;
char *id;
int pos;
int panel;
long flags;
} register_toy;
/* Create drawer parameters */
struct {
char *name;
char *iconopen;
char *iconclosed;
int step_size;
int pos;
int panel;
} create_drawer;
/* Tooltip */
struct {
GtkWidget *applet;
char *tooltip;
} set_tooltip;
} params;
} PanelCommand;
typedef gpointer (*PanelCmdFunc) (PanelCommand *cmd);
END_GNOME_DECLS
#endif
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