[sdk/kdiff3] /: Repurpose Auto Detect "Unicode" preference

Michael Reeves null at kde.org
Sat Oct 28 03:12:02 BST 2023


Git commit f2034ee291c989d173742b7b29e4eb1a30361af3 by Michael Reeves.
Committed on 28/10/2023 at 04:11.
Pushed by mreeves into branch 'master'.

Repurpose Auto Detect "Unicode" preference

This seems to have always functioned as an auto detect flag.
In any event it that is now the express purpose.

M  +1    -1    doc/en/index.docbook
M  +4    -3    src/SourceData.cpp
M  +19   -19   src/optiondialog.cpp
M  +3    -3    src/optiondialog.h
M  +3    -3    src/options.h
M  +3    -3    src/pdiff.cpp

https://invent.kde.org/sdk/kdiff3/-/commit/f2034ee291c989d173742b7b29e4eb1a30361af3

diff --git a/doc/en/index.docbook b/doc/en/index.docbook
index 1d174f45..7c0e474f 100644
--- a/doc/en/index.docbook
+++ b/doc/en/index.docbook
@@ -917,7 +917,7 @@ Yet there is one option here that is also relevant for saving single files:
 	</para></listitem></varlistentry>
     <varlistentry><term><guilabel>Note: Local Encoding is "..."</guilabel></term><listitem><para>Above the codec-selectors appears this note that tells you what the local encoding is. (This is not adjustable but for your information just in case you don't know your local encoding, but need to select it.)
 	</para></listitem></varlistentry>
-    <varlistentry><term><guilabel>Auto Detect Unicode</guilabel></term><listitem><para> This option attempts to use the BOM or meta data from XML/HTML documents to detect Unicode encoding. Failing that it will check if a short sample from the beginning of the file can be interpreted as UTF-8. If this check passes UTF-8 will be used. Otherwise it will fall back to the user selected codec. Only UTF-8 is supported with no BOM or metadata present.
+    <varlistentry><term><guilabel>Auto Detect</guilabel></term><listitem><para> This option attempts to use the BOM or meta data from XML/HTML documents to detect encoding. Failing that it will check if a short sample from the beginning of the file can be interpreted as UTF-8. If this check passes UTF-8 will be used. Otherwise it will fall back to the user selected codec. Only UTF-8 is supported with no BOM or metadata present.
 	</para></listitem></varlistentry>
     <varlistentry><term><guilabel>File Encoding for A/B/C:</guilabel></term><listitem><para> Adjust the file encoding for input files. This has an effect on how the special characters are interpreted. Since you can adjust each codec separately you can even compare and merge files that were saved using different codecs.
 	</para></listitem></varlistentry>
diff --git a/src/SourceData.cpp b/src/SourceData.cpp
index ef72f7ee..29471451 100644
--- a/src/SourceData.cpp
+++ b/src/SourceData.cpp
@@ -337,15 +337,16 @@ std::optional<const char*> SourceData::detectEncoding(const QString& fileName)
     return {};
 }
 
