void eventNotify() {
   int event = -1;
   synchronized (taskList) {
     for (Enumeration e = taskList.elements(); e.hasMoreElements(); ) {
       TransferTask t = (TransferTask) e.nextElement();
       if (t.showEvent) event = t.getImageIndex();
     }
   }
   Integer icon = (event < 0) ? null : new Integer(event);
   StaticData.getInstance().roster.setEventIcon(icon);
 }
  public int blockArrived(JabberDataBlock data) {
    if (data instanceof Iq) {
      String id = data.getAttribute("id");

      JabberDataBlock si = data.getChildBlock("si");
      if (si != null) {
        // stream initiating
        String sid = si.getAttribute("id");

        JabberDataBlock file = si.getChildBlock("file");
        JabberDataBlock feature = si.getChildBlock("feature");

        String type = data.getTypeAttribute();
        if (type.equals("set")) {
          // sender initiates file sending process
          TransferTask task =
              new TransferTask(
                  data.getAttribute("from"),
                  id,
                  sid,
                  file.getAttribute("name"),
                  file.getChildBlockText("desc"),
                  Integer.parseInt(file.getAttribute("size")),
                  null);

          synchronized (taskList) {
            taskList.addElement(task);
          }

          eventNotify();
          StaticData.getInstance().roster.playNotify(0);
          return BLOCK_PROCESSED;
        }
        if (type.equals("result")) {
          // our file were accepted
          TransferTask task = getTransferBySid(id);
          task.initIBB();

          eventNotify();
          return BLOCK_PROCESSED;
        }
      }
      JabberDataBlock open = data.getChildBlock("open");
      if (open != null) {
        String sid = open.getAttribute("sid");
        TransferTask task = getTransferBySid(sid);

        JabberDataBlock accept = new Iq(task.jid, Iq.TYPE_RESULT, id);
        send(accept, true);
        eventNotify();
        return BLOCK_PROCESSED;
      }
      JabberDataBlock close = data.getChildBlock("close");
      if (close != null) {
        String sid = close.getAttribute("sid");
        TransferTask task = getTransferBySid(sid);

        JabberDataBlock done = new Iq(task.jid, Iq.TYPE_RESULT, id);
        send(done, true);
        task.closeFile();
        eventNotify();
        return BLOCK_PROCESSED;
      }
      if (data.getTypeAttribute().equals("result")) {
        TransferTask task = getTransferBySid(id);
        if (task != null) {
          task.startTransfer();
        }
      }
      if (data.getTypeAttribute().equals("error")) {
        TransferTask task = getTransferBySid(id);
        if (task != null) {
          task.cancel();
        }
      }
    }
    if (data instanceof Message) {
      JabberDataBlock bdata = data.getChildBlock("data");
      if (bdata == null) return BLOCK_REJECTED;
      if (!bdata.isJabberNameSpace("http://jabber.org/protocol/ibb")) return BLOCK_REJECTED;
      String sid = bdata.getAttribute("sid");
      TransferTask task = getTransferBySid(sid);

      byte b[] = strconv.fromBase64(bdata.getText());
      System.out.println("data chunk received");
      repaintNotify();
      task.writeFile(b);
    }
    return BLOCK_REJECTED;
  }
 void sendFile(TransferTask task) {
   synchronized (taskList) {
     taskList.addElement(task);
   }
   task.sendInit();
 }