KCM: Make sure Unicode is used for editing bashrc (fixes issue #6) #7

Merged
blu.256 merged 1 commits from fix/issue-6 into master 3 years ago

@ -509,13 +509,14 @@ void KcmGtk::save()
if (file.exists())
{
file.open(IO_ReadOnly);
TQByteArray fileData = file.readAll();
TQTextStream fileDataStream = TQTextStream(&file);
SlavekB commented 3 years ago
Review

Now I found that there is already TQTextStream stream(&file); for file defined above. So you can use the previous stream variable. Instead of a new fileDataStream.
I'll do a test if it also solves the FTBFS, which I watch now.

Now I found that there is already `TQTextStream stream(&file);` for `file` defined above. So you can use the previous `stream` variable. Instead of a new `fileDataStream`. I'll do a test if it also solves the FTBFS, which I watch now.
blu.256 commented 3 years ago
Review

I just checked with the following changes:

diff --git a/kcm_gtk/kcmgtk.cpp b/kcm_gtk/kcmgtk.cpp
index bd3ab79..9822b30 100644
--- a/kcm_gtk/kcmgtk.cpp
+++ b/kcm_gtk/kcmgtk.cpp
@@ -509,9 +509,9 @@ void KcmGtk::save()
        if (file.exists())
        {
                file.open(IO_ReadOnly);
-               TQTextStream fileDataStream = TQTextStream(&file);
-               fileDataStream.setEncoding(TQTextStream::Locale);
-               TQString fileDataString = fileDataStream.read();
+               stream.setDevice(TQT_TQIODEVICE(&file));
+               stream.setEncoding(TQTextStream::Locale);
+               TQString fileDataString = stream.read();
                file.close();

                TQString rcLine = "export GTK2_RC_FILES=$HOME/.gtkrc-2.0";

Builds and works as expected.

I just checked with the following changes: ``` diff --git a/kcm_gtk/kcmgtk.cpp b/kcm_gtk/kcmgtk.cpp index bd3ab79..9822b30 100644 --- a/kcm_gtk/kcmgtk.cpp +++ b/kcm_gtk/kcmgtk.cpp @@ -509,9 +509,9 @@ void KcmGtk::save() if (file.exists()) { file.open(IO_ReadOnly); - TQTextStream fileDataStream = TQTextStream(&file); - fileDataStream.setEncoding(TQTextStream::Locale); - TQString fileDataString = fileDataStream.read(); + stream.setDevice(TQT_TQIODEVICE(&file)); + stream.setEncoding(TQTextStream::Locale); + TQString fileDataString = stream.read(); file.close(); TQString rcLine = "export GTK2_RC_FILES=$HOME/.gtkrc-2.0"; ``` Builds and works as expected.
SlavekB commented 3 years ago
Review

For me build was successful only on Debian 12 (Bookworm), Ubuntu 21.10 (Impish) and Ubuntu 22.04 (Jammy). With an update in #8 build is successfull also on Debian 9 (Stretch).

For me build was successful only on Debian 12 (Bookworm), Ubuntu 21.10 (Impish) and Ubuntu 22.04 (Jammy). With an update in #8 build is successfull also on Debian 9 (Stretch).
fileDataStream.setEncoding(TQTextStream::Locale);
TQString fileDataString = fileDataStream.read();
file.close();
TQString rcLine = "export GTK2_RC_FILES=$HOME/.gtkrc-2.0";
TQString fileDataString(fileData);
fileDataString.replace("\n" + rcLine, "\n# (This is no longer needed from version 0.8 of the theme engine)\n# " + rcLine);
file.open(IO_WriteOnly);
stream.setDevice(TQT_TQIODEVICE(&file));
SlavekB marked this conversation as resolved
SlavekB commented 3 years ago
Review

One more idea: Encoding should also be set when writing data back to file?

One more idea: Encoding should also be set when writing data back to file?
blu.256 commented 3 years ago
Review

I don't know; right now it works well. Maybe encoding should only be set when reading from stream?

According to the TQt docs,

By default, output of Unicode text (i.e. TQString) is done using the local 8-bit encoding.

so if I understood that well, it sets the appropriate encoding automatically for the output.

I don't know; right now it works well. Maybe encoding should only be set when reading from stream? According to the TQt docs, > By default, output of Unicode text (i.e. TQString) is done using the local 8-bit encoding. so if I understood that well, it sets the appropriate encoding automatically for the output.
SlavekB commented 3 years ago
Review

Ok, thank you, in this case it should probably be fine.

Ok, thank you, in this case it should probably be fine.
stream << fileDataString;

Loading…
Cancel
Save