?? lumaqq.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.text.MessageFormat;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import org.eclipse.jface.dialogs.MessageDialog;
import edu.tsinghua.lumaqq.qq.QQ;
import edu.tsinghua.lumaqq.qq.QQClient;
import edu.tsinghua.lumaqq.qq.beans.QQUser;
import edu.tsinghua.lumaqq.ui.MainShell;
import edu.tsinghua.lumaqq.ui.dialogs.LoginDialog;
import edu.tsinghua.lumaqq.xml.servers.Servers;
import edu.tsinghua.lumaqq.xml.servers.ServersUnmarshaller;
/**
* LumaQQ的GUI主程序,主要負責構造界面
*
* @author 馬若劼
*/
public class LumaQQ {
/** 國際化資源 */
public static ResourceBundle resourceBundle;
/** 安裝目錄 */
public static String INSTALL_DIR;
/** 自定義表情目錄 */
public static String CUSTOM_FACE_DIR;
/** 接收到的自定義表情目錄 */
public static String CUSTOM_FACE_RECV_DIR;
// 一些系統需要使用的文件路徑
/** 服務器列表文件 */
public static String SERVERS;
/** 聊天機器人配置文件 */
public static String ROBOTS;
/** IP數據庫文件 */
public static String IP_FILE;
// 用戶文件路徑
/** 用戶登錄歷史信息文件 */
public static String LOGIN_HISTORY;
/** 用戶組信息文件 */
public static String GROUPS;
/** 自動回復和快捷回復設置文件 */
public static String REPLIES;
/** 代理服務器列表文件 */
public static String PROXIES;
/** 系統參數設置文件 */
public static String SYSTEM_OPTIONS;
/** 好友備注信息文件 */
public static String REMARKS;
/** 手機好友信息文件 */
public static String MOBILES;
/** 自定義表情配置文件 */
public static String CUSTOM_FACES;
// 聲音文件路徑
/** 普通消息聲音文件 */
public static String MSG_SOUND;
/** 系統消息聲音 */
public static String SYS_MSG_SOUND;
// 登陸服務器數組,需要從xml文件中讀取
/** UDP服務器的列表 */
public static String[] udpServers;
/** TCP服務器列表 */
public static String[] tcpServers;
/** 缺省組背景顏色 */
public static final String DEFAULT_GROUP_COLOR = "255,255,255";
/**
* LumaQQ啟動主程序
* @param args
*/
public static void main(String[] args) {
// 初始化系統文件路徑
initSysFilePath(args);
// 初始化資源文件
resourceBundle = ResourceBundle.getBundle("locale.LumaQQ", Locale.CHINESE, ClassLoader.getSystemClassLoader());
MainShell main = new MainShell();
// 讀取服務器列表文件,如果不成功則退出,服務器數量為0也退出
if(!readServerFile()) {
MessageDialog.openError(main.getShell(), LumaQQ.getString("message.box.common.fail.title"), LumaQQ.getString("message.box.server.file.error"));
main.close();
System.exit(1);
}
// 服務器列表讀取成功,開始登陸
LoginDialog login = new LoginDialog(main.getShell());
if(login.open()) {
// 創建QQ用戶對象
QQUser me = new QQUser(login.getQQ(), login.getMd5Password());
me.setUdp(false);
if(login.isLoginHidden()) {
me.setLoginMode(QQ.QQ_LOGIN_MODE_HIDDEN);
me.setStatus(QQ.QQ_FRIEND_STATUS_HIDDEN);
} else {
me.setLoginMode(QQ.QQ_LOGIN_MODE_NORMAL);
me.setStatus(QQ.QQ_FRIEND_STATUS_ONLINE);
}
// 創建QQ客戶端對象
QQClient client = new QQClient();
client.setRobotConfig(ROBOTS);
client.setUser(me);
// 初始化用戶文件路徑
initUserFilePath(me);
// 傳遞給主界面
main.setClient(client);
// 打開主界面
main.open();
} else
main.close();
}
/**
* 初始化用戶文件路徑,對于每個用戶來說,這些值是變化的。在改變用戶的時候將被調用
*
* @param me
* QQ用戶對象
*/
public static void initUserFilePath(QQUser me) {
GROUPS = INSTALL_DIR + "/" + me.getQQ() + "/groups.xml";
REPLIES = INSTALL_DIR + "/" + me.getQQ() + "/replies.xml";
PROXIES = INSTALL_DIR + "/" + me.getQQ() + "/proxies.xml";
SYSTEM_OPTIONS = INSTALL_DIR + "/" + me.getQQ() + "/sysopts.xml";
REMARKS = INSTALL_DIR + "/" + me.getQQ() + "/remarks.xml";
MOBILES = INSTALL_DIR + "/" + me.getQQ() + "/mobiles.xml";
CUSTOM_FACE_DIR = INSTALL_DIR + "/" + me.getQQ() + "/custom_face/";
CUSTOM_FACE_RECV_DIR = INSTALL_DIR + "/" + me.getQQ() + "/custom_face_recv/";
CUSTOM_FACES = INSTALL_DIR + "/" + me.getQQ() + "/faces.xml";
}
/**
* 初始化系統文件的路徑,對于每個用戶來說,這些值是不變的,所以這個方法只調用一次
* @param args
*/
private static void initSysFilePath(String[] args) {
if(args.length == 0)
INSTALL_DIR = ".";
else
INSTALL_DIR = args[0];
LOGIN_HISTORY = INSTALL_DIR + "/logins.xml";
SERVERS = INSTALL_DIR + "/xml/servers.xml";
ROBOTS = INSTALL_DIR + "/xml/robots.xml";
IP_FILE = INSTALL_DIR + "/QQWry.dat";
MSG_SOUND = INSTALL_DIR + "/sound/msg.au";
SYS_MSG_SOUND = INSTALL_DIR + "/sound/system.wav";
}
/**
* 讀取服務器列表文件
* @return true表示服務器列表文件沒有問題,false表示有問題,程序不會繼續執行下去
*/
private static boolean readServerFile() {
File file = new File(LumaQQ.SERVERS);
if(file.exists()) {
Servers servers = null;
try {
servers = ServersUnmarshaller.unmarshal(file);
} catch (IOException e) {
return false;
}
// 得到UDP服務器列表
int i = 0;
List list = servers.getUDPServerList();
if(list != null && list.size() > 0) {
udpServers = new String[list.size()];
Iterator iter = list.iterator();
while(iter.hasNext()) {
udpServers[i++] = ((String)iter.next()).trim();
}
} else
udpServers = new String[0];
// 得到TCP服務器列表
i = 0;
list = servers.getTCPServerList();
if(list != null && list.size() > 0) {
tcpServers = new String[list.size()];
Iterator iter = list.iterator();
while(iter.hasNext()) {
tcpServers[i++] = ((String)iter.next()).trim();
}
} else
tcpServers = new String[0];
// 判斷服務器數量是否大于1
if(tcpServers.length + udpServers.length < 1)
return false;
else
return true;
} else
return false;
}
/**
* 從資源文件中返回字符串 我們不希望程序崩潰,所以如果沒有找到Key,就直接返回Key
*/
public static String getString(String key) {
try {
return resourceBundle.getString(key);
} catch (MissingResourceException e) {
return key;
} catch (NullPointerException e) {
return "!" + key + "!";
}
}
/**
* 從資源文件中返回字符串 我們不希望程序崩潰,所以如果沒有找到Key,就直接返回Key
*/
public static String getString(String key, Object[] args) {
try {
return MessageFormat.format(getString(key), args);
} catch (MissingResourceException e) {
return key;
} catch (NullPointerException e) {
return "!" + key + "!";
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -