bool KFileItemModelFilter::matchesPattern(const KFileItem& item) const
{
    if (m_useRegExp) {
        return m_regExp->exactMatch(item.text());
    } else {
        return item.text().toLower().contains(m_lowerCasePattern);
    }
}
QString KFileItemListWidgetInformant::itemText(int index, const KItemListView* view) const
{
    Q_ASSERT(qobject_cast<KFileItemModel*>(view->model()));
    KFileItemModel* fileItemModel = static_cast<KFileItemModel*>(view->model());

    const KFileItem item = fileItemModel->fileItem(index);
    return item.text();
}
void HiddenFileView::insertNewFiles(const KFileItemList &newone)
{
  if ( newone.isEmpty() )
     return;

  KFileItem *tmp;

  int j=0;

  for (KFileItemListIterator it(newone); (tmp = it.current()); ++it)
  {
    j++;

    bool hidden = matchHidden(tmp->text());
    bool veto = matchVeto(tmp->text());
    bool vetoOplock = matchVetoOplock(tmp->text());

    new HiddenListViewItem( _dlg->hiddenListView, tmp, hidden, veto, vetoOplock );

  }
}
K3FileTreeViewItem::K3FileTreeViewItem( K3FileTreeView* parent,
				      const KFileItem &item,
				      KFileTreeBranch *brnch )
   :K3ListViewItem( (Q3ListView*)parent ),
    m_kfileitem(item ),
    m_branch( brnch ),
    m_wasListed(false)
{
   setPixmap(0, item.pixmap( KIconLoader::SizeSmall ));
   setText( 0, item.text());

   m_kfileitem.setExtraData( m_branch, this );
}
void PreferencesDialog::setExcludedMedia(QStringList excludedList)
{
    mpMediaListView->clear();
    mpMediaListView->setRootIsDecorated(false);

    KFileItemListIterator it(mMedia);
    KFileItem *file;
    while((file = it.current()) != 0)
    {
        ++it;

        bool ok = excludedList.contains(file->url().url()) == 0;
        MediumItem *item = new MediumItem(mpMediaListView, file->text(), *file);
        item->setOn(ok);
    }
}
Example #6
0
void FoldersPanel::slotRoleEditingFinished(int index, const QByteArray& role, const QVariant& value)
{
    if (role == "text") {
        const KFileItem item = m_model->fileItem(index);
        const QString newName = value.toString();
        if (!newName.isEmpty() && newName != item.text() && newName != QLatin1String(".") && newName != QLatin1String("..")) {
            const QUrl oldUrl = item.url();
            QUrl newUrl = oldUrl.adjusted(QUrl::RemoveFilename);
            newUrl.setPath(newUrl.path() + KIO::encodeFileName(newName));

            KIO::Job* job = KIO::moveAs(oldUrl, newUrl);
            KJobWidgets::setWindow(job, this);
            KIO::FileUndoManager::self()->recordJob(KIO::FileUndoManager::Rename, {oldUrl}, newUrl, job);
            job->ui()->setAutoErrorHandlingEnabled(true);
        }
    }
}
Example #7
0
QVariant DirModel::data( const QModelIndex & index, int role  ) const
{

  if (role != Qt::DisplayRole) {
    return KDirModel::data(index, role);
  }
  
  KFileItem item = itemForIndex(index);
  if(item.isDesktopFile()) {
    KDesktopFile f(item.url().path());
    QString name = f.readName();
    if(!name.isEmpty()){
      return name;
    }
  }
  return item.text();
}
void DolphinFileItemDelegate::adjustOptionWidth(QStyleOptionViewItemV4& option,
                                                const QAbstractProxyModel* proxyModel,
                                                const DolphinModel* dolphinModel,
                                                const QModelIndex& index)
{
    const QModelIndex dirIndex = proxyModel->mapToSource(index);
    const KFileItem item = dolphinModel->itemForIndex(dirIndex);
    if (!item.isNull()) {
        // symbolic links are displayed in an italic font
        if (item.isLink()) {
            option.font.setItalic(true);
        }

        const int width = nameColumnWidth(item.text(), option);
        option.rect.setWidth(width);
    }
}
void InformationPanelContent::showItem(const KFileItem& item)
{
    m_pendingPreview = false;

    const KUrl itemUrl = item.url();
    const bool isSearchUrl = itemUrl.protocol().contains("search") && item.nepomukUri().isEmpty();
    if (!applyPlace(itemUrl)) {
        setNameLabelText(item.text());
        if (isSearchUrl) {
            // in the case of a search-URL the URL is not readable for humans
            // (at least not useful to show in the Information Panel)
            KIconLoader iconLoader;
            QPixmap icon = iconLoader.loadIcon("nepomuk",
                                               KIconLoader::NoGroup,
                                               KIconLoader::SizeEnormous);
            m_preview->setPixmap(icon);
        } else {
            // try to get a preview pixmap from the item...
            m_pendingPreview = true;

            // Mark the currently shown preview as outdated. This is done
            // with a small delay to prevent a flickering when the next preview
            // can be shown within a short timeframe. This timer is not started
            // for directories, as directory previews might fail and return the
            // same icon.
            if (!item.isDir()) {
                m_outdatedPreviewTimer->start();
            }

            KIO::PreviewJob* job = KIO::filePreview(KFileItemList() << item, QSize(m_preview->width(), m_preview->height()));
            job->setScaleType(KIO::PreviewJob::Unscaled);

            connect(job, SIGNAL(gotPreview(const KFileItem&, const QPixmap&)),
                    this, SLOT(showPreview(const KFileItem&, const QPixmap&)));
            connect(job, SIGNAL(failed(const KFileItem&)),
                    this, SLOT(showIcon(const KFileItem&)));
        }
    }
Example #10
0
void QExtFileInfo::slotNewEntries(KIO::Job *job, const KIO::UDSEntryList& udsList)
{
  KURL url = static_cast<KIO::ListJob *>(job)->url();
  url.adjustPath(-1);
  // avoid creating these QStrings again and again
  static const QString& dot = KGlobal::staticQString(".");
  static const QString& dotdot = KGlobal::staticQString("..");

  KIO::UDSEntryListConstIterator it = udsList.begin();
  KIO::UDSEntryListConstIterator end = udsList.end();
  KURL itemURL;
  for ( ; it != end; ++it )
  {
    QString name;

    // find out about the name
    KIO::UDSEntry::ConstIterator entit = (*it).begin();
    for( ; entit != (*it).end(); ++entit )
      if ( (*entit).m_uds == KIO::UDS_NAME )
      {
        name = (*entit).m_str;
        break;
      }

    if ( ! name.isEmpty() && name != dot && name != dotdot)
    {
      KFileItem* item = new KFileItem( *it, url, false, true );
      itemURL = item->url();
      if (item->isDir()) itemURL.adjustPath(1);
      for ( QPtrListIterator<QRegExp> filterIt( lstFilters ); filterIt.current(); ++filterIt )
      if ( filterIt.current()->exactMatch( item->text() ) )
           dirListItems.append(itemURL);
      delete item;
    }
  }
}
KJS::Value KJSEmbed::Bindings::KFileItemImp::call( KJS::ExecState * exec, KJS::Object & self, const KJS::List & args )
{
	kdDebug() << "KFileItemImp::call() " << mid << endl;
	JSOpaqueProxy *op = JSProxy::toOpaqueProxy( self.imp() );
	if ( !op ) {
		kdWarning() << "KFileItemImp::call() failed, not a JSOpaqueProxy" << endl;
		return KJS::Value();
	}
	
	if ( op->typeName() != "KFileItem" ) {
		kdWarning() << "KFileItemImp::call() failed, type is " << op->typeName() << endl;
		return KJS::Value();
	}
	
	KFileItem *obj = op->toNative<KFileItem >();
	
	KJS::Value retValue = KJS::Value();
	switch ( mid ) {
	case Methodrefresh:
		obj->refresh();
		break;
	case MethodrefreshMimeType:
		obj->refreshMimeType(); 
		break;
	case Methodurl:
	{
		QString url = obj->url().url();
		retValue = KJS::String(url);
		break;
	}
	case MethodsetUrl:
	{
		QString url = extractQString(exec, args, 0);
		obj->setURL(url);
		break;
	}
	case MethodsetName: 
	case MethodpermissionsString: 
	case Methoduser: 
	case Methodgroup: 
	case MethodisLink: 
	case MethodisDir: 
	case MethodisFile: 
	case MethodisReadable: 
	case MethodlinkDest: 
	case MethodtimeString: 
	case MethodisLocalFile: 
	case Methodtext:
	{
		retValue = convertToValue(exec, obj->text() );
		break;
	} 
	case Methodname:  
	case MethodmimeType: 
	case MethodisMimeTypeKnown: 
	case MethodmimeComment: 
	case MethodiconName: 
	{
		retValue = convertToValue( exec, obj->iconName() );
		break;
	}
	case Methodpixmap:
	{
		int size = extractInt(exec, args, 0);
		int state = extractInt(exec, args, 1);
		retValue = convertToValue(exec, obj->pixmap(size, state));
		break;
	}
	case Methodoverlays: 
	{
		retValue = convertToValue(exec, obj->overlays());
		break;
	}
	case MethodgetStatusBarInfo: 
	{
		retValue = KJS::String( obj->getStatusBarInfo() );
		break;
	}
	case MethodgetToolTipText:
	{
		int maxcount = extractInt(exec, args, 0);
		retValue = KJS::String(obj->getToolTipText(maxcount));
		break;
	}
	case Methodrun:
		obj->run();
		break;
	default:
		kdWarning() << "KFileItemImp has no method " << mid << endl;
		break;
	}
	
	op->setValue((void*) obj, "KFileItem");
	return retValue;

} 
Example #12
0
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 );
}
void InformationPanelContent::showItem(const KFileItem& item)
{
    // If there is a preview job, kill it to prevent that we have jobs for
    // multiple items running, and thus a race condition (bug 250787).
    if (m_previewJob) {
        m_previewJob->kill();
    }

    const QUrl itemUrl = item.url();
    const bool isSearchUrl = itemUrl.scheme().contains(QStringLiteral("search")) && item.localPath().isEmpty();
    if (!applyPlace(itemUrl)) {
        setNameLabelText(item.text());
        if (isSearchUrl) {
            // in the case of a search-URL the URL is not readable for humans
            // (at least not useful to show in the Information Panel)
            KIconLoader iconLoader;
            QPixmap icon = iconLoader.loadIcon(QStringLiteral("nepomuk"),
                                               KIconLoader::NoGroup,
                                               KIconLoader::SizeEnormous);
            m_preview->setPixmap(icon);
        } else {
            // try to get a preview pixmap from the item...

            // Mark the currently shown preview as outdated. This is done
            // with a small delay to prevent a flickering when the next preview
            // can be shown within a short timeframe. This timer is not started
            // for directories, as directory previews might fail and return the
            // same icon.
            if (!item.isDir()) {
                m_outdatedPreviewTimer->start();
            }

            m_previewJob = new KIO::PreviewJob(KFileItemList() << item, QSize(m_preview->width(), m_preview->height()));
            m_previewJob->setScaleType(KIO::PreviewJob::Unscaled);
            m_previewJob->setIgnoreMaximumSize(item.isLocalFile());
            if (m_previewJob->ui()) {
                KJobWidgets::setWindow(m_previewJob, this);
            }

            connect(m_previewJob.data(), &KIO::PreviewJob::gotPreview,
                    this, &InformationPanelContent::showPreview);
            connect(m_previewJob.data(), &KIO::PreviewJob::failed,
                    this, &InformationPanelContent::showIcon);
        }
    }

    if (m_metaDataWidget) {
        m_metaDataWidget->show();
        m_metaDataWidget->setItems(KFileItemList() << item);
    }

    if (InformationPanelSettings::previewsShown()) {
        const QString mimeType = item.mimetype();
        const bool usePhonon = mimeType.startsWith(QLatin1String("audio/")) || mimeType.startsWith(QLatin1String("video/"));
        if (usePhonon) {
            m_phononWidget->show();
            m_phononWidget->setUrl(item.targetUrl());
            if (m_preview->isVisible()) {
                m_phononWidget->setVideoSize(m_preview->size());
            }
        } else {
            m_phononWidget->hide();
            m_preview->setVisible(true);
        }
    } else {
        m_phononWidget->hide();
    }

    m_item = item;
}
void InformationPanelContent::showItem(const KFileItem& item)
{
    m_pendingPreview = false;

    const KUrl itemUrl = item.url();
    const bool isSearchUrl = itemUrl.protocol().contains("search") && item.nepomukUri().isEmpty();
    if (!applyPlace(itemUrl)) {
        setNameLabelText(item.text());
        if (isSearchUrl) {
            // in the case of a search-URL the URL is not readable for humans
            // (at least not useful to show in the Information Panel)
            KIconLoader iconLoader;
            QPixmap icon = iconLoader.loadIcon("nepomuk",
                                               KIconLoader::NoGroup,
                                               KIconLoader::SizeEnormous);
            m_preview->setPixmap(icon);
        } else {
            // try to get a preview pixmap from the item...
            m_pendingPreview = true;

            // Mark the currently shown preview as outdated. This is done
            // with a small delay to prevent a flickering when the next preview
            // can be shown within a short timeframe. This timer is not started
            // for directories, as directory previews might fail and return the
            // same icon.
            if (!item.isDir()) {
                m_outdatedPreviewTimer->start();
            }

            KIO::PreviewJob* job = new KIO::PreviewJob(KFileItemList() << item, QSize(m_preview->width(), m_preview->height()));
            job->setScaleType(KIO::PreviewJob::Unscaled);
            job->setIgnoreMaximumSize(item.isLocalFile());
            if (job->ui()) {
                job->ui()->setWindow(this);
            }

            connect(job, SIGNAL(gotPreview(KFileItem,QPixmap)),
                    this, SLOT(showPreview(KFileItem,QPixmap)));
            connect(job, SIGNAL(failed(KFileItem)),
                    this, SLOT(showIcon(KFileItem)));
        }
    }

    if (m_metaDataWidget) {
        m_metaDataWidget->show();
        m_metaDataWidget->setItems(KFileItemList() << item);
    }

    if (InformationPanelSettings::previewsShown()) {
        const QString mimeType = item.mimetype();
        const bool usePhonon = mimeType.startsWith("audio/") || mimeType.startsWith("video/");
        if (usePhonon) {
            m_phononWidget->show();
            m_phononWidget->setUrl(item.targetUrl());
            if (m_preview->isVisible()) {
                m_phononWidget->setVideoSize(m_preview->size());
            }
        } else {
            m_phononWidget->hide();
            m_preview->setVisible(true);
        }
    } else {
        m_phononWidget->hide();
    }

    m_item = item;
}