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

📄 userinfoshell.java

📁 类似于MSN
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/*
* 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.shells;

import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.events.ShellAdapter;
import org.eclipse.swt.events.ShellEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import starlight.util.Base64;
import edu.tsinghua.lumaqq.IconHolder;
import edu.tsinghua.lumaqq.LumaQQ;
import edu.tsinghua.lumaqq.models.FriendModel;
import edu.tsinghua.lumaqq.qq.QQ;
import edu.tsinghua.lumaqq.qq.Utils;
import edu.tsinghua.lumaqq.qq.beans.ContactInfo;
import edu.tsinghua.lumaqq.qq.beans.FriendRemark;
import edu.tsinghua.lumaqq.qq.events.QQEvent;
import edu.tsinghua.lumaqq.qq.events.QQListener;
import edu.tsinghua.lumaqq.qq.packets.in.FriendRemarkOpReplyPacket;
import edu.tsinghua.lumaqq.qq.packets.out.FriendRemarkOpPacket;
import edu.tsinghua.lumaqq.utils.OptionUtils;
import edu.tsinghua.lumaqq.utils.RemarkUtils;
import edu.tsinghua.lumaqq.xml.logins.Login;
import edu.tsinghua.lumaqq.xml.logins.Logins;
import edu.tsinghua.lumaqq.xml.logins.LoginsUnmarshaller;
import edu.tsinghua.lumaqq.xml.remarks.Remark;
import edu.tsinghua.lumaqq.xml.remarks.RemarkImpl;
import edu.tsinghua.swt.widgets.MySWT;
import edu.tsinghua.swt.widgets.ShutterLabel;

/**
 * 查看用户信息的对话框
 * 
 *  * @author 马若劼
 */
public class UserInfoShell extends ShellAdapter implements DisposeListener, QQListener {
    // banner的paint事件监听器
    private class BannerPaintListener implements PaintListener {
        private String text;
        
        public BannerPaintListener(String text) {
            this.text = text;            
        }
        
        public void paintControl(PaintEvent e) {
            Control control = (Control)e.widget;
            Rectangle ca = control.getBounds();
            Point extent = e.gc.textExtent(text);
            e.gc.drawString(text, (ca.width - extent.x) / 2, (ca.height - extent.y) / 2);
        }
    }
    
	// 监听备注信息改变事件,把修改按钮使能
	private class RemarkTextModifiedListener implements ModifyListener {
		public void modifyText(ModifyEvent e) {
			btnUpdate.setEnabled(true);
		}
	}
	
	// 头像选择框监听器,在选择框关闭的时候得到选择的代码
	private class FacePanelListener extends ShellAdapter {
		public void shellClosed(ShellEvent e) {
			int code = iss.getSelectedImageCode();
			if(code != -1)
				faceId = code;
			btnFace.setImage(icons.getFace(faceId));
		}
	}
	
	protected static Log log = LogFactory.getLog(UserInfoShell.class);
    private IconHolder icons = IconHolder.getInstance();
    
	private ShutterLabel[] buttons;
	private Composite[] composites;
	private ShutterLabel prevButton;	
	private Composite prevComposite;
	private int prevPanel;
	private static final int PANEL_NUM = 5;
	private static final int BASIC = 0;
	private static final int CONTACT = 1;
	private static final int DETAIL = 2;
	private static final int SECURITY = 3;
	private static final int REMARK = 4;
	
