def accept(self):
     """
     Public slot handling the acceptance of the dialog.
     """
     if (not self.__addFolder and self.addressEdit.text().isEmpty()) or \
        self.nameEdit.text().isEmpty():
         QDialog.accept(self)
         return
     
     idx = self.currentIndex()
     if not idx.isValid():
         idx = self.__bookmarksManager.bookmarksModel().index(0, 0)
     parent = self.__bookmarksManager.bookmarksModel().node(idx)
     
     if self.__addFolder:
         type_ = BookmarkNode.Folder
     else:
         type_ = BookmarkNode.Bookmark
     bookmark = BookmarkNode(type_)
     bookmark.title = self.nameEdit.text()
     if not self.__addFolder:
         bookmark.url = self.addressEdit.text()
     
     self.__bookmarksManager.addBookmark(parent, bookmark)
     self.__addedNode = bookmark
     
     QDialog.accept(self)
Example #2
0
    def __readBookmarkNode(self, node):
        """
        Private method to read and parse a bookmark subtree.
        
        @param node reference to the node to attach to (BookmarkNode)
        """
        if not self.isStartElement() and self.name() != "bookmark":
            return

        bookmark = BookmarkNode(BookmarkNode.Bookmark, node)
        bookmark.url = self.attributes().value("href").toString()

        while not self.atEnd():
            self.readNext()
            if self.isEndElement():
                break

            if self.isStartElement():
                if self.name() == "title":
                    self.__readTitle(bookmark)
                elif self.name() == "desc":
                    self.__readDescription(bookmark)
                else:
                    self.__skipUnknownElement()

        if bookmark.title.isEmpty():
            bookmark.title = QCoreApplication.translate("XbelReader", "Unknown title")
 def dropMimeData(self, data, action, row, column, parent):
     """
     Public method to accept the mime data of a drop action.
     
     @param data reference to the mime data (QMimeData)
     @param action drop action requested (Qt.DropAction)
     @param row row number (integer)
     @param column column number (integer)
     @param parent index of the parent node (QModelIndex)
     @return flag indicating successful acceptance of the data (boolean)
     """
     if action == Qt.IgnoreAction:
         return True
     
     if column > 0:
         return False
     
     parentNode = self.node(parent)
     
     if not data.hasFormat(self.MIMETYPE):
         if not data.hasUrls():
             return False
         
         node = BookmarkNode(BookmarkNode.Bookmark, parentNode)
         node.url = QString.fromUtf8(data.urls()[0].toEncoded())
         
         if data.hasText():
             node.title = data.text()
         else:
             node.title = node.url
         
         self.__bookmarksManager.addBookmark(parentNode, node, row)
         return True
     
     ba = data.data(self.MIMETYPE)
     stream = QDataStream(ba, QIODevice.ReadOnly)
     if stream.atEnd():
         return False
     
     undoStack = self.__bookmarksManager.undoRedoStack()
     undoStack.beginMacro("Move Bookmarks")
     
     while not stream.atEnd():
         encodedData = QByteArray()
         stream >> encodedData
         buffer = QBuffer(encodedData)
         buffer.open(QIODevice.ReadOnly)
         
         reader = XbelReader()
         rootNode = reader.read(buffer)
         for bookmarkNode in rootNode.children():
             rootNode.remove(bookmarkNode)
             row = max(0, row)
             self.__bookmarksManager.addBookmark(parentNode, bookmarkNode, row)
             self.__endMacro = True
     
     return True
 def __convertFromOldBookmarks(self):
     """
     Private method to convert the old bookmarks into the new ones.
     """
     bmNames = Preferences.Prefs.settings.value('Bookmarks/Names')
     bmFiles = Preferences.Prefs.settings.value('Bookmarks/Files')
     
     if bmNames.isValid() and bmFiles.isValid():
         bmNames = bmNames.toStringList()
         bmFiles = bmFiles.toStringList()
         if len(bmNames) == len(bmFiles):
             convertedRootNode = BookmarkNode(BookmarkNode.Folder)
             convertedRootNode.title = self.trUtf8("Converted %1")\
                 .arg(QDate.currentDate().toString(Qt.SystemLocaleShortDate))
             for i in range(len(bmNames)):
                 node = BookmarkNode(BookmarkNode.Bookmark, convertedRootNode)
                 node.title = bmNames[i]
                 url = QUrl(bmFiles[i])
                 if url.scheme().isEmpty():
                     url.setScheme("file")
                 node.url = url.toString()
             self.addBookmark(self.menu(), convertedRootNode)
             
             Preferences.Prefs.settings.remove('Bookmarks')