~ubuntu-branches/ubuntu/quantal/zeitgeist/quantal

« back to all changes in this revision

Viewing changes to src/utils.vala

  • Committer: Package Import Robot
  • Author(s): Didier Roche
  • Date: 2011-11-15 11:15:56 UTC
  • mto: (6.2.2 experimental) (1.3.1)
  • mto: This revision was merged to the branch mainline in revision 19.
  • Revision ID: package-import@ubuntu.com-20111115111556-so7cmhfbqongw7hf
Tags: upstream-0.8.99~alpha1
Import upstream version 0.8.99~alpha1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* utils.vala
 
2
 *
 
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>
 
8
 *
 
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.
 
13
 *
 
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.
 
18
 *
 
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/>.
 
21
 *
 
22
 */
 
23
 
 
24
namespace Zeitgeist
 
25
{
 
26
    namespace Utils
 
27
    {
 
28
        // Paths
 
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;
 
33
 
 
34
        public const string ZEITGEIST_DATA_FOLDER = "zeitgeist";
 
35
        public const string USER_EXTENSION_PATH = "";
 
36
 
 
37
        // D-Bus
 
38
        public const string DBUS_INTERFACE = "";
 
39
        public const string SIG_EVENT = "asaasay";
 
40
 
 
41
        // configure runtime cache for events
 
42
        // default size is 2000
 
43
        public const uint CACHE_SIZE = 0;
 
44
 
 
45
        public unowned string get_data_path ()
 
46
        {
 
47
            if (DATA_PATH != null) return DATA_PATH;
 
48
 
 
49
            DATA_PATH = Environment.get_variable ("ZEITGEIST_DATA_PATH") ??
 
50
                Path.build_filename (Environment.get_user_data_dir (),
 
51
                    ZEITGEIST_DATA_FOLDER);
 
52
 
 
53
            if (!FileUtils.test (DATA_PATH, FileTest.IS_DIR))
 
54
            {
 
55
                 DirUtils.create_with_parents (DATA_PATH, 0755);
 
56
            }
 
57
 
 
58
            debug ("DATA_PATH = %s", DATA_PATH);
 
59
 
 
60
            return DATA_PATH;
 
61
        }
 
62
 
 
63
        public unowned string get_database_file_path ()
 
64
        {
 
65
            if (DATABASE_FILE_PATH != null) return DATABASE_FILE_PATH;
 
66
 
 
67
            DATABASE_FILE_PATH =
 
68
                Environment.get_variable ("ZEITGEIST_DATABASE_PATH") ??
 
69
                Path.build_filename (get_data_path (), "activity.sqlite");
 
70
 
 
71
            debug ("DATABASE_FILE_PATH = %s", DATABASE_FILE_PATH);
 
72
 
 
73
            return DATABASE_FILE_PATH;
 
74
        }
 
75
 
 
76
        public unowned string get_database_file_backup_path ()
 
77
        {
 
78
            if (DATABASE_FILE_BACKUP_PATH != null)
 
79
                return DATABASE_FILE_BACKUP_PATH;
 
80
 
 
81
            DATABASE_FILE_BACKUP_PATH =
 
82
                Environment.get_variable ("ZEITGEIST_DATABASE_BACKUP_PATH") ??
 
83
                Path.build_filename (get_data_path (), "activity.sqlite.bck");
 
84
 
 
85
            debug ("DATABASE_FILE_BACKUP_PATH = %s", DATABASE_FILE_BACKUP_PATH);
 
86
 
 
87
            return DATABASE_FILE_BACKUP_PATH;
 
88
        }
 
89
 
 
90
        public unowned string get_local_extensions_path ()
 
91
        {
 
92
            if (LOCAL_EXTENSIONS_PATH != null) return LOCAL_EXTENSIONS_PATH;
 
93
 
 
94
            LOCAL_EXTENSIONS_PATH = Path.build_filename (get_data_path (),
 
95
                "extensions");
 
96
 
 
97
            debug ("LOCAL_EXTENSIONS_PATH = %s", LOCAL_EXTENSIONS_PATH);
 
98
 
 
99
            return LOCAL_EXTENSIONS_PATH;
 
100
        }
 
101
 
 
102
        public bool using_in_memory_database ()
 
103
        {
 
104
            return get_database_file_path () == ":memory:";
 
105
        }
 
106
 
 
107
        public void backup_database () throws Error
 
108
        {
 
109
            File original;
 
110
            File destination;
 
111
            original = File.new_for_path (get_database_file_path ());
 
112
            destination = File.new_for_path (get_database_file_backup_path ());
 
113
 
 
114
            original.copy (destination, FileCopyFlags.OVERWRITE, null, null);
 
115
        }
 
116
    }
 
117
}
 
118
 
 
119
// vim:expandtab:ts=4:sw=4