optimise tree view a tiny bit
don't refresh all the time, wait for the data to be ready. waiting on the data is not a good idea either, but it is better than to continously refresh all the data
This commit is contained in:
parent
af49931b49
commit
a9f23fc278
@ -45,6 +45,12 @@ bool dc_session_logout(dc_session_t s);
|
|||||||
*/
|
*/
|
||||||
bool dc_session_login(dc_session_t s, dc_account_t login);
|
bool dc_session_login(dc_session_t s, dc_account_t login);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the session is ready, i.e. a login has been performed
|
||||||
|
* and the READY event has been parsed from the websocket.
|
||||||
|
*/
|
||||||
|
bool dc_session_is_ready(dc_session_t s);
|
||||||
|
|
||||||
bool dc_session_has_token(dc_session_t s);
|
bool dc_session_has_token(dc_session_t s);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -9,6 +9,7 @@ struct dc_session_
|
|||||||
dc_api_t api;
|
dc_api_t api;
|
||||||
dc_account_t login;
|
dc_account_t login;
|
||||||
dc_gateway_t gateway;
|
dc_gateway_t gateway;
|
||||||
|
bool ready;
|
||||||
|
|
||||||
GHashTable *accounts;
|
GHashTable *accounts;
|
||||||
GHashTable *channels;
|
GHashTable *channels;
|
||||||
@ -161,6 +162,8 @@ static void dc_session_handle_ready(dc_session_t s, dc_event_t e)
|
|||||||
dc_session_add_channel(s, chan);
|
dc_session_add_channel(s, chan);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s->ready = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dc_session_handler(dc_gateway_t gw, dc_event_t e, void *p)
|
static void dc_session_handler(dc_gateway_t gw, dc_event_t e, void *p)
|
||||||
@ -237,6 +240,8 @@ bool dc_session_logout(dc_session_t s)
|
|||||||
s->gateway = NULL;
|
s->gateway = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s->ready = false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,6 +253,8 @@ bool dc_session_login(dc_session_t s, dc_account_t login)
|
|||||||
dc_session_logout(s);
|
dc_session_logout(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s->ready = false;
|
||||||
|
|
||||||
s->login = dc_ref(login);
|
s->login = dc_ref(login);
|
||||||
if (!dc_account_has_token(login)) {
|
if (!dc_account_has_token(login)) {
|
||||||
if (!dc_api_authenticate(s->api, s->login)) {
|
if (!dc_api_authenticate(s->api, s->login)) {
|
||||||
@ -276,6 +283,12 @@ bool dc_session_has_token(dc_session_t s)
|
|||||||
return dc_account_has_token(s->login);
|
return dc_account_has_token(s->login);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool dc_session_is_ready(dc_session_t s)
|
||||||
|
{
|
||||||
|
return_if_true(s == NULL, false);
|
||||||
|
return s->ready;
|
||||||
|
}
|
||||||
|
|
||||||
dc_api_t dc_session_api(dc_session_t s)
|
dc_api_t dc_session_api(dc_session_t s)
|
||||||
{
|
{
|
||||||
return_if_true(s == NULL, NULL);
|
return_if_true(s == NULL, NULL);
|
||||||
|
@ -17,6 +17,7 @@ void ncdc_treeitem_set_label(ncdc_treeitem_t i, wchar_t const *s);
|
|||||||
void *ncdc_treeitem_tag(ncdc_treeitem_t i);
|
void *ncdc_treeitem_tag(ncdc_treeitem_t i);
|
||||||
void ncdc_treeitem_set_tag(ncdc_treeitem_t i, void *t);
|
void ncdc_treeitem_set_tag(ncdc_treeitem_t i, void *t);
|
||||||
|
|
||||||
|
size_t ncdc_treeitem_size(ncdc_treeitem_t i);
|
||||||
void ncdc_treeitem_clear(ncdc_treeitem_t i);
|
void ncdc_treeitem_clear(ncdc_treeitem_t i);
|
||||||
void ncdc_treeitem_add(ncdc_treeitem_t i, ncdc_treeitem_t c);
|
void ncdc_treeitem_add(ncdc_treeitem_t i, ncdc_treeitem_t c);
|
||||||
void ncdc_treeitem_remove(ncdc_treeitem_t i, ncdc_treeitem_t c);
|
void ncdc_treeitem_remove(ncdc_treeitem_t i, ncdc_treeitem_t c);
|
||||||
|
@ -50,7 +50,16 @@ bool ncdc_cmd_login(ncdc_mainwindow_t n, size_t ac,
|
|||||||
dc_unref(current_session);
|
dc_unref(current_session);
|
||||||
current_session = dc_ref(s);
|
current_session = dc_ref(s);
|
||||||
|
|
||||||
LOG(n, L"login: %ls: authentication successful, waiting for data...", av[1]);
|
LOG(n, L"login: %ls: authentication successful, waiting for ready from websocket...",
|
||||||
|
av[1]
|
||||||
|
);
|
||||||
|
|
||||||
|
while (!dc_session_is_ready(current_session))
|
||||||
|
;
|
||||||
|
|
||||||
|
LOG(n, L"login: %ls: ready", av[1]);
|
||||||
|
ncdc_mainwindow_update_guilds(n);
|
||||||
|
|
||||||
ret = true;
|
ret = true;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
@ -21,6 +21,8 @@ bool ncdc_cmd_logout(ncdc_mainwindow_t n, size_t ac,
|
|||||||
dc_unref(current_session);
|
dc_unref(current_session);
|
||||||
current_session = NULL;
|
current_session = NULL;
|
||||||
|
|
||||||
|
ncdc_mainwindow_update_guilds(n);
|
||||||
|
|
||||||
LOG(n, L"logout: successfully logged out");
|
LOG(n, L"logout: successfully logged out");
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
@ -397,7 +397,6 @@ void ncdc_mainwindow_refresh(ncdc_mainwindow_t n)
|
|||||||
{
|
{
|
||||||
ncdc_textview_t v = 0;
|
ncdc_textview_t v = 0;
|
||||||
|
|
||||||
ncdc_mainwindow_update_guilds(n);
|
|
||||||
ncdc_treeview_render(n->guildview, n->guilds, n->guilds_h, n->guilds_w);
|
ncdc_treeview_render(n->guildview, n->guilds, n->guilds_h, n->guilds_w);
|
||||||
wnoutrefresh(n->guilds);
|
wnoutrefresh(n->guilds);
|
||||||
|
|
||||||
|
@ -22,6 +22,19 @@ struct ncdc_treeitem_
|
|||||||
void *tag;
|
void *tag;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct ncdc_treeview_
|
||||||
|
{
|
||||||
|
dc_refable_t ref;
|
||||||
|
|
||||||
|
/* root element
|
||||||
|
*/
|
||||||
|
ncdc_treeitem_t root;
|
||||||
|
|
||||||
|
/* currently selected item
|
||||||
|
*/
|
||||||
|
ncdc_treeitem_t current;
|
||||||
|
};
|
||||||
|
|
||||||
static void ncdc_treeitem_free(ncdc_treeitem_t t)
|
static void ncdc_treeitem_free(ncdc_treeitem_t t)
|
||||||
{
|
{
|
||||||
return_if_true(t == NULL,);
|
return_if_true(t == NULL,);
|
||||||
@ -63,6 +76,12 @@ ncdc_treeitem_t ncdc_treeitem_new_string(wchar_t const *s)
|
|||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t ncdc_treeitem_size(ncdc_treeitem_t i)
|
||||||
|
{
|
||||||
|
return_if_true(i == NULL || i->children == NULL, 0);
|
||||||
|
return i->children->len;
|
||||||
|
}
|
||||||
|
|
||||||
void ncdc_treeitem_add(ncdc_treeitem_t i, ncdc_treeitem_t c)
|
void ncdc_treeitem_add(ncdc_treeitem_t i, ncdc_treeitem_t c)
|
||||||
{
|
{
|
||||||
return_if_true(i == NULL || c == NULL,);
|
return_if_true(i == NULL || c == NULL,);
|
||||||
@ -132,13 +151,6 @@ ncdc_treeitem_render(ncdc_treeitem_t t, WINDOW *win,
|
|||||||
return off;
|
return off;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ncdc_treeview_
|
|
||||||
{
|
|
||||||
dc_refable_t ref;
|
|
||||||
|
|
||||||
ncdc_treeitem_t root;
|
|
||||||
};
|
|
||||||
|
|
||||||
static void ncdc_treeview_free(ncdc_treeview_t t)
|
static void ncdc_treeview_free(ncdc_treeview_t t)
|
||||||
{
|
{
|
||||||
return_if_true(t == NULL,);
|
return_if_true(t == NULL,);
|
||||||
@ -159,6 +171,8 @@ ncdc_treeview_t ncdc_treeview_new(void)
|
|||||||
t->root = ncdc_treeitem_new();
|
t->root = ncdc_treeitem_new();
|
||||||
goto_if_true(t->root == NULL, error);
|
goto_if_true(t->root == NULL, error);
|
||||||
|
|
||||||
|
t->current = t->root;
|
||||||
|
|
||||||
return dc_ref(t);
|
return dc_ref(t);
|
||||||
|
|
||||||
error:
|
error:
|
||||||
|
Loading…
Reference in New Issue
Block a user