Exemplo n.º 1
0
void KMSoundTestWidget::openSoundDialog( KURLRequester * )
{
    static bool init = true;
    if ( !init )
        return;

    init = false;

    KFileDialog *fileDialog = m_urlRequester->fileDialog();
    fileDialog->setCaption( i18n("Select Sound File") );
    QStringList filters;
    filters << "audio/x-wav" << "audio/x-mp3" << "application/x-ogg"
            << "audio/x-adpcm";
    fileDialog->setMimeFilter( filters );

   QStringList soundDirs = KGlobal::dirs()->resourceDirs( "sound" );

    if ( !soundDirs.isEmpty() ) {
        KURL soundURL;
        QDir dir;
        dir.setFilter( QDir::Files | QDir::Readable );
        QStringList::ConstIterator it = soundDirs.begin();
        while ( it != soundDirs.end() ) {
            dir = *it;
            if ( dir.isReadable() && dir.count() > 2 ) {
                soundURL.setPath( *it );
                fileDialog->setURL( soundURL );
                break;
            }
            ++it;
        }
    }

}
Exemplo n.º 2
0
bool KugarPart::initDoc( InitDocFlags /*flags*/, QWidget* /*parentWidget*/ )
{
    QString filename;
    bool ok = false;

    KFileDialog *dialog = 
        new KFileDialog( QString::null, QString::null, 0L, "file dialog", true );
    dialog->setMimeFilter( KoFilterManager::mimeFilter( KoDocument::readNativeFormatMimeType(),
                           KoFilterManager::Import ) );
    if ( dialog->exec() != QDialog::Accepted )
    {
        delete dialog;
        return false;
    }

    KURL url( dialog->selectedURL() );
    delete dialog;

    if ( url.isEmpty() )
        return false;

    if ( url.isValid() )
    {
        ok = openURL( url );
    }
    return ok;

    // If nothing is loaded, do initialize here
    return TRUE;
}
Exemplo n.º 3
0
void KFDTest::doit()
{
    KFileDialog *dlg = new KFileDialog( m_startDir, QString(), 0L);
    dlg->setMode( KFile::File);
    dlg->setOperationMode( KFileDialog::Saving );
    QStringList filter;
    filter << "all/allfiles" << "text/plain";
    dlg->setMimeFilter( filter, "all/allfiles" );

    if ( dlg->exec() == KDialog::Accepted )
    {
        KMessageBox::information(0, QString::fromLatin1("You selected the file: %1").arg( dlg->selectedUrl().prettyUrl() ));
    }

//     qApp->quit();
}
Exemplo n.º 4
0
void KoPAView::importDocument()
{
    KFileDialog *dialog = new KFileDialog( KUrl("kfiledialog:///OpenDialog"),QString(), this );
    dialog->setObjectName( "file dialog" );
    dialog->setMode( KFile::File );
    if ( d->doc->pageType() == KoPageApp::Slide ) {
        dialog->setCaption(i18n("Import Slideshow"));
    }
    else {
        dialog->setCaption(i18n("Import Document"));
    }

    // TODO make it possible to select also other supported types (then the default format) here.
    // this needs to go via the filters to get the file in the correct format.
    // For now we only support the native mime types
    QStringList mimeFilter;
#if 1
    mimeFilter << KoOdf::mimeType( d->doc->documentType() ) << KoOdf::templateMimeType( d->doc->documentType() );
#else
    mimeFilter = KoFilterManager::mimeFilter( KoDocument::readNativeFormatMimeType(d->doc->componentData()), KoFilterManager::Import,
                                              KoDocument::readExtraNativeMimeTypes() );
#endif

    dialog->setMimeFilter( mimeFilter );
    if (dialog->exec() == QDialog::Accepted) {
        KUrl url(dialog->selectedUrl());
        QString tmpFile;
        if ( KIO::NetAccess::download( url, tmpFile, 0 ) ) {
            QFile file( tmpFile );
            file.open( QIODevice::ReadOnly );
            QByteArray ba;
            ba = file.readAll();

            // set the correct mime type as otherwise it does not find the correct tag when loading
            QMimeData data;
            data.setData( KoOdf::mimeType( d->doc->documentType() ), ba);
            KoPAPastePage paste( d->doc,d->activePage );
            if ( ! paste.paste( d->doc->documentType(), &data ) ) {
                KMessageBox::error(0, i18n("Could not import\n%1", url.pathOrUrl()));
            }
        }
        else {
            KMessageBox::error(0, i18n("Could not import\n%1", url.pathOrUrl()));
        }
    }
    delete dialog;
}
Exemplo n.º 5
0
void KfindWindow::saveResults()
{
  TQListViewItem *item;

  KFileDialog *dlg = new KFileDialog(TQString::null, TQString::null, this,
	"filedialog", true);
  dlg->setOperationMode (KFileDialog::Saving);

  dlg->setCaption(i18n("Save Results As"));

  TQStringList list;

  list << "text/plain" << "text/html";

  dlg->setOperationMode(KFileDialog::Saving);
  
  dlg->setMimeFilter(list, TQString("text/plain"));

  dlg->exec();

  KURL u = dlg->selectedURL();
  KMimeType::Ptr mimeType = dlg->currentFilterMimeType();
  delete dlg;

  if (!u.isValid() || !u.isLocalFile())
     return;

  TQString filename = u.path();

  TQFile file(filename);

  if ( !file.open(IO_WriteOnly) )
    KMessageBox::error(parentWidget(),
		       i18n("Unable to save results."));
  else {
    TQTextStream stream( &file );
    stream.setEncoding( TQTextStream::Locale );

    if ( mimeType->name() == "text/html") {
      stream << TQString::fromLatin1("<HTML><HEAD>\n"
				    "<!DOCTYPE %1>\n"
				    "<TITLE>%2</TITLE></HEAD>\n"
				    "<BODY><H1>%3</H1>"
				    "<DL><p>\n")
	.arg(i18n("KFind Results File"))
	.arg(i18n("KFind Results File"))
	.arg(i18n("KFind Results File"));

      item = firstChild();
      while(item != NULL)
	{
	  TQString path=((KfFileLVI*)item)->fileitem.url().url();
	  TQString pretty=((KfFileLVI*)item)->fileitem.url().htmlURL();
	  stream << TQString::fromLatin1("<DT><A HREF=\"") << path
		 << TQString::fromLatin1("\">") << pretty
		 << TQString::fromLatin1("</A>\n");

	  item = item->nextSibling();
	}
      stream << TQString::fromLatin1("</DL><P></BODY></HTML>\n");
    }
    else {
      item = firstChild();
      while(item != NULL)
      {
	TQString path=((KfFileLVI*)item)->fileitem.url().url();
	stream << path << endl;
	item = item->nextSibling();
      }
    }

    file.close();
    KMessageBox::information(parentWidget(),
			     i18n("Results were saved to file\n")+
			     filename);
  }
}
Exemplo n.º 6
0
int main(int argc, char **argv)
{
    KCmdLineOptions options;
    options.add("+[cmd]");
    options.add("+[url]");

    KCmdLineArgs::init(argc, argv, "kfstest", 0, ki18n("kfstest"), "0", ki18n("test app"));
    KCmdLineArgs::addCmdLineOptions(options);
    KApplication a;
    a.setQuitOnLastWindowClosed(false);

    QString name1;
    QStringList names;

    QString argv1;
    KUrl startDir;
    if (argc > 1)
        argv1 = QLatin1String(argv[1]);
    if ( argc > 2 )
        startDir = KUrl( argv[2] );

#if 0 // SPLIT-TODO
    if (argv1 == QLatin1String("diroperator")) {
        KDirOperator *op = new KDirOperator(startDir, 0);
        KConfigGroup grp(KGlobal::config(), "TestGroup" );
        op->setViewConfig(grp);
        op->setView(KFile::Simple);
        op->show();
        a.exec();
    } else
#endif
    if (argv1 == QLatin1String("localonly")) {
        QString name = KFileDialog::getOpenFileName(startDir);
        qDebug("filename=%s",name.toLatin1().constData());
    }
    else if (argv1 == QLatin1String("oneurl")) {
        KUrl url = KFileDialog::getOpenUrl(startDir);
        qDebug() << "url=" << url;
    }

    else if (argv1 == QLatin1String("existingDirectoryUrl")) {
        KUrl url = KFileDialog::getExistingDirectoryUrl();
        qDebug("URL=%s",url.url().toLatin1().constData());
        name1 = url.url();
    }

    else if (argv1 == QLatin1String("preview")) {
        KUrl u =  KFileDialog::getImageOpenUrl();
        qDebug("filename=%s", u.url().toLatin1().constData());
    }

    else if (argv1 == QLatin1String("preselect")) {
        names = KFileDialog::getOpenFileNames(KUrl("/etc/passwd"));
        QStringList::Iterator it = names.begin();
        while ( it != names.end() ) {
            qDebug("selected file: %s", (*it).toLatin1().constData());
            ++it;
        }
    }

    else if (argv1 == QLatin1String("dirs"))
        name1 = KFileDialog::getExistingDirectory();

    else if (argv1 == QLatin1String("heap")) {
        KFileDialog *dlg = new KFileDialog( startDir, QString(), 0L);
        dlg->setMode( KFile::File);
        dlg->setOperationMode( KFileDialog::Saving );
        QStringList filter;
        filter << "all/allfiles" << "text/plain";
        dlg->setMimeFilter( filter, "all/allfiles" );
#if 0 // SPLIT-TODO
        KUrlBar *urlBar = dlg->speedBar();
        if ( urlBar )
        {
            urlBar->insertDynamicItem( KUrl("ftp://ftp.kde.org"),
                                       QLatin1String("KDE FTP Server") );
        }
#endif
        if ( dlg->exec() == KDialog::Accepted )
            name1 = dlg->selectedUrl().url();
    }

    else if ( argv1 == QLatin1String("eventloop") )
    {
        new KFDTest( startDir );
        return a.exec();
    }

    else if (argv1 == QLatin1String("save")) {
        KUrl u = KFileDialog::getSaveUrl(startDir);
//        QString(QDir::homePath() + QLatin1String("/testfile")),
//        QString(), 0L);
        name1 = u.url();
    }

    else if (argv1 == QLatin1String("icon")) {
        KIconDialog dlg;
        QString icon = dlg.getIcon();
        kDebug() << icon;
    }

//     else if ( argv1 == QLatin1String("dirselect") ) {
//         KUrl url;
//         url.setPath( "/" );
//         KUrl selected = KDirSelectDialog::selectDirectory( url );
//         name1 = selected.url();
//         qDebug("*** selected: %s", selected.url().toLatin1().constData());
//     }

    else {
        KFileDialog dlg(startDir,
                        QString::fromLatin1("*|All Files\n"
                                            "*.lo *.o *.la|All libtool Files"),0);
//    dlg.setFilter( "*.kdevelop" );
        dlg.setMode( KFile::Files |
                     KFile::Directory |
                     KFile::ExistingOnly |
                     KFile::LocalOnly );
//        QStringList filter;
//        filter << "text/plain" << "text/html" << "image/png";
//        dlg.setMimeFilter( filter );
//        KMimeType::List types;
//        types.append( KMimeType::mimeType( "text/plain" ) );
//        types.append( KMimeType::mimeType( "text/html" ) );
//        dlg.setFilterMimeType( "Filetypes:", types, types.first() );
        if ( dlg.exec() == QDialog::Accepted ) {
            const KUrl::List list = dlg.selectedUrls();
            KUrl::List::ConstIterator it = list.constBegin();
            qDebug("*** selectedUrls(): ");
            while ( it != list.constEnd() ) {
                name1 = (*it).url();
                qDebug("  -> %s", name1.toLatin1().constData());
                ++it;
            }
            qDebug("*** selectedFile: %s", dlg.selectedFile().toLatin1().constData());
            qDebug("*** selectedUrl: %s", dlg.selectedUrl().url().toLatin1().constData());
            qDebug("*** selectedFiles: ");
            QStringList l = dlg.selectedFiles();
            QStringList::Iterator it2 = l.begin();
            while ( it2 != l.end() ) {
                qDebug("  -> %s", (*it2).toLatin1().constData());
                ++it2;
            }
        }
    }

    if (!(name1.isNull()))
        KMessageBox::information(0, QLatin1String("You selected the file " ) + name1,
                                 QLatin1String("Your Choice"));
    return 0;
}