// swad_icon.c: icons
/*
SWAD (Shared Workspace At a Distance),
is a web platform developed at the University of Granada (Spain),
and used to support university teaching.
This file is part of SWAD core.
Copyright (C) 1999-2019 Antonio Caņas Vargas
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
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. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
*/
/*****************************************************************************/
/********************************* Headers ***********************************/
/*****************************************************************************/
#include
#include "swad_box.h"
#include "swad_config.h"
#include "swad_database.h"
#include "swad_form.h"
#include "swad_global.h"
#include "swad_HTML.h"
#include "swad_icon.h"
#include "swad_layout.h"
#include "swad_parameter.h"
#include "swad_setting.h"
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/******************************** Private constants **************************/
/*****************************************************************************/
#define Ico_MAX_BYTES_ICON_SET_ID 16
const char *Ico_IconSetId[Ico_NUM_ICON_SETS] =
{
"awesome",
"nuvola",
};
const char *Ico_IconSetNames[Ico_NUM_ICON_SETS] =
{
"Awesome",
"Nuvola",
};
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
static void Ico_PutIconsIconSet (void);
/*****************************************************************************/
/*********** Get icon with extension from icon without extension *************/
/*****************************************************************************/
#define Ico_NUM_ICON_EXTENSIONS 3
const char *Ico_GetIcon (const char *IconWithoutExtension)
{
static const char *Ico_IconExtensions[Ico_NUM_ICON_EXTENSIONS] =
{ // In order of preference
"svg",
"png",
"gif",
};
static char IconWithExtension[NAME_MAX + 1];
char PathIcon[PATH_MAX + 1];
unsigned NumExt;
for (NumExt = 0;
NumExt < Ico_NUM_ICON_EXTENSIONS;
NumExt++)
{
snprintf (IconWithExtension,sizeof (IconWithExtension),
"%s.%s",
IconWithoutExtension,Ico_IconExtensions[NumExt]);
snprintf (PathIcon,sizeof (PathIcon),
"%s/%s/%s",
Cfg_PATH_ICON_SETS_PUBLIC,
Ico_IconSetId[Gbl.Prefs.IconSet],
IconWithExtension);
if (Fil_CheckIfPathExists (PathIcon))
return IconWithExtension;
}
return "default.svg";
}
/*****************************************************************************/
/************************ Put icons to select a IconSet **********************/
/*****************************************************************************/
void Ico_PutIconsToSelectIconSet (void)
{
extern const char *Hlp_PROFILE_Settings_icons;
extern const char *Txt_Icons;
Ico_IconSet_t IconSet;
char Icon[PATH_MAX + 1];
Box_StartBox (NULL,Txt_Icons,Ico_PutIconsIconSet,
Hlp_PROFILE_Settings_icons,Box_NOT_CLOSABLE);
Set_StartSettingsHead ();
Set_StartOneSettingSelector ();
for (IconSet = (Ico_IconSet_t) 0;
IconSet < Ico_NUM_ICON_SETS;
IconSet++)
{
fprintf (Gbl.F.Out,"
",DivClass);
fprintf (Gbl.F.Out,"",
Cfg_URL_ICON_PUBLIC,Icon,
Title,Title);
HTM_DIV_End ();
}
/*****************************************************************************/
/*********** Show an icon with a link inside a div (without text) ************/
/*****************************************************************************/
void Ico_PutDivIconLink (const char *DivClass,const char *Icon,const char *Title)
{
fprintf (Gbl.F.Out,"
",DivClass);
Ico_PutIconLink (Icon,Title);
HTM_DIV_End ();
}
/*****************************************************************************/
/****************** Show an icon with a link (without text) ******************/
/*****************************************************************************/
void Ico_PutIconLink (const char *Icon,const char *Title)
{
fprintf (Gbl.F.Out,"",
Cfg_URL_ICON_PUBLIC,Icon,
Title,Title);
}
/*****************************************************************************/
/******************* Show an icon with a link (with text) ********************/
/*****************************************************************************/
void Ico_PutIconTextLink (const char *Icon,const char *Text)
{
/***** Print icon and optional text *****/
fprintf (Gbl.F.Out,"
");
fprintf (Gbl.F.Out,""
" %s",
Cfg_URL_ICON_PUBLIC,Icon,Text,Text,
Text);
HTM_DIV_End ();
}
/*****************************************************************************/
/**************************** Show a setting selector *************************/
/*****************************************************************************/
void Ico_PutSettingIconLink (const char *Icon,const char *Title)
{
fprintf (Gbl.F.Out,"",
Cfg_URL_ICON_PUBLIC,Icon,
Title,Title);
}
/*****************************************************************************/
/********************** Put an inactive/disabled icon ************************/
/*****************************************************************************/
void Ico_PutIconOff (const char *Icon,const char *Title)
{
fprintf (Gbl.F.Out,"",
Cfg_URL_ICON_PUBLIC,Icon,Title,Title);
}
/*****************************************************************************/
/********** Put a icon to submit a form. **********/
/********** When clicked, the icon will be replaced by an animation **********/
/*****************************************************************************/
void Ico_PutCalculateIcon (const char *Title)
{
fprintf (Gbl.F.Out,"
");
fprintf (Gbl.F.Out,""
"", // Animated icon hidden
Gbl.Form.Num,Cfg_URL_ICON_PUBLIC,Title,Title,
Gbl.Form.Num,Cfg_URL_ICON_PUBLIC,Title,Title);
HTM_DIV_End ();
fprintf (Gbl.F.Out,"");
}
/*****************************************************************************/
/********** Put a icon with a text to submit a form. **********/
/********** When clicked, the icon will be replaced by an animation **********/
/*****************************************************************************/
void Ico_PutCalculateIconWithText (const char *Text)
{
fprintf (Gbl.F.Out,"
");
fprintf (Gbl.F.Out,""
"" // Animated icon hidden
" %s",
Gbl.Form.Num,Cfg_URL_ICON_PUBLIC,Text,Text,
Gbl.Form.Num,Cfg_URL_ICON_PUBLIC,Text,Text,
Text);
HTM_DIV_End ();
fprintf (Gbl.F.Out,"");
}
/*****************************************************************************/
/******** Put a disabled icon indicating that removal is not allowed *********/
/*****************************************************************************/
void Ico_PutIconRemovalNotAllowed (void)
{
extern const char *Txt_Removal_not_allowed;
Ico_PutIconOff ("trash.svg",Txt_Removal_not_allowed);
}
/*****************************************************************************/
/************************ Put an icon to remove ******************************/
/*****************************************************************************/
void Ico_PutIconRemove (void)
{
extern const char *Txt_Remove;
Ico_PutIconLink ("trash.svg",Txt_Remove);
}
/*****************************************************************************/
/*************************** Put an icon to cut ******************************/
/*****************************************************************************/
void Ico_PutIconCut (void)
{
extern const char *Txt_Cut;
Ico_PutIconLink ("cut.svg",Txt_Cut);
}
/*****************************************************************************/
/************************** Put an icon to paste *****************************/
/*****************************************************************************/
void Ico_PutIconPaste (void)
{
extern const char *Txt_Paste;
Ico_PutIconLink ("paste.svg",Txt_Paste);
}