コード例 #1
0
  void login() {
    try {
      logoutBtn.setEnabled(true);
      contactList.setEditable(false);
      loginBtn.setEnabled(false);
      loginId.setEnabled(false);
      password.setEnabled(false);

      //
      plugin.login(
          getMyLoginId(), password.getText(), getContactList(), MessagingNetwork.STATUS_ONLINE);
      logoutBtn.setEnabled(true);
    } catch (Throwable tr) {
      printException(tr);
      boolean loggedIn = false;
      try {
        loggedIn = plugin.getClientStatus(getMyLoginId()) != MessagingNetwork.STATUS_OFFLINE;
      } catch (Throwable tr2) {
        printException(tr2);
      }
      if (!loggedIn) {
        enableLoginUI();
      }
    }
  }
コード例 #2
0
 void logout() {
   try {
     //
     plugin.logout(getMyLoginId());
   } catch (Throwable tr) {
     printException(tr);
   }
   enableLoginUI();
 }
コード例 #3
0
  void sendContacts() {
    try {
      int n = (int) (7 * Math.random());
      if (n < 1) n = 2;

      String[] nicks = new String[n];
      String[] loginIds = new String[n];

      int i = 0;
      while (i < n) {
        nicks[i] = "random uin #" + i;
        loginIds[i] = "" + (22222 + (int) (10000000 * Math.random()));
        i++;
      }
      plugin.sendContacts(getMyLoginId(), contactListEntry.getText(), nicks, loginIds);
    } catch (Exception ex) {
      printException(ex);
    }
  }
コード例 #4
0
 void fetchUserDetails() {
   try {
     UserDetails d = plugin.getUserDetails(getMyLoginId(), contactListEntry.getText());
     String s =
         getMyLoginId()
             + " reports: user details for "
             + contactListEntry.getText()
             + " are:\r\n  nick="
             + StringUtil.toPrintableString(d.getNick())
             + ",\r\n  real name="
             + StringUtil.toPrintableString(d.getRealName())
             + ",\r\n  email="
             + StringUtil.toPrintableString(d.getEmail())
             + ".";
     CAT.info(s);
     log(s);
   } catch (Exception ex) {
     printException(ex);
   }
 }
コード例 #5
0
  public void run() {
    try {
      // start logging in
      plugin.addMessagingNetworkListener(
          new MessagingNetworkListener() {
            public void messageReceived(byte networkId, String from, String to, String text) {
              CAT.info(
                  "incoming message from "
                      + from
                      + " to "
                      + to
                      + " (len: "
                      + text.length()
                      + "):\r\n\""
                      + text
                      + "\"");
              log(
                  "incoming message from "
                      + from
                      + " to "
                      + to
                      + (text == null
                          ? ": null (BUGGG!!)"
                          : " (" + text.length() + " chars):\r\n\"" + text + "\""));
            }

            public void contactsReceived(
                byte networkId,
                String from,
                String to,
                String[] contactsUins,
                String[] contactsNicks) {
              StringBuffer sb =
                  new StringBuffer(
                      "incoming contacts from "
                          + from
                          + " to "
                          + to
                          + ", number of contacts="
                          + contactsNicks.length
                          + ":\r\n");
              int i = 0;
              while (i < contactsNicks.length) {
                sb.append(
                    "  nick="
                        + StringUtil.toPrintableString(contactsNicks[i])
                        + "\r\n"
                        + "  uin ="
                        + StringUtil.toPrintableString(contactsUins[i])
                        + "\r\n");
                i++;
              }
              String s = sb.toString();
              CAT.info(s);
              log(s);
            }

            public void statusChanged(
                byte networkId,
                String srcLoginId,
                String dstLoginId,
                int status,
                int reasonCategory,
                String reasonMessage) {
              String status_s = "invalid: " + status + " (BUGGG!)";
              switch (status) {
                case MessagingNetwork.STATUS_OFFLINE:
                  status_s = "offline";
                  break;
                case MessagingNetwork.STATUS_ONLINE:
                  status_s = "online";
                  break;
                case MessagingNetwork.STATUS_BUSY:
                  status_s = "busy";
                  break;
              }
              if (srcLoginId.equals(dstLoginId))
                log(
                    srcLoginId
                        + " changed its client status to "
                        + status_s
                        + " ["
                        + (reasonMessage == null ? "no reason given" : "reason: " + reasonMessage)
                        + "]");
              else log(srcLoginId + " reports: " + dstLoginId + " changed status to " + status_s);
              // java.awt.Toolkit.getDefaultToolkit().beep();
              if (getMyLoginId().equals(srcLoginId) && srcLoginId.equals(dstLoginId)) {
                switch (status) {
                  case MessagingNetwork.STATUS_OFFLINE:
                    clientStatus.select("Offline");
                    enableLoginUI();
                    break;
                  case MessagingNetwork.STATUS_ONLINE:
                    clientStatus.select("Online");
                    break;
                  case MessagingNetwork.STATUS_BUSY:
                    clientStatus.select("Busy");
                    break;
                }
              }
            }
          });
      login();
      thread = null;
    } catch (Throwable tr) {
      printException(tr);
    }
  }