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
|
BAboutWindow* about
|
||||||
= new BAboutWindow(B_TRANSLATE_SYSTEM_NAME("DumBer"), kApplicationSignature);
|
= 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->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();
|
about->Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
BIN
DumBer
BIN
DumBer
Binary file not shown.
254
MainWindow.cpp
254
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.
|
* All rights reserved. Distributed under the terms of the MIT license.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "MainWindow.h"
|
#include "MainWindow.h"
|
||||||
|
|
||||||
|
#include <Url.h>
|
||||||
|
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
|
#include <Button.h>
|
||||||
#include <Catalog.h>
|
#include <Catalog.h>
|
||||||
#include <LayoutBuilder.h>
|
#include <LayoutBuilder.h>
|
||||||
#include <Menu.h>
|
#include <Menu.h>
|
||||||
#include <MenuBar.h>
|
#include <MenuBar.h>
|
||||||
#include <Button.h>
|
|
||||||
|
|
||||||
#include <View.h>
|
#include <View.h>
|
||||||
|
|
||||||
|
// #include <iostream>
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
|
using namespace BPrivate::Network;
|
||||||
|
|
||||||
#undef B_TRANSLATION_CONTEXT
|
#undef B_TRANSLATION_CONTEXT
|
||||||
#define B_TRANSLATION_CONTEXT "Window"
|
#define B_TRANSLATION_CONTEXT "Window"
|
||||||
|
|
||||||
|
@ -27,114 +33,182 @@ static const uint32 kMsgSaveFile = 'fsav';
|
||||||
static const uint32 kSendPrompt = 'kspt';
|
static const uint32 kSendPrompt = 'kspt';
|
||||||
static const uint32 kQuestionChanged = 'kqch';
|
static const uint32 kQuestionChanged = 'kqch';
|
||||||
|
|
||||||
|
|
||||||
MainWindow::MainWindow()
|
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)
|
|
||||||
{
|
|
||||||
BMenuBar* menuBar = _BuildMenu();
|
|
||||||
|
|
||||||
BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
|
auto sess = BHttpSession();
|
||||||
.Add(menuBar)
|
_sharedSession = sess;
|
||||||
.AddGlue()
|
|
||||||
.End();
|
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);
|
.AddGroup(B_HORIZONTAL, 0)
|
||||||
|
.Add(_answerView)
|
||||||
BButton *sendButton = new BButton("send",B_TRANSLATE("ask"),new BMessage(kSendPrompt), B_WILL_DRAW | B_NAVIGABLE);
|
.End()
|
||||||
|
|
||||||
|
.SetInsets(5, 5, 5, 5)
|
||||||
|
.End();
|
||||||
//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();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
printf("Sending Prompt to server...\n");
|
||||||
MainWindow::MessageReceived(BMessage* message)
|
|
||||||
{
|
_progress->SetMaxValue(100);
|
||||||
switch (message->what) {
|
_progress->SetTo(50);
|
||||||
case kMsgNewFile:
|
|
||||||
{
|
|
||||||
fSaveMenuItem->SetEnabled(false);
|
|
||||||
printf("New\n");
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case kMsgOpenFile:
|
auto url = BUrl("https://www.smallte.ch/");
|
||||||
{
|
auto request = BHttpRequest(std::move(url));
|
||||||
fSaveMenuItem->SetEnabled(true);
|
|
||||||
printf("Open\n");
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case kMsgSaveFile:
|
// Add a cookie to the session, this cookie will be used in window1 and
|
||||||
{
|
// window2
|
||||||
printf("Save\n");
|
// BNetworkCookie cookie("key", "value", BUrl("https://example.com/"));
|
||||||
} break;
|
// session.AddCookie(std::move(cookie));
|
||||||
|
|
||||||
case kSendPrompt:
|
_sharedSession.Execute(request, nullptr, this);
|
||||||
{
|
|
||||||
printf("Sending Prompt...");
|
|
||||||
|
|
||||||
} break;
|
|
||||||
|
|
||||||
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
BWindow::MessageReceived(message);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BMenuBar *MainWindow::_BuildMenu() {
|
||||||
|
BMenuBar *menuBar = new BMenuBar("menubar");
|
||||||
|
BMenu *menu;
|
||||||
|
BMenuItem *item;
|
||||||
|
|
||||||
BMenuBar*
|
// menu 'File'
|
||||||
MainWindow::_BuildMenu()
|
menu = new BMenu(B_TRANSLATE("File"));
|
||||||
{
|
|
||||||
BMenuBar* menuBar = new BMenuBar("menubar");
|
|
||||||
BMenu* menu;
|
|
||||||
BMenuItem* item;
|
|
||||||
|
|
||||||
// menu 'File'
|
// item = new BMenuItem(B_TRANSLATE("New"), new BMessage(kMsgNewFile), 'N');
|
||||||
menu = new BMenu(B_TRANSLATE("File"));
|
// menu->AddItem(item);
|
||||||
|
|
||||||
item = new BMenuItem(B_TRANSLATE("New"), new BMessage(kMsgNewFile), 'N');
|
// item = new BMenuItem(B_TRANSLATE("Open" B_UTF8_ELLIPSIS),
|
||||||
menu->AddItem(item);
|
// new BMessage(kMsgOpenFile), 'O');
|
||||||
|
// menu->AddItem(item);
|
||||||
|
|
||||||
item = new BMenuItem(B_TRANSLATE("Open" B_UTF8_ELLIPSIS), new BMessage(kMsgOpenFile), 'O');
|
// fSaveMenuItem =
|
||||||
menu->AddItem(item);
|
// 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');
|
// menu->AddSeparatorItem();
|
||||||
fSaveMenuItem->SetEnabled(false);
|
|
||||||
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("About" B_UTF8_ELLIPSIS), new BMessage(B_ABOUT_REQUESTED));
|
item =
|
||||||
item->SetTarget(be_app);
|
new BMenuItem(B_TRANSLATE("Quit"), new BMessage(B_QUIT_REQUESTED), 'Q');
|
||||||
menu->AddItem(item);
|
menu->AddItem(item);
|
||||||
|
|
||||||
item = new BMenuItem(B_TRANSLATE("Quit"), new BMessage(B_QUIT_REQUESTED), 'Q');
|
menuBar->AddItem(menu);
|
||||||
menu->AddItem(item);
|
|
||||||
|
|
||||||
menuBar->AddItem(menu);
|
return menuBar;
|
||||||
|
}
|
||||||
return menuBar;
|
|
||||||
}
|
|
39
MainWindow.h
39
MainWindow.h
|
@ -5,23 +5,42 @@
|
||||||
#ifndef MAINWINDOW_H
|
#ifndef MAINWINDOW_H
|
||||||
#define MAINWINDOW_H
|
#define MAINWINDOW_H
|
||||||
|
|
||||||
|
|
||||||
#include <MenuItem.h>
|
#include <MenuItem.h>
|
||||||
|
#include <TextControl.h>
|
||||||
|
#include <TextView.h>
|
||||||
|
#include <StatusBar.h>
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
|
||||||
|
|
||||||
class MainWindow : public BWindow
|
//From private headers !
|
||||||
{
|
//#include "/boot/system/develop/headers/private/netservices2/HttpRequest.h"
|
||||||
public:
|
//#include "/boot/system/develop/headers/private/netservices2/ErrorsExt.h"
|
||||||
MainWindow();
|
//#include <ErrorsExt.h>
|
||||||
virtual ~MainWindow();
|
#include <NetServicesDefs.h>
|
||||||
|
#include <HttpSession.h>
|
||||||
|
#include <HttpRequest.h>
|
||||||
|
#include <HttpResult.h>
|
||||||
|
|
||||||
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:
|
private:
|
||||||
BMenuBar* _BuildMenu();
|
BMenuBar *_BuildMenu();
|
||||||
|
BHttpSession _sharedSession;
|
||||||
BMenuItem* fSaveMenuItem;
|
BTextView * _answerView;
|
||||||
|
BTextControl* _inputField;
|
||||||
|
BStatusBar* _progress;
|
||||||
|
BMenuItem *fSaveMenuItem;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
9
Makefile
9
Makefile
|
@ -57,24 +57,25 @@ RSRCS =
|
||||||
# you need to specify the path to the library and it's name.
|
# 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")
|
# (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
|
# Specify additional paths to directories following the standard libXXX.so
|
||||||
# or libXXX.a naming scheme. You can specify full paths or paths relative
|
# or libXXX.a naming scheme. You can specify full paths or paths relative
|
||||||
# to the Makefile. The paths included are not parsed recursively, so
|
# to the Makefile. The paths included are not parsed recursively, so
|
||||||
# include all of the paths where libraries must be found. Directories where
|
# include all of the paths where libraries must be found. Directories where
|
||||||
# source files were specified are automatically included.
|
# source files were specified are automatically included.
|
||||||
LIBPATHS =
|
LIBPATHS =
|
||||||
|
|
||||||
# Additional paths to look for system headers. These use the form
|
# Additional paths to look for system headers. These use the form
|
||||||
# "#include <header>". Directories that contain the files in SRCS are
|
# "#include <header>". Directories that contain the files in SRCS are
|
||||||
# NOT auto-included here.
|
# 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
|
# Additional paths paths to look for local headers. These use the form
|
||||||
# #include "header". Directories that contain the files in SRCS are
|
# #include "header". Directories that contain the files in SRCS are
|
||||||
# automatically included.
|
# 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),
|
# Specify the level of optimization that you want. Specify either NONE (O0),
|
||||||
# SOME (O1), FULL (O2), or leave blank (for the default optimization level).
|
# 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;
|
resource app_flags B_SINGLE_LAUNCH;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue