File indexing completed on 2024-05-05 04:49:36

0001 #!/usr/bin/env ruby
0002 #
0003 #
0004 # Form implementation generated from reading ui file 'selector.ui'
0005 #
0006 # Created: Fri Dec 2 23:40:46 2005
0007 #      by: The QtRuby User Interface Compiler (rbuic)
0008 #
0009 # WARNING! All changes made in this file will be lost!
0010 #
0011 # Ruby script for generic amarok database scripts
0012 # (c) 2005 Seb Ruiz <me@sebruiz.net>
0013 # Released under the GPL v2 license
0014 
0015 begin
0016     require 'Korundum'
0017 rescue LoadError
0018     error = 'Korundum (KDE bindings for ruby) from kdebindings v3.4 is required for this script.'
0019     system("dcop", "amarok", "playlist", "popupMessage", "DatabaseScripts: #{error}")
0020     exit
0021 end
0022 
0023 class DatabaseScriptChooser < Qt::Dialog
0024 
0025     attr_reader :m_optionCombo
0026     attr_reader :m_saveText
0027     attr_reader :m_saveDir
0028     attr_reader :m_okayButton
0029 
0030     slots 'optionChanged(int)', 'textChanged(const QString &)', 'accept()', 'cancel()'
0031 
0032     def initialize(parent = nil, name = nil, modal = false, fl = 0)
0033         super
0034 
0035         if name.nil?
0036             setName("Database Script Chooser")
0037         end
0038 
0039         @Form1Layout = Qt::GridLayout.new(self, 1, 1, 2, 2, 'Form1Layout')
0040 
0041         @layout3 = Qt::VBoxLayout.new(nil, 0, 2, 'layout3')
0042 
0043         @m_optionCombo = Qt::ComboBox.new(false, self, "m_optionCombo")
0044         @layout3.addWidget(@m_optionCombo)
0045 
0046         @layout1 = Qt::HBoxLayout.new(nil, 0, 2, 'layout1')
0047 
0048         @m_saveText = Qt::Label.new(self, "m_saveText")
0049         @layout1.addWidget(@m_saveText)
0050 
0051         @m_saveDir = KDE::URLRequester.new(self, "m_saveDir")
0052         @m_saveDir.setMode( KDE::File::Directory | KDE::File::ExistingOnly );
0053         @m_saveDir.setURL( ENV["HOME"] )
0054 
0055         @layout1.addWidget(@m_saveDir)
0056         @layout3.addLayout(@layout1)
0057         @spacer1 = Qt::SpacerItem.new(20, 21, Qt::SizePolicy::Minimum, Qt::SizePolicy::Expanding)
0058         @layout3.addItem(@spacer1)
0059 
0060         @layout2 = Qt::HBoxLayout.new(nil, 0, 2, 'layout2')
0061 
0062         @m_cancelButton = Qt::PushButton.new(self, "@m_cancelButton")
0063         @layout2.addWidget(@m_cancelButton)
0064 
0065         @spacer2 = Qt::SpacerItem.new(61, 20, Qt::SizePolicy::Expanding, Qt::SizePolicy::Minimum)
0066         @layout2.addItem(@spacer2)
0067 
0068         @m_okayButton = Qt::PushButton.new(self, "m_okayButton")
0069         @layout2.addWidget(@m_okayButton)
0070         @layout3.addLayout(@layout2)
0071 
0072         connect( @m_optionCombo,  SIGNAL( "activated(int)" ), self, SLOT( "optionChanged(int)" ) );
0073         connect( @m_okayButton,   SIGNAL( "clicked()" ),      self, SLOT( "accept()" ) )
0074         connect( @m_cancelButton, SIGNAL( "clicked()" ),      self, SLOT( "cancel()" ) )
0075 
0076         connect( @m_saveDir, SIGNAL( "textChanged(const QString &)" ),
0077                  self,       SLOT( "textChanged(const QString &)" ) );
0078 
0079         @Form1Layout.addLayout(@layout3, 0, 0)
0080         languageChange()
0081 
0082         resize( Qt::Size.new(356, 137).expandedTo(minimumSizeHint()) )
0083         clearWState( WState_Polished )
0084     end
0085 
0086     def optionChanged( i )
0087         @m_saveDir.setEnabled( i == 0 )
0088         @m_saveText.setEnabled( i == 0 )
0089     end
0090 
0091     def textChanged(s)
0092         @m_okayButton.setEnabled( !s.empty?() )
0093     end
0094 
0095     def accept()
0096         arg = ""
0097         case @m_optionCombo.currentItem()
0098             when 0 # Backup
0099                 filename = File.dirname( File.expand_path( __FILE__ ) ) + "/backupDatabase.rb"
0100                 arg      = @m_saveDir.url()
0101 
0102             when 1 # Optimise
0103                 filename = File.dirname( File.expand_path( __FILE__ ) ) + "/staleStatistics.rb"
0104         end
0105 
0106         system("ruby", filename, arg)
0107 
0108         done( 0 )
0109     end
0110 
0111     def cancel()
0112         done( 0 )
0113     end
0114 
0115 
0116     #
0117     #  Sets the strings of the subwidgets using the current
0118     #  language.
0119     #
0120     def languageChange()
0121         setCaption( trUtf8("Database Scripts") )
0122         @m_optionCombo.clear()
0123 
0124         # add combo box items
0125         @m_optionCombo.insertItem( trUtf8("Backup Database") )
0126         @m_optionCombo.insertItem( trUtf8("Optimise Database") )
0127 
0128         @m_saveText.setText( trUtf8("Save location:") )
0129         @m_cancelButton.setText( trUtf8("Cancel") )
0130         @m_okayButton.setText( trUtf8("Go!") )
0131     end
0132     protected :languageChange
0133 
0134 
0135 end
0136 
0137 if $0 == __FILE__
0138     about = KDE::AboutData.new("databaseScriptChooser", "DatabaseScriptChooser", "0.1")
0139     KDE::CmdLineArgs.init(ARGV, about)
0140     a = KDE::Application.new
0141     w = DatabaseScriptChooser.new
0142     a.mainWidget = w
0143     w.show
0144     a.exec
0145 end