From e812038241452ca0c169e918655e27cedfee6a56 Mon Sep 17 00:00:00 2001 From: Damian Minkov Date: Wed, 1 Apr 2015 14:19:30 +0300 Subject: [PATCH] Adds plugin that adds contact source services (groups to the contact list) with the monitored lines of OperationSetTelephonyBLF. Adds custom action button to pickup calls is possible. --- build.xml | 10 + lib/felix.client.run.properties | 1 + resources/images/images.properties | 6 + .../images/impl/gui/buttons/pickupCall.png | Bin 0 -> 1539 bytes .../impl/gui/buttons/pickupCallPressed.png | Bin 0 -> 1838 bytes .../impl/gui/buttons/pickupCallRollover.png | Bin 0 -> 1739 bytes resources/languages/resources.properties | 2 + .../plugin/busylampfield/BLFActivator.java | 249 ++++++++++++++++++ .../plugin/busylampfield/BLFContactQuery.java | 152 +++++++++++ .../BLFContactSourceService.java | 158 +++++++++++ .../busylampfield/BLFPresenceStatus.java | 77 ++++++ .../busylampfield/BLFSourceContact.java | 47 ++++ .../CustomActionsBLFSourceContact.java | 188 +++++++++++++ .../busylampfield/busylampfield.manifest.mf | 14 + 14 files changed, 904 insertions(+) create mode 100644 resources/images/impl/gui/buttons/pickupCall.png create mode 100644 resources/images/impl/gui/buttons/pickupCallPressed.png create mode 100644 resources/images/impl/gui/buttons/pickupCallRollover.png create mode 100644 src/net/java/sip/communicator/plugin/busylampfield/BLFActivator.java create mode 100644 src/net/java/sip/communicator/plugin/busylampfield/BLFContactQuery.java create mode 100644 src/net/java/sip/communicator/plugin/busylampfield/BLFContactSourceService.java create mode 100644 src/net/java/sip/communicator/plugin/busylampfield/BLFPresenceStatus.java create mode 100644 src/net/java/sip/communicator/plugin/busylampfield/BLFSourceContact.java create mode 100644 src/net/java/sip/communicator/plugin/busylampfield/CustomActionsBLFSourceContact.java create mode 100644 src/net/java/sip/communicator/plugin/busylampfield/busylampfield.manifest.mf diff --git a/build.xml b/build.xml index 921031823..9a98d1dfc 100644 --- a/build.xml +++ b/build.xml @@ -1070,6 +1070,7 @@ bundle-notification-service,bundle-notification-handlers, bundle-notification-wiring,bundle-notification-config, bundle-contacteventhandler, + bundle-plugin-blf, bundle-plugin-contactinfo,bundle-plugin-chatalerter, bundle-keybindings, bundle-plugin-keybindingChooser,bundle-plugin-globalproxyconfig, bundle-jfontchooserlib,bundle-update,bundle-plugin-update, @@ -2753,6 +2754,15 @@ org.bouncycastle.util"/> + + + + + + + DSr z1<%~X^wgl##FWaylc_cg49ppsArU1JzCKpT`MG+DAT@dwxdlMo3=B5*6$OdO*{LN8 zNvY|XdA3ULckfqH$V{%1*XSQL?vFu&J;D8jzb> zlBiITo0C^;Rbi_HHrEQs1_|pcDS(xfWZNo192Makpx~Tel&WB=XRMoSU}&gdW~OIo zVrph)sH0$HU}&Uo07PcGh9*{~W>!Y#3Q(W~w5=#5%__*n4QdyVXRDM^Qc_^0uU}qX zu2*iXmtT~wZ)j<02{OaTNEfI=x41H|B(Xv_uUHvof=g;~a#3bMNoIbY0?5R~r2Ntn zTP2`NAzsKW@b!fooL3ADC}5E3S0onb8|oS8=jMX^1y)^L5|oN?23FO@A(aKG`a!A1 z`K3k4!1zd0hG_np+{nPp!qCvt+`_`i(bC1z$jQyX(#;WO1~$EpCXSZo&W45thOU-|hOS0VE{={C z28NCAFt#)@G&h6z z+`_=Z*uu%x)ZEg@)X~-4R0*m#g`7~+2RcR{lsu4<3rq-@20=`C;sF!Nq_$Tw`aCx5N4ixV1;Y*eI>CNp`M2q9&YDfbn^bb!pFyME%lxr_V3@{ z-^v!8#)cc~|NaV{zU0Z-Lx&czCNrDfx2^y8M=<5*qD70E8X6jAg|CmxWjSTv)X7|{ z>Kyc`O)XU7$D-A%e=|lFy}PsXcjFa(adGj?gs>ltQ=}?AK3$xyA0Kz%#+*5GE|ry) zIc0b`{CvKD!h{J5*4DcXCcU?xlydR)_4WEnkxMvDbY#4R(nZ9?`kp>`5YSZl;_vV8 z+dVhEcyV#@Z=hdm+VsUwQ{BA+k1O=OV6-)m%RB2Fo>>SUmG2+uA!m99@KwY$t{LeBj_b> zQpfToOC&0*t7m&LG4k{C+iR5G-Ch3v;xyf8KPKb1ssX*kf6tQ!P~pzt>FVdQ&MBb@0LfE4-v9sr literal 0 HcmV?d00001 diff --git a/resources/images/impl/gui/buttons/pickupCallPressed.png b/resources/images/impl/gui/buttons/pickupCallPressed.png new file mode 100644 index 0000000000000000000000000000000000000000..e95a52efc0719e52862e2474399664d6c1457244 GIT binary patch literal 1838 zcmbVNc~BE~6pms!q~HN#As%caDhedoXikZeWD|lKgb*}}R+nTUD3xvyRMXgXo z?Fec`ixc-L^oDE0 z1xiRZ?2B9pX*z;13K)#IxHx*;TsnqFFhD+^Z{c9Eyh#ghQ@nwI&E5vn^brOKF==qr zNT8SjurR`5SPUVgkxGX`&>IzskHiMkaH7bRG0d=$0n(Waz1|Yn2Wu0dME;fWNo$iT z-iR=ihzX0qHRO4OPagr3x%<2$iy^5-uoOqhLxH0pOcSF=41_-*3fT2w2LL0lOK za_2F*EGCBsf_yHICl>J`K1(cP@@1kCj!$8wAcx5pNtsMg$^}6wOALubJSHfDSTep; zECNTc{st2P8#Ks>UzGGagoR|E#R?=i0uvan!my~33JBC;1ZL7yJ*^keapi;wMt7|5Q%$>u1#U06-_+$w)aq%vPWyG$XU95lYg z5bLDbweMh=uC$KB)~8pP^OR7kv;DFh+oP(y1BEu#l5vOPE{2uLbL88O)~8IW*4UF%kI&||RxfGL=9NDKlv^2_Cw_~$zU@C3KQ?o#;@llLEn>_@ z`$dig=MFob%BoJ8KuwY5tmtxRaqpFU=|GvZ$fH{h*^P4dE+}#yb1-PbY*d^zzOmf) znS)}-_kFoJo>LsFL}e%Q@}h#|sp6d0_==maghJt|T@8H~P^Xe*12TBH=z5qkf z@}HW+H3bC)jisev#`#k9YMaqiSLk^4`;I41o-|J1w}1axsc*v`WQE?(uRa_1mUuY1 zspf>#T)uocJwMN?fgL?1t@hnyM#H6&Ibs@eA zg+hOe=REdtQBhIy&f<*i+bdmMUE?3)NIh69yCa`dV9C8`|63BmLXCTyCh1 zjg5VJdb(Y=7as)Sm1?zFSGLmaaIT~BuUBuXE;ct;)Fhy)7-wEGWnt3ZthHI0nFo9} z$!Fbu_P1mItb6M=eUr)Ydi|v5(WAoEysJl=3+Hoacs|gTn4O({{pHKpG~Tx7g`+4l z!)DYkoz^o5hlkhgY}8IflCFe|ruEMtg;Z@UUKJVX>8JDRbg~_@zNoN}cPuw|>b=|s zaCV8jv&%n&d-c_e7pvW<)L&87-XHSB?EHrp@7xI=|E{O=+O^)0K2hF$yH>cR*M_YU zrOHqDUFt5Lu&AQ#O0g#Yv}?l`b&JQftxGAc<({*1_uDXWaFoZAO4VrhuDiBMN*$+h tXGXXEI_F)hJik^nS#@*iE$7#avZj26;=q-OTYD{kFn?(PR4iWm-9H@b&y@fG literal 0 HcmV?d00001 diff --git a/resources/images/impl/gui/buttons/pickupCallRollover.png b/resources/images/impl/gui/buttons/pickupCallRollover.png new file mode 100644 index 0000000000000000000000000000000000000000..a4a6a71cc185ea4efdb1f8f2e85d4ee2d6f995a8 GIT binary patch literal 1739 zcmbVNdrT8|9Iv3vl*fETWR~f17?fArE3~C21zV1e4qBj~RC!2g4=A*~dOe^#R0N~) z5UC12m>~{9K`~P|9XQ4^l8G1w2{;iUibTLM0Z9Ns7I)?0_J{G0UGDDp`+e{G`F!8G zf-vbP;_RV1M@ zRH4e;{{Z!+P%M+xk#a&V34xWEmaZ`C(2ZI>iKb9|{f&BsG8H9&1T;ylOr7C$U(BBX6HNqr;79|vbQLE7zU?U$~;DyP(S)vLx|gSt2|)mdLx;TC91i3Gu$T~w!6a{vC*%#YIWUV0EL|XJ z4Ob~{_Dm^ zwGEM(dXynU4OkkkBz*C;rVurYilHn_?ue{Dv}r?0eV7d49vNb?6Rv>yDbHiRUxJGvCZ)KAU;xX9{ttipO(T^scy& zQhakKwPz&`u33AEmU|?nr0np?BUiVau&Zk*--_I^YD=pteqjKdL`AiRTZg2%2>7P3 zM(z6WRy8$bWq?C(z@<)FMf;G>!6dxIEL6n2r<6;t4C?N_Gt^Hdea(g8y4dLG?2$Ld zv5Rl3KML#Y%*x8?DPX-&zkV4s3^wclKX=@{3^%SA3B(mGykNg zrzg1i*_I%e(~vHvT9!sF3=a-28XEb|?W|$Kt)=pFtNiiSGqT!lK@-TeJO47z_t&Vg z{o4B7*KY5v*WNEb6I5I*Qqo$x`{Lco+NdD)Sj)bKJJKu4Qpb$YRwvVOmu=g|Q@t-( zKMJ{yfTrYjuhofH*@rJ|?|D64QD0y0CY$Q-?;jc%7_e-LYd(4IWlc?u!z@`%iD=RAxotRx8XHpJMyGq4p%gZ`rF6WTjFJ0F=$rc|320Jitsi is distributed under \ the terms of the LGPL (\ http://www.gnu.org). +plugin.busylampfield.PICKUP=Pickup call + # Dict protocol service.protocol.DICTIONARIES=Dictionaries plugin.dictaccregwizz.ANY_DICTIONARY=Any Dictionary diff --git a/src/net/java/sip/communicator/plugin/busylampfield/BLFActivator.java b/src/net/java/sip/communicator/plugin/busylampfield/BLFActivator.java new file mode 100644 index 000000000..a8b780714 --- /dev/null +++ b/src/net/java/sip/communicator/plugin/busylampfield/BLFActivator.java @@ -0,0 +1,249 @@ +/* + * Jitsi, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.plugin.busylampfield; + +import net.java.sip.communicator.service.contactsource.*; +import net.java.sip.communicator.service.customcontactactions.*; +import net.java.sip.communicator.service.protocol.*; +import net.java.sip.communicator.service.protocol.event.*; +import net.java.sip.communicator.util.*; +import org.jitsi.service.configuration.*; +import org.osgi.framework.*; + +import java.util.*; + +/** + * OSGi Activator for the Busy Lamp Field Plugin. + * + * @author Damian Minkov + */ +public class BLFActivator + implements BundleActivator, + ServiceListener, + BLFStatusListener +{ + /** + * The bundle context. + */ + static BundleContext bundleContext; + + /** + * Property to enable/disable this plugin. + */ + private static final String BLF_PLUGIN_ENABLED = + "net.java.sip.communicator.plugin.busylampfield.ENABLED"; + + /** + * The name of default group name if none is present. + */ + private static final String BLF_DEFAULT_GROUP_NAME = "Monitored Lines"; + + /** + * List of currently registered contact source services for the + * corresponding group. + */ + private Map> + currentBLFGroups = new LinkedHashMap + >(); + + /** + * Starts implementation. + * + * @param bundleContext + * @throws Exception + */ + @Override + public void start(BundleContext bundleContext) + throws Exception + { + ConfigurationService config = ServiceUtils.getService( + bundleContext, ConfigurationService.class); + + if(!config.getBoolean(BLF_PLUGIN_ENABLED, false)) + return; + + BLFActivator.bundleContext = bundleContext; + + bundleContext.addServiceListener(this); + + initProviders(); + + bundleContext.registerService( + CustomContactActionsService.class.getName(), + new CustomActionsBLFSourceContact(), + null + ); + } + + /** + * Stops. + * @param bundleContext + * @throws Exception + */ + @Override + public void stop(BundleContext bundleContext) + throws Exception + {} + + /** + * Listens for registered providers. + * @param serviceEvent + */ + @Override + public void serviceChanged(ServiceEvent serviceEvent) + { + ServiceReference serviceRef = serviceEvent.getServiceReference(); + + // if the event is caused by a bundle being stopped, we don't want to + // know + if(serviceRef.getBundle().getState() == Bundle.STOPPING) + return; + + Object service = bundleContext.getService(serviceRef); + + // we don't care if the source service is not a protocol provider + if(!(service instanceof ProtocolProviderService)) + return; + + switch(serviceEvent.getType()) + { + case ServiceEvent.REGISTERED: + handleProviderAdded((ProtocolProviderService) service); + break; + case ServiceEvent.UNREGISTERING: + handleProviderRemoved((ProtocolProviderService) service); + break; + } + } + + /** + * Initializes all currently registered protocol providers that contain + * the desired operation set. + */ + private void initProviders() + { + for(ServiceReference serRef : + ServiceUtils.getServiceReferences( + bundleContext, ProtocolProviderService.class)) + { + handleProviderAdded(bundleContext.getService(serRef)); + } + } + + /** + * Adds a protocol provider, when such provider is registered. + * + * @param protocolProvider the ProtocolProviderService to add + */ + private void handleProviderAdded(ProtocolProviderService protocolProvider) + { + OperationSetTelephonyBLF opset = + protocolProvider.getOperationSet(OperationSetTelephonyBLF.class); + + if(opset == null) + return; + + opset.addStatusListener(this); + + for(OperationSetTelephonyBLF.Line line + : opset.getCurrentlyMonitoredLines()) + { + String groupName = line.getGroup(); + if(groupName == null) + groupName = BLF_DEFAULT_GROUP_NAME; + + ServiceRegistration serviceReg + = currentBLFGroups.get(groupName); + + if(serviceReg != null) + { + BLFContactSourceService css + = (BLFContactSourceService)bundleContext.getService( + serviceReg.getReference()); + css.addLine(line); + + continue; + } + else + { + BLFContactSourceService css + = new BLFContactSourceService( + groupName, currentBLFGroups.size() + 1); + + serviceReg = (ServiceRegistration) + bundleContext.registerService( + ContactSourceService.class.getName(), + css, + null); + currentBLFGroups.put(groupName, serviceReg); + + css.addLine(line); + } + } + } + + /** + * Removes a protocol provider from the list when unregistered. + * @param protocolProvider the ProtocolProviderService to remove + */ + private void handleProviderRemoved(ProtocolProviderService protocolProvider) + { + OperationSetTelephonyBLF opset = + protocolProvider.getOperationSet(OperationSetTelephonyBLF.class); + + if(opset == null) + return; + + opset.removeStatusListener(this); + + for(OperationSetTelephonyBLF.Line line + : opset.getCurrentlyMonitoredLines()) + { + String groupName = line.getGroup(); + if(groupName == null) + groupName = BLF_DEFAULT_GROUP_NAME; + + ServiceRegistration serviceReg + = currentBLFGroups.remove(groupName); + + if(serviceReg == null) + continue; + + serviceReg.unregister(); + } + } + + /** + * Called whenever a change occurs in the BLFStatus of one of the + * monitored lines that we have subscribed for. + * @param event the BLFStatusEvent describing the status change. + */ + @Override + public void blfStatusChanged(BLFStatusEvent event) + { + if(!(event.getSource() instanceof OperationSetTelephonyBLF.Line)) + return; + + OperationSetTelephonyBLF.Line line + = (OperationSetTelephonyBLF.Line)event.getSource(); + + String gr = line.getGroup(); + if(gr == null) + gr = BLF_DEFAULT_GROUP_NAME; + + ServiceRegistration serviceReg + = currentBLFGroups.get(gr); + + if(serviceReg == null) + return; + + BLFContactSourceService css + = (BLFContactSourceService)bundleContext.getService( + serviceReg.getReference()); + css.updateLineStatus(line, event.getType()); + } +} \ No newline at end of file diff --git a/src/net/java/sip/communicator/plugin/busylampfield/BLFContactQuery.java b/src/net/java/sip/communicator/plugin/busylampfield/BLFContactQuery.java new file mode 100644 index 000000000..ef0150a20 --- /dev/null +++ b/src/net/java/sip/communicator/plugin/busylampfield/BLFContactQuery.java @@ -0,0 +1,152 @@ +/* + * Jitsi, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.plugin.busylampfield; + +import net.java.sip.communicator.service.contactsource.*; +import net.java.sip.communicator.service.protocol.*; +import net.java.sip.communicator.service.protocol.event.*; + +import java.util.*; + +/** + * The query that will update lines. + * + * @author Damian Minkov + */ +public class BLFContactQuery + extends AbstractContactQuery +{ + /** + * The query string. + */ + private String queryString; + + /** + * The query result list. + */ + private final List results; + + /** + * Constructs new query. + * + * @param parentService the parent contact source service + * @param queryString the query string + * @param contactCount contacts to process, not used currently. + */ + public BLFContactQuery( + BLFContactSourceService parentService, + Collection monitoredLines, + String queryString, int contactCount) + { + super(parentService); + + this.queryString = queryString; + this.results = new ArrayList(); + for(OperationSetTelephonyBLF.Line line : monitoredLines) + { + addLine(line, false); + } + } + + /** + * Returns the query string. + * + * @return the query string + */ + @Override + public String getQueryString() + { + return queryString; + } + + /** + * Returns the list of query results. + * + * @return the list of query results + */ + @Override + public List getQueryResults() + { + return results; + } + + /** + * Starts this BLFContactQuery. + */ + @Override + public void start() + { + for(SourceContact sc : results) + { + fireContactReceived(sc, false); + } + } + + /** + * Adds new line to display. + * @param line to display status. + * @param fireEvent whether to fire events + */ + void addLine(OperationSetTelephonyBLF.Line line, boolean fireEvent) + { + for(SourceContact sc : results) + { + BLFSourceContact blfSC = (BLFSourceContact)sc; + + if(blfSC.getLine().equals(line)) + return; + } + + BLFSourceContact sc + = new BLFSourceContact(getContactSource(), line); + results.add(sc); + + if(fireEvent) + fireContactReceived(sc, false); + } + + /** + * Updates the source contact status. + * @param line + * @param status + */ + void updateLineStatus(OperationSetTelephonyBLF.Line line, int status) + { + for(SourceContact sc : results) + { + BLFSourceContact blfSC = (BLFSourceContact)sc; + if(blfSC.getLine().equals(line)) + { + blfSC.setPresenceStatus(getPresenceStatus(status)); + fireContactChanged(blfSC); + break; + } + } + } + + /** + * Maps BLFStatusEvent.type to BLFPresenceStatus. + * @param status the staus to map. + * @return the corresponding BLFPresenceStatus. + */ + private BLFPresenceStatus getPresenceStatus(int status) + { + switch(status) + { + case BLFStatusEvent.STATUS_BUSY: + return BLFPresenceStatus.BLF_BUSY; + case BLFStatusEvent.STATUS_OFFLINE: + return BLFPresenceStatus.BLF_OFFLINE; + case BLFStatusEvent.STATUS_RINGING: + return BLFPresenceStatus.BLF_RINGING; + case BLFStatusEvent.STATUS_FREE: + return BLFPresenceStatus.BLF_FREE; + default: + return null; + } + } +} diff --git a/src/net/java/sip/communicator/plugin/busylampfield/BLFContactSourceService.java b/src/net/java/sip/communicator/plugin/busylampfield/BLFContactSourceService.java new file mode 100644 index 000000000..264758c87 --- /dev/null +++ b/src/net/java/sip/communicator/plugin/busylampfield/BLFContactSourceService.java @@ -0,0 +1,158 @@ +/* + * Jitsi, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.plugin.busylampfield; + +import net.java.sip.communicator.service.contactsource.*; +import net.java.sip.communicator.service.protocol.*; +import net.java.sip.communicator.util.Logger; +import org.jitsi.util.*; + +import java.util.*; + +/** + * The contact source service to manage query and lines. + * + * @author Damian Minkov + */ +public class BLFContactSourceService + implements ContactSourceService +{ + /** + * The Logger used by the + * ConfCallsContactSource class for logging output. + */ + private static final Logger logger + = Logger.getLogger(BLFContactSourceService.class); + + /** + * Type of a recent messages source. + */ + public static final int BLF_TYPE = CONTACT_LIST_TYPE; + + + /** + * Constants to display name ContactSource. + */ + private final String displayName; + + /** + * The latest query. + */ + private BLFContactQuery ourContactQuery = null; + + /** + * The list of lines this service will handle. + */ + private Set monitoredLines + = new HashSet(); + + /** + * The current group index. + */ + private final int index; + + /** + * Constructs. + * @param displayName + */ + public BLFContactSourceService(String displayName, int index) + { + this.displayName = displayName; + this.index = index; + } + + /** + * Returns the identifier of this contact source. Some of the common + * identifiers are defined here (For example the CALL_HISTORY identifier + * should be returned by all call history implementations of this interface) + * @return the identifier of this contact source + */ + @Override + public int getType() + { + return BLF_TYPE; + } + + /** + * Returns a user-friendly string that identifies this contact source. + * @return the display name of this contact source + */ + @Override + public String getDisplayName() + { + return displayName; + } + + /** + * Queries this search source for the given queryString. + * @param queryString the string to search for + * @return the created query + */ + @Override + public ContactQuery createContactQuery(String queryString) + { + return createContactQuery(queryString, 20); + } + + /** + * Queries this search source for the given queryString. + * + * @param queryString the string to search for + * @param contactCount the maximum count of result contacts + * @return the created query + */ + @Override + public ContactQuery createContactQuery(String queryString, int contactCount) + { + if(!StringUtils.isNullOrEmpty(queryString)) + return null; + + if(ourContactQuery == null) + ourContactQuery = new BLFContactQuery( + this, monitoredLines, queryString, contactCount); + + return ourContactQuery; + } + + /** + * Returns the index of the contact source in the result list. + * + * @return the index of the contact source in the result list + */ + @Override + public int getIndex() + { + // shift it with 2 position (recent messages-0 and chat rooms-1), + // counting from 0 + return 1 + index; + } + + /** + * Adds new line to display. + * @param line to display status. + */ + void addLine(OperationSetTelephonyBLF.Line line) + { + monitoredLines.add(line); + + if(ourContactQuery != null) + ourContactQuery.addLine(line, true); + } + + /** + * Updates the source contact status. + * @param line + * @param status + */ + void updateLineStatus(OperationSetTelephonyBLF.Line line, int status) + { + if(ourContactQuery == null) + return; + + ourContactQuery.updateLineStatus(line, status); + } +} diff --git a/src/net/java/sip/communicator/plugin/busylampfield/BLFPresenceStatus.java b/src/net/java/sip/communicator/plugin/busylampfield/BLFPresenceStatus.java new file mode 100644 index 000000000..d448be720 --- /dev/null +++ b/src/net/java/sip/communicator/plugin/busylampfield/BLFPresenceStatus.java @@ -0,0 +1,77 @@ +/* + * Jitsi, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.plugin.busylampfield; + +import net.java.sip.communicator.service.protocol.*; + +/** + * The status to display for the contact srouces. + * @author Damian Minkov + */ +public class BLFPresenceStatus + extends PresenceStatus +{ + /** + * The Online status. Indicate that the line is available and free. + */ + public static final String AVAILABLE = "Available"; + + /** + * On The Phone Chat status. + * Indicates that the line is used. + */ + public static final String BUSY = "Busy"; + + /** + * Ringing status. + * Indicates that the line is currently ringing. + */ + public static final String RINGING = "On the phone"; + + /** + * Indicates an Offline status or status with 0 connectivity. + */ + public static final String OFFLINE = "Offline"; + + /** + * The Online status. Indicate that the line is free. + */ + public static final BLFPresenceStatus BLF_FREE = new BLFPresenceStatus( + 65, AVAILABLE); + + /** + * The Offline status. Indicates the line status retrieval + * is not available. + */ + public static final BLFPresenceStatus BLF_OFFLINE = new BLFPresenceStatus( + 0, OFFLINE); + + /** + * Indicates an On The Phone status. + */ + public static final BLFPresenceStatus BLF_BUSY = new BLFPresenceStatus( + 30, BUSY); + + /** + * Indicates Ringing status. + */ + public static final BLFPresenceStatus BLF_RINGING = new BLFPresenceStatus( + 31, RINGING); + + /** + * Creates an instance of BLFPresenceStatus with the + * specified parameters. + * + * @param status the connectivity level of the new presence status + * instance + * @param statusName the name of the presence status. + */ + private BLFPresenceStatus(int status, String statusName) + { + super(status, statusName); + } +} diff --git a/src/net/java/sip/communicator/plugin/busylampfield/BLFSourceContact.java b/src/net/java/sip/communicator/plugin/busylampfield/BLFSourceContact.java new file mode 100644 index 000000000..6ec3167c2 --- /dev/null +++ b/src/net/java/sip/communicator/plugin/busylampfield/BLFSourceContact.java @@ -0,0 +1,47 @@ +/* + * Jitsi, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.plugin.busylampfield; + +import net.java.sip.communicator.service.contactsource.*; +import net.java.sip.communicator.service.protocol.*; + +import java.util.*; + +/** + * The BLF source contact. + * @author Damian Minkov + */ +public class BLFSourceContact + extends GenericSourceContact +{ + private final OperationSetTelephonyBLF.Line line; + + /** + * Initializes a new AddrBookSourceContact instance. + * + * @param contactSource the ContactSourceService which is creating + * the new instance + */ + public BLFSourceContact(ContactSourceService contactSource, + OperationSetTelephonyBLF.Line line) + { + super(contactSource, + line.getName() != null ? line.getName() : line.getAddress(), + new ArrayList()); + + this.line = line; + } + + /** + * Returns the line displayed. + * @return + */ + public OperationSetTelephonyBLF.Line getLine() + { + return line; + } +} diff --git a/src/net/java/sip/communicator/plugin/busylampfield/CustomActionsBLFSourceContact.java b/src/net/java/sip/communicator/plugin/busylampfield/CustomActionsBLFSourceContact.java new file mode 100644 index 000000000..23edae9eb --- /dev/null +++ b/src/net/java/sip/communicator/plugin/busylampfield/CustomActionsBLFSourceContact.java @@ -0,0 +1,188 @@ +/* + * Jitsi, the OpenSource Java VoIP and Instant Messaging client. + * + * Distributable under LGPL license. + * See terms of license at gnu.org. + */ +package net.java.sip.communicator.plugin.busylampfield; + +import net.java.sip.communicator.service.contactsource.*; +import net.java.sip.communicator.service.customcontactactions.*; +import net.java.sip.communicator.service.protocol.*; +import net.java.sip.communicator.service.resources.*; +import net.java.sip.communicator.util.*; + +import java.util.*; + +/** + * Custom acction to show pickup call button. + * + * @author Damian Minkov + */ +public class CustomActionsBLFSourceContact + implements CustomContactActionsService +{ + /** + * Our logger. + */ + private final Logger logger = Logger.getLogger( + CustomActionsBLFSourceContact.class); + + /** + * List of actions. + */ + private final List> actionsList + = new LinkedList>(); + + public CustomActionsBLFSourceContact() + { + actionsList.add(new PickupAction()); + } + + /** + * Returns the template class that this service has been initialized with + * + * @return the template class + */ + @Override + public Class getContactSourceClass() + { + return SourceContact.class; + } + + /** + * Returns all custom actions defined by this service. + * + * @return an iterator over a list of ContactActions + */ + @Override + public Iterator> getCustomContactActions() + { + return actionsList.iterator(); + } + + /** + * Returns all custom actions menu items defined by this service. + * + * @return an iterator over a list of ContactActionMenuItems + */ + @Override + public Iterator> + getCustomContactActionsMenuItems() + { + return null; + } + + /** + * Action that represents pickup button. + */ + private class PickupAction + implements ContactAction + { + /** + * Invoked when an action occurs. + * + * @param actionSource the source of the action + * @param x the x coordinate of the action + * @param y the y coordinate of the action + */ + @Override + public void actionPerformed(final SourceContact actionSource, int x, int y) + throws + OperationFailedException + { + if(!(actionSource instanceof BLFSourceContact)) + return; + + new Thread(new Runnable() + { + public void run() + { + try + { + OperationSetTelephonyBLF.Line line + = ((BLFSourceContact)actionSource).getLine(); + OperationSetTelephonyBLF opset = + line.getProvider().getOperationSet( + OperationSetTelephonyBLF.class); + opset.pickup(line); + } + catch(Exception ex) + { + logger.error("Error picking up call", ex); + } + } + }).start(); + } + + /** + * The icon used by the UI to visualize this action. + * @return the button icon. + */ + @Override + public byte[] getIcon() + { + return ResourceManagementServiceUtils.getService( + BLFActivator.bundleContext).getImageInBytes( + "plugin.busylampfield.PICKUP_CALL"); + } + + /** + * The icon used by the UI to visualize this action. + * @return the button icon. + */ + @Override + public byte[] getRolloverIcon() + { + return ResourceManagementServiceUtils.getService( + BLFActivator.bundleContext).getImageInBytes( + "plugin.busylampfield.PICKUP_CALL_ROLLOVER"); + } + + /** + * The icon used by the UI to visualize this action. + * @return the button icon. + */ + @Override + public byte[] getPressedIcon() + { + return ResourceManagementServiceUtils.getService( + BLFActivator.bundleContext).getImageInBytes( + "plugin.busylampfield.PICKUP_CALL_PRESSED"); + } + + /** + * Returns the tool tip text of the component to create for this contact + * action. + * + * @return the tool tip text of the component to create for this contact + * action + */ + @Override + public String getToolTipText() + { + return ResourceManagementServiceUtils.getService( + BLFActivator.bundleContext).getI18NString( + "plugin.busylampfield.PICKUP"); + } + + /** + * Indicates if this action is visible for the + * given actionSource. + * + * @param actionSource the action source for which we're verifying the + * action. + * @return true if the action should be visible for the given + * actionSource, false - otherwise + */ + @Override + public boolean isVisible(SourceContact actionSource) + { + if(actionSource.getPresenceStatus() + .equals(BLFPresenceStatus.BLF_RINGING)) + return true; + else + return false; + } + } +} \ No newline at end of file diff --git a/src/net/java/sip/communicator/plugin/busylampfield/busylampfield.manifest.mf b/src/net/java/sip/communicator/plugin/busylampfield/busylampfield.manifest.mf new file mode 100644 index 000000000..91f2de6d3 --- /dev/null +++ b/src/net/java/sip/communicator/plugin/busylampfield/busylampfield.manifest.mf @@ -0,0 +1,14 @@ +Bundle-Activator: net.java.sip.communicator.plugin.busylampfield.BLFActivator +Bundle-Name: Busy Lamp Field Plugin +Bundle-Description: Contact Sources that show and control BLF operation sets +Bundle-Vendor: jitsi.org +Bundle-Version: 0.0.1 +Bundle-SymbolicName: net.java.sip.communicator.plugin.busylampfield +Import-Package: org.osgi.framework, + org.jitsi.service.configuration, + net.java.sip.communicator.service.contactsource, + net.java.sip.communicator.service.customcontactactions, + net.java.sip.communicator.service.protocol, + net.java.sip.communicator.service.protocol.event, + net.java.sip.communicator.service.resources, org.jitsi.service.resources, + net.java.sip.communicator.util, org.jitsi.util