Skip to content

Commit

Permalink
first
Browse files Browse the repository at this point in the history
  • Loading branch information
kirb committed Jan 30, 2014
0 parents commit f271b4a
Show file tree
Hide file tree
Showing 33 changed files with 652 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.deb
_
obj
*.o
theos
*~
*.save
.DS_Store
Empty file added .stamp
Empty file.
Empty file added .theos/fakeroot
Empty file.
1 change: 1 addition & 0 deletions .theos/last_package
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
debs/ws.hbang.common_1.0_iphoneos-arm.deb
1 change: 1 addition & 0 deletions .theos/packages/ws.hbang.common-0.0.1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
68
4 changes: 4 additions & 0 deletions HBGlobal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
NSBundle *globalBundle;

#define L18N(key) [globalBundle localizedStringForKey:key value:key table:@"TypeStatus"]
#define URL_ENCODE(string) [(NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)(string), NULL, CFSTR(":/=,!$& '()*+;[]@#?"), kCFStringEncodingUTF8) autorelease]
5 changes: 5 additions & 0 deletions HBGlobal.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#import "HBGlobal.h"

%ctor {
globalBundle = [[NSBundle bundleWithPath:@"/Library/PreferenceBundles/libhbangprefs.bundle"] retain];
}
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
TARGET = :clang::4.0

include theos/makefiles/common.mk

SUBPROJECTS = prefs
include $(THEOS_MAKE_PATH)/aggregate.mk

