This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository enlightenment.

View the commit online.

commit 8739375762e7d2d50d0e725a6f74724a94330332
Author: Carsten Haitzler <[email protected]>
AuthorDate: Wed Jan 7 17:36:02 2026 +0000

    clipboard - move history into clipboard cfg file..
---
 src/bin/e_config_data.h              |   1 +
 src/modules/clipboard/e_mod_config.c | 128 +++++++++++---
 src/modules/clipboard/e_mod_main.c   | 247 ++++++++-------------------
 src/modules/clipboard/e_mod_main.h   |  66 ++++----
 src/modules/clipboard/history.c      | 313 -----------------------------------
 src/modules/clipboard/meson.build    |   1 -
 6 files changed, 206 insertions(+), 550 deletions(-)

diff --git a/src/bin/e_config_data.h b/src/bin/e_config_data.h
index 148c69322..49983a566 100644
--- a/src/bin/e_config_data.h
+++ b/src/bin/e_config_data.h
@@ -48,6 +48,7 @@
 #define UINT   EET_T_UINT
 #define ULL    EET_T_ULONG_LONG
 #define STR    EET_T_STRING
+#define STRI   EET_T_INLINED_STRING
 
 typedef Eet_Data_Descriptor                 E_Config_DD;
 
diff --git a/src/modules/clipboard/e_mod_config.c b/src/modules/clipboard/e_mod_config.c
index 16bcf2d2b..939accaf5 100644
--- a/src/modules/clipboard/e_mod_config.c
+++ b/src/modules/clipboard/e_mod_config.c
@@ -1,5 +1,7 @@
 #include "e_mod_main.h"
 
+extern Mod_Inst     *clip_inst; // in e_mod_main.c
+
 struct _E_Config_Dialog_Data
 {
   E_Config_Dialog *cfd;
@@ -21,13 +23,23 @@ struct _E_Config_Dialog_Data
   int    trim_nl;        // should we trim new lines from selection
 };
 
+/////////////////////////////////////////////////////////////////////////////
+//
 static int           _basic_apply_data(E_Config_Dialog *cfd EINA_UNUSED, E_Config_Dialog_Data *cfdata);
 static void         *_create_data(E_Config_Dialog *cfd EINA_UNUSED);
 static int           _basic_check_changed(E_Config_Dialog *cfd EINA_UNUSED, E_Config_Dialog_Data *cfdata);
 static void          _fill_data(E_Config_Dialog_Data *cfdata);
-void                 _free_data(E_Config_Dialog *cfd EINA_UNUSED, E_Config_Dialog_Data *cfdata);
+static void          _free_data(E_Config_Dialog *cfd EINA_UNUSED, E_Config_Dialog_Data *cfdata);
 static Evas_Object  *_basic_create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata);
-extern Mod_Inst     *clip_inst; // in e_mod_main.c
+
+/////////////////////////////////////////////////////////////////////////////
+
+static E_Config_DD *conf_edd = NULL;
+static E_Config_DD *conf_item_edd = NULL;
+
+Config *clip_cfg = NULL;
+
+/////////////////////////////////////////////////////////////////////////////
 
 static void *
 _create_data(E_Config_Dialog *cfd EINA_UNUSED)
@@ -37,7 +49,7 @@ _create_data(E_Config_Dialog *cfd EINA_UNUSED)
   return cfdata;
 }
 
