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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
|
/*
Copyright (C) 2012-24 Miranda NG team (https://miranda-ng.org)
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 version 2
of the License.
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, see <http://www.gnu.org/licenses/>.
*/
#include "stdafx.h"
static bool g_bDontShow, g_bStartup;
/////////////////////////////////////////////////////////////////////////////////////////
class CLoadSessionDlg : public CDlgBase
{
CSession *pSession = nullptr;
CTimer timerShow, timerLoad;
CCtrlCombo m_list;
CCtrlButton btnDelete;
public:
CLoadSessionDlg() :
CDlgBase(g_plugin, IDD_WLCMDIALOG),
m_list(this, IDC_LIST),
btnDelete(this, IDC_SESSDEL),
timerLoad(this, TIMERID_LOAD),
timerShow(this, TIMERID_SHOW)
{
btnDelete.OnClick = Callback(this, &CLoadSessionDlg::onClick_Delete);
m_list.OnSelChanged = Callback(this, &CLoadSessionDlg::onSelChange_List);
timerLoad.OnEvent = Callback(this, &CLoadSessionDlg::onTimer_Load);
timerShow.OnEvent = Callback(this, &CLoadSessionDlg::onTimer_Show);
}
bool OnInitDialog() override
{
g_hDlg = m_hwnd;
LoadSessionToCombobox(m_list, false);
LoadSessionToCombobox(m_list, true);
m_list.SetCurSel(0);
pSession = (CSession *)m_list.GetItemData(0);
if (g_bDontShow == TRUE)
timerLoad.Start(g_plugin.iStartupDelay);
else {
LoadPosition(m_hwnd, "LoadDlg");
if (g_bStartup)
timerShow.Start(g_plugin.iStartupDelay);
else
Show();
}
return true;
}
bool OnApply() override
{
if (!LoadSession(pSession))
return true;
return false;
}
void OnDestroy() override
{
SavePosition(m_hwnd, "LoadDlg");
g_hDlg = nullptr;
}
void onTimer_Load(CTimer *pTimer)
{
pTimer->Stop();
LoadSession(pSession);
g_bDontShow = g_bStartup = false;
Close();
}
void onTimer_Show(CTimer *pTimer)
{
pTimer->Stop();
Show();
g_bStartup = FALSE;
}
void onSelChange_List(CCtrlCombo *)
{
int index = m_list.GetCurSel();
if (index != CB_ERR)
pSession = (CSession*)m_list.GetItemData(index);
}
void onClick_Delete(CCtrlButton *)
{
if (pSession == nullptr) {
if (session_list_recovered[0]) {
for (int i = 0; session_list_recovered[i]; i++)
g_plugin.setByte(session_list_recovered[i], "wasInLastSession", 0);
memset(session_list_recovered, 0, sizeof(session_list_recovered));
}
g_bIncompletedSave = 0;
}
else pSession->remove();
m_list.ResetContent();
LoadSessionToCombobox(m_list, false);
LoadSessionToCombobox(m_list, true);
m_list.SetCurSel(0);
btnDelete.Enable(m_list.GetCount() != 0);
}
};
INT_PTR OpenSessionsManagerWindow(WPARAM, LPARAM)
{
if (g_hDlg) {
ShowWindow(g_hDlg, SW_SHOW);
return 0;
}
if (g_bIncompletedSave || g_arDateSessions.getCount() || g_arUserSessions.getCount()) {
(new CLoadSessionDlg())->Create();
return 0;
}
if (g_plugin.bOtherWarnings)
MessageBox(nullptr, TranslateT("No sessions to open"), TranslateT("Sessions Manager"), MB_OK | MB_ICONWARNING);
return 1;
}
void CALLBACK LaunchSessions()
{
int startup = g_plugin.getByte("StartupMode", 3);
if (startup == 1 || (startup == 3 && g_bLastSessionPresent)) {
g_bStartup = true;
(new CLoadSessionDlg())->Create();
}
else if (startup == 2 && g_bLastSessionPresent) {
g_bDontShow = true;
(new CLoadSessionDlg())->Create();
}
}
/////////////////////////////////////////////////////////////////////////////////////////
INT_PTR LoadLastSession(WPARAM, LPARAM)
{
int cnt = g_arDateSessions.getCount();
if (g_bLastSessionPresent && cnt)
return LoadSession(&g_arDateSessions[cnt-1]);
if (g_plugin.bOtherWarnings)
MessageBox(nullptr, TranslateT("Last Sessions is empty"), TranslateT("Sessions Manager"), MB_OK);
return 0;
}
/////////////////////////////////////////////////////////////////////////////////////////
// Load session dialog
int LoadSession(CSession *pSession)
{
int dup = 0;
int hidden[255] = { '0' };
MCONTACT session_list_t[255] = {};
if (session_list_recovered[0] && pSession == nullptr)
memcpy(session_list_t, session_list_recovered, sizeof(session_list_t));
else {
int i = 0;
for (auto &cc : pSession->contacts)
session_list_t[i++] = cc;
}
int i = 0, j = 0;
// TODO: change to "switch"
while (session_list_t[i] != 0) {
if (CheckForDuplicate(session_list, session_list_t[i]) == -1)
Clist_ContactDoubleClicked(session_list_t[i]);
else if (g_plugin.bWarnOnHidden) {
if (!CheckContactVisibility(session_list_t[i])) {
hidden[j] = i + 1;
j++;
}
dup++;
}
i++;
}
if (i == 0) {
if (g_plugin.bOtherWarnings)
MessageBox(nullptr, TranslateT("No contacts to open"), TranslateT("Sessions Manager"), MB_OK | MB_ICONWARNING);
return 1;
}
if (dup == i) {
if (!hidden[i]) {
if (g_plugin.bOtherWarnings)
MessageBox(nullptr, TranslateT("This Session already opened"), TranslateT("Sessions Manager"), MB_OK | MB_ICONWARNING);
return 1;
}
if (!g_plugin.bWarnOnHidden && g_plugin.bOtherWarnings) {
MessageBox(nullptr, TranslateT("This Session already opened"), TranslateT("Sessions Manager"), MB_OK | MB_ICONWARNING);
return 1;
}
if (g_plugin.bWarnOnHidden) {
if (IDYES == MessageBox(nullptr, TranslateT("This Session already opened (but probably hidden).\nDo you want to show hidden contacts?"), TranslateT("Sessions Manager"), MB_YESNO | MB_ICONQUESTION))
for (j = 0; hidden[j] != 0; j++)
Clist_ContactDoubleClicked(session_list_t[hidden[j] - 1]);
}
}
return 0;
}
|