3
* Copyright (C) 2010 by Andreas M.
4
* http://zdfmediathk.sourceforge.net/
6
* This program is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19
package mediathek.controller;
21
import java.io.BufferedReader;
22
import java.io.BufferedWriter;
23
import java.io.DataInputStream;
24
import java.io.DataOutputStream;
25
import java.io.IOException;
26
import java.io.InputStreamReader;
27
import java.io.OutputStreamWriter;
28
import java.nio.file.Files;
29
import java.nio.file.Path;
30
import java.util.ArrayList;
31
import java.util.HashSet;
32
import java.util.Iterator;
33
import mediathek.daten.Daten;
34
import mediathek.daten.DatenDownload;
35
import mediathek.tool.ListenerMediathekView;
37
public class History extends HashSet<String> {
38
private Path historyFilePath = null;
42
historyFilePath = getHistoryFilePath();
43
} catch (IOException ex) {
49
public boolean add(String url) {
50
boolean ret = super.add(url);
51
ListenerMediathekView.notify(ListenerMediathekView.EREIGNIS_LISTE_HISTORY_GEAENDERT, History.class.getSimpleName());
55
public void add(ArrayList<DatenDownload> ad) {
56
for (DatenDownload d : ad) {
57
super.add(d.arr[DatenDownload.DOWNLOAD_HISTORY_URL_NR]);
59
ListenerMediathekView.notify(ListenerMediathekView.EREIGNIS_LISTE_HISTORY_GEAENDERT, History.class.getSimpleName());
63
public boolean remove(Object url) {
64
boolean ret = super.remove(url);
65
ListenerMediathekView.notify(ListenerMediathekView.EREIGNIS_LISTE_HISTORY_GEAENDERT, History.class.getSimpleName());
70
* Get the Path to the history file
71
* @return Path object to history file
73
private Path getHistoryFilePath() throws IOException {
74
Path historyFilePath = null;
75
historyFilePath = Daten.getSettingsDirectory().resolve("history.txt");
77
return historyFilePath;
83
if (Files.notExists(historyFilePath))
86
try (BufferedReader br = new BufferedReader(new InputStreamReader(new DataInputStream(Files.newInputStream(historyFilePath))))) {
88
while ((strLine = br.readLine()) != null) {
92
ListenerMediathekView.notify(ListenerMediathekView.EREIGNIS_LISTE_HISTORY_GEAENDERT, History.class.getSimpleName());
93
} catch (Exception e) {
94
System.err.println("Fehler: " + e);
95
Log.fehlerMeldung(303049876, Log.FEHLER_ART_PROG, History.class.getName(), e);
99
public void speichern() {
100
try (BufferedWriter br = new BufferedWriter(new OutputStreamWriter(new DataOutputStream(Files.newOutputStream(historyFilePath)))))
102
for (String h : this)
107
} catch (Exception e) {//Catch exception if any
108
Log.fehlerMeldung(978786563, Log.FEHLER_ART_PROG, History.class.getName(), e);
112
public void loeschen() {
115
if (Files.notExists(historyFilePath))
119
Files.delete(historyFilePath);
120
ListenerMediathekView.notify(ListenerMediathekView.EREIGNIS_LISTE_HISTORY_GEAENDERT, History.class.getSimpleName());
121
} catch (IOException ignored) {
125
public Object[][] getObjectData() {
128
Iterator<String> iterator = this.iterator();
129
object = new Object[this.size()][1];
130
while (iterator.hasNext()) {
131
object[i][0] = iterator.next();