Commit ff3a84b0 authored by Stefan Majewsky's avatar Stefan Majewsky

Change the write protection mechanism in Palapeli in such a way that it works...

Change the write protection mechanism in Palapeli in such a way that it works reliably on all operating systems.

svn path=/trunk/KDE/kdegames/palapeli/; revision=1060702
parent d724238b
if(NOT WIN32)
install(FILES
castle-maintenon.puzzle
cincinnati-bridge.puzzle
citrus-fruits.puzzle
european-honey-bee.puzzle
panther-chameleon-female.puzzle
DESTINATION ${DATA_INSTALL_DIR}/palapeli/collection
PERMISSIONS OWNER_READ GROUP_READ WORLD_READ)
install(FILES
default-collection.conf
DESTINATION ${CONFIG_INSTALL_DIR}
PERMISSIONS OWNER_READ GROUP_READ WORLD_READ
RENAME palapeli-collectionrc)
else(NOT WIN32)
install(FILES
castle-maintenon.puzzle
cincinnati-bridge.puzzle
......@@ -21,8 +5,8 @@ install(FILES
european-honey-bee.puzzle
panther-chameleon-female.puzzle
DESTINATION ${DATA_INSTALL_DIR}/palapeli/collection)
install(FILES
default-collection.conf
DESTINATION ${CONFIG_INSTALL_DIR}
RENAME palapeli-collectionrc)
endif(NOT WIN32)
\ No newline at end of file
......@@ -44,3 +44,6 @@ Image=castle-maintenon.jpg
Slicer=palapeli_jigsawslicer
PieceCount=80
PieceAspect=6
[Collection]
ModifyProtection=true
......@@ -45,3 +45,6 @@ Image=cincinnati-bridge.jpg
Slicer=palapeli_jigsawslicer
PieceCount=56
PieceAspect=6
[Collection]
ModifyProtection=true
......@@ -30,3 +30,6 @@ Image=citrus-fruits.jpg
Slicer=palapeli_jigsawslicer
PieceCount=42
PieceAspect=6
[Collection]
ModifyProtection=true
......@@ -29,3 +29,6 @@ Image=european-honey-bee.jpg
Slicer=palapeli_jigsawslicer
PieceCount=48
PieceAspect=6
[Collection]
ModifyProtection=true
......@@ -43,3 +43,6 @@ Image=panther-chameleon-female.jpg
Slicer=palapeli_jigsawslicer
PieceCount=48
PieceAspect=6
[Collection]
ModifyProtection=true
......@@ -153,6 +153,7 @@ void Palapeli::PuzzleCreatorDialog::createPuzzle()
metadata->pieceCount = job.pieces().count();
metadata->image = image;
metadata->thumbnail = image.scaled(Palapeli::Puzzle::ThumbnailBaseSize, Qt::KeepAspectRatio);
metadata->modifyProtection = false; //only enabled for puzzles in the default collection (see ListCollection::canDeletePuzzle)
Palapeli::PuzzleContents* contents = new Palapeli::PuzzleContents;
contents->imageSize = image.size();
QMapIterator<int, QImage> pieceIter(job.pieces());
......
......@@ -127,6 +127,7 @@ QModelIndex Palapeli::ListCollection::addPuzzleInternal(Palapeli::Puzzle* puzzle
metadata->comment = puzzleGroup.readEntry("Comment", QString());
metadata->author = puzzleGroup.readEntry("Author", QString());
metadata->pieceCount = puzzleGroup.readEntry("PieceCount", 0);
metadata->modifyProtection = puzzleGroup.readEntry("ModifyProtection", false);
//Reading the thumbnail is a bit harder, because KConfig does not support images directly.
QImage image; image.loadFromData(puzzleGroup.readEntry("Thumbnail", QByteArray()));
metadata->thumbnail = image;
......@@ -144,6 +145,7 @@ QModelIndex Palapeli::ListCollection::addPuzzleInternal(Palapeli::Puzzle* puzzle
puzzleGroup.writeEntry("Comment", puzzle->metadata()->comment);
puzzleGroup.writeEntry("Author", puzzle->metadata()->author);
puzzleGroup.writeEntry("PieceCount", puzzle->metadata()->pieceCount);
puzzleGroup.writeEntry("ModifyProtection", puzzle->metadata()->modifyProtection);
puzzleGroup.writeEntry("ModifyDateTime", modificationTime);
//Writing the thumbnail is a bit harder, because KConfig does not support images directly.
QBuffer buffer;
......@@ -204,12 +206,11 @@ bool Palapeli::ListCollection::canDeletePuzzle(const QModelIndex& index) const
//get puzzle object
QObject* puzzlePayload = index.data(PuzzleObjectRole).value<QObject*>();
Palapeli::Puzzle* puzzle = qobject_cast<Palapeli::Puzzle*>(puzzlePayload);
if (!puzzle)
if (!puzzle || !puzzle->metadata())
return false;
//check whether that particular file can be removed
QString file = puzzle->location().path();
return QFileInfo(file).isWritable();
//NOTE: This is a protection for the default puzzles, which are installed with read-only permissions.
//check whether that particular puzzle can be removed
return !puzzle->metadata()->modifyProtection;
//NOTE: This is a protection for the default puzzles. In user-generated puzzles, ModifyProtection is not enabled.
}
bool Palapeli::ListCollection::deletePuzzle(const QModelIndex& index)
......
......@@ -137,6 +137,8 @@ bool Palapeli::Puzzle::readMetadata(bool force)
m_metadata->comment = manifest.readComment();
m_metadata->image.load(m_cache->name() + "image.jpg");
m_metadata->thumbnail = m_metadata->image.scaled(ThumbnailBaseSize, Qt::KeepAspectRatio);
KConfigGroup collectionGroup(&manifest, "Collection");
m_metadata->modifyProtection = collectionGroup.readEntry("ModifyProtection", false);
//find piece count
KConfigGroup offsetGroup(&manifest, "PieceOffsets");
const QMap<QString, QString> offsetGroupMap = offsetGroup.entryMap();
......@@ -235,6 +237,8 @@ void Palapeli::Puzzle::createNewArchiveFile()
mainGroup.writeEntry("Comment", m_metadata->comment);
mainGroup.writeEntry("X-KDE-PluginInfo-Author", m_metadata->author);
mainGroup.writeEntry("Type", "X-Palapeli-Puzzle");
KConfigGroup collectionGroup(&manifest, "Collection");
collectionGroup.writeEntry("ModifyProtection", m_metadata->modifyProtection);
KConfigGroup jobGroup(&manifest, "Job");
jobGroup.writeEntry("ImageSize", m_contents->imageSize);
if (m_creationContext)
......
......@@ -32,6 +32,7 @@ namespace Palapeli
QString name, author, comment;
int pieceCount;
QImage image, thumbnail;
bool modifyProtection;
};
struct PuzzleContents
......
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