2011-03-03 18:29:20 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2012-01-01 15:29:55 +01:00
|
|
|
* Copyright (C) 2010-2012 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"
|
|
|
|
#include "bookmarksmodel.h"
|
2011-04-25 20:56:45 +02:00
|
|
|
#include "iconprovider.h"
|
2011-07-30 17:57:14 +02:00
|
|
|
#include "browsinglibrary.h"
|
2011-09-21 14:20:49 +02:00
|
|
|
#include "globalfunctions.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"
|
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>
|
|
|
|
|
2011-10-28 17:52:42 +02:00
|
|
|
BookmarksManager::BookmarksManager(QupZilla* mainClass, QWidget* parent)
|
|
|
|
: QWidget(parent)
|
|
|
|
, m_isRefreshing(false)
|
|
|
|
, ui(new Ui::BookmarksManager)
|
|
|
|
, p_QupZilla(mainClass)
|
|
|
|
, m_bookmarksModel(mApp->bookmarksModel())
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
2011-11-06 17:01:23 +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()));
|
|
|
|
connect(ui->bookmarksTree, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(contextMenuRequested(const QPoint &)));
|
|
|
|
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*)));
|
2011-04-17 13:03:29 +02:00
|
|
|
|
|
|
|
connect(m_bookmarksModel, SIGNAL(bookmarkAdded(BookmarksModel::Bookmark)), this, SLOT(addBookmark(BookmarksModel::Bookmark)));
|
|
|
|
connect(m_bookmarksModel, SIGNAL(bookmarkDeleted(BookmarksModel::Bookmark)), this, SLOT(removeBookmark(BookmarksModel::Bookmark)));
|
2011-11-06 17:01:23 +01:00
|
|
|
connect(m_bookmarksModel, SIGNAL(bookmarkEdited(BookmarksModel::Bookmark, BookmarksModel::Bookmark)), this, SLOT(bookmarkEdited(BookmarksModel::Bookmark, BookmarksModel::Bookmark)));
|
2011-10-28 17:52:42 +02:00
|
|
|
connect(m_bookmarksModel, SIGNAL(subfolderAdded(QString)), this, SLOT(addSubfolder(QString)));
|
2011-04-17 13:03:29 +02:00
|
|
|
connect(m_bookmarksModel, SIGNAL(folderAdded(QString)), this, SLOT(addFolder(QString)));
|
|
|
|
connect(m_bookmarksModel, SIGNAL(folderDeleted(QString)), this, SLOT(removeFolder(QString)));
|
2011-11-06 17:01:23 +01:00
|
|
|
connect(m_bookmarksModel, SIGNAL(folderRenamed(QString, QString)), this, SLOT(renameFolder(QString, QString)));
|
2011-04-17 13:03:29 +02:00
|
|
|
|
2011-07-30 17:57:14 +02:00
|
|
|
connect(ui->optimizeDb, SIGNAL(clicked(QPoint)), this, SLOT(optimizeDb()));
|
2011-12-12 21:14:43 +01:00
|
|
|
connect(ui->importBookmarks, SIGNAL(clicked(QPoint)), this, SLOT(importBookmarks()));
|
|
|
|
|
|
|
|
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);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2011-12-12 21:14:43 +01:00
|
|
|
void BookmarksManager::importBookmarks()
|
|
|
|
{
|
|
|
|
BookmarksImportDialog* b = new BookmarksImportDialog(this);
|
|
|
|
b->show();
|
|
|
|
}
|
|
|
|
|
2011-07-30 17:57:14 +02:00
|
|
|
void BookmarksManager::search(const QString &string)
|
|
|
|
{
|
|
|
|
ui->bookmarksTree->filterString(string);
|
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
QupZilla* BookmarksManager::getQupZilla()
|
|
|
|
{
|
2012-01-18 18:36:10 +01:00
|
|
|
if (!p_QupZilla) {
|
2011-03-04 13:59:07 +01:00
|
|
|
p_QupZilla = mApp->getWindow();
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-12-09 21:56:01 +01:00
|
|
|
return p_QupZilla.data();
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2011-03-17 17:03:04 +01:00
|
|
|
void BookmarksManager::setMainWindow(QupZilla* window)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (window) {
|
2011-03-02 16:57:41 +01:00
|
|
|
p_QupZilla = window;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksManager::addFolder()
|
|
|
|
{
|
|
|
|
QString text = QInputDialog::getText(this, tr("Add new folder"), tr("Choose name for new bookmark folder: "));
|
2011-11-06 17:01:23 +01:00
|
|
|
if (text.isEmpty()) {
|
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
|
|
|
|
|
|
|
m_bookmarksModel->createFolder(text);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2011-10-28 17:52:42 +02:00
|
|
|
void BookmarksManager::addSubfolder()
|
|
|
|
{
|
|
|
|
QString text = QInputDialog::getText(this, tr("Add new subfolder"), tr("Choose name for new subfolder in bookmarks toolbar: "));
|
2011-11-06 17:01:23 +01:00
|
|
|
if (text.isEmpty()) {
|
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
|
|
|
|
|
|
|
m_bookmarksModel->createSubfolder(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksManager::renameFolder()
|
|
|
|
{
|
|
|
|
QTreeWidgetItem* item = ui->bookmarksTree->currentItem();
|
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
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!item->text(1).isEmpty()) {
|
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
|
|
|
|
|
|
|
QString folder = item->text(0);
|
|
|
|
|
2011-12-17 14:30:54 +01:00
|
|
|
if (folder == _bookmarksMenu || folder == _bookmarksToolbar) {
|
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
|
|
|
|
|
|
|
QString text = QInputDialog::getText(this, tr("Rename Folder"), tr("Choose name for folder: "), QLineEdit::Normal, folder);
|
2011-11-06 17:01:23 +01:00
|
|
|
if (text.isEmpty()) {
|
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
|
|
|
|
|
|
|
m_bookmarksModel->renameFolder(folder, text);
|
|
|
|
}
|
|
|
|
|
2011-12-12 21:14:43 +01:00
|
|
|
void BookmarksManager::renameBookmark()
|
|
|
|
{
|
|
|
|
QTreeWidgetItem* item = ui->bookmarksTree->currentItem();
|
|
|
|
if (!item) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ui->bookmarksTree->editItem(item, 0);
|
|
|
|
}
|
|
|
|
|
2012-05-22 11:46:22 +02:00
|
|
|
void BookmarksManager::changeIcon()
|
|
|
|
{
|
|
|
|
QTreeWidgetItem* item = ui->bookmarksTree->currentItem();
|
|
|
|
if (!item) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int id = item->data(0, Qt::UserRole + 10).toInt();
|
|
|
|
QIcon icon;
|
|
|
|
|
|
|
|
IconChooser chooser(this);
|
|
|
|
icon = chooser.exec();
|
|
|
|
|
|
|
|
if (!icon.isNull()) {
|
|
|
|
m_bookmarksModel->changeIcon(id, icon);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-17 17:03:04 +01:00
|
|
|
void BookmarksManager::itemChanged(QTreeWidgetItem* item)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!item || m_isRefreshing || item->text(1).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
|
|
|
|
|
|
|
QString name = item->text(0);
|
2012-02-01 15:37:45 +01:00
|
|
|
QUrl url = QUrl::fromEncoded(item->text(1).toUtf8());
|
2012-03-13 17:51:06 +01:00
|
|
|
int id = item->data(0, Qt::UserRole + 10).toInt();
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-07-30 17:57:14 +02:00
|
|
|
ui->bookmarksTree->deleteItem(item);
|
2012-09-02 11:42:41 +02:00
|
|
|
m_bookmarksModel->editBookmark(id, name, url, QString());
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2011-03-17 17:03:04 +01:00
|
|
|
void BookmarksManager::itemControlClicked(QTreeWidgetItem* item)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!item || item->text(1).isEmpty()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-12-20 18:58:42 +01:00
|
|
|
getQupZilla()->tabWidget()->addView(QUrl(item->text(1)), item->text(0));
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksManager::loadInNewTab()
|
|
|
|
{
|
2011-11-06 17:01:23 +01:00
|
|
|
if (QAction* action = qobject_cast<QAction*>(sender())) {
|
2012-08-10 21:16:43 +02:00
|
|
|
getQupZilla()->tabWidget()->addView(action->data().toUrl(), qzSettings->newTabPosition);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksManager::deleteItem()
|
|
|
|
{
|
|
|
|
QTreeWidgetItem* item = ui->bookmarksTree->currentItem();
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!item) {
|
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
|
|
|
|
2012-03-29 20:02:21 +02:00
|
|
|
QApplication::setOverrideCursor(Qt::WaitCursor);
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
if (item->text(1).isEmpty()) { // Delete folder
|
|
|
|
QString folder = item->text(0);
|
2011-04-17 13:03:29 +02:00
|
|
|
m_bookmarksModel->removeFolder(folder);
|
2012-04-04 23:43:37 +02:00
|
|
|
|
|
|
|
QApplication::restoreOverrideCursor();
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-13 17:51:06 +01:00
|
|
|
int id = item->data(0, Qt::UserRole + 10).toInt();
|
2011-04-15 20:45:22 +02:00
|
|
|
m_bookmarksModel->removeBookmark(id);
|
2012-03-29 20:02:21 +02:00
|
|
|
QApplication::restoreOverrideCursor();
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2011-03-17 17:03:04 +01:00
|
|
|
void BookmarksManager::addBookmark(WebView* view)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-01-21 20:27:45 +01:00
|
|
|
insertBookmark(view->url(), view->title(), view->icon());
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksManager::moveBookmark()
|
|
|
|
{
|
|
|
|
QTreeWidgetItem* item = ui->bookmarksTree->currentItem();
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!item) {
|
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
|
|
|
|
2011-03-17 17:03:04 +01:00
|
|
|
if (QAction* action = qobject_cast<QAction*>(sender())) {
|
2012-03-13 17:51:06 +01:00
|
|
|
int id = item->data(0, Qt::UserRole + 10).toInt();
|
|
|
|
|
|
|
|
m_bookmarksModel->editBookmark(id, item->text(0), QUrl(), action->data().toString());
|
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"));
|
2011-12-17 14:30:54 +01:00
|
|
|
moveMenu.addAction(QIcon(":icons/other/unsortedbookmarks.png"), _bookmarksUnsorted, this, SLOT(moveBookmark()))->setData("unsorted");
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksManager::refreshTable()
|
|
|
|
{
|
|
|
|
m_isRefreshing = true;
|
|
|
|
ui->bookmarksTree->setUpdatesEnabled(false);
|
|
|
|
ui->bookmarksTree->clear();
|
|
|
|
|
|
|
|
QSqlQuery query;
|
|
|
|
QTreeWidgetItem* newItem = new QTreeWidgetItem(ui->bookmarksTree);
|
2011-12-17 14:30:54 +01:00
|
|
|
newItem->setText(0, _bookmarksMenu);
|
2011-03-02 16:57:41 +01:00
|
|
|
newItem->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon));
|
|
|
|
ui->bookmarksTree->addTopLevelItem(newItem);
|
|
|
|
|
2011-10-28 17:52:42 +02:00
|
|
|
QTreeWidgetItem* bookmarksToolbar = new QTreeWidgetItem(ui->bookmarksTree);
|
2011-12-17 14:30:54 +01:00
|
|
|
bookmarksToolbar->setText(0, _bookmarksToolbar);
|
2011-10-28 17:52:42 +02:00
|
|
|
bookmarksToolbar->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon));
|
|
|
|
ui->bookmarksTree->addTopLevelItem(bookmarksToolbar);
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-10-28 17:52:42 +02:00
|
|
|
query.exec("SELECT name FROM folders WHERE subfolder!='yes'");
|
2011-11-06 17:01:23 +01:00
|
|
|
while (query.next()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
newItem = new QTreeWidgetItem(ui->bookmarksTree);
|
|
|
|
newItem->setText(0, query.value(0).toString());
|
|
|
|
newItem->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon));
|
|
|
|
ui->bookmarksTree->addTopLevelItem(newItem);
|
|
|
|
}
|
|
|
|
|
2011-07-30 17:57:14 +02:00
|
|
|
query.exec("SELECT title, url, id, folder, icon FROM bookmarks");
|
2011-11-06 17:01:23 +01:00
|
|
|
while (query.next()) {
|
2011-03-02 16:57:41 +01:00
|
|
|
QString title = query.value(0).toString();
|
|
|
|
QUrl url = query.value(1).toUrl();
|
|
|
|
int id = query.value(2).toInt();
|
|
|
|
QString folder = query.value(3).toString();
|
2012-04-22 20:51:28 +02:00
|
|
|
QIcon icon = qIconProvider->iconFromImage(QImage::fromData(query.value(4).toByteArray()));
|
2011-11-05 18:36:53 +01:00
|
|
|
QTreeWidgetItem* item = new QTreeWidgetItem();
|
2011-11-06 17:01:23 +01:00
|
|
|
if (folder == "bookmarksMenu") {
|
2011-12-17 14:30:54 +01:00
|
|
|
folder = _bookmarksMenu;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
if (folder == "bookmarksToolbar") {
|
2011-12-17 14:30:54 +01:00
|
|
|
folder = _bookmarksToolbar;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
if (folder != "unsorted") {
|
|
|
|
QList<QTreeWidgetItem*> findParent = ui->bookmarksTree->findItems(folder, 0);
|
2011-11-06 17:01:23 +01:00
|
|
|
if (findParent.count() != 1) {
|
2011-10-28 17:52:42 +02:00
|
|
|
continue;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-11-05 18:36:53 +01:00
|
|
|
findParent.at(0)->addChild(item);
|
2011-10-28 17:52:42 +02:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
item->setText(0, title);
|
|
|
|
item->setText(1, url.toEncoded());
|
|
|
|
item->setToolTip(0, title);
|
|
|
|
item->setToolTip(1, url.toEncoded());
|
|
|
|
|
2012-03-13 17:51:06 +01:00
|
|
|
item->setData(0, Qt::UserRole + 10, id);
|
2012-05-22 11:46:22 +02:00
|
|
|
item->setData(0, Qt::UserRole + 11, url);
|
2011-07-30 17:57:14 +02:00
|
|
|
item->setIcon(0, icon);
|
2011-03-02 16:57:41 +01:00
|
|
|
item->setFlags(item->flags() | Qt::ItemIsEditable);
|
|
|
|
ui->bookmarksTree->addTopLevelItem(item);
|
|
|
|
}
|
|
|
|
|
2011-10-28 17:52:42 +02:00
|
|
|
query.exec("SELECT name FROM folders WHERE subfolder='yes'");
|
2011-11-06 17:01:23 +01:00
|
|
|
while (query.next()) {
|
2011-10-28 17:52:42 +02:00
|
|
|
newItem = new QTreeWidgetItem(bookmarksToolbar);
|
|
|
|
newItem->setText(0, query.value(0).toString());
|
|
|
|
newItem->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon));
|
|
|
|
|
|
|
|
QSqlQuery query2;
|
|
|
|
query2.prepare("SELECT title, url, id, icon FROM bookmarks WHERE folder=?");
|
|
|
|
query2.addBindValue(query.value(0).toString());
|
|
|
|
query2.exec();
|
2011-11-06 17:01:23 +01:00
|
|
|
while (query2.next()) {
|
2011-10-28 17:52:42 +02:00
|
|
|
QString title = query2.value(0).toString();
|
|
|
|
QUrl url = query2.value(1).toUrl();
|
|
|
|
int id = query2.value(2).toInt();
|
2012-04-22 20:51:28 +02:00
|
|
|
QIcon icon = qIconProvider->iconFromImage(QImage::fromData(query2.value(3).toByteArray()));
|
2011-10-28 17:52:42 +02:00
|
|
|
QTreeWidgetItem* item = new QTreeWidgetItem(newItem);
|
|
|
|
|
|
|
|
item->setText(0, title);
|
|
|
|
item->setText(1, url.toEncoded());
|
|
|
|
item->setToolTip(0, title);
|
|
|
|
item->setToolTip(1, url.toEncoded());
|
|
|
|
|
2012-03-13 17:51:06 +01:00
|
|
|
item->setData(0, Qt::UserRole + 10, id);
|
2012-05-22 11:46:22 +02:00
|
|
|
item->setData(0, Qt::UserRole + 11, url);
|
2011-10-28 17:52:42 +02:00
|
|
|
item->setIcon(0, icon);
|
|
|
|
item->setFlags(item->flags() | Qt::ItemIsEditable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ui->bookmarksTree->expandAll();
|
2011-03-02 16:57:41 +01:00
|
|
|
ui->bookmarksTree->setUpdatesEnabled(true);
|
|
|
|
m_isRefreshing = false;
|
|
|
|
}
|
|
|
|
|
2011-04-17 13:03:29 +02:00
|
|
|
void BookmarksManager::addBookmark(const BookmarksModel::Bookmark &bookmark)
|
|
|
|
{
|
|
|
|
m_isRefreshing = true;
|
|
|
|
QString translatedFolder = BookmarksModel::toTranslatedFolder(bookmark.folder);
|
|
|
|
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-05-22 11:46:22 +02:00
|
|
|
item->setData(0, Qt::UserRole + 11, bookmark.url);
|
2012-04-22 20:51:28 +02:00
|
|
|
item->setIcon(0, qIconProvider->iconFromImage(bookmark.image));
|
2011-04-17 13:03:29 +02:00
|
|
|
item->setToolTip(0, bookmark.title);
|
|
|
|
item->setToolTip(1, bookmark.url.toEncoded());
|
|
|
|
item->setFlags(item->flags() | Qt::ItemIsEditable);
|
|
|
|
|
2011-10-28 17:52:42 +02:00
|
|
|
if (bookmark.inSubfolder) {
|
|
|
|
QList<QTreeWidgetItem*> list = ui->bookmarksTree->findItems(bookmark.folder, Qt::MatchExactly | Qt::MatchRecursive);
|
|
|
|
if (list.count() != 0) {
|
2011-11-06 17:01:23 +01:00
|
|
|
foreach(QTreeWidgetItem * it, list) {
|
2011-10-28 17:52:42 +02:00
|
|
|
if (it->text(1).isEmpty()) {
|
|
|
|
it->addChild(item);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-11-06 17:01:23 +01:00
|
|
|
else if (bookmark.folder != "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-17 13:03:29 +02:00
|
|
|
ui->bookmarksTree->addTopLevelItem(item);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-04-17 13:03:29 +02:00
|
|
|
m_isRefreshing = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksManager::removeBookmark(const BookmarksModel::Bookmark &bookmark)
|
|
|
|
{
|
|
|
|
m_isRefreshing = true;
|
2011-10-28 17:52:42 +02:00
|
|
|
|
|
|
|
if (bookmark.inSubfolder) {
|
|
|
|
QList<QTreeWidgetItem*> list = ui->bookmarksTree->findItems(bookmark.folder, Qt::MatchExactly | Qt::MatchRecursive);
|
|
|
|
QTreeWidgetItem* subfolderItem = 0;
|
|
|
|
if (list.count() != 0) {
|
2011-11-06 17:01:23 +01:00
|
|
|
foreach(QTreeWidgetItem * it, list) {
|
2011-10-28 17:52:42 +02:00
|
|
|
if (it->text(1).isEmpty()) {
|
|
|
|
subfolderItem = it;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!subfolderItem) {
|
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
|
|
|
|
|
|
|
for (int i = 0; i < subfolderItem->childCount(); i++) {
|
|
|
|
QTreeWidgetItem* item = subfolderItem->child(i);
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!item) {
|
2011-10-28 17:52:42 +02:00
|
|
|
continue;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2012-03-13 17:51:06 +01:00
|
|
|
|
|
|
|
int id = item->data(0, Qt::UserRole + 10).toInt();
|
|
|
|
|
|
|
|
if (item->text(0) == bookmark.title && id == bookmark.id) {
|
2011-10-28 17:52:42 +02:00
|
|
|
ui->bookmarksTree->deleteItem(item);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (bookmark.folder == "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
|
|
|
int id = item->data(0, Qt::UserRole + 10).toInt();
|
|
|
|
|
2012-03-15 19:35:37 +01:00
|
|
|
if (id == bookmark.id) {
|
2011-07-30 17:57:14 +02:00
|
|
|
ui->bookmarksTree->deleteItem(item);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-10-28 17:52:42 +02:00
|
|
|
}
|
|
|
|
else {
|
2011-04-17 13:03:29 +02:00
|
|
|
QList<QTreeWidgetItem*> list = ui->bookmarksTree->findItems(BookmarksModel::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-17 13:03:29 +02:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-04-17 13:03:29 +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-17 13:03:29 +02:00
|
|
|
continue;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2012-03-13 17:51:06 +01:00
|
|
|
|
|
|
|
int id = item->data(0, Qt::UserRole + 10).toInt();
|
|
|
|
|
|
|
|
if (item->text(0) == bookmark.title && id == bookmark.id) {
|
2011-07-30 17:57:14 +02:00
|
|
|
ui->bookmarksTree->deleteItem(item);
|
2011-04-17 13:03:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
m_isRefreshing = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksManager::bookmarkEdited(const BookmarksModel::Bookmark &before, const BookmarksModel::Bookmark &after)
|
|
|
|
{
|
|
|
|
removeBookmark(before);
|
|
|
|
addBookmark(after);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksManager::addFolder(const QString &name)
|
|
|
|
{
|
|
|
|
m_isRefreshing = true;
|
2011-10-28 17:52:42 +02:00
|
|
|
|
2011-04-17 13:03:29 +02:00
|
|
|
QTreeWidgetItem* item = new QTreeWidgetItem(ui->bookmarksTree);
|
|
|
|
item->setText(0, name);
|
|
|
|
item->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon));
|
2011-10-28 17:52:42 +02:00
|
|
|
|
|
|
|
m_isRefreshing = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksManager::addSubfolder(const QString &name)
|
|
|
|
{
|
|
|
|
m_isRefreshing = true;
|
|
|
|
|
2011-12-17 14:30:54 +01:00
|
|
|
QList<QTreeWidgetItem*> list = ui->bookmarksTree->findItems(_bookmarksToolbar, Qt::MatchExactly);
|
2011-10-28 17:52:42 +02:00
|
|
|
if (list.count() != 0) {
|
|
|
|
QTreeWidgetItem* item = new QTreeWidgetItem(list.at(0));
|
|
|
|
item->setText(0, name);
|
|
|
|
item->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon));
|
|
|
|
}
|
|
|
|
|
2011-04-17 13:03:29 +02:00
|
|
|
m_isRefreshing = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksManager::removeFolder(const QString &name)
|
|
|
|
{
|
2011-10-28 17:52:42 +02:00
|
|
|
QList<QTreeWidgetItem*> list = ui->bookmarksTree->findItems(name, Qt::MatchExactly | Qt::MatchRecursive);
|
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* folderItem = 0;
|
|
|
|
if (list.count() != 0) {
|
2011-11-06 17:01:23 +01:00
|
|
|
foreach(QTreeWidgetItem * it, list) {
|
2011-10-28 17:52:42 +02:00
|
|
|
if (it->text(1).isEmpty()) {
|
|
|
|
folderItem = it;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!folderItem) {
|
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
|
|
|
|
|
|
|
ui->bookmarksTree->deleteItem(folderItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksManager::renameFolder(const QString &before, const QString &after)
|
|
|
|
{
|
|
|
|
QList<QTreeWidgetItem*> list = ui->bookmarksTree->findItems(before, Qt::MatchExactly | Qt::MatchRecursive);
|
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* folderItem = 0;
|
|
|
|
if (list.count() != 0) {
|
2011-11-06 17:01:23 +01:00
|
|
|
foreach(QTreeWidgetItem * it, list) {
|
2011-10-28 17:52:42 +02:00
|
|
|
if (it->text(0) == before && it->text(1).isEmpty()) {
|
|
|
|
folderItem = it;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!folderItem) {
|
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
|
|
|
|
|
|
|
folderItem->setText(0, after);
|
2011-04-17 13:03:29 +02:00
|
|
|
}
|
|
|
|
|
2011-07-30 17:57:14 +02:00
|
|
|
void BookmarksManager::insertBookmark(const QUrl &url, const QString &title, const QIcon &icon)
|
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);
|
|
|
|
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);
|
2011-11-06 17:01:23 +01:00
|
|
|
if (m_bookmarksModel->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);
|
|
|
|
|
2011-12-17 14:30:54 +01:00
|
|
|
combo->addItem(QIcon(":icons/other/unsortedbookmarks.png"), _bookmarksUnsorted);
|
|
|
|
combo->addItem(style()->standardIcon(QStyle::SP_DirOpenIcon), _bookmarksMenu);
|
|
|
|
combo->addItem(style()->standardIcon(QStyle::SP_DirOpenIcon), _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
|
|
|
combo->addItem(style()->standardIcon(QStyle::SP_DirIcon), query.value(0).toString());
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2012-02-04 22:47:55 +01:00
|
|
|
combo->setCurrentIndex(combo->findText(BookmarksModel::toTranslatedFolder(m_bookmarksModel->lastFolder())));
|
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) {
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
|
|
|
if (edit->text().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
|
|
|
|
2011-07-30 17:57:14 +02:00
|
|
|
m_bookmarksModel->saveBookmark(url, edit->text(), icon, BookmarksModel::fromTranslatedFolder(combo->currentText()));
|
2011-03-02 16:57:41 +01:00
|
|
|
delete dialog;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
|
2011-12-17 14:30:54 +01:00
|
|
|
combo->addItem(QIcon(":icons/other/unsortedbookmarks.png"), _bookmarksUnsorted);
|
|
|
|
combo->addItem(style()->standardIcon(QStyle::SP_DirOpenIcon), _bookmarksMenu);
|
|
|
|
combo->addItem(style()->standardIcon(QStyle::SP_DirOpenIcon), _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
|
|
|
combo->addItem(style()->standardIcon(QStyle::SP_DirIcon), query.value(0).toString());
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2012-02-04 22:47:55 +01:00
|
|
|
combo->setCurrentIndex(combo->findText(BookmarksModel::toTranslatedFolder(m_bookmarksModel->lastFolder())));
|
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
|
|
|
|
2011-11-06 17:01:23 +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
|
|
|
|
2012-03-11 15:17:12 +01:00
|
|
|
m_bookmarksModel->saveBookmark(tab->url(), tab->title(), tab->icon(), BookmarksModel::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;
|
|
|
|
}
|
|
|
|
|
2011-07-30 17:57:14 +02:00
|
|
|
void BookmarksManager::optimizeDb()
|
|
|
|
{
|
2011-10-21 23:26:34 +02:00
|
|
|
BrowsingLibrary* b = qobject_cast<BrowsingLibrary*>(parentWidget()->parentWidget());
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!b) {
|
2011-07-30 17:57:14 +02:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-07-30 17:57:14 +02:00
|
|
|
b->optimizeDatabase();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
BookmarksManager::~BookmarksManager()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|