📄 modelutils.java
字号:
/*
* LumaQQ - Java QQ Client
*
* Copyright (C) 2004 luma <stubma@163.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package edu.tsinghua.lumaqq;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import org.eclipse.swt.graphics.Image;
import edu.tsinghua.lumaqq.models.ClusterModel;
import edu.tsinghua.lumaqq.models.FriendModel;
import edu.tsinghua.lumaqq.models.GroupModel;
import edu.tsinghua.lumaqq.qq.QQ;
import edu.tsinghua.lumaqq.qq.Utils;
import edu.tsinghua.lumaqq.qq.beans.ClusterInfo;
import edu.tsinghua.lumaqq.qq.beans.ContactInfo;
import edu.tsinghua.lumaqq.qq.beans.QQFriend;
import edu.tsinghua.lumaqq.xml.groups.Cluster;
import edu.tsinghua.lumaqq.xml.groups.ClusterImpl;
import edu.tsinghua.lumaqq.xml.groups.Friend;
import edu.tsinghua.lumaqq.xml.groups.FriendImpl;
import edu.tsinghua.lumaqq.xml.groups.Group;
import edu.tsinghua.lumaqq.xml.groups.GroupImpl;
import edu.tsinghua.lumaqq.xml.groups.Groups;
import edu.tsinghua.lumaqq.xml.groups.GroupsImpl;
import edu.tsinghua.lumaqq.xml.logins.Logins;
import edu.tsinghua.lumaqq.xml.logins.LoginsImpl;
import edu.tsinghua.lumaqq.xml.proxies.Proxies;
import edu.tsinghua.lumaqq.xml.proxies.ProxiesImpl;
import edu.tsinghua.lumaqq.xml.remarks.Remarks;
import edu.tsinghua.lumaqq.xml.remarks.RemarksImpl;
import edu.tsinghua.lumaqq.xml.replies.Replies;
import edu.tsinghua.lumaqq.xml.replies.RepliesImpl;
import edu.tsinghua.lumaqq.xml.sysopts.GUIOption;
import edu.tsinghua.lumaqq.xml.sysopts.GUIOptionImpl;
import edu.tsinghua.lumaqq.xml.sysopts.LoginOption;
import edu.tsinghua.lumaqq.xml.sysopts.LoginOptionImpl;
import edu.tsinghua.lumaqq.xml.sysopts.MessageOption;
import edu.tsinghua.lumaqq.xml.sysopts.MessageOptionImpl;
import edu.tsinghua.lumaqq.xml.sysopts.Options;
import edu.tsinghua.lumaqq.xml.sysopts.OptionsImpl;
import edu.tsinghua.swt.models.INode;
/**
* 这个类负责提供一些创建数据的方法,纯粹是为了免得个别的文件行数太多,
* 所以把这些集中操作底层数据的方法抽出来放在一个工具类里
*
* @author 马若劼
*/
public class ModelUtils {
/**
* 从QQFriend类创建一个contact info结构
* @param friend QQFriend
* @return ContactInfo
*/
public static ContactInfo createContact(QQFriend friend) {
ContactInfo ret = new ContactInfo();
ret.infos[ret.nick] = friend.nick;
ret.infos[ret.qqStr] = String.valueOf(friend.qqNum);
ret.infos[ret.age] = String.valueOf(friend.age);
if(friend.isGG())
ret.infos[ret.gender] = LumaQQ.getResourceString("gender.gg");
else
ret.infos[ret.gender] = LumaQQ.getResourceString("gender.mm");
return ret;
}
/**
* 从FriendModel创建一个ContactInfo
* @param f
* @return
*/
public static ContactInfo createContact(FriendModel f) {
ContactInfo ret = new ContactInfo();
ret.infos[ret.nick] = (String)f.getProperty("name");
ret.infos[ret.qqStr] = ((Integer)f.getProperty("qq")).toString();
ret.infos[ret.face] = ((Integer)f.getProperty("face")).toString();
return ret;
}
/**
* 从Friend元素创建一个ContactInfo对象
* @param friend Friend元素对象
* @return ContactInfo
*/
public static ContactInfo createContact(Friend friend) {
ContactInfo ret = new ContactInfo();
ret.infos[ret.qqStr] = friend.getQqNum();
ret.infos[ret.nick] = friend.getNick();
ret.infos[ret.name] = friend.getName();
ret.infos[ret.age] = friend.getAge();
ret.infos[ret.face] = friend.getFace();
ret.infos[ret.gender] = friend.getGender();
ret.infos[ret.country] = friend.getCountry();
ret.infos[ret.province] = friend.getProvince();
ret.infos[ret.city] = friend.getCity();
ret.infos[ret.email] = friend.getEmail();
ret.infos[ret.address] = friend.getAddress();
ret.infos[ret.zipcode] = friend.getZipcode();
ret.infos[ret.telephone] = friend.getTelephone();
ret.infos[ret.mobile] = friend.getMobile();
ret.infos[ret.college] = friend.getCollege();
ret.infos[ret.occupation] = friend.getOccupation();
ret.infos[ret.homepage] = friend.getHomepage();
ret.infos[ret.intro] = friend.getIntro();
ret.infos[ret.horoscope] = friend.getHoroscope();
ret.infos[ret.zodiac] = friend.getZodiac();
ret.infos[ret.blood] = friend.getBlood();
ret.infos[ret.openContact] = friend.getOpenContact();
ret.infos[ret.openHp] = friend.getOpenHp();
ret.infos[ret.authType] = friend.getAuthType();
return ret;
}
/**
* 从XML元素中创建GroupModel
* @param group Group元素对象
* @return GroupModel
*/
public static GroupModel createGroupModel(Group group) {
GroupModel ret = new GroupModel(group.getName());
ret.addProperty("friendly", group.getFriendly());
ret.addProperty("blacklist", group.getBlacklist());
ret.addProperty("visible", group.getVisible());
ret.addProperty("upload", group.getUpload());
ret.addProperty("cluster", group.getIsCluster());
return ret;
}
/**
* 从Friend元素创建一个FriendModel
* @param friend Friend元素对象
* @return FriendModel
*/
public static FriendModel createFriendModel(Friend friend) {
// 得到头像ID,如果解析失败,使用缺省值0,加1是因为初始都是不在线状态
int faceId = Utils.getInt(friend.getFace(), 0);
int locationX = Utils.getInt(friend.getLocationX(), -1);
int locationY = Utils.getInt(friend.getLocationY(), -1);
// 得到头像,加1是因为一开始都要把好友置成离线状态
Image face = IconHolder.getInstance().getFace(faceId + 1);
// 创建FriendModel
FriendModel ret = new FriendModel(friend.getNick(), face);
// 设置其他属性
ret.addProperty("qq", new Integer(friend.getQqNum()));
ret.addProperty("nick", friend.getNick());
ret.addProperty("face", new Integer(faceId));
ret.addProperty("member", friend.getMember());
ret.addProperty("status", "offline");
ret.addProperty("contact", createContact(friend));
ret.addProperty("talkMode", friend.getTalkMode());
ret.addProperty("locationX", new Integer(locationX));
ret.addProperty("locationY", new Integer(locationY));
return ret;
}
/**
* 从QQFriend类创建一个FriendModel
* @param friend
* @return
*/
public static FriendModel createFriendModel(QQFriend friend) {
int faceId = friend.face & 0xFF;
// 得到头像
Image face = IconHolder.getInstance().getFace(faceId + 1);
// 创建FriendModel
FriendModel ret = new FriendModel(friend.nick, face);
// 设置其他属性
ret.addProperty("qq", new Integer(friend.qqNum));
ret.addProperty("nick", friend.nick);
ret.addProperty("face", new Integer(faceId));
ret.addProperty("loginTime", new Date(friend.loginTime).toString());
ret.addProperty("status", "offline");
ret.addProperty("member", String.valueOf(friend.isMember()));
ret.addProperty("contact", createContact(friend));
return ret;
}
/**
* 创建群的Model
* @param cluster
* @return
*/
public static ClusterModel createClusterModel(Cluster cluster) {
int faceId = Utils.getInt(cluster.getFace(), 1);
// 得到头像
Image face = IconHolder.getInstance().getClusterFace(faceId);
// 创建FriendModel
ClusterModel ret = new ClusterModel(cluster.getClusterId(), cluster.getName(), face);
// 设置其他属性
ClusterInfo info = createClusterInfo(cluster);
ret.addProperty("face", new Integer(faceId));
ret.addProperty("info", info);
ret.addProperty("message", cluster.getMessage());
ret.addProperty("permanent", String.valueOf(info.type == QQ.QQ_CLUSTER_TYPE_PERMANENT));
return ret;
}
/**
* 从Cluster创建一个ClusterInfo对象
* @param cluster Cluster对象
* @return 创建的ClusterInfo对象
*/
public static ClusterInfo createClusterInfo(Cluster cluster) {
ClusterInfo ret = new ClusterInfo();
try {
ret.name = cluster.getName();
ret.description = cluster.getDescription();
ret.notice = cluster.getNotice();
ret.clusterId = Integer.parseInt(cluster.getClusterId());
ret.externalId = Integer.parseInt(cluster.getExternalId());
ret.type = (byte)Integer.parseInt(cluster.getType());
ret.authType = (byte)Integer.parseInt(cluster.getAuthType());
ret.category = (char)Integer.parseInt(cluster.getCategory());
ret.creator = Integer.parseInt(cluster.getCreator());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -