Enlightenment CVS committal
Author : fletch3k
Project : misc
Module : enotes
Dir : misc/enotes/src
Modified Files:
config.c config.h debug.c main.c main.h note.c note.h
saveload.c settings.c settings.h storage.c storage.h usage.c
usage.h
Log Message:
Autosave Feature.
===================================================================
RCS file: /cvsroot/enlightenment/misc/enotes/src/config.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -3 -r1.4 -r1.5
--- config.c 15 Feb 2004 15:13:34 -0000 1.4
+++ config.c 17 Feb 2004 12:07:28 -0000 1.5
@@ -26,6 +26,7 @@
p->debug = 0;
p->intro = 0;
p->controlcentre = 1;
+ p->autosave = 1;
return (p);
}
@@ -100,7 +101,10 @@
p->intro = atoi(info->value);
} else if (!strcmp(info->name, "debug")) {
p->debug = atoi(info->value);
+ } else if (!strcmp(info->name, "autosave")) {
+ p->autosave = atoi(info->value);
}
+
return;
}
===================================================================
RCS file: /cvsroot/enlightenment/misc/enotes/src/config.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -3 -r1.4 -r1.5
--- config.h 15 Feb 2004 15:13:35 -0000 1.4
+++ config.h 17 Feb 2004 12:07:28 -0000 1.5
@@ -32,6 +32,7 @@
int controlcentre;
int intro;
int debug;
+ int autosave;
} MainConfig;
#ifndef XMLENTRY_DEF
===================================================================
RCS file: /cvsroot/enlightenment/misc/enotes/src/debug.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- debug.c 6 Feb 2004 07:36:30 -0000 1.2
+++ debug.c 17 Feb 2004 12:07:28 -0000 1.3
@@ -114,15 +114,21 @@
{"save_settings", 1},
/* storage */
+ {"alloc_note_stor", 1},
{"free_note_stor", 1},
{"append_note_stor", 1},
+ {"append_autosave_note_stor", 1},
{"remove_note_stor", 1},
{"stor_cycle_begin", 1},
+ {"stor_cycle_begin_autosave", 1},
{"stor_cycle_end", 1},
{"stor_cycle_next", 1},
{"stor_cycle_prev", 1},
{"stor_cycle_get_notestor", 1},
+ {"autoload", 1},
+ {"autosave", 1},
{"make_storage_fn", 1},
+ {"make_autosave_fn", 1},
{"get_notestor_from_value", 1},
{"get_value_from_notestor", 1},
===================================================================
RCS file: /cvsroot/enlightenment/misc/enotes/src/main.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -3 -r1.6 -r1.7
--- main.c 15 Feb 2004 15:13:35 -0000 1.6
+++ main.c 17 Feb 2004 12:07:28 -0000 1.7
@@ -101,12 +101,22 @@
free_note_stor(tmpn);
}
+ /* Autoloading */
+ if (main_config->autosave == 1) {
+ autoload();
+ }
+
/* Begin the main loop */
dml("Starting Main Loop", 1);
ecore_main_loop_begin();
dml("Main Loop Ended", 1);
+ /* Autosaving */
+ if (main_config->autosave == 1) {
+ autosave();
+ }
+
/* Shutdown the E-Libs */
edje_shutdown();
ecore_evas_shutdown();
===================================================================
RCS file: /cvsroot/enlightenment/misc/enotes/src/main.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -3 -r1.4 -r1.5
--- main.h 15 Feb 2004 15:13:35 -0000 1.4
+++ main.h 17 Feb 2004 12:07:28 -0000 1.5
@@ -25,6 +25,7 @@
#include "config.h"
#include "note.h"
+#include "storage.h"
#include "usage.h"
#include "debug.h"
===================================================================
RCS file: /cvsroot/enlightenment/misc/enotes/src/note.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -3 -r1.9 -r1.10
--- note.c 16 Feb 2004 11:23:03 -0000 1.9
+++ note.c 17 Feb 2004 12:07:28 -0000 1.10
@@ -80,7 +80,7 @@
double edje_w, edje_h;
/* Fix Newlines in Content */
- fcontent=fix_newlines (content);
+ fcontent = fix_newlines(content);
/* Get the Note from the Evas_List** */
pl = *note;
@@ -186,7 +186,7 @@
if (fontpath != NULL)
free(fontpath);
if (fcontent != NULL)
- free (fcontent);
+ free(fcontent);
return;
}
===================================================================
RCS file: /cvsroot/enlightenment/misc/enotes/src/note.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -3 -r1.3 -r1.4
--- note.h 7 Feb 2004 15:26:54 -0000 1.3
+++ note.h 17 Feb 2004 12:07:28 -0000 1.4
@@ -21,6 +21,7 @@
#include "debug.h"
#include "config.h"
+#include "ipc.h"
#include "../config.h"
===================================================================
RCS file: /cvsroot/enlightenment/misc/enotes/src/saveload.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -3 -r1.5 -r1.6
--- saveload.c 6 Feb 2004 22:12:46 -0000 1.5
+++ saveload.c 17 Feb 2004 12:07:28 -0000 1.6
@@ -242,9 +242,9 @@
int x, y, w, h;
Note *note;
Evas_List *p;
- NoteStor *n = malloc(sizeof(NoteStor));
+ NoteStor *n = alloc_note_stor();
- dml("Saving Selection", 2);
+ dml("Saving Selected Note", 2);
if (saveload_selected == NULL)
return;
===================================================================
RCS file: /cvsroot/enlightenment/misc/enotes/src/settings.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -3 -r1.4 -r1.5
--- settings.c 15 Feb 2004 15:13:35 -0000 1.4
+++ settings.c 17 Feb 2004 12:07:28 -0000 1.5
@@ -128,6 +128,11 @@
setup_settings_opt_int(settings->tree, "Debugging Level [0-2]:",
main_config->debug);
+ settings->autosave =
+ setup_settings_opt_int(settings->tree,
+ "Autosaving [0=No 1=Yes]:",
+ main_config->autosave);
+
return;
}
@@ -249,6 +254,9 @@
xml_write_append_entry(p, "debug",
ewl_entry_get_text((Ewl_Entry *) settings->debug.
entry));
+ xml_write_append_entry(p, "autosave",
+ ewl_entry_get_text((Ewl_Entry *) settings->
+ autosave.entry));
xml_write_end(p);
===================================================================
RCS file: /cvsroot/enlightenment/misc/enotes/src/settings.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -3 -r1.4 -r1.5
--- settings.h 15 Feb 2004 15:13:35 -0000 1.4
+++ settings.h 17 Feb 2004 12:07:28 -0000 1.5
@@ -47,7 +47,7 @@
Ewl_Widget *savebtn;
Ewl_Widget *revertbtn;
Ewl_Widget *closebtn;
- Settings_Opt render_method, theme, intro, debug, cc;
+ Settings_Opt render_method, theme, intro, debug, cc, autosave;
} Settings;
extern MainConfig *main_config;
===================================================================
RCS file: /cvsroot/enlightenment/misc/enotes/src/storage.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -3 -r1.4 -r1.5
--- storage.c 15 Feb 2004 15:13:35 -0000 1.4
+++ storage.c 17 Feb 2004 12:07:29 -0000 1.5
@@ -40,6 +40,62 @@
/* One Shot Functions. :-) */
void
+append_autosave_note_stor(NoteStor * p)
+{
+ Evas_List *list;
+ Evas_List *lt;
+ XmlReadHandle *r;
+ XmlWriteHandle *w;
+ XmlEntry *e;
+ char *fn;
+ char *value;
+ char *val;
+
+ list = NULL;
+
+ /* Making the strings */
+ value = get_value_from_notestor(p);
+ fn = make_autosave_fn();
+
+ /* Read */
+ r = xml_read(fn);
+ if (r != NULL) {
+ while (r->cur != NULL) {
+ e = xml_read_entry_get_entry(r);
+ list = evas_list_append(list, strdup(e->value));
+ free_xmlentry(e);
+ xml_read_next_entry(r);
+ }
+ xml_read_end(r);
+ } else {
+ list = NULL;
+ }
+
+ /* Write */
+ w = xml_write(fn);
+ if (list != NULL) {
+ lt = list;
+ while (lt != NULL) {
+ xml_write_append_entry(w, "NoteStor",
+ (char *) evas_list_data(lt));
+ free(evas_list_data(lt));
+ list = evas_list_remove(lt, evas_list_data(lt));
+ lt = evas_list_next(lt);
+ }
+ }
+ val = get_value_from_notestor(p);
+ xml_write_append_entry(w, "NoteStor", val);
+ free(val);
+ xml_write_end(w);
+
+ /* Leaving */
+ evas_list_free(list);
+ free(value);
+ free(fn);
+ return;
+}
+
+void
append_note_stor(NoteStor * p)
{
Evas_List *list;
@@ -170,6 +226,18 @@
return (retval);
}
+XmlReadHandle *
+stor_cycle_begin_autosave(void)
+{
+ char *p;
+ XmlReadHandle *retval;
+
+ p = make_autosave_fn();
+ retval = xml_read(p);
+ free(p);
+ return (retval);
+}
+
void
stor_cycle_end(XmlReadHandle * p)
{
@@ -205,6 +273,61 @@
return (h);
}
+/* Autosave Functions */
+void
+autoload(void)
+{
+ XmlReadHandle *r;
+ NoteStor *p;
+
+ dml("Autoloading Saved Notes", 1);
+
+ r = stor_cycle_begin_autosave();
+ if (r != NULL) {
+ while (r->cur != NULL) {
+ p = stor_cycle_get_notestor(r);
+ new_note_with_values(p->width, p->height, p->title,
+ p->content);
+ free_note_stor(p);
+ stor_cycle_next(r);
+ }
+ stor_cycle_end(r);
+ }
+ return;
+}
+
+void
+autosave(void)
+{
+ int x, y, w, h;
+ Note *note;
+ Evas_List *tmp = gbl_notes;
+ NoteStor *n;
+ XmlWriteHandle *p;
+ char *pp;
+
+ dml("Autosaving", 1);
+
+ pp = make_autosave_fn();
+ p = xml_write(pp);
+ xml_write_end(p);
+ free(pp);
+
+ while ((tmp = evas_list_next(tmp)) != NULL) {
+ note = evas_list_data(tmp);
+ ecore_evas_geometry_get(note->win, &x, &y, &w, &h);
+ n = alloc_note_stor();
+ n->width = w;
+ n->height = h;
+ n->title = strdup(get_title_by_note(tmp));
+ n->content = strdup(get_content_by_note(tmp));
+ append_autosave_note_stor(n);
+ free_note_stor(n);
+ }
+
+ return;
+}
+
/* Internal Functions */
char *
make_storage_fn(void)
@@ -215,6 +338,15 @@
return (p);
}
+char *
+make_autosave_fn(void)
+{
+ char *p = malloc(PATH_MAX);
+
+ snprintf(p, PATH_MAX, DEF_AUTOSAVE_LOC, getenv("HOME"));
+ return (p);
+}
+
NoteStor *
get_notestor_from_value(char *e)
{
===================================================================
RCS file: /cvsroot/enlightenment/misc/enotes/src/storage.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -3 -r1.2 -r1.3
--- storage.h 6 Feb 2004 07:36:31 -0000 1.2
+++ storage.h 17 Feb 2004 12:07:29 -0000 1.3
@@ -22,9 +22,11 @@
#include <Evas.h> // For the list structures.
#include "xml.h"
+#include "note.h"
#include "debug.h"
#define DEF_STORAGE_LOC "%s/.e/notes/notes.xml"
+#define DEF_AUTOSAVE_LOC "%s/.e/notes/autosave.xml"
#define DEF_VALUE_SEPERATION "|"
#define MAX_VALUE 2000
@@ -36,14 +38,17 @@
} NoteStor;
/* Freeing */
+NoteStor *alloc_note_stor();
void free_note_stor(NoteStor * p);
/* One Shot Functions. :-) */
void append_note_stor(NoteStor * p);
+void append_autosave_note_stor(NoteStor * p);
void remove_note_stor(NoteStor * p);
/* Cycle Functions */
XmlReadHandle *stor_cycle_begin(void);
+XmlReadHandle *stor_cycle_begin_autosave(void);
void stor_cycle_end(XmlReadHandle * p);
void stor_cycle_next(XmlReadHandle * p);
@@ -51,8 +56,14 @@
NoteStor *stor_cycle_get_notestor(XmlReadHandle * p);
+/* Autosave Functions */
+void autoload(void);
+void autosave(void);
+
/* Internal Functions */
char *make_storage_fn(void);
+char *make_autosave_fn(void);
+
NoteStor *get_notestor_from_value(char *e);
char *get_value_from_notestor(NoteStor * p);
===================================================================
RCS file: /cvsroot/enlightenment/misc/enotes/src/usage.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -3 -r1.5 -r1.6
--- usage.c 15 Feb 2004 15:13:35 -0000 1.5
+++ usage.c 17 Feb 2004 12:07:29 -0000 1.6
@@ -66,10 +66,16 @@
main_config->theme = strdup(optarg);
break;
case 'C':
- main_config->controlcentre = atoi(optarg);
+ if (atoi(optarg) == 0 || atoi(optarg) == 1)
+ main_config->controlcentre = atoi(optarg);
+ break;
+ case 'A':
+ if (atoi(optarg) == 0 || atoi(optarg) == 1)
+ main_config->autosave = atoi(optarg);
break;
case 'i':
- main_config->intro = atoi(optarg);
+ if (atoi(optarg) == 0 || atoi(optarg) == 1)
+ main_config->intro = atoi(optarg);
break;
case 'v':
printf(USAGE_VERSION, VERSION);
===================================================================
RCS file: /cvsroot/enlightenment/misc/enotes/src/usage.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -3 -r1.4 -r1.5
--- usage.h 15 Feb 2004 15:13:35 -0000 1.4
+++ usage.h 17 Feb 2004 12:07:29 -0000 1.5
@@ -43,13 +43,15 @@
-t --theme STR Theme\n\
-C --control-centre INT Enable/Disable the Control\n\
Centre.\n\
+-A --auto-save INT Enable the autosaving and\n\
+ loading of notes.\n\
-i --intro INT Display the Intro.\n\
\
\n"
#define USAGE_VERSION "E-Notes Version:\n%s\n"
-#define OPTSTR "v?hc:r:t:i:R:d:"
+#define OPTSTR "v?hc:r:t:i:R:d:A:"
static struct option long_options[] = {
{"help", 0, 0, '?'},
@@ -61,6 +63,7 @@
{"control-centre", 1, 0, 'C'},
{"intro", 1, 0, 'i'},
{"debug", 1, 0, 'd'},
+ {"auto-save", 1, 0, 'A'},
{NULL, 0, 0, 0}
};
-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
_______________________________________________
enlightenment-cvs mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs