-
Notifications
You must be signed in to change notification settings - Fork 0
/
uifeedback.m
221 lines (188 loc) · 8.71 KB
/
uifeedback.m
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
classdef uifeedback < matlab.apps.AppBase
% Author: Alberto Cuadra Lara
% Website: acuadralara.com
% Last update: 28/10/2021
% Properties that correspond to app components
properties (Access = public)
feedbackUIFigure matlab.ui.Figure
attachments matlab.ui.control.TextArea
ClearButton matlab.ui.control.Button
subject matlab.ui.control.DropDown
AttachButton matlab.ui.control.Button
SendButton matlab.ui.control.Button
name matlab.ui.control.EditField
email matlab.ui.control.EditField
message matlab.ui.control.TextArea
end
properties (Access = private)
attachFiles % attachment file
FLAG_SEND = false % FLAG mail send
subject_0 % Default subject
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app)
% Take snapshot
% gui_SnapshotMenuSelected(app.feedbackUIFigure);
% Default subject
app.subject_0 = app.subject.Value;
end
% Button pushed function: SendButton
function SendButtonPushed(app, event)
% Inputs
source = '[email protected]'; % source email address (gmail)
sourcePassword = 'sourcePassword'; % source password
recipients = 'recipients'; % recipient email address (any email). Use {'mail1','mail2',...} for a set of recipients
subj = app.subject.Value; % subject mail
name = app.name.Value; % name of the sender (for contact)
mail = app.email.Value; % email of the sender (for contact)
msg = app.message.Value; % main body of email
attch = app.attachFiles; % attachments
% Set up SMTP service for gmail
setpref('Internet', 'E_mail', source);
setpref('Internet', 'SMTP_Server', 'smtp.gmail.com');
setpref('Internet', 'SMTP_Username', source);
setpref('Internet', 'SMTP_Password', sourcePassword);
% Gmail server
props = java.lang.System.getProperties;
props.setProperty('mail.smtp.auth', 'true');
props.setProperty('mail.smtp.socketFactory.class', 'javax.net.ssl.SSLSocketFactory');
props.setProperty('mail.smtp.socketFactory.port', '465');
% Format message
msg = [{strcat('Name: ', name)}; {strcat('Email: ', mail)}; {' '}; msg];
% Send the email
if ~isempty(mail) && contains(mail, '@') && contains(mail, '.')
if ~app.FLAG_SEND
if ~isempty(msg{4})
try
if isempty(attch)
sendmail(recipients, subj, msg);
else
sendmail(recipients, subj, msg, attch)
end
app.FLAG_SEND = true;
uialert(app.feedbackUIFigure, 'Message sent', 'Info', 'Icon', 'success');
catch
app.FLAG_SEND = false;
end
else
uialert(app.feedbackUIFigure, 'Empty message', 'Warning', 'Icon', 'warning');
end
else
uialert(app.feedbackUIFigure, 'Message already sent', 'Info', 'Icon', 'info');
end
else
uialert(app.feedbackUIFigure, 'Empty email', 'Warning', 'Icon', 'warning');
end
end
% Button pushed function: AttachButton
function AttachButtonPushed(app, event)
[file, path] = uigetfile({'*.png';'*.jpg';'*.svg';'*.pdf';'*.m'}, 'Select One or More Files', 'MultiSelect', 'on');
if ~isnumeric(file)
try
app.attachments.Value = {file};
catch
app.attachments.Value = file;
end
app.attachFiles = strcat(path, file);
end
end
% Button pushed function: ClearButton
function ClearButtonPushed(app, event)
% Clear GUI
app.subject.Value = app.subject_0;
app.name.Value = '';
app.email.Value = '';
app.message.Value = '';
app.attachments.Value = '';
app.attachFiles = 0;
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create feedbackUIFigure and hide until all components are created
app.feedbackUIFigure = uifigure('Visible', 'off');
app.feedbackUIFigure.AutoResizeChildren = 'off';
app.feedbackUIFigure.Color = [0.9098 0.9098 0.8902];
app.feedbackUIFigure.Position = [650 300 425 349];
app.feedbackUIFigure.Name = 'Feedback';
app.feedbackUIFigure.Icon = 'feedback_icon.png';
app.feedbackUIFigure.Resize = 'off';
% Create message
app.message = uitextarea(app.feedbackUIFigure);
app.message.Placeholder = 'message';
app.message.Position = [11 9 405 223];
% Create email
app.email = uieditfield(app.feedbackUIFigure, 'text');
app.email.Placeholder = 'email';
app.email.Position = [11 242 231 25];
% Create name
app.name = uieditfield(app.feedbackUIFigure, 'text');
app.name.Placeholder = 'name (optional)';
app.name.Position = [11 277 231 25];
% Create SendButton
app.SendButton = uibutton(app.feedbackUIFigure, 'push');
app.SendButton.ButtonPushedFcn = createCallbackFcn(app, @SendButtonPushed, true);
app.SendButton.Icon = 'send_icon.svg';
app.SendButton.Position = [255 312 75 25];
app.SendButton.Text = 'Send';
% Create AttachButton
app.AttachButton = uibutton(app.feedbackUIFigure, 'push');
app.AttachButton.ButtonPushedFcn = createCallbackFcn(app, @AttachButtonPushed, true);
app.AttachButton.Icon = 'clip_icon.svg';
app.AttachButton.Position = [341 312 75 25];
app.AttachButton.Text = 'Attach';
% Create subject
app.subject = uidropdown(app.feedbackUIFigure);
app.subject.Items = {'bug', 'enhancement', 'documentation'};
app.subject.Editable = 'on';
app.subject.BackgroundColor = [1 1 1];
app.subject.Placeholder = 'subject';
app.subject.Position = [11 312 142 25];
app.subject.Value = 'bug';
% Create ClearButton
app.ClearButton = uibutton(app.feedbackUIFigure, 'push');
app.ClearButton.ButtonPushedFcn = createCallbackFcn(app, @ClearButtonPushed, true);
app.ClearButton.Icon = 'clear_icon.svg';
app.ClearButton.Position = [167 312 75 25];
app.ClearButton.Text = 'Clear';
% Create attachments
app.attachments = uitextarea(app.feedbackUIFigure);
app.attachments.Editable = 'off';
app.attachments.Position = [255 242 161 60];
% Show the figure after all components are created
app.feedbackUIFigure.Visible = 'on';
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = uifeedback
runningApp = getRunningApp(app);
% Check for running singleton app
if isempty(runningApp)
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.feedbackUIFigure)
% Execute the startup function
runStartupFcn(app, @startupFcn)
else
% Focus the running singleton app
figure(runningApp.feedbackUIFigure)
app = runningApp;
end
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.feedbackUIFigure)
end
end
end