2008-12-02 12:01:29 +01:00
|
|
|
/***************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
|
|
|
|
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
|
|
|
|
|
**
|
|
|
|
|
** Contact: Qt Software Information (qt-info@nokia.com)
|
|
|
|
|
**
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
|
|
|
|
** Non-Open Source Usage
|
|
|
|
|
**
|
2008-12-02 12:01:29 +01:00
|
|
|
** Licensees may use this file in accordance with the Qt Beta Version
|
|
|
|
|
** License Agreement, Agreement version 2.2 provided with the Software or,
|
|
|
|
|
** alternatively, in accordance with the terms contained in a written
|
2008-12-02 14:17:16 +01:00
|
|
|
** agreement between you and Nokia.
|
|
|
|
|
**
|
|
|
|
|
** GNU General Public License Usage
|
|
|
|
|
**
|
2008-12-02 12:01:29 +01:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU General
|
|
|
|
|
** Public License versions 2.0 or 3.0 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.GPL included in the packaging
|
|
|
|
|
** of this file. Please review the following information to ensure GNU
|
|
|
|
|
** General Public Licensing requirements will be met:
|
|
|
|
|
**
|
|
|
|
|
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
|
|
|
|
|
** http://www.gnu.org/copyleft/gpl.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2008-12-02 14:17:16 +01:00
|
|
|
** rights. These rights are described in the Nokia Qt GPL Exception
|
|
|
|
|
** version 1.2, included in the file GPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
***************************************************************************/
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "settingspage.h"
|
2008-12-09 15:25:01 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "quickopenplugin.h"
|
|
|
|
|
#include "iquickopenfilter.h"
|
|
|
|
|
#include "directoryfilter.h"
|
|
|
|
|
|
|
|
|
|
#include <qtconcurrent/QtConcurrentTools>
|
2008-12-09 15:25:01 +01:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
|
|
|
|
#include <QtGui/QMessageBox>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(QuickOpen::IQuickOpenFilter*)
|
|
|
|
|
|
|
|
|
|
using namespace QuickOpen;
|
|
|
|
|
using namespace QuickOpen::Internal;
|
|
|
|
|
|
|
|
|
|
SettingsPage::SettingsPage(Core::ICore *core, QuickOpenPlugin *plugin)
|
2008-12-09 15:25:01 +01:00
|
|
|
: m_core(core), m_plugin(plugin), m_page(0)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget *SettingsPage::createPage(QWidget *parent)
|
|
|
|
|
{
|
|
|
|
|
if (!m_page) {
|
|
|
|
|
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()));
|
|
|
|
|
}
|
|
|
|
|
m_ui.refreshInterval->setValue(m_plugin->refreshInterval());
|
|
|
|
|
m_filters = m_plugin->filter();
|
|
|
|
|
m_customFilters = m_plugin->customFilter();
|
|
|
|
|
saveFilterStates();
|
|
|
|
|
updateFilterList();
|
|
|
|
|
return m_page;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SettingsPage::finished(bool accepted)
|
|
|
|
|
{
|
|
|
|
|
if (!accepted) {
|
|
|
|
|
restoreFilterStates();
|
|
|
|
|
foreach (IQuickOpenFilter *filter, m_addedFilters)
|
|
|
|
|
delete filter;
|
|
|
|
|
} else {
|
|
|
|
|
foreach (IQuickOpenFilter *filter, m_removedFilters)
|
|
|
|
|
delete filter;
|
|
|
|
|
m_plugin->setFilter(m_filters);
|
|
|
|
|
m_plugin->setCustomFilter(m_customFilters);
|
|
|
|
|
m_plugin->setRefreshInterval(m_ui.refreshInterval->value());
|
|
|
|
|
requestRefresh();
|
|
|
|
|
m_plugin->saveSettings();
|
|
|
|
|
}
|
|
|
|
|
m_addedFilters.clear();
|
|
|
|
|
m_removedFilters.clear();
|
|
|
|
|
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();
|
|
|
|
|
foreach (IQuickOpenFilter *filter, m_filters)
|
|
|
|
|
m_filterStates.insert(filter, filter->saveState());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SettingsPage::restoreFilterStates()
|
|
|
|
|
{
|
|
|
|
|
foreach (IQuickOpenFilter *filter, m_filterStates.keys())
|
|
|
|
|
filter->restoreState(m_filterStates.value(filter));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void SettingsPage::updateFilterList()
|
|
|
|
|
{
|
|
|
|
|
m_ui.filterList->clear();
|
|
|
|
|
foreach (IQuickOpenFilter *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();
|
|
|
|
|
IQuickOpenFilter *filter = (item ? item->data(Qt::UserRole).value<IQuickOpenFilter *>() : 0);
|
|
|
|
|
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);
|
2008-12-02 12:01:29 +01:00
|
|
|
IQuickOpenFilter *filter = item->data(Qt::UserRole).value<IQuickOpenFilter *>();
|
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()
|
|
|
|
|
{
|
|
|
|
|
IQuickOpenFilter *filter = new DirectoryFilter(m_core);
|
|
|
|
|
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);
|
2008-12-02 12:01:29 +01:00
|
|
|
IQuickOpenFilter *filter = item->data(Qt::UserRole).value<IQuickOpenFilter *>();
|
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();
|
|
|
|
|
}
|