~ubuntu-branches/ubuntu/oneiric/inkscape/oneiric-updates

« back to all changes in this revision

Viewing changes to inkscape-0.47pre1/src/extension/output.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Bryce Harrington
  • Date: 2009-07-02 17:09:45 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20090702170945-nn6d6zswovbwju1t
Tags: 0.47~pre1-0ubuntu1
* New upstream release.
  - Don't constrain maximization on small resolution devices (pre0)
    (LP: #348842)
  - Fixes segfault on startup (pre0)
    (LP: #391149)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Authors:
 
3
 *   Ted Gould <ted@gould.cx>
 
4
 *
 
5
 * Copyright (C) 2006 Johan Engelen <johan@shouraizou.nl>
 
6
 * Copyright (C) 2002-2004 Authors
 
7
 *
 
8
 * Released under GNU GPL, read the file 'COPYING' for more information
 
9
 */
 
10
 
 
11
#include "document.h"
 
12
#include "implementation/implementation.h"
 
13
#include "output.h"
 
14
 
 
15
#include "prefdialog.h"
 
16
 
 
17
/* Inkscape::Extension::Output */
 
18
 
 
19
namespace Inkscape {
 
20
namespace Extension {
 
21
 
 
22
/**
 
23
    \return   None
 
24
    \brief    Builds a SPModuleOutput object from a XML description
 
25
    \param    module  The module to be initialized
 
26
    \param    repr    The XML description in a Inkscape::XML::Node tree
 
27
 
 
28
    Okay, so you want to build a SPModuleOutput object.
 
29
 
 
30
    This function first takes and does the build of the parent class,
 
31
    which is SPModule.  Then, it looks for the <output> section of the
 
32
    XML description.  Under there should be several fields which
 
33
    describe the output module to excruciating detail.  Those are parsed,
 
34
    copied, and put into the structure that is passed in as module.
 
35
    Overall, there are many levels of indentation, just to handle the
 
36
    levels of indentation in the XML file.
 
37
*/
 
38
Output::Output (Inkscape::XML::Node * in_repr, Implementation::Implementation * in_imp) : Extension(in_repr, in_imp)
 
39
{
 
40
    mimetype = NULL;
 
41
    extension = NULL;
 
42
    filetypename = NULL;
 
43
    filetypetooltip = NULL;
 
44
        dataloss = TRUE;
 
45
 
 
46
    if (repr != NULL) {
 
47
        Inkscape::XML::Node * child_repr;
 
48
 
 
49
        child_repr = sp_repr_children(repr);
 
50
 
 
51
        while (child_repr != NULL) {
 
52
            if (!strcmp(child_repr->name(), INKSCAPE_EXTENSION_NS "output")) {
 
53
                child_repr = sp_repr_children(child_repr);
 
54
                while (child_repr != NULL) {
 
55
                    char const * chname = child_repr->name();
 
56
                                        if (!strncmp(chname, INKSCAPE_EXTENSION_NS_NC, strlen(INKSCAPE_EXTENSION_NS_NC))) {
 
57
                                                chname += strlen(INKSCAPE_EXTENSION_NS);
 
58
                                        }
 
59
                    if (chname[0] == '_') /* Allow _ for translation of tags */
 
60
                        chname++;
 
61
                    if (!strcmp(chname, "extension")) {
 
62
                        g_free (extension);
 
63
                        extension = g_strdup(sp_repr_children(child_repr)->content());
 
64
                    }
 
65
                    if (!strcmp(chname, "mimetype")) {
 
66
                        g_free (mimetype);
 
67
                        mimetype = g_strdup(sp_repr_children(child_repr)->content());
 
68
                    }
 
69
                    if (!strcmp(chname, "filetypename")) {
 
70
                        g_free (filetypename);
 
71
                        filetypename = g_strdup(sp_repr_children(child_repr)->content());
 
72
                    }
 
73
                    if (!strcmp(chname, "filetypetooltip")) {
 
74
                        g_free (filetypetooltip);
 
75
                        filetypetooltip = g_strdup(sp_repr_children(child_repr)->content());
 
76
                    }
 
77
                    if (!strcmp(chname, "dataloss")) {
 
78
                        if (!strcmp(sp_repr_children(child_repr)->content(), "false")) {
 
79
                                                        dataloss = FALSE;
 
80
                                                }
 
81
                                        }
 
82
 
 
83
                    child_repr = sp_repr_next(child_repr);
 
84
                }
 
85
 
 
86
                break;
 
87
            }
 
88
 
 
89
            child_repr = sp_repr_next(child_repr);
 
90
        }
 
91
 
 
92
    }
 
93
}
 
94
 
 
95
/**
 
96
    \brief  Destroy an output extension
 
97
*/
 
98
Output::~Output (void)
 
99
{
 
100
    g_free(mimetype);
 
101
    g_free(extension);
 
102
    g_free(filetypename);
 
103
    g_free(filetypetooltip);
 
104
    return;
 
105
}
 
106
 
 
107
/**
 
108
    \return  Whether this extension checks out
 
109
        \brief   Validate this extension
 
110
 
 
111
        This function checks to make sure that the output extension has
 
112
        a filename extension and a MIME type.  Then it calls the parent
 
113
        class' check function which also checks out the implmentation.
 
114
*/
 
115
bool
 
116
Output::check (void)
 
117
{
 
118
        if (extension == NULL)
 
119
                return FALSE;
 
120
        if (mimetype == NULL)
 
121
                return FALSE;
 
122
 
 
123
        return Extension::check();
 
124
}
 
125
 
 
126
/**
 
127
    \return  IETF mime-type for the extension
 
128
        \brief   Get the mime-type that describes this extension
 
129
*/
 
130
gchar *
 
131
Output::get_mimetype(void)
 
132
{
 
133
    return mimetype;
 
134
}
 
135
 
 
136
/**
 
137
    \return  Filename extension for the extension
 
138
        \brief   Get the filename extension for this extension
 
139
*/
 
140
gchar *
 
141
Output::get_extension(void)
 
142
{
 
143
    return extension;
 
144
}
 
145
 
 
146
/**
 
147
    \return  The name of the filetype supported
 
148
        \brief   Get the name of the filetype supported
 
149
*/
 
150
gchar *
 
151
Output::get_filetypename(void)
 
152
{
 
153
    if (filetypename != NULL)
 
154
        return filetypename;
 
155
    else
 
156
        return get_name();
 
157
}
 
158
 
 
159
/**
 
160
    \return  Tooltip giving more information on the filetype
 
161
        \brief   Get the tooltip for more information on the filetype
 
162
*/
 
163
gchar *
 
164
Output::get_filetypetooltip(void)
 
165
{
 
166
    return filetypetooltip;
 
167
}
 
168
 
 
169
/**
 
170
    \return  A dialog to get settings for this extension
 
171
        \brief   Create a dialog for preference for this extension
 
172
 
 
173
        Calls the implementation to get the preferences.
 
174
*/
 
175
bool
 
176
Output::prefs (void)
 
177
{
 
178
    if (!loaded())
 
179
        set_state(Extension::STATE_LOADED);
 
180
    if (!loaded()) return false;
 
181
 
 
182
    Gtk::Widget * controls;
 
183
    controls = imp->prefs_output(this);
 
184
    if (controls == NULL) {
 
185
        // std::cout << "No preferences for Output" << std::endl;
 
186
        return true;
 
187
    }
 
188
 
 
189
    PrefDialog * dialog = new PrefDialog(this->get_name(), this->get_help(), controls);
 
190
    int response = dialog->run();
 
191
    dialog->hide();
 
192
 
 
193
    delete dialog;
 
194
 
 
195
    if (response == Gtk::RESPONSE_OK) return true;
 
196
    return false;
 
197
}
 
198
 
 
199
/**
 
200
    \return  None
 
201
        \brief   Save a document as a file
 
202
        \param   doc  Document to save
 
203
        \param   filename  File to save the document as
 
204
 
 
205
        This function does a little of the dirty work involved in saving
 
206
        a document so that the implementation only has to worry about geting
 
207
        bits on the disk.
 
208
 
 
209
        The big thing that it does is remove and read the fields that are
 
210
        only used at runtime and shouldn't be saved.  One that may surprise
 
211
        people is the output extension.  This is not saved so that the IDs
 
212
        could be changed, and old files will still work properly.
 
213
*/
 
214
void
 
215
Output::save(SPDocument *doc, gchar const *filename)
 
216
{
 
217
        try {
 
218
            imp->save(this, doc, filename);
 
219
        }
 
220
        catch (...) {
 
221
            g_warning("There was an error saving the file.");
 
222
        }
 
223
 
 
224
        return;
 
225
}
 
226
 
 
227
} }  /* namespace Inkscape, Extension */
 
228
 
 
229
/*
 
230
  Local Variables:
 
231
  mode:c++
 
232
  c-file-style:"stroustrup"
 
233
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
 
234
  indent-tabs-mode:nil
 
235
  fill-column:99
 
236
  End:
 
237
*/
 
238
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :