source: branches/nameserver/SL/AW_NAME/AW_names_admin.cxx

Last change on this file was 16763, checked in by westram, 7 years ago
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.3 KB
Line 
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
27static 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
35inline 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
43static void awtc_delete_names_file(AW_window*, GBDATA *gb_main) {
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
54static void awtc_edit_names_file(AW_window*, GBDATA *gb_main) {
55    if (continue_with_namesDat_destruction("editing")) {
56        char *path = namesFilename(gb_main);
57        AW_edit(path);
58        free(path);
59    }
60}
61
62static void awtc_remove_arb_acc(AW_window*, GBDATA *gb_main) {
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
81static void addid_changed_cb(AW_root *awr, GBDATA *gb_main, bool show_advice) {
82    GB_ERROR error = AW_test_nameserver(gb_main);
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
90void AW_create_namesadmin_awars(AW_root *awr, GBDATA *gb_main) {
91    awr->awar_string(AWAR_NAMESERVER_ADDID, "", gb_main);
92    awr->awar_string(AWAR_NAMESERVER_STATUS, "<unchecked>", gb_main);
93}
94
95AW_window *AW_create_namesadmin_window(AW_root *root, GBDATA *gb_main) {
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}
Note: See TracBrowser for help on using the repository browser.