Browse Source

make xml parsing replace entities

(Old svn revision: 3248)
upstream/xfce4-panel-4.10.1
Jasper Huijsmans 20 years ago
parent
commit
2cc9a219b3
  1. 66
      callbacks.c
  2. 20
      callbacks.h
  3. 96
      dialogs.c
  4. 20
      item.c
  5. 1
      item.h
  6. 23
      popup.c
  7. 1
      popup.h
  8. 1
      settings.c
  9. 2
      settings.h
  10. 10
      xfce.c

66
callbacks.c

@ -42,13 +42,19 @@ void hide_current_popup_menu(void);
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
void exec_cmd(const char *cmd)
void exec_cmd(const char *cmd, gboolean in_terminal)
{
GError *error = NULL; /* this must be NULL to prevent crash :( */
char execute[MAXSTRLEN + 1];
if(!cmd)
return;
if (in_terminal)
snprintf(execute, MAXSTRLEN, "xfterm -e /bin/sh -c %s", cmd);
else
snprintf(execute, MAXSTRLEN, "/bin/sh -c %s", cmd);
if(!g_spawn_command_line_async(cmd, &error))
{
char *msg;
@ -275,7 +281,7 @@ void mini_lock_cb(char *cmd)
hide_current_popup_menu();
exec_cmd(cmd);
exec_cmd(cmd, FALSE);
}
void mini_info_cb(void)
@ -309,7 +315,7 @@ void mini_power_cb(GtkButton * b, GdkEventButton * ev, char *cmd)
if(ev->button == 1)
{
exec_cmd(cmd);
exec_cmd(cmd, FALSE);
quit();
}
else
@ -461,14 +467,14 @@ gboolean delete_popup(GtkWidget * window, GdkEvent * ev, PanelPopup * pp)
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Item callbacks (panel and menu items)
Panel item callbacks
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
void
item_drop_cb(GtkWidget * widget, GdkDragContext * context,
panel_item_drop_cb(GtkWidget * widget, GdkDragContext * context,
gint x, gint y, GtkSelectionData * data,
guint info, guint time, char *command)
guint info, guint time, PanelItem *pi)
{
GList *fnames, *fnp;
guint count;
@ -481,7 +487,7 @@ item_drop_cb(GtkWidget * widget, GdkDragContext * context,
{
execute = (char *)g_new0(char, MAXSTRLEN);
strcpy(execute, command);
strcpy(execute, pi->command);
for(fnp = fnames; fnp; fnp = fnp->next, count--)
{
@ -489,7 +495,7 @@ item_drop_cb(GtkWidget * widget, GdkDragContext * context,
strncat(execute, (char *)(fnp->data), MAXSTRLEN - strlen(execute));
}
exec_cmd(execute);
exec_cmd(execute, pi->in_terminal);
g_free(execute);
hide_current_popup_menu();
@ -499,10 +505,10 @@ item_drop_cb(GtkWidget * widget, GdkDragContext * context,
time);
}
void item_click_cb(GtkButton * b, char *command)
void panel_item_click_cb(GtkButton * b, PanelItem *pi)
{
hide_current_popup_menu();
exec_cmd(command);
exec_cmd(pi->command, pi->in_terminal);
}
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
@ -569,3 +575,43 @@ gboolean menu_item_press(GtkButton * b, GdkEventButton * ev, MenuItem * mi)
return TRUE;
}
void
menu_item_drop_cb(GtkWidget * widget, GdkDragContext * context,
gint x, gint y, GtkSelectionData * data,
guint info, guint time, MenuItem *mi)
{
GList *fnames, *fnp;
guint count;
char *execute;
fnames = gnome_uri_list_extract_filenames((char *)data->data);
count = g_list_length(fnames);
if(count > 0)
{
execute = (char *)g_new0(char, MAXSTRLEN);
strcpy(execute, mi->command);
for(fnp = fnames; fnp; fnp = fnp->next, count--)
{
strcat(execute, " ");
strncat(execute, (char *)(fnp->data), MAXSTRLEN - strlen(execute));
}
exec_cmd(execute, mi->in_terminal);
g_free(execute);
hide_current_popup_menu();
}
gnome_uri_list_free_strings(fnames);
gtk_drag_finish(context, (count > 0), (context->action == GDK_ACTION_MOVE),
time);
}
void menu_item_click_cb(GtkButton * b, MenuItem *mi)
{
hide_current_popup_menu();
exec_cmd(mi->command, mi->in_terminal);
}

20
callbacks.h

@ -24,7 +24,7 @@
/*****************************************************************************/
void exec_cmd(const char *cmd);
void exec_cmd(const char *cmd, gboolean in_terminal);
GList *gnome_uri_list_extract_filenames(const gchar * uri_list);
void gnome_uri_list_free_strings(GList * list);
@ -60,18 +60,26 @@ gboolean delete_popup(GtkWidget * window, GdkEvent * ev, PanelPopup * pp);
/*****************************************************************************/
void panel_item_drop_cb(GtkWidget * widget, GdkDragContext * context,
gint x, gint y, GtkSelectionData * data,
guint info, guint time, PanelItem *pi);
void panel_item_click_cb(GtkButton * b, PanelItem *pi);
/*****************************************************************************/
void addtomenu_item_drop_cb(GtkWidget * widget, GdkDragContext * context,
gint x, gint y, GtkSelectionData * data,
guint info, guint time, PanelPopup * pp);
void addtomenu_item_click_cb(GtkButton * b, PanelPopup * pp);
void item_drop_cb(GtkWidget * widget, GdkDragContext * context,
gint x, gint y, GtkSelectionData * data,
guint info, guint time, char *command);
gboolean menu_item_press(GtkButton * b, GdkEventButton * ev, MenuItem * mi);
void item_click_cb(GtkButton * b, char *command);
void menu_item_drop_cb(GtkWidget * widget, GdkDragContext * context,
gint x, gint y, GtkSelectionData * data,
guint info, guint time, MenuItem *mi);
gboolean menu_item_press(GtkButton * b, GdkEventButton * ev, MenuItem * mi);
void menu_item_click_cb(GtkButton * b, MenuItem *mi);
#endif /* __XFCE_CALLBACKS_H__ */

96
dialogs.c

@ -145,6 +145,7 @@ struct _ItemFrame
GtkWidget *command_entry;
GtkWidget *command_browse_button;
GtkWidget *term_check_button;
GtkWidget *caption_entry;
GtkWidget *tooltip_entry;
@ -173,6 +174,7 @@ static ItemFrame *item_frame_new(gboolean is_menuitem)
iframe->frame = NULL;
iframe->command_entry = NULL;
iframe->command_browse_button = NULL;
iframe->term_check_button = NULL;
iframe->caption_entry = NULL;
iframe->tooltip_entry = NULL;
iframe->icon_option_menu = NULL;
@ -274,6 +276,19 @@ static void create_icon_option_menu(void)
/*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
/* icon preview */
static void new_extern_icon(const char *path)
{
g_return_if_fail(path && g_file_test(path, G_FILE_TEST_EXISTS));
g_free(iframe->icon_path);
iframe->icon_path = g_strdup(path);
/* this takes care of setting the preview */
iframe->icon_id = NUM_ICONS; /* something it definitely is not now */
gtk_option_menu_set_history(GTK_OPTION_MENU(iframe->icon_option_menu), 0);
icon_id_changed();
}
static void
icon_drop_cb(GtkWidget * widget, GdkDragContext * context,
gint x, gint y, GtkSelectionData * data,
@ -291,12 +306,7 @@ icon_drop_cb(GtkWidget * widget, GdkDragContext * context,
icon = (char *)fnames->data;
g_free(iframe->icon_path);
iframe->icon_path = g_strdup(icon);
/* this takes care of setting the preview */
iframe->icon_id = NUM_ICONS;
gtk_option_menu_set_history(GTK_OPTION_MENU(iframe->icon_option_menu), 0);
icon_id_changed();
new_extern_icon(icon);
}
gnome_uri_list_free_strings(fnames);
@ -338,8 +348,21 @@ void browse_cb(GtkWidget * b, GtkEntry * entry)
file = select_file_name(NULL, path, dialog);
if(file)
gtk_entry_set_text(entry, file);
if(file && strlen(file))
{
if(b == iframe->icon_browse_button)
{
if(g_file_test(file, G_FILE_TEST_EXISTS))
{
new_extern_icon(file);
gtk_entry_set_text(entry, file);
}
}
else
{
gtk_entry_set_text(entry, file);
}
}
g_free(file);
g_free(path);
@ -386,6 +409,19 @@ static void create_item_frame(void)
g_signal_connect(iframe->command_browse_button, "clicked", G_CALLBACK(browse_cb),
iframe->command_entry);
/* terminal */
hbox = gtk_hbox_new(FALSE, 4);
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
label = gtk_label_new("");
gtk_size_group_add_widget(sg, label);
gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
iframe->term_check_button =
gtk_check_button_new_with_mnemonic(_("Run in _terminal"));
gtk_box_pack_start(GTK_BOX(hbox), iframe->term_check_button, FALSE, FALSE, 0);
gtk_widget_show(iframe->term_check_button);
/* icon */
hbox = gtk_hbox_new(FALSE, 4);
gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
@ -864,6 +900,9 @@ static GtkWidget *create_panel_control_dialog(PanelItem * pi, PanelModule * pm)
gtk_entry_set_text(GTK_ENTRY(iframe->icon_entry), pi->path);
if(pi && pi->command)
gtk_entry_set_text(GTK_ENTRY(iframe->command_entry), pi->command);
if(pi && pi->in_terminal)
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(iframe->term_check_button),
TRUE);
if(pi && pi->tooltip)
gtk_entry_set_text(GTK_ENTRY(iframe->tooltip_entry), pi->tooltip);
@ -899,6 +938,17 @@ static GtkWidget *create_panel_control_dialog(PanelItem * pi, PanelModule * pm)
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
static void reposition_popup(PanelPopup * pp)
{
if(pp->detached)
return;
gtk_toggle_button_toggled(GTK_TOGGLE_BUTTON(pp->button));
toggle_popup(pp->button, pp);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pp->button), TRUE);
}
void add_menu_item_dialog(PanelPopup * pp)
{
int response;
@ -936,6 +986,9 @@ void add_menu_item_dialog(PanelPopup * pp)
mi->command =
gtk_editable_get_chars(GTK_EDITABLE(iframe->command_entry), 0, -1);
mi->in_terminal =
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
(iframe->term_check_button));
mi->caption =
gtk_editable_get_chars(GTK_EDITABLE(iframe->caption_entry), 0, -1);
mi->tooltip =
@ -959,10 +1012,7 @@ void add_menu_item_dialog(PanelPopup * pp)
menu_item_set_popup_size(mi, settings.size);
menu_item_set_style(mi, settings.style);
gtk_toggle_button_toggled(GTK_TOGGLE_BUTTON(pp->button));
toggle_popup(pp->button, pp);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pp->button), TRUE);
reposition_popup(pp);
}
/* clean up */
@ -1012,6 +1062,9 @@ void edit_menu_item_dialog(MenuItem * mi)
gtk_entry_set_text(GTK_ENTRY(iframe->icon_entry), mi->icon_path);
if(mi->command)
gtk_entry_set_text(GTK_ENTRY(iframe->command_entry), mi->command);
if(mi->in_terminal)
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(iframe->term_check_button),
TRUE);
if(mi->caption)
gtk_entry_set_text(GTK_ENTRY(iframe->caption_entry), mi->caption);
if(mi->tooltip)
@ -1029,12 +1082,16 @@ void edit_menu_item_dialog(MenuItem * mi)
PanelPopup *pp = mi->parent;
gtk_container_remove(GTK_CONTAINER(mi->parent->vbox), mi->button);
pp->items = g_list_remove(pp->items, mi);
menu_item_free(mi);
mi = menu_item_new(pp);
mi->command =
gtk_editable_get_chars(GTK_EDITABLE(iframe->command_entry), 0, -1);
mi->in_terminal =
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
(iframe->term_check_button));
mi->caption =
gtk_editable_get_chars(GTK_EDITABLE(iframe->caption_entry), 0, -1);
mi->tooltip =
@ -1047,7 +1104,7 @@ void edit_menu_item_dialog(MenuItem * mi)
mi->pos =
gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON
(iframe->spinbutton)) - 1;
pp->items = g_list_insert(pp->items, mi, mi->pos);
create_menu_item(mi);
gtk_box_pack_start(GTK_BOX(pp->vbox), mi->button, TRUE, TRUE, 0);
@ -1057,10 +1114,7 @@ void edit_menu_item_dialog(MenuItem * mi)
menu_item_set_popup_size(mi, settings.size);
menu_item_set_style(mi, settings.style);
gtk_toggle_button_toggled(GTK_TOGGLE_BUTTON(pp->button));
toggle_popup(pp->button, pp);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pp->button), TRUE);
reposition_popup(pp);
}
else if(response == RESPONSE_REMOVE)
{
@ -1071,10 +1125,7 @@ void edit_menu_item_dialog(MenuItem * mi)
gtk_container_remove(GTK_CONTAINER(mi->parent->vbox), mi->button);
menu_item_free(mi);
gtk_toggle_button_toggled(GTK_TOGGLE_BUTTON(pp->button));
toggle_popup(pp->button, pp);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pp->button), TRUE);
reposition_popup(pp);
}
/* clean up */
@ -1131,6 +1182,9 @@ void edit_panel_control_dialog(PanelGroup * pg)
pi = pg->item = panel_item_new(pg);
pi->command =
gtk_editable_get_chars(GTK_EDITABLE(iframe->command_entry), 0, -1);
pi->in_terminal =
gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON
(iframe->term_check_button));
pi->tooltip =
gtk_editable_get_chars(GTK_EDITABLE(iframe->tooltip_entry), 0, -1);
pi->id = iframe->icon_id;

