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);
+ SearchCriterionSelector* tagCriterion = new SearchCriterionSelector(SearchCriterionSelector::Tag, this);
+ // Add the items in the same order as available in the description combo (verified by Q_ASSERTs). This
+ // is not mandatory from an implementation point of view, but preferable from a usability point of view.
+ Q_ASSERT(static_cast<int>(SearchCriterionSelector::Date) == 0);
+ Q_ASSERT(static_cast<int>(SearchCriterionSelector::Size) == 1);
+ Q_ASSERT(static_cast<int>(SearchCriterionSelector::Tag) == 2);
addSelector(dateCriterion);
- addSelector(tagCriterion);
addSelector(sizeCriterion);
+ addSelector(tagCriterion);
m_initialized = true;
}
void DolphinSearchOptionsConfigurator::slotAddSelectorButtonClicked()
{
- SearchCriterionSelector* selector = new SearchCriterionSelector(SearchCriterionSelector::Size, this);
+ SearchCriterionSelector* selector = new SearchCriterionSelector(SearchCriterionSelector::Tag, this);
addSelector(selector);
}
dateComps,
dateValue);
+ // 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",
+ sizeComps,
+ sizeValue);
+
// add "Tag" description
QList<SearchCriterionDescription::Comparator> tagComps;
tagComps.append(SearchCriterionDescription::Comparator(i18nc("@label All (tags)", "All")));
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",
- sizeComps,
- sizeValue);
-
+ Q_ASSERT(static_cast<int>(SearchCriterionSelector::Date) == 0);
+ Q_ASSERT(static_cast<int>(SearchCriterionSelector::Size) == 1);
+ Q_ASSERT(static_cast<int>(SearchCriterionSelector::Tag) == 2);
m_descriptions.append(date);
- m_descriptions.append(tag);
m_descriptions.append(size);
+ m_descriptions.append(tag);
// add all descriptions to the combo box
const int count = m_descriptions.count();
Q_OBJECT
public:
- enum Type { Date, Tag, Size };
+ enum Type { Date, Size, Tag };
SearchCriterionSelector(Type type, QWidget* parent = 0);
virtual ~SearchCriterionSelector();
#include <klineedit.h>
#include <klocale.h>
+#include <nepomuk/tag.h>
+
#include <QComboBox>
#include <QDateEdit>
#include <QLabel>
#include <QHBoxLayout>
+#include <QShowEvent>
SearchCriterionValue::SearchCriterionValue(QWidget* parent) :
QWidget(parent)
m_tags(0)
{
m_tags = new QComboBox(this);
- m_tags->addItem("feffi");
+ m_tags->setInsertPolicy(QComboBox::InsertAlphabetically);
QHBoxLayout* layout = new QHBoxLayout(this);
layout->setMargin(0);
return QString();
}
+void TagValue::showEvent(QShowEvent* event)
+{
+ if (!event->spontaneous() && (m_tags->count() == 0)) {
+ const QList<Nepomuk::Tag> tags = Nepomuk::Tag::allTags();
+ foreach (const Nepomuk::Tag& tag, tags) {
+ m_tags->addItem(tag.label());
+ }
+
+ if (tags.count() == 0) {
+ m_tags->addItem(i18nc("@label", "No Tags Available"));
+ }
+ }
+ SearchCriterionValue::showEvent(event);
+}
+
// -------------------------------------------------------------------------
SizeValue::SizeValue(QWidget* parent) :
virtual ~TagValue();
virtual QString value() const;
+protected:
+ virtual void showEvent(QShowEvent* event);
+
private:
QComboBox* m_tags;
};