Browse Source

Major update

(Old svn revision: 3246)
upstream/xfce4-panel-4.10.1
Jasper Huijsmans 20 years ago
parent
commit
5ee060b63e
  1. 9
      Makefile
  2. 100
      README
  3. 81
      README.xml
  4. 707
      builtins.c
  5. 29
      builtins.h
  6. 701
      callbacks.c
  7. 76
      callbacks.h
  8. 886
      central.c
  9. 94
      central.h
  10. 1581
      dialogs.c
  11. 31
      dialogs.h
  12. 44
      dnd.c
  13. 27
      dnd.h
  14. 216
      example.xfce4rc
  15. 121
      global.h
  16. 410
      icons.c
  17. 122
      icons.h
  18. 368
      item.c
  19. 72
      item.h
  20. 400
      module.c
  21. 109
      module.h
  22. 283
      move.c
  23. 6
      move.h
  24. 497
      plugins/mailcheck.c
  25. 580
      popup.c
  26. 129
      popup.h
  27. 734
      settings.c
  28. 40
      settings.h
  29. 592
      side.c
  30. 112
      side.h
  31. 299
      wmhints.c
  32. 35
      wmhints.h
  33. 671
      xfce.c
  34. 172
      xfce.h

9
Makefile

@ -1,6 +1,6 @@
OBJS = xfce.o central.o side.o \
popup.o item.o module.o settings.o icons.o wmhints.o \
builtins.o move.o dialogs.o callbacks.o
OBJS = xfce.o central.o side.o dnd.o \
popup.o item.o module.o icons.o wmhints.o \
builtins.o move.o dialogs.o callbacks.o settings.o
PROG = xfce2
@ -18,9 +18,6 @@ all: $(PROG) sub
$(PROG): $(OBJS)
$(CC) $(GTK_LIBS) -o $(PROG) $(OBJS)
mailcheck.o:
$(CC) -fPIC $(GTK_CFLAGS) -c mailcheck.c -o mailcheck.o
sub:
(cd plugins; make)

100
README

