]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Implemented initialization of value-widgets. This allows e.g. to apply dates like...
authorPeter Penz <peter.penz19@gmail.com>
Fri, 13 Nov 2009 22:48:07 +0000 (22:48 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Fri, 13 Nov 2009 22:48:07 +0000 (22:48 +0000)
svn path=/trunk/KDE/kdebase/apps/; revision=1048771

src/dolphinviewcontainer.cpp
src/search/searchcriteriondescription.h
src/search/searchcriterionselector.cpp
src/search/searchcriterionvalue.cpp
src/search/searchcriterionvalue.h

index bdeaab25833a05e8d0d525dbaae7697fdb3adc96..5639d9bf2e38e3cea6015b386fd195a4b8566ad4 100644 (file)
@@ -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
index 5da188633aee218b76611973d0fdea86d2a79850..98211793eccf0c037aad2ba65750c96cca7341c7 100644 (file)
@@ -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,
index 4b6112b9caa4f5954aa84da340b5430bd57fcd22..104f83c1cf22cf848d72f6faee835b3375e96da6 100644 (file)
@@ -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);
     }
index 7bf83e94fff19c347da305817b40dda270cb7651..7d8e2d8cd0e59a189fb96b098a33456c67646392 100644 (file)
@@ -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) :
index 972b95f7a75560f01aff5fb02f0bb3908b292f70..652b58a7ca6017f8e95eb9563490d81a605274bd 100644 (file)
@@ -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;
 };