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 importBookmarks(self):
     """
     Public method to import bookmarks.
     """
     supportedFormats = QStringList() \
         << self.trUtf8("XBEL bookmarks").append(" (*.xbel *.xml)") \
         << self.trUtf8("HTML Netscape bookmarks").append(" (*.html *.htm)")
     
     fileName = KQFileDialog.getOpenFileName(\
         None,
         self.trUtf8("Import Bookmarks"),
         QString(),
         supportedFormats.join(";;"),
         None)
     if fileName.isEmpty():
         return
     
     reader = XbelReader()
     importRootNode = None
     if fileName.endsWith(".html"):
         inFile = QFile(fileName)
         inFile.open(QIODevice.ReadOnly)
         if inFile.openMode == QIODevice.NotOpen:
             KQMessageBox.warning(None,
                 self.trUtf8("Import Bookmarks"),
                 self.trUtf8("""Error opening bookmarks file <b>%1</b>.""")\
                     .arg(fileName))
             return
         
         webpage = QWebPage()
         webpage.mainFrame().setHtml(QString(inFile.readAll()))
         result = webpage.mainFrame().evaluateJavaScript(extract_js).toByteArray()
         buffer_ = QBuffer(result)
         buffer_.open(QIODevice.ReadOnly)
         importRootNode = reader.read(buffer_)
     else:
         importRootNode = reader.read(fileName)
     
     if reader.error() != QXmlStreamReader.NoError:
         KQMessageBox.warning(None,
             self.trUtf8("Import Bookmarks"),
             self.trUtf8("""Error when importing bookmarks on line %1, column %2:\n"""
                         """%3""")\
                 .arg(reader.lineNumber())\
                 .arg(reader.columnNumber())\
                 .arg(reader.errorString()))
         return
     
     importRootNode.setType(BookmarkNode.Folder)
     importRootNode.title = self.trUtf8("Imported %1")\
         .arg(QDate.currentDate().toString(Qt.SystemLocaleShortDate))
     self.addBookmark(self.menu(), importRootNode)
 def load(self):
     """
     Public method to load the bookmarks.
     """
     if self.__loaded:
         return
     
     self.__loaded = True
     
     bookmarkFile = os.path.join(Utilities.getConfigDir(), "browser", "bookmarks.xbel")
     if not QFile.exists(bookmarkFile):
         ba = QByteArray(DefaultBookmarks)
         bookmarkFile = QBuffer(ba)
         bookmarkFile.open(QIODevice.ReadOnly)
     
     reader = XbelReader()
     self.__bookmarkRootNode = reader.read(bookmarkFile)
     if reader.error() != QXmlStreamReader.NoError:
         KQMessageBox.warning(None,
             self.trUtf8("Loading Bookmarks"),
             self.trUtf8("""Error when loading bookmarks on line %1, column %2:\n"""
                         """%3""")\
                 .arg(reader.lineNumber())\
                 .arg(reader.columnNumber())\
                 .arg(reader.errorString()))
     
     others = []
     for index in range(len(self.__bookmarkRootNode.children()) - 1, -1, -1):
         node = self.__bookmarkRootNode.children()[index]
         if node.type() == BookmarkNode.Folder:
             if (node.title == self.trUtf8("Toolbar Bookmarks") or \
                 node.title == BOOKMARKBAR) and \
                self.__toolbar is None:
                 node.title = self.trUtf8(BOOKMARKBAR)
                 self.__toolbar = node
             
             if (node.title == self.trUtf8("Menu") or \
                 node.title == BOOKMARKMENU) and \
                self.__menu is None:
                 node.title = self.trUtf8(BOOKMARKMENU)
                 self.__menu = node
         else:
             others.append(node)
         self.__bookmarkRootNode.remove(node)
         
     if len(self.__bookmarkRootNode.children()) > 0:
         raise RuntimeError("Error loading bookmarks.")
     
     if self.__toolbar is None:
         self.__toolbar = BookmarkNode(BookmarkNode.Folder, self.__bookmarkRootNode)
         self.__toolbar.title = self.trUtf8(BOOKMARKBAR)
     else:
         self.__bookmarkRootNode.add(self.__toolbar)
     
     if self.__menu is None:
         self.__menu = BookmarkNode(BookmarkNode.Folder, self.__bookmarkRootNode)
         self.__menu.title = self.trUtf8(BOOKMARKMENU)
     else:
         self.__bookmarkRootNode.add(self.__menu)
     
     for node in others:
         self.__menu.add(node)
     
     self.__convertFromOldBookmarks()