Debian Codegraph @

lib/ninix/dll/textcopy.rb

raw
1 # -*- coding: utf-8 -*-
2 #
3 # textcopy.rb - a TEXTCOPY compatible Saori module for ninix
4 # Copyright (C) 2002-2019 by Shyouzou Sugitani <[email protected]>
5 # Copyright (C) 2002, 2003 by MATSUMURA Namihiko <[email protected]>
6 #
7 # This program is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License (version 2) as
9 # published by the Free Software Foundation. It is distributed in the
10 # hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
11 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 # PURPOSE. See the GNU General Public License for more details.
13 #
14
15 require "gtk4"
16
17 require_relative "../dll"
18
19
20 module Textcopy
21
22 class Saori < DLL::SAORI
23
24 def initialize
25 super
26 @clipboard = nil
27 end
28
29 def setup
30 @clipboard = Gtk::Clipboard.get('PRIMARY')
31 1
32 end
33
34 def finalize
35 @clipboard = nil
36 1
37 end
38
39 def execute(argument)
40 return RESPONSE[400] if argument.nil? or argument.empty? or @clipboard.nil?
41 text = argument[0]
42 @clipboard.set_text(text)
43 if argument.length >= 2 and not argument[1].zero?
44 "SAORI/1.0 200 OK\r\n" \
45 "Result: " \
46 "#{text.encode(@charset, :invalid => :replace, :undef => :replace)}" \
47 "\r\n\r\n"
48 else
49 RESPONSE[204]
50 end
51 end
52 end
53 end