1 ! Copyright (C) 2007 Slava Pestov.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: io.server io.sockets io strings parser byte-arrays
4 namespaces ui.clipboards ui.gadgets.panes ui.gadgets.scrollers
5 ui.gadgets.buttons ui.gadgets.tracks ui.gadgets ui.operations
6 ui.commands ui kernel splitting combinators continuations
7 sequences io.streams.duplex models ;
10 : clipboard-port 4444 ;
13 clipboard get clipboard-contents write ;
16 [ 1024 read dup ] [ ] [ drop ] unfold concat ;
19 contents clipboard get set-clipboard-contents ;
21 : clipboard-server ( -- )
22 clipboard-port internet-server "clip-server" [
24 { "GET" [ get-request ] }
25 { "SET" [ set-request ] }
34 : with-client ( addrspec quot -- )
35 >r <client> r> with-stream ; inline
37 : send-text ( text host -- )
38 clipboard-port <inet4> [ write ] with-client ;
46 : send-clipboard ( host -- )
48 "SET\n" clipboard get clipboard-contents append swap send-text ;
50 [ host? ] \ send-clipboard H{ } define-operation
52 : ask-text ( text host -- text )
53 clipboard-port <inet4>
54 [ write flush contents ] with-client ;
56 : receive-clipboard ( host -- )
59 clipboard get set-clipboard-contents ;
61 [ host? ] \ receive-clipboard H{ } define-operation
65 [ dup <host> write-object nl ] each ;
67 TUPLE: network-clipboard-tool ;
69 \ network-clipboard-tool "toolbar" f {
70 { f clipboard-server }
73 : <network-clipboard-tool> ( model -- gadget )
74 \ network-clipboard-tool construct-empty [
76 [ hosts. ] <pane-control> <scroller> 1 track,
77 ] { 0 1 } build-track ;
79 SYMBOL: network-clipboards
81 { } <model> network-clipboards set-global
83 : set-network-clipboards ( seq -- )
84 network-clipboards get set-model ;
86 : add-network-clipboard ( host -- )
87 network-clipboards get [ swap add ] change-model ;
89 : network-clipboard-tool ( -- )
91 network-clipboards get
92 <network-clipboard-tool>
93 "Network clipboard" open-window
96 MAIN: network-clipboard-tool