Enlightenment CVS committal

Author  : handyande
Project : misc
Module  : enotes

Dir     : misc/enotes/src


Modified Files:
        main.c note.c note.h saveload.c storage.c storage.h 


Log Message:
Merge autosave with main save
Autosave now simply is a regular save for all notes on a timer
when closing a note ask if you want to delete or unload
clear up some unused methods
===================================================================
RCS file: /cvsroot/enlightenment/misc/enotes/src/main.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -3 -r1.26 -r1.27
--- main.c      6 Mar 2006 20:53:18 -0000       1.26
+++ main.c      16 Mar 2006 00:05:55 -0000      1.27
@@ -50,8 +50,8 @@
        ecore_ipc_init();
        dml("IPC Initiated Successfully", 1);
        
-       /* autoload (if on) will increment this if there are notes
-        * if not we may need to create a blank one */
+       /* loading will increment this if there are notes if not we may need to
+   * create a blank one */
        note_count = 0;
 
        if ((ecore_config_init("enotes")) == ECORE_CONFIG_ERR_FAIL) {
@@ -100,11 +100,9 @@
 
                dml("Efl Successfully Initiated", 1);
 
-               /* Autoloading */
-               if (main_config->autosave == 1) {
-      autoload();
-      update_autosave();
-    }
+    autoload();
+    /* create autosave timer */
+    update_autosave();
 
                if(remotecmd!=NULL)handle_ipc_message(remotecmd);
 
@@ -131,9 +129,7 @@
                /* Save Controlcentre Settings */
                set_cc_pos();
 
-               /* Autosaving */
-               if (main_config->autosave == 1)
-                       autosave();
+         autosave();
     if (autosave_timer)
       ecore_timer_del(autosave_timer);
 
===================================================================
RCS file: /cvsroot/enlightenment/misc/enotes/src/note.c,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -3 -r1.58 -r1.59
--- note.c      15 Mar 2006 01:25:28 -0000      1.58
+++ note.c      16 Mar 2006 00:05:56 -0000      1.59
@@ -13,6 +13,10 @@
 
 #include "note.h"
 
+static void note_close_dialog_close_cb(Ewl_Widget *w, void *ev, void *data);
+static void note_close_dialog_delete_cb(Ewl_Widget *w, void *ev, void *data);
+static void note_close_dialog_unload_cb(Ewl_Widget *w, void *ev, void *data);
+
 extern MainConfig *main_config;
 
 Evas_List      *gbl_notes = NULL;
@@ -76,27 +80,102 @@
 void
 remove_note(Evas_List * note)
 {
-       Note           *p = evas_list_data(note);
-
+  Ewl_Widget     *w;
+       Note           *p;
+ 
        dml("Closing a Note", 2);
 
+  p = evas_list_data(note);
+  if (p->timcomp)
+    {
        ecore_timer_del(p->timcomp);
        p->timcomp = NULL;
+    }
+
+  if (p->dialog)
+    return;
+
+  p->dialog = ewl_dialog_new();
+  ewl_window_title_set(EWL_WINDOW(p->dialog), "Enotes Delete");
+  ewl_window_name_set(EWL_WINDOW(p->dialog), "Enotes");
+  ewl_window_class_set(EWL_WINDOW(p->dialog), "Enotes");
+  ewl_callback_append(p->dialog, EWL_CALLBACK_DELETE_WINDOW, 
note_close_dialog_close_cb, p);
+
+  ewl_dialog_active_area_set(EWL_DIALOG(p->dialog), EWL_POSITION_TOP);
+  w = ewl_text_new();
+  ewl_text_text_set(EWL_TEXT(w), "Do you want to perminantly delete this note 
or just unload it?");
+  ewl_container_child_append(EWL_CONTAINER(p->dialog), w);
+  ewl_widget_show(w);
+
+  ewl_dialog_active_area_set(EWL_DIALOG(p->dialog), EWL_POSITION_BOTTOM);
+  w = ewl_button_new();
+  ewl_button_label_set(EWL_BUTTON(w), "Delete");
+  ewl_container_child_append(EWL_CONTAINER(p->dialog), w);
+  ewl_callback_append(w, EWL_CALLBACK_CLICKED, note_close_dialog_delete_cb, p);
+  ewl_widget_show(w);
+
+  w = ewl_button_new();
+  ewl_button_label_set(EWL_BUTTON(w), "Unload");
+  ewl_container_child_append(EWL_CONTAINER(p->dialog), w);
+  ewl_callback_append(w, EWL_CALLBACK_CLICKED, note_close_dialog_unload_cb, p);
+  ewl_widget_show(w);
+
+  w = ewl_button_new();
+  ewl_button_label_set(EWL_BUTTON(w), "Cancel");
+  ewl_container_child_append(EWL_CONTAINER(p->dialog), w);
+  ewl_callback_append(w, EWL_CALLBACK_CLICKED, note_close_dialog_close_cb, p);
+  ewl_widget_show(w);
+
+  ewl_dialog_active_area_set(EWL_DIALOG(p->dialog), EWL_POSITION_TOP);
+  ewl_widget_show(p->dialog);
+}
+
+static void
+note_close_dialog_close_cb(Ewl_Widget *w, void *ev, void *data) {
+  Note *p;
+
+  p = (Note *) data;
+  ewl_widget_destroy(p->dialog);
+  p->dialog = NULL;
+}
+
+static void
+note_close_dialog_delete_cb(Ewl_Widget *w, void *ev, void *data) {
+  Note *p;
+  char *path = malloc(PATH_MAX);
+
+  note_close_dialog_unload_cb(w, ev, data);
+
+  dml("Deleting Saved Note", 2);
+  sprintf(path, "%s/.e/apps/enotes/notes/%s", getenv("HOME"),
+      get_title_by_content(ewl_text_text_get(EWL_TEXT(p->content))));
+  unlink(path);
+
+  /* FIXME more intelligent things once we have sorted
+   * saveload */
+  ewl_saveload_revert(NULL, NULL, NULL);
+}
+
+static void
+note_close_dialog_unload_cb(Ewl_Widget *w, void *ev, void *data) {
+  Note *p;
+
+  note_close_dialog_close_cb(w, ev, data);
 
+  p = (Note *) data;
        edje_object_part_unswallow(p->edje, p->eo);
        ewl_widget_destroy(p->emb);
        evas_object_del(p->edje);
 
        ecore_evas_free(p->win);
        free(p);
-       gbl_notes = evas_list_remove_list(gbl_notes, note);
+       gbl_notes = evas_list_remove(gbl_notes, p);
 
   /* FIXME more intelligent things once we have sorted saveload */
   ewl_saveload_revert(NULL, NULL, NULL);
 
        /*  Check if it was the last note  */
-       if (evas_list_next(note) == NULL && evas_list_prev(note) == NULL &&
-           controlcentre == NULL)
+       if (evas_list_next(gbl_notes) == NULL && controlcentre == NULL)
                ecore_main_loop_quit();
 
        return;
@@ -315,6 +394,7 @@
                        free(title);
        }
 
+  p->dialog = NULL;
        return;
 }
 
@@ -559,7 +639,7 @@
 {
        Note           *p;
        char           *tmp;
-
+  
        p = (Note *) data;
        if (!p->timcomp)
                return (0);
@@ -686,28 +766,6 @@
 }
 
 /**
- * @param content: The content to search for.
- * @return: Returns the Evas_List of the note requested by "content".
- * @brief: Searches for and returns the note with the content being "content"
- */
-Evas_List      *
-get_note_by_content(char *content)
-{
-       Evas_List      *a;
-
-       a = get_cycle_begin();
-       if (!strcmp(get_content_by_note(a), content)) {
-               return (a);
-       }
-       while ((a = get_cycle_next_note(a)) != NULL) {
-               if (!strcmp(get_content_by_note(a), content)) {
-                       return (a);
-               }
-       }
-       return (NULL);
-}
-
-/**
  * @param note: The note to grab the title from.
  * @return: Returns the title of the supplied note.
  * @brief: Returns the title text of the supplied note.
===================================================================
RCS file: /cvsroot/enlightenment/misc/enotes/src/note.h,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -3 -r1.25 -r1.26
--- note.h      15 Mar 2006 01:25:28 -0000      1.25
+++ note.h      16 Mar 2006 00:05:56 -0000      1.26
@@ -79,6 +79,7 @@
        Ewl_Widget     *content;
        Ewl_Widget     *pane;
 
+  Ewl_Widget     *dialog;
        Menu           *menu;
 
        /* Comparison Strings and Timer */
@@ -140,7 +141,6 @@
 int             get_note_count();
 
 Evas_List      *get_note_by_title(char *title);
-Evas_List      *get_note_by_content(char *content);
 
 char           *get_title_by_note(Evas_List * note);
 char           *get_title_by_note_struct(Note * note);
===================================================================
RCS file: /cvsroot/enlightenment/misc/enotes/src/saveload.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -3 -r1.24 -r1.25
--- saveload.c  15 Mar 2006 01:25:28 -0000      1.24
+++ saveload.c  16 Mar 2006 00:05:56 -0000      1.25
@@ -200,6 +200,9 @@
 {
        dml("Refreshing the Saveload List", 2);
 
+  if (!saveload)
+    return;
+
        ewl_container_reset((Ewl_Container *) saveload->tree);
   ewl_widget_enable(saveload->savebtn);
   ewl_widget_state_set(saveload->savebtn, "enabled");
===================================================================
RCS file: /cvsroot/enlightenment/misc/enotes/src/storage.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -3 -r1.15 -r1.16
--- storage.c   25 Oct 2005 01:07:53 -0000      1.15
+++ storage.c   16 Mar 2006 00:05:56 -0000      1.16
@@ -47,32 +47,6 @@
 /* One Shot Functions. :-) */
 
 /**
- * @param p: The NoteStor containing the required information.
- * @brief: Appends a new autosave note according to whats in p.
- */
-void
-append_autosave_note_stor(NoteStor * p)
-{
-       char           *target = malloc(PATH_MAX);
-       char           *title;
-       char           *string = get_value_from_notestor(p);
-       FILE           *fp;
-
-       title = get_title_by_content(p->content);
-       sprintf(target, "%s/.e/apps/enotes/autosave/%s", getenv("HOME"), title);
-       free(title);
-
-       if ((fp = fopen(target, "w")) != NULL) {
-               fputs(string, fp);
-               fclose(fp);
-       }
-
-       free(string);
-       free(target);
-       return;
-}
-
-/**
  * @param p: The information required (about the note we're saving).
  * @brief: Appends a new note to the note storage according to the
  *         information stored in p.
@@ -90,17 +64,11 @@
        sprintf(target, "%s/.e/apps/enotes/notes/%s", getenv("HOME"), title);
        free(title);
 
-       if ((fp = fopen(target, "r")) == NULL) {
-               if ((fp = fopen(target, "w")) != NULL) {
-                       fputs(string, fp);
-                       fclose(fp);
-                       retval=1;
-               }
-       } else {
+       if ((fp = fopen(target, "w")) != NULL) {
+               fputs(string, fp);
                fclose(fp);
-               msgbox("Note Already Exists",
-                      "Unable to save note because a note with the same title 
exists.\nPlease delete this note first.");
-       }
+               retval=1;
+  }
 
        free(string);
        free(target);
@@ -174,17 +142,6 @@
                closedir(p);
        }
 
-       sprintf(f, "%s/.e/apps/enotes/autosave", getenv("HOME"));
-       if ((p = opendir(f)) == NULL) {
-               dml("Note Autosave Storage Location Doesn't Exist; Creating...",
-                   1);
-               if (mkdir(f, (mode_t) 0755) == -1)
-                       dml("Unable to Create Autosave Storage Location.  
Expect problems!", 1);
-       } else {
-               dml("Note Autosave Storage Location Found", 1);
-               closedir(p);
-       }
-
        free(f);
        return;
 }
@@ -193,7 +150,7 @@
 /* Autosave Functions */
 
 /**
- * @brief: Automatically loads all of the "autosave" notes.
+ * @brief: Automatically loads all of the notes.
  */
 void
 autoload(void)
@@ -204,7 +161,7 @@
        char           *targetf = malloc(PATH_MAX);
        struct stat     buf;
 
-       sprintf(target, "%s/.e/apps/enotes/autosave", getenv("HOME"));
+       sprintf(target, "%s/.e/apps/enotes/notes", getenv("HOME"));
        if ((dir = opendir(target)) != NULL) {
 
                while ((p = readdir(dir)) != NULL) {
@@ -222,7 +179,7 @@
 }
 
 /**
- * @brief: Automatically saves all open notes into the autosave storage.
+ * @brief: Automatically saves all open notes into the storage.
  */
 void
 autosave(void)
@@ -231,39 +188,9 @@
        Note           *note;
        Evas_List      *tmp = gbl_notes;
        NoteStor       *n;
-       char           *path = malloc(PATH_MAX);
-       char           *work = malloc(PATH_MAX);
-       DIR            *dir;
-       struct dirent  *d;
-       struct stat     buf;
 
        dml("Autosaving", 1);
 
-       sprintf(path, "%s/.e/apps/enotes/autosave", getenv("HOME"));
-
-       if ((dir = opendir(path)) != NULL) {
-               while ((d = readdir(dir)) != NULL) {
-                       sprintf(work, "%s/%s", path, d->d_name);
-                       stat(work, &buf);
-                       if (S_ISREG(buf.st_mode)) {
-                               unlink(work);
-                       }
-               }
-               closedir(dir);
-       }
-
-       if (rmdir(path) != -1) {
-               if (mkdir(path, 0755) != -1) {
-                       dml("Successfully Cleaned the Autosaves", 1);
-               } else {
-                       dml("Error Recreating Autosave Directory", 1);
-               }
-       } else {
-               dml("Error Removing the Autosave Location", 1);
-       }
-       free(path);
-       free(work);
-
        while (tmp != NULL) {
                note = evas_list_data(tmp);
                ecore_evas_geometry_get(note->win, &x, &y, &w, &h);
@@ -273,7 +200,7 @@
                n->x = x;
                n->y = y;
                n->content = strdup(get_content_by_note(tmp));
-               append_autosave_note_stor(n);
+               append_note_stor(n);
                free_note_stor(n);
                tmp = evas_list_next(tmp);
        }
===================================================================
RCS file: /cvsroot/enlightenment/misc/enotes/src/storage.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -3 -r1.9 -r1.10
--- storage.h   10 Sep 2005 21:06:14 -0000      1.9
+++ storage.h   16 Mar 2006 00:05:56 -0000      1.10
@@ -48,7 +48,6 @@
 
 /* One Shot Functions. :-) */
 int             append_note_stor(NoteStor * p);
-void            append_autosave_note_stor(NoteStor * p);
 void            remove_note_stor(NoteStor * p);
 void            process_note_storage_locations();
 
@@ -59,9 +58,6 @@
 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);
 




-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to