ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/cf.schmorp.de/dclient/src/frontend/client/query_handler.cpp
Revision: 1.4
Committed: Tue Oct 19 09:45:10 2010 UTC (16 years ago) by sf-pippijn
Branch: MAIN
Changes since 1.3: +2 -2 lines
Log Message:
- use wchar_t for single characters (glyphs and line drawing)
- merge ncurses and ndk wrappers
- simplify colour caching

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     #include <ndk++/application.hh>
9    
10     #include <boost/algorithm/string/split.hpp>
11    
12     query_handler::query_handler ( interface::communicator &comm
13     , 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     send ("reply", username);
38     else if (flags == 4 && !strncmp (prompt, "What is your password?"))
39     send ("reply", password);
40     else if (flags == 4 && !strncmp (prompt, "Please type your password again."))
41     send ("reply", password);
42     return;
43     }
44     else
45     {
46     if (flags == 4 && !strncmp (prompt, "What is your password?"))
47 sf-pippijn 1.3 ui.query_input->set_mode (ndk::edit::password);
48 sf-pippijn 1.1 else if (flags == 4 && !strncmp (prompt, "Please type your password again."))
49 sf-pippijn 1.3 ui.query_input->set_mode (ndk::edit::password);
50 sf-pippijn 1.1 else
51 sf-pippijn 1.3 ui.query_input->set_mode (ndk::edit::normal);
52 sf-pippijn 1.1 }
53    
54     std::vector<std::string> lines;
55     boost::split (lines, prompt, [](char c) { return c == '\n'; });
56    
57     ui.query->update (std::move (lines));
58     ui.query->visualize ();
59     ui.repack ();
60    
61 sf-pippijn 1.3 ui.query_input->focus ();
62 sf-pippijn 1.1
63 sf-pippijn 1.4 ndk::app->update ();
64 sf-pippijn 1.1 }