#!/usr/bin/python
# -*- coding: utf-8 -*-
#   Willow-Config-Qt - Qt frontend to the WillowNG Content Filtering Web Proxy 
#   Copyright (C) 2006  Robert Day
#   Credit to Travis Watkins for the underlying library
#
#   This library is free software; you can redistribute it and/or
#   modify it under the terms of the GNU Library General Public
#   License as published by the Free Software Foundation; either
#   version 2 of the License, or (at your option) any later version.
#
#   This library 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
#   Library General Public License for more details.
#
#   You should have received a copy of the GNU Library General Public
#   License along with this library; if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

# Form implementation generated from reading ui file 'qt-config-dialog.ui'
#
# Created: Sat Aug 26 21:56:42 2006
#      by: The PyQt User Interface Compiler (pyuic) 3.15.1
#
# WARNING! All changes made in this file will be lost!


from qt import *
import dbus
import gettext
import os
import urllib2
gettext.bindtextdomain('alacarte')
gettext.textdomain('alacarte')
_ = gettext.gettext


class WillowNG_Configuration(QDialog):
    def __init__(self,parent = None,name = None,modal = 0,fl = 0):
        QDialog.__init__(self,parent,name,modal,fl)

        if not name:
            self.setName("MyDialog2")

        self.setSizeGripEnabled(1)

        MyDialog2Layout = QGridLayout(self,1,1,11,6,"MyDialog2Layout")

        self.tabWidget = QTabWidget(self,"tabWidget")

        self.TabPage = QWidget(self.tabWidget,"TabPage")

        self.checkBox1 = QCheckBox(self.TabPage,"checkBox1")
        self.checkBox1.setGeometry(QRect(31,22,300,31))

        self.textLabel4 = QLabel(self.TabPage,"textLabel4")
        self.textLabel4.setGeometry(QRect(61,52,281,31))
        self.tabWidget.insertTab(self.TabPage,QString.fromLatin1(""))

        self.Widget2 = QWidget(self.tabWidget,"Widget2")

        self.groupBox1 = QGroupBox(self.Widget2,"groupBox1")
        self.groupBox1.setGeometry(QRect(1,12,281,261))

        self.lineEdit3_2_2 = QLineEdit(self.groupBox1,"lineEdit3_2_2")
        self.lineEdit3_2_2.setGeometry(QRect(9,168,170,31))

        self.pushButton4 = QPushButton(self.groupBox1,"pushButton4")
        self.pushButton4.setGeometry(QRect(190,168,70,31))

        self.pushButton5 = QPushButton(self.groupBox1,"pushButton5")
        self.pushButton5.setGeometry(QRect(189,218,71,31))

        self.listBox2 = QListBox(self.groupBox1,"listBox2")
        self.listBox2.setGeometry(QRect(119,48,141,101))

        self.groupBox2 = QGroupBox(self.Widget2,"groupBox2")
        self.groupBox2.setGeometry(QRect(291,12,271,261))

        self.pushButton5_2 = QPushButton(self.groupBox2,"pushButton5_2")
        self.pushButton5_2.setGeometry(QRect(189,218,71,31))

        self.lineEdit3_2 = QLineEdit(self.groupBox2,"lineEdit3_2")
        self.lineEdit3_2.setGeometry(QRect(10,170,170,31))

        self.pushButton4_2 = QPushButton(self.groupBox2,"pushButton4_2")
        self.pushButton4_2.setGeometry(QRect(190,168,70,31))

        self.listBox2_2 = QListBox(self.groupBox2,"listBox2_2")
        self.listBox2_2.setGeometry(QRect(119,48,141,101))
        self.tabWidget.insertTab(self.Widget2,QString.fromLatin1(""))

        self.Widget3 = QWidget(self.tabWidget,"Widget3")

        self.textLabel1_2 = QLabel(self.Widget3,"textLabel1_2")
        self.textLabel1_2.setGeometry(QRect(50,150,231,31))

        self.textLabel3_2 = QLabel(self.Widget3,"textLabel3_2")
        self.textLabel3_2.setGeometry(QRect(10,210,67,20))

        self.textLabel3 = QLabel(self.Widget3,"textLabel3")
        self.textLabel3.setGeometry(QRect(11,82,67,20))

        self.textLabel1 = QLabel(self.Widget3,"textLabel1")
        self.textLabel1.setGeometry(QRect(51,22,231,31))

        self.pushButton8 = QPushButton(self.Widget3,"pushButton8")
        self.pushButton8.setGeometry(QRect(440,80,101,31))

        self.lineEdit1 = QLineEdit(self.Widget3,"lineEdit1")
        self.lineEdit1.setGeometry(QRect(81,80,330,30))

        self.lineEdit1_2 = QLineEdit(self.Widget3,"lineEdit1_2")
        self.lineEdit1_2.setGeometry(QRect(80,208,330,30))

        self.pushButton8_2 = QPushButton(self.Widget3,"pushButton8_2")
        self.pushButton8_2.setGeometry(QRect(439,208,101,31))
        self.tabWidget.insertTab(self.Widget3,QString.fromLatin1(""))

        MyDialog2Layout.addWidget(self.tabWidget,0,1)

        Layout1 = QHBoxLayout(None,0,6,"Layout1")
        Horizontal_Spacing2 = QSpacerItem(20,20,QSizePolicy.Expanding,QSizePolicy.Minimum)
        Layout1.addItem(Horizontal_Spacing2)

        self.buttonOk = QPushButton(self,"buttonOk")
        self.buttonOk.setAutoDefault(1)
        self.buttonOk.setDefault(1)
        Layout1.addWidget(self.buttonOk)

        self.buttonCancel = QPushButton(self,"buttonCancel")
        self.buttonCancel.setAutoDefault(1)
        Layout1.addWidget(self.buttonCancel)

        MyDialog2Layout.addMultiCellLayout(Layout1,1,1,0,1)

        self.languageChange()

        self.resize(QSize(602,368).expandedTo(self.minimumSizeHint()))
        self.clearWState(Qt.WState_Polished)

        self.connect(self.pushButton4_2,SIGNAL("clicked()"),self.pushButton4_2_clicked)
        self.connect(self.buttonCancel,SIGNAL("clicked()"),self.reject)
        self.connect(self.pushButton5,SIGNAL("clicked()"),self.pushButton5_clicked)
        self.connect(self.pushButton4,SIGNAL("clicked()"),self.pushButton4_clicked)
        self.connect(self.pushButton5_2,SIGNAL("clicked()"),self.pushButton5_2_clicked)
        self.connect(self.pushButton8,SIGNAL("clicked()"),self.pushButton8_clicked)
        self.connect(self.pushButton8_2,SIGNAL("clicked()"),self.pushButton8_2_clicked)
        self.connect(self.buttonOk,SIGNAL("clicked()"),self.accept)

    bus = dbus.SystemBus()
    remote_object = bus.get_object('com.ubuntu.WillowNG', '/com/ubuntu/WillowNG')
    self.iface = dbus.Interface(remote_object, 'com.ubuntu.WillowNG')

    domains = self.iface.getDomains()
    if domains == None:
        return
    for domain in domains:
        if domain[0] == 'bad':
            QListBoxText(self.listBox2_2,QString(domain[1]))
        elif domain[0] == 'good':
            QListBoxText(self.listBox2,QString(domain[1]))


    def languageChange(self):
        self.setCaption(self.__tr("WillowNG Configuration"))
        self.checkBox1.setText(self.__tr("Turn Content Filtering On"))
        self.textLabel4.setText(self.__tr("<i>Proxy will run on port 8563</i>"))
        self.tabWidget.changeTab(self.TabPage,self.__tr("General"))
        self.groupBox1.setTitle(self.__tr("Good Domains"))
        self.pushButton4.setText(self.__tr("Add"))
        self.pushButton5.setText(self.__tr("Remove"))
        self.groupBox2.setTitle(self.__tr("Bad Domains"))
        self.pushButton5_2.setText(self.__tr("Remove"))
        self.pushButton4_2.setText(self.__tr("Add"))
        self.tabWidget.changeTab(self.Widget2,self.__tr("Domain Filter"))
        self.textLabel1_2.setText(self.__tr("Bad Content"))
        self.textLabel3_2.setText(self.__tr("URL:"))
        self.textLabel3.setText(self.__tr("URL:"))
        self.textLabel1.setText(self.__tr("Good Content"))
        self.pushButton8.setText(self.__tr("Submit"))
        self.pushButton8_2.setText(self.__tr("Submit"))
        self.tabWidget.changeTab(self.Widget3,self.__tr("Content Filter"))
        self.buttonOk.setText(self.__tr("&OK"))
        self.buttonOk.setAccel(QString.null)
        self.buttonCancel.setText(self.__tr("&Cancel"))
        self.buttonCancel.setAccel(QString.null)


    def pushButton4_clicked(self):
        self.iface.domainGood(self.lineEdit3_2_2.text().ascii())
        newitem = QListBoxText(self.listBox2,self.lineEdit3_2_2.text())
        self.lineEdit3_2_2.setText(QString(''))
        
        

    def pushButton5_clicked(self):
        self.iface.removeDomain(self.listBox2.text(self.listBox2.currentItem()).ascii())
        self.listBox2.removeItem(self.listBox2.currentItem())
        
        

    def pushButton4_2_clicked(self):
        self.iface.domainBad(self.lineEdit3_2.text().ascii())
        newitem = QListBoxText(self.listBox2_2,self.lineEdit3_2.text())
        self.lineEdit3_2.setText(QString(''))
        
        

    def pushButton5_2_clicked(self):
        self.iface.removeDomain(self.listBox2_2.text(self.listBox2_2.currentItem()).ascii())
        self.listBox2.removeItem(self.listBox2_2.currentItem())
        
        

    def pushButton8_clicked(self):
        self.iface.trainGood(self.lineEdit1.text().ascii())
        self.lineEdit1.setText(QString(''))
        

    def pushButton8_2_clicked(self):
        self.iface.trainBad(self.lineEdit1_2.text().ascii())
        self.lineEdit1_2.setText(QString(''))
        

    def changeDomainFilterHTML(self):
        print "WillowNG_Configuration.changeDomainFilterHTML(): Not implemented yet"

    def changeContentFilterHTML(self):
        print "WillowNG_Configuration.changeContentFilterHTML(): Not implemented yet"

    def __tr(self,s,c = None):
        return qApp.translate("WillowNG_Configuration",s,c)
app = QApplication([])
kdeconfig = WillowNG_Configuration()
app.setMainWidget(kdeconfig)
kdeconfig.show()
app.exec_loop()
