Solving the problem of launching the settings dialog without xine support #14

Merged
MicheleC merged 1 commits from feat/settings into master 5 months ago
Collaborator

The settings dialog crashes if built without xine support. These changes do not affect the recording process.
These changes solve the problem of opening the settings dialog box if the build is carried out without xine support.

The settings dialog crashes if built without `xine` support. These changes do not affect the recording process. These changes solve the problem of opening the settings dialog box if the build is carried out without `xine` support.
ormorph added 1 commit 5 months ago
3ccdc7986f
Solving the problem of launching the settings dialog without xine support
Poster
Collaborator

The main reason for adding this is that the recorderClicked slot only applies to xine. File src/pref.cpp:

KDE_NO_EXPORT void PrefRecordPage::recorderClicked (int id) {
    bool b = recorder->find(id)->text().find (TQString::fromLatin1("Xine")) > -1;
    replay->setEnabled (!b);
    if (b)
        replay->setButton (Settings::ReplayNo);

}

In addition, in this file this slot is already bound to the HAVE_XINE macro:

#ifdef HAVE_XINE
    connect (recorder, TQT_SIGNAL (clicked(int)), this, TQT_SLOT(recorderClicked(int)));
#endif

It seems that in the src/kmplayerconfig.cpp file someone forgot to do the same for the recorderClicked slot.

The main reason for adding this is that the recorderClicked slot only applies to `xine`. File `src/pref.cpp`: ``` KDE_NO_EXPORT void PrefRecordPage::recorderClicked (int id) { bool b = recorder->find(id)->text().find (TQString::fromLatin1("Xine")) > -1; replay->setEnabled (!b); if (b) replay->setButton (Settings::ReplayNo); } ``` In addition, in this file this slot is already bound to the `HAVE_XINE` macro: ``` #ifdef HAVE_XINE connect (recorder, TQT_SIGNAL (clicked(int)), this, TQT_SLOT(recorderClicked(int))); #endif ``` It seems that in the `src/kmplayerconfig.cpp` file someone forgot to do the same for the `recorderClicked` slot.
Owner

I am interested to understand where the crash happens. Is it because recorder->find(id) returns a null pointer? In that case it may be more appropriate to check for that and return from the call instead of introducing a #ifdef block (we could in fact remove the original one too).
Using #ifdef blocks to protect from crashes is not really good practice, because it only hides a problem away rather than fixing it properly. If someone uses a different settings for some #define, the problem could show up again.

I am interested to understand where the crash happens. Is it because `recorder->find(id)` returns a null pointer? In that case it may be more appropriate to check for that and return from the call instead of introducing a #ifdef block (we could in fact remove the original one too). Using #ifdef blocks to protect from crashes is not really good practice, because it only hides a problem away rather than fixing it properly. If someone uses a different settings for some #define, the problem could show up again.
Poster
Collaborator

I am interested to understand where the crash happens. Is it because recorder->find(id) returns a null pointer?

Yes, sure.link
The problem occurs when the ~/.trinity/share/config/kmplayerrc file has not yet been created.
An option without macros might look like this:

--- a/src/pref.cpp	2023-11-28 08:00:37.426857575 +0300
+++ b/src/pref.cpp	2023-11-28 08:04:58.909846639 +0300
@@ -475,7 +475,10 @@
 }
 
 KDE_NO_EXPORT void PrefRecordPage::recorderClicked (int id) {
-    bool b = recorder->find(id)->text().find (TQString::fromLatin1("Xine")) > -1;
+    bool b = false;
+    if (recorder->find(id)) {
+        b = recorder->find(id)->text().find (TQString::fromLatin1("Xine")) > -1;
+    }
     replay->setEnabled (!b);
     if (b)
         replay->setButton (Settings::ReplayNo);
> I am interested to understand where the crash happens. Is it because recorder->find(id) returns a null pointer? Yes, sure.[link](https://bpa.st/46YQ) The problem occurs when the `~/.trinity/share/config/kmplayerrc` file has not yet been created. An option without macros might look like this: ``` --- a/src/pref.cpp 2023-11-28 08:00:37.426857575 +0300 +++ b/src/pref.cpp 2023-11-28 08:04:58.909846639 +0300 @@ -475,7 +475,10 @@ } KDE_NO_EXPORT void PrefRecordPage::recorderClicked (int id) { - bool b = recorder->find(id)->text().find (TQString::fromLatin1("Xine")) > -1; + bool b = false; + if (recorder->find(id)) { + b = recorder->find(id)->text().find (TQString::fromLatin1("Xine")) > -1; + } replay->setEnabled (!b); if (b) replay->setButton (Settings::ReplayNo); ```
Owner

That's a better solution IMO. You can improve even further by avoiding a double call to find():

bool b = false;
TQButton *recBtn = recorder->find(id);
if (recBtn)
{
  b = recorder->find(id)->text().find (TQString::fromLatin1("Xine")) > -1;
}

You can now try to remove the #ifdef HAVE_XINE in src/pref.cpp:438 and see if all still works fine.

That's a better solution IMO. You can improve even further by avoiding a double call to `find()`: ``` bool b = false; TQButton *recBtn = recorder->find(id); if (recBtn) { b = recorder->find(id)->text().find (TQString::fromLatin1("Xine")) > -1; } ``` You can now try to remove the `#ifdef HAVE_XINE` in src/pref.cpp:438 and see if all still works fine.
Owner

Btw, I could not access the link above, but I think we are both clear on the solution now :-)

Btw, I could not access the link above, but I think we are both clear on the solution now :-)
Poster
Collaborator

