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
|
/*
KeePass Password Safe - The Open-Source Password Manager
Copyright (C) 2003-2012 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.Drawing;
using System.Text;
using System.Windows.Forms;
using KeePass.Resources;
using KeePass.UI;
using KeePassLib;
using KeePassLib.Interfaces;
namespace KeePass.Forms
{
public partial class StatusLoggerForm : Form, IStatusLogger
{
private bool m_bIsModal = false;
private bool m_bCancelled = false;
private bool m_bCloseMode = false;
private uint m_uLastPercent = 0;
private uint uWarnings = 0;
private uint uErrors = 0;
public void InitEx(bool bIsModal)
{
m_bIsModal = bIsModal;
}
public void StartLogging(string strOperation, bool bWriteOperationToLog)
{
if(strOperation != null)
{
this.Text = PwDefs.ShortProductName + " - " + strOperation;
if(bWriteOperationToLog)
this.SetText(strOperation, LogStatusType.Info);
}
m_pbProgress.Value = 0;
m_uLastPercent = 0;
}
public void EndLogging()
{
m_btnCancel.Text = KPRes.CloseButton;
m_bCloseMode = true;
this.SetText(string.Empty, LogStatusType.AdditionalInfo);
string strFinish = KPRes.Ready + " " + uErrors.ToString() + " " + KPRes.Errors +
", " + uWarnings.ToString() + " " + KPRes.Warnings + ".";
this.SetText(strFinish, LogStatusType.Info);
m_pbProgress.Value = 100;
m_uLastPercent = 100;
Application.DoEvents();
}
public bool SetProgress(uint uPercent)
{
if(uPercent != m_uLastPercent)
{
m_pbProgress.Value = (int)uPercent;
m_uLastPercent = uPercent;
Application.DoEvents();
}
return !m_bCancelled;
}
public bool SetText(string strNewText, LogStatusType lsType)
{
if(strNewText != null)
{
m_lvMessages.Items.Add(strNewText, (int)lsType);
m_lvMessages.EnsureVisible(m_lvMessages.Items.Count - 1);
}
if(lsType == LogStatusType.Warning) ++uWarnings;
else if(lsType == LogStatusType.Error) ++uErrors;
ProcessResize();
Application.DoEvents();
return !m_bCancelled;
}
public bool ContinueWork()
{
Application.DoEvents();
return !m_bCancelled;
}
public StatusLoggerForm()
{
InitializeComponent();
Program.Translation.ApplyTo(this);
}
private void OnFormLoad(object sender, EventArgs e)
{
GlobalWindowManager.AddWindow(this);
this.Icon = new Icon("/usr/share/keepass2/KeePass.ico");
this.Text = PwDefs.ShortProductName;
m_pbProgress.Minimum = 0;
m_pbProgress.Maximum = 100;
int nWidth = m_lvMessages.ClientRectangle.Width - 1;
m_lvMessages.Columns.Add("<>", nWidth);
ProcessResize();
}
private void ProcessResize()
{
if(m_lvMessages.Columns.Count > 0)
{
int nColumnWidth = m_lvMessages.ClientRectangle.Width - 2;
m_lvMessages.Columns[0].Width = nColumnWidth;
}
}
private void OnBtnCancel(object sender, EventArgs e)
{
if(m_bCloseMode)
{
if(m_bIsModal) this.DialogResult = DialogResult.Cancel;
else Close();
}
else
{
m_bCancelled = true;
this.DialogResult = DialogResult.None;
}
}
private void OnMessagesSelectedIndexChanged(object sender, EventArgs e)
{
ListView.SelectedListViewItemCollection slvic = m_lvMessages.SelectedItems;
if(slvic.Count == 0)
{
m_tbDetails.Text = string.Empty;
return;
}
m_tbDetails.Text = slvic[0].Text;
}
private void OnFormClosed(object sender, FormClosedEventArgs e)
{
GlobalWindowManager.RemoveWindow(this);
}
}
}
|