33 #include <KMessageBox>
47 setCaption(i18n(
"Key Server"));
51 m_autoclose = autoclose;
52 m_filtermodel.setSortCaseSensitivity(Qt::CaseInsensitive);
53 m_filtermodel.setDynamicSortFilter(
true);
54 m_filtermodel.setFilterKeyColumn(0);
59 page->kCBexportks->addItems(serverlist);
60 page->kCBimportks->addItems(serverlist);
61 page->kLEimportid->setFocus();
63 connect(page->Buttonimport, SIGNAL(clicked()), SLOT(
slotImport()));
64 connect(page->Buttonsearch, SIGNAL(clicked()), SLOT(slotSearch()));
65 connect(page->Buttonexport, SIGNAL(clicked()), SLOT(
slotPreExport()));
66 connect(page->kLEimportid, SIGNAL(returnPressed()), SLOT(slotSearch()));
67 connect(
this, SIGNAL(okClicked()), SLOT(
slotOk()));
68 connect(page->cBproxyI, SIGNAL(toggled(
bool)), SLOT(
slotEnableProxyI(
bool)));
69 connect(page->cBproxyE, SIGNAL(toggled(
bool)), SLOT(
slotEnableProxyE(
bool)));
70 connect(page->kLEimportid, SIGNAL(textChanged(QString)), SLOT(
slotTextChanged(QString)));
75 const QString httpproxy(QLatin1String( qgetenv(
"http_proxy") ));
76 if (!httpproxy.isEmpty()) {
77 page->cBproxyI->setEnabled(
true);
78 page->cBproxyE->setEnabled(
true);
79 page->kLEproxyI->setText(httpproxy);
80 page->kLEproxyE->setText(httpproxy);
83 page->Buttonimport->setEnabled(!page->kLEimportid->text().isEmpty());
84 page->Buttonsearch->setEnabled(!page->kLEimportid->text().isEmpty());
85 setMinimumSize(sizeHint());
89 page->kCBexportkey->setModel(m_itemmodel);
99 if (page->kCBimportks->currentText().isEmpty())
102 if (page->kLEimportid->text().isEmpty()) {
103 KMessageBox::sorry(
this, i18n(
"You must enter a search string."));
107 startImport(page->kLEimportid->text().simplified().split(QLatin1Char(
' ' )), page->kCBimportks->currentText(), page->kLEproxyI->text());
112 if (server.isEmpty()) {
114 if (kservers.isEmpty()) {
115 KMessageBox::sorry(
this, i18n(
"You need to configure keyservers before trying to download keys."),
116 i18n(
"No keyservers defined"));
120 server = kservers.first();
123 QApplication::setOverrideCursor(QCursor(Qt::BusyCursor));
126 connect(proc, SIGNAL(done(
int)), SLOT(slotDownloadKeysFinished(
int)));
131 void KeyServer::slotDownloadKeysFinished(
int resultcode)
133 QApplication::restoreOverrideCursor();
136 const QStringList log(t->
getLog());
151 (void)
new KgpgDetailedInfo(
this, resultmessage, log.join(QLatin1String(
"\n")),
153 i18nc(
"Caption of message box",
"Key Import Finished"));
158 if (page->kCBexportks->currentText().isEmpty())
161 QApplication::setOverrideCursor(QCursor(Qt::BusyCursor));
163 KGpgSendKeys *nk =
new KGpgSendKeys(
this, page->kCBimportks->currentText(), keyIds, expattr,
true, page->kLEproxyI->text());
164 connect(nk, SIGNAL(done(
int)), SLOT(slotUploadKeysFinished(
int)));
169 void KeyServer::slotUploadKeysFinished(
int resultcode)
172 Q_ASSERT(nk != NULL);
174 const QStringList message(nk->
getLog());
177 QApplication::restoreOverrideCursor();
181 title = i18n(
"Upload to keyserver finished without errors");
183 title = i18n(
"Upload to keyserver failed");
184 KMessageBox::informationList(
this, title, message);
187 void KeyServer::slotSearch()
189 if (page->kCBimportks->currentText().isEmpty())
192 if (page->kLEimportid->text().isEmpty()) {
193 KMessageBox::sorry(
this, i18n(
"You must enter a search string."));
197 page->Buttonsearch->setEnabled(
false);
201 if (m_resultmodel != NULL)
202 m_resultmodel->deleteLater();
204 m_filtermodel.setSourceModel(m_resultmodel);
205 m_filtermodel.setFilterRegExp(QRegExp());
207 m_dialogserver =
new KDialog(
this );
208 m_dialogserver->setCaption( i18n(
"Import Key From Keyserver") );
209 m_dialogserver->setButtons( KDialog::Ok | KDialog::Close );
210 m_dialogserver->setDefaultButton( KDialog::Ok);
211 m_dialogserver->setModal(
true );
213 m_dialogserver->setButtonText(KDialog::Ok, i18n(
"&Import"));
214 m_dialogserver->enableButtonOk(
false);
215 m_listpop =
new searchRes(m_dialogserver);
216 m_listpop->kLVsearch->setModel(&m_filtermodel);
217 m_listpop->kLVsearch->setColumnWidth(0, 180);
218 m_listpop->statusText->setText(i18n(
"Connecting to the server..."));
220 connect(m_listpop->filterEdit, SIGNAL(textChanged(QString)), SLOT(slotSetFilterString(QString)));
221 connect(m_listpop->kLVsearch->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection)), SLOT(
transferKeyID()));
222 connect(m_dialogserver, SIGNAL(okClicked()),
this, SLOT(
slotPreImport()));
223 connect(m_listpop->kLVsearch, SIGNAL(activated(QModelIndex)), m_dialogserver, SIGNAL(okClicked()));
224 connect(m_dialogserver, SIGNAL(closeClicked()),
this, SLOT(
handleQuit()));
225 connect(m_listpop->kLEID, SIGNAL(clearButtonClicked()), m_listpop->kLVsearch->selectionModel(), SLOT(clearSelection()));
227 m_listpop->kLVsearch->setSelectionMode(QAbstractItemView::ExtendedSelection);
229 m_readmessage.clear();
231 const QString keyserv(page->kCBimportks->currentText());
233 bool useproxy = page->cBproxyI->isChecked();
236 proxy = page->kLEproxyI->text();
240 connect(m_searchproc, SIGNAL(done(
int)), SLOT(slotSearchResult(
int)));
241 connect(m_searchproc, SIGNAL(
newKey(QStringList)), m_resultmodel, SLOT(slotAddKey(QStringList)));
242 m_searchproc->
start();
244 QApplication::setOverrideCursor(QCursor(Qt::BusyCursor));
245 m_dialogserver->setMainWidget(m_listpop);
246 m_listpop->setMinimumSize(m_listpop->sizeHint());
247 m_dialogserver->exec();
250 void KeyServer::slotSearchResult(
int result)
252 Q_ASSERT(sender() == m_searchproc);
253 m_searchproc->deleteLater();
255 page->Buttonsearch->setEnabled(
true);
256 QApplication::restoreOverrideCursor();
259 delete m_dialogserver;
260 m_dialogserver = NULL;
264 m_dialogserver->enableButtonOk(
true);
266 const int keys = m_resultmodel->
rowCount(QModelIndex());
269 m_listpop->statusText->setText(i18np(
"Found 1 matching key",
"Found %1 matching keys", keys));
270 m_listpop->kLVsearch->selectionModel()->setCurrentIndex(m_resultmodel->
index(0, 0),
271 QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows);
273 m_listpop->statusText->setText(i18n(
"No matching keys found"));
279 page->kLEimportid->setText(text);
284 page->Buttonimport->setEnabled(!text.isEmpty());
285 page->Buttonsearch->setEnabled(!text.isEmpty() && (m_searchproc == NULL));
290 if (!state.isEmpty())
298 page->kLEproxyI->setEnabled(on);
303 page->kLEproxyE->setEnabled(on);
310 foreach (
const QModelIndex &index, m_listpop->kLVsearch->selectionModel()->selectedIndexes())
311 ids << m_resultmodel->
idForIndex(m_filtermodel.mapToSource(index));
313 const QStringList idlist(ids.toList());
314 m_listpop->kLEID->setText(idlist.join( QLatin1String(
" " )));
320 if (m_listpop->kLEID->text().isEmpty()) {
321 KMessageBox::sorry(
this, i18n(
"You must choose a key."));
324 const QStringList keys = m_listpop->kLEID->text().simplified().split(QLatin1Char(
' '));
325 m_dialogserver->close();
326 startImport(keys, page->kCBimportks->currentText(), page->kLEproxyI->text());
331 slotExport(QStringList(page->kCBexportkey->currentText().section(QLatin1Char(
':' ), 0, 0)));
342 if (!serverList.isEmpty()) {
343 serverList.replaceInStrings(QRegExp(QLatin1String(
" .*")), QString());
344 const QString defaultServer(serverList.takeFirst());
346 serverList.prepend(defaultServer);
354 if (m_searchproc != NULL) {
355 QApplication::restoreOverrideCursor();
356 disconnect(m_searchproc, 0, 0, 0);
357 m_searchproc->deleteLater();
360 m_dialogserver->close();
361 page->Buttonsearch->setEnabled(
true);
366 page->kCBimportks->setCurrentIndex(page->kCBimportks->findText(server));
369 void KeyServer::slotSetFilterString(
const QString &expression)
371 m_filtermodel.setFilterRegExp(QRegExp(expression, Qt::CaseInsensitive, QRegExp::RegExp2));
374 #include "keyservers.moc"
void slotSetKeyserver(const QString &server)
base class for transactions downloading from key servers
QString getImportMessage() const
get textual summary of the import events
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const
void start()
Start the operation.
void setKeyModel(KGpgItemModel *)
static QString getDetailedImportMessage(const QStringList &log, const KGpgItemModel *model=NULL)
get detailed summary of import
void slotEnableProxyI(const bool &on)
const QStringList & getLog() const
void setTrustFilter(const KgpgCore::KgpgKeyTrustFlag t)
set the minimum trust level to be shown
Model of the results of a keyserver search.
static bool useProxy()
Get Use HTTP proxy when available.
KeyServer(QWidget *parent=0, KGpgItemModel *model=0, const bool autoclose=false)
void slotSetText(const QString &text)
void slotExport(const QStringList &keyIds)
base class for transactions downloading from key servers
void startImport(const QStringList &keys, QString server=QString(), const QString &proxy=QString())
import the given keys
void importFailed()
importing failed
trust value undefined (i.e. you did not set a trust level)
the user aborted the transaction
virtual QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
static QStringList keyServers()
Get Key servers used by KGpg.
const QString & idForIndex(const QModelIndex &index) const
get the key fingerprint for the given index
const QStringList & getLog() const
class for downloading new keys from keyserver
static QStringList getServerList()
Returns the server list.
void importFinished(QStringList)
void slotEnableProxyE(const bool &on)
static QStringList getImportedIds(const QStringList &log, const int reason=-1)
get the full fingerprints of the imported keys
void slotTextChanged(const QString &text)
class for uploading keys from the keyring to a keyserver
void slotSetExportAttribute(const QString &attr)