Changeset View
Changeset View
Standalone View
Standalone View
src/gui/ksudoku.cpp
Show All 25 Lines | |||||
26 | 26 | | |||
27 | #include <QDragEnterEvent> | 27 | #include <QDragEnterEvent> | ||
28 | #include <QDropEvent> | 28 | #include <QDropEvent> | ||
29 | 29 | | |||
30 | #include <QHBoxLayout> | 30 | #include <QHBoxLayout> | ||
31 | #include <QLabel> | 31 | #include <QLabel> | ||
32 | #include <QComboBox> | 32 | #include <QComboBox> | ||
33 | 33 | | |||
34 | #include <QMimeData> | ||||
35 | | ||||
34 | #include <QPrinter> | 36 | #include <QPrinter> | ||
35 | #include <QPrintDialog> | 37 | #include <QPrintDialog> | ||
36 | #include <QStandardPaths> | 38 | #include <QStandardPaths> | ||
37 | 39 | | |||
38 | #include <KLocalizedString> | 40 | #include <KLocalizedString> | ||
39 | #include <KActionCollection> | 41 | #include <KActionCollection> | ||
40 | #include <KStandardAction> | 42 | #include <KStandardAction> | ||
41 | #include <QAction> | 43 | #include <QAction> | ||
42 | #include <KConfigDialog> | 44 | #include <KConfigDialog> | ||
43 | 45 | | |||
44 | #define USE_UNSTABLE_LIBKDEGAMESPRIVATE_API | 46 | #define USE_UNSTABLE_LIBKDEGAMESPRIVATE_API | ||
45 | #include <libkdegamesprivate/kgamethemeselector.h> | 47 | #include <libkdegamesprivate/kgamethemeselector.h> | ||
46 | #include <QKeySequence> | 48 | #include <QKeySequence> | ||
47 | #include <KUrl> | 49 | #include <QUrl> | ||
48 | #include <kmessagebox.h> | 50 | #include <kmessagebox.h> | ||
49 | #include <KLocalizedString> | 51 | #include <KLocalizedString> | ||
50 | #include <qstatusbar.h> | 52 | #include <qstatusbar.h> | ||
51 | #include <kio/netaccess.h> | 53 | #include <kio/netaccess.h> | ||
52 | #include <krun.h> | 54 | #include <krun.h> | ||
53 | 55 | | |||
54 | #include "ksview.h" | 56 | #include "ksview.h" | ||
55 | #include "gameactions.h" | 57 | #include "gameactions.h" | ||
56 | #include "renderer.h" | 58 | #include "renderer.h" | ||
57 | 59 | | |||
58 | #include "puzzle.h" // TODO | 60 | #include "puzzle.h" // TODO | ||
59 | #include "skgraph.h" | 61 | #include "skgraph.h" | ||
60 | #include "serializer.h" | 62 | #include "serializer.h" | ||
61 | 63 | | |||
62 | #include "puzzleprinter.h" | 64 | #include "puzzleprinter.h" | ||
63 | 65 | | |||
64 | #include <ktar.h> | 66 | #include <ktar.h> | ||
65 | #include <kio/job.h> | 67 | #include <kio/job.h> | ||
66 | #include <kstandardgameaction.h> | 68 | #include <kstandardgameaction.h> | ||
67 | #include <QDir> | 69 | #include <QDir> | ||
68 | #include <KSharedConfig> | 70 | #include <KSharedConfig> | ||
69 | #include <QFileDialog> | 71 | #include <QFileDialog> | ||
72 | #include <QFileInfo> | ||||
70 | 73 | | |||
71 | #include "gamevariants.h" | 74 | #include "gamevariants.h" | ||
72 | #include "welcomescreen.h" | 75 | #include "welcomescreen.h" | ||
73 | #include "valuelistwidget.h" | 76 | #include "valuelistwidget.h" | ||
74 | 77 | | |||
75 | #include "settings.h" | 78 | #include "settings.h" | ||
76 | #include "config.h" | 79 | #include "config.h" | ||
77 | 80 | | |||
▲ Show 20 Lines • Show All 121 Lines • ▼ Show 20 Line(s) | 190 | #endif | |||
199 | } | 202 | } | ||
200 | 203 | | |||
201 | QString variantName; | 204 | QString variantName; | ||
202 | QString variantDescr; | 205 | QString variantDescr; | ||
203 | QString variantDataPath; | 206 | QString variantDataPath; | ||
204 | QString variantIcon; | 207 | QString variantIcon; | ||
205 | 208 | | |||
206 | foreach(const QString &filepath, filepaths) { | 209 | foreach(const QString &filepath, filepaths) { | ||
210 | const QFileInfo configFileInfo(filepath); | ||||
211 | const QDir variantDir = configFileInfo.dir(); | ||||
207 | KConfig variantConfig(filepath, KConfig::SimpleConfig); | 212 | KConfig variantConfig(filepath, KConfig::SimpleConfig); | ||
208 | KConfigGroup group = variantConfig.group ("KSudokuVariant"); | 213 | KConfigGroup group = variantConfig.group ("KSudokuVariant"); | ||
209 | 214 | | |||
210 | variantName = group.readEntry("Name", i18n("Missing Variant Name")); // Translated. | 215 | variantName = group.readEntry("Name", i18n("Missing Variant Name")); // Translated. | ||
211 | variantDescr = group.readEntry("Description", ""); // Translated. | 216 | variantDescr = group.readEntry("Description", ""); // Translated. | ||
212 | variantIcon = group.readEntry("Icon", "ksudoku-ksudoku_9x9"); | 217 | variantIcon = group.readEntry("Icon", "ksudoku-ksudoku_9x9"); | ||
213 | variantDataPath = group.readEntry("FileName", ""); | 218 | const QString variantDataFile = group.readEntry("FileName", ""); | ||
214 | if(variantDataPath == "") continue; | 219 | if(variantDataFile == "") continue; | ||
215 | 220 | | |||
216 | variantDataPath = filepath.left(filepath.lastIndexOf("/")+1) + variantDataPath; | 221 | variantDataPath = variantDir.filePath(variantDataFile); | ||
217 | 222 | | |||
218 | variant = new CustomGame(variantName, variantDataPath, m_gameVariants); | 223 | variant = new CustomGame(variantName, QUrl::fromLocalFile(variantDataPath), m_gameVariants); | ||
219 | variant->setDescription(variantDescr); | 224 | variant->setDescription(variantDescr); | ||
220 | variant->setIcon(variantIcon); | 225 | variant->setIcon(variantIcon); | ||
221 | } | 226 | } | ||
222 | 227 | | |||
223 | // Put variants first and extra sizes last. | 228 | // Put variants first and extra sizes last. | ||
224 | variant = new SudokuGame(i18n("Sudoku 16x16"), 16, m_gameVariants); | 229 | variant = new SudokuGame(i18n("Sudoku 16x16"), 16, m_gameVariants); | ||
225 | variant->setDescription(i18n("Sudoku with 16 symbols")); | 230 | variant->setDescription(i18n("Sudoku with 16 symbols")); | ||
226 | variant->setIcon("ksudoku-ksudoku_16x16"); | 231 | variant->setIcon("ksudoku-ksudoku_16x16"); | ||
▲ Show 20 Lines • Show All 132 Lines • ▼ Show 20 Line(s) | 362 | void KSudoku::endCurrentGame() { | |||
359 | 364 | | |||
360 | delete m_gameUI; | 365 | delete m_gameUI; | ||
361 | m_gameUI = 0; | 366 | m_gameUI = 0; | ||
362 | 367 | | |||
363 | adaptActions2View(); | 368 | adaptActions2View(); | ||
364 | 369 | | |||
365 | } | 370 | } | ||
366 | 371 | | |||
367 | void KSudoku::loadGame(const KUrl& Url) { | 372 | void KSudoku::loadGame(const QUrl& Url) { | ||
368 | QString errorMsg; | 373 | QString errorMsg; | ||
369 | Game game = ksudoku::Serializer::load(Url, this, &errorMsg); | 374 | Game game = ksudoku::Serializer::load(Url, this, &errorMsg); | ||
370 | if(!game.isValid()) { | 375 | if(!game.isValid()) { | ||
371 | KMessageBox::information(this, errorMsg); | 376 | KMessageBox::information(this, errorMsg); | ||
372 | return; | 377 | return; | ||
373 | } | 378 | } | ||
374 | 379 | | |||
375 | startGame(game); | 380 | startGame(game); | ||
376 | } | 381 | } | ||
377 | 382 | | |||
378 | void KSudoku::showWelcomeScreen() { | 383 | void KSudoku::showWelcomeScreen() { | ||
379 | endCurrentGame(); | 384 | endCurrentGame(); | ||
380 | 385 | | |||
381 | m_welcomeScreen->show(); | 386 | m_welcomeScreen->show(); | ||
382 | } | 387 | } | ||
383 | 388 | | |||
384 | void KSudoku::homepage() | 389 | void KSudoku::homepage() | ||
385 | { | 390 | { | ||
386 | KRun::runUrl (KUrl("http://ksudoku.sourceforge.net/"), "text/html", this); | 391 | KRun::runUrl (QUrl("http://ksudoku.sourceforge.net/"), "text/html", this, KRun::RunFlags()); | ||
387 | } | 392 | } | ||
stikonas: Maybe KRun::RunFlags()) ? | |||||
388 | 393 | | |||
389 | void KSudoku::giveHint() | 394 | void KSudoku::giveHint() | ||
390 | { | 395 | { | ||
391 | Game game = currentGame(); | 396 | Game game = currentGame(); | ||
392 | if(!game.isValid()) return; | 397 | if(!game.isValid()) return; | ||
393 | game.giveHint(); | 398 | game.giveHint(); | ||
394 | } | 399 | } | ||
395 | 400 | | |||
▲ Show 20 Lines • Show All 221 Lines • ▼ Show 20 Line(s) | |||||
617 | 622 | | |||
618 | void KSudoku::pop() | 623 | void KSudoku::pop() | ||
619 | { | 624 | { | ||
620 | // TODO replace this with history | 625 | // TODO replace this with history | ||
621 | // if(type == 0) {if(m_view) m_view->pop(); return;} | 626 | // if(type == 0) {if(m_view) m_view->pop(); return;} | ||
622 | // if(glwin) glwin->pop(); | 627 | // if(glwin) glwin->pop(); | ||
623 | } | 628 | } | ||
624 | 629 | | |||
625 | void KSudoku::dragEnterEvent(QDragEnterEvent */*event*/) | 630 | void KSudoku::dragEnterEvent(QDragEnterEvent * event) | ||
626 | { | 631 | { | ||
627 | // accept uri drops only | 632 | // accept uri drops only | ||
628 | 633 | if(event->mimeData()->hasUrls()) | |||
629 | //TODO PORT | 634 | event->accept(); | ||
630 | //KUrl::List::fromMimeData( e->mimeData() ) | | |||
631 | | ||||
632 | //event->accept(KUrlDrag::canDecode(event)); | | |||
633 | } | 635 | } | ||
634 | 636 | | |||
635 | void KSudoku::dropEvent(QDropEvent *event) | 637 | void KSudoku::dropEvent(QDropEvent *event) | ||
636 | { | 638 | { | ||
637 | //TODO PORT | 639 | const QMimeData * data = event->mimeData(); | ||
638 | KUrl::List Urls = KUrl::List::fromMimeData( event->mimeData() ); | 640 | if(data->hasUrls()) | ||
639 | 641 | { | |||
642 | QList<QUrl> Urls = data->urls(); | ||||
640 | 643 | | |||
641 | if ( !Urls.isEmpty() ) | 644 | if ( !Urls.isEmpty() ) | ||
642 | { | 645 | { | ||
643 | // okay, we have a URI.. process it | 646 | // okay, we have a URI.. process it | ||
644 | const KUrl &Url = Urls.first(); | 647 | const QUrl &Url = Urls.first(); | ||
645 | 648 | | |||
646 | Game game = ksudoku::Serializer::load(Url, this); | 649 | Game game = ksudoku::Serializer::load(Url, this); | ||
647 | // if(game) | | |||
648 | // (new KSudoku(game))->show(); | | |||
649 | if(game.isValid()) | 650 | if(game.isValid()) | ||
650 | startGame(game); | 651 | startGame(game); | ||
651 | // delete game; | | |||
652 | } | 652 | } | ||
653 | 653 | } | |||
654 | } | 654 | } | ||
655 | 655 | | |||
656 | void KSudoku::gameNew() | 656 | void KSudoku::gameNew() | ||
657 | { | 657 | { | ||
658 | // this slot is called whenever the Game->New menu is selected, | 658 | // this slot is called whenever the Game->New menu is selected, | ||
659 | // the New shortcut is pressed (usually CTRL+N) or the New toolbar | 659 | // the New shortcut is pressed (usually CTRL+N) or the New toolbar | ||
660 | // button is clicked | 660 | // button is clicked | ||
661 | 661 | | |||
Show All 13 Lines | |||||
675 | } | 675 | } | ||
676 | 676 | | |||
677 | void KSudoku::gameOpen() | 677 | void KSudoku::gameOpen() | ||
678 | { | 678 | { | ||
679 | // this slot is called whenever the Game->Open menu is selected, | 679 | // this slot is called whenever the Game->Open menu is selected, | ||
680 | // the Open shortcut is pressed (usually CTRL+O) or the Open toolbar | 680 | // the Open shortcut is pressed (usually CTRL+O) or the Open toolbar | ||
681 | // button is clicked | 681 | // button is clicked | ||
682 | // standard filedialog | 682 | // standard filedialog | ||
683 | KUrl Url = QFileDialog::getOpenFileUrl(this, i18n("Open Location"), QUrl::fromLocalFile(QDir::homePath()), QString()); | 683 | const QUrl Url = QFileDialog::getOpenFileUrl(this, i18n("Open Location"), QUrl::fromLocalFile(QDir::homePath()), QString()); | ||
684 | 684 | | |||
685 | if (!Url.isEmpty() && Url.isValid()) | 685 | if (!Url.isEmpty() && Url.isValid()) | ||
686 | { | 686 | { | ||
687 | Game game = ksudoku::Serializer::load(Url, this); | 687 | Game game = ksudoku::Serializer::load(Url, this); | ||
688 | if(!game.isValid()) { | 688 | if(!game.isValid()) { | ||
689 | KMessageBox::error(this, i18n("Could not load game.")); | 689 | KMessageBox::error(this, i18n("Could not load game.")); | ||
690 | return; | 690 | return; | ||
691 | } | 691 | } | ||
▲ Show 20 Lines • Show All 252 Lines • Show Last 20 Lines |
Maybe KRun::RunFlags()) ?