[baobab/wip/vala: 40/53] Start to implement "Scan remote dir"
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [baobab/wip/vala: 40/53] Start to implement "Scan remote dir"
- Date: Thu, 5 Apr 2012 22:04:55 +0000 (UTC)
commit c3d785eeed67e4b546dbcdae677c55f0a3f2d196
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 | 82 ++++++++++++++++++++++++++++++++++++++++
src/baobab-window.vala | 11 +++++-
4 files changed, 103 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..14d7a76
--- /dev/null
+++ b/src/baobab-connect-server.vala
@@ -0,0 +1,82 @@
+/* Baobab - disk usage analyzer
+ *
+ * Copyright (C) 2012 Paolo Borelli <pborelli gnome org>
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+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 2c17d58..8701e5e 100644
--- a/src/baobab-window.vala
+++ b/src/baobab-window.vala
@@ -170,7 +170,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]