summaryrefslogtreecommitdiffstats
path: root/src/plugin/astroid_activatable.c
blob: 9655b059c91f64b8f15a6d6f11304e86cd303159 (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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# include "astroid_activatable.h"

/**
 * SECTION: astroid_activatable
 * @short_description: Interface for activatable extensions on the shell
 * @see_also: #PeasExtensionSet
 *
 * #AstroidActivatable is an interface which should be implemented by
 * extensions that should be activated on the Liferea main window.
 **/

G_DEFINE_INTERFACE (AstroidActivatable, astroid_activatable, G_TYPE_OBJECT)

void
astroid_activatable_default_init (AstroidActivatableInterface *iface)
{
    static gboolean initialized = FALSE;

  (void)(iface); /* unused */

    if (!initialized) {
        /**
         * AstroidActivatable:window:
         *
         * The window property contains the gtr window for this
         * #AstroidActivatable instance.
         */
    /*
        g_object_interface_install_property (iface,
                           g_param_spec_object ("shell",
                                                "Shell",
                                                "The Liferea shell",
                                                ASTROID_TYPE,
                                                G_PARAM_READWRITE |
                                                G_PARAM_CONSTRUCT_ONLY |
                                                G_PARAM_STATIC_STRINGS));

                                                */
        initialized = TRUE;
    }
}

/**
 * astroid_activatable_activate:
 * @activatable: A #AstroidActivatable.
 *
 * Activates the extension on the shell property.
 */
void
astroid_activatable_activate (AstroidActivatable * activatable)
{
    AstroidActivatableInterface *iface;

    g_return_if_fail (ASTROID_IS_ACTIVATABLE (activatable));

    iface = ASTROID_ACTIVATABLE_GET_IFACE (activatable);
    if (iface->activate)
        iface->activate (activatable);
}

/**
 * astroid_activatable_deactivate:
 * @activatable: A #AstroidActivatable.
 *
 * Deactivates the extension on the shell property.
 */
void
astroid_activatable_deactivate (AstroidActivatable * activatable)
{
    AstroidActivatableInterface *iface;

    g_return_if_fail (ASTROID_IS_ACTIVATABLE (activatable));

    iface = ASTROID_ACTIVATABLE_GET_IFACE (activatable);
    if (iface->deactivate)
        iface->deactivate (activatable);
}

/**
 * astroid_activatable_update_state:
 * @activatable: A #AstroidActivatable.
 *
 * Triggers an update of the extension internal state to take into account
 * state changes in the window, due to some event or user action.
 */
void
astroid_activatable_update_state (AstroidActivatable * activatable)
{
    AstroidActivatableInterface *iface;

    g_return_if_fail (ASTROID_IS_ACTIVATABLE (activatable));

    iface = ASTROID_ACTIVATABLE_GET_IFACE (activatable);
    if (iface->update_state)
        iface->update_state (activatable);
}

/**
 * astroid_activatable_get_user_agent:
 * @activatable: A #AstroidActivatable.
 *
 * Returns: (transfer none): A #string.
 */
const char *
astroid_activatable_get_user_agent (AstroidActivatable * activatable)
{
    AstroidActivatableInterface *iface;

    if (!ASTROID_IS_ACTIVATABLE (activatable)) return NULL;

    iface = ASTROID_ACTIVATABLE_GET_IFACE (activatable);
    if (iface->get_user_agent)
        return iface->get_user_agent (activatable);

  return NULL;
}

/**
 * astroid_activatable_generate_mid:
 * @activatable: A #AstroidActivatable.
 *
 * Returns: (transfer none): A #string.
 */
const char *
astroid_activatable_generate_mid (AstroidActivatable * activatable)
{
    AstroidActivatableInterface *iface;

    if (!ASTROID_IS_ACTIVATABLE (activatable)) return NULL;

    iface = ASTROID_ACTIVATABLE_GET_IFACE (activatable);
    if (iface->generate_mid)
        return iface->generate_mid (activatable);

  return NULL;
}

/**
 * astroid_activatable_get_tag_colors:
 * @activatable: A #AstroidActivatable.
 * @tag : A #utf8.
 * @bg : A #utf8.
 *
 * Returns: (element-type utf8) (transfer container): List of forground and background color for tag.
 */
GList *
astroid_activatable_get_tag_colors (AstroidActivatable * activatable, const char * tag, const char * bg)
{
    AstroidActivatableInterface *iface;

    if (!ASTROID_IS_ACTIVATABLE (activatable)) return NULL;

    iface = ASTROID_ACTIVATABLE_GET_IFACE (activatable);
    if (iface->get_tag_colors)
        return iface->get_tag_colors (activatable, tag, bg);

  return NULL;
}

/**
 * astroid_activatable_get_queries:
 * @activatable: A #AstroidActivatable.
 *
 * Returns: (element-type utf8) (transfer container): List of lists containing a name and a query.
 */
GList *
astroid_activatable_get_queries (AstroidActivatable * activatable)
{
    AstroidActivatableInterface *iface;

    if (!ASTROID_IS_ACTIVATABLE (activatable)) return NULL;

    iface = ASTROID_ACTIVATABLE_GET_IFACE (activatable);
    if (iface->get_queries)
        return iface->get_queries (activatable);

  return NULL;
}

/**
 * astroid_activatable_process:
 * @activatable: A #AstroidActivatable.
 * @fname: A #utf8.
 *
 * Returns: (transfer full): Stream of the processed raw message.
 */
GMimeStream *
astroid_activatable_process (AstroidActivatable * activatable, const char * fname)
{
  AstroidActivatableInterface *iface;

  if (!ASTROID_IS_ACTIVATABLE (activatable)) return NULL;

  iface = ASTROID_ACTIVATABLE_GET_IFACE (activatable);
  if (iface->process) {
    return iface->process (activatable, fname);
  }

  return NULL;
}