Skip to content

Commit

Permalink
Make preview optional dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
bartkessels committed Feb 12, 2018
1 parent 2abcc0f commit 70b1519
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 14 deletions.
8 changes: 1 addition & 7 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,12 @@ project('getit','c',
)
i18n = import('i18n')

config_h = configuration_data()
config_h.set_quoted('GETTEXT_PACKAGE', 'getit')
config_h.set_quoted('LOCALEDIR', join_paths(get_option('prefix'), get_option('localedir')))
configure_file(
output: 'getit-config.h',
configuration: config_h,
)
add_project_arguments([
'-I' + meson.build_root(),
], language: 'c')

subdir('data')
subdir('src')
subdir('po')

meson.add_install_script('build-aux/meson/postinstall.py')
16 changes: 15 additions & 1 deletion src/getit-content-response.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,13 @@ getit_content_response_new ()
GetitContentResponse *content_response;

content_response = g_object_new (GETIT_TYPE_CONTENT_RESPONSE, NULL);

#ifdef WEBKIT2_AVAILABLE
content_response->wv_output_preview = webkit_web_view_new ();
gtk_container_add (GTK_CONTAINER (content_response->sw_output_preview), content_response->wv_output_preview);
#else
gtk_widget_destroy (GTK_WIDGET (content_response->sw_output_preview));
#endif

return content_response;
}
Expand Down Expand Up @@ -120,11 +125,14 @@ getit_content_response_show_response (GetitContentResponse *self,
const gchar *status_value;
GtkTextBuffer *text_buffer_pretty;
GtkTextBuffer *text_buffer_raw;
const gchar *mimetype;
GError *json_error = NULL;
JsonParser *json_parser;

#ifdef WEBKIT2_AVAILABLE
const gchar *mimetype;
GString *string_response;
GBytes *bytes_response;
#endif

getit_content_response_show_screen (self,
FALSE,
Expand All @@ -151,8 +159,10 @@ getit_content_response_show_response (GetitContentResponse *self,
gtk_text_buffer_set_text (text_buffer_pretty, "", 0);
gtk_text_buffer_set_text (text_buffer_raw, "", 0);

#ifdef WEBKIT2_AVAILABLE
/* Clear webview */
webkit_web_view_load_plain_text (WEBKIT_WEB_VIEW (self->wv_output_preview), "");
#endif

/* Don't continue if the body is empty */
gtk_widget_show_all (GTK_WIDGET (self->pnd_output));
Expand All @@ -168,11 +178,13 @@ getit_content_response_show_response (GetitContentResponse *self,
gtk_text_buffer_set_text (text_buffer_pretty, body, strlen (body));
gtk_text_buffer_set_text (text_buffer_raw, body, strlen (body));

#ifdef WEBKIT2_AVAILABLE
/* Get mimetype */
mimetype = NULL;
if (language != NULL) {
mimetype = gtk_source_language_get_mime_types (language)[0];
}
#endif

/* Make JSON response readable */
json_parser = json_parser_new ();
Expand All @@ -196,6 +208,7 @@ getit_content_response_show_response (GetitContentResponse *self,
g_error_free (json_error);
}

#ifdef WEBKIT2_AVAILABLE
/* Load webview */
string_response = g_string_new (body);
bytes_response = g_string_free_to_bytes (string_response);
Expand All @@ -204,6 +217,7 @@ getit_content_response_show_response (GetitContentResponse *self,
mimetype,
NULL,
uri);
#endif

/* Set language of response */
if (GTK_SOURCE_IS_LANGUAGE (language)) {
Expand Down
7 changes: 6 additions & 1 deletion src/getit-content-response.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,19 @@

#pragma once

#include "getit-config.h"

#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include <gtksourceview/gtksource.h>
#include <libsoup/soup.h>
#include <string.h>
#include <webkit2/webkit2.h>
#include <json-glib/json-glib.h>

#ifdef WEBKIT2_AVAILABLE
#include <webkit2/webkit2.h>
#endif

#include "getit-messages.h"
#include "getit-settings.h"

Expand Down
2 changes: 0 additions & 2 deletions src/getit-window.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,6 @@ getit_window_request_finished (SoupSession *session,
self = GETIT_WINDOW (user_data);
content_response = getit_stack_get_content_response (self->stack);

g_print ("Status code: %d\n", message->status_code); // 6

/* Check if connection was timed out */
if (message->status_code == 7) {
/* Abort session */
Expand Down
21 changes: 19 additions & 2 deletions src/meson.build
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
config_h = configuration_data()
config_h.set_quoted('GETTEXT_PACKAGE', 'getit')
config_h.set_quoted('LOCALEDIR', join_paths(get_option('prefix'), get_option('localedir')))

getit_sources = [
'getit-application.c',
'getit-content-body.c',
Expand All @@ -19,24 +23,37 @@ getit_sources = [
'main.c'
]

# Required dependencies
getit_deps = [
dependency('gio-2.0', version: '>= 2.50'),
dependency('glib-2.0', version: '>= 2.50'),
dependency('gtk+-3.0', version: '>= 3.22'),
dependency('libsoup-2.4', version: '>= 2.40'),
dependency('gtksourceview-3.0', version: '>= 3.22'),
dependency('libnotify', version: '>= 0.7.6'),
dependency('json-glib-1.0', version: '>= 1.2'),
dependency('webkit2gtk-4.0', version: '>= 2.18.5')
dependency('json-glib-1.0', version: '>= 1.2')
]

# Optional dependencies
webkit_dep = dependency('webkit2gtk-4.0', version: '>= 2.18.5', required: false)

if webkit_dep.found()
config_h.set('WEBKIT2_AVAILABLE', 'TRUE')
getit_deps += webkit_dep
endif

gnome = import('gnome')

getit_sources += gnome.compile_resources('getit-resources',
'getit.gresource.xml',
c_name: 'getit'
)

configure_file(
output: 'getit-config.h',
configuration: config_h,
)

executable('getit', getit_sources,

dependencies: getit_deps,
Expand Down
2 changes: 1 addition & 1 deletion src/ui/content_response.glade
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
</child>
<child>
<object class="GtkPaned" id="pnd_output">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="orientation">vertical</property>
<property name="position">250</property>
Expand Down Expand Up @@ -226,7 +227,6 @@
</child>
<child>
<object class="GtkNotebook" id="nb_output_content">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="margin_top">5</property>
<property name="tab_pos">left</property>
Expand Down

0 comments on commit 70b1519

Please sign in to comment.