diff options
Diffstat (limited to 'src/net/java/sip/communicator/impl/gui/main/contactlist')
7 files changed, 457 insertions, 500 deletions
diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/AddContactDialog.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/AddContactDialog.java index 856ae5b..8d43c7f 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/AddContactDialog.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/AddContactDialog.java @@ -21,9 +21,14 @@ import java.awt.*; import java.awt.Container; import java.awt.event.*; import java.util.*; +import java.util.List; import javax.swing.*; +import javax.swing.border.*; import javax.swing.event.*; +import javax.swing.text.*; + +import org.jitsi.util.*; import net.java.sip.communicator.impl.gui.*; import net.java.sip.communicator.impl.gui.main.contactlist.addgroup.*; @@ -163,31 +168,100 @@ public class AddContactDialog } /** + * Adds a faint gray prompt to the provided text field that + * will vanish as soon as text is entered into the field. + */ + private void addPrompt(JTextField field, String text) + { + final JLabel prompt = new JLabel(text); + + // Give prompt a foreground color like the original + // text field, but with half transparency. + final Color fg = field.getForeground(); + final Color color = new Color( + fg.getRed(), fg.getGreen(), fg.getBlue(), 128); + + // Mimic properties of given text field + prompt.setFont(field.getFont()); + prompt.setForeground(color); + prompt.setBorder(new EmptyBorder(field.getInsets())); + prompt.setHorizontalAlignment(JLabel.LEADING); + + // Add handler to hide prompt when text is entered + final Document doc = field.getDocument(); + doc.addDocumentListener( new DocumentListener() { + public void insertUpdate(DocumentEvent e) + { + prompt.setVisible(doc.getLength() == 0); + } + + public void removeUpdate(DocumentEvent e) + { + prompt.setVisible(doc.getLength() == 0); + } + + public void changedUpdate(DocumentEvent e) {} + }); + + // Add prompt to text field + field.setLayout( new BorderLayout() ); + field.add(prompt); + } + + /** * Initializes the dialog. */ private void init() { + // Get tool tip text for primary controls + final String displayNameInfo = + GuiActivator.getResources().getI18NString( + "service.gui.DISPLAY_NAME_INFO"); + final String contactInfo = + GuiActivator.getResources().getI18NString( + "service.gui.CONTACT_NAME_INFO"); + final String accountInfo = + GuiActivator.getResources().getI18NString( + "service.gui.SELECT_ACCOUNT_INFO"); + final String groupInfo = + GuiActivator.getResources().getI18NString( + "service.gui.SELECT_GROUP_INFO"); + + // Initialize controls this.accountLabel = new JLabel( GuiActivator.getResources().getI18NString( "service.gui.SELECT_ACCOUNT") + ": "); + this.accountLabel.setToolTipText(accountInfo); this.accountCombo = new JComboBox(); - - this.groupLabel = new JLabel( - GuiActivator.getResources().getI18NString( - "service.gui.SELECT_GROUP") + ": "); + this.accountCombo.setToolTipText(accountInfo); this.contactAddressLabel = new JLabel( GuiActivator.getResources().getI18NString( "service.gui.CONTACT_NAME") + ": "); + this.contactAddressLabel.setToolTipText(contactInfo); this.displayNameLabel = new JLabel( GuiActivator.getResources().getI18NString( "service.gui.DISPLAY_NAME") + ": "); + this.displayNameLabel.setToolTipText(displayNameInfo); this.contactAddressField = new JTextField(); + this.contactAddressField.setToolTipText(contactInfo); + addPrompt(this.contactAddressField, + GuiActivator.getResources().getI18NString( + "service.gui.CONTACT_NAME_PROMPT")); this.displayNameField = new JTextField(); + this.displayNameField.setToolTipText(displayNameInfo); + addPrompt(this.displayNameField, + GuiActivator.getResources().getI18NString( + "service.gui.DISPLAY_NAME_PROMPT")); + + this.groupLabel = new JLabel( + GuiActivator.getResources().getI18NString( + "service.gui.SELECT_GROUP") + ": "); + this.groupLabel.setToolTipText(groupInfo); this.addButton = new JButton( GuiActivator.getResources().getI18NString("service.gui.ADD")); @@ -198,6 +272,7 @@ public class AddContactDialog this.imageLabel = new JLabel(); this.groupCombo = createGroupCombo(this); + this.groupCombo.setToolTipText(groupInfo); if(metaContact != null) { @@ -225,15 +300,15 @@ public class AddContactDialog fieldsPanel.add(accountCombo); } - labelsPanel.add(groupLabel); - fieldsPanel.add(groupCombo); - labelsPanel.add(contactAddressLabel); fieldsPanel.add(contactAddressField); labelsPanel.add(displayNameLabel); fieldsPanel.add(displayNameField); + labelsPanel.add(groupLabel); + fieldsPanel.add(groupCombo); + contactAddressField.getDocument().addDocumentListener( new DocumentListener() { @@ -499,6 +574,26 @@ public class AddContactDialog final String contactAddress = contactAddressField.getText().trim(); final String displayName = displayNameField.getText(); + List<String> validationResult = new ArrayList<>(2); + if (!protocolProvider.validateContactAddress(contactAddress, + validationResult)) + { + new ErrorDialog(GuiActivator.getUIService().getMainFrame(), + GuiActivator.getResources() + .getI18NString("service.gui.ADD_CONTACT_ERROR_TITLE"), + validationResult.get(0), ErrorDialog.WARNING).showDialog(); + if (validationResult.size() >= 2) + { + contactAddressField.setText(validationResult.get(1)); + if (StringUtils.isNullOrEmpty(displayName, true)) + { + displayNameField.setText(contactAddress); + } + } + + return; + } + if (!protocolProvider.isRegistered()) { new ErrorDialog( diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactInfoDialog.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactInfoDialog.java deleted file mode 100644 index 325be90..0000000 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactInfoDialog.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Jitsi, the OpenSource Java VoIP and Instant Messaging client. - * - * Copyright @ 2015 Atlassian Pty Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package net.java.sip.communicator.impl.gui.main.contactlist; - -import java.awt.*; -import java.awt.event.*; - -import javax.swing.*; - -import net.java.sip.communicator.impl.gui.customcontrols.*; -import net.java.sip.communicator.plugin.desktoputil.*; -import net.java.sip.communicator.service.contactlist.*; - -/** - * The <tt>ContactInfoPanel</tt> is a popup dialog containing the contact - * detailed info. - * - * @author Yana Stamcheva - */ -public class ContactInfoDialog - extends SIPCommDialog - implements WindowFocusListener -{ - - private JPanel protocolsPanel = new TransparentPanel(new GridLayout(0, 1)); - - private TransparentBackground bg; - - /** - * Creates an instance of the <tt>ContactInfoPanel</tt>. - * - * @param owner The frame owner of this dialog. - * @param contactItem The <tt>MetaContact</tt> for the info. - */ - public ContactInfoDialog(Frame owner, MetaContact contactItem) - { - super(owner); - - this.setUndecorated(true); - - this.setModal(true); - - // Create the transparent background component - this.bg = new TransparentBackground(this); - - this.bg.setLayout(new BorderLayout()); - - this.bg.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); - - this.getContentPane().setLayout(new BorderLayout()); - - this.init(); - - this.getContentPane().add(bg, BorderLayout.CENTER); - - this.pack(); - - this.setSize(140, 50); - - this.addWindowFocusListener(this); - } - - /** - * Initializes the <tt>ContactInfoPanel</tt>. - */ - private void init() - { - /* - * String[] protocolList = this.contactItem.getC(); - * - * if(protocolsPanel.getComponentCount() == 0){ for(int i = 0; i < - * protocolList.length; i ++){ - * - * JLabel protocolLabel = new JLabel(protocolList[i], new - * ImageIcon(Constants.getProtocolIcon(protocolList[i])), JLabel.LEFT); - * - * this.protocolsPanel.add(protocolLabel); } } - * - * this.bg.add(protocolsPanel, BorderLayout.CENTER); - */ - } - - /** - * Returns the panel containing all contact protocols' information. - * - * @return the panel containing all contact protocols' information. - */ - public JPanel getProtocolsPanel() - { - return protocolsPanel; - } - - public void windowGainedFocus(WindowEvent e) - { - - } - - public void windowLostFocus(WindowEvent e) - { - close(false); - } - - public void setPopupLocation(int x, int y) - { - this.setLocation(x, y); - - this.bg.updateBackground(x, y); - } - - @Override - protected void close(boolean isEscaped) - { - this.setVisible(false); - this.dispose(); - } -} diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListTreeCellRenderer.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListTreeCellRenderer.java index bfe2fd3..ae0e3b0 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListTreeCellRenderer.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/ContactListTreeCellRenderer.java @@ -1078,7 +1078,7 @@ public class ContactListTreeCellRenderer UIContactDetail desktopContact = uiContact.getDefaultContactDetail( - OperationSetDesktopStreaming.class); + OperationSetDesktopSharingServer.class); if (desktopContact != null || (contactPhoneUtil != null diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/PresenceFilter.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/PresenceFilter.java index cf7108f..011b00a 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/PresenceFilter.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/PresenceFilter.java @@ -1,4 +1,4 @@ -/*
+/* * Jitsi, the OpenSource Java VoIP and Instant Messaging client. * * Copyright @ 2015 Atlassian Pty Ltd @@ -15,353 +15,353 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package net.java.sip.communicator.impl.gui.main.contactlist;
-
-import java.util.*;
-
-import net.java.sip.communicator.impl.gui.*;
-import net.java.sip.communicator.impl.gui.main.contactlist.contactsource.*;
-import net.java.sip.communicator.service.contactlist.*;
-import net.java.sip.communicator.service.contactsource.*;
-import net.java.sip.communicator.service.gui.*;
-import net.java.sip.communicator.service.gui.event.*;
-import net.java.sip.communicator.service.protocol.*;
-import net.java.sip.communicator.util.*;
-
-/**
- * The <tt>PresenceFilter</tt> is used to filter offline contacts from the
- * contact list.
- *
- * @author Yana Stamcheva
- */
-public class PresenceFilter
- implements ContactListFilter
-{
- /**
- * The <tt>Logger</tt> used by the <tt>PresenceFilter</tt> class and its
- * instances to print debugging information.
- */
- private static final Logger logger = Logger.getLogger(PresenceFilter.class);
-
- /**
- * Indicates if this presence filter shows or hides the offline contacts.
- */
- private boolean isShowOffline;
-
- /**
- * The initial result count below which we insert all filter results
- * directly to the contact list without firing events.
- */
- private static final int INITIAL_CONTACT_COUNT = 30;
-
- /**
- * Creates an instance of <tt>PresenceFilter</tt>.
- */
- public PresenceFilter()
- {
- isShowOffline = ConfigurationUtils.isShowOffline();
- }
-
- /**
- * Applies this filter. This filter is applied over the
- * <tt>MetaContactListService</tt>.
- *
- * @param filterQuery the query which keeps track of the filtering results
- */
- public void applyFilter(FilterQuery filterQuery)
- {
- // Create the query that will track filtering.
- MetaContactQuery query = new MetaContactQuery();
-
- // Add this query to the filterQuery.
- filterQuery.addContactQuery(query);
-
- TreeContactList contactList = GuiActivator.getContactList();
-
- Collection<UIContactSource> uiContactSourceCollection
- = contactList.getContactSources(
- ContactSourceService.CONTACT_LIST_TYPE);
-
- Iterator<UIContactSource> filterSources
- = uiContactSourceCollection.iterator();
- int maxIndex = 0;
- while (filterSources.hasNext())
- {
- UIContactSource filterSource = filterSources.next();
- int currIx = filterSource.getContactSourceService().getIndex();
- if(maxIndex < currIx)
- maxIndex = currIx;
- }
-
- contactList.getMetaContactListSource().setIndex(maxIndex + 1);
-
- filterSources = uiContactSourceCollection.iterator();
- while (filterSources.hasNext())
- {
- UIContactSource filterSource = filterSources.next();
-
- filterSource.setContactSourceIndex(
- filterSource.getContactSourceService().getIndex());
-
- ContactSourceService sourceService
- = filterSource.getContactSourceService();
-
- ContactQuery contactQuery
- = sourceService.createContactQuery(null);
-
- if(contactQuery == null)
- continue;
-
- // Add this query to the filterQuery.
- filterQuery.addContactQuery(contactQuery);
-
- contactQuery.addContactQueryListener(contactList);
-
- contactQuery.start();
- }
-
- // Closes this filter to indicate that we finished adding queries to it.
- filterQuery.close();
-
- query.addContactQueryListener(GuiActivator.getContactList());
- int resultCount = 0;
-
- addMatching(GuiActivator.getContactListService().getRoot(),
- query,
- resultCount);
-
- query.fireQueryEvent(
- query.isCanceled()
- ? MetaContactQueryStatusEvent.QUERY_CANCELED
- : MetaContactQueryStatusEvent.QUERY_COMPLETED);
- }
-
- /**
- * Indicates if the given <tt>uiContact</tt> is matching this filter.
- *
- * @param uiContact the <tt>UIContact</tt> to check
- * @return <tt>true</tt> if the given <tt>uiContact</tt> is matching
- * this filter, otherwise returns <tt>false</tt>
- */
- public boolean isMatching(UIContact uiContact)
- {
- Object descriptor = uiContact.getDescriptor();
-
- if (descriptor instanceof MetaContact)
- return isMatching((MetaContact) descriptor);
- else if (descriptor instanceof SourceContact)
- return isMatching((SourceContact)descriptor);
- else
- return false;
- }
-
- /**
- * Indicates if the given <tt>uiGroup</tt> is matching this filter.
- *
- * @param uiGroup the <tt>UIGroup</tt> to check
- * @return <tt>true</tt> if the given <tt>uiGroup</tt> is matching
- * this filter, otherwise returns <tt>false</tt>
- */
- public boolean isMatching(UIGroup uiGroup)
- {
- Object descriptor = uiGroup.getDescriptor();
-
- if (descriptor instanceof MetaContactGroup)
- return isMatching((MetaContactGroup) descriptor);
- else
- return false;
- }
-
- /**
- * Sets the show offline property.
- *
- * @param isShowOffline indicates if offline contacts are shown
- */
- public void setShowOffline(boolean isShowOffline)
- {
- this.isShowOffline = isShowOffline;
-
- ConfigurationUtils.setShowOffline(isShowOffline);
- }
-
- /**
- * Returns <tt>true</tt> if offline contacts are shown, otherwise returns
- * <tt>false</tt>.
- *
- * @return <tt>true</tt> if offline contacts are shown, otherwise returns
- * <tt>false</tt>
- */
- public boolean isShowOffline()
- {
- return isShowOffline;
- }
-
- /**
- * Returns <tt>true</tt> if offline contacts are shown or if the given
- * <tt>MetaContact</tt> is online, otherwise returns false.
- *
- * @param metaContact the <tt>MetaContact</tt> to check
- * @return <tt>true</tt> if the given <tt>MetaContact</tt> is matching this
- * filter
- */
- public boolean isMatching(MetaContact metaContact)
- {
- return isShowOffline || isContactOnline(metaContact);
- }
-
- /**
- * Returns <tt>true</tt> if offline contacts are shown or if the given
- * <tt>MetaContact</tt> is online, otherwise returns false.
- *
- * @param contact the <tt>MetaContact</tt> to check
- * @return <tt>true</tt> if the given <tt>MetaContact</tt> is matching this
- * filter
- */
- public boolean isMatching(SourceContact contact)
- {
- // make sure we always show chat rooms and recent messages
- return
- isShowOffline
- || contact.getPresenceStatus().isOnline()
- || contact.getContactSource().getType()
- == ContactSourceService.CONTACT_LIST_TYPE;
- }
-
- /**
- * Returns <tt>true</tt> if offline contacts are shown or if the given
- * <tt>MetaContactGroup</tt> contains online contacts.
- *
- * @param metaGroup the <tt>MetaContactGroup</tt> to check
- * @return <tt>true</tt> if the given <tt>MetaContactGroup</tt> is matching
- * this filter
- */
- private boolean isMatching(MetaContactGroup metaGroup)
- {
- return
- isShowOffline
- || (metaGroup.countOnlineChildContacts() > 0)
- || MetaContactListSource.isNewGroup(metaGroup);
- }
-
- /**
- * Returns <tt>true</tt> if the given meta contact is online, <tt>false</tt>
- * otherwise.
- *
- * @param contact the meta contact
- * @return <tt>true</tt> if the given meta contact is online, <tt>false</tt>
- * otherwise
- */
- private boolean isContactOnline(MetaContact contact)
- {
- // If for some reason the default contact is null we return false.
- Contact defaultContact = contact.getDefaultContact();
- if(defaultContact == null)
- return false;
-
- // Lays on the fact that the default contact is the most connected.
- return defaultContact.getPresenceStatus().getStatus()
- >= PresenceStatus.ONLINE_THRESHOLD;
- }
-
- /**
- * Adds all contacts contained in the given <tt>MetaContactGroup</tt>
- * matching the current filter and not contained in the contact list.
- *
- * @param metaGroup the <tt>MetaContactGroup</tt>, which matching contacts
- * to add
- * @param query the <tt>MetaContactQuery</tt> that notifies interested
- * listeners of the results of this matching
- * @param resultCount the initial result count we would insert directly to
- * the contact list without firing events
- */
- private void addMatching( MetaContactGroup metaGroup,
- MetaContactQuery query,
- int resultCount)
- {
- Iterator<MetaContact> childContacts = metaGroup.getChildContacts();
-
- while (childContacts.hasNext() && !query.isCanceled())
- {
- MetaContact metaContact = childContacts.next();
-
- if(isMatching(metaContact))
- {
-
- resultCount++;
- if (resultCount <= INITIAL_CONTACT_COUNT)
- {
- UIGroup uiGroup = null;
-
- if (!MetaContactListSource.isRootGroup(metaGroup))
- {
- synchronized (metaGroup)
- {
- uiGroup = MetaContactListSource
- .getUIGroup(metaGroup);
- if (uiGroup == null)
- uiGroup = MetaContactListSource
- .createUIGroup(metaGroup);
- }
- }
-
- if (logger.isDebugEnabled())
- logger.debug("Presence filter contact added: "
- + metaContact.getDisplayName());
-
- UIContactImpl newUIContact;
- synchronized (metaContact)
- {
- newUIContact
- = MetaContactListSource.getUIContact(metaContact);
-
- if (newUIContact == null)
- {
- newUIContact = MetaContactListSource
- .createUIContact(metaContact);
- }
- }
-
- GuiActivator.getContactList().addContact(
- newUIContact,
- uiGroup,
- true,
- true);
-
- query.setInitialResultCount(resultCount);
- }
- else
- {
- query.fireQueryEvent(metaContact);
- }
- }
- }
-
- // If in the meantime the filtering has been stopped we return here.
- if (query.isCanceled())
- return;
-
- Iterator<MetaContactGroup> subgroups = metaGroup.getSubgroups();
- while(subgroups.hasNext() && !query.isCanceled())
- {
- MetaContactGroup subgroup = subgroups.next();
-
- if (isMatching(subgroup))
- {
- UIGroup uiGroup;
- synchronized(subgroup)
- {
- uiGroup = MetaContactListSource
- .getUIGroup(subgroup);
-
- if (uiGroup == null)
- uiGroup = MetaContactListSource
- .createUIGroup(subgroup);
- }
-
- GuiActivator.getContactList().addGroup(uiGroup, true);
-
- addMatching(subgroup, query, resultCount);
- }
- }
- }
-}
+package net.java.sip.communicator.impl.gui.main.contactlist; + +import java.util.*; + +import net.java.sip.communicator.impl.gui.*; +import net.java.sip.communicator.impl.gui.main.contactlist.contactsource.*; +import net.java.sip.communicator.service.contactlist.*; +import net.java.sip.communicator.service.contactsource.*; +import net.java.sip.communicator.service.gui.*; +import net.java.sip.communicator.service.gui.event.*; +import net.java.sip.communicator.service.protocol.*; +import net.java.sip.communicator.util.*; + +/** + * The <tt>PresenceFilter</tt> is used to filter offline contacts from the + * contact list. + * + * @author Yana Stamcheva + */ +public class PresenceFilter + implements ContactListFilter +{ + /** + * The <tt>Logger</tt> used by the <tt>PresenceFilter</tt> class and its + * instances to print debugging information. + */ + private static final Logger logger = Logger.getLogger(PresenceFilter.class); + + /** + * Indicates if this presence filter shows or hides the offline contacts. + */ + private boolean isShowOffline; + + /** + * The initial result count below which we insert all filter results + * directly to the contact list without firing events. + */ + private static final int INITIAL_CONTACT_COUNT = 30; + + /** + * Creates an instance of <tt>PresenceFilter</tt>. + */ + public PresenceFilter() + { + isShowOffline = ConfigurationUtils.isShowOffline(); + } + + /** + * Applies this filter. This filter is applied over the + * <tt>MetaContactListService</tt>. + * + * @param filterQuery the query which keeps track of the filtering results + */ + public void applyFilter(FilterQuery filterQuery) + { + // Create the query that will track filtering. + MetaContactQuery query = new MetaContactQuery(); + + // Add this query to the filterQuery. + filterQuery.addContactQuery(query); + + TreeContactList contactList = GuiActivator.getContactList(); + + Collection<UIContactSource> uiContactSourceCollection + = contactList.getContactSources( + ContactSourceService.CONTACT_LIST_TYPE); + + Iterator<UIContactSource> filterSources + = uiContactSourceCollection.iterator(); + int maxIndex = 0; + while (filterSources.hasNext()) + { + UIContactSource filterSource = filterSources.next(); + int currIx = filterSource.getContactSourceService().getIndex(); + if(maxIndex < currIx) + maxIndex = currIx; + } + + contactList.getMetaContactListSource().setIndex(maxIndex + 1); + + filterSources = uiContactSourceCollection.iterator(); + while (filterSources.hasNext()) + { + UIContactSource filterSource = filterSources.next(); + + filterSource.setContactSourceIndex( + filterSource.getContactSourceService().getIndex()); + + ContactSourceService sourceService + = filterSource.getContactSourceService(); + + ContactQuery contactQuery + = sourceService.createContactQuery(null); + + if(contactQuery == null) + continue; + + // Add this query to the filterQuery. + filterQuery.addContactQuery(contactQuery); + + contactQuery.addContactQueryListener(contactList); + + contactQuery.start(); + } + + // Closes this filter to indicate that we finished adding queries to it. + filterQuery.close(); + + query.addContactQueryListener(GuiActivator.getContactList()); + int resultCount = 0; + + addMatching(GuiActivator.getContactListService().getRoot(), + query, + resultCount); + + query.fireQueryEvent( + query.isCanceled() + ? MetaContactQueryStatusEvent.QUERY_CANCELED + : MetaContactQueryStatusEvent.QUERY_COMPLETED); + } + + /** + * Indicates if the given <tt>uiContact</tt> is matching this filter. + * + * @param uiContact the <tt>UIContact</tt> to check + * @return <tt>true</tt> if the given <tt>uiContact</tt> is matching + * this filter, otherwise returns <tt>false</tt> + */ + public boolean isMatching(UIContact uiContact) + { + Object descriptor = uiContact.getDescriptor(); + + if (descriptor instanceof MetaContact) + return isMatching((MetaContact) descriptor); + else if (descriptor instanceof SourceContact) + return isMatching((SourceContact)descriptor); + else + return false; + } + + /** + * Indicates if the given <tt>uiGroup</tt> is matching this filter. + * + * @param uiGroup the <tt>UIGroup</tt> to check + * @return <tt>true</tt> if the given <tt>uiGroup</tt> is matching + * this filter, otherwise returns <tt>false</tt> + */ + public boolean isMatching(UIGroup uiGroup) + { + Object descriptor = uiGroup.getDescriptor(); + + if (descriptor instanceof MetaContactGroup) + return isMatching((MetaContactGroup) descriptor); + else + return false; + } + + /** + * Sets the show offline property. + * + * @param isShowOffline indicates if offline contacts are shown + */ + public void setShowOffline(boolean isShowOffline) + { + this.isShowOffline = isShowOffline; + + ConfigurationUtils.setShowOffline(isShowOffline); + } + + /** + * Returns <tt>true</tt> if offline contacts are shown, otherwise returns + * <tt>false</tt>. + * + * @return <tt>true</tt> if offline contacts are shown, otherwise returns + * <tt>false</tt> + */ + public boolean isShowOffline() + { + return isShowOffline; + } + + /** + * Returns <tt>true</tt> if offline contacts are shown or if the given + * <tt>MetaContact</tt> is online, otherwise returns false. + * + * @param metaContact the <tt>MetaContact</tt> to check + * @return <tt>true</tt> if the given <tt>MetaContact</tt> is matching this + * filter + */ + public boolean isMatching(MetaContact metaContact) + { + return isShowOffline || isContactOnline(metaContact); + } + + /** + * Returns <tt>true</tt> if offline contacts are shown or if the given + * <tt>MetaContact</tt> is online, otherwise returns false. + * + * @param contact the <tt>MetaContact</tt> to check + * @return <tt>true</tt> if the given <tt>MetaContact</tt> is matching this + * filter + */ + public boolean isMatching(SourceContact contact) + { + // make sure we always show chat rooms and recent messages + return + isShowOffline + || contact.getPresenceStatus().isOnline() + || contact.getContactSource().getType() + == ContactSourceService.CONTACT_LIST_TYPE; + } + + /** + * Returns <tt>true</tt> if offline contacts are shown or if the given + * <tt>MetaContactGroup</tt> contains online contacts. + * + * @param metaGroup the <tt>MetaContactGroup</tt> to check + * @return <tt>true</tt> if the given <tt>MetaContactGroup</tt> is matching + * this filter + */ + private boolean isMatching(MetaContactGroup metaGroup) + { + return + isShowOffline + || (metaGroup.countOnlineChildContacts() > 0) + || MetaContactListSource.isNewGroup(metaGroup); + } + + /** + * Returns <tt>true</tt> if the given meta contact is online, <tt>false</tt> + * otherwise. + * + * @param contact the meta contact + * @return <tt>true</tt> if the given meta contact is online, <tt>false</tt> + * otherwise + */ + private boolean isContactOnline(MetaContact contact) + { + // If for some reason the default contact is null we return false. + Contact defaultContact = contact.getDefaultContact(); + if(defaultContact == null) + return false; + + // Lays on the fact that the default contact is the most connected. + return defaultContact.getPresenceStatus().getStatus() + >= PresenceStatus.ONLINE_THRESHOLD; + } + + /** + * Adds all contacts contained in the given <tt>MetaContactGroup</tt> + * matching the current filter and not contained in the contact list. + * + * @param metaGroup the <tt>MetaContactGroup</tt>, which matching contacts + * to add + * @param query the <tt>MetaContactQuery</tt> that notifies interested + * listeners of the results of this matching + * @param resultCount the initial result count we would insert directly to + * the contact list without firing events + */ + private void addMatching( MetaContactGroup metaGroup, + MetaContactQuery query, + int resultCount) + { + Iterator<MetaContact> childContacts = metaGroup.getChildContacts(); + + while (childContacts.hasNext() && !query.isCanceled()) + { + MetaContact metaContact = childContacts.next(); + + if(isMatching(metaContact)) + { + + resultCount++; + if (resultCount <= INITIAL_CONTACT_COUNT) + { + UIGroup uiGroup = null; + + if (!MetaContactListSource.isRootGroup(metaGroup)) + { + synchronized (metaGroup) + { + uiGroup = MetaContactListSource + .getUIGroup(metaGroup); + if (uiGroup == null) + uiGroup = MetaContactListSource + .createUIGroup(metaGroup); + } + } + + if (logger.isDebugEnabled()) + logger.debug("Presence filter contact added: " + + metaContact.getDisplayName()); + + UIContactImpl newUIContact; + synchronized (metaContact) + { + newUIContact + = MetaContactListSource.getUIContact(metaContact); + + if (newUIContact == null) + { + newUIContact = MetaContactListSource + .createUIContact(metaContact); + } + } + + GuiActivator.getContactList().addContact( + newUIContact, + uiGroup, + true, + true); + + query.setInitialResultCount(resultCount); + } + else + { + query.fireQueryEvent(metaContact); + } + } + } + + // If in the meantime the filtering has been stopped we return here. + if (query.isCanceled()) + return; + + Iterator<MetaContactGroup> subgroups = metaGroup.getSubgroups(); + while(subgroups.hasNext() && !query.isCanceled()) + { + MetaContactGroup subgroup = subgroups.next(); + + if (isMatching(subgroup)) + { + UIGroup uiGroup; + synchronized(subgroup) + { + uiGroup = MetaContactListSource + .getUIGroup(subgroup); + + if (uiGroup == null) + uiGroup = MetaContactListSource + .createUIGroup(subgroup); + } + + GuiActivator.getContactList().addGroup(uiGroup, true); + + addMatching(subgroup, query, resultCount); + } + } + } +} diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/SearchFilter.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/SearchFilter.java index 837d369..4735892 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/SearchFilter.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/SearchFilter.java @@ -270,14 +270,13 @@ public class SearchFilter */ private boolean isMatching(String text) { - if (filterPattern != null) - return filterPattern.matcher(text).find(); + if (filterPattern != null && filterPattern.matcher(text).find()) + return true; if(isSearchingPhoneNumber && this.filterString != null) return GuiActivator.getPhoneNumberI18nService() .phoneNumbersMatch(this.filterString, text); return true; - } } diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/TreeContactList.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/TreeContactList.java index a916b2b..119e000 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/TreeContactList.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/TreeContactList.java @@ -565,10 +565,6 @@ public class TreeContactList if (isActive) { activeContacts.add(contactNode); -// SystrayService stray = GuiActivator.getSystrayService(); -// -// if (stray != null) -// stray.setSystrayIcon(SystrayService.ENVELOPE_IMG_TYPE); } else activeContacts.remove(contactNode); diff --git a/src/net/java/sip/communicator/impl/gui/main/contactlist/contactsource/SourceUIContact.java b/src/net/java/sip/communicator/impl/gui/main/contactlist/contactsource/SourceUIContact.java index 72bec25..1419416 100644 --- a/src/net/java/sip/communicator/impl/gui/main/contactlist/contactsource/SourceUIContact.java +++ b/src/net/java/sip/communicator/impl/gui/main/contactlist/contactsource/SourceUIContact.java @@ -573,7 +573,7 @@ public class SourceUIContact } else { - labelText = contactDetail.getDetail(); + labelText = contactDetail.getDisplayName(); } jLabels[i] = new JLabel(filterAddressDisplay(labelText)); @@ -709,11 +709,9 @@ public class SourceUIContact case AIM: case ICQ: case Jabber: - case MSN: case Yahoo: case Skype: case GoogleTalk: - case Facebook: label = subCategory.value(); break; default: |