summaryrefslogtreecommitdiff
path: root/imagelist.c
blob: c605b32fa817fbf7ca42f9d869d2acde5061098e (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
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
#include "imagelist.h"

//cImageList ImageList;

cImageList::cImageList(void)
{
  Setup = false;
}

cImageList::~ cImageList(void)
{
}

void cImageList::Init(void)
{
  dsyslog("Init ImageList");
  if(!Setup)
  {
    Add(new cImageListItem(tr("Directory with 'VIDEO_TS' Folder"),
                           tr("Directory"),
                           tDir,
                           "video_ts",
                           true));
    Add(new cImageListItem(tr("File with '.iso' Extension"),
                           tr("Iso-Image"),
                           tFile,
                           ".iso",
                           true));
  }
}

void cImageList::AddItem(const char *item)
{
  dsyslog("Neues Item soll hinzugefügt werden: %s", item);

  if (!isempty(item))
  {
    cTokenizer *token = new cTokenizer(item, "|");
    if(token->Count() == 5)
      Add(new cImageListItem(token->GetToken(1),
                             token->GetToken(2),
                             (eFileInfo)atoi(token->GetToken(3)),
                             token->GetToken(4),
                             atoi(token->GetToken(5))));
    delete(token);
  }
}

void cImageList::AddSetup(const char *value)
{
  dsyslog("Erhalte SetupString: %s",value);

  Setup = true;
  Clear();

  if(!isempty(value))
  {
    cTokenizer *token = new cTokenizer(value, "@");
    for(int i = 1; i <= token->Count(); i++)
      AddItem(token->GetToken(i));
    DELETENULL(token);
  }
}

char *cImageList::GetSetupString(void)
{
  dsyslog("Erstelle SetupString");

  SString = NULL;
  cImageListItem *item = First();

  while(item)
  {
    dsyslog("Füge hinzu: %s", item->SaveString());
    SString += item->SaveString();
    SString += "@";
    item = Next(item);
  }

  return &SString;
}

char *cImageList::GetExtensions(void)
{
  dsyslog("Erstelle Liste aller Extensions");

  Ext = NULL;
  cImageListItem *item = First();

  while(item)
  {
    dsyslog("Item ist vom Type: %i", (int) item->GetFType());
    if(item->GetFType() == tFile)
    {
      dsyslog("Item wird hinzugefügt: %s", item->GetValue());
      Ext += item->GetValue();
      Ext += "@";
    }
    item = Next(item);
  }

  return stripspace(&Ext);
}

char *cImageList::GetHideExtensions(void)
{
  dsyslog("Erstelle Liste aller Extensions die ausgeblendet werden sollen");

  HideExt = NULL;
  cImageListItem *item = First();

  while(item)
  {
    dsyslog("Item ist vom Type: %i", (int) item->GetFType());
    if(item->GetFType() == tFile && item->IsHide())
    {
      dsyslog("Item wird hinzugefügt: %s", item->GetValue());
      HideExt += item->GetValue();
      HideExt += "@";
    }
    item = Next(item);
  }

  return stripspace(&HideExt);
}

char *cImageList::GetDirContains(void)
{
  dsyslog("Erstelle Liste aller Verzeichnisinhalte");

  DirIn = NULL;
  cImageListItem *item = First();

  while(item)
  {
    dsyslog("Item ist vom Type: %i", (int) item->GetFType());
    if(item->GetFType() == tDir)
    {
      dsyslog("Item wird hinzugefügt: %s", item->GetValue());
      DirIn += item->GetValue();
      DirIn += "@";
    }
    item = Next(item);
  }

  return stripspace(&DirIn);
}

char *cImageList::GetShortName(const char *file)
{
  dsyslog("Shortname wird gesucht: %s", file);

  Short = NULL;
  cImageListItem *item = First();
  cFileInfo *info = new cFileInfo(file);

  switch(info->Type())
  {
    case tDir:
      while(item)
      {
        if(item->GetFType() == tDir &&
           cFileList::DirIsIn(file, item->GetValue()))
          break;
        item = Next(item);
      }
      if(item)
        Short = item->GetSName();
      break;
    case tFile:
      while(item)
      {
        if(item->GetFType() == tFile &&
           !strcasecmp(item->GetValue(), info->Extension()))
          break;
        item = Next(item);
      }
      if(item)
        Short = item->GetSName();
      break;
    default:
      break;
  }

  return &Short;
}

bool cImageList::IsHide(const char *ext)
{
  if(!ext)
    return false;

  cImageListItem *item = First();
  while(item)
  {
    if(item->GetFType() == tFile &&
       item->IsHide() &&
       !strcasecmp(ext, item->GetValue()))
      return true;
    item = Next(item);
  }
  return false;
}