[zephyrchat-cvs] zchat/zChat status-available.tiff,NONE,1.1 status-away.tiff,NONE,1.1 ZCChatWindowCo
Status: Alpha
Brought to you by:
akosut
Update of /cvsroot/zephyrchat/zchat/zChat
In directory sc8-pr-cvs1:/tmp/cvs-serv31571
Modified Files:
ZCChatWindowController.h ZChatAppController.h
ZChatAppController.mm ZChatFriendsController.h
ZChatFriendsController.mm
Added Files:
status-available.tiff status-away.tiff
Log Message:
Add partial status control (no custom status)
--- NEW FILE: status-available.tiff ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: status-away.tiff ---
(This appears to be a binary file; contents omitted.)
Index: ZCChatWindowController.h
===================================================================
RCS file: /cvsroot/zephyrchat/zchat/zChat/ZCChatWindowController.h,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- ZCChatWindowController.h 1 Apr 2003 15:18:39 -0000 1.15
+++ ZCChatWindowController.h 7 Apr 2003 20:37:33 -0000 1.16
@@ -81,8 +81,8 @@
* used to later remove completely the addition (with the exception of any added
* timestamp).
*/
-- (NSRange)appendMessage:(NSAttributedString *)message from:(NSString *)sender color:(NSColor *)bgColor
- textColor:(NSColor *)fgColor alignment:(NSTextAlignment)alignment;
+- (NSRange)appendMessage:(NSAttributedString *)message from:(NSString *)sender instance:(NSString *)instance
+ color:(NSColor *)bgColor textColor:(NSColor *)fgColor alignment:(NSTextAlignment)alignment;
- (NSAttributedString *)pingMessageWithColor:(NSColor *)textColor;
- (IBAction)sendMessage:(id)sender;
Index: ZChatAppController.h
===================================================================
RCS file: /cvsroot/zephyrchat/zchat/zChat/ZChatAppController.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- ZChatAppController.h 29 Mar 2003 19:21:38 -0000 1.14
+++ ZChatAppController.h 7 Apr 2003 20:37:33 -0000 1.15
@@ -44,11 +44,13 @@
- (IBAction)showFriendsWindow:(id)sender;
- (IBAction)connect:(id)sender;
+- (IBAction)connectWithTerminal:(NSString *)terminal;
- (IBAction)disconnect:(id)sender;
- (void)zephyrAbort:(zephyrlib::ZephyrStatus)status;
- (IBAction)zephyrHide:(id)sender;
- (IBAction)zephyrUnhide:(id)sender;
+- (void)setTerminal:(NSString *)status;
- (BOOL)validateMenuItem:(id <NSMenuItem>)menuItem;
Index: ZChatAppController.mm
===================================================================
RCS file: /cvsroot/zephyrchat/zchat/zChat/ZChatAppController.mm,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- ZChatAppController.mm 29 Mar 2003 19:21:38 -0000 1.17
+++ ZChatAppController.mm 7 Apr 2003 20:37:33 -0000 1.18
@@ -143,18 +143,25 @@
}
- (IBAction)zephyrHide:(id)sender {
- _mgr->SetTerminal("", new ZChatAppControllerUpdateCallback);
- _busy = true;
- [[NSNotificationCenter defaultCenter] postNotificationName:ZChatStatusNotification object:self];
+ [self setTerminal:@""];
}
- (IBAction)zephyrUnhide:(id)sender {
- _mgr->SetTerminal("Available", new ZChatAppControllerUpdateCallback);
+ [self setTerminal:[_friends defaultTerminal]];
+}
+
+- (void)setTerminal:(NSString *)status {
+ _mgr->SetTerminal([status stlString], new ZChatAppControllerUpdateCallback);
_busy = true;
[[NSNotificationCenter defaultCenter] postNotificationName:ZChatStatusNotification object:self];
}
+
- (IBAction)connect:(id)sender {
+ [self connectWithTerminal:[_friends defaultTerminal]];
+}
+
+- (IBAction)connectWithTerminal:(NSString *)terminal {
NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
delete _mgr;
@@ -169,7 +176,7 @@
NSLocalizedString(@"Cancel", nil), nil,
NSLocalizedString(@"Open Preferences", nil));
if (code == NSAlertOtherReturn) {
- [self showPrefsPanel:sender];
+ [self showPrefsPanel:nil];
}
return;
@@ -191,12 +198,11 @@
// calling the ZephyrMgr constructor (because we can pause/fail there)
_mgr = new ZephyrMgr(_otCtx, [[NSRunLoop currentRunLoop] getCFRunLoop],
- [server stlString],
- "Available",
- new ZChatAppControllerLoginCallback,
- new ZChatAppControllerMessageCallback,
- address);
-
+ [server stlString], [terminal stlString],
+ new ZChatAppControllerLoginCallback,
+ new ZChatAppControllerMessageCallback,
+ address);
+
[NSApp runModalForWindow:_progressPanel];
} catch (ZephyrStatus err) {
[self zephyrAbort:err];
@@ -584,6 +590,5 @@
return result;
}
-
@end
Index: ZChatFriendsController.h
===================================================================
RCS file: /cvsroot/zephyrchat/zchat/zChat/ZChatFriendsController.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- ZChatFriendsController.h 31 Mar 2003 17:07:21 -0000 1.14
+++ ZChatFriendsController.h 7 Apr 2003 20:37:33 -0000 1.15
@@ -40,17 +40,14 @@
- (NSArray *)friends;
- (NSArray *)selectedFriends;
+- (IBAction)changeStatus:(id)sender;
+
- (IBAction)newFriend:(id)sender;
- (IBAction)delete:(id)sender;
- (IBAction)chatFriend:(id)sender;
- (IBAction)emailFriend:(id)sender;
- (IBAction)infoFriend:(id)sender;
-- (void)_selectNotification:(NSNotification *)notification;
-- (void)_busyNotification:(NSNotification *)notification;
-
-- (void)_loginNotification:(NSNotification *)notification;
-- (void)_logoutNotification:(NSNotification *)notification;
-- (void)_statusNotification:(NSNotification *)notification;
+- (NSString *)defaultTerminal;
@end
Index: ZChatFriendsController.mm
===================================================================
RCS file: /cvsroot/zephyrchat/zchat/zChat/ZChatFriendsController.mm,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- ZChatFriendsController.mm 1 Apr 2003 17:41:00 -0000 1.19
+++ ZChatFriendsController.mm 7 Apr 2003 20:37:33 -0000 1.20
@@ -18,6 +18,17 @@
static const NSTimeInterval ZChatFriendTimeInterval = 60.0 * 5.0; // five minutes
+@interface ZChatFriendsController (ZChatFriendsControllerPrivateMethods)
+- (void)_updateStatusMenu;
+
+- (void)_selectNotification:(NSNotification *)notification;
+- (void)_busyNotification:(NSNotification *)notification;
+
+- (void)_loginNotification:(NSNotification *)notification;
+- (void)_logoutNotification:(NSNotification *)notification;
+- (void)_statusNotification:(NSNotification *)notification;
+@end
+
@implementation ZChatFriendsController
- (id)init {
@@ -79,10 +90,21 @@
[_busyIndicator setStyle:NSProgressIndicatorSpinningStyle];
[_busyIndicator setDisplayedWhenStopped:NO];
+
+ [[_statusMenu itemAtIndex:[_statusMenu indexOfItemWithTag:1]] setImage:
+ [NSImage imageNamed:@"status-available"]];
+ [[_statusMenu itemAtIndex:[_statusMenu indexOfItemWithTag:11]] setImage:
+ [NSImage imageNamed:@"status-available"]];
+ [[_statusMenu itemAtIndex:[_statusMenu indexOfItemWithTag:2]] setImage:
+ [NSImage imageNamed:@"status-away"]];
+ [[_statusMenu itemAtIndex:[_statusMenu indexOfItemWithTag:22]] setImage:
+ [NSImage imageNamed:@"status-away"]];
}
- (void)windowDidLoad {
[self reloadFriendViews];
+ [self _updateStatusMenu];
+ [_name setStringValue:[ZChatApp mySignature]];
}
/* This is a simplified and rewritten-from-scratch version of Camino's CHStackView, which is a simplified
@@ -126,11 +148,113 @@
[_data makeObjectsPerformSelector:@selector(reset)];
}
+- (void)_updateStatusMenu {
+ /* Status menu:
+ * - Available (tag 1)
+ * - <custom available> (tag 111)
+ * - Custom... (tag 11)
+ *
+ * - Away (tag 2)
+ * - <custom away> (tag 222)
+ * - Custom... (tag 22)
+ *
+ * Hidden (tag -2)
+ *
+ * Offline (tag -1)
+ */
+
+ if ([ZChatApp mgr] == nil) {
+ [_statusMenu selectItemAtIndex:[_statusMenu indexOfItemWithTag:-1]];
+ return;
+ }
+
+ if ([ZChatApp mgr]->GetTerminal().empty()) {
+ [_statusMenu selectItemAtIndex:[_statusMenu indexOfItemWithTag:-2]];
+ return;
+ }
+
+ NSString *status = [NSString stringWithSTLString:[ZChatApp mgr]->GetTerminal()];
+ bool away = [status characterAtIndex:0] == '-';
+
+ if ([status characterAtIndex:0] == '+' || [status characterAtIndex:0] == '-') {
+ status = [status substringFromIndex:1];
+ }
+
+ // Check for existing title
+ id <NSMenuItem> item = [_statusMenu itemWithTitle:status];
+ if (item != NULL) {
+ if ([item tag] == away ? 2 : 1 || [item tag] == away ? 222 : 111) {
+ [_statusMenu selectItem:item];
+ return;
+ }
+ }
+
+ // Add a custom title
+ item = [_statusMenu itemAtIndex:[_statusMenu indexOfItemWithTag:away ? 2 : 1]];
+ int index = 1 + [_statusMenu indexOfItem:item];
+
+ [_statusMenu insertItemWithTitle:status atIndex:index];
+ [[_statusMenu itemAtIndex:index] setTag:away ? 222 : 111];
+ [[_statusMenu itemAtIndex:index] setImage:[item image]];
+
+ [_statusMenu selectItemAtIndex:index];
+}
+
+- (NSString *)defaultTerminal {
+ /* Does it seem odd to you that this is here? Me too. But we may as well store it in the nib
+ * as a menu item as anything else...
+ */
+ return [NSString stringWithFormat:@"+%@",
+ [[_statusMenu itemAtIndex:[_statusMenu indexOfItemWithTag:1]] title]];
+}
+
+- (IBAction)changeStatus:(id)sender {
+ id <NSMenuItem> item = [sender selectedItem];
+ NSString *terminal = nil;
+
+ switch ([item tag]) {
+ case -1:
+ [ZChatApp disconnect:nil];
+ return;
+
+ case -2:
+ terminal = @"";
+ break;
+
+ case 1:
+ case 111:
+ terminal = [NSString stringWithFormat:@"+%@", [item title]];
+ break;
+
+ case 2:
+ case 222:
+ terminal = [NSString stringWithFormat:@"-%@", [item title]];
+ break;
+
+ case 11:
+ case 22:
+ /* Haul out the heavy artillery... */
+ // TODO
+ break;
+ }
+
+ if (terminal != nil) {
+ if ([ZChatApp mgr] != nil) {
+ [ZChatApp setTerminal:terminal];
+ } else {
+ [ZChatApp connectWithTerminal:terminal];
+ }
+ }
+}
+
+
- (void)_loginNotification:(NSNotification *)notification {
[_reloadButton setEnabled:YES];
[_chatButton setEnabled:[[self selectedFriends] count] > 0];
-
+
[self reload:notification];
+
+ [self _updateStatusMenu];
}
- (void)_logoutNotification:(NSNotification *)notification {
@@ -138,8 +262,10 @@
[_chatButton setEnabled:NO];
[_busyIndicator stopAnimation:nil];
-
+
[self resetAll];
+
+ [self _updateStatusMenu];
}
- (void)_statusNotification:(NSNotification *)notification {
@@ -371,6 +497,8 @@
- (void)_busyNotification:(NSNotification *)notification {
[self reloadFriendViews];
+ [self _updateStatusMenu];
+
if ([ZChatApp busy]) {
[_busyIndicator startAnimation:nil];
return;
@@ -390,6 +518,7 @@
}
- (void)_abNotification:(NSNotification *)notification {
+ [_name setStringValue:[ZChatApp mySignature]];
[_data makeObjectsPerformSelector:@selector(updateNames)];
}
|