	private Display display;
    private MainShell main;
	private Shell shell;
	private Label basicBanner, contactBanner, detailBanner, securityBanner;
	private Label qqShow;
	private ShutterLabel btnUpdate, btnModify, btnFace;
	private boolean canModified;
	private CCombo comboGender, comboCountry, comboProvince;
	private CCombo comboHoroscope, comboBlood, comboZodiac, comboOccupation;
	private FriendModel f;
	private ImageSelectShell iss;
	private int qqNum, faceId;
	private Button radioAnyOne, radioAuth, radioNever, chkChangePassword;
	private Button radioOpen, radioOnlyFriend, radioClose;
    private Color switchButtonColor, controlBackground, bannerBackground, panelBackground, commonButtonColor;
	private Text textName, textCollege, textHomePage, textIntro;
	private Text textOldPassword, textNewPassword, textConfirmPassword;
	private Text textQQ, textNick, textAge, textGender, textCity, textEmail, textAddress, textZipcode, textTelephone, textMobile;
	private Text textRemarkName, textRemarkZipcode, textRemarkTelephone, textRemarkMobile, textRemarkEmail, textRemarkAddress, textRemarkNote;
	private ShutterLabel btnUploadRemark, btnDownloadRemark, btnUpdateQQShow;
	private RemarkTextModifiedListener rtml;
	private Image qqShowImage;
    
	/**
	 * @param parent
	 */
	public UserInfoShell(MainShell main) {
		this.main = main;
		this.display = main.display;
		shell = new Shell(display, SWT.TITLE | SWT.CLOSE | SWT.MIN);
		shell.setSize(450, 320);
		shell.setImage(icons.getResource(IconHolder.icoQQ));
		// 设置layout
		shell.setLayout(new FormLayout());
		// 添加事件监听器
		shell.addDisposeListener(this);
		shell.addShellListener(this);
		
		// 初始化变量
        panelBackground = new Color(display, 0xF3, 0xF3, 0xF3);
        controlBackground = new Color(display, 0xF7, 0xE2, 0xF7);
        bannerBackground = new Color(display, 0x5D, 0x83, 0xD4);
        commonButtonColor = new Color(display, 0xC6, 0xD3, 0xF7);
        switchButtonColor = bannerBackground;
        buttons = new ShutterLabel[PANEL_NUM];
        composites = new Composite[PANEL_NUM];
        faceId = 0;
        rtml = new RemarkTextModifiedListener();
		
		initLayout();
	}
	
	// 把各个输入框的内容组装成ContactInfo类
	protected ContactInfo assembleContactInfo() {
		ContactInfo info = new ContactInfo();
		info.infos[info.qqStr] = textQQ.getText();
		info.infos[info.nick] = textNick.getText();
		info.infos[info.face] = String.valueOf(faceId);
		info.infos[info.age] = textAge.getText();
		info.infos[info.gender] = comboGender.getText();
		info.infos[info.country] = comboCountry.getText();
		info.infos[info.province] = comboProvince.getText();
		info.infos[info.city] = textCity.getText();
		info.infos[info.email] = textEmail.getText();
		info.infos[info.address] = textAddress.getText();
		info.infos[info.zipcode] = textZipcode.getText();
		info.infos[info.telephone] = textTelephone.getText();
		info.infos[info.mobile] = textMobile.getText();
		if(radioOpen.getSelection())
			info.infos[info.openContact] = "0";
		else if(radioOnlyFriend.getSelection())
			info.infos[info.openContact] = "1";
		else
			info.infos[info.openContact] = "2";
		info.infos[info.name] = textName.getText();
		info.infos[info.college] = textCollege.getText();
		info.infos[info.occupation] = comboOccupation.getText();
		info.infos[info.zodiac] = String.valueOf(comboZodiac.indexOf(comboZodiac.getText()));
		info.infos[info.blood] = String.valueOf(comboBlood.indexOf(comboBlood.getText()));
		info.infos[info.horoscope] = String.valueOf(comboHoroscope.indexOf(comboHoroscope.getText()));
		info.infos[info.homepage] = textHomePage.getText();
		info.infos[info.intro] = textIntro.getText();
		if(radioAnyOne.getSelection())
			info.infos[info.authType] = "0";
		else if(radioAuth.getSelection())
			info.infos[info.authType] = "1";
		else
			info.infos[info.authType] = "2";
		return info;
	}

