gimp/app/gimpconsoleapp.c

85 lines
2.4 KiB
C
Raw Normal View History

/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
*
* gimpapp.c
* Copyright (C) 2021 Niels De Graef <nielsdegraef@gmail.com>
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <https://www.gnu.org/licenses/>.
*/
#include <config.h>
app: cleanup MR !734. - app_activate_callback() moved with other private functions. - Removing the `if (app)` test in app_activate_callback() as we don't set it to NULL anymore. The app variable is always set. - As a consequence of the previous point, change signature of app_exit_after_callback() which doesn't have to change the value of app anymore. - Don't emit direcly the "exit" signal from app_activate_callback(). We must call `gimp_exit (gimp, TRUE);` instead, which does more than just emitting this signal. It also takes care of cleaning any remaining images without a display. If we don't do this, we are leaking GeglBuffer when opening images from command lines while quitting immediately with --quit. - Get rid of gimp_core_app_set_values() which was completely bypassing the fact that all the properties of a GimpCoreApp were construct-only. Instead make these proper properties. I use a trick used in other interface, creating a gimp_container_view_install_properties() which is called from child classes. The point of GimpCoreApp is not just to share a common interface, it's rather to weakly simulate some kind of multi-inheritance in GObject. Since we want both GimpApp and GimpConsoleApp to inherit from a same parent class while we also want them to inherit either from GtkApplication and GApplication respectively (yet without linking to GTK in this second case), we are stuck as far as normal GObject inheritance goes. This is why we use an interface to which we add a private struct through a GQuark trick. We want the property settings and function implementations to also be part of this shared code. - Get rid of all the abstract methods of GimpCoreApp of the form get_*(). These are useless as we don't expect these to have different implementation depending on the actual child class. Once again, our main goal was to simulate multiple inheritance rather than actually have an interface with various implementations. - Make "no-splash" a property of GimpApp, because it's cleaner this way. - Fix gimp_core_app_private_finalize(). - don't use #pragma once, it's not standard. Just use include guards. - Fix includes: order was wrong, include from the source, not other headers, etc. - Clean various other details, coding styles, fix several more bugs and more…
2022-10-07 02:44:06 +08:00
#include <gio/gio.h>
#include "libgimpbase/gimpbase.h"
app: cleanup MR !734. - app_activate_callback() moved with other private functions. - Removing the `if (app)` test in app_activate_callback() as we don't set it to NULL anymore. The app variable is always set. - As a consequence of the previous point, change signature of app_exit_after_callback() which doesn't have to change the value of app anymore. - Don't emit direcly the "exit" signal from app_activate_callback(). We must call `gimp_exit (gimp, TRUE);` instead, which does more than just emitting this signal. It also takes care of cleaning any remaining images without a display. If we don't do this, we are leaking GeglBuffer when opening images from command lines while quitting immediately with --quit. - Get rid of gimp_core_app_set_values() which was completely bypassing the fact that all the properties of a GimpCoreApp were construct-only. Instead make these proper properties. I use a trick used in other interface, creating a gimp_container_view_install_properties() which is called from child classes. The point of GimpCoreApp is not just to share a common interface, it's rather to weakly simulate some kind of multi-inheritance in GObject. Since we want both GimpApp and GimpConsoleApp to inherit from a same parent class while we also want them to inherit either from GtkApplication and GApplication respectively (yet without linking to GTK in this second case), we are stuck as far as normal GObject inheritance goes. This is why we use an interface to which we add a private struct through a GQuark trick. We want the property settings and function implementations to also be part of this shared code. - Get rid of all the abstract methods of GimpCoreApp of the form get_*(). These are useless as we don't expect these to have different implementation depending on the actual child class. Once again, our main goal was to simulate multiple inheritance rather than actually have an interface with various implementations. - Make "no-splash" a property of GimpApp, because it's cleaner this way. - Fix gimp_core_app_private_finalize(). - don't use #pragma once, it's not standard. Just use include guards. - Fix includes: order was wrong, include from the source, not other headers, etc. - Clean various other details, coding styles, fix several more bugs and more…
2022-10-07 02:44:06 +08:00
#include "core/core-types.h"
#include "core/gimp.h"
#include "gimpconsoleapp.h"
#include "gimpcoreapp.h"
struct _GimpConsoleApp
{
GApplication parent_instance;
};
G_DEFINE_TYPE_WITH_CODE (GimpConsoleApp, gimp_console_app, G_TYPE_APPLICATION,
G_IMPLEMENT_INTERFACE (GIMP_TYPE_CORE_APP, NULL))
static void
gimp_console_app_class_init (GimpConsoleAppClass *klass)
{
GObjectClass *gobj_class = G_OBJECT_CLASS (klass);
app: cleanup MR !734. - app_activate_callback() moved with other private functions. - Removing the `if (app)` test in app_activate_callback() as we don't set it to NULL anymore. The app variable is always set. - As a consequence of the previous point, change signature of app_exit_after_callback() which doesn't have to change the value of app anymore. - Don't emit direcly the "exit" signal from app_activate_callback(). We must call `gimp_exit (gimp, TRUE);` instead, which does more than just emitting this signal. It also takes care of cleaning any remaining images without a display. If we don't do this, we are leaking GeglBuffer when opening images from command lines while quitting immediately with --quit. - Get rid of gimp_core_app_set_values() which was completely bypassing the fact that all the properties of a GimpCoreApp were construct-only. Instead make these proper properties. I use a trick used in other interface, creating a gimp_container_view_install_properties() which is called from child classes. The point of GimpCoreApp is not just to share a common interface, it's rather to weakly simulate some kind of multi-inheritance in GObject. Since we want both GimpApp and GimpConsoleApp to inherit from a same parent class while we also want them to inherit either from GtkApplication and GApplication respectively (yet without linking to GTK in this second case), we are stuck as far as normal GObject inheritance goes. This is why we use an interface to which we add a private struct through a GQuark trick. We want the property settings and function implementations to also be part of this shared code. - Get rid of all the abstract methods of GimpCoreApp of the form get_*(). These are useless as we don't expect these to have different implementation depending on the actual child class. Once again, our main goal was to simulate multiple inheritance rather than actually have an interface with various implementations. - Make "no-splash" a property of GimpApp, because it's cleaner this way. - Fix gimp_core_app_private_finalize(). - don't use #pragma once, it's not standard. Just use include guards. - Fix includes: order was wrong, include from the source, not other headers, etc. - Clean various other details, coding styles, fix several more bugs and more…
2022-10-07 02:44:06 +08:00
gobj_class->get_property = gimp_core_app_get_property;
gobj_class->set_property = gimp_core_app_set_property;
gimp_core_app_install_properties (gobj_class);
}
static void
gimp_console_app_init (GimpConsoleApp *self)
{
}
/* public functions */
GApplication *
gimp_console_app_new (Gimp *gimp,
gboolean quit,
gboolean as_new,
const char **filenames,
const char *batch_interpreter,
const char **batch_commands)
{
GimpConsoleApp *app;
app: cleanup MR !734. - app_activate_callback() moved with other private functions. - Removing the `if (app)` test in app_activate_callback() as we don't set it to NULL anymore. The app variable is always set. - As a consequence of the previous point, change signature of app_exit_after_callback() which doesn't have to change the value of app anymore. - Don't emit direcly the "exit" signal from app_activate_callback(). We must call `gimp_exit (gimp, TRUE);` instead, which does more than just emitting this signal. It also takes care of cleaning any remaining images without a display. If we don't do this, we are leaking GeglBuffer when opening images from command lines while quitting immediately with --quit. - Get rid of gimp_core_app_set_values() which was completely bypassing the fact that all the properties of a GimpCoreApp were construct-only. Instead make these proper properties. I use a trick used in other interface, creating a gimp_container_view_install_properties() which is called from child classes. The point of GimpCoreApp is not just to share a common interface, it's rather to weakly simulate some kind of multi-inheritance in GObject. Since we want both GimpApp and GimpConsoleApp to inherit from a same parent class while we also want them to inherit either from GtkApplication and GApplication respectively (yet without linking to GTK in this second case), we are stuck as far as normal GObject inheritance goes. This is why we use an interface to which we add a private struct through a GQuark trick. We want the property settings and function implementations to also be part of this shared code. - Get rid of all the abstract methods of GimpCoreApp of the form get_*(). These are useless as we don't expect these to have different implementation depending on the actual child class. Once again, our main goal was to simulate multiple inheritance rather than actually have an interface with various implementations. - Make "no-splash" a property of GimpApp, because it's cleaner this way. - Fix gimp_core_app_private_finalize(). - don't use #pragma once, it's not standard. Just use include guards. - Fix includes: order was wrong, include from the source, not other headers, etc. - Clean various other details, coding styles, fix several more bugs and more…
2022-10-07 02:44:06 +08:00
app = g_object_new (GIMP_TYPE_CONSOLE_APP,
"application-id", GIMP_APPLICATION_ID,
#if GLIB_CHECK_VERSION(2,74,0)
"flags", G_APPLICATION_DEFAULT_FLAGS | G_APPLICATION_NON_UNIQUE,
#else
"flags", G_APPLICATION_FLAGS_NONE | G_APPLICATION_NON_UNIQUE,
#endif
app: cleanup MR !734. - app_activate_callback() moved with other private functions. - Removing the `if (app)` test in app_activate_callback() as we don't set it to NULL anymore. The app variable is always set. - As a consequence of the previous point, change signature of app_exit_after_callback() which doesn't have to change the value of app anymore. - Don't emit direcly the "exit" signal from app_activate_callback(). We must call `gimp_exit (gimp, TRUE);` instead, which does more than just emitting this signal. It also takes care of cleaning any remaining images without a display. If we don't do this, we are leaking GeglBuffer when opening images from command lines while quitting immediately with --quit. - Get rid of gimp_core_app_set_values() which was completely bypassing the fact that all the properties of a GimpCoreApp were construct-only. Instead make these proper properties. I use a trick used in other interface, creating a gimp_container_view_install_properties() which is called from child classes. The point of GimpCoreApp is not just to share a common interface, it's rather to weakly simulate some kind of multi-inheritance in GObject. Since we want both GimpApp and GimpConsoleApp to inherit from a same parent class while we also want them to inherit either from GtkApplication and GApplication respectively (yet without linking to GTK in this second case), we are stuck as far as normal GObject inheritance goes. This is why we use an interface to which we add a private struct through a GQuark trick. We want the property settings and function implementations to also be part of this shared code. - Get rid of all the abstract methods of GimpCoreApp of the form get_*(). These are useless as we don't expect these to have different implementation depending on the actual child class. Once again, our main goal was to simulate multiple inheritance rather than actually have an interface with various implementations. - Make "no-splash" a property of GimpApp, because it's cleaner this way. - Fix gimp_core_app_private_finalize(). - don't use #pragma once, it's not standard. Just use include guards. - Fix includes: order was wrong, include from the source, not other headers, etc. - Clean various other details, coding styles, fix several more bugs and more…
2022-10-07 02:44:06 +08:00
"gimp", gimp,
"filenames", filenames,
"as-new", as_new,
app: cleanup MR !734. - app_activate_callback() moved with other private functions. - Removing the `if (app)` test in app_activate_callback() as we don't set it to NULL anymore. The app variable is always set. - As a consequence of the previous point, change signature of app_exit_after_callback() which doesn't have to change the value of app anymore. - Don't emit direcly the "exit" signal from app_activate_callback(). We must call `gimp_exit (gimp, TRUE);` instead, which does more than just emitting this signal. It also takes care of cleaning any remaining images without a display. If we don't do this, we are leaking GeglBuffer when opening images from command lines while quitting immediately with --quit. - Get rid of gimp_core_app_set_values() which was completely bypassing the fact that all the properties of a GimpCoreApp were construct-only. Instead make these proper properties. I use a trick used in other interface, creating a gimp_container_view_install_properties() which is called from child classes. The point of GimpCoreApp is not just to share a common interface, it's rather to weakly simulate some kind of multi-inheritance in GObject. Since we want both GimpApp and GimpConsoleApp to inherit from a same parent class while we also want them to inherit either from GtkApplication and GApplication respectively (yet without linking to GTK in this second case), we are stuck as far as normal GObject inheritance goes. This is why we use an interface to which we add a private struct through a GQuark trick. We want the property settings and function implementations to also be part of this shared code. - Get rid of all the abstract methods of GimpCoreApp of the form get_*(). These are useless as we don't expect these to have different implementation depending on the actual child class. Once again, our main goal was to simulate multiple inheritance rather than actually have an interface with various implementations. - Make "no-splash" a property of GimpApp, because it's cleaner this way. - Fix gimp_core_app_private_finalize(). - don't use #pragma once, it's not standard. Just use include guards. - Fix includes: order was wrong, include from the source, not other headers, etc. - Clean various other details, coding styles, fix several more bugs and more…
2022-10-07 02:44:06 +08:00
"quit", quit,
"batch-interpreter", batch_interpreter,
"batch-commands", batch_commands,
NULL);
return G_APPLICATION (app);
}