~centralelyon2010/inkscape/imagelinks2

« back to all changes in this revision

Viewing changes to src/ui/dialog/document-properties.cpp

  • Committer: Ted Gould
  • Date: 2008-11-21 05:24:08 UTC
  • Revision ID: ted@canonical.com-20081121052408-tilucis2pjrrpzxx
MergeĀ fromĀ fe-moved

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#include "ui/widget/scalar-unit.h"
27
27
 
28
28
#include "xml/node-event-vector.h"
 
29
#include "xml/repr.h"
29
30
#include "helper/units.h"
30
31
#include "preferences.h"
31
32
 
32
33
#include "inkscape.h"
 
34
#include "io/sys.h"
33
35
#include "verbs.h"
34
36
#include "document.h"
35
37
#include "desktop-handles.h"
36
38
#include "desktop.h"
37
39
#include "sp-namedview.h"
 
40
#include "sp-object-repr.h"
 
41
#include "sp-root.h"
38
42
#include "widgets/icon.h"
39
43
#include "document-properties.h"
40
44
 
41
45
#include "display/canvas-grid.h"
42
46
 
 
47
#if ENABLE_LCMS
 
48
#include <lcms.h>
 
49
//#include "color-profile-fns.h"
 
50
#include "color-profile.h"
 
51
#endif // ENABLE_LCMS
 
52
 
43
53
using std::pair;
44
54
 
45
55
namespace Inkscape {
82
92
DocumentProperties::DocumentProperties()
83
93
    : UI::Widget::Panel ("", "/dialogs/documentoptions", SP_VERB_DIALOG_NAMEDVIEW),
84
94
      _page_page(1, 1, true, true), _page_guides(1, 1),
85
 
      _page_snap(1, 1), _page_snap_dtls(1, 1),
 
95
      _page_snap(1, 1), _page_snap_dtls(1, 1), _page_cms(1, 1),
86
96
    //---------------------------------------------------------------
87
97
      _rcb_canb(_("Show page _border"), _("If set, rectangular page border is shown"), "showborder", _wr, false),
88
98
      _rcb_bord(_("Border on _top of drawing"), _("If set, border is always on top of the drawing"), "borderlayer", _wr, false),
100
110
      _rcp_hgui(_("_Highlight color:"), _("Highlighted guideline color"), _("Color of a guideline when it is under mouse"), "guidehicolor", "guidehiopacity", _wr),
101
111
    //---------------------------------------------------------------
102
112
      _rcbs(_("_Enable snapping"), _("Toggle snapping on or off"), "inkscape:snap-global", _wr),
103
 
      _rcbsi(_("_Enable snap indicator"), _("After snapping, a symbol is drawn at the point that has snapped"), "inkscape:snap-indicator", _wr),
104
113
      _rcbsnbb(_("_Bounding box corners"), _("Only available in the selector tool: snap bounding box corners to guides, to grids, and to other bounding boxes (but not to nodes or paths)"),
105
114
                  "inkscape:snap-bbox", _wr),
106
115
      _rcbsnn(_("_Nodes"), _("Snap nodes (e.g. path nodes, special points in shapes, gradient handles, text base points, transformation origins, etc.) to guides, to grids, to paths and to other nodes"),
135
144
    _notebook.append_page(_grids_vbox,     _("Grids"));
136
145
    _notebook.append_page(_page_snap,      _("Snap"));
137
146
    _notebook.append_page(_page_snap_dtls, _("Snap points"));
 
147
    _notebook.append_page(_page_cms, _("Color Management"));
138
148
 
139
149
    build_page();
140
150
    build_guides();
141
151
    build_gridspage();
142
152
    build_snap();
143
153
    build_snap_dtls();
 
154
#if ENABLE_LCMS
 
155
    build_cms();
 
156
#endif // ENABLE_LCMS
144
157
 
145
158
    _grids_button_new.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::onNewGrid));
146
159
    _grids_button_remove.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::onRemoveGrid));
312
325
    slaves.clear();
313
326
    slaves.push_back(&_rcbsnn);
314
327
    slaves.push_back(&_rcbsnbb);
315
 
    slaves.push_back(&_rcbsi);
316
 
 
317
328
    _rcbs.setSlaveWidgets(slaves);
318
329
 
319
330
    Gtk::Label *label_g = manage (new Gtk::Label);
331
342
    {
332
343
        label_g,            0,
333
344
        0,                  &_rcbs,
334
 
        0,                  &_rcbsi,
335
345
        0,                  0,
336
346
        label_w,            0,
337
347
        0,                  &_rcbsnn,
375
385
        0,                  0,
376
386
        label_m,            0,
377
387
        0,                  &_rcbic,
378
 
        0,                                      &_rcbsm
 
388
        0,                  &_rcbsm
379
389
    };
380
390
 
381
391
    attach_all(_page_snap_dtls.table(), array, G_N_ELEMENTS(array));
382
392
}
383
393
 
 
394
#if ENABLE_LCMS
 
