/// <summary> /// Display the directory for the specified CategoryFolder /// </summary> public override bool ViewFromFolder(FolderBase folder, Address address, FolderOptions flags) { CategoryFolder category = folder as CategoryFolder; if (category != null) { if (flags.HasFlag(FolderOptions.ClearFilter)) { _currentFilterString = null; } _currentCategory = category; _items = ItemsForView(); SortItems(); } return(true); }
/// <summary> /// Returns true if 1 or more copies of the value were written /// </summary> /// <param name="filename"></param> /// <param name="value"></param> /// <returns></returns> public bool TryDiskWrite(string filename, string value) { if (value == null) { return(TryDelete(filename)); } else { try { filesystem.EnterWriteLock(); int successfulWrites = 0; foreach (var dest in candidateFolders.Except(badWriteLocations)) { if (options.HasFlag(FolderOptions.CreateIfMissing)) { try { if (!Directory.Exists(dest)) { Directory.CreateDirectory(dest); } } catch (Exception e) { AddBadWriteLocation(dest, new Issue(this.issueSource, "Failed to create directory " + dest, e.ToString(), IssueSeverity.Warning)); } } else if (!Directory.Exists(dest)) { AddBadWriteLocation(dest, null); } if (Directory.Exists(dest)) { var path = Path.Combine(dest, filename); try { File.WriteAllText(path, value, Encoding.UTF8); // TODO: Original version made license files world readable. // Make world readable // var sec = File.GetAccessControl(path); // SecurityIdentifier everyone = new SecurityIdentifier(WellKnownSidType.WorldSid, null); // sec.AddAccessRule( // new FileSystemAccessRule(everyone, // FileSystemRights.Read, InheritanceFlags.None, PropagationFlags.None, AccessControlType.Allow)); // File.SetAccessControl(path, sec); successfulWrites++; } catch (Exception e) { AddBadWriteLocation(dest, new Issue(this.issueSource, "Failed to write " + dataKind + " to location " + path, e.ToString(), IssueSeverity.Warning)); } } } if (successfulWrites > 0) { return(true); } } finally { filesystem.ExitWriteLock(); } sink.AcceptIssue(new Issue(this.issueSource, "Unable to cache " + dataKind + " to disk in any location.", null, IssueSeverity.Error)); return(false); } }
/// <summary> /// Locate and display the next folder, after the selected one, that contains /// unread messages. Then select the first message in that folder that is unread. /// /// Options are a combination of: /// FolderOption.Priority - only display the next unread priority message /// FolderOption.Reset - when displaying the next unread in a folder, start scan /// from the top of the list rather than from the current /// selection in that folder. /// /// </summary> /// <param name="options">Flags that control the next unread behaviour</param> public void NextUnread(FolderOptions options) { if (frmList.Nodes.Count == 0) { return; } TreeNode currentNode = frmList.SelectedNode ?? frmList.Nodes[0]; TreeNode startingNode = currentNode; bool resetLoop = false; _isRBut = false; bool acceptSmartFolders = currentNode.Tag is SmartFolder; bool priorityOnly = options.HasFlag(FolderOptions.Priority); do { FolderBase folder = (FolderBase)currentNode.Tag; if (folder.ViewForFolder == AppView.AppViewForum) { TopicFolder topicFolder = (TopicFolder)folder; if (priorityOnly ? topicFolder.UnreadPriority > 0 : topicFolder.Unread > 0) { frmList.BeginUpdate(); if (startingNode.Tag is TopicFolder) { TreeNode parentNode = startingNode.Parent; if (parentNode != null && parentNode.Parent != null) { parentNode.Collapse(); } } currentNode.ExpandAll(); frmList.EndUpdate(); } } else if (folder is MailGroup && !priorityOnly) { MailGroup group = (MailGroup)folder; if (group.Unread > 0) { currentNode.Expand(); } } else if (folder is ForumGroup) { ForumGroup group = (ForumGroup)folder; if (group.Unread > 0) { currentNode.Expand(); } } else { if ((acceptSmartFolders && folder is SmartFolder) || (priorityOnly ? folder.UnreadPriority > 0 : folder.Unread > 0)) { if (SelectViewForFolder(currentNode, null, options)) { MoveSelection(currentNode); return; } } } if (currentNode.Nodes.Count > 0) { currentNode = currentNode.Nodes[0]; } else if (currentNode.NextNode != null) { currentNode = currentNode.NextNode; } else if (currentNode.Parent != null) { currentNode = currentNode.Parent; currentNode = currentNode.NextNode; if (currentNode == null) { if (resetLoop) { break; } currentNode = frmList.Nodes[0]; resetLoop = true; } } else { break; } acceptSmartFolders = false; options |= FolderOptions.Reset; } while (true); }
/// <summary> /// Display the specified topic folder in the thread list. /// </summary> /// <param name="folder">The folder whose topic is to be displayed</param> /// <param name="address"></param> /// <param name="options">Folder display flags</param> public override bool ViewFromFolder(FolderBase folder, Address address, FolderOptions options) { if (folder.ViewForFolder == AppView.AppViewTopic) { if ((_currentFolder != folder) || options.HasFlag(FolderOptions.ClearFilter)) { _currentFolder = folder; _currentFilterString = null; _isFiltering = false; _isTopicFolder = IsTopicFolder(); tsvMessages.SelectedIndices.Clear(); ShowMessage(null); if (FoldersTree.MainForm.RunEvent(EventID.FolderSelected, _isTopicFolder ? ((TopicFolder) folder).Folder : null)) { if (_isTopicFolder) { // Attempt to make topic switches cleaner by removing the old messages from display // when switching to a new topic will involve a delay caused by loading the messages // from the DB, sorting, etc. if (!((TopicFolder)_currentFolder).Folder.HasMessages && _messages != null && _messages.Count > 0) { _messages = new List<CIXMessage>(); InitialiseList(); RedrawAllItems(); } } SortConversations(); } UpdateFromFlags(); } // Load this topic from the server only if we're empty. if (_messages != null && _messages.Count == 0) { if (address != null && address.Scheme == "cix") { Int32.TryParse(address.Data, out _lastIndex); } folder.Refresh(); return false; } if (options.HasFlag(FolderOptions.ClearFilter)) { options &= ~FolderOptions.ClearFilter; _currentFilterString = null; _isFiltering = false; } if (address != null && address.Scheme == "cix") { int selectedID; Int32.TryParse(address.Data, out selectedID); if (!GoToMessage(selectedID)) { SetInitialSelection(); } if (address.Unread) { SelectedMessage.MarkUnread(); } } else if (options == 0) { SetInitialSelection(); } else { int row = SelectedRow; if (row < 0 || options.HasFlag(FolderOptions.Reset)) { row = -1; } else { CIXMessage selectedMessage = SelectedMessage; if (selectedMessage != null && selectedMessage.Unread) { selectedMessage.MarkRead(); } } if (!FirstUnreadAfterRow(row, options)) { return false; } } ActiveControl = tsvMessages; } return true; }
/// <summary> /// Display the first unread message after the specified row. /// </summary> /// <param name="row">Row after which we begin searching</param> /// <param name="options">FolderOptions flags that control the search</param> /// <returns>True if we found an unread message</returns> private bool FirstUnreadAfterRow(int row, FolderOptions options) { while (++row < _messages.Count) { CIXMessage message = _messages[row]; if (IsCollapsed(message) && message.UnreadChildren > 0) { ExpandThread(message); } if (options.HasFlag(FolderOptions.Priority)) { if (message.Priority && message.Unread) { SelectedRow = row; break; } } else if (options.HasFlag(FolderOptions.NextUnread) && message.Unread) { if (options.HasFlag(FolderOptions.Root)) { while (message.CommentID > 0 && row > 0) { message = _messages[--row]; } } SelectedRow = row; break; } } return (row != _messages.Count); }
/// <summary> /// Display the directory for the specified CategoryFolder /// </summary> public override bool ViewFromFolder(FolderBase folder, Address address, FolderOptions options) { if (folder != _currentFolder) { _currentFolder = folder; SortConversations(); } // If an address is specified then it refers to a conversation ID that // needs to be selected. If it is not found, the first message is selected // instead. if (address != null && address.Scheme == "cixmailbox") { int selectedID; Int32.TryParse(address.Data, out selectedID); int selectedIndex; for (selectedIndex = 0; selectedIndex < _conversations.Count; ++selectedIndex) { InboxConversation conversation = _conversations[selectedIndex]; if (conversation.RemoteID == selectedID) break; } if (selectedIndex == _conversations.Count) { selectedIndex = 0; } SelectedRow = selectedIndex; if (address.Unread) { SelectedMessage.MarkUnread(); } return true; } // If options are specified then search for the next unread // in the list otherwise set the initial selection to something // useful. if (options == 0 && SelectedRow == -1) { SetInitialSelection(); } else { int row = inboxConversations.SearchRow; if (row < 0 || options.HasFlag(FolderOptions.Reset)) { row = 0; } else if (_conversations.Count > 0) { InboxConversation conversation = _conversations[row]; if (conversation.UnreadCount > 0) { conversation.MarkRead(); } } if (!FirstUnreadAfterRow(row, options)) { inboxConversations.SearchRow = 0; return false; } } FoldersTree.SetTopicName(_currentFolder.FullName); ActiveControl = inboxConversations; inboxConversations.Focus(); return true; }
/// <summary> /// Display the directory for the specified CategoryFolder /// </summary> public override bool ViewFromFolder(FolderBase folder, Address address, FolderOptions flags) { CategoryFolder category = folder as CategoryFolder; if (category != null) { if (flags.HasFlag(FolderOptions.ClearFilter)) { _currentFilterString = null; } _currentCategory = category; _items = ItemsForView(); SortItems(); } return true; }
/// <summary> /// Display the directory for the specified CategoryFolder /// </summary> public override bool ViewFromFolder(FolderBase folder, Address address, FolderOptions options) { if (folder != _currentFolder) { _currentFolder = folder; SortConversations(); } // If an address is specified then it refers to a conversation ID that // needs to be selected. If it is not found, the first message is selected // instead. if (address != null && address.Scheme == "cixmailbox") { int selectedID; Int32.TryParse(address.Data, out selectedID); int selectedIndex; for (selectedIndex = 0; selectedIndex < _conversations.Count; ++selectedIndex) { InboxConversation conversation = _conversations[selectedIndex]; if (conversation.RemoteID == selectedID) { break; } } if (selectedIndex == _conversations.Count) { selectedIndex = 0; } SelectedRow = selectedIndex; if (address.Unread) { SelectedMessage.MarkUnread(); } return(true); } // If options are specified then search for the next unread // in the list otherwise set the initial selection to something // useful. if (options == 0 && SelectedRow == -1) { SetInitialSelection(); } else { int row = inboxConversations.SearchRow; if (row < 0 || options.HasFlag(FolderOptions.Reset)) { row = 0; } else if (_conversations.Count > 0) { InboxConversation conversation = _conversations[row]; if (conversation.UnreadCount > 0) { conversation.MarkRead(); } } if (!FirstUnreadAfterRow(row, options)) { inboxConversations.SearchRow = 0; return(false); } } FoldersTree.SetTopicName(_currentFolder.FullName); ActiveControl = inboxConversations; inboxConversations.Focus(); return(true); }