[bijiben/wip/sadiq/modernize: 3/9] application: Port to bjb-application
- From: Mohammed Sadiq <pksadiq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [bijiben/wip/sadiq/modernize: 3/9] application: Port to bjb-application
- Date: Wed, 1 Nov 2017 14:31:22 +0000 (UTC)
commit 994f52eb10ad33061484a81aa2354206932648d5
Author: Mohammed Sadiq <sadiq sadiqpk org>
Date: Tue Oct 24 12:16:45 2017 +0530
application: Port to bjb-application
The class isn't derivable, so there is no point of making it private.
Also use G_DECLARE_FINAL_TYPE to reduce lots of boilerplate code.
And to be consistent with gnome coding standard, rename the file
to bjb-application.[ch]
This is a part of effort to clean up codebase and make the code
more maintainable.
https://bugzilla.gnome.org/show_bug.cgi?id=789696
src/bjb-app-menu.c | 2 +-
src/{bjb-bijiben.c => bjb-application.c} | 144 +++++++++++++-----------------
src/{bjb-bijiben.h => bjb-application.h} | 31 ++-----
src/bjb-editor-toolbar.c | 2 +-
src/bjb-main-toolbar.c | 2 +-
src/bjb-main-view.c | 2 +-
src/bjb-main.c | 6 +-
src/bjb-note-view.c | 2 +-
src/bjb-selection-toolbar.c | 2 +-
src/bjb-settings-dialog.c | 4 +-
src/bjb-settings.c | 2 +-
src/bjb-window-base.c | 6 +-
src/meson.build | 2 +-
13 files changed, 86 insertions(+), 121 deletions(-)
---
diff --git a/src/bjb-app-menu.c b/src/bjb-app-menu.c
index c0828e0..f1877a9 100644
--- a/src/bjb-app-menu.c
+++ b/src/bjb-app-menu.c
@@ -19,7 +19,7 @@
#include <glib/gi18n.h>
#include "bjb-app-menu.h"
-#include "bjb-bijiben.h"
+#include "bjb-application.h"
#include "bjb-import-dialog.h"
#include "bjb-main-view.h"
#include "bjb-settings.h"
diff --git a/src/bjb-bijiben.c b/src/bjb-application.c
similarity index 76%
rename from src/bjb-bijiben.c
rename to src/bjb-application.c
index 7a5c2dc..85f0298 100644
--- a/src/bjb-bijiben.c
+++ b/src/bjb-application.c
@@ -2,6 +2,7 @@
* bjb-bijiben.c
* Copyright (C) 2011 Pierre-Yves LUYTEN <py luyten fr>
* Copyright (C) 2017 Iñigo Martínez <inigomartinez gmail com>
+ * Copyright (C) 2017 Mohammed Sadiq <sadiq sadiqpk org>
*
* bijiben is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
@@ -28,14 +29,16 @@
#include <libbiji/libbiji.h>
#include "bjb-app-menu.h"
-#include "bjb-bijiben.h"
+#include "bjb-application.h"
#include "bjb-settings.h"
#include "bjb-main-view.h"
#include "bjb-note-view.h"
#include "bjb-window-base.h"
-struct _BijibenPriv
+struct _BjbApplication
{
+ GtkApplication parent_instance;
+
BijiManager *manager;
BjbSettings *settings;
@@ -47,33 +50,30 @@ struct _BijibenPriv
GQueue files_to_open; // paths
};
+G_DEFINE_TYPE (BjbApplication, bjb_application, GTK_TYPE_APPLICATION)
-G_DEFINE_TYPE (Bijiben, bijiben, GTK_TYPE_APPLICATION);
-
-static void bijiben_new_window_internal (Bijiben *self,
+static void bijiben_new_window_internal (BjbApplication *self,
BijiNoteObj *note);
-static gboolean bijiben_open_path (Bijiben *self,
- gchar *path,
+static gboolean bijiben_open_path (BjbApplication *self,
+ gchar *path,
BjbWindowBase *window);
static void
-on_window_activated_cb (BjbWindowBase *window,
- gboolean available,
- Bijiben *self)
+on_window_activated_cb (BjbWindowBase *window,
+ gboolean available,
+ BjbApplication *self)
{
- BijibenPriv *priv;
GList *l, *next;
- priv = self->priv;
- priv->is_loaded = TRUE;
+ self->is_loaded = TRUE;
- for (l = priv->files_to_open.head; l != NULL; l = next)
+ for (l = self->files_to_open.head; l != NULL; l = next)
{
next = l->next;
if (bijiben_open_path (self, l->data, (available ? window : NULL)))
{
g_free (l->data);
- g_queue_delete_link (&priv->files_to_open, l);
+ g_queue_delete_link (&self->files_to_open, l);
}
}
@@ -81,22 +81,22 @@ on_window_activated_cb (BjbWindowBase *window,
* This implementation is not really safe,
* we might have loaded SOME provider(s)
* but not the default one - more work is needed here */
- if (priv->new_note && g_queue_is_empty (&priv->files_to_open))
+ if (self->new_note && g_queue_is_empty (&self->files_to_open))
{
BijiItem *item;
- priv->new_note = FALSE;
+ self->new_note = FALSE;
item = BIJI_ITEM (biji_manager_note_new (
- priv->manager,
+ self->manager,
NULL,
- bjb_settings_get_default_location (self->priv->settings)));
+ bjb_settings_get_default_location (self->settings)));
bijiben_new_window_internal (self, BIJI_NOTE_OBJ (item));
}
}
static void
-bijiben_new_window_internal (Bijiben *self,
- BijiNoteObj *note)
+bijiben_new_window_internal (BjbApplication *self,
+ BijiNoteObj *note)
{
BjbWindowBase *window;
GList *windows;
@@ -116,16 +116,16 @@ bijiben_new_window_internal (Bijiben *self,
}
static gboolean
-bijiben_open_path (Bijiben *self,
- gchar *path,
- BjbWindowBase *window)
+bijiben_open_path (BjbApplication *self,
+ gchar *path,
+ BjbWindowBase *window)
{
BijiItem *item;
- if (!self->priv->is_loaded)
+ if (!self->is_loaded)
return FALSE;
- item = biji_manager_get_item_at_path (self->priv->manager, path);
+ item = biji_manager_get_item_at_path (self->manager, path);
if (BIJI_IS_NOTE_OBJ (item) || !window)
bijiben_new_window_internal (self, BIJI_NOTE_OBJ (item));
@@ -139,7 +139,7 @@ void
bijiben_new_window_for_note (GApplication *app,
BijiNoteObj *note)
{
- bijiben_new_window_internal (BIJIBEN_APPLICATION (app), note);
+ bijiben_new_window_internal (BJB_APPLICATION (app), note);
}
static void
@@ -161,11 +161,11 @@ bijiben_open (GApplication *application,
gint n_files,
const gchar *hint)
{
- Bijiben *self;
+ BjbApplication *self;
gint i;
gchar *path;
- self = BIJIBEN_APPLICATION (application);
+ self = BJB_APPLICATION (application);
for (i = 0; i < n_files; i++)
{
@@ -173,33 +173,25 @@ bijiben_open (GApplication *application,
if (bijiben_open_path (self, path, NULL))
g_free (path);
else
- g_queue_push_head (&self->priv->files_to_open, path);
+ g_queue_push_head (&self->files_to_open, path);
}
}
static void
-bijiben_init (Bijiben *self)
+bjb_application_init (BjbApplication *self)
{
- BijibenPriv *priv;
-
-
- priv = self->priv =
- G_TYPE_INSTANCE_GET_PRIVATE (self, BIJIBEN_TYPE_APPLICATION, BijibenPriv);
-
- priv->settings = bjb_settings_new ();
- g_queue_init (&priv->files_to_open);
- priv->new_note = FALSE;
- priv->is_loaded = FALSE;
+ self->settings = bjb_settings_new ();
+ g_queue_init (&self->files_to_open);
}
void
-bijiben_import_notes (Bijiben *self, gchar *uri)
+bijiben_import_notes (BjbApplication *self, gchar *uri)
{
- g_debug ("IMPORT to %s", bjb_settings_get_default_location (self->priv->settings));
+ g_debug ("IMPORT to %s", bjb_settings_get_default_location (self->settings));
- biji_manager_import_uri (self->priv->manager,
- bjb_settings_get_default_location (self->priv->settings),
+ biji_manager_import_uri (self->manager,
+ bjb_settings_get_default_location (self->settings),
uri);
}
@@ -258,10 +250,10 @@ manager_ready_cb (GObject *source,
GAsyncResult *res,
gpointer user_data)
{
- Bijiben *self = user_data;
+ BjbApplication *self = user_data;
GError *error = NULL;
- self->priv->manager = biji_manager_new_finish (res, &error);
+ self->manager = biji_manager_new_finish (res, &error);
g_application_release (G_APPLICATION (self));
if (error != NULL)
@@ -277,7 +269,7 @@ manager_ready_cb (GObject *source,
static void
bijiben_startup (GApplication *application)
{
- Bijiben *self;
+ BjbApplication *self;
gchar *storage_path, *default_color;
GFile *storage;
GError *error;
@@ -285,8 +277,8 @@ bijiben_startup (GApplication *application)
GdkRGBA color = {0,0,0,0};
- G_APPLICATION_CLASS (bijiben_parent_class)->startup (application);
- self = BIJIBEN_APPLICATION (application);
+ G_APPLICATION_CLASS (bjb_application_parent_class)->startup (application);
+ self = BJB_APPLICATION (application);
error = NULL;
bjb_apply_style ();
@@ -297,13 +289,13 @@ bijiben_startup (GApplication *application)
storage = g_file_new_for_path (storage_path);
// Create the bijiben dir to ensure.
- self->priv->first_run = TRUE;
+ self->first_run = TRUE;
g_file_make_directory (storage, NULL, &error);
// If fails it's not the first run
if (error && error->code == G_IO_ERROR_EXISTS)
{
- self->priv->first_run = FALSE;
+ self->first_run = FALSE;
g_error_free (error);
}
@@ -313,20 +305,14 @@ bijiben_startup (GApplication *application)
g_error_free (error);
}
- else
- {
- self->priv->first_run = TRUE;
- }
-
-
- g_object_get (self->priv->settings, "color", &default_color, NULL);
+ g_object_get (self->settings, "color", &default_color, NULL);
gdk_rgba_parse (&color, default_color);
g_application_hold (application);
biji_manager_new_async (storage, &color, manager_ready_cb, self);
/* Automatic imports on startup */
- if (self->priv->first_run == TRUE)
+ if (self->first_run == TRUE)
{
path = g_build_filename (g_get_user_data_dir (), "tomboy", NULL);
uri = g_filename_to_uri (path, NULL, NULL);
@@ -351,7 +337,7 @@ bijiben_application_local_command_line (GApplication *application,
gchar ***arguments,
gint *exit_status)
{
- Bijiben *self;
+ BjbApplication *self;
gboolean version = FALSE;
gchar **remaining = NULL;
GOptionContext *context;
@@ -362,7 +348,7 @@ bijiben_application_local_command_line (GApplication *application,
const GOptionEntry options[] = {
{ "version", 0, 0, G_OPTION_ARG_NONE, &version,
N_("Show the application’s version"), NULL},
- { "new-note", 0, 0, G_OPTION_ARG_NONE, &BIJIBEN_APPLICATION(application)->priv->new_note,
+ { "new-note", 0, 0, G_OPTION_ARG_NONE, &BJB_APPLICATION(application)->new_note,
N_("Create a new note"), NULL},
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &remaining,
NULL, N_("[FILE…]") },
@@ -413,15 +399,15 @@ bijiben_application_local_command_line (GApplication *application,
goto out;
}
- self = BIJIBEN_APPLICATION (application);
+ self = BJB_APPLICATION (application);
- if (!self->priv->new_note && remaining != NULL)
+ if (!self->new_note && remaining != NULL)
{
gchar **args;
for (args = remaining; *args; args++)
if (!bijiben_open_path (self, *args, NULL))
- g_queue_push_head (&self->priv->files_to_open, g_strdup (*args));
+ g_queue_push_head (&self->files_to_open, g_strdup (*args));
}
out:
@@ -434,18 +420,18 @@ bijiben_application_local_command_line (GApplication *application,
static void
bijiben_finalize (GObject *object)
{
- Bijiben *self = BIJIBEN_APPLICATION (object);
+ BjbApplication *self = BJB_APPLICATION (object);
- g_clear_object (&self->priv->manager);
- g_clear_object (&self->priv->settings);
- g_queue_foreach (&self->priv->files_to_open, (GFunc) g_free, NULL);
- g_queue_clear (&self->priv->files_to_open);
+ g_clear_object (&self->manager);
+ g_clear_object (&self->settings);
+ g_queue_foreach (&self->files_to_open, (GFunc) g_free, NULL);
+ g_queue_clear (&self->files_to_open);
- G_OBJECT_CLASS (bijiben_parent_class)->finalize (object);
+ G_OBJECT_CLASS (bjb_application_parent_class)->finalize (object);
}
static void
-bijiben_class_init (BijibenClass *klass)
+bjb_application_class_init (BjbApplicationClass *klass)
{
GApplicationClass *aclass = G_APPLICATION_CLASS (klass);
GObjectClass *oclass = G_OBJECT_CLASS (klass);
@@ -456,23 +442,21 @@ bijiben_class_init (BijibenClass *klass)
aclass->local_command_line = bijiben_application_local_command_line;
oclass->finalize = bijiben_finalize;
-
- g_type_class_add_private (klass, sizeof (BijibenPriv));
}
-Bijiben *
-bijiben_new (void)
+BjbApplication *
+bjb_application_new (void)
{
- return g_object_new (BIJIBEN_TYPE_APPLICATION,
+ return g_object_new (BJB_TYPE_APPLICATION,
"application-id", "org.gnome.bijiben",
"flags", G_APPLICATION_HANDLES_OPEN,
NULL);
}
BijiManager *
-bijiben_get_manager(Bijiben *self)
+bijiben_get_manager(BjbApplication *self)
{
- return self->priv->manager ;
+ return self->manager;
}
const gchar *
@@ -483,5 +467,5 @@ bijiben_get_bijiben_dir (void)
BjbSettings * bjb_app_get_settings(gpointer application)
{
- return BIJIBEN_APPLICATION(application)->priv->settings ;
+ return BJB_APPLICATION(application)->settings;
}
diff --git a/src/bjb-bijiben.h b/src/bjb-application.h
similarity index 52%
rename from src/bjb-bijiben.h
rename to src/bjb-application.h
index 731a9aa..31d17fd 100644
--- a/src/bjb-bijiben.h
+++ b/src/bjb-application.h
@@ -2,6 +2,7 @@
/*
* bijiben.h
* Copyright (C) Pierre-Yves LUYTEN 2011 <py luyten fr>
+ * Copyright (C) 2017 Mohammed Sadiq <sadiq sadiqpk org>
*
* bijiben is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
@@ -27,42 +28,22 @@
G_BEGIN_DECLS
-#define BIJIBEN_TYPE_APPLICATION (bijiben_get_type ())
-#define BIJIBEN_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), BIJIBEN_TYPE_APPLICATION,
Bijiben))
-#define BIJIBEN_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), BIJIBEN_TYPE_APPLICATION,
BijibenClass))
-#define BIJIBEN_IS_APPLICATION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), BIJIBEN_TYPE_APPLICATION))
-#define BIJIBEN_IS_APPLICATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), BIJIBEN_TYPE_APPLICATION))
-#define BIJIBEN_APPLICATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BIJIBEN_TYPE_APPLICATION,
BijibenClass))
+#define BJB_TYPE_APPLICATION (bjb_application_get_type ())
-typedef struct _BijibenClass BijibenClass;
-typedef struct _Bijiben Bijiben;
+G_DECLARE_FINAL_TYPE (BjbApplication, bjb_application, BJB, APPLICATION, GtkApplication)
-typedef struct _BijibenPriv BijibenPriv;
-
-struct _BijibenClass
-{
- GtkApplicationClass parent_class;
-};
-
-struct _Bijiben
-{
- GtkApplication parent_instance;
- BijibenPriv *priv;
-};
-
-GType bijiben_get_type (void) G_GNUC_CONST;
-Bijiben *bijiben_new (void);
+BjbApplication *bjb_application_new (void);
// Accessors
const gchar *bijiben_get_bijiben_dir (void);
-BijiManager * bijiben_get_manager(Bijiben *self);
+BijiManager * bijiben_get_manager(BjbApplication *self);
BjbSettings * bjb_app_get_settings(gpointer application);
// Windows
void bijiben_new_window_for_note (GApplication *app, BijiNoteObj *note);
-void bijiben_import_notes (Bijiben *self, gchar *uri);
+void bijiben_import_notes (BjbApplication *self, gchar *uri);
G_END_DECLS
diff --git a/src/bjb-editor-toolbar.c b/src/bjb-editor-toolbar.c
index ad8a29f..e791b63 100644
--- a/src/bjb-editor-toolbar.c
+++ b/src/bjb-editor-toolbar.c
@@ -24,7 +24,7 @@
#include <gtk/gtk.h>
#include <libbiji/libbiji.h>
-#include "bjb-bijiben.h"
+#include "bjb-application.h"
#include "bjb-editor-toolbar.h"
#include "bjb-window-base.h"
diff --git a/src/bjb-main-toolbar.c b/src/bjb-main-toolbar.c
index f955dd6..9643e8a 100644
--- a/src/bjb-main-toolbar.c
+++ b/src/bjb-main-toolbar.c
@@ -20,7 +20,7 @@
#include <glib/gi18n.h>
#include <libgd/gd.h>
-#include "bjb-bijiben.h"
+#include "bjb-application.h"
#include "bjb-color-button.h"
#include "bjb-main-toolbar.h"
#include "bjb-organize-dialog.h"
diff --git a/src/bjb-main-view.c b/src/bjb-main-view.c
index 7c50d11..c51f003 100644
--- a/src/bjb-main-view.c
+++ b/src/bjb-main-view.c
@@ -21,7 +21,7 @@
#include <libgd/gd-main-view.h>
#include "bjb-app-menu.h"
-#include "bjb-bijiben.h"
+#include "bjb-application.h"
#include "bjb-controller.h"
#include "bjb-load-more-button.h"
#include "bjb-main-toolbar.h"
diff --git a/src/bjb-main.c b/src/bjb-main.c
index 257ad3f..d46b156 100644
--- a/src/bjb-main.c
+++ b/src/bjb-main.c
@@ -21,19 +21,19 @@
#include <gtk/gtk.h>
#include <libbiji/libbiji.h>
-#include "bjb-bijiben.h"
+#include "bjb-application.h"
int
main (int argc, char *argv[])
{
- Bijiben *app;
+ BjbApplication *app;
int status;
bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
- app = bijiben_new ();
+ app = bjb_application_new ();
status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
diff --git a/src/bjb-note-view.c b/src/bjb-note-view.c
index 9943e99..dbe5786 100644
--- a/src/bjb-note-view.c
+++ b/src/bjb-note-view.c
@@ -21,7 +21,7 @@
#include <libbiji/libbiji.h>
#include <libgd/gd.h>
-#include "bjb-bijiben.h"
+#include "bjb-application.h"
#include "bjb-editor-toolbar.h"
#include "bjb-main-view.h"
#include "bjb-note-view.h"
diff --git a/src/bjb-selection-toolbar.c b/src/bjb-selection-toolbar.c
index df19c15..2f2fce9 100644
--- a/src/bjb-selection-toolbar.c
+++ b/src/bjb-selection-toolbar.c
@@ -24,7 +24,7 @@
#include <gtk/gtk.h>
#include <libgd/gd.h>
-#include "bjb-bijiben.h"
+#include "bjb-application.h"
#include "bjb-color-button.h"
#include "bjb-main-view.h"
#include "bjb-organize-dialog.h"
diff --git a/src/bjb-settings-dialog.c b/src/bjb-settings-dialog.c
index 6d6c192..a480cf4 100644
--- a/src/bjb-settings-dialog.c
+++ b/src/bjb-settings-dialog.c
@@ -22,7 +22,7 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>
-#include "bjb-bijiben.h"
+#include "bjb-application.h"
#include "bjb-color-button.h"
#include "bjb-settings.h"
#include "bjb-settings-dialog.h"
@@ -289,7 +289,7 @@ bjb_settings_dialog_constructed (GObject *object)
self = BJB_SETTINGS_DIALOG (object);
app = g_application_get_default ();
- self->manager = bijiben_get_manager (BIJIBEN_APPLICATION (app));
+ self->manager = bijiben_get_manager (BJB_APPLICATION (app));
self->settings = bjb_app_get_settings (app);
gtk_list_box_set_selection_mode (self->listbox, GTK_SELECTION_NONE);
diff --git a/src/bjb-settings.c b/src/bjb-settings.c
index cb8784e..aed67b4 100644
--- a/src/bjb-settings.c
+++ b/src/bjb-settings.c
@@ -19,7 +19,7 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>
-#include "bjb-bijiben.h"
+#include "bjb-application.h"
#include "bjb-settings.h"
#include "bjb-settings-dialog.h"
diff --git a/src/bjb-window-base.c b/src/bjb-window-base.c
index 8b26c16..ea590da 100644
--- a/src/bjb-window-base.c
+++ b/src/bjb-window-base.c
@@ -7,7 +7,7 @@
#include <libgd/gd.h>
#include "bjb-app-menu.h"
-#include "bjb-bijiben.h"
+#include "bjb-application.h"
#include "bjb-empty-results-box.h"
#include "bjb-window-base.h"
#include "bjb-main-toolbar.h"
@@ -290,7 +290,7 @@ bjb_window_base_constructed (GObject *obj)
priv->entry = NULL ;
priv->controller = bjb_controller_new
- (bijiben_get_manager (BIJIBEN_APPLICATION(g_application_get_default())),
+ (bijiben_get_manager (BJB_APPLICATION(g_application_get_default())),
GTK_WINDOW (obj),
priv->entry );
@@ -585,7 +585,7 @@ bjb_window_base_get_view_type (BjbWindowBase *win)
BijiManager *
bjb_window_base_get_manager(GtkWidget * win)
{
- return bijiben_get_manager (BIJIBEN_APPLICATION (g_application_get_default()));
+ return bijiben_get_manager (BJB_APPLICATION (g_application_get_default()));
}
void
diff --git a/src/meson.build b/src/meson.build
index 9e5eeb3..9d2af90 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -2,7 +2,7 @@ subdir('libbiji')
sources = files(
'bjb-app-menu.c',
- 'bjb-bijiben.c',
+ 'bjb-application.c',
'bjb-color-button.c',
'bjb-controller.c',
'bjb-debug.c',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]