Example #1
0
void PreviewModel::SetFavourite(bool favourite)
{
	if(save)
	{
		if (Client::Ref().FavouriteSave(save->id, favourite) == RequestOkay)
			save->Favourite = favourite;
		else if (favourite)
			throw PreviewModelException("Error, could not fav. the save: " + Client::Ref().GetLastError());
		else
			throw PreviewModelException("Error, could not unfav. the save: " + Client::Ref().GetLastError());
		notifySaveChanged();
	}
}
void PreviewModel::Update()
{
	if(updateSaveDataWorking)
	{
		if(updateSaveDataFinished)
		{
			updateSaveDataWorking = false;
			pthread_join(updateSaveDataThread, NULL);

			if(updateSaveInfoFinished && save)
			{
				commentsTotal = save->Comments;
				try
				{
					save->SetGameSave(new GameSave(&saveDataBuffer[0], saveDataBuffer.size()));
				}
				catch(ParseException &e)
				{
					throw PreviewModelException("Save file corrupt or from newer version");
				}
				notifySaveChanged();
				notifyCommentsPageChanged();
			}
		}
	}

	if(updateSaveInfoWorking)
	{
		if(updateSaveInfoFinished)
		{
			if(save)
			{
				delete save;
				save = NULL;
			}
			updateSaveInfoWorking = false;
			pthread_join(updateSaveInfoThread, (void**)(&save));
			if(updateSaveDataFinished && save)
			{
				commentsTotal = save->Comments;
				try
				{
					save->SetGameSave(new GameSave(&saveDataBuffer[0], saveDataBuffer.size()));
				}
				catch(ParseException &e)
				{
					throw PreviewModelException("Save file corrupt or from newer version");
				}
				notifyCommentsPageChanged();
			}
			notifySaveChanged();

			if(!save)
				throw PreviewModelException("Unable to load save");
		}
	}

	if(updateSaveCommentsWorking)
	{
		if(updateSaveCommentsFinished)
		{
			if(saveComments)
			{
				for(int i = 0; i < saveComments->size(); i++)
					delete saveComments->at(i);
				saveComments->clear();
				saveComments = NULL;
			}
			commentsLoaded = true;
			updateSaveCommentsWorking = false;
			pthread_join(updateSaveCommentsThread, (void**)(&saveComments));
			notifySaveCommentsChanged();
		}
	}
}