home *** CD-ROM | disk | FTP | other *** search
- #include "sysheaders.h"
- #include "cdpanel.h"
- #include "CompactPlayer.h"
-
- /* Define as 0 to get the more traditional "click on line, edit it in a
- * string gadget" editing. Default is using listbrowser's in place editing.
- */
- #define INPLACEEDIT 1
-
- /********************************************************
- * CD Index editor
- */
-
- struct Window *ListWin;
- Object *ListWinObj;
- struct Gadget *ListLayout;
-
- static struct List *TitleList;
-
- static UBYTE artist[40], title[40], work1[40], work2[40];
- #if !INPLACEEDIT
- static UBYTE track[40];
- #endif
-
- STRPTR IndexPath = "Disks";
-
- static UBYTE cd[20];
-
- BOOL
- GetIndex( ULONG t, ULONG a1, ULONG a2 )
- {
- UBYTE buf[256];
- BPTR f;
-
- /* Read an index file from the disk */
-
- strcpy( buf, IndexPath );
- Sprintf( cd, "ID%02.2ld%06.6lx%06.6lx", t, a1, a2 );
- AddPart( buf, cd, sizeof(buf)-1 );
-
- TOCP[0] = ~0;
-
- if (f = Open(buf, MODE_OLDFILE))
- {
- ULONG i;
-
- FGets(f, buf, sizeof(buf)-1);
- stccpy(TITLE[0] = &TitleBuffer[0], buf, 40);
- FGets(f, buf, sizeof(buf)-1);
- stccpy(TITLE[1] = &TitleBuffer[40], buf, 40);
-
- for (i = 0 ; i < t ; i++)
- {
- FGets(f, buf, sizeof(buf)-1);
- stccpy(TOCS[i] = &TitleBuffer[(i+2)*40], buf, 40);
- }
- TOCS[i] = NULL;
-
- for (i = 0 ; i < (t+2)*40 ; i++)
- {
- if (TitleBuffer[i] == '\n')
- TitleBuffer[i] = 0;
- }
-
- Close(f);
-
- return TRUE;
- }
- return FALSE;
- }
-
- void
- SaveIndex(void)
- {
- UBYTE name[256];
- BPTR f;
-
- /* Save an index file to disk */
-
- strcpy( name, IndexPath );
- AddPart( name, cd, 256 );
-
- if (f = Open(name, MODE_NEWFILE))
- {
- ULONG i;
-
- FPuts(f, TITLE[0]);
- FPutC(f, '\n');
- FPuts(f, TITLE[1]);
- FPutC(f, '\n');
-
- for (i = 0 ; TOCS[i] ; i++)
- {
- FPuts(f, TOCS[i]);
- FPutC(f, '\n');
- }
-
- Close(f);
- }
- }
-
- struct Window *
- OpenListWindow(ULONG X, ULONG Y)
- {
- if (ListWin)
- return ListWin;
-
- /* A very simple layout here. I won't bother even explaining it */
-
- ListLayout = VGroupObject, LAYOUT_SpaceOuter, TRUE,
- GA_DrawInfo, Dri,
- LAYOUT_DeferLayout, TRUE,
- StartMember, GList[G_Artist] = StringObject,
- STRINGA_WorkBuffer, work1,
- STRINGA_UndoBuffer, work2,
- STRINGA_Buffer, artist,
- STRINGA_MaxChars, 39,
- STRINGA_TextVal, "",
- GA_RelVerify, TRUE,
- GA_ID, G_Artist,
- GA_TabCycle, TRUE,
- End,
- CHILD_Label, LabelObject, LABEL_Text, GS(STR_ARTIST), End,
- StartMember, GList[G_Title] = StringObject,
- STRINGA_WorkBuffer, work1,
- STRINGA_UndoBuffer, work2,
- STRINGA_Buffer, title,
- STRINGA_MaxChars, 39,
- STRINGA_TextVal, "",
- GA_RelVerify, TRUE,
- GA_ID, G_Title,
- GA_TabCycle, TRUE,
- End,
- CHILD_Label, LabelObject, LABEL_Text, GS(STR_TITLE), End,
- StartMember, GList[G_TitleList] = ListBrowserObject,
- LISTBROWSER_Labels, &dummyList,
- #if !INPLACEEDIT
- LISTBROWSER_ShowSelected, TRUE,
- #else
- LISTBROWSER_Editable, TRUE,
- #endif
- GA_RelVerify, TRUE,
- GA_ID, G_TitleList,
- End,
- CHILD_MinHeight, ScreenFont->tf_YSize * 6,
- CHILD_MinWidth, ScreenFont->tf_XSize * 20,
- #if !INPLACEEDIT
- StartMember, GList[G_Track] = StringObject,
- STRINGA_WorkBuffer, work1,
- STRINGA_UndoBuffer, work2,
- STRINGA_Buffer, track,
- STRINGA_MaxChars, 39,
- STRINGA_TextVal, "",
- GA_Disabled, TRUE,
- GA_RelVerify, TRUE,
- GA_ID, G_Track,
- GA_TabCycle, TRUE,
- End,
- #endif
- StartMember, GList[G_SaveTitles] = ButtonObject,
- GA_Text, GS(SAVE_TITLES),
- GA_RelVerify, TRUE,
- GA_Disabled, TRUE,
- GA_ID, G_SaveTitles,
- End,
- CHILD_NominalSize, TRUE,
- CHILD_WeightedWidth, TRUE,
- End;
-
- if (ListLayout)
- {
- if (ListWinObj = WindowObject,
- WA_DepthGadget, TRUE,
- WA_CloseGadget, TRUE,
- WA_DragBar, TRUE,
- WA_Activate, TRUE,
- WA_Top, Y,
- WA_Left, X,
- WA_PubScreen, Scr,
- WA_Title, GS(TITLE_EDITOR),
- WA_ScreenTitle, GS(TITLE_COPYRIGHT),
- WA_AutoAdjust, TRUE,
- WINDOW_Layout, ListLayout,
- WINDOW_AppPort, AppPort,
- WINDOW_SharedPort, WinPort,
- TAG_END))
- {
- if (ListWin = CA_OpenWindow(ListWinObj))
- ActivateLayoutGadget(ListLayout, ListWin, NULL, GList[G_Artist]);
-
- return ListWin;
- }
- DisposeObject(ListLayout);
- ListLayout = NULL;
- }
- ErrorMsg(GS(GUI_FAIL));
- }
-
- void
- CloseListWindow(void)
- {
- if (ListLayout)
- {
- SetGadgetAttrs(GList[G_TitleList], Win, NULL, LISTBROWSER_Labels, ~0, TAG_END);
- FreeBrowserNodes(TitleList);
- TitleList = NULL;
- }
- if (ListWinObj)
- {
- DisposeObject(ListWinObj);
- ListWin = NULL;
- ListWinObj = NULL;
- ListLayout = NULL;
- memset(&GList[G_Artist], 0, (ULONG)&GList[GG_MAX2]-(ULONG)&GList[G_Artist]);
- }
- }
-
- void
- ListWindowIDCMP(void)
- {
- BOOL close = FALSE;
- ULONG result;
-
- if (!ListWinObj)
- return;
-
- while ((result = CA_HandleInput(ListWinObj,NULL)) != WMHI_LASTMSG)
- {
- /* CA_HandleInput (aka. WM_HANDLEINPUT) will translate keyboard events
- * into GADGETUPs on its own */
- switch (result & WMHI_CLASSMASK)
- {
- case WMHI_CLOSEWINDOW:
- close = TRUE;
- break;
-
- case WMHI_GADGETUP:
- /* changing a gadget this window is reflected in the other window */
- switch(result & WMHI_GADGETMASK)
- {
- case G_Artist:
- SetGadgetAttrs(GList[G_Panel], Win, NULL,
- CDPANEL_Artist, "",
- TAG_END);
- strcpy(TITLE[0], artist);
- SetGadgetAttrs(GList[G_Panel], Win, NULL,
- CDPANEL_Artist, TITLE[0],
- TAG_END);
- ActivateLayoutGadget(ListLayout, ListWin, NULL, GList[G_Title]);
- break;
-
- case G_Title:
- {
- struct Node *n = TitleList->lh_Head;
- ULONG status = 0;
-
- strcpy(TITLE[1], title);
-
- GetAttr(CDPANEL_Status, GList[G_Panel], &status);
- if (status != CDP_PLAYING && status != CDP_PAUSED)
- SetGadgetAttrs(GList[G_Panel], Win, NULL,
- CDPANEL_Title, TITLE[1],
- TAG_END);
-
- if (SetGadgetAttrs(GList[G_TitleList], ListWin, NULL,
- LISTBROWSER_Selected, 0,
- LISTBROWSER_MakeVisible, 0,
- TAG_END))
- RefreshGList(GList[G_TitleList], ListWin, NULL, 1);
- #if !INPLACEEDIT
- if (SetGadgetAttrs(GList[G_Track], ListWin, NULL,
- STRINGA_TextVal, n->ln_Name,
- GA_Disabled, FALSE,
- TAG_END));
- RefreshGList(GList[G_Track], ListWin, NULL, 1);
-
- ActivateLayoutGadget(ListLayout, ListWin, NULL, GList[G_Track]);
- #else
- SetGadgetAttrs(GList[G_TitleList], ListWin, NULL,
- LISTBROWSER_EditNode, 0,
- LISTBROWSER_EditColumn, 0,
- TAG_END);
-
- ActivateLayoutGadget(ListLayout, ListWin, NULL, GList[G_TitleList]);
- #endif
- break;
- }
-
- #if !INPLACEEDIT
- case G_TitleList:
- {
- struct Node *n;
- GetAttr(LISTBROWSER_SelectedNode, GList[G_TitleList], (ULONG *)&n);
- if (n)
- {
- if (SetGadgetAttrs(GList[G_Track], ListWin, NULL,
- STRINGA_TextVal, n->ln_Name,
- STRINGA_BufferPos, 0,
- STRINGA_DispPos, 0,
- GA_Disabled, FALSE,
- TAG_END));
- RefreshGList(GList[G_Track], ListWin, NULL, 1);
-
- ActivateLayoutGadget(ListLayout, ListWin, NULL, GList[G_Track]);
- }
- else
- {
- if (SetGadgetAttrs(GList[G_Track], ListWin, NULL,
- STRINGA_TextVal, "",
- GA_Disabled, TRUE,
- TAG_END));
- RefreshGList(GList[G_Track], ListWin, NULL, 1);
- }
- }
- break;
-
- case G_Track:
- {
- #else
- case G_TitleList:
- {
- STRPTR track;
- ULONG event = 0;
- #endif
- struct Node *n;
- ULONG i, ctrack;
- GetAttr(LISTBROWSER_SelectedNode, GList[G_TitleList], (ULONG *)&n);
- GetAttr(LISTBROWSER_Selected, GList[G_TitleList], &i);
- GetAttr(CDPANEL_Track, GList[G_Panel], &ctrack);
-
- if (i == ~0 || !n)
- break;
-
- #if !INPLACEEDIT
- SetGadgetAttrs(GList[G_List], Win, NULL,
- LISTBROWSER_Labels, ~0,
- TAG_END);
-
- SetGadgetAttrs(GList[G_TitleList], ListWin, NULL,
- LISTBROWSER_Labels, ~0,
- TAG_END);
- #else
- GetListBrowserNodeAttrs( n, LBNCA_Text, &track );
- GetAttr( LISTBROWSER_RelEvent, GList[G_TitleList], &event );
-
- if (event == LBRE_EDIT)
- {
- #endif
- strcpy(TOCS[i], track);
-
- if (i + 1 == ctrack) /* make panel gadget update itself */
- {
- SetGadgetAttrs(GList[G_Panel], Win, NULL,
- CDPANEL_Track, 0,
- CDPANEL_Track, i + 1,
- TAG_END);
- }
-
- if (TrackList)
- {
- FreeBrowserNodes(TrackList);
-
- TrackList = BrowserNodesA(TOCS);
-
- if (SetGadgetAttrs(GList[G_List], Win, NULL,
- LISTBROWSER_Labels, TrackList,
- TAG_END))
- RefreshGList(GList[G_List], Win, NULL, 1);
- }
- #if !INPLACEEDIT
- SetListBrowserNodeAttrs(n, LBNCA_Text, TOCS[i], TAG_END);
-
- if (SetGadgetAttrs(GList[G_TitleList], ListWin, NULL,
- LISTBROWSER_Labels, TitleList,
- TAG_END))
- RefreshGList(GList[G_TitleList], ListWin, NULL, 1);
- #endif
- n = n->ln_Succ;
- if (n->ln_Succ)
- {
- if (SetGadgetAttrs(GList[G_TitleList], ListWin, NULL,
- LISTBROWSER_Selected, i+1,
- LISTBROWSER_MakeVisible, i+1,
- TAG_END))
- RefreshGList(GList[G_TitleList], ListWin, NULL, 1);
- #if !INPLACEEDIT
- if (SetGadgetAttrs(GList[G_Track], ListWin, NULL,
- STRINGA_TextVal, n->ln_Name,
- STRINGA_BufferPos, 0,
- STRINGA_DispPos, 0,
- TAG_END));
- RefreshGList(GList[G_Track], ListWin, NULL, 1);
-
- ActivateLayoutGadget(ListLayout, ListWin, NULL, GList[G_Track]);
- #else
- SetGadgetAttrs(GList[G_TitleList], ListWin, NULL,
- LISTBROWSER_EditNode, i+1,
- LISTBROWSER_EditColumn, 0,
- TAG_END);
-
- ActivateLayoutGadget(ListLayout, ListWin, NULL, GList[G_TitleList]);
- #endif
- }
- else
- {
- if (SetGadgetAttrs(GList[G_TitleList], ListWin, NULL,
- LISTBROWSER_Selected, ~0,
- TAG_END))
- RefreshGList(GList[G_TitleList], ListWin, NULL, 1);
- #if !INPLACEEDIT
- if (SetGadgetAttrs(GList[G_Track], ListWin, NULL,
- STRINGA_TextVal, "",
- GA_Disabled, TRUE,
- TAG_END));
- RefreshGList(GList[G_Track], ListWin, NULL, 1);
- #endif
- }
- #if INPLACEEDIT
- }
- else
- {
- SetGadgetAttrs(GList[G_TitleList], ListWin, NULL,
- LISTBROWSER_MakeVisible, i,
- LISTBROWSER_EditNode, i,
- LISTBROWSER_EditColumn, 0,
- TAG_END);
-
- ActivateLayoutGadget(ListLayout, ListWin, NULL, GList[G_TitleList]);
- }
- #endif
- }
- break;
-
- case G_SaveTitles:
- SaveIndex();
- break;
- }
- break;
- }
- }
- if (close)
- CloseListWindow();
- }
-
- void
- UpdateTitleEditor(void)
- {
- /* Changing a CD will trigger this function to update the contents of the
- * editor. */
- if (SetGadgetAttrs(GList[G_Artist], ListWin, NULL,
- STRINGA_TextVal, TITLE[0],
- TAG_END));
- RefreshGList(GList[G_Artist], ListWin, NULL, 1);
- if (SetGadgetAttrs(GList[G_Title], ListWin, NULL,
- STRINGA_TextVal, TITLE[1],
- TAG_END));
- RefreshGList(GList[G_Title], ListWin, NULL, 1);
- SetGadgetAttrs(GList[G_TitleList], Win, NULL,
- LISTBROWSER_Labels, ~0,
- TAG_END);
- FreeBrowserNodes(TitleList);
- TitleList = EditBrowserNodesA(TOCS);
- if (SetGadgetAttrs(GList[G_TitleList], ListWin, NULL,
- LISTBROWSER_Labels, TitleList,
- LISTBROWSER_Selected, ~0,
- TAG_END))
- RefreshGList(GList[G_TitleList], ListWin, NULL, 1);
- #if !INPLACEEDIT
- if (SetGadgetAttrs(GList[G_Track], ListWin, NULL,
- GA_Disabled, TRUE,
- TAG_END));
- RefreshGList(GList[G_Track], ListWin, NULL, 1);
- #endif
- if (SetGadgetAttrs(GList[G_SaveTitles], ListWin, NULL,
- GA_Disabled, FALSE,
- TAG_END ))
- RefreshGList(GList[G_SaveTitles], ListWin, NULL, 1);
- }
-