NetSurf
|
generic data viewer implementation. More...
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <stdio.h>
#include <unistd.h>
#include <gtk/gtk.h>
#include "utils/log.h"
#include "utils/nsoption.h"
#include "utils/utf8.h"
#include "utils/messages.h"
#include "utils/utils.h"
#include "utils/file.h"
#include "utils/filepath.h"
#include "utils/nsurl.h"
#include "netsurf/browser_window.h"
#include "gtk/warn.h"
#include "gtk/about.h"
#include "gtk/fetch.h"
#include "gtk/compat.h"
#include "gtk/resources.h"
#include "gtk/viewdata.h"
Go to the source code of this file.
Data Structures | |
struct | nsgtk_viewdata_ctx |
struct | menu_events |
Macros | |
#define | _WITH_GETLINE /* necessary for FreeBSD */ |
#define | MENUEVENT(x) { #x, G_CALLBACK(nsgtk_on_##x##_activate) } |
#define | MENUPROTO(x) |
Functions | |
MENUPROTO (viewdata_save_as) | |
MENUPROTO (viewdata_print) | |
MENUPROTO (viewdata_close) | |
MENUPROTO (viewdata_select_all) | |
MENUPROTO (viewdata_cut) | |
MENUPROTO (viewdata_copy) | |
MENUPROTO (viewdata_paste) | |
MENUPROTO (viewdata_delete) | |
MENUPROTO (viewdata_zoom_in) | |
MENUPROTO (viewdata_zoom_out) | |
MENUPROTO (viewdata_zoom_normal) | |
MENUPROTO (viewdata_about) | |
static void | nsgtk_attach_viewdata_menu_handlers (GtkBuilder *xml, gpointer g) |
static gboolean | nsgtk_viewdata_destroy_event (GtkBuilder *window, gpointer g) |
static gboolean | nsgtk_viewdata_delete_event (GtkWindow *window, gpointer g) |
static void | nsgtk_viewdata_file_save (GtkWindow *parent, const char *filename, const char *data, size_t data_size) |
gboolean | nsgtk_on_viewdata_save_as_activate (GtkMenuItem *widget, gpointer g) |
gboolean | nsgtk_on_viewdata_print_activate (GtkMenuItem *widget, gpointer g) |
gboolean | nsgtk_on_viewdata_close_activate (GtkMenuItem *widget, gpointer g) |
gboolean | nsgtk_on_viewdata_select_all_activate (GtkMenuItem *widget, gpointer g) |
gboolean | nsgtk_on_viewdata_cut_activate (GtkMenuItem *widget, gpointer g) |
gboolean | nsgtk_on_viewdata_copy_activate (GtkMenuItem *widget, gpointer g) |
gboolean | nsgtk_on_viewdata_paste_activate (GtkMenuItem *widget, gpointer g) |
gboolean | nsgtk_on_viewdata_delete_activate (GtkMenuItem *widget, gpointer g) |
static void | nsgtk_viewdata_update_zoomlevel (gpointer g) |
gboolean | nsgtk_on_viewdata_zoom_in_activate (GtkMenuItem *widget, gpointer g) |
gboolean | nsgtk_on_viewdata_zoom_out_activate (GtkMenuItem *widget, gpointer g) |
gboolean | nsgtk_on_viewdata_zoom_normal_activate (GtkMenuItem *widget, gpointer g) |
gboolean | nsgtk_on_viewdata_about_activate (GtkMenuItem *widget, gpointer g) |
static nserror | window_init (const char *title, const char *filename, char *ndata, size_t ndata_len) |
View the data in a gtk text window. More... | |
static nserror | window_init_fname (const char *title, const char *leafname, const char *filename) |
open a window to dispaly an existing file. More... | |
static nserror | tab_init_fname (const char *title, const char *leafname, const char *fname) |
open a new tab from an existing file. More... | |
static nserror | tab_init (const char *title, const char *leafname, char *ndata, size_t ndata_len) |
create a new tab from data. More... | |
static char ** | xdg_data_strvec (void) |
Build string vector of search path. More... | |
static char * | xdg_get_default_app (const char *path, const char *mimetype) |
Search application defaults file for matching mime type. More... | |
static char * | xdg_get_exec_cmd (const char *path, const char *desktop) |
Search desktop file for an Exec line. More... | |
static char * | exec_arg (const char *arg, int len, const char *fname) |
static char ** | build_exec_argv (const char *fname, const char *exec_cmd) |
Build vector for executing app. More... | |
static nserror | editor_init_fname (const char *title, const char *leafname, const char *fname) |
open an editor from an existing file. More... | |
static nserror | editor_init (const char *title, const char *leafname, char *ndata, size_t ndata_len) |
open an editor with data. More... | |
nserror | nsgtk_viewdata (const char *title, const char *filename, char *ndata, size_t ndata_len) |
Display text to a user. More... | |
nserror | nsgtk_viewfile (const char *title, const char *leafname, const char *filename) |
Display file to a user. More... | |
Variables | |
static struct nsgtk_viewdata_ctx * | nsgtk_viewdata_list = NULL |
static char | viewdata_zoomlevel = 10 |
static struct menu_events | viewdata_menu_events [] |
generic data viewer implementation.
This viewer can be used for utf-8 encoded chunk of data. Thie data might be page source or the debugging of dom or box trees. It will show the data in a tab, window or editor as per user configuration.
Definition in file viewdata.c.
#define _WITH_GETLINE /* necessary for FreeBSD */ |
Definition at line 31 of file viewdata.c.
#define MENUEVENT | ( | x | ) | { #x, G_CALLBACK(nsgtk_on_##x##_activate) } |
Definition at line 74 of file viewdata.c.
#define MENUPROTO | ( | x | ) |
Definition at line 75 of file viewdata.c.
|
static |
Build vector for executing app.
Definition at line 777 of file viewdata.c.
References exec_arg(), and NSLOG.
Referenced by editor_init_fname().
|
static |
open an editor with data.
Definition at line 892 of file viewdata.c.
References editor_init_fname(), messages_get(), NSERROR_OK, NSERROR_SAVE_FAILED, and nsgtk_warning().
Referenced by nsgtk_viewdata().
|
static |
open an editor from an existing file.
Definition at line 826 of file viewdata.c.
References build_exec_argv(), filepath_free_strvec(), NSERROR_NOT_FOUND, NSERROR_OK, xdg_data_strvec(), xdg_get_default_app(), and xdg_get_exec_cmd().
Referenced by editor_init(), and nsgtk_viewfile().
|
static |
Definition at line 754 of file viewdata.c.
Referenced by build_exec_argv().
MENUPROTO | ( | viewdata_about | ) |
MENUPROTO | ( | viewdata_close | ) |
MENUPROTO | ( | viewdata_copy | ) |
MENUPROTO | ( | viewdata_cut | ) |
MENUPROTO | ( | viewdata_delete | ) |
MENUPROTO | ( | viewdata_paste | ) |
MENUPROTO | ( | viewdata_print | ) |
MENUPROTO | ( | viewdata_save_as | ) |
MENUPROTO | ( | viewdata_select_all | ) |
MENUPROTO | ( | viewdata_zoom_in | ) |
MENUPROTO | ( | viewdata_zoom_normal | ) |
MENUPROTO | ( | viewdata_zoom_out | ) |
|
static |
Definition at line 107 of file viewdata.c.
References viewdata_menu_events.
Referenced by window_init().
gboolean nsgtk_on_viewdata_about_activate | ( | GtkMenuItem * | widget, |
gpointer | g | ||
) |
Definition at line 338 of file viewdata.c.
References nsgtk_about_dialog_init(), and nsgtk_viewdata_ctx::window.
gboolean nsgtk_on_viewdata_close_activate | ( | GtkMenuItem * | widget, |
gpointer | g | ||
) |
Definition at line 223 of file viewdata.c.
References nsgtk_viewdata_ctx::window.
gboolean nsgtk_on_viewdata_copy_activate | ( | GtkMenuItem * | widget, |
gpointer | g | ||
) |
Definition at line 252 of file viewdata.c.
References nsgtk_viewdata_ctx::gv.
gboolean nsgtk_on_viewdata_cut_activate | ( | GtkMenuItem * | widget, |
gpointer | g | ||
) |
Definition at line 247 of file viewdata.c.
gboolean nsgtk_on_viewdata_delete_activate | ( | GtkMenuItem * | widget, |
gpointer | g | ||
) |
Definition at line 268 of file viewdata.c.
gboolean nsgtk_on_viewdata_paste_activate | ( | GtkMenuItem * | widget, |
gpointer | g | ||
) |
Definition at line 263 of file viewdata.c.
gboolean nsgtk_on_viewdata_print_activate | ( | GtkMenuItem * | widget, |
gpointer | g | ||
) |
Definition at line 216 of file viewdata.c.
gboolean nsgtk_on_viewdata_save_as_activate | ( | GtkMenuItem * | widget, |
gpointer | g | ||
) |
Definition at line 184 of file viewdata.c.
References nsgtk_viewdata_ctx::data, nsgtk_viewdata_ctx::data_len, nsgtk_viewdata_ctx::filename, messages_get(), NSGTK_STOCK_CANCEL, NSGTK_STOCK_SAVE, nsgtk_viewdata_file_save(), and nsgtk_viewdata_ctx::window.
gboolean nsgtk_on_viewdata_select_all_activate | ( | GtkMenuItem * | widget, |
gpointer | g | ||
) |
Definition at line 234 of file viewdata.c.
References nsgtk_viewdata_ctx::gv.
gboolean nsgtk_on_viewdata_zoom_in_activate | ( | GtkMenuItem * | widget, |
gpointer | g | ||
) |
Definition at line 311 of file viewdata.c.
References nsgtk_viewdata_update_zoomlevel(), and viewdata_zoomlevel.
gboolean nsgtk_on_viewdata_zoom_normal_activate | ( | GtkMenuItem * | widget, |
gpointer | g | ||
) |
Definition at line 330 of file viewdata.c.
References nsgtk_viewdata_update_zoomlevel(), and viewdata_zoomlevel.
gboolean nsgtk_on_viewdata_zoom_out_activate | ( | GtkMenuItem * | widget, |
gpointer | g | ||
) |
Definition at line 319 of file viewdata.c.
References nsgtk_viewdata_update_zoomlevel(), and viewdata_zoomlevel.
nserror nsgtk_viewdata | ( | const char * | title, |
const char * | filename, | ||
char * | data, | ||
size_t | data_size | ||
) |
Display text to a user.
The data is utf-8 encoded text and will be presented in a window, a tab or an editor as per the user configuration.
title | The title of the data being displayed. |
filename | The suggested filename to be used. |
data | The data to be shown. This data will be freed once the display is complete, the caller no longer owns the allocation. |
data_size | The size of the data in data. |
Definition at line 931 of file viewdata.c.
References editor_init(), nsgtk_viewdata_ctx::filename, NSERROR_BAD_PARAMETER, NSERROR_OK, nsoption_int, tab_init(), and window_init().
Referenced by nsgtk_viewsource().
|
static |
Definition at line 145 of file viewdata.c.
Referenced by window_init().
|
static |
Definition at line 119 of file viewdata.c.
References nsgtk_viewdata_ctx::builder, nsgtk_viewdata_ctx::data, nsgtk_viewdata_ctx::next, nsgtk_viewdata_list, and nsgtk_viewdata_ctx::prev.
Referenced by window_init().
|
static |
Definition at line 152 of file viewdata.c.
References nsgtk_viewdata_ctx::data, nsgtk_viewdata_ctx::filename, messages_get(), nsgtk_dialog_get_content_area(), NSGTK_STOCK_OK, and parent.
Referenced by nsgtk_on_viewdata_save_as_activate().
|
static |
Definition at line 273 of file viewdata.c.
References nsgtk_viewdata_ctx::gv, nsgtk_viewdata_ctx::next, nsgtk_viewdata_list, and viewdata_zoomlevel.
Referenced by nsgtk_on_viewdata_zoom_in_activate(), nsgtk_on_viewdata_zoom_normal_activate(), and nsgtk_on_viewdata_zoom_out_activate().
nserror nsgtk_viewfile | ( | const char * | title, |
const char * | leafname, | ||
const char * | filename | ||
) |
Display file to a user.
The file is interpreted as utf-8 encoded text and will be presented in a window, a tab or an editor as per the user configuration.
title | The title of the data being displayed. |
leafname | The suggested leafname to be used. |
filename | The filename of the data to be viewed. |
Definition at line 966 of file viewdata.c.
References editor_init_fname(), nsgtk_viewdata_ctx::filename, NSERROR_BAD_PARAMETER, nsoption_int, tab_init_fname(), and window_init_fname().
Referenced by debugboxtree_button_clicked_cb(), and debugdomtree_button_clicked_cb().
|
static |
create a new tab from data.
Definition at line 527 of file viewdata.c.
References messages_get(), NSERROR_OK, NSERROR_SAVE_FAILED, nsgtk_warning(), and tab_init_fname().
Referenced by nsgtk_viewdata().
|
static |
open a new tab from an existing file.
Definition at line 500 of file viewdata.c.
References browser_window_create(), BW_CREATE_HISTORY, BW_CREATE_TAB, netsurf_path_to_nsurl(), NSERROR_OK, and nsurl_unref().
Referenced by nsgtk_viewfile(), and tab_init().
|
static |
View the data in a gtk text window.
Definition at line 351 of file viewdata.c.
References nsgtk_viewdata_ctx::builder, nsgtk_viewdata_ctx::data, nsgtk_viewdata_ctx::data_len, nsgtk_viewdata_ctx::filename, nsgtk_viewdata_ctx::gv, nsgtk_viewdata_ctx::next, NSERROR_INIT_FAILED, NSERROR_NOMEM, NSERROR_OK, nsgtk_attach_viewdata_menu_handlers(), nsgtk_builder_new_from_resname(), nsgtk_viewdata_delete_event(), nsgtk_viewdata_destroy_event(), nsgtk_viewdata_list, nsgtk_widget_modify_font(), NSLOG, nsgtk_viewdata_ctx::prev, and nsgtk_viewdata_ctx::window.
Referenced by nsgtk_viewdata(), and window_init_fname().
|
static |
open a window to dispaly an existing file.
Definition at line 451 of file viewdata.c.
References nsgtk_viewdata_ctx::filename, NSERROR_BAD_SIZE, NSERROR_NOT_FOUND, NSERROR_OK, and window_init().
Referenced by nsgtk_viewfile().
|
static |
Build string vector of search path.
${XDG_DATA_HOME:-$HOME/.local/share}:${XDG_DATA_DIRS:-/usr/local/share:/usr/share}
$XDG_DATA_HOME if empty use $HOME/.local/share
XDG_DATA_DIRS if empty use /usr/local/share/:/usr/share/
Definition at line 575 of file viewdata.c.
References filepath_path_to_strvec(), NSLOG, and SLEN.
Referenced by editor_init_fname().
|
static |
Search application defaults file for matching mime type.
create filename form path and applications/defaults.list
look for [Default Applications] search lines looking like mime/type=Desktop
path | The base path. |
mimetype | The mimetype to search for. |
Definition at line 639 of file viewdata.c.
References line(), NSLOG, path(), and SLEN.
Referenced by editor_init_fname().
|
static |
Search desktop file for an Exec line.
search path is combined with applications/application.desktop to create a filename.
Desktop file format http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html
Definition at line 706 of file viewdata.c.
References line(), NSLOG, path(), and SLEN.
Referenced by editor_init_fname().
|
static |
Definition at line 71 of file viewdata.c.
Referenced by nsgtk_viewdata_destroy_event(), nsgtk_viewdata_update_zoomlevel(), and window_init().
|
static |
Definition at line 91 of file viewdata.c.
Referenced by nsgtk_attach_viewdata_menu_handlers().
|
static |
Definition at line 72 of file viewdata.c.
Referenced by nsgtk_on_viewdata_zoom_in_activate(), nsgtk_on_viewdata_zoom_normal_activate(), nsgtk_on_viewdata_zoom_out_activate(), and nsgtk_viewdata_update_zoomlevel().