Updating branch refs/heads/master to 8bd24fe4440fd54644c7b833a3d836ab5e05023d (commit) from a865bdae23a07db6300c77119a874ec8b3192e9f (commit)
commit 8bd24fe4440fd54644c7b833a3d836ab5e05023d Author: Nick Schermer <n...@xfce.org> Date: Tue May 31 19:15:51 2011 +0200 Add c demo. .../merge-with-xfrun/demo-code/c/Makefile | 10 + .../demo-code/c/appfinder-window.c | 224 ++++++++++++++++++++ .../demo-code/c/appfinder-window.h | 28 +++ .../merge-with-xfrun/demo-code/c/main.c | 80 +++++++ .../merge-with-xfrun/demo-code/{ => vala}/Makefile | 0 .../demo-code/{ => vala}/mockup.vala | 0 6 files changed, 342 insertions(+), 0 deletions(-) diff --git a/xfce4-appfinder/merge-with-xfrun/demo-code/c/Makefile b/xfce4-appfinder/merge-with-xfrun/demo-code/c/Makefile new file mode 100644 index 0000000..b92b7db --- /dev/null +++ b/xfce4-appfinder/merge-with-xfrun/demo-code/c/Makefile @@ -0,0 +1,10 @@ + +all: + gcc -Wall -Werror -O0 -g -ggdb -pipe \ + `pkg-config --libs --cflags gtk+-2.0` \ + `pkg-config --libs --cflags libxfce4util-1.0` \ + `pkg-config --libs --cflags garcon-1` \ + `pkg-config --libs --cflags gthread-2.0` \ + `pkg-config --libs --cflags libxfce4ui-1` \ + main.c appfinder-window.c appfinder-window.h \ + -o appfinder diff --git a/xfce4-appfinder/merge-with-xfrun/demo-code/c/appfinder-window.c b/xfce4-appfinder/merge-with-xfrun/demo-code/c/appfinder-window.c new file mode 100644 index 0000000..9c0225f --- /dev/null +++ b/xfce4-appfinder/merge-with-xfrun/demo-code/c/appfinder-window.c @@ -0,0 +1,224 @@ +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <string.h> +#include <libxfce4util/libxfce4util.h> + +#include "appfinder-window.h" + + + +static void xfce_appfinder_window_finalize (GObject *object); +static void xfce_appfinder_window_entry_icon_released (GtkEntry *entry, + GtkEntryIconPosition icon_pos, + GdkEvent *event, + XfceAppfinderWindow *window); + + +struct _XfceAppfinderWindowClass +{ + GtkWindowClass __parent__; +}; + +struct _XfceAppfinderWindow +{ + GtkWindow __parent__; + + GtkWidget *paned; + GtkWidget *entry; +}; + + + +G_DEFINE_TYPE (XfceAppfinderWindow, xfce_appfinder_window, GTK_TYPE_WINDOW) + + + +static void +xfce_appfinder_window_class_init (XfceAppfinderWindowClass *klass) +{ + GObjectClass *gobject_class; + + gobject_class = G_OBJECT_CLASS (klass); + gobject_class->finalize = xfce_appfinder_window_finalize; +} + + + +static void +xfce_appfinder_window_init (XfceAppfinderWindow *window) +{ + GtkWidget *vbox; + GtkWidget *entry; + GtkWidget *pane; + GtkWidget *scroll; + GtkWidget *sidepane; + GtkWidget *bbox; + GtkWidget *button; + GtkWidget *treeview; + GtkWidget *image; + GtkWidget *hbox; + /*GtkTreeViewColumn *column; + GtkCellRenderer *renderer;*/ + + gtk_window_set_title (GTK_WINDOW (window), _("Application Finder")); + gtk_window_set_default_size (GTK_WINDOW (window), 400 /* todo, remember */, -1); + gtk_window_set_icon_name (GTK_WINDOW (window), GTK_STOCK_EXECUTE); + g_signal_connect (G_OBJECT (window), "delete-event", G_CALLBACK (gtk_main_quit), NULL); + + vbox = gtk_vbox_new (FALSE, 6); + gtk_container_add (GTK_CONTAINER (window), vbox); + gtk_container_set_border_width (GTK_CONTAINER (vbox), 6); + gtk_widget_show (vbox); + + hbox = gtk_hbox_new (FALSE, 12); + gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0); + gtk_widget_show (hbox); + + image = gtk_image_new_from_icon_name ("terminal", GTK_ICON_SIZE_DIALOG); + gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0); + gtk_widget_show (image); + + window->entry = entry = gtk_entry_new (); + gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0); + g_signal_connect (G_OBJECT (entry), "icon-release", + G_CALLBACK (xfce_appfinder_window_entry_icon_released), window); + gtk_widget_show (entry); + + window->paned = pane = gtk_hpaned_new (); + gtk_box_pack_start (GTK_BOX (vbox), pane, TRUE, TRUE, 0); + gtk_paned_set_position (GTK_PANED (pane), 180 /* todo remember */); + + scroll = gtk_scrolled_window_new (NULL, NULL); + gtk_paned_add1 (GTK_PANED (pane), scroll); + gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroll), GTK_SHADOW_ETCHED_IN); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); + gtk_widget_show (scroll); + + sidepane = gtk_tree_view_new (); + gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (sidepane), FALSE); + /*gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (sidepane), + xfce_appfinder_model_row_separator_func, NULL, NULL);*/ + gtk_container_add (GTK_CONTAINER (scroll), sidepane); + gtk_widget_show (sidepane); + + /*selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (sidepane)); + g_signal_connect_swapped (G_OBJECT (selection), "changed", + G_CALLBACK (xfce_appfinder_window_category_changed), window);*/ + + /* column = gtk_tree_view_column_new (); + gtk_tree_view_append_column (GTK_TREE_VIEW (sidepane), GTK_TREE_VIEW_COLUMN (column)); + + renderer = gtk_cell_renderer_pixbuf_new (); + gtk_tree_view_column_pack_start (GTK_TREE_VIEW_COLUMN (column), renderer, FALSE); + gtk_tree_view_column_set_attributes (GTK_TREE_VIEW_COLUMN (column), renderer, + "pixbuf", XFCE_APPFINDER_MODEL_COLUMN_ICON, NULL); + + renderer = gtk_cell_renderer_text_new (); + g_object_set (renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL); + gtk_tree_view_column_pack_start (GTK_TREE_VIEW_COLUMN (column), renderer, TRUE); + gtk_tree_view_column_set_attributes (GTK_TREE_VIEW_COLUMN (column), renderer, + "text", XFCE_APPFINDER_MODEL_COLUMN_NAME, NULL); */ + + scroll = gtk_scrolled_window_new (NULL, NULL); + gtk_paned_add2 (GTK_PANED (pane), scroll); + gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroll), GTK_SHADOW_ETCHED_IN); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); + gtk_widget_show (scroll); + + treeview = gtk_tree_view_new (); + gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE); + /* gtk_tree_view_set_tooltip_column (GTK_TREE_VIEW (treeview), XFCE_RUN_MODEL_COLUMN_TOOLTIP); */ + gtk_container_add (GTK_CONTAINER (scroll), treeview); + gtk_widget_show (treeview); + + /*renderer = gtk_cell_renderer_pixbuf_new (); + column = gtk_tree_view_column_new_with_attributes (NULL, renderer, "pixbuf", XFCE_APPFINDER_MODEL_COLUMN_ICON, NULL); + gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), GTK_TREE_VIEW_COLUMN (column)); + + renderer = gtk_cell_renderer_text_new (); + g_object_set (renderer, "ellipsize", PANGO_ELLIPSIZE_END, NULL); + column = gtk_tree_view_column_new_with_attributes (NULL, renderer, "markup", XFCE_APPFINDER_MODEL_COLUMN_NAME, NULL); + gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), GTK_TREE_VIEW_COLUMN (column));*/ + + bbox = gtk_hbutton_box_new (); + gtk_box_pack_start (GTK_BOX (vbox), bbox, FALSE, TRUE, 0); + gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_END); + gtk_button_box_set_spacing (GTK_BUTTON_BOX (bbox), 6); + gtk_widget_show (bbox); + + button = gtk_button_new_from_stock (GTK_STOCK_CLOSE); + gtk_container_add (GTK_CONTAINER (bbox), button); + g_signal_connect (G_OBJECT (button), "clicked", + G_CALLBACK (gtk_main_quit), NULL); + gtk_widget_show (button); + + button = gtk_button_new_with_mnemonic ("La_unch"); + gtk_container_add (GTK_CONTAINER (bbox), button); + gtk_widget_show (button); + + image = gtk_image_new_from_stock (GTK_STOCK_EXECUTE, GTK_ICON_SIZE_BUTTON); + gtk_button_set_image (GTK_BUTTON (button), image); + gtk_widget_show (image); +} + + + +static void +xfce_appfinder_window_finalize (GObject *object) +{ + //XfceAppfinderWindow *window = XFCE_APPFINDER_WINDOW (object); + + (*G_OBJECT_CLASS (xfce_appfinder_window_parent_class)->finalize) (object); +} + + + +static void +xfce_appfinder_window_entry_icon_released (GtkEntry *entry, + GtkEntryIconPosition icon_pos, + GdkEvent *event, + XfceAppfinderWindow *window) +{ + if (icon_pos == GTK_ENTRY_ICON_SECONDARY) + xfce_appfinder_window_set_expanded (window, !gtk_widget_get_visible (window->paned)); +} + + + +GtkWidget * +xfce_appfinder_window_new (void) +{ + return g_object_new (XFCE_TYPE_APPFINDER_WINDOW, NULL); +} + + + +void +xfce_appfinder_window_set_expanded (XfceAppfinderWindow *window, + gboolean expanded) +{ + GdkGeometry hints; + gint width; + + if (expanded) + { + gtk_window_set_geometry_hints (GTK_WINDOW (window), NULL, NULL, 0); + gtk_window_get_size (GTK_WINDOW (window), &width, NULL); + gtk_window_resize (GTK_WINDOW (window), width, 500); + } + else + { + hints.max_height = -1; + hints.max_width = G_MAXINT; + gtk_window_set_geometry_hints (GTK_WINDOW (window), NULL, &hints, GDK_HINT_MAX_SIZE); + } + + gtk_widget_set_visible (window->paned, expanded); + gtk_entry_set_icon_from_icon_name (GTK_ENTRY (window->entry), GTK_ENTRY_ICON_SECONDARY, + expanded ? GTK_STOCK_GO_UP : GTK_STOCK_GO_DOWN); + gtk_entry_set_icon_tooltip_text (GTK_ENTRY (window->entry), GTK_ENTRY_ICON_SECONDARY, + expanded ? _("Collapse the icon views") + : _("Show all applications")); +} diff --git a/xfce4-appfinder/merge-with-xfrun/demo-code/c/appfinder-window.h b/xfce4-appfinder/merge-with-xfrun/demo-code/c/appfinder-window.h new file mode 100644 index 0000000..46b4744 --- /dev/null +++ b/xfce4-appfinder/merge-with-xfrun/demo-code/c/appfinder-window.h @@ -0,0 +1,28 @@ +#ifndef __XFCE_APPFINDER_WINDOW_H__ +#define __XFCE_APPFINDER_WINDOW_H__ + +#include <gtk/gtk.h> + +G_BEGIN_DECLS + +typedef struct _XfceAppfinderWindowClass XfceAppfinderWindowClass; +typedef struct _XfceAppfinderWindow XfceAppfinderWindow; + +#define XFCE_TYPE_APPFINDER_WINDOW (xfce_appfinder_window_get_type ()) +#define XFCE_APPFINDER_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), XFCE_TYPE_APPFINDER_WINDOW, XfceAppfinderWindow)) +#define XFCE_APPFINDER_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), XFCE_TYPE_APPFINDER_WINDOW, XfceAppfinderWindowClass)) +#define XFCE_IS_APPFINDER_WINDOW(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XFCE_TYPE_APPFINDER_WINDOW)) +#define XFCE_IS_APPFINDER_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XFCE_TYPE_APPFINDER_WINDOW)) +#define XFCE_APPFINDER_WINDOW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XFCE_TYPE_APPFINDER_WINDOW, XfceAppfinderWindowClass)) + +GType xfce_appfinder_window_get_type (void) G_GNUC_CONST; + +GtkWidget *xfce_appfinder_window_new (void) G_GNUC_MALLOC; + +void xfce_appfinder_window_set_expanded (XfceAppfinderWindow *window, + gboolean expanded); + +G_END_DECLS + +#endif /* !__XFCE_APPFINDER_WINDOW_H__ */ + diff --git a/xfce4-appfinder/merge-with-xfrun/demo-code/c/main.c b/xfce4-appfinder/merge-with-xfrun/demo-code/c/main.c new file mode 100644 index 0000000..b603826 --- /dev/null +++ b/xfce4-appfinder/merge-with-xfrun/demo-code/c/main.c @@ -0,0 +1,80 @@ +#include <stdlib.h> +#include <gtk/gtk.h> +#include <libxfce4util/libxfce4util.h> +#include <garcon/garcon.h> + +#include "appfinder-window.h" + +#define PACKAGE_NAME "xfce4-appfinder" +#define PACKAGE_VERSION "4.9.0" +#define PACKAGE_BUGREPORT "http://bugzilla.xfce.org" +#define GETTEXT_PACKAGE PACKAGE_NAME +#define PACKAGE_LOCALE_DIR "/opt/xfce/share/locale" + + + +static gboolean opt_finder = FALSE; +static gboolean opt_version = FALSE; +static gchar *opt_filename = NULL; + + + +static GOptionEntry option_entries[] = +{ + { "finder", '\0', 0, G_OPTION_ARG_NONE, &opt_finder, N_("Start in expanded mode"), NULL }, + { "version", 'V', 0, G_OPTION_ARG_NONE, &opt_version, N_("Print version information and exit"), NULL }, + { G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME, &opt_filename, NULL, NULL }, + { NULL } +}; + + + +gint +main (gint argc, gchar **argv) +{ + GError *error = NULL; + GtkWidget *window; + + /* set translation domain */ + xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8"); + +#ifdef G_ENABLE_DEBUG + /* do NOT remove this line for now, If something doesn't work, + * fix your code instead! */ + g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING); +#endif + + if (!g_thread_supported ()) + g_thread_init (NULL); + + if (!gtk_init_with_args (&argc, &argv, _("[MENUFILE]"), option_entries, GETTEXT_PACKAGE, &error)) + { + g_printerr ("%s: %s.\n", PACKAGE_NAME, error->message); + g_printerr (_("Type \"%s --help\" for usage."), PACKAGE_NAME); + g_printerr ("\n"); + g_error_free (error); + + return EXIT_FAILURE; + } + + if (opt_version) + { + g_print ("%s %s (Xfce %s)\n\n", PACKAGE_NAME, PACKAGE_VERSION, xfce_version_string ()); + g_print ("%s\n", "Copyright (c) 2004-2010"); + g_print ("\t%s\n\n", _("The Xfce development team. All rights reserved.")); + g_print (_("Please report bugs to <%s>."), PACKAGE_BUGREPORT); + g_print ("\n"); + + return EXIT_SUCCESS; + } + + garcon_set_environment ("XFCE"); + + window = xfce_appfinder_window_new (); + xfce_appfinder_window_set_expanded (XFCE_APPFINDER_WINDOW (window), opt_finder); + gtk_widget_show (window); + + gtk_main (); + + return EXIT_SUCCESS; +} diff --git a/xfce4-appfinder/merge-with-xfrun/demo-code/Makefile b/xfce4-appfinder/merge-with-xfrun/demo-code/vala/Makefile similarity index 100% rename from xfce4-appfinder/merge-with-xfrun/demo-code/Makefile rename to xfce4-appfinder/merge-with-xfrun/demo-code/vala/Makefile diff --git a/xfce4-appfinder/merge-with-xfrun/demo-code/mockup.vala b/xfce4-appfinder/merge-with-xfrun/demo-code/vala/mockup.vala similarity index 100% rename from xfce4-appfinder/merge-with-xfrun/demo-code/mockup.vala rename to xfce4-appfinder/merge-with-xfrun/demo-code/vala/mockup.vala _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org http://foo-projects.org/mailman/listinfo/xfce4-commits