/* ** Search */ #include "include/config.h" #include #include #include #include #include "include/mui.h" #include #include #include "include/gui.h" #include "include/search.h" #include "include/protos.h" #include "include/napster.h" #include "include/download.h" #include "include/panel.h" #include "include/prefs.h" #include "amster_Cat.h" #include "include/protos.h" ULONG search_new(struct IClass *cl, Object *obj, struct opSet *msg); MUIF songlistdisp(REG(a2) char **array, REG(a1) song s); MUIF songlistcomp(REG(a0) struct Hook *hook, REG(a2) Object *obj, REG(a1) struct NList_CompareMessage *ncm); void search_clear(struct searchdata *data); void search_download(struct searchdata *data, int t); void search_go(struct searchdata *data, char *sname); void search_nick(struct searchdata *data); void search_stat(struct searchdata *data, int t); void search_found(struct searchdata *data, song s); void search_reset(struct searchdata *data); void search_toggle(struct searchdata *data); void search_set(struct searchdata *data); void search_use(struct searchdata *data); int search_count = 0; int search_state = 0; MUIF search_dispatch(REG(a0) struct IClass *cl,REG(a2) Object *obj,REG(a1) Msg msg) { struct searchdata *data = INST_DATA(cl,obj); switch(msg->MethodID) { case OM_NEW: return(search_new(cl,obj,(APTR)msg)); case SEARCH_CLEAR: search_clear(data); return(0); case SEARCH_DOWNLOAD: search_download(data,(int)(((muimsg)msg)->arg1)); return(0); case SEARCH_GO: search_go(data,(char*)(((muimsg)msg)->arg1)); return(0); case SEARCH_NICK: search_nick(data); return(0); case SEARCH_FOUND: search_found(data,(song)(((muimsg)msg)->arg1)); return(0); case SEARCH_RESET: search_reset(data); return(0); case SEARCH_REFRESH: set(data->fptog,MUIA_Selected,prf->fullpath); DoMethod(data->list,MUIM_NList_Redraw,MUIV_NList_Redraw_All); return(0); case SEARCH_TOGGLE: search_toggle(data); return(0); case SEARCH_SET: search_set(data); return(0); case SEARCH_GET: search_use(data); return(0); case SEARCH_USE: search_use(data); prf_save("ENV:"AMSTER_PREFS); DoMethod(data->pop, MUIM_Popstring_Close, TRUE); return(0); } return(DoSuperMethodA(cl,obj,msg)); } ULONG search_new(struct IClass *cl, Object *obj, struct opSet *msg) { static char *numbers = "0123456789"; static char *opts[] = { (char*)_MSG_COMPARE_NONE, (char*)_MSG_COMPARE_ATLEAST, (char*)_MSG_COMPARE_EQUALTO, (char*)_MSG_COMPARE_ATBEST, NULL }; static struct Hook songlistdispHook = { {0,0}, &songlistdisp, NULL, NULL }; static struct Hook songlistcompHook = { {0,0}, &songlistcomp, NULL, NULL }; struct searchdata *data; Object *str,*maxstr,*snick,*sbut,*nbut; Object *pop; Object *popspeed, *popspeedval, *popbit, *popbitval, *popfreq, *popfreqval; Object *popuse, *popreset; Object *result, *list; Object *clrbut, *BT_Resume, *dlbut, *fptog; if(opts[0] == (char *)_MSG_COMPARE_NONE) localize_array(opts); if (obj = (Object *)DoSuperNew(cl,obj, Child, VGroup, Child, ColGroup(2), Child, Label2(MSG_SEARCH), Child, HGroup, Child, str = StringObject, StringFrame, MUIA_HorizWeight, 400, MUIA_String_MaxLen, 80, MUIA_CycleChain, 1, End, Child, sbut = SimpleButton(MSG_SEARCH_GAD), End, Child, Label2(MSG_SEARCHUSER), Child, HGroup, Child, snick = StringObject, StringFrame, MUIA_HorizWeight, 400, MUIA_String_MaxLen, 20, MUIA_CycleChain, 1, MUIA_ShortHelp, MSG_SEARCHUSER_HELP, End, Child, nbut = SimpleButton(MSG_SEARCHUSER_GAD), Child, Label2(MSG_MAX), Child, maxstr = StringObject, StringFrame, MUIA_String_Accept, numbers, MUIA_String_Integer, 100, MUIA_String_MaxLen, 4, MUIA_CycleChain, 1, End, Child, pop = PopobjectObject, MUIA_Popstring_Button, PopButton(MUII_PopUp), MUIA_Popobject_Object, VGroup, MUIA_Frame, MUIV_Frame_PopUp, Child, TextObject, MUIA_Text_Contents, MSG_ADVSEARCH, End, Child, ColGroup(3), Child, Label2(MSG_LINESPEED), Child, popspeed = CycleObject, MUIA_Cycle_Active, 0, MUIA_Cycle_Entries, opts, MUIA_CycleChain, 1, End, Child, popspeedval = CycleObject, MUIA_Cycle_Active, 1, MUIA_Cycle_Entries, nap_linktype, MUIA_CycleChain, 1, End, Child, Label2(MSG_BITRATE), Child, popbit = CycleObject, MUIA_Cycle_Active, 0, MUIA_Cycle_Entries, opts, MUIA_CycleChain, 1, End, Child, HGroup, Child, popbitval = StringObject, StringFrame, MUIA_String_Accept, numbers, MUIA_String_Integer, 128, MUIA_String_MaxLen, 4, MUIA_CycleChain, 1, End, Child, Label2(MSG_KBPS), End, Child, Label2(MSG_FREQUENCY), Child, popfreq = CycleObject, MUIA_Cycle_Active, 0, MUIA_Cycle_Entries, opts, MUIA_CycleChain, 1, End, Child, HGroup, Child, popfreqval = StringObject, StringFrame, MUIA_String_Accept, numbers, MUIA_String_Integer, 44100, MUIA_String_MaxLen, 6, MUIA_CycleChain, 1, End, Child, Label2(MSG_HZ), End, End, Child, HGroup, Child, popuse = SimpleButton(MSG_ADVUSE_GAD), Child, HSpace(0), Child, popreset = SimpleButton(MSG_ADVRESET_GAD), End, End, End, End, End, Child, HGroup, Child, Label(MSG_RESULT), Child, result = TextObject, End, End, Child, NListviewObject, MUIA_NListview_NList, list = NListObject, InputListFrame, MUIA_NList_Title, TRUE, MUIA_NList_Format, "BAR, BAR, BAR, BAR, BAR, BAR, BAR, BAR", MUIA_NList_MultiSelect, MUIV_NList_MultiSelect_Default, MUIA_NList_DisplayHook, &songlistdispHook, MUIA_NList_CompareHook2, &songlistcompHook, MUIA_CycleChain, 1, End, End, Child, HGroup, Child, clrbut = SimpleButton(MSG_CLEAR_GAD), Child, BT_Resume = SimpleButton(MSG_RESUME_GAD), Child, dlbut = SimpleButton(MSG_DOWNLOAD_GAD), Child, TextObject, MUIA_HorizWeight, 25, MUIA_Text_PreParse, "\33r", MUIA_Text_Contents, MSG_SEARCH_FULLPATH, End, Child, fptog = ImageObject, ButtonFrame, MUIA_HorizWeight, 10, MUIA_Background, MUII_ButtonBack, MUIA_InputMode, MUIV_InputMode_Toggle, MUIA_ShowSelState, FALSE, MUIA_Image_Spec, "6:15", MUIA_Selected, prf->fullpath, End, End, End, TAG_MORE, msg->ops_AttrList)) { data = INST_DATA(cl,obj); data->str = str; data->maxstr = maxstr; data->snick = snick; data->pop = pop; data->popspeed = popspeed; data->popspeedval = popspeedval; data->popbit = popbit; data->popbitval = popbitval; data->popfreq = popfreq; data->popfreqval = popfreqval; data->result = result; data->list = list; data->BT_Resume = BT_Resume; data->clrbut = clrbut; data->dlbut = dlbut; data->fptog = fptog; lamp_useinlist(list); DoMethod(str,MUIM_Notify,MUIA_String_Acknowledge,MUIV_EveryTime,obj,2,SEARCH_GO,NULL); DoMethod(sbut,MUIM_Notify,MUIA_Pressed,FALSE,obj,2,SEARCH_GO,NULL); DoMethod(snick,MUIM_Notify,MUIA_String_Acknowledge,MUIV_EveryTime,obj,1,SEARCH_NICK); DoMethod(nbut,MUIM_Notify,MUIA_Pressed,FALSE,obj,1,SEARCH_NICK); DoMethod(popuse, MUIM_Notify, MUIA_Pressed, FALSE, obj, 1, SEARCH_USE ); DoMethod(popreset, MUIM_Notify, MUIA_Pressed, FALSE, obj, 1, SEARCH_RESET); DoMethod(clrbut, MUIM_Notify, MUIA_Pressed, FALSE, obj, 1, SEARCH_CLEAR); DoMethod(dlbut, MUIM_Notify, MUIA_Pressed, FALSE, obj, 2, SEARCH_DOWNLOAD, 0); DoMethod(BT_Resume, MUIM_Notify, MUIA_Pressed, FALSE, obj, 2, SEARCH_DOWNLOAD, 2); DoMethod(list, MUIM_Notify, MUIA_NList_DoubleClick, MUIV_EveryTime, obj, 2, SEARCH_DOWNLOAD, 1); DoMethod(fptog,MUIM_Notify,MUIA_Selected,MUIV_EveryTime,obj,1,SEARCH_TOGGLE); DoMethod(list, MUIM_Notify, MUIA_NList_TitleClick, MUIV_EveryTime, list, 4, MUIM_NList_Sort3, MUIV_TriggerValue, MUIV_NList_SortTypeAdd_2Values, MUIV_NList_Sort3_SortType_Both); DoMethod(list, MUIM_Notify, MUIA_NList_TitleClick2, MUIV_EveryTime, list, 4, MUIM_NList_Sort3, MUIV_TriggerValue, MUIV_NList_SortTypeAdd_2Values, MUIV_NList_Sort3_SortType_2); DoMethod(list, MUIM_Notify, MUIA_NList_SortType, MUIV_EveryTime, list, 3, MUIM_Set, MUIA_NList_TitleMark, MUIV_TriggerValue); DoMethod(list, MUIM_Notify, MUIA_NList_SortType2, MUIV_EveryTime, list, 3, MUIM_Set, MUIA_NList_TitleMark2, MUIV_TriggerValue); set(BT_Resume, MUIA_Disabled, TRUE); /* Until it's implemented! */ return((ULONG)obj); } return(0); } MUIF songlistdisp(REG(a2) char **array, REG(a1) song s) { static char buf[50], buf2[50], buf3[50], time[40]; if (s) { if(s->link == 0) *array++ = lamp_getforlist(0); else if(s->link < 5) *array++ = lamp_getforlist(1); else if(s->link < 8) *array++ = lamp_getforlist(2); else *array++ = lamp_getforlist(3); if(prf->fullpath) *array++ = s->title; else *array++ = nap_strippath(s->title); sprintf(buf,"\33c%d",s->bit); *array++ = buf; sprintf(buf2,"\33c%d",s->freq); *array++ = buf2; sprintf(buf3,"\33r%ld",s->size); *array++ = buf3; if(s->time>0) { int secs = s->size/(s->bit*125); if(abs(s->time - secs)*100/s->time > 3) sprintf(time,"\33r\33i%ld:%02ld",s->time/60,s->time%60); else sprintf(time,"\33r%ld:%02ld",s->time/60,s->time%60); } else { sprintf(time,"\33r0:00"); } *array++ = time; *array++ = s->user; *array = nap_linktype[s->link]; } else { *array++ = "\33c@"; *array++ = (char *)MSG_LH_SONG; *array++ = (char *)MSG_LH_KBPS; *array++ = (char *)MSG_LH_HZ; *array++ = (char *)MSG_LH_SIZE; *array++ = (char *)MSG_LH_TIME; *array++ = (char *)MSG_LH_USER; *array = (char *)MSG_LH_LINK; } return(0); } void search_clear(struct searchdata *data) { u_long item; set(data->list, MUIA_NList_Quiet, MUIV_NList_Quiet_Visual); while (1) { DoMethod(data->list, MUIM_NList_GetEntry, 0, &item); if (!item) break; DoMethod(data->list, MUIM_NList_Remove, MUIV_NList_Remove_First); nap_songfree((song)item); } set(data->list, MUIA_NList_Quiet, MUIV_NList_Quiet_None); search_stat(data, 0); } void search_download(struct searchdata *data, int t) { int f=0; u_long item, listid; if (!gui_napon) return; switch (t) { case 0: listid = MUIV_NList_NextSelected_Start; for (;;) { DoMethod(data->list, MUIM_NList_NextSelected, &listid); if (listid == MUIV_NList_NextSelected_End) break; DoMethod(data->list, MUIM_NList_GetEntry, listid, &item); if (item) { if (!f) { DoMethod(gui->iconpanel, PANEL_OPENDL); f=1; } sprintf(nap_buf, "\"%s\" \"%s\"", ((song)item)->user, ((song)item)->title); nap_send(NAPC_FILEINFOREQ); dl_addq((song)item); } } break; case 1: GetAttr(MUIA_NList_DoubleClick, data->list, &listid); if (listid == -1 || listid == -2) return; DoMethod(data->list, MUIM_NList_GetEntry, listid, &item); if (!item) return; if (!f) { DoMethod(gui->iconpanel, PANEL_OPENDL); f=1; } sprintf(nap_buf, "\"%s\" \"%s\"", ((song)item)->user, ((song)item)->title); nap_send(NAPC_FILEINFOREQ); dl_addq((song)item); break; case 2: DoMethod(data->list, MUIM_NList_GetEntry, MUIV_NList_GetEntry_Active, &item); if (!item) return; gui_debugf("Resume attempted for: %s", ((song)item)->title); break; } } void search_go(struct searchdata *data, char *sname) { static char *opts[] = { "AT LEAST", "EQUAL TO", "AT BEST" }; char *p, str[80]; u_long tmp,tmp2; if(!gui_napon) return; if(sname) { tmp = (u_long)sname; } else { GetAttr(MUIA_String_Acknowledge,data->str,&tmp); if(!tmp || ((char*)tmp)[0]==0) return; } GetAttr(MUIA_String_Integer,data->maxstr,&tmp2); if(tmp2<3) tmp2=3; /* if(tmp2>100) tmp2=100;*/ strcpy(str,(char*)tmp); strlwr(str); p = nap_buf + sprintf(nap_buf,"FILENAME CONTAINS \"%s\" MAX_RESULTS %d",str,tmp2); GetAttr(MUIA_Cycle_Active,data->popspeed,&tmp); GetAttr(MUIA_Cycle_Active,data->popspeedval,&tmp2); if(tmp) p=p+sprintf(p," LINESPEED \"%s\" %d",opts[tmp-1],tmp2); GetAttr(MUIA_Cycle_Active,data->popbit,&tmp); GetAttr(MUIA_String_Integer,data->popbitval,&tmp2); if(tmp) p=p+sprintf(p," BITRATE \"%s\" %d",opts[tmp-1],tmp2); GetAttr(MUIA_Cycle_Active,data->popfreq,&tmp); GetAttr(MUIA_String_Integer,data->popfreqval,&tmp2); if(tmp) sprintf(p," FREQ \"%s\" %d",opts[tmp-1],tmp2); search_count=0; if(prf->clrlist) search_clear(data); search_stat(data,1); nap_send(NAPC_SEARCH); } void search_nick(struct searchdata *data) { u_long tmp; if (!gui_napon) return; GetAttr(MUIA_String_Acknowledge, data->snick, &tmp); if (tmp && ((char *)tmp)[0] != '\0') { search_count=0; if (prf->clrlist) search_clear(data); nap_sendbuf(NAPC_BROWSEUSER, (char *)tmp); search_stat(data, 3); } } void search_stat(struct searchdata *data, int t) { static char buf[80]; char *txt; switch(t) { case 0: txt = ""; search_state = 0; break; case 1: search_state = 1; txt = (char*)MSG_STATUS1_SEARCHING; break; case 2: if(search_count==0) txt = (char*)MSG_STATUS1_NOFILES; else if(search_count==1) txt = (char*)MSG_STATUS1_ONEFOUND; else { sprintf(buf,MSG_STATUS1_FOUND,search_count); txt = buf; } search_state = 2; break; case 3: txt = (char*)MSG_STATUS1_REQLIST; break; } set(data->result,MUIA_Text_Contents,txt); } void search_found(struct searchdata *data, song s) { if(s) { DoMethod(data->list,MUIM_NList_InsertSingle,s,MUIV_NList_Insert_Sorted); search_count++; } else { search_stat(data,2); } } void search_reset(struct searchdata *data) { set(data->popspeed,MUIA_Cycle_Active,0); set(data->popspeedval,MUIA_Cycle_Active,1); set(data->popbit,MUIA_Cycle_Active,0); set(data->popbitval,MUIA_String_Integer,128); set(data->popfreq,MUIA_Cycle_Active,0); set(data->popfreqval,MUIA_String_Integer,44100); } void search_toggle(struct searchdata *data) { u_long tmp; GetAttr(MUIA_Selected,data->fptog,&tmp); prf->fullpath = tmp; DoMethod(data->list,MUIM_NList_Redraw,MUIV_NList_Redraw_All); } void search_set(struct searchdata *data) { set(data->maxstr, MUIA_String_Integer, prf->max); set(data->popspeed, MUIA_Cycle_Active, prf->speedqual); set(data->popspeedval, MUIA_Cycle_Active, prf->speedval); set(data->popbit, MUIA_Cycle_Active, prf->bitratequal); set(data->popbitval, MUIA_String_Integer, prf->bitrateval); set(data->popfreq, MUIA_Cycle_Active, prf->freqqual); set(data->popfreqval, MUIA_String_Integer, prf->freqval); } void search_use(struct searchdata *data) { u_long tmp; GetAttr(MUIA_Cycle_Active,data->popspeed,&tmp); prf->speedqual = tmp; GetAttr(MUIA_Cycle_Active,data->popspeedval,&tmp); prf->speedval = tmp; GetAttr(MUIA_Cycle_Active,data->popbit,&tmp); prf->bitratequal = tmp; GetAttr(MUIA_String_Integer,data->popbitval,&tmp); prf->bitrateval = (int)tmp; GetAttr(MUIA_Cycle_Active,data->popfreq,&tmp); prf->freqqual = tmp; GetAttr(MUIA_String_Integer,data->popfreqval,&tmp); prf->freqval = (int)tmp; GetAttr(MUIA_String_Integer,data->maxstr,&tmp); prf->max = (int)tmp; } MUIF songlistcomp(REG(a0) struct Hook *hook, REG(a2) Object *obj, REG(a1) struct NList_CompareMessage *ncm) { song entry1 = ncm->entry1; song entry2 = ncm->entry2; LONG col1 = ncm->sort_type & MUIV_NList_TitleMark_ColMask; LONG col2 = ncm->sort_type2 & MUIV_NList_TitleMark2_ColMask; ULONG result = 0; if (ncm->sort_type == MUIV_NList_SortType_None) return (0); if (col1 == 1) { if (ncm->sort_type & MUIV_NList_TitleMark_TypeMask) { if (prf->fullpath) result = (LONG) stricmp(entry2->title, entry1->title); else result = (LONG) stricmp(nap_strippath(entry2->title), nap_strippath(entry1->title)); } else { if (prf->fullpath) result = (LONG) stricmp(entry1->title, entry2->title); else result = (LONG) stricmp(nap_strippath(entry1->title), nap_strippath(entry2->title)); } } else if (col1 == 2) { if (ncm->sort_type & MUIV_NList_TitleMark_TypeMask) result = entry2->bit - entry1->bit; else result = entry1->bit - entry2->bit; } else if (col1 == 3) { if (ncm->sort_type & MUIV_NList_TitleMark_TypeMask) result = entry2->freq - entry1->freq; else result = entry1->freq - entry2->freq; } else if (col1 == 4) { if (ncm->sort_type & MUIV_NList_TitleMark_TypeMask) result = entry2->size - entry1->size; else result = entry1->size - entry2->size; } else if (col1 == 5) { if (ncm->sort_type & MUIV_NList_TitleMark_TypeMask) result = entry2->time - entry1->time; else result = entry1->time - entry2->time; } else if (col1 == 6) { if (ncm->sort_type & MUIV_NList_TitleMark_TypeMask) result = (LONG) stricmp(entry2->user, entry1->user); else result = (LONG) stricmp(entry1->user, entry2->user); } else if (col1 == 7) { if (ncm->sort_type & MUIV_NList_TitleMark_TypeMask) result = entry2->link - entry1->link; else result = entry1->link - entry2->link; } if ((result != 0) || (col1 == col2)) return (result); if (col2 == 1) { if (ncm->sort_type & MUIV_NList_TitleMark2_TypeMask) { if (prf->fullpath) result = (LONG) stricmp(entry2->title, entry1->title); else result = (LONG) stricmp(nap_strippath(entry2->title), nap_strippath(entry1->title)); } else { if (prf->fullpath) result = (LONG) stricmp(entry1->title, entry2->title); else result = (LONG) stricmp(nap_strippath(entry1->title), nap_strippath(entry2->title)); } } else if (col2 == 2) { if (ncm->sort_type & MUIV_NList_TitleMark2_TypeMask) result = entry2->bit - entry1->bit; else result = entry1->bit - entry2->bit; } else if (col2 == 3) { if (ncm->sort_type & MUIV_NList_TitleMark2_TypeMask) result = entry2->freq - entry1->freq; else result = entry1->freq - entry2->freq; } else if (col2 == 4) { if (ncm->sort_type & MUIV_NList_TitleMark2_TypeMask) result = entry2->size - entry1->size; else result = entry1->size - entry2->size; } else if (col2 == 5) { if (ncm->sort_type & MUIV_NList_TitleMark2_TypeMask) result = entry2->time - entry1->time; else result = entry1->time - entry2->time; } else if (col2 == 6) { if (ncm->sort_type & MUIV_NList_TitleMark2_TypeMask) result = (LONG) stricmp(entry2->user, entry1->user); else result = (LONG) stricmp(entry1->user, entry2->user); } else if (col2 == 7) { if (ncm->sort_type & MUIV_NList_TitleMark2_TypeMask) result = entry2->link - entry1->link; else result = entry1->link - entry2->link; } return (result); }