|
From: CORE C. L. <cor...@li...> - 2000-11-21 17:59:02
|
Core CVS committal
Author : rbdpngn
Project : core
Module : src
Modified Files:
account.c account.h callbacks.c callbacks.h
Log Message:
Fixed new_account to initialize all members of account struct. Made callbacks.c
use the account API.
===================================================================
RCS file: /cvsroot/corem/core/src/account.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -3 -r1.7 -r1.8
--- account.c 2000/11/21 05:10:40 1.7
+++ account.c 2000/11/21 17:59:01 1.8
@@ -17,6 +17,8 @@
ret->name = NULL;
ret->full_name = NULL;
+ ret->username = NULL;
+ ret->password = NULL;
ret->address = NULL;
ret->server = NULL;
ret->path = NULL;
@@ -62,6 +64,30 @@
return TRUE;
}
+int account_set_username(Account * ac, char *username)
+{
+ if (!username || !ac)
+ return FALSE;
+
+ if (ac->username)
+ free(ac->username);
+
+ ac->username = g_strdup(username);
+ return TRUE;
+}
+
+int account_set_password(Account * ac, char *password)
+{
+ if (!password || !ac)
+ return FALSE;
+
+ if (ac->password)
+ free(ac->password);
+
+ ac->password = g_strdup(password);
+ return TRUE;
+}
+
char *account_get_name(Account * ac)
{
if (!ac)
@@ -182,35 +208,55 @@
account_set_server(acct, line + 12);
else if (g_strncasecmp(line, "full_name=", 10) == 0)
account_set_fullname(acct, line + 10);
- else if (g_strncasecmp(line, "email_address=", 14) == 0)
- account_set_address(acct, line + 14);
- else if (g_strncasecmp(line, "path=", 5) == 0)
- account_set_path(acct, line + 5);
+ else if (g_strncasecmp(line, "email_address=", 14) == 0)
+ account_set_address(acct, line + 14);
+ else if (g_strncasecmp(line, "path=", 5) == 0)
+ account_set_path(acct, line + 5);
}
return acct;
}
-Account *account_write(Account * acct)
+int account_write(Account * acct)
{
FILE *fp;
- gchar *file = g_strconcat(getenv("HOME"), "/.core/accounts/", acct->name, NULL);
+ gchar *file;
+
+ if (!acct)
+ return FALSE;
+
+ file =
+ g_strconcat(getenv("HOME"), "/.core/accounts/", acct->name,
+ NULL);
fp = fopen(file, "w");
if (fp == NULL) {
perror("fopen");
- return NULL;
+ return FALSE;
}
+
+ if (acct->name && *acct->name)
+ fprintf(fp, "account_name=%s\n", acct->name);
- fprintf(fp, "account_name=%s\n", acct->name);
- fprintf(fp, "full_name=%s\n", acct->full_name);
- fprintf(fp, "email_address=%s\n", acct->address);
- fprintf(fp, "username=%s\n", acct->username);
- fprintf(fp, "password=%s\n", acct->password);
- fprintf(fp, "smtp_server=%s\n", acct->server);
- fprintf(fp, "path=%s\n", acct->path);
+ if (acct->full_name && *acct->full_name)
+ fprintf(fp, "full_name=%s\n", acct->full_name);
- return NULL;
+ if (acct->address && *acct->address)
+ fprintf(fp, "email_address=%s\n", acct->address);
+
+ if (acct->username && *acct->username)
+ fprintf(fp, "username=%s\n", acct->username);
+
+ if (acct->username && *acct->username)
+ fprintf(fp, "password=%s\n", acct->password);
+
+ if (acct->server && *acct->server)
+ fprintf(fp, "smtp_server=%s\n", acct->server);
+
+ if (acct->path && *acct->path)
+ fprintf(fp, "path=%s\n", acct->path);
+
+ return TRUE;
}
Account *get_next_folder()
===================================================================
RCS file: /cvsroot/corem/core/src/account.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -3 -r1.6 -r1.7
--- account.h 2000/11/21 05:10:40 1.6
+++ account.h 2000/11/21 17:59:01 1.7
@@ -55,7 +55,7 @@
/* Read in the settings found in the file path, return an account structure */
Account *account_read(gchar * path);
-Account *account_write(Account * acct);
+int account_write(Account * acct);
/* Move through the various folders returning them one at a time */
Account *get_next_folder(void);
===================================================================
RCS file: /cvsroot/corem/core/src/callbacks.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -3 -r1.18 -r1.19
--- callbacks.c 2000/11/21 05:10:40 1.18
+++ callbacks.c 2000/11/21 17:59:01 1.19
@@ -5,10 +5,11 @@
#include "panes.h"
extern Account *current_mbox;
-extern Account *mail_ctree;
-extern ConfigData config;
+extern GtkWidget *mail_ctree;
extern GtkWidget *main_win;
+extern ConfigData config;
extern gchar *title;
+
GtkWidget *clist;
GtkWidget *folder_name, *full_name, *email_address, *type, *username,
*password, *server, *path;
@@ -20,11 +21,10 @@
{
GtkWidget *accounts_win;
GtkWidget *main_vbox, *hbox;
- GtkWidget *hbutton_box;
+ GtkWidget *hbutton_box;
GtkWidget *button_new, *button_edit, *button_remove, *button_close;
gchar *titles[] = { "Folder Name", "Full Name", "E-mail Address",
- "Mailbox Path"
- };
+ "Mailbox Path" };
/* Window title */
title = g_strdup_printf("Accounts");
@@ -49,8 +49,7 @@
/* The buttons at the bottom of the window */
hbutton_box = gtk_hbutton_box_new();
- gtk_box_pack_start(GTK_BOX(hbox), hbutton_box, FALSE, FALSE,
- 0);
+ gtk_box_pack_start(GTK_BOX(hbox), hbutton_box, FALSE, FALSE, 0);
/* New account button */
button_new = gtk_button_new_with_label("New");
@@ -58,7 +57,7 @@
gtk_signal_connect_object(GTK_OBJECT(button_new), "clicked",
GTK_SIGNAL_FUNC
(create_accounts_win_new_edit),
- GINT_TO_POINTER(0));
+ NULL);
gtk_container_add(GTK_CONTAINER(hbutton_box), button_new);
/* Edit account button */
@@ -67,7 +66,7 @@
gtk_signal_connect_object(GTK_OBJECT(button_edit), "clicked",
GTK_SIGNAL_FUNC
(create_accounts_win_new_edit),
- GINT_TO_POINTER(1));
+ NULL);
gtk_container_add(GTK_CONTAINER(hbutton_box), button_edit);
/* Remove account button */
@@ -87,9 +86,9 @@
}
/* The new/edit account window */
-void create_accounts_win_new_edit(gint type) /* type 0 for new account and
- type 1 for edit a account */
+void create_accounts_win_new_edit()
{
+
GtkWidget *main_vbox;
GtkWidget *table;
GtkWidget *label;
@@ -97,11 +96,10 @@
GtkWidget *hbutton_box;
GtkWidget *button_save, *button_cancel;
- /* Set the right title for the window */
- if (type == 0)
- title = g_strdup_printf("New Account");
- if (type == 1)
- title = g_strdup_printf("Edit Account");
+ /* Set the right title for the window */
+ /* This still needs to be done. It can be figured out by looking for a
+ * selected row in the account clist. */
+ title = g_strdup("New");
/* Create the new/edit account window */
accounts_win_new = gtk_window_new(GTK_WINDOW_TOPLEVEL);
@@ -123,7 +121,8 @@
1, GTK_EXPAND | GTK_FILL, 0, 1, 1);
/* Folder name entry */
- folder_name = gtk_entry_new();
+ folder_name = gtk_entry_new();
+ gtk_entry_set_text(GTK_ENTRY(folder_name), "");
gtk_widget_set_usize(GTK_WIDGET(folder_name), 200, 20);
gtk_table_attach(GTK_TABLE(table), folder_name, 1, 2, 0,
1, GTK_EXPAND | GTK_FILL, 0, 1, 1);
@@ -135,6 +134,7 @@
/* Full name entry */
full_name = gtk_entry_new();
+ gtk_entry_set_text(GTK_ENTRY(full_name), "");
gtk_widget_set_usize(GTK_WIDGET(full_name), 200, 20);
gtk_table_attach(GTK_TABLE(table), full_name, 1, 2, 1,
2, GTK_EXPAND | GTK_FILL, 0, 1, 1);
@@ -146,6 +146,7 @@
/* E-mail address entry */
email_address = gtk_entry_new();
+ gtk_entry_set_text(GTK_ENTRY(email_address), "");
gtk_widget_set_usize(GTK_WIDGET(email_address), 200, 20);
gtk_table_attach(GTK_TABLE(table), email_address, 1, 2, 2,
3, GTK_EXPAND | GTK_FILL, 0, 1, 1);
@@ -162,6 +163,7 @@
/* Username entry */
username = gtk_entry_new();
+ gtk_entry_set_text(GTK_ENTRY(username), "");
gtk_widget_set_usize(GTK_WIDGET(username), 100, 20);
gtk_table_attach(GTK_TABLE(table), username, 1, 2, 0,
1, GTK_EXPAND | GTK_FILL, 0, 1, 1);
@@ -173,6 +175,7 @@
/* Password entry */
password = gtk_entry_new();
+ gtk_entry_set_text(GTK_ENTRY(password), "");
gtk_widget_set_usize(GTK_WIDGET(password), 100, 20);
gtk_table_attach(GTK_TABLE(table), password, 3, 4, 0,
1, GTK_EXPAND | GTK_FILL, 0, 1, 1);
@@ -184,6 +187,7 @@
/* Server entry */
server = gtk_entry_new();
+ gtk_entry_set_text(GTK_ENTRY(server), "");
gtk_widget_set_usize(GTK_WIDGET(server), 100, 20);
gtk_table_attach(GTK_TABLE(table), server, 1, 2, 1,
2, GTK_EXPAND | GTK_FILL, 0, 1, 1);
@@ -195,6 +199,7 @@
/* Path entry */
path = gtk_entry_new();
+ gtk_entry_set_text(GTK_ENTRY(path), "");
gtk_widget_set_usize(GTK_WIDGET(path), 100, 20);
gtk_table_attach(GTK_TABLE(table), path, 3, 4, 1,
2, GTK_EXPAND | GTK_FILL, 0, 1, 1);
@@ -212,8 +217,7 @@
button_save = gtk_button_new_with_label("Save");
gtk_widget_set_usize(GTK_WIDGET(button_save), 55, 22);
gtk_signal_connect(GTK_OBJECT(button_save), "clicked",
- GTK_SIGNAL_FUNC(save_account),
- GINT_TO_POINTER(type));
+ GTK_SIGNAL_FUNC(save_account), NULL);
gtk_container_add(GTK_CONTAINER(hbutton_box), button_save);
/* Cancel button */
@@ -229,20 +233,24 @@
}
-void save_account(gint type)
+void save_account()
{
Account *acct;
acct = new_account();
- acct->name = gtk_entry_get_text(GTK_ENTRY(folder_name));
- acct->full_name = gtk_entry_get_text(GTK_ENTRY(full_name));
- acct->address = gtk_entry_get_text(GTK_ENTRY(email_address));
- /*acct->type = gtk_entry_get_text(GTK_ENTRY(type));*/
- acct->username = gtk_entry_get_text(GTK_ENTRY(username));
- acct->password = gtk_entry_get_text(GTK_ENTRY(password));
- acct->server = gtk_entry_get_text(GTK_ENTRY(server));
- acct->path = gtk_entry_get_text(GTK_ENTRY(path));
+ account_set_name(acct, gtk_entry_get_text(GTK_ENTRY(folder_name)));
+ account_set_fullname(acct,
+ gtk_entry_get_text(GTK_ENTRY(full_name)));
+ account_set_address(acct,
+ gtk_entry_get_text(GTK_ENTRY(email_address)));
+ /*acct->type = gtk_entry_get_text(GTK_ENTRY(type)); */
+ account_set_username(acct,
+ gtk_entry_get_text(GTK_ENTRY(username)));
+ account_set_password(acct,
+ gtk_entry_get_text(GTK_ENTRY(password)));
+ account_set_server(acct, gtk_entry_get_text(GTK_ENTRY(server)));
+ account_set_path(acct, gtk_entry_get_text(GTK_ENTRY(path)));
account_write(acct);
===================================================================
RCS file: /cvsroot/corem/core/src/callbacks.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -3 -r1.6 -r1.7
--- callbacks.h 2000/11/21 05:10:40 1.6
+++ callbacks.h 2000/11/21 17:59:01 1.7
@@ -60,7 +60,7 @@
void create_account_window();
/* The new/edit account window */
-void create_accounts_win_new_edit(gint type);
+void create_accounts_win_new_edit(void);
/* Save account */
-void save_account(gint type);
+void save_account(void);
|