File indexing completed on 2024-04-21 05:50:47
0001 /* 0002 SPDX-FileCopyrightText: 2002 Jean-Baptiste Mardelle <bj@altern.org> 0003 SPDX-FileCopyrightText: 2007-2022 Rolf Eike Beer <kde@opensource.sf-tec.de> 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef KEYSMANAGER_H 0008 #define KEYSMANAGER_H 0009 0010 #include "ui_adduid.h" 0011 0012 #include "core/kgpgkey.h" 0013 #include "model/kgpgitemmodel.h" 0014 #include "model/kgpgitemnode.h" 0015 0016 #include <KToggleAction> 0017 #include <KXmlGuiWindow> 0018 0019 #include <QClipboard> 0020 #include <QSet> 0021 #include <QUrl> 0022 0023 class KJob; 0024 0025 class KSelectAction; 0026 0027 class QAction; 0028 class QEvent; 0029 class QKeySequence; 0030 class QLineEdit; 0031 class QMenu; 0032 0033 class KeyServer; 0034 class KgpgEditor; 0035 class KeyServer; 0036 class KeyListProxyModel; 0037 class KeyTreeView; 0038 class KGpgAddUid; 0039 class KGpgDelKey; 0040 class KGpgImport; 0041 class KGpgTransactionJob; 0042 0043 class KStatusNotifierItem; 0044 0045 0046 class AddUid : public QWidget, public Ui::AddUid 0047 { 0048 public: 0049 explicit AddUid( QWidget *parent ) 0050 : QWidget( parent ) 0051 { 0052 setupUi( this ); 0053 } 0054 }; 0055 0056 class KeysManager : public KXmlGuiWindow 0057 { 0058 Q_OBJECT 0059 0060 public: 0061 explicit KeysManager(QWidget *parent = nullptr); 0062 ~KeysManager() override = default; 0063 0064 KGpgItemModel *getModel(); 0065 0066 KgpgEditor *s_kgpgEditor; 0067 0068 void saveToggleOpts(void); 0069 void showTrayMessage(const QString &message); 0070 0071 /** 0072 * @brief returns the shortcut to go to the default key in a key selection 0073 */ 0074 QKeySequence goDefaultShortcut() const; 0075 0076 private: 0077 KToggleAction *sTrust; 0078 KToggleAction *sCreat; 0079 KToggleAction *sExpi; 0080 KToggleAction *sSize; 0081 KToggleAction *hPublic; 0082 KToggleAction *longId; 0083 KSelectAction *photoProps; 0084 KSelectAction *trustProps; 0085 0086 Q_SIGNALS: 0087 void readAgainOptions(); 0088 void certificate(QString); 0089 void closeAsked(); 0090 void fontChanged(QFont); 0091 0092 public Q_SLOTS: 0093 void slotGenerateKey(); 0094 void refreshkey(); 0095 void readAllOptions(); 0096 void showKeyInfo(const QString &keyID); 0097 void slotSetDefaultKey(const QString &newID); 0098 void showKeyManager(); 0099 bool importRemoteKey(const QString &keyIDs); 0100 bool importRemoteKeys(const QStringList &keyIDs, const bool dialog = true); 0101 void showKeyServer(); 0102 void showOptions(); 0103 void slotOpenEditor(); 0104 void slotImport(const QString &text); 0105 void slotImport(const QList<QUrl> &files); 0106 /** 0107 * When you click on "encrypt the clipboard" in the systray, 0108 * this slot will open the dialog to choose a key and encrypt the 0109 * clipboard. 0110 */ 0111 void clipEncrypt(); 0112 void clipDecrypt(); 0113 void clipSign(); 0114 void slotImportDone(int ret); 0115 0116 protected: 0117 void removeFromGroups(KGpgKeyNode *nd); 0118 void setDefaultKeyNode(KGpgKeyNode *key); 0119 0120 private Q_SLOTS: 0121 void slotGenerateKeyDone(KJob *job); 0122 0123 void slotShowTrust(); 0124 void slotShowSize(); 0125 void slotShowCreation(); 0126 void slotShowExpiration(); 0127 0128 void slotAddUidFin(int res); 0129 void slotDelPhotoFinished(int res); 0130 void quitApp(); 0131 void slotShowLongId(bool); 0132 void slotSetTrustFilter(int); 0133 void slotGotoDefaultKey(); 0134 void slotDelUid(); 0135 void slotDelUidDone(int); 0136 void slotPrimUid(); 0137 void slotPrimUidDone(int result); 0138 void slotAddUid(); 0139 void slotAddUidEnable(const QString &name); 0140 void slotUpdatePhoto(); 0141 void slotDeletePhoto(); 0142 void slotAddPhoto(); 0143 void slotAddPhotoFinished(int res); 0144 void slotSetPhotoSize(int size); 0145 void slotShowPhoto(); 0146 void revokeWidget(); 0147 void slotRevokeDialogFinished(int result); 0148 void slotRevokeGenerated(int result); 0149 void doPrint(const QString &txt); 0150 void checkList(); 0151 void slotManpage(); 0152 void slotExportFinished(int result); 0153 void slotProcessExportMail(int result); 0154 void slotProcessExportClip(int result); 0155 void readOptions(); 0156 void slotSetDefKey(); 0157 void confirmdeletekey(); 0158 void deleteseckey(); 0159 void signkey(); 0160 void signuid(); 0161 void caff(); 0162 void slotCaffDone(); 0163 void delsignkey(); 0164 void preimportsignkey(); 0165 void importallsignkey(); 0166 void signatureResult(int success); 0167 void delsignatureResult(int success); 0168 void defaultAction(const QModelIndex &); 0169 void defaultAction(KGpgNode *); 0170 void slotDefaultAction(); 0171 void showProperties(KGpgNode *); 0172 void keyproperties(); 0173 void slotexport(); 0174 void slotexportsec(); 0175 void slotExportSecFinished(int result); 0176 0177 void slotMenu(const QPoint &); 0178 0179 void slotPreImportKey(); 0180 void slotSendEmail(); 0181 void slotedit(); 0182 0183 /** 0184 * @brief start an "add to addressbook" operation 0185 * 0186 * This searches if given id already exists in the addressbook. 0187 * The search result is handled in slotAddressbookSearchResult() 0188 */ 0189 void addToKAB(); 0190 0191 /** 0192 * @brief add or change the addressbook entry 0193 * @param job the search job 0194 * 0195 * This handles the result of the search started in addToKAB(). 0196 */ 0197 void slotAddressbookSearchResult(KJob *job); 0198 0199 void editGroup(); 0200 void createNewGroup(); 0201 void deleteGroup(); 0202 void renameGroup(); 0203 void slotImportRevokeTxt(const QString &revokeText); 0204 void refreshKeyFromServer(); 0205 void slotKeyRefreshDone(int result); 0206 void slotregenerate(); 0207 void secretKeyDeleted(int); 0208 void getMissingSigs(QSet<QString> &missingKeys, const KGpgExpandableNode *nd); 0209 void slotEditDone(int exitcode); 0210 void importRemoteFinished(int result); 0211 void slotDelKeyDone(int ret); 0212 void slotSetClip(int result); 0213 void slotOpenKeyUrl(); 0214 0215 private: 0216 KGpgItemModel *imodel; 0217 KeyListProxyModel *iproxy; 0218 KeyTreeView *iview; 0219 0220 KGpgAddUid *m_adduid; 0221 KGpgTransactionJob *m_genkey; 0222 KGpgDelKey *m_delkey; 0223 0224 QString globalkeyID; 0225 QString searchString; 0226 0227 QList<KGpgSignableNode *> signList; 0228 QList<KGpgKeyNode *> refreshList; 0229 QHash<KJob *, KGpgNode *> m_addIds; ///< user ids to add to addressbook 0230 0231 QClipboard::Mode m_clipboardmode; 0232 0233 QMenu *m_popuppub; // popup on a public key 0234 QMenu *m_popupsec; // popup on a secret key 0235 QMenu *m_popupgroup; // popup on a group 0236 QMenu *m_popupout; // popup there is no key or when the user don't right-click on a key 0237 QMenu *m_popupsig; // popup on a signature 0238 QMenu *m_popupphoto; // popup on a photo 0239 QMenu *m_popupuid; // popup on an user id 0240 QMenu *m_popuporphan; // popup on an orphan key 0241 0242 QLineEdit *m_listviewsearch; 0243 QDialog *addUidWidget; 0244 AddUid *keyUid; 0245 0246 QLabel m_statusBarLabel; 0247 0248 QAction *importSignatureKey; 0249 QAction *importAllSignKeys; 0250 QAction *signKey; 0251 QAction *signUid; 0252 QAction *signMailUid; 0253 QAction *refreshKey; 0254 QAction *editKey; 0255 QAction *setPrimUid; 0256 QAction *delUid; 0257 QAction *delSignKey; 0258 QAction *deleteKey; 0259 QAction *editCurrentGroup; 0260 QAction *delGroup; 0261 QAction *setDefaultKey; 0262 QAction *kserver; 0263 QAction *openEditor; 0264 QAction *goToDefaultKey; 0265 QAction *exportPublicKey; 0266 QAction *m_sendEmail; 0267 QAction *createGroup; 0268 QAction *m_groupRename; 0269 QAction *m_revokeKey; 0270 0271 bool m_signuids; 0272 0273 int keyCount; 0274 0275 KGpgKeyNode *terminalkey; // the key currently edited in a terminal 0276 0277 void startImport(KGpgImport *import); 0278 0279 // react to network status changes 0280 bool m_online; 0281 void toggleNetworkActions(bool online); 0282 0283 KStatusNotifierItem *m_trayicon; 0284 void setupTrayIcon(); 0285 0286 void setActionDescriptions(int cnt); 0287 /** 0288 * @brief show a message in the status bar 0289 * @param msg the text to show 0290 * @param keep if the text should stay visible or may be hidden after a while 0291 */ 0292 void changeMessage(const QString &msg, const bool keep = false); 0293 /** 0294 * @brief update the key and group counter in the status bar 0295 */ 0296 void updateStatusCounter(); 0297 /** 0298 * @brief sign the next key from signList 0299 * @param localsign if signature should be a local (not exportable) one 0300 * @param checklevel how careful the identity of the key was checked 0301 */ 0302 void signLoop(const bool localsign, const int checklevel); 0303 /** 0304 * @brief Opens the console when the user want to sign a key manually. 0305 * @param signer key to sign with 0306 * @param keyid key to sign 0307 * @param checking how careful the identify was checked 0308 * @param local if signature should be local (not exportable) 0309 */ 0310 void signKeyOpenConsole(const QString &signer, const QString &keyid, const int checking, const bool local); 0311 }; 0312 0313 #endif // KEYSMANAGER_H