2011-03-03 18:29:20 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2014-01-11 16:11:42 +01:00
|
|
|
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
|
2011-03-03 18:29:20 +01: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/>.
|
|
|
|
* ============================================================ */
|
2011-03-02 16:57:41 +01:00
|
|
|
#include "mainapplication.h"
|
|
|
|
#include "bookmarksmanager.h"
|
|
|
|
#include "ui_bookmarksmanager.h"
|
|
|
|
#include "qupzilla.h"
|
2012-01-21 20:27:45 +01:00
|
|
|
#include "tabbedwebview.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
#include "bookmarkstoolbar.h"
|
|
|
|
#include "tabwidget.h"
|
2014-02-05 15:26:51 +01:00
|
|
|
#include "bookmarks.h"
|
2011-04-25 20:56:45 +02:00
|
|
|
#include "iconprovider.h"
|
2011-07-30 17:57:14 +02:00
|
|
|
#include "browsinglibrary.h"
|
2013-01-22 19:04:22 +01:00
|
|
|
#include "qztools.h"
|
2011-12-12 21:14:43 +01:00
|
|
|
#include "bookmarksimportdialog.h"
|
2012-05-22 11:46:22 +02:00
|
|
|
#include "iconchooser.h"
|
2012-01-21 23:19:38 +01:00
|
|
|
#include "webtab.h"
|
2012-08-10 21:16:43 +02:00
|
|
|
#include "qzsettings.h"
|
2014-02-08 18:14:38 +01:00
|
|
|
#include "bookmarkstree.h"
|
|
|
|
#include "bookmarkitem.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QInputDialog>
|
|
|
|
#include <QComboBox>
|
|
|
|
#include <QDialogButtonBox>
|
|
|
|
#include <QShortcut>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QSqlQuery>
|
2013-12-30 00:35:01 +01:00
|
|
|
#include <QLabel>
|
2012-02-29 18:33:50 +01:00
|
|
|
|
2014-02-08 18:14:38 +01:00
|
|
|
#include <QDebug>
|
|
|
|
|
2011-10-28 17:52:42 +02:00
|
|
|
BookmarksManager::BookmarksManager(QupZilla* mainClass, QWidget* parent)
|
|
|
|
: QWidget(parent)
|
|
|
|
, ui(new Ui::BookmarksManager)
|
|
|
|
, p_QupZilla(mainClass)
|
2014-02-05 15:26:51 +01:00
|
|
|
, m_bookmarks(mApp->bookmarks())
|
2014-02-08 18:14:38 +01:00
|
|
|
, m_blockDescriptionChangedSignal(false)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2014-02-08 18:14:38 +01:00
|
|
|
|
|
|
|
connect(ui->tree, SIGNAL(bookmarkActivated(BookmarkItem*)), this, SLOT(bookmarkActivated(BookmarkItem*)));
|
|
|
|
connect(ui->tree, SIGNAL(bookmarkCtrlActivated(BookmarkItem*)), this, SLOT(bookmarkCtrlActivated(BookmarkItem*)));
|
|
|
|
connect(ui->tree, SIGNAL(bookmarkShiftActivated(BookmarkItem*)), this, SLOT(bookmarkShiftActivated(BookmarkItem*)));
|
|
|
|
connect(ui->tree, SIGNAL(bookmarksSelected(QList<BookmarkItem*>)), this, SLOT(bookmarksSelected(QList<BookmarkItem*>)));
|
|
|
|
|
|
|
|
// Disable edit box
|
|
|
|
updateEditBox(0);
|
|
|
|
|
|
|
|
connect(ui->title, SIGNAL(textEdited(QString)), this, SLOT(bookmarkEdited()));
|
|
|
|
connect(ui->address, SIGNAL(textEdited(QString)), this, SLOT(bookmarkEdited()));
|
|
|
|
connect(ui->keyword, SIGNAL(textEdited(QString)), this, SLOT(bookmarkEdited()));
|
|
|
|
connect(ui->description, SIGNAL(textChanged()), this, SLOT(descriptionEdited()));
|
|
|
|
|
|
|
|
#if 0
|
2013-01-09 13:59:37 +01:00
|
|
|
ui->bookmarksTree->setViewType(BookmarksTree::ManagerView);
|
2011-03-02 16:57:41 +01: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
|
|
|
|
2013-03-06 09:05:41 +01:00
|
|
|
connect(ui->bookmarksTree, SIGNAL(itemChanged(QTreeWidgetItem*,int)), this, SLOT(itemChanged(QTreeWidgetItem*)));
|
2011-03-02 16:57:41 +01:00
|
|
|
connect(ui->addFolder, SIGNAL(clicked()), this, SLOT(addFolder()));
|
2013-03-06 09:05:41 +01:00
|
|
|
connect(ui->bookmarksTree, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequested(QPoint)));
|
2011-03-02 16:57:41 +01: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-01-10 17:48:35 +01:00
|
|
|
connect(ui->collapseAll, SIGNAL(clicked()), ui->bookmarksTree, SLOT(collapseAll()));
|
|
|
|
connect(ui->expandAll, SIGNAL(clicked()), ui->bookmarksTree, SLOT(expandAll()));
|
2011-04-17 13:03:29 +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(subfolderAdded(QString)), this, SLOT(addSubfolder(QString)));
|
|
|
|
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)), this, SLOT(changeBookmarkParent(QString,QByteArray,int,QUrl,QString,QString)));
|
2011-04-17 13:03:29 +02:00
|
|
|
|
2013-12-30 00:35:01 +01:00
|
|
|
QMenu* menu = new QMenu;
|
|
|
|
menu->addAction(tr("Import Bookmarks..."), this, SLOT(importBookmarks()));
|
|
|
|
menu->addAction(tr("Export Bookmarks to HTML..."), this, SLOT(exportBookmarks()));
|
|
|
|
|
|
|
|
ui->importExport->setMenu(menu);
|
2011-12-12 21:14:43 +01:00
|
|
|
|
|
|
|
QShortcut* deleteAction = new QShortcut(QKeySequence("Del"), ui->bookmarksTree);
|
|
|
|
connect(deleteAction, SIGNAL(activated()), this, SLOT(deleteItem()));
|
2011-07-30 17:57:14 +02:00
|
|
|
|
|
|
|
ui->bookmarksTree->setDefaultItemShowMode(TreeWidget::ItemsExpanded);
|
2012-09-01 13:56:00 +02:00
|
|
|
ui->bookmarksTree->sortByColumn(-1);
|
2014-02-08 18:14:38 +01:00
|
|
|
#endif
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2014-02-08 18:14:38 +01:00
|
|
|
BookmarksManager::~BookmarksManager()
|
2011-12-12 21:14:43 +01:00
|
|
|
{
|
2014-02-08 18:14:38 +01:00
|
|
|
delete ui;
|
2011-12-12 21:14:43 +01:00
|
|
|
}
|
|
|
|
|
2014-02-08 18:14:38 +01:00
|
|
|
void BookmarksManager::bookmarkActivated(BookmarkItem* item)
|
2013-12-30 00:35:01 +01:00
|
|
|
{
|
2014-02-08 18:14:38 +01:00
|
|
|
// TODO: Open all children in tabs for folder?
|
2014-02-08 18:28:01 +01:00
|
|
|
if (!item->isUrl()) {
|
2014-02-08 18:14:38 +01:00
|
|
|
return;
|
2013-12-30 00:35:01 +01:00
|
|
|
}
|
|
|
|
|
2014-02-08 18:14:38 +01:00
|
|
|
getQupZilla()->loadAddress(item->url());
|
2011-07-30 17:57:14 +02:00
|
|
|
}
|
|
|
|
|
2014-02-08 18:14:38 +01:00
|
|
|
void BookmarksManager::bookmarkCtrlActivated(BookmarkItem* item)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2014-02-08 18:28:01 +01:00
|
|
|
if (!item->isUrl()) {
|
2014-02-08 18:14:38 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2014-02-08 18:14:38 +01:00
|
|
|
getQupZilla()->tabWidget()->addView(item->url(), item->title(), qzSettings->newTabPosition);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2014-02-08 18:14:38 +01:00
|
|
|
void BookmarksManager::bookmarkShiftActivated(BookmarkItem* item)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2014-02-08 18:28:01 +01:00
|
|
|
if (!item->isUrl()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-04-15 20:45:22 +02:00
|
|
|
|
2014-02-08 18:14:38 +01:00
|
|
|
mApp->makeNewWindow(Qz::BW_NewWindow, item->url());
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksManager::bookmarksSelected(const QList<BookmarkItem*> &items)
|
|
|
|
{
|
|
|
|
if (items.size() != 1) {
|
|
|
|
updateEditBox(0);
|
2013-01-09 13:59:37 +01:00
|
|
|
}
|
|
|
|
else {
|
2014-02-08 18:14:38 +01:00
|
|
|
updateEditBox(items.first());
|
2013-01-09 13:59:37 +01:00
|
|
|
}
|
2014-02-08 18:14:38 +01:00
|
|
|
}
|
2013-01-09 13:59:37 +01:00
|
|
|
|
2014-02-08 18:14:38 +01:00
|
|
|
void BookmarksManager::bookmarkEdited()
|
|
|
|
{
|
|
|
|
Q_ASSERT(ui->tree->selectedBookmarks().count() == 1);
|
2013-01-09 13:59:37 +01:00
|
|
|
|
2014-02-08 18:14:38 +01:00
|
|
|
BookmarkItem* item = ui->tree->selectedBookmarks().first();
|
|
|
|
item->setTitle(ui->title->text());
|
|
|
|
item->setUrl(QUrl::fromEncoded(ui->address->text().toUtf8()));
|
|
|
|
item->setKeyword(ui->keyword->text());
|
|
|
|
item->setDescription(ui->description->toPlainText());
|
|
|
|
|
|
|
|
m_bookmarks->notifyBookmarkChanged(item);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2014-02-08 18:14:38 +01:00
|
|
|
void BookmarksManager::descriptionEdited()
|
2011-10-28 17:52:42 +02:00
|
|
|
{
|
2014-02-08 18:14:38 +01:00
|
|
|
// There is no textEdited() signal in QPlainTextEdit
|
|
|
|
// textChanged() is emitted also when text is changed programatically
|
|
|
|
if (!m_blockDescriptionChangedSignal) {
|
|
|
|
bookmarkEdited();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2014-02-08 18:14:38 +01:00
|
|
|
}
|
2011-10-28 17:52:42 +02:00
|
|
|
|
2014-02-08 18:14:38 +01:00
|
|
|
void BookmarksManager::importBookmarks()
|
|
|
|
{
|
|
|
|
BookmarksImportDialog* b = new BookmarksImportDialog(this);
|
|
|
|
b->show();
|
2011-10-28 17:52:42 +02:00
|
|
|
}
|
|
|
|
|
2014-02-08 18:14:38 +01:00
|
|
|
void BookmarksManager::exportBookmarks()
|
2011-10-28 17:52:42 +02:00
|
|
|
{
|
2014-02-08 18:14:38 +01:00
|
|
|
QString file = QzTools::getSaveFileName("BookmarksManager-Export", this, tr("Export to HTML..."), QDir::homePath() + "/bookmarks.html");
|
2011-10-28 17:52:42 +02:00
|
|
|
|
2014-02-08 18:14:38 +01:00
|
|
|
if (!file.isEmpty()) {
|
|
|
|
m_bookmarks->exportToHtml(file);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2014-02-08 18:14:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksManager::updateEditBox(BookmarkItem* item)
|
|
|
|
{
|
|
|
|
setUpdatesEnabled(false);
|
|
|
|
m_blockDescriptionChangedSignal = true;
|
2011-10-28 17:52:42 +02:00
|
|
|
|
2014-02-08 18:28:01 +01:00
|
|
|
bool editable = item && !item->isSeparator() && m_bookmarks->canBeModified(item);
|
|
|
|
bool showAddressAndKeyword = item && item->isUrl();
|
2014-02-08 18:14:38 +01:00
|
|
|
bool clearBox = !item;
|
2011-10-28 17:52:42 +02:00
|
|
|
|
2014-02-08 18:14:38 +01:00
|
|
|
if (clearBox) {
|
|
|
|
ui->title->clear();
|
|
|
|
ui->address->clear();
|
|
|
|
ui->keyword->clear();
|
|
|
|
ui->description->clear();
|
2011-10-28 17:52:42 +02:00
|
|
|
|
2014-02-08 18:14:38 +01:00
|
|
|
ui->title->setReadOnly(true);
|
|
|
|
ui->address->setReadOnly(true);
|
|
|
|
ui->keyword->setReadOnly(true);
|
|
|
|
ui->description->setReadOnly(true);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ui->title->setText(item->title());
|
|
|
|
ui->address->setText(item->url().toEncoded());
|
|
|
|
ui->keyword->setText(item->keyword());
|
|
|
|
ui->description->setPlainText(item->description());
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-10-28 17:52:42 +02:00
|
|
|
|
2014-02-08 18:14:38 +01:00
|
|
|
ui->title->setReadOnly(!editable);
|
|
|
|
ui->address->setReadOnly(!editable);
|
|
|
|
ui->keyword->setReadOnly(!editable);
|
|
|
|
ui->description->setReadOnly(!editable);
|
2011-10-28 17:52:42 +02:00
|
|
|
|
2014-02-08 18:14:38 +01:00
|
|
|
ui->labelAddress->setVisible(showAddressAndKeyword);
|
|
|
|
ui->address->setVisible(showAddressAndKeyword);
|
|
|
|
ui->labelKeyword->setVisible(showAddressAndKeyword);
|
|
|
|
ui->keyword->setVisible(showAddressAndKeyword);
|
2011-12-12 21:14:43 +01:00
|
|
|
|
2014-02-08 18:14:38 +01:00
|
|
|
// Without removing widgets from layout, there is unwanted extra spacing
|
|
|
|
QFormLayout* l = static_cast<QFormLayout*>(ui->editBox->layout());
|
2011-12-12 21:14:43 +01:00
|
|
|
|
2014-02-08 18:14:38 +01:00
|
|
|
if (showAddressAndKeyword) {
|
|
|
|
// Show Address + Keyword
|
|
|
|
l->insertRow(1, ui->labelAddress, ui->address);
|
|
|
|
l->insertRow(2, ui->labelKeyword, ui->keyword);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Hide Address + Keyword
|
|
|
|
l->removeWidget(ui->labelAddress);
|
|
|
|
l->removeWidget(ui->labelKeyword);
|
|
|
|
l->removeWidget(ui->address);
|
|
|
|
l->removeWidget(ui->keyword);
|
2012-05-22 11:46:22 +02:00
|
|
|
}
|
|
|
|
|
2014-02-08 18:14:38 +01:00
|
|
|
m_blockDescriptionChangedSignal = false;
|
|
|
|
setUpdatesEnabled(true);
|
|
|
|
}
|
2012-05-22 11:46:22 +02:00
|
|
|
|
2014-02-08 18:14:38 +01:00
|
|
|
QupZilla* BookmarksManager::getQupZilla()
|
|
|
|
{
|
|
|
|
if (!p_QupZilla) {
|
|
|
|
p_QupZilla = mApp->getWindow();
|
2012-05-22 11:46:22 +02:00
|
|
|
}
|
2014-02-08 18:14:38 +01:00
|
|
|
return p_QupZilla.data();
|
2012-05-22 11:46:22 +02:00
|
|
|
}
|
|
|
|
|
2014-02-08 18:14:38 +01:00
|
|
|
void BookmarksManager::setMainWindow(QupZilla* window)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2014-02-08 18:14:38 +01:00
|
|
|
if (window) {
|
|
|
|
p_QupZilla = window;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2014-02-08 18:14:38 +01:00
|
|
|
#if 0
|
2011-03-02 16:57:41 +01:00
|
|
|
void BookmarksManager::contextMenuRequested(const QPoint &position)
|
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!ui->bookmarksTree->itemAt(position)) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2012-05-22 11:46:22 +02:00
|
|
|
|
|
|
|
QUrl link = ui->bookmarksTree->itemAt(position)->data(0, Qt::UserRole + 11).toUrl();
|
2011-11-06 17:01:23 +01:00
|
|
|
if (link.isEmpty()) {
|
2011-12-12 21:14:43 +01:00
|
|
|
QString folderName = ui->bookmarksTree->itemAt(position)->text(0);
|
|
|
|
QMenu menu;
|
2011-12-17 14:30:54 +01:00
|
|
|
if (folderName == _bookmarksToolbar) {
|
2011-12-12 21:14:43 +01:00
|
|
|
menu.addAction(tr("Add Subfolder"), this, SLOT(addSubfolder()));
|
|
|
|
menu.addSeparator();
|
|
|
|
}
|
|
|
|
|
2011-12-17 14:30:54 +01:00
|
|
|
if (folderName != _bookmarksToolbar && folderName != _bookmarksMenu) {
|
2011-12-12 21:14:43 +01:00
|
|
|
menu.addAction(tr("Rename folder"), this, SLOT(renameFolder()));
|
|
|
|
menu.addAction(tr("Remove folder"), this, SLOT(deleteItem()));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (menu.actions().count() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Prevent choosing first option with double rightclick
|
2012-04-11 18:06:50 +02:00
|
|
|
QPoint pos = ui->bookmarksTree->viewport()->mapToGlobal(position);
|
2011-12-12 21:14:43 +01:00
|
|
|
QPoint p(pos.x(), pos.y() + 1);
|
|
|
|
menu.exec(p);
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
QMenu menu;
|
2012-01-25 15:46:18 +01:00
|
|
|
menu.addAction(tr("Open link in current &tab"), getQupZilla(), SLOT(loadActionUrl()))->setData(link);
|
2011-04-09 00:22:50 +02:00
|
|
|
menu.addAction(tr("Open link in &new tab"), this, SLOT(loadInNewTab()))->setData(link);
|
2011-03-02 16:57:41 +01:00
|
|
|
menu.addSeparator();
|
|
|
|
|
|
|
|
QMenu moveMenu;
|
2011-04-09 00:22:50 +02:00
|
|
|
moveMenu.setTitle(tr("Move bookmark to &folder"));
|
2014-01-04 22:37:18 +01:00
|
|
|
moveMenu.addAction(QIcon(":icons/theme/unsortedbookmarks.png"), _bookmarksUnsorted, this, SLOT(moveBookmark()))->setData("unsorted");
|
2011-12-17 14:30:54 +01:00
|
|
|
moveMenu.addAction(style()->standardIcon(QStyle::SP_DirOpenIcon), _bookmarksMenu, this, SLOT(moveBookmark()))->setData("bookmarksMenu");
|
|
|
|
moveMenu.addAction(style()->standardIcon(QStyle::SP_DirOpenIcon), _bookmarksToolbar, this, SLOT(moveBookmark()))->setData("bookmarksToolbar");
|
2011-03-02 16:57:41 +01:00
|
|
|
QSqlQuery query;
|
|
|
|
query.exec("SELECT name FROM folders");
|
2011-11-06 17:01:23 +01:00
|
|
|
while (query.next()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
moveMenu.addAction(style()->standardIcon(QStyle::SP_DirIcon), query.value(0).toString(), this, SLOT(moveBookmark()))->setData(query.value(0).toString());
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
menu.addMenu(&moveMenu);
|
|
|
|
|
2011-12-12 21:14:43 +01:00
|
|
|
menu.addSeparator();
|
2012-05-22 11:46:22 +02:00
|
|
|
menu.addAction(tr("Change icon"), this, SLOT(changeIcon()));
|
2011-12-12 21:14:43 +01:00
|
|
|
menu.addAction(tr("Rename bookmark"), this, SLOT(renameBookmark()));
|
|
|
|
menu.addAction(tr("Remove bookmark"), this, SLOT(deleteItem()));
|
|
|
|
|
2011-03-02 16:57:41 +01: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-03-02 16:57:41 +01:00
|
|
|
menu.exec(p);
|
|
|
|
}
|
2014-02-08 18:14:38 +01:00
|
|
|
#endif
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2014-02-08 18:14:38 +01:00
|
|
|
// OLD
|
2012-09-05 23:52:40 +02:00
|
|
|
|
2014-02-08 18:14:38 +01:00
|
|
|
void BookmarksManager::addBookmark(WebView* view)
|
2011-10-28 17:52:42 +02:00
|
|
|
{
|
2014-02-08 18:14:38 +01:00
|
|
|
insertBookmark(view->url(), view->title(), view->icon());
|
2011-04-17 13:03:29 +02:00
|
|
|
}
|
|
|
|
|
2013-01-09 13:59:37 +01:00
|
|
|
void BookmarksManager::insertBookmark(const QUrl &url, const QString &title, const QIcon &icon, const QString &folder)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (url.isEmpty() || title.isEmpty()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
QDialog* dialog = new QDialog(getQupZilla());
|
|
|
|
QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom, dialog);
|
|
|
|
QLabel* label = new QLabel(dialog);
|
|
|
|
QLineEdit* edit = new QLineEdit(dialog);
|
|
|
|
QComboBox* combo = new QComboBox(dialog);
|
2013-01-16 14:52:50 +01:00
|
|
|
BookmarksTree* bookmarksTree = new BookmarksTree(dialog);
|
2013-03-06 09:05:41 +01:00
|
|
|
connect(bookmarksTree, SIGNAL(requestNewFolder(QWidget*,QString*,bool,QString,WebView*)),
|
|
|
|
this, SLOT(addFolder(QWidget*,QString*,bool,QString,WebView*)));
|
2013-01-09 13:59:37 +01:00
|
|
|
bookmarksTree->setViewType(BookmarksTree::ComboFolderView);
|
|
|
|
bookmarksTree->header()->hide();
|
|
|
|
bookmarksTree->setColumnCount(1);
|
|
|
|
combo->setModel(bookmarksTree->model());
|
|
|
|
combo->setView(bookmarksTree);
|
|
|
|
bookmarksTree->refreshTree();
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
QDialogButtonBox* box = new QDialogButtonBox(dialog);
|
|
|
|
box->addButton(QDialogButtonBox::Ok);
|
|
|
|
box->addButton(QDialogButtonBox::Cancel);
|
|
|
|
connect(box, SIGNAL(rejected()), dialog, SLOT(reject()));
|
|
|
|
connect(box, SIGNAL(accepted()), dialog, SLOT(accept()));
|
|
|
|
layout->addWidget(label);
|
|
|
|
layout->addWidget(edit);
|
|
|
|
layout->addWidget(combo);
|
2014-02-05 15:26:51 +01:00
|
|
|
if (m_bookmarks->isBookmarked(url)) {
|
2011-12-16 19:38:29 +01:00
|
|
|
layout->addWidget(new QLabel(tr("<b>Warning: </b>You already have bookmarked this page!")));
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
layout->addWidget(box);
|
|
|
|
|
2014-02-05 15:26:51 +01:00
|
|
|
int index = combo->findText(Bookmarks::toTranslatedFolder(folder.isEmpty() ? m_bookmarks->lastFolder() : folder));
|
2013-01-09 13:59:37 +01:00
|
|
|
// QComboBox::find() returns index related to the item's parent
|
2013-01-10 18:05:02 +01:00
|
|
|
if (index == -1) { // subfolder
|
2013-01-09 13:59:37 +01:00
|
|
|
QModelIndex rootIndex = combo->rootModelIndex();
|
2013-01-16 14:52:50 +01:00
|
|
|
combo->setRootModelIndex(combo->model()->index(combo->findText(_bookmarksToolbar), 0));
|
2014-02-05 15:26:51 +01:00
|
|
|
index = combo->findText(Bookmarks::toTranslatedFolder(folder.isEmpty() ? m_bookmarks->lastFolder() : folder));
|
2013-01-10 18:05:02 +01:00
|
|
|
combo->setCurrentIndex(index);
|
|
|
|
combo->setRootModelIndex(rootIndex);
|
2013-01-09 13:59:37 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
combo->setCurrentIndex(index);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2013-01-09 13:59:37 +01:00
|
|
|
connect(combo, SIGNAL(currentIndexChanged(int)), bookmarksTree, SLOT(activeItemChange(int)));
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-12-16 19:38:29 +01:00
|
|
|
label->setText(tr("Choose name and location of this bookmark."));
|
2011-03-02 16:57:41 +01:00
|
|
|
edit->setText(title);
|
|
|
|
edit->setCursorPosition(0);
|
2011-04-25 20:56:45 +02:00
|
|
|
dialog->setWindowIcon(_iconForUrl(url));
|
2011-03-02 16:57:41 +01:00
|
|
|
dialog->setWindowTitle(tr("Add New Bookmark"));
|
|
|
|
|
|
|
|
QSize size = dialog->size();
|
|
|
|
size.setWidth(350);
|
|
|
|
dialog->resize(size);
|
|
|
|
dialog->exec();
|
2011-11-06 17:01:23 +01:00
|
|
|
if (dialog->result() == QDialog::Rejected) {
|
2013-01-09 13:59:37 +01:00
|
|
|
delete dialog;
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
if (edit->text().isEmpty()) {
|
2013-01-09 13:59:37 +01:00
|
|
|
delete dialog;
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2014-02-05 15:26:51 +01:00
|
|
|
m_bookmarks->saveBookmark(url, edit->text(), icon, Bookmarks::fromTranslatedFolder(combo->currentText()));
|
2011-03-02 16:57:41 +01:00
|
|
|
delete dialog;
|
|
|
|
}
|
|
|
|
|
2014-02-08 18:14:38 +01:00
|
|
|
void BookmarksManager::search(const QString &string)
|
|
|
|
{
|
|
|
|
Q_UNUSED(string)
|
|
|
|
//ui->bookmarksTree->filterString(string);
|
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
void BookmarksManager::insertAllTabs()
|
|
|
|
{
|
|
|
|
QDialog* dialog = new QDialog(getQupZilla());
|
|
|
|
QBoxLayout* layout = new QBoxLayout(QBoxLayout::TopToBottom, dialog);
|
|
|
|
QLabel* label = new QLabel(dialog);
|
|
|
|
QComboBox* combo = new QComboBox(dialog);
|
2013-01-16 14:52:50 +01:00
|
|
|
BookmarksTree* bookmarksTree = new BookmarksTree(dialog);
|
2013-03-06 09:05:41 +01:00
|
|
|
connect(bookmarksTree, SIGNAL(requestNewFolder(QWidget*,QString*,bool,QString,WebView*)),
|
|
|
|
this, SLOT(addFolder(QWidget*,QString*,bool,QString,WebView*)));
|
2013-01-09 13:59:37 +01:00
|
|
|
bookmarksTree->setViewType(BookmarksTree::ComboFolderView);
|
|
|
|
bookmarksTree->header()->hide();
|
|
|
|
bookmarksTree->setColumnCount(1);
|
|
|
|
combo->setModel(bookmarksTree->model());
|
|
|
|
combo->setView(bookmarksTree);
|
2011-03-02 16:57:41 +01:00
|
|
|
QDialogButtonBox* box = new QDialogButtonBox(dialog);
|
|
|
|
box->addButton(QDialogButtonBox::Ok);
|
|
|
|
box->addButton(QDialogButtonBox::Cancel);
|
|
|
|
connect(box, SIGNAL(rejected()), dialog, SLOT(reject()));
|
|
|
|
connect(box, SIGNAL(accepted()), dialog, SLOT(accept()));
|
|
|
|
layout->addWidget(label);
|
|
|
|
layout->addWidget(combo);
|
|
|
|
layout->addWidget(box);
|
|
|
|
|
2013-01-09 13:59:37 +01:00
|
|
|
bookmarksTree->refreshTree();
|
|
|
|
|
|
|
|
|
2014-02-05 15:26:51 +01:00
|
|
|
int index = combo->findText(Bookmarks::toTranslatedFolder(m_bookmarks->lastFolder()));
|
2013-01-09 13:59:37 +01:00
|
|
|
// QComboBox::find() returns index related to the item's parent
|
2013-01-10 18:05:02 +01:00
|
|
|
if (index == -1) { // subfolder
|
2013-01-09 13:59:37 +01:00
|
|
|
QModelIndex rootIndex = combo->rootModelIndex();
|
2013-01-16 14:52:50 +01:00
|
|
|
combo->setRootModelIndex(combo->model()->index(combo->findText(_bookmarksToolbar), 0));
|
2014-02-05 15:26:51 +01:00
|
|
|
index = combo->findText(Bookmarks::toTranslatedFolder(m_bookmarks->lastFolder()));
|
2013-01-10 18:05:02 +01:00
|
|
|
combo->setCurrentIndex(index);
|
|
|
|
combo->setRootModelIndex(rootIndex);
|
2013-01-09 13:59:37 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
combo->setCurrentIndex(index);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2013-01-09 13:59:37 +01:00
|
|
|
connect(combo, SIGNAL(currentIndexChanged(int)), bookmarksTree, SLOT(activeItemChange(int)));
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
label->setText(tr("Choose folder for bookmarks:"));
|
|
|
|
dialog->setWindowTitle(tr("Bookmark All Tabs"));
|
|
|
|
|
|
|
|
QSize size = dialog->size();
|
|
|
|
size.setWidth(350);
|
|
|
|
dialog->resize(size);
|
|
|
|
dialog->exec();
|
2011-11-06 17:01:23 +01:00
|
|
|
if (dialog->result() == QDialog::Rejected) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2013-03-06 09:05:41 +01:00
|
|
|
foreach (WebTab* tab, getQupZilla()->tabWidget()->allTabs(false)) {
|
2012-03-11 15:17:12 +01:00
|
|
|
if (tab->url().isEmpty()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
continue;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-04-15 20:45:22 +02:00
|
|
|
|
2014-02-05 15:26:51 +01:00
|
|
|
m_bookmarks->saveBookmark(tab->url(), tab->title(), tab->icon(), Bookmarks::fromTranslatedFolder(combo->currentText()));
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
2011-04-15 20:45:22 +02:00
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
delete dialog;
|
|
|
|
}
|
|
|
|
|