spek

Acoustic spectrum analyser
git clone http://git.hanabi.in/repos/spek.git
Log | Files | Refs | README

commit e4e8e6bb23a734634da1f3f19a03c247adcfe476
parent 82b5e2c779690012dde783af2c45ac9bf3bf446c
Author: Alexander Kojevnikov <alexander@kojevnikov.com>
Date:   Wed, 19 May 2010 19:25:48 +1000

DnD support (issue 4)

Diffstat:
Msrc/spek-window.vala | 23+++++++++++++++++++++++
Mvapi/config.vapi | 6++++++
2 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/src/spek-window.vala b/src/spek-window.vala @@ -27,6 +27,9 @@ namespace Spek { private FileFilter filter_all; private FileFilter filter_audio; private FileFilter filter_png; + private const Gtk.TargetEntry[] DEST_TARGET_ENTRIES = { + { "text/uri-list", 0, 0 } + }; public Window (string? file_name) { title = _("Spek - Acoustic Spectrum Analyser"); @@ -96,11 +99,31 @@ namespace Spek { add (vbox); show_all (); + // Set up Drag and Drop + drag_dest_set (this, DestDefaults.ALL, DEST_TARGET_ENTRIES, DragAction.COPY); + drag_data_received.connect (on_dropped); + if (file_name != null) { open_file (file_name); } } + void on_dropped (DragContext cx, int x, int y, SelectionData data, uint info, uint time) { + if (data.length > 0 && data.format == 8) { + string[] files = data.get_uris (); + if (files.length > 0) { + try { + string hostname; + var file = filename_from_uri (files[0], out hostname); + open_file (file); + drag_finish (cx, true, false, time); + return; + } catch {} + } + } + drag_finish (cx, false, false, time); + } + private void open_file (string file_name) { cur_dir = Path.get_dirname (file_name); spectrogram.open (file_name); diff --git a/vapi/config.vapi b/vapi/config.vapi @@ -14,3 +14,9 @@ namespace Config { public const string PKGDATADIR; /* /usr/local/share/spek */ public const string PKGLIBDIR; /* /usr/local/lib/spek */ } + +// TODO: file a bug to have this included +[CCode (cprefix = "G", lower_case_cprefix = "g_", cheader_filename = "glib.h", gir_namespace = "GLib", gir_version = "2.0")] +namespace GLib { + public static string filename_from_uri (string uri, out string hostname) throws Error; +}