Esempio n. 1
0
    def __list_items(self, root=None):
        if not root:
            root = QtGui.QTreeWidgetItem(self.treeComputers)
            root.dn = self.directory.directory_domain
            root.name = root.dn.split(",")[0].split("=")[1]
            root.folder = True
            root.setText(0, self.directory.get_name())
            root.setChildIndicatorPolicy(QtGui.QTreeWidgetItem.ShowIndicator)
            root.setIcon(0, wrappers.Icon("folder48"))
            return

        dn = root.dn

        results = self.directory.search(dn, ["o", "cn"], "one")
        fancy = len(results) < 100
        for dn, attrs in results:
            name = dn.split(",")[0].split("=")[1]
            label = name
            folder = dn.startswith("dc=")
            user = dn.startswith("uid=")

            if folder and "o" in attrs:
                label = attrs["o"][0]

            item = QtGui.QTreeWidgetItem(root)
            item.dn = dn
            item.name = name
            item.folder = folder
            item.setText(0, label)

            self.nodes_dn[dn] = item

            if fancy:
                if folder:
                    item.setChildIndicatorPolicy(
                        QtGui.QTreeWidgetItem.ShowIndicator)
                    item.setIcon(0, wrappers.Icon("folder48"))
                elif user:
                    item.setIcon(0, wrappers.Icon("user48"))
                else:
                    self.nodes_cn[name] = item
                    self.__update_icon(name)
Esempio n. 2
0
    def __init__(self, parent=None):
        """
            Constructor for main window.

            Arguments:
                parent: Parent object
        """
        plugins.PluginWidget.__init__(self)
        QtGui.QWidget.__init__(self, parent)

        self.setupUi(self)

        # Fine tune UI
        self.listRepositories.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)

        # Popup for new items
        self.menu = wrappers.Menu(self)
        self.menu.newAction("Add Item", wrappers.Icon("add48"),
                            self.__slot_repo_add)
        self.menu.newAction("Remove Item", wrappers.Icon("remove48"),
                            self.__slot_repo_remove)

        # Days of week
        self.day_widgets = [
            self.checkMonday, self.checkTuesday, self.checkWednesday,
            self.checkThursday, self.checkFriday, self.checkSaturday,
            self.checkSunday
        ]

        # UI events
        self.connect(self.listRepositories,
                     QtCore.SIGNAL("customContextMenuRequested(QPoint)"),
                     self.__slot_list_menu)
        self.connect(self.listRepositories,
                     QtCore.SIGNAL("itemDoubleClicked(QListWidgetItem*)"),
                     self.__slot_list_click)

        self.connect(self.pushAddRepo, QtCore.SIGNAL("clicked()"),
                     self.__slot_repo_add)
        self.connect(self.pushRemoveRepo, QtCore.SIGNAL("clicked()"),
                     self.__slot_repo_remove)
Esempio n. 3
0
    def __update_icon(self, name, status=None):
        """
            Updates Talk status of a directory node.

            Arguments:
                name: Node name
                status: talk.Online, talk.Offline (or None)
        """
        name = name.lower()
        if name in self.nodes_cn:
            if not status:
                if name in self.talk.online:
                    status = talk.Online
                else:
                    status = talk.Offline
            node = self.nodes_cn[name]
            if status == talk.Online:
                icon = wrappers.Icon("computer48", 32, [("online8", 1, 1)])
            else:
                icon = wrappers.Icon("computer48")
            node.setIcon(0, icon)
Esempio n. 4
0
    def __add_repo_item(self, url, name, secure=False, checked=False):
        """
            Adds a new item to repository list.

            Arguments:
                url: Repository URL
                name: Repository name
                secure: if repository is signed
                checked: if repository is enabled
        """
        item = QtGui.QListWidgetItem(self.listRepositories)
        if secure:
            item.setIcon(wrappers.Icon("locked48"))
        else:
            item.setIcon(wrappers.Icon("unlocked48"))
        if checked:
            item.setCheckState(QtCore.Qt.Checked)
        else:
            item.setCheckState(QtCore.Qt.UnChecked)
        item.setText("%s - %s" % (name, url))
        item.repo_url = url
        item.repo_name = name
Esempio n. 5
0
    def __update_status(self, backend, status):
        """
            Updates backend statuses.

            Arguments:
                backend: Name of backend (talk, directory)
                status: Status (online, offline, error)
        """
        if backend == "directory":
            self.status_directory = status
            if status == "online":
                self.__log("Directory connection established.", "directory",
                           "info")
            elif status == "offline":
                self.__log("Directory connection closed.", "directory", "info")
            elif status == "error":
                self.__log("Directory connection error.", "directory", "error")
        elif backend == "talk":
            self.status_talk = status
            if status == "online":
                self.__log("XMPP connection established.", "talk", "info")
            elif status == "offline":
                self.__log("XMPP connection closed.", "talk", "info")
            elif status == "error":
                self.__log("XMPP connection error.", "talk", "error")

        if self.status_directory == "offline":
            icon = wrappers.Icon("offline48")
        elif self.status_directory == "error":
            icon = wrappers.Icon("error48")
        elif self.status_directory == "online":
            if self.status_talk == "online":
                icon = wrappers.Icon("online48")
            else:
                icon = wrappers.Icon("partial48")
        self.pushConnection.setIcon(icon)
Esempio n. 6
0
    def __slot_stop_service(self):
        """
            This method is called when the stop button clicked to stop the selected service
        """
        item = self.tableWidget.selectedItems()
        item_name = str(item[3].text())

        for x in self.start_set:
            print "xxxxxxxxx:"
            print x
            if x == item_name:
                print "equal %s" % x
                self.start_set.remove(x)

        if item_name not in self.stop_set:
            self.stop_set.append(item_name)
        print self.start_set
        print self.stop_set

        item_status = item[1]
        item_status.setIcon(wrappers.Icon("flag-red"))
Esempio n. 7
0
    def __init__(self, app):
        """
            Constructor for main window.

            Arguments:
                parent: Parent object
        """
        QtGui.QWidget.__init__(self)

        # Application
        self.app = app

        # Attach generated UI
        self.setupUi(self)

        # Fine tune UI
        self.treeComputers.header().setResizeMode(0, QtGui.QHeaderView.Stretch)
        self.treeComputers.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)

        # Popup for connection management
        menu = wrappers.Menu(self)
        menu.newAction("Connect", wrappers.Icon("online48"),
                       self.__slot_connect)
        menu.newAction("Disconnect", wrappers.Icon("offline48"),
                       self.__slot_disconnect)
        self.pushConnection.setMenu(menu)

        # Popup for new items
        self.menu = wrappers.Menu(self)
        self.menu.newAction("New Folder", wrappers.Icon("folder48"),
                            self.__slot_new_folder)
        self.menu.newAction("New Computer", wrappers.Icon("computer48"),
                            self.__slot_new_computer)
        self.menu.newAction("New User", wrappers.Icon("user48"),
                            self.__slot_new_user)

        # Backends
        self.talk = talk.Talk()
        self.directory = directory.Directory()

        # Backend statuses
        self.status_directory = "offline"
        self.status_talk = "offline"

        # UI events
        self.connect(self.talk, QtCore.SIGNAL("stateChanged(int)"),
                     self.__slot_talk_state)
        self.connect(
            self.talk,
            QtCore.SIGNAL("messageFetched(QString, QString, QString)"),
            self.__slot_talk_message)
        self.connect(self.talk,
                     QtCore.SIGNAL("userStatusChanged(QString, int)"),
                     self.__slot_talk_status)
        self.connect(self.pushMain, QtCore.SIGNAL("clicked()"),
                     self.__slot_main)
        self.connect(self.pushDebug, QtCore.SIGNAL("toggled(bool)"),
                     self.__slot_debug)
        self.connect(self.treeComputers,
                     QtCore.SIGNAL("itemClicked(QTreeWidgetItem*, int)"),
                     self.__slot_tree_click)
        self.connect(self.treeComputers,
                     QtCore.SIGNAL("itemDoubleClicked(QTreeWidgetItem*, int)"),
                     self.__slot_tree_double_click)
        self.connect(self.treeComputers,
                     QtCore.SIGNAL("itemExpanded(QTreeWidgetItem*)"),
                     self.__slot_tree_expand)
        self.connect(self.treeComputers,
                     QtCore.SIGNAL("itemCollapsed(QTreeWidgetItem*)"),
                     self.__slot_tree_collapse)
        self.connect(self.treeComputers,
                     QtCore.SIGNAL("customContextMenuRequested(QPoint)"),
                     self.__slot_tree_menu)
        self.connect(self.pushApply, QtCore.SIGNAL("clicked()"),
                     self.__slot_apply)
        self.connect(self.pushReset, QtCore.SIGNAL("clicked()"),
                     self.__slot_reset)
        self.connect(self.pushOK, QtCore.SIGNAL("clicked()"), self.__slot_ok)

        # Initialize "talk" backend
        self.talk.start()

        # Directory nodes
        self.item = None
        self.policy = {}
        self.nodes_cn = {}
        self.nodes_dn = {}

        # Load plugins
        self.__load_plugins()

        # Reset UI
        self.__update_toolbar()
        self.__slot_debug(False)
Esempio n. 8
0
    def talk_message(self, sender, command, arguments=None):
        """
            Main window calls this method when an XMPP message is received.
        """
        startset = []
        stopset = []
        print "-----  TALK MESSAGE IS CALLED  -----"
        print command

        print "---- information ----"
        print "start set size %d" % len(self.start_set)
        print self.start_set
        print "stop set size %d" % len(self.stop_set)
        print self.stop_set

        for services in self.start_set:
            #print services
            for service in services.split(","):
                #print service
                startset.append(service)

        for services in self.stop_set:
            #print services
            for service in services.split(","):
                #print service
                stopset.append(service)

        if command == "service.info":

            self.tableWidget.setRowCount(len(arguments))
            print "----------- ARGUMENTS --------------"
            index = 0

            arguments.sort(key=lambda t: tuple(t[0].lower()))
            print arguments

            for name, desc, status in arguments:
                item_description = QtGui.QTableWidgetItem(str(desc))
                self.tableWidget.setItem(index, 0, item_description)

                item_name = QtGui.QTableWidgetItem(str(name))
                self.tableWidget.setItem(index, 3, item_name)

                item_status = QtGui.QTableWidgetItem()

                if status in ['started', 'on', 'conditional_started']:
                    item_status.setText(i18n("Running"))
                    state = True
                else:
                    item_status.setText(i18n("Stopped"))
                    state = False

                for start in startset:
                    if start == str(name):
                        item_status.setIcon(wrappers.Icon("flag-green"))

                for stop in stopset:
                    if stop == str(name):
                        item_status.setIcon(wrappers.Icon("flag-red"))

                self.tableWidget.setItem(index, 1, item_status)

                if status in ['stopped', 'on']:
                    item_autostart = QtGui.QTableWidgetItem(i18n("Yes"))
                elif status in ['conditional_started', 'conditional_stopped']:
                    item_autostart = QtGui.QTableWidgetItem(
                        i18n("Conditional"))
                else:
                    item_autostart = QtGui.QTableWidgetItem(i18n("No"))
                self.tableWidget.setItem(index, 2, item_autostart)

                if state:
                    self._set_service_item_color(index, SERV_START_COLOR)
                else:
                    self._set_service_item_color(index, SERV_STOP_COLOR)

                index += 1
        elif command in ["service.start.status", "service.stop.status"]:
            msg = QtGui.QMessageBox.information(self, i18n("Status"),
                                                arguments)