summaryrefslogtreecommitdiff
path: root/src/modules/physics/e_mod_main.c
blob: a7ae7b974eae969956639a992969d4d7325f7609 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include "e.h"
#include "e_mod_main.h"
#include "e_mod_physics.h"
#include <EPhysics.h>

/* module private routines */
Mod *_physics_mod = NULL;

/* public module routines. all modules must have these */
EAPI E_Module_Api e_modapi =
{
   E_MODULE_API_VERSION,
   "Physics"
};

EAPI void *
e_modapi_init(E_Module *m)
{
   Mod *mod;
   char buf[4096];

   {
      Eina_List *l;
      E_Module *m2;
      EINA_LIST_FOREACH(e_module_list(), l, m2)
        {
           if (m2->enabled && (!strcmp(m2->name, "tiling")))
             {
                e_util_dialog_internal(_("Physics"),
                                       _("Cowardly refusing to battle<br>"
                                         "with the Tiling module for control<br>"
                                         "of your windows. There can be only one!"));
                return NULL;
             }
        }
   }

   if (!ephysics_init()) return NULL;
   mod = calloc(1, sizeof(Mod));
   m->data = mod;

   mod->module = m;

   snprintf(buf, sizeof(buf), "%s/e-module-physics.edj", e_module_dir_get(m));
   e_configure_registry_category_add("appearance", 10, _("Look"), NULL,
                                     "preferences-look");
   e_configure_registry_item_add("appearance/physics", 120, _("Physics"), NULL,
                                 buf, e_int_config_physics_module);
   mod->conf_edd = e_mod_physics_cfdata_edd_init();

   mod->conf = e_config_domain_load("module.physics", mod->conf_edd);
   if (mod->conf)
     {
        if (!e_util_module_config_check(_("Physics"), mod->conf->config_version, MOD_CONFIG_FILE_VERSION))
          {
             e_mod_cfdata_config_free(mod->conf);
             mod->conf = NULL;
          }
     }
   if (!mod->conf)
     _e_mod_config_new(m);
   mod->conf->config_version = MOD_CONFIG_FILE_VERSION;
   _physics_mod = mod;

   if (!e_mod_physics_init())
     {
        e_util_dialog_internal(_("Physics Error"), _("The physics module could not be started"));
        e_modapi_shutdown(mod->module);
        return NULL;
     }

   e_module_delayed_set(m, 0);
   e_module_priority_set(m, -1000);
   return mod;
}

void
_e_mod_config_new(E_Module *m)
{
   Mod *mod = m->data;

   mod->conf = e_mod_physics_cfdata_config_new();
}

void
_e_mod_config_free(E_Module *m)
{
   Mod *mod = m->data;

   e_mod_cfdata_config_free(mod->conf);
   mod->conf = NULL;
}

EAPI int
e_modapi_shutdown(E_Module *m)
{
   Mod *mod = m->data;

   e_mod_physics_shutdown();

   e_configure_registry_item_del("appearance/physics");
   e_configure_registry_category_del("appearance");

   if (mod->config_dialog)
     {
        e_object_del(E_OBJECT(mod->config_dialog));
        mod->config_dialog = NULL;
     }
   _e_mod_config_free(m);

   E_CONFIG_DD_FREE(mod->conf_edd);
   free(mod);

   if (mod == _physics_mod) _physics_mod = NULL;

   ephysics_shutdown();
   return 1;
}

EAPI int
e_modapi_save(E_Module *m)
{
   Mod *mod = m->data;
   e_config_domain_save("module.physics", mod->conf_edd, mod->conf);
   return 1;
}