Showing with 145 additions and 44 deletions.
  1. +1 −1 jabber/BlabberApp.cpp
  2. +23 −19 jabber/JabberSpeak.cpp
  3. +2 −4 jabber/JabberSpeak.h
  4. +0 −1 jabber/Messages.h
  5. +116 −18 ui/MainWindow.cpp
  6. +3 −1 ui/MainWindow.h
2 changes: 1 addition & 1 deletion jabber/BlabberApp.cpp
Expand Up @@ -28,7 +28,7 @@ BlabberApp::BlabberApp()
BlabberMainWindow::Instance()->Show();

// launch initial login process
JabberSpeak::Instance()->SendConnect();
JabberSpeak::Instance()->SendConnect("", "");
}

BlabberApp::~BlabberApp() {
Expand Down
42 changes: 23 additions & 19 deletions jabber/JabberSpeak.cpp
Expand Up @@ -167,9 +167,20 @@ void JabberSpeak::SendConnect(std::string username, std::string password, std::s
_curr_login = username;
_password = password;

// PLACEHOLDER
// spawn listener thread (communication from remote machine)
resume_thread(_connection_thread_id = spawn_thread(JabberSpeak::_SpawnConnectionThread, "connection_listener", B_LOW_PRIORITY, this));
resume_thread(_connection_thread_id = spawn_thread(JabberSpeak::_SpawnConnectionThread,
"connection_listener", B_LOW_PRIORITY, this));
}

void JabberSpeak::SendConnect(std::string realname)
{
_curr_realname = realname;
_curr_login = "";
_password = "";

// spawn listener thread (communication from remote machine)
resume_thread(_connection_thread_id = spawn_thread(JabberSpeak::_SpawnConnectionThread,
"connection_listener", B_LOW_PRIORITY, this));
}


Expand All @@ -181,22 +192,15 @@ int32 JabberSpeak::_SpawnConnectionThread(void *obj) {
}


std::string
JabberSpeak::GetRealServer()
void JabberSpeak::_ConnectionThread()
{
return gloox::JID(_curr_login).server();
}

int
JabberSpeak::GetRealPort()
{
return 5222; //default jabber port.
}


void JabberSpeak::_ConnectionThread() {
gloox::JID jid(_curr_login);
fClient = new gloox::Client(jid, _password);
if (_curr_login == "") {
fClient = new gloox::Client("anon.jabberfr.org");
fClient->setSASLMechanisms(gloox::SaslMechAnonymous);
} else {
gloox::JID jid(_curr_login);
fClient = new gloox::Client(jid, _password);
}

// Prepare for handling carbons
fClient->registerStanzaExtension(new gloox::Forward());
Expand All @@ -207,7 +211,7 @@ void JabberSpeak::_ConnectionThread() {

// Register for logging
fClient->logInstance().registerLogHandler(gloox::LogLevelDebug,
gloox::LogAreaXmlIncoming, new LogHandler);
gloox::LogAreaXmlIncoming | gloox::LogAreaXmlOutgoing, new LogHandler());

// Register for connection events
fClient->registerConnectionListener(this);
Expand Down Expand Up @@ -464,7 +468,7 @@ JabberSpeak::onDisconnect(gloox::ConnectionError e)
// reset networking
Reset();

SendConnect();
SendConnect(_curr_login, _password, _curr_realname);
}
}

Expand Down
6 changes: 2 additions & 4 deletions jabber/JabberSpeak.h
Expand Up @@ -52,8 +52,9 @@ class JabberSpeak : public BHandler,
void JabberSpeakReset();

