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

📄 historystorage.java.svn-base

📁 类似QQ的功能
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************* Jimm - Mobile Messaging - J2ME ICQ clone Copyright (C) 2003-05  Jimm Project 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. ******************************************************************************** File: src/jimm/HistoryStorage.java Version: ###VERSION###  Date: ###DATE### Author(s): Artyomov Denis, Igor Palkin *******************************************************************************///#sijapp cond.if modules_HISTORY is "true" #package jimm;import java.util.*;import javax.microedition.lcdui.Alert;import javax.microedition.lcdui.Font;import javax.microedition.rms.RecordStore;import jimm.util.ResourceBundle;import java.io.*;import javax.microedition.lcdui.*;//#sijapp cond.if target="RIM" | target="MOTOROLA" | target="MIDP2"#import javax.microedition.io.Connector;//#sijapp cond.elseif target="SIEMENS2"#//# import javax.microedition.io.Connector;//# import com.siemens.mp.io.file.*;//#sijapp cond.end#import DrawControls.ListItem;import DrawControls.VirtualList;import DrawControls.TextList;import DrawControls.VirtualListCommands;import jimm.comm.Util;import jimm.ContactItem;// Class to cache one line in messages list// All fields are public to easy and fast accessclass CachedRecord{	String shortText, text, date, from;	Integer index;	byte type; // 0 - incoming message, 1 - outgoing message//#sijapp cond.if target != "DEFAULT"#	boolean contains_url;//#sijapp cond.end#}// Visual messages history listclass HistoryStorageList extends VirtualList implements CommandListener,		VirtualListCommands//#sijapp cond.if target != "DEFAULT"#		, Runnable//#sijapp cond.end#{	// commands for message text	private static Command cmdMsgBack = new Command(ResourceBundle			.getString("back"), Jimm.cmdBack, 1);	private static Command cmdMsgNext = new Command(ResourceBundle			.getString("next"), Command.ITEM, 2);	private static Command cmdMsgPrev = new Command(ResourceBundle			.getString("prev"), Command.ITEM, 3);	private static Command cmdMsgCopyText = new Command(ResourceBundle			.getString("copy_text"), Command.ITEM, 4);	// commands for messages list	private static Command cmdSelect = new Command(ResourceBundle			.getString("select"), Command.OK, 1);	private static Command cmdBack = new Command(ResourceBundle			.getString("back"), Jimm.cmdBack, 2);	private static Command cmdClear = new Command(ResourceBundle.getString(			"clear", ResourceBundle.FLAG_ELLIPSIS), Command.ITEM, 4);	private static Command cmdFind = new Command(ResourceBundle.getString(			"find", ResourceBundle.FLAG_ELLIPSIS), Command.ITEM, 3);	private static Command cmdInfo = new Command(ResourceBundle			.getString("history_info"), Command.ITEM, 6);	private static Command cmdCopytext = new Command(ResourceBundle			.getString("copy_text"), Command.ITEM, 5);	private static Command cmdExport = new Command(ResourceBundle			.getString("export"), Command.ITEM, 7);	private static Command cmdExportAll = new Command(ResourceBundle			.getString("exportall"), Command.ITEM, 8);//#sijapp cond.if target != "DEFAULT"#	private static Command cmdGotoURL = new Command(ResourceBundle.getString("goto_url"), Command.ITEM, 9);//#sijapp cond.end#		//commands for url list	private static Command cmdurlSelect = new Command(ResourceBundle			.getString("select"), Command.OK, 1);	private static Command cmdurlBack = new Command(ResourceBundle			.getString("back"), Jimm.cmdBack, 2);	static TextList messText;	private final static int SELECTOR_DEL_HISTORY = 2;	// list UIN	private static String currUin = new String(), currName = new String();	// Controls for finding text	private static Form frmFind;	private static Command cmdFindOk;	private static Command cmdFindCancel;	private static TextField tfldFind;	private static ChoiceGroup chsFind;	// Constructor	public HistoryStorageList()	{		super(null);				addCommandEx(cmdBack, VirtualList.MENU_TYPE_LEFT_BAR);//#sijapp cond.if target!="RIM" & target!="DEFAULT"#		addCommandEx(JimmUI.cmdMenu, VirtualList.MENU_TYPE_RIGHT_BAR);//#sijapp cond.end#		addCommandEx(cmdSelect, VirtualList.MENU_TYPE_RIGHT);		addCommandEx(cmdClear, VirtualList.MENU_TYPE_RIGHT);		addCommandEx(cmdFind, VirtualList.MENU_TYPE_RIGHT);		addCommandEx(cmdInfo, VirtualList.MENU_TYPE_RIGHT);		addCommandEx(cmdCopytext, VirtualList.MENU_TYPE_RIGHT);		addCommandEx(cmdExport, VirtualList.MENU_TYPE_RIGHT);		addCommandEx(cmdExportAll, VirtualList.MENU_TYPE_RIGHT);		//addCommand(cmdGotoURL);		setCommandListener(this);		setVLCommands(this);		JimmUI.setColorScheme(this, false, -1, true);	}	// VirtualList command impl.	public void vlCursorMoved(VirtualList sender)	{		// user select some history storage line		if (sender == this)		{			CachedRecord record = HistoryStorage.getCachedRecord(currUin,					getCurrIndex());			if (record == null)				return;//#sijapp cond.if target != "DEFAULT"#			removeCommandEx(cmdGotoURL);			if (record.contains_url)				addCommandEx(cmdGotoURL, VirtualList.MENU_TYPE_RIGHT);//#sijapp cond.end#			setCaption(record.from + " " + record.date);		}	}	// VirtualList command impl.	public void vlKeyPress(VirtualList sender, int keyCode, int type)	{		if ((sender == messText) && (type == VirtualList.KEY_PRESSED))		{			switch (getGameAction(keyCode))			{			case Canvas.LEFT:				moveInList(-1);				break;			case Canvas.RIGHT:				moveInList(1);				break;			}		}	}	// Moves on next/previous message in list and shows message text	private void moveInList(int offset)	{		moveCursor(offset, false);		showMessText();	}	// VirtualList command impl.	public void vlItemClicked(VirtualList sender)	{		if (sender == this)		{			showMessText();		}	}//#sijapp cond.if target != "DEFAULT"#	private Object fileSystem; 	private boolean cp1251;	private String exportUin;	private String directory;	private TextList messTextList;	public void export(String uin)	{		exportUin = uin;		try		{			FileSystem2 fb = new FileSystem2();			fb.browse(null, this, true);			fileSystem = fb; 		} catch (Exception e)		{		}	}		private static final int MODE_EXPORT_HISTORY = 1;	private static final int MODE_SHOW_EH_MESSAGE = 2;	private int currentMode;	private String currMessage;	public void run()	{		switch (currentMode)		{		case MODE_EXPORT_HISTORY:			System.out.println("Start history export!");			if (exportUin == null) startExport(null);			else startExport(new ContactItem[]{ ContactList.getItembyUIN(exportUin) });			break;					case MODE_SHOW_EH_MESSAGE:			messTextList = new TextList(currName);			JimmUI.setColorScheme(messTextList, false, -1, true);			messTextList.setFontSize(Font.SIZE_LARGE);			messTextList.setMode(VirtualList.CURSOR_MODE_DISABLED);			messTextList.addBigText(currMessage, messTextList.getTextColor(), Font.STYLE_PLAIN, -1);			messTextList.setCommandListener(this);			messTextList.addCommandEx(JimmUI.cmdOk, VirtualList.MENU_TYPE_RIGHT_BAR);			messTextList.activate(Jimm.display);			break;		}	}	private void exportUinToStream(ContactItem item, OutputStream os)			throws IOException	{		String endl = "\r\n";		CachedRecord record;		String uin = item				.getStringValue(ContactItem.CONTACTITEM_UIN);		int max = HistoryStorage.getRecordCount(uin);		if (max > 0)		{			String nick = (item.getStringValue(					ContactItem.CONTACTITEM_NAME).length() > 0) ? item					.getStringValue(ContactItem.CONTACTITEM_NAME)					: uin;			SplashCanvas.setMessage(nick);			SplashCanvas.setProgress(0);			StringBuffer str_buf = new StringBuffer().append(endl).append(					'\t').append(					ResourceBundle.getString("message_history_with")).append(					nick).append(" (").append(uin).append(')').append(endl).append('\t')					.append(ResourceBundle.getString("export_date")).append(							Util.getDateString(false)).append(endl).append(endl);			os.write(Util.stringToByteArray(str_buf.toString(), !cp1251));			char cc;			String curr_msg_text;			StringBuffer msg_str_buf;			for (int i = 0; i < max; i++)			{				record = HistoryStorage.getRecord(uin, i);				os.write(Util.stringToByteArray(" "						+ ((record.type == 0) ? nick : ResourceBundle								.getString("me")) + " (" + record.date						+ "):\r\n", !cp1251));				curr_msg_text = record.text.trim();				msg_str_buf = new StringBuffer(curr_msg_text.length());				for (int k = 0; k < curr_msg_text.length(); k++)				{					cc = curr_msg_text.charAt(k);					if (cc == '\r') continue;					else if (cc == '\n') msg_str_buf.append(endl);					else msg_str_buf.append(cc);				}				msg_str_buf.append(endl);				os.write(Util.stringToByteArray(msg_str_buf.toString(), !cp1251));				os.flush();				SplashCanvas.setProgress((100 * i) / max);			}			curr_msg_text = null;			msg_str_buf = null;		}	}	private void exportUinToFile(ContactItem item, String filename) throws IOException	{		if (HistoryStorage.getRecordCount(item.getStringValue(ContactItem.CONTACTITEM_UIN)) > 0)		{			FileSystem2 fs = null;			OutputStream os = null;			try			{				fs = (FileSystem2)fileSystem;				fs.openFile(filename, Connector.READ_WRITE);				os = fs.openOutputStream();				if (!cp1251) os.write(new byte[]{ (byte) 0xef, (byte) 0xbb, (byte) 0xbf });				exportUinToStream(item, os);			}			finally			{				if (os != null) try { os.close(); } catch (Exception e) {}				if (fs != null) try { fs.close(); } catch (Exception e) {}			}		}	}	public void startExport(ContactItem[] citems)	{		cp1251 = Options.getBoolean(Options.OPTION_CP1251_HACK);		SplashCanvas.setMessage(ResourceBundle.getString("exporting",				ResourceBundle.FLAG_ELLIPSIS));		SplashCanvas.setProgress(0);		Jimm.display.setCurrent(Jimm.jimm.getSplashCanvasRef());		Jimm.setBkltOn(true);				if (citems == null)			citems = ContactList.getContactItems();				try		{			for (int i = 0; i < citems.length; i++)				exportUinToFile(						citems[i],						directory								+ "jimm_hist_"								+ citems[i]										.getStringValue(ContactItem.CONTACTITEM_UIN)								+ ".txt");									((FileSystem2)fileSystem).close();			currMessage = ResourceBundle.getString("export_complete");		}		catch (Exception e)		{			currMessage = e.toString()+e.getMessage();		}		fileSystem = null;				System.out.println("currMessage="+currMessage);				// Show success (or error message) in main thread		currentMode = MODE_SHOW_EH_MESSAGE;		Jimm.display.callSerially(this);	}	private static TextList URLList;	private void gotoURL()	{		CachedRecord rec = HistoryStorage.getCachedRecord(currUin,				getCurrIndex());		Vector urls = Util.parseMessageForURL(rec.text + "\n");		if (urls == null)			return;		if (urls.size() == 1)			try			{				Jimm.jimm.platformRequest((String) urls.elementAt(0));			} catch (Exception e)			{			}		else		{			URLList = JimmUI.getInfoTextList(ResourceBundle.getString("goto_url"), false);			URLList.addCommandEx(cmdurlSelect, VirtualList.MENU_TYPE_RIGHT_BAR);			URLList.addCommandEx(cmdurlBack, VirtualList.MENU_TYPE_LEFT_BAR);			URLList.setCommandListener(this);			for (int i = 0; i < urls.size(); i++)			{				URLList.addBigText((String) urls.elementAt(i), getTextColor(),						Font.STYLE_PLAIN, i).doCRLF(i);			}			JimmUI.showInfoTextList(URLList);		}	}//#sijapp cond.end#	public void commandAction(Command c, Displayable d)	{		Jimm.aaUserActivity();		//#sijapp cond.if target != "DEFAULT"#				if (JimmUI.isControlActive(messTextList))		{			messTextList = null;			HistoryStorage.showHistoryList(currUin, currName);			return;		}				if (fileSystem != null)		{			if (c == JimmUI.cmdOk)			{				FileSystem2 fs = (FileSystem2)fileSystem;				directory = fs.getValue();				currentMode = MODE_EXPORT_HISTORY;				(new Thread(this)).start();			}			else			{				HistoryStorage.showHistoryList(currUin, currName);				fileSystem = null;			}			return;		}				if (c == cmdurlBack)		{			URLList = null;			HistoryStorage.showHistoryList(currUin, currName);		}		else if (c == cmdurlSelect)		{			try			{				Jimm.jimm.platformRequest(URLList.getCurrText(0, false));			} catch (Exception e)			{			}		}		else if (c == cmdGotoURL)			gotoURL();				// Export history to txt file		if (c == cmdExport)			export(currUin);		if (c == cmdExportAll)			export(null);//#sijapp cond.end#		// back to contact list		if (c == cmdBack)		{			HistoryStorage.clearCache();			messText = null;			JimmUI.backToLastScreen();		}		// select message		else if (c == cmdSelect)		{			showMessText();		}		// Clear messages		else if (c == cmdClear)		{			JimmUI.showSelector("clear_history", JimmUI.stdSelector, this,					SELECTOR_DEL_HISTORY, true);		}		// "Clear history"		else if (JimmUI.getCurScreenTag() == SELECTOR_DEL_HISTORY)		{			if (c == JimmUI.cmdOk)			{				switch (JimmUI.getLastSelIndex())				{				case 0: // Current					HistoryStorage.clearHistory(currUin);					break;				case 1: // All except current					HistoryStorage.clear_all(currUin);					break;				case 2: // All					HistoryStorage.clear_all(null);					break;				}			}			activate(Jimm.display);			invalidate();		}		// Copy text from messages list		else if ((c == cmdCopytext) || (c == cmdMsgCopyText))		{			int index = getCurrIndex();			if (index == -1)				return;			CachedRecord record = HistoryStorage					.getCachedRecord(currUin, index);			if (record == null)				return;			JimmUI.setClipBoardText((record.type == 0), record.date,					record.from, record.text);		}		// back to messages list		else if (c == cmdMsgBack)		{			activate(Jimm.display);		}		// next message command		else if (c == cmdMsgNext)		{			moveInList(1);		}

⌨️ 快捷键说明

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