summaryrefslogtreecommitdiff
authorzecke <zecke>2004-02-05 15:57:13 (UTC)
committer zecke <zecke>2004-02-05 15:57:13 (UTC)
commit823399a552c04821fb0b49d816d733fa21a12a21 (patch) (side-by-side diff)
treea5683ede5436c6b912a89d4ccc6cd63953214ea4
parent8cb0ae68f155c989cb9533c1f04d04ec64083708 (diff)
downloadopie-823399a552c04821fb0b49d816d733fa21a12a21.zip
opie-823399a552c04821fb0b49d816d733fa21a12a21.tar.gz
opie-823399a552c04821fb0b49d816d733fa21a12a21.tar.bz2
Stop trying to scale a null image
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/launcher/startmenu.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/core/launcher/startmenu.cpp b/core/launcher/startmenu.cpp
index f17c7f8..b84eed8 100644
--- a/core/launcher/startmenu.cpp
+++ b/core/launcher/startmenu.cpp
@@ -55,198 +55,200 @@ void StartPopupMenu::keyPressEvent( QKeyEvent *e )
} else {
QPopupMenu::keyPressEvent( e );
}
}
//---------------------------------------------------------------------------
StartMenu::StartMenu(QWidget *parent) : QLabel( parent )
{
startButtonPixmap = "go"; // No tr
int sz = AppLnk::smallIconSize()+3;
QPixmap pm;
pm.convertFromImage(Resource::loadImage( startButtonPixmap).smoothScale( sz,sz) );
setPixmap(pm);
setFocusPolicy( NoFocus );
useWidePopupMenu = true;
launchMenu = 0;
refreshMenu();
}
void StartMenu::mousePressEvent( QMouseEvent * )
{
launch();
}
StartMenu::~StartMenu()
{
clearApplets();
}
void StartMenu::createMenu()
{
clearApplets();
delete launchMenu;
launchMenu = new StartPopupMenu( this );
loadMenu( launchMenu );
loadApplets();
bool result = currentItem || menuApplets.count();
if ( result )
connect( launchMenu, SIGNAL(activated(int)), SLOT(itemSelected(int)) );
}
void StartMenu::refreshMenu()
{
Config cfg( "StartMenu" );
cfg.setGroup( "Menu" );
bool ltabs = cfg.readBoolEntry( "LauncherTabs", TRUE );
bool lot = cfg.readBoolEntry( "LauncherOther", TRUE );
useWidePopupMenu = cfg.readBoolEntry( "LauncherSubPopup", TRUE );
if ( launchMenu && !(ltabs || lot) ) return; // nothing to do
createMenu();
}
void StartMenu::itemSelected( int id )
{
if ( id == NO_ID ) return;
if ( id < 0 ) {
MenuApplet *applet = menuApplets.find( id );
if ( applet ) {
applet->iface->activated();
}
} else if ( id >= APPLNK_ID_OFFSET ) {
AppLnk * appLnk = appLnks.find( id );
if ( appLnk ) {
appLnk->execute();
}
} else {
QString *tabName = tabNames.find( id );
if ( tabName ) {
emit tabSelected( *tabName );
}
}
}
void StartMenu::createAppEntry( QPopupMenu *menu, QDir dir, QString file )
{
if ( file.right(8) == ".desktop" ) {
AppLnk* applnk = new AppLnk( dir.path() + "/" + file );
if ( !applnk->isValid() ) {
delete applnk;
return;
}
if ( applnk->type() == "Separator" ) { // No tr
menu->insertSeparator();
delete applnk;
} else {
- QPixmap test;
- test.convertFromImage(
- Resource::loadImage( applnk->icon() ).smoothScale(
- AppLnk::smallIconSize(), AppLnk::smallIconSize() ), 0 );
-
- menu->insertItem( test, applnk->name(),
+ QPixmap test;
+ QImage img = Resource::loadImage( applnk->icon() );
+ if(!img.isNull() )
+ test.convertFromImage(
+ img.smoothScale(
+ AppLnk::smallIconSize(), AppLnk::smallIconSize() ), 0 );
+
+ menu->insertItem( test, applnk->name(),
currentItem + APPLNK_ID_OFFSET );
appLnks.insert( currentItem + APPLNK_ID_OFFSET, applnk );
currentItem++;
}
}
}
void StartMenu::createDirEntry( QPopupMenu *menu, QDir dir, QString file, bool lot )
{
// do some sanity checks and collect information
if ( file == "." || file == ".." ) return;
Config cfg( dir.path() + "/" + file + "/.directory", Config::File );
if ( !cfg.isValid() ) return;
QString name = cfg.readEntry( "Name" );
QString icon = cfg.readEntry( "Icon" );
if ( !name || !icon ) return;
QDir subdir = QDir( dir );
subdir.cd( file );
subdir.setFilter( QDir::Files );
subdir.setNameFilter( "*.desktop" );
// we don' t show the menu if there are no entries
// perhaps one should check if there exist subsubdirs with entries...
if ( subdir.entryList().isEmpty() ) return;
// checks were ok
QPixmap test;
test.convertFromImage( Resource::loadImage( icon ).smoothScale(
AppLnk::smallIconSize(), AppLnk::smallIconSize() ), 0 );
if ( useWidePopupMenu ) {
// generate submenu
QPopupMenu *submenu = new QPopupMenu( menu );
connect( submenu, SIGNAL(activated(int)), SLOT(itemSelected(int)) );
menu->insertItem( test, name, submenu, NO_ID );
// ltabs is true cause else we wouldn't stuck around..
createMenuEntries( submenu, subdir, true, lot );
} else {
// no submenus - just bring corresponding tab to front
menu->insertItem( test, name, currentItem );
tabNames.insert( currentItem, new QString( file ) );
currentItem++;
}
}
void StartMenu::createMenuEntries( QPopupMenu *menu, QDir dir, bool ltabs, bool lot )
{
if ( lot ) {
dir.setFilter( QDir::Files );
dir.setNameFilter( "*.desktop" );
QStringList files = dir.entryList();
files.sort();
for ( QStringList::Iterator it = files.begin(); it != files.end(); it++ ) {
createAppEntry( menu, dir, *it );
}
}
if ( ltabs ) {
dir.setNameFilter( "*" );
dir.setFilter( QDir::Dirs );
QStringList dirs = dir.entryList();
dirs.sort();
for ( QStringList::Iterator it = dirs.begin(); it != dirs.end(); it++ ) {
createDirEntry( menu, dir, *it, lot );
}
}
}
bool StartMenu::loadMenu( QPopupMenu *menu )
{
Config cfg("StartMenu");
cfg.setGroup("Menu");
bool ltabs = cfg.readBoolEntry("LauncherTabs", TRUE);
bool lot = cfg.readBoolEntry("LauncherOther", TRUE);
useWidePopupMenu = cfg.readBoolEntry( "LauncherSubPopup", TRUE );
bool sepfirst = !ltabs && !lot;
currentItem = 0;
launchMenu->clear();
appLnks.setAutoDelete( true );
tabNames.setAutoDelete( true );
appLnks.clear();
tabNames.clear();
appLnks.setAutoDelete( false );
tabNames.setAutoDelete( false );
QDir dir( MimeType::appsFolderName(), QString::null, QDir::Name );