Only subscribe to wanted notifications.
[doldaconnect.git] / lib / guile / autodl
index 3d2a340..281c236 100755 (executable)
@@ -62,7 +62,9 @@
 
 (define (wanttosearch)
   (> (- (current-time) lastsearch)
 
 (define (wanttosearch)
   (> (- (current-time) lastsearch)
-     (if (> (length trans) 0) 300 60))
+     (if (eq? (cdr (assoc 'search-mode session)) 'wait)
+        7200
+        (if (> (length trans) 0) 300 60)))
   )
 
 (define defspeed '())
   )
 
 (define defspeed '())
                     (cons 'realsr info-numreal)
                     (cons 'totalsr info-numtotal)
                     (cons 'lastsrch lastsearch)
                     (cons 'realsr info-numreal)
                     (cons 'totalsr info-numtotal)
                     (cons 'lastsrch lastsearch)
-                    (cons 'srcheta info-searcheta))
+                    (cons 'srcheta info-searcheta)
+                    (cons 'srchmode (cdr (assoc 'search-mode session))))
               op)
        (newline op)
        (close-port op))))
               op)
        (newline op)
        (close-port op))))
   )
 
 (define (handlesr filename fnet peer size slots resptime hash)
   )
 
 (define (handlesr filename fnet peer size slots resptime hash)
+  (if (eq? (cdr (assoc 'search-mode session)) 'wait)
+      (begin (set-cdr! (assoc 'search-mode session) 'normal)
+            (logf "reverting to normal mode")))
   (let ((cl (or (assoc size sr)
                (let ((newp (cons size '()))) (set! sr (append sr (list newp))) newp)))
        (newsr (list
   (let ((cl (or (assoc size sr)
                (let ((newp (cons size '()))) (set! sr (append sr (list newp))) newp)))
        (newsr (list
 
 (define (autodl-main args)
   (let ((dc-server #f) (done #f) (retval 0))
 
 (define (autodl-main args)
   (let ((dc-server #f) (done #f) (retval 0))
-    (let ((getopt (make-getopt (cdr args) "hs:S:e:p:t:a:I:")) (arg #f))
+    (let ((getopt (make-getopt (cdr args) "whs:S:e:p:t:a:I:")) (arg #f))
       (do ((arg (getopt) (getopt))) ((not (and (pair? arg) (char? (car arg)))) (set! args arg))
        (cond ((eq? (car arg) #\h)
               (begin (display "usage: autodl [-s server] -S sessfile\n" (current-error-port))
       (do ((arg (getopt) (getopt))) ((not (and (pair? arg) (char? (car arg)))) (set! args arg))
        (cond ((eq? (car arg) #\h)
               (begin (display "usage: autodl [-s server] -S sessfile\n" (current-error-port))
-                     (display "       autodl [-s server] -e search-expression [-p prio] [-t tag] [-a userarg]\n" (current-error-port))
+                     (display "       autodl [-w] [-s server] -e search-expression [-p prio] [-t tag] [-a userarg]\n" (current-error-port))
                      (display "       autodl [-s server]\n" (current-error-port))
                      (display "       autodl -h\n" (current-error-port))
                      (exit 0)))
                      (display "       autodl [-s server]\n" (current-error-port))
                      (display "       autodl -h\n" (current-error-port))
                      (exit 0)))
                     (set! session (cons (cons 'info-file (cdr arg)) session)))))
              ((eq? (car arg) #\e)
               (set! session (cons (cons 'sexpr (dc-lexsexpr (cdr arg))) session)))
                     (set! session (cons (cons 'info-file (cdr arg)) session)))))
              ((eq? (car arg) #\e)
               (set! session (cons (cons 'sexpr (dc-lexsexpr (cdr arg))) session)))
+             ((eq? (car arg) #\w)
+              (set! session (cons '(search-mode . wait) session)))
              )
        )
       )
              )
        )
       )
        (set! session (cons '(prio . 10) session)))
     (if (not (assoc 'maxtrans session))
        (set! session (cons '(maxtrans . 1) session)))
        (set! session (cons '(prio . 10) session)))
     (if (not (assoc 'maxtrans session))
        (set! session (cons '(maxtrans . 1) session)))
+    (if (not (assoc 'search-mode session))
+       (set! session (cons '(search-mode . normal) session)))
     (if (not (validate-session session)) (begin (display "Invalid session!\n" (current-error-port)) (exit 1)))
     (if (not dc-server) (set! dc-server (getenv "DCSERVER")))
     (if (not dc-server) (set! dc-server "localhost"))
     (if (not (validate-session session)) (begin (display "Invalid session!\n" (current-error-port)) (exit 1)))
     (if (not dc-server) (set! dc-server (getenv "DCSERVER")))
     (if (not dc-server) (set! dc-server "localhost"))
           (lambda (key . args)
             (logf (string-append "could not connect to server: " (apply format #f (cadr args) (caddr args))))
             (exit 2)))
           (lambda (key . args)
             (logf (string-append "could not connect to server: " (apply format #f (cadr args) (caddr args))))
             (exit 2)))
-    (dc-ecmd-assert 200 "notify" "all" "on")
+    (dc-ecmd-assert 200 "notify" "trans:act" "on" "trans:prog" "on" "srch:act" "on")
     (for-each (lambda (sig) (sigaction sig (lambda (sig) (throw 'sig sig)))) (list SIGINT SIGTERM SIGHUP))
     (catch 'sig
           (lambda ()
     (for-each (lambda (sig) (sigaction sig (lambda (sig) (throw 'sig sig)))) (list SIGINT SIGTERM SIGHUP))
     (catch 'sig
           (lambda ()
                                           (let ((ires (dc-intresp resp)))
                                             (if (and ires (= (car ires) srchid))
                                                 (begin (set! info-searcheta (+ (current-time) (cadr ires)))
                                           (let ((ires (dc-intresp resp)))
                                             (if (and ires (= (car ires) srchid))
                                                 (begin (set! info-searcheta (+ (current-time) (cadr ires)))
-                                                       (logf (string-append "search rescheduled to T+" (number->string (cadr ires))))))))
+                                                       (logf (string-append "search rescheduled to T+" (number->string (cadr ires))))
+                                                       (write-info-file)))))
                                          ((621) ; Search committed
                                           (let ((ires (dc-intresp resp)))
                                             (if (and ires (= (car ires) srchid))
                                                 (begin (logf "search committed")
                                                        (set! info-searcheta 0)
                                          ((621) ; Search committed
                                           (let ((ires (dc-intresp resp)))
                                             (if (and ires (= (car ires) srchid))
                                                 (begin (logf "search committed")
                                                        (set! info-searcheta 0)
-                                                       (set! lastsearch (current-time))))))
+                                                       (set! lastsearch (current-time))
+                                                       (write-info-file)))))
                                          ((622) ; Search result
                                           (let ((ires (list->vector (dc-intresp resp))))
                                             (if (and ires (= (vector-ref ires 0) srchid)) (apply handlesr (map (lambda (n) (vector-ref ires n)) '(1 2 3 4 5 7 8))))))
                                          ((622) ; Search result
                                           (let ((ires (list->vector (dc-intresp resp))))
                                             (if (and ires (= (vector-ref ires 0) srchid)) (apply handlesr (map (lambda (n) (vector-ref ires n)) '(1 2 3 4 5 7 8))))))