swad-core/swad_icon.c

495 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 ***********************************/
/*****************************************************************************/
#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"
2019-10-23 20:07:56 +02:00
#include "swad_HTML.h"
2014-12-01 23:55:08 +01:00
#include "swad_icon.h"
#include "swad_layout.h"
#include "swad_parameter.h"
2019-03-26 11:53:21 +01:00
#include "swad_setting.h"
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
/************** External global variables from others modules ****************/
/*****************************************************************************/
extern struct Globals Gbl;
/*****************************************************************************/
2019-11-21 16:47:07 +01:00
/******************************** Public constants ***************************/
2014-12-01 23:55:08 +01:00
/*****************************************************************************/
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] =
{
2019-11-21 16:47:07 +01:00
[Ico_ICON_SET_AWESOME] = "awesome",
[Ico_ICON_SET_NUVOLA ] = "nuvola",
2014-12-01 23:55:08 +01:00
};
const char *Ico_IconSetNames[Ico_NUM_ICON_SETS] =
{
2019-11-21 16:47:07 +01:00
[Ico_ICON_SET_AWESOME] = "Awesome",
[Ico_ICON_SET_NUVOLA ] = "Nuvola",
2014-12-01 23:55:08 +01:00
};
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),
2019-03-20 01:36:36 +01:00
"%s/%s/%s",
Cfg_PATH_ICON_SETS_PUBLIC,
Ico_IconSetId[Gbl.Prefs.IconSet],
2019-01-09 01:41:54 +01:00
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)
{
2019-03-26 11:53:21 +01:00
extern const char *Hlp_PROFILE_Settings_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
2019-10-25 22:48:34 +02:00
Box_BoxBegin (NULL,Txt_Icons,Ico_PutIconsIconSet,
2019-03-26 11:53:21 +01:00
Hlp_PROFILE_Settings_icons,Box_NOT_CLOSABLE);
Set_StartSettingsHead ();
Set_StartOneSettingSelector ();
2014-12-01 23:55:08 +01:00
for (IconSet = (Ico_IconSet_t) 0;
IconSet < Ico_NUM_ICON_SETS;
IconSet++)
{
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"%s\"",
IconSet == Gbl.Prefs.IconSet ? "PREF_ON" :
"PREF_OFF");
2018-11-09 20:47:39 +01:00
Frm_StartForm (ActChgIco);
2019-11-03 13:19:32 +01:00
Par_PutHiddenParamString (NULL,"IconSet",Ico_IconSetId[IconSet]);
2019-01-12 03:00:59 +01:00
snprintf (Icon,sizeof (Icon),
"%s/%s/cog.svg",
2019-03-20 01:36:36 +01:00
Cfg_ICON_FOLDER_SETS,
2019-01-12 03:00:59 +01:00
Ico_IconSetId[IconSet]);
2019-03-26 11:53:21 +01:00
Ico_PutSettingIconLink (Icon,Ico_IconSetNames[IconSet]);
2018-11-09 20:47:39 +01:00
Frm_EndForm ();
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2014-12-01 23:55:08 +01:00
}
2019-03-26 11:53:21 +01:00
Set_EndOneSettingSelector ();
Set_EndSettingsHead ();
2019-10-25 22:48:34 +02:00
Box_BoxEnd ();
2016-11-07 12:59:44 +01:00
}
/*****************************************************************************/
2019-03-26 11:53:21 +01:00
/***************** Put contextual icons in icon-set setting *******************/
2016-11-07 12:59:44 +01:00
/*****************************************************************************/
static void Ico_PutIconsIconSet (void)
{
/***** Put icon to show a figure *****/
2019-02-12 14:46:14 +01:00
Gbl.Figures.FigureType = Fig_ICON_SETS;
Fig_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),
2019-03-20 01:36:36 +01:00
"%s/%s",
Cfg_URL_ICON_SETS_PUBLIC,
2018-10-18 02:02:32 +02:00
Ico_IconSetId[Gbl.Prefs.IconSet]);
2014-12-01 23:55:08 +01:00
/***** Store icon set in database *****/
if (Gbl.Usrs.Me.Logged)
2019-03-26 11:53:21 +01:00
DB_QueryUPDATE ("can not update your setting about icon set",
2018-11-03 12:16:40 +01:00
"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
2019-03-26 11:53:21 +01:00
/***** Set settings from current IP *****/
Set_SetSettingsFromIP ();
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,
2019-04-11 14:45:31 +02:00
void (*FuncParams) (void),
2019-01-10 15:26:33 +01:00
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
}
2019-04-11 14:45:31 +02:00
void Ico_PutContextualIconToRemove (Act_Action_t NextAction,void (*FuncParams) (void))
2017-06-11 19:13:28 +02:00
{
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
}
2019-04-11 14:45:31 +02:00
void Ico_PutContextualIconToEdit (Act_Action_t NextAction,void (*FuncParams) (void))
2017-06-11 19:13:28 +02:00
{
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
}
2019-04-11 14:45:31 +02:00
void Ico_PutContextualIconToViewFiles (Act_Action_t NextAction,void (*FuncParams) (void))
2017-10-06 01:20:05 +02:00
{
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
}
2019-04-11 14:45:31 +02:00
void Ico_PutContextualIconToView (Act_Action_t NextAction,void (*FuncParams) (void))
2017-06-11 19:13:28 +02:00
{
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
}
2019-10-25 01:36:42 +02:00
void Ico_PutContextualIconToConfigure (Act_Action_t NextAction,void (*FuncParams) (void))
{
extern const char *Txt_Configure;
Lay_PutContextualLinkOnlyIcon (NextAction,NULL,FuncParams,
"cog.svg",
Txt_Configure);
}
2019-04-11 14:45:31 +02:00
void Ico_PutContextualIconToHide (Act_Action_t NextAction,const char *Anchor,void (*FuncParams) (void))
2017-06-11 19:13:28 +02:00
{
extern const char *Txt_Hide;
2019-03-25 19:05:10 +01:00
Lay_PutContextualLinkOnlyIcon (NextAction,Anchor,FuncParams,
2019-01-12 03:00:59 +01:00
"eye.svg",
Txt_Hide);
2017-06-11 19:13:28 +02:00
}
2019-04-11 14:45:31 +02:00
void Ico_PutContextualIconToUnhide (Act_Action_t NextAction,const char *Anchor,void (*FuncParams) (void))
2017-06-11 19:13:28 +02:00
{
extern const char *Txt_Show;
2019-03-25 19:05:10 +01:00
Lay_PutContextualLinkOnlyIcon (NextAction,Anchor,FuncParams,
2019-01-12 03:00:59 +01:00
"eye-slash.svg",
Txt_Show);
2017-06-11 19:13:28 +02:00
}
2019-04-11 14:45:31 +02:00
void Ico_PutContextualIconToPrint (Act_Action_t NextAction,void (*FuncParams) (void))
2017-06-11 19:13:28 +02:00
{
extern const char *Txt_Print;
2019-01-12 03:00:59 +01:00
Lay_PutContextualLinkOnlyIcon (NextAction,NULL,FuncParams,
"print.svg",
Txt_Print);
}
2019-04-21 23:27:04 +02:00
void Ico_PutContextualIconToCopy (Act_Action_t NextAction,void (*FuncParams) (void))
{
extern const char *Txt_Copy;
Lay_PutContextualLinkOnlyIcon (NextAction,NULL,FuncParams,
"copy.svg",
Txt_Copy);
}
2019-04-21 23:53:21 +02:00
void Ico_PutContextualIconToPaste (Act_Action_t NextAction,void (*FuncParams) (void))
{
extern const char *Txt_Paste;
Lay_PutContextualLinkOnlyIcon (NextAction,NULL,FuncParams,
"paste.svg",
Txt_Paste);
}
2019-04-22 01:06:48 +02:00
void Ico_PutContextualIconToCreateInFolder (Act_Action_t NextAction,void (*FuncParams) (void),bool Open)
{
extern const char *Txt_Upload_file_or_create_folder;
Lay_PutContextualLinkOnlyIcon (NextAction,NULL,FuncParams,
Open ? "folder-open-yellow-plus.png" :
"folder-yellow-plus.png",
Txt_Upload_file_or_create_folder);
}
2019-04-22 14:50:31 +02:00
void Ico_PutContextualIconToZIP (Act_Action_t NextAction,void (*FuncParams) (void))
{
extern const char *Txt_Create_ZIP_file;
Lay_PutContextualLinkOnlyIcon (NextAction,NULL,FuncParams,
"download.svg",
Txt_Create_ZIP_file);
}
2019-01-12 03:00:59 +01:00
/*****************************************************************************/
/**************** Show an icon inside a div (without text) *******************/
/*****************************************************************************/
void Ico_PutDivIcon (const char *DivClass,const char *Icon,const char *Title)
{
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"%s\"",DivClass);
2019-10-29 09:01:05 +01:00
Ico_PutIcon (Icon,Title,"CONTEXT_ICO_16x16");
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-01-12 03:00:59 +01:00
}
/*****************************************************************************/
/*********** Show an icon with a link inside a div (without text) ************/
/*****************************************************************************/
void Ico_PutDivIconLink (const char *DivClass,const char *Icon,const char *Title)
{
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"%s\"",DivClass);
2019-01-12 19:46:33 +01:00
Ico_PutIconLink (Icon,Title);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
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-11-11 15:46:54 +01:00
HTM_INPUT_IMAGE (Cfg_URL_ICON_PUBLIC,Icon,Title,"CONTEXT_OPT ICO_HIGHLIGHT CONTEXT_ICO_16x16");
2019-01-12 03:00:59 +01:00
}
2019-01-12 19:46:33 +01:00
/*****************************************************************************/
/******************* Show an icon with a link (with text) ********************/
/*****************************************************************************/
void Ico_PutIconTextLink (const char *Icon,const char *Text)
{
/***** Print icon and optional text *****/
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"CONTEXT_OPT ICO_HIGHLIGHT\"");
2019-10-29 09:01:05 +01:00
Ico_PutIcon (Icon,Text,"CONTEXT_ICO_x16");
2019-11-11 10:59:24 +01:00
HTM_TxtF ("&nbsp;%s",Text);
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2019-01-12 19:46:33 +01:00
}
2019-01-12 03:00:59 +01:00
/*****************************************************************************/
2019-03-26 11:53:21 +01:00
/**************************** Show a setting selector *************************/
2019-01-12 03:00:59 +01:00
/*****************************************************************************/
2019-03-26 11:53:21 +01:00
void Ico_PutSettingIconLink (const char *Icon,const char *Title)
2019-01-12 03:00:59 +01:00
{
2019-11-11 15:46:54 +01:00
HTM_INPUT_IMAGE (Cfg_URL_ICON_PUBLIC,Icon,Title,"ICO_HIGHLIGHT ICOx20");
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-12 19:46:33 +01:00
void Ico_PutIconOff (const char *Icon,const char *Title)
2017-09-11 09:05:26 +02:00
{
2019-10-29 09:01:05 +01:00
Ico_PutIcon (Icon,Title,"CONTEXT_OPT ICO_HIDDEN CONTEXT_ICO_16x16");
}
/*****************************************************************************/
/******************************* Put an icon *********************************/
/*****************************************************************************/
void Ico_PutIcon (const char *Icon,const char *Title,const char *Class)
{
2019-10-30 00:42:01 +01:00
HTM_IMG (Cfg_URL_ICON_PUBLIC,Icon,Title,
2019-10-30 22:31:03 +01:00
"class=\"%s\"",Class);
2017-06-11 19:13:28 +02:00
}
/*****************************************************************************/
/********** Put a icon to submit a form. **********/
/********** When clicked, the icon will be replaced by an animation **********/
/*****************************************************************************/
2019-01-12 19:46:33 +01:00
void Ico_PutCalculateIcon (const char *Title)
2017-06-11 19:13:28 +02:00
{
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"CONTEXT_OPT ICO_HIGHLIGHT\"");
2019-10-28 21:24:07 +01:00
2019-10-30 22:31:03 +01:00
HTM_IMG (Cfg_URL_ICON_PUBLIC,"recycle16x16.gif",Title, // TODO: change name and resolution to refresh64x64.png
"class=\"CONTEXT_ICO_16x16\""
" id=\"update_%d\"",Gbl.Form.Num);
2019-10-28 21:24:07 +01:00
2019-10-30 22:31:03 +01:00
HTM_IMG (Cfg_URL_ICON_PUBLIC,"working16x16.gif",Title, // TODO: change name and resolution to refreshing64x64.gif
"class=\"CONTEXT_ICO_16x16\" style=\"display:none;\"" // Animated icon hidden
" id=\"updating_%d\"",Gbl.Form.Num);
2019-10-28 21:24:07 +01:00
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
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 **********/
/*****************************************************************************/
2019-01-12 19:46:33 +01:00
void Ico_PutCalculateIconWithText (const char *Text)
2017-06-11 19:13:28 +02:00
{
2019-10-24 00:04:40 +02:00
HTM_DIV_Begin ("class=\"ICO_HIGHLIGHT\" style=\"margin:0 6px 0 0; display:inline;\"");
2019-10-28 21:24:07 +01:00
2019-10-30 22:31:03 +01:00
HTM_IMG (Cfg_URL_ICON_PUBLIC,"recycle16x16.gif",Text,
"class=\"ICO20x20\""
" id=\"update_%d\"",Gbl.Form.Num);
2019-10-28 21:24:07 +01:00
2019-10-30 22:31:03 +01:00
HTM_IMG (Cfg_URL_ICON_PUBLIC,"working16x16.gif",Text,
"class=\"ICO20x20\" style=\"display:none;\"" // Animated icon hidden
" id=\"updating_%d\"",Gbl.Form.Num);
2019-10-28 21:24:07 +01:00
2019-11-11 10:59:24 +01:00
HTM_TxtF ("&nbsp;%s",Text);
2019-10-28 21:24:07 +01:00
2019-10-23 20:07:56 +02:00
HTM_DIV_End ();
2017-06-11 19:13:28 +02:00
}
/*****************************************************************************/
/******** 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
}