You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MSNFakeChannel.java 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. * Copyright (c) 2006-2013 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc.addons.parser_msn;
  23. import com.dmdirc.parser.common.BaseChannelInfo;
  24. import com.dmdirc.parser.common.ChannelListModeItem;
  25. import com.dmdirc.parser.interfaces.ChannelClientInfo;
  26. import com.dmdirc.parser.interfaces.ClientInfo;
  27. import com.dmdirc.parser.interfaces.Parser;
  28. import com.dmdirc.parser.interfaces.callbacks.ChannelNamesListener;
  29. import java.util.Collection;
  30. import java.util.Collections;
  31. /**
  32. * A 'fake' local channel used to display contact lists.
  33. */
  34. public class MSNFakeChannel extends BaseChannelInfo {
  35. /**
  36. * Creates a new fake channel belonging to the specified parser and
  37. * with the given name.
  38. *
  39. * @param parser The parser that owns this channel
  40. * @param name The name of the channel
  41. */
  42. public MSNFakeChannel(final Parser parser, final String name) {
  43. super(parser, name);
  44. }
  45. /** {@inheritDoc} */
  46. @Override
  47. public void setTopic(final String topic) {
  48. //Ignore
  49. }
  50. /** {@inheritDoc} */
  51. @Override
  52. public String getTopic() {
  53. return "";
  54. }
  55. /** {@inheritDoc} */
  56. @Override
  57. public long getTopicTime() {
  58. return 0;
  59. }
  60. /** {@inheritDoc} */
  61. @Override
  62. public String getTopicSetter() {
  63. return "";
  64. }
  65. /** {@inheritDoc} */
  66. @Override
  67. public String getModes() {
  68. return "";
  69. }
  70. /** {@inheritDoc} */
  71. @Override
  72. public String getMode(final char mode) {
  73. return "";
  74. }
  75. /** {@inheritDoc} */
  76. @Override
  77. public Collection<ChannelListModeItem> getListMode(final char mode) {
  78. return Collections.<ChannelListModeItem>emptyList();
  79. }
  80. /** {@inheritDoc} */
  81. @Override
  82. public void part(final String reason) {
  83. throw new UnsupportedOperationException("Not supported yet.");
  84. }
  85. /** {@inheritDoc} */
  86. @Override
  87. public void sendWho() {
  88. //Ignore
  89. }
  90. /** {@inheritDoc} */
  91. @Override
  92. public void alterMode(final boolean add,
  93. final Character mode, final String parameter) {
  94. //Ignore
  95. }
  96. /** {@inheritDoc} */
  97. @Override
  98. public void flushModes() {
  99. //Ignore
  100. }
  101. /** {@inheritDoc} */
  102. @Override
  103. public void requestListModes() {
  104. //Ignore
  105. }
  106. /** {@inheritDoc} */
  107. @Override
  108. public ChannelClientInfo getChannelClient(final ClientInfo client) {
  109. return getClient(client.getNickname());
  110. }
  111. /** {@inheritDoc} */
  112. @Override
  113. public ChannelClientInfo getChannelClient(final String client,
  114. final boolean create) {
  115. final String[] parts = getParser().parseHostmask(client);
  116. if (create && getClient(parts[0]) == null) {
  117. return new MSNChannelClientInfo(this, getParser().getClient(client));
  118. }
  119. return getClient(parts[0]);
  120. }
  121. /**
  122. * Replaces the clients in this channel with a the new list of clients.
  123. *
  124. * @param clients client list
  125. */
  126. public void replaceContacts(final Collection<ClientInfo> clients) {
  127. for (ChannelClientInfo client : getChannelClients()) {
  128. removeClient(client.getClient().getNickname());
  129. }
  130. for (ClientInfo client : clients) {
  131. addClient(client.getNickname(), new MSNChannelClientInfo(this,
  132. client));
  133. }
  134. getParser().getCallbackManager().getCallbackType(
  135. ChannelNamesListener.class).call(this);
  136. }
  137. /**
  138. * Adds the specified clients to this channel
  139. *
  140. * @param clients client list
  141. */
  142. public void addContacts(final Collection<ClientInfo> clients) {
  143. for (ClientInfo client : clients) {
  144. addClient(client.getNickname(), new MSNChannelClientInfo(this,
  145. client));
  146. }
  147. getParser().getCallbackManager().getCallbackType(
  148. ChannelNamesListener.class).call(this);
  149. }
  150. /**
  151. * Removes the specified clients from this channel
  152. *
  153. * @param clients client list
  154. */
  155. public void removeContacts(final Collection<ClientInfo> clients) {
  156. for (ClientInfo client : clients) {
  157. removeClient(client.getNickname());
  158. }
  159. getParser().getCallbackManager().getCallbackType(
  160. ChannelNamesListener.class).call(this);
  161. }
  162. }