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_concat_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  static AW_window *aww = NULp;
97  if (!aww) {
98  AW_root *root = parent_win->get_root();
99  AW_window_simple *aws = new AW_window_simple;
100 
101  aws->init(root, "NAME_SERVER_ADMIN", "Nameserver admin");
102 
103  aws->load_xfig("awtc/names_admin.fig");
104 
105  aws->at("help");
106  aws->callback(makeHelpCallback("namesadmin.hlp"));
107  aws->create_button("HELP", "HELP", "H");
108 
109  aws->at("close");
110  aws->callback(AW_POPDOWN);
111  aws->create_button("CLOSE", "CLOSE", "C");
112 
113  aws->button_length(30);
114 
115  aws->sens_mask(AWM_EXP);
116  {
117  aws->at("delete");
118  aws->callback(makeWindowCallback(awtc_delete_names_file, gb_main));
119  aws->create_button("DELETE_OLD_NAMES_FILE", "Delete old names file");
120 
121  aws->at("edit");
122  aws->callback(makeWindowCallback(awtc_edit_names_file, gb_main));
123  aws->create_button("EDIT_NAMES_FILE", "Edit names file");
124 
125  aws->at("remove_arb");
126  aws->callback(makeWindowCallback(awtc_remove_arb_acc, gb_main));
127  aws->create_button("REMOVE_SUPERFLUOUS_ENTRIES_IN_NAMES_FILE",
128  "Remove all entries with an\n'ARB*' accession number\nfrom names file");
129 
130  aws->at("config");
131  aws->callback(awt_edit_arbtcpdat_cb);
132  aws->create_button("CREATE_TEMPLATE", "Configure arb_tcp.dat");
133  }
134  aws->sens_mask(AWM_ALL);
135 
136  AW_awar *awar_addid = root->awar(AWAR_NAMESERVER_ADDID);
137  awar_addid->add_callback(makeRootCallback(addid_changed_cb, gb_main, true));
138 
139  aws->at("add_field");
140  aws->create_input_field(AWAR_NAMESERVER_ADDID, 20); // (don't use field selection here atm; needs too many changes)
141 
142  aws->at("status");
143  aws->button_length(50);
144  aws->create_button(NULp, AWAR_NAMESERVER_STATUS, NULp, "+");
145 
146  addid_changed_cb(root, gb_main, false); // force status update
147 
148  aww = aws;
149  }
150  aww->activate();
151 }
152 
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 AW_edit(const char *path)
Definition: AW_edit.cxx:16
const char * GBS_global_string(const char *templat,...)
Definition: arb_msg.cxx:203
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
void activate()
Definition: aw_window.hxx:365
AW_awar * add_callback(const RootCallback &cb)
Definition: AW_awar.cxx:231
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
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)
void AW_popup_namesadmin_window(AW_window *parent_win, GBDATA *gb_main)
static char * namesFilename(GBDATA *gb_main)
GB_CSTR GB_concat_path_in_ARBLIB(const char *relative_path_left, const char *anypath_right)
Definition: adsocket.cxx:1159
void aw_message(const char *msg)
Definition: AW_status.cxx:1142
AW_root * get_root()
Definition: aw_window.hxx:359
#define NULp
Definition: cxxforward.h:116
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:32
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:194
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