-void SourceData::readAndPreprocess(const char* encoding, bool bAutoDetectUnicode)
+void SourceData::readAndPreprocess(const char* encoding, bool bAutoDetect)
 {
-    mEncoding = encoding;
     QTemporaryFile fileIn1, fileOut1;
     QString fileNameIn1;
     QString fileNameOut1;
     QString fileNameIn2;
     QString fileNameOut2;
 
+    mEncoding = encoding;
+
     // Detect the input for the preprocessing operations
     if(!mFromClipBoard)
     {
@@ -373,7 +374,7 @@ void SourceData::readAndPreprocess(const char* encoding, bool bAutoDetectUnicode
 
             fileNameIn1 = m_tempInputFileName;
         }
-        if(bAutoDetectUnicode)
+        if(bAutoDetect)
         {
             mEncoding = detectEncoding(fileNameIn1).value_or(encoding);
         }
diff --git a/src/optiondialog.cpp b/src/optiondialog.cpp
index 13340baa..b8deef13 100644
--- a/src/optiondialog.cpp
+++ b/src/optiondialog.cpp
@@ -1330,13 +1330,13 @@ void OptionDialog::setupRegionalPage()
     gbox->addWidget(m_pEncodingAComboBox, line, 1);
 
     QString autoDetectToolTip = i18n(
-        "If enabled then Unicode (UTF-16 or UTF-8) encoding will be detected.\n"
-        "If the file is not Unicode then the selected encoding will be used as fallback.\n"
+        "If enabled then encoding will be automaticly detected.\n"
+        "If the file's encoding can not be found automaticly then the selected encoding will be used as fallback.\n"
         "(Unicode detection depends on the first bytes of a file.)");
-    m_pAutoDetectUnicodeA = new OptionCheckBox(i18n("Auto Detect Unicode"), true, "AutoDetectUnicodeA", &gOptions->m_bAutoDetectUnicodeA, page);
-    gbox->addWidget(m_pAutoDetectUnicodeA, line, 2);
+    mAutoDetectA = new OptionCheckBox(i18n("Auto Detect"), true, "AutoDetectUnicodeA", &gOptions->mAutoDetectA, page);
+    gbox->addWidget(mAutoDetectA, line, 2);
 
-    m_pAutoDetectUnicodeA->setToolTip(autoDetectToolTip);
+    mAutoDetectA->setToolTip(autoDetectToolTip);
     ++line;
 
     label = new QLabel(i18n("File Encoding for B:"), page);
@@ -1344,10 +1344,10 @@ void OptionDialog::setupRegionalPage()
     m_pEncodingBComboBox = new OptionEncodingComboBox("EncodingForB", &gOptions->mEncodingB, page);
 
     gbox->addWidget(m_pEncodingBComboBox, line, 1);
-    m_pAutoDetectUnicodeB = new OptionCheckBox(i18n("Auto Detect Unicode"), true, "AutoDetectUnicodeB", &gOptions->m_bAutoDetectUnicodeB, page);
+    mAutoDetectB = new OptionCheckBox(i18n("Auto Detect"), true, "AutoDetectUnicodeB", &gOptions->mAutoDetectB, page);
 
-    gbox->addWidget(m_pAutoDetectUnicodeB, line, 2);
-    m_pAutoDetectUnicodeB->setToolTip(autoDetectToolTip);
+    gbox->addWidget(mAutoDetectB, line, 2);
+    mAutoDetectB->setToolTip(autoDetectToolTip);
     ++line;
 
     label = new QLabel(i18n("File Encoding for C:"), page);
@@ -1355,10 +1355,10 @@ void OptionDialog::setupRegionalPage()
     m_pEncodingCComboBox = new OptionEncodingComboBox("EncodingForC", &gOptions->mEncodingC, page);
 
     gbox->addWidget(m_pEncodingCComboBox, line, 1);
-    m_pAutoDetectUnicodeC = new OptionCheckBox(i18n("Auto Detect Unicode"), true, "AutoDetectUnicodeC", &gOptions->m_bAutoDetectUnicodeC, page);
+    mAutoDetectC = new OptionCheckBox(i18n("Auto Detect"), true, "AutoDetectUnicodeC", &gOptions->mAutoDetectC, page);
 
-    gbox->addWidget(m_pAutoDetectUnicodeC, line, 2);
-    m_pAutoDetectUnicodeC->setToolTip(autoDetectToolTip);
+    gbox->addWidget(mAutoDetectC, line, 2);
+    mAutoDetectC->setToolTip(autoDetectToolTip);
     ++line;
 
     label = new QLabel(i18n("File Encoding for Merge Output and Saving:"), page);
@@ -1382,7 +1382,7 @@ void OptionDialog::setupRegionalPage()
 
     chk_connect_a(m_pSameEncoding, &OptionCheckBox::toggled, this, &OptionDialog::slotEncodingChanged);
     chk_connect_a(m_pEncodingAComboBox, static_cast<void (OptionEncodingComboBox::*)(qint32)>(&OptionEncodingComboBox::activated), this, &OptionDialog::slotEncodingChanged);
-    chk_connect_a(m_pAutoDetectUnicodeA, &OptionCheckBox::toggled, this, &OptionDialog::slotEncodingChanged);
+    chk_connect_a(mAutoDetectA, &OptionCheckBox::toggled, this, &OptionDialog::slotEncodingChanged);
     chk_connect_a(m_pAutoSelectOutEncoding, &OptionCheckBox::toggled, this, &OptionDialog::slotEncodingChanged);
 
     OptionCheckBox* pRightToLeftLanguage = new OptionCheckBox(i18n("Right To Left Language"), false, "RightToLeftLanguage", &gOptions->m_bRightToLeftLanguage, page);
@@ -1455,12 +1455,12 @@ void OptionDialog::slotEncodingChanged()
         m_pEncodingOutComboBox->setCurrentIndex(m_pEncodingAComboBox->currentIndex());
         m_pEncodingPPComboBox->setEnabled(false);
         m_pEncodingPPComboBox->setCurrentIndex(m_pEncodingAComboBox->currentIndex());
-        m_pAutoDetectUnicodeB->setEnabled(false);
-        m_pAutoDetectUnicodeB->setCheckState(m_pAutoDetectUnicodeA->checkState());
-        m_pAutoDetectUnicodeC->setEnabled(false);
-        m_pAutoDetectUnicodeC->setCheckState(m_pAutoDetectUnicodeA->checkState());
+        mAutoDetectB->setEnabled(false);
+        mAutoDetectB->setCheckState(mAutoDetectA->checkState());
+        mAutoDetectC->setEnabled(false);
+        mAutoDetectC->setCheckState(mAutoDetectA->checkState());
         m_pAutoSelectOutEncoding->setEnabled(false);
-        m_pAutoSelectOutEncoding->setCheckState(m_pAutoDetectUnicodeA->checkState());
+        m_pAutoSelectOutEncoding->setCheckState(mAutoDetectA->checkState());
     }
     else
     {
@@ -1468,8 +1468,8 @@ void OptionDialog::slotEncodingChanged()
         m_pEncodingCComboBox->setEnabled(true);
         m_pEncodingOutComboBox->setEnabled(true);
         m_pEncodingPPComboBox->setEnabled(true);
-        m_pAutoDetectUnicodeB->setEnabled(true);
-        m_pAutoDetectUnicodeC->setEnabled(true);
+        mAutoDetectB->setEnabled(true);
+        mAutoDetectC->setEnabled(true);
         m_pAutoSelectOutEncoding->setEnabled(true);
         m_pEncodingOutComboBox->setEnabled(m_pAutoSelectOutEncoding->checkState() == Qt::Unchecked);
     }
diff --git a/src/optiondialog.h b/src/optiondialog.h
index cb427a66..183a8579 100644
--- a/src/optiondialog.h
+++ b/src/optiondialog.h
@@ -66,11 +66,11 @@ class OptionDialog: public KPageDialog
 
     OptionCheckBox* m_pSameEncoding;
     OptionEncodingComboBox* m_pEncodingAComboBox;
-    OptionCheckBox* m_pAutoDetectUnicodeA;
+    OptionCheckBox* mAutoDetectA;
     OptionEncodingComboBox* m_pEncodingBComboBox;
-    OptionCheckBox* m_pAutoDetectUnicodeB;
+    OptionCheckBox* mAutoDetectB;
     OptionEncodingComboBox* m_pEncodingCComboBox;
-    OptionCheckBox* m_pAutoDetectUnicodeC;
+    OptionCheckBox* mAutoDetectC;
     OptionEncodingComboBox* m_pEncodingOutComboBox;
     OptionCheckBox* m_pAutoSelectOutEncoding;
     OptionEncodingComboBox* m_pEncodingPPComboBox;
diff --git a/src/options.h b/src/options.h
index a5a934ed..67a0517c 100644
--- a/src/options.h
+++ b/src/options.h
@@ -172,11 +172,11 @@ class Options
     bool m_bAutoCopySelection = false;
     bool m_bSameEncoding = true;
     QByteArray mEncodingA = nullptr;
-    bool m_bAutoDetectUnicodeA = true;
+    bool mAutoDetectA = true;
     QByteArray mEncodingB = nullptr;
-    bool m_bAutoDetectUnicodeB = true;
+    bool mAutoDetectB = true;
     QByteArray mEncodingC = nullptr;
-    bool m_bAutoDetectUnicodeC = true;
+    bool mAutoDetectC = true;
     QByteArray mEncodingOut = nullptr;
     bool m_bAutoSelectOutEncoding = true;
     QByteArray mEncodingPP = nullptr;
diff --git a/src/pdiff.cpp b/src/pdiff.cpp
index 583d0c86..70d5171f 100644
--- a/src/pdiff.cpp
+++ b/src/pdiff.cpp
@@ -126,7 +126,7 @@ void KDiff3App::mainInit(TotalDiffStatus* pTotalDiffStatus, const InitFlags inFl
         if(bUseCurrentEncoding)
             m_sd1->readAndPreprocess(m_sd1->getEncoding(), false);
         else
-            m_sd1->readAndPreprocess(gOptions->mEncodingA, gOptions->m_bAutoDetectUnicodeA);
+            m_sd1->readAndPreprocess(gOptions->mEncodingA, gOptions->mAutoDetectA);
 
         ProgressProxy::step();
 
@@ -136,7 +136,7 @@ void KDiff3App::mainInit(TotalDiffStatus* pTotalDiffStatus, const InitFlags inFl
         if(bUseCurrentEncoding)
             m_sd2->readAndPreprocess(m_sd2->getEncoding(), false);
         else
-            m_sd2->readAndPreprocess(gOptions->mEncodingB, gOptions->m_bAutoDetectUnicodeB);
+            m_sd2->readAndPreprocess(gOptions->mEncodingB, gOptions->mAutoDetectB);
 
         ProgressProxy::step();
         mErrors.append(m_sd1->getErrors());
@@ -194,7 +194,7 @@ void KDiff3App::mainInit(TotalDiffStatus* pTotalDiffStatus, const InitFlags inFl
                     if(bUseCurrentEncoding)
                         m_sd3->readAndPreprocess(m_sd3->getEncoding(), false);
                     else
-                        m_sd3->readAndPreprocess(gOptions->mEncodingC, gOptions->m_bAutoDetectUnicodeC);
+                        m_sd3->readAndPreprocess(gOptions->mEncodingC, gOptions->mAutoDetectC);
 
                     ProgressProxy::step();
                 }


More information about the kde-doc-english mailing list