2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2012-01-26 18:33:46 +01:00
|
|
|
** Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2011-11-02 15:59:12 +01:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** 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.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-11-02 15:59:12 +01:00
|
|
|
** Nokia at qt-info@nokia.com.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01: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
|
|
|
|
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
|
|
|
{
|
2012-05-22 11:17:13 +02:00
|
|
|
setId(QLatin1String("B.Documentation"));
|
|
|
|
|
setDisplayName(tr("Documentation"));
|
|
|
|
|
setCategory(QLatin1String(Help::Constants::HELP_CATEGORY));
|
|
|
|
|
setDisplayCategory(QCoreApplication::translate("Help", Help::Constants::HELP_TR_CATEGORY));
|
|
|
|
|
setCategoryIcon(QLatin1String(Help::Constants::HELP_CATEGORY_ICON));
|
2010-03-26 17:34:10 +01:00
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
QWidget *DocSettingsPage::createPage(QWidget *parent)
|
|
|
|
|
{
|
2010-03-16 15:48:09 +01:00
|
|
|
QWidget *widget = new QWidget(parent);
|
|
|
|
|
m_ui.setupUi(widget);
|
2009-01-13 15:41:33 +01:00
|
|
|
|
2010-03-16 15:48:09 +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
|
|
|
|
2010-03-02 16:48:49 +01:00
|
|
|
m_ui.docsListWidget->installEventFilter(this);
|
2010-03-16 15:48:09 +01:00
|
|
|
|
2010-06-11 13:11:37 +02:00
|
|
|
Core::HelpManager *manager = Core::HelpManager::instance();
|
|
|
|
|
const QStringList &nameSpaces = manager->registeredNamespaces();
|
2010-03-16 15:48:09 +01:00
|
|
|
foreach (const QString &nameSpace, nameSpaces)
|
2010-06-11 13:11:37 +02:00
|
|
|
addItem(nameSpace, manager->fileFromNamespace(nameSpace));
|
2010-03-16 15:48:09 +01:00
|
|
|
|
|
|
|
|
m_filesToRegister.clear();
|
|
|
|
|
m_filesToUnregister.clear();
|
|
|
|
|
|
2009-11-24 15:05:02 +01:00
|
|
|
if (m_searchKeywords.isEmpty())
|
|
|
|
|
m_searchKeywords = m_ui.groupBox->title();
|
2010-03-16 15:48:09 +01:00
|
|
|
return 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();
|
|
|
|
|
|
2010-06-11 13:11:37 +02:00
|
|
|
Core::HelpManager *manager = Core::HelpManager::instance();
|
|
|
|
|
const QStringList &nameSpaces = manager->registeredNamespaces();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
foreach (const QString &file, files) {
|
2010-06-11 13:11:37 +02:00
|
|
|
const QString &nameSpace = manager->namespaceFromFile(file);
|
2010-03-16 15:48:09 +01:00
|
|
|
if (nameSpace.isEmpty())
|
2008-12-02 12:01:29 +01:00
|
|
|
continue;
|
2010-03-16 15:48:09 +01:00
|
|
|
|
|
|
|
|
if (m_filesToUnregister.value(nameSpace) != QDir::cleanPath(file)) {
|
|
|
|
|
if (!m_filesToRegister.contains(nameSpace) && !nameSpaces.contains(nameSpace)) {
|
|
|
|
|
addItem(nameSpace, file);
|
|
|
|
|
m_filesToRegister.insert(nameSpace, QDir::cleanPath(file));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
addItem(nameSpace, file);
|
|
|
|
|
m_filesToUnregister.remove(nameSpace);
|
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
|
|
|
{
|
2010-06-11 13:11:37 +02:00
|
|
|
Core::HelpManager *manager = Core::HelpManager::instance();
|
|
|
|
|
|
2010-03-23 18:11:43 +01:00
|
|
|
manager->unregisterDocumentation(m_filesToUnregister.keys());
|
|
|
|
|
manager->registerDocumentation(m_filesToRegister.values());
|
2010-03-16 15:48:09 +01:00
|
|
|
|
|
|
|
|
m_filesToRegister.clear();
|
|
|
|
|
m_filesToUnregister.clear();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-11-24 15:05:02 +01:00
|
|
|
bool DocSettingsPage::matches(const QString &s) const
|
|
|
|
|
{
|
|
|
|
|
return m_searchKeywords.contains(s, Qt::CaseInsensitive);
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-02 16:48:49 +01:00
|
|
|
bool DocSettingsPage::eventFilter(QObject *object, QEvent *event)
|
|
|
|
|
{
|
|
|
|
|
if (object != m_ui.docsListWidget)
|
|
|
|
|
return Core::IOptionsPage::eventFilter(object, event);
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Core::IOptionsPage::eventFilter(object, event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DocSettingsPage::removeDocumentation(const QList<QListWidgetItem*> items)
|
|
|
|
|
{
|
|
|
|
|
if (items.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
int row = 0;
|
2010-06-11 13:11:37 +02:00
|
|
|
Core::HelpManager *manager = Core::HelpManager::instance();
|
2010-03-02 16:48:49 +01:00
|
|
|
foreach (QListWidgetItem* item, items) {
|
2010-03-16 15:48:09 +01:00
|
|
|
const QString &nameSpace = item->text();
|
2010-06-11 13:11:37 +02:00
|
|
|
const QString &docPath = manager->fileFromNamespace(nameSpace);
|
2010-03-16 15:48:09 +01:00
|
|
|
|
|
|
|
|
if (m_filesToRegister.value(nameSpace) != docPath) {
|
|
|
|
|
if (!m_filesToUnregister.contains(nameSpace))
|
|
|
|
|
m_filesToUnregister.insert(nameSpace, docPath);
|
|
|
|
|
} else {
|
|
|
|
|
m_filesToRegister.remove(nameSpace);
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
}
|