~ubuntu-branches/ubuntu/trusty/keepass2/trusty-proposed

« back to all changes in this revision

Viewing changes to KeePass/Forms/PwGeneratorForm.cs

  • Committer: Package Import Robot
  • Author(s): Julian Taylor
  • Date: 2011-12-30 15:45:59 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20111230154559-3en1b9v90hswvs1w
Tags: 2.18+dfsg-1
* New upstream release
  - refresh patches
  - drop upstream applied patches:
    explicitly-PUT-for-webdav-writes.patch
    prefer-4.0-framework-if-available.patch
* add patch to improve autotype when dealing with multiple keyboard layouts
  - Thanks to amiryal for the patch
* disable initial autoupdate popup via patch
* update years in debian/copyright

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
  KeePass Password Safe - The Open-Source Password Manager
3
 
  Copyright (C) 2003-2011 Dominik Reichl <dominik.reichl@t-online.de>
 
3
  Copyright (C) 2003-2012 Dominik Reichl <dominik.reichl@t-online.de>
4
4
 
5
5
  This program is free software; you can redistribute it and/or modify
6
6
  it under the terms of the GNU General Public License as published by
100
100
                        FontUtil.AssignDefaultBold(m_rbStandardCharSet);
101
101
                        FontUtil.AssignDefaultBold(m_rbPattern);
102
102
                        FontUtil.AssignDefaultBold(m_rbCustom);
 
103
                        FontUtil.AssignDefaultMono(m_tbPreview, true);
103
104
 
104
105
                        m_ttMain.SetToolTip(m_btnProfileAdd, KPRes.GenProfileSaveDesc);
105
106
                        m_ttMain.SetToolTip(m_btnProfileRemove, KPRes.GenProfileRemoveDesc);
165
166
 
166
167
                        m_cmbProfiles.SelectedIndex = ((m_optInitial == null) ? 0 : 1);
167
168
 
168
 
                        PwGeneratorUtil.AddStandardProfilesIfNoneAvailable();
169
 
 
170
 
                        foreach(PwProfile ppw in Program.Config.PasswordGenerator.UserProfiles)
 
169
                        foreach(PwProfile ppw in PwGeneratorUtil.GetAllProfiles(true))
171
170
                        {
172
171
                                m_cmbProfiles.Items.Add(ppw.Name);
173
172
 
234
233
 
235
234
                        string strProfile = m_cmbProfiles.Text;
236
235
                        m_btnProfileRemove.Enabled = ((strProfile != CustomMeta) &&
237
 
                                (strProfile != DeriveFromPrevious) &&
238
 
                                (strProfile != AutoGeneratedMeta));
 
236
                                (strProfile != DeriveFromPrevious) && (strProfile != AutoGeneratedMeta) &&
 
237
                                !PwGeneratorUtil.IsBuiltInProfile(strProfile));
239
238
 
