'everything' module:
authorHannes Janetzek <hannes.janetzek@gmail.com>
Wed, 15 Jul 2009 12:22:42 +0000 (12:22 +0000)
committerHannes Janetzek <hannes.janetzek@gmail.com>
Wed, 15 Jul 2009 12:22:42 +0000 (12:22 +0000)
- added edit/new application entry actions
- cleaned up action-selector plugin

SVN revision: 41349

src/modules/everything/e_mod_main.h
src/modules/everything/evry.c
src/modules/everything/evry_plug_apps.c

index 253e0369a6706e147739ece81a86d3e1a3997714..87f0fd0562ece87b5a317150e03dd39bd3dd8160 100644 (file)
@@ -42,6 +42,8 @@ struct _Config
 
   int auto_select_first;
 
+  Eina_Hash *key_bindings;
+  
   /**/
   Eina_List *plugins;
   
@@ -141,9 +143,11 @@ struct _Evry_Action
   Evry_Item *thing1;
   Evry_Item *thing2;
   
-  int  (*action) (void);
+  int  (*action) (Evry_Action *act);
 
-  void (*icon_get) (Evry_Plugin *p, Evry_Item *it, Evas *e);  
+  int (*check_item) (Evry_Action *act, Evry_Item *it);  
+
+  void (*icon_get) (Evry_Action *act, Evry_Item *it, Evas *e);  
   
   void *priv;
 
index cf7661d7a2e152be2e4c8d4f26b6fcf5aa2ee52d..c725d17a391c3dbd5b32439be33993eee4f952a8 100644 (file)
@@ -65,7 +65,7 @@ static void _evry_plugin_selector_show(Evry_Plugin *p);
 static int  _evry_cb_plugin_sort(const void *data1, const void *data2);
 
 static int  _evry_plug_act_select_init(void);
-static int  _evry_plug_act_select_actions_set(void);
+static int  _evry_plug_act_select_begin(Evry_Plugin *p, Evry_Item *it);
 static int  _evry_plug_act_select_fetch(Evry_Plugin *p, const char *input);
 static int  _evry_plug_act_select_action(Evry_Plugin *p, Evry_Item *item, const char *input);
 static void _evry_plug_act_select_cleanup(Evry_Plugin *p);
@@ -433,7 +433,7 @@ _evry_push_state(void)
      {
        if (!p->config->enabled) continue;
        
-       if (strstr(p->type_in, cur_type))
+       if (strstr(p->type_in, cur_type) || p == action_selector)
          {
             /* printf("%s- in:%s out:%s\n", p->name, p->type_in, p->type_out); */
 
@@ -460,18 +460,8 @@ _evry_push_state(void)
          }
      }
 
-   if (s && !s->cur_action)
-     {
-       if (_evry_plug_act_select_actions_set())
-         {
-            list = eina_list_append(list, action_selector);
-         }
-     }
-
    if (!list) return 0;
 
-   /* list = eina_list_sort(list, eina_list_count(list), _evry_cb_plugin_sort); */
-
    _evry_list_clear();
 
    s = E_NEW(Evry_State, 1);
@@ -486,6 +476,7 @@ _evry_push_state(void)
      {
        s->request_type = cur_state->request_type;
        s->cur_action = cur_state->cur_action;
+       s->cur_actions = cur_state->cur_actions;
        s->initial = 0;
      }
    else
@@ -868,9 +859,8 @@ _evry_plugin_action(int finished)
    if (s->cur_plugin == action_selector)
      {
        /* set cur_action and start plugins for second parameter (if required)*/
-       if (s->sel_item) _evry_plug_act_select_action(s->cur_plugin, s->sel_item, s->input);
-
-       finished = 0;
+       if (s->sel_item)
+         finished = _evry_plug_act_select_action(s->cur_plugin, s->sel_item, s->input);
      }
    else if (s->cur_action)
      {
@@ -878,7 +868,7 @@ _evry_plugin_action(int finished)
        if (s->sel_item && (!strcmp(s->cur_plugin->type_out, s->request_type)))
          {
             s->cur_action->thing2 = s->sel_item;
-            s->cur_action->action();
+            s->cur_action->action(s->cur_action);
          }
      }
    else if (s->cur_plugin && (s->sel_item || s->input))
