summaryrefslogtreecommitdiff
path: root/src/core/meta-selection-source.c
blob: b076391ce963d453803cf315397f3759d25ae132 (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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
 * Copyright (C) 2018 Red Hat
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program 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
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 *
 * Author: Carlos Garnacho <carlosg@gnome.org>
 */

#include "config.h"

#include "meta/meta-selection.h"
#include "meta/meta-selection-source.h"

typedef struct MetaSelectionSourcePrivate MetaSelectionSourcePrivate;

struct MetaSelectionSourcePrivate
{
  guint active : 1;
};

G_DEFINE_TYPE_WITH_PRIVATE (MetaSelectionSource,
                            meta_selection_source,
                            G_TYPE_OBJECT)

enum
{
  ACTIVE,
  INACTIVE,
  N_SIGNALS
};

static guint signals[N_SIGNALS] = { 0 };

static void
meta_selection_source_activated (MetaSelectionSource *source)
{
  MetaSelectionSourcePrivate *priv =
    meta_selection_source_get_instance_private (source);

  priv->active = TRUE;
}

static void
meta_selection_source_deactivated (MetaSelectionSource *source)
{
  MetaSelectionSourcePrivate *priv =
    meta_selection_source_get_instance_private (source);

  priv->active = FALSE;
}

static void
meta_selection_source_class_init (MetaSelectionSourceClass *klass)
{
  klass->activated = meta_selection_source_activated;
  klass->deactivated = meta_selection_source_deactivated;

  signals[ACTIVE] =
    g_signal_new ("activated",
                  G_TYPE_FROM_CLASS (klass),
                  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
                  G_STRUCT_OFFSET (MetaSelectionSourceClass, activated),
                  NULL, NULL, NULL,
                  G_TYPE_NONE, 0);
  signals[INACTIVE] =
    g_signal_new ("deactivated",
                  G_TYPE_FROM_CLASS (klass),
                  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
                  G_STRUCT_OFFSET (MetaSelectionSourceClass, deactivated),
                  NULL, NULL, NULL,
                  G_TYPE_NONE, 0);
}

static void
meta_selection_source_init (MetaSelectionSource *source)
{
}

void
meta_selection_source_read_async (MetaSelectionSource *source,
                                  const gchar         *mimetype,
                                  GCancellable        *cancellable,
                                  GAsyncReadyCallback  callback,
                                  gpointer             user_data)
{
  g_return_if_fail (META_IS_SELECTION_SOURCE (source));
  g_return_if_fail (mimetype != NULL);
  g_return_if_fail (callback != NULL);

  META_SELECTION_SOURCE_GET_CLASS (source)->read_async (source,
                                                        mimetype,
                                                        cancellable,
                                                        callback,
                                                        user_data);
}

/**
 * meta_selection_source_read_finish:
 * @source: The selection source
 * @result: The async result
 * @error: Location for returned error
 *
 * Finishes a read from the selection source.
 *
 * Returns: (transfer full): The resulting #GInputStream
 */
GInputStream *
meta_selection_source_read_finish (MetaSelectionSource  *source,
                                   GAsyncResult         *result,
                                   GError              **error)
{
  g_return_val_if_fail (META_IS_SELECTION_SOURCE (source), NULL);
  g_return_val_if_fail (g_task_is_valid (result, source), NULL);

  return META_SELECTION_SOURCE_GET_CLASS (source)->read_finish (source,
                                                                result,
                                                                error);
}

/**
 * meta_selection_source_get_mimetypes:
 * @source: The selection source
 *
 * Returns the list of supported mimetypes.
 *
 * Returns: (element-type utf8) (transfer full): The supported mimetypes
 */
GList *
meta_selection_source_get_mimetypes (MetaSelectionSource  *source)
{
  g_return_val_if_fail (META_IS_SELECTION_SOURCE (source), NULL);

  return META_SELECTION_SOURCE_GET_CLASS (source)->get_mimetypes (source);
}

/**
 * meta_selection_source_is_active:
 * @source: the selection source
 *
 * Returns #TRUE if the source is active on a selection.
 *
 * Returns: #TRUE if the source owns a selection.
 **/
gboolean
meta_selection_source_is_active (MetaSelectionSource *source)
{
  MetaSelectionSourcePrivate *priv =
    meta_selection_source_get_instance_private (source);

  g_return_val_if_fail (META_IS_SELECTION_SOURCE (source), FALSE);

  return priv->active;
}