ARB
AW_names_admin.cxx
Go to the documentation of this file.
1 // =============================================================== //
2 // //
3 // File : AW_names_admin.cxx //
4 // Purpose : //
5 // //
6 // Institute of Microbiology (Technical University Munich) //
7 // http://www.arb-home.de/ //
8 // //
9 // =============================================================== //
10 
11 #include "AW_rename.hxx"
12 
13 #include <awt_misc.hxx>
14 #include <awt_sel_boxes.hxx>
15 
16 #include <aw_question.hxx>
17 #include <aw_advice.hxx>
18 #include <aw_edit.hxx>
19 #include <aw_awar.hxx>
20 #include <aw_msg.hxx>
21 #include <aw_root.hxx>
22 
23 #include <arb_file.h>
24 
25 #define AWAR_NAMESERVER_STATUS "tmp/nameserver/status"
26 
27 static char *namesFilename(GBDATA *gb_main) {
28  const char *field = AW_get_nameserver_addid(gb_main);
29  const char *filename = field[0] ? GBS_global_string("names_%s.dat", field) : "names.dat";
30  char *fullname = nulldup(GB_path_in_ARBLIB("nas", filename));
31 
32  return fullname;
33 }
34 
35 inline bool continue_with_namesDat_destruction(const char *kindOfDestruction) {
36  return aw_ask_sure("MOD_NAMES_DAT",
37  GBS_global_string("This may DESTROY the name-consistency for ALL USERS of names.dat!\n"
38  "Names will have to be regenerated for all databases.\n"
39  "\n"
40  "Are you REALLY sure you like to continue %s names.dat?", kindOfDestruction));
41 }
42 
44  if (continue_with_namesDat_destruction("deleting")) {
45  char *path = namesFilename(gb_main);
46  char *newpath = GBS_string_eval(path, "*=*%");
47  GB_ERROR error = GB_move_file(path, newpath);
48  if (error) aw_message(error);
49  free(newpath);
50  free(path);
51  }
52 }
53 
55  if (continue_with_namesDat_destruction("editing")) {
56  char *path = namesFilename(gb_main);
57  AW_edit(path);
58  free(path);
59  }
60 }
61 
63  if (continue_with_namesDat_destruction("filtering")) {
64  char *path = namesFilename(gb_main);
65  char *newpath = GBS_string_eval(path, "*=*%");
66  char *command = GBS_global_string_copy("cp %s %s;"
67  "arb_replace -l '"
68  "*ACC {}*=:" // remove entries w/o acc
69  "*ACC {ARB*='" // remove entries with 'ARB_' prefix (Note: Nameserver does not store the '_'!)
70  " %s",
71  path, newpath, path);
72 
73  AWT_system_cb(command);
74 
75  free(command);
76  free(newpath);
77  free(path);
78  }
79 }
80 
81 static void addid_changed_cb(AW_root *awr, GBDATA *gb_main, bool show_advice) {
83 
84  awr->awar(AWAR_NAMESERVER_STATUS)->write_string(error ? error : "ok");
85  if (!error && show_advice) {
86  AW_advice("Calling 'Species/Synchronize IDs' is highly recommended", AW_ADVICE_TOGGLE_AND_HELP, NULp, "namesadmin.hlp");
87  }
88 }
89 
91  awr->awar_string(AWAR_NAMESERVER_ADDID, "", gb_main);
92  awr->awar_string(AWAR_NAMESERVER_STATUS, "<unchecked>", gb_main);
93 }
94 
96  AW_window_simple *aws = new AW_window_simple;
97  aws->init(root, "NAME_SERVER_ADMIN", "NAME_SERVER ADMIN");
98 
99  aws->load_xfig("awtc/names_admin.fig");
100 
101  aws->at("help");
102  aws->callback(makeHelpCallback("namesadmin.hlp"));
103  aws->create_button("HELP", "HELP", "H");
104 
105  aws->at("close");
106  aws->callback(AW_POPDOWN);
107  aws->create_button("CLOSE", "CLOSE", "C");
108 
109  aws->button_length(30);
110 
111  aws->sens_mask(AWM_EXP);
112  {
113  aws->at("delete");
114  aws->callback(makeWindowCallback(awtc_delete_names_file, gb_main));
115  aws->create_button("DELETE_OLD_NAMES_FILE", "Delete old names file");
116 
117  aws->at("edit");
118  aws->callback(makeWindowCallback(awtc_edit_names_file, gb_main));
119  aws->create_button("EDIT_NAMES_FILE", "Edit names file");
120 
121  aws->at("remove_arb");
122  aws->callback(makeWindowCallback(awtc_remove_arb_acc, gb_main));
123  aws->create_button("REMOVE_SUPERFLUOUS_ENTRIES_IN_NAMES_FILE",
124  "Remove all entries with an\n'ARB*' accession number\nfrom names file");
125 
126  aws->at("config");
127  aws->callback(awt_edit_arbtcpdat_cb);
128  aws->create_button("CREATE_TEMPLATE", "Configure arb_tcp.dat");
129  }
130  aws->sens_mask(AWM_ALL);
131 
132  AW_awar *awar_addid = root->awar(AWAR_NAMESERVER_ADDID);
133  awar_addid->add_callback(makeRootCallback(addid_changed_cb, gb_main, true));
134 
135  aws->at("add_field");
136  aws->create_input_field(AWAR_NAMESERVER_ADDID, 20); // (don't use field selection here atm; needs too many changes)
137 
138  aws->at("status");
139  aws->button_length(50);
140  aws->create_button(NULp, AWAR_NAMESERVER_STATUS);
141 
142  addid_changed_cb(root, gb_main, false); // force status update
143 
144  return aws;
145 }
const char * GB_ERROR
Definition: arb_core.h:25
#define AWAR_NAMESERVER_ADDID
Definition: AW_rename.hxx:21
static void addid_changed_cb(AW_root *awr, GBDATA *gb_main, bool show_advice)
void load_xfig(const char *file, bool resize=true)
Definition: AW_window.cxx:717
void AW_edit(const char *path)
Definition: AW_edit.cxx:16
const char * GBS_global_string(const char *templat,...)
Definition: arb_msg.cxx:204
void AW_advice(const char *message, AW_Advice_Type type, const char *title, const char *corresponding_help)
Show a message box with an advice for the user.
Definition: AW_advice.cxx:160
bool continue_with_namesDat_destruction(const char *kindOfDestruction)
char * GBS_string_eval(const char *insource, const char *icommand)
Definition: admatch.cxx:699
void AW_POPDOWN(AW_window *window)
Definition: AW_window.cxx:52
AW_awar * add_callback(const RootCallback &cb)
Definition: AW_awar.cxx:234
void AW_create_namesadmin_awars(AW_root *awr, GBDATA *gb_main)
const char * AW_get_nameserver_addid(GBDATA *gb_main)
Definition: AW_rename.cxx:39
WindowCallback makeHelpCallback(const char *helpfile)
Definition: aw_window.hxx:106
void awt_edit_arbtcpdat_cb(AW_window *)
GB_ERROR GB_move_file(const char *oldpath, const char *newpath)
Definition: arb_file.cxx:284
static void error(const char *msg)
Definition: mkptypes.cxx:96
#define AWAR_NAMESERVER_STATUS
GB_CSTR GB_path_in_ARBLIB(const char *relative_path)
Definition: adsocket.cxx:1103
AW_awar * awar(const char *awar)
Definition: AW_root.cxx:554
static void awtc_remove_arb_acc(AW_window *, GBDATA *gb_main)
bool aw_ask_sure(const char *unique_id, const char *msg)
static void awtc_delete_names_file(AW_window *, GBDATA *gb_main)
AW_window * AW_create_namesadmin_window(AW_root *root, GBDATA *gb_main)
static char * namesFilename(GBDATA *gb_main)
void aw_message(const char *msg)
Definition: AW_status.cxx:932
#define NULp
Definition: cxxforward.h:97
GB_ERROR write_string(const char *aw_string)
static char * command
Definition: arb_a2ps.c:319
GB_ERROR AW_test_nameserver(GBDATA *gb_main)
Definition: AW_rename.cxx:311
GBDATA * gb_main
Definition: adname.cxx:33
AW_awar * awar_string(const char *var_name, const char *default_value="", AW_default default_file=AW_ROOT_DEFAULT)
Definition: AW_root.cxx:570
char * GBS_global_string_copy(const char *templat,...)
Definition: arb_msg.cxx:195
static void awtc_edit_names_file(AW_window *, GBDATA *gb_main)
void AWT_system_cb(AW_window *, const char *command)
Definition: AWT_misc.cxx:84