libyui-ncurses-pkg  2.50.7
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  {
179  // show the popup
180  popupDialog();
181  } while ( postAgain() );
182 
183  popdownDialog();
184 
185  return postevent;
186 }
187 
188 ///////////////////////////////////////////////////////////////////
189 //
190 //
191 // METHOD NAME : NCPkgPopupDescr::niceSize
192 // METHOD TYPE : void
193 //
194 // DESCRIPTION :
195 //
196 
197 long NCPkgPopupDescr::nicesize(YUIDimension dim)
198 {
199  long vdim;
200  if ( NCurses::lines() > 17 )
201  vdim = 17;
202  else
203  vdim = NCurses::lines()-4;
204 
205  return ( dim == YD_HORIZ ? NCurses::cols()*2/3 : vdim );
206 }
207 
208 ///////////////////////////////////////////////////////////////////
209 //
210 //
211 // METHOD NAME : NCPopup::wHandleInput
212 // METHOD TYPE : NCursesEvent
213 //
214 // DESCRIPTION :
215 //
216 NCursesEvent NCPkgPopupDescr::wHandleInput( wint_t ch )
217 {
218  if ( ch == 27 ) // ESC
219  return NCursesEvent::cancel;
220 
221  if ( ch == KEY_RETURN )
222  return NCursesEvent::button;
223 
224  return NCDialog::wHandleInput( ch );
225 }
226 
227 ///////////////////////////////////////////////////////////////////
228 //
229 //
230 // METHOD NAME : NCPkgPopupDescr::postAgain
231 // METHOD TYPE : bool
232 //
233 // DESCRIPTION :
234 // x
235 bool NCPkgPopupDescr::postAgain()
236 {
237  if ( ! postevent.widget )
238  return false;
239 
240  if ( postevent == NCursesEvent::button || postevent == NCursesEvent::cancel )
241  {
242  // return false means: close the popup dialog
243  return false;
244  }
245  return true;
246 }
247 
The package table class.
Definition: NCPkgTable.h:205
void fillHeader()
Fills the header of the table.
Definition: NCPkgTable.cc:409
bool createListEntry(ZyppPkg pkgPtr, ZyppSel slbPtr)
Creates a line in the package table.
Definition: NCPkgTable.cc:516
virtual void itemsCleared()
Clears the package list.
Definition: NCPkgTable.cc:159
void drawList()
Draws the package list (has to be called after the loop with addLine() calls)
Definition: NCPkgTable.h:296
void setPackager(NCPackageSelector *pkg)
Sets the member variable PackageSelector *packager.
Definition: NCPkgTable.h:333
static const std::string OKLabel()
The label of the OK button.