Port usage of KUrl and friends to equivalent constructs with QUrl.
ClosedPublic

Authored by ouwerkerk on Apr 22 2017, 2:42 PM.

Details

Summary

KUrl is part of the deprecated kdelibs4support API.
Porting away from it removes one obstacle towards legacy free sudoku for KDE.

Test Plan

Using XDG_DATA_DIRS to point to locally built copy of ksudoku game assets, I tested the following:

  1. Generate a Killer type (i.e. a custom Sudoku variant) puzzle using defaults for difficulty/symmetry
  2. Reconfigured toolbars to add the Home Page action & invoke the Home Page action
  3. Save the puzzle/game file & Quit the application
  4. Reload the application and load the previously saved puzzle.

Diff Detail

Repository
R417 KSudoku
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
ouwerkerk created this revision.Apr 22 2017, 2:42 PM
Restricted Application added a reviewer: KDE Games. · View Herald TranscriptApr 22 2017, 2:42 PM
Restricted Application added a subscriber: KDE Games. · View Herald Transcript

Shorter command line. Please follow the guidelines for git commits. First line no more than 55/60 characters, followed by a blank line and the rest of the commit message (with more or less 78/80 character limit).

ltoscano requested changes to this revision.Apr 22 2017, 2:51 PM
This revision now requires changes to proceed.Apr 22 2017, 2:51 PM
ouwerkerk updated this revision to Diff 13701.Apr 22 2017, 3:18 PM
ouwerkerk edited edge metadata.

Updating D5544: Summary:

Port usage of KUrl and friends to equivalent constructs with QUrl.
KUrl is part of the deprecated kdelibs4support API.
Porting away from it removes one obstacle towards legacy free sudoku for KDE.

ouwerkerk retitled this revision from Summary: Port usage of KUrl and friends to equivalent constructs with QUrl. KUrl is part of the deprecated kdelibs4support API. Porting away from it removes one obstacle towards legacy free sudoku for KDE. to Port usage of KUrl and friends to equivalent constructs with QUrl..Apr 22 2017, 3:19 PM
ouwerkerk edited the summary of this revision. (Show Details)
ouwerkerk updated this revision to Diff 13709.Apr 22 2017, 10:31 PM

Rebased onto latest frameworks.

ltoscano requested changes to this revision.Apr 22 2017, 10:58 PM

There are few errors; following the chat on IRC, I think you need a development environment:

/mnt/kde/git/kde/kdegames/ksudoku/src/gui/ksudoku.cpp: In member function ‘void KSudoku::updateShapesList()’:
/mnt/kde/git/kde/kdegames/ksudoku/src/gui/ksudoku.cpp:220:72: error: no matching function for call to ‘ksudoku::CustomGame::CustomGame(QString&, QString&, ksudoku::GameVariantCollection*&)’
   variant = new CustomGame(variantName, variantDataPath, m_gameVariants);
                                                                        ^
In file included from /mnt/kde/git/kde/kdegames/ksudoku/src/gui/ksudoku.cpp:73:0:
/mnt/kde/git/kde/kdegames/ksudoku/src/gui/gamevariants.h:170:2: note: candidate: ksudoku::CustomGame::CustomGame(const QString&, const QUrl&, ksudoku::GameVariantCollection*)
  CustomGame(const QString& name, const QUrl& url, GameVariantCollection* collection=0);
  ^~~~~~~~~~
