home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Enigma Amiga Life 109
/
EnigmaAmiga109CD.iso
/
software
/
on-line
/
amster
/
src
/
prefs.c
< prev
next >
Wrap
C/C++ Source or Header
|
2000-01-21
|
10KB
|
360 lines
/*
** Preferences
*/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mui.h"
#include <libraries/asl.h>
#include "gui.h"
#include "search.h"
#include "prefs.h"
#include "info.h"
#include "amster_Cat.h"
ULONG prf_new(struct IClass *cl, Object *obj, struct opSet *msg);
void _prf_set(struct prfdata *data);
void _prf_use(struct prfdata *data);
/* defaults for preferences */
char *pref_mainserver="server.napster.com:8875";
char *pref_server=NULL;
char *pref_napvers="V2.0 BETA 3";
char *pref_user="luser42";
char *pref_pass="pussy";
char *pref_email="anon@napster.com";
char *pref_dlpath="ram:";
int pref_link=3;
int pref_regflag=1;
int pref_clrlist=0;
int pref_autocon=0;
int pref_fullpath=0;
MUIF prf_dispatch(REG(a0) struct IClass *cl,REG(a2) Object *obj,REG(a1) Msg msg)
{
switch(msg->MethodID) {
case OM_NEW: return(prf_new(cl,obj,(APTR)msg));
case PRF_UPDATE:
{
if(gui_napon) nap_updateaccount();
else MUI_Request(gui->app, gui->swin, 0L, (char *)MSG_ERROR_TITLE, (char *)MSG_OK_GAD, (char *)MSG_ERROR_UPDATEEMAIL);
return(NULL);
}
case PRF_OPEN:
{
struct prfdata *data = INST_DATA(cl,obj);
_prf_set(data);
set(obj,MUIA_Window_Open,TRUE);
return(NULL);
}
case PRF_USE:
{
struct prfdata *data = INST_DATA(cl,obj);
_prf_use(data);
set(obj,MUIA_Window_Open,FALSE);
return(NULL);
}
case PRF_SAVE:
{
struct prfdata *data = INST_DATA(cl,obj);
_prf_use(data);
set(obj,MUIA_Window_Open,FALSE);
prf_save();
return(NULL);
}
case PRF_CANCEL:
set(obj,MUIA_Window_Open,FALSE);
return(NULL);
}
return(DoSuperMethodA(cl,obj,msg));
}
ULONG prf_new(struct IClass *cl, Object *obj, struct opSet *msg)
{
struct prfdata *data;
Object *idstr,*pwstr,*emailstr,*emailbut,*pathstr,*links,*clrtog,*msstr,*sstr,*vstr,*savbut,*usebut,*canbut,*autotog,*fptog;
static char *PrefsPages[] = {
(char *)_MSG_GROUP_USER,
(char *)_MSG_GROUP_OPTIONS,
(char *)_MSG_GROUP_ADVANCED,
NULL
};
localize_array(PrefsPages);
if (obj = (Object *)DoSuperNew(cl,obj,
MUIA_HelpNode, "config",
WindowContents, VGroup,
Child, RegisterGroup(PrefsPages),
Child, ColGroup(2),
MUIA_HelpNode, "conf-user",
Child, Label2(MSG_USERNAME),
Child, idstr = StringObject,
StringFrame,
MUIA_String_AdvanceOnCR, TRUE,
MUIA_CycleChain, 1,
End,
Child, Label2(MSG_PASSWORD),
Child, pwstr = StringObject,
StringFrame,
MUIA_String_AdvanceOnCR, TRUE,
MUIA_String_Secret, TRUE,
MUIA_CycleChain, 1,
End,
Child, Label2(MSG_EMAIL),
Child, HGroup,
Child, emailstr = StringObject,
StringFrame,
MUIA_String_AdvanceOnCR, TRUE,
MUIA_CycleChain, 1,
End,
Child, emailbut = SimpleButton(MSG_UPDATE_GAD),
End,
Child, Label2(MSG_CONNECTION),
Child, links = CycleObject,
MUIA_Cycle_Active, pref_link,
MUIA_Cycle_Entries, nap_linktype,
End,
Child, Label2(MSG_DOWNLOADPATH),
Child, pathstr = PopaslObject,
MUIA_Popstring_String, StringObject,
StringFrame,
MUIA_String_MaxLen, 256,
MUIA_CycleChain, 1,
End,
MUIA_Popstring_Button, PopButton(MUII_PopFile),
MUIA_Popasl_Type, ASL_FileRequest,
ASLFR_TitleText, MSG_DOWNLOADPATH_REQ,
ASLFR_DrawersOnly, TRUE,
End,
End,
Child, ColGroup(2),
MUIA_HelpNode, "conf-opts",
Child, clrtog = ImageObject,
MUIA_HorizWeight, 10,
ButtonFrame,
MUIA_Background, MUII_ButtonBack,
MUIA_InputMode, MUIV_InputMode_Toggle,
MUIA_ShowSelState, FALSE,
MUIA_CycleChain, 1,
MUIA_Image_Spec, "6:15",
End,
Child, TextObject,
MUIA_HorizWeight, 90,
MUIA_Text_Contents, MSG_CLEARLIST,
End,
Child, autotog = ImageObject,
MUIA_HorizWeight, 10,
ButtonFrame,
MUIA_Background, MUII_ButtonBack,
MUIA_InputMode, MUIV_InputMode_Toggle,
MUIA_ShowSelState, FALSE,
MUIA_CycleChain, 1,
MUIA_Image_Spec, "6:15",
End,
Child, TextObject,
MUIA_HorizWeight, 90,
MUIA_Text_Contents, MSG_AUTOCONNECT,
End,
Child, fptog = ImageObject,
MUIA_HorizWeight, 10,
ButtonFrame,
MUIA_Background, MUII_ButtonBack,
MUIA_InputMode, MUIV_InputMode_Toggle,
MUIA_ShowSelState, FALSE,
MUIA_CycleChain, 1,
MUIA_Image_Spec, "6:15",
End,
Child, TextObject,
MUIA_HorizWeight, 90,
MUIA_Text_Contents, MSG_FULLPATHS,
End,
End,
Child, ColGroup(2),
MUIA_HelpNode, "conf-adv",
Child, Label2(MSG_MAINSERVER),
Child, msstr = StringObject,
StringFrame,
MUIA_String_AdvanceOnCR, TRUE,
MUIA_CycleChain, 1,
MUIA_ShortHelp, MSG_MAINSERVER_HELP,
End,
Child, Label2(MSG_MP3SERVER),
Child, sstr = StringObject,
StringFrame,
MUIA_String_AdvanceOnCR, TRUE,
MUIA_CycleChain, 1,
MUIA_ShortHelp, MSG_MP3SERVER_HELP,
End,
Child, Label2(MSG_VERSION),
Child, vstr = StringObject,
StringFrame,
MUIA_CycleChain, 1,
End,
End,
End,
Child, HGroup,
Child, savbut = SimpleButton(MSG_SAVE_GAD),
Child, usebut = SimpleButton(MSG_USE_GAD),
Child, canbut = SimpleButton(MSG_CANCEL_GAD),
End,
End,
TAG_MORE, msg->ops_AttrList))
{
data = INST_DATA(cl,obj);
data->idstr = idstr;
data->pwstr = pwstr;
data->emailstr = emailstr;
data->pathstr = pathstr;
data->links = links;
data->clrtog = clrtog;
data->autotog = autotog;
data->fptog = fptog;
data->msstr = msstr;
data->sstr = sstr;
data->vstr = vstr;
set(obj,MUIA_Window_ID,MAKE_ID('S','E','T','T'));
set(obj,MUIA_Window_Title,MSG_SETTINGS_TITLE),
DoMethod(emailbut,MUIM_Notify,MUIA_Pressed,FALSE,obj,1,PRF_UPDATE);
DoMethod(canbut,MUIM_Notify,MUIA_Pressed,FALSE,obj,1,PRF_CANCEL);
DoMethod(obj,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,obj,1,PRF_CANCEL);
DoMethod(usebut,MUIM_Notify,MUIA_Pressed,FALSE,obj,1,PRF_USE);
DoMethod(savbut,MUIM_Notify,MUIA_Pressed,FALSE,obj,1,PRF_SAVE);
return((ULONG)obj);
}
return(0);
}
void _prf_set(struct prfdata *data)
{
set(data->msstr,MUIA_String_Contents,pref_mainserver);
set(data->sstr,MUIA_String_Contents,pref_server);
set(data->vstr,MUIA_String_Contents,pref_napvers);
set(data->idstr,MUIA_String_Contents,pref_user);
set(data->pwstr,MUIA_String_Contents,pref_pass);
set(data->emailstr,MUIA_String_Contents,pref_email);
set(data->pathstr,MUIA_String_Contents,pref_dlpath);
set(data->links,MUIA_Cycle_Active,pref_link);
set(data->clrtog,MUIA_Selected,pref_clrlist);
set(data->autotog,MUIA_Selected,pref_autocon);
set(data->fptog,MUIA_Selected,pref_fullpath);
}
void _prf_use(struct prfdata *data)
{
u_long tmp;
int oldfp;
GetAttr(MUIA_String_Acknowledge,data->msstr,&tmp);
if (((char*)tmp)[0]==0) pref_mainserver=NULL; else pref_mainserver=strdup((char*)tmp);
GetAttr(MUIA_String_Acknowledge,data->sstr,&tmp);
if (((char*)tmp)[0]==0) pref_server=NULL; else pref_server=strdup((char*)tmp);
GetAttr(MUIA_String_Acknowledge,data->vstr,&tmp);
if (((char*)tmp)[0]==0) pref_napvers=NULL; else pref_napvers=strdup((char*)tmp);
GetAttr(MUIA_String_Acknowledge,data->idstr,&tmp);
if (((char*)tmp)[0]==0) pref_user=NULL; else pref_user=strdup((char*)tmp);
GetAttr(MUIA_String_Acknowledge,data->pwstr,&tmp);
if (((char*)tmp)[0]==0) pref_pass=NULL; else pref_pass=strdup((char*)tmp);
GetAttr(MUIA_String_Acknowledge,data->emailstr,&tmp);
if (((char*)tmp)[0]==0) pref_email=NULL; else pref_email=strdup((char*)tmp);
GetAttr(MUIA_String_Acknowledge,data->pathstr,&tmp);
if (((char*)tmp)[0]==0) pref_dlpath=NULL; else pref_dlpath=strdup((char*)tmp);
GetAttr(MUIA_Cycle_Active,data->links,&tmp);
pref_link = tmp;
GetAttr(MUIA_Selected,data->clrtog,&tmp);
pref_clrlist = tmp;
GetAttr(MUIA_Selected,data->autotog,&tmp);
pref_autocon = tmp;
oldfp = pref_fullpath;
GetAttr(MUIA_Selected,data->fptog,&tmp);
pref_fullpath = tmp;
if(pref_fullpath!=oldfp) DoMethod(gui->searchpanel,SEARCH_REFRESH);
}
void prf_load(void)
{
FILE *f;
char tmp[100],*s;
f=fopen(AMSTER_PREFS,"r");
if(f==0) return;
while(fgets(tmp,sizeof(tmp),f)) {
s = strtok(tmp," ");
if(!s) {
continue;
} else if(strcmp(s,"mainserver")==0) {
if(s=strtok(NULL,"\n")) pref_mainserver=strdup(s);
} else if(strcmp(s,"server")==0) {
if(s=strtok(NULL,"\n")) pref_server=strdup(s);
} else if(strcmp(s,"napvers")==0) {
if(s=strtok(NULL,"\n")) pref_napvers=strdup(s);
} else if(strcmp(s,"user")==0) {
if(s=strtok(NULL,"\n")) pref_user=strdup(s);
} else if(strcmp(s,"pass")==0) {
if(s=strtok(NULL,"\n")) pref_pass=strdup(s);
} else if(strcmp(s,"email")==0) {
if(s=strtok(NULL,"\n")) pref_email=strdup(s);
} else if(strcmp(s,"dlpath")==0) {
if(s=strtok(NULL,"\n")) pref_dlpath=strdup(s);
} else if(strcmp(s,"linktype")==0) {
if(s=strtok(NULL,"\n")) pref_link=atoi(s);
} else if(strcmp(s,"optclrlist")==0) {
pref_clrlist = 1;
} else if(strcmp(s,"autoconnect")==0) {
pref_autocon = 1;
} else if(strcmp(s,"fullpath")==0) {
pref_fullpath = 1;
}
}
fclose(f);
}
void prf_save(void)
{
FILE *f;
f=fopen(AMSTER_PREFS,"w");
if(f==0) {
gui_debug((char *)MSG_ERROR_SAVE);
return;
}
if(pref_mainserver) fprintf(f,"mainserver %s\n",pref_mainserver);
if(pref_server) fprintf(f,"server %s\n",pref_server);
if(pref_napvers) fprintf(f,"napvers %s\n",pref_napvers);
if(pref_user) fprintf(f,"user %s\n",pref_user);
if(pref_pass) fprintf(f,"pass %s\n",pref_pass);
if(pref_email) fprintf(f,"email %s\n",pref_email);
if(pref_dlpath) fprintf(f,"dlpath %s\n",pref_dlpath);
fprintf(f,"linktype %d\n",pref_link);
if(pref_clrlist) fprintf(f,"optclrlist \n");
if(pref_autocon) fprintf(f,"autoconnect \n");
if(pref_fullpath) fprintf(f,"fullpath \n");
fclose(f);
}