395
static void
 
396
lcms_profile_get_name (cmsHPROFILE   profile, const gchar **name)
 
397
{
 
398
  if (profile)
 
399
    {
 
400
      *name = cmsTakeProductDesc (profile);
 
401
 
 
402
      if (! *name)
 
403
        *name = cmsTakeProductName (profile);
 
404
 
 
405
      if (*name && ! g_utf8_validate (*name, -1, NULL))
 
406
        *name = _("(invalid UTF-8 string)");
 
407
    }
 
408
  else
 
409
    {
 
410
      *name = _("None");
 
411
    }
 
412
}
 
413
 
 
414
void
 
415
DocumentProperties::populate_available_profiles(){
 
416
 
 
417
    // add "None"
 
418
/*    Gtk::MenuItem *i = new Gtk::MenuItem();
 
419
    i->show();
 
420
 
 
421
    i->set_data("filepath", NULL);
 
422
    i->set_data("name", _("None"));
 
423
 
 
424
    Gtk::HBox *hb = new Gtk::HBox(false,  0);
 
425
    hb->show();
 
426
 
 
427
    Gtk::Label *l = new Gtk::Label( _("None") );
 
428
    l->show();
 
429
    l->set_alignment(0.0, 0.5);
 
430
 
 
431
    hb->pack_start(*l, true, true, 0);
 
432
 
 
433
    hb->show();
 
434
    i->add(*hb);
 
435
    _menu.append(*i);
 
436
*/
 
437
    std::list<gchar *> sources;
 
438
    sources.push_back( profile_path("color/icc") );
 
439
    //sources.push_back( g_strdup(INKSCAPE_COLORPROFILESDIR) );
 
440
 
 
441
    int index = 1;
 
442
 
 
443
    // Use this loop to iterate through a list of possible document locations.
 
444
    while (!sources.empty()) {
 
445
        gchar *dirname = sources.front();
 
446
 
 
447
        if ( Inkscape::IO::file_test( dirname, G_FILE_TEST_EXISTS )
 
448
            && Inkscape::IO::file_test( dirname, G_FILE_TEST_IS_DIR )) {
 
449
            GError *err = 0;
 
450
            GDir *directory = g_dir_open(dirname, 0, &err);
 
451
            if (!directory) {
 
452
                gchar *safeDir = Inkscape::IO::sanitizeString(dirname);
 
453
                g_warning(_("Color profiles directory (%s) is unavailable."), safeDir);
 
454
                g_free(safeDir);
 
455
            } else {
 
456
                gchar *filename = 0;
 
457
                while ((filename = (gchar *)g_dir_read_name(directory)) != NULL) {
 
458
                    gchar* lower = g_ascii_strdown( filename, -1 );
 
459
                    gchar* full = g_build_filename(dirname, filename, NULL);
 
460
                    if ( !Inkscape::IO::file_test( full, G_FILE_TEST_IS_DIR ) ) {
 
461
                        cmsHPROFILE hProfile = cmsOpenProfileFromFile(full, "r");
 
462
                        if (hProfile != NULL){
 
463
                            const gchar* name;
 
464
                            lcms_profile_get_name(hProfile, &name);
 
465
                            Gtk::MenuItem* mi = new Gtk::MenuItem();
 
466
                            mi->set_data("filepath", g_strdup(full));
 
467
                            mi->set_data("name", g_strdup(name));
 
468
                            Gtk::HBox *hbox = new Gtk::HBox();
 
469
                            hbox->show();
 
470
                            Gtk::Label* lbl = manage(new Gtk::Label(name));
 
471
                            lbl->show();
 
472
                            hbox->pack_start(*lbl, true, true, 0);
 
473
                            mi->add(*hbox);
 
474
                            mi->show_all();
 
475
                            _menu.append(*mi);
 
476
        //                    g_free((void*)name);
 
477
                        }
 
478
                        cmsCloseProfile(hProfile);
 
479
                        index++;
 
480
                    }
 
481
                    g_free(full);
 
482
                    g_free(lower);
 
483
                }
 
484
                g_dir_close(directory);
 
485
            }
 
486
        }
 
487
 
 
488
        // toss the dirname
 
489
        g_free(dirname);
 
490
        sources.pop_front();
 
491
    }
 
492
    _menu.show_all();
 
493
}
 
494
 
 
495
void
 
496
DocumentProperties::onEmbedProfile()
 
497
{
 
498
//store this profile in the SVG document (create <color-profile> element in the XML)
 
499
    SPDesktop *desktop = SP_ACTIVE_DESKTOP;
 
500
    if (!desktop){
 
501
        g_warning("No active desktop");
 
502
        return;
 
503
    }
 
504
    Inkscape::XML::Document *xml_doc = sp_document_repr_doc(desktop->doc());
 
505
    Inkscape::XML::Node *cprofRepr = xml_doc->createElement("svg:color-profile");
 
506
    cprofRepr->setAttribute("name", (gchar*) _menu.get_active()->get_data("name"));
 
507
    cprofRepr->setAttribute("xlink:href", (gchar*) _menu.get_active()->get_data("filepath"));
 
508
 
 
509
    /* Checks whether there is a defs element. Creates it when needed */
 
510
    Inkscape::XML::Node *defsRepr = sp_repr_lookup_name(xml_doc, "svg:defs");
 
511
    if (!defsRepr){
 
512
        defsRepr = xml_doc->createElement("svg:defs");
 
513
        xml_doc->root()->addChild(defsRepr, NULL);
 
514
    }
 
515
 
 
516
    g_assert(SP_ROOT(desktop->doc()->root)->defs);
 
517
    defsRepr->addChild(cprofRepr, NULL);
 
518
 
 
519
    Inkscape::GC::release(defsRepr);
 
520
 
 
521
    // inform the document, so we can undo
 
522
    sp_document_done(desktop->doc(), SP_VERB_EMBED_COLOR_PROFILE, _("Embed Color Profile"));
 
523
 
 
524
    populate_embedded_profiles_box();
 
525
}
 
526
 
 
527
void
 
528
DocumentProperties::populate_embedded_profiles_box()
 
529
{
 
530
    _EmbeddedProfilesListStore->clear();
 
531
    const GSList *current = sp_document_get_resource_list( SP_ACTIVE_DOCUMENT, "iccprofile" );
 
532
    while ( current ) {
 
533
        SPObject* obj = SP_OBJECT(current->data);
 
534
        Inkscape::ColorProfile* prof = reinterpret_cast<Inkscape::ColorProfile*>(obj);
 
535
        Gtk::TreeModel::Row row = *(_EmbeddedProfilesListStore->append());
 
536
        row[_EmbeddedProfilesListColumns.nameColumn] = prof->name;
 
537
//        row[_EmbeddedProfilesListColumns.previewColumn] = "Color Preview";
 
538
        current = g_slist_next(current);
 
539
    }
 
540
}
 
541
 
 
542
 
 
543
void
 
544
DocumentProperties::build_cms()
 
545
{
 
546
    _page_cms.show();
 
547
 
 
548
    Gtk::Label *label_embed= manage (new Gtk::Label);
 
549
    label_embed->set_markup (_("<b>Embedded Color Profiles:</b>"));
 
550
    Gtk::Label *label_avail = manage (new Gtk::Label);
 
551
    label_avail->set_markup (_("<b>Available Color Profiles:</b>"));
 
552
 
 
553
    _embed_btn.set_label("Embed Profile");
 
554
 
 
555
    Gtk::Widget *const array[] =
 
556
    {
 
557
        label_embed,          0,
 
558
        &_EmbeddedProfilesListScroller,      0,
 
559
        label_avail,        0,
 
560
        &_combo_avail,        &_embed_btn,
 
561
    };
 
562
 
 
563
    attach_all(_page_cms.table(), array, G_N_ELEMENTS(array));
 
564
 
 
565
    populate_available_profiles();
 
566
 
 
567
    _combo_avail.set_menu(_menu);
 
568
    _combo_avail.set_history(0);
 
569
    _combo_avail.show_all();
 
570
 
 
571
    //# Set up the Embedded Profiles combo box
 
572
    _EmbeddedProfilesListStore = Gtk::ListStore::create(_EmbeddedProfilesListColumns);
 
573
    _EmbeddedProfilesList.set_model(_EmbeddedProfilesListStore);
 
574
    _EmbeddedProfilesList.append_column(_("Profile Name"), _EmbeddedProfilesListColumns.nameColumn);
 
575
//    _EmbeddedProfilesList.append_column(_("Color Preview"), _EmbeddedProfilesListColumns.previewColumn);
 
576
    _EmbeddedProfilesList.set_headers_visible(false);
 
577
    _EmbeddedProfilesList.set_fixed_height_mode(true);
 
578
 
 
579
    populate_embedded_profiles_box();
 
580
 
 
581
    _EmbeddedProfilesListScroller.add(_EmbeddedProfilesList);
 
582
    _EmbeddedProfilesListScroller.set_shadow_type(Gtk::SHADOW_IN);
 
583
    _EmbeddedProfilesListScroller.set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_ALWAYS);
 
584
    _EmbeddedProfilesListScroller.set_size_request(-1, 90);
 
585
 
 
586
    _embed_btn.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::onEmbedProfile));
 
587
}
 
588
#endif // ENABLE_LCMS
 
589
 
384
590
/**
385
591
* Called for _updating_ the dialog (e.g. when a new grid was manually added in XML)
386
592
*/
515
721
    _rsu_gusn.setValue (nv->guidetolerance);
516
722
 
517
723
    _rcbs.setActive (nv->snap_manager.snapprefs.getSnapEnabledGlobally());
518
 
    _rcbsi.setActive (nv->snapindicator);
519
 
 
520
724
    //-----------------------------------------------------------grids page
521
725
 
522
726
    update_gridspage();