<commit_before>/*
 * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

package net.java.sip.communicator.impl.gui.main;

import java.util.*;
import java.util.List;

import java.awt.*;
import javax.swing.*;

import net.java.sip.communicator.impl.gui.*;
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.service.configuration.*;
import net.java.sip.communicator.service.protocol.*;

/**
 * The <tt>StatusPanel</tt> is the place where the user can see and change
 * its status for all registered protocols. 
 * 
 * @author <NAME>
 */
public class StatusPanel extends JPanel {

    private Hashtable protocolStatusCombos = new Hashtable();

    private MainFrame mainFrame;

    /**
     * Creates an instance of <tt>StatusPanel</tt>.
     * @param mainFrame The main application window.
     */
    public StatusPanel(MainFrame mainFrame) {

        this.mainFrame = mainFrame;

        this.setLayout(new FlowLayout(FlowLayout.RIGHT, 0, 0));

        this.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0,
                Constants.MOVER_START_COLOR));
    }

    /**
     * Creates the selector box, containing all protocol statuses, adds it to 
     * the StatusPanel and refreshes the panel.
     * 
     * @param protocolProvider The protocol provider.
     */
    public void addAccount(ProtocolProviderService protocolProvider) {
        
        StatusSelectorBox protocolStatusCombo = new StatusSelectorBox(
                this.mainFrame, protocolProvider);
        
        this.protocolStatusCombos.put(protocolProvider.getAccountID(),
                protocolStatusCombo);

        this.add(protocolStatusCombo);

        this.getParent().validate();
    }

    /**
     * Removes the selector box, containing all protocol statuses, from 
     * the StatusPanel and refreshes the panel.
     * 
     * @param accountID The identifier of the account to remove.
     */
    public void removeAccount(AccountID accountID) {
        
        StatusSelectorBox protocolStatusCombo = (StatusSelectorBox)
            this.protocolStatusCombos.get(accountID);

        this.protocolStatusCombos.remove(accountID);
        this.remove(protocolStatusCombo);

        this.getParent().validate();
    }
    
    /**
     * Sets the selected status.
     * 
     * @param protocolProvider The protocol provider.
     * @param status The newly selected status.
     */
    public void setSelectedStatus(ProtocolProviderService protocolProvider,
                                    PresenceStatus status) {
        
        StatusSelectorBox selectorBox 
            = (StatusSelectorBox) protocolStatusCombos.get(
                    protocolProvider.getAccountID());

        selectorBox.setSelectedStatus(status);

        selectorBox.repaint();
    }

    /**
     * Shows the protocol animated icon, which indicates that it is in a
     * connecting state.
     * 
     * @param protocolProvider The protocol provider.
     */
    public void startConnecting(ProtocolProviderService protocolProvider) {

        StatusSelectorBox selectorBox 
            = (StatusSelectorBox) protocolStatusCombos
                .get(protocolProvider.getAccountID());

        selectorBox.startConnecting(Constants
                .getProtocolAnimatedIcon(protocolProvider.getProtocolName()));

        selectorBox.repaint();
    }

    /**
     * Updates the status for this protocol provider.
     *  
     * @param protocolProvider The ProtocolProvider, which presence status to
     * update.
     */
    public void updateStatus(ProtocolProviderService protocolProvider) {

        StatusSelectorBox selectorBox 
            = (StatusSelectorBox) protocolStatusCombos
                .get(protocolProvider.getAccountID());

        if(!protocolProvider.isRegistered())
            selectorBox.updateStatus(selectorBox.getOfflineStatus());
        else {            
            if(selectorBox.getLastSelectedStatus() != null) {
                selectorBox.updateStatus(selectorBox.getLastSelectedStatus());
            }
            else {
                ConfigurationService configService
                    = GuiActivator.getConfigurationService();
            
                Iterator pproviders = mainFrame.getProtocolProviders();
                
                //For each protocol provider find the last contact status
                //saved in the configuration.
                while(pproviders.hasNext()) {
                    ProtocolProviderService pps
                        = (ProtocolProviderService) pproviders.next();
                    
                    String lastStatus = null;
                    
                    Iterator i = mainFrame.getProtocolPresence(pps)
                        .getSupportedStatusSet();
                    
                    String prefix = "net.java.sip.communicator.impl.ui";
                    
                    List accounts = configService
                            .getPropertyNamesByPrefix(prefix, true);
                    
                    Iterator accountsIter = accounts.iterator();
                    
                    while(accountsIter.hasNext()) {
                        String accountRootPropName 
                            = (String) accountsIter.next();
                        
                        String accountUID 
                            = configService.getString(accountRootPropName);
                        
                        if(accountUID.equals(protocolProvider
                                .getAccountID().getAccountUniqueID())) {
                            lastStatus = configService.getString(
                                    accountRootPropName + ".lastAccountStatus");
                            
                            if(lastStatus != null)
                                break;
                        }
                    }
                    
                    if(lastStatus == null) {                
                        selectorBox.updateStatus(selectorBox.getOnlineStatus());
                    }
                    else {
                        PresenceStatus status;
                        while(i.hasNext()) {
                            status = (PresenceStatus)i.next();
                            if(status.getStatusName().equals(lastStatus)) {
                                selectorBox.updateStatus(status);
                                break;
                            } 
                        }
                    }
                }
            }
        }
        selectorBox.repaint();
    }

    /**
     * Checks if the given protocol has already its <tt>StatusSelectorBox</tt>
     * in the <tt>StatusPanel</tt>.
     * 
     * @param accountID The identifier of the account.
     * @return True if the protcol has already its StatusSelectorBox in the 
     * StatusPanel, False otherwise.
     */
    public boolean containsAccount(AccountID accountID) {
        if (protocolStatusCombos.containsKey(accountID))
            return true;
        else
            return false;
    }   
}<commit_msg>update status for a provider<commit_after>/*
 * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

package net.java.sip.communicator.impl.gui.main;

import java.util.*;
import java.util.List;

import java.awt.*;
import javax.swing.*;

import net.java.sip.communicator.impl.gui.*;
import net.java.sip.communicator.impl.gui.utils.*;
import net.java.sip.communicator.service.configuration.*;
import net.java.sip.communicator.service.protocol.*;

/**
 * The <tt>StatusPanel</tt> is the place where the user can see and change
 * its status for all registered protocols. 
 * 
 * @author <NAME>
 */
