diff options
author | Not Zed <NotZed@Ximian.com> | 2004-10-21 16:39:32 +0800 |
---|---|---|
committer | Michael Zucci <zucchi@src.gnome.org> | 2004-10-21 16:39:32 +0800 |
commit | afd12780109f1c42fcfcb232a2b4803cc3cb5ca2 (patch) | |
tree | 20814b8c734e03716487b5de2c127b2c5b9c7340 /plugins/copy-tool/copy-tool.c | |
parent | 76f723f9d0e1d6590d09e89c90a520cb010784a1 (diff) | |
download | gsoc2013-evolution-afd12780109f1c42fcfcb232a2b4803cc3cb5ca2.tar gsoc2013-evolution-afd12780109f1c42fcfcb232a2b4803cc3cb5ca2.tar.gz gsoc2013-evolution-afd12780109f1c42fcfcb232a2b4803cc3cb5ca2.tar.bz2 gsoc2013-evolution-afd12780109f1c42fcfcb232a2b4803cc3cb5ca2.tar.lz gsoc2013-evolution-afd12780109f1c42fcfcb232a2b4803cc3cb5ca2.tar.xz gsoc2013-evolution-afd12780109f1c42fcfcb232a2b4803cc3cb5ca2.tar.zst gsoc2013-evolution-afd12780109f1c42fcfcb232a2b4803cc3cb5ca2.zip |
implemented a copy-utils plugin.
2004-10-20 Not Zed <NotZed@Ximian.com>
* implemented a copy-utils plugin.
svn path=/trunk/; revision=27671
Diffstat (limited to 'plugins/copy-tool/copy-tool.c')
-rw-r--r-- | plugins/copy-tool/copy-tool.c | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/plugins/copy-tool/copy-tool.c b/plugins/copy-tool/copy-tool.c new file mode 100644 index 0000000000..5571ba25c1 --- /dev/null +++ b/plugins/copy-tool/copy-tool.c @@ -0,0 +1,100 @@ + +/* Copyright (C) 2004 Michael Zucchi */ + +/* This file is licensed under the GNU GPL v2 or later */ + +/* Add 'copy to clipboard' things to various menu's. + + Uh, so far only to copy mail addresses from mail content */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <glib/gi18n-lib.h> +#include <string.h> +#include <stdio.h> + +#include "mail/em-popup.h" + +#include <gtk/gtkmain.h> +#include <gtk/gtkinvisible.h> +#include <gtk/gtkselection.h> + +#include "camel/camel-internet-address.h" +#include "camel/camel-url.h" + +static GtkWidget *invisible; +static char *address_uri; + +void org_gnome_copy_tool_copy_address(void *ep, EMPopupTargetURI *t); + +void +org_gnome_copy_tool_copy_address(void *ep, EMPopupTargetURI *t) +{ + g_free(address_uri); + address_uri = g_strdup(t->uri); + + printf("copying address '%s'\n", address_uri); + + gtk_selection_owner_set(invisible, GDK_SELECTION_PRIMARY, gtk_get_current_event_time()); + gtk_selection_owner_set(invisible, GDK_SELECTION_CLIPBOARD, gtk_get_current_event_time()); +} + +static void +ct_selection_get(GtkWidget *widget, GtkSelectionData *data, guint info, guint time_stamp, void *dummy) +{ + printf("get selection, address is '%s'\n", address_uri); + + if (address_uri == NULL) + return; + + if (strncmp (address_uri, "mailto:", 7) == 0) { + CamelInternetAddress *cia = camel_internet_address_new(); + CamelURL *curl; + char *addr; + const char *tmp; + + curl = camel_url_new(address_uri, NULL); + camel_address_decode((CamelAddress *)cia, curl->path); + /* should it perhaps use address format? */ + addr = camel_address_encode((CamelAddress *)cia); + tmp = addr && addr[0] ? addr : address_uri + 7; + printf("get selection, setting to' %s'\n", tmp); + + gtk_selection_data_set(data, data->target, 8, tmp, strlen(tmp)); + g_free(addr); + camel_url_free(curl); + camel_object_unref(cia); + } +} + +static void +ct_selection_clear_event(GtkWidget *widget, GdkEventSelection *event, void *dummy) +{ + printf("selection clear event\n"); + + g_free(address_uri); + address_uri = NULL; +} + +int e_plugin_lib_enable(EPluginLib *ep, int enable); + +int +e_plugin_lib_enable(EPluginLib *ep, int enable) +{ + if (enable) { + invisible = gtk_invisible_new(); + g_signal_connect(invisible, "selection_get", G_CALLBACK(ct_selection_get), NULL); + g_signal_connect(invisible, "selection_clear_event", G_CALLBACK(ct_selection_clear_event), NULL); + gtk_selection_add_target(invisible, GDK_SELECTION_PRIMARY, GDK_SELECTION_TYPE_STRING, 0); + gtk_selection_add_target(invisible, GDK_SELECTION_CLIPBOARD, GDK_SELECTION_TYPE_STRING, 1); + } else { + g_free(address_uri); + address_uri = NULL; + gtk_widget_destroy(invisible); + invisible = NULL; + } + + return 0; +} |