@ -1,5 +1,5 @@
README for xfce version 4.x
---------------------------
===========================
WHAT IS IT ?
------------
@ -11,58 +11,52 @@ this new and improved toolkit (see http://www.gtk.org).
WHAT'S NEW ?
------------
Apart from the toolkit changes the underlying framework of the panel has also
changed completely. All interactions with the window manager take place through
the new window manager hints as defined on http://www.freedesktop.org. This
means that you will need a compliant window manager for xfce to function
properly (preferably xfwm4 ;-).
changed completely.
All interactions with the window manager take place through the new window
manager hints as defined on http://www.freedesktop.org. This means that you will
need a compliant window manager for xfce to function properly (preferably xfwm4
;-).
The panel can now hold normal buttons and dynamic modules.
INFO FOR DEVELOPERS
-------------------
This section gives an overview of the internal design of the panel to assist
anyone who wants to read the code.
Several structures are defined to describe the different parts of the panel.
The panel consists of three subpanels: two side panels (left and right) and a
central panel. The central panel contains the desktop switcher and four small
butons. The side panels consist of several panel groups.
A panel group in turn consists of a top and a bottom widget. The top widget is
usually a popup button, except for the outer groups on both panels where it is a
move handle. The bottom widget is either a normal panel item (icon button with
run action) or a module.
A module can be a builtin module or an external plugin. It usually is an
indicator of some sort, e.g. a clock, a trashcan and a mail checker. For
demonstration purposes xfce comes with a builtin clock and trashcan and a sample
plugin mailchecker. plugins are loaded throught the gmodule interface.
The panel defines a sort of API where commands are passed on through the
hierarchy of structures.
*** UNFINISHED PART ***
Popup menus are not yet implemented.
Currently there is no configuration framework yet. There are functions to change
the size of the panel (small, medium or large) and the style (new or old). The
number of desktops can be set in settings.c for now.
The panel can switch desktops and, even nicer, reacts to changes made by other
programs, both for the current desktop and the number of desktops.
C STRUCTURE HIERARCHY
---------------------
This only defines the relation between structures. Their members are omitted.
You can find them in their corresponding header files.
XfcePanel panel
SidePanel *left_panel
PanelGroup *groups [NBGROUPS]
MoveHandle handle / PanelPopup popup
PanelItem item / PanelModule module
CentralPanel central_panel
ScreenButton *screen_buttons [NBSCREENS]
SidePanel right_panel
PanelGroup *groups [NBGROUPS]
MoveHandle handle / PanelPopup popup
PanelItem item / PanelModule module
===================
If you are interested in helping with the development of xfce4 the best place to
start reading is global.h which hold the type definitions of the different
data structures used.
The panel design is a hierarchy of components:
- Panel (file xfce.c): Global settings and panel framework.
- Central panel (file central.c): Minibuttons and desktop switcher.
- Side panels (file side.c): Left and right panel containing several panel groups.
A panel group consists of a top widget and a bottom widget. The top widget is
usually a popup button, but for the outermost groups it is a move handle. The
bottom widget is either a panel item (a button with an icon) or a panel module
(dynamically updated).
- Panel popup (file popup.c): Popup button and popup menu containing menu items.
- Panel item (file item.c): Tradioanl panel item consisting of an icon button,
which starts an application.
- Panel module (files module.c and builtins.c): New panel control, which is
dynamically updated. Modules can be builtin or external using the gmodule
interface.
Other files:
- callbacks.c: most callback functions are defined here.
- dialogs.c: convenience dialogs and panel configuration dialogs.
- dnd.c: general dnd convenience functions.
- move.c: moveing the panel around.
- settings.c: reading and writing panel configuration.
- wmhints.c: window manager hints

81
README.xml

@ -1,25 +1,29 @@
Proposal for xml config file for xfce
-------------------------------------
namespace: xfce:"http://www.xfce.org/xfce"
root: Panel
See example.xfce4rc for an example
name: Panel
parent: none
properties: size (int), popupsize (int), style (int), icontheme (string)
namespace: xfce:"http://www.xfce.org/xfce" (not implemented)
==============================================================================
root: Xfce
children:
Position
Panel
Central
Left
Right
name: Position
parent: Panel
properties: x (int), y (int)
content: none
children: none
==============================================================================
name: Panel
parent: Xfce
properties: size (int), popupsize (int), style (int), icontheme (string),
left (int), right (int), screens (int)
children:
Position
Lock
Exit
name: Central
parent: Panel
parent: Xfce
properties: none
content: none
children:
@ -28,44 +32,46 @@ children:
Power
name: Left
parent: Panel
parent: Xfce
properties: visible
content: none
children:
Group
name Right
parent: Panel
parent: Xfce
properties: visible
content: none
children:
Group
name: Screens
parent: Central
properties: visible (int)
==============================================================================
name: Position
parent: Panel
properties: x (int), y (int)
content: none
children:
Screen
name: Screen
parent: Screens
properties: none
content: screen name
children: none
name: Lock
parent: Central
parent: Panel
properties: none
content: lock command
children: none
name: Power
name: Exit
parent: Panel
properties: none
content: command run at exit
children: none
------------------------------------------------------------------------------
name: Screen
parent: Central
properties: ?
content: ? something to quit the session
properties: none
content: screen name
children: none
------------------------------------------------------------------------------
name: Group
parent: Left, Right
properties: none
@ -75,6 +81,7 @@ children:
Item
Module
==============================================================================
name: Popup
parent: Group
properties: none
@ -82,6 +89,13 @@ content: none
children:
Item
name: Module
parent: Group
properties: id (int)
content: module name
children: none
------------------------------------------------------------------------------
name: Item
parent: Group, Popup
properties: none
@ -91,14 +105,8 @@ children:
Command
Tooltip
Icon
:close
name: Module
parent: Group
properties: id (int)
content: module name
children: none
==============================================================================
name: Caption
parent: Item
properties: none
@ -123,6 +131,3 @@ properties: id (int)
content: path to icon
children: none
Example
-------

707
builtins.c

@ -1,435 +1,452 @@
/* builtins.c
*
* Copyright (C) 2002 Jasper Huijsmans (j.b.huijsmans@hetnet.nl)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/stat.h>
#include <gtk/gtk.h>
#include <time.h>
#include "xfce.h"
#include "builtins.h"
#include "callbacks.h"
#include "xfce.h"
#include "module.h"
#include "item.h"
#include "icons.h"
#include "dialogs.h"
extern GtkTooltips *tooltips;
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
/*****************************************************************************/
Builtin modules
enum
{
TARGET_STRING,
TARGET_ROOTWIN,
TARGET_URL
};
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
static GtkTargetEntry target_table[] = {
{"text/uri-list", 0, TARGET_URL},
{"STRING", 0, TARGET_STRING}
};
static gboolean create_clock_module(PanelModule * pm);
static guint n_targets = sizeof (target_table) / sizeof (target_table[0]);
static gboolean create_trash_module(PanelModule * pm);
/*****************************************************************************/
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
/* clock module */
gboolean create_builtin_module(PanelModule * pm)
{
switch (pm->id)
{
case CLOCK_MODULE:
return create_clock_module(pm);
break;
case TRASH_MODULE:
return create_trash_module(pm);
break;
default:
return FALSE;
}
}
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Clock module
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
typedef struct
{
GtkWidget *eventbox;
int size;
gboolean show_colon;
int interval;
int timeout;
GtkWidget *frame;
GtkWidget *label;
int size;
gboolean show_colon;
GtkWidget *frame;
GtkWidget *eventbox;
GtkWidget *label;
}
t_clock;
/* "There can be only one" */
gboolean panel_has_clock = FALSE;
static t_clock *clock_new(void)
{
t_clock *clock = g_new(t_clock, 1);
int secs_in_day = 24 * 60 * 60;
clock->size = MEDIUM;
clock->show_colon = TRUE;
static gboolean
adjust_time (t_clock *clock)
clock->frame = gtk_frame_new(NULL);
gtk_container_set_border_width(GTK_CONTAINER(clock->frame), 4);
gtk_frame_set_shadow_type(GTK_FRAME(clock->frame), GTK_SHADOW_IN);
gtk_widget_show(clock->frame);
clock->eventbox = gtk_event_box_new();
gtk_container_add(GTK_CONTAINER(clock->frame), clock->eventbox);
gtk_widget_show(clock->eventbox);
clock->label = gtk_label_new(NULL);
gtk_container_add(GTK_CONTAINER(clock->eventbox), clock->label);
gtk_widget_show(clock->label);
return clock;
}
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
static gboolean adjust_time(PanelModule *pm)
{
GTimeVal tv;
int today;
int hrs, mins;
char *text, *markup;
g_get_current_time (&tv);
today = tv.tv_sec % secs_in_day;
hrs = today / 3600;
mins = (today % 3600) / 60;
text = g_strdup_printf ("%.2d%c%.2d",
hrs + 2, clock->show_colon ? ':' : ' ', mins);
switch (clock->size)
{
case SMALL:
markup = g_strconcat ("<tt><span size=\"smaller\">",
text, "</span></tt>", NULL);
break;
case LARGE:
markup = g_strconcat ("<tt><span size=\"larger\">",
text, "</span></tt>", NULL);
break;
default:
markup = g_strconcat ("<tt>", text, "</tt>", NULL);
break;
}
clock->show_colon = !clock->show_colon;
gtk_label_set_markup (GTK_LABEL (clock->label), markup);
g_free (text);
g_free (markup);
return TRUE;
time_t t;
struct tm *tm;
int hrs, mins;
char *text, *markup;
t_clock *clock = (t_clock *) pm->data;
t = time(0);
tm = localtime(&t);
hrs = tm->tm_hour;
mins = tm->tm_min;
text = g_strdup_printf("%.2d%c%.2d", hrs, clock->show_colon ? ':' : ' ', mins);
switch (clock->size)
{
case SMALL:
markup = g_strconcat("<tt><span size=\"medium\">",
text, "</span></tt>", NULL);
break;
case LARGE:
markup = g_strconcat("<tt><span size=\"x-large\">",
text, "</span></tt>", NULL);
break;
default:
markup = g_strconcat("<tt><span size=\"large\">",
text, "</span></tt>", NULL);
break;
}
clock->show_colon = !clock->show_colon;
gtk_label_set_markup(GTK_LABEL(clock->label), markup);
g_free(text);
g_free(markup);
return TRUE;
}
t_clock *
clock_init (GtkWidget *eventbox)
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
void clock_pack(PanelModule * pm, GtkBox * box)
{
t_clock *clock = g_new (t_clock, 1);
panel_has_clock = TRUE;
clock->size = MEDIUM;
clock->interval = 1000; /* 1 sec */
clock->timeout = 0;
clock->frame = gtk_frame_new (NULL);
gtk_container_set_border_width (GTK_CONTAINER (clock->frame), 4);
gtk_frame_set_shadow_type (GTK_FRAME (clock->frame), GTK_SHADOW_IN);
gtk_container_add (GTK_CONTAINER (eventbox), clock->frame);
clock->eventbox = gtk_event_box_new ();
gtk_container_add (GTK_CONTAINER (clock->frame), clock->eventbox);
clock->label = gtk_label_new (NULL);
gtk_container_add (GTK_CONTAINER (clock->eventbox), clock->label);
gtk_widget_show_all (clock->frame);
adjust_time (clock);
return clock;
t_clock *clock = (t_clock *) pm->data;
gtk_box_pack_start(box, clock->frame, TRUE, TRUE, 0);
}
void
clock_run (t_clock *clock)
void clock_unpack(PanelModule * pm, GtkContainer * container)
{
clock->timeout = g_timeout_add (clock->interval,
(GSourceFunc) adjust_time, clock);
t_clock *clock = (t_clock *) pm->data;
gtk_container_remove(container, clock->frame);
}
void
clock_stop (t_clock *clock)
void clock_free(PanelModule * pm)
{
panel_has_clock = FALSE;
g_source_remove (clock->timeout);
gtk_widget_destroy (clock->frame);
g_free (clock);
t_clock *clock = (t_clock *) pm->data;
if (GTK_IS_WIDGET(clock->frame))
gtk_widget_destroy(clock->frame);
g_free(clock);
}
void
clock_set_size (t_clock *clock, int size)
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
void clock_set_size(PanelModule * pm, int size)
{
int s = icon_size (size);
clock->size = size;
gtk_widget_set_size_request (clock->frame, s, s);
int s = icon_size(size);
t_clock *clock = (t_clock *) pm->data;
clock->size = size;
gtk_widget_set_size_request(clock->frame, s, s);
}
void
clock_set_style (t_clock *clock, int style)
void clock_set_style(PanelModule * pm, int style)
{
if (style == OLD_STYLE)
t_clock *clock = (t_clock *) pm->data;
if(style == OLD_STYLE)
{
gtk_widget_set_name (clock->frame, "gxfce_color2");
gtk_widget_set_name (clock->label, "gxfce_color2");
gtk_widget_set_name (clock->eventbox, "gxfce_color2");
gtk_widget_set_name(clock->frame, "gxfce_color2");
gtk_widget_set_name(clock->label, "gxfce_color2");
gtk_widget_set_name(clock->eventbox, "gxfce_color2");
}
else
else
{
gtk_widget_set_name (clock->frame, "gxfce_color4");
gtk_widget_set_name (clock->label, "gxfce_color4");
gtk_widget_set_name (clock->eventbox, "gxfce_color4");
gtk_widget_set_name(clock->frame, "gxfce_color4");
gtk_widget_set_name(clock->label, "gxfce_color4");
gtk_widget_set_name(clock->eventbox, "gxfce_color4");
}
}
void
clock_configure (void)
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
void clock_configure(PanelModule * pm)
{
report_error(_("No configuration possible (yet)."));
}
gboolean
create_clock_module (PanelModule *pm)
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
static gboolean create_clock_module(PanelModule * pm)
{
if (panel_has_clock)
return FALSE;
pm->init = (gpointer) clock_init;
pm->run = (gpointer) clock_run;
pm->stop = (gpointer) clock_stop;
pm->set_size = (gpointer) clock_set_size;
pm->set_style = (gpointer) clock_set_style;
pm->configure = (gpointer) clock_configure;
pm->data = (gpointer) clock_init (pm->eventbox);
return TRUE;
t_clock *clock = clock_new();
pm->caption = g_strdup(_("Clock"));
pm->data = (gpointer) clock;
pm->main = clock->eventbox;
pm->interval = 1000; /* 1 sec */
pm->update = (gpointer) adjust_time;
pm->pack = (gpointer) clock_pack;
pm->unpack = (gpointer) clock_unpack;
pm->free = (gpointer) clock_free;
pm->set_size = (gpointer) clock_set_size;
pm->set_style = (gpointer) clock_set_style;
pm->configure = (gpointer) clock_configure;
if (pm->parent)
adjust_time(pm);
return TRUE;
}
/*****************************************************************************/
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
/* trashcan module */
Trash module
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
typedef struct
{
char *dirname;
char *command;
int interval;
gboolean stop;
int size;
gboolean empty;
int changed;
GdkPixbuf *current_pb;
GdkPixbuf *empty_pb;
GdkPixbuf *full_pb;
GtkWidget *button;
GtkWidget *image;
char *dirname;
int size;
gboolean empty;
GdkPixbuf *empty_pb;
GdkPixbuf *full_pb;
/* we just overload the panel item a bit */
PanelItem *item;
}
t_trash;
static void
free_trash (t_trash *trash)
static t_trash *trash_new(PanelGroup * pg)
{
g_free (trash->dirname);
g_free (trash->command);
g_object_unref (trash->empty_pb);
g_object_unref (trash->full_pb);
}
t_trash *trash = g_new(t_trash, 1);
const char *home = g_getenv("HOME");
static void
trash_set_scaled_image (t_trash *trash)
{
GdkPixbuf *pb;
int width, height, bw;
bw = trash->size == SMALL ? 0 : 2;
width = height = icon_size (trash->size);
gtk_container_set_border_width (GTK_CONTAINER (trash->button), bw);
gtk_widget_set_size_request (trash->button, width + 4, height + 4);
trash->dirname = g_strconcat(home, "/.xfce/trash", NULL);
trash->size = MEDIUM;
trash->empty = TRUE;
trash->item = panel_item_new(pg);
trash->item->command = g_strdup("xftrash");
trash->empty_pb = get_trash_pixbuf(TRASH_EMPTY_ICON);
trash->full_pb = get_trash_pixbuf(TRASH_FULL_ICON);
pb = gdk_pixbuf_scale_simple (trash->current_pb,
width - 2 * bw,
height - 2 * bw,
GDK_INTERP_BILINEAR);
gtk_image_set_from_pixbuf (GTK_IMAGE (trash->image), pb);
g_object_unref (pb);
create_panel_item(trash->item);
g_object_unref (trash->item->pb);
trash->item->pb = trash->empty_pb;
panel_item_set_size(trash->item, MEDIUM);
add_tooltip(trash->item->button, _("Trashcan: 0 files"));
return trash;
}
static gboolean
check_trash (t_trash *trash)
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
static gboolean check_trash(PanelModule *pm)
{
GDir *dir = g_dir_open (trash->dirname, 0, NULL);
const char *file;
char text[MAXSTRLEN];
if (dir)
file = g_dir_read_name (dir);
if (!dir || !file)
t_trash *trash = (t_trash *) pm->data;
PanelItem *pi = trash->item;
GDir *dir = g_dir_open(trash->dirname, 0, NULL);
const char *file;
char text[MAXSTRLEN];
gboolean changed = FALSE;
if(dir)
file = g_dir_read_name(dir);
if(!dir || !file)
{
if (dir)
g_dir_close (dir);
if (!trash->empty)
{
trash->current_pb = trash->empty_pb;
trash->empty = TRUE;
trash->changed = TRUE;
gtk_tooltips_set_tip (tooltips, trash->button,
_("Trashcan: 0 files"), NULL);
}
if(!trash->empty)
{
pi->pb = trash->empty_pb;
trash->empty = TRUE;
changed = TRUE;
add_tooltip(pi->button, _("Trashcan: 0 files"));
}
}
else
else
{
struct stat s;
int number = 0;
int size = 0;
char *cwd = g_get_current_dir ();
chdir (trash->dirname);
if (trash->empty)
{
trash->current_pb = trash->full_pb;
trash->empty = FALSE;
trash->changed = TRUE;
}
while (file)
{
number++;
stat (file, &s);
size += s.st_size;
file = g_dir_read_name (dir);
}
chdir (cwd);
g_free (cwd);
g_dir_close (dir);
struct stat s;
int number = 0;
int size = 0;
char *cwd = g_get_current_dir();
chdir(trash->dirname);
if(trash->empty)
{
pi->pb = trash->full_pb;
trash->empty = FALSE;
changed = TRUE;
}
while(file)
{
number++;
stat(file, &s);
size += s.st_size;
file = g_dir_read_name(dir);
}
chdir(cwd);
g_free(cwd);
sprintf (text, _("Trashcan: %d files / %d kb"), number, size / 1024);
gtk_tooltips_set_tip (tooltips, trash->button,
text, NULL);
if (size < 1024)
sprintf(text, _("Trashcan: %d files / %d B"), number, size);
else if (size < 1024 * 1024)
sprintf(text, _("Trashcan: %d files / %d KB"), number, size / 1024);
else
sprintf(text, _("Trashcan: %d files / %d MB"), number, size / (1024 * 1024));
add_tooltip(pi->button, text);
}
if (trash->changed)
{
trash_set_scaled_image (trash);
trash->changed = FALSE;
}
if (trash->stop)
if (dir)
g_dir_close(dir);
if(changed)
{
free_trash (trash);
return FALSE;
panel_item_set_size(trash->item, settings.size);
}
else
return TRUE;
}
void
trash_drop_cb (GtkWidget * widget, GdkDragContext * context,
gint x, gint y, GtkSelectionData * data,
guint info, guint time, gpointer cbdata)
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
static void trash_pack(PanelModule * pm, GtkBox * box)
{
GList *fnames, *fnp;
guint count;
char *execute, *cmd;
fnames = gnome_uri_list_extract_filenames ((char *) data->data);
count = g_list_length (fnames);
if (count > 0)
{
execute = (char *) g_malloc (MAXSTRLEN);
cmd = (char *) cbdata;
strcpy (execute, cmd);
for (fnp = fnames; fnp; fnp = fnp->next, count--)
{
strcat (execute, " ");
strncat (execute, (char *) (fnp->data), MAXSTRLEN - 1);
}
exec_cmd (execute);
g_free (execute);
}
gnome_uri_list_free_strings (fnames);
gtk_drag_finish (context, (count > 0), (context->action == GDK_ACTION_MOVE), time);
t_trash *trash = (t_trash *) pm->data;
panel_item_pack(trash->item, box);
}
t_trash *
trash_init (GtkWidget *eventbox)
static void trash_unpack(PanelModule * pm, GtkContainer *container)
{
const char *home = g_getenv ("HOME");
t_trash *trash = g_new (t_trash, 1);
trash->dirname = g_strconcat (home, "/.xfce/trash", NULL);
trash->command = g_strdup ("xftrash");
trash->interval = 2000; /* 2 sec */
trash->stop = FALSE;
trash->size = MEDIUM;
trash->empty = TRUE;
trash->changed = FALSE;
trash->empty_pb = get_trashcan_pixbuf (TRASH_EMPTY_ICON);
trash->full_pb = get_trashcan_pixbuf (TRASH_FULL_ICON);
trash->button = gtk_button_new ();
gtk_button_set_relief (GTK_BUTTON (trash->button), GTK_RELIEF_NONE);
trash->image = gtk_image_new ();
trash->current_pb = trash->empty_pb;
trash_set_scaled_image (trash);
gtk_container_add (GTK_CONTAINER (trash->button), trash->image);
gtk_container_add (GTK_CONTAINER (eventbox), trash->button);
gtk_widget_show_all (trash->button);
gtk_tooltips_set_tip (tooltips, trash->button,
_("Trashcan: 0 files"), NULL);
check_trash (trash);
/* signals */
if (trash->command)
{
g_signal_connect_swapped (trash->button, "clicked",
G_CALLBACK (exec_cmd), trash->command);
gtk_drag_dest_set (trash->button, GTK_DEST_DEFAULT_ALL,
target_table, n_targets, GDK_ACTION_COPY);
g_signal_connect (trash->button, "drag_data_received",
G_CALLBACK (trash_drop_cb), trash->command);
}
return trash;
t_trash *trash = (t_trash *) pm->data;
panel_item_unpack(trash->item, container);
}
void
trash_run (t_trash *trash)
static void trash_free(PanelModule * pm)
{
g_timeout_add (trash->interval, (GSourceFunc) check_trash, trash);
t_trash *trash = (t_trash *) pm->data;
g_free(trash->dirname);
/* will be unreffed in panel_item_free() */
g_object_ref(trash->item->pb);
panel_item_free(trash->item);
g_object_unref(trash->empty_pb);
g_object_unref(trash->full_pb);
if (GTK_IS_WIDGET(pm->main))
gtk_widget_destroy(pm->main);
g_free(trash);
}
void
trash_stop (t_trash *trash)
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
static void trash_set_size(PanelModule * pm, int size)
{
trash->stop = TRUE;
t_trash *trash = (t_trash *) pm->data;
trash->size = size;
panel_item_set_size(trash->item, size);
}
void trash_set_size (t_trash *trash, int size)
static void trash_set_icon_theme(PanelModule * pm, const char *theme)
{
trash->size = size;
trash_set_scaled_image (trash);
t_trash *trash = (t_trash *) pm->data;
g_object_unref(trash->empty_pb);
g_object_unref(trash->full_pb);
trash->empty_pb = get_themed_trash_pixbuf(TRASH_EMPTY_ICON, theme);
trash->full_pb = get_themed_trash_pixbuf(TRASH_FULL_ICON, theme);
if(trash->empty)
trash->item->pb = trash->empty_pb;
else
trash->item->pb = trash->full_pb;
panel_item_set_size(trash->item, trash->size);
}
gboolean
create_trash_module (PanelModule *pm)
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
static gboolean create_trash_module(PanelModule * pm)
{
pm->init = (gpointer) trash_init;
pm->run = (gpointer) trash_run;
pm->stop = (gpointer) trash_stop;
pm->set_size = (gpointer) trash_set_size;
pm->data = (gpointer) trash_init (pm->eventbox);
return TRUE;
}
t_trash *trash = trash_new(pm->parent);
pm->caption = g_strdup(_("Trash can"));
pm->data = (gpointer) trash;
pm->main = trash->item->button;
pm->interval = 2000; /* 2 sec */
pm->update = (gpointer) check_trash;
pm->pack = (gpointer) trash_pack;
pm->unpack = (gpointer) trash_unpack;
pm->free = (gpointer) trash_free;
pm->set_size = (gpointer) trash_set_size;
pm->set_icon_theme = (gpointer) trash_set_icon_theme;
if (pm->parent)
check_trash(pm);
return TRUE;
}

