Skip to content

Commit

Permalink
minor refactoring for setting current folder in ui
Browse files Browse the repository at this point in the history
  • Loading branch information
d99kris committed Aug 10, 2024
1 parent 2ae9560 commit 208faed
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/imapmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ bool ImapManager::ProcessIdle()
bool rv = true;
static bool firstIdle = true;
std::set<uint32_t> uids;
Imap::FolderInfo lastFolderInfo = m_Imap.GetFolderInfo(m_CurrentFolder);
Imap::FolderInfo lastFolderInfo = m_Imap.GetFolderInfo(idleFolder);
if (!lastFolderInfo.IsValid())
{
LOG_WARNING("idle folder info failed");
Expand Down
2 changes: 1 addition & 1 deletion src/nmail.1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man.
.TH NMAIL "1" "August 2024" "nmail 5.1.12" "User Commands"
.TH NMAIL "1" "August 2024" "nmail 5.1.13" "User Commands"
.SH NAME
nmail \- ncurses mail
.SH SYNOPSIS
Expand Down
28 changes: 18 additions & 10 deletions src/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Ui::Ui(const std::string& p_Inbox, const std::string& p_Address, const std::stri
, m_PrefetchLevel(p_PrefetchLevel)
, m_PrefetchAllHeaders(p_PrefetchAllHeaders)
{
m_CurrentFolder = p_Inbox;
SetCurrentFolder(p_Inbox);
Init();
InitWindows();
}
Expand Down Expand Up @@ -2153,8 +2153,7 @@ void Ui::ViewFolderListKeyHandler(int p_Key)
{
if (m_State == StateGotoFolder)
{
m_CurrentFolder = m_FolderListCurrentFolder;
m_ImapManager->SetCurrentFolder(m_CurrentFolder);
SetCurrentFolder(m_FolderListCurrentFolder);
SetState(StateViewMessageList);
UpdateIndexFromUid();
}
Expand Down Expand Up @@ -2383,7 +2382,7 @@ void Ui::ViewMessageListKeyHandler(int p_Key)
if (m_MessageListSearch)
{
m_MessageListSearch = false;
m_CurrentFolder = m_PreviousFolder;
SetCurrentFolder(m_PreviousFolder);
m_PreviousFolder = "";
UpdateIndexFromUid();
}
Expand All @@ -2407,7 +2406,7 @@ void Ui::ViewMessageListKeyHandler(int p_Key)

if (m_CurrentFolder != m_Inbox)
{
m_CurrentFolder = m_Inbox;
SetCurrentFolder(m_Inbox);
}
else
{
Expand Down Expand Up @@ -2680,7 +2679,7 @@ void Ui::ViewMessageListKeyHandler(int p_Key)
if (m_MessageListSearch)
{
m_MessageListSearch = false;
m_CurrentFolder = m_CurrentFolderUid.first;
SetCurrentFolder(m_CurrentFolderUid.first);
const uint32_t uid = m_CurrentFolderUid.second;

if (!m_HasRequestedUids[m_CurrentFolder])
Expand Down Expand Up @@ -2834,7 +2833,7 @@ void Ui::ViewMessageKeyHandler(int p_Key)
m_PreviousFolder = "";
}

m_CurrentFolder = m_Inbox;
SetCurrentFolder(m_Inbox);
SetState(StateViewMessageList);
}
else if ((p_Key == m_KeyMove) || (p_Key == m_KeyAutoMove))
Expand Down Expand Up @@ -3343,7 +3342,7 @@ void Ui::ViewPartListKeyHandler(int p_Key)
m_PreviousFolder = "";
}

m_CurrentFolder = m_Inbox;
SetCurrentFolder(m_Inbox);
SetState(StateViewMessageList);
}
else if (HandleListKey(p_Key, m_PartListCurrentIndex))
Expand Down Expand Up @@ -5767,7 +5766,7 @@ void Ui::SearchMessage(const std::string& p_Query /*= std::string()*/)
if (m_CurrentFolder != "")
{
m_PreviousFolder = m_CurrentFolder;
m_CurrentFolder = "";
SetCurrentFolder("");
}

m_MessageListCurrentIndex[m_CurrentFolder] = 0;
Expand Down Expand Up @@ -5798,7 +5797,7 @@ void Ui::SearchMessage(const std::string& p_Query /*= std::string()*/)
ClearSelection();
if (m_PreviousFolder != "")
{
m_CurrentFolder = m_PreviousFolder;
SetCurrentFolder(m_PreviousFolder);
m_PreviousFolder = "";
}

Expand Down Expand Up @@ -7181,3 +7180,12 @@ void Ui::AutoMoveSelectFolder()
m_FolderListCurrentFolder = !foundFolder.empty() ? foundFolder : folder;
m_FolderListCurrentIndex = INT_MAX;
}

void Ui::SetCurrentFolder(const std::string& p_Folder)
{
m_CurrentFolder = p_Folder;
if (m_ImapManager && !m_CurrentFolder.empty())
{
m_ImapManager->SetCurrentFolder(m_CurrentFolder);
}
}
1 change: 1 addition & 0 deletions src/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ class Ui

void OnWakeUp();
void AutoMoveSelectFolder();
void SetCurrentFolder(const std::string& p_Folder);

private:
std::shared_ptr<ImapManager> m_ImapManager;
Expand Down
2 changes: 1 addition & 1 deletion src/version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "version.h"

#define NMAIL_VERSION "5.1.12"
#define NMAIL_VERSION "5.1.13"

std::string Version::GetBuildOs()
{
Expand Down

0 comments on commit 208faed

Please sign in to comment.