Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show all url schemas in entry view #1768

Merged
merged 2 commits into from
Jul 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/core/Entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,7 @@ QString Entry::webUrl() const
QString Entry::displayUrl() const
{
QString url = maskPasswordPlaceholders(m_attributes->value(EntryAttributes::URLKey));
url = resolveMultiplePlaceholders(url);
return resolveUrl(url);
return resolveMultiplePlaceholders(url);
}

QString Entry::username() const
Expand Down
10 changes: 8 additions & 2 deletions src/core/Uuid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,19 @@ bool Uuid::operator!=(const Uuid& other) const
Uuid Uuid::fromBase64(const QString& str)
{
QByteArray data = QByteArray::fromBase64(str.toLatin1());
return Uuid(data);
if (data.size() == Uuid::Length) {
return Uuid(data);
}
return {};
}

Uuid Uuid::fromHex(const QString& str)
{
QByteArray data = QByteArray::fromHex(str.toLatin1());
return Uuid(data);
if (data.size() == Uuid::Length) {
return Uuid(data);
}
return {};
}

uint qHash(const Uuid& key)
Expand Down
28 changes: 13 additions & 15 deletions src/gui/DatabaseWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -633,25 +633,22 @@ void DatabaseWidget::openUrl()

void DatabaseWidget::openUrlForEntry(Entry* entry)
{
QString urlString = entry->resolveMultiplePlaceholders(entry->url());
if (urlString.isEmpty()) {
return;
}

if (urlString.startsWith("cmd://")) {
QString cmdString = entry->resolveMultiplePlaceholders(entry->url());
if (cmdString.startsWith("cmd://")) {
// check if decision to execute command was stored
if (entry->attributes()->hasKey(EntryAttributes::RememberCmdExecAttr)) {
if (entry->attributes()->value(EntryAttributes::RememberCmdExecAttr) == "1") {
QProcess::startDetached(urlString.mid(6));
QProcess::startDetached(cmdString.mid(6));
}
return;
}

// otherwise ask user
if (urlString.length() > 6) {
QString cmdTruncated = urlString.mid(6);
if (cmdTruncated.length() > 400)
if (cmdString.length() > 6) {
QString cmdTruncated = cmdString.mid(6);
if (cmdTruncated.length() > 400) {
cmdTruncated = cmdTruncated.left(400) + " […]";
}
QMessageBox msgbox(QMessageBox::Icon::Question,
tr("Execute command?"),
tr("Do you really want to execute the following command?<br><br>%1<br>")
Expand All @@ -672,18 +669,19 @@ void DatabaseWidget::openUrlForEntry(Entry* entry)

int result = msgbox.exec();
if (result == QMessageBox::Yes) {
QProcess::startDetached(urlString.mid(6));
QProcess::startDetached(cmdString.mid(6));
}

if (remember) {
entry->attributes()->set(EntryAttributes::RememberCmdExecAttr,
result == QMessageBox::Yes ? "1" : "0");
}
}
}
else {
QUrl url = QUrl::fromUserInput(urlString);
QDesktopServices::openUrl(url);
} else {
QString urlString = entry->webUrl();
if (!urlString.isEmpty()) {
QDesktopServices::openUrl(urlString);
}
}
}

Expand Down
8 changes: 3 additions & 5 deletions src/gui/DetailsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,15 @@ void DetailsWidget::updateEntryGeneralTab()
m_ui->entryPasswordLabel->setToolTip({});
}

m_ui->entryUrlLabel->setRawText(m_currentEntry->displayUrl());
const QString url = m_currentEntry->webUrl();
if (!url.isEmpty()) {
// URL is well formed and can be opened in a browser
// create a new display url that masks password placeholders
// the actual link will use the password
m_ui->entryUrlLabel->setRawText(m_currentEntry->displayUrl());
m_ui->entryUrlLabel->setUrl(url);
m_ui->entryUrlLabel->setCursor(Qt::PointingHandCursor);
} else {
// Fallback to the raw url string
m_ui->entryUrlLabel->setRawText(m_currentEntry->resolveMultiplePlaceholders(m_currentEntry->url()));
m_ui->entryUrlLabel->setUrl({});
m_ui->entryUrlLabel->setCursor(Qt::ArrowCursor);
}

const TimeInfo entryTime = m_currentEntry->timeInfo();
Expand Down
3 changes: 3 additions & 0 deletions src/gui/DetailsWidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@
<property name="text">
<string/>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse</set>
</property>
</widget>
</item>
<item row="0" column="2">
Expand Down