Beispiel #1
0
class NodeFilterBox(QWidget, Ui_NodeFBox, EventHandler):
    """
  This class is designed to perform searches on nodes in the VFS or a part of the VFS.
  """

    def __init__(self, parent, model):
        QWidget.__init__(self)
        Ui_NodeFBox.__init__(parent)
        EventHandler.__init__(self)
        self.parent = parent

        self.setupUi(self)
        self.model = model
        self.translation()

        if IndexerFound:
            self.opt = ModifIndex(self, model)
        self.vfs = vfs()

        if QtCore.PYQT_VERSION_STR >= "4.5.0":
            self.search.clicked.connect(self.searching)
            if IndexerFound:
                self.notIndexed.linkActivated.connect(self.index_opt2)
                self.indexOpt.clicked.connect(self.explain_this_odd_behavior)
            self.advancedSearch.clicked.connect(self.adv_search)
            # self.connect(self, SIGNAL("add_node"), self.parent.model.fillingList)
        else:
            QtCore.QObject.connect(self.search, SIGNAL("clicked(bool)"), self.searching)
            if IndexerFound:
                QtCore.QObject.connect(self.index_opt, SIGNAL("clicked(bool)"), self.explain_this_odd_behavior)
                QtCore.QObject.connect(self.notIndexed, SIGNAL("linkActivated()"), self.index_opt2)
            QtCore.QObject.connect(self.advancedSearch, SIGNAL("clicked(bool)"), self.adv_search)
            # self.connect(self, SIGNAL("add_node"), self.parent.model.fillingList)
        self.filterThread = FilterThread()

        # Future feature
        self.indexOpt.hide()

    # def Event(self, e):
    #  node = e.value.value()
    #  if e.type == 514:
    #    self.emit(SIGNAL("add_node"), long(node.this))

    def index_opt2(self, url):
        self.explain_this_odd_behavior()

    def explain_this_odd_behavior(self):
        ret = self.opt.exec_()
        thread.start_new_thread(self.index_opt, (True, ret))

    def index_opt(self, changed, ret):
        # set labal to indicate that a dir is not indexed to empty
        self.notIndexed.setText("")

        conf = Conf()
        index_path = conf.index_path

        if ret == QDialog.Accepted:
            index = Index(index_path)
            index.createIndex()

            # config index
            index_c = self.opt.indexFileContent.checkState()
            index_a = self.opt.indexFileAttr.checkState()

            if index_c == Qt.Checked:
                index.setIndexContent(True)
            else:
                index.setIndexContent(False)

            if index_a == Qt.Checked:
                index.setIndexAttr(True)
            else:
                index.setIndexAttr(False)

            value = 0
            for i in self.opt.un_index:
                recurse = self.opt.indexed_items[long(i)]
                node = VFS.Get().getNodeFromPointer(i)
                for (root_dir, files, dirs) in self.vfs.walk(node, True, 1):
                    value += len(files)

            for i in self.opt.tmp_indexed_items:
                recurse = self.opt.tmp_indexed_items[long(i)]
                node = VFS.Get().getNodeFromPointer(i)
                for (root_dir, files, dirs) in self.vfs.walk(node, True, 1):
                    value += len(files)
            self.emit(SIGNAL("number_max"), value)

            # delete doc from index (if any stuff are to be deleted)
            value = 0
            for i in self.opt.un_index:
                recurse = self.opt.indexed_items[long(i)]
                node = VFS.Get().getNodeFromPointer(i)
                if recurse == True:
                    tmp = node.children()
                    for j in tmp:
                        value += 1
                        IndexSearch.deleteDoc(str(j.absolute()).lower(), str(index_path).lower())
                else:
                    value += 1
                    self.deleteRecurse(node, index, index_path)
                self.emit(SIGNAL("number_indexed"), value)
                self.opt.indexed_items.pop(i)

            # adding new selected nodes in index
            for i in self.opt.tmp_indexed_items:
                node = VFS.Get().getNodeFromPointer(i)
                self.opt.indexed_items[i] = self.opt.tmp_indexed_items[i]

                # only index current node content
                if self.opt.indexed_items[i] == True:
                    tmp = node.children()
                    for ii in tmp:
                        value += 1
                        index.indexData(ii)
                else:  # index recursively
                    value += 1
                    self.recurseNode(node, index)
                self.emit(SIGNAL("number_indexed"), value)
            self.opt.tmp_indexed_items.clear()

            index.closeIndex()
            # un-activated the check box for nodes which have been recursivly indexed.
            self.hide_recurse()
            # clear the un index dict
            self.opt.un_index.clear()

    def hide_recurse(self):
        for i in range(0, self.opt.indexedItems.rowCount()):
            item = self.opt.indexedItems.item(i, 1)
            if item.data(Qt.CheckStateRole) == Qt.Checked:
                item.setFlags(Qt.NoItemFlags)

    def deleteRecurse(self, node, index, index_path):
        if not node:
            return
        if node.size() and node.isFile():
            IndexSearch.deleteDoc(str(node.absolute()), index_path)
        if node.hasChildren():  # if the node has children, get all of them
            tmp = node.children()
            for i in tmp:
                self.deleteRecurse(i, index, index_path)

    def recurseNode(self, node, index):
        if not node:
            return
        if node.size() and node.isFile():
            index.indexData(node)
        if node.hasChildren():  # if the node has children, get all of them
            tmp = node.children()
            for i in tmp:
                self.recurseNode(i, index)

    def adv_search(self, changed):

        # parent is an instance of NodeBrowser
        adv = AdvSearch(self)

        self.parent.parent.addSearchTab(adv)
        adv.setCurrentNode(self.parent.model.rootItem)
        adv.path.setText(adv.search_in_node.absolute())
        return

        ret = self.adv.show()
        return

        ret = self.adv.exec_()
        if ret == QDialog.Accepted:
            all_word = str(self.adv.allWords.text())
            none_word = str(self.adv.noneWord.text())
            one_word = str(self.adv.oneWord.text())

            if all_word == "t":
                all_word = ""
            if none_word == "t":
                none_word = ""
            if one_word == "t":
                one_word = ""
            if all_word == "" and none_word == "" and one_word == "":
                return

            query = ""
            query += one_word
            none_word = none_word.lstrip()
            l = none_word.split()
            if len(l):
                for i in l:
                    query += " -" + i
            elif none_word != "":
                query += " -" + none_word

            all_word = all_word.lstrip()
            l = all_word.split()
            if len(l):
                for i in l:
                    query += " AND " + i
            elif all_word != "":
                if self.adv.allWordTitle.isChecked():
                    query += all_word
                if self.adv.allWordContent.isChecked():
                    query += all_word

            # prepare stuff to fo the query
            conf = Conf()
            index_path = conf.index_path  # get path to the index
            search_engine = IndexSearch(index_path)
            search_engine.exec_query(query, "")

    def filterRegExpChanged(self):
        if self.quickSearch.isChecked():
            if self.caseSensitivity.isChecked():
                caseSensitivity = Qt.CaseSensitive
            else:
                caseSensitivity = Qt.CaseInsensitive
            regExp = QRegExp(self.filterPatternLineEdit.text(), caseSensitivity)
            regExp.setPatternSyntax(QRegExp.RegExp)
            if self.parent.currentProxyModel():
                self.parent.currentProxyModel().setFilterRegExp(regExp)

    def searching(self, changed):
        if not self.searchClause.text().isEmpty():
            if self.recurse.checkState() != Qt.Checked:
                self.filterThread.setOneFolder(True)
            else:
                self.filterThread.setOneFolder(False)
                self.filterThread.setRecursive(True)

            clause = 'name == w("*' + str(self.searchClause.text()) + '*",i)'
            self.filterThread.setContext(clause, self.parent.model.rootItem, self.parent.model)
            self.filterThread.start()

    def translation(self):
        self.msg_not_indexed = self.tr("This location is not indexed.")
        self.msg_not_indexed2 = self.tr("Index it ?")

    def vfs_item_model(self, model):
        """
    Method used to access to the vfsitemmodel. It is used to know
    the current directory in which we currently are.
    """
        self.vfs_model = model
        self.connect(self.vfs_model, SIGNAL("rootPathChanged"), self.hideIndexBar)

    def hideIndexBar(self, node):
        self.notIndexed.setText("")
Beispiel #2
0
class IndexOpt(QDialog, Ui_IndexationUI):
    """
    This GUI dialog box is used to display nodes which already are indexedm with the exception of
    subdirectories which are nod added in the index.

    It is made as follow :

    Indexed items | Exceptions
    ------------------------------------
    Dir1          |        --
    Dir2          | Subdir2.1, Subdir2.2
    Dir3          |        --

    and so on.

    To button are clickable "Modify" and "Advanced", respectively allowing to modify the content
    of the index and to configure the behavior of the index.
    """
    def __init__(self, parent, model):
        """
        Init the GUI, the parent and connect signals.

        **Param**::
                * ``parent`` : the parent widget (NodeFilterBox instance)
        """

        super(QDialog, self).__init__()
        self.parent = parent
        self.setupUi(self)
        self.model = model
        
        self.adv_index = ModifIndex(self, model)
        
        # connect the buttons signal to their slots.
        if QtCore.PYQT_VERSION_STR >= "4.5.0":
            self.indexAdvanced.clicked.connect(self.advanceOpt)
            self.modifIndexItems.clicked.connect(self.indexItems)
        else:
            QtCore.QObject.connect(self.indexAdvanced, SIGNAL("clicked(bool)"), self.advanceOpt)
            QtCore.QObject.connect(self.modifIndexItems, SIGNAL("clicked(bool)"), self.indexItems)

        self.initTableWidget()

        # ### FOR TESTING ###
        self.indexedItems.setRowCount(3)
        self.load_items()

    def initTableWidget(self):
        self.indexedItems.setColumnCount(2)

        # set the headers' titles and stretch the last section
        head1 = QTableWidgetItem("Indexed items")
        head2 = QTableWidgetItem("Exceptions")
        self.indexedItems.setHorizontalHeaderItem(0, head1)
        self.indexedItems.setHorizontalHeaderItem(1, head2)
        self.indexedItems.horizontalHeader().setStretchLastSection(True)

        # hide vertical header and grid, remove editable mode
        self.indexedItems.verticalHeader().hide()
        self.indexedItems.setEditTriggers(QAbstractItemView.NoEditTriggers)
        self.indexedItems.setShowGrid(False)
        self.indexedItems.setAlternatingRowColors(True)
        self.indexedItems.setSelectionBehavior(QAbstractItemView.SelectRows)

    # ### FOR TESTING ###
    def load_items(self):
        item1 = QTableWidgetItem(QIcon(":/folder.png"), "Dir 1")
        self.indexedItems.setItem(0, 0, item1)
        self.indexedItems.setItem(1, 0, QTableWidgetItem(QIcon(":/folder.png"), "Dir2"))
        self.indexedItems.setItem(1, 1, QTableWidgetItem("Dir2.1, Dir2.2"))
        self.indexedItems.setItem(2, 0, QTableWidgetItem(QIcon(":/folder.png"), "Dir3"))

    def indexItems(self, changed):
        """
        Open the dialog box to modify index.
        """
        self.adv_index.tabWidget.setCurrentIndex(0)

        #self.adv_index.model.emit(SIGNAL("layoutAboutToBeChanged()"))
        self.adv_index.model.root_item = self.model.root_item
        #self.adv_index.model.emit(SIGNAL("layoutChanged()"))
        self.adv_index.exec_()
        # self.adv_index.model.setCh(False)

    def advanceOpt(self, changed):
        """
        Open the dialog box to configure the index engine.
        """
        self.adv_index.tabWidget.setCurrentIndex(1)


        #self.adv_index.model.emit(SIGNAL("layoutAboutToBeChanged()"))
        self.adv_index.model.root_item = self.model.root_item
        #self.adv_index.model.emit(SIGNAL("layoutChanged()"))
        # self.adv_index.model.setCh(True)
        self.adv_index.exec_()
        #elf.adv_index.model.setCh(False)

    def translation(self):
        pass