1 /*===========================================================================
2 *
3 *                            PUBLIC DOMAIN NOTICE
4 *               National Center for Biotechnology Information
5 *
6 *  This software/database is a "United States Government Work" under the
7 *  terms of the United States Copyright Act.  It was written as part of
8 *  the author's official duties as a United States Government employee and
9 *  thus cannot be copyrighted.  This software/database is freely available
10 *  to the public for use. The National Library of Medicine and the U.S.
11 *  Government have not placed any restriction on its use or reproduction.
12 *
13 *  Although all reasonable efforts have been taken to ensure the accuracy
14 *  and reliability of the software and data, the NLM and the U.S.
15 *  Government do not and cannot warrant the performance or results that
16 *  may be obtained by using this software or data. The NLM and the U.S.
17 *  Government disclaim all warranties, express or implied, including
18 *  warranties of performance, merchantability or fitness for any particular
19 *  purpose.
20 *
21 *  Please cite the author in any work or product based on this material.
22 *
23 * ===========================================================================
24 *
25 */
26 
27 #include "sraconfigmodel.h"
28 #include "../vdb-config/vdb-config-model.hpp"
29 
30 #include <kfg/config.h>
31 
32 #include <QMessageBox>
33 #include <string>
34 
35 static
translate_state(ESetRootState state)36 RootState translate_state ( ESetRootState state )
37 {
38     switch ( state )
39     {
40     case eSetRootState_OK:
41         return RootState_OK;             // successfully changed repository root
42     case eSetRootState_NotChanged:
43         return RootState_NotChanged;     // the new path is the same as the old one
44     case eSetRootState_NotUnique:
45         return RootState_NotUnique;      // there is another repository with the same root
46     case eSetRootState_MkdirFail:
47         return RootState_MkdirFail;      // failed to make new repository directory
48     case eSetRootState_NewPathEmpty:
49         return RootState_NewPathEmpty;   // new repository directory path is not empty
50     case eSetRootState_NewDirNotEmpty:
51         return RootState_NewDirNotEmpty; // new repository directory is not empty
52     case eSetRootState_NewNotDir:
53         return RootState_NewNotDir;      // new repository exists and is not a directory
54     case eSetRootState_OldNotEmpty:
55         return RootState_OldNotEmpty;    // old repository is not empty
56     case eSetRootState_Error:
57         return RootState_Error;          // some unusual error happened
58     }
59 }
60 
commit()61 bool SRAConfigModel::commit()
62 {
63     return model . commit ();
64 }
65 
config_changed()66 bool SRAConfigModel :: config_changed ()
67 {
68     return model . get_config_changed ();
69 }
70 
71 
path_exists(std::string & path)72 bool SRAConfigModel :: path_exists ( std :: string &path )
73 {
74     return model . does_path_exist ( path );
75 }
76 
create_directory(const KNgcObj * ngc)77 void SRAConfigModel :: create_directory ( const KNgcObj *ngc )
78 {
79     model . mkdir ( ngc );
80 }
81 
reload()82 void SRAConfigModel :: reload ()
83 {
84     model . reload ();
85 }
86 
87 // cache
global_cache_enabled()88 bool SRAConfigModel :: global_cache_enabled ()
89 {
90     return model . is_global_cache_enabled ();
91 }
92 
user_cache_enabled()93 bool SRAConfigModel :: user_cache_enabled ()
94 {
95     return model . is_user_cache_enabled ();
96 }
97 
set_global_cache_enabled(bool enabled)98 void SRAConfigModel :: set_global_cache_enabled ( bool enabled )
99 {
100     model . set_global_cache_enabled ( enabled );
101 }
102 
set_user_cache_enabled(bool enabled)103 void SRAConfigModel :: set_user_cache_enabled ( bool enabled )
104 {
105     model . set_user_cache_enabled ( enabled );
106 }
107 
108 // network
remote_enabled()109 bool SRAConfigModel :: remote_enabled ()
110 {
111     return model . is_remote_enabled ();
112 }
113 
set_remote_enabled(bool enabled)114 void SRAConfigModel :: set_remote_enabled ( bool enabled )
115 {
116     model . set_remote_enabled ( enabled );
117 }
118 
site_enabled()119 bool SRAConfigModel :: site_enabled ()
120 {
121     return model . is_site_enabled ();
122 }
123 
set_site_enabled(bool enabled)124 void SRAConfigModel :: set_site_enabled ( bool enabled )
125 {
126     model . set_site_enabled ( enabled );
127 }
128 
allow_all_certs()129 bool SRAConfigModel :: allow_all_certs ()
130 {
131     return model . allow_all_certs ();
132 }
133 
set_allow_all_certs(bool allow)134 void SRAConfigModel :: set_allow_all_certs ( bool allow )
135 {
136     model . set_allow_all_certs ( allow );
137 }
138 
139 // ngc
import_ngc(const std::string path,const KNgcObj * ngc,uint32_t permissions,uint32_t * rslt_flags)140 bool SRAConfigModel :: import_ngc ( const std :: string path, const KNgcObj *ngc, uint32_t permissions, uint32_t *rslt_flags )
141 {
142     return model . import_ngc ( path, ngc, permissions, rslt_flags );
143 }
144 
get_ngc_obj_id(const KNgcObj * ngc,uint32_t * id)145 bool SRAConfigModel :: get_ngc_obj_id ( const KNgcObj *ngc, uint32_t *id )
146 {
147     return model . get_id_of_ngc_obj ( ngc, id );
148 }
149 
get_ngc_root(std::string & dir,const KNgcObj * ngc)150 std :: string SRAConfigModel :: get_ngc_root ( std :: string &dir, const KNgcObj *ngc )
151 {
152     return model . get_ngc_root ( dir, ngc );
153 }
154 
155 // proxy
proxy_enabled()156 bool SRAConfigModel :: proxy_enabled ()
157 {
158     return model . is_http_proxy_enabled ();
159 }
160 
set_proxy_enabled(bool enabled)161 void SRAConfigModel :: set_proxy_enabled ( bool enabled )
162 {
163     model . set_http_proxy_enabled ( enabled );
164 }
165 
get_proxy_path()166 std :: string SRAConfigModel :: get_proxy_path ()
167 {
168     return model . get_http_proxy_path ();
169 }
170 
set_proxy_path(const std::string & path)171 void SRAConfigModel :: set_proxy_path ( const std :: string &path )
172 {
173     model . set_http_proxy_path ( path );
174 }
175 
proxy_priority()176 bool SRAConfigModel :: proxy_priority ()
177 {
178     return model . has_http_proxy_env_higher_priority ();
179 }
180 
set_proxy_priority(bool priority)181 void SRAConfigModel :: set_proxy_priority ( bool priority )
182 {
183     model . set_http_proxy_env_higher_priority ( priority );
184 }
185 
186 // settings
get_current_path()187 std :: string SRAConfigModel :: get_current_path ()
188 {
189     return model . get_current_dir ();
190 }
191 
get_home_path()192 std :: string SRAConfigModel :: get_home_path ()
193 {
194     return model . get_home_dir ();
195 }
196 
get_public_path()197 std :: string SRAConfigModel :: get_public_path ()
198 {
199     return model . get_public_location ();
200 }
201 
set_public_path(std::string & path,bool flushOld,bool reuseNew)202 RootState SRAConfigModel :: set_public_path ( std :: string &path, bool flushOld, bool reuseNew )
203 {
204     return translate_state ( model . set_public_location ( flushOld, path, reuseNew ) );
205 }
206 
get_user_default_path()207 std :: string SRAConfigModel :: get_user_default_path ()
208 {
209     return model . get_user_default_dir ();
210 }
211 
set_user_default_path(const char * path)212 void SRAConfigModel :: set_user_default_path ( const char *path )
213 {
214     model . set_user_default_dir ( path );
215 }
216 
217 // workspace
218 
site_workspace_exists()219 bool SRAConfigModel :: site_workspace_exists ()
220 {
221     return model . does_site_repo_exist ();
222 }
223 
configure_workspace(const std::string & path,bool reuseNew)224 RootState SRAConfigModel :: configure_workspace ( const std :: string &path, bool reuseNew )
225 {
226     return translate_state ( model . prepare_repo_directory ( path, reuseNew ) );
227 }
228 
workspace_count()229 uint32_t SRAConfigModel :: workspace_count ()
230 {
231     return model . get_repo_count ();
232 }
233 
get_workspace_id(const std::string & name)234 int32_t SRAConfigModel :: get_workspace_id ( const std :: string &name )
235 {
236     return model . get_repo_id ( name );
237 }
238 
get_workspace_name(uint32_t id)239 std :: string SRAConfigModel :: get_workspace_name ( uint32_t id )
240 {
241     return model . get_repo_name ( id );
242 }
243 
get_workspace_path(uint32_t id)244 std :: string SRAConfigModel :: get_workspace_path ( uint32_t id )
245 {
246     return model . get_repo_location ( id );
247 }
248 
set_workspace_path(const std::string & path,uint32_t id,bool flushOld,bool reuseNew)249 RootState SRAConfigModel :: set_workspace_path ( const std :: string & path, uint32_t id, bool flushOld, bool reuseNew )
250 {
251     return translate_state ( model . set_repo_location ( id, flushOld, path, reuseNew ) );
252 }
253 
SRAConfigModel(vdbconf_model & config_model,QObject * parent)254 SRAConfigModel :: SRAConfigModel ( vdbconf_model &config_model, QObject *parent )
255     : QObject ( parent )
256     , model ( config_model )
257 {
258 }
259 
260