ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/cf.schmorp.de/dclient/src/frontend/client/query_handler.cpp
Revision: 1.6
Committed: Sun Oct 24 22:41:36 2010 UTC (16 years ago) by sf-pippijn
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +12 -4 lines
Log Message:
fixed bug causing queries to be hidden if the user supplied a username on the cmdline

File Contents

# User Rev Content
1 sf-pippijn 1.1 #include "dclient/query_handler.h"
2     #include "dclient/widgets.h"
3     #include "dclient/widgets/map.h"
4     #include "dclient/widgets/query.h"
5    
6     #include "adt/string.h"
7    
8 sf-pippijn 1.5 #include <ndk/application.hh>
9 sf-pippijn 1.1
10     #include <boost/algorithm/string/split.hpp>
11    
12 sf-pippijn 1.5 query_handler::query_handler ( communicator &comm
13 sf-pippijn 1.1 , widgets &ui
14     , std::string const &username
15     , std::string const &password
16     )
17     : sender (comm)
18     , ui (ui)
19     , username (username)
20     , password (password)
21     {
22 sf-pippijn 1.3 ui.query_input->on_commit () = [this] (std::string const &answer) {
23 sf-pippijn 1.2 this->send ("reply", answer);
24 sf-pippijn 1.1 this->ui.map->focus ();
25 sf-pippijn 1.3 this->ui.query_input->set_text ("");
26 sf-pippijn 1.1 this->ui.query->hide ();
27 sf-pippijn 1.4 ndk::app->cursor_off ();
28 sf-pippijn 1.1 };
29     }
30    
31     void
32     query_handler::query (int flags, std::string const &prompt)
33     {
34     if (!username.empty ())
35     {
36     if (flags == 0 && !strncmp (prompt, "What is your name?"))
37 sf-pippijn 1.6 {
38     send ("reply", username);
39     return;
40     }
41 sf-pippijn 1.1 else if (flags == 4 && !strncmp (prompt, "What is your password?"))
42 sf-pippijn 1.6 {
43     send ("reply", password);
44     return;
45     }
46 sf-pippijn 1.1 else if (flags == 4 && !strncmp (prompt, "Please type your password again."))
47 sf-pippijn 1.6 {
48     send ("reply", password);
49     return;
50     }
51 sf-pippijn 1.1 }
52     else
53     {
54     if (flags == 4 && !strncmp (prompt, "What is your password?"))
55 sf-pippijn 1.3 ui.query_input->set_mode (ndk::edit::password);
56 sf-pippijn 1.1 else if (flags == 4 && !strncmp (prompt, "Please type your password again."))
57 sf-pippijn 1.3 ui.query_input->set_mode (ndk::edit::password);
58 sf-pippijn 1.1 else
59 sf-pippijn 1.3 ui.query_input->set_mode (ndk::edit::normal);
60 sf-pippijn 1.1 }
61    
62     std::vector<std::string> lines;
63     boost::split (lines, prompt, [](char c) { return c == '\n'; });
64    
65     ui.query->update (std::move (lines));
66     ui.query->visualize ();
67     ui.repack ();
68    
69 sf-pippijn 1.3 ui.query_input->focus ();
70 sf-pippijn 1.1
71 sf-pippijn 1.4 ndk::app->update ();
72 sf-pippijn 1.1 }