[baobab/wip/vala: 40/65] Start to implement "Scan remote dir"
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [baobab/wip/vala: 40/65] Start to implement "Scan remote dir"
- Date: Thu, 5 Apr 2012 12:18:19 +0000 (UTC)
commit 901b72338ac9a129bb48e9cd518222807b791c4d
Author: Paolo Borelli <pborelli gnome org>
Date: Sat Feb 4 00:09:56 2012 +0100
Start to implement "Scan remote dir"
Instead of reimplementing it, spawn nautilus-connect-server and grab the
output uri. The actual scanning does not work yet.
data/baobab-menu.ui | 12 ++++++-
src/Makefile.am | 1 +
src/baobab-connect-server.vala | 63 ++++++++++++++++++++++++++++++++++++++++
src/baobab-window.vala | 11 ++++++-
4 files changed, 84 insertions(+), 3 deletions(-)
---
diff --git a/data/baobab-menu.ui b/data/baobab-menu.ui
index b3e1658..41e139b 100644
--- a/data/baobab-menu.ui
+++ b/data/baobab-menu.ui
@@ -14,10 +14,14 @@
<attribute name="accel"><Primary>f</attribute>
</item>
<item>
- <attribute name="label" translatable="yes">Scan F_older</attribute>
+ <attribute name="label" translatable="yes">Scan F_olderâ</attribute>
<attribute name="action">win.scan-folder</attribute>
<attribute name="accel"><Primary>o</attribute>
</item>
+ <item>
+ <attribute name="label" translatable="yes">Scan Remote Fo_lderâ</attribute>
+ <attribute name="action">win.scan-remote</attribute>
+ </item>
</section>
<section>
<item>
@@ -64,10 +68,14 @@
<attribute name="accel"><Primary>f</attribute>
</item>
<item>
- <attribute name="label" translatable="yes">Scan F_older</attribute>
+ <attribute name="label" translatable="yes">Scan F_olderâ</attribute>
<attribute name="action">win.scan-folder</attribute>
<attribute name="accel"><Primary>o</attribute>
</item>
+ <item>
+ <attribute name="label" translatable="yes">Scan Remote Fo_lderâ</attribute>
+ <attribute name="action">win.scan-remote</attribute>
+ </item>
</section>
<section>
<item>
diff --git a/src/Makefile.am b/src/Makefile.am
index 0aa7da2..9daab6a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -27,6 +27,7 @@ baobab_SOURCES = \
baobab-cellrenderers.vala \
baobab-application.vala \
baobab-window.vala \
+ baobab-connect-server.vala \
main.vala
AM_CFLAGS = \
diff --git a/src/baobab-connect-server.vala b/src/baobab-connect-server.vala
new file mode 100644
index 0000000..31a6699
--- /dev/null
+++ b/src/baobab-connect-server.vala
@@ -0,0 +1,63 @@
+namespace Baobab {
+ class ConnectServer : Object {
+ string[] argv = {
+ "nautilus-connect-server",
+ "--print-uri"
+ };
+
+ public signal void selected(string? uri);
+
+ void on_child_watch (Pid pid, int status) {
+ Process.close_pid (pid);
+ }
+
+ bool on_out_watch (IOChannel channel, IOCondition cond) {
+ if (IOCondition.HUP in cond) {
+ selected(null);
+ return false;
+ }
+
+ string? uri = null;
+ try {
+ size_t len;
+ size_t lineend;
+ channel.read_line(out uri, out len, out lineend);
+ if (len > 0) {
+ uri = uri[0:(int)lineend];
+ }
+ } catch {
+ } finally {
+ selected(uri);
+ }
+
+ return true;
+ }
+
+ public void show () {
+
+ Pid pid;
+ int out_fd;
+
+ try {
+ Process.spawn_async_with_pipes (
+ null,
+ argv,
+ null, // envp
+ SpawnFlags.SEARCH_PATH | SpawnFlags.STDERR_TO_DEV_NULL,
+ null, // child_setup
+ out pid,
+ null, // stdin
+ out out_fd,
+ null // stderr
+ );
+ } catch (SpawnError e) {
+ warning ("Failed to run nautilus-connect-server: %s", e.message);
+ }
+
+ var out_channel = new IOChannel.unix_new (out_fd);
+ out_channel.add_watch (IOCondition.IN | IOCondition.HUP, on_out_watch);
+
+ ChildWatch.add (pid, on_child_watch);
+ }
+ }
+}
diff --git a/src/baobab-window.vala b/src/baobab-window.vala
index 3d4ff50..eb94a09 100644
--- a/src/baobab-window.vala
+++ b/src/baobab-window.vala
@@ -150,7 +150,16 @@ namespace Baobab {
}
void on_scan_remote_activate () {
- print ("sr\n");
+ var connect_server = new ConnectServer ();
+
+ connect_server.selected.connect ((uri) => {
+ if (uri != null) {
+ var dir = File.new_for_uri (uri);
+ scan_directory (dir);
+ }
+ });
+
+ connect_server.show ();
}
void on_stop_activate () {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]