Code

fix parameter ranges, copyedit
[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     if (_doc) {
32         const GSList *current = sp_document_get_resource_list( _doc, "iccprofile" );
33         while ( current ) {
34             newList.push_back(SP_OBJECT(current->data));
35             current = g_slist_next(current);
36         }
37     }
38     sort( newList.begin(), newList.end() );
40     std::vector<SPObject*> diff1;
41     std::set_difference( _knownProfiles.begin(), _knownProfiles.end(), newList.begin(), newList.end(),
42                          std::insert_iterator<std::vector<SPObject*> >(diff1, diff1.begin()) );
44     std::vector<SPObject*> diff2;
45     std::set_difference( newList.begin(), newList.end(), _knownProfiles.begin(), _knownProfiles.end(),
46                          std::insert_iterator<std::vector<SPObject*> >(diff2, diff2.begin()) );
48     if ( !diff1.empty() ) {
49         for ( std::vector<SPObject*>::iterator it = diff1.begin(); it < diff1.end(); ++it ) {
50             SPObject* tmp = *it;
51             _knownProfiles.erase( remove(_knownProfiles.begin(), _knownProfiles.end(), tmp), _knownProfiles.end() );
52             if ( includes(tmp) ) {
53                 _removeOne(tmp);
54             }
55         }
56     }
58     if ( !diff2.empty() ) {
59         for ( std::vector<SPObject*>::iterator it = diff2.begin(); it < diff2.end(); ++it ) {
60             SPObject* tmp = *it;
61             _knownProfiles.push_back(tmp);
62             _addOne(tmp);
63         }
64         sort( _knownProfiles.begin(), _knownProfiles.end() );
65     }
66 }
68 ColorProfile* ProfileManager::find(gchar const* name)
69 {
70     ColorProfile* match = 0;
71     if ( name ) {
72         unsigned int howMany = childCount(NULL);
73         for ( unsigned int index = 0; index < howMany; index++ ) {
74             SPObject *obj = nthChildOf(NULL, index);
75             ColorProfile* prof = reinterpret_cast<ColorProfile*>(obj);
76             if ( prof && prof->name && !strcmp(name, prof->name) ) {
77                 match = prof;
78                 break;
79             }
80         }
81     }
82     return match;
83 }
85 }
88 /*
89   Local Variables:
90   mode:c++
91   c-file-style:"stroustrup"
92   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
93   indent-tabs-mode:nil
94   fill-column:99
95   End:
96 */
97 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :