diff --git a/qetapp.cpp b/qetapp.cpp index 4fe21ebd3..204c86fb5 100644 --- a/qetapp.cpp +++ b/qetapp.cpp @@ -840,7 +840,7 @@ void QETApp::slot_updateMenuFenetres() { @return Le chemin du dossier des elements communs */ QString QETApp::commonElementsDir() { - return(QDir::current().path() + "/elements/"); + return(QDir::current().path() + QDir::separator() + "elements" + QDir::separator()); } /** @@ -850,11 +850,7 @@ QString QETApp::commonElementsDir() { @return Le chemin du dossier des elements persos */ QString QETApp::customElementsDir() { -#ifdef Q_OS_WIN32 - return(QETApp::configDir() + "elements\\"); -#else - return(QETApp::configDir() + "elements/"); -#endif + return(QETApp::configDir() + "elements" + QDir::separator()); } /** @@ -872,3 +868,41 @@ QString QETApp::configDir() { return(QDir::homePath() + "/.qet/"); #endif } + +/** + Permet de connaitre le chemin absolu du fichier *.elmt correspondant a un + chemin symbolique (du type custom://outils_pervers/sado_maso/contact_bizarre) + @param sym_path Chaine de caracteres representant le chemin absolu du fichier + @return Une chaine de caracteres vide en cas d'erreur ou le chemin absolu du + fichier *.elmt. +*/ +QString QETApp::realPath(QString &sym_path) { + QString directory; + if (sym_path.startsWith("common://")) { + directory = commonElementsDir(); + } else if (sym_path.startsWith("custom://")) { + directory = customElementsDir(); + } else return(QString()); + return(directory + QDir::toNativeSeparators(sym_path.right(sym_path.length() - 9))); +} + +/** + Construit le chemin symbolique (du type custom://outils_pervers/sado_maso/ + contact_bizarre) correspondant a un fichier. + @param real_pathChaine de caracteres representant le chemin symbolique du fichier + @return Une chaine de caracteres vide en cas d'erreur ou le chemin + symbolique designant l'element. +*/ +QString QETApp::symbolicPath(QString &real_path) { + // recupere les dossier common et custom + QString commond = commonElementsDir(); + QString customd = customElementsDir(); + QString chemin; + // analyse le chemin de fichier passe en parametre + if (real_path.startsWith(commond)) { + chemin = "common://" + real_path.right(real_path.length() - commond.length()); + } else if (real_path.startsWith(customd)) { + chemin = "custom://" + real_path.right(real_path.length() - customd.length()); + } else chemin = QString(); + return(chemin); +} diff --git a/qetapp.h b/qetapp.h index 71cc3b426..c42b922b0 100644 --- a/qetapp.h +++ b/qetapp.h @@ -19,6 +19,8 @@ static QString commonElementsDir(); static QString customElementsDir(); static QString configDir(); + static QString realPath(QString &); + static QString symbolicPath(QString &); public slots: void systray(QSystemTrayIcon::ActivationReason raison); void systrayReduire(); diff --git a/schema.cpp b/schema.cpp index d3c54c221..e2e8b38fc 100644 --- a/schema.cpp +++ b/schema.cpp @@ -145,9 +145,8 @@ QDomDocument Schema::toXml(bool schema) { // type QString chemin_elmt = elmt -> typeId(); - QString type_elmt = QString(""); - if (QFileInfo(chemin_elmt).dir() == dossier_elmts_persos) type_elmt = "perso://"; - element.setAttribute("type", type_elmt + QFileInfo(chemin_elmt).fileName()); + QString type_elmt = QETApp::symbolicPath(chemin_elmt); + element.setAttribute("type", type_elmt); // position, selection et orientation element.setAttribute("x", elmt -> pos().x()); @@ -300,9 +299,7 @@ bool Schema::fromXml(QDomDocument &document, QPointF position) { Element *Schema::elementFromXml(QDomElement &e, QHash &table_id_adr) { // cree un element dont le type correspond à l'id type QString type = e.attribute("type"); - QString chemin_fichier; - if (type.startsWith("perso://")) chemin_fichier = QETApp::customElementsDir() + type.right(type.size()-8); - else chemin_fichier = QETApp::commonElementsDir() + type; + QString chemin_fichier = QETApp::realPath(type); int etat; Element *nvel_elmt = new ElementPerso(chemin_fichier, 0, 0, &etat); if (etat != 0) return(false);