Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ add_definitions (-DGETTEXT_PACKAGE=\"${GETTEXT_PACKAGE}\")
add_definitions(-w)

set (PKG_DEPS
granite>=0.3
granite>=0.4
gee-0.8
gtk+-3.0>=3.9.10
json-glib-1.0
Expand Down
4 changes: 4 additions & 0 deletions data/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/com.github.philip-scott.spice-up.appda
# install the mimefile
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/com.github.philip-scott.spice-up.mime.xml
DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/mime/packages/)

# install thumbnailer file
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/com.github.philip-scott.spice-up.thumbnailer
DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/thumbnailers/)
4 changes: 4 additions & 0 deletions data/com.github.philip-scott.spice-up.thumbnailer
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[Thumbnailer Entry]
TryExec=com.github.philip-scott.spice-up
Exec=com.github.philip-scott.spice-up -t %i %o
MimeType=application/x-spiceup;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[Specialized Thumbnailer]
Name=org.freedesktop.thumbnails.Thumbnailer1.spiceup
ObjectPath=/org/freedesktop/thumbnails/Thumbnailer1/spiceup
MimeTypes=application/x-spiceup
Comment=free comment
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[D-BUS Service]
Name=org.freedesktop.thumbnails.Thumbnailer1.spiceup
Exec=/usr/bin/com.github.philip-scott.spice-up -b
67 changes: 66 additions & 1 deletion src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ public class Spice.Application : Granite.Application {
public const string ABOUT_STOCK = N_("About Spice-Up");

public bool running = false;
Spice.DbusThumbnailer? thumbnailer = null;

construct {
flags |= ApplicationFlags.HANDLES_OPEN;
flags |= ApplicationFlags.HANDLES_COMMAND_LINE;

application_id = "com.github.philip-scott.spice-up";
program_name = PROGRAM_NAME;
Expand Down Expand Up @@ -66,7 +68,7 @@ public class Spice.Application : Granite.Application {
}

public override void activate () {
if (!running) {
if (window == null) {
weak Gtk.IconTheme default_theme = Gtk.IconTheme.get_default ();
default_theme.add_resource_path ("/com/github/philip-scott/spice-up");

Expand All @@ -79,4 +81,67 @@ public class Spice.Application : Granite.Application {

window.show_app ();
}

protected override int command_line (ApplicationCommandLine command_line) {
var context = new OptionContext ("File");
context.add_main_entries (entries, "com.github.philip-scott.spice-up");
context.add_group (Gtk.get_option_group (true));

string[] args = command_line.get_arguments ();
int unclaimed_args;

try {
unowned string[] tmp = args;
context.parse (ref tmp);
unclaimed_args = tmp.length - 1;
} catch(Error e) {
print (e.message + "\n");

return Posix.EXIT_FAILURE;
}

if (start_thumbnailer) {
start_thumbnailer = false;
if (unclaimed_args > 1) {
var files = new List<File>();

foreach (string arg in args[1:unclaimed_args + 1]) {
var file = File.new_for_commandline_arg (arg);
files.append (file);
}

Spice.Services.Thumbnailer.run (files);
}
} else if (start_dbus) {
start_dbus = false;
if (thumbnailer == null) {
thumbnailer = new Spice.DbusThumbnailer ();

new MainLoop ().run ();
}
} else {
activate ();

if (unclaimed_args > 0) {
foreach (string arg in args[1:unclaimed_args + 1]) {
var file = File.new_for_commandline_arg (arg);
var files = new File[1];
files[0] = file;

open (files, "");
}
}
}

return Posix.EXIT_SUCCESS;
}

private static bool start_thumbnailer;
private static bool start_dbus;

const OptionEntry[] entries = {
{ "thumbnailer", 't', 0, OptionArg.NONE, out start_thumbnailer, N_("Thumbnailer"), null },
{ "dbus-thumbnailer", 'b', 0, OptionArg.NONE, out start_dbus, N_("Thumbnailer"), null },
{ null }
};
}
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ vala_precompile(VALA_C
Services/FileManager.vala
Services/HistoryManager.vala
Services/Utils.vala
Services/Thumbnailer.vala
Services/DBusThumnailer.vala
Services/GamepadSlideController.vala

Widgets/Canvas.vala
Widgets/ColorButton.vala
Widgets/EntryCombo.vala
Expand Down
44 changes: 44 additions & 0 deletions src/Services/DBusThumnailer.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@


[DBus (name = "org.freedesktop.thumbnails.Thumbnailer1.spiceup")]
public class Spice.Tumbler : GLib.Object {
public async uint Queue (string[] uris, string[] mime_types, string flavor, string sheduler, uint handle) throws GLib.IOError, GLib.DBusError {
stderr.printf ("Requesting file! \n");
var files = new List<File>();

files.append (File.new_for_uri ("file:///home/felipe/FirstPresentation.spice"));
files.append (File.new_for_uri ("file:///home/felipe/FirstPresentation.png"));

Spice.Services.Thumbnailer.run (files);

return 0;
}
}

public class Spice.DbusThumbnailer : GLib.Object {
private const string THUMBNAILER_IFACE = "org.freedesktop.thumbnails.Thumbnailer1.spiceup";
private const string THUMBNAILER_SERVICE = "/org/freedesktop/thumbnails/Thumbnailer1/spiceup";

private const uint THUMBNAIL_MAX_QUEUE_SIZE = 50;

Spice.Tumbler tumbler;

public DbusThumbnailer (string flavor = "normal") throws GLib.Error {
tumbler = new Spice.Tumbler ();

Bus.own_name (BusType.SESSION, THUMBNAILER_IFACE, BusNameOwnerFlags.NONE,
on_bus_aquired,
() => {},
() => stderr.printf ("Could not aquire name\n"));
}

void on_bus_aquired (DBusConnection conn) {
stderr.printf ("dbus aquired\n");

try {
conn.register_object (THUMBNAILER_SERVICE, tumbler);
} catch (IOError e) {
stderr.printf ("Could not register service\n");
}
}
}
19 changes: 12 additions & 7 deletions src/Services/FileManager.vala
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,23 @@ public class Spice.Services.FileManager {

public static string open_file () {
if (current_file != null && current_file.query_exists ()) {
try {
var dis = new DataInputStream (current_file.read ());
size_t size;
return dis.read_upto ("\0", -1, out size);
} catch (Error e) {
warning ("Error loading file: %s", e.message);
}
return get_contents (current_file);
}

return "";
}

public static string get_contents (File file) {
try {
var dis = new DataInputStream (file.read ());
size_t size;
return dis.read_upto ("\0", -1, out size);
} catch (Error e) {
warning ("Error loading file: %s", e.message);
}
return "";
}

public static void create_file_if_not_exists (File file) {
if (!file.query_exists ()) {
try {
Expand Down
75 changes: 75 additions & 0 deletions src/Services/Thumbnailer.vala
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright (c) 2017 Felipe Escoto (https://github.com/Philip-Scott/Spice-up)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Authored by: Felipe Escoto <[email protected]>
*/

public class Spice.Services.Thumbnailer {
private static int width;

public static void run (List<File> files) {
if (files.length () < 1) return;
var input = files.nth_data (0);
var output = files.nth_data (1);

if (!input.query_exists ()) return;
var data = Spice.Services.FileManager.get_contents (input);

var preview_data = get_thumbnail_data (data);

if (preview_data != "") {
make_surface (preview_data, output);
}
}

private static string get_thumbnail_data (string raw_json) {
try {
var parser = new Json.Parser ();
parser.load_from_data (raw_json);

var root_object = parser.get_root ().get_object ();
var slides_array = root_object.get_array_member ("slides");

var ratio = (int) root_object.get_int_member ("aspect-ratio");
width = Spice.AspectRatio.get_width_value (Spice.AspectRatio.get_mode (ratio));

var slides = slides_array.get_elements ();
if (slides.length () > 0) {
var preview_data = slides.nth_data (0).get_object ().get_string_member ("preview");

if (preview_data != null) return preview_data;
}
} catch (Error e) {
error ("Error loading file: %s", e.message);
}

return "";
}

private static void make_surface (string data, File output_file) {
var pixbuf = Utils.base64_to_pixbuf (data);
pixbuf.scale_simple (width, SlideList.HEIGHT, Gdk.InterpType.BILINEAR);

var surface = new Granite.Drawing.BufferSurface (width, SlideList.HEIGHT);
Gdk.cairo_set_source_pixbuf (surface.context, pixbuf, 0, 0);
surface.context.paint ();

Spice.Services.FileManager.create_file_if_not_exists (output_file);
surface.surface.write_to_png (output_file.get_path ());
}
}
1 change: 0 additions & 1 deletion src/Widgets/Canvas.vala
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ public class Spice.Canvas : Gtk.Overlay {
Utils.set_style (grid, CANVAS_CSS.printf (background_color));

grid.style (background_pattern);
request_draw_preview ();
}

public Granite.Drawing.BufferSurface? surface = null;
Expand Down