29
builtins.h

@ -1,14 +1,27 @@
/* builtins.h
*
* Copyright (C) 2002 Jasper Huijsmans (j.b.huijsmans@hetnet.nl)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __XFCE_BUILTINS_H__
#define __XFCE_BUILTINS_H__
#include "xfce.h"
#include "module.h"
/* builtin modules */
gboolean create_clock_module (PanelModule *pm);
gboolean create_trash_module (PanelModule *pm);
#include "global.h"
gboolean create_mailcheck_module (PanelModule *pm);
gboolean create_builtin_module(PanelModule * pm);
#endif /* __XFCE_BUILTINS_H__ */

701
callbacks.c

@ -1,11 +1,31 @@
/* callbacks.c
*
* Copyright (C) 2002 Jasper Huijsmans <j.b.huijsmans@hetnet.nl>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <gtk/gtk.h>
#include "xfce.h"
#include "callbacks.h"
#include "dialogs.h"
#include "panel.h"
#include "central.h"
#include "side.h"
#include "item.h"
@ -14,33 +34,35 @@
static PanelPopup *open_popup = NULL;
void hide_current_popup_menu (void);
void hide_current_popup_menu(void);
/*****************************************************************************/
/* useful utility functions */
void
exec_cmd (const char *cmd)
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Utility functions
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
void exec_cmd(const char *cmd)
{
GError *error = NULL; /* this must be NULL to prevent crash :( */
GError *error = NULL; /* this must be NULL to prevent crash :( */
if(!cmd)
return;
if (!g_spawn_command_line_async (cmd, &error))
if(!g_spawn_command_line_async(cmd, &error))
{
GtkWidget *dialog;
char *msg;
msg = g_strcompress (error->message);
dialog = gtk_message_dialog_new (NULL,
GTK_DIALOG_MODAL,
GTK_MESSAGE_WARNING,
GTK_BUTTONS_OK, msg);
gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
g_free (msg);
char *msg;
msg = g_strcompress(error->message);
report_error(msg);
g_free(msg);
}
}
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
/*** the next three routines are taken straight from gnome-libs so that the
gtk-only version can receive drag and drops as well ***/
/**
@ -49,11 +71,10 @@ exec_cmd (const char *cmd)
*
* Releases all of the resources allocated by @list.
*/
void
gnome_uri_list_free_strings (GList * list)
void gnome_uri_list_free_strings(GList * list)
{
g_list_foreach (list, (GFunc) g_free, NULL);
g_list_free (list);
g_list_foreach(list, (GFunc) g_free, NULL);
g_list_free(list);
}
@ -64,52 +85,51 @@ gnome_uri_list_free_strings (GList * list)
* Returns a GList containing strings allocated with g_malloc
* that have been splitted from @uri-list.
*/
GList *
gnome_uri_list_extract_uris (const gchar * uri_list)
GList *gnome_uri_list_extract_uris(const gchar * uri_list)
{
const gchar *p, *q;
gchar *retval;
GList *result = NULL;
const gchar *p, *q;
gchar *retval;
GList *result = NULL;
g_return_val_if_fail (uri_list != NULL, NULL);
g_return_val_if_fail(uri_list != NULL, NULL);
p = uri_list;
p = uri_list;
/* We don't actually try to validate the URI according to RFC
* 2396, or even check for allowed characters - we just ignore
* comments and trim whitespace off the ends. We also
* allow LF delimination as well as the specified CRLF.
*/
while (p)
/* We don't actually try to validate the URI according to RFC
* 2396, or even check for allowed characters - we just ignore
* comments and trim whitespace off the ends. We also
* allow LF delimination as well as the specified CRLF.
*/
while(p)
{
if (*p != '#')
{
while (isspace ((int) (*p)))
p++;
q = p;
while (*q && (*q != '\n') && (*q != '\r'))
q++;
if (q > p)
{
q--;
while (q > p && isspace ((int) (*q)))
q--;
retval = (char *) g_malloc (q - p + 2);
strncpy (retval, p, q - p + 1);
retval[q - p + 1] = '\0';
result = g_list_prepend (result, retval);
}
}
p = strchr (p, '\n');
if (p)
p++;
if(*p != '#')
{
while(isspace((int)(*p)))
p++;
q = p;
while(*q && (*q != '\n') && (*q != '\r'))
q++;
if(q > p)
{
q--;
while(q > p && isspace((int)(*q)))
q--;
retval = (char *)g_malloc(q - p + 2);
strncpy(retval, p, q - p + 1);
retval[q - p + 1] = '\0';
result = g_list_prepend(result, retval);
}
}
p = strchr(p, '\n');
if(p)
p++;
}
return g_list_reverse (result);
return g_list_reverse(result);
}
@ -123,412 +143,429 @@ gnome_uri_list_extract_uris (const gchar * uri_list)
* Note that unlike gnome_uri_list_extract_uris() function, this
* will discard any non-file uri from the result value.
*/
GList *
gnome_uri_list_extract_filenames (const gchar * uri_list)
GList *gnome_uri_list_extract_filenames(const gchar * uri_list)
{
GList *tmp_list, *node, *result;
GList *tmp_list, *node, *result;
g_return_val_if_fail (uri_list != NULL, NULL);
g_return_val_if_fail(uri_list != NULL, NULL);
result = gnome_uri_list_extract_uris (uri_list);
result = gnome_uri_list_extract_uris(uri_list);
tmp_list = result;
while (tmp_list)
tmp_list = result;
while(tmp_list)
{
gchar *s = (char *) tmp_list->data;
node = tmp_list;
tmp_list = tmp_list->next;
if (!strncmp (s, "file:", 5))
{
/* added by Jasper Huijsmans
remove leading multiple slashes */
if (!strncmp (s + 5, "///", 3))
node->data = g_strdup (s + 7);
else
node->data = g_strdup (s + 5);
}
else
{
node->data = g_strdup (s);
}
g_free (s);
gchar *s = (char *)tmp_list->data;
node = tmp_list;
tmp_list = tmp_list->next;
if(!strncmp(s, "file:", 5))
{
/* added by Jasper Huijsmans
remove leading multiple slashes */
if(!strncmp(s + 5, "///", 3))
node->data = g_strdup(s + 7);
else
node->data = g_strdup(s + 5);
}
else
{
node->data = g_strdup(s);
}
g_free(s);
}
return result;
return result;
}
/*****************************************************************************/
/* panel */
gboolean
panel_delete_cb (GtkWidget * window, GdkEvent * ev, gpointer data)
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Panel callbacks
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
gboolean panel_delete_cb(GtkWidget * window, GdkEvent * ev, gpointer data)
{
GtkWidget *dialog;
int response;
GtkWidget *dialog;
int response;
char *text = _("The panel recieved a request from the window "
"manager to quit. Usually this is by accident.\n"
"If you want to continue using the panel choose "
"\'No\'\n\n" "Do you want to quit the panel?");
hide_current_popup_menu ();
hide_current_popup_menu();
dialog = gtk_message_dialog_new (GTK_WINDOW (window),
GTK_DIALOG_MODAL |
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO,
_
("The panel recieved a request from the window manager\n"
"to quit. Usually this is by accident. If you want to\n"
"continue using the panel choose \'No\'\n\n"
"Do you want to quit the panel?"));
dialog = gtk_message_dialog_new(GTK_WINDOW(window),
GTK_DIALOG_MODAL |
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, text);
gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER);
response = gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
response = gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
if (response == GTK_RESPONSE_YES)
quit ();
if(response == GTK_RESPONSE_YES)
quit();
return TRUE;
return TRUE;
}
/*****************************************************************************/
/* central panel */
gboolean panel_destroy_cb(GtkWidget * window, GdkEvent * ev, gpointer data)
{
quit();
return TRUE;
}
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Central panel callbacks
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
gboolean
screen_button_pressed_cb (GtkButton * b, GdkEventButton * ev,
ScreenButton * sb)
screen_button_pressed_cb(GtkButton * b, GdkEventButton * ev, ScreenButton * sb)
{
hide_current_popup_menu ();
hide_current_popup_menu();
if (ev->button != 3)
return FALSE;
if(ev->button != 3)
return FALSE;
return TRUE;
return TRUE;
}
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
To be removed !
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
/* temporary functions for testing purposes */
void
switch_size_cb (void)
void switch_size_cb(void)
{
static int size = MEDIUM;
static int size = MEDIUM;
size = size == MEDIUM ? SMALL : size == SMALL ? LARGE : MEDIUM;
size = size == MEDIUM ? SMALL : size == SMALL ? LARGE : MEDIUM;
panel_set_size (size);
panel_set_popup_size (size);
panel_set_size(size);
panel_set_popup_size(size);
}
void
switch_style_cb (void)
void switch_style_cb(void)
{
static int style = NEW_STYLE;
static int style = NEW_STYLE;
style = style == NEW_STYLE ? OLD_STYLE : NEW_STYLE;
style = style == NEW_STYLE ? OLD_STYLE : NEW_STYLE;
panel_set_style (style);
panel_set_style(style);
}
/**/ void
mini_lock_cb (char *cmd)
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
End temporary functions
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
void mini_lock_cb(char *cmd)
{
hide_current_popup_menu ();
if(!cmd)
return;
exec_cmd (cmd);
hide_current_popup_menu();
exec_cmd(cmd);
}
void
mini_info_cb (void)
void mini_info_cb(void)
{
hide_current_popup_menu ();
hide_current_popup_menu();
switch_size_cb ();
switch_size_cb();
}
void
mini_palet_cb (void)
void mini_palet_cb(void)
{
hide_current_popup_menu ();
hide_current_popup_menu();
switch_style_cb ();
switch_style_cb();
}
void
mini_power_cb (GtkButton * b, GdkEventButton * ev, gpointer data)
void mini_power_cb(GtkButton * b, GdkEventButton * ev, char *cmd)
{
int w, h;
int w, h;
hide_current_popup_menu ();
hide_current_popup_menu();
gdk_window_get_size (ev->window, &w, &h);
gdk_window_get_size(ev->window, &w, &h);
/* we have to check if the pointer is still inside the button */
if (ev->x < 0 || ev->x > w || ev->y < 0 || ev->y > h)
/* we have to check if the pointer is still inside the button */
if(ev->x < 0 || ev->x > w || ev->y < 0 || ev->y > h)
{
gtk_button_released (b);
return;
gtk_button_released(b);
return;
}
if (ev->button == 1)
quit ();
else
restart ();
if(ev->button == 1)
{
exec_cmd(cmd);
quit();