diff options
Diffstat (limited to 'src/search')
| -rw-r--r-- | src/search/dolphinsearchbox.cpp | 27 | ||||
| -rw-r--r-- | src/search/dolphinsearchbox.h | 2 |
2 files changed, 29 insertions, 0 deletions
diff --git a/src/search/dolphinsearchbox.cpp b/src/search/dolphinsearchbox.cpp index c6943c608..345692008 100644 --- a/src/search/dolphinsearchbox.cpp +++ b/src/search/dolphinsearchbox.cpp @@ -22,6 +22,8 @@ #include "dolphin_searchsettings.h" #include "dolphinfacetswidget.h" +#include <panels/places/placesitemmodel.h> + #include <QIcon> #include <QLineEdit> #include <KLocalizedString> @@ -54,6 +56,7 @@ DolphinSearchBox::DolphinSearchBox(QWidget* parent) : m_topLayout(0), m_searchLabel(0), m_searchInput(0), + m_saveSearchAction(0), m_optionsScrollArea(0), m_fileNameButton(0), m_contentButton(0), @@ -250,6 +253,7 @@ void DolphinSearchBox::emitSearchRequest() { m_startSearchTimer->stop(); m_startedSearching = true; + m_saveSearchAction->setEnabled(true); emit searchRequest(); } @@ -257,6 +261,7 @@ void DolphinSearchBox::emitCloseRequest() { m_startSearchTimer->stop(); m_startedSearching = false; + m_saveSearchAction->setEnabled(false); emit closeRequest(); } @@ -299,6 +304,20 @@ void DolphinSearchBox::slotFacetChanged() emit searchRequest(); } +void DolphinSearchBox::slotSearchSaved() +{ + const QUrl searchURL = urlForSearching(); + if (searchURL.isValid()) { + PlacesItemModel model; + const QString label = i18n("Search for %1 in %2", text(), searchPath().fileName()); + PlacesItem* item = model.createPlacesItem(label, + searchURL, + QStringLiteral("folder-saved-search-symbolic")); + model.appendItemToGroup(item); + model.saveBookmarks(); + } +} + void DolphinSearchBox::initButton(QToolButton* button) { button->installEventFilter(this); @@ -356,6 +375,14 @@ void DolphinSearchBox::init() this, &DolphinSearchBox::slotSearchTextChanged); setFocusProxy(m_searchInput); + // Add "Save search" button inside search box + m_saveSearchAction = new QAction(this); + m_saveSearchAction->setIcon (QIcon::fromTheme(QStringLiteral("document-save-symbolic"))); + m_saveSearchAction->setText(i18nc("action:button", "Save this search to quickly access it again in the future")); + m_saveSearchAction->setEnabled(false); + m_searchInput->addAction(m_saveSearchAction, QLineEdit::TrailingPosition); + connect(m_saveSearchAction, &QAction::triggered, this, &DolphinSearchBox::slotSearchSaved); + // Apply layout for the search input QHBoxLayout* searchInputLayout = new QHBoxLayout(); searchInputLayout->setMargin(0); diff --git a/src/search/dolphinsearchbox.h b/src/search/dolphinsearchbox.h index 5063c2bf5..f1ea49091 100644 --- a/src/search/dolphinsearchbox.h +++ b/src/search/dolphinsearchbox.h @@ -139,6 +139,7 @@ private slots: void slotReturnPressed(); void slotFacetsButtonToggled(); void slotFacetChanged(); + void slotSearchSaved(); private: void initButton(QToolButton* button); @@ -167,6 +168,7 @@ private: QLabel* m_searchLabel; QLineEdit* m_searchInput; + QAction* m_saveSearchAction; QScrollArea* m_optionsScrollArea; QToolButton* m_fileNameButton; QToolButton* m_contentButton; |
