2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** 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.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "docsettingspage.h"
|
2009-11-27 16:12:12 +01:00
|
|
|
#include "helpconstants.h"
|
2010-06-11 13:11:37 +02:00
|
|
|
|
|
|
|
|
#include <coreplugin/helpmanager.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QCoreApplication>
|
2010-03-02 16:48:49 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QFileDialog>
|
|
|
|
|
#include <QKeyEvent>
|
|
|
|
|
#include <QMessageBox>
|
2010-03-02 16:48:49 +01:00
|
|
|
|
2013-08-29 19:00:34 +02:00
|
|
|
using namespace Core;
|
2008-12-02 12:01:29 +01:00
|
|
|
using namespace Help::Internal;
|
2009-01-13 15:41:33 +01:00
|
|
|
|
2010-03-16 15:48:09 +01:00
|
|
|
DocSettingsPage::DocSettingsPage()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2013-01-16 15:22:58 +01:00
|
|
|
setId("B.Documentation");
|
2012-05-22 11:17:13 +02:00
|
|
|
setDisplayName(tr("Documentation"));
|
2012-12-29 03:37:27 +01:00
|
|
|
setCategory(Help::Constants::HELP_CATEGORY);
|
2012-05-22 11:17:13 +02:00
|
|
|
setDisplayCategory(QCoreApplication::translate("Help", Help::Constants::HELP_TR_CATEGORY));
|
|
|
|
|
setCategoryIcon(QLatin1String(Help::Constants::HELP_CATEGORY_ICON));
|
2010-03-26 17:34:10 +01:00
|
|
|
}
|
|
|
|
|
|
2013-12-03 14:17:03 +01:00
|
|
|
QWidget *DocSettingsPage::widget()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2013-12-03 14:17:03 +01:00
|
|
|
if (!m_widget) {
|
|
|
|
|
m_widget = new QWidget;
|
|
|
|
|
m_ui.setupUi(m_widget);
|
2009-01-13 15:41:33 +01:00
|
|
|
|
2013-12-03 14:17:03 +01:00
|
|
|
connect(m_ui.addButton, SIGNAL(clicked()), this, SLOT(addDocumentation()));
|
|
|
|
|
connect(m_ui.removeButton, SIGNAL(clicked()), this, SLOT(removeDocumentation()));
|
2009-01-13 15:41:33 +01:00
|
|
|
|
2013-12-03 14:17:03 +01:00
|
|
|
m_ui.docsListWidget->installEventFilter(this);
|
2010-03-16 15:48:09 +01:00
|
|
|
|
2013-12-03 14:17:03 +01:00
|
|
|
const QStringList nameSpaces = HelpManager::registeredNamespaces();
|
|
|
|
|
foreach (const QString &nameSpace, nameSpaces) {
|
|
|
|
|
addItem(nameSpace, HelpManager::fileFromNamespace(nameSpace));
|
|
|
|
|
m_filesToRegister.insert(nameSpace, HelpManager::fileFromNamespace(nameSpace));
|
|
|
|
|
}
|
2010-03-16 15:48:09 +01:00
|
|
|
|
2013-12-03 14:17:03 +01:00
|
|
|
m_filesToUnregister.clear();
|
|
|
|
|
}
|
|
|
|
|
return m_widget;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DocSettingsPage::addDocumentation()
|
|
|
|
|
{
|
2010-03-16 15:48:09 +01:00
|
|
|
const QStringList &files =
|
|
|
|
|
QFileDialog::getOpenFileNames(m_ui.addButton->parentWidget(),
|
|
|
|
|
tr("Add Documentation"), m_recentDialogPath, tr("Qt Help Files (*.qch)"));
|
2009-01-13 15:41:33 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
if (files.isEmpty())
|
|
|
|
|
return;
|
2010-03-16 15:48:09 +01:00
|
|
|
m_recentDialogPath = QFileInfo(files.first()).canonicalPath();
|
|
|
|
|
|
2012-05-25 16:32:37 +02:00
|
|
|
NameSpaceToPathHash docsUnableToRegister;
|
2008-12-02 12:01:29 +01:00
|
|
|
foreach (const QString &file, files) {
|
2012-05-25 16:32:37 +02:00
|
|
|
const QString filePath = QDir::cleanPath(file);
|
2013-08-29 19:00:34 +02:00
|
|
|
const QString &nameSpace = HelpManager::namespaceFromFile(filePath);
|
2012-05-25 16:32:37 +02:00
|
|
|
if (nameSpace.isEmpty()) {
|
|
|
|
|
docsUnableToRegister.insertMulti(QLatin1String("UnknownNamespace"),
|
|
|
|
|
QDir::toNativeSeparators(filePath));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_filesToRegister.contains(nameSpace)) {
|
|
|
|
|
docsUnableToRegister.insert(nameSpace, QDir::toNativeSeparators(filePath));
|
2008-12-02 12:01:29 +01:00
|
|
|
continue;
|
2012-05-25 16:32:37 +02:00
|
|
|
}
|
2010-03-16 15:48:09 +01:00
|
|
|
|
2012-05-25 16:32:37 +02:00
|
|
|
addItem(nameSpace, file);
|
|
|
|
|
m_filesToRegister.insert(nameSpace, QDir::toNativeSeparators(filePath));
|
|
|
|
|
|
|
|
|
|
// If the files to unregister contains the namespace, grab a copy of all paths added and try to
|
|
|
|
|
// remove the current file path. Afterwards remove the whole entry and add the clean list back.
|
|
|
|
|
// Possible outcome:
|
|
|
|
|
// - might not add the entry back at all if we register the same file again
|
|
|
|
|
// - might add the entry back with paths to other files with the same namespace
|
|
|
|
|
// The reason to do this is, if we remove a file with a given namespace/ path and re-add another
|
|
|
|
|
// file with the same namespace but a different path, we need to unregister the namespace before
|
|
|
|
|
// we can register the new one. Help engine allows just one registered namespace.
|
|
|
|
|
if (m_filesToUnregister.contains(nameSpace)) {
|
|
|
|
|
QSet<QString> values = m_filesToUnregister.values(nameSpace).toSet();
|
|
|
|
|
values.remove(filePath);
|
2010-03-16 15:48:09 +01:00
|
|
|
m_filesToUnregister.remove(nameSpace);
|
2012-05-25 16:32:37 +02:00
|
|
|
foreach (const QString &value, values)
|
|
|
|
|
m_filesToUnregister.insertMulti(nameSpace, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString formatedFail;
|
|
|
|
|
if (docsUnableToRegister.contains(QLatin1String("UnknownNamespace"))) {
|
|
|
|
|
formatedFail += QString::fromLatin1("<ul><li><b>%1</b>").arg(tr("Invalid documentation file:"));
|
|
|
|
|
foreach (const QString &value, docsUnableToRegister.values(QLatin1String("UnknownNamespace")))
|
|
|
|
|
formatedFail += QString::fromLatin1("<ul><li>%2</li></ul>").arg(value);
|
|
|
|
|
formatedFail += QLatin1String("</li></ul>");
|
|
|
|
|
docsUnableToRegister.remove(QLatin1String("UnknownNamespace"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!docsUnableToRegister.isEmpty()) {
|
|
|
|
|
formatedFail += QString::fromLatin1("<ul><li><b>%1</b>").arg(tr("Namespace already registered:"));
|
2013-03-14 14:19:23 +01:00
|
|
|
const NameSpaceToPathHash::ConstIterator cend = docsUnableToRegister.constEnd();
|
|
|
|
|
for (NameSpaceToPathHash::ConstIterator it = docsUnableToRegister.constBegin(); it != cend; ++it) {
|
|
|
|
|
formatedFail += QString::fromLatin1("<ul><li>%1 - %2</li></ul>").arg(it.key(), it.value());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2012-05-25 16:32:37 +02:00
|
|
|
formatedFail += QLatin1String("</li></ul>");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!formatedFail.isEmpty()) {
|
|
|
|
|
QMessageBox::information(m_ui.addButton->parentWidget(), tr("Registration failed"),
|
|
|
|
|
tr("Unable to register documentation.") + formatedFail, QMessageBox::Ok);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DocSettingsPage::removeDocumentation()
|
|
|
|
|
{
|
2010-03-02 16:48:49 +01:00
|
|
|
removeDocumentation(m_ui.docsListWidget->selectedItems());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-01-13 15:41:33 +01:00
|
|
|
void DocSettingsPage::apply()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2013-08-29 19:00:34 +02:00
|
|
|
HelpManager::unregisterDocumentation(m_filesToUnregister.keys());
|
|
|
|
|
HelpManager::registerDocumentation(m_filesToRegister.values());
|
2010-03-16 15:48:09 +01:00
|
|
|
|
|
|
|
|
m_filesToUnregister.clear();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2013-12-03 14:17:03 +01:00
|
|
|
void DocSettingsPage::finish()
|
2009-11-24 15:05:02 +01:00
|
|
|
{
|
2013-12-03 14:17:03 +01:00
|
|
|
delete m_widget;
|
2009-11-24 15:05:02 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-02 16:48:49 +01:00
|
|
|
bool DocSettingsPage::eventFilter(QObject *object, QEvent *event)
|
|
|
|
|
{
|
|
|
|
|
if (object != m_ui.docsListWidget)
|
2013-08-29 19:00:34 +02:00
|
|
|
return IOptionsPage::eventFilter(object, event);
|
2010-03-02 16:48:49 +01:00
|
|
|
|
|
|
|
|
if (event->type() == QEvent::KeyPress) {
|
|
|
|
|
QKeyEvent *ke = static_cast<QKeyEvent*>(event);
|
|
|
|
|
switch (ke->key()) {
|
|
|
|
|
case Qt::Key_Delete:
|
|
|
|
|
removeDocumentation(m_ui.docsListWidget->selectedItems());
|
|
|
|
|
break;
|
|
|
|
|
default: break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-29 19:00:34 +02:00
|
|
|
return IOptionsPage::eventFilter(object, event);
|
2010-03-02 16:48:49 +01:00
|
|
|
}
|
|
|
|
|
|
2014-05-19 18:33:47 +03:00
|
|
|
void DocSettingsPage::removeDocumentation(const QList<QListWidgetItem*> &items)
|
2010-03-02 16:48:49 +01:00
|
|
|
{
|
|
|
|
|
if (items.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
int row = 0;
|
|
|
|
|
foreach (QListWidgetItem* item, items) {
|
2012-05-25 16:32:37 +02:00
|
|
|
const QString nameSpace = item->text();
|
|
|
|
|
|
|
|
|
|
m_filesToRegister.remove(nameSpace);
|
2013-08-29 19:00:34 +02:00
|
|
|
m_filesToUnregister.insertMulti(nameSpace, QDir::cleanPath(HelpManager::fileFromNamespace(nameSpace)));
|
2010-03-16 15:48:09 +01:00
|
|
|
|
2010-03-02 16:48:49 +01:00
|
|
|
row = m_ui.docsListWidget->row(item);
|
|
|
|
|
delete m_ui.docsListWidget->takeItem(row);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_ui.docsListWidget->setCurrentRow(qMax(row - 1, 0),
|
|
|
|
|
QItemSelectionModel::ClearAndSelect);
|
|
|
|
|
}
|
2010-03-16 15:48:09 +01:00
|
|
|
|
|
|
|
|
void DocSettingsPage::addItem(const QString &nameSpace, const QString &fileName)
|
|
|
|
|
{
|
|
|
|
|
QListWidgetItem* item = new QListWidgetItem(nameSpace);
|
|
|
|
|
item->setToolTip(fileName);
|
|
|
|
|
m_ui.docsListWidget->addItem(item);
|
|
|
|
|
}
|