Implemented copy, cut and paste frame
[dashstudio.git] / dashdctl.rb
blobe193182556d43d15a08d8ca75b9276768d3eff5b
2 print "Loading... "
3 $stdout.flush
5 has_qt4 = false
6 begin
7 has_qt4 = require 'Qt4'
8 rescue LoadError
9     puts "[FAILED]"
10     puts "ruby qt4 is required!"
11     exit -1
12 end
14 class Manager
15     def self.restart_server(host, port)
16         begin
17             settings = Qt::Settings.new("dashd", "dashd")
18             settings.beginGroup("Connection")
19             
20             settings.setValue("host", Qt::Variant.new(host) )
21             settings.setValue("port", Qt::Variant.new(port) )
22             
23             settings.endGroup()
24             
25             settings.sync
26             settings.dispose
27         end
28         
29         `pkill dashd` # Restart the server
30     end
31     
32     def self.server_port
33         server = nil
34         port = nil
35         begin
36             settings = Qt::Settings.new("dashd", "dashd");
37             settings.beginGroup("Connection")
38             
39             server = settings.value("host").toString
40             port = settings.value("port").toInt
41             
42             settings.endGroup()
43         end
44         
45         [server, port]
46     end
47 end
49 if not has_qt4
50     puts "[OK]"
51     
52     
53 end
55 class Control < Qt::Frame
56     slots 'restart()'
57     def initialize
58         super
59         @layout = Qt::VBoxLayout.new(self)
60         
61         server, port = Manager.server_port
62         
63         @grid = Qt::GridLayout.new
64         
65         @host = Qt::LineEdit.new
66         @host.setText server.to_s
67         
68         @port = Qt::SpinBox.new
69         @port.setMaximum(65000)
70         @port.setValue port.to_i
71         
72         @grid.addWidget(Qt::Label.new(tr("Host")), 0, 0)
73         @grid.addWidget(@host, 0, 1)
74         
75         @grid.addWidget(Qt::Label.new(tr("Port")), 1, 0)
76         @grid.addWidget(@port, 1, 1)
77         
78         
79         @layout.addLayout @grid
80         
81         @buttons = Qt::HBoxLayout.new
82         restart = Qt::PushButton.new(tr("Restart"))
83         connect(restart, SIGNAL('clicked()'), self, SLOT('restart()'))
84         @buttons.addWidget(restart)
85         
86         @layout.addLayout @buttons
87     end
88     
89     def restart
90         Manager.restart_server(@host.text, @port.value)
91     end
92 end
94 class MainWindow < Qt::MainWindow
95     def initialize
96         super
97         
98         @control = Control.new
99         setCentralWidget(@control)
100     end
104 app = Qt::Application.new(ARGV)
106 mw = MainWindow.new
107 mw.show
109 puts "[OK]"
110 app.exec