Code

Merge and cleanup of GSoC C++-ification project.
[inkscape.git] / src / ui / dialog / document-properties.cpp
index 4e1ddda2e7b2d95dfa4c54205d3ec8f38182d7d4..16212bef7fb830a3830ddfdacf39aa755348226a 100644 (file)
@@ -8,6 +8,8 @@
  *   Jon Phillips <jon@rejon.org>
  *   Ralf Stephan <ralf@ark.in-berlin.de> (Gtkmm)
  *   Diederik van Lierop <mail@diedenrezi.nl>
+ *   Jon A. Cruz <jon@joncruz.org>
+ *   Abhishek Sharma
  *
  * Copyright (C) 2006-2008 Johan Engelen  <johan@shouraizou.nl>
  * Copyright (C) 2000 - 2008 Authors
@@ -103,11 +105,8 @@ DocumentProperties::DocumentProperties()
       _rcp_hgui(_("_Highlight color:"), _("Highlighted guideline color"), _("Color of a guideline when it is under mouse"), "guidehicolor", "guidehiopacity", _wr),
     //---------------------------------------------------------------
       _grids_label_crea("", Gtk::ALIGN_LEFT),
-      //TRANSLATORS: only translate "string" in "context|string".
-      // For more details, see http://developer.gnome.org/doc/API/2.0/glib/glib-I18N.html#Q-:CAPS
-      // "New" refers to grid
-      _grids_button_new(Q_("Grid|_New"), _("Create new grid.")),
-      _grids_button_remove(_("_Remove"), _("Remove selected grid.")),
+      _grids_button_new(C_("Grid", "_New"), _("Create new grid.")),
+      _grids_button_remove(C_("Grid", "_Remove"), _("Remove selected grid.")),
       _grids_label_def("", Gtk::ALIGN_LEFT)
     //---------------------------------------------------------------
 {
@@ -336,49 +335,28 @@ DocumentProperties::populate_available_profiles(){
         delete(*it2);
     }
 
-    std::list<Glib::ustring> sources = ColorProfile::getProfileDirs();
-
-    // Use this loop to iterate through a list of possible document locations.
-    for ( std::list<Glib::ustring>::const_iterator it = sources.begin(); it != sources.end(); ++it ) {
-        if ( Inkscape::IO::file_test( it->c_str(), G_FILE_TEST_EXISTS )
-             && Inkscape::IO::file_test( it->c_str(), G_FILE_TEST_IS_DIR )) {
-            GError *err = 0;
-            GDir *directory = g_dir_open(it->c_str(), 0, &err);
-            if (!directory) {
-                gchar *safeDir = Inkscape::IO::sanitizeString(it->c_str());
-                g_warning(_("Color profiles directory (%s) is unavailable."), safeDir);
-                g_free(safeDir);
-            } else {
-                gchar *filename = 0;
-                while ((filename = (gchar *)g_dir_read_name(directory)) != NULL) {
-                    gchar* full = g_build_filename(it->c_str(), filename, NULL);
-                    if ( !Inkscape::IO::file_test( full, G_FILE_TEST_IS_DIR ) ) {
-                        cmsErrorAction( LCMS_ERROR_SHOW );
-                        cmsHPROFILE hProfile = cmsOpenProfileFromFile(full, "r");
-                        if (hProfile != NULL){
-                            const gchar* name;
-                            lcms_profile_get_name(hProfile, &name);
-                            Gtk::MenuItem* mi = manage(new Gtk::MenuItem());
-                            mi->set_data("filepath", g_strdup(full));
-                            mi->set_data("name", g_strdup(name));
-                            Gtk::HBox *hbox = manage(new Gtk::HBox());
-                            hbox->show();
-                            Gtk::Label* lbl = manage(new Gtk::Label(name));
-                            lbl->show();
-                            hbox->pack_start(*lbl, true, true, 0);
-                            mi->add(*hbox);
-                            mi->show_all();
-                            _menu.append(*mi);
-        //                    g_free((void*)name);
-                            cmsCloseProfile(hProfile);
-                        }
-                    }
-                    g_free(full);
-                }
-                g_dir_close(directory);
-            }
+    std::list<Glib::ustring> files = ColorProfile::getProfileFiles();
+    for ( std::list<Glib::ustring>::const_iterator it = files.begin(); it != files.end(); ++it ) {
+        cmsHPROFILE hProfile = cmsOpenProfileFromFile(it->c_str(), "r");
+        if ( hProfile ){
+            const gchar* name = 0;
+            lcms_profile_get_name(hProfile, &name);
+            Gtk::MenuItem* mi = manage(new Gtk::MenuItem());
+            mi->set_data("filepath", g_strdup(it->c_str()));
+            mi->set_data("name", g_strdup(name));
+            Gtk::HBox *hbox = manage(new Gtk::HBox());
+            hbox->show();
+            Gtk::Label* lbl = manage(new Gtk::Label(name));
+            lbl->show();
+            hbox->pack_start(*lbl, true, true, 0);
+            mi->add(*hbox);
+            mi->show_all();
+            _menu.append(*mi);
+//            g_free((void*)name);
+            cmsCloseProfile(hProfile);
         }
     }
+
     _menu.show_all();
 }
 
@@ -428,7 +406,7 @@ DocumentProperties::linkSelectedProfile()
             g_warning("No color profile available.");
             return;
         }
-        Inkscape::XML::Document *xml_doc = sp_document_repr_doc(desktop->doc());
+        Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc();
         Inkscape::XML::Node *cprofRepr = xml_doc->createElement("svg:color-profile");
         gchar* tmp = static_cast<gchar*>(_menu.get_active()->get_data("name"));
         Glib::ustring nameStr = tmp ? tmp : "profile"; // TODO add some auto-numbering to avoid collisions
@@ -450,7 +428,7 @@ DocumentProperties::linkSelectedProfile()
         //Inkscape::GC::release(defsRepr);
 
         // inform the document, so we can undo
-        SPDocumentUndo::done(desktop->doc(), SP_VERB_EDIT_LINK_COLOR_PROFILE, _("Link Color Profile"));
+        DocumentUndo::done(desktop->doc(), SP_VERB_EDIT_LINK_COLOR_PROFILE, _("Link Color Profile"));
 
         populate_linked_profiles_box();
     }
@@ -460,7 +438,7 @@ void
 DocumentProperties::populate_linked_profiles_box()
 {
     _LinkedProfilesListStore->clear();
-    const GSList *current = SP_ACTIVE_DOCUMENT->get_resource_list( "iccprofile" );
+    const GSList *current = SP_ACTIVE_DOCUMENT->getResourceList( "iccprofile" );
     if (current) _emb_profiles_observer.set(SP_OBJECT(current->data)->parent);
     while ( current ) {
         SPObject* obj = SP_OBJECT(current->data);
@@ -517,15 +495,15 @@ void DocumentProperties::removeSelectedProfile(){
         }
     }
 
-    const GSList *current = SP_ACTIVE_DOCUMENT->get_resource_list( "iccprofile" );
+    const GSList *current = SP_ACTIVE_DOCUMENT->getResourceList( "iccprofile" );
     while ( current ) {
         SPObject* obj = SP_OBJECT(current->data);
         Inkscape::ColorProfile* prof = reinterpret_cast<Inkscape::ColorProfile*>(obj);
         if (!name.compare(prof->name)){
 
-                       //XML Tree being used directly here while it shouldn't be.
+            //XML Tree being used directly here while it shouldn't be.
             sp_repr_unparent(obj->getRepr());
-            SPDocumentUndo::done(SP_ACTIVE_DOCUMENT, SP_VERB_EDIT_REMOVE_COLOR_PROFILE, _("Remove linked color profile"));
+            DocumentUndo::done(SP_ACTIVE_DOCUMENT, SP_VERB_EDIT_REMOVE_COLOR_PROFILE, _("Remove linked color profile"));
         }
         current = g_slist_next(current);
     }
@@ -591,7 +569,7 @@ DocumentProperties::build_cms()
     _LinkedProfilesList.signal_button_release_event().connect_notify(sigc::mem_fun(*this, &DocumentProperties::linked_profiles_list_button_release));
     cms_create_popup_menu(_LinkedProfilesList, sigc::mem_fun(*this, &DocumentProperties::removeSelectedProfile));
 
-    const GSList *current = SP_ACTIVE_DOCUMENT->get_resource_list( "defs" );
+    const GSList *current = SP_ACTIVE_DOCUMENT->getResourceList( "defs" );
     if (current) {
         _emb_profiles_observer.set(SP_OBJECT(current->data)->parent);
     }
@@ -649,7 +627,7 @@ DocumentProperties::build_scripting()
 #endif // ENABLE_LCMS
 
 //TODO: review this observers code:
-    const GSList *current = SP_ACTIVE_DOCUMENT->get_resource_list( "script" );
+    const GSList *current = SP_ACTIVE_DOCUMENT->getResourceList( "script" );
     if (current) {
         _ext_scripts_observer.set(SP_OBJECT(current->data)->parent);
     }
@@ -662,7 +640,7 @@ void DocumentProperties::addExternalScript(){
     if (!desktop){
         g_warning("No active desktop");
     } else {
-        Inkscape::XML::Document *xml_doc = sp_document_repr_doc(desktop->doc());
+        Inkscape::XML::Document *xml_doc = desktop->doc()->getReprDoc();
         Inkscape::XML::Node *scriptRepr = xml_doc->createElement("svg:script");
         scriptRepr->setAttribute("xlink:href", (gchar*) _script_entry.get_text().c_str());
         _script_entry.set_text("");
@@ -670,7 +648,7 @@ void DocumentProperties::addExternalScript(){
         xml_doc->root()->addChild(scriptRepr, NULL);
 
         // inform the document, so we can undo
-        SPDocumentUndo::done(desktop->doc(), SP_VERB_EDIT_ADD_EXTERNAL_SCRIPT, _("Add external script..."));
+        DocumentUndo::done(desktop->doc(), SP_VERB_EDIT_ADD_EXTERNAL_SCRIPT, _("Add external script..."));
 
         populate_external_scripts_box();
     }
@@ -688,15 +666,15 @@ void DocumentProperties::removeExternalScript(){
         }
     }
 
-    const GSList *current = SP_ACTIVE_DOCUMENT->get_resource_list( "script" );
+    const GSList *current = SP_ACTIVE_DOCUMENT->getResourceList( "script" );
     while ( current ) {
         SPObject* obj = SP_OBJECT(current->data);
         SPScript* script = (SPScript*) obj;
         if (name == script->xlinkhref){
 
-                       //XML Tree being used directly here while it shouldn't be.
+            //XML Tree being used directly here while it shouldn't be.
             sp_repr_unparent(obj->getRepr());
-            SPDocumentUndo::done(SP_ACTIVE_DOCUMENT, SP_VERB_EDIT_REMOVE_EXTERNAL_SCRIPT, _("Remove external script"));
+            DocumentUndo::done(SP_ACTIVE_DOCUMENT, SP_VERB_EDIT_REMOVE_EXTERNAL_SCRIPT, _("Remove external script"));
         }
         current = g_slist_next(current);
     }
@@ -707,7 +685,7 @@ void DocumentProperties::removeExternalScript(){
 
 void DocumentProperties::populate_external_scripts_box(){
     _ExternalScriptsListStore->clear();
-    const GSList *current = SP_ACTIVE_DOCUMENT->get_resource_list( "script" );
+    const GSList *current = SP_ACTIVE_DOCUMENT->getResourceList( "script" );
     if (current) _ext_scripts_observer.set(SP_OBJECT(current->data)->parent);
     while ( current ) {
         SPObject* obj = SP_OBJECT(current->data);
@@ -989,7 +967,7 @@ DocumentProperties::onRemoveGrid()
         // delete the grid that corresponds with the selected tab
         // when the grid is deleted from SVG, the SPNamedview handler automatically deletes the object, so found_grid becomes an invalid pointer!
         found_grid->repr->parent()->removeChild(found_grid->repr);
-        SPDocumentUndo::done(sp_desktop_document(dt), SP_VERB_DIALOG_NAMEDVIEW, _("Remove grid"));
+        DocumentUndo::done(sp_desktop_document(dt), SP_VERB_DIALOG_NAMEDVIEW, _("Remove grid"));
     }
 }
 
@@ -1007,4 +985,4 @@ DocumentProperties::onRemoveGrid()
   fill-column:99
   End:
 */
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :