1
1
/***************************************************************************
2
* Copyright 2009 Stefan Majewsky <majewsky@gmx.net>
2
* Copyright 2009-2011 Stefan Majewsky <majewsky@gmx.net>
4
4
* This program is free software; you can redistribute it and/or
5
5
* modify it under the terms of the GNU General Public
17
17
***************************************************************************/
19
19
#include "importhelper.h"
20
#include "file-io/collection-filesystem.h"
21
#include "file-io/collection-list.h"
20
#include "file-io/collection.h"
21
#include "file-io/components.h"
22
22
#include "file-io/puzzle.h"
24
#include <QApplication>
26
#include <KCmdLineArgs>
27
#include <KDebug> //we use kError
28
#include <KLocalizedString>
29
#include <KMessageBox>
30
#include <KNotification>
24
#include <QtCore/QFutureWatcher>
25
#include <QtCore/QTimer>
26
#include <QtGui/QApplication>
27
#include <KDE/KCmdLineArgs>
28
#include <KDE/KDebug> //we use kError
29
#include <KDE/KNotification>
32
31
Palapeli::ImportHelper::ImportHelper(KCmdLineArgs* args)
34
, m_fileSystemCollection(new Palapeli::FileSystemCollection)
35
, m_localCollection(new Palapeli::LocalCollection)
37
34
QTimer::singleShot(0, this, SLOT(doWork()));
44
41
kError() << i18nc("command line message", "Error: No puzzle file given.");
48
QModelIndex index = m_fileSystemCollection->providePuzzle(m_args->url(0));
49
QObject* puzzlePayload = index.data(Palapeli::Collection::PuzzleObjectRole).value<QObject*>();
50
Palapeli::Puzzle* puzzle = qobject_cast<Palapeli::Puzzle*>(puzzlePayload);
53
KMessageBox::sorry(0, i18n("The given puzzle file is corrupted."));
57
const QModelIndex newIndex = m_localCollection->importPuzzle(puzzle);
58
if (!newIndex.isValid())
60
KMessageBox::sorry(0, i18n("The puzzle file could not be imported into the local collection."));
45
Palapeli::Puzzle* puzzle = Palapeli::Collection::instance()->importPuzzle(m_args->arg(0));
63
46
//show notification
64
KNotification::event(QLatin1String("importingPuzzle"),
65
i18n("Importing puzzle \"%1\" into your collection", puzzle->metadata()->name),
66
QPixmap::fromImage(puzzle->metadata()->thumbnail)
47
puzzle->get(Palapeli::PuzzleComponent::Metadata).waitForFinished();
48
const Palapeli::MetadataComponent* cmp = puzzle->component<Palapeli::MetadataComponent>();
51
KNotification::event(QLatin1String("importingPuzzle"),
52
i18n("Importing puzzle \"%1\" into your collection", cmp->metadata.name),
53
QPixmap::fromImage(cmp->metadata.thumbnail)
68
56
//keep program running until the puzzle has been written
69
QObject* newPuzzlePayload = newIndex.data(Palapeli::Collection::PuzzleObjectRole).value<QObject*>();
70
connect(newPuzzlePayload, SIGNAL(writeFinished()), qApp, SLOT(quit()));
73
Palapeli::ImportHelper::~ImportHelper()
75
delete m_fileSystemCollection;
76
delete m_localCollection;
57
Palapeli::FutureWatcher* watcher = new Palapeli::FutureWatcher;
58
connect(watcher, SIGNAL(finished()), watcher, SLOT(deleteLater()));
59
connect(watcher, SIGNAL(finished()), qApp, SLOT(quit()));
60
watcher->setFuture(puzzle->get(Palapeli::PuzzleComponent::ArchiveStorage));