#!/usr/bin/env ruby
#
# Copyright © 2009 Harald Sitter <apachelogger@ubuntu.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of
# the License or (at your option) version 3 or any later version
# accepted by the membership of KDE e.V. (or its successor approved
# by the membership of KDE e.V.), which shall act as a proxy
# defined in Section 14 of version 3 of the license.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

$KCODE='u'
require 'korundum4'
require 'kubuntu-firefox-installer-ui'

class KubuntuFirefoxInstaller < Qt::MainWindow
    slots :invoke_install

    def initialize(parent=nil)
        super parent

        appname = i18n("Mozilla Firefox Installer")

        ui = Ui_MainWindow.new
        ui.setupUi(self)

        icon = KDE::Icon.new("firefox-installer")
        setWindowIcon icon

        setWindowTitle appname

        ui.welcome_heading_label.text = "<h1>" + appname + "</h1>"

#         ui.image_label.margin = 50
        ui.image_label.setPixmap(icon.pixmap(128,128))

        ui.install_button.icon = KDE::Icon.new("list-add")
        ui.install_button.iconSize = 16
        ui.install_button.text = i18n("Install")
        connect(ui.install_button, SIGNAL(:released), self, SLOT(:invoke_install))

        ui.quit_button.icon = KDE::Icon.new("application-exit")
        ui.quit_button.iconSize = 16
        ui.quit_button.text = i18n("Exit")

#         ui.text_label.margin = 20
        ui.text_label.wordWrap = true
        ui.text_label.alignment = Qt::AlignTop|Qt::AlignLeading|Qt::AlignLeft
        ui.text_label.text = i18n("Mozilla Firefox is the popular, award-winning web browser used by millions for it's simplicity, security features and many available addons.")

        self.setWindowState Qt::WindowFullScreen

        def invoke_install
            exec("kdesudo -c 'kubuntu-firefox-installer -i'")
        end
    end
end

if ARGV[0] == "-i"
    exec("install-package --install firefox")
end
cr = "© "
about = KDE::AboutData.new("kubuntu-firefox-installer", "", KDE.ki18n("Mozilla Firefox Installer"), "0.4", KDE.ki18n("Mozilla Firefox Installer"),
                           KDE::AboutData::License_GPL, KDE.ki18n(cr+"2009 Harald Sitter <apachelogger@ubuntu.com>"))
about.setBugAddress Qt::ByteArray.new("Launchpad")
about.addAuthor(KDE.ki18n("Harald Sitter"), KDE.ki18n("Maintainer"), "apachelogger@ubuntu.com")

KDE::CmdLineArgs.init(ARGV, about)

$kapp = KDE::Application.new
$kapp.setStyleSheet(File.new("/usr/share/kubuntu-firefox-installer/style/style.qss").read)

dialog = KubuntuFirefoxInstaller.new
dialog.show

$kapp.exec
