-
Notifications
You must be signed in to change notification settings - Fork 0
/
AxMenuMailView.cpp
409 lines (346 loc) · 15.6 KB
/
AxMenuMailView.cpp
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
//=============================================================================
/*
* See the file README in the main directory for a description of
* this software, copyright information, and how to reach the author.
*
* Author: alex
* Date: 15.11.2003
*
* Last modfied:
* $Author: alex $
* $Date: 2014-10-26 15:41:24 +0100 (So, 26 Okt 2014) $
*/
//=============================================================================
//=============================================================================
// includes
//=============================================================================
//----- multiple defs of swap() workaround ------------------------------------
#include "AxPluginGlobals.h"
//----- qt --------------------------------------------------------------------
//----- CORBA -----------------------------------------------------------------
//----- ICE -------------------------------------------------------------------
//----- C++ -------------------------------------------------------------------
#include <string>
//----- C ---------------------------------------------------------------------
//----- vdr -------------------------------------------------------------------
#include <vdr/tools.h>
#include <vdr/font.h>
#include <vdr/i18n.h>
#include <vdr/menuitems.h>
#include <vdr/remote.h>
#include <vdr/status.h>
//----- AxLib -----------------------------------------------------------------
#include <Ax/Tools/Trace.h>
// #include <Ax/Tools/TraceOn.h>
#include <Ax/Tools/Globals.h>
#include <Ax/Tools/String.h>
#include <Ax/Mail/Mail.h>
#include <Ax/Mail/MailFolder.h>
#include <Ax/Mail/MailPart.h>
#include <Ax/Mail/MailBox.h>
#include <Ax/Mail/Tools.h>
#include <Ax/Vdr/Tools.h>
//----- local plugin ----------------------------------------------------------
#include "AxPluginMailBox.h"
#include "AxPluginSetup.h"
#include "AxMenuMailView.h"
#include "AxMenuMailListView.h"
#include "AxVdrTools.h"
#include "AxMailWrapper.h"
//=============================================================================
// using namespaces
//=============================================================================
using namespace std;
using namespace Ax;
//=============================================================================
// class AxMenuMailView
//=============================================================================
//-----------------------------------------------------------------------------
// AxMenuMailView::AxMenuMailView()
//-----------------------------------------------------------------------------
AxMenuMailView::AxMenuMailView( AxPluginMailBox *thePlugin
, Ax::Mail::MailFolder *theFolder
, Ax::Mail::Mail *theMail
, AxMenuMailViewBase *theMailViewParent
)
: PARENT( thePlugin
, theFolder
, theMail
, theMailViewParent
, tr("Mail-View")
, ""
, 9
)
, myMailWrapper (0)
, myBodyText ("")
, myWrapMode (AxMailWrapper::WrapMode(thePlugin->getSetup().Settings.MV_ViewMode))
, myUseFixedFont(false)
, myShowAllParts(false)
{
#if VDRVERSNUM >= 10734
SetMenuCategory(mcText);
#endif
//----- create actions ------------------------------------------------------
addAction(new Vdr::ActionActivateButtonPage<PARENT>
( this
, A_SHOW_PAGE_JUMP
, tr("Back..." )
, PAGE_JUMP
, "ShowPageJump"
, tr("Use color keys for movement")
));
addAction(new Vdr::ActionActivateButtonPage<PARENT>
( this
, A_SHOW_PAGE_MARK
, tr("Flags...")
, PAGE_MARK
, "ShowPageMark"
, tr("Use color keys to toggle flags")
));
addAction(new Vdr::ActionCallback<PARENT>( this
, A_SWITCH_WRAP
, tr("Action$Wrap mode")
, "SwitchWrap"
, tr("Switch word-wrapping mode")
));
addAction(new Vdr::ActionCallback<PARENT>( this
, A_SHOW_ALL_PARTS
, tr("Action$Toggle parts")
, "ToggleAllParts"
, tr("Show all parts")
));
bool fConvHtml = thePlugin->getSetup().Settings.MailConvCmd.length() > 0
&& thePlugin->getSetup().Settings.MailSrcFile.length() > 0
&& thePlugin->getSetup().Settings.MailDstFile.length() > 0
;
setActionSupported(A_SHOW_ALL_PARTS, fConvHtml);
//----- query width and font for text area ----------------------------------
const cFont *aFont = 0;
int aWidth = 0;
if (myWrapMode > AxMailWrapper::WM_NONE)
{
aFont = DisplayMenu()->GetTextAreaFont(myUseFixedFont);
aWidth = DisplayMenu()->GetTextAreaWidth();
if (aFont == 0 || aWidth == 0)
{
wsinfo(("unable to query osd-properties for the current skin '%s'"
, Skins.Current()->Name()
));
wsinfo(("word-wrapping-mode %s is only supported for the two standard skins and Elchi"
, AxVdrTools::WrapModeStrings[myWrapMode]
));
myWrapMode = AxMailWrapper::WM_NONE;
wsinfo(("using wrapping-mode %s for now"
, AxVdrTools::WrapModeStrings[myWrapMode]
));
setActionSupported(A_SWITCH_WRAP, false);
} // if
} // if
myMailWrapper = new AxMailWrapper(getPlugin(), aFont, aWidth);
//----- show the mail -------------------------------------------------------
updateWithCurrentMail();
//----- assign actions to keys ----------------------------------------------
setKeyAction(k1 , A_TOGGLE_SEEN );
setKeyAction(k2 , A_TOGGLE_FLAGGED );
setKeyAction(k3 , A_TOGGLE_DELETED );
setKeyAction(k5 , A_SWITCH_WRAP );
// jump to previous mail
setKeyAction(kFastRew , A_JUMP_2_PREV );
setKeyAction(kFastRew| k_Repeat, A_JUMP_2_PREV );
setKeyAction(k4 , A_JUMP_2_PREV );
setKeyAction(k4 | k_Repeat, A_JUMP_2_PREV );
// jump to next mail
setKeyAction(kFastFwd , A_JUMP_2_NEXT );
setKeyAction(kFastFwd| k_Repeat, A_JUMP_2_NEXT );
setKeyAction(k6 , A_JUMP_2_NEXT );
setKeyAction(k6 | k_Repeat, A_JUMP_2_NEXT );
// jump to previous unread mail
setKeyAction(k7 , A_JUMP_2_PREV_NEW);
setKeyAction(k7 | k_Repeat, A_JUMP_2_PREV_NEW);
// toggle display of all parts
setKeyAction(k8 , A_SHOW_ALL_PARTS );
// jump to next unread mail
setKeyAction(k9 , A_JUMP_2_NEXT_NEW);
setKeyAction(k9 | k_Repeat, A_JUMP_2_NEXT_NEW);
setButtonActions( PAGE_JUMP
// red , green , yellow , blue
, A_NONE , A_JUMP_2_PREV_NEW, A_JUMP_2_NEXT_NEW, A_SHOW_PAGE_MARK
, A_NONE , A_JUMP_2_PREV_NEW, A_JUMP_2_NEXT_NEW, A_NONE
);
setButtonActions( PAGE_MARK
// red , green , yellow , blue
, A_TOGGLE_SEEN , A_TOGGLE_FLAGGED , A_TOGGLE_DELETED , A_SHOW_PAGE_JUMP
);
setActionSupported(A_TOGGLE_FLAGGED, getFolder()->supportsFlag(Mail::MF_FLAGGED));
setActionSupported(A_TOGGLE_SEEN , getFolder()->supportsFlag(Mail::MF_SEEN ));
setActionSupported(A_TOGGLE_DELETED, getFolder()->supportsFlag(Mail::MF_DELETED));
if (getButtonPage() != PAGE_JUMP) selectButtonPage(PAGE_JUMP);
// if we can't toggle any flags -> disable switching pages
if ( !isActionSupported(A_TOGGLE_FLAGGED)
&& !isActionSupported(A_TOGGLE_SEEN )
&& !isActionSupported(A_TOGGLE_DELETED)
)
{
// setting the deleted-flag makes only sense if
// - we have an IMAP-account (which stores the deleted flag)
// - ExpungeOnClose is enabled
setActionSupported(A_SHOW_PAGE_MARK, false);
setActionSupported(A_SHOW_PAGE_JUMP, false);
} // if
} // AxMenuMailView::AxMenuMailView()
//-----------------------------------------------------------------------------
// AxMenuMailView::~AxMenuMailView()
//-----------------------------------------------------------------------------
AxMenuMailView::~AxMenuMailView()
{
delete myMailWrapper;
} // AxMenuMailView::~AxMenuMailView()
//-------------------------------------------------------------------------
// AxMenuMailView::processAction()
//-------------------------------------------------------------------------
eOSState AxMenuMailView::processAction(const Ax::Vdr::Action &theAction, eOSState theState)
{
switch (theAction.getID())
{
case A_SWITCH_WRAP:
{
myWrapMode = AxMailWrapper::WrapMode(myWrapMode + 1);
if (myWrapMode >= AxMailWrapper::WM_COUNT) myWrapMode = AxMailWrapper::WM_NONE;
updateWithCurrentMail();
showStatusMsg( ::Ax::Tools::String::sprintf( "%s: %s"
, tr("Info$Wrap mode")
, std::string(AxVdrTools::WrapModeStrings[myWrapMode]).c_str()
)
);
break;
}
case A_SHOW_ALL_PARTS:
{
myShowAllParts = !myShowAllParts;
getAction(A_SHOW_ALL_PARTS)->setDesc(myShowAllParts ? tr("Show text parts") : tr("Show all parts"));
updateWithCurrentMail();
break;
}
default: //----- give parents a chance --------------------------------
{
theState = PARENT::processAction(theAction, theState);
break;
}
} // switch
return theState;
} // AxMenuMailView::processAction()
//-------------------------------------------------------------------------
// AxMenuMailView::ProcessKey()
//-------------------------------------------------------------------------
eOSState AxMenuMailView::ProcessKey(eKeys theKey)
{
//--------------------------------------------------------------------------------------------
// scroll the text-area ('borrowed from vdr/menu.c: eOSState cMenuText::ProcessKey(eKeys Key)
if (!HasSubMenu())
{
switch (int(theKey))
{
case kUp|k_Repeat:
case kUp:
case kDown|k_Repeat:
case kDown:
case kLeft|k_Repeat:
case kLeft:
case kRight|k_Repeat:
case kRight:
{
DisplayMenu()->Scroll( NORMALKEY(theKey) == kUp || NORMALKEY(theKey) == kLeft // up?
, NORMALKEY(theKey) == kLeft || NORMALKEY(theKey) == kRight // page?
);
cStatus::MsgOsdTextItem(NULL, NORMALKEY(theKey) == kUp || NORMALKEY(theKey) == kLeft);
return osContinue;
break;
}
default:
{
break;
}
} // switch
} // if
//--------------------------------------------------------------------------------------------
eOSState aState = PARENT::ProcessKey(theKey);
return aState;
} // AxMenuMailView::ProcessKey()
//-------------------------------------------------------------------------
// AxMenuMailView::setCurrentMail()
//-------------------------------------------------------------------------
void AxMenuMailView::setCurrentMail(Ax::Mail::Mail *theMail)
{
myShowAllParts = false;
PARENT::setCurrentMail(theMail);
} // AxMenuMailView::setCurrentMail()
//-------------------------------------------------------------------------
// AxMenuMailView::Display()
//-------------------------------------------------------------------------
void AxMenuMailView::Display(void)
{
PARENT::Display();
//----- display the mail text
DisplayMenu()->SetText(myBodyText.c_str(), myUseFixedFont);
//----- forward the text to status receivers (e.g. for graphlcd/tft)
if (!myBodyText.empty())
{
cStatus::MsgOsdTextItem(myBodyText.c_str());
} // if
} // AxMenuMailView::Display()
//-------------------------------------------------------------------------
// AxMenuMailView::updateActions()
//-------------------------------------------------------------------------
void AxMenuMailView::updateActions()
{
PARENT::updateActions();
//----- refresh title -------
std::string aStr = Ax::Tools::String::sprintf( "%s: %ld / %ld [%s]"
, getMailBox() ? getMailBox()->getAccountName().c_str() : ""
, getCurrentMail() ? getCurrentMail()->getMsgNo() : 0
, getMailBox() ? getFolder() ->getCountMails() : 0
, getCurrentMail() ? AxMenuMailListView::getFlagsStr(getCurrentMail()).c_str() : ""
);
SetTitle(aStr.c_str());
//----- refresh display -----
Display();
} // AxMenuMailView::updateActions()
//-------------------------------------------------------------------------
// AxMenuMailView::updateWithCurrentMail()
//-------------------------------------------------------------------------
void AxMenuMailView::updateWithCurrentMail()
{
myBodyText = "";
Ax::Mail::Mail *aMail = getCurrentMail();
if (getCurrentMail())
{
std::string aText;
//----- Subject: --------------------------------------------------------
if (!Ax::Mail::Tools::decodeEncodedWords(aMail->getSubject(), aText, AxVdrTools::getVdrCharSet(), true))
{
wswarn(("AxMenuMailView::updateWithCurrentMail() unable to decode subject line '%s'", aText.c_str()));
} // if
myBodyText += string(tr("Subject")) + ": " + aText + "\n";
//----- From: ------------------------------------------------------------
if (!Ax::Mail::Tools::decodeEncodedWords(aMail->getFrom(), aText, AxVdrTools::getVdrCharSet(), true))
{
wswarn(("AxMenuMailView::updateWithCurrentMail() unable to decode from line '%s'", aText.c_str()));
} // if
myBodyText += string(tr("From" )) + ": " + aText + "\n";
//----- Date: ------------------------------------------------------------
myBodyText += string(tr("Date" )) + ": " + aMail->getDate() + "\n";
//----- Body: ------------------------------------------------------------
myBodyText += std::string("\n")
+ myMailWrapper->getMailText(aMail, myWrapMode, myShowAllParts);
} // if
//----- update title and buttons ------------------------------------------
updateActions();
} // AxMenuMailView::updateWithCurrentMail()
//-------------------------------------------------------------------------
// AxMenuMailView::informSubOSDClosed()
//-------------------------------------------------------------------------
void AxMenuMailView::informSubOSDClosed(const Ax::Vdr::Action &theAction, eKeys theKey)
{
PARENT::informSubOSDClosed(theAction, theKey);
updateWithCurrentMail();
} // AxMenuMailView::informSubOSDClosed()