Free structures only if they were ever allocated
2000-08-07 Bradford Hovinen <hovinen@helixcode.com> * screensaver-prefs-dialog.c (screensaver_prefs_dialog_destroy): Free structures only if they were ever allocated * selection-dialog.c (get_known_savers): Implement. Read the screensaver directory for a list of valid screensavers (place_screensaver_list): Use known_savers rather than XML data * preferences.c (screensaver_get_label): Implement. Copy from get_label in resources.c * prefs-widget.c (deselect_saver_cb): Toggle only if event was a mouse button press, not a keyboard press (prefs_widget_init): Change vertical size of preview window to 200 (prefs_widget_init): Use a table for the buttons below the screensaver list (prefs_widget_init): Change label of edit button to Settings... (prefs_widget_init): Don't have description and preview frames expand, have selection frame expand * Makefile.am (screensaver_properties_capplet_LDADD): Don't link against glade (INCLUDES): Don't set glade compilation flags * screensaver-prefs-dialog.c (get_select_widget): Show menu item (populate_table): Don't skip hgroups that lack ids (place_number): (place_boolean): Attach items with GTK_FILL (get_check_button): (get_select_widget): Set object data to point back to dialog (populate_table): Pass dialog, remove extraneous arguments (get_check_button): Connect toggled signal from here (get_select_widget): Set data and connect activate signals from here (place_number): Set default from default attribute (get_spinbutton): Set step_increment, page_increment, and page_size on adjustment (get_spinbutton): (place_number): Set default to average of high and low if not supplied (get_argument_data): Add i18n support (read_boolean): (read_number): (read_select): (write_boolean): (write_number): (write_select): Check if id is NULL before trying to look up a node (screensaver_prefs_dialog_new): Make sure CLI arguments and XML data were read successfully before trying to build the widget (get_argument_data): Return pointer to document rather than root node (screensaver_prefs_dialog_new): Set argument_data from argument_doc (screensaver_prefs_dialog_class_init): Set parent_class (screensaver_prefs_dialog_destroy): Implement; free all structures (free_set_cb): Implement (write_number): Don't assume correct format on the output string; just replace the '%' with the appropriate argument (write_command_line): Free arg iff generated from number 2000-08-06 Bradford Hovinen <hovinen@helixcode.com> * screensaver-prefs-dialog.c (get_screensaver_widget): Accept ScreensaverPrefsDialog as option (get_argument_data): Assume one file per screensaver (get_spinbutton): (get_check_button): (get_select_widget): (place_number): (place_boolean): (place_hgroup): (place_select): (populate_table): Implement (get_screensaver_widget): Rewrite to build screensaver config dialogs manually from the XML data (activate_option_cb): (toggle_check_cb): Pass dialog to set_widgets_sensitive (set_widgets_sensitive): Rewrite to use dialog->widget_db (write_boolean): (write_number): (write_select): Use widget_db (write_select): (write_command_line): Don't check no-output (write_command_line): Pass widget_db (read_boolean): (read_number): (read_select): Use widget_db (place_screensaver_properties): Pass dialog->widget_db to above functions (arg_mapping_exists): Use XML file rather than Glade definition (screensaver_prefs_dialog_new): Initialize settings_widget with the widget to be placed in the settings frame (place_screensaver_properties): Take xml node; process hgroups recursively (write_command_line): Process hgroups recursively (read_boolean): (read_number): (read_select): Check if set and set->value_widget are set before proceeding * screensaver-prefs-dialog.h (struct _PrefsDialogConfigOption): New structure (struct _ScreensaverPrefsDialog ): New member widget_db -- key-value database of PrefsDialogConfigOptions indexed by id attribute from XML
This commit is contained in:
parent
8c5ee35a90
commit
148d8186a5
14 changed files with 1178 additions and 1323 deletions
|
@ -26,6 +26,9 @@
|
|||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <dirent.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include <gnome.h>
|
||||
|
@ -39,10 +42,16 @@ enum {
|
|||
LAST_SIGNAL
|
||||
};
|
||||
|
||||
static xmlDocPtr screensaver_doc;
|
||||
|
||||
static gint selection_dialog_signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
typedef struct _saver_entry_t
|
||||
{
|
||||
gchar *name;
|
||||
gchar *label;
|
||||
} saver_entry_t;
|
||||
|
||||
GList *known_savers;
|
||||
|
||||
static void selection_dialog_init (SelectionDialog *dialog);
|
||||
static void selection_dialog_class_init (SelectionDialogClass *dialog);
|
||||
|
||||
|
@ -55,6 +64,8 @@ static void selection_dialog_ok_cb (GtkWidget *widget,
|
|||
static void selection_dialog_cancel_cb (GtkWidget *widget,
|
||||
SelectionDialog *dialog);
|
||||
|
||||
static GList *get_known_savers (void);
|
||||
|
||||
guint
|
||||
selection_dialog_get_type (void)
|
||||
{
|
||||
|
@ -94,7 +105,8 @@ selection_dialog_init (SelectionDialog *dialog)
|
|||
|
||||
vbox = GTK_BOX (GNOME_DIALOG (dialog)->vbox);
|
||||
|
||||
label = gtk_label_new (_("Select the screensaver to run from the list below:"));
|
||||
label = gtk_label_new (_("Select the screensaver to run from " \
|
||||
"the list below:"));
|
||||
gtk_box_pack_start (vbox, label, FALSE, TRUE, 0);
|
||||
|
||||
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
|
||||
|
@ -141,6 +153,8 @@ selection_dialog_class_init (SelectionDialogClass *class)
|
|||
selection_dialog_signals,
|
||||
LAST_SIGNAL);
|
||||
|
||||
known_savers = get_known_savers ();
|
||||
|
||||
class->ok_clicked = NULL;
|
||||
}
|
||||
|
||||
|
@ -150,12 +164,7 @@ selection_dialog_new (PrefsWidget *prefs_widget)
|
|||
GtkWidget *widget;
|
||||
|
||||
widget = gtk_type_new (selection_dialog_get_type ());
|
||||
|
||||
if (!screensaver_doc)
|
||||
screensaver_doc = xmlParseFile (SSPROP_DATADIR "/hacks.xml");
|
||||
|
||||
place_screensaver_list (SELECTION_DIALOG (widget));
|
||||
|
||||
gtk_widget_show (widget);
|
||||
|
||||
return widget;
|
||||
|
@ -165,34 +174,25 @@ static void
|
|||
place_screensaver_list (SelectionDialog *dialog)
|
||||
{
|
||||
GtkWidget *item;
|
||||
GList *item_list_head = NULL, *item_list_tail = NULL;
|
||||
xmlNodePtr node;
|
||||
GList *item_list_head = NULL, *item_list_tail = NULL, *node;
|
||||
gchar *label;
|
||||
saver_entry_t *entry;
|
||||
|
||||
node = xmlDocGetRootElement (screensaver_doc);
|
||||
for (node = known_savers; node; node = node->next) {
|
||||
entry = (saver_entry_t *) node->data;
|
||||
item = gtk_list_item_new_with_label (entry->label);
|
||||
gtk_widget_show (item);
|
||||
gtk_object_set_data (GTK_OBJECT (item), "name", entry->name);
|
||||
gtk_signal_connect (GTK_OBJECT (item), "select",
|
||||
GTK_SIGNAL_FUNC (select_program_cb),
|
||||
dialog);
|
||||
|
||||
if (node) {
|
||||
node = node->childs;
|
||||
|
||||
while (node) {
|
||||
label = xmlGetProp (node, "name");
|
||||
label[0] = toupper (label[0]);
|
||||
item = gtk_list_item_new_with_label (label);
|
||||
gtk_widget_show (item);
|
||||
gtk_object_set_data (GTK_OBJECT (item), "node", node);
|
||||
gtk_signal_connect (GTK_OBJECT (item), "select",
|
||||
GTK_SIGNAL_FUNC
|
||||
(select_program_cb),
|
||||
dialog);
|
||||
|
||||
item_list_tail = g_list_append (item_list_tail, item);
|
||||
if (!item_list_head) item_list_head = item_list_tail;
|
||||
item_list_tail = g_list_last (item_list_tail);
|
||||
node = node->next;
|
||||
}
|
||||
item_list_tail = g_list_append (item_list_tail, item);
|
||||
if (!item_list_head) item_list_head = item_list_tail;
|
||||
item_list_tail = g_list_last (item_list_tail);
|
||||
}
|
||||
|
||||
item = gtk_list_item_new_with_label ("Custom");
|
||||
item = gtk_list_item_new_with_label (_("Custom"));
|
||||
gtk_widget_show (item);
|
||||
gtk_signal_connect (GTK_OBJECT (item), "select",
|
||||
GTK_SIGNAL_FUNC (select_program_cb), dialog);
|
||||
|
@ -208,8 +208,8 @@ static void
|
|||
select_program_cb (GtkListItem *item, SelectionDialog *dialog)
|
||||
{
|
||||
dialog->selected_program_item = item;
|
||||
dialog->selected_program_node =
|
||||
gtk_object_get_data (GTK_OBJECT (item), "node");
|
||||
dialog->selected_name =
|
||||
gtk_object_get_data (GTK_OBJECT (item), "name");
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -220,11 +220,11 @@ selection_dialog_ok_cb (GtkWidget *widget, SelectionDialog *dialog)
|
|||
saver = screensaver_new ();
|
||||
saver->label = g_strdup (_("New screensaver"));
|
||||
|
||||
if (dialog->selected_program_node) {
|
||||
if (dialog->selected_name) {
|
||||
saver->name =
|
||||
g_strdup (xmlGetProp (dialog->selected_program_node,
|
||||
"name"));
|
||||
saver->command_line = g_strconcat (saver->name, " -root", NULL);
|
||||
g_strdup (dialog->selected_name);
|
||||
saver->command_line =
|
||||
g_strconcat (saver->name, " -root", NULL);
|
||||
}
|
||||
|
||||
gtk_signal_emit (GTK_OBJECT (dialog),
|
||||
|
@ -237,3 +237,74 @@ selection_dialog_cancel_cb (GtkWidget *widget, SelectionDialog *dialog)
|
|||
{
|
||||
gnome_dialog_close (GNOME_DIALOG (dialog));
|
||||
}
|
||||
|
||||
static gint
|
||||
node_compare (gconstpointer a, gconstpointer b)
|
||||
{
|
||||
return strcmp (((saver_entry_t *) a)->label,
|
||||
((saver_entry_t *) b)->label);
|
||||
}
|
||||
|
||||
static GList *
|
||||
get_known_savers (void)
|
||||
{
|
||||
GList *list_head, *list_tail;
|
||||
DIR *parent_dir;
|
||||
struct dirent *child_dir;
|
||||
struct stat filedata;
|
||||
gchar *fullpath;
|
||||
saver_entry_t *entry;
|
||||
char *tmp, *name;
|
||||
|
||||
if (known_savers) return known_savers;
|
||||
|
||||
parent_dir = opendir (SSPROP_DATADIR "/screensavers");
|
||||
if (parent_dir == NULL)
|
||||
return NULL;
|
||||
|
||||
list_head = list_tail = NULL;
|
||||
|
||||
while ((child_dir = readdir (parent_dir)) != NULL) {
|
||||
if (child_dir->d_name[0] != '.') {
|
||||
fullpath = g_concat_dir_and_file
|
||||
(SSPROP_DATADIR "/screensavers",
|
||||
child_dir->d_name);
|
||||
|
||||
if (stat (fullpath, &filedata) != -1) {
|
||||
if (!S_ISDIR (filedata.st_mode)) {
|
||||
name = g_strdup (child_dir->d_name);
|
||||
tmp = strstr (name, ".xml");
|
||||
if (tmp) {
|
||||
*tmp = '\0';
|
||||
|
||||
entry = g_new0
|
||||
(saver_entry_t, 1);
|
||||
entry->name = name;
|
||||
entry->label =
|
||||
screensaver_get_label
|
||||
(name);
|
||||
} else {
|
||||
g_free (name);
|
||||
}
|
||||
} else {
|
||||
entry = NULL;
|
||||
}
|
||||
|
||||
if (entry) {
|
||||
list_tail = g_list_append
|
||||
(list_tail, entry);
|
||||
if (!list_head)
|
||||
list_head = list_tail;
|
||||
else
|
||||
list_tail = list_tail->next;
|
||||
}
|
||||
}
|
||||
|
||||
g_free (fullpath);
|
||||
}
|
||||
}
|
||||
|
||||
closedir (parent_dir);
|
||||
|
||||
list_head = g_list_sort (list_head, node_compare);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue