Ejemplo n.º 1
0
//***************************************************************************
QStringList *Kwave::SaveBlocksPlugin::setup(QStringList &previous_params)
{
    // try to interpret the previous parameters
    interpreteParameters(previous_params);

    // create the setup dialog
    sample_index_t selection_left  = 0;
    sample_index_t selection_right = 0;
    selection(0, &selection_left, &selection_right, false);

    // enable the "selection only" checkbox only if there is something
    // selected but not everything
    bool selected_something = (selection_left != selection_right);
    bool selected_all = ((selection_left == 0) &&
                         (selection_right + 1 >= signalLength()));
    bool enable_selection_only = selected_something && !selected_all;

    QString filename = m_url.path();
    QString base = findBase(filename, m_pattern);
    scanBlocksToSave(base, m_selection_only && enable_selection_only);

    QPointer<Kwave::SaveBlocksDialog> dialog =
	new(std::nothrow) Kwave::SaveBlocksDialog(
	    _("kfiledialog:///kwave_save_blocks"),
	    Kwave::CodecManager::encodingFilter(),
	    parentWidget(),
	    QUrl::fromUserInput(signalName()),
	    _("*.wav"),
	    m_pattern,
	    m_numbering_mode,
	    m_selection_only,
	    enable_selection_only
	);
    if (!dialog) return 0;

    // connect the signals/slots from the plugin and the dialog
    connect(dialog, SIGNAL(sigSelectionChanged(QString,
	QString,Kwave::SaveBlocksPlugin::numbering_mode_t,bool)),
	this, SLOT(updateExample(QString,QString,
	Kwave::SaveBlocksPlugin::numbering_mode_t,bool)));
    connect(this, SIGNAL(sigNewExample(QString)),
	dialog, SLOT(setNewExample(QString)));

    dialog->setWindowTitle(i18n("Save Blocks"));
    dialog->emitUpdate();
    if (dialog->exec() != QDialog::Accepted) {
	delete dialog;
	return 0;
    }

    QStringList *list = new QStringList();
    Q_ASSERT(list);
    if (list) {
	// user has pressed "OK"
	QString pattern;

	QUrl url = dialog->selectedUrl();
	if (url.isEmpty()) {
	    delete dialog;
	    return 0;
	}
	QString name = url.path();
	QFileInfo path(name);

	// add the correct extension if necessary
	if (!path.suffix().length()) {
	    QString ext = dialog->selectedExtension();
	    QStringList extensions = ext.split(_(" "));
	    ext = extensions.first();
	    name += ext.mid(1);
	    path = name;
	    url.setPath(name);
	}

	name     = Kwave::Parser::escape(name);
	pattern  = Kwave::Parser::escape(dialog->pattern());
	int mode = static_cast<int>(dialog->numberingMode());
	bool selection_only = (enable_selection_only) ?
	    dialog->selectionOnly() : m_selection_only;

	*list << name;
	*list << pattern;
	*list << QString::number(mode);
	*list << QString::number(selection_only);

	emitCommand(_("plugin:execute(saveblocks,") +
	    name + _(",") + pattern + _(",") +
	    QString::number(mode) + _(",") +
	    QString::number(selection_only) + _(")")
	);
    } else {
	// user pressed "Cancel"
	delete list;
	list = 0;
    }

    if (dialog) delete dialog;
    return list;
}