diff --git a/App.cpp b/App.cpp index 53407b4..1a0a567 100644 --- a/App.cpp +++ b/App.cpp @@ -38,7 +38,7 @@ App::AboutRequested() about->AddDescription(B_TRANSLATE("about_body")); about->AddCopyright(2024, "Santiago Lema"); about->AddText("e-mail me at haiku@lema.org"); - about->AddText("or ping me on the fediverse on @santiago@masto.lema.org"); + about->AddText("or ping me on the fediverse on @santi@go.lema.org"); about->Show(); } diff --git a/DumBer b/DumBer index 2792e85..94e673f 100755 Binary files a/DumBer and b/DumBer differ diff --git a/MainWindow.cpp b/MainWindow.cpp index 005707d..988836c 100644 --- a/MainWindow.cpp +++ b/MainWindow.cpp @@ -3,6 +3,7 @@ * All rights reserved. Distributed under the terms of the MIT license. */ + #include "MainWindow.h" #include @@ -13,7 +14,7 @@ #include #include #include - +#include #include @@ -37,53 +38,76 @@ MainWindow::MainWindow() : BWindow(BRect(100, 100, 600, 400), B_TRANSLATE("BeDumb"), B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE) { - auto sess = BHttpSession(); - _sharedSession = sess; BMenuBar *menuBar = _BuildMenu(); BLayoutBuilder::Group<>(this, B_VERTICAL, 0).Add(menuBar).AddGlue().End(); - _inputField = new BTextControl(B_TRANSLATE("question"), "", - new BMessage(kQuestionChanged)); - - _progress = new BStatusBar(BRect(0,0,100,10),"prog"); + _inputField = + new BTextControl(B_TRANSLATE("Your question: "), "What is the matrix ?", new BMessage(kQuestionChanged)); + + + _progress = new BStatusBar("prog"); _progress->SetMaxValue(100); _progress->SetTo(0); + _progress->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + - _answerView = - new BTextView("answer", B_WILL_DRAW | B_FOLLOW_ALL_SIDES); + _answerView = new BTextView("answer"); + + + BStringView* header = new BStringView("biglabel", "Let's Be Dumber!"); + BFont font; + header->GetFont(&font); + font.SetSize(20); + header->SetFont(&font); + + // Info view, only one line high + _infoView = new BTextView("info"); + _infoView->SetText("Ask your question.."); + _infoView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + _infoView->MakeEditable(false); + _infoView->MakeSelectable(false); + _infoView->SetWordWrap(false); + + float lineHeight = _infoView->LineHeight(0); + _infoView->SetExplicitMinSize(BSize(B_SIZE_UNSET, lineHeight)); + _infoView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, lineHeight)); + + float askH = lineHeight * 2; + _inputField->SetExplicitMinSize(BSize(B_SIZE_UNSET, askH)); + _inputField->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, askH * 6)); BButton *sendButton = new BButton("send", B_TRANSLATE("ask"), new BMessage(kSendPrompt), B_WILL_DRAW | B_NAVIGABLE); - // BLayoutItem * addMe = new BLayoutItem(): - BLayoutBuilder::Group<>(this, B_VERTICAL, 0) - - .AddGroup(B_HORIZONTAL, 0,1) + + .Add(header) + + .AddGroup(B_HORIZONTAL, 0, 1) .Add(_inputField) - .AddGroup(B_VERTICAL,B_USE_DEFAULT_SPACING, 0.1f) - .Add(_progress) + .AddGroup(B_HORIZONTAL, 0, 1) .Add(sendButton) .End() .End() - - - .AddGroup(B_HORIZONTAL, 0) + .Add(_progress) + .Add(_infoView) .Add(_answerView) - .End() - + .SetInsets(5, 5, 5, 5) + .End(); } MainWindow::~MainWindow() {} void MainWindow::MessageReceived(BMessage *message) { + switch (message->what) { + // case kMsgNewFile: { // fSaveMenuItem->SetEnabled(false); // printf("New\n"); @@ -100,8 +124,9 @@ void MainWindow::MessageReceived(BMessage *message) { case kQuestionChanged: { printf("Question Changed\n"); + _progress->SetTo(2); - sendQuery(); +// sendQuery(); } break; @@ -114,74 +139,130 @@ void MainWindow::MessageReceived(BMessage *message) { case UrlEvent::HostNameResolved: { printf("Host name resolved\n"); - _inputField->SetText("Hostname resolve..."); - _progress->SetTo(10); + auto name = message->GetString(UrlEventData::HostName); + message->PrintToStream(); + + _infoView->SetText("Hostname resolve..."); + _infoView->SetText(name); + _progress->SetTo(5); } break; case UrlEvent::ConnectionOpened: { printf("ConnectionOpened\n"); - _progress->SetTo(20); - _inputField->SetText("connection opened..."); + _progress->SetTo(10); + _infoView->SetText("connection opened..."); + } break; + + case UrlEvent::ResponseStarted: { + printf("ResponseStarted\n"); + _progress->SetTo(14); + _infoView->SetText("ResponseStarted..."); } break; - case UrlEvent::RequestCompleted: { + case UrlEvent::HttpRedirect: { + printf("HttpRedirect\n"); + _progress->SetTo(16); + _infoView->SetText("HttpRedirect..."); + } break; - printf("RequestCompleted\n"); - _inputField->SetText("Completed"); - _progress->SetMaxValue(100); - _progress->SetTo(100); + + + case UrlEvent::RequestCompleted: { + printf("RequestCompleted\n"); + auto identifier = message->GetInt32(UrlEventData::Id, -1); + if (resultOne->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()); + } + + _infoView->SetText("Completed"); + _progress->SetMaxValue(100); + _progress->SetTo(100); + + } break; + + + case UrlEvent::HttpStatus: { + + printf("HttpStatus\n"); + _infoView->SetText("HttpStatus received"); + _progress->SetTo(20); } break; 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); + //off_t numBytes = message->GetInt64(UrlEventData::NumBytes, 0); + //_progress->SetTo(numBytes); //} } break; case UrlEvent::DownloadProgress: { - // auto identifier = message->GetInt32(UrlEventData::Id, -1); - // if (fResult.Identifier() == identifier) { - off_t nn = message->GetInt64(UrlEventData::NumBytes, 0); + 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); - //} + _progress->SetMaxValue(totalBytes); + _progress->SetTo(nn); + _infoView->SetText("Download Progress.."); + } } break; + + default: { - BWindow::MessageReceived(message); + message->PrintToStream(); + BWindow::MessageReceived(message); // call the parent handler for other messages + // _infoView->SetText(message->FindMessage()); break; } - } -} + + +}//end switch + +} //end function + + void MainWindow::sendQuery() { - - printf("Sending Prompt to server...\n"); - + + //if (resultOne!=nullptr) + // _sharedSession.Cancel(resultOne->Identity()); + _progress->SetMaxValue(100); - _progress->SetTo(50); + _progress->SetTo(0); - auto url = BUrl("https://www.smallte.ch/"); - auto request = BHttpRequest(url); + auto url = BUrl("https://www.link-u.com/ip/"); + BHttpRequest request = BHttpRequest(url); +// requestOne = &request; +// request.SetTimeout() +// request.SetMethod(BHttpMethod::Get); - // Add a cookie to the session, this cookie will be used in window1 and - // window2 - // BNetworkCookie cookie("key", "value", BUrl("https://example.com/")); - // session.AddCookie(std::move(cookie)); - _sharedSession.Execute(std::move(request), nullptr, this); + printf("Sending Prompt to server: %s\n", url.UrlString().String()); + + + BHttpResult res = _sharedSession.Execute(std::move(request), nullptr, this); + printf("Result has identity: %d\n", res.Identity()); + resultOne = &res; + } -BMenuBar *MainWindow::_BuildMenu() { - BMenuBar *menuBar = new BMenuBar("menubar"); - BMenu *menu; - BMenuItem *item; +BMenuBar *MainWindow::_BuildMenu() { + + BMenuBar *menuBar = new BMenuBar("menubar"); + BMenu *menu; + BMenuItem *item; + // menu 'File' menu = new BMenu(B_TRANSLATE("File")); @@ -189,7 +270,7 @@ BMenuBar *MainWindow::_BuildMenu() { // menu->AddItem(item); // item = new BMenuItem(B_TRANSLATE("Open" B_UTF8_ELLIPSIS), - // new BMessage(kMsgOpenFile), 'O'); + // new BMessage(kMsgOpenFile), 'O'); // menu->AddItem(item); // fSaveMenuItem = @@ -198,17 +279,17 @@ BMenuBar *MainWindow::_BuildMenu() { // menu->AddItem(fSaveMenuItem); // menu->AddSeparatorItem(); - + item = new BMenuItem(B_TRANSLATE("About" B_UTF8_ELLIPSIS), new BMessage(B_ABOUT_REQUESTED)); item->SetTarget(be_app); menu->AddItem(item); - item = - new BMenuItem(B_TRANSLATE("Quit"), new BMessage(B_QUIT_REQUESTED), 'Q'); + item = new BMenuItem(B_TRANSLATE("Quit"), new BMessage(B_QUIT_REQUESTED), 'Q'); menu->AddItem(item); menuBar->AddItem(menu); return menuBar; -} \ No newline at end of file +} + diff --git a/MainWindow.h b/MainWindow.h index 2c00332..8ddb894 100644 --- a/MainWindow.h +++ b/MainWindow.h @@ -11,16 +11,26 @@ #include #include + + +//NEED THIS IN MAKE FILE TO USE PRIVATE HEADERS +//CXXFLAGS = -std=c++17 -Wall -I/boot/system/develop/headers/private + + +//Build works but Genio doesn't see class definitions unless I use full path ? +#include "/boot/system/develop/headers/private/netservices2/NetServicesDefs.h" +#include "/boot/system/develop/headers/private/netservices2/HttpSession.h" +#include "/boot/system/develop/headers/private/netservices2/HttpRequest.h" +#include "/boot/system/develop/headers/private/netservices2/HttpResult.h" +#include "/boot/system/develop/headers/private/netservices2/ErrorsExt.h" //From private headers ! -//#include "/boot/system/develop/headers/private/netservices2/HttpRequest.h" -//#include "/boot/system/develop/headers/private/netservices2/ErrorsExt.h" +//#include +//#include +//#include +//#include +//#include //#include -#include -#include -#include -#include - using namespace BPrivate::Network; @@ -35,9 +45,15 @@ public: void sendQuery(); private: + + BHttpSession _sharedSession = BHttpSession (); + + BHttpResult* resultOne; + BHttpRequest* requestOne; + BMenuBar *_BuildMenu(); - BHttpSession _sharedSession; BTextView * _answerView; + BTextView * _infoView; BTextControl* _inputField; BStatusBar* _progress; BMenuItem *fSaveMenuItem; diff --git a/Makefile b/Makefile index d9b5293..72da370 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,11 @@ ## Haiku Generic Makefile v2.6 ## + ## Fill in this file to specify the project being created, and the referenced ## Makefile-Engine will do all of the hard work for you. This handles any ## architecture of Haiku. -# The name of the binary. +# The name of the binary. NAME = DumBer TARGET_DIR = . @@ -109,7 +110,7 @@ SYMBOLS := DEBUGGER := # Specify any additional compiler flags to be used. -COMPILER_FLAGS = +COMPILER_FLAGS = # Specify any additional linker flags to be used. LINKER_FLAGS =