Skip to content

Commit

Permalink
Implemented initial draft of contact list manipulation
Browse files Browse the repository at this point in the history
git-svn-id: http://sanoi.webfactional.com/trunk@32 79def182-f41f-0410-b320-e94a04284523
  • Loading branch information
mario committed Jul 30, 2007
1 parent edadd29 commit 02e506c
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 38 deletions.
2 changes: 2 additions & 0 deletions src/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ source_files = Split("""fama-config.h
ui-command-status.c
ui-command-connect.c
ui-command-account.c
ui-command-contact.c
tpa-connection.c
tpa-account.c
tpa-contact.c
tpa-manager-factory.c
tpa-channel.c""")

Expand Down
44 changes: 39 additions & 5 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,24 @@ typedef enum {
WindowTypeConversation,
} FamaWindowType;




/**
* FamaWindow.
*/
typedef struct {

WINDOW *ncwin; /**< NCurses WINDOW pointer */
PANEL *ncpanel; /**< NCurses PANEL pointer */

wchar_t *title; /**< The title of the window */
PANEL *ncpanel; /**< NCurses PANEL pointer */

wchar_t *title; /**< The title of the window */

GPtrArray *messages; /**< An array of FamaMessage data-types */

FamaWindowType type; /**< The FamaWindowType of the window */

gboolean is_updated; /**< True if window has unread messages */

TpaChannel *channel; /**< The channel associated with the window */
Expand All @@ -40,8 +48,8 @@ typedef struct {
* FamaConnection.
*/
typedef struct {
TpaConnection *connection;
gchar *account;
TpaConnection *connection;
gchar *account;
} FamaConnection;


Expand All @@ -59,8 +67,11 @@ typedef enum {
* A window's content consists of a GPtrArray of this type.
*/
typedef struct {

gint attr; /**< Attribute of the title */
wchar_t *title; /**< Title of the message */

wchar_t *title; /**< Title of the message */

wchar_t *message; /**< Message string */
} FamaMessage;

Expand All @@ -70,8 +81,11 @@ typedef struct {
* contain the actual items.
*/
typedef struct _FamaContactListGroup {

TpaConnection *tpa_connection; /**< TpaConnection associated with the group */

TpaContactList *tpa_contactlist; /**< TpaContactList associated with the group */

GPtrArray *items; /**< An array of FamaContactListItem's */
} FamaContactListGroup;

Expand All @@ -80,9 +94,13 @@ typedef struct _FamaContactListGroup {
* An item in the contact-list, returned by contactlist_get_selected()
*/
typedef struct _FamaContactListItem {

FamaContactListGroup *parent_group; /**< Parent group of the item */

TpaContact *contact; /**< TpaContact associated with the item */

wchar_t *text; /**< Text displayed in the contact-list */

gint attr; /**< Attribute of the text displayed in the contact-list */
} FamaContactListItem;

Expand All @@ -92,16 +110,27 @@ typedef struct _FamaContactListItem {
* Each element contains an attribute for use with wattron()
*/
typedef struct {

gint borders; /**< Bars and borders */

gint command_line; /**< Command line */

gint window_title; /**< Title of the conversation windows */

gint outgoing_message; /**< Outgoing message title */

gint incoming_message; /**< Incoming message title */

gint status_available; /** Contact-list status 'available' */

gint status_away; /** Contact-list status 'away' */

gint status_busy; /** Contact-list status 'busy' */

gint status_idle; /** Contact-list status 'idle' */

gint status_offline; /** Contact-list status 'offline' */

gint status_other; /** Contact-list other or unrecognized statuses */
} ColorSettings;

Expand Down Expand Up @@ -238,6 +267,11 @@ void statusbar_draw();
/* Util.c */
int mvwaddwstr_with_maxwidth(WINDOW *, int, int, const wchar_t *, int);

/* Contact.c */
gboolean contact_add(gchar *, gchar *);
gboolean contact_remove(const gchar *, const gchar *);
gboolean contact_authorize(const gchar *, const gchar *);

/* Account.c */
gboolean account_init();
void account_destroy();
Expand Down
3 changes: 2 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ init_all()
* Print version information
*/

g_message("Fama v%s (c) 2007 Mario Danic & Jonas Broms", VERSION_STRING);
g_message("Fama v%s (c) 2007 Mario Danic & Jonas Broms",
VERSION_STRING);

/*
* Check wether a D-Bus session is available or not
Expand Down
15 changes: 10 additions & 5 deletions src/tpa-channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,12 @@ channel_created_cb(TpaConnection * conn, TpaChannel * channel)
win->channel = channel;
win->is_updated = TRUE;

/* uncomment to automatically change current window */
/* window_set_current(win); */
/*
* uncomment to automatically change current window
*/
/*
* window_set_current(win);
*/

target_w = g_new(wchar_t, strlen(target) + 1);
utf8_to_wchar(target, target_w, strlen(target));
Expand All @@ -108,14 +112,15 @@ channel_created_cb(TpaConnection * conn, TpaChannel * channel)
window_draw_title_bar();
statusbar_draw();

messages = tpa_text_channel_get_pending (text_channel, TRUE);
messages = tpa_text_channel_get_pending(text_channel, TRUE);
if (messages) {
TpaTextMessage *message;
gint i;

for (i = 0; i < messages->len; i++) {
message = g_ptr_array_index (messages, i);
message_add_text_message(text_channel, message, MessageReceived);
message = g_ptr_array_index(messages, i);
message_add_text_message(text_channel, message,
MessageReceived);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/tpa-connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ connection_get_account_from_connection(TpaConnection * conn)
}

TpaConnection *
connection_get_connection_from_account(gchar *account)
connection_get_connection_from_account(gchar * account)
{
FamaConnection *connection;
gint i;
Expand Down
9 changes: 3 additions & 6 deletions src/ui-color.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,8 @@ color_init()
init_pair(7, COLOR_WHITE, background);
init_pair(8, -1, background);

settings.borders =
color_with_fallback("borders", COLOR_PAIR(6));
settings.command_line =
color_with_fallback("command_line", 0);
settings.borders = color_with_fallback("borders", COLOR_PAIR(6));
settings.command_line = color_with_fallback("command_line", 0);
settings.window_title =
color_with_fallback("window_title", COLOR_PAIR(3));
settings.outgoing_message =
Expand All @@ -89,8 +87,7 @@ color_init()
color_with_fallback("status_idle", COLOR_PAIR(3));
settings.status_busy =
color_with_fallback("status_busy", COLOR_PAIR(5));
settings.status_offline =
color_with_fallback("status_offline", 0);
settings.status_offline = color_with_fallback("status_offline", 0);
settings.status_other =
color_with_fallback("status_available", COLOR_PAIR(1));
}
Expand Down
42 changes: 24 additions & 18 deletions src/ui-command-status.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "common.h"

TpaContactPresence
_string_to_presence(gchar *string)
_string_to_presence(gchar * string)
{
if (g_ascii_strcasecmp(string, "available") == 0)
return TPA_PRESENCE_AVAILABLE;
Expand Down Expand Up @@ -45,32 +45,38 @@ command_func_status(gint argc, gchar ** argv)
return FALSE;
}

presence = _string_to_presence (argv[1]);
presence = _string_to_presence(argv[1]);
if (!presence) {
g_warning("Unrecognized presence string '%s'", argv[1]);
return FALSE;
}

for (i = 0; i < connections->len; i++) {
conn = g_ptr_array_index(connections, i);
conn = g_ptr_array_index(connections, i);

user = tpa_connection_get_user_contact (conn->connection);
g_assert(user);
user = tpa_connection_get_user_contact(conn->connection);
g_assert(user);

if (argc >= 3) {
success = tpa_user_contact_set_presence_with_message(user, presence, argv[2]);
if (success)
g_message("%s: Presence set to %s - '%s'", conn->account, argv[1], argv[2]);
} else {
success = tpa_user_contact_set_presence(user, presence);
if (success)
g_message("%s: Presence set to '%s'", conn->account, argv[1]);
}
if (argc >= 3) {
success =
tpa_user_contact_set_presence_with_message(user,
presence,
argv
[2]);
if (success)
g_message("%s: Presence set to %s - '%s'",
conn->account, argv[1], argv[2]);
} else {
success = tpa_user_contact_set_presence(user, presence);
if (success)
g_message("%s: Presence set to '%s'",
conn->account, argv[1]);
}

if (!success) {
g_warning("Could not set contact presence.");
return FALSE;
}
if (!success) {
g_warning("Could not set contact presence.");
return FALSE;
}

}

Expand Down
2 changes: 2 additions & 0 deletions src/ui-command.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ gboolean command_func_help(gint argc, gchar ** argv);
gboolean command_func_connect(gint argc, gchar ** argv);
gboolean command_func_quit(gint argc, gchar ** argv);
gboolean command_func_account(gint argc, gchar ** argv);
gboolean command_func_contact(gint argc, gchar ** argv);
gboolean command_func_status(gint argc, gchar ** argv);

/*
Expand Down Expand Up @@ -127,6 +128,7 @@ command_init()
command_add("connect", command_func_connect);
command_add("account", command_func_account);
command_add("status", command_func_status);
command_add("contact", command_func_contact);
}

/*
Expand Down
6 changes: 4 additions & 2 deletions src/ui-contactlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,10 @@ void
contactlist_authorization_requested_cb(TpaContactList * list,
TpaContact * contact)
{
g_message("%s has requested your authorization",
tpa_contact_base_get_alias(TPA_CONTACT_BASE(contact)));
gchar *uri;

uri = tpa_channel_target_get_uri(TPA_CHANNEL_TARGET(contact));
g_message("%s has requested your authorization", uri);
}


Expand Down

0 comments on commit 02e506c

Please sign in to comment.