1
// Copyright (C) 2009 Novell, Inc.
3
// This program is free software; you can redistribute it and/or
4
// modify it under the terms of the GNU General Public License
5
// as published by the Free Software Foundation; either version 2
6
// of the License, or (at your option) any later version.
8
// This program is distributed in the hope that it will be useful,
9
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
// GNU General Public License for more details.
13
// You should have received a copy of the GNU General Public License
14
// along with this program; if not, write to the Free Software
15
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
using System.Collections.Generic;
29
public abstract class Client
31
static readonly string old_cache_dir = Path.Combine (System.Environment.GetFolderPath (System.Environment.SpecialFolder.ApplicationData), "pdfmod");
32
static readonly string CacheDir = Path.Combine (XdgBaseDirectorySpec.GetUserDirectory ("XDG_CACHE_HOME", ".cache"), "pdfmod");
34
public Document Document { get; protected set; }
35
public static Configuration Configuration { get; private set; }
37
public event EventHandler DocumentLoaded;
41
Configuration = new Configuration ();
49
protected void OnDocumentLoaded ()
51
var handler = DocumentLoaded;
52
if (handler != null) {
53
handler (this, EventArgs.Empty);
57
protected void LoadFiles ()
59
// This variable should probably be marked volatile
60
Hyena.Log.Debugging = true;
61
LoadFiles (ApplicationContext.CommandLine.Files);
64
public abstract void LoadFiles (IList<string> files);
66
public void LoadPath (string path)
68
LoadPath (path, null);
71
public abstract void LoadPath (string path, string suggestedFilename);
73
static void InitCache ()
75
// Remove the old "cache" dir that really ended up being ~/.config/
76
if (Directory.Exists (old_cache_dir)) {
78
foreach (string file in Directory.GetFiles (CacheDir)) {
79
if (file.Contains ("tmpfile-")) {
86
// Make sure the new one exists
88
Directory.CreateDirectory (CacheDir);
89
Log.DebugFormat ("Cache directory set to {0}", CacheDir);
91
// Remove any tmp files that haven't been touched in three days
92
var too_old = DateTime.Now;
94
foreach (string file in Directory.GetFiles (CacheDir)) {
95
if (file.Contains ("tmpfile-")) {
96
if (File.GetLastAccessTime (file) < too_old) {
101
} catch (Exception e) {
102
Log.Exception (String.Format ("Unable to create cache directory: {0}", CacheDir), e);
106
public static string GetTmpFilename ()
108
string filename = null;
110
while (filename == null) {
111
filename = Path.Combine (CacheDir, "tmpfile-" + i++);
112
if (File.Exists (filename)) {