Commit 4ee9b92f authored by Stefan Majewsky's avatar Stefan Majewsky

Ugly hack for the default-puzzle-localisation problem. Because the feature freeze is upon us.

CCBUG: 233784

svn path=/trunk/KDE/kdegames/palapeli/; revision=1119208
parent d888fe00
You might want to distribute the files at $KDEDIR/share/apps/palapeli/collection/*.puzzle in a separate data package. These are the default puzzle files, which are quite big, but change only seldomly. You might want to distribute the files at $KDEDIR/share/apps/palapeli/collection/*.{desktop,jpg} in a separate data package.
\ No newline at end of file
Changelog for packagers
-----------------------
Version 1.0 -> 1.1: If you have previously distributed libpala-puzzlebuilder in some development package, this is the right moment to move it to the main palapeli package, because Palapeli needs this tool to build its default puzzles on first run.
install(FILES install(FILES
castle-maintenon.puzzle castle-maintenon.desktop
cincinnati-bridge.puzzle castle-maintenon.jpg
citrus-fruits.puzzle cincinnati-bridge.desktop
european-honey-bee.puzzle cincinnati-bridge.jpg
panther-chameleon-female.puzzle citrus-fruits.desktop
citrus-fruits.jpg
european-honey-bee.desktop
european-honey-bee.jpg
panther-chameleon-female.desktop
panther-chameleon-female.jpg
DESTINATION ${DATA_INSTALL_DIR}/palapeli/collection) DESTINATION ${DATA_INSTALL_DIR}/palapeli/collection)
install(FILES install(FILES
......
#!/bin/sh
for MANIFEST in *.desktop; do
TARGET=$(basename $MANIFEST .desktop).puzzle
echo "Creating $TARGET"
libpala-puzzlebuilder $MANIFEST $TARGET
done
...@@ -30,6 +30,7 @@ set(palapeli_SRCS ...@@ -30,6 +30,7 @@ set(palapeli_SRCS
file-io/collection-list.cpp file-io/collection-list.cpp
file-io/collection-view.cpp file-io/collection-view.cpp
file-io/puzzle.cpp file-io/puzzle.cpp
firsttimehelper.cpp
importhelper.cpp importhelper.cpp
main.cpp main.cpp
window/collectionwidget.cpp window/collectionwidget.cpp
......
/***************************************************************************
* Copyright 2009, 2010 Stefan Majewsky <majewsky@gmx.net>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
***************************************************************************/
#include "firsttimehelper.h"
#include "window/mainwindow.h"
#include <QDir>
#include <QFileInfo>
#include <QGridLayout>
#include <QLabel>
#include <QProcess>
#include <QProgressBar>
#include <QTimer>
#include <KCmdLineArgs>
#include <KConfig>
#include <KConfigGroup>
#include <KLocalizedString>
#include <KGlobal>
#include <KIcon>
#include <KStandardDirs>
//NOTE: A local copy of Palapeli::ListCollection::readUrl, with an extension to resolve local URLs.
static KUrl resolveUrl(const KUrl& url, bool local)
{
if (url.protocol() == "palapeli")
{
//resolve special URLs with KStandardDirs
QString path = url.path(KUrl::RemoveTrailingSlash);
if (path.startsWith('/'))
path.remove(0, 1);
return KUrl(local ? KStandardDirs::locateLocal("appdata", path) : KStandardDirs::locate("appdata", path));
}
else
return url;
}
Palapeli::FirstTimeHelper::FirstTimeHelper()
: m_bar(0)
{
//open config, read puzzles
KConfig config("palapeli-collectionrc", KConfig::CascadeConfig);
KConfigGroup mainGroup(&config, "Palapeli Collection");
const QStringList puzzleIds = mainGroup.groupList();
foreach (const QString& puzzleId, puzzleIds)
{
KConfigGroup puzzleGroup(&mainGroup, puzzleId);
const KUrl barePuzzleUrl = puzzleGroup.readEntry("Location", KUrl());
//generate name of corresponding .desktop file
QString desktopFileName = barePuzzleUrl.fileName();
desktopFileName.replace(QRegExp("\\.puzzle$"), QLatin1String(".desktop"));
KUrl bareDesktopUrl(barePuzzleUrl);
bareDesktopUrl.setFileName(desktopFileName);
//if desktop file does not exist, we cannot do anything
const KUrl puzzleUrl = resolveUrl(barePuzzleUrl, false);
const KUrl desktopUrl = resolveUrl(bareDesktopUrl, false);
if (desktopUrl.isEmpty())
continue;
//if puzzle file does not exist or is older than desktop file (e.g. because of translation update), schedule update
if (puzzleUrl.isEmpty() || (QFileInfo(puzzleUrl.path()).lastModified() < QFileInfo(desktopUrl.path()).lastModified()))
{
const KUrl localPuzzleUrl = resolveUrl(barePuzzleUrl, true);
Task task = { desktopUrl, localPuzzleUrl };
m_tasks << task;
}
}
}
bool Palapeli::FirstTimeHelper::isNecessary() const
{
return !m_tasks.isEmpty();
}
void Palapeli::FirstTimeHelper::execute()
{
//create a progress dialog
QWidget* widget = new QWidget;
widget->setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint);
connect(this, SIGNAL(done()), widget, SLOT(deleteLater()));
QGridLayout* layout = new QGridLayout;
widget->setLayout(layout);
QLabel* icon = new QLabel;
QLabel* label = new QLabel(i18nc("content of first-run wizard (which behaves more like a splashscreen in fact, i.e. no user interaction)", "<title>Palapeli first-run and update wizard</title><para>Creating default puzzles...</para><para>This needs to be done only once.</para>"), widget);
// label2->setWordWrap(true);
m_bar = new QProgressBar(widget);
layout->addWidget(icon, 0, 0, 2, 1);
layout->addWidget(label, 0, 1);
layout->addWidget(m_bar, 1, 1);
const int iconSize = layout->sizeHint().height() - layout->contentsMargins().top() - layout->contentsMargins().bottom();
icon->setPixmap(KIcon("palapeli").pixmap(iconSize));
icon->setFixedSize(QSize(iconSize, iconSize));
m_bar->setMinimum(0);
m_bar->setMaximum(m_tasks.count() + 1); //do not let the bar reach 100% while it is visible
m_bar->setValue(0);
widget->show();
QTimer::singleShot(0, this, SLOT(next()));
}
void Palapeli::FirstTimeHelper::next()
{
if (m_tasks.isEmpty())
{
//done
emit done();
(new Palapeli::MainWindow(KCmdLineArgs::parsedArgs()))->show();
deleteLater();
return;
}
m_bar->setValue(m_bar->value() + 1);
//create next puzzle
Task task = m_tasks.takeFirst();
QProcess* process = new QProcess;
QFileInfo desktopFile(task.desktopUrl.path());
process->setWorkingDirectory(desktopFile.dir().absolutePath());
QStringList args;
args << desktopFile.fileName() << task.puzzleUrl.path();
process->start("libpala-puzzlebuilder", args);
connect(process, SIGNAL(finished(int, QProcess::ExitStatus)), SLOT(next()));
}
#include "firsttimehelper.moc"
/***************************************************************************
* Copyright 2009, 2010 Stefan Majewsky <majewsky@gmx.net>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
***************************************************************************/
#ifndef PALAPELI_FIRSTTIMEHELPER_H
#define PALAPELI_FIRSTTIMEHELPER_H
#include <QObject>
class QProgressBar;
#include <KUrl>
namespace Palapeli
{
///This whole class is a hack, which I only implement at all because feature freeze is just 5.5 hours from now.
///It checks the standard collection, and if some puzzles have not yet been built, it calls libpala-puzzlebuilder to build them.
///TODO: Of course, the right way would be to implement this feature directly in the collection, but this will have to wait until Palapeli 1.2 because of aforementioned feature freeze.
class FirstTimeHelper : public QObject
{
Q_OBJECT
public:
FirstTimeHelper();
bool isNecessary() const;
public Q_SLOTS:
void execute();
private Q_SLOTS:
void next();
Q_SIGNALS:
void done();
private:
struct Task
{
KUrl desktopUrl, puzzleUrl;
};
QList<Task> m_tasks;
QProgressBar* m_bar;
};
}
#endif // PALAPELI_FIRSTTIMEHELPER_H
/*************************************************************************** /***************************************************************************
* Copyright 2009 Stefan Majewsky <majewsky@gmx.net> * Copyright 2009, 2010 Stefan Majewsky <majewsky@gmx.net>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public * modify it under the terms of the GNU General Public
...@@ -16,10 +16,12 @@ ...@@ -16,10 +16,12 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
***************************************************************************/ ***************************************************************************/
#include "firsttimehelper.h"
#include "importhelper.h" #include "importhelper.h"
#include "window/mainwindow.h" #include "window/mainwindow.h"
#include <ctime> #include <ctime>
#include <QTimer>
#include <KAboutData> #include <KAboutData>
#include <KApplication> #include <KApplication>
#include <KCmdLineArgs> #include <KCmdLineArgs>
...@@ -48,7 +50,16 @@ int main(int argc, char** argv) ...@@ -48,7 +50,16 @@ int main(int argc, char** argv)
//perform import request //perform import request
new Palapeli::ImportHelper(args); new Palapeli::ImportHelper(args);
else else
{
//no import request, show main window //no import request, show main window
(new Palapeli::MainWindow(args))->show(); Palapeli::FirstTimeHelper* helper = new Palapeli::FirstTimeHelper;
if (helper->isNecessary())
QTimer::singleShot(0, helper, SLOT(execute()));
else
{
delete helper;
(new Palapeli::MainWindow(args))->show();
}
}
return app.exec(); return app.exec();
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment