libyui-ncurses  2.44.1
 All Classes Functions Variables
NCApplication.cc
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: NCApplication.cc
20 
21  Authors: Gabriele Mohr <gs@suse.de>
22  Stefan Hundhammer <sh@suse.de>
23 
24 /-*/
25 
26 #include <ncursesw/curses.h>
27 
28 #define YUILogComponent "ncurses"
29 #include <yui/YUILog.h>
30 #include "NCurses.h"
31 #include "YNCursesUI.h"
32 #include "NCApplication.h"
33 #include "NCAskForDirectory.h"
34 #include "NCAskForFile.h"
35 
36 
38 {
39 
40 }
41 
42 
44 {
45 
46 }
47 
48 void
49 NCApplication::setLanguage( const std::string & language,
50  const std::string & encoding )
51 {
52  // Intentionally NOT calling
53  // YApplication::setLanguage( language, encoding );
54  // This would implicitly overwrite LC_CTYPE which might result in encoding bugs.
55 
56  setlocale( LC_NUMERIC, "C" ); // always format numbers with "."
57  NCurses::Refresh();
58 
59  yuiDebug() << "Language: " << language << " Encoding: " << (( encoding != "" ) ? encoding : "NOT SET" ) << std::endl;
60 
61 }
62 
63 
64 std::string
65 NCApplication::askForSaveFileName( const std::string & startDir,
66  const std::string & filter,
67  const std::string & headline )
68 {
69  NCAskForSaveFileName * filePopup = new NCAskForSaveFileName( wpos( 1, 1 ), startDir, filter, headline );
70  YUI_CHECK_NEW( filePopup );
71 
72  NCursesEvent retEvent = filePopup->showDirPopup( );
73  YDialog::deleteTopmostDialog();
74 
75  yuiMilestone() << "Returning: " << retEvent.result << std::endl;
76  return retEvent.result;
77 }
78 
79 
80 std::string
81 NCApplication::askForExistingFile( const std::string & startDir,
82  const std::string & filter,
83  const std::string & headline )
84 {
85  NCAskForExistingFile * filePopup = new NCAskForExistingFile( wpos( 1, 1 ), startDir, filter, headline );
86  YUI_CHECK_NEW( filePopup );
87 
88  NCursesEvent retEvent = filePopup->showDirPopup( );
89  YDialog::deleteTopmostDialog();
90 
91  yuiMilestone() << "Returning: " << retEvent.result << std::endl;
92  return retEvent.result;
93 }
94 
95 
96 std::string
97 NCApplication::askForExistingDirectory( const std::string & startDir,
98  const std::string & headline )
99 {
100  NCAskForExistingDirectory * dirPopup = new NCAskForExistingDirectory( wpos( 1, 1 ), startDir, headline );
101  YUI_CHECK_NEW( dirPopup );
102 
103  NCursesEvent retEvent = dirPopup->showDirPopup( );
104  YDialog::deleteTopmostDialog();
105 
106  yuiMilestone() << "Returning: " << retEvent.result << std::endl;
107  return retEvent.result;
108 }
109 
110 
111 void
113 {
114  ::beep();
115 }
116 
117 
119 {
120  YNCursesUI::ui()->Refresh();
121 }
122 
123 
124 void
126 {
127  /*
128  * Following code breaks the console keyboard e.g. for czech language during
129  * installation (bnc #433016). According to bnc #367801 comment #18/#19 the
130  * line isn't needed at all.
131  * "dumpkeys | loadkeys -C "$KBD_TTY" --unicode" has been also removed from kbd
132  * initscript. If dumpkeys has to be called for any reason it definitely needs
133  * the codepage argument, otherwise it cannot work.
134  */
135 #if 0
136  std::string cmd = "/bin/dumpkeys | /bin/loadkeys --unicode";
137 
138  if ( NCstring::terminalEncoding() == "UTF-8" )
139  {
140  int ret = system(( cmd + " >/dev/null 2>&1" ).c_str() );
141 
142  if ( ret != 0 )
143  {
144  yuiError() << "ERROR: /bin/dumpkeys | /bin/loadkeys --unicode returned: " << ret << std::endl;
145  }
146  }
147 #endif
148 }
149 
150 
151 void
152 NCApplication::setConsoleFont( const std::string & console_magic,
153  const std::string & font,
154  const std::string & screen_map,
155  const std::string & unicode_map,
156  const std::string & language )
157 {
158  /**
159  * Moving that code from YNCursesUI to this class turned out to be
160  * impossible (or at least a lot more work than it's worth) that I finally
161  * gave it up.
162  *
163  * - sh@suse.de 2008-02-06
164  **/
165  YNCursesUI::ui()->setConsoleFont( console_magic,
166  font,
167  screen_map,
168  unicode_map,
169  language );
170 }
171 
172 
173 int
174 NCApplication::runInTerminal( const std::string & cmd )
175 {
176  int ret;
177 
178  // Save tty modes and end ncurses mode temporarily
179  ::def_prog_mode();
180  ::endwin();
181 
182  // Regenerate saved stdout and stderr, so that app called
183  // via system() can use them and draw something to the terminal
184  dup2( YNCursesUI::ui()->stdout_save, 1 );
185  dup2( YNCursesUI::ui()->stderr_save, 2 );
186 
187  // Call external program
188  ret = system( cmd.c_str() );
189 
190  if ( ret != 0 )
191  {
192  yuiError() << cmd << " returned:" << ret << std::endl;
193  }
194 
195  // Redirect stdout and stderr to y2log again
196  YNCursesUI::ui()->RedirectToLog();
197 
198  // Resume tty modes and refresh the screen
199  ::reset_prog_mode();
200 
201  ::refresh();
202 
203  return ret;
204 }
205 
206 
207 int
208 NCApplication::displayWidth()
209 {
210  return ::COLS; // exported from ncurses.h
211 }
212 
213 
214 int
215 NCApplication::displayHeight()
216 {
217  return ::LINES; // exported from ncurses.h
218 }
219 
220 
221 int
222 NCApplication::displayDepth()
223 {
224  return -1;
225 }
226 
227 
228 long
229 NCApplication::displayColors()
230 {
231  return NCattribute::colors();
232 }
233 
234 
235 int
236 NCApplication::defaultWidth()
237 {
238  return ::COLS; // exported from ncurses.h
239 }
240 
241 
242 int
243 NCApplication::defaultHeight()
244 {
245  return ::LINES; // exported from ncurses.h
246 }
247 
248 
249 bool
250 NCApplication::hasFullUtf8Support()
251 {
252  return ( NCstring::terminalEncoding() == "UTF-8" );
253 }
254 
255 void NCApplication::setApplicationTitle ( const std::string& title )
256 {
257  YApplication::setApplicationTitle ( title );
258  NCurses::SetTitle(title);
259 }
260 
virtual std::string askForSaveFileName(const std::string &startWith, const std::string &filter, const std::string &headline)
virtual void setApplicationTitle(const std::string &title)
virtual void redrawScreen()
virtual void setConsoleFont(const std::string &console_magic, const std::string &font, const std::string &screen_map, const std::string &unicode_map, const std::string &lang)
Definition: YNCursesUI.cc:337
virtual ~NCApplication()
virtual int runInTerminal(const std::string &command)
static YNCursesUI * ui()
Definition: YNCursesUI.h:91
Definition: position.h:109
virtual void initConsoleKeyboard()
virtual void setLanguage(const std::string &language, const std::string &encoding=std::string())
virtual void beep()
virtual std::string askForExistingDirectory(const std::string &startDir, const std::string &headline)
NCursesEvent & showDirPopup()
virtual std::string askForExistingFile(const std::string &startWith, const std::string &filter, const std::string &headline)
virtual void setConsoleFont(const std::string &console_magic, const std::string &font, const std::string &screen_map, const std::string &unicode_map, const std::string &language)