resolve URL for correct favicon downloading, fixes #240 #238

This commit is contained in:
thez3ro 2017-06-29 19:54:49 +02:00 committed by Janek Bevendorff
parent 98c812a297
commit 35c6df2535
6 changed files with 39 additions and 5 deletions

View File

@ -237,6 +237,11 @@ QString Entry::url() const
return m_attributes->value(EntryAttributes::URLKey); return m_attributes->value(EntryAttributes::URLKey);
} }
QString Entry::webUrl() const
{
return resolveUrl(m_attributes->value(EntryAttributes::URLKey));
}
QString Entry::username() const QString Entry::username() const
{ {
return m_attributes->value(EntryAttributes::UserNameKey); return m_attributes->value(EntryAttributes::UserNameKey);
@ -784,3 +789,23 @@ QString Entry::resolvePlaceholder(const QString& str) const
return result; return result;
} }
QString Entry::resolveUrl(const QString& url) const
{
QString newurl = url;
if (!url.contains("://")) {
// URL doesn't have a protocol, add https by default
newurl.prepend("https://");
}
QUrl uurl = QUrl(newurl);
if(uurl.scheme() == "cmd") {
// URL is a cmd, hopefully the second argument it's an URL
QStringList cmd = newurl.split(" ");
return resolveUrl(cmd[1].remove("'").remove("\""));
} else if(uurl.scheme() != "http" && uurl.scheme() != "https") {
// URL isn't very nice
return QString("");
}
return uurl.url();
}

View File

@ -78,6 +78,7 @@ public:
const AutoTypeAssociations* autoTypeAssociations() const; const AutoTypeAssociations* autoTypeAssociations() const;
QString title() const; QString title() const;
QString url() const; QString url() const;
QString webUrl() const;
QString username() const; QString username() const;
QString password() const; QString password() const;
QString notes() const; QString notes() const;
@ -143,6 +144,7 @@ public:
void copyDataFrom(const Entry* other); void copyDataFrom(const Entry* other);
QString resolveMultiplePlaceholders(const QString& str) const; QString resolveMultiplePlaceholders(const QString& str) const;
QString resolvePlaceholder(const QString& str) const; QString resolvePlaceholder(const QString& str) const;
QString resolveUrl(const QString& url) const;
/** /**
* Call before and after set*() methods to create a history item * Call before and after set*() methods to create a history item

View File

@ -223,8 +223,15 @@ void EditWidgetIcons::fetchFavicon(const QUrl& url)
} }
m_httpClient->setConnectingTimeOut(5000, [this]() { m_httpClient->setConnectingTimeOut(5000, [this]() {
resetFaviconDownload(); QUrl tempurl = QUrl(m_url);
MessageBox::warning(this, tr("Error"), tr("Unable to fetch favicon.")); if (tempurl.scheme() == "http") {
resetFaviconDownload();
MessageBox::warning(this, tr("Error"), tr("Unable to fetch favicon."));
} else {
tempurl.setScheme("http");
tempurl.setPath("/favicon.ico");
fetchFavicon(tempurl);
}
}); });
m_ui->faviconButton->setDisabled(true); m_ui->faviconButton->setDisabled(true);

View File

@ -363,7 +363,7 @@ void EditEntryWidget::setForms(const Entry* entry, bool restore)
IconStruct iconStruct; IconStruct iconStruct;
iconStruct.uuid = entry->iconUuid(); iconStruct.uuid = entry->iconUuid();
iconStruct.number = entry->iconNumber(); iconStruct.number = entry->iconNumber();
m_iconsWidget->load(entry->uuid(), m_database, iconStruct, entry->url()); m_iconsWidget->load(entry->uuid(), m_database, iconStruct, entry->webUrl());
connect(m_mainUi->urlEdit, SIGNAL(textChanged(QString)), m_iconsWidget, SLOT(setUrl(QString))); connect(m_mainUi->urlEdit, SIGNAL(textChanged(QString)), m_iconsWidget, SLOT(setUrl(QString)));
m_autoTypeUi->enableButton->setChecked(entry->autoTypeEnabled()); m_autoTypeUi->enableButton->setChecked(entry->autoTypeEnabled());

View File

@ -203,7 +203,7 @@ QList<Entry*> Service::searchEntries(Database* db, const QString& hostname)
const auto results = EntrySearcher().search(hostname, rootGroup, Qt::CaseInsensitive); const auto results = EntrySearcher().search(hostname, rootGroup, Qt::CaseInsensitive);
for (Entry* entry: results) { for (Entry* entry: results) {
QString title = entry->title(); QString title = entry->title();
QString url = entry->url(); QString url = entry->webUrl();
//Filter to match hostname in Title and Url fields //Filter to match hostname in Title and Url fields
if ( (!title.isEmpty() && hostname.contains(title)) if ( (!title.isEmpty() && hostname.contains(title))

View File

@ -98,7 +98,7 @@ set(TEST_LIBRARIES
set(testsupport_SOURCES modeltest.cpp FailDevice.cpp) set(testsupport_SOURCES modeltest.cpp FailDevice.cpp)
add_library(testsupport STATIC ${testsupport_SOURCES}) add_library(testsupport STATIC ${testsupport_SOURCES})
target_link_libraries(testsupport ${MHD_LIBRARIES} Qt5::Core Qt5::Concurrent Qt5::Widgets Qt5::Test) target_link_libraries(testsupport Qt5::Core Qt5::Concurrent Qt5::Widgets Qt5::Test)
if(YUBIKEY_FOUND) if(YUBIKEY_FOUND)
set(TEST_LIBRARIES ${TEST_LIBRARIES} ${YUBIKEY_LIBRARIES}) set(TEST_LIBRARIES ${TEST_LIBRARIES} ${YUBIKEY_LIBRARIES})