Code

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