Modified code to allow running as an applet or standalone. It auto detects
whether to operate in applet mode based on the command line arguments. git-svn-id: https://samskivert.googlecode.com/svn/trunk@297 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
dnl $Id: configure.in,v 1.3 2001/08/16 19:25:56 mdb Exp $
|
dnl $Id: configure.in,v 1.4 2001/08/18 02:34:06 mdb Exp $
|
||||||
dnl
|
dnl
|
||||||
dnl Process this file with autoconf to produce a configure script.
|
dnl Process this file with autoconf to produce a configure script.
|
||||||
|
|
||||||
@@ -34,12 +34,11 @@ AM_MAINTAINER_MODE
|
|||||||
AM_ACLOCAL_INCLUDE(macros)
|
AM_ACLOCAL_INCLUDE(macros)
|
||||||
AC_ISC_POSIX
|
AC_ISC_POSIX
|
||||||
|
|
||||||
GNOME_INIT
|
GNOME_INIT(applets)
|
||||||
|
|
||||||
dnl Check for programs
|
dnl Check for programs
|
||||||
AC_PROG_CC
|
AC_PROG_CC
|
||||||
AM_PROG_CC_STDC
|
AM_PROG_CC_STDC
|
||||||
AC_ARG_PROGRAM
|
|
||||||
AM_PROG_LIBTOOL
|
AM_PROG_LIBTOOL
|
||||||
|
|
||||||
dnl this should come after `AC_PROG_CC'
|
dnl this should come after `AC_PROG_CC'
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#
|
#
|
||||||
# $Id: Makefile.am,v 1.3 2001/08/16 00:12:11 mdb Exp $
|
# $Id: Makefile.am,v 1.4 2001/08/18 02:34:06 mdb Exp $
|
||||||
|
|
||||||
bin_PROGRAMS = lookuplet
|
bin_PROGRAMS = lookuplet
|
||||||
|
|
||||||
@@ -20,6 +20,7 @@ INCLUDES = \
|
|||||||
lookuplet_LDADD = \
|
lookuplet_LDADD = \
|
||||||
$(GNOME_LIBDIR) \
|
$(GNOME_LIBDIR) \
|
||||||
$(GNOMEUI_LIBS) \
|
$(GNOMEUI_LIBS) \
|
||||||
|
$(GNOME_APPLETS_LIBS) \
|
||||||
$(INTLLIBS)
|
$(INTLLIBS)
|
||||||
|
|
||||||
# currently the installation of these bitmaps wouldn't be necessary
|
# currently the installation of these bitmaps wouldn't be necessary
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* $Id: lookuplet.c,v 1.5 2001/08/16 20:25:09 mdb Exp $
|
* $Id: lookuplet.c,v 1.6 2001/08/18 02:34:06 mdb Exp $
|
||||||
*
|
*
|
||||||
* lookuplet - a utility for quickly looking up information
|
* lookuplet - a utility for quickly looking up information
|
||||||
* Copyright (C) 2001 Michael Bayne
|
* Copyright (C) 2001 Michael Bayne
|
||||||
@@ -20,22 +20,62 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
#include <applet-widget.h>
|
||||||
#include <gnome.h>
|
#include <gnome.h>
|
||||||
|
|
||||||
#include "querybox.h"
|
#include "querybox.h"
|
||||||
#include "preferences.h"
|
#include "preferences.h"
|
||||||
|
|
||||||
|
/* Used to track whether or not we're being run as an applet or
|
||||||
|
* standalone. */
|
||||||
|
int applet_mode = 0;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
exit_lookuplet (GtkWidget* widget, gpointer data)
|
exit_lookuplet (GtkWidget* widget, gpointer data)
|
||||||
{
|
{
|
||||||
gtk_main_quit();
|
gtk_main_quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
about_box_cb (AppletWidget *applet, gpointer data)
|
||||||
|
{
|
||||||
|
static GtkWidget* about_box = NULL;
|
||||||
|
const gchar* authors[] = {
|
||||||
|
(gchar*) "Michael Bayne <mdb@samskivert.com>", (gchar*)NULL };
|
||||||
|
|
||||||
|
if (about_box != NULL) {
|
||||||
|
gdk_window_show(about_box->window);
|
||||||
|
gdk_window_raise(about_box->window);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
about_box = gnome_about_new(
|
||||||
|
_("lookuplet"), VERSION, "(C) 2001 Michael Bayne", authors,
|
||||||
|
_("This GNOME applet provides a simple means by which web and "
|
||||||
|
"other queries can be launched with minimal typing.\n\n\n"
|
||||||
|
"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."),
|
||||||
|
(gchar*)NULL);
|
||||||
|
gtk_signal_connect(GTK_OBJECT(about_box), "destroy",
|
||||||
|
GTK_SIGNAL_FUNC(gtk_widget_destroyed), &about_box);
|
||||||
|
gtk_widget_show(about_box);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char** argv)
|
main (int argc, char** argv)
|
||||||
{
|
{
|
||||||
GtkWidget* window;
|
GtkWidget* top;
|
||||||
GtkWidget* contents;
|
GtkWidget* contents;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
/* figure out if we're running as an applet */
|
||||||
|
for (i = 0; i < argc; i++) {
|
||||||
|
if (strstr(argv[i], "activate-goad-server")) {
|
||||||
|
applet_mode = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_NLS
|
#ifdef ENABLE_NLS
|
||||||
/* initialize the i18n stuff */
|
/* initialize the i18n stuff */
|
||||||
@@ -43,34 +83,64 @@ main (int argc, char** argv)
|
|||||||
textdomain(PACKAGE);
|
textdomain(PACKAGE);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef APPLET_MODE
|
if (applet_mode) {
|
||||||
/* initialize gtk */
|
/* intialize; this will basically set up the applet, corba and
|
||||||
gtk_init(&argc, &argv);
|
call gnome_init() */
|
||||||
#else
|
applet_widget_init(PACKAGE, VERSION, argc, argv, NULL, 0, NULL);
|
||||||
/* initialize gnome */
|
|
||||||
gnome_init(PACKAGE, VERSION, argc, argv);
|
/* create our applet_widget */
|
||||||
#endif
|
if (!(top = applet_widget_new(PACKAGE))) {
|
||||||
|
g_error("Can't create applet widget.\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
/* initialize gnome */
|
||||||
|
gnome_init(PACKAGE, VERSION, argc, argv);
|
||||||
|
|
||||||
|
/* create a new window */
|
||||||
|
top = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||||
|
gtk_signal_connect(GTK_OBJECT(top), "destroy",
|
||||||
|
GTK_SIGNAL_FUNC(exit_lookuplet), NULL);
|
||||||
|
}
|
||||||
|
|
||||||
/* initialize our preferences */
|
/* initialize our preferences */
|
||||||
lk_prefs_init();
|
lk_prefs_init();
|
||||||
|
|
||||||
/* create a new window */
|
|
||||||
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
|
||||||
gtk_signal_connect(GTK_OBJECT(window), "destroy",
|
|
||||||
GTK_SIGNAL_FUNC(exit_lookuplet), NULL);
|
|
||||||
|
|
||||||
/* create our contents and set them up real proper like */
|
/* create our contents and set them up real proper like */
|
||||||
contents = lk_querybox_create();
|
contents = lk_querybox_create();
|
||||||
gtk_container_add(GTK_CONTAINER(window), contents);
|
|
||||||
gtk_container_set_border_width(GTK_CONTAINER(window), GNOME_PAD_SMALL);
|
if (applet_mode) {
|
||||||
|
applet_widget_add(APPLET_WIDGET(top), contents);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
/* we only want a border if we're not an applet */
|
||||||
|
gtk_container_set_border_width(GTK_CONTAINER(top), GNOME_PAD_SMALL);
|
||||||
|
gtk_container_add(GTK_CONTAINER(top), contents);
|
||||||
|
}
|
||||||
|
|
||||||
gtk_widget_show_all(contents);
|
gtk_widget_show_all(contents);
|
||||||
gtk_widget_show(window);
|
gtk_widget_show(top);
|
||||||
|
|
||||||
|
/* set up our applet menu */
|
||||||
|
if (applet_mode) {
|
||||||
|
applet_widget_register_stock_callback(
|
||||||
|
APPLET_WIDGET(top), "properties", GNOME_STOCK_MENU_PROP,
|
||||||
|
_("Properties..."), lk_prefs_display_applet, NULL);
|
||||||
|
applet_widget_register_stock_callback(
|
||||||
|
APPLET_WIDGET(top), "about", GNOME_STOCK_MENU_ABOUT,
|
||||||
|
_("About..."), about_box_cb, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
/* initialize the querybox (which handles about everything) */
|
/* initialize the querybox (which handles about everything) */
|
||||||
lk_querybox_init();
|
lk_querybox_init();
|
||||||
|
|
||||||
/* main loop */
|
/* main loop */
|
||||||
gtk_main();
|
if (applet_mode) {
|
||||||
|
applet_widget_gtk_main();
|
||||||
|
} else {
|
||||||
|
gtk_main();
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
/**
|
||||||
|
* $Id: lookuplet.h,v 1.1 2001/08/18 02:34:06 mdb Exp $
|
||||||
|
*
|
||||||
|
* lookuplet - a utility for quickly looking up information
|
||||||
|
* Copyright (C) 2001 Michael Bayne
|
||||||
|
*
|
||||||
|
* 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.1 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 _LOOKUPLET_H_
|
||||||
|
#define _LOOKUPLET_H_
|
||||||
|
|
||||||
|
/* Used to indicate whether or not we're running in applet mode. */
|
||||||
|
extern int applet_mode;
|
||||||
|
|
||||||
|
#endif /* _LOOKUPLET_H_ */
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* $Id: preferences.c,v 1.2 2001/08/16 20:25:09 mdb Exp $
|
* $Id: preferences.c,v 1.3 2001/08/18 02:34:06 mdb Exp $
|
||||||
*
|
*
|
||||||
* lookuplet - a utility for quickly looking up information
|
* lookuplet - a utility for quickly looking up information
|
||||||
* Copyright (C) 2001 Michael Bayne
|
* Copyright (C) 2001 Michael Bayne
|
||||||
@@ -453,3 +453,9 @@ lk_prefs_display ()
|
|||||||
/* and finally show our property box */
|
/* and finally show our property box */
|
||||||
gtk_widget_show_all(_prefBox);
|
gtk_widget_show_all(_prefBox);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
lk_prefs_display_applet (AppletWidget* applet, gpointer data)
|
||||||
|
{
|
||||||
|
lk_prefs_display();
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* $Id: preferences.h,v 1.3 2001/08/16 20:25:09 mdb Exp $
|
* $Id: preferences.h,v 1.4 2001/08/18 02:34:06 mdb Exp $
|
||||||
*
|
*
|
||||||
* lookuplet - a utility for quickly looking up information
|
* lookuplet - a utility for quickly looking up information
|
||||||
* Copyright (C) 2001 Michael Bayne
|
* Copyright (C) 2001 Michael Bayne
|
||||||
@@ -22,6 +22,7 @@
|
|||||||
#ifndef _PREFERENCES_H_
|
#ifndef _PREFERENCES_H_
|
||||||
#define _PREFERENCES_H_
|
#define _PREFERENCES_H_
|
||||||
|
|
||||||
|
#include <applet-widget.h>
|
||||||
#include <gnome.h>
|
#include <gnome.h>
|
||||||
|
|
||||||
extern void
|
extern void
|
||||||
@@ -36,4 +37,7 @@ lk_prefs_cleanup (void);
|
|||||||
extern void
|
extern void
|
||||||
lk_prefs_display (void);
|
lk_prefs_display (void);
|
||||||
|
|
||||||
|
extern void
|
||||||
|
lk_prefs_display_applet (AppletWidget* applet, gpointer data);
|
||||||
|
|
||||||
#endif /* _PREFERENCES_H_ */
|
#endif /* _PREFERENCES_H_ */
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
* $Id: querybox.c,v 1.6 2001/08/16 20:25:09 mdb Exp $
|
* $Id: querybox.c,v 1.7 2001/08/18 02:34:06 mdb Exp $
|
||||||
*
|
*
|
||||||
* lookuplet - a utility for quickly looking up information
|
* lookuplet - a utility for quickly looking up information
|
||||||
* Copyright (C) 2001 Michael Bayne
|
* Copyright (C) 2001 Michael Bayne
|
||||||
@@ -29,6 +29,7 @@
|
|||||||
#include "launcher.h"
|
#include "launcher.h"
|
||||||
#include "keysym-util.h"
|
#include "keysym-util.h"
|
||||||
#include "preferences.h"
|
#include "preferences.h"
|
||||||
|
#include "lookuplet.h"
|
||||||
#include "querybox.h"
|
#include "querybox.h"
|
||||||
|
|
||||||
static GtkWidget* _query;
|
static GtkWidget* _query;
|
||||||
@@ -88,12 +89,12 @@ key_pressed (GtkWidget* widget, GdkEvent* event, gpointer callback_data)
|
|||||||
/* launch the appropriate thing */
|
/* launch the appropriate thing */
|
||||||
lk_launcher_launch(binding, search_text);
|
lk_launcher_launch(binding, search_text);
|
||||||
g_free(search_text);
|
g_free(search_text);
|
||||||
#ifdef APPLET_MODE
|
if (applet_mode) {
|
||||||
/* clear out the contents of the entry box */
|
/* clear out the contents of the entry box */
|
||||||
gtk_entry_set_text(GTK_ENTRY(widget), "");
|
gtk_entry_set_text(GTK_ENTRY(widget), "");
|
||||||
#else
|
} else {
|
||||||
gtk_exit(0);
|
gtk_exit(0);
|
||||||
#endif
|
}
|
||||||
handled = TRUE;
|
handled = TRUE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -120,12 +121,12 @@ launch (GtkWidget* widget, gpointer data)
|
|||||||
lk_launcher_launch(NULL, search_text);
|
lk_launcher_launch(NULL, search_text);
|
||||||
g_free(search_text);
|
g_free(search_text);
|
||||||
|
|
||||||
#ifdef APPLET_MODE
|
if (applet_mode) {
|
||||||
/* clear out the contents of the entry box */
|
/* clear out the contents of the entry box */
|
||||||
gtk_entry_set_text(GTK_ENTRY(widget), "");
|
gtk_entry_set_text(GTK_ENTRY(widget), "");
|
||||||
#else
|
} else {
|
||||||
gtk_exit(0);
|
gtk_exit(0);
|
||||||
#endif
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GtkWidget*
|
GtkWidget*
|
||||||
@@ -145,18 +146,22 @@ lk_querybox_create (void)
|
|||||||
gtk_signal_connect(GTK_OBJECT(_query), "activate",
|
gtk_signal_connect(GTK_OBJECT(_query), "activate",
|
||||||
GTK_SIGNAL_FUNC(launch), NULL);
|
GTK_SIGNAL_FUNC(launch), NULL);
|
||||||
|
|
||||||
/* create our preferences button */
|
/* create a horizontal box to hold our query input box and the
|
||||||
prefs = gtk_button_new_with_label(_("Prefs"));
|
* label */
|
||||||
gtk_signal_connect (GTK_OBJECT(prefs), "clicked",
|
|
||||||
GTK_SIGNAL_FUNC(prefs_clicked), NULL);
|
|
||||||
|
|
||||||
/* create a vertical box to hold our query input box and the label */
|
|
||||||
hbox = gtk_hbox_new(FALSE, GNOME_PAD_SMALL);
|
hbox = gtk_hbox_new(FALSE, GNOME_PAD_SMALL);
|
||||||
|
|
||||||
/* pack the query box and label into the hbox */
|
/* pack the query box and label into the hbox */
|
||||||
gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
|
gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
|
||||||
gtk_box_pack_start(GTK_BOX(hbox), _query, TRUE, TRUE, 0);
|
gtk_box_pack_start(GTK_BOX(hbox), _query, TRUE, TRUE, 0);
|
||||||
gtk_box_pack_start(GTK_BOX(hbox), prefs, FALSE, FALSE, 0);
|
|
||||||
|
/* create our preferences button (only if we're not an applet, if
|
||||||
|
* we're an applet we'll have a preferences menu item instead) */
|
||||||
|
if (!applet_mode) {
|
||||||
|
prefs = gtk_button_new_with_label(_("Prefs"));
|
||||||
|
gtk_signal_connect (GTK_OBJECT(prefs), "clicked",
|
||||||
|
GTK_SIGNAL_FUNC(prefs_clicked), NULL);
|
||||||
|
gtk_box_pack_start(GTK_BOX(hbox), prefs, FALSE, FALSE, 0);
|
||||||
|
}
|
||||||
|
|
||||||
return hbox;
|
return hbox;
|
||||||
}
|
}
|
||||||
@@ -170,18 +175,22 @@ lk_querybox_init (void)
|
|||||||
gtk_signal_connect(GTK_OBJECT(_query), "key_press_event",
|
gtk_signal_connect(GTK_OBJECT(_query), "key_press_event",
|
||||||
GTK_SIGNAL_FUNC(key_pressed), NULL);
|
GTK_SIGNAL_FUNC(key_pressed), NULL);
|
||||||
|
|
||||||
/* focus the text entry box */
|
/* if we're not an applet, we want to request focus and grab the
|
||||||
gtk_widget_grab_focus(_query);
|
current X selection */
|
||||||
|
if (!applet_mode) {
|
||||||
|
/* focus the text entry box */
|
||||||
|
gtk_widget_grab_focus(_query);
|
||||||
|
|
||||||
/* register a signal handler that will select the selection when it
|
/* register a signal handler that will select the selection when
|
||||||
arrives */
|
it arrives */
|
||||||
gtk_signal_connect_after(GTK_OBJECT(_query), "selection_received",
|
gtk_signal_connect_after(GTK_OBJECT(_query), "selection_received",
|
||||||
GTK_SIGNAL_FUNC(selection_received), NULL);
|
GTK_SIGNAL_FUNC(selection_received), NULL);
|
||||||
|
|
||||||
/* request the selection as type "STRING" */
|
/* request the selection as type "STRING" */
|
||||||
if (targets_atom == GDK_NONE) {
|
if (targets_atom == GDK_NONE) {
|
||||||
targets_atom = gdk_atom_intern ("STRING", FALSE);
|
targets_atom = gdk_atom_intern ("STRING", FALSE);
|
||||||
|
}
|
||||||
|
gtk_selection_convert(_query, GDK_SELECTION_PRIMARY, targets_atom,
|
||||||
|
GDK_CURRENT_TIME);
|
||||||
}
|
}
|
||||||
gtk_selection_convert(_query, GDK_SELECTION_PRIMARY, targets_atom,
|
|
||||||
GDK_CURRENT_TIME);
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user