Commit 502a347d authored by Jean-Francois Dockes's avatar Jean-Francois Dockes
Browse files

Also restore search mode when loading saved simple search data

parent 90dab893
......@@ -115,14 +115,14 @@ void RclMain::loadSavedQuery()
return;
}
// Try to parse as SearchData
std::shared_ptr<SearchData> sd = xmlToSearchData(xml);
// Try to parse as advanced search SearchData
std::shared_ptr<SearchData> sd = xmlToSearchData(xml, false);
if (sd) {
showAdvSearchDialog();
asearchform->fromSearch(sd);
return;
}
LOGDEB("loadSavedQuery: Not advanced search. Parsing as simple search\n");
// Try to parse as Simple Search
SSearchDef sdef;
if (xmlToSSearch(xml, sdef)) {
......
......@@ -364,7 +364,10 @@ bool SSearch::fromXML(const SSearchDef& fxml)
tr("Autophrase is unset but it was set for stored query"));
}
setSearchString(QString::fromUtf8(fxml.text.c_str()));
searchTypCMB->setCurrentIndex(prefs.ssearchTyp);
// We used to use prefs.ssearchTyp here. Not too sure why?
// Minimize user surprise factor ? Anyway it seems cleaner to
// restore the saved search type
searchTypCMB->setCurrentIndex(fxml.mode);
return true;
}
......
......@@ -88,7 +88,7 @@ bool SDHXMLHandler::startElement(const QString & /* namespaceURI */,
// either if type is absent, or if it's searchdata
int idx = attrs.index("type");
if (idx >= 0 && attrs.value(idx).compare("searchdata")) {
LOGDEB("XMLTOSD: bad type\n");
LOGDEB("XMLTOSD: bad type: " << qs2utf8s(attrs.value(idx)) << endl);
return false;
}
resetTemps();
......@@ -206,7 +206,8 @@ bool SDHXMLHandler::endElement(const QString & /* namespaceURI */,
}
std::shared_ptr<Rcl::SearchData> xmlToSearchData(const string& xml)
std::shared_ptr<Rcl::SearchData> xmlToSearchData(const string& xml,
bool verbose)
{
SDHXMLHandler handler;
QXmlSimpleReader reader;
......@@ -217,7 +218,9 @@ std::shared_ptr<Rcl::SearchData> xmlToSearchData(const string& xml)
xmlInputSource.setData(QString::fromUtf8(xml.c_str()));
if (!reader.parse(xmlInputSource) || !handler.isvalid) {
LOGERR("xmlToSearchData: parse failed for [" << xml << "]\n");
if (verbose) {
LOGERR("xmlToSearchData: parse failed for [" << xml << "]\n");
}
return std::shared_ptr<SearchData>();
}
return handler.sd;
......@@ -271,8 +274,13 @@ bool SSHXMLHandler::startElement(const QString & /* namespaceURI */,
if (qName == "SD") {
// Simple search saved data has a type='ssearch' attribute.
int idx = attrs.index("type");
if (idx < 0 && attrs.value(idx).compare("ssearch")) {
LOGDEB("XMLTOSSS: bad type\n");
if (idx < 0 || attrs.value(idx).compare("ssearch")) {
if (idx < 0) {
LOGDEB("XMLTOSSS: bad type\n");
} else {
LOGDEB("XMLTOSSS: bad type: " << qs2utf8s(attrs.value(idx))
<< endl);
}
return false;
}
resetTemps();
......
......@@ -63,9 +63,10 @@
#include <memory>
#include "searchdata.h"
// Parsing XML from advanced search history or saved advanced search to to
// SearchData structure:
std::shared_ptr<Rcl::SearchData> xmlToSearchData(const string& xml);
// Parsing XML from advanced search history or saved advanced search into
// a SearchData structure:
std::shared_ptr<Rcl::SearchData> xmlToSearchData(const string& xml,
bool complain = true);
// Parsing XML from saved simple search to ssearch parameters
struct SSearchDef {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment