added new libs to get web data
This commit is contained in:
		
							parent
							
								
									13fb5cf3b3
								
							
						
					
					
						commit
						7cb8eecde9
					
				
					 6 changed files with 203 additions and 107 deletions
				
			
		
							
								
								
									
										6
									
								
								App.cpp
									
										
									
									
									
								
							
							
						
						
									
										6
									
								
								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(); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										
											BIN
										
									
								
								DumBer
									
										
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								DumBer
									
										
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										196
									
								
								MainWindow.cpp
									
										
									
									
									
								
							
							
						
						
									
										196
									
								
								MainWindow.cpp
									
										
									
									
									
								
							|  | @ -1,22 +1,28 @@ | |||
| /*
 | ||||
|  * Copyright 2024, My Name <my@email.address> | ||||
|  * Copyright 2024, Santiago Lema <santiago@lema.org> | ||||
|  * All rights reserved. Distributed under the terms of the MIT license. | ||||
|  */ | ||||
| 
 | ||||
| 
 | ||||
| #include "MainWindow.h" | ||||
| 
 | ||||
| #include <Url.h> | ||||
| 
 | ||||
| #include <Application.h> | ||||
| #include <Button.h> | ||||
| #include <Catalog.h> | ||||
| #include <LayoutBuilder.h> | ||||
| #include <Menu.h> | ||||
| #include <MenuBar.h> | ||||
| #include <Button.h> | ||||
| 
 | ||||
| 
 | ||||
| #include <View.h> | ||||
| 
 | ||||
| // #include <iostream>
 | ||||
| 
 | ||||
| #include <cstdio> | ||||
| 
 | ||||
| using namespace BPrivate::Network; | ||||
| 
 | ||||
| #undef B_TRANSLATION_CONTEXT | ||||
| #define B_TRANSLATION_CONTEXT "Window" | ||||
| 
 | ||||
|  | @ -27,87 +33,151 @@ 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) | ||||
| { | ||||
|     : 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(); | ||||
|   BLayoutBuilder::Group<>(this, B_VERTICAL, 0).Add(menuBar).AddGlue().End(); | ||||
| 
 | ||||
|   _inputField = new BTextControl(B_TRANSLATE("question"), "", | ||||
|                                  new BMessage(kQuestionChanged)); | ||||
| 								  | ||||
| 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); | ||||
|   _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) | ||||
| 	 .Add(input) | ||||
|    | ||||
|       .AddGroup(B_HORIZONTAL, 0,1) | ||||
|       .Add(_inputField) | ||||
|       .AddGroup(B_VERTICAL,B_USE_DEFAULT_SPACING, 0.1f) | ||||
|       .Add(_progress) | ||||
|       .Add(sendButton) | ||||
|       .End() | ||||
| 	.Add(answerView) | ||||
|       .End() | ||||
| 
 | ||||
| 
 | ||||
| 	   | ||||
|       .AddGroup(B_HORIZONTAL, 0) | ||||
|       .Add(_answerView) | ||||
|       .End() | ||||
| 	   | ||||
|       .SetInsets(5, 5, 5, 5) | ||||
|       .End(); | ||||
| 
 | ||||
| 		 | ||||
| } | ||||
| 
 | ||||
| MainWindow::~MainWindow() {} | ||||
| 
 | ||||
| MainWindow::~MainWindow() | ||||
| { | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| void | ||||
| MainWindow::MessageReceived(BMessage* message) | ||||
| { | ||||
| void MainWindow::MessageReceived(BMessage *message) { | ||||
|   switch (message->what) { | ||||
| 		case kMsgNewFile: | ||||
| 		{ | ||||
| 			fSaveMenuItem->SetEnabled(false); | ||||
| 			printf("New\n"); | ||||
| 		} break; | ||||
|     //  case kMsgNewFile: {
 | ||||
|     //    fSaveMenuItem->SetEnabled(false);
 | ||||
|     //    printf("New\n");
 | ||||
|     //  } break;
 | ||||
| 
 | ||||
| 		case kMsgOpenFile: | ||||
| 		{ | ||||
| 			fSaveMenuItem->SetEnabled(true); | ||||
| 			printf("Open\n"); | ||||
| 		} break; | ||||
|     //  case kMsgOpenFile: {
 | ||||
|     //    fSaveMenuItem->SetEnabled(true);
 | ||||
|     //    printf("Open\n");
 | ||||
|     //  } break;
 | ||||
| 
 | ||||
| 		case kMsgSaveFile: | ||||
| 		{ | ||||
| 			printf("Save\n"); | ||||
| 		} break; | ||||
|     //  case kMsgSaveFile: {
 | ||||
|     //    printf("Save\n");
 | ||||
|     //  } break;
 | ||||
| 
 | ||||
| 		case kSendPrompt: | ||||
| 		{ | ||||
| 			printf("Sending Prompt..."); | ||||
|   case kQuestionChanged: { | ||||
|     printf("Question Changed\n"); | ||||
| 
 | ||||
|     sendQuery(); | ||||
| 
 | ||||
|   } break; | ||||
| 
 | ||||
|   case kSendPrompt: { | ||||
| 
 | ||||
| 		default: | ||||
| 		{ | ||||
|     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() { | ||||
| 
 | ||||
| BMenuBar* | ||||
| MainWindow::_BuildMenu() | ||||
| { | ||||
|   printf("Sending Prompt to server...\n"); | ||||
|    | ||||
|   _progress->SetMaxValue(100); | ||||
|   _progress->SetTo(50); | ||||
| 
 | ||||
|   auto url = BUrl("https://www.smallte.ch/"); | ||||
|   auto request = BHttpRequest(std::move(url)); | ||||
| 
 | ||||
|   // 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(request, nullptr, this); | ||||
| } | ||||
| 
 | ||||
| BMenuBar *MainWindow::_BuildMenu() { | ||||
|   BMenuBar *menuBar = new BMenuBar("menubar"); | ||||
|   BMenu *menu; | ||||
|   BMenuItem *item; | ||||
|  | @ -115,23 +185,27 @@ MainWindow::_BuildMenu() | |||
|   // 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 = 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); | ||||
|  |  | |||
							
								
								
									
										27
									
								
								MainWindow.h
									
										
									
									
									
								
							
							
						
						
									
										27
									
								
								MainWindow.h
									
										
									
									
									
								
							|  | @ -5,22 +5,41 @@ | |||
| #ifndef MAINWINDOW_H | ||||
| #define MAINWINDOW_H | ||||
| 
 | ||||
| 
 | ||||
| #include <MenuItem.h> | ||||
| #include <TextControl.h> | ||||
| #include <TextView.h> | ||||
| #include <StatusBar.h> | ||||
| #include <Window.h> | ||||
| 
 | ||||
| 
 | ||||
| class MainWindow : public BWindow | ||||
| { | ||||
| //From private headers !
 | ||||
| //#include "/boot/system/develop/headers/private/netservices2/HttpRequest.h"
 | ||||
| //#include "/boot/system/develop/headers/private/netservices2/ErrorsExt.h"
 | ||||
| //#include <ErrorsExt.h>
 | ||||
| #include <NetServicesDefs.h> | ||||
| #include <HttpSession.h> | ||||
| #include <HttpRequest.h> | ||||
| #include <HttpResult.h> | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| using namespace BPrivate::Network; | ||||
| 
 | ||||
| class MainWindow : public BWindow { | ||||
| public: | ||||
|   MainWindow(); | ||||
|   virtual ~MainWindow(); | ||||
| 
 | ||||
|   virtual void MessageReceived(BMessage *msg); | ||||
| 
 | ||||
|   void 	sendQuery(); | ||||
| 
 | ||||
| private: | ||||
|   BMenuBar *_BuildMenu(); | ||||
| 
 | ||||
|   BHttpSession _sharedSession; | ||||
|   BTextView * _answerView; | ||||
|   BTextControl* _inputField; | ||||
|   BStatusBar* _progress; | ||||
|   BMenuItem *fSaveMenuItem; | ||||
| }; | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										7
									
								
								Makefile
									
										
									
									
									
								
							
							
						
						
									
										7
									
								
								Makefile
									
										
									
									
									
								
							|  | @ -57,7 +57,7 @@ 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
 | ||||
|  | @ -69,12 +69,13 @@ LIBPATHS = | |||
| #	Additional paths to look for system headers. These use the form
 | ||||
| #	"#include <header>". 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).
 | ||||
|  |  | |||
|  | @ -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; | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue