-
Notifications
You must be signed in to change notification settings - Fork 0
/
pastesend.c
111 lines (88 loc) · 2.91 KB
/
pastesend.c
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#define PURPLE_PLUGINS
#include <glib.h>
#include "notify.h"
#include "plugin.h"
#include "version.h"
#include "gtkconv.h"
#include "gtkplugin.h"
PurplePlugin *pastesend_plugin = NULL;
static void paste_and_send(GtkWidget *menu_entry, PidginConversation *gtkconv)
{
g_return_if_fail(gtkconv != NULL);
GtkClipboard *clipboard = gtk_clipboard_get(GDK_SELECTION_CLIPBOARD);
gtk_text_buffer_paste_clipboard(gtkconv->entry_buffer, clipboard, NULL, TRUE);
g_signal_emit_by_name(gtkconv->entry, "message_send");
}
static void right_click_popup(GtkTextView *text_view, GtkMenu *menu, PidginConversation *gtkconv)
{
GtkWidget *menu_entry = gtk_menu_item_new_with_label("Paste & Send");
gtk_widget_set_tooltip_text(menu_entry, "Pastes the current clipboard text and presses \"send\".");
gtk_menu_insert(GTK_MENU(menu), menu_entry, 1);
g_signal_connect(G_OBJECT(menu_entry), "activate", G_CALLBACK(paste_and_send), gtkconv);
gtk_widget_show(menu_entry);
}
static void attach_to_conversation(PurpleConversation *conv)
{
PidginConversation *gtkconv = PIDGIN_CONVERSATION(conv);
GtkTextView *view = GTK_TEXT_VIEW(gtkconv->entry);
g_signal_connect(G_OBJECT(view), "populate-popup", G_CALLBACK(right_click_popup), gtkconv);
}
static void detach_from_conversation(PurpleConversation *conv)
{
PidginConversation *gtkconv = PIDGIN_CONVERSATION(conv);
GtkTextView *view = GTK_TEXT_VIEW(gtkconv->entry);
g_signal_handlers_disconnect_matched(G_OBJECT(view), G_SIGNAL_MATCH_FUNC, 0, 0, NULL, G_CALLBACK(right_click_popup), NULL);
}
static gboolean plugin_load(PurplePlugin *plugin)
{
pastesend_plugin = plugin;
GList *convs;
for (convs = purple_get_conversations(); convs != NULL; convs = convs->next) {
attach_to_conversation((PurpleConversation *)convs->data);
}
void *conv_handle = purple_conversations_get_handle();
purple_signal_connect(conv_handle, "conversation-created", plugin, PURPLE_CALLBACK(attach_to_conversation), NULL);
return TRUE;
}
static gboolean plugin_unload(PurplePlugin *plugin)
{
GList *convs;
for (convs = purple_get_conversations(); convs != NULL; convs = convs->next) {
PurpleConversation *conv = (PurpleConversation *)convs->data;
if(PIDGIN_IS_PIDGIN_CONVERSATION(conv)) {
detach_from_conversation(conv);
}
}
return TRUE;
}
static PurplePluginInfo info = {
PURPLE_PLUGIN_MAGIC,
PURPLE_MAJOR_VERSION,
PURPLE_MINOR_VERSION,
PURPLE_PLUGIN_STANDARD,
NULL,
0,
NULL,
PURPLE_PRIORITY_DEFAULT,
"core-Paste_Send",
"Paste & Send",
"1.0",
"Paste & Send Plugin",
"Paste & Send Plugin",
"4lab group",
"https://github.com/4lab",
plugin_load,
plugin_unload,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL
};
static void init_plugin(PurplePlugin *plugin)
{ }
PURPLE_INIT_PLUGIN(Paste_Send, init_plugin, info)