source: trunk/SL/AW_NAME/AW_names_admin.cxx

Last change on this file was 18750, checked in by westram, 3 years ago
  • fix unwanted export of overloaded functions to perl interface:
    • GBT_log_to_tree_remark()
    • GB_path_in_ARBLIB()
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.6 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_concat_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
95void AW_popup_namesadmin_window(AW_window *parent_win, GBDATA *gb_main) {
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
Note: See TracBrowser for help on using the repository browser.