/mnt/kde/git/kde/kdegames/ksudoku/src/gui/gamevariants.h:170:2: note:   no known conversion for argument 2 from ‘QString’ to ‘const QUrl&’
/mnt/kde/git/kde/kdegames/ksudoku/src/gui/gamevariants.h:168:7: note: candidate: ksudoku::CustomGame::CustomGame(const ksudoku::CustomGame&)
 class CustomGame : public GameVariant {
       ^~~~~~~~~~
/mnt/kde/git/kde/kdegames/ksudoku/src/gui/gamevariants.h:168:7: note:   candidate expects 1 argument, 3 provided
/mnt/kde/git/kde/kdegames/ksudoku/src/gui/gamevariants.h:168:7: note: candidate: ksudoku::CustomGame::CustomGame(ksudoku::CustomGame&&)
/mnt/kde/git/kde/kdegames/ksudoku/src/gui/gamevariants.h:168:7: note:   candidate expects 1 argument, 3 provided
/mnt/kde/git/kde/kdegames/ksudoku/src/gui/ksudoku.cpp: In member function ‘virtual void KSudoku::dragEnterEvent(QDragEnterEvent*)’:
/mnt/kde/git/kde/kdegames/ksudoku/src/gui/ksudoku.cpp:631:37: error: request for member ‘hasUrls’ in ‘event->QDragEnterEvent::<anonymous>.QDragMoveEvent::<anonymous>.QDropEvent::mimeData()’, which is of pointer type ‘const QMimeData*’ (maybe you meant to use ‘->’ ?)
     event->accept(event->mimeData().hasUrls());
                                     ^~~~~~~
/mnt/kde/git/kde/kdegames/ksudoku/src/gui/ksudoku.cpp: In member function ‘virtual void KSudoku::dropEvent(QDropEvent*)’:
/mnt/kde/git/kde/kdegames/ksudoku/src/gui/ksudoku.cpp:636:43: error: conversion from ‘const QMimeData*’ to non-scalar type ‘const QMimeData’ requested
     const QMimeData data = event->mimeData();
                            ~~~~~~~~~~~~~~~^~
This revision now requires changes to proceed.Apr 22 2017, 10:58 PM
ouwerkerk updated this revision to Diff 13710.Apr 22 2017, 11:49 PM
ouwerkerk edited edge metadata.

Fixes to make it compile.

ltoscano requested changes to this revision.Apr 23 2017, 3:23 PM

The program crashes when you select a non-standard game (which I guess comes from wrong reading of some URL). Porting to QUrl requires a bit of investigation as the behavior is a bit different.

Please note that they may be other crashes or other unexpected behaviors; a deeper testing which touches all the code which is changed here is needed.

Example of crash:

#6  0x000055e83b8bfcbc in QVector<int>::size() const ()
#7  0x000055e83b8ce5d0 in ksudoku::Puzzle::hasSolution() const ()
#8  0x000055e83b8de721 in ksudoku::WelcomeScreen::generatePuzzle() ()
#9  0x000055e83b8dfae3 in QtPrivate::FunctorCall<QtPrivate::IndexesList<>, QtPrivate::List<>, void, void (ksudoku::WelcomeScreen::*)()>::call(void (ksudoku::WelcomeScreen::*)(), ksudoku::WelcomeScreen*, void**) ()
#10 0x000055e83b8dfa75 in void QtPrivate::FunctionPointer<void (ksudoku::WelcomeScreen::*)()>::call<QtPrivate::List<>, void>(void (ksudoku::WelcomeScreen::*)(), ksudoku::WelcomeScreen*, void**) ()
#11 0x000055e83b8df981 in QtPrivate::QSlotObject<void (ksudoku::WelcomeScreen::*)(), QtPrivate::List<>, void>::impl(int, QtPrivate::QSlotObjectBase*, QObject*, void**, bool*) ()
#12 0x00007f89c5ef295e in QMetaObject::activate(QObject*, int, int, void**) () from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#13 0x00007f89c7559135 in QAbstractItemView::doubleClicked(QModelIndex const&) () from /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#14 0x00007f89c756686a in QAbstractItemView::mouseDoubleClickEvent(QMouseEvent*) () from /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
[...]
This revision now requires changes to proceed.Apr 23 2017, 3:23 PM

Thanks for the pointer. I'm still now sure why ksudoku would crash because at worst the puzzle should be in some 'invalid' state with bogus contents ... but then the QVector should still return a proper size() without crashing.
Alternatively, possibly more likely, the memory management of the containing Puzzle object itself was already messed up and the change in code merely tickles the bug.

ouwerkerk updated this revision to Diff 13886.Apr 27 2017, 7:16 PM
ouwerkerk edited edge metadata.

Fix: crash on opening a custom game variant.

KUrl accepts raw file paths, but QUrl doesn't.
Use QUrl::fromLocalFile() to fix the crash.
Also make sure to not do hacky things with raw file paths when Qt supplies perfectly good APIs for that purpose already.
(Note: the entire function should probably be updated to use Qt APIs instead of manual fiddling with file & directory paths.)

ouwerkerk edited the test plan for this revision. (Show Details)Apr 27 2017, 8:42 PM
ouwerkerk edited the test plan for this revision. (Show Details)
stikonas added inline comments.
src/gui/ksudoku.cpp
392

Maybe KRun::RunFlags()) ?

stikonas requested changes to this revision.Apr 27 2017, 9:01 PM

Also, I think you need to bump KF5 requirement to KF 5.31 to be able to use runUrl.

This revision now requires changes to proceed.Apr 27 2017, 9:01 PM
ouwerkerk updated this revision to Diff 13890.Apr 27 2017, 9:22 PM
ouwerkerk edited edge metadata.

Incorporate stikonas's suggestions.

stikonas accepted this revision.Apr 27 2017, 9:28 PM
ltoscano accepted this revision.Apr 27 2017, 9:37 PM

Thanks!

This revision is now accepted and ready to land.Apr 27 2017, 9:37 PM
This revision was automatically updated to reflect the committed changes.
ouwerkerk marked an inline comment as done.