3 * Purple is the legal property of its developers, whose names are too numerous
4 * to list here. Please refer to the COPYRIGHT file distributed with this
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
22 #ifndef PURPLE_CONVERSATION_H
23 #define PURPLE_CONVERSATION_H
25 * SECTION:conversation
26 * @section_id: libpurple-conversation
27 * @short_description: Conversation base class <filename>conversation.h</filename>
28 * @title: Conversation Base Class
30 * This is the base class for the conversation abstraction on Libpurple.
32 * The present API manages the common functionallity for both kinds of conversations
33 * @PurpleIMConversation and @PurpleChatConversation.
36 #define PURPLE_TYPE_CONVERSATION (purple_conversation_get_type())
37 #define PURPLE_CONVERSATION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), PURPLE_TYPE_CONVERSATION, PurpleConversation))
38 #define PURPLE_CONVERSATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), PURPLE_TYPE_CONVERSATION, PurpleConversationClass))
39 #define PURPLE_IS_CONVERSATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), PURPLE_TYPE_CONVERSATION))
40 #define PURPLE_IS_CONVERSATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), PURPLE_TYPE_CONVERSATION))
41 #define PURPLE_CONVERSATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), PURPLE_TYPE_CONVERSATION, PurpleConversationClass))
43 #define PURPLE_TYPE_CONVERSATION_UI_OPS (purple_conversation_ui_ops_get_type())
45 #define PURPLE_TYPE_CONVERSATION_MESSAGE (purple_conversation_message_get_type())
47 /**************************************************************************/
49 /**************************************************************************/
51 typedef struct _PurpleConversation PurpleConversation
;
52 typedef struct _PurpleConversationClass PurpleConversationClass
;
54 typedef struct _PurpleConversationUiOps PurpleConversationUiOps
;
57 * PurpleConversationUpdateType:
58 * @PURPLE_CONVERSATION_UPDATE_ADD: The buddy associated with the
59 * conversation was added.
60 * @PURPLE_CONVERSATION_UPDATE_REMOVE: The buddy associated with the
61 * conversation was removed.
62 * @PURPLE_CONVERSATION_UPDATE_ACCOUNT: The purple_account was changed.
63 * @PURPLE_CONVERSATION_UPDATE_TYPING: The typing state was updated.
64 * @PURPLE_CONVERSATION_UPDATE_UNSEEN: The unseen state was updated.
65 * @PURPLE_CONVERSATION_UPDATE_LOGGING: Logging for this conversation was
66 * enabled or disabled.
67 * @PURPLE_CONVERSATION_UPDATE_TOPIC: The topic for a chat was updated.
68 * @PURPLE_CONVERSATION_UPDATE_E2EE: The End-to-end encryption state was
70 * @PURPLE_CONVERSATION_ACCOUNT_ONLINE: One of the user's accounts went online.
71 * @PURPLE_CONVERSATION_ACCOUNT_OFFLINE: One of the user's accounts went
73 * @PURPLE_CONVERSATION_UPDATE_AWAY: The other user went away.
74 * @PURPLE_CONVERSATION_UPDATE_ICON: The other user's buddy icon changed.
75 * @PURPLE_CONVERSATION_UPDATE_NAME: The name of the conversation was changed.
76 * @PURPLE_CONVERSATION_UPDATE_TITLE: The title of the conversation was updated.
77 * @PURPLE_CONVERSATION_UPDATE_CHATLEFT: The user left a chat.
78 * @PURPLE_CONVERSATION_UPDATE_FEATURES: The features for a chat have changed.
80 * Conversation update type.
84 PURPLE_CONVERSATION_UPDATE_ADD
= 0,
85 PURPLE_CONVERSATION_UPDATE_REMOVE
,
86 PURPLE_CONVERSATION_UPDATE_ACCOUNT
,
87 PURPLE_CONVERSATION_UPDATE_TYPING
,
88 PURPLE_CONVERSATION_UPDATE_UNSEEN
,
89 PURPLE_CONVERSATION_UPDATE_LOGGING
,
90 PURPLE_CONVERSATION_UPDATE_TOPIC
,
91 PURPLE_CONVERSATION_UPDATE_E2EE
,
94 * XXX These need to go when we implement a more generic core/UI event
97 PURPLE_CONVERSATION_ACCOUNT_ONLINE
,
98 PURPLE_CONVERSATION_ACCOUNT_OFFLINE
,
99 PURPLE_CONVERSATION_UPDATE_AWAY
,
100 PURPLE_CONVERSATION_UPDATE_ICON
,
101 PURPLE_CONVERSATION_UPDATE_NAME
,
102 PURPLE_CONVERSATION_UPDATE_TITLE
,
103 PURPLE_CONVERSATION_UPDATE_CHATLEFT
,
105 PURPLE_CONVERSATION_UPDATE_FEATURES
107 } PurpleConversationUpdateType
;
110 * PurpleMessageFlags:
111 * @PURPLE_MESSAGE_SEND: Outgoing message.
112 * @PURPLE_MESSAGE_RECV: Incoming message.
113 * @PURPLE_MESSAGE_SYSTEM: System message.
114 * @PURPLE_MESSAGE_AUTO_RESP: Auto response.
115 * @PURPLE_MESSAGE_ACTIVE_ONLY: Hint to the UI that this message should not be
116 * shown in conversations which are only open for
117 * internal UI purposes (e.g. for contact-aware
119 * @PURPLE_MESSAGE_NICK: Contains your nick.
120 * @PURPLE_MESSAGE_NO_LOG: Do not log.
121 * @PURPLE_MESSAGE_ERROR: Error message.
122 * @PURPLE_MESSAGE_DELAYED: Delayed message.
123 * @PURPLE_MESSAGE_RAW: "Raw" message - don't apply formatting
124 * @PURPLE_MESSAGE_IMAGES: Message contains images
125 * @PURPLE_MESSAGE_NOTIFY: Message is a notification
126 * @PURPLE_MESSAGE_NO_LINKIFY: Message should not be auto-linkified
127 * @PURPLE_MESSAGE_INVISIBLE: Message should not be displayed
128 * @PURPLE_MESSAGE_REMOTE_SEND: Message sent from another location,
129 * not an echo of a local one
131 * Flags applicable to a message. Most will have send, recv or system.
133 typedef enum /*< flags >*/
135 PURPLE_MESSAGE_SEND
= 0x0001,
136 PURPLE_MESSAGE_RECV
= 0x0002,
137 PURPLE_MESSAGE_SYSTEM
= 0x0004,
138 PURPLE_MESSAGE_AUTO_RESP
= 0x0008,
139 PURPLE_MESSAGE_ACTIVE_ONLY
= 0x0010,
140 PURPLE_MESSAGE_NICK
= 0x0020,
141 PURPLE_MESSAGE_NO_LOG
= 0x0040,
142 PURPLE_MESSAGE_ERROR
= 0x0200,
143 PURPLE_MESSAGE_DELAYED
= 0x0400,
144 PURPLE_MESSAGE_RAW
= 0x0800,
145 PURPLE_MESSAGE_IMAGES
= 0x1000,
146 PURPLE_MESSAGE_NOTIFY
= 0x2000,
147 PURPLE_MESSAGE_NO_LINKIFY
= 0x4000,
148 PURPLE_MESSAGE_INVISIBLE
= 0x8000,
149 PURPLE_MESSAGE_REMOTE_SEND
= 0x10000
150 } PurpleMessageFlags
;
153 #include <glib-object.h>
156 /**************************************************************************/
157 /* PurpleConversation */
158 /**************************************************************************/
160 * PurpleConversation:
161 * @ui_data: The UI data associated with this conversation. This is a
162 * convenience field provided to the UIs -- it is not used by the
165 * A core representation of a conversation between two or more people.
167 * The conversation can be an IM or a chat.
169 * Note: When a conversation is destroyed with the last g_object_unref(), the
170 * specified conversation is removed from the parent window. If this
171 * conversation is the only one contained in the parent window, that
172 * window is also destroyed.
174 struct _PurpleConversation
183 * PurpleConversationClass:
184 * @write_message: Writes a message to a chat or IM conversation. See
185 * purple_conversation_write_message().
187 * Base class for all #PurpleConversation's
189 struct _PurpleConversationClass
{
190 GObjectClass parent_class
;
192 void (*write_message
)(PurpleConversation
*conv
, PurpleMessage
*msg
);
195 void (*_purple_reserved1
)(void);
196 void (*_purple_reserved2
)(void);
197 void (*_purple_reserved3
)(void);
198 void (*_purple_reserved4
)(void);
202 #include "buddyicon.h"
205 #include "smiley-list.h"
207 /**************************************************************************/
208 /* PurpleConversationUiOps */
209 /**************************************************************************/
211 * PurpleConversationUiOps:
212 * @create_conversation: Called when @conv is created (but before the
213 * <link linkend="conversations-conversation-created"><literal>"conversation-created"</literal></link>
214 * signal is emitted).
215 * @destroy_conversation: Called just before @conv is freed.
216 * @write_chat: Write a message to a chat. If this field is %NULL, libpurple
217 * will fall back to using @write_conv.
218 * See purple_conversation_write_message().
219 * @write_im: Write a message to an IM conversation. If this field is %NULL,
220 * libpurple will fall back to using @write_conv.
221 * See purple_conversation_write_message().
222 * @write_conv: Write a message to a conversation. This is used rather than the
223 * chat- or im-specific ops for errors, system messages (such as "x
224 * is now know as y"), and as the fallback if @write_im and
225 * @write_chat are not implemented. It should be implemented, or
226 * the UI will miss conversation error messages and your users will
227 * hate you. See purple_conversation_write_message().
228 * @chat_add_users: Add @cbuddies to a chat.
229 * <sbr/>@cbuddies: A GList of #PurpleChatUser structs.
230 * <sbr/>@new_arrivals: Whether join notices should be shown.
231 * (Join notices are actually written to
232 * the conversation by
233 * purple_chat_conversation_add_users())
234 * @chat_rename_user: Rename the user in this chat named @old_name to @new_name.
235 * (The rename message is written to the conversation by
236 * libpurple.) See purple_chat_conversation_rename_user().
237 * <sbr/>@new_alias: @new_name's new alias, if they have one.
238 * @chat_remove_users: Remove @users from a chat @chat.
239 * See purple_chat_conversation_remove_users().
240 * @chat_update_user: Called when a user's flags are changed.
241 * See purple_chat_user_set_flags().
242 * @present: Present this conversation to the user; for example, by displaying
244 * @has_focus: If this UI has a concept of focus (as in a windowing system) and
245 * this conversation has the focus, return %TRUE; otherwise, return
247 * @send_confirm: Prompt the user for confirmation to send @message. This
248 * function should arrange for the message to be sent if the user
249 * accepts. If this field is %NULL, libpurple will fall back to
250 * using purple_request_action().
252 * Conversation operations and events.
254 * Any UI representing a conversation must assign a filled-out
255 * #PurpleConversationUiOps structure to the #PurpleConversation.
257 struct _PurpleConversationUiOps
259 void (*create_conversation
)(PurpleConversation
*conv
);
260 void (*destroy_conversation
)(PurpleConversation
*conv
);
262 void (*write_chat
)(PurpleChatConversation
*chat
, PurpleMessage
*msg
);
263 void (*write_im
)(PurpleIMConversation
*im
, PurpleMessage
*msg
);
264 void (*write_conv
)(PurpleConversation
*conv
, PurpleMessage
*msg
);
266 void (*chat_add_users
)(PurpleChatConversation
*chat
,
268 gboolean new_arrivals
);
270 void (*chat_rename_user
)(PurpleChatConversation
*chat
, const char *old_name
,
271 const char *new_name
, const char *new_alias
);
273 void (*chat_remove_users
)(PurpleChatConversation
*chat
, GList
*users
);
275 void (*chat_update_user
)(PurpleChatUser
*cb
);
277 void (*present
)(PurpleConversation
*conv
);
278 gboolean (*has_focus
)(PurpleConversation
*conv
);
280 void (*send_confirm
)(PurpleConversation
*conv
, const char *message
);
283 void (*_purple_reserved1
)(void);
284 void (*_purple_reserved2
)(void);
285 void (*_purple_reserved3
)(void);
286 void (*_purple_reserved4
)(void);
291 /**************************************************************************/
292 /* Conversation API */
293 /**************************************************************************/
296 * purple_conversation_get_type:
298 * Returns: The #GType for the Conversation object.
300 GType
purple_conversation_get_type(void);
303 * purple_conversation_ui_ops_get_type:
305 * Returns: The #GType for the #PurpleConversationUiOps boxed structure.
307 GType
purple_conversation_ui_ops_get_type(void);
310 * purple_conversation_present:
311 * @conv: The conversation to present
313 * Present a conversation to the user. This allows core code to initiate a
314 * conversation by displaying the IM dialog.
316 void purple_conversation_present(PurpleConversation
*conv
);
319 * purple_conversation_set_ui_ops:
320 * @conv: The conversation.
321 * @ops: The UI conversation operations structure.
323 * Sets the specified conversation's UI operations structure.
325 void purple_conversation_set_ui_ops(PurpleConversation
*conv
,
326 PurpleConversationUiOps
*ops
);
329 * purple_conversation_get_ui_ops:
330 * @conv: The conversation.
332 * Returns the specified conversation's UI operations structure.
334 * Returns: The operations structure.
336 PurpleConversationUiOps
*purple_conversation_get_ui_ops(PurpleConversation
*conv
);
339 * purple_conversation_set_account:
340 * @conv: The conversation.
341 * @account: The purple_account.
343 * Sets the specified conversation's purple_account.
345 * This purple_account represents the user using purple, not the person the user
346 * is having a conversation/chat/flame with.
348 void purple_conversation_set_account(PurpleConversation
*conv
,
349 PurpleAccount
*account
);
352 * purple_conversation_get_account:
353 * @conv: The conversation.
355 * Returns the specified conversation's purple_account.
357 * This purple_account represents the user using purple, not the person the user
358 * is having a conversation/chat/flame with.
360 * Returns: (transfer none): The conversation's purple_account.
362 PurpleAccount
*purple_conversation_get_account(PurpleConversation
*conv
);
365 * purple_conversation_get_connection:
366 * @conv: The conversation.
368 * Returns the specified conversation's purple_connection.
370 * Returns: (transfer none): The conversation's purple_connection.
372 PurpleConnection
*purple_conversation_get_connection(PurpleConversation
*conv
);
375 * purple_conversation_set_title:
376 * @conv: The conversation.
379 * Sets the specified conversation's title.
381 void purple_conversation_set_title(PurpleConversation
*conv
, const char *title
);
384 * purple_conversation_get_title:
385 * @conv: The conversation.
387 * Returns the specified conversation's title.
389 * Returns: The title.
391 const char *purple_conversation_get_title(PurpleConversation
*conv
);
394 * purple_conversation_autoset_title:
395 * @conv: The conversation.
397 * Automatically sets the specified conversation's title.
399 * This function takes OPT_IM_ALIAS_TAB into account, as well as the
402 void purple_conversation_autoset_title(PurpleConversation
*conv
);
405 * purple_conversation_set_name:
406 * @conv: The conversation.
407 * @name: The conversation's name.
409 * Sets the specified conversation's name.
411 void purple_conversation_set_name(PurpleConversation
*conv
, const char *name
);
414 * purple_conversation_get_name:
415 * @conv: The conversation.
417 * Returns the specified conversation's name.
419 * Returns: The conversation's name. If the conversation is an IM with a
420 * PurpleBuddy, then it's the name of the PurpleBuddy.
422 const char *purple_conversation_get_name(PurpleConversation
*conv
);
425 * purple_conversation_set_e2ee_state:
426 * @conv: The conversation.
427 * @state: The E2EE state.
429 * Sets current E2EE state for the conversation.
432 purple_conversation_set_e2ee_state(PurpleConversation
*conv
,
433 PurpleE2eeState
*state
);
436 * purple_conversation_get_e2ee_state:
437 * @conv: The conversation.
439 * Gets current conversation's E2EE state.
441 * Returns: Current E2EE state for conversation.
444 purple_conversation_get_e2ee_state(PurpleConversation
*conv
);
447 * purple_conversation_set_logging:
448 * @conv: The conversation.
449 * @log: %TRUE if logging should be enabled, or %FALSE otherwise.
451 * Enables or disables logging for this conversation.
453 void purple_conversation_set_logging(PurpleConversation
*conv
, gboolean log
);
456 * purple_conversation_is_logging:
457 * @conv: The conversation.
459 * Returns whether or not logging is enabled for this conversation.
461 * Returns: %TRUE if logging is enabled, or %FALSE otherwise.
463 gboolean
purple_conversation_is_logging(PurpleConversation
*conv
);
466 * purple_conversation_close_logs:
467 * @conv: The conversation.
469 * Closes any open logs for this conversation.
471 * Note that new logs will be opened as necessary (e.g. upon receipt of a
472 * message, if the conversation has logging enabled. To disable logging for
473 * the remainder of the conversation, use purple_conversation_set_logging().
475 void purple_conversation_close_logs(PurpleConversation
*conv
);
478 * purple_conversation_write_message:
479 * @conv: The conversation.
480 * @msg: The message to write.
482 * Writes to a chat or an IM.
484 void purple_conversation_write_message(PurpleConversation
*conv
,
488 * purple_conversation_write_system_message:
489 * @conv: The conversation.
490 * @message: The message to write.
491 * @flags: The message flags (you don't need to set %PURPLE_MESSAGE_SYSTEM.
493 * Wites a system message to a chat or an IM.
495 void purple_conversation_write_system_message(PurpleConversation
*conv
,
496 const gchar
*message
, PurpleMessageFlags flags
);
499 * purple_conversation_send:
500 * @conv: The conversation.
501 * @message: The message to send.
503 * Sends a message to this conversation. This function calls
504 * purple_conversation_send_with_flags() with no additional flags.
506 void purple_conversation_send(PurpleConversation
*conv
, const char *message
);
509 * purple_conversation_send_with_flags:
510 * @conv: The conversation.
511 * @message: The message to send.
512 * @flags: The PurpleMessageFlags flags to use in addition to
513 * PURPLE_MESSAGE_SEND.
515 * Sends a message to this conversation with specified flags.
517 void purple_conversation_send_with_flags(PurpleConversation
*conv
, const char *message
,
518 PurpleMessageFlags flags
);
521 * purple_conversation_set_features:
522 * @conv: The conversation
523 * @features: Bitset defining supported features
525 * Set the features as supported for the given conversation.
527 void purple_conversation_set_features(PurpleConversation
*conv
,
528 PurpleConnectionFlags features
);
532 * purple_conversation_get_features:
533 * @conv: The conversation
535 * Get the features supported by the given conversation.
537 PurpleConnectionFlags
purple_conversation_get_features(PurpleConversation
*conv
);
540 * purple_conversation_has_focus:
541 * @conv: The conversation.
543 * Determines if a conversation has focus
545 * Returns: %TRUE if the conversation has focus, %FALSE if
546 * it does not or the UI does not have a concept of conversation focus
548 gboolean
purple_conversation_has_focus(PurpleConversation
*conv
);
551 * purple_conversation_update:
552 * @conv: The conversation.
553 * @type: The update type.
555 * Updates the visual status and UI of a conversation.
557 void purple_conversation_update(PurpleConversation
*conv
, PurpleConversationUpdateType type
);
560 * purple_conversation_get_message_history:
561 * @conv: The conversation
563 * Retrieve the message history of a conversation.
565 * Returns: (element-type PurpleMessage) (transfer none):
566 * A GList of PurpleMessage's. You must not modify the
567 * list or the data within. The list contains the newest message at
568 * the beginning, and the oldest message at the end.
570 GList
*purple_conversation_get_message_history(PurpleConversation
*conv
);
573 * purple_conversation_clear_message_history:
574 * @conv: The conversation
576 * Clear the message history of a conversation.
578 void purple_conversation_clear_message_history(PurpleConversation
*conv
);
581 * purple_conversation_set_ui_data:
582 * @conv: The conversation.
583 * @ui_data: A pointer to associate with this conversation.
585 * Set the UI data associated with this conversation.
587 void purple_conversation_set_ui_data(PurpleConversation
*conv
, gpointer ui_data
);
590 * purple_conversation_get_ui_data:
591 * @conv: The conversation.
593 * Get the UI data associated with this conversation.
595 * Returns: (transfer none): The UI data associated with this conversation.
596 * This is a convenience field provided to the UIs--it is not
597 * used by the libpurple core.
599 gpointer
purple_conversation_get_ui_data(const PurpleConversation
*conv
);
602 * purple_conversation_send_confirm:
603 * @conv: The conversation.
604 * @message: The message to send.
606 * Sends a message to a conversation after confirming with
609 * This function is intended for use in cases where the user
610 * hasn't explicitly and knowingly caused a message to be sent.
611 * The confirmation ensures that the user isn't sending a
612 * message by mistake.
614 void purple_conversation_send_confirm(PurpleConversation
*conv
, const char *message
);
617 * purple_conversation_get_extended_menu:
618 * @conv: The conversation.
620 * Retrieves the extended menu items for the conversation.
622 * Returns: (element-type PurpleActionMenu) (transfer full): The extended menu
623 * items for a conversation, as harvested by the chat-extended-menu
626 GList
* purple_conversation_get_extended_menu(PurpleConversation
*conv
);
629 * purple_conversation_do_command:
630 * @conv: The conversation.
631 * @cmdline: The entire command including the arguments.
632 * @markup: %NULL, or the formatted command line.
633 * @error: If the command failed errormsg is filled in with the appropriate error
634 * message, if not %NULL. It must be freed by the caller with g_free().
636 * Perform a command in a conversation. Similar to purple_cmd_do_command().
638 * Returns: %TRUE if the command was executed successfully, %FALSE otherwise.
640 gboolean
purple_conversation_do_command(PurpleConversation
*conv
,
641 const gchar
*cmdline
, const gchar
*markup
, gchar
**error
);
644 * purple_conversation_get_max_message_size:
645 * @conv: The conversation to query.
647 * Gets the maximum message size in bytes for the conversation.
649 * See #PurpleProtocolClientInterface's <literal>get_max_message_size</literal>.
651 * Returns: Maximum message size, 0 if unspecified, -1 for infinite.
654 purple_conversation_get_max_message_size(PurpleConversation
*conv
);
657 * purple_conversation_add_smiley:
658 * @conv: The conversation that receives new smiley.
659 * @smiley: The smiley.
661 * Adds a smiley to the list of smileys that belong to this conversation.
663 void purple_conversation_add_smiley(PurpleConversation
*conv
, PurpleSmiley
*smiley
);
666 * purple_conversation_get_smiley:
667 * @conv: The conversation.
668 * @shortcut: The shortcut.
670 * Lookups for the smiley previously added to this conversation.
672 * Returns: (transfer none): The smiley, or %NULL if it doesn't exists.
674 PurpleSmiley
*purple_conversation_get_smiley(PurpleConversation
*conv
, const gchar
*shortcut
);
677 * purple_conversation_get_remote_smileys:
678 * @conv: The conversation.
680 * Get all remote smileys previously added to this conversation.
682 * Returns: (transfer none): The list of remote smileys.
685 purple_conversation_get_remote_smileys(PurpleConversation
*conv
);
687 /**************************************************************************/
688 /* Conversation Helper API */
689 /**************************************************************************/
692 * purple_conversation_present_error:
693 * @who: The user this error is about
694 * @account: The account this error is on
697 * Presents an IM-error to the user
699 * This is a helper function to find a conversation, write an error to it, and
700 * raise the window. If a conversation with this user doesn't already exist,
701 * the function will return FALSE and the calling function can attempt to present
702 * the error another way (purple_notify_error, most likely)
704 * Returns: TRUE if the error was presented, else FALSE
706 gboolean
purple_conversation_present_error(const char *who
, PurpleAccount
*account
, const char *what
);
710 #endif /* PURPLE_CONVERSATION_H */