diff options
author | Ramiro Estrugo <ramiro@src.gnome.org> | 2001-01-24 03:24:38 +0000 |
---|---|---|
committer | Ramiro Estrugo <ramiro@src.gnome.org> | 2001-01-24 03:24:38 +0000 |
commit | c773f94ce998d9b9e651680f08c51cf60b41ceeb (patch) | |
tree | d76bcd37b87057ef3b501f96672b4f6dda7a42d8 | |
parent | 4d41b0bb00925db7549c8398fce559ba0e769931 (diff) | |
download | nautilus-c773f94ce998d9b9e651680f08c51cf60b41ceeb.tar.gz |
A very simple applet to debug show desktop and smooth graphics
* applets/Makefile.am:
* applets/launcher/Makefile.am:
* applets/launcher/nautilus-launcher-applet.c: (button_toggled),
(show_desktop_changed_callback), (delete_event), (main):
* applets/launcher/nautilus-launcher-applet.gnorba:
* applets/preferences-applet/Makefile.am:
* applets/preferences-applet/nautilus-preferences-applet.c:
(accept_all_cookies), (preference_toggle_destroy_callback),
(boolean_preference_changed_callback), (button_toggled),
(boolean_toggle_button_new), (main):
* applets/preferences-applet/nautilus-preferences-applet.gnorba:
* configure.in:
A very simple applet to debug show desktop and smooth graphics
preferences.
-rw-r--r-- | ChangeLog | 17 | ||||
-rw-r--r-- | applets/Makefile.am | 1 | ||||
-rw-r--r-- | applets/launcher/Makefile.am | 2 | ||||
-rw-r--r-- | applets/launcher/nautilus-launcher-applet.c | 296 | ||||
-rw-r--r-- | applets/launcher/nautilus-launcher-applet.gnorba | 6 | ||||
-rw-r--r-- | applets/preferences-applet/Makefile.am | 31 | ||||
-rw-r--r-- | applets/preferences-applet/nautilus-preferences-applet.c | 181 | ||||
-rw-r--r-- | applets/preferences-applet/nautilus-preferences-applet.gnorba | 5 | ||||
-rw-r--r-- | configure.in | 1 |
9 files changed, 289 insertions, 251 deletions
@@ -1,3 +1,20 @@ +2001-01-23 Ramiro Estrugo <ramiro@eazel.com> + + * applets/Makefile.am: + * applets/launcher/Makefile.am: + * applets/launcher/nautilus-launcher-applet.c: (button_toggled), + (show_desktop_changed_callback), (delete_event), (main): + * applets/launcher/nautilus-launcher-applet.gnorba: + * applets/preferences-applet/Makefile.am: + * applets/preferences-applet/nautilus-preferences-applet.c: + (accept_all_cookies), (preference_toggle_destroy_callback), + (boolean_preference_changed_callback), (button_toggled), + (boolean_toggle_button_new), (main): + * applets/preferences-applet/nautilus-preferences-applet.gnorba: + * configure.in: + A very simple applet to debug show desktop and smooth graphics + preferences. + 2001-01-23 Andy Hertzfeld <andy@eazel.com> * libnautilus-extensions/nautilus-directory-background.c: diff --git a/applets/Makefile.am b/applets/Makefile.am index 52a1083e2..f17e756e5 100644 --- a/applets/Makefile.am +++ b/applets/Makefile.am @@ -2,4 +2,5 @@ include $(top_srcdir)/Makefile.shared SUBDIRS = \ launcher \ + preferences-applet \ $(NULL) diff --git a/applets/launcher/Makefile.am b/applets/launcher/Makefile.am index c6af2386a..56aacf2be 100644 --- a/applets/launcher/Makefile.am +++ b/applets/launcher/Makefile.am @@ -27,5 +27,5 @@ gnorbadir = $(sysconfdir)/CORBA/servers gnorba_DATA = nautilus-launcher-applet.gnorba EXTRA_DIST =\ - nautilus-launcher-applet.gnorba \ + $(gnorba_DATA) \ $(NULL) diff --git a/applets/launcher/nautilus-launcher-applet.c b/applets/launcher/nautilus-launcher-applet.c index f6f6367f2..44e523911 100644 --- a/applets/launcher/nautilus-launcher-applet.c +++ b/applets/launcher/nautilus-launcher-applet.c @@ -17,289 +17,91 @@ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - Authors: Mathieu Lacage <mathieu@eazel.com> - Ramiro Estrugo <ramiro@eazel.com> + Authors: Ramiro Estrugo <ramiro@eazel.com> */ -/* Everything beyond this point is pure evil. */ +/* + * A very simple applet to toggle some Nautilus preferences. + */ #include <config.h> #include <applet-widget.h> #include <libnautilus-extensions/nautilus-image.h> -#include <libnautilus-extensions/nautilus-graphic-effects.h> -#include <libgnome/gnome-exec.h> -#include <gtk/gtkobject.h> -#include <gtk/gtkeventbox.h> -#include <gdk/gdkx.h> -#include <gdk/gdkprivate.h> -#include <X11/Xatom.h> -#include <gdk/gdkx.h> - -/* - * The purpose of this applet is to launch Nautilus. The applet tries very hard to - * give good feedback to the user by changing the appearance of the launch icon. - * The launch icon cursor and the desktop cursor are also updated in concert when - * a new Nautilus window is launching. - */ - -#define ICON_NAME "nautilus-launch-icon.png" -#define VERTICAL_OFFSET 2 -#define HORIZONTAL_OFFSET 2 - -static GdkPixbuf *icon_pixbuf = NULL; -static GdkPixbuf *icon_prelight_pixbuf = NULL; -static long last_window_realize_time = 0; -static GtkWidget *icon_image = NULL; -static GtkWidget *icon_event_box = NULL; - -static void set_is_launching (gboolean state); -static gboolean get_is_launching (void); +#include <libnautilus-extensions/nautilus-global-preferences.h> +#include <gtk.h> static void -create_pixbufs () +button_toggled (GtkWidget *button, + gpointer callback_data) { - if (icon_pixbuf == NULL) { - char *path; - - path = g_strdup_printf ("%s/pixmaps/%s", DATADIR, ICON_NAME); - - icon_pixbuf = gdk_pixbuf_new_from_file (path); - g_free (path); - - g_assert (icon_pixbuf != NULL); - - icon_prelight_pixbuf = nautilus_create_spotlight_pixbuf (icon_pixbuf); - } + nautilus_preferences_set_boolean (NAUTILUS_PREFERENCES_SHOW_DESKTOP, + GTK_TOGGLE_BUTTON (button)->active); } static void -applet_change_pixel_size(GtkWidget *widget, int size, gpointer data) +show_desktop_changed_callback (gpointer callback_data) { - /* need to change the size of the button here */ -} - -static gint -image_enter_event (GtkWidget *event_box, - GdkEventCrossing *event, - gpointer client_data) -{ - g_return_val_if_fail (GTK_IS_EVENT_BOX (event_box), TRUE); - g_return_val_if_fail (NAUTILUS_IS_IMAGE (client_data), TRUE); - - if (!get_is_launching ()) { - nautilus_image_set_pixbuf (NAUTILUS_IMAGE (client_data), icon_prelight_pixbuf); - } + gboolean show_desktop; - return TRUE; -} - -static gint -image_leave_event (GtkWidget *event_box, - GdkEventCrossing *event, - gpointer client_data) -{ - g_return_val_if_fail (GTK_IS_EVENT_BOX (event_box), TRUE); - g_return_val_if_fail (NAUTILUS_IS_IMAGE (client_data), TRUE); + show_desktop = nautilus_preferences_get_boolean (NAUTILUS_PREFERENCES_SHOW_DESKTOP); - nautilus_image_set_pixbuf (NAUTILUS_IMAGE (client_data), icon_pixbuf); - gtk_object_set_data (GTK_OBJECT (event_box), "was-pressed", FALSE); - - return TRUE; -} - -static GdkWindow * -get_root_window (void) -{ - return GDK_ROOT_PARENT (); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (callback_data), + nautilus_preferences_get_boolean (NAUTILUS_PREFERENCES_SHOW_DESKTOP)); } static void -window_set_cursor_for_state (GdkWindow *window, gboolean busy) +delete_event (GtkWidget *widget, GdkEvent *event, gpointer callback_data) { - GdkCursor *cursor; - - g_return_if_fail (window != NULL); - - cursor = gdk_cursor_new (busy ? GDK_WATCH : GDK_LEFT_PTR); - gdk_window_set_cursor (window, cursor); - gdk_cursor_destroy (cursor); -} - -static gboolean is_launching = FALSE; - -static void -set_is_launching (gboolean state) -{ - if (is_launching == state) { - return; - } - - is_launching = state; - - window_set_cursor_for_state (get_root_window (), is_launching); - window_set_cursor_for_state (GTK_WIDGET (icon_event_box)->window, is_launching); - - nautilus_image_set_pixbuf_opacity (NAUTILUS_IMAGE (icon_image), is_launching ? 128 : 255); -} - -static gboolean -get_is_launching (void) -{ - return is_launching; -} - -static gint -image_button_press_event (GtkWidget *event_box, - GdkEventButton *event, - gpointer client_data) -{ - GtkWidget *icon = GTK_WIDGET (client_data); - - g_return_val_if_fail (GTK_IS_EVENT_BOX (event_box), TRUE); - g_return_val_if_fail (NAUTILUS_IS_IMAGE (icon), TRUE); - - if (!get_is_launching ()) { - gtk_object_set_data (GTK_OBJECT (event_box), "was-pressed", GINT_TO_POINTER (TRUE)); - } - - return TRUE; -} - -static gint -image_button_release_event (GtkWidget *event_box, - GdkEventButton *event, - gpointer client_data) -{ - GtkWidget *icon = GTK_WIDGET (client_data); - - g_return_val_if_fail (GTK_IS_EVENT_BOX (event_box), TRUE); - g_return_val_if_fail (NAUTILUS_IS_IMAGE (icon), TRUE); - - if (GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (event_box), "was-pressed"))) { - gtk_object_set_data (GTK_OBJECT (event_box), "was-pressed", FALSE); - - if (!get_is_launching ()) - { - char *path; - gint pid; - - path = g_strdup_printf ("%s/%s", BINDIR, "run-nautilus"); - - pid = gnome_execute_async (NULL, 1, &path); - - if (pid != 0) { - set_is_launching (TRUE); - } - - g_free (path); - } - } - - return TRUE; -} - -static GdkFilterReturn -event_filter (GdkXEvent *gdk_xevent, - GdkEvent *event, - gpointer client_data) -{ - XEvent *xevent = (XEvent *) gdk_xevent; - - if (xevent->type == PropertyNotify) { - GdkAtom actual_property_type; - gint actual_format; - gint actual_length; - guchar *data; - - if (gdk_property_get (get_root_window (), - gdk_atom_intern ("_NAUTILUS_LAST_WINDOW_REALIZE_TIME", FALSE), - 0, - 0, - 1L, - FALSE, - &actual_property_type, - &actual_format, - &actual_length, - &data)) { - - if (actual_format == 32 && actual_length == 4) { - long realize_time; - - realize_time = *((long *) data); - - if (last_window_realize_time != realize_time) { - last_window_realize_time = realize_time; - set_is_launching (FALSE); - } - } - - g_free (data); - - } - } - - return GDK_FILTER_CONTINUE; -} - -static void -root_listen_for_property_changes (void) -{ - XWindowAttributes attribs = { 0 }; - - gdk_window_add_filter (get_root_window (), event_filter, NULL); - - XGetWindowAttributes (GDK_DISPLAY (), GDK_ROOT_WINDOW (), &attribs); - - XSelectInput (GDK_DISPLAY (), GDK_ROOT_WINDOW (), attribs.your_event_mask | PropertyChangeMask); - - gdk_flush (); + gtk_main_quit (); } int main (int argc, char **argv) { GtkWidget *applet; - int size; + GtkWidget *button; bindtextdomain (PACKAGE, GNOMELOCALEDIR); textdomain (PACKAGE); - applet_widget_init ("nautilus_launcher_applet", VERSION, argc, - argv, NULL, 0, NULL); - - applet = applet_widget_new ("nautilus_launcher_applet"); - if (applet == NULL) - g_error (_("Can't create nautilus-launcher-applet!")); - - root_listen_for_property_changes (); - - create_pixbufs (); - - icon_event_box = gtk_event_box_new (); - gtk_object_set_data (GTK_OBJECT (icon_event_box), "was-pressed", FALSE); + applet_widget_init ("nautilus_preferences_applet", + VERSION, + argc, + argv, + NULL, + 0, + NULL); + + applet = applet_widget_new ("nautilus_preferences_applet"); + + if (applet == NULL) { + g_error (_("Can't create nautilus-preferences-applet!")); + exit (1); + } - icon_image = nautilus_image_new (NULL); - gtk_misc_set_padding (GTK_MISC (icon_image), 2, 2); + nautilus_global_preferences_initialize (); - gtk_signal_connect (GTK_OBJECT (icon_event_box), "enter_notify_event", GTK_SIGNAL_FUNC (image_enter_event), icon_image); - gtk_signal_connect (GTK_OBJECT (icon_event_box), "leave_notify_event", GTK_SIGNAL_FUNC (image_leave_event), icon_image); - gtk_signal_connect (GTK_OBJECT (icon_event_box), "button_press_event", GTK_SIGNAL_FUNC (image_button_press_event), icon_image); - gtk_signal_connect (GTK_OBJECT (icon_event_box), "button_release_event", GTK_SIGNAL_FUNC (image_button_release_event), icon_image); + button = gtk_toggle_button_new_with_label ("Show Desktop"); - nautilus_image_set_pixbuf (NAUTILUS_IMAGE (icon_image), icon_pixbuf); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), + nautilus_preferences_get_boolean (NAUTILUS_PREFERENCES_SHOW_DESKTOP)); + + gtk_signal_connect (GTK_OBJECT (button), + "toggled", + GTK_SIGNAL_FUNC (button_toggled), + NULL); - gtk_container_add (GTK_CONTAINER (icon_event_box), icon_image); - gtk_object_set_data (GTK_OBJECT (applet), "widget", icon_event_box); - applet_widget_add (APPLET_WIDGET (applet), icon_event_box); + nautilus_preferences_add_callback (NAUTILUS_PREFERENCES_SHOW_DESKTOP, + show_desktop_changed_callback, + button); - size = applet_widget_get_panel_pixel_size(APPLET_WIDGET(applet)) - 2; - applet_change_pixel_size (GTK_WIDGET (applet), size, NULL); + gtk_container_add (GTK_CONTAINER (applet), button); gtk_widget_show_all (applet); - - gtk_signal_connect(GTK_OBJECT(applet),"change_pixel_size", - GTK_SIGNAL_FUNC(applet_change_pixel_size), - NULL); + +// gtk_signal_connect(GTK_OBJECT(applet),"change_pixel_size", +// GTK_SIGNAL_FUNC (applet_change_pixel_size), +// NULL); applet_widget_gtk_main (); diff --git a/applets/launcher/nautilus-launcher-applet.gnorba b/applets/launcher/nautilus-launcher-applet.gnorba index a94f3bd81..f2feb22e7 100644 --- a/applets/launcher/nautilus-launcher-applet.gnorba +++ b/applets/launcher/nautilus-launcher-applet.gnorba @@ -1,5 +1,5 @@ -[nautilus_launcher_applet] +[nautilus_preferences_applet] type=exe repo_id=IDL:GNOME/Applet:1.0 -description=Nautilus Launcher Applet -location_info=nautilus-launcher-applet +description=Nautilus Preferences Applet +location_info=nautilus-preferences-applet diff --git a/applets/preferences-applet/Makefile.am b/applets/preferences-applet/Makefile.am new file mode 100644 index 000000000..d958a90da --- /dev/null +++ b/applets/preferences-applet/Makefile.am @@ -0,0 +1,31 @@ +include $(top_srcdir)/Makefile.shared + +INCLUDES = -I. -I$(srcdir) \ + -DGNOMELOCALEDIR=\""$(datadir)/locale"\" \ + -I$(top_srcdir) \ + -I$(top_builddir) \ + -I$(includedir) \ + $(GNOME_CFLAGS) \ + $(APPLETS_CFLAGS) \ + -DDATADIR=\""$(datadir)"\" \ + -DBINDIR=\""$(bindir)"\" \ + $(NULL) + +bin_PROGRAMS = nautilus-preferences-applet + +nautilus_preferences_applet_SOURCES =\ + nautilus-preferences-applet.c \ + $(NULL) + +nautilus_preferences_applet_LDADD = \ + $(top_builddir)/libnautilus/libnautilus.la \ + $(top_builddir)/libnautilus-extensions/libnautilus-extensions.la \ + $(APPLETS_LIBS) \ + $(NULL) + +gnorbadir = $(sysconfdir)/CORBA/servers +gnorba_DATA = nautilus-preferences-applet.gnorba + +EXTRA_DIST =\ + $(gnorba_DATA) \ + $(NULL) diff --git a/applets/preferences-applet/nautilus-preferences-applet.c b/applets/preferences-applet/nautilus-preferences-applet.c new file mode 100644 index 000000000..c25e72ad3 --- /dev/null +++ b/applets/preferences-applet/nautilus-preferences-applet.c @@ -0,0 +1,181 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* + Copyright (C) 2000 Eazel, Inc. + + The Gnome Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. + + The Gnome Library 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 Library General Public + License along with the Gnome Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. + + Authors: Ramiro Estrugo <ramiro@eazel.com> + */ + +/* + * A very simple applet to toggle some Nautilus preferences. + */ + +#include <config.h> +#include <applet-widget.h> +#include <libnautilus-extensions/nautilus-image.h> +#include <libnautilus-extensions/nautilus-global-preferences.h> +#include <gtk/gtkvbox.h> +#include <gtk/gtktogglebutton.h> + +/* UTTER HACK */ +static ORBit_MessageValidationResult +accept_all_cookies (CORBA_unsigned_long request_id, + CORBA_Principal *principal, + CORBA_char *operation) +{ + /* allow ALL cookies */ + return ORBIT_MESSAGE_ALLOW_ALL; +} + + +typedef struct +{ + char *preference_name; + GtkWidget *button; +} Foo; + +static void +preference_toggle_destroy_callback (GtkObject *object, gpointer callback_data) +{ + Foo *foo = callback_data; + + g_return_if_fail (foo != NULL); + g_return_if_fail (foo->preference_name != NULL); + g_return_if_fail (GTK_IS_TOGGLE_BUTTON (foo->button)); + + g_free (foo->preference_name); + g_free (foo); +} + +static void +boolean_preference_changed_callback (gpointer callback_data) +{ + Foo *foo = callback_data; + + g_return_if_fail (foo != NULL); + g_return_if_fail (foo->preference_name != NULL); + g_return_if_fail (GTK_IS_TOGGLE_BUTTON (foo->button)); + + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (foo->button), + nautilus_preferences_get_boolean (foo->preference_name)); +} + +static void +button_toggled (GtkWidget *button, + gpointer callback_data) +{ + Foo *foo = callback_data; + + g_return_if_fail (foo != NULL); + g_return_if_fail (foo->preference_name != NULL); + g_return_if_fail (GTK_IS_TOGGLE_BUTTON (foo->button)); + + nautilus_preferences_set_boolean (foo->preference_name, GTK_TOGGLE_BUTTON (foo->button)->active); +} + +static GtkWidget * +boolean_toggle_button_new (const char *preference_name, + const char *button_label) +{ + Foo *foo; + GtkWidget *button; + + g_return_val_if_fail (preference_name != NULL, NULL); + g_return_val_if_fail (button_label != NULL, NULL); + + + button = gtk_toggle_button_new_with_label (button_label); + + foo = g_new (Foo, 1); + foo->preference_name = g_strdup (preference_name); + foo->button = button; + + gtk_signal_connect (GTK_OBJECT (button), + "destroy", + GTK_SIGNAL_FUNC (preference_toggle_destroy_callback), + foo); + + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), + nautilus_preferences_get_boolean (preference_name)); + + gtk_signal_connect_while_alive (GTK_OBJECT (button), + "toggled", + GTK_SIGNAL_FUNC (button_toggled), + foo, + GTK_OBJECT (button)); + + nautilus_preferences_add_callback_while_alive (preference_name, + boolean_preference_changed_callback, + foo, + GTK_OBJECT (button)); + + return button; +} + +int +main (int argc, char **argv) +{ + GtkWidget *applet; + GtkWidget *vbox; + GtkWidget *show_desktop_button; + GtkWidget *smooth_graphics_button; + + bindtextdomain (PACKAGE, GNOMELOCALEDIR); + textdomain (PACKAGE); + + applet_widget_init ("nautilus_preferences_applet", + VERSION, + argc, + argv, + NULL, + 0, + NULL); + + /* want to accept all corba messages so we setup the request validator + * to just "accept all". With Orbit 5.1 and higher this should be + * secure */ + ORBit_set_request_validation_handler (accept_all_cookies); + + applet = applet_widget_new ("nautilus_preferences_applet"); + + if (applet == NULL) { + g_error (_("Can't create nautilus-preferences-applet!")); + exit (1); + } + + nautilus_global_preferences_initialize (); + + vbox = gtk_vbox_new (FALSE, 1); + + show_desktop_button = boolean_toggle_button_new (NAUTILUS_PREFERENCES_SHOW_DESKTOP, + "Show Desktop"); + + gtk_box_pack_start (GTK_BOX (vbox), show_desktop_button, TRUE, TRUE, 1); + + smooth_graphics_button = boolean_toggle_button_new (NAUTILUS_PREFERENCES_SMOOTH_GRAPHICS_MODE, + "Smooth Graphics"); + + gtk_box_pack_start (GTK_BOX (vbox), smooth_graphics_button, TRUE, TRUE, 1); + + gtk_container_add (GTK_CONTAINER (applet), vbox); + + gtk_widget_show_all (applet); + + applet_widget_gtk_main (); + + return 0; +} diff --git a/applets/preferences-applet/nautilus-preferences-applet.gnorba b/applets/preferences-applet/nautilus-preferences-applet.gnorba new file mode 100644 index 000000000..a94f3bd81 --- /dev/null +++ b/applets/preferences-applet/nautilus-preferences-applet.gnorba @@ -0,0 +1,5 @@ +[nautilus_launcher_applet] +type=exe +repo_id=IDL:GNOME/Applet:1.0 +description=Nautilus Launcher Applet +location_info=nautilus-launcher-applet diff --git a/configure.in b/configure.in index 9c9f42961..747bced84 100644 --- a/configure.in +++ b/configure.in @@ -853,6 +853,7 @@ user-guide/Makefile user-guide/C/Makefile applets/Makefile applets/launcher/Makefile +applets/preferences-applet/Makefile ]) dnl <= Configuration summary => |