2 * ion/ioncore/saveload.c
4 * Copyright (c) Tuomo Valkonen 1999-2006.
6 * Ion is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
16 #include <libtu/objp.h>
17 #include <libextl/readconfig.h>
18 #include <libextl/extl.h>
32 static bool loading_layout=FALSE;
33 static bool layout_load_error=FALSE;
36 /*{{{ Session management module support */
39 static SMAddCallback *add_cb;
40 static SMCfgCallback *cfg_cb;
41 static SMPHolderCallback *ph_cb;
42 static bool clientwin_was_missing=FALSE;
45 void ioncore_set_sm_callbacks(SMAddCallback *add, SMCfgCallback *cfg)
52 void ioncore_get_sm_callbacks(SMAddCallback **add, SMCfgCallback **cfg)
59 void ioncore_set_sm_pholder_callback(SMPHolderCallback *phcb)
65 void ioncore_clientwin_load_missing()
67 clientwin_was_missing=TRUE;
74 /*{{{ Load support functions */
77 WRegion *create_region_load(WWindow *par, const WFitParams *fp,
80 char *objclass=NULL, *name=NULL;
81 WRegionLoadCreateFn* fn=NULL;
82 WRegClassInfo *info=NULL;
85 char *grouped_name=NULL;
87 if(!extl_table_gets_s(tab, "type", &objclass))
90 /* Backwards compatibility hack. */
91 if(strcmp(objclass, "WFloatWS")==0){
92 objclass=scopy("WGroupWS");
93 }else if(strcmp(objclass, "WIonWS")==0){
94 WGroupWS *ws=create_groupws(par, fp);
96 extl_table_gets_s(tab, "name", &name);
97 extl_table_sets_s(tab, "type", "WTiling");
98 extl_table_sets_b(tab, "bottom", TRUE);
99 extl_table_sets_b(tab, "bottom_last_close", TRUE);
100 extl_table_sets_i(tab, "sizepolicy", SIZEPOLICY_FULL_EXACT);
103 region_set_name((WRegion*)ws, name);
105 reg=group_attach_new((WGroup*)ws, tab);
110 destroy_obj((Obj*)ws);
112 objclass=scopy("WTiling");
113 }else if(strcmp(objclass, "WFloatFrame")==0){
114 objclass=scopy("WFrame");
120 info=ioncore_lookup_regclass(objclass, FALSE);
125 warn(TR("Unknown class \"%s\", cannot create region."),
127 layout_load_error=loading_layout;
133 clientwin_was_missing=FALSE;
135 reg=fn(par, fp, tab);
138 if(clientwin_was_missing && add_cb!=NULL && ph_cb!=NULL){
139 WPHolder *ph=ph_cb();
142 destroy_obj((Obj*)ph);
146 if(!OBJ_IS(reg, WClientWin)){
147 if(extl_table_gets_s(tab, "name", &name)){
148 region_set_name(reg, name);
163 /*{{{ Save support functions */
166 bool region_supports_save(WRegion *reg)
168 return HAS_DYN(reg, region_get_configuration);
172 ExtlTab region_get_base_configuration(WRegion *reg)
177 tab=extl_create_table();
179 extl_table_sets_s(tab, "type", OBJ_TYPESTR(reg));
181 name=region_name(reg);
183 if(name!=NULL && !OBJ_IS(reg, WClientWin))
184 extl_table_sets_s(tab, "name", name);
190 ExtlTab region_get_configuration(WRegion *reg)
192 ExtlTab tab=extl_table_none();
193 CALL_DYN_RET(tab, ExtlTab, region_get_configuration, reg, (reg));
201 /*{{{ save_workspaces, load_workspaces */
204 static const char backup_msg[]=DUMMY_TR(
205 "There were errors loading layout. Backing up current layout savefile as\n"
207 "If you are _not_ running under a session manager and wish to restore your\n"
208 "old layout, copy this backup file over the layout savefile found in the\n"
209 "same directory while Ion is not running and after having fixed your other\n"
210 "configuration files that are causing this problem. (Maybe a missing\n"
214 bool ioncore_init_layout()
221 ok=extl_read_savefile("saved_layout", &tab);
224 layout_load_error=FALSE;
226 FOR_ALL_SCREENS(scr){
227 ExtlTab scrtab=extl_table_none();
230 scrok=extl_table_geti_t(tab, screen_id(scr), &scrtab);
232 n+=(TRUE==screen_init_layout(scr, scrtab));
235 extl_unref_table(scrtab);
238 loading_layout=FALSE;
240 if(layout_load_error){
242 char tm[]="saved_layout.backup-YYYYMMDDHHMMSS\0\0\0\0";
245 strftime(tm+20, 15, "%Y%m%d%H%M%S", localtime(&t));
246 backup=extl_get_savefile(tm);
248 warn(TR("Unable to get file for layout backup."));
251 if(access(backup, F_OK)==0){
252 warn(TR("Backup file %s already exists."), backup);
256 warn(TR(backup_msg), backup);
257 if(!extl_serialise(backup, tab))
258 warn(TR("Failed backup."));
263 warn(TR("Unable to initialise layout on any screen."));
271 bool ioncore_save_layout()
274 ExtlTab tab=extl_create_table();
277 if(tab==extl_table_none())
280 FOR_ALL_SCREENS(scr){
281 ExtlTab scrtab=region_get_configuration((WRegion*)scr);
282 if(scrtab==extl_table_none()){
283 warn(TR("Unable to get configuration for screen %d."),
286 extl_table_seti_t(tab, screen_id(scr), scrtab);
287 extl_unref_table(scrtab);
291 ret=extl_write_savefile("saved_layout", tab);
293 extl_unref_table(tab);
296 warn(TR("Unable to save layout."));