~ubuntu-branches/debian/experimental/thunar/experimental

« back to all changes in this revision

Viewing changes to docs/reference/thunarx/html/thunarx-writing-extensions-getting-started.html

  • Committer: Bazaar Package Importer
  • Author(s): Yves-Alexis Perez
  • Date: 2006-01-02 23:42:32 UTC
  • Revision ID: james.westby@ubuntu.com-20060102234232-8xeq0lqhyn70syr0
Tags: upstream-0.1.4svn+r18850
ImportĀ upstreamĀ versionĀ 0.1.4svn+r18850

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<html>
 
2
<head>
 
3
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
 
4
<title>Getting Started</title>
 
5
<meta name="generator" content="DocBook XSL Stylesheets V1.68.1">
 
6
<link rel="start" href="index.html" title="Thunar Extensions Reference Manual">
 
7
<link rel="up" href="thunarx-writing-extensions.html" title="Part&#160;II.&#160;Writing Extensions">
 
8
<link rel="prev" href="thunarx-writing-extensions.html" title="Part&#160;II.&#160;Writing Extensions">
 
9
<link rel="next" href="thunarx-writing-extensions-advanced-topics.html" title="Advanced topics">
 
10
<meta name="generator" content="GTK-Doc V1.4 (XML mode)">
 
11
<link rel="stylesheet" href="style.css" type="text/css">
 
12
<link rel="part" href="thunarx-overview.html" title="Part&#160;I.&#160;Overview">
 
13
<link rel="part" href="thunarx-writing-extensions.html" title="Part&#160;II.&#160;Writing Extensions">
 
14
<link rel="part" href="thunarx-fundamentals.html" title="Part&#160;III.&#160;Fundamentals">
 
15
<link rel="part" href="thunarx-abstraction-layer.html" title="Part&#160;IV.&#160;Abstraction Layer">
 
16
<link rel="part" href="thunarx-providers.html" title="Part&#160;V.&#160;Providers">
 
17
<link rel="index" href="ix01.html" title="Index">
 
18
</head>
 
19
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
 
20
<table class="navigation" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle">
 
21
<td><a accesskey="p" href="thunarx-writing-extensions.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
 
22
<td><a accesskey="u" href="thunarx-writing-extensions.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
 
23
<td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
 
24
<th width="100%" align="center">Thunar Extensions Reference Manual</th>
 
25
<td><a accesskey="n" href="thunarx-writing-extensions-advanced-topics.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
 
26
</tr></table>
 
27
<div class="sect1" lang="en">
 
28
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
 
29
<a name="thunarx-writing-extensions-getting-started"></a>Getting Started</h2></div></div></div>
 
30
<p>
 
31
        Providers are <span class="type">GTypeModule</span>s loaded from shared libraries installed in
 
32
        <code class="filename">$libdir/thunarx-1/</code>. The shared libraries are linked against the
 
33
        <code class="systemitem">thunarx-1</code> library.
 
34
      </p>
 
35
<p>
 
36
        The extensions must provide three public functions, <code class="function">thunar_extension_initialize()</code>,
 
37
        <code class="function">thunar_extension_shutdown()</code> and <code class="function">thunar_extension_list_types()</code>.
 
38
      </p>
 
39
<p>
 
40
        <code class="function">thunar_extension_initialize()</code> is passed a <span class="type">GTypeModule</span>
 
41
        object, and must register all GTypes that the extension needs. <code class="function">thunar_extension_shutdown()</code> should
 
42
        perform any extension-specific shutdown required prior to unloading the extension. <code class="function">thunar_extension_list_types()</code>
 
43
        returns an array of GTypes that represent the types of the providers exported by the extension. Thunar will instantiate
 
44
        objects of those types when needed.
 
45
      </p>
 
46
<div class="example">
 
47
<a name="id2539667"></a><p class="title"><b>Example&#160;1.&#160;Basic Structure of an extension</b></p>
 
48
<pre class="programlisting">
 
49
#include &lt;gmodule.h&gt;
 
50
#include &lt;thunarx/thunarx.h&gt;
 
51
 
 
52
static GType type_list[1];
 
53
 
 
54
static void
 
55
foo_extension_register_type (GTypeModule *module)
 
56
{
 
57
  static const GTypeInfo info =
 
58
  {
 
59
    sizeof (FooExtensionClass),
 
60
    NULL,
 
61
    NULL,
 
62
    (GClassInitFunc) foo_extension_class_init,
 
63
    NULL,
 
64
    NULL,
 
65
    sizeof (FooExtension),
 
66
    0,
 
67
    (GInstanceInitFunc) foo_extension_init,
 
68
    NULL,
 
69
  };
 
70
 
 
71
  type_list[0] = g_type_module_register_type (module,
 
72
                                              G_TYPE_OBJECT,
 
73
                                              "FooExtension",
 
74
                                              &amp;info, 0);
 
75
 
 
76
  /* implement the desired provider interfaces */
 
77
}
 
78
 
 
79
static GType
 
80
foo_extension_get_type (void)
 
81
{
 
82
  return type_list[0];
 
83
}
 
