Simplify parsing and add support for tags
This commit is contained in:
		
					parent
					
						
							
								1026087083
							
						
					
				
			
			
				commit
				
					
						8d012115f0
					
				
			
		
					 2 changed files with 36 additions and 28 deletions
				
			
		| 
						 | 
				
			
			@ -296,6 +296,33 @@ QVariantMap extractPoolData(const QVariant &data, ApiType type) {
 | 
			
		|||
    
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QVariantMap extractTagData(const QVariant &data, ApiType type) {
 | 
			
		||||
    
 | 
			
		||||
    auto mapped = data.toMap();
 | 
			
		||||
    int id = mapped.value("id").toInt();
 | 
			
		||||
    QString name = mapped.value("name").toString();
 | 
			
		||||
    int postCount;
 | 
			
		||||
    int category;
 | 
			
		||||
    
 | 
			
		||||
    switch(type) {
 | 
			
		||||
        case MoeBooru:
 | 
			
		||||
            postCount = mapped.value("count").toInt();
 | 
			
		||||
            category = mapped.value("type").toInt();
 | 
			
		||||
            break;
 | 
			
		||||
        default:
 | 
			
		||||
            postCount = mapped.value("post_count").toInt();
 | 
			
		||||
            category = mapped.value("category").toInt();
 | 
			
		||||
    };
 | 
			
		||||
    
 | 
			
		||||
    QVariantMap map = {
 | 
			
		||||
        {QL1S("id"), id}, 
 | 
			
		||||
        {QL1S("name"), name}, {QL1S("postCount"), postCount},
 | 
			
		||||
        {QL1S("category"), category}
 | 
			
		||||
    };
 | 
			
		||||
    
 | 
			
		||||
    return map;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QVariantMap extractPostData(const QVariant &data, ApiType type) {
 | 
			
		||||
 | 
			
		||||
    auto mapped = data.toMap();
 | 
			
		||||
| 
						 | 
				
			
			@ -322,36 +349,16 @@ QVariantMap extractPostData(const QVariant &data, ApiType type) {
 | 
			
		|||
            rating = RATING_MAP.value(mapped.value("rating").toString());
 | 
			
		||||
            fileSize = mapped.value("file_size").toInt();
 | 
			
		||||
            break;
 | 
			
		||||
        case Danbooru::Gelbooru:
 | 
			
		||||
            id = 0;
 | 
			
		||||
            tags = QSet<QString>();
 | 
			
		||||
            width = 0;
 | 
			
		||||
            height = 0;
 | 
			
		||||
            fileSize = 0;
 | 
			
		||||
            url = QUrl();
 | 
			
		||||
            thumbnailUrl = QUrl();
 | 
			
		||||
            sampleUrl = QUrl();
 | 
			
		||||
            rating = Danbooru::Safe;
 | 
			
		||||
            break;
 | 
			
		||||
        default:
 | 
			
		||||
            auto tagKey = mapped.contains("tag_string") ? QL1S("tag_string"): QL1S("tag-string");
 | 
			
		||||
            auto widthKey = mapped.contains("image_width") ? QL1S("image_width"): QL1S("image-width");
 | 
			
		||||
            auto heightKey = mapped.contains("image_height") ? QL1S("image_height"): QL1S("image-height");
 | 
			
		||||
            auto fileSizeKey = mapped.contains("file_size") ? QL1S("file_size"): QL1S("file-size");
 | 
			
		||||
            auto fileUrlKey = mapped.contains("file_url") ? QL1S("file_url"): QL1S("file-url");
 | 
			
		||||
            auto thumbnailUrlKey = mapped.contains("preview_file_url") ? QL1S("preview_file_url"): QL1S("preview-file-url");
 | 
			
		||||
            auto sampleUrlKey = mapped.contains("large_file_url") ? QL1S("large_file_url"): QL1S("large-file-url");
 | 
			
		||||
            
 | 
			
		||||
            id = mapped.value("id").toString().toInt();
 | 
			
		||||
            tags = QSet<QString>::fromList(mapped.value(tagKey).toString().split(' '));
 | 
			
		||||
            width = mapped.value(widthKey).toString().toInt();
 | 
			
		||||
            height = mapped.value(heightKey).toString().toInt();
 | 
			
		||||
            url = mapped.value(fileUrlKey).toUrl();
 | 
			
		||||
            thumbnailUrl = mapped.value(thumbnailUrlKey).toUrl();
 | 
			
		||||
            fileSize = mapped.value(fileSizeKey).toInt();
 | 
			
		||||
            tags = QSet<QString>::fromList(mapped.value("tag_string_general").toString().split(' '));
 | 
			
		||||
            width = mapped.value("image_width").toString().toInt();
 | 
			
		||||
            height = mapped.value("image_height").toString().toInt();
 | 
			
		||||
            url = mapped.value("file_url").toUrl();
 | 
			
		||||
            thumbnailUrl = mapped.value("preview_file_url").toUrl();
 | 
			
		||||
            fileSize = mapped.value("file_size").toInt();
 | 
			
		||||
            rating = RATING_MAP.value(mapped.value("rating").toString());
 | 
			
		||||
            sampleUrl = mapped.value(sampleUrlKey).toUrl();
 | 
			
		||||
            break;
 | 
			
		||||
            sampleUrl = mapped.value("large_file_url").toUrl();
 | 
			
		||||
    };
 | 
			
		||||
    
 | 
			
		||||
        
 | 
			
		||||
| 
						 | 
				
			
			@ -397,7 +404,7 @@ QList<QVariantMap> parseResult(const QByteArray &data, ApiType type, Danbooru::R
 | 
			
		|||
                qDebug() << "Reimplement";
 | 
			
		||||
                break;
 | 
			
		||||
            case Tag:
 | 
			
		||||
                qDebug() << "Reimplement";
 | 
			
		||||
                mapped = extractTagData(element, type);
 | 
			
		||||
                break;
 | 
			
		||||
            default:
 | 
			
		||||
                mapped = extractPostData(element, type);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -125,6 +125,7 @@ QList<QVariantMap> parseResult(const QXmlStreamAttributes &data, Danbooru::ApiTy
 | 
			
		|||
 | 
			
		||||
QVariantMap extractPostData(const QVariant &data, ApiType type);
 | 
			
		||||
QVariantMap extractPoolData(const QVariant &data, ApiType type);
 | 
			
		||||
QVariantMap extractTagData(const QVariant &data, ApiType type);
 | 
			
		||||
 | 
			
		||||
const QMap< QString, Danbooru::Rating > initRatingMap();
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue