1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3  * License, v. 2.0. If a copy of the MPL was not distributed with this
4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 
6 #ifndef CRASHREPORTER_OSX_H__
7 #define CRASHREPORTER_OSX_H__
8 
9 #include <Cocoa/Cocoa.h>
10 #include "HTTPMultipartUpload.h"
11 #include "crashreporter.h"
12 
13 // Defined below
14 @class TextViewWithPlaceHolder;
15 
16 @interface CrashReporterUI : NSObject {
17   IBOutlet NSWindow* mWindow;
18 
19   /* Crash reporter view */
20   IBOutlet NSTextField* mHeaderLabel;
21   IBOutlet NSTextField* mDescriptionLabel;
22   IBOutlet NSButton* mViewReportButton;
23   IBOutlet NSScrollView* mCommentScrollView;
24   IBOutlet TextViewWithPlaceHolder* mCommentText;
25   IBOutlet NSButton* mSubmitReportButton;
26   IBOutlet NSButton* mIncludeURLButton;
27   IBOutlet NSButton* mEmailMeButton;
28   IBOutlet NSTextField* mEmailText;
29   IBOutlet NSButton* mCloseButton;
30   IBOutlet NSButton* mRestartButton;
31   IBOutlet NSProgressIndicator* mProgressIndicator;
32   IBOutlet NSTextField* mProgressText;
33 
34   /* Error view */
35   IBOutlet NSView* mErrorView;
36   IBOutlet NSTextField* mErrorHeaderLabel;
37   IBOutlet NSTextField* mErrorLabel;
38   IBOutlet NSButton* mErrorCloseButton;
39 
40   /* For "show info" alert */
41   IBOutlet NSWindow* mViewReportWindow;
42   IBOutlet NSTextView* mViewReportTextView;
43   IBOutlet NSButton* mViewReportOkButton;
44 
45   HTTPMultipartUpload* mPost;
46 }
47 
48 - (void)showCrashUI:(const StringTable&)files
49     queryParameters:(const StringTable&)queryParameters
50             sendURL:(const std::string&)sendURL;
51 - (void)showErrorUI:(const std::string&)message;
52 - (void)showReportInfo;
53 - (void)maybeSubmitReport;
54 - (void)closeMeDown:(id)unused;
55 
56 - (IBAction)submitReportClicked:(id)sender;
57 - (IBAction)viewReportClicked:(id)sender;
58 - (IBAction)viewReportOkClicked:(id)sender;
59 - (IBAction)closeClicked:(id)sender;
60 - (IBAction)restartClicked:(id)sender;
61 - (IBAction)includeURLClicked:(id)sender;
62 - (IBAction)emailMeClicked:(id)sender;
63 
64 - (void)controlTextDidChange:(NSNotification*)note;
65 - (void)textDidChange:(NSNotification*)aNotification;
66 - (BOOL)textView:(NSTextView*)aTextView
67     shouldChangeTextInRange:(NSRange)affectedCharRange
68           replacementString:(NSString*)replacementString;
69 
70 - (void)doInitialResizing;
71 - (float)setStringFitVertically:(NSControl*)control
72                          string:(NSString*)str
73                    resizeWindow:(BOOL)resizeWindow;
74 - (void)setView:(NSView*)v animate:(BOOL)animate;
75 - (void)enableControls:(BOOL)enabled;
76 - (void)updateSubmit;
77 - (void)updateURL;
78 - (void)updateEmail;
79 - (void)sendReport;
80 - (bool)setupPost;
81 - (void)uploadThread:(HTTPMultipartUpload*)post;
82 - (void)uploadComplete:(NSData*)data;
83 
84 - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication*)theApplication;
85 - (void)applicationWillTerminate:(NSNotification*)aNotification;
86 
87 @end
88 
89 /*
90  * Subclass NSTextView to provide a text view with placeholder text.
91  * Also provide a setEnabled implementation.
92  */
93 @interface TextViewWithPlaceHolder : NSTextView {
94   NSMutableAttributedString* mPlaceHolderString;
95 }
96 
97 - (BOOL)becomeFirstResponder;
98 - (void)drawRect:(NSRect)rect;
99 - (BOOL)resignFirstResponder;
100 - (void)setPlaceholder:(NSString*)placeholder;
101 - (void)insertTab:(id)sender;
102 - (void)insertBacktab:(id)sender;
103 - (void)setEnabled:(BOOL)enabled;
104 - (void)dealloc;
105 
106 @end
107 
108 #endif
109