Initial, incomplete, version of lookuplet.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@35 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
#
|
||||
# $Id: Makefile.am,v 1.1 2000/12/10 23:38:39 mdb Exp $
|
||||
|
||||
AUTOMAKE_OPTIONS = no-dependencies
|
||||
|
||||
INCLUDES = \
|
||||
$(GNOME_INCLUDEDIR)
|
||||
|
||||
bin_PROGRAMS = lookuplet
|
||||
bin_DIR = ../install.d/
|
||||
|
||||
lookuplet_SOURCES = \
|
||||
launcher.c \
|
||||
lookuplet.c \
|
||||
querybox.c
|
||||
|
||||
lookuplet_LDADD = \
|
||||
$(GNOME_LIBDIR) \
|
||||
$(GTK_LIBS) \
|
||||
$(GNOMEGNORBA_LIBS) \
|
||||
-lpanel_applet
|
||||
@@ -0,0 +1,192 @@
|
||||
/**
|
||||
* $Id: launcher.c,v 1.1 2000/12/10 23:38:39 mdb Exp $
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include <config.h>
|
||||
#include <glib.h>
|
||||
#include <gnome.h>
|
||||
|
||||
#include "launcher.h"
|
||||
|
||||
#define DEFAULT_QUERY "http://search.metacrawler.com/crawler?general=%U"
|
||||
|
||||
/**
|
||||
* This hashtable stores the mappings from qualifier keys to URL templates
|
||||
* for use when we launch a URL for a particular set of terms.
|
||||
*/
|
||||
static GHashTable* _qualmap;
|
||||
|
||||
/**
|
||||
* Removes and frees any previous entry registered with the supplied key
|
||||
* before inserting the new key/value pair.
|
||||
*/
|
||||
static void
|
||||
g_hash_table_insert_safe (GHashTable* table, gchar* key, gchar* value)
|
||||
{
|
||||
gpointer oldkey, oldvalue;
|
||||
|
||||
if (g_hash_table_lookup_extended(table, key, &oldkey, &oldvalue)) {
|
||||
g_free(oldkey);
|
||||
g_free(oldvalue);
|
||||
}
|
||||
|
||||
g_hash_table_insert(table, key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads up the mappings for the launcher from the configuration
|
||||
* repository.
|
||||
*/
|
||||
void
|
||||
lookuplet_launcher_init (void)
|
||||
{
|
||||
_qualmap = g_hash_table_new(g_str_hash, g_str_equal);
|
||||
|
||||
/* for now, just insert some bogus config parameters */
|
||||
g_hash_table_insert_safe(_qualmap,
|
||||
g_strdup("Ctrl-s"), g_strdup(DEFAULT_QUERY));
|
||||
}
|
||||
|
||||
static void
|
||||
free_table_entry (gpointer key, gpointer value, gpointer rock)
|
||||
{
|
||||
g_free(key);
|
||||
g_free(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Frees the mapping information used by the launcher.
|
||||
*/
|
||||
void
|
||||
lookuplet_launcher_cleanup (void)
|
||||
{
|
||||
g_hash_table_foreach(_qualmap, free_table_entry, NULL);
|
||||
g_hash_table_destroy(_qualmap);
|
||||
_qualmap = NULL;
|
||||
}
|
||||
|
||||
#define ESC_CHAR '%'
|
||||
|
||||
static const gchar*
|
||||
escape (gchar value)
|
||||
{
|
||||
static char buffer[] = "%xx";
|
||||
static char* xlate = "0123456789ABCDEF";
|
||||
buffer[0] = ESC_CHAR;
|
||||
buffer[1] = xlate[(value >> 4) & 0xF];
|
||||
buffer[2] = xlate[value & 0xF];
|
||||
return buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* URL encodes the supplied text. The result must be freed by the caller
|
||||
* using g_free().
|
||||
*/
|
||||
static gchar*
|
||||
url_encode (const gchar* text)
|
||||
{
|
||||
GString* result;
|
||||
guint tlen, i;
|
||||
gchar* retval;
|
||||
|
||||
tlen = strlen(text);
|
||||
result = g_string_sized_new(tlen);
|
||||
|
||||
for (i = 0; i < tlen; i++) {
|
||||
if (!isalnum(text[i]) || text[i] == ESC_CHAR) {
|
||||
g_string_append(result, escape(text[i]));
|
||||
} else {
|
||||
g_string_append_c(result, text[i]);
|
||||
}
|
||||
}
|
||||
|
||||
retval = result->str;
|
||||
g_string_free(result, FALSE);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces all instances of before with after in the supplied source
|
||||
* string.
|
||||
*
|
||||
* @return the number of replacements made.
|
||||
*/
|
||||
static
|
||||
guint g_string_replace (GString* source, const gchar* before,
|
||||
const gchar* after)
|
||||
{
|
||||
gchar* pos;
|
||||
gchar* spot;
|
||||
guint beflen = strlen(before);
|
||||
guint aftlen = strlen(after);
|
||||
guint replacements = 0;
|
||||
|
||||
/* sanity checks */
|
||||
g_return_val_if_fail(source != NULL, 0);
|
||||
g_return_val_if_fail(before != NULL, 0);
|
||||
g_return_val_if_fail(after != NULL, 0);
|
||||
g_return_val_if_fail(beflen > 0, 0);
|
||||
|
||||
pos = source->str;
|
||||
while ((spot = strstr(pos, before)) != NULL) {
|
||||
replacements++;
|
||||
/* erase the match and insert the new stuff */
|
||||
g_string_erase(source, spot-source->str, beflen);
|
||||
g_string_insert(source, spot-source->str, after);
|
||||
/* move the pointer on up */
|
||||
pos += spot-source->str + aftlen;
|
||||
}
|
||||
|
||||
return replacements;
|
||||
}
|
||||
|
||||
#define TOKEN_START '%'
|
||||
#define TERM_TOKEN 'T'
|
||||
#define ENCODED_TERM_TOKEN "U"
|
||||
|
||||
/**
|
||||
* Displays a URL with the supplied terms appropriately embedded. The URL
|
||||
* shown depends on the supplied qualifier. Each qualifier is mapped to a
|
||||
* particular URL into which the terms are substituted before loading.
|
||||
*
|
||||
* @return false if no qualifier mapping could be found for the supplied
|
||||
* qualifier.
|
||||
*/
|
||||
gboolean
|
||||
lookuplet_launcher_launch (const char* terms, const char* qualifier)
|
||||
{
|
||||
gchar* uterms;
|
||||
gchar* template;
|
||||
|
||||
uterms = url_encode(terms);
|
||||
|
||||
/* if no qualifier was supplied, we use the default template;
|
||||
* otherwise we get the template from the mapping table */
|
||||
if (qualifier == NULL) {
|
||||
template = DEFAULT_QUERY;
|
||||
} else {
|
||||
template = g_hash_table_lookup(_qualmap, qualifier);
|
||||
}
|
||||
|
||||
/* if we found a template, construct the actual URL from it by
|
||||
* replacing instances of %T with the terms and %U with the URL
|
||||
* encoded terms. */
|
||||
if (template != NULL) {
|
||||
GString* url = g_string_new(template);
|
||||
/* first replace %U because we know that won't result in any '%T's
|
||||
* being inserted into the string because the url encoded terms
|
||||
* encode all %s */
|
||||
g_string_replace(url, "%U", uterms);
|
||||
g_string_replace(url, "%T", terms);
|
||||
gnome_url_show(url->str);
|
||||
g_string_free(url, TRUE);
|
||||
}
|
||||
|
||||
g_free(uterms);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* $Id: launcher.h,v 1.1 2000/12/10 23:38:39 mdb Exp $
|
||||
*/
|
||||
|
||||
#ifndef _LAUNCHER_H_
|
||||
#define _LAUNCHER_H_
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
extern void
|
||||
lookuplet_launcher_init (void);
|
||||
|
||||
extern void
|
||||
lookuplet_launcher_cleanup (void);
|
||||
|
||||
extern gboolean
|
||||
lookuplet_launcher_launch (const char* terms, const char* qualifier);
|
||||
|
||||
#endif /* _LAUNCHER_H_ */
|
||||
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
* $Id: lookuplet.c,v 1.1 2000/12/10 23:38:39 mdb Exp $
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <gnome.h>
|
||||
#include <applet-widget.h>
|
||||
|
||||
#include "querybox.h"
|
||||
|
||||
int
|
||||
main (int argc, char** argv)
|
||||
{
|
||||
GtkWidget* applet;
|
||||
GtkWidget* contents;
|
||||
|
||||
/* initialize the i18n stuff */
|
||||
bindtextdomain(PACKAGE, GNOMELOCALEDIR);
|
||||
textdomain(PACKAGE);
|
||||
|
||||
/* intialize, this will basically set up the applet, corba and
|
||||
call gnome_init */
|
||||
applet_widget_init("lookuplet", NULL, argc, argv, NULL, 0, NULL);
|
||||
|
||||
/* create a new applet_widget */
|
||||
applet = applet_widget_new("lookuplet");
|
||||
if (applet == NULL) {
|
||||
g_error("Can't create applet!\n");
|
||||
}
|
||||
|
||||
/* create our contents and set them up real proper like */
|
||||
contents = lookuplet_querybox_create();
|
||||
applet_widget_add(APPLET_WIDGET(applet), contents);
|
||||
gtk_widget_show(contents);
|
||||
gtk_widget_show(applet);
|
||||
|
||||
/* special corba main loop */
|
||||
applet_widget_gtk_main();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* $Id: querybox.c,v 1.1 2000/12/10 23:38:39 mdb Exp $
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include <glib.h>
|
||||
#include <gnome.h>
|
||||
|
||||
#include "launcher.h"
|
||||
#include "querybox.h"
|
||||
|
||||
#define BORDER 1
|
||||
#define SPACER 2
|
||||
|
||||
static void
|
||||
launch (GtkWidget* widget, gpointer data)
|
||||
{
|
||||
gchar* search_text = gtk_entry_get_text(GTK_ENTRY(widget));
|
||||
|
||||
/* pass the contents of the querybox on to the launcher for display
|
||||
* (specifying NULL for the qualifier since they just pressed return
|
||||
* instead of pressing some special key combination) */
|
||||
lookuplet_launcher_launch(search_text, NULL);
|
||||
|
||||
/* clear out the contents of the entry box */
|
||||
gtk_entry_set_text(GTK_ENTRY(widget), "");
|
||||
}
|
||||
|
||||
GtkWidget*
|
||||
lookuplet_querybox_create ()
|
||||
{
|
||||
GtkWidget* vbox;
|
||||
GtkWidget* label;
|
||||
GtkWidget* query;
|
||||
|
||||
/* create the widget we are going to put on the applet */
|
||||
label = gtk_label_new(_("Query"));
|
||||
gtk_widget_show(label);
|
||||
|
||||
/* make the query text box and attach the "activate" signal handler */
|
||||
query = gtk_entry_new();
|
||||
|
||||
/* Connect "return" in the search box to the launch func. */
|
||||
gtk_signal_connect(GTK_OBJECT(query), "activate",
|
||||
GTK_SIGNAL_FUNC(launch), NULL);
|
||||
|
||||
/* create a vertical box to hold our query input box and the label */
|
||||
vbox = gtk_hbox_new(FALSE, SPACER);
|
||||
|
||||
/* pack the query box and label into the vbox */
|
||||
gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, SPACER);
|
||||
gtk_box_pack_start(GTK_BOX(vbox), query, FALSE, FALSE, SPACER);
|
||||
|
||||
gtk_widget_show(query);
|
||||
gtk_widget_show(label);
|
||||
|
||||
return vbox;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* $Id: querybox.h,v 1.1 2000/12/10 23:38:39 mdb Exp $
|
||||
*/
|
||||
|
||||
#ifndef _QUERYBOX_H_
|
||||
#define _QUERYBOX_H_
|
||||
|
||||
extern GtkWidget*
|
||||
lookuplet_querybox_create (void);
|
||||
|
||||
#endif /* _QUERYBOX_H_ */
|
||||
@@ -0,0 +1,103 @@
|
||||
/* XPM */
|
||||
static char * paw_small_xpm[] = {
|
||||
"14 18 82 1",
|
||||
" c None",
|
||||
". c #FEFEFE",
|
||||
"+ c #FDFDFD",
|
||||
"@ c #A4A4A4",
|
||||
"# c #BEBEBE",
|
||||
"$ c #E3E3E3",
|
||||
"% c #767676",
|
||||
"& c #FFFFFF",
|
||||
"* c #858585",
|
||||
"= c #5E5E5E",
|
||||
"- c #E0E0E0",
|
||||
"; c #9E9E9E",
|
||||
"> c #292929",
|
||||
", c #0D0D0D",
|
||||
"' c #000000",
|
||||
") c #2E2E2E",
|
||||
"! c #DDDDDD",
|
||||
"~ c #181818",
|
||||
"{ c #717171",
|
||||
"] c #F6F6F6",
|
||||
"^ c #909090",
|
||||
"/ c #777777",
|
||||
"( c #131313",
|
||||
"_ c #F9F9F9",
|
||||
": c #D1D1D1",
|
||||
"< c #B8B8B8",
|
||||
"[ c #555555",
|
||||
"} c #414141",
|
||||
"| c #878787",
|
||||
"1 c #DADADA",
|
||||
"2 c #808080",
|
||||
"3 c #757575",
|
||||
"4 c #464646",
|
||||
"5 c #222222",
|
||||
"6 c #B4B4B4",
|
||||
"7 c #212121",
|
||||
"8 c #151515",
|
||||
"9 c #D9D9D9",
|
||||
"0 c #9A9A9A",
|
||||
"a c #656565",
|
||||
"b c #303030",
|
||||
"c c #0C0C0C",
|
||||
"d c #0F0F0F",
|
||||
"e c #BFBFBF",
|
||||
"f c #1B1B1B",
|
||||
"g c #7A7A7A",
|
||||
"h c #4B4B4B",
|
||||
"i c #010101",
|
||||
"j c #8B8B8B",
|
||||
"k c #BABABA",
|
||||
"l c #F0F0F0",
|
||||
"m c #F5F5F5",
|
||||
"n c #929292",
|
||||
"o c #3D3D3D",
|
||||
"p c #3B3B3B",
|
||||
"q c #444444",
|
||||
"r c #AEAEAE",
|
||||
"s c #3E3E3E",
|
||||
"t c #737373",
|
||||
"u c #4D4D4D",
|
||||
"v c #969696",
|
||||
"w c #B5B5B5",
|
||||
"x c #070707",
|
||||
"y c #030303",
|
||||
"z c #CCCCCC",
|
||||
"A c #BBBBBB",
|
||||
"B c #DEDEDE",
|
||||
"C c #161616",
|
||||
"D c #060606",
|
||||
"E c #C3C3C3",
|
||||
"F c #CECECE",
|
||||
"G c #FBFBFB",
|
||||
"H c #A8A8A8",
|
||||
"I c #CDCDCD",
|
||||
"J c #373737",
|
||||
"K c #454545",
|
||||
"L c #DFDFDF",
|
||||
"M c #AAAAAA",
|
||||
"N c #7F7F7F",
|
||||
"O c #FCFCFC",
|
||||
"P c #5A5A5A",
|
||||
"Q c #EBEBEB",
|
||||
" + @ ",
|
||||
" #$ % ",
|
||||
" *=- ;>$ ",
|
||||
" -,')!~'{ ",
|
||||
"] ^'''/''(_ : ",
|
||||
"<$['''}'''] | ",
|
||||
"123'''4''56789",
|
||||
"0'ab'(-cdef''g",
|
||||
"h'ijkl m-n'''o",
|
||||
"p''q rs%&t'''o",
|
||||
"u''vwx'y0z)''0",
|
||||
"AybBC'''DE+FFG",
|
||||
" HIJ'''''K ",
|
||||
" w'''''''L ",
|
||||
" ^'''''''* ",
|
||||
" M'''''''N ",
|
||||
" OP''''''N ",
|
||||
" GtssssaQ "};
|
||||
Executable
+7
@@ -0,0 +1,7 @@
|
||||
[Desktop Entry]
|
||||
Name=Lookuplet
|
||||
Comment=Look things up on the web and elsewhere
|
||||
Exec=lookuplet --activate-goad-server=lookuplet
|
||||
Icon=lookuplet.xpm
|
||||
Terminal=0
|
||||
Type=Application
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
[lookuplet]
|
||||
type=exe
|
||||
repo_id=IDL:GNOME/Applet:1.0
|
||||
description=Looks things up on the web and elsewhere
|
||||
location_info=lookuplet
|
||||
Reference in New Issue
Block a user