swad-core/swad_icon.c

467 lines
16 KiB
C
Raw Normal View History

2017-06-11 19:13:28 +02:00
// swad_icon.c: icons
2014-12-01 23:55:08 +01:00
/*
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.
2019-01-07 21:52:19 +01:00
Copyright (C) 1999-2019 Antonio Ca<EFBFBD>as Vargas
2014-12-01 23:55:08 +01:00
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 <http://www.gnu.org/licenses/>.
*/
/*****************************************************************************/
/********************************* Headers ***********************************/
/*****************************************************************************/
2018-10-22 10:21:34 +02:00
#define _GNU_SOURCE // For asprintf
#include <stdio.h> // For asprintf, fprintf, etc.
2014-12-01 23:55:08 +01:00
#include <string.h>
2017-06-10 21:38:10 +02:00
#include "swad_box.h"
2014-12-01 23:55:08 +01:00
#include "swad_config.h"
#include "swad_database.h"
2018-11-09 20:47:39 +01:00
#include "swad_form.h"
2014-12-01 23:55:08 +01:00
#include "swad_global.h"
#include "swad_icon.h"
#include "swad_layout.h"
#include "swad_parameter.h"
#include "swad_preference.h"
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
/******************************** Private constants **************************/
/*****************************************************************************/
2015-11-21 20:23:28 +01:00
#define Ico_MAX_BYTES_ICON_SET_ID 16
2014-12-01 23:55:08 +01:00
const char *Ico_IconSetId[Ico_NUM_ICON_SETS] =
{
"awesome",
"nuvola",
};
const char *Ico_IconSetNames[Ico_NUM_ICON_SETS] =
{
"Awesome",
"Nuvola",
};
2016-11-07 12:59:44 +01:00
/*****************************************************************************/
/***************************** Private prototypes ****************************/
/*****************************************************************************/
static void Ico_PutIconsIconSet (void);
2019-01-09 01:41:54 +01:00
/*****************************************************************************/
/*********** 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/%s/%s",
Cfg_PATH_SWAD_PUBLIC,Cfg_FOLDER_PUBLIC_ICON,
Cfg_ICON_FOLDER_ICON_SETS,Ico_IconSetId[Gbl.Prefs.IconSet],
IconWithExtension);
if (Fil_CheckIfPathExists (PathIcon))
return IconWithExtension;
}
return "default.svg";
}
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/************************ Put icons to select a IconSet **********************/
/*****************************************************************************/
void Ico_PutIconsToSelectIconSet (void)
{
2016-11-13 01:21:35 +01:00
extern const char *Hlp_PROFILE_Preferences_icons;
2015-01-01 15:50:45 +01:00
extern const char *Txt_Icons;
2014-12-01 23:55:08 +01:00
Ico_IconSet_t IconSet;
2019-01-12 03:00:59 +01:00
char Icon[PATH_MAX + 1];
2014-12-01 23:55:08 +01:00
2017-06-11 22:26:40 +02:00
Box_StartBox (NULL,Txt_Icons,Ico_PutIconsIconSet,
2017-06-12 15:03:29 +02:00
Hlp_PROFILE_Preferences_icons,Box_NOT_CLOSABLE);
2016-12-23 22:19:03 +01:00
fprintf (Gbl.F.Out,"<div class=\"PREF_CONTAINER\">");
2014-12-01 23:55:08 +01:00
for (IconSet = (Ico_IconSet_t) 0;
IconSet < Ico_NUM_ICON_SETS;
IconSet++)
{
2016-12-23 22:19:03 +01:00
fprintf (Gbl.F.Out,"<div class=\"%s\">",
2015-11-22 00:52:55 +01:00
IconSet == Gbl.Prefs.IconSet ? "PREF_ON" :
"PREF_OFF");
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActChgIco);
2014-12-01 23:55:08 +01:00
Par_PutHiddenParamString ("IconSet",Ico_IconSetId[IconSet]);
2019-01-12 03:00:59 +01:00
snprintf (Icon,sizeof (Icon),
"%s/%s/cog.svg",
Cfg_ICON_FOLDER_ICON_SETS,
Ico_IconSetId[IconSet]);
Ico_PutPrefIconLink (Icon,Ico_IconSetNames[IconSet]);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2016-12-23 22:19:03 +01:00
fprintf (Gbl.F.Out,"</div>");
2014-12-01 23:55:08 +01:00
}
2016-12-23 22:19:03 +01:00
fprintf (Gbl.F.Out,"</div>");
2017-06-10 21:38:10 +02:00
Box_EndBox ();
2016-11-07 12:59:44 +01:00
}
/*****************************************************************************/
/*************** Put contextual icons in icon-set preference *****************/
/*****************************************************************************/
static void Ico_PutIconsIconSet (void)
{
/***** Put icon to show a figure *****/
Gbl.Stat.FigureType = Sta_ICON_SETS;
Sta_PutIconToShowFigure ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/***************************** Change icon set *******************************/
/*****************************************************************************/
void Ico_ChangeIconSet (void)
{
/***** Get param with icon set *****/
Gbl.Prefs.IconSet = Ico_GetParamIconSet ();
2019-01-09 01:41:54 +01:00
snprintf (Gbl.Prefs.URLIconSet,sizeof (Gbl.Prefs.URLIconSet),
2018-10-18 02:02:32 +02:00
"%s/%s/%s/%s",
Cfg_URL_SWAD_PUBLIC,Cfg_FOLDER_PUBLIC_ICON,
Cfg_ICON_FOLDER_ICON_SETS,
Ico_IconSetId[Gbl.Prefs.IconSet]);
2014-12-01 23:55:08 +01:00
/***** Store icon set in database *****/
if (Gbl.Usrs.Me.Logged)
2018-11-03 12:16:40 +01:00
DB_QueryUPDATE ("can not update your preference about icon set",
"UPDATE usr_data SET IconSet='%s' WHERE UsrCod=%ld",
Ico_IconSetId[Gbl.Prefs.IconSet],
Gbl.Usrs.Me.UsrDat.UsrCod);
2014-12-01 23:55:08 +01:00
/***** Set preferences from current IP *****/
2015-03-14 17:39:04 +01:00
Pre_SetPrefsFromIP ();
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/*********************** Get parameter with icon set *************************/
/*****************************************************************************/
Ico_IconSet_t Ico_GetParamIconSet (void)
{
2017-01-28 15:58:46 +01:00
char IconSetId[Ico_MAX_BYTES_ICON_SET_ID + 1];
2014-12-01 23:55:08 +01:00
Ico_IconSet_t IconSet;
2015-11-21 20:23:28 +01:00
Par_GetParToText ("IconSet",IconSetId,Ico_MAX_BYTES_ICON_SET_ID);
2014-12-01 23:55:08 +01:00
for (IconSet = (Ico_IconSet_t) 0;
IconSet < Ico_NUM_ICON_SETS;
IconSet++)
if (!strcmp (IconSetId,Ico_IconSetId[IconSet]))
return IconSet;
2015-11-21 20:23:28 +01:00
return Ico_ICON_SET_DEFAULT;
2014-12-01 23:55:08 +01:00
}
/*****************************************************************************/
/************************* Get icon set from string **************************/
/*****************************************************************************/
Ico_IconSet_t Ico_GetIconSetFromStr (const char *Str)
{
Ico_IconSet_t IconSet;
for (IconSet = (Ico_IconSet_t) 0;
IconSet < Ico_NUM_ICON_SETS;
IconSet++)
if (!strcasecmp (Str,Ico_IconSetId[IconSet]))
return IconSet;
2015-11-21 20:23:28 +01:00
return Ico_ICON_SET_DEFAULT;
2014-12-01 23:55:08 +01:00
}
2017-06-11 19:13:28 +02:00
/*****************************************************************************/
2019-01-10 15:26:33 +01:00
/*** Show contextual icons to add, remove, edit, view, hide, unhide, print ***/
2017-06-11 19:13:28 +02:00
/*****************************************************************************/
2019-01-10 15:26:33 +01:00
void Ico_PutContextualIconToAdd (Act_Action_t NextAction,const char *Anchor,
void (*FuncParams) (),
const char *Txt)
{
2019-01-12 03:00:59 +01:00
Lay_PutContextualLinkOnlyIcon (NextAction,Anchor,FuncParams,
"plus.svg",
Txt);
2019-01-10 15:26:33 +01:00
}
2017-06-11 19:13:28 +02:00
void Ico_PutContextualIconToRemove (Act_Action_t NextAction,void (*FuncParams) ())
{
extern const char *Txt_Remove;
2019-01-12 03:00:59 +01:00
Lay_PutContextualLinkOnlyIcon (NextAction,NULL,FuncParams,
"trash.svg",
Txt_Remove);
2017-06-11 19:13:28 +02:00
}
void Ico_PutContextualIconToEdit (Act_Action_t NextAction,void (*FuncParams) ())
{
extern const char *Txt_Edit;
2019-01-12 03:00:59 +01:00
Lay_PutContextualLinkOnlyIcon (NextAction,NULL,FuncParams,
"pen.svg",
Txt_Edit);
2017-06-11 19:13:28 +02:00
}
2017-10-06 01:20:05 +02:00
void Ico_PutContextualIconToViewFiles (Act_Action_t NextAction,void (*FuncParams) ())
{
2017-10-08 17:35:02 +02:00
extern const char *Txt_Files;
2017-10-06 01:20:05 +02:00
2019-01-12 03:00:59 +01:00
Lay_PutContextualLinkOnlyIcon (NextAction,NULL,FuncParams,
"folder-open.svg",
Txt_Files);
2017-10-06 01:20:05 +02:00
}
2017-06-11 19:13:28 +02:00
void Ico_PutContextualIconToView (Act_Action_t NextAction,void (*FuncParams) ())
{
extern const char *Txt_View;
2019-01-12 03:00:59 +01:00
Lay_PutContextualLinkOnlyIcon (NextAction,NULL,FuncParams,
"eye.svg",
Txt_View);
2017-06-11 19:13:28 +02:00
}
void Ico_PutContextualIconToHide (Act_Action_t NextAction,void (*FuncParams) ())
{
extern const char *Txt_Hide;
2019-01-12 03:00:59 +01:00
Lay_PutContextualLinkOnlyIcon (NextAction,NULL,FuncParams,
"eye.svg",
Txt_Hide);
2017-06-11 19:13:28 +02:00
}
void Ico_PutContextualIconToUnhide (Act_Action_t NextAction,void (*FuncParams) ())
{
extern const char *Txt_Show;
2019-01-12 03:00:59 +01:00
Lay_PutContextualLinkOnlyIcon (NextAction,NULL,FuncParams,
"eye-slash.svg",
Txt_Show);
2017-06-11 19:13:28 +02:00
}
void Ico_PutContextualIconToPrint (Act_Action_t NextAction,void (*FuncParams) ())
{
extern const char *Txt_Print;
2019-01-12 03:00:59 +01:00
Lay_PutContextualLinkOnlyIcon (NextAction,NULL,FuncParams,
"print.svg",
Txt_Print);
}
/*****************************************************************************/
/**************** Show an icon inside a div (without text) *******************/
/*****************************************************************************/
void Ico_PutDivIcon (const char *DivClass,const char *Icon,const char *Title)
{
fprintf (Gbl.F.Out,"<div class=\"%s\">"
"<img src=\"%s/%s\""
" alt=\"%s\" title=\"%s\""
" class=\"CONTEXT_ICO_16x16\" />"
"</div>",
DivClass,
Gbl.Prefs.URLIcons,Icon,
Title,Title);
}
/*****************************************************************************/
/*********** 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,"<div class=\"%s\">"
"<input type=\"image\""
" src=\"%s/%s\""
" alt=\"%s\" title=\"%s\""
" class=\"CONTEXT_OPT ICO_HIGHLIGHT CONTEXT_ICO_16x16\" />"
"</div>",
DivClass,
Gbl.Prefs.URLIcons,Icon,
Title,Title);
2017-06-11 19:13:28 +02:00
}
/*****************************************************************************/
/****************** Show an icon with a link (without text) ******************/
/*****************************************************************************/
2019-01-12 03:00:59 +01:00
void Ico_PutIconLink (const char *Icon,const char *Title)
2017-06-11 19:13:28 +02:00
{
2019-01-12 03:00:59 +01:00
fprintf (Gbl.F.Out,"<input type=\"image\" src=\"%s/%s\""
" alt=\"%s\" title=\"%s\""
" class=\"CONTEXT_OPT ICO_HIGHLIGHT CONTEXT_ICO_16x16\" />",
Gbl.Prefs.URLIcons,Icon,
Title,Title);
}
/*****************************************************************************/
/************************** Show a preference selector ***********************/
/*****************************************************************************/
void Ico_PutPrefIconLink (const char *Icon,const char *Title)
{
fprintf (Gbl.F.Out,"<input type=\"image\" src=\"%s/%s\""
" alt=\"%s\" title=\"%s\""
" class=\"ICO_HIGHLIGHT ICOx25\""
" style=\"margin:0 auto;\"\" />",
Gbl.Prefs.URLIcons,Icon,
Title,Title);
2017-06-11 19:13:28 +02:00
}
2017-09-11 09:05:26 +02:00
/*****************************************************************************/
2019-01-08 13:13:04 +01:00
/********************** Put an inactive/disabled icon ************************/
2017-09-11 09:05:26 +02:00
/*****************************************************************************/
2019-01-08 13:13:04 +01:00
void Ico_PutIconOff (const char *Icon,const char *Alt)
2017-09-11 09:05:26 +02:00
{
fprintf (Gbl.F.Out,"<img src=\"%s/%s\" alt=\"%s\" title=\"%s\""
2019-01-12 03:00:59 +01:00
" class=\"CONTEXT_OPT ICO_HIDDEN CONTEXT_ICO_16x16\" />",
2019-01-09 01:41:54 +01:00
Gbl.Prefs.URLIcons,Icon,Alt,Alt);
2017-09-11 09:05:26 +02:00
}
2017-06-11 19:13:28 +02:00
/*****************************************************************************/
/**************** Put a icon with a text to submit a form ********************/
/*****************************************************************************/
void Ico_PutIconWithText (const char *Icon,const char *Alt,const char *Text)
{
/***** Print icon and optional text *****/
fprintf (Gbl.F.Out,"<div class=\"CONTEXT_OPT ICO_HIGHLIGHT\">"
"<img src=\"%s/%s\" alt=\"%s\" title=\"%s\""
2019-01-12 03:00:59 +01:00
" class=\"CONTEXT_ICO_x16\" />",
2019-01-09 01:41:54 +01:00
Gbl.Prefs.URLIcons,Icon,Alt,Text ? Text :
2017-09-11 09:05:26 +02:00
Alt);
2017-06-11 19:13:28 +02:00
if (Text)
if (Text[0])
fprintf (Gbl.F.Out,"&nbsp;%s",Text);
fprintf (Gbl.F.Out,"</div>");
}
/*****************************************************************************/
/********** Put a icon to submit a form. **********/
/********** When clicked, the icon will be replaced by an animation **********/
/*****************************************************************************/
void Ico_PutCalculateIcon (const char *Alt)
{
fprintf (Gbl.F.Out,"<div class=\"CONTEXT_OPT ICO_HIGHLIGHT\">"
"<img id=\"update_%d\" src=\"%s/recycle16x16.gif\"" // TODO: change name and resolution to refresh64x64.png
" alt=\"%s\" title=\"%s\""
2019-01-12 03:00:59 +01:00
" class=\"CONTEXT_ICO_16x16\" />"
2017-06-11 19:13:28 +02:00
"<img id=\"updating_%d\" src=\"%s/working16x16.gif\"" // TODO: change name and resolution to refreshing64x64.gif
" alt=\"%s\" title=\"%s\""
2019-01-12 03:00:59 +01:00
" class=\"CONTEXT_ICO_16x16\" style=\"display:none;\" />" // Animated icon hidden
2017-06-11 19:13:28 +02:00
"</div>"
"</a>",
2019-01-09 01:41:54 +01:00
Gbl.Form.Num,Gbl.Prefs.URLIcons,Alt,Alt,
Gbl.Form.Num,Gbl.Prefs.URLIcons,Alt,Alt);
2017-06-11 19:13:28 +02:00
}
/*****************************************************************************/
/********** 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 *Alt,const char *Text)
{
fprintf (Gbl.F.Out,"<div class=\"ICO_HIGHLIGHT\""
" style=\"margin:0 6px 0 0; display:inline;\">"
"<img id=\"update_%d\" src=\"%s/recycle16x16.gif\""
" alt=\"%s\" title=\"%s\""
" class=\"ICO20x20\" />"
"<img id=\"updating_%d\" src=\"%s/working16x16.gif\""
" alt=\"%s\" title=\"%s\""
" class=\"ICO20x20\" style=\"display:none;\" />" // Animated icon hidden
"&nbsp;%s"
"</div>"
"</a>",
2019-01-09 01:41:54 +01:00
Gbl.Form.Num,Gbl.Prefs.URLIcons,Alt,Text,
Gbl.Form.Num,Gbl.Prefs.URLIcons,Alt,Text,
2017-06-11 19:13:28 +02:00
Text);
}
/*****************************************************************************/
/******** Put a disabled icon indicating that removal is not allowed *********/
/*****************************************************************************/
void Ico_PutIconRemovalNotAllowed (void)
{
extern const char *Txt_Removal_not_allowed;
2019-01-08 13:13:04 +01:00
Ico_PutIconOff ("trash.svg",Txt_Removal_not_allowed);
2017-06-11 19:13:28 +02:00
}
/*****************************************************************************/
2019-01-11 02:55:01 +01:00
/************************ Put an icon to remove ******************************/
2017-06-11 19:13:28 +02:00
/*****************************************************************************/
void Ico_PutIconRemove (void)
{
extern const char *Txt_Remove;
2019-01-12 03:00:59 +01:00
Ico_PutIconLink ("trash.svg",Txt_Remove);
2017-06-11 19:13:28 +02:00
}
2019-01-11 02:55:01 +01:00
/*****************************************************************************/
/*************************** Put an icon to cut ******************************/
/*****************************************************************************/
void Ico_PutIconCut (void)
{
extern const char *Txt_Cut;
2019-01-12 03:00:59 +01:00
Ico_PutIconLink ("cut.svg",Txt_Cut);
2019-01-11 02:55:01 +01:00
}
/*****************************************************************************/
/************************** Put an icon to paste *****************************/
/*****************************************************************************/
void Ico_PutIconPaste (void)
{
extern const char *Txt_Paste;
2019-01-12 03:00:59 +01:00
Ico_PutIconLink ("paste.svg",Txt_Paste);
2019-01-11 02:55:01 +01:00
}