summaryrefslogtreecommitdiff
path: root/menu_reset.c
blob: 96f305ff594f71a0ff825cb8e58af67d19636011 (plain)
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
/* * menu_reset.c: The actual menu implementations
 *
 * See the main source file 'vdr.c' for copyright information and
 * how to reach the author.
 *
 * $Id:
 */

#include "menu_reset.h"
#include "zaplist.h"
#include "setup-zaphistory.h"

#include <vdr/menu.h>
#include <vdr/interface.h>

cMenuHistoryReset::cMenuHistoryReset(cZapHistoryChannel *zapChan)
    :cOsdMenu(tr("Reset history") )
{
    zapChannel = zapChan;
    Setup();
}

void cMenuHistoryReset::Setup() {
    Clear(); // Remove old menuitems

    char *buffer = NULL;

    // Items to operate on the complete history  
    Add( new cOsdItem( tr("Delete all entries") ) );
    Add( new cOsdItem( tr("Reset all statistics") ) );

    // if a channel has been passed, add menuitems for operations on that channel
    if (zapChannel != NULL) {
        asprintf(&buffer, "%s%s %s", tr("Delete entry"), ":", zapChannel->GetChannel()->Name() );
        Add( new cOsdItem( buffer ) );
        free(buffer);

        asprintf(&buffer, "%s%s %s", tr("Reset statistics for"), ":", zapChannel->GetChannel()->Name() );
        Add( new cOsdItem( buffer ) );
        free(buffer);
    }

    // Buttons
    SetHelp(tr("Button$Ok"), 0,  0, tr("Button$Back") );  

    Display();
}

eOSState cMenuHistoryReset::ProcessKey(eKeys Key)
{
    eOSState state = cOsdMenu::ProcessKey(Key);

    if (state == osUnknown) {
        switch (Key) {
            case kBlue: // Close reset menu
	            return osBack;
            case kRed:
            case kOk: // Execute operation
                // Validate index of selected item
	            switch ( Current() ) {
	                case 0: // Delete all entries
		                if (Interface->Confirm(tr("Delete complete history?") ) ) {
		                    ZapHistory.Reset(NULL, false);
		                    return osBack;
		                }
		                break;
	                case 1: // Reset complete statistisc
		                if (Interface->Confirm(tr("Reset all?") ) ) {
		                    ZapHistory.Reset(NULL);
		                    return osBack;
		                }
		                break;
	                case 2: // Delete entry XYZ
		                if (zapChannel != NULL && Interface->Confirm(tr("Delete entry?") ) ) {
		                    ZapHistory.Reset(zapChannel, false);
		                    return osBack;
		                }
		                break;
	                case 3: // Reset statistics for XYZ
		                if (zapChannel != NULL && Interface->Confirm(tr("Reset entry?") ) ) {
		                    ZapHistory.Reset(zapChannel);
		                    return osBack;
		                }
		                break;
	            }
      	        return osContinue;

            default: return osContinue;  
        }
    }

    return state;
}