• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdeutils
  • Sitemap
  • Contact Us
 

kgpg

kgpglibrary.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           kgpglibrary.cpp  -  description
00003                              -------------------
00004     begin                : Mon Jul 8 2002
00005     copyright          : (C) 2002 by Jean-Baptiste Mardelle
00006     email                : bj@altern.org
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include "kgpglibrary.h"
00019 
00020 #include <QDesktopWidget>
00021 #include <QApplication>
00022 #include <QTextStream>
00023 #include <QFile>
00024 
00025 #include <KFileDialog>
00026 #include <KPassivePopup>
00027 #include <kio/renamedialog.h>
00028 #include <KMessageBox>
00029 #include <KLocale>
00030 #include <kio/deletejob.h>
00031 #include <kio/jobuidelegate.h>
00032 
00033 #include "images.h"
00034 #include "selectpublickeydialog.h"
00035 #include "kgpgsettings.h"
00036 #include "kgpginterface.h"
00037 #include "kgpgtextinterface.h"
00038 #include "kgpgitemmodel.h"
00039 
00040 using namespace KgpgCore;
00041 
00042 KgpgLibrary::KgpgLibrary(QWidget *parent)
00043 {
00044     m_extension = ".gpg";
00045 
00046     m_popisactive = false;
00047     m_panel = parent;
00048 }
00049 
00050 void KgpgLibrary::setFileExtension(const QString &ext)
00051 {
00052     m_extension = ext;
00053 }
00054 
00055 void KgpgLibrary::slotFileEnc(const KUrl::List &urls, const QStringList &opts, KGpgItemModel *model, const KShortcut &goDefaultKey, const QString &defaultKey)
00056 {
00057     if (!urls.empty())
00058     {
00059         m_urlselecteds = urls;
00060             QString fileNames = urls.first().fileName();
00061             if (urls.count() > 1)
00062                 fileNames += ", ...";
00063 
00064             KgpgSelectPublicKeyDlg *dialog = new KgpgSelectPublicKeyDlg(0, model, goDefaultKey, fileNames);
00065             if (dialog->exec() == KDialog::Accepted)
00066             {
00067                 QStringList options = opts;
00068                 if (dialog->getUntrusted()) options << "--always-trust";
00069                 if (dialog->getArmor())     options << "--armor";
00070                 if (dialog->getHideId())    options << "--throw-keyid";
00071 
00072                 if (!dialog->getCustomOptions().isEmpty())
00073                     if (KGpgSettings::allowCustomEncryptionOptions())
00074                         options << dialog->getCustomOptions().split(' ');
00075 
00076                 QStringList keys = dialog->selectedKeys();
00077                 if (!defaultKey.isEmpty() && !keys.contains(defaultKey))
00078                     keys << defaultKey;
00079                 startEncode(keys, options, dialog->getSymmetric());
00080             }
00081 
00082             delete dialog;
00083     }
00084 }
00085 
00086 void KgpgLibrary::startEncode(const QStringList &encryptkeys, const QStringList &encryptoptions, const bool &symetric)
00087 {
00088     m_popisactive = false;
00089     //KUrl::List::iterator it;
00090     //filesToEncode=m_urlselecteds.count();
00091     m_encryptkeys = encryptkeys;
00092     m_encryptoptions = encryptoptions;
00093     m_symetric = symetric;
00094     fastEncode(m_urlselecteds.first(), encryptkeys, encryptoptions, symetric);
00095 }
00096 
00097 void KgpgLibrary::fastEncode(const KUrl &filetocrypt, const QStringList &encryptkeys, const QStringList &encryptoptions, const bool &symetric)
00098 {
00099     if ((encryptkeys.isEmpty()) && (!symetric))
00100     {
00101         KMessageBox::sorry(0, i18n("You have not chosen an encryption key."));
00102         return;
00103     }
00104 
00105     m_urlselected = filetocrypt;
00106 
00107     KUrl dest;
00108     if (encryptoptions.contains("--armor"))
00109         dest.setPath(m_urlselected.path() + ".asc");
00110     else
00111         dest.setPath(m_urlselected.path() + m_extension);
00112 
00113     QFile fgpg(dest.path());
00114     if (fgpg.exists())
00115     {
00116         KIO::RenameDialog over(0, i18n("File Already Exists"), KUrl(), dest, KIO::M_OVERWRITE);
00117         if (over.exec() == QDialog::Rejected)
00118         {
00119             emit systemMessage(QString(), true);
00120             return;
00121         }
00122 
00123         dest = over.newDestUrl();
00124     }
00125 
00126     int filesToEncode = m_urlselecteds.count();
00127     if (filesToEncode > 1)
00128         emit systemMessage(i18n("<p><b>%1 Files left.</b><br /><b>Encrypting </b>%2</p>", filesToEncode, m_urlselecteds.first().path()));
00129     else
00130         emit systemMessage(i18n("<b>Encrypting </b>%1", m_urlselecteds.first().path()));
00131 
00132     m_pop = new KPassivePopup(m_panel);
00133 
00134     KGpgTextInterface *cryptFileProcess = new KGpgTextInterface();
00135     connect(cryptFileProcess, SIGNAL(fileEncryptionFinished(KUrl, KGpgTextInterface*)), this, SLOT(processEnc(KUrl, KGpgTextInterface*)));
00136     connect(cryptFileProcess, SIGNAL(errorMessage(QString, KGpgTextInterface*)), this, SLOT(processEncError(QString, KGpgTextInterface*)));
00137     cryptFileProcess->encryptFile(encryptkeys, m_urlselected, dest, encryptoptions, symetric);
00138 
00139     if (!m_popisactive)
00140     {
00141         //connect(cryptFileProcess,SIGNAL(processstarted(QString)),this,SLOT(processpopup2(QString)));
00142         m_popisactive = true;
00143     }
00144 
00145 }
00146 
00147 void KgpgLibrary::processEnc(const KUrl &, KGpgTextInterface *i)
00148 {
00149     i->deleteLater();
00150     emit systemMessage(QString());
00151 
00152     m_urlselecteds.pop_front();
00153 
00154     if (m_urlselecteds.count() > 0)
00155         fastEncode(m_urlselecteds.first(), m_encryptkeys, m_encryptoptions, m_symetric);
00156     else
00157         emit encryptionOver();
00158 }
00159 
00160 void KgpgLibrary::processEncError(const QString &mssge, KGpgTextInterface *i)
00161 {
00162     i->deleteLater();
00163     m_popisactive = false;
00164     emit systemMessage(QString(), true);
00165     KMessageBox::detailedSorry(m_panel, i18n("<p><b>Process halted</b>.<br />Not all files were encrypted.</p>"), mssge);
00166 }
00167 
00168 void KgpgLibrary::slotFileDec(const KUrl &src, const KUrl &dest, const QStringList &customDecryptOption)
00169 {
00170     // decode file from konqueror or menu
00171     m_pop = new KPassivePopup();
00172     m_urlselected = src;
00173 
00174     KGpgTextInterface *decryptFileProcess = new KGpgTextInterface();
00175     decryptFileProcess->decryptFile(src, dest, customDecryptOption);
00176     connect(decryptFileProcess, SIGNAL(decryptFileStarted(KUrl)), this, SLOT(processEncPopup(KUrl)));
00177     connect(decryptFileProcess, SIGNAL(decryptFileFinished(int, KGpgTextInterface*)), this, SLOT(processDecOver(int, KGpgTextInterface*)));
00178 }
00179 
00180 void KgpgLibrary::processDecOver(int ret, KGpgTextInterface *iface)
00181 {
00182     emit systemMessage(QString());
00183     delete m_pop;
00184     iface->deleteLater();
00185     if (ret != 0)
00186     emit decryptionOver(this, m_urlselected);
00187     else
00188     emit decryptionOver(this, KUrl());
00189 }
00190 
00191 void KgpgLibrary::slotImportOver(KgpgInterface *iface, const QStringList &keys)
00192 {
00193     iface->deleteLater();
00194     emit importOver(this, keys);
00195 }
00196 
00197 void KgpgLibrary::processEncPopup(const KUrl &url)
00198 {
00199     emit systemMessage(i18n("Decrypting %1", url.pathOrUrl()));
00200 
00201     m_pop->setTimeout(0);
00202     m_pop->setView(i18n("Processing decryption"), i18n("Please wait..."), Images::kgpg());
00203     m_pop->show();
00204 
00205     QRect qRect(QApplication::desktop()->screenGeometry());
00206     int iXpos = qRect.width() / 2 - m_pop->width() / 2;
00207     int iYpos = qRect.height() / 2 - m_pop->height() / 2;
00208     m_pop->move(iXpos, iYpos);
00209 }
00210 
00211 void KgpgLibrary::processPopup2(const QString &fileName)
00212 {
00213     //m_pop->setTimeout(0);
00214     m_pop->setView(i18n("Processing encryption (%1)", fileName),i18n("Please wait..."), Images::kgpg());
00215     m_pop->show();
00216     /*QRect qRect(QApplication::desktop()->screenGeometry());
00217     int iXpos=qRect.width()/2-m_pop->width()/2;
00218     int iYpos=qRect.height()/2-m_pop->height()/2;
00219     m_pop->move(iXpos,iYpos);*/
00220 }
00221 
00222 #include "kgpglibrary.moc"

kgpg

Skip menu "kgpg"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdeutils

Skip menu "kdeutils"
  • ark
  • kcalc
  • kcharselect
  • kdessh
  • kdf
  • kfloppy
  • kgpg
  • ktimer
  • kwallet
  • okteta
  • printer-applet
  • superkaramba
  • sweeper
Generated for kdeutils by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal