Code

Super duper mega (fun!) commit: replaced encoding=utf-8 with fileencoding=utf-8 in...
[inkscape.git] / src / ui / dialog / document-properties.cpp
index 423778276e8fd32752bbe40a0909b0e6225882a3..f22509496ec8685cc96c32241da718e55b660524 100644 (file)
@@ -103,11 +103,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)
     //---------------------------------------------------------------
 {
@@ -222,7 +219,7 @@ DocumentProperties::build_page()
     Gtk::Label* label_bor = manage (new Gtk::Label);
     label_bor->set_markup (_("<b>Border</b>"));
     Gtk::Label *label_for = manage (new Gtk::Label);
-    label_for->set_markup (_("<b>Format</b>"));
+    label_for->set_markup (_("<b>Page Size</b>"));
     _page_sizer.init();
 
     Gtk::Widget *const widget_array[] =
@@ -336,51 +333,64 @@ 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 ) ) {
-                        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();
 }
 
+/**
+ * Cleans up name to remove disallowed characters.
+ * Some discussion at http://markmail.org/message/bhfvdfptt25kgtmj
+ * Allowed ASCII first characters:  ':', 'A'-'Z', '_', 'a'-'z'
+ * Allowed ASCII remaining chars add: '-', '.', '0'-'9', 
+ *
+ * @param str the string to clean up.
+ */
+static void sanitizeName( Glib::ustring& str )
+{
+    if (str.size() > 1) {
+        char val = str.at(0);
+        if (((val < 'A') || (val > 'Z'))
+            && ((val < 'a') || (val > 'z'))
+            && (val != '_')
+            && (val != ':')) {
+            str.replace(0, 1, "-");
+        }
+        for (Glib::ustring::size_type i = 1; i < str.size(); i++) {
+            char val = str.at(i);
+            if (((val < 'A') || (val > 'Z'))
+                && ((val < 'a') || (val > 'z'))
+                && ((val < '0') || (val > '9'))
+                && (val != '_')
+                && (val != ':')
+                && (val != '-')
+                && (val != '.')) {
+                str.replace(i, 1, "-");
+            }
+        }
+    }
+}
+
 void
 DocumentProperties::linkSelectedProfile()
 {
@@ -396,7 +406,10 @@ DocumentProperties::linkSelectedProfile()
         }
         Inkscape::XML::Document *xml_doc = sp_document_repr_doc(desktop->doc());
         Inkscape::XML::Node *cprofRepr = xml_doc->createElement("svg:color-profile");
-        cprofRepr->setAttribute("name", (gchar*) _menu.get_active()->get_data("name"));
+        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
+        sanitizeName(nameStr);
+        cprofRepr->setAttribute("name", nameStr.c_str());
         cprofRepr->setAttribute("xlink:href", (gchar*) _menu.get_active()->get_data("filepath"));
 
         // Checks whether there is a defs element. Creates it when needed
@@ -788,6 +801,7 @@ DocumentProperties::update()
     double const doc_w_px = sp_document_width(sp_desktop_document(dt));
     double const doc_h_px = sp_document_height(sp_desktop_document(dt));
     _page_sizer.setDim (doc_w_px, doc_h_px);
+    _page_sizer.updateFitMarginsUI(SP_OBJECT_REPR(nv));
 
     //-----------------------------------------------------------guide page
 
@@ -965,4 +979,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 :