summaryrefslogtreecommitdiff
authordrw <drw>2004-01-24 01:30:42 (UTC)
committer drw <drw>2004-01-24 01:30:42 (UTC)
commitd542ba6a426f9868d521dbd9eb502184086535fc (patch) (side-by-side diff)
tree6c975a8d20949d10dc48f2f372b836032988dcbd
parent77ad4fd70864e36745dbee587ca959a2e56998a6 (diff)
downloadopie-d542ba6a426f9868d521dbd9eb502184086535fc.zip
opie-d542ba6a426f9868d521dbd9eb502184086535fc.tar.gz
opie-d542ba6a426f9868d521dbd9eb502184086535fc.tar.bz2
Added download packages (requires current version of libipkg) and code to have Opie update links so apps will display properly in Launcher after adding/removing
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/settings/packagemanager/ChangeLog6
-rw-r--r--noncore/settings/packagemanager/entrydlg.cpp82
-rw-r--r--noncore/settings/packagemanager/entrydlg.h57
-rw-r--r--noncore/settings/packagemanager/installdlg.cpp2
-rw-r--r--noncore/settings/packagemanager/mainwindow.cpp38
-rw-r--r--noncore/settings/packagemanager/mainwindow.h2
-rw-r--r--noncore/settings/packagemanager/oipkg.cpp9
-rw-r--r--noncore/settings/packagemanager/packagemanager.pro4
-rw-r--r--noncore/settings/packagemanager/promptdlg.cpp2
9 files changed, 179 insertions, 23 deletions
diff --git a/noncore/settings/packagemanager/ChangeLog b/noncore/settings/packagemanager/ChangeLog
index 1ba12af..efa75b1 100644
--- a/noncore/settings/packagemanager/ChangeLog
+++ b/noncore/settings/packagemanager/ChangeLog
@@ -1,9 +1,15 @@
+2004-01-23 Dan Williams <drw@handhelds.org>
+
+ * Added package download functionality
+ * Have Opie update links after install/removal so that apps
+ will display properly in Launcher
+
2004-01-20 Dan Williams <drw@handhelds.org>
* Released version 0.2.0
* Converted to use libipkg in place of spawning ipkg process
2004-01-13 Dan Williams <drw@handhelds.org>
* Released version 0.1.0
* Initial check-in of new package management client to eventually replace AQPkg
diff --git a/noncore/settings/packagemanager/entrydlg.cpp b/noncore/settings/packagemanager/entrydlg.cpp
new file mode 100644
index 0000000..8deaa37
--- a/dev/null
+++ b/noncore/settings/packagemanager/entrydlg.cpp
@@ -0,0 +1,82 @@
+/*
+                This file is part of the OPIE Project
+
+ =. Copyright (c) 2004 Dan Williams <drw@handhelds.org>
+             .=l.
+           .>+-=
+ _;:,     .>    :=|. This file is free software; you can
+.> <`_,   >  .   <= redistribute it and/or modify it under
+:`=1 )Y*s>-.--   : the terms of the GNU General Public
+.="- .-=="i,     .._ License as published by the Free Software
+ - .   .-<_>     .<> Foundation; either version 2 of the License,
+     ._= =}       : or (at your option) any later version.
+    .%`+i>       _;_.
+    .i_,=:_.      -<s. This file is distributed in the hope that
+     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
+    : ..    .:,     . . . without even the implied warranty of
+    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
+  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
+..}^=.=       =       ; Public License for more details.
+++=   -.     .`     .:
+ :     =  ...= . :.=- You should have received a copy of the GNU
+ -.   .:....=;==+<; General Public License along with this file;
+  -_. . .   )=.  = see the file COPYING. If not, write to the
+    --        :-=` Free Software Foundation, Inc.,
+ 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+*/
+
+#include "entrydlg.h"
+
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qlineedit.h>
+#include <qpushbutton.h>
+
+EntryDlg::EntryDlg( const QString &label, QWidget* parent, const char* name, bool modal )
+ : QDialog( parent, name, modal )
+{
+ QVBoxLayout *vbox = new QVBoxLayout( this, 6, 6 );
+
+ QLabel *l = new QLabel( label, this );
+ l->setAlignment( AlignLeft | AlignTop | WordBreak );
+ vbox->addWidget( l );
+
+ m_entry = new QLineEdit( this );
+ vbox->addWidget( m_entry );
+
+ connect( m_entry, SIGNAL(returnPressed()), this, SLOT(tryAccept()) );
+}
+
+void EntryDlg::setText( const QString &text )
+{
+ m_entry->setText( text );
+ m_entry->selectAll();
+}
+
+QString EntryDlg::getText()
+{
+ return m_entry->text();
+}
+
+QString EntryDlg::getText( const QString &caption, const QString &label, const QString &text, bool *ok,
+ QWidget *parent, const char *name )
+{
+ EntryDlg *dlg = new EntryDlg( label, parent, name, true );
+ dlg->setCaption( caption );
+ dlg->setText( text );
+
+ QString result;
+ *ok = ( dlg->exec() == QDialog::Accepted );
+ if ( *ok )
+ result = dlg->getText();
+
+ delete dlg;
+ return result;
+}
+void EntryDlg::tryAccept()
+{
+ if ( !m_entry->text().isEmpty() )
+ accept();
+}
diff --git a/noncore/settings/packagemanager/entrydlg.h b/noncore/settings/packagemanager/entrydlg.h
new file mode 100644
index 0000000..33a7920
--- a/dev/null
+++ b/noncore/settings/packagemanager/entrydlg.h
@@ -0,0 +1,57 @@
+/*
+                This file is part of the OPIE Project
+
+ =. Copyright (c) 2004 Dan Williams <drw@handhelds.org>
+             .=l.
+           .>+-=
+ _;:,     .>    :=|. This file is free software; you can
+.> <`_,   >  .   <= redistribute it and/or modify it under
+:`=1 )Y*s>-.--   : the terms of the GNU General Public
+.="- .-=="i,     .._ License as published by the Free Software
+ - .   .-<_>     .<> Foundation; either version 2 of the License,
+     ._= =}       : or (at your option) any later version.
+    .%`+i>       _;_.
+    .i_,=:_.      -<s. This file is distributed in the hope that
+     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
+    : ..    .:,     . . . without even the implied warranty of
+    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
+  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
+..}^=.=       =       ; Public License for more details.
+++=   -.     .`     .:
+ :     =  ...= . :.=- You should have received a copy of the GNU
+ -.   .:....=;==+<; General Public License along with this file;
+  -_. . .   )=.  = see the file COPYING. If not, write to the
+    --        :-=` Free Software Foundation, Inc.,
+ 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+*/
+
+#ifndef ENTRYDLG_H
+#define ENTRYDLG_H
+
+#include <qdialog.h>
+
+class QLineEdit;
+
+class EntryDlg : public QDialog
+{
+ Q_OBJECT
+
+public:
+ static QString getText( const QString &caption, const QString &label, const QString &text = QString::null,
+ bool *ok = 0, QWidget *parent = 0, const char *name = 0 );
+
+ EntryDlg( const QString &label, QWidget* parent = 0, const char* name = 0, bool modal = true );
+
+ void setText( const QString &text );
+ QString getText();
+
+private slots:
+ void tryAccept();
+
+private:
+ QLineEdit *m_entry;
+};
+
+#endif // EntryDlg_H
diff --git a/noncore/settings/packagemanager/installdlg.cpp b/noncore/settings/packagemanager/installdlg.cpp
index 6a9ccbd..0c2ea78 100644
--- a/noncore/settings/packagemanager/installdlg.cpp
+++ b/noncore/settings/packagemanager/installdlg.cpp
@@ -48,192 +48,194 @@
#include <opie/ofiledialog.h>
#include "opackagemanager.h"
InstallDlg::InstallDlg( QWidget *parent, OPackageManager *pm, const QString &caption, bool showDestInfo,
OPackage::Command command1, QStringList *packages1,
OPackage::Command command2, QStringList *packages2,
OPackage::Command command3, QStringList *packages3 )
: QWidget( 0x0 )
, m_packman( pm )
, m_numCommands( 0 )
, m_currCommand( 0 )
{
// Save command/package list information
if ( command1 != OPackage::NotDefined )
{
m_command[ m_numCommands ] = command1;
m_packages[ m_numCommands ] = packages1;
++m_numCommands;
}
if ( command2 != OPackage::NotDefined )
{
m_command[ m_numCommands ] = command2;
m_packages[ m_numCommands ] = packages2;
++m_numCommands;
}
if ( command3 != OPackage::NotDefined )
{
m_command[ m_numCommands ] = command3;
m_packages[ m_numCommands ] = packages3;
++m_numCommands;
}
// Initialize UI
if ( parent )
parent->setCaption( caption );
QGridLayout *layout = new QGridLayout( this, 4, 2, 2, 4 );
if ( showDestInfo )
{
QLabel *label = new QLabel( tr( "Destination" ), this );
layout->addWidget( label, 0, 0 );
m_destination = new QComboBox( this );
m_destination->insertStringList( *(m_packman->destinations()) );
layout->addWidget( m_destination, 0, 1 );
connect( m_destination, SIGNAL(highlighted(const QString&)),
this, SLOT(slotDisplayAvailSpace(const QString&)) );
label = new QLabel( tr( "Space Avail" ), this );
layout->addWidget( label, 1, 0 );
m_availSpace = new QLabel( this );
layout->addWidget( m_availSpace, 1, 1 );
// TODO - select correct destination
slotDisplayAvailSpace( m_destination->currentText() );
}
else
{
m_destination = 0x0;
m_availSpace = 0x0;
}
QGroupBox *groupBox = new QGroupBox( 0, Qt::Vertical, tr( "Output" ), this );
groupBox->layout()->setSpacing( 0 );
groupBox->layout()->setMargin( 4 );
QVBoxLayout *groupBoxLayout = new QVBoxLayout( groupBox->layout() );
m_output = new QMultiLineEdit( groupBox );
m_output->setReadOnly( true );
groupBoxLayout->addWidget( m_output );
layout->addMultiCellWidget( groupBox, 2, 2, 0, 1 );
m_btnStart = new QPushButton( Resource::loadPixmap( "packagemanager/apply" ), tr( "Start" ), this );
layout->addWidget( m_btnStart, 3, 0 );
connect( m_btnStart, SIGNAL(clicked()), this, SLOT(slotBtnStart()) );
m_btnOptions = new QPushButton( Resource::loadPixmap( "SettingsIcon" ), tr( "Options" ), this );
layout->addWidget( m_btnOptions, 3, 1 );
connect( m_btnOptions, SIGNAL( clicked() ), this, SLOT(slotBtnOptions()) );
// Display packages being acted upon in output widget
for( int i = 0; i < m_numCommands; i++ )
{
if ( m_packages[ i ] )
{
QString lineStr = tr( "Packages to " );
switch( m_command[ i ] )
{
case OPackage::Install : lineStr.append( tr( "install" ) );
break;
case OPackage::Remove : lineStr.append( tr( "remove" ) );
break;
case OPackage::Upgrade : lineStr.append( tr( "upgrade" ) );
break;
+ case OPackage::Download : lineStr.append( tr( "download" ) );
+ break;
default :
break;
};
lineStr.append( ":\n" );
for ( QStringList::Iterator it = m_packages[ i ]->begin(); it != m_packages[ i ]->end(); ++it )
{
lineStr.append( QString( "\t%1\n" ).arg( ( *it ) ) );
}
m_output->append( lineStr );
}
}
m_output->append( tr( "Press the start button to begin.\n" ) );
m_output->setCursorPosition( m_output->numLines(), 0 );
}
InstallDlg::~InstallDlg()
{
for( int i = 0; i < m_numCommands; i++ )
{
if ( m_packages[ i ] )
delete m_packages[ i ];
}
}
void InstallDlg::slotDisplayAvailSpace( const QString &destination )
{
// If available space is not displayed, exit
if ( !m_availSpace )
return;
QString space = tr( "Unknown" );
// Get destination
OConfItem *dest = m_packman->findConfItem( OConfItem::Destination, destination );
if ( dest )
{
// Calculate available space
struct statfs fs;
if ( !statfs( dest->value(), &fs ) )
{
long mult = fs.f_bsize / 1024;
long div = 1024 / fs.f_bsize;
if ( !mult ) mult = 1;
if ( !div ) div = 1;
long avail = fs.f_bavail * mult / div;
space = tr( "%1 Kb" ).arg( avail );
}
}
// Display available space
m_availSpace->setText( space );
}
void InstallDlg::slotBtnStart()
{
QString btnText = m_btnStart->text();
if ( btnText == tr( "Abort" ) )
{
// Prevent unexecuted commands from executing
m_currCommand = 999;
// Allow user to close dialog
m_btnStart->setText( tr( "Close" ) );
m_btnStart->setIconSet( Resource::loadPixmap( "enter" ) );
return;
}
else if ( btnText == tr( "Close" ) )
{
// TODO - force reload of package data
emit closeInstallDlg();
return;
}
// Start was clicked, start executing
m_btnOptions->setEnabled( false );
if ( m_numCommands > 1 )
{
m_btnStart->setText( tr( "Abort" ) );
m_btnStart->setIconSet( Resource::loadPixmap( "close" ) );
}
else
{
m_btnStart->setEnabled( false );
}
QString dest;
if ( m_destination )
dest = m_destination->currentText();
diff --git a/noncore/settings/packagemanager/mainwindow.cpp b/noncore/settings/packagemanager/mainwindow.cpp
index 4611404..486561d 100644
--- a/noncore/settings/packagemanager/mainwindow.cpp
+++ b/noncore/settings/packagemanager/mainwindow.cpp
@@ -1,269 +1,270 @@
/*
                This file is part of the OPIE Project
=. Copyright (c) 2003 Dan Williams <drw@handhelds.org>
             .=l.
           .>+-=
 _;:,     .>    :=|. This file is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This file is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
..}^=.=       =       ; Public License for more details.
++=   -.     .`     .:
 :     =  ...= . :.=- You should have received a copy of the GNU
 -.   .:....=;==+<; General Public License along with this file;
  -_. . .   )=.  = see the file COPYING. If not, write to the
    --        :-=` Free Software Foundation, Inc.,
59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include <qaction.h>
+#include <qdir.h>
#include <qlayout.h>
#include <qlineedit.h>
#include <qmenubar.h>
#include <qmessagebox.h>
#include <qpopupmenu.h>
#include <qtimer.h>
#include <qtoolbar.h>
#include <qwhatsthis.h>
+#include <qpe/qcopenvelope_qws.h>
#include <qpe/qpeapplication.h>
#include <qpe/resource.h>
#include "mainwindow.h"
#include "installdlg.h"
#include "filterdlg.h"
#include "promptdlg.h"
+#include "entrydlg.h"
MainWindow::MainWindow( QWidget *parent, const char *name, WFlags fl )
: QMainWindow( parent, name, fl || WStyle_ContextHelp )
, m_config( "packman" )
, m_packman( &m_config, this )
, m_menuBar( this )
, m_toolBar( this )
, m_findBar( this )
, m_widgetStack( this )
, m_packageList( this )
, m_statusWidget( this )
, m_statusText( &m_statusWidget )
, m_statusBar( &m_statusWidget )
, m_iconUpdated( Resource::loadPixmap( "packagemanager/updated" ) )
, m_iconInstalled( Resource::loadPixmap( "installed" ) )
, m_iconNull( m_iconUpdated.size() )
, m_filterName( QString::null )
, m_filterServer( QString::null )
, m_filterDest( QString::null )
, m_filterStatus( OPackageManager::NotDefined )
, m_filterCategory( QString::null )
{
// setCaption( tr( "Package Manager" ) );
m_iconNull.fill( colorGroup().base() );
connect( &m_widgetStack, SIGNAL(aboutToShow(QWidget*)), this, SLOT(slotWidgetStackShow(QWidget*)) );
// Initialize widget stack, package list and status widget
initStatusWidget();
initPackageList();
m_widgetStack.addWidget( &m_statusWidget, 2 );
m_widgetStack.addWidget( &m_packageList, 1 );
setCentralWidget( &m_widgetStack );
// Initialize remaining user interface items
initUI();
// Initialize package information
QTimer::singleShot( 100, this, SLOT( initPackageInfo() ) );
}
void MainWindow::closeEvent( QCloseEvent *event )
{
// Close app only if either the package or status widgets are currently active
bool close = m_widgetStack.visibleWidget() == &m_packageList ||
m_widgetStack.visibleWidget() == &m_statusWidget;
if ( close )
{
// TODO - write out application configuration settings
// Write out package manager configuration settings
m_packman.saveSettings();
event->accept();
}
else
{
delete m_widgetStack.visibleWidget();
m_widgetStack.raiseWidget( &m_packageList );
event->ignore();
}
}
void MainWindow::initPackageList()
{
m_packageList.addColumn( tr( "Packages" ) );
QWhatsThis::add( &m_packageList, tr( "This is a listing of all packages.\n\nA blue dot next to the package name indicates that the package is currently installed.\n\nA blue dot with a star indicates that a newer version of the package is available from the server feed.\n\nClick inside the box at the left to select a package." ) );
QPEApplication::setStylusOperation( m_packageList.viewport(), QPEApplication::RightOnHold );
}
void MainWindow::initStatusWidget()
{
QVBoxLayout *layout = new QVBoxLayout( &m_statusWidget, 4, 4 );
m_statusText.setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
layout->addWidget( &m_statusText );
connect( &m_packman, SIGNAL(initStatus(int)), this, SLOT(slotInitStatusBar(int)) );
connect( &m_packman, SIGNAL(statusText(const QString &)), this, SLOT(slotStatusText(const QString &)) );
connect( &m_packman, SIGNAL(statusBar(int)), this, SLOT(slotStatusBar(int)) );
layout->addWidget( &m_statusBar );
}
void MainWindow::initUI()
{
// Build menu and tool bars
setToolBarsMovable( false );
m_menuBar.setHorizontalStretchable( true );
QMenuBar *mb = new QMenuBar( &m_menuBar );
mb->setMargin( 0 );
// Find toolbar
addToolBar( &m_findBar, QMainWindow::Top, true );
m_findBar.setHorizontalStretchable( true );
m_findEdit = new QLineEdit( &m_findBar );
QWhatsThis::add( m_findEdit, tr( "Type the text to search for here." ) );
m_findBar.setStretchableWidget( m_findEdit );
connect( m_findEdit, SIGNAL(textChanged(const QString &)), this, SLOT(slotFindChanged(const QString &)) );
// Packages menu
QPopupMenu *popup = new QPopupMenu( this );
QAction *a = new QAction( tr( "Update lists" ), Resource::loadPixmap( "packagemanager/update" ), QString::null, 0, this, 0 );
a->setWhatsThis( tr( "Click here to update package lists from servers." ) );
connect( a, SIGNAL(activated()), this, SLOT(slotUpdate()) );
a->addTo( popup );
a->addTo( &m_toolBar );
QAction *actionUpgrade = new QAction( tr( "Upgrade" ), Resource::loadPixmap( "packagemanager/upgrade" ), QString::null, 0, this, 0 );
actionUpgrade->setWhatsThis( tr( "Click here to upgrade all installed packages if a newer version is available." ) );
connect( actionUpgrade, SIGNAL(activated()), this, SLOT(slotUpgrade()) );
actionUpgrade->addTo( popup );
actionUpgrade->addTo( &m_toolBar );
-/*
QPixmap iconDownload = Resource::loadPixmap( "packagemanager/download" );
QPixmap iconRemove = Resource::loadPixmap( "packagemanager/remove" );
QAction *actionDownload = new QAction( tr( "Download" ), iconDownload, QString::null, 0, this, 0 );
actionDownload->setWhatsThis( tr( "Click here to download the currently selected package(s)." ) );
connect( actionDownload, SIGNAL(activated()), this, SLOT(slotDownload()) );
actionDownload->addTo( popup );
actionDownload->addTo( &m_toolBar );
-*/
a = new QAction( tr( "Apply changes" ), Resource::loadPixmap( "packagemanager/apply" ), QString::null, 0, this, 0 );
a->setWhatsThis( tr( "Click here to install, remove or upgrade currently selected package(s)." ) );
connect( a, SIGNAL(activated()), this, SLOT(slotApply()) );
a->addTo( popup );
a->addTo( &m_toolBar );
popup->insertSeparator();
a = new QAction( tr( "Configure" ), Resource::loadPixmap( "SettingsIcon" ), QString::null, 0, this, 0 );
a->setWhatsThis( tr( "Click here to configure this application." ) );
connect( a, SIGNAL(activated()), this, SLOT(slotConfigure()) );
a->addTo( popup );
mb->insertItem( tr( "Actions" ), popup );
// View menu
popup = new QPopupMenu( this );
m_actionShowNotInstalled = new QAction( tr( "Show packages not installed" ), QString::null, 0, this, 0 );
m_actionShowNotInstalled->setToggleAction( true );
m_actionShowNotInstalled->setWhatsThis( tr( "Click here to show packages available which have not been installed." ) );
connect( m_actionShowNotInstalled, SIGNAL(activated()), this, SLOT(slotShowNotInstalled()) );
m_actionShowNotInstalled->addTo( popup );
m_actionShowInstalled = new QAction( tr( "Show installed packages" ), QString::null, 0, this, 0 );
m_actionShowInstalled->setToggleAction( true );
m_actionShowInstalled->setWhatsThis( tr( "Click here to show packages currently installed on this device." ) );
connect( m_actionShowInstalled, SIGNAL(activated()), this, SLOT(slotShowInstalled()) );
m_actionShowInstalled->addTo( popup );
m_actionShowUpdated = new QAction( tr( "Show updated packages" ), QString::null, 0, this, 0 );
m_actionShowUpdated->setToggleAction( true );
m_actionShowUpdated->setWhatsThis( tr( "Click here to show packages currently installed on this device which have a newer version available." ) );
connect( m_actionShowUpdated, SIGNAL(activated()), this, SLOT(slotShowUpdated()) );
m_actionShowUpdated->addTo( popup );
popup->insertSeparator();
a = new QAction( tr( "Configure filter" ), QString::null, 0, this, 0 );
a->setWhatsThis( tr( "Click here to change package filter criteria." ) );
connect( a, SIGNAL(activated()), this, SLOT(slotFilterChange()) );
a->addTo( popup );
m_actionFilter = new QAction( tr( "Filter" ), Resource::loadPixmap( "packagemanager/filter" ),
QString::null, 0, this, 0 );
m_actionFilter->setToggleAction( true );
m_actionFilter->setWhatsThis( tr( "Click here to apply current filter." ) );
connect( m_actionFilter, SIGNAL(toggled(bool)), this, SLOT(slotFilter(bool)) );
m_actionFilter->addTo( popup );
popup->insertSeparator();
a = new QAction( tr( "Find" ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 );
a->setWhatsThis( tr( "Click here to search for text in package names." ) );
connect( a, SIGNAL(activated()), this, SLOT(slotFindShowToolbar()) );
a->addTo( popup );
m_actionFindNext = new QAction( tr( "Find next" ), Resource::loadIconSet( "next" ), QString::null, 0, this, 0 );
m_actionFindNext->setEnabled( false );
m_actionFindNext->setWhatsThis( tr( "Click here to find the next package name containing the text you are searching for." ) );
connect( m_actionFindNext, SIGNAL(activated()), this, SLOT(slotFindNext()) );
m_actionFindNext->addTo( popup );
m_actionFindNext->addTo( &m_findBar );
mb->insertItem( tr( "View" ), popup );
// Finish find toolbar creation
a = new QAction( QString::null, Resource::loadPixmap( "close" ), QString::null, 0, this, 0 );
a->setWhatsThis( tr( "Click here to hide the find toolbar." ) );
connect( a, SIGNAL(activated()), this, SLOT(slotFindHideToolbar()) );
a->addTo( &m_findBar );
m_findBar.hide();
}
void MainWindow::loadPackageList( OPackageList *packages, bool clearList )
{
if ( clearList )
m_packageList.clear();
if ( packages )
{
for ( OPackageListIterator packageIt( *packages ); packageIt.current(); ++packageIt )
{
OPackage *package = packageIt.current();
QCheckListItem *item = new QCheckListItem( &m_packageList, package->name(),
QCheckListItem::CheckBox );
m_packageList.insertItem( item );
// If a different version of package is available, show update available icon
// Otherwise, show installed icon
if ( !package->versionInstalled().isNull() )
{
if ( m_packman.compareVersions( package->version(), package->versionInstalled() ) == 1 )
item->setPixmap( 0, m_iconUpdated );
else
item->setPixmap( 0, m_iconInstalled );
@@ -277,348 +278,349 @@ void MainWindow::loadPackageList( OPackageList *packages, bool clearList )
void MainWindow::searchForPackage( const QString &text )
{
if ( !text.isEmpty() )
{
// look through package list for text startng at current position
QCheckListItem *start = static_cast<QCheckListItem *>(m_packageList.currentItem());
if ( start == 0 )
start = static_cast<QCheckListItem *>(m_packageList.firstChild());
// for ( QCheckListItem *item = static_cast<QCheckListItem *>(start->nextSibling()); item != 0 ;
for ( QCheckListItem *item = static_cast<QCheckListItem *>(start); item != 0 ;
item = static_cast<QCheckListItem *>(item->nextSibling()) )
{
if ( item->text().lower().find( text ) != -1 )
{
m_packageList.ensureItemVisible( item );
m_packageList.setCurrentItem( item );
break;
}
}
}
}
void MainWindow::initPackageInfo()
{
m_widgetStack.raiseWidget( &m_statusWidget );
// Load package list
m_packman.loadAvailablePackages();
m_packman.loadInstalledPackages();
OPackageList *packageList = m_packman.packages();
if ( packageList )
{
loadPackageList( packageList, true );
delete packageList;
}
m_widgetStack.raiseWidget( &m_packageList );
}
void MainWindow::slotWidgetStackShow( QWidget *widget )
{
if ( widget == &m_packageList )
{
setCaption( tr( "Package Manager" ) );
m_menuBar.show();
m_toolBar.show();
}
else
{
m_menuBar.hide();
m_toolBar.hide();
}
}
void MainWindow::slotInitStatusBar( int numSteps )
{
m_statusBar.setTotalSteps( numSteps );
}
void MainWindow::slotStatusText( const QString &status )
{
m_statusText.setText( status );
}
void MainWindow::slotStatusBar( int currStep )
{
m_statusBar.setProgress( currStep );
}
void MainWindow::slotUpdate()
{
// Create package manager output widget
InstallDlg *dlg = new InstallDlg( this, &m_packman, tr( "Update package information" ), false,
OPackage::Update );
connect( dlg, SIGNAL(closeInstallDlg()), this, SLOT(slotCloseInstallDlg()) );
// Display widget
m_widgetStack.addWidget( dlg, 3 );
m_widgetStack.raiseWidget( dlg );
}
void MainWindow::slotUpgrade()
{
// Create package manager output widget
InstallDlg *dlg = new InstallDlg( this, &m_packman, tr( "Upgrade installed packages" ), false,
OPackage::Upgrade );
connect( dlg, SIGNAL(closeInstallDlg()), this, SLOT(slotCloseInstallDlg()) );
// Display widget
m_widgetStack.addWidget( dlg, 3 );
m_widgetStack.raiseWidget( dlg );
}
-/*
void MainWindow::slotDownload()
{
// Retrieve list of packages selected for download (if any)
QStringList *workingPackages = new QStringList();
for ( QCheckListItem *item = static_cast<QCheckListItem *>(m_packageList.firstChild());
item != 0 ;
item = static_cast<QCheckListItem *>(item->nextSibling()) )
{
if ( item->isOn() )
workingPackages->append( item->text() );
}
if ( workingPackages->isEmpty() )
{
- // No packages were selected, prompt for URL of package to download
+ QMessageBox::information( this, tr( "Nothing to do" ), tr( "No packages selected" ), tr( "OK" ) );
+ return;
}
else
{
// Download selected packages
m_config.setGroup( "settings" );
QString workingDir = m_config.readEntry( "DownloadDir", "/tmp" );
-// QString text = InputDialog::getText( tr( "Download to where" ), tr( "Enter path to download to" ), workingDir, &ok, this );
-// if ( ok && !text.isEmpty() )
-// workingDir = text; // user entered something and pressed ok
-// else
-// return; // user entered nothing or pressed cancel
+ bool ok = false;
+ QString text = EntryDlg::getText( tr( "Download" ), tr( "Enter path to download package to:" ), workingDir, &ok, this );
+ if ( ok && !text.isEmpty() )
+ workingDir = text; // user entered something and pressed ok
+ else
+ return; // user entered nothing or pressed cancel
-// // Store download directory in config file
-// m_config.writeEntry( "DownloadDir", workingDir );
+ // Store download directory in config file
+ m_config.writeEntry( "DownloadDir", workingDir );
// Get starting directory
-// char initDir[PATH_MAX];
-// getcwd( initDir, PATH_MAX );
-
- // Download packages
-
- }
+ QDir::setCurrent( workingDir );
// Create package manager output widget
InstallDlg *dlg = new InstallDlg( this, &m_packman, tr( "Download packages" ), false,
OPackage::Download, workingPackages );
connect( dlg, SIGNAL(closeInstallDlg()), this, SLOT(slotCloseInstallDlg()) );
// Display widget
m_widgetStack.addWidget( dlg, 3 );
m_widgetStack.raiseWidget( dlg );
}
-*/
+}
void MainWindow::slotApply()
{
QStringList *removeList = 0x0;
QStringList *installList = 0x0;
QStringList *upgradeList = 0x0;
for ( QCheckListItem *item = static_cast<QCheckListItem *>(m_packageList.firstChild());
item != 0 ;
item = static_cast<QCheckListItem *>(item->nextSibling()) )
{
if ( item->isOn() )
{
OPackage *package = m_packman.findPackage( item->text() );
if ( package )
{
if ( !package->versionInstalled().isNull() )
{
if ( m_packman.compareVersions( package->version(), package->versionInstalled() ) == 1 )
{
// Remove/upgrade package
int answer = PromptDlg::ask( tr( "Remove or upgrade" ),
tr( QString( "Do you wish to remove or upgrade\n%1?" ).arg( item->text() ) ),
tr( "Remove" ), tr( "Upgrade" ), this );
if ( answer == 1 ) // Remove
{
if ( !removeList )
removeList = new QStringList();
removeList->append( item->text() );
}
else if ( answer == 2 ) // Upgrade
{
if ( !upgradeList )
upgradeList = new QStringList();
upgradeList->append( item->text() );
}
}
else
{
// Remove/reinstall package
int answer = PromptDlg::ask( tr( "Remove or reinstall" ),
tr( QString( "Do you wish to remove or reinstall\n%1?" ).arg( item->text() ) ),
tr( "Remove" ), tr( "Reinstall" ), this );
if ( answer == 1 ) // Remove
{
if ( !removeList )
removeList = new QStringList();
removeList->append( item->text() );
}
else if ( answer == 2 ) // Reinstall
{
if ( !installList )
installList = new QStringList();
installList->append( item->text() );
}
}
}
else
{
// Install package
if ( !installList )
installList = new QStringList();
installList->append( item->text() );
}
}
}
}
// If nothing is selected, display message and exit
if ( !removeList && !installList && !upgradeList )
{
QMessageBox::information( this, tr( "Nothing to do" ), tr( "No packages selected" ), tr( "OK" ) );
return;
}
// Send command only if there are packages to process
OPackage::Command removeCmd = OPackage::NotDefined;
if ( removeList && !removeList->isEmpty() )
removeCmd = OPackage::Remove;
OPackage::Command installCmd = OPackage::NotDefined;
if ( installList && !installList->isEmpty() )
installCmd = OPackage::Install;
OPackage::Command upgradeCmd = OPackage::NotDefined;
if ( upgradeList && !upgradeList->isEmpty() )
upgradeCmd = OPackage::Upgrade;
// Create package manager output widget
InstallDlg *dlg = new InstallDlg( this, &m_packman, tr( "Apply changes" ), true,
removeCmd, removeList,
installCmd, installList,
upgradeCmd, upgradeList );
connect( dlg, SIGNAL(closeInstallDlg()), this, SLOT(slotCloseInstallDlg()) );
// Display widget
m_widgetStack.addWidget( dlg, 3 );
m_widgetStack.raiseWidget( dlg );
}
void MainWindow::slotCloseInstallDlg()
{
// Close install dialog
delete m_widgetStack.visibleWidget();
// Reload package list
initPackageInfo();
+
+ // Update Opie launcher links
+ QCopEnvelope e("QPE/System", "linkChanged(QString)");
+ QString lf = QString::null;
+ e << lf;
}
void MainWindow::slotConfigure()
{
if ( m_packman.configureDlg( false ) )
{
if ( PromptDlg::ask( tr( "Config updated" ),
tr( "The configuration has been updated. Do you want to update server and package information now?" ),
tr( "Yes" ), tr( "No" ), this ) == 1 )
{
// Update package list and reload package info
slotUpdate();
}
}
}
void MainWindow::slotShowNotInstalled()
{
OPackageList *packageList;
if ( m_actionShowNotInstalled->isOn() )
{
m_actionShowInstalled->setOn( false );
m_actionShowUpdated->setOn( false );
packageList = m_packman.filterPackages( QString::null, QString::null, QString::null,
OPackageManager::NotInstalled, QString::null );
}
else
packageList = m_packman.packages();
if ( packageList )
{
loadPackageList( packageList, true );
delete packageList;
}
}
void MainWindow::slotShowInstalled()
{
OPackageList *packageList;
if ( m_actionShowInstalled->isOn() )
{
m_actionShowNotInstalled->setOn( false );
m_actionShowUpdated->setOn( false );
packageList = m_packman.filterPackages( QString::null, QString::null, QString::null,
OPackageManager::Installed, QString::null );
}
else
packageList = m_packman.packages();
if ( packageList )
{
loadPackageList( packageList, true );
delete packageList;
}
}
void MainWindow::slotShowUpdated()
{
OPackageList *packageList;
if ( m_actionShowUpdated->isOn() )
{
m_actionShowInstalled->setOn( false );
m_actionShowNotInstalled->setOn( false );
packageList = m_packman.filterPackages( QString::null, QString::null, QString::null,
OPackageManager::Updated, QString::null );
}
else
packageList = m_packman.packages();
if ( packageList )
{
loadPackageList( packageList, true );
delete packageList;
}
}
void MainWindow::slotFilterChange()
{
FilterDlg dlg( this, &m_packman, m_filterName, m_filterServer, m_filterDest, m_filterStatus,
m_filterCategory );
if ( dlg.exec() == QDialog::Accepted )
{
m_filterName = dlg.name();
m_filterServer = dlg.server();
m_filterDest = dlg.destination();
m_filterStatus = dlg.status();
m_filterCategory = dlg.category();
m_actionFilter->setOn( true );
slotFilter( true );
}
else
{
m_actionFilter->setOn( false );
slotFilter( false );
}
}
diff --git a/noncore/settings/packagemanager/mainwindow.h b/noncore/settings/packagemanager/mainwindow.h
index 49bb66c..285cddf 100644
--- a/noncore/settings/packagemanager/mainwindow.h
+++ b/noncore/settings/packagemanager/mainwindow.h
@@ -21,116 +21,116 @@
 :     =  ...= . :.=- You should have received a copy of the GNU
 -.   .:....=;==+<; General Public License along with this file;
  -_. . .   )=.  = see the file COPYING. If not, write to the
    --        :-=` Free Software Foundation, Inc.,
59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <qlabel.h>
#include <qlistview.h>
#include <qmainwindow.h>
#include <qpixmap.h>
#include <qprogressbar.h>
#include <qtoolbar.h>
#include <qwidgetstack.h>
#include <qpe/config.h>
#include "opackagemanager.h"
class QAction;
class QLineEdit;
class MainWindow :public QMainWindow
{
Q_OBJECT
public:
MainWindow( QWidget *parent = 0x0, const char *name = 0x0, WFlags fl = 0 );
static QString appName() { return QString::fromLatin1( "packagemanager" ); };
protected:
void closeEvent( QCloseEvent *event );
private:
Config m_config; // Configuration file
OPackageManager m_packman; // Package manager
// Toolbars
QToolBar m_menuBar; // Main toolbar containing menu
QToolBar m_toolBar; // Main toolbar
QToolBar m_findBar; // Find toolbar
QWidgetStack m_widgetStack; // Main widget stack which contains m_packageList & m_statusWidget
QListView m_packageList; // Main list view of all packages
QLineEdit *m_findEdit; // Line edit box used for find toolbar
// Status widget controls
QWidget m_statusWidget; // Widget to display status during long operations
QLabel m_statusText; // Text status message
QProgressBar m_statusBar; // Progress bar showing % completed
// Icon pixmaps
QPixmap m_iconUpdated; // Cached icon which shows when package can be updated
QPixmap m_iconInstalled; // Cached icon which shows when package is installed
QPixmap m_iconNull; // Cached icon which shows when package is not installed
// Menu/tool bar actions
QAction *m_actionShowNotInstalled; // Action to show pakages not currently installed
QAction *m_actionShowInstalled; // Action to show pakages currently installed
QAction *m_actionShowUpdated; // Action to show pakages currently installed with update available
QAction *m_actionFilter; // Action to filter packages
QAction *m_actionFindNext; // Action to find next match
// Cached filter settings
QString m_filterName; // Cached name filter value
QString m_filterServer; // Cached server name filter value
QString m_filterDest; // Cached destination name filter value
OPackageManager::Status m_filterStatus; // Cached status filter value
QString m_filterCategory; // Cached category filter value
void initPackageList();
void initStatusWidget();
void initUI();
void loadPackageList( OPackageList *packages = 0x0, bool clearList = true );
void searchForPackage( const QString &text );
private slots:
void initPackageInfo();
void slotWidgetStackShow( QWidget *widget );
// Status widget slots
void slotInitStatusBar( int numSteps );
void slotStatusText( const QString &status );
void slotStatusBar( int currStep );
// Actions menu action slots
void slotUpdate();
void slotUpgrade();
-// void slotDownload();
+ void slotDownload();
void slotApply();
void slotCloseInstallDlg();
void slotConfigure();
// View menu action slots
void slotShowNotInstalled();
void slotShowInstalled();
void slotShowUpdated();
void slotFilterChange();
void slotFilter( bool isOn );
// Find action slots
void slotFindShowToolbar();
void slotFindHideToolbar();
void slotFindChanged( const QString &findText );
void slotFindNext();
};
#endif
diff --git a/noncore/settings/packagemanager/oipkg.cpp b/noncore/settings/packagemanager/oipkg.cpp
index eeb0131..ed9ea10 100644
--- a/noncore/settings/packagemanager/oipkg.cpp
+++ b/noncore/settings/packagemanager/oipkg.cpp
@@ -234,194 +234,199 @@ OPackageList *OIpkg::installedPackages( const QString &destName, const QString &
// Allocate new package and insert into list
if ( newPackage && !key.isEmpty() )
{
// Add to list only if it has a valid name and is installed
if ( !name.isNull() && status.contains( " installed" ) )
{
pl->append( new OPackage( name, QString::null, version, QString::null, destName ) );
name = QString::null;
version = QString::null;
status = QString::null;
newPackage = false;
}
}
// Update package data
if ( key == "Package" )
name = value;
else if ( key == "Version" )
version = value;
else if ( key == "Status" )
status = value;
else if ( key.isEmpty() && value.isEmpty() )
newPackage = true;
// Skip past all description lines
if ( key == "Description" )
{
line = t.readLine();
while ( !line.isEmpty() && line.find( ':', 0 ) == -1 && !t.eof() )
line = t.readLine();
}
else
line = t.readLine();
}
f.close();
return pl;
}
bool OIpkg::executeCommand( OPackage::Command command, QStringList *parameters, const QString &destination,
const QObject *receiver, const char *slotOutput, bool rawOutput )
{
if ( command == OPackage::NotDefined )
return false;
// Set ipkg run-time options/arguments
m_ipkgArgs.force_depends = ( m_ipkgExecOptions & FORCE_DEPENDS );
m_ipkgArgs.force_reinstall = ( m_ipkgExecOptions & FORCE_REINSTALL );
// TODO m_ipkgArgs.force_remove = ( m_ipkgExecOptions & FORCE_REMOVE );
m_ipkgArgs.force_overwrite = ( m_ipkgExecOptions & FORCE_OVERWRITE );
m_ipkgArgs.verbosity = m_ipkgExecVerbosity;
if ( m_ipkgArgs.dest )
free( m_ipkgArgs.dest );
if ( !destination.isNull() )
{
int len = destination.length() + 1;
m_ipkgArgs.dest = (char *)malloc( len );
strncpy( m_ipkgArgs.dest, destination, destination.length() );
m_ipkgArgs.dest[ len - 1 ] = '\0';
}
else
m_ipkgArgs.dest = 0x0;
// Connect output signal to widget
if ( rawOutput )
{
if ( slotOutput )
connect( this, SIGNAL(execOutput(char *)), receiver, slotOutput );
}
else
{
// TODO - connect to local slot and parse output before emitting execOutput
}
switch( command )
{
case OPackage::Update : ipkg_lists_update( &m_ipkgArgs );
break;
case OPackage::Upgrade : ipkg_packages_upgrade( &m_ipkgArgs );
break;
case OPackage::Install : {
for ( QStringList::Iterator it = parameters->begin(); it != parameters->end(); ++it )
{
ipkg_packages_install( &m_ipkgArgs, (*it) );
}
};
break;
case OPackage::Remove : {
for ( QStringList::Iterator it = parameters->begin(); it != parameters->end(); ++it )
{
ipkg_packages_remove( &m_ipkgArgs, (*it), true );
}
};
break;
- //case OPackage::Download : ;
- // break;
+ case OPackage::Download : {
+ for ( QStringList::Iterator it = parameters->begin(); it != parameters->end(); ++it )
+ {
+ ipkg_packages_download( &m_ipkgArgs, (*it) );
+ }
+ };
+ break;
default : break;
};
return true;
}
void OIpkg::ipkgOutput( char *msg )
{
emit execOutput( msg );
}
void OIpkg::loadConfiguration()
{
if ( m_confInfo )
delete m_confInfo;
// Load configuration item list
m_confInfo = new OConfItemList();
QStringList confFiles;
QDir confDir( IPKG_CONF_DIR );
if ( confDir.exists() )
{
confDir.setNameFilter( "*.conf" );
confDir.setFilter( QDir::Files );
confFiles = confDir.entryList( "*.conf", QDir::Files );
confFiles << IPKG_CONF;
for ( QStringList::Iterator it = confFiles.begin(); it != confFiles.end(); ++it )
{
// Create absolute file path if necessary
QString absFile = (*it);
if ( !absFile.startsWith( "/" ) )
absFile.prepend( QString( IPKG_CONF_DIR ) + "/" );
// Read in file
QFile f( absFile );
if ( f.open( IO_ReadOnly ) )
{
QTextStream s( &f );
while ( !s.eof() )
{
QString line = s.readLine().simplifyWhiteSpace();
// Parse line and save info to the conf options list
if ( !line.isEmpty() )
{
if ( !line.startsWith( "#" ) ||
line.startsWith( "#src" ) ||
line.startsWith( "#dest" ) ||
line.startsWith( "#arch" ) ||
line.startsWith( "#option" ) )
{
int pos = line.find( ' ', 1 );
// Type
QString typeStr = line.left( pos );
OConfItem::Type type;
if ( typeStr == "src" || typeStr == "#src" )
type = OConfItem::Source;
else if ( typeStr == "dest" || typeStr == "#dest" )
type = OConfItem::Destination;
else if ( typeStr == "option" || typeStr == "#option" )
type = OConfItem::Option;
else if ( typeStr == "arch" || typeStr == "#arch" )
type = OConfItem::Arch;
else
type = OConfItem::NotDefined;
++pos;
int endpos = line.find( ' ', pos );
// Name
QString name = line.mid( pos, endpos - pos );
// Value
QString value = "";
if ( endpos > -1 )
value = line.right( line.length() - endpos - 1 );
// Active
bool active = !line.startsWith( "#" );
// Add to list
m_confInfo->append( new OConfItem( absFile, type, name, value, active ) );
}
}
}
f.close();
}
}
}
// Load Ipkg execution options from application configuration file
if ( m_config )
diff --git a/noncore/settings/packagemanager/packagemanager.pro b/noncore/settings/packagemanager/packagemanager.pro
index 55af13e..9a64322 100644
--- a/noncore/settings/packagemanager/packagemanager.pro
+++ b/noncore/settings/packagemanager/packagemanager.pro
@@ -1,36 +1,38 @@
CONFIG = qt warn_on release quick-app
//TEMPLATE = app
//CONFIG += qte warn_on debug
//DESTDIR = $(OPIEDIR)/bin
SOURCES = opackage.cpp \
oconfitem.cpp \
oipkg.cpp \
oipkgconfigdlg.cpp \
opackagemanager.cpp \
mainwindow.cpp \
installdlg.cpp \
packageinfodlg.cpp \
filterdlg.cpp \
promptdlg.cpp \
+ entrydlg.cpp \
main.cpp
HEADERS = opackage.h \
oconfitem.h \
oipkg.h \
oipkgconfigdlg.h \
opackagemanager.h \
mainwindow.h \
installdlg.h \
packageinfodlg.h \
filterdlg.h \
- promptdlg.h
+ promptdlg.h \
+ entrydlg.h
DEFINES += IPKG_LIB
DEFINES += HAVE_MKDTEMP
TARGET = packagemanager
INCLUDEPATH += $(OPIEDIR)/include $(IPKGDIR)
DEPENDPATH += $(OPIEDIR)/include
LIBS += -lqpe -lopie -lipkg
include ( $(OPIEDIR)/include.pro )
diff --git a/noncore/settings/packagemanager/promptdlg.cpp b/noncore/settings/packagemanager/promptdlg.cpp
index 3122699..bb27190 100644
--- a/noncore/settings/packagemanager/promptdlg.cpp
+++ b/noncore/settings/packagemanager/promptdlg.cpp
@@ -1,140 +1,140 @@
/*
                This file is part of the OPIE Project
=. Copyright (c) 2003 Dan Williams <drw@handhelds.org>
             .=l.
           .>+-=
 _;:,     .>    :=|. This file is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This file is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
..}^=.=       =       ; Public License for more details.
++=   -.     .`     .:
 :     =  ...= . :.=- You should have received a copy of the GNU
 -.   .:....=;==+<; General Public License along with this file;
  -_. . .   )=.  = see the file COPYING. If not, write to the
    --        :-=` Free Software Foundation, Inc.,
59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include "promptdlg.h"
#include <qlabel.h>
#include <qlayout.h>
#include <qpushbutton.h>
#include <qwidgetlist.h>
#include <qpe/qpeapplication.h>
PromptDlg::PromptDlg( const QString &caption, const QString &text, const QString &btn1, const QString &btn2,
QWidget *parent )
: QWidget( parent, QString::null, WType_Modal | WType_TopLevel | WStyle_Dialog )
, m_btnClicked( -1 )
{
setCaption( caption );
QGridLayout *layout = new QGridLayout( this, 2, 2, 4, 2 );
QLabel *label = new QLabel( text, this );
- label->setAlignment( AlignCenter | WordBreak );
+ label->setAlignment( AlignCenter | AlignTop | WordBreak );
layout->addMultiCellWidget( label, 0, 0, 0, 1 );
QPushButton *btn = new QPushButton( btn1, this );
layout->addWidget( btn, 1, 0 );
connect( btn, SIGNAL(clicked()), this, SLOT(slotBtn1Clicked()) );
btn = new QPushButton( btn2, this );
layout->addWidget( btn, 1, 1 );
connect( btn, SIGNAL(clicked()), this, SLOT(slotBtn2Clicked()) );
}
int PromptDlg::exec()
{
// Determine position of dialog. Derived from QT's QDialog::show() method.
QWidget *w = parentWidget();
QPoint p( 0, 0 );
int extraw = 0, extrah = 0;
QWidget * desk = QApplication::desktop();
if ( w )
w = w->topLevelWidget();
QWidgetList *list = QApplication::topLevelWidgets();
QWidgetListIt it( *list );
while ( (extraw == 0 || extrah == 0) && it.current() != 0 )
{
int w, h;
QWidget * current = it.current();
++it;
w = current->geometry().x() - current->x();
h = current->geometry().y() - current->y();
extraw = QMAX( extraw, w );
extrah = QMAX( extrah, h );
}
delete list;
// sanity check for decoration frames. With embedding, we
// might get extraordinary values
if ( extraw >= 10 || extrah >= 40 )
extraw = extrah = 0;
if ( w )
{
// Use mapToGlobal rather than geometry() in case w might
// be embedded in another application
QPoint pp = w->mapToGlobal( QPoint(0,0) );
p = QPoint( pp.x() + w->width()/2, pp.y() + w->height()/ 2 );
}
else
p = QPoint( desk->width()/2, desk->height()/2 );
p = QPoint( p.x()-width()/2 - extraw, p.y()-height()/2 - extrah );
if ( p.x() + extraw + width() > desk->width() )
p.setX( desk->width() - width() - extraw );
if ( p.x() < 0 )
p.setX( 0 );
if ( p.y() + extrah + height() > desk->height() )
p.setY( desk->height() - height() - extrah );
if ( p.y() < 0 )
p.setY( 0 );
move( p );
show();
// Enter event loop for modality
qApp->enter_loop();
return m_btnClicked;
}
int PromptDlg::ask( const QString &caption, const QString &text, const QString &btn1, const QString &btn2,
QWidget *parent )
{
PromptDlg *dlg = new PromptDlg( caption, text, btn1, btn2, parent );
int rc = dlg->exec();
delete dlg;
return rc;
}
void PromptDlg::slotBtn1Clicked()
{
m_btnClicked = 1;
qApp->exit_loop();
}
void PromptDlg::slotBtn2Clicked()
{
m_btnClicked = 2;
qApp->exit_loop();
}