From 358cf707744dbfe1c85eebc7c44d7cf98bdd42e4 Mon Sep 17 00:00:00 2001 From: Kent Sutherland Date: Sun, 31 Jul 2005 18:47:02 +0000 Subject: [PATCH] Added support for attributed strings, which allows us to have non-sucky stars in 10.4. Added a debug mode status window to notify the user, and debug mode is enabled when control is held down at launch. --- English.lproj/InfoPlist.strings | Bin 540 -> 548 bytes English.lproj/Localizable.strings | 3 +- MainController.m | 6 +++- StatusWindow.h | 5 ++- StatusWindow.m | 26 +++++++++------- StatusWindowController.h | 1 + StatusWindowController.m | 49 +++++++++++++++++++++++------- 7 files changed, 65 insertions(+), 25 deletions(-) diff --git a/English.lproj/InfoPlist.strings b/English.lproj/InfoPlist.strings index 286e9222929c6923263eb9a580b034131c6df34b..6036df352ff1cdbb3f5eb61feb121cbab3345648 100755 GIT binary patch delta 25 ecmbQkvV>*AYi2zL!-;+3lNlLpK+MTDj1K^0E(bpV delta 13 VcmZ3&GKXct>xu7!Cc84;2LLMk22KC~ diff --git a/English.lproj/Localizable.strings b/English.lproj/Localizable.strings index 40eb0c0..0b70ce5 100755 --- a/English.lproj/Localizable.strings +++ b/English.lproj/Localizable.strings @@ -67,4 +67,5 @@ radio = "Radio"; genericDevice = "Generic Device"; iPod = "iPod"; cd = "CD"; -sharedLibrary = "Shared Library"; \ No newline at end of file +sharedLibrary = "Shared Library"; +debugmodeenabled = "Debug Mode Enabled\nAll actions MenuTunes performs will be logged\nto the console. To disable debug mode, quit\nand relaunch MenuTunes.\n\n(debug mode is enabled by holding down\nthe control key while MenuTunes opens)"; \ No newline at end of file diff --git a/MainController.m b/MainController.m index 2a3d6b3..d185d83 100755 --- a/MainController.m +++ b/MainController.m @@ -103,8 +103,12 @@ static MainController *sharedController; float iTunesVersion; //Turn on debug mode if needed - if ([df boolForKey:@"ITDebugMode"]) { + /*if ((GetCurrentKeyModifiers() & (controlKey | rightControlKey)) != 0) + if ((GetCurrentKeyModifiers() & (optionKey | rightOptionKey)) != 0) + if ((GetCurrentKeyModifiers() & (shiftKey | rightShiftKey)) != 0)*/ + if ([df boolForKey:@"ITDebugMode"] || ((GetCurrentKeyModifiers() & (controlKey | rightControlKey)) != 0)) { SetITDebugMode(YES); + [[StatusWindowController sharedController] showDebugModeEnabledWindow]; } //Check if iTunes 4.7 or later is installed diff --git a/StatusWindow.h b/StatusWindow.h index 4b678bc..7bc9762 100755 --- a/StatusWindow.h +++ b/StatusWindow.h @@ -15,6 +15,9 @@ #import #import +#define SMALL_DIVISOR 1.33333 +#define MINI_DIVISOR 1.66667 + @interface StatusWindow : ITTransientStatusWindow { NSImage *_image; BOOL _locked; @@ -23,7 +26,7 @@ - (void)setImage:(NSImage *)newImage; - (void)setLocked:(BOOL)flag; -- (void)buildTextWindowWithString:(NSString *)text; +- (void)buildTextWindowWithString:(id)text; - (void)buildMeterWindowWithCharacter:(NSString *)character size:(float)size count:(int)count diff --git a/StatusWindow.m b/StatusWindow.m index 253f075..0fdc52d 100755 --- a/StatusWindow.m +++ b/StatusWindow.m @@ -19,8 +19,6 @@ #define SW_BUTTON_DIV 12.00 #define SW_BUTTON_EXTRA_W 8.00 #define SW_SHADOW_SAT 1.25 -#define SMALL_DIVISOR 1.33333 -#define MINI_DIVISOR 1.66667 @interface StatusWindow (Private) - (NSRect)setupWindowWithDataSize:(NSSize)dataSize; @@ -195,7 +193,7 @@ dataHeight); } -- (void)buildTextWindowWithString:(NSString *)text +- (void)buildTextWindowWithString:(id)text { if ( ! _locked ) { @@ -203,9 +201,9 @@ float dataWidth = 0.0; float dataHeight = 0.0; NSRect dataRect; - NSArray *lines = [text componentsSeparatedByString:@"\n"]; + NSArray *lines = [(([text isKindOfClass:[NSString class]]) ? text : [text mutableString]) componentsSeparatedByString:@"\n"]; id oneLine = nil; - NSEnumerator *lineEnum = [lines objectEnumerator]; + NSEnumerator *lineEnum = [lines objectEnumerator]; float baseFontSize = 18.0; ITTextField *textField; NSFont *font; @@ -216,10 +214,10 @@ } else if ( _sizing == ITTransientStatusWindowMini ) { divisor = MINI_DIVISOR; } - - font = [NSFont fontWithName:@"LucidaGrande-Bold" size:(baseFontSize / divisor)]; - attr = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName]; - + + font = [NSFont fontWithName:@"LucidaGrande-Bold" size:(baseFontSize / divisor)]; + attr = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName]; + // Iterate over each line to get text width and height while ( (oneLine = [lineEnum nextObject]) ) { // Get the width of one line, adding 8.0 because Apple sucks donkey rectum. @@ -246,7 +244,13 @@ [textField setTextColor:[NSColor whiteColor]]; [textField setCastsShadow:YES]; [[textField cell] setWraps:NO]; - [textField setStringValue:text]; + + if ([text isKindOfClass:[NSString class]]) { + [textField setStringValue:text]; + } else { + [textField setAttributedStringValue:text]; + } + [textField setShadowSaturation:SW_SHADOW_SAT]; [[self contentView] addSubview:textField]; @@ -284,7 +288,7 @@ divisor = MINI_DIVISOR; } - font = [NSFont fontWithName:@"LucidaGrande-Bold" size:( size / divisor )]; + font = [NSFont fontWithName:@"AppleGothic" size:( size / divisor )]; attr = [NSDictionary dictionaryWithObject:font forKey:NSFontAttributeName]; charSize = [character sizeWithAttributes:attr]; cellHeight = ( charSize.height + 4.0 ); // Add 4.0 for shadow diff --git a/StatusWindowController.h b/StatusWindowController.h index 118ca38..c5a4566 100755 --- a/StatusWindowController.h +++ b/StatusWindowController.h @@ -42,6 +42,7 @@ typedef enum { - (void)showReconnectQueryWindow; - (void)showNetworkErrorQueryWindow; - (void)showPreferencesUpdateWindow; +- (void)showDebugModeEnabledWindow; - (void)showSongInfoWindowWithSource:(ITMTRemotePlayerSource)source title: (NSString *)title diff --git a/StatusWindowController.m b/StatusWindowController.m index 633c31c..e06176f 100755 --- a/StatusWindowController.m +++ b/StatusWindowController.m @@ -119,7 +119,7 @@ static StatusWindowController *sharedController; image: (NSImage *)art { NSImage *image = nil; - NSString *text = title; + NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:title]; if ( art != nil ) { image = art; @@ -138,31 +138,38 @@ static StatusWindowController *sharedController; } [_window setImage:image]; + [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]]; if ( album ) { - text = [text stringByAppendingString:[@"\n" stringByAppendingString:album]]; + [[text mutableString] appendFormat:@"\n%@", album]; + //text = [text stringByAppendingString:[@"\n" stringByAppendingString:album]]; } if ( artist ) { - text = [text stringByAppendingString:[@"\n" stringByAppendingString:artist]]; + [[text mutableString] appendFormat:@"\n%@", artist]; + //text = [text stringByAppendingString:[@"\n" stringByAppendingString:artist]]; } if ( composer ) { - text = [text stringByAppendingString:[@"\n" stringByAppendingString:composer]]; + [[text mutableString] appendFormat:@"\n%@", composer]; + //text = [text stringByAppendingString:[@"\n" stringByAppendingString:composer]]; } if ( time ) { - text = [text stringByAppendingString:[@"\n" stringByAppendingString:time]]; + [[text mutableString] appendFormat:@"\n%@", time]; + //text = [text stringByAppendingString:[@"\n" stringByAppendingString:time]]; } if ( track ) { - text = [text stringByAppendingString:[@"\n" stringByAppendingString:track]]; + [[text mutableString] appendFormat:@"\n%@", track]; + //text = [text stringByAppendingString:[@"\n" stringByAppendingString:track]]; } if (playCount > -1) { - text = [text stringByAppendingString:[NSString stringWithFormat:@"\n%@: %i", NSLocalizedString(@"playCount", @"Play Count"), playCount]]; + [[text mutableString] appendFormat:@"\n%@: %i", NSLocalizedString(@"playCount", @"Play Count"), playCount]; + //text = [text stringByAppendingString:[NSString stringWithFormat:@"\n%@: %i", NSLocalizedString(@"playCount", @"Play Count"), playCount]]; } if ( rating > -1 ) { NSString *ratingString = [NSString string]; NSString *emptyChar = [NSString stringWithUTF8String:"☆"]; NSString *fullChar = [NSString stringWithUTF8String:"★"]; - int i; + int i, start = [[text mutableString] length], size = 18; for ( i = 1; i < 6; i++ ) { @@ -172,11 +179,17 @@ static StatusWindowController *sharedController; ratingString = [ratingString stringByAppendingString:emptyChar]; } } - - text = [text stringByAppendingString:[@"\n" stringByAppendingString:ratingString]]; + + [[text mutableString] appendFormat:@"\n%@", ratingString]; + if ([_window sizing] == ITTransientStatusWindowSmall) { + size /= SMALL_DIVISOR; + } else if ([_window sizing] == ITTransientStatusWindowMini) { + size /= MINI_DIVISOR; + } + [text setAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[NSFont fontWithName:@"AppleGothic" size:size], NSFontAttributeName, nil, nil] range:NSMakeRange(start + 1, 5)]; + //text = [text stringByAppendingString:[@"\n" stringByAppendingString:ratingString]]; } - [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]]; [_window buildTextWindowWithString:text]; [_window appear:self]; } @@ -326,4 +339,18 @@ static StatusWindowController *sharedController; [_window setLocked:YES]; } +- (void)showDebugModeEnabledWindow +{ + [_window setImage:[NSImage imageNamed:@"Setup"]]; + [_window setSizing:(ITTransientStatusWindowSizing)[df integerForKey:@"statusWindowSizing"]]; + [_window buildDialogWindowWithMessage:NSLocalizedString(@"debugmodeenabled", @"Debug Mode Enabled") + defaultButton:@"OK" + alternateButton:nil + target:[MainController sharedController] + defaultAction:@selector(cancelReconnect) + alternateAction:nil]; + [_window appear:self]; + [_window setLocked:YES]; +} + @end \ No newline at end of file -- 2.20.1