a tiny webserver used to display the current itunes song
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at master 106 lines 3.6 kB view raw
1/* 2 * eyetunesgui 3 * Copyright (c) 2011, 2013 joshua stein <jcs@jcs.org> 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29#import "WKWindow.h" 30#import <Cocoa/Cocoa.h> 31 32@implementation WKWindow 33 34- (id)initWithX:(int)x y:(int)y width:(int)width height:(int)height 35{ 36 screen = [NSScreen mainScreen]; 37 screen_frame = [screen visibleFrame]; 38 39 /* convert normal geometry to cocoa 0,0-is-bottom-left */ 40 y += height; 41 42 NSRect coords = NSMakeRect((float)x, (float)y, (float)width, 43 (float)height); 44 self = [[super initWithContentRect:coords 45 styleMask:nil 46 backing:NSBackingStoreBuffered 47 defer:NO 48 screen:screen] autorelease]; 49 [self setBackgroundColor:[NSColor redColor]]; 50 [self setOpaque:NO]; 51 52 currentURL = [[NSURL alloc] init]; 53 54 /* XXX: not sure why this 120 is needed */ 55 NSRect bframe = NSMakeRect(0, 0, (float)width, (float)height - 120); 56 browser = [[WebView alloc] initWithFrame:bframe 57 frameName:nil 58 groupName:nil]; 59 [browser setGroupName:@"eyetunes"]; 60 [browser setUIDelegate:self]; 61 [browser setResourceLoadDelegate:self]; 62 [browser setFrameLoadDelegate:self]; 63 wframe = [browser mainFrame]; 64 [self.contentView addSubview:browser]; 65 66 [self makeFirstResponder:browser]; 67 [self makeKeyAndOrderFront:self]; 68 69 /* add a simple menu to refresh and quit */ 70 NSMenu *menubar = [[NSMenu new] autorelease]; 71 NSMenuItem *appMenuItem = [[NSMenuItem new] autorelease]; 72 [menubar addItem:appMenuItem]; 73 [NSApp setMainMenu:menubar]; 74 75 NSMenu *appMenu = [[NSMenu new] autorelease]; 76 NSMenuItem *refresher = [[[NSMenuItem alloc] initWithTitle:@"Refresh" 77 action:@selector(refresh:) keyEquivalent:@"r"] autorelease]; 78 [refresher setTarget:self]; 79 [refresher setEnabled:YES]; 80 [appMenu addItem:refresher]; 81 82 [appMenu addItem:[[[NSMenuItem alloc] initWithTitle:@"Quit" 83 action:@selector(terminate:) keyEquivalent:@"q"] autorelease]]; 84 85 [appMenuItem setSubmenu:appMenu]; 86 87 return self; 88} 89 90- (void)refresh:(id)sender 91{ 92 [wframe loadRequest:[NSURLRequest requestWithURL:currentURL]]; 93} 94 95- (void)loadURL:(NSString *)url 96{ 97 currentURL = [NSURL URLWithString:url]; 98 99 if ([[currentURL scheme] length] == 0) 100 currentURL = [NSURL URLWithString:[NSString 101 stringWithFormat:@"http://%@", url]]; 102 103 [wframe loadRequest:[NSURLRequest requestWithURL:currentURL]]; 104} 105 106@end