File indexing completed on 2024-04-28 04:05:19
0001 /* 0002 SPDX-FileCopyrightText: 2009-2011 Stefan Majewsky <majewsky@gmx.net> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "importhelper.h" 0008 #include "file-io/collection.h" 0009 #include "file-io/components.h" 0010 #include "file-io/puzzle.h" 0011 0012 #include <QTimer> 0013 #include <QApplication> 0014 #include "palapeli_debug.h" 0015 #include <KLocalizedString> 0016 #include <KNotification> 0017 0018 Palapeli::ImportHelper::ImportHelper(const QString &path) 0019 : m_path(path) 0020 { 0021 QTimer::singleShot(0, this, &ImportHelper::doWork); 0022 } 0023 0024 void Palapeli::ImportHelper::doWork() 0025 { 0026 if (m_path.isEmpty()) 0027 { 0028 qCCritical(PALAPELI_LOG) << i18nc("command line message", "Error: No puzzle file given."); 0029 qApp->quit(); 0030 } 0031 //import puzzle 0032 Palapeli::Puzzle* puzzle = Palapeli::Collection::instance()->importPuzzle(m_path); 0033 //show notification 0034 puzzle->get(Palapeli::PuzzleComponent::Metadata); 0035 const Palapeli::MetadataComponent* cmp = puzzle->component<Palapeli::MetadataComponent>(); 0036 puzzle->get(Palapeli::PuzzleComponent::ArchiveStorage); 0037 if (cmp) 0038 { 0039 auto *noti = KNotification::event(QStringLiteral("importingPuzzle"), 0040 i18n("Importing puzzle \"%1\" into your collection", cmp->metadata.name), 0041 QPixmap::fromImage(cmp->metadata.thumbnail) 0042 ); 0043 0044 // Delay quitting until the notification expires 0045 // Otherwise the notification is never shown 0046 connect(noti, &KNotification::closed, this, []{ 0047 qApp->quit (); 0048 }); 0049 } else { 0050 qApp->quit (); 0051 } 0052 } 0053 0054 #include "moc_importhelper.cpp"