locatorplugin.h 3.7 KB
Newer Older
1
/**************************************************************************
con's avatar
con committed
2
3
4
**
** This file is part of Qt Creator
**
5
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
con's avatar
con committed
6
**
7
** Contact: Nokia Corporation (qt-info@nokia.com)
con's avatar
con committed
8
**
9
** Commercial Usage
10
**
11
12
13
14
** 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.
15
**
16
** GNU Lesser General Public License Usage
17
**
18
19
20
21
22
23
** 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.
24
**
25
** If you are unsure which license is appropriate for your use, please
hjk's avatar
hjk committed
26
** contact the sales department at http://qt.nokia.com/contact.
con's avatar
con committed
27
**
28
**************************************************************************/
hjk's avatar
hjk committed
29

con's avatar
con committed
30
31
#ifndef LOCATORPLUGIN_H
#define LOCATORPLUGIN_H
con's avatar
con committed
32

33
#include "ilocatorfilter.h"
34
#include "directoryfilter.h"
con's avatar
con committed
35
36
37
38
39
40
41
42
43
44

#include <extensionsystem/iplugin.h>

#include <QtCore/QObject>
#include <QtCore/QTimer>
#include <QtCore/QFutureWatcher>

namespace QuickOpen {
namespace Internal {

45
class LocatorWidget;
con's avatar
con committed
46
47
48
class OpenDocumentsFilter;
class FileSystemFilter;
class SettingsPage;
con's avatar
con committed
49
class LocatorPlugin;
con's avatar
con committed
50

con's avatar
con committed
51
class LocatorPlugin : public ExtensionSystem::IPlugin
con's avatar
con committed
52
53
54
55
{
    Q_OBJECT

public:
con's avatar
con committed
56
57
    LocatorPlugin();
    ~LocatorPlugin();
con's avatar
con committed
58
59
60
61

    bool initialize(const QStringList &arguments, QString *error_message);
    void extensionsInitialized();

62
63
64
65
    QList<ILocatorFilter*> filters();
    QList<ILocatorFilter*> customFilters();
    void setFilters(QList<ILocatorFilter*> f);
    void setCustomFilters(QList<ILocatorFilter*> f);
con's avatar
con committed
66
67
68
69
    int refreshInterval();
    void setRefreshInterval(int interval);

public slots:
70
    void refresh(QList<ILocatorFilter*> filters = QList<ILocatorFilter*>());
con's avatar
con committed
71
    void saveSettings();
con's avatar
con committed
72
    void openLocator();
con's avatar
con committed
73
74
75
76
77
78
79
80

private slots:
    void startSettingsLoad();
    void settingsLoaded();

private:
    void loadSettings();

81
82
83
    template <typename S>
    void loadSettingsHelper(S *settings);

84
    LocatorWidget *m_locatorWidget;
con's avatar
con committed
85
86
    SettingsPage *m_settingsPage;

87
88
    QList<ILocatorFilter*> m_filters;
    QList<ILocatorFilter*> m_customFilters;
con's avatar
con committed
89
90
91
92
93
94
95
    int m_refreshInterval;
    QTimer m_refreshTimer;
    OpenDocumentsFilter *m_openDocumentsFilter;
    FileSystemFilter *m_fileSystemFilter;
    QFutureWatcher<void> m_loadWatcher;
};

96
template <typename S>
con's avatar
con committed
97
void LocatorPlugin::loadSettingsHelper(S *settings)
98
99
100
101
{
    settings->beginGroup("QuickOpen");
    m_refreshTimer.setInterval(settings->value("RefreshInterval", 60).toInt() * 60000);

102
    foreach (ILocatorFilter *filter, m_filters) {
103
104
105
106
107
108
109
        if (settings->contains(filter->name())) {
            const QByteArray state = settings->value(filter->name()).toByteArray();
            if (!state.isEmpty())
                filter->restoreState(state);
        }
    }
    settings->beginGroup("CustomFilters");
110
    QList<ILocatorFilter *> customFilters;
111
112
    const QStringList keys = settings->childKeys();
    foreach (const QString &key, keys) {
113
        ILocatorFilter *filter = new DirectoryFilter;
114
115
116
117
118
119
120
121
122
        filter->restoreState(settings->value(key).toByteArray());
        m_filters.append(filter);
        customFilters.append(filter);
    }
    setCustomFilters(customFilters);
    settings->endGroup();
    settings->endGroup();
}

con's avatar
con committed
123
124
125
} // namespace Internal
} // namespace QuickOpen

con's avatar
con committed
126
#endif // LOCATORPLUGIN_H