public class StatusPanel extends JPanel {

    private Hashtable protocolStatusCombos = new Hashtable();

    private MainFrame mainFrame;

    /**
     * Creates an instance of <tt>StatusPanel</tt>.
     * @param mainFrame The main application window.
     */
    public StatusPanel(MainFrame mainFrame) {

        this.mainFrame = mainFrame;

        this.setLayout(new FlowLayout(FlowLayout.RIGHT, 0, 0));

        this.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0,
                Constants.MOVER_START_COLOR));
    }

    /**
     * Creates the selector box, containing all protocol statuses, adds it to 
     * the StatusPanel and refreshes the panel.
     * 
     * @param protocolProvider The protocol provider.
     */
    public void addAccount(ProtocolProviderService protocolProvider) {

        StatusSelectorBox protocolStatusCombo = new StatusSelectorBox(
                this.mainFrame, protocolProvider);
        
        this.protocolStatusCombos.put(protocolProvider.getAccountID(),
                protocolStatusCombo);

        this.add(protocolStatusCombo);

        this.getParent().validate();
    }

    /**
     * Removes the selector box, containing all protocol statuses, from 
     * the StatusPanel and refreshes the panel.
     * 
     * @param accountID The identifier of the account to remove.
     */
    public void removeAccount(AccountID accountID) {
        
        StatusSelectorBox protocolStatusCombo = (StatusSelectorBox)
            this.protocolStatusCombos.get(accountID);

        this.protocolStatusCombos.remove(accountID);
        this.remove(protocolStatusCombo);

        this.getParent().validate();
    }
    
    /**
     * Shows the protocol animated icon, which indicates that it is in a
     * connecting state.
     * 
     * @param protocolProvider The protocol provider.
     */
    public void startConnecting(ProtocolProviderService protocolProvider) {

        StatusSelectorBox selectorBox 
            = (StatusSelectorBox) protocolStatusCombos
                .get(protocolProvider.getAccountID());

        selectorBox.startConnecting(Constants
                .getProtocolAnimatedIcon(protocolProvider.getProtocolName()));

        selectorBox.repaint();
    }

    /**
     * Updates the status for this protocol provider.
     *  
     * @param protocolProvider The ProtocolProvider, which presence status to
     * update.
     */
    public void updateStatus(ProtocolProviderService protocolProvider) {

        StatusSelectorBox selectorBox 
            = (StatusSelectorBox) protocolStatusCombos
                .get(protocolProvider.getAccountID());

        if(!protocolProvider.isRegistered())
            selectorBox.updateStatus(selectorBox.getOfflineStatus());
        else {            
            if(selectorBox.getLastSelectedStatus() != null) {
                selectorBox.updateStatus(selectorBox.getLastSelectedStatus());
            }
            else {
                ConfigurationService configService
                    = GuiActivator.getConfigurationService();
                
                //find the last contact status saved in the configuration.                
                String lastStatus = null;
                
                Iterator i = mainFrame.getProtocolPresence(protocolProvider)
                    .getSupportedStatusSet();
                
                String prefix = "net.java.sip.communicator.impl.ui";
                
                List accounts = configService
                        .getPropertyNamesByPrefix(prefix, true);
                
                Iterator accountsIter = accounts.iterator();
                
                while(accountsIter.hasNext()) {
                    String accountRootPropName 
                        = (String) accountsIter.next();
                    
                    String accountUID 
                        = configService.getString(accountRootPropName);
                    
                    if(accountUID.equals(protocolProvider
                            .getAccountID().getAccountUniqueID())) {
                        lastStatus = configService.getString(
                                accountRootPropName + ".lastAccountStatus");
                        
                        if(lastStatus != null)
                            break;
                    }
                }
                
                if(lastStatus == null) {                
                    selectorBox.updateStatus(selectorBox.getOnlineStatus());
                }
                else {
                    PresenceStatus status;
                    while(i.hasNext()) {
                        status = (PresenceStatus)i.next();
                        if(status.getStatusName().equals(lastStatus)) {
                            selectorBox.updateStatus(status);
                            break;
                        } 
                    }
                }
            }
        }
        selectorBox.repaint();
    }

    /**
     * Checks if the given protocol has already its <tt>StatusSelectorBox</tt>
     * in the <tt>StatusPanel</tt>.
     * 
     * @param accountID The identifier of the account.
     * @return True if the protcol has already its StatusSelectorBox in the 
     * StatusPanel, False otherwise.
     */
    public boolean containsAccount(AccountID accountID) {
        if (protocolStatusCombos.containsKey(accountID))
            return true;
        else
            return false;
    }   
}
{'fraction_non_alphanumeric': 0.07836126629422718, 'fraction_numerical': 0.000893854748603352, 'mean_word_length': 1.6707777998806446, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5010479', 'n_tokens_mistral': 3213, 'n_tokens_neox': 3021, 'n_words': 714}