1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Use resource_presence_t in Resource

This commit is contained in:
James Booth 2013-02-10 17:27:08 +00:00
parent e922568770
commit 1a6490a5b7
3 changed files with 10 additions and 18 deletions

View File

@ -65,7 +65,8 @@ p_contact_new(const char * const barejid, const char * const name,
(GDestroyNotify)resource_destroy); (GDestroyNotify)resource_destroy);
// TODO, priority, last activity // TODO, priority, last activity
if (g_strcmp0(presence, "offline") != 0) { if (g_strcmp0(presence, "offline") != 0) {
Resource *resource = resource_new("default", presence, status, 0, caps_str); resource_presence_t resource_presence = resource_presence_from_string(presence);
Resource *resource = resource_new("default", resource_presence, status, 0, caps_str);
g_hash_table_insert(contact->available_resources, strdup(resource->name), resource); g_hash_table_insert(contact->available_resources, strdup(resource->name), resource);
} }
@ -130,7 +131,7 @@ p_contact_presence(const PContact contact)
return "offline"; return "offline";
} else { } else {
Resource *resource = g_hash_table_lookup(contact->available_resources, "default"); Resource *resource = g_hash_table_lookup(contact->available_resources, "default");
return resource->show; return string_from_resource_presence(resource->presence);
} }
} }
@ -180,17 +181,13 @@ p_contact_set_presence(const PContact contact, const char * const presence)
if (g_strcmp0(presence, "offline") == 0) { if (g_strcmp0(presence, "offline") == 0) {
g_hash_table_remove(contact->available_resources, "default"); g_hash_table_remove(contact->available_resources, "default");
} else { } else {
resource_presence_t resource_presence = resource_presence_from_string(presence);
if (g_hash_table_size(contact->available_resources) == 0) { if (g_hash_table_size(contact->available_resources) == 0) {
Resource *resource = resource_new("default", presence, NULL, 0, NULL); Resource *resource = resource_new("default", resource_presence, NULL, 0, NULL);
g_hash_table_insert(contact->available_resources, strdup(resource->name), resource); g_hash_table_insert(contact->available_resources, strdup(resource->name), resource);
} else { } else {
Resource *resource = g_hash_table_lookup(contact->available_resources, "default"); Resource *resource = g_hash_table_lookup(contact->available_resources, "default");
if (presence != NULL) { resource->presence = resource_presence;
FREE_SET_NULL(resource->show);
resource->show = strdup(presence);
} else {
resource->show = NULL;
}
} }
} }
} }

View File

@ -27,17 +27,13 @@
#include <common.h> #include <common.h>
#include <resource.h> #include <resource.h>
Resource * resource_new(const char * const name, const char * const show, Resource * resource_new(const char * const name, resource_presence_t presence,
const char * const status, const int priority, const char * const caps_str) const char * const status, const int priority, const char * const caps_str)
{ {
assert(g_strcmp0(show, "offline") != 0);
assert(name != NULL); assert(name != NULL);
Resource *new_resource = malloc(sizeof(struct resource_t)); Resource *new_resource = malloc(sizeof(struct resource_t));
new_resource->name = strdup(name); new_resource->name = strdup(name);
if (show == NULL || (strcmp(show, "") == 0)) new_resource->presence = presence;
new_resource->show = strdup("online");
else
new_resource->show = strdup(show);
if (status != NULL) { if (status != NULL) {
new_resource->status = strdup(status); new_resource->status = strdup(status);
} else { } else {
@ -57,7 +53,6 @@ void resource_destroy(Resource *resource)
{ {
assert(resource != NULL); assert(resource != NULL);
FREE_SET_NULL(resource->name); FREE_SET_NULL(resource->name);
FREE_SET_NULL(resource->show);
FREE_SET_NULL(resource->status); FREE_SET_NULL(resource->status);
FREE_SET_NULL(resource->caps_str); FREE_SET_NULL(resource->caps_str);
FREE_SET_NULL(resource); FREE_SET_NULL(resource);

View File

@ -25,13 +25,13 @@
typedef struct resource_t { typedef struct resource_t {
char *name; char *name;
char *show; resource_presence_t presence;
char *status; char *status;
int priority; int priority;
char *caps_str; char *caps_str;
} Resource; } Resource;
Resource * resource_new(const char * const name, const char * const show, Resource * resource_new(const char * const name, resource_presence_t presence,
const char * const status, const int priority, const char * const caps_str); const char * const status, const int priority, const char * const caps_str);
void resource_destroy(Resource *resource); void resource_destroy(Resource *resource);