本文整理汇总了C++中KFileItem::setExtraData方法的典型用法代码示例。如果您正苦于以下问题:C++ KFileItem::setExtraData方法的具体用法?C++ KFileItem::setExtraData怎么用?C++ KFileItem::setExtraData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类KFileItem
的用法示例。
在下文中一共展示了KFileItem::setExtraData方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: slNewFileItems
void ThumbView::slNewFileItems( const KFileItemList& items )
{
kdDebug(28000) << "Creating thumbnails for fileItemList" << endl;
/* Fill the pending jobs list. */
KFileItemListIterator it( items );
KFileItem *item = 0;
for ( ; (item = it.current()); ++it )
{
QString filename = item->url().prettyURL();
if( item->isDir() )
{
/* create a dir pixmap */
}
else
{
QPixmap p(m_basePix) ;
QPixmap mime( item->pixmap(0) );
if( p.width() > mime.width() && p.height() > mime.height() )
{
QPainter paint( &p );
paint.drawPixmap( (p.width()-mime.width())/2,
(p.height()-mime.height())/2,
mime );
paint.flush();
}
/* Create a new empty preview pixmap and store the pointer to it */
ThumbViewItem *newIconViewIt = new ThumbViewItem( m_iconView,
item->url().filename(),
createPixmap( p ),
item );
newIconViewIt->setItemUrl( item->url() );
/* tell the file item about the iconView-representation */
item->setExtraData( this, newIconViewIt );
m_pendingJobs.append( item );
}
}
/*
From a mail from Waldo Bastian pointing out problems with thumbview:
2) I think you may end up creating two PreviewJob's in parallel
when the slNewFileItems() function is called two times in
quick succession. The current code doesn't seem to expect
that, given the comment in slPreviewResult(). In the light of
1) it might become fatal since you will not be able to call
PreviewJob::removeItem on the proper job. I suggest to queue
new items when a job is already running and start a new job
once the first one is finished when there are any items left
in the queue. Don't forget to delete items from the queue if
they get deleted in the mean time.
The strategy is as follows: In the global list m_pendingJobs
the jobs to start are appended. Only if m_job is zero (no job
is running) a job is started on the current m_pendingJobs list.
The m_pendingJobs list is clear afterwords.
*/
if( ! m_job && m_pendingJobs.count() > 0 )
{
/* Progress-Bar */
m_progress->show();
m_progress->setTotalSteps(m_pendingJobs.count());
m_cntJobsStarted = 0;
/* start a preview-job */
m_job = KIO::filePreview(m_pendingJobs, m_pixWidth, m_pixHeight );
if( m_job )
{
connect( m_job, SIGNAL( result( KIO::Job * )),
this, SLOT( slPreviewResult( KIO::Job * )));
connect( m_job, SIGNAL( gotPreview( const KFileItem*, const QPixmap& )),
SLOT( slGotPreview( const KFileItem*, const QPixmap& ) ));
m_pendingJobs.clear();
/* KIO::Jo result is called in any way: Success, Failed, Error,
* thus connecting the failed is not really necessary.
*/
// connect( job, SIGNAL( failed( const KFileItem* )),
// this, SLOT( slotFailed( const KFileItem* ) ));
}
}
示例2: addItems
void KFileTreeBranch::addItems( const KFileItemList& list )
{
KFileItemListIterator it( list );
kdDebug(250) << "Adding " << list.count() << " items !" << endl;
KFileItem *currItem;
KFileTreeViewItemList treeViewItList;
KFileTreeViewItem *parentItem = 0;
while ( (currItem = it.current()) != 0 )
{
parentItem = parentKFTVItem( currItem );
/* Only create a new KFileTreeViewItem if it does not yet exist */
KFileTreeViewItem *newKFTVI =
static_cast<KFileTreeViewItem *>(currItem->extraData( this ));
if( ! newKFTVI )
{
newKFTVI = createTreeViewItem( parentItem, currItem );
if (!newKFTVI)
{
// TODO: Don't fail if parentItem == 0
++it;
continue;
}
currItem->setExtraData( this, newKFTVI );
/* Cut off the file extension in case it is not a directory */
if( !m_showExtensions && !currItem->isDir() ) /* Need to cut the extension */
{
TQString name = currItem->text();
int mPoint = name.findRev( '.' );
if( mPoint > 0 )
name = name.left( mPoint );
newKFTVI->setText( 0, name );
}
}
/* Now try to find out if there are children for dirs in the treeview */
/* This stats a directory on the local file system and checks the */
/* hardlink entry in the stat-buf. This works only for local directories. */
if( dirOnlyMode() && !m_recurseChildren && currItem->isLocalFile( ) && currItem->isDir() )
{
KURL url = currItem->url();
TQString filename = url.directory( false, true ) + url.fileName();
/* do the stat trick of Carsten. The problem is, that the hardlink
* count only contains directory links. Thus, this method only seem
* to work in dir-only mode */
kdDebug(250) << "Doing stat on " << filename << endl;
KDE_struct_stat statBuf;
if( KDE_stat( TQFile::encodeName( filename ), &statBuf ) == 0 )
{
int hardLinks = statBuf.st_nlink; /* Count of dirs */
kdDebug(250) << "stat succeeded, hardlinks: " << hardLinks << endl;
// If the link count is > 2, the directory likely has subdirs. If it's < 2
// it's something weird like a mounted SMB share. In that case we don't know
// if there are subdirs, thus show it as expandable.
if( hardLinks != 2 )
{
newKFTVI->setExpandable(true);
}
else
{
newKFTVI->setExpandable(false);
}
if( hardLinks >= 2 ) // "Normal" directory with subdirs
{
kdDebug(250) << "Emitting for " << url.prettyURL() << endl;
emit( directoryChildCount( newKFTVI, hardLinks-2)); // parentItem, hardLinks-1 ));
}
}
else
{
kdDebug(250) << "stat of " << filename << " failed !" << endl;
}
}
++it;
treeViewItList.append( newKFTVI );
}
emit newTreeViewItems( this, treeViewItList );
}