after-stage::
mkdir -p $(THEOS)/include/libhbangcommon
rsync -rav *.h prefs/*.h $(THEOS)/include/libhbangcommon

after-install::
install.exec "killall Preferences; sleep 0.2; sbopenurl 'prefs:root=Cydia&path=FlagPaint7'"
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# libhbangcommon
Common stuff shared by HASHBANG Productions packages. Documentation to come soon.

_(Please don't release anything that relies on this package until the documentation is completed. Thanks!)_

[Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0.html)
9 changes: 9 additions & 0 deletions control
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Package: ws.hbang.common
Name: HASHBANG Productions Common
Version: 1.0
Architecture: iphoneos-arm
Description: Code shared by HASHBANG packages
Maintainer: HASHBANG Productions <[email protected]>
Author: HASHBANG Productions <[email protected]>
Section: System
Tag: role::developer
Empty file added prefs/.stamp
Empty file.
6 changes: 6 additions & 0 deletions prefs/HBAboutListController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#import "HBListController.h"
#import <MessageUI/MFMailComposeViewController.h>

@interface HBAboutListController : HBListController <MFMailComposeViewControllerDelegate>

@end
84 changes: 84 additions & 0 deletions prefs/HBAboutListController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#import "HBGlobal.h"
#import "HBAboutListController.h"
#import "HBOutputForShellCommand.h"
#import <MobileGestalt/MobileGestalt.h>
#include <version.h>

@implementation HBAboutListController

#pragma mark - Constants

+ (NSURL *)hb_websiteURL {
return [NSURL URLWithString:@"http://hbang.ws"];
}

+ (NSURL *)hb_donateURL {
return [NSURL URLWithString:@"http://hbang.ws/donate"];
}

+ (NSString *)hb_supportEmailAddress {
return @"HASHBANG Productions Support <[email protected]>";
}

#pragma mark - PSListController

- (NSArray *)specifiers {
if (!_specifiers) {
_specifiers = [[self loadSpecifiersFromPlistName:@"About" target:self] retain];
}

return _specifiers;
}

#pragma mark - Callbacks

- (void)hb_openWebsite {
[[UIApplication sharedApplication] openURL:[self.class hb_websiteURL]];
}

- (void)hb_openDonate {
[[UIApplication sharedApplication] openURL:[self.class hb_donateURL]];
}

- (void)hb_sendSupportEmail {
if (![MFMailComposeViewController canSendMail]) {
UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:L18N(@"No mail accounts are set up.") message:L18N(@"Use the Mail settings to add a new account.") delegate:nil cancelButtonTitle:L18N(@"OK") otherButtonTitles:nil] autorelease];
[alertView show];

return;
}

NSDictionary *info = [NSBundle bundleForClass:self.class].infoDictionary;

MFMailComposeViewController *viewController = [[[MFMailComposeViewController alloc] init] autorelease];
viewController.mailComposeDelegate = self;
viewController.toRecipients = @[ [self.class hb_supportEmailAddress] ];
viewController.subject = [NSString stringWithFormat:L18N(@"%@ %@ Support"), info[@"CFBundleName"], HBOutputForShellCommand([NSString stringWithFormat:@"/usr/bin/dpkg-query -f '${Version}' -W '%@'", info[@"HBPackageIdentifier"]])];
[viewController addAttachmentData:[HBOutputForShellCommand(@"/usr/bin/dpkg -l") dataUsingEncoding:NSUTF8StringEncoding] mimeType:@"text/plain" fileName:@"dpkgl.txt"];

NSString *product = nil, *version = nil, *build = nil;

if (IS_IOS_OR_NEWER(iOS_6_0)) {
product = (NSString *)MGCopyAnswer(kMGProductType);
version = (NSString *)MGCopyAnswer(kMGProductVersion);
build = (NSString *)MGCopyAnswer(kMGBuildVersion);
} else {
product = [UIDevice currentDevice].localizedModel;
version = [UIDevice currentDevice].systemVersion;
build = @"?";
}

NSLog(@"wat");NSLog(@"%@ %@ %@",product,version,build);
[viewController setMessageBody:[NSString stringWithFormat:L18N(@"\n\nDevice information: %@, iOS %@ (%@)"), product, version, build] isHTML:NO];
NSLog(@"yes");

[self.navigationController presentViewController:viewController animated:YES completion:nil];
}

#pragma mark - MFMailComposeViewControllerDelegate

- (void)mailComposeController:(MFMailComposeViewController *)viewController didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
[viewController dismissViewControllerAnimated:YES completion:nil];
}

@end
1 change: 1 addition & 0 deletions prefs/HBGlobal.h
1 change: 1 addition & 0 deletions prefs/HBGlobal.x
7 changes: 7 additions & 0 deletions prefs/HBListController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#import <Preferences/PSListController.h>

@interface HBListController : PSListController

+ (UIColor *)hb_tintColor;

@end
74 changes: 74 additions & 0 deletions prefs/HBListController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#import "HBListController.h"
#import "HBTintedTableCell.h"
#import <version.h>

@class HBRootListController;

#define IS_MODERN IS_IOS_OR_NEWER(iOS_7_0)
;

@interface HBListController () {
UIColor *_cachedTintColor;
}

@end

@implementation HBListController

#pragma mark - Constants

+ (UIColor *)hb_tintColor {
return nil;
}

#pragma mark - UIViewController

- (void)viewDidLoad {
[super viewDidLoad];

if (IS_MODERN) {
// https://www.youtube.com/watch?v=BkWl679wB1c
UIColor *tintColor = [self.class hb_tintColor];
NSArray *viewControllers = self.navigationController.viewControllers;

if (!tintColor) {
NSInteger i = viewControllers.count;

while (--i) {
if ([((NSObject *)viewControllers[i]).class respondsToSelector:@selector(hb_tintColor)] && [((HBListController *)viewControllers[i]).class hb_tintColor]) {
tintColor = [((HBListController *)viewControllers[i]).class hb_tintColor];
break;
}
}
}

_cachedTintColor = [tintColor copy];

[UISwitch appearanceWhenContainedIn:self.class, nil].onTintColor = tintColor;
[UILabel appearanceWhenContainedIn:HBTintedTableCell.class, nil].textColor = tintColor;
}
}

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];

// fix weird bug where selected row doesn't deselect
// thanks insanj <4
[(UITableView *)self.view deselectRowAtIndexPath:((UITableView *)self.view).indexPathForSelectedRow animated:YES];

if (IS_MODERN) {
self.view.tintColor = _cachedTintColor;
self.navigationController.navigationBar.tintColor = _cachedTintColor;
}
}

- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];

if (IS_MODERN) {
self.view.tintColor = nil;
self.navigationController.navigationBar.tintColor = nil;
}
}

@end
1 change: 1 addition & 0 deletions prefs/HBOutputForShellCommand.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NSString *HBOutputForShellCommand(NSString *command);
20 changes: 20 additions & 0 deletions prefs/HBOutputForShellCommand.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
NSString *HBOutputForShellCommand(NSString *command) {
FILE *file = popen(command.UTF8String, "r");

if (!file) {
return nil;
}

char data[1024];
NSMutableString *output = [NSMutableString string];

while (fgets(data, 1024, file) != NULL) {
[output appendString:[NSString stringWithUTF8String:data]];
}

if (pclose(file) != 0) {
return nil;
}

return [NSString stringWithString:output];
}
5 changes: 5 additions & 0 deletions prefs/HBRootListController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#import "HBListController.h"

@interface HBRootListController : HBListController

@end
43 changes: 43 additions & 0 deletions prefs/HBRootListController.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#import "../HBGlobal.h"
#import "HBRootListController.h"
#import <Twitter/Twitter.h>

@implementation HBRootListController

#pragma mark - Constants

+ (NSString *)hb_shareText {
return nil;
}

+ (NSURL *)hb_shareURL {
return nil;
}

#pragma mark - UIViewController

- (void)loadView {
[super loadView];

if ([self.class hb_shareText] && [self.class hb_shareURL]) {
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(hb_shareTapped)] autorelease];
}
}

#pragma mark - Callbacks

- (void)hb_shareTapped {
if (%c(UIActivityViewController)) {
UIActivityViewController *viewController = [[[UIActivityViewController alloc] initWithActivityItems:@[ [self.class hb_shareText], [self.class hb_shareURL] ] applicationActivities:nil] autorelease];
[self.navigationController presentViewController:viewController animated:YES completion:nil];
} else if (%c(TWTweetComposeViewController) && [TWTweetComposeViewController canSendTweet]) {
TWTweetComposeViewController *viewController = [[[TWTweetComposeViewController alloc] init] autorelease];
viewController.initialText = [self.class hb_shareText];
[viewController addURL:[self.class hb_shareURL]];
[self.navigationController presentViewController:viewController animated:YES completion:nil];
} else {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://twitter.com/intent/tweet?text=%@%%20%@", URL_ENCODE([self.class hb_shareText]), URL_ENCODE([self.class hb_shareURL].absoluteString)]]];
}
}

@end
5 changes: 5 additions & 0 deletions prefs/HBTintedTableCell.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#import <Preferences/PSTableCell.h>

@interface HBTintedTableCell : PSTableCell

@end
13 changes: 13 additions & 0 deletions prefs/HBTintedTableCell.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#import "HBTintedTableCell.h"

@implementation HBTintedTableCell

- (void)layoutSubviews {
[super layoutSubviews];

if ([self respondsToSelector:@selector(tintColor)]) {
self.textLabel.textColor = self.tintColor;
}
}

@end
5 changes: 5 additions & 0 deletions prefs/HBTwitterCell.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#import <Preferences/PSTableCell.h>

@interface HBTwitterCell : PSTableCell

@end
Loading

0 comments on commit f271b4a

Please sign in to comment.