Line data Source code
1 : /* File: gui_main.c; Copyright and License: see below */
2 :
3 : #include "gui_main.h"
4 : #include "gui_main_window.h"
5 : #include "gui_window_manager.h"
6 : #include "storage/data_database_reader.h"
7 : #include "meta/meta_info.h"
8 : #include "u8/u8_trace.h"
9 : #include "u8/u8_log.h"
10 : #include "gui_gtk.h"
11 : #include <stdio.h>
12 : #include <stdlib.h>
13 :
14 : static gui_window_manager_t window_manager;
15 :
16 0 : static void gui_main_activate_callback( GtkApplication* app, gpointer user_data )
17 : {
18 0 : U8_TRACE_BEGIN();
19 0 : U8_TRACE_TIMESTAMP();
20 0 : gui_window_manager_t *const win_manager = user_data;
21 0 : assert( win_manager != NULL );
22 :
23 0 : gui_window_manager_open_main_window( win_manager );
24 :
25 0 : U8_TRACE_END();
26 0 : }
27 :
28 : #if (( GTK_MAJOR_VERSION == 4 ) && ( GTK_MINOR_VERSION <= 6 ))
29 : #define G_APPLICATION_DEFAULT_FLAGS (G_APPLICATION_FLAGS_NONE)
30 : #endif /* (( GTK_MAJOR_VERSION == 4 ) && ( GTK_MINOR_VERSION <= 6 )) */
31 :
32 0 : void gui_main ( io_data_file_t *data_file, int argc, char **argv ) {
33 0 : U8_TRACE_BEGIN();
34 0 : U8_TRACE_TIMESTAMP();
35 0 : U8_TRACE_INFO_INT( "sizeof(gui_window_manager_t):", sizeof(gui_window_manager_t) );
36 : /* expect that no gtk_get_micro_version needed for analysis: */
37 0 : U8_LOG_EVENT_INT( "compiled against gtk: ", GTK_MAJOR_VERSION * 1000 + GTK_MINOR_VERSION );
38 0 : U8_LOG_EVENT_INT( "linked against gtk: ", gtk_get_major_version() * 1000 + gtk_get_minor_version() );
39 0 : U8_TRACE_INFO( "initializing gui thread..." );
40 :
41 : /* init */
42 : GtkApplication *const gtk_app
43 0 : = gtk_application_new( META_INFO_APPLICATION_ID_STR, G_APPLICATION_DEFAULT_FLAGS );
44 :
45 0 : gui_window_manager_init( &window_manager, data_file, gtk_app );
46 :
47 0 : g_signal_connect( gtk_app, "activate", G_CALLBACK( gui_main_activate_callback ), &window_manager);
48 :
49 : /* run */
50 0 : U8_LOG_EVENT( "Connecting to a display (if display is remote, this may take some seconds) ..." );
51 0 : int error_code = g_application_run( G_APPLICATION(gtk_app), argc, argv );
52 0 : if ( error_code != 0 )
53 : {
54 0 : U8_LOG_ERROR_INT( "g_application_run:", error_code );
55 : }
56 :
57 : /* destroy */
58 0 : gui_window_manager_destroy( &window_manager );
59 0 : g_object_unref( gtk_app );
60 :
61 0 : U8_TRACE_TIMESTAMP();
62 0 : U8_TRACE_END();
63 0 : }
64 :
65 :
66 : /*
67 : Copyright 2016-2025 Andreas Warnke
68 :
69 : Licensed under the Apache License, Version 2.0 (the "License");
70 : you may not use this file except in compliance with the License.
71 : You may obtain a copy of the License at
72 :
73 : http://www.apache.org/licenses/LICENSE-2.0
74 :
75 : Unless required by applicable law or agreed to in writing, software
76 : distributed under the License is distributed on an "AS IS" BASIS,
77 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
78 : See the License for the specific language governing permissions and
79 : limitations under the License.
80 : */
|