diff --git a/App.cpp b/App.cpp index c71e347..53407b4 100644 --- a/App.cpp +++ b/App.cpp @@ -35,9 +35,11 @@ App::AboutRequested() { BAboutWindow* about = new BAboutWindow(B_TRANSLATE_SYSTEM_NAME("DumBer"), kApplicationSignature); - about->AddDescription(B_TRANSLATE("Type text in there to feel dumber.")); + about->AddDescription(B_TRANSLATE("about_body")); about->AddCopyright(2024, "Santiago Lema"); - about->AddText("Ho"); + about->AddText("e-mail me at haiku@lema.org"); + about->AddText("or ping me on the fediverse on @santiago@masto.lema.org"); + about->Show(); } diff --git a/DumBer b/DumBer index f119170..e15edf5 100755 Binary files a/DumBer and b/DumBer differ diff --git a/MainWindow.cpp b/MainWindow.cpp index 6523f77..53d3b7d 100644 --- a/MainWindow.cpp +++ b/MainWindow.cpp @@ -1,22 +1,28 @@ /* - * Copyright 2024, My Name + * Copyright 2024, Santiago Lema * All rights reserved. Distributed under the terms of the MIT license. */ - #include "MainWindow.h" +#include + #include +#include #include #include #include #include -#include + #include +// #include + #include +using namespace BPrivate::Network; + #undef B_TRANSLATION_CONTEXT #define B_TRANSLATION_CONTEXT "Window" @@ -27,114 +33,182 @@ static const uint32 kMsgSaveFile = 'fsav'; static const uint32 kSendPrompt = 'kspt'; static const uint32 kQuestionChanged = 'kqch'; - MainWindow::MainWindow() - : - BWindow(BRect(100, 100, 600, 400), B_TRANSLATE("BeDumb"), B_TITLED_WINDOW, - B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE) -{ - BMenuBar* menuBar = _BuildMenu(); + : BWindow(BRect(100, 100, 600, 400), B_TRANSLATE("BeDumb"), B_TITLED_WINDOW, + B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE) { - BLayoutBuilder::Group<>(this, B_VERTICAL, 0) - .Add(menuBar) - .AddGlue() - .End(); + 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"); + _progress->SetMaxValue(100); + _progress->SetTo(0); + + _answerView = + new BTextView("answer", B_WILL_DRAW | B_FOLLOW_ALL_SIDES); + + 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(_inputField) + .AddGroup(B_VERTICAL,B_USE_DEFAULT_SPACING, 0.1f) + .Add(_progress) + .Add(sendButton) + .End() + .End() -BTextControl* input = new BTextControl(B_TRANSLATE("question"), "", new BMessage(kQuestionChanged)); -BTextView* answerView = new BTextView("answer", B_WILL_DRAW | B_FOLLOW_ALL_SIDES); - -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) - .Add(input) - .Add(sendButton) - .End() - .Add(answerView) - .SetInsets(5, 5, 5, 5) -.End(); - - + + .AddGroup(B_HORIZONTAL, 0) + .Add(_answerView) + .End() + + .SetInsets(5, 5, 5, 5) + .End(); } +MainWindow::~MainWindow() {} -MainWindow::~MainWindow() -{ +void MainWindow::MessageReceived(BMessage *message) { + switch (message->what) { + // case kMsgNewFile: { + // fSaveMenuItem->SetEnabled(false); + // printf("New\n"); + // } break; + + // case kMsgOpenFile: { + // fSaveMenuItem->SetEnabled(true); + // printf("Open\n"); + // } break; + + // case kMsgSaveFile: { + // printf("Save\n"); + // } break; + + case kQuestionChanged: { + printf("Question Changed\n"); + + sendQuery(); + + } break; + + case kSendPrompt: { + + printf("Button Pressed\n"); + sendQuery(); + + } break; + + case UrlEvent::HostNameResolved: { + printf("Host name resolved\n"); + _inputField->SetText("Hostname resolve..."); + _progress->SetTo(10); + + } break; + + case UrlEvent::ConnectionOpened: { + printf("ConnectionOpened\n"); + _progress->SetTo(20); + _inputField->SetText("connection opened..."); + } break; + + case UrlEvent::RequestCompleted: { + + printf("RequestCompleted\n"); + _inputField->SetText("Completed"); + _progress->SetMaxValue(100); + _progress->SetTo(100); + + } break; + + case UrlEvent::BytesWritten: { + // auto identifier = message->GetInt32(UrlEventData::Id, -1); + // if (fResult.Identifier() == identifier) { + 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); + off_t totalBytes = message->GetInt64(UrlEventData::TotalBytes, 0); + _progress->SetMaxValue(totalBytes); + _progress->SetTo(nn); + //} + } break; + + default: { + BWindow::MessageReceived(message); + break; + } + } } +void MainWindow::sendQuery() { -void -MainWindow::MessageReceived(BMessage* message) -{ - switch (message->what) { - case kMsgNewFile: - { - fSaveMenuItem->SetEnabled(false); - printf("New\n"); - } break; + printf("Sending Prompt to server...\n"); + + _progress->SetMaxValue(100); + _progress->SetTo(50); - case kMsgOpenFile: - { - fSaveMenuItem->SetEnabled(true); - printf("Open\n"); - } break; + auto url = BUrl("https://www.smallte.ch/"); + auto request = BHttpRequest(std::move(url)); - case kMsgSaveFile: - { - printf("Save\n"); - } break; + // 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)); - case kSendPrompt: - { - printf("Sending Prompt..."); - - } break; - - - default: - { - BWindow::MessageReceived(message); - break; - } - } + _sharedSession.Execute(request, nullptr, this); } +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")); - // menu 'File' - menu = new BMenu(B_TRANSLATE("File")); + // item = new BMenuItem(B_TRANSLATE("New"), new BMessage(kMsgNewFile), 'N'); + // menu->AddItem(item); - item = new BMenuItem(B_TRANSLATE("New"), new BMessage(kMsgNewFile), 'N'); - menu->AddItem(item); + // item = new BMenuItem(B_TRANSLATE("Open" B_UTF8_ELLIPSIS), + // new BMessage(kMsgOpenFile), 'O'); + // menu->AddItem(item); - item = new BMenuItem(B_TRANSLATE("Open" B_UTF8_ELLIPSIS), new BMessage(kMsgOpenFile), 'O'); - menu->AddItem(item); + // fSaveMenuItem = + // new BMenuItem(B_TRANSLATE("Save"), new BMessage(kMsgSaveFile), 'S'); + // fSaveMenuItem->SetEnabled(false); + // menu->AddItem(fSaveMenuItem); - fSaveMenuItem = new BMenuItem(B_TRANSLATE("Save"), new BMessage(kMsgSaveFile), 'S'); - fSaveMenuItem->SetEnabled(false); - menu->AddItem(fSaveMenuItem); + // menu->AddSeparatorItem(); - 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("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'); + menu->AddItem(item); - item = new BMenuItem(B_TRANSLATE("Quit"), new BMessage(B_QUIT_REQUESTED), 'Q'); - menu->AddItem(item); + menuBar->AddItem(menu); - menuBar->AddItem(menu); - - return menuBar; -} + return menuBar; +} \ No newline at end of file diff --git a/MainWindow.h b/MainWindow.h index a775010..2c00332 100644 --- a/MainWindow.h +++ b/MainWindow.h @@ -5,23 +5,42 @@ #ifndef MAINWINDOW_H #define MAINWINDOW_H - #include +#include +#include +#include #include -class MainWindow : public BWindow -{ -public: - MainWindow(); - virtual ~MainWindow(); +//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 - virtual void MessageReceived(BMessage* msg); + + +using namespace BPrivate::Network; + +class MainWindow : public BWindow { +public: + MainWindow(); + virtual ~MainWindow(); + + virtual void MessageReceived(BMessage *msg); + + void sendQuery(); private: - BMenuBar* _BuildMenu(); - - BMenuItem* fSaveMenuItem; + BMenuBar *_BuildMenu(); + BHttpSession _sharedSession; + BTextView * _answerView; + BTextControl* _inputField; + BStatusBar* _progress; + BMenuItem *fSaveMenuItem; }; #endif diff --git a/Makefile b/Makefile index a67ade3..d9b5293 100644 --- a/Makefile +++ b/Makefile @@ -57,24 +57,25 @@ RSRCS = # you need to specify the path to the library and it's name. # (e.g. for mylib.a, specify "mylib.a" or "path/mylib.a") -LIBS = be localestub $(STDCPPLIBS) +LIBS = be netservices2 localestub $(STDCPPLIBS) network bnetapi # Specify additional paths to directories following the standard libXXX.so # or libXXX.a naming scheme. You can specify full paths or paths relative # to the Makefile. The paths included are not parsed recursively, so # include all of the paths where libraries must be found. Directories where # source files were specified are automatically included. -LIBPATHS = +LIBPATHS = # Additional paths to look for system headers. These use the form # "#include
". Directories that contain the files in SRCS are # NOT auto-included here. -SYSTEM_INCLUDE_PATHS = $(shell findpaths -e B_FIND_PATH_HEADERS_DIRECTORY private/interface) +#SYSTEM_INCLUDE_PATHS = $(shell findpaths -e B_FIND_PATH_HEADERS_DIRECTORY private/interface) $(shell findpaths -e B_FIND_PATH_HEADERS_DIRECTORY private/netservices2) +SYSTEM_INCLUDE_PATHS = $(shell findpaths -e B_FIND_PATH_HEADERS_DIRECTORY private/interface) $(shell findpaths -e B_FIND_PATH_HEADERS_DIRECTORY private/netservices2) # Additional paths paths to look for local headers. These use the form # #include "header". Directories that contain the files in SRCS are # automatically included. -LOCAL_INCLUDE_PATHS = +LOCAL_INCLUDE_PATHS = /boot/system/developer/headers/privates/netservices2 # Specify the level of optimization that you want. Specify either NONE (O0), # SOME (O1), FULL (O2), or leave blank (for the default optimization level). diff --git a/Resources.rdef b/Resources.rdef index 8168d64..d15a1b6 100644 --- a/Resources.rdef +++ b/Resources.rdef @@ -1,4 +1,4 @@ -resource app_signature "application/x-vnd.MyName-MyApp"; +resource app_signature "application/x-vnd.SLema-DumBer"; resource app_flags B_SINGLE_LAUNCH;