#!/usr/bin/env python

# reportbug-ng - Report a bug in Debian's BTS.
# Copyright (C) 2007  Bastian Venthur
#
# 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) any later version.
#
# 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, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import gettext
gettext.install('reportbug-ng', '/usr/share/locale', unicode=1)

import sys, os
sys.path = sys.path + [os.curdir, '/usr/share/reportbug-ng']

from ui.MyMainWindow import MyMainWindow

import signal
import qt
import sys
import os
from optparse import OptionParser

import lib.ReportbugNG
from lib.Settings import Settings

CONFIGFILE = os.path.expanduser("~/.reportbug-ng")


if __name__ == "__main__":
    # Get Options
    description = """\
Report a bug in Debian's BTS. The optional paremter QUERY behaves exactly like the query inside the program. \
Supported queries are: packagename, bugnumber, maintainer@foo.bar, src:package, from:submitter@foo.bar, severity:foo and tag:bar."""
    usage = "%prog [Options] [Query]"
    version = """
Copyright (C) 2007 Bastian Venthur <venthur at debian org>

Homepage: http://reportbug-ng.alioth.debian.org

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) any later version.
"""
    parser = OptionParser(usage=usage, version=version, description=description)
    
    #
    #parser.set_defaults(interface="html")
    #parser.add_option("-i", "--interface", type="choice", choices=["soap", "html"], dest="interface",
    #	help="which interface to use to query the BTS [default: html]", metavar="(html|soap)")
    
    (options, args) = parser.parse_args()

    settings = Settings(CONFIGFILE)
    settings.load()

    app = qt.QApplication(sys.argv)
    app.connect(app, qt.SIGNAL("lastWindowClosed()"), app, qt.SLOT("quit()"))
    
    mw = MyMainWindow(settings)
    app.setMainWidget(mw)
    mw.show()

    signal.signal(signal.SIGINT, signal.SIG_DFL) 
    app.exec_loop()
    
    settings.save()    
   
    