2011-04-15 20:45:22 +02:00
|
|
|
/* ============================================================
|
2017-08-25 17:11:29 +02:00
|
|
|
* Falkon - Qt web browser
|
2014-01-11 16:11:42 +01:00
|
|
|
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
|
2011-04-15 20:45:22 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* ============================================================ */
|
|
|
|
#include "bookmarkssidebar.h"
|
|
|
|
#include "ui_bookmarkssidebar.h"
|
2014-02-09 11:02:51 +01:00
|
|
|
#include "bookmarkstools.h"
|
|
|
|
#include "bookmarkitem.h"
|
2014-02-05 15:26:51 +01:00
|
|
|
#include "bookmarks.h"
|
2014-02-09 11:02:51 +01:00
|
|
|
#include "mainapplication.h"
|
2014-03-24 16:08:33 +01:00
|
|
|
#include "iconprovider.h"
|
2011-04-15 20:45:22 +02:00
|
|
|
|
2012-02-29 18:33:50 +01:00
|
|
|
#include <QMenu>
|
|
|
|
|
2014-02-19 22:07:21 +01:00
|
|
|
BookmarksSidebar::BookmarksSidebar(BrowserWindow* window, QWidget* parent)
|
2011-10-18 21:07:58 +02:00
|
|
|
: QWidget(parent)
|
|
|
|
, ui(new Ui::BookmarksSideBar)
|
2014-02-19 22:07:21 +01:00
|
|
|
, m_window(window)
|
2014-02-05 15:26:51 +01:00
|
|
|
, m_bookmarks(mApp->bookmarks())
|
2011-04-15 20:45:22 +02:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2014-02-09 11:02:51 +01:00
|
|
|
ui->tree->setViewType(BookmarksTreeView::BookmarksSidebarViewType);
|
2011-04-15 20:45:22 +02:00
|
|
|
|
2014-02-09 11:02:51 +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(contextMenuRequested(QPoint)), this, SLOT(createContextMenu(QPoint)));
|
2011-12-04 16:54:57 +01:00
|
|
|
|
2014-02-09 15:44:38 +01:00
|
|
|
connect(ui->search, SIGNAL(textChanged(QString)), ui->tree, SLOT(search(QString)));
|
2011-04-15 20:45:22 +02:00
|
|
|
}
|
|
|
|
|
2014-02-09 11:02:51 +01:00
|
|
|
BookmarksSidebar::~BookmarksSidebar()
|
2011-04-15 20:45:22 +02:00
|
|
|
{
|
2014-02-09 11:02:51 +01:00
|
|
|
delete ui;
|
2011-04-15 20:45:22 +02:00
|
|
|
}
|
|
|
|
|
2014-02-09 11:02:51 +01:00
|
|
|
void BookmarksSidebar::bookmarkActivated(BookmarkItem* item)
|
2011-10-28 17:52:42 +02:00
|
|
|
{
|
2014-02-09 11:02:51 +01:00
|
|
|
openBookmark(item);
|
2011-10-28 17:52:42 +02:00
|
|
|
}
|
|
|
|
|
2014-02-09 11:02:51 +01:00
|
|
|
void BookmarksSidebar::bookmarkCtrlActivated(BookmarkItem* item)
|
2011-04-15 20:45:22 +02:00
|
|
|
{
|
2014-02-09 11:02:51 +01:00
|
|
|
openBookmarkInNewTab(item);
|
2011-04-15 20:45:22 +02:00
|
|
|
}
|
|
|
|
|
2014-02-09 11:02:51 +01:00
|
|
|
void BookmarksSidebar::bookmarkShiftActivated(BookmarkItem* item)
|
2011-04-15 20:45:22 +02:00
|
|
|
{
|
2014-02-09 11:02:51 +01:00
|
|
|
openBookmarkInNewWindow(item);
|
2011-04-15 20:45:22 +02:00
|
|
|
}
|
|
|
|
|
2014-02-09 11:02:51 +01:00
|
|
|
void BookmarksSidebar::openBookmark(BookmarkItem* item)
|
2011-04-15 20:45:22 +02:00
|
|
|
{
|
2014-02-09 11:02:51 +01:00
|
|
|
item = item ? item : ui->tree->selectedBookmark();
|
|
|
|
BookmarksTools::openBookmark(m_window, item);
|
2011-04-15 20:45:22 +02:00
|
|
|
}
|
|
|
|
|
2014-02-09 11:02:51 +01:00
|
|
|
void BookmarksSidebar::openBookmarkInNewTab(BookmarkItem* item)
|
2011-04-15 20:45:22 +02:00
|
|
|
{
|
2014-02-09 11:02:51 +01:00
|
|
|
item = item ? item : ui->tree->selectedBookmark();
|
|
|
|
BookmarksTools::openBookmarkInNewTab(m_window, item);
|
2011-04-15 20:45:22 +02:00
|
|
|
}
|
|
|
|
|
2014-02-09 11:02:51 +01:00
|
|
|
void BookmarksSidebar::openBookmarkInNewWindow(BookmarkItem* item)
|
2011-04-15 20:45:22 +02:00
|
|
|
{
|
2014-02-09 11:02:51 +01:00
|
|
|
item = item ? item : ui->tree->selectedBookmark();
|
|
|
|
BookmarksTools::openBookmarkInNewWindow(item);
|
2011-04-15 20:45:22 +02:00
|
|
|
}
|
|
|
|
|
2014-02-22 15:20:54 +01:00
|
|
|
void BookmarksSidebar::openBookmarkInNewPrivateWindow(BookmarkItem* item)
|
|
|
|
{
|
|
|
|
item = item ? item : ui->tree->selectedBookmark();
|
|
|
|
BookmarksTools::openBookmarkInNewPrivateWindow(item);
|
|
|
|
}
|
|
|
|
|
2014-02-09 11:02:51 +01:00
|
|
|
void BookmarksSidebar::deleteBookmarks()
|
2011-04-15 20:45:22 +02:00
|
|
|
{
|
2014-02-09 11:02:51 +01:00
|
|
|
QList<BookmarkItem*> items = ui->tree->selectedBookmarks();
|
2011-04-15 20:45:22 +02:00
|
|
|
|
2014-02-09 11:02:51 +01:00
|
|
|
foreach (BookmarkItem* item, items) {
|
|
|
|
if (m_bookmarks->canBeModified(item)) {
|
|
|
|
m_bookmarks->removeBookmark(item);
|
|
|
|
}
|
2011-11-06 17:01:23 +01:00
|
|
|
}
|
2011-04-15 20:45:22 +02:00
|
|
|
}
|
|
|
|
|
2014-02-09 11:02:51 +01:00
|
|
|
void BookmarksSidebar::createContextMenu(const QPoint &pos)
|
2011-10-28 17:52:42 +02:00
|
|
|
{
|
2014-02-09 11:02:51 +01:00
|
|
|
QMenu menu;
|
2014-03-24 16:08:33 +01:00
|
|
|
QAction* actNewTab = menu.addAction(IconProvider::newTabIcon(), tr("Open in new tab"));
|
|
|
|
QAction* actNewWindow = menu.addAction(IconProvider::newWindowIcon(), tr("Open in new window"));
|
|
|
|
QAction* actNewPrivateWindow = menu.addAction(IconProvider::privateBrowsingIcon(), tr("Open in new private window"));
|
2014-02-22 15:20:54 +01:00
|
|
|
|
2014-02-09 11:02:51 +01:00
|
|
|
menu.addSeparator();
|
|
|
|
QAction* actDelete = menu.addAction(QIcon::fromTheme("edit-delete"), tr("Delete"));
|
2011-10-28 17:52:42 +02:00
|
|
|
|
2014-02-09 11:02:51 +01:00
|
|
|
connect(actNewTab, SIGNAL(triggered()), this, SLOT(openBookmarkInNewTab()));
|
|
|
|
connect(actNewWindow, SIGNAL(triggered()), this, SLOT(openBookmarkInNewWindow()));
|
2014-02-22 15:20:54 +01:00
|
|
|
connect(actNewPrivateWindow, SIGNAL(triggered()), this, SLOT(openBookmarkInNewPrivateWindow()));
|
2014-02-09 11:02:51 +01:00
|
|
|
connect(actDelete, SIGNAL(triggered()), this, SLOT(deleteBookmarks()));
|
2012-09-05 23:52:40 +02:00
|
|
|
|
2014-02-09 11:02:51 +01:00
|
|
|
bool canBeDeleted = false;
|
|
|
|
QList<BookmarkItem*> items = ui->tree->selectedBookmarks();
|
2012-09-05 23:52:40 +02:00
|
|
|
|
2014-02-09 11:02:51 +01:00
|
|
|
foreach (BookmarkItem* item, items) {
|
|
|
|
if (m_bookmarks->canBeModified(item)) {
|
|
|
|
canBeDeleted = true;
|
2012-09-05 23:52:40 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-09 11:02:51 +01:00
|
|
|
if (!canBeDeleted) {
|
|
|
|
actDelete->setDisabled(true);
|
2012-09-05 23:52:40 +02:00
|
|
|
}
|
2012-09-02 15:53:00 +02:00
|
|
|
|
2014-02-09 11:02:51 +01:00
|
|
|
if (!ui->tree->selectedBookmark() || !ui->tree->selectedBookmark()->isUrl()) {
|
|
|
|
actNewTab->setDisabled(true);
|
|
|
|
actNewWindow->setDisabled(true);
|
2014-02-22 15:20:54 +01:00
|
|
|
actNewPrivateWindow->setDisabled(true);
|
2012-09-02 15:53:00 +02:00
|
|
|
}
|
|
|
|
|
2014-02-09 11:02:51 +01:00
|
|
|
menu.exec(pos);
|
2011-04-15 20:45:22 +02:00
|
|
|
}
|