diff --git a/src/globalsearch/globalsearchview.cpp b/src/globalsearch/globalsearchview.cpp index 45c9f1028..ae02dfd74 100644 --- a/src/globalsearch/globalsearchview.cpp +++ b/src/globalsearch/globalsearchview.cpp @@ -62,7 +62,7 @@ GlobalSearchView::GlobalSearchView(Application* app, QWidget* parent) ui_->setupUi(this); ui_->search->installEventFilter(this); - ui_->results->installEventFilter(this); + ui_->results_stack->installEventFilter(this); // Must be a queued connection to ensure the GlobalSearch handles it first. connect(app_, SIGNAL(SettingsChanged()), SLOT(ReloadSettings()), Qt::QueuedConnection); @@ -77,7 +77,7 @@ GlobalSearchView::GlobalSearchView(Application* app, QWidget* parent) ui_->results->setStyleSheet("QTreeView::item{padding-top:1px;}"); // Show the help page initially - ui_->stack->setCurrentWidget(ui_->help_page); + ui_->results_stack->setCurrentWidget(ui_->help_page); ui_->help_frame->setBackgroundRole(QPalette::Base); QVBoxLayout* enabled_layout = new QVBoxLayout(ui_->enabled_list); QVBoxLayout* disabled_layout = new QVBoxLayout(ui_->disabled_list); @@ -255,9 +255,9 @@ void GlobalSearchView::SwapModels() { ui_->results->setModel(front_proxy_); if (ui_->search->text().trimmed().isEmpty()) { - ui_->stack->setCurrentWidget(ui_->help_page); + ui_->results_stack->setCurrentWidget(ui_->help_page); } else { - ui_->stack->setCurrentWidget(ui_->results_page); + ui_->results_stack->setCurrentWidget(ui_->results_page); } } @@ -315,6 +315,9 @@ void GlobalSearchView::ArtLoaded(int id, const QPixmap& pixmap) { } MimeData* GlobalSearchView::SelectedMimeData() { + if (!ui_->results->selectionModel()) + return NULL; + // Get all selected model indexes QModelIndexList indexes = ui_->results->selectionModel()->selectedRows(); if (indexes.isEmpty()) { @@ -349,7 +352,7 @@ bool GlobalSearchView::eventFilter(QObject* object, QEvent* event) { if (SearchKeyEvent(static_cast(event))) { return true; } - } else if (object == ui_->results && event->type() == QEvent::ContextMenu) { + } else if (object == ui_->results_stack && event->type() == QEvent::ContextMenu) { if (ResultsContextMenuEvent(static_cast(event))) { return true; } @@ -383,16 +386,28 @@ bool GlobalSearchView::SearchKeyEvent(QKeyEvent* event) { bool GlobalSearchView::ResultsContextMenuEvent(QContextMenuEvent* event) { if (!context_menu_) { context_menu_ = new QMenu(this); - context_menu_->addAction(IconLoader::Load("media-playback-start"), + context_actions_ << context_menu_->addAction(IconLoader::Load("media-playback-start"), tr("Append to current playlist"), this, SLOT(AddSelectedToPlaylist())); - context_menu_->addAction(IconLoader::Load("media-playback-start"), + context_actions_ << context_menu_->addAction(IconLoader::Load("media-playback-start"), tr("Replace current playlist"), this, SLOT(LoadSelected())); - context_menu_->addAction(IconLoader::Load("document-new"), + context_actions_ << context_menu_->addAction(IconLoader::Load("document-new"), tr("Open in new playlist"), this, SLOT(OpenSelectedInNewPlaylist())); context_menu_->addSeparator(); - context_menu_->addAction(IconLoader::Load("go-next"), + context_actions_ << context_menu_->addAction(IconLoader::Load("go-next"), tr("Queue track"), this, SLOT(AddSelectedToPlaylistEnqueue())); + + context_menu_->addSeparator(); + context_menu_->addAction(IconLoader::Load("configure"), + tr("Configure global search..."), this, SLOT(OpenSettingsDialog())); + } + + const bool enable_context_actions = + ui_->results->selectionModel() && + ui_->results->selectionModel()->hasSelection(); + + foreach (QAction* action, context_actions_) { + action->setEnabled(enable_context_actions); } context_menu_->popup(event->globalPos()); @@ -406,18 +421,27 @@ void GlobalSearchView::AddSelectedToPlaylist() { void GlobalSearchView::LoadSelected() { MimeData* data = SelectedMimeData(); + if (!data) + return; + data->clear_first_ = true; emit AddToPlaylist(data); } void GlobalSearchView::AddSelectedToPlaylistEnqueue() { MimeData* data = SelectedMimeData(); + if (!data) + return; + data->enqueue_now_ = true; emit AddToPlaylist(data); } void GlobalSearchView::OpenSelectedInNewPlaylist() { MimeData* data = SelectedMimeData(); + if (!data) + return; + data->open_in_new_playlist_ = true; emit AddToPlaylist(data); } @@ -428,6 +452,13 @@ void GlobalSearchView::showEvent(QShowEvent* e) { update_suggestions_timer_->start(); } QWidget::showEvent(e); + + FocusSearchField(); +} + +void GlobalSearchView::FocusSearchField() { + ui_->search->set_focus(); + ui_->search->selectAll(); } void GlobalSearchView::hideEvent(QHideEvent* e) { @@ -439,3 +470,7 @@ void GlobalSearchView::FocusOnFilter(QKeyEvent* event) { ui_->search->set_focus(); QApplication::sendEvent(ui_->search, event); } + +void GlobalSearchView::OpenSettingsDialog() { + app_->OpenSettingsDialogAtPage(SettingsDialog::Page_GlobalSearch); +} diff --git a/src/globalsearch/globalsearchview.h b/src/globalsearch/globalsearchview.h index 492dd84f0..afba841dc 100644 --- a/src/globalsearch/globalsearchview.h +++ b/src/globalsearch/globalsearchview.h @@ -59,10 +59,11 @@ public: public slots: void ReloadSettings(); void StartSearch(const QString& query); + void FocusSearchField(); + void OpenSettingsDialog(); signals: void AddToPlaylist(QMimeData* data); - void OpenSettingsAtPage(SettingsDialog::Page page); private slots: void UpdateSuggestions(); @@ -91,6 +92,7 @@ private: Ui_GlobalSearchView* ui_; QMenu* context_menu_; + QList context_actions_; int last_search_id_; diff --git a/src/globalsearch/globalsearchview.ui b/src/globalsearch/globalsearchview.ui index fc3bb7858..f39da4dd7 100644 --- a/src/globalsearch/globalsearchview.ui +++ b/src/globalsearch/globalsearchview.ui @@ -25,7 +25,7 @@ - + 1 @@ -80,7 +80,7 @@ 0 0 435 - 604 + 605 diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index 5c27c4de2..56c02cc1d 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -222,7 +222,6 @@ MainWindow::MainWindow(Application* app, global_search_view_->ReloadSettings(); connect(global_search_view_, SIGNAL(AddToPlaylist(QMimeData*)), SLOT(AddToPlaylist(QMimeData*))); - connect(global_search_view_, SIGNAL(OpenSettingsAtPage(SettingsDialog::Page)), SLOT(OpenSettingsDialogAtPage(SettingsDialog::Page))); // Add tabs to the fancy tab widget ui_->tabs->AddTab(global_search_view_, IconLoader::Load("search"), tr("Search")); @@ -510,6 +509,15 @@ MainWindow::MainWindow(Application* app, connect(app_->device_manager()->connected_devices_model(), SIGNAL(IsEmptyChanged(bool)), playlist_copy_to_device_, SLOT(setDisabled(bool))); + // Global search shortcut + QAction* global_search_action = new QAction(this); + global_search_action->setShortcuts(QList() + << QKeySequence("Ctrl+F") + << QKeySequence("Ctrl+L")); + addAction(global_search_action); + connect(global_search_action, SIGNAL(triggered()), + SLOT(FocusGlobalSearchField())); + // Internet connections connect(app_->internet_model(), SIGNAL(StreamError(QString)), SLOT(ShowErrorDialog(QString))); connect(app_->internet_model(), SIGNAL(StreamMetadataFound(QUrl,Song)), app_->playlist_manager(), SLOT(SetActiveStreamMetadata(QUrl,Song))); @@ -2025,7 +2033,7 @@ void MainWindow::ConnectInfoView(SongInfoBase* view) { connect(view, SIGNAL(ShowSettingsDialog()), SLOT(ShowSongInfoConfig())); connect(view, SIGNAL(DoGlobalSearch(QString)), - global_search_view_, SLOT(StartSearch(QString))); + SLOT(DoGlobalSearch(QString))); } void MainWindow::AddSongInfoGenerator(smart_playlists::GeneratorPtr gen) { @@ -2236,3 +2244,13 @@ void MainWindow::ScrollToInternetIndex(const QModelIndex& index) { void MainWindow::AddPodcast() { app_->internet_model()->Service()->AddPodcast(); } + +void MainWindow::FocusGlobalSearchField() { + ui_->tabs->SetCurrentWidget(global_search_view_); + global_search_view_->FocusSearchField(); +} + +void MainWindow::DoGlobalSearch(const QString& query) { + FocusGlobalSearchField(); + global_search_view_->StartSearch(query); +} diff --git a/src/ui/mainwindow.h b/src/ui/mainwindow.h index 67991d80b..c2f68d622 100644 --- a/src/ui/mainwindow.h +++ b/src/ui/mainwindow.h @@ -248,6 +248,8 @@ class MainWindow : public QMainWindow, public PlatformInterface { void HandleNotificationPreview(OSD::Behaviour type, QString line1, QString line2); void ScrollToInternetIndex(const QModelIndex& index); + void FocusGlobalSearchField(); + void DoGlobalSearch(const QString& query); private: void ConnectInfoView(SongInfoBase* view);