/* * Jeti, a Java Jabber client, Copyright (C) 2003 E.S. de Boer * * 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 * * For questions, comments etc, * use the website at http://jeti.jabberstudio.org * or mail/im me at jeti@jabber.org */ package nu.fw.jeti.jabber; import java.awt.Container; import java.awt.Frame; import java.awt.Window; import java.util.*; import javax.swing.JFrame; import nu.fw.jeti.backend.*; import nu.fw.jeti.backend.roster.Roster; import nu.fw.jeti.backend.roster.Server; import nu.fw.jeti.events.*; import nu.fw.jeti.jabber.elements.IQXCaps; import nu.fw.jeti.jabber.elements.InfoQuery; import nu.fw.jeti.jabber.elements.Message; import nu.fw.jeti.jabber.elements.Packet; import nu.fw.jeti.jabber.elements.StreamError; import nu.fw.jeti.jabber.handlers.ExtensionHandler; import nu.fw.jeti.ui.Jeti; /** * @author E.S. de Boer */ public class Backend { private Map eventListeners; private Map presenceListeners; private Map messageListeners; private int identifier; private Connect connect; private Roster roster; private Server server; private Jeti main; private JFrame mainFrame; private Container mainWindow; private Start start; private IQTimerQueue iqTimerQueue; private Handlers handlers; private CapabilitiesCache capabilitiesCache; public Backend(Start start) { eventListeners = new HashMap(10); iqTimerQueue = new IQTimerQueue(); handlers = new Handlers(); connect = new Connect(this,iqTimerQueue,handlers); server =new Server(this); roster = new Roster(this,server); capabilitiesCache = new CapabilitiesCache(this); this.start = start; } public void setMain(Jeti main,Window window, JFrame frame) { this.main = main; this.mainWindow = window; this.mainFrame = frame; } public Container getMainWindow() {//TODO bit of a hack, think of something nicer if(mainWindow==null) { mainWindow=main.getTopLevelAncestor(); } return mainWindow; } public JFrame getMainFrame(){return mainFrame;} public Jeti getMain(){return main;} /* public void setBackend(JabberBackend backend) { this.backend = backend; } */ public void login(LoginInfo loginInfo) { connect.login(loginInfo); } public void autoLogin(LoginInfo loginInfo,int tries) { connect.autoLogin(loginInfo,tries); } public void abortLogin() { connect.abort(); } public JID getMyJID() { return Connect.getMyJID(); } /** * Checks if the password matches the password used to login on this account * @param password the password to check * @return true if the password matches the password of this account */ public boolean isPasswordValid(String password) { return connect.isPasswordValid(password); } public synchronized String getIdentifier() { return "JETI_" + identifier++; } public String createThread() { return Integer.toHexString("JETI".hashCode()) + Long.toHexString(System.currentTimeMillis()); } public String getAccountInfo() { return connect.getAccountInfo(); } public Map getAvailableTransports() { return server.getAvailableTransports(); } public void changeStatus(int show,String status) { connect.changeStatus(show, status); } public void rosterLoaded() { connect.connected(); } public void disconnect() { connect.disconnect(); } public boolean isLoggedIn() { return connect.isLoggedIn(); } public void streamError(StreamError error) { connect.streamError(error); } public void exit() { if(!Start.applet) { System.out.println("This window will close in one minute"); Timer t = new Timer(true); t.schedule(new TimerTask() { public void run() { System.exit(0); } },10000); } //end connection connect.exit(); Frame[] frames = Frame.getFrames(); for(int i =0;i