threading something something threading
This commit is contained in:
parent
b9b1b50599
commit
996bc38052
6 changed files with 60 additions and 11 deletions
|
@ -1,9 +1,10 @@
|
||||||
#include "App.h"
|
#include "App.h"
|
||||||
#include "gui/MainWindow.h"
|
#include "gui/MainWindow.h"
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
App::App(void) : BApplication(kSignature)
|
App::App(void) : BApplication(kSignature)
|
||||||
{
|
{
|
||||||
MainWindow *mainWindow = new MainWindow(this);
|
MainWindow *mainWindow = new MainWindow();
|
||||||
mainWindow->Show();
|
mainWindow->Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,3 +16,4 @@ int main(void)
|
||||||
delete app;
|
delete app;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#ifndef APP_H
|
#ifndef APP_H
|
||||||
#define APP_H
|
#define APP_H
|
||||||
|
|
||||||
#include <Message.h>
|
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
#include <gloox/connectionlistener.h>
|
#include <gloox/connectionlistener.h>
|
||||||
#include <gloox/presencehandler.h>
|
#include <gloox/presencehandler.h>
|
||||||
|
|
|
@ -20,10 +20,9 @@
|
||||||
#include <TextControl.h>
|
#include <TextControl.h>
|
||||||
#include "Middleman.h"
|
#include "Middleman.h"
|
||||||
|
|
||||||
MainWindow::MainWindow(App *app)
|
MainWindow::MainWindow()
|
||||||
: BWindow(BRect(100, 100, 500, 400), "Renga", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE)
|
: BWindow(BRect(100, 100, 500, 400), "Renga", B_TITLED_WINDOW, B_QUIT_ON_WINDOW_CLOSE)
|
||||||
{
|
{
|
||||||
Application = app;
|
|
||||||
// parent layout (defines the entire window layout)
|
// parent layout (defines the entire window layout)
|
||||||
BGroupLayout *pGroup = new BGroupLayout(B_HORIZONTAL);
|
BGroupLayout *pGroup = new BGroupLayout(B_HORIZONTAL);
|
||||||
SetLayout(pGroup);
|
SetLayout(pGroup);
|
||||||
|
@ -76,7 +75,7 @@ void MainWindow::MessageReceived(BMessage *msg)
|
||||||
|
|
||||||
Hide();
|
Hide();
|
||||||
|
|
||||||
Middleman *middleman = new Middleman(JidInputBox->Text(), PwInputBox->Text(), Application);
|
Middleman *middleman = new Middleman(JidInputBox->Text(), PwInputBox->Text());
|
||||||
middleman->Show();
|
middleman->Show();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -14,7 +14,7 @@ const uint32 msgConnectButtonClicked = 'mCBC';
|
||||||
class MainWindow : public BWindow
|
class MainWindow : public BWindow
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MainWindow(App *app);
|
MainWindow();
|
||||||
virtual void MessageReceived(BMessage *msg);
|
virtual void MessageReceived(BMessage *msg);
|
||||||
private:
|
private:
|
||||||
App *Application;
|
App *Application;
|
||||||
|
|
|
@ -6,11 +6,19 @@
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
#include <StringView.h>
|
#include <StringView.h>
|
||||||
#include "../App.h"
|
#include "../App.h"
|
||||||
|
#include <cstdio>
|
||||||
#include <format>
|
#include <format>
|
||||||
|
#include <gloox/gloox.h>
|
||||||
|
#include <gloox/jid.h>
|
||||||
|
#include <gloox/client.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <ostream>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
// Connection middleman window.
|
// Connection middleman window.
|
||||||
// This window, when called, automatically sets up a connection to the XMPP server.
|
// This window, when called, automatically sets up a connection to the XMPP server.
|
||||||
Middleman::Middleman(const char* jid, const char* password, App *app)
|
|
||||||
|
Middleman::Middleman(const char* _jid, const char* password)
|
||||||
: BWindow(BRect(200,200,600,400), TITLE, B_TITLED_WINDOW, B_NOT_MINIMIZABLE | B_QUIT_ON_WINDOW_CLOSE)
|
: BWindow(BRect(200,200,600,400), TITLE, B_TITLED_WINDOW, B_NOT_MINIMIZABLE | B_QUIT_ON_WINDOW_CLOSE)
|
||||||
{
|
{
|
||||||
BGroupLayout *group = new BGroupLayout(B_VERTICAL);
|
BGroupLayout *group = new BGroupLayout(B_VERTICAL);
|
||||||
|
@ -19,5 +27,34 @@ Middleman::Middleman(const char* jid, const char* password, App *app)
|
||||||
group->View()->AdoptSystemColors();
|
group->View()->AdoptSystemColors();
|
||||||
|
|
||||||
group->AddView(new BStringView("label", "Placeholder label (connecting...)"));
|
group->AddView(new BStringView("label", "Placeholder label (connecting...)"));
|
||||||
group->AddView(new BStringView("label", std::format("JID: {}\nPassword: {}", jid, password).c_str()));
|
group->AddView(new BStringView("label", std::format("JID: {}\nPassword: {}", _jid, password).c_str()));
|
||||||
|
|
||||||
|
auto lambda = [](Middleman *mm, const char *_jid, const char *password) {
|
||||||
|
gloox::JID jid(std::format("{}/{}", _jid, appName));
|
||||||
|
mm->client = new gloox::Client(jid, password);
|
||||||
|
mm->client->registerConnectionListener(mm);
|
||||||
|
mm->client->registerPresenceHandler(mm);
|
||||||
|
mm->client->connect(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
std::thread tobj(lambda, this, _jid, password);
|
||||||
|
tobj.detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Middleman::onDisconnect(gloox::ConnectionError err)
|
||||||
|
{
|
||||||
|
std::cout << "err: " << err << std::endl;
|
||||||
|
};
|
||||||
|
void Middleman::handlePresence(const gloox::Presence &presence)
|
||||||
|
{
|
||||||
|
std::cout << "meow 1";
|
||||||
|
};
|
||||||
|
bool Middleman::onTLSConnect(const gloox::CertInfo &info)
|
||||||
|
{
|
||||||
|
std::cout << "meow 1";
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
void Middleman::onConnect()
|
||||||
|
{
|
||||||
|
std::cout << "meow 333";
|
||||||
|
};
|
||||||
|
|
|
@ -2,15 +2,27 @@
|
||||||
#define MIDDLEMAN_H
|
#define MIDDLEMAN_H
|
||||||
|
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
#include "../App.h"
|
#include <gloox/connectionlistener.h>
|
||||||
|
#include <gloox/gloox.h>
|
||||||
|
#include <gloox/presence.h>
|
||||||
|
#include <gloox/presencehandler.h>
|
||||||
|
#include <gloox/client.h>
|
||||||
#define TITLE "Connecting..."
|
#define TITLE "Connecting..."
|
||||||
|
|
||||||
// Middleman is the "middle" window that sets up the XMPP connection and manages all windows that require one.
|
// Middleman is the "middle" window that sets up the XMPP connection and manages all windows that require one.
|
||||||
|
// Windows are designed to be opened up in a "flow"
|
||||||
|
// Main (login) window -> Middleman <-> Contacts List <-> Chatbox
|
||||||
// TODO: add client class to mm class for windows to send message
|
// TODO: add client class to mm class for windows to send message
|
||||||
|
|
||||||
class Middleman : public BWindow {
|
class Middleman : public BWindow, gloox::PresenceHandler, gloox::ConnectionListener {
|
||||||
public:
|
public:
|
||||||
Middleman(const char* jid, const char* password, App *app);
|
Middleman(const char* jid, const char* password);
|
||||||
|
virtual void handlePresence(const gloox::Presence &presence);
|
||||||
|
virtual bool onTLSConnect(const gloox::CertInfo &info);
|
||||||
|
virtual void onConnect();
|
||||||
|
virtual void onDisconnect(gloox::ConnectionError err);
|
||||||
|
private:
|
||||||
|
gloox::Client *client;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue