Beispiel #1
0
gboolean
bookmark_add(const char *jid, const char *nick, const char *password, const char *autojoin_str)
{
    if (autocomplete_contains(bookmark_ac, jid)) {
        return FALSE;
    } else {
        Bookmark *item = malloc(sizeof(*item));
        item->jid = strdup(jid);
        if (nick) {
            item->nick = strdup(nick);
        } else {
            item->nick = NULL;
        }
        if (password) {
            item->password = strdup(password);
        } else {
            item->password = NULL;
        }

        if (g_strcmp0(autojoin_str, "on") == 0) {
            item->autojoin = TRUE;
        } else {
            item->autojoin = FALSE;
        }

        bookmark_list = g_list_append(bookmark_list, item);
        autocomplete_add(bookmark_ac, jid);
        _send_bookmarks();

        return TRUE;
    }
}
Beispiel #2
0
gboolean
bookmark_update(const char *jid, const char *nick, const char *password, const char *autojoin_str)
{
    Bookmark *item = malloc(sizeof(*item));
    item->jid = strdup(jid);
    item->nick = NULL;
    item->password = NULL;
    item->autojoin = FALSE;

    GList *found = g_list_find_custom(bookmark_list, item, _match_bookmark_by_jid);
    _bookmark_item_destroy(item);
    if (found == NULL) {
        return FALSE;
    } else {
        Bookmark *bm = found->data;
        if (nick) {
            free(bm->nick);
            bm->nick = strdup(nick);
        }
        if (password) {
            free(bm->password);
            bm->password = strdup(password);
        }
        if (autojoin_str) {
            if (g_strcmp0(autojoin_str, "on") == 0) {
                bm->autojoin = TRUE;
            } else if (g_strcmp0(autojoin_str, "off") == 0) {
                bm->autojoin = FALSE;
            }
        }
        _send_bookmarks();
        return TRUE;
    }
}
Beispiel #3
0
static gboolean
_bookmark_add(const char *jid, const char *nick, gboolean autojoin)
{
    gboolean added = TRUE;
    if (autocomplete_contains(bookmark_ac, jid)) {
        added = FALSE;
    }

    /* this may be command for modifying */
    Bookmark *item = malloc(sizeof(*item));
    item->jid = strdup(jid);
    if (nick != NULL) {
        item->nick = strdup(nick);
    } else {
        item->nick = NULL;
    }
    item->autojoin = autojoin;

    GList *found = g_list_find_custom(bookmark_list, item, _match_bookmark_by_jid);
    if (found != NULL) {
        bookmark_list = g_list_remove_link(bookmark_list, found);
        _bookmark_item_destroy(found->data);
        g_list_free(found);
    }
    bookmark_list = g_list_append(bookmark_list, item);

    autocomplete_remove(bookmark_ac, jid);
    autocomplete_add(bookmark_ac, jid);

    _send_bookmarks();

    return added;
}
Beispiel #4
0
static gboolean
_bookmark_remove(const char *jid, gboolean autojoin)
{
    Bookmark *item = malloc(sizeof(*item));
    item->jid = strdup(jid);
    item->nick = NULL;
    item->autojoin = autojoin;

    GList *found = g_list_find_custom(bookmark_list, item, _match_bookmark_by_jid);
    _bookmark_item_destroy(item);
    gboolean removed = found != NULL;

    if (removed) {
        // set autojoin FALSE
        if (autojoin) {
            Bookmark *bookmark = found->data;
            bookmark->autojoin = FALSE;

        // remove bookmark
        } else {
            bookmark_list = g_list_remove_link(bookmark_list, found);
            _bookmark_item_destroy(found->data);
            g_list_free(found);
            autocomplete_remove(bookmark_ac, jid);
        }

        _send_bookmarks();
    }

    return removed;
}
Beispiel #5
0
gboolean
bookmark_update(const char *jid, const char *nick, const char *password, const char *autojoin_str)
{
    assert(jid != NULL);

    Bookmark *bookmark = g_hash_table_lookup(bookmarks, jid);
    if (!bookmark) {
        return FALSE;
    }

    if (nick) {
        free(bookmark->nick);
        bookmark->nick = strdup(nick);
    }
    if (password) {
        free(bookmark->password);
        bookmark->password = strdup(password);
    }
    if (autojoin_str) {
        if (g_strcmp0(autojoin_str, "on") == 0) {
            bookmark->autojoin = TRUE;
        } else if (g_strcmp0(autojoin_str, "off") == 0) {
            bookmark->autojoin = FALSE;
        }
    }

    _send_bookmarks();
    return TRUE;
}
Beispiel #6
0
gboolean
bookmark_add(const char *jid, const char *nick, const char *password, const char *autojoin_str)
{
    assert(jid != NULL);

    if (g_hash_table_contains(bookmarks, jid)) {
        return FALSE;
    }

    Bookmark *bookmark = malloc(sizeof(Bookmark));
    bookmark->barejid = strdup(jid);
    if (nick) {
        bookmark->nick = strdup(nick);
    } else {
        bookmark->nick = NULL;
    }
    if (password) {
        bookmark->password = strdup(password);
    } else {
        bookmark->password = NULL;
    }

    if (g_strcmp0(autojoin_str, "on") == 0) {
        bookmark->autojoin = TRUE;
    } else {
        bookmark->autojoin = FALSE;
    }

    g_hash_table_insert(bookmarks, strdup(jid), bookmark);
    autocomplete_add(bookmark_ac, jid);

    _send_bookmarks();

    return TRUE;
}
Beispiel #7
0
gboolean
bookmark_remove(const char *jid)
{
    assert(jid != NULL);

    Bookmark *bookmark = g_hash_table_lookup(bookmarks, jid);
    if (!bookmark) {
        return FALSE;
    }

    g_hash_table_remove(bookmarks, jid);
    autocomplete_remove(bookmark_ac, jid);

    _send_bookmarks();

    return TRUE;
}
Beispiel #8
0
gboolean
bookmark_remove(const char *jid)
{
    Bookmark *item = malloc(sizeof(*item));
    item->jid = strdup(jid);
    item->nick = NULL;
    item->password = NULL;
    item->autojoin = FALSE;

    GList *found = g_list_find_custom(bookmark_list, item, _match_bookmark_by_jid);
    _bookmark_item_destroy(item);
    gboolean removed = found != NULL;

    if (removed) {
        bookmark_list = g_list_remove_link(bookmark_list, found);
        _bookmark_item_destroy(found->data);
        g_list_free(found);
        autocomplete_remove(bookmark_ac, jid);
        _send_bookmarks();
        return TRUE;
    } else {
        return FALSE;
    }
}