Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
darkoverlordofdata committed Dec 2, 2022
1 parent c66adbb commit d0e93ab
Show file tree
Hide file tree
Showing 13 changed files with 282 additions and 75 deletions.
16 changes: 0 additions & 16 deletions Controller.m

This file was deleted.

11 changes: 6 additions & 5 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,18 @@ Resources/DailyBing.png
# Header files
#
DailyBing_HEADER_FILES = \
Window.h \
Controller.h
Source/Window.h \
Source/AppDelegate.h

#
# Class files
#
DailyBing_OBJC_FILES = \
main.m \
Window.m \
Controller.m
Source/main.m \
Source/Window.m \
Source/AppDelegate.m

OBJC_LIBS+= -ldispatch

#
# Makefiles
Expand Down
14 changes: 9 additions & 5 deletions Controller.h → Source/AppDelegate.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
/*
* Copyright (c) 2022 bruce davidson <darkoverlordofdata@gmail.com>.
*
* BSD 2-Clause License
*/

#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>

#import "Window.h"

@interface Controller : NSObject
{
Window *window;
}
@interface AppDelegate : NSObject

@property (strong, nonatomic) Window *window;

// - (void)applicationWillFinishLaunching:(NSNotification *) not;
- (void)applicationDidFinishLaunching:(NSNotification *) not;
Expand Down
28 changes: 28 additions & 0 deletions Source/AppDelegate.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2022 bruce davidson <darkoverlordofdata@gmail.com>.
*
* BSD 2-Clause License
*/

#import "AppDelegate.h"

@implementation AppDelegate

@synthesize window = _window;


- (void)applicationDidFinishLaunching:(NSNotification *)aNotification;
{
_window = [[Window alloc] init];
[_window setDelegate:self];
}

- (void)dealloc
{
[_window release];
[super dealloc];
}

@end


29 changes: 29 additions & 0 deletions Source/Window.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2022 bruce davidson <darkoverlordofdata@gmail.com>.
*
* BSD 2-Clause License
*/

#import <Cocoa/Cocoa.h>


@interface Window : NSWindow {
NSImageView *pictureBox1;
NSImageView *pictureBox2;
NSImageView *pictureBox3;
NSImageView *pictureBox4;
NSImageView *pictureBox5;
NSImageView *pictureBox6;
NSImageView *pictureBox7;
NSImageView *pictureBox8;


}
- (instancetype)init;
- (BOOL)windowShouldClose:(id)sender;
- (void) fetchUrl:(NSURL *)url on:(NSImageView *) view;
// - (void)URLResourceDidFinishLoading:(NSURL *)sender;



@end
77 changes: 77 additions & 0 deletions Source/Window.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright (c) 2022 bruce davidson <darkoverlordofdata@gmail.com>.
*
* BSD 2-Clause License
*/

#import <Cocoa/Cocoa.h>
#import "Window.h"

