зеркало из https://github.com/mozilla/pjs.git
implement "clear log". make sure the log is there before viewing it, otherwise
the user gets a nasty "file not found" alert, like they would on the browser. r/sr=bienvenu. for bug #167891.
This commit is contained in:
Родитель
db68adf77f
Коммит
beb17fc222
|
@ -120,8 +120,11 @@ interface nsIMsgFilterList : nsISupports {
|
|||
void writeBoolAttr(in nsMsgFilterFileAttribValue attrib, in boolean value, in nsIOFileStream stream);
|
||||
boolean matchOrChangeFilterTarget(in string oldUri, in string newUri, in boolean caseInsensitive);
|
||||
|
||||
// for filter logging
|
||||
attribute nsIOutputStream logStream;
|
||||
readonly attribute string logURL;
|
||||
void clearLog();
|
||||
void ensureLogFile();
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
var gFilterList;
|
||||
var gLogFilters;
|
||||
var gLogView;
|
||||
|
||||
function onLoad()
|
||||
{
|
||||
|
@ -8,15 +9,16 @@ function onLoad()
|
|||
gLogFilters = document.getElementById("logFilters");
|
||||
gLogFilters.checked = gFilterList.loggingEnabled;
|
||||
|
||||
var logView = document.getElementById("logView");
|
||||
gLogView = document.getElementById("logView");
|
||||
|
||||
// for security, disable JS
|
||||
logView.docShell.allowJavascript = false;
|
||||
gLogView.docShell.allowJavascript = false;
|
||||
|
||||
// won't work yet
|
||||
// Security Error: Content at chrome://messenger/content/filterLog.xul
|
||||
// may not load or link to file:///C|/Documents%20and%20Settings/Administrator/Application%20Data/Mozilla/Profiles/sspitzer/js48p4bs.slt/ImapMail/nsmail-1/filterlog.html.
|
||||
logView.setAttribute("src", gFilterList.logURL);
|
||||
// if log doesn't exist, this will create an empty file on disk
|
||||
// otherwise, the user will get an error that the file doesn't exist
|
||||
gFilterList.ensureLogFile();
|
||||
|
||||
gLogView.setAttribute("src", gFilterList.logURL);
|
||||
}
|
||||
|
||||
function toggleLogFilters()
|
||||
|
@ -26,10 +28,9 @@ function toggleLogFilters()
|
|||
|
||||
function clearLog()
|
||||
{
|
||||
// var logURL = gFilterList.logURL;
|
||||
// gFilterList.logStream = null;
|
||||
// get file for logURL;
|
||||
// truncate file
|
||||
// reload blank log file in viewer
|
||||
gFilterList.clearLog();
|
||||
|
||||
// reload the newly truncated file
|
||||
gLogView.setAttribute("src", gFilterList.logURL);
|
||||
}
|
||||
|
||||
|
|
|
@ -120,6 +120,50 @@ NS_IMETHODIMP nsMsgFilterList::SaveToFile(nsIOFileStream *stream)
|
|||
return SaveTextFilters(stream);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgFilterList::EnsureLogFile()
|
||||
{
|
||||
nsCOMPtr <nsIFileSpec> file;
|
||||
nsresult rv = GetLogFileSpec(getter_AddRefs(file));
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
PRBool exists;
|
||||
rv = file->Exists(&exists);
|
||||
if (NS_SUCCEEDED(rv) && !exists) {
|
||||
rv = file->Touch();
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsMsgFilterList::TruncateLog()
|
||||
{
|
||||
// this will flush and close the steam
|
||||
nsresult rv = SetLogStream(nsnull);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
nsCOMPtr <nsIFileSpec> file;
|
||||
rv = GetLogFileSpec(getter_AddRefs(file));
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
rv = file->Truncate(0);
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgFilterList::ClearLog()
|
||||
{
|
||||
PRBool loggingEnabled = m_loggingEnabled;
|
||||
|
||||
// disable logging while clearing
|
||||
m_loggingEnabled = PR_FALSE;
|
||||
|
||||
nsresult rv = TruncateLog();
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to truncate filter log");
|
||||
|
||||
m_loggingEnabled = loggingEnabled;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsMsgFilterList::GetLogFileSpec(nsIFileSpec **aFileSpec)
|
||||
{
|
||||
|
@ -154,12 +198,10 @@ nsMsgFilterList::GetLogURL(char **aLogURL)
|
|||
NS_IMETHODIMP
|
||||
nsMsgFilterList::SetLogStream(nsIOutputStream *aLogStream)
|
||||
{
|
||||
// if there is a log stream already, flush it to disk and close it
|
||||
// if there is a log stream already, close it
|
||||
if (m_logStream) {
|
||||
nsresult rv = m_logStream->Flush();
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
|
||||
rv = m_logStream->Close();
|
||||
// will flush
|
||||
nsresult rv = m_logStream->Close();
|
||||
NS_ENSURE_SUCCESS(rv,rv);
|
||||
}
|
||||
|
||||
|
|
|
@ -99,7 +99,9 @@ protected:
|
|||
nsCOMPtr<nsISupportsArray> m_filters;
|
||||
nsCString m_arbitraryHeaders;
|
||||
nsCOMPtr<nsIFileSpec> m_defaultFile;
|
||||
|
||||
private:
|
||||
nsresult TruncateLog();
|
||||
nsresult GetLogFileSpec(nsIFileSpec **aFileSpec);
|
||||
nsCOMPtr<nsIOutputStream> m_logStream;
|
||||
};
|
||||
|
|
Загрузка…
Ссылка в новой задаче