20
item.c

@ -33,6 +33,7 @@ PanelItem *panel_item_new(PanelGroup * pg)
pi->parent = pg;
pi->command = NULL;
pi->in_terminal = FALSE;
pi->tooltip = NULL;
pi->id = UNKNOWN_ICON;
@ -80,7 +81,7 @@ void create_panel_item(PanelItem * pi)
if(pi->command && strlen(pi->command))
{
g_signal_connect(pi->button, "clicked",
G_CALLBACK(item_click_cb), pi->command);
G_CALLBACK(panel_item_click_cb), pi);
if(pi->tooltip && strlen(pi->tooltip))
add_tooltip(pi->button, pi->tooltip);
@ -90,7 +91,7 @@ void create_panel_item(PanelItem * pi)
dnd_set_drag_dest(pi->button);
g_signal_connect(pi->button, "drag_data_received",
G_CALLBACK(item_drop_cb), pi->command);
G_CALLBACK(panel_item_drop_cb), pi);
}
else
add_tooltip(pi->button, _("Click Mouse 3 to change item"));
@ -165,10 +166,20 @@ void panel_item_parse_xml(xmlNodePtr node, PanelItem * pi)
{
if(xmlStrEqual(child->name, (const xmlChar *)"Command"))
{
int n = -1;
value = DATA(child);
if(value)
pi->command = (char *)value;
value = xmlGetProp(child, "term");
if (value)
n = atoi(value);
if (n == 1)
pi->in_terminal = TRUE;
}
else if(xmlStrEqual(child->name, (const xmlChar *)"Tooltip"))
{
@ -210,7 +221,10 @@ void panel_item_write_xml(xmlNodePtr root, PanelItem *pi)
node = xmlNewTextChild(root, NULL, "Item", NULL);
xmlNewTextChild(node, NULL, "Command", pi->command);
child = xmlNewChild(node, NULL, "Command", pi->command);
snprintf(value, 2, "%d", pi->in_terminal);
xmlSetProp(child, "term", value);
if (pi->tooltip)
xmlNewTextChild(node, NULL, "Tooltip", pi->tooltip);

1
item.h

@ -27,6 +27,7 @@ struct _PanelItem
PanelGroup *parent;
char *command;
gboolean in_terminal;
char *tooltip;
int id;

23
popup.c

@ -246,6 +246,7 @@ MenuItem *menu_item_new(PanelPopup * pp)
mi->pos = 0;
mi->command = NULL;
mi->in_terminal = FALSE;
mi->caption = NULL;
mi->tooltip = NULL;
@ -334,8 +335,8 @@ void create_menu_item(MenuItem * mi)
if(mi->command && strlen(mi->command))
{
g_signal_connect(mi->button, "clicked", G_CALLBACK(item_click_cb),
mi->command);
g_signal_connect(mi->button, "clicked", G_CALLBACK(menu_item_click_cb),
mi);
if(mi->tooltip && strlen(mi->tooltip))
add_tooltip(mi->button, mi->tooltip);
@ -345,7 +346,7 @@ void create_menu_item(MenuItem * mi)
dnd_set_drag_dest(mi->button);
g_signal_connect(mi->button, "drag_data_received",
G_CALLBACK(item_drop_cb), mi->command);
G_CALLBACK(menu_item_drop_cb), mi);
}
else
add_tooltip(mi->button, _("Click Mouse 3 to change item"));
@ -414,10 +415,20 @@ void menu_item_parse_xml(xmlNodePtr node, MenuItem * mi)
}
else if(xmlStrEqual(child->name, (const xmlChar *)"Command"))
{
int n = -1;
value = DATA(child);
if(value)
mi->command = (char *)value;
value = xmlGetProp(child, "term");
if (value)
n = atoi(value);
if (n == 1)
mi->in_terminal = TRUE;
}
else if(xmlStrEqual(child->name, (const xmlChar *)"Tooltip"))
{
@ -460,7 +471,11 @@ void menu_item_write_xml(xmlNodePtr root, MenuItem *mi)
node = xmlNewTextChild(root, NULL, "Item", NULL);
xmlNewTextChild(node, NULL, "Caption", mi->caption);
xmlNewTextChild(node, NULL, "Command", mi->command);
child = xmlNewChild(node, NULL, "Command", mi->command);
snprintf(value, 2, "%d", mi->in_terminal);
xmlSetProp(child, "term", value);
if (mi->tooltip)
xmlNewTextChild(node, NULL, "Tooltip", mi->tooltip);

1
popup.h

@ -49,6 +49,7 @@ struct _PanelPopup
struct _MenuItem
{
char *command;
gboolean in_terminal;
char *caption;
char *tooltip;

1
settings.c

@ -21,7 +21,6 @@
#include <stdlib.h>
#include <sys/stat.h>
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
#include <libxml/tree.h>

2
settings.h

@ -28,6 +28,6 @@ void get_panel_config(void);
extern xmlDocPtr xmlconfig;
#define DATA(node) xmlNodeListGetString(xmlconfig, node->children, 0)
#define DATA(node) xmlNodeListGetString(xmlconfig, node->children, 1)
#endif /* __XFCE_XMLCONFIG_H__ */

10
xfce.c

@ -23,6 +23,8 @@
* and panel function.
*/
#include <signal.h>
#include "xfce.h"
#include "central.h"
@ -82,6 +84,11 @@ void add_tooltip(GtkWidget * widget, char *tip)
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*/
void sighandler(int sig)
{
quit();
}
void quit(void)
{
gtk_main_quit();
@ -101,6 +108,9 @@ void xfce_init(void)
check_net_support();
create_builtin_pixbufs();
signal(SIGTERM, &sighandler);
signal(SIGINT, &sighandler);
}
void xfce_run(void)

Loading…
Cancel
Save