1
0
Fork 0
tinmop/src/gui/client/stream-frame.lisp

123 lines
6.0 KiB
Common Lisp

(in-package :client-stream-frame)
(named-readtables:in-readtable nodgui.syntax:nodgui-syntax)
(defclass stream-frame (gui:frame)
((table
:initform nil
:initarg :table
:accessor table)))
(defclass stream-table (gui-goodies:table-frame) ())
(defun resync-rows (stream-table new-rows)
(with-accessors ((tree gui-goodies:tree)
(rows gui-goodies:rows)) stream-table
(gui:treeview-delete-all tree)
(setf rows new-rows)
(loop for row in rows do
(let* ((iri (getf row :download-iri))
(stream-client-wrapper (client-main-window:find-db-stream-url iri))
(stream-status (to-s (client-main-window::status stream-client-wrapper)))
(tree-row (make-instance 'gui:tree-item
:id iri
:text iri
:column-values
(list stream-status
(to-s (getf row :octect-count)))
:index gui:+treeview-last-index+)))
(gui:treeview-insert-item tree :item tree-row)))
(gui:treeview-refit-columns-width (gui-goodies:tree stream-table))
stream-table))
(defun all-rows ()
(let ((rows (cev:enqueue-request-and-wait-results :gemini-all-stream-info
1
ev:+standard-event-priority+)))
(setf rows (sort rows
(lambda (a b) (string< (getf a :download-iri)
(getf b :download-iri)))))
rows))
(defun refresh-all-streams (stream-table)
(with-accessors ((tree gui-goodies:tree)
(rows gui-goodies:rows)) stream-table
(let ((new-rows (all-rows)))
(resync-rows stream-table new-rows)
stream-table)))
(defmethod initialize-instance :after ((object stream-table) &key &allow-other-keys)
(with-accessors ((tree gui-goodies:tree)) object
(let ((treeview (make-instance 'gui:scrolled-treeview
:master object
:pack '(:side :top :expand t :fill :both)
:columns (list (_ "Status")
(_ "Number of octects downloaded")))))
(gui:treeview-heading treeview
gui:+treeview-first-column-id+
:text (_ "Address"))
(setf tree treeview)
(refresh-all-streams object))))
(defun delete-stream-clsr (stream-table)
(with-accessors ((tree gui-goodies:tree)) stream-table
(lambda ()
(a:when-let* ((selections (gui:treeview-get-selection tree)))
(loop for selection in selections do
(let* ((url (gui:id selection))
(stream-client-wrapper (client-main-window::find-db-stream-url url)))
(when (eq (client-main-window:status stream-client-wrapper)
client-main-window:+stream-status-streaming+)
(ev:with-enqueued-process-and-unblock ()
(client-main-window:stop-steaming-stream-thread)))
(ev:with-enqueued-process-and-unblock ()
(client-main-window:remove-db-stream stream-client-wrapper)
(comm:make-request :gemini-remove-stream 1 url))
(let ((new-rows (all-rows)))
(resync-rows stream-table new-rows))))))))
(defun revive-stream-clsr (stream-table)
(with-accessors ((tree gui-goodies:tree)) stream-table
(lambda ()
(a:when-let* ((selections (gui:treeview-get-selection tree))
(selection (first selections)))
(let* ((url (gui:id selection))
(new-rows (all-rows)))
(client-main-window::open-iri url gui-goodies:*main-frame* t)
(resync-rows stream-table new-rows))))))
(defun init-frame (main-window)
(let* ((wrapper-frame (make-instance 'stream-frame :master main-window))
(table (make-instance 'stream-table :master wrapper-frame))
(buttons-frame (make-instance 'gui:frame :master wrapper-frame))
(reload-button (make-instance 'gui:button :master buttons-frame
:image icons:*refresh*
:command (lambda ()
(refresh-all-streams table))))
(delete-button (make-instance 'gui:button
:master buttons-frame
:image icons:*document-delete*
:command (delete-stream-clsr table)))
(revive-button (make-instance 'gui:button
:master buttons-frame
:image icons:*document-accept*
:command (revive-stream-clsr table)))
(close-button (make-instance 'gui:button :image icons:*cross*
:master buttons-frame
:command (lambda ()
(gui:grid-forget wrapper-frame)))))
(setf (table wrapper-frame) table)
(gui-goodies:attach-tooltips (reload-button (_ "refresh"))
(delete-button (_ "delete selected stream"))
(revive-button (_ "show selected stream"))
(close-button (_ "close")))
(gui:grid table 0 0 :sticky :news)
(gui:grid buttons-frame 1 0 :sticky :s)
(gui:grid reload-button 0 0 :sticky :s)
(gui:grid delete-button 0 1 :sticky :s)
(gui:grid revive-button 0 2 :sticky :s)
(gui:grid close-button 0 3 :sticky :s)
(gui:grid-columnconfigure wrapper-frame 0 :weight 1)
(gui:grid-rowconfigure wrapper-frame 1 :weight 1)
wrapper-frame))