~ubuntu-branches/ubuntu/oneiric/kdegames/oneiric

« back to all changes in this revision

Viewing changes to palapeli/src/importhelper.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer, Rohan Garg, Philip Muškovac, Felix Geyer
  • Date: 2011-07-12 12:53:09 UTC
  • mfrom: (1.3.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20110712125309-08z2aidih2ynpu43
Tags: 4:4.6.90-0ubuntu1
[ Rohan Garg ]
* New upstream release
  - Drop Granatier, libopenal is in universe
  - Bump so versions for various packages

[ Philip Muškovac ]
* fix debug package depends on kdebase-runtime-dbg -> kde-runtime-dbg 

[ Felix Geyer ]
* Update symbols files.
* Add new files to kajongg.install.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/***************************************************************************
2
 
 *   Copyright 2009 Stefan Majewsky <majewsky@gmx.net>
 
2
 *   Copyright 2009-2011 Stefan Majewsky <majewsky@gmx.net>
3
3
 *
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
***************************************************************************/
18
18
 
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"
23
23
 
24
 
#include <QApplication>
25
 
#include <QTimer>
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>
31
30
 
32
31
Palapeli::ImportHelper::ImportHelper(KCmdLineArgs* args)
33
32
        : m_args(args)
34
 
        , m_fileSystemCollection(new Palapeli::FileSystemCollection)
35
 
        , m_localCollection(new Palapeli::LocalCollection)
36
33
{
37
34
        QTimer::singleShot(0, this, SLOT(doWork()));
38
35
}
44
41
                kError() << i18nc("command line message", "Error: No puzzle file given.");
45
42
                qApp->quit();
46
43
        }
47
 
        //try to load puzzle
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);
51
 
        if (!puzzle)
52
 
        {
53
 
                KMessageBox::sorry(0, i18n("The given puzzle file is corrupted."));
54
 
                qApp->quit();
55
 
        }
56
 
        //do import
57
 
        const QModelIndex newIndex = m_localCollection->importPuzzle(puzzle);
58
 
        if (!newIndex.isValid())
59
 
        {
60
 
                KMessageBox::sorry(0, i18n("The puzzle file could not be imported into the local collection."));
61
 
                qApp->quit();
62
 
        }
 
44
        //import puzzle
 
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)
67
 
        );
 
47
        puzzle->get(Palapeli::PuzzleComponent::Metadata).waitForFinished();
 
48
        const Palapeli::MetadataComponent* cmp = puzzle->component<Palapeli::MetadataComponent>();
 
49
        if (cmp)
 
50
        {
 
51
                KNotification::event(QLatin1String("importingPuzzle"),
 
52
                        i18n("Importing puzzle \"%1\" into your collection", cmp->metadata.name),
 
53
                        QPixmap::fromImage(cmp->metadata.thumbnail)
 
54
                );
 
55
        }
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()));
71
 
}
72
 
 
73
 
Palapeli::ImportHelper::~ImportHelper()
74
 
{
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));
77
61
}