~valavanisalex/ubuntu/precise/inkscape/fix-943984

« back to all changes in this revision

Viewing changes to inkscape-0.47pre1/src/extension/implementation/script.h

  • 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
 * Code for handling extensions (i.e., scripts)
 
3
 *
 
4
 * Authors:
 
5
 *   Bryce Harrington <bryce@osdl.org>
 
6
 *   Ted Gould <ted@gould.cx>
 
7
 *
 
8
 * Copyright (C) 2002-2005 Authors
 
9
 *
 
10
 * Released under GNU GPL, read the file 'COPYING' for more information
 
11
 */
 
12
 
 
13
#ifndef __INKSCAPE_EXTENSION_IMPEMENTATION_SCRIPT_H__
 
14
#define __INKSCAPE_EXTENSION_IMPEMENTATION_SCRIPT_H__
 
15
 
 
16
#include "implementation.h"
 
17
#include <gtkmm/messagedialog.h>
 
18
 
 
19
namespace Inkscape {
 
20
namespace XML {
 
21
class Node;
 
22
}
 
23
}
 
24
 
 
25
 
 
26
namespace Inkscape {
 
27
namespace Extension {
 
28
namespace Implementation {
 
29
 
 
30
 
 
31
 
 
32
/**
 
33
 * Utility class used for loading and launching script extensions
 
34
 */
 
35
class Script : public Implementation {
 
36
 
 
37
public:
 
38
 
 
39
    /**
 
40
     *
 
41
     */
 
42
    Script(void);
 
43
 
 
44
    /**
 
45
     *
 
46
     */
 
47
    virtual ~Script();
 
48
 
 
49
 
 
50
    /**
 
51
     *
 
52
     */
 
53
    virtual bool load(Inkscape::Extension::Extension *module);
 
54
 
 
55
    /**
 
56
     *
 
57
     */
 
58
    virtual void unload(Inkscape::Extension::Extension *module);
 
59
 
 
60
    /**
 
61
     *
 
62
     */
 
63
    virtual bool check(Inkscape::Extension::Extension *module);
 
64
 
 
65
        ImplementationDocumentCache * newDocCache (Inkscape::Extension::Extension * ext, Inkscape::UI::View::View * view);
 
66
 
 
67
    /**
 
68
     *
 
69
     */
 
70
    virtual Gtk::Widget *prefs_input(Inkscape::Extension::Input *module,
 
71
                                     gchar const *filename);
 
72
 
 
73
    /**
 
74
     *
 
75
     */
 
76
    virtual SPDocument *open(Inkscape::Extension::Input *module,
 
77
                             gchar const *filename);
 
78
 
 
79
    /**
 
80
     *
 
81
     */
 
82
    virtual Gtk::Widget *prefs_output(Inkscape::Extension::Output *module);
 
83
 
 
84
    /**
 
85
     *
 
86
     */
 
87
    virtual void save(Inkscape::Extension::Output *module,
 
88
                      SPDocument *doc,
 
89
                      gchar const *filename);
 
90
 
 
91
    /**
 
92
     *
 
93
     */
 
94
    virtual void effect(Inkscape::Extension::Effect *module,
 
95
                        Inkscape::UI::View::View *doc,
 
96
                                                ImplementationDocumentCache * docCache);
 
97
 
 
98
    virtual bool cancelProcessing (void);
 
99
 
 
100
private:
 
101
    bool _canceled;
 
102
    Glib::Pid _pid;
 
103
    Glib::RefPtr<Glib::MainLoop> _main_loop;
 
104
 
 
105
    /**
 
106
     * The command that has been dirived from
 
107
     * the configuration file with appropriate directories
 
108
     */
 
109
    std::list<std::string> command;
 
110
 
 
111
     /**
 
112
      * This is the extension that will be used
 
113
      * as the helper to read in or write out the
 
114
      * data
 
115
      */
 
116
    Glib::ustring helper_extension;
 
117
 
 
118
    /**
 
119
     * Just a quick function to find and resolve relative paths for
 
120
     * the incoming scripts
 
121
     */
 
122
    Glib::ustring solve_reldir (Inkscape::XML::Node *reprin);
 
123
 
 
124
    /**
 
125
     *
 
126
     */
 
127
    bool check_existance (const Glib::ustring &command);
 
128
 
 
129
    /**
 
130
     *
 
131
     */
 
132
    void copy_doc (Inkscape::XML::Node * olddoc,
 
133
                   Inkscape::XML::Node * newdoc);
 
134
 
 
135
    /**
 
136
     *
 
137
     */
 
138
    void checkStderr (const Glib::ustring &filename, 
 
139
                      Gtk::MessageType type,
 
140
                      const Glib::ustring &message);
 
141
 
 
142
 
 
143
    class file_listener {
 
144
        Glib::ustring _string;
 
145
        sigc::connection _conn;
 
146
        Glib::RefPtr<Glib::IOChannel> _channel;
 
147
        Glib::RefPtr<Glib::MainLoop> _main_loop;
 
148
        bool _dead;
 
149
        
 
150
    public:
 
151
        file_listener () : _dead(false) { };
 
152
        virtual ~file_listener () {
 
153
            _conn.disconnect();
 
154
        };
 
155
 
 
156
        bool isDead () { return _dead; }
 
157
 
 
158
        void init (int fd, Glib::RefPtr<Glib::MainLoop> main) {
 
159
            _channel = Glib::IOChannel::create_from_fd(fd);
 
160
            _channel->set_encoding();
 
161
            _conn = Glib::signal_io().connect(sigc::mem_fun(*this, &file_listener::read), _channel, Glib::IO_IN | Glib::IO_HUP | Glib::IO_ERR);
 
162
            _main_loop = main;
 
163
 
 
164
            return;
 
165
        };
 
166
 
 
167
        bool read (Glib::IOCondition condition) {
 
168
            if (condition != Glib::IO_IN) {
 
169
                _main_loop->quit();
 
170
                return false;
 
171
            }
 
172
 
 
173
            Glib::IOStatus status;
 
174
            Glib::ustring out;
 
175
            status = _channel->read_line(out);
 
176
            _string += out;
 
177
 
 
178
            if (status != Glib::IO_STATUS_NORMAL) {
 
179
                _main_loop->quit();
 
180
                _dead = true;
 
181
                return false;
 
182
            }
 
183
 
 
184
            return true;
 
185
        };
 
186
 
 
187
        // Note, doing a copy here, on purpose
 
188
        Glib::ustring string (void) { return _string; };
 
189
 
 
190
        void toFile (const Glib::ustring &name) {
 
191
            Glib::RefPtr<Glib::IOChannel> stdout_file = Glib::IOChannel::create_from_file(name, "w");
 
192
            stdout_file->set_encoding();
 
193
            stdout_file->write(_string);
 
194
            return;
 
195
        };
 
196
    };
 
197
 
 
198
    int execute (const std::list<std::string> &in_command,
 
199
                 const std::list<std::string> &in_params,
 
200
                 const Glib::ustring &filein,
 
201
                 file_listener &fileout);
 
202
 
 
203
        void pump_events (void);
 
204
 
 
205
        /** \brief  A definition of an interpreter, which can be specified
 
206
                    in the INX file, but we need to know what to call */
 
207
        struct interpreter_t {
 
208
                        gchar const *identity;    /**< The ID that is in the INX file */
 
209
                        gchar const *prefstring;  /**< The preferences key that can override the default */
 
210
                        gchar const *defaultval;  /**< The default value if there are no preferences */
 
211
        };
 
212
    static interpreter_t const interpreterTab[];
 
213
 
 
214
        Glib::ustring resolveInterpreterExecutable(const Glib::ustring &interpNameArg);
 
215
 
 
216
}; // class Script
 
217
 
 
218
 
 
219
 
 
220
 
 
221
 
 
222
}  // namespace Implementation
 
223
}  // namespace Extension
 
224
}  // namespace Inkscape
 
225
 
 
226
#endif /* __INKSCAPE_EXTENSION_IMPEMENTATION_SCRIPT_H__ */
 
227
 
 
228
/*
 
229
  Local Variables:
 
230
  mode:c++
 
231
  c-file-style:"stroustrup"
 
232
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
 
233
  indent-tabs-mode:nil
 
234
  fill-column:99
 
235
  End:
 
236
*/
 
237
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :