예제 #1
0
파일: scangallery.cpp 프로젝트: KDE/kooka
void ScanGallery::slotExportFile()
{
    FileTreeViewItem *curr = highlightedFileTreeViewItem();
    if (curr==NULL) return;

    if (curr->isDir())
    {
        kDebug() << "Not yet implemented!";
        return;
    }

    KUrl fromUrl(curr->url());

    QString filter;
    ImageFormat format = getImgFormat(curr);
    if (format.isValid()) filter = "*."+format.extension()+"|"+format.mime()->comment()+"\n";
// TODO: do we need the below?
    filter += "*|"+i18n("All Files");

    QString initial = "kfiledialog:///exportImage/"+fromUrl.fileName();
    KUrl fileName = KFileDialog::getSaveUrl(KUrl(initial), filter, this);
    if (!fileName.isValid()) return;			// didn't get a file name
    if (fromUrl==fileName) return;			// can't save over myself

    /* Since it is asynchron, we will never know if it succeeded. */
    ImgSaver::copyImage(fromUrl, fileName);
}
예제 #2
0
파일: scangallery.cpp 프로젝트: KDE/kooka
void ScanGallery::slotDecorate(FileTreeViewItem *item)
{
    if (item==NULL) return;

    if (!item->isDir())					// dir is done in another slot
    {
        ImageFormat format = getImgFormat(item);	// this is safe for any file
        item->setText(2,(" "+format.name()+" "));

        const KookaImage *img = imageForItem(item);
        if (img!=NULL)					// image appears to be loaded
        {						// set image depth pixmap
            if (img->depth()==1) item->setIcon(0, mPixBw);
            else
            {
                if (img->isGrayscale()) item->setIcon(0, mPixGray);
                else item->setIcon(0, mPixColor);
            }
							// set image size column
            QString t = i18n(" %1 x %2", img->width(), img->height());
            item->setText(1,t);
        }
        else						// not yet loaded, show file info
        {
            if (format.isValid())			// if a valid image file
            {
                item->setIcon(0, mPixFloppy);
                const KFileItem *kfi = item->fileItem();
                if (!kfi->isNull()) item->setText(1, (" "+KIO::convertSize(kfi->size())));
            }
            else
            {
                item->setIcon(0, KIO::pixmapForUrl(item->url(), 0, KIconLoader::Small));
            }
        }
    }

    // This code is quite similar to m_nextUrlToSelect in FileTreeView::slotNewTreeViewItems
    // When scanning a new image, we wait for the KDirLister to notice the new file,
    // and then we have the FileTreeViewItem that we need to display the image.
    if (!m_nextUrlToShow.isEmpty())
    {
        if (m_nextUrlToShow.equals(item->url(), KUrl::CompareWithoutTrailingSlash))
        {
            m_nextUrlToShow = KUrl();			// do this first to prevent recursion
            slotItemActivated(item);
            setCurrentItem(item);			// neccessary in case of new file from D&D
        }
    }
}
예제 #3
0
파일: scangallery.cpp 프로젝트: KDE/kooka
void ScanGallery::loadImageForItem(FileTreeViewItem *item)
{
    if (item==NULL) return;

    const KFileItem *kfi = item->fileItem();
    if (kfi->isNull()) return;

    kDebug() << "loading" << item->url();

    QString ret = QString::null;			// no error so far

    ImageFormat format = getImgFormat(item);		// check for valid image format
    if (!format.isValid())
    {
        ret = i18n("Not a valid image format");
    }
    else
    {
        KookaImage *img = imageForItem(item);
        if (img==NULL)					// image not already loaded
        {
            // The image needs to be loaded. Possibly it is a multi-page image.
            // If it is, the kookaImage has a subImageCount larger than one. We
            // create an subimage-item for every subimage, but do not yet load
            // them.

            img = new KookaImage();
            ret = img->loadFromUrl(item->url());
            if (ret.isEmpty())				// image loaded OK
            {
                img->setFileItem(kfi);			// store the fileitem

                kDebug() << "subImage-count" << img->subImagesCount();
                if (img->subImagesCount()>1)		// look for subimages,
                {					// create items for them
                    KIconLoader *loader = KIconLoader::global();

                    // Start at the image with index 1, that makes one less than
                    // are actually in the image. But image 0 was already created above.
                    FileTreeViewItem *prevItem = NULL;
                    for (int i = 1; i<img->subImagesCount(); i++)
                    {
                        kDebug() << "Creating subimage" << i;
                        KFileItem newKfi(*kfi);
                        FileTreeViewItem *subImgItem = new FileTreeViewItem(item,newKfi,item->branch());

                        // TODO: what's the equivalent?
                        //if (prevItem!=NULL) subImgItem->moveItem(prevItem);
                        prevItem = subImgItem;

                        subImgItem->setIcon(0, loader->loadIcon("editcopy", KIconLoader::Small));
                        subImgItem->setText(0, i18n("Sub-image %1", i));
                        KookaImage *subImgImg = new KookaImage(i, img);
                        subImgImg->setFileItem(&newKfi);
                        subImgItem->setClientData(subImgImg);
                    }
                }

                if (img->isSubImage())			// this is a subimage
                {
                    kDebug() << "it is a subimage";
                    if (img->isNull())			// if not already loaded,
                    {
                        kDebug() << "extracting subimage";
                        img->extractNow();		// load it now
                    }
                }

                slotImageArrived(item, img);
            }
            else
            {
                delete img;				// nothing to load
            }
        }
    }

    if (!ret.isEmpty()) KMessageBox::error(this,	// image loading failed
                                           i18n("<qt>"
                                                "<p>Unable to load the image<br>"
                                                "<filename>%2</filename><br>"
                                                "<br>"
                                                "%1",
                                                ret,
                                                item->url().prettyUrl()),
                                           i18n("Image Load Error"));
}