File indexing completed on 2023-12-03 09:19:02
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 bool eventFilter(QObject *, QEvent *e) override; 0118 void removeFromGroups(KGpgKeyNode *nd); 0119 void setDefaultKeyNode(KGpgKeyNode *key); 0120 0121 private Q_SLOTS: 0122 void slotGenerateKeyDone(KJob *job); 0123 0124 void slotShowTrust(); 0125 void slotShowSize(); 0126 void slotShowCreation(); 0127 void slotShowExpiration(); 0128 0129 void slotAddUidFin(int res); 0130 void slotDelPhotoFinished(int res); 0131 void quitApp(); 0132 void slotShowLongId(bool); 0133 void slotSetTrustFilter(int); 0134 void slotGotoDefaultKey(); 0135 void slotDelUid(); 0136 void slotDelUidDone(int); 0137 void slotPrimUid(); 0138 void slotPrimUidDone(int result); 0139 void slotAddUid(); 0140 void slotAddUidEnable(const QString &name); 0141 void slotUpdatePhoto(); 0142 void slotDeletePhoto(); 0143 void slotAddPhoto(); 0144 void slotAddPhotoFinished(int res); 0145 void slotSetPhotoSize(int size); 0146 void slotShowPhoto(); 0147 void revokeWidget(); 0148 void slotRevokeDialogFinished(int result); 0149 void slotRevokeGenerated(int result); 0150 void doPrint(const QString &txt); 0151 void checkList(); 0152 void slotManpage(); 0153 void slotTip(); 0154 void slotExportFinished(int result); 0155 void slotProcessExportMail(int result); 0156 void slotProcessExportClip(int result); 0157 void readOptions(); 0158 void slotSetDefKey(); 0159 void confirmdeletekey(); 0160 void deleteseckey(); 0161 void signkey(); 0162 void signuid(); 0163 void caff(); 0164 void slotCaffDone(); 0165 void delsignkey(); 0166 void preimportsignkey(); 0167 void importallsignkey(); 0168 void signatureResult(int success); 0169 void delsignatureResult(int success); 0170 void defaultAction(const QModelIndex &); 0171 void defaultAction(KGpgNode *); 0172 void slotDefaultAction(); 0173 void showProperties(KGpgNode *); 0174 void keyproperties(); 0175 void slotexport(); 0176 void slotexportsec(); 0177 void slotExportSecFinished(int result); 0178 0179 void slotMenu(const QPoint &); 0180 0181 void slotPreImportKey(); 0182 void slotSendEmail(); 0183 void slotedit(); 0184 0185 /** 0186 * @brief start an "add to addressbook" operation 0187 * 0188 * This searches if given id already exists in the addressbook. 0189 * The search result is handled in slotAddressbookSearchResult() 0190 */ 0191 void addToKAB(); 0192 0193 /** 0194 * @brief add or change the addressbook entry 0195 * @param job the search job 0196 * 0197 * This handles the result of the search started in addToKAB(). 0198 */ 0199 void slotAddressbookSearchResult(KJob *job); 0200 0201 void editGroup(); 0202 void createNewGroup(); 0203 void deleteGroup(); 0204 void renameGroup(); 0205 void slotImportRevokeTxt(const QString &revokeText); 0206 void refreshKeyFromServer(); 0207 void slotKeyRefreshDone(int result); 0208 void slotregenerate(); 0209 void secretKeyDeleted(int); 0210 void getMissingSigs(QSet<QString> &missingKeys, const KGpgExpandableNode *nd); 0211 void slotEditDone(int exitcode); 0212 void importRemoteFinished(int result); 0213 void slotDelKeyDone(int ret); 0214 void slotSetClip(int result); 0215 void slotOpenKeyUrl(); 0216 0217 private: 0218 KGpgItemModel *imodel; 0219 KeyListProxyModel *iproxy; 0220 KeyTreeView *iview; 0221 0222 KGpgAddUid *m_adduid; 0223 KGpgTransactionJob *m_genkey; 0224 KGpgDelKey *m_delkey; 0225 0226 QString globalkeyID; 0227 QString searchString; 0228 0229 QList<KGpgSignableNode *> signList; 0230 QList<KGpgKeyNode *> refreshList; 0231 QHash<KJob *, KGpgNode *> m_addIds; ///< user ids to add to addressbook 0232 0233 QClipboard::Mode m_clipboardmode; 0234 0235 QMenu *m_popuppub; // popup on a public key 0236 QMenu *m_popupsec; // popup on a secret key 0237 QMenu *m_popupgroup; // popup on a group 0238 QMenu *m_popupout; // popup there is no key or when the user don't right-click on a key 0239 QMenu *m_popupsig; // popup on a signature 0240 QMenu *m_popupphoto; // popup on a photo 0241 QMenu *m_popupuid; // popup on an user id 0242 QMenu *m_popuporphan; // popup on an orphan key 0243 0244 QLineEdit *m_listviewsearch; 0245 QDialog *addUidWidget; 0246 AddUid *keyUid; 0247 0248 QLabel m_statusBarLabel; 0249 0250 QAction *importSignatureKey; 0251 QAction *importAllSignKeys; 0252 QAction *signKey; 0253 QAction *signUid; 0254 QAction *signMailUid; 0255 QAction *refreshKey; 0256 QAction *editKey; 0257 QAction *setPrimUid; 0258 QAction *delUid; 0259 QAction *delSignKey; 0260 QAction *deleteKey; 0261 QAction *editCurrentGroup; 0262 QAction *delGroup; 0263 QAction *setDefaultKey; 0264 QAction *kserver; 0265 QAction *openEditor; 0266 QAction *goToDefaultKey; 0267 QAction *exportPublicKey; 0268 QAction *m_sendEmail; 0269 QAction *createGroup; 0270 QAction *m_groupRename; 0271 QAction *m_revokeKey; 0272 0273 bool showTipOfDay; 0274 bool m_signuids; 0275 0276 int keyCount; 0277 0278 KGpgKeyNode *terminalkey; // the key currently edited in a terminal 0279 0280 void startImport(KGpgImport *import); 0281 0282 // react to network status changes 0283 bool m_online; 0284 void toggleNetworkActions(bool online); 0285 0286 KStatusNotifierItem *m_trayicon; 0287 void setupTrayIcon(); 0288 0289 void setActionDescriptions(int cnt); 0290 /** 0291 * @brief show a message in the status bar 0292 * @param msg the text to show 0293 * @param keep if the text should stay visible or may be hidden after a while 0294 */ 0295 void changeMessage(const QString &msg, const bool keep = false); 0296 /** 0297 * @brief update the key and group counter in the status bar 0298 */ 0299 void updateStatusCounter(); 0300 /** 0301 * @brief sign the next key from signList 0302 * @param localsign if signature should be a local (not exportable) one 0303 * @param checklevel how careful the identity of the key was checked 0304 */ 0305 void signLoop(const bool localsign, const int checklevel); 0306 /** 0307 * @brief Opens the console when the user want to sign a key manually. 0308 * @param signer key to sign with 0309 * @param keyid key to sign 0310 * @param checking how careful the identify was checked 0311 * @param local if signature should be local (not exportable) 0312 */ 0313 void signKeyOpenConsole(const QString &signer, const QString &keyid, const int checking, const bool local); 0314 }; 0315 0316 #endif // KEYSMANAGER_H