Package net.sphene.goim.rcp.ui.actions

Source Code of net.sphene.goim.rcp.ui.actions.ChangeStatusAction

/*
* File    : ChangeStatusAction.java
* Created : 02.04.2006
* By      : kahless
*
* GOIM - Gamers Own Instant Messenger
* Copyright (C) 2005-2006 Herbert Poul
*              (JabberId: kahless@sphene.net / Email: herbert.poul@gmail.com)
* http://goim.sphene.net
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
*/
package net.sphene.goim.rcp.ui.actions;

import java.util.EnumMap;
import java.util.Map;

import net.sphene.goim.rcp.beans.GOIMAccount;
import net.sphene.goim.rcp.ui.GOIMIcons;
import net.sphene.goim.rcp.ui.GOIMOnlineStatus;

import org.eclipse.jface.action.Action;
import org.jivesoftware.smack.packet.Presence;

public class ChangeStatusAction extends Action {
  public static final Map<GOIMOnlineStatus,Presence.Mode> statusSmackPresenceMap;
 
  static {
    statusSmackPresenceMap = new EnumMap<GOIMOnlineStatus,Presence.Mode>(GOIMOnlineStatus.class);
    statusSmackPresenceMap.put(GOIMOnlineStatus.AVAILABLE,Presence.Mode.AVAILABLE);
    statusSmackPresenceMap.put(GOIMOnlineStatus.AWAY,Presence.Mode.AWAY);
    statusSmackPresenceMap.put(GOIMOnlineStatus.CHAT,Presence.Mode.CHAT);
    statusSmackPresenceMap.put(GOIMOnlineStatus.XA,Presence.Mode.EXTENDED_AWAY);
    statusSmackPresenceMap.put(GOIMOnlineStatus.DND,Presence.Mode.DO_NOT_DISTURB);
    statusSmackPresenceMap.put(GOIMOnlineStatus.INVISIBLE,Presence.Mode.INVISIBLE);
  }
 
  private GOIMOnlineStatus status;
  private ChangeStatusContribution changeStatusContribution;

  public ChangeStatusAction(ChangeStatusContribution changeStatusContribution, GOIMOnlineStatus status) {
    super(status.readableName(),GOIMIcons.getImageDescriptor(status));
    this.changeStatusContribution = changeStatusContribution;
    this.status = status;
  }
 
  public void run() {
    GOIMAccount account = changeStatusContribution.getAccount();
    Presence.Mode mode = statusSmackPresenceMap.get(status);
    Presence.Type type = Presence.Type.UNAVAILABLE;
    if(mode != null) {
      type = Presence.Type.AVAILABLE;
    }
    if(account.xmpp.isConnected()) {
      account.xmpp.changeStatus(type,mode,true);
    } else {
      if(type == Presence.Type.AVAILABLE) {
        account.xmpp.connect(type,mode);
      }
    }
  }
}
TOP

Related Classes of net.sphene.goim.rcp.ui.actions.ChangeStatusAction

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.