📄 exportprogressdialog.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.dialogs;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.widgets.Shell;
import edu.tsinghua.lumaqq.IconHolder;
import edu.tsinghua.lumaqq.LumaQQ;
import edu.tsinghua.lumaqq.models.ClusterModel;
import edu.tsinghua.lumaqq.models.FriendModel;
import edu.tsinghua.lumaqq.models.GroupModel;
import edu.tsinghua.lumaqq.ui.MainShell;
import edu.tsinghua.lumaqq.widgets.ClusterMessageExporter;
import edu.tsinghua.lumaqq.widgets.FriendMessageExporter;
/**
* 进度对话框
*
* @author 马若劼
*/
public class ExportProgressDialog extends Dialog {
/**
* 设置进度条的值
* @author luma
*/
private class SetRunnable implements Runnable {
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
public void run() {
try {
pb.setSelection(pb.getSelection() + 1);
if(pb.getSelection() == pb.getMaximum() - 1)
lblHint.setText(LumaQQ.getString("export.progress.label.finish"));
} catch (RuntimeException e) {
}
}
}
/**
* 导出线程
*
* @author luma
*/
private class ExportRunnable implements Runnable {
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
public void run() {
// 创建两个空的导出器
FriendMessageExporter fme = new FriendMessageExporter();
fme.setMyModel(main.getMyModel());
ClusterMessageExporter cme = new ClusterMessageExporter();
// 列举所有model,导出聊天记录
int tabCount = main.getModel().getTabCount();
for(int i = 0; i < tabCount; i++) {
GroupModel g = (GroupModel)main.getModel().getTab(i);
// 除了最近联系人,都导出
if(!g.getName().equals(LumaQQ.getString("group.default.latest"))) {
int itemCount = main.getModel().getItemCount(i);
boolean isCluster = g.isCluster();
// 判断model类型,导出
for(int j = 0; j < itemCount; j++) {
if(isCluster) {
ClusterModel c = (ClusterModel)main.getModel().getItem(i, j);
cme.setClusterModel(c);
main.getExportHelper().exportMessage(c.getClusterId(), cme, dir + LumaQQ.getString("cluster.record.file.name", new Object[] { String.valueOf(c.getClusterId()), c.getName() }));
} else {
FriendModel f = (FriendModel)main.getModel().getItem(i, j);
fme.setFriendModel(f);
main.getExportHelper().exportMessage(f.getQQ(), fme, dir + f.getQQ() + '-' + f.getName() + ".txt");
}
increaseSelection();
}
}
}
}
}
private IconHolder icons = IconHolder.getInstance();
private MainShell main;
private ProgressBar pb;
private Label lblHint;
private String dir;
private SetRunnable setRunnable;
/**
* @param parent
*/
public ExportProgressDialog(MainShell main, String dir) {
super(main.getShell());
this.main = main;
this.dir = dir;
this.setRunnable = new SetRunnable();
}
private void increaseSelection() {
main.getDisplay().syncExec(setRunnable);
}
/**
* 打开对话框
*/
public void open() {
// create dialog
Shell parent = getParent();
Display display = parent.getDisplay();
Shell dialog = new Shell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL | SWT.MIN);
// init child controls
initLayout(dialog);
// set title and image
dialog.setImage(icons.getImage(IconHolder.icoQQ));
dialog.setText(LumaQQ.getString("export.progress.title"));
// pack
dialog.pack();
// set dialog to center of screen
Rectangle dialogRect = dialog.getBounds();
Rectangle displayRect = display.getBounds();
dialog.setLocation((displayRect.width-dialogRect.width)/2, (displayRect.height-dialogRect.height)/2);
dialog.open();
// start export
new Thread(new ExportRunnable()).start();
while(!dialog.isDisposed())
if(!display.readAndDispatch())
display.sleep();
}
/**
* @param dialog
*/
private void initLayout(final Shell dialog) {
dialog.setLayout(new GridLayout());
lblHint = new Label(dialog, SWT.LEFT);
lblHint.setText(LumaQQ.getString("export.progress.label.exporting"));
lblHint.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
pb = new ProgressBar(dialog, SWT.HORIZONTAL | SWT.SMOOTH);
pb.setMinimum(0);
pb.setMaximum(main.getModel().getAllItemCount());
pb.setSelection(0);
GridData gd = new GridData(GridData.FILL_HORIZONTAL);
gd.widthHint = 300;
pb.setLayoutData(gd);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -