DeleteDialog.py :  » Network » Luma » luma-2.4 » lib » luma » base » utils » gui » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Network » Luma 
Luma » luma 2.4 » lib » luma » base » utils » gui » DeleteDialog.py
# -*- coding: utf-8 -*-

###########################################################################
#    Copyright (C) 2005 by Wido Depping                                      
#    <widod@users.sourceforge.net>                                                             
#
# Copyright: See COPYING file that comes with this distribution
#
###########################################################################

from qt import *
import os.path

from base.utils.gui.DeleteDialogDesign import DeleteDialogDesign
from base.backend.LumaConnection import LumaConnection
import environment


class DeleteDialog(DeleteDialogDesign):

    def __init__(self,parent = None,name = None,modal = 0,fl = 0):
        DeleteDialogDesign.__init__(self,parent,name,modal,fl)
        
        self.iconPath = os.path.join(environment.lumaInstallationPrefix, "share", "luma", "icons")
        self.deleteIcon = QPixmap(os.path.join(self.iconPath, "trashcan.png"))
        self.iconLabel.setPixmap(self.deleteIcon)
        
        self.okIcon = QPixmap(os.path.join(self.iconPath, "ok.png"))
        self.failureIcon = QPixmap(os.path.join(self.iconPath, "no.png"))
        
        self.itemView.setColumnText(0, "")
        self.itemView.setColumnWidth(0, 32)
        self.itemView.setSorting(-1, False) 
        
        # Dictionary of items which should be deleted
        # Key is the dn; value is as list with the SmartDataObject 
        # and the QListViewItem
        self.deleteDictionary = {}
        
        # List of entries which have been deleted
        self.deletedEntries = []
        
        
        
###############################################################################

    def initData(self, tmpList):
        """ Initializaion of the dialog with data.
        """
        
        for x in tmpList[::-1]:
            prettyDN = x.getPrettyDN()
            tmpItem = QListViewItem(self.itemView)
            tmpItem.setText(1, prettyDN)
            self.deleteDictionary[prettyDN] = [x, tmpItem]
            
###############################################################################

    def removeItems(self):
        """ Remove the currently selected items from the list of items to 
        be deleted.
        """
        
        selectedList = []
        
        listIterator = QListViewItemIterator(self.itemView)
        while listIterator.current():
            item = listIterator.current()
            if item.isSelected():
                selectedList.append(item)
            listIterator += 1
        
        for x in selectedList:
            name = unicode(x.text(1))
            self.itemView.takeItem(self.deleteDictionary[name][1])
            del self.deleteDictionary[name]
            
###############################################################################

    def deleteItems(self):
        """ Delete items from server and display statusmessages.
        """
        
        environment.setBusy(True)
        
        connectionObject = None
        currentServerMeta = None
        connected = False
        
        deleteList = map(lambda x: self.deleteDictionary[x][0], self.deleteDictionary.keys())
        deleteList.sort()
        
        allDeleted = True
        
        for x in deleteList[::-1]:
            prettyDN = x.getPrettyDN()
            normalDN = x.getDN()
            
            if connectionObject == None:
                currentServerMeta = x.getServerMeta()
                connectionObject = LumaConnection(currentServerMeta)
                
            tmpServerMeta = x.getServerMeta()
            if not (tmpServerMeta.name == currentServerMeta.name):
                if connected:
                    connectionObject.unbind()
                    
                currentServerMeta = tmpServerMeta
                connectionObject = LumaConnection(currentServerMeta)
                
            if not connected:
                success, exceptionObject = connectionObject.bind()
                self.displayItemStatus(self.deleteDictionary[prettyDN][1], success, exceptionObject)
                
                if not success:
                    allDeleted = False
                    continue
                    
            success, exceptionObject = connectionObject.delete(normalDN)
            self.displayItemStatus(self.deleteDictionary[prettyDN][1], success, exceptionObject)
            
            if success:
                self.deletedEntries.append(normalDN)
            else:
                allDeleted = False
                
        environment.setBusy(False)
        
        if allDeleted:
            self.accept()
            
###############################################################################

    def displayItemStatus(self, listItem, success, exceptionObject):
        if success:
            listItem.setPixmap(0, self.okIcon)
            listItem.setText(2, self.trUtf8("Item deleted successfully."))
        else:
            listItem.setPixmap(0, self.failureIcon)
            listItem.setText(2, str(exceptionObject))
        
###############################################################################

    def getDeletedItems(self):
        """ Returns a list of items which have been deleted.
        """
        
        return self.deletedEntries
        
        
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
        
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.