	// 检查新密码
	private boolean checkNewPassword() {
		if(textNewPassword.getText().equals(textConfirmPassword.getText()))
			return true;
		else
			return false;
	}

	// 检查旧密码
	private boolean checkOldPassword() {
		// 加密消息
		if(textOldPassword.getText() != null) {
			Logins logins = null;
			try {
				logins = LoginsUnmarshaller.unmarshal(new File(LumaQQ.LOGIN_HISTORY));
			} catch (IOException e) {
				log.error("无法读取登陆历史信息文件");
				return false;
			}
			List list = logins.getLoginList();
			Iterator iter = list.iterator();
			while(iter.hasNext()) {
				Login login = (Login)iter.next();
				if(login.getQq().equals(((Integer)f.getProperty("qq")).toString())) {
					// 哈,这里就是要人看着晕~
					String s = "";
					if(login.getRememberPassword().equalsIgnoreCase("true")) 
						s = new String(Base64.encode(Utils.doMD5(Utils.doMD5(textOldPassword.getText().getBytes()))));
					else
						s = new String(Base64.encode(Utils.doMD5(new String(Base64.encode(Utils.doMD5(Utils.doMD5(textOldPassword.getText().getBytes())))).getBytes())));
					if(login.getPassword().equals(s))
						return true;
					else
						return false;
				}
			}
			return false;
		} else
			return false;
	}
	
	/**
	 * 关闭窗口
	 */
	public void close() {
		shell.close();
	}
	
	// 创建一个面板
	private Composite createPanel() {
		Composite comp = new Composite(shell, SWT.NONE);
		comp.setBackground(panelBackground);
		FormData fd = new FormData();
		fd.left = new FormAttachment(buttons[0], 5, SWT.RIGHT);
		fd.right = new FormAttachment(100, -5);
		fd.top = new FormAttachment(0, 5);
		fd.bottom = new FormAttachment(100, -36);
		comp.setLayoutData(fd);
		comp.setLayout(new FormLayout());
		return comp;
	}

	// 初始化各控件的值
	public void freshValue() {
		// 昵称和头像和QQ号放到前面来设置,万一contact info是空的话,至少也保证
		//     能显示出昵称和头像和QQ号
		textNick.setText((String)f.getProperty("nick"));
		textQQ.setText(((Integer)f.getProperty("qq")).toString());
		btnFace.setImage(main.getFriendFace(f));
		// 开始设置其他联系信息
		ContactInfo info = (ContactInfo)f.getProperty("contact");
		if(info == null) return;
		// 年龄
		textAge.setText(info.infos[info.age]);
		// 性别
		comboGender.setText(info.infos[info.gender]);
		// 国家/地区
		comboCountry.setText(info.infos[info.country]);
		// 省份
		comboProvince.setText(info.infos[info.province]);
		// 城市
		textCity.setText(info.infos[info.city]);
		// email
		textEmail.setText(info.infos[info.email]);
		// 地址
		textAddress.setText(info.infos[info.address]);
		// 邮政编码
		textZipcode.setText(info.infos[info.zipcode]);
		// 电话
		textTelephone.setText(info.infos[info.telephone]);
		// 手机
		textMobile.setText(info.infos[info.mobile]);
		// 通讯信息可见性
		int openContact = Utils.getInt(info.infos[info.openContact], 0);
		if(openContact == QQ.QQ_CONTACT_OPEN) {
			radioOpen.setSelection(true);
			radioOnlyFriend.setSelection(false);
			radioClose.setSelection(false);
		} else if(openContact == QQ.QQ_CONTACT_ONLY_FRIENDS) {
			radioOpen.setSelection(false);
			radioOnlyFriend.setSelection(true);
			radioClose.setSelection(false);
		} else {
			radioOpen.setSelection(false);
			radioOnlyFriend.setSelection(false);
			radioClose.setSelection(true);			

⌨️ 快捷键说明

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