aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/otr_floater_smp_progress.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/newview/otr_floater_smp_progress.cpp')
-rw-r--r--linden/indra/newview/otr_floater_smp_progress.cpp288
1 files changed, 288 insertions, 0 deletions
diff --git a/linden/indra/newview/otr_floater_smp_progress.cpp b/linden/indra/newview/otr_floater_smp_progress.cpp
new file mode 100644
index 0000000..76bfc6e
--- /dev/null
+++ b/linden/indra/newview/otr_floater_smp_progress.cpp
@@ -0,0 +1,288 @@
1/* otr_floater_smp_progress.cpp - SMP progress dialog box [$PLOTR$]
2 See http://www.cypherpunks.ca/otr/
3
4 Copyright (C) 2009 Chris Tuchs
5
6 This is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of
9 the License, or (at your option) any later version.
10
11 This is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14 License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with the viewer; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 02111-1307, USA. */
20
21#include "llviewerprecompiledheaders.h"
22
23#include "llagent.h"
24#include "llcachename.h"
25#include "llimpanel.h"
26#include "llprogressbar.h"
27#include "lluictrlfactory.h"
28#include "llweb.h"
29
30#include "otr_wrapper.h"
31#include "otr_floater_smp_progress.h"
32
33void OtrFloaterSmpProgress::init()
34{
35 LLUICtrlFactory::getInstance()->buildFloater(this, "otr_floater_smp_progress.xml");
36 childSetAction("otr_smp_prog_help_btn", onClickHelp, this);
37 childSetAction("otr_smp_prog_cancel_btn", onClickCancel, this);
38 childSetAction("otr_smp_prog_ok_btn", onClickOk, this);
39 setDefaultBtn("otr_smp_prog_cancel_btn");
40 LLUIString title = mIsReply
41 ? getString("otr_smp_prog_name_auth_me")
42 : getString("otr_smp_prog_I_auth_name");
43 std::string them;
44 if (!gCacheName->getFullName(mOtherParticipantUUID, them)) them = getString("otr_generic_name");
45 title.setArg("[NAME]", them);
46 setTitle(title.getString());
47}
48
49OtrFloaterSmpProgress::OtrFloaterSmpProgress(
50 LLFloaterIMPanel *im_panel, LLUUID session_id, LLUUID other_id,
51 std::string a_question, std::string a_secret_answer, bool is_reply)
52: LLFloater(std::string("otr_floater_smp_progress"), std::string("OtrFloaterSmpProgRect"), LLStringUtil::null),
53 mIMPanel(im_panel), mIsReply(is_reply),
54 mSessionUUID(session_id), mOtherParticipantUUID(other_id),
55 mQuestion(a_question), mSecretAnswer(a_secret_answer),
56 mSecretAnswerOnly(false)
57{
58 init();
59 if (!gOTR)
60 {
61 llwarns << "$PLOTR$ Can't find gOTR." << llendl;
62 setFinalStatus("otr_smp_prog_auth_errored");
63 return;
64 }
65 if (!mIMPanel)
66 {
67 llwarns << "$PLOTR$ Can't find mIMPanel." << llendl;
68 setFinalStatus("otr_smp_prog_auth_errored");
69 return;
70 }
71 ConnContext *context = mIMPanel->getOtrContext();
72 if (!context)
73 {
74 llwarns << "$PLOTR$ Can't find context." << llendl;
75 setFinalStatus("otr_smp_prog_auth_errored");
76 return;
77 }
78 if (mIsReply)
79 {
80 otrl_message_respond_smp(
81 gOTR->get_userstate(),
82 gOTR->get_uistate(),
83 &mSessionUUID,
84 context,
85 (const unsigned char *)mSecretAnswer.c_str(),
86 mSecretAnswer.length());
87 setPercent(50);
88 setStatusName("otr_smp_prog_name_auth_me");
89 }
90 else
91 {
92 otrl_message_initiate_smp_q(
93 gOTR->get_userstate(),
94 gOTR->get_uistate(),
95 &mSessionUUID,
96 context,
97 mQuestion.c_str(),
98 (const unsigned char *)mSecretAnswer.c_str(),
99 mSecretAnswer.length());
100 setStatusName("otr_smp_prog_I_auth_name");
101 }
102}
103
104OtrFloaterSmpProgress::OtrFloaterSmpProgress(
105 LLFloaterIMPanel *im_panel, LLUUID session_id, LLUUID other_id,
106 std::string a_secret_answer, bool is_reply)
107: LLFloater(std::string("otr_floater_smp_progress"), std::string("OtrFloaterSmpProgRect"), LLStringUtil::null),
108 mIMPanel(im_panel), mIsReply(is_reply),
109 mSessionUUID(session_id), mOtherParticipantUUID(other_id),
110 mSecretAnswer(a_secret_answer),
111 mSecretAnswerOnly(true)
112{
113 init();
114 if (!gOTR)
115 {
116 llwarns << "$PLOTR$ Can't find gOTR." << llendl;
117 setFinalStatus("otr_smp_prog_auth_errored");
118 return;
119 }
120 if (!mIMPanel)
121 {
122 llwarns << "$PLOTR$ Can't find mIMPanel." << llendl;
123 setFinalStatus("otr_smp_prog_auth_errored");
124 return;
125 }
126 ConnContext *context = mIMPanel->getOtrContext();
127 if (!context)
128 {
129 llwarns << "$PLOTR$ Can't find context." << llendl;
130 setFinalStatus("otr_smp_prog_auth_errored");
131 return;
132 }
133 if (mIsReply)
134 {
135 otrl_message_respond_smp(
136 gOTR->get_userstate(),
137 gOTR->get_uistate(),
138 &mSessionUUID,
139 context,
140 (const unsigned char *)mSecretAnswer.c_str(),
141 mSecretAnswer.length());
142 setPercent(50);
143 setStatusName("otr_smp_prog_name_auth_me");
144 }
145 else
146 {
147 otrl_message_initiate_smp(
148 gOTR->get_userstate(),
149 gOTR->get_uistate(),
150 &mSessionUUID,
151 context,
152 (const unsigned char *)mSecretAnswer.c_str(),
153 mSecretAnswer.length());
154 setStatusName("otr_smp_prog_I_auth_name");
155 }
156}
157
158OtrFloaterSmpProgress::~OtrFloaterSmpProgress()
159{
160}
161
162BOOL OtrFloaterSmpProgress::postBuild()
163{
164 mProgressBar = getChild<LLProgressBar>("otr_smp_prog_progress_bar");
165 LLButton* cancel_btn = getChild<LLButton>("otr_smp_prog_cancel_btn");
166 cancel_btn->setEnabled(TRUE);
167 LLButton* ok_btn = getChild<LLButton>("otr_smp_prog_ok_btn");
168 ok_btn->setEnabled(FALSE);
169 return TRUE;
170}
171
172void OtrFloaterSmpProgress::show()
173{
174 this->open(); /*Flawfinder: ignore*/
175 this->center();
176}
177
178void OtrFloaterSmpProgress::setPercent(float percent)
179{
180 mProgressBar->setPercent(percent);
181 if (100 <= percent)
182 {
183 LLButton* cancel_btn = getChild<LLButton>("otr_smp_prog_cancel_btn");
184 cancel_btn->setEnabled(FALSE);
185 LLButton* ok_btn = getChild<LLButton>("otr_smp_prog_ok_btn");
186 ok_btn->setEnabled(TRUE);
187 }
188 else
189 {
190 LLButton* cancel_btn = getChild<LLButton>("otr_smp_prog_cancel_btn");
191 cancel_btn->setEnabled(TRUE);
192 LLButton* ok_btn = getChild<LLButton>("otr_smp_prog_ok_btn");
193 ok_btn->setEnabled(FALSE);
194 }
195}
196
197void OtrFloaterSmpProgress::setStatus(const char *message_string_name)
198{
199 LLTextBox *status = getChild<LLTextBox>("otr_smp_prog_status");
200 if (!status)
201 {
202 llwarns << "$PLOTR$ Can't find OTR progress status textbox" << llendl;
203 return;
204 }
205 status->setWrappedText(getString(message_string_name));
206}
207
208void OtrFloaterSmpProgress::setStatusName(const char *message_string_name)
209{
210 LLTextBox *status = getChild<LLTextBox>("otr_smp_prog_status");
211 if (!status)
212 {
213 llwarns << "$PLOTR$ Can't find OTR progress status textbox" << llendl;
214 return;
215 }
216 LLUIString msg = getString(message_string_name);
217 std::string them;
218 if (!gCacheName->getFullName(mOtherParticipantUUID, them)) them = getString("otr_generic_name");
219 msg.setArg("[NAME]", them);
220 status->setWrappedText(msg.getString());
221}
222
223void OtrFloaterSmpProgress::setFinalStatus(const char *message_string_name)
224{
225 setPercent(100);
226 setStatusName(message_string_name);
227}
228
229// static
230void OtrFloaterSmpProgress::onClickHelp(void*)
231{
232 LLWeb::loadURL("http://www.cypherpunks.ca/otr/help/3.2.0/authenticate.php");
233}
234
235// static
236void OtrFloaterSmpProgress::onClickCancel(void* userdata)
237{
238 OtrFloaterSmpProgress *self= (OtrFloaterSmpProgress*)userdata;
239 if (!self)
240 {
241 llwarns << "$PLOTR$ can't find OTR SMP PROG dialog." << llendl;
242 return;
243 }
244 if (!self->mIMPanel)
245 {
246 llwarns << "$PLOTR$ Can't find mIMPanel." << llendl;
247 return;
248 }
249 ConnContext *context = self->mIMPanel->getOtrContext();
250 if (!context)
251 {
252 llwarns << "$PLOTR$ Can't find context." << llendl;
253 return;
254 }
255 otrl_message_abort_smp(
256 gOTR->get_userstate(),
257 gOTR->get_uistate(),
258 &(self->mSessionUUID),
259 context);
260 self->close();
261}
262
263// static
264void OtrFloaterSmpProgress::onClickOk(void* userdata)
265{
266 OtrFloaterSmpProgress *self= (OtrFloaterSmpProgress*)userdata;
267 if (!self)
268 {
269 llwarns << "$PLOTR$ can't find OTR SMP PROG dialog." << llendl;
270 return;
271 }
272 self->close();
273}
274
275// virtual
276void OtrFloaterSmpProgress::onClose(bool app_quitting)
277{
278 destroy();
279 if (!mIMPanel)
280 {
281 llwarns << "$PLOTR$ Can't find mIMPanel." << llendl;
282 }
283 else
284 {
285 mIMPanel->endSmpProgress();
286 }
287}
288// [/$PLOTR$]