summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrea Diamantini <adjam7@gmail.com>2008-11-13 03:13:34 +0100
committerAndrea Diamantini <adjam7@gmail.com>2008-11-13 03:13:34 +0100
commit76319190fa422c0a12417410ad12241172bf3c0a (patch)
tree3d43c0d5a1d883dcd4c8d8791df6f44cdf1e5697 /src
parentRe-enabled history! (diff)
downloadrekonq-76319190fa422c0a12417410ad12241172bf3c0a.tar.xz
1st new implementation of KDE bookmarks system.
The idea is to share konqueror bookmarks until we don't have an akonadi storage of them..
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt5
-rw-r--r--src/addbookmarkdialog.ui98
-rw-r--r--src/bookmarks.cpp968
-rw-r--r--src/bookmarks.h289
-rw-r--r--src/bookmarks.ui106
-rw-r--r--src/browserapplication.cpp13
-rw-r--r--src/browserapplication.h3
-rw-r--r--src/browsermainwindow.cpp68
-rw-r--r--src/browsermainwindow.h7
-rw-r--r--src/xbel.cpp304
-rw-r--r--src/xbel.h92
11 files changed, 31 insertions, 1922 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index d4317b2d..50b13782 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,6 +1,5 @@
SET( rekonq_SRCS
autosaver.cpp
- bookmarks.cpp
browserapplication.cpp
browsermainwindow.cpp
cookiejar.cpp
@@ -19,13 +18,10 @@ SET( rekonq_SRCS
toolbarsearch.cpp
urllineedit.cpp
webview.cpp
- xbel.cpp
main.cpp
)
KDE4_ADD_UI_FILES( rekonq_SRCS
- addbookmarkdialog.ui
- bookmarks.ui
cookies.ui
cookiesexceptions.ui
downloaditem.ui
@@ -47,6 +43,7 @@ TARGET_LINK_LIBRARIES( rekonq
${QT_QTNETWORK_LIBRARY}
${QT_QTWEBKIT_LIBRARY}
${KDE4_KDEUI_LIBS}
+ ${KDE4_KIO_LIBS}
${QT_QTUITOOLS_LIBRARY}
)
diff --git a/src/addbookmarkdialog.ui b/src/addbookmarkdialog.ui
deleted file mode 100644
index 3460d7bb..00000000
--- a/src/addbookmarkdialog.ui
+++ /dev/null
@@ -1,98 +0,0 @@
-<ui version="4.0" >
- <class>AddBookmarkDialog</class>
- <widget class="QDialog" name="AddBookmarkDialog" >
- <property name="geometry" >
- <rect>
- <x>0</x>
- <y>0</y>
- <width>240</width>
- <height>168</height>
- </rect>
- </property>
- <property name="windowTitle" >
- <string>Add Bookmark</string>
- </property>
- <layout class="QVBoxLayout" name="verticalLayout" >
- <item>
- <widget class="QLabel" name="label" >
- <property name="text" >
- <string>Type a name for the bookmark, and choose where to keep it.</string>
- </property>
- <property name="textFormat" >
- <enum>Qt::PlainText</enum>
- </property>
- <property name="wordWrap" >
- <bool>true</bool>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QLineEdit" name="name" />
- </item>
- <item>
- <widget class="QComboBox" name="location" />
- </item>
- <item>
- <spacer name="verticalSpacer" >
- <property name="orientation" >
- <enum>Qt::Vertical</enum>
- </property>
- <property name="sizeHint" stdset="0" >
- <size>
- <width>20</width>
- <height>2</height>
- </size>
- </property>
- </spacer>
- </item>
- <item>
- <widget class="QDialogButtonBox" name="buttonBox" >
- <property name="orientation" >
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="standardButtons" >
- <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
- </property>
- <property name="centerButtons" >
- <bool>false</bool>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- <resources/>
- <connections>
- <connection>
- <sender>buttonBox</sender>
- <signal>accepted()</signal>
- <receiver>AddBookmarkDialog</receiver>
- <slot>accept()</slot>
- <hints>
- <hint type="sourcelabel" >
- <x>248</x>
- <y>254</y>
- </hint>
- <hint type="destinationlabel" >
- <x>157</x>
- <y>274</y>
- </hint>
- </hints>
- </connection>
- <connection>
- <sender>buttonBox</sender>
- <signal>rejected()</signal>
- <receiver>AddBookmarkDialog</receiver>
- <slot>reject()</slot>
- <hints>
- <hint type="sourcelabel" >
- <x>316</x>
- <y>260</y>
- </hint>
- <hint type="destinationlabel" >
- <x>286</x>
- <y>274</y>
- </hint>
- </hints>
- </connection>
- </connections>
-</ui>
diff --git a/src/bookmarks.cpp b/src/bookmarks.cpp
deleted file mode 100644
index 6f87d3a4..00000000
--- a/src/bookmarks.cpp
+++ /dev/null
@@ -1,968 +0,0 @@
-/* ============================================================
- *
- * This file is a part of the reKonq project
- *
- * Copyright (C) 2007-2008 Trolltech ASA. All rights reserved
- * Copyright (C) 2008 by Andrea Diamantini <adjam7 at gmail dot com>
- *
- *
- * 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 2, 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.
- *
- * ============================================================ */
-
-
-// Local Includes
-#include "bookmarks.h"
-#include "autosaver.h"
-#include "browserapplication.h"
-#include "history.h"
-#include "xbel.h"
-
-// Qt Includes
-#include <QBuffer>
-#include <QFile>
-#include <QMimeData>
-#include <QDesktopServices>
-#include <QDragEnterEvent>
-#include <QFileDialog>
-#include <QHeaderView>
-#include <QIcon>
-#include <QMessageBox>
-#include <QToolButton>
-#include <QWebSettings>
-#include <QDebug>
-
-
-#define BOOKMARKBAR "Bookmarks Bar"
-#define BOOKMARKMENU "Bookmarks Menu"
-
-BookmarksManager::BookmarksManager(QObject *parent)
- : QObject(parent)
- , m_loaded(false)
- , m_saveTimer(new AutoSaver(this))
- , m_bookmarkRootNode(0)
- , m_bookmarkModel(0)
-{
- connect(this, SIGNAL(entryAdded(BookmarkNode *)),
- m_saveTimer, SLOT(changeOccurred()));
- connect(this, SIGNAL(entryRemoved(BookmarkNode *, int, BookmarkNode *)),
- m_saveTimer, SLOT(changeOccurred()));
- connect(this, SIGNAL(entryChanged(BookmarkNode *)),
- m_saveTimer, SLOT(changeOccurred()));
-}
-
-BookmarksManager::~BookmarksManager()
-{
- m_saveTimer->saveIfNeccessary();
-}
-
-void BookmarksManager::changeExpanded()
-{
- m_saveTimer->changeOccurred();
-}
-
-void BookmarksManager::load()
-{
- if (m_loaded)
- return;
- m_loaded = true;
-
- QString dir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
- QString bookmarkFile = dir + QLatin1String("/bookmarks.xbel");
- if (!QFile::exists(bookmarkFile))
- bookmarkFile = QLatin1String(":defaultbookmarks.xbel");
-
- XbelReader reader;
- m_bookmarkRootNode = reader.read(bookmarkFile);
- if (reader.error() != QXmlStreamReader::NoError) {
- QMessageBox::warning(0, QLatin1String("Loading Bookmark"),
- i18n("Error when loading bookmarks on line ") +
- QString( (int) reader.lineNumber() ) +
- i18n(", column ") +
- QString( (int) reader.columnNumber() ) +
- ":\n" +
- reader.errorString()
- ) ;
- }
-
- BookmarkNode *toolbar = 0;
- BookmarkNode *menu = 0;
- QList<BookmarkNode*> others;
- for (int i = m_bookmarkRootNode->children().count() - 1; i >= 0; --i) {
- BookmarkNode *node = m_bookmarkRootNode->children().at(i);
- if (node->type() == BookmarkNode::Folder) {
- // Automatically convert
- if (node->title == i18n("Toolbar Bookmarks") && !toolbar) {
- node->title = i18n(BOOKMARKBAR);
- }
- if (node->title == i18n(BOOKMARKBAR) && !toolbar) {
- toolbar = node;
- }
-
- // Automatically convert
- if (node->title == i18n("Menu") && !menu) {
- node->title = i18n(BOOKMARKMENU);
- }
- if (node->title == i18n(BOOKMARKMENU) && !menu) {
- menu = node;
- }
- } else {
- others.append(node);
- }
- m_bookmarkRootNode->remove(node);
- }
- Q_ASSERT(m_bookmarkRootNode->children().count() == 0);
- if (!toolbar) {
- toolbar = new BookmarkNode(BookmarkNode::Folder, m_bookmarkRootNode);
- toolbar->title = i18n(BOOKMARKBAR);
- } else {
- m_bookmarkRootNode->add(toolbar);
- }
-
- if (!menu) {
- menu = new BookmarkNode(BookmarkNode::Folder, m_bookmarkRootNode);
- menu->title = i18n(BOOKMARKMENU);
- } else {
- m_bookmarkRootNode->add(menu);
- }
-
- for (int i = 0; i < others.count(); ++i)
- menu->add(others.at(i));
-}
-
-void BookmarksManager::save() const
-{
- if (!m_loaded)
- return;
-
- XbelWriter writer;
- QString dir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
- QString bookmarkFile = dir + QLatin1String("/bookmarks.xbel");
- if (!writer.write(bookmarkFile, m_bookmarkRootNode))
- qWarning() << "BookmarkManager: error saving to" << bookmarkFile;
-}
-
-void BookmarksManager::addBookmark(BookmarkNode *parent, BookmarkNode *node, int row)
-{
- if (!m_loaded)
- return;
- Q_ASSERT(parent);
- InsertBookmarksCommand *command = new InsertBookmarksCommand(this, parent, node, row);
- m_commands.push(command);
-}
-
-void BookmarksManager::removeBookmark(BookmarkNode *node)
-{
- if (!m_loaded)
- return;
-
- Q_ASSERT(node);
- BookmarkNode *parent = node->parent();
- int row = parent->children().indexOf(node);
- RemoveBookmarksCommand *command = new RemoveBookmarksCommand(this, parent, row);
- m_commands.push(command);
-}
-
-void BookmarksManager::setTitle(BookmarkNode *node, const QString &newTitle)
-{
- if (!m_loaded)
- return;
-
- Q_ASSERT(node);
- ChangeBookmarkCommand *command = new ChangeBookmarkCommand(this, node, newTitle, true);
- m_commands.push(command);
-}
-
-void BookmarksManager::setUrl(BookmarkNode *node, const QString &newUrl)
-{
- if (!m_loaded)
- return;
-
- Q_ASSERT(node);
- ChangeBookmarkCommand *command = new ChangeBookmarkCommand(this, node, newUrl, false);
- m_commands.push(command);
-}
-
-BookmarkNode *BookmarksManager::bookmarks()
-{
- if (!m_loaded)
- load();
- return m_bookmarkRootNode;
-}
-
-BookmarkNode *BookmarksManager::menu()
-{
- if (!m_loaded)
- load();
-
- for (int i = m_bookmarkRootNode->children().count() - 1; i >= 0; --i) {
- BookmarkNode *node = m_bookmarkRootNode->children().at(i);
- if (node->title == i18n(BOOKMARKMENU))
- return node;
- }
- Q_ASSERT(false);
- return 0;
-}
-
-BookmarkNode *BookmarksManager::toolbar()
-{
- if (!m_loaded)
- load();
-
- for (int i = m_bookmarkRootNode->children().count() - 1; i >= 0; --i) {
- BookmarkNode *node = m_bookmarkRootNode->children().at(i);
- if (node->title == i18n(BOOKMARKBAR))
- return node;
- }
- Q_ASSERT(false);
- return 0;
-}
-
-BookmarksModel *BookmarksManager::bookmarksModel()
-{
- if (!m_bookmarkModel)
- m_bookmarkModel = new BookmarksModel(this, this);
- return m_bookmarkModel;
-}
-
-void BookmarksManager::importBookmarks()
-{
- QString fileName = QFileDialog::getOpenFileName(0, i18n("Open File"),
- QString(),
- i18n("XBEL (*.xbel *.xml)"));
- if (fileName.isEmpty())
- return;
-
- XbelReader reader;
- BookmarkNode *importRootNode = reader.read(fileName);
- if (reader.error() != QXmlStreamReader::NoError) {
- QMessageBox::warning(0, QLatin1String("Loading Bookmark"),
- i18n("Error when loading bookmarks on line %1, column %2:\n %3", reader.lineNumber(), reader.columnNumber(), reader.errorString() )
- );
- }
-
- importRootNode->setType(BookmarkNode::Folder);
- importRootNode->title = ( i18n("Imported ") + QDate::currentDate().toString(Qt::SystemLocaleShortDate) );
- addBookmark(menu(), importRootNode);
-}
-
-void BookmarksManager::exportBookmarks()
-{
- QString fileName = QFileDialog::getSaveFileName(0, i18n("Save File"),
- QCoreApplication::applicationName() + i18n(" Bookmarks.xbel"),
- i18n("XBEL (*.xbel *.xml)"));
- if (fileName.isEmpty())
- return;
-
- XbelWriter writer;
- if (!writer.write(fileName, m_bookmarkRootNode))
- QMessageBox::critical(0, i18n("Export error"), i18n("error saving bookmarks"));
-}
-
-RemoveBookmarksCommand::RemoveBookmarksCommand(BookmarksManager *m_bookmarkManagaer, BookmarkNode *parent, int row)
- : QUndoCommand( i18n("Remove Bookmark") )
- , m_row(row)
- , m_bookmarkManagaer(m_bookmarkManagaer)
- , m_node(parent->children().value(row))
- , m_parent(parent)
- , m_done(false)
-{
-}
-
-RemoveBookmarksCommand::~RemoveBookmarksCommand()
-{
- if (m_done && !m_node->parent()) {
- delete m_node;
- }
-}
-
-void RemoveBookmarksCommand::undo()
-{
- m_parent->add(m_node, m_row);
- emit m_bookmarkManagaer->entryAdded(m_node);
- m_done = false;
-}
-
-void RemoveBookmarksCommand::redo()
-{
- m_parent->remove(m_node);
- emit m_bookmarkManagaer->entryRemoved(m_parent, m_row, m_node);
- m_done = true;
-}
-
-InsertBookmarksCommand::InsertBookmarksCommand(BookmarksManager *m_bookmarkManagaer,
- BookmarkNode *parent, BookmarkNode *node, int row)
- : RemoveBookmarksCommand(m_bookmarkManagaer, parent, row)
-{
- setText( i18n("Insert Bookmark") );
- m_node = node;
-}
-
-ChangeBookmarkCommand::ChangeBookmarkCommand(BookmarksManager *m_bookmarkManagaer, BookmarkNode *node,
- const QString &newValue, bool title)
- : QUndoCommand()
- , m_bookmarkManagaer(m_bookmarkManagaer)
- , m_title(title)
- , m_newValue(newValue)
- , m_node(node)
-{
- if (m_title) {
- m_oldValue = m_node->title;
- setText( i18n("Name Change") );
- } else {
- m_oldValue = m_node->url;
- setText( i18n("Address Change") );
- }
-}
-
-void ChangeBookmarkCommand::undo()
-{
- if (m_title)
- m_node->title = m_oldValue;
- else
- m_node->url = m_oldValue;
- emit m_bookmarkManagaer->entryChanged(m_node);
-}
-
-void ChangeBookmarkCommand::redo()
-{
- if (m_title)
- m_node->title = m_newValue;
- else
- m_node->url = m_newValue;
- emit m_bookmarkManagaer->entryChanged(m_node);
-}
-
-BookmarksModel::BookmarksModel(BookmarksManager *bookmarkManager, QObject *parent)
- : QAbstractItemModel(parent)
- , m_endMacro(false)
- , m_bookmarksManager(bookmarkManager)
-{
- connect(bookmarkManager, SIGNAL(entryAdded(BookmarkNode *)), this, SLOT(entryAdded(BookmarkNode *)));
- connect(bookmarkManager, SIGNAL(entryRemoved(BookmarkNode *, int, BookmarkNode *)), this, SLOT(entryRemoved(BookmarkNode *, int, BookmarkNode *)));
- connect(bookmarkManager, SIGNAL(entryChanged(BookmarkNode *)), this, SLOT(entryChanged(BookmarkNode *)));
-}
-
-QModelIndex BookmarksModel::index(BookmarkNode *node) const
-{
- BookmarkNode *parent = node->parent();
- if (!parent)
- return QModelIndex();
- return createIndex(parent->children().indexOf(node), 0, node);
-}
-
-void BookmarksModel::entryAdded(BookmarkNode *item)
-{
- Q_ASSERT(item && item->parent());
- int row = item->parent()->children().indexOf(item);
- BookmarkNode *parent = item->parent();
- // item was already added so remove beore beginInsertRows is called
- parent->remove(item);
- beginInsertRows(index(parent), row, row);
- parent->add(item, row);
- endInsertRows();
-}
-
-void BookmarksModel::entryRemoved(BookmarkNode *parent, int row, BookmarkNode *item)
-{
- // item was already removed, re-add so beginRemoveRows works
- parent->add(item, row);
- beginRemoveRows(index(parent), row, row);
- parent->remove(item);
- endRemoveRows();
-}
-
-void BookmarksModel::entryChanged(BookmarkNode *item)
-{
- QModelIndex idx = index(item);
- emit dataChanged(idx, idx);
-}
-
-bool BookmarksModel::removeRows(int row, int count, const QModelIndex &parent)
-{
- if (row < 0 || count <= 0 || row + count > rowCount(parent))
- return false;
-
- BookmarkNode *bookmarkNode = node(parent);
- for (int i = row + count - 1; i >= row; --i) {
- BookmarkNode *node = bookmarkNode->children().at(i);
- if (node == m_bookmarksManager->menu()
- || node == m_bookmarksManager->toolbar())
- continue;
-
- m_bookmarksManager->removeBookmark(node);
- }
- if (m_endMacro) {
- m_bookmarksManager->undoRedoStack()->endMacro();
- m_endMacro = false;
- }
- return true;
-}
-
-QVariant BookmarksModel::headerData(int section, Qt::Orientation orientation, int role) const
-{
- if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
- switch (section) {
- case 0: return i18n("Title");
- case 1: return i18n("Address");
- }
- }
- return QAbstractItemModel::headerData(section, orientation, role);
-}
-
-QVariant BookmarksModel::data(const QModelIndex &index, int role) const
-{
- if (!index.isValid() || index.model() != this)
- return QVariant();
-
- const BookmarkNode *bookmarkNode = node(index);
- switch (role) {
- case Qt::EditRole:
- case Qt::DisplayRole:
- if (bookmarkNode->type() == BookmarkNode::Separator) {
- switch (index.column()) {
- case 0: return QString(50, 0xB7);
- case 1: return QString();
- }
- }
-
- switch (index.column()) {
- case 0: return bookmarkNode->title;
- case 1: return bookmarkNode->url;
- }
- break;
- case BookmarksModel::UrlRole:
- return QUrl(bookmarkNode->url);
- break;
- case BookmarksModel::UrlStringRole:
- return bookmarkNode->url;
- break;
- case BookmarksModel::TypeRole:
- return bookmarkNode->type();
- break;
- case BookmarksModel::SeparatorRole:
- return (bookmarkNode->type() == BookmarkNode::Separator);
- break;
- case Qt::DecorationRole:
- if (index.column() == 0) {
- if (bookmarkNode->type() == BookmarkNode::Folder)
- return QApplication::style()->standardIcon(QStyle::SP_DirIcon);
- return BrowserApplication::instance()->icon(bookmarkNode->url);
- }
- }
-
- return QVariant();
-}
-
-int BookmarksModel::columnCount(const QModelIndex &parent) const
-{
- return (parent.column() > 0) ? 0 : 2;
-}
-
-int BookmarksModel::rowCount(const QModelIndex &parent) const
-{
- if (parent.column() > 0)
- return 0;
-
- if (!parent.isValid())
- return m_bookmarksManager->bookmarks()->children().count();
-
- const BookmarkNode *item = static_cast<BookmarkNode*>(parent.internalPointer());
- return item->children().count();
-}
-
-QModelIndex BookmarksModel::index(int row, int column, const QModelIndex &parent) const
-{
- if (row < 0 || column < 0 || row >= rowCount(parent) || column >= columnCount(parent))
- return QModelIndex();
-
- // get the parent node
- BookmarkNode *parentNode = node(parent);
- return createIndex(row, column, parentNode->children().at(row));
-}
-
-QModelIndex BookmarksModel::parent(const QModelIndex &index) const
-{
- if (!index.isValid())
- return QModelIndex();
-
- BookmarkNode *itemNode = node(index);
- BookmarkNode *parentNode = (itemNode ? itemNode->parent() : 0);
- if (!parentNode || parentNode == m_bookmarksManager->bookmarks())
- return QModelIndex();
-
- // get the parent's row
- BookmarkNode *grandParentNode = parentNode->parent();
- int parentRow = grandParentNode->children().indexOf(parentNode);
- Q_ASSERT(parentRow >= 0);
- return createIndex(parentRow, 0, parentNode);
-}
-
-bool BookmarksModel::hasChildren(const QModelIndex &parent) const
-{
- if (!parent.isValid())
- return true;
- const BookmarkNode *parentNode = node(parent);
- return (parentNode->type() == BookmarkNode::Folder);
-}
-
-Qt::ItemFlags BookmarksModel::flags(const QModelIndex &index) const
-{
- if (!index.isValid())
- return Qt::NoItemFlags;
-
- Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
-
- BookmarkNode *bookmarkNode = node(index);
-
- if (bookmarkNode != m_bookmarksManager->menu()
- && bookmarkNode != m_bookmarksManager->toolbar()) {
- flags |= Qt::ItemIsDragEnabled;
- if (bookmarkNode->type() != BookmarkNode::Separator)
- flags |= Qt::ItemIsEditable;
- }
- if (hasChildren(index))
- flags |= Qt::ItemIsDropEnabled;
- return flags;
-}
-
-Qt::DropActions BookmarksModel::supportedDropActions () const
-{
- return Qt::CopyAction | Qt::MoveAction;
-}
-
-#define MIMETYPE QLatin1String("application/bookmarks.xbel")
-
-QStringList BookmarksModel::mimeTypes() const
-{
- QStringList types;
- types << MIMETYPE;
- return types;
-}
-
-QMimeData *BookmarksModel::mimeData(const QModelIndexList &indexes) const
-{
- QMimeData *mimeData = new QMimeData();
- QByteArray data;
- QDataStream stream(&data, QIODevice::WriteOnly);
- foreach (QModelIndex index, indexes) {
- if (index.column() != 0 || !index.isValid())
- continue;
- QByteArray encodedData;
- QBuffer buffer(&encodedData);
- buffer.open(QBuffer::ReadWrite);
- XbelWriter writer;
- const BookmarkNode *parentNode = node(index);
- writer.write(&buffer, parentNode);
- stream << encodedData;
- }
- mimeData->setData(MIMETYPE, data);
- return mimeData;
-}
-
-bool BookmarksModel::dropMimeData(const QMimeData *data,
- Qt::DropAction action, int row, int column, const QModelIndex &parent)
-{
- if (action == Qt::IgnoreAction)
- return true;
-
- if (!data->hasFormat(MIMETYPE)
- || column > 0)
- return false;
-
- QByteArray ba = data->data(MIMETYPE);
- QDataStream stream(&ba, QIODevice::ReadOnly);
- if (stream.atEnd())
- return false;
-
- QUndoStack *undoStack = m_bookmarksManager->undoRedoStack();
- undoStack->beginMacro(QLatin1String("Move Bookmarks"));
-
- while (!stream.atEnd()) {
- QByteArray encodedData;
- stream >> encodedData;
- QBuffer buffer(&encodedData);
- buffer.open(QBuffer::ReadOnly);
-
- XbelReader reader;
- BookmarkNode *rootNode = reader.read(&buffer);
- QList<BookmarkNode*> children = rootNode->children();
- for (int i = 0; i < children.count(); ++i) {
- BookmarkNode *bookmarkNode = children.at(i);
- rootNode->remove(bookmarkNode);
- row = qMax(0, row);
- BookmarkNode *parentNode = node(parent);
- m_bookmarksManager->addBookmark(parentNode, bookmarkNode, row);
- m_endMacro = true;
- }
- delete rootNode;
- }
- return true;
-}
-
-bool BookmarksModel::setData(const QModelIndex &index, const QVariant &value, int role)
-{
- if (!index.isValid() || (flags(index) & Qt::ItemIsEditable) == 0)
- return false;
-
- BookmarkNode *item = node(index);
-
- switch (role) {
- case Qt::EditRole:
- case Qt::DisplayRole:
- if (index.column() == 0) {
- m_bookmarksManager->setTitle(item, value.toString());
- break;
- }
- if (index.column() == 1) {
- m_bookmarksManager->setUrl(item, value.toString());
- break;
- }
- return false;
- case BookmarksModel::UrlRole:
- m_bookmarksManager->setUrl(item, value.toUrl().toString());
- break;
- case BookmarksModel::UrlStringRole:
- m_bookmarksManager->setUrl(item, value.toString());
- break;
- default:
- break;
- return false;
- }
-
- return true;
-}
-
-BookmarkNode *BookmarksModel::node(const QModelIndex &index) const
-{
- BookmarkNode *itemNode = static_cast<BookmarkNode*>(index.internalPointer());
- if (!itemNode)
- return m_bookmarksManager->bookmarks();
- return itemNode;
-}
-
-
-AddBookmarkProxyModel::AddBookmarkProxyModel(QObject *parent)
- : QSortFilterProxyModel(parent)
-{
-}
-
-int AddBookmarkProxyModel::columnCount(const QModelIndex &parent) const
-{
- return qMin(1, QSortFilterProxyModel::columnCount(parent));
-}
-
-bool AddBookmarkProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
-{
- QModelIndex idx = sourceModel()->index(source_row, 0, source_parent);
- return sourceModel()->hasChildren(idx);
-}
-
-AddBookmarkDialog::AddBookmarkDialog(const QString &url, const QString &title, QWidget *parent, BookmarksManager *bookmarkManager)
- : QDialog(parent)
- , m_url(url)
- , m_bookmarksManager(bookmarkManager)
-{
- setWindowFlags(Qt::Sheet);
- if (!m_bookmarksManager)
- m_bookmarksManager = BrowserApplication::bookmarksManager();
- setupUi(this);
- QTreeView *view = new QTreeView(this);
- m_proxyModel = new AddBookmarkProxyModel(this);
- BookmarksModel *model = m_bookmarksManager->bookmarksModel();
- m_proxyModel->setSourceModel(model);
- view->setModel(m_proxyModel);
- view->expandAll();
- view->header()->setStretchLastSection(true);
- view->header()->hide();
- view->setItemsExpandable(false);
- view->setRootIsDecorated(false);
- view->setIndentation(10);
- location->setModel(m_proxyModel);
- view->show();
- location->setView(view);
- BookmarkNode *menu = m_bookmarksManager->menu();
- QModelIndex idx = m_proxyModel->mapFromSource(model->index(menu));
- view->setCurrentIndex(idx);
- location->setCurrentIndex(idx.row());
- name->setText(title);
-}
-
-void AddBookmarkDialog::accept()
-{
- QModelIndex index = location->view()->currentIndex();
- index = m_proxyModel->mapToSource(index);
- if (!index.isValid())
- index = m_bookmarksManager->bookmarksModel()->index(0, 0);
- BookmarkNode *parent = m_bookmarksManager->bookmarksModel()->node(index);
- BookmarkNode *bookmark = new BookmarkNode(BookmarkNode::Bookmark);
- bookmark->url = m_url;
- bookmark->title = name->text();
- m_bookmarksManager->addBookmark(parent, bookmark);
- QDialog::accept();
-}
-
-BookmarksMenu::BookmarksMenu(QWidget *parent)
- : ModelMenu(parent)
- , m_bookmarksManager(0)
-{
- connect(this, SIGNAL(activated(const QModelIndex &)),
- this, SLOT(activated(const QModelIndex &)));
- setMaxRows(-1);
- setHoverRole(BookmarksModel::UrlStringRole);
- setSeparatorRole(BookmarksModel::SeparatorRole);
-}
-
-void BookmarksMenu::activated(const QModelIndex &index)
-{
- emit openUrl(index.data(BookmarksModel::UrlRole).toUrl());
-}
-
-bool BookmarksMenu::prePopulated()
-{
- m_bookmarksManager = BrowserApplication::bookmarksManager();
- setModel(m_bookmarksManager->bookmarksModel());
- setRootIndex(m_bookmarksManager->bookmarksModel()->index(1, 0));
- // initial actions
- for (int i = 0; i < m_initialActions.count(); ++i)
- addAction(m_initialActions.at(i));
- if (!m_initialActions.isEmpty())
- addSeparator();
- createMenu(model()->index(0, 0), 1, this);
- return true;
-}
-
-void BookmarksMenu::setInitialActions(QList<QAction*> actions)
-{
- m_initialActions = actions;
- for (int i = 0; i < m_initialActions.count(); ++i)
- addAction(m_initialActions.at(i));
-}
-
-BookmarksDialog::BookmarksDialog(QWidget *parent, BookmarksManager *manager)
- : QDialog(parent)
-{
- m_bookmarksManager = manager;
- if (!m_bookmarksManager)
- m_bookmarksManager = BrowserApplication::bookmarksManager();
- setupUi(this);
-
- tree->setUniformRowHeights(true);
- tree->setSelectionBehavior(QAbstractItemView::SelectRows);
- tree->setSelectionMode(QAbstractItemView::ContiguousSelection);
- tree->setTextElideMode(Qt::ElideMiddle);
- m_bookmarksModel = m_bookmarksManager->bookmarksModel();
- m_proxyModel = new TreeProxyModel(this);
- connect(search, SIGNAL(textChanged(QString)),
- m_proxyModel, SLOT(setFilterFixedString(QString)));
- connect(removeButton, SIGNAL(clicked()), tree, SLOT(removeOne()));
- m_proxyModel->setSourceModel(m_bookmarksModel);
- tree->setModel(m_proxyModel);
- tree->setDragDropMode(QAbstractItemView::InternalMove);
- tree->setExpanded(m_proxyModel->index(0, 0), true);
- tree->setAlternatingRowColors(true);
- QFontMetrics fm(font());
- int header = fm.width(QLatin1Char('m')) * 40;
- tree->header()->resizeSection(0, header);
- tree->header()->setStretchLastSection(true);
- connect(tree, SIGNAL(activated(const QModelIndex&)),
- this, SLOT(open()));
- tree->setContextMenuPolicy(Qt::CustomContextMenu);
- connect(tree, SIGNAL(customContextMenuRequested(const QPoint &)),
- this, SLOT(customContextMenuRequested(const QPoint &)));
- connect(addFolderButton, SIGNAL(clicked()),
- this, SLOT(newFolder()));
- expandNodes(m_bookmarksManager->bookmarks());
- setAttribute(Qt::WA_DeleteOnClose);
-}
-
-BookmarksDialog::~BookmarksDialog()
-{
- if (saveExpandedNodes(tree->rootIndex()))
- m_bookmarksManager->changeExpanded();
-}
-
-bool BookmarksDialog::saveExpandedNodes(const QModelIndex &parent)
-{
- bool changed = false;
- for (int i = 0; i < m_proxyModel->rowCount(parent); ++i) {
- QModelIndex child = m_proxyModel->index(i, 0, parent);
- QModelIndex sourceIndex = m_proxyModel->mapToSource(child);
- BookmarkNode *childNode = m_bookmarksModel->node(sourceIndex);
- bool wasExpanded = childNode->expanded;
- if (tree->isExpanded(child)) {
- childNode->expanded = true;
- changed |= saveExpandedNodes(child);
- } else {
- childNode->expanded = false;
- }
- changed |= (wasExpanded != childNode->expanded);
- }
- return changed;
-}
-
-void BookmarksDialog::expandNodes(BookmarkNode *node)
-{
- for (int i = 0; i < node->children().count(); ++i) {
- BookmarkNode *childNode = node->children()[i];
- if (childNode->expanded) {
- QModelIndex idx = m_bookmarksModel->index(childNode);
- idx = m_proxyModel->mapFromSource(idx);
- tree->setExpanded(idx, true);
- expandNodes(childNode);
- }
- }
-}
-
-void BookmarksDialog::customContextMenuRequested(const QPoint &pos)
-{
- QMenu menu;
- QModelIndex index = tree->indexAt(pos);
- index = index.sibling(index.row(), 0);
- if (index.isValid() && !tree->model()->hasChildren(index)) {
- menu.addAction( i18n("Open"), this, SLOT(open()));
- menu.addSeparator();
- }
- menu.addAction( i18n("Delete"), tree, SLOT(removeOne()));
- menu.exec(QCursor::pos());
-}
-
-void BookmarksDialog::open()
-{
- QModelIndex index = tree->currentIndex();
- if (!index.parent().isValid())
- return;
- emit openUrl(index.sibling(index.row(), 1).data(BookmarksModel::UrlRole).toUrl());
-}
-
-void BookmarksDialog::newFolder()
-{
- QModelIndex currentIndex = tree->currentIndex();
- QModelIndex idx = currentIndex;
- if (idx.isValid() && !idx.model()->hasChildren(idx))
- idx = idx.parent();
- if (!idx.isValid())
- idx = tree->rootIndex();
- idx = m_proxyModel->mapToSource(idx);
- BookmarkNode *parent = m_bookmarksManager->bookmarksModel()->node(idx);
- BookmarkNode *node = new BookmarkNode(BookmarkNode::Folder);
- node->title = i18n("New Folder");
- m_bookmarksManager->addBookmark(parent, node, currentIndex.row() + 1);
-}
-
-BookmarksToolBar::BookmarksToolBar(BookmarksModel *model, QWidget *parent)
- : QToolBar( i18n("Bookmark"), parent)
- , m_bookmarksModel(model)
-{
- connect(this, SIGNAL(actionTriggered(QAction*)), this, SLOT(triggered(QAction*)));
- setRootIndex(model->index(0, 0));
- connect(m_bookmarksModel, SIGNAL(modelReset()), this, SLOT(build()));
- connect(m_bookmarksModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)), this, SLOT(build()));
- connect(m_bookmarksModel, SIGNAL(rowsRemoved(const QModelIndex &, int, int)), this, SLOT(build()));
- connect(m_bookmarksModel, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)), this, SLOT(build()));
- setAcceptDrops(true);
-}
-
-void BookmarksToolBar::dragEnterEvent(QDragEnterEvent *event)
-{
- const QMimeData *mimeData = event->mimeData();
- if (mimeData->hasUrls())
- event->acceptProposedAction();
- QToolBar::dragEnterEvent(event);
-}
-
-void BookmarksToolBar::dropEvent(QDropEvent *event)
-{
- const QMimeData *mimeData = event->mimeData();
- if (mimeData->hasUrls() && mimeData->hasText()) {
- QList<QUrl> urls = mimeData->urls();
- QAction *action = actionAt(event->pos());
- QString dropText;
- if (action)
- dropText = action->text();
- int row = -1;
- QModelIndex parentIndex = m_root;
- for (int i = 0; i < m_bookmarksModel->rowCount(m_root); ++i) {
- QModelIndex idx = m_bookmarksModel->index(i, 0, m_root);
- QString title = idx.data().toString();
- if (title == dropText) {
- row = i;
- if (m_bookmarksModel->hasChildren(idx)) {
- parentIndex = idx;
- row = -1;
- }
- break;
- }
- }
- BookmarkNode *bookmark = new BookmarkNode(BookmarkNode::Bookmark);
- bookmark->url = urls.at(0).toString();
- bookmark->title = mimeData->text();
-
- BookmarkNode *parent = m_bookmarksModel->node(parentIndex);
- BookmarksManager *bookmarksManager = m_bookmarksModel->bookmarksManager();
- bookmarksManager->addBookmark(parent, bookmark, row);
- event->acceptProposedAction();
- }
- QToolBar::dropEvent(event);
-}
-
-
-void BookmarksToolBar::setRootIndex(const QModelIndex &index)
-{
- m_root = index;
- build();
-}
-
-QModelIndex BookmarksToolBar::rootIndex() const
-{
- return m_root;
-}
-
-void BookmarksToolBar::build()
-{
- clear();
- for (int i = 0; i < m_bookmarksModel->rowCount(m_root); ++i) {
- QModelIndex idx = m_bookmarksModel->index(i, 0, m_root);
- if (m_bookmarksModel->hasChildren(idx)) {
- QToolButton *button = new QToolButton(this);
- button->setPopupMode(QToolButton::InstantPopup);
- button->setArrowType(Qt::DownArrow);
- button->setText(idx.data().toString());
- ModelMenu *menu = new ModelMenu(this);
- connect(menu, SIGNAL(activated(const QModelIndex &)),
- this, SLOT(activated(const QModelIndex &)));
- menu->setModel(m_bookmarksModel);
- menu->setRootIndex(idx);
- menu->addAction(new QAction(menu));
- button->setMenu(menu);
- button->setToolButtonStyle(Qt::ToolButtonTextOnly);
- QAction *a = addWidget(button);
- a->setText(idx.data().toString());
- } else {
- QAction *action = addAction(idx.data().toString());
- action->setData(idx.data(BookmarksModel::UrlRole));
- }
- }
-}
-
-void BookmarksToolBar::triggered(QAction *action)
-{
- QVariant v = action->data();
- if (v.canConvert<QUrl>()) {
- emit openUrl(v.toUrl());
- }
-}
-
-void BookmarksToolBar::activated(const QModelIndex &index)
-{
- emit openUrl(index.data(BookmarksModel::UrlRole).toUrl());
-}
-
diff --git a/src/bookmarks.h b/src/bookmarks.h
deleted file mode 100644
index 4ce3e49f..00000000
--- a/src/bookmarks.h
+++ /dev/null
@@ -1,289 +0,0 @@
-/* ============================================================
- *
- * This file is a part of the reKonq project
- *
- * Copyright (C) 2007-2008 Trolltech ASA. All rights reserved
- * Copyright (C) 2008 by Andrea Diamantini <adjam7 at gmail dot com>
- *
- *
- * 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 2, 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.
- *
- * ============================================================ */
-
-#ifndef BOOKMARKS_H
-#define BOOKMARKS_H
-
-#include <QtCore/QObject>
-#include <QtCore/QAbstractItemModel>
-
-#include <QtGui/QUndoCommand>
-
-/*!
- Bookmark manager, owner of the bookmarks, loads, saves and basic tasks
- */
-class AutoSaver;
-class BookmarkNode;
-class BookmarksModel;
-class BookmarksManager : public QObject
-{
- Q_OBJECT
-
-signals:
- void entryAdded(BookmarkNode *item);
- void entryRemoved(BookmarkNode *parent, int row, BookmarkNode *item);
- void entryChanged(BookmarkNode *item);
-
-public:
- BookmarksManager(QObject *parent = 0);
- ~BookmarksManager();
-
- void addBookmark(BookmarkNode *parent, BookmarkNode *node, int row = -1);
- void removeBookmark(BookmarkNode *node);
- void setTitle(BookmarkNode *node, const QString &newTitle);
- void setUrl(BookmarkNode *node, const QString &newUrl);
- void changeExpanded();
-
- BookmarkNode *bookmarks();
- BookmarkNode *menu();
- BookmarkNode *toolbar();
-
- BookmarksModel *bookmarksModel();
- QUndoStack *undoRedoStack() { return &m_commands; };
-
-public slots:
- void importBookmarks();
- void exportBookmarks();
-
-private slots:
- void save() const;
-
-private:
- void load();
-
- bool m_loaded;
- AutoSaver *m_saveTimer;
- BookmarkNode *m_bookmarkRootNode;
- BookmarksModel *m_bookmarkModel;
- QUndoStack m_commands;
-
- friend class RemoveBookmarksCommand;
- friend class ChangeBookmarkCommand;
-};
-
-class RemoveBookmarksCommand : public QUndoCommand
-{
-
-public:
- RemoveBookmarksCommand(BookmarksManager *m_bookmarkManagaer, BookmarkNode *parent, int row);
- ~RemoveBookmarksCommand();
- void undo();
- void redo();
-
-protected:
- int m_row;
- BookmarksManager *m_bookmarkManagaer;
- BookmarkNode *m_node;
- BookmarkNode *m_parent;
- bool m_done;
-};
-
-class InsertBookmarksCommand : public RemoveBookmarksCommand
-{
-
-public:
- InsertBookmarksCommand(BookmarksManager *m_bookmarkManagaer,
- BookmarkNode *parent, BookmarkNode *node, int row);
- void undo() { RemoveBookmarksCommand::redo(); }
- void redo() { RemoveBookmarksCommand::undo(); }
-
-};
-
-class ChangeBookmarkCommand : public QUndoCommand
-{
-
-public:
- ChangeBookmarkCommand(BookmarksManager *m_bookmarkManagaer,
- BookmarkNode *node, const QString &newValue, bool title);
- void undo();
- void redo();
-
-private:
- BookmarksManager *m_bookmarkManagaer;
- bool m_title;
- QString m_oldValue;
- QString m_newValue;
- BookmarkNode *m_node;
-};
-
-/*!
- BookmarksModel is a QAbstractItemModel wrapper around the BookmarkManager
- */
-#include <QtGui/QIcon>
-class BookmarksModel : public QAbstractItemModel
-{
- Q_OBJECT
-
-public slots:
- void entryAdded(BookmarkNode *item);
- void entryRemoved(BookmarkNode *parent, int row, BookmarkNode *item);
- void entryChanged(BookmarkNode *item);
-
-public:
- enum Roles {
- TypeRole = Qt::UserRole + 1,
- UrlRole = Qt::UserRole + 2,
- UrlStringRole = Qt::UserRole + 3,
- SeparatorRole = Qt::UserRole + 4
- };
-
- BookmarksModel(BookmarksManager *bookmarkManager, QObject *parent = 0);
- inline BookmarksManager *bookmarksManager() const { return m_bookmarksManager; }
-
- QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
- QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
- int columnCount(const QModelIndex &parent = QModelIndex()) const;
- int rowCount(const QModelIndex &parent = QModelIndex()) const;
- QModelIndex index(int, int, const QModelIndex& = QModelIndex()) const;
- QModelIndex parent(const QModelIndex& index= QModelIndex()) const;
- Qt::ItemFlags flags(const QModelIndex &index) const;
- Qt::DropActions supportedDropActions () const;
- bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
- bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
- QMimeData *mimeData(const QModelIndexList &indexes) const;
- QStringList mimeTypes() const;
- bool dropMimeData(const QMimeData *data,
- Qt::DropAction action, int row, int column, const QModelIndex &parent);
- bool hasChildren(const QModelIndex &parent = QModelIndex()) const;
-
- BookmarkNode *node(const QModelIndex &index) const;
- QModelIndex index(BookmarkNode *node) const;
-
-private:
-
- bool m_endMacro;
- BookmarksManager *m_bookmarksManager;
-};
-
-// Menu that is dynamically populated from the bookmarks
-#include "modelmenu.h"
-class BookmarksMenu : public ModelMenu
-{
- Q_OBJECT
-
-signals:
- void openUrl(const QUrl &url);
-
-public:
- BookmarksMenu(QWidget *parent = 0);
- void setInitialActions(QList<QAction*> actions);
-
-protected:
- bool prePopulated();
-
-private slots:
- void activated(const QModelIndex &index);
-
-private:
- BookmarksManager *m_bookmarksManager;
- QList<QAction*> m_initialActions;
-};
-
-/*
- Proxy model that filters out the bookmarks so only the folders
- are left behind. Used in the add bookmark dialog combobox.
- */
-#include <QtGui/QSortFilterProxyModel>
-class AddBookmarkProxyModel : public QSortFilterProxyModel
-{
- Q_OBJECT
-public:
- AddBookmarkProxyModel(QObject * parent = 0);
- int columnCount(const QModelIndex & parent = QModelIndex()) const;
-
-protected:
- bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;
-};
-
-/*!
- Add bookmark dialog
- */
-#include "ui_addbookmarkdialog.h"
-class AddBookmarkDialog : public QDialog, public Ui_AddBookmarkDialog
-{
- Q_OBJECT
-
-public:
- AddBookmarkDialog(const QString &url, const QString &title, QWidget *parent = 0, BookmarksManager *bookmarkManager = 0);
-
-private slots:
- void accept();
-
-private:
- QString m_url;
- BookmarksManager *m_bookmarksManager;
- AddBookmarkProxyModel *m_proxyModel;
-};
-
-#include "ui_bookmarks.h"
-class TreeProxyModel;
-class BookmarksDialog : public QDialog, public Ui_BookmarksDialog
-{
- Q_OBJECT
-
-signals:
- void openUrl(const QUrl &url);
-
-public:
- BookmarksDialog(QWidget *parent = 0, BookmarksManager *manager = 0);
- ~BookmarksDialog();
-
-private slots:
- void customContextMenuRequested(const QPoint &pos);
- void open();
- void newFolder();
-
-private:
- void expandNodes(BookmarkNode *node);
- bool saveExpandedNodes(const QModelIndex &parent);
-
- BookmarksManager *m_bookmarksManager;
- BookmarksModel *m_bookmarksModel;
- TreeProxyModel *m_proxyModel;
-};
-
-#include <QtGui/QToolBar>
-class BookmarksToolBar : public QToolBar
-{
- Q_OBJECT
-
-signals:
- void openUrl(const QUrl &url);
-
-public:
- BookmarksToolBar(BookmarksModel *model, QWidget *parent = 0);
- void setRootIndex(const QModelIndex &index);
- QModelIndex rootIndex() const;
-
-protected:
- void dragEnterEvent(QDragEnterEvent *event);
- void dropEvent(QDropEvent *event);
-
-private slots:
- void triggered(QAction *action);
- void activated(const QModelIndex &index);
- void build();
-
-private:
- BookmarksModel *m_bookmarksModel;
- QPersistentModelIndex m_root;
-};
-
-#endif // BOOKMARKS_H
diff --git a/src/bookmarks.ui b/src/bookmarks.ui
deleted file mode 100644
index c893e941..00000000
--- a/src/bookmarks.ui
+++ /dev/null
@@ -1,106 +0,0 @@
-<ui version="4.0" >
- <class>BookmarksDialog</class>
- <widget class="QDialog" name="BookmarksDialog" >
- <property name="geometry" >
- <rect>
- <x>0</x>
- <y>0</y>
- <width>758</width>
- <height>450</height>
- </rect>
- </property>
- <property name="windowTitle" >
- <string>Bookmarks</string>
- </property>
- <layout class="QGridLayout" name="gridLayout" >
- <item row="0" column="0" >
- <spacer>
- <property name="orientation" >
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" stdset="0" >
- <size>
- <width>252</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- <item row="0" column="1" >
- <widget class="SearchLineEdit" name="search" />
- </item>
- <item row="1" column="0" colspan="2" >
- <widget class="EditTreeView" name="tree" />
- </item>
- <item row="2" column="0" colspan="2" >
- <layout class="QHBoxLayout" >
- <item>
- <widget class="QPushButton" name="removeButton" >
- <property name="text" >
- <string>&amp;Remove</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="addFolderButton" >
- <property name="text" >
- <string>Add Folder</string>
- </property>
- </widget>
- </item>
- <item>
- <spacer>
- <property name="orientation" >
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" stdset="0" >
- <size>
- <width>40</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- <item>
- <widget class="QDialogButtonBox" name="buttonBox" >
- <property name="standardButtons" >
- <set>QDialogButtonBox::Ok</set>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- </layout>
- </widget>
- <customwidgets>
- <customwidget>
- <class>SearchLineEdit</class>
- <extends>QLineEdit</extends>
- <header>searchlineedit.h</header>
- </customwidget>
- <customwidget>
- <class>EditTreeView</class>
- <extends>QTreeView</extends>
- <header>edittreeview.h</header>
- </customwidget>
- </customwidgets>
- <resources/>
- <connections>
- <connection>
- <sender>buttonBox</sender>
- <signal>accepted()</signal>
- <receiver>BookmarksDialog</receiver>
- <slot>accept()</slot>
- <hints>
- <hint type="sourcelabel" >
- <x>472</x>
- <y>329</y>
- </hint>
- <hint type="destinationlabel" >
- <x>461</x>
- <y>356</y>
- </hint>
- </hints>
- </connection>
- </connections>
-</ui>
diff --git a/src/browserapplication.cpp b/src/browserapplication.cpp
index 2a487143..7a125bdc 100644
--- a/src/browserapplication.cpp
+++ b/src/browserapplication.cpp
@@ -21,7 +21,6 @@
#include "browserapplication.h"
-#include "bookmarks.h"
#include "browsermainwindow.h"
#include "cookiejar.h"
#include "downloadmanager.h"
@@ -52,7 +51,6 @@
DownloadManager *BrowserApplication::s_downloadManager = 0;
HistoryManager *BrowserApplication::s_historyManager = 0;
NetworkAccessManager *BrowserApplication::s_networkAccessManager = 0;
-BookmarksManager *BrowserApplication::s_bookmarksManager = 0;
@@ -109,7 +107,6 @@ BrowserApplication::~BrowserApplication()
delete s_downloadManager;
qDeleteAll(m_mainWindows);
delete s_networkAccessManager;
- delete s_bookmarksManager;
}
@@ -392,16 +389,6 @@ HistoryManager *BrowserApplication::historyManager()
-BookmarksManager *BrowserApplication::bookmarksManager()
-{
- if (!s_bookmarksManager) {
- s_bookmarksManager = new BookmarksManager;
- }
- return s_bookmarksManager;
-}
-
-
-
KIcon BrowserApplication::icon(const QUrl &url) const
{
KIcon icon = KIcon( QWebSettings::iconForUrl(url) );
diff --git a/src/browserapplication.h b/src/browserapplication.h
index 95b93218..43d374d3 100644
--- a/src/browserapplication.h
+++ b/src/browserapplication.h
@@ -33,7 +33,6 @@ QT_BEGIN_NAMESPACE
class QLocalServer;
QT_END_NAMESPACE
-class BookmarksManager;
class BrowserMainWindow;
class CookieJar;
class DownloadManager;
@@ -62,7 +61,6 @@ public:
static CookieJar *cookieJar();
static DownloadManager *downloadManager();
static NetworkAccessManager *networkAccessManager();
- static BookmarksManager *bookmarksManager();
public slots:
BrowserMainWindow *newMainWindow();
@@ -80,7 +78,6 @@ private:
static HistoryManager *s_historyManager;
static DownloadManager *s_downloadManager;
static NetworkAccessManager *s_networkAccessManager;
- static BookmarksManager *s_bookmarksManager;
QList<QPointer<BrowserMainWindow> > m_mainWindows;
QLocalServer *m_localServer;
diff --git a/src/browsermainwindow.cpp b/src/browsermainwindow.cpp
index c3f82354..7aa4a899 100644
--- a/src/browsermainwindow.cpp
+++ b/src/browsermainwindow.cpp
@@ -22,7 +22,6 @@
// Local Includes
#include "browsermainwindow.h"
#include "autosaver.h"
-#include "bookmarks.h"
#include "browserapplication.h"
#include "downloadmanager.h"
#include "history.h"
@@ -41,6 +40,8 @@
#include <KStandardAction>
#include <KAction>
#include <KActionCollection>
+#include <KBookmarkManager>
+#include <KBookmarkOwner>
// Qt Includes
#include <QSettings>
@@ -66,6 +67,7 @@ BrowserMainWindow::BrowserMainWindow(QWidget *parent, Qt::WindowFlags flags)
, m_historyForward(0)
, m_stop(0)
, m_reload(0)
+ , m_bookmarkMenu(0)
{
setAttribute(Qt::WA_DeleteOnClose, true);
statusBar()->setSizeGripEnabled(true);
@@ -191,13 +193,11 @@ bool BrowserMainWindow::restoreState(const QByteArray &state)
QSize size;
bool showToolbar;
- bool showBookmarksBar;
bool showStatusbar;
QByteArray tabState;
stream >> size;
stream >> showToolbar;
- stream >> showBookmarksBar;
stream >> showStatusbar;
stream >> tabState;
@@ -341,32 +341,14 @@ void BrowserMainWindow::setupMenu()
// ------------------------------------------------------------- BOOKMARKS --------------------------------------------------------------------------------------------------
-// BookmarksMenu *bookmarksMenu = new BookmarksMenu(this);
-// connect(bookmarksMenu, SIGNAL(openUrl(const QUrl&)), m_tabWidget, SLOT(loadUrlInCurrentTab(const QUrl&)));
-// connect(bookmarksMenu, SIGNAL(hovered(const QString&)), this, SLOT(slotUpdateStatusbar(const QString&)));
-// bookmarksMenu->setTitle(i18n("&Bookmarks"));
-// menuBar()->addMenu(bookmarksMenu);
-//
-// // FIXME
-// BookmarksManager *bookmarksManager = BrowserApplication::bookmarksManager();
-// bookmarksMenu->addAction(i18n("&Import Bookmarks..."), bookmarksManager, SLOT(importBookmarks()));
-// bookmarksMenu->addAction(i18n("&Export Bookmarks..."), bookmarksManager, SLOT(exportBookmarks()));
-// bookmarksMenu->addSeparator();
-//
-// QList<QAction*> bookmarksActions;
-//
-// QAction *showAllBookmarksAction = new QAction(i18n("Show All Bookmarks"), this);
-// connect(showAllBookmarksAction, SIGNAL(triggered()), this, SLOT(slotShowBookmarksDialog()));
-// m_addBookmark = new QAction( KIcon("bookmark-new"), i18n("Add Bookmark..."), this);
-// m_addBookmark->setIconVisibleInMenu(false);
-//
-// connect(m_addBookmark, SIGNAL(triggered()), this, SLOT(slotAddBookmark()));
-// m_addBookmark->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_D));
-//
-// bookmarksActions.append(showAllBookmarksAction);
-// bookmarksActions.append(m_addBookmark);
-// bookmarksMenu->setInitialActions(bookmarksActions);
+ KMenu* bookmarksMenu = new KMenu( i18n("&Bookmarks"), this );
+
+ menuBar()->addMenu( bookmarksMenu );
+
+ KBookmarkManager *mgr = KBookmarkManager::managerForFile( "~/.kde/share/apps/konqueror/bookmarks.xml" , "konqueror" );
+ KActionCollection * ac = new KActionCollection( this );
+ m_bookmarkMenu = new KBookmarkMenu( mgr , 0 , bookmarksMenu , ac );
// ------------------------------------------------------------- WINDOW --------------------------------------------------------------------------------------------------
m_windowMenu = (KMenu *) menuBar()->addMenu( i18n("&Window") );
@@ -393,7 +375,7 @@ void BrowserMainWindow::setupMenu()
void BrowserMainWindow::setupToolBar()
{
m_navigationBar = (KToolBar *) addToolBar(i18n("Navigation"));
- connect(m_navigationBar->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(updateToolbarActionText(bool)));
+// connect(m_navigationBar->toggleViewAction(), SIGNAL(toggled(bool)), this, SLOT(updateToolbarActionText(bool)));
m_historyBack = new KAction( KIcon("go-previous"), i18n("Back"), this);
m_historyBackMenu = new KMenu(this);
@@ -427,24 +409,24 @@ void BrowserMainWindow::setupToolBar()
-void BrowserMainWindow::slotShowBookmarksDialog()
-{
- BookmarksDialog *dialog = new BookmarksDialog(this);
- connect(dialog, SIGNAL(openUrl(const QUrl&)), m_tabWidget, SLOT(loadUrlInCurrentTab(const QUrl&)));
- dialog->show();
-}
+// void BrowserMainWindow::slotShowBookmarksDialog()
+// {
+// BookmarksDialog *dialog = new BookmarksDialog(this);
+// connect(dialog, SIGNAL(openUrl(const QUrl&)), m_tabWidget, SLOT(loadUrlInCurrentTab(const QUrl&)));
+// dialog->show();
+// }
-void BrowserMainWindow::slotAddBookmark()
-{
- WebView *webView = currentTab();
- QString url = webView->url().toString();
- QString title = webView->title();
- AddBookmarkDialog dialog(url, title);
- dialog.exec();
-}
+// void BrowserMainWindow::slotAddBookmark()
+// {
+// WebView *webView = currentTab();
+// QString url = webView->url().toString();
+// QString title = webView->title();
+// AddBookmarkDialog dialog(url, title);
+// dialog.exec();
+// }
void BrowserMainWindow::updateStatusbarActionText(bool visible)
diff --git a/src/browsermainwindow.h b/src/browsermainwindow.h
index 17aa1479..8f4a30f9 100644
--- a/src/browsermainwindow.h
+++ b/src/browsermainwindow.h
@@ -31,6 +31,7 @@
#include <KToolBar>
#include <KAction>
#include <KMenu>
+#include <KBookmarkMenu>
// Qt Includes
#include <QUrl>
@@ -88,8 +89,8 @@ private slots:
void slotEditFind();
void slotEditFindNext();
void slotEditFindPrevious();
- void slotShowBookmarksDialog();
- void slotAddBookmark();
+/* void slotShowBookmarksDialog();
+ void slotAddBookmark();*/
void slotViewTextBigger();
void slotViewTextNormal();
void slotViewTextSmaller();
@@ -145,6 +146,8 @@ private:
FindWidget *m_findWidg;
QString m_lastSearch;
+
+ KBookmarkMenu* m_bookmarkMenu;
};
#endif // BROWSERMAINWINDOW_H
diff --git a/src/xbel.cpp b/src/xbel.cpp
deleted file mode 100644
index 13a91ccb..00000000
--- a/src/xbel.cpp
+++ /dev/null
@@ -1,304 +0,0 @@
-/* ============================================================
- *
- * This file is a part of the reKonq project
- *
- * Copyright (C) 2007-2008 Trolltech ASA. All rights reserved
- * Copyright (C) 2008 by Andrea Diamantini <adjam7 at gmail dot com>
- *
- *
- * 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 2, 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.
- *
- * ============================================================ */
-
-// Local Includes
-#include "xbel.h"
-
-// KDE Includes
-#include <KLocalizedString>
-
-// Qt Includes
-#include <QFile>
-
-
-BookmarkNode::BookmarkNode(BookmarkNode::Type type, BookmarkNode *parent) :
- expanded(false)
- , m_parent(parent)
- , m_type(type)
-{
- if (parent)
- parent->add(this);
-}
-
-BookmarkNode::~BookmarkNode()
-{
- if (m_parent)
- m_parent->remove(this);
- qDeleteAll(m_children);
- m_parent = 0;
- m_type = BookmarkNode::Root;
-}
-
-bool BookmarkNode::operator==(const BookmarkNode &other)
-{
- if (url != other.url
- || title != other.title
- || desc != other.desc
- || expanded != other.expanded
- || m_type != other.m_type
- || m_children.count() != other.m_children.count())
- return false;
-
- for (int i = 0; i < m_children.count(); ++i)
- if (!((*(m_children[i])) == (*(other.m_children[i]))))
- return false;
- return true;
-}
-
-BookmarkNode::Type BookmarkNode::type() const
-{
- return m_type;
-}
-
-void BookmarkNode::setType(Type type)
-{
- m_type = type;
-}
-
-QList<BookmarkNode *> BookmarkNode::children() const
-{
- return m_children;
-}
-
-BookmarkNode *BookmarkNode::parent() const
-{
- return m_parent;
-}
-
-void BookmarkNode::add(BookmarkNode *child, int offset)
-{
- Q_ASSERT(child->m_type != Root);
- if (child->m_parent)
- child->m_parent->remove(child);
- child->m_parent = this;
- if (-1 == offset)
- offset = m_children.size();
- m_children.insert(offset, child);
-}
-
-void BookmarkNode::remove(BookmarkNode *child)
-{
- child->m_parent = 0;
- m_children.removeAll(child);
-}
-
-
-XbelReader::XbelReader()
-{
-}
-
-BookmarkNode *XbelReader::read(const QString &fileName)
-{
- QFile file(fileName);
- if (!file.exists()) {
- return new BookmarkNode(BookmarkNode::Root);
- }
- file.open(QFile::ReadOnly);
- return read(&file);
-}
-
-BookmarkNode *XbelReader::read(QIODevice *device)
-{
- BookmarkNode *root = new BookmarkNode(BookmarkNode::Root);
- setDevice(device);
- while (!atEnd()) {
- readNext();
- if (isStartElement()) {
- QString version = attributes().value(QLatin1String("version")).toString();
- if (name() == QLatin1String("xbel")
- && (version.isEmpty() || version == QLatin1String("1.0"))) {
- readXBEL(root);
- } else {
- raiseError( i18n("The file is not an XBEL version 1.0 file.") );
- }
- }
- }
- return root;
-}
-
-void XbelReader::readXBEL(BookmarkNode *parent)
-{
- Q_ASSERT(isStartElement() && name() == QLatin1String("xbel"));
-
- while (!atEnd()) {
- readNext();
- if (isEndElement())
- break;
-
- if (isStartElement()) {
- if (name() == QLatin1String("folder"))
- readFolder(parent);
- else if (name() == QLatin1String("bookmark"))
- readBookmarkNode(parent);
- else if (name() == QLatin1String("separator"))
- readSeparator(parent);
- else
- skipUnknownElement();
- }
- }
-}
-
-void XbelReader::readFolder(BookmarkNode *parent)
-{
- Q_ASSERT(isStartElement() && name() == QLatin1String("folder"));
-
- BookmarkNode *folder = new BookmarkNode(BookmarkNode::Folder, parent);
- folder->expanded = (attributes().value(QLatin1String("folded")) == QLatin1String("no"));
-
- while (!atEnd()) {
- readNext();
-
- if (isEndElement())
- break;
-
- if (isStartElement()) {
- if (name() == QLatin1String("title"))
- readTitle(folder);
- else if (name() == QLatin1String("desc"))
- readDescription(folder);
- else if (name() == QLatin1String("folder"))
- readFolder(folder);
- else if (name() == QLatin1String("bookmark"))
- readBookmarkNode(folder);
- else if (name() == QLatin1String("separator"))
- readSeparator(folder);
- else
- skipUnknownElement();
- }
- }
-}
-
-void XbelReader::readTitle(BookmarkNode *parent)
-{
- Q_ASSERT(isStartElement() && name() == QLatin1String("title"));
- parent->title = readElementText();
-}
-
-void XbelReader::readDescription(BookmarkNode *parent)
-{
- Q_ASSERT(isStartElement() && name() == QLatin1String("desc"));
- parent->desc = readElementText();
-}
-
-void XbelReader::readSeparator(BookmarkNode *parent)
-{
- new BookmarkNode(BookmarkNode::Separator, parent);
- // empty elements have a start and end element
- readNext();
-}
-
-void XbelReader::readBookmarkNode(BookmarkNode *parent)
-{
- Q_ASSERT(isStartElement() && name() == QLatin1String("bookmark"));
- BookmarkNode *bookmark = new BookmarkNode(BookmarkNode::Bookmark, parent);
- bookmark->url = attributes().value(QLatin1String("href")).toString();
- while (!atEnd()) {
- readNext();
- if (isEndElement())
- break;
-
- if (isStartElement()) {
- if (name() == QLatin1String("title"))
- readTitle(bookmark);
- else if (name() == QLatin1String("desc"))
- readDescription(bookmark);
- else
- skipUnknownElement();
- }
- }
- if (bookmark->title.isEmpty())
- bookmark->title = i18n("Unknown title");
-}
-
-void XbelReader::skipUnknownElement()
-{
- Q_ASSERT(isStartElement());
-
- while (!atEnd()) {
- readNext();
-
- if (isEndElement())
- break;
-
- if (isStartElement())
- skipUnknownElement();
- }
-}
-
-
-XbelWriter::XbelWriter()
-{
- setAutoFormatting(true);
-}
-
-bool XbelWriter::write(const QString &fileName, const BookmarkNode *root)
-{
- QFile file(fileName);
- if (!root || !file.open(QFile::WriteOnly))
- return false;
- return write(&file, root);
-}
-
-bool XbelWriter::write(QIODevice *device, const BookmarkNode *root)
-{
- setDevice(device);
-
- writeStartDocument();
- writeDTD(QLatin1String("<!DOCTYPE xbel>"));
- writeStartElement(QLatin1String("xbel"));
- writeAttribute(QLatin1String("version"), QLatin1String("1.0"));
- if (root->type() == BookmarkNode::Root) {
- for (int i = 0; i < root->children().count(); ++i)
- writeItem(root->children().at(i));
- } else {
- writeItem(root);
- }
-
- writeEndDocument();
- return true;
-}
-
-void XbelWriter::writeItem(const BookmarkNode *parent)
-{
- switch (parent->type()) {
- case BookmarkNode::Folder:
- writeStartElement(QLatin1String("folder"));
- writeAttribute(QLatin1String("folded"), parent->expanded ? QLatin1String("no") : QLatin1String("yes"));
- writeTextElement(QLatin1String("title"), parent->title);
- for (int i = 0; i < parent->children().count(); ++i)
- writeItem(parent->children().at(i));
- writeEndElement();
- break;
- case BookmarkNode::Bookmark:
- writeStartElement(QLatin1String("bookmark"));
- if (!parent->url.isEmpty())
- writeAttribute(QLatin1String("href"), parent->url);
- writeTextElement(QLatin1String("title"), parent->title);
- if (!parent->desc.isEmpty())
- writeAttribute(QLatin1String("desc"), parent->desc);
- writeEndElement();
- break;
- case BookmarkNode::Separator:
- writeEmptyElement(QLatin1String("separator"));
- break;
- default:
- break;
- }
-}
diff --git a/src/xbel.h b/src/xbel.h
deleted file mode 100644
index b636a437..00000000
--- a/src/xbel.h
+++ /dev/null
@@ -1,92 +0,0 @@
-/* ============================================================
- *
- * This file is a part of the reKonq project
- *
- * Copyright (C) 2007-2008 Trolltech ASA. All rights reserved
- * Copyright (C) 2008 by Andrea Diamantini <adjam7 at gmail dot com>
- *
- *
- * 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 2, 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.
- *
- * ============================================================ */
-
-#ifndef XBEL_H
-#define XBEL_H
-
-#include <QtCore/QXmlStreamReader>
-#include <QtCore/QDateTime>
-
-class BookmarkNode
-{
-public:
- enum Type {
- Root,
- Folder,
- Bookmark,
- Separator
- };
-
- BookmarkNode(Type type = Root, BookmarkNode *parent = 0);
- ~BookmarkNode();
- bool operator==(const BookmarkNode &other);
-
- Type type() const;
- void setType(Type type);
- QList<BookmarkNode *> children() const;
- BookmarkNode *parent() const;
-
- void add(BookmarkNode *child, int offset = -1);
- void remove(BookmarkNode *child);
-
- QString url;
- QString title;
- QString desc;
- bool expanded;
-
-private:
- BookmarkNode *m_parent;
- Type m_type;
- QList<BookmarkNode *> m_children;
-
-};
-
-class XbelReader : public QXmlStreamReader
-{
-public:
- XbelReader();
- BookmarkNode *read(const QString &fileName);
- BookmarkNode *read(QIODevice *device);
-
-private:
- void skipUnknownElement();
- void readXBEL(BookmarkNode *parent);
- void readTitle(BookmarkNode *parent);
- void readDescription(BookmarkNode *parent);
- void readSeparator(BookmarkNode *parent);
- void readFolder(BookmarkNode *parent);
- void readBookmarkNode(BookmarkNode *parent);
-};
-
-#include <QtCore/QXmlStreamWriter>
-
-class XbelWriter : public QXmlStreamWriter
-{
-public:
- XbelWriter();
- bool write(const QString &fileName, const BookmarkNode *root);
- bool write(QIODevice *device, const BookmarkNode *root);
-
-private:
- void writeItem(const BookmarkNode *parent);
-};
-
-#endif // XBEL_H
-