コード例 #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
static QString buildNewFilename(const QString &cmplFilename, const ImageFormat &currFormat)
{
   /* cmplFilename = new name the user wishes.
    * currFormat   = the current format of the image.
    * if the new filename has a valid extension, which is the same as the
    * format of the current, fine. A ''-String has to be returned.
    */
   QFileInfo fiNew(cmplFilename);
   QString base = fiNew.baseName();
   QString newExt = fiNew.suffix().toLower();
   QString nowExt = currFormat.extension();
   QString ext = "";

   kDebug() << "Filename wanted:"<< cmplFilename << "ext" << nowExt << "->" << newExt;

   if( newExt.isEmpty() )
   {
      /* ok, fine -> return the currFormat-Extension */
      ext = base + "." + nowExt;
   }
   else if( newExt == nowExt )
   {
      /* also good, no reason to put another extension */
      ext = cmplFilename;
   }
   else
   {
      /* new Ext. differs from the current extension. Later. */
      KMessageBox::sorry(NULL, i18n( "You entered a file extension that differs from the existing one. That is not yet possible. Converting 'on the fly' is planned for a future release.\n"
				      "Kooka corrects the extension."),
			  i18n("On the Fly Conversion"));
      ext = base + "." + nowExt;
   }
   return( ext );
}