00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "keysmanager.h"
00019
00020 #include <QApplication>
00021 #include <QDesktopWidget>
00022 #include <QKeySequence>
00023 #include <QTextStream>
00024 #include <QClipboard>
00025 #include <QPainter>
00026 #include <QPrinter>
00027 #include <QPrintDialog>
00028 #include <QWidget>
00029 #include <QLabel>
00030 #include <QTimer>
00031 #include <QEvent>
00032 #include <QMovie>
00033 #include <QList>
00034 #include <QFile>
00035 #include <QDir>
00036 #include <QtDBus/QtDBus>
00037 #include <QProcess>
00038
00039 #include <kabc/addresseedialog.h>
00040 #include <kabc/stdaddressbook.h>
00041 #include <KToolInvocation>
00042 #include <KStandardDirs>
00043 #include <KPassivePopup>
00044 #include <KInputDialog>
00045 #include <KFileDialog>
00046 #include <KMessageBox>
00047 #include <KFindDialog>
00048 #include <KService>
00049 #include <KMimeTypeTrader>
00050 #include <KLineEdit>
00051 #include <KMimeType>
00052 #include <KShortcut>
00053 #include <KStandardShortcut>
00054 #include <KLocale>
00055 #include <KProcess>
00056 #include <KAction>
00057 #include <KDebug>
00058 #include <KFind>
00059 #include <KMenu>
00060 #include <KUrl>
00061 #include <ktip.h>
00062 #include <KActionCollection>
00063 #include <KStandardAction>
00064 #include <KSelectAction>
00065 #include <KIcon>
00066 #include <KVBox>
00067 #include <KToggleAction>
00068 #include <KStatusBar>
00069 #include <KToolBar>
00070
00071 #include "kgpgkey.h"
00072 #include "selectsecretkey.h"
00073 #include "newkey.h"
00074 #include "kgpg.h"
00075 #include "kgpgeditor.h"
00076 #include "keyexport.h"
00077 #include "kgpgrevokewidget.h"
00078 #include "keyservers.h"
00079 #include "kgpginterface.h"
00080 #include "kgpgsettings.h"
00081 #include "kgpgkeygenerate.h"
00082 #include "kgpgoptions.h"
00083 #include "keyinfodialog.h"
00084 #include "kgpglibrary.h"
00085 #include "keyadaptor.h"
00086 #include "images.h"
00087 #include "sourceselect.h"
00088 #include "keylistproxymodel.h"
00089 #include "keytreeview.h"
00090 #include "groupedit.h"
00091 #include "kgpgchangekey.h"
00092 #include "kgpgdeluid.h"
00093 #include "kgpgaddphoto.h"
00094
00095 using namespace KgpgCore;
00096
00097 KeysManager::KeysManager(QWidget *parent)
00098 : KXmlGuiWindow(parent)
00099 {
00100 new KeyAdaptor(this);
00101 QDBusConnection::sessionBus().registerObject("/KeyInterface", this);
00102
00103 setAttribute(Qt::WA_DeleteOnClose, false);
00104 setWindowTitle(i18n("Key Management"));
00105
00106 m_statusbartimer = new QTimer(this);
00107 m_statusbar = 0;
00108 imodel = NULL;
00109 readOptions();
00110
00111 terminalkey = NULL;
00112 delkey = NULL;
00113
00114 if (showTipOfDay)
00115 installEventFilter(this);
00116
00117 KStandardAction::quit(this, SLOT(quitApp()), actionCollection());
00118 KStandardAction::find(this, SLOT(findKey()), actionCollection());
00119 KStandardAction::findNext(this, SLOT(findNextKey()), actionCollection());
00120 actionCollection()->addAction(KStandardAction::Preferences, "options_configure", this, SLOT(showOptions()));
00121
00122 QAction *action = 0;
00123
00124 action = actionCollection()->addAction( "default" );
00125 connect(action, SIGNAL(triggered(bool)), SLOT(slotDefaultAction()));
00126 action->setShortcut(QKeySequence(Qt::Key_Return));
00127
00128 action = actionCollection()->addAction( "key_server" );
00129 action->setText( i18n("&Key Server Dialog") );
00130 action->setIcon( KIcon("network-server") );
00131 connect(action, SIGNAL(triggered(bool)), SLOT(showKeyServer()));
00132
00133 action = actionCollection()->addAction( "help_tipofday");
00134 action->setIcon( KIcon("help-hint") );
00135 action->setText( i18n("Tip of the &Day") );
00136 connect(action, SIGNAL(triggered(bool)), SLOT(slotTip()));
00137
00138 action = actionCollection()->addAction( "gpg_man");
00139 action->setText( i18n("View GnuPG Manual") );
00140 action->setIcon( KIcon("help-contents") );
00141 connect(action, SIGNAL(triggered(bool)), SLOT(slotManpage()));
00142
00143 action = actionCollection()->addAction("kgpg_editor");
00144 action->setIcon(KIcon("accessories-text-editor"));
00145 action->setText(i18n("&Open Editor"));
00146 connect(action, SIGNAL(triggered(bool)), SLOT(slotOpenEditor()));
00147
00148 action = actionCollection()->addAction("go_default_key");
00149 action->setIcon(KIcon("go-home"));
00150 action->setText(i18n("&Go to Default Key"));
00151 connect(action, SIGNAL(triggered(bool)), SLOT(slotGotoDefaultKey()));
00152 action->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Home));
00153
00154 action = actionCollection()->addAction("key_refresh");
00155 action->setIcon(KIcon("view-refresh"));
00156 action->setText(i18n("&Refresh List"));
00157 connect(action, SIGNAL(triggered(bool)), SLOT(refreshkey()));
00158 action->setShortcuts(KStandardShortcut::reload());
00159
00160 hPublic = actionCollection()->add<KToggleAction>("show_secret");
00161 hPublic->setIcon(KIcon("view-key-secret"));
00162 hPublic->setText(i18n("&Show only Secret Keys"));
00163 hPublic->setChecked(KGpgSettings::showSecret());
00164 connect(hPublic, SIGNAL(triggered(bool)), SLOT(slotToggleSecret(bool)));
00165
00166 longId = actionCollection()->add<KToggleAction>("show_long_keyid");
00167 longId->setText(i18n("Show &long key id"));
00168 longId->setChecked(KGpgSettings::showLongKeyId());
00169 connect(longId, SIGNAL(triggered(bool)), SLOT(slotShowLongId(bool)));
00170
00171 QAction *infoKey = actionCollection()->addAction("key_info");
00172 infoKey->setIcon(KIcon("document-properties-key"));
00173 infoKey->setText(i18n("K&ey properties"));
00174 connect(infoKey, SIGNAL(triggered(bool)), SLOT(keyproperties()));
00175
00176 editKey = actionCollection()->addAction("key_edit");
00177 editKey->setIcon(KIcon("utilities-terminal"));
00178 editKey->setText(i18n("Edit Key in &Terminal"));
00179 connect(editKey, SIGNAL(triggered(bool)), SLOT(slotedit()));
00180 editKey->setShortcut(QKeySequence(Qt::ALT+Qt::Key_Return));
00181
00182 QAction *generateKey = actionCollection()->addAction("key_gener");
00183 generateKey->setIcon(KIcon("key-generate-pair"));
00184 generateKey->setText(i18n("&Generate Key Pair..."));
00185 connect(generateKey, SIGNAL(triggered(bool)), SLOT(slotGenerateKey()));
00186 generateKey->setShortcuts(KStandardShortcut::shortcut(KStandardShortcut::New));
00187
00188 QAction *exportPublicKey = actionCollection()->addAction("key_export");
00189 exportPublicKey->setIcon(KIcon("document-export-key"));
00190 exportPublicKey->setText(i18n("E&xport Public Keys..."));
00191 connect(exportPublicKey, SIGNAL(triggered(bool)), SLOT(slotexport()));
00192 exportPublicKey->setShortcuts(KStandardShortcut::shortcut(KStandardShortcut::Copy));
00193
00194 QAction *importKey = actionCollection()->addAction("key_import");
00195 importKey->setIcon(KIcon("document-import-key"));
00196 importKey->setText(i18n("&Import Key..."));
00197 connect(importKey, SIGNAL(triggered(bool)), SLOT(slotPreImportKey()));
00198 importKey->setShortcuts(KStandardShortcut::shortcut(KStandardShortcut::Paste));
00199
00200 QAction *newContact = actionCollection()->addAction("add_kab");
00201 newContact->setIcon(KIcon("contact-new"));
00202 newContact->setText(i18n("&Create New Contact in Address Book"));
00203 connect(newContact, SIGNAL(triggered(bool)), SLOT(addToKAB()));
00204
00205 QAction *createGroup = actionCollection()->addAction("create_group");
00206 createGroup->setText(i18n("&Create Group with Selected Keys..."));
00207 connect(createGroup, SIGNAL(triggered(bool)), SLOT(createNewGroup()));
00208
00209 editCurrentGroup = actionCollection()->addAction("edit_group");
00210 editCurrentGroup->setText(i18n("&Edit Group"));
00211 connect(editCurrentGroup, SIGNAL(triggered(bool)), SLOT(editGroup()));
00212
00213 delGroup = actionCollection()->addAction("delete_group");
00214 delGroup->setText(i18n("&Delete Group"));
00215 connect(delGroup, SIGNAL(triggered(bool)), SLOT(deleteGroup()));
00216
00217 deleteKey = actionCollection()->addAction("key_delete");
00218 deleteKey->setIcon(KIcon("edit-delete"));
00219 deleteKey->setText(i18n("&Delete Keys"));
00220 connect(deleteKey, SIGNAL(triggered(bool)), SLOT(confirmdeletekey()));
00221 deleteKey->setShortcut(QKeySequence(Qt::Key_Delete));
00222
00223 setDefaultKey = actionCollection()->addAction("key_default");
00224 setDefaultKey->setText(i18n("Set as De&fault Key"));
00225 connect(setDefaultKey, SIGNAL(triggered(bool)), SLOT(slotSetDefKey()));
00226 QAction *addPhoto = actionCollection()->addAction("add_photo");
00227 addPhoto->setText(i18n("&Add Photo"));
00228 connect(addPhoto, SIGNAL(triggered(bool)), SLOT(slotAddPhoto()));
00229 QAction *addUid = actionCollection()->addAction("add_uid");
00230 addUid->setText(i18n("&Add User Id"));
00231 connect(addUid, SIGNAL(triggered(bool)), SLOT(slotAddUid()));
00232 QAction *exportSecretKey = actionCollection()->addAction("key_sexport");
00233 exportSecretKey->setText(i18n("Export Secret Key..."));
00234 connect(exportSecretKey, SIGNAL(triggered(bool)), SLOT(slotexportsec()));
00235 QAction *deleteKeyPair = actionCollection()->addAction("key_pdelete");
00236 deleteKeyPair->setText(i18n("Delete Key Pair"));
00237 connect(deleteKeyPair, SIGNAL(triggered(bool)), SLOT(deleteseckey()));
00238 QAction *revokeKey = actionCollection()->addAction("key_revoke");
00239 revokeKey->setText(i18n("Revoke Key..."));
00240 connect(revokeKey, SIGNAL(triggered(bool)), SLOT(revokeWidget()));
00241 QAction *regeneratePublic = actionCollection()->addAction("key_regener");
00242 regeneratePublic->setText(i18n("&Regenerate Public Key"));
00243 connect(regeneratePublic, SIGNAL(triggered(bool)), SLOT(slotregenerate()));
00244 delUid = actionCollection()->addAction("del_uid");
00245 delUid->setText(i18n("&Delete User Id"));
00246 connect(delUid, SIGNAL(triggered(bool)), SLOT(slotDelUid()));
00247 setPrimUid = actionCollection()->addAction("prim_uid");
00248 setPrimUid->setText(i18n("Set User Id as &primary"));
00249 connect(setPrimUid, SIGNAL(triggered(bool)), SLOT(slotPrimUid()));
00250 QAction *openPhoto = actionCollection()->addAction("key_photo");
00251 openPhoto->setIcon(KIcon("image-x-generic"));
00252 openPhoto->setText(i18n("&Open Photo"));
00253 connect(openPhoto, SIGNAL(triggered(bool)), SLOT(slotShowPhoto()));
00254 QAction *deletePhoto = actionCollection()->addAction("delete_photo");
00255 deletePhoto->setIcon(KIcon("edit-delete"));
00256 deletePhoto->setText(i18n("&Delete Photo"));
00257 connect(deletePhoto, SIGNAL(triggered(bool)), SLOT(slotDeletePhoto()));
00258 delSignKey = actionCollection()->addAction("key_delsign");
00259 delSignKey->setIcon(KIcon("edit-delete"));
00260 delSignKey->setText(i18n("Delete sign&ature(s)"));
00261 connect(delSignKey, SIGNAL(triggered(bool)), SLOT(delsignkey()));
00262
00263 importAllSignKeys = actionCollection()->addAction("key_importallsign");
00264 importAllSignKeys->setIcon(KIcon("document-import"));
00265 importAllSignKeys->setText(i18n("Import &Missing Signatures From Keyserver"));
00266 connect(importAllSignKeys, SIGNAL(triggered(bool)), SLOT(importallsignkey()));
00267 refreshKey = actionCollection()->addAction("key_server_refresh");
00268 refreshKey->setIcon(KIcon("view-refresh"));
00269 refreshKey->setText(i18n("&Refresh Keys From Keyserver"));
00270 connect(refreshKey, SIGNAL(triggered(bool)), SLOT(refreshKeyFromServer()));
00271 signKey = actionCollection()->addAction("key_sign");
00272 signKey->setIcon(KIcon("document-sign-key"));
00273 signKey->setText(i18n("&Sign Keys..."));
00274 connect(signKey, SIGNAL(triggered(bool)), SLOT(signkey()));
00275 signUid = actionCollection()->addAction("key_sign_uid");
00276 signUid->setIcon(KIcon("document-sign-key"));
00277 signUid->setText(i18n("&Sign User ID ..."));
00278 connect(signUid, SIGNAL(triggered(bool)), SLOT(signuid()));
00279 importSignatureKey = actionCollection()->addAction("key_importsign");
00280 importSignatureKey->setIcon(KIcon("document-import-key"));
00281 importSignatureKey->setText(i18n("Import key(s) from keyserver"));
00282 connect(importSignatureKey, SIGNAL(triggered(bool)), SLOT(preimportsignkey()));
00283
00284 sTrust = actionCollection()->add<KToggleAction>("show_trust");
00285 sTrust->setText(i18n("Trust"));
00286 connect(sTrust, SIGNAL(triggered(bool) ), SLOT(slotShowTrust()));
00287 sSize = actionCollection()->add<KToggleAction>("show_size");
00288 sSize->setText(i18n("Size"));
00289 connect(sSize, SIGNAL(triggered(bool) ), SLOT(slotShowSize()));
00290 sCreat = actionCollection()->add<KToggleAction>("show_creat");
00291 sCreat->setText(i18n("Creation"));
00292 connect(sCreat, SIGNAL(triggered(bool) ), SLOT(slotShowCreation()));
00293 sExpi = actionCollection()->add<KToggleAction>("show_expi");
00294 sExpi->setText(i18n("Expiration"));
00295 connect(sExpi, SIGNAL(triggered(bool) ), SLOT(slotShowExpiration()));
00296
00297 photoProps = actionCollection()->add<KSelectAction>("photo_settings");
00298 photoProps->setIcon(KIcon("image-x-generic"));
00299 photoProps->setText(i18n("&Photo ID's"));
00300
00301
00302 QStringList list;
00303 list.append(i18n("Disable"));
00304 list.append(i18nc("small picture", "Small"));
00305 list.append(i18nc("medium picture", "Medium"));
00306 list.append(i18nc("large picture", "Large"));
00307 photoProps->setItems(list);
00308
00309 trustProps = actionCollection()->add<KSelectAction>("trust_filter_settings");
00310 trustProps->setText(i18n("Minimum &trust"));
00311
00312 QStringList tlist;
00313 tlist.append(i18nc("no filter: show all keys", "&None"));
00314 tlist.append(i18nc("show only active keys", "&Active"));
00315 tlist.append(i18nc("show only keys with at least marginal trust", "&Marginal"));
00316 tlist.append(i18nc("show only keys with at least full trust", "&Full"));
00317 tlist.append(i18nc("show only ultimately trusted keys", "&Ultimate"));
00318
00319 trustProps->setItems(tlist);
00320
00321 imodel = new KGpgItemModel(this);
00322
00323 iproxy = new KeyListProxyModel(this);
00324 iproxy->setKeyModel(imodel);
00325
00326 iview = new KeyTreeView(this, iproxy);
00327 connect(iview, SIGNAL(doubleClicked(const QModelIndex &)), this, SLOT(defaultAction(const QModelIndex &)));
00328 iview->setSelectionMode(QAbstractItemView::ExtendedSelection);
00329 setCentralWidget(iview);
00330 iview->resizeColumnsToContents();
00331 iview->setAlternatingRowColors(true);
00332 iview->setSortingEnabled(true);
00333 connect(iview, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(slotMenu(const QPoint &)));
00334 iview->setContextMenuPolicy(Qt::CustomContextMenu);
00335 connect(iview->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)), this, SLOT(checkList()));
00336
00337 int psize = KGpgSettings::photoProperties();
00338 photoProps->setCurrentItem(psize);
00339 slotSetPhotoSize(psize);
00340 psize = KGpgSettings::trustLevel();
00341 trustProps->setCurrentItem(psize);
00342 slotSetTrustFilter(psize);
00343 slotShowLongId(KGpgSettings::showLongKeyId());
00344
00345 m_popuppub = new KMenu(this);
00346 m_popuppub->addAction(exportPublicKey);
00347 m_popuppub->addAction(deleteKey);
00348 m_popuppub->addAction(signKey);
00349 m_popuppub->addAction(signUid);
00350 m_popuppub->addAction(infoKey);
00351 m_popuppub->addAction(editKey);
00352 m_popuppub->addAction(refreshKey);
00353 m_popuppub->addAction(createGroup);
00354 m_popuppub->addAction(setDefaultKey);
00355 m_popuppub->addSeparator();
00356 m_popuppub->addAction(importAllSignKeys);
00357
00358 m_popupsec = new KMenu(this);
00359 m_popupsec->addAction(exportPublicKey);
00360 m_popupsec->addAction(signKey);
00361 m_popupsec->addAction(signUid);
00362 m_popupsec->addAction(infoKey);
00363 m_popupsec->addAction(editKey);
00364 m_popupsec->addAction(refreshKey);
00365 m_popupsec->addAction(setDefaultKey);
00366 m_popupsec->addSeparator();
00367 m_popupsec->addAction(importAllSignKeys);
00368 m_popupsec->addSeparator();
00369 m_popupsec->addAction(addPhoto);
00370 m_popupsec->addAction(addUid);
00371 m_popupsec->addAction(exportSecretKey);
00372 m_popupsec->addAction(deleteKeyPair);
00373 m_popupsec->addAction(revokeKey);
00374
00375 m_popupgroup = new KMenu(this);
00376 m_popupgroup->addAction(editCurrentGroup);
00377 m_popupgroup->addAction(delGroup);
00378 m_popupgroup->addAction(refreshKey);
00379
00380 m_popupout = new KMenu(this);
00381 m_popupout->addAction(importKey);
00382
00383 m_popupsig = new KMenu();
00384 m_popupsig->addAction(importSignatureKey);
00385 m_popupsig->addAction(delSignKey);
00386
00387 m_popupphoto = new KMenu(this);
00388 m_popupphoto->addAction(openPhoto);
00389 m_popupphoto->addAction(signUid);
00390 m_popupphoto->addAction(deletePhoto);
00391
00392 m_popupuid = new KMenu(this);
00393 m_popupuid->addAction(signUid);
00394 m_popupuid->addAction(delUid);
00395 m_popupuid->addAction(setPrimUid);
00396
00397 m_popuporphan = new KMenu(this);
00398 m_popuporphan->addAction(regeneratePublic);
00399 m_popuporphan->addAction(deleteKeyPair);
00400
00401 editCurrentGroup->setEnabled(false);
00402 delGroup->setEnabled(false);
00403 createGroup->setEnabled(false);
00404 infoKey->setEnabled(false);
00405 editKey->setEnabled(false);
00406 signKey->setEnabled(false);
00407 signUid->setEnabled(false);
00408 refreshKey->setEnabled(false);
00409 exportPublicKey->setEnabled(false);
00410 newContact->setEnabled(false);
00411
00412 KConfigGroup cg = KConfigGroup(KGlobal::config().data(), "KeyView");
00413 iview->restoreLayout(cg);
00414
00415 connect(photoProps, SIGNAL(triggered(int)), this, SLOT(slotSetPhotoSize(int)));
00416 connect(trustProps, SIGNAL(triggered(int)), this, SLOT(slotSetTrustFilter(int)));
00417
00418
00419 setupGUI(KXmlGuiWindow::Create | Save | ToolBar | StatusBar | Keys, "keysmanager.rc");
00420 toolBar()->addSeparator();
00421
00422 QLabel *searchLabel = new QLabel(i18n("Search: "), this);
00423 m_listviewsearch = new KLineEdit(this);
00424 m_listviewsearch->setClearButtonShown(true);
00425
00426 QWidget *searchWidget = new QWidget(this);
00427 QHBoxLayout *searchLayout = new QHBoxLayout(searchWidget);
00428 searchLayout->addWidget(searchLabel);
00429 searchLayout->addWidget(m_listviewsearch);
00430 searchLayout->addStretch();
00431
00432 KAction *serchLineAction = new KAction(i18n("Search Line"), this);
00433 actionCollection()->addAction("search_line", serchLineAction);
00434 serchLineAction->setDefaultWidget(searchWidget);
00435
00436 toolBar()->addAction(actionCollection()->action("search_line"));
00437
00438 action = actionCollection()->addAction("search_focus");
00439 action->setText(i18n("Filter Search"));
00440 connect(action, SIGNAL(triggered(bool) ), m_listviewsearch, SLOT(setFocus()));
00441 action->setShortcut(QKeySequence(Qt::Key_F6));
00442 connect(m_listviewsearch, SIGNAL(textChanged(const QString &)), iproxy, SLOT(setFilterFixedString(const QString &)));
00443
00444 sTrust->setChecked(KGpgSettings::showTrust());
00445 iview->setColumnHidden(2, !KGpgSettings::showTrust());
00446 sSize->setChecked(KGpgSettings::showSize());
00447 iview->setColumnHidden(3, !KGpgSettings::showSize());
00448 sCreat->setChecked(KGpgSettings::showCreat());
00449 iview->setColumnHidden(4, !KGpgSettings::showCreat());
00450 sExpi->setChecked(KGpgSettings::showExpi());
00451 iview->setColumnHidden(5, !KGpgSettings::showExpi());
00452 iproxy->setOnlySecret(KGpgSettings::showSecret());
00453
00454 m_statusbar = statusBar();
00455 m_statusbar->insertItem("", 0, 1);
00456 m_statusbar->insertPermanentFixedItem(i18n("00000 Keys, 000 Groups"), 1);
00457 m_statusbar->setItemAlignment(0, Qt::AlignLeft);
00458 m_statusbar->changeItem("", 1);
00459
00460 connect(m_statusbartimer, SIGNAL(timeout()), this, SLOT(statusBarTimeout()));
00461
00462 cg = KConfigGroup(KGlobal::config().data(), "MainWindow");
00463 setAutoSaveSettings(cg, true);
00464 applyMainWindowSettings(cg);
00465
00466 s_kgpgEditor = new KgpgEditor(parent, imodel, Qt::Dialog, qobject_cast<KAction *>(actionCollection()->action("go_default_key"))->shortcut(), true);
00467 connect(s_kgpgEditor, SIGNAL(refreshImported(QStringList)), imodel, SLOT(refreshKeys(QStringList)));
00468 connect(this, SIGNAL(fontChanged(QFont)), s_kgpgEditor, SLOT(slotSetFont(QFont)));
00469 }
00470
00471 KeysManager::~KeysManager()
00472 {
00473 delete imodel;
00474 delete iview;
00475 }
00476
00477 void KeysManager::slotGenerateKey()
00478 {
00479 KgpgKeyGenerate *kg = new KgpgKeyGenerate(this);
00480 if (kg->exec() == QDialog::Accepted)
00481 {
00482 if (!kg->isExpertMode())
00483 {
00484 KgpgInterface *interface = new KgpgInterface();
00485 connect(interface, SIGNAL(generateKeyStarted(KgpgInterface*)), this, SLOT(slotGenerateKeyProcess(KgpgInterface*)));
00486 connect(interface, SIGNAL(generateKeyFinished(int, KgpgInterface*, QString, QString, QString)), this, SLOT(slotGenerateKeyDone(int, KgpgInterface*, QString, QString, QString)));
00487 interface->generateKey(kg->name(), kg->email(), kg->comment(), kg->algo(), kg->size(), kg->expiration(), kg->days());
00488 }
00489 else
00490 {
00491 KConfigGroup config(KGlobal::config(), "General");
00492
00493 QString terminalApp = config.readPathEntry("TerminalApplication", "konsole");
00494 QStringList args;
00495 args << "-e" << KGpgSettings::gpgBinaryPath() << "--gen-key";
00496
00497 QProcess *genKeyProc = new QProcess(this);
00498 genKeyProc->start(terminalApp, args);
00499 if (!genKeyProc->waitForStarted(-1)) {
00500 KMessageBox::error(this, i18n("Generating new key pair"), i18n("Can not start \"konsole\" application for expert mode."));
00501 } else {
00502 genKeyProc->waitForFinished(-1);
00503 refreshkey();
00504 }
00505 }
00506 }
00507
00508 delete kg;
00509 }
00510
00511 void KeysManager::showKeyManager()
00512 {
00513 show();
00514 }
00515
00516 void KeysManager::slotOpenEditor()
00517 {
00518 KgpgEditor *kgpgtxtedit = new KgpgEditor(this, imodel, Qt::Window, qobject_cast<KAction *>(actionCollection()->action("go_default_key"))->shortcut());
00519 kgpgtxtedit->setAttribute(Qt::WA_DeleteOnClose);
00520
00521 connect(kgpgtxtedit, SIGNAL(refreshImported(QStringList)), imodel, SLOT(refreshKeys(QStringList)));
00522 connect(kgpgtxtedit, SIGNAL(encryptFiles(KUrl::List)), this, SIGNAL(encryptFiles(KUrl::List)));
00523 connect(this, SIGNAL(fontChanged(QFont)), kgpgtxtedit, SLOT(slotSetFont(QFont)));
00524
00525 kgpgtxtedit->show();
00526 }
00527
00528 void KeysManager::statusBarTimeout()
00529 {
00530 if (m_statusbar)
00531 m_statusbar->changeItem("", 0);
00532 }
00533
00534 void KeysManager::changeMessage(const QString &msg, const int nb, const bool keep)
00535 {
00536 m_statusbartimer->stop();
00537 if (m_statusbar)
00538 {
00539 if ((nb == 0) && (!keep))
00540 m_statusbartimer->start(10000);
00541 m_statusbar->changeItem(' ' + msg + ' ', nb);
00542 }
00543 }
00544
00545 void KeysManager::slotGenerateKeyProcess(KgpgInterface *)
00546 {
00547 pop = new KPassivePopup(this);
00548 pop->setTimeout(0);
00549
00550 KVBox *passiveBox = pop->standardView(i18n("Generating new key pair."), QString(), Images::kgpg());
00551
00552 QMovie anim(KStandardDirs::locate("appdata", "pics/kgpg_anim.gif"));
00553 QLabel *text1 = new QLabel(passiveBox);
00554 text1->setAlignment(Qt::AlignHCenter);
00555 text1->setMovie(&anim);
00556
00557 QLabel *text2 = new QLabel(passiveBox);
00558 text2->setText(i18n("\nPlease wait..."));
00559
00560 pop->setView(passiveBox);
00561 pop->show();
00562
00563 QRect qRect(QApplication::desktop()->screenGeometry());
00564 int Xpos = qRect.width() / 2 - pop->width() / 2;
00565 int Ypos = qRect.height() / 2 - pop->height() / 2;
00566 pop->move(Xpos, Ypos);
00567
00568 pop->setAutoDelete(false);
00569 changeMessage(i18n("Generating New Key..."), 0, true);
00570 }
00571
00572 void KeysManager::slotGenerateKeyDone(int res, KgpgInterface *interface, const QString &name, const QString &email, const QString &fingerprint)
00573 {
00574 interface->deleteLater();
00575 changeMessage(i18nc("Application ready for user input", "Ready"), 0);
00576
00577 delete pop;
00578 pop = NULL;
00579
00580 if (res == 1)
00581 {
00582 QString infomessage = i18n("Generating new key pair");
00583 QString infotext = i18n("Bad passphrase. Cannot generate a new key pair.");
00584 KMessageBox::error(this, infotext, infomessage);
00585 }
00586 else
00587 if (res == 3)
00588 {
00589 QString infomessage = i18n("Generating new key pair");
00590 QString infotext = i18n("Aborted by the user. Cannot generate a new key pair.");
00591 KMessageBox::error(this, infotext, infomessage);
00592 }
00593 else
00594 if (res == 4)
00595 {
00596 QString infomessage = i18n("Generating new key pair");
00597 QString infotext = i18n("The email address is not valid. Cannot generate a new key pair.");
00598 KMessageBox::error(this, infotext, infomessage);
00599 }
00600 else
00601 if (res == 10)
00602 {
00603 QString infomessage = i18n("Generating new key pair");
00604 QString infotext = i18n("The name is not accepted by gpg. Cannot generate a new key pair.");
00605 KMessageBox::error(this, infotext, infomessage);
00606 }
00607 else
00608 if (res != 2)
00609 {
00610 QString infomessage = i18n("Generating new key pair");
00611 QString infotext = i18n("gpg process did not finish. Cannot generate a new key pair.");
00612 KMessageBox::error(this, infotext, infomessage);
00613 }
00614 else
00615 {
00616 changeMessage(imodel->statusCountMessage(), 1);
00617
00618 KDialog *keyCreated = new KDialog(this);
00619 keyCreated->setCaption(i18n("New Key Pair Created"));
00620 keyCreated->setButtons(KDialog::Ok);
00621 keyCreated->setDefaultButton(KDialog::Ok);
00622 keyCreated->setModal(true);
00623
00624 newKey *page = new newKey(keyCreated);
00625 page->TLname->setText("<b>" + name + "</b>");
00626 page->TLemail->setText("<b>" + email + "</b>");
00627
00628 QString revurl;
00629 QString gpgPath = KGpgSettings::gpgConfigPath();
00630 if (!gpgPath.isEmpty())
00631 revurl = KUrl::fromPath(gpgPath).directory(KUrl::AppendTrailingSlash);
00632 else
00633 revurl = QDir::homePath() + '/';
00634
00635 if (!email.isEmpty())
00636 page->kURLRequester1->setUrl(revurl + email.section("@", 0, 0) + ".revoke");
00637 else
00638 page->kURLRequester1->setUrl(revurl + email.section(" ", 0, 0) + ".revoke");
00639
00640 page->TLid->setText("<b>" + fingerprint.right(8) + "</b>");
00641 page->LEfinger->setText(fingerprint);
00642 page->CBdefault->setChecked(true);
00643 page->show();
00644 keyCreated->setMainWidget(page);
00645
00646 keyCreated->exec();
00647
00648 imodel->refreshKey(fingerprint);
00649 if (page->CBdefault->isChecked())
00650 imodel->setDefaultKey(fingerprint);
00651
00652 iview->selectNode(imodel->getRootNode()->findKey(fingerprint));
00653
00654 if (page->CBsave->isChecked())
00655 {
00656 slotrevoke(fingerprint, page->kURLRequester1->url().path(), 0, i18n("backup copy"));
00657 if (page->CBprint->isChecked())
00658 connect(revKeyProcess, SIGNAL(revokeurl(QString)), this, SLOT(doFilePrint(QString)));
00659 }
00660 else
00661 if (page->CBprint->isChecked())
00662 {
00663 slotrevoke(fingerprint, QString(), 0, i18n("backup copy"));
00664 connect(revKeyProcess, SIGNAL(revokecertificate(QString)), this, SLOT(doPrint(QString)));
00665 }
00666 }
00667 }
00668
00669 void KeysManager::slotShowTrust()
00670 {
00671 bool b = !sTrust->isChecked();
00672 iview->setColumnHidden(KEYCOLUMN_TRUST, b);
00673 if (!b && (iview->columnWidth(KEYCOLUMN_TRUST) == 0))
00674 iview->resizeColumnToContents(KEYCOLUMN_TRUST);
00675 }
00676
00677 void KeysManager::slotShowExpiration()
00678 {
00679 bool b = !sExpi->isChecked();
00680 iview->setColumnHidden(KEYCOLUMN_EXPIR, b);
00681 if (!b && (iview->columnWidth(KEYCOLUMN_EXPIR) == 0))
00682 iview->resizeColumnToContents(KEYCOLUMN_EXPIR);
00683 }
00684
00685 void KeysManager::slotShowSize()
00686 {
00687 bool b = !sSize->isChecked();
00688 iview->setColumnHidden(KEYCOLUMN_SIZE, b);
00689 if (!b && (iview->columnWidth(KEYCOLUMN_SIZE) == 0))
00690 iview->resizeColumnToContents(KEYCOLUMN_SIZE);
00691 }
00692
00693 void KeysManager::slotShowCreation()
00694 {
00695 bool b = !sCreat->isChecked();
00696 iview->setColumnHidden(KEYCOLUMN_CREAT, b);
00697 if (!b && (iview->columnWidth(KEYCOLUMN_CREAT) == 0))
00698 iview->resizeColumnToContents(KEYCOLUMN_CREAT);
00699 }
00700
00701 void KeysManager::slotToggleSecret(bool b)
00702 {
00703 iproxy->setOnlySecret(b);
00704 }
00705
00706 void KeysManager::slotShowLongId(bool b)
00707 {
00708 iproxy->setIdLength(b ? 16 : 8);
00709 }
00710
00711 void KeysManager::slotSetTrustFilter(int i)
00712 {
00713 KgpgCore::KgpgKeyTrustFlag t;
00714
00715 Q_ASSERT((i >= 0) && (i < 5));
00716 switch (i) {
00717 case 0:
00718 t = TRUST_MINIMUM;
00719 break;
00720 case 1:
00721 t = TRUST_UNDEFINED;
00722 break;
00723 case 2:
00724 t = TRUST_MARGINAL;
00725 break;
00726 case 3:
00727 t = TRUST_FULL;
00728 break;
00729 default:
00730 t = TRUST_ULTIMATE;
00731 }
00732
00733 iproxy->setTrustFilter(t);
00734 }
00735
00736 bool KeysManager::eventFilter(QObject *, QEvent *e)
00737 {
00738 if ((e->type() == QEvent::Show) && (showTipOfDay))
00739 {
00740 KTipDialog::showTip(this, QString("kgpg/tips"), false);
00741 showTipOfDay = false;
00742 }
00743
00744 return false;
00745 }
00746
00747 void KeysManager::slotGotoDefaultKey()
00748 {
00749 iview->selectNode(imodel->getRootNode()->findKey(KGpgSettings::defaultKey()));
00750 }
00751
00752 void KeysManager::refreshKeyFromServer()
00753 {
00754 QList<KGpgNode *> keysList = iview->selectedNodes();
00755 if (keysList.isEmpty())
00756 return;
00757
00758 QStringList keyIDS;
00759
00760 for (int i = 0; i < keysList.count(); ++i)
00761 {
00762 KGpgNode *item = keysList.at(i);
00763
00764 if (item->getType() == ITYPE_GROUP)
00765 {
00766 for (int j = 0; j < item->getChildCount(); j++)
00767 keyIDS << item->getChild(j)->getId();
00768
00769 continue;
00770 }
00771
00772 if (item->getType() & ITYPE_PAIR)
00773 keyIDS << item->getId();
00774 else
00775 {
00776 KMessageBox::sorry(this, i18n("You can only refresh primary keys. Please check your selection."));
00777 return;
00778 }
00779 }
00780
00781 kServer = new KeyServer(this, false);
00782 connect(kServer, SIGNAL(importFinished(QStringList)), imodel, SLOT(refreshKeys(QStringList)));
00783 kServer->refreshKeys(keyIDS);
00784 }
00785
00786 void KeysManager::slotDelUid()
00787 {
00788 KGpgNode *nd = iview->selectedNode();
00789 Q_ASSERT(nd->getType() == ITYPE_UID);
00790
00791 m_deluid = new KGpgDelUid(this, nd->getParentKeyNode()->getId(), nd->getId());
00792
00793 connect(m_deluid, SIGNAL(done(int)), SLOT(slotDelUidDone(int)));
00794 m_deluid->start();
00795 }
00796
00797 void KeysManager::slotDelUidDone(int result)
00798 {
00799 m_deluid->deleteLater();
00800 m_deluid = NULL;
00801
00802 Q_UNUSED(result)
00803 }
00804
00805 void KeysManager::slotPrimUid()
00806 {
00807 KGpgNode *nd = iview->selectedNode();
00808 Q_ASSERT(nd->getType() == ITYPE_UID);
00809
00810 QProcess *process = new QProcess(this);
00811 KConfigGroup config(KGlobal::config(), "General");
00812 QString terminalApp = config.readPathEntry("TerminalApplication", "konsole");
00813 QStringList args;
00814 args << "-e" << KGpgSettings::gpgBinaryPath();
00815 args << "--edit-key" << nd->getParentKeyNode()->getId() << "uid" << nd->getId() << "primary" << "save";
00816 process->start(terminalApp, args);
00817 process->waitForFinished();
00818 imodel->refreshKey(static_cast<KGpgKeyNode *>(nd->getParentKeyNode()));
00819 }
00820
00821 void KeysManager::slotregenerate()
00822 {
00823 QString regID = iview->selectedNode()->getId();
00824 KProcess *p1, *p2, *p3;
00825
00826 p1 = new KProcess(this);
00827 *p1 << KGpgSettings::gpgBinaryPath() << "--no-secmem-warning" << "--export-secret-key" << regID;
00828 p1->setOutputChannelMode(KProcess::OnlyStdoutChannel);
00829
00830 p2 = new KProcess(this);
00831 *p2 << "gpgsplit" << "--no-split" << "--secret-to-public";
00832 p2->setOutputChannelMode(KProcess::OnlyStdoutChannel);
00833
00834 p3 = new KProcess(this);
00835 *p3 << KGpgSettings::gpgBinaryPath() << "--import";
00836
00837 p1->setStandardOutputProcess(p2);
00838 p2->setStandardOutputProcess(p3);
00839
00840 p1->start();
00841 p2->start();
00842 p3->start();
00843
00844 p1->waitForFinished();
00845 p2->waitForFinished();
00846 p3->waitForFinished();
00847
00848 delete p1;
00849 delete p2;
00850 delete p3;
00851
00852 imodel->refreshKey(regID);
00853 }
00854
00855 void KeysManager::slotAddUid()
00856 {
00857 addUidWidget = new KDialog(this );
00858 addUidWidget->setCaption( i18n("Add New User Id") );
00859 addUidWidget->setButtons( KDialog::Ok | KDialog::Cancel );
00860 addUidWidget->setDefaultButton( KDialog::Ok );
00861 addUidWidget->setModal( true );
00862 addUidWidget->enableButtonOk(false);
00863 AddUid *keyUid = new AddUid(0);
00864 addUidWidget->setMainWidget(keyUid);
00865
00866 keyUid->setMinimumWidth(300);
00867
00868 connect(keyUid->kLineEdit1, SIGNAL(textChanged(const QString & )), this, SLOT(slotAddUidEnable(const QString & )));
00869 if (addUidWidget->exec() != QDialog::Accepted)
00870 return;
00871
00872 KgpgInterface *addUidProcess = new KgpgInterface();
00873 connect(addUidProcess,SIGNAL(addUidFinished(int, KgpgInterface*)), this ,SLOT(slotAddUidFin(int, KgpgInterface*)));
00874 addUidProcess->addUid(iview->selectedNode()->getId(), keyUid->kLineEdit1->text(), keyUid->kLineEdit2->text(), keyUid->kLineEdit3->text());
00875 }
00876
00877 void KeysManager::slotAddUidFin(int res, KgpgInterface *interface)
00878 {
00879
00880 kDebug(2100) << "Resultat : " << res ;
00881 interface->deleteLater();
00882 KGpgNode *nd = iview->selectedNode();
00883 Q_ASSERT(!(nd->getType() & ~ITYPE_PAIR));
00884 imodel->refreshKey(static_cast<KGpgKeyNode *>(nd));
00885 }
00886
00887 void KeysManager::slotAddUidEnable(const QString & name)
00888 {
00889 addUidWidget->enableButtonOk(name.length() > 4);
00890 }
00891
00892 void KeysManager::slotAddPhoto()
00893 {
00894 QString mess = i18n("The image must be a JPEG file. Remember that the image is stored within your public key. "
00895 "If you use a very large picture, your key will become very large as well! Keeping the image "
00896 "close to 240x288 is a good size to use.");
00897
00898 if (KMessageBox::warningContinueCancel(0, mess) != KMessageBox::Continue)
00899 return;
00900
00901 QString imagepath = KFileDialog::getOpenFileName(KUrl(), "image/jpeg", 0);
00902 if (imagepath.isEmpty())
00903 return;
00904
00905 kDebug(3125) << imagepath;
00906 m_addphoto = new KGpgAddPhoto(this, iview->selectedNode()->getId(), imagepath);
00907 connect(m_addphoto, SIGNAL(done(int)), SLOT(slotAddPhotoFinished(int)));
00908 m_addphoto->start();
00909 }
00910
00911 void KeysManager::slotAddPhotoFinished(int res)
00912 {
00913 m_addphoto->deleteLater();
00914
00915
00916
00917 if (res == 0)
00918 slotUpdatePhoto();
00919 }
00920
00921 void KeysManager::slotDeletePhoto()
00922 {
00923 KGpgNode *nd = iview->selectedNode();
00924 Q_ASSERT(nd->getType() == ITYPE_UAT);
00925 KGpgUatNode *und = static_cast<KGpgUatNode *>(nd);
00926 KGpgKeyNode *parent = und->getParentKeyNode();
00927
00928 QString mess = i18n("<qt>Are you sure you want to delete Photo id <b>%1</b><br/>from key <b>%2 <%3></b>?</qt>",
00929 und->getId(), parent->getName(), parent->getEmail());
00930
00931 m_deluid = new KGpgDelUid(this, parent->getId(), und->getId());
00932 connect(m_deluid, SIGNAL(done(int)), SLOT(slotDelPhotoFinished(int)));
00933
00934 m_deluid->start();
00935 }
00936
00937 void KeysManager::slotDelPhotoFinished(int res)
00938 {
00939 m_deluid->deleteLater();
00940
00941
00942
00943 if (res == 0)
00944 slotUpdatePhoto();
00945 }
00946
00947 void KeysManager::slotUpdatePhoto()
00948 {
00949 KGpgNode *nd = iview->selectedNode();
00950 Q_ASSERT(!(nd->getType() & ~ITYPE_PAIR));
00951 imodel->refreshKey(static_cast<KGpgKeyNode *>(nd));
00952 }
00953
00954 void KeysManager::slotSetPhotoSize(int size)
00955 {
00956 switch(size)
00957 {
00958 case 1:
00959 iproxy->setPreviewSize(22);
00960 break;
00961 case 2:
00962 iproxy->setPreviewSize(42);
00963 break;
00964 case 3:
00965 iproxy->setPreviewSize(65);
00966 break;
00967 default:
00968 iproxy->setPreviewSize(0);
00969 break;
00970 }
00971 }
00972
00973 void KeysManager::findKey()
00974 {
00975 KFindDialog fd(this);
00976 if (fd.exec() != QDialog::Accepted)
00977 return;
00978
00979 searchString = fd.pattern();
00980 searchOptions = fd.options();
00981 findFirstKey();
00982 }
00983
00984 void KeysManager::findFirstKey()
00985 {
00986 if (searchString.isEmpty())
00987 return;
00988
00989 return;
00990 #ifdef __GNUC__
00991 #warning port me
00992 #endif
00993 #if 0
00994 bool foundItem = true;
00995 KeyListViewItem *item = keysList2->firstChild();
00996 if (!item)
00997 return;
00998 QString searchText = item->text(0) + ' ' + item->text(1) + ' ' + item->text(6);
00999
01000 KFind *m_find = new KFind(searchString, searchOptions, this);
01001 m_find->setData(searchText);
01002 while (m_find->find() == KFind::NoMatch)
01003 {
01004 if (!item->nextSibling())
01005 {
01006 foundItem = false;
01007 break;
01008 }
01009 else
01010 {
01011 item = item->nextSibling();
01012 searchText = item->text(0) + ' ' + item->text(1) + ' ' + item->text(6);
01013 m_find->setData(searchText);
01014 }
01015 }
01016 delete m_find;
01017
01018 if (foundItem)
01019 {
01020 keysList2->clearSelection();
01021 keysList2->setCurrentItem(item);
01022 keysList2->setSelected(item, true);
01023 keysList2->ensureItemVisible(item);
01024 }
01025 else
01026 KMessageBox::sorry(this, i18n("<qt>Search string '<b>%1</b>' not found.</qt>", searchString));
01027 #endif
01028 }
01029
01030 void KeysManager::findNextKey()
01031 {
01032
01033 if (searchString.isEmpty())
01034 {
01035 findKey();
01036 return;
01037 }
01038 return;
01039
01040 #ifdef __GNUC__
01041 #warning port me
01042 #endif
01043 #if 0
01044 bool foundItem = true;
01045 KeyListViewItem *item = keysList2->currentItem();
01046 if (!item)
01047 return;
01048
01049 while(item->depth() > 0)
01050 item = item->parent();
01051 item = item->nextSibling();
01052
01053 QString searchText = item->text(0) + ' ' + item->text(1) + ' ' + item->text(6);
01054
01055