1 /*
2  *  Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
3  *
4  *  This program is free software: you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation, either version 2 or (at your option)
7  *  version 3 of the License.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef KEEPASSX_DETAILSWIDGET_H
19 #define KEEPASSX_DETAILSWIDGET_H
20 
21 #include "config-keepassx.h"
22 #include "gui/DatabaseWidget.h"
23 
24 #include <QWidget>
25 
26 namespace Ui
27 {
28     class EntryPreviewWidget;
29 }
30 
31 class QTextEdit;
32 
33 class EntryPreviewWidget : public QWidget
34 {
35     Q_OBJECT
36 
37 public:
38     explicit EntryPreviewWidget(QWidget* parent = nullptr);
39     ~EntryPreviewWidget() override;
40 
41 public slots:
42     void setEntry(Entry* selectedEntry);
43     void setGroup(Group* selectedGroup);
44     void setDatabaseMode(DatabaseWidget::Mode mode);
45 
46 signals:
47     void errorOccurred(const QString& error);
48     void entryUrlActivated(Entry* entry);
49 
50 private slots:
51     void updateEntryHeaderLine();
52     void updateEntryTotp();
53     void updateEntryGeneralTab();
54     void updateEntryAdvancedTab();
55     void updateEntryAutotypeTab();
56     void setPasswordVisible(bool state);
57     void setEntryNotesVisible(bool state);
58     void setGroupNotesVisible(bool state);
59     void setNotesVisible(QTextEdit* notesWidget, const QString& notes, bool state);
60 
61     void updateGroupHeaderLine();
62     void updateGroupGeneralTab();
63 #if defined(WITH_XC_KEESHARE)
64     void updateGroupSharingTab();
65 #endif
66 
67     void updateTotpLabel();
68     void updateTabIndexes();
69     void openEntryUrl();
70 
71 private:
72     void removeTab(QTabWidget* tabWidget, QWidget* widget);
73     void setTabEnabled(QTabWidget* tabWidget, QWidget* widget, bool enabled);
74 
75     static QString hierarchy(const Group* group, const QString& title);
76 
77     const QScopedPointer<Ui::EntryPreviewWidget> m_ui;
78     bool m_locked;
79     QPointer<Entry> m_currentEntry;
80     QPointer<Group> m_currentGroup;
81     QTimer m_totpTimer;
82     quint8 m_selectedTabEntry;
83     quint8 m_selectedTabGroup;
84 };
85 
86 #endif // KEEPASSX_DETAILSWIDGET_H
87