2011-03-03 18:29:20 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
|
|
|
* Copyright (C) 2010-2011 nowrep
|
|
|
|
*
|
|
|
|
* 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"
|
|
|
|
#include "webview.h"
|
|
|
|
#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-03-02 16:57:41 +01:00
|
|
|
|
2011-03-17 17:03:04 +01:00
|
|
|
BookmarksManager::BookmarksManager(QupZilla* mainClass, QWidget* parent) :
|
2011-03-02 16:57:41 +01:00
|
|
|
QWidget(parent)
|
|
|
|
,m_isRefreshing(false)
|
|
|
|
,ui(new Ui::BookmarksManager)
|
|
|
|
,p_QupZilla(mainClass)
|
2011-04-15 20:45:22 +02:00
|
|
|
,m_bookmarksModel(mApp->bookmarksModel())
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2011-09-21 14:20:49 +02:00
|
|
|
qz_centerWidgetOnScreen(this);
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
connect(ui->deleteB, SIGNAL(clicked()), this, SLOT(deleteItem()));
|
|
|
|
connect(ui->bookmarksTree, SIGNAL(itemChanged(QTreeWidgetItem*,int)), this, SLOT(itemChanged(QTreeWidgetItem*)));
|
|
|
|
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-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)));
|
|
|
|
connect(m_bookmarksModel, SIGNAL(folderAdded(QString)), this, SLOT(addFolder(QString)));
|
|
|
|
connect(m_bookmarksModel, SIGNAL(folderDeleted(QString)), this, SLOT(removeFolder(QString)));
|
|
|
|
connect(m_bookmarksModel, SIGNAL(bookmarkEdited(BookmarksModel::Bookmark,BookmarksModel::Bookmark)), this, SLOT(bookmarkEdited(BookmarksModel::Bookmark,BookmarksModel::Bookmark)));
|
|
|
|
|
2011-07-30 17:57:14 +02:00
|
|
|
connect(ui->optimizeDb, SIGNAL(clicked(QPoint)), this, SLOT(optimizeDb()));
|
|
|
|
|
|
|
|
ui->bookmarksTree->setDefaultItemShowMode(TreeWidget::ItemsExpanded);
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
//QTimer::singleShot(0, this, SLOT(refreshTable()));
|
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
if (!p_QupZilla)
|
2011-03-04 13:59:07 +01:00
|
|
|
p_QupZilla = mApp->getWindow();
|
2011-03-02 16:57:41 +01:00
|
|
|
return p_QupZilla;
|
|
|
|
}
|
|
|
|
|
2011-03-17 17:03:04 +01:00
|
|
|
void BookmarksManager::setMainWindow(QupZilla* window)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
|
|
|
if (window)
|
|
|
|
p_QupZilla = window;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksManager::addFolder()
|
|
|
|
{
|
|
|
|
QString text = QInputDialog::getText(this, tr("Add new folder"), tr("Choose name for new bookmark folder: "));
|
|
|
|
if (text.isEmpty())
|
|
|
|
return;
|
2011-04-15 20:45:22 +02:00
|
|
|
|
|
|
|
m_bookmarksModel->createFolder(text);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2011-03-17 17:03:04 +01:00
|
|
|
void BookmarksManager::itemChanged(QTreeWidgetItem* item)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
|
|
|
if (!item || m_isRefreshing)
|
|
|
|
return;
|
|
|
|
|
|
|
|
QString name = item->text(0);
|
|
|
|
QUrl url = QUrl(item->text(1));
|
|
|
|
int id = item->whatsThis(1).toInt();
|
|
|
|
|
2011-07-30 17:57:14 +02:00
|
|
|
ui->bookmarksTree->deleteItem(item);
|
2011-04-15 20:45:22 +02:00
|
|
|
m_bookmarksModel->editBookmark(id, name, url, "");
|
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
|
|
|
{
|
|
|
|
if (!item || item->text(1).isEmpty())
|
|
|
|
return;
|
|
|
|
getQupZilla()->tabWidget()->addView(QUrl(item->text(1)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksManager::loadInNewTab()
|
|
|
|
{
|
2011-03-17 17:03:04 +01:00
|
|
|
if (QAction* action = qobject_cast<QAction*>(sender()))
|
2011-03-02 16:57:41 +01:00
|
|
|
getQupZilla()->tabWidget()->addView(action->data().toUrl(), tr("New Tab"), TabWidget::NewNotSelectedTab);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksManager::deleteItem()
|
|
|
|
{
|
|
|
|
QTreeWidgetItem* item = ui->bookmarksTree->currentItem();
|
|
|
|
if (!item)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (item->text(1).isEmpty()) { // Delete folder
|
|
|
|
QString folder = item->text(0);
|
2011-04-17 13:03:29 +02:00
|
|
|
m_bookmarksModel->removeFolder(folder);
|
2011-03-02 16:57:41 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-04-15 20:45:22 +02:00
|
|
|
int id = item->whatsThis(1).toInt();
|
|
|
|
m_bookmarksModel->removeBookmark(id);
|
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
|
|
|
{
|
2011-07-30 17:57:14 +02:00
|
|
|
insertBookmark(view->url(), view->title(), view->siteIcon());
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksManager::moveBookmark()
|
|
|
|
{
|
|
|
|
QTreeWidgetItem* item = ui->bookmarksTree->currentItem();
|
|
|
|
if (!item)
|
|
|
|
return;
|
2011-03-17 17:03:04 +01:00
|
|
|
if (QAction* action = qobject_cast<QAction*>(sender())) {
|
2011-04-15 20:45:22 +02:00
|
|
|
m_bookmarksModel->editBookmark(item->whatsThis(1).toInt(), item->text(0), QUrl(), action->data().toString());
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksManager::contextMenuRequested(const QPoint &position)
|
|
|
|
{
|
|
|
|
if (!ui->bookmarksTree->itemAt(position))
|
|
|
|
return;
|
|
|
|
QString link = ui->bookmarksTree->itemAt(position)->text(1);
|
|
|
|
if (link.isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
QMenu menu;
|
2011-04-09 00:22:50 +02:00
|
|
|
menu.addAction(tr("Open link in actual &tab"), getQupZilla(), SLOT(loadActionUrl()))->setData(link);
|
|
|
|
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-03-02 16:57:41 +01:00
|
|
|
moveMenu.addAction(QIcon(":icons/other/unsortedbookmarks.png"), tr("Unsorted Bookmarks"), this, SLOT(moveBookmark()))->setData("unsorted");
|
|
|
|
moveMenu.addAction(style()->standardIcon(QStyle::SP_DirOpenIcon), tr("Bookmarks In Menu"), this, SLOT(moveBookmark()))->setData("bookmarksMenu");
|
|
|
|
moveMenu.addAction(style()->standardIcon(QStyle::SP_DirOpenIcon), tr("Bookmarks In ToolBar"), this, SLOT(moveBookmark()))->setData("bookmarksToolbar");
|
|
|
|
QSqlQuery query;
|
|
|
|
query.exec("SELECT name FROM folders");
|
|
|
|
while(query.next())
|
|
|
|
moveMenu.addAction(style()->standardIcon(QStyle::SP_DirIcon), query.value(0).toString(), this, SLOT(moveBookmark()))->setData(query.value(0).toString());
|
|
|
|
menu.addMenu(&moveMenu);
|
|
|
|
|
|
|
|
//Prevent choosing first option with double rightclick
|
|
|
|
QPoint pos = QCursor::pos();
|
|
|
|
QPoint p(pos.x(), pos.y()+1);
|
|
|
|
menu.exec(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksManager::refreshTable()
|
|
|
|
{
|
|
|
|
m_isRefreshing = true;
|
|
|
|
ui->bookmarksTree->setUpdatesEnabled(false);
|
|
|
|
ui->bookmarksTree->clear();
|
|
|
|
|
|
|
|
QSqlQuery query;
|
|
|
|
QTreeWidgetItem* newItem = new QTreeWidgetItem(ui->bookmarksTree);
|
|
|
|
newItem->setText(0, tr("Bookmarks In Menu"));
|
|
|
|
newItem->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon));
|
|
|
|
ui->bookmarksTree->addTopLevelItem(newItem);
|
|
|
|
|
|
|
|
newItem = new QTreeWidgetItem(ui->bookmarksTree);
|
|
|
|
newItem->setText(0, tr("Bookmarks In ToolBar"));
|
|
|
|
newItem->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon));
|
|
|
|
ui->bookmarksTree->addTopLevelItem(newItem);
|
|
|
|
|
|
|
|
query.exec("SELECT name FROM folders");
|
|
|
|
while(query.next()) {
|
|
|
|
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-03-02 16:57:41 +01:00
|
|
|
while(query.next()) {
|
|
|
|
QString title = query.value(0).toString();
|
|
|
|
QUrl url = query.value(1).toUrl();
|
|
|
|
int id = query.value(2).toInt();
|
|
|
|
QString folder = query.value(3).toString();
|
2011-07-30 17:57:14 +02:00
|
|
|
QIcon icon = IconProvider::iconFromBase64(query.value(4).toByteArray());
|
2011-03-02 16:57:41 +01:00
|
|
|
QTreeWidgetItem* item;
|
|
|
|
if (folder == "bookmarksMenu")
|
|
|
|
folder = tr("Bookmarks In Menu");
|
|
|
|
if (folder == "bookmarksToolbar")
|
|
|
|
folder = tr("Bookmarks In ToolBar");
|
|
|
|
|
|
|
|
if (folder != "unsorted") {
|
|
|
|
QList<QTreeWidgetItem*> findParent = ui->bookmarksTree->findItems(folder, 0);
|
|
|
|
if (findParent.count() == 1) {
|
|
|
|
item = new QTreeWidgetItem(findParent.at(0));
|
|
|
|
}else{
|
|
|
|
QTreeWidgetItem* newParent = new QTreeWidgetItem(ui->bookmarksTree);
|
|
|
|
newParent->setText(0, folder);
|
|
|
|
newParent->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon));
|
|
|
|
ui->bookmarksTree->addTopLevelItem(newParent);
|
|
|
|
item = new QTreeWidgetItem(newParent);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
item = new QTreeWidgetItem(ui->bookmarksTree);
|
|
|
|
|
|
|
|
item->setText(0, title);
|
|
|
|
item->setText(1, url.toEncoded());
|
|
|
|
item->setToolTip(0, title);
|
|
|
|
item->setToolTip(1, url.toEncoded());
|
|
|
|
|
|
|
|
item->setWhatsThis(1, QString::number(id));
|
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);
|
|
|
|
}
|
|
|
|
ui->bookmarksTree->expandAll();
|
|
|
|
|
|
|
|
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());
|
|
|
|
item->setWhatsThis(1, QString::number(bookmark.id));
|
2011-07-30 17:57:14 +02:00
|
|
|
item->setIcon(0, bookmark.icon);
|
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);
|
|
|
|
|
|
|
|
if (bookmark.folder != "unsorted")
|
2011-07-30 17:57:14 +02:00
|
|
|
ui->bookmarksTree->appendToParentItem(translatedFolder, item);
|
2011-04-17 13:03:29 +02:00
|
|
|
else
|
|
|
|
ui->bookmarksTree->addTopLevelItem(item);
|
|
|
|
m_isRefreshing = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksManager::removeBookmark(const BookmarksModel::Bookmark &bookmark)
|
|
|
|
{
|
|
|
|
m_isRefreshing = true;
|
|
|
|
if (bookmark.folder == "unsorted") {
|
|
|
|
QList<QTreeWidgetItem*> list = ui->bookmarksTree->findItems(bookmark.title, Qt::MatchExactly);
|
|
|
|
if (list.count() == 0)
|
|
|
|
return;
|
|
|
|
QTreeWidgetItem* item = list.at(0);
|
|
|
|
if (item && item->whatsThis(1) == QString::number(bookmark.id))
|
2011-07-30 17:57:14 +02:00
|
|
|
ui->bookmarksTree->deleteItem(item);
|
2011-04-17 13:03:29 +02:00
|
|
|
} else {
|
|
|
|
QList<QTreeWidgetItem*> list = ui->bookmarksTree->findItems(BookmarksModel::toTranslatedFolder(bookmark.folder), Qt::MatchExactly);
|
|
|
|
if (list.count() == 0)
|
|
|
|
return;
|
|
|
|
QTreeWidgetItem* parentItem = list.at(0);
|
|
|
|
if (!parentItem)
|
|
|
|
return;
|
|
|
|
for (int i = 0; i < parentItem->childCount(); i++) {
|
|
|
|
QTreeWidgetItem* item = parentItem->child(i);
|
|
|
|
if (!item)
|
|
|
|
continue;
|
|
|
|
if (item->text(0) == bookmark.title && item->whatsThis(1) == QString::number(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;
|
|
|
|
QTreeWidgetItem* item = new QTreeWidgetItem(ui->bookmarksTree);
|
|
|
|
item->setText(0, name);
|
|
|
|
item->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon));
|
|
|
|
m_isRefreshing = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksManager::removeFolder(const QString &name)
|
|
|
|
{
|
|
|
|
QTreeWidgetItem* item = ui->bookmarksTree->findItems(name, Qt::MatchExactly).at(0);
|
|
|
|
if (item)
|
2011-07-30 17:57:14 +02:00
|
|
|
ui->bookmarksTree->deleteItem(item);
|
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
|
|
|
{
|
|
|
|
if (url.isEmpty() || title.isEmpty())
|
|
|
|
return;
|
|
|
|
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);
|
|
|
|
if (m_bookmarksModel->isBookmarked(url))
|
|
|
|
layout->addWidget(new QLabel(tr("<b>Warning: </b>You already have this page bookmarked!")));
|
|
|
|
layout->addWidget(box);
|
|
|
|
|
|
|
|
combo->addItem(QIcon(":icons/other/unsortedbookmarks.png"), tr("Unsorted Bookmarks"));
|
|
|
|
combo->addItem(style()->standardIcon(QStyle::SP_DirOpenIcon), tr("Bookmarks In Menu"));
|
|
|
|
combo->addItem(style()->standardIcon(QStyle::SP_DirOpenIcon), tr("Bookmarks In ToolBar"));
|
|
|
|
QSqlQuery query;
|
|
|
|
query.exec("SELECT name FROM folders");
|
|
|
|
while(query.next())
|
|
|
|
combo->addItem(style()->standardIcon(QStyle::SP_DirIcon), query.value(0).toString());
|
|
|
|
|
|
|
|
label->setText(tr("Choose name and location of bookmark."));
|
|
|
|
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();
|
|
|
|
if (dialog->result() == QDialog::Rejected)
|
|
|
|
return;
|
|
|
|
if (edit->text().isEmpty())
|
|
|
|
return;
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
combo->addItem(QIcon(":icons/other/unsortedbookmarks.png"), tr("Unsorted Bookmarks"));
|
|
|
|
combo->addItem(style()->standardIcon(QStyle::SP_DirOpenIcon), tr("Bookmarks In Menu"));
|
|
|
|
combo->addItem(style()->standardIcon(QStyle::SP_DirOpenIcon), tr("Bookmarks In ToolBar"));
|
|
|
|
QSqlQuery query;
|
|
|
|
query.exec("SELECT name FROM folders");
|
|
|
|
while(query.next())
|
|
|
|
combo->addItem(style()->standardIcon(QStyle::SP_DirIcon), query.value(0).toString());
|
|
|
|
|
|
|
|
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();
|
|
|
|
if (dialog->result() == QDialog::Rejected)
|
|
|
|
return;
|
|
|
|
|
2011-04-19 18:15:36 +02:00
|
|
|
foreach (WebTab* tab, getQupZilla()->tabWidget()->allTabs(false)) {
|
|
|
|
WebView* view = tab->view();
|
|
|
|
if (view->url().isEmpty())
|
2011-03-02 16:57:41 +01:00
|
|
|
continue;
|
2011-04-15 20:45:22 +02:00
|
|
|
|
2011-07-30 17:57:14 +02:00
|
|
|
m_bookmarksModel->saveBookmark(view->url(), view->title(), view->siteIcon(),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()
|
|
|
|
{
|
|
|
|
BrowsingLibrary* b = (BrowsingLibrary*) parentWidget();
|
|
|
|
if (!b)
|
|
|
|
return;
|
|
|
|
b->optimizeDatabase();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
BookmarksManager::~BookmarksManager()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|