1 | package nu.fw.jeti.jabber.elements; |
---|
2 | |
---|
3 | import java.text.DateFormat; |
---|
4 | import java.text.MessageFormat; |
---|
5 | import java.util.Calendar; |
---|
6 | |
---|
7 | import javax.swing.JOptionPane; |
---|
8 | |
---|
9 | import nu.fw.jeti.jabber.Backend; |
---|
10 | import nu.fw.jeti.util.I18N; |
---|
11 | import nu.fw.jeti.util.Popups; |
---|
12 | |
---|
13 | /** |
---|
14 | * @author E.S. de Boer |
---|
15 | * |
---|
16 | * |
---|
17 | */ |
---|
18 | public class IQLast extends Extension implements IQExtension |
---|
19 | { |
---|
20 | private String seconds; |
---|
21 | |
---|
22 | public IQLast(){} |
---|
23 | |
---|
24 | public IQLast(String seconds) |
---|
25 | { |
---|
26 | this.seconds = seconds; |
---|
27 | } |
---|
28 | |
---|
29 | public String getSeconds(){return seconds;} |
---|
30 | |
---|
31 | public void execute(InfoQuery iq,Backend backend) |
---|
32 | { |
---|
33 | if (iq.getType().equals("get")) |
---|
34 | { |
---|
35 | //TODO idle time?? |
---|
36 | //sendTime(infoQuery.getFrom(),infoQuery.getID()); |
---|
37 | } |
---|
38 | else if (iq.getType().equals("result")) |
---|
39 | { |
---|
40 | lastSeenPopup(iq.getFrom().toStringNoResource(), getSeconds()); |
---|
41 | } |
---|
42 | else if (iq.getType().equals("error")) |
---|
43 | { |
---|
44 | Popups.errorPopup(iq.getErrorDescription(), I18N.gettext("main.error.Last_Seen_Error")); |
---|
45 | } |
---|
46 | } |
---|
47 | |
---|
48 | private void lastSeenPopup(String jid,String seconds) |
---|
49 | { |
---|
50 | int second = 0; |
---|
51 | try{ |
---|
52 | second = Integer.parseInt(seconds); |
---|
53 | } |
---|
54 | catch (NumberFormatException e) |
---|
55 | { |
---|
56 | Popups.popup(MessageFormat.format(I18N.gettext("main.popup.{0}_was_last_seen_{1}_seconds_ago"),new Object[]{jid,seconds}) ,"main.popup.Last_Seen",JOptionPane.INFORMATION_MESSAGE); |
---|
57 | } |
---|
58 | Calendar calendar = Calendar.getInstance(); |
---|
59 | //calendar.clear(); |
---|
60 | calendar.add(Calendar.SECOND,-second); |
---|
61 | |
---|
62 | DateFormat dateFormat = DateFormat.getDateTimeInstance(); |
---|
63 | Popups.popup(MessageFormat.format(I18N.gettext("main.popup.{0}_was_last_seen_on_{1}"),new Object[]{jid, dateFormat.format(calendar.getTime())}),I18N.gettext("main.popup.Last_Seen"),JOptionPane.INFORMATION_MESSAGE); |
---|
64 | //JOptionPane.showMessageDialog(main,display +"\n Time: " + time + "\n Timezone: " + timezone ,jid + "Time",javax.swing.JOptionPane.INFORMATION_MESSAGE); |
---|
65 | |
---|
66 | } |
---|
67 | |
---|
68 | public void appendToXML(StringBuffer xml) |
---|
69 | { |
---|
70 | xml.append("<query xmlns=\"jabber:iq:last\""); |
---|
71 | appendAttribute(xml,"seconds",seconds); |
---|
72 | xml.append("/>"); |
---|
73 | } |
---|
74 | } |
---|
75 | /* |
---|
76 | * Overrides for emacs |
---|
77 | * Local variables: |
---|
78 | * tab-width: 4 |
---|
79 | * End: |
---|
80 | */ |
---|