--- a/PDFViewer/pdfviewer/PDFViewer.m
+++ b/PDFViewer/pdfviewer/PDFViewer.m
@@ -20,7 +20,13 @@
NSMutableString *strings = [[NSMutableString alloc] init];
NSUInteger nOps = [[self document] pageCount];
- [strings appendString:[NSString stringWithFormat:@"Genosse Parteisekretär, das Dokument hat %lu Seiten", nOps]];
+ NSString *salutation = [self getSalutation];
+
+ if (nOps > 0) {
+ [strings appendString:[NSString stringWithFormat:@"%@, das Dokument hat %lu Seiten", salutation, nOps]];
+ } else {
+ [strings appendString:[NSString stringWithFormat:@"%@, laden Sie ein Dokument mit MAC-O", salutation]];
+ }
for (int pages = 0; pages < nOps; pages++) {
PDFPage *page = [[self document] pageAtIndex:pages];
@@ -45,9 +51,8 @@
// neues PDF laden
NSURL* url = [[panel URLs] objectAtIndex:0];
- PDFDocument *doc = [[PDFDocument alloc] initWithURL:url];
+ [self loadUrl:url];
- [self setDocument:doc];
[self startSpeaking:nil];
}
}];
@@ -104,4 +109,44 @@
return inputStr;
}
+- (NSString*) getSalutation {
+ NSString *fullName = NSFullUserName();
+ NSArray<NSString*> *array = [fullName componentsSeparatedByString:@" "];
+
+ NSString *name = @"Parteisekretär";
+
+ if (array != NULL) {
+ if ([array count] >= 1) {
+ name = [array objectAtIndex:1];
+ }
+ }
+
+ NSString *salutation = [NSString stringWithFormat:@"Genosse %@", name];
+
+ return salutation;
+}
+
+- (BOOL) loadUrl: (NSURL*) url {
+ PDFDocument *doc = [[PDFDocument alloc] initWithURL:url];
+
+ [self silence];
+ [self setDocument:doc];
+
+ return (doc != NULL);
+}
+
+- (void) showErrorMessage: (NSString*) message {
+ NSAlert *alert = [[NSAlert alloc] init];
+ [alert setMessageText:message];
+ [alert setInformativeText:@"Fehler"];
+ [alert runModal];
+}
+
+- (void) showDebugMessage: (NSString*) message {
+ NSAlert *alert = [[NSAlert alloc] init];
+ [alert setMessageText:message];
+ [alert setInformativeText:@"Debug"];
+ [alert runModal];
+}
+
@end