summaryrefslogtreecommitdiff
path: root/noncore/unsupported/oipkg/mainwindow.cpp
Unidiff
Diffstat (limited to 'noncore/unsupported/oipkg/mainwindow.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/unsupported/oipkg/mainwindow.cpp264
1 files changed, 264 insertions, 0 deletions
diff --git a/noncore/unsupported/oipkg/mainwindow.cpp b/noncore/unsupported/oipkg/mainwindow.cpp
new file mode 100644
index 0000000..b485a03
--- a/dev/null
+++ b/noncore/unsupported/oipkg/mainwindow.cpp
@@ -0,0 +1,264 @@
1// adadpted form qpe/qipkg
2
3
4#include "mainwindow.h"
5
6#include <qpe/qpemenubar.h>
7#include <qpe/qpemessagebox.h>
8#include <qpe/resource.h>
9#include <qpe/qpetoolbar.h>
10#include <qaction.h>
11#include <qmessagebox.h>
12#include <qpopupmenu.h>
13#include <qtoolbutton.h>
14#include <qstring.h>
15#include <qlistview.h>
16#include <qtextview.h>
17#include <qtabwidget.h>
18#include <qcombobox.h>
19#include <qlayout.h>
20
21#include "pksettingsbase.h"
22#include "packagelistitem.h"
23
24MainWindow::MainWindow( QWidget *parent, const char *name, WFlags f = 0 ) :
25 QMainWindow( parent, name, f )
26 {
27 setCaption( tr("Package Manager") );
28 table = new PackageWindow( this,0,0 );
29 setCentralWidget( table );
30 makeMenu();
31
32 QFontMetrics fm = fontMetrics();
33 int w0 = fm.width(tr("Package"))+30;
34 int w2 = fm.width("00000")+4;
35 table->ListViewPackages->setColumnWidth(0,w0);
36 table->ListViewPackages->setColumnWidth(1,228-w2-w0); // ### screen-biased
37 table->ListViewPackages->setColumnWidth(2,w2);
38 table->ListViewPackages->setColumnWidthMode(0,QListView::Manual);
39 table->ListViewPackages->setColumnWidthMode(1,QListView::Manual);
40 table->ListViewPackages->setColumnWidthMode(2,QListView::Manual);
41 table->ListViewPackages->setSelectionMode( QListView::Multi );
42
43 connect( table->section, SIGNAL( activated(int) ),
44 this, SLOT( sectionChanged() ) );
45 connect( table->subsection, SIGNAL(activated(int) ),
46 this, SLOT( subSectionChanged() ) );
47 connect( table->ListViewPackages, SIGNAL( clicked( QListViewItem* ) ),
48 this, SLOT( setCurrent( QListViewItem* ) ) );
49
50 settings = new PackageManagerSettings(this,0,TRUE);
51
52 ipkg = new PmIpkg( settings, this );
53 packageList.setSettings( settings );
54 newList();
55 setSections();
56 setSubSections();
57 displayList();
58}
59
60void MainWindow::makeMenu()
61{
62
63 QPEToolBar *toolBar = new QPEToolBar( this );
64 QPEMenuBar *menuBar = new QPEMenuBar( toolBar );
65 QPopupMenu *srvMenu = new QPopupMenu( menuBar );
66 QPopupMenu *cfgMenu = new QPopupMenu( menuBar );
67 // QPopupMenu *sectMenu = new QPopupMenu( menuBar );
68
69 contextMenu = new QPopupMenu( this );
70
71 setToolBarsMovable( false );
72 toolBar->setHorizontalStretchable( true );
73 menuBar->insertItem( tr( "Package" ), srvMenu );
74 menuBar->insertItem( tr( "Settings" ), cfgMenu );
75 // menuBar->insertItem( tr( "Sections" ), sectMenu );
76
77 toolBar->setStretchableWidget (srvMenu);
78
79
80 runAction = new QAction( tr( "Run" ),
81 Resource::loadPixmap( "oipkg/install" ),
82 QString::null, 0, this, 0 );
83 connect( runAction, SIGNAL( activated() ),
84 this, SLOT( runIpkg() ) );
85 runAction->addTo( toolBar );
86 runAction->addTo( srvMenu );
87
88 srvMenu->insertSeparator ();
89
90 updateAction = new QAction( tr( "Update" ),
91 Resource::loadIconSet( "oipkg/repeat" ),
92 QString::null, 0, this, 0 );
93 connect( updateAction, SIGNAL( activated() ),
94 this , SLOT( updateList() ) );
95 updateAction->addTo( toolBar );
96 updateAction->addTo( srvMenu );
97
98 // detailsAction = new QAction( tr( "Details" ),
99 // Resource::loadIconSet( "oipkg/details" ),
100 // QString::null, 0, this, 0 );
101 // connect( detailsAction, SIGNAL( activated() ),
102 // this , SLOT( showDetails() ) );
103 // detailsAction->addTo( toolBar );
104 // detailsAction->addTo( srvMenu );
105
106 QAction *cfgact;
107
108 cfgact = new QAction( tr( "Setups" ),
109 Resource::loadIconSet( "" ),
110 QString::null, 0, this, 0 );
111 connect( cfgact, SIGNAL( activated() ),
112 SLOT( showSettings() ) );
113 cfgact->addTo( cfgMenu );
114
115 cfgact = new QAction( tr( "Servers" ),
116 Resource::loadIconSet( "" ),
117 QString::null, 0, this, 0 );
118 connect( cfgact, SIGNAL( activated() ),
119 SLOT( showSettingsSrv() ) );
120 cfgact->addTo( cfgMenu );
121 cfgact = new QAction( tr( "Destinations" ),
122 Resource::loadIconSet( "" ),
123 QString::null, 0, this, 0 );
124 connect( cfgact, SIGNAL( activated() ),
125 SLOT( showSettingsDst() ) );
126 cfgact->addTo( cfgMenu );
127
128}
129
130MainWindow::~MainWindow()
131{
132}
133
134void MainWindow::runIpkg()
135{
136 ipkg->commit( packageList );
137 ipkg->runIpkg("update");
138 packageList.update();
139}
140
141void MainWindow::updateList()
142{
143 ipkg->runIpkg("update");
144 packageList.update();
145}
146
147void MainWindow::newList()
148{
149 packageList.update();
150}
151
152void MainWindow::filterList()
153{
154 packageList.filterPackages();
155}
156
157void MainWindow::displayList()
158{
159 table->ListViewPackages->clear();
160 Package *pack = packageList.first();
161 while( pack )
162 {
163 if ( pack && (pack->name() != "") )
164 {
165 table->ListViewPackages->insertItem(
166 new PackageListItem( table->ListViewPackages, pack ) );
167 }
168 pack = packageList.next();
169 }
170}
171
172void MainWindow::sectionChanged()
173{
174 disconnect( table->section, SIGNAL( activated(int) ),
175 this, SLOT( sectionChanged() ) );
176 disconnect( table->subsection, SIGNAL(activated(int) ),
177 this, SLOT( subSectionChanged() ) );
178 table->subsection->clear();
179 packageList.setSection( table->section->currentText() );
180 setSubSections();
181 filterList();
182 connect( table->section, SIGNAL( activated(int) ),
183 this, SLOT( sectionChanged() ) );
184 connect( table->subsection, SIGNAL(activated(int) ),
185 this, SLOT( subSectionChanged() ) );
186 displayList();
187}
188
189void MainWindow::subSectionChanged()
190{
191 disconnect( table->section, SIGNAL( activated(int) ),
192 this, SLOT( sectionChanged() ) );
193 disconnect( table->subsection, SIGNAL(activated(int) ),
194 this, SLOT( subSectionChanged() ) );
195 packageList.setSubSection( table->subsection->currentText() );
196 filterList();
197 connect( table->section, SIGNAL( activated(int) ),
198 this, SLOT( sectionChanged() ) );
199 connect( table->subsection, SIGNAL(activated(int) ),
200 this, SLOT( subSectionChanged() ) );
201 displayList();
202}
203
204void MainWindow::setSections()
205{
206 table->section->clear();
207 table->section->insertStringList( packageList.getSections() );
208}
209
210void MainWindow::setSubSections()
211{
212 table->subsection->clear();
213 table->subsection->insertStringList( packageList.getSubSections() );
214}
215
216
217void MainWindow::showSettings()
218{
219 if ( settings->showDialog( 0 ) )
220 newList();
221}
222void MainWindow::showSettingsSrv()
223{
224 if ( settings->showDialog( 1 ) )
225 newList();
226}
227void MainWindow::showSettingsDst()
228{
229 if ( settings->showDialog( 2 ) )
230 newList();
231}
232
233
234void MainWindow::showDetails()
235{
236 if ( activePackage ) return;
237 if ( details )
238 {
239 details = new PackageDetails( this );
240 connect( details->install, SIGNAL(clicked()), SLOT( toggleActivePackage() ) );
241 connect( details->remove, SIGNAL(clicked()), SLOT( toggleActivePackage() ) );
242 connect( details->ignore, SIGNAL(clicked()), details, SLOT(close()));
243 details->description->setTextFormat(RichText);
244 }
245
246 details->setCaption("Package: " + activePackage->name());
247 details->description->setText(activePackage->details() );
248 details->install->setEnabled(!activePackage->installed());
249 details->remove->setEnabled(activePackage->installed());
250 details->showMaximized();
251}
252
253void MainWindow::toggleActivePackage()
254{
255 activePackage->toggleProcess();
256 if ( details ) details->close();
257}
258
259void MainWindow::setCurrent( QListViewItem* p )
260{
261 pvDebug(2, "MainWindow::setCurrent ");
262 //+((Package*)p)->name());
263 activePackage = (Package*)p;
264}