2
# -*- coding: utf-8 -*-
4
# Copyright (C) 2010 Daniel Fett
5
# This program is free software: you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation, either version 3 of the License, or
8
# (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program. If not, see <http://www.gnu.org/licenses/>.
18
# Author: Daniel Fett agtl@danielfett.de
19
# Jabber: fett.daniel@jaber.ccc.de
20
# Bugtracker and GIT Repository: http://github.com/webhamster/advancedcaching
25
from PyQt4.QtCore import *
26
from PyQt4.QtGui import *
28
from searchresultsdialog import QtSearchResultsDialog
29
from ui_searchgeocachesdialog import Ui_SearchGeocachesDialog
30
d = lambda x: x.decode('utf-8')
32
logger = logging.getLogger('qtsearchgeocachesdialog')
34
class QtSearchGeocachesDialog(Ui_SearchGeocachesDialog, QDialog):
36
RADI = [1, 2, 3, 5, 10, 15, 20, 50, 100]
39
('traditional', geocaching.GeocacheCoordinate.TYPE_REGULAR),
40
('multi stage', geocaching.GeocacheCoordinate.TYPE_MULTI),
41
('virtual', geocaching.GeocacheCoordinate.TYPE_VIRTUAL),
42
('earth', geocaching.GeocacheCoordinate.TYPE_EARTH),
43
('event', geocaching.GeocacheCoordinate.TYPE_EVENT),
44
('mystery', geocaching.GeocacheCoordinate.TYPE_MYSTERY),
45
('webcam', geocaching.GeocacheCoordinate.TYPE_WEBCAM),
46
('all/other', geocaching.GeocacheCoordinate.TYPE_UNKNOWN)
49
def __init__(self, core, map_position, user_position, parent=None):
50
QDialog.__init__(self, parent)
55
self.dialogButtonBox.clicked.connect(self.__button_clicked)
56
self.map_position = map_position
57
self.user_position = user_position
61
for name, type in self.TYPELIST:
62
m = QListWidgetItem(name, self.listWidgetType)
63
m.setCheckState(Qt.Unchecked if type == geocaching.GeocacheCoordinate.TYPE_UNKNOWN else Qt.Checked)
64
self.comboBoxLocation.currentIndexChanged.connect(self.__combo_box_changed)
66
def __combo_box_changed(self, index):
67
self.spinBoxRadius.setEnabled(index != 0)
69
text = self.map_position.get_latlon() if self.map_position != None else 'not available'
71
text = self.user_position.get_latlon() if self.user_position != None else 'not available'
74
self.labelLocation.setText(d(text))
80
def __button_clicked(self, button):
81
id = self.dialogButtonBox.standardButton(button)
82
if id == QDialogButtonBox.Ok:
85
def __start_search(self):
89
name = str(self.lineEditName.text()).strip().lower()
93
logger.debug("Name: %s" % name)
97
i = self.comboBoxLocation.currentIndex()
98
if i == 1 and self.map_position != None:
99
center = self.map_position
100
elif i == 2 and self.user_position != None:
101
center = self.user_position
106
radius = self.spinBoxRadius.value()
108
c1 = center.transform(-45, radius * 1000 * sqrt_2)
109
c2 = center.transform(-45 + 180, radius * 1000 * sqrt_2)
111
logger.debug("Location: %s %s" % location)
114
logger.debug("Location: None")
120
types = [self.TYPELIST[x][1] for x in range(self.listWidgetType.count()) if self.listWidgetType.item(x).checkState() == Qt.Checked]
121
if geocaching.GeocacheCoordinate.TYPE_UNKNOWN in types:
123
logger.debug("Types: %s" % types)
125
if self.checkBoxHideFound.checkState() == Qt.Checked:
129
logger.debug("Found: %s" % found)
131
if self.checkBoxShowOnlyMarked.checkState() == Qt.Checked:
135
logger.debug("Marked: %s" % marked)
138
sizes = [x + 1 for x in range(self.listWidgetSize.count()) if self.listWidgetSize.item(x).checkState() == Qt.Checked]
139
if sizes == [1, 2, 3, 4, 5]:
141
logger.debug("Sizes: %s" % sizes)
143
r = lambda x: int(x / 0.5) * 0.5
145
diff_min = r(self.doubleSpinBoxDifficultyMin.value())
146
diff_max = r(self.doubleSpinBoxDifficultyMax.value() + 0.5)
147
if diff_min == 1 and diff_max == 5.5:
150
# range doesn't support floats!
151
difficulties = [x / 10.0 for x in range(int(diff_min * 10), int(diff_max * 10), 5)]
152
logger.debug("Difficulties: %s" % difficulties)
154
terr_min = r(self.doubleSpinBoxTerrainMin.value())
155
terr_max = r(self.doubleSpinBoxTerrainMax.value() + 0.5)
156
if terr_min == 1 and terr_max == 5.5:
159
# range doesn't support floats!
160
terrains = [x / 10.0 for x in range(int(terr_min * 10), int(terr_max * 10), 5)]
161
logger.debug("Terrains: %s" % terrains)
163
results = self.core.get_points_filter(found=found, name_search=name, size=sizes, terrain=terrains, diff=difficulties, ctype=types, marked=marked, location=location)
164
logger.debug("Found %d results" % len(results[0]))
166
self.__show_results(results)
168
def __show_results(self, results):
169
d = QtSearchResultsDialog(self.core)