X-Git-Url: http://git.ithinksw.org/GrowlITTSW.git/blobdiff_plain/fad781e94b464109aaa2243aa5ad2e593ea6e9bb..HEAD:/GrowlITTSWController.m diff --git a/GrowlITTSWController.m b/GrowlITTSWController.m index 172453a..5503ee8 100644 --- a/GrowlITTSWController.m +++ b/GrowlITTSWController.m @@ -56,6 +56,11 @@ } - (void)syncWithPrefs { + _imageSize = [GrowlITTSWPrefs imageSize]; + _imageNoUpscale = [GrowlITTSWPrefs imageNoUpscale]; + _wrapNotifications = [GrowlITTSWPrefs wrapNotifications]; + _wrapColumns = [GrowlITTSWPrefs wrapColumns]; + NSScreen *screen = [GrowlITTSWPrefs screen]; ITHorizontalWindowPosition horizontalPosition = [GrowlITTSWPrefs horizontalPosition]; ITVerticalWindowPosition verticalPosition = [GrowlITTSWPrefs verticalPosition]; @@ -107,17 +112,33 @@ } } -- (void)showWindowWithText:(NSString *)text image:(NSImage *)image { +- (void)showWindowWithTitle:(NSString *)title desc:(NSString *)desc image:(NSImage *)image { + NSString *text = title; + + if (desc && ![desc isEqualToString:@""] && ![desc isEqualToString:@"\n"]) { + text = [text stringByAppendingFormat:@"\n%@", desc]; + } + NSSize newSize; NSSize oldSize = [image size]; + BOOL wouldUpscale = ((oldSize.width <= _imageSize) && (oldSize.height <= _imageSize)); + + if (!(wouldUpscale && _imageNoUpscale)) { + if (oldSize.width > oldSize.height) { + newSize = NSMakeSize(_imageSize, (oldSize.height * (_imageSize / oldSize.width))); + } else { + newSize = NSMakeSize((oldSize.width * (_imageSize / oldSize.height)), _imageSize); + } + + image = [[[[NSImage alloc] initWithData:[image TIFFRepresentation]] autorelease] imageScaledSmoothlyToSize:newSize]; + } - if (oldSize.width > oldSize.height) { - newSize = NSMakeSize(110.0f, (oldSize.height * (110.0f / oldSize.width))); - } else { - newSize = NSMakeSize((oldSize.width * (110.0f / oldSize.height)), 110.0f); + if (_wrapNotifications) { + text = [text stringByReplacingOccurrencesOfRegex:[NSString stringWithFormat:@"(\\S\\S{%i,}|.{1,%i})(?:\\s+|$)", _wrapColumns, _wrapColumns] withString:@"$1\n"]; } - image = [[[[NSImage alloc] initWithData:[image TIFFRepresentation]] autorelease] imageScaledSmoothlyToSize:newSize]; + //trim trailing whitespace + text = [text stringByReplacingOccurrencesOfRegex:@"\\s+$" withString:@""]; NSArray *gothicChars = [NSArray arrayWithObjects:[NSString stringWithUTF8String:"☆"], [NSString stringWithUTF8String:"★"], nil]; NSMutableAttributedString *attributedText = [[NSMutableAttributedString alloc] initWithString:text]; @@ -125,7 +146,7 @@ if (([gothicChars count] > 0) && ([text length] > 0)) { NSMutableString *gothicRegex = [[NSMutableString alloc] init]; - [gothicRegex appendString:@"["]; + [gothicRegex appendString:@"[\\n"]; for (NSString *gothicChar in gothicChars) { [gothicRegex appendString:gothicChar]; }