summaryrefslogtreecommitdiff
path: root/mainmenu.c
blob: 469686d62da51439432a21754c367e96f5da971a (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
/*
 * mainmenu.c
 */

#include "mainmenu.h"
#include "browse.h"
#include "dispatcher.h"
#include "audiorecorder.h"

#include <sstream>


using namespace std;

/* --- cMainmenu ------------------------------------------------------------ */

cMainmenu::cMainmenu(cDispatcher *_dispatcher)
:cOsdMenu("Audiorecorder, Mainmenu")
{
        dispatcher = _dispatcher;
        active = dispatcher->is_active();

        Clear();

        Add(new cOsdItem(tr("Browse tracks"), osUser1));
        Add(new cOsdItem(active ? tr("Stop receiving") : tr("Start receiving"),
                        osUser2));
        Add(new cOsdItem(tr("Start rebuilding cache"), osUser3));

        Display();
}


eOSState cMainmenu::ProcessKey(eKeys key)
{
        eOSState state = cOsdMenu::ProcessKey(key);

        if (HasSubMenu())
                return osContinue;

        switch (state) {
        case osBack:
                state = osEnd;
                break;
        case osUser1:
                if (Cache.is_rebuilding()) {
                        Skins.Message(mtStatus, tr("Rebuilding cache, try later"));
                        break;
                }

                AddSubMenu(new cBrowse());

                break;
        case osUser2:
                if (active) {
                        Add(new cOsdItem(tr("Start receiving"), osUser2), false,
                                Get(Current()));
                        dispatcher->stop();
                        active = false;
                }
                else {
                       // Message if there are no channels to record
                       if (dispatcher->get_no_of_channels() < 1) {
                               char* tmp = NULL;
                               asprintf(&tmp, tr("no channel in %s"),
                                 cPluginAudiorecorder::get_cfg().c_str());
                               Skins.Message(mtStatus, tmp);
                               free(tmp);
                               return state;
                        }
                        Add(new cOsdItem(tr("Stop receiving"), osUser2), false,
                                Get(Current()));
                        dispatcher->start();
                        active = true;
                }
                Del(Current());
                Display();

                break;
        case osUser3:
                Cache.rebuild();
                Skins.Message(mtStatus, tr("Rebuilding cache"));

                break;
        default:
                break;
        }

        return state;
}