From b1d0cd9228baec1a333eae85c793cea46411edc3 Mon Sep 17 00:00:00 2001 From: nowrep Date: Thu, 5 Apr 2012 10:27:35 +0200 Subject: [PATCH] Improved performance of bookmarks import and bookmarks deleting. - moved general defines into qz_namespace.h file - fixed showing default theme to be "default" on mac in theme manager instead of "mac" theme --- README.md | 8 +- src/lib/app/mainapplication.cpp | 18 ---- src/lib/app/profileupdater.cpp | 2 +- src/lib/app/qz_namespace.h | 36 ++++++++ src/lib/bookmarks/bookmarksmodel.cpp | 87 ++++++++++--------- src/lib/bookmarks/bookmarksmodel.h | 9 +- .../bookmarksimport/bookmarksimportdialog.cpp | 10 ++- src/lib/downloads/downloadmanager.cpp | 8 +- src/lib/plugins/plugininterface.h | 4 + src/lib/plugins/plugins.cpp | 6 -- src/lib/preferences/pluginslist.cpp | 6 -- src/lib/preferences/preferences.cpp | 10 +-- src/lib/preferences/thememanager.cpp | 6 -- 13 files changed, 106 insertions(+), 104 deletions(-) diff --git a/README.md b/README.md index 562e1d959..d5420ef4e 100644 --- a/README.md +++ b/README.md @@ -45,13 +45,13 @@ Then you can start compiling by running this commands: After a successful compilation the executable binary can be found in the bin/ directory. -On Linux/Unix: To install QupZilla, you will have to run this command: (it may be necessary to run it as root) +On Linux/Unix: To install QupZilla, run this command: (it may be necessary to run it as root) $ make install On Mac OS X: To deploy QupZilla in bundle, run this command: - $ cd scripts && ./macdeploy.sh full-path-to-macdeployqt + $ ./scripts/macdeploy.sh full-path-to-macdeployqt You need to specify path to `macdeployqt` only if it is not in PATH. @@ -80,6 +80,4 @@ FAQ and Changelog If you are experiencing some sort of problem, please read the FAQ before you open an issue. -FAQ: https://github.com/nowrep/QupZilla/wiki/FAQ - -Changelog: https://github.com/nowrep/QupZilla/wiki/Changelog +[FAQ](https://github.com/nowrep/QupZilla/wiki/FAQ) | [Changelog](https://github.com/nowrep/QupZilla/wiki/Changelog) | [Bug Reports](https://github.com/nowrep/QupZilla/wiki/Bug-Reports) diff --git a/src/lib/app/mainapplication.cpp b/src/lib/app/mainapplication.cpp index d53860de3..01ddad2b7 100644 --- a/src/lib/app/mainapplication.cpp +++ b/src/lib/app/mainapplication.cpp @@ -60,24 +60,6 @@ #include #include -#ifdef Q_WS_WIN -#define DEFAULT_CHECK_UPDATES true -#else -#define DEFAULT_CHECK_UPDATES false -#endif - -#ifdef Q_WS_WIN -#define DEFAULT_THEME_NAME "windows" -#elif defined(Q_WS_X11) -#define DEFAULT_THEME_NAME "linux" -#elif defined(Q_WS_MAC) -#define DEFAULT_THEME_NAME "mac" -#elif defined(Q_OS_OS2) -#define DEFAULT_THEME_NAME "windows" -#else -#define DEFAULT_THEME_NAME "default" -#endif - #if defined(PORTABLE_BUILD) && !defined(NO_SYSTEM_DATAPATH) #define NO_SYSTEM_DATAPATH #endif diff --git a/src/lib/app/profileupdater.cpp b/src/lib/app/profileupdater.cpp index e16bc5e50..5d0839305 100644 --- a/src/lib/app/profileupdater.cpp +++ b/src/lib/app/profileupdater.cpp @@ -120,7 +120,7 @@ void ProfileUpdater::copyDataToProfile() 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:

" + browseDataBackup + "
" + settingsBackup + "
"; + "backed up in following directories:

