File: menu_searchactions.c

package info (click to toggle)
vdr-plugin-epgsearch 1.0.1~beta3-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,764 kB
  • ctags: 2,316
  • sloc: ansic: 23,300; perl: 1,330; sh: 608; makefile: 193
file content (204 lines) | stat: -rw-r--r-- 6,650 bytes parent folder | download | duplicates (2)
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
/*                                                                  -*- c++ -*-
Copyright (C) 2004-2013 Christian Wieninger

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; either version 2
of the License, or (at your option) any later version.

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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Or, point your browser to http://www.gnu.org/licenses/old-licenses/gpl-2.0.html

The author can be reached at cwieninger@gmx.de

The project's page is at http://winni.vdr-developer.org/epgsearch
*/

#include <vector>
#include <string>
#include "menu_commands.h"
#include <vdr/interface.h>
#include <vdr/menu.h>
#include <vdr/plugin.h>
#include "menu_searchactions.h"
#include "menu_searchresults.h"
#include "menu_recsdone.h"
#include "menu_timersdone.h"
#include "menu_switchtimers.h"
#include "menu_blacklists.h"
#include "epgsearchtools.h"
#include "menu_conflictcheck.h"
#include "epgsearchcfg.h"
#include "searchtimer_thread.h"
#include "menu_searchedit.h"

using namespace std;

#define ACTION_COUNTER 11
extern int updateForced;
// --- cMenuSearchActions ---------------------------------------------------------

cMenuSearchActions::cMenuSearchActions(cSearchExt* Search, bool DirectCall)
:cOsdMenu(tr("Search actions"))
{
#if VDRVERSNUM >= 10728
  SetMenuCategory(mcCommand);
#endif
    directCall = DirectCall;
    SetHasHotkeys();

    search = Search;

    Add(new cOsdItem(hk(tr("Execute search"))));
    Add(new cOsdItem(hk(tr("Use as search timer on/off"))));
    Add(new cOsdItem(hk(tr("Trigger search timer update"))));
    Add(new cOsdItem(hk(tr("Show recordings done"))));
    Add(new cOsdItem(hk(tr("Show timers created"))));
    Add(new cOsdItem(hk(tr("Create a copy"))));
    Add(new cOsdItem(hk(tr("Use as template"))));
    Add(new cOsdItem(hk(tr("Show switch list"))));
    Add(new cOsdItem(hk(tr("Show blacklists"))));
    Add(new cOsdItem(hk(tr("Delete created timers?"))));
    Add(new cOsdItem(hk(tr("Timer conflict check"))));
}

cMenuSearchActions::~cMenuSearchActions()
{
}


eOSState cMenuSearchActions::Search(void)
{
    cMenuTemplate* MenuTemplate = NULL;
    if (!search) return osContinue;
    if (search->menuTemplate > 0)
	MenuTemplate = cTemplFile::GetSearchTemplateByPos(search->menuTemplate);
    if (!MenuTemplate)
	MenuTemplate = cTemplFile::GetTemplateByName("MenuSearchResults");
    return AddSubMenu(new cMenuSearchResultsForSearch(search, MenuTemplate));
}

eOSState cMenuSearchActions::OnOffSearchtimer(void)
{
   if (search)
   {
      search->useAsSearchTimer = search->useAsSearchTimer?0:1;
	  SearchExts.Save();
	  if (!search->useAsSearchTimer && Interface->Confirm(tr("Disable associated timers too?")))
         search->OnOffTimers(false);
      if (search->useAsSearchTimer && Interface->Confirm(tr("Activate associated timers too?")))
      {
         search->OnOffTimers(true);
         if (!EPGSearchConfig.useSearchTimers) // enable search timer thread if necessary
         {
            cSearchTimerThread::Init((cPluginEpgsearch*) cPluginManager::GetPlugin("epgsearch"), true);
            INFO(tr("Search timers activated in setup."));
         }
      }
  }
  return osBack;
}


eOSState cMenuSearchActions::Execute()
{
   int current = Current();

   if (current <= ACTION_COUNTER-1)
   {
      if (current == 0)
         return Search();
      if (current == 1)
         return OnOffSearchtimer();
      if (current == 2)
      {
         if (!EPGSearchConfig.useSearchTimers) // enable search timer thread if necessary
         {
            cSearchTimerThread::Init((cPluginEpgsearch*) cPluginManager::GetPlugin("epgsearch"), true);
            INFO(tr("Search timers activated in setup."));
         }
         if (Interface->Confirm(tr("Run search timer update?")))
            updateForced = 3; // with message about completion
         return osBack;
      }
      if (current == 3 && search)
         return AddSubMenu(new cMenuRecsDone(search));
      if (current == 4 && search)
         return AddSubMenu(new cMenuTimersDone(search));
      if (current == 5 && search)
      {
         if (!Interface->Confirm(tr("Copy this entry?")))
            return osBack;
         cSearchExt* copy = new cSearchExt;
         copy->CopyFromTemplate(search);
	 string copyname = string(tr("Copy")) + ": " + search->search;
         strcpy(copy->search, copyname.c_str());
	 cMutexLock SearchExtsLock(&SearchExts);
	 copy->ID = SearchExts.GetNewID();
	 SearchExts.Add(copy);
	 SearchExts.Save();
	 return AddSubMenu(new cMenuEditSearchExt(copy));
      }
      if (current == 6 && search)
      {
         if (!Interface->Confirm(tr("Copy this entry to templates?")))
            return osBack;
         cSearchExt* templateObj = new cSearchExt;
         templateObj->CopyFromTemplate(search);
         strcpy(templateObj->search, search->search);
         cMutexLock SearchTemplatesLock(&SearchTemplates);
         templateObj->ID = SearchTemplates.GetNewID();
         SearchTemplates.Add(templateObj);
         SearchTemplates.Save();
         return osBack;
      }
      if (current == 7)
         return AddSubMenu(new cMenuSwitchTimers());
      if (current == 8)
         return AddSubMenu(new cMenuBlacklists());
      if (current == 9)
      {
         if (!Interface->Confirm(tr("Delete all timers created from this search?")))
            return osBack;
	 search->DeleteAllTimers();
	 return osBack;
     }
     if (current == 10)
       return AddSubMenu(new cMenuConflictCheck());
  }
  return osContinue;
}

eOSState cMenuSearchActions::ProcessKey(eKeys Key)
{
   bool hadSubmenu = HasSubMenu();
   if (directCall && Key == k1 && !HasSubMenu())
      return Search();

   eOSState state = cOsdMenu::ProcessKey(Key);

   // jump back to calling menu, if a command was called directly with key '1' .. '9'
   if (directCall && hadSubmenu && !HasSubMenu())
      return osBack;

   if (state == osUnknown) {
      switch (Key) {
         case kGreen:
         case kYellow:
         case kBlue:
            return osContinue;
         case kOk:
            if (!HasSubMenu())
               return Execute();
         default:   break;
      }
   }
   return state;
}