2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-06-17 00:01:27 +10:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Commercial Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** 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.
|
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
|
|
|
**
|
2009-02-25 09:15:00 +01: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.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** If you are unsure which license is appropriate for your use, please
|
2009-08-14 09:30:56 +02:00
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
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 "settingspage.h"
|
2009-03-18 16:43:01 +01:00
|
|
|
#include "quickopenconstants.h"
|
2008-12-09 15:25:01 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "quickopenplugin.h"
|
2009-10-15 15:24:21 +02:00
|
|
|
#include "ilocatorfilter.h"
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "directoryfilter.h"
|
|
|
|
|
|
|
|
|
|
#include <qtconcurrent/QtConcurrentTools>
|
2008-12-09 15:25:01 +01:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2009-03-18 16:43:01 +01:00
|
|
|
#include <QtCore/QCoreApplication>
|
|
|
|
|
|
2009-10-15 15:24:21 +02:00
|
|
|
Q_DECLARE_METATYPE(QuickOpen::ILocatorFilter*)
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
using namespace QuickOpen;
|
|
|
|
|
using namespace QuickOpen::Internal;
|
|
|
|
|
|
2009-01-20 17:14:00 +01:00
|
|
|
SettingsPage::SettingsPage(QuickOpenPlugin *plugin)
|
|
|
|
|
: m_plugin(plugin), m_page(0)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-18 16:43:01 +01:00
|
|
|
QString SettingsPage::id() const
|
|
|
|
|
{
|
|
|
|
|
return QLatin1String(Constants::FILTER_OPTIONS_PAGE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString SettingsPage::trName() const
|
|
|
|
|
{
|
|
|
|
|
return QCoreApplication::translate("Locator", QuickOpen::Constants::FILTER_OPTIONS_PAGE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString SettingsPage::category() const
|
|
|
|
|
{
|
|
|
|
|
return Constants::QUICKOPEN_CATEGORY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString SettingsPage::trCategory() const
|
|
|
|
|
{
|
|
|
|
|
return QCoreApplication::translate("Locator", QuickOpen::Constants::QUICKOPEN_CATEGORY);
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
QWidget *SettingsPage::createPage(QWidget *parent)
|
|
|
|
|
{
|
2009-05-05 15:42:52 +02:00
|
|
|
|
|
|
|
|
m_page = new QWidget(parent);
|
|
|
|
|
m_ui.setupUi(m_page);
|
|
|
|
|
connect(m_ui.filterList, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)),
|
|
|
|
|
this, SLOT(updateButtonStates()));
|
|
|
|
|
connect(m_ui.filterList, SIGNAL(itemActivated(QListWidgetItem *)),
|
|
|
|
|
this, SLOT(configureFilter(QListWidgetItem *)));
|
|
|
|
|
connect(m_ui.editButton, SIGNAL(clicked()),
|
|
|
|
|
this, SLOT(configureFilter()));
|
|
|
|
|
connect(m_ui.addButton, SIGNAL(clicked()),
|
|
|
|
|
this, SLOT(addCustomFilter()));
|
|
|
|
|
connect(m_ui.removeButton, SIGNAL(clicked()),
|
|
|
|
|
this, SLOT(removeCustomFilter()));
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
m_ui.refreshInterval->setValue(m_plugin->refreshInterval());
|
2009-01-13 15:41:33 +01:00
|
|
|
m_filters = m_plugin->filters();
|
|
|
|
|
m_customFilters = m_plugin->customFilters();
|
2008-12-02 12:01:29 +01:00
|
|
|
saveFilterStates();
|
|
|
|
|
updateFilterList();
|
|
|
|
|
return m_page;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-13 15:41:33 +01:00
|
|
|
void SettingsPage::apply()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-01-13 15:41:33 +01:00
|
|
|
// Delete removed filters and clear added filters
|
|
|
|
|
qDeleteAll(m_removedFilters);
|
|
|
|
|
m_removedFilters.clear();
|
|
|
|
|
m_addedFilters.clear();
|
|
|
|
|
|
|
|
|
|
// Pass the new configuration on to the plugin
|
|
|
|
|
m_plugin->setFilters(m_filters);
|
|
|
|
|
m_plugin->setCustomFilters(m_customFilters);
|
|
|
|
|
m_plugin->setRefreshInterval(m_ui.refreshInterval->value());
|
|
|
|
|
requestRefresh();
|
|
|
|
|
m_plugin->saveSettings();
|
|
|
|
|
saveFilterStates();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SettingsPage::finish()
|
|
|
|
|
{
|
|
|
|
|
// If settings were applied, this shouldn't change anything. Otherwise it
|
|
|
|
|
// makes sure the filter states aren't changed permanently.
|
|
|
|
|
restoreFilterStates();
|
|
|
|
|
|
|
|
|
|
// Delete added filters and clear removed filters
|
|
|
|
|
qDeleteAll(m_addedFilters);
|
2008-12-02 12:01:29 +01:00
|
|
|
m_addedFilters.clear();
|
|
|
|
|
m_removedFilters.clear();
|
2009-01-13 15:41:33 +01:00
|
|
|
|
|
|
|
|
// Further cleanup
|
2008-12-02 12:01:29 +01:00
|
|
|
m_filters.clear();
|
|
|
|
|
m_customFilters.clear();
|
|
|
|
|
m_refreshFilters.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SettingsPage::requestRefresh()
|
|
|
|
|
{
|
|
|
|
|
if (!m_refreshFilters.isEmpty())
|
|
|
|
|
m_plugin->refresh(m_refreshFilters);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SettingsPage::saveFilterStates()
|
|
|
|
|
{
|
|
|
|
|
m_filterStates.clear();
|
2009-10-15 15:24:21 +02:00
|
|
|
foreach (ILocatorFilter *filter, m_filters)
|
2008-12-02 12:01:29 +01:00
|
|
|
m_filterStates.insert(filter, filter->saveState());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SettingsPage::restoreFilterStates()
|
|
|
|
|
{
|
2009-10-15 15:24:21 +02:00
|
|
|
foreach (ILocatorFilter *filter, m_filterStates.keys())
|
2008-12-02 12:01:29 +01:00
|
|
|
filter->restoreState(m_filterStates.value(filter));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SettingsPage::updateFilterList()
|
|
|
|
|
{
|
|
|
|
|
m_ui.filterList->clear();
|
2009-10-15 15:24:21 +02:00
|
|
|
foreach (ILocatorFilter *filter, m_filters) {
|
2008-12-12 11:52:04 +01:00
|
|
|
if (filter->isHidden())
|
|
|
|
|
continue;
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
QString title;
|
2008-12-12 11:52:04 +01:00
|
|
|
if (filter->isIncludedByDefault())
|
2008-12-02 12:01:29 +01:00
|
|
|
title = filter->trName();
|
|
|
|
|
else
|
|
|
|
|
title = tr("%1 (Prefix: %2)").arg(filter->trName()).arg(filter->shortcutString());
|
|
|
|
|
QListWidgetItem *item = new QListWidgetItem(title);
|
|
|
|
|
item->setData(Qt::UserRole, qVariantFromValue(filter));
|
|
|
|
|
m_ui.filterList->addItem(item);
|
|
|
|
|
}
|
|
|
|
|
if (m_ui.filterList->count() > 0)
|
|
|
|
|
m_ui.filterList->setCurrentRow(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SettingsPage::updateButtonStates()
|
|
|
|
|
{
|
|
|
|
|
QListWidgetItem *item = m_ui.filterList->currentItem();
|
2009-10-15 15:24:21 +02:00
|
|
|
ILocatorFilter *filter = (item ? item->data(Qt::UserRole).value<ILocatorFilter *>() : 0);
|
2008-12-02 12:01:29 +01:00
|
|
|
m_ui.editButton->setEnabled(filter && filter->isConfigurable());
|
|
|
|
|
m_ui.removeButton->setEnabled(filter && m_customFilters.contains(filter));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SettingsPage::configureFilter(QListWidgetItem *item)
|
|
|
|
|
{
|
|
|
|
|
if (!item)
|
|
|
|
|
item = m_ui.filterList->currentItem();
|
2008-12-09 15:25:01 +01:00
|
|
|
QTC_ASSERT(item, return);
|
2009-10-15 15:24:21 +02:00
|
|
|
ILocatorFilter *filter = item->data(Qt::UserRole).value<ILocatorFilter *>();
|
2008-12-09 15:25:01 +01:00
|
|
|
QTC_ASSERT(filter, return);
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
if (!filter->isConfigurable())
|
|
|
|
|
return;
|
|
|
|
|
bool needsRefresh = false;
|
|
|
|
|
filter->openConfigDialog(m_page, needsRefresh);
|
|
|
|
|
if (needsRefresh && !m_refreshFilters.contains(filter))
|
|
|
|
|
m_refreshFilters.append(filter);
|
|
|
|
|
updateFilterList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SettingsPage::addCustomFilter()
|
|
|
|
|
{
|
2009-10-15 15:24:21 +02:00
|
|
|
ILocatorFilter *filter = new DirectoryFilter;
|
2008-12-02 12:01:29 +01:00
|
|
|
bool needsRefresh = false;
|
|
|
|
|
if (filter->openConfigDialog(m_page, needsRefresh)) {
|
|
|
|
|
m_filters.append(filter);
|
|
|
|
|
m_addedFilters.append(filter);
|
|
|
|
|
m_customFilters.append(filter);
|
|
|
|
|
m_refreshFilters.append(filter);
|
|
|
|
|
updateFilterList();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SettingsPage::removeCustomFilter()
|
|
|
|
|
{
|
|
|
|
|
QListWidgetItem *item = m_ui.filterList->currentItem();
|
2008-12-09 15:25:01 +01:00
|
|
|
QTC_ASSERT(item, return);
|
2009-10-15 15:24:21 +02:00
|
|
|
ILocatorFilter *filter = item->data(Qt::UserRole).value<ILocatorFilter *>();
|
2008-12-09 15:25:01 +01:00
|
|
|
QTC_ASSERT(m_customFilters.contains(filter), return);
|
2008-12-02 12:01:29 +01:00
|
|
|
m_filters.removeAll(filter);
|
|
|
|
|
m_customFilters.removeAll(filter);
|
|
|
|
|
m_refreshFilters.removeAll(filter);
|
|
|
|
|
if (m_addedFilters.contains(filter)) {
|
|
|
|
|
m_addedFilters.removeAll(filter);
|
|
|
|
|
delete filter;
|
|
|
|
|
} else {
|
|
|
|
|
m_removedFilters.append(filter);
|
|
|
|
|
}
|
|
|
|
|
updateFilterList();
|
|
|
|
|
}
|