mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 18:56:34 +01:00
Added initial support for sidebar widget + rewritten bookmarks backend
This commit is contained in:
parent
a84af542ab
commit
b81de62f24
Binary file not shown.
Binary file not shown.
@ -107,7 +107,10 @@ SOURCES += main.cpp\
|
|||||||
adblock/adblockmanager.cpp \
|
adblock/adblockmanager.cpp \
|
||||||
adblock/adblockdialog.cpp \
|
adblock/adblockdialog.cpp \
|
||||||
adblock/adblockblockednetworkreply.cpp \
|
adblock/adblockblockednetworkreply.cpp \
|
||||||
adblock/adblockicon.cpp
|
adblock/adblockicon.cpp \
|
||||||
|
tools/docktitlebarwidget.cpp \
|
||||||
|
sidebar/bookmarkssidebar.cpp \
|
||||||
|
bookmarks/bookmarkicon.cpp
|
||||||
|
|
||||||
HEADERS += 3rdparty/squeezelabel.h \
|
HEADERS += 3rdparty/squeezelabel.h \
|
||||||
3rdparty/qtwin.h \
|
3rdparty/qtwin.h \
|
||||||
@ -174,7 +177,10 @@ HEADERS += 3rdparty/squeezelabel.h \
|
|||||||
adblock/adblockmanager.h \
|
adblock/adblockmanager.h \
|
||||||
adblock/adblockdialog.h \
|
adblock/adblockdialog.h \
|
||||||
adblock/adblockblockednetworkreply.h \
|
adblock/adblockblockednetworkreply.h \
|
||||||
adblock/adblockicon.h
|
adblock/adblockicon.h \
|
||||||
|
tools/docktitlebarwidget.h \
|
||||||
|
sidebar/bookmarkssidebar.h \
|
||||||
|
bookmarks/bookmarkicon.h
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
preferences/autofillmanager.ui \
|
preferences/autofillmanager.ui \
|
||||||
@ -198,7 +204,9 @@ FORMS += \
|
|||||||
other/clearprivatedata.ui \
|
other/clearprivatedata.ui \
|
||||||
other/sourceviewersearch.ui \
|
other/sourceviewersearch.ui \
|
||||||
other/closedialog.ui \
|
other/closedialog.ui \
|
||||||
adblock/adblockdialog.ui
|
adblock/adblockdialog.ui \
|
||||||
|
tools/docktitlebarwidget.ui \
|
||||||
|
sidebar/bookmarkssidebar.ui
|
||||||
|
|
||||||
RESOURCES += \
|
RESOURCES += \
|
||||||
data/icons.qrc \
|
data/icons.qrc \
|
||||||
|
@ -45,7 +45,6 @@
|
|||||||
#include "adblockdialog.h"
|
#include "adblockdialog.h"
|
||||||
#include "adblockmanager.h"
|
#include "adblockmanager.h"
|
||||||
#include "adblocksubscription.h"
|
#include "adblocksubscription.h"
|
||||||
#include "ui_adblockdialog.h"
|
|
||||||
#include "mainapplication.h"
|
#include "mainapplication.h"
|
||||||
|
|
||||||
AdBlockDialog::AdBlockDialog(QWidget *parent)
|
AdBlockDialog::AdBlockDialog(QWidget *parent)
|
||||||
|
@ -246,10 +246,18 @@ void QupZilla::setupMenu()
|
|||||||
actionEncoding->setMenu(m_menuEncoding);
|
actionEncoding->setMenu(m_menuEncoding);
|
||||||
connect(m_menuEncoding, SIGNAL(aboutToShow()), this, SLOT(aboutToShowEncodingMenu()));
|
connect(m_menuEncoding, SIGNAL(aboutToShow()), this, SLOT(aboutToShowEncodingMenu()));
|
||||||
|
|
||||||
m_menuView->addAction(m_actionShowMenubar);
|
QMenu* toolbarsMenu = new QMenu(tr("Toolbars"));
|
||||||
m_menuView->addAction(m_actionShowToolbar);
|
toolbarsMenu->addAction(m_actionShowMenubar);
|
||||||
m_menuView->addAction(m_actionShowBookmarksToolbar);
|
toolbarsMenu->addAction(m_actionShowToolbar);
|
||||||
m_menuView->addAction(m_actionShowStatusbar);
|
toolbarsMenu->addAction(m_actionShowBookmarksToolbar);
|
||||||
|
toolbarsMenu->addAction(m_actionShowStatusbar);
|
||||||
|
QMenu* sidebarsMenu = new QMenu(tr("Sidebars"));
|
||||||
|
sidebarsMenu->addAction(tr("Bookmarks"), this, SLOT(showBookmarksSideBar()))->setCheckable(true);
|
||||||
|
sidebarsMenu->addAction(tr("History"), this, SLOT(showHistorySideBar()))->setCheckable(true);
|
||||||
|
sidebarsMenu->addAction(tr("RSS Reader"), this, SLOT(showRssSideBar()))->setCheckable(true);
|
||||||
|
|
||||||
|
m_menuView->addMenu(toolbarsMenu);
|
||||||
|
m_menuView->addMenu(sidebarsMenu);
|
||||||
m_menuView->addSeparator();
|
m_menuView->addSeparator();
|
||||||
m_menuView->addAction(m_actionStop);
|
m_menuView->addAction(m_actionStop);
|
||||||
m_menuView->addAction(m_actionReload);
|
m_menuView->addAction(m_actionReload);
|
||||||
@ -307,8 +315,8 @@ void QupZilla::setBackground(QColor textColor)
|
|||||||
"QMenuBar{color:"+color+";background-image:url(:icons/transp.png); border:none;} QStatusBar{background-image:url(:icons/transp.png); border:none; color:"+color+";}"
|
"QMenuBar{color:"+color+";background-image:url(:icons/transp.png); border:none;} QStatusBar{background-image:url(:icons/transp.png); border:none; color:"+color+";}"
|
||||||
"QMenuBar:item{spacing: 5px; padding: 2px 6px;background: transparent;}"
|
"QMenuBar:item{spacing: 5px; padding: 2px 6px;background: transparent;}"
|
||||||
"QMenuBar::item:pressed { background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,stop:0 lightgray, stop:1 darkgray); border: 1px solid darkgrey; border-top-left-radius: 4px;border-top-right-radius: 4px; border-bottom: none;}"
|
"QMenuBar::item:pressed { background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,stop:0 lightgray, stop:1 darkgray); border: 1px solid darkgrey; border-top-left-radius: 4px;border-top-right-radius: 4px; border-bottom: none;}"
|
||||||
"QSplitter::handle{background-color:transparent;}"
|
|
||||||
);
|
);
|
||||||
|
m_navigation->setStyleSheet("QSplitter::handle{background-color:transparent;}");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -399,10 +399,10 @@ RSSManager* MainApplication::rssManager()
|
|||||||
return m_rssmanager;
|
return m_rssmanager;
|
||||||
}
|
}
|
||||||
|
|
||||||
BookmarksModel* MainApplication::bookmarks()
|
BookmarksModel* MainApplication::bookmarksModel()
|
||||||
{
|
{
|
||||||
if (!m_bookmarksModel)
|
if (!m_bookmarksModel)
|
||||||
m_bookmarksModel = new BookmarksModel();
|
m_bookmarksModel = new BookmarksModel(this);
|
||||||
return m_bookmarksModel;
|
return m_bookmarksModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +78,7 @@ public:
|
|||||||
CookieJar* cookieJar();
|
CookieJar* cookieJar();
|
||||||
RSSManager* rssManager();
|
RSSManager* rssManager();
|
||||||
PluginProxy* plugins();
|
PluginProxy* plugins();
|
||||||
BookmarksModel* bookmarks();
|
BookmarksModel* bookmarksModel();
|
||||||
DownloadManager* downManager();
|
DownloadManager* downManager();
|
||||||
AutoFillModel* autoFill();
|
AutoFillModel* autoFill();
|
||||||
QNetworkDiskCache* networkCache() { return m_networkCache; }
|
QNetworkDiskCache* networkCache() { return m_networkCache; }
|
||||||
|
@ -46,6 +46,8 @@
|
|||||||
#include "ui_closedialog.h"
|
#include "ui_closedialog.h"
|
||||||
#include "adblockmanager.h"
|
#include "adblockmanager.h"
|
||||||
#include "clickablelabel.h"
|
#include "clickablelabel.h"
|
||||||
|
#include "docktitlebarwidget.h"
|
||||||
|
#include "sidebar.h"
|
||||||
|
|
||||||
const QString QupZilla::VERSION = "1.0.0-b1";
|
const QString QupZilla::VERSION = "1.0.0-b1";
|
||||||
//const QString QupZilla::BUILDTIME = QLocale(QLocale::English).toDateTime(__DATE__" "__TIME__, "MMM d yyyy hh:mm:ss").toString("MM/dd/yyyy hh:ss");
|
//const QString QupZilla::BUILDTIME = QLocale(QLocale::English).toDateTime(__DATE__" "__TIME__, "MMM d yyyy hh:mm:ss").toString("MM/dd/yyyy hh:ss");
|
||||||
@ -62,6 +64,7 @@ QupZilla::QupZilla(bool tryRestore, QUrl startUrl) :
|
|||||||
,m_actionPrivateBrowsing(0)
|
,m_actionPrivateBrowsing(0)
|
||||||
,m_webInspectorDock(0)
|
,m_webInspectorDock(0)
|
||||||
,m_webSearchToolbar(0)
|
,m_webSearchToolbar(0)
|
||||||
|
,m_sideBar(0)
|
||||||
{
|
{
|
||||||
setAttribute(Qt::WA_DeleteOnClose);
|
setAttribute(Qt::WA_DeleteOnClose);
|
||||||
this->resize(640,480);
|
this->resize(640,480);
|
||||||
@ -552,6 +555,17 @@ void QupZilla::showBookmarksToolbar()
|
|||||||
settings.setValue("Browser-View-Settings/showBookmarksToolbar", !status);
|
settings.setValue("Browser-View-Settings/showBookmarksToolbar", !status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QupZilla::showBookmarksSideBar()
|
||||||
|
{
|
||||||
|
if (!m_sideBar) {
|
||||||
|
m_sideBar = new SideBar(this);
|
||||||
|
addDockWidget(Qt::LeftDockWidgetArea, m_sideBar);
|
||||||
|
m_sideBar->showBookmarks();
|
||||||
|
} else {
|
||||||
|
delete m_sideBar;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void QupZilla::showNavigationToolbar()
|
void QupZilla::showNavigationToolbar()
|
||||||
{
|
{
|
||||||
if (!menuBar()->isVisible() && !m_actionShowToolbar->isChecked())
|
if (!menuBar()->isVisible() && !m_actionShowToolbar->isChecked())
|
||||||
@ -598,6 +612,7 @@ void QupZilla::showInspector()
|
|||||||
m_webInspector->setPage(weView()->page());
|
m_webInspector->setPage(weView()->page());
|
||||||
addDockWidget(Qt::BottomDockWidgetArea, m_webInspectorDock);
|
addDockWidget(Qt::BottomDockWidgetArea, m_webInspectorDock);
|
||||||
m_webInspectorDock->setWindowTitle(tr("Web Inspector"));
|
m_webInspectorDock->setWindowTitle(tr("Web Inspector"));
|
||||||
|
m_webInspectorDock->setTitleBarWidget(new DockTitleBarWidget(tr("Web Inspector"), m_webInspectorDock));
|
||||||
m_webInspectorDock->setObjectName("WebInspector");
|
m_webInspectorDock->setObjectName("WebInspector");
|
||||||
m_webInspectorDock->setWidget(m_webInspector);
|
m_webInspectorDock->setWidget(m_webInspector);
|
||||||
m_webInspectorDock->setFeatures(QDockWidget::DockWidgetClosable);
|
m_webInspectorDock->setFeatures(QDockWidget::DockWidgetClosable);
|
||||||
|
@ -71,6 +71,7 @@ class AutoFillModel;
|
|||||||
class MainApplication;
|
class MainApplication;
|
||||||
class WebTab;
|
class WebTab;
|
||||||
class AdBlockIcon;
|
class AdBlockIcon;
|
||||||
|
class SideBar;
|
||||||
class QupZilla : public QMainWindow
|
class QupZilla : public QMainWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -152,9 +153,9 @@ private slots:
|
|||||||
void showCookieManager();
|
void showCookieManager();
|
||||||
void showHistoryManager();
|
void showHistoryManager();
|
||||||
void showBookmarksManager();
|
void showBookmarksManager();
|
||||||
|
void showBookmarksSideBar();
|
||||||
void showRSSManager();
|
void showRSSManager();
|
||||||
void showDownloadManager();
|
void showDownloadManager();
|
||||||
|
|
||||||
void showMenubar();
|
void showMenubar();
|
||||||
void showNavigationToolbar();
|
void showNavigationToolbar();
|
||||||
void showStatusbar();
|
void showStatusbar();
|
||||||
@ -223,6 +224,7 @@ private:
|
|||||||
BookmarksToolbar* m_bookmarksToolbar;
|
BookmarksToolbar* m_bookmarksToolbar;
|
||||||
LocationBar* m_locationBar;
|
LocationBar* m_locationBar;
|
||||||
TabWidget* m_tabWidget;
|
TabWidget* m_tabWidget;
|
||||||
|
QPointer<SideBar> m_sideBar;
|
||||||
|
|
||||||
QSplitter* m_navigationSplitter;
|
QSplitter* m_navigationSplitter;
|
||||||
QAction* m_buttonBack;
|
QAction* m_buttonBack;
|
||||||
|
@ -33,7 +33,7 @@ BookmarksManager::BookmarksManager(QupZilla* mainClass, QWidget* parent) :
|
|||||||
,m_isRefreshing(false)
|
,m_isRefreshing(false)
|
||||||
,ui(new Ui::BookmarksManager)
|
,ui(new Ui::BookmarksManager)
|
||||||
,p_QupZilla(mainClass)
|
,p_QupZilla(mainClass)
|
||||||
,m_bookmarksModel(mApp->bookmarks())
|
,m_bookmarksModel(mApp->bookmarksModel())
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
//CENTER on scren
|
//CENTER on scren
|
||||||
@ -75,8 +75,8 @@ void BookmarksManager::addFolder()
|
|||||||
QString text = QInputDialog::getText(this, tr("Add new folder"), tr("Choose name for new bookmark folder: "));
|
QString text = QInputDialog::getText(this, tr("Add new folder"), tr("Choose name for new bookmark folder: "));
|
||||||
if (text.isEmpty())
|
if (text.isEmpty())
|
||||||
return;
|
return;
|
||||||
QSqlQuery query;
|
|
||||||
query.exec("INSERT INTO folders (name) VALUES ('"+text+"')");
|
m_bookmarksModel->createFolder(text);
|
||||||
refreshTable();
|
refreshTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ void BookmarksManager::itemChanged(QTreeWidgetItem* item)
|
|||||||
QUrl url = QUrl(item->text(1));
|
QUrl url = QUrl(item->text(1));
|
||||||
int id = item->whatsThis(1).toInt();
|
int id = item->whatsThis(1).toInt();
|
||||||
|
|
||||||
m_bookmarksModel->editBookmark(id, url, name);
|
m_bookmarksModel->editBookmark(id, name, url, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
void BookmarksManager::itemControlClicked(QTreeWidgetItem* item)
|
void BookmarksManager::itemControlClicked(QTreeWidgetItem* item)
|
||||||
@ -110,24 +110,18 @@ void BookmarksManager::deleteItem()
|
|||||||
QTreeWidgetItem* item = ui->bookmarksTree->currentItem();
|
QTreeWidgetItem* item = ui->bookmarksTree->currentItem();
|
||||||
if (!item)
|
if (!item)
|
||||||
return;
|
return;
|
||||||
QSqlQuery query;
|
|
||||||
|
|
||||||
if (item->text(1).isEmpty()) { // Delete folder
|
if (item->text(1).isEmpty()) { // Delete folder
|
||||||
QString folder = item->text(0);
|
QString folder = item->text(0);
|
||||||
if (folder == tr("Bookmarks In Menu") || folder == tr("Bookmarks In ToolBar"))
|
if (m_bookmarksModel->removeFolder(folder))
|
||||||
return;
|
delete item;
|
||||||
|
|
||||||
query.exec("DELETE FROM folders WHERE name='"+folder+"'");
|
|
||||||
query.exec("DELETE FROM bookmarks WHERE folder='"+folder+"'");
|
|
||||||
delete item;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString id = item->whatsThis(1);
|
int id = item->whatsThis(1).toInt();
|
||||||
|
|
||||||
query.exec("DELETE FROM bookmarks WHERE id="+id);
|
m_bookmarksModel->removeBookmark(id);
|
||||||
delete item;
|
delete item;
|
||||||
getQupZilla()->bookmarksToolbar()->refreshBookmarks();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void BookmarksManager::addBookmark(WebView* view)
|
void BookmarksManager::addBookmark(WebView* view)
|
||||||
@ -141,7 +135,7 @@ void BookmarksManager::moveBookmark()
|
|||||||
if (!item)
|
if (!item)
|
||||||
return;
|
return;
|
||||||
if (QAction* action = qobject_cast<QAction*>(sender())) {
|
if (QAction* action = qobject_cast<QAction*>(sender())) {
|
||||||
m_bookmarksModel->editBookmark(item->whatsThis(1).toInt(), item->text(0), action->data().toString());
|
m_bookmarksModel->editBookmark(item->whatsThis(1).toInt(), item->text(0), QUrl(), action->data().toString());
|
||||||
}
|
}
|
||||||
refreshTable();
|
refreshTable();
|
||||||
}
|
}
|
||||||
@ -290,20 +284,7 @@ void BookmarksManager::insertBookmark(const QUrl &url, const QString &title)
|
|||||||
if (edit->text().isEmpty())
|
if (edit->text().isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
query.prepare("INSERT INTO bookmarks (title, url, folder) VALUES (?,?,?)");
|
m_bookmarksModel->saveBookmark(url, edit->text(), BookmarksModel::fromTranslatedFolder(combo->currentText()));
|
||||||
query.bindValue(0, edit->text());
|
|
||||||
query.bindValue(1, url.toString());
|
|
||||||
if (combo->currentText() == tr("Bookmarks In Menu"))
|
|
||||||
query.bindValue(2,"bookmarksMenu");
|
|
||||||
else if (combo->currentText() == tr("Bookmarks In ToolBar"))
|
|
||||||
query.bindValue(2,"bookmarksToolbar");
|
|
||||||
else if (combo->currentText() == tr("Unsorted Bookmarks"))
|
|
||||||
query.bindValue(2, "unsorted");
|
|
||||||
else query.bindValue(2, combo->currentText());
|
|
||||||
query.exec();
|
|
||||||
|
|
||||||
getQupZilla()->bookmarksToolbar()->refreshBookmarks();
|
|
||||||
getQupZilla()->locationBar()->checkBookmark();
|
|
||||||
delete dialog;
|
delete dialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -345,20 +326,10 @@ void BookmarksManager::insertAllTabs()
|
|||||||
WebView* view = getQupZilla()->weView(i);
|
WebView* view = getQupZilla()->weView(i);
|
||||||
if (!view || view->url().isEmpty())
|
if (!view || view->url().isEmpty())
|
||||||
continue;
|
continue;
|
||||||
query.prepare("INSERT INTO bookmarks (title, url, folder) VALUES (?,?,?)");
|
|
||||||
query.bindValue(0, view->title());
|
m_bookmarksModel->saveBookmark(view->url(), view->title(), BookmarksModel::fromTranslatedFolder(combo->currentText()));
|
||||||
query.bindValue(1, view->url().toString());
|
|
||||||
if (combo->currentText() == tr("Bookmarks In Menu"))
|
|
||||||
query.bindValue(2,"bookmarksMenu");
|
|
||||||
else if (combo->currentText() == tr("Bookmarks In ToolBar"))
|
|
||||||
query.bindValue(2,"bookmarksToolbar");
|
|
||||||
else if (combo->currentText() == tr("Unsorted Bookmarks"))
|
|
||||||
query.bindValue(2, "unsorted");
|
|
||||||
else query.bindValue(2, combo->currentText());
|
|
||||||
query.exec();
|
|
||||||
}
|
}
|
||||||
getQupZilla()->bookmarksToolbar()->refreshBookmarks();
|
|
||||||
getQupZilla()->locationBar()->checkBookmark();
|
|
||||||
delete dialog;
|
delete dialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,8 +15,8 @@
|
|||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* ============================================================ */
|
* ============================================================ */
|
||||||
#include "mainapplication.h"
|
|
||||||
#include "bookmarksmodel.h"
|
#include "bookmarksmodel.h"
|
||||||
|
#include "mainapplication.h"
|
||||||
#include "webview.h"
|
#include "webview.h"
|
||||||
|
|
||||||
// SQLite DB -> table bookmarks + folders
|
// SQLite DB -> table bookmarks + folders
|
||||||
@ -24,7 +24,8 @@
|
|||||||
// However from bookmark icon, it is not possible to add more than one bookmark
|
// However from bookmark icon, it is not possible to add more than one bookmark
|
||||||
// Only from Ctrl+D dialog it is possible
|
// Only from Ctrl+D dialog it is possible
|
||||||
|
|
||||||
BookmarksModel::BookmarksModel()
|
BookmarksModel::BookmarksModel(QObject *parent)
|
||||||
|
: QObject(parent)
|
||||||
{
|
{
|
||||||
loadSettings();
|
loadSettings();
|
||||||
}
|
}
|
||||||
@ -46,7 +47,7 @@ void BookmarksModel::setShowingMostVisited(bool state)
|
|||||||
m_showMostVisited = state;
|
m_showMostVisited = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BookmarksModel::isBookmarked(QUrl url)
|
bool BookmarksModel::isBookmarked(const QUrl &url)
|
||||||
{
|
{
|
||||||
QSqlQuery query;
|
QSqlQuery query;
|
||||||
query.prepare("SELECT count(id) FROM bookmarks WHERE url=?");
|
query.prepare("SELECT count(id) FROM bookmarks WHERE url=?");
|
||||||
@ -58,7 +59,7 @@ bool BookmarksModel::isBookmarked(QUrl url)
|
|||||||
|
|
||||||
// Bookmark search priority:
|
// Bookmark search priority:
|
||||||
// Bookmarks in menu > bookmarks in toolbar -> user folders and unsorted
|
// Bookmarks in menu > bookmarks in toolbar -> user folders and unsorted
|
||||||
int BookmarksModel::bookmarkId(QUrl url)
|
int BookmarksModel::bookmarkId(const QUrl &url)
|
||||||
{
|
{
|
||||||
QSqlQuery query;
|
QSqlQuery query;
|
||||||
query.prepare("SELECT id FROM bookmarks WHERE url=? AND folder='bookmarksMenu' ");
|
query.prepare("SELECT id FROM bookmarks WHERE url=? AND folder='bookmarksMenu' ");
|
||||||
@ -82,7 +83,7 @@ int BookmarksModel::bookmarkId(QUrl url)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BookmarksModel::bookmarkId(QUrl url, QString title, QString folder)
|
int BookmarksModel::bookmarkId(const QUrl &url, const QString &title, const QString &folder)
|
||||||
{
|
{
|
||||||
QSqlQuery query;
|
QSqlQuery query;
|
||||||
query.prepare("SELECT id FROM bookmarks WHERE url=? AND title=? AND folder=? ");
|
query.prepare("SELECT id FROM bookmarks WHERE url=? AND title=? AND folder=? ");
|
||||||
@ -95,22 +96,23 @@ int BookmarksModel::bookmarkId(QUrl url, QString title, QString folder)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList BookmarksModel::getBookmark(int id)
|
BookmarksModel::Bookmark BookmarksModel::getBookmark(int id)
|
||||||
{
|
{
|
||||||
|
Bookmark bookmark;
|
||||||
QSqlQuery query;
|
QSqlQuery query;
|
||||||
query.prepare("SELECT url, title, folder FROM bookmarks WHERE id=?");
|
query.prepare("SELECT url, title, folder FROM bookmarks WHERE id=?");
|
||||||
query.bindValue(0, id);
|
query.bindValue(0, id);
|
||||||
query.exec();
|
query.exec();
|
||||||
if (!query.next())
|
if (query.next()) {
|
||||||
return QStringList();
|
bookmark.id = id;
|
||||||
QStringList list;
|
bookmark.url = query.value(0).toUrl();
|
||||||
list.append(query.value(0).toString());
|
bookmark.title = query.value(1).toString();
|
||||||
list.append(query.value(1).toString());
|
bookmark.folder = query.value(2).toString();
|
||||||
list.append(query.value(2).toString());
|
}
|
||||||
return list;
|
return bookmark;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BookmarksModel::saveBookmark(QUrl url, QString title, QString folder)
|
bool BookmarksModel::saveBookmark(const QUrl &url, const QString &title, const QString &folder)
|
||||||
{
|
{
|
||||||
if (url.isEmpty() || title.isEmpty() || folder.isEmpty())
|
if (url.isEmpty() || title.isEmpty() || folder.isEmpty())
|
||||||
return false;
|
return false;
|
||||||
@ -120,10 +122,20 @@ bool BookmarksModel::saveBookmark(QUrl url, QString title, QString folder)
|
|||||||
query.bindValue(0, url.toString());
|
query.bindValue(0, url.toString());
|
||||||
query.bindValue(1, title);
|
query.bindValue(1, title);
|
||||||
query.bindValue(2, folder);
|
query.bindValue(2, folder);
|
||||||
return query.exec();
|
|
||||||
|
if (!query.exec())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
Bookmark bookmark;
|
||||||
|
bookmark.id = query.lastInsertId().toInt();
|
||||||
|
bookmark.url = url;
|
||||||
|
bookmark.title = title;
|
||||||
|
bookmark.folder = folder;
|
||||||
|
emit bookmarkAdded(bookmark);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BookmarksModel::saveBookmark(WebView* view, QString folder)
|
bool BookmarksModel::saveBookmark(WebView *view, const QString &folder)
|
||||||
{
|
{
|
||||||
return saveBookmark(view->url(), view->title(), folder);
|
return saveBookmark(view->url(), view->title(), folder);
|
||||||
}
|
}
|
||||||
@ -131,12 +143,26 @@ bool BookmarksModel::saveBookmark(WebView* view, QString folder)
|
|||||||
bool BookmarksModel::removeBookmark(int id)
|
bool BookmarksModel::removeBookmark(int id)
|
||||||
{
|
{
|
||||||
QSqlQuery query;
|
QSqlQuery query;
|
||||||
query.prepare("DELETE FROM bookmarks WHERE id = ?");
|
query.prepare("SELECT url, title, folder FROM bookmarks WHERE id = ?");
|
||||||
query.bindValue(0, id);
|
query.bindValue(0, id);
|
||||||
return query.exec();
|
query.exec();
|
||||||
|
if (!query.next())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
Bookmark bookmark;
|
||||||
|
bookmark.id = id;
|
||||||
|
bookmark.url = query.value(0).toUrl();
|
||||||
|
bookmark.title = query.value(1).toString();
|
||||||
|
bookmark.folder = query.value(2).toString();
|
||||||
|
|
||||||
|
if (!query.exec("DELETE FROM bookmarks WHERE id = " + QString::number(id)))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
emit bookmarkDeleted(bookmark);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BookmarksModel::removeBookmark(QUrl url)
|
bool BookmarksModel::removeBookmark(const QUrl &url)
|
||||||
{
|
{
|
||||||
return removeBookmark(bookmarkId(url));
|
return removeBookmark(bookmarkId(url));
|
||||||
}
|
}
|
||||||
@ -146,22 +172,137 @@ bool BookmarksModel::removeBookmark(WebView* view)
|
|||||||
return removeBookmark(bookmarkId(view->url()));
|
return removeBookmark(bookmarkId(view->url()));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BookmarksModel::editBookmark(int id, QString title, QString folder)
|
//bool BookmarksModel::editBookmark(int id, const QString &title, const QString &folder)
|
||||||
|
//{
|
||||||
|
// QSqlQuery query;
|
||||||
|
// query.prepare("UPDATE bookmarks SET title=?, folder=? WHERE id=?");
|
||||||
|
// query.bindValue(0, title);
|
||||||
|
// query.bindValue(1, folder);
|
||||||
|
// query.bindValue(2, id);
|
||||||
|
// return query.exec();
|
||||||
|
//}
|
||||||
|
|
||||||
|
//bool BookmarksModel::editBookmark(int id, const QUrl &url, const QString &title)
|
||||||
|
//{
|
||||||
|
// QSqlQuery query;
|
||||||
|
// query.prepare("UPDATE bookmarks SET title=?, url=? WHERE id=?");
|
||||||
|
// query.bindValue(0, title);
|
||||||
|
// query.bindValue(1, url.toString());
|
||||||
|
// query.bindValue(2, id);
|
||||||
|
// return query.exec();
|
||||||
|
//}
|
||||||
|
|
||||||
|
bool BookmarksModel::editBookmark(int id, const QString &title, const QUrl &url, const QString &folder)
|
||||||
{
|
{
|
||||||
|
if (title.isEmpty() && url.isEmpty() && folder.isEmpty())
|
||||||
|
return false;
|
||||||
QSqlQuery query;
|
QSqlQuery query;
|
||||||
query.prepare("UPDATE bookmarks SET title=?, folder=? WHERE id=?");
|
if (!query.exec("SELECT title, url, folder FROM bookmarks WHERE id = "+QString::number(id)))
|
||||||
query.bindValue(0, title);
|
return false;
|
||||||
query.bindValue(1, folder);
|
|
||||||
query.bindValue(2, id);
|
query.next();
|
||||||
return query.exec();
|
|
||||||
|
Bookmark before;
|
||||||
|
before.id = id;
|
||||||
|
before.title = query.value(0).toString();
|
||||||
|
before.url = query.value(1).toUrl();
|
||||||
|
before.folder = query.value(2).toString();
|
||||||
|
|
||||||
|
Bookmark after;
|
||||||
|
after.id = id;
|
||||||
|
after.title = title.isEmpty() ? before.title : title;
|
||||||
|
after.url = url.isEmpty() ? before.url : url;
|
||||||
|
after.folder = folder.isEmpty() ? before.folder : folder;
|
||||||
|
|
||||||
|
query.prepare("UPDATE bookmarks SET title=?, url=?, folder=? WHERE id = ?");
|
||||||
|
query.bindValue(0, after.title);
|
||||||
|
query.bindValue(1, after.url.toString());
|
||||||
|
query.bindValue(2, after.folder);
|
||||||
|
query.bindValue(3, id);
|
||||||
|
|
||||||
|
if (!query.exec())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
emit bookmarkEdited(before, after);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BookmarksModel::editBookmark(int id, QUrl url, QString title)
|
bool BookmarksModel::createFolder(const QString &name)
|
||||||
{
|
{
|
||||||
QSqlQuery query;
|
QSqlQuery query;
|
||||||
query.prepare("UPDATE bookmarks SET title=?, url=? WHERE id=?");
|
query.prepare("INSERT INTO folders (name) VALUES (?)");
|
||||||
query.bindValue(0, title);
|
query.bindValue(0, name);
|
||||||
query.bindValue(1, url.toString());
|
if (!query.exec())
|
||||||
query.bindValue(2, id);
|
return false;
|
||||||
return query.exec();
|
|
||||||
|
emit folderAdded(name);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool BookmarksModel::removeFolder(const QString &name)
|
||||||
|
{
|
||||||
|
if (name == tr("Bookmarks In Menu") || name == tr("Bookmarks In ToolBar"))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
QSqlQuery query;
|
||||||
|
query.prepare("SELECT id FROM bookmarks WHERE folder = ? ");
|
||||||
|
query.bindValue(0, name);
|
||||||
|
if (!query.exec())
|
||||||
|
return false;
|
||||||
|
while (query.next())
|
||||||
|
removeBookmark(query.value(0).toInt());
|
||||||
|
|
||||||
|
query.prepare("DELETE FROM folders WHERE name=?");
|
||||||
|
query.bindValue(0, name);
|
||||||
|
if (!query.exec())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
query.prepare("DELETE FROM bookmarks WHERE folder=?");
|
||||||
|
query.bindValue(0, name);
|
||||||
|
if (!query.exec())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
emit folderDeleted(name);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool BookmarksModel::bookmarksEqual(const Bookmark &one, const Bookmark &two)
|
||||||
|
{
|
||||||
|
if (one.id != two.id)
|
||||||
|
return false;
|
||||||
|
if (one.title != two.title)
|
||||||
|
return false;
|
||||||
|
if (one.folder != two.folder)
|
||||||
|
return false;
|
||||||
|
if (one.url != two.url)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString BookmarksModel::toTranslatedFolder(const QString &name)
|
||||||
|
{
|
||||||
|
QString trFolder;
|
||||||
|
if (name == "bookmarksMenu")
|
||||||
|
trFolder = tr("Bookmarks In Menu");
|
||||||
|
else if (name == "bookmarksToolbar")
|
||||||
|
trFolder = tr("Bookmarks In ToolBar");
|
||||||
|
else if (name == "unsorted")
|
||||||
|
trFolder = tr("Unsorted Bookmarks");
|
||||||
|
else
|
||||||
|
trFolder = name;
|
||||||
|
return trFolder;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString BookmarksModel::fromTranslatedFolder(const QString &name)
|
||||||
|
{
|
||||||
|
QString folder;
|
||||||
|
if (name == tr("Bookmarks In Menu"))
|
||||||
|
folder = "bookmarksMenu";
|
||||||
|
else if (name == tr("Bookmarks In ToolBar"))
|
||||||
|
folder = "bookmarksToolbar";
|
||||||
|
else if (name == tr("Unsorted Bookmarks"))
|
||||||
|
folder = "unsorted";
|
||||||
|
else
|
||||||
|
folder = name;
|
||||||
|
return folder;
|
||||||
}
|
}
|
||||||
|
@ -18,35 +18,59 @@
|
|||||||
#ifndef BOOKMARKSMODEL_H
|
#ifndef BOOKMARKSMODEL_H
|
||||||
#define BOOKMARKSMODEL_H
|
#define BOOKMARKSMODEL_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QSqlQuery>
|
#include <QSqlQuery>
|
||||||
|
|
||||||
class WebView;
|
class WebView;
|
||||||
class BookmarksModel
|
class BookmarksModel : public QObject
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit BookmarksModel();
|
explicit BookmarksModel(QObject* parent);
|
||||||
|
|
||||||
|
struct Bookmark {
|
||||||
|
int id;
|
||||||
|
QString title;
|
||||||
|
QString folder;
|
||||||
|
QUrl url;
|
||||||
|
};
|
||||||
|
|
||||||
void loadSettings();
|
void loadSettings();
|
||||||
inline bool isShowingMostVisited() { return m_showMostVisited; }
|
inline bool isShowingMostVisited() { return m_showMostVisited; }
|
||||||
void setShowingMostVisited(bool state);
|
void setShowingMostVisited(bool state);
|
||||||
|
|
||||||
bool isBookmarked(QUrl url);
|
bool isBookmarked(const QUrl &url);
|
||||||
int bookmarkId(QUrl url);
|
int bookmarkId(const QUrl &url);
|
||||||
int bookmarkId(QUrl url, QString title, QString folder);
|
int bookmarkId(const QUrl &url, const QString &title, const QString &folder);
|
||||||
QStringList getBookmark(int id);
|
Bookmark getBookmark(int id);
|
||||||
|
|
||||||
bool saveBookmark(QUrl url, QString title, QString folder = "unsorted");
|
bool saveBookmark(const QUrl &url, const QString &title, const QString &folder = "unsorted");
|
||||||
bool saveBookmark(WebView* view, QString folder = "unsorted");
|
bool saveBookmark(WebView* view, const QString &folder = "unsorted");
|
||||||
|
|
||||||
bool removeBookmark(int id);
|
bool removeBookmark(int id);
|
||||||
bool removeBookmark(QUrl url);
|
bool removeBookmark(const QUrl &url);
|
||||||
bool removeBookmark(WebView* view);
|
bool removeBookmark(WebView* view);
|
||||||
|
|
||||||
bool editBookmark(int id, QString title, QString folder);
|
bool editBookmark(int id, const QString &title = "", const QUrl &url = QUrl(), const QString &folder = "");
|
||||||
bool editBookmark(int id, QUrl url, QString title);
|
// bool editBookmark(int id, const QString &title, const QString &folder);
|
||||||
|
// bool editBookmark(int id, const QUrl &url, const QString &title);
|
||||||
|
|
||||||
|
bool createFolder(const QString &name);
|
||||||
|
bool removeFolder(const QString &name);
|
||||||
|
|
||||||
|
static bool bookmarksEqual(const Bookmark &one, const Bookmark &two);
|
||||||
|
static QString toTranslatedFolder(const QString &name);
|
||||||
|
static QString fromTranslatedFolder(const QString &name);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
void bookmarkAdded(const BookmarksModel::Bookmark &bookmark);
|
||||||
|
void bookmarkDeleted(const BookmarksModel::Bookmark &bookmark);
|
||||||
|
void bookmarkEdited(const BookmarksModel::Bookmark &before, const BookmarksModel::Bookmark &after);
|
||||||
|
|
||||||
|
void folderAdded(const QString &title);
|
||||||
|
void folderDeleted(const QString &title);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
|
@ -31,7 +31,14 @@ BookmarksToolbar::BookmarksToolbar(QupZilla* mainClass, QWidget* parent) :
|
|||||||
setMovable(false);
|
setMovable(false);
|
||||||
setContextMenuPolicy(Qt::CustomContextMenu);
|
setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
|
|
||||||
|
m_bookmarksModel = mApp->bookmarksModel();
|
||||||
|
|
||||||
connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(customContextMenuRequested(QPoint)));
|
connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(customContextMenuRequested(QPoint)));
|
||||||
|
|
||||||
|
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(bookmarkEdited(BookmarksModel::Bookmark,BookmarksModel::Bookmark)), this, SLOT(bookmarkEdited(BookmarksModel::Bookmark,BookmarksModel::Bookmark)));
|
||||||
|
|
||||||
QTimer::singleShot(0, this, SLOT(refreshBookmarks()));
|
QTimer::singleShot(0, this, SLOT(refreshBookmarks()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,17 +85,91 @@ void BookmarksToolbar::hidePanel()
|
|||||||
p_QupZilla->showBookmarksToolbar();
|
p_QupZilla->showBookmarksToolbar();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BookmarksToolbar::addBookmark(const BookmarksModel::Bookmark &bookmark)
|
||||||
|
{
|
||||||
|
if (bookmark.folder != "bookmarksToolbar")
|
||||||
|
return;
|
||||||
|
QAction* action = new QAction(this);
|
||||||
|
QString title = bookmark.title;
|
||||||
|
if (title.length()>15) {
|
||||||
|
title.truncate(13);
|
||||||
|
title+="..";
|
||||||
|
}
|
||||||
|
|
||||||
|
action->setText(title);
|
||||||
|
action->setData(bookmark.url);
|
||||||
|
action->setIcon(LocationBar::icon(bookmark.url));
|
||||||
|
QToolButton* button = new QToolButton(this);
|
||||||
|
button->setDefaultAction(action);
|
||||||
|
button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
||||||
|
button->setMaximumHeight(25);
|
||||||
|
button->setToolTip(bookmark.url.toEncoded());
|
||||||
|
button->setWhatsThis(bookmark.title);
|
||||||
|
|
||||||
|
connect(action, SIGNAL(triggered()), p_QupZilla, SLOT(loadActionUrl()));
|
||||||
|
insertWidget(actions().at(actions().count() - 1), button);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BookmarksToolbar::removeBookmark(const BookmarksModel::Bookmark &bookmark)
|
||||||
|
{
|
||||||
|
foreach (QAction* act, actions()) {
|
||||||
|
QToolButton* button = qobject_cast<QToolButton*>(widgetForAction(act));
|
||||||
|
if (!button)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
QAction* action = button->actions().at(0);
|
||||||
|
if (!action)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (action->data().toUrl() == bookmark.url) {
|
||||||
|
delete button;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BookmarksToolbar::bookmarkEdited(const BookmarksModel::Bookmark &before, const BookmarksModel::Bookmark &after)
|
||||||
|
{
|
||||||
|
if (before.folder == "bookmarksToolbar" && after.folder != "bookmarksToolbar") //Editing from toolbar folder to other folder -> Remove bookmark
|
||||||
|
removeBookmark(before);
|
||||||
|
else if (before.folder != "bookmarksToolbar" && after.folder == "bookmarksToolbar") //Editing from other folder to toolbar folder -> Add bookmark
|
||||||
|
addBookmark(after);
|
||||||
|
else { //Editing bookmark already in toolbar
|
||||||
|
foreach (QAction* act, actions()) {
|
||||||
|
QToolButton* button = qobject_cast<QToolButton*>(widgetForAction(act));
|
||||||
|
if (!button)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
QAction* action = button->actions().at(0);
|
||||||
|
if (!action)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (action->data().toUrl() == before.url && button->whatsThis() == before.title) {
|
||||||
|
QString title = after.title;
|
||||||
|
if (title.length()>15) {
|
||||||
|
title.truncate(13);
|
||||||
|
title+="..";
|
||||||
|
}
|
||||||
|
|
||||||
|
action->setText(title);
|
||||||
|
action->setData(after.url);
|
||||||
|
action->setIcon(LocationBar::icon(after.url));
|
||||||
|
button->setToolTip(after.url.toEncoded());
|
||||||
|
button->setWhatsThis(after.title);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void BookmarksToolbar::refreshBookmarks()
|
void BookmarksToolbar::refreshBookmarks()
|
||||||
{
|
{
|
||||||
if (!m_bookmarksModel)
|
|
||||||
m_bookmarksModel =mApp->bookmarks();
|
|
||||||
|
|
||||||
clear();
|
clear();
|
||||||
QSqlQuery query;
|
QSqlQuery query;
|
||||||
query.exec("SELECT title, url FROM bookmarks WHERE folder='bookmarksToolbar'");
|
query.exec("SELECT title, url FROM bookmarks WHERE folder='bookmarksToolbar'");
|
||||||
while(query.next()) {
|
while(query.next()) {
|
||||||
QUrl url = query.value(1).toUrl();
|
QUrl url = query.value(1).toUrl();
|
||||||
QString title = query.value(0).toString();
|
QString title = query.value(0).toString();
|
||||||
|
QString title_ = title;
|
||||||
QAction* action = new QAction(this);
|
QAction* action = new QAction(this);
|
||||||
if (title.length()>15) {
|
if (title.length()>15) {
|
||||||
title.truncate(13);
|
title.truncate(13);
|
||||||
@ -102,6 +183,8 @@ void BookmarksToolbar::refreshBookmarks()
|
|||||||
button->setDefaultAction(action);
|
button->setDefaultAction(action);
|
||||||
button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
||||||
button->setMaximumHeight(25);
|
button->setMaximumHeight(25);
|
||||||
|
button->setToolTip(url.toEncoded());
|
||||||
|
button->setWhatsThis(title_);
|
||||||
connect(action, SIGNAL(triggered()), p_QupZilla, SLOT(loadActionUrl()));
|
connect(action, SIGNAL(triggered()), p_QupZilla, SLOT(loadActionUrl()));
|
||||||
addWidget(button);
|
addWidget(button);
|
||||||
}
|
}
|
||||||
@ -109,18 +192,19 @@ void BookmarksToolbar::refreshBookmarks()
|
|||||||
if (!m_bookmarksModel->isShowingMostVisited())
|
if (!m_bookmarksModel->isShowingMostVisited())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QToolButton* mostVis = new QToolButton(this);
|
m_mostVis = new QToolButton(this);
|
||||||
mostVis->setPopupMode(QToolButton::InstantPopup);
|
m_mostVis->setPopupMode(QToolButton::InstantPopup);
|
||||||
mostVis->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
m_mostVis->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
||||||
mostVis->setMaximumHeight(25);
|
m_mostVis->setMaximumHeight(25);
|
||||||
mostVis->setIcon(style()->standardIcon(QStyle::SP_DirIcon));
|
m_mostVis->setIcon(style()->standardIcon(QStyle::SP_DirIcon));
|
||||||
mostVis->setText(tr("Most visited"));
|
m_mostVis->setText(tr("Most visited"));
|
||||||
mostVis->setToolTip(tr("Sites You visited the most"));
|
m_mostVis->setToolTip(tr("Sites You visited the most"));
|
||||||
|
|
||||||
m_menuMostVisited = new QMenu();
|
m_menuMostVisited = new QMenu();
|
||||||
mostVis->setMenu(m_menuMostVisited);
|
m_mostVis->setMenu(m_menuMostVisited);
|
||||||
connect(m_menuMostVisited, SIGNAL(aboutToShow()), this, SLOT(refreshMostVisited()));
|
connect(m_menuMostVisited, SIGNAL(aboutToShow()), this, SLOT(refreshMostVisited()));
|
||||||
|
|
||||||
addWidget(mostVis);
|
addWidget(m_mostVis);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BookmarksToolbar::refreshMostVisited()
|
void BookmarksToolbar::refreshMostVisited()
|
||||||
|
@ -22,9 +22,10 @@
|
|||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
|
|
||||||
|
#include "bookmarksmodel.h"
|
||||||
|
|
||||||
class QupZilla;
|
class QupZilla;
|
||||||
class BookmarksModel;
|
class BookmarksModel;
|
||||||
|
|
||||||
class BookmarksToolbar : public QToolBar
|
class BookmarksToolbar : public QToolBar
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -37,14 +38,20 @@ signals:
|
|||||||
public slots:
|
public slots:
|
||||||
void refreshBookmarks();
|
void refreshBookmarks();
|
||||||
void refreshMostVisited();
|
void refreshMostVisited();
|
||||||
void customContextMenuRequested(const QPoint &pos);
|
|
||||||
void hidePanel();
|
void hidePanel();
|
||||||
void showMostVisited();
|
void showMostVisited();
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void addBookmark(const BookmarksModel::Bookmark &bookmark);
|
||||||
|
void removeBookmark(const BookmarksModel::Bookmark &bookmark);
|
||||||
|
void bookmarkEdited(const BookmarksModel::Bookmark &before, const BookmarksModel::Bookmark &after);
|
||||||
|
void customContextMenuRequested(const QPoint &pos);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QupZilla* p_QupZilla;
|
QupZilla* p_QupZilla;
|
||||||
BookmarksModel* m_bookmarksModel;
|
BookmarksModel* m_bookmarksModel;
|
||||||
QMenu* m_menuMostVisited;
|
QMenu* m_menuMostVisited;
|
||||||
|
QToolButton* m_mostVis;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -32,14 +32,14 @@ BookmarksWidget::BookmarksWidget(int bookmarkId, QWidget* parent) :
|
|||||||
connect(ui->removeBookmark, SIGNAL(clicked()), this, SLOT(removeBookmark()));
|
connect(ui->removeBookmark, SIGNAL(clicked()), this, SLOT(removeBookmark()));
|
||||||
connect(ui->save, SIGNAL(clicked()), this, SLOT(saveBookmark()));
|
connect(ui->save, SIGNAL(clicked()), this, SLOT(saveBookmark()));
|
||||||
|
|
||||||
m_bookmarksModel = mApp->bookmarks();
|
m_bookmarksModel = mApp->bookmarksModel();
|
||||||
loadBookmark();
|
loadBookmark();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BookmarksWidget::loadBookmark()
|
void BookmarksWidget::loadBookmark()
|
||||||
{
|
{
|
||||||
QStringList bookmark = m_bookmarksModel->getBookmark(m_bookmarkId);
|
BookmarksModel::Bookmark bookmark = m_bookmarksModel->getBookmark(m_bookmarkId);
|
||||||
ui->name->setText( bookmark.at(1) );
|
ui->name->setText( bookmark.title );
|
||||||
|
|
||||||
// Bookmark folders
|
// Bookmark folders
|
||||||
ui->folder->addItem(QIcon(":icons/other/unsortedbookmarks.png"), tr("Unsorted Bookmarks"), "unsorted");
|
ui->folder->addItem(QIcon(":icons/other/unsortedbookmarks.png"), tr("Unsorted Bookmarks"), "unsorted");
|
||||||
@ -50,7 +50,7 @@ void BookmarksWidget::loadBookmark()
|
|||||||
while(query.next())
|
while(query.next())
|
||||||
ui->folder->addItem(style()->standardIcon(QStyle::SP_DirIcon), query.value(0).toString(), query.value(0).toString());
|
ui->folder->addItem(style()->standardIcon(QStyle::SP_DirIcon), query.value(0).toString(), query.value(0).toString());
|
||||||
|
|
||||||
ui->folder->setCurrentIndex( ui->folder->findData(bookmark.at(2)) );
|
ui->folder->setCurrentIndex( ui->folder->findData(bookmark.folder) );
|
||||||
ui->name->setCursorPosition(0);
|
ui->name->setCursorPosition(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ void BookmarksWidget::removeBookmark()
|
|||||||
|
|
||||||
void BookmarksWidget::saveBookmark()
|
void BookmarksWidget::saveBookmark()
|
||||||
{
|
{
|
||||||
m_bookmarksModel->editBookmark(m_bookmarkId, ui->name->text(), ui->folder->itemData(ui->folder->currentIndex()).toString() );
|
m_bookmarksModel->editBookmark(m_bookmarkId, ui->name->text(), QUrl(), ui->folder->itemData(ui->folder->currentIndex()).toString() );
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,11 +22,10 @@
|
|||||||
#include "mainapplication.h"
|
#include "mainapplication.h"
|
||||||
#include "locationcompleter.h"
|
#include "locationcompleter.h"
|
||||||
#include "clickablelabel.h"
|
#include "clickablelabel.h"
|
||||||
#include "bookmarkswidget.h"
|
|
||||||
#include "bookmarksmodel.h"
|
|
||||||
#include "siteinfowidget.h"
|
#include "siteinfowidget.h"
|
||||||
#include "rsswidget.h"
|
#include "rsswidget.h"
|
||||||
#include "webpage.h"
|
#include "webpage.h"
|
||||||
|
#include "bookmarkicon.h"
|
||||||
|
|
||||||
LocationBar::LocationBar(QupZilla* mainClass, QWidget* parent)
|
LocationBar::LocationBar(QupZilla* mainClass, QWidget* parent)
|
||||||
: LineEdit(parent)
|
: LineEdit(parent)
|
||||||
@ -34,7 +33,6 @@ LocationBar::LocationBar(QupZilla* mainClass, QWidget* parent)
|
|||||||
,m_addComWithCtrl(false)
|
,m_addComWithCtrl(false)
|
||||||
,m_addCountryWithAlt(false)
|
,m_addCountryWithAlt(false)
|
||||||
,p_QupZilla(mainClass)
|
,p_QupZilla(mainClass)
|
||||||
,m_bookmarksModel(0)
|
|
||||||
{
|
{
|
||||||
m_siteIcon = new QToolButton(this);
|
m_siteIcon = new QToolButton(this);
|
||||||
m_siteIcon->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
m_siteIcon->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
||||||
@ -59,19 +57,14 @@ LocationBar::LocationBar(QupZilla* mainClass, QWidget* parent)
|
|||||||
m_goButton->setHidden(true);
|
m_goButton->setHidden(true);
|
||||||
m_goButton->setStyleSheet("margin-bottom:2px;");
|
m_goButton->setStyleSheet("margin-bottom:2px;");
|
||||||
|
|
||||||
m_bookmarkButton = new ClickableLabel(this);
|
m_bookmarkIcon = new BookmarkIcon(p_QupZilla);
|
||||||
m_bookmarkButton->setPixmap(QPixmap(":/icons/locationbar/starg.png"));
|
|
||||||
m_bookmarkButton->setCursor(Qt::PointingHandCursor);
|
|
||||||
m_bookmarkButton->setStyleSheet("margin-bottom: 2px;");
|
|
||||||
m_bookmarkButton->setToolTip(tr("Bookmark this Page"));
|
|
||||||
m_bookmarkButton->setFocusPolicy(Qt::ClickFocus);
|
|
||||||
|
|
||||||
ClickableLabel* down = new ClickableLabel(this);
|
ClickableLabel* down = new ClickableLabel(this);
|
||||||
down->setPixmap(QPixmap(":icons/locationbar/arrow-down.gif"));
|
down->setPixmap(QPixmap(":icons/locationbar/arrow-down.gif"));
|
||||||
down->setCursor(Qt::ArrowCursor);
|
down->setCursor(Qt::ArrowCursor);
|
||||||
|
|
||||||
addWidget(down, LineEdit::RightSide);
|
addWidget(down, LineEdit::RightSide);
|
||||||
addWidget(m_bookmarkButton, LineEdit::RightSide);
|
addWidget(m_bookmarkIcon, LineEdit::RightSide);
|
||||||
addWidget(m_goButton, LineEdit::RightSide);
|
addWidget(m_goButton, LineEdit::RightSide);
|
||||||
addWidget(m_rssIcon, LineEdit::RightSide);
|
addWidget(m_rssIcon, LineEdit::RightSide);
|
||||||
|
|
||||||
@ -92,7 +85,6 @@ LocationBar::LocationBar(QupZilla* mainClass, QWidget* parent)
|
|||||||
connect(m_siteIcon, SIGNAL(clicked()), this, SLOT(showSiteInfo()));
|
connect(m_siteIcon, SIGNAL(clicked()), this, SLOT(showSiteInfo()));
|
||||||
// connect(down, SIGNAL(clicked(QPoint)), com, SLOT(show()));
|
// connect(down, SIGNAL(clicked(QPoint)), com, SLOT(show()));
|
||||||
connect(m_goButton, SIGNAL(clicked(QPoint)), p_QupZilla, SLOT(urlEnter()));
|
connect(m_goButton, SIGNAL(clicked(QPoint)), p_QupZilla, SLOT(urlEnter()));
|
||||||
connect(m_bookmarkButton, SIGNAL(clicked(QPoint)), this, SLOT(bookmarkIconClicked()));
|
|
||||||
connect(m_rssIcon, SIGNAL(clicked(QPoint)), this, SLOT(rssIconClicked()));
|
connect(m_rssIcon, SIGNAL(clicked(QPoint)), this, SLOT(rssIconClicked()));
|
||||||
|
|
||||||
setStyleSheet("QLineEdit { background: transparent; border-image: url(:/icons/locationbar/lineedit.png); border-width:4; color:black;}");
|
setStyleSheet("QLineEdit { background: transparent; border-image: url(:/icons/locationbar/lineedit.png); border-width:4; color:black;}");
|
||||||
@ -122,7 +114,7 @@ void LocationBar::showGoButton()
|
|||||||
|
|
||||||
m_rssIconVisible = m_rssIcon->isVisible();
|
m_rssIconVisible = m_rssIcon->isVisible();
|
||||||
|
|
||||||
m_bookmarkButton->hide();
|
m_bookmarkIcon->hide();
|
||||||
m_rssIcon->hide();
|
m_rssIcon->hide();
|
||||||
m_goButton->show();
|
m_goButton->show();
|
||||||
}
|
}
|
||||||
@ -133,7 +125,7 @@ void LocationBar::hideGoButton()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
m_rssIcon->setVisible(m_rssIconVisible);
|
m_rssIcon->setVisible(m_rssIconVisible);
|
||||||
m_bookmarkButton->show();
|
m_bookmarkIcon->show();
|
||||||
m_goButton->hide();
|
m_goButton->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,20 +143,6 @@ void LocationBar::showSiteInfo()
|
|||||||
info->showAt(this);
|
info->showAt(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocationBar::bookmarkIconClicked()
|
|
||||||
{
|
|
||||||
QUrl url = p_QupZilla->weView()->url();
|
|
||||||
|
|
||||||
if (m_bookmarksModel->isBookmarked(url)) {
|
|
||||||
BookmarksWidget* menu = new BookmarksWidget(m_bookmarksModel->bookmarkId(url), this);
|
|
||||||
menu->showAt(this);
|
|
||||||
connect(menu, SIGNAL(bookmarkDeleted()), this, SLOT(checkBookmark()));
|
|
||||||
} else if (m_bookmarksModel->saveBookmark(p_QupZilla->weView())) {
|
|
||||||
m_bookmarkButton->setPixmap(QPixmap(":/icons/locationbar/star.png"));
|
|
||||||
m_bookmarkButton->setToolTip(tr("Edit this bookmark"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void LocationBar::rssIconClicked()
|
void LocationBar::rssIconClicked()
|
||||||
{
|
{
|
||||||
QList<QPair<QString,QString> > _rss = p_QupZilla->weView()->getRss();
|
QList<QPair<QString,QString> > _rss = p_QupZilla->weView()->getRss();
|
||||||
@ -173,20 +151,6 @@ void LocationBar::rssIconClicked()
|
|||||||
rss->showAt(this);
|
rss->showAt(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocationBar::checkBookmark()
|
|
||||||
{
|
|
||||||
if (!m_bookmarksModel)
|
|
||||||
m_bookmarksModel = mApp->bookmarks();
|
|
||||||
|
|
||||||
if (m_bookmarksModel->isBookmarked(QUrl(text()))) {
|
|
||||||
m_bookmarkButton->setPixmap(QPixmap(":/icons/locationbar/star.png"));
|
|
||||||
m_bookmarkButton->setToolTip(tr("Edit this bookmark"));
|
|
||||||
} else {
|
|
||||||
m_bookmarkButton->setPixmap(QPixmap(":/icons/locationbar/starg.png"));
|
|
||||||
m_bookmarkButton->setToolTip(tr("Bookmark this Page"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
QIcon LocationBar::icon(const QUrl &url)
|
QIcon LocationBar::icon(const QUrl &url)
|
||||||
{
|
{
|
||||||
QUrl url2 = url.scheme() + "://" + url.host();
|
QUrl url2 = url.scheme() + "://" + url.host();
|
||||||
@ -239,8 +203,10 @@ void LocationBar::showUrl(const QUrl &url, bool empty)
|
|||||||
p_QupZilla->statusBar()->showMessage(tr("Done"));
|
p_QupZilla->statusBar()->showMessage(tr("Done"));
|
||||||
p_QupZilla->ipLabel()->show();
|
p_QupZilla->ipLabel()->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
hideGoButton();
|
hideGoButton();
|
||||||
checkBookmark();
|
|
||||||
|
m_bookmarkIcon->checkBookmark(url);
|
||||||
m_rssIcon->setVisible(view->hasRss());
|
m_rssIcon->setVisible(view->hasRss());
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -329,7 +295,7 @@ void LocationBar::keyPressEvent(QKeyEvent *event)
|
|||||||
|
|
||||||
LocationBar::~LocationBar()
|
LocationBar::~LocationBar()
|
||||||
{
|
{
|
||||||
delete m_bookmarkButton;
|
delete m_bookmarkIcon;
|
||||||
delete m_goButton;
|
delete m_goButton;
|
||||||
delete m_siteIcon;
|
delete m_siteIcon;
|
||||||
delete m_rssIcon;
|
delete m_rssIcon;
|
||||||
|
@ -36,8 +36,7 @@ class QupZilla;
|
|||||||
class LineEdit;
|
class LineEdit;
|
||||||
class LocationCompleter;
|
class LocationCompleter;
|
||||||
class ClickableLabel;
|
class ClickableLabel;
|
||||||
class BookmarksModel;
|
class BookmarkIcon;
|
||||||
|
|
||||||
class LocationBar : public LineEdit
|
class LocationBar : public LineEdit
|
||||||
{
|
{
|
||||||
Q_OBJECT;
|
Q_OBJECT;
|
||||||
@ -50,14 +49,12 @@ public:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void showUrl(const QUrl &url, bool empty = true);
|
void showUrl(const QUrl &url, bool empty = true);
|
||||||
void checkBookmark();
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void siteIconChanged();
|
void siteIconChanged();
|
||||||
void setPrivacy(bool state);
|
void setPrivacy(bool state);
|
||||||
void textEdit();
|
void textEdit();
|
||||||
void showPopup();
|
void showPopup();
|
||||||
void bookmarkIconClicked();
|
|
||||||
void showSiteInfo();
|
void showSiteInfo();
|
||||||
void rssIconClicked();
|
void rssIconClicked();
|
||||||
|
|
||||||
@ -70,7 +67,7 @@ private:
|
|||||||
void showGoButton();
|
void showGoButton();
|
||||||
void hideGoButton();
|
void hideGoButton();
|
||||||
|
|
||||||
ClickableLabel* m_bookmarkButton;
|
BookmarkIcon* m_bookmarkIcon;
|
||||||
ClickableLabel* m_goButton;
|
ClickableLabel* m_goButton;
|
||||||
ClickableLabel* m_rssIcon;
|
ClickableLabel* m_rssIcon;
|
||||||
QToolButton* m_siteIcon;
|
QToolButton* m_siteIcon;
|
||||||
@ -80,7 +77,6 @@ private:
|
|||||||
bool m_addCountryWithAlt;
|
bool m_addCountryWithAlt;
|
||||||
QupZilla* p_QupZilla;
|
QupZilla* p_QupZilla;
|
||||||
LocationCompleter* m_locationCompleter;
|
LocationCompleter* m_locationCompleter;
|
||||||
BookmarksModel* m_bookmarksModel;
|
|
||||||
|
|
||||||
bool m_rssIconVisible;
|
bool m_rssIconVisible;
|
||||||
};
|
};
|
||||||
|
251
src/sidebar/bookmarkssidebar.cpp
Normal file
251
src/sidebar/bookmarkssidebar.cpp
Normal file
@ -0,0 +1,251 @@
|
|||||||
|
/* ============================================================
|
||||||
|
* 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/>.
|
||||||
|
* ============================================================ */
|
||||||
|
#include "bookmarkssidebar.h"
|
||||||
|
#include "mainapplication.h"
|
||||||
|
#include "ui_bookmarkssidebar.h"
|
||||||
|
#include "qupzilla.h"
|
||||||
|
#include "locationbar.h"
|
||||||
|
#include "webview.h"
|
||||||
|
#include "bookmarkstoolbar.h"
|
||||||
|
#include "tabwidget.h"
|
||||||
|
#include "bookmarksmodel.h"
|
||||||
|
|
||||||
|
BookmarksSideBar::BookmarksSideBar(QupZilla* mainClass, QWidget* parent) :
|
||||||
|
QWidget(parent)
|
||||||
|
,m_isRefreshing(false)
|
||||||
|
,ui(new Ui::BookmarksSideBar)
|
||||||
|
,p_QupZilla(mainClass)
|
||||||
|
,m_bookmarksModel(mApp->bookmarksModel())
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
connect(ui->bookmarksTree, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(contextMenuRequested(const QPoint &)));
|
||||||
|
connect(ui->bookmarksTree, SIGNAL(itemControlClicked(QTreeWidgetItem*)), this, SLOT(itemControlClicked(QTreeWidgetItem*)));
|
||||||
|
connect(ui->bookmarksTree, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), this, SLOT(itemDoubleClicked(QTreeWidgetItem*)));
|
||||||
|
connect(ui->search, SIGNAL(textChanged(QString)), ui->bookmarksTree, SLOT(filterStringWithoutTopItems(QString)));
|
||||||
|
|
||||||
|
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)));
|
||||||
|
|
||||||
|
QTimer::singleShot(0, this, SLOT(refreshTable()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void BookmarksSideBar::itemControlClicked(QTreeWidgetItem* item)
|
||||||
|
{
|
||||||
|
if (!item || item->text(1).isEmpty())
|
||||||
|
return;
|
||||||
|
p_QupZilla->tabWidget()->addView(QUrl(item->text(1)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void BookmarksSideBar::itemDoubleClicked(QTreeWidgetItem *item)
|
||||||
|
{
|
||||||
|
if (!item || item->text(1).isEmpty())
|
||||||
|
return;
|
||||||
|
p_QupZilla->loadAddress(QUrl(item->text(1)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void BookmarksSideBar::loadInNewTab()
|
||||||
|
{
|
||||||
|
if (QAction* action = qobject_cast<QAction*>(sender()))
|
||||||
|
p_QupZilla->tabWidget()->addView(action->data().toUrl(), tr("New Tab"), TabWidget::NewNotSelectedTab);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BookmarksSideBar::deleteItem()
|
||||||
|
{
|
||||||
|
QTreeWidgetItem* item = ui->bookmarksTree->currentItem();
|
||||||
|
if (!item)
|
||||||
|
return;
|
||||||
|
|
||||||
|
int id = item->whatsThis(0).toInt();
|
||||||
|
m_bookmarksModel->removeBookmark(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BookmarksSideBar::moveBookmark()
|
||||||
|
{
|
||||||
|
QTreeWidgetItem* item = ui->bookmarksTree->currentItem();
|
||||||
|
if (!item)
|
||||||
|
return;
|
||||||
|
if (QAction* action = qobject_cast<QAction*>(sender())) {
|
||||||
|
m_bookmarksModel->editBookmark(item->whatsThis(0).toInt(), item->text(0), QUrl(), action->data().toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BookmarksSideBar::contextMenuRequested(const QPoint &position)
|
||||||
|
{
|
||||||
|
if (!ui->bookmarksTree->itemAt(position))
|
||||||
|
return;
|
||||||
|
QString link = ui->bookmarksTree->itemAt(position)->text(1);
|
||||||
|
if (link.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
QMenu menu;
|
||||||
|
menu.addAction(tr("Open link in actual &tab"), p_QupZilla, SLOT(loadActionUrl()))->setData(link);
|
||||||
|
menu.addAction(tr("Open link in &new tab"), this, SLOT(loadInNewTab()))->setData(link);
|
||||||
|
menu.addSeparator();
|
||||||
|
|
||||||
|
QMenu moveMenu;
|
||||||
|
moveMenu.setTitle(tr("Move bookmark to &folder"));
|
||||||
|
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);
|
||||||
|
menu.addAction(tr("&Delete"), this, SLOT(deleteItem()));
|
||||||
|
//Prevent choosing first option with double rightclick
|
||||||
|
QPoint pos = QCursor::pos();
|
||||||
|
QPoint p(pos.x(), pos.y()+1);
|
||||||
|
menu.exec(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BookmarksSideBar::addBookmark(const BookmarksModel::Bookmark &bookmark)
|
||||||
|
{
|
||||||
|
QString translatedFolder = BookmarksModel::toTranslatedFolder(bookmark.folder);
|
||||||
|
QTreeWidgetItem* item = new QTreeWidgetItem();
|
||||||
|
item->setText(0, bookmark.title);
|
||||||
|
item->setText(1, bookmark.url.toEncoded());
|
||||||
|
item->setWhatsThis(0, QString::number(bookmark.id));
|
||||||
|
item->setIcon(0, LocationBar::icon(bookmark.url));
|
||||||
|
item->setToolTip(0, bookmark.url.toEncoded());
|
||||||
|
|
||||||
|
if (bookmark.folder != "unsorted")
|
||||||
|
ui->bookmarksTree->addToParentItem(translatedFolder, item);
|
||||||
|
else
|
||||||
|
ui->bookmarksTree->addTopLevelItem(item);
|
||||||
|
|
||||||
|
// if (!ui->search->text().isEmpty())
|
||||||
|
item->setHidden(!bookmark.title.contains(ui->search->text(), Qt::CaseInsensitive));
|
||||||
|
}
|
||||||
|
|
||||||
|
void BookmarksSideBar::removeBookmark(const BookmarksModel::Bookmark &bookmark)
|
||||||
|
{
|
||||||
|
if (bookmark.folder == "unsorted") {
|
||||||
|
QTreeWidgetItem* item = ui->bookmarksTree->findItems(bookmark.title, Qt::MatchExactly).at(0);
|
||||||
|
if (item && item->whatsThis(0) == QString::number(bookmark.id))
|
||||||
|
delete item;
|
||||||
|
} else {
|
||||||
|
QTreeWidgetItem* parentItem = ui->bookmarksTree->findItems(BookmarksModel::toTranslatedFolder(bookmark.folder), Qt::MatchExactly).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(0) == QString::number(bookmark.id)) {
|
||||||
|
delete item;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BookmarksSideBar::bookmarkEdited(const BookmarksModel::Bookmark &before, const BookmarksModel::Bookmark &after)
|
||||||
|
{
|
||||||
|
removeBookmark(before);
|
||||||
|
addBookmark(after);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BookmarksSideBar::addFolder(const QString &name)
|
||||||
|
{
|
||||||
|
QTreeWidgetItem* item = new QTreeWidgetItem(ui->bookmarksTree);
|
||||||
|
item->setText(0, name);
|
||||||
|
item->setIcon(0, style()->standardIcon(QStyle::SP_DirIcon));
|
||||||
|
}
|
||||||
|
|
||||||
|
void BookmarksSideBar::removeFolder(const QString &name)
|
||||||
|
{
|
||||||
|
QTreeWidgetItem* item = ui->bookmarksTree->findItems(name, Qt::MatchExactly).at(0);
|
||||||
|
if (item)
|
||||||
|
delete item;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BookmarksSideBar::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);
|
||||||
|
}
|
||||||
|
|
||||||
|
query.exec("SELECT title, url, id, folder FROM bookmarks");
|
||||||
|
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();
|
||||||
|
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, url.toEncoded());
|
||||||
|
// item->setToolTip(1, url.toEncoded());
|
||||||
|
|
||||||
|
item->setWhatsThis(0, QString::number(id));
|
||||||
|
item->setIcon(0, LocationBar::icon(url));
|
||||||
|
ui->bookmarksTree->addTopLevelItem(item);
|
||||||
|
}
|
||||||
|
ui->bookmarksTree->expandAll();
|
||||||
|
|
||||||
|
ui->bookmarksTree->setUpdatesEnabled(true);
|
||||||
|
m_isRefreshing = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
BookmarksSideBar::~BookmarksSideBar()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
}
|
@ -16,8 +16,32 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* ============================================================ */
|
* ============================================================ */
|
||||||
#include "sidebar.h"
|
#include "sidebar.h"
|
||||||
|
#include "docktitlebarwidget.h"
|
||||||
|
#include "bookmarkssidebar.h"
|
||||||
|
#include "qupzilla.h"
|
||||||
|
|
||||||
SideBar::SideBar(QWidget* parent) :
|
SideBar::SideBar(QWidget* parent) :
|
||||||
QDockWidget(parent)
|
QDockWidget(parent)
|
||||||
{
|
{
|
||||||
|
setObjectName("SideBar");
|
||||||
|
setAttribute(Qt::WA_DeleteOnClose);
|
||||||
|
m_titleBar = new DockTitleBarWidget("", this);
|
||||||
|
setTitleBarWidget(m_titleBar);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SideBar::showBookmarks()
|
||||||
|
{
|
||||||
|
m_titleBar->setTitle(tr("Bookmarks"));
|
||||||
|
BookmarksSideBar* bar = new BookmarksSideBar((QupZilla*)parentWidget(), this);
|
||||||
|
setWidget(bar);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SideBar::showHistory()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void SideBar::showRSS()
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -20,16 +20,22 @@
|
|||||||
|
|
||||||
#include <QDockWidget>
|
#include <QDockWidget>
|
||||||
|
|
||||||
|
class DockTitleBarWidget;
|
||||||
class SideBar : public QDockWidget
|
class SideBar : public QDockWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit SideBar(QWidget* parent = 0);
|
explicit SideBar(QWidget* parent = 0);
|
||||||
|
void showBookmarks();
|
||||||
|
void showHistory();
|
||||||
|
void showRSS();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
|
private:
|
||||||
|
DockTitleBarWidget* m_titleBar;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SIDEBAR_H
|
#endif // SIDEBAR_H
|
||||||
|
@ -65,7 +65,7 @@ void TreeWidget::filterStringWithoutTopItems(QString string)
|
|||||||
item->setHidden(false);
|
item->setHidden(false);
|
||||||
} else {
|
} else {
|
||||||
foreach (QTreeWidgetItem* item, _allItems)
|
foreach (QTreeWidgetItem* item, _allItems)
|
||||||
item->setHidden(!item->text(0).contains(string));
|
item->setHidden(!item->text(0).contains(string, Qt::CaseInsensitive));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,6 +78,16 @@ void TreeWidget::filterStringWithTopItems(QString string)
|
|||||||
item->setHidden(false);
|
item->setHidden(false);
|
||||||
} else {
|
} else {
|
||||||
foreach (QTreeWidgetItem* item, _allItems)
|
foreach (QTreeWidgetItem* item, _allItems)
|
||||||
item->setHidden(!item->text(0).contains(string));
|
item->setHidden(!item->text(0).contains(string, Qt::CaseInsensitive));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TreeWidget::addToParentItem(const QString &text, QTreeWidgetItem* item)
|
||||||
|
{
|
||||||
|
QTreeWidgetItem* parentItem = findItems(text, Qt::MatchExactly).at(0);
|
||||||
|
if (!parentItem)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
parentItem->addChild(item);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
@ -28,6 +28,7 @@ class TreeWidget : public QTreeWidget
|
|||||||
public:
|
public:
|
||||||
explicit TreeWidget(QWidget* parent = 0);
|
explicit TreeWidget(QWidget* parent = 0);
|
||||||
QList<QTreeWidgetItem*> allItems(bool includeTopLevelItems = true);
|
QList<QTreeWidgetItem*> allItems(bool includeTopLevelItems = true);
|
||||||
|
bool addToParentItem(const QString &text, QTreeWidgetItem* item);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void itemControlClicked(QTreeWidgetItem* item);
|
void itemControlClicked(QTreeWidgetItem* item);
|
||||||
|
@ -290,54 +290,57 @@
|
|||||||
</widget>
|
</widget>
|
||||||
<widget class="QWidget" name="page_3">
|
<widget class="QWidget" name="page_3">
|
||||||
<layout class="QGridLayout" name="gridLayout_3">
|
<layout class="QGridLayout" name="gridLayout_3">
|
||||||
<property name="topMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="bottomMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QTreeWidget" name="treeImages">
|
<widget class="QSplitter" name="splitter">
|
||||||
<property name="minimumSize">
|
<property name="orientation">
|
||||||
<size>
|
<enum>Qt::Vertical</enum>
|
||||||
<width>0</width>
|
|
||||||
<height>110</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
</property>
|
||||||
<property name="maximumSize">
|
<widget class="QTreeWidget" name="treeImages">
|
||||||
<size>
|
<property name="minimumSize">
|
||||||
<width>16777215</width>
|
<size>
|
||||||
<height>110</height>
|
<width>0</width>
|
||||||
</size>
|
<height>0</height>
|
||||||
</property>
|
</size>
|
||||||
<property name="itemsExpandable">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<attribute name="headerMinimumSectionSize">
|
|
||||||
<number>200</number>
|
|
||||||
</attribute>
|
|
||||||
<column>
|
|
||||||
<property name="text">
|
|
||||||
<string>Image</string>
|
|
||||||
</property>
|
</property>
|
||||||
</column>
|
<property name="itemsExpandable">
|
||||||
<column>
|
<bool>false</bool>
|
||||||
<property name="text">
|
|
||||||
<string>Image address</string>
|
|
||||||
</property>
|
</property>
|
||||||
</column>
|
<attribute name="headerMinimumSectionSize">
|
||||||
|
<number>200</number>
|
||||||
|
</attribute>
|
||||||
|
<column>
|
||||||
|
<property name="text">
|
||||||
|
<string>Image</string>
|
||||||
|
</property>
|
||||||
|
</column>
|
||||||
|
<column>
|
||||||
|
<property name="text">
|
||||||
|
<string>Image address</string>
|
||||||
|
</property>
|
||||||
|
</column>
|
||||||
|
</widget>
|
||||||
|
<widget class="QWidget" name="">
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_5">
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>16777215</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string><b>Preview</b></string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QGraphicsView" name="mediaPreview"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0">
|
|
||||||
<widget class="QLabel" name="label_5">
|
|
||||||
<property name="text">
|
|
||||||
<string><b>Preview</b></string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="0">
|
|
||||||
<widget class="QGraphicsView" name="mediaPreview"/>
|
|
||||||
</item>
|
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QWidget" name="page_2">
|
<widget class="QWidget" name="page_2">
|
||||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user