libyui-ncurses-pkg  2.48.5
NCPkgMenuView.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: NCPkgMenuView.cc
37 
38  Author: Hedgehog Painter <kmachalkova@suse.cz>
39 
40 /-*/
41 #define YUILogComponent "ncurses-pkg"
42 #include <YUILog.h>
43 
44 #include "NCPkgMenuView.h"
45 #include "NCPackageSelector.h"
46 
47 using std::endl;
48 
49 /*
50  Textdomain "ncurses-pkg"
51 */
52 
53 NCPkgMenuView::NCPkgMenuView (YWidget *parent, std::string label, NCPackageSelector *pkger)
54  : NCMenuButton( parent, label)
55  ,pkg (pkger)
56 {
57  createLayout();
58 }
59 
60 NCPkgMenuView::~NCPkgMenuView()
61 {
62 
63 }
64 
65 void NCPkgMenuView::createLayout()
66 {
67  if ( !pkg->isYouMode() )
68  {
69  // begin: menu items of the view (package information) menu
70  // please note: use unique hotkeys until end:
71  technical = new YMenuItem( _( "&Technical Data" ) );
72  description = new YMenuItem( _( "&Package Description" ) );
73  versions = new YMenuItem( _( "Package &Versions" ) );
74  files = new YMenuItem( _( "&File List" ) );
75  // end: menu items of the view menu
76  deps = new YMenuItem( _( "&Dependencies" ) );
77 
78  items.push_back( technical );
79  items.push_back( description );
80  items.push_back( versions );
81  items.push_back( files );
82  items.push_back( deps );
83 
84  addItems( items );
85  }
86  else
87  {
88  // menu items of the patch view menu - keep them short and
89  // use unique hotkeys from begin: to end:
90  // begin:
91  patchDescription = new YMenuItem( _( "&Long Description" ) );
92  patchPackages = new YMenuItem( _( "&Package List" ) );
93  // end: menu items of the view menu
94  patchPkgVersions = new YMenuItem( _( "&Versions" ) );
95 
96  items.push_back( patchDescription );
97  items.push_back( patchPackages );
98  items.push_back( patchPkgVersions );
99  addItems( items );
100  }
101 }
102 
103 
104 bool NCPkgMenuView::handleEvent ( const NCursesEvent & event)
105 {
106  if ( !event.selection)
107  return false;
108 
109  NCPkgTable *pkgList = pkg->PackageList();
110  int idx = pkgList->getCurrentItem();
111 
112  ZyppObj pkgPtr = pkgList->getDataPointer( idx );
113  ZyppSel slbPtr = pkgList->getSelPointer( idx );
114 
115  if ( !pkgPtr || !slbPtr)
116  {
117  yuiWarning() << "package list empty - no package pointer" << endl;
118  return true;
119  }
120 
121  // Call the appropriate method from NCPackageSelector for
122  // the selected menu entry.
123  // Set the information type of the package list (NCPkgTable)
124  // acccordingly to to able to show the required information while
125  // scrolling the list (NCPkgTable::updateList())
126 
127  if ( event.selection == versions )
128  {
129  pkg->showVersionsList();
130  pkgList->setVisibleInfo (NCPkgTable::I_Versions);
131  }
132  else if ( event.selection == patchPackages )
133  {
134  pkg->showPatchPackages();
135  pkgList->setVisibleInfo (NCPkgTable::I_PatchPkgs);
136  }
137  else if ( event.selection == patchPkgVersions )
138  {
139  pkg->showPatchPkgVersions(); // opens a popup
140  pkgList->setVisibleInfo (NCPkgTable::I_PatchPkgs); // info remains patch pkgs
141  }
142  else
143  {
144  pkg->showInformation();
145 
146  if ( !pkg->InfoText() )
147  return false;
148 
149  if (event.selection == description)
150  {
151  pkg->InfoText()->longDescription( pkgPtr );
152  pkgList->setVisibleInfo (NCPkgTable::I_Descr);
153  }
154  else if (event.selection == technical )
155  {
156  pkg->InfoText()->technicalData( pkgPtr, slbPtr );
157  pkgList->setVisibleInfo (NCPkgTable::I_Technical);
158  }
159  else if (event.selection == files )
160  {
161  pkg->InfoText()->fileList( slbPtr );
162  pkgList->setVisibleInfo (NCPkgTable::I_Files);
163  }
164  else if (event.selection == deps )
165  {
166  pkg->InfoText()->dependencyList( pkgPtr, slbPtr );
167  pkgList->setVisibleInfo (NCPkgTable::I_Deps);
168  }
169  else if ( event.selection == patchDescription )
170  {
171  pkg->InfoText()->patchDescription( pkgPtr, slbPtr );
172  pkgList->setVisibleInfo (NCPkgTable::I_PatchDescr);
173  }
174  }
175 
176 
177  return true;
178 }
The package table class.
Definition: NCPkgTable.h:207
ZyppObj getDataPointer(int index)
Gets the data pointer of a certain package.
Definition: NCPkgTable.cc:874
void showPatchPackages()
Creates an NCPkgTable widget and shows all packages belonging to a patch.
ZyppSel getSelPointer(int index)
Gets the selectable pointer of a certain package.
Definition: NCPkgTable.cc:884
void showPatchPkgVersions()
Creates an NCPkgTable widget and shows all versions of all packages belonging to a patch...
void showInformation()
Creates an NCRichText widget for package (patch) information.
void showVersionsList()
Creates an NCPkgTable widget and shows all verions a the selected package.