~ubuntu-branches/ubuntu/trusty/mediathekview/trusty

« back to all changes in this revision

Viewing changes to src/mediathek/controller/History.java

  • Committer: Package Import Robot
  • Author(s): Markus Koschany
  • Date: 2014-01-07 17:25:52 UTC
  • mfrom: (4.1.6 sid)
  • Revision ID: package-import@ubuntu.com-20140107172552-vkv6uixpou3sa5og
Tags: 4-1
* Imported Upstream version 4.
* Declare compliance with Standards-Version 3.9.5.
* Correct a mistake in the last changelog entry.
  - build-dependencies <-> dependencies
* Override lintian warning:incompatible-java-bytecode-format Java7 because
  Java7 is the current default JRE for Jessie. MediathekView also requires
  Java7 to run and is incompatible with Java6 or earlier.
* debian/control: Add libjackson2-core-java, libtimingframework-java and
  libxz-java to Build-Depends-Indep.
* Drop README.source. Now upstream provides a source tarball.
* Refresh modify-ant-build-system.patch.
* debian/rules: Remove get-orig-source target. No longer needed.
* Update mediathekview.manifest. Add new required libraries to classpath.
* Update debian/watch for new versioning scheme.
* Update debian/copyright for new release. Add BSD-3-clause license.
* Update man pages and remove unsupported options.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *    MediathekView
 
3
 *    Copyright (C) 2010 by Andreas M.
 
4
 *    http://zdfmediathk.sourceforge.net/
 
5
 *    
 
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
 
9
 *    any later version.
 
10
 *
 
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.
 
15
 *
 
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/>.
 
18
 */
 
19
package mediathek.controller;
 
20
 
 
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;
 
36
 
 
37
public class History extends HashSet<String> {
 
38
    private Path historyFilePath = null;
 
39
 
 
40
    public History() {
 
41
        try {
 
42
            historyFilePath = getHistoryFilePath();
 
43
        } catch (IOException ex) {
 
44
            ex.printStackTrace();
 
45
        }
 
46
    }
 
47
 
 
48
    @Override
 
49
    public boolean add(String url) {
 
50
        boolean ret = super.add(url);
 
51
        ListenerMediathekView.notify(ListenerMediathekView.EREIGNIS_LISTE_HISTORY_GEAENDERT, History.class.getSimpleName());
 
52
        return ret;
 
53
    }
 
54
 
 
55
    public void add(ArrayList<DatenDownload> ad) {
 
56
        for (DatenDownload d : ad) {
 
57
            super.add(d.arr[DatenDownload.DOWNLOAD_HISTORY_URL_NR]);
 
58
        }
 
59
        ListenerMediathekView.notify(ListenerMediathekView.EREIGNIS_LISTE_HISTORY_GEAENDERT, History.class.getSimpleName());
 
60
    }
 
61
 
 
62
    @Override
 
63
    public boolean remove(Object url) {
 
64
        boolean ret = super.remove(url);
 
65
        ListenerMediathekView.notify(ListenerMediathekView.EREIGNIS_LISTE_HISTORY_GEAENDERT, History.class.getSimpleName());
 
66
        return ret;
 
67
    }
 
68
 
 
69
    /**
 
70
     * Get the Path to the history file
 
71
     * @return Path object to history file
 
72
     */
 
73
    private Path getHistoryFilePath() throws IOException {
 
74
        Path historyFilePath = null;
 
75
        historyFilePath = Daten.getSettingsDirectory().resolve("history.txt");
 
76
 
 
77
        return historyFilePath;
 
78
    }
 
79
 
 
80
    public void laden() {
 
81
        clear();
 
82
 
 
83
        if (Files.notExists(historyFilePath))
 
84
            return;
 
85
 
 
86
        try (BufferedReader br = new BufferedReader(new InputStreamReader(new DataInputStream(Files.newInputStream(historyFilePath))))) {
 
87
            String strLine;
 
88
            while ((strLine = br.readLine()) != null) {
 
89
                super.add(strLine);
 
90
            }
 
91
            br.close();
 
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);
 
96
        }
 
97
    }
 
98
 
 
99
    public void speichern() {
 
100
        try (BufferedWriter br = new BufferedWriter(new OutputStreamWriter(new DataOutputStream(Files.newOutputStream(historyFilePath)))))
 
101
        {
 
102
            for (String h : this)
 
103
                br.write(h + "\n");
 
104
 
 
105
            br.flush();
 
106
            br.close();
 
107
        } catch (Exception e) {//Catch exception if any
 
108
            Log.fehlerMeldung(978786563, Log.FEHLER_ART_PROG, History.class.getName(), e);
 
109
        }
 
110
    }
 
111
 
 
112
    public void loeschen() {
 
113
        this.clear();
 
114
 
 
115
        if (Files.notExists(historyFilePath))
 
116
            return;
 
117
 
 
118
        try {
 
119
            Files.delete(historyFilePath);
 
120
            ListenerMediathekView.notify(ListenerMediathekView.EREIGNIS_LISTE_HISTORY_GEAENDERT, History.class.getSimpleName());
 
121
        } catch (IOException ignored) {
 
122
        }
 
123
    }
 
124
 
 
125
    public Object[][] getObjectData() {
 
126
        Object[][] object;
 
127
        int i = 0;
 
128
        Iterator<String> iterator = this.iterator();
 
129
        object = new Object[this.size()][1];
 
130
        while (iterator.hasNext()) {
 
131
            object[i][0] = iterator.next();
 
132
            ++i;
 
133
        }
 
134
        return object;
 
135
    }
 
136
}