////////////////////////////////////////////////////////// // WebAddressManager.cpp // // // // Description: A program to manage and modify lists of // // URLS. Imports Netscape HTML Bookmark files into // // proprietary format. Rewritten WAL -- Contains code // // for the fancy UI. // // // // AUTHOR: Lucas Scharf // // Jan 24 - April 9 1998 // // // // REVISIONS: None // // VERSION: 2.00 // ////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////// // Compiler Directives // ////////////////////////////////////////////////////////// #include //strcpy() & strcat() #include //Time conversions #include //Used for itoa() #include //Used in LoadMenuFromFile() #include "BookmarkFileStructs.h"//Bookmark & Folder types #include "CUIToolkit.h" //Encapsulated Curses #include "ListFunctions.h" //For #include "ImportFromHTML.h" //Import #include "WALProprietaryFormat.h"//Load & Save #include "MiscFileFunctions.h" //Changing filename extension & existance check #include "ExportTree.h" //View ////////////////////////////////////////////////////////// // Constant Declarations // ////////////////////////////////////////////////////////// const TitleWidth = 30; //Width alotted to the title section of the bookmark listitem const SmallDateWidth = 10; //Width of the abridged date format const BASETEN = 10; //Base to convert integer values to const char BOOKMARKFLAG = 'b'; //This item is a bookmark const char FOLDERFLAG = 'f'; //This item is a folder //-- Main Display Area const MainDisplayAreaX = 0; //Horizontal Coord of Main Display Area const MainDisplayAreaY = 1; //Vertical Coord of Main Display Area const MainDisplayAreaH = 24; //Width of Main Display Area const MainDisplayAreaW = 80; //Height of Main Display Area //-- Standard Dialog Box -- const StandardDialogX = 1; //Horizontal Coordinate of the dialog box const StandardDialogY = 10; //Vertical Coordinate of the dialog box const StandardDialogH = 5; //Width of the dialog const StandardDialogW = 78; //Height of the dialog const StandardDialogInputLength = 76; //Stadnard dialog box string input width //-- Are you sure? -- const AreYouSureInputWidth = 1; //Input width for "Are You Sure" boxes const char AreYouSureYESUC = 'Y';//Are You Sure uppercase const char AreYouSureYESLC = 'y';//Are You Sure lowercase //-- File Extensions -- const char WAMFILEEXTENSION[5] = ".wam";//the extension for all WAM files const char ERRORFILEEXTEION[5] = ".rpt";//the extension for all error log files ////////////////////////////////////////////////////////// // Enumerated Types // ////////////////////////////////////////////////////////// enum ENUMFolderToAddLabel {EFolderNoLabel, EFolderParentLabel, EFolderSubLabel}; ////////////////////////////////////////////////////////// // Private Function Prototypes // ////////////////////////////////////////////////////////// //-- Menus -- void FileMenu(char CurrentFile[], BookmarkDataPtr &BookmarkListHeadPtr, FolderDataPtr &FolderListHeadPtr, FolderDataPtr &CurrentFolder, bool &TellProgramToQuit); //void EditMenu(CUIListItemPtr CUICurrentItemPtr); void WAMMenu(BookmarkDataPtr &BookmarkListPtr, FolderDataPtr &FolderListPtr, FolderDataPtr CurrentFolder, CUIListItemPtr CUIListHeadPtr, CUIListItemPtr CUICurrentItemPtr); void EditMenu(CUIListItemPtr CUICurrentItemPtr); void SearchMenu(BookmarkDataPtr BookmarkListPtr, FolderDataPtr FolderListPtr, CUIListItemPtr &CUIListHeadPtr); void ProgramMenu(); void LoadMenuFromFile(CUIListItemPtr &MenuList, const char FileToLoad[]); //-- Folder and bookmark list <-> CUI list interface Functions -- void MakeCUIListFromCurrentFolder(FolderDataPtr FolderListHeadPtr, BookmarkDataPtr BookmarkListHeadPtr, CUIListItemPtr &CUIListHeadPtr, FolderDataPtr &CurrentFolder); void ChildFoldersToCUIList(FolderDataPtr FolderListHeadPtr, CUIListItemPtr &CUIListHead, FolderDataPtr WorkingFolderPtr); void AddOneFolderToCUIList(FolderDataPtr FolderToAdd, CUIListItemPtr &CUIListHeadPtr, ENUMFolderToAddLabel FolderLabel); void ChildBookmarksToCUIList(BookmarkDataPtr BookmarkListHeadPtr, CUIListItemPtr &CUIListHead, FolderDataPtr WorkingFolderPtr); void AddOneBookmarkToCUIList(BookmarkDataPtr BookmarkToAdd, CUIListItemPtr &CUIListHeadPtr); void ShowBookmark(BookmarkDataStruct BookmarkToDisplay); //-- Prompt Functions -- void PromptAddBookmark(BookmarkDataPtr &BookmarkList, FolderDataPtr CurrentFolder); void PromptAddFolder(FolderDataPtr &FolderList, FolderDataPtr CurrentFolder); int GetUTCTime(char PromptText[], long DefaultUTCTime); ////////////////////////////////////////////////////////// // WebAddressManager Central Function // // // // Function central to the WebAddressManager. Backbone.// // // // // // CALLED BY: main() // // CALLS: // // CUI // // FileMenu() // // ProgramMenu() // // // // Parameters // // const char FileToLoad[]: In - a string containing // // the file to load. If file is null, or DNE, // // than file is not loaded. // // // // REVISIONS: DATE, REASON // // AUTHOR FOR EACH (if different) // // VERSION: x.xx // ////////////////////////////////////////////////////////// void WebAddressManager(const char FileToLoad[]){ //-- Constant Declarations -- const char FILEMENUKEYUC = 'F'; //File menu key, uppercase const char FILEMENUKEYLC = 'f'; //File menu key, lowercase const char WAMMENUKEYUC = 'W'; //WAM Menu key, uppercase const char WAMMENUKEYLC = 'w'; //WAM Menu key, lowercase const char EDITMENUUC = 'E'; //Edit menu key, uppercase const char EDITMENULC = 'e'; //Edit menu key, lowercase const char SEARCHMENUUC = 'S'; //Search menu key, uppercase const char SEARCHMENULC = 's'; //Search menu key, lowercase const char PROGMENUKEYUC = 'P'; //Program menu key, uppercase const char PROGMENUKEYLC = 'p'; //Program menu key, lowercase const char STATUSLINEFILEFFOLDERSEPERATOR[4] = " : "; //The string that seperates the filename //from the folder on the status line const MainDisplayAreaX = 0; //Horizontal Coord of Main Display Area const MainDisplayAreaY = 1; //Vertical Coord of Main Display Area const MainDisplayAreaH = 24; //Width of Main Display Area const MainDisplayAreaW = 80; //Height of Main Display Area const MenuBarX = 0; //Horizontal Coord of Menu Bar const MenuBarY = 0; //Vertical Coord of Menu Bar const MenuBarH = 1; //Width of Menu Bar const MenuBarW = 80; //Height of Menu Bar //-- UI Variable Declarations -- int LastKey = -1; //Last key pressed before returning from CUIListPrompt bool RefreshMainDisplayListFlag = true;//Flag to refresh the list in the main display area //-- List Head Variable Declarations -- FolderDataPtr FolderListHeadPtr; //Head of the folder list BookmarkDataPtr BookmarkListHeadPtr;//Head of the bookmark list CUIListItemPtr CUIListHeadPtr; //Pointer to the 1st item in the main display area list //-- List Position Variable Declarations -- CUIListItemPtr CUIListCurrentPtr; //Pointer to the currently selected item in the main display area FolderDataPtr CurrentFolder; //The current folder //-- Quit Variable Declaration -- bool QuitFlag = false; //Flag modified by FileMenu. True == quit, false == don't quit //-- File Variable Declarations -- char CurrentFile[StringLength+1]={""};//Path & Filename of the current file //-- Scratch Variable Declarations -- char TmpStr[StringLength+1]; //Used in concatonating status line //-- List Init -- CreateBookmarkList(BookmarkListHeadPtr); CreateFolderList(FolderListHeadPtr); CUICreateList(CUIListHeadPtr); CurrentFolder = null; CUIListCurrentPtr = null; //-- Startup CUIToolkit -- CUIInit(); //-- Display Splash Screen -- CUICreateWindow(MainDisplayAreaX, MainDisplayAreaY, MainDisplayAreaW, MainDisplayAreaH); CUIDisplayFile("About.txt"); //Constant won't work here CUIDestroyWindow(); //-- Load file from the command line, if it exists -- if (InputWALFile(BookmarkListHeadPtr, FolderListHeadPtr, FileToLoad)){ //InputWALFile returns true if the file was loaded //-- Set CurrentFile string -- strcpy(CurrentFile, FileToLoad); //-- Fill Display list with contents of the current folder -- MakeCUIListFromCurrentFolder(FolderListHeadPtr, BookmarkListHeadPtr, CUIListHeadPtr, CurrentFolder); } else { CurrentFile[0] = null; //Set CurrentFile string null }//end 0f //-- Define Menu Bar -- CUICreateWindow(MenuBarX, MenuBarY, MenuBarW, MenuBarH); CUIWriteText(0,0, "File Edit WAM Search Program "); //Constant won't work here //-- Main UI Loop -- CUICreateWindow(MainDisplayAreaX, MainDisplayAreaY, MainDisplayAreaW, MainDisplayAreaH); //Create Main Display Area while (!QuitFlag){ //-- Display List Dialog -- if (FolderListHeadPtr){ if (!CurrentFolder) CurrentFolder = FindFolderWithEntryIndex(FolderListHeadPtr, ROOTENTRYINDEX); //-- Create Status line -- strcpy(TmpStr, CurrentFile); strcat(TmpStr, STATUSLINEFILEFFOLDERSEPERATOR); strcat(TmpStr, CurrentFolder->Name); //-- Display Menu with Status Line -- CUIListPrompt(CUIListHeadPtr, CUIListCurrentPtr, TmpStr, LastKey); } else { //-- Display Menu Without Status line -- CUIListPrompt(CUIListHeadPtr, CUIListCurrentPtr, "No Current File", LastKey); }//end if //-- Handle input -- switch (LastKey){ case FILEMENUKEYUC: case FILEMENUKEYLC: //-- File Menu -- //-- Call Menu -- FileMenu(CurrentFile, BookmarkListHeadPtr, FolderListHeadPtr, CurrentFolder, QuitFlag); //-- Refresh contents of the main display list box -- MakeCUIListFromCurrentFolder(FolderListHeadPtr, BookmarkListHeadPtr, CUIListHeadPtr, CurrentFolder); break; case EDITMENUUC: case EDITMENULC: //-- Edit Menu -- //-- No File Loaded check -- if (!FolderListHeadPtr) break; //-- Call Menu -- EditMenu(CUIListCurrentPtr); //-- Refresh contents of the main display list box -- MakeCUIListFromCurrentFolder(FolderListHeadPtr, BookmarkListHeadPtr, CUIListHeadPtr, CurrentFolder); break; case SEARCHMENUUC: case SEARCHMENULC: //-- Search Menu -- //-- No File Loaded check -- if (!FolderListHeadPtr) break; //-- Call menu -- SearchMenu(BookmarkListHeadPtr, FolderListHeadPtr, CUIListHeadPtr); break; case PROGMENUKEYUC: case PROGMENUKEYLC: //-- Program Menu -- //-- Call Menu -- ProgramMenu(); break; case WAMMENUKEYUC: case WAMMENUKEYLC: //-- WAM Menu -- //-- No File Loaded check -- if (!FolderListHeadPtr) break; //-- Call Menu -- WAMMenu(BookmarkListHeadPtr, FolderListHeadPtr, CurrentFolder, CUIListHeadPtr, CUIListCurrentPtr); //-- Refresh contents of the main display list box -- MakeCUIListFromCurrentFolder(FolderListHeadPtr, BookmarkListHeadPtr, CUIListHeadPtr, CurrentFolder); break; case KEY_ASCII_ENTER: //-- Navigate -- if (!CUIListCurrentPtr) break; //-- Move to subfolder, or view bookmark -- if (CUIListCurrentPtr->Flag == FOLDERFLAG){ //-- If folder, move to it -- CurrentFolder = (FolderDataPtr) CUIListCurrentPtr->MoreInfoPtr; //-- Refresh contents of the main display list box -- MakeCUIListFromCurrentFolder(FolderListHeadPtr, BookmarkListHeadPtr, CUIListHeadPtr, CurrentFolder); } //end if - folder else if (CUIListCurrentPtr->Flag == BOOKMARKFLAG){ //-- If bookmark, display it -- ShowBookmark(*(BookmarkDataPtr)CUIListCurrentPtr->MoreInfoPtr); }// end if-bookmark break; default: beep(); }//end switch }//end while CUIDestroyWindow(); //Destroy Window //-- Shutdown CUI --- CUIShutdown(); }//end WebAddressManager ////////////////////////////////////////////////////////// // FileMenu // // // // Displays file menu and calls load, import, save, // // and close functions. Function queries user and // // branches via a case statement. // // // // CALLED BY: WebAddressManager // // CALLS: // // CUICreateList // // CUIListPrompt // // CUIDestroyList // // DestroyFolderList // // DestroyBookmarkList // // InputWALFile // // ImportBookmarks // // OutputWALFile // // FileExists // // ChangeFileExtension // // // // Parameters: // // BookmarkDataPtr BookmarkListHeadPtr: In & Out - // // pointer to the first item in the bookmarklist // // FolderDataPtr FolderListHeadPtr: In & Out - pointer // // to the first item in the folderlist // // FolderDataPtr CurrentFolder: In & Out - pointer to // // the current folder. // // // // REVISIONS: DATE, REASON // // AUTHOR FOR EACH (if different) // // VERSION: x.xx // ////////////////////////////////////////////////////////// void FileMenu(char CurrentFile[], BookmarkDataPtr &BookmarkListHeadPtr, FolderDataPtr &FolderListHeadPtr, FolderDataPtr &CurrentFolder, bool &TellProgramToQuit){ //-- Constant Declarations -- const char NEWFLAG = 'N'; //Flag New const char ADDFLAG = 'A'; //Flag Add const char IMPORTFLAG = 'I'; //Flag Import const char OPENFLAG = 'O'; //Flag Open const char SAVEFLAG = 'S'; //Flag Save const char SAVEASFLAG = 'A'; //Flag Save As const char CLOSEFLAG = 'C'; //Flag Close const char QUITFLAG = 'Q'; //Flag Quit const char MENUDEFINITIONFILENAME[13] = "FileMenu.txt"; //File containing menu title const FileMenuX = 0; //Horizontal Coord of menu const FileMenuY = 0; //Vertical Coord of menu const FileMenuW = 11; //Width of menu const FileMenuH = 9; //Height of menu //-- Variable Declarations -- //-- UI Stuff -- int LastKey = -1; //Last key pressed before returning from CUIListPrompt char AreYouSure[1]; //User resopnse for Are You Sure boxes CUIListItemPtr CUIFMenu; //Pointer to the 1st item in the main display area list CUIListItemPtr CUIFMenuSel=null;//Pointer to the currently selected item in the main display area //-- Scratch Variables -- char TmpStr[StringLength+1]; //Scratch variable used in concatonating strings //-- File Stuff -- char ErrorFile[StringLength+1]; //Path & filemame of the HTML Import Errpr Log file //-- New List stuff -- FolderDataStruct RootFolder; //Used in creating new WAM file //-- Create CUIList -- CUICreateList(CUIFMenu); LoadMenuFromFile(CUIFMenu, MENUDEFINITIONFILENAME); //-- Dislplay List -- CUICreateWindow(FileMenuX, FileMenuY, FileMenuW, FileMenuH); //Create Filebox CUIListPrompt(CUIFMenu, CUIFMenuSel, "File", LastKey); //Constant won't work here CUIDestroyWindow(); //Destroy Filebox //-- Handle User input -- if (LastKey==KEY_ASCII_ENTER && CUIFMenuSel){ switch (CUIFMenuSel->Flag){ case (NEWFLAG): //-- New -- //Note: This could be implimented by calling PromptAddFolder. Using // PromptAddFolder would be a kludge, though, because I would have to // create a phantum CurrentFolder that would act as a parent for the // root. I decided to skip the kludge and write code similar to // PromptAddFolder, just because I hate using the wrong tool for the // job more than a kludge like this one... //-- if nothing loaded -- if (!FolderListHeadPtr && !BookmarkListHeadPtr){ //-- Create Window -- CUICreateWindow(StandardDialogX,StandardDialogY,StandardDialogW,StandardDialogH); //-- Assign Data -- //-- Title -- CUIDialogStringPrompt("Title for new WAM file?", "New", RootFolder.Name, StandardDialogInputLength); //Constants won't work here //-- Comments -- CUIDialogStringPrompt("Comments?", "New", RootFolder.Comment, StandardDialogInputLength); //Constants won't work here //-- Time -- RootFolder.AddDate = GetUTCTime("Today's date", null); //Constant strings won't work here //-- Heirarchy Managment -- RootFolder.EntryIndex = ROOTENTRYINDEX; RootFolder.ParentEntryIndex = ROOTPARENTENTRYINDEX; //-- Add to list -- AddFolder(RootFolder, FolderListHeadPtr); //-- Destroy Window -- CUIDestroyWindow(); } else { //-- If something is allready loaded -- CUICreateWindow(StandardDialogX,StandardDialogY,StandardDialogW,StandardDialogH); CUIDialogOk("A file is loaded!", "New Error"); //Constants won't work here CUIDestroyWindow(); }// end if-file loaded break; case IMPORTFLAG: //-- Import -- //-- Create Window -- CUICreateWindow(StandardDialogX,StandardDialogY,StandardDialogW,StandardDialogH); if (!FolderListHeadPtr && !BookmarkListHeadPtr){ //File loaded check //-- Get & Calculate Filenames -- CUIDialogStringPrompt("Enter the path and filename of the HTML Bookmark file to import:", "Import", CurrentFile, StandardDialogInputLength); //Constants won't work here strcpy(ErrorFile, CurrentFile); ChangeFilenameExtension(ErrorFile, ERRORFILEEXTEION); //-- Import HTML File -- if (FileExists(CurrentFile)){ //-- If file exists, Import HTML file -- ImportBookmarks(BookmarkListHeadPtr, FolderListHeadPtr, CurrentFile, ErrorFile); } else { //-- Else Display Error Message -- CUIDialogOk("Could not load HTML file", "Import Error"); //Constants won't work here }//end if input-failure //-- Set Current Folder -- CurrentFolder = FolderListHeadPtr; } else { //-- If something is allready loaded -- beep(); CUIDialogOk("A file is allready loaded!", "Import Error"); //Constants won't work here }//end if-something loaded //-- Destroy Window -- CUIDestroyWindow(); break; case OPENFLAG: //-- Open -- //-- Create Window -- CUICreateWindow(StandardDialogX,StandardDialogY,StandardDialogW,StandardDialogH); if (!FolderListHeadPtr && !BookmarkListHeadPtr){ //-- If there are no bookmarks or folders loaded -- //-- Get Filename -- CUIDialogStringPrompt("Enter the path and filename of the WAM file to open(without extension):", "Open", CurrentFile, StandardDialogInputLength); //Constants won't work here strcat(CurrentFile, WAMFILEEXTENSION); //-- Load WAL File -- if (FileExists(CurrentFile)){ //-- If file exists, load WAL file -- InputWALFile(BookmarkListHeadPtr, FolderListHeadPtr, CurrentFile); } else { //-- Else Display Error Message -- beep(); CUIDialogOk("Could not load WAM file", "Open Error"); //Constants won't work here CurrentFile[0] = '\0'; }//end if input-failure //-- Set Current Folder -- CurrentFolder = FolderListHeadPtr; } else { //-- If something is allready loaded -- beep(); CUIDialogOk("A file is allready loaded!", "Open Error"); //Constants won't work here }//end if-something loaded //-- Destroy Window -- CUIDestroyWindow(); break; case SAVEFLAG: //-- Save -- ChangeFilenameExtension(CurrentFile, WAMFILEEXTENSION); if (!OutputWALFile(BookmarkListHeadPtr, FolderListHeadPtr, CurrentFile)){ //-- Display error message -- beep(); CUICreateWindow(StandardDialogX,StandardDialogY,StandardDialogW,StandardDialogH); CUIDialogOk("Could not save file!", "Save Errror"); //Constants won't work here CUIDestroyWindow(); }//end if break; case SAVEASFLAG: //-- Get new filename -- //-- Create Window -- CUICreateWindow(StandardDialogX,StandardDialogY,StandardDialogW,StandardDialogH); //-- Get Filename -- CUIDialogStringPrompt("Enter the path and filename to save(eithout extension):", "Save As", TmpStr, StandardDialogInputLength); //-- Destroy Window -- CUIDestroyWindow(); //-- exit if filename not entered -- if (TmpStr[0]){ strcpy(CurrentFile, TmpStr); strcat(CurrentFile, WAMFILEEXTENSION); } else { break; }//end if //-- Write output -- if (!OutputWALFile(BookmarkListHeadPtr, FolderListHeadPtr, CurrentFile)){ //-- Display error message -- CUICreateWindow(StandardDialogX,StandardDialogY,StandardDialogW,StandardDialogH); beep(); CUIDialogOk("Could not save file!", "Save As Errror"); CUIDestroyWindow(); }//end if break; case CLOSEFLAG: //-- Close -- //-- If nothing is loaded, abort -- if (!BookmarkListHeadPtr && !FolderListHeadPtr) break; //-- Are you sure? -- CUICreateWindow(StandardDialogX,StandardDialogY,StandardDialogW,StandardDialogH);;//Create Window CUIDialogStringPrompt("Close the current file(Y/N)?", "Are you sure?", AreYouSure, AreYouSureInputWidth); CUIDestroyWindow(); if (AreYouSure[0] != AreYouSureYESUC && AreYouSure[0] != AreYouSureYESLC) break; //-- Destroy Lists -- DestroyFolderList(FolderListHeadPtr); DestroyBookmarkList(BookmarkListHeadPtr); CurrentFile[0]=null; break; case QUITFLAG: //-- Quit -- //-- Are you sure? -- CUICreateWindow(StandardDialogX,StandardDialogY,StandardDialogW,StandardDialogH);//Create Window CUIDialogStringPrompt("Exit from the WAM(Y/N)?", "Are you sure?", AreYouSure, AreYouSureInputWidth); CUIDestroyWindow(); if (AreYouSure[0] != AreYouSureYESUC && AreYouSure[0] != AreYouSureYESLC) break; //-- Set quit flag -- TellProgramToQuit = true; break; }//end switch } else { //-- If key was not enter, beep -- beep(); } //End if - key is enter //-- Clean Up -- CUIDestroyList(CUIFMenu); }//end FileMenu ////////////////////////////////////////////////////////// // EditMenu // // // // Displays edit menu. Calls edit functions // // // // CALLED BY: WebAddressManager // // CALLS: // // CUICreateList // // CUIDestroyList // // LoadMenuFromFile // // CUIListPrompt // // CUIDialogStringPrompt // // GetUTCTime // // // // Parameters: // // CUIListItemPtr CUICurrentItemPtr: In - Pointer to // // the currently selected list item. // // // // REVISIONS: DATE, REASON // // AUTHOR FOR EACH (if different) // // VERSION: x.xx // ////////////////////////////////////////////////////////// void EditMenu(CUIListItemPtr CUICurrentItemPtr){ //-- Constant Declarations -- const char EDIT_TITLE_FLAG = 'T'; //Flag Edit Title const char EDIT_URL_FLAG = 'U'; //Flag edit Link Text const char EDIT_ADDDATE_FLAG = 'A'; //Flag edit add date const char EDIT_VISITDATE_FLAG = 'V'; //Flag edit Visit Date const char EDIT_MODIFYDATE_FLAG = 'M';//Flag edit Modified Date const char EDIT_COMMENT_FLAG = 'C'; //Flag edit Comments... const char MENUDEFINITIONFILENAME[15] = "EditMenu.txt"; //File containing menu titles const EditMenuX = 13; //Horizontal Coord const EditMenuY = 0; //Vertical Coord const EditMenuW = 18; //Width const EditMenuH = 8; //Height //-- Variable Declarations -- int LastKey = -1; //Last key pressed before returning from CUIListPrompt CUIListItemPtr CUIEMenu; //Pointer: 1st item in the main display area list CUIListItemPtr CUIEMenuSel=null;//Pointer: currently selected item in the Edit menu //-- Initialize and fill lists -- CUICreateList(CUIEMenu); LoadMenuFromFile(CUIEMenu, MENUDEFINITIONFILENAME); //-- Dislplay List -- CUICreateWindow(EditMenuX,EditMenuY,EditMenuW,EditMenuH); //Create box CUIListPrompt(CUIEMenu, CUIEMenuSel, "Edit", LastKey); CUIDestroyWindow(); //Destroy box //-- Handle User input -- if (LastKey==KEY_ASCII_ENTER && CUIEMenuSel){ switch (CUIEMenuSel->Flag){ case EDIT_TITLE_FLAG: //-- Edit "Title" -- //-- Create Window -- CUICreateWindow(StandardDialogX,StandardDialogY,StandardDialogW,StandardDialogH); //-- Edit Bookmark Title -- if (CUICurrentItemPtr->Flag == BOOKMARKFLAG){ CUIDialogStringPrompt("New name for this bookmark?","Edit Bookmark Title",((BookmarkDataPtr)CUICurrentItemPtr->MoreInfoPtr)->Name, StandardDialogInputLength); }//end if-bookmark //-- Edit Folder Title -- else if (CUICurrentItemPtr->Flag == FOLDERFLAG){ CUIDialogStringPrompt("New name for this folder?","Edit Folder Title", ((FolderDataPtr)CUICurrentItemPtr->MoreInfoPtr)->Name, StandardDialogInputLength); }//end if-folder //-- Destroy Window -- CUIDestroyWindow(); break; case EDIT_URL_FLAG: //-- Edit "URL" -- //-- Create Window -- CUICreateWindow(StandardDialogX,StandardDialogY,StandardDialogW,StandardDialogH); //-- Edit URL Text -- if (CUICurrentItemPtr->Flag == BOOKMARKFLAG){ CUIDialogStringPrompt("New URL for this bookmark?","Edit URL",((BookmarkDataPtr)CUICurrentItemPtr->MoreInfoPtr)->URL, StandardDialogInputLength); }//end if-bookmark //-- Destroy Window -- CUIDestroyWindow(); break; case EDIT_ADDDATE_FLAG: //-- Edit Add Date -- //-- If it's a bookmark -- if (CUICurrentItemPtr->Flag == BOOKMARKFLAG){ ((BookmarkDataPtr)CUICurrentItemPtr->MoreInfoPtr)->AddDate = GetUTCTime("New Add date for this bookmark?", ((BookmarkDataPtr)CUICurrentItemPtr->MoreInfoPtr)->AddDate); }//end if-bookmark //-- if it's a folder -- else if (CUICurrentItemPtr->Flag == FOLDERFLAG){ ((FolderDataPtr)CUICurrentItemPtr->MoreInfoPtr)->AddDate = GetUTCTime("New Add date for this folder?", ((FolderDataPtr)CUICurrentItemPtr->MoreInfoPtr)->AddDate); }//end if-Folder break; case EDIT_VISITDATE_FLAG: //-- Edit "Last Vistit" Date -- //-- If it's a bookmark -- if (CUICurrentItemPtr->Flag == BOOKMARKFLAG){ ((BookmarkDataPtr)CUICurrentItemPtr->MoreInfoPtr)->LastVisit = GetUTCTime("New Add date for this bookmark?", ((BookmarkDataPtr)CUICurrentItemPtr->MoreInfoPtr)->LastVisit); }//end if-bookmark break; case EDIT_MODIFYDATE_FLAG: //-- Edit "Last Modify" Date -- //-- If it's a bookmark -- if (CUICurrentItemPtr->Flag == BOOKMARKFLAG){ ((BookmarkDataPtr)CUICurrentItemPtr->MoreInfoPtr)->LastModified = GetUTCTime("New Add date for this bookmark?", ((BookmarkDataPtr)CUICurrentItemPtr->MoreInfoPtr)->LastModified); }//end if-bookmark break; case EDIT_COMMENT_FLAG: //-- Edit "Title" -- //-- Create Window -- CUICreateWindow(StandardDialogX,StandardDialogY,StandardDialogW,StandardDialogH); //-- Edit Bookmark Title -- if (CUICurrentItemPtr->Flag == BOOKMARKFLAG){ CUIDialogStringPrompt("New comment for this bookmark?","Edit Bookmark Comment",((BookmarkDataPtr)CUICurrentItemPtr->MoreInfoPtr)->Comment, StandardDialogInputLength); }//end if-bookmark //-- Edit Folder Title -- else if (CUICurrentItemPtr->Flag == FOLDERFLAG){ CUIDialogStringPrompt("New comment for this folder?","Edit Folder Comment", ((FolderDataPtr)CUICurrentItemPtr->MoreInfoPtr)->Comment, StandardDialogInputLength); }//end if-folder //-- Destroy Window -- CUIDestroyWindow(); break; }//end switch } else { //-- If LastKey was not enter -- beep(); }//end if - lastkey was enter and something was selected //-- Clean up -- CUIDestroyList(CUIEMenu); }//end EditMenu ////////////////////////////////////////////////////////// // WAMMenu // // // // Displays WAM menu and calls PromptAddFolder, // // PromptAddBookmark, RemoveFolder, RemoveBookmark, // // MoveFolder, MoveBookmark, or ShowBookmark. // // Function queries user and branches via a case // // statement. // // // // CALLED BY: WebAddressManager // // CALLS: // // CUICreateList // // CUIListPrompt // // CUIDestroyList // // PromptAddBookmark // // PromptAddFolder // // MoveFolder // // MoveBookmark // // // // Parameters: // // BookmarkDataPtr BookmarkListPtr: In - pointer to // // the head of the bookmark list // // FolderDataPtr FolderListPtr: In - pointer to the // // head of the folder list // // FolderDataPtr CurrentFolder: In - pointer to the // // current folder // // CUIListItemPtr CUIListHeadPtr: In - Pointer to the // // head of the main display area list // // CUIListItemPtr CUICurrentItemPtr: In - Pointer to // // the currently selected list item in the main // // display area // // // // REVISIONS: DATE, REASON // // AUTHOR FOR EACH (if different) // // VERSION: x.xx // ////////////////////////////////////////////////////////// void WAMMenu(BookmarkDataPtr &BookmarkListPtr, FolderDataPtr &FolderListPtr, FolderDataPtr CurrentFolder, CUIListItemPtr CUIListHeadPtr, CUIListItemPtr CUICurrentItemPtr){ //-- Constant Declarations -- //-- WAM pulldown menu -- const WAMMenuX = 26; //Horizontal Coordinate of the dialog menu const WAMMenuY = 0; //Vertical Coordinate of the dialog menu const WAMMenuW = 19; //Height of the menu const WAMMenuH = 7; //Width of the menu //-- Destination Box -- const DestinationBoxX = 1; //Horizontal Coordinate of the folder/bookmark destination box const DestinationBoxY = 2; //Vertical Coordinate of the folder/bookmark destination box const DestinationBoxW = 78; //Width of the desination box const DestinationBoxH = 20; //Height of the desination box //-- Style-of-delete-prompt info -- const DeleteStyleInputLength = 1; //Width of the deletestyly input length const char RECURSIVEDELETEUC = 'R'; //Key for recursive delete uppercase const char RECURSIVEDELETELC = 'r'; //Key for recursive delete lowercase const char SHIFTDELETEUC = 'S'; //Key for shift delete uppercase const char SHIFTDELETELC = 's'; //Key for shift delete lowercase //-- View Info -- const char VIEWSCRATCHFILE[13] = {"ViewTemp.txt"};//The temporary file used by view //-- Flags -- const char ADDBOOKMARKFLAG = 'B'; //Flag Create Bookmark const char ADDFOLDERFLAG = 'F'; //Flag Create Folder const char DELETEFLAG = 'D'; //Flag Delete Current item const char MOVEFLAG = 'M'; //Flag Move const char VIEWFLAG = 'V'; //Flag View const char MENUDEFINITIONFILENAME[12] = "WAMMenu.txt"; //File containing menu titles //-- Variable Declarations -- //-- Drop-down menu -- CUIListItemPtr CUIWMenu; //Pointer to the 1st item in the main display area list CUIListItemPtr CUIWMenuSel = null; //Pointer to the currently selected item in the main display area CUIListItemPtr CUIDestMenu; //Pointer to the 1st item of the destination box list CUIListItemPtr CUIDestMenuItemSelected = null;//Pointer to the currently selected item in the destination list int LastKey = -1; //Last key pressed before returning from CUIListPrompt //-- Delete -- FolderDataPtr FolderToDelete; //Pointer to the folder to nuke. Eases type-casting & readability. BookmarkDataPtr BookmarkToDelete; //Pointer to the Bookmark to nuke. Eases type-casting & readability. char DeleteTypeUserResponse[2]; //The user's response to the type-of-delete-prompt //-- Move -- FolderDataPtr DestinationFolder; //Pointer to the destination folder during move. Aids in //typecasting and readability FolderDataPtr FolderToMove; //Pointer to the that will be moved. Aids in checking typecasting //and readability BookmarkDataPtr BookmarkToMove; //Pointer to the bookmark that will be moved to DesinationFolder. //Aids in typecasting and readability //-- Initialize and fill lists -- CUICreateList(CUIWMenu); LoadMenuFromFile(CUIWMenu, MENUDEFINITIONFILENAME); //-- Dislplay List -- CUICreateWindow(WAMMenuX,WAMMenuY,WAMMenuW,WAMMenuH); //Create WAM Menu box CUIListPrompt(CUIWMenu, CUIWMenuSel, "WAM", LastKey); CUIDestroyWindow(); //Destroy Filebox //-- Handle User Response -- if (LastKey==KEY_ASCII_ENTER && CUIWMenuSel){ switch (CUIWMenuSel->Flag){ case ADDBOOKMARKFLAG: //-- Add Bookmark -- PromptAddBookmark(BookmarkListPtr, CurrentFolder); break; case ADDFOLDERFLAG: //-- Add Folder -- PromptAddFolder(FolderListPtr, CurrentFolder); break; case DELETEFLAG: //-- Delete -- //-- RootFolderCheck -- if ( CUICurrentItemPtr->Flag == FOLDERFLAG && ((FolderDataPtr)CUICurrentItemPtr->MoreInfoPtr)->EntryIndex == ROOTENTRYINDEX ){ //-- Beep & Display Error Message -- beep(); CUICreateWindow(StandardDialogX, StandardDialogY, StandardDialogW, StandardDialogH); //Create Window CUIDialogOk("Root folder cannot be deleted!", "Impossible Request"); CUIDestroyWindow(); //-- Exit -- break; }//end if-we're trying to do something with the root folder //-- Delete Folder -- if (CUICurrentItemPtr->Flag == FOLDERFLAG){ //-- Typecast Pointer to folder -- FolderToDelete = (FolderDataPtr)CUICurrentItemPtr->MoreInfoPtr; //-- Create Window -- CUICreateWindow(StandardDialogX, StandardDialogY, StandardDialogW, StandardDialogH); //-- Prompt user for type of delete -- CUIDialogStringPrompt("(R)ecursive delete or (S)hift delete?", "Delete Style", DeleteTypeUserResponse, DeleteStyleInputLength); //-- Delete based on user's response -- if (DeleteTypeUserResponse[0] == SHIFTDELETEUC || DeleteTypeUserResponse[0] == SHIFTDELETELC){ RemoveFolder(FolderListPtr, BookmarkListPtr, FolderToDelete, EDeleteShift); }//end if-shift-style-delete else if (DeleteTypeUserResponse[0] == RECURSIVEDELETEUC || DeleteTypeUserResponse[0] == RECURSIVEDELETELC){ RemoveFolder(FolderListPtr, BookmarkListPtr, FolderToDelete, EDeleteAll); }//end if-recursive-style-delete else { beep(); CUIDialogOk("No delete type specified; nothing deleted", "Error"); }//end all-else //-- Destroy Window -- CUIDestroyWindow(); }//end if-folder //-- Delete Bookmark -- if (CUICurrentItemPtr->Flag == BOOKMARKFLAG){ BookmarkToDelete = (BookmarkDataPtr)CUICurrentItemPtr->MoreInfoPtr; RemoveBookmark(BookmarkListPtr, BookmarkToDelete); }//end if-Bookmark break; case MOVEFLAG: //-- Move Bookmark or folder -- //-- RootFolderCheck -- if ( CUICurrentItemPtr->Flag == FOLDERFLAG && ((FolderDataPtr)CUICurrentItemPtr->MoreInfoPtr)->EntryIndex == ROOTENTRYINDEX ){ //-- Beep & Display Error Message -- beep(); CUICreateWindow(StandardDialogX, StandardDialogY, StandardDialogW, StandardDialogH); //Create Window CUIDialogOk("Root folder cannot be moved!", "Impossible Request"); CUIDestroyWindow(); //-- Exit -- break; }//end if-we're trying to do something with the root folder //-- Create window -- CUICreateWindow(DestinationBoxX, DestinationBoxY, DestinationBoxW, DestinationBoxH); //Create Window CUICreateList(CUIDestMenu); CUIDestMenuItemSelected = null; //Initialize CUI List MakeCUIListFromCurrentFolder(FolderListPtr, BookmarkListPtr, CUIDestMenu, CurrentFolder);//Copy parent folder and child folder to list CUIListPrompt(CUIDestMenu, CUIDestMenuItemSelected, "Select Destination", LastKey); //Prompt user for destination CUIDestroyWindow(); //-- If it's a bookmark -- if (CUICurrentItemPtr->Flag == BOOKMARKFLAG){ //-- Move Bookmark -- //Assign the entryindex of the folder selected in the //Destination Box to the bookmark selected in the main menu. //Pointers have to be typecased and than dereferenced. //-- Typecase Generic Pointers -- DestinationFolder = (FolderDataPtr)CUIDestMenuItemSelected->MoreInfoPtr; BookmarkToMove = (BookmarkDataPtr)CUICurrentItemPtr->MoreInfoPtr; //-- Move Bookmark -- BookmarkToMove->ParentEntryIndex = DestinationFolder->EntryIndex; }//end if-bookmark //-- If it's a folder -- else if (CUICurrentItemPtr->Flag == FOLDERFLAG){ //-- Move Folder -- //Promote: Typecast pointers, Promote folder by changing EntryIndex //-- Typecast pointers -- FolderToMove = (FolderDataPtr)CUICurrentItemPtr->MoreInfoPtr; DestinationFolder = (FolderDataPtr)CUIDestMenuItemSelected->MoreInfoPtr; //-- If it's a promotion -- if (FolderToMove->EntryIndex != DestinationFolder->ParentEntryIndex){ FolderToMove->ParentEntryIndex = DestinationFolder->EntryIndex; }//end if-it's a promotion else { beep(); }//end all-else }//end if-Folder break; case VIEWFLAG: //-- View -- //-- Create Screatch File -- ExportTree(FolderListPtr, BookmarkListPtr, VIEWSCRATCHFILE); //-- View scratch file -- CUICreateWindow(MainDisplayAreaX, MainDisplayAreaY, MainDisplayAreaW, MainDisplayAreaH); CUIDisplayFile("ViewTemp.txt"); CUIDestroyWindow(); break; }//end switch }else { //-- If lastkey was not enter -- beep(); }//end if - lastkey was enter //-- Clean up -- CUIDestroyList(CUIWMenu); }//end WAMMenu ////////////////////////////////////////////////////////// // SearchMenu // // // // Displays Search menu and adds matches to list. // // // // CALLED BY: WebAddressManager // // CALLS: // // CUICreateList // // CUIListPrompt // // CUIDestroyList // // // // Parameters: // // BookmarkDataPtr BookmarkListPtr: In - pointer to // // the head of the bookmark list // // FolderDataPtr FolderListPtr: In - pointer to the // // head of the folder list // // CUIListItemPtr CUIListHeadPtr: In - Pointer to // // the head of the CUI list for the main display // // area. // // // // REVISIONS: DATE, REASON // // AUTHOR FOR EACH (if different) // // VERSION: x.xx // ////////////////////////////////////////////////////////// void SearchMenu(BookmarkDataPtr BookmarkListPtr, FolderDataPtr FolderListPtr, CUIListItemPtr &CUIListHeadPtr){ //-- Constant Declarations -- const char LOOKFOLDERFLAG = 'F'; //Flag look through folders const char LOOKBOOKMARKFLAG = 'B'; //Flag look though bookmarks const char MENUDEFINITIONFILENAME[15] = "SearchMenu.txt"; //File containing menu titles const SearchMenuX = 38; //Horizontal Coordinate of search menu const SearchMenuY = 0; //Vertical Coordinate of search menu const SearchMenuH = 15; //Width of search menu const SearchMenuW = 4; //Height of search menu //-- Variable Declarations -- int LastKey = -1; //Last key pressed before returning from CUIListPrompt CUIListItemPtr CUISMenu; //Pointer to the 1st item in the main display area list CUIListItemPtr CUISMenuSel=null; //Pointer to the currently selected item in the main display area FolderDataPtr FolderSearchPtr; //Used for the folder search BookmarkDataPtr BookmarkSearchPtr; //Used for the Bookmark search char StringToFind[StringLength+1]; //String to search for //-- Initialize and fill lists -- CUICreateList(CUISMenu); LoadMenuFromFile(CUISMenu, MENUDEFINITIONFILENAME); //-- Dislplay List -- CUICreateWindow(SearchMenuX,SearchMenuY,SearchMenuH,SearchMenuW); //Create search menu box CUIListPrompt(CUISMenu, CUISMenuSel, "Search", LastKey); CUIDestroyWindow(); //Destroy box //-- Handle User input -- if (LastKey==KEY_ASCII_ENTER && CUISMenuSel){ //-- Get string to search for -- CUICreateWindow(StandardDialogX,StandardDialogY,StandardDialogW,StandardDialogH); CUIDialogStringPrompt("Enter the partial or complete title to search for:", "Search", StringToFind, StandardDialogInputLength); CUIDestroyWindow(); //-- Find folder or bookmark -- switch (CUISMenuSel->Flag){ case LOOKFOLDERFLAG: //-- Find Folders -- //-- Empty List & Add Root -- CUIDestroyList(CUIListHeadPtr); AddOneFolderToCUIList(FindFolderWithEntryIndex(FolderListPtr, ROOTENTRYINDEX), CUIListHeadPtr, EFolderParentLabel); //-- Find all folders matching the criteria -- FolderSearchPtr = FindFolderWithName(FolderListPtr, StringToFind); //Priming Search while (FolderSearchPtr){ //-- Add Folder -- AddOneFolderToCUIList(FolderSearchPtr, CUIListHeadPtr, EFolderNoLabel); //-- Find next Folder -- FolderSearchPtr = FindFolderWithName(FolderSearchPtr->LinkNext, StringToFind); }//end while break; case LOOKBOOKMARKFLAG: //-- Find Bookmarks -- //-- Empty List & Add Root -- CUIDestroyList(CUIListHeadPtr); AddOneFolderToCUIList(FindFolderWithEntryIndex(FolderListPtr, ROOTENTRYINDEX), CUIListHeadPtr, EFolderParentLabel); //-- Find all bookmarks matching the criteria -- BookmarkSearchPtr = FindBookmarkWithName(BookmarkListPtr, StringToFind); //Priming Search while (BookmarkSearchPtr){ //-- Add Bookmark -- AddOneBookmarkToCUIList(BookmarkSearchPtr, CUIListHeadPtr); //-- Find next Folder -- BookmarkSearchPtr = FindBookmarkWithName(BookmarkSearchPtr->LinkNext, StringToFind); }//end while break; }//end switch } else { //-- If last key was not enter -- beep(); }//end if - lastkey was enter //-- Clean up -- CUIDestroyList(CUISMenu); }//end SearchMenu ////////////////////////////////////////////////////////// // ProgramMenu // // // // Displays program menu with options "About" and // // "Help" // // // // Algorithm: Query and switch // // // // CALLED BY: main // // CALLS: // // CUICreateWindow // // CUIDestroyWindow // // CUICreateList // // CUIDestroyList // // CUIDialogStringPrompt // // CUIDisplayFile // // // // PARAMETERS: None // // // // REVISIONS: DATE, REASON // // AUTHOR FOR EACH (if different) // // VERSION: x.xx // ////////////////////////////////////////////////////////// void ProgramMenu(){ //-- Constant Declarations -- const char ABOUTFLAG = 'A'; //Flag About const char HELPFLAG = 'H'; //Flag Help const char MENUDEFINITIONFILENAME[13] = "ProgMenu.txt"; //File containing menu titles const ProgMenuX = 53; //Horiz coord of menu const ProgMenuY = 0; //Very coorf of menu const ProgMenuW = 11; //Width of menu const ProgMenuH = 4; //Height of menu //-- Variable Declarations -- CUIListItemPtr ProgMenuPtr; //Pointer to the head of the list CUIListItemPtr ProgMenuSelPtr; //Pointer to the head of the list int LastKey; //The key the user pressed while in the window //-- Initialize -- ProgMenuSelPtr = null; LastKey = -1; //-- Create Menu -- CUICreateList(ProgMenuPtr); LoadMenuFromFile(ProgMenuPtr, MENUDEFINITIONFILENAME); //-- Display Menu -- CUICreateWindow(ProgMenuX,ProgMenuY,ProgMenuW,ProgMenuH); CUIListPrompt(ProgMenuPtr, ProgMenuSelPtr, "Program", LastKey); CUIDestroyWindow(); //-- Handle input -- if (LastKey == KEY_ASCII_ENTER && ProgMenuSelPtr){ CUICreateWindow(MainDisplayAreaX, MainDisplayAreaY, MainDisplayAreaW, MainDisplayAreaH); //Create window in which to display file switch(ProgMenuSelPtr->Flag){ case ABOUTFLAG: CUIDisplayFile("About.txt"); //Show about screen break; case HELPFLAG: CUIDisplayFile("Help.txt"); //Show help screen break; }//end switch CUIDestroyWindow(); //Remove the window } else { //-- If last key was not enter -- beep(); }//end if //-- Clean up -- CUIDestroyList(ProgMenuPtr); }//end ProgramMenu ////////////////////////////////////////////////////////// // LoadMenuFromFile // // // // Loads the contents of a menu from a file into a // // CUI List. // // // // CALLED BY: // // FileMenu // // EditMenu // // WAMMenu // // ProgramMenu // // CALLS: // // CUIAddItem // // File Streams // // // // PARAMETERS: NAME AND ROLE IN ALGORITHM OF EACH // // // // REVISIONS: DATE, REASON // // AUTHOR FOR EACH (if different) // // VERSION: x.xx // ////////////////////////////////////////////////////////// void LoadMenuFromFile(CUIListItemPtr &MenuList, const char FileToLoad[]){ //-- Variable Declarations -- CUIListItem NewItem; //The item to be added to the list ifstream InFile; //File from which to read info //-- Open File -- InFile.open(FileToLoad, ios::nocreate); //-- Priming Read -- InFile.get(NewItem.Flag); InFile.getline(NewItem.Title, StringLength); while (InFile){ //-- Add to list -- NewItem.MoreInfoPtr = null; if (NewItem.Flag != ';') CUIAddItem(MenuList, NewItem); //-- Read Next Line -- InFile.get(NewItem.Flag); InFile.getline(NewItem.Title, StringLength); }//end while }//End LoadMenuFromFile ////////////////////////////////////////////////////////// // MakeCUIListFromCurrentFolder // // // // Make CUI List of the entire contents of the current // // folder. // // // // CALLED BY: WebAddressManager // // CALLS: // // CUIDestroyList // // ChiildFoldersToCUIList // // ChildBookmarksToCUIList // // // // Parameters: // // FolderDataPtr FolderLIstHeadPtr: In - pointer to // // the head of the folder list. // // BookmarkDataPtr BookmarkListHead: In - pointer to // // the head of the bookmarks list // // CUIListItemPtr &CUIListHead: In & Out - Pointer to // // the head of CUI list where the results will be // // stored. // // FolderDataPtr CurrentFolder: In & Out - pointer to // // the current folder // // // // REVISIONS: DATE, REASON // // AUTHOR FOR EACH (if different) // ////////////////////////////////////////////////////////// void MakeCUIListFromCurrentFolder(FolderDataPtr FolderListHeadPtr, BookmarkDataPtr BookmarkListHeadPtr, CUIListItemPtr &CUIListHeadPtr, FolderDataPtr &CurrentFolder){ //-- No current folder check -- if (!CurrentFolder) CurrentFolder = FindFolderWithEntryIndex(FolderListHeadPtr, ROOTENTRYINDEX); //-- Fill Display -- CUIDestroyList(CUIListHeadPtr); ChildFoldersToCUIList(FolderListHeadPtr, CUIListHeadPtr, CurrentFolder); ChildBookmarksToCUIList(BookmarkListHeadPtr, CUIListHeadPtr, CurrentFolder); }//end MakeCUIListFromCurrentFolder ////////////////////////////////////////////////////////// // ChildFoldersToCUIList // // // // Walk through folderlist and add folders child and // // parent to the current folder to the CUIFolderList, // // // // Simple linear search & copy // // // // CALLED BY: WebAddressManager // // CALLS: None // // // // Parameters: // // FolderDataPtr FolderListHeadPtr: In - pointer to // // the first item in the folderlist. // // CUIListItemPtr CUIListHead: In & Out - pointer to // // CUI listhead. // // FolderDataPtr WorkingFolder: In - pointer to the // // present working / current folder. // // // // REVISIONS: DATE, REASON // // AUTHOR FOR EACH (if different) // ////////////////////////////////////////////////////////// void ChildFoldersToCUIList(FolderDataPtr FolderListHeadPtr, CUIListItemPtr &CUIListHead, FolderDataPtr WorkingFolderPtr){ //-- Variable Declarations -- FolderDataPtr FolderBeingExamined; //The folder being examined //-- Initialization & Null list check -- if (!FolderListHeadPtr || !WorkingFolderPtr) return; //-- Add Parent -- FolderBeingExamined = FindFolderWithEntryIndex(FolderListHeadPtr, WorkingFolderPtr->ParentEntryIndex); if (FolderBeingExamined) AddOneFolderToCUIList(FolderBeingExamined, CUIListHead, EFolderParentLabel); //-- Add Children -- FolderBeingExamined = FindFolderWithParentEntryIndex(FolderListHeadPtr, WorkingFolderPtr->EntryIndex); while (FolderBeingExamined){ //-- If this folder is child to WorkingFolderPtr -- AddOneFolderToCUIList(FolderBeingExamined, CUIListHead, EFolderSubLabel); //-- Move to next folder -- FolderBeingExamined = FindFolderWithParentEntryIndex(FolderBeingExamined->LinkNext, WorkingFolderPtr->EntryIndex); }//end while }//end ChildFoldersToCUIList ////////////////////////////////////////////////////////// // AddOneFolderToCUIList // // // // Dereference and add a folder to the provided CUI // // List. Stores a modified version of the folder in // // the CUI list, along with a pointer to the origional // // item for the full information. // // // // CALLED BY: // // ChildFoldersToCUIList // // SearchMenu // // CALLS: CUIAddItem // // // // Parameters: // // FolderDataPtr FolderToAdd: In - A pointer to the // // folder being added // // CUIListItemPtr &CUIListHeadPtr: In & Out - the CUI // // List to which the modified folder contents and // // reference to the origional will be added. // // // // REVISIONS: DATE, REASON // // AUTHOR FOR EACH (if different) // ////////////////////////////////////////////////////////// void AddOneFolderToCUIList(FolderDataPtr FolderToAdd, CUIListItemPtr &CUIListHeadPtr, ENUMFolderToAddLabel FolderLabel){ //-- Variable Declarations -- CUIListItem NewItem; //The item to add to the list time_t UTCTime; //UTC time struct tm ExpandedTime; //Converted time char TmpStr[StringLength+1]; //Temporary string used in string construction/concationation int ForCnt; //For-loop counter //-- Folder Title -- strncpy(NewItem.Title, FolderToAdd->Name, TitleWidth); strcat(NewItem.Title, "/"); for (ForCnt = strlen(NewItem.Title); ForCnt < TitleWidth; ForCnt++) NewItem.Title[ForCnt] = ' '; NewItem.Title[TitleWidth] = null; //-- Time -- UTCTime = FolderToAdd->AddDate; ExpandedTime = *gmtime(&UTCTime); //-- Month -- itoa(ExpandedTime.tm_mon+1, TmpStr, BASETEN); strcat(NewItem.Title," "); strcat(NewItem.Title, TmpStr); //-- Day -- itoa(ExpandedTime.tm_mday, TmpStr, BASETEN); strcat(NewItem.Title,"/"); strcat(NewItem.Title, TmpStr); //-- Year -- itoa(ExpandedTime.tm_year, TmpStr, BASETEN); strcat(NewItem.Title,"/"); strcat(NewItem.Title, TmpStr); //-- Space -- for (ForCnt = strlen(NewItem.Title); ForCnt < TitleWidth+SmallDateWidth; ForCnt++) NewItem.Title[ForCnt] = ' '; NewItem.Title[ForCnt] = null; //-- Label -- if (FolderLabel == EFolderSubLabel) strcat(NewItem.Title, "[ /subfolder ]"); else if (FolderLabel == EFolderParentLabel) strcat(NewItem.Title, "[ ../Parent ]"); //-- Set flag to indicate WAM Folder -- NewItem.Flag = FOLDERFLAG; //-- Set Pointer to the folder -- NewItem.MoreInfoPtr = (void *)FolderToAdd; //-- Add Item to List -- CUIAddItem(CUIListHeadPtr, NewItem); }//end AddOneFolderToCUIList ////////////////////////////////////////////////////////// // ChildBookmarksToCUIList // // // // Walk through bookmarklist and add bookmarks child to // // the current folder to the CUIFolderList, // // // // Simple linear search & copy // // // // CALLED BY: WebAddressManager // // CALLS: CUIAddItem // // // // Parameters: // // BookmarkDataPtr BookmarkListHeadPtr: In - pointer // // to the first item in the bookmarklist. // // CUIListItemPtr CUIListHead: In & Out - pointer to // // CUI listhead. // // FolderDataPtr WorkingFolder: In - pointer to the // // present working / current folder. // // // // REVISIONS: DATE, REASON // // AUTHOR FOR EACH (if different) // ////////////////////////////////////////////////////////// void ChildBookmarksToCUIList(BookmarkDataPtr BookmarkListHeadPtr, CUIListItemPtr &CUIListHead, FolderDataPtr WorkingFolderPtr){ //-- Variable Declarations -- BookmarkDataPtr BookmarkBeingExamined; //The Bookmark being examined //-- Initialization & Null list check -- if (BookmarkListHeadPtr && WorkingFolderPtr) BookmarkBeingExamined = FindBookmarkWithParentEntryIndex(BookmarkListHeadPtr, WorkingFolderPtr->EntryIndex); else return; //-- Traverse List -- while (BookmarkBeingExamined){ AddOneBookmarkToCUIList(BookmarkBeingExamined, CUIListHead); //-- Move to next Bookmark -- BookmarkBeingExamined = FindBookmarkWithParentEntryIndex(BookmarkBeingExamined->LinkNext, WorkingFolderPtr->EntryIndex); }//end while }//end ChildBookmarksToCUIList ////////////////////////////////////////////////////////// // AddOneBookmarkToCUIList // // // // Dereference and add a Bookmark to the provided CUI // // List. Stores a modified version of the Bookmark in // // the CUI list, along with a pointer to the origional // // item for the full information. // // // // CALLED BY: // // ChildBookmarksToCUIList // // SearchMenu // // CALLS: CUIAddItem // // // // Parameters: // // BookmarkDataPtr BookmarkToAdd: In - A pointer to the// // Bookmark being added // // CUIListItemPtr &CUIListHeadPtr: In & Out - the CUI // // List to which the modified Bookmark contents and// // reference to the origional will be added. // // // // REVISIONS: DATE, REASON // // AUTHOR FOR EACH (if different) // ////////////////////////////////////////////////////////// void AddOneBookmarkToCUIList(BookmarkDataPtr BookmarkToAdd, CUIListItemPtr &CUIListHeadPtr){ //-- Variable Declarations -- CUIListItem NewItem; //The item to add to the list time_t UTCTime; //UTC time struct tm ExpandedTime; //Converted time char TmpStr[StringLength+1]; //Temporary string used in string construction/concationation int ForCnt; //For-loop counter //-- Name -- strncpy(NewItem.Title, BookmarkToAdd->Name, TitleWidth); for (ForCnt = strlen(NewItem.Title); ForCnt < TitleWidth; ForCnt++) NewItem.Title[ForCnt] = ' '; NewItem.Title[TitleWidth] = null; //-- Time -- UTCTime = BookmarkToAdd->LastModified; ExpandedTime = *gmtime(&UTCTime); //-- Month -- itoa(ExpandedTime.tm_mon+1, TmpStr, BASETEN); strcat(NewItem.Title," "); strcat(NewItem.Title, TmpStr); //-- Day -- itoa(ExpandedTime.tm_mday, TmpStr, BASETEN); strcat(NewItem.Title,"/"); strcat(NewItem.Title, TmpStr); //-- Year -- itoa(ExpandedTime.tm_year, TmpStr, BASETEN); strcat(NewItem.Title,"/"); strcat(NewItem.Title, TmpStr); //-- Space -- for (ForCnt = strlen(NewItem.Title); ForCnt < TitleWidth+SmallDateWidth; ForCnt++) NewItem.Title[ForCnt] = ' '; NewItem.Title[ForCnt] = '\0'; //-- URL -- strncat(NewItem.Title, BookmarkToAdd->URL, 38); //-- Set flag to indicate WAM Bookmark -- NewItem.Flag = BOOKMARKFLAG; //-- Set Pointer to the Bookmark -- NewItem.MoreInfoPtr = (void *)BookmarkToAdd; //-- Add Item to List -- CUIAddItem(CUIListHeadPtr, NewItem); }//end AddOneBookmarkToCUIList ////////////////////////////////////////////////////////// // ShowBookmark // // // // Displays bookmark information by concatonating // // together strings and using CUI. // // // // // // CALLED BY: WebAddressManager // // CALLS: // // CUICreateWindow() // // CUIDialogOK() // // CUIDestroyWindow // // // // Parameters: // // BookmarkDataStruct BookmarkToDisplay: In - the // // bookmark to display // // // // REVISIONS: DATE, REASON // // AUTHOR FOR EACH (if different) // // VERSION: x.xx // ////////////////////////////////////////////////////////// void ShowBookmark(BookmarkDataStruct BookmarkToDisplay){ //-- Constants Declarations -- const char NEWLINE[2] = {"\n"}; const char NAMELABEL[13] = {"Name: "}; const char URLLABEL[13] = {"URL "}; const char ADDLABEL[13] = {"Add Date "}; const char MODIFYLABEL[13] = {"Modify Date:"}; const char VISITLABEL[13] = {"Last Visit: "}; const char COMMENTLABEL[13] = {"Comments: "}; const ShowURLDialogX = 1; //Horizontal Coordinate of the dialog box const ShowURLDialogY = 2; //Vertical Coordinate of the dialog box const ShowURLDialogH = 10; //Width of the dialog const ShowURLDialogW = 78; //Height of the dialog //-- Variable Declarations -- char DialogText[StringLength+1]; //Text of the dialog box; the target of the concatonation long TmpTime; //Used to temporarily hold UTC time values; removes the need for typecasting //-- Concatonate dialog text -- //-- Name -- strcpy(DialogText, NAMELABEL); strcat(DialogText, BookmarkToDisplay.Name); strcat(DialogText, NEWLINE); //-- URL -- strcat(DialogText, URLLABEL); strcat(DialogText, BookmarkToDisplay.URL); strcat(DialogText, NEWLINE); //-- Add Date -- strcat(DialogText, ADDLABEL); TmpTime = BookmarkToDisplay.AddDate; strcat(DialogText, ctime(&TmpTime)); //-- Modify Date -- strcat(DialogText, MODIFYLABEL); TmpTime = BookmarkToDisplay.LastModified; strcat(DialogText, ctime(&TmpTime)); //-- Last Visit Date -- strcat(DialogText, VISITLABEL); TmpTime = BookmarkToDisplay.LastVisit; strcat(DialogText, ctime(&TmpTime)); //-- URL -- strcat(DialogText, COMMENTLABEL); strcat(DialogText, NEWLINE); strcat(DialogText, BookmarkToDisplay.Comment); //-- Show Dialog Box -- CUICreateWindow(ShowURLDialogX,ShowURLDialogY,ShowURLDialogW,ShowURLDialogH); CUIDialogOk(DialogText, ""); CUIDestroyWindow(); }//end ShowBookmark ////////////////////////////////////////////////////////// // PromptAddBookmark // // // // Prompts the user for bookmark information. // // Defaults passed in. // // // // // // CALLED BY: WAMMenu // // CALLS: // // CUICreateWindow() // // CUIDialogStringPrompt() // // CUIDestroyWindow() // // GetUTCTime() // // AddBookmark() // // // // PARAMETERS: // // BookmarkList: Data in & out - pointer to the first // // item in the bookmark list. // // FolderDataPtr CurrentFolder: Data in -- pointer to // // the current folder. Used to in placing the // // current folder. // // // // VERSION: 1.00 // ////////////////////////////////////////////////////////// void PromptAddBookmark(BookmarkDataPtr &BookmarkList, FolderDataPtr CurrentFolder){ //-- Variable Declarations -- char UserResponse[StringLength+1]; //Used to retrieve the user's response to the prompt BookmarkDataStruct NewBkm; //Contains the information to be added to the bookmark list //-- Get Input -- //-- Create Window -- CUICreateWindow(StandardDialogX,StandardDialogY,StandardDialogW,StandardDialogH); //-- Name -- CUIDialogStringPrompt("Name of Bookmark?", "Add Bookmark", UserResponse, StandardDialogInputLength); strcpy(NewBkm.Name, UserResponse); //-- URL -- CUIDialogStringPrompt("Text of URL? ", "Add Bookmark", UserResponse, StandardDialogInputLength); strcpy(NewBkm.URL, UserResponse); //-- Comment -- CUIDialogStringPrompt("Comments?", "Add Bookmark", UserResponse, StandardDialogInputLength); strcpy(NewBkm.Comment, UserResponse); //-- Destroy Window -- CUIDestroyWindow(); //-- Add Date -- NewBkm.AddDate = GetUTCTime("Today's date?", null); //-- Calculated Fields -- //-- ParentEntryIndex -- NewBkm.ParentEntryIndex = CurrentFolder->EntryIndex; //-- LastVisit -- NewBkm.LastVisit = NewBkm.AddDate; //-- LastModified -- NewBkm.LastModified = NewBkm.AddDate; //-- Add info to folder list -- AddBookmark(NewBkm, BookmarkList); }//End PromptAddBookmark ////////////////////////////////////////////////////////// // PromptAddFolder // // // // Prompts the user for Folder information. Default // // values can be specified. Adds folder to folder // // list. // // // // // // CALLED BY: WAMMenu // // CALLS: // // CUICreateWindow() // // CUIStringPrompt() // // CUIDestroyWindow() // // GetUTCTime() // // AddFolder() // // // // PARAMETERS: // // FolderList: Data in & out - pointer to the first // // item in the folder list // // DefaultFolder: Data in - a FolderDataStruct // // containing the default values for the folder // // // // VERSION: 1.00 // ////////////////////////////////////////////////////////// void PromptAddFolder(FolderDataPtr &FolderList, FolderDataPtr CurrentFolder){ //-- Variable Declarations -- char UserResponse[StringLength+1]; //Used to retrieve the user's response to the prompt FolderDataStruct NewFld; //Contains the information to be added to the bookmark list FolderDataPtr CurrentPositionPtr = FolderList; //Current Position Pointer int MaxEntryIndex = -32767; //Used in finding the larges entryindex so far //-- Get Input -- //-- Create Window -- CUICreateWindow(StandardDialogX,StandardDialogY,StandardDialogW,StandardDialogH); //-- Name -- CUIDialogStringPrompt("Name of Folder?", "Add Folder", UserResponse, StandardDialogInputLength); strcpy(NewFld.Name, UserResponse); //-- Comment -- CUIDialogStringPrompt("Comment?", "Add Folder", UserResponse, StandardDialogInputLength); strcpy(NewFld.Comment, UserResponse); //-- Destroy Window -- CUIDestroyWindow(); //-- Add Date -- NewFld.AddDate = GetUTCTime("Today's Date?", null); //-- Calculated Fields -- //-- ParentEntryIndex -- NewFld.ParentEntryIndex = CurrentFolder->EntryIndex; //-- EntryIndex -- while (CurrentPositionPtr){ //-- Compare -- if (CurrentPositionPtr->EntryIndex > MaxEntryIndex) MaxEntryIndex = CurrentPositionPtr->EntryIndex; //-- Move to next item in list -- CurrentPositionPtr = CurrentPositionPtr->LinkNext; }//End while MaxEntryIndex++; NewFld.EntryIndex = MaxEntryIndex; //-- Add info to folder list -- AddFolder(NewFld, FolderList); }//End PromptAddFolder ////////////////////////////////////////////////////////// // GetUTCTime // // // // Prompt user for date information and convert into // // UTC time. // // // // CALLED BY: // // FileMenu // // EditMenu // // WAMMenu // // // // CALLS: // // CUICreateWindow // // CUIDestroyWindow // // CUIStringPrompt // // // // PARAMETERS: // // char PromptText[]: In - Text to show user // // long DefaultUTCTime: In - The time to use as the // // default time. // // // // Returns: // // int: UTC value for the time entered by the user. // // // // Notes: // // Time Conversion code besed on Barnette's web page // // located at // // http://ei.cs.vt.edu/~cs1704/miscp2errs98.htm // // // // REVISIONS: DATE, REASON // // AUTHOR FOR EACH (if different) // // VERSION: x.xx // ////////////////////////////////////////////////////////// int GetUTCTime(char PromptText[], long DefaultUTCTime){ //-- Constant Declarations -- const char MONTHPROMPT[8] = {"\nMonth("}; //Prompt for month const char DAYPROMPT[6] = {"\nDay("}; //Prompt for day const char YEARPROMPT[7] = {"\nYear("}; //Prompt for Year const char ENDPROMPT[3] = {")?"}; //End for all prompts const DateDialogInputWidth = 2; //Width of date input //-- Variable Declarations -- struct tm NewTime; //The time being rad struct tm DefaultTime; //Holds default time char UserResponse[3]; //User response char TmpStr[StringLength+1]; //used in concatonating prompt strings char PromptStr[StringLength+1]; //used in concatonating prompt strings int ReturnValue; //used in range-checking return value //-- Initialize -- NewTime.tm_sec = 0; NewTime.tm_min = 0; NewTime.tm_hour = 0; NewTime.tm_wday = 0; NewTime.tm_yday = 0; NewTime.tm_isdst = false; DefaultTime = *gmtime(&DefaultUTCTime); //-- Create Window -- CUICreateWindow(StandardDialogX,StandardDialogY,StandardDialogW,StandardDialogH); //-- Prompt for month -- strcpy(PromptStr, PromptText); strcat(PromptStr, MONTHPROMPT); itoa(DefaultTime.tm_mon+1, TmpStr, BASETEN); strcat(PromptStr, TmpStr); strcat(PromptStr, ENDPROMPT); CUIDialogStringPrompt(PromptStr, "Date", UserResponse, DateDialogInputWidth); if (UserResponse[0]) NewTime.tm_mon = atoi(UserResponse)-1; else NewTime.tm_mon = DefaultTime.tm_mon; //-- Prompt for Day -- strcpy(PromptStr, PromptText); strcat(PromptStr, DAYPROMPT); itoa(DefaultTime.tm_mday, TmpStr, BASETEN); strcat(PromptStr, TmpStr); strcat(PromptStr, ENDPROMPT); CUIDialogStringPrompt(PromptStr, "Date", UserResponse, DateDialogInputWidth); if (UserResponse[0]) NewTime.tm_mday = atoi(UserResponse); else NewTime.tm_mday = DefaultTime.tm_mday; //-- Prompt for year -- strcpy(PromptStr, PromptText); strcat(PromptStr, YEARPROMPT); itoa(DefaultTime.tm_year, TmpStr, BASETEN); strcat(PromptStr, TmpStr); strcat(PromptStr, ENDPROMPT); CUIDialogStringPrompt(PromptStr, "Date", UserResponse, DateDialogInputWidth); if (UserResponse[0]) NewTime.tm_year = atoi(UserResponse); else NewTime.tm_year = DefaultTime.tm_year; //-- Destroy Window -- CUIDestroyWindow(); //-- Convert & return -- ReturnValue = mktime(&NewTime); if (ReturnValue >= 0) return ReturnValue; else return 0; }//end GetUTCTime