-void
+static void
 _free_data(E_Config_Dialog *cfd EINA_UNUSED, E_Config_Dialog_Data *cfdata)
 {
   EINA_SAFETY_ON_NULL_RETURN(clip_cfg);
@@ -73,7 +85,7 @@ _basic_apply_data(E_Config_Dialog *cfd EINA_UNUSED, E_Config_Dialog_Data *cfdata
 
   // do we need to Truncate our history list?
   if (clip_cfg->hist_items != (unsigned int)cfdata->hist_items)
-    truncate_history(cfdata-> hist_items);
+    config_truncate_history(cfdata->hist_items);
 
   clip_cfg->hist_items     = cfdata->hist_items;
   clip_cfg->confirm_clear  = cfdata->confirm_clear;
@@ -200,25 +212,54 @@ _basic_check_changed(E_Config_Dialog *cfd EINA_UNUSED, E_Config_Dialog_Data *cfd
   return 0;
 }
 
-Eet_Error
-truncate_history(const unsigned int n)
-{
-  Eet_Error err = EET_ERROR_NONE;
+/////////////////////////////////////////////////////////////////////////////
 
-  EINA_SAFETY_ON_NULL_RETURN_VAL(clip_inst, EET_ERROR_BAD_OBJECT);
-  if (clip_inst->items)
-    {
-      if (eina_list_count(clip_inst->items) > n)
-        {
-          Eina_List *discard;
-          Eina_List *last = eina_list_nth_list(clip_inst->items, n - 1);
-          clip_inst->items = eina_list_split_list(clip_inst->items, last, &discard);
-          if (discard) E_FREE_LIST(discard, free_clip_data);
-          err = clip_save(clip_inst->items);
-        }
+Eina_Bool
+config_init(void)
+{
+  conf_item_edd = E_CONFIG_DD_NEW("Config_Item", Config_Item);
+  if (!conf_item_edd) return EINA_FALSE;
+#undef T
+#undef D
+#define T Config_Item
+#define D conf_item_edd
+  E_CONFIG_VAL(D, T, str, STRI);
+  conf_edd = E_CONFIG_DD_NEW("Config", Config);
+  if (!conf_edd) return EINA_FALSE;
+#undef T
+#undef D
+#define T Config
+#define D conf_edd
+  E_CONFIG_VAL(D, T, version, UINT);
+  E_CONFIG_LIST(D, T, items, conf_item_edd);
+  E_CONFIG_VAL(D, T, label_length, UINT);
+  E_CONFIG_VAL(D, T, hist_items, INT);
+  E_CONFIG_VAL(D, T, clip_copy, INT);
+  E_CONFIG_VAL(D, T, clip_select, INT);
+  E_CONFIG_VAL(D, T, persistence, INT);
+  E_CONFIG_VAL(D, T, hist_reverse, INT);
+  E_CONFIG_VAL(D, T, confirm_clear, INT);
+  E_CONFIG_VAL(D, T, ignore_ws, INT);
+  E_CONFIG_VAL(D, T, ignore_ws_copy, INT);
+  E_CONFIG_VAL(D, T, trim_ws, INT);
+  E_CONFIG_VAL(D, T, trim_nl, INT);
+
+  clip_cfg = e_config_domain_load("module.clipboard", conf_edd);
+  if (clip_cfg)
+    { // check config version
+      if (!e_util_module_config_check("Clipboard", clip_cfg->version,
+                                      MOD_CONFIG_FILE_VERSION))
+        config_free();
     }
-  else err = EET_ERROR_EMPTY;
-  return err;
+  return EINA_TRUE;
+}
+
+void
+config_shutdown(void)
+{
+  config_free();
+  E_CONFIG_DD_FREE(conf_edd);
+  E_CONFIG_DD_FREE(conf_item_edd);
 }
 
 Eina_Bool
@@ -260,3 +301,48 @@ conifg_new_limit(void)
     }
   return EINA_TRUE;
 }
+
+void
+config_free(void)
+{
+  Config_Item *ci;
+
+  if (!clip_cfg) return;
+  EINA_LIST_FREE(clip_cfg->items, ci)
+    {
+      eina_stringshare_del(ci->name);
+      eina_stringshare_del(ci->str);
+      free(ci);
+    }
+  clip_cfg->module = NULL;
+  E_FREE(clip_cfg);
+}
+
+void
+config_save(void)
+{
+  e_config_domain_save("module.clipboard", conf_edd, clip_cfg);
+}
+
+void
+config_truncate_history(unsigned int max)
+{
+  EINA_SAFETY_ON_NULL_RETURN(clip_cfg);
+  if ((clip_cfg->items) && (eina_list_count(clip_cfg->items) > max))
+    {
+      Eina_List *discard = NULL;
+      Eina_List *last = eina_list_nth_list(clip_cfg->items, max - 1);
+      clip_cfg->items = eina_list_split_list(clip_cfg->items, last, &discard);
+      if (discard) E_FREE_LIST(discard, config_clip_data_free);
+      e_config_save_queue();
+    }
+}
+
+void
+config_clip_data_free(Config_Item *cd)
+{
+  EINA_SAFETY_ON_NULL_RETURN(cd);
+  free(cd->name);
+  eina_stringshare_del(cd->str);
+  free(cd);
+}
diff --git a/src/modules/clipboard/e_mod_main.c b/src/modules/clipboard/e_mod_main.c
index 204e641fb..552b3967c 100644
--- a/src/modules/clipboard/e_mod_main.c
+++ b/src/modules/clipboard/e_mod_main.c
@@ -29,13 +29,11 @@ static const E_Gadcon_Client_Class _gadcon_class =
 E_API E_Module_Api e_modapi = { E_MODULE_API_VERSION, "Clipboard"};
 
 // actual module specifics
-Config *clip_cfg = NULL;
 Mod_Inst *clip_inst = NULL; // Need by e_mod_config.c
 
-static E_Config_DD *conf_edd = NULL;
-static E_Config_DD *conf_item_edd = NULL;
 static E_Action *act = NULL;
 static Ecore_Timer *delay_sel_timer = NULL;
+static double _mod_time_start = 0.0;
 
 // first some call backs
 static void       _clipboard_cb_paste_item(void *d1, void *d2);
@@ -51,29 +49,12 @@ static void       _clipboard_config_show(void *d1, void *d2 EINA_UNUSED);
 static void       _clipboard_popup_free(Instance *inst);
 
 // and then some auxillary functions
-static void       _clip_config_free(void);
 static void       _clip_inst_free(Instance *inst);
-static void       _clip_add_item(Clip_Data *clip_data);
+static void       _clip_add_item(Config_Item *cd);
 static void       _clipboard_popup_new(Instance *inst);
 static void       _clear_history(void);
-static Eina_List *_item_in_history(Clip_Data *cd);
-static int        _clip_compare(Clip_Data *cd, char *text);
-
-// This is called when we need to cleanup the actual configuration,
-// for example when our configuration is too old
-static void
-_clip_config_free(void)
-{
-  Config_Item *ci;
-
-  EINA_LIST_FREE(clip_cfg->items, ci)
-    {
-      eina_stringshare_del(ci->id);
-      free(ci);
-    }
-  clip_cfg->module = NULL;
-  E_FREE(clip_cfg);
-}
+static Eina_List *_item_in_history(Config_Item *cd);
+static int        _clip_compare(Config_Item *cd, char *text);
 
 static void
 _clipboard_cb_mouse_down(void *data,
@@ -150,7 +131,7 @@ _gc_orient(E_Gadcon_Client *gcc, E_Gadcon_Orient orient EINA_UNUSED)
  *  do not confuse this with E_Module_Api
  */
 static const char *
-_gc_label (const E_Gadcon_Client_Class *client_class EINA_UNUSED)
+_gc_label(const E_Gadcon_Client_Class *client_class EINA_UNUSED)
 {
   return "Clipboard";
 }
@@ -172,7 +153,7 @@ _gc_icon(const E_Gadcon_Client_Class *client_class EINA_UNUSED, Evas * evas)
  * modules
  */
 static const char *
-_gc_id_new (const E_Gadcon_Client_Class *client_class EINA_UNUSED)
+_gc_id_new(const E_Gadcon_Client_Class *client_class EINA_UNUSED)
 {
   return _gadcon_class.name;
 }
@@ -192,7 +173,7 @@ _cb_context_show(void *data,
   EINA_SAFETY_ON_NULL_RETURN(inst);
   EINA_SAFETY_ON_NULL_RETURN(event);
   // ignore all mouse events but left clicks
-  IF_TRUE_RETURN(event->button != 3);
+  if (event->button != 3) return;
 
   // create popup menu
   m = e_menu_new();
@@ -247,38 +228,43 @@ _clipboard_popup_new(Instance *inst)
 
   inst->table = e_widget_table_add(e_win_evas_win_get(evas), 0);
 
-  if (clip_inst->items)
+  if (clip_cfg->items)
     {
       Eina_List *it;
-      Clip_Data *clip;
+      Config_Item *cd;
 
-      // Flag to see if Label len changed
+      // flag to see if label len changed
       Eina_Bool label_length_changed = clip_cfg->label_length_changed;
       clip_cfg->label_length_changed = EINA_FALSE;
 
       // revert list if selected
-      if (clip_cfg->hist_reverse) clip_inst->items=eina_list_reverse(clip_inst->items);
+      if (clip_cfg->hist_reverse) clip_cfg->items=eina_list_reverse(clip_cfg->items);
 
       // show list in history menu
-      EINA_LIST_FOREACH(clip_inst->items, it, clip)
+      EINA_LIST_FOREACH(clip_cfg->items, it, cd)
         {
           if (label_length_changed)
             {
-              free(clip->name);
-              set_clip_name(&clip->name, clip->content,
+              free(cd->name);
+              cd->name = NULL;
+            }
+          if (!cd->name)
+            {
+              eina_stringshare_del(cd->name);
+              set_clip_name(&cd->name, cd->str,
                             clip_cfg->ignore_ws, clip_cfg->label_length);
             }
           o = e_widget_button_add(evas,
-                                  clip->name,
+                                  cd->name,
                                   NULL,
                                   _clipboard_cb_paste_item,
-                                  clip->content,
+                                  cd->str,
                                   inst);
           e_widget_table_object_align_append(inst->table, o, 0, row, 2, 1, 1, 0, 1, 0, 0, 0.5);
           row++;
         }
       // revert list back if selected
-      if (clip_cfg->hist_reverse) clip_inst->items=eina_list_reverse(clip_inst->items);
+      if (clip_cfg->hist_reverse) clip_cfg->items=eina_list_reverse(clip_cfg->items);
     }
   else
     {
@@ -288,7 +274,7 @@ _clipboard_popup_new(Instance *inst)
     }
 
   o = e_widget_button_add(evas, _("Clear"), "edit-clear", _cb_clear_history, inst, NULL);
-  e_widget_disabled_set(o, !clip_inst->items);
+  e_widget_disabled_set(o, !clip_cfg->items);
   e_widget_table_object_align_append(inst->table, o, 0, row, 1, 1, 0, 0, 0, 0, 0.5, 0.5);
 
   o = e_widget_button_add(evas, _("Settings"), "preferences-system", _clipboard_config_show, inst, NULL);
@@ -305,73 +291,62 @@ _clipboard_popup_new(Instance *inst)
 }
 
 static void
-_clip_add_item(Clip_Data *cd)
+_clip_add_item(Config_Item *cd)
 {
   Eina_List *it;
 
   EINA_SAFETY_ON_NULL_RETURN(cd);
-  if (*cd->content == 0)
-    {
-      ERR("Warning Clip content is Empty!");
-      return;
-    }
+  if (cd->str[0] == 0) return;
   if ((it = _item_in_history(cd)))
     { // move to top of list
-      clip_inst->items = eina_list_promote_list(clip_inst->items, it);
+      clip_cfg->items = eina_list_promote_list(clip_cfg->items, it);
     }
   else
     { // add item to the list
-      if (eina_list_count(clip_inst->items) < clip_cfg->hist_items)
-        {
-          clip_inst->items = eina_list_prepend(clip_inst->items, cd);
+      if (eina_list_count(clip_cfg->items) < clip_cfg->hist_items)
+        { // add to start of list
+          clip_cfg->items = eina_list_prepend(clip_cfg->items, cd);
         }
       else
         { // remove last item from the list
-          Eina_List *l_last = eina_list_last(clip_inst->items);
+          Eina_List *l_last = eina_list_last(clip_cfg->items);
 
           if (l_last)
             {
-              free_clip_data(l_last->data);
-              clip_inst->items = eina_list_remove_list(clip_inst->items, l_last);
+              config_clip_data_free(l_last->data);
+              clip_cfg->items = eina_list_remove_list(clip_cfg->items, l_last);
             }
           //  add clipboard data stored in cd to the list as a first item
-          clip_inst->items = eina_list_prepend(clip_inst->items, cd);
+          clip_cfg->items = eina_list_prepend(clip_cfg->items, cd);
         }
     }
   // saving list to the file
-  clip_save(clip_inst->items);
+  e_config_save_queue();
 }
 
 static Eina_List *
-_item_in_history(Clip_Data *cd)
+_item_in_history(Config_Item *cd)
 {
   EINA_SAFETY_ON_NULL_RETURN_VAL(cd, NULL);
-  if (clip_inst->items)
-    return eina_list_search_unsorted_list(clip_inst->items, (Eina_Compare_Cb) _clip_compare, cd->content);
+  if (clip_cfg->items)
+    return eina_list_search_unsorted_list(clip_cfg->items, (Eina_Compare_Cb) _clip_compare, cd->str);
   else
     return NULL;
 }
 
 static int
-_clip_compare(Clip_Data *cd, char *text)
+_clip_compare(Config_Item *cd, char *text)
 {
-  return strcmp(cd->content, text);
+  return strcmp(cd->str, text);
 }
 
 static void
 _clear_history(void)
 {
-  EINA_SAFETY_ON_NULL_RETURN(clip_inst);
-  if (clip_inst->items) E_FREE_LIST(clip_inst->items, free_clip_data);
+  EINA_SAFETY_ON_NULL_RETURN(clip_cfg);
+  if (clip_cfg->items) E_FREE_LIST(clip_cfg->items, config_clip_data_free);
   elm_object_cnp_selection_clear(e_comp->evas, ELM_SEL_TYPE_CLIPBOARD);
-  clip_save(clip_inst->items);
-}
-
-Eet_Error
-clip_save(Eina_List *items)
-{
-  if (clip_cfg->persistence) return save_history(items);
-  else return EET_ERROR_NONE;
+  e_config_save_queue();
 }
 
 static void
@@ -439,19 +414,10 @@ _cb_action_switch(E_Object *o EINA_UNUSED, const char *params)
   if (!strcmp(params, "float")) _clipboard_popup_new(inst);
   else if (!strcmp(params, "settings")) _cb_config_show(inst, NULL, NULL);
   // Only call clear dialog if there is something to clear
-  else if ((!strcmp(params, "clear")) && (clip_inst->items))
+  else if ((!strcmp(params, "clear")) && (clip_cfg->items))
     _cb_clear_history(NULL, NULL);
 }
 
-void
-free_clip_data(Clip_Data *clip)
-{
-  EINA_SAFETY_ON_NULL_RETURN(clip);
-  free(clip->name);
-  free(clip->content);
-  free(clip);
-}
-
 static void
 _clip_inst_free(Instance *inst)
 {
@@ -466,37 +432,34 @@ _cliboard_cb_paste(void *data,
                    Evas_Object *obj EINA_UNUSED,
                    Elm_Selection_Data *event)
 {
-  Clip_Data *cd = NULL;
+  Config_Item *cd = NULL;
   Instance *instance = data;
   char *paste = NULL;
   char *last = "";
 
   EINA_SAFETY_ON_NULL_RETURN_VAL(instance, EINA_TRUE);
 
-  if (clip_inst->items)
-    last =  ((Clip_Data *)eina_list_data_get(clip_inst->items))->content;
+  if (clip_cfg->items)
+    last = ((Config_Item *)eina_list_data_get(clip_cfg->items))->str;
   if (event) paste = event->data;
 
   if (!paste) return EINA_TRUE;
 
-  // some debug here for now
-  printf("CP: [%6.3f] [%s]\n", ecore_time_get(), paste);
-
   if (!!strcmp(last, paste))
     {
       if (strlen(paste) == 0) return ECORE_CALLBACK_DONE;
       if (clip_cfg->ignore_ws_copy && is_empty(paste)) return ECORE_CALLBACK_DONE;
-      cd = E_NEW(Clip_Data, 1);
+      cd = E_NEW(Config_Item, 1);
       if (cd)
         {
-          if (!set_clip_content(&cd->content, paste,
+          if (!set_clip_content(&cd->str, paste,
                                 CLIP_TRIM_MODE(clip_cfg)))
             { // try to continue
               CRI("Something bad happened !!");
               E_FREE(cd);
               goto error;
             }
-          if (!set_clip_name(&cd->name, cd->content,
+          if (!set_clip_name(&cd->name, cd->str,
                              clip_cfg->ignore_ws, clip_cfg->label_length))
             { // try to continue
               CRI("Something bad happened !!");
@@ -529,6 +492,7 @@ _cb_sel_change_delay(void *data)
   Mod_Inst *mod_inst = data;
   Eina_Bool fetch = EINA_FALSE;
 
+  printf("CP: delyay from sel change... get sel!\n");
   delay_sel_timer = NULL;
   if ((mod_inst->sel_type == ELM_SEL_TYPE_PRIMARY) &&
       (clip_cfg->clip_select))
@@ -552,6 +516,8 @@ _clipboard_cb_event_selection(void *data,
   Mod_Inst *mod_inst = data;
   Elm_Cnp_Event_Selection_Changed *ev = event;
 
+  // skip sel change event early on
+  if ((ecore_time_get() - _mod_time_start) < 1.0) return EINA_TRUE;
   if (delay_sel_timer)
     {
       ecore_timer_del(delay_sel_timer);
@@ -585,49 +551,10 @@ _cb_config_show(void *data,
 E_API void *
 e_modapi_init(E_Module *m)
 {
-  Eet_Error hist_err;
-
-  // display this module's config info in the main config panel
-  // under preferences catogory
-  e_configure_registry_item_add("preferences/clipboard", 10,
-            "Clipboard Settings", NULL,
-            "edit-paste", config_clipboard_module);
-
-  conf_item_edd = E_CONFIG_DD_NEW("clip_cfg_Item", Config_Item);
-#undef T
-#undef D
-#define T Config_Item
-#define D conf_item_edd
-  E_CONFIG_VAL(D, T, id, STR);
-  conf_edd = E_CONFIG_DD_NEW("clip_cfg", Config);
-#undef T
-#undef D
-#define T Config
-#define D conf_edd
-  E_CONFIG_LIST(D, T, items, conf_item_edd);
-  E_CONFIG_VAL(D, T, version, UINT);
-  E_CONFIG_VAL(D, T, label_length, UINT);
-  E_CONFIG_VAL(D, T, hist_items, INT);
-  E_CONFIG_VAL(D, T, clip_copy, INT);
-  E_CONFIG_VAL(D, T, clip_select, INT);
-  E_CONFIG_VAL(D, T, persistence, INT);
-  E_CONFIG_VAL(D, T, hist_reverse, INT);
-  E_CONFIG_VAL(D, T, confirm_clear, INT);
-  E_CONFIG_VAL(D, T, ignore_ws, INT);
-  E_CONFIG_VAL(D, T, ignore_ws_copy, INT);
-  E_CONFIG_VAL(D, T, trim_ws, INT);
-  E_CONFIG_VAL(D, T, trim_nl, INT);
-
-  // Tell E to find any existing module data. First run ?
-  clip_cfg = e_config_domain_load("module.clipboard", conf_edd);
-
-  if (clip_cfg)
-    { // Check config version
-      if (!e_util_module_config_check("Clipboard", clip_cfg->version, MOD_CONFIG_FILE_VERSION))
-        _clip_config_free();
-    }
-
+  if (!config_init()) return NULL;
   if (!conifg_new_limit()) return NULL;
+  config_truncate_history(clip_cfg->hist_items);
+
   clip_cfg->module = m;
 
   act = e_action_add("clipboard"); // module key binding actions
@@ -638,56 +565,35 @@ e_modapi_init(E_Module *m)
       e_action_predef_name_set(_("Clipboard"), ACT_CONFIG, "clipboard", "settings", NULL, 0);
       e_action_predef_name_set(_("Clipboard"), ACT_CLEAR,  "clipboard", "clear",    NULL, 0);
     }
-
+  // display this module's config info in the main config panel
+  // under preferences catogory
+  e_configure_registry_item_add("preferences/clipboard", 10,
+                                "Clipboard Settings", NULL,
+                                "edit-paste", config_clipboard_module);
   // create a global clip_inst for our module
   // complete with a hidden window for event notification purposes
   clip_inst = E_NEW(Mod_Inst, 1);
-
-  // read History file and set clipboard
-  hist_err = read_history(&(clip_inst->items), clip_cfg->ignore_ws, clip_cfg->label_length);
-
-  if ((hist_err == EET_ERROR_NONE) &&
-      eina_list_count(clip_inst->items))
-    _clipboard_cb_paste_item(eina_list_data_get(clip_inst->items), NULL);
-  else
-    // something must be wrong with history file
-    // so we create a new one
-    clip_save(clip_inst->items);
-  // make sure the history read has no more items than allowed
-  // by clipboard config file. This should never happen without user
-  // intervention of some kind.
-  if (clip_inst->items)
-    {
-      if (eina_list_count(clip_inst->items) > clip_cfg->hist_items)
-        {
-          // FIXME: Do we need to warn user in case this is backed up data
-          // being restored ?
-          WRN("History File truncation!");
-          truncate_history(clip_cfg->hist_items);
-        }
-    }
-
+  if (!clip_inst) return NULL;
   clip_inst->ewin = elm_win_add(NULL, NULL, ELM_WIN_BASIC);
-
   // now add some callbacks to handle clipboard events
   // re-add to history
   elm_cnp_selection_loss_callback_set(e_comp->evas,
                                       ELM_SEL_TYPE_CLIPBOARD,
                                       _clipboard_cb_elm_selection_lost,
                                       clip_inst);
-  E_LIST_HANDLER_APPEND(clip_inst->handle,
+  E_LIST_HANDLER_APPEND(clip_inst->handles,
                         ECORE_EVENT_MOUSE_BUTTON_UP,
                         _clipboard_cb_event_selection,
                         clip_inst);
   // Does not seem to fire?
-  E_LIST_HANDLER_APPEND(clip_inst->handle,
+  E_LIST_HANDLER_APPEND(clip_inst->handles,
                         ELM_CNP_EVENT_SELECTION_CHANGED,
                         _clipboard_cb_event_selection,
                         clip_inst);
-
   // tell any gadget containers (shelves, etc) that we provide a module
   e_gadcon_provider_register(&_gadcon_class);
   // give e the module
+  _mod_time_start = ecore_time_get(); // rcored start time to skip early events
   return m;
 }
 
@@ -698,8 +604,6 @@ e_modapi_init(E_Module *m)
 E_API int
 e_modapi_shutdown(E_Module *m EINA_UNUSED)
 {
-  Config_Item *ci;
-
   e_gadcon_provider_unregister(&_gadcon_class);
   if (delay_sel_timer) ecore_timer_del(delay_sel_timer);
   delay_sel_timer = NULL;
@@ -707,10 +611,9 @@ e_modapi_shutdown(E_Module *m EINA_UNUSED)
   // and i usually avoid gotos but here I feel their use is harmless */
   EINA_SAFETY_ON_NULL_GOTO(clip_inst, noclip);
 
-  // Kill our clip_inst and cleanup
-  E_FREE_LIST(clip_inst->handle, ecore_event_handler_del);
-  clip_inst->handle = NULL;
-  E_FREE_LIST(clip_inst->items, free_clip_data);
+  // kill our clip_inst and cleanup
+  E_FREE_LIST(clip_inst->handles, ecore_event_handler_del);
+  clip_inst->handles = NULL;
   E_FREE(clip_inst);
 
 noclip:
@@ -723,15 +626,7 @@ noclip:
   if (clip_cfg->config_dialog) e_object_del(E_OBJECT(clip_cfg->config_dialog));
   E_FREE(clip_cfg->config_dialog);
 
-  // cleanup our item list
-  EINA_LIST_FREE(clip_cfg->items, ci)
-    {
-      eina_stringshare_del(ci->id);
-      free(ci);
-    }
-  clip_cfg->module = NULL;
-  // keep the planet green
-  E_FREE(clip_cfg);
+  config_shutdown();
 
 noconfig:
   // unregister the config dialog from the main panel
@@ -747,10 +642,6 @@ noconfig:
       act = NULL;
     }
 
-  // clean EET
-  E_CONFIG_DD_FREE(conf_edd);
-  E_CONFIG_DD_FREE(conf_item_edd);
-  INF("Shutting down Clipboard Module");
   // tell e the module is now unloaded. Gets removed from shelves, etc.
   e_gadcon_provider_unregister(&_gadcon_class);
   return 1;
@@ -763,6 +654,6 @@ noconfig:
 E_API int
 e_modapi_save(E_Module *m EINA_UNUSED)
 {
-  e_config_domain_save("module.clipboard", conf_edd, clip_cfg);
+  config_save();
   return 1;
 }
diff --git a/src/modules/clipboard/e_mod_main.h b/src/modules/clipboard/e_mod_main.h
index 1ae5c0894..6299c25a2 100644
--- a/src/modules/clipboard/e_mod_main.h
+++ b/src/modules/clipboard/e_mod_main.h
@@ -38,40 +38,26 @@ EAPI int   e_modapi_save     (E_Module *m EINA_UNUSED);
 #define MOD_CONFIG_FILE_GENERATION 4
 #define MOD_CONFIG_FILE_VERSION    ((MOD_CONFIG_FILE_EPOCH * 1000000) + MOD_CONFIG_FILE_GENERATION)
 
-/* Stuff for convenience to compress code */
-#define IF_TRUE_RETURN(exp) \
-   do {                     \
-     if (exp) return;       \
-   } while(0)
-
-typedef struct _Clip_Data Clip_Data;
-typedef struct _Instance Instance;
-typedef struct _Mod_Inst Mod_Inst;
-typedef struct _Config Config;
+typedef struct _Instance    Instance;
+typedef struct _Mod_Inst    Mod_Inst;
+typedef struct _Config      Config;
 typedef struct _Config_Item Config_Item;
 
-struct _Clip_Data
-{ // structure used for storing clipboard data in
-  char *name;
-  char *content;
-};
-
 struct _Instance
 { // gadget instances
   E_Gadcon_Client *gcc;
-  Evas_Object *o_button;
-  Evas_Object *table;
-  E_Gadcon_Popup *popup;
+  Evas_Object     *o_button;
+  Evas_Object     *table;
+  E_Gadcon_Popup  *popup;
 };
 
 struct _Mod_Inst
 { // sructure to store a global module instance in
   // complete with a hidden window for event notification purposes
-  Evas_Object *ewin; // window to send clipboard events to
-  Eina_List *handle; // for handling clipboard events
-  Eina_List *items; // clipboard history
-  Elm_Sel_Type sel_type; // type of sel we last saw change
-  Eina_List *instances; // all instances of gadgets
+  Evas_Object  *ewin; // window to send clipboard events to
+  Eina_List    *handles; // for handling clipboard events
+  Elm_Sel_Type  sel_type; // type of sel we last saw change
+  Eina_List    *instances; // all instances of gadgets
 };
 
 #define LABEL_MIN  5
@@ -80,17 +66,19 @@ struct _Mod_Inst
 #define HIST_MIN   5
 #define HIST_MAX   100
 
-/* We create a structure config for our module, and also a config structure
- * for every item element (you can have multiple gadgets for the same module) */
+// We create a structure config for our module, and also a config structure
+// for every item element (you can have multiple gadgets for the same module)
 struct _Config
 {
-  Eina_List *items;
+  // runtime stuff we don't store
   E_Module *module;
   E_Config_Dialog *config_dialog;
-  const char *log_name;
+
   Eina_Bool label_length_changed; // Flag indicating a need to update all clip labels as configfuration changed.
 
-  int version;          /* Configuration version                           */
+  // stored data
+  int version;          /* Configuration version */
+  Eina_List *items;     /* list of stored selection texts */
   unsigned int hist_items;   /* Number of history items to store                */
   unsigned int label_length; /* Number of characters of item to display         */
   // these are booleans really...
@@ -107,20 +95,24 @@ struct _Config
 
 struct _Config_Item
 {
-  const char *id;
+  char *name; // cut down label/name for gui
+  char *str; // stored string
 };
 
-extern Config *clip_cfg;
-
-Eet_Error        clip_save(Eina_List *items);
-void             free_clip_data(Clip_Data *clip);
 E_Config_Dialog *config_clipboard_module(Evas_Object *parent, const char *params EINA_UNUSED);
-Eet_Error        truncate_history(const unsigned int n);
-Eet_Error        read_history(Eina_List **items, unsigned int ignore_ws, unsigned int label_length);
-Eet_Error        save_history(Eina_List *items);
+
 Eina_Bool        set_clip_content(char **content, char *text, int mode);
 Eina_Bool        set_clip_name(char **name, char *text, int mode, int n);
 Eina_Bool        is_empty(const char *str);
+
+extern           Config *clip_cfg;
+
+Eina_Bool        config_init(void);
+void             config_shutdown(void);
 Eina_Bool        conifg_new_limit(void);
+void             config_free(void);
+void             config_save(void);
+void             config_truncate_history(unsigned int max);
+void             config_clip_data_free(Config_Item *cd);
 
 #endif
diff --git a/src/modules/clipboard/history.c b/src/modules/clipboard/history.c
deleted file mode 100644
index 3087ae430..000000000
--- a/src/modules/clipboard/history.c
+++ /dev/null
@@ -1,313 +0,0 @@
-#include "e_mod_main.h"
-
-#define CLIPBOARD_MOD_NAME "clipboard"
-#define DATA_DIR           CLIPBOARD_MOD_NAME
-#define HISTORY_NAME       "history"
-#define HISTORY_VERSION    1 /* must be < 9  */
-
-/* convenience macros to compress code */
-#define CALLOC_DIGIT_STR(str, n)                     \
-do {                                                 \
-  long _digits_ = 1;                                 \
-  long _tempn_ = n + 9;                              \
-  while (_tempn_ /= 10) _digits_++;                  \
-  str = calloc(_digits_ + 1, sizeof(char));          \
-  if (!str) {                                        \
-    /* This is bad, leave it to calling function */  \
-    CRI("ERROR: Memory allocation Failed!!");        \
-    eet_close(history_file);                         \
-    return EET_ERROR_OUT_OF_MEMORY;                  \
-   }                                                 \
-   snprintf(str, _digits_ + 1, "%d", 0);             \
- } while(0)
-
-#define PATH_MAX_ERR                                              \
-do {                                                              \
-  ERR("PATH_MAX exceeded. Need Len %d, PATH_MAX %d", len, PATH_MAX); \
-  memset(path,0,PATH_MAX);                                        \
-  success = EINA_FALSE;                                           \
- } while(0)                                                       \
-
-static Eina_Bool _mkpath_if_not_exists(const char *path);
-static Eina_Bool _set_data_path(char *path);
-static Eina_Bool _set_history_path(char *path);
-
-/**
- * @brief Creates path if non-existant
- *
- * @param path char array to create.
- * @return EINA_TRUE on success EINA_FALSE otherwise
- *
- */
-static Eina_Bool
-_mkpath_if_not_exists(const char *path)
-{
-  EINA_SAFETY_ON_NULL_RETURN_VAL(path, EINA_FALSE);
-  Eina_Bool success = EINA_TRUE;
-
-  if (!ecore_file_exists(path)) return ecore_file_mkdir(path);
-  return success;
-}
-
-/**
- * @brief Sets the XDG_DATA_HOME location for saving clipboard history data.
- *
- * @param path char array to store history path in.
- * @return EINA_TRUE on success EINA_FALSE otherwise
- *
- */
-static Eina_Bool
-_set_data_path(char *path)
-{ // XXX: put this back in e's .e dir
-  EINA_SAFETY_ON_NULL_RETURN_VAL(path, EINA_FALSE);
-  const char *temp_str = NULL;
-  struct passwd *pw = NULL;
-  Eina_Bool success = EINA_TRUE;
-
-  /* See if XDG_DATA_HOME is defined
-   *     if so use it
-   *     if not use XDG_DATA_HOME default
-   */
-  temp_str = getenv("XDG_DATA_HOME");
-  if (temp_str && temp_str[0] == '/' )
-    {
-      const int len = snprintf(NULL, 0, "%s", temp_str)
-        + 1 + (temp_str[strlen(temp_str)] != '/');
-      if (len <= PATH_MAX)
-        {
-          snprintf(path, strlen(temp_str)+1, "%s", temp_str);
-          // Ensure XDG_DATA_HOME terminates in '/'
-          if (path[strlen(path)-1] != '/')
-            strncat(path, "/", PATH_MAX-strlen(path)-1);
-        }
-      else PATH_MAX_ERR;
-    }
-  // XDG_DATA_HOME default
-  else
-    {
-      if ((temp_str) && (temp_str[0] != '/'))
-        WRN("Malformed XDG_DATA_HOME path: %s", temp_str);
-      pw = getpwuid(getuid());
-      temp_str = pw->pw_dir;
-      const int len = snprintf(NULL, 0, "%s/.local/share/", temp_str) + 1;
-      if (len <= PATH_MAX)
-        { // hopefully unnecessary Safety check
-          if (temp_str)
-            snprintf(path, PATH_MAX-1, "%s/.local/share/", temp_str);
-          else
-            { // should never happen
-              memset(path, 0, PATH_MAX);
-              success = EINA_FALSE;
-            }
-        }
-      else PATH_MAX_ERR;
-    }
-  return success;
-}
-
-/**
- * @brief Sets the path and file name for saving clipboard history data.
- *
- * @param history_path char array to store history path in.
- * @return EINA_TRUE on success EINA_FALSE otherwise
- *
- * This function not only sets the history path but also creates the needed
- * directories if they do not exist.
- *
- */
-static Eina_Bool
-_set_history_path(char *path)
-{
-  EINA_SAFETY_ON_NULL_RETURN_VAL(path, EINA_FALSE);
-  char temp_str[PATH_MAX] = { 0 };
-  Eina_Bool success = EINA_TRUE;
-
-  if (_set_data_path(path))
-    {
-      const int len = snprintf(NULL, 0, "%s%s/%s", path, CLIPBOARD_MOD_NAME, HISTORY_NAME) + 1;
-      if (len <= PATH_MAX)
-        {
-          strncpy(temp_str, path, PATH_MAX-1);
-          snprintf(path, PATH_MAX-1, "%s%s/", temp_str, CLIPBOARD_MOD_NAME);
-          success = _mkpath_if_not_exists(path);
-          strncat(path, HISTORY_NAME, PATH_MAX-strlen(path)-1);
-        }
-      else PATH_MAX_ERR;
-    }
-  else success = EINA_FALSE;
-  return success;
-}
-
-/**
- * @brief  Reads clipboard Instantance history  from a binary file with location
- *           specified by FreeDesktop XDG specifications
- *
- * @param  items,        the address of an Eina_List to fill with history file
- *         ignore_ws     flag to ignore whitespace in setting label name
- *         label_length  number of characters to store in label name
- *
- * @return  EET_ERROR_NONE on success
- *          Eet error identifier of error otherwise.
- *          On error *items set to NULL
- */
-Eet_Error
-read_history(Eina_List **items, unsigned int ignore_ws, unsigned int label_length)
-{
-  Eet_File *history_file = NULL;
-  Clip_Data *cd = NULL;
-  Eina_List *l = NULL;
-  char history_path[PATH_MAX] = {0};
-  char *ret = NULL;
-  char *str = NULL;
-  int size = 0;
-  int str_len = 0;
-  unsigned int i =0;
-  long item_num = 0;
-  long version = 0;
-
-  // xxx - should use eet data codec here... it'd be a 1 liner then
-  // open history file
-  if (!_set_history_path(history_path))
-    {
-      ERR("History File Creation Error: %s", history_path);
-      return EET_ERROR_BAD_OBJECT;
-    }
-  history_file = eet_open(history_path, EET_FILE_MODE_READ);
-  if (!history_file)
-    {
-      ERR("Failed to open history file: %s", history_path);
-      *items = NULL;
-      return EET_ERROR_BAD_OBJECT;
-    }
-  // check History Version
-  ret = eet_read(history_file, "VERSION", &size);
-  if (!ret)
-    {
-      INF("No version number in history file");
-      ret = "0";
-    }
-  version = strtol(ret, NULL, 10);
-  if (version && version != HISTORY_VERSION)
-    {
-      INF("History file version mismatch, deleting history");
-      *items = NULL;
-      return eet_close(history_file);
-    }
-  // Read Number of items
-  ret = eet_read(history_file, "MAX_ITEMS", &size);
-  if (!ret)
-    {
-      ERR("History file corruption: %s", history_path);
-      *items = NULL;
-      return eet_close(history_file);
-    }
-  // if we have no items in history wrap it up and return
-  item_num = strtol(ret, NULL, 10);
-  if (item_num <= 0)
-    {
-      INF("History file empty or corrupt: %s", history_path);
-      *items = NULL;
-      return eet_close(history_file);
-    }
-  // malloc properly sized str
-  CALLOC_DIGIT_STR(str, item_num);
-  str_len = sizeof(str);
-  // read each item
-  for (i = 1; i <= item_num; i++)
-    {
-      cd = E_NEW(Clip_Data, 1);
-      snprintf(str, str_len, "%d", i);
-      ret = eet_read(history_file, str, &size);
-      if (!ret)
-        {
-          ERR("History file corruption: %s", history_path);
-          *items = NULL;
-          if (l) E_FREE_LIST(l, free_clip_data);
-          free(str);
-          free(cd);
-          return eet_close(history_file);
-        }
-      // FIXME: DATA VALIDATION
-      cd->content = strdup(ret);
-      set_clip_name(&cd->name, cd->content,
-                    ignore_ws, label_length);
-      l = eina_list_append(l, cd);
-    }
-  // and wrap it up
-  free(ret);
-  free(str);
-  *items = l;
-  return eet_close(history_file);
-}
-
-/**
- * @brief  Saves clipboard Instantance history  in a binary file with location
- *           specified by FreeDesktop XDG specifications
- *
- * @param  items, the Eina_List to save to the history file
- *
- * @return  EET_ERROR_NONE on success
- *          Eet error identifier of error otherwise.
- *
- * This function not only sets the history path but will also create the needed
- *    directories if they do not exist. See warnings in auxillary functions.
- *
- */
-Eet_Error
-save_history(Eina_List *items)
-{
-  Eet_File *history_file = NULL;
-  Eina_List *l = NULL;
-  Clip_Data *cd = NULL;
-  char history_path[PATH_MAX] = {0};
-  char *str = NULL;
-  int str_len = 0;
-  unsigned int i = 1;
-  unsigned int n = 0;
-  Eet_Error ret;
-
-  // XXX: use eet data codec. this would be a 1 liner...
-  // open history file
-  if (!_set_history_path(history_path))
-    {
-      ERR("History File Creation Error: %s", history_path);
-      return EET_ERROR_BAD_OBJECT;
-    }
-  history_file = eet_open(history_path, EET_FILE_MODE_WRITE);
-  if (history_file)
-    {
-      // malloc properly sized str
-      //   if !items, 0 items is assumed
-      n = eina_list_count(items);
-      CALLOC_DIGIT_STR(str,n);
-      str_len = sizeof(str) - 1;
-      // write history version
-      snprintf(str, str_len, "%d", (HISTORY_VERSION > 9 ? 9 : HISTORY_VERSION));
-      eet_write(history_file, "VERSION",  str, strlen(str) + 1, 0);
-      // If we have no items in history wrap it up and return
-      if (!items)
-        {
-          snprintf(str, str_len, "%d", 0);
-          eet_write(history_file, "MAX_ITEMS",  str, strlen(str) + 1, 0);
-          free(str);
-          return eet_close(history_file);
-        }
-      // Otherwise write each item
-      EINA_LIST_FOREACH(items, l, cd)
-        {
-          snprintf(str, str_len, "%d", i);
-          eet_write(history_file, str,  cd->content, strlen(cd->content) + 1, 0);
-          i++;
-        }
-      // and wrap it up
-      eet_write(history_file, "MAX_ITEMS",  str, strlen(str) + 1, 0);
-      ret = eet_close(history_file);
-      free(str);
-    }
-  else
-    {
-      ERR("Unable to open history file: %s", history_path);
-      return  EET_ERROR_BAD_OBJECT;
-    }
-  return ret;
-}
diff --git a/src/modules/clipboard/meson.build b/src/modules/clipboard/meson.build
index 9b202f29b..11dfc0c02 100644
--- a/src/modules/clipboard/meson.build
+++ b/src/modules/clipboard/meson.build
@@ -2,6 +2,5 @@ src = ""
   'e_mod_config.c',
   'e_mod_main.c',
   'e_mod_main.h',
-  'history.c',
   'utility.c',
  )

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to