/*
** Copyright (c) 2009 D. Richard Hipp
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the Simplified BSD License (also
** known as the "2-Clause License" or "FreeBSD License".)
** This program is distributed in the hope that it will be useful,
** but without any warranty; without even the implied warranty of
** merchantability or fitness for a particular purpose.
**
** Author contact information:
** drh@hwaci.com
** http://www.hwaci.com/drh/
**
*******************************************************************************
**
** Implementation of the Setup page for "skins".
*/
#include "config.h"
#include
#include "skins.h"
/*
** An array of available built-in skins.
**
** To add new built-in skins:
**
** 1. Pick a name for the new skin. (Here we use "xyzzy").
**
** 2. Install files skins/xyzzy/css.txt, skins/xyzzy/header.txt,
** and skins/xyzzy/footer.txt into the source tree.
**
** 3. Rerun "tclsh makemake.tcl" in the src/ folder in order to
** rebuild the makefiles to reference the new CSS, headers, and footers.
**
** 4. Make an entry in the following array for the new skin.
*/
static struct BuiltinSkin {
const char *zDesc; /* Description of this skin */
const char *zLabel; /* The directory under skins/ holding this skin */
char *zSQL; /* Filled in at run-time with SQL to insert this skin */
} aBuiltinSkin[] = {
{ "Default", "default", 0 },
{ "Plain Gray, No Logo", "plain_gray", 0 },
{ "Khaki, No Logo", "khaki", 0 },
{ "Black & White, Menu on Left", "black_and_white", 0 },
{ "Shadow boxes & Rounded Corners", "rounded1", 0 },
{ "Enhanced Default", "enhanced1", 0 },
{ "San Francisco Modern", "etienne1", 0 },
{ "Eagle", "eagle", 0 },
};
/*
** For a skin named zSkinName, compute the name of the CONFIG table
** entry where that skin is stored and return it.
**
** Return NULL if zSkinName is NULL or an empty string.
**
** If ifExists is true, and the named skin does not exist, return NULL.
*/
static char *skinVarName(const char *zSkinName, int ifExists){
char *z;
if( zSkinName==0 || zSkinName[0]==0 ) return 0;
z = mprintf("skin:%s", zSkinName);
if( ifExists && !db_exists("SELECT 1 FROM config WHERE name=%Q", z) ){
free(z);
z = 0;
}
return z;
}
/*
** Return true if there exists a skin name "zSkinName".
*/
static int skinExists(const char *zSkinName){
int i;
if( zSkinName==0 ) return 0;
for(i=0; iThere is already another skin
@ named "%h(zNewName)". Choose a different name.
}
@
style_footer();
return 1;
}
db_multi_exec(
"UPDATE config SET name='skin:%q' WHERE name='skin:%q';",
zNewName, zOldName
);
return 0;
}
/*
** Respond to a Save button press. Return TRUE if a dialog was painted.
** Return FALSE to continue with the main Skins page.
*/
static int skinSave(const char *zCurrent){
const char *zNewName;
int ex = 0;
if( P("save")==0 ) return 0;
zNewName = P("svname");
if( zNewName && zNewName[0]!=0 ){
}
if( zNewName==0 || zNewName[0]==0 || (ex = skinExists(zNewName))!=0 ){
if( zNewName==0 ) zNewName = "";
style_header("Save Current Skin");
if( ex ){
@
There is already another skin
@ named "%h(zNewName)". Choose a different name.
Deletion of a custom skin is a permanent action that cannot
@ be undone. Please confirm that this is what you want to do:
@
@
@
login_insert_csrf_secret();
@
style_footer();
return;
}
if( P("del2")!=0 && (zName = skinVarName(P("sn"), 1))!=0 ){
db_multi_exec("DELETE FROM config WHERE name=%Q", zName);
}
if( skinRename() ) return;
if( skinSave(zCurrent) ) return;
/* The user pressed one of the "Install" buttons. */
if( P("load") && (z = P("sn"))!=0 && z[0] ){
int seen = 0;
/* Check to see if the current skin is already saved. If it is, there
** is no need to create a backup */
zCurrent = getSkin(0);
for(i=0; i%h(zErr)
}
@
A "skin" is a combination of
@ CSS,
@ Header, and
@ Footer that determines the look and feel
@ of the web interface.
@
@
Available Skins:
@
for(i=0; i
%d(i+1).
%h(z)
if( fossil_strcmp(aBuiltinSkin[i].zSQL, zCurrent)==0 ){
@ (Currently In Use)
seenCurrent = 1;
}else{
@
}
@
}
db_prepare(&q,
"SELECT substr(name, 6), value FROM config"
" WHERE name GLOB 'skin:*'"
" ORDER BY name"
);
while( db_step(&q)==SQLITE_ROW ){
const char *zN = db_column_text(&q, 0);
const char *zV = db_column_text(&q, 1);
i++;
@