libyui-ncurses-pkg  2.43.4.1
 All Classes Functions
NCPkgPopupDescr.cc
1 /****************************************************************************
2 |
3 | Copyright (c) [2002-2011] Novell, Inc.
4 | All Rights Reserved.
5 |
6 | This program is free software; you can redistribute it and/or
7 | modify it under the terms of version 2 of the GNU General Public License as
8 | published by the Free Software Foundation.
9 |
10 | This program is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with this program; if not, contact Novell, Inc.
17 |
18 | To contact Novell about this file by physical or electronic mail,
19 | you may find current contact information at www.novell.com
20 |
21 |***************************************************************************/
22 
23 
24 /*---------------------------------------------------------------------\
25 | |
26 | __ __ ____ _____ ____ |
27 | \ \ / /_ _/ ___|_ _|___ \ |
28 | \ V / _` \___ \ | | __) | |
29 | | | (_| |___) || | / __/ |
30 | |_|\__,_|____/ |_| |_____| |
31 | |
32 | core system |
33 | (C) SuSE GmbH |
34 \----------------------------------------------------------------------/
35 
36  File: NCPkgPopupDescr.cc
37 
38  Author: Gabriele Strattner <gs@suse.de>
39 
40 /-*/
41 #define YUILogComponent "ncurses-pkg"
42 #include <YUILog.h>
43 
44 #include "YMenuButton.h"
45 #include "YDialog.h"
46 
47 #include "NCLayoutBox.h"
48 #include "NCSpacing.h"
49 #include "NCPkgStrings.h"
50 #include "NCLabel.h"
51 #include "NCPushButton.h"
52 #include "NCPkgTable.h"
53 #include "NCRichText.h"
54 
55 #include "NCZypp.h"
56 #include "NCi18n.h"
57 
58 #include "NCPkgPopupDescr.h"
59 #include "NCPackageSelector.h"
60 
61 /*
62  Textdomain "ncurses-pkg"
63 */
64 
65 ///////////////////////////////////////////////////////////////////
66 //
67 //
68 // METHOD NAME : NCPkgPopupDescr::NCPkgPopupDescr
69 // METHOD TYPE : Constructor
70 //
71 // DESCRIPTION :
72 //
73 NCPkgPopupDescr::NCPkgPopupDescr( const wpos at, NCPackageSelector * pkger )
74  : NCPopup( at, false )
75  , pkgTable( 0 )
76  , okButton( 0 )
77  , headline( 0 )
78  , packager( pkger )
79 {
80  createLayout( );
81 }
82 
83 ///////////////////////////////////////////////////////////////////
84 //
85 //
86 // METHOD NAME : NCPkgPopupDescr::~NCPkgPopupDescr
87 // METHOD TYPE : Destructor
88 //
89 // DESCRIPTION :
90 //
91 NCPkgPopupDescr::~NCPkgPopupDescr()
92 {
93 }
94 
95 ///////////////////////////////////////////////////////////////////
96 //
97 //
98 // METHOD NAME : NCPkgPopupDescr::createLayout
99 // METHOD TYPE : void
100 //
101 // DESCRIPTION :
102 //
103 void NCPkgPopupDescr::createLayout( )
104 {
105  // the vertical split is the (only) child of the dialog
106  NCLayoutBox * split = new NCLayoutBox( this, YD_VERT );
107 
108  new NCSpacing( split, YD_VERT, false, 0.8 ); // stretchable = false
109 
110  headline = new NCLabel( split, "", true, false ); // isHeading = true
111  new NCSpacing( split, YD_VERT, false, 0.4 );
112 
113  // add the rich text widget for the package description
114  descrText = new NCRichText( split, "" );
115 
116  new NCSpacing( split, YD_VERT, true, 0.6 ); // stretchable = true
117 
118  YTableHeader * tableHeader = new YTableHeader();
119 
120  // add the package table (use default type T_Packages)
121  pkgTable = new NCPkgTable( split, tableHeader );
122  pkgTable->setPackager( packager );
123  pkgTable->fillHeader();
124 
125  new NCSpacing( split, YD_VERT, true, 0.6 );
126 
127  // a help line for the dependency popup
128  new NCLabel( split, _( " [+] Select [-] Delete [>] Update " ), false, false );
129 
130  new NCSpacing( split, YD_VERT, false, 0.6 ); // stretchable = false
131 
132  // add the OK button
133  okButton = new NCPushButton( split, NCPkgStrings::OKLabel() );
134  okButton->setFunctionKey( 10 );
135 }
136 
137 ///////////////////////////////////////////////////////////////////
138 //
139 //
140 // METHOD NAME : NCPkgPopupDescr::fillData
141 // METHOD TYPE : bool
142 //
143 // DESCRIPTION :
144 //
145 bool NCPkgPopupDescr::fillData( ZyppPkg pkgPtr, ZyppSel slbPtr )
146 {
147  if ( !pkgPtr )
148  return false;
149 
150  pkgTable->itemsCleared(); // clear the table
151 
152  pkgTable->createListEntry( pkgPtr, slbPtr );
153 
154  pkgTable->drawList();
155 
156  headline->setLabel( pkgPtr->summary() );
157 
158  descrText->setText( pkgPtr->description() );
159 
160  return true;
161 }
162 
163 ///////////////////////////////////////////////////////////////////
164 //
165 //
166 // METHOD NAME : NCPkgPopupDescr::showInfoPopup
167 // METHOD TYPE : NCursesEvent event
168 //
169 // DESCRIPTION :
170 //
171 NCursesEvent NCPkgPopupDescr::showInfoPopup( ZyppPkg pkgPtr, ZyppSel slbPtr )
172 {
173  postevent = NCursesEvent();
174 
175  fillData( pkgPtr, slbPtr );
176 
177  do {
178  // show the popup
179  popupDialog( );
180  } while ( postAgain() );
181 
182  popdownDialog();
183 
184  return postevent;
185 }
186 
187 ///////////////////////////////////////////////////////////////////
188 //
189 //
190 // METHOD NAME : NCPkgPopupDescr::niceSize
191 // METHOD TYPE : void
192 //
193 // DESCRIPTION :
194 //
195 
196 long NCPkgPopupDescr::nicesize(YUIDimension dim)
197 {
198  long vdim;
199  if ( NCurses::lines() > 17 )
200  vdim = 17;
201  else
202  vdim = NCurses::lines()-4;
203 
204  return ( dim == YD_HORIZ ? NCurses::cols()*2/3 : vdim );
205 }
206 
207 ///////////////////////////////////////////////////////////////////
208 //
209 //
210 // METHOD NAME : NCPopup::wHandleInput
211 // METHOD TYPE : NCursesEvent
212 //
213 // DESCRIPTION :
214 //
215 NCursesEvent NCPkgPopupDescr::wHandleInput( wint_t ch )
216 {
217  if ( ch == 27 ) // ESC
218  return NCursesEvent::cancel;
219 
220  if ( ch == KEY_RETURN )
221  return NCursesEvent::button;
222 
223  return NCDialog::wHandleInput( ch );
224 }
225 
226 ///////////////////////////////////////////////////////////////////
227 //
228 //
229 // METHOD NAME : NCPkgPopupDescr::postAgain
230 // METHOD TYPE : bool
231 //
232 // DESCRIPTION :
233 //x
234 bool NCPkgPopupDescr::postAgain()
235 {
236  if ( ! postevent.widget )
237  return false;
238 
239  if ( postevent == NCursesEvent::button || postevent == NCursesEvent::cancel )
240  {
241  // return false means: close the popup dialog
242  return false;
243  }
244  return true;
245 }
246