Commit 1c20ac76 authored by Adrien Dorsaz's avatar Adrien Dorsaz

add User model

parent c576c318
......@@ -214,7 +214,6 @@ AccountAssistant::on_apply()
Settings settings;
settings.addAccount(jid->get_text(), websocket_uri->get_text());
settings.get_accounts();
assistant->hide();
......
......@@ -55,7 +55,16 @@ void
MainWindow::start_clients ()
{
// Read all accounts inside Settings
settings.get_accounts();
auto accounts = settings.get_accounts();
for (auto &account : std::as_const(accounts))
{
if (clients.count(account.first) == 0)
{
XmppClient client = {account.second};
clients.insert(std::make_pair(account.first, client));
}
}
}
void
......
......@@ -18,6 +18,12 @@
#pragma once
// cpp
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#include <gtkmm/builder.h>
#include <gtkmm/headerbar.h>
#include <gtkmm/menubutton.h>
......@@ -27,7 +33,6 @@
#include <gtkmm/stack.h>
#include <gtkmm/window.h>
#include <gtkmm/box.h>
#include <vector>
#include "../settings.h"
#include "../xmpp-client.h"
......@@ -63,7 +68,7 @@ private:
Settings settings;
std::vector<XmppClient> clients;
std::unordered_map<std::string, XmppClient> clients;
void toggle_search();
void toggle_searchbar();
......
......@@ -23,3 +23,9 @@ CallbackFactory::wellknown_websocket(SoupSession *session, SoupMessage *result,
{
static_cast<AccountAssistant*>(cb_pointer)->set_wellknown_websocket(session, result);
}
void
CallbackFactory::get_password (GObject *source, GAsyncResult *result, void * cb_pointer)
{
static_cast<XmppClient*>(cb_pointer)->get_password(source, result);
}
......@@ -19,10 +19,14 @@
#pragma once
#include "../controllers/account-assistant.h"
#include "../xmpp-client.h"
class CallbackFactory
{
public:
// Account assistant
static void wellknown_websocket (SoupSession *session, SoupMessage *result, void *cb_pointer);
// Xmpp client
static void get_password (GObject *source, GAsyncResult *result, void * cb_pointer);
};
......@@ -18,37 +18,14 @@
#include "xmpp-client.h"
XmppClient::XmppClient(ustring jid, ustring websocket_uri)
: jid {jid}
, websocket_uri {websocket_uri}
XmppClient::XmppClient(User account)
:account {account}
{
// Init soup session and logger
soup_session = soup_session_new_with_options (
SOUP_SESSION_USER_AGENT, "org.gnome.ibex/0.1.0",
NULL);
soup_logger = soup_logger_new(SOUP_LOGGER_LOG_BODY, -1);
soup_session_add_feature(soup_session, SOUP_SESSION_FEATURE(soup_logger));
// Retrieve domain from jid
set_domain();
}
XmppClient::XmppClient(XmppClient const &other)
:account {other.account}
{
jid = other.jid;
websocket_uri = other.websocket_uri;
// Init soup session and logger
soup_session = soup_session_new_with_options (
SOUP_SESSION_USER_AGENT, "org.gnome.ibex/0.1.0",
NULL);
soup_logger = soup_logger_new(SOUP_LOGGER_LOG_BODY, -1);
soup_session_add_feature(soup_session, SOUP_SESSION_FEATURE(soup_logger));
// Retrieve domain from jid
set_domain();
}
XmppClient::~XmppClient()
......@@ -59,44 +36,30 @@ XmppClient&
XmppClient::operator=(XmppClient const &other)
{
if (this != &other) {
jid = other.jid;
websocket_uri = other.websocket_uri;
// Init soup session and logger
soup_session = soup_session_new_with_options (
SOUP_SESSION_USER_AGENT, "org.gnome.ibex/0.1.0",
NULL);
soup_logger = soup_logger_new(SOUP_LOGGER_LOG_BODY, -1);
soup_session_add_feature(soup_session, SOUP_SESSION_FEATURE(soup_logger));
// Retrieve domain from jid
set_domain();
account = other.account;
}
return *this;
}
void
XmppClient::set_domain()
XmppClient::get_password (GObject *source, GAsyncResult *result)
{
auto pos = jid.find('@', 0);
user = jid.substr(0, pos);
domain = jid.substr(pos + 1, jid.length() - pos - 1);
g_log_structured (DEBUG_DOMAIN, G_LOG_LEVEL_DEBUG,
"MESSAGE", "jid <%s>, intiated with user <%s> and domain <%s>", jid.c_str(), user.c_str(), domain.c_str()
);
}
ustring
XmppClient::get_jid()
{
return jid;
}
void
XmppClient::connect()
{
// Open WebSocket connection
// Ask user password
// Init soup session and logger
soup_session = soup_session_new_with_options (
SOUP_SESSION_USER_AGENT, "org.gnome.ibex/0.1.0",
NULL);
soup_logger = soup_logger_new(SOUP_LOGGER_LOG_BODY, -1);
soup_session_add_feature(soup_session, SOUP_SESSION_FEATURE(soup_logger));
// Connect to server
}
......@@ -19,19 +19,20 @@
#pragma once
#include <giomm/inputstream.h>
#include <libsoup/soup.h>
#include <libsecret/secret.h>
#include <libsoup/soup.h>
#include <libxml++/libxml++.h>
#include "constants/xmpp.h"
#include "constants/oasis.h"
#include "models/user.h"
using Glib::ustring;
class XmppClient
{
public:
XmppClient(ustring jid, ustring websocket_uri);
XmppClient(User account);
XmppClient(XmppClient const &other);
~XmppClient();
......@@ -39,22 +40,28 @@ public:
XmppClient& operator=(XmppClient const &other);
// Start connection to WebSocket server
void get_password (GObject *source, GAsyncResult *result);
void connect();
ustring get_jid();
/*
static SecretSchema const secret_schema = {
"org.gnome.Ibex", SECRET_SCHEMA_NONE,
{
{"login", SECRET_SCHEMA_ATTRIBUTE_STRING},
{"type", SECRET_SCHEMA_ATTRIBUTE_STRING},
{"NULL", 0}
}
};
*/
private:
User account;
gchar const * const DEBUG_DOMAIN = {"xmpp-client"};
ustring jid;
ustring user;
ustring domain;
ustring websocket_uri;
xmlpp::DomParser dom_parser;
SoupSession *soup_session;
SoupLogger *soup_logger;
void set_domain();
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment