Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add PMPackage and PMDatabase classes
Signed-off-by: Sebastian Nowicki <sebnow@gmail.com>
- Loading branch information
Showing
4 changed files
with
248 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright (c) 2008 Sebastian Nowicki <sebnow@gmail.com> | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a | ||
* copy of this software and associated documentation files (the "Software"), | ||
* to deal in the Software without restriction, including without limitation | ||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
* and/or sell copies of the Software, and to permit persons to whom the | ||
* Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
* DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface PMDatabase : NSObject { | ||
@package | ||
struct __pmdb_t *_database; | ||
} | ||
|
||
- (NSArray *) filteredPackagesUsingPredicate:(NSPredicate *)thePredicate; | ||
- (NSArray *) packages; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright (c) 2008 Sebastian Nowicki <sebnow@gmail.com> | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a | ||
* copy of this software and associated documentation files (the "Software"), | ||
* to deal in the Software without restriction, including without limitation | ||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
* and/or sell copies of the Software, and to permit persons to whom the | ||
* Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
* DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
#import "PMDatabase.h" | ||
#import <alpm.h> | ||
#import "PMPackage.h" | ||
|
||
@implementation PMDatabase | ||
|
||
- (void) dealloc | ||
{ | ||
alpm_db_unregister(_database); | ||
[super dealloc]; | ||
} | ||
|
||
- (NSArray *) packages | ||
{ | ||
size_t count; | ||
NSMutableArray *packages; | ||
alpm_list_t *list; | ||
alpm_list_t *node; | ||
PMPackage *package; | ||
pmpkg_t *alpmPackage; | ||
NSString *name; | ||
NSArray *result; | ||
|
||
list = alpm_db_getpkgcache(_database); | ||
count = alpm_list_count(list); | ||
packages = [[NSMutableArray alloc] initWithCapacity:count]; | ||
for(node = list; node != NULL; node = alpm_list_next(node)) { | ||
alpmPackage = alpm_list_getdata(node); | ||
name = [[NSString alloc] initWithUTF8String:alpm_pkg_get_name(alpmPackage)]; | ||
package = [[PMPackage alloc] initWithName:name fromDatabase:self]; | ||
[name release]; | ||
[packages addObject:package]; | ||
[package release]; | ||
} | ||
result = [NSArray arrayWithArray:packages]; | ||
[packages release]; | ||
return result; | ||
} | ||
|
||
- (NSArray *) filteredPackagesUsingPredicate:(NSPredicate *)thePredicate | ||
{ | ||
NSArray *packages = [self packages]; | ||
return [packages filteredArrayUsingPredicate:thePredicate]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright (c) 2008 Sebastian Nowicki <sebnow@gmail.com> | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a | ||
* copy of this software and associated documentation files (the "Software"), | ||
* to deal in the Software without restriction, including without limitation | ||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
* and/or sell copies of the Software, and to permit persons to whom the | ||
* Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
* DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@class PMDatabase; | ||
|
||
@interface PMPackage : NSObject { | ||
@package | ||
struct __pmpkg_t *_package; | ||
PMDatabase *_database; | ||
NSString *_name; | ||
NSString *_version; | ||
NSURL *_url; | ||
NSString *_description; | ||
NSString *_packager; | ||
NSNumber *_size; | ||
} | ||
|
||
@property (nonatomic, readonly) NSString *name; | ||
@property (nonatomic, readonly) NSString *version; | ||
@property (nonatomic, readonly) NSURL *url; | ||
@property (nonatomic, readonly) PMDatabase *database; | ||
@property (nonatomic, readonly) NSString *description; | ||
@property (nonatomic, readonly) NSString *packager; | ||
@property (nonatomic, readonly) NSNumber *size; | ||
|
||
- (id) initWithName:(NSString *)aName fromDatabase:(PMDatabase *)theDatabase; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* Copyright (c) 2008 Sebastian Nowicki <sebnow@gmail.com> | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a | ||
* copy of this software and associated documentation files (the "Software"), | ||
* to deal in the Software without restriction, including without limitation | ||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
* and/or sell copies of the Software, and to permit persons to whom the | ||
* Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
* DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
#import "PMPackage.h" | ||
#import <alpm.h> | ||
#import <alpm_list.h> | ||
#import "PMDatabase.h" | ||
|
||
@implementation PMPackage | ||
@synthesize name = _name; | ||
@synthesize version = _version; | ||
@synthesize database = _database; | ||
@synthesize description = _description; | ||
@synthesize packager = _packager; | ||
@synthesize size = _size; | ||
|
||
- (id) initWithName:(NSString *)aName fromDatabase:(PMDatabase *)theDatabase | ||
{ | ||
self = [super init]; | ||
if(self != nil) { | ||
_package = alpm_db_get_pkg(theDatabase->_database, [aName UTF8String]); | ||
if(_package == NULL) { | ||
return nil; | ||
} | ||
_database = [theDatabase retain]; | ||
_name = [[NSString alloc] initWithUTF8String:alpm_pkg_get_name(_package)]; | ||
_version = [[NSString alloc] initWithUTF8String:alpm_pkg_get_version(_package)]; | ||
} | ||
return self; | ||
} | ||
|
||
- (void) dealloc | ||
{ | ||
[_database release]; | ||
[_name release]; | ||
[_packager release]; | ||
[_version release]; | ||
[_size release]; | ||
[_description release]; | ||
[_url release]; | ||
[super dealloc]; | ||
} | ||
|
||
- (NSString *) packager | ||
{ | ||
if(_packager == nil) { | ||
_packager = [[NSString alloc] initWithUTF8String:alpm_pkg_get_packager(_package)]; | ||
} | ||
return _packager; | ||
} | ||
|
||
- (NSNumber *) size | ||
{ | ||
if(_size == nil) { | ||
unsigned long long size = alpm_pkg_get_size(_package); | ||
_size = [[NSNumber alloc] initWithUnsignedLongLong:size]; | ||
} | ||
return _size; | ||
} | ||
|
||
- (NSString *) description | ||
{ | ||
if(_description == nil) { | ||
_description = [[NSString alloc] initWithUTF8String:alpm_pkg_get_desc(_package)]; | ||
} | ||
return _description; | ||
} | ||
|
||
- (NSURL *) url | ||
{ | ||
if(_url == nil) { | ||
NSString *url = [[NSString alloc] initWithUTF8String:alpm_pkg_get_url(_package)]; | ||
_url = [[NSURL alloc] initWithString:url]; | ||
[url release]; | ||
} | ||
return _url; | ||
} | ||
|
||
@end |