Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Imgur upload functionality #311

Open
wants to merge 53 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
0c4eeb4
Add libsoup and json-glib pkgs
gort818 Apr 13, 2018
d962cf3
Update CMakeLists.txt
gort818 Apr 13, 2018
c5ba2fb
Add new files to cmake
gort818 Apr 29, 2018
ea6c9a9
Add ui for share dialog
gort818 Apr 29, 2018
1328aa4
Add code for share dialog window
gort818 Apr 29, 2018
83fd79b
Add share dialog instance
gort818 Apr 29, 2018
1deb39c
Add share dialog ui to resources
gort818 Apr 29, 2018
9465011
Rename share dialog file
gort818 Apr 29, 2018
ea3ee1c
Change required gtk version to 3.14
gort818 May 1, 2018
87128ee
Destroy file chooser dialog after confirming save location
gort818 May 1, 2018
62d5030
Add error handling, code formatting
gort818 May 1, 2018
6e0bba7
Small ui changes
gort818 May 1, 2018
59625f4
Add preprocesser for gtk 3.22
gort818 May 2, 2018
d5b1bf7
Pass file extention to share dialog
gort818 May 2, 2018
c6768e5
Check for file format
gort818 May 2, 2018
853d91d
Wrong file
gort818 May 2, 2018
9495360
wrong file
gort818 May 2, 2018
e9576c6
Check for file format
gort818 May 2, 2018
5e96ae5
Check for file format
gort818 May 2, 2018
686d640
add debug message.
gort818 May 2, 2018
465e5ce
Change positon of share dialog window
gort818 May 2, 2018
dd0fee9
Close the share dialog after uploading image.
gort818 May 2, 2018
97c3253
Fix selection boxes
gort818 May 4, 2018
d07328f
Imgur upload and share Dialog changes
gort818 Jul 20, 2018
f790dfd
Add libsoup and json-glib pkgs
gort818 Apr 13, 2018
0eaa85c
Update CMakeLists.txt
gort818 Apr 13, 2018
37bbc01
Add new files to cmake
gort818 Apr 29, 2018
c738a54
Add ui for share dialog
gort818 Apr 29, 2018
f888bca
Add code for share dialog window
gort818 Apr 29, 2018
81ce285
Add share dialog instance
gort818 Apr 29, 2018
74fd725
Add share dialog ui to resources
gort818 Apr 29, 2018
c1d169b
Rename share dialog file
gort818 Apr 29, 2018
3cbbd4e
Change required gtk version to 3.14
gort818 May 1, 2018
625701b
Destroy file chooser dialog after confirming save location
gort818 May 1, 2018
e3db2c5
Add error handling, code formatting
gort818 May 1, 2018
5a63323
Small ui changes
gort818 May 1, 2018
f9bf8d2
Add preprocesser for gtk 3.22
gort818 May 2, 2018
2da5d2f
Pass file extention to share dialog
gort818 May 2, 2018
bedf997
Check for file format
gort818 May 2, 2018
979fb47
Wrong file
gort818 May 2, 2018
d650a43
wrong file
gort818 May 2, 2018
4aa0242
Check for file format
gort818 May 2, 2018
0e0fd6b
Check for file format
gort818 May 2, 2018
a5ecf1d
add debug message.
gort818 May 2, 2018
f2771e3
Change positon of share dialog window
gort818 May 2, 2018
abfc727
Close the share dialog after uploading image.
gort818 May 2, 2018
4265d33
Fix selection boxes
gort818 May 4, 2018
da7f7f5
Imgur upload and share Dialog changes
gort818 Jul 20, 2018
fb49937
Merge branch 'imgur' of https://github.com/gort818/peek into imgur
gort818 Sep 22, 2018
e5c43b7
Add dependencies to meson build system
gort818 Sep 22, 2018
aacdc10
Added whitelist for supported upload formats
gort818 Oct 25, 2018
22908f9
Merge https://github.com/phw/peek into imgur
gort818 Sep 7, 2019
ef0480e
fix merge conflicts
gort818 Sep 7, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -220,3 +228,4 @@ set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64")
set(CPACK_DEBIAN_PACKAGE_SECTION "video")

include(CPack)

3 changes: 3 additions & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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',
]
Expand Down Expand Up @@ -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,
]

Expand Down
13 changes: 13 additions & 0 deletions src/ui/application-window.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -706,6 +711,8 @@ namespace Peek.Ui {
// Close the FileChooserDialog:
chooser.close ();
#endif

chooser.destroy();
}

private void try_save_file () {
Expand Down Expand Up @@ -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) {
Expand Down
144 changes: 144 additions & 0 deletions src/ui/share-dialog.vala
Original file line number Diff line number Diff line change
@@ -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<string> ();
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 ();
}
}


}
35 changes: 18 additions & 17 deletions ui/peek.gresource.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/com/uploadedlobster/peek">
<!-- UI files -->
<file preprocess="xml-stripblanks">application-window.ui</file>
<file preprocess="xml-stripblanks">error-dialog.ui</file>
<file preprocess="xml-stripblanks">preferences.ui</file>
<file preprocess="xml-stripblanks">about.ui</file>

<!-- Stylesheets -->
<file>css/peek.css</file>
<file>css/unity.css</file>
<file>css/ambiance.css</file>
<file>css/breeze.css</file>
<file>css/breeze-dark.css</file>
</gresource>
</gresources>
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/com/uploadedlobster/peek">
<!-- UI files -->
<file preprocess="xml-stripblanks">application-window.ui</file>
<file preprocess="xml-stripblanks">error-dialog.ui</file>
<file preprocess="xml-stripblanks">preferences.ui</file>
<file preprocess="xml-stripblanks">about.ui</file>
<file preprocess="xml-stripblanks">share-dialog.ui</file>

<!-- Stylesheets -->
<file>css/peek.css</file>
<file>css/unity.css</file>
<file>css/ambiance.css</file>
<file>css/breeze.css</file>
<file>css/breeze-dark.css</file>
</gresource>
</gresources>