@@ -1036,14 +1026,13 @@ _evry_matches_update(Evry_Plugin *cur_plugin)
    /* remove tabs for not active plugins */
    EINA_LIST_FOREACH(evry_conf->plugins, l, p)
      {
-       if (!p->config->enabled) continue;
-       
        if (p->tab && !eina_list_data_find(s->cur_plugins, p))
          {
             evas_object_del(p->tab);
             p->tab = NULL;
          }
      }
+
    /* show/update tabs of active plugins */
    EINA_LIST_FOREACH(s->cur_plugins, l, p)
      _evry_plugin_selector_show(p);
@@ -1100,7 +1089,7 @@ _evry_scroll_to(int i)
      {
        scroll_align_to = (double)i / (double)(n - 1);
        if (evry_conf->scroll_animate)
-         {
+         {
             if (!scroll_timer)
               scroll_timer = ecore_timer_add(0.01, _evry_scroll_timer, NULL);
             if (!scroll_animator)
@@ -1377,35 +1366,50 @@ _evry_plugin_selector_show(Evry_Plugin *p)
    p->tab = o;
 }
 
+
+/* action selector plugin: provides list of actions registered for
+   candidate types provided by current plugin */
 static int
 _evry_plug_act_select_init(void)
 {
+   Plugin_Config *pc;
    Evry_Plugin *p = E_NEW(Evry_Plugin, 1);
    p->name = "Select Action";
    p->type_in  = "ANY";
    p->type_out = "NONE";
+   p->begin    = &_evry_plug_act_select_begin;
    p->cleanup  = &_evry_plug_act_select_cleanup;
    p->fetch    = &_evry_plug_act_select_fetch;
    p->action   = &_evry_plug_act_select_action;
    p->icon_get = &_evry_plug_act_select_item_icon_get;
+
+   pc = E_NEW(Plugin_Config, 1);
+   pc->name = eina_stringshare_add(p->name);
+   pc->enabled = 1;
+   pc->priority = 100;
+   p->config = pc;
+
+   evry_conf->plugins = eina_list_append(evry_conf->plugins, p);
    action_selector = p;
 }
 
 static int
-_evry_plug_act_select_actions_set(void)
+_evry_plug_act_select_begin(Evry_Plugin *p, Evry_Item *it)
 {
    Evry_Action *act;
    Eina_List *l;
    Evry_State *s = cur_state;
-   Evry_Plugin *p = action_selector;
 
    _evry_plug_act_select_cleanup(p);
 
+   if (!s || !s->cur_plugin || s->cur_action) return 0;
+   
    const char *type = s->cur_plugin->type_out;
 
    EINA_LIST_FOREACH(actions, l, act)
      {
-       if (strstr(act->type_in1, type))
+       if ((strstr(act->type_in1, type)) &&
+           (!act->check_item || act->check_item(act, s->sel_item)))
          {
             act->thing1 = s->sel_item;
             s->cur_actions = eina_list_append(s->cur_actions, act);
@@ -1422,10 +1426,11 @@ _evry_plug_act_select_fetch(Evry_Plugin *p, const char *input)
 {
    Evry_Action *act;
    Eina_List *l;
-
+   Evry_State *s = cur_state;
+   
    if (p->items) return 1;
    
-   EINA_LIST_FOREACH(actions, l, act)
+   EINA_LIST_FOREACH(s->cur_actions, l, act)
      {
        Evry_Item *it;
 
@@ -1446,10 +1451,19 @@ _evry_plug_act_select_action(Evry_Plugin *p, Evry_Item *it, const char *input)
 {
    Evry_Action *act = it->data[0];
    cur_state->cur_action = act;
-
-   cur_state->request_type = act->type_in2;
-
-   return _evry_push_state();
+   if (strcmp(act->type_in2, "NONE"))
+     {
+       /* XXX hackish - param for push? */
+       cur_state->request_type = act->type_in2;
+       _evry_push_state();
+       
+       return 0;
+     }
+   else
+     {
+       act->action(act);
+       return 1;
+     }
 }
 
 static void
@@ -1457,6 +1471,8 @@ _evry_plug_act_select_cleanup(Evry_Plugin *p)
 {
    Evry_Item *it;
 
+   if (!cur_state) return;
+   
    EINA_LIST_FREE(p->items, it)
      {
        eina_stringshare_del(it->label);
@@ -1467,12 +1483,6 @@ _evry_plug_act_select_cleanup(Evry_Plugin *p)
    cur_state->cur_actions = NULL;
 
    p->items = NULL;
-
-   if (p->tab)
-     {
-       evas_object_del(p->tab);
-       p->tab = NULL;
-     }
 }
 
 static void
index d1b1e1781f51f1e6516515c0eaa42a27b2c269ce..82f7707be07542659ff5b66a29c6de091d26e477 100644 (file)
@@ -17,11 +17,16 @@ static void _cleanup(Evry_Plugin *p);
 static void _item_add(Evry_Plugin *p, Efreet_Desktop *desktop, char *file, int prio);
 static int  _cb_sort(const void *data1, const void *data2);
 static void _item_icon_get(Evry_Plugin *p, Evry_Item *it, Evas *e);
-static int _exec_action(void);
+static int _exec_app_action(Evry_Action *act);
+static int _edit_app_action(Evry_Action *act);
+static int _edit_app_check_item(Evry_Action *act, Evry_Item *it);
+static int _new_app_action(Evry_Action *act);
 
 static Evry_Plugin *p1;
 static Evry_Plugin *p2;
 static Evry_Action *act;
+static Evry_Action *act2;
+static Evry_Action *act3;
 static Inst *inst;
 
 
@@ -57,9 +62,26 @@ evry_plug_apps_init(void)
    act->type_in1 = "APPLICATION";
    act->type_in2 = "FILE";
    act->type_out = "NONE";
-   act->action = &_exec_action;
+   act->action = &_exec_app_action;
    evry_action_register(act);
 
+   act2 = E_NEW(Evry_Action, 1);
+   act2->name = "Edit Application Entry";
+   act2->type_in1 = "APPLICATION";
+   act2->type_in2 = "NONE";
+   act2->type_out = "NONE";
+   act2->action = &_edit_app_action;
+   act2->check_item = &_edit_app_check_item;
+   evry_action_register(act2);
+
+   act3 = E_NEW(Evry_Action, 1);
+   act3->name = "New Application Entry";
+   act3->type_in1 = "APPLICATION";
+   act3->type_in2 = "NONE";
+   act3->type_out = "NONE";
+   act3->action = &_new_app_action;
+   evry_action_register(act3);
+
    inst = NULL;
 
    return 1;
@@ -71,6 +93,8 @@ evry_plug_apps_shutdown(void)
    evry_plugin_unregister(p1);
    evry_plugin_unregister(p2);
    evry_action_unregister(act);
+   evry_action_unregister(act2);
+   evry_action_unregister(act3);
 
    return 1;
 }
@@ -149,14 +173,14 @@ _action(Evry_Plugin *p, Evry_Item *it, const char *input)
 
    if (desktop)
      {
-       if (inst->candidate)
+       if (inst && inst->candidate)
          files = eina_list_append(files, inst->candidate->uri);
 
        zone = e_util_zone_current_get(e_manager_current_get());
 
        e_exec(zone, desktop, NULL, files, "everything");
 
-       if (inst->candidate && inst->candidate->mime)
+       if (inst && inst->candidate && inst->candidate->mime)
          e_exehist_mime_desktop_add(inst->candidate->mime, desktop);
        
        if (!it)
@@ -207,10 +231,12 @@ _fetch(Evry_Plugin *p, const char *input)
    char *file;
    char match1[4096];
    char match2[4096];
-
+   Evry_Item *it;
+   Evry_App *app;
+   
    _list_free(p);
 
-   if (inst->apps)
+   if (inst && inst->apps)
      {
        if (!input)
          {
@@ -279,9 +305,17 @@ _fetch(Evry_Plugin *p, const char *input)
        inst->added = NULL;
      }
 
-   if (p->items)
+   it = E_NEW(Evry_Item, 1);
+   app = E_NEW(Evry_App, 1);
+   app->file = eina_stringshare_add(input);
+   app->desktop = NULL;
+   it->data[0] = app;
+   it->priority = 100;
+   it->label = eina_stringshare_add("Run Command");
+   p->items = eina_list_append(p->items, it);
+
+     if (p->items)
      {
-       /* if (input) */
        p->items = eina_list_sort(p->items, eina_list_count(p->items), _cb_sort);
        return 1;
      }
@@ -429,20 +463,158 @@ _cb_sort(const void *data1, const void *data2)
 }
 
 static int
-_exec_action()
+_exec_app_action(Evry_Action *act)
 {
    if (act->thing1 && act->thing2)
      {
-       inst = E_NEW(Inst, 1);
-       inst->candidate = act->thing2;
+       E_Zone *zone;
+       Evry_App *app = NULL;
+       Efreet_Desktop *desktop = NULL;
+       Eina_List *files = NULL;
 
-       _action(NULL, act->thing1, NULL);
+       app = act->thing1->data[0];
 
-       E_FREE(inst);
-       inst = NULL;
+       if (app->desktop)
+         desktop = app->desktop;
+       else
+         {
+            desktop = efreet_desktop_empty_new("");
+            if (strchr(app->file, '%'))
+              desktop->exec = strdup(app->file);
+            else
+              {
+                 int len = strlen(app->file) + 4;
+                 desktop->exec = malloc(len);
+                 if (desktop->exec)
+                   snprintf(desktop->exec, len, "%s %%U", app->file);
+              }
+         }
+
+       if (desktop)
+         {
+            files = eina_list_append(files, act->thing2->uri);
+
+            zone = e_util_zone_current_get(e_manager_current_get());
+
+            e_exec(zone, desktop, NULL, files, "everything");
+
+            if (act->thing2->mime)
+              e_exehist_mime_desktop_add(act->thing2->mime, desktop);
+       
+            if (!app->desktop)
+              efreet_desktop_free(desktop);
+
+            eina_list_free(files);
+
+            return EVRY_ACTION_FINISHED;
+         }
+
+       return EVRY_ACTION_CONTINUE;
+     }
+
+   return 0;
+}
+
+static int
+_edit_app_check_item(Evry_Action *act, Evry_Item *it)
+{
+   Evry_App *app = it->data[0];
+   if (app->desktop)
+     return 1;
+
+   return 0;
+}
 
+
+static int
+_edit_app_action(Evry_Action *act)
+{
+   if (act->thing1)
+     {
+       Evry_Item *it = act->thing1;
+       Evry_App *app = it->data[0];
+       
+       Efreet_Desktop *desktop;
+       
+       if (app->desktop)
+         desktop = app->desktop;
+       else
+         {
+            char buf[128];
+            snprintf(buf, 128, "%s/.local/share/applications/%s.desktop", e_user_homedir_get(), app->file);
+            
+            desktop = efreet_desktop_empty_new(eina_stringshare_add(buf));
+            /* XXX check if this is freed */
+            desktop->exec = strdup(app->file); 
+         }
+
+       e_desktop_edit(e_container_current_get(e_manager_current_get()), desktop);
+       
        return 1;
      }
+   
+   return 0;
+}
 
+
+static int
+_new_app_action(Evry_Action *act)
+{
+   if (act->thing1)
+     {
+       Evry_Item *it = act->thing1;
+       Evry_App *app = it->data[0];
+       char *name;
+       char buf[4096];
+       char *end;
+       Efreet_Desktop *desktop;
+       int i;
+       
+       if (app->desktop)
+         name = strdup(app->desktop->name);
+       else
+         /* TODO replace '/' and remove other special characters */
+         name = strdup(app->file);
+
+       if ((end = strchr(name, ' ')))
+         name[end - name] = '\0';
+       
+       for (i = 0; i < 10; i++)
+         {
+            snprintf(buf, 4096, "%s/.local/share/applications/%s-%d.desktop", e_user_homedir_get(), name, i);
+            if (ecore_file_exists(buf))
+              {
+                 buf[0] = '\0';
+                 continue;
+              }
+            else break;
+         }
+
+       free(name);
+          
+       if (strlen(buf) == 0)
+         return 0;
+       
+       if (!app->desktop)
+         {
+            desktop = efreet_desktop_empty_new(buf);
+            desktop->exec = strdup(app->file);
+         }
+       else 
+         {
+            efreet_desktop_save_as(app->desktop, buf);
+            /*XXX hackish - desktop is removed on save_as..*/
+            efreet_desktop_new(app->desktop->orig_path);
+            
+            desktop = efreet_desktop_new(buf);
+         }
+       
+       e_desktop_edit(e_container_current_get(e_manager_current_get()), desktop);
+
+       return 1;
+     }
+   
    return 0;
 }
+
+