aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/copy-tool/copy-tool.c
blob: 052722f4eb7c5d2de6cdd480e35efc2d2e3bf819 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) version 3.
 *
 * 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with the program; if not, see <http://www.gnu.org/licenses/>  
 *
 *
 * Authors:
 *      Michael Zucchi <notzed@novell.com>
 *
 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 *
 */

/* 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 "mail/em-popup.h"

#include <gtk/gtk.h>

#include "camel/camel-internet-address.h"
#include "camel/camel-url.h"

void org_gnome_copy_tool_copy_address(void *ep, EMPopupTargetURI *t);

void
org_gnome_copy_tool_copy_address(void *ep, EMPopupTargetURI *t)
{
    if  (t->uri) {
        CamelInternetAddress *cia = camel_internet_address_new();
        CamelURL *curl;
        GtkClipboard *clipboard;
        char *addr;
        const char *tmp;

        curl = camel_url_new(t->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 : t->uri + 7;

        clipboard = gtk_clipboard_get (GDK_SELECTION_PRIMARY);

        gtk_clipboard_set_text (clipboard, tmp, strlen (tmp));

        clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
        gtk_clipboard_set_text (clipboard, tmp, strlen (tmp));

        g_free(addr);
        camel_url_free(curl);
        camel_object_unref(cia);
    }
}