Branch data Line data Source code
1 : : /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
2 : : *
3 : : * Copyright 2024, 2025 GNOME Foundation, Inc.
4 : : *
5 : : * SPDX-License-Identifier: LGPL-2.1-or-later
6 : : *
7 : : * This library is free software; you can redistribute it and/or
8 : : * modify it under the terms of the GNU Lesser General Public
9 : : * License as published by the Free Software Foundation; either
10 : : * version 2.1 of the License, or (at your option) any later version.
11 : : *
12 : : * This library is distributed in the hope that it will be useful,
13 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 : : * Lesser General Public License for more details.
16 : : *
17 : : * You should have received a copy of the GNU Lesser General Public
18 : : * License along with this library; if not, write to the Free Software
19 : : * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 : : *
21 : : * Authors:
22 : : * - Philip Withnall <pwithnall@gnome.org>
23 : : */
24 : :
25 : : #pragma once
26 : :
27 : : #include <gio/gio.h>
28 : : #include <glib.h>
29 : : #include <glib-object.h>
30 : : #include <libmalcontent-timer/time-span.h>
31 : :
32 : : G_BEGIN_DECLS
33 : :
34 : : /**
35 : : * MctTimerStoreRecordType:
36 : : * @MCT_TIMER_STORE_RECORD_TYPE_LOGIN_SESSION: a login session
37 : : * @MCT_TIMER_STORE_RECORD_TYPE_APP: an app
38 : : *
39 : : * Types of records supported by [class@Mct.TimerStore].
40 : : *
41 : : * Each record indicates that the user was using something, such as a particular
42 : : * app, or being logged in to a desktop session (i.e. using the computer at
43 : : * all), for a period of time.
44 : : *
45 : : * Since: 0.14.0
46 : : */
47 : : typedef enum {
48 : : MCT_TIMER_STORE_RECORD_TYPE_LOGIN_SESSION,
49 : : MCT_TIMER_STORE_RECORD_TYPE_APP,
50 : : } MctTimerStoreRecordType;
51 : :
52 : : const char *mct_timer_store_record_type_to_string (MctTimerStoreRecordType record_type);
53 : : MctTimerStoreRecordType mct_timer_store_record_type_from_string (const char *str);
54 : : gboolean mct_timer_store_record_type_validate_string (const char *record_type_str,
55 : : GError **error);
56 : : gboolean mct_timer_store_record_type_validate_identifier (MctTimerStoreRecordType record_type,
57 : : const char *identifier,
58 : : GError **error);
59 : :
60 : : /**
61 : : * MctTimerStoreTransaction:
62 : : *
63 : : * Opaque handle for an open and pending transaction to modify data in
64 : : * [class@Mct.TimerStore].
65 : : *
66 : : * A transaction must either be saved using
67 : : * [method@Mct.TimerStore.save_transaction_async] or cancelled using
68 : : * [method@Mct.TimerStore.roll_back_transaction]. There is no other way of
69 : : * freeing one.
70 : : *
71 : : * Since: 0.14.0
72 : : */
73 : : typedef void MctTimerStoreTransaction;
74 : :
75 : : #define MCT_TYPE_TIMER_STORE mct_timer_store_get_type ()
76 [ - + + - : 16 : G_DECLARE_FINAL_TYPE (MctTimerStore, mct_timer_store, MCT, TIMER_STORE, GObject)
+ - ][ + - ]
77 : :
78 : : MctTimerStore *mct_timer_store_new (GFile *store_directory);
79 : :
80 : : GFile *mct_timer_store_get_store_directory (MctTimerStore *self);
81 : :
82 : : void mct_timer_store_open_username_async (MctTimerStore *self,
83 : : const char *username,
84 : : GCancellable *cancellable,
85 : : GAsyncReadyCallback callback,
86 : : void *user_data);
87 : : const MctTimerStoreTransaction *mct_timer_store_open_username_finish (MctTimerStore *self,
88 : : GAsyncResult *result,
89 : : GError **error);
90 : : void mct_timer_store_save_transaction_async (MctTimerStore *self,
91 : : const MctTimerStoreTransaction *transaction,
92 : : uint64_t expiry_cutoff_secs,
93 : : GCancellable *cancellable,
94 : : GAsyncReadyCallback callback,
95 : : void *user_data);
96 : : gboolean mct_timer_store_save_transaction_finish (MctTimerStore *self,
97 : : GAsyncResult *result,
98 : : GError **error);
99 : : void mct_timer_store_roll_back_transaction (MctTimerStore *self,
100 : : const MctTimerStoreTransaction *transaction);
101 : :
102 : : void mct_timer_store_add_time_spans (MctTimerStore *self,
103 : : const MctTimerStoreTransaction *transaction,
104 : : MctTimerStoreRecordType record_type,
105 : : const char *identifier,
106 : : const MctTimeSpan * const *time_spans,
107 : : size_t n_time_spans);
108 : :
109 : : GHashTable *mct_timer_store_calculate_total_times_between (MctTimerStore *self,
110 : : const MctTimerStoreTransaction *transaction,
111 : : MctTimerStoreRecordType record_type,
112 : : uint64_t since_secs,
113 : : uint64_t until_secs);
114 : :
115 : : G_END_DECLS
|