diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f274fff --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +obj +*.app \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..2d1fd6b --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,16 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "lldb", + "request": "launch", + "name": "Debug", + "program": "${workspaceFolder}/${workspaceFolderBasename}.app/${workspaceFolderBasename}", + "args": [], + "cwd": "${workspaceFolder}/${workspaceFolderBasename}.app" + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..cad7657 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "cmake.configureOnOpen": false +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..84cac5b --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,13 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "type": "shell", + "command": "gmake", + "args": [] + } + ] + } \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..3c516b2 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 3.1) + +# Project +Project(DailyBing VERSION 1.0.0) +find_library(COCOA_LIBRARY Cocoa) + +# Options +set(MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}) +set(MACOSX_BUNDLE_COPYRIGHT "© 2022 by darkoverlordofdata") +set(MACOSX_BUNDLE_INFO_STRING "Select a Bing Picture of the Day") +set(MACOSX_BUNDLE_GUI_IDENTIFIER "org.darkoverlordofdata.dailybing") + +# Resources +set_source_files_properties(Resources/DailyBing.png PROPERTIES MACOSX_PACKAGE_LOCATION "Resources") + +# Application +add_executable(${PROJECT_NAME} MACOSX_BUNDLE main.m Controller.m Window.m Resources/Logo.png) +target_link_libraries(${PROJECT_NAME} ${COCOA_LIBRARY}) +set_target_properties(${PROJECT_NAME} PROPERTIES FOLDER ".") diff --git a/Controller.h b/Controller.h new file mode 100644 index 0000000..693ae1f --- /dev/null +++ b/Controller.h @@ -0,0 +1,16 @@ +#import +#import + +#import "Window.h" + +@interface Controller : NSObject +{ + Window *window; +} + +// - (void)applicationWillFinishLaunching:(NSNotification *) not; +- (void)applicationDidFinishLaunching:(NSNotification *) not; + + +@end + diff --git a/Controller.m b/Controller.m new file mode 100644 index 0000000..f1a2bc7 --- /dev/null +++ b/Controller.m @@ -0,0 +1,16 @@ + +#import + +#import "Controller.h" + +@implementation Controller + +- (void)applicationDidFinishLaunching:(NSNotification *)aNotification; +{ + window = [[Window alloc] init]; + [window setDelegate:self]; +} + +@end + + diff --git a/DailyBingInfo.plist b/DailyBingInfo.plist new file mode 100644 index 0000000..aabf4a6 --- /dev/null +++ b/DailyBingInfo.plist @@ -0,0 +1,17 @@ +{ + ApplicationDescription = "Bing Picture Of the Day"; + ApplicationIcon = "DailyBing.png"; + ApplicationName = DailyBing; + ApplicationRelease = "1.0.0"; + Authors = ( + "darkoverlordofdata" + ); + Copyright = "Copyright (C) 2022 BSD 2 clause."; + CopyrightDescription = "Released under BSD 2 clause"; + FullVersionID = "1.0.0"; + NSExecutable = DailyBing; + NSIcon = "DailyBing.png"; + NSPrincipalClass = NSApplication; + NSRole = Application; + URL = "http://darkoverlordofdata.com/application/"; +} \ No newline at end of file diff --git a/GNUmakefile b/GNUmakefile new file mode 100644 index 0000000..b080e8e --- /dev/null +++ b/GNUmakefile @@ -0,0 +1,50 @@ +# +# GNUmakefile - Generated by ProjectCenter +# +ifeq ($(GNUSTEP_MAKEFILES),) + GNUSTEP_MAKEFILES := $(shell gnustep-config --variable=GNUSTEP_MAKEFILES 2>/dev/null) +endif +ifeq ($(GNUSTEP_MAKEFILES),) + $(error You need to set GNUSTEP_MAKEFILES before compiling!) +endif + +include $(GNUSTEP_MAKEFILES)/common.make + +# +# DailyBing +# +VERSION = 1.0.0 +PACKAGE_NAME = DailyBing +APP_NAME = DailyBing +DailyBing_APPLICATION_ICON = DailyBing.png + + +# +# Resource files +# +DailyBing_RESOURCE_FILES = \ +Resources/DailyBing.png + +# +# Header files +# +DailyBing_HEADER_FILES = \ +Window.h \ +Controller.h + +# +# Class files +# +DailyBing_OBJC_FILES = \ +main.m \ +Window.m \ +Controller.m + + +# +# Makefiles +# +-include GNUmakefile.preamble +include $(GNUSTEP_MAKEFILES)/aggregate.make +include $(GNUSTEP_MAKEFILES)/application.make +-include GNUmakefile.postamble diff --git a/HPImageArchive.json b/HPImageArchive.json new file mode 100644 index 0000000..9281fa3 --- /dev/null +++ b/HPImageArchive.json @@ -0,0 +1 @@ +{"images":[{"startdate":"20221129","fullstartdate":"202211290800","enddate":"20221130","url":"/th?id=OHR.HeronGiving_EN-US9774285216_1920x1080.jpg&rf=LaDigue_1920x1080.jpg&pid=hp","urlbase":"/th?id=OHR.HeronGiving_EN-US9774285216","copyright":"Great blue herons building a nest in Wakodahatchee Wetlands, Delray Beach, Florida (© Imagebroker/Alamy)","copyrightlink":"https://www.bing.com/search?q=giving+tuesday&form=hpcapt&filters=HpDate%3a%2220221129_0800%22","title":"A day for giving","quiz":"/search?q=Bing+homepage+quiz&filters=WQOskey:%22HPQuiz_20221129_HeronGiving%22&FORM=HPQUIZ","wp":true,"hsh":"d113d81f469c96bda2d895cfd32e31d2","drk":1,"top":1,"bot":1,"hs":[]},{"startdate":"20221128","fullstartdate":"202211280800","enddate":"20221129","url":"/th?id=OHR.RedPlanetDay_EN-US9693219784_1920x1080.jpg&rf=LaDigue_1920x1080.jpg&pid=hp","urlbase":"/th?id=OHR.RedPlanetDay_EN-US9693219784","copyright":"Mars (© NASA/Alamy)","copyrightlink":"https://www.bing.com/search?q=Mars+planet&form=hpcapt&filters=HpDate%3a%2220221128_0800%22","title":"Fourth rock from the sun","quiz":"/search?q=Bing+homepage+quiz&filters=WQOskey:%22HPQuiz_20221128_RedPlanetDay%22&FORM=HPQUIZ","wp":true,"hsh":"3d31fa46fee528d7998eb847f376c702","drk":1,"top":1,"bot":1,"hs":[]},{"startdate":"20221127","fullstartdate":"202211270800","enddate":"20221128","url":"/th?id=OHR.Cecropia_EN-US9602789937_1920x1080.jpg&rf=LaDigue_1920x1080.jpg&pid=hp","urlbase":"/th?id=OHR.Cecropia_EN-US9602789937","copyright":"Cecropia leaf atop lobster claw petals, Mexico (© Gerry Ellis/Minden Pictures)","copyrightlink":"https://www.bing.com/search?q=Cecropia&form=hpcapt&filters=HpDate%3a%2220221127_0800%22","title":"Unbe-leaf-able","quiz":"/search?q=Bing+homepage+quiz&filters=WQOskey:%22HPQuiz_20221127_Cecropia%22&FORM=HPQUIZ","wp":true,"hsh":"bb8c8d1568eda76a3575949b56a23f5d","drk":1,"top":1,"bot":1,"hs":[]},{"startdate":"20221126","fullstartdate":"202211260800","enddate":"20221127","url":"/th?id=OHR.OliveTreeDay_EN-US9460125670_1920x1080.jpg&rf=LaDigue_1920x1080.jpg&pid=hp","urlbase":"/th?id=OHR.OliveTreeDay_EN-US9460125670","copyright":"An olive tree in front of the Temple of Concordia on the island of Sicily, Italy (© Alfio Finocchiaro/Shutterstock)","copyrightlink":"https://www.bing.com/search?q=world+olive+tree+day+unesco&form=hpcapt&filters=HpDate%3a%2220221126_0800%22","title":"A symbol of peace","quiz":"/search?q=Bing+homepage+quiz&filters=WQOskey:%22HPQuiz_20221126_OliveTreeDay%22&FORM=HPQUIZ","wp":true,"hsh":"ee7b58af12cee118f8d88170c81879d7","drk":1,"top":1,"bot":1,"hs":[]},{"startdate":"20221125","fullstartdate":"202211250800","enddate":"20221126","url":"/th?id=OHR.MonksMound_EN-US9323884241_1920x1080.jpg&rf=LaDigue_1920x1080.jpg&pid=hp","urlbase":"/th?id=OHR.MonksMound_EN-US9323884241","copyright":"Monks Mound at the Cahokia Mounds UNESCO World Heritage Site near Collinsville, Illinois (© Matthew Gush/Alamy)","copyrightlink":"https://www.bing.com/search?q=native+american+heritage+day&form=hpcapt&filters=HpDate%3a%2220221125_0800%22","title":"Pyramid built by Native Americans","quiz":"/search?q=Bing+homepage+quiz&filters=WQOskey:%22HPQuiz_20221125_MonksMound%22&FORM=HPQUIZ","wp":true,"hsh":"3c986250c94574c1deac9fad2f7d52e6","drk":1,"top":1,"bot":1,"hs":[]},{"startdate":"20221124","fullstartdate":"202211240800","enddate":"20221125","url":"/th?id=OHR.CranberryBog_EN-US4145520322_1920x1080.jpg&rf=LaDigue_1920x1080.jpg&pid=hp","urlbase":"/th?id=OHR.CranberryBog_EN-US4145520322","copyright":"Cranberry bog (© SHSPhotography/Getty Images)","copyrightlink":"https://www.bing.com/search?q=thanksgiving+day+history&form=hpcapt&filters=HpDate%3a%2220221124_0800%22","title":"A crimson quagmire","quiz":"/search?q=Bing+homepage+quiz&filters=WQOskey:%22HPQuiz_20221124_CranberryBog%22&FORM=HPQUIZ","wp":true,"hsh":"1c73eaacd2ea4e2a1030e1b714455798","drk":1,"top":1,"bot":1,"hs":[]},{"startdate":"20221123","fullstartdate":"202211230800","enddate":"20221124","url":"/th?id=OHR.HelianthusAnnuus_EN-US9168789034_1920x1080.jpg&rf=LaDigue_1920x1080.jpg&pid=hp","urlbase":"/th?id=OHR.HelianthusAnnuus_EN-US9168789034","copyright":"Sunflower (© Dileep Chandran/Alamy)","copyrightlink":"https://www.bing.com/search?q=fibonacci+day&form=hpcapt&filters=HpDate%3a%2220221123_0800%22","title":"Nature, art, and...math?","quiz":"/search?q=Bing+homepage+quiz&filters=WQOskey:%22HPQuiz_20221123_HelianthusAnnuus%22&FORM=HPQUIZ","wp":true,"hsh":"8e2e2981ecf8f35ea431591a4a9913f4","drk":1,"top":1,"bot":1,"hs":[]},{"startdate":"20221122","fullstartdate":"202211220800","enddate":"20221123","url":"/th?id=OHR.Waterleidingduinen_EN-US9090200846_1920x1080.jpg&rf=LaDigue_1920x1080.jpg&pid=hp","urlbase":"/th?id=OHR.Waterleidingduinen_EN-US9090200846","copyright":"Red fox in Amsterdamse Waterleidingduinen Nature Reserve, Netherlands (© Edwin Giesbers/Minden Pictures)","copyrightlink":"https://www.bing.com/search?q=Red+fox&form=hpcapt&filters=HpDate%3a%2220221122_0800%22","title":"A fox in the dunes","quiz":"/search?q=Bing+homepage+quiz&filters=WQOskey:%22HPQuiz_20221122_Waterleidingduinen%22&FORM=HPQUIZ","wp":true,"hsh":"f553b0968ce9f8017291fde2acdae1bd","drk":1,"top":1,"bot":1,"hs":[]}],"tooltips":{"loading":"Loading...","previous":"Previous image","next":"Next image","walle":"This image is not available to download as wallpaper.","walls":"Download this image. Use of this image is restricted to wallpaper only."}} \ No newline at end of file diff --git a/NSPatch/NSGuiDefines.h b/NSPatch/NSGuiDefines.h new file mode 100644 index 0000000..ddc957b --- /dev/null +++ b/NSPatch/NSGuiDefines.h @@ -0,0 +1,47 @@ +#import + +// missing enum values in gnustep-gui + +#define NSBezelStyleRounded 1 +#define NSBezelStyleRegularSquare 2 +#define NSBezelStyleShadowlessSquare 6 +#define NSBezelStyleSmallSquare 10 +#define NSBezelStyleRoundRect 12 +#define NSBezelStyleInline 15 +#define NSBezelStyleRecessed 13 +#define NSBezelStyleDisclosure 5 +#define NSBezelStyleRoundedDisclosure 14 +#define NSBezelStyleCircular 7 +#define NSBezelStyleHelpButton 9 +#define NSBezelStyleTexturedRounded 12 +#define NSBezelStyleTexturedSquare 8 + +#define NSButtonTypeSwitch NSSwitchButton +#define NSButtonTypeOnOff NSOnOffButton + +#define NSButtonTypeRadio NSRadioButton + +#define NSEventMaskAny NSUIntegerMax + +#define NSEventModifierFlagCapsLock (1 << 16) +#define NSEventModifierFlagShift (1 << 17) +#define NSEventModifierFlagControl (1 << 18) +#define NSEventModifierFlagOption (1 << 19) +#define NSEventModifierFlagCommand (1 << 20) +#define NSEventModifierFlagNumericPad (1 << 21) +#define NSEventModifierFlagHelp (1 << 22) +#define NSEventModifierFlagFunction (1 << 23) +#define NSEventModifierFlagDeviceIndependentFlagsMask = 0xffff0000UL + + +#define NSEventMaskAny NSUIntegerMax + +#define NSAlertStyleCritical 2 +#define NSAlertStyleInformational 1 +#define NSAlertStyleWarning 0 + +#define NSTabPositionNone 0 +#define NSTabPositionTop 1 +#define NSTabPositionLeft 2 +#define NSTabPositionBottom 3 +#define NSTabPositionRight 4 diff --git a/NSPatch/NSPatch.h b/NSPatch/NSPatch.h new file mode 100644 index 0000000..c6c1419 --- /dev/null +++ b/NSPatch/NSPatch.h @@ -0,0 +1,7 @@ +// compatibility patches + + +// sudo cp -rf NSPatch /usr/local/include + +#import "NSGuiDefines.h" +// #import "NSWindow+SetIsVisible.h" diff --git a/NSPatch/NSWindow+SetIsVisible.h b/NSPatch/NSWindow+SetIsVisible.h new file mode 100644 index 0000000..687761e --- /dev/null +++ b/NSPatch/NSWindow+SetIsVisible.h @@ -0,0 +1,31 @@ +#import + +/* +not required in GNUstep 1.9 +required in GNUstep 2.0 +not required in GNUstep 2.1 + +*/ +@interface NSWindow (NSWindowSetIsVisible) +- (void)setIsVisible: (BOOL) yes_no; +@end + +@implementation NSWindow (NSWindowSetIsVisible) +- (void)setIsVisible: (BOOL) flag { + // _f.visible = flag; + if (flag) + { + [self orderFrontRegardless]; + } + else + { + [self orderOut: nil]; + } + // if (yes_no) { + // [self center]; + // [self orderFrontRegardless]; + // [self makeKeyWindow]; + // [self display]; + // } +} +@end diff --git a/NSPatch/nspatch.md b/NSPatch/nspatch.md new file mode 100644 index 0000000..9c9bbba --- /dev/null +++ b/NSPatch/nspatch.md @@ -0,0 +1,5 @@ +* NSPatch + +various cocoa patches for objc 2.0 on Linux + +sudo cp -rf NSPatch /usr/local/include diff --git a/README.md b/README.md new file mode 100644 index 0000000..9a58e1b --- /dev/null +++ b/README.md @@ -0,0 +1,14 @@ +# dailybing + +prototype for selecting the daily bing + +## ill behaviour: +this demonstrates NSImageView loading the wrong image i.e. whatever image is loaded first is the only image displayed. + +## build + +GNUastep: +``` +cd DailyBing +gmake +``` \ No newline at end of file diff --git a/Resources/DailyBing.png b/Resources/DailyBing.png new file mode 100644 index 0000000..0d4fb1c Binary files /dev/null and b/Resources/DailyBing.png differ diff --git a/Window.h b/Window.h new file mode 100644 index 0000000..b95f68c --- /dev/null +++ b/Window.h @@ -0,0 +1,11 @@ +#import + + +@interface Window : NSWindow { + NSImageView* pictureBox1; + NSImageView* pictureBox2; +} +- (instancetype)init; +- (BOOL)windowShouldClose:(id)sender; + +@end diff --git a/Window.m b/Window.m new file mode 100644 index 0000000..1e96e13 --- /dev/null +++ b/Window.m @@ -0,0 +1,35 @@ +#import +#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]; + + [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 setIsVisible:YES]; + + NSURL *url1 = [NSURL URLWithString:@"https://www.bing.com/th?id=OHR.RedPlanetDay_EN-US9693219784_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"]; + + NSImage *img1 = [[NSImage alloc] initWithContentsOfURL:url1]; + NSImage *img2 = [[NSImage alloc] initWithContentsOfURL:url2]; + + [pictureBox1 setImage:img1]; + [pictureBox2 setImage:img2]; + + return self; +} + +- (BOOL)windowShouldClose:(id)sender { + [NSApp terminate:sender]; + return YES; +} + + +@end + diff --git a/Windowv1.m b/Windowv1.m new file mode 100644 index 0000000..886c7de --- /dev/null +++ b/Windowv1.m @@ -0,0 +1,134 @@ +#import +#import "./NSPatch/NSPatch.h" + +#import "Window.h" + +@implementation Window +- (instancetype)init { + + [NSApp setMainMenu:[[[NSMenu alloc] init] autorelease]]; + + [[NSApp mainMenu] setSubmenu: [NSMenu new] forItem:[[NSApp mainMenu] addItemWithTitle: @"File" action:NULL keyEquivalent: @""]]; + [[[[NSApp mainMenu] itemArray][0] submenu] addItemWithTitle:@"Get POD" action:@selector(fileGetPOD:) keyEquivalent:@""]; + [[[[NSApp mainMenu] itemArray][0] submenu] addItemWithTitle:@"Preferences" action:NSSelectorFromString(@"") keyEquivalent:@""]; + [[[[NSApp mainMenu] itemArray][0] submenu] addItemWithTitle:@"Open" action:@selector(fileOpen:) keyEquivalent:@""]; + [[[[NSApp mainMenu] itemArray][0] submenu] addItem:[NSMenuItem separatorItem]]; + [[[[NSApp mainMenu] itemArray][0] submenu] addItemWithTitle:@"Save" action:@selector(fileSave:) keyEquivalent:@""]; + [[[[NSApp mainMenu] itemArray][0] submenu] addItemWithTitle:@"Close" action:@selector(fileClose:) keyEquivalent:@""]; + [[[[NSApp mainMenu] itemArray][0] submenu] addItem:[NSMenuItem separatorItem]]; + [[[[NSApp mainMenu] itemArray][0] submenu] addItemWithTitle:@"Quit" action:@selector(terminate:) keyEquivalent:@"q"]; + + [[NSApp mainMenu] setSubmenu: [NSMenu new] forItem:[[NSApp mainMenu] addItemWithTitle: NSLocalizedString(@"Help", @"") action:NULL keyEquivalent: @""]]; + [[[[NSApp mainMenu] itemArray][1] submenu] addItemWithTitle:@"About" action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@"o"]; + + + pictureBox1 = [[[NSImageView alloc] initWithFrame:NSMakeRect(0, 0, 240, 135)] autorelease]; + pictureBox2 = [[[NSImageView alloc] initWithFrame:NSMakeRect(240, 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 setIsVisible:YES]; + return self; +} + +- (BOOL)windowShouldClose:(id)sender { + [NSApp terminate:sender]; + return YES; +} + +- (void)fileNew:(id)sender { + NSLog(@"MainMenu/File/New"); +} + +- (void)fileOpen:(id)sender { + NSLog(@"MainMenu/File/New"); +} + +- (void)fileGetPOD:(id)sender { + NSLog(@"MainMenu/File/GetPOD"); + + // https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=8&mkt=en-US + + NSString *bingUrl= @"https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=en-US"; + NSURL *url = [NSURL URLWithString:bingUrl]; + NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url + cachePolicy:NSURLRequestReloadIgnoringCacheData + timeoutInterval:60]; + + NSURLResponse *response = nil; + NSError *error = nil; + NSError *jsonErr = nil; + + NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; + + NSDictionary* json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&jsonErr]; + + NSArray *images = [json valueForKey:@"images"]; + + // NSDictionary *image = [images objectAtIndex: 0]; + // NSString *imageUrl = [image valueForKey:@"url"]; + // NSURL *baseUrl = [NSURL URLWithString:@"https://www.bing.com"]; + // NSURL *fullUrl = [NSURL URLWithString:imageUrl relativeToURL:baseUrl]; + + + + // NSImage *img1 = [[NSImage alloc] initWithContentsOfURL:fullUrl]; + // [pictureBox1 setImage:img1]; + [pictureBox1 setImage:[self getImageAt:0 from:images]]; + [pictureBox1 setImageFrameStyle:(NSImageFrameNone)]; + + // NSImage *img2 = [[NSImage alloc] initWithContentsOfURL:fullUrl]; + // [pictureBox2 setImage:img2]; + [pictureBox2 setImage:[self getImageAt:1 from:images]]; + [pictureBox2 setImageFrameStyle:(NSImageFrameNone)]; + +} + +- (NSImage*)getImageAt:(int)index from:(NSArray*)images { + NSDictionary *image = [images objectAtIndex: index]; + NSString *imageUrl = [image valueForKey:@"url"]; + NSLog(@"imageUrl = %@", imageUrl); + // NSString *name = [image valueForKey:@"copyright"]; + // NSString *title = [image valueForKey:@"title"]; + NSURL *baseUrl = [NSURL URLWithString:@"https://www.bing.com"]; + NSURL *fullUrl = [NSURL URLWithString:imageUrl relativeToURL:baseUrl]; + NSLog(@"fullUrl = %@", fullUrl.absoluteString); + return [[NSImage alloc] initWithContentsOfURL:fullUrl]; +} + +- (void)fileClose:(id)sender { + NSLog(@"MainMenu/File/Close"); +} + +- (void)editUndo:(id)sender { + NSLog(@"MainMenu/Edit/Undo"); +} + +- (void)editRedo:(id)sender { + NSLog(@"MainMenu/Edit/Redo"); +} + +- (void)editCut:(id)sender { + NSLog(@"MainMenu/Edit/Cut"); +} + +- (void)editCopy:(id)sender { + NSLog(@"MainMenu/Edit/Copy"); +} + +- (void)editPaste:(id)sender { + NSLog(@"MainMenu/Edit/Paste"); +} + +- (void)editDelete:(id)sender { + NSLog(@"MainMenu/Edit/Delete"); +} + +- (void)editSelectAll:(id)sender { + NSLog(@"MainMenu/Edit/SelectAll"); +} + +@end + diff --git a/Windowv2.m b/Windowv2.m new file mode 100644 index 0000000..140993c --- /dev/null +++ b/Windowv2.m @@ -0,0 +1,127 @@ +#import +#import "./NSPatch/NSPatch.h" + +#import "Window.h" + +@implementation Window +- (instancetype)init { + + [NSApp setMainMenu:[[[NSMenu alloc] init] autorelease]]; + + [[NSApp mainMenu] setSubmenu: [NSMenu new] forItem:[[NSApp mainMenu] addItemWithTitle: @"File" action:NULL keyEquivalent: @""]]; + [[[[NSApp mainMenu] itemArray][0] submenu] addItemWithTitle:@"Get POD" action:@selector(fileGetPOD:) keyEquivalent:@""]; + [[[[NSApp mainMenu] itemArray][0] submenu] addItemWithTitle:@"Preferences" action:NSSelectorFromString(@"") keyEquivalent:@""]; + [[[[NSApp mainMenu] itemArray][0] submenu] addItemWithTitle:@"Open" action:@selector(fileOpen:) keyEquivalent:@""]; + [[[[NSApp mainMenu] itemArray][0] submenu] addItem:[NSMenuItem separatorItem]]; + [[[[NSApp mainMenu] itemArray][0] submenu] addItemWithTitle:@"Save" action:@selector(fileSave:) keyEquivalent:@""]; + [[[[NSApp mainMenu] itemArray][0] submenu] addItemWithTitle:@"Close" action:@selector(fileClose:) keyEquivalent:@""]; + [[[[NSApp mainMenu] itemArray][0] submenu] addItem:[NSMenuItem separatorItem]]; + [[[[NSApp mainMenu] itemArray][0] submenu] addItemWithTitle:@"Quit" action:@selector(terminate:) keyEquivalent:@"q"]; + + [[NSApp mainMenu] setSubmenu: [NSMenu new] forItem:[[NSApp mainMenu] addItemWithTitle: NSLocalizedString(@"Help", @"") action:NULL keyEquivalent: @""]]; + [[[[NSApp mainMenu] itemArray][1] submenu] addItemWithTitle:@"About" action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@"o"]; + + + pictureBox1 = [[[NSImageView alloc] initWithFrame:NSMakeRect(0, 0, 240, 135)] autorelease]; + pictureBox2 = [[[NSImageView alloc] initWithFrame:NSMakeRect(240, 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 setIsVisible:YES]; + return self; +} + +- (BOOL)windowShouldClose:(id)sender { + [NSApp terminate:sender]; + return YES; +} + +- (void)fileNew:(id)sender { + NSLog(@"MainMenu/File/New"); +} + +- (void)fileOpen:(id)sender { + NSLog(@"MainMenu/File/New"); +} + +- (void)fileGetPOD:(id)sender { + NSLog(@"MainMenu/File/GetPOD"); + + // https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=8&mkt=en-US + + NSString *bingUrl= @"https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=8&mkt=en-US"; + NSURL *url = [NSURL URLWithString:bingUrl]; + NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url + cachePolicy:NSURLRequestReloadIgnoringCacheData + timeoutInterval:60]; + + NSURLResponse *response = nil; + NSError *error = nil; + NSError *jsonErr = nil; + + NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; + + NSDictionary* json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&jsonErr]; + NSArray *images = [json valueForKey:@"images"]; + + + + NSDictionary *image1 = [images objectAtIndex: 1]; + NSString *imageUrl1 = [image1 valueForKey:@"url"]; + NSURL *baseUrl1 = [NSURL URLWithString:@"https://www.bing.com"]; + NSURL *fullUrl1 = [NSURL URLWithString:imageUrl1 relativeToURL:baseUrl1]; + NSLog(@"fullUrl1 = %@", fullUrl1); + + NSDictionary *image = [images objectAtIndex: 0]; + NSString *imageUrl = [image valueForKey:@"url"]; + NSURL *baseUrl = [NSURL URLWithString:@"https://www.bing.com"]; + NSURL *fullUrl = [NSURL URLWithString:imageUrl relativeToURL:baseUrl]; + NSLog(@"fullUrl = %@", fullUrl); + + NSURL url1 = [NSURL URLWithString:@"https://www.bing.com/th?id=OHR.RedPlanetDay_EN-US9693219784_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"]; + + NSImage *img1 = [[NSImage alloc] initWithContentsOfURL:fullUrl]; + NSImage *img2 = [[NSImage alloc] initWithContentsOfURL:fullUrl1]; + + [pictureBox2 setImage:img2]; + [pictureBox1 setImage:img1]; + +} + +- (void)fileClose:(id)sender { + NSLog(@"MainMenu/File/Close"); +} + +- (void)editUndo:(id)sender { + NSLog(@"MainMenu/Edit/Undo"); +} + +- (void)editRedo:(id)sender { + NSLog(@"MainMenu/Edit/Redo"); +} + +- (void)editCut:(id)sender { + NSLog(@"MainMenu/Edit/Cut"); +} + +- (void)editCopy:(id)sender { + NSLog(@"MainMenu/Edit/Copy"); +} + +- (void)editPaste:(id)sender { + NSLog(@"MainMenu/Edit/Paste"); +} + +- (void)editDelete:(id)sender { + NSLog(@"MainMenu/Edit/Delete"); +} + +- (void)editSelectAll:(id)sender { + NSLog(@"MainMenu/Edit/SelectAll"); +} + +@end + diff --git a/license.md b/license.md new file mode 100644 index 0000000..59fb051 --- /dev/null +++ b/license.md @@ -0,0 +1,25 @@ +BSD 2-Clause License + +Copyright (c) 2021 bruce davidson . +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/main.m b/main.m new file mode 100644 index 0000000..264131d --- /dev/null +++ b/main.m @@ -0,0 +1,18 @@ +#import +#import "Controller.h" +#import "Window.h" + + +int main(int argc, const char *argv[]) +{ + + @autoreleasepool { + [NSApplication sharedApplication]; + Controller *controller = [Controller new]; + [[NSApplication sharedApplication] setDelegate: controller]; + + NSApplicationMain(argc, argv); + + } +} +