Changed from a GNOME applet to a standalone application. Finished the
implementation of various things. git-svn-id: https://samskivert.googlecode.com/svn/trunk@53 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* $Id: launcher.c,v 1.1 2000/12/10 23:38:39 mdb Exp $
|
||||
* $Id: launcher.c,v 1.2 2001/02/24 02:35:20 mdb Exp $
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
@@ -11,62 +11,8 @@
|
||||
|
||||
#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 DEFAULT_COMMAND "%T"
|
||||
#define DEFAULT_TYPE URL
|
||||
|
||||
#define ESC_CHAR '%'
|
||||
|
||||
@@ -157,36 +103,47 @@ guint g_string_replace (GString* source, const gchar* before,
|
||||
* qualifier.
|
||||
*/
|
||||
gboolean
|
||||
lookuplet_launcher_launch (const char* terms, const char* qualifier)
|
||||
lk_launcher_launch (const LkBinding* binding, const gchar* terms)
|
||||
{
|
||||
gchar* uterms;
|
||||
gchar* template;
|
||||
char cwdbuf[1024];
|
||||
GString* cmd;
|
||||
gchar* uterms, *command;
|
||||
LkBindingType type;
|
||||
|
||||
uterms = url_encode(terms);
|
||||
/* figure out what we're supposed to do */
|
||||
if (binding == NULL) {
|
||||
command = DEFAULT_COMMAND;
|
||||
type = DEFAULT_TYPE;
|
||||
|
||||
/* 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);
|
||||
command = binding->argument;
|
||||
type = binding->type;
|
||||
}
|
||||
|
||||
/* construct the actual command from it by replacing instances of %T
|
||||
* with the terms and %U with the URL encoded terms. */
|
||||
cmd = g_string_new(command);
|
||||
/* 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 */
|
||||
uterms = url_encode(terms);
|
||||
g_string_replace(cmd, "%U", uterms);
|
||||
g_free(uterms);
|
||||
g_string_replace(cmd, "%T", terms);
|
||||
|
||||
/* now we either invoke a program or launch a URL */
|
||||
switch (type) {
|
||||
case EXEC:
|
||||
gnome_execute_shell(getcwd(cwdbuf, 1024), cmd->str);
|
||||
break;
|
||||
|
||||
default:
|
||||
case URL:
|
||||
gnome_url_show(cmd->str);
|
||||
break;
|
||||
}
|
||||
|
||||
g_string_free(cmd, TRUE);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user