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