2 @interface Source : NSObject {
3 NSString *description_;
8 NSString *distribution_;
16 - (Source *) initWithMetaIndex:(metaIndex *)index;
21 - (NSString *) distribution;
24 - (NSString *) description;
26 - (NSString *) origin;
29 @implementation Source
33 [distribution_ release];
36 if (description_ != nil)
37 [description_ release];
46 - (Source *) initWithMetaIndex:(metaIndex *)index {
47 if ((self = [super init]) != nil) {
48 trusted_ = index->IsTrusted();
50 uri_ = [[NSString stringWithCString:index->GetURI().c_str()] retain];
51 distribution_ = [[NSString stringWithCString:index->GetDist().c_str()] retain];
52 type_ = [[NSString stringWithCString:index->GetType()] retain];
58 debReleaseIndex *dindex(dynamic_cast<debReleaseIndex *>(index));
60 std::ifstream release(dindex->MetaIndexFile("Release").c_str());
62 while (std::getline(release, line)) {
63 std::string::size_type colon(line.find(':'));
64 if (colon == std::string::npos)
67 std::string name(line.substr(0, colon));
68 std::string value(line.substr(colon + 1));
69 while (!value.empty() && value[0] == ' ')
70 value = value.substr(1);
72 if (name == "Description")
73 description_ = [[NSString stringWithCString:value.c_str()] retain];
74 else if (name == "Label")
75 label_ = [[NSString stringWithCString:value.c_str()] retain];
76 else if (name == "Origin")
77 origin_ = [[NSString stringWithCString:value.c_str()] retain];
91 - (NSString *) distribution {
99 - (NSString *) description {
103 - (NSString *) label {
107 - (NSString *) origin {
113 /* Source Cell {{{ */
114 @interface SourceCell : UITableCell {
115 UITextLabel *description_;
116 UIRightTextLabel *label_;
117 UITextLabel *origin_;
122 - (SourceCell *) initWithSource:(Source *)source;
124 - (void) _setSelected:(float)fraction;
125 - (void) setSelected:(BOOL)selected;
126 - (void) setSelected:(BOOL)selected withFade:(BOOL)fade;
127 - (void) _setSelectionFadeFraction:(float)fraction;
131 @implementation SourceCell
134 [description_ release];
140 - (SourceCell *) initWithSource:(Source *)source {
141 if ((self = [super init]) != nil) {
142 GSFontRef bold = GSFontCreateWithName("Helvetica", kGSFontTraitBold, 20);
143 GSFontRef small = GSFontCreateWithName("Helvetica", kGSFontTraitNone, 14);
145 CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB();
146 float clear[] = {0, 0, 0, 0};
148 NSString *description = [source description];
149 if (description == nil)
150 description = [source uri];
152 description_ = [[UITextLabel alloc] initWithFrame:CGRectMake(12, 7, 270, 25)];
153 [description_ setBackgroundColor:CGColorCreate(space, clear)];
154 [description_ setFont:bold];
155 [description_ setText:description];
157 NSString *label = [source label];
159 label = [source type];
161 label_ = [[UIRightTextLabel alloc] initWithFrame:CGRectMake(290, 32, 90, 25)];
162 [label_ setBackgroundColor:CGColorCreate(space, clear)];
163 [label_ setFont:small];
164 [label_ setText:label];
166 NSString *origin = [source origin];
168 origin = [source distribution];
170 origin_ = [[UITextLabel alloc] initWithFrame:CGRectMake(13, 35, 315, 20)];
171 [origin_ setBackgroundColor:CGColorCreate(space, clear)];
172 [origin_ setFont:small];
173 [origin_ setText:origin];
175 [self addSubview:description_];
176 [self addSubview:label_];
177 [self addSubview:origin_];
184 - (void) _setSelected:(float)fraction {
185 CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB();
188 interpolate(0.0, 1.0, fraction),
189 interpolate(0.0, 1.0, fraction),
190 interpolate(0.0, 1.0, fraction),
194 interpolate(0.2, 1.0, fraction),
195 interpolate(0.2, 1.0, fraction),
196 interpolate(1.0, 1.0, fraction),
200 interpolate(0.4, 1.0, fraction),
201 interpolate(0.4, 1.0, fraction),
202 interpolate(0.4, 1.0, fraction),
205 [description_ setColor:CGColorCreate(space, black)];
206 [label_ setColor:CGColorCreate(space, blue)];
207 [origin_ setColor:CGColorCreate(space, gray)];
210 - (void) setSelected:(BOOL)selected {
211 [self _setSelected:(selected ? 1.0 : 0.0)];
212 [super setSelected:selected];
215 - (void) setSelected:(BOOL)selected withFade:(BOOL)fade {
217 [self _setSelected:(selected ? 1.0 : 0.0)];
218 [super setSelected:selected withFade:fade];
221 - (void) _setSelectionFadeFraction:(float)fraction {
222 [self _setSelected:fraction];
223 [super _setSelectionFadeFraction:fraction];
229 /* Sources View {{{ */
230 @interface SourcesView : UIView {
231 UISectionList *list_;
234 NSMutableArray *sources_;
235 UIActionSheet *alert_;
238 - (int) numberOfSectionsInSectionList:(UISectionList *)list;
239 - (NSString *) sectionList:(UISectionList *)list titleForSection:(int)section;
240 - (int) sectionList:(UISectionList *)list rowForSection:(int)section;
242 - (int) numberOfRowsInTable:(UITable *)table;
243 - (float) table:(UITable *)table heightForRow:(int)row;
244 - (UITableCell *) table:(UITable *)table cellForRow:(int)row column:(UITableColumn *)col;
245 - (BOOL) table:(UITable *)table showDisclosureForRow:(int)row;
246 - (void) tableRowSelected:(NSNotification*)notification;
248 - (void) navigationBar:(UINavigationBar *)navbar buttonClicked:(int)button;
251 - (id) initWithFrame:(CGRect)frame database:(Database *)database;
252 - (void) setDelegate:(id)delegate;
254 - (NSString *) leftTitle;
255 - (NSString *) rightTitle;
258 @implementation SourcesView
260 - (int) numberOfSectionsInSectionList:(UISectionList *)list {
264 - (NSString *) sectionList:(UISectionList *)list titleForSection:(int)section {
268 - (int) sectionList:(UISectionList *)list rowForSection:(int)section {
272 - (int) numberOfRowsInTable:(UITable *)table {
273 return [sources_ count];
276 - (float) table:(UITable *)table heightForRow:(int)row {
280 - (UITableCell *) table:(UITable *)table cellForRow:(int)row column:(UITableColumn *)col {
281 return [[[SourceCell alloc] initWithSource:[sources_ objectAtIndex:row]] autorelease];
284 - (BOOL) table:(UITable *)table showDisclosureForRow:(int)row {
288 - (void) tableRowSelected:(NSNotification*)notification {
289 UITable *table([list_ table]);
290 int row([table selectedRow]);
294 [table selectRow:-1 byExtendingSelection:NO withFade:YES];
297 - (void) alertSheet:(UIActionSheet *)sheet buttonClicked:(int)button {
303 - (void) navigationBar:(UINavigationBar *)navbar buttonClicked:(int)button {
306 alert_ = [[UIActionSheet alloc]
307 initWithTitle:@"Unimplemented"
308 buttons:[NSArray arrayWithObjects:@"Okay", nil]
314 [alert_ setBodyText:@"This feature will be implemented soon. In the mean time, you may add sources by adding .list files to '/etc/apt/sources.list.d'. If you'd like to be in the default list, please contact the author of Packager."];
315 [alert_ popupAlertAnimated:YES];
331 - (id) initWithFrame:(CGRect)frame database:(Database *)database {
332 if ((self = [super initWithFrame:frame]) != nil) {
333 database_ = database;
336 CGSize navsize = [UINavigationBar defaultSize];
337 CGRect navrect = {{0, 0}, navsize};
338 CGRect bounds = [self bounds];
340 navbar_ = [[UINavigationBar alloc] initWithFrame:navrect];
341 [self addSubview:navbar_];
343 [navbar_ setBarStyle:1];
344 [navbar_ setDelegate:self];
346 UINavigationItem *navitem = [[[UINavigationItem alloc] initWithTitle:@"Sources"] autorelease];
347 [navbar_ pushNavigationItem:navitem];
349 list_ = [[UISectionList alloc] initWithFrame:CGRectMake(
350 0, navsize.height, bounds.size.width, bounds.size.height - navsize.height
353 [self addSubview:list_];
355 [list_ setDataSource:self];
356 [list_ setShouldHideHeaderInShortLists:NO];
358 UITableColumn *column = [[UITableColumn alloc]
359 initWithTitle:@"Name"
361 width:frame.size.width
364 UITable *table = [list_ table];
365 [table setSeparatorStyle:1];
366 [table addTableColumn:column];
367 [table setDelegate:self];
371 - (void) setDelegate:(id)delegate {
372 delegate_ = delegate;
375 - (void) reloadData {
377 _assert(list.ReadMainList());
382 sources_ = [[NSMutableArray arrayWithCapacity:16] retain];
383 for (pkgSourceList::const_iterator source = list.begin(); source != list.end(); ++source)
384 [sources_ addObject:[[[Source alloc] initWithMetaIndex:*source] autorelease]];
389 - (NSString *) leftTitle {
390 return @"Refresh All";
393 - (NSString *) rightTitle {
399 /* Settings View {{{ */
400 @interface SettingsView : ResetView {
407 @implementation SettingsView
413 - (id) initWithFrame:(CGRect)frame database:(Database *)database {
414 if ((self = [super initWithFrame:frame]) != nil) {
415 database_ = database;
418 CGSize navsize = [UINavigationBar defaultSize];
419 CGRect navrect = {{0, 0}, navsize};
420 CGRect bounds = [self bounds];
422 navbar_ = [[UINavigationBar alloc] initWithFrame:navrect];
423 [self addSubview:navbar_];
425 [navbar_ setBarStyle:1];
426 [navbar_ setDelegate:self];
428 UINavigationItem *navitem = [[[UINavigationItem alloc] initWithTitle:@"Settings"] autorelease];
429 [navbar_ pushNavigationItem:navitem];
433 - (void) reloadData {