00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "mainwindow.h"
00015
00016 #include <qmenubar.h>
00017 #include <qpe/qpemessagebox.h>
00018 #include <qpe/resource.h>
00019 #include <qpe/config.h>
00020 #include <qtoolbar.h>
00021 #include <qpe/qcopenvelope_qws.h>
00022 #include <qaction.h>
00023 #include <qmessagebox.h>
00024 #include <qpopupmenu.h>
00025 #include <qtoolbutton.h>
00026 #include <qstring.h>
00027 #include <qlabel.h>
00028 #include <qfile.h>
00029 #include <qlistview.h>
00030 #include <qtextview.h>
00031 #include <qcheckbox.h>
00032 #include <qlineedit.h>
00033 #include <qtabwidget.h>
00034 #include <qcombobox.h>
00035 #include <qmessagebox.h>
00036 #include <qpushbutton.h>
00037 #include <qlayout.h>
00038
00039 #include "pksettingsbase.h"
00040 #include "utils.h"
00041 #include "packagelistitem.h"
00042
00043
00044 MainWindow::MainWindow( QWidget *parent, const char *name, WFlags f ) :
00045 QMainWindow( parent, name, f )
00046
00047
00048
00049 {
00050 setCaption( tr("Package Manager") );
00051 settings = new PackageManagerSettings(this,0,TRUE);
00052 listViewPackages = new PackageListView( this,"listViewPackages",settings );
00053 setCentralWidget( listViewPackages );
00054 listViewPackages->addList( tr("feeds"), &packageListServers );
00055 listViewPackages->addList( tr("ipkgfind&killefiz"), &packageListSearch );
00056 listViewPackages->addList( tr("documents"), &packageListDocLnk );
00057 ipkg = new PmIpkg( settings, this );
00058 packageListServers.setSettings( settings );
00059 packageListSearch.setSettings( settings );
00060 packageListDocLnk.setSettings( settings );
00061 pvDebug(9,"packageListServers.update");
00062 packageListServers.update();
00063 pvDebug(9,"packageListDocLnk.update");
00064 packageListDocLnk.update();
00065 pvDebug(9,"makeMenu");
00066 makeMenu();
00067 makeChannel();
00068
00069
00070 connect( section, SIGNAL(activated(int)), SLOT(sectionChanged()) );
00071 connect( subsection, SIGNAL(activated(int)), SLOT(subSectionChanged()) );
00072
00073 connect( settings->removeLinksButton, SIGNAL( clicked()),
00074 SLOT(removeLinks()) );
00075 connect( settings->createLinksButton, SIGNAL( clicked()),
00076 SLOT(createLinks()) );
00077
00078 pvDebug(9,"displayList");
00079 displayList();
00080 }
00081
00082 void MainWindow::makeMenu()
00083 {
00084
00085 QToolBar *toolBar = new QToolBar( this );
00086 QMenuBar *menuBar = new QMenuBar( toolBar );
00087 QPopupMenu *srvMenu = new QPopupMenu( menuBar );
00088 QPopupMenu *viewMenu = new QPopupMenu( menuBar );
00089 QPopupMenu *cfgMenu = new QPopupMenu( menuBar );
00090 QPopupMenu *helpMenu = new QPopupMenu( menuBar );
00091
00092 setToolBarsMovable( false );
00093 toolBar->setHorizontalStretchable( true );
00094 menuBar->insertItem( tr( "Package" ), srvMenu );
00095 menuBar->insertItem( tr( "View" ), viewMenu );
00096 menuBar->insertItem( tr( "Settings" ), cfgMenu );
00097 menuBar->insertItem( tr( "Help" ), helpMenu );
00098
00099
00100
00101
00102
00103
00104
00105 runAction = new QAction( tr( "Apply" ),
00106 Resource::loadPixmap( "oipkg/install" ),
00107 QString::null, 0, this, 0 );
00108 connect( runAction, SIGNAL( activated() ),
00109 this, SLOT( runIpkg() ) );
00110 runAction->addTo( toolBar );
00111 runAction->addTo( srvMenu );
00112
00113 srvMenu->insertSeparator();
00114
00115 updateAction = new QAction( tr( "Update" ),
00116 Resource::loadIconSet( "oipkg/update" ),
00117 QString::null, 0, this, 0 );
00118 connect( updateAction, SIGNAL( activated() ),
00119 this , SLOT( updateList() ) );
00120 updateAction->addTo( toolBar );
00121 updateAction->addTo( srvMenu );
00122
00123 QAction *cfgact;
00124
00125 cfgact = new QAction( tr( "Setups" ),
00126 QString::null, 0, this, 0 );
00127 connect( cfgact, SIGNAL( activated() ),
00128 SLOT( showSettingsSetup() ) );
00129 cfgact->addTo( cfgMenu );
00130
00131 cfgact = new QAction( tr( "Servers" ),
00132 QString::null, 0, this, 0 );
00133 connect( cfgact, SIGNAL( activated() ),
00134 SLOT( showSettingsSrv() ) );
00135 cfgact->addTo( cfgMenu );
00136 cfgact = new QAction( tr( "Destinations" ),
00137 QString::null, 0, this, 0 );
00138 connect( cfgact, SIGNAL( activated() ),
00139 SLOT( showSettingsDst() ) );
00140 cfgact->addTo( cfgMenu );
00141
00142 QAction *a;
00143
00144
00145 sectionBar = new QToolBar( this );
00146 addToolBar( sectionBar, "Section", QMainWindow::Top, TRUE );
00147 sectionBar->setHorizontalStretchable( true );
00148 QLabel *label = new QLabel( sectionBar, "section" );
00149
00150 label->font().setPointSize( 8 );
00151 label->setText( tr( "Section:" ) );
00152 sectionBar->setStretchableWidget( label );
00153 section = new QComboBox( false, sectionBar );
00154 section->font().setPointSize( 8 );
00155 label = new QLabel( " / ", sectionBar );
00156 label->font().setPointSize( 8 );
00157
00158 subsection = new QComboBox( false, sectionBar );
00159 subsection->font().setPointSize( 8 );
00160 a = new QAction( tr( "Close Section" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 );
00161 connect( a, SIGNAL( activated() ), this, SLOT( sectionClose() ) );
00162 a->addTo( sectionBar );
00163 setSections();
00164 setSubSections();
00165 sectionAction = new QAction( tr( "Sections" ), QString::null, 0, this, 0 );
00166 connect( sectionAction, SIGNAL( toggled(bool) ), this, SLOT( sectionShow(bool) ) );
00167 sectionAction->setToggleAction( true );
00168 sectionAction->addTo( viewMenu );
00169
00170
00171
00172 findBar = new QToolBar(this);
00173 addToolBar( findBar, "Filter", QMainWindow::Top, TRUE );
00174 label = new QLabel( tr("Filter: "), findBar );
00175
00176 findBar->setHorizontalStretchable( TRUE );
00177 findEdit = new QLineEdit( findBar, "findEdit" );
00178 findBar->setStretchableWidget( findEdit );
00179 connect( findEdit, SIGNAL( textChanged(const QString&) ),
00180 this, SLOT( displayList() ) );
00181 a = new QAction( tr( "Clear Find" ), Resource::loadPixmap( "back" ), QString::null, 0, this, 0 );
00182 connect( a, SIGNAL( activated() ), findEdit, SLOT( clear() ) );
00183 a->addTo( findBar );
00184 a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 );
00185 connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) );
00186 a->addTo( findBar );
00187 findAction = new QAction( tr( "Filter" ), QString::null, 0, this, 0 );
00188 connect( findAction, SIGNAL( toggled(bool) ), this, SLOT( findShow(bool) ) );
00189 findAction->setToggleAction( true );
00190 findAction->addTo( viewMenu );
00191
00192
00193 searchBar = new QToolBar(this);
00194 addToolBar( searchBar, "Search", QMainWindow::Top, TRUE );
00195 label = new QLabel( tr("Search: "), searchBar );
00196
00197 searchBar->setHorizontalStretchable( TRUE );
00198 searchEdit = new QLineEdit( searchBar, "seachEdit" );
00199 searchBar->setStretchableWidget( searchEdit );
00200
00201
00202 a = new QAction( tr( "Clear Search" ), Resource::loadPixmap( "back" ), QString::null, 0, this, 0 );
00203 connect( a, SIGNAL( activated() ), searchEdit, SLOT( clear() ) );
00204 a->addTo( searchBar );
00205 searchCommit = new QAction( tr( "Do Search" ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 );
00206 connect( searchCommit, SIGNAL( activated() ), SLOT( remotePackageQuery() ) );
00207 searchCommit->addTo( searchBar );
00208 a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 );
00209 connect( a, SIGNAL( activated() ), this, SLOT( searchClose() ) );
00210 a->addTo( searchBar );
00211 searchAction = new QAction( tr( "Search" ), QString::null, 0, this, 0 );
00212 connect( searchAction, SIGNAL( toggled(bool) ), this, SLOT( searchShow(bool) ) );
00213 searchAction->setToggleAction( true );
00214 searchAction->addTo( viewMenu );
00215
00216
00217 destBar = new QToolBar(this);
00218 addToolBar( destBar, "Destination", QMainWindow::Top, TRUE );
00219 label = new QLabel( tr("Destination: "), destBar );
00220
00221 destBar->setHorizontalStretchable( TRUE );
00222 destination = new QComboBox( false, destBar );
00223 destination->insertStringList( settings->getDestinationNames() );
00224 setComboName(destination,settings->getDestinationName());
00225 connect( destination, SIGNAL(activated(int)),
00226 settings, SLOT(activeDestinationChange(int)) );
00227
00228 CheckBoxLink = new QCheckBox( tr("Link"), destBar);
00229
00230 CheckBoxLink->setChecked( settings->createLinks() );
00231 connect( CheckBoxLink, SIGNAL(toggled(bool)),
00232 settings, SLOT(linkEnabled(bool)) );
00233 destAction = new QAction( tr( "Destinations" ), QString::null, 0, this, 0 );
00234 connect( destAction, SIGNAL( toggled(bool) ), SLOT( destShow(bool) ) );
00235 a = new QAction( tr( "Close Destinations" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 );
00236 connect( a, SIGNAL( activated() ), SLOT( destClose() ) );
00237 a->addTo( destBar );
00238 destBar->setStretchableWidget( CheckBoxLink );
00239 destAction->setToggleAction( true );
00240 destAction->addTo( viewMenu );
00241
00242
00243 helpMenu->insertSeparator();
00244 a = new QAction( tr( "Package Actions" ), QString::null, 0, this, 0 );
00245 a->addTo( helpMenu );
00246 helpMenu->insertSeparator();
00247 a = new QAction( tr( "Install" ),
00248 Resource::loadPixmap( "oipkg/install" ), QString::null, 0, this, 0 );
00249 a->addTo( helpMenu );
00250 a = new QAction( tr( "Remove" ),
00251 Resource::loadPixmap( "oipkg/uninstall" ), QString::null, 0, this, 0 );
00252 a->addTo( helpMenu );
00253 helpMenu->insertSeparator();
00254 a = new QAction( tr( "Package Status" ), QString::null, 0, this, 0 );
00255 a->addTo( helpMenu );
00256 helpMenu->insertSeparator();
00257 a = new QAction( tr( "New version, installed" ),
00258 Resource::loadPixmap( "oipkg/installed" ), QString::null, 0, this, 0 );
00259 a->addTo( helpMenu );
00260 a = new QAction( tr( "New version, not installed" ),
00261 Resource::loadPixmap( "oipkg/uninstalled" ), QString::null, 0, this, 0 );
00262 a->addTo( helpMenu );
00263 a = new QAction( tr( "Old version, installed" ),
00264 Resource::loadPixmap( "oipkg/installedOld" ), QString::null, 0, this, 0 );
00265 a->addTo( helpMenu );
00266 a = new QAction( tr( "Old version, not installed" ),
00267 Resource::loadPixmap( "oipkg/uninstalledOld" ), QString::null, 0, this, 0 );
00268 a->addTo( helpMenu );
00269 a = new QAction( tr( "Old version, new version installed" ),
00270 Resource::loadPixmap( "oipkg/uninstalledOldinstalledNew" ), QString::null, 0, this, 0 );
00271 a->addTo( helpMenu );
00272 a = new QAction( tr( "New version, old version installed" ),
00273 Resource::loadPixmap( "oipkg/uninstalledInstalledOld" ), QString::null, 0, this, 0 );
00274 a->addTo( helpMenu );
00275
00276
00277
00278
00279
00280 Config cfg( "oipkg", Config::User );
00281 cfg.setGroup( "gui" );
00282
00283 findShow( cfg.readBoolEntry( "findBar", true ) );
00284 searchShow( cfg.readBoolEntry( "searchBar", true ) );
00285 sectionShow( cfg.readBoolEntry( "sectionBar", true ) );
00286 destShow( cfg.readBoolEntry( "destBar", false ) );
00287 setComboName(section,cfg.readEntry("default_section"));
00288 sectionChanged();
00289 }
00290
00291 MainWindow::~MainWindow()
00292 {
00293 Config cfg( "oipkg", Config::User );
00294 cfg.setGroup( "gui" );
00295 cfg.writeEntry( "findBar", !findBar->isHidden() );
00296 cfg.writeEntry( "searchBar", !searchBar->isHidden() );
00297 cfg.writeEntry( "sectionBar", !sectionBar->isHidden() );
00298 cfg.writeEntry( "destBar", !destBar->isHidden() );
00299 cfg.writeEntry( "default_section", section->currentText() );
00300
00301 }
00302
00303 void MainWindow::runIpkg()
00304 {
00305 packageListServers.allPackages();
00306 ipkg->loadList( &packageListSearch );
00307 ipkg->loadList( &packageListDocLnk );
00308 ipkg->loadList( &packageListServers );
00309 ipkg->commit();
00310 ipkg->clearLists();
00311
00312
00313 QCopEnvelope e("QPE/System", "linkChanged(QString)");
00314 QString lf = QString::null;
00315 e << lf;
00316 displayList();
00317 }
00318
00319 void MainWindow::updateList()
00320 {
00321 packageListServers.clear();
00322 packageListSearch.clear();
00323
00324 packageListDocLnk.clear();
00325 ipkg->update();
00326 packageListServers.update();
00327 packageListSearch.update();
00328 packageListDocLnk.update();
00329 }
00330
00331 void MainWindow::filterList()
00332 {
00333 QString f = "";
00334 if ( findAction->isOn() ) f = findEdit->text();
00335 packageListServers.filterPackages( f );
00336 }
00337
00338 void MainWindow::displayList()
00339 {
00340 filterList();
00341 listViewPackages->display();
00342 }
00343
00344 void MainWindow::sectionChanged()
00345 {
00346 disconnect( section, SIGNAL( activated(int) ),
00347 this, SLOT( sectionChanged() ) );
00348 disconnect( subsection, SIGNAL(activated(int) ),
00349 this, SLOT( subSectionChanged() ) );
00350 subsection->clear();
00351 packageListServers.setSection( section->currentText() );
00352 setSubSections();
00353 connect( section, SIGNAL( activated(int) ),
00354 this, SLOT( sectionChanged() ) );
00355 connect( subsection, SIGNAL(activated(int) ),
00356 this, SLOT( subSectionChanged() ) );
00357 displayList();
00358 }
00359
00360 void MainWindow::subSectionChanged()
00361 {
00362 disconnect( section, SIGNAL( activated(int) ),
00363 this, SLOT( sectionChanged() ) );
00364 disconnect( subsection, SIGNAL(activated(int) ),
00365 this, SLOT( subSectionChanged() ) );
00366 packageListServers.setSubSection( subsection->currentText() );
00367 connect( section, SIGNAL( activated(int) ),
00368 this, SLOT( sectionChanged() ) );
00369 connect( subsection, SIGNAL(activated(int) ),
00370 this, SLOT( subSectionChanged() ) );
00371 displayList();
00372 }
00373
00374 void MainWindow::setSections()
00375 {
00376 section->clear();
00377 section->insertStringList( packageListServers.getSections() );
00378 }
00379
00380 void MainWindow::setSubSections()
00381 {
00382 subsection->clear();
00383 subsection->insertStringList( packageListServers.getSubSections() );
00384 }
00385
00386
00387 void MainWindow::showSettings(int i)
00388 {
00389 if ( settings->showDialog( i ) )
00390 {
00391 updateList();
00392 }
00393 setComboName(destination,settings->getDestinationName());
00394 CheckBoxLink->setChecked( settings->createLinks() );
00395 }
00396 void MainWindow::showSettingsSetup()
00397 {
00398 showSettings(0);
00399 }
00400 void MainWindow::showSettingsSrv()
00401 {
00402 showSettings(1);
00403 }
00404 void MainWindow::showSettingsDst()
00405 {
00406 showSettings(2);
00407 }
00408
00409 void MainWindow::sectionShow(bool b)
00410 {
00411 if (b) sectionBar->show();
00412 else sectionBar->hide();
00413 sectionAction->setOn( b );
00414 }
00415
00416 void MainWindow::sectionClose()
00417 {
00418 sectionAction->setOn( false );
00419 }
00420
00421 void MainWindow::findShow(bool b)
00422 {
00423 if (b) findBar->show();
00424 else findBar->hide();
00425 findAction->setOn( b );
00426 }
00427
00428 void MainWindow::findClose()
00429 {
00430 findAction->setOn( false );
00431 }
00432
00433 void MainWindow::searchShow(bool b)
00434 {
00435 if (b) searchBar->show();
00436 else searchBar->hide();
00437 searchAction->setOn( b );
00438 }
00439
00440 void MainWindow::searchClose()
00441 {
00442 searchAction->setOn( false );
00443 }
00444
00445
00446 void MainWindow::destShow(bool b)
00447 {
00448 if (b) destBar->show();
00449 else destBar->hide();
00450 destAction->setOn( b );
00451 }
00452
00453 void MainWindow::destClose()
00454 {
00455 destAction->setOn( false );
00456 }
00457
00458 void MainWindow::setDocument(const QString &fileName)
00459 {
00460 if ( !QFile::exists( fileName ) ) return;
00461 ipkg->installFile( fileName );
00462 QCopEnvelope e("QPE/System", "linkChanged(QString)");
00463 QString lf = QString::null;
00464 e << lf;
00465 }
00466
00467
00468 void MainWindow::makeChannel()
00469 {
00470 channel = new QCopChannel( "QPE/Application/oipkg", this );
00471 connect( channel, SIGNAL(received(const QCString&,const QByteArray&)),
00472 this, SLOT(receive(const QCString&,const QByteArray&)) );
00473 }
00474
00475
00476
00477 void MainWindow::receive(const QCString &msg, const QByteArray &arg)
00478 {
00479 pvDebug(3, "QCop "+msg+" "+QCString(arg));
00480 if ( msg == "installFile(QString)" )
00481 {
00482 ipkg->installFile( QString(arg) );
00483 }else if( msg == "removeFile(QString)" )
00484 {
00485 ipkg->removeFile( QString(arg) );
00486 }else if( msg == "createLinks(QString)" )
00487 {
00488 ipkg->createLinks( QString(arg) );
00489 }else if( msg == "removeLinks(QString)" )
00490 {
00491 ipkg->removeLinks( QString(arg) );
00492 }else{
00493 pvDebug(2,"Huh what do ya want")
00494 }
00495 }
00496
00497
00498 void MainWindow::createLinks()
00499 {
00500 pvDebug(2,"creating links...");
00501 ipkg->createLinks( settings->destinationurl->text() );
00502 }
00503
00504 void MainWindow::removeLinks()
00505 {
00506 pvDebug(2,"removing links...");
00507 ipkg->removeLinks( settings->destinationurl->text() );
00508 }
00509
00510 void MainWindow::remotePackageQuery()
00511 {
00512 packageListSearch.query( searchEdit->text() );
00513 packageListSearch.update();
00514 displayList();
00515 }