From 6d6a89f4ff4b5cbcf50ceba7b451730e1e8e0f47 Mon Sep 17 00:00:00 2001 From: Alan Knowles Date: Mon, 12 May 2014 00:31:29 +0800 Subject: [PATCH] sync --- GitMonitor.vala | 3 +- GitRepo.vala | 37 +++++++++++----------- Gitlive.vala | 24 +++++++++++---- Monitor.vala | 82 ++++++++++++++++++++++++++++--------------------- StatusIcon.vala | 6 ++-- WindowLog.vala | 10 ++++-- xorg_idletime.c | 4 +-- 7 files changed, 99 insertions(+), 67 deletions(-) diff --git a/GitMonitor.vala b/GitMonitor.vala index cde0db6d..7efedfea 100644 --- a/GitMonitor.vala +++ b/GitMonitor.vala @@ -399,7 +399,8 @@ public class GitMonitor : Monitor // make sure monitoring is paused so it does not recursively pick up // deletions - // -- DO STUFF.. try { + // -- DO STUFF.. + try { repo.add(add_files); } catch(Error e) { failure += e.message; diff --git a/GitRepo.vala b/GitRepo.vala index 5ff250b6..2e7c9e33 100644 --- a/GitRepo.vala +++ b/GitRepo.vala @@ -14,23 +14,25 @@ public class GitRepo : Object public string gitdir; + public string git_working_dir; public bool debug = false; /** * index of.. matching gitpath.. */ public static int indexOf( Array repos, string gitpath) { + // make a fake object to compare against.. + var test_repo = new GitRepo(gitpath); + for(var i =0; i < repos.length; i++) { - if (repos.index(i).gitdir == gitpath) { + if (repos.index(i).gitdir == test_repo.gitdir) { return i; } } return -1; } - - - + /** * constructor: @@ -42,7 +44,7 @@ public class GitRepo : Object public GitRepo(string path) { // cal parent? - + this.git_working_dir = path; this.gitdir = path + "/.git"; if (!FileUtils.test(this.gitdir , FileTest.IS_DIR)) { this.gitdir = path; // naked... @@ -193,13 +195,10 @@ public class GitRepo : Object string[] args = { "git" }; - args += "--git-dir"; - args += this.gitdir; + //args += "--git-dir"; + //args += this.gitdir; args += "--no-pager"; - - - - + //if (this.gitdir != this.repopath) { // args += "--work-tree"; @@ -210,10 +209,11 @@ public class GitRepo : Object } //this.lastCmd = args.join(" "); - if(this.debug) { - - print( string.joinv (", ", args)); - } + //if(this.debug) { + stdout.printf( "CWD=%s\n", this.git_working_dir ); + print( string.joinv (" ", args)); + //} + string[] env = {}; string home = "HOME=" + Environment.get_home_dir() ; env += home ; @@ -223,13 +223,14 @@ public class GitRepo : Object //} - var cfg = new SpawnConfig(this.gitdir, args , env); + + var cfg = new SpawnConfig(this.git_working_dir , args , env); // may throw error... var sp = new Spawn(cfg); - - //print("GOT: " + output) + + stdout.printf( "GOT: %s\n" , sp.output); // parse output for some commands ? return sp.output; } diff --git a/Gitlive.vala b/Gitlive.vala index 6fa2e6b8..3f564eaf 100644 --- a/Gitlive.vala +++ b/Gitlive.vala @@ -1,14 +1,18 @@ /* - valac --pkg gio-2.0 --pkg posix --pkg gtk+-3.0 --pkg libnotify \ + valac --pkg gio-2.0 --pkg posix --pkg gtk+-3.0 --pkg libnotify --pkg libwnck-3.0 \ Gitlive.vala \ Monitor.vala \ GitMonitor.vala \ Spawn.vala \ StatusIcon.vala \ GitRepo.vala \ - -o /tmp/Gitlive + xorg_idletime.c \ + WindowLog.vala \ + --Xcc=-lXss \ + --Xcc=-DWNCK_I_KNOW_THIS_IS_UNSTABLE \ + -o /tmp/Gitlive && /tmp/Gitlive @@ -23,17 +27,25 @@ static int main (string[] args) { GitMonitor.gitlive = Environment.get_home_dir() + "/gitlive"; + print("GitMonitor.gitlive=" + GitMonitor.gitlive); + Notify.init("gitlive"); new StatusIconA(); + var gm = new GitMonitor(); Timeout.add_full(Priority.LOW, 500, () => { // this should start after we have shown the icon... - GitMonitor.add(GitMonitor.gitlive); - GitMonitor.start(); - - // WindowLog.start(); + print("adding GitMonitor.gitlive: " + GitMonitor.gitlive); + gm.add(GitMonitor.gitlive); + print("gm.start()"); + gm.start(); + + new WindowLog(); + + return false; + }); Gtk.main (); diff --git a/Monitor.vala b/Monitor.vala index d7086844..99cf199e 100644 --- a/Monitor.vala +++ b/Monitor.vala @@ -90,6 +90,8 @@ public class Monitor : Object */ public void add (string add) { + + print("Monitor.add: " + add); this.top.append_val(add); } /** @@ -137,7 +139,7 @@ public class Monitor : Object public void monitor(string path, int depth = 0) { - print("ADD: " + path + "\n"); + stdout.printf("ADD: (%d): %s\n", depth, path); //depth = typeof(depth) == 'number' ? depth *1 : 0; depth = depth > 0 ? depth *1 : 0; @@ -156,13 +158,7 @@ public class Monitor : Object var fm = f.monitor(FileMonitorFlags.SEND_MOVED,null); //Gio.FileMonitorFlags.SEND_MOVED - fm.changed.connect( ( fm, f_orig, of_orig, event_type) => { - //if (fn) { - this.onEvent (fm, f_orig, of_orig, event_type ) ; - // return; - //} - //this.onEvent (fm, f_orig, of_orig, event_type ) ; - }); + fm.changed.connect( this.onEvent ); this.monitors.append_val(fm); } catch (Error e) { @@ -177,34 +173,43 @@ public class Monitor : Object // this.initRepo(path); //} FileEnumerator file_enum; + var cancellable = new Cancellable (); try { file_enum = f.enumerate_children( FileAttribute.STANDARD_DISPLAY_NAME + "," + FileAttribute.STANDARD_TYPE, - 0, // FileQueryInfoFlags.NONE, - null); + FileQueryInfoFlags.NOFOLLOW_SYMLINKS, // FileQueryInfoFlags.NONE, + cancellable); } catch (Error e) { // FIXME - show error.. return; } FileInfo next_file; - while (true) { - try { - next_file = file_enum.next_file(null); - } catch (Error e) { + while (cancellable.is_cancelled () == false ) { + try { + next_file = file_enum .next_file (cancellable); + } catch(Error e) { + print(e.message); break; } + if (next_file == null) { break; } + //print("got a file " + next_file.sudo () + '?=' + Gio.FileType.DIRECTORY); - + if (next_file.get_file_type() != FileType.DIRECTORY) { next_file = null; continue; } - - if (next_file.get_file_type() ==FileType.SYMBOLIC_LINK) { + + + //stdout.printf("Monitor.monitor: got file %s : type :%u\n", + // next_file.get_display_name(), next_file.get_file_type()); + + + if (next_file.get_is_symlink()) { next_file = null; continue; } @@ -260,25 +265,19 @@ public class Monitor : Object - public void onEvent(FileMonitor fm, File f_orig, File of_orig, FileMonitorEvent event_type) + public void onEvent(File f_orig, File? of_orig, FileMonitorEvent event_type) { if (this.paused) { return; } - print("onEvent"); + // print("onEvent\n"); var f = this.realpath(f_orig); - var of = this.realpath(of_orig); - - MonitorNamePathDir src = new MonitorNamePathDir( f.get_basename(), f.get_path() , Path.get_dirname(f.get_path())); - MonitorNamePathDir dest = null; + - if (of != null) { - dest = new MonitorNamePathDir( of.get_basename(), of.get_path(), Path.get_dirname(of.get_path())); - - } + //string event_name = "UKNOWN"; @@ -297,6 +296,7 @@ public class Monitor : Object //print ("got event: " + src.toString()); try { + switch(event_type) { case FileMonitorEvent.CHANGED: src.action = "changed"; @@ -324,11 +324,22 @@ public class Monitor : Object return; case FileMonitorEvent.MOVED: // eg. chmod/chatt + + var of = this.realpath(of_orig); + var dest = new MonitorNamePathDir( + of.get_basename(), + of.get_path(), + Path.get_dirname(of.get_path()) + ); + + src.action = "moved"; dest.action = "moved"; this.onMoved(src,dest); return; - + default: + stdout.printf("event type not handled %u", event_type); + break; // rest are mount related - not really relivant.. maybe add later.. } } catch(Error e) { @@ -337,14 +348,15 @@ public class Monitor : Object } + /** override these to do stuff.. */ - public void initRepo(MonitorNamePathDir src) { } // called on startup at the top level repo dir. - public void onChanged(MonitorNamePathDir src) { } - public void onChangesDoneHint(MonitorNamePathDir src) { } - public void onDeleted(MonitorNamePathDir src) { } - public void onCreated(MonitorNamePathDir src) { } - public void onAttributeChanged(MonitorNamePathDir src) { } - public void onMoved(MonitorNamePathDir src,MonitorNamePathDir dest) { } + //public void initRepo(MonitorNamePathDir src) { } // called on startup at the top level repo dir. + public virtual void onChanged(MonitorNamePathDir src) { } + public virtual void onChangesDoneHint(MonitorNamePathDir src) { } + public virtual void onDeleted(MonitorNamePathDir src) { } + public virtual void onCreated(MonitorNamePathDir src) { } + public virtual void onAttributeChanged(MonitorNamePathDir src) { } + public virtual void onMoved(MonitorNamePathDir src,MonitorNamePathDir dest) { } } diff --git a/StatusIcon.vala b/StatusIcon.vala index c74ee5f3..cd3fac35 100644 --- a/StatusIcon.vala +++ b/StatusIcon.vala @@ -132,8 +132,8 @@ public class StatusIconA : StatusIcon { this.activate.connect( () => { statusicon.paused = true; - - //GitMonitor.GitMonitor.stop(); + GitMonitor.gitmonitor.stop(); + // this.el.label = status ? 'Resume' : 'Pause'; statusicon.set_from_stock( Gtk.Stock.MEDIA_PAUSE ); @@ -157,7 +157,7 @@ public class StatusIconA : StatusIcon { this.accel_group = null; this.activate.connect( () => { - //GitMonitor.GitMonitor.start(); + GitMonitor.gitmonitor.start(); statusicon.paused = false; // diff --git a/WindowLog.vala b/WindowLog.vala index d41d3be9..afdb2789 100644 --- a/WindowLog.vala +++ b/WindowLog.vala @@ -72,7 +72,10 @@ public class WindowLog : Object { print("/proc/%u/cmdline".printf(pid) + "\n"); if (pid > 0 ) { - FileUtils.get_contents("/proc/%u/cmdline".printf(pid), out cmd, out len); + var cf = File.new_for_path("/proc/%u/cmdline".printf(pid)); + var dis = new DataInputStream (cf.read ()); + cmd = dis.read_line (null); + } else { cmd = "UNKNOWN"; } @@ -99,6 +102,8 @@ public class WindowLog : Object { var now = new DateTime.now(new TimeZone.local()); var dir = this.outdir + now.format("/%Y/%m"); + print(dir + "\n"); + if (this.lastdir.length < 1 || this.lastdir != dir) { if (!FileUtils.test(dir, FileTest.IS_DIR)) { @@ -113,7 +118,8 @@ public class WindowLog : Object { var fname = now.format("/%d") + ".log"; var path = dir + "/" + fname; - var time = now.format("%H:%i:%s "); + var time = now.format("%H:%M:%S "); + print("time: " + time + "\n"); var f = File.new_for_path(path); FileOutputStream ios = f.append_to (FileCreateFlags.NONE); var data_out = new DataOutputStream (ios); diff --git a/xorg_idletime.c b/xorg_idletime.c index 23a73d6b..36e8e5ee 100644 --- a/xorg_idletime.c +++ b/xorg_idletime.c @@ -1,8 +1,8 @@ #include -extern int xorg_idletime() { +int xorg_idletime() { int rc = -1; - XScreenSaverInfo *info = XScreenSaverAllocInfo(); + XScreenSaverInfo *info = XScreenSaverAllocInfo(); Display *display = XOpenDisplay(NULL); if (display != NULL) { -- 2.39.2