Advanced search builder: Allow using days/weeks/months/years when building a date based search with number of days ago. Fixes #1431695 [[GUI Improvement] Date Search Selection](https://bugs.launchpad.net/calibre/+bug/1431695)

This commit is contained in:
Kovid Goyal 2015-03-13 16:27:03 +05:30
parent 977d76db87
commit c625f7771c
2 changed files with 13 additions and 7 deletions

View File

@ -50,6 +50,7 @@ class SearchDialog(QDialog, Ui_Dialog):
self.date_month.currentIndexChanged.connect(lambda : self.sel_date.setChecked(True)) self.date_month.currentIndexChanged.connect(lambda : self.sel_date.setChecked(True))
self.date_day.valueChanged.connect(lambda : self.sel_date.setChecked(True)) self.date_day.valueChanged.connect(lambda : self.sel_date.setChecked(True))
self.date_daysago.valueChanged.connect(lambda : self.sel_daysago.setChecked(True)) self.date_daysago.valueChanged.connect(lambda : self.sel_daysago.setChecked(True))
self.date_ago_type.addItems([_('days'), _('weeks'), _('months'), _('years')])
self.date_human.currentIndexChanged.connect(lambda : self.sel_human.setChecked(True)) self.date_human.currentIndexChanged.connect(lambda : self.sel_human.setChecked(True))
init_dateop(self.dateop_date) init_dateop(self.dateop_date)
self.sel_date.setChecked(True) self.sel_date.setChecked(True)
@ -143,7 +144,9 @@ class SearchDialog(QDialog, Ui_Dialog):
ans += '-%s' % d ans += '-%s' % d
return ans return ans
if self.sel_daysago.isChecked(): if self.sel_daysago.isChecked():
return '%s%sdaysago' % (prefix, self.date_daysago.value()) val = self.date_daysago.value()
val *= {0:1, 1:7, 2:30, 3:365}[self.date_ago_type.currentIndex()]
return '%s%sdaysago' % (prefix, val)
return '%s%s' % (prefix, unicode(self.date_human.itemData(self.date_human.currentIndex()) or '')) return '%s%s' % (prefix, unicode(self.date_human.itemData(self.date_human.currentIndex()) or ''))
def adv_search_string(self): def adv_search_string(self):

View File

@ -52,7 +52,7 @@
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="label_5"> <widget class="QLabel" name="label_5">
<property name="text"> <property name="text">
<string>&amp;What kind of match to use:</string> <string>What &amp;kind of match to use:</string>
</property> </property>
<property name="buddy"> <property name="buddy">
<cstring>matchkind</cstring> <cstring>matchkind</cstring>
@ -109,7 +109,7 @@
<item> <item>
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="text"> <property name="text">
<string>&amp;All these words:</string> <string>A&amp;ll these words:</string>
</property> </property>
<property name="buddy"> <property name="buddy">
<cstring>all</cstring> <cstring>all</cstring>
@ -126,7 +126,7 @@
<item> <item>
<widget class="QLabel" name="label_2"> <widget class="QLabel" name="label_2">
<property name="text"> <property name="text">
<string>This exact &amp;phrase:</string> <string>&amp;This exact phrase:</string>
</property> </property>
<property name="buddy"> <property name="buddy">
<cstring>all</cstring> <cstring>all</cstring>
@ -143,7 +143,7 @@
<item> <item>
<widget class="QLabel" name="label_3"> <widget class="QLabel" name="label_3">
<property name="text"> <property name="text">
<string>&amp;One or more of these words:</string> <string>O&amp;ne or more of these words:</string>
</property> </property>
<property name="buddy"> <property name="buddy">
<cstring>all</cstring> <cstring>all</cstring>
@ -402,7 +402,7 @@
<item> <item>
<widget class="QLabel" name="label_15"> <widget class="QLabel" name="label_15">
<property name="text"> <property name="text">
<string>&amp;month</string> <string>mo&amp;nth</string>
</property> </property>
<property name="buddy"> <property name="buddy">
<cstring>date_month</cstring> <cstring>date_month</cstring>
@ -460,10 +460,13 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QComboBox" name="date_ago_type"/>
</item>
<item> <item>
<widget class="QLabel" name="label_18"> <widget class="QLabel" name="label_18">
<property name="text"> <property name="text">
<string>days ago</string> <string> ago</string>
</property> </property>
</widget> </widget>
</item> </item>