forked from qt-creator/qt-creator
Implement import - export of help bookmarks.
Task-number: 254695
This commit is contained in:
@@ -29,8 +29,10 @@
|
||||
|
||||
#include "generalsettingspage.h"
|
||||
|
||||
#include "bookmarkmanager.h"
|
||||
#include "centralwidget.h"
|
||||
#include "helpviewer.h"
|
||||
#include "xbelsupport.h"
|
||||
|
||||
#if defined(QT_NO_WEBKIT)
|
||||
#include <QtGui/QApplication>
|
||||
@@ -38,6 +40,8 @@
|
||||
#include <QtWebKit/QWebSettings>
|
||||
#endif
|
||||
|
||||
#include <QtCore/QDebug>
|
||||
#include <QtGui/QFileDialog>
|
||||
#include <QtHelp/QHelpEngine>
|
||||
|
||||
#include <coreplugin/coreconstants.h>
|
||||
@@ -45,10 +49,11 @@
|
||||
using namespace Help::Internal;
|
||||
|
||||
GeneralSettingsPage::GeneralSettingsPage(QHelpEngine *helpEngine,
|
||||
CentralWidget *centralWidget)
|
||||
CentralWidget *centralWidget, BookmarkManager *bookmarkManager)
|
||||
: m_currentPage(0)
|
||||
, m_helpEngine(helpEngine)
|
||||
, m_centralWidget(centralWidget)
|
||||
, m_bookmarkManager(bookmarkManager)
|
||||
{
|
||||
#if !defined(QT_NO_WEBKIT)
|
||||
QWebSettings* webSettings = QWebSettings::globalSettings();
|
||||
@@ -114,6 +119,10 @@ QWidget *GeneralSettingsPage::createPage(QWidget *parent)
|
||||
if (viewer == 0)
|
||||
m_ui.currentPageButton->setEnabled(false);
|
||||
|
||||
m_ui.errorLabel->setVisible(false);
|
||||
connect(m_ui.importButton, SIGNAL(clicked()), this, SLOT(importBookmarks()));
|
||||
connect(m_ui.exportButton, SIGNAL(clicked()), this, SLOT(exportBookmarks()));
|
||||
|
||||
return m_currentPage;
|
||||
}
|
||||
|
||||
@@ -183,6 +192,46 @@ void GeneralSettingsPage::setDefaultPage()
|
||||
m_ui.homePageLineEdit->setText(homePage);
|
||||
}
|
||||
|
||||
void GeneralSettingsPage::importBookmarks()
|
||||
{
|
||||
m_ui.errorLabel->setVisible(false);
|
||||
|
||||
QString fileName = QFileDialog::getOpenFileName(0, tr("Open Image"),
|
||||
QDir::currentPath(), tr("Files (*.xbel)"));
|
||||
|
||||
if (fileName.isEmpty())
|
||||
return;
|
||||
|
||||
QFile file(fileName);
|
||||
if (file.open(QIODevice::ReadOnly)) {
|
||||
XbelReader reader(m_bookmarkManager->treeBookmarkModel(),
|
||||
m_bookmarkManager->listBookmarkModel());
|
||||
if (reader.readFromFile(&file))
|
||||
return;
|
||||
}
|
||||
|
||||
m_ui.errorLabel->setVisible(true);
|
||||
m_ui.errorLabel->setText(tr("There was an error while importing bookmarks!"));
|
||||
}
|
||||
|
||||
void GeneralSettingsPage::exportBookmarks()
|
||||
{
|
||||
m_ui.errorLabel->setVisible(false);
|
||||
|
||||
QString fileName = QFileDialog::getSaveFileName(0, tr("Save File"),
|
||||
"untitled.xbel", tr("Files (*.xbel)"));
|
||||
|
||||
QLatin1String suffix(".xbel");
|
||||
if (!fileName.endsWith(suffix))
|
||||
fileName.append(suffix);
|
||||
|
||||
QFile file(fileName);
|
||||
if (file.open(QIODevice::WriteOnly)) {
|
||||
XbelWriter writer(m_bookmarkManager->treeBookmarkModel());
|
||||
writer.writeToFile(&file);
|
||||
}
|
||||
}
|
||||
|
||||
void GeneralSettingsPage::updateFontSize()
|
||||
{
|
||||
const QString &family = font.family();
|
||||
|
||||
@@ -37,6 +37,8 @@
|
||||
|
||||
#include "ui_generalsettingspage.h"
|
||||
|
||||
class BookmarkManager;
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QFont)
|
||||
QT_FORWARD_DECLARE_CLASS(QHelpEngine)
|
||||
|
||||
@@ -50,7 +52,8 @@ class GeneralSettingsPage : public Core::IOptionsPage
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
GeneralSettingsPage(QHelpEngine *helpEngine, CentralWidget *centralWidget);
|
||||
GeneralSettingsPage(QHelpEngine *helpEngine, CentralWidget *centralWidget,
|
||||
BookmarkManager *bookmarkManager);
|
||||
|
||||
QString id() const;
|
||||
virtual QString trName() const;
|
||||
@@ -68,6 +71,8 @@ private slots:
|
||||
void setCurrentPage();
|
||||
void setBlankPage();
|
||||
void setDefaultPage();
|
||||
void importBookmarks();
|
||||
void exportBookmarks();
|
||||
|
||||
private:
|
||||
void updateFontSize();
|
||||
@@ -79,6 +84,7 @@ private:
|
||||
QWidget *m_currentPage;
|
||||
QHelpEngine *m_helpEngine;
|
||||
CentralWidget *m_centralWidget;
|
||||
BookmarkManager *m_bookmarkManager;
|
||||
|
||||
QFont font;
|
||||
QFontDatabase fontDatabase;
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
@@ -249,6 +249,90 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_3">
|
||||
<property name="title">
|
||||
<string>Help Bookmarks</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>244</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="importButton">
|
||||
<property name="text">
|
||||
<string>Import...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="exportButton">
|
||||
<property name="text">
|
||||
<string>Export...</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="errorLabel">
|
||||
<property name="palette">
|
||||
<palette>
|
||||
<active>
|
||||
<colorrole role="Text">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>255</red>
|
||||
<green>0</green>
|
||||
<blue>0</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
</active>
|
||||
<inactive>
|
||||
<colorrole role="Text">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>255</red>
|
||||
<green>0</green>
|
||||
<blue>0</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
</inactive>
|
||||
<disabled>
|
||||
<colorrole role="Text">
|
||||
<brush brushstyle="SolidPattern">
|
||||
<color alpha="255">
|
||||
<red>120</red>
|
||||
<green>120</green>
|
||||
<blue>120</blue>
|
||||
</color>
|
||||
</brush>
|
||||
</colorrole>
|
||||
</disabled>
|
||||
</palette>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
|
||||
@@ -17,7 +17,8 @@ HEADERS += helpplugin.h \
|
||||
helpfindsupport.h \
|
||||
help_global.h \
|
||||
helpindexfilter.h \
|
||||
generalsettingspage.h
|
||||
generalsettingspage.h \
|
||||
xbelsupport.h
|
||||
|
||||
SOURCES += helpplugin.cpp \
|
||||
docsettingspage.cpp \
|
||||
@@ -27,7 +28,8 @@ SOURCES += helpplugin.cpp \
|
||||
searchwidget.cpp \
|
||||
helpfindsupport.cpp \
|
||||
helpindexfilter.cpp \
|
||||
generalsettingspage.cpp
|
||||
generalsettingspage.cpp \
|
||||
xbelsupport.cpp
|
||||
|
||||
FORMS += docsettingspage.ui \
|
||||
filtersettingspage.ui \
|
||||
|
||||
@@ -417,8 +417,8 @@ bool HelpPlugin::initialize(const QStringList &arguments, QString *error)
|
||||
advancedMenu->addAction(cmd, Core::Constants::G_EDIT_FONT);
|
||||
}
|
||||
|
||||
GeneralSettingsPage *generalSettings =
|
||||
new GeneralSettingsPage(m_helpEngine, m_centralWidget);
|
||||
GeneralSettingsPage *generalSettings = new GeneralSettingsPage(m_helpEngine,
|
||||
m_centralWidget, m_bookmarkManager);
|
||||
addAutoReleasedObject(generalSettings);
|
||||
connect(generalSettings, SIGNAL(fontChanged()), this, SLOT(fontChanged()));
|
||||
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 913 B After Width: | Height: | Size: 1.2 KiB |
222
src/plugins/help/xbelsupport.cpp
Normal file
222
src/plugins/help/xbelsupport.cpp
Normal file
@@ -0,0 +1,222 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://www.qtsoftware.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#include "xbelsupport.h"
|
||||
#include "bookmarkmanager.h"
|
||||
|
||||
using namespace Help::Internal;
|
||||
|
||||
struct Bookmark {
|
||||
QString title;
|
||||
QString url;
|
||||
bool folded;
|
||||
};
|
||||
|
||||
XbelWriter::XbelWriter(BookmarkModel *model)
|
||||
: QXmlStreamWriter()
|
||||
, treeModel(model)
|
||||
{
|
||||
setAutoFormatting(true);
|
||||
}
|
||||
|
||||
void XbelWriter::writeToFile(QIODevice *device)
|
||||
{
|
||||
setDevice(device);
|
||||
|
||||
writeStartDocument();
|
||||
writeDTD(QLatin1String("<!DOCTYPE xbel>"));
|
||||
writeStartElement(QLatin1String("xbel"));
|
||||
writeAttribute(QLatin1String("version"), QLatin1String("1.0"));
|
||||
|
||||
QStandardItem *root = treeModel->invisibleRootItem();
|
||||
for (int i = 0; i < root->rowCount(); ++i)
|
||||
writeData(root->child(i));
|
||||
|
||||
writeEndDocument();
|
||||
}
|
||||
|
||||
void XbelWriter::writeData(QStandardItem *child)
|
||||
{
|
||||
Bookmark entry;
|
||||
entry.title = child->data(Qt::DisplayRole).toString();
|
||||
entry.url = child->data(Qt::UserRole + 10).toString();
|
||||
|
||||
if (entry.url == QLatin1String("Folder")) {
|
||||
writeStartElement(QLatin1String("folder"));
|
||||
|
||||
entry.folded = !child->data(Qt::UserRole + 11).toBool();
|
||||
writeAttribute(QLatin1String("folded"),
|
||||
entry.folded ? QLatin1String("yes") : QLatin1String("no"));
|
||||
|
||||
writeTextElement(QLatin1String("title"), entry.title);
|
||||
|
||||
for (int i = 0; i < child->rowCount(); ++i)
|
||||
writeData(child->child(i));
|
||||
|
||||
writeEndElement();
|
||||
} else {
|
||||
writeStartElement(QLatin1String("bookmark"));
|
||||
writeAttribute(QLatin1String("href"), entry.url);
|
||||
writeTextElement(QLatin1String("title"), entry.title);
|
||||
writeEndElement();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -- XbelReader
|
||||
|
||||
|
||||
XbelReader::XbelReader(BookmarkModel *tree, BookmarkModel *list)
|
||||
: QXmlStreamReader()
|
||||
, treeModel(tree)
|
||||
, listModel(list)
|
||||
{
|
||||
bookmarkIcon = QIcon(QLatin1String(":/help/images/bookmark.png"));
|
||||
folderIcon = QApplication::style()->standardIcon(QStyle::SP_DirClosedIcon);
|
||||
}
|
||||
|
||||
bool XbelReader::readFromFile(QIODevice *device)
|
||||
{
|
||||
setDevice(device);
|
||||
|
||||
while (!atEnd()) {
|
||||
readNext();
|
||||
|
||||
if (isStartElement()) {
|
||||
if (name() == QLatin1String("xbel")
|
||||
&& attributes().value(QLatin1String("version"))
|
||||
== QLatin1String("1.0")) {
|
||||
readXBEL();
|
||||
} else {
|
||||
raiseError(QObject::tr("The file is not an XBEL version 1.0 file."));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return !error();
|
||||
}
|
||||
|
||||
void XbelReader::readXBEL()
|
||||
{
|
||||
while (!atEnd()) {
|
||||
readNext();
|
||||
|
||||
if (isEndElement())
|
||||
break;
|
||||
|
||||
if (isStartElement()) {
|
||||
if (name() == QLatin1String("folder"))
|
||||
readFolder(0);
|
||||
else if (name() == QLatin1String("bookmark"))
|
||||
readBookmark(0);
|
||||
else
|
||||
readUnknownElement();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void XbelReader::readUnknownElement()
|
||||
{
|
||||
while (!atEnd()) {
|
||||
readNext();
|
||||
|
||||
if (isEndElement())
|
||||
break;
|
||||
|
||||
if (isStartElement())
|
||||
readUnknownElement();
|
||||
}
|
||||
}
|
||||
|
||||
void XbelReader::readFolder(QStandardItem *item)
|
||||
{
|
||||
QStandardItem *folder = createChildItem(item);
|
||||
folder->setIcon(folderIcon);
|
||||
folder->setData(QLatin1String("Folder"), Qt::UserRole + 10);
|
||||
|
||||
bool expanded =
|
||||
(attributes().value(QLatin1String("folded")) != QLatin1String("no"));
|
||||
folder->setData(expanded, Qt::UserRole + 11);
|
||||
|
||||
while (!atEnd()) {
|
||||
readNext();
|
||||
|
||||
if (isEndElement())
|
||||
break;
|
||||
|
||||
if (isStartElement()) {
|
||||
if (name() == QLatin1String("title"))
|
||||
folder->setText(readElementText());
|
||||
else if (name() == QLatin1String("folder"))
|
||||
readFolder(folder);
|
||||
else if (name() == QLatin1String("bookmark"))
|
||||
readBookmark(folder);
|
||||
else
|
||||
readUnknownElement();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void XbelReader::readBookmark(QStandardItem *item)
|
||||
{
|
||||
QStandardItem *bookmark = createChildItem(item);
|
||||
bookmark->setIcon(bookmarkIcon);
|
||||
bookmark->setText(QObject::tr("Unknown title"));
|
||||
bookmark->setData(attributes().value(QLatin1String("href")).toString(),
|
||||
Qt::UserRole + 10);
|
||||
|
||||
while (!atEnd()) {
|
||||
readNext();
|
||||
|
||||
if (isEndElement())
|
||||
break;
|
||||
|
||||
if (isStartElement()) {
|
||||
if (name() == QLatin1String("title"))
|
||||
bookmark->setText(readElementText());
|
||||
else
|
||||
readUnknownElement();
|
||||
}
|
||||
}
|
||||
|
||||
listModel->appendRow(bookmark->clone());
|
||||
}
|
||||
|
||||
QStandardItem *XbelReader::createChildItem(QStandardItem *item)
|
||||
{
|
||||
QStandardItem *childItem = new QStandardItem();
|
||||
childItem->setEditable(false);
|
||||
|
||||
if (item)
|
||||
item->appendRow(childItem);
|
||||
else
|
||||
treeModel->appendRow(childItem);
|
||||
|
||||
return childItem;
|
||||
}
|
||||
81
src/plugins/help/xbelsupport.h
Normal file
81
src/plugins/help/xbelsupport.h
Normal file
@@ -0,0 +1,81 @@
|
||||
/**************************************************************************
|
||||
**
|
||||
** This file is part of Qt Creator
|
||||
**
|
||||
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
||||
**
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** Commercial Usage
|
||||
**
|
||||
** Licensees holding valid Qt Commercial licenses may use this file in
|
||||
** accordance with the Qt Commercial License Agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and Nokia.
|
||||
**
|
||||
** GNU Lesser General Public License Usage
|
||||
**
|
||||
** Alternatively, this file may be used under the terms of the GNU Lesser
|
||||
** General Public License version 2.1 as published by the Free Software
|
||||
** Foundation and appearing in the file LICENSE.LGPL included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU Lesser General Public License version 2.1 requirements
|
||||
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, please
|
||||
** contact the sales department at http://www.qtsoftware.com/contact.
|
||||
**
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef XBELSUPPORT_H
|
||||
#define XBELSUPPORT_H
|
||||
|
||||
#include <QtGui/QIcon>
|
||||
#include <QtXml/QXmlStreamReader>
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QIODevice)
|
||||
QT_FORWARD_DECLARE_CLASS(QStandardItem)
|
||||
|
||||
class BookmarkModel;
|
||||
|
||||
namespace Help {
|
||||
namespace Internal {
|
||||
|
||||
class XbelWriter : public QXmlStreamWriter
|
||||
{
|
||||
public:
|
||||
XbelWriter(BookmarkModel *model);
|
||||
void writeToFile(QIODevice *device);
|
||||
|
||||
private:
|
||||
void writeData(QStandardItem *item);
|
||||
|
||||
private:
|
||||
BookmarkModel *treeModel;
|
||||
};
|
||||
|
||||
class XbelReader : public QXmlStreamReader
|
||||
{
|
||||
public:
|
||||
XbelReader(BookmarkModel *tree, BookmarkModel *list);
|
||||
bool readFromFile(QIODevice *device);
|
||||
|
||||
private:
|
||||
void readXBEL();
|
||||
void readUnknownElement();
|
||||
void readFolder(QStandardItem *item);
|
||||
void readBookmark(QStandardItem *item);
|
||||
QStandardItem* createChildItem(QStandardItem *item);
|
||||
|
||||
private:
|
||||
QIcon folderIcon;
|
||||
QIcon bookmarkIcon;
|
||||
|
||||
BookmarkModel *treeModel;
|
||||
BookmarkModel *listModel;
|
||||
};
|
||||
|
||||
} // Internal
|
||||
} // Help
|
||||
|
||||
#endif // XBELSUPPORT_H
|
||||
Reference in New Issue
Block a user