aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules/bryce_migration/e_mod_main.c
blob: deeae97a5cd869bbd4838f276e4fedd992941d65 (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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#include <e.h>

static Eina_Bool _ask_user_migration(void *data);
static Eina_Bool _ask_user_valid(void *data);
static void _migrate_user_cb(void *data, E_Dialog *dia);
static void _migrate_user_ok_cb(void *data, E_Dialog *dia);
static void _migrate_user_cancel_cb(void *data, E_Dialog *dia);

typedef enum _Bryce_Migration_Step
{
   BRYCE_MIGRATION_ASK = 0,
   BRYCE_MIGRATION_RUN,
   BRYCE_MIGRATION_DONE
} Bryce_Migration_Step;

typedef struct _Config
{
   Bryce_Migration_Step step;
} Config;

static Config *_bryce_migration_config = NULL;
static E_Config_DD *_conf_edd = NULL;


E_API E_Module_Api e_modapi =
{
   E_MODULE_API_VERSION,
   "Bryce migration"
};

E_API void *
e_modapi_init(E_Module *m)
{
   _conf_edd = E_CONFIG_DD_NEW("Config", Config);
#undef T
#undef D
#define T Config
#define D _conf_edd
   E_CONFIG_VAL(D, T, step, UINT);
   _bryce_migration_config =  e_config_domain_load("module.bryce_migration", _conf_edd);
   if (!_bryce_migration_config)
     _bryce_migration_config = E_NEW(Config, 1);



   switch(_bryce_migration_config->step)
   {
    case BRYCE_MIGRATION_ASK:
       ecore_timer_add(1.0, _ask_user_migration, NULL);
       break;
    case BRYCE_MIGRATION_RUN:
       ecore_timer_add(1.0, _ask_user_valid, NULL);
       break;
    case BRYCE_MIGRATION_DONE:
       fprintf(stderr, "migration done\n");
       break;
   }


   return m;
}

E_API int
e_modapi_shutdown(E_Module *m EINA_UNUSED)
{
   E_FREE(_bryce_migration_config);
   return 1;
}

E_API int
e_modapi_save(E_Module *m EINA_UNUSED)
{
   e_config_domain_save("module.bryce_migration", _conf_edd, _bryce_migration_config);
   return 1;
}

static Eina_Bool
_ask_user_migration(void *data)
{
   E_Dialog *dia;

   dia = e_dialog_new(NULL, "E", "_module_bryce_migration");

   e_dialog_title_set(dia, "Bryce Migration");
   e_dialog_icon_set(dia, "enlightenment", 64);
   e_dialog_text_set(dia, "Hi, shelf are deprecatede</br>We Will try to update your config to the new gadget container (bryce). Hope this run works well for you !");
   e_dialog_button_add(dia, _("Migrate"), NULL, _migrate_user_cb, NULL);
   e_dialog_button_add(dia, _("Later"), NULL, NULL, NULL);
   elm_win_center(dia->win, 1, 1);
   e_win_no_remember_set(dia->win, 1);
   e_dialog_show(dia);

   return ECORE_CALLBACK_CANCEL;
}

static Eina_Bool
_ask_user_valid(void *data)
{
   E_Dialog *dia;

   dia = e_dialog_new(NULL, "E", "_module_bryce_migration");

   e_dialog_title_set(dia, "Bryce Migration");
   e_dialog_icon_set(dia, "enlightenment", 64);
   e_dialog_text_set(dia, _("Would you keep this setup ?"));
   e_dialog_button_add(dia, _("Keep this config"), NULL, _migrate_user_ok_cb, NULL);
   e_dialog_button_add(dia, _("Reset to my old Config"), NULL, _migrate_user_cancel_cb, NULL);
   elm_win_center(dia->win, 1, 1);
   e_win_no_remember_set(dia->win, 1);
   e_dialog_show(dia);

   return ECORE_CALLBACK_CANCEL;
}



static void
_migrate_user_cb(void *data, E_Dialog *dia)
{
   char buf[4096];
   char buf2[4096];
   char cmd[PATH_MAX];

   e_object_del(E_OBJECT(dia));
   e_user_dir_snprintf(buf, sizeof(buf), "config/%s", e_config_profile_get());
   e_user_dir_snprintf(buf2, sizeof(buf2), "config/bryce_backup");
   snprintf(cmd, sizeof(cmd), "rm -rf %s", buf2);
   fprintf(stderr, "exec -> %s\n", cmd);
   system(cmd);
   snprintf(cmd, sizeof(cmd), "/usr/bin/cp -a %s %s", buf, buf2);
   fprintf(stderr, "exec -> %s\n", cmd);
   system(cmd);
   fprintf(stderr, "Backup current profile %s\n", cmd);
   _bryce_migration_config->step = BRYCE_MIGRATION_RUN;
   e_config_save();
   e_config_save_flush();
   e_config_save_block_set(EINA_TRUE);

   snprintf(cmd, sizeof(cmd),
            "/usr/lib/enlightenment/utils/enlightenment_bryce_migration "
            "--path %s ", buf);
   system(cmd);
   kill(getpid(), SIGKILL);
}

static void
_migrate_user_ok_cb(void *data, E_Dialog *dia)
{
   E_Module *m;
   e_object_del(E_OBJECT(dia));
   _bryce_migration_config->step = BRYCE_MIGRATION_DONE;
   m = e_module_find("bryce_migration");
   e_module_disable(m);
   e_config_save_queue();
}

static void
_migrate_user_cancel_cb(void *data, E_Dialog *dia)
{
   char buf[4096];
   char buf2[4096];
   char cmd[PATH_MAX];

   _bryce_migration_config->step = BRYCE_MIGRATION_ASK;
   e_config_save();
   e_config_save_flush();
   e_object_del(E_OBJECT(dia));
   e_config_save_block_set(EINA_TRUE);
   fprintf(stderr, "Reset config\n");
   e_user_dir_snprintf(buf, sizeof(buf), "config/%s", e_config_profile_get());
   e_user_dir_snprintf(buf2, sizeof(buf2), "config/bryce_backup");
   fprintf(stderr, "exec -> %s\n", cmd);
   snprintf(cmd, sizeof(cmd), "rm -rf %s", buf);
   system(cmd);
   snprintf(cmd, sizeof(cmd), "/usr/bin/cp -a %s %s", buf2, buf);
   system(cmd);
   snprintf(cmd, sizeof(cmd), "rm -rf %s", buf2);
   system(cmd);
   kill(getpid(), SIGKILL);
}