1
/* This file is part of Clementine.
2
Copyright 2010, David Sansome <me@davidsansome.com>
4
Clementine is free software: you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation, either version 3 of the License, or
7
(at your option) any later version.
9
Clementine is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
18
#ifndef GLOBALSEARCHWIDGET_H
19
#define GLOBALSEARCHWIDGET_H
21
#include "searchprovider.h"
22
#include "ui/settingsdialog.h"
24
#include <QScopedPointer>
27
#include <boost/bimap.hpp>
30
class GlobalSearchTooltip;
31
class LibraryBackendInterface;
32
class Ui_GlobalSearchWidget;
38
class QSortFilterProxyModel;
39
class QStandardItemModel;
43
class GlobalSearchWidget : public QWidget {
47
GlobalSearchWidget(QWidget* parent = 0);
48
~GlobalSearchWidget();
50
static const int kMinVisibleItems;
51
static const int kMaxVisibleItems;
52
static const int kSwapModelsTimeoutMsec;
53
static const int kSuggestionTimeoutMsec;
54
static const int kSuggestionCount;
57
Role_PrimaryResult = Qt::UserRole + 1,
63
void Init(GlobalSearch* engine_);
65
// Called by the delegate
66
void LazyLoadArt(const QModelIndex& index);
69
bool eventFilter(QObject* o, QEvent* e);
72
void ReloadSettings();
73
void StartSearch(const QString& query);
76
void AddToPlaylist(QMimeData* data);
77
void OpenSettingsAtPage(SettingsDialog::Page page);
80
void resizeEvent(QResizeEvent* e);
81
void paintEvent(QPaintEvent* e);
82
void showEvent(QShowEvent* e);
83
void hideEvent(QHideEvent* e);
86
void TextEdited(const QString& text);
87
void AddResults(int id, const SearchProvider::ResultList& results);
89
void ArtLoaded(int id, const QPixmap& pixmap);
91
void TracksLoaded(int id, MimeData* mime_data);
93
void ResultDoubleClicked();
95
void AddAndPlayCurrent();
96
void AddAndQueueCurrent();
97
void ReplaceCurrent();
98
void ReplaceAndPlayCurrent();
99
void SettingsClicked();
101
void HidePopup(bool manual);
102
void UpdateTooltip();
103
void UpdateTooltipPosition();
107
void NextSuggestion();
110
// Return values from CanCombineResults
112
CannotCombine, // The two results are different and can't be combined
113
LeftPreferred, // The two results can be combined - the left one is better
114
RightPreferred // The two results can be combined - the right one is better
119
CombineCache(QAbstractItemModel* model);
121
QModelIndexList FindCandidates(const QModelIndex& result) const;
122
void Insert(const QModelIndex& index);
123
void Remove(const QModelIndex& index);
126
static uint Hash(const QModelIndex& index);
129
QAbstractItemModel* model_;
130
QMultiMap<uint, int> data_;
133
void RepositionPopup();
134
CombineAction CanCombineResults(const QModelIndex& left, const QModelIndex& right) const;
135
void CombineResults(const QModelIndex& superior, const QModelIndex& inferior);
137
bool EventFilterSearchWidget(QObject* o, QEvent* e);
138
bool EventFilterPopup(QObject* o, QEvent* e);
140
void LoadTracks(QAction* trigger);
143
Ui_GlobalSearchWidget* ui_;
145
GlobalSearch* engine_;
147
int order_arrived_counter_;
148
bool closed_since_search_began_;
150
QMap<int, QModelIndex> art_requests_;
151
QMap<int, QAction*> track_requests_;
153
// Like graphics APIs have a front buffer and a back buffer, there's a front
154
// model and a back model - the front model is the one that's shown in the
155
// UI and the back model is the one that lies in wait. current_model_ will
156
// point to either the front or the back model.
157
QStandardItemModel* front_model_;
158
QStandardItemModel* back_model_;
159
QStandardItemModel* current_model_;
161
QMap<QStandardItemModel*, CombineCache*> combine_cache_;
163
QSortFilterProxyModel* front_proxy_;
164
QSortFilterProxyModel* back_proxy_;
165
QSortFilterProxyModel* current_proxy_;
168
bool consume_focus_out_;
170
QTimer* swap_models_timer_;
173
QPixmap background_scaled_;
175
QDesktopWidget* desktop_;
178
bool combine_identical_results_;
179
QStringList provider_order_;
181
QScopedPointer<GlobalSearchTooltip> tooltip_;
184
QAction* add_and_play_;
185
QAction* add_and_queue_;
187
QAction* replace_and_play_;
188
QList<QAction*> actions_;
191
QTimer* next_suggestion_timer_;
194
#endif // GLOBALSEARCHWIDGET_H