forked from vnotex/vnote
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvfilesessioninfo.cpp
More file actions
78 lines (66 loc) · 2.67 KB
/
vfilesessioninfo.cpp
File metadata and controls
78 lines (66 loc) · 2.67 KB
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
#include "vfilesessioninfo.h"
#include <QSettings>
#include "vedittabinfo.h"
#include "vtableofcontent.h"
#include "vedittab.h"
VFileSessionInfo::VFileSessionInfo()
: m_mode(OpenFileMode::Read),
m_active(false),
m_headerIndex(-1),
m_cursorBlockNumber(-1),
m_cursorPositionInBlock(-1)
{
}
VFileSessionInfo::VFileSessionInfo(const QString &p_file,
OpenFileMode p_mode)
: m_file(p_file),
m_mode(p_mode),
m_active(false),
m_headerIndex(-1),
m_cursorBlockNumber(-1),
m_cursorPositionInBlock(-1)
{
}
// Fetch VFileSessionInfo from @p_tabInfo.
VFileSessionInfo VFileSessionInfo::fromEditTabInfo(const VEditTabInfo *p_tabInfo)
{
Q_ASSERT(p_tabInfo);
VEditTab *tab = p_tabInfo->m_editTab;
VFileSessionInfo info(tab->getFile()->fetchPath(),
tab->isEditMode() ? OpenFileMode::Edit : OpenFileMode::Read);
info.m_headerIndex = p_tabInfo->m_headerIndex;
info.m_cursorBlockNumber = p_tabInfo->m_cursorBlockNumber;
info.m_cursorPositionInBlock = p_tabInfo->m_cursorPositionInBlock;
return info;
}
void VFileSessionInfo::toEditTabInfo(VEditTabInfo *p_tabInfo) const
{
p_tabInfo->m_headerIndex = m_headerIndex;
p_tabInfo->m_cursorBlockNumber = m_cursorBlockNumber;
p_tabInfo->m_cursorPositionInBlock = m_cursorPositionInBlock;
}
VFileSessionInfo VFileSessionInfo::fromSettings(const QSettings *p_settings)
{
VFileSessionInfo info;
info.m_file = p_settings->value(FileSessionConfig::c_file).toString();
int tmpMode = p_settings->value(FileSessionConfig::c_mode).toInt();
if (tmpMode >= (int)OpenFileMode::Read && tmpMode < (int)OpenFileMode::Invalid) {
info.m_mode = (OpenFileMode)tmpMode;
} else {
info.m_mode = OpenFileMode::Read;
}
info.m_active = p_settings->value(FileSessionConfig::c_active).toBool();
info.m_headerIndex = p_settings->value(FileSessionConfig::c_headerIndex).toInt();
info.m_cursorBlockNumber = p_settings->value(FileSessionConfig::c_cursorBlockNumber).toInt();
info.m_cursorPositionInBlock = p_settings->value(FileSessionConfig::c_cursorPositionInBlock).toInt();
return info;
}
void VFileSessionInfo::toSettings(QSettings *p_settings) const
{
p_settings->setValue(FileSessionConfig::c_file, m_file);
p_settings->setValue(FileSessionConfig::c_mode, (int)m_mode);
p_settings->setValue(FileSessionConfig::c_active, m_active);
p_settings->setValue(FileSessionConfig::c_headerIndex, m_headerIndex);
p_settings->setValue(FileSessionConfig::c_cursorBlockNumber, m_cursorBlockNumber);
p_settings->setValue(FileSessionConfig::c_cursorPositionInBlock, m_cursorPositionInBlock);
}