74#define MENUEVENT(x) { #x, G_CALLBACK(nsgtk_on_##x##_activate) }
75#define MENUPROTO(x) static gboolean nsgtk_on_##x##_activate( \
76 GtkMenuItem *widget, gpointer g)
111 while (event->widget != NULL)
113 GtkWidget *w = GTK_WIDGET(gtk_builder_get_object(xml, event->widget));
114 g_signal_connect(G_OBJECT(w),
"activate", event->handler, g);
123 if (vdctx->
next != NULL) {
127 if (vdctx->
prev != NULL) {
137 g_object_unref(G_OBJECT(vdctx->
builder));
153 const char *
data,
size_t data_size)
161 fwrite(
data, data_size, 1, f);
167 notif = gtk_dialog_new_with_buttons(
messages_get(
"gtkSaveFailedTitle"),
174 g_signal_connect_swapped(notif,
"response",
175 G_CALLBACK(gtk_widget_destroy), notif);
179 gtk_widget_show_all(notif);
189 fc = gtk_file_chooser_dialog_new(
messages_get(
"gtkSaveFile"),
191 GTK_FILE_CHOOSER_ACTION_SAVE,
198 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(fc), nsg->
filename);
200 gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(fc),
203 if (gtk_dialog_run(GTK_DIALOG(fc)) == GTK_RESPONSE_ACCEPT) {
205 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(fc));
210 gtk_widget_destroy(fc);
227 gtk_widget_destroy(GTK_WIDGET(nsg->
window));
237 GtkTextBuffer *buf = gtk_text_view_get_buffer(nsg->
gv);
238 GtkTextIter start, end;
240 gtk_text_buffer_get_bounds(buf, &start, &end);
242 gtk_text_buffer_select_range(buf, &start, &end);
255 GtkTextBuffer *buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(nsg->
gv));
257 gtk_text_buffer_copy_clipboard(buf,
258 gtk_clipboard_get(GDK_SELECTION_CLIPBOARD));
277 GtkTextTagTable *tab;
283 buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(nsg->
gv));
285 tab = gtk_text_buffer_get_tag_table(
286 GTK_TEXT_BUFFER(buf));
288 tag = gtk_text_tag_table_lookup(tab,
"zoomlevel");
290 tag = gtk_text_tag_new(
"zoomlevel");
291 gtk_text_tag_table_add(tab, GTK_TEXT_TAG(tag));
296 g_object_set(GTK_TEXT_TAG(tag),
"scale", fscale, NULL);
298 GtkTextIter start, end;
300 gtk_text_buffer_get_bounds(GTK_TEXT_BUFFER(buf),
302 gtk_text_buffer_remove_all_tags(GTK_TEXT_BUFFER(buf),
304 gtk_text_buffer_apply_tag(GTK_TEXT_BUFFER(buf),
305 GTK_TEXT_TAG(tag), &start, &end);
357 GtkWidget *cutbutton;
358 GtkWidget *pastebutton;
359 GtkWidget *deletebutton;
360 GtkWidget *printbutton;
361 GtkTextView *dataview;
362 PangoFontDescription *fontdesc;
368 if (newctx == NULL) {
374 NSLOG(netsurf, INFO,
"Viewdata UI builder init failed");
379 gtk_builder_connect_signals(newctx->
builder, NULL);
384 NSLOG(netsurf, INFO,
"Unable to find window in builder ");
387 g_object_unref(G_OBJECT(newctx->
builder));
395 cutbutton = GTK_WIDGET(gtk_builder_get_object(newctx->
builder,
"viewdata_cut"));
396 pastebutton = GTK_WIDGET(gtk_builder_get_object(newctx->
builder,
"viewdata_paste"));
397 deletebutton = GTK_WIDGET(gtk_builder_get_object(newctx->
builder,
"viewdata_delete"));
398 printbutton = GTK_WIDGET(gtk_builder_get_object(newctx->
builder,
"viewdata_print"));
399 gtk_widget_set_sensitive(cutbutton, FALSE);
400 gtk_widget_set_sensitive(pastebutton, FALSE);
401 gtk_widget_set_sensitive(deletebutton, FALSE);
403 gtk_widget_set_sensitive(printbutton, FALSE);
408 newctx->
data = ndata;
422 gtk_window_set_title(
window, title);
424 g_signal_connect(G_OBJECT(
window),
"destroy",
427 g_signal_connect(G_OBJECT(
window),
"delete-event",
431 dataview = GTK_TEXT_VIEW(gtk_builder_get_object(newctx->
builder,
434 fontdesc = pango_font_description_from_string(
"Monospace 8");
436 newctx->
gv = dataview;
439 tb = gtk_text_view_get_buffer(dataview);
440 gtk_text_buffer_set_text(tb, newctx->
data, -1);
442 gtk_widget_show(GTK_WIDGET(
window));
452 const char *leafname,
465 if (fseek(f, 0, SEEK_END) != 0) {
471 if (tell_len == -1) {
476 if (fseek(f, 0, SEEK_SET) != 0) {
481 ndata = malloc(tell_len);
483 ndata_len = fread(ndata, 1, tell_len, f);
488 ret =
window_init(title, leafname, ndata, ndata_len);
501 const char *leafname,
528 const char *leafname,
537 handle = g_file_open_tmp(
"nsgtkdataXXXXXX", &fname, NULL);
538 if ((handle == -1) || (fname == NULL)) {
544 f = fopen(fname,
"w");
550 fprintf(f,
"%s", ndata);
577 const char *xdg_data_dirs;
578 const char *xdg_data_home;
579 const char *home_dir;
584 xdg_data_dirs = getenv(
"XDG_DATA_DIRS");
585 if ((xdg_data_dirs == NULL) ||
586 (*xdg_data_dirs == 0) ||
587 (strlen(xdg_data_dirs) > 4096)) {
588 xdg_data_dirs =
"/usr/local/share/:/usr/share/";
591 xdg_data_home = getenv(
"XDG_DATA_HOME");
592 if ((xdg_data_home == NULL) ||
593 (*xdg_data_home == 0) ||
594 (strlen(xdg_data_home) > 4096)) {
597 home_dir = getenv(
"HOME");
598 if ((home_dir == NULL) ||
600 (strlen(home_dir) > 4096)) {
601 xdg_data_path = strdup(xdg_data_dirs);
603 xdg_data_size = strlen(home_dir) +
604 SLEN(
"/.local/share:") +
605 strlen(xdg_data_dirs) + 1;
606 xdg_data_path = malloc(xdg_data_size);
607 snprintf(xdg_data_path, xdg_data_size ,
608 "%s/.local/share/:%s",
609 home_dir, xdg_data_dirs);
612 xdg_data_size = strlen(xdg_data_home) +
613 strlen(xdg_data_dirs) + 2;
614 xdg_data_path = malloc(xdg_data_size);
615 snprintf(xdg_data_path, xdg_data_size ,
"%s:%s",
616 xdg_data_home, xdg_data_dirs);
619 NSLOG(netsurf, INFO,
"%s", xdg_data_path);
650 fname_len = strlen(
path) +
SLEN(
"/applications/defaults.list") + 1;
651 fname = malloc(fname_len);
652 snprintf(fname, fname_len,
"%s/applications/defaults.list",
path);
654 NSLOG(netsurf, INFO,
"Checking %s", fname);
656 fp = fopen(fname,
"r");
662 mimetype_len = strlen(mimetype);
663 while ((rd = getline(&
line, &len, fp)) != -1) {
665 while ((
line[rd - 1] ==
'\n') || (
line[rd - 1] ==
'\r')) {
671 if ((rd > mimetype_len) &&
672 (
line[mimetype_len] ==
'=') &&
673 (strncmp(
line, mimetype, mimetype_len) == 0)) {
675 ret = strdup(
line + mimetype_len + 1);
678 "Found line match for %s length %zu\n",
681 NSLOG(netsurf, INFO,
"Result %s", ret);
716 fname_len = strlen(
path) +
SLEN(
"/applications/") + strlen(desktop) + 1;
717 fname = malloc(fname_len);
718 snprintf(fname, fname_len,
"%s/applications/%s",
path, desktop);
720 NSLOG(netsurf, INFO,
"Checking %s", fname);
722 fp = fopen(fname,
"r");
728 while ((rd = getline(&
line, &len, fp)) != -1) {
730 while ((
line[rd - 1] ==
'\n') || (
line[rd - 1] ==
'\r')) {
736 if ((rd > (ssize_t)
SLEN(
"Exec=")) &&
737 (strncmp(
line,
"Exec=",
SLEN(
"Exec=")) == 0)) {
741 NSLOG(netsurf, INFO,
"Found Exec length %zu", rd);
742 NSLOG(netsurf, INFO,
"Result %s", ret);
754static char *
exec_arg(
const char *arg,
int len,
const char *fname)
760 if ((*arg ==
'f') || (*arg ==
'F') ||
761 (*arg ==
'u') || (*arg ==
'U')) {
765 res = calloc(1, len + 1);
767 memcpy(res, arg, len);
784 argv = calloc(10,
sizeof(
char *));
792 while ((*cur != 0) && (*cur ==
' ')) {
801 while ((*cur != 0) && (*cur !=
' ')) {
805 argv[aidx] =
exec_arg(start, cur - start, fname);
806 if (argv[aidx] != NULL) {
807 NSLOG(netsurf, INFO,
"adding \"%s\"", argv[aidx]);
827 const char *leafname,
833 char *def_app_desktop = NULL;
834 char *exec_cmd = NULL;
842 while (xdg_data_vec[veci] != NULL) {
845 if (def_app_desktop != NULL) {
851 if (def_app_desktop == NULL) {
859 while (xdg_data_vec[veci] != NULL) {
861 if (exec_cmd != NULL) {
866 free(def_app_desktop);
869 if (exec_cmd == NULL) {
879 if (g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL,
880 NULL, NULL) != TRUE) {
893 const char *leafname,
903 handle = g_file_open_tmp(
"nsgtkdataXXXXXX", &fname, NULL);
904 if ((handle == -1) || (fname == NULL)) {
910 f = fopen(fname,
"w");
916 fprintf(f,
"%s", ndata);
967 const char *leafname,
Browser window creation and manipulation interface.
nserror browser_window_create(enum browser_window_create_flags flags, struct nsurl *url, struct nsurl *referrer, struct browser_window *existing, struct browser_window **bw)
Create and open a new root browser window with the given page.
@ BW_CREATE_HISTORY
this will form a new history node (don't set for back/reload/etc)
@ BW_CREATE_TAB
New gui_window to be tab in same window as "existing" gui_window.
GtkWidget * nsgtk_dialog_get_content_area(GtkDialog *dialog)
void nsgtk_widget_modify_font(GtkWidget *widget, PangoFontDescription *font_desc)
Compatibility functions for older GTK versions (interface)
#define NSGTK_STOCK_CANCEL
nserror
Enumeration of error codes.
@ NSERROR_SAVE_FAILED
Failed to save data.
@ NSERROR_NOT_FOUND
Requested item not found.
@ NSERROR_INIT_FAILED
Initialisation failed.
@ NSERROR_BAD_PARAMETER
Bad Parameter.
@ NSERROR_BAD_SIZE
Bad size.
@ NSERROR_NOMEM
Memory exhaustion.
char ** filepath_path_to_strvec(const char *path)
Convert a colon separated list of path elements into a string vector.
void filepath_free_strvec(char **pathv)
Free a string vector.
Utility routines to obtain paths to file resources.
void nsgtk_about_dialog_init(GtkWindow *parent)
nserror nsgtk_warning(const char *warning, const char *detail)
Warn the user of an event.
#define NSLOG(catname, level, logmsg, args...)
const char * messages_get(const char *key)
Fast lookup of a message by key from the standard Messages hash.
Localised message support (interface).
NetSurf URL handling (interface).
void nsurl_unref(nsurl *url)
Drop a reference to a NetSurf URL object.
struct nsurl nsurl
NetSurf URL object.
nserror nsgtk_builder_new_from_resname(const char *resname, GtkBuilder **builder_out)
Create gtk builder object for the named ui resource.
Interface to gtk builtin resource handling.
Interface to utility string handling.
struct nsgtk_viewdata_ctx * prev
struct nsgtk_viewdata_ctx * next
GtkBuilder * builder
The gtk builder that built the widgets.
GtkTextView * gv
handle to gtk text view (builder holds reference)
GtkWindow * window
handle to gtk window (builder holds reference)
nserror netsurf_path_to_nsurl(const char *path, struct nsurl **url)
Create a nsurl from a path.
Default operations table for files.
Option reading and saving interface.
#define nsoption_int(OPTION)
Get the value of an integer option.
UTF-8 manipulation functions (interface).
Interface to a number of general purpose functionality.
#define SLEN(x)
Calculate length of constant C string.
gboolean nsgtk_on_viewdata_select_all_activate(GtkMenuItem *widget, gpointer g)
static gboolean nsgtk_viewdata_destroy_event(GtkBuilder *window, gpointer g)
static char * xdg_get_exec_cmd(const char *path, const char *desktop)
Search desktop file for an Exec line.
nserror nsgtk_viewfile(const char *title, const char *leafname, const char *filename)
Display file to a user.
static nserror tab_init_fname(const char *title, const char *leafname, const char *fname)
open a new tab from an existing file.
static char ** build_exec_argv(const char *fname, const char *exec_cmd)
Build vector for executing app.
gboolean nsgtk_on_viewdata_about_activate(GtkMenuItem *widget, gpointer g)
static char ** xdg_data_strvec(void)
Build string vector of search path.
static nserror window_init(const char *title, const char *filename, char *ndata, size_t ndata_len)
View the data in a gtk text window.
static void nsgtk_attach_viewdata_menu_handlers(GtkBuilder *xml, gpointer g)
static char * xdg_get_default_app(const char *path, const char *mimetype)
Search application defaults file for matching mime type.
static void nsgtk_viewdata_file_save(GtkWindow *parent, const char *filename, const char *data, size_t data_size)
gboolean nsgtk_on_viewdata_zoom_normal_activate(GtkMenuItem *widget, gpointer g)
static nserror editor_init(const char *title, const char *leafname, char *ndata, size_t ndata_len)
open an editor with data.
gboolean nsgtk_on_viewdata_zoom_in_activate(GtkMenuItem *widget, gpointer g)
gboolean nsgtk_on_viewdata_save_as_activate(GtkMenuItem *widget, gpointer g)
gboolean nsgtk_on_viewdata_copy_activate(GtkMenuItem *widget, gpointer g)
static nserror editor_init_fname(const char *title, const char *leafname, const char *fname)
open an editor from an existing file.
static struct nsgtk_viewdata_ctx * nsgtk_viewdata_list
static gboolean nsgtk_viewdata_delete_event(GtkWindow *window, gpointer g)
static nserror tab_init(const char *title, const char *leafname, char *ndata, size_t ndata_len)
create a new tab from data.
gboolean nsgtk_on_viewdata_paste_activate(GtkMenuItem *widget, gpointer g)
nserror nsgtk_viewdata(const char *title, const char *filename, char *ndata, size_t ndata_len)
Display text to a user.
static nserror window_init_fname(const char *title, const char *leafname, const char *filename)
open a window to dispaly an existing file.
static char viewdata_zoomlevel
gboolean nsgtk_on_viewdata_print_activate(GtkMenuItem *widget, gpointer g)
gboolean nsgtk_on_viewdata_close_activate(GtkMenuItem *widget, gpointer g)
gboolean nsgtk_on_viewdata_delete_activate(GtkMenuItem *widget, gpointer g)
gboolean nsgtk_on_viewdata_zoom_out_activate(GtkMenuItem *widget, gpointer g)
static void nsgtk_viewdata_update_zoomlevel(gpointer g)
static struct menu_events viewdata_menu_events[]
gboolean nsgtk_on_viewdata_cut_activate(GtkMenuItem *widget, gpointer g)
static char * exec_arg(const char *arg, int len, const char *fname)
static nserror path(const struct redraw_context *ctx, const plot_style_t *pstyle, const float *p, unsigned int n, const float transform[6])
Plots a path.
static nserror line(const struct redraw_context *ctx, const plot_style_t *style, const struct rect *line)
Plots a line.