LCOV - code coverage report
Current view: top level - gui/source - gui_file_db_manager.c (source / functions) Hit Total Coverage
Test: crystal-facet-uml_v1.57.0_covts Lines: 0 43 0.0 %
Date: 2024-04-07 11:14:42 Functions: 0 3 0.0 %

          Line data    Source code
       1             : /* File: gui_file_db_manager.c; Copyright and License: see below */
       2             : 
       3             : #include "gui_file_db_manager.h"
       4             : #include "u8/u8_error_info.h"
       5             : #include "u8/u8_trace.h"
       6             : #include <gtk/gtk.h>
       7             : #include <stdio.h>
       8             : #include <stdbool.h>
       9             : #include <assert.h>
      10             : 
      11           0 : void gui_file_db_manager_init( gui_file_db_manager_t *this_,
      12             :                                ctrl_controller_t *controller,
      13             :                                io_data_file_t *data_file,
      14             :                                gui_simple_message_to_user_t *message_to_user )
      15             : {
      16           0 :     U8_TRACE_BEGIN();
      17           0 :     assert( NULL != controller );
      18           0 :     assert( NULL != data_file );
      19           0 :     assert( NULL != message_to_user );
      20             : 
      21           0 :     (*this_).controller = controller;
      22           0 :     (*this_).data_file = data_file;
      23           0 :     (*this_).message_to_user = message_to_user;
      24             : 
      25           0 :     U8_TRACE_END();
      26           0 : }
      27             : 
      28           0 : void gui_file_db_manager_destroy( gui_file_db_manager_t *this_ )
      29             : {
      30           0 :     U8_TRACE_BEGIN();
      31             : 
      32           0 :     (*this_).controller = NULL;
      33           0 :     (*this_).data_file = NULL;
      34           0 :     (*this_).message_to_user = NULL;
      35             : 
      36           0 :     U8_TRACE_END();
      37           0 : }
      38             : 
      39           0 : u8_error_t gui_file_db_manager_use_db( gui_file_db_manager_t *this_, const char *filename )
      40             : {
      41           0 :     U8_TRACE_BEGIN();
      42             : 
      43           0 :     if ( io_data_file_is_open( (*this_).data_file ) )
      44             :     {
      45           0 :         const u8_error_t close_err = io_data_file_close( (*this_).data_file );
      46           0 :         if ( close_err != U8_ERROR_NONE )
      47             :         {
      48           0 :             U8_LOG_ERROR( "Closing the database was not possible" );
      49           0 :             U8_TRACE_INFO_STR( "Closing the database was not possible:", io_data_file_get_filename_const( (*this_).data_file ) );
      50             :         }
      51             :     }
      52             : 
      53             :     /* react immediately */
      54           0 :     gui_simple_message_to_user_show_message_with_name( (*this_).message_to_user,
      55             :                                                        GUI_SIMPLE_MESSAGE_TYPE_INFO,
      56             :                                                        GUI_SIMPLE_MESSAGE_CONTENT_LOADING_WAIT,
      57             :                                                        filename
      58             :                                                      );
      59           0 :     bool events_handled = true;
      60           0 :     for ( uint_fast8_t max_loop = 40; events_handled && ( max_loop > 0 ); max_loop-- )
      61             :     {
      62           0 :         events_handled = g_main_context_iteration( NULL, /*may_block*/ FALSE );
      63             :     }
      64             : 
      65             :     u8_error_info_t err_info;
      66           0 :     const u8_error_t error = io_data_file_open_writeable ( (*this_).data_file, filename, &err_info );
      67             : 
      68           0 :     if ( U8_ERROR_NONE == error )
      69             :     {
      70             :         /* ensure that at least one diagram exists - otherwise the first window looks a bit empty */
      71             :         ctrl_diagram_controller_t *diag_control;
      72           0 :         diag_control = ctrl_controller_get_diagram_control_ptr( (*this_).controller );
      73           0 :         ctrl_diagram_controller_create_root_diagram_if_not_exists( diag_control,
      74             :                                                                    DATA_DIAGRAM_TYPE_UML_USE_CASE_DIAGRAM,
      75             :                                                                    "New Overview",
      76             :                                                                    NULL
      77             :                                                                  );
      78             : 
      79             :         /* remove the loading message if not overwritten: */
      80           0 :         if ( GUI_SIMPLE_MESSAGE_TYPE_INFO == gui_simple_message_to_user_get_type_id( (*this_).message_to_user ) )
      81             :         {
      82           0 :             gui_simple_message_to_user_hide( (*this_).message_to_user );
      83             :         }
      84             :     }
      85           0 :     else if ( U8_ERROR_NO_DB == error )
      86             :     {
      87             :         /* Most likely the parent directory of database is read only */
      88           0 :         gui_simple_message_to_user_show_message_with_name( (*this_).message_to_user,
      89             :                                                            GUI_SIMPLE_MESSAGE_TYPE_ERROR,
      90             :                                                            GUI_SIMPLE_MESSAGE_CONTENT_DB_FILE_NOT_CREATEABLE,
      91             :                                                            filename
      92             :                                                          );
      93             :     }
      94             :     else
      95             :     {
      96           0 :         if ( u8_error_info_is_error( &err_info ) )
      97             :         {
      98           0 :             gui_simple_message_to_user_show_error_info( (*this_).message_to_user, &err_info );
      99             :         }
     100           0 :         else if ( io_data_file_is_open( (*this_).data_file ) )
     101             :         {
     102           0 :             gui_simple_message_to_user_show_message_with_name( (*this_).message_to_user,
     103             :                                                                GUI_SIMPLE_MESSAGE_TYPE_WARNING,
     104             :                                                                GUI_SIMPLE_MESSAGE_CONTENT_DB_FILE_OPENED_WITH_ERROR,
     105             :                                                                filename
     106             :                                                              );
     107             :         }
     108             :         else
     109             :         {
     110           0 :             gui_simple_message_to_user_show_message_with_name( (*this_).message_to_user,
     111             :                                                                GUI_SIMPLE_MESSAGE_TYPE_ERROR,
     112             :                                                                GUI_SIMPLE_MESSAGE_CONTENT_DB_FILE_NOT_OPENED,
     113             :                                                                filename
     114             :                                                              );
     115             :         }
     116             :     }
     117             : 
     118           0 :     U8_TRACE_END_ERR( error );
     119           0 :     return error;
     120             : }
     121             : 
     122             : 
     123             : /*
     124             : Copyright 2016-2024 Andreas Warnke
     125             : 
     126             : Licensed under the Apache License, Version 2.0 (the "License");
     127             : you may not use this file except in compliance with the License.
     128             : You may obtain a copy of the License at
     129             : 
     130             :     http://www.apache.org/licenses/LICENSE-2.0
     131             : 
     132             : Unless required by applicable law or agreed to in writing, software
     133             : distributed under the License is distributed on an "AS IS" BASIS,
     134             : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     135             : See the License for the specific language governing permissions and
     136             : limitations under the License.
     137             : */

Generated by: LCOV version 1.16