diff --git a/CMakeLists.txt b/CMakeLists.txt index 217171a4..244d7336 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,12 +61,17 @@ pkg_check_modules(GIO REQUIRED gio-2.0>=2.42) pkg_check_modules(GLIB2 REQUIRED glib-2.0>=2.38) pkg_check_modules(GMODULE REQUIRED gmodule-2.0) pkg_check_modules(KEYBINDER keybinder-3.0) +pkg_check_modules(LIBSOUP libsoup-2.4) +pkg_check_modules(JSON_GLIB json-glib-1.0) add_definitions(${GTK_CFLAGS} ${GTK_CFLAGS_OTHER}) link_libraries(${GTK_LIBRARIES}) link_libraries(${KEYBINDER_LIBRARIES}) link_directories(${GTK_LIBRARY_DIRS}) - +include_directories(${LIBSOUP_INCLUDE_DIRS}) +include_directories(${JSON_GLIB_INCLUDE_DIRS}) +link_libraries(${LIBSOUP_LDFLAGS}) +link_libraries(${JSON_GLIB_LDFLAGS}) # compile glib resource files to c code configure_file ( "${PROJECT_SOURCE_DIR}/ui/about.ui.in" @@ -154,9 +159,12 @@ vala_precompile(VALA_C src/ui/error-dialog.vala src/ui/preferences-dialog.vala src/ui/shortcut-label.vala + src/ui/share-dialog.vala PACKAGES gtk+-3.0 posix + libsoup-2.4 + json-glib-1.0 DEFINITIONS ${VALA_DEFINITIONS} CUSTOM_VAPIS @@ -220,3 +228,4 @@ set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64") set(CPACK_DEBIAN_PACKAGE_SECTION "video") include(CPack) + diff --git a/src/meson.build b/src/meson.build index cf2c45a7..6b3b54ed 100644 --- a/src/meson.build +++ b/src/meson.build @@ -28,6 +28,7 @@ peek_sources = [ 'ui/application-window.vala', 'ui/error-dialog.vala', 'ui/preferences-dialog.vala', + 'ui/share-dialog.vala', 'ui/shortcut-label.vala', 'vapi/config.vapi', ] @@ -55,6 +56,8 @@ peek_deps = [ dependency('gio-2.0', version: '>= 2.42'), dependency('glib-2.0', version: '>= 2.38'), dependency('gmodule-2.0'), + dependency('libsoup-2.4'), + dependency('json-glib-1.0'), gtk, ] diff --git a/src/ui/application-window.vala b/src/ui/application-window.vala index 08ffa123..8d884b17 100644 --- a/src/ui/application-window.vala +++ b/src/ui/application-window.vala @@ -31,6 +31,7 @@ namespace Peek.Ui { public string default_file_name_format { get; set; } public string save_folder { get; set; } + // public string get_file {get; set;} [GtkChild] private HeaderBar headerbar; @@ -196,6 +197,10 @@ namespace Peek.Ui { this.set_close_button_position (); } + public string get_file(){ + return out_file.get_uri(); + } + public void hide_headerbar () { this.get_style_context ().add_class ("headerbar-hidden"); @@ -706,6 +711,8 @@ namespace Peek.Ui { // Close the FileChooserDialog: chooser.close (); #endif + + chooser.destroy(); } private void try_save_file () { @@ -747,6 +754,12 @@ namespace Peek.Ui { private void handle_saved_file (File file) { save_preferred_save_folder (file); + string out_file_ext = Utils.get_file_extension_for_format ( + recorder.config.output_format); + ShareDialog.get_file_ext(out_file_ext); + ShareDialog.filename(file); + ShareDialog.present_single_instance(this); + #if ! DISABLE_OPEN_FILE_MANAGER if (this.visible && open_file_manager) { diff --git a/src/ui/share-dialog.vala b/src/ui/share-dialog.vala new file mode 100644 index 00000000..df3c4aab --- /dev/null +++ b/src/ui/share-dialog.vala @@ -0,0 +1,144 @@ + +using Gtk; +using Soup; + +namespace Peek.Ui { + + [GtkTemplate (ui = "/com/uploadedlobster/peek/share-dialog.ui")] + class ShareDialog : Window { + private static Gtk.Window? instance; + + public static Gtk.Window present_single_instance (Gtk.Window main_window) { + if (instance == null) { + instance = new ShareDialog (); + instance.delete_event.connect ((event) => { + instance = null; + main_window.set_keep_above (true); + return false; + }); + } + + instance.transient_for = main_window; + main_window.set_keep_above (false); + instance.present (); + return instance; + } + + public static File file { get; set; } + public static string file_type { get; set; } + + public static void filename (File out_file) { + file=out_file; + } + + public static void get_file_ext (string file_ext) { + file_type=file_ext; + } + public void do_imgur_upload() { + string image_uri = file.get_path(); + //string image=image_uri.replace("%20"," "); + debug(image_uri); + uint8[] data; + try { + GLib.FileUtils.get_data(image_uri, out data); + } catch (GLib.FileError e) { + warning(e.message); + } + const string CLIENT_ID = "Client-ID bfb3ac58837a0d0"; + string image_test =GLib.Base64.encode(data); + var mpart = new Multipart(FORM_MIME_TYPE_MULTIPART); + var session = new Soup.Session (); + mpart.append_form_string("image", image_test); + var message = Soup.Form.request_new_from_multipart("https://api.imgur.com/3/image",mpart); + message.request_headers.append("Authorization", CLIENT_ID); + MainLoop loop = new MainLoop (); + session.queue_message (message, (sess, mess) => { + // Process the result: + var response = (string) message.response_body.data; + debug(response); + try { + var parser = new Json.Parser (); + parser.load_from_data (response, -1); + var root_object = parser.get_root ().get_object (); + string link = root_object.get_object_member ("data") + .get_string_member ("link"); + debug(link); +#if HAS_GTK_SHOW_URI_ON_WINDOW + Gtk.show_uri_on_window(instance, link, Gdk.CURRENT_TIME); +#else + Gtk.show_uri(null, link, Gdk.CURRENT_TIME); +#endif + this.close(); + }catch(Error e) { + error("%s", e.message); + } + loop.quit (); + }); + loop.run (); + + } + + public void open_file_manager () { + DesktopIntegration.launch_file_manager (file); + } + + [GtkChild] + private Gtk.Image check_1; + + [GtkChild] + private Gtk.Image check_2; + + [GtkChild] + private Gtk.ListBox options_list; + + [GtkChild] + private Gtk.ListBoxRow imgur_row; + + [GtkChild] + private Gtk.ListBoxRow open_file_row; + + [GtkCallback] + private void on_options_list_row_selected () { + var selection = options_list.get_selected_row (); + //string[] white_list = {"gif", "apng"}; + var white_list = new List (); + white_list.append ("gif"); + white_list.append ("apng"); + if (!white_list.data.contains(file_type) ) { + imgur_row.set_selectable(false); + imgur_row.hide(); + check_2.show(); + check_1.hide(); + options_list.select_row(open_file_row); + debug("WebM and Mp4 files are not supported with in imgur upload api"); + }else { + imgur_row.set_selectable(true); + check_1.show (); + if (selection == imgur_row ) { + check_2.hide(); + }else if (selection == open_file_row ){ + check_2.show (); + check_1.hide (); + } + } + + + } + [GtkCallback] + private void on_confirm_option_clicked () { + if (options_list.get_selected_row () == imgur_row ) { + do_imgur_upload(); + } + else { + DesktopIntegration.launch_file_manager (file); + this.close(); + } + } + [GtkCallback] + private void on_sharing_cancel_clicked () { + this.close (); + } + } + + +} diff --git a/ui/peek.gresource.xml b/ui/peek.gresource.xml index f9eda428..b34312af 100644 --- a/ui/peek.gresource.xml +++ b/ui/peek.gresource.xml @@ -1,17 +1,18 @@ - - - - - application-window.ui - error-dialog.ui - preferences.ui - about.ui - - - css/peek.css - css/unity.css - css/ambiance.css - css/breeze.css - css/breeze-dark.css - - + + + + + application-window.ui + error-dialog.ui + preferences.ui + about.ui + share-dialog.ui + + + css/peek.css + css/unity.css + css/ambiance.css + css/breeze.css + css/breeze-dark.css + + diff --git a/ui/share-dialog.ui b/ui/share-dialog.ui new file mode 100644 index 00000000..8975bb0e --- /dev/null +++ b/ui/share-dialog.ui @@ -0,0 +1,153 @@ + + + + + +