'everything'
authorHannes Janetzek <hannes.janetzek@gmail.com>
Thu, 3 Sep 2009 14:21:27 +0000 (14:21 +0000)
committerHannes Janetzek <hannes.janetzek@gmail.com>
Thu, 3 Sep 2009 14:21:27 +0000 (14:21 +0000)
- remember context of action. e.g. which app was used for
  opening a file with a specific mimetype

SVN revision: 42205

src/modules/everything/Evry.h
src/modules/everything/e_mod_main.h
src/modules/everything/evry.c
src/modules/everything/evry_history.c
src/modules/everything/evry_plug_aggregator.c
src/modules/everything/sources/evry_plug_dir_browse.c

index c2f713d..71639c4 100644 (file)
@@ -70,6 +70,10 @@ struct _Evry_Item
   const char *label;
   const char *icon;
 
+  /* context provided by item. e.g. to remember which action
+   * was performed on a file with a specific mimetype */
+  const char *context;
+
   /* item can be browsed, e.g. folders */
   Eina_Bool browseable;
 
index 76cb8a7..b7ae908 100644 (file)
@@ -140,8 +140,8 @@ void evry_history_init(void);
 void evry_history_free(void);
 void evry_history_load(void);
 void evry_history_unload(void);
-void evry_history_add(Eina_Hash *hist, Evry_State *s);
-EAPI int  evry_history_item_usage_set(Eina_Hash *hist, Evry_Item *it, const char *input);
+void evry_history_add(Eina_Hash *hist, Evry_State *s, const char *ctxt);
+int  evry_history_item_usage_set(Eina_Hash *hist, Evry_Item *it, const char *input, const char *ctxt);
 
 EAPI int  evry_browse_item(Evry_Selector *sel);
 void evry_browse_back(Evry_Selector *sel);
index 31ec0d4..d6a9a03 100644 (file)
@@ -306,7 +306,8 @@ evry_item_free(Evry_Item *it)
 
    if (it->label) eina_stringshare_del(it->label);
    if (it->id) eina_stringshare_del(it->id);
-
+   if (it->context) eina_stringshare_del(it->context);
+   
    if (it->free)
      it->free(it);
    else
@@ -1080,7 +1081,7 @@ evry_browse_item(Evry_Selector *sel)
    if (!plugins)
      return 1;
 
-   evry_history_add(sel->history, s); 
+   evry_history_add(sel->history, s, NULL); 
    
    if (s->view)
      {
@@ -1440,9 +1441,9 @@ _evry_plugin_action(Evry_Selector *sel, int finished)
      }
    else return;
 
-   evry_history_add(evry_hist->subjects, s_subject);
-   evry_history_add(evry_hist->actions, s_action);
-   evry_history_add(evry_hist->subjects, s_object);
+   evry_history_add(evry_hist->subjects, s_subject, NULL);
+   evry_history_add(evry_hist->actions, s_action, s_subject->cur_item->context);
+   evry_history_add(evry_hist->subjects, s_object, s_action->cur_item->context);
    
    /* let subject and object plugin know that an action was performed */
    if (s_subject->plugin->action)
index fa5b4d4..e364326 100644 (file)
@@ -195,7 +195,7 @@ evry_history_unload(void)
 }
 
 void
-evry_history_add(Eina_Hash *hist, Evry_State *s)
+evry_history_add(Eina_Hash *hist, Evry_State *s, const char *ctxt)
 {
    History_Entry *he;
    History_Item  *hi = NULL;
@@ -219,7 +219,9 @@ evry_history_add(Eina_Hash *hist, Evry_State *s)
    else
      {
        EINA_LIST_FOREACH(he->items, l, hi)
-         if (hi->plugin == it->plugin->name) break;
+         if ((hi->plugin == it->plugin->name) &&
+             (ctxt == hi->context))
+           break;
      }
 
    if (!hi)
@@ -236,7 +238,9 @@ evry_history_add(Eina_Hash *hist, Evry_State *s)
        hi->usage += TIME_FACTOR(hi->last_used);
        hi->transient = it->transient;
        hi->count += (hi->transient ? 2:1);
-
+       if (ctxt && !hi->context)
+         hi->context = eina_stringshare_ref(ctxt);
+       
        if (s->input)
          {
             if (hi->input)
@@ -248,7 +252,7 @@ evry_history_add(Eina_Hash *hist, Evry_State *s)
 }
 
 int
-evry_history_item_usage_set(Eina_Hash *hist, Evry_Item *it, const char *input)
+evry_history_item_usage_set(Eina_Hash *hist, Evry_Item *it, const char *input, const char *ctxt)
 {
    History_Entry *he;
    History_Item *hi;
@@ -266,7 +270,7 @@ evry_history_item_usage_set(Eina_Hash *hist, Evry_Item *it, const char *input)
 
        if (!input || !hi->input)
          {
-            it->usage = hi->usage * hi->count;
+            it->usage += hi->usage * hi->count;
          }
        else
          {
@@ -280,6 +284,11 @@ evry_history_item_usage_set(Eina_Hash *hist, Evry_Item *it, const char *input)
                  it->usage += hi->usage * hi->count;
               }
          }
+       if (hi->context && ctxt)
+         {
+            if (hi->context == ctxt)
+              it->usage += hi->usage * hi->count * 2;
+         }
      }
    
    if (it->usage > 0.0)
index cc78088..0069193 100644 (file)
@@ -99,13 +99,25 @@ _fetch(Evry_Plugin *plugin, const char *input)
    Evry_State *s;
    Eina_List *l, *ll, *lp;
    Evry_Item *it;
-   int cnt = 0;
+   int i, cnt = 0;
    Eina_List *items = NULL;
-
+   const char *context = NULL;
+   
    EVRY_PLUGIN_ITEMS_FREE(p);
 
    s = p->selector->state;
 
+   for (i = 1; i < 3; i++)
+     {
+       Evry_Item *item;
+       if (p->selector == selectors[i])
+         {
+            item = selectors[i-1]->state->cur_item;
+            context = item->context;
+         }     
+     }
+   
+   
    /* first is aggregator itself */
    lp = s->cur_plugins->next;
 
@@ -153,7 +165,7 @@ _fetch(Evry_Plugin *plugin, const char *input)
      {
        EINA_LIST_FOREACH(pp->items, ll, it)
          {
-            if (evry_history_item_usage_set(p->selector->history, it, input) &&
+            if (evry_history_item_usage_set(p->selector->history, it, input, context) &&
                 (!eina_list_data_find_list(items, it)))
               {
                  evry_item_ref(it);
index 108876a..2bb9e28 100644 (file)
@@ -50,7 +50,8 @@ _item_fill(Evry_Item_File *file)
    if ((mime = efreet_mime_type_get(file->uri)))
      {
        file->mime = eina_stringshare_add(mime);
-
+       EVRY_ITEM(file)->context = eina_stringshare_ref(file->mime);
+         
        if ((!strcmp(mime, "inode/directory")) ||
            (!strcmp(mime, "inode/mount-point")))
          EVRY_ITEM(file)->browseable = EINA_TRUE;
@@ -202,8 +203,11 @@ _scan_end_func(void *data)
        p->files = eina_list_append(p->files, file);
 
        if (item->browseable)
-         file->mime = eina_stringshare_ref(mime_folder);
-
+         {
+            file->mime = eina_stringshare_ref(mime_folder);
+            EVRY_ITEM(file)->context = eina_stringshare_ref(file->mime);
+         }
+       
        if (p->command || cnt >= MAX_ITEMS) continue;
        cnt += _append_file(p, file);
      }