[pim/incidenceeditor] src: Fix string puzzles in template dialog

Volker Krause <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 245adbb59822d0d2ef4e5183b110a3c412a081df by Volker Krause.
Committed on 05/08/2026 at 16:41.
Pushed by vkrause into branch 'master'.

Fix string puzzles in template dialog

This was previously using a translated incidence type name, attempted to
translate that again, and then puzzled together window titles and default
templates names from it.

The double-translation is obviously not going to work, the string puzzle
happens to work in English but fails e.g. in German where "event template"
would be a single word.

Instead, create all messages explicitly here. More code but I don't see
how to do this in a way that works for all languages otherwise.

M  +1    -3    src/incidencedialog.cpp
M  +37   -10   src/templatemanagementdialog.cpp
M  +4    -2    src/templatemanagementdialog.h

https://invent.kde.org/pim/incidenceeditor/-/commit/245adbb59822d0d2ef4e5183b110a3c412a081df

diff --git a/src/incidencedialog.cpp b/src/incidencedialog.cpp
index b0d1fd2b..bc39cefe 100644
--- a/src/incidencedialog.cpp
+++ b/src/incidencedialog.cpp
@@ -35,7 +35,6 @@ using namespace Qt::Literals::StringLiterals;
 #include <Akonadi/EntityTreeModel>
 #include <Akonadi/Item>
 
-#include <KCalUtils/Stringify>
 #include <KCalendarCore/ICalFormat>
 #include <KCalendarCore/MemoryCalendar>
 
@@ -352,9 +351,8 @@ void IncidenceDialogPrivate::manageTemplates()
     Q_Q(IncidenceDialog);
 
     const QStringList &templates = IncidenceEditorNG::EditorConfig::instance()->templates(mEditor->type());
-    const QString typeStr = KCalUtils::Stringify::incidenceTypeCaps(mEditor->type());
     QPointer<IncidenceEditorNG::TemplateManagementDialog> const dialog(
-        new IncidenceEditorNG::TemplateManagementDialog(q, templates, typeStr, mEditor->isDirty()));
+        new IncidenceEditorNG::TemplateManagementDialog(q, templates, mEditor->type(), mEditor->isDirty()));
 
     q->connect(dialog, &TemplateManagementDialog::loadTemplate, q, [this](const QString &templateName) {
         loadTemplate(templateName);
diff --git a/src/templatemanagementdialog.cpp b/src/templatemanagementdialog.cpp
index 5d3eddbc..2035a972 100644
--- a/src/templatemanagementdialog.cpp
+++ b/src/templatemanagementdialog.cpp
@@ -24,14 +24,30 @@ using namespace Qt::Literals::StringLiterals;
 
 using namespace IncidenceEditorNG;
 
-TemplateManagementDialog::TemplateManagementDialog(QWidget *parent, const QStringList &templates, const QString &incidenceType, bool isDirty)
+TemplateManagementDialog::TemplateManagementDialog(QWidget *parent,
+                                                   const QStringList &templates,
+                                                   KCalendarCore::Incidence::IncidenceType incidenceType,
+                                                   bool isDirty)
     : QDialog(parent)
     , m_templates(templates)
     , m_type(incidenceType)
     , m_isdirty(isDirty)
 {
-    QString const m_type_translated = i18n(qPrintable(m_type));
-    setWindowTitle(i18nc("@title:window", "Manage %1 Templates", m_type_translated));
+    switch (m_type) {
+    case KCalendarCore::Incidence::TypeEvent:
+        setWindowTitle(i18nc("@title:window", "Manage Event Templates"));
+        break;
+    case KCalendarCore::Incidence::TypeTodo:
+        setWindowTitle(i18nc("@title:window", "Manage To-do Templates"));
+        break;
+    case KCalendarCore::Incidence::TypeJournal:
+        setWindowTitle(i18nc("@title:window", "Manage Journal Templates"));
+        break;
+    case KCalendarCore::Incidence::TypeUnknown:
+    case KCalendarCore::Incidence::TypeFreeBusy:
+        Q_UNREACHABLE(); // cannot be edited
+        break;
+    }
     auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help, this);
     auto mainLayout = new QVBoxLayout(this);
     m_okButton = buttonBox->button(QDialogButtonBox::Ok);
@@ -93,13 +109,24 @@ void TemplateManagementDialog::slotAddTemplate()
 {
     bool ok;
     bool duplicate = false;
-    QString const m_type_translated = i18n(qPrintable(m_type));
-    const QString newTemplate = QInputDialog::getText(this,
-                                                      i18n("Template Name"),
-                                                      i18n("Please enter a name for the new template:"),
-                                                      QLineEdit::Normal,
-                                                      i18n("New %1 Template", m_type_translated),
-                                                      &ok);
+    QString text;
+    switch (m_type) {
+    case KCalendarCore::Incidence::TypeEvent:
+        text = i18n("New Event Template");
+        break;
+    case KCalendarCore::Incidence::TypeTodo:
+        text = i18n("New To-do Template");
+        break;
+    case KCalendarCore::Incidence::TypeJournal:
+        text = i18n("New Journal Template");
+        break;
+    case KCalendarCore::Incidence::TypeUnknown:
+    case KCalendarCore::Incidence::TypeFreeBusy:
+        Q_UNREACHABLE(); // cannot be edited
+        break;
+    }
+    const QString newTemplate =
+        QInputDialog::getText(this, i18n("Template Name"), i18n("Please enter a name for the new template:"), QLineEdit::Normal, text, &ok);
     if (newTemplate.isEmpty() || !ok) {
         return;
     }
diff --git a/src/templatemanagementdialog.h b/src/templatemanagementdialog.h
index b906c652..a393c74b 100644
--- a/src/templatemanagementdialog.h
+++ b/src/templatemanagementdialog.h
@@ -9,6 +9,8 @@
 
 #include "ui_template_management_dialog_base.h"
 
+#include <KCalendarCore/Incidence>
+
 #include <QDialog>
 class QPushBotton;
 
@@ -18,7 +20,7 @@ class TemplateManagementDialog : public QDialog
 {
     Q_OBJECT
 public:
-    explicit TemplateManagementDialog(QWidget *parent, const QStringList &templates, const QString &incidenceType, bool isDirty);
+    explicit TemplateManagementDialog(QWidget *parent, const QStringList &templates, KCalendarCore::Incidence::IncidenceType incidenceType, bool isDirty);
 
 Q_SIGNALS:
     /* Emitted whenever the user hits apply, indicating that the currently
@@ -52,7 +54,7 @@ private:
     Ui::TemplateManagementDialog_base m_base;
     QStringList m_templates;
     QStringList m_templatesSave;
-    QString m_type;
+    KCalendarCore::Incidence::IncidenceType m_type;
     QString m_newTemplate;
     bool m_isdirty = false;
     QPushButton *m_okButton;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.