summaryrefslogtreecommitdiffstats
path: root/src/ui/dialog/filedialogimpl-gtkmm.h
blob: 65bb389716abe5f383746ab8cfa70c9f3cc51d1b (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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
/** @file
 * @brief Implementation of the file dialog interfaces defined in filedialogimpl.h
 */
/* Authors:
 *   Bob Jamison
 *   Johan Engelen <johan@shouraizou.nl>
 *   Joel Holdsworth
 *   Bruno Dilly
 *   Other dudes from The Inkscape Organization
 *
 * Copyright (C) 2004-2008 Authors
 * Copyright (C) 2004-2007 The Inkscape Organization
 *
 * Released under GNU GPL, read the file 'COPYING' for more information
 */

#ifndef __FILE_DIALOGIMPL_H__
#define __FILE_DIALOGIMPL_H__

#include "filedialog.h"
#include "extension/system.h"

//General includes
#include <unistd.h>
#include <sys/stat.h>
#include <errno.h>
#include <libxml/parser.h>
#include <libxml/tree.h>


//Gtk includes
#include <glibmm/i18n.h>
#include <glib/gstdio.h>

//Temporary ugly hack
//Remove this after the get_filter() calls in
//show() on both classes are fixed
#include <gtk/gtkfilechooser.h>

//Another hack
#include <gtk/gtkentry.h>
#include <gtk/gtkexpander.h>

//Inkscape includes
#include "extension/input.h"
#include "extension/output.h"
#include "extension/db.h"
#include "inkscape.h"
#include "svg-view-widget.h"

//For export dialog
#include "ui/widget/scalar-unit.h"

namespace Inkscape
{
namespace UI
{
namespace Dialog
{

/*#########################################################################
### Utility
#########################################################################*/
void
fileDialogExtensionToPattern(Glib::ustring &pattern,
                      Glib::ustring &extension);

void
findEntryWidgets(Gtk::Container *parent,
                 std::vector<Gtk::Entry *> &result);

void
findExpanderWidgets(Gtk::Container *parent,
                    std::vector<Gtk::Expander *> &result);

/*#########################################################################
### SVG Preview Widget
#########################################################################*/

class FileType
{
    public:
    FileType() {}
    ~FileType() {}
    Glib::ustring name;
    Glib::ustring pattern;
    Inkscape::Extension::Extension *extension;
};

/**
 * Simple class for displaying an SVG file in the "preview widget."
 * Currently, this is just a wrapper of the sp_svg_view Gtk widget.
 * Hopefully we will eventually replace with a pure Gtkmm widget.
 */
class SVGPreview : public Gtk::VBox
{
public:

    SVGPreview();

    ~SVGPreview();

    bool setDocument(SPDocument *doc);

    bool setFileName(Glib::ustring &fileName);

    bool setFromMem(char const *xmlBuffer);

    bool set(Glib::ustring &fileName, int dialogType);

    bool setURI(URI &uri);

    /**
     * Show image embedded in SVG
     */
    void showImage(Glib::ustring &fileName);

    /**
     * Show the "No preview" image
     */
    void showNoPreview();

    /**
     * Show the "Too large" image
     */
    void showTooLarge(long fileLength);

private:
    /**
     * The svg document we are currently showing
     */
    SPDocument *document;

    /**
     * The sp_svg_view widget
     */
    GtkWidget *viewerGtk;

    /**
     * are we currently showing the "no preview" image?
     */
    bool showingNoPreview;

};

/*#########################################################################
### F I L E     D I A L O G    B A S E    C L A S S
#########################################################################*/

/**
 * This class is the base implementation for the others.  This
 * reduces redundancies and bugs.
 */
class FileDialogBaseGtk : public Gtk::FileChooserDialog
{
public:

    /**
     *
     */
    FileDialogBaseGtk(Gtk::Window& parentWindow, const Glib::ustring &title,
    		Gtk::FileChooserAction dialogType, FileDialogType type, gchar const* preferenceBase) :
        Gtk::FileChooserDialog(parentWindow, title, dialogType),
        preferenceBase(preferenceBase ? preferenceBase : "unknown"),
        _dialogType(type)
    {
        internalSetup();
    }

    /**
     *
     */
    FileDialogBaseGtk(Gtk::Window& parentWindow, const char *title,
                   Gtk::FileChooserAction dialogType, FileDialogType type, gchar const* preferenceBase) :
        Gtk::FileChooserDialog(parentWindow, title, dialogType),
        preferenceBase(preferenceBase ? preferenceBase : "unknown"),
        _dialogType(type)
    {
        internalSetup();
    }

    /**
     *
     */
    virtual ~FileDialogBaseGtk()
        {}

protected:
    void cleanup( bool showConfirmed );

    Glib::ustring const preferenceBase;
    /**
     * What type of 'open' are we? (open, import, place, etc)
     */
    FileDialogType _dialogType;

    /**
     * Our svg preview widget
     */
    SVGPreview svgPreview;

    /**
	 * Child widgets
	 */
    Gtk::CheckButton previewCheckbox;

private:
    void internalSetup();

    /**
     * Callback for user changing preview checkbox
     */
    void _previewEnabledCB();

    /**
     * Callback for seeing if the preview needs to be drawn
     */
    void _updatePreviewCallback();
};




/*#########################################################################
### F I L E    O P E N
#########################################################################*/

/**
 * Our implementation class for the FileOpenDialog interface..
 */
class FileOpenDialogImplGtk : public FileOpenDialog, public FileDialogBaseGtk
{
public:

    FileOpenDialogImplGtk(Gtk::Window& parentWindow,
    		       const Glib::ustring &dir,
                       FileDialogType fileTypes,
                       const Glib::ustring &title);

    virtual ~FileOpenDialogImplGtk();

    bool show();

    Inkscape::Extension::Extension *getSelectionType();

    Glib::ustring getFilename();

    std::vector<Glib::ustring> getFilenames();

	Glib::ustring getCurrentDirectory();

private:

    /**
     *  Create a filter menu for this type of dialog
     */
    void createFilterMenu();

    /**
     * Filter name->extension lookup
     */
    std::map<Glib::ustring, Inkscape::Extension::Extension *> extensionMap;

    /**
     * The extension to use to write this file
     */
    Inkscape::Extension::Extension *extension;

};



//########################################################################
//# F I L E    S A V E
//########################################################################

/**
 * Our implementation of the FileSaveDialog interface.
 */
class FileSaveDialogImplGtk : public FileSaveDialog, public FileDialogBaseGtk
{

public:
    FileSaveDialogImplGtk(Gtk::Window &parentWindow,
                          const Glib::ustring &dir,
                          FileDialogType fileTypes,
                          const Glib::ustring &title,
                          const Glib::ustring &default_key,
                          const gchar* docTitle,
                          const Inkscape::Extension::FileSaveMethod save_method);

    virtual ~FileSaveDialogImplGtk();

    bool show();

    Inkscape::Extension::Extension *getSelectionType();
    virtual void setSelectionType( Inkscape::Extension::Extension * key );

	Glib::ustring getCurrentDirectory();

private:
    //void change_title(const Glib::ustring& title);
    void change_path(const Glib::ustring& path);
    void updateNameAndExtension();

    /**
     * The file save method (essentially whether the dialog was invoked by "Save as ..." or "Save a
     * copy ..."), which is used to determine file extensions and save paths.
     */
    Inkscape::Extension::FileSaveMethod save_method;

    /**
     * Fix to allow the user to type the file name
     */
    Gtk::Entry *fileNameEntry;


    /**
     * Allow the specification of the output file type
     */
    Gtk::ComboBoxText fileTypeComboBox;


    /**
     *  Data mirror of the combo box
     */
    std::vector<FileType> fileTypes;

    //# Child widgets
    Gtk::HBox childBox;
    Gtk::VBox checksBox;

    Gtk::CheckButton fileTypeCheckbox;

    /**
     * Callback for user input into fileNameEntry
     */
    void fileTypeChangedCallback();

    /**
     *  Create a filter menu for this type of dialog
     */
    void createFileTypeMenu();


    /**
     * The extension to use to write this file
     */
    Inkscape::Extension::Extension *extension;

    /**
     * Callback for user input into fileNameEntry
     */
    void fileNameEntryChangedCallback();
};




#ifdef NEW_EXPORT_DIALOG

//########################################################################
//# F I L E     E X P O R T
//########################################################################

/**
 * Our implementation of the FileExportDialog interface.
 */
class FileExportDialogImpl : public FileExportDialog, public FileDialogBaseGtk
{

public:
    FileExportDialogImpl(Gtk::Window& parentWindow,
            const Glib::ustring &dir,
            FileDialogType fileTypes,
            const Glib::ustring &title,
            const Glib::ustring &default_key);

    virtual ~FileExportDialogImpl();

    bool show();

    Inkscape::Extension::Extension *getSelectionType();

    Glib::ustring getFilename();


    /**
     * Return the scope of the export.  One of the enumerated types
     * in ScopeType
     */
    ScopeType getScope()
        {
        if (pageButton.get_active())
            return SCOPE_PAGE;
        else if (selectionButton.get_active())
            return SCOPE_SELECTION;
        else if (customButton.get_active())
            return SCOPE_CUSTOM;
        else
            return SCOPE_DOCUMENT;

        }

    /**
     * Return left side of the exported region
     */
    double getSourceX()
        { return sourceX0Spinner.getValue(); }

    /**
     * Return the top of the exported region
     */
    double getSourceY()
        { return sourceY1Spinner.getValue(); }

    /**
     * Return the width of the exported region
     */
    double getSourceWidth()
        { return sourceWidthSpinner.getValue(); }

    /**
     * Return the height of the exported region
     */
    double getSourceHeight()
        { return sourceHeightSpinner.getValue(); }

    /**
     * Return the units of the coordinates of exported region
     */
    Glib::ustring getSourceUnits()
        { return sourceUnitsSpinner.getUnitAbbr(); }

    /**
     * Return the width of the destination document
     */
    double getDestinationWidth()
        { return destWidthSpinner.getValue(); }

    /**
     * Return the height of the destination document
     */
    double getDestinationHeight()
        { return destHeightSpinner.getValue(); }

    /**
     * Return the height of the exported region
     */
    Glib::ustring getDestinationUnits()
        { return destUnitsSpinner.getUnitAbbr(); }

    /**
     * Return the destination DPI image resulution, if bitmap
     */
    double getDestinationDPI()
        { return destDPISpinner.getValue(); }

    /**
     * Return whether we should use Cairo for rendering
     */
    bool getUseCairo()
        { return cairoButton.get_active(); }

    /**
     * Return whether we should use antialiasing
     */
    bool getUseAntialias()
        { return antiAliasButton.get_active(); }

    /**
     * Return the background color for exporting
     */
    unsigned long getBackground()
        { return backgroundButton.get_color().get_pixel(); }

private:

    /**
     * Fix to allow the user to type the file name
     */
    Gtk::Entry *fileNameEntry;

    //##########################################
    //# EXTRA WIDGET -- SOURCE SIDE
    //##########################################

    Gtk::Frame            sourceFrame;
    Gtk::VBox             sourceBox;

    Gtk::HBox             scopeBox;
    Gtk::RadioButtonGroup scopeGroup;
    Gtk::RadioButton      documentButton;
    Gtk::RadioButton      pageButton;
    Gtk::RadioButton      selectionButton;
    Gtk::RadioButton      customButton;

    Gtk::Table                      sourceTable;
    Inkscape::UI::Widget::Scalar    sourceX0Spinner;
    Inkscape::UI::Widget::Scalar    sourceY0Spinner;
    Inkscape::UI::Widget::Scalar    sourceX1Spinner;
    Inkscape::UI::Widget::Scalar    sourceY1Spinner;
    Inkscape::UI::Widget::Scalar    sourceWidthSpinner;
    Inkscape::UI::Widget::Scalar    sourceHeightSpinner;
    Inkscape::UI::Widget::UnitMenu  sourceUnitsSpinner;


    //##########################################
    //# EXTRA WIDGET -- DESTINATION SIDE
    //##########################################

    Gtk::Frame       destFrame;
    Gtk::VBox        destBox;

    Gtk::Table                      destTable;
    Inkscape::UI::Widget::Scalar    destWidthSpinner;
    Inkscape::UI::Widget::Scalar    destHeightSpinner;
    Inkscape::UI::Widget::Scalar    destDPISpinner;
    Inkscape::UI::Widget::UnitMenu  destUnitsSpinner;

    Gtk::HBox        otherOptionBox;
    Gtk::CheckButton cairoButton;
    Gtk::CheckButton antiAliasButton;
    Gtk::ColorButton backgroundButton;


    /**
     * 'Extra' widget that holds two boxes above
     */
    Gtk::HBox exportOptionsBox;


    //# Child widgets
    Gtk::CheckButton fileTypeCheckbox;

    /**
     * Allow the specification of the output file type
     */
    Gtk::ComboBoxText fileTypeComboBox;


    /**
     *  Data mirror of the combo box
     */
    std::vector<FileType> fileTypes;



    /**
     * Callback for user input into fileNameEntry
     */
    void fileTypeChangedCallback();

    /**
     *  Create a filter menu for this type of dialog
     */
    void createFileTypeMenu();


    bool append_extension;

    /**
     * The extension to use to write this file
     */
    Inkscape::Extension::Extension *extension;

    /**
     * Callback for user input into fileNameEntry
     */
    void fileNameEntryChangedCallback();

    /**
     * Filename that was given
     */
    Glib::ustring myFilename;
};

#endif // NEW_EXPORT_DIALOG

} // namespace Dialog
} // namespace UI
} // namespace Inkscape

#endif /*__FILE_DIALOGIMPL_H__*/

/*
  Local Variables:
  mode:c++
  c-file-style:"stroustrup"
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
  indent-tabs-mode:nil
  fill-column:99
  End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :