1 /*
2 * Inkscape::ProfileManager - a view of a document's color profiles.
3 *
4 * Copyright 2007 Jon A. Cruz <jon@joncruz.org>
5 * Abhishek Sharma
6 *
7 * Released under GNU GPL, read the file 'COPYING' for more information
8 */
10 #include <algorithm>
12 #include "profile-manager.h"
13 #include "document.h"
14 #include "color-profile.h"
16 namespace Inkscape {
18 ProfileManager::ProfileManager(SPDocument *document) :
19 _doc(document),
20 _knownProfiles()
21 {
22 _resource_connection = _doc->connectResourcesChanged( "iccprofile", sigc::mem_fun(*this, &ProfileManager::_resourcesChanged) );
23 }
25 ProfileManager::~ProfileManager()
26 {
27 _resource_connection.disconnect();
28 _doc = 0;
29 }
31 void ProfileManager::_resourcesChanged()
32 {
33 std::vector<SPObject*> newList;
34 if (_doc) {
35 const GSList *current = _doc->getResourceList( "iccprofile" );
36 while ( current ) {
37 newList.push_back(SP_OBJECT(current->data));
38 current = g_slist_next(current);
39 }
40 }
41 sort( newList.begin(), newList.end() );
43 std::vector<SPObject*> diff1;
44 std::set_difference( _knownProfiles.begin(), _knownProfiles.end(), newList.begin(), newList.end(),
45 std::insert_iterator<std::vector<SPObject*> >(diff1, diff1.begin()) );
47 std::vector<SPObject*> diff2;
48 std::set_difference( newList.begin(), newList.end(), _knownProfiles.begin(), _knownProfiles.end(),
49 std::insert_iterator<std::vector<SPObject*> >(diff2, diff2.begin()) );
51 if ( !diff1.empty() ) {
52 for ( std::vector<SPObject*>::iterator it = diff1.begin(); it < diff1.end(); ++it ) {
53 SPObject* tmp = *it;
54 _knownProfiles.erase( remove(_knownProfiles.begin(), _knownProfiles.end(), tmp), _knownProfiles.end() );
55 if ( includes(tmp) ) {
56 _removeOne(tmp);
57 }
58 }
59 }
61 if ( !diff2.empty() ) {
62 for ( std::vector<SPObject*>::iterator it = diff2.begin(); it < diff2.end(); ++it ) {
63 SPObject* tmp = *it;
64 _knownProfiles.push_back(tmp);
65 _addOne(tmp);
66 }
67 sort( _knownProfiles.begin(), _knownProfiles.end() );
68 }
69 }
71 ColorProfile* ProfileManager::find(gchar const* name)
72 {
73 ColorProfile* match = 0;
74 if ( name ) {
75 unsigned int howMany = childCount(NULL);
76 for ( unsigned int index = 0; index < howMany; index++ ) {
77 SPObject *obj = nthChildOf(NULL, index);
78 ColorProfile* prof = reinterpret_cast<ColorProfile*>(obj);
79 if ( prof && prof->name && !strcmp(name, prof->name) ) {
80 match = prof;
81 break;
82 }
83 }
84 }
85 return match;
86 }
88 }
91 /*
92 Local Variables:
93 mode:c++
94 c-file-style:"stroustrup"
95 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
96 indent-tabs-mode:nil
97 fill-column:99
98 End:
99 */
100 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :