mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-02-17 21:04:19 -05:00
Use EntryAttachmentsWidget in details view
This commit is contained in:
parent
c490c21cd5
commit
80636ab083
@ -39,12 +39,11 @@ DetailsWidget::DetailsWidget(QWidget* parent)
|
|||||||
, m_currentEntry(nullptr)
|
, m_currentEntry(nullptr)
|
||||||
, m_currentGroup(nullptr)
|
, m_currentGroup(nullptr)
|
||||||
, m_timer(nullptr)
|
, m_timer(nullptr)
|
||||||
, m_attributesWidget(nullptr)
|
, m_attributesTabWidget(nullptr)
|
||||||
, m_attachmentsWidget(nullptr)
|
, m_attachmentsTabWidget(nullptr)
|
||||||
, m_autotypeWidget(nullptr)
|
, m_autotypeTabWidget(nullptr)
|
||||||
, m_selectedTabEntry(0)
|
, m_selectedTabEntry(0)
|
||||||
, m_selectedTabGroup(0)
|
, m_selectedTabGroup(0)
|
||||||
, m_attachmentsModel(new EntryAttachmentsModel(this))
|
|
||||||
{
|
{
|
||||||
m_ui->setupUi(this);
|
m_ui->setupUi(this);
|
||||||
|
|
||||||
@ -59,16 +58,12 @@ DetailsWidget::DetailsWidget(QWidget* parent)
|
|||||||
connect(m_ui->closeButton, SIGNAL(toggled(bool)), SLOT(hideDetails()));
|
connect(m_ui->closeButton, SIGNAL(toggled(bool)), SLOT(hideDetails()));
|
||||||
connect(m_ui->tabWidget, SIGNAL(tabBarClicked(int)), SLOT(updateTabIndex(int)));
|
connect(m_ui->tabWidget, SIGNAL(tabBarClicked(int)), SLOT(updateTabIndex(int)));
|
||||||
|
|
||||||
m_ui->attachmentsTableView->setModel(m_attachmentsModel);
|
m_ui->attachmentsWidget->setReadOnly(true);
|
||||||
m_ui->attachmentsTableView->horizontalHeader()->setStretchLastSection(true);
|
m_ui->attachmentsWidget->setButtonsVisible(false);
|
||||||
m_ui->attachmentsTableView->horizontalHeader()->resizeSection(0, 600);
|
|
||||||
m_ui->attachmentsTableView->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
||||||
m_ui->attachmentsTableView->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
||||||
connect(m_ui->attachmentsTableView, SIGNAL(activated(QModelIndex)), SLOT(openAttachment(QModelIndex)));
|
|
||||||
|
|
||||||
m_attributesWidget = m_ui->tabWidget->widget(AttributesTab);
|
m_attributesTabWidget = m_ui->tabWidget->widget(AttributesTab);
|
||||||
m_attachmentsWidget = m_ui->tabWidget->widget(AttachmentsTab);
|
m_attachmentsTabWidget = m_ui->tabWidget->widget(AttachmentsTab);
|
||||||
m_autotypeWidget = m_ui->tabWidget->widget(AutotypeTab);
|
m_autotypeTabWidget = m_ui->tabWidget->widget(AutotypeTab);
|
||||||
|
|
||||||
this->hide();
|
this->hide();
|
||||||
}
|
}
|
||||||
@ -93,9 +88,9 @@ void DetailsWidget::getSelectedEntry(Entry* selectedEntry)
|
|||||||
m_ui->stackedWidget->setCurrentIndex(EntryPreview);
|
m_ui->stackedWidget->setCurrentIndex(EntryPreview);
|
||||||
|
|
||||||
if (m_ui->tabWidget->count() < 5) {
|
if (m_ui->tabWidget->count() < 5) {
|
||||||
m_ui->tabWidget->insertTab(static_cast<int>(AttributesTab), m_attributesWidget, "Attributes");
|
m_ui->tabWidget->insertTab(static_cast<int>(AttributesTab), m_attributesTabWidget, tr("Attributes"));
|
||||||
m_ui->tabWidget->insertTab(static_cast<int>(AttachmentsTab), m_attachmentsWidget, "Attachments");
|
m_ui->tabWidget->insertTab(static_cast<int>(AttachmentsTab), m_attachmentsTabWidget, tr("Attachments"));
|
||||||
m_ui->tabWidget->insertTab(static_cast<int>(AutotypeTab), m_autotypeWidget, "Autotype");
|
m_ui->tabWidget->insertTab(static_cast<int>(AutotypeTab), m_autotypeTabWidget, tr("Autotype"));
|
||||||
}
|
}
|
||||||
|
|
||||||
m_ui->tabWidget->setTabEnabled(AttributesTab, false);
|
m_ui->tabWidget->setTabEnabled(AttributesTab, false);
|
||||||
@ -193,7 +188,7 @@ void DetailsWidget::getSelectedEntry(Entry* selectedEntry)
|
|||||||
|
|
||||||
const bool hasAttachments = !m_currentEntry->attachments()->isEmpty();
|
const bool hasAttachments = !m_currentEntry->attachments()->isEmpty();
|
||||||
m_ui->tabWidget->setTabEnabled(AttachmentsTab, hasAttachments);
|
m_ui->tabWidget->setTabEnabled(AttachmentsTab, hasAttachments);
|
||||||
m_attachmentsModel->setEntryAttachments(hasAttachments ? m_currentEntry->attachments() : nullptr);
|
m_ui->attachmentsWidget->setEntryAttachments(m_currentEntry->attachments());
|
||||||
|
|
||||||
m_ui->autotypeTree->clear();
|
m_ui->autotypeTree->clear();
|
||||||
AutoTypeAssociations* autotypeAssociations = m_currentEntry->autoTypeAssociations();
|
AutoTypeAssociations* autotypeAssociations = m_currentEntry->autoTypeAssociations();
|
||||||
@ -359,28 +354,3 @@ void DetailsWidget::updateTabIndex(int index)
|
|||||||
m_selectedTabEntry = index;
|
m_selectedTabEntry = index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DetailsWidget::openAttachment(const QModelIndex& index)
|
|
||||||
{
|
|
||||||
Q_ASSERT(m_currentEntry != nullptr);
|
|
||||||
const QString filename = m_attachmentsModel->keyByIndex(index);
|
|
||||||
const QByteArray attachmentData = m_currentEntry->attachments()->value(filename);
|
|
||||||
|
|
||||||
// tmp file will be removed once the database (or the application) has been closed
|
|
||||||
const QString tmpFileTemplate = QDir::temp().absoluteFilePath(QString("XXXXXX.").append(filename));
|
|
||||||
QTemporaryFile* tmpFile = new QTemporaryFile(tmpFileTemplate, this);
|
|
||||||
|
|
||||||
const bool saveOk = tmpFile->open()
|
|
||||||
&& tmpFile->write(attachmentData) == attachmentData.size()
|
|
||||||
&& tmpFile->flush();
|
|
||||||
|
|
||||||
if (!saveOk) {
|
|
||||||
delete tmpFile;
|
|
||||||
emit errorOccurred(tr("Unable to open the attachment:\n").append(tmpFile->errorString()));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpFile->close();
|
|
||||||
QDesktopServices::openUrl(QUrl::fromLocalFile(tmpFile->fileName()));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@ -25,8 +25,6 @@ namespace Ui {
|
|||||||
class DetailsWidget;
|
class DetailsWidget;
|
||||||
}
|
}
|
||||||
|
|
||||||
class EntryAttachmentsModel;
|
|
||||||
|
|
||||||
class DetailsWidget : public QWidget
|
class DetailsWidget : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -62,7 +60,6 @@ private slots:
|
|||||||
void hideDetails();
|
void hideDetails();
|
||||||
void setDatabaseMode(DatabaseWidget::Mode mode);
|
void setDatabaseMode(DatabaseWidget::Mode mode);
|
||||||
void updateTabIndex(int index);
|
void updateTabIndex(int index);
|
||||||
void openAttachment(const QModelIndex& index);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const QScopedPointer<Ui::DetailsWidget> m_ui;
|
const QScopedPointer<Ui::DetailsWidget> m_ui;
|
||||||
@ -71,12 +68,11 @@ private:
|
|||||||
Group* m_currentGroup;
|
Group* m_currentGroup;
|
||||||
quint8 m_step;
|
quint8 m_step;
|
||||||
QTimer* m_timer;
|
QTimer* m_timer;
|
||||||
QWidget* m_attributesWidget;
|
QWidget* m_attributesTabWidget;
|
||||||
QWidget* m_attachmentsWidget;
|
QWidget* m_attachmentsTabWidget;
|
||||||
QWidget* m_autotypeWidget;
|
QWidget* m_autotypeTabWidget;
|
||||||
quint8 m_selectedTabEntry;
|
quint8 m_selectedTabEntry;
|
||||||
quint8 m_selectedTabGroup;
|
quint8 m_selectedTabGroup;
|
||||||
EntryAttachmentsModel* const m_attachmentsModel;
|
|
||||||
QString shortUrl(QString url);
|
QString shortUrl(QString url);
|
||||||
QString shortPassword(QString password);
|
QString shortPassword(QString password);
|
||||||
};
|
};
|
||||||
|
@ -2,14 +2,6 @@
|
|||||||
<ui version="4.0">
|
<ui version="4.0">
|
||||||
<class>DetailsWidget</class>
|
<class>DetailsWidget</class>
|
||||||
<widget class="QWidget" name="DetailsWidget">
|
<widget class="QWidget" name="DetailsWidget">
|
||||||
<property name="geometry">
|
|
||||||
<rect>
|
|
||||||
<x>0</x>
|
|
||||||
<y>0</y>
|
|
||||||
<width>600</width>
|
|
||||||
<height>200</height>
|
|
||||||
</rect>
|
|
||||||
</property>
|
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0,0,0,0,0,0">
|
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,0,0,0,0,0,0">
|
||||||
@ -460,7 +452,7 @@
|
|||||||
</attribute>
|
</attribute>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_6">
|
<layout class="QVBoxLayout" name="verticalLayout_6">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTableView" name="attachmentsTableView"/>
|
<widget class="EntryAttachmentsWidget" name="attachmentsWidget" native="true"/>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
@ -543,6 +535,14 @@
|
|||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>EntryAttachmentsWidget</class>
|
||||||
|
<extends>QWidget</extends>
|
||||||
|
<header>gui/entry/EntryAttachmentsWidget.h</header>
|
||||||
|
<container>1</container>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user