1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
|
/***************************************************************************
kgpgoptions.cpp - description
-------------------
begin : Mon Jul 8 2002
copyright : (C) 2002 by Jean-Baptiste Mardelle
email : bj@altern.org
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/////////////////////////////////////////////// code for the option dialog box
#include <config.h>
#include <tqlayout.h>
#include <tqtabwidget.h>
#include <tqlabel.h>
#include <tqtoolbutton.h>
#include <tqfile.h>
#include <tdeconfig.h>
#include <tdeversion.h>
#include <tdelocale.h>
#include <kprocio.h>
#include <tqcheckbox.h>
#include <tqradiobutton.h>
#include <tqpushbutton.h>
#include <tqfont.h>
#include <tdeaction.h>
#include <tdemessagebox.h>
#include <klineedit.h>
#include <kcombobox.h>
#include <kurlrequester.h>
#include <kiconloader.h>
#include <tdefiledialog.h>
#include <kinputdialog.h>
#include <tdefontdialog.h>
#include <kdesktopfile.h>
#include <kstandarddirs.h>
#include <kcolorbutton.h>
#include <stdlib.h>
#include <kdebug.h>
#include <kactivelabel.h>
#include "kgpgoptions.h"
#include "kgpgsettings.h"
#include "listkeys.h"
#include "conf_decryption.h"
#include "conf_encryption.h"
#include "conf_gpg.h"
#include "conf_servers.h"
#include "conf_ui2.h"
#include "conf_misc.h"
class TQTabWidget;
/////////////////////// main window
kgpgOptions::kgpgOptions(TQWidget *parent, const char *name)
: TDEConfigDialog( parent, name, KGpgSettings::self())
{
defaultKeyServer="hkp://pool.sks-keyservers.net";
defaultServerList=defaultKeyServer;
// defaultServerList+=i18n("(Default)");
// defaultServerList+=",hkp://search.keyserver.net,hkp://wwwkeys.pgp.net,hkp://pgp.dtype.org,hkp://wwwkeys.us.pgp.net";
config = new TDEConfig ("kgpgrc");
config->setGroup("Servers");
defaultKeyServer=config->readEntry("Default_Server",defaultKeyServer);
TQString keyServer = KgpgInterface::getGpgSetting("keyserver", KGpgSettings::gpgConfigPath());
if (!keyServer.isEmpty() ) {
defaultKeyServer=keyServer;
}
serverList=TQStringList::split (",",config->readEntry("Server_List",defaultServerList));
// kdDebug(2100)<<"Servers: "<< serverList.join(", ")<<endl;
defaultHomePath=TQDir::homeDirPath()+"/.gnupg/";
if (TQFile(defaultHomePath+"options").exists()) defaultConfigPath="options";
else
{
if (TQFile(defaultHomePath+"gpg.conf").exists()) defaultConfigPath="gpg.conf";
else defaultConfigPath=TQString();
}
// kdDebug(2100)<<"Adding pages"<<endl;
page1=new Encryption();
page2=new Decryption();
page3=new UIConf();
page4=new GPGConf();
page6=new ServerConf();
page7=new MiscConf();
TQBoxLayout *fontLayout=new TQBoxLayout(page3->tabWidget3->page(1),TQBoxLayout::TopToBottom,10);
kfc=new TDEFontChooser(page3->tabWidget3->page(1),"kcfg_Font",false,TQStringList(),false);
fontLayout->addWidget(kfc);
page7->shredInfo->setText(i18n( "<qt><p>You must be aware that <b>shredding is not secure</b> on all file systems, and that parts of the file may have been saved in a temporary file or in the spooler of your printer if you previously opened it in an editor or tried to print it. Only works on files (not on folders).</p></qt>"));
page7->groupShred->adjustSize();
pixkeySingle=TDEGlobal::iconLoader()->loadIcon("kgpg_key1",TDEIcon::Small,20);
pixkeyDouble=TDEGlobal::iconLoader()->loadIcon("kgpg_key2",TDEIcon::Small,20);
addPage(page1, i18n("Encryption"), "encrypted");
addPage(page2, i18n("Decryption"), "decrypted");
addPage(page3, i18n("Appearance"), "preferences-desktop");
addPage(page4, i18n("GnuPG Settings"), "kgpg");
addPage(page6, i18n("Key Servers"), "network");
addPage(page7, i18n("Misc"), "misc");
page1->clear_akey->setIconSet(TQIconSet(TQPixmap(SmallIcon("clear_left"))));
page1->clear_fkey->setIconSet(TQIconSet(TQPixmap(SmallIcon("clear_left"))));
// The following widgets are managed manually.
connect(page1->change_fkey, TQT_SIGNAL(clicked()), this, TQT_SLOT(insertFileKey()));
connect(page1->clear_fkey, TQT_SIGNAL(clicked()), page1->kcfg_FileKey, TQT_SLOT(clear()));
connect(page1->change_akey, TQT_SIGNAL(clicked()), this, TQT_SLOT(insertAlwaysKey()));
connect(page1->clear_akey, TQT_SIGNAL(clicked()), page1->alwaysKey, TQT_SLOT(clear()));
connect(page1->alwaysKey, TQT_SIGNAL(textChanged(const TQString&)), this, TQT_SLOT(updateButtons()));
connect(page4->gpg_conf_path, TQT_SIGNAL(textChanged(const TQString&)), this, TQT_SLOT(updateButtons()));
connect(page4->gpg_home_path, TQT_SIGNAL(textChanged(const TQString&)), this, TQT_SLOT(updateButtons()));
connect(page4->use_agent, TQT_SIGNAL(toggled(bool)), this, TQT_SLOT(updateButtons()));
connect(page4->changeHome, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotChangeHome()));
connect(page4->kcfg_PubKeyring, TQT_SIGNAL(toggled (bool)), page4->kcfg_PubKeyringUrl, TQT_SLOT(setEnabled(bool)));
connect(page4->kcfg_PubKeyring, TQT_SIGNAL(toggled (bool)), this, TQT_SLOT(checkAdditionalState(bool)));
connect(page4->kcfg_PrivKeyring, TQT_SIGNAL(toggled (bool)), page4->kcfg_PrivKeyringUrl, TQT_SLOT(setEnabled(bool)));
connect(page4->kcfg_PrivKeyring, TQT_SIGNAL(toggled (bool)), this, TQT_SLOT(checkAdditionalState(bool)));
connect(page6->server_add, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotAddKeyServer()));
connect(page6->server_del, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotDelKeyServer()));
connect(page6->server_default, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotDefaultKeyServer()));
connect(page6->ServerBox, TQT_SIGNAL(currentChanged ( TQListBoxItem *)), this, TQT_SLOT(updateButtons()));
connect(page7->pushShredder, TQT_SIGNAL(clicked ()), this, TQT_SIGNAL(installShredder()));
//connect(this, TQT_SIGNAL(settingsChanged()), TQT_SLOT(updateSettings()));
keyGood=KGpgSettings::colorGood();
keyUnknown=KGpgSettings::colorUnknown();
keyRev=KGpgSettings::colorRev();
keyBad=KGpgSettings::colorBad();
}
kgpgOptions::~kgpgOptions()
{
delete config;
}
void kgpgOptions::checkAdditionalState(bool)
{
// enable / disable the "use only this keyring" option depending on the other checkboxes state
if (page4->kcfg_PubKeyring->isOn() && page4->kcfg_PrivKeyring->isOn())
page4->kcfg_OnlyAdditional->setEnabled(true);
else
page4->kcfg_OnlyAdditional->setEnabled(false);
}
void kgpgOptions::insertFileKey()
{
TQString signKeyID;
///// open key selection dialog
KgpgSelKey *opts=new KgpgSelKey(this,0,true,page1->kcfg_FileKey->text());
if (opts->exec()==TQDialog::Accepted) {
page1->kcfg_FileKey->setText(opts->getkeyID());
} else {
delete opts;
return;
}
delete opts;
}
void kgpgOptions::insertAlwaysKey()
{
TQString signKeyID;
///// open key selection dialog
KgpgSelKey *opts=new KgpgSelKey(this,0,true,page1->alwaysKey->text());
if (opts->exec()==TQDialog::Accepted) {
page1->alwaysKey->setText(opts->getkeyID());
} else {
delete opts;
return;
}
delete opts;
}
void kgpgOptions::slotChangeHome()
{
TQString gpgHome=KFileDialog::getExistingDirectory(page4->gpg_home_path->text(),this,i18n("New GnuPG Home Location"));
if (gpgHome.isEmpty()) {
return;
}
if (!gpgHome.endsWith("/")) {
gpgHome.append("/");
}
TQString confPath="options";
if (!TQFile(gpgHome+confPath).exists()) {
confPath="gpg.conf";
if (!TQFile(gpgHome+confPath).exists()) {
if (KMessageBox::questionYesNo(this,i18n("No configuration file was found in the selected location.\nDo you want to create it now ?\n\nWithout configuration file, neither KGpg nor Gnupg will work properly."),i18n("No Configuration File Found"),i18n("Create"),i18n("Ignore"))
==KMessageBox::Yes) {////////// Try to create config File by running gpg once
KProcIO *p=new KProcIO();
*p<<"gpg"<<"--homedir"<<gpgHome<<"--no-tty"<<"--list-secret-keys";
p->start(TDEProcess::Block); //// start gnupg so that it will create a config file
confPath="gpg.conf";
TQFile confFile(gpgHome+confPath);
if (!confFile.open(IO_WriteOnly)) {
KMessageBox::sorry(this,i18n("Cannot create configuration file. Please check if destination media is mounted and if you have write access"));
return;
}
else {
TQTextStream stream( &confFile );
stream<<"# Config file created by KGpg\n\n";
confFile.close();
}
}
else {
confPath=TQString();
}
}
}
page4->gpg_conf_path->setText(confPath);
page4->gpg_home_path->setText(gpgHome);
}
void kgpgOptions::updateWidgets()
{
TQString pubKeyring,privKeyring;
gpgConfigPath = KGpgSettings::gpgConfigPath();
page4->gpg_conf_path->setText(KURL(gpgConfigPath).fileName());
page4->gpg_home_path->setText(KURL(gpgConfigPath).directory(false));
pubKeyring=KgpgInterface::getGpgSetting("keyring", gpgConfigPath);
if (pubKeyring!="")
{
page4->kcfg_PubKeyringUrl->setURL(pubKeyring);
page4->kcfg_PubKeyring->setChecked(true);
}
else page4->kcfg_PubKeyring->setChecked(false);
privKeyring=KgpgInterface::getGpgSetting("secret-keyring", gpgConfigPath);
if (privKeyring!="")
{
page4->kcfg_PrivKeyringUrl->setURL(privKeyring);
page4->kcfg_PrivKeyring->setChecked(true);
}
else page4->kcfg_PrivKeyring->setChecked(false);
page4->kcfg_OnlyAdditional->setChecked(KgpgInterface::getGpgBoolSetting("no-default-keyring", gpgConfigPath));
// fill some values from kgpg's config file
useAgent = KgpgInterface::getGpgBoolSetting("use-agent", gpgConfigPath);
defaultUseAgent = false;
page1->alwaysKey->setText(KgpgInterface::getGpgMultiSetting("encrypt-to", gpgConfigPath));
alwaysKeyID = page1->alwaysKey->text();
page4->use_agent->setChecked( useAgent );
TQString keyServer = KgpgInterface::getGpgSetting("keyserver", gpgConfigPath);
// defaultKeyServer = "hkp://wwwkeys.pgp.net";
if (!keyServer.isEmpty()) {
defaultKeyServer = keyServer;
}
else {
defaultKeyServer = "hkp://wwwkeys.pgp.net";
}
serverList.prepend(defaultKeyServer+" "+i18n("(Default)"));
page6->ServerBox->clear();
page6->ServerBox->insertStringList(serverList);
// kdDebug(2100)<<"Finishing options"<<endl;
}
void kgpgOptions::updateWidgetsDefault()
{
page1->alwaysKey->clear();
page1->kcfg_FileKey->clear();
page4->use_agent->setChecked( defaultUseAgent );
page4->gpg_conf_path->setText(defaultConfigPath);
page4->gpg_home_path->setText(defaultHomePath);
page4->kcfg_PubKeyringUrl->setURL(TQString());
page4->kcfg_PubKeyring->setChecked(false);
page4->kcfg_PrivKeyringUrl->setURL(TQString());
page4->kcfg_PrivKeyring->setChecked(false);
page4->kcfg_OnlyAdditional->setChecked(false);
page6->ServerBox->clear();
page6->ServerBox->insertStringList(TQStringList::split(",",defaultServerList));
// kdDebug(2100)<<"Finishing default options"<<endl;
}
bool kgpgOptions::isDefault()
{
if (!page1->alwaysKey->text().isEmpty())
return false;
if (page4->gpg_conf_path->text()!=defaultConfigPath)
return false;
if (page4->gpg_home_path->text()!=defaultHomePath)
return false;
if (page4->use_agent->isChecked() != defaultUseAgent)
return false;
TQString currList;
for (uint i=0;i<page6->ServerBox->count();i++)
currList+=page6->ServerBox->text(i)+",";
currList.truncate(currList.length()-1);
if (currList!=defaultServerList) return false;
return true;
}
bool kgpgOptions::hasChanged()
{
if (page1->alwaysKey->text()!= alwaysKeyID)
return true;
if (page4->gpg_conf_path->text() != KURL(gpgConfigPath).fileName())
return true;
if (page4->gpg_home_path->text() != KURL(gpgConfigPath).directory(false))
return true;
if (page4->use_agent->isChecked() != useAgent)
return true;
TQStringList currList;
for (uint i=0;i<page6->ServerBox->count();i++)
currList.append(page6->ServerBox->text(i));
if (currList!=serverList) return true;
return false;
}
void kgpgOptions::updateSettings()
{
// Update config path first!
KGpgSettings::setGpgConfigPath( page4->gpg_home_path->text()+page4->gpg_conf_path->text() );
KGpgSettings::writeConfig(); //Don't forget to write the config file
if (page4->gpg_home_path->text()!=KURL(gpgConfigPath).directory(false))
{
if (page4->gpg_home_path->text()!=defaultHomePath)
setenv("GNUPGHOME", TQFile::encodeName(page4->gpg_home_path->text()), 1);
else setenv("GNUPGHOME","",1);
emit homeChanged();
gpgConfigPath = KGpgSettings::gpgConfigPath();
}
bool emitReload=false;
if (page4->kcfg_OnlyAdditional->isChecked()!=KgpgInterface::getGpgBoolSetting("no-default-keyring", gpgConfigPath)) emitReload=true;
KgpgInterface::setGpgBoolSetting("no-default-keyring",page4->kcfg_OnlyAdditional->isChecked(), gpgConfigPath);
if (page4->kcfg_PubKeyring->isChecked())
{
if (page4->kcfg_PubKeyringUrl->url()!=KgpgInterface::getGpgSetting("keyring", gpgConfigPath)) emitReload=true;
KgpgInterface::setGpgSetting("keyring",page4->kcfg_PubKeyringUrl->url(), gpgConfigPath);
}
else
{
if (KgpgInterface::getGpgSetting("keyring", gpgConfigPath)!="") emitReload=true;
KgpgInterface::setGpgSetting("keyring",TQString(), gpgConfigPath);
}
if (page4->kcfg_PrivKeyring->isChecked())
{
if (page4->kcfg_PrivKeyringUrl->url()!=KgpgInterface::getGpgSetting("secret-keyring", gpgConfigPath)) emitReload=true;
KgpgInterface::setGpgSetting("secret-keyring",page4->kcfg_PrivKeyringUrl->url(), gpgConfigPath);
}
else
{
if (KgpgInterface::getGpgSetting("secret-keyring", gpgConfigPath)!="") emitReload=true;
KgpgInterface::setGpgSetting("secret-keyring",TQString(), gpgConfigPath);
}
emit changeFont(kfc->font());
/////////////// install service menus
if (page7->kcfg_SignMenu->currentItem()==KGpgSettings::EnumSignMenu::AllFiles)
slotInstallSign("all/allfiles");
else
slotRemoveMenu("signfile.desktop");
if (page7->kcfg_DecryptMenu->currentItem()==KGpgSettings::EnumDecryptMenu::AllFiles)
slotInstallDecrypt("all/allfiles");
else if (page7->kcfg_DecryptMenu->currentItem()==KGpgSettings::EnumDecryptMenu::EncryptedFiles)
slotInstallDecrypt("application/pgp-encrypted,application/pgp-signature,application/pgp-keys");
else
slotRemoveMenu("decryptfile.desktop");
KgpgInterface::setGpgMultiSetting("encrypt-to",TQStringList::split(" ",page1->alwaysKey->text()),KGpgSettings::gpgConfigPath());
alwaysKeyID = page1->alwaysKey->text();
useAgent = page4->use_agent->isChecked();
if (useAgent)
{
KgpgInterface::setGpgBoolSetting("use-agent",true, KGpgSettings::gpgConfigPath());
KgpgInterface::setGpgBoolSetting("no-use-agent",false, KGpgSettings::gpgConfigPath());
}
else
{
// KgpgInterface::setGpgBoolSetting("no-use-agent",true, KGpgSettings::gpgConfigPath());
KgpgInterface::setGpgBoolSetting("use-agent",false, KGpgSettings::gpgConfigPath());
}
////////////////// save key servers
TQString currList;
serverList=TQStringList ();
for (uint i=0;i<page6->ServerBox->count();i++) { // 0 is always the default
TQString currItem=page6->ServerBox->text(i);
if (currItem.find(" ")!=-1) {// it is the default keyserver
defaultKeyServer = currItem.section(" ",0,0);
}
else {
serverList.append(currItem);
}
}
KgpgInterface::setGpgSetting("keyserver",defaultKeyServer, KGpgSettings::gpgConfigPath());
//serverList.prepend(keyServer+" "+i18n("(Default)"));
currList=serverList.join(",");
if (keyGood!=page3->kcfg_ColorGood->color())
emit refreshTrust(GoodColor,page3->kcfg_ColorGood->color());
if (keyBad!=page3->kcfg_ColorBad->color()) emit refreshTrust(BadColor,page3->kcfg_ColorBad->color());
if (keyUnknown!=page3->kcfg_ColorUnknown->color()) emit refreshTrust(UnknownColor,page3->kcfg_ColorUnknown->color());
if (keyRev!=page3->kcfg_ColorRev->color()) emit refreshTrust(RevColor,page3->kcfg_ColorRev->color());
// KGpgSettings::writeConfig();
config->setGroup("Servers");
config->writeEntry("Default_Server",defaultKeyServer);
config->writeEntry("Server_List",currList);
emit settingsUpdated();
if (emitReload) emit reloadKeyList();
}
void kgpgOptions::slotInstallSign(TQString mimetype)
{
TQString path=locateLocal("data","konqueror/servicemenus/signfile.desktop");
KDesktopFile configl2(path, false);
if (configl2.isImmutable() ==false) {
configl2.setGroup("Desktop Entry");
configl2.writeEntry("X-TDE-ServiceTypes", mimetype);
configl2.writeEntry("Actions", "sign");
configl2.setGroup("Desktop Action sign");
configl2.writeEntry("Name",i18n("Sign File"));
//configl2.writeEntry("Icon", "sign_file");
configl2.writeEntry("Exec","kgpg -S %F");
//KMessageBox::information(this,i18n("Decrypt file option is now added in Konqueror's menu."));
}
}
void kgpgOptions::slotInstallDecrypt(TQString mimetype)
{
TQString path=locateLocal("data","konqueror/servicemenus/decryptfile.desktop");
KDesktopFile configl2(path, false);
if (configl2.isImmutable() ==false) {
configl2.setGroup("Desktop Entry");
configl2.writeEntry("X-TDE-ServiceTypes", mimetype);
configl2.writeEntry("Actions", "decrypt");
configl2.setGroup("Desktop Action decrypt");
configl2.writeEntry("Name",i18n("Decrypt File"));
//configl2.writeEntry("Icon", "decrypt_file");
configl2.writeEntry("Exec","kgpg %U");
//KMessageBox::information(this,i18n("Decrypt file option is now added in Konqueror's menu."));
}
}
void kgpgOptions::slotRemoveMenu(TQString menu)
{
TQString path=locateLocal("data","konqueror/servicemenus/"+menu);
TQFile qfile(path);
if (qfile.exists()) {
qfile.remove();
//if (!qfile.remove()) {
// KMessageBox::sorry(this,i18n("Cannot remove service menu. Check permissions"));
//}
//else {
// KMessageBox::information(this,i18n("Service menu 'Decrypt File' has been removed."));
//}
}
//else {
// KMessageBox::sorry(this,i18n("No service menu found"));
//}
}
TQString kgpgOptions::namecode(TQString kid)
{
for ( uint counter = 0; counter<names.count(); counter++ )
if (TQString(ids[counter].right(8))==kid)
return names[counter];
return TQString();
}
TQString kgpgOptions::idcode(TQString kname)
{
for ( uint counter = 0; counter<names.count(); counter++ )
if (names[counter]==kname)
return TQString(ids[counter].right(8));
return TQString();
}
void kgpgOptions::listkey()
{
//////// update display of keys in main management window
FILE *fp;
TQString name,trustedvals="idre-",issec;
int counter=0;
char line[300];
TQString currentKey;
TQMap<TQString,TQStringList> hashMap;
FILE *fp2;
fp2 = popen("gpg --no-secmem-warning --no-tty --with-colon --list-secret-keys", "r");
while ( fgets( line, sizeof(line), fp2)) {
TQString lineRead=line;
if (lineRead.startsWith("sec"))
issec+=lineRead.section(':',4,4);
}
pclose(fp2);
fp = popen("gpg --no-tty --with-colon --list-keys", "r");
while ( fgets( line, sizeof(line), fp)) {
TQString tst=TQString::fromUtf8(line);
kdDebug(2100) << k_funcinfo << "Read one secret key line: " << tst << endl;
if ( tst.startsWith("pub") ) {
currentKey = tst.section(':',4,4);
TQStringList lst; lst << tst;
hashMap.insert(currentKey,lst);
}
else {
hashMap.find(currentKey).data().append(tst);
}
}
pclose(fp);
// process the list
TQMap<TQString,TQStringList>::Iterator ite;
for (ite = hashMap.begin(); ite != hashMap.end(); ite++) {
TDEListViewItem *item;
TQStringList::Iterator it;
bool dead = true;
TQString name,id,val;
for (it = ite.data().begin(); it != ite.data().end(); it++) {
TQString tst = (*it);
if ( tst.startsWith("pub") ) {
if ( KgpgInterface::getGpgVersion() < 210 ) {
name=KgpgInterface::checkForUtf8(tst.section(':',9,9));
}
val = tst.section(':',1,1);
id = tst.section(':',4,4);
}
if ( tst.startsWith("uid") && KgpgInterface::getGpgVersion() >= 210 ) {
name=KgpgInterface::checkForUtf8(tst.section(':',9,9));
}
}
if ((!name.isEmpty()) && (trustedvals.find(val)==-1)) {
counter++;
//name=name.section('<',-1,-1);
// name=name.section('>',0,0);
names+=name;
ids+=id;
if (id.right(8)==alwaysKeyID) {
alwaysKeyName=id.right(8)+":"+name;
}
if (issec.find(id.right(8),0,FALSE)!=-1) {
//*** page1->file_key->insertItem(pixkeyDouble,tst.section(':',4,4).right(8)+":"+name);
//*** page1->always_key->insertItem(pixkeyDouble,tst.section(':',4,4).right(8)+":"+name);
}
else {
//*** page1->file_key->insertItem(pixkeySingle,tst.section(':',4,4).right(8)+":"+name);
//*** page1->always_key->insertItem(pixkeySingle,tst.section(':',4,4).right(8)+":"+name);
}
}
}
if (counter==0) {
ids+="0";
//*** page1->file_key->insertItem(i18n("none"));
//*** page1->always_key->insertItem(i18n("none"));
}
}
void kgpgOptions::slotAddKeyServer()
{
TQString newServer=KInputDialog::getText(i18n("Add New Key Server"),i18n("Server URL:"));
if (!newServer.isEmpty()) {
page6->ServerBox->insertItem(newServer.stripWhiteSpace());
}
page6->ServerBox->setSelected(page6->ServerBox->findItem(newServer.stripWhiteSpace()),true);
}
void kgpgOptions::slotDelKeyServer()
{
bool defaultDeleted=false;
if (page6->ServerBox->currentText().find(" ")!=-1) {
defaultDeleted=true;
}
page6->ServerBox->removeItem(page6->ServerBox->currentItem());
page6->ServerBox->setSelected(0,true);
if (defaultDeleted) {
page6->ServerBox->changeItem(page6->ServerBox->currentText().section(" ",0,0)+" "+i18n("(Default)"),0);
}
}
void kgpgOptions::slotDefaultKeyServer()
{
uint curr=page6->ServerBox->currentItem();
page6->ServerBox->changeItem(page6->ServerBox->currentText ().section(" ",0,0)+" "+i18n("(Default)"),curr);
for (uint i=0;i<page6->ServerBox->count();i++) {
if (i!=curr) {
page6->ServerBox->changeItem(page6->ServerBox->text(i).section(" ",0,0),i);
}
}
page6->ServerBox->setSelected(curr,true);
}
#include "kgpgoptions.moc"
|