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

📄 logindialog.java

📁 lumaQQ的源文件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
* 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.dialogs;

import static edu.tsinghua.lumaqq.resource.Messages.*;
import static org.apache.commons.codec.digest.DigestUtils.md5;

import java.io.File;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
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.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import edu.tsinghua.lumaqq.LumaQQ;
import edu.tsinghua.lumaqq.ecore.LoginOption;
import edu.tsinghua.lumaqq.ecore.ProxyType;
import edu.tsinghua.lumaqq.ecore.login.Login;
import edu.tsinghua.lumaqq.ecore.login.LoginFactory;
import edu.tsinghua.lumaqq.ecore.login.Logins;
import edu.tsinghua.lumaqq.eutil.LoginUtil;
import edu.tsinghua.lumaqq.models.ModelUtils;
import edu.tsinghua.lumaqq.qq.Util;
import edu.tsinghua.lumaqq.resource.Colors;
import edu.tsinghua.lumaqq.resource.Resources;
import edu.tsinghua.lumaqq.ui.BorderStyler;
import edu.tsinghua.lumaqq.ui.helper.UITool;
import edu.tsinghua.lumaqq.ui.listener.AroundBorderPaintListener;
import edu.tsinghua.lumaqq.widgets.qstyle.Slat;


/**
 * 登陆对话框
 *
 * @author luma
 * @author starboy
 */
public class LoginDialog extends Dialog {
    // Log对象
    protected static Log log = LogFactory.getLog(LoginDialog.class);
    // Shell
    private Shell dialog;
    // 是否记住密码
    private boolean rememberPassword;
    // 是否隐身登陆
    private boolean loginHidden;
    // 是否自动登录
    private boolean autoLogin;
    // 是否忽略自动登录选项
    private boolean ignoreAuto;
    // 用户QQ号
    private int qqNum;
    // 密码的MD5形式
    private byte[] md5pwd;
    // 所有组件
    private Slat btnLogin, btnCancel;
    private Button chkRemember, chkHidden, chkAuto;
    private Text text;
    private CCombo combo;
    // 用户是否点了登陆按钮
    private boolean ok;
    // 登陆历史信息文件根元素对象
    private Logins logins;
    // 用户这次是否修改了密码
    private boolean changed;
    // 是否使用登录框的网络设置
    private boolean useNetworkSetting;
    // IconHolder实例
    private Resources res = Resources.getInstance();
    // Base64 codec
    private Base64 codec = new Base64();
	private Composite networkContainer;
	private CCombo comboServer;
	private CCombo comboPort;
	private Button chkAutoSelect;
	private Button rdoUdp;
	private Button rdoTcp;
	private Text textProxyServer;
	private Text textProxyPort;
	private Text textUsername;
	private Text textPassword;
	private CCombo comboProxyType;
	
	// 没有显示网络设置时的大小
	private Rectangle smallRect;
    
    /**
     * 构造函数
     * 
     * @param shell
     * 		父窗口
     * @param ignoreAuto
     * 		true表示忽略掉自动登录选项,不要自动返回
     */
    public LoginDialog(Shell shell, boolean ignoreAuto) {
        super(shell, SWT.NO_TRIM | SWT.NO_BACKGROUND);
        this.ignoreAuto = ignoreAuto;
    }

    /**
     * @param dialog
     */
    private void initLayout() {  
    	BorderStyler styler = new BorderStyler();
    	styler.setHideWhenMinimize(false);
    	styler.setResizable(false);
    	Composite center = styler.decorateShell(dialog);
    	
        GridLayout layout = new GridLayout();
        layout.marginHeight = layout.marginWidth = layout.verticalSpacing = layout.horizontalSpacing = 0;
        center.setLayout(layout);
        center.setBackground(Colors.LOGIN_BACKGROUND);

        UITool.setDefaultBackground(Colors.LOGIN_BACKGROUND);
        
        // logo
        Label lblLogo = UITool.createLabel(center, "", SWT.CENTER);
        setLogo(lblLogo);
        
        layout = new GridLayout(4, false);
        layout.marginHeight = layout.marginWidth = 25;
        layout.verticalSpacing = 14;
        layout.horizontalSpacing = 10;        
        Composite c = UITool.createContainer(center, new GridData(GridData.FILL_BOTH), layout);
        c.addPaintListener(new PaintListener() {
            public void paintControl(PaintEvent e) {
                Rectangle rect = ((Composite)e.getSource()).getClientArea();
                rect.x = rect.y = 5;
                rect.width -= 10;
                rect.height -= 10;
                e.gc.setForeground(Colors.PAGE_CONTROL_BORDER);
                e.gc.drawRectangle(rect);
            }
        });
        c.addPaintListener(new AroundBorderPaintListener(new Class[] { Text.class, CCombo.class }, Colors.PAGE_CONTROL_BORDER));

        // 号码
        UITool.createLabel(c, login_qq_number);
        // 号码下拉框
        GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
        gd.horizontalSpan = 2;
        gd.heightHint = 18;
        combo = UITool.createCCombo(c, gd, SWT.FLAT);
        combo.setBackground(Colors.WHITE);
        // placeholder
        UITool.createLabel(c, "");
        
        // 密码
        UITool.createLabel(c, login_qq_password);
        // 密码框
        gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
        gd.horizontalSpan = 2;
        gd.heightHint = 18;
        text = UITool.createSingleText(c, gd, SWT.SINGLE | SWT.PASSWORD);
        text.setBackground(Colors.WHITE);
        text.setEchoChar('*');
        // placeholder
        UITool.createLabel(c, "");
        
        // placeholder
        UITool.createLabel(c, "");        
        // 记住密码
        chkRemember = UITool.createCheckbox(c, login_remember_password);
        // 隐身登陆
        chkHidden = UITool.createCheckbox(c, login_hidden, new GridData(GridData.HORIZONTAL_ALIGN_END));
        // 自动登录
        chkAuto = UITool.createCheckbox(c, login_auto);
        chkAuto.addSelectionListener(new SelectionAdapter() {
        	@Override
        	public void widgetSelected(SelectionEvent e) {
        		if(chkAuto.getSelection())
        			chkRemember.setSelection(true);
        		chkRemember.setEnabled(!chkAuto.getSelection());
        	}
        });
        
        // 按钮区容器
        layout = new GridLayout(3, false);
        layout.horizontalSpacing = 10;
        c = UITool.createContainer(center, new GridData(GridData.FILL_HORIZONTAL), layout);
        
        // 网络设置
        gd = new GridData();
        gd.widthHint = 80;
        Slat btnNetwork = UITool.createSlat(c, login_network, gd);
        btnNetwork.addMouseListener(new MouseAdapter() {
        	@Override
        	public void mouseUp(MouseEvent e) {
        		switchNetworkSetting(); 
        	}
        });
        // 登录
        gd = new GridData(GridData.HORIZONTAL_ALIGN_END);
        gd.grabExcessHorizontalSpace = true;
        gd.widthHint = 70;
        btnLogin = UITool.createSlat(c, button_login, gd);
        // 取消
        gd = new GridData();
        gd.widthHint = 70;
        btnCancel = UITool.createSlat(c, button_cancel, gd); 
        
        gd = new GridData(GridData.FILL_HORIZONTAL);
        gd.exclude = true;
        networkContainer = UITool.createContainer(center, gd, new GridLayout());
		// 网络设置组
        Group netGroup = UITool.createGroup(networkContainer, login_network, new GridLayout());

        layout = new GridLayout(4, false);
        layout.marginWidth = layout.marginHeight = 0;
        Composite comp = UITool.createContainer(netGroup, new GridData(GridData.FILL_HORIZONTAL), layout);
        // 登录方式
        UITool.createLabel(comp, sys_opt_group_login);
        rdoUdp = UITool.createRadio(comp, sys_opt_login_method_udp);
		rdoTcp = UITool.createRadio(comp, sys_opt_login_method_tcp);
		chkAutoSelect = UITool.createCheckbox(comp, sys_opt_login_server_random);
        chkAutoSelect.setSelection(true);
		rdoTcp.setLayoutData(gd);
        rdoTcp.setSelection(true);
        rdoUdp.addSelectionListener(new SelectionAdapter() {
        	@Override
        	public void widgetSelected(SelectionEvent e) {
        		switchMethod(true);
        	}
        });
        rdoTcp.addSelectionListener(new SelectionAdapter() {
        	@Override
        	public void widgetSelected(SelectionEvent e) {
        		switchMethod(false);
        	}
        });
        
        layout = new GridLayout(4, false);
        layout.marginHeight = 1;
        layout.marginWidth = 0;
        layout.marginRight = 1;
        layout.verticalSpacing = 7;
        comp = UITool.createContainer(netGroup, new GridData(GridData.FILL_HORIZONTAL), layout);        
        comp.addPaintListener(new AroundBorderPaintListener(new Class[] { CCombo.class, Text.class }, Colors.PAGE_CONTROL_BORDER));
        // 服务器地址
        UITool.createLabel(comp, sys_opt_group_server);
        comboServer = UITool.createCCombo(comp, new GridData(GridData.FILL_HORIZONTAL), SWT.FLAT);
		// 端口
        UITool.createLabel(comp, sys_opt_login_proxy_port);
        comboPort = UITool.createCCombo(comp, new GridData(GridData.FILL_HORIZONTAL));
        comboPort.add("80");
        comboPort.add("443");
        comboPort.select(0);
        // 代理服务器类型
        UITool.createLabel(comp, login_proxy_type);
        gd = new GridData(GridData.FILL_HORIZONTAL);
        gd.horizontalSpan = 3;
        comboProxyType = UITool.createCCombo(comp, gd);
		comboProxyType.add(login_no_proxy);
		comboProxyType.add(login_http);
        comboProxyType.add(login_socks5);
        comboProxyType.addSelectionListener(new SelectionAdapter() {
        	@Override
        	public void widgetSelected(SelectionEvent e) {
        		selectProxy(comboProxyType.getSelectionIndex());
        	}
        });
        // 服务器地址
        UITool.createLabel(comp, login_proxy_server);
        textProxyServer = UITool.createSingleText(comp, new GridData(GridData.FILL_HORIZONTAL));
		// 服务器端口
        UITool.createLabel(comp, login_proxy_port);
        textProxyPort = UITool.createSingleText(comp, new GridData(GridData.FILL_HORIZONTAL));
		// 服务器用户名
        UITool.createLabel(comp, login_proxy_username);
        textUsername = UITool.createSingleText(comp, new GridData(GridData.FILL_HORIZONTAL));
		// 服务器密码
        UITool.createLabel(comp, login_proxy_password);
        textPassword = UITool.createSingleText(comp, new GridData(GridData.FILL_HORIZONTAL), SWT.SINGLE | SWT.PASSWORD);
        
		switchMethod(false);
    }    
    
    /**
     * 选择代理类型
     * 
     * @param i
     */
    private void selectProxy(int i) {
    	switch(i) {
    		case 0:
    			logins.getNetwork().setProxyType(ProxyType.NONE_LITERAL);
    			textProxyServer.setEnabled(false);
    			textProxyPort.setEnabled(false);
    			textUsername.setEnabled(false);
    			textPassword.setEnabled(false);
    			Color color = dialog.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
    			textProxyServer.setBackground(color);
    			textProxyPort.setBackground(color);
    			textUsername.setBackground(color);
    			textPassword.setBackground(color);
    			break;
    		case 1:
    			logins.getNetwork().setProxyType(ProxyType.HTTP_LITERAL);
    			textProxyServer.setEnabled(true);
    			textProxyPort.setEnabled(true);
    			textUsername.setEnabled(true);
    			textPassword.setEnabled(true);
    			textProxyServer.setBackground(Colors.LOGIN_BACKGROUND);
    			textProxyPort.setBackground(Colors.LOGIN_BACKGROUND);
    			textUsername.setBackground(Colors.LOGIN_BACKGROUND);
    			textPassword.setBackground(Colors.LOGIN_BACKGROUND);
    			break;
    		case 2:
    			logins.getNetwork().setProxyType(ProxyType.SOCKS5_LITERAL);
    			textProxyServer.setEnabled(true);
    			textProxyPort.setEnabled(true);
    			textUsername.setEnabled(true);
    			textPassword.setEnabled(true);
    			textProxyServer.setBackground(Colors.LOGIN_BACKGROUND);
    			textProxyPort.setBackground(Colors.LOGIN_BACKGROUND);
    			textUsername.setBackground(Colors.LOGIN_BACKGROUND);
    			textPassword.setBackground(Colors.LOGIN_BACKGROUND);
    			break;
    	}
	}

	/**
     * 切换登录方式
     * 
     * @param udp
     */
    protected void switchMethod(boolean udp) {
    	fillServers(udp);
    	comboServer.select(0);
    	comboPort.setEnabled(!udp);
	}

⌨️ 快捷键说明

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