diff --git a/mozilla/cmd/winfe/mkfiles32/mozilla.mak b/mozilla/cmd/winfe/mkfiles32/mozilla.mak index fba837ef63d..9d9461b240e 100644 --- a/mozilla/cmd/winfe/mkfiles32/mozilla.mak +++ b/mozilla/cmd/winfe/mkfiles32/mozilla.mak @@ -967,7 +967,6 @@ $(OUTDIR)\mozilla.dep: $(DEPTH)\cmd\winfe\mkfiles32\mozilla.mak !endif $(DEPTH)\lib\libmisc\glhist.c - $(DEPTH)\lib\libmisc\hotlist.c $(DEPTH)\lib\libmisc\shist.c $(DEPTH)\lib\libmisc\undo.c diff --git a/mozilla/cmd/winfe/winproto.h b/mozilla/cmd/winfe/winproto.h index 7bb6209c669..2ff12057413 100755 --- a/mozilla/cmd/winfe/winproto.h +++ b/mozilla/cmd/winfe/winproto.h @@ -150,7 +150,6 @@ extern char * szLoadString (UINT iID, ResourceSwitcher *pSwticher = NULL); extern void fe_InitFileFormatTypes(void); extern CHelperApp * fe_AddNewFileFormatType(const char *mime_type,const char *subtype); extern void fe_CleanupFileFormatTypes(void); -extern HotlistStruct * fe_find_hotlist_root (HotlistStruct * pListTop, BOOL add_p, MWContext * context); // Get a file name given a type prefix and extension // Name is returned in static space --- user must not free diff --git a/mozilla/include/bkmks.h b/mozilla/include/bkmks.h deleted file mode 100644 index 791ebda4268..00000000000 --- a/mozilla/include/bkmks.h +++ /dev/null @@ -1,700 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public License - * Version 1.0 (the "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ -#ifndef BKMKS_H -#define BKMKS_H - -#include "xp_mcom.h" -#include "ntypes.h" - -XP_BEGIN_PROTOS - -#define BM_LAST_CELL 0xFFFF /* See BMFE_RefreshCells */ - -typedef time_t BM_Date; - -typedef enum { - BM_Cmd_Invalid, /* XFE in particular likes to have an invalid - ID code as one of the entries here...*/ - - BM_Cmd_Open, /* Open a new bookmark file. */ - - BM_Cmd_ImportBookmarks, /* Import entries from another bookmark - file. */ - - BM_Cmd_SaveAs, /* Save these bookmarks into another file. */ - - BM_Cmd_Close, /* Close the bookmarks window. (NYI ###) */ - - BM_Cmd_Undo, /* Undo the last command. */ - BM_Cmd_Redo, /* Redo the last undone command. */ - - BM_Cmd_Cut, /* Cut the selected bookmarks. */ - BM_Cmd_Copy, /* Copy the selected bookmarks. */ - BM_Cmd_Paste, /* Paste in the most recent cut/copy. */ - BM_Cmd_Delete, /* Delete the selected bookmarks without - affecting the clipboard. */ - - BM_Cmd_SelectAllBookmarks, /* Select every bookmark in the window. */ - - BM_Cmd_Find, /* Find a string. */ - - BM_Cmd_FindAgain, /* Find the same string again. */ - - BM_Cmd_BookmarkProps, /* Bring up the properties window. */ - - BM_Cmd_GotoBookmark, /* Load the selected bookmark in a browser - window. */ - - /* Sort the bookmarks. NYI### */ - BM_Cmd_Sort_Name, - BM_Cmd_Sort_Name_Asc, - - BM_Cmd_Sort_Address, - BM_Cmd_Sort_Address_Asc, - - BM_Cmd_Sort_AddDate, - BM_Cmd_Sort_AddDate_Asc, - - BM_Cmd_Sort_LastVisit, - BM_Cmd_Sort_LastVisit_Asc, - - BM_Cmd_Sort_Natural, - - - BM_Cmd_InsertBookmark, /* Insert a new bookmark (or a new address if - in addressbook). */ - - BM_Cmd_InsertHeader, /* Insert a new header. */ - - BM_Cmd_InsertSeparator, /* Insert a separator. */ - - BM_Cmd_MakeAlias, /* Make an alias of this bookmark. */ - - BM_Cmd_SetAddHeader, /* Make the current header be the one where new - bookmarks are added. */ - - BM_Cmd_SetMenuHeader /* Make the current header be the one which the - pulldown menu is created from. */ - -} BM_CommandType; -#define BM_Cmd_SortBookmarks BM_Cmd_Sort_Name - -typedef enum -{ - BM_Sort_NONE = -1, - - BM_Sort_Name, - BM_Sort_Name_Asc, - - BM_Sort_Address, - BM_Sort_Address_Asc, - - BM_Sort_AddDate, - BM_Sort_AddDate_Asc, - - BM_Sort_LastVisit, - BM_Sort_LastVisit_Asc, - - BM_Sort_Natural - -} BM_SortType; - -/* The various types of bookmark entries (as returned by BM_GetType). */ - -typedef uint16 BM_Type; - -#define BM_TYPE_HEADER 0x0001 -#define BM_TYPE_URL 0x0002 -#define BM_TYPE_ADDRESS 0x0004 -#define BM_TYPE_SEPARATOR 0x0008 -#define BM_TYPE_ALIAS 0x0010 - - -/* This represents one line in the bookmarks window -- a URL, a - separater, an addressbook entry, a header, etc. It's also already - defined in ntypes.h, and some compilers bitch and moan about seeing it - twice, so I've commented it out here. */ -/* typedef struct BM_Entry_struct BM_Entry; */ - - - -/* information for the find dialog */ -typedef struct BM_FindInfo { - char* textToFind; - XP_Bool checkNickname; /* Meaningful only in addressbook */ - XP_Bool checkName; - XP_Bool checkLocation; - XP_Bool checkDescription; - XP_Bool matchCase; - XP_Bool matchWholeWord; - - BM_Entry* lastEntry; -} BM_FindInfo; - -struct BM_Entry_Focus { - BM_Entry* saveFocus; - XP_Bool foundSelection; -}; - -extern XP_Bool BM_IsHeader(BM_Entry* entry); -extern XP_Bool BM_IsUrl(BM_Entry* entry); -extern XP_Bool BM_IsAddress(BM_Entry* entry); -extern XP_Bool BM_IsSeparator(BM_Entry* entry); -extern XP_Bool BM_IsAlias(BM_Entry* entry); -extern XP_Bool BM_IsFolded(BM_Entry* entry); -extern XP_Bool BM_IsSelected(BM_Entry* entry); - - -/* Returns the state of whether this is a "changed URL"; that is, a URL whose - contents have apparently changed since we last visited it. */ - -#define BM_CHANGED_YES 1 -#define BM_CHANGED_NO 0 -#define BM_CHANGED_UNKNOWN -1 - -extern int32 BM_GetChangedState(BM_Entry* entry); - - - -/* Get/Set the header that is to be the root of the pulldown menu. */ -extern BM_Entry* BM_GetMenuHeader(MWContext* context); -extern void BM_SetMenuHeader(MWContext* context, BM_Entry* entry); - -/* Get/Set the header that is to be the container of new items added from - browser windows. */ -extern BM_Entry* BM_GetAddHeader(MWContext* context); -extern void BM_SetAddHeader(MWContext* context, BM_Entry* entry); - - -typedef void (*EntryFunc)(MWContext* context, BM_Entry* entry, void* closure); - - -/* Executes the given function on every single entry in the bookmark file. */ -extern void BM_EachEntryDo(MWContext* context, EntryFunc func, void* closure); - -/* Executes the given function for every entry that is selected. */ -extern void BM_EachSelectedEntryDo(MWContext* context, EntryFunc func, - void* closure); - -/* Executes the given function for every entry that is selected and is not a - descendent of a header that is not folded or selected. */ -extern void BM_EachProperSelectedEntryDo(MWContext* context, EntryFunc func, - void* closure, struct BM_Entry_Focus* bmFocus); - - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -/* Front end stubs -- each FE needs to implement these. */ - -/* Refresh each cell between and including first and last in the bookmarks - widget (if now is TRUE, the FE is expected to redraw them BEFORE returning, - otherwise the FE can simply invalidate them and wait for the redraw to - happen). If BM_LAST_CELL is passed in as last, then it means paint from - the first to the end. */ -extern void BMFE_RefreshCells(MWContext* context, int32 first, int32 last, - XP_Bool now); - - -/* Resize the widget to accomodate "visibleCount" number of entries vertically - and the width of widest entry the actual widget should NOT change size, just - the size of the scrollable area under it */ -extern void BMFE_SyncDisplay(MWContext* context); - - -/* measure the item and assign the width and height required to draw it into - the widget into width and height. This is used only by BM_WidestEntry(); if - you don't need that call, you can just make this an empty stub. */ -extern void BMFE_MeasureEntry(MWContext* context, BM_Entry* entry, - uint32* width, uint32* height); - -/* Save the given bucket o' bits as the clipboard. This same bucket needs to - be returned later if BMFE_GetClipContents() is called. */ -extern void BMFE_SetClipContents(MWContext* context, void* buffer, - int32 length); - - -/* return the clipboard contents */ -extern void* BMFE_GetClipContents(MWContext* context, int32* length); - - -/* Copy the selected items from a history window to the clipboard (as bookmarks) */ -extern char *BM_ClipCopyHistorySelection( void *pHistCsr, uint32 *pSelections, int iCount, int *pSize, XP_Bool bLongFormat ); - -/* Insert the block into the list */ -extern void BM_DropBlockL( MWContext *pContext, char *pData, BM_Entry *firstSelected ); - -/* Create the bookmarks property window. If one already exists, just bring it - to the front. This will always be immediately followed by a call to - BMFE_EditItem(). */ -extern void BMFE_OpenBookmarksWindow(MWContext* context); - - -/* Edit the given item in the bookmarks property window. If there is no - bookmarks property window currently, then the FE should ignore this call. - If the bookmarks property window is currently displaying some other entry, - then it should save any changes made to that entry (by calling BM_SetName, - etc.) before loading up this entry. */ -extern void BMFE_EditItem(MWContext* context, BM_Entry* entry); - -/* The given entry is no longer valid (i.e., the user just deleted it). So, - the given pointer is about to become invalid, and the FE should remove any - references to it it may have. In particular, if it is the one being edited - in the bookmarks property window, then the FE should clear that window. */ -extern void BMFE_EntryGoingAway(MWContext* context, BM_Entry* entry); - - -/* The user has requested to view the given url. Show it to him in, using some - appropriate context. Url may be targeted to a different window */ -extern void BMFE_GotoBookmark(MWContext* context, - const char* url, const char* target); - - -/* Create the find dialog, and fill it in as specified in the given - structure. When the user hits the "Find" button in the dialog, call - BM_DoFindBookmark. */ -extern void* BMFE_OpenFindWindow(MWContext* context, BM_FindInfo* findInfo); - - -/* Make sure that the given entry is visible. */ -extern void BMFE_ScrollIntoView(MWContext* context, BM_Entry* entry); - - -/* The list of bookmarks has changed somehow, so any "bookmarks" menu needs to - be recreated. This should be a cheap call, just setting a flag in the FE so - that it knows to recreate the menu later (like, when the user tries to view - it). Recreating it immediately would be bad, because this can get called - much more often than is reasonable. */ -extern void BMFE_BookmarkMenuInvalid(MWContext* context); - - -/* We're in the process of doing a What's Changed operation. The What's - Changed window should update to display the URL, the percentage (calculate - as done*100/total), and the total estimated time (given here as a - pre-formatted string). The What's Changed window should end up looking - something like this: - - Checking ... (<13> left) - {===================== } (progress bar) - - Estimated time remaining: <2 hours 13 minutes> - (Remaining time depends on the sites selected and - the network traffic). - - - [ Cancel ] - - It's up to the FE to notice the first time this is called and change its - window to display the info instead of the initial What's Changed screen. - - If the user ever hits Cancel (or does something equivilant, like destroys - the window), the FE must call BM_CancelWhatsChanged(). */ - -extern void BMFE_UpdateWhatsChanged(MWContext* context, - const char* url, /* If NULL, just display - "Checking..." */ - int32 done, int32 total, - const char* totaltime); - - - -/* We've finished processing What's Changed. The What's Changed window should - change to display the summary of what happened. It should look something - like this: - - Done checking <157> Bookmarks. - <134> documents were reached. - <27> documents have changed and are marked in blue. - - [ OK ] - - When the user clicks on the OK, the FE should just take down the window. - (It doesn't matter if the FE calls BM_CancelWhatsChanged(); it will be a - no-op in this situtation.) */ - -extern void BMFE_FinishedWhatsChanged(MWContext* context, int32 totalchecked, - int32 numreached, int32 numchanged); - -#ifdef XP_WIN -/* The current bookmarks file is about to change */ -extern void BMFE_ChangingBookmarksFile(void); - -/* The current bookmarks file has been changed */ -extern void BMFE_ChangedBookmarksFile(void); -#endif - -#ifdef XP_UNIX -/* Use these to know when to allow refresh */ -extern void BMFE_StartBatch(MWContext* context); -extern void BMFE_EndBatch(MWContext* context); -#endif - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - - - -/* Initialize a new bookmarks context. (returns negative on failure) */ -extern int BM_InitializeBookmarksContext(MWContext* context); - - -/* Prepare to destroy a bookmarks context. Will save any changes that have - been made. */ -extern void BM_CleanupBookmarksContext(MWContext* context); - - -/* Set some FE data to associate with a bookmarks context. */ -extern void BM_SetFEData(MWContext* context, void* data); - -/* Get the FE data previously associated with a context. */ -extern void* BM_GetFEData(MWContext* context); - - -/* Create a new url entry. */ -extern BM_Entry* BM_NewUrl(const char* name, const char* address, - const char* content_type, BM_Date last_visit); - -/* Create a new header. */ -extern BM_Entry* BM_NewHeader(const char* name); - - -/* Create a copy of an existing bookmark. If the bookmark is a folder - it will also contain a copy of all of the bookmarks in the folder.*/ -extern BM_Entry* BM_CopyBookmark(MWContext* context, BM_Entry* original); - -/* Frees an entry. This should never be called unless you are sure the entry - has not been added to some header, and is not the object of some alias. In - other words, be sure nothing could possibly have a pointer to this it. - If the object is a header, this will also free all of its descendents. */ -extern void BM_FreeEntry(MWContext* context, BM_Entry* entry); - - -/* Get the type of this bookmark. (Returns one of the BM_TYPE_* values.) */ -extern BM_Type BM_GetType(BM_Entry* entry); - -extern char* BM_GetName(BM_Entry* entry); - -extern char* BM_GetAddress(BM_Entry* entry); -extern char* BM_GetTarget(BM_Entry* entry, XP_Bool recurse); -extern char* BM_GetDescription(BM_Entry* entry); - -extern char* BM_GetNickName(BM_Entry* entry); /* Only meaningful in address - book. */ - -/* Get the full name and address of the given entry (which must be an - address book entry or header). Result is returned in a newly allocated - string; free it with XP_FREE() when through. */ -extern char* BM_GetFullAddress(MWContext* context, BM_Entry* entry); - -/* These return prettily formated info about the bookmark. They each - return the result in a staticly allocated string, so if you call the - same function twice the results get stomped. */ -extern char* BM_PrettyLastVisitedDate(BM_Entry* entry); -extern char* BM_PrettyAddedOnDate(BM_Entry* entry); -extern char* BM_PrettyAliasCount(MWContext* context, BM_Entry* entry); - - -/* Get the root node of a context. */ -extern BM_Entry* BM_GetRoot(MWContext* context); - - -/* Given a node, return the first of its children (if any). */ -extern BM_Entry* BM_GetChildren(BM_Entry* entry); - -/* Given a node, return the next node that has the same parent (if any). */ -extern BM_Entry* BM_GetNext(BM_Entry* entry); - -/* Given a node, returns its parent (or NULL if this is the root) */ -extern BM_Entry* BM_GetParent(BM_Entry* entry); - -/* Does this node have a sibling somewhere below it? */ -extern XP_Bool BM_HasNext(BM_Entry* entry); - -/* Does this node have a sibling somewhere above it? Note that there is *not* - an API to actually get that sibling, as this is not a simple call. However, - determing the existance of such a child is easy, and that's what Windows - needs to paint its pipes. */ -extern XP_Bool BM_HasPrev(BM_Entry* entry); - - - -/* Routines to change the name/address/description of an entry. These routines - will take care of updating the display as necessary. */ -extern void BM_SetName(MWContext* context, BM_Entry* entry, - const char* newName); -extern void BM_SetAddress(MWContext* context, BM_Entry* entry, - const char* newAddress); -extern void BM_SetTarget(MWContext* context, BM_Entry* entry, - const char* newTarget); -extern void BM_SetDescription(MWContext* context, BM_Entry* entry, - const char* newDesc); - -/* Only meaningful in addressbook (on an address or header or alias to same) */ -extern XP_Bool BM_SetNickName(MWContext* context, BM_Entry* entry, - const char* newName); - -/* The user just hit "Cancel" on the properties window, which was editing - the given item. This gives the bookmarks code a chance to delete the - item if it was just newly created. */ -extern void BM_CancelEdit(MWContext* context, BM_Entry* entry); - - -/* fold or unfold the header according to "fold" and all its subfolders if - foldAll is TRUE */ -extern void BM_FoldHeader(MWContext* context, BM_Entry* entry, XP_Bool fold, - XP_Bool refresh, XP_Bool foldAll); - - -/* clear all the selection flags, and cause a redisplay if refresh is set. */ -extern void BM_ClearAllSelection(MWContext* context, XP_Bool refresh); - -/* Clear all the child selections of the passes header and redisplay if refresh - is set. */ -extern void BM_ClearAllChildSelection(MWContext* context, BM_Entry* at, - XP_Bool refresh); - -/* Select everything. */ -extern void BM_SelectAll(MWContext* context, XP_Bool refresh); - - -/* selects the item, call BMFE_Refresh on it if "refresh" and calls - BM_ClearSelection first if extend is FALSE */ -extern void BM_SelectItem(MWContext* context, BM_Entry* item, XP_Bool refresh, - XP_Bool extend, XP_Bool select); - -/* Adds a range of bookmarks to the current selection. To be called by the FE - when the user Shift-Clicks in the window. This will unselect everything and - then select a range of bookmarks, from the last bookmark that was selected - with BM_SelectItem to the one given here. */ -extern void BM_SelectRangeTo(MWContext* context, BM_Entry* item); - -/* toggles the selected state of the item, call BMFE_Refresh on it if "refresh" - and calls BM_ClearSelection if extend is FALSE */ -extern void BM_ToggleItem(MWContext* context, BM_Entry* item, XP_Bool refresh, - XP_Bool extend ); - -/* returns the first selected entry */ -extern BM_Entry* BM_FirstSelectedItem(MWContext* context); - - -extern BM_Date BM_GetLastVisited(BM_Entry *); -extern BM_Date BM_GetAdditionDate(BM_Entry *); - -/* return the number of bookmarks */ -extern int32 BM_GetCount(MWContext* context); - -/* return the number of visible bookmarks */ -extern int32 BM_GetVisibleCount(MWContext* context); - -/* returns an integer index of the item in the list */ -extern int32 BM_GetIndex(MWContext* context, BM_Entry* item); - -/* returns an integer index of the item in the list and does not pay attention - to the is_folded value */ -extern int32 BM_GetUnfoldedIndex(MWContext* context, BM_Entry* item); - -/* returns the object associated with the index returned by BM_GetIndex() */ -extern BM_Entry* BM_AtIndex(MWContext* context, int32 index); - -/* returns the object associated with the index returned by - BM_GetUnfoldedIndex() */ -extern BM_Entry* BM_AtUnfoldedIndex(MWContext* context, int32 index); - - -/* returns an integer depth of the item in the list starting - at zero */ -extern int32 BM_GetDepth(MWContext* context, BM_Entry* item); - - -/* Execute a find operation according to the data in the given structure. This - will cause the appropriate entry to be selected and made visible. */ -extern void BM_DoFindBookmark(MWContext* context, BM_FindInfo* findInfo); - -/* For addressbook only: find and return the entry (if any) for the e-mail - address within the given mailto: url. (used by libmsg) */ -extern BM_Entry* BM_FindAddress(MWContext* context, const char* mailtourl); - - -/* For addressbook only: edit the entry for the e-mail address within the - given mailto: url, creating the entry if necessary. (used by libmsg) */ -extern void BM_EditAddress(MWContext* context, const char* mailtourl); - - -/* For addressbook only: if the given list of addresses includes a nickname - from the addresses, then return a new string with the addresses expanded. - If expandfull is True, then all mailing list entries are expanded too, - otherwise, mailing list entries are only expanded to include their name. - (used by libmsg). */ -extern char* BM_ExpandHeaderString(MWContext* context, const char* value, - XP_Bool expandfull); - - -/* Checks every bookmark context for a url and updates the last accessed - time. (For use by global history code; FE's probably don't need this.) */ -extern void BM_UpdateBookmarksTime(URL_Struct* URL_s, BM_Date cur_time); - -/* returns TRUE if the second argument is a direct descendent of the first - argument, returns FALSE otherwise */ -extern XP_Bool BM_IsDescendent(MWContext* context, BM_Entry* parent, - BM_Entry* possible_child); - - -/* The front end can use this call to determine what the indentation depth is - needed to display all the icons in the bookmarks. The XFE uses this to - dynamically resize the icon column. In true C style, the number returned is - actually one bigger than the biggest depth the FE will ever get. */ -extern int BM_GetMaxDepth(MWContext* context); - - -/* This is called during a drag operation. The user is dragging some bookmarks - and is currently pointing at the given line. (If under is True, then the - user is really pointing between the given line and the next line.) This - returns TRUE if the FE should draw a box around the given line, and FALSE if - it should underline it. */ -extern XP_Bool BM_IsDragEffectBox(MWContext* context, int line, XP_Bool under); - - -/* Actually do a drop in a drag-n-drop reordering operation. The arguments are - the same as BM_IsDragEffectBox(); the selected items will be moved. */ -extern void BM_DoDrop(MWContext* ctnx, int line, XP_Bool under); - - - - -/* find and return the widest visible entry in the bookmarks tree. This makes - sense only if your FE has defined a meaningful BMFE_MeasureEntry(). */ -extern BM_Entry* BM_WidestEntry(MWContext* context); - - - -/* insert an item after another item in the bm if the insert_after item is NULL - or not found the item will be inserted at the end of the list */ -extern void BM_InsertItemAfter(MWContext* context, BM_Entry* insert_after, - BM_Entry* insertee); - -/* insert an item in a header if "insert_after" is a Header type, or after the - item if "insert after" is not a header type. if the insert_after item is - NULL or not found the item will be inserted at the end of the bm */ -extern void BM_InsertItemInHeaderOrAfterItem(MWContext* context, - BM_Entry* insert_after, - BM_Entry* insertee ); - -/* Cause the given item to be inserted at the end of the given header. The - header passed in here is usually BM_GetAddHeader(). */ -extern void BM_AppendToHeader(MWContext* context, BM_Entry* header, - BM_Entry* entry); - -extern void BM_PrependChildToHeader(MWContext* context, BM_Entry* parent, BM_Entry* child); - -/* Removes the given item from bookmarks without deleting it*/ -extern void BM_RemoveChildFromHeader(MWContext* context, BM_Entry* parent, BM_Entry* child); - -/* Cause the given bookmark to be displayed in a browser window somewhere. - The given item must be an URL (BM_IsUrl must return TRUE). */ -extern void BM_GotoBookmark(MWContext* context, BM_Entry* item); - - -/* Reads the hostlist from disk, what else? Pass in the bm filename and a - relative URL which represents the original location of the html file. If - you are reading the default bm you should pass in a file URL of the form - file://localhost/PATH */ -extern void BM_ReadBookmarksFromDisk(MWContext* context, const char* filename, - const char* relative_url); - -/* saves the bm to a file. If the given filename is NULL, then save it back to - where it was loaded from and only if changes have been made. Returns - negative on failure. */ -extern int32 BM_SaveBookmarks(MWContext* context, const char* filename); - - -/* Returns the filename that the bookmarks are saved in. */ -extern const char* BM_GetFileName(MWContext* context); - -/* read in a new bookmarks file (esp for LI use). */ -extern void BM_Open_File(MWContext* context, char* newFile); - -/* ability to set the modified to true or false (esp for LI use). */ -extern void BM_SetModified(MWContext* context, XP_Bool mod); - -/* Whether the file will be written when Save is called. */ -extern XP_Bool BM_Modified(MWContext* context); - -/* Convert a number of selections in a bm list into a block of memory that the - user can use for cut and paste operations */ -extern char* BM_ConvertSelectionsToBlock(MWContext* context, - XP_Bool bLongFormat, - int32* lTotalLen); - -/* Take a block of memory and insert the bm items it represents into the - current bm */ -extern void BM_InsertBlockAt(MWContext* context, char* pOriginalBlock, - BM_Entry* addTo, XP_Bool bLongFormat, - int32 lTotalLen); - - -/* select all aliases for an entry */ -extern void BM_SelectAliases(MWContext* context, BM_Entry* forEntry ); - - -/* Count how many aliases there are to the given entry. */ -extern int32 BM_CountAliases(MWContext* context, BM_Entry* forEntry); - - -/* Make an alias for each of the currently selected entries. */ -extern void BM_MakeAliases(MWContext* context); - - -/* Returns the real item that an alias points to. The given entry must be an - alias (BM_IsAlias must return TRUE on it). */ -extern BM_Entry* BM_GetAliasOriginal(BM_Entry*); - - - -/* Start a What's Changed operation. Before calling this routine, it's up to - the FE to present a dialog like this when What's Changed starts: - - Look for documents that have changed on: - (o) All bookmarks - ( ) Selected bookmarks - - [ Start Checking ] [ Cancel ] - - Then the FE calls this routine when the user clicks Start Checking. The FE - will immediately get called via BMFE_UpdateWhatsChanged(), and the FE should - change the dialog box's appearance to match. */ -extern int BM_StartWhatsChanged(MWContext* context, - XP_Bool do_only_selected); - - -/* Cancel a running What's Changed operation. */ -extern int BM_CancelWhatsChanged(MWContext* context); - - - -/* Returns whether the given command can be executed right now. Should be - used to decide whether to disable a menu item for this command. */ -extern XP_Bool BM_FindCommandStatus(MWContext* context, - BM_CommandType command); - -/* Execute the given command. */ -extern void BM_ObeyCommand(MWContext* context, BM_CommandType command ); - -/* Clean up the undo queue */ -void BM_ResetUndo(MWContext * context); - -XP_END_PROTOS - -#endif /* BMLIST_H */ diff --git a/mozilla/include/client.h b/mozilla/include/client.h index a84b421fa9e..eb2eea8ad3f 100644 --- a/mozilla/include/client.h +++ b/mozilla/include/client.h @@ -49,7 +49,6 @@ #include "net.h" #include "gui.h" #include "shist.h" -#include "hotlist.h" #include "glhist.h" #include "mime.h" diff --git a/mozilla/include/hotlist.h b/mozilla/include/hotlist.h deleted file mode 100644 index 31b4c3e11d3..00000000000 --- a/mozilla/include/hotlist.h +++ /dev/null @@ -1,250 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public License - * Version 1.0 (the "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ - -#ifndef HOTLIST_H -#define HOTLIST_H - -#include "xp_mcom.h" -#include "ntypes.h" - -XP_BEGIN_PROTOS - -typedef enum HOT_Type { - HOT_URLType, HOT_HeaderType, HOT_SeparatorType } HOT_Type; - -typedef struct HotlistStruct_ { - HOT_Type type; - Bool is_folded; /* if it's a header is it folded? */ - XP_List *children; /* a list of children, only headers have these */ - char *name; /* a title */ - char *address; /* the URL address */ - char *description; /* random text */ - time_t last_visit; - time_t addition_date; - char *content_type; - struct HotlistStruct_ *parent; /* My hotlist parent */ - XP_List *lParent; /* The XP_List object that points to my parent or NULL */ -} HotlistStruct; - -/* tell the hotlist code that the hotlist has been modified - * so that it gets saved the next time SaveHotlist is called - */ -extern void HOT_SetModified(void); - -/* changes a entry to a header type from a non header type - * and vice versa. If the object was a header and - * has children, the children will be blown away. (very bad) - */ -extern void HOT_ChangeEntryType(HotlistStruct * entry, HOT_Type new_type); - -/* Fold or unfold a hotlist header - * - * set the Boolean to True to fold the list and - * False to unfold - */ -extern void HOT_FoldHeader(HotlistStruct * item, Bool fold); - -/* checks the hotlist for a url and updates the last accessed - * time - */ -extern void HOT_UpdateHotlistTime(URL_Struct *URL_s, time_t cur_time); - -/* Performs regular expression match on hotlist name and address - * fields. Returns the found object, or NULL if not - * found. - * - * start_obj specifies the object to start searching - * on. The start_num object WILL NOT be searched but all those - * after it will be. - * To search the whole list give NULL as start_obj. - * - * If headers became unfolded because of the search then redisplay_all - * will be set to TRUE - */ -extern HotlistStruct * HOT_SearchHotlist(char * search_string, - HotlistStruct * start_obj, - Bool * redisplay_all); - -/* returns TRUE if the second argument is a direct - * descendent of the first argument. - * - * returns FALSE otherwise - */ -extern Bool HOT_IsDescendent(HotlistStruct *parent, HotlistStruct *possible_child); - - -/* Reads the hostlist from disk, what else? - * - * pass in the hotlist filename and a relative URL which represents - * the original location of the html file. If you are reading the - * default hotlist you should pass in a file URL of the form - * file://localhost/PATH - * - */ -extern void HOT_ReadHotlistFromDisk (char * filename, char * relative_url); - -/* returns an integer index of the item in the list - */ -extern int HOT_GetIndex(HotlistStruct * item); - -/* returns an integer index of the item in the list - * and does not pay attention to the is_folded value - */ -extern int HOT_GetUnfoldedIndex(HotlistStruct * item); - -/* returns the object associated with the index returned by - * HOT_GetIndex() - */ -extern HotlistStruct * HOT_IndexOf(int index); - -/* returns the object associated with the index returned by - * HOT_GetUnfoldedIndex() - */ -extern HotlistStruct * HOT_UnfoldedIndexOf(int index); - -/* returns an integer depth of the item in the list starting at zero - */ -extern int HOT_GetDepth(HotlistStruct * item); - -/* return a pointer to the main hotlist list - * - * returns NULL if nothing has ever been - * added to the hotlist - */ -extern XP_List * HOT_GetHotlistList(void); - -/* saves the hotlist to a configuration file - */ -extern int HOT_SaveHotlist (char * filename); - -/* Free's the entire hotlist - */ -extern void HOT_FreeHotlist (void); - - -/* create a hotlist entry struct and fill it in with - * the passed in data - * - * returns NULL on out of memory error. - */ -extern HotlistStruct * -HOT_CreateEntry(HOT_Type type, - const char *name, - const char *address, - const char *content_type, - time_t last_visit); - -/* free's a hotlist entry - */ -extern void HOT_FreeEntry(HotlistStruct * entry); - -/* create a completely new copy of the entry passed in - */ -extern HotlistStruct * HOT_CopyEntry(HotlistStruct * entry); - -/* insert an item before another item in the hotlist - * - * if the insert_before item is NULL or not found the item - * will be inserted at the begining of the list - */ -extern void HOT_InsertItemBefore(HotlistStruct * insert_before, HotlistStruct * insertee); - -/* insert an item after another item in the hotlist - * - * if the insert_after item is NULL or not found the item - * will be inserted at the end of the list - */ -extern void HOT_InsertItemAfter(HotlistStruct * insert_after, HotlistStruct * insertee); - -/* insert an item in a header if "insert_after" is a - * Header type, or after the item if "insert after" is - * not a header type. - * - * if the insert_after item is NULL or not found the item - * will be inserted at the end of the hotlist - */ -extern void -HOT_InsertItemInHeaderOrAfterItem(HotlistStruct * insert_after, - HotlistStruct * insertee); - -/* remove an item from the hotlist and free's it - * - * returns TRUE on success, FALSE if not found - */ -extern Bool HOT_RemoveItem(HotlistStruct * old_item); - -/* remove an item from the hotlist and doesn't free it - * - * returns TRUE on success, FALSE if not found - */ -extern Bool HOT_RemoveItemFromList(HotlistStruct * old_item); - -/* move an item up in the list - */ -extern void HOT_MoveObjectUp(HotlistStruct * item); - -/* move an item down in the list - */ -extern void HOT_MoveObjectDown(HotlistStruct * item); - -/* returns True if the object can be moved Up - * False if the object cannot be moved Up or if - * it cannot be found in the list - */ -extern Bool HOT_ObjectCanGoUp(HotlistStruct * item); - -/* returns True if the object can be moved down - * False if the object cannot be moved down or if - * it cannot be found in the list - */ -extern Bool HOT_ObjectCanGoDown(HotlistStruct * item); - -/* Whether the file will be written when Save is called. */ -extern Bool HOT_Modified(void); - -/* - * Gets the top node of the hotlist -*/ -extern HotlistStruct* -HOT_GetHotlist (void); - - -/* - * Convert a number of selections in a hotlist list into a block of - * memory that the user can use for cut and paste operations - */ -extern char * -HOT_ConvertSelectionsToBlock(HotlistStruct ** list, - int iCount, - int bLongFormat, - int32 * lTotalLen); -/* - * Take a block of memory and insert the hotlist items it represents into - * the current hotlist - */ -extern void -HOT_InsertBlockAt(char * pOriginalBlock, - HotlistStruct * item, - int bLongFormat, - int32 lTotalLen); - -XP_END_PROTOS - -#endif /* HOTLIST_H */ - - diff --git a/mozilla/include/shist.h b/mozilla/include/shist.h index 532170bb76c..7585c202c6f 100644 --- a/mozilla/include/shist.h +++ b/mozilla/include/shist.h @@ -21,7 +21,6 @@ #include "xp_list.h" #include "ntypes.h" -#include "hotlist.h" /* see shistele.h for the structure definitions. :( diff --git a/mozilla/lib/libmisc/Makefile b/mozilla/lib/libmisc/Makefile index 42b00870833..0e19beedc90 100644 --- a/mozilla/lib/libmisc/Makefile +++ b/mozilla/lib/libmisc/Makefile @@ -23,12 +23,9 @@ MODULE = misc LIBRARY_NAME = misc CSRCS = \ - bkmutils.c \ glhist.c \ undo.c \ - bkmks.c \ shist.c \ - hotlist.c \ dirprefs.c \ $(NULL) diff --git a/mozilla/lib/libmisc/Makefile.in b/mozilla/lib/libmisc/Makefile.in index 48a2b7fd064..e5f6dd5d885 100644 --- a/mozilla/lib/libmisc/Makefile.in +++ b/mozilla/lib/libmisc/Makefile.in @@ -16,7 +16,7 @@ # Reserved. - + DEPTH = ../.. topsrcdir = @top_srcdir@ VPATH = @srcdir@ @@ -28,12 +28,9 @@ MODULE = misc LIBRARY_NAME = misc CSRCS = \ - bkmutils.c \ glhist.c \ undo.c \ - bkmks.c \ shist.c \ - hotlist.c \ dirprefs.c \ $(NULL) diff --git a/mozilla/lib/libmisc/bkmks.c b/mozilla/lib/libmisc/bkmks.c deleted file mode 100644 index 6b45cc7d2f4..00000000000 --- a/mozilla/lib/libmisc/bkmks.c +++ /dev/null @@ -1,7428 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * - * The contents of this file are subject to the Netscape Public License - * Version 1.0 (the "NPL"); you may not use this file except in - * compliance with the NPL. You may obtain a copy of the NPL at - * http://www.mozilla.org/NPL/ - * - * Software distributed under the NPL is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL - * for the specific language governing rights and limitations under the - * NPL. - * - * The Initial Developer of this code under the NPL is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All Rights - * Reserved. - */ - -/* If you add code to this file, make sure it still builds on win16 debug - its - * code segment is too big. - */ - -#include "bkmks.h" -#include "net.h" -#include "xp_mcom.h" -#include "client.h" -#include "msgcom.h" -#include "undo.h" -#include "xp_hash.h" -#include "xpgetstr.h" -#include "glhist.h" -#include "libi18n.h" -#include "xp_qsort.h" -#include "intl_csi.h" - -#ifdef XP_MAC -#pragma warn_unusedarg off -#pragma warn_possunwant off -#endif - -#define INTL_SORT 1 -#ifdef INTL_SORT /* Added by ftang */ -#include "xplocale.h" -#endif - -extern int MK_OUT_OF_MEMORY; - -extern int XP_BKMKS_BOOKMARKS_CHANGED; -extern int XP_BKMKS_ADDRESSBOOK_CHANGED; -extern int XP_BKMKS_BOOKMARKS_CONFLICT; -extern int XP_BKMKS_ADDRESSBOOK_CONFLICT; -extern int XP_BKMKS_CANT_WRITE_ADDRESSBOOK; -extern int XP_BKMKS_CANT_WRITE_BOOKMARKS; - -/* added by L10N team */ -extern int XP_BKMKS_HOURS_AGO; -extern int XP_BKMKS_DAYS_AGO; -extern int XP_BKMKS_COUNTALIASES_MANY; -extern int XP_BKMKS_COUNTALIASES_ONE; -extern int XP_BKMKS_COUNTALIASES_NONE; -extern int XP_BKMKS_INVALID_NICKNAME; -extern int XP_BKMKS_NICKNAME_ALREADY_EXISTS; -extern int XP_BKMKS_REMOVE_THIS_ITEMS_ALIASES; -extern int XP_BKMKS_REMOVE_SOME_ITEMS_ALIASES; -extern int XP_BKMKS_AUTOGENERATED_FILE; -extern int XP_BKMKS_READ_AND_OVERWRITE; -extern int XP_BKMKS_DO_NOT_EDIT; -extern int XP_BKMKS_NEW_HEADER; -extern int XP_BKMKS_NEW_BOOKMARK; -extern int XP_BKMKS_NOT_FOUND; -extern int XP_BKMKS_OPEN_BKMKS_FILE; -extern int XP_BKMKS_IMPORT_BKMKS_FILE; -extern int XP_BKMKS_IMPORT_ADDRBOOK; -extern int XP_BKMKS_SAVE_BKMKS_FILE; -extern int XP_BKMKS_SAVE_ADDRBOOK; -extern int XP_BKMKS_LESS_THAN_ONE_HOUR_AGO; - - -extern int XP_BKMKS_SOMEONE_S_BOOKMARKS; /* "%s%s's Bookmarks%s" */ -extern int XP_BKMKS_PERSONAL_BOOKMARKS; /* "%sPersonal Bookmarks%s" */ -extern int XP_BKMKS_SOMEONE_S_ADDRESSBOOK; /* "%s%s's Addressbook%s" */ -extern int XP_BKMKS_PERSONAL_ADDRESSBOOK; /* "%sPersonal Addressbook%s" */ - -extern int XP_BKMKS_BOOKMARK; -extern int XP_BKMKS_ENTRY; -extern int XP_BKMKS_SECONDS; -extern int XP_BKMKS_MINUTES; -extern int XP_BKMKS_HOURS_MINUTES; - -extern int XP_BKMKS_HEADER; -extern int XP_ADDRBOOK_HEADER; - - -#define SECONDS_PER_DAY 86400L -#define BMLIST_COOKIE "" -#define BM_ADDR_LIST_COOKIE "" -#define READ_BUFFER_SIZE 2048 -#define WRITE_BUFFER_SIZE 1848 /* Make this a few hundred less than - read buffer so we can be sure to - read the bookmarks back properly */ -#define DEF_NAME "Personal Bookmarks" /* L10N? This doesn't seem to be used. */ - -#ifdef FREEIF -#undef FREEIF -#endif -#define FREEIF(obj) do { if (obj) { XP_FREE (obj); obj = 0; }} while (0) - -#define BM_ATTR_FOLDED 0x0001 -#define BM_ATTR_SELECTED 0x0002 -#define BM_ATTR_ISNEW 0x0004 -#define BM_ATTR_FINDAFF 0x0008 /* This entry is temporarily unfolded only - as a result of the last find - operation. */ -#define BM_ATTR_HASALIASES 0x0010 /* Actually, being set only means that - this entry *might* have aliases. But - if an entry has aliases, this bit is - definitely set. */ -#define BM_ATTR_MARKED 0x0020 /* Random bit to temporarily mark a bunch of - items. */ -#define BM_ATTR_CHECKING 0x0040 /* In the midst of checking whether this - entry has changed. */ - - -#define BM_ISHEADER(bmStruct) \ - ((bmStruct) && ((bmStruct)->type == BM_TYPE_HEADER)) - -#define BM_ISURL(bmStruct) \ - ((bmStruct) && ((bmStruct)->type == BM_TYPE_URL)) - -#define BM_ISADDRESS(bmStruct) \ - ((bmStruct) && ((bmStruct)->type == BM_TYPE_ADDRESS)) - -#define BM_ISSEPARATOR(bmStruct) \ - ((bmStruct) && ((bmStruct)->type == BM_TYPE_SEPARATOR)) - -#define BM_ISALIAS(bmStruct) \ - ((bmStruct) && ((bmStruct)->type == BM_TYPE_ALIAS)) - -#define BM_ISFOLDED(bmStruct) \ - ((bmStruct) && ((bmStruct)->flags & BM_ATTR_FOLDED)) - -#define BM_ISSELECTED(bmStruct) \ - ((bmStruct) && ((bmStruct)->flags & BM_ATTR_SELECTED)) - -#define BM_SETFLAG(bmStruct, flag) \ - ((bmStruct) ? ((bmStruct)->flags |= (flag)) : 0) - -#define BM_CLEARFLAG(bmStruct, flag) \ - ((bmStruct) ? ((bmStruct)->flags &= ~(flag)) : 0) - -static int32 g_iNaturalIndexPool = 0; - -struct BM_Entry_struct -{ - BM_Type type; - - uint16 flags; - BM_Entry* next; - BM_Entry* parent; - char* name; - char* description; - BM_Date addition_date; - int32 iNaturalIndex; /* Index for user arranged "sort" */ - char* nickname; /* Used only by address book, alas. */ - - union { - struct BM_Header { - char* target; /* target */ - BM_Entry* children; /* a linked list of my children */ - uint32 childCount; /* the number of "children" */ - BM_Entry* lastChild; /* the last child in "children" */ - } header; - struct BM_Url { - char* address; /* address */ - char* target; /* target */ - char* content_type; /* content-type */ - BM_Date last_visit; /* when last visited */ - BM_Date last_modified; /* when the contents of the URL was last - modified. */ - } url; - struct BM_Address { - char* address; /* e-mail address */ - } address; - struct BM_Alias { - BM_Entry* original; /* the original bm */ - } alias; - } d; -}; - - -typedef struct BM_Frame { - BM_Entry* gBookmarks; /* root of the tree */ - XP_Bool gBookmarksModified; /* TRUE if the tree is modified */ - int32 gCount; /* number of entries in tree. If - negative, then need to be - recalculated. */ - int32 gVisCount; /* number of visible entries. If - negative, then need to be - recalculated. */ - int32 gSelectionCount; /* number of selected items. If - negative, then we're out of sync, - call bm_SyncSelection to - synchronize. */ - uint32 gSelectionMask; /* what types of items are selected - (invalid if gSelectionCount is - negative.)*/ - BM_FindInfo* gFindInfo; /* information for the find dialog */ - char* gFile; /* the file this data is from */ - void* gTemporary; - void* feData; - int32 max_depth; /* The number of levels in the heirarchy that - we currently display. (If zero, then we - don't know. */ - UndoState* undo; - MWContext* next; /* Next bookmarks context in master linked list. */ - XP_Bool unfoldedForFind; /* TRUE if some headers have been unfolded - as the result of a find operation. The - headers in question will have the - BM_ATTR_FINDAFF flag set.*/ - - BM_SortType enSortType; /* the sort field (a column or natural) */ - XP_Bool bSorting; - XP_HashTable aliasTable; - XP_HashTable nicknameTable; - int aliasID; - XP_Bool errorSavingBookmarks; - - int32 batch_depth; - int32 first_update_line; - int32 last_update_line; - - void* savetimer; - - BM_Entry* lastSelectedItem; - - BM_Entry* menuheader; /* Which header to use as the menu bar. */ - BM_Entry* addheader; /* Which entry to add new items into. */ - - XP_StatStruct laststat; /* Stat of the file when we loaded it in. */ - - - - struct BM_WhatsChangedInfo { - int32 total; - int32 numreached; - int32 numchanged; - time_t starttime; - } whatschanged; - -} BM_Frame; - - -#define CHKCONTEXT(context) \ -XP_ASSERT(context != NULL && (context->type == MWContextAddressBook || \ - context->type == MWContextBookmarks) && \ - context->bmframe != NULL); \ -if (!context || (context->type != MWContextAddressBook && \ - context->type != MWContextBookmarks) || \ - !context->bmframe) return 0; - -#define CHKCONTEXTVOID(context) \ -XP_ASSERT(context != NULL && (context->type == MWContextAddressBook || \ - context->type == MWContextBookmarks) && \ - context->bmframe != NULL); \ -if (!context || (context->type != MWContextAddressBook && \ - context->type != MWContextBookmarks) || \ - !context->bmframe) return; - - -/* Should probably be a macro, but putting the assert in the macro and - making this still be easy to use is just too painful. */ -static BM_Frame* -GETFRAME(MWContext* context) -{ - XP_ASSERT(context && - (context->type == MWContextBookmarks || - context->type == MWContextAddressBook) && - context->bmframe != NULL); - return (context && (context->type == MWContextBookmarks || - context->type == MWContextAddressBook)) - ? context->bmframe : NULL; -} - - -static void bm_CancelLastFind(MWContext* context); -static void bm_InsertItemAfter(MWContext* context, BM_Entry* insert_after, - BM_Entry* insertee, XP_Bool sync); -static void bm_SortSelected(MWContext* context, BM_SortType enSortType); -static void bm_SyncCount(MWContext* context); -static void bm_AddChildToHeaderSorted(MWContext* context, BM_Entry* parent, - BM_Entry* child); -static void bm_SortSilent(MWContext* context, BM_SortType enSortType ); - - - -XP_Bool -BM_IsHeader(BM_Entry* entry) -{ - return BM_ISHEADER(entry); -} - -XP_Bool -BM_IsUrl(BM_Entry* entry) -{ - return BM_ISURL(entry); -} - -XP_Bool -BM_IsAddress(BM_Entry* entry) -{ - return BM_ISADDRESS(entry); -} - -XP_Bool -BM_IsSeparator(BM_Entry* entry) -{ - return BM_ISSEPARATOR(entry); -} - -XP_Bool -BM_IsAlias(BM_Entry* entry) -{ - return BM_ISALIAS(entry); -} - -XP_Bool -BM_IsFolded(BM_Entry* entry) -{ - return BM_ISFOLDED(entry); -} - -XP_Bool -BM_IsSelected(BM_Entry* entry) -{ - return BM_ISSELECTED(entry); -} - - -int32 -BM_GetChangedState(BM_Entry* entry) -{ - if (BM_ISALIAS(entry)) { - entry = entry->d.alias.original; - } - if (BM_ISURL(entry)) { - if (entry->d.url.last_modified == 0 || entry->flags & BM_ATTR_CHECKING) { - return BM_CHANGED_UNKNOWN; - } - if (entry->d.url.last_visit < entry->d.url.last_modified) { - return BM_CHANGED_YES; - } - } - return BM_CHANGED_NO; -} - -/* globals */ -static MWContext* ContextList = NULL; - - -void -BM_SetFEData(MWContext* context, void* data) -{ - BM_Frame* f = GETFRAME(context); - CHKCONTEXTVOID(context); - f->feData = data; -} - -void* -BM_GetFEData(MWContext* context) -{ - BM_Frame* f = GETFRAME(context); - CHKCONTEXT(context); - return f->feData; -} - - -/* creates a new empty bookmark entry */ -static BM_Entry* -bm_NewEntry(int16 type) -{ - BM_Entry* new_entry = XP_NEW_ZAP(BM_Entry); - if (!new_entry) return NULL; - XP_MEMSET(new_entry, 0, sizeof(BM_Entry)); - new_entry->type = type; - return new_entry; -} - -/* creates a new header bookmarks entry */ -BM_Entry* -BM_NewHeader(const char* name) -{ - BM_Entry* header; - header = bm_NewEntry(BM_TYPE_HEADER); - if (!header) return NULL; - StrAllocCopy(header->name, name); - return header; -} - -/* creates a new URL bookmarks entry */ -BM_Entry* -BM_NewUrl(const char* name, const char* address, const char* content_type, - BM_Date last_visit) -{ - BM_Entry* url; - - url = bm_NewEntry(BM_TYPE_URL); - - if (!url) return NULL; - - StrAllocCopy(url->name, name); - url->description = NULL; - StrAllocCopy(url->d.url.address, address); - StrAllocCopy(url->d.url.content_type, content_type); - url->d.url.last_visit = last_visit; - url->d.url.last_modified = last_visit; /* ### Is this right? */ - url->addition_date = 0; - - return url; -} - -/* creates a new URL bookmarks entry */ -static BM_Entry* -bm_NewAddress(const char* name, const char* address) -{ - BM_Entry* add_struct; - - add_struct = bm_NewEntry(BM_TYPE_ADDRESS); - - if (!add_struct) return NULL; - - StrAllocCopy(add_struct->name, name ? name : ""); - StrAllocCopy(add_struct->d.address.address, address ? address : ""); - - return add_struct; -} - -/* creates a new separator bookmarks entry */ -static BM_Entry* -bm_NewSeparator(void) -{ - return bm_NewEntry(BM_TYPE_SEPARATOR); -} - -/* creates a new alias bookmarks entry */ -static BM_Entry* -bm_NewAlias(BM_Entry* original) -{ - BM_Entry* alias; - alias = bm_NewEntry(BM_TYPE_ALIAS); - alias->d.alias.original = original; - BM_SETFLAG(original, BM_ATTR_HASALIASES); - return alias; -} - -extern BM_Entry* BM_CopyBookmark(MWContext* context, BM_Entry* original) -{ - BM_Entry* copy; - BM_Entry* child; - BM_Entry* childCopy; - - copy = NULL; - - if(!original) - return NULL; - - switch (original->type) { - case BM_TYPE_URL: - copy = BM_NewUrl(original->name, original->d.url.address, - original->d.url.content_type, original->d.url.last_visit); - break; - case BM_TYPE_ADDRESS: - copy = bm_NewAddress(original->name, original->d.address.address); - break; - case BM_TYPE_SEPARATOR: - copy = bm_NewSeparator(); - break; - case BM_TYPE_ALIAS: - copy = bm_NewAlias(original->d.alias.original); - break; - case BM_TYPE_HEADER: - copy = BM_NewHeader(original->name); - - child = original->d.header.children; - - while (child) { - childCopy = BM_CopyBookmark(context, child); - if(childCopy) - BM_AppendToHeader(context, copy, childCopy); - child = child->next; - } - break; - } - - if(copy) - { - StrAllocCopy(copy->description, original->description); - StrAllocCopy(copy->nickname, original->nickname); - } - return copy; -} - -/* gets the top node of the bmlist */ -BM_Entry* -BM_GetRoot(MWContext* context) -{ - BM_Frame* f = GETFRAME(context); - CHKCONTEXT(context); - if (!f) return NULL; - if (!f->gBookmarks) { - f->gBookmarks = BM_NewHeader(context->type == MWContextBookmarks ? - XP_GetString(XP_BKMKS_HEADER) : XP_GetString(XP_ADDRBOOK_HEADER)); - if (context->type == MWContextBookmarks) { - f->menuheader = f->addheader = f->gBookmarks; - } - bm_SyncCount(context); - } else { - if (f->gBookmarks->parent != NULL) - XP_ASSERT(f->gBookmarks->next == NULL); /* Stupid consistancy test; - dunno what action to take if - this isn't so. */ - } - return f->gBookmarks; -} - -static void -bm_EachEntryDo_1(MWContext* context, BM_Entry* at, EntryFunc func, void* closure) -{ - BM_Entry* nextChild; - BM_Entry* children; - - while (at) { - nextChild = at->next; - if (BM_ISHEADER(at)) { - children = at->d.header.children; - } else { - children = NULL; - } - - (*func)(context, at, closure); - - if (children) { - bm_EachEntryDo_1(context, children, func, closure); - } - - at = nextChild; - } -} - -static void -bm_EachSelectedEntryDo_1(MWContext* context, BM_Entry* at, EntryFunc func, - void* closure) -{ - BM_Entry* nextChild; - BM_Entry* children; - - while (at) { - nextChild = at->next; - if (BM_ISHEADER(at)) { - children = at->d.header.children; - } else { - children = NULL; - } - - if (BM_ISSELECTED(at)) (*func)(context, at, closure); - - if (children) { - bm_EachSelectedEntryDo_1(context, children, func, closure); - } - - at = nextChild; - } -} - -static void -bm_EachProperSelectedEntryDo_1(MWContext* context, BM_Entry* at, EntryFunc func, - void* closure, struct BM_Entry_Focus* bmFocus) -{ - BM_Entry* child; - BM_Entry* nextChild; - - XP_ASSERT(at); - if (!at) return; - - XP_ASSERT(BM_ISHEADER(at)); - child = at->d.header.children; - - while (child) { - nextChild = child->next; - switch (child->type) { - case BM_TYPE_URL: - case BM_TYPE_ADDRESS: - case BM_TYPE_SEPARATOR: - case BM_TYPE_ALIAS: - if (BM_ISSELECTED(child)) { - if ((bmFocus != NULL) && !bmFocus->foundSelection) - bmFocus->foundSelection = TRUE; - (*func)(context, child, closure); - } - else if (bmFocus && !bmFocus->foundSelection) { - bmFocus->saveFocus = child; - } - break; - case BM_TYPE_HEADER: - if (BM_ISSELECTED(child)) { - if ((bmFocus != NULL) && !bmFocus->foundSelection) - bmFocus->foundSelection = TRUE; - (*func)(context, child, closure); - } - else { - if (bmFocus && !bmFocus->foundSelection) - bmFocus->saveFocus = child; - if (! BM_ISFOLDED(child)) { - bm_EachProperSelectedEntryDo_1(context, child, func, closure, bmFocus); - } - } - break; - } - child = nextChild; - } -} - - - -void -BM_EachEntryDo(MWContext* context, EntryFunc func, void* closure) -{ - CHKCONTEXTVOID(context); - bm_EachEntryDo_1(context, BM_GetRoot(context), func, closure); -} - -void -BM_EachSelectedEntryDo(MWContext* context, EntryFunc func, void* closure) -{ - CHKCONTEXTVOID(context); - bm_EachSelectedEntryDo_1(context, BM_GetRoot(context), func, closure); -} - -void -BM_EachProperSelectedEntryDo(MWContext* context, EntryFunc func, void* closure, - struct BM_Entry_Focus* bmFocus) -{ - CHKCONTEXTVOID(context); - bm_EachProperSelectedEntryDo_1(context, BM_GetRoot(context), func, closure, - bmFocus); -} - - - -static void -bm_ClearMarkEverywhere_1(MWContext* context, BM_Entry* entry, void* closure) -{ - BM_CLEARFLAG(entry, BM_ATTR_MARKED); -} - - -static void -bm_ClearMarkEverywhere(MWContext* context) -{ - BM_EachEntryDo(context, bm_ClearMarkEverywhere_1, NULL); -} - - -static MWContext* -bm_GetContextForEntry(BM_Entry* entry) -{ - MWContext* result; - BM_Frame* f; - while (entry->parent) entry = entry->parent; - for (result = ContextList ; result ; result = f->next) { - f = GETFRAME(result); - if (f->gBookmarks == entry) return result; - } - return NULL; -} - - -BM_Type -BM_GetType(BM_Entry* entry) -{ - XP_ASSERT(entry); - return entry ? entry->type : 0; -} - - -/* return the "name" for item -- may vary depending on its type */ -char* -BM_GetName(BM_Entry* entry) -{ - XP_ASSERT(entry); - if (!entry) return NULL; - - switch (entry->type) { - case BM_TYPE_URL: - case BM_TYPE_HEADER: - case BM_TYPE_ADDRESS: - return entry->name; - case BM_TYPE_ALIAS: - if (entry->d.alias.original) - return BM_GetName(entry->d.alias.original); - else - return entry->name; - default: - return NULL; - } -} - -/* return the "address" for item -- may vary depending - on its type */ -char* -BM_GetAddress(BM_Entry* entry) -{ - XP_ASSERT(entry); - if (!entry) return NULL; - - switch (entry->type) { - case BM_TYPE_URL: - return entry->d.url.address; - case BM_TYPE_ADDRESS: - return entry->d.address.address; - case BM_TYPE_HEADER: - case BM_TYPE_SEPARATOR: - case BM_TYPE_ALIAS: - if (entry->d.alias.original) return BM_GetAddress(entry->d.alias.original); - return NULL; - default: - return NULL; - } -} - -/* return the "target" for item -- may vary depending - on its type */ -char* -BM_GetTarget(BM_Entry* entry, XP_Bool recurse) -{ - XP_ASSERT(entry); - if (!entry) return NULL; - - switch (entry->type) { - case BM_TYPE_URL: - if ((recurse)&&(entry->d.url.target == NULL)&&(entry->parent != NULL)) - { - return BM_GetTarget(entry->parent, recurse); - } - else - { - return entry->d.url.target; - } - case BM_TYPE_HEADER: - if ((recurse)&&(entry->d.header.target == NULL)&&(entry->parent != NULL)) - { - return BM_GetTarget(entry->parent, recurse); - } - else - { - return entry->d.header.target; - } - case BM_TYPE_ADDRESS: - case BM_TYPE_SEPARATOR: - return NULL; - case BM_TYPE_ALIAS: - if (entry->d.alias.original) return BM_GetTarget(entry->d.alias.original, recurse); - return NULL; - default: - return NULL; - } -} - -/* return the "description" for item -- may vary depending on its type */ -char* -BM_GetDescription(BM_Entry* entry) -{ - XP_ASSERT(entry); - if (!entry) return NULL; - - switch (entry->type) { - case BM_TYPE_URL: - case BM_TYPE_HEADER: - case BM_TYPE_ADDRESS: - return entry->description; - default: - return NULL; - } -} - -char* -BM_GetNickName(BM_Entry* entry) -{ - XP_ASSERT(bm_GetContextForEntry(entry)->type == MWContextAddressBook); - if (BM_ISALIAS(entry)) return BM_GetNickName(entry->d.alias.original); - else return entry->nickname; -} - - -PRIVATE int32 -bm_CountAliases_1(BM_Entry* at, BM_Entry* forEntry) -{ - int32 count = 0; - for ( ; at ; at = at->next) { - if (BM_ISHEADER(at)) { - count += bm_CountAliases_1(at->d.header.children, forEntry); - } else if (BM_ISALIAS(at)) { - if (at->d.alias.original == forEntry) count++; - } - } - return count; -} - -PUBLIC int32 -BM_CountAliases(MWContext* context, BM_Entry* entry) -{ - int32 result; - CHKCONTEXT(context); - result = bm_CountAliases_1(BM_GetRoot(context), entry); - if (result) { - XP_ASSERT(entry->flags & BM_ATTR_HASALIASES); - BM_SETFLAG(entry, BM_ATTR_HASALIASES); - } else { - BM_CLEARFLAG(entry, BM_ATTR_HASALIASES); - } - return result; -} - -BM_Date -BM_GetLastVisited(BM_Entry *entry) -{ - XP_ASSERT(entry); - if (!entry || (entry->type != BM_TYPE_URL)) return 0; - - return entry->d.url.last_visit; -} - -BM_Date -BM_GetAdditionDate(BM_Entry *entry) -{ - XP_ASSERT(entry); - - if (!entry) return 0; - - return entry->addition_date; -} - - -/* pretty print the last visited date ### fix i18n */ -char* -BM_PrettyLastVisitedDate(BM_Entry* entry) -{ - static char buffer[200]; - - buffer[0] = 0; - - XP_ASSERT(entry); - if (!entry) return NULL; - - if (entry->type == BM_TYPE_URL) { - time_t lastVisited; - time_t today; - time_t elapsed; - - lastVisited = entry->d.url.last_visit; - if (lastVisited == 0) return ""; - today = XP_TIME(); - - elapsed = today - lastVisited; - - if (elapsed < SECONDS_PER_DAY) { - int32 hours = (elapsed + 1800L) / 3600L; - if (hours < 1) { - return XP_GetString(XP_BKMKS_LESS_THAN_ONE_HOUR_AGO); - } - sprintf(buffer, XP_GetString(XP_BKMKS_HOURS_AGO), hours); - } else if (elapsed < (SECONDS_PER_DAY * 31)) { - sprintf(buffer, XP_GetString(XP_BKMKS_DAYS_AGO), - (elapsed + (SECONDS_PER_DAY / 2)) / SECONDS_PER_DAY); - } else { - struct tm* tmp; - tmp = localtime(&lastVisited); - - sprintf(buffer, asctime(tmp)); - } - return buffer; - } - return NULL; -} - -/* pretty print the added on date */ -char* -BM_PrettyAddedOnDate(BM_Entry* entry) -{ - static char buffer[200]; - struct tm* tmp; - - XP_ASSERT(entry); - - if (entry && entry->addition_date != 0) { - tmp = localtime(&(entry->addition_date)); - sprintf(buffer, asctime(tmp)); - return buffer; - } - return NULL; -} - -char* -BM_PrettyAliasCount(MWContext* context, BM_Entry* entry) -{ - static char buffer[100]; - int32 count; - char* name = context->type == MWContextBookmarks ? - XP_GetString(XP_BKMKS_BOOKMARK) : XP_GetString(XP_BKMKS_ENTRY); - CHKCONTEXT(context); - XP_ASSERT(entry); - if (!entry) return NULL; - - count = BM_CountAliases(context, entry); - buffer[0] = 0; - - if (count > 1) { - sprintf(buffer, XP_GetString(XP_BKMKS_COUNTALIASES_MANY), count, name); - } else if (count == 1) { - sprintf(buffer, XP_GetString(XP_BKMKS_COUNTALIASES_ONE), name); - } else { - sprintf(buffer, XP_GetString(XP_BKMKS_COUNTALIASES_NONE), name); - } - return buffer; -} - - -BM_Entry* -BM_GetChildren(BM_Entry* entry) -{ - if (BM_ISHEADER(entry)) return entry->d.header.children; - return NULL; -} - -BM_Entry* -BM_GetNext(BM_Entry* entry) -{ - XP_ASSERT(entry); - return entry ? entry->next : NULL; -} - - -BM_Entry* -BM_GetParent(BM_Entry* entry) -{ - XP_ASSERT(entry); - return entry ? entry->parent : NULL; -} - - -XP_Bool -BM_HasNext(BM_Entry* entry) -{ - XP_ASSERT(entry); - return entry ? (entry->next != NULL) : FALSE; -} - - -XP_Bool -BM_HasPrev(BM_Entry* entry) -{ - BM_Entry* parent = entry->parent; - if (parent) { - XP_ASSERT(BM_ISHEADER(parent)); - return parent->d.header.children != entry; - } else { - return GETFRAME(bm_GetContextForEntry(entry))->gBookmarks != entry; - } -} - - -static void -bm_flush_updates(MWContext* context) -{ - BM_Frame* f = GETFRAME(context); - CHKCONTEXTVOID(context); - if (f->first_update_line > 0) { - BMFE_RefreshCells(context, f->first_update_line, f->last_update_line, - FALSE); - f->first_update_line = 0; - } -} - -static void -bm_start_batch(MWContext* context) -{ - BM_Frame* f = GETFRAME(context); - -#ifdef XP_UNIX - BMFE_StartBatch(context); -#endif - - CHKCONTEXTVOID(context); - if (f->undo) UNDO_StartBatch(f->undo); - f->batch_depth++; -} - -static void -bm_end_batch(MWContext* context) -{ - BM_Frame* f = GETFRAME(context); - CHKCONTEXTVOID(context); - f->batch_depth--; - XP_ASSERT(f->batch_depth >= 0); - if (f->batch_depth == 0) { - bm_flush_updates(context); - } - if (f->undo) UNDO_EndBatch(f->undo, NULL, NULL); - -#ifdef XP_UNIX - BMFE_EndBatch(context); -#endif -} - -static void -bm_refresh(MWContext* context, int32 first, int32 last) -{ - BM_Frame* f = GETFRAME(context); - CHKCONTEXTVOID(context); - XP_ASSERT(first >= 1 && first <= last); - if (first < 1 || first > last) { - /* Something bogus got passed in; just repaint everything to - be safe. */ - first = 1; - last = BM_LAST_CELL; - } - if (f->first_update_line <= 0 || - first > f->last_update_line + 1 || - last + 1 < f->first_update_line) { - bm_flush_updates(context); - f->first_update_line = first; - f->last_update_line = last; - } else { - if (f->first_update_line > first) f->first_update_line = first; - if (f->last_update_line < last) f->last_update_line = last; - } - if (f->batch_depth == 0) bm_flush_updates(context); -} - - -/* Handy routine to detect if we're already going to refresh everything. - If so, then the caller knows there's no need to refresh any more... */ -static XP_Bool -bm_refreshing_all(MWContext* context) -{ - BM_Frame* f = GETFRAME(context); - return (f != NULL && - f->first_update_line == 1 && - f->last_update_line == BM_LAST_CELL); -} - - -static void -bm_entry_changed_2(MWContext* context, BM_Entry* entry) -{ - int32 index = BM_GetIndex(context, entry); - if (index < 1) return; - if (context->type == MWContextBookmarks || entry->parent == NULL) { - bm_refresh(context, index, index); - } else { - /* Changing the entry might have messed up the sorting order. Better - go resort it. What a hack...*/ - BM_Entry* parent = entry->parent; - BM_RemoveChildFromHeader(context, parent, entry); - bm_AddChildToHeaderSorted(context, parent, entry); - } -} - -static void -bm_entry_changed_1(MWContext* context, BM_Entry* entry, BM_Entry* find) -{ - for (; entry ; entry = entry->next) { - if (BM_ISALIAS(entry) && entry->d.alias.original == find) { - bm_entry_changed_2(context, entry); - } else if (BM_ISHEADER(entry)) { - bm_entry_changed_1(context, entry->d.header.children, find); - } - } -} - -static void -bm_entry_changed(MWContext* context, BM_Entry* entry) -{ - XP_ASSERT(!BM_ISALIAS(entry)); - if (entry->flags & BM_ATTR_HASALIASES) { - bm_entry_changed_1(context, BM_GetRoot(context), entry); - } - bm_entry_changed_2(context, entry); -} - - -static void -bm_save_timer(void* closure) -{ - MWContext* context = (MWContext*) closure; - BM_Frame* f = GETFRAME(context); - f->savetimer = NULL; - BM_SaveBookmarks(context, NULL); -} - -/* The bookmarks have been modified somehow. Set or reset a timer to cause - them to be saved.*/ -static void -bm_SetModified(MWContext* context, XP_Bool mod) -{ - BM_Frame* f = GETFRAME(context); - f->gBookmarksModified = mod; - f->max_depth = 0; - if (f->savetimer) { - FE_ClearTimeout(f->savetimer); - f->savetimer = NULL; - } - if (mod) { - f->savetimer = FE_SetTimeout(bm_save_timer, context, - 60000L); /* ### hard-coding... */ - if (!f->savetimer) BM_SaveBookmarks(context, NULL); - } -} - -/* give LI the ability to set the modified to false */ -void -BM_SetModified(MWContext* context, XP_Bool mod) -{ - bm_SetModified(context, mod); -} - -typedef struct bm_setheader_info { - MWContext* context; - BM_Entry* entry; - XP_Bool isadd; -} bm_setheader_info; - -static void -bm_setheader_freeit(void* closure) -{ - XP_FREE((bm_setheader_info*) closure); -} - -static int bm_setheader_undo(void* closure); - -static void -bm_SetMenuOrAddHeader(MWContext* context, BM_Entry* entry, XP_Bool isadd) -{ - BM_Frame* f = GETFRAME(context); - XP_ASSERT(context->type == MWContextBookmarks); - XP_ASSERT(BM_ISHEADER(entry)); - if (context->type == MWContextBookmarks && f && BM_ISHEADER(entry)) { - if (f->undo) { - bm_setheader_info* info = XP_NEW_ZAP(bm_setheader_info); - if (!info) { - UNDO_DiscardAll(f->undo); - } else { - info->context = context; - info->entry = isadd ? f->addheader : f->menuheader; - info->isadd = isadd; - UNDO_LogEvent(f->undo, bm_setheader_undo, bm_setheader_freeit, info, NULL, NULL); - } - } - bm_start_batch(context); - bm_entry_changed(context, isadd ? f->addheader : f->menuheader); - if (isadd) f->addheader = entry; - else f->menuheader = entry; - bm_entry_changed(context, entry); - if (!isadd) BMFE_BookmarkMenuInvalid(context); - bm_SetModified(context, TRUE); - bm_end_batch(context); - } -} - -int bm_setheader_undo(void* closure) -{ - bm_setheader_info* info = (bm_setheader_info*) closure; - bm_SetMenuOrAddHeader(info->context, info->entry, info->isadd); - return 0; -} - -BM_Entry* -BM_GetMenuHeader(MWContext* context) -{ - BM_Frame* f = GETFRAME(context); - XP_ASSERT(context->type == MWContextBookmarks); - return f ? f->menuheader : NULL; -} - -void BM_SetMenuHeader(MWContext* context, BM_Entry* entry) -{ - bm_SetMenuOrAddHeader(context, entry, FALSE); -} - - -BM_Entry* -BM_GetAddHeader(MWContext* context) -{ - BM_Frame* f = GETFRAME(context); - XP_ASSERT(context->type == MWContextBookmarks); - return f ? f->addheader : NULL; -} - -void BM_SetAddHeader(MWContext* context, BM_Entry* entry) -{ - bm_SetMenuOrAddHeader(context, entry, TRUE); -} - - -typedef struct bm_copy_string_info { - MWContext* context; - BM_Entry* entry; - char** string; - char* value; -} bm_copy_string_info; - - -static void -bm_copy_string_freeit(void* closure) -{ - bm_copy_string_info* info = (bm_copy_string_info*) closure; - FREEIF(info->value); - XP_FREE(info); -} - -static int bm_copy_string_undo(void* closure); - -static int -bm_CopyStringWithUndo(MWContext* context, BM_Entry* entry, char** string, - const char* value) -{ - BM_Frame* f = GETFRAME(context); - int status = 0; - bm_SetModified(context, TRUE); - if (f->undo) { - bm_copy_string_info* info = XP_NEW_ZAP(bm_copy_string_info); - if (!info) { - UNDO_DiscardAll(f->undo); - status = MK_OUT_OF_MEMORY; - } else { - info->context = context; - info->entry = entry; - info->string = string; - info->value = *string ? XP_STRDUP(*string) : NULL; - UNDO_LogEvent(f->undo, bm_copy_string_undo, bm_copy_string_freeit, - info, NULL, NULL); - } - } - if (*string) XP_FREE(*string); - *string = value ? XP_STRDUP(value) : NULL; - bm_entry_changed(context, entry); - return 0; -} - -static int -bm_copy_string_undo(void* closure) -{ - bm_copy_string_info* info = (bm_copy_string_info*) closure; - if (info->string == &(info->entry->nickname)) { - /* Have to use BM_SetNickName to get side effect of changing hashtable. */ - BM_SetNickName(info->context, info->entry, info->value); - } else { - bm_CopyStringWithUndo(info->context, info->entry, info->string, - info->value); - } - return 0; -} - - - -/* sets the name for a bm entry */ -void -BM_SetName(MWContext* context, BM_Entry* entry, const char* newName) -{ - CHKCONTEXTVOID(context); - XP_ASSERT(entry); - if (!entry) return; - BM_CLEARFLAG(entry, BM_ATTR_ISNEW); - - switch (entry->type) { - case BM_TYPE_URL: - case BM_TYPE_HEADER: - case BM_TYPE_ADDRESS: - if (entry->name == NULL || XP_STRCMP(entry->name, newName) != 0) { - bm_CopyStringWithUndo(context, entry, &entry->name, newName); - BMFE_BookmarkMenuInvalid(context); - } - break; - case BM_TYPE_ALIAS: - BM_SetName(context, entry->d.alias.original, newName); - break; - } -} - - - -/* sets the location field of a bm_url bookmarks entry */ -void -BM_SetAddress(MWContext* context, BM_Entry* entry, const char* newAddress) -{ - CHKCONTEXTVOID(context); - XP_ASSERT(entry); - if (!entry) return; - BM_CLEARFLAG(entry, BM_ATTR_ISNEW); - - switch (entry->type) { - case BM_TYPE_URL: - if (entry->d.url.address == NULL || - XP_STRCMP(entry->d.url.address, newAddress) != 0) { - bm_CopyStringWithUndo(context, entry, &entry->d.url.address, newAddress); - } - break; - case BM_TYPE_ADDRESS: - if (entry->d.address.address == NULL || - XP_STRCMP(entry->d.address.address, newAddress) != 0) { - bm_CopyStringWithUndo(context, entry, &entry->d.address.address, - newAddress); - } - break; - case BM_TYPE_ALIAS: - BM_SetAddress(context, entry->d.alias.original, newAddress); - break; - } -} - - -/* sets the target field of a bm_url bookmarks entry */ -void -BM_SetTarget(MWContext* context, BM_Entry* entry, const char* newTarget) -{ - CHKCONTEXTVOID(context); - XP_ASSERT(entry); - if (!entry) return; - BM_CLEARFLAG(entry, BM_ATTR_ISNEW); - - switch (entry->type) { - case BM_TYPE_URL: - if (entry->d.url.target == NULL || - XP_STRCMP(entry->d.url.target, newTarget) != 0) { - bm_CopyStringWithUndo(context, entry, &entry->d.url.target, newTarget); - if (entry->d.url.target[0] == '\0') { - entry->d.url.target = NULL; - } - } - break; - case BM_TYPE_HEADER: - if (entry->d.header.target == NULL || - XP_STRCMP(entry->d.header.target, newTarget) != 0) { - bm_CopyStringWithUndo(context, entry, &entry->d.header.target, newTarget); - if (entry->d.header.target[0] == '\0') { - entry->d.header.target = NULL; - } - } - break; - case BM_TYPE_ADDRESS: - break; - case BM_TYPE_ALIAS: - BM_SetAddress(context, entry->d.alias.original, newTarget); - break; - } -} - -/* sets the description field of an entry */ -PUBLIC void -BM_SetDescription(MWContext* context, BM_Entry* entry, const char* newDesc) -{ - CHKCONTEXTVOID(context); - XP_ASSERT(entry); - if (!entry) return; - BM_CLEARFLAG(entry, BM_ATTR_ISNEW); - - switch (entry->type) { - case BM_TYPE_URL: - case BM_TYPE_HEADER: - case BM_TYPE_ADDRESS: - if (entry->description == NULL || - XP_STRCMP(entry->description, newDesc)) { - bm_CopyStringWithUndo(context, entry, &entry->description, newDesc); - } - break; - case BM_TYPE_ALIAS: - BM_SetDescription(context, entry->d.alias.original, newDesc); - break; - } -} - - -/* BM_SetNickName returns FALSE if it reported an error to the user . - * It returns TRUE if everything worked fine. - * 5-16-95 jefft - * Passing in NULL value removes the entry from the hash table. - */ - -XP_Bool -BM_SetNickName(MWContext* context, BM_Entry* entry, const char* value) -{ - BM_Frame* f = GETFRAME(context); - char* pName; - CHKCONTEXT(context); - XP_ASSERT(context->type == MWContextAddressBook); - if (!entry) return(TRUE); - if (!value) { - /* 5-16-95 jefft -- bug#: 20808, remove entry from the hash table */ - if (entry->nickname && *entry->nickname) { - XP_Remhash(f->nicknameTable, entry->nickname); - FREEIF(entry->nickname); - } - return(TRUE); - } - - /* allocate a copy of the string so we can modify it to be a legal alias */ - /* But only if value is non-null */ - pName = (value) ? XP_STRDUP(value) : NULL; - if (value && !pName) return(FALSE); - - BM_CLEARFLAG(entry, BM_ATTR_ISNEW); - - if (BM_ISALIAS(entry)) { - XP_Bool retVal; - retVal = BM_SetNickName(context, entry->d.alias.original, value); - XP_FREE(pName); - return(retVal); - } else { - if (entry->nickname == NULL || value == NULL || XP_STRCMP(entry->nickname, value)) { - if (pName != NULL) - { - char* ptr; - for (ptr = pName ; *ptr ; ptr++) { - if (!isalnum(*ptr) && (*ptr != '-') && (*ptr != '_')) { - FE_Alert(context, XP_GetString(XP_BKMKS_INVALID_NICKNAME)); - XP_FREE(pName); - return(FALSE); - } - /* convert to lowercase */ - if (isupper(*ptr)) { - *ptr = (char)tolower(*ptr); - } - } - if (XP_Gethash(f->nicknameTable, pName, NULL)) { - FE_Alert(context, XP_GetString(XP_BKMKS_NICKNAME_ALREADY_EXISTS)); - FREEIF(pName); - return(FALSE); - } - } - } - if (entry->nickname && *entry->nickname) { - XP_Remhash(f->nicknameTable, entry->nickname); - } - bm_CopyStringWithUndo(context, entry, &entry->nickname, pName); - if (entry->nickname && *entry->nickname) { - XP_Puthash(f->nicknameTable, entry->nickname, entry); - } - } - FREEIF(pName); - return(TRUE); -} - - - -void -BM_CancelEdit(MWContext* context, BM_Entry* entry) -{ - CHKCONTEXTVOID(context); - bm_start_batch(context); - if (entry && (entry->flags & BM_ATTR_ISNEW) && - !(entry->flags & BM_ATTR_HASALIASES) && entry->parent) { - BM_RemoveChildFromHeader(context, entry->parent, entry); - BM_FreeEntry(context, entry); - bm_refresh(context, 1, BM_LAST_CELL); - } - bm_end_batch(context); -} - - - -/* returns the number of children parent has - if visible is TRUE, only visible children are counted, - otherwise all children are counted */ -static int32 -bm_CountChildren(BM_Entry* parent, XP_Bool visible) -{ - BM_Entry* child; - int32 count = 1; - - XP_ASSERT(parent); - XP_ASSERT(BM_ISHEADER(parent)); - - if (!parent || !BM_ISHEADER(parent)) return 0; - - if (!visible || !(parent->flags & BM_ATTR_FOLDED)) { - child = parent->d.header.children; - while (child) { - if (BM_ISHEADER(child)) { - count += bm_CountChildren(child, visible); - } else { - count++; - } - child = child->next; - } - } - - return count; -} - - -static void -bm_WidestEntry_1(MWContext* context, BM_Entry* parent, BM_Entry** widest, - uint32* widestWidth) -{ - BM_Entry* child; - uint32 width; - uint32 height; - - XP_ASSERT(parent); - XP_ASSERT(BM_ISHEADER(parent)); - XP_ASSERT(widestWidth); - XP_ASSERT(widest); - - BMFE_MeasureEntry(context, parent, &width, &height); - - if (width > *widestWidth) { - *widestWidth = width; - *widest = parent; - } - - if (!(BM_ISFOLDED(parent))) { - child = parent->d.header.children; - while (child) { - if (BM_ISHEADER(child)) { - bm_WidestEntry_1(context, child, widest, widestWidth); - } else { - BMFE_MeasureEntry(context, child, &width, &height); - if (width > *widestWidth) { - *widestWidth = width; - *widest = child; - } - } - child = child->next; - } - } -} - -/* returns the widest visible entry in the tree -(this uses a FE function to measure the width) */ -PUBLIC BM_Entry* -BM_WidestEntry(MWContext* context) -{ - BM_Entry* widest = NULL; - uint32 widestWidth = 0; - CHKCONTEXT(context); - - bm_WidestEntry_1(context, BM_GetRoot(context), &widest, &widestWidth); - return widest; -} - - -static void -bm_SyncCount(MWContext* context) -{ - BM_Frame* f = GETFRAME(context); - if (f) { - f->gCount = -1; - f->gVisCount = -1; - } - BMFE_SyncDisplay(context); -} - -PRIVATE void -bm_SyncSelection_1(BM_Entry* parent, int32* count, uint32* selectionMask) -{ - BM_Entry* child; - - XP_ASSERT(parent); - XP_ASSERT(BM_ISHEADER(parent)); - - if (parent->flags & BM_ATTR_SELECTED) { - *selectionMask |= BM_TYPE_HEADER; - (*count)++; - } - - child = parent->d.header.children; - while (child) { - if (BM_ISHEADER(child)) { - bm_SyncSelection_1(child, count, selectionMask); - } else { - if (BM_ISSELECTED(child)) { - *selectionMask |= child->type; - (*count)++; - } - } - child = child->next; - } -} - -/* synchronizes the selection mask and the selection count with - what is actually selected - this is necessary when items become deselected because - we don't have a global selection list, only a count and - mask -*/ -static void -bm_SyncSelection(MWContext* context) -{ - BM_Frame* f = GETFRAME(context); - f->gSelectionCount = 0; - f->gSelectionMask = 0; - - bm_SyncSelection_1(BM_GetRoot(context), &(f->gSelectionCount), - &(f->gSelectionMask)); -} - -/* return the index number of item in cur_count with regards -to the BM_ATTR_FOLDED flag */ -PRIVATE int32 -bm_GetIndexNum(BM_Entry* parent, BM_Entry* item, int32* cur_count) -{ - BM_Entry* child; - int32 rv = 0; - - XP_ASSERT(parent); - XP_ASSERT(BM_ISHEADER(parent)); - - child = parent->d.header.children; - - if (parent == item) return *cur_count; - - while (child) { - (*cur_count)++; - - if (child == item) { - return *cur_count; - } - - /* if it's a header and it's unfolded, traverse it's children */ - if (child->type == BM_TYPE_HEADER && !BM_ISFOLDED(child)) { - rv = bm_GetIndexNum(child, item, cur_count); - if (rv) - return rv; - } - child = child->next; - } - return 0; -} - -/* return the index number of item in cur_count without regards to - the BM_ATTR_FOLDED flag */ -PRIVATE int32 -bm_GetUnfoldedIndexNum(BM_Entry* parent, BM_Entry* item, int32* cur_count) -{ - BM_Entry* child; - int32 rv = 0; - - XP_ASSERT(parent); - XP_ASSERT(parent->type == BM_TYPE_HEADER); - - if (parent == item) return *cur_count; - - for (child = parent->d.header.children; child; child = child->next) { - (*cur_count)++; - - if (child == item) return *cur_count; - - - if (child->type == BM_TYPE_HEADER) { - rv = bm_GetUnfoldedIndexNum(child, item, cur_count); - if (rv) return rv; - } - } - return 0; -} - -/* returns the child url entry of parent whose address is the same as - url_address */ -PRIVATE void -bm_FindItemStub(MWContext *context, BM_Entry* parent, char* url_address, EntryFunc pf, void *pClosure) -{ - BM_Entry* child; - - if (!parent) { /* Eric made me do it */ - return; - } - - for (child = parent->d.header.children; child; child = child->next) { - if (child->type == BM_TYPE_URL && child->d.url.address && - !XP_STRCMP(child->d.url.address, url_address)) { - (*pf)(context, child, pClosure); - } - if (child->type == BM_TYPE_HEADER) { - bm_FindItemStub(context, child, url_address, pf, pClosure); - } - } - return; -} - - -PRIVATE int32 -bm_GetDepth(BM_Entry* parent, BM_Entry* item) -{ - int32 rv = 0; - BM_Entry* next; - - if (!item) return -1; - - next = item; - while (next && next->parent) { /* I think extra "next &&" is - necessary for Win16 busted - optimizer... */ - rv++; - next = next->parent; - } - return rv; -} - - - -static void -bm_simple_freeit(void* closure) -{ - XP_FREE(closure); -} - - -typedef struct bm_delete_child_info { - MWContext* context; - BM_Entry* parent; - BM_Entry* child; -} bm_delete_child_info; - - -static int -bm_delete_child_doit(void* closure) -{ - bm_delete_child_info* info = (bm_delete_child_info*) closure; - BM_RemoveChildFromHeader(info->context, info->parent, info->child); - return 0; -} - - -static void -bm_LogDeleteChild(MWContext* context, BM_Entry* parent, BM_Entry* child) -{ - BM_Frame* f = GETFRAME(context); - bm_delete_child_info* info; - - /* Magic side effect -- if a child has just been added, and it doesn't have - an addition date set, set it to be now. */ - if (child->addition_date == 0) { - child->addition_date = XP_TIME(); - } - - if (!f || !f->undo) return; - bm_SetModified(context, TRUE); - info = XP_NEW_ZAP(bm_delete_child_info); - if (!info) { - UNDO_DiscardAll(f->undo); - } else { - info->context = context; - info->parent = parent; - info->child = child; - UNDO_LogEvent(f->undo, bm_delete_child_doit, bm_simple_freeit, info, NULL, NULL); - } -} - -/* appends a child item to a parent at the end of the - parents child list */ -static void -bm_AppendChildToHeader(MWContext* context, BM_Entry* parent, BM_Entry* child) -{ - BM_Frame* f = GETFRAME(context); - BM_Entry* lastChild; - - XP_ASSERT(parent); - XP_ASSERT(BM_ISHEADER(parent)); - XP_ASSERT(child); - XP_ASSERT(child != parent); - - f->gCount = -1; - f->gVisCount = -1; - - lastChild = parent->d.header.lastChild; - if (lastChild) { - lastChild->next = child; - parent->d.header.lastChild = child; - } else { - parent->d.header.children = child; - parent->d.header.lastChild = child; - } - - parent->d.header.childCount++; - child->parent = parent; - - if( !f->bSorting ) - child->iNaturalIndex = g_iNaturalIndexPool++; - - if (context) { - BMFE_BookmarkMenuInvalid(context); - bm_LogDeleteChild(context, parent, child); - } -} - -void -BM_AppendToHeader(MWContext* context, BM_Entry* parent, BM_Entry* child) -{ - int index; - bm_start_batch(context); - bm_AppendChildToHeader(context, parent, child); - index = BM_GetIndex(context, child); - if (index > 0) bm_refresh(context, index, BM_LAST_CELL); - bm_end_batch(context); -} - - -/* Add a child item to a parent at the beginning of the - parents child list */ -void -BM_PrependChildToHeader(MWContext* context, BM_Entry* parent, BM_Entry* child) -{ - BM_Frame* f = GETFRAME(context); - BM_Entry* firstChild; - - XP_ASSERT(parent); - XP_ASSERT(parent->type == BM_TYPE_HEADER); - XP_ASSERT(child); - XP_ASSERT(child != parent); - - f->gCount = -1; - f->gVisCount = -1; - firstChild = parent->d.header.children; - if (!firstChild) { - bm_AppendChildToHeader(context, parent, child); - } else { - child->next = firstChild; - parent->d.header.children = child; - - parent->d.header.childCount++; - child->parent = parent; - - if( !f->bSorting ) - child->iNaturalIndex = g_iNaturalIndexPool++; - - if (context) { - BMFE_BookmarkMenuInvalid(context); - bm_LogDeleteChild(context, parent, child); - } - } -} - - -static int -bm_SortAddressBook(const void* obj1, const void* obj2) -{ - const BM_Entry* entry1 = (const BM_Entry*) obj1; - const BM_Entry* entry2 = (const BM_Entry*) obj2; - - if (BM_ISALIAS(entry1)) { - entry1 = entry1->d.alias.original; - XP_ASSERT(!BM_ISALIAS(entry1)); - } - if (BM_ISALIAS(entry2)) { - entry2 = entry2->d.alias.original; - XP_ASSERT(!BM_ISALIAS(entry2)); - } - XP_ASSERT(BM_ISHEADER(entry1) || BM_ISADDRESS(entry1)); - XP_ASSERT(BM_ISHEADER(entry2) || BM_ISADDRESS(entry2)); - if (entry1 == entry2) return 0; /* Can happen with two aliases to the same - thing... */ - if (BM_ISHEADER(entry1)) { - if (BM_ISHEADER(entry2)) { -#ifdef INTL_SORT - return XP_StrColl(entry1->name, entry2->name); -#else - return XP_STRCMP(entry1->name, entry2->name); -#endif - } else { - return 1; - } - } else { - if (BM_ISHEADER(entry2)) { - return -1; - } else { -#ifdef INTL_SORT - return XP_StrColl(entry1->name, entry2->name); -#else - return XP_STRCMP(entry1->name, entry2->name); -#endif - } - } -} - - -static BM_Entry* -bm_RealEntry(BM_Entry* entry) -{ - if (BM_ISALIAS(entry)) return entry->d.alias.original; - else return entry; -} - - -/* Adds a child item to a parent, sorting it according to address book sorting - rules. */ -static void -bm_AddChildToHeaderSorted(MWContext* context, BM_Entry* parent, - BM_Entry* child) -{ - BM_Frame* f = GETFRAME(context); - BM_Entry* entry; - BM_Entry* previous = NULL; - XP_ASSERT(context->type == MWContextAddressBook); - XP_ASSERT(BM_ISHEADER(parent)); - if (!BM_ISALIAS(child)) parent = BM_GetRoot(context); - if (parent->d.header.lastChild && - bm_SortAddressBook(parent->d.header.lastChild, child) < 0) { - /* Ah, the most common case (especially when loading from a file). This - kid goes last. */ - previous = parent->d.header.lastChild; - bm_AppendChildToHeader(context, parent, child); - } else { - for (entry = parent->d.header.children ; entry ; entry = entry->next) { - int value = bm_SortAddressBook(entry, child); - if (value > 0) break; - if (value == 0) { - /* Hmm. Let's not allow any duplicate aliases to the same thing - in the same header. */ - if (bm_RealEntry(entry) == bm_RealEntry(child)) { - if (BM_ISALIAS(child)) { - BM_FreeEntry(context, child); - } else { - XP_ASSERT(BM_ISALIAS(entry)); - BM_RemoveChildFromHeader(context, parent, entry); - bm_AddChildToHeaderSorted(context, parent, child); - } - return; - } - } - previous = entry; - } - if (previous == NULL) { - BM_PrependChildToHeader(context, parent, child); - previous = parent; - } else { - bm_InsertItemAfter(context, previous, child, FALSE); - } - } - f->gCount = -1; - f->gVisCount = -1; - if (!BM_ISFOLDED(parent) && !bm_refreshing_all(context)) { - int index = BM_GetIndex(context, previous); - if (index > 0) { - f->gVisCount++; - bm_refresh(context, index + 1, BM_LAST_CELL); - } - } -} - -static BM_Entry* -bm_get_previous(BM_Entry* entry) -{ - BM_Entry* child; - BM_Entry* previous = NULL; - - if (entry && entry->parent) { - child = entry->parent->d.header.children; - previous = NULL; - while (child && child != entry) { - previous = child; - child = child->next; - } - } - - if (child == NULL) previous = NULL; - - return previous; -} - - - -typedef struct bm_add_child_info { - MWContext* context; - BM_Entry* parent; - BM_Entry* previous; - BM_Entry* child; -} bm_add_child_info; - - -static int -bm_add_child_doit(void* closure) -{ - bm_add_child_info* info = (bm_add_child_info*) closure; - XP_ASSERT(info->previous == NULL || info->previous->parent == info->parent); - if (info->previous) { - bm_InsertItemAfter(info->context, info->previous, info->child, FALSE); - } else { - BM_PrependChildToHeader(info->context, info->parent, info->child); - } - BM_ClearAllSelection(info->context, FALSE); - return 0; -} - - - -void BM_RemoveChildFromHeader(MWContext* context, BM_Entry* parent, BM_Entry* child) -{ - BM_Frame* f = GETFRAME(context); - BM_Entry* previous; - - XP_ASSERT(BM_ISHEADER(parent)); - if (!BM_ISHEADER(parent)) return; - XP_ASSERT(child); - if (!child) return; - XP_ASSERT(child != parent); - if (child == parent) return; - XP_ASSERT(child->parent == parent); - if (child->parent != parent) return; - - if (context && (child->flags & BM_ATTR_SELECTED)) { - BM_SelectItem(context, child, TRUE, TRUE, FALSE); - } - previous = bm_get_previous(child); - - if (previous) previous->next = child->next; - - if (parent->d.header.children == child) { - parent->d.header.children = child->next; - } - - if (parent->d.header.lastChild == child) { - parent->d.header.lastChild = previous; - } - - f->gCount = -1; - f->gVisCount = -1; - - parent->d.header.childCount--; - - if (context) { - BM_Frame* f = GETFRAME(context); - bm_add_child_info* info; - BMFE_BookmarkMenuInvalid(context); - bm_SetModified(context, TRUE); - if (f->undo) { - info = XP_NEW_ZAP(bm_add_child_info); - if (!info) { - UNDO_DiscardAll(f->undo); - } else { - info->context = context; - info->parent = parent; - info->previous = previous; - info->child = child; - UNDO_LogEvent(f->undo, bm_add_child_doit, bm_simple_freeit, info, NULL, NULL); - } - } - } - child->parent = NULL; - child->next = NULL; -} - - - -#define BM_HEADER_BEGIN 0xD000 -#define BM_HEADER_END 0xE000 -#define BM_UNKNOWN 0xF000 - -static uint16 -bm_tokenize_line(MWContext* context, char* buffer, char** ptr) -{ - if ((*ptr = strcasestr(buffer, "HREF=\""))) { - return context->type == MWContextBookmarks ? BM_TYPE_URL : BM_TYPE_ADDRESS; - } else if ((*ptr = strcasestr(buffer, ""))) { - return BM_TYPE_SEPARATOR; - } else if (strcasestr(buffer, "") || - strcasestr(buffer, "") || - strcasestr(buffer, "")) { - return BM_HEADER_END; - } else if (strcasestr(buffer, "") || - strcasestr(buffer_ptr, "") || - strcasestr(buffer_ptr, "")) - { - /* end of a header */ - if(item != hot_list) - return; - } - else - { - /* assume the rest is descriptions - * only add if new_item is a URL - */ - if(new_item && new_item->type == HOT_URLType) - { - /* skip
if present */ - if(*buffer_ptr == '<') - buffer_ptr += 4; - - end = buffer_ptr+XP_STRLEN(buffer_ptr)-1; - - /* check for
on the end and remove it - * - * also add a return - */ - if(*end == '>') - { - end -= 3; - XP_STRCPY(end, LINEBREAK); - end += XP_STRLEN(LINEBREAK); - *end = '\0'; - } - else - { - end++; - XP_STRCPY(end, LINEBREAK); - end += XP_STRLEN(LINEBREAK); - *end = '\0'; - } - - /* go through and turn < into '<' - */ - for(ptr=buffer_ptr, end=buffer_ptr; *end != '\0'; end++) - { - if(!strncasecomp(end, "<", 4)) - { - end += 3; - *ptr++ = '<'; - } - else - { - *ptr++ = *end; - } - } - *ptr = '\0'; /* terminate */ - - StrAllocCat(new_item->description, buffer_ptr); - } - } - - if(new_item) - { - /* search for other general attributes - */ - if((ptr = strcasestr(buffer_ptr, "ADD_DATE=\""))!=0) - { - end = XP_STRCHR(ptr+10, '"'); - - if(end) - { - *end = '\0'; - if(new_item) - new_item->addition_date = (time_t) atol(ptr+10); - *end = '"'; - } - } - - if((ptr = strcasestr(buffer_ptr, "LAST_VISIT=\""))!=0) - { - end = XP_STRCHR(ptr+12, '"'); - - if(end) - { - *end = '\0'; - if(new_item) - new_item->last_visit = (time_t) atol(ptr+12); - *end = '"'; - } - } - - if(!item_saved) - { - if(!item) - { - if(!hot_list) - { - if(new_item->type == HOT_HeaderType) - { - hot_list = new_item; - } - else - { - hot_list = HOT_CreateEntry(HOT_HeaderType, - DEF_NAME, NULL, NULL, 0); - if(!hot_list) - return; - - XP_ListAddObjectToEnd(hot_list->children, new_item); - new_item->parent = NULL; - new_item->lParent = XP_ListFindObject(hot_list->children, new_item); - } - } - - item = hot_list; - } - else - { - XP_ListAddObjectToEnd(item->children, new_item); - if(item == hot_list) - new_item->parent = NULL; - else - new_item->parent = item; - new_item->lParent = XP_ListFindObject(item->children, new_item); - - } - - item_saved = TRUE; - } - - if(new_item->type == HOT_HeaderType) - hot_ReadSaveList(fp, new_item, buffer, relative_url); - } - } -} - -/* read hotlist file from disk - * - * pass in a file url - */ -PUBLIC void -HOT_ReadHotlistFromDisk(char * filename, char * relative_url) -{ - XP_File fp; - char buffer[READ_BUFFER_SIZE]; - - fp = XP_FileOpen(filename, xpHotlist, XP_FILE_READ); - - if(!fp) - { - TRACEMSG(("could not open hotlist file for reading")); - return; - } - - TRACEMSG(("Reading MCC hotlist file")); - -/* DONT REQUIRE THE COOKIE FOR NOW - * - * if(XP_STRNCMP(buffer, HOTLIST_COOKIE, strlen(HOTLIST_COOKIE))) - * { - * TRACEMSG(("ERROR! - Hotlist cookie not found in hotlist file")); - * return; - * } - */ - /* hot_list probably doesn't exist yet - */ - hot_ReadSaveList(fp, hot_list, buffer, relative_url); - XP_FileClose(fp); - hot_list_modified = FALSE; - -} - - -PRIVATE void -hot_PrintList(XP_File fp, HotlistStruct * item, int level) -{ - int i; - char buffer[16]; - - /* indent - */ - for(i=0; itype == HOT_HeaderType) - { - XP_List * list_ptr = item->children; - HotlistStruct * obj_ptr; - - if(level != 0) - { - if(item->name) - { - XP_FileWrite("

is_folded) - XP_FileWrite("FOLDED ", -1, fp); - XP_FileWrite("ADD_DATE=\"", -1, fp); - XP_SPRINTF(buffer, "%ld\">", item->addition_date); - XP_FileWrite(buffer, XP_STRLEN(buffer), fp); - XP_FileWrite(item->name, XP_STRLEN(item->name), fp); - XP_FileWrite("

", -1, fp); - XP_FileWrite(LINEBREAK, XP_STRLEN(LINEBREAK), fp); - } - for(i=0; i

", -1, fp); - XP_FileWrite(LINEBREAK, XP_STRLEN(LINEBREAK), fp); - - while((obj_ptr = (HotlistStruct *) XP_ListNextObject(list_ptr))!=0) - hot_PrintList(fp, obj_ptr, level+1); - - for(i=0; i

", -1, fp); - XP_FileWrite(LINEBREAK, XP_STRLEN(LINEBREAK), fp); - } - else if(item->type == HOT_SeparatorType) - { - XP_FileWrite("


", -1, fp); - XP_FileWrite(LINEBREAK, XP_STRLEN(LINEBREAK), fp); - } - else if(item->address) /* item type */ - { - XP_FileWrite("
", -1, fp); - XP_FileWrite("address, XP_STRLEN(item->address), fp); - XP_FileWrite("\" ADD_DATE=\"", -1, fp); - - XP_SPRINTF(buffer, "%ld", item->addition_date); - XP_FileWrite(buffer, XP_STRLEN(buffer), fp); - - XP_FileWrite("\" LAST_VISIT=\"", -1, fp); - - XP_SPRINTF(buffer, "%ld\">", item->last_visit); - XP_FileWrite(buffer, XP_STRLEN(buffer), fp); - - if(item->name) - XP_FileWrite(item->name, XP_STRLEN(item->name), fp); - else - XP_FileWrite(item->address, XP_STRLEN(item->address), fp); - - XP_FileWrite("", -1, fp); - XP_FileWrite(LINEBREAK, XP_STRLEN(LINEBREAK), fp); - - /* write description if there is one - */ - if(item->description) - { - char *ptr = XP_StripLine(item->description); - - XP_FileWrite("
", -1, fp); - - for(; *ptr != '\0'; ptr++) - if(*ptr == '<') - { - XP_FileWrite("<", -1, fp); - } - else if(*ptr == '\n') - { - XP_FileWrite("
", -1, fp); - XP_FileWrite(LINEBREAK, XP_STRLEN(LINEBREAK), fp); - } - else - { - XP_FileWrite(ptr, 1, fp); - } - - XP_FileWrite(LINEBREAK, XP_STRLEN(LINEBREAK), fp); - } - } -} - -PUBLIC Bool -HOT_Modified (void) -{ - return (hot_list_modified); -} - -/* save out the hotlist - * - * returns 1 on success and 0 on failure - * NOTE: the hotlist may not be saved if nothing has - * changed - */ -PUBLIC int -HOT_SaveHotlist(char * filename) -{ - XP_File fp; - char buffer[128]; - const char * hot_list_name; - - if(!hot_list_modified) - return(1); /* don't rewrite */ - -#ifdef MOZ_MAIL_NEWS - hot_list_name = FE_UsersFullName(); - if(!hot_list_name) - hot_list_name = FE_UsersMailAddress(); -#else - hot_list_name = NULL; -#endif /* MOZ_MAIL_NEWS */ - -#if defined(DEBUG_BOOKMARKS) && defined(XP_UNIX) - fprintf (stderr, "HOT_SaveHotlist: writing %s\n", filename); -#endif - - fp = XP_FileOpen(filename, xpHotlist, XP_FILE_WRITE); - - if(!fp) - { - TRACEMSG(("could not open hotlist file for writing")); - return(0); - } - - /* write cookie - */ - XP_FileWrite(HOTLIST_COOKIE, strlen(HOTLIST_COOKIE), fp); - XP_FileWrite(LINEBREAK, XP_STRLEN(LINEBREAK), fp); - - XP_FileWrite(XP_GetString(XP_HOTLIST_AUTOGENERATED_FILE), -1, fp); - -/* L10N? are we still using this code? */ - XP_SPRINTF(buffer, "\ -%s%s Bookmarks\n\ -

%s%s Bookmarks

\n", hot_list_name ? hot_list_name : "Personal", - hot_list_name ? "'s" : "", - hot_list_name ? hot_list_name : "Personal", - hot_list_name ? "'s" : ""); - - XP_FileWrite(buffer, XP_STRLEN(buffer), fp); - - if(hot_list) - hot_PrintList(fp, hot_list, 0); - else - TRACEMSG(("No hotlist to write!")); - - XP_FileClose(fp); - - hot_list_modified = FALSE; - - return(1); -} - - -/* - * Gets the top node of the hotlist -*/ -PUBLIC HotlistStruct* -HOT_GetHotlist (void) -{ - if (!hot_list) - { - hot_list = HOT_CreateEntry (HOT_HeaderType, DEF_NAME, NULL, NULL, 0); - if (!hot_list) - return NULL; - hot_list->children = XP_ListNew (); - if (!hot_list->children) - { - HOT_FreeEntry(hot_list); - hot_list = NULL; - } - } - return hot_list; -} - -/* Free's the entire hotlist - */ -PUBLIC void -HOT_FreeHotlist (void) -{ - if (hot_list) - HOT_FreeEntry (hot_list); - hot_list = 0; -} diff --git a/mozilla/lib/libmisc/shist.c b/mozilla/lib/libmisc/shist.c index 6df8b9248a8..f32fe032e5e 100644 --- a/mozilla/lib/libmisc/shist.c +++ b/mozilla/lib/libmisc/shist.c @@ -36,15 +36,10 @@ #include "libi18n.h" -#include "hotlist.h" #include "net.h" #include "xp.h" #include "secnav.h" -#if !defined(XP_MAC) && !defined(XP_WIN32) /* macOS doesn't need this anymore... nor does Windows */ - #include "bkmks.h" -#endif - #ifdef EDITOR #include "edt.h" /* for EDT_IS_EDITOR macro */ extern char *XP_NEW_DOC_URL; @@ -246,37 +241,6 @@ SHIST_CreateWysiwygURLStruct(MWContext * ctxt, History_entry * entry) return URL_s; } -/* - * Returns NULL if the entry cannot be a hotlist item (form submission). - */ - -#if !defined(XP_MAC) && !defined(XP_WIN32) /* macOS doesn't need this anymore -- we're 100% RDF! so is windows! */ - -BM_Entry* SHIST_CreateHotlistStructFromHistoryEntry(History_entry * h) -{ - BM_Entry* hs = NULL; - if ((h == NULL) || h->post_data) /* Cannot make form submission into bookmarks */ - return NULL; - - /* if title is empty make the title the URL in the form www.XXX...YYY.html */ - if ( *h->title ) - hs = BM_NewUrl( h->title, h->address, NULL, h->last_access); - else - { - /* Strip off the protocol info (eg, http://) */ - char trunkedAddress [HIST_MAX_URL_LEN + 1]; - char* strippedAddress = SHIST_StripProtocol ( h->address ); - - /* truncate it */ - INTL_MidTruncateString ( 0, strippedAddress, trunkedAddress, HIST_MAX_URL_LEN ); - hs = BM_NewUrl( trunkedAddress, h->address, NULL, h->last_access); - } - - return hs; - -} /* SHIST_CreateHotlistStructFromHistoryEntry */ -#endif - /* * SHIST_StripProtocol *