2004-06-30 21:44:11 +04:00
|
|
|
/*
|
2005-03-19 02:52:38 +03:00
|
|
|
* Copyright 2004, 2005 Richard Wilson <info@tinct.net>
|
2014-01-03 02:25:23 +04:00
|
|
|
* Copyright 2010, 2013 Stephen Fryatt <stevef@netsurf-browser.org>
|
2007-08-08 20:16:03 +04:00
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2004-06-30 21:44:11 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
* Hotlist (implementation).
|
|
|
|
*/
|
|
|
|
|
2009-03-28 22:59:46 +03:00
|
|
|
#include <ctype.h>
|
2004-06-30 21:44:11 +04:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdbool.h>
|
2004-12-09 13:30:44 +03:00
|
|
|
#include <stdio.h>
|
2004-06-30 21:44:11 +04:00
|
|
|
#include <stdlib.h>
|
2004-07-03 20:28:09 +04:00
|
|
|
#include <time.h>
|
2004-07-04 18:59:29 +04:00
|
|
|
#include "oslib/osfile.h"
|
2011-10-09 17:32:43 +04:00
|
|
|
#include "oslib/osmodule.h"
|
2004-06-30 21:44:11 +04:00
|
|
|
#include "oslib/wimp.h"
|
2014-03-08 18:13:27 +04:00
|
|
|
|
2014-10-16 12:50:55 +04:00
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/messages.h"
|
|
|
|
#include "utils/utils.h"
|
|
|
|
#include "utils/nsoption.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "content/content.h"
|
2010-04-07 16:19:08 +04:00
|
|
|
#include "content/hlcache.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "content/urldb.h"
|
2013-09-02 19:19:16 +04:00
|
|
|
#include "desktop/hotlist.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "desktop/tree.h"
|
2014-10-16 12:50:55 +04:00
|
|
|
#include "desktop/gui_window.h"
|
2014-03-08 18:13:27 +04:00
|
|
|
|
|
|
|
#include "riscos/gui.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "riscos/dialog.h"
|
2010-10-05 23:14:46 +04:00
|
|
|
#include "riscos/hotlist.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "riscos/menus.h"
|
2011-10-09 17:32:43 +04:00
|
|
|
#include "riscos/message.h"
|
2010-10-05 23:14:46 +04:00
|
|
|
#include "riscos/save.h"
|
2011-02-21 02:16:33 +03:00
|
|
|
#include "riscos/toolbar.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "riscos/treeview.h"
|
|
|
|
#include "riscos/wimp.h"
|
|
|
|
#include "riscos/wimp_event.h"
|
2014-01-16 18:28:25 +04:00
|
|
|
#include "riscos/query.h"
|
2004-06-30 21:44:11 +04:00
|
|
|
|
2011-02-21 02:16:33 +03:00
|
|
|
static void ro_gui_hotlist_toolbar_update_buttons(void);
|
|
|
|
static void ro_gui_hotlist_toolbar_save_buttons(char *config);
|
|
|
|
static bool ro_gui_hotlist_menu_prepare(wimp_w w, wimp_i i, wimp_menu *menu,
|
|
|
|
wimp_pointer *pointer);
|
|
|
|
static void ro_gui_hotlist_menu_warning(wimp_w w, wimp_i i, wimp_menu *menu,
|
|
|
|
wimp_selection *selection, menu_action action);
|
|
|
|
static bool ro_gui_hotlist_menu_select(wimp_w w, wimp_i i, wimp_menu *menu,
|
|
|
|
wimp_selection *selection, menu_action action);
|
|
|
|
static void ro_gui_hotlist_toolbar_click(button_bar_action action);
|
2011-10-09 17:32:43 +04:00
|
|
|
static void ro_gui_hotlist_addurl_bounce(wimp_message *message);
|
2011-10-14 00:40:52 +04:00
|
|
|
static void ro_gui_hotlist_scheduled_callback(void *p);
|
2013-12-31 20:45:32 +04:00
|
|
|
static void ro_gui_hotlist_remove_confirmed(query_id id,
|
|
|
|
enum query_response res, void *p);
|
|
|
|
static void ro_gui_hotlist_remove_cancelled(query_id id,
|
|
|
|
enum query_response res, void *p);
|
|
|
|
|
|
|
|
static const query_callback remove_funcs = {
|
|
|
|
ro_gui_hotlist_remove_confirmed,
|
|
|
|
ro_gui_hotlist_remove_cancelled
|
|
|
|
};
|
2011-02-21 02:16:33 +03:00
|
|
|
|
|
|
|
struct ro_treeview_callbacks ro_hotlist_treeview_callbacks = {
|
|
|
|
ro_gui_hotlist_toolbar_click,
|
|
|
|
ro_gui_hotlist_toolbar_update_buttons,
|
|
|
|
ro_gui_hotlist_toolbar_save_buttons
|
|
|
|
};
|
|
|
|
|
2011-10-09 17:32:43 +04:00
|
|
|
/* Hotlist Protocol Message Blocks, which are currently not in OSLib. */
|
|
|
|
|
|
|
|
struct ro_hotlist_message_hotlist_addurl {
|
|
|
|
wimp_MESSAGE_HEADER_MEMBERS /**< The standard message header. */
|
|
|
|
char *url; /**< Pointer to the URL in RMA. */
|
|
|
|
char *title; /**< Pointer to the title in RMA. */
|
|
|
|
char appname[32]; /**< The application name. */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ro_hotlist_message_hotlist_changed {
|
|
|
|
wimp_MESSAGE_HEADER_MEMBERS /**< The standard message header. */
|
|
|
|
};
|
|
|
|
|
|
|
|
static char *hotlist_url = NULL; /**< URL area claimed from RMA. */
|
|
|
|
static char *hotlist_title = NULL; /**< Title area claimed from RMA. */
|
|
|
|
|
2013-12-31 20:45:32 +04:00
|
|
|
/** Hotlist Query Handler. */
|
|
|
|
|
|
|
|
static query_id hotlist_query = QUERY_INVALID;
|
|
|
|
static nsurl *hotlist_delete_url = NULL;
|
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
/* The RISC OS hotlist window, toolbar and treeview data. */
|
|
|
|
|
|
|
|
static struct ro_hotlist {
|
2011-10-09 17:32:43 +04:00
|
|
|
wimp_w window; /**< The hotlist RO window handle. */
|
|
|
|
struct toolbar *toolbar; /**< The hotlist toolbar handle. */
|
|
|
|
ro_treeview *tv; /**< The hotlist treeview handle. */
|
|
|
|
wimp_menu *menu; /**< The hotlist window menu. */
|
2010-10-05 23:14:46 +04:00
|
|
|
} hotlist_window;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Pre-Initialise the hotlist tree. This is called for things that need to
|
|
|
|
* be done at the gui_init() stage, such as loading templates.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_gui_hotlist_preinitialise(void)
|
2008-07-27 02:29:15 +04:00
|
|
|
{
|
2010-10-05 23:14:46 +04:00
|
|
|
/* Create our window. */
|
2004-07-04 23:27:42 +04:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
hotlist_window.window = ro_gui_dialog_create("tree");
|
|
|
|
ro_gui_set_window_title(hotlist_window.window,
|
2006-01-07 00:25:34 +03:00
|
|
|
messages_get("Hotlist"));
|
2004-06-30 21:44:11 +04:00
|
|
|
}
|
|
|
|
|
2004-07-09 02:05:35 +04:00
|
|
|
/**
|
2010-10-05 23:14:46 +04:00
|
|
|
* Initialise the hotlist tree, at the gui_init2() stage.
|
2004-07-09 02:05:35 +04:00
|
|
|
*/
|
2010-10-05 23:14:46 +04:00
|
|
|
|
|
|
|
void ro_gui_hotlist_postinitialise(void)
|
2008-07-27 02:29:15 +04:00
|
|
|
{
|
2010-10-05 23:14:46 +04:00
|
|
|
/* Create our toolbar. */
|
2005-04-08 00:46:22 +04:00
|
|
|
|
2011-02-21 02:16:33 +03:00
|
|
|
hotlist_window.toolbar = ro_toolbar_create(NULL, hotlist_window.window,
|
|
|
|
THEME_STYLE_HOTLIST_TOOLBAR, TOOLBAR_FLAGS_NONE,
|
|
|
|
ro_treeview_get_toolbar_callbacks(), NULL,
|
|
|
|
"HelpHotToolbar");
|
|
|
|
if (hotlist_window.toolbar != NULL) {
|
|
|
|
ro_toolbar_add_buttons(hotlist_window.toolbar,
|
|
|
|
hotlist_toolbar_buttons,
|
2012-03-22 13:34:34 +04:00
|
|
|
nsoption_charp(toolbar_hotlist));
|
2011-02-21 02:16:33 +03:00
|
|
|
ro_toolbar_rebuild(hotlist_window.toolbar);
|
|
|
|
}
|
2010-10-05 23:14:46 +04:00
|
|
|
|
|
|
|
/* Create the treeview with the window and toolbar. */
|
2013-08-15 22:38:00 +04:00
|
|
|
tree_hotlist_path = nsoption_charp(hotlist_path);
|
2010-10-05 23:14:46 +04:00
|
|
|
hotlist_window.tv = ro_treeview_create(hotlist_window.window,
|
2011-02-21 02:16:33 +03:00
|
|
|
hotlist_window.toolbar, &ro_hotlist_treeview_callbacks,
|
2013-09-02 17:42:53 +04:00
|
|
|
TREE_HOTLIST);
|
2010-10-05 23:14:46 +04:00
|
|
|
if (hotlist_window.tv == NULL) {
|
|
|
|
LOG(("Failed to allocate treeview"));
|
2006-01-06 15:59:29 +03:00
|
|
|
return;
|
2010-10-05 23:14:46 +04:00
|
|
|
}
|
2004-12-09 13:30:44 +03:00
|
|
|
|
2011-02-21 02:16:33 +03:00
|
|
|
ro_toolbar_update_client_data(hotlist_window.toolbar,
|
|
|
|
hotlist_window.tv);
|
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
/* Build the hotlist window menu. */
|
|
|
|
|
|
|
|
static const struct ns_menu hotlist_definition = {
|
|
|
|
"Hotlist", {
|
|
|
|
{ "Hotlist", NO_ACTION, 0 },
|
|
|
|
{ "Hotlist.New", NO_ACTION, 0 },
|
|
|
|
{ "Hotlist.New.Folder", TREE_NEW_FOLDER, 0 },
|
|
|
|
{ "Hotlist.New.Link", TREE_NEW_LINK, 0 },
|
|
|
|
{ "_Hotlist.Export", HOTLIST_EXPORT, &dialog_saveas },
|
|
|
|
{ "Hotlist.Expand", TREE_EXPAND_ALL, 0 },
|
|
|
|
{ "Hotlist.Expand.All", TREE_EXPAND_ALL, 0 },
|
|
|
|
{ "Hotlist.Expand.Folders", TREE_EXPAND_FOLDERS, 0 },
|
|
|
|
{ "Hotlist.Expand.Links", TREE_EXPAND_LINKS, 0 },
|
|
|
|
{ "Hotlist.Collapse", TREE_COLLAPSE_ALL, 0 },
|
|
|
|
{ "Hotlist.Collapse.All", TREE_COLLAPSE_ALL, 0 },
|
|
|
|
{ "Hotlist.Collapse.Folders", TREE_COLLAPSE_FOLDERS, 0 },
|
|
|
|
{ "Hotlist.Collapse.Links", TREE_COLLAPSE_LINKS, 0 },
|
|
|
|
{ "Hotlist.Toolbars", NO_ACTION, 0 },
|
|
|
|
{ "_Hotlist.Toolbars.ToolButtons", TOOLBAR_BUTTONS, 0 },
|
|
|
|
{ "Hotlist.Toolbars.EditToolbar", TOOLBAR_EDIT, 0 },
|
|
|
|
{ "Selection", TREE_SELECTION, 0 },
|
|
|
|
{ "Selection.Edit", TREE_SELECTION_EDIT, 0 },
|
|
|
|
{ "Selection.Launch", TREE_SELECTION_LAUNCH, 0 },
|
|
|
|
{ "Selection.Delete", TREE_SELECTION_DELETE, 0 },
|
|
|
|
{ "SelectAll", TREE_SELECT_ALL, 0 },
|
|
|
|
{ "Clear", TREE_CLEAR_SELECTION, 0 },
|
|
|
|
{NULL, 0, 0}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
hotlist_window.menu = ro_gui_menu_define_menu(&hotlist_definition);
|
|
|
|
|
2011-02-21 02:16:33 +03:00
|
|
|
ro_gui_wimp_event_register_menu(hotlist_window.window,
|
|
|
|
hotlist_window.menu, false, false);
|
|
|
|
ro_gui_wimp_event_register_menu_prepare(hotlist_window.window,
|
|
|
|
ro_gui_hotlist_menu_prepare);
|
|
|
|
ro_gui_wimp_event_register_menu_selection(hotlist_window.window,
|
|
|
|
ro_gui_hotlist_menu_select);
|
|
|
|
ro_gui_wimp_event_register_menu_warning(hotlist_window.window,
|
|
|
|
ro_gui_hotlist_menu_warning);
|
2004-07-09 02:05:35 +04:00
|
|
|
}
|
|
|
|
|
2013-09-08 22:04:45 +04:00
|
|
|
/**
|
|
|
|
* Destroy the hotlist window.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_gui_hotlist_destroy(void)
|
|
|
|
{
|
|
|
|
if (hotlist_window.tv == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
tree_hotlist_path = nsoption_charp(hotlist_save);
|
|
|
|
ro_treeview_destroy(hotlist_window.tv);
|
|
|
|
}
|
|
|
|
|
2004-06-30 21:44:11 +04:00
|
|
|
|
2004-12-09 13:30:44 +03:00
|
|
|
/**
|
2010-10-05 23:14:46 +04:00
|
|
|
* Open the hotlist window.
|
2004-12-09 13:30:44 +03:00
|
|
|
*
|
|
|
|
*/
|
2010-10-05 23:14:46 +04:00
|
|
|
|
|
|
|
void ro_gui_hotlist_open(void)
|
2008-07-27 02:29:15 +04:00
|
|
|
{
|
2014-01-03 02:25:23 +04:00
|
|
|
if (nsoption_bool(external_hotlists) &&
|
2014-05-26 14:50:11 +04:00
|
|
|
nsoption_charp(external_hotlist_app) != NULL &&
|
|
|
|
*nsoption_charp(external_hotlist_app) != '\0') {
|
|
|
|
char command[2048];
|
|
|
|
os_error *error;
|
|
|
|
|
2011-11-20 01:59:46 +04:00
|
|
|
snprintf(command, sizeof(command), "Filer_Run %s",
|
2012-03-22 13:34:34 +04:00
|
|
|
nsoption_charp(external_hotlist_app));
|
2011-11-20 01:59:46 +04:00
|
|
|
error = xos_cli(command);
|
|
|
|
|
|
|
|
if (error == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
LOG(("xos_cli: 0x%x: %s", error->errnum, error->errmess));
|
|
|
|
warn_user("Failed to launch external hotlist: %s",
|
|
|
|
error->errmess);
|
|
|
|
}
|
|
|
|
|
2011-02-21 02:16:33 +03:00
|
|
|
ro_gui_hotlist_toolbar_update_buttons();
|
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
if (!ro_gui_dialog_open_top(hotlist_window.window,
|
|
|
|
hotlist_window.toolbar, 600, 800)) {
|
|
|
|
ro_treeview_set_origin(hotlist_window.tv, 0,
|
2011-02-21 02:16:33 +03:00
|
|
|
-(ro_toolbar_height(hotlist_window.toolbar)));
|
2010-10-05 23:14:46 +04:00
|
|
|
}
|
2004-07-29 15:40:48 +04:00
|
|
|
}
|
|
|
|
|
2010-10-25 00:00:45 +04:00
|
|
|
/**
|
2011-02-21 02:16:33 +03:00
|
|
|
* Handle toolbar button clicks.
|
2010-10-25 00:00:45 +04:00
|
|
|
*
|
2011-02-21 02:16:33 +03:00
|
|
|
* \param action The action to handle
|
2010-10-25 00:00:45 +04:00
|
|
|
*/
|
|
|
|
|
2011-02-21 02:16:33 +03:00
|
|
|
void ro_gui_hotlist_toolbar_click(button_bar_action action)
|
2010-10-25 00:00:45 +04:00
|
|
|
{
|
2011-02-21 02:16:33 +03:00
|
|
|
switch (action) {
|
|
|
|
case TOOLBAR_BUTTON_DELETE:
|
2013-09-03 01:41:04 +04:00
|
|
|
hotlist_keypress(KEY_DELETE_LEFT);
|
2013-12-30 20:20:37 +04:00
|
|
|
ro_toolbar_update_all_hotlists();
|
2011-02-21 02:16:33 +03:00
|
|
|
break;
|
2010-10-25 03:17:21 +04:00
|
|
|
|
2011-02-21 02:16:33 +03:00
|
|
|
case TOOLBAR_BUTTON_EXPAND:
|
2013-09-03 15:36:55 +04:00
|
|
|
hotlist_expand(false);
|
2011-02-21 02:16:33 +03:00
|
|
|
break;
|
2010-10-25 00:00:45 +04:00
|
|
|
|
2011-02-21 02:16:33 +03:00
|
|
|
case TOOLBAR_BUTTON_COLLAPSE:
|
2013-09-03 15:36:55 +04:00
|
|
|
hotlist_contract(false);
|
2010-10-25 00:00:45 +04:00
|
|
|
break;
|
2011-02-21 02:16:33 +03:00
|
|
|
|
|
|
|
case TOOLBAR_BUTTON_OPEN:
|
2013-09-03 15:36:55 +04:00
|
|
|
hotlist_expand(true);
|
2010-10-25 00:00:45 +04:00
|
|
|
break;
|
2011-02-21 02:16:33 +03:00
|
|
|
|
|
|
|
case TOOLBAR_BUTTON_CLOSE:
|
2013-09-03 15:36:55 +04:00
|
|
|
hotlist_contract(true);
|
2010-10-25 00:00:45 +04:00
|
|
|
break;
|
2011-02-21 02:16:33 +03:00
|
|
|
|
|
|
|
case TOOLBAR_BUTTON_LAUNCH:
|
2013-09-03 01:41:04 +04:00
|
|
|
hotlist_keypress(KEY_CR);
|
2010-10-25 00:00:45 +04:00
|
|
|
break;
|
2011-02-21 02:16:33 +03:00
|
|
|
|
|
|
|
case TOOLBAR_BUTTON_CREATE:
|
2013-09-03 01:41:04 +04:00
|
|
|
hotlist_add_folder(NULL, false, 0);
|
2011-02-21 02:16:33 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2010-10-25 00:00:45 +04:00
|
|
|
break;
|
|
|
|
}
|
2011-02-21 02:16:33 +03:00
|
|
|
}
|
2010-10-25 00:00:45 +04:00
|
|
|
|
2011-02-21 02:16:33 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the button state in the hotlist toolbar.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_gui_hotlist_toolbar_update_buttons(void)
|
|
|
|
{
|
|
|
|
ro_toolbar_set_button_shaded_state(hotlist_window.toolbar,
|
|
|
|
TOOLBAR_BUTTON_DELETE,
|
2013-09-02 19:19:16 +04:00
|
|
|
!hotlist_has_selection());
|
2011-02-21 02:16:33 +03:00
|
|
|
|
|
|
|
ro_toolbar_set_button_shaded_state(hotlist_window.toolbar,
|
|
|
|
TOOLBAR_BUTTON_LAUNCH,
|
2013-09-02 19:19:16 +04:00
|
|
|
!hotlist_has_selection());
|
2011-02-21 02:16:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Save a new button arrangement in the hotlist toolbar.
|
|
|
|
*
|
|
|
|
* \param *config The new button configuration string.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_gui_hotlist_toolbar_save_buttons(char *config)
|
|
|
|
{
|
2012-03-22 13:34:34 +04:00
|
|
|
nsoption_set_charp(toolbar_hotlist, config);
|
2011-02-21 02:16:33 +03:00
|
|
|
ro_gui_save_options();
|
2010-10-25 00:00:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-29 15:40:48 +04:00
|
|
|
/**
|
2010-10-05 23:14:46 +04:00
|
|
|
* Prepare the hotlist menu for opening
|
2004-07-29 15:40:48 +04:00
|
|
|
*
|
2010-10-05 23:14:46 +04:00
|
|
|
* \param window The window owning the menu.
|
|
|
|
* \param *menu The menu about to be opened.
|
2011-02-21 02:16:33 +03:00
|
|
|
* \param *pointer Pointer to the relevant wimp event block, or
|
|
|
|
* NULL for an Adjust click.
|
|
|
|
* \return true if the event was handled; else false.
|
2004-07-29 15:40:48 +04:00
|
|
|
*/
|
2010-10-05 23:14:46 +04:00
|
|
|
|
2011-02-21 02:16:33 +03:00
|
|
|
bool ro_gui_hotlist_menu_prepare(wimp_w w, wimp_i i, wimp_menu *menu,
|
|
|
|
wimp_pointer *pointer)
|
2008-07-27 02:29:15 +04:00
|
|
|
{
|
2010-10-05 23:14:46 +04:00
|
|
|
bool selection;
|
|
|
|
|
2011-02-21 02:16:33 +03:00
|
|
|
if (menu != hotlist_window.menu)
|
|
|
|
return false;
|
2010-10-25 03:17:21 +04:00
|
|
|
|
2013-09-02 19:19:16 +04:00
|
|
|
selection = hotlist_has_selection();
|
2010-10-05 23:14:46 +04:00
|
|
|
|
2011-02-21 02:16:33 +03:00
|
|
|
ro_gui_menu_set_entry_shaded(hotlist_window.menu,
|
|
|
|
TREE_SELECTION, !selection);
|
|
|
|
ro_gui_menu_set_entry_shaded(hotlist_window.menu,
|
|
|
|
TREE_CLEAR_SELECTION, !selection);
|
2010-10-05 23:14:46 +04:00
|
|
|
|
2011-02-21 02:16:33 +03:00
|
|
|
ro_gui_save_prepare(GUI_SAVE_HOTLIST_EXPORT_HTML,
|
|
|
|
NULL, NULL, NULL, NULL);
|
2010-10-25 03:17:21 +04:00
|
|
|
|
|
|
|
ro_gui_menu_set_entry_shaded(menu, TOOLBAR_BUTTONS,
|
2011-02-21 02:16:33 +03:00
|
|
|
ro_toolbar_menu_option_shade(hotlist_window.toolbar));
|
2010-10-25 03:17:21 +04:00
|
|
|
ro_gui_menu_set_entry_ticked(menu, TOOLBAR_BUTTONS,
|
2011-02-21 02:16:33 +03:00
|
|
|
ro_toolbar_menu_buttons_tick(hotlist_window.toolbar));
|
2010-10-05 23:14:46 +04:00
|
|
|
|
2010-10-25 03:17:21 +04:00
|
|
|
ro_gui_menu_set_entry_shaded(menu, TOOLBAR_EDIT,
|
2011-02-21 02:16:33 +03:00
|
|
|
ro_toolbar_menu_edit_shade(hotlist_window.toolbar));
|
2010-10-25 03:17:21 +04:00
|
|
|
ro_gui_menu_set_entry_ticked(menu, TOOLBAR_EDIT,
|
2011-02-21 02:16:33 +03:00
|
|
|
ro_toolbar_menu_edit_tick(hotlist_window.toolbar));
|
|
|
|
|
|
|
|
return true;
|
2004-12-09 13:30:44 +03:00
|
|
|
}
|
2004-07-29 15:40:48 +04:00
|
|
|
|
2010-10-25 03:17:21 +04:00
|
|
|
|
2004-12-09 13:30:44 +03:00
|
|
|
/**
|
2010-10-05 23:14:46 +04:00
|
|
|
* Handle submenu warnings for the hotlist menu
|
2004-12-09 13:30:44 +03:00
|
|
|
*
|
2011-02-21 02:16:33 +03:00
|
|
|
* \param w The window owning the menu.
|
|
|
|
* \param i The icon owning the menu.
|
2010-10-05 23:14:46 +04:00
|
|
|
* \param *menu The menu to which the warning applies.
|
|
|
|
* \param *selection The wimp menu selection data.
|
|
|
|
* \param action The selected menu action.
|
2004-12-09 13:30:44 +03:00
|
|
|
*/
|
2010-10-05 23:14:46 +04:00
|
|
|
|
2011-02-21 02:16:33 +03:00
|
|
|
void ro_gui_hotlist_menu_warning(wimp_w w, wimp_i i, wimp_menu *menu,
|
2010-10-05 23:14:46 +04:00
|
|
|
wimp_selection *selection, menu_action action)
|
2008-07-27 02:29:15 +04:00
|
|
|
{
|
2010-10-05 23:14:46 +04:00
|
|
|
/* Do nothing */
|
2004-07-29 15:40:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-10-05 23:14:46 +04:00
|
|
|
* Handle selections from the hotlist menu
|
2004-07-29 15:40:48 +04:00
|
|
|
*
|
2011-02-21 02:16:33 +03:00
|
|
|
* \param w The window owning the menu.
|
|
|
|
* \param i The icon owning the menu.
|
2010-10-05 23:14:46 +04:00
|
|
|
* \param *menu The menu from which the selection was made.
|
|
|
|
* \param *selection The wimp menu selection data.
|
|
|
|
* \param action The selected menu action.
|
|
|
|
* \return true if action accepted; else false.
|
2004-07-29 15:40:48 +04:00
|
|
|
*/
|
2010-10-05 23:14:46 +04:00
|
|
|
|
2011-02-21 02:16:33 +03:00
|
|
|
bool ro_gui_hotlist_menu_select(wimp_w w, wimp_i i, wimp_menu *menu,
|
2010-10-05 23:14:46 +04:00
|
|
|
wimp_selection *selection, menu_action action)
|
2008-07-27 02:29:15 +04:00
|
|
|
{
|
2010-10-05 23:14:46 +04:00
|
|
|
switch (action) {
|
|
|
|
case HOTLIST_EXPORT:
|
2011-02-21 02:16:33 +03:00
|
|
|
ro_gui_dialog_open_persistent(w, dialog_saveas, true);
|
2010-10-05 23:14:46 +04:00
|
|
|
return true;
|
|
|
|
case TREE_NEW_FOLDER:
|
2013-09-03 01:41:04 +04:00
|
|
|
hotlist_add_folder(NULL, false, 0);
|
2010-10-05 23:14:46 +04:00
|
|
|
return true;
|
|
|
|
case TREE_NEW_LINK:
|
2013-09-03 01:41:04 +04:00
|
|
|
hotlist_add_entry(NULL, NULL, false, 0);
|
2010-10-05 23:14:46 +04:00
|
|
|
return true;
|
|
|
|
case TREE_EXPAND_ALL:
|
2013-09-03 15:36:55 +04:00
|
|
|
hotlist_expand(false);
|
2010-10-05 23:14:46 +04:00
|
|
|
return true;
|
|
|
|
case TREE_EXPAND_FOLDERS:
|
2013-09-03 15:36:55 +04:00
|
|
|
hotlist_expand(true);
|
2010-10-05 23:14:46 +04:00
|
|
|
return true;
|
|
|
|
case TREE_EXPAND_LINKS:
|
2013-09-03 15:36:55 +04:00
|
|
|
hotlist_expand(false);
|
2010-10-05 23:14:46 +04:00
|
|
|
return true;
|
|
|
|
case TREE_COLLAPSE_ALL:
|
2013-09-03 15:36:55 +04:00
|
|
|
hotlist_contract(true);
|
2010-10-05 23:14:46 +04:00
|
|
|
return true;
|
|
|
|
case TREE_COLLAPSE_FOLDERS:
|
2013-09-03 15:36:55 +04:00
|
|
|
hotlist_contract(true);
|
2010-10-05 23:14:46 +04:00
|
|
|
return true;
|
|
|
|
case TREE_COLLAPSE_LINKS:
|
2013-09-03 15:36:55 +04:00
|
|
|
hotlist_contract(false);
|
2010-10-05 23:14:46 +04:00
|
|
|
return true;
|
|
|
|
case TREE_SELECTION_EDIT:
|
2013-09-03 01:41:04 +04:00
|
|
|
hotlist_edit_selection();
|
2010-10-05 23:14:46 +04:00
|
|
|
return true;
|
|
|
|
case TREE_SELECTION_LAUNCH:
|
2013-09-03 01:41:04 +04:00
|
|
|
hotlist_keypress(KEY_CR);
|
2010-10-05 23:14:46 +04:00
|
|
|
return true;
|
|
|
|
case TREE_SELECTION_DELETE:
|
2013-09-03 01:41:04 +04:00
|
|
|
hotlist_keypress(KEY_DELETE_LEFT);
|
2013-12-30 20:20:37 +04:00
|
|
|
ro_toolbar_update_all_hotlists();
|
2010-10-05 23:14:46 +04:00
|
|
|
return true;
|
|
|
|
case TREE_SELECT_ALL:
|
2013-09-03 01:41:04 +04:00
|
|
|
hotlist_keypress(KEY_SELECT_ALL);
|
2010-10-05 23:14:46 +04:00
|
|
|
return true;
|
|
|
|
case TREE_CLEAR_SELECTION:
|
2013-09-03 01:41:04 +04:00
|
|
|
hotlist_keypress(KEY_CLEAR_SELECTION);
|
2010-10-05 23:14:46 +04:00
|
|
|
return true;
|
2010-10-25 01:52:16 +04:00
|
|
|
case TOOLBAR_BUTTONS:
|
2011-02-21 02:16:33 +03:00
|
|
|
ro_toolbar_set_display_buttons(hotlist_window.toolbar,
|
|
|
|
!ro_toolbar_get_display_buttons(
|
|
|
|
hotlist_window.toolbar));
|
2010-10-25 01:52:16 +04:00
|
|
|
return true;
|
|
|
|
case TOOLBAR_EDIT:
|
2011-02-21 02:16:33 +03:00
|
|
|
ro_toolbar_toggle_edit(hotlist_window.toolbar);
|
2010-10-25 01:52:16 +04:00
|
|
|
return true;
|
2010-10-05 23:14:46 +04:00
|
|
|
default:
|
|
|
|
return false;
|
2006-01-08 04:51:33 +03:00
|
|
|
}
|
2004-07-16 03:58:08 +04:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
return false;
|
|
|
|
}
|
2004-07-16 03:58:08 +04:00
|
|
|
|
2004-07-06 02:17:59 +04:00
|
|
|
/**
|
2010-10-05 23:14:46 +04:00
|
|
|
* Check if a particular window handle is the hotlist window
|
2004-07-06 02:17:59 +04:00
|
|
|
*
|
2010-10-05 23:14:46 +04:00
|
|
|
* \param window The window in question
|
|
|
|
* \return true if this window is the hotlist
|
2004-07-06 02:17:59 +04:00
|
|
|
*/
|
2010-10-05 23:14:46 +04:00
|
|
|
bool ro_gui_hotlist_check_window(wimp_w window)
|
2008-07-27 02:29:15 +04:00
|
|
|
{
|
2010-10-05 23:14:46 +04:00
|
|
|
if (hotlist_window.window == window)
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
2009-03-28 22:59:46 +03:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
/**
|
|
|
|
* Check if a particular menu handle is the hotlist menu
|
|
|
|
*
|
|
|
|
* \param *menu The menu in question.
|
|
|
|
* \return true if this menu is the hotlist menu
|
|
|
|
*/
|
2009-03-28 22:59:46 +03:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
bool ro_gui_hotlist_check_menu(wimp_menu *menu)
|
|
|
|
{
|
|
|
|
if (hotlist_window.menu == menu)
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
2009-03-28 22:59:46 +03:00
|
|
|
|
2011-10-09 17:32:43 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a URL to the hotlist. This will be passed on to the core hotlist, then
|
|
|
|
* Message_HotlistAddURL will broadcast to any bookmark applications via the
|
|
|
|
* Hotlist Protocol.
|
|
|
|
*
|
2013-11-22 22:19:20 +04:00
|
|
|
* \param *url The URL to be added.
|
2011-10-09 17:32:43 +04:00
|
|
|
*/
|
|
|
|
|
2013-11-22 22:19:20 +04:00
|
|
|
void ro_gui_hotlist_add_page(nsurl *url)
|
2011-10-09 17:32:43 +04:00
|
|
|
{
|
|
|
|
const struct url_data *data;
|
|
|
|
wimp_message message;
|
|
|
|
struct ro_hotlist_message_hotlist_addurl *add_url =
|
|
|
|
(struct ro_hotlist_message_hotlist_addurl *) &message;
|
|
|
|
|
|
|
|
if (url == NULL)
|
|
|
|
return;
|
|
|
|
|
2011-10-14 00:40:52 +04:00
|
|
|
/* If we're not using external hotlists, add the page to NetSurf's
|
|
|
|
* own hotlist and return...
|
|
|
|
*/
|
2011-10-09 17:32:43 +04:00
|
|
|
|
2012-03-22 13:34:34 +04:00
|
|
|
if (!nsoption_bool(external_hotlists)) {
|
2013-11-22 22:19:20 +04:00
|
|
|
hotlist_add_url(url);
|
2011-10-14 00:40:52 +04:00
|
|
|
return;
|
|
|
|
}
|
2011-10-09 17:32:43 +04:00
|
|
|
|
2011-10-14 00:40:52 +04:00
|
|
|
/* ...otherwise try broadcasting the details to any other
|
|
|
|
* interested parties. If no-one answers, we'll fall back to
|
|
|
|
* NetSurf's hotlist anyway when the message bounces.
|
2011-10-09 17:32:43 +04:00
|
|
|
*/
|
|
|
|
|
2011-10-14 00:40:52 +04:00
|
|
|
ro_gui_hotlist_add_cleanup();
|
2011-10-09 17:32:43 +04:00
|
|
|
|
2013-11-22 22:19:20 +04:00
|
|
|
data = urldb_get_url_data(url);
|
2011-10-09 17:32:43 +04:00
|
|
|
if (data == NULL)
|
|
|
|
return;
|
|
|
|
|
2013-11-22 22:19:20 +04:00
|
|
|
hotlist_url = osmodule_alloc(nsurl_length(url) + 1);
|
2011-10-09 17:32:43 +04:00
|
|
|
hotlist_title = osmodule_alloc(strlen(data->title) + 1);
|
|
|
|
|
|
|
|
if (hotlist_url == NULL || hotlist_title == NULL) {
|
|
|
|
ro_gui_hotlist_add_cleanup();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-22 22:19:20 +04:00
|
|
|
strcpy(hotlist_url, nsurl_access(url));
|
2011-10-09 17:32:43 +04:00
|
|
|
strcpy(hotlist_title, data->title);
|
|
|
|
|
|
|
|
add_url->size = 60;
|
|
|
|
add_url->your_ref = 0;
|
|
|
|
add_url->action = message_HOTLIST_ADD_URL;
|
|
|
|
add_url->url = hotlist_url;
|
|
|
|
add_url->title = hotlist_title;
|
|
|
|
strcpy(add_url->appname, "NetSurf");
|
|
|
|
|
|
|
|
if (!ro_message_send_message(wimp_USER_MESSAGE_RECORDED, &message, 0,
|
|
|
|
ro_gui_hotlist_addurl_bounce))
|
|
|
|
ro_gui_hotlist_add_cleanup();
|
2011-10-14 00:40:52 +04:00
|
|
|
|
|
|
|
/* Listen for the next Null poll, as an indication that the
|
|
|
|
* message didn't bounce.
|
|
|
|
*/
|
|
|
|
|
2014-03-08 18:13:27 +04:00
|
|
|
riscos_schedule(0, ro_gui_hotlist_scheduled_callback, NULL);
|
2011-10-09 17:32:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle bounced Message_HotlistAddURL, so that RMA storage can be freed.
|
|
|
|
*
|
|
|
|
* \param *message The bounced message content.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void ro_gui_hotlist_addurl_bounce(wimp_message *message)
|
|
|
|
{
|
2013-09-03 01:41:04 +04:00
|
|
|
if (hotlist_url != NULL) {
|
|
|
|
nsurl *nsurl;
|
|
|
|
|
|
|
|
if (nsurl_create(hotlist_url, &nsurl) != NSERROR_OK)
|
|
|
|
return;
|
|
|
|
|
2013-09-03 15:36:55 +04:00
|
|
|
hotlist_add_url(nsurl);
|
2013-09-03 01:41:04 +04:00
|
|
|
nsurl_unref(nsurl);
|
|
|
|
}
|
2011-10-14 00:40:52 +04:00
|
|
|
|
|
|
|
ro_gui_hotlist_add_cleanup();
|
|
|
|
|
|
|
|
/* There's no longer any need to listen for the next Null poll. */
|
|
|
|
|
2014-03-08 18:13:27 +04:00
|
|
|
riscos_schedule(-1, ro_gui_hotlist_scheduled_callback, NULL);
|
2011-10-14 00:40:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback to schedule for the next available Null poll, by which point
|
|
|
|
* a hotlist client will have claimed the Message_HotlistAddURL and any
|
|
|
|
* details in RMA can safely be discarded.
|
|
|
|
*
|
|
|
|
* \param *p Unused data pointer.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void ro_gui_hotlist_scheduled_callback(void *p)
|
|
|
|
{
|
2011-10-09 17:32:43 +04:00
|
|
|
ro_gui_hotlist_add_cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clean up RMA storage used by the Message_HotlistAddURL protocol.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_gui_hotlist_add_cleanup(void)
|
|
|
|
{
|
|
|
|
if (hotlist_url != NULL) {
|
|
|
|
osmodule_free(hotlist_url);
|
|
|
|
hotlist_url = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hotlist_title != NULL) {
|
|
|
|
osmodule_free(hotlist_title);
|
|
|
|
hotlist_title = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-30 16:36:24 +04:00
|
|
|
/**
|
|
|
|
* Remove a URL from the hotlist. This will be passed on to the core hotlist,
|
|
|
|
* unless we're configured to use external hotlists in which case we ignore it.
|
|
|
|
*
|
|
|
|
* \param *url The URL to be removed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ro_gui_hotlist_remove_page(nsurl *url)
|
|
|
|
{
|
2013-12-31 20:45:32 +04:00
|
|
|
if (url == NULL || nsoption_bool(external_hotlists) ||
|
|
|
|
!hotlist_has_url(url))
|
2013-12-30 16:36:24 +04:00
|
|
|
return;
|
|
|
|
|
2013-12-31 20:45:32 +04:00
|
|
|
/* Clean up any existing delete attempts before continuing. */
|
|
|
|
|
|
|
|
if (hotlist_query != QUERY_INVALID) {
|
|
|
|
query_close(hotlist_query);
|
|
|
|
hotlist_query = QUERY_INVALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hotlist_delete_url != NULL) {
|
|
|
|
nsurl_unref(hotlist_delete_url);
|
|
|
|
hotlist_delete_url = NULL;
|
|
|
|
}
|
|
|
|
|
2013-12-31 20:57:47 +04:00
|
|
|
/* Check with the user before removing the URL, unless they don't
|
|
|
|
* want us to be careful in which case just do it.
|
|
|
|
*/
|
2013-12-31 20:45:32 +04:00
|
|
|
|
2013-12-31 20:57:47 +04:00
|
|
|
if (nsoption_bool(confirm_hotlist_remove)) {
|
|
|
|
hotlist_query = query_user("RemoveHotlist", NULL,
|
|
|
|
&remove_funcs, NULL,
|
|
|
|
messages_get("Remove"),
|
|
|
|
messages_get("DontRemove"));
|
2013-12-31 20:45:32 +04:00
|
|
|
|
2013-12-31 20:57:47 +04:00
|
|
|
hotlist_delete_url = nsurl_ref(url);
|
|
|
|
} else {
|
|
|
|
hotlist_remove_url(url);
|
|
|
|
ro_toolbar_update_all_hotlists();
|
|
|
|
}
|
2013-12-31 20:45:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback confirming a URL delete query.
|
|
|
|
*
|
|
|
|
* \param id The ID of the query calling us.
|
|
|
|
* \param res The user's response to the query.
|
|
|
|
* \param *p Callback data (always NULL).
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void ro_gui_hotlist_remove_confirmed(query_id id,
|
|
|
|
enum query_response res, void *p)
|
|
|
|
{
|
|
|
|
hotlist_remove_url(hotlist_delete_url);
|
|
|
|
ro_toolbar_update_all_hotlists();
|
|
|
|
|
|
|
|
nsurl_unref(hotlist_delete_url);
|
|
|
|
hotlist_delete_url = NULL;
|
|
|
|
hotlist_query = QUERY_INVALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback cancelling a URL delete query.
|
|
|
|
*
|
|
|
|
* \param id The ID of the query calling us.
|
|
|
|
* \param res The user's response to the query.
|
|
|
|
* \param *p Callback data (always NULL).
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void ro_gui_hotlist_remove_cancelled(query_id id,
|
|
|
|
enum query_response res, void *p)
|
|
|
|
{
|
|
|
|
nsurl_unref(hotlist_delete_url);
|
|
|
|
hotlist_delete_url = NULL;
|
|
|
|
hotlist_query = QUERY_INVALID;
|
2013-12-30 16:36:24 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-30 19:41:38 +04:00
|
|
|
/**
|
|
|
|
* Report whether the hotlist contains a given URL. This will be passed on to
|
|
|
|
* the core hotlist, unless we're configured to use an external hotlist in which
|
|
|
|
* case we always report false.
|
|
|
|
*
|
|
|
|
* \param *url The URL to be tested.
|
|
|
|
* \return true if the hotlist contains the URL; else false.
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool ro_gui_hotlist_has_page(nsurl *url)
|
|
|
|
{
|
|
|
|
if (url == NULL || nsoption_bool(external_hotlists))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return hotlist_has_url(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
#if 0
|
|
|
|
/**
|
|
|
|
* Handle URL dropped on hotlist
|
|
|
|
*
|
|
|
|
* \param message the wimp message we're acting on
|
|
|
|
* \param url the URL to add
|
|
|
|
*/
|
|
|
|
void ro_gui_hotlist_url_drop(wimp_message *message, const char *url)
|
|
|
|
{
|
|
|
|
int x, y;
|
2013-09-03 01:41:04 +04:00
|
|
|
nsurl *nsurl;
|
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
if (hotlist_window.window != message->data.data_xfer.w)
|
|
|
|
return;
|
2005-12-31 07:36:24 +03:00
|
|
|
|
2013-09-03 01:41:04 +04:00
|
|
|
if (url == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (nsurl_create(url, &nsurl) != NSERROR_OK)
|
|
|
|
return;
|
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
ro_gui_tree_get_tree_coordinates(hotlist_window.tree,
|
|
|
|
message->data.data_xfer.pos.x,
|
|
|
|
message->data.data_xfer.pos.y,
|
|
|
|
&x, &y);
|
2013-09-03 01:41:04 +04:00
|
|
|
|
|
|
|
hotlist_add_entry(nsurl, NULL, true, y);
|
|
|
|
nsurl_unref(nsurl);
|
2004-06-30 21:44:11 +04:00
|
|
|
}
|
2010-10-05 23:14:46 +04:00
|
|
|
#endif
|