|
From: CORE C. L. <cor...@li...> - 2000-11-21 05:10:41
|
Core CVS committal
Author : smugg
Project : core
Module : src
Modified Files:
account.c account.h callbacks.c callbacks.h
Log Message:
added a save_account, and account_write, now it works saving a account, fixed the folder_selected bug, now we need to fix listing of accounts for the main accounts window
===================================================================
RCS file: /cvsroot/corem/core/src/account.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -3 -r1.6 -r1.7
--- account.c 2000/11/20 22:59:01 1.6
+++ account.c 2000/11/21 05:10:40 1.7
@@ -182,15 +182,37 @@
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, "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, "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)
+{
+ FILE *fp;
+ gchar *file = g_strconcat(getenv("HOME"), "/.core/accounts/", acct->name, NULL);
+
+ fp = fopen(file, "w");
+ if (fp == NULL) {
+ perror("fopen");
+ return NULL;
+ }
+
+ 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);
+
+ return NULL;
+}
+
Account *get_next_folder()
{
struct stat file_stat;
@@ -235,11 +257,11 @@
return mbox;
}
-int account_reset_file(Account *ac)
+int account_reset_file(Account * ac)
{
- if (!ac || !ac->fp)
- return FALSE;
+ if (!ac || !ac->fp)
+ return FALSE;
- rewind(ac->fp);
- return TRUE;
+ rewind(ac->fp);
+ return TRUE;
}
===================================================================
RCS file: /cvsroot/corem/core/src/account.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -3 -r1.5 -r1.6
--- account.h 2000/11/20 22:59:01 1.5
+++ account.h 2000/11/21 05:10:40 1.6
@@ -55,8 +55,9 @@
/* Read in the settings found in the file path, return an account structure */
Account *account_read(gchar * path);
+Account *account_write(Account * acct);
/* Move through the various folders returning them one at a time */
Account *get_next_folder(void);
/* Reset the file pointer for the local mailbox */
-int account_reset(Account *ac);
+int account_reset(Account * ac);
===================================================================
RCS file: /cvsroot/corem/core/src/callbacks.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -3 -r1.17 -r1.18
--- callbacks.c 2000/11/20 22:59:01 1.17
+++ callbacks.c 2000/11/21 05:10:40 1.18
@@ -14,37 +14,45 @@
*password, *server, *path;
GtkWidget *accounts_win_new;
+
+/* The main account window */
void create_account_window()
{
GtkWidget *accounts_win;
- GtkWidget *main_vbox, *vbox;
- GtkWidget *hbutton_box;
+ GtkWidget *main_vbox, *hbox;
+ GtkWidget *hbutton_box;
GtkWidget *button_new, *button_edit, *button_remove, *button_close;
gchar *titles[] = { "Folder Name", "Full Name", "E-mail Address",
"Mailbox Path"
};
+ /* Window title */
title = g_strdup_printf("Accounts");
+ /* Create the account window */
accounts_win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ /* Set title for the account window */
gtk_window_set_title(GTK_WINDOW(accounts_win), title);
+ /* Account window main vbox */
main_vbox = gtk_vbox_new(FALSE, 0);
gtk_container_set_border_width(GTK_CONTAINER(main_vbox), 0);
gtk_container_add(GTK_CONTAINER(accounts_win), main_vbox);
- vbox = gtk_vbox_new(FALSE, 0);
- gtk_container_set_border_width(GTK_CONTAINER(vbox), 0);
- gtk_box_pack_start(GTK_BOX(main_vbox), vbox, TRUE, TRUE, 0);
-
+ /* The clist for browsing accounts */
clist = gtk_clist_new_with_titles(4, titles);
gtk_widget_set_usize(GTK_WIDGET(clist), 600, 180);
- gtk_container_add(GTK_CONTAINER(vbox), clist);
+ gtk_container_add(GTK_CONTAINER(main_vbox), clist);
+
+ hbox = gtk_hbox_new(FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(main_vbox), hbox, FALSE, FALSE, 0);
+ /* The buttons at the bottom of the window */
hbutton_box = gtk_hbutton_box_new();
- gtk_box_pack_start(GTK_BOX(main_vbox), hbutton_box, FALSE, FALSE,
+ gtk_box_pack_start(GTK_BOX(hbox), hbutton_box, FALSE, FALSE,
0);
+ /* New account button */
button_new = gtk_button_new_with_label("New");
gtk_widget_set_usize(GTK_WIDGET(button_new), 55, 22);
gtk_signal_connect_object(GTK_OBJECT(button_new), "clicked",
@@ -53,6 +61,7 @@
GINT_TO_POINTER(0));
gtk_container_add(GTK_CONTAINER(hbutton_box), button_new);
+ /* Edit account button */
button_edit = gtk_button_new_with_label("Edit");
gtk_widget_set_usize(GTK_WIDGET(button_edit), 55, 22);
gtk_signal_connect_object(GTK_OBJECT(button_edit), "clicked",
@@ -61,135 +70,153 @@
GINT_TO_POINTER(1));
gtk_container_add(GTK_CONTAINER(hbutton_box), button_edit);
+ /* Remove account button */
button_remove = gtk_button_new_with_label("Remove");
gtk_widget_set_usize(GTK_WIDGET(button_remove), 55, 22);
gtk_container_add(GTK_CONTAINER(hbutton_box), button_remove);
-
- hbutton_box = gtk_hbutton_box_new();
- gtk_box_pack_start(GTK_BOX(main_vbox), hbutton_box, FALSE, FALSE,
- 0);
+ /* Close button */
button_close = gtk_button_new_with_label("Close");
gtk_signal_connect_object(GTK_OBJECT(button_close), "clicked",
GTK_SIGNAL_FUNC(gtk_widget_destroy),
GTK_OBJECT(accounts_win));
gtk_container_add(GTK_CONTAINER(hbutton_box), button_close);
+ /* Show all widgets in the accounts window */
gtk_widget_show_all(accounts_win);
}
-
-void create_accounts_win_new_edit(gint type)
+/* 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 */
{
- GtkWidget *main_vbox, *hbox;
+ GtkWidget *main_vbox;
GtkWidget *table;
GtkWidget *label;
GtkWidget *sep1;
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");
-
+ /* Create the new/edit account window */
accounts_win_new = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(accounts_win_new), title);
+ /* Main vbox, in here everything goes */
main_vbox = gtk_vbox_new(FALSE, 0);
gtk_container_set_border_width(GTK_CONTAINER(main_vbox), 0);
gtk_container_add(GTK_CONTAINER(accounts_win_new), main_vbox);
+ /* A nice table with 2 columns */
table = gtk_table_new(4, 2, FALSE);
gtk_table_set_row_spacings(GTK_TABLE(table), 2);
gtk_box_pack_start(GTK_BOX(main_vbox), table, FALSE, FALSE, 4);
+ /* Folder name label */
label = gtk_label_new("Folder Name:");
gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0,
1, GTK_EXPAND | GTK_FILL, 0, 1, 1);
+ /* Folder name entry */
folder_name = gtk_entry_new();
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);
+ /* Full name label */
label = gtk_label_new("Full Name:");
gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1,
2, GTK_EXPAND | GTK_FILL, 0, 1, 1);
+ /* Full name entry */
full_name = gtk_entry_new();
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);
+ /* E-mail address label */
label = gtk_label_new("E-mail Address:");
gtk_table_attach(GTK_TABLE(table), label, 0, 1, 2,
3, GTK_EXPAND | GTK_FILL, 0, 1, 1);
+ /* E-mail address entry */
email_address = gtk_entry_new();
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);
+ /* A nice table with 4 columns */
table = gtk_table_new(2, 4, FALSE);
gtk_table_set_row_spacings(GTK_TABLE(table), 2);
gtk_box_pack_start(GTK_BOX(main_vbox), table, FALSE, FALSE, 4);
+ /* Username label */
label = gtk_label_new("Username:");
gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0,
1, GTK_EXPAND | GTK_FILL, 0, 1, 1);
+ /* Username entry */
username = gtk_entry_new();
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);
+ /* Password label */
label = gtk_label_new("Password:");
gtk_table_attach(GTK_TABLE(table), label, 2, 3, 0,
1, GTK_EXPAND | GTK_FILL, 0, 1, 1);
+ /* Password entry */
password = gtk_entry_new();
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);
+ /* Server label */
label = gtk_label_new("Server:");
gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1,
2, GTK_EXPAND | GTK_FILL, 0, 1, 1);
+ /* Server entry */
server = gtk_entry_new();
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);
+ /* Path label */
label = gtk_label_new("Path:");
gtk_table_attach(GTK_TABLE(table), label, 2, 3, 1,
2, GTK_EXPAND | GTK_FILL, 0, 1, 1);
+ /* Path entry */
path = gtk_entry_new();
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);
- hbox = gtk_hbox_new(FALSE, 0);
- gtk_container_set_border_width(GTK_CONTAINER(hbox), 0);
- gtk_box_pack_start(GTK_BOX(main_vbox), hbox, TRUE, TRUE, 0);
-
+ /* A separator betwen the entryboxes and the buttons */
sep1 = gtk_hseparator_new();
gtk_box_pack_start(GTK_BOX(main_vbox), sep1, TRUE, TRUE, 0);
+ /* A new hbutton box */
hbutton_box = gtk_hbutton_box_new();
gtk_box_pack_start(GTK_BOX(main_vbox), hbutton_box, FALSE, FALSE,
0);
+ /* Save button */
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(account_write),
- GINT_TO_POINTER(type)); */
+ gtk_signal_connect(GTK_OBJECT(button_save), "clicked",
+ GTK_SIGNAL_FUNC(save_account),
+ GINT_TO_POINTER(type));
gtk_container_add(GTK_CONTAINER(hbutton_box), button_save);
+ /* Cancel button */
button_cancel = gtk_button_new_with_label("Cancel");
gtk_widget_set_usize(GTK_WIDGET(button_cancel), 55, 22);
gtk_signal_connect_object(GTK_OBJECT(button_cancel), "clicked",
@@ -197,63 +224,42 @@
GTK_OBJECT(accounts_win_new));
gtk_container_add(GTK_CONTAINER(hbutton_box), button_cancel);
+ /* Show all widgets in new/edit account window */
gtk_widget_show_all(accounts_win_new);
}
-void account_write()
+void save_account(gint type)
{
- /*FILE *account;
- gchar *account_file;
- gchar *acct_name, *fullname, *email, *spool, *pop, *smtp;
-
- acct_name = g_strdup(gtk_entry_get_text(GTK_ENTRY(account_name)));
- fullname = g_strdup(gtk_entry_get_text(GTK_ENTRY(full_name)));
- email = g_strdup(gtk_entry_get_text(GTK_ENTRY(email_address)));
- if (type == 0)
- spool = g_strdup(gtk_entry_get_text(GTK_ENTRY(spoolfile)));
- if (type == 1)
- pop = g_strdup(gtk_entry_get_text(GTK_ENTRY(popserver)));
- mtp = g_strdup(gtk_entry_get_text(GTK_ENTRY(smtpserver)));
-
- account_file =
- g_strconcat(getenv("HOME"), "/.core/accounts/", acct_name, NULL);
-
- if (g_strcasecmp(acct_name, "") == 0) {
- g_print("ERROR: You must specify a account name");
- return;
- }
-
- account = fopen(account_file, "w");
- if (account == NULL) {
- fprintf(account, "ERROR: Cannot write to account file\n");
- return;
- }
-
- if (type == 0)
- fprintf(account, "account_type=mbox\n");
- if (type == 1)
- fprintf(account, "account_type=pop3\n");
- fprintf(account, "account_name=%s\n", acct_name);
- fprintf(account, "full_name=%s\n", fullname);
- fprintf(account, "email_address=%s\n", email);
- if (type == 0)
- fprintf(account, "spoolfile=%s\n", spool);
- if (type == 1)
- fprintf(account, "popserver=%s\n", pop);
- fprintf(account, "smtpserver=%s\n", smtp);
+ Account *acct;
+
+ acct = new_account();
- gtk_widget_destroy(accounts_win_new);
- return; */
+ 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_write(acct);
+
+ gtk_widget_destroy(accounts_win_new);
+ return;
}
+/* This creates the preference window with the correct title About */
void create_core_about_window(void)
{
+ /* Set the title */
gchar *title = g_strdup_printf("About");
+ /* Pass the title to right callback */
create_preferences_window_cb(title);
}
-
+/* Calls the create_mail_window_cb showing the right stuff for viewing a mail */
void create_mail_window_view(GtkWidget * button, gpointer data)
{
Message *m;
@@ -271,6 +277,7 @@
button = NULL;
}
+/* Calls the create_mail_window_cb showing the right stuff for creating a new mail */
void create_mail_window_new(GtkWidget * button)
{
Message *m;
@@ -285,6 +292,7 @@
button = NULL;
}
+/* Calls the create_mail_window_cb showing the right stuff for replying to a mail */
void create_mail_window_reply(GtkWidget * button, gpointer data)
{
Message *m;
@@ -301,6 +309,7 @@
button = NULL;
}
+/* Calls the create_mail_window_cb showing the right stuff to reply to all recipients of a mail */
void create_mail_window_reply_all(GtkWidget * button, gpointer data)
{
Message *m;
@@ -316,6 +325,7 @@
button = NULL;
}
+/* Calls the create_mail_window_cb showing the right stuff to forward a mail */
void create_mail_window_forward(GtkWidget * button, gpointer data)
{
Message *m;
@@ -332,6 +342,7 @@
button = NULL;
}
+/* The real create_mail_window callback */
void create_mail_window_cb(gchar * title, Message * message,
MessageFlags mode)
{
@@ -362,6 +373,7 @@
gtk_widget_show_all(mail);
}
+/* Function when selecting a folder */
int folder_selected(GtkWidget * list, GList * node, gint col,
gpointer data)
{
@@ -372,10 +384,7 @@
mbox = (Account *) gtk_ctree_node_get_row_data(GTK_CTREE(list),
GTK_CTREE_NODE
(node));
- title =
- g_strdup_printf("Core %d.%d.%d", CORE_MAJOR,
- CORE_MINOR, CORE_MICRO);
- gtk_window_set_title(GTK_WINDOW(main_win), title);
+
while (1) {
GtkCTreeNode *top, *item;
char *temp;
@@ -485,17 +494,18 @@
free);
destroy_message(message);
}
- current_mbox = mbox;
- account_reset_file(mbox);
+ current_mbox = mbox;
+ account_reset_file(mbox);
return TRUE;
data = NULL;
}
+/* Function for unselecting a item in the folder ctree */
int folder_unselected(GtkWidget * list, GList * node, gint col,
gpointer data)
{
- gtk_ctree_remove_node(GTK_CTREE(mail_ctree), NULL);
+ gtk_ctree_remove_node(GTK_CTREE(mail_ctree), NULL);
return TRUE;
list = NULL;
@@ -504,6 +514,7 @@
data = NULL;
}
+/* Function for selecting a mail in the mail ctree */
int mail_selected(GtkWidget * list, GList * node, gint col, gpointer data)
{
char *temp;
@@ -522,6 +533,9 @@
data = NULL;
}
+/* Function for unselecting a mail in the mail ctree
+ * Don't really need to do anything in this function, nothing to free from memory
+ */
int mail_unselected(GtkWidget * list, GList * node, gint col,
gpointer data)
{
===================================================================
RCS file: /cvsroot/corem/core/src/callbacks.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -3 -r1.5 -r1.6
--- callbacks.h 2000/11/20 21:02:13 1.5
+++ callbacks.h 2000/11/21 05:10:40 1.6
@@ -1,31 +1,66 @@
+/* This function is called from main() to create the main window */
void create_core_main_window(void);
+
+/* This function creates the preference window with 'About' as title */
void create_core_about_window(void);
+
+/* The main menu widget */
GtkWidget *create_main_menu();
+
+/* The toolbar that goes in the main window */
GtkWidget *create_main_toolbar();
-void create_account_window();
+
+/* The real callback for create_mail_window_view/new/reply/reply_all/forward */
void create_mail_window_cb(gchar * title, Message * message,
MessageFlags mode);
+
+/* Calls the create_mail_window_cb showing the right stuff for viewing a mail */
void create_mail_window_view(GtkWidget * button, gpointer data);
+
+/* Calls the create_mail_window_cb showing the right stuff for creating a new mail */
void create_mail_window_new(GtkWidget * button);
+
+/* Calls the create_mail_window_cb showing the right stuff for replying to a mail */
void create_mail_window_reply(GtkWidget * button, gpointer data);
+
+/* Calls the create_mail_window_cb showing the right stuff to reply to all recipients of a mail */
void create_mail_window_reply_all(GtkWidget * button, gpointer data);
+
+/* Calls the create_mail_window_cb showing the right stuff to forward a mail */
void create_mail_window_forward(GtkWidget * button, gpointer data);
+/* The mail window menu */
void create_mail_menu(GtkWidget * window, GtkWidget ** menubar);
+/* Function when selecting a folder */
int folder_selected(GtkWidget * list, GList * node, gint col,
gpointer data);
+/* Function when unselecting a folder */
int folder_unselected(GtkWidget * list, GList * node, gint col,
gpointer data);
+/* Function for selecting a mail in the mail ctree */
int mail_selected(GtkWidget * list, GList * node, gint col, gpointer data);
+
+/* Function for unselecting a mail in the mail ctree
+ * Don't really need to do anything in this function, nothing to free from memory */
int mail_unselected(GtkWidget * list, GList * node, gint col,
gpointer data);
+/* Menu function for hiding/shoing the toolbar */
void toolbar_hide_show();
+
+/* Change toolbar typ, 0 for text, 1 for icons and 2 for both text and icons */
void toolbar_change_layout(gint type);
+
+/* Quit core funcion */
void core_main_quit(void);
+/* The main account window */
+void create_account_window();
+
+/* The new/edit account window */
void create_accounts_win_new_edit(gint type);
-void create_accounts_win_delete();
-void account_write();
+
+/* Save account */
+void save_account(gint type);
|