From d9ea78e35d82e6fc11a861f67dfa0eb1c5909feb Mon Sep 17 00:00:00 2001 From: Damian Minkov Date: Tue, 18 Jun 2013 17:20:26 +0300 Subject: [PATCH] Updates callinfo plugin to be able to add its button to more locations. --- resources/images/images.properties | 2 + .../plugin/contactinfo/callUserInfo.png | Bin 0 -> 1831 bytes .../plugin/contactinfo/chatWindowUserInfo.png | Bin 0 -> 1351 bytes .../contactinfo/ContactInfoActivator.java | 105 +++++++++++++++++- .../contactinfo/ContactInfoMenuItem.java | 96 ++++++++++++++-- .../contactinfo/contactinfo.manifest.mf | 1 + 6 files changed, 195 insertions(+), 9 deletions(-) create mode 100644 resources/images/plugin/contactinfo/callUserInfo.png create mode 100644 resources/images/plugin/contactinfo/chatWindowUserInfo.png diff --git a/resources/images/images.properties b/resources/images/images.properties index 37133a52d..8c2cb24f7 100644 --- a/resources/images/images.properties +++ b/resources/images/images.properties @@ -484,6 +484,8 @@ plugin.whiteboard.TEXT2_ICON=resources/images/plugin/whiteboard/text2.png # contactinfo plugin icons plugin.contactinfo.CONTACT_INFO_ICON=resources/images/plugin/contactinfo/userInfo16x16.png +plugin.contactinfo.CONTACT_INFO_TOOLBAR=resources/images/plugin/contactinfo/chatWindowUserInfo.png +plugin.contactinfo.CONTACT_INFO_CALL_WINDOW=resources/images/plugin/contactinfo/callUserInfo.png # keybinding plugin.keybinding.PLUGIN_ICON=resources/images/plugin/keybindingchooser/pluginIcon.png diff --git a/resources/images/plugin/contactinfo/callUserInfo.png b/resources/images/plugin/contactinfo/callUserInfo.png new file mode 100644 index 0000000000000000000000000000000000000000..2784bda3c06bcb5993bddd26d89f08dc4b756655 GIT binary patch literal 1831 zcmbVNX;2eq7>)-95sI}G5RooH7*Uh#=1yt^l1%_5h!7E-L0OW8q>^mdY#>lkz*Z1M zDhQ(-MX449RLY@4xf~r3L~RwRq5>XOs^U;b6rF1AhQs!U?T>!5$M?PaKF@p4?hXm| zx3h7vp-?DxfdOzR`Cdrg&en6tr+s61r$s=>B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n0j8g1Vb)P_|FdtAIfX~Mnb{{CCmwR(P(?U~wWGMN&_mZddrYN3XRe(Fva zxb9_N?R+jikbeM=y5-tFj`YeIPMc0vxLU8W4q$6F8qMm8UR9p4+AVjOQJT{cJ>2o- z^5x6(zw(?n^VF-4ySuzDJbE$E+uN%;RE>T2#J0Zv^y%^41Nt2~Z_lTT^SgsyZ)+QF z*l%?hxI1#}#-YA1niXF8TnC#-n6h~W)s8nSj+tCnY`b*GA-!o=aeKh^H7`4RZ$7}S zYQn3-4ta4M8%8K+ZuR%~Qws_Tw%jSvi!$mwp~1m(@$J{2v}X98ef8@i&L!_tg)P@8 z6}yUxingZ?;LQW$T85-2QzmIY2JfHo?qW}jgzoFepZ{Q;w_nuquwzPUadEM!>tW=Q z1sm^`+7zXqn5+8!ngcI&aKqiMZu_>OxdmF#Eq6R8H`m|lyr;jIGJBY_u`kQVX(L$J zZr*TbTS-|>&An0Bu5hvMNk+s9NAb+<^|iIWZ@ug8@ZUmB&&osNat*WR;0I!3V!SG! z*_Qjfu)oq{lNnz})@(Ox$u}NZ?>ub1&a|24zZrSG7Jy&itFvy%vLnYn^Ef)j3n+Ye mByTjMXosF}eZ~B=f-;NJ?+{(PA`jMCeqDjGVEBY2D*Z3C4#hM8 literal 0 HcmV?d00001 diff --git a/resources/images/plugin/contactinfo/chatWindowUserInfo.png b/resources/images/plugin/contactinfo/chatWindowUserInfo.png new file mode 100644 index 0000000000000000000000000000000000000000..1f221a3afa4ec066e605832b8908c8ba528d30b5 GIT binary patch literal 1351 zcmbVMZA{!`94{|2UN(n=7*NnsKqc8-uXo%_D+l!2>+Z&mUCOy(ByqjAaFx5ZYaez8 zCgy|>GLt!9;xHPQ&5<#UPU1fJLFbsViJ8V2jb>ADk~p%RJsTvU7t9QuLmgHPH% z&;NP;zu*7$>HcWvwoRq?l_ChTDI8*XIM-TlaS{CPdZlkOoT@>v8+2*CAT1a&LQ7g) zM#CwgPv&Jo8r=JZ+=3tl2_@DIx+6O%QA^ncOUIr`=@5+|Eo~WH5c_3-#^pXm^<%$( zbOu8e$&c-JM;sBIkrPU2$dJ2+I%DEczeq}0TPxa>PV98agy_O#2c8GSfGlBC7qblRYX%^XyLkg=&|eU5>ZP0>(v zplB*;F$!^Q0QfQJ=}HJGJrY?XR?XE!!Ia?{LB|QZ15c%_xR$j|z{~%-v97im8`Nc- zmrZTJ5Me!f>vLe3yE_}Q6rnfNPD6o35t6JX4y0rigjqiZPwbK+Q5@~%2*TU!@H!nH zA3=~l!Wr~2td}Jjj;5VCj`gsF+rzlMB+al+$Psh~Xp&>#@VN+13fiO$QGMD0iE-kecoX)HG49UJEHkH};&&-5CT^iko z#9iq3NPI8)Ov$u2d#keiL1g|-$GHn*_`|b&!{x&1lJ=Sdjnep$s`29+N5}H7=c9Am z!q<)?*8%!MW58Asn*}FYKiGPglH3q?Z#lMc{FB-$e^bNbrQac?CwcVVI@f#I#a9Dg z)m@q>k#3d0aj;@C?09P|)c(V>{8djr{q^Yd`Q77x6~ys9+vmbF6L-hHJhLNuqqw)) zm0xta;qs%ySAcss2b=Ob{yrw$Q}gy<)6m)M`&EUH?fh`& z8e!-^55LazTr2~%Ct80in%^8f`eXxzRQ@y@HAC-AFSK9fx0EeC5iMJI@kawuK7MZE z*X-fM=u>3*w>=j(oa+cH^}ifg{O0`4$y1f+6p~?tg{N=6OIp9SaIlj-8Q3%Y59v$G A0RR91 literal 0 HcmV?d00001 diff --git a/src/net/java/sip/communicator/plugin/contactinfo/ContactInfoActivator.java b/src/net/java/sip/communicator/plugin/contactinfo/ContactInfoActivator.java index 0aeb839d1..2412bf27d 100644 --- a/src/net/java/sip/communicator/plugin/contactinfo/ContactInfoActivator.java +++ b/src/net/java/sip/communicator/plugin/contactinfo/ContactInfoActivator.java @@ -3,9 +3,11 @@ import java.util.*; import net.java.sip.communicator.service.browserlauncher.*; +import net.java.sip.communicator.service.contactlist.*; import net.java.sip.communicator.service.gui.*; import net.java.sip.communicator.util.*; +import org.jitsi.service.configuration.*; import org.osgi.framework.*; /** @@ -18,8 +20,32 @@ public class ContactInfoActivator implements BundleActivator { private Logger logger = Logger.getLogger(ContactInfoActivator.class); + /** + * Indicates if the contact info button is enabled in the chat window. + */ + private static final String ENABLED_IN_CHAT_WINDOW_PROP + = "net.java.sip.communicator.plugin.contactinfo." + + "ENABLED_IN_CHAT_WINDOW_PROP"; + + /** + * Indicates if the contact info button is enabled in the call window. + */ + private static final String ENABLED_IN_CALL_WINDOW_PROP + = "net.java.sip.communicator.plugin.contactinfo." + + "ENABLED_IN_CALL_WINDOW_PROP"; + private static BrowserLauncherService browserLauncherService; + /** + * The image loader service implementation. + */ + private static ImageLoaderService imageLoaderService = null; + + /** + * The contact list service implementation. + */ + private static MetaContactListService metaCListService; + static BundleContext bundleContext; /** @@ -41,7 +67,33 @@ public void start(BundleContext bc) throws Exception cinfoMenuItem, containerFilter); - if (logger.isInfoEnabled()) + if(getConfigService().getBoolean(ENABLED_IN_CHAT_WINDOW_PROP, false)) + { + containerFilter = new Hashtable(); + containerFilter.put( + Container.CONTAINER_ID, + Container.CONTAINER_CHAT_TOOL_BAR.getID()); + + bundleContext.registerService( + PluginComponent.class.getName(), + new ContactInfoMenuItem(Container.CONTAINER_CHAT_TOOL_BAR), + containerFilter); + } + + if(getConfigService().getBoolean(ENABLED_IN_CALL_WINDOW_PROP, false)) + { + containerFilter = new Hashtable(); + containerFilter.put( + Container.CONTAINER_ID, + Container.CONTAINER_CALL_DIALOG.getID()); + + bundleContext.registerService( + PluginComponent.class.getName(), + new ContactInfoMenuItem(Container.CONTAINER_CALL_DIALOG), + containerFilter); + } + + if (logger.isInfoEnabled()) logger.info("CONTACT INFO... [REGISTERED]"); } @@ -68,4 +120,53 @@ public static BrowserLauncherService getBrowserLauncher() return browserLauncherService; } -} + + /** + * Returns the imageLoaderService instance, if missing query osgi for it. + * @return the imageLoaderService. + */ + public static ImageLoaderService getImageLoaderService() + { + if(imageLoaderService == null) + { + imageLoaderService = + ServiceUtils.getService( + bundleContext, + ImageLoaderService.class); + } + + return imageLoaderService; + } + + /** + * Returns the MetaContactListService obtained from the bundle + * context. + * @return the MetaContactListService obtained from the bundle + * context + */ + public static MetaContactListService getContactListService() + { + if (metaCListService == null) + { + metaCListService + = ServiceUtils.getService( + bundleContext, + MetaContactListService.class); + } + return metaCListService; + } + + /** + * Returns a reference to a ConfigurationService implementation currently + * registered in the bundle context or null if no such implementation was + * found. + * + * @return a currently valid implementation of the ConfigurationService. + */ + public static ConfigurationService getConfigService() + { + return ServiceUtils.getService(bundleContext, + ConfigurationService.class); + } + +} diff --git a/src/net/java/sip/communicator/plugin/contactinfo/ContactInfoMenuItem.java b/src/net/java/sip/communicator/plugin/contactinfo/ContactInfoMenuItem.java index 5e3960e91..1d33857a5 100644 --- a/src/net/java/sip/communicator/plugin/contactinfo/ContactInfoMenuItem.java +++ b/src/net/java/sip/communicator/plugin/contactinfo/ContactInfoMenuItem.java @@ -11,9 +11,12 @@ import javax.swing.*; +import net.java.sip.communicator.plugin.desktoputil.*; import net.java.sip.communicator.service.contactlist.*; import net.java.sip.communicator.service.gui.*; import net.java.sip.communicator.service.gui.Container; +import net.java.sip.communicator.service.protocol.*; +import net.java.sip.communicator.service.resources.*; /** * @@ -23,16 +26,29 @@ public class ContactInfoMenuItem extends AbstractPluginComponent implements ActionListener { - private JMenuItem menuItem = null; + private AbstractButton menuItem = null; private MetaContact metaContact; + /** + * The button index, for now placed on last position. + */ + private final static int CONTACT_INFO_BUTTON_IX = 50; + /** * Creates a ContactInfoMenuItem. */ public ContactInfoMenuItem() { - super(Container.CONTAINER_CONTACT_RIGHT_BUTTON_MENU); + this(Container.CONTAINER_CONTACT_RIGHT_BUTTON_MENU); + } + + /** + * Creates a ContactInfoMenuItem. + */ + public ContactInfoMenuItem(Container container) + { + super(container); } /** @@ -45,11 +61,32 @@ public void setCurrentContact(MetaContact metaContact) this.metaContact = metaContact; } + /* + * Implements PluginComponent#setCurrentContact(Contact). + * @param contact the currently selected contact + */ + @Override + public void setCurrentContact(Contact contact) + { + if(metaContact == null) + { + // search for the metacontact + MetaContactListService mcs = + ContactInfoActivator.getContactListService(); + + metaContact = + mcs.findMetaContactByContact(contact); + } + } + /** * Initializes and shows the contact details dialog. */ public void actionPerformed(ActionEvent e) { + if(metaContact == null) + return; + ContactInfoDialog cinfoDialog = new ContactInfoDialog(metaContact); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); @@ -69,14 +106,59 @@ public String getName() return getMenuItem().getText(); } - private JMenuItem getMenuItem() + private AbstractButton getMenuItem() { if(menuItem == null) { - menuItem = - new JMenuItem(Resources.getString("service.gui.CONTACT_INFO"), - new ImageIcon(Resources.getImage( - "plugin.contactinfo.CONTACT_INFO_ICON"))); + if(getContainer().equals(Container.CONTAINER_CHAT_TOOL_BAR)) + { + menuItem = + new SIPCommButton(null, + (Image)ContactInfoActivator.getImageLoaderService() + .getImage(new ImageID( + "plugin.contactinfo.CONTACT_INFO_TOOLBAR"))) + { + /** + * Returns the button index. + * @return the button index. + */ + public int getIndex() + { + return CONTACT_INFO_BUTTON_IX; + } + }; + + menuItem.setPreferredSize(new Dimension(25, 25)); + menuItem.setToolTipText( + Resources.getString("service.gui.CONTACT_INFO")); + } + else if(getContainer().equals(Container.CONTAINER_CALL_DIALOG)) + { + menuItem = + new SIPCommButton(null, + (Image)ContactInfoActivator.getImageLoaderService() + .getImage(new ImageID( + "plugin.contactinfo.CONTACT_INFO_CALL_WINDOW"))) + { + /** + * Returns the button index. + * @return the button index. + */ + public int getIndex() + { + return CONTACT_INFO_BUTTON_IX; + } + }; + menuItem.setPreferredSize(new Dimension(44, 38)); + menuItem.setToolTipText( + Resources.getString("service.gui.CONTACT_INFO")); + } + else + menuItem = + new JMenuItem( + Resources.getString("service.gui.CONTACT_INFO"), + new ImageIcon(Resources.getImage( + "plugin.contactinfo.CONTACT_INFO_ICON"))); menuItem.addActionListener(this); } diff --git a/src/net/java/sip/communicator/plugin/contactinfo/contactinfo.manifest.mf b/src/net/java/sip/communicator/plugin/contactinfo/contactinfo.manifest.mf index b1ec3cab7..9e5a9e249 100644 --- a/src/net/java/sip/communicator/plugin/contactinfo/contactinfo.manifest.mf +++ b/src/net/java/sip/communicator/plugin/contactinfo/contactinfo.manifest.mf @@ -12,6 +12,7 @@ Import-Package: org.osgi.framework, net.java.sip.communicator.service.gui.event, net.java.sip.communicator.service.protocol, org.jitsi.service.resources, net.java.sip.communicator.service.resources, + org.jitsi.service.configuration, net.java.sip.communicator.util, net.java.sip.communicator.plugin.desktoputil, javax.swing,