1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
|
/*
Grr RSS Reader
Copyright (C) 2006, 2007 Guenther Noack <guenther@unix-ag.uni-kl.de>
Copyright (C) 2009-2012 GNUstep Application Team
Riccardo Mottola
This application is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
This application is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#import "SubscriptionPanel.h"
#import "Database.h"
#ifdef __APPLE__
#import "GNUstep.h"
#endif
@implementation SubscriptionPanel
// -----------------------------------------------------
// initialisation
// -----------------------------------------------------
+(id) shared
{
static SubscriptionPanel* controller = nil;
if (controller == nil)
{
ASSIGN(controller, [SubscriptionPanel new]);
}
return controller;
}
-(id) init
{
if ((self = [super init]) != nil)
{
BOOL nibLoaded;
nibLoaded = [NSBundle loadNibNamed:@"SubscriptionPanel" owner:self];
if (nibLoaded == NO)
{
NSLog(@"SubscriptionPanel: Failed to load nib.");
return nil;
}
}
return self;
}
-(void) dealloc
{
DESTROY(panel);
DESTROY(referenceElement);
[super dealloc];
}
// ------------------------------------------------------------
// SubscriptionPanel protocol (see FeedOperations component)
// ------------------------------------------------------------
-(void) show
{
[panel makeKeyAndOrderFront: self];
}
-(void) setReferenceElement: (id<DatabaseElement>) anElement
{
ASSIGN(referenceElement, anElement);
}
// ------------------------------------------------------------
// helper methods
// ------------------------------------------------------------
-(BOOL) subscribeToURL: (NSURL*) url
{
BOOL result = NO;
NSParameterAssert([url isKindOfClass: [NSURL class]]);
if (referenceElement != nil) {
if ([referenceElement conformsToProtocol: @protocol(Category)]) {
result = [[Database shared] subscribeToURL: url
inCategory: (id<Category>)referenceElement];
} else {
NSUInteger index = 0;
id<Category> category;
NSAssert1(
[referenceElement conformsToProtocol: @protocol(DatabaseElement)],
@"The reference element %@ is not a DatabaseElement.", referenceElement
);
// The category to put the subscription into is the super category of the
// reference element, the index is one below the reference element.
category = [referenceElement superElement];
if (category != nil) {
index = [[category elements] indexOfObject: referenceElement] + 1;
} else {
// The ref elements category was nil, so it's a top level element in the database.
index = [[[Database shared] topLevelElements] indexOfObject: referenceElement];
NSAssert(index != NSNotFound, @"The reference element points to a bad super element!");
index ++;
}
result = [[Database shared] subscribeToURL: url
inCategory: category
position: index];
}
} else {
result = [[Database shared] subscribeToURL: url];
}
return result;
}
// ------------------------------------------------------------
// GUI actions
// ------------------------------------------------------------
-(IBAction) subscribe: (id)sender
{
NSURL* URL = [NSURL URLWithString: [urlField stringValue]];
NSLog(@"URL: %@", [urlField stringValue]);
if (URL == nil) {
NSRunAlertPanel(
NSLocalizedString(@"Subscription failed", @"title of an alert dialog"),
NSLocalizedString(
@"The string you provided is not in URL format.",
@"failure reason in alert dialog"
),
_(@"Ok"), nil, nil
);
} else {
// URL is valid.
if ([self subscribeToURL: URL]) {
// success
[panel close];
} else {
// could not subscribe
NSRunAlertPanel(
NSLocalizedString(@"Subscription failed", @"alert message title"),
NSLocalizedString(
@"Your subscription failed. Possible reasons include:\n"
@"\t- There's not a RSS or Atom document stored at this URL\n"
@"\t- Incorrect Web Proxy settings\n",
@"failure reason in alert dialog"
),
_(@"Ok"), nil, nil
);
}
}
}
@end
|