// OUTGOING COMMUNICATION
void SendConnect(std::string username = "", std::string password = "",
void SendConnect(std::string username, std::string password,
std::string realname = "", bool suppress_auto_connect = false);
void SendConnect(std::string realname);
void SendDisconnect();
void SendSubscriptionRequest(std::string username);
void SendUnsubscriptionRequest(std::string username);
Expand All @@ -78,9 +79,6 @@ class JabberSpeak : public BHandler,
const std::string CurrentRealName() const;
const std::string CurrentLogin() const;

std::string GetRealServer();
int GetRealPort();

// gloox::ConnectionListener
void onConnect() final;
void onDisconnect(gloox::ConnectionError e) final;
Expand Down
1 change: 0 additions & 1 deletion jabber/Messages.h
Expand Up @@ -72,7 +72,6 @@
#define JAB_USER_INFO 0x15007000

// jabber
#define JAB_CONNECT 0x16000000
#define JAB_RECONNECTING 0x16000002
#define JAB_RESET 0x16001000
#define JAB_DISCONNECT 0x16002000
Expand Down
134 changes: 116 additions & 18 deletions ui/MainWindow.cpp
Expand Up @@ -40,6 +40,7 @@
#include <MenuItem.h>
#include <be_apps/NetPositive/NetPositive.h>
#include <Path.h>
#include <RadioButton.h>
#include <Roster.h>
#include <ScrollView.h>
#include <String.h>
Expand All @@ -53,7 +54,11 @@

enum {
kCreateAccount = 'crea',
kSelectExistingAccount = 'sexa'
kSelectExistingAccount = 'sexa',

kRadioCreateAccount = 'rcra',
kRadioUseAccount = 'ruea',
kRadioNoAccount = 'rnoa'
};


Expand Down Expand Up @@ -103,6 +108,25 @@ BlabberMainWindow::~BlabberMainWindow() {
_instance = NULL;
}


void
BlabberMainWindow::LoginSetNoAccount()
{
while (_login_realname->IsHidden())
_login_realname->Show();
while (!_login_username->IsHidden())
_login_username->Hide();
while (!_login_password->IsHidden())
_login_password->Hide();
while (_login_auto_login->IsHidden())
_login_auto_login->Show();
while (fAnonymousLimitationsWarning->IsHidden())
fAnonymousLimitationsWarning->Show();
_login_login->SetMessage(new BMessage(JAB_LOGIN));
_login_login->SetLabel(B_TRANSLATE("Connect"));
}


void BlabberMainWindow::MessageReceived(BMessage *msg) {
switch (msg->what) {

Expand All @@ -129,20 +153,67 @@ void BlabberMainWindow::MessageReceived(BMessage *msg) {
break;
}

case kRadioCreateAccount:
{
while (!_login_realname->IsHidden())
_login_realname->Hide();
while (!_login_username->IsHidden())
_login_username->Hide();
while (!_login_password->IsHidden())
_login_password->Hide();
while (!_login_auto_login->IsHidden())
_login_auto_login->Hide();
while (!fAnonymousLimitationsWarning->IsHidden())
fAnonymousLimitationsWarning->Hide();
_login_login->SetMessage(new BMessage(kCreateAccount));
_login_login->SetLabel(B_TRANSLATE("Create a new account"));
break;
}

case kRadioUseAccount:
{
while (_login_realname->IsHidden())
_login_realname->Show();
while (_login_username->IsHidden())
_login_username->Show();
while (_login_password->IsHidden())
_login_password->Show();
while (_login_auto_login->IsHidden())
_login_auto_login->Show();
while (!fAnonymousLimitationsWarning->IsHidden())
fAnonymousLimitationsWarning->Hide();
_login_login->SetMessage(new BMessage(JAB_LOGIN));
_login_login->SetLabel(B_TRANSLATE("Login"));
break;
}

case kRadioNoAccount:
{
LoginSetNoAccount();
break;
}

// transplanted from LoginWindow
case JAB_LOGIN: {
_status_view->SetText(B_TRANSLATE("Connecting" B_UTF8_ELLIPSIS));
// must pass validation
if (!ValidateLogin()) {
break;
}

bool anonymous = _login_password->IsHidden();

// switch out views
_login_login->MakeDefault(false);
BCardLayout* cl = (BCardLayout*)GetLayout();
cl->SetVisibleItem((int32)0);

// connect with current username or register new account
JabberSpeak::Instance()->SendConnect(_login_username->Text(), _login_password->Text(), _login_realname->Text());
// connect with current username
if (anonymous) {
JabberSpeak::Instance()->SendConnect(_login_realname->Text());
} else {
JabberSpeak::Instance()->SendConnect(_login_username->Text(), _login_password->Text(), _login_realname->Text());
}

break;
}
Expand All @@ -163,13 +234,6 @@ void BlabberMainWindow::MessageReceived(BMessage *msg) {
break;
}

case JAB_CONNECT: {
_status_view->SetText(B_TRANSLATE("Connecting" B_UTF8_ELLIPSIS));
JabberSpeak::Instance()->SendConnect("", "", "", true);

break;
}

case JAB_RECONNECTING: {
// we are connecting
_status_view->SetText(B_TRANSLATE("Reconnecting" B_UTF8_ELLIPSIS));
Expand Down Expand Up @@ -922,10 +986,6 @@ BlabberMainWindow::BlabberMainWindow(BRect frame)
_login_password = new BTextControl(NULL, B_TRANSLATE("Password:"), NULL, NULL);
_login_password->TextView()->HideTyping(true);

BMessage* createAccount = new BMessage(kCreateAccount);
_login_new_account = new BButton("create", B_TRANSLATE("Create a new account"),
createAccount);

_login_auto_login = new BCheckBox(NULL, B_TRANSLATE("Auto-login"), NULL);

// login button
Expand All @@ -942,6 +1002,20 @@ BlabberMainWindow::BlabberMainWindow(BRect frame)
BStringView* tagline = new BStringView("", B_TRANSLATE("An XMPP client for Haiku"));
tagline->SetAlignment(B_ALIGN_CENTER);

BRadioButton* useAccount = new BRadioButton("", B_TRANSLATE("Use existing account"),
new BMessage(kRadioUseAccount));
BRadioButton* noAccount = new BRadioButton("", B_TRANSLATE("Start chatting without account"),
new BMessage(kRadioNoAccount));

fAnonymousLimitationsWarning = new BTextView("anonymous warning");
fAnonymousLimitationsWarning->SetText(B_TRANSLATE("To avoid spam and limit abusive behavior, "
"anonymous users are restricted to a single server and cannot reach all of the XMPP "
"network."
));
fAnonymousLimitationsWarning->MakeEditable(false);
fAnonymousLimitationsWarning->MakeSelectable(false);
fAnonymousLimitationsWarning->SetViewUIColor(B_PANEL_BACKGROUND_COLOR);

BLayoutBuilder::Group<>(_login_full_view, B_VERTICAL)
.SetInsets(B_USE_DEFAULT_SPACING)
.AddGroup(B_HORIZONTAL)
Expand All @@ -950,15 +1024,24 @@ BlabberMainWindow::BlabberMainWindow(BRect frame)
.Add(_login_bulb, 0, 0, 1, 1)
.Add(appName, 1, 0)
.Add(tagline, 0, 1, 2, 1)
.AddGlue(0, 2, 2, 1)
.Add(_login_new_account, 0, 3, 2, 1)
.End()
.AddGlue()
.End()
.AddGlue(1)
.AddStrut(B_USE_WINDOW_SPACING)
.AddGroup(B_HORIZONTAL)
.AddGlue(0)
.AddGroup(B_VERTICAL, B_USE_DEFAULT_SPACING)
.AddGroup(B_VERTICAL, B_USE_SMALL_SPACING)
.Add(new BRadioButton("", B_TRANSLATE("Create an account"),
new BMessage(kRadioCreateAccount)))
.Add(useAccount)
.Add(noAccount)
.End()
.AddGlue(0)
.End()
.AddStrut(B_USE_WINDOW_SPACING)
.AddGroup(B_HORIZONTAL)
.AddGlue(0)
.AddGroup(B_VERTICAL, B_USE_SMALL_SPACING)
.AddGrid(1, B_USE_SMALL_SPACING)
.SetExplicitMaxSize(BSize(_login_username->StringWidth("x") * 50, B_SIZE_UNSET))
.AddTextControl(_login_realname, 0, 0)
Expand All @@ -973,6 +1056,7 @@ BlabberMainWindow::BlabberMainWindow(BRect frame)
.End()
.AddGlue(0)
.End()
.Add(fAnonymousLimitationsWarning)
.AddGlue()
.End();

Expand Down Expand Up @@ -1003,9 +1087,23 @@ BlabberMainWindow::BlabberMainWindow(BRect frame)
BString password;
uint32 cookie = 0;

bool hasAccounts = false;

while (keystore.GetNextKey("XMPP", B_KEY_TYPE_PASSWORD, B_KEY_PURPOSE_GENERIC, cookie,
passwordkey) == B_OK) {
_login_username->AddEntry(passwordkey.Identifier());
hasAccounts = true;
}

if (hasAccounts) {
useAccount->SetValue(B_CONTROL_ON);
fAnonymousLimitationsWarning->Hide();
} else {
noAccount->SetValue(B_CONTROL_ON);
_login_username->Hide();
_login_password->Hide();
_login_login->SetMessage(new BMessage(JAB_LOGIN));
_login_login->SetLabel(B_TRANSLATE("Connect"));
}

if (keystore.GetKey("XMPP", B_KEY_TYPE_PASSWORD, _login_username->Text(), passwordkey) == B_OK) {
Expand Down
4 changes: 3 additions & 1 deletion ui/MainWindow.h
Expand Up @@ -51,6 +51,8 @@ class BlabberMainWindow : public BWindow {
void FlagBookmarkItem(const gloox::JID& room, uint32 flags);
void AddTalkView(TalkView* view);

void LoginSetNoAccount();

private:
// singleton
static BlabberMainWindow *_instance;
Expand All @@ -62,8 +64,8 @@ class BlabberMainWindow : public BWindow {
BTextControl *_login_realname;
PopupTextControl *_login_username;
BTextControl *_login_password;
BTextView *fAnonymousLimitationsWarning;

BButton *_login_new_account;
BCheckBox *_login_auto_login;

BButton *_login_login;
Expand Down