mirror of
https://invent.kde.org/system/dolphin
synced 2024-11-05 18:47:12 +00:00
Implemented initialization of value-widgets. This allows e.g. to apply dates like "today", "last week", ... to the date-value-widgets just by specifying a search criterion.
svn path=/trunk/KDE/kdebase/apps/; revision=1048771
This commit is contained in:
parent
bd30bb6ca9
commit
3d7b54b21a
5 changed files with 72 additions and 13 deletions
|
@ -284,7 +284,7 @@ void DolphinViewContainer::updateStatusBar()
|
|||
|
||||
void DolphinViewContainer::initializeProgress()
|
||||
{
|
||||
if (m_view->url().protocol() == "nepomuksearch") {
|
||||
if (url().protocol() == "nepomuksearch") {
|
||||
// The Nepomuk IO-slave does not provide any progress information. Give
|
||||
// an immediate hint to the user that a searching is done:
|
||||
m_statusBar->setProgressText(i18nc("@info", "Searching..."));
|
||||
|
@ -307,7 +307,13 @@ void DolphinViewContainer::slotDirListerCompleted()
|
|||
m_statusBar->setProgress(100);
|
||||
}
|
||||
|
||||
updateStatusBar();
|
||||
if ((url().protocol() == "nepomuksearch") && (m_dirLister->items().count() == 0)) {
|
||||
// The dir lister has been completed on a Nepomuk-URI and no items have been found. Instead
|
||||
// of showing the default status bar information ("0 items") a more helpful information is given:
|
||||
m_statusBar->setMessage(i18nc("@info:status", "No items found."), DolphinStatusBar::Information);
|
||||
} else {
|
||||
updateStatusBar();
|
||||
}
|
||||
QMetaObject::invokeMethod(this, "restoreContentsPos", Qt::QueuedConnection);
|
||||
|
||||
// Enable the 'File'->'Create New...' menu only if the directory
|
||||
|
|
|
@ -38,11 +38,13 @@ class SearchCriterionDescription
|
|||
public:
|
||||
struct Comparator
|
||||
{
|
||||
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
|
||||
QString prefix; // prefix like "+" or "-" that is part of the Nepomuk query
|
||||
Comparator(const QString& n, const QString& o = QString(),
|
||||
const QString& p = QString(), const QString& a = QString()) :
|
||||
name(n), operation(o), prefix(p), autoValueType(a) {}
|
||||
QString name; // user visible and translated name
|
||||
QString operation; // Nepomuk operation that represents the comparator
|
||||
QString prefix; // prefix like "+" or "-" that is part of the Nepomuk query
|
||||
QString autoValueType; // type for an automatically calculated value of the value widget
|
||||
};
|
||||
|
||||
SearchCriterionDescription(const QString& name,
|
||||
|
|
|
@ -132,7 +132,13 @@ void SearchCriterionSelector::slotComparatorChanged(int index)
|
|||
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());
|
||||
|
||||
m_valueWidget->initializeValue(comp.autoValueType);
|
||||
if (!comp.operation.isEmpty() && comp.autoValueType.isEmpty()) {
|
||||
// only show the value widget, if an operation is defined
|
||||
// and no automatic calculation is provided
|
||||
m_valueWidget->show();
|
||||
}
|
||||
|
||||
emit criterionChanged();
|
||||
}
|
||||
|
@ -152,10 +158,11 @@ void SearchCriterionSelector::createDescriptions()
|
|||
|
||||
// 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
|
||||
dateComps.append(SearchCriterionDescription::Comparator(i18nc("@label", "Anytime")));
|
||||
dateComps.append(SearchCriterionDescription::Comparator(i18nc("@label", "Today"), ":", "+", "today"));
|
||||
dateComps.append(SearchCriterionDescription::Comparator(i18nc("@label", "This Week"), ">=", "+", "thisWeek"));
|
||||
dateComps.append(SearchCriterionDescription::Comparator(i18nc("@label", "This Month"), ">=", "+", "thisMonth"));
|
||||
dateComps.append(SearchCriterionDescription::Comparator(i18nc("@label", "This Year"), ">=", "+", "thisYear"));
|
||||
foreach (const SearchCriterionDescription::Comparator& comp, defaultComps) {
|
||||
dateComps.append(comp);
|
||||
}
|
||||
|
|
|
@ -42,6 +42,11 @@ SearchCriterionValue::~SearchCriterionValue()
|
|||
{
|
||||
}
|
||||
|
||||
void SearchCriterionValue::initializeValue(const QString& valueType)
|
||||
{
|
||||
Q_UNUSED(valueType);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
DateValue::DateValue(QWidget* parent) :
|
||||
|
@ -64,6 +69,31 @@ QString DateValue::value() const
|
|||
return m_dateWidget->date().toString(Qt::ISODate);
|
||||
}
|
||||
|
||||
void DateValue::initializeValue(const QString& valueType)
|
||||
{
|
||||
if (valueType.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QDate date;
|
||||
if (valueType == "today") {
|
||||
date = QDate::currentDate();
|
||||
} else if (valueType == "thisWeek") {
|
||||
const QDate today = QDate::currentDate();
|
||||
const int dayOfWeek = today.dayOfWeek();
|
||||
date = today.addDays(-dayOfWeek);
|
||||
} else if (valueType == "thisMonth") {
|
||||
const QDate today = QDate::currentDate();
|
||||
date = QDate(today.year(), today.month(), 1);
|
||||
} else if (valueType == "thisYear") {
|
||||
date = QDate(QDate::currentDate().year(), 1, 1);
|
||||
} else {
|
||||
// unknown value-type
|
||||
Q_ASSERT(false);
|
||||
}
|
||||
m_dateWidget->setDate(date);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
TagValue::TagValue(QWidget* parent) :
|
||||
|
|
|
@ -39,8 +39,21 @@ public:
|
|||
SearchCriterionValue(QWidget* parent = 0);
|
||||
virtual ~SearchCriterionValue();
|
||||
|
||||
/**
|
||||
* Must be overwritten by derived classes and returns
|
||||
* the string representation of the search criterion value.
|
||||
*/
|
||||
virtual QString value() const = 0;
|
||||
|
||||
/**
|
||||
* Initializes the widget on the base of the given value-type.
|
||||
* It is in the hand of the derived classes to interprete
|
||||
* the value-type string and create a corresponding value for
|
||||
* the widget (@see SearchCriterionSelector::Comparator).
|
||||
* The default implementation is empty.
|
||||
*/
|
||||
virtual void initializeValue(const QString& valueType);
|
||||
|
||||
signals:
|
||||
void valueChanged(const QString& value);
|
||||
};
|
||||
|
@ -56,7 +69,8 @@ public:
|
|||
DateValue(QWidget* parent = 0);
|
||||
virtual ~DateValue();
|
||||
virtual QString value() const;
|
||||
|
||||
virtual void initializeValue(const QString& valueType);
|
||||
|
||||
private:
|
||||
KDateWidget* m_dateWidget;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue