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