/**
     * The method is called by a ProtocolProvider implementation whenever a change in the
     * registration state of the corresponding provider had occurred.
     *
     * @param evt ProviderStatusChangeEvent the event describing the status change.
     */
    public void registrationStateChanged(RegistrationStateChangeEvent evt) {
      if (logger.isDebugEnabled())
        logger.debug(
            "The provider changed state from: " + evt.getOldState() + " to: " + evt.getNewState());

      if (evt.getNewState() == RegistrationState.REGISTERED) {
        AimConnection aimConnection = icqProvider.getAimConnection();
        aimConnection
            .getIcbmService()
            .getRvConnectionManager()
            .addConnectionManagerListener(OperationSetFileTransferIcqImpl.this);
      }
    }
Exemple #2
0
  @Override
  public void sendMessage(final FriendMessage message) {

    HashMap<String, Friend> friends = AccountManager.getInstance().getFriends();
    Friend friend = friends.get(message.getTo());
    Screenname buddy = new Screenname(friend.getUserName());
    Conversation c = (Conversation) friend.getUserInfo();
    if (c == null) {
      c = connection.getIcbmService().getImConversation(buddy);
      friend.setUserInfo(c);
    }
    Message oscarMessage =
        new Message() {

          public boolean isAutoResponse() {
            return false;
          }

          public String getMessageBody() {
            return message.getMessage();
          }
        };
    c.sendMessage(oscarMessage);
    Friend recipient = friends.get(message.getTo());
    accountListener.didReceiveMessageForFriend(message, recipient);
  }
  /**
   * Sends a file transfer request to the given <tt>toContact</tt> by specifying the local and
   * remote file path and the <tt>fromContact</tt>, sending the file.
   *
   * @param toContact the contact that should receive the file
   * @param file the file to send
   * @return the transfer object
   * @throws IllegalStateException if the protocol provider is not registered or connected
   * @throws IllegalArgumentException if some of the arguments doesn't fit the protocol requirements
   */
  public FileTransfer sendFile(Contact toContact, File file)
      throws IllegalStateException, IllegalArgumentException {
    assertConnected();

    if (file.length() > getMaximumFileLength())
      throw new IllegalArgumentException("File length exceeds the allowed one for this protocol");

    // Get the aim connection
    AimConnection aimConnection = icqProvider.getAimConnection();

    // Create an outgoing file transfer instance
    OutgoingFileTransfer outgoingFileTransfer =
        aimConnection
            .getIcbmService()
            .getRvConnectionManager()
            .createOutgoingFileTransfer(new Screenname(toContact.getAddress()));

    String id =
        String.valueOf(outgoingFileTransfer.getRvSessionInfo().getRvSession().getRvSessionId());

    FileTransferImpl outFileTransfer =
        new FileTransferImpl(outgoingFileTransfer, id, toContact, file, FileTransfer.OUT);

    // Adding the file to the outgoing file transfer
    try {
      outgoingFileTransfer.setSingleFile(new File(file.getPath()));
    } catch (IOException e) {
      if (logger.isDebugEnabled()) logger.debug("Error sending file", e);
      return null;
    }

    // Notify all interested listeners that a file transfer has been
    // created.
    FileTransferCreatedEvent event = new FileTransferCreatedEvent(outFileTransfer, new Date());

    fireFileTransferCreated(event);

    // Sending the file
    outgoingFileTransfer.sendRequest(new InvitationMessage(""));

    outFileTransfer.fireStatusChangeEvent(FileTransferStatusChangeEvent.PREPARING);

    return outFileTransfer;
  }
Exemple #4
0
  @Override
  public boolean connect(AccountLoginListener loginListener) {
    Screenname name = new Screenname(this.getUserName());
    AimConnectionProperties props = new AimConnectionProperties(name, this.getPassword());
    try {
      File dir = Util.getInstance().activity.getDir("aimconfig", Context.MODE_PRIVATE);
      DAppSession sess = new DAppSession(new File(dir.getAbsolutePath(), ".dolca"));
      sess.setSavePrefsOnExit(true);
      aimSession = (DAimAppSession) sess.openAimSession(name);
      connection = aimSession.openConnection(props);

      connection.addStateListener(connStateListener);
      //			connection.addOpenedServiceListener(new OpenedServiceListener() {
      //
      //				public void openedServices(AimConnection conn,
      //						Collection<? extends Service> services) {
      //					// TODO Auto-generated method stub
      //
      //				}
      //
      //				public void closedServices(AimConnection conn,
      //						Collection<? extends Service> services) {
      //					// TODO Auto-generated method stub
      //
      //				}
      //			})

      connection.connect();
      this.loginListener = loginListener;

    } catch (Exception e) {
      String errorMessage = e.getLocalizedMessage();
      loginListener.loginDidFailedWithError(errorMessage != null ? errorMessage : e.toString());
      return false;
    }
    return true;
  }
Exemple #5
0
    public void handleStateChange(StateEvent event) {
      AimConnection conn = event.getAimConnection();
      if (aimSession == null || conn != aimSession.getConnection()) {
        return;
      }

      State state = event.getNewState();

      if (state == State.FAILED) {
        if (AIMAccount.this.loginListener != null) {
          AIMAccount.this.loginListener.loginDidFailedWithError(
              "Failed to connect to '" + AIMAccount.this.getUserName() + "' account");
          AIMAccount.this.loginListener = null;
        }
      }

      if (state == State.ONLINE) {
        if (AIMAccount.this.loginListener != null) {
          AIMAccount.this.loginListener.loginDidSucceeded();
          AIMAccount.this.loginListener = null;
        }

        isOnline = true;
        IcbmService icbmservice = conn.getIcbmService();
        icbmservice.addIcbmListener(
            new IcbmListener() {

              public void buddyInfoUpdated(
                  IcbmService service, Screenname buddy, IcbmBuddyInfo info) {}

              public void newConversation(IcbmService service, Conversation conv) {
                conv.addConversationListener(
                    new ConversationListener() {

                      public void sentOtherEvent(
                          Conversation conversation, ConversationEventInfo event) {
                        // TODO Auto-generated method stub

                      }

                      public void sentMessage(Conversation c, MessageInfo minfo) {
                        // TODO Auto-generated method stub

                      }

                      public void gotOtherEvent(
                          Conversation conversation, ConversationEventInfo event) {
                        // TODO Auto-generated method stub

                      }

                      public void gotMessage(Conversation c, MessageInfo minfo) {
                        Friend friend = getFriendFromBuddy(minfo.getFrom(), false);
                        HashMap<String, Friend> friends = AccountManager.getInstance().getFriends();
                        Friend existingFriend = friends.get(friend.getUniqueDescriptior());
                        existingFriend.setUserInfo(c);
                        Spanned messageText = Html.fromHtml(minfo.getMessage().getMessageBody());
                        FriendMessage friendMessage =
                            new FriendMessage(
                                existingFriend.getUniqueDescriptior(),
                                AIMAccount.this.getUserName(),
                                messageText.toString(),
                                false);
                        accountListener.didReceiveMessageForFriend(friendMessage, existingFriend);
                      }

                      public void conversationOpened(Conversation c) {
                        // TODO Auto-generated method stub

                      }

                      public void conversationClosed(Conversation c) {
                        Friend friend = getFriendFromBuddy(c.getBuddy(), false);
                        HashMap<String, Friend> friends = AccountManager.getInstance().getFriends();
                        Friend existingFriend = friends.get(friend.getUniqueDescriptior());
                        existingFriend.setUserInfo(null);
                      }

                      public void canSendMessageChanged(Conversation c, boolean canSend) {
                        // TODO Auto-generated method stub

                      }
                    });
              }

              public void sendAutomaticallyFailed(
                  IcbmService service, Message message, Set<Conversation> triedConversations) {
                // TODO Auto-generated method stub

              }
            });

        connection
            .getBuddyInfoManager()
            .addGlobalBuddyInfoListener(
                new GlobalBuddyInfoListener() {

                  @Override
                  public void receivedStatusUpdate(
                      BuddyInfoManager manager, Screenname buddy, BuddyInfo info) {}

                  @Override
                  public void newBuddyInfo(
                      BuddyInfoManager manager, Screenname buddy, BuddyInfo info) {
                    Friend friend = getFriendFromBuddy(buddy, false);
                    HashMap<String, Friend> friends = AccountManager.getInstance().getFriends();
                    Friend existingFriend = friends.get(friend.getUniqueDescriptior());
                    if (existingFriend != null) {
                      ByteBlock iconData = info.getIconData();
                      if (iconData != null) {
                        Bitmap bitmap =
                            BitmapFactory.decodeByteArray(
                                iconData.toByteArray(), 0, iconData.getLength());
                        if (bitmap != null) {
                          existingFriend.setAvatar(bitmap);
                        }
                      }
                      applyInfoToFriendFromBuddyInfo(existingFriend, info);
                      accountListener.friendStatusDidChange(existingFriend);
                    }
                  }

                  @Override
                  public void buddyInfoChanged(
                      BuddyInfoManager manager,
                      Screenname buddy,
                      BuddyInfo info,
                      PropertyChangeEvent event) {
                    Friend friend = getFriendFromBuddy(buddy, false);
                    HashMap<String, Friend> friends = AccountManager.getInstance().getFriends();
                    Friend existingFriend = friends.get(friend.getUniqueDescriptior());

                    if (existingFriend != null) {
                      ByteBlock iconData = info.getIconData();
                      if (iconData != null) {
                        Bitmap bitmap =
                            BitmapFactory.decodeByteArray(
                                iconData.toByteArray(), 0, iconData.getLength());
                        if (bitmap != null) {
                          existingFriend.setAvatar(bitmap);
                        }
                      }
                      applyInfoToFriendFromBuddyInfo(existingFriend, info);
                      accountListener.friendStatusDidChange(existingFriend);
                    }
                  }
                });

        connection
            .getInfoService()
            .addInfoListener(
                new InfoServiceListener() {

                  @Override
                  public void handleUserProfile(
                      InfoService service, Screenname buddy, String userInfo) {
                    Friend friend = getFriendFromBuddy(buddy, false);
                    HashMap<String, Friend> friends = AccountManager.getInstance().getFriends();
                    Friend existingFriend = friends.get(friend.getUniqueDescriptior());
                    existingFriend.setName(userInfo);
                  }

                  @Override
                  public void handleInvalidCertificates(
                      InfoService service,
                      Screenname buddy,
                      CertificateInfo origCertInfo,
                      Throwable ex) {}

                  @Override
                  public void handleDirectoryInfo(
                      InfoService service, Screenname buddy, DirInfo dirInfo) {
                    Friend friend = getFriendFromBuddy(buddy, false);
                    HashMap<String, Friend> friends = AccountManager.getInstance().getFriends();
                    Friend existingFriend = friends.get(friend.getUniqueDescriptior());

                    if (dirInfo != null) {
                      String firstName = dirInfo.getFirstname();
                      String nick = dirInfo.getNickname();
                      String lastName = dirInfo.getLastname();
                      String fullName =
                          firstName != null ? firstName : "" + lastName != null ? lastName : "";
                      if (fullName != null && fullName.length() > 0) {
                        existingFriend.setName(fullName);
                      } else if (nick != null && nick.length() > 0) {
                        existingFriend.setName(nick);
                      }
                    }
                  }

                  @Override
                  public void handleCertificateInfo(
                      InfoService service, Screenname buddy, BuddyCertificateInfo certInfo) {}

                  @Override
                  public void handleAwayMessage(
                      InfoService service, Screenname buddy, String awayMessage) {}
                });

        conn.getChatRoomManager()
            .addListener(
                new ChatRoomManagerListener() {

                  public void handleInvitation(
                      ChatRoomManager chatRoomManager, ChatInvitation ourInvitation) {}
                });

        BuddyService buddyService = conn.getBuddyService();
        buddyService.addBuddyListener(
            new BuddyServiceListener() {

              public void buddyOffline(BuddyService service, Screenname buddy) {
                synchronized (AIMAccount.this) {
                  Friend friend = getFriendFromBuddy(buddy, false);
                  friend.setIsAvailable(false);
                  HashMap<String, Friend> friends = AccountManager.getInstance().getFriends();
                  Friend existingFriend = friends.get(friend.getUniqueDescriptior());
                  if (existingFriend == null) {
                    existingFriend = friend;
                    accountListener.didAddFriend(existingFriend);
                  } else {
                    accountListener.friendStatusDidChange(existingFriend);
                  }
                }
              }

              public void gotBuddyStatus(
                  BuddyService service, Screenname buddy, FullUserInfo info) {
                synchronized (AIMAccount.this) {
                  Friend friend = getFriendFromBuddy(buddy, false);
                  HashMap<String, Friend> friends = AccountManager.getInstance().getFriends();
                  Friend existingFriend = friends.get(friend.getUniqueDescriptior());
                  if (existingFriend == null) {
                    existingFriend = friend;
                    accountListener.didAddFriend(existingFriend);
                  }
                  applyInfoToFriend(existingFriend, info);
                  accountListener.friendStatusDidChange(existingFriend);
                }
              }
            });
      } else {
        disconnect();
      }
    }