comparison pui-application.c @ 1:2f04ec9e0506

Add preferences application Split settings into separate file.
author Guido Berhoerster <guido+pui@berhoerster.name>
date Fri, 08 Jun 2018 08:38:42 +0200
parents 6884bb8130ca
children 7172a0db97af
comparison
equal deleted inserted replaced
0:6884bb8130ca 1:2f04ec9e0506
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */ 22 */
23 23
24 #define G_SETTINGS_ENABLE_BACKEND
25 #include <gio/gsettingsbackend.h>
26 #include <glib/gi18n.h> 24 #include <glib/gi18n.h>
27 #include <libappindicator/app-indicator.h> 25 #include <libappindicator/app-indicator.h>
28 #include <stdlib.h> 26 #include <stdlib.h>
29 #include <string.h> 27 #include <string.h>
30 28
29 #include "pui-application.h"
30 #include "pui-backend.h"
31 #include "pui-common.h" 31 #include "pui-common.h"
32 #include "pui-application.h" 32 #include "pui-settings.h"
33 #include "pui-types.h" 33 #include "pui-types.h"
34 #include "pui-backend.h"
35
36 #define SETTINGS_ROOT_PATH \
37 "/org/guido-berhoerster/code/package-update-indicator/"
38 #define SETTINGS_ROOT_GROUP "General"
39 34
40 struct _PuiApplication { 35 struct _PuiApplication {
41 GApplication parent_instance; 36 GApplication parent_instance;
42 GSettings *settings; 37 GSettings *settings;
43 GCancellable *cancellable; 38 GCancellable *cancellable;
408 static void 403 static void
409 pui_application_startup(GApplication *application) 404 pui_application_startup(GApplication *application)
410 { 405 {
411 PuiApplication *self = PUI_APPLICATION(application); 406 PuiApplication *self = PUI_APPLICATION(application);
412 gsize i; 407 gsize i;
413 gchar *settings_filename;
414 GSettingsBackend *settings_backend;
415 GtkWidget *menu; 408 GtkWidget *menu;
416 GtkWidget *menu_item; 409 GtkWidget *menu_item;
417 410
418 G_APPLICATION_CLASS(pui_application_parent_class)->startup(application); 411 G_APPLICATION_CLASS(pui_application_parent_class)->startup(application);
419 412
426 for (i = 0; i < G_N_ELEMENTS(self->icons); i++) { 419 for (i = 0; i < G_N_ELEMENTS(self->icons); i++) {
427 self->icons[i] = g_themed_icon_new(icon_names[i]); 420 self->icons[i] = g_themed_icon_new(icon_names[i]);
428 } 421 }
429 422
430 /* create settings */ 423 /* create settings */
431 settings_filename = g_build_filename(g_get_user_config_dir(), PACKAGE, 424 self->settings = pui_settings_new();
432 PACKAGE ".conf", NULL);
433 settings_backend = g_keyfile_settings_backend_new(settings_filename,
434 SETTINGS_ROOT_PATH, SETTINGS_ROOT_GROUP);
435 self->settings = g_settings_new_with_backend(APPLICATION_ID,
436 settings_backend);
437 g_settings_bind(self->settings, "update-command", self, 425 g_settings_bind(self->settings, "update-command", self,
438 "update-command", G_SETTINGS_BIND_GET); 426 "update-command", G_SETTINGS_BIND_GET);
439 427
440 /* start instantiating backend */ 428 /* start instantiating backend */
441 pui_backend_new_async(self->cancellable, on_pui_backend_finished, self); 429 pui_backend_new_async(self->cancellable, on_pui_backend_finished, self);
466 454
467 update_ui(self); 455 update_ui(self);
468 456
469 /* keep GApplication running */ 457 /* keep GApplication running */
470 g_application_hold(application); 458 g_application_hold(application);
471
472 g_object_unref(settings_backend);
473 g_free(settings_filename);
474 } 459 }
475 460
476 static void 461 static void
477 pui_application_shutdown(GApplication *application) 462 pui_application_shutdown(GApplication *application)
478 { 463 {