~ubuntu-branches/ubuntu/saucy/clementine/saucy

« back to all changes in this revision

Viewing changes to src/library/libraryfilterwidget.cpp

  • Committer: Package Import Robot
  • Author(s): Thomas PIERSON
  • Date: 2012-01-01 20:43:39 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120101204339-lsb6nndwhfy05sde
Tags: 1.0.1+dfsg-1
New upstream release. (Closes: #653926, #651611, #657391)

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
    ui_(new Ui_LibraryFilterWidget),
37
37
    model_(NULL),
38
38
    group_by_dialog_(new GroupByDialog),
39
 
    filter_delay_(new QTimer(this))
 
39
    filter_delay_(new QTimer(this)),
 
40
    filter_applies_to_model_(true),
 
41
    delay_behaviour_(DelayedOnLargeLibraries)
40
42
{
41
43
  ui_->setupUi(this);
42
44
  connect(ui_->filter, SIGNAL(returnPressed()), SIGNAL(ReturnPressed()));
104
106
  connect(group_by_group_, SIGNAL(triggered(QAction*)), SLOT(GroupByClicked(QAction*)));
105
107
 
106
108
  // Library config menu
107
 
  library_menu_ = new QMenu(this);
 
109
  library_menu_ = new QMenu(tr("Display options"), this);
 
110
  library_menu_->setIcon(ui_->options->icon());
108
111
  library_menu_->addMenu(filter_age_menu_);
109
112
  library_menu_->addMenu(group_by_menu_);
110
113
  library_menu_->addSeparator();
111
114
  ui_->options->setMenu(library_menu_);
112
115
 
113
116
#ifdef Q_OS_DARWIN
 
117
  QString hint = ui_->filter->hint();
114
118
  delete ui_->filter;
115
119
  MacLineEdit* lineedit = new MacLineEdit(this);
116
120
  ui_->horizontalLayout->insertWidget(1, lineedit);
117
121
  filter_ = lineedit;
 
122
  filter_->set_hint(hint);
118
123
#else
119
124
  filter_ = ui_->filter;
120
125
#endif
230
235
      break;
231
236
 
232
237
    case Qt::Key_Escape:
233
 
      ui_->filter->LineEditInterface::clear();
 
238
      filter_->clear();
234
239
      e->accept();
235
240
      break;
236
241
  }
243
248
  // even with FTS, so if there are a large number of songs in the database
244
249
  // introduce a small delay before actually filtering the model, so if the
245
250
  // user is typing the first few characters of something it will be quicker.
246
 
  if (!text.isEmpty() && text.length() < 3 && model_->total_song_count() >= 100000) {
 
251
  const bool delay = (delay_behaviour_ == AlwaysDelayed)
 
252
                  || (delay_behaviour_ == DelayedOnLargeLibraries &&
 
253
                      !text.isEmpty() && text.length() < 3 &&
 
254
                      model_->total_song_count() >= 100000);
 
255
 
 
256
  if (delay) {
247
257
    filter_delay_->start();
248
258
  } else {
249
259
    filter_delay_->stop();
250
 
    model_->SetFilterText(text);
 
260
    FilterDelayTimeout();
251
261
  }
252
262
}
253
263
 
254
264
void LibraryFilterWidget::FilterDelayTimeout() {
255
 
  model_->SetFilterText(filter_->text());
 
265
  emit Filter(filter_->text());
 
266
  if (filter_applies_to_model_) {
 
267
    model_->SetFilterText(filter_->text());
 
268
  }
256
269
}