📄 userinfowindow.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.ui.config.user;
import static edu.tsinghua.lumaqq.resource.Messages.*;
import static org.apache.commons.codec.digest.DigestUtils.md5;
import java.io.File;
import java.util.Iterator;
import org.apache.commons.codec.binary.Base64;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import edu.tsinghua.lumaqq.LumaQQ;
import edu.tsinghua.lumaqq.ecore.login.Login;
import edu.tsinghua.lumaqq.ecore.login.Logins;
import edu.tsinghua.lumaqq.ecore.remark.Remark;
import edu.tsinghua.lumaqq.ecore.remark.RemarkFactory;
import edu.tsinghua.lumaqq.eutil.LoginUtil;
import edu.tsinghua.lumaqq.models.User;
import edu.tsinghua.lumaqq.qq.QQ;
import edu.tsinghua.lumaqq.qq.beans.Card;
import edu.tsinghua.lumaqq.qq.beans.ContactInfo;
import edu.tsinghua.lumaqq.qq.beans.FriendRemark;
import edu.tsinghua.lumaqq.qq.events.IQQListener;
import edu.tsinghua.lumaqq.qq.events.QQEvent;
import edu.tsinghua.lumaqq.qq.packets.in.ClusterCommandReplyPacket;
import edu.tsinghua.lumaqq.qq.packets.in.FriendDataOpReplyPacket;
import edu.tsinghua.lumaqq.qq.packets.in.SignatureOpReplyPacket;
import edu.tsinghua.lumaqq.qq.packets.out.ClusterModifyCardPacket;
import edu.tsinghua.lumaqq.qq.packets.out.FriendDataOpPacket;
import edu.tsinghua.lumaqq.qq.packets.out.ModifyInfoPacket;
import edu.tsinghua.lumaqq.resource.Resources;
import edu.tsinghua.lumaqq.ui.MainShell;
import edu.tsinghua.lumaqq.ui.config.AbstractConfigurationWindow;
import edu.tsinghua.lumaqq.ui.config.AbstractPage;
import edu.tsinghua.lumaqq.ui.config.IPacketFiller;
/**
* 用户信息窗口
*
* @author luma
*/
public class UserInfoWindow extends AbstractConfigurationWindow implements IQQListener {
private MainShell main;
private User model;
private ModifyInfoPacket mip;
private ClusterModifyCardPacket cmcp;
// true表示群名片已经自动请求过
private boolean cardUpdated;
// true表示个性签名要修改
private boolean modifySignature;
// true表示其他信息已经修改成功
private boolean infoModified;
private boolean sigModified;
private char sigSequence;
// style
/** 用户资料可以编辑,对应于修改个人设置窗口 */
public static final int EDITABLE = 1;
/** 用户资料只读,对应于查看好友资料窗口 */
public static final int READ_ONLY = 2;
/**
* 还没有添加为好友的用户资料页面,此种类型的页面不可以编辑备注。
*/
public static final int REALLY_READ_ONLY = 4;
// 页ID
public static final int PERSONAL_INFO = 0;
public static final int QQ_SHOW = 1;
@SuppressWarnings("unused")
public static final int CONTACT = 2;
public static final int SECURITY = 3;
public static final int REMARK = 3;
public static final int CARD = 4;
/**
* @param parent
*/
public UserInfoWindow(MainShell main, User model, int style) {
super(main.getShell(), style);
this.model = model;
this.main = main;
cardUpdated = false;
modifySignature = false;
setOKButtonText(button_modify);
}
/* (non-Javadoc)
* @see edu.tsinghua.lumaqq.shells.AbstractConfigurationWindow#initialPages()
*/
@Override
protected void initialPages() {
addPage(new PersonalPage(getPageContainer(), model, style));
addPage(new QQShowPage(getPageContainer(), main, model, style));
addPage(new ContactPage(getPageContainer(), model, style));
if(isEditable())
addPage(new SecurityPage(getPageContainer(), model));
if(isReadOnly())
addPage(new RemarkPage(getPageContainer(), main, model));
if(hasCluster())
addPage(new CardPage(getPageContainer(), model, style));
main.getClient().addQQListener(this);
}
/**
* @return
* true表示这个用户在一个群中
*/
private boolean hasCluster() {
return model.group != null && model.group.isCluster();
}
private boolean isEditable() {
return (style & EDITABLE) != 0;
}
private boolean isReadOnly() {
return (style & READ_ONLY) != 0;
}
private boolean isReallyReadOnly() {
return (style & REALLY_READ_ONLY) != 0;
}
/* (non-Javadoc)
* @see edu.tsinghua.lumaqq.shells.AbstractConfigurationWindow#onOK()
*/
@Override
protected void onOK() {
if(isEditable()) {
setOKButtonEnabled(false);
if(getCurrentPageId() == CARD) {
cmcp = new ClusterModifyCardPacket(main.getClient().getUser());
Iterator<AbstractPage> i = getPageIterator();
while(i.hasNext()) {
AbstractPage page = i.next();
if(page instanceof IPacketFiller)
((IPacketFiller)page).fill(cmcp);
}
main.getClient().sendPacket(cmcp);
} else {
// 检查旧密码是否输入正确
if(!((SecurityPage)getPage(SECURITY)).checkOldPassword()) {
MessageDialog.openError(parentShell, message_box_change_password_title, error_old_password_wrong);
setOKButtonEnabled(true);
return;
}
// 检查新密码是否输入正确
if(!((SecurityPage)getPage(SECURITY)).checkNewPassword()) {
MessageDialog.openError(parentShell, message_box_change_password_title, error_two_password_differ);
setOKButtonEnabled(true);
return;
}
// 组装包
mip = new ModifyInfoPacket(main.getClient().getUser());
mip.setContactInfo(new ContactInfo());
Iterator<AbstractPage> i = getPageIterator();
while(i.hasNext()) {
AbstractPage page = i.next();
if(page instanceof IPacketFiller)
((IPacketFiller)page).fill(mip);
}
// 检查是否需要修改个性签名
PersonalPage pp = (PersonalPage)getPage(PERSONAL_INFO);
modifySignature = pp.isSignatureModified();
if(modifySignature) {
if(pp.getSignature().equals(""))
sigSequence = main.getClient().deleteSignature();
else
sigSequence = main.getClient().modifySignature(pp.getSignature());
}
// 发送包
main.getClient().sendPacket(mip);
}
} else {
switch(getCurrentPageId()) {
case REMARK:
RemarkPage page = (RemarkPage)getPage(REMARK);
page.doSave();
break;
case CARD:
main.getClient().getCard(model.cluster.clusterId, model.qq);
break;
default:
main.getClient().getUserInfo(model.qq);
break;
}
}
}
/* (non-Javadoc)
* @see edu.tsinghua.lumaqq.shells.AbstractConfigurationWindow#pageChanged()
*/
@Override
protected void pageChanged() {
if(isReadOnly()) {
switch(getCurrentPageId()) {
case REMARK:
setOKButtonText(button_modify);
break;
default:
setOKButtonText(button_update);
break;
}
} else if (isReallyReadOnly()) {
setOKButtonText(button_update);
}
if(cardUpdated == false && getCurrentPageId() == CARD) {
main.getClient().getCard(model.cluster.clusterId, model.qq);
cardUpdated = true;
}
}
/* (non-Javadoc)
* @see edu.tsinghua.lumaqq.shells.AbstractConfigurationWindow#onShellClose()
*/
@Override
protected void onShellClose() {
main.getShellRegistry().removeUserInfoWindow(model);
main.getClient().removeQQListener(this);
}
/* (non-Javadoc)
* @see edu.tsinghua.lumaqq.shells.AbstractConfigurationWindow#getTitle()
*/
@Override
protected String getTitle() {
return isEditable() ? user_info_title_modify : user_info_title_view;
}
/* (non-Javadoc)
* @see edu.tsinghua.lumaqq.shells.AbstractConfigurationWindow#getImage()
*/
@Override
protected Image getImage() {
return Resources.getInstance().getImage(Resources.icoPersonInfo);
}
/* (non-Javadoc)
* @see edu.tsinghua.lumaqq.shells.AbstractConfigurationWindow#getInitialSize()
*/
@Override
protected Point getInitialSize() {
return new Point(600, 550);
}
/**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -