summaryrefslogtreecommitdiff
path: root/visibility.c
diff options
context:
space:
mode:
authorTimo Eskola <timo@tolleri.net>2015-09-08 12:59:54 +0300
committerTimo Eskola <timo@tolleri.net>2015-09-08 12:59:54 +0300
commitb94ebafe8c2f32b404d69f1ea8e6bc2de68e606a (patch)
treecfcdfef1696b16df880e5be0d880e8f72e96446f /visibility.c
parent47a129b230b2b2e9a880948b5bc188ab715ba3b2 (diff)
downloadvdr-plugin-duplicates-b94ebafe8c2f32b404d69f1ea8e6bc2de68e606a.tar.gz
vdr-plugin-duplicates-b94ebafe8c2f32b404d69f1ea8e6bc2de68e606a.tar.bz2
Version 0.1.0:
- Added hiding of duplicate recordings. - Updated German translations, thanks to Joerg Bornkessel.
Diffstat (limited to 'visibility.c')
-rw-r--r--visibility.c75
1 files changed, 75 insertions, 0 deletions
diff --git a/visibility.c b/visibility.c
new file mode 100644
index 0000000..35bdd97
--- /dev/null
+++ b/visibility.c
@@ -0,0 +1,75 @@
+/*
+ * visibility.c: Visibility classes for duplicates plugin.
+ *
+ * See the README file for copyright information and how to reach the author.
+ *
+ * $Id$
+ */
+
+#include "visibility.h"
+
+// --- cVisibility -----------------------------------------------------------
+
+#ifdef DEBUG_VISIBILITY
+int cVisibility::getCount = 0;
+int cVisibility::readCount = 0;
+int cVisibility::accessCount = 0;
+#endif
+
+cVisibility::cVisibility(const char *fileName) {
+ hiddenFileName = AddDirectory(fileName, "duplicates.hidden");
+ visibility = UNKNOWN;
+}
+
+cVisibility::cVisibility(const cVisibility &Visibility) :
+ hiddenFileName(Visibility.hiddenFileName),
+ visibility(Visibility.visibility) {}
+
+eVisibility cVisibility::Get(void) {
+#ifdef DEBUG_VISIBILITY
+ getCount++;
+#endif
+ return visibility;
+}
+
+void cVisibility::Set(bool visible) {
+ visibility = visible ? VISIBLE : HIDDEN;
+}
+
+eVisibility cVisibility::Read(void) {
+#ifdef DEBUG_VISIBILITY
+ readCount++;
+#endif
+ if (visibility == UNKNOWN) {
+#ifdef DEBUG_VISIBILITY
+ accessCount++;
+#endif
+ visibility = access(hiddenFileName, F_OK) == 0 ? HIDDEN : VISIBLE;
+ }
+ return visibility;
+}
+
+bool cVisibility::Write(bool visible) {
+ if (visible) {
+ if (remove(hiddenFileName) == 0) {
+ visibility = VISIBLE;
+ return true;
+ }
+ } else {
+ FILE *f = fopen(hiddenFileName, "w");
+ if (f) {
+ fclose(f);
+ visibility = HIDDEN;
+ return true;
+ }
+ }
+ return false;
+}
+
+#ifdef DEBUG_VISIBILITY
+void cVisibility::ClearCounters(void) {
+ getCount = 0;
+ readCount = 0;
+ accessCount = 0;
+}
+#endif