summaryrefslogtreecommitdiff
path: root/telepathy-glib/client-message.c
blob: a8e46a188d63b9a79835613590be039288671394 (plain)
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
112
113
114
115
116
117
118
119
120
/*
 * client-message.c - Source for TpClientMessage
 * Copyright (C) 2006-2010 Collabora Ltd.
 * Copyright (C) 2006-2008 Nokia Corporation
 *
 * This library 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.1 of the License, or (at your option) any later version.
 *
 * This library 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 this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

/**
 * SECTION:client-message
 * @title: TpClientMessage
 * @short_description: a message in the Telepathy message interface, client side
 *
 * #TpClientMessage is used within Telepathy clients to represent a
 * message composed by a client, which it will send using the
 * Messages interface.
 * Its subclass #TpSignalledMessage represents messages as signalled by a
 * connection manager.
 *
 * Since: 0.13.9
 */

#include "config.h"

#include "client-message.h"
#include "client-message-internal.h"
#include "message-internal.h"

#include <telepathy-glib/dbus.h>
#include <telepathy-glib/gtypes.h>
#include <telepathy-glib/util.h>

/**
 * TpClientMessage:
 *
 * Opaque structure representing a message in the Telepathy messages interface
 * (client side).
 *
 * Since: 0.13.9
 */

G_DEFINE_TYPE (TpClientMessage, tp_client_message, TP_TYPE_MESSAGE)

struct _TpClientMessagePrivate
{
  gpointer unused;
};

static void
tp_client_message_class_init (TpClientMessageClass *klass)
{
}

static void
tp_client_message_init (TpClientMessage *self)
{
  self->priv = G_TYPE_INSTANCE_GET_PRIVATE ((self), TP_TYPE_MESSAGE,
      TpClientMessagePrivate);
}

/**
 * tp_client_message_new:
 *
 * A convenient function to create a new #TpClientMessage
 *
 * Returns: (transfer full): a newly allocated #TpClientMessage having only
 * the header part.
 *
 * Since: 0.13.9
 */
TpMessage *
tp_client_message_new (void)
{
  return g_object_new (TP_TYPE_CLIENT_MESSAGE,
      NULL);
}

/**
 * tp_client_message_new_text:
 * @type: the type of message
 * @text: content of the messsage
 *
 * A convenient function to create a new #TpClientMessage having
 * 'text/plain' as 'content-type', @type as 'message-type' and
 * @text as 'content'.
 *
 * Returns: (transfer full): a newly allocated #TpClientMessage
 *
 * Since: 0.13.9
 */
TpMessage *
tp_client_message_new_text (TpChannelTextMessageType type,
    const gchar *text)
{
  TpMessage *msg;

  msg = g_object_new (TP_TYPE_CLIENT_MESSAGE,
      NULL);

  if (type != TP_CHANNEL_TEXT_MESSAGE_TYPE_NORMAL)
    tp_message_set_uint32 (msg, 0, "message-type", type);

  tp_message_append_part (msg);
  tp_message_set_string (msg, 1, "content-type", "text/plain");
  tp_message_set_string (msg, 1, "content", text);

  return msg;
}