File: menu_blacklists.c

package info (click to toggle)
vdr-plugin-epgsearch 2.2.0+git20170817-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 2,788 kB
  • sloc: ansic: 23,630; perl: 1,330; sh: 634; makefile: 226
file content (191 lines) | stat: -rw-r--r-- 5,772 bytes parent folder | download
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
/*                                                                  -*- 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 <iomanip>
#include <sstream>

#include "menu_blacklists.h"
#include "epgsearchtools.h"
#include "menu_blacklistedit.h"
#include "epgsearchcfg.h"
#include "menu_searchresults.h"

using namespace std;

// --- cMenuBlacklistsItem ----------------------------------------------------------
class cMenuBlacklistsItem : public cOsdItem {
  private:
public:
  cBlacklist* blacklist;
  cMenuBlacklistsItem(cBlacklist* Blacklist);
  int Compare(const cListObject &ListObject) const;
  void Set(void);
  };

cMenuBlacklistsItem::cMenuBlacklistsItem(cBlacklist* Blacklist)
{
    blacklist = Blacklist;
    Set();
}

void cMenuBlacklistsItem::Set(void)
{
  ostringstream line;

  if (blacklist->isGlobal != 0)
    line << setiosflags(ios::left) << "G";
  line << "\t";

  if (blacklist->search && strlen(blacklist->search) > 0)
    line << setiosflags(ios::left) << string(blacklist->search);
  else
    line << setiosflags(ios::left) << "*";

  line << "\t";
  if (blacklist->useChannel == 1)
  {
      if (blacklist->channelMin != blacklist->channelMax)
	  line << setiosflags(ios::left) << blacklist->channelMin->Number() << " - " << blacklist->channelMax->Number();
      else
	line << setiosflags(ios::left) << setw(11) << (blacklist->useChannel?CHANNELNAME(blacklist->channelMin):"");
  }
  else if (blacklist->useChannel == 2)
      line << setiosflags(ios::left) << setw(11) << blacklist->channelGroup;

  line << "\t";
  if (blacklist->useTime)
  {
    ostringstream timeline;
    timeline << setfill('0') << setw(2) << blacklist->startTime / 100 << ":" << setw(2) << blacklist->startTime % 100;
    timeline << "\t";
    timeline << setfill('0') << setw(2) << blacklist->stopTime / 100 << ":" << setw(2) << blacklist->stopTime % 100;
    line << timeline.str();
  }
  else
    line << "--:--\t--:--";

  SetText(strdup(line.str().c_str()), false);
}

int cMenuBlacklistsItem::Compare(const cListObject &ListObject) const
{
  cMenuBlacklistsItem *p = (cMenuBlacklistsItem *)&ListObject;
  return strcasecmp(blacklist->search, p->blacklist->search);
}

// --- cMenuBlacklists ----------------------------------------------------------
cMenuBlacklists::cMenuBlacklists()
:cOsdMenu(tr("Blacklists"), 3, 20, 11, 6, 5)
{
  SetMenuCategory(mcSetupPlugins);
    cMutexLock BlacklistLock(&Blacklists);
    cBlacklist *Blacklist = Blacklists.First();
    while (Blacklist) {
	Add(new cMenuBlacklistsItem(Blacklist));
	Blacklist = Blacklists.Next(Blacklist);
    }
    SetHelp(trVDR("Button$Edit"), trVDR("Button$New"), trVDR("Button$Delete"), NULL);
    Sort();
    Display();

}

cBlacklist *cMenuBlacklists::CurrentBlacklist(void)
{
    cMenuBlacklistsItem *item = (cMenuBlacklistsItem *)Get(Current());
    if (item && Blacklists.Exists(item->blacklist))
	return item->blacklist;
    return NULL;
}

eOSState cMenuBlacklists::New(void)
{
    if (HasSubMenu())
	return osContinue;
    return AddSubMenu(new cMenuBlacklistEdit(new cBlacklist, true));
}

eOSState cMenuBlacklists::Delete(void)
{
    cBlacklist *curBlacklist = CurrentBlacklist();
    if (curBlacklist) {
	if (Interface->Confirm(tr("Edit$Delete blacklist?"))) {
	    LogFile.Log(1,"blacklist %s (%d) deleted", curBlacklist->search, curBlacklist->ID);
	    SearchExts.RemoveBlacklistID(curBlacklist->ID);
	    cMutexLock BlacklistLock(&Blacklists);
	    Blacklists.Del(curBlacklist);
	    Blacklists.Save();
	    cOsdMenu::Del(Current());
	    Display();
	}
    }
    return osContinue;
}

eOSState cMenuBlacklists::ProcessKey(eKeys Key)
{
  int BlacklistNumber = HasSubMenu() ? Count() : -1;
  eOSState state = cOsdMenu::ProcessKey(Key);
  if (state == osUnknown) {
      if (HasSubMenu())
	  return osContinue;
      switch (Key) {
	  case kOk:
	      return AddSubMenu(new cMenuSearchResultsForBlacklist(CurrentBlacklist()));
	      break;
	  case kRed:
	      if (CurrentBlacklist())
		  state = AddSubMenu(new cMenuBlacklistEdit(CurrentBlacklist()));
	      else
		  state = osContinue;
	      break;
	  case kGreen: state = New(); break;
	  case kYellow: state = Delete(); break;
	  default: break;
      }
  }
  if (BlacklistNumber >= 0 && !HasSubMenu())
  {
      cMutexLock BlacklistLock(&Blacklists);
      cBlacklist* Blacklist = Blacklists.Get(BlacklistNumber);
      if (Blacklist)       // a newly created search was confirmed with Ok
	  Add(new cMenuBlacklistsItem(Blacklist));
      // always update all entries, since channel group names may have changed and affect other searches
      Sort();
      for(int i=0; i<Count(); i++)
      {
	  cMenuBlacklistsItem *item = (cMenuBlacklistsItem *)Get(i);
	  if (item)
	  {
	      item->Set();
	      if (item->blacklist == Blacklist)
		  SetCurrent(item);
	  }
      }
      Display();
  }

  return state;
}