2011-04-15 20:45:22 +02:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2014-01-11 16:11:42 +01:00
|
|
|
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
|
2011-04-15 20:45:22 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* ============================================================ */
|
|
|
|
#include "bookmarkssidebar.h"
|
|
|
|
#include "mainapplication.h"
|
|
|
|
#include "ui_bookmarkssidebar.h"
|
|
|
|
#include "qupzilla.h"
|
2011-04-25 20:56:45 +02:00
|
|
|
#include "iconprovider.h"
|
2012-01-21 20:27:45 +01:00
|
|
|
#include "tabbedwebview.h"
|
2011-04-15 20:45:22 +02:00
|
|
|
#include "bookmarkstoolbar.h"
|
|
|
|
#include "tabwidget.h"
|
2014-02-05 15:26:51 +01:00
|
|
|
#include "bookmarks.h"
|
2012-08-10 21:16:43 +02:00
|
|
|
#include "qzsettings.h"
|
2011-04-15 20:45:22 +02:00
|
|
|
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QMenu>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QClipboard>
|
|
|
|
#include <QSqlQuery>
|
2012-09-02 15:53:00 +02:00
|
|
|
#include <QKeyEvent>
|
2012-02-29 18:33:50 +01:00
|
|
|
|
2011-10-18 21:07:58 +02:00
|
|
|
BookmarksSideBar::BookmarksSideBar(QupZilla* mainClass, QWidget* parent)
|
|
|
|
: QWidget(parent)
|
|
|
|
, m_isRefreshing(false)
|
|
|
|
, ui(new Ui::BookmarksSideBar)
|
|
|
|
, p_QupZilla(mainClass)
|
2014-02-05 15:26:51 +01:00
|
|
|
, m_bookmarks(mApp->bookmarks())
|
2011-04-15 20:45:22 +02:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2013-01-09 13:59:37 +01:00
|
|
|
ui->bookmarksTree->setViewType(BookmarksTree::SideBarView);
|
2011-04-15 20:45:22 +02:00
|
|
|
|
2012-09-05 23:52:40 +02:00
|
|
|
ui->bookmarksTree->setSelectionBehavior(QAbstractItemView::SelectRows);
|
2014-02-05 15:26:51 +01:00
|
|
|
ui->bookmarksTree->setDragDropReceiver(true, m_bookmarks);
|
2012-09-06 11:28:43 +02:00
|
|
|
ui->bookmarksTree->setMimeType(QLatin1String("application/qupzilla.treewidgetitem.bookmarks"));
|
2012-09-05 23:52:40 +02:00
|
|
|
|
2014-01-04 22:37:18 +01:00
|
|
|
ui->expandAll->setIcon(QIcon::fromTheme("view-sort-ascending", QIcon(":/icons/theme/expand.png")));
|
|
|
|
ui->collapseAll->setIcon(QIcon::fromTheme("view-sort-descending", QIcon(":/icons/theme/collapse.png")));
|
2014-01-01 12:29:19 +01:00
|
|
|
|
2011-07-30 17:57:14 +02:00
|
|
|
ui->bookmarksTree->setDefaultItemShowMode(TreeWidget::ItemsExpanded);
|
2013-03-06 09:05:41 +01:00
|
|
|
connect(ui->bookmarksTree, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequested(QPoint)));
|
2011-04-15 20:45:22 +02:00
|
|
|
connect(ui->bookmarksTree, SIGNAL(itemControlClicked(QTreeWidgetItem*)), this, SLOT(itemControlClicked(QTreeWidgetItem*)));
|
2011-10-18 21:07:58 +02:00
|
|
|
connect(ui->bookmarksTree, SIGNAL(itemMiddleButtonClicked(QTreeWidgetItem*)), this, SLOT(itemControlClicked(QTreeWidgetItem*)));
|
2013-03-06 09:05:41 +01:00
|
|
|
connect(ui->bookmarksTree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), this, SLOT(itemDoubleClicked(QTreeWidgetItem*)));
|
2011-07-30 17:57:14 +02:00
|
|
|
connect(ui->search, SIGNAL(textChanged(QString)), ui->bookmarksTree, SLOT(filterString(QString)));
|
2014-01-01 12:29:19 +01:00
|
|
|
connect(ui->collapseAll, SIGNAL(clicked()), ui->bookmarksTree, SLOT(collapseAll()));
|
|
|
|
connect(ui->expandAll, SIGNAL(clicked()), ui->bookmarksTree, SLOT(expandAll()));
|
2011-04-15 20:45:22 +02:00
|
|
|
|
2014-02-05 15:26:51 +01:00
|
|
|
connect(m_bookmarks, SIGNAL(bookmarkAdded(Bookmarks::Bookmark)), this, SLOT(addBookmark(Bookmarks::Bookmark)));
|
|
|
|
connect(m_bookmarks, SIGNAL(bookmarkDeleted(Bookmarks::Bookmark)), this, SLOT(removeBookmark(Bookmarks::Bookmark)));
|
|
|
|
connect(m_bookmarks, SIGNAL(bookmarkEdited(Bookmarks::Bookmark,Bookmarks::Bookmark)),
|
|
|
|
this, SLOT(bookmarkEdited(Bookmarks::Bookmark,Bookmarks::Bookmark)));
|
|
|
|
connect(m_bookmarks, SIGNAL(folderAdded(QString)), this, SLOT(addFolder(QString)));
|
|
|
|
connect(m_bookmarks, SIGNAL(folderDeleted(QString)), this, SLOT(removeFolder(QString)));
|
|
|
|
connect(m_bookmarks, SIGNAL(folderRenamed(QString,QString)), this, SLOT(renameFolder(QString,QString)));
|
|
|
|
connect(m_bookmarks, SIGNAL(folderParentChanged(QString,bool)), this, SLOT(changeFolderParent(QString,bool)));
|
|
|
|
connect(m_bookmarks, SIGNAL(bookmarkParentChanged(QString,QByteArray,int,QUrl,QString,QString)),
|
2013-03-06 09:05:41 +01:00
|
|
|
this, SLOT(changeBookmarkParent(QString,QByteArray,int,QUrl,QString,QString)));
|
2011-04-15 20:45:22 +02:00
|
|
|
|
|
|
|
QTimer::singleShot(0, this, SLOT(refreshTable()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksSideBar::itemControlClicked(QTreeWidgetItem* item)
|
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!item || item->text(1).isEmpty()) {
|
2011-04-15 20:45:22 +02:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-12-04 16:54:57 +01:00
|
|
|
|
2013-12-30 13:43:48 +01:00
|
|
|
const QUrl url = QUrl::fromEncoded(item->text(1).toUtf8());
|
2011-12-20 18:58:42 +01:00
|
|
|
p_QupZilla->tabWidget()->addView(url, item->text(0));
|
2011-04-15 20:45:22 +02:00
|
|
|
}
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
void BookmarksSideBar::itemDoubleClicked(QTreeWidgetItem* item)
|
2011-04-15 20:45:22 +02:00
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!item || item->text(1).isEmpty()) {
|
2011-04-15 20:45:22 +02:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-12-04 16:54:57 +01:00
|
|
|
|
2013-12-30 13:43:48 +01:00
|
|
|
const QUrl url = QUrl::fromEncoded(item->text(1).toUtf8());
|
2011-12-04 16:54:57 +01:00
|
|
|
p_QupZilla->loadAddress(url);
|
2011-04-15 20:45:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksSideBar::loadInNewTab()
|
|
|
|
{
|
2012-09-02 15:19:12 +02:00
|
|
|
QTreeWidgetItem* item = ui->bookmarksTree->currentItem();
|
|
|
|
QAction* action = qobject_cast<QAction*>(sender());
|
|
|
|
|
|
|
|
if (!item || !action) {
|
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2012-09-02 15:19:12 +02:00
|
|
|
|
|
|
|
p_QupZilla->tabWidget()->addView(action->data().toUrl(), item->text(0), qzSettings->newTabPosition);
|
2011-04-15 20:45:22 +02:00
|
|
|
}
|
|
|
|
|
2011-10-28 17:52:42 +02:00
|
|
|
void BookmarksSideBar::copyAddress()
|
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (QAction* action = qobject_cast<QAction*>(sender())) {
|
2011-12-04 16:54:57 +01:00
|
|
|
QApplication::clipboard()->setText(action->data().toUrl().toEncoded());
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-10-28 17:52:42 +02:00
|
|
|
}
|
|
|
|
|
2011-04-15 20:45:22 +02:00
|
|
|
void BookmarksSideBar::deleteItem()
|
|
|
|
{
|
|
|
|
QTreeWidgetItem* item = ui->bookmarksTree->currentItem();
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!item) {
|
2011-04-15 20:45:22 +02:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-04-15 20:45:22 +02:00
|
|
|
|
2012-03-13 17:51:06 +01:00
|
|
|
int id = item->data(0, Qt::UserRole + 10).toInt();
|
2014-02-05 15:26:51 +01:00
|
|
|
m_bookmarks->removeBookmark(id);
|
2011-04-15 20:45:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksSideBar::contextMenuRequested(const QPoint &position)
|
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!ui->bookmarksTree->itemAt(position)) {
|
2011-04-15 20:45:22 +02:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-12-04 16:54:57 +01:00
|
|
|
QUrl link = QUrl::fromEncoded(ui->bookmarksTree->itemAt(position)->text(1).toUtf8());
|
2011-11-06 17:01:23 +01:00
|
|
|
if (link.isEmpty()) {
|
2011-04-15 20:45:22 +02:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-04-15 20:45:22 +02:00
|
|
|
|
|
|
|
QMenu menu;
|
2012-01-25 15:46:18 +01:00
|
|
|
menu.addAction(tr("Open link in current &tab"), p_QupZilla, SLOT(loadActionUrl()))->setData(link);
|
2011-04-15 20:45:22 +02:00
|
|
|
menu.addAction(tr("Open link in &new tab"), this, SLOT(loadInNewTab()))->setData(link);
|
2011-10-28 17:52:42 +02:00
|
|
|
menu.addAction(tr("Copy address"), this, SLOT(copyAddress()))->setData(link);
|
2011-04-15 20:45:22 +02:00
|
|
|
menu.addSeparator();
|
|
|
|
menu.addAction(tr("&Delete"), this, SLOT(deleteItem()));
|
2011-10-28 17:52:42 +02:00
|
|
|
|
2011-04-15 20:45:22 +02:00
|
|
|
//Prevent choosing first option with double rightclick
|
2012-04-11 18:06:50 +02:00
|
|
|
QPoint pos = ui->bookmarksTree->viewport()->mapToGlobal(position);
|
2011-11-06 17:01:23 +01:00
|
|
|
QPoint p(pos.x(), pos.y() + 1);
|
2011-04-15 20:45:22 +02:00
|
|
|
menu.exec(p);
|
|
|
|
}
|
|
|
|
|
2014-02-05 15:26:51 +01:00
|
|
|
void BookmarksSideBar::addBookmark(const Bookmarks::Bookmark &bookmark)
|
2011-04-15 20:45:22 +02:00
|
|
|
{
|
2014-02-05 15:26:51 +01:00
|
|
|
QString translatedFolder = Bookmarks::toTranslatedFolder(bookmark.folder);
|
2011-04-15 20:45:22 +02:00
|
|
|
QTreeWidgetItem* item = new QTreeWidgetItem();
|
|
|
|
item->setText(0, bookmark.title);
|
|
|
|
item->setText(1, bookmark.url.toEncoded());
|
2012-03-13 17:51:06 +01:00
|
|
|
item->setData(0, Qt::UserRole + 10, bookmark.id);
|
2012-04-22 20:51:28 +02:00
|
|
|
item->setIcon(0, qIconProvider->iconFromImage(bookmark.image));
|
2011-04-15 20:45:22 +02:00
|
|
|
item->setToolTip(0, bookmark.url.toEncoded());
|
2012-09-05 23:52:40 +02:00
|
|
|
item->setFlags(item->flags() | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled);
|
2011-04-15 20:45:22 +02:00
|
|
|
|
2012-09-05 19:57:36 +02:00
|
|
|
if (bookmark.folder != QLatin1String("unsorted")) {
|
2011-07-30 17:57:14 +02:00
|
|
|
ui->bookmarksTree->appendToParentItem(translatedFolder, item);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
else {
|
2011-04-15 20:45:22 +02:00
|
|
|
ui->bookmarksTree->addTopLevelItem(item);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-04-15 20:45:22 +02:00
|
|
|
|
|
|
|
// if (!ui->search->text().isEmpty())
|
2011-11-06 17:01:23 +01:00
|
|
|
item->setHidden(!bookmark.title.contains(ui->search->text(), Qt::CaseInsensitive));
|
2011-04-15 20:45:22 +02:00
|
|
|
}
|
|
|
|
|
2014-02-05 15:26:51 +01:00
|
|
|
void BookmarksSideBar::removeBookmark(const Bookmarks::Bookmark &bookmark)
|
2011-04-15 20:45:22 +02:00
|
|
|
{
|
2012-09-04 12:42:45 +02:00
|
|
|
if (bookmark.folder == QLatin1String("unsorted")) {
|
2011-04-17 13:03:29 +02:00
|
|
|
QList<QTreeWidgetItem*> list = ui->bookmarksTree->findItems(bookmark.title, Qt::MatchExactly);
|
2011-11-06 17:01:23 +01:00
|
|
|
if (list.count() == 0) {
|
2011-04-17 13:03:29 +02:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-04-17 13:03:29 +02:00
|
|
|
QTreeWidgetItem* item = list.at(0);
|
2012-03-13 17:51:06 +01:00
|
|
|
if (item && item->data(0, Qt::UserRole + 10).toInt() == bookmark.id) {
|
2011-07-30 17:57:14 +02:00
|
|
|
ui->bookmarksTree->deleteItem(item);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2014-02-05 15:26:51 +01:00
|
|
|
QList<QTreeWidgetItem*> list = ui->bookmarksTree->findItems(Bookmarks::toTranslatedFolder(bookmark.folder), Qt::MatchExactly);
|
2011-11-06 17:01:23 +01:00
|
|
|
if (list.count() == 0) {
|
2011-04-17 13:03:29 +02:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-04-17 13:03:29 +02:00
|
|
|
QTreeWidgetItem* parentItem = list.at(0);
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!parentItem) {
|
2011-04-15 20:45:22 +02:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-04-15 20:45:22 +02:00
|
|
|
for (int i = 0; i < parentItem->childCount(); i++) {
|
|
|
|
QTreeWidgetItem* item = parentItem->child(i);
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!item) {
|
2011-04-15 20:45:22 +02:00
|
|
|
continue;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2012-03-13 17:51:06 +01:00
|
|
|
if (item->text(0) == bookmark.title && item->data(0, Qt::UserRole + 10).toInt() == bookmark.id) {
|
2011-07-30 17:57:14 +02:00
|
|
|
ui->bookmarksTree->deleteItem(item);
|
2011-04-15 20:45:22 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-05 15:26:51 +01:00
|
|
|
void BookmarksSideBar::bookmarkEdited(const Bookmarks::Bookmark &before, const Bookmarks::Bookmark &after)
|
2011-04-15 20:45:22 +02:00
|
|
|
{
|
|
|
|
removeBookmark(before);
|
|
|
|
addBookmark(after);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksSideBar::addFolder(const QString &name)
|
|
|
|
{
|
|
|
|
QTreeWidgetItem* item = new QTreeWidgetItem(ui->bookmarksTree);
|
|
|
|
item->setText(0, name);
|
|
|
|
item->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon));
|
2012-09-05 23:52:40 +02:00
|
|
|
|
|
|
|
if (name != _bookmarksToolbar && name != _bookmarksMenu) {
|
|
|
|
item->setFlags(item->flags() | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled);
|
|
|
|
}
|
|
|
|
else {
|
2012-09-06 11:28:43 +02:00
|
|
|
item->setFlags((item->flags() & ~Qt::ItemIsDragEnabled) | Qt::ItemIsDropEnabled);
|
2012-09-05 23:52:40 +02:00
|
|
|
}
|
2011-04-15 20:45:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksSideBar::removeFolder(const QString &name)
|
|
|
|
{
|
2011-10-28 17:52:42 +02:00
|
|
|
QList<QTreeWidgetItem*> list = ui->bookmarksTree->findItems(name, Qt::MatchExactly);
|
2011-11-06 17:01:23 +01:00
|
|
|
if (list.count() == 0) {
|
2011-10-28 17:52:42 +02:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-10-28 17:52:42 +02:00
|
|
|
QTreeWidgetItem* item = list.at(0);
|
2011-11-06 17:01:23 +01:00
|
|
|
if (item) {
|
2011-07-30 17:57:14 +02:00
|
|
|
ui->bookmarksTree->deleteItem(item);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-04-15 20:45:22 +02:00
|
|
|
}
|
|
|
|
|
2011-10-28 17:52:42 +02:00
|
|
|
void BookmarksSideBar::renameFolder(const QString &before, const QString &after)
|
|
|
|
{
|
|
|
|
QList<QTreeWidgetItem*> list = ui->bookmarksTree->findItems(before, Qt::MatchExactly);
|
2011-11-06 17:01:23 +01:00
|
|
|
if (list.count() == 0) {
|
2011-10-28 17:52:42 +02:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-10-28 17:52:42 +02:00
|
|
|
QTreeWidgetItem* item = list.at(0);
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!item) {
|
2011-10-28 17:52:42 +02:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-10-28 17:52:42 +02:00
|
|
|
|
|
|
|
item->setText(0, after);
|
|
|
|
}
|
|
|
|
|
2012-09-05 23:52:40 +02:00
|
|
|
void BookmarksSideBar::changeBookmarkParent(const QString &name, const QByteArray &imageData, int id,
|
2012-09-06 11:28:43 +02:00
|
|
|
const QUrl &url, const QString &oldParent, const QString &newParent)
|
2012-09-05 23:52:40 +02:00
|
|
|
{
|
|
|
|
if (!newParent.isEmpty() && newParent != QLatin1String("unsorted")
|
|
|
|
&& newParent != _bookmarksUnsorted && !oldParent.isEmpty()
|
|
|
|
&& oldParent != QLatin1String("unsorted")
|
|
|
|
&& oldParent != _bookmarksUnsorted) { // old and new parent are not invisibleRootItem()
|
|
|
|
QList<QTreeWidgetItem*> list = ui->bookmarksTree->findItems(newParent, Qt::MatchExactly);
|
|
|
|
if (list.isEmpty()) { // newParent is a subfolder
|
|
|
|
list = ui->bookmarksTree->findItems(oldParent, Qt::MatchExactly);
|
|
|
|
if (list.isEmpty()) { // oldParent is a subfolder
|
|
|
|
return; // item was reparented from bookmarkToolbar(subfolder) to subfolder(bookmarkToolbar)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<QTreeWidgetItem*> list = ui->bookmarksTree->findItems(name, Qt::MatchExactly | Qt::MatchRecursive);
|
|
|
|
|
|
|
|
QTreeWidgetItem* item = 0;
|
2013-03-06 09:05:41 +01:00
|
|
|
foreach (item, list) {
|
2012-09-05 23:52:40 +02:00
|
|
|
if (id == item->data(0, Qt::UserRole + 10).toInt()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!item || id != item->data(0, Qt::UserRole + 10).toInt()) { // list is empty or item with 'id' was not found
|
|
|
|
// bookmark's oldParent was bookmarkToolbar(subfolder)
|
|
|
|
Bookmark bookmark;
|
|
|
|
bookmark.id = id;
|
|
|
|
bookmark.url = url;
|
|
|
|
bookmark.title = name;
|
2014-02-05 15:26:51 +01:00
|
|
|
bookmark.folder = Bookmarks::fromTranslatedFolder(newParent.isEmpty() ? QLatin1String("unsorted") : newParent);
|
2012-09-05 23:52:40 +02:00
|
|
|
bookmark.image = QImage::fromData(imageData);
|
|
|
|
bookmark.inSubfolder = false;
|
|
|
|
addBookmark(bookmark);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QTreeWidgetItem* parent = 0;
|
|
|
|
if (newParent.isEmpty() || newParent == QLatin1String("unsorted") || newParent == _bookmarksUnsorted) {
|
|
|
|
parent = ui->bookmarksTree->invisibleRootItem();
|
|
|
|
}
|
|
|
|
item->parent() ? item->parent()->removeChild(item) : ui->bookmarksTree->invisibleRootItem()->removeChild(item);
|
|
|
|
|
|
|
|
if (!parent) {
|
|
|
|
list = ui->bookmarksTree->findItems(newParent, Qt::MatchExactly);
|
|
|
|
if (list.count() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
parent = list.at(0);
|
|
|
|
if (!parent) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
parent->addChild(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksSideBar::changeFolderParent(const QString &name, bool isSubfolder)
|
|
|
|
{
|
|
|
|
if (isSubfolder) { // folder moved to _bookmarksToolbar as a subfolder
|
|
|
|
removeFolder(name);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
addFolder(name);
|
2014-02-05 16:44:19 +01:00
|
|
|
QVector<Bookmark> bookmarksList = m_bookmarks->getFolderBookmarks(name);
|
2013-03-06 09:05:41 +01:00
|
|
|
foreach (const Bookmark &b, bookmarksList) {
|
2012-09-05 23:52:40 +02:00
|
|
|
addBookmark(b);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-02 15:53:00 +02:00
|
|
|
void BookmarksSideBar::keyPressEvent(QKeyEvent* event)
|
|
|
|
{
|
|
|
|
if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) {
|
|
|
|
QTreeWidgetItem* item = ui->bookmarksTree->currentItem();
|
|
|
|
|
|
|
|
if (event->modifiers() & Qt::ControlModifier) {
|
|
|
|
itemControlClicked(item);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
itemDoubleClicked(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QWidget::keyPressEvent(event);
|
|
|
|
}
|
|
|
|
|
2011-04-15 20:45:22 +02:00
|
|
|
void BookmarksSideBar::refreshTable()
|
|
|
|
{
|
|
|
|
m_isRefreshing = true;
|
2013-01-09 13:59:37 +01:00
|
|
|
ui->bookmarksTree->refreshTree();
|
2011-04-15 20:45:22 +02:00
|
|
|
m_isRefreshing = false;
|
2012-09-02 15:53:00 +02:00
|
|
|
|
|
|
|
ui->search->setFocus();
|
2011-04-15 20:45:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
BookmarksSideBar::~BookmarksSideBar()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|