Code

Adding function to locate profile by bane
[inkscape.git] / src / profile-manager.cpp
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"
13 #include "color-profile.h"
15 namespace Inkscape {
17 ProfileManager::ProfileManager(SPDocument *document) :
18     _doc(document),
19     _knownProfiles()
20 {
21     _resource_connection = sp_document_resources_changed_connect( _doc, "iccprofile", sigc::mem_fun(*this, &ProfileManager::_resourcesChanged) );
22 }
24 ProfileManager::~ProfileManager()
25 {
26 }
28 void ProfileManager::_resourcesChanged()
29 {
30     std::vector<SPObject*> newList;
31     const GSList *current = sp_document_get_resource_list( _doc, "iccprofile" );
32     while ( current ) {
33         newList.push_back(SP_OBJECT(current->data));
34         current = g_slist_next(current);
35     }
36     sort( newList.begin(), newList.end() );
38     std::vector<SPObject*> diff1;
39     std::set_difference( _knownProfiles.begin(), _knownProfiles.end(), newList.begin(), newList.end(),
40                          std::insert_iterator<std::vector<SPObject*> >(diff1, diff1.begin()) );
42     std::vector<SPObject*> diff2;
43     std::set_difference( newList.begin(), newList.end(), _knownProfiles.begin(), _knownProfiles.end(),
44                          std::insert_iterator<std::vector<SPObject*> >(diff2, diff2.begin()) );
46     if ( !diff1.empty() ) {
47         for ( std::vector<SPObject*>::iterator it = diff1.begin(); it < diff1.end(); ++it ) {
48             SPObject* tmp = *it;
49             _knownProfiles.erase( remove(_knownProfiles.begin(), _knownProfiles.end(), tmp), _knownProfiles.end() );
50             if ( includes(tmp) ) {
51                 _removeOne(tmp);
52             }
53         }
54     }
56     if ( !diff2.empty() ) {
57         for ( std::vector<SPObject*>::iterator it = diff2.begin(); it < diff2.end(); ++it ) {
58             SPObject* tmp = *it;
59             _knownProfiles.push_back(tmp);
60             _addOne(tmp);
61         }
62         sort( _knownProfiles.begin(), _knownProfiles.end() );
63     }
64 }
66 ColorProfile* ProfileManager::find(gchar const* name)
67 {
68     ColorProfile* match = 0;
69     if ( name ) {
70         unsigned int howMany = childCount(NULL);
71         for ( unsigned int index = 0; index < howMany; index++ ) {
72             SPObject *obj = nthChildOf(NULL, index);
73             ColorProfile* prof = reinterpret_cast<ColorProfile*>(obj);
74             if ( prof && prof->name && !strcmp(name, prof->name) ) {
75                 match = prof;
76                 break;
77             }
78         }
79     }
80     return match;
81 }
83 }
86 /*
87   Local Variables:
88   mode:c++
89   c-file-style:"stroustrup"
90   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
91   indent-tabs-mode:nil
92   fill-column:99
93   End:
94 */
95 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :