1 /*
2  * Photos - access, organize and share your photos on GNOME
3  * Copyright © 2014 – 2019 Red Hat, Inc.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 /* Based on code from:
20  *   + Documents
21  */
22 
23 
24 #include "config.h"
25 
26 #include <gio/gio.h>
27 
28 #include "photos-query-builder.h"
29 #include "photos-offset-search-controller.h"
30 #include "photos-search-context.h"
31 
32 
33 struct _PhotosOffsetSearchController
34 {
35   PhotosOffsetController parent_instance;
36 };
37 
38 
39 G_DEFINE_TYPE (PhotosOffsetSearchController, photos_offset_search_controller, PHOTOS_TYPE_OFFSET_CONTROLLER);
40 
41 
42 static PhotosQuery *
photos_offset_search_controller_get_query(PhotosOffsetController * offset_cntrlr)43 photos_offset_search_controller_get_query (PhotosOffsetController *offset_cntrlr)
44 {
45   GApplication *app;
46   PhotosSearchContextState *state;
47 
48   app = g_application_get_default ();
49   state = photos_search_context_get_state (PHOTOS_SEARCH_CONTEXT (app));
50 
51   return photos_query_builder_count_query (state, PHOTOS_QUERY_FLAGS_SEARCH);
52 }
53 
54 
55 static GObject *
photos_offset_search_controller_constructor(GType type,guint n_construct_params,GObjectConstructParam * construct_params)56 photos_offset_search_controller_constructor (GType type,
57                                              guint n_construct_params,
58                                              GObjectConstructParam *construct_params)
59 {
60   static GObject *self = NULL;
61 
62   if (self == NULL)
63     {
64       self = G_OBJECT_CLASS (photos_offset_search_controller_parent_class)->constructor (type,
65                                                                                          n_construct_params,
66                                                                                          construct_params);
67       g_object_add_weak_pointer (self, (gpointer) &self);
68       return self;
69     }
70 
71   return g_object_ref (self);
72 }
73 
74 
75 static void
photos_offset_search_controller_init(PhotosOffsetSearchController * self)76 photos_offset_search_controller_init (PhotosOffsetSearchController *self)
77 {
78 }
79 
80 
81 static void
photos_offset_search_controller_class_init(PhotosOffsetSearchControllerClass * class)82 photos_offset_search_controller_class_init (PhotosOffsetSearchControllerClass *class)
83 {
84   GObjectClass *object_class = G_OBJECT_CLASS (class);
85   PhotosOffsetControllerClass *offset_controller_class = PHOTOS_OFFSET_CONTROLLER_CLASS (class);
86 
87   object_class->constructor = photos_offset_search_controller_constructor;
88   offset_controller_class->get_query = photos_offset_search_controller_get_query;
89 }
90 
91 
92 PhotosOffsetController *
photos_offset_search_controller_dup_singleton(void)93 photos_offset_search_controller_dup_singleton (void)
94 {
95   return g_object_new (PHOTOS_TYPE_OFFSET_SEARCH_CONTROLLER, NULL);
96 }
97