c2d3446296ed450f20e41e2526a15fa262922766
1 /*
2 * Inkscape::ProfileManager - a view of a document's color profiles.
3 *
4 * Copyright 2007 Jon A. Cruz <jon@joncruz.org>
5 *
6 * Released under GNU GPL, read the file 'COPYING' for more information
7 */
9 #include <algorithm>
11 #include "profile-manager.h"
12 #include "document.h"
14 namespace Inkscape {
16 ProfileManager::ProfileManager(SPDocument *document) :
17 _doc(document),
18 _knownProfiles()
19 {
20 _resource_connection = sp_document_resources_changed_connect( _doc, "iccprofile", sigc::mem_fun(*this, &ProfileManager::_resourcesChanged) );
21 }
23 ProfileManager::~ProfileManager()
24 {
25 }
27 void ProfileManager::_resourcesChanged()
28 {
29 std::vector<SPObject*> newList;
30 const GSList *current = sp_document_get_resource_list( _doc, "iccprofile" );
31 while ( current ) {
32 newList.push_back(SP_OBJECT(current->data));
33 current = g_slist_next(current);
34 }
35 sort( newList.begin(), newList.end() );
37 std::vector<SPObject*> diff1;
38 std::set_difference( _knownProfiles.begin(), _knownProfiles.end(), newList.begin(), newList.end(),
39 std::insert_iterator<std::vector<SPObject*> >(diff1, diff1.begin()) );
41 std::vector<SPObject*> diff2;
42 std::set_difference( newList.begin(), newList.end(), _knownProfiles.begin(), _knownProfiles.end(),
43 std::insert_iterator<std::vector<SPObject*> >(diff2, diff2.begin()) );
45 if ( !diff1.empty() ) {
46 for ( std::vector<SPObject*>::iterator it = diff1.begin(); it < diff1.end(); ++it ) {
47 SPObject* tmp = *it;
48 _knownProfiles.erase( remove(_knownProfiles.begin(), _knownProfiles.end(), tmp), _knownProfiles.end() );
49 if ( includes(tmp) ) {
50 _removeOne(tmp);
51 }
52 }
53 }
55 if ( !diff2.empty() ) {
56 for ( std::vector<SPObject*>::iterator it = diff2.begin(); it < diff2.end(); ++it ) {
57 SPObject* tmp = *it;
58 _knownProfiles.push_back(tmp);
59 _addOne(tmp);
60 }
61 sort( _knownProfiles.begin(), _knownProfiles.end() );
62 }
63 }
66 }
69 /*
70 Local Variables:
71 mode:c++
72 c-file-style:"stroustrup"
73 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
74 indent-tabs-mode:nil
75 fill-column:99
76 End:
77 */
78 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :