#!/usr/bin/python
# qdialogdoulbefreetest.py
# ------------------------------
# begin     : Sun Mar 12 2006
# copyright : (C) Simon Edwards
# email     : simon@simonzone.com
# GPL

from qt import *
from kdeui import *
from kdecore import *
import sys

###########################################################################
class UserConfigApp(KDialogBase):
    def __init__(self,parent=None,name=None):
        KDialogBase.__init__(self, KJanusWidget.Tabbed, # Tabbed or Plain, does not matter.
            QString("User Accounts and Groups"),
            KDialogBase.Close, KDialogBase.Close)

        usershbox = self.addHBoxPage("A tab")

        self.modifybutton = KPushButton(i18n("Show dialog"),usershbox)
        self.connect(self.modifybutton,SIGNAL("clicked()"),self.slotModifyClicked)
        
        self.usereditdialog = UserEditDialog(self)
        

    def slotModifyClicked(self):

        print "Pre exec_loop() object tree --------------------------------------------"
        self.dumpObjectTree()
        self.usereditdialog.exec_loop()
        
        # Uncomment this line to work around the bug.
        self.removeChild(self.usereditdialog)
        
        print "Post exec_loop() object tree -------------------------------------------"
        self.dumpObjectTree()

    def __del__(self):
        print "UserConfigApp KDialogBase __del__ ",repr(self)

###########################################################################
class UserEditDialog(QDialog):
    def __init__(self,parent):
        QDialog.__init__(self, parent, "User Account", True)
        
    def __del__(self):
        print "UserEditDialog QDialog __del__!",repr(self)
        
##########################################################################
def main():
    global kapp

    aboutdata = KAboutData("dialogtest","qdialogdoublefree","1.0",str(i18n("Double free test")), KAboutData.License_GPL, "Copyright (C) 2006 Simon Edwards")

    KCmdLineArgs.init(sys.argv,aboutdata)

    kapp = KApplication()
    userconfigapp = UserConfigApp()
    userconfigapp.exec_loop()
main()
