/** * Copyright 2003 Braden MacDonald * Copyright 2003 Ravikiran Rajagopal * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 program; if not, write to the Free Software * * * Please see the README * */ /** * @file UserInfo's Dialog for changing your face. * @author Braden MacDonald */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "chfacedlg.h" /** * TODO: It would be nice if the widget were in a .ui */ ChFaceDlg::ChFaceDlg(const TQString& picsdir, TQWidget *parent, const char *name, bool modal) : KDialogBase( parent, name, modal, i18n("Change your Face"), Ok|Cancel, Ok, true ) { // Global settings m_maxFaceSize = 64; TQWidget *page = new TQWidget(this); setMainWidget( page ); TQVBoxLayout *top = new TQVBoxLayout(page, 0, spacingHint()); TQLabel *header = new TQLabel( i18n("Select a new face:"), page ); top->addWidget( header ); m_FacesWidget = new TDEIconView( page ); m_FacesWidget->setSelectionMode( TQIconView::Single ); m_FacesWidget->setItemsMovable( false ); m_FacesWidget->setMinimumSize( 400, 200 ); connect( m_FacesWidget, TQ_SIGNAL( selectionChanged( TQIconViewItem * ) ), TQ_SLOT( slotFaceWidgetSelectionChanged( TQIconViewItem * ) ) ); connect( m_FacesWidget, TQ_SIGNAL( doubleClicked( TQIconViewItem *, const TQPoint & ) ), TQ_SLOT( slotOk() ) ); top->addWidget( m_FacesWidget ); // Buttons to get more pics TQHBoxLayout * morePics = new TQHBoxLayout( 0, 0, spacingHint() ); TQPushButton *browseBtn = new TQPushButton( i18n("Custom &Image..."), page ); connect( browseBtn, TQ_SIGNAL( clicked() ), TQ_SLOT( slotGetCustomImage() ) ); morePics->addWidget( browseBtn ); #if 0 TQPushButton *acquireBtn = new TQPushButton( i18n("&Acquire Image..."), page ); acquireBtn->setEnabled( false ); morePics->addWidget( acquireBtn ); #endif morePics->addStretch(); top->addLayout( morePics ); // Filling the icon view TQDir facesDir( picsdir ); if ( facesDir.exists() ) { TQStringList picslist = facesDir.entryList( TQDir::Files ); for ( TQStringList::Iterator it = picslist.begin(); it != picslist.end(); ++it ) new TQIconViewItem( m_FacesWidget, (*it).section(".",0,0), TQPixmap( picsdir + *it ) ); } m_FacesWidget->setResizeMode( TQIconView::Adjust ); //m_FacesWidget->setGridX( FACE_PIX_SIZE - 10 ); m_FacesWidget->arrangeItemsInGrid(); enableButtonOK( false ); //connect( this, TQ_SIGNAL( okClicked() ), TQ_SLOT( slotSaveCustomImage() ) ); resize( 420, 400 ); } void ChFaceDlg::addCustomPixmap( TQString imPath ) { TQImage pix( imPath ); // TODO: save pix to TMPDIR/userinfo-tmp, // then scale and copy *that* to ~/.faces if (pix.isNull()) { KMessageBox::sorry( this, i18n("There was an error loading the image.") ); return; } if ( (pix.width() > m_maxFaceSize) || (pix.height() > m_maxFaceSize) ) pix = pix.scale( m_maxFaceSize, m_maxFaceSize, TQImage::ScaleMin );// Should be no bigger than certain size. TQIconViewItem* newface = new TQIconViewItem( m_FacesWidget, TQFileInfo(imPath).fileName().section(".",0,0) , pix ); m_FacesWidget->ensureItemVisible( newface ); m_FacesWidget->setCurrentItem( newface ); } void ChFaceDlg::slotGetCustomImage( ) { KFileDialog *dlg = new KFileDialog( TQDir::homeDirPath(), KImageIO::pattern( KImageIO::Reading ), this, 0, true); dlg->setOperationMode( KFileDialog::Opening ); dlg->setCaption( i18n("Choose Image") ); dlg->setMode( KFile::File | KFile::LocalOnly ); KImageFilePreview *ip = new KImageFilePreview( dlg ); dlg->setPreviewWidget( ip ); if (dlg->exec() == TQDialog::Accepted) addCustomPixmap( dlg->selectedFile() ); // Because we give it a parent we have to close it ourselves. dlg->close(true); } #include "chfacedlg.moc"