You can now try to remove the #ifdef HAVE_XINE in src/pref.cpp:438 and see if all still works fine.

Ok, I'll add it now and check it. But I already think that everything will be okay.

tw, I could not access the link above, but I think we are both clear on the solution now :-)

Now I also cannot access this information, apparently there are some problems with the server. Here I re-uploaded it. Link

> You can now try to remove the #ifdef HAVE_XINE in src/pref.cpp:438 and see if all still works fine. Ok, I'll add it now and check it. But I already think that everything will be okay. > tw, I could not access the link above, but I think we are both clear on the solution now :-) Now I also cannot access this information, apparently there are some problems with the server. Here I re-uploaded it. [Link](https://dpaste.com/2DHCDGBDY)
Owner

Ok, I'll add it now and check it. But I already think that everything will be okay.

Excellent. If you update the patch, then we can approve and merge it in the new form.

> Ok, I'll add it now and check it. But I already think that everything will be okay. Excellent. If you update the patch, then we can approve and merge it in the new form.
ormorph force-pushed feat/settings from 3ccdc7986f to 0a09dae2f6 5 months ago
Poster
Collaborator

Added changes, checked it works!

Added changes, checked it works!
Owner

Patch looks good and well prepared. One last touch: can you remove the #ifdef HAVE_XINE in src/pref.cpp:438 if it doesn't cause any side effect?

Patch looks good and well prepared. One last touch: can you remove the #ifdef HAVE_XINE in src/pref.cpp:438 if it doesn't cause any side effect?
Poster
Collaborator

Okay, I'll test this with an additional call to connect.

Okay, I'll test this with an additional call to connect.
ormorph force-pushed feat/settings from 0a09dae2f6 to 6212c1b319 5 months ago
Poster
Collaborator

Patch looks good and well prepared. One last touch: can you remove the #ifdef HAVE_XINE in src/pref.cpp:438 if it doesn't cause any side effect?

I added the changes, everything works fine. No side effects occurred after adding these changes.

> Patch looks good and well prepared. One last touch: can you remove the #ifdef HAVE_XINE in src/pref.cpp:438 if it doesn't cause any side effect? I added the changes, everything works fine. No side effects occurred after adding these changes.
MicheleC approved these changes 5 months ago
MicheleC left a comment
Owner

Now all looks good. We removed a bad hackish solution (the #ifdef) and replace it with a proper fix 🙂

Now all looks good. We removed a bad hackish solution (the #ifdef) and replace it with a proper fix 🙂
MicheleC merged commit 6212c1b319 into master 5 months ago
MicheleC deleted branch feat/settings 5 months ago
MicheleC added this to the R14.1.2 release milestone 5 months ago
Owner

Merged and backport. Thanks @ormorph for the patch, the testing and the patience to update through the process.

Merged and backport. Thanks @ormorph for the patch, the testing and the patience to update through the process.

Reviewers

MicheleC approved these changes 5 months ago
The pull request has been merged as 6212c1b319.
Sign in to join this conversation.
No reviewers
No Milestone
No Assignees
2 Participants
Notifications
Due Date

No due date set.

Dependencies

No dependencies set.

Reference: TDE/kmplayer#14
Loading…
There is no content yet.