⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 customface.cpp

📁 linux下的eva源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
					result = group.removeChild(e);					break;				}			}			break;		}		index++;		n = n.nextSibling();	}		if(!result.isNull()){		// remove success, so update count attribute		group.setAttribute(ATTR_count, group.childNodes().count());		return true;	}	// otherwise, remove failed	return false;}bool CustomFaceConfig::updateFaceTip( const int gId,							const  int fNo,							const QString & tip){	if(!m_Doc) return false;	if(gId <0 || gId >= numGroups())		return false; // out of range	QDomNode root = m_Doc->documentElement();	QDomNodeList groups = root.childNodes();	QDomNode node = groups.item(gId);	if(node.isNull()) return false;	QDomElement group = node.toElement();	QDomNode n = group.firstChild();	int index = 0;	while(!n.isNull()){		if(index == fNo){			QDomElement e = n.toElement();			if(!e.isNull()){				if( e.tagName() == TAG_FACE){					e.setAttribute(ATTR_tip, tip);					return true;				}			}			break;		}		index++;		n = n.nextSibling();	}	return false;}bool CustomFaceConfig::updateFaceShortcut( const int gId,							const  int fNo,							const QString & shortcut ){	if(!m_Doc) return false;	if(gId <0 || gId >= numGroups())		return false; // out of range	QDomNode root = m_Doc->documentElement();	QDomNodeList groups = root.childNodes();	QDomNode node = groups.item(gId);	if(node.isNull()) return false;	QDomElement group = node.toElement();	QDomNode n = group.firstChild();	int index = 0;	while(!n.isNull()){		if(index == fNo){			QDomElement e = n.toElement();			if(!e.isNull()){				if( e.tagName() == TAG_FACE){					e.setAttribute(ATTR_shortcut, shortcut);					return true;				}			}			break;		}		index++;		n = n.nextSibling();	}	return false;}bool CustomFaceConfig::addGroup(const QString &name){	if(name.isEmpty()) return false;	if(!m_Doc) createConfig();	QDomElement g = m_Doc->createElement(TAG_CUSTOMFACEGROUP);	g.setAttribute(ATTR_count, 0);	g.setAttribute(ATTR_version, FACE_GROUP_VERSION);	g.setAttribute(ATTR_name, name);	m_Doc->documentElement().appendChild(g);	return true;}bool CustomFaceConfig::removeGroup(const int groupIndex){	if(!m_Doc) return false;	// default group never be removed	if(groupIndex == 0) return false;	QDomNode root = m_Doc->documentElement();	QDomNodeList groups = root.childNodes();	printf("groupIndex: %d, nums: %d\n", groupIndex, groups.count());	QDomNode group = groups.item(groupIndex);	if(group.isNull()) return false;	QDomNode result = root.removeChild(group);	return (result.isNull()) ? false : true;}bool CustomFaceConfig::removeGroup( const QString & name ){	if(!m_Doc) return false;	QDomNode root = m_Doc->documentElement();	QDomNode n = root.firstChild();	QDomNode sibling;	printf("CustomFaceConfig::removeGroup: %s\n", name.local8Bit().data());	while(!n.isNull()){		QDomElement e = n.toElement();		sibling = e.nextSibling();		if(!e.isNull()){			if( e.tagName() == TAG_CUSTOMFACEGROUP){				printf("group name: %s\n", e.attribute(ATTR_name, "").local8Bit().data());				if(e.attribute(ATTR_name, "") == name){					QDomNode old = root.removeChild( e);					printf("finished remove\n");					if(old.isNull()) return false;					else return true;				}			}		}		n = sibling;	}	return false;}bool CustomFaceConfig::renameGroup( const QString & oldName, const QString & newName ){	if(!m_Doc) return false;		bool renamed = false;	QDomNode root = m_Doc->documentElement();	QDomNode n = root.firstChild();	while(!n.isNull()){		QDomElement e = n.toElement();		if(!e.isNull()){			if( e.tagName() == TAG_CUSTOMFACEGROUP){				if(e.attribute(ATTR_name, "") == oldName){					e.setAttribute( ATTR_name, newName);					renamed = true;				}			}		}		n = n.nextSibling();	}	return renamed;	}bool CustomFaceConfig::moveChildrenTo(const int srcIndex, const int destIndex){	if(!m_Doc) return false;	QDomNode root = m_Doc->documentElement();	QDomNodeList groups = root.childNodes();	QDomNode src = groups.item(srcIndex);	if(src.isNull()) return false;	QDomNode dest = groups.item(destIndex);	if(dest.isNull()) return false;	QDomNode n = src.firstChild();	QDomNode sibling;	while(!n.isNull()){		sibling = n.nextSibling();		n = src.removeChild( n );		dest.appendChild(n);		n = sibling;	}	return true;}int CustomFaceConfig::groupIndex( const QString & name ){	if(!m_Doc) return -1;	int count = -1, index = -1;	QDomNode root = m_Doc->documentElement();	QDomNode n = root.firstChild();	while(!n.isNull()){		QDomElement e = n.toElement();		if(!e.isNull()){			if(e.tagName() == TAG_CUSTOMFACE){				count++;				// note that QQ config file has not tag name for the default group				if( name == e.attribute(ATTR_name, i18n("Default")) ){					index = count;					break;				}			}			if( e.tagName() == TAG_CUSTOMFACEGROUP){				count++;				if( name == e.attribute(ATTR_name, "") ){					index = count;					break;				}			}		}		n = n.nextSibling();	}	return index;}const int CustomFaceConfig::numGroups(){	if(!m_Doc) return 0; // 0 means empty	return m_Doc->documentElement().childNodes().count();}QString CustomFaceConfig::groupName(const int groupIndex){	if(!m_Doc) return "";	QDomNode root = m_Doc->documentElement();	QDomNodeList groups = root.childNodes();	QDomNode node = groups.item(groupIndex);	if(node.isNull()) return "";	QDomElement group = node.toElement();	return group.attribute(ATTR_name, i18n("Default"));}QStringList CustomFaceConfig::groupNames(){	QStringList list;	if(!m_Doc) return list;	QDomNode root = m_Doc->documentElement();	QDomNode n = root.firstChild();	while(!n.isNull()){		QDomElement e = n.toElement();		if(!e.isNull()){			if( e.tagName() == TAG_CUSTOMFACEGROUP ||				e.tagName() == TAG_CUSTOMFACE){				list += e.attribute(ATTR_name, i18n("Default"));			}		}		n = n.nextSibling();	}		return list;}FaceList CustomFaceConfig::groupMembers(const int groupIndex){	FaceList list;	if(!m_Doc) return list;	QDomNode root = m_Doc->documentElement();	QDomNodeList groups = root.childNodes();	QDomNode node = groups.item(groupIndex);	if(node.isNull()) return list;	QDomElement group = node.toElement();	QDomNode n = group.firstChild();	while(!n.isNull()){		QDomElement e = n.toElement();		if(!e.isNull()){			if( e.tagName() == TAG_FACE){				QString id = e.attribute(ATTR_id, "");				QString shortcut = e.attribute(ATTR_shortcut, "");				QString tip = e.attribute(ATTR_tip, "");				QString frames = e.attribute(ATTR_multiframe, 0);				QString org, fixed;				QDomNode fsubN = e.firstChild();				if(fsubN.isNull()){					org = id+".jpg";					// fixed could be generated automatically in CustomFace					//fixed = id+"fixed.bmp";				} else {					QDomElement fsub = fsubN.toElement();					if(fsub.tagName() == TAG_FILE_ORG){						org = fsub.text();						// we got org, we might stop looking for fixed?						QDomNode fixN = fsub.nextSibling();						if(fixN.isNull()) fixed = org.left(org.findRev('.')) + "fixed.bmp";						else{							QDomElement ssub = fixN.toElement();							if(ssub.isNull()) 								fixed = org.left(org.findRev('.')) + "fixed.bmp";							else								fixed = ssub.text();						}					}else if(fsub.tagName() == TAG_FILE_FIXED){						fixed = fsub.text();						QDomNode orgN = fsub.nextSibling();						if(orgN.isNull())  // in this case, just a guess							org = fixed.left(org.findRev('.')) + ".jpg";						else{							QDomElement ssub = orgN.toElement();							if(ssub.isNull()) // give a guessed value								org = fixed.left(org.findRev('.')) + ".jpg";							else 								org = ssub.text();						}					}else {						org = id + ".jpg";						// don't care about fixed					}				}				// acutually, "fixed" is useless. only org used here				bool ok;				int num = frames.toInt(&ok);				CustomFace face(org, shortcut, tip, num, groupIndex);				list += face;			}		}		n = n.nextSibling();	}	return list;}bool CustomFaceConfig::loadXML(){	QFile xmlFile(m_Dir+"/"XML_FACE_FILE);	if(! xmlFile.open( IO_ReadOnly ) ) {		// if config file not existed we create an default config file		createConfig();		saveXML();		return false;	}		QTextStream xmlStream(&xmlFile);	xmlStream.setCodec(QTextCodec::codecForName("GB18030") );	QString xmlstr = xmlStream.read();	xmlFile.close();	xmlstr.replace(__FILE_ORG, TAG_FILE_ORG);	xmlstr.replace(__FILE_FIXED, TAG_FILE_FIXED);	if(!m_Doc) {		m_Doc = new QDomDocument();	}	bool result = false;	QString errmsg;	int line, col;	result = m_Doc->setContent(xmlstr, &errmsg, &line, &col);	if(!result){		printf("XML custom face config parse error @(%d, %d): %s\n", line, col, errmsg.local8Bit().data());	}	return result;}bool CustomFaceConfig::saveXML(){	if(!m_Doc) return false;	QString xmlstr = m_Doc->toString();	xmlstr.replace(TAG_FILE_ORG, __FILE_ORG);	xmlstr.replace(TAG_FILE_FIXED, __FILE_FIXED);	QFile xmlFile(m_Dir+"/"XML_FACE_FILE);	if(! xmlFile.open( IO_WriteOnly ) ) return false;	QTextStream xmlStream(&xmlFile);	xmlStream.setCodec(QTextCodec::codecForName("GB18030") );	xmlStream << xmlstr;	xmlFile.close();	return true;}QString CustomFaceConfig::toString() {	if(!m_Doc) return "";	return m_Doc->toString();}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -