diff options
author | saturneric <[email protected]> | 2024-07-29 19:29:56 +0000 |
---|---|---|
committer | saturneric <[email protected]> | 2024-07-29 19:29:56 +0000 |
commit | fa90ec4b5315b9e70a44a9625c143ce253f0e885 (patch) | |
tree | 8ffa82e33522de03974d6d0289aa831b4fd6ebdf /src/ui/widgets/KeyList.h | |
parent | fix: correct urls at appdata.xml (diff) | |
parent | Merge branch 'develop' of github.com:saturneric/GpgFrontend into develop (diff) | |
download | GpgFrontend-fa90ec4b5315b9e70a44a9625c143ce253f0e885.tar.gz GpgFrontend-fa90ec4b5315b9e70a44a9625c143ce253f0e885.zip |
Merge branch 'develop'
Diffstat (limited to 'src/ui/widgets/KeyList.h')
-rw-r--r-- | src/ui/widgets/KeyList.h | 208 |
1 files changed, 65 insertions, 143 deletions
diff --git a/src/ui/widgets/KeyList.h b/src/ui/widgets/KeyList.h index 1761fb23..cbad6812 100644 --- a/src/ui/widgets/KeyList.h +++ b/src/ui/widgets/KeyList.h @@ -28,7 +28,7 @@ #pragma once -#include "core/model/GpgKey.h" +#include "ui/widgets/KeyTable.h" class Ui_KeyList; @@ -38,126 +38,39 @@ namespace GpgFrontend::UI { * @brief * */ -struct KeyListRow { - using KeyType = unsigned int; - - static const KeyType SECRET_OR_PUBLIC_KEY = 0; ///< - static const KeyType ONLY_SECRET_KEY = 1; ///< +enum class KeyMenuAbility : unsigned int { + kNONE = 0, + kREFRESH = 1 << 0, + kSYNC_PUBLIC_KEY = 1 << 1, + kUNCHECK_ALL = 1 << 2, + kCHECK_ALL = 1 << 3, + kCOLUMN_FILTER = 1 << 4, + kSEARCH_BAR = 1 << 5, + + kALL = ~0U }; -/** - * @brief - * - */ -struct KeyListColumn { - using InfoType = unsigned int; - - static constexpr InfoType ALL = ~0; ///< - static constexpr InfoType TYPE = 1 << 0; ///< - static constexpr InfoType NAME = 1 << 1; ///< - static constexpr InfoType EmailAddress = 1 << 2; ///< - static constexpr InfoType Usage = 1 << 3; ///< - static constexpr InfoType Validity = 1 << 4; ///< - static constexpr InfoType FingerPrint = 1 << 5; ///< - static constexpr InfoType KeyID = 1 << 6; ///< -}; +inline auto operator|(KeyMenuAbility lhs, KeyMenuAbility rhs) + -> KeyMenuAbility { + using T = std::underlying_type_t<KeyMenuAbility>; + return static_cast<KeyMenuAbility>(static_cast<T>(lhs) | static_cast<T>(rhs)); +} -/** - * @brief - * - */ -struct KeyMenuAbility { - using AbilityType = unsigned int; - - static constexpr AbilityType ALL = ~0; ///< - static constexpr AbilityType NONE = 0; ///< - static constexpr AbilityType REFRESH = 1 << 0; ///< - static constexpr AbilityType SYNC_PUBLIC_KEY = 1 << 1; ///< - static constexpr AbilityType UNCHECK_ALL = 1 << 3; ///< - static constexpr AbilityType CHECK_ALL = 1 << 5; ///< - static constexpr AbilityType SEARCH_BAR = 1 << 6; ///< -}; +inline auto operator|=(KeyMenuAbility& lhs, KeyMenuAbility rhs) + -> KeyMenuAbility& { + lhs = lhs | rhs; + return lhs; +} -/** - * @brief - * - */ -struct KeyTable { - using KeyTableFilter = std::function<bool(const GpgKey&, const KeyTable&)>; - - QTableWidget* key_list_; ///< - KeyListRow::KeyType select_type_; ///< - KeyListColumn::InfoType info_type_; ///< - std::vector<GpgKey> buffered_keys_; ///< - KeyTableFilter filter_; ///< - KeyIdArgsListPtr checked_key_ids_; ///< - KeyMenuAbility::AbilityType ability_; ///< - QString keyword_; ///< +inline auto operator&(KeyMenuAbility lhs, KeyMenuAbility rhs) -> bool { + using T = std::underlying_type_t<KeyMenuAbility>; + return (static_cast<T>(lhs) & static_cast<T>(rhs)) != 0; +} - /** - * @brief Construct a new Key Table object - * - * @param _key_list - * @param _select_type - * @param _info_type - * @param _filter - */ - KeyTable( - QTableWidget* _key_list, KeyListRow::KeyType _select_type, - KeyListColumn::InfoType _info_type, - KeyTableFilter _filter = [](const GpgKey&, const KeyTable&) -> bool { - return true; - }) - : key_list_(_key_list), - select_type_(_select_type), - info_type_(_info_type), - filter_(std::move(_filter)) {} - - /** - * @brief - * - * @param m_keys - */ - void Refresh(KeyLinkListPtr m_keys = nullptr); - - /** - * @brief Get the Checked object - * - * @return KeyIdArgsListPtr& - */ - KeyIdArgsListPtr& GetChecked(); - - /** - * @brief - * - */ - void UncheckALL() const; - - /** - * @brief - * - */ - void CheckALL() const; - - /** - * @brief Set the Checked object - * - * @param key_ids - */ - void SetChecked(KeyIdArgsListPtr key_ids); - - /** - * @brief - * - */ - void SetMenuAbility(KeyMenuAbility::AbilityType ability); - - /** - * @brief - * - */ - void SetFilterKeyword(QString keyword); -}; +inline auto operator~(KeyMenuAbility hs) -> KeyMenuAbility { + using T = std::underlying_type_t<GpgKeyTableColumn>; + return static_cast<KeyMenuAbility>(~static_cast<T>(hs)); +} /** * @brief @@ -173,8 +86,10 @@ class KeyList : public QWidget { * @param menu_ability * @param parent */ - explicit KeyList(KeyMenuAbility::AbilityType menu_ability, - QWidget* parent = nullptr); + explicit KeyList( + KeyMenuAbility menu_ability, + GpgKeyTableColumn fixed_column_filter = GpgKeyTableColumn::kALL, + QWidget* parent = nullptr); /** * @brief @@ -186,10 +101,11 @@ class KeyList : public QWidget { */ void AddListGroupTab( const QString& name, const QString& id, - KeyListRow::KeyType selectType = KeyListRow::SECRET_OR_PUBLIC_KEY, - KeyListColumn::InfoType infoType = KeyListColumn::ALL, - KeyTable::KeyTableFilter filter = - [](const GpgKey&, const KeyTable&) -> bool { return true; }); + GpgKeyTableDisplayMode display_mode = + GpgKeyTableDisplayMode::kPRIVATE_KEY, + GpgKeyTableProxyModel::KeyFilter search_filter = + [](const GpgKey&) -> bool { return true; }, + GpgKeyTableColumn custom_columns_filter = GpgKeyTableColumn::kALL); /** * @brief Set the Double Clicked Action object @@ -259,17 +175,10 @@ class KeyList : public QWidget { /** * @brief Set the Checked object * - * @param key_ids - */ - void SetChecked(KeyIdArgsListPtr key_ids); - - /** - * @brief Set the Checked object - * * @param keyIds * @param key_table */ - static void SetChecked(const KeyIdArgsListPtr& keyIds, + static void SetChecked(const KeyIdArgsListPtr& key_ids, const KeyTable& key_table); /** @@ -294,6 +203,12 @@ class KeyList : public QWidget { */ [[maybe_unused]] auto ContainsPrivateKeys() -> bool; + /** + * @brief + * + */ + void UpdateKeyTableColumnType(GpgKeyTableColumn); + signals: /** * @brief @@ -309,6 +224,14 @@ class KeyList : public QWidget { */ void SignalRefreshDatabase(); + signals: + + /** + * @brief + * + */ + void SignalColumnTypeChange(GpgKeyTableColumn); + public slots: /** @@ -335,7 +258,7 @@ class KeyList : public QWidget { * * @param inBuffer */ - void import_keys(const QByteArray& inBuffer); + void import_keys(const QByteArray& in_buffer); /** * @brief @@ -355,15 +278,20 @@ class KeyList : public QWidget { */ void filter_by_keyword(); - std::mutex buffered_key_list_mutex_; ///< - std::shared_ptr<Ui_KeyList> ui_; ///< - QTableWidget* m_key_list_{}; ///< - std::vector<KeyTable> m_key_tables_; ///< QMenu* popup_menu_{}; ///< - GpgFrontend::KeyLinkListPtr buffered_keys_list_; ///< std::function<void(const GpgKey&, QWidget*)> m_action_ = nullptr; ///< - KeyMenuAbility::AbilityType menu_ability_ = KeyMenuAbility::ALL; ///< + KeyMenuAbility menu_ability_ = KeyMenuAbility::kALL; ///< + QSharedPointer<GpgKeyTableModel> model_; + GpgKeyTableColumn fixed_columns_filter_; + GpgKeyTableColumn global_column_filter_; + + QAction* key_id_column_action_; + QAction* algo_column_action_; + QAction* create_date_column_action_; + QAction* owner_trust_column_action_; + QAction* subkeys_number_column_action_; + QAction* comment_column_action_; private slots: @@ -378,12 +306,6 @@ class KeyList : public QWidget { * @brief * */ - void slot_refresh_ui(); - - /** - * @brief - * - */ void slot_sync_with_key_server(); protected: |