240
239
                        m_tabAdvanced.Text = ((m_cbExcludeLookAlike.Checked ||
241
240
                                m_cbNoRepeat.Checked || (m_tbExcludeChars.Text.Length > 0)) ?
372
371
                                SetGenerationOptions(Program.Config.PasswordGenerator.AutoGeneratedPasswordsProfile);
373
372
                        else
374
373
                        {
375
 
                                foreach(PwProfile pwgo in Program.Config.PasswordGenerator.UserProfiles)
 
374
                                foreach(PwProfile pwgo in PwGeneratorUtil.GetAllProfiles(false))
376
375
                                {
377
376
                                        if(pwgo.Name == strProfile)
378
377
                                        {
405
404
                                pwCurrent.Name = strProfile;
406
405
 
407
406
                                if(strProfile.Equals(CustomMeta) || strProfile.Equals(DeriveFromPrevious) ||
408
 
                                        (strProfile.Length == 0))
 
407
                                        (strProfile.Length == 0) || PwGeneratorUtil.IsBuiltInProfile(strProfile))
409
408
                                {
410
409
                                        MessageService.ShowWarning(KPRes.FieldNameInvalid);
411
410
                                }
417
416
                                }
418
417
                                else
419
418
                                {
 
419
                                        List<PwProfile> lUser = Program.Config.PasswordGenerator.UserProfiles;
 
420
 
420
421
                                        bool bExists = false;
421
 
                                        for(int i = 0; i < Program.Config.PasswordGenerator.UserProfiles.Count; ++i)
 
422
                                        for(int i = 0; i < lUser.Count; ++i)
422
423
                                        {
423
 
                                                if(Program.Config.PasswordGenerator.UserProfiles[i].Name == strProfile)
 
424
                                                if(lUser[i].Name.Equals(strProfile, StrUtil.CaseIgnoreCmp))
424
425
                                                {
425
 
                                                        Program.Config.PasswordGenerator.UserProfiles[i] = pwCurrent;
426
 
                                                        m_cmbProfiles.SelectedIndex = m_cmbProfiles.FindString(strProfile);
427
 
                                                        bExists = true;
 
426
                                                        lUser[i] = pwCurrent;
 
427
 
 
428
                                                        for(int j = 0; j < m_cmbProfiles.Items.Count; ++j)
 
429
                                                        {
 
430
                                                                if(m_cmbProfiles.Items[j].ToString().Equals(strProfile,
 
431
                                                                        StrUtil.CaseIgnoreCmp))
 
432
                                                                {
 
433
                                                                        m_bBlockUIUpdate = true;
 
434
                                                                        m_cmbProfiles.Items[j] = strProfile; // Fix case
 
435
                                                                        m_bBlockUIUpdate = false;
 
436
                                                                        m_cmbProfiles.SelectedIndex = j;
 
437
                                                                        bExists = true;
 
438
                                                                        break;
 
439
                                                                }
 
440
                                                        }
 
441
 
 
442
                                                        break;
428
443
                                                }
429
444
                                        }
430
445
 
431
 
                                        if(bExists == false)
 
446
                                        if(!bExists)
432
447
                                        {
433
 
                                                Program.Config.PasswordGenerator.UserProfiles.Add(pwCurrent);
434
 
                                                m_cmbProfiles.Items.Add(strProfile);
435
 
                                                m_cmbProfiles.SelectedIndex = m_cmbProfiles.Items.Count - 1;
 
448
                                                m_bBlockUIUpdate = true;
 
449
 
 
450
                                                List<PwProfile> lAll = PwGeneratorUtil.GetAllProfiles(false);
 
451
                                                for(int c = 0; c < lAll.Count; ++c)
 
452
                                                        m_cmbProfiles.Items.RemoveAt(m_cmbProfiles.Items.Count - 1);
 
453
 
 
454
                                                lUser.Add(pwCurrent);
 
455
 
 
456
                                                int iNewSel = 0;
 
457
                                                foreach(PwProfile pwAdd in PwGeneratorUtil.GetAllProfiles(true))
 
458
                                                {
 
459
                                                        m_cmbProfiles.Items.Add(pwAdd.Name);
 
460
                                                        if(pwAdd.Name == strProfile)
 
461
                                                                iNewSel = m_cmbProfiles.Items.Count - 1;
 
462
                                                }
 
463
 
 
464
                                                m_bBlockUIUpdate = false;
 
465
                                                m_cmbProfiles.SelectedIndex = iNewSel;
436
466
                                        }
437
467
                                }
438
468
                        }
446
476
                        string strProfile = m_cmbProfiles.Text;
447
477
 
448
478
                        if((strProfile == CustomMeta) || (strProfile == DeriveFromPrevious) ||
449
 
                                (strProfile == AutoGeneratedMeta))
 
479
                                (strProfile == AutoGeneratedMeta) || PwGeneratorUtil.IsBuiltInProfile(strProfile))
450
480
                                return;
451
481
 
452
482
                        m_cmbProfiles.SelectedIndex = 0;
456
486
                                {
457
487
                                        m_cmbProfiles.Items.RemoveAt(i);
458
488
 
459
 
                                        List<PwProfile> lProfiles = Program.Config.PasswordGenerator.UserProfiles;
460
 
                                        for(int j = 0; j < lProfiles.Count; ++j)
 
489
                                        List<PwProfile> lUser = Program.Config.PasswordGenerator.UserProfiles;
 
490
                                        for(int j = 0; j < lUser.Count; ++j)
461
491
                                        {
462
 
                                                if(lProfiles[j].Name == strProfile)
 
492
                                                if(lUser[j].Name == strProfile)
463
493
                                                {
464
 
                                                        lProfiles.RemoveAt(j);
 
494
                                                        lUser.RemoveAt(j);
465
495
                                                        break;
466
496
                                                }
467
497
                                        }
499
529
                        {
500
530
                                Application.DoEvents();
501
531
 
502
 
                                ProtectedString psNew = new ProtectedString(false);
503
 
                                PwGenerator.Generate(psNew, pwOpt, null, Program.PwGeneratorPool);
 
532
                                ProtectedString psNew;
 
533
                                PwGenerator.Generate(out psNew, pwOpt, null, Program.PwGeneratorPool);
504
534
                                sbList.AppendLine(psNew.ReadString());
505
535
                                m_pbPreview.Value = (int)((100 * i) / MaxPreviewPasswords);
506
536
                        }