diff --git a/DumBer b/DumBer index 94e673f..7142dde 100755 Binary files a/DumBer and b/DumBer differ diff --git a/MainWindow.cpp b/MainWindow.cpp index 988836c..466b44a 100644 --- a/MainWindow.cpp +++ b/MainWindow.cpp @@ -44,7 +44,7 @@ MainWindow::MainWindow() BLayoutBuilder::Group<>(this, B_VERTICAL, 0).Add(menuBar).AddGlue().End(); _inputField = - new BTextControl(B_TRANSLATE("Your question: "), "What is the matrix ?", new BMessage(kQuestionChanged)); + new BTextControl("", "What is the matrix ?", new BMessage(kQuestionChanged)); _progress = new BStatusBar("prog"); @@ -55,7 +55,6 @@ MainWindow::MainWindow() _answerView = new BTextView("answer"); - BStringView* header = new BStringView("biglabel", "Let's Be Dumber!"); BFont font; header->GetFont(&font); @@ -64,7 +63,7 @@ MainWindow::MainWindow() // Info view, only one line high _infoView = new BTextView("info"); - _infoView->SetText("Ask your question.."); + _infoView->SetText("..."); _infoView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); _infoView->MakeEditable(false); _infoView->MakeSelectable(false); @@ -79,7 +78,7 @@ MainWindow::MainWindow() _inputField->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, askH * 6)); BButton *sendButton = - new BButton("send", B_TRANSLATE("ask"), new BMessage(kSendPrompt), + new BButton("send", B_TRANSLATE("Send"), new BMessage(kSendPrompt), B_WILL_DRAW | B_NAVIGABLE); BLayoutBuilder::Group<>(this, B_VERTICAL, 0) @@ -171,14 +170,14 @@ void MainWindow::MessageReceived(BMessage *message) { case UrlEvent::RequestCompleted: { printf("RequestCompleted\n"); auto identifier = message->GetInt32(UrlEventData::Id, -1); - if (resultOne->Identity() == identifier) { + if (_lastResult->Identity() == identifier) { // The following call will not block, because we have been notified // that the request is done. - auto body = resultOne->Body(); - //if (body) - // _DisplayHttpResult(body.value()); - //else - // _DisplayError(body.error()); + BHttpBody body = _lastResult->Body(); + if (body.text.has_value()) + _answerView->SetText(body.text.value()); + else + _answerView->SetText("nuthin'"); } _infoView->SetText("Completed"); @@ -198,28 +197,30 @@ void MainWindow::MessageReceived(BMessage *message) { case UrlEvent::BytesWritten: { _infoView->SetText("Some bytes written.."); - // auto identifier = message->GetInt32(UrlEventData::Id, -1); - // if (fResult.Identifier() == identifier) { - //off_t numBytes = message->GetInt64(UrlEventData::NumBytes, 0); - //_progress->SetTo(numBytes); - //} + auto identifier = message->GetInt32(UrlEventData::Id, -1); + if (_lastResult->Identity() == identifier) { + off_t numBytes = message->GetInt64(UrlEventData::NumBytes, 0); + off_t totalBytes = message->GetInt64(UrlEventData::TotalBytes, 0); + _progress->SetTo(numBytes); + _progress->SetMaxValue(totalBytes); + } } break; case UrlEvent::DownloadProgress: { auto identifier = message->GetInt32(UrlEventData::Id, -1); - if (resultOne->Identity() == identifier) { - off_t nn = message->GetInt64(UrlEventData::NumBytes, 0); - off_t totalBytes = message->GetInt64(UrlEventData::TotalBytes, 0); - _progress->SetMaxValue(totalBytes); - _progress->SetTo(nn); - _infoView->SetText("Download Progress.."); + if (_lastResult->Identity() == identifier) { + off_t nn = message->GetInt64(UrlEventData::NumBytes, 0); + off_t totalBytes = message->GetInt64(UrlEventData::TotalBytes, 0); + _progress->SetTo(nn); + _progress->SetMaxValue(totalBytes); + _infoView->SetText("Download Progress.."); } } break; - + default: { - message->PrintToStream(); + //message->PrintToStream(); BWindow::MessageReceived(message); // call the parent handler for other messages // _infoView->SetText(message->FindMessage()); break; @@ -234,24 +235,21 @@ void MainWindow::MessageReceived(BMessage *message) { void MainWindow::sendQuery() { - //if (resultOne!=nullptr) - // _sharedSession.Cancel(resultOne->Identity()); + if (_lastResult) + _sharedSession.Cancel(_lastResult->Identity()); _progress->SetMaxValue(100); _progress->SetTo(0); auto url = BUrl("https://www.link-u.com/ip/"); BHttpRequest request = BHttpRequest(url); -// requestOne = &request; -// request.SetTimeout() -// request.SetMethod(BHttpMethod::Get); printf("Sending Prompt to server: %s\n", url.UrlString().String()); + _lastResult = _sharedSession.Execute(std::move(request), nullptr, this); - - BHttpResult res = _sharedSession.Execute(std::move(request), nullptr, this); - printf("Result has identity: %d\n", res.Identity()); - resultOne = &res; + if (_lastResult) { + printf("Result has identity: %d\n", _lastResult->Identity()); + } } diff --git a/MainWindow.h b/MainWindow.h index 8ddb894..07f09b8 100644 --- a/MainWindow.h +++ b/MainWindow.h @@ -34,7 +34,7 @@ using namespace BPrivate::Network; - + class MainWindow : public BWindow { public: MainWindow(); @@ -48,8 +48,7 @@ private: BHttpSession _sharedSession = BHttpSession (); - BHttpResult* resultOne; - BHttpRequest* requestOne; + std::optional _lastResult; BMenuBar *_BuildMenu(); BTextView * _answerView;