swad-core/swad_icon.c

179 lines
6.2 KiB
C
Raw Normal View History

2014-12-01 23:55:08 +01:00
// swad_icon.c: icon selection
/*
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.
2017-01-13 01:51:23 +01:00
Copyright (C) 1999-2017 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 <stdio.h> // For fprintf, etc.
#include <string.h>
#include "swad_config.h"
#include "swad_database.h"
#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);
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;
2016-11-13 01:21:35 +01:00
Lay_StartRoundFrame (NULL,Txt_Icons,
Ico_PutIconsIconSet,Hlp_PROFILE_Preferences_icons);
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");
2014-12-01 23:55:08 +01:00
Act_FormStart (ActChgIco);
Par_PutHiddenParamString ("IconSet",Ico_IconSetId[IconSet]);
2015-01-13 14:19:08 +01:00
fprintf (Gbl.F.Out,"<input type=\"image\" src=\"%s/%s/%s/%s/heart64x64.gif\""
2016-12-24 13:46:29 +01:00
" alt=\"%s\" title=\"%s\" class=\"ICO40x40B\" />",
2014-12-01 23:55:08 +01:00
Gbl.Prefs.IconsURL,
Cfg_ICON_FOLDER_ICON_SETS,
Ico_IconSetId[IconSet],
2015-01-13 14:19:08 +01:00
Cfg_ICON_ACTION,
2014-12-01 23:55:08 +01:00
Ico_IconSetNames[IconSet],
Ico_IconSetNames[IconSet]);
2015-03-13 00:16:02 +01:00
Act_FormEnd ();
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>");
2016-11-07 12:59:44 +01:00
Lay_EndRoundFrame ();
}
/*****************************************************************************/
/*************** 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)
{
char Query[512];
/***** Get param with icon set *****/
Gbl.Prefs.IconSet = Ico_GetParamIconSet ();
sprintf (Gbl.Prefs.PathIconSet,"%s/%s/%s",
Gbl.Prefs.IconsURL,Cfg_ICON_FOLDER_ICON_SETS,
Ico_IconSetId[Gbl.Prefs.IconSet]);
/***** Store icon set in database *****/
if (Gbl.Usrs.Me.Logged)
{
sprintf (Query,"UPDATE usr_data SET IconSet='%s' WHERE UsrCod='%ld'",
Ico_IconSetId[Gbl.Prefs.IconSet],
Gbl.Usrs.Me.UsrDat.UsrCod);
DB_QueryUPDATE (Query,"can not update your preference about icon set");
}
/***** 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)
{
2015-11-21 20:23:28 +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
}