2011-03-03 18:29:20 +01:00
|
|
|
/* ============================================================
|
|
|
|
* QupZilla - WebKit based browser
|
2013-02-05 22:33:54 +01:00
|
|
|
* Copyright (C) 2010-2013 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 "bookmarkstoolbar.h"
|
|
|
|
#include "qupzilla.h"
|
2012-01-21 23:19:38 +01:00
|
|
|
#include "mainapplication.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
#include "bookmarksmodel.h"
|
2011-04-25 20:56:45 +02:00
|
|
|
#include "iconprovider.h"
|
2012-04-30 16:33:14 +02:00
|
|
|
#include "history.h"
|
2011-09-11 19:15:06 +02:00
|
|
|
#include "toolbutton.h"
|
2011-12-08 19:12:43 +01:00
|
|
|
#include "databasewriter.h"
|
2011-12-14 22:30:05 +01:00
|
|
|
#include "enhancedmenu.h"
|
2012-01-21 23:19:38 +01:00
|
|
|
#include "tabwidget.h"
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QDialog>
|
|
|
|
#include <QIcon>
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QFormLayout>
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QDialogButtonBox>
|
|
|
|
#include <QMimeData>
|
|
|
|
#include <QDragEnterEvent>
|
|
|
|
|
2011-10-28 17:52:42 +02:00
|
|
|
BookmarksToolbar::BookmarksToolbar(QupZilla* mainClass, QWidget* parent)
|
|
|
|
: QWidget(parent)
|
|
|
|
, p_QupZilla(mainClass)
|
|
|
|
, m_bookmarksModel(mApp->bookmarksModel())
|
|
|
|
, m_historyModel(mApp->history())
|
2012-04-04 17:41:33 +02:00
|
|
|
, m_toolButtonStyle(Qt::ToolButtonTextBesideIcon)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-09-11 19:15:06 +02:00
|
|
|
setObjectName("bookmarksbar");
|
|
|
|
m_layout = new QHBoxLayout();
|
2012-03-04 22:30:45 +01:00
|
|
|
m_layout->setMargin(3);
|
2011-09-11 19:15:06 +02:00
|
|
|
m_layout->setSpacing(0);
|
|
|
|
setLayout(m_layout);
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-12-17 14:26:34 +01:00
|
|
|
setAcceptDrops(true);
|
|
|
|
|
2011-09-11 19:15:06 +02:00
|
|
|
setContextMenuPolicy(Qt::CustomContextMenu);
|
2011-03-02 16:57:41 +01:00
|
|
|
connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(customContextMenuRequested(QPoint)));
|
2011-04-15 20:45:22 +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)));
|
2013-03-06 09:05:41 +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(subfolderAdded(QString)));
|
|
|
|
connect(m_bookmarksModel, SIGNAL(folderDeleted(QString)), this, SLOT(folderDeleted(QString)));
|
2013-03-06 09:05:41 +01:00
|
|
|
connect(m_bookmarksModel, SIGNAL(folderRenamed(QString,QString)), this, SLOT(folderRenamed(QString,QString)));
|
|
|
|
connect(m_bookmarksModel, SIGNAL(folderParentChanged(QString,bool)), this, SLOT(changeFolderParent(QString,bool)));
|
|
|
|
connect(m_bookmarksModel, SIGNAL(bookmarkParentChanged(QString,QByteArray,int,QUrl,QString,QString)), this, SLOT(changeBookmarkParent(QString,QByteArray,int,QUrl,QString,QString)));
|
2011-04-15 20:45:22 +02:00
|
|
|
|
2011-12-29 15:21:26 +01:00
|
|
|
setMaximumWidth(p_QupZilla->width());
|
|
|
|
|
2011-09-11 19:15:06 +02:00
|
|
|
refreshBookmarks();
|
2012-02-17 19:54:58 +01:00
|
|
|
showOnlyIconsChanged();
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksToolbar::customContextMenuRequested(const QPoint &pos)
|
|
|
|
{
|
2011-09-11 19:15:06 +02:00
|
|
|
Q_UNUSED(pos)
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
QMenu menu;
|
2011-04-09 00:22:50 +02:00
|
|
|
menu.addAction(tr("&Bookmark Current Page"), p_QupZilla, SLOT(bookmarkPage()));
|
|
|
|
menu.addAction(tr("Bookmark &All Tabs"), p_QupZilla, SLOT(bookmarkAllTabs()));
|
2012-04-22 20:51:28 +02:00
|
|
|
menu.addAction(qIconProvider->fromTheme("user-bookmarks"), tr("&Organize Bookmarks"), p_QupZilla, SLOT(showBookmarksManager()));
|
2011-03-02 16:57:41 +01:00
|
|
|
menu.addSeparator();
|
2012-02-17 19:54:58 +01:00
|
|
|
QAction act(tr("Show Most &Visited"), this);
|
|
|
|
act.setCheckable(true);
|
|
|
|
act.setChecked(m_bookmarksModel->isShowingMostVisited());
|
|
|
|
connect(&act, SIGNAL(triggered()), this, SLOT(showMostVisited()));
|
|
|
|
menu.addAction(&act);
|
|
|
|
QAction act2(tr("Show Only Icons"), this);
|
|
|
|
act2.setCheckable(true);
|
|
|
|
act2.setChecked(m_bookmarksModel->isShowingOnlyIconsInToolbar());
|
|
|
|
connect(&act2, SIGNAL(triggered()), this, SLOT(toggleShowOnlyIcons()));
|
|
|
|
menu.addAction(&act2);
|
|
|
|
menu.addSeparator();
|
2011-04-09 00:22:50 +02:00
|
|
|
menu.addAction(tr("&Hide Toolbar"), this, SLOT(hidePanel()));
|
2011-03-02 16:57:41 +01:00
|
|
|
|
|
|
|
//Prevent choosing first option with double rightclick
|
2012-03-09 16:02:27 +01:00
|
|
|
QPoint position = mapToGlobal(pos);
|
2011-11-06 17:01:23 +01:00
|
|
|
QPoint p(position.x(), position.y() + 1);
|
2011-03-02 16:57:41 +01:00
|
|
|
menu.exec(p);
|
|
|
|
}
|
|
|
|
|
2011-10-28 17:52:42 +02:00
|
|
|
void BookmarksToolbar::showBookmarkContextMenu(const QPoint &pos)
|
|
|
|
{
|
|
|
|
Q_UNUSED(pos)
|
|
|
|
|
|
|
|
ToolButton* button = qobject_cast<ToolButton*>(sender());
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!button) {
|
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
|
|
|
|
2013-02-05 22:33:54 +01:00
|
|
|
QVariant buttonPointer = QVariant::fromValue((void*) button);
|
2011-10-28 17:52:42 +02:00
|
|
|
|
|
|
|
QMenu menu;
|
2012-10-05 22:15:18 +02:00
|
|
|
menu.addAction(tr("Open bookmark"), this, SLOT(loadClickedBookmark()))->setData(buttonPointer);
|
|
|
|
menu.addAction(tr("Open bookmark in new tab"), this, SLOT(loadClickedBookmarkInNewTab()))->setData(buttonPointer);
|
|
|
|
menu.addSeparator();
|
2012-04-22 20:51:28 +02:00
|
|
|
menu.addAction(qIconProvider->fromTheme("go-next"), tr("Move right"), this, SLOT(moveRight()))->setData(buttonPointer);
|
|
|
|
menu.addAction(qIconProvider->fromTheme("go-previous"), tr("Move left"), this, SLOT(moveLeft()))->setData(buttonPointer);
|
2012-01-18 15:05:50 +01:00
|
|
|
menu.addAction(tr("Edit bookmark"), this, SLOT(editBookmark()))->setData(buttonPointer);
|
2011-10-28 17:52:42 +02:00
|
|
|
menu.addSeparator();
|
2012-04-22 20:51:28 +02:00
|
|
|
menu.addAction(qIconProvider->fromTheme("list-remove"), tr("Remove bookmark"), this, SLOT(removeButton()))->setData(buttonPointer);
|
2011-10-28 17:52:42 +02:00
|
|
|
|
|
|
|
//Prevent choosing first option with double rightclick
|
2012-03-09 16:02:27 +01:00
|
|
|
QPoint position = button->mapToGlobal(pos);
|
2011-11-06 17:01:23 +01:00
|
|
|
QPoint p(position.x(), position.y() + 1);
|
2011-10-28 17:52:42 +02:00
|
|
|
menu.exec(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksToolbar::moveRight()
|
|
|
|
{
|
|
|
|
QAction* act = qobject_cast<QAction*> (sender());
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!act) {
|
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
|
|
|
|
2012-01-03 21:02:35 +01:00
|
|
|
ToolButton* button = static_cast<ToolButton*>(act->data().value<void*>());
|
2011-10-28 17:52:42 +02:00
|
|
|
|
|
|
|
int index = m_layout->indexOf(button);
|
2011-11-06 17:01:23 +01:00
|
|
|
if (index == m_layout->count() - 1) {
|
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
|
|
|
|
|
|
|
ToolButton* buttonRight = qobject_cast<ToolButton*> (m_layout->itemAt(index + 1)->widget());
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!buttonRight || buttonRight->menu()) {
|
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
|
|
|
|
|
|
|
Bookmark bookmark = button->data().value<Bookmark>();
|
|
|
|
Bookmark bookmarkRight = buttonRight->data().value<Bookmark>();
|
|
|
|
|
|
|
|
QSqlQuery query;
|
2012-07-11 18:31:23 +02:00
|
|
|
query.prepare("UPDATE bookmarks SET position=? WHERE id=?");
|
2011-10-28 17:52:42 +02:00
|
|
|
query.addBindValue(index + 1);
|
|
|
|
query.addBindValue(bookmark.id);
|
2011-12-08 19:12:43 +01:00
|
|
|
mApp->dbWriter()->executeQuery(query);
|
2011-10-28 17:52:42 +02:00
|
|
|
|
2012-07-11 18:31:23 +02:00
|
|
|
query.prepare("UPDATE bookmarks SET position=? WHERE id=?");
|
2011-10-28 17:52:42 +02:00
|
|
|
query.addBindValue(index);
|
|
|
|
query.addBindValue(bookmarkRight.id);
|
2011-12-08 19:12:43 +01:00
|
|
|
mApp->dbWriter()->executeQuery(query);
|
2011-10-28 17:52:42 +02:00
|
|
|
|
|
|
|
QWidget* w = m_layout->takeAt(index)->widget();
|
|
|
|
m_layout->insertWidget(index + 1, w);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksToolbar::moveLeft()
|
|
|
|
{
|
|
|
|
QAction* act = qobject_cast<QAction*> (sender());
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!act) {
|
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
|
|
|
|
2012-01-03 21:02:35 +01:00
|
|
|
ToolButton* button = static_cast<ToolButton*>(act->data().value<void*>());
|
2011-10-28 17:52:42 +02:00
|
|
|
|
|
|
|
int index = m_layout->indexOf(button);
|
2011-11-06 17:01:23 +01:00
|
|
|
if (index == 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
|
|
|
|
|
|
|
ToolButton* buttonLeft = qobject_cast<ToolButton*> (m_layout->itemAt(index - 1)->widget());
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!buttonLeft) {
|
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
|
|
|
|
|
|
|
Bookmark bookmark = button->data().value<Bookmark>();
|
|
|
|
Bookmark bookmarkLeft = buttonLeft->data().value<Bookmark>();
|
|
|
|
|
|
|
|
QSqlQuery query;
|
2012-07-11 18:31:23 +02:00
|
|
|
query.prepare("UPDATE bookmarks SET position=? WHERE id=?");
|
2011-10-28 17:52:42 +02:00
|
|
|
query.addBindValue(index - 1);
|
|
|
|
query.addBindValue(bookmark.id);
|
2011-12-08 19:12:43 +01:00
|
|
|
mApp->dbWriter()->executeQuery(query);
|
2011-10-28 17:52:42 +02:00
|
|
|
|
2012-07-11 18:31:23 +02:00
|
|
|
query.prepare("UPDATE bookmarks SET position=? WHERE id=?");
|
2011-10-28 17:52:42 +02:00
|
|
|
query.addBindValue(index);
|
|
|
|
query.addBindValue(bookmarkLeft.id);
|
2011-12-08 19:12:43 +01:00
|
|
|
mApp->dbWriter()->executeQuery(query);
|
2011-10-28 17:52:42 +02:00
|
|
|
|
|
|
|
QWidget* w = m_layout->takeAt(index)->widget();
|
|
|
|
m_layout->insertWidget(index - 1, w);
|
|
|
|
}
|
|
|
|
|
2012-01-18 15:05:50 +01:00
|
|
|
void BookmarksToolbar::editBookmark()
|
|
|
|
{
|
|
|
|
QAction* act = qobject_cast<QAction*> (sender());
|
|
|
|
if (!act) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ToolButton* button = static_cast<ToolButton*>(act->data().value<void*>());
|
|
|
|
if (!button) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Bookmark b = button->data().value<Bookmark>();
|
|
|
|
|
|
|
|
QDialog* dialog = new QDialog(this);
|
|
|
|
QFormLayout* layout = new QFormLayout(dialog);
|
|
|
|
QLabel* label = new QLabel(dialog);
|
|
|
|
QLineEdit* editUrl = new QLineEdit(dialog);
|
|
|
|
QLineEdit* editTitle = new QLineEdit(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()));
|
|
|
|
|
|
|
|
label->setText(tr("Edit bookmark: "));
|
|
|
|
layout->addRow(label);
|
|
|
|
layout->addRow(new QLabel(tr("Title: ")), editTitle);
|
|
|
|
layout->addRow(new QLabel(tr("Url: ")), editUrl);
|
|
|
|
layout->addRow(box);
|
|
|
|
|
|
|
|
editUrl->setText(b.url.toString());
|
|
|
|
editTitle->setText(b.title);
|
2012-01-21 20:27:45 +01:00
|
|
|
editUrl->setCursorPosition(0);
|
|
|
|
editTitle->setCursorPosition(0);
|
2012-01-18 15:05:50 +01:00
|
|
|
|
|
|
|
dialog->setWindowTitle(tr("Edit Bookmark"));
|
|
|
|
dialog->setMinimumSize(400, 100);
|
|
|
|
dialog->exec();
|
|
|
|
if (dialog->result() == QDialog::Rejected) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-31 21:10:22 +01:00
|
|
|
QUrl url = QUrl::fromEncoded(editUrl->text().toUtf8());
|
2012-01-18 15:05:50 +01:00
|
|
|
QString title = editTitle->text();
|
|
|
|
|
|
|
|
if (url.isEmpty() || title.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_bookmarksModel->editBookmark(b.id, title, url, b.folder);
|
|
|
|
}
|
|
|
|
|
2011-10-28 17:52:42 +02:00
|
|
|
void BookmarksToolbar::removeButton()
|
|
|
|
{
|
|
|
|
QAction* act = qobject_cast<QAction*> (sender());
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!act) {
|
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
|
|
|
|
2012-01-03 21:02:35 +01:00
|
|
|
ToolButton* button = static_cast<ToolButton*>(act->data().value<void*>());
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!button) {
|
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
|
|
|
|
|
|
|
Bookmark bookmark = button->data().value<Bookmark>();
|
|
|
|
m_bookmarksModel->removeBookmark(bookmark.id);
|
|
|
|
}
|
|
|
|
|
2011-09-11 19:15:06 +02:00
|
|
|
void BookmarksToolbar::hidePanel()
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2011-09-11 19:15:06 +02:00
|
|
|
p_QupZilla->showBookmarksToolbar();
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2012-02-17 19:54:58 +01:00
|
|
|
void BookmarksToolbar::toggleShowOnlyIcons()
|
|
|
|
{
|
|
|
|
m_bookmarksModel->setShowingOnlyIconsInToolbar(!m_bookmarksModel->isShowingOnlyIconsInToolbar());
|
|
|
|
showOnlyIconsChanged();
|
|
|
|
}
|
|
|
|
|
2011-09-11 19:15:06 +02:00
|
|
|
void BookmarksToolbar::loadClickedBookmark()
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-10-05 22:15:18 +02:00
|
|
|
ToolButton* button = 0;
|
|
|
|
|
|
|
|
QAction* act = qobject_cast<QAction*> (sender());
|
|
|
|
if (act) {
|
|
|
|
button = static_cast<ToolButton*>(act->data().value<void*>());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!button) {
|
|
|
|
button = qobject_cast<ToolButton*>(sender());
|
|
|
|
}
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!button) {
|
2011-09-11 19:15:06 +02:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-09-11 19:15:06 +02:00
|
|
|
|
2011-10-28 17:52:42 +02:00
|
|
|
Bookmark bookmark = button->data().value<Bookmark>();
|
|
|
|
|
|
|
|
p_QupZilla->loadAddress(bookmark.url);
|
2011-09-11 19:15:06 +02:00
|
|
|
}
|
|
|
|
|
2011-10-18 21:07:58 +02:00
|
|
|
void BookmarksToolbar::loadClickedBookmarkInNewTab()
|
|
|
|
{
|
2012-10-05 22:15:18 +02:00
|
|
|
ToolButton* button = 0;
|
|
|
|
|
|
|
|
QAction* act = qobject_cast<QAction*> (sender());
|
|
|
|
if (act) {
|
|
|
|
button = static_cast<ToolButton*>(act->data().value<void*>());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!button) {
|
|
|
|
button = qobject_cast<ToolButton*>(sender());
|
|
|
|
}
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!button) {
|
2011-10-18 21:07:58 +02:00
|
|
|
return;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-10-18 21:07:58 +02:00
|
|
|
|
2011-10-28 17:52:42 +02:00
|
|
|
Bookmark bookmark = button->data().value<Bookmark>();
|
|
|
|
|
2011-12-20 18:58:42 +01:00
|
|
|
p_QupZilla->tabWidget()->addView(bookmark.url, bookmark.title);
|
2011-10-18 21:07:58 +02:00
|
|
|
}
|
|
|
|
|
2011-12-19 21:30:26 +01:00
|
|
|
void BookmarksToolbar::loadFolderBookmarksInTabs()
|
|
|
|
{
|
|
|
|
ToolButton* b = qobject_cast<ToolButton*>(sender());
|
|
|
|
if (!b) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString folder = b->text();
|
|
|
|
if (folder.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-06 09:05:41 +01:00
|
|
|
foreach (const Bookmark &b, m_bookmarksModel->folderBookmarks(folder)) {
|
2012-01-21 23:19:38 +01:00
|
|
|
p_QupZilla->tabWidget()->addView(b.url, b.title, Qz::NT_NotSelectedTab);
|
2011-12-19 21:30:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-11 19:15:06 +02:00
|
|
|
void BookmarksToolbar::showMostVisited()
|
|
|
|
{
|
|
|
|
m_bookmarksModel->setShowingMostVisited(!m_bookmarksModel->isShowingMostVisited());
|
2011-10-17 14:19:49 +02:00
|
|
|
m_mostVis->setVisible(!m_mostVis->isVisible());
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2011-10-28 17:52:42 +02:00
|
|
|
int BookmarksToolbar::indexOfLastBookmark()
|
|
|
|
{
|
|
|
|
for (int i = m_layout->count() - 1; i >= 0; i--) {
|
|
|
|
ToolButton* button = qobject_cast<ToolButton*>(m_layout->itemAt(i)->widget());
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!button) {
|
2011-10-28 17:52:42 +02:00
|
|
|
continue;
|
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 (!button->menu()) {
|
2011-10-28 17:52:42 +02:00
|
|
|
return i + 1;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-10-28 17:52:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksToolbar::subfolderAdded(const QString &name)
|
|
|
|
{
|
|
|
|
ToolButton* b = new ToolButton(this);
|
|
|
|
b->setPopupMode(QToolButton::InstantPopup);
|
2012-03-04 22:30:45 +01:00
|
|
|
b->setToolButtonStyle(m_toolButtonStyle);
|
2011-10-28 17:52:42 +02:00
|
|
|
b->setIcon(style()->standardIcon(QStyle::SP_DirIcon));
|
|
|
|
b->setText(name);
|
2011-12-19 21:30:26 +01:00
|
|
|
connect(b, SIGNAL(middleMouseClicked()), this, SLOT(loadFolderBookmarksInTabs()));
|
2011-10-28 17:52:42 +02:00
|
|
|
|
2011-12-11 17:51:03 +01:00
|
|
|
Menu* menu = new Menu(name);
|
2011-10-28 17:52:42 +02:00
|
|
|
b->setMenu(menu);
|
|
|
|
connect(menu, SIGNAL(aboutToShow()), this, SLOT(aboutToShowFolderMenu()));
|
|
|
|
|
|
|
|
m_layout->insertWidget(m_layout->count() - 2, b);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksToolbar::folderDeleted(const QString &name)
|
|
|
|
{
|
|
|
|
int index = indexOfLastBookmark();
|
|
|
|
|
|
|
|
for (int i = index; i < m_layout->count(); i++) {
|
|
|
|
ToolButton* button = qobject_cast<ToolButton*>(m_layout->itemAt(i)->widget());
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!button) {
|
2011-10-28 17:52:42 +02:00
|
|
|
continue;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-10-28 17:52:42 +02:00
|
|
|
|
|
|
|
if (button->text() == name) {
|
|
|
|
delete button;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksToolbar::folderRenamed(const QString &before, const QString &after)
|
|
|
|
{
|
|
|
|
int index = indexOfLastBookmark();
|
|
|
|
|
|
|
|
for (int i = index; i < m_layout->count(); i++) {
|
|
|
|
ToolButton* button = qobject_cast<ToolButton*>(m_layout->itemAt(i)->widget());
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!button) {
|
2011-10-28 17:52:42 +02:00
|
|
|
continue;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-10-28 17:52:42 +02:00
|
|
|
|
|
|
|
if (button->text() == before) {
|
|
|
|
button->setText(after);
|
|
|
|
button->menu()->setTitle(after);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-05 23:52:40 +02:00
|
|
|
void BookmarksToolbar::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 (oldParent != _bookmarksToolbar && newParent != _bookmarksToolbar) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool itemIsAboutToRemove = (newParent != _bookmarksToolbar);
|
|
|
|
|
|
|
|
Bookmark bookmark;
|
|
|
|
bookmark.id = id;
|
|
|
|
bookmark.url = url;
|
|
|
|
bookmark.title = name;
|
|
|
|
bookmark.folder = QLatin1String("bookmarksToolbar");
|
|
|
|
bookmark.image = QImage::fromData(imageData);
|
|
|
|
bookmark.inSubfolder = false;
|
|
|
|
|
|
|
|
if (itemIsAboutToRemove) {
|
|
|
|
removeBookmark(bookmark);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
addBookmark(bookmark);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksToolbar::changeFolderParent(const QString &name, bool isSubfolder)
|
|
|
|
{
|
|
|
|
if (!isSubfolder) {
|
|
|
|
folderDeleted(name);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
subfolderAdded(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-15 20:45:22 +02:00
|
|
|
void BookmarksToolbar::addBookmark(const BookmarksModel::Bookmark &bookmark)
|
2011-03-02 16:57:41 +01:00
|
|
|
{
|
2012-09-05 19:57:36 +02:00
|
|
|
if (bookmark.folder != QLatin1String("bookmarksToolbar")) {
|
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
|
|
|
QString title = bookmark.title;
|
2011-11-06 17:01:23 +01:00
|
|
|
if (title.length() > 15) {
|
2011-04-15 20:45:22 +02:00
|
|
|
title.truncate(13);
|
2011-11-06 17:01:23 +01:00
|
|
|
title += "..";
|
2011-04-15 20:45:22 +02:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
|
2011-10-28 17:52:42 +02:00
|
|
|
QVariant v;
|
|
|
|
v.setValue<Bookmark>(bookmark);
|
|
|
|
|
2011-09-11 19:15:06 +02:00
|
|
|
ToolButton* button = new ToolButton(this);
|
|
|
|
button->setText(title);
|
2011-10-28 17:52:42 +02:00
|
|
|
button->setData(v);
|
2012-04-22 20:51:28 +02:00
|
|
|
button->setIcon(qIconProvider->iconFromImage(bookmark.image));
|
2012-03-04 22:30:45 +01:00
|
|
|
button->setToolButtonStyle(m_toolButtonStyle);
|
2011-04-15 20:45:22 +02:00
|
|
|
button->setToolTip(bookmark.url.toEncoded());
|
2011-09-11 19:15:06 +02:00
|
|
|
button->setAutoRaise(true);
|
2011-10-28 17:52:42 +02:00
|
|
|
button->setContextMenuPolicy(Qt::CustomContextMenu);
|
2011-04-15 20:45:22 +02:00
|
|
|
|
2011-09-11 19:15:06 +02:00
|
|
|
connect(button, SIGNAL(clicked()), this, SLOT(loadClickedBookmark()));
|
2011-10-18 21:07:58 +02:00
|
|
|
connect(button, SIGNAL(middleMouseClicked()), this, SLOT(loadClickedBookmarkInNewTab()));
|
2011-12-07 15:17:21 +01:00
|
|
|
connect(button, SIGNAL(controlClicked()), this, SLOT(loadClickedBookmarkInNewTab()));
|
2011-10-28 17:52:42 +02:00
|
|
|
connect(button, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showBookmarkContextMenu(QPoint)));
|
|
|
|
|
|
|
|
int indexForBookmark = indexOfLastBookmark();
|
|
|
|
m_layout->insertWidget(indexForBookmark, button);
|
|
|
|
|
|
|
|
QSqlQuery query;
|
2012-07-11 18:31:23 +02:00
|
|
|
query.prepare("UPDATE bookmarks SET position=? WHERE id=?");
|
2011-10-28 17:52:42 +02:00
|
|
|
query.addBindValue(indexForBookmark);
|
|
|
|
query.addBindValue(bookmark.id);
|
2011-12-08 19:12:43 +01:00
|
|
|
mApp->dbWriter()->executeQuery(query);
|
2011-04-15 20:45:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksToolbar::removeBookmark(const BookmarksModel::Bookmark &bookmark)
|
|
|
|
{
|
2011-09-11 19:15:06 +02:00
|
|
|
for (int i = 0; i < m_layout->count(); i++) {
|
|
|
|
ToolButton* button = qobject_cast<ToolButton*>(m_layout->itemAt(i)->widget());
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!button) {
|
2011-04-15 20:45:22 +02:00
|
|
|
continue;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-04-15 20:45:22 +02:00
|
|
|
|
2011-10-28 17:52:42 +02:00
|
|
|
Bookmark book = button->data().value<Bookmark>();
|
|
|
|
|
|
|
|
if (book == bookmark) {
|
2011-04-15 20:45:22 +02:00
|
|
|
delete button;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksToolbar::bookmarkEdited(const BookmarksModel::Bookmark &before, const BookmarksModel::Bookmark &after)
|
|
|
|
{
|
2012-09-04 12:42:45 +02:00
|
|
|
if (before.folder == QLatin1String("bookmarksToolbar") && after.folder != QLatin1String("bookmarksToolbar")) {
|
|
|
|
// Editing from toolbar folder to other folder -> Remove bookmark
|
2011-04-15 20:45:22 +02:00
|
|
|
removeBookmark(before);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2012-09-04 12:42:45 +02:00
|
|
|
else if (before.folder != QLatin1String("bookmarksToolbar") && after.folder == QLatin1String("bookmarksToolbar")) {
|
|
|
|
// Editing from other folder to toolbar folder -> Add bookmark
|
2011-04-15 20:45:22 +02:00
|
|
|
addBookmark(after);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2012-09-04 12:42:45 +02:00
|
|
|
else {
|
|
|
|
// Editing bookmark already in toolbar
|
2011-09-11 19:15:06 +02:00
|
|
|
for (int i = 0; i < m_layout->count(); i++) {
|
|
|
|
ToolButton* button = qobject_cast<ToolButton*>(m_layout->itemAt(i)->widget());
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!button) {
|
2011-04-15 20:45:22 +02:00
|
|
|
continue;
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-04-15 20:45:22 +02:00
|
|
|
|
2011-10-28 17:52:42 +02:00
|
|
|
Bookmark book = button->data().value<Bookmark>();
|
|
|
|
|
|
|
|
if (book == before) {
|
2011-04-15 20:45:22 +02:00
|
|
|
QString title = after.title;
|
2011-11-06 17:01:23 +01:00
|
|
|
if (title.length() > 15) {
|
2011-04-15 20:45:22 +02:00
|
|
|
title.truncate(13);
|
2011-11-06 17:01:23 +01:00
|
|
|
title += "..";
|
2011-04-15 20:45:22 +02:00
|
|
|
}
|
|
|
|
|
2011-10-28 17:52:42 +02:00
|
|
|
QVariant v;
|
|
|
|
v.setValue<Bookmark>(after);
|
|
|
|
|
2011-09-11 19:15:06 +02:00
|
|
|
button->setText(title);
|
2011-10-28 17:52:42 +02:00
|
|
|
button->setData(v);
|
2012-04-22 20:51:28 +02:00
|
|
|
button->setIcon(qIconProvider->iconFromImage(after.image));
|
2011-04-15 20:45:22 +02:00
|
|
|
button->setToolTip(after.url.toEncoded());
|
2011-10-28 17:52:42 +02:00
|
|
|
return;
|
2011-04-15 20:45:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BookmarksToolbar::refreshBookmarks()
|
|
|
|
{
|
2011-03-02 16:57:41 +01:00
|
|
|
QSqlQuery query;
|
2012-07-11 18:31:23 +02:00
|
|
|
query.exec("SELECT id, title, url, icon FROM bookmarks WHERE folder='bookmarksToolbar' ORDER BY position");
|
2011-11-06 17:01:23 +01:00
|
|
|
while (query.next()) {
|
2011-10-28 17:52:42 +02:00
|
|
|
Bookmark bookmark;
|
|
|
|
bookmark.id = query.value(0).toInt();
|
|
|
|
bookmark.title = query.value(1).toString();
|
|
|
|
bookmark.url = query.value(2).toUrl();
|
2012-01-17 19:27:24 +01:00
|
|
|
bookmark.image = QImage::fromData(query.value(3).toByteArray());
|
2011-10-28 17:52:42 +02:00
|
|
|
bookmark.folder = "bookmarksToolbar";
|
|
|
|
QString title = bookmark.title;
|
2011-11-06 17:01:23 +01:00
|
|
|
if (title.length() > 15) {
|
2011-03-02 16:57:41 +01:00
|
|
|
title.truncate(13);
|
2011-11-06 17:01:23 +01:00
|
|
|
title += "..";
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2011-10-28 17:52:42 +02:00
|
|
|
QVariant v;
|
|
|
|
v.setValue<Bookmark>(bookmark);
|
|
|
|
|
2011-09-11 19:15:06 +02:00
|
|
|
ToolButton* button = new ToolButton(this);
|
|
|
|
button->setText(title);
|
2011-10-28 17:52:42 +02:00
|
|
|
button->setData(v);
|
2012-04-22 20:51:28 +02:00
|
|
|
button->setIcon(qIconProvider->iconFromImage(bookmark.image));
|
2012-03-04 22:30:45 +01:00
|
|
|
button->setToolButtonStyle(m_toolButtonStyle);
|
2011-10-28 17:52:42 +02:00
|
|
|
button->setToolTip(bookmark.url.toEncoded());
|
2011-09-11 19:15:06 +02:00
|
|
|
button->setAutoRaise(true);
|
2011-10-28 17:52:42 +02:00
|
|
|
button->setContextMenuPolicy(Qt::CustomContextMenu);
|
2011-09-11 19:15:06 +02:00
|
|
|
|
|
|
|
connect(button, SIGNAL(clicked()), this, SLOT(loadClickedBookmark()));
|
2011-10-18 21:07:58 +02:00
|
|
|
connect(button, SIGNAL(middleMouseClicked()), this, SLOT(loadClickedBookmarkInNewTab()));
|
2011-12-07 15:17:21 +01:00
|
|
|
connect(button, SIGNAL(controlClicked()), this, SLOT(loadClickedBookmarkInNewTab()));
|
2011-10-28 17:52:42 +02:00
|
|
|
connect(button, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(showBookmarkContextMenu(QPoint)));
|
2011-09-11 19:15:06 +02:00
|
|
|
m_layout->addWidget(button);
|
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-10-28 17:52:42 +02:00
|
|
|
ToolButton* b = new ToolButton(this);
|
|
|
|
b->setPopupMode(QToolButton::InstantPopup);
|
2012-03-04 22:30:45 +01:00
|
|
|
b->setToolButtonStyle(m_toolButtonStyle);
|
2011-10-28 17:52:42 +02:00
|
|
|
b->setIcon(style()->standardIcon(QStyle::SP_DirIcon));
|
|
|
|
b->setText(query.value(0).toString());
|
2011-12-19 21:30:26 +01:00
|
|
|
connect(b, SIGNAL(middleMouseClicked()), this, SLOT(loadFolderBookmarksInTabs()));
|
2011-10-28 17:52:42 +02:00
|
|
|
|
2011-12-11 17:51:03 +01:00
|
|
|
Menu* menu = new Menu(query.value(0).toString());
|
2011-10-28 17:52:42 +02:00
|
|
|
b->setMenu(menu);
|
|
|
|
connect(menu, SIGNAL(aboutToShow()), this, SLOT(aboutToShowFolderMenu()));
|
|
|
|
|
|
|
|
m_layout->addWidget(b);
|
|
|
|
}
|
|
|
|
|
2011-09-11 19:15:06 +02:00
|
|
|
m_mostVis = new ToolButton(this);
|
2011-04-15 20:45:22 +02:00
|
|
|
m_mostVis->setPopupMode(QToolButton::InstantPopup);
|
2012-03-04 22:30:45 +01:00
|
|
|
m_mostVis->setToolButtonStyle(m_toolButtonStyle);
|
2011-04-15 20:45:22 +02:00
|
|
|
m_mostVis->setIcon(style()->standardIcon(QStyle::SP_DirIcon));
|
|
|
|
m_mostVis->setText(tr("Most visited"));
|
2011-10-21 23:26:34 +02:00
|
|
|
m_mostVis->setToolTip(tr("Sites you visited the most"));
|
2011-04-15 20:45:22 +02:00
|
|
|
|
2011-12-11 17:51:03 +01:00
|
|
|
m_menuMostVisited = new Menu();
|
2011-04-15 20:45:22 +02:00
|
|
|
m_mostVis->setMenu(m_menuMostVisited);
|
2011-03-02 16:57:41 +01:00
|
|
|
connect(m_menuMostVisited, SIGNAL(aboutToShow()), this, SLOT(refreshMostVisited()));
|
|
|
|
|
2011-09-11 19:15:06 +02:00
|
|
|
m_layout->addWidget(m_mostVis);
|
|
|
|
m_layout->addStretch();
|
2011-10-17 14:19:49 +02:00
|
|
|
|
|
|
|
m_mostVis->setVisible(m_bookmarksModel->isShowingMostVisited());
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
|
|
|
|
2011-10-28 17:52:42 +02:00
|
|
|
void BookmarksToolbar::aboutToShowFolderMenu()
|
|
|
|
{
|
|
|
|
QMenu* menu = qobject_cast<QMenu*> (sender());
|
2011-11-06 17:01:23 +01:00
|
|
|
if (!menu) {
|
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
|
|
|
|
|
|
|
menu->clear();
|
|
|
|
QString folder = menu->title();
|
|
|
|
|
2013-03-06 09:05:41 +01:00
|
|
|
foreach (const Bookmark &b, m_bookmarksModel->folderBookmarks(folder)) {
|
2012-01-23 17:30:34 +01:00
|
|
|
QString title = b.title;
|
|
|
|
if (title.length() > 40) {
|
|
|
|
title.truncate(40);
|
|
|
|
title += "..";
|
2011-10-28 17:52:42 +02:00
|
|
|
}
|
2011-12-11 17:51:03 +01:00
|
|
|
|
2012-04-22 20:51:28 +02:00
|
|
|
Action* act = new Action(qIconProvider->iconFromImage(b.image), title);
|
2011-12-19 21:30:26 +01:00
|
|
|
act->setData(b.url);
|
2011-12-12 21:14:43 +01:00
|
|
|
connect(act, SIGNAL(triggered()), p_QupZilla, SLOT(loadActionUrl()));
|
2011-12-16 20:17:17 +01:00
|
|
|
connect(act, SIGNAL(middleClicked()), p_QupZilla, SLOT(loadActionUrlInNewNotSelectedTab()));
|
2011-12-11 17:51:03 +01:00
|
|
|
menu->addAction(act);
|
2011-10-28 17:52:42 +02:00
|
|
|
}
|
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (menu->isEmpty()) {
|
2012-01-23 17:30:34 +01:00
|
|
|
menu->addAction(tr("Empty"))->setEnabled(false);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-10-28 17:52:42 +02:00
|
|
|
}
|
|
|
|
|
2012-03-05 11:30:18 +01:00
|
|
|
void BookmarksToolbar::dropEvent(QDropEvent* e)
|
|
|
|
{
|
|
|
|
const QMimeData* mime = e->mimeData();
|
|
|
|
|
|
|
|
if (!mime->hasUrls() || !mime->hasText()) {
|
|
|
|
QWidget::dropEvent(e);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString title = mime->text();
|
|
|
|
QUrl url = mime->urls().at(0);
|
2012-04-22 20:51:28 +02:00
|
|
|
QIcon icon = qIconProvider->iconFromImage(qvariant_cast<QImage>(mime->imageData()));
|
2012-03-05 11:30:18 +01:00
|
|
|
|
|
|
|
m_bookmarksModel->saveBookmark(url, title, icon, "bookmarksToolbar");
|
|
|
|
}
|
|
|
|
|
2011-12-17 16:04:04 +01:00
|
|
|
void BookmarksToolbar::dragEnterEvent(QDragEnterEvent* e)
|
2011-12-17 14:26:34 +01:00
|
|
|
{
|
|
|
|
const QMimeData* mime = e->mimeData();
|
|
|
|
|
2012-03-05 11:30:18 +01:00
|
|
|
if (mime->hasUrls() && mime->hasText()) {
|
2011-12-17 14:26:34 +01:00
|
|
|
e->acceptProposedAction();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-05 11:30:18 +01:00
|
|
|
QWidget::dragEnterEvent(e);
|
2011-12-17 14:26:34 +01:00
|
|
|
}
|
|
|
|
|
2012-02-17 19:54:58 +01:00
|
|
|
void BookmarksToolbar::showOnlyIconsChanged()
|
|
|
|
{
|
2012-04-04 17:41:33 +02:00
|
|
|
m_toolButtonStyle = m_bookmarksModel->isShowingOnlyIconsInToolbar() ? Qt::ToolButtonIconOnly : Qt::ToolButtonTextBesideIcon;
|
2012-02-17 19:54:58 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < m_layout->count(); ++i) {
|
|
|
|
ToolButton* button = qobject_cast<ToolButton*>(m_layout->itemAt(i)->widget());
|
|
|
|
if (!button) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-03-04 22:30:45 +01:00
|
|
|
button->setToolButtonStyle(m_toolButtonStyle);
|
2012-02-17 19:54:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-02 16:57:41 +01:00
|
|
|
void BookmarksToolbar::refreshMostVisited()
|
|
|
|
{
|
|
|
|
m_menuMostVisited->clear();
|
|
|
|
|
2013-02-26 12:56:11 +01:00
|
|
|
QVector<HistoryEntry> mostList = m_historyModel->mostVisited(10);
|
2013-03-06 09:05:41 +01:00
|
|
|
foreach (const HistoryEntry &entry, mostList) {
|
2012-01-23 17:30:34 +01:00
|
|
|
QString title = entry.title;
|
|
|
|
if (title.length() > 40) {
|
|
|
|
title.truncate(40);
|
|
|
|
title += "..";
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
2011-12-11 17:51:03 +01:00
|
|
|
|
2012-01-23 17:30:34 +01:00
|
|
|
Action* act = new Action(_iconForUrl(entry.url), title);
|
2011-12-11 17:51:03 +01:00
|
|
|
act->setData(entry.url);
|
2011-12-12 21:14:43 +01:00
|
|
|
connect(act, SIGNAL(triggered()), p_QupZilla, SLOT(loadActionUrl()));
|
2011-12-16 20:17:17 +01:00
|
|
|
connect(act, SIGNAL(middleClicked()), p_QupZilla, SLOT(loadActionUrlInNewNotSelectedTab()));
|
2011-12-11 17:51:03 +01:00
|
|
|
m_menuMostVisited->addAction(act);
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|
2011-10-28 17:52:42 +02:00
|
|
|
|
2011-11-06 17:01:23 +01:00
|
|
|
if (m_menuMostVisited->isEmpty()) {
|
2012-01-23 17:30:34 +01:00
|
|
|
m_menuMostVisited->addAction(tr("Empty"))->setEnabled(false);
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-03-02 16:57:41 +01:00
|
|
|
}
|