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

[Code] Various cleanups in Bookmarks code

This commit is contained in:
nowrep 2014-02-05 16:44:19 +01:00
parent fe9ecbbbaa
commit 371306cd3c
6 changed files with 42 additions and 73 deletions

View File

@ -1507,7 +1507,7 @@ void QupZilla::loadFolderBookmarks(Menu* menu)
return;
}
foreach (const Bookmark &b, mApp->bookmarks()->folderBookmarks(folder)) {
foreach (const Bookmark &b, mApp->bookmarks()->getFolderBookmarks(folder)) {
tabWidget()->addView(b.url, b.title, Qz::NT_NotSelectedTab);
}
}

View File

@ -48,6 +48,11 @@ void Bookmarks::loadSettings()
settings.endGroup();
}
bool Bookmarks::isShowingMostVisited() const
{
return m_showMostVisited;
}
void Bookmarks::setShowingMostVisited(bool state)
{
Settings settings;
@ -57,6 +62,11 @@ void Bookmarks::setShowingMostVisited(bool state)
m_showMostVisited = state;
}
bool Bookmarks::isShowingOnlyIconsInToolbar() const
{
return m_showOnlyIconsInToolbar;
}
void Bookmarks::setShowingOnlyIconsInToolbar(bool state)
{
Settings settings;
@ -82,6 +92,11 @@ bool Bookmarks::isFolder(const QString &name)
return query.next();
}
QString Bookmarks::lastFolder() const
{
return m_lastFolder;
}
void Bookmarks::setLastFolder(const QString &folder)
{
Settings settings;
@ -106,45 +121,34 @@ bool Bookmarks::isBookmarked(const QUrl &url)
// Bookmark search priority:
// Bookmarks in menu > bookmarks in toolbar -> user folders and unsorted
int Bookmarks::bookmarkId(const QUrl &url)
Bookmarks::Bookmark Bookmarks::getBookmark(const QUrl &url)
{
QSqlQuery query;
query.prepare("SELECT id FROM bookmarks WHERE url=? AND folder='bookmarksMenu' ");
query.bindValue(0, url.toString());
query.exec();
if (query.next()) {
return query.value(0).toInt();
return getBookmark(query.value(0).toInt());
}
query.prepare("SELECT id FROM bookmarks WHERE url=? AND folder='bookmarksToolbar' ");
query.bindValue(0, url.toString());
query.exec();
if (query.next()) {
return query.value(0).toInt();
return getBookmark(query.value(0).toInt());
}
query.prepare("SELECT id FROM bookmarks WHERE url=? ");
query.bindValue(0, url.toString());
query.exec();
if (query.next()) {
return query.value(0).toInt();
return getBookmark(query.value(0).toInt());
}
return -1;
}
int Bookmarks::bookmarkId(const QUrl &url, const QString &title, const QString &folder)
{
QSqlQuery query;
query.prepare("SELECT id FROM bookmarks WHERE url=? AND title=? AND folder=? ");
query.bindValue(0, url.toString());
query.bindValue(1, title);
query.bindValue(2, folder);
query.exec();
if (query.next()) {
return query.value(0).toInt();
}
return -1;
return Bookmark();
}
Bookmarks::Bookmark Bookmarks::getBookmark(int id)
@ -260,16 +264,6 @@ void Bookmarks::removeBookmark(const QList<int> list)
mApp->sendMessages(Qz::AM_BookmarksChanged, true);
}
void Bookmarks::removeBookmark(const QUrl &url)
{
removeBookmark(bookmarkId(url));
}
void Bookmarks::removeBookmark(WebView* view)
{
removeBookmark(bookmarkId(view->url()));
}
bool Bookmarks::editBookmark(int id, const QString &title, const QUrl &url, const QString &folder)
{
if (title.isEmpty() && url.isEmpty() && folder.isEmpty()) {
@ -511,7 +505,7 @@ void Bookmarks::exportToHtml(const QString &fileName)
out << "</DL><p>" << endl;
}
QVector<Bookmark> Bookmarks::folderBookmarks(const QString &name)
QVector<Bookmark> Bookmarks::getFolderBookmarks(const QString &name)
{
QVector<Bookmark> list;
@ -565,23 +559,6 @@ bool Bookmarks::isSubfolder(const QString &name)
return query.value(0).toString() == QLatin1String("yes");
}
bool Bookmarks::bookmarksEqual(const Bookmark &one, const Bookmark &two)
{
if (one.id != two.id) {
return false;
}
if (one.title != two.title) {
return false;
}
if (one.folder != two.folder) {
return false;
}
if (one.url != two.url) {
return false;
}
return true;
}
QString Bookmarks::toTranslatedFolder(const QString &name)
{
QString trFolder;

View File

@ -47,10 +47,7 @@ public:
QImage image;
bool inSubfolder;
Bookmark() {
id = -1;
inSubfolder = false;
}
Bookmark() : id(-1) , inSubfolder(false) { }
bool operator==(const Bookmark &other) const {
return (this->title == other.title &&
@ -62,26 +59,26 @@ public:
void loadSettings();
bool isShowingMostVisited() { return m_showMostVisited; }
bool isShowingMostVisited() const;
void setShowingMostVisited(bool state);
bool isShowingOnlyIconsInToolbar() { return m_showOnlyIconsInToolbar; }
bool isShowingOnlyIconsInToolbar() const;
void setShowingOnlyIconsInToolbar(bool state);
bool isFolder(const QString &name);
QString lastFolder() { return m_lastFolder; }
QString lastFolder() const;
void setLastFolder(const QString &folder);
bool isBookmarked(const QUrl &url);
int bookmarkId(const QUrl &url);
int bookmarkId(const QUrl &url, const QString &title, const QString &folder);
Bookmark getBookmark(int id);
bool saveBookmark(const QUrl &url, const QString &title, const QIcon &icon, const QString &folder = "unsorted");
Bookmark getBookmark(int id);
Bookmark getBookmark(const QUrl &url);
QVector<Bookmark> getFolderBookmarks(const QString &name);
bool saveBookmark(const QUrl &url, const QString &title, const QIcon &icon, const QString &folder = QLatin1String("unsorted"));
bool saveBookmark(WebView* view, QString folder = QString());
void removeBookmark(const QUrl &url);
void removeBookmark(WebView* view);
void removeBookmark(int id);
void removeBookmark(const QList<int> list);
@ -90,17 +87,13 @@ public:
bool createFolder(const QString &name);
void removeFolder(const QString &name);
QVector<Bookmark> folderBookmarks(const QString &name);
bool renameFolder(const QString &before, const QString &after);
bool createSubfolder(const QString &name);
bool isSubfolder(const QString &name);
bool renameFolder(const QString &before, const QString &after);
void exportToHtml(const QString &fileName);
static bool bookmarksEqual(const Bookmark &one, const Bookmark &two);
static QString toTranslatedFolder(const QString &name);
static QString fromTranslatedFolder(const QString &name);

View File

@ -342,7 +342,7 @@ void BookmarksToolbar::loadFolderBookmarksInTabs()
return;
}
foreach (const Bookmark &b, m_bookmarks->folderBookmarks(folder)) {
foreach (const Bookmark &b, m_bookmarks->getFolderBookmarks(folder)) {
p_QupZilla->tabWidget()->addView(b.url, b.title, Qz::NT_NotSelectedTab);
}
}
@ -629,7 +629,7 @@ void BookmarksToolbar::aboutToShowFolderMenu()
menu->clear();
QString folder = menu->title();
foreach (const Bookmark &b, m_bookmarks->folderBookmarks(folder)) {
foreach (const Bookmark &b, m_bookmarks->getFolderBookmarks(folder)) {
QString title = b.title;
if (title.length() > 40) {
title.truncate(40);

View File

@ -74,11 +74,10 @@ void BookmarksWidget::loadBookmark()
// Bookmark folders
m_bookmarksTree->refreshTree();
m_bookmarkId = m_bookmarks->bookmarkId(m_url);
Bookmarks::Bookmark bookmark = m_bookmarks->getBookmark(m_bookmarkId);
m_bookmarkId = bookmark.id;
if (m_bookmarkId > 0) {
Bookmarks::Bookmark bookmark = m_bookmarks->getBookmark(m_bookmarkId);
int index = ui->folder->findData(bookmark.folder);
// QComboBox::findData() returns index related to the item's parent
if (index == -1) { // subfolder
@ -139,7 +138,7 @@ void BookmarksWidget::on_saveRemove_clicked(bool)
m_bookmarks->editBookmark(m_bookmarkId, m_view->title(), QUrl(), Bookmarks::fromTranslatedFolder(ui->folder->currentText()));
}
else {
m_bookmarks->removeBookmark(m_url);
m_bookmarks->removeBookmark(m_bookmarkId);
emit bookmarkDeleted();
}
}

View File

@ -313,7 +313,7 @@ void BookmarksSideBar::changeFolderParent(const QString &name, bool isSubfolder)
}
else {
addFolder(name);
QVector<Bookmark> bookmarksList = m_bookmarks->folderBookmarks(name);
QVector<Bookmark> bookmarksList = m_bookmarks->getFolderBookmarks(name);
foreach (const Bookmark &b, bookmarksList) {
addBookmark(b);
}