@implementation Window
- (instancetype)init {

pictureBox1 = [[[NSImageView alloc] initWithFrame:NSMakeRect(0, 0, 240, 135)] autorelease];
pictureBox2 = [[[NSImageView alloc] initWithFrame:NSMakeRect(240, 0, 240, 135)] autorelease];
pictureBox3 = [[[NSImageView alloc] initWithFrame:NSMakeRect(480, 0, 240, 135)] autorelease];
pictureBox4 = [[[NSImageView alloc] initWithFrame:NSMakeRect(720, 0, 240, 135)] autorelease];
pictureBox5 = [[[NSImageView alloc] initWithFrame:NSMakeRect(960, 0, 240, 135)] autorelease];
pictureBox6 = [[[NSImageView alloc] initWithFrame:NSMakeRect(1200, 0, 240, 135)] autorelease];
pictureBox7 = [[[NSImageView alloc] initWithFrame:NSMakeRect(1440, 0, 240, 135)] autorelease];
pictureBox8 = [[[NSImageView alloc] initWithFrame:NSMakeRect(1680, 0, 240, 135)] autorelease];

[super initWithContentRect:NSMakeRect(0, 0, 1920, 140) styleMask:NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable backing:NSBackingStoreBuffered defer:NO];
[self setTitle:@"Bing Picture Of the Day"];
[[self contentView] addSubview:pictureBox1];
[[self contentView] addSubview:pictureBox2];
[[self contentView] addSubview:pictureBox3];
[[self contentView] addSubview:pictureBox4];
[[self contentView] addSubview:pictureBox5];
[[self contentView] addSubview:pictureBox6];
[[self contentView] addSubview:pictureBox7];
[[self contentView] addSubview:pictureBox8];
[self setIsVisible:YES];

NSURL *url1 = [NSURL URLWithString:@"https://www.bing.com/th?id=OHR.RovinjCroatia_EN-US9834093615_1920x1080.jpg&rf=LaDigue_1920x1080.jpg&pid=hp"];
NSURL *url2 = [NSURL URLWithString:@"https://www.bing.com/th?id=OHR.HeronGiving_EN-US9774285216_1920x1080.jpg&rf=LaDigue_1920x1080.jpg&pid=hp"];
NSURL *url3 = [NSURL URLWithString:@"https://www.bing.com/th?id=OHR.RedPlanetDay_EN-US9693219784_1920x1080.jpg&rf=LaDigue_1920x1080.jpg&pid=hp"];
NSURL *url4 = [NSURL URLWithString:@"https://www.bing.com/th?id=OHR.Cecropia_EN-US9602789937_1920x1080.jpg&rf=LaDigue_1920x1080.jpg&pid=hp"];
NSURL *url5 = [NSURL URLWithString:@"https://www.bing.com/th?id=OHR.OliveTreeDay_EN-US9460125670_1920x1080.jpg&rf=LaDigue_1920x1080.jpg&pid=hp"];
NSURL *url6 = [NSURL URLWithString:@"https://www.bing.com/th?id=OHR.MonksMound_EN-US9323884241_1920x1080.jpg&rf=LaDigue_1920x1080.jpg&pid=hp"];
NSURL *url7 = [NSURL URLWithString:@"https://www.bing.com/th?id=OHR.CranberryBog_EN-US4145520322_1920x1080.jpg&rf=LaDigue_1920x1080.jpg&pid=hp"];
NSURL *url8 = [NSURL URLWithString:@"https://www.bing.com/th?id=OHR.HelianthusAnnuus_EN-US9168789034_1920x1080.jpg&rf=LaDigue_1920x1080.jpg&pid=hp"];

dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);

dispatch_async(queue, ^{ [self fetchUrl:url1 on:pictureBox1]; });
dispatch_async(queue, ^{ [self fetchUrl:url2 on:pictureBox2]; });
dispatch_async(queue, ^{ [self fetchUrl:url3 on:pictureBox3]; });
dispatch_async(queue, ^{ [self fetchUrl:url4 on:pictureBox4]; });
dispatch_async(queue, ^{ [self fetchUrl:url5 on:pictureBox5]; });
dispatch_async(queue, ^{ [self fetchUrl:url6 on:pictureBox6]; });
dispatch_async(queue, ^{ [self fetchUrl:url7 on:pictureBox7]; });
dispatch_async(queue, ^{ [self fetchUrl:url8 on:pictureBox8]; });
return self;
}

// https://stackoverflow.com/questions/8332897/simple-http-request-in-gnusteps-objective-c-not-working
- (void) fetchUrl:(NSURL *)url on:(NSImageView *) view {

NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:60];
NSURLResponse *response;
NSError *error = [[NSError alloc] init];

NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSImage *img = [[NSImage alloc] initWithData: data];
[view setImage:img];

}

- (BOOL)windowShouldClose:(id)sender {
[NSApp terminate:sender];
return YES;
}

@end

11 changes: 9 additions & 2 deletions main.m → Source/main.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
/*
* Copyright (c) 2022 bruce davidson <darkoverlordofdata@gmail.com>.
*
* BSD 2-Clause License
*/

#import <Cocoa/Cocoa.h>
#import "Controller.h"
#import "AppDelegate.h"
#import "Window.h"


Expand All @@ -8,11 +14,12 @@ int main(int argc, const char *argv[])

@autoreleasepool {
[NSApplication sharedApplication];
Controller *controller = [Controller new];
AppDelegate *controller = [AppDelegate new];
[[NSApplication sharedApplication] setDelegate: controller];

NSApplicationMain(argc, argv);

}
return 0;
}

11 changes: 0 additions & 11 deletions Window.h

This file was deleted.

35 changes: 0 additions & 35 deletions Window.m

This file was deleted.

2 changes: 1 addition & 1 deletion license.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 2-Clause License

Copyright (c) 2021 bruce davidson <darkoverlordofdata@gmail.com>.
Copyright (c) 2022 bruce davidson <darkoverlordofdata@gmail.com>.
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
Loading

0 comments on commit d0e93ab

Please sign in to comment.