You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
189 lines
6.5 KiB
189 lines
6.5 KiB
15 years ago
|
/**
|
||
|
* Copyright 2003 Braden MacDonald <bradenm_k@shaw.ca>
|
||
|
* Copyright 2003 Ravikiran Rajagopal <ravi@ee.eng.ohio-state.edu>
|
||
|
*
|
||
|
* 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
|
||
|
*/
|
||
|
|
||
15 years ago
|
#include <tqstring.h>
|
||
13 years ago
|
#include <tqlayout.h>
|
||
15 years ago
|
#include <tqlabel.h>
|
||
|
#include <tqpixmap.h>
|
||
|
#include <tqimage.h>
|
||
|
#include <tqpushbutton.h>
|
||
|
#include <tqdir.h>
|
||
|
#include <tqcheckbox.h>
|
||
15 years ago
|
|
||
|
#include <kdialogbase.h>
|
||
12 years ago
|
#include <tdelocale.h>
|
||
12 years ago
|
#include <tdefiledialog.h>
|
||
15 years ago
|
#include <kiconview.h>
|
||
|
#include <kimagefilepreview.h>
|
||
|
#include <kimageio.h>
|
||
12 years ago
|
#include <tdemessagebox.h>
|
||
15 years ago
|
#include <konq_operations.h>
|
||
|
#include <kurl.h>
|
||
|
|
||
|
#include "chfacedlg.h"
|
||
12 years ago
|
#include "settings.h" // TDEConfigXT
|
||
15 years ago
|
|
||
|
|
||
|
|
||
|
/**
|
||
|
* TODO: It would be nice if the widget were in a .ui
|
||
|
*/
|
||
15 years ago
|
ChFaceDlg::ChFaceDlg(const TQString& picsdir, TQWidget *parent, const char *name, bool modal)
|
||
15 years ago
|
: KDialogBase( parent, name, modal, i18n("Change your Face"), Ok|Cancel, Ok, true )
|
||
|
{
|
||
15 years ago
|
TQWidget *page = new TQWidget(this);
|
||
15 years ago
|
setMainWidget( page );
|
||
|
|
||
15 years ago
|
TQVBoxLayout *top = new TQVBoxLayout(page, 0, spacingHint());
|
||
15 years ago
|
|
||
15 years ago
|
TQLabel *header = new TQLabel( i18n("Select a new face:"), page );
|
||
15 years ago
|
top->addWidget( header );
|
||
|
|
||
12 years ago
|
m_FacesWidget = new TDEIconView( page );
|
||
15 years ago
|
m_FacesWidget->setSelectionMode( TQIconView::Single );
|
||
15 years ago
|
m_FacesWidget->setItemsMovable( false );
|
||
|
m_FacesWidget->setMinimumSize( 400, 200 );
|
||
|
|
||
15 years ago
|
connect( m_FacesWidget, TQT_SIGNAL( selectionChanged( TQIconViewItem * ) ), TQT_SLOT( slotFaceWidgetSelectionChanged( TQIconViewItem * ) ) );
|
||
15 years ago
|
|
||
15 years ago
|
connect( m_FacesWidget, TQT_SIGNAL( doubleClicked( TQIconViewItem *, const TQPoint & ) ), TQT_SLOT( slotOk() ) );
|
||
15 years ago
|
|
||
|
top->addWidget( m_FacesWidget );
|
||
|
|
||
|
// Buttons to get more pics
|
||
15 years ago
|
TQHBoxLayout * morePics = new TQHBoxLayout( 0, 0, spacingHint() );
|
||
|
TQPushButton *browseBtn = new TQPushButton( i18n("Custom &Image..."), page );
|
||
|
connect( browseBtn, TQT_SIGNAL( clicked() ), TQT_SLOT( slotGetCustomImage() ) );
|
||
15 years ago
|
morePics->addWidget( browseBtn );
|
||
|
#if 0
|
||
15 years ago
|
TQPushButton *acquireBtn = new TQPushButton( i18n("&Acquire Image..."), page );
|
||
15 years ago
|
acquireBtn->setEnabled( false );
|
||
|
morePics->addWidget( acquireBtn );
|
||
|
#endif
|
||
|
morePics->addStretch();
|
||
|
top->addLayout( morePics );
|
||
|
|
||
|
// Filling the icon view
|
||
15 years ago
|
TQDir facesDir( picsdir );
|
||
15 years ago
|
if ( facesDir.exists() )
|
||
|
{
|
||
15 years ago
|
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 ) );
|
||
15 years ago
|
}
|
||
|
facesDir.setPath( KCFGUserAccount::userFaceDir() );
|
||
|
if ( facesDir.exists() )
|
||
|
{
|
||
15 years ago
|
TQStringList picslist = facesDir.entryList( TQDir::Files );
|
||
|
for ( TQStringList::Iterator it = picslist.begin(); it != picslist.end(); ++it )
|
||
|
new TQIconViewItem( m_FacesWidget, "/"+(*it) == KCFGUserAccount::customFaceFile() ?
|
||
15 years ago
|
i18n("(Custom)") : (*it).section(".",0,0),
|
||
15 years ago
|
TQPixmap( KCFGUserAccount::userFaceDir() + *it ) );
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
m_FacesWidget->setResizeMode( TQIconView::Adjust );
|
||
15 years ago
|
//m_FacesWidget->setGridX( FACE_PIX_SIZE - 10 );
|
||
|
m_FacesWidget->arrangeItemsInGrid();
|
||
|
|
||
|
enableButtonOK( false );
|
||
15 years ago
|
//connect( this, TQT_SIGNAL( okClicked() ), TQT_SLOT( slotSaveCustomImage() ) );
|
||
15 years ago
|
|
||
|
resize( 420, 400 );
|
||
|
}
|
||
|
|
||
15 years ago
|
void ChFaceDlg::addCustomPixmap( TQString imPath, bool saveCopy )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQImage pix( imPath );
|
||
15 years ago
|
// 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() > KCFGUserAccount::faceSize())
|
||
|
|| (pix.height() > KCFGUserAccount::faceSize()) )
|
||
14 years ago
|
pix = pix.scale( KCFGUserAccount::faceSize(), KCFGUserAccount::faceSize(), TQ_ScaleMin );// Should be no bigger than certain size.
|
||
15 years ago
|
|
||
|
if ( saveCopy )
|
||
|
{
|
||
|
// If we should save a copy:
|
||
15 years ago
|
TQDir userfaces( KCFGUserAccount::userFaceDir() );
|
||
15 years ago
|
if ( !userfaces.exists( ) )
|
||
|
userfaces.mkdir( userfaces.absPath() );
|
||
|
|
||
|
pix.save( userfaces.absPath() + "/.userinfo-tmp" , "PNG" );
|
||
15 years ago
|
KonqOperations::copy( this, KonqOperations::COPY, KURL::List( KURL( userfaces.absPath() + "/.userinfo-tmp" ) ), KURL( userfaces.absPath() + "/" + TQFileInfo(imPath).fileName().section(".",0,0) ) );
|
||
15 years ago
|
#if 0
|
||
|
if ( !pix.save( userfaces.absPath() + "/" + imPath , "PNG" ) )
|
||
|
KMessageBox::sorry(this, i18n("There was an error saving the image:\n%1").arg( userfaces.absPath() ) );
|
||
|
#endif
|
||
|
}
|
||
|
|
||
15 years ago
|
TQIconViewItem* newface = new TQIconViewItem( m_FacesWidget, TQFileInfo(imPath).fileName().section(".",0,0) , pix );
|
||
15 years ago
|
newface->setKey( KCFGUserAccount::customKey() );// Add custom items to end
|
||
|
m_FacesWidget->ensureItemVisible( newface );
|
||
|
m_FacesWidget->setCurrentItem( newface );
|
||
|
}
|
||
|
|
||
|
void ChFaceDlg::slotGetCustomImage( )
|
||
|
{
|
||
15 years ago
|
TQCheckBox* checkWidget = new TQCheckBox( i18n("&Save copy in custom faces folder for future use"), 0 );
|
||
15 years ago
|
|
||
15 years ago
|
KFileDialog *dlg = new KFileDialog( TQDir::homeDirPath(), KImageIO::pattern( KImageIO::Reading ),
|
||
15 years ago
|
this, 0, true, checkWidget);
|
||
|
|
||
|
dlg->setOperationMode( KFileDialog::Opening );
|
||
|
dlg->setCaption( i18n("Choose Image") );
|
||
|
dlg->setMode( KFile::File | KFile::LocalOnly );
|
||
|
|
||
|
KImageFilePreview *ip = new KImageFilePreview( dlg );
|
||
|
dlg->setPreviewWidget( ip );
|
||
15 years ago
|
if (dlg->exec() == TQDialog::Accepted)
|
||
15 years ago
|
addCustomPixmap( dlg->selectedFile(), checkWidget->isChecked() );
|
||
|
// Because we give it a parent we have to close it ourselves.
|
||
|
dlg->close(true);
|
||
|
}
|
||
|
|
||
|
#if 0
|
||
|
void ChFaceDlg::slotSaveCustomImage()
|
||
|
{
|
||
|
if ( m_FacesWidget->currentItem()->key() == USER_CUSTOM_KEY)
|
||
|
{
|
||
15 years ago
|
TQDir userfaces( TQDir::homeDirPath() + USER_FACES_DIR );
|
||
15 years ago
|
if ( !userfaces.exists( ) )
|
||
|
userfaces.mkdir( userfaces.absPath() );
|
||
|
|
||
|
if ( !m_FacesWidget->currentItem()->pixmap()->save( userfaces.absPath() + USER_CUSTOM_FILE , "PNG" ) )
|
||
|
KMessageBox::sorry(this, i18n("There was an error saving the image:\n%1").arg( userfaces.absPath() ) );
|
||
|
}
|
||
|
}
|
||
|
#endif
|
||
|
|
||
|
#include "chfacedlg.moc"
|