" + browseDataBackup + "
" + settingsBackup + "
"; QMessageBox::warning(0, "QupZilla: Incompatible profile version", text); } diff --git a/src/lib/app/qz_namespace.h b/src/lib/app/qz_namespace.h index 4a97c896e..81c5e2902 100644 --- a/src/lib/app/qz_namespace.h +++ b/src/lib/app/qz_namespace.h @@ -81,4 +81,40 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(Qz::NewTabPositionFlags) } +#ifdef Q_WS_WIN +#define DEFAULT_THEME_NAME "windows" +#elif defined(Q_WS_X11) +#define DEFAULT_THEME_NAME "linux" +#elif defined(Q_WS_MAC) +#define DEFAULT_THEME_NAME "mac" +#elif defined(Q_OS_OS2) +#define DEFAULT_THEME_NAME "windows" +#else +#define DEFAULT_THEME_NAME "default" +#endif + +#ifdef Q_WS_WIN +#define DEFAULT_CHECK_UPDATES true +#else +#define DEFAULT_CHECK_UPDATES false +#endif + +#ifdef Q_WS_WIN +#define DEFAULT_DOWNLOAD_USE_NATIVE_DIALOG false +#else +#define DEFAULT_DOWNLOAD_USE_NATIVE_DIALOG true +#endif + +#ifdef PORTABLE_BUILD +#define DEFAULT_ENABLE_PLUGINS false +#else +#define DEFAULT_ENABLE_PLUGINS true +#endif + +#ifdef Q_WS_WIN +#define DEFAULT_DOWNLOAD_USE_NATIVE_DIALOG false +#else +#define DEFAULT_DOWNLOAD_USE_NATIVE_DIALOG true +#endif + #endif // QZ_NAMESPACE_H diff --git a/src/lib/bookmarks/bookmarksmodel.cpp b/src/lib/bookmarks/bookmarksmodel.cpp index 617245942..23f0db44b 100644 --- a/src/lib/bookmarks/bookmarksmodel.cpp +++ b/src/lib/bookmarks/bookmarksmodel.cpp @@ -204,41 +204,55 @@ bool BookmarksModel::saveBookmark(WebView* view, QString folder) return saveBookmark(view->url(), view->title(), view->icon(), folder); } -bool BookmarksModel::removeBookmark(int id) +void BookmarksModel::removeBookmark(int id) { - QSqlQuery query; - query.prepare("SELECT url, title, folder FROM bookmarks WHERE id = ?"); - query.bindValue(0, id); - query.exec(); - if (!query.next()) { - return false; + QList list; + list.append(id); + + return removeBookmark(list); +} + +void BookmarksModel::removeBookmark(const QList list) +{ + QSqlDatabase db = QSqlDatabase::database(); + db.transaction(); + + foreach (int id, list) { + QSqlQuery query; + query.prepare("SELECT url, title, folder FROM bookmarks WHERE id = ?"); + query.bindValue(0, id); + query.exec(); + if (!query.next()) { + continue; + } + + Bookmark bookmark; + bookmark.id = id; + bookmark.url = query.value(0).toUrl(); + bookmark.title = query.value(1).toString(); + bookmark.folder = query.value(2).toString(); + bookmark.image = QImage::fromData(query.value(3).toByteArray()); + bookmark.inSubfolder = isSubfolder(bookmark.folder); + + if (!query.exec("DELETE FROM bookmarks WHERE id = " + QString::number(id))) { + continue; + } + + emit bookmarkDeleted(bookmark); } - Bookmark bookmark; - bookmark.id = id; - bookmark.url = query.value(0).toUrl(); - bookmark.title = query.value(1).toString(); - bookmark.folder = query.value(2).toString(); - bookmark.image = QImage::fromData(query.value(3).toByteArray()); - bookmark.inSubfolder = isSubfolder(bookmark.folder); - - if (!query.exec("DELETE FROM bookmarks WHERE id = " + QString::number(id))) { - return false; - } - - emit bookmarkDeleted(bookmark); + db.commit(); mApp->sendMessages(Qz::AM_BookmarksChanged, true); - return true; } -bool BookmarksModel::removeBookmark(const QUrl &url) +void BookmarksModel::removeBookmark(const QUrl &url) { - return removeBookmark(bookmarkId(url)); + removeBookmark(bookmarkId(url)); } -bool BookmarksModel::removeBookmark(WebView* view) +void BookmarksModel::removeBookmark(WebView* view) { - return removeBookmark(bookmarkId(view->url())); + removeBookmark(bookmarkId(view->url())); } //bool BookmarksModel::editBookmark(int id, const QString &title, const QString &folder) @@ -322,37 +336,32 @@ bool BookmarksModel::createFolder(const QString &name) return true; } -bool BookmarksModel::removeFolder(const QString &name) +void BookmarksModel::removeFolder(const QString &name) { if (name == _bookmarksMenu || name == _bookmarksToolbar) { - return false; + return; } QSqlQuery query; query.prepare("SELECT id FROM bookmarks WHERE folder = ? "); query.bindValue(0, name); if (!query.exec()) { - return false; + return; } + + QList list; while (query.next()) { - removeBookmark(query.value(0).toInt()); + list.append(query.value(0).toInt()); } + removeBookmark(list); query.prepare("DELETE FROM folders WHERE name=?"); query.bindValue(0, name); - if (!query.exec()) { - return false; - } - - query.prepare("DELETE FROM bookmarks WHERE folder=?"); - query.bindValue(0, name); - if (!query.exec()) { - return false; - } + query.exec(); emit folderDeleted(name); + mApp->sendMessages(Qz::AM_BookmarksChanged, true); - return true; } bool BookmarksModel::renameFolder(const QString &before, const QString &after) diff --git a/src/lib/bookmarks/bookmarksmodel.h b/src/lib/bookmarks/bookmarksmodel.h index 9a5a17d41..aeb51e279 100644 --- a/src/lib/bookmarks/bookmarksmodel.h +++ b/src/lib/bookmarks/bookmarksmodel.h @@ -80,16 +80,17 @@ public: bool saveBookmark(const QUrl &url, const QString &title, const QIcon &icon, const QString &folder = "unsorted"); bool saveBookmark(WebView* view, QString folder = QString()); - bool removeBookmark(int id); - bool removeBookmark(const QUrl &url); - bool removeBookmark(WebView* view); + void removeBookmark(const QUrl &url); + void removeBookmark(WebView* view); + void removeBookmark(int id); + void removeBookmark(const QList list); bool editBookmark(int id, const QString &title = "", const QUrl &url = QUrl(), const QString &folder = ""); // bool editBookmark(int id, const QString &title, const QString &folder); // bool editBookmark(int id, const QUrl &url, const QString &title); bool createFolder(const QString &name); - bool removeFolder(const QString &name); + void removeFolder(const QString &name); QList folderBookmarks(const QString &name); diff --git a/src/lib/bookmarksimport/bookmarksimportdialog.cpp b/src/lib/bookmarksimport/bookmarksimportdialog.cpp index 5939b46a7..4650bf43a 100644 --- a/src/lib/bookmarksimport/bookmarksimportdialog.cpp +++ b/src/lib/bookmarksimport/bookmarksimportdialog.cpp @@ -260,15 +260,19 @@ void BookmarksImportDialog::setFile() void BookmarksImportDialog::addExportedBookmarks() { - qApp->setOverrideCursor(Qt::WaitCursor); - + QApplication::setOverrideCursor(Qt::WaitCursor); BookmarksModel* model = mApp->bookmarksModel(); + QSqlDatabase db = QSqlDatabase::database(); + db.transaction(); + foreach(const Bookmark & b, m_exportedBookmarks) { model->saveBookmark(b.url, b.title, IconProvider::iconFromImage(b.image), b.folder); } - qApp->restoreOverrideCursor(); + db.commit(); + + QApplication::restoreOverrideCursor(); } void BookmarksImportDialog::setupBrowser(Browser browser) diff --git a/src/lib/downloads/downloadmanager.cpp b/src/lib/downloads/downloadmanager.cpp index 664f37a15..7dc85b6d2 100644 --- a/src/lib/downloads/downloadmanager.cpp +++ b/src/lib/downloads/downloadmanager.cpp @@ -35,12 +35,6 @@ #include #include -#ifdef Q_WS_WIN -#define DEFAULT_USE_NATIVE_DIALOG false -#else -#define DEFAULT_USE_NATIVE_DIALOG true -#endif - DownloadManager::DownloadManager(QWidget* parent) : QWidget(parent) , ui(new Ui::DownloadManager) @@ -76,7 +70,7 @@ void DownloadManager::loadSettings() m_downloadPath = settings.value("defaultDownloadPath", "").toString(); m_lastDownloadPath = settings.value("lastDownloadPath", QDir::homePath().append("/")).toString(); m_closeOnFinish = settings.value("CloseManagerOnFinish", false).toBool(); - m_useNativeDialog = settings.value("useNativeDialog", DEFAULT_USE_NATIVE_DIALOG).toBool(); + m_useNativeDialog = settings.value("useNativeDialog", DEFAULT_DOWNLOAD_USE_NATIVE_DIALOG).toBool(); m_useExternalManager = settings.value("UseExternalManager", false).toBool(); m_externalExecutable = settings.value("ExternalManagerExecutable", "").toString(); diff --git a/src/lib/plugins/plugininterface.h b/src/lib/plugins/plugininterface.h index 0505fd00a..52d9cfe05 100644 --- a/src/lib/plugins/plugininterface.h +++ b/src/lib/plugins/plugininterface.h @@ -33,6 +33,10 @@ struct PluginSpec { QPixmap icon; bool hasSettings; + PluginSpec() { + hasSettings = false; + } + bool operator==(const PluginSpec &other) { return (this->name == other.name && this->info == other.info && diff --git a/src/lib/plugins/plugins.cpp b/src/lib/plugins/plugins.cpp index 2f5e3bf39..f9e9f10bc 100644 --- a/src/lib/plugins/plugins.cpp +++ b/src/lib/plugins/plugins.cpp @@ -25,12 +25,6 @@ #include #include -#ifdef PORTABLE_BUILD -#define DEFAULT_ENABLE_PLUGINS false -#else -#define DEFAULT_ENABLE_PLUGINS true -#endif - Plugins::Plugins(QObject* parent) : QObject(parent) , m_pluginsLoaded(false) diff --git a/src/lib/preferences/pluginslist.cpp b/src/lib/preferences/pluginslist.cpp index d537a077c..a319ba895 100644 --- a/src/lib/preferences/pluginslist.cpp +++ b/src/lib/preferences/pluginslist.cpp @@ -27,12 +27,6 @@ #include #include -#ifdef PORTABLE_BUILD -#define DEFAULT_ENABLE_PLUGINS false -#else -#define DEFAULT_ENABLE_PLUGINS true -#endif - PluginsList::PluginsList(QWidget* parent) : QWidget(parent) , ui(new Ui::PluginsList) diff --git a/src/lib/preferences/preferences.cpp b/src/lib/preferences/preferences.cpp index b1c0b2b14..0263ddac7 100644 --- a/src/lib/preferences/preferences.cpp +++ b/src/lib/preferences/preferences.cpp @@ -48,14 +48,6 @@ #include #include -#ifdef Q_WS_WIN -#define DEFAULT_CHECK_UPDATES true -#define DEFAULT_USE_NATIVE_DIALOG false -#else -#define DEFAULT_CHECK_UPDATES false -#define DEFAULT_USE_NATIVE_DIALOG true -#endif - Preferences::Preferences(QupZilla* mainClass, QWidget* parent) : QDialog(parent) , ui(new Ui::Preferences) @@ -285,7 +277,7 @@ Preferences::Preferences(QupZilla* mainClass, QWidget* parent) settings.beginGroup("DownloadManager"); ui->downLoc->setText(settings.value("defaultDownloadPath", "").toString()); ui->closeDownManOnFinish->setChecked(settings.value("CloseManagerOnFinish", false).toBool()); - ui->downlaodNativeSystemDialog->setChecked(settings.value("useNativeDialog", DEFAULT_USE_NATIVE_DIALOG).toBool()); + ui->downlaodNativeSystemDialog->setChecked(settings.value("useNativeDialog", DEFAULT_DOWNLOAD_USE_NATIVE_DIALOG).toBool()); if (ui->downLoc->text().isEmpty()) { ui->askEverytime->setChecked(true); } diff --git a/src/lib/preferences/thememanager.cpp b/src/lib/preferences/thememanager.cpp index 60c319edb..425f135db 100644 --- a/src/lib/preferences/thememanager.cpp +++ b/src/lib/preferences/thememanager.cpp @@ -26,12 +26,6 @@ #include #include -#ifdef Q_WS_WIN -#define DEFAULT_THEME_NAME "windows" -#else -#define DEFAULT_THEME_NAME "linux" -#endif - ThemeManager::ThemeManager(QWidget* parent, Preferences* preferences) : QWidget() , ui(new Ui::ThemeManager)