still learning
This commit is contained in:
parent
e2cc208ee4
commit
6fb8e69244
5 changed files with 170 additions and 72 deletions
2
App.cpp
2
App.cpp
|
@ -38,7 +38,7 @@ App::AboutRequested()
|
||||||
about->AddDescription(B_TRANSLATE("about_body"));
|
about->AddDescription(B_TRANSLATE("about_body"));
|
||||||
about->AddCopyright(2024, "Santiago Lema");
|
about->AddCopyright(2024, "Santiago Lema");
|
||||||
about->AddText("e-mail me at haiku@lema.org");
|
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();
|
about->Show();
|
||||||
}
|
}
|
||||||
|
|
BIN
DumBer
BIN
DumBer
Binary file not shown.
203
MainWindow.cpp
203
MainWindow.cpp
|
@ -3,6 +3,7 @@
|
||||||
* All rights reserved. Distributed under the terms of the MIT license.
|
* All rights reserved. Distributed under the terms of the MIT license.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "MainWindow.h"
|
#include "MainWindow.h"
|
||||||
|
|
||||||
#include <Url.h>
|
#include <Url.h>
|
||||||
|
@ -13,7 +14,7 @@
|
||||||
#include <LayoutBuilder.h>
|
#include <LayoutBuilder.h>
|
||||||
#include <Menu.h>
|
#include <Menu.h>
|
||||||
#include <MenuBar.h>
|
#include <MenuBar.h>
|
||||||
|
#include <StringView.h>
|
||||||
|
|
||||||
#include <View.h>
|
#include <View.h>
|
||||||
|
|
||||||
|
@ -37,53 +38,76 @@ MainWindow::MainWindow()
|
||||||
: BWindow(BRect(100, 100, 600, 400), B_TRANSLATE("BeDumb"), B_TITLED_WINDOW,
|
: BWindow(BRect(100, 100, 600, 400), B_TRANSLATE("BeDumb"), B_TITLED_WINDOW,
|
||||||
B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE) {
|
B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE) {
|
||||||
|
|
||||||
auto sess = BHttpSession();
|
|
||||||
_sharedSession = sess;
|
|
||||||
|
|
||||||
BMenuBar *menuBar = _BuildMenu();
|
BMenuBar *menuBar = _BuildMenu();
|
||||||
|
|
||||||
BLayoutBuilder::Group<>(this, B_VERTICAL, 0).Add(menuBar).AddGlue().End();
|
BLayoutBuilder::Group<>(this, B_VERTICAL, 0).Add(menuBar).AddGlue().End();
|
||||||
|
|
||||||
_inputField = new BTextControl(B_TRANSLATE("question"), "",
|
_inputField =
|
||||||
new BMessage(kQuestionChanged));
|
new BTextControl(B_TRANSLATE("Your question: "), "What is the matrix ?", new BMessage(kQuestionChanged));
|
||||||
|
|
||||||
_progress = new BStatusBar(BRect(0,0,100,10),"prog");
|
|
||||||
|
_progress = new BStatusBar("prog");
|
||||||
_progress->SetMaxValue(100);
|
_progress->SetMaxValue(100);
|
||||||
_progress->SetTo(0);
|
_progress->SetTo(0);
|
||||||
|
_progress->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
|
|
||||||
|
|
||||||
_answerView =
|
_answerView = new BTextView("answer");
|
||||||
new BTextView("answer", B_WILL_DRAW | B_FOLLOW_ALL_SIDES);
|
|
||||||
|
|
||||||
|
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 =
|
BButton *sendButton =
|
||||||
new BButton("send", B_TRANSLATE("ask"), new BMessage(kSendPrompt),
|
new BButton("send", B_TRANSLATE("ask"), new BMessage(kSendPrompt),
|
||||||
B_WILL_DRAW | B_NAVIGABLE);
|
B_WILL_DRAW | B_NAVIGABLE);
|
||||||
|
|
||||||
// BLayoutItem * addMe = new BLayoutItem():
|
|
||||||
|
|
||||||
BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
|
BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
|
||||||
|
|
||||||
.AddGroup(B_HORIZONTAL, 0,1)
|
.Add(header)
|
||||||
|
|
||||||
|
.AddGroup(B_HORIZONTAL, 0, 1)
|
||||||
.Add(_inputField)
|
.Add(_inputField)
|
||||||
.AddGroup(B_VERTICAL,B_USE_DEFAULT_SPACING, 0.1f)
|
.AddGroup(B_HORIZONTAL, 0, 1)
|
||||||
.Add(_progress)
|
|
||||||
.Add(sendButton)
|
.Add(sendButton)
|
||||||
.End()
|
.End()
|
||||||
.End()
|
.End()
|
||||||
|
|
||||||
|
.Add(_progress)
|
||||||
|
.Add(_infoView)
|
||||||
.AddGroup(B_HORIZONTAL, 0)
|
|
||||||
.Add(_answerView)
|
.Add(_answerView)
|
||||||
.End()
|
|
||||||
|
|
||||||
.SetInsets(5, 5, 5, 5)
|
.SetInsets(5, 5, 5, 5)
|
||||||
|
|
||||||
.End();
|
.End();
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow() {}
|
MainWindow::~MainWindow() {}
|
||||||
|
|
||||||
void MainWindow::MessageReceived(BMessage *message) {
|
void MainWindow::MessageReceived(BMessage *message) {
|
||||||
|
|
||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
|
|
||||||
// case kMsgNewFile: {
|
// case kMsgNewFile: {
|
||||||
// fSaveMenuItem->SetEnabled(false);
|
// fSaveMenuItem->SetEnabled(false);
|
||||||
// printf("New\n");
|
// printf("New\n");
|
||||||
|
@ -100,8 +124,9 @@ void MainWindow::MessageReceived(BMessage *message) {
|
||||||
|
|
||||||
case kQuestionChanged: {
|
case kQuestionChanged: {
|
||||||
printf("Question Changed\n");
|
printf("Question Changed\n");
|
||||||
|
_progress->SetTo(2);
|
||||||
|
|
||||||
sendQuery();
|
// sendQuery();
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
|
@ -114,74 +139,130 @@ void MainWindow::MessageReceived(BMessage *message) {
|
||||||
|
|
||||||
case UrlEvent::HostNameResolved: {
|
case UrlEvent::HostNameResolved: {
|
||||||
printf("Host name resolved\n");
|
printf("Host name resolved\n");
|
||||||
_inputField->SetText("Hostname resolve...");
|
auto name = message->GetString(UrlEventData::HostName);
|
||||||
_progress->SetTo(10);
|
message->PrintToStream();
|
||||||
|
|
||||||
|
_infoView->SetText("Hostname resolve...");
|
||||||
|
_infoView->SetText(name);
|
||||||
|
_progress->SetTo(5);
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case UrlEvent::ConnectionOpened: {
|
case UrlEvent::ConnectionOpened: {
|
||||||
printf("ConnectionOpened\n");
|
printf("ConnectionOpened\n");
|
||||||
_progress->SetTo(20);
|
_progress->SetTo(10);
|
||||||
_inputField->SetText("connection opened...");
|
_infoView->SetText("connection opened...");
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case UrlEvent::ResponseStarted: {
|
||||||
|
printf("ResponseStarted\n");
|
||||||
|
_progress->SetTo(14);
|
||||||
|
_infoView->SetText("ResponseStarted...");
|
||||||
} break;
|
} 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);
|
case UrlEvent::RequestCompleted: {
|
||||||
_progress->SetTo(100);
|
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;
|
} break;
|
||||||
|
|
||||||
case UrlEvent::BytesWritten: {
|
case UrlEvent::BytesWritten: {
|
||||||
|
_infoView->SetText("Some bytes written..");
|
||||||
// auto identifier = message->GetInt32(UrlEventData::Id, -1);
|
// auto identifier = message->GetInt32(UrlEventData::Id, -1);
|
||||||
// if (fResult.Identifier() == identifier) {
|
// if (fResult.Identifier() == identifier) {
|
||||||
off_t numBytes = message->GetInt64(UrlEventData::NumBytes, 0);
|
//off_t numBytes = message->GetInt64(UrlEventData::NumBytes, 0);
|
||||||
_progress->SetTo(numBytes);
|
//_progress->SetTo(numBytes);
|
||||||
//}
|
//}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case UrlEvent::DownloadProgress: {
|
case UrlEvent::DownloadProgress: {
|
||||||
// auto identifier = message->GetInt32(UrlEventData::Id, -1);
|
auto identifier = message->GetInt32(UrlEventData::Id, -1);
|
||||||
// if (fResult.Identifier() == identifier) {
|
if (resultOne->Identity() == identifier) {
|
||||||
off_t nn = message->GetInt64(UrlEventData::NumBytes, 0);
|
off_t nn = message->GetInt64(UrlEventData::NumBytes, 0);
|
||||||
off_t totalBytes = message->GetInt64(UrlEventData::TotalBytes, 0);
|
off_t totalBytes = message->GetInt64(UrlEventData::TotalBytes, 0);
|
||||||
_progress->SetMaxValue(totalBytes);
|
_progress->SetMaxValue(totalBytes);
|
||||||
_progress->SetTo(nn);
|
_progress->SetTo(nn);
|
||||||
//}
|
_infoView->SetText("Download Progress..");
|
||||||
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
BWindow::MessageReceived(message);
|
message->PrintToStream();
|
||||||
|
BWindow::MessageReceived(message); // call the parent handler for other messages
|
||||||
|
// _infoView->SetText(message->FindMessage());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
}//end switch
|
||||||
|
|
||||||
|
} //end function
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::sendQuery() {
|
void MainWindow::sendQuery() {
|
||||||
|
|
||||||
printf("Sending Prompt to server...\n");
|
//if (resultOne!=nullptr)
|
||||||
|
// _sharedSession.Cancel(resultOne->Identity());
|
||||||
|
|
||||||
_progress->SetMaxValue(100);
|
_progress->SetMaxValue(100);
|
||||||
_progress->SetTo(50);
|
_progress->SetTo(0);
|
||||||
|
|
||||||
auto url = BUrl("https://www.smallte.ch/");
|
auto url = BUrl("https://www.link-u.com/ip/");
|
||||||
auto request = BHttpRequest(url);
|
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
|
printf("Sending Prompt to server: %s\n", url.UrlString().String());
|
||||||
// window2
|
|
||||||
// BNetworkCookie cookie("key", "value", BUrl("https://example.com/"));
|
|
||||||
// session.AddCookie(std::move(cookie));
|
BHttpResult res = _sharedSession.Execute(std::move(request), nullptr, this);
|
||||||
_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 'File'
|
||||||
menu = new BMenu(B_TRANSLATE("File"));
|
menu = new BMenu(B_TRANSLATE("File"));
|
||||||
|
|
||||||
|
@ -189,7 +270,7 @@ BMenuBar *MainWindow::_BuildMenu() {
|
||||||
// menu->AddItem(item);
|
// menu->AddItem(item);
|
||||||
|
|
||||||
// item = new BMenuItem(B_TRANSLATE("Open" B_UTF8_ELLIPSIS),
|
// item = new BMenuItem(B_TRANSLATE("Open" B_UTF8_ELLIPSIS),
|
||||||
// new BMessage(kMsgOpenFile), 'O');
|
// new BMessage(kMsgOpenFile), 'O');
|
||||||
// menu->AddItem(item);
|
// menu->AddItem(item);
|
||||||
|
|
||||||
// fSaveMenuItem =
|
// fSaveMenuItem =
|
||||||
|
@ -198,17 +279,17 @@ BMenuBar *MainWindow::_BuildMenu() {
|
||||||
// menu->AddItem(fSaveMenuItem);
|
// menu->AddItem(fSaveMenuItem);
|
||||||
|
|
||||||
// menu->AddSeparatorItem();
|
// menu->AddSeparatorItem();
|
||||||
|
|
||||||
item = new BMenuItem(B_TRANSLATE("About" B_UTF8_ELLIPSIS),
|
item = new BMenuItem(B_TRANSLATE("About" B_UTF8_ELLIPSIS),
|
||||||
new BMessage(B_ABOUT_REQUESTED));
|
new BMessage(B_ABOUT_REQUESTED));
|
||||||
item->SetTarget(be_app);
|
item->SetTarget(be_app);
|
||||||
menu->AddItem(item);
|
menu->AddItem(item);
|
||||||
|
|
||||||
item =
|
item = new BMenuItem(B_TRANSLATE("Quit"), new BMessage(B_QUIT_REQUESTED), 'Q');
|
||||||
new BMenuItem(B_TRANSLATE("Quit"), new BMessage(B_QUIT_REQUESTED), 'Q');
|
|
||||||
menu->AddItem(item);
|
menu->AddItem(item);
|
||||||
|
|
||||||
menuBar->AddItem(menu);
|
menuBar->AddItem(menu);
|
||||||
|
|
||||||
return menuBar;
|
return menuBar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
32
MainWindow.h
32
MainWindow.h
|
@ -11,16 +11,26 @@
|
||||||
#include <StatusBar.h>
|
#include <StatusBar.h>
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//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 !
|
//From private headers !
|
||||||
//#include "/boot/system/develop/headers/private/netservices2/HttpRequest.h"
|
//#include <NetServicesDefs.h>
|
||||||
//#include "/boot/system/develop/headers/private/netservices2/ErrorsExt.h"
|
//#include <HttpSession.h>
|
||||||
|
//#include <HttpSession.h>
|
||||||
|
//#include <HttpRequest.h>
|
||||||
|
//#include <HttpResult.h>
|
||||||
//#include <ErrorsExt.h>
|
//#include <ErrorsExt.h>
|
||||||
#include <NetServicesDefs.h>
|
|
||||||
#include <HttpSession.h>
|
|
||||||
#include <HttpRequest.h>
|
|
||||||
#include <HttpResult.h>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
using namespace BPrivate::Network;
|
using namespace BPrivate::Network;
|
||||||
|
@ -35,9 +45,15 @@ public:
|
||||||
void sendQuery();
|
void sendQuery();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
BHttpSession _sharedSession = BHttpSession ();
|
||||||
|
|
||||||
|
BHttpResult* resultOne;
|
||||||
|
BHttpRequest* requestOne;
|
||||||
|
|
||||||
BMenuBar *_BuildMenu();
|
BMenuBar *_BuildMenu();
|
||||||
BHttpSession _sharedSession;
|
|
||||||
BTextView * _answerView;
|
BTextView * _answerView;
|
||||||
|
BTextView * _infoView;
|
||||||
BTextControl* _inputField;
|
BTextControl* _inputField;
|
||||||
BStatusBar* _progress;
|
BStatusBar* _progress;
|
||||||
BMenuItem *fSaveMenuItem;
|
BMenuItem *fSaveMenuItem;
|
||||||
|
|
5
Makefile
5
Makefile
|
@ -1,10 +1,11 @@
|
||||||
## Haiku Generic Makefile v2.6 ##
|
## Haiku Generic Makefile v2.6 ##
|
||||||
|
|
||||||
|
|
||||||
## Fill in this file to specify the project being created, and the referenced
|
## 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
|
## Makefile-Engine will do all of the hard work for you. This handles any
|
||||||
## architecture of Haiku.
|
## architecture of Haiku.
|
||||||
|
|
||||||
# The name of the binary.
|
# The name of the binary.
|
||||||
NAME = DumBer
|
NAME = DumBer
|
||||||
TARGET_DIR = .
|
TARGET_DIR = .
|
||||||
|
|
||||||
|
@ -109,7 +110,7 @@ SYMBOLS :=
|
||||||
DEBUGGER :=
|
DEBUGGER :=
|
||||||
|
|
||||||
# Specify any additional compiler flags to be used.
|
# Specify any additional compiler flags to be used.
|
||||||
COMPILER_FLAGS =
|
COMPILER_FLAGS =
|
||||||
|
|
||||||
# Specify any additional linker flags to be used.
|
# Specify any additional linker flags to be used.
|
||||||
LINKER_FLAGS =
|
LINKER_FLAGS =
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue