📄 mainshell.java
字号:
btnStatus.stopAnimate();
stopBlinkSystemMessageIcon();
uiHelper.stopBlinkImage();
uiHelper.stopAllOtherEffect();
// 重设图标状态和相关变量,把所有好友设为下线模式
uiHelper.setIconByStatus();
uiHelper.setAllFriendOffline();
mq.clear();
}
/**
* 检查登陆状态,如果正在登录或者已经登录,直接返回,如果尚未登录则执行登录操作
*
* @param forceRandom
* true表示强制随机选择服务器
* @return
* 如果当前正在登陆,则返回false,否则返回true
*/
public boolean checkLogin(boolean forceRandom, boolean forceTcp) {
// 如果正在登陆,不执行动作
if(client.isLogging()) return false;
// 万一用户还没有登陆,需要先登陆
if(!client.getUser().isLoggedIn()) {
// 如果设置了强制tcp方式,则不管设置什么都用tcp
boolean useTcp = forceTcp ? true : options.isUseTcp();
// 设置登陆的服务器和登陆方式
OptionUtil options = OptionUtil.getInstance();
if(options.isAutoSelect() || forceRandom) {
String[] servers = useTcp ? LumaQQ.tcpServers : LumaQQ.udpServers;
client.setLoginServer(servers[Util.random().nextInt(servers.length)]);
} else {
if(forceTcp && options.isUseTcp() != forceTcp)
client.setLoginServer(LumaQQ.tcpServers[0]);
else
client.setLoginServer(options.getServer());
}
// 如果是TCP方式登录,设置TCP服务器的端口和登录模式
if(useTcp) {
client.getUser().setUdp(false);
client.setTcpLoginPort(options.getTcpPort());
} else
client.getUser().setUdp(true);
// 设置代理服务器的类型,地址和验证用户名密码
try {
client.setProxy(new InetSocketAddress(options.getProxyServer(), options.getProxyPort()));
client.setProxyType(options.getProxyType());
client.setProxyUsername(options.getProxyUsername());
client.setProxyPassword(options.getProxyPassword());
} catch (IllegalArgumentException e) {
client.setProxyType("None");
}
// 设置是否显示虚拟摄像头
client.getUser().setShowFakeCam(options.isShowFakeCam());
// 开始登陆
btnStatus.startAnimate(loginFrames);
processor.clear();
client.addQQListener(processor);
client.addQQListener(faceReceiver);
try {
client.login();
} catch (Exception e) {
client.getUser().setStatus(QQ.QQ_FRIEND_STATUS_OFFLINE);
logout();
MessageDialog.openError(shell, LumaQQ.getString("message.box.common.fail.title"), e.getMessage());
}
return false;
}
return true;
}
/**
* @return Shell
*/
public Shell getShell() {
return shell;
}
/**
* 打开shell,开始事件循环
*/
public void open() {
soundDaemon.start();
// 初始化系统Tray Icon
initTray();
item.setToolTipText("LumaQQ " + String.valueOf(client.getUser().getQQ()));
// 如果设置了隐藏view bar
if(!options.isShowViewBar())
uiHelper.hideViewBar();
// 设置窗口位置和大小
Rectangle bound = new Rectangle(options.getLocationX(), options.getLocationY(), 0, 0);
bound.width = options.getWidth();
bound.height = options.getHeight();
if(bound.width == -1) bound.width = 150;
if(bound.height == -1) bound.height = 450;
shell.setBounds(bound);
// 保存窗口位置,本来这个位置是在controlMoved事件里面保存的,但是有可能有的系统
// 一开始没有这个事件,从而造成空指针,所以还是要在这里保存一下
loc = shell.getLocation();
// 打开shell,开始事件循环
shell.layout();
shell.open();
// 登陆
checkLogin(false, false);
// 开始事件循环
while(!shell.isDisposed()) {
if(!display.readAndDispatch())
display.sleep();
}
}
/**
* 添加程序图标到系统托盘中
*/
private void initTray() {
// 创建Tray Icon
Tray tray = display.getSystemTray();
item = new TrayItem(tray, SWT.NONE);
// 设置图标
item.setImage(icons.getImage(IconHolder.icoOffline));
// 添加listener
// 鼠标单击事件
item.addListener (SWT.Selection, new Listener () {
public void handleEvent (Event event) {
if(mq.hasNext()) {
int source = mq.nextMessageSource();
if(source == QQ.QQ_IM_FROM_SYS)
shellLauncher.openReceiveSystemMessageShell(mq.getSystemMessage());
else if(source == QQ.QQ_IM_FROM_SMS)
shellLauncher.openReceiveSMSShell();
else {
int sender = mq.nextSender();
shellLauncher.openIMShell(sender);
}
} else {
menuHelper.setStatusMenuVisible(false);
// 如果当前处于自动隐藏状态,则不继续处理,在windows下面已经没有问题,linux还是不行,注释掉
//if(ahm.needHide()) {
// ahm.autoShow();
//} else {
if(!shell.getMinimized()) {
tipHelper.closeFriendTipShell();
shell.setMinimized(true);
} else {
shell.setVisible(true);
shell.setMinimized(false);
}
//}
}
}
});
// 鼠标右键点击事件
item.addListener (SWT.MenuDetect, new Listener () {
public void handleEvent (Event event) {
menuHelper.setSystemMenuVisible(true);
}
});
}
/**
* 初始化界面布局
*/
private void initLayout() {
// 设置layout
GridLayout layout = new GridLayout();
layout.marginHeight = layout.marginWidth = layout.verticalSpacing = layout.horizontalSpacing = 0;
shell.setLayout(layout);
/* 主界面上部 */
// 容器
Composite comp = new Composite(shell, SWT.NONE);
comp.setLayoutData(new GridData(GridData.FILL_BOTH));
layout = new GridLayout(2, false);
layout.marginHeight = layout.marginWidth = layout.verticalSpacing = layout.horizontalSpacing = 0;
comp.setLayout(layout);
// 切换各个view的bar容器
viewBar = new Composite(comp, SWT.NONE);
GridData gd = new GridData(GridData.FILL_VERTICAL);
viewBar.setLayoutData(gd);
layout = new GridLayout();
layout.marginHeight = layout.marginWidth = 3;
layout.horizontalSpacing = 0;
layout.verticalSpacing = 10;
viewBar.setLayout(layout);
viewBar.addMouseListener(new MouseAdapter() {
public void mouseUp(MouseEvent e) {
if(e.button == 3) {
menuHelper.setViewBarMenuLocation(viewBar.toDisplay(e.x, e.y));
menuHelper.setViewBarMenuVisible(true);
}
}
});
// 好友视图
CoolButton btnFriendView = new CoolButton(viewBar, MySWT.FLAT | MySWT.TOGGLE | MySWT.HOVER | SWT.CENTER);
btnFriendView.setImage(icons.getImage(IconHolder.icoFriendView));
btnFriendView.setDrawEmptyString(false);
btnFriendView.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
btnFriendView.addMouseListener(new MouseAdapter() {
public void mouseDown(MouseEvent e) {
setCurrentView(FRIEND_VIEW);
}
});
viewButtons[FRIEND_VIEW] = btnFriendView;
// 手机好友视图
CoolButton btnMobildView = new CoolButton(viewBar, MySWT.FLAT | MySWT.TOGGLE | MySWT.HOVER | SWT.CENTER);
btnMobildView.setImage(icons.getImage(IconHolder.icoMobile));
btnMobildView.setDrawEmptyString(false);
btnMobildView.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
btnMobildView.addMouseListener(new MouseAdapter() {
public void mouseDown(MouseEvent e) {
setCurrentView(MOBILE_VIEW);
}
});
viewButtons[MOBILE_VIEW] = btnMobildView;
// view容器
Composite viewComp = new Composite(comp, SWT.NONE);
viewComp.setLayoutData(new GridData(GridData.FILL_BOTH));
viewComp.setLayout(new FormLayout());
viewComp.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
Composite c = (Composite)e.getSource();
e.gc.setForeground(shutterBorderColor);
Rectangle rect = c.getClientArea();
rect.width -= 3;
rect.height -= 3;
e.gc.drawRectangle(rect);
}
});
// 好友视图
shutter = new Shutter(viewComp, SWT.NONE);
FormData fd = new FormData();
fd.top = fd.left = new FormAttachment(0, 1);
fd.bottom = fd.right = new FormAttachment(100, -3);
shutter.setLayoutData(fd);
shutter.setItemSorter(new ModelSorter());
shutter.addPropertyListener(new FriendPropertyListener(this));
shutter.addPropertyListener(new GroupPropertyListener(this));
shutter.sortItems(true);
shutter.setItemMouseTrackColor(display.getSystemColor(SWT.COLOR_BLUE));
shutter.addItemDragSourceListener(new FriendDragSourceListener());
shutter.addTabDropTargetListener(new GroupDropTargetListener(this));
shutter.addModelListener(new LumaQQModelListener(this));
views[FRIEND_VIEW] = shutter;
// 手机好友视图
Shutter mobileShutter = new Shutter(viewComp, SWT.NONE);
mobileShutter.setItemSorter(new MobileModelSorter());
mobileShutter.sortItems(true);
fd = new FormData();
fd.top = fd.left = new FormAttachment(0, 1);
fd.bottom = fd.right = new FormAttachment(100, -3);
mobileShutter.setLayoutData(fd);
views[MOBILE_VIEW] = mobileShutter;
/* 按钮区 */
// separator
Label lblSeparator = new Label(shell, SWT.HORIZONTAL | SWT.SEPARATOR);
lblSeparator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
// 按钮容器
comp = new Composite(shell, SWT.NONE);
comp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
layout = new GridLayout(11, false);
layout.marginHeight = layout.marginWidth = layout.verticalSpacing = layout.horizontalSpacing = 0;
comp.setLayout(layout);
// 添加查找按钮
CoolButton btnFind = new CoolButton(comp, MySWT.FLAT | MySWT.HOVER | SWT.CENTER, null, icons.getImage(IconHolder.icoSearch));
btnFind.setToolTipText(LumaQQ.getString("tooltip.button.search"));
btnFind.setDrawEmptyString(false);
btnFind.setLayoutData(new GridData());
btnFind.addMouseListener(
new MouseAdapter() {
public void mouseUp(MouseEvent e) {
if(client.getUser().isLoggedIn())
shellLauncher.openSearchWizard();
}
}
);
// separator
lblSeparator = new Label(comp, SWT.VERTICAL | SWT.SEPARATOR);
lblSeparator.setLayoutData(new GridData(-1, 20));
// 系统消息按钮
btnSysMsg = new CoolButton(comp, MySWT.FLAT | MySWT.HOVER | SWT.CENTER, null, icons.getImage(IconHolder.icoSysMsg));
btnSysMsg.setToolTipText(LumaQQ.getString("tooltip.button.sysmsg"));
btnSysMsg.setDrawEmptyString(false);
btnSysMsg.setLayoutData(new GridData());
btnSysMsg.addMouseListener(
new MouseAdapter() {
public void mouseUp(MouseEvent e) {
if(mq.hasSystemMessage())
shellLauncher.openReceiveSystemMessageShell(mq.getSystemMessage());
else
shellLauncher.openSystemMessageListShell();
}
}
);
// separator
lblSeparator = new Label(comp, SWT.VERTICAL | SWT.SEPARATOR);
lblSeparator.setLayoutData(new GridData(-1, 20));
// 发送接收短消息按钮
btnSMS = new CoolButton(comp, MySWT.FLAT | MySWT.HOVER | SWT.CENTER, null, icons.getImage(IconHolder.icoMobile));
btnSMS.setToolTipText(LumaQQ.getString("tooltip.button.sms"));
btnSMS.setDrawEmptyString(false);
btnSMS.setLayoutData(new GridData());
btnSMS.addMouseListener(
new MouseAdapter() {
public void mouseUp(MouseEvent e) {
if(mq.hasSMS())
shellLauncher.openReceiveSMSShell();
else
shellLauncher.openSMSShell();
}
}
);
// separator
lblSeparator = new Label(comp, SWT.VERTICAL | SWT.SEPARATOR);
lblSeparator.setLayoutData(new GridData(-1, 20));
// LumaQQ主页按钮
CoolButton btnHomepage = new CoolButton(comp, MySWT.FLAT | MySWT.HOVER | SWT.CENTER, null, icons.getImage(IconHolder.icoFirefox));
btnHomepage.setToolTipText(LumaQQ.getString("tooltip.button.homepage"));
btnHomepage.setDrawEmptyString(false);
btnHomepage.setLayoutData(new GridData());
btnHomepage.addMouseListener(
new MouseAdapter() {
public void mouseUp(MouseEvent e) {
shellLauncher.goLumaQQ();
}
}
);
// separator
lblSeparator = new Label(comp, SWT.VERTICAL | SWT.SEPARATOR);
lblSeparator.setLayoutData(new GridData(-1, 20));
// 聊天室按钮
CoolButton btnChatroom = new CoolButton(comp, MySWT.FLAT | MySWT.HOVER | SWT.CENTER, null, icons.getImage(IconHolder.icoChatroom));
btnChatroom.setToolTipText(LumaQQ.getString("tooltip.button.chatroom"));
btnChatroom.setDrawEmptyString(false);
btnChatroom.setLayoutData(new GridData());
btnChatroom.addMouseListener(
new MouseAdapter() {
public void mouseUp(MouseEvent e) {
shellLauncher.goChatroom();
}
}
);
// separator
lblSeparator = new Label(comp, SWT.VERTICAL | SWT.SEPARATOR);
lblSeparator.setLayoutData(new GridData(-1, 20));
// QQ游戏按钮
CoolButton btnQQGame = new CoolButton(comp, MySWT.FLAT | MySWT.HOVER | SWT.CENTER, null, icons.getImage(IconHolder.icoQQGame));
btnQQGame.setToolTipText(LumaQQ.getString("tooltip.button.qqgame"));
btnQQGame.setDrawEmptyString(false);
btnQQGame.setLayoutData(new GridData());
btnQQGame.addMouseListener(
new MouseAdapter() {
public void mouseUp(MouseEvent e) {
shellLauncher.goQQGame();
}
}
);
// separator
lblSeparator = new Label(shell, SWT.HORIZONTAL | SWT.SEPARATOR);
lblSeparator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
// 按钮容器
comp = new Composite(shell, SWT.NONE);
comp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
layout = new GridLayout(3, false);
layout.marginHeight = layout.marginWidth = layout.verticalSpacing = layout.horizontalSpacing = 0;
comp.setLayout(layout);
// 添加系统菜单按钮
btnSysMenu = new CoolButton(comp, MySWT.FLAT | MySWT.NO_ZOOM | MySWT.HOVER | SWT.RIGHT, null, icons.getImage(IconHolder.icoBackground));
btnSysMenu.setToolTipText(LumaQQ.getString("tooltip.button.sysmenu"));
btnSysMenu.setDrawEmptyString(false);
btnSysMenu.setLayoutData(new GridData());
btnSysMenu.addMouseListener(
new MouseAdapter() {
public void mouseUp(MouseEvent e) {
menuHelper.setSystemMenuVisible(true);
}
}
);
// separator
lblSeparator = new Label(comp, SWT.VERTICAL | SWT.SEPARATOR);
lblSeparator.setLayoutData(new GridData(-1, 20));
// 添加改变状态按钮
btnStatus = new CoolButton(comp, MySWT.FLAT | MySWT.HOVER | SWT.CENTER, LumaQQ.getString("button.status.offline"), icons.getImage(IconHolder.icoOffline));
btnStatus.setToolTipText(LumaQQ.getString("tooltip.button.status"));
btnSMS.setDrawEmptyString(false);
btnStatus.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
btnStatus.addMouseListener(
new MouseAdapter() {
public void mouseUp(MouseEvent e) {
menuHelper.setStatusMenuLocation(btnStatus.toDisplay(0, 20));
menuHelper.setStatusMenuVisible(true);
}
}
);
// 设置当前为好友视图
setCurrentView(FRIEND_VIEW);
}
/**
* 设置当前view
*
* @param viewId
* view的序号,也是view按钮在数组中的序号
*/
private void setCurrentView(int viewId) {
for(int i = 0; i < VIEW_COUNT; i++) {
viewButtons[i].setSelection(false);
views[i].setVisible(false);
}
viewButtons[viewId].setSelection(true);
views[viewId].setVisible(true);
currentView = viewId;
}
/**
* 设置手机好友model
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -