3
* Copyright © 2011 Collabora Ltd.
4
* By Seif Lotfy <seif@lotfy.com>
5
* By Siegfried-Angel Gevatter Pujals <siegfried@gevatter.com>
6
* Copyright © 2011 Michal Hruby <michal.mhr@gmail.com>
7
* Copyright © 2011 Manish Sinha <manishsinha@ubuntu.com>
9
* This program is free software: you can redistribute it and/or modify
10
* it under the terms of the GNU Lesser General Public License as published by
11
* the Free Software Foundation, either version 2.1 of the License, or
12
* (at your option) any later version.
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* You should have received a copy of the GNU Lesser General Public License
20
* along with this program. If not, see <http://www.gnu.org/licenses/>.
29
private static string DATA_PATH;
30
private static string DATABASE_FILE_PATH;
31
private static string DATABASE_FILE_BACKUP_PATH;
32
private static string LOCAL_EXTENSIONS_PATH;
34
public const string ZEITGEIST_DATA_FOLDER = "zeitgeist";
35
public const string USER_EXTENSION_PATH = "";
38
public const string DBUS_INTERFACE = "";
39
public const string SIG_EVENT = "asaasay";
41
// configure runtime cache for events
42
// default size is 2000
43
public const uint CACHE_SIZE = 0;
45
public unowned string get_data_path ()
47
if (DATA_PATH != null) return DATA_PATH;
49
DATA_PATH = Environment.get_variable ("ZEITGEIST_DATA_PATH") ??
50
Path.build_filename (Environment.get_user_data_dir (),
51
ZEITGEIST_DATA_FOLDER);
53
if (!FileUtils.test (DATA_PATH, FileTest.IS_DIR))
55
DirUtils.create_with_parents (DATA_PATH, 0755);
58
debug ("DATA_PATH = %s", DATA_PATH);
63
public unowned string get_database_file_path ()
65
if (DATABASE_FILE_PATH != null) return DATABASE_FILE_PATH;
68
Environment.get_variable ("ZEITGEIST_DATABASE_PATH") ??
69
Path.build_filename (get_data_path (), "activity.sqlite");
71
debug ("DATABASE_FILE_PATH = %s", DATABASE_FILE_PATH);
73
return DATABASE_FILE_PATH;
76
public unowned string get_database_file_backup_path ()
78
if (DATABASE_FILE_BACKUP_PATH != null)
79
return DATABASE_FILE_BACKUP_PATH;
81
DATABASE_FILE_BACKUP_PATH =
82
Environment.get_variable ("ZEITGEIST_DATABASE_BACKUP_PATH") ??
83
Path.build_filename (get_data_path (), "activity.sqlite.bck");
85
debug ("DATABASE_FILE_BACKUP_PATH = %s", DATABASE_FILE_BACKUP_PATH);
87
return DATABASE_FILE_BACKUP_PATH;
90
public unowned string get_local_extensions_path ()
92
if (LOCAL_EXTENSIONS_PATH != null) return LOCAL_EXTENSIONS_PATH;
94
LOCAL_EXTENSIONS_PATH = Path.build_filename (get_data_path (),
97
debug ("LOCAL_EXTENSIONS_PATH = %s", LOCAL_EXTENSIONS_PATH);
99
return LOCAL_EXTENSIONS_PATH;
102
public bool using_in_memory_database ()
104
return get_database_file_path () == ":memory:";
107
public void backup_database () throws Error
111
original = File.new_for_path (get_database_file_path ());
112
destination = File.new_for_path (get_database_file_backup_path ());
114
original.copy (destination, FileCopyFlags.OVERWRITE, null, null);
119
// vim:expandtab:ts=4:sw=4