84
 
 
85
G_MODULE_EXPORT void
 
86
thunar_extension_initialize (GTypeModule *module)
 
87
{
 
88
  const gchar *mismatch;
 
89
 
 
90
  /* verify the versions */
 
91
  mismatch = thunarx_check_version (THUNARX_MAJOR_VERSION,
 
92
                                    THUNARX_MINOR_VERSION,
 
93
                                    THUNARX_MICRO_VERSION);
 
94
  if (G_UNLIKELY (mismatch != NULL))
 
95
    {
 
96
      g_warning ("Version mismatch: %s", mismatch);
 
97
      return;
 
98
    }
 
99
 
 
100
  foo_extension_register_type (module);
 
101
}
 
102
 
 
103
G_MODULE_EXPORT void
 
104
thunar_extension_shutdown (void)
 
105
{
 
106
  /* any extension-specific shutdown */
 
107
}
 
108
 
 
109
G_MODULE_EXPORT void
 
110
thunar_extension_list_types (const GType **types,
 
111
                             gint         *n_types)
 
112
{
 
113
  *types = type_list;
 
114
  *n_types = G_N_ELEMENTS (type_list);
 
115
}</pre>
 
116
</div>
 
117
<div class="sect2" lang="en">
 
118
<div class="titlepage"><div><div><h3 class="title">
 
119
<a name="thunarx-writing-extensions-compiling-thunar-extensions"></a>Compiling Thunar Extensions</h3></div></div></div>
 
120
<p>
 
121
          To compile a Thunar extension, you need to tell the compiler where to find the
 
122
          <code class="systemitem">thunarx</code> header files and library. This
 
123
          is done with the <code class="literal">pkg-config</code> utility.
 
124
        </p>
 
125
<p>
 
126
          The following interactive shell session demonstrates how <code class="literal">pkg-config</code>
 
127
          is used (the actual output on your system will be different):
 
128
          </p>
 
129
<pre class="screen">
 
130
$ pkg-config --cflags thunarx-1
 
131
-DXTHREADS -DXUSE_MTSAFE_API -I/opt/local/include/thunarx-1 -I/usr/local/include/atk-1.0 \
 
132
-I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include -I/usr/X11R6/include/gtk-2.0 \
 
133
-I/usr/X11R6/lib/gtk-2.0/include -I/usr/X11R6/include -I/usr/X11R6/include/pango-1.0 \
 
134
-I/usr/local/include/freetype2 -I/usr/local/include
 
135
$ pkg-config --libs thunarx-1
 
136
-Wl,--rpath -Wl,/usr/local/lib -L/usr/local/lib -L/usr/X11R6/lib -L/opt/local/lib -lthunarx-1</pre>
 
137
<p>
 
138
        </p>
 
139
<p>
 
140
          The easiest way to compile an extension is to use the <span class="emphasis"><em>backticks</em></span>
 
141
          feature of the shell. If you enclose a command in backticks (<span class="emphasis"><em>not single
 
142
          quotes</em></span>), then its output will be substituted into the command line before
 
143
          execution. So to compile an extension, you would type the following:
 
144
          </p>
 
145
<pre class="screen">
 
146
$ gcc -shared -fPIC -DPIC `pkg-config --cflags --libs thunarx-1` foo.c -o foo.so</pre>
 
147
<p>
 
148
        </p>
 
149
</div>
 
150
<div class="sect2" lang="en">
 
151
<div class="titlepage"><div><div><h3 class="title">
 
152
<a name="thunarx-writing-extensions-installing-thunar-extensions"></a>Installing Thunar Extensions</h3></div></div></div>
 
153
<p>
 
154
          To determine the directory where extensions must be installed on your local system,
 
155
          you can use the following command (as mentioned above, the output will be different
 
156
          on your system):
 
157
          </p>
 
158
<pre class="screen">
 
159
$ pkg-config --variable=extensionsdir thunarx-1
 
160
/opt/local/lib/thunarx-1</pre>
 
161
<p>
 
162
        </p>
 
163
<p>
 
164
          For example, to install the extension <code class="filename">foo.so</code> on your system,
 
165
          you would type the following:
 
166
          </p>
 
167
<pre class="screen">
 
168
$ install -d `pkg-config --variable=extensionsdir thunarx-1`
 
169
$ install -c -m 0755 foo.so `pkg-config --variable=extensionsdir thunarx-1`/foo.so</pre>
 
170
<p>
 
171
        </p>
 
172
</div>
 
173
</div>
 
174
<table class="navigation" width="100%" summary="Navigation footer" cellpadding="2" cellspacing="0"><tr valign="middle">
 
175
<td align="left"><a accesskey="p" href="thunarx-writing-extensions.html"><b>&lt;&lt;&#160;Part&#160;II.&#160;Writing Extensions</b></a></td>
 
176
<td align="right"><a accesskey="n" href="thunarx-writing-extensions-advanced-topics.html"><b>Advanced topics&#160;&gt;&gt;</b></a></td>
 
177
</tr></table>
 
178
</body>
 
179
</html>