pidgin/gtkeventloop.c

Tue, 24 Nov 2015 23:16:45 -0800

author
Jorge Villaseñor <salinasv@pidgin.im>
date
Tue, 24 Nov 2015 23:16:45 -0800
changeset 37398
a9aa2aa0b1b6
parent 35859
3d157ce203ed
child 38352
7b6c89006e93
permissions
-rw-r--r--

Replace magic numbers on the sound API

Added an enum for the enable sound preference.
Added sound.c on the list to convert them to GEnums

20147
66f05a854eee applied changes from 8a731bbd0197fbcc91a705c2d8f528154216defa
Richard Laager <rlaager@pidgin.im>
parents: 19859
diff changeset
1 /* pidgin
8273
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
2 *
15931
716b5fac1895 Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@pidgin.im>
parents: 15884
diff changeset
3 * Pidgin is the legal property of its developers, whose names are too numerous
8273
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
4 * to list here. Please refer to the COPYRIGHT file distributed with this
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
5 * source distribution.
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
6 *
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
7 * This program is free software; you can redistribute it and/or modify
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
8 * it under the terms of the GNU General Public License as published by
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
10 * (at your option) any later version.
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
11 *
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful,
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
15 * GNU General Public License for more details.
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
16 *
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
18 * along with this program; if not, write to the Free Software
19859
71d37b57eff2 The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 18075
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
8273
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
20 */
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
21
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
22 #include <glib.h>
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
23 #include "gtkeventloop.h"
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
24 #include "eventloop.h"
35856
1777950ff49f cross-win32: fix pidgin code warnings and errors
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35454
diff changeset
25 #include "internal.h"
8273
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
26
15562
8c8249fe5e3c gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
27 #define PIDGIN_READ_COND (G_IO_IN | G_IO_HUP | G_IO_ERR)
8c8249fe5e3c gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
28 #define PIDGIN_WRITE_COND (G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL)
8273
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
29
15562
8c8249fe5e3c gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
30 typedef struct _PidginIOClosure {
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15746
diff changeset
31 PurpleInputFunction function;
8273
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
32 guint result;
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
33 gpointer data;
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
34
15562
8c8249fe5e3c gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
35 } PidginIOClosure;
8273
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
36
15562
8c8249fe5e3c gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
37 static gboolean pidgin_io_invoke(GIOChannel *source, GIOCondition condition, gpointer data)
8273
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
38 {
15562
8c8249fe5e3c gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
39 PidginIOClosure *closure = data;
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15746
diff changeset
40 PurpleInputCondition purple_cond = 0;
8273
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
41
15562
8c8249fe5e3c gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
42 if (condition & PIDGIN_READ_COND)
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15746
diff changeset
43 purple_cond |= PURPLE_INPUT_READ;
15562
8c8249fe5e3c gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
44 if (condition & PIDGIN_WRITE_COND)
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15746
diff changeset
45 purple_cond |= PURPLE_INPUT_WRITE;
8273
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
46
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
47 #if 0
29990
198caf410219 Why create a wrapper function when you can use g_free directly?
Mark Doliner <markdoliner@pidgin.im>
parents: 23119
diff changeset
48 purple_debug_misc("gtk_eventloop",
8273
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
49 "CLOSURE: callback for %d, fd is %d\n",
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
50 closure->result, g_io_channel_unix_get_fd(source));
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
51 #endif
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
52
11065
895342350443 [gaim-migrate @ 13046]
Christopher O'Brien <siege@pidgin.im>
parents: 8807
diff changeset
53 #ifdef _WIN32
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15746
diff changeset
54 if(! purple_cond) {
35859
3d157ce203ed cross-win32: make libpidgin and libfinch shared, disable hacky libpidgin loading code. Pidgin runs now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents: 35856
diff changeset
55 #if 0
29995
67edb2e8330d Fix typo, fix compile (on windows).
Sadrul Habib Chowdhury <sadrul@pidgin.im>
parents: 29990
diff changeset
56 purple_debug_misc("gtk_eventloop",
11065
895342350443 [gaim-migrate @ 13046]
Christopher O'Brien <siege@pidgin.im>
parents: 8807
diff changeset
57 "CLOSURE received GIOCondition of 0x%x, which does not"
895342350443 [gaim-migrate @ 13046]
Christopher O'Brien <siege@pidgin.im>
parents: 8807
diff changeset
58 " match 0x%x (READ) or 0x%x (WRITE)\n",
15562
8c8249fe5e3c gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
59 condition, PIDGIN_READ_COND, PIDGIN_WRITE_COND);
11065
895342350443 [gaim-migrate @ 13046]
Christopher O'Brien <siege@pidgin.im>
parents: 8807
diff changeset
60 #endif /* DEBUG */
895342350443 [gaim-migrate @ 13046]
Christopher O'Brien <siege@pidgin.im>
parents: 8807
diff changeset
61
895342350443 [gaim-migrate @ 13046]
Christopher O'Brien <siege@pidgin.im>
parents: 8807
diff changeset
62 return TRUE;
895342350443 [gaim-migrate @ 13046]
Christopher O'Brien <siege@pidgin.im>
parents: 8807
diff changeset
63 }
895342350443 [gaim-migrate @ 13046]
Christopher O'Brien <siege@pidgin.im>
parents: 8807
diff changeset
64 #endif /* _WIN32 */
895342350443 [gaim-migrate @ 13046]
Christopher O'Brien <siege@pidgin.im>
parents: 8807
diff changeset
65
895342350443 [gaim-migrate @ 13046]
Christopher O'Brien <siege@pidgin.im>
parents: 8807
diff changeset
66 closure->function(closure->data, g_io_channel_unix_get_fd(source),
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15746
diff changeset
67 purple_cond);
8273
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
68
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
69 return TRUE;
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
70 }
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
71
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15746
diff changeset
72 static guint pidgin_input_add(gint fd, PurpleInputCondition condition, PurpleInputFunction function,
8273
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
73 gpointer data)
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
74 {
15562
8c8249fe5e3c gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
75 PidginIOClosure *closure = g_new0(PidginIOClosure, 1);
8273
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
76 GIOChannel *channel;
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
77 GIOCondition cond = 0;
23119
2f1afd977845 Add the ability on win32 to choose at runtime whether we use the GIOChannel
Daniel Atallah <datallah@pidgin.im>
parents: 20147
diff changeset
78 #ifdef _WIN32
2f1afd977845 Add the ability on win32 to choose at runtime whether we use the GIOChannel
Daniel Atallah <datallah@pidgin.im>
parents: 20147
diff changeset
79 static int use_glib_io_channel = -1;
2f1afd977845 Add the ability on win32 to choose at runtime whether we use the GIOChannel
Daniel Atallah <datallah@pidgin.im>
parents: 20147
diff changeset
80
2f1afd977845 Add the ability on win32 to choose at runtime whether we use the GIOChannel
Daniel Atallah <datallah@pidgin.im>
parents: 20147
diff changeset
81 if (use_glib_io_channel == -1)
2f1afd977845 Add the ability on win32 to choose at runtime whether we use the GIOChannel
Daniel Atallah <datallah@pidgin.im>
parents: 20147
diff changeset
82 use_glib_io_channel = (g_getenv("PIDGIN_GLIB_IO_CHANNEL") != NULL) ? 1 : 0;
2f1afd977845 Add the ability on win32 to choose at runtime whether we use the GIOChannel
Daniel Atallah <datallah@pidgin.im>
parents: 20147
diff changeset
83 #endif
8273
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
84
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
85 closure->function = function;
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
86 closure->data = data;
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
87
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15746
diff changeset
88 if (condition & PURPLE_INPUT_READ)
15562
8c8249fe5e3c gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
89 cond |= PIDGIN_READ_COND;
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15746
diff changeset
90 if (condition & PURPLE_INPUT_WRITE)
15562
8c8249fe5e3c gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
91 cond |= PIDGIN_WRITE_COND;
8273
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
92
14792
02a5df4343f7 [gaim-migrate @ 17486]
Daniel Atallah <datallah@pidgin.im>
parents: 14253
diff changeset
93 #ifdef _WIN32
23119
2f1afd977845 Add the ability on win32 to choose at runtime whether we use the GIOChannel
Daniel Atallah <datallah@pidgin.im>
parents: 20147
diff changeset
94 if (use_glib_io_channel == 0)
2f1afd977845 Add the ability on win32 to choose at runtime whether we use the GIOChannel
Daniel Atallah <datallah@pidgin.im>
parents: 20147
diff changeset
95 channel = wpurple_g_io_channel_win32_new_socket(fd);
2f1afd977845 Add the ability on win32 to choose at runtime whether we use the GIOChannel
Daniel Atallah <datallah@pidgin.im>
parents: 20147
diff changeset
96 else
2f1afd977845 Add the ability on win32 to choose at runtime whether we use the GIOChannel
Daniel Atallah <datallah@pidgin.im>
parents: 20147
diff changeset
97 #endif
8280
f448633d3f3a [gaim-migrate @ 9004]
Scott Lamb
parents: 8273
diff changeset
98 channel = g_io_channel_unix_new(fd);
23119
2f1afd977845 Add the ability on win32 to choose at runtime whether we use the GIOChannel
Daniel Atallah <datallah@pidgin.im>
parents: 20147
diff changeset
99
8273
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
100 closure->result = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT, cond,
29990
198caf410219 Why create a wrapper function when you can use g_free directly?
Mark Doliner <markdoliner@pidgin.im>
parents: 23119
diff changeset
101 pidgin_io_invoke, closure, g_free);
8273
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
102
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
103 #if 0
29990
198caf410219 Why create a wrapper function when you can use g_free directly?
Mark Doliner <markdoliner@pidgin.im>
parents: 23119
diff changeset
104 purple_debug_misc("gtk_eventloop",
8273
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
105 "CLOSURE: adding input watcher %d for fd %d\n",
8280
f448633d3f3a [gaim-migrate @ 9004]
Scott Lamb
parents: 8273
diff changeset
106 closure->result, fd);
8273
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
107 #endif
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
108
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
109 g_io_channel_unref(channel);
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
110 return closure->result;
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
111 }
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
112
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15746
diff changeset
113 static PurpleEventLoopUiOps eventloop_ops =
8273
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
114 {
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
115 g_timeout_add,
15729
6932ac4e5b3d Change out source_remove and input_remove eventloop functions to return
Mark Doliner <markdoliner@pidgin.im>
parents: 15697
diff changeset
116 g_source_remove,
15562
8c8249fe5e3c gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
117 pidgin_input_add,
15746
017e33725857 Added a new GaimEventLoopUiOps item, input_get_error(). This function allows the UI to return the current error status on a socket/input. If the UI does not implement it (as Pidgin and gntgaim do not, since glib's handling of sockets is sane), it is just a wrapper around getsockopt(). Implemented or not, its return values should match those of getsockopt() with a level of SOL_SOCKET and an option of SO_ERROR. For curious souls, Adium will be using this to provide a working version of getsockopt(); the CoreFoundation CFSocket class which is used for socket read/write calls getsockopt() with SO_ERROR itself, thereby clearing the error flag [as documented in getsockopt()'s behavior], so depending upon it for determining if an error occurred leads to significant misbehavior.
Evan Schoenberg <evands@pidgin.im>
parents: 15729
diff changeset
118 g_source_remove,
16752
e6bcb1628c57 Patch from John 'rekkanoryo' Bailey to add the padding struct members in pidgin
Gary Kramlich <grim@reaperworld.com>
parents: 16254
diff changeset
119 NULL, /* input_get_error */
18070
79c7fe0d8e4b Wire everything up and document it.
Richard Laager <rlaager@pidgin.im>
parents: 18068
diff changeset
120 g_timeout_add_seconds,
16752
e6bcb1628c57 Patch from John 'rekkanoryo' Bailey to add the padding struct members in pidgin
Gary Kramlich <grim@reaperworld.com>
parents: 16254
diff changeset
121 NULL,
e6bcb1628c57 Patch from John 'rekkanoryo' Bailey to add the padding struct members in pidgin
Gary Kramlich <grim@reaperworld.com>
parents: 16254
diff changeset
122 NULL,
35024
eb3afb7643ce Added /*< private >*/ for padding members, clean them up and add missing ones
Ankit Vani <a@nevitus.org>
parents: 33587
diff changeset
123 NULL,
16752
e6bcb1628c57 Patch from John 'rekkanoryo' Bailey to add the padding struct members in pidgin
Gary Kramlich <grim@reaperworld.com>
parents: 16254
diff changeset
124 NULL
8273
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
125 };
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
126
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15746
diff changeset
127 PurpleEventLoopUiOps *
15562
8c8249fe5e3c gaim_gtk to pidgin. I hope
Sean Egan <seanegan@pidgin.im>
parents: 15435
diff changeset
128 pidgin_eventloop_get_ui_ops(void)
8273
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
129 {
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
130 return &eventloop_ops;
7882af5843e9 [gaim-migrate @ 8997]
Scott Lamb
parents:
diff changeset
131 }

mercurial