Conversation class implementation
[python-purple] / core / conversation.pxd
1 #
2 #  Copyright (c) 2008 INdT - Instituto Nokia de Tecnologia
3 #
4 #  This file is part of python-purple.
5 #
6 #  python-purple is free software: you can redistribute it and/or modify
7 #  it under the terms of the GNU General Public License as published by
8 #  the Free Software Foundation, either version 3 of the License, or
9 #  (at your option) any later version.
10 #
11 #  python-purple is distributed in the hope that it will be useful,
12 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 #  GNU General Public License for more details.
15 #
16 #  You should have received a copy of the GNU General Public License
17 #  along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 #
19
20 cdef extern from "libpurple/conversation.h":
21     ctypedef struct PurpleConversation:
22         pass
23
24     ctypedef struct PurpleConvIm:
25         pass
26
27     ctypedef enum PurpleMessageFlags:
28         PURPLE_MESSAGE_SEND = 0x0001
29         PURPLE_MESSAGE_RECV = 0x0002
30         PURPLE_MESSAGE_SYSTEM = 0x0004
31         PURPLE_MESSAGE_AUTO_RESP = 0x0008
32         PURPLE_MESSAGE_ACTIVE_ONLY = 0x0010
33         PURPLE_MESSAGE_NICK = 0x0020
34         PURPLE_MESSAGE_NO_LOG = 0x0040
35         PURPLE_MESSAGE_WHISPER = 0x0080
36         PURPLE_MESSAGE_ERROR = 0x0200
37         PURPLE_MESSAGE_DELAYED = 0x0400
38         PURPLE_MESSAGE_RAW = 0x0800
39         PURPLE_MESSAGE_IMAGES = 0x1000
40         PURPLE_MESSAGE_NOTIFY = 0x2000
41         PURPLE_MESSAGE_NO_LINKIFY = 0x4000
42         PURPLE_MESSAGE_INVISIBLE = 0x8000
43
44     ctypedef struct PurpleConversationUiOps:
45         void (*create_conversation) (PurpleConversation *conv)
46         void (*destroy_conversation) (PurpleConversation *conv)
47         void (*write_chat) (PurpleConversation *conv, const_char_ptr who, const_char_ptr message, PurpleMessageFlags flags, time_t mtime)
48         void (*write_im) (PurpleConversation *conv, const_char_ptr who, const_char_ptr message, PurpleMessageFlags flags, time_t mtime)
49         void (*write_conv) (PurpleConversation *conv, const_char_ptr name, const_char_ptr alias, const_char_ptr message, PurpleMessageFlags flags, time_t mtime)
50         void (*chat_add_users) (PurpleConversation *conv, GList *cbuddies, gboolean new_arrivals)
51         void (*chat_rename_user) (PurpleConversation *conv, const_char_ptr old_name, const_char_ptr new_name, const_char_ptr new_alias)
52         void (*chat_remove_users) (PurpleConversation *conv, GList *users)
53         void (*chat_update_user) (PurpleConversation *conv, const_char_ptr user)
54         void (*present) (PurpleConversation *conv)
55         gboolean (*has_focus) (PurpleConversation *conv)
56         gboolean (*custom_smiley_add) (PurpleConversation *conv, const_char_ptr smile, gboolean remote)
57         void (*custom_smiley_write) (PurpleConversation *conv, const_char_ptr smile, const_guchar_ptr data, gsize size)
58         void (*custom_smiley_close) (PurpleConversation *conv, const_char_ptr smile)
59         void (*send_confirm) (PurpleConversation *conv, const_char_ptr message)
60
61     void purple_conversations_init()
62     PurpleConversation *purple_conversation_new(int type, PurpleAccount *account, const_char_ptr name)
63     void purple_conversation_set_ui_ops(PurpleConversation *conv, PurpleConversationUiOps *ops)
64     PurpleConvIm *purple_conversation_get_im_data(PurpleConversation *conv)
65     void purple_conv_im_send(PurpleConvIm *im, const_char_ptr message)
66     void *purple_conversations_get_handle()
67     void purple_conversation_destroy(PurpleConversation *conv)
68
69 cdef class Conversation:
70     """ Conversation class """
71     cdef PurpleConversation *__conv
72
73     def __cinit__(self):
74         purple_conversations_init()
75
76     def conversation_new(self, type, acc, const_char_ptr name):
77         self.__conv = purple_conversation_new(type, <PurpleAccount*>acc.__account, name)
78
79     def conversation_set_ui_ops(self):
80         cdef PurpleConversationUiOps c_conv_ui_ops
81         c_conv_ui_ops.create_conversation = NULL
82         c_conv_ui_ops.destroy_conversation = NULL
83         c_conv_ui_ops.write_chat = NULL
84         c_conv_ui_ops.write_im = NULL
85         c_conv_ui_ops.write_conv = NULL
86         c_conv_ui_ops.chat_add_users = NULL
87         c_conv_ui_ops.chat_rename_user = NULL
88         c_conv_ui_ops.chat_remove_users = NULL
89         c_conv_ui_ops.chat_update_user = NULL
90         c_conv_ui_ops.present = NULL
91         c_conv_ui_ops.has_focus = NULL
92         c_conv_ui_ops.custom_smiley_add = NULL
93         c_conv_ui_ops.custom_smiley_write = NULL
94         c_conv_ui_ops.custom_smiley_close = NULL
95         c_conv_ui_ops.send_confirm = NULL
96
97         purple_conversation_set_ui_ops(self.__conv, &c_conv_ui_ops)
98
99     def conversation_write(self, const_char_ptr message):
100         purple_conv_im_send(purple_conversation_get_im_data(self.__conv), message)
101
102     def conversation_destroy(self):
103         purple_conversation_destroy(self.__conv)
104
105     def conversation_get_handle(self):
106         purple_conversations_get_handle()
107
108     def send_message(self, buddy, const_char_ptr message):
109         self.conversation_new(1, buddy.account, buddy.name)
110         self.conversation_set_ui_ops()
111         self.conversation_write(message)