gaim/gaim

sf patch #1166665, from Bleeter Yaluser type guy
oldstatus
2005-03-19, Mark Doliner
ad2e10a4e998
Parents 90e82df8c548
Children c87fcedc8d25
sf patch #1166665, from Bleeter Yaluser type guy
Save blist.xml when privacy settings change.
  • +29 -29
    src/blist.c
  • +897 -0
    src/blist.h
  • +680 -0
    src/gtkprivacy.c
  • +188 -0
    src/privacy.c
  • --- a/src/blist.c Sat Mar 19 19:16:32 2005 -0500
    +++ b/src/blist.c Sat Mar 19 19:37:02 2005 -0500
    @@ -165,13 +165,6 @@
    return FALSE;
    }
    -static void schedule_blist_save()
    -{
    - if (blist_save_timer != 0)
    - gaim_timeout_remove(blist_save_timer);
    - blist_save_timer = gaim_timeout_add(1000, blist_save_callback, NULL);
    -}
    -
    /*****************************************************************************
    * Public API functions *
    @@ -405,7 +398,7 @@
    g_free(buddy->name);
    buddy->name = g_strdup(name);
    - schedule_blist_save();
    + gaim_schedule_blist_save();
    if (ops && ops->update)
    ops->update(gaimbuddylist, (GaimBlistNode *)buddy);
    @@ -423,7 +416,7 @@
    else
    chat->alias = NULL;
    - schedule_blist_save();
    + gaim_schedule_blist_save();
    if (ops && ops->update)
    ops->update(gaimbuddylist, (GaimBlistNode *)chat);
    @@ -442,7 +435,7 @@
    else
    buddy->alias = NULL;
    - schedule_blist_save();
    + gaim_schedule_blist_save();
    if (ops && ops->update)
    ops->update(gaimbuddylist, (GaimBlistNode *)buddy);
    @@ -465,7 +458,7 @@
    else
    buddy->server_alias = NULL;
    - schedule_blist_save();
    + gaim_schedule_blist_save();
    if (ops && ops->update)
    ops->update(gaimbuddylist, (GaimBlistNode *)buddy);
    @@ -548,7 +541,7 @@
    }
    /* Save our changes */
    - schedule_blist_save();
    + gaim_schedule_blist_save();
    /* Update the UI */
    if (ops && ops->update)
    @@ -654,7 +647,7 @@
    else
    gaim_blist_node_remove_setting((GaimBlistNode *)buddy, "buddy_icon");
    - schedule_blist_save();
    + gaim_schedule_blist_save();
    gaim_blist_update_buddy_icon(buddy);
    }
    @@ -707,7 +700,7 @@
    ops->remove(gaimbuddylist, cnode);
    - schedule_blist_save();
    + gaim_schedule_blist_save();
    }
    if (node != NULL) {
    @@ -736,7 +729,7 @@
    }
    }
    - schedule_blist_save();
    + gaim_schedule_blist_save();
    if (ops && ops->update)
    ops->update(gaimbuddylist, (GaimBlistNode *)cnode);
    @@ -808,7 +801,7 @@
    ops->remove(gaimbuddylist, bnode);
    - schedule_blist_save();
    + gaim_schedule_blist_save();
    if (bnode->parent->parent != (GaimBlistNode*)g) {
    hb = g_new(struct _gaim_hbuddy, 1);
    @@ -865,7 +858,7 @@
    gaim_contact_compute_priority_buddy(gaim_buddy_get_contact(buddy));
    - schedule_blist_save();
    + gaim_schedule_blist_save();
    if (ops && ops->update)
    ops->update(gaimbuddylist, (GaimBlistNode*)buddy);
    @@ -902,7 +895,7 @@
    else
    contact->alias = NULL;
    - schedule_blist_save();
    + gaim_schedule_blist_save();
    if (ops && ops->update)
    ops->update(gaimbuddylist, (GaimBlistNode*)contact);
    @@ -1045,7 +1038,7 @@
    ops->remove(gaimbuddylist, cnode);
    - schedule_blist_save();
    + gaim_schedule_blist_save();
    }
    if (node && (GAIM_BLIST_NODE_IS_CONTACT(node) ||
    @@ -1071,7 +1064,7 @@
    g->currentsize++;
    g->totalsize++;
    - schedule_blist_save();
    + gaim_schedule_blist_save();
    if (ops && cnode->child)
    ops->update(gaimbuddylist, cnode);
    @@ -1162,7 +1155,7 @@
    gaimbuddylist->root = gnode;
    }
    - schedule_blist_save();
    + gaim_schedule_blist_save();
    if (ops && ops->update) {
    ops->update(gaimbuddylist, gnode);
    @@ -1205,7 +1198,7 @@
    if (node->next)
    node->next->prev = node->prev;
    - schedule_blist_save();
    + gaim_schedule_blist_save();
    /* Update the UI */
    if (ops && ops->remove)
    @@ -1254,7 +1247,7 @@
    }
    contact->totalsize--;
    - schedule_blist_save();
    + gaim_schedule_blist_save();
    /* Re-sort the contact */
    if (contact->priority == buddy) {
    @@ -1317,7 +1310,7 @@
    }
    group->totalsize--;
    - schedule_blist_save();
    + gaim_schedule_blist_save();
    /* Update the UI */
    if (ops && ops->remove)
    @@ -1371,7 +1364,7 @@
    if (node->next)
    node->next->prev = node->prev;
    - schedule_blist_save();
    + gaim_schedule_blist_save();
    /* Update the UI */
    if (ops && ops->remove)
    @@ -2438,6 +2431,13 @@
    g_free(filename_real);
    }
    +void
    +gaim_schedule_blist_save()
    +{
    + if (blist_save_timer != 0)
    + gaim_timeout_remove(blist_save_timer);
    + blist_save_timer = gaim_timeout_add(1000, blist_save_callback, NULL);
    +}
    static void gaim_blist_node_setting_free(struct gaim_blist_node_setting *setting)
    {
    @@ -2469,7 +2469,7 @@
    g_hash_table_remove(node->settings, key);
    - schedule_blist_save();
    + gaim_schedule_blist_save();
    }
    @@ -2487,7 +2487,7 @@
    g_hash_table_replace(node->settings, g_strdup(key), setting);
    - schedule_blist_save();
    + gaim_schedule_blist_save();
    }
    gboolean gaim_blist_node_get_bool(GaimBlistNode* node, const char *key)
    @@ -2522,7 +2522,7 @@
    g_hash_table_replace(node->settings, g_strdup(key), setting);
    - schedule_blist_save();
    + gaim_schedule_blist_save();
    }
    int gaim_blist_node_get_int(GaimBlistNode* node, const char *key)
    @@ -2558,7 +2558,7 @@
    g_hash_table_replace(node->settings, g_strdup(key), setting);
    - schedule_blist_save();
    + gaim_schedule_blist_save();
    }
    const char *gaim_blist_node_get_string(GaimBlistNode* node, const char *key)
    --- /dev/null Thu Jan 01 00:00:00 1970 +0000
    +++ b/src/blist.h Sat Mar 19 19:37:02 2005 -0500
    @@ -0,0 +1,897 @@
    +/**
    + * @file blist.h Buddy List API
    + * @ingroup core
    + *
    + * gaim
    + *
    + * Gaim is the legal property of its developers, whose names are too numerous
    + * to list here. Please refer to the COPYRIGHT file distributed with this
    + * source distribution.
    + *
    + * This program is free software; you can redistribute it and/or modify
    + * it under the terms of the GNU General Public License as published by
    + * the Free Software Foundation; either version 2 of the License, or
    + * (at your option) any later version.
    + *
    + * This program is distributed in the hope that it will be useful,
    + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    + * GNU General Public License for more details.
    + *
    + * You should have received a copy of the GNU General Public License
    + * along with this program; if not, write to the Free Software
    + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    + */
    +#ifndef _GAIM_BLIST_H_
    +#define _GAIM_BLIST_H_
    +
    +/* I can't believe I let ChipX86 inspire me to write good code. -Sean */
    +
    +#include <glib.h>
    +
    +typedef struct _GaimBuddyList GaimBuddyList;
    +typedef struct _GaimBlistUiOps GaimBlistUiOps;
    +typedef struct _GaimBlistNode GaimBlistNode;
    +
    +typedef struct _GaimBlistNodeAction GaimBlistNodeAction;
    +
    +typedef struct _GaimChat GaimChat;
    +typedef struct _GaimGroup GaimGroup;
    +typedef struct _GaimContact GaimContact;
    +typedef struct _GaimBuddy GaimBuddy;
    +
    +#include "account.h"
    +#include "buddyicon.h"
    +
    +/**************************************************************************/
    +/* Enumerations */
    +/**************************************************************************/
    +typedef enum
    +{
    + GAIM_BLIST_GROUP_NODE,
    + GAIM_BLIST_CONTACT_NODE,
    + GAIM_BLIST_BUDDY_NODE,
    + GAIM_BLIST_CHAT_NODE,
    + GAIM_BLIST_OTHER_NODE
    +
    +} GaimBlistNodeType;
    +
    +#define GAIM_BLIST_NODE_IS_CHAT(n) ((n)->type == GAIM_BLIST_CHAT_NODE)
    +#define GAIM_BLIST_NODE_IS_BUDDY(n) ((n)->type == GAIM_BLIST_BUDDY_NODE)
    +#define GAIM_BLIST_NODE_IS_CONTACT(n) ((n)->type == GAIM_BLIST_CONTACT_NODE)
    +#define GAIM_BLIST_NODE_IS_GROUP(n) ((n)->type == GAIM_BLIST_GROUP_NODE)
    +
    +typedef enum
    +{
    + GAIM_BUDDY_SIGNING_OFF = -1,
    + GAIM_BUDDY_OFFLINE = 0,
    + GAIM_BUDDY_ONLINE,
    + GAIM_BUDDY_SIGNING_ON
    +
    +} GaimBuddyPresenceState;
    +
    +#define GAIM_BUDDY_IS_ONLINE(b) ((b)->account->gc && \
    + ((b)->present == GAIM_BUDDY_ONLINE || \
    + (b)->present == GAIM_BUDDY_SIGNING_ON))
    +
    +typedef enum
    +{
    + GAIM_BLIST_NODE_FLAG_NO_SAVE = 1, /**< node should not be saved with the buddy list */
    +} GaimBlistNodeFlags;
    +
    +#define GAIM_BLIST_NODE_HAS_FLAG(b, f) ((b)->flags & (f))
    +#define GAIM_BLIST_NODE_SHOULD_SAVE(b) (! GAIM_BLIST_NODE_HAS_FLAG(b, GAIM_BLIST_NODE_FLAG_NO_SAVE))
    +
    +
    +/**************************************************************************/
    +/* Data Structures */
    +/**************************************************************************/
    +
    +/**
    + * A Buddy list node. This can represent a group, a buddy, or anything else. This is a base class for struct buddy and
    + * struct group and for anything else that wants to put itself in the buddy list. */
    +struct _GaimBlistNode {
    + GaimBlistNodeType type; /**< The type of node this is */
    + GaimBlistNode *prev; /**< The sibling before this buddy. */
    + GaimBlistNode *next; /**< The sibling after this buddy. */
    + GaimBlistNode *parent; /**< The parent of this node */
    + GaimBlistNode *child; /**< The child of this node */
    + GHashTable *settings; /**< per-node settings */
    + void *ui_data; /**< The UI can put data here. */
    + GaimBlistNodeFlags flags; /**< The buddy flags */
    +};
    +
    +/**
    + * A buddy. This contains everything Gaim will ever need to know about someone on the buddy list. Everything.
    + */
    +struct _GaimBuddy {
    + GaimBlistNode node; /**< The node that this buddy inherits from */
    + char *name; /**< The screenname of the buddy. */
    + char *alias; /**< The user-set alias of the buddy */
    + char *server_alias; /**< The server-specified alias of the buddy. (i.e. MSN "Friendly Names") */
    + GaimBuddyPresenceState present; /**< This is 0 if the buddy appears offline, 1 if he appears online, and 2 if
    + he has recently signed on */
    + int evil; /**< The warning level */
    + time_t signon; /**< The time the buddy signed on. */
    + int idle; /**< The time the buddy has been idle in minutes. */
    + int uc; /**< This is a cryptic bitmask that makes sense only to the prpl. This will get changed */
    + void *proto_data; /**< This allows the prpl to associate whatever data it wants with a buddy */
    + GaimBuddyIcon *icon; /**< The buddy icon. */
    + GaimAccount *account; /**< the account this buddy belongs to */
    + guint timer; /**< The timer handle. */
    +};
    +
    +/**
    + * A contact. This contains everything Gaim will ever need to know about a contact.
    + */
    +struct _GaimContact {
    + GaimBlistNode node; /**< The node that this contact inherits from. */
    + char *alias; /**< The user-set alias of the contact */
    + int totalsize; /**< The number of buddies in this contact */
    + int currentsize; /**< The number of buddies in this contact corresponding to online accounts */
    + int online; /**< The number of buddies in this contact who are currently online */
    + GaimBuddy *priority; /**< The "top" buddy for this contact */
    +};
    +
    +
    +/**
    + * A group. This contains everything Gaim will ever need to know about a group.
    + */
    +struct _GaimGroup {
    + GaimBlistNode node; /**< The node that this group inherits from */
    + char *name; /**< The name of this group. */
    + int totalsize; /**< The number of chats and contacts in this group */
    + int currentsize; /**< The number of chats and contacts in this group corresponding to online accounts */
    + int online; /**< The number of chats and contacts in this group who are currently online */
    +};
    +
    +/**
    + * A chat. This contains everything Gaim needs to put a chat room in the
    + * buddy list.
    + */
    +struct _GaimChat {
    + GaimBlistNode node; /**< The node that this chat inherits from */
    + char *alias; /**< The display name of this chat. */
    + GHashTable *components; /**< the stuff the protocol needs to know to join the chat */
    + GaimAccount *account; /**< The account this chat is attached to */
    +};
    +
    +
    +/**
    + * The Buddy List
    + */
    +struct _GaimBuddyList {
    + GaimBlistNode *root; /**< The first node in the buddy list */
    + GHashTable *buddies; /**< Every buddy in this list */
    + GaimBlistUiOps *ui_ops; /**< The UI operations for the buddy list */
    +
    + void *ui_data; /**< UI-specific data. */
    +};
    +
    +/**
    + * Buddy list UI operations.
    + *
    + * Any UI representing a buddy list must assign a filled-out GaimBlistUiOps
    + * structure to the buddy list core.
    + */
    +struct _GaimBlistUiOps
    +{
    + void (*new_list)(GaimBuddyList *list); /**< Sets UI-specific data on a buddy list. */
    + void (*new_node)(GaimBlistNode *node); /**< Sets UI-specific data on a node. */
    + void (*show)(GaimBuddyList *list); /**< The core will call this when its finished doing it's core stuff */
    + void (*update)(GaimBuddyList *list,
    + GaimBlistNode *node); /**< This will update a node in the buddy list. */
    + void (*remove)(GaimBuddyList *list,
    + GaimBlistNode *node); /**< This removes a node from the list */
    + void (*destroy)(GaimBuddyList *list); /**< When the list gets destroyed, this gets called to destroy the UI. */
    + void (*set_visible)(GaimBuddyList *list,
    + gboolean show); /**< Hides or unhides the buddy list */
    + void (*request_add_buddy)(GaimAccount *account, const char *username,
    + const char *group, const char *alias);
    + void (*request_add_chat)(GaimAccount *account, GaimGroup *group,
    + const char *alias, const char *name);
    + void (*request_add_group)(void);
    +};
    +
    +
    +struct _GaimBlistNodeAction {
    + char *label;
    + void (*callback)(GaimBlistNode *, gpointer);
    + gpointer data;
    +};
    +
    +
    +#ifdef __cplusplus
    +extern "C" {
    +#endif
    +
    +/**************************************************************************/
    +/** @name Buddy List API */
    +/**************************************************************************/
    +/*@{*/
    +
    +/**
    + * Creates a new buddy list
    + */
    +GaimBuddyList *gaim_blist_new();
    +
    +/**
    + * Sets the main buddy list.
    + *
    + * @return The main buddy list.
    + */
    +void gaim_set_blist(GaimBuddyList *blist);
    +
    +/**
    + * Returns the main buddy list.
    + *
    + * @return The main buddy list.
    + */
    +GaimBuddyList *gaim_get_blist(void);
    +
    +/**
    + * Shows the buddy list, creating a new one if necessary.
    + *
    + */
    +void gaim_blist_show();
    +
    +
    +/**
    + * Destroys the buddy list window.
    + */
    +void gaim_blist_destroy();
    +
    +/**
    + * Hides or unhides the buddy list.
    + *
    + * @param show Whether or not to show the buddy list
    + */
    +void gaim_blist_set_visible(gboolean show);
    +
    +/**
    + * Updates a buddy's status.
    + *
    + * This needs to not take an int.
    + *
    + * @param buddy The buddy whose status has changed
    + * @param status The new status in cryptic prpl-understood code
    + */
    +void gaim_blist_update_buddy_status(GaimBuddy *buddy, int status);
    +
    +
    +/**
    + * Updates a buddy's presence.
    + *
    + * @param buddy The buddy whose presence has changed
    + * @param online If the buddy is now online
    + */
    +void gaim_blist_update_buddy_presence(GaimBuddy *buddy, gboolean online);
    +
    +/**
    + * Updates a buddy's signon time.
    + *
    + * @param buddy The buddy whose idle time has changed.
    + * @param signon The buddy's signon time since the dawn of the UNIX epoch.
    + */
    +void gaim_blist_update_buddy_signon(GaimBuddy *buddy, time_t signon);
    +
    +/**
    + * Updates a buddy's idle time.
    + *
    + * @param buddy The buddy whose idle time has changed
    + * @param idle The buddy's idle time in minutes.
    + */
    +void gaim_blist_update_buddy_idle(GaimBuddy *buddy, int idle);
    +
    +
    +/**
    + * Updates a buddy's warning level.
    + *
    + * @param buddy The buddy whose warning level has changed.
    + * @param warning The warning level as an int from 0 to 100.
    + */
    +void gaim_blist_update_buddy_evil(GaimBuddy *buddy, int warning);
    +
    +/**
    + * Updates a buddy's icon.
    + *
    + * @param buddy The buddy whose buddy icon has changed
    + */
    +void gaim_blist_update_buddy_icon(GaimBuddy *buddy);
    +
    +/**
    + * Renames a buddy in the buddy list.
    + *
    + * @param buddy The buddy whose name will be changed.
    + * @param name The new name of the buddy.
    + */
    +void gaim_blist_rename_buddy(GaimBuddy *buddy, const char *name);
    +
    +
    +/**
    + * Aliases a buddy in the buddy list.
    + *
    + * @param buddy The buddy whose alias will be changed.
    + * @param alias The buddy's alias.
    + */
    +void gaim_blist_alias_buddy(GaimBuddy *buddy, const char *alias);
    +
    +/**
    + * Sets the server-sent alias of a buddy in the buddy list.
    + *
    + * @param buddy The buddy whose alias will be changed.
    + * @param alias The buddy's "official" alias.
    + */
    +void gaim_blist_server_alias_buddy(GaimBuddy *buddy, const char *alias);
    +
    +/**
    + * Aliases a chat in the buddy list.
    + *
    + * @param chat The chat whose alias will be changed.
    + * @param alias The chat's new alias.
    + */
    +void gaim_blist_alias_chat(GaimChat *chat, const char *alias);
    +
    +/**
    + * Renames a group
    + *
    + * @param group The group to rename
    + * @param name The new name
    + */
    +void gaim_blist_rename_group(GaimGroup *group, const char *name);
    +
    +/**
    + * Creates a new chat for the buddy list
    + *
    + * @param account The account this chat will get added to
    + * @param alias The alias of the new chat
    + * @param components The info the prpl needs to join the chat
    + * @return A newly allocated chat
    + */
    +GaimChat *gaim_chat_new(GaimAccount *account, const char *alias, GHashTable *components);
    +
    +/**
    + * Gets the alias of the chat, or the chat name if the alias does not exist
    + *
    + * @param chat The chat
    + * @return The display name of the chat
    + */
    +char *gaim_chat_get_display_name(GaimChat *chat);
    +
    +/**
    + * Adds a new chat to the buddy list.
    + *
    + * The chat will be inserted right after node or appended to the end
    + * of group if node is NULL. If both are NULL, the buddy will be added to
    + * the "Chats" group.
    + *
    + * @param chat The new chat who gets added
    + * @param group The group to add the new chat to.
    + * @param node The insertion point
    + */
    +void gaim_blist_add_chat(GaimChat *chat, GaimGroup *group, GaimBlistNode *node);
    +
    +/**
    + * Creates a new buddy
    + *
    + * @param account The account this buddy will get added to
    + * @param screenname The screenname of the new buddy
    + * @param alias The alias of the new buddy (or NULL if unaliased)
    + * @return A newly allocated buddy
    + */
    +GaimBuddy *gaim_buddy_new(GaimAccount *account, const char *screenname, const char *alias);
    +
    +/**
    + * Sets a buddy's icon.
    + *
    + * This should only be called from within Gaim. You probably want to
    + * call gaim_buddy_icon_set_data().
    + *
    + * @param buddy The buddy.
    + * @param icon The buddy icon.
    + *
    + * @see gaim_buddy_icon_set_data()
    + */
    +void gaim_buddy_set_icon(GaimBuddy *buddy, GaimBuddyIcon *icon);
    +
    +/**
    + * Returns a buddy's icon.
    + *
    + * @param buddy The buddy.
    + *
    + * @return The buddy icon.
    + */
    +GaimBuddyIcon *gaim_buddy_get_icon(const GaimBuddy *buddy);
    +
    +/**
    + * Returns a buddy's contact.
    + *
    + * @param buddy The buddy.
    + *
    + * @return The buddy's contact.
    + */
    +GaimContact *gaim_buddy_get_contact(GaimBuddy *buddy);
    +
    +/**
    + * Adds a new buddy to the buddy list.
    + *
    + * The buddy will be inserted right after node or prepended to the
    + * group if node is NULL. If both are NULL, the buddy will be added to
    + * the "Buddies" group.
    + *
    + * @param buddy The new buddy who gets added
    + * @param contact The optional contact to place the buddy in.
    + * @param group The group to add the new buddy to.
    + * @param node The insertion point
    + */
    +void gaim_blist_add_buddy(GaimBuddy *buddy, GaimContact *contact, GaimGroup *group, GaimBlistNode *node);
    +
    +/**
    + * Creates a new group
    + *
    + * You can't have more than one group with the same name. Sorry. If you pass
    + * this the * name of a group that already exists, it will return that group.
    + *
    + * @param name The name of the new group
    + * @return A new group struct
    +*/
    +GaimGroup *gaim_group_new(const char *name);
    +
    +/**
    + * Adds a new group to the buddy list.
    + *
    + * The new group will be inserted after insert or prepended to the list if
    + * node is NULL.
    + *
    + * @param group The group
    + * @param node The insertion point
    + */
    +void gaim_blist_add_group(GaimGroup *group, GaimBlistNode *node);
    +
    +/**
    + * Creates a new contact
    + *
    + * @return A new contact struct
    + */
    +GaimContact *gaim_contact_new();
    +
    +/**
    + * Adds a new contact to the buddy list.
    + *
    + * The new contact will be inserted after insert or prepended to the list if
    + * node is NULL.
    + *
    + * @param contact The contact
    + * @param group The group to add the contact to
    + * @param node The insertion point
    + */
    +void gaim_blist_add_contact(GaimContact *contact, GaimGroup *group, GaimBlistNode *node);
    +
    +/**
    + * Merges two contacts
    + *
    + * All of the buddies from source will be moved to target
    + *
    + * @param source The contact to merge
    + * @param node The place to merge to (a buddy or contact)
    + */
    +void gaim_blist_merge_contact(GaimContact *source, GaimBlistNode *node);
    +
    +/**
    + * Returns the highest priority buddy for a given contact.
    + *
    + * @param contact The contact
    + * @return The highest priority buddy
    + */
    +GaimBuddy *gaim_contact_get_priority_buddy(GaimContact *contact);
    +
    +/**
    + * Sets the alias for a contact.
    + *
    + * @param contact The contact
    + * @param alias The alias to set, or NULL to unset
    + */
    +void gaim_contact_set_alias(GaimContact *contact, const char *alias);
    +
    +/**
    + * Gets the alias for a contact.
    + *
    + * @param contact The contact
    + * @return The alias, or NULL if it is not set.
    + */
    +const char *gaim_contact_get_alias(GaimContact *contact);
    +
    +/**
    + * Determines whether an account owns any buddies in a given contact
    + *
    + * @param contact The contact to search through.
    + * @param account The account.
    + *
    + * @return TRUE if there are any buddies from account in the contact, or FALSE otherwise.
    + */
    +gboolean gaim_contact_on_account(GaimContact *contact, GaimAccount *account);
    +
    +
    +/**
    + * Removes a buddy from the buddy list and frees the memory allocated to it.
    + *
    + * @param buddy The buddy to be removed
    + */
    +void gaim_blist_remove_buddy(GaimBuddy *buddy);
    +
    +/**
    + * Removes a contact, and any buddies it contains, and frees the memory
    + * allocated to it.
    + *
    + * @param contact The contact to be removed
    + */
    +void gaim_blist_remove_contact(GaimContact *contact);
    +
    +/**
    + * Removes a chat from the buddy list and frees the memory allocated to it.
    + *
    + * @param chat The chat to be removed
    + */
    +void gaim_blist_remove_chat(GaimChat *chat);
    +
    +/**
    + * Removes a group from the buddy list and frees the memory allocated to it and to
    + * its children
    + *
    + * @param group The group to be removed
    + */
    +void gaim_blist_remove_group(GaimGroup *group);
    +
    +/**
    + * Returns the alias of a buddy.
    + *
    + * @param buddy The buddy whose name will be returned.
    + * @return The alias (if set), server alias (if set and preference
    + * is to display server aliases), or NULL.
    + */
    +const char *gaim_buddy_get_alias_only(GaimBuddy *buddy);
    +
    +
    +/**
    + * Returns the correct name to display for a buddy, taking the contact alias
    + * into account. In order of precedence: the buddy's alias; the buddy's
    + * contact alias; the buddy's server alias; the buddy's user name.
    + *
    + * @param buddy The buddy whose name will be returned
    + * @return The appropriate name or alias, or NULL.
    + *
    + */
    +const char *gaim_buddy_get_contact_alias(GaimBuddy *buddy);
    +
    +
    +/**
    + * Returns the correct name to display for a buddy. In order of precedence:
    + * the buddy's alias; the buddy's server alias; the buddy's contact alias;
    + * the buddy's user name.
    + *
    + * @param buddy The buddy whose name will be returned.
    + * @return The appropriate name or alias, or NULL
    + */
    +const char *gaim_buddy_get_alias(GaimBuddy *buddy);
    +
    +/**
    + * Returns the correct name to display for a blist chat.
    + *
    + * @param chat The chat whose name will be returned.
    + * @return The alias (if set), or first component value.
    + */
    +const char *gaim_chat_get_name(GaimChat *chat);
    +
    +/**
    + * Finds the buddy struct given a screenname and an account
    + *
    + * @param name The buddy's screenname
    + * @param account The account this buddy belongs to
    + * @return The buddy or NULL if the buddy does not exist
    + */
    +GaimBuddy *gaim_find_buddy(GaimAccount *account, const char *name);
    +
    +/**
    + * Finds the buddy struct given a screenname, an account, and a group
    + *
    + * @param name The buddy's screenname
    + * @param account The account this buddy belongs to
    + * @param group The group to look in
    + * @return The buddy or NULL if the buddy does not exist in the group
    + */
    +GaimBuddy *gaim_find_buddy_in_group(GaimAccount *account, const char *name,
    + GaimGroup *group);
    +
    +/**
    + * Finds all GaimBuddy structs given a screenname and an account
    + *
    + * @param name The buddy's screenname
    + * @param account The account this buddy belongs to
    + *
    + * @return A GSList of buddies (which must be freed), or NULL if the buddy doesn't exist
    + */
    +GSList *gaim_find_buddies(GaimAccount *account, const char *name);
    +
    +
    +/**
    + * Finds a group by name
    + *
    + * @param name The groups name
    + * @return The group or NULL if the group does not exist
    + */
    +GaimGroup *gaim_find_group(const char *name);
    +
    +/**
    + * Finds a chat by name.
    + *
    + * @param account The chat's account.
    + * @param name The chat's name.
    + *
    + * @return The chat, or @c NULL if the chat does not exist.
    + */
    +GaimChat *gaim_blist_find_chat(GaimAccount *account, const char *name);
    +
    +/**
    + * Returns the group of which the chat is a member.
    + *
    + * @param chat The chat.
    + *
    + * @return The parent group, or @c NULL if the chat is not in a group.
    + */
    +GaimGroup *gaim_chat_get_group(GaimChat *chat);
    +
    +/**
    + * Returns the group of which the buddy is a member.
    + *
    + * @param buddy The buddy
    + * @return The group or NULL if the buddy is not in a group
    + */
    +GaimGroup *gaim_find_buddys_group(GaimBuddy *buddy);
    +
    +
    +/**
    + * Returns a list of accounts that have buddies in this group
    + *
    + * @param g The group
    + *
    + * @return A list of gaim_accounts
    + */
    +GSList *gaim_group_get_accounts(GaimGroup *g);
    +
    +/**
    + * Determines whether an account owns any buddies in a given group
    + *
    + * @param g The group to search through.
    + * @param account The account.
    + *
    + * @return TRUE if there are any buddies in the group, or FALSE otherwise.
    + */
    +gboolean gaim_group_on_account(GaimGroup *g, GaimAccount *account);
    +
    +/**
    + * Called when an account gets signed on. Tells the UI to update all the
    + * buddies.
    + *
    + * @param account The account
    + */
    +void gaim_blist_add_account(GaimAccount *account);
    +
    +
    +/**
    + * Called when an account gets signed off. Sets the presence of all the buddies to 0
    + * and tells the UI to update them.
    + *
    + * @param account The account
    + */
    +void gaim_blist_remove_account(GaimAccount *account);
    +
    +
    +/**
    + * Determines the total size of a group
    + *
    + * @param group The group
    + * @param offline Count buddies in offline accounts
    + * @return The number of buddies in the group
    + */
    +int gaim_blist_get_group_size(GaimGroup *group, gboolean offline);
    +
    +/**
    + * Determines the number of online buddies in a group
    + *
    + * @param group The group
    + * @return The number of online buddies in the group, or 0 if the group is NULL
    + */
    +int gaim_blist_get_group_online_count(GaimGroup *group);
    +
    +/*@}*/
    +
    +/****************************************************************************************/
    +/** @name Buddy list file management API */
    +/****************************************************************************************/
    +
    +/*@{*/
    +/**
    + * Force an immediate write of the buddy list. Normally the buddy list is
    + * saved automatically a few seconds after a change is made.
    + */
    +void gaim_blist_sync();
    +
    +/**
    + * Schedule a save of the buddy list.
    + */
    +void gaim_schedule_blist_save();
    +
    +/**
    + * Loads the buddy list from ~/.gaim/blist.xml.
    + */
    +void gaim_blist_load();
    +
    +/**
    + * Requests from the user information needed to add a buddy to the
    + * buddy list.
    + *
    + * @param account The account the buddy is added to.
    + * @param username The username of the buddy.
    + * @param group The name of the group to place the buddy in.
    + * @param alias The optional alias for the buddy.
    + */
    +void gaim_blist_request_add_buddy(GaimAccount *account, const char *username,
    + const char *group, const char *alias);
    +
    +/**
    + * Requests from the user information needed to add a chat to the
    + * buddy list.
    + *
    + * @param account The account the buddy is added to.
    + * @param group The optional group to add the chat to.
    + * @param alias The optional alias for the chat.
    + * @param name The required chat name.
    + */
    +void gaim_blist_request_add_chat(GaimAccount *account, GaimGroup *group,
    + const char *alias, const char *name);
    +
    +/**
    + * Requests from the user information needed to add a group to the
    + * buddy list.
    + */
    +void gaim_blist_request_add_group(void);
    +
    +/**
    + * Associates a boolean with a node in the buddy list
    + *
    + * @param node The node to associate the data with
    + * @param key The identifier for the data
    + * @param value The value to set
    + */
    +void gaim_blist_node_set_bool(GaimBlistNode *node, const char *key, gboolean value);
    +
    +/**
    + * Retrieves a named boolean setting from a node in the buddy list
    + *
    + * @param node The node to retrieve the data from
    + * @param key The identifier of the data
    + *
    + * @return The value, or FALSE if there is no setting
    + */
    +gboolean gaim_blist_node_get_bool(GaimBlistNode *node, const char *key);
    +
    +/**
    + * Associates an integer with a node in the buddy list
    + *
    + * @param node The node to associate the data with
    + * @param key The identifier for the data
    + * @param value The value to set
    + */
    +void gaim_blist_node_set_int(GaimBlistNode *node, const char *key, int value);
    +
    +/**
    + * Retrieves a named integer setting from a node in the buddy list
    + *
    + * @param node The node to retrieve the data from
    + * @param key The identifier of the data
    + *
    + * @return The value, or 0 if there is no setting
    + */
    +int gaim_blist_node_get_int(GaimBlistNode *node, const char *key);
    +
    +/**
    + * Associates a string with a node in the buddy list
    + *
    + * @param node The node to associate the data with
    + * @param key The identifier for the data
    + * @param value The value to set
    + */
    +void gaim_blist_node_set_string(GaimBlistNode *node, const char *key,
    + const char *value);
    +
    +/**
    + * Retrieves a named string setting from a node in the buddy list
    + *
    + * @param node The node to retrieve the data from
    + * @param key The identifier of the data
    + *
    + * @return The value, or NULL if there is no setting
    + */
    +const char *gaim_blist_node_get_string(GaimBlistNode *node, const char *key);
    +
    +/**
    + * Removes a named setting from a blist node
    + *
    + * @param node The node from which to remove the setting
    + * @param key The name of the setting
    + */
    +void gaim_blist_node_remove_setting(GaimBlistNode *node, const char *key);
    +
    +/*@}*/
    +
    +
    +/**
    + * Retrieves the extended menu items for a buddy list node.
    + * @param n The blist node for which to obtain the extended menu items.
    + * @return list of GaimBlistNodeAction items, as harvested by the
    + * blist-node-extended-menu signal.
    + */
    +GList *gaim_blist_node_get_extended_menu(GaimBlistNode *n);
    +
    +
    +/**
    + * Creates a new GaimBlistNodeAction.
    + * @param label The text label to display for this action.
    + * @param callback The function to be called when the action is used on
    + * a selected GaimBlistNode.
    + * @param data Additional data, to be passed to the callback
    + */
    +GaimBlistNodeAction *gaim_blist_node_action_new(char *label,
    + void (*callback)(GaimBlistNode *, gpointer), gpointer data);
    +
    +
    +/**************************************************************************/
    +/** @name UI Registration Functions */
    +/**************************************************************************/
    +/*@{*/
    +
    +/**
    + * Sets the UI operations structure to be used for the buddy list.
    + *
    + * @param ops The ops struct.
    + */
    +void gaim_blist_set_ui_ops(GaimBlistUiOps *ops);
    +
    +/**
    + * Returns the UI operations structure to be used for the buddy list.
    + *
    + * @return The UI operations structure.
    + */
    +GaimBlistUiOps *gaim_blist_get_ui_ops(void);
    +
    +/*@}*/
    +
    +/**************************************************************************/
    +/** @name Buddy List Subsystem */
    +/**************************************************************************/
    +/*@{*/
    +
    +/**
    + * Returns the handle for the buddy list subsystem.
    + *
    + * @return The buddy list subsystem handle.
    + */
    +void *gaim_blist_get_handle(void);
    +
    +/**
    + * Initializes the buddy list subsystem.
    + */
    +void gaim_blist_init(void);
    +
    +/**
    + * Uninitializes the buddy list subsystem.
    + */
    +void gaim_blist_uninit(void);
    +
    +/*@}*/
    +
    +#ifdef __cplusplus
    +}
    +#endif
    +
    +#endif /* _GAIM_BLIST_H_ */
    --- /dev/null Thu Jan 01 00:00:00 1970 +0000
    +++ b/src/gtkprivacy.c Sat Mar 19 19:37:02 2005 -0500
    @@ -0,0 +1,680 @@
    +/**
    + * @file gtkprivacy.c GTK+ Privacy UI
    + * @ingroup gtkui
    + *
    + * gaim
    + *
    + * Gaim is the legal property of its developers, whose names are too numerous
    + * to list here. Please refer to the COPYRIGHT file distributed with this
    + * source distribution.
    + *
    + * This program is free software; you can redistribute it and/or modify
    + * it under the terms of the GNU General Public License as published by
    + * the Free Software Foundation; either version 2 of the License, or
    + * (at your option) any later version.
    + *
    + * This program is distributed in the hope that it will be useful,
    + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    + * GNU General Public License for more details.
    + *
    + * You should have received a copy of the GNU General Public License
    + * along with this program; if not, write to the Free Software
    + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    + */
    +#include "internal.h"
    +#include "gtkgaim.h"
    +
    +#include "blist.h"
    +#include "connection.h"
    +#include "debug.h"
    +#include "privacy.h"
    +#include "request.h"
    +#include "util.h"
    +
    +#include "gtkprivacy.h"
    +#include "gtkutils.h"
    +
    +typedef struct
    +{
    + GtkWidget *win;
    +
    + GtkWidget *type_menu;
    +
    + GtkWidget *add_button;
    + GtkWidget *remove_button;
    + GtkWidget *clear_button;
    +
    + GtkWidget *button_box;
    + GtkWidget *allow_widget;
    + GtkWidget *block_widget;
    +
    + GtkListStore *allow_store;
    + GtkListStore *block_store;
    +
    + GtkWidget *allow_list;
    + GtkWidget *block_list;
    +
    + gboolean in_allow_list;
    +
    + GaimAccount *account;
    +
    +} GaimGtkPrivacyDialog;
    +
    +typedef struct
    +{
    + GaimAccount *account;
    + char *name;
    + gboolean block;
    +
    +} GaimGtkPrivacyRequestData;
    +
    +static struct
    +{
    + const char *text;
    + int num;
    +
    +} menu_entries[] =
    +{
    + { N_("Allow all users to contact me"), GAIM_PRIVACY_ALLOW_ALL },
    + { N_("Allow only the users on my buddy list"), GAIM_PRIVACY_ALLOW_BUDDYLIST },
    + { N_("Allow only the users below"), GAIM_PRIVACY_ALLOW_USERS },
    + { N_("Block all users"), GAIM_PRIVACY_DENY_ALL },
    + { N_("Block only the users below"), GAIM_PRIVACY_DENY_USERS }
    +};
    +
    +static size_t menu_entry_count = sizeof(menu_entries) / sizeof(*menu_entries);
    +
    +static GaimGtkPrivacyDialog *privacy_dialog = NULL;
    +
    +static void
    +rebuild_allow_list(GaimGtkPrivacyDialog *dialog)
    +{
    + GSList *l;
    + GtkTreeIter iter;
    +
    + gtk_list_store_clear(dialog->allow_store);
    +
    + for (l = dialog->account->permit; l != NULL; l = l->next) {
    + gtk_list_store_append(dialog->allow_store, &iter);
    + gtk_list_store_set(dialog->allow_store, &iter, 0, l->data, -1);
    + }
    +}
    +
    +static void
    +rebuild_block_list(GaimGtkPrivacyDialog *dialog)
    +{
    + GSList *l;
    + GtkTreeIter iter;
    +
    + gtk_list_store_clear(dialog->block_store);
    +
    + for (l = dialog->account->deny; l != NULL; l = l->next) {
    + gtk_list_store_append(dialog->block_store, &iter);
    + gtk_list_store_set(dialog->block_store, &iter, 0, l->data, -1);
    + }
    +}
    +
    +static const char *
    +find_permit_block_by_name(GSList *list, const char *name)
    +{
    + const char *temp_name;
    + GSList *l;
    +
    + for (l = list; l != NULL; l = l->next) {
    + temp_name = (const char *)l->data;
    +
    + if (!gaim_utf8_strcasecmp(name, temp_name))
    + return temp_name;
    + }
    +
    + return NULL;
    +}
    +
    +static void
    +user_selected_cb(GtkTreeSelection *sel, GaimGtkPrivacyDialog *dialog)
    +{
    + gtk_widget_set_sensitive(dialog->remove_button, TRUE);
    +}
    +
    +static GtkWidget *
    +build_list(GaimGtkPrivacyDialog *dialog, GtkListStore *model,
    + GtkWidget **ret_treeview)
    +{
    + GtkWidget *sw;
    + GtkWidget *treeview;
    + GtkCellRenderer *rend;
    + GtkTreeViewColumn *column;
    + GtkTreeSelection *sel;
    +
    + sw = gtk_scrolled_window_new(NULL, NULL);
    + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
    + GTK_POLICY_AUTOMATIC,
    + GTK_POLICY_ALWAYS);
    + gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), GTK_SHADOW_IN);
    +
    + treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model));
    + *ret_treeview = treeview;
    +
    + rend = gtk_cell_renderer_text_new();
    +
    + column = gtk_tree_view_column_new_with_attributes(NULL, rend,
    + "text", 0,
    + NULL);
    + gtk_tree_view_column_set_clickable(GTK_TREE_VIEW_COLUMN(column), TRUE);
    + gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column);
    + gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), FALSE);
    + gtk_container_add(GTK_CONTAINER(sw), treeview);
    +
    + gtk_widget_show(treeview);
    +
    + sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
    +
    + g_signal_connect(G_OBJECT(sel), "changed",
    + G_CALLBACK(user_selected_cb), dialog);
    +
    + gtk_widget_set_size_request(sw, -1, 200);
    +
    + return sw;
    +}
    +
    +static GtkWidget *
    +build_allow_list(GaimGtkPrivacyDialog *dialog)
    +{
    + GtkWidget *widget;
    + GtkWidget *list;
    +
    + dialog->allow_store = gtk_list_store_new(1, G_TYPE_STRING);
    +
    + widget = build_list(dialog, dialog->allow_store, &list);
    +
    + dialog->allow_list = list;
    +
    + rebuild_allow_list(dialog);
    +
    + return widget;
    +}
    +
    +static GtkWidget *
    +build_block_list(GaimGtkPrivacyDialog *dialog)
    +{
    + GtkWidget *widget;
    + GtkWidget *list;
    +
    + dialog->block_store = gtk_list_store_new(1, G_TYPE_STRING);
    +
    + widget = build_list(dialog, dialog->block_store, &list);
    +
    + dialog->block_list = list;
    +
    + rebuild_block_list(dialog);
    +
    + return widget;
    +}
    +
    +static gint
    +destroy_cb(GtkWidget *w, GdkEvent *event, GaimGtkPrivacyDialog *dialog)
    +{
    + gaim_gtk_privacy_dialog_hide();
    +
    + return 0;
    +}
    +
    +static void
    +select_account_cb(GtkWidget *dropdown, GaimAccount *account,
    + GaimGtkPrivacyDialog *dialog)
    +{
    + int i;
    +
    + dialog->account = account;
    +
    + for (i = 0; i < menu_entry_count; i++) {
    + if (menu_entries[i].num == account->perm_deny) {
    + gtk_option_menu_set_history(GTK_OPTION_MENU(dialog->type_menu), i);
    + break;
    + }
    + }
    +
    + rebuild_allow_list(dialog);
    + rebuild_block_list(dialog);
    +}
    +
    +/*
    + * TODO: Setting the permit/deny setting needs to go through privacy.c.
    + * Even better: the privacy API needs to not suck.
    + */
    +static void
    +type_changed_cb(GtkOptionMenu *optmenu, GaimGtkPrivacyDialog *dialog)
    +{
    + int new_type = menu_entries[gtk_option_menu_get_history(optmenu)].num;
    +
    + dialog->account->perm_deny = new_type;
    + serv_set_permit_deny(gaim_account_get_connection(dialog->account));
    +
    + gtk_widget_hide(dialog->allow_widget);
    + gtk_widget_hide(dialog->block_widget);
    + gtk_widget_hide(dialog->button_box);
    +
    + if (new_type == GAIM_PRIVACY_ALLOW_USERS) {
    + gtk_widget_show(dialog->allow_widget);
    + gtk_widget_show(dialog->button_box);
    + dialog->in_allow_list = TRUE;
    + }
    + else if (new_type == GAIM_PRIVACY_DENY_USERS) {
    + gtk_widget_show(dialog->block_widget);
    + gtk_widget_show(dialog->button_box);
    + dialog->in_allow_list = FALSE;
    + }
    +
    + gaim_schedule_blist_save();
    +}
    +
    +static void
    +add_cb(GtkWidget *button, GaimGtkPrivacyDialog *dialog)
    +{
    + if (dialog->in_allow_list)
    + gaim_gtk_request_add_permit(dialog->account, NULL);
    + else
    + gaim_gtk_request_add_block(dialog->account, NULL);
    +}
    +
    +static void
    +remove_cb(GtkWidget *button, GaimGtkPrivacyDialog *dialog)
    +{
    + GtkTreeIter iter;
    + GtkTreeModel *model;
    + GtkTreeSelection *sel;
    + char *name;
    +
    + if (dialog->in_allow_list && dialog->allow_store == NULL)
    + return;
    +
    + if (!dialog->in_allow_list && dialog->block_store == NULL)
    + return;
    +
    + if (dialog->in_allow_list) {
    + model = GTK_TREE_MODEL(dialog->allow_store);
    + sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->allow_list));
    + }
    + else {
    + model = GTK_TREE_MODEL(dialog->block_store);
    + sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(dialog->block_list));
    + }
    +
    + if (gtk_tree_selection_get_selected(sel, NULL, &iter))
    + gtk_tree_model_get(model, &iter, 0, &name, -1);
    + else
    + return;
    +
    + if (dialog->in_allow_list) {
    + if (find_permit_block_by_name(dialog->account->permit, name))
    + gaim_privacy_permit_remove(dialog->account, name, FALSE);
    + }
    + else {
    + if (find_permit_block_by_name(dialog->account->deny, name))
    + gaim_privacy_deny_remove(dialog->account, name, FALSE);
    + }
    +}
    +
    +static void
    +clear_cb(GtkWidget *button, GaimGtkPrivacyDialog *dialog)
    +{
    + GSList *l;
    + if (dialog->in_allow_list)
    + l = dialog->account->permit;
    + else
    + l = dialog->account->deny;
    + while (l) {
    + char *user;
    + user = l->data;
    + l = l->next;
    + if (dialog->in_allow_list)
    + gaim_privacy_permit_remove(dialog->account, user, FALSE);
    + else
    + gaim_privacy_deny_remove(dialog->account, user, FALSE);
    + }
    +}
    +
    +static void
    +close_cb(GtkWidget *button, GaimGtkPrivacyDialog *dialog)
    +{
    + gtk_widget_destroy(dialog->win);
    +
    + gaim_gtk_privacy_dialog_hide();
    +}
    +
    +static gboolean
    +check_account_func(GaimAccount *account)
    +{
    + GaimConnection *gc = gaim_account_get_connection(account);
    + GaimPluginProtocolInfo *prpl_info = NULL;
    +
    + prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
    +
    + return (prpl_info->set_permit_deny != NULL);
    +}
    +
    +gboolean
    +gaim_gtk_privacy_is_showable()
    +{
    + GList *c;
    + GaimConnection *gc;
    +
    + for (c = gaim_connections_get_all(); c != NULL; c = c->next) {
    + gc = c->data;
    +
    + if (check_account_func(gaim_connection_get_account(gc)))
    + return TRUE;
    + }
    +
    + return FALSE;
    +}
    +
    +static GaimGtkPrivacyDialog *
    +privacy_dialog_new(void)
    +{
    + GaimGtkPrivacyDialog *dialog;
    + GtkWidget *bbox;
    + GtkWidget *hbox;
    + GtkWidget *vbox;
    + GtkWidget *button;
    + GtkWidget *dropdown;
    + GtkWidget *label;
    + GtkWidget *menu;
    + GtkWidget *sep;
    + int selected = 0;
    + int i;
    +
    + dialog = g_new0(GaimGtkPrivacyDialog, 1);
    +
    + dialog->win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    + gtk_window_set_resizable(GTK_WINDOW(dialog->win), FALSE);
    + gtk_window_set_role(GTK_WINDOW(dialog->win), "privacy");
    + gtk_window_set_title(GTK_WINDOW(dialog->win), _("Privacy"));
    + gtk_container_set_border_width(GTK_CONTAINER(dialog->win), 12);
    +
    + g_signal_connect(G_OBJECT(dialog->win), "delete_event",
    + G_CALLBACK(destroy_cb), dialog);
    +
    + /* Main vbox */
    + vbox = gtk_vbox_new(FALSE, 12);
    + gtk_container_add(GTK_CONTAINER(dialog->win), vbox);
    + gtk_widget_show(vbox);
    +
    + /* Description label */
    + label = gtk_label_new(
    + _("Changes to privacy settings take effect immediately."));
    +
    + gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
    + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
    + gtk_widget_show(label);
    +
    + /* Hbox for the accounts drop-down and label. */
    + hbox = gtk_hbox_new(FALSE, 12);
    + gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
    + gtk_widget_show(hbox);
    +
    + /* "Set privacy for:" label */
    + label = gtk_label_new(_("Set privacy for:"));
    + gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
    + gtk_widget_show(label);
    +
    + /* Accounts drop-down */
    + dropdown = gaim_gtk_account_option_menu_new(NULL, FALSE,
    + G_CALLBACK(select_account_cb),
    + check_account_func, dialog);
    + gtk_box_pack_start(GTK_BOX(hbox), dropdown, FALSE, FALSE, 0);
    + gtk_widget_show(dropdown);
    + gaim_set_accessible_label (dropdown, label);
    + dialog->account = gaim_gtk_account_option_menu_get_selected(dropdown);
    +
    + /* Add the drop-down list with the allow/block types. */
    + dialog->type_menu = gtk_option_menu_new();
    + gtk_box_pack_start(GTK_BOX(vbox), dialog->type_menu, FALSE, FALSE, 0);
    + gtk_widget_show(dialog->type_menu);
    +
    + /* Build the menu for that. */
    + menu = gtk_menu_new();
    +
    + for (i = 0; i < menu_entry_count; i++) {
    + gaim_new_item(menu, _(menu_entries[i].text));
    +
    + if (menu_entries[i].num == dialog->account->perm_deny)
    + selected = i;
    + }
    +
    + gtk_option_menu_set_menu(GTK_OPTION_MENU(dialog->type_menu), menu);
    + gtk_option_menu_set_history(GTK_OPTION_MENU(dialog->type_menu), selected);
    +
    + g_signal_connect(G_OBJECT(dialog->type_menu), "changed",
    + G_CALLBACK(type_changed_cb), dialog);
    +
    + /* Build the treeview for the allow list. */
    + dialog->allow_widget = build_allow_list(dialog);
    + gtk_box_pack_start(GTK_BOX(vbox), dialog->allow_widget, TRUE, TRUE, 0);
    +
    + /* Build the treeview for the block list. */
    + dialog->block_widget = build_block_list(dialog);
    + gtk_box_pack_start(GTK_BOX(vbox), dialog->block_widget, TRUE, TRUE, 0);
    +
    + /* Add the button box for Add, Remove, Clear */
    + dialog->button_box = bbox = gtk_hbutton_box_new();
    + gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_SPREAD);
    + gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
    +
    + /* Add button */
    + button = gtk_button_new_from_stock(GTK_STOCK_ADD);
    + dialog->add_button = button;
    + gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0);
    + gtk_widget_show(button);
    +
    + g_signal_connect(G_OBJECT(button), "clicked",
    + G_CALLBACK(add_cb), dialog);
    +
    + /* Remove button */
    + button = gtk_button_new_from_stock(GTK_STOCK_REMOVE);
    + dialog->remove_button = button;
    + gtk_widget_set_sensitive(button, FALSE);
    + gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0);
    + gtk_widget_show(button);
    +
    + g_signal_connect(G_OBJECT(button), "clicked",
    + G_CALLBACK(remove_cb), dialog);
    +
    + /* Clear button */
    + button = gtk_button_new_from_stock(GTK_STOCK_CLEAR);
    + dialog->clear_button = button;
    + gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0);
    + gtk_widget_show(button);
    +
    + g_signal_connect(G_OBJECT(button), "clicked",
    + G_CALLBACK(clear_cb), dialog);
    +
    + /* Separator */
    + sep = gtk_hseparator_new();
    + gtk_box_pack_start(GTK_BOX(vbox), sep, FALSE, FALSE, 0);
    + gtk_widget_show(sep);
    +
    + /* Another button box. */
    + bbox = gtk_hbutton_box_new();
    + gtk_button_box_set_layout(GTK_BUTTON_BOX(bbox), GTK_BUTTONBOX_END);
    + gtk_box_pack_start(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
    + gtk_widget_show(bbox);
    +
    + /* Close button */
    + button = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
    + gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0);
    + gtk_widget_show(button);
    +
    + g_signal_connect(G_OBJECT(button), "clicked",
    + G_CALLBACK(close_cb), dialog);
    +
    + if (dialog->account->perm_deny == GAIM_PRIVACY_ALLOW_USERS) {
    + gtk_widget_show(dialog->allow_widget);
    + gtk_widget_show(dialog->button_box);
    + dialog->in_allow_list = TRUE;
    + }
    + else if (dialog->account->perm_deny == GAIM_PRIVACY_DENY_USERS) {
    + gtk_widget_show(dialog->block_widget);
    + gtk_widget_show(dialog->button_box);
    + dialog->in_allow_list = FALSE;
    + }
    +
    + return dialog;
    +}
    +
    +void
    +gaim_gtk_privacy_dialog_show(void)
    +{
    + if (privacy_dialog == NULL)
    + privacy_dialog = privacy_dialog_new();
    +
    + gtk_widget_show(privacy_dialog->win);
    + gdk_window_raise(privacy_dialog->win->window);
    +}
    +
    +void
    +gaim_gtk_privacy_dialog_hide(void)
    +{
    + if (privacy_dialog == NULL)
    + return;
    +
    + g_free(privacy_dialog);
    + privacy_dialog = NULL;
    +}
    +
    +static void
    +destroy_request_data(GaimGtkPrivacyRequestData *data)
    +{
    + if (data->name != NULL)
    + g_free(data->name);
    +
    + g_free(data);
    +}
    +
    +static void
    +confirm_permit_block_cb(GaimGtkPrivacyRequestData *data, int option)
    +{
    + if (data->block)
    + gaim_privacy_deny_add(data->account, data->name, FALSE);
    + else
    + gaim_privacy_permit_add(data->account, data->name, FALSE);
    +
    + destroy_request_data(data);
    +}
    +
    +static void
    +add_permit_block_cb(GaimGtkPrivacyRequestData *data, const char *name)
    +{
    + data->name = g_strdup(name);
    +
    + confirm_permit_block_cb(data, 0);
    +}
    +
    +void
    +gaim_gtk_request_add_permit(GaimAccount *account, const char *name)
    +{
    + GaimGtkPrivacyRequestData *data;
    +
    + g_return_if_fail(account != NULL);
    +
    + data = g_new0(GaimGtkPrivacyRequestData, 1);
    + data->account = account;
    + data->name = g_strdup(name);
    + data->block = FALSE;
    +
    + if (name == NULL) {
    + gaim_request_input(account, _("Permit User"),
    + _("Type a user you permit to contact you."),
    + _("Please enter the name of the user you wish to be "
    + "able to contact you."),
    + NULL, FALSE, FALSE, NULL,
    + _("Permit"), G_CALLBACK(add_permit_block_cb),
    + _("Cancel"), G_CALLBACK(destroy_request_data),
    + data);
    + }
    + else {
    + char *primary = g_strdup_printf(_("Allow %s to contact you?"), name);
    + char *secondary =
    + g_strdup_printf(_("Are you sure you wish to allow "
    + "%s to contact you?"), name);
    +
    +
    + gaim_request_action(account, _("Permit User"), primary, secondary,
    + 0, data, 2,
    + _("Permit"), G_CALLBACK(confirm_permit_block_cb),
    + _("Cancel"), G_CALLBACK(destroy_request_data));
    +
    + g_free(primary);
    + g_free(secondary);
    + }
    +}
    +
    +void
    +gaim_gtk_request_add_block(GaimAccount *account, const char *name)
    +{
    + GaimGtkPrivacyRequestData *data;
    +
    + g_return_if_fail(account != NULL);
    +
    + data = g_new0(GaimGtkPrivacyRequestData, 1);
    + data->account = account;
    + data->name = g_strdup(name);
    + data->block = TRUE;
    +
    + if (name == NULL) {
    + gaim_request_input(account, _("Block User"),
    + _("Type a user to block."),
    + _("Please enter the name of the user you wish to block."),
    + NULL, FALSE, FALSE, NULL,
    + _("Block"), G_CALLBACK(add_permit_block_cb),
    + _("Cancel"), G_CALLBACK(destroy_request_data),
    + data);
    + }
    + else {
    + char *primary = g_strdup_printf(_("Block %s?"), name);
    + char *secondary =
    + g_strdup_printf(_("Are you sure you want to block %s?"), name);
    +
    + gaim_request_action(account, _("Block User"), primary, secondary,
    + 0, data, 2,
    + _("Block"), G_CALLBACK(confirm_permit_block_cb),
    + _("Cancel"), G_CALLBACK(destroy_request_data));
    +
    + g_free(primary);
    + g_free(secondary);
    + }
    +}
    +
    +static void
    +gaim_gtk_permit_added_removed(GaimAccount *account, const char *name)
    +{
    + if (privacy_dialog != NULL)
    + rebuild_allow_list(privacy_dialog);
    +}
    +
    +static void
    +gaim_gtk_deny_added_removed(GaimAccount *account, const char *name)
    +{
    + if (privacy_dialog != NULL)
    + rebuild_block_list(privacy_dialog);
    +}
    +
    +static GaimPrivacyUiOps privacy_ops =
    +{
    + gaim_gtk_permit_added_removed,
    + gaim_gtk_permit_added_removed,
    + gaim_gtk_deny_added_removed,
    + gaim_gtk_deny_added_removed
    +};
    +
    +GaimPrivacyUiOps *
    +gaim_gtk_privacy_get_ui_ops(void)
    +{
    + return &privacy_ops;
    +}
    +
    +void
    +gaim_gtk_privacy_init(void)
    +{
    +}
    --- /dev/null Thu Jan 01 00:00:00 1970 +0000
    +++ b/src/privacy.c Sat Mar 19 19:37:02 2005 -0500
    @@ -0,0 +1,188 @@
    +/**
    + * gaim
    + *
    + * Gaim is the legal property of its developers, whose names are too numerous
    + * to list here. Please refer to the COPYRIGHT file distributed with this
    + * source distribution.
    + *
    + * This program is free software; you can redistribute it and/or modify
    + * it under the terms of the GNU General Public License as published by
    + * the Free Software Foundation; either version 2 of the License, or
    + * (at your option) any later version.
    + *
    + * This program is distributed in the hope that it will be useful,
    + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    + * GNU General Public License for more details.
    + *
    + * You should have received a copy of the GNU General Public License
    + * along with this program; if not, write to the Free Software
    + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    + */
    +#include "internal.h"
    +
    +#include "account.h"
    +#include "privacy.h"
    +#include "server.h"
    +#include "util.h"
    +
    +static GaimPrivacyUiOps *privacy_ops = NULL;
    +
    +gboolean
    +gaim_privacy_permit_add(GaimAccount *account, const char *who,
    + gboolean local_only)
    +{
    + GSList *l;
    + char *name;
    +
    + g_return_val_if_fail(account != NULL, FALSE);
    + g_return_val_if_fail(who != NULL, FALSE);
    +
    + name = g_strdup(gaim_normalize(account, who));
    +
    + for (l = account->permit; l != NULL; l = l->next) {
    + if (!gaim_utf8_strcasecmp(name, gaim_normalize(account, (char *)l->data)))
    + break;
    + }
    +
    + g_free(name);
    +
    + if (l != NULL)
    + return FALSE;
    +
    + account->permit = g_slist_append(account->permit, g_strdup(who));
    +
    + if (!local_only && gaim_account_is_connected(account))
    + serv_add_permit(gaim_account_get_connection(account), who);
    +
    + if (privacy_ops != NULL && privacy_ops->permit_added != NULL)
    + privacy_ops->permit_added(account, who);
    +
    + gaim_schedule_blist_save();
    +
    + return TRUE;
    +}
    +
    +gboolean
    +gaim_privacy_permit_remove(GaimAccount *account, const char *who,
    + gboolean local_only)
    +{
    + GSList *l;
    + char *name;
    +
    + g_return_val_if_fail(account != NULL, FALSE);
    + g_return_val_if_fail(who != NULL, FALSE);
    +
    + name = g_strdup(gaim_normalize(account, who));
    +
    + for (l = account->permit; l != NULL; l = l->next) {
    + if (!gaim_utf8_strcasecmp(name, gaim_normalize(account, (char *)l->data)))
    + break;
    + }
    +
    + g_free(name);
    +
    + if (l == NULL)
    + return FALSE;
    +
    + account->permit = g_slist_remove(account->permit, l->data);
    + g_free(l->data);
    +
    + if (!local_only && gaim_account_is_connected(account))
    + serv_rem_permit(gaim_account_get_connection(account), who);
    +
    + if (privacy_ops != NULL && privacy_ops->permit_removed != NULL)
    + privacy_ops->permit_removed(account, who);
    +
    + gaim_schedule_blist_save();
    +
    + return TRUE;
    +}
    +
    +gboolean
    +gaim_privacy_deny_add(GaimAccount *account, const char *who,
    + gboolean local_only)
    +{
    + GSList *l;
    + char *name;
    +
    + g_return_val_if_fail(account != NULL, FALSE);
    + g_return_val_if_fail(who != NULL, FALSE);
    +
    + name = g_strdup(gaim_normalize(account, who));
    +
    + for (l = account->deny; l != NULL; l = l->next) {
    + if (!gaim_utf8_strcasecmp(name, gaim_normalize(account, (char *)l->data)))
    + break;
    + }
    +
    + g_free(name);
    +
    + if (l != NULL)
    + return FALSE;
    +
    + account->deny = g_slist_append(account->deny, g_strdup(who));
    +
    + if (!local_only && gaim_account_is_connected(account))
    + serv_add_deny(gaim_account_get_connection(account), who);
    +
    + if (privacy_ops != NULL && privacy_ops->deny_added != NULL)
    + privacy_ops->deny_added(account, who);
    +
    + gaim_schedule_blist_save();
    +
    + return TRUE;
    +}
    +
    +gboolean
    +gaim_privacy_deny_remove(GaimAccount *account, const char *who,
    + gboolean local_only)
    +{
    + GSList *l;
    + char *name;
    +
    + g_return_val_if_fail(account != NULL, FALSE);
    + g_return_val_if_fail(who != NULL, FALSE);
    +
    + name = g_strdup(gaim_normalize(account, who));
    +
    + for (l = account->deny; l != NULL; l = l->next) {
    + if (!gaim_utf8_strcasecmp(name, gaim_normalize(account, (char *)l->data)))
    + break;
    + }
    +
    + g_free(name);
    +
    + if (l == NULL)
    + return FALSE;
    +
    + account->deny = g_slist_remove(account->deny, l->data);
    + g_free(l->data);
    +
    + if (!local_only && gaim_account_is_connected(account))
    + serv_rem_deny(gaim_account_get_connection(account), who);
    +
    + if (privacy_ops != NULL && privacy_ops->deny_removed != NULL)
    + privacy_ops->deny_removed(account, who);
    +
    + gaim_schedule_blist_save();
    +
    + return TRUE;
    +}
    +
    +void
    +gaim_privacy_set_ui_ops(GaimPrivacyUiOps *ops)
    +{
    + privacy_ops = ops;
    +}
    +
    +GaimPrivacyUiOps *
    +gaim_privacy_get_ui_ops(void)
    +{
    + return privacy_ops;
    +}
    +
    +void
    +gaim_privacy_init(void)
    +{
    +}