File: AceMainWindow.cs

package info (click to toggle)
keepass2 2.41%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 13,892 kB
  • sloc: cs: 103,600; xml: 5,869; cpp: 308; sh: 48; makefile: 46
file content (724 lines) | stat: -rw-r--r-- 17,487 bytes parent folder | download
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
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
/*
  KeePass Password Safe - The Open-Source Password Manager
  Copyright (C) 2003-2019 Dominik Reichl <dominik.reichl@t-online.de>

  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.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.Text;
using System.Windows.Forms;
using System.Xml.Serialization;

using KeePass.Resources;
using KeePass.UI;

using KeePassLib;
using KeePassLib.Security;

namespace KeePass.App.Configuration
{
	public enum AceMainWindowLayout
	{
		Default = 0,
		SideBySide = 1
	}

	[Flags]
	public enum AceListGrouping
	{
		Auto = 0,
		On = 1,
		Off = 2,

		// Additional flags: use value > Primary

		Primary = 0x0F // Auto/On/Off are primary states
	}

	public enum AceEscAction
	{
		None = 0,
		Lock = 1,
		Minimize = 2,
		MinimizeToTray = 3,
		Exit = 4
	}

	public sealed class AceMainWindow
	{
		public AceMainWindow()
		{
		}

		private int m_posX = AppDefs.InvalidWindowValue;
		public int X
		{
			get { return m_posX; }
			set { m_posX = value; }
		}

		private int m_posY = AppDefs.InvalidWindowValue;
		public int Y
		{
			get { return m_posY; }
			set { m_posY = value; }
		}

		private int m_sizeW = AppDefs.InvalidWindowValue;
		public int Width
		{
			get { return m_sizeW; }
			set { m_sizeW = value; }
		}

		private int m_sizeH = AppDefs.InvalidWindowValue;
		public int Height
		{
			get { return m_sizeH; }
			set { m_sizeH = value; }
		}

		private bool m_bMax = false;
		[DefaultValue(false)]
		public bool Maximized
		{
			get { return m_bMax; }
			set { m_bMax = value; }
		}

		private double m_dSplitterHorz = double.Epsilon;
		public double SplitterHorizontalFrac
		{
			get { return m_dSplitterHorz; }
			set { m_dSplitterHorz = value; }
		}

		private double m_dSplitterVert = double.Epsilon;
		public double SplitterVerticalFrac
		{
			get { return m_dSplitterVert; }
			set { m_dSplitterVert = value; }
		}

		private AceMainWindowLayout m_layout = AceMainWindowLayout.Default;
		[DefaultValue(AceMainWindowLayout.Default)]
		public AceMainWindowLayout Layout
		{
			get { return m_layout; }
			set { m_layout = value; }
		}

		private bool m_bTop = false;
		[DefaultValue(false)]
		public bool AlwaysOnTop
		{
			get { return m_bTop; }
			set { m_bTop = value; }
		}

		private bool m_bCloseMin = false;
		[DefaultValue(false)]
		public bool CloseButtonMinimizesWindow
		{
			get { return m_bCloseMin; }
			set { m_bCloseMin = value; }
		}

		// For backward compatibility only; use EscAction instead
		private bool m_bEscMin = false;
		[DefaultValue(false)]
		public bool EscMinimizesToTray
		{
			get { return m_bEscMin; }
			set { m_bEscMin = value; }
		}

		private AceEscAction m_aEsc = AceEscAction.Lock;
		[DefaultValue(AceEscAction.Lock)]
		public AceEscAction EscAction
		{
			get { return m_aEsc; }
			set { m_aEsc = value; }
		}

		private bool m_bMinToTray = false;
		[DefaultValue(false)]
		public bool MinimizeToTray
		{
			get { return m_bMinToTray; }
			set { m_bMinToTray = value; }
		}

		private bool m_bFullPath = false;
		[DefaultValue(false)]
		public bool ShowFullPathInTitle
		{
			get { return m_bFullPath; }
			set { m_bFullPath = value; }
		}

		private bool m_bDropToBackAfterCopy = false;
		[DefaultValue(false)]
		public bool DropToBackAfterClipboardCopy
		{
			get { return m_bDropToBackAfterCopy; }
			set { m_bDropToBackAfterCopy = value; }
		}

		private bool m_bMinAfterCopy = false;
		[DefaultValue(false)]
		public bool MinimizeAfterClipboardCopy
		{
			get { return m_bMinAfterCopy; }
			set { m_bMinAfterCopy = value; }
		}

		private bool m_bMinAfterAutoType = false;
		[DefaultValue(false)]
		public bool MinimizeAfterAutoType
		{
			get { return m_bMinAfterAutoType; }
			set { m_bMinAfterAutoType = value; }
		}

		private bool m_bMinAfterLocking = true;
		[DefaultValue(true)]
		public bool MinimizeAfterLocking
		{
			get { return m_bMinAfterLocking; }
			set { m_bMinAfterLocking = value; }
		}

		private bool m_bMinAfterOpeningDb = false;
		[DefaultValue(false)]
		public bool MinimizeAfterOpeningDatabase
		{
			get { return m_bMinAfterOpeningDb; }
			set { m_bMinAfterOpeningDb = value; }
		}

		private bool m_bQuickFindSearchInPasswords = false;
		[DefaultValue(false)]
		public bool QuickFindSearchInPasswords
		{
			get { return m_bQuickFindSearchInPasswords; }
			set { m_bQuickFindSearchInPasswords = value; }
		}

		private bool m_bQuickFindExcludeExpired = false;
		[DefaultValue(false)]
		public bool QuickFindExcludeExpired
		{
			get { return m_bQuickFindExcludeExpired; }
			set { m_bQuickFindExcludeExpired = value; }
		}

		private bool m_bQuickFindDerefData = false;
		[DefaultValue(false)]
		public bool QuickFindDerefData
		{
			get { return m_bQuickFindDerefData; }
			set { m_bQuickFindDerefData = value; }
		}

		private bool m_bFocusResAfterQuickFind = false;
		[DefaultValue(false)]
		public bool FocusResultsAfterQuickFind
		{
			get { return m_bFocusResAfterQuickFind; }
			set { m_bFocusResAfterQuickFind = value; }
		}

		private bool m_bFocusQuickFindOnRestore = false;
		/// <summary>
		/// Focus the quick search box when restoring the main
		/// window. Here 'restoring' actually means unminimizing,
		/// i.e. restoring or maximizing the window.
		/// </summary>
		[DefaultValue(false)]
		public bool FocusQuickFindOnRestore
		{
			get { return m_bFocusQuickFindOnRestore; }
			set { m_bFocusQuickFindOnRestore = value; }
		}

		private bool m_bFocusQuickFindOnUntray = false;
		[DefaultValue(false)]
		public bool FocusQuickFindOnUntray
		{
			get { return m_bFocusQuickFindOnUntray; }
			set { m_bFocusQuickFindOnUntray = value; }
		}

		private bool m_bCopyUrls = false;
		[DefaultValue(false)]
		public bool CopyUrlsInsteadOfOpening
		{
			get { return m_bCopyUrls; }
			set { m_bCopyUrls = value; }
		}

		private bool m_bEntrySelGroupSel = true;
		[DefaultValue(true)]
		public bool EntrySelGroupSel
		{
			get { return m_bEntrySelGroupSel; }
			set { m_bEntrySelGroupSel = value; }
		}

		private bool m_bDisableSaveIfNotModified = false;
		/// <summary>
		/// Disable 'Save' button (instead of graying it out) if the database
		/// hasn't been modified.
		/// </summary>
		[DefaultValue(false)]
		public bool DisableSaveIfNotModified
		{
			get { return m_bDisableSaveIfNotModified; }
			set { m_bDisableSaveIfNotModified = value; }
		}

		private bool m_bHideCloseDbTb = true;
		[DefaultValue(true)]
		public bool HideCloseDatabaseButton
		{
			get { return m_bHideCloseDbTb; }
			set { m_bHideCloseDbTb = value; }
		}

		private AceToolBar m_tb = new AceToolBar();
		public AceToolBar ToolBar
		{
			get { return m_tb; }
			set
			{
				if(value == null) throw new ArgumentNullException("value");
				m_tb = value;
			}
		}

		private AceEntryView m_ev = new AceEntryView();
		public AceEntryView EntryView
		{
			get { return m_ev; }
			set
			{
				if(value == null) throw new ArgumentNullException("value");
				m_ev = value;
			}
		}

		private AceTanView m_tan = new AceTanView();
		public AceTanView TanView
		{
			get { return m_tan; }
			set
			{
				if(value == null) throw new ArgumentNullException("value");
				m_tan = value;
			}
		}

		private List<AceColumn> m_aceColumns = new List<AceColumn>();
		[XmlArray("EntryListColumnCollection")]
		public List<AceColumn> EntryListColumns
		{
			get { return m_aceColumns; }
			set
			{
				if(value == null) throw new ArgumentNullException("value");
				m_aceColumns = value;
			}
		}

		private string m_strDisplayIndices = string.Empty;
		[DefaultValue("")]
		public string EntryListColumnDisplayOrder
		{
			get { return m_strDisplayIndices; }
			set
			{
				if(value == null) throw new ArgumentNullException("value");
				m_strDisplayIndices = value;
			}
		}

		private bool m_bAutoResizeColumns = false;
		[DefaultValue(false)]
		public bool EntryListAutoResizeColumns
		{
			get { return m_bAutoResizeColumns; }
			set { m_bAutoResizeColumns = value; }
		}

		private bool m_bAlternatingBgColor = true;
		[DefaultValue(true)]
		public bool EntryListAlternatingBgColors
		{
			get { return m_bAlternatingBgColor; }
			set { m_bAlternatingBgColor = value; }
		}

		private int m_argbAltBgColor = 0;
		[DefaultValue(0)]
		public int EntryListAlternatingBgColor
		{
			get { return m_argbAltBgColor; }
			set { m_argbAltBgColor = value; }
		}

		private bool m_bResolveFieldRefs = false;
		[DefaultValue(false)]
		public bool EntryListShowDerefData
		{
			get { return m_bResolveFieldRefs; }
			set { m_bResolveFieldRefs = value; }
		}

		private bool m_bResolveFieldRefsAsync = false;
		[DefaultValue(false)]
		public bool EntryListShowDerefDataAsync
		{
			get { return m_bResolveFieldRefsAsync; }
			set { m_bResolveFieldRefsAsync = value; }
		}

		private bool m_bDerefDataWithRefs = true;
		[DefaultValue(true)]
		public bool EntryListShowDerefDataAndRefs
		{
			get { return m_bDerefDataWithRefs; }
			set { m_bDerefDataWithRefs = value; }
		}

		// private bool m_bGridLines = false;
		// public bool ShowGridLines
		// {
		//	get { return m_bGridLines; }
		//	set { m_bGridLines = value; }
		// }

		private ListSorter m_pListSorter = null;
		public ListSorter ListSorting
		{
			get
			{
				if(m_pListSorter == null) m_pListSorter = new ListSorter();
				return m_pListSorter;
			}
			set
			{
				if(value == null) throw new ArgumentNullException("value");
				m_pListSorter = value;
			}
		}

		private int m_iLgMain = (int)AceListGrouping.Auto;
		[DefaultValue((int)AceListGrouping.Auto)]
		public int ListGrouping // AceListGrouping
		{
			get { return m_iLgMain; }
			set { m_iLgMain = value; }
		}

		private bool m_bShowEntriesOfSubGroups = false;
		[DefaultValue(false)]
		public bool ShowEntriesOfSubGroups
		{
			get { return m_bShowEntriesOfSubGroups; }
			set { m_bShowEntriesOfSubGroups = value; }
		}

		public AceColumn FindColumn(AceColumnType t)
		{
			foreach(AceColumn c in m_aceColumns)
			{
				if(c.Type == t) return c;
			}

			return null;
		}

		public bool IsColumnHidden(AceColumnType t)
		{
			return IsColumnHidden(t, (t == AceColumnType.Password));
		}

		public bool IsColumnHidden(AceColumnType t, bool bDefault)
		{
			foreach(AceColumn c in m_aceColumns)
			{
				if(c.Type == t) return c.HideWithAsterisks;
			}

			return bDefault;
		}

		public bool ShouldHideCustomString(string strCustomName,
			ProtectedString psValue)
		{
			foreach(AceColumn c in m_aceColumns)
			{
				if((c.Type == AceColumnType.CustomString) &&
					(c.CustomName == strCustomName))
					return c.HideWithAsterisks;
			}
			if(psValue != null) return psValue.IsProtected;
			return false;
		}
	}

	public sealed class AceEntryView
	{
		public AceEntryView()
		{
		}

		private bool m_bShow = true;
		[DefaultValue(true)]
		public bool Show
		{
			get { return m_bShow; }
			set { m_bShow = value; }
		}

		// private bool m_bHideProtectedCustomStrings = true;
		// [DefaultValue(true)]
		// public bool HideProtectedCustomStrings
		// {
		//	get { return m_bHideProtectedCustomStrings; }
		//	set { m_bHideProtectedCustomStrings = value; }
		// }
	}

	public sealed class AceTanView
	{
		public AceTanView()
		{
		}

		private bool m_bSimple = true;
		[DefaultValue(true)]
		public bool UseSimpleView
		{
			get { return m_bSimple; }
			set { m_bSimple = value; }
		}

		private bool m_bIndices = true;
		[DefaultValue(true)]
		public bool ShowIndices
		{
			get { return m_bIndices; }
			set { m_bIndices = value; }
		}
	}

	public enum AceColumnType
	{
		Title = 0,
		UserName,
		Password,
		Url,
		Notes,
		CreationTime,
		LastModificationTime,
		LastAccessTime,
		ExpiryTime,
		Uuid,
		Attachment,

		CustomString,

		PluginExt, // Column data provided by a plugin

		OverrideUrl,
		Tags,
		ExpiryTimeDateOnly,
		Size,
		HistoryCount,
		AttachmentCount,
		LastPasswordModTime,

		Count // Virtual identifier representing the number of types
	}

	[XmlType(TypeName = "Column")]
	public sealed class AceColumn
	{
		private AceColumnType m_type = AceColumnType.Count;
		public AceColumnType Type
		{
			get { return m_type; }
			set
			{
				if(((int)value >= 0) && ((int)value < (int)AceColumnType.Count))
					m_type = value;
				else { Debug.Assert(false); }
			}
		}

		private string m_strCustomName = string.Empty;
		[DefaultValue("")]
		public string CustomName
		{
			get { return m_strCustomName; }
			set
			{
				if(value == null) throw new ArgumentNullException("value");
				m_strCustomName = value;
			}
		}

		private int m_nWidth = -1;
		public int Width
		{
			get { return m_nWidth; }
			set { m_nWidth = value; }
		}

		private bool m_bHide = false;
		[DefaultValue(false)]
		public bool HideWithAsterisks
		{
			get { return m_bHide; }
			set { m_bHide = value; }
		}

		public AceColumn()
		{
		}

		public AceColumn(AceColumnType t)
		{
			m_type = t;
		}

		public AceColumn(AceColumnType t, string strCustomName, bool bHide,
			int nWidth)
		{
			m_type = t;
			m_strCustomName = strCustomName;
			m_bHide = bHide;
			m_nWidth = nWidth;
		}

		public string GetDisplayName()
		{
			string str = string.Empty;

			switch(m_type)
			{
				case AceColumnType.Title: str = KPRes.Title; break;
				case AceColumnType.UserName: str = KPRes.UserName; break;
				case AceColumnType.Password: str = KPRes.Password; break;
				case AceColumnType.Url: str = KPRes.Url; break;
				case AceColumnType.Notes: str = KPRes.Notes; break;
				case AceColumnType.CreationTime: str = KPRes.CreationTime; break;
				case AceColumnType.LastModificationTime: str = KPRes.LastModificationTime; break;
				case AceColumnType.LastAccessTime: str = KPRes.LastAccessTime; break;
				case AceColumnType.ExpiryTime: str = KPRes.ExpiryTime; break;
				case AceColumnType.Uuid: str = KPRes.Uuid; break;
				case AceColumnType.Attachment: str = KPRes.Attachments; break;
				case AceColumnType.CustomString: str = m_strCustomName; break;
				case AceColumnType.PluginExt: str = m_strCustomName; break;
				case AceColumnType.OverrideUrl: str = KPRes.UrlOverride; break;
				case AceColumnType.Tags: str = KPRes.Tags; break;
				case AceColumnType.ExpiryTimeDateOnly: str = KPRes.ExpiryTimeDateOnly; break;
				case AceColumnType.Size: str = KPRes.Size; break;
				case AceColumnType.HistoryCount:
					str = KPRes.History + " (" + KPRes.Count + ")"; break;
				case AceColumnType.AttachmentCount:
					str = KPRes.Attachments + " (" + KPRes.Count + ")"; break;
				case AceColumnType.LastPasswordModTime: str = KPRes.LastModTimePwHist; break;
				default: Debug.Assert(false); break;
			};

			return str;
		}

		public int SafeGetWidth(int nDefaultWidth)
		{
			if(m_nWidth >= 0) return m_nWidth;
			return nDefaultWidth;
		}

		internal string GetTypeNameEx()
		{
			try
			{
				string str = m_type.ToString();

				if(!string.IsNullOrEmpty(m_strCustomName))
					str += " - " + m_strCustomName;

				return str;
			}
			catch(Exception) { Debug.Assert(false); }

			return ((long)m_type).ToString(NumberFormatInfo.InvariantInfo);
		}

#if DEBUG
		public override string ToString()
		{
			return (GetTypeNameEx() + ", Width: " + m_nWidth.ToString() +
				", Hide: " + m_bHide.ToString());
		}
#endif

		public static bool IsTimeColumn(AceColumnType t)
		{
			return ((t == AceColumnType.CreationTime) ||
				(t == AceColumnType.LastModificationTime) ||
				(t == AceColumnType.LastAccessTime) ||
				(t == AceColumnType.ExpiryTime) ||
				(t == AceColumnType.ExpiryTimeDateOnly) ||
				(t == AceColumnType.LastPasswordModTime));

			/* bool bTime = false;
			switch(t)
			{
				case AceColumnType.CreationTime:
				case AceColumnType.LastModificationTime:
				case AceColumnType.LastAccessTime:
				case AceColumnType.ExpiryTime:
				case AceColumnType.ExpiryTimeDateOnly:
				case AceColumnType.LastPasswordModTime:
					bTime = true;
					break;
				default:
					break;
			}

			return bTime; */
		}

		public static HorizontalAlignment GetTextAlign(AceColumnType t)
		{
			if((t == AceColumnType.Size) || (t == AceColumnType.HistoryCount) ||
				(t == AceColumnType.AttachmentCount))
				return HorizontalAlignment.Right;

			return HorizontalAlignment.Left;
		}
	}
}