1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 01:22:10 +01:00

Fixed importing Html bookmarks from various browsers.

- fixed one potentional crash in importing
This commit is contained in:
nowrep 2012-04-04 23:28:19 +02:00
parent f94e69d557
commit b287c5f829
4 changed files with 51 additions and 18 deletions

View File

@ -1,8 +1,8 @@
QupZilla Web Browser
----------------------------------------------------------------------------------------
Homepage: http://www.qupzilla.com
Blog: http://blog.qupzilla.com/
Homepage: http://www.qupzilla.com
Blog: http://blog.qupzilla.com/
IRC: `#qupzilla` at `irc.freenode.net`
About QupZilla

View File

@ -1,27 +1,29 @@
#!/bin/bash
COMMAND=$1
LIBRARY_NAME="libQupZilla.1.dylib"
if [ $COMMAND = "" ]; then
$COMMAND="macdeployqt"
fi
# cd to directory with bundle
cd ../build
test -d build || cd ..
cd build
# copy libQupZilla into bundle
cp libQupZilla* QupZilla.app/Contents/MacOS/QupZilla
cp $LIBRARY_NAME QupZilla.app/Contents/MacOS/
# copy all plugins into bundle
test -d QupZilla.app/Contents/Resources/plugins || mkdir QupZilla.app/Contents/Resources/plugins
cp plugins/*.dylib QupZilla.app/Contents/Resources/plugins
cp plugins/*.dylib QupZilla.app/Contents/Resources/plugins/
# fix libQupZilla
install_name_tool -change libQupZilla.1.dylib @executable_path/libQupZilla.1.dylib QupZilla.app/Contents/MacOS/QupZilla
install_name_tool -change $LIBRARY_NAME @executable_path/$LIBRARY_NAME QupZilla.app/Contents/MacOS/QupZilla
# fix plugins
for plugin in QupZilla.app/Contents/Resources/plugins*.dylib
for plugin in QupZilla.app/Contents/Resources/plugins/*.dylib
do
install_name_tool -change libQupZilla.1.dylib @executable_path/libQupZilla.1.dylib $plugin
install_name_tool -change $LIBRARY_NAME @executable_path/$LIBRARY_NAME $plugin
done
# run macdeployqt

View File

@ -18,10 +18,12 @@
#include "profileupdater.h"
#include "qupzilla.h"
#include "updater.h"
#include "globalfunctions.h"
#include "mainapplication.h"
#include <QDir>
#include <QSqlQuery>
#include <QMessageBox>
#include <iostream>
ProfileUpdater::ProfileUpdater(const QString &profilePath)
@ -111,7 +113,18 @@ void ProfileUpdater::copyDataToProfile()
QDir profileDir(m_profilePath);
profileDir.mkdir("certificates");
QFile(m_profilePath + "browsedata.db").remove();
QFile browseData(m_profilePath + "browsedata.db");
if (browseData.exists()) {
const QString &browseDataBackup = qz_ensureUniqueFilename(m_profilePath + "browsedata-backup.db");
const QString &settingsBackup = qz_ensureUniqueFilename(m_profilePath + "settings-backup.ini");
browseData.copy(browseDataBackup);
QFile(m_profilePath + "settings.ini").copy(settingsBackup);
const QString &text = "Incompatible profile version has been detected. To avoid losing your profile data, they were "
"backed up in following directories:<br/><br/><b>" + browseDataBackup + "<br/>" + settingsBackup + "<br/></b>";
QMessageBox::warning(0, "QupZilla: Incompatible profile version", text);
}
browseData.remove();
QFile(":data/browsedata.db").copy(m_profilePath + "browsedata.db");
QFile(m_profilePath + "browsedata.db").setPermissions(QFile::ReadUser | QFile::WriteUser);
}

View File

@ -66,17 +66,33 @@ QList<BookmarksModel::Bookmark> HtmlImporter::exportBookmarks()
QString bookmarks = QString::fromUtf8(m_file.readAll());
m_file.close();
bookmarks = bookmarks.mid(0, bookmarks.lastIndexOf("</DL><p>"));
int start = bookmarks.indexOf("<DL><p>", Qt::CaseInsensitive);
// Converting tags to lower case -,-
// For some reason Qt::CaseInsensitive is not everytime insensitive :-D
bookmarks.replace("<DL", "<dl");
bookmarks.replace("</DL", "</dl");
bookmarks.replace("<DT", "<dt");
bookmarks.replace("</DT", "</dt");
bookmarks.replace("<P", "<p");
bookmarks.replace("</P", "</p");
bookmarks.replace("<A", "<a");
bookmarks.replace("</A", "</a");
bookmarks.replace("HREF=", "href=");
bookmarks.replace("<H3", "<h3");
bookmarks.replace("</H3", "</h3");
bookmarks = bookmarks.mid(0, bookmarks.lastIndexOf("</dl><p>"));
int start = bookmarks.indexOf("<dl><p>");
QStringList folders("Html Import");
while (start > 0) {
QString string = bookmarks.mid(start);
int posOfFolder = string.indexOf("<DT><H3", Qt::CaseInsensitive);
int posOfEndFolder = string.indexOf("</DL><p>", Qt::CaseInsensitive);
int posOfLink = string.indexOf("<DT><A", Qt::CaseInsensitive);
int posOfFolder = string.indexOf("<dt><h3");
int posOfEndFolder = string.indexOf("</dl><p>");
int posOfLink = string.indexOf("<dt><a");
int nearest = qzMin(posOfLink, qzMin(posOfFolder, posOfEndFolder));
if (nearest == -1) {
@ -85,7 +101,7 @@ QList<BookmarksModel::Bookmark> HtmlImporter::exportBookmarks()
if (nearest == posOfFolder) {
// Next is folder
QRegExp rx("<DT><H3(.*)>(.*)</H3>", Qt::CaseInsensitive);
QRegExp rx("<dt><h3(.*)>(.*)</h3>");
rx.setMinimal(true);
rx.indexIn(string);
@ -98,20 +114,22 @@ QList<BookmarksModel::Bookmark> HtmlImporter::exportBookmarks()
}
else if (nearest == posOfEndFolder) {
// Next is end of folder
folders.removeLast();
if (!folders.isEmpty()) {
folders.removeLast();
}
start += posOfEndFolder + 8;
}
else {
// Next is link
QRegExp rx("<DT><A(.*)>(.*)</A>", Qt::CaseInsensitive);
QRegExp rx("<dt><a(.*)>(.*)</a>");
rx.setMinimal(true);
rx.indexIn(string);
QString arguments = rx.cap(1);
QString linkName = rx.cap(2);
QRegExp rx2("HREF=\"(.*)\"", Qt::CaseInsensitive);
QRegExp rx2("href=\"(.*)\"");
rx2.setMinimal(true);
rx2.indexIn(arguments);