source: trunk/hiptop/cognet++/org/twodot/cognet/Cognet.java

Last change on this file was 210, checked in by Nicholas Riley, 19 years ago

cognet++: Brian Swetland et al.'s generic proxied hiptop chat client.
Requires cognetd to function.

File size: 4.8 KB
Line 
1/*
2 * cognet chat app
3 *
4 * Copyright 2003, Brian Swetland <swetland@frotz.net>
5 * See LICENSE for redistribution terms
6 *
7 */
8package org.twodot.cognet;
9
10import danger.app.Application;
11import danger.app.Timer;
12import danger.ui.Menu;
13import danger.ui.MenuItem;
14import danger.ui.Bitmap;
15import danger.app.Event;
16import danger.app.EventType;
17import danger.app.SettingsDB;
18import danger.ui.NotificationManager;
19import danger.util.DEBUG;
20
21public class Cognet extends Application implements Resources
22{
23 public Cognet() {
24
25 timer = new Timer(300*1000); // 5 minutes;
26
27 bm_plain = getBitmap(kBlank);
28 bm_mail = getBitmap(kMarker);
29 bm_tag = getBitmap(kTag);
30 bm_notify = getBitmap(kPending);
31
32 try {
33 NotificationManager.registerPendingIcon("cognet", getBitmap(kPending), getBitmap(kPending));
34 } catch (Throwable t){
35 System.out.println(t.getMessage());
36 }
37
38 cogSettings = new SettingsDB("prefs");
39
40 DEBUG.p("cognet: setReceiveConnectivityEvents(true");
41 setReceiveConnectivityEvents(true);
42 }
43
44 void Notify() {
45 synchronized (this) {
46 //System.err.println("cognet: notify");
47 if(!fgapp&&doActivity)
48 NotificationManager.setPendingIconVisible("cognet", true);
49 }
50 }
51
52 public void resume() {
53 timer.stop();
54
55 if(engine == null) {
56 engine = new Engine(this);
57 }
58 synchronized (this) {
59 fgapp = true;
60 System.err.println("cognet: no notify");
61 NotificationManager.setPendingIconVisible("cognet", false);
62 engine.sendResume();
63 }
64 }
65
66 public void quit() {
67 try {
68 synchronized (this) {
69 fgapp = true;
70 System.err.println("cognet: no notify");
71 NotificationManager.setPendingIconVisible("cognet", false);
72 }
73 engine.logout();
74 } catch (Throwable t){
75 }
76 unload();
77 }
78
79 public void suspend() {
80 synchronized (this) {
81 fgapp = false;
82 timer.start();
83 }
84 }
85
86 public void MakeMenu(Menu a, ChatWindow w) {
87 MenuItem mi;
88
89 a.removeAllItems();
90 engine.AddWindows(a);
91
92 a.addDivider();
93
94 if( w != null )
95 {
96 Menu links;
97
98 links = w.links.makeLinkMenu(kURL);
99
100 if( links != null )
101 {
102 mi = a.addItem("Links");
103 mi.addSubMenu(links);
104 }
105
106 menuWindow = w;
107 }
108
109 Menu options = new Menu("Options");
110
111 mi = options.addItem("Icons and Smileys",kSmileys);
112 mi.setChecked(doSmileys);
113
114 mi = options.addItem("Activity Indicator",kActivity);
115 mi.setChecked(doActivity);
116
117 mi = options.addItem("Marquee", kMarquee);
118 mi.setChecked(doMarquee);
119
120 mi = options.addItem("Auto-Reconnect",kAutoConnect);
121 mi.setChecked(doAutoConnect);
122
123 mi = a.addItem("Options");
124 mi.addSubMenu(options);
125
126 if(w != null){
127 mi = a.addItem("Close Tab",kCloseWindow,0,w.key,this);
128 mi.setShortcut('.');
129 }
130 if(engine.state == Engine.ONLINE){
131 a.addItem("Disconnect",kDisconnect);
132 } else {
133 a.addItem("Connect",kConnect);
134 }
135
136 }
137
138 public boolean receiveEvent(Event e) {
139 if( (e.type >= kURL) && (e.type <= kURLend) )
140 {
141 menuWindow.links.dispatchLink(e.type,kURL);
142 return true;
143 }
144
145 switch(e.type){
146 case EventType.EVENT_ENTERING_KEY_GUARD:
147 timer.start();
148 return true;
149 case EventType.EVENT_TIMER:
150 engine.sendSuspend();
151 timer.stop();
152 return true;
153
154 case kGotoLogin:
155 engine.login.show();
156 return true;
157 case kGotoWindow:
158 engine.Select((String)e.argument,false);
159 return true;
160 case kCloseWindow:
161 engine.Close((String)e.argument);
162 return true;
163 case Event.EVENT_CONNECTION_UP:
164 engine.login.SendEvent(5040);
165 return true;
166 case kConnect:
167 engine.login();
168 return true;
169 case kDisconnect:
170 engine.logout();
171 return true;
172
173 case kSmileys:
174 doSmileys = !doSmileys;
175 savePrefs();
176 return true;
177
178 case kActivity:
179 doActivity = !doActivity;
180 savePrefs();
181 return true;
182
183 case kMarquee:
184 doMarquee = !doMarquee;
185 savePrefs();
186 return true;
187
188 case kAutoConnect:
189 doAutoConnect = !doAutoConnect;
190 savePrefs();
191 return true;
192
193 default:
194 return super.receiveEvent(e);
195 }
196 }
197
198 public void savePrefs()
199 {
200 cogSettings.setIntValue("doSmileys",doSmileys ? 1 : 0);
201 cogSettings.setIntValue("doActivity",doActivity ? 1 : 0);
202 cogSettings.setIntValue("doMarquee",doMarquee ? 1 : 0);
203 cogSettings.setIntValue("doAutoConnect",doAutoConnect ? 1 : 0);
204 }
205
206 static final int kGotoLogin = 1;
207 static final int kGotoWindow = 2;
208 static final int kCloseWindow = 3;
209 static final int kDisconnect = 4;
210 static final int kConnect = 5;
211 static final int kPrefs = 6;
212 static final int kLinks = 7;
213 static final int kSmileys = 8;
214 static final int kActivity = 9;
215 static final int kMarquee = 10;
216 static final int kAutoConnect = 11;
217
218 static final int kURL = 100;
219 static final int kURLend = kURL + LinkMenu.maxLinkTargets;
220
221 ChatWindow menuWindow;
222
223 Engine engine;
224
225 Timer timer;
226
227 Bitmap bm_plain;
228 Bitmap bm_mail;
229 Bitmap bm_tag;
230 Bitmap bm_notify;
231
232 SettingsDB cogSettings;
233
234 boolean fgapp;
235
236 boolean doActivity;
237 boolean doMarquee;
238 boolean doSmileys;
239 boolean doAutoConnect;
240}
Note: See TracBrowser for help on using the repository browser.