* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
***************************************************************************/
+
#include "dolphinsearchbox.h"
#include <config-nepomuk.h>
m_searchInput->setClickMessage(i18nc("@label:textbox", "Search..."));
m_searchInput->installEventFilter(this);
hLayout->addWidget(m_searchInput);
- connect(m_searchInput, SIGNAL(textChanged(const QString&)),
- this, SIGNAL(textChanged(const QString&)));
connect(m_searchInput, SIGNAL(returnPressed()),
this, SLOT(emitSearchSignal()));
return QWidget::event(event);
}
+#include <kdebug.h>
bool DolphinSearchBox::eventFilter(QObject* watched, QEvent* event)
{
if ((watched == m_searchInput) && (event->type() == QEvent::FocusIn)) {
if (m_completer == 0) {
m_completer = new DolphinSearchCompleter(m_searchInput);
}
+ kDebug() << "---- got focus! is visible? " << isVisible();
emit requestSearchOptions();
}
#include <QHBoxLayout>
#include <QLabel>
#include <QPushButton>
+#include <QShowEvent>
#include <QVBoxLayout>
DolphinSearchOptionsConfigurator::DolphinSearchOptionsConfigurator(QWidget* parent) :
QWidget(parent),
+ m_initialized(false),
m_searchFromBox(0),
m_searchWhatBox(0),
m_addSelectorButton(0),
m_searchWhatBox->addItem(i18nc("@label", "Text"));
m_searchWhatBox->addItem(i18nc("@label", "Filenames"));
- QWidget* filler = new QWidget(this);
-
// add button "Save"
QPushButton* saveButton = new QPushButton(this);
saveButton->setIcon(KIcon("document-save"));
m_addSelectorButton->setIcon(KIcon("list-add"));
m_addSelectorButton->setToolTip(i18nc("@info", "Add search option"));
m_addSelectorButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
- connect(m_addSelectorButton, SIGNAL(clicked()), this, SLOT(addSelector()));
-
- QHBoxLayout* hBoxLayout = new QHBoxLayout(this);
- hBoxLayout->addWidget(searchLabel);
- hBoxLayout->addWidget(m_searchFromBox);
- hBoxLayout->addWidget(whatLabel);
- hBoxLayout->addWidget(m_searchWhatBox);
- hBoxLayout->addWidget(filler, 1);
- hBoxLayout->addWidget(saveButton);
- hBoxLayout->addWidget(closeButton);
- hBoxLayout->addWidget(m_addSelectorButton);
+ connect(m_addSelectorButton, SIGNAL(clicked()), this, SLOT(slotAddSelectorButtonClicked()));
- // add default search criterions
- SearchCriterionSelector* dateCriterion = new SearchCriterionSelector(SearchCriterionSelector::Date, this);
- connect(dateCriterion, SIGNAL(removeCriterion()), this, SLOT(removeCriterion()));
+ QHBoxLayout* firstLineLayout = new QHBoxLayout();
+ firstLineLayout->addWidget(searchLabel);
+ firstLineLayout->addWidget(m_searchFromBox);
+ firstLineLayout->addWidget(whatLabel);
+ firstLineLayout->addWidget(m_searchWhatBox);
+ firstLineLayout->addWidget(new QWidget(this), 1); // filler
+ firstLineLayout->addWidget(m_addSelectorButton);
- SearchCriterionSelector* fileSizeCriterion = new SearchCriterionSelector(SearchCriterionSelector::FileSize, this);
- connect(fileSizeCriterion, SIGNAL(removeCriterion()), this, SLOT(removeCriterion()));
+ QHBoxLayout* lastLineLayout = new QHBoxLayout();
+ lastLineLayout->addWidget(new QWidget(this), 1); // filler
+ lastLineLayout->addWidget(saveButton);
+ lastLineLayout->addWidget(closeButton);
m_vBoxLayout->addWidget(new KSeparator(this));
- m_vBoxLayout->addLayout(hBoxLayout);
- m_vBoxLayout->addWidget(dateCriterion);
- m_vBoxLayout->addWidget(fileSizeCriterion);
+ m_vBoxLayout->addLayout(firstLineLayout);
+ m_vBoxLayout->addLayout(lastLineLayout);
m_vBoxLayout->addWidget(new KSeparator(this));
}
{
}
-void DolphinSearchOptionsConfigurator::addSelector()
+void DolphinSearchOptionsConfigurator::showEvent(QShowEvent* event)
{
- SearchCriterionSelector* selector = new SearchCriterionSelector(SearchCriterionSelector::Undefined, this);
- connect(selector, SIGNAL(removeCriterion()), this, SLOT(removeCriterion()));
+ if (!event->spontaneous() && !m_initialized) {
+ // add default search criterions
+ SearchCriterionSelector* dateCriterion = new SearchCriterionSelector(SearchCriterionSelector::Date, this);
+ SearchCriterionSelector* tagCriterion = new SearchCriterionSelector(SearchCriterionSelector::Tag, this);
+ SearchCriterionSelector* sizeCriterion = new SearchCriterionSelector(SearchCriterionSelector::Size, this);
+
+ addSelector(dateCriterion);
+ addSelector(tagCriterion);
+ addSelector(sizeCriterion);
+
+ m_initialized = true;
+ }
+ QWidget::showEvent(event);
+}
- // insert the new selector before the KSeparator at the bottom
- const int index = m_vBoxLayout->count() - 1;
- m_vBoxLayout->insertWidget(index, selector);
- updateSelectorButton();
+void DolphinSearchOptionsConfigurator::slotAddSelectorButtonClicked()
+{
+ SearchCriterionSelector* selector = new SearchCriterionSelector(SearchCriterionSelector::Size, this);
+ addSelector(selector);
}
void DolphinSearchOptionsConfigurator::removeCriterion()
dialog.exec(); // TODO...
}
+void DolphinSearchOptionsConfigurator::addSelector(SearchCriterionSelector* selector)
+{
+ connect(selector, SIGNAL(removeCriterion()), this, SLOT(removeCriterion()));
+
+ // insert the new selector before the lastLineLayout and the KSeparator at the bottom
+ const int index = m_vBoxLayout->count() - 2;
+ m_vBoxLayout->insertWidget(index, selector);
+ updateSelectorButton();
+}
+
#include "dolphinsearchoptionsconfigurator.moc"
#include <QWidget>
class KComboBox;
+class SearchCriterionSelector;
class QPushButton;
class QVBoxLayout;
DolphinSearchOptionsConfigurator(QWidget* parent = 0);
virtual ~DolphinSearchOptionsConfigurator();
+protected:
+ virtual void showEvent(QShowEvent* event);
+
private slots:
- /**
- * Adds a new search description selector to the bottom
- * of the layout.
- */
- void addSelector();
+ void slotAddSelectorButtonClicked();
void removeCriterion();
void saveQuery();
private:
+ /**
+ * Adds the new search description selector to the bottom
+ * of the layout.
+ */
+ void addSelector(SearchCriterionSelector* selector);
+
+private:
+ bool m_initialized;
KComboBox* m_searchFromBox;
KComboBox* m_searchWhatBox;
QPushButton* m_addSelectorButton;
public:
struct Comparator
{
- Comparator(const QString& n, const QString& o, const QString& p) :
+ Comparator(const QString& n, const QString& o = QString(), const QString& p = QString()) :
name(n), operation(o), prefix(p) {}
QString name; // user visible and translated name
QString operation; // Nepomuk operation that represents the comparator
m_descriptions()
{
m_descriptionsBox = new QComboBox(this);
- m_descriptionsBox->addItem(i18nc("@label", "Select..."), -1);
- createDescriptions();
- connect(m_descriptionsBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotDescriptionChanged(int)));
m_comparatorBox = new QComboBox(this);
- m_comparatorBox->hide();
- connect(m_comparatorBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updateQuery()));
+ m_comparatorBox->setSizeAdjustPolicy(QComboBox::AdjustToContents);
+
+ createDescriptions();
+ const int index = static_cast<int>(type);
+ m_descriptionsBox->setCurrentIndex(index);
QWidget* filler = new QWidget(this);
filler->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
setLayout(m_layout);
- // preselect the used criterion dependent on the type
- switch (type) {
- case Date:
- m_descriptionsBox->setCurrentIndex(1);
- m_comparatorBox->setCurrentIndex(1);
- break;
- case FileSize:
- m_descriptionsBox->setCurrentIndex(2);
- break;
- case Undefined:
- default:
- break;
- }
+ slotDescriptionChanged(index);
+ connect(m_descriptionsBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotDescriptionChanged(int)));
}
SearchCriterionSelector::~SearchCriterionSelector()
void SearchCriterionSelector::createDescriptions()
{
+ Q_ASSERT(m_descriptionsBox != 0);
+ Q_ASSERT(m_comparatorBox != 0);
+
// TODO: maybe this creation should be forwarded to a factory if
// the number of items increases in future
- QList<SearchCriterionDescription::Comparator> comperators;
- comperators.append(SearchCriterionDescription::Comparator(i18nc("@label", "Greater Than"), ">", "+"));
- comperators.append(SearchCriterionDescription::Comparator(i18nc("@label", "Greater Than or Equal to"), ">=", "+"));
- comperators.append(SearchCriterionDescription::Comparator(i18nc("@label", "Less Than"), "<", "+"));
- comperators.append(SearchCriterionDescription::Comparator(i18nc("@label", "Less Than or Equal to"), "<=", "+"));
+ QList<SearchCriterionDescription::Comparator> defaultComps;
+ defaultComps.append(SearchCriterionDescription::Comparator(i18nc("@label", "Greater Than"), ">", "+"));
+ defaultComps.append(SearchCriterionDescription::Comparator(i18nc("@label", "Greater Than or Equal to"), ">=", "+"));
+ defaultComps.append(SearchCriterionDescription::Comparator(i18nc("@label", "Less Than"), "<", "+"));
+ defaultComps.append(SearchCriterionDescription::Comparator(i18nc("@label", "Less Than or Equal to"), "<=", "+"));
// add "Date" description
QList<SearchCriterionDescription::Comparator> dateComps;
- dateComps.append(SearchCriterionDescription::Comparator(i18nc("@label", "Anytime"), "", "")); // TODO
- dateComps.append(SearchCriterionDescription::Comparator(i18nc("@label", "Today"), ">", "+")); // TODO
- dateComps.append(SearchCriterionDescription::Comparator(i18nc("@label", "This week"), ">", "+")); // TODO
- dateComps.append(SearchCriterionDescription::Comparator(i18nc("@label", "This month"), ">", "+")); // TODO
- foreach (const SearchCriterionDescription::Comparator& comp, comperators) {
+ dateComps.append(SearchCriterionDescription::Comparator(i18nc("@label", "Anytime"))); // TODO
+ dateComps.append(SearchCriterionDescription::Comparator(i18nc("@label", "Today"))); // TODO
+ dateComps.append(SearchCriterionDescription::Comparator(i18nc("@label", "This week"))); // TODO
+ dateComps.append(SearchCriterionDescription::Comparator(i18nc("@label", "This month"))); // TODO
+ foreach (const SearchCriterionDescription::Comparator& comp, defaultComps) {
dateComps.append(comp);
}
DateValue* dateValue = new DateValue(this);
dateValue->hide();
- SearchCriterionDescription date(i18nc("@label", "Date Modified"),
+ SearchCriterionDescription date(i18nc("@label", "Date"),
"sourceModified",
dateComps,
dateValue);
- // add "File Size" description
- FileSizeValue* fileSizeValue = new FileSizeValue(this);
- fileSizeValue->hide();
- SearchCriterionDescription size(i18nc("@label", "File Size"),
+ // add "Tag" description
+ QList<SearchCriterionDescription::Comparator> tagComps;
+ tagComps.append(SearchCriterionDescription::Comparator(i18nc("@label All (tags)", "All")));
+ tagComps.append(SearchCriterionDescription::Comparator(i18nc("@label", "Equal to"), "=="));
+
+ TagValue* tagValue = new TagValue(this);
+ tagValue->hide();
+ SearchCriterionDescription tag(i18nc("@label", "Tag"),
+ "tag",
+ tagComps,
+ tagValue);
+
+ // add "Size" description
+ QList<SearchCriterionDescription::Comparator> sizeComps = defaultComps;
+ sizeComps.insert(0, SearchCriterionDescription::Comparator(i18nc("@label Any (file size)", "Any")));
+
+ SizeValue* sizeValue = new SizeValue(this);
+ sizeValue->hide();
+ SearchCriterionDescription size(i18nc("@label", "Size"),
"contentSize",
- comperators,
- fileSizeValue);
+ sizeComps,
+ sizeValue);
m_descriptions.append(date);
+ m_descriptions.append(tag);
m_descriptions.append(size);
// add all descriptions to the combo box
void SearchCriterionSelector::slotDescriptionChanged(int index)
{
- m_comparatorBox->clear();
- m_comparatorBox->show();
if (m_valueWidget != 0) {
+ m_valueWidget->hide();
m_layout->removeWidget(m_valueWidget);
+ m_valueWidget = 0;
// the value widget is obtained by the Search Criterion
// Selector instance and may not get deleted
}
- // adjust the comparator box and the value widget dependent from the selected description
- m_comparatorBox->addItem(i18nc("@label", "Select..."), -1);
- const int descrIndex = m_descriptionsBox->itemData(index).toInt();
- if (descrIndex >= 0) {
- // add comparator items
- const SearchCriterionDescription& description = m_descriptions[descrIndex];
- foreach (const SearchCriterionDescription::Comparator& comp, description.comparators()) {
- m_comparatorBox->addItem(comp.name);
- }
-
- // add value widget
- m_valueWidget = description.valueWidget();
- const int layoutIndex = m_layout->count() - 2;
- m_layout->insertWidget(layoutIndex, m_valueWidget);
- m_valueWidget->show();
+ // add comparator items
+ disconnect(m_comparatorBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotComparatorChanged(int)));
+ m_comparatorBox->clear();
+
+ const SearchCriterionDescription& description = m_descriptions[index];
+ foreach (const SearchCriterionDescription::Comparator& comp, description.comparators()) {
+ m_comparatorBox->addItem(comp.name);
}
+
+ // add value widget
+ m_valueWidget = description.valueWidget();
+ m_layout->insertWidget(2, m_valueWidget);
+
+ m_comparatorBox->setCurrentIndex(0);
+ slotComparatorChanged(0);
+ connect(m_comparatorBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotComparatorChanged(int)));
}
-void SearchCriterionSelector::updateQuery()
+void SearchCriterionSelector::slotComparatorChanged(int index)
{
- const SearchCriterionDescription* descr = description();
- if (descr == 0) {
- // no description has been selected
- return;
- }
+ Q_ASSERT(index >= 0);
- // get selected comparator related to the description
- const int compBoxIndex = m_comparatorBox->currentIndex();
- const int compIndex = m_comparatorBox->itemData(compBoxIndex).toInt();
- if (compIndex < 0) {
- // no comparator has been selected
- return;
- }
+ // only show the value widget if an operation is defined by the comparator
+ const int descIndex = m_descriptionsBox->currentIndex();
+ const SearchCriterionDescription& descr = m_descriptions[descIndex];
+ const SearchCriterionDescription::Comparator& comp = descr.comparators()[index];
+ m_valueWidget->setVisible(!comp.operation.isEmpty());
// create query string
- const SearchCriterionDescription::Comparator& comp = descr->comparators()[compIndex];
- const QString queryString = comp.prefix + descr->identifier() + comp.operation + m_valueWidget->value();
+ const QString queryString = comp.prefix + descr.identifier() + comp.operation + m_valueWidget->value();
emit criterionChanged(queryString);
}
-const SearchCriterionDescription* SearchCriterionSelector::description() const
-{
- const int descrBoxIndex = m_descriptionsBox->currentIndex();
- const int descrIndex = m_descriptionsBox->itemData(descrBoxIndex).toInt();
- return (descrIndex < 0) ? 0 : &m_descriptions[descrIndex];
-}
-
#include "searchcriterionselector.moc"
Q_OBJECT
public:
- enum Type
- {
- Undefined,
- Date,
- FileSize
- };
+ enum Type { Date, Tag, Size };
SearchCriterionSelector(Type type, QWidget* parent = 0);
virtual ~SearchCriterionSelector();
private slots:
void slotDescriptionChanged(int index);
-
- /**
- * Updates the query string and emits the signal criterionChanged().
- */
- void updateQuery();
+ void slotComparatorChanged(int index);
private:
/**
*/
void createDescriptions();
- /**
- * Returns the currently selected searc criterion description. If nothing
- * is selected, 0 is returned.
- */
- const SearchCriterionDescription* description() const;
-
private:
QHBoxLayout* m_layout;
QComboBox* m_descriptionsBox; // has items like "File Size", "Date Modified", ...
{
}
-
+// -------------------------------------------------------------------------
DateValue::DateValue(QWidget* parent) :
SearchCriterionValue(parent),
return QString();
}
+// -------------------------------------------------------------------------
+
+TagValue::TagValue(QWidget* parent) :
+ SearchCriterionValue(parent),
+ m_tags(0)
+{
+ m_tags = new QComboBox(this);
+ m_tags->addItem("feffi");
+
+ QHBoxLayout* layout = new QHBoxLayout(this);
+ layout->setMargin(0);
+ layout->addWidget(m_tags);
+}
+
+TagValue::~TagValue()
+{
+}
+
+QString TagValue::value() const
+{
+ return QString();
+}
+// -------------------------------------------------------------------------
-FileSizeValue::FileSizeValue(QWidget* parent) :
+SizeValue::SizeValue(QWidget* parent) :
SearchCriterionValue(parent),
m_lineEdit(0),
m_units(0)
layout->addWidget(m_units);
}
-FileSizeValue::~FileSizeValue()
+SizeValue::~SizeValue()
{
}
-QString FileSizeValue::value() const
+QString SizeValue::value() const
{
return QString();
}
+/** @brief Allows to input a tag as search criterion. */
+class TagValue : public SearchCriterionValue
+{
+ Q_OBJECT
+
+public:
+ TagValue(QWidget* parent = 0);
+ virtual ~TagValue();
+ virtual QString value() const;
+
+private:
+ QComboBox* m_tags;
+};
+
+
+
/** @brief Allows to input a file size value as search criterion. */
-class FileSizeValue : public SearchCriterionValue
+class SizeValue : public SearchCriterionValue
{
Q_OBJECT
public:
- FileSizeValue(QWidget* parent = 0);
- virtual ~FileSizeValue();
+ SizeValue(QWidget* parent = 0);
+ virtual ~SizeValue();
virtual QString value() const;
private: