Refactoring window types, removing recipient and from references - wip

This commit is contained in:
James Booth
2014-12-18 23:57:19 +00:00
parent 76c665e986
commit 0146e62576
11 changed files with 760 additions and 605 deletions

View File

@@ -35,6 +35,7 @@
#include "config.h"
#include <string.h>
#include <assert.h>
#include <glib.h>
@@ -75,6 +76,90 @@ wins_get_console(void)
return g_hash_table_lookup(windows, GINT_TO_POINTER(1));
}
ProfChatWin *
wins_get_chat(const char * const barejid)
{
GList *values = g_hash_table_get_values(windows);
GList *curr = values;
while (curr != NULL) {
ProfWin *window = curr->data;
if (window->type == WIN_CHAT) {
ProfChatWin *chatwin = (ProfChatWin*)window;
if (g_strcmp0(chatwin->barejid, barejid) == 0) {
g_list_free(values);
return chatwin;
}
}
curr = g_list_next(curr);
}
g_list_free(values);
return NULL;
}
ProfMucConfWin *
wins_get_muc_conf_win(const char * const title)
{
GList *values = g_hash_table_get_values(windows);
GList *curr = values;
while (curr != NULL) {
ProfWin *window = curr->data;
if (window->type == WIN_MUC_CONFIG) {
ProfMucConfWin *confwin = (ProfMucConfWin*)window;
if (g_strcmp0(confwin->from, title) == 0) {
g_list_free(values);
return confwin;
}
}
curr = g_list_next(curr);
}
g_list_free(values);
return NULL;
}
ProfMucWin *
wins_get_muc_win(const char * const roomjid)
{
GList *values = g_hash_table_get_values(windows);
GList *curr = values;
while (curr != NULL) {
ProfWin *window = curr->data;
if ((g_strcmp0(window->from, roomjid) == 0) && window->type == WIN_MUC) {
g_list_free(values);
return (ProfMucWin*)window;
}
curr = g_list_next(curr);
}
g_list_free(values);
return NULL;
}
ProfPrivateWin *
wins_get_private(const char * const fulljid)
{
GList *values = g_hash_table_get_values(windows);
GList *curr = values;
while (curr != NULL) {
ProfWin *window = curr->data;
if (window->type == WIN_PRIVATE) {
ProfPrivateWin *privatewin = (ProfPrivateWin*)window;
if (g_strcmp0(privatewin->fulljid, fulljid) == 0) {
return privatewin;
}
}
curr = g_list_next(curr);
}
g_list_free(values);
return NULL;
}
ProfWin *
wins_get_current(void)
{
@@ -85,6 +170,74 @@ wins_get_current(void)
}
}
ProfChatWin *
wins_get_current_chat(void)
{
if (windows) {
ProfWin *window = g_hash_table_lookup(windows, GINT_TO_POINTER(current));
if (window) {
ProfChatWin *chatwin = (ProfChatWin*)window;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
return chatwin;
} else {
return NULL;
}
} else {
return NULL;
}
}
ProfMucWin *
wins_get_current_muc(void)
{
if (windows) {
ProfWin *window = g_hash_table_lookup(windows, GINT_TO_POINTER(current));
if (window) {
ProfMucWin *mucwin = (ProfMucWin*)window;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
return mucwin;
} else {
return NULL;
}
} else {
return NULL;
}
}
ProfPrivateWin *
wins_get_current_private(void)
{
if (windows) {
ProfWin *window = g_hash_table_lookup(windows, GINT_TO_POINTER(current));
if (window) {
ProfPrivateWin *privatewin = (ProfPrivateWin*)window;
assert(privatewin->memcheck == PROFPRIVATEWIN_MEMCHECK);
return privatewin;
} else {
return NULL;
}
} else {
return NULL;
}
}
ProfMucConfWin *
wins_get_current_muc_conf(void)
{
if (windows) {
ProfWin *window = g_hash_table_lookup(windows, GINT_TO_POINTER(current));
if (window) {
ProfMucConfWin *confwin = (ProfMucConfWin*)window;
assert(confwin->memcheck == PROFCONFWIN_MEMCHECK);
return confwin;
} else {
return NULL;
}
} else {
return NULL;
}
}
GList *
wins_get_nums(void)
{
@@ -105,6 +258,32 @@ wins_get_by_num(int i)
return g_hash_table_lookup(windows, GINT_TO_POINTER(i));
}
ProfChatWin *
wins_get_chat_by_num(int i)
{
ProfWin *window = g_hash_table_lookup(windows, GINT_TO_POINTER(i));
if (window) {
ProfChatWin *chatwin = (ProfChatWin*)window;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
return chatwin;
} else {
return NULL;
}
}
ProfMucWin *
wins_get_muc_by_num(int i)
{
ProfWin *window = g_hash_table_lookup(windows, GINT_TO_POINTER(i));
if (window) {
ProfMucWin *mucwin = (ProfMucWin*)window;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
return mucwin;
} else {
return NULL;
}
}
ProfWin *
wins_get_next(void)
{
@@ -164,43 +343,25 @@ wins_get_previous(void)
}
}
ProfWin *
wins_get_by_recipient(const char * const recipient)
{
GList *values = g_hash_table_get_values(windows);
GList *curr = values;
while (curr != NULL) {
ProfWin *window = curr->data;
if (g_strcmp0(window->from, recipient) == 0) {
g_list_free(values);
return window;
}
curr = g_list_next(curr);
}
g_list_free(values);
return NULL;
}
ProfMucWin *
wins_get_muc_win(const char * const roomjid)
{
GList *values = g_hash_table_get_values(windows);
GList *curr = values;
while (curr != NULL) {
ProfWin *window = curr->data;
if ((g_strcmp0(window->from, roomjid) == 0) && window->type == WIN_MUC) {
g_list_free(values);
return (ProfMucWin*)window;
}
curr = g_list_next(curr);
}
g_list_free(values);
return NULL;
}
// TODO REMOVE
//ProfWin *
//wins_get_by_recipient(const char * const recipient)
//{
// GList *values = g_hash_table_get_values(windows);
// GList *curr = values;
//
// while (curr != NULL) {
// ProfWin *window = curr->data;
// if (g_strcmp0(window->from, recipient) == 0) {
// g_list_free(values);
// return window;
// }
// curr = g_list_next(curr);
// }
//
// g_list_free(values);
// return NULL;
//}
int
wins_get_num(ProfWin *window)