/** * Saves the last status for all accounts. This information is used on loging. Each time user logs * in he's logged with the same status as he was the last time before closing the application. * * @param protocolProvider the protocol provider to save status information for * @param statusName the name of the status to save */ private void saveStatusInformation(ProtocolProviderService protocolProvider, String statusName) { ConfigurationService configService = GuiActivator.getConfigurationService(); String prefix = "net.java.sip.communicator.impl.gui.accounts"; List<String> accounts = configService.getPropertyNamesByPrefix(prefix, true); boolean savedAccount = false; for (String accountRootPropName : accounts) { String accountUID = configService.getString(accountRootPropName); if (accountUID.equals(protocolProvider.getAccountID().getAccountUniqueID())) { configService.setProperty(accountRootPropName + ".lastAccountStatus", statusName); savedAccount = true; } } if (!savedAccount) { String accNodeName = "acc" + Long.toString(System.currentTimeMillis()); String accountPackage = "net.java.sip.communicator.impl.gui.accounts." + accNodeName; configService.setProperty( accountPackage, protocolProvider.getAccountID().getAccountUniqueID()); configService.setProperty(accountPackage + ".lastAccountStatus", statusName); } }
/** * Returns the last contact status saved in the configuration. * * @param protocolProvider the protocol provider to which the status corresponds * @return the last contact status saved in the configuration. */ public String getLastStatusString(ProtocolProviderService protocolProvider) { // find the last contact status saved in the configuration. String lastStatus = null; ConfigurationService configService = GuiActivator.getConfigurationService(); String prefix = "net.java.sip.communicator.impl.gui.accounts"; List<String> accounts = configService.getPropertyNamesByPrefix(prefix, true); String protocolProviderAccountUID = protocolProvider.getAccountID().getAccountUniqueID(); for (String accountRootPropName : accounts) { String accountUID = configService.getString(accountRootPropName); if (accountUID.equals(protocolProviderAccountUID)) { lastStatus = configService.getString(accountRootPropName + ".lastAccountStatus"); if (lastStatus != null) break; } } return lastStatus; }
@Override public void run() { try { presence.publishPresenceStatus(status, ""); } catch (IllegalArgumentException e1) { logger.error("Error - changing status", e1); } catch (IllegalStateException e1) { logger.error("Error - changing status", e1); } catch (OperationFailedException e1) { if (e1.getErrorCode() == OperationFailedException.GENERAL_ERROR) { String msgText = GuiActivator.getResources() .getI18NString( "service.gui.STATUS_CHANGE_GENERAL_ERROR", new String[] { protocolProvider.getAccountID().getUserID(), protocolProvider.getAccountID().getService() }); new ErrorDialog( null, GuiActivator.getResources().getI18NString("service.gui.GENERAL_ERROR"), msgText, e1) .showDialog(); } else if (e1.getErrorCode() == OperationFailedException.NETWORK_FAILURE) { String msgText = GuiActivator.getResources() .getI18NString( "service.gui.STATUS_CHANGE_NETWORK_FAILURE", new String[] { protocolProvider.getAccountID().getUserID(), protocolProvider.getAccountID().getService() }); new ErrorDialog( null, msgText, GuiActivator.getResources().getI18NString("service.gui.NETWORK_FAILURE"), e1) .showDialog(); } else if (e1.getErrorCode() == OperationFailedException.PROVIDER_NOT_REGISTERED) { String msgText = GuiActivator.getResources() .getI18NString( "service.gui.STATUS_CHANGE_NETWORK_FAILURE", new String[] { protocolProvider.getAccountID().getUserID(), protocolProvider.getAccountID().getService() }); new ErrorDialog( null, GuiActivator.getResources().getI18NString("service.gui.NETWORK_FAILURE"), msgText, e1) .showDialog(); } logger.error("Error - changing status", e1); } }