diff --git a/src/gpgui/CMakeLists.txt b/src/gpgui/CMakeLists.txt index b278ff74..40606706 100644 --- a/src/gpgui/CMakeLists.txt +++ b/src/gpgui/CMakeLists.txt @@ -38,6 +38,8 @@ add_executable(gpgui gui/xml/xml_attribute.cpp gui/xml/xml_edit.cpp gui/xml/xml_string_edit.cpp + + ${PROJECT_SOURCE_DIR}/translations/translations.qrc ) if(SYSTEM_NAME STREQUAL "FreeBSD") diff --git a/src/gpgui/gui/xml/xml_attribute.cpp b/src/gpgui/gui/xml/xml_attribute.cpp index 3af9afd9..a8b5611f 100644 --- a/src/gpgui/gui/xml/xml_attribute.cpp +++ b/src/gpgui/gui/xml/xml_attribute.cpp @@ -19,6 +19,9 @@ #include "xml_attribute.h" +#include +#include + XmlAttribute::XmlAttribute(const QDomNode &node) { // NOTE: there are two "attributes", attributes of the object and xml attributes const QDomNamedNodeMap attributes = node.attributes(); @@ -31,37 +34,6 @@ XmlAttribute::XmlAttribute(const QDomNode &node) { const QDomNode attribute_use = attributes.namedItem("use"); m_required = (attribute_use.nodeValue() == "required"); - - // Recurse through all ancestors of node and check if any of them have an attribute "name" set to "Properties" - // TODO: might actually not be useful? Delete if not - auto get_is_property = - [node]() -> bool { - QDomNode current = node.parentNode(); - - while (!current.isNull()) { - const QDomNamedNodeMap current_attributes = current.attributes(); - const QDomNode name_node = current_attributes.namedItem("name"); - if (!name_node.isNull()) { - const QString this_name = name_node.nodeValue(); - - if (this_name == "Properties") { - return true; - } - } - - const QDomNode new_current = current.parentNode(); - - if (new_current == current) { - // Reached top node - return false; - } else { - current = new_current; - } - } - - return false; - }; - m_is_property = get_is_property(); } void XmlAttribute::print() const { @@ -69,7 +41,6 @@ void XmlAttribute::print() const { printf(" name=%s\n", qPrintable(m_name)); printf(" type=%s\n", qPrintable(attribute_type_to_string(m_type))); printf(" required=%d\n", m_required); - printf(" properties=%d\n", m_is_property); } @@ -85,8 +56,17 @@ bool XmlAttribute::required() const { return m_required; } -bool XmlAttribute::is_property() const { - return m_is_property; +bool XmlAttribute::hidden() const { + // TODO: there's gotta be some external resource that says which attributes are hidden + static const QSet hidden_attributes = { + "clsid", + "disabled", + "changed", + "uid", + }; + const bool is_hidden = hidden_attributes.contains(name()); + + return is_hidden; } const QHash attribute_type_to_string_map = { @@ -123,3 +103,34 @@ XmlAttributeType string_to_attribute_type(const QString string_raw) { return type; } + +#define DISPLAY_STRING_MACRO(attribute) {attribute, QObject::tr(attribute)}, +#define DISPLAY_STRING_MACRO_2(attribute) attribute "_test" + +QString XmlAttribute::display_string() const { + static const QHash display_strings = { + {"pidl", QObject::tr("pidl DISPLAY_STRING")}, + {"name", QObject::tr("name DISPLAY_STRING")}, + {"image", QObject::tr("image DISPLAY_STRING")}, + {"targetType", QObject::tr("targetType DISPLAY_STRING")}, + {"action", QObject::tr("action DISPLAY_STRING")}, + {"comment", QObject::tr("comment DISPLAY_STRING")}, + {"shortcutKey", QObject::tr("shortcutKey DISPLAY_STRING")}, + {"startIn", QObject::tr("startIn DISPLAY_STRING")}, + {"arguments", QObject::tr("arguments DISPLAY_STRING")}, + {"iconIndex", QObject::tr("iconIndex DISPLAY_STRING")}, + {"targetPath", QObject::tr("targetPath DISPLAY_STRING")}, + {"iconPath", QObject::tr("iconPath DISPLAY_STRING")}, + {"window", QObject::tr("window DISPLAY_STRING")}, + {"shortcutPath", QObject::tr("shortcutPath DISPLAY_STRING")}, + {"desc", QObject::tr("desc DISPLAY_STRING")}, + {"bypassErrors", QObject::tr("bypassErrors DISPLAY_STRING")}, + {"userContext", QObject::tr("userContext DISPLAY_STRING")}, + {"removePolicy", QObject::tr("removePolicy DISPLAY_STRING")}, + }; + static const QString default_value = QObject::tr("UNKNOWN XML ATTRIBUTE NAME"); + + const QString display_string = display_strings.value(name(), default_value); + + return display_string; +} diff --git a/src/gpgui/gui/xml/xml_attribute.h b/src/gpgui/gui/xml/xml_attribute.h index fc72eea6..e32b0787 100644 --- a/src/gpgui/gui/xml/xml_attribute.h +++ b/src/gpgui/gui/xml/xml_attribute.h @@ -41,13 +41,13 @@ public: QString name() const; XmlAttributeType type() const; bool required() const; - bool is_property() const; + bool hidden() const; + QString display_string() const; private: QString m_name; XmlAttributeType m_type; bool m_required; - bool m_is_property; }; QString attribute_type_to_string(const XmlAttributeType type); diff --git a/src/gpgui/gui/xml/xml_editor.cpp b/src/gpgui/gui/xml/xml_editor.cpp index 092e60cf..38d450fe 100644 --- a/src/gpgui/gui/xml/xml_editor.cpp +++ b/src/gpgui/gui/xml/xml_editor.cpp @@ -102,6 +102,10 @@ XmlEditor::XmlEditor(const QString &path_arg) auto edits_layout = new QGridLayout(); for (auto attribute : schema_attributes) { + if (attribute.hidden()) { + continue; + } + auto edit = new XmlStringEdit(attribute); edit->add_to_layout(edits_layout); edit->load(doc); diff --git a/src/gpgui/gui/xml/xml_string_edit.cpp b/src/gpgui/gui/xml/xml_string_edit.cpp index b2ac156b..3c30da65 100644 --- a/src/gpgui/gui/xml/xml_string_edit.cpp +++ b/src/gpgui/gui/xml/xml_string_edit.cpp @@ -48,7 +48,7 @@ void XmlStringEdit::load(const QDomDocument &doc) { } void XmlStringEdit::add_to_layout(QGridLayout *layout) { - const QString label_text = attribute.name() + ":"; + const QString label_text = attribute.display_string() + ":"; const auto label = new QLabel(label_text); // TODO: connect_changed_marker(this, label); @@ -69,16 +69,16 @@ bool XmlStringEdit::changed() const { } bool XmlStringEdit::apply(QDomDocument *doc) { - printf("apply %s\n", qPrintable(attribute.name())); if (!changed()) { printf(" not applying\n"); return true; } - printf("!!!!!!!applying\n"); QDomNode attribute_node = find_attribute_node(*doc, attribute.name()); const QString new_value = edit->text(); attribute_node.setNodeValue(new_value); + printf("apply %s: [%s]=>[%s]\n", qPrintable(attribute.name()), qPrintable(original_value), qPrintable(new_value)); + return true; } diff --git a/src/gpgui/main.cpp b/src/gpgui/main.cpp index 3a10129f..47908221 100644 --- a/src/gpgui/main.cpp +++ b/src/gpgui/main.cpp @@ -34,6 +34,10 @@ int main(int argc, char **argv) { app.setOrganizationName(GPGUI_ORGANIZATION); app.setOrganizationDomain(GPGUI_ORGANIZATION_DOMAIN); + QTranslator translator; + translator.load(QLocale(), QString(), QString(), ":/translations"); + app.installTranslator(&translator); + QCommandLineParser cli_parser; cli_parser.setApplicationDescription(QCoreApplication::applicationName()); cli_parser.addHelpOption(); diff --git a/translations/en.ts b/translations/en.ts index 740506ea..d170a3f9 100644 --- a/translations/en.ts +++ b/translations/en.ts @@ -546,37 +546,41 @@ MainWindow - + File - + File - + File untranslated + File + + + Open - + Exit - + About GPGUI - + GPGUI about - + Loaded PReg file - + Open Directory @@ -967,6 +971,101 @@ Attribute "%1" cannot be empty! + + + pidl DISPLAY_STRING + PIDL + + + + name DISPLAY_STRING + Name + + + + image DISPLAY_STRING + Image + + + + targetType DISPLAY_STRING + Target type + + + + action DISPLAY_STRING + Action + + + + comment DISPLAY_STRING + Comment + + + + shortcutKey DISPLAY_STRING + Shortcut key + + + + startIn DISPLAY_STRING + Start in + + + + arguments DISPLAY_STRING + Arguments + + + + iconIndex DISPLAY_STRING + Icon index + + + + targetPath DISPLAY_STRING + Target path + + + + iconPath DISPLAY_STRING + Icon path + + + + window DISPLAY_STRING + Window + + + + shortcutPath DISPLAY_STRING + Shortcut path + + + + desc DISPLAY_STRING + Description + + + + bypassErrors DISPLAY_STRING + Bypass errors + + + + userContext DISPLAY_STRING + Apply in security context of user + + + + removePolicy DISPLAY_STRING + Remove policy when it stops being applied + + + + UNKNOWN XML ATTRIBUTE NAME + + RenameDialog @@ -1063,7 +1162,7 @@ XmlEditor - + Editing xml file: diff --git a/translations/ru.ts b/translations/ru.ts index 810f5941..c37d783e 100644 --- a/translations/ru.ts +++ b/translations/ru.ts @@ -566,37 +566,37 @@ MainWindow - + File Файл - + Open - + Exit Выход - + About GPGUI - + GPGUI about - + Loaded PReg file - + Open Directory @@ -1058,6 +1058,101 @@ Attribute "%1" cannot be empty! + + + pidl DISPLAY_STRING + + + + + name DISPLAY_STRING + + + + + image DISPLAY_STRING + + + + + targetType DISPLAY_STRING + + + + + action DISPLAY_STRING + + + + + comment DISPLAY_STRING + + + + + shortcutKey DISPLAY_STRING + + + + + startIn DISPLAY_STRING + + + + + arguments DISPLAY_STRING + + + + + iconIndex DISPLAY_STRING + + + + + targetPath DISPLAY_STRING + + + + + iconPath DISPLAY_STRING + + + + + window DISPLAY_STRING + + + + + shortcutPath DISPLAY_STRING + + + + + desc DISPLAY_STRING + + + + + bypassErrors DISPLAY_STRING + + + + + userContext DISPLAY_STRING + + + + + removePolicy DISPLAY_STRING + + + + + UNKNOWN XML ATTRIBUTE NAME + + RenameDialog @@ -1197,7 +1292,7 @@ XmlEditor - + Editing xml file: