[pim/kdepim-addons] kaddressbook/plugins/sendvcards: USe contains with Qt::CaseInsensitive + use directly arg(index)

Laurent Montel <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 7177096c11d404d1b4eadde5662d0e87190ebfa2 by Laurent Montel.
Committed on 16/08/2026 at 07:05.
Pushed by mlaurent into branch 'master'.

USe contains with Qt::CaseInsensitive + use directly arg(index)

M  +11   -1    kaddressbook/plugins/sendvcards/autotests/sendvcardsjobtest.cpp
M  +1    -1    kaddressbook/plugins/sendvcards/autotests/sendvcardsjobtest.h
M  +2    -2    kaddressbook/plugins/sendvcards/sendvcardsjob.cpp

https://invent.kde.org/pim/kdepim-addons/-/commit/7177096c11d404d1b4eadde5662d0e87190ebfa2

diff --git a/kaddressbook/plugins/sendvcards/autotests/sendvcardsjobtest.cpp b/kaddressbook/plugins/sendvcards/autotests/sendvcardsjobtest.cpp
index 08f12bcd2..2a1bbedca 100644
--- a/kaddressbook/plugins/sendvcards/autotests/sendvcardsjobtest.cpp
+++ b/kaddressbook/plugins/sendvcards/autotests/sendvcardsjobtest.cpp
@@ -42,7 +42,7 @@ void SendVcardsJobTest::shouldChangeExportVersion()
     QCOMPARE(job.version(), KContacts::VCardConverter::v3_0);
 }
 
-void SendVcardsJobTest::shouldGenerageUniqueFileName()
+void SendVcardsJobTest::shouldGenerateUniqueFileName()
 {
     {
         QStringList existingVcard;
@@ -74,6 +74,16 @@ void SendVcardsJobTest::shouldGenerageUniqueFileName()
         QString contactRealName;
         QCOMPARE(KABSendVCards::SendVcardsJob::createUniqueAttachmentName(contactRealName, existingVcard), u"vcard_1"_s);
     }
+    {
+        QStringList existingVcard = QStringList() << u"bla"_s << u"bla_1"_s << u"Vcard"_s;
+        QString contactRealName;
+        QCOMPARE(KABSendVCards::SendVcardsJob::createUniqueAttachmentName(contactRealName, existingVcard), u"vcard_1"_s);
+    }
+    {
+        QStringList existingVcard = QStringList() << u"bla"_s;
+        QString contactRealName = u"Bla"_s;
+        QCOMPARE(KABSendVCards::SendVcardsJob::createUniqueAttachmentName(contactRealName, existingVcard), u"Bla_1"_s);
+    }
 }
 
 #include "moc_sendvcardsjobtest.cpp"
diff --git a/kaddressbook/plugins/sendvcards/autotests/sendvcardsjobtest.h b/kaddressbook/plugins/sendvcards/autotests/sendvcardsjobtest.h
index c69ac304b..0fb7d807c 100644
--- a/kaddressbook/plugins/sendvcards/autotests/sendvcardsjobtest.h
+++ b/kaddressbook/plugins/sendvcards/autotests/sendvcardsjobtest.h
@@ -20,5 +20,5 @@ private Q_SLOTS:
     void shouldNotStartWhenListAddressIsEmpty();
     void shouldHasDefaultValue();
     void shouldChangeExportVersion();
-    void shouldGenerageUniqueFileName();
+    void shouldGenerateUniqueFileName();
 };
diff --git a/kaddressbook/plugins/sendvcards/sendvcardsjob.cpp b/kaddressbook/plugins/sendvcards/sendvcardsjob.cpp
index d9a7b2fde..cc45ba285 100644
--- a/kaddressbook/plugins/sendvcards/sendvcardsjob.cpp
+++ b/kaddressbook/plugins/sendvcards/sendvcardsjob.cpp
@@ -40,12 +40,12 @@ QString SendVcardsJob::createUniqueAttachmentName(const QString &contactRealName
     if (newContactRealName.isEmpty()) {
         newContactRealName = QStringLiteral("vcard");
     }
-    if (existingVcard.contains(newContactRealName)) {
+    if (existingVcard.contains(newContactRealName, Qt::CaseInsensitive)) {
         int index = 0;
         QString uniqueContactRealName = newContactRealName;
         do {
             index++;
-            uniqueContactRealName = u"%1_%2"_s.arg(newContactRealName).arg(QString::number(index));
+            uniqueContactRealName = u"%1_%2"_s.arg(newContactRealName).arg(index);
         } while (existingVcard.contains(uniqueContactRealName));
         newContactRealName = uniqueContactRealName;
     }
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.