renderwidget.cpp 95.7 KB
Newer Older
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/***************************************************************************
 *   Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
 ***************************************************************************/

20

21 22 23
#include "renderwidget.h"
#include "kdenlivesettings.h"
#include "ui_saveprofile_ui.h"
24
#include "timecode.h"
Vincent PINON's avatar
Vincent PINON committed
25
#include "dialogs/profilesdialog.h"
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
26 27 28

#include <KStandardDirs>
#include <KDebug>
29
#include <KMessageBox>
30
#include <KComboBox>
31
#include <KRun>
32
#include <KIO/NetAccess>
33
#include <KColorScheme>
34
#include <KNotification>
35
#include <KStartupInfo>
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
36

37 38 39 40 41 42 43
#include <QDomDocument>
#include <QItemDelegate>
#include <QTreeWidgetItem>
#include <QListWidgetItem>
#include <QHeaderView>
#include <QMenu>
#include <QInputDialog>
44
#include <QProcess>
45 46
#include <QDBusConnectionInterface>
#include <QDBusInterface>
47
#include <QThread>
48
#include <QScriptEngine>
49
#include <QKeyEvent>
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
50

51 52
#include "locale.h"

53 54

// Render profiles roles
55 56 57 58 59
const int GroupRole = Qt::UserRole;
const int ExtensionRole = GroupRole + 1;
const int StandardRole = GroupRole + 2;
const int RenderRole = GroupRole + 3;
const int ParamsRole = GroupRole + 4;
60
const int EditableRole = GroupRole + 5;
61
const int MetaGroupRole = GroupRole + 6;
62
const int ExtraRole = GroupRole + 7;
63 64
const int BitratesRole = GroupRole + 8;
const int DefaultBitrateRole = GroupRole + 9;
65 66
const int AudioBitratesRole = GroupRole + 10;
const int DefaultAudioBitrateRole = GroupRole + 11;
67

68 69 70
// Render job roles
const int ParametersRole = Qt::UserRole + 1;
const int TimeRole = Qt::UserRole + 2;
71 72
const int ProgressRole = Qt::UserRole + 3;
const int ExtraInfoRole = Qt::UserRole + 5;
73

74 75
const int DirectRenderType = QTreeWidgetItem::Type;
const int ScriptRenderType = QTreeWidgetItem::UserType;
76 77


78 79 80 81
// Running job status
const int WAITINGJOB = 0;
const int RUNNINGJOB = 1;
const int FINISHEDJOB = 2;
82 83 84 85
const int FAILEDJOB = 3;
const int ABORTEDJOB = 4;


Laurent Montel's avatar
Laurent Montel committed
86 87
RenderJobItem::RenderJobItem(QTreeWidget * parent, const QStringList & strings, int type)
    : QTreeWidgetItem(parent, strings, type),
88 89
    m_status(-1)
{
90
    setSizeHint(1, QSize(parent->columnWidth(1), parent->fontMetrics().height() * 3));
91 92 93 94 95
    setStatus(WAITINGJOB);
}

void RenderJobItem::setStatus(int status)
{
Laurent Montel's avatar
Laurent Montel committed
96 97
    if (m_status == status)
        return;
98 99 100 101 102 103 104 105 106
    m_status = status;
    switch (status) {
        case WAITINGJOB:
            setIcon(0, KIcon("media-playback-pause"));
            setData(1, Qt::UserRole, i18n("Waiting..."));
            break;
        case FINISHEDJOB:
            setData(1, Qt::UserRole, i18n("Rendering finished"));
            setIcon(0, KIcon("dialog-ok"));
107
            setData(1, ProgressRole, 100);
108 109 110 111
            break;
        case FAILEDJOB:
            setData(1, Qt::UserRole, i18n("Rendering crashed"));
            setIcon(0, KIcon("dialog-close"));
112
            setData(1, ProgressRole, 100);
113 114 115 116
            break;
        case ABORTEDJOB:
            setData(1, Qt::UserRole, i18n("Rendering aborted"));
            setIcon(0, KIcon("dialog-cancel"));
117
            setData(1, ProgressRole, 100);
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
        
        default:
            break;
    }
}

int RenderJobItem::status() const
{
    return m_status;
}

void RenderJobItem::setMetadata(const QString &data)
{
    m_data = data;
}

const QString RenderJobItem::metadata() const
{
    return m_data;
}
138 139


Laurent Montel's avatar
Laurent Montel committed
140
RenderWidget::RenderWidget(const QString &projectfolder, bool enableProxy, const MltVideoProfile &profile, QWidget * parent) :
141
        QDialog(parent),
142
        m_projectFolder(projectfolder),
143
        m_profile(profile),
144
        m_blockProcessing(false)
145
{
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
146
    m_view.setupUi(this);
147 148 149
    int size = style()->pixelMetric(QStyle::PM_SmallIconSize);
    QSize iconSize(size, size);
    
150
    setWindowTitle(i18n("Rendering"));
151 152 153 154 155 156
    m_view.buttonDelete->setIconSize(iconSize);
    m_view.buttonEdit->setIconSize(iconSize);
    m_view.buttonSave->setIconSize(iconSize);
    m_view.buttonInfo->setIconSize(iconSize);
    m_view.buttonFavorite->setIconSize(iconSize);
    
157 158 159 160
    m_view.buttonDelete->setIcon(KIcon("trash-empty"));
    m_view.buttonDelete->setToolTip(i18n("Delete profile"));
    m_view.buttonDelete->setEnabled(false);

161 162 163 164
    m_view.buttonEdit->setIcon(KIcon("document-properties"));
    m_view.buttonEdit->setToolTip(i18n("Edit profile"));
    m_view.buttonEdit->setEnabled(false);

165 166 167
    m_view.buttonSave->setIcon(KIcon("document-new"));
    m_view.buttonSave->setToolTip(i18n("Create new profile"));

168
    m_view.buttonInfo->setIcon(KIcon("help-about"));
169
    m_view.hide_log->setIcon(KIcon("go-down"));
170

171 172
    m_view.buttonFavorite->setIcon(KIcon("favorites"));
    m_view.buttonFavorite->setToolTip(i18n("Copy profile to favorites"));
173
    
174 175
    m_view.show_all_profiles->setToolTip(i18n("Show profiles with different framerate"));
    
176
    m_view.advanced_params->setMaximumHeight(QFontMetrics(font()).lineSpacing() * 5);
177 178 179
    
    m_view.buttonRender->setEnabled(false);
    m_view.buttonGenerateScript->setEnabled(false);
180
    setRescaleEnabled(false);
181 182 183 184 185 186 187 188
    m_view.guides_box->setVisible(false);
    m_view.open_dvd->setVisible(false);
    m_view.create_chapter->setVisible(false);
    m_view.open_browser->setVisible(false);
    m_view.error_box->setVisible(false);
    m_view.tc_type->setEnabled(false);
    m_view.checkTwoPass->setEnabled(false);
    
189 190
    if (KdenliveSettings::showrenderparams()) {
        m_view.buttonInfo->setDown(true);
Laurent Montel's avatar
Laurent Montel committed
191 192 193
    } else {
        m_view.advanced_params->hide();
    }
194
    
195
    m_view.proxy_render->setHidden(!enableProxy);
196

197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
    KColorScheme scheme(palette().currentColorGroup(), KColorScheme::Window, KSharedConfig::openConfig(KdenliveSettings::colortheme()));
    QColor bg = scheme.background(KColorScheme::NegativeBackground).color();
    m_view.errorBox->setStyleSheet(QString("QGroupBox { background-color: rgb(%1, %2, %3); border-radius: 5px;}; ").arg(bg.red()).arg(bg.green()).arg(bg.blue()));
    int height = QFontInfo(font()).pixelSize();
    m_view.errorIcon->setPixmap(KIcon("dialog-warning").pixmap(height, height));
    m_view.errorBox->setHidden(true);

#if KDE_IS_VERSION(4,7,0)
    m_infoMessage = new KMessageWidget;
    QGridLayout *s =  static_cast <QGridLayout*> (m_view.tab->layout());
    s->addWidget(m_infoMessage, 16, 0, 1, -1);
    m_infoMessage->setCloseButtonVisible(false);
    m_infoMessage->hide();
#endif

212 213 214 215
    m_view.encoder_threads->setMaximum(QThread::idealThreadCount());
    m_view.encoder_threads->setValue(KdenliveSettings::encodethreads());
    connect(m_view.encoder_threads, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateEncodeThreads(int)));

216 217 218 219 220 221
    m_view.rescale_keep->setChecked(KdenliveSettings::rescalekeepratio());
    connect(m_view.rescale_width, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateRescaleWidth(int)));
    connect(m_view.rescale_height, SIGNAL(valueChanged(int)), this, SLOT(slotUpdateRescaleHeight(int)));
    m_view.rescale_keep->setIcon(KIcon("insert-link"));
    m_view.rescale_keep->setToolTip(i18n("Preserve aspect ratio"));
    connect(m_view.rescale_keep, SIGNAL(clicked()), this, SLOT(slotSwitchAspectRatio()));
222

223 224 225
    connect(m_view.buttonRender, SIGNAL(clicked()), this, SLOT(slotPrepareExport()));
    connect(m_view.buttonGenerateScript, SIGNAL(clicked()), this, SLOT(slotGenerateScript()));

226 227 228 229
    m_view.abort_job->setEnabled(false);
    m_view.start_script->setEnabled(false);
    m_view.delete_script->setEnabled(false);

230 231
    m_view.format_list->setAlternatingRowColors(true);
    m_view.size_list->setAlternatingRowColors(true);
232

233 234 235
    connect(m_view.export_audio, SIGNAL(stateChanged(int)), this, SLOT(slotUpdateAudioLabel(int)));
    m_view.export_audio->setCheckState(Qt::PartiallyChecked);

236
    parseProfiles();
237
    parseScriptFiles();
238 239
    m_view.running_jobs->setUniformRowHeights(false);
    m_view.scripts_list->setUniformRowHeights(false);
240 241
    connect(m_view.start_script, SIGNAL(clicked()), this, SLOT(slotStartScript()));
    connect(m_view.delete_script, SIGNAL(clicked()), this, SLOT(slotDeleteScript()));
242 243
    connect(m_view.scripts_list, SIGNAL(itemSelectionChanged()), this, SLOT(slotCheckScript()));
    connect(m_view.running_jobs, SIGNAL(itemSelectionChanged()), this, SLOT(slotCheckJob()));
Laurent Montel's avatar
Laurent Montel committed
244
    connect(m_view.running_jobs, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), this, SLOT(slotPlayRendering(QTreeWidgetItem*,int)));
245

246 247
    connect(m_view.buttonInfo, SIGNAL(clicked()), this, SLOT(showInfoPanel()));

248
    connect(m_view.buttonSave, SIGNAL(clicked()), this, SLOT(slotSaveProfile()));
249
    connect(m_view.buttonEdit, SIGNAL(clicked()), this, SLOT(slotEditProfile()));
250
    connect(m_view.buttonDelete, SIGNAL(clicked()), this, SLOT(slotDeleteProfile()));
251 252
    connect(m_view.buttonFavorite, SIGNAL(clicked()), this, SLOT(slotCopyToFavorites()));

253
    connect(m_view.abort_job, SIGNAL(clicked()), this, SLOT(slotAbortCurrentJob()));
254
    connect(m_view.start_job, SIGNAL(clicked()), this, SLOT(slotStartCurrentJob()));
255 256 257
    connect(m_view.clean_up, SIGNAL(clicked()), this, SLOT(slotCLeanUpJobs()));
    connect(m_view.hide_log, SIGNAL(clicked()), this, SLOT(slotHideLog()));

258 259
    connect(m_view.buttonClose, SIGNAL(clicked()), this, SLOT(hide()));
    connect(m_view.buttonClose2, SIGNAL(clicked()), this, SLOT(hide()));
260
    connect(m_view.buttonClose3, SIGNAL(clicked()), this, SLOT(hide()));
261
    connect(m_view.rescale, SIGNAL(toggled(bool)), this, SLOT(setRescaleEnabled(bool)));
262
    connect(m_view.destination_list, SIGNAL(activated(int)), this, SLOT(refreshCategory()));
Laurent Montel's avatar
Laurent Montel committed
263 264
    connect(m_view.out_file, SIGNAL(textChanged(QString)), this, SLOT(slotUpdateButtons()));
    connect(m_view.out_file, SIGNAL(urlSelected(KUrl)), this, SLOT(slotUpdateButtons(KUrl)));
265 266
    connect(m_view.format_list, SIGNAL(currentRowChanged(int)), this, SLOT(refreshView()));
    connect(m_view.size_list, SIGNAL(currentRowChanged(int)), this, SLOT(refreshParams()));
267
    connect(m_view.show_all_profiles, SIGNAL(stateChanged(int)), this, SLOT(refreshView()));
268

Laurent Montel's avatar
Laurent Montel committed
269
    connect(m_view.size_list, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(slotEditItem(QListWidgetItem*)));
270

271 272 273 274 275 276 277
    connect(m_view.render_guide, SIGNAL(clicked(bool)), this, SLOT(slotUpdateGuideBox()));
    connect(m_view.render_zone, SIGNAL(clicked(bool)), this, SLOT(slotUpdateGuideBox()));
    connect(m_view.render_full, SIGNAL(clicked(bool)), this, SLOT(slotUpdateGuideBox()));

    connect(m_view.guide_end, SIGNAL(activated(int)), this, SLOT(slotCheckStartGuidePosition()));
    connect(m_view.guide_start, SIGNAL(activated(int)), this, SLOT(slotCheckEndGuidePosition()));

278
    connect(m_view.tc_overlay, SIGNAL(toggled(bool)), m_view.tc_type, SLOT(setEnabled(bool)));
279

280 281
    m_view.splitter->setStretchFactor(1, 5);
    m_view.splitter->setStretchFactor(0, 2);
282

283
    m_view.out_file->setMode(KFile::File);
284
    m_view.out_file->setFocusPolicy(Qt::ClickFocus);
285

286
    m_view.running_jobs->setHeaderLabels(QStringList() << QString() << i18n("File"));
287 288
    m_jobsDelegate = new RenderViewDelegate(this);
    m_view.running_jobs->setItemDelegate(m_jobsDelegate);
289

290
    QHeaderView *header = m_view.running_jobs->header();
291 292
    header->setResizeMode(0, QHeaderView::Fixed);
    header->resizeSection(0, 30);
293
    header->setResizeMode(1, QHeaderView::Interactive);
294

295
    m_view.scripts_list->setHeaderLabels(QStringList() << QString() << i18n("Script Files"));
296 297
    m_scriptsDelegate = new RenderViewDelegate(this);
    m_view.scripts_list->setItemDelegate(m_scriptsDelegate);
298 299 300
    header = m_view.scripts_list->header();
    header->setResizeMode(0, QHeaderView::Fixed);
    header->resizeSection(0, 30);
301

Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
302 303 304 305
    // Find path for Kdenlive renderer
    m_renderer = QCoreApplication::applicationDirPath() + QString("/kdenlive_render");
    if (!QFile::exists(m_renderer)) {
        m_renderer = KStandardDirs::findExe("kdenlive_render");
Laurent Montel's avatar
Laurent Montel committed
306 307 308 309
        if (m_renderer.isEmpty())
            m_renderer = KStandardDirs::locate("exe", "kdenlive_render");
        if (m_renderer.isEmpty())
            m_renderer = "kdenlive_render";
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
310 311
    }

312
    QDBusConnectionInterface* interface = QDBusConnection::sessionBus().interface();
313
    if (!interface || (!interface->isServiceRegistered("org.kde.ksmserver") && !interface->isServiceRegistered("org.gnome.SessionManager")))
314 315
        m_view.shutdown->setEnabled(false);

316
    focusFirstVisibleItem();
317
    adjustSize();
318 319 320 321 322 323
}

QSize RenderWidget::sizeHint() const
{
    // Make sure the widget has minimum size on opening
    return QSize(200, 200);
324 325
}

326 327 328 329 330 331 332 333
RenderWidget::~RenderWidget()
{
    m_view.running_jobs->blockSignals(true);
    m_view.scripts_list->blockSignals(true);
    m_view.running_jobs->clear();
    m_view.scripts_list->clear();
    delete m_jobsDelegate;
    delete m_scriptsDelegate;
334 335 336
#if KDE_IS_VERSION(4,7,0)
    delete m_infoMessage;
#endif
337 338
}

339 340
void RenderWidget::slotEditItem(QListWidgetItem *item)
{
Laurent Montel's avatar
Laurent Montel committed
341 342 343
    const QString edit = item->data(EditableRole).toString();
    if (edit.isEmpty() || !edit.endsWith(QLatin1String("customprofiles.xml")))
        slotSaveProfile();
344 345 346
    else slotEditProfile();
}

347 348
void RenderWidget::showInfoPanel()
{
349 350 351 352 353 354 355 356 357
    if (m_view.advanced_params->isVisible()) {
        m_view.advanced_params->setVisible(false);
        m_view.buttonInfo->setDown(false);
        KdenliveSettings::setShowrenderparams(false);
    } else {
        m_view.advanced_params->setVisible(true);
        m_view.buttonInfo->setDown(true);
        KdenliveSettings::setShowrenderparams(true);
    }
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
358 359
}

360
void RenderWidget::setDocumentPath(const QString &path)
361
{
362 363 364 365
    if (m_view.out_file->url().directory() == KUrl(m_projectFolder).directory()) {
        const QString fileName = m_view.out_file->url().fileName();
        m_view.out_file->setUrl(KUrl(path + fileName));
    }
366
    m_projectFolder = path;
367
    parseScriptFiles();
368

369 370
}

371 372
void RenderWidget::slotUpdateGuideBox()
{
373 374 375
    m_view.guides_box->setVisible(m_view.render_guide->isChecked());
}

376 377
void RenderWidget::slotCheckStartGuidePosition()
{
378 379 380 381
    if (m_view.guide_start->currentIndex() > m_view.guide_end->currentIndex())
        m_view.guide_start->setCurrentIndex(m_view.guide_end->currentIndex());
}

382 383
void RenderWidget::slotCheckEndGuidePosition()
{
384 385 386 387
    if (m_view.guide_end->currentIndex() < m_view.guide_start->currentIndex())
        m_view.guide_end->setCurrentIndex(m_view.guide_start->currentIndex());
}

388 389
void RenderWidget::setGuides(QDomElement guidesxml, double duration)
{
390 391 392
    m_view.guide_start->clear();
    m_view.guide_end->clear();
    QDomNodeList nodes = guidesxml.elementsByTagName("guide");
Laurent Montel's avatar
Laurent Montel committed
393
    if (!nodes.isEmpty()) {
394
        m_view.guide_start->addItem(i18n("Beginning"), "0");
395
        m_view.render_guide->setEnabled(true);
396 397 398 399 400
        m_view.create_chapter->setEnabled(true);
    } else {
        m_view.render_guide->setEnabled(false);
        m_view.create_chapter->setEnabled(false);
    }
401
    double fps = (double) m_profile.frame_rate_num / m_profile.frame_rate_den;
402
    for (int i = 0; i < nodes.count(); ++i) {
403 404
        QDomElement e = nodes.item(i).toElement();
        if (!e.isNull()) {
405 406 407 408
            GenTime pos = GenTime(e.attribute("time").toDouble());
            const QString guidePos = Timecode::getStringTimecode(pos.frames(fps), fps);
            m_view.guide_start->addItem(e.attribute("comment") + '/' + guidePos, e.attribute("time").toDouble());
            m_view.guide_end->addItem(e.attribute("comment") + '/' + guidePos, e.attribute("time").toDouble());
409 410
        }
    }
Laurent Montel's avatar
Laurent Montel committed
411
    if (!nodes.isEmpty())
412 413 414
        m_view.guide_end->addItem(i18n("End"), QString::number(duration));
}

415
/**
Simon Eugster's avatar
Simon Eugster committed
416 417 418
 * Will be called when the user selects an output file via the file dialog.
 * File extension will be added automatically.
 */
Laurent Montel's avatar
Laurent Montel committed
419
void RenderWidget::slotUpdateButtons(const KUrl &url)
420
{
421 422 423 424
    if (m_view.out_file->url().isEmpty()) {
        m_view.buttonGenerateScript->setEnabled(false);
        m_view.buttonRender->setEnabled(false);
    } else {
425 426
        updateButtons(); // This also checks whether the selected format is available
    }
427
    if (url != 0) {
428
        QListWidgetItem *item = m_view.size_list->currentItem();
429
        if (!item) {
430 431
            m_view.buttonRender->setEnabled(false);
            m_view.buttonGenerateScript->setEnabled(false);
432 433
            return;
        }
Laurent Montel's avatar
Laurent Montel committed
434 435
        const QString extension = item->data(ExtensionRole).toString();
        m_view.out_file->setUrl(filenameWithExtension(url, extension));
436 437 438
    }
}

Simon Eugster's avatar
Simon Eugster committed
439 440 441 442
/**
 * Will be called when the user changes the output file path in the text line.
 * File extension must NOT be added, would make editing impossible!
 */
443 444
void RenderWidget::slotUpdateButtons()
{
445 446 447 448 449 450
    if (m_view.out_file->url().isEmpty()) {
        m_view.buttonRender->setEnabled(false);
        m_view.buttonGenerateScript->setEnabled(false);
    } else {
        updateButtons(); // This also checks whether the selected format is available
    }
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
451 452
}

453 454
void RenderWidget::slotSaveProfile()
{
455
    //TODO: update to correctly use metagroups
456
    Ui::SaveProfile_UI ui;
457
    QPointer<QDialog> d = new QDialog(this);
458
    ui.setupUi(d);
459

460
    for (int i = 0; i < m_view.destination_list->count(); ++i)
461
        ui.destination_list->addItem(m_view.destination_list->itemIcon(i), m_view.destination_list->itemText(i), m_view.destination_list->itemData(i, Qt::UserRole));
462 463

    ui.destination_list->setCurrentIndex(m_view.destination_list->currentIndex());
464
    QString dest = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
465

466
    QString customGroup = m_view.format_list->currentItem()->text();
Yuri Chornoivan's avatar
Yuri Chornoivan committed
467
    if (customGroup.isEmpty()) customGroup = i18nc("Group Name", "Custom");
468
    ui.group_name->setText(customGroup);
469

470
    QStringList arguments = m_view.advanced_params->toPlainText().split(' ', QString::SkipEmptyParts);
471
    ui.parameters->setText(arguments.join(" "));
472 473
    ui.extension->setText(m_view.size_list->currentItem()->data(ExtensionRole).toString());
    ui.profile_name->setFocus();
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492
    QListWidgetItem *item = m_view.size_list->currentItem();
    if (ui.parameters->toPlainText().contains("%bitrate")) {
        if ( item && item->data(BitratesRole).canConvert(QVariant::StringList) && item->data(BitratesRole).toStringList().count()) {
            QStringList bitrates = item->data(BitratesRole).toStringList();
	    ui.vbitrates_list->setText(bitrates.join(","));
            if (item->data(DefaultBitrateRole).canConvert(QVariant::String))
                ui.default_vbitrate->setValue(item->data(DefaultBitrateRole).toInt());
        }
    }
    else ui.vbitrates->setHidden(true);
    if (ui.parameters->toPlainText().contains("%audiobitrate")) {
      if ( item && item->data(AudioBitratesRole).canConvert(QVariant::StringList) && item->data(AudioBitratesRole).toStringList().count()) {
            QStringList bitrates = item->data(AudioBitratesRole).toStringList();
	    ui.abitrates_list->setText(bitrates.join(","));
            if (item->data(DefaultAudioBitrateRole).canConvert(QVariant::String))
                ui.default_abitrate->setValue(item->data(DefaultAudioBitrateRole).toInt());
        }
    }
    else ui.abitrates->setHidden(true);
493

494
    if (d->exec() == QDialog::Accepted && !ui.profile_name->text().simplified().isEmpty()) {
495 496
        QString newProfileName = ui.profile_name->text().simplified();
        QString newGroupName = ui.group_name->text().simplified();
Yuri Chornoivan's avatar
Yuri Chornoivan committed
497
        if (newGroupName.isEmpty()) newGroupName = i18nc("Group Name", "Custom");
498
        QString newMetaGroupId = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
499 500

        QDomDocument doc;
501 502 503 504 505
        QDomElement profileElement = doc.createElement("profile");
        profileElement.setAttribute("name", newProfileName);
        profileElement.setAttribute("category", newGroupName);
        profileElement.setAttribute("destinationid", newMetaGroupId);
        profileElement.setAttribute("extension", ui.extension->text().simplified());
506 507 508 509
        QString args = ui.parameters->toPlainText().simplified();
        profileElement.setAttribute("args", args);
        if (args.contains("%bitrate")) {
            // profile has a variable bitrate
510 511
            profileElement.setAttribute("defaultbitrate", QString::number(ui.default_vbitrate->value()));
            profileElement.setAttribute("bitrates", ui.vbitrates_list->text());
512 513 514
        }
        if (args.contains("%audiobitrate")) {
            // profile has a variable bitrate
515 516
            profileElement.setAttribute("defaultaudiobitrate", QString::number(ui.default_abitrate->value()));
            profileElement.setAttribute("audiobitrates", ui.abitrates_list->text());
517
        }
518 519 520
        doc.appendChild(profileElement);
        saveProfile(doc.documentElement());

521 522 523 524 525 526
        parseProfiles(newMetaGroupId, newGroupName, newProfileName);
    }
    delete d;
}


527
void RenderWidget::saveProfile(const QDomElement &newprofile)
528
{
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549
    QString exportFile = KStandardDirs::locateLocal("appdata", "export/customprofiles.xml");
    QDomDocument doc;
    QFile file(exportFile);
    doc.setContent(&file, false);
    file.close();
    QDomElement documentElement;
    QDomElement profiles = doc.documentElement();
    if (profiles.isNull() || profiles.tagName() != "profiles") {
        doc.clear();
        profiles = doc.createElement("profiles");
        profiles.setAttribute("version", 1);
        doc.appendChild(profiles);
    }
    int version = profiles.attribute("version", 0).toInt();
    if (version < 1) {
        kDebug() << "// OLD profile version";
        doc.clear();
        profiles = doc.createElement("profiles");
        profiles.setAttribute("version", 1);
        doc.appendChild(profiles);
    }
550

551

552 553 554 555 556 557 558 559 560
    QDomNodeList profilelist = doc.elementsByTagName("profile");
    int i = 0;
    while (!profilelist.item(i).isNull()) {
        // make sure a profile with same name doesn't exist
        documentElement = profilelist.item(i).toElement();
        QString profileName = documentElement.attribute("name");
        if (profileName == newprofile.attribute("name")) {
            // a profile with that same name already exists
            bool ok;
Vincent PINON's avatar
Vincent PINON committed
561
            QString newProfileName = QInputDialog::getText(this, i18n("Profile already exists"), i18n("This profile name already exists. Change the name if you don't want to overwrite it."), KLineEdit::Normal, profileName, &ok);
562 563 564 565
            if (!ok) return;
            if (profileName == newProfileName) {
                profiles.removeChild(profilelist.item(i));
                break;
566 567
            }
        }
568
        ++i;
569
    }
570

571
    profiles.appendChild(newprofile);
572

573
    //QCString save = doc.toString().utf8();
574

575 576 577 578 579 580 581 582
    if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
        KMessageBox::sorry(this, i18n("Unable to write to file %1", exportFile));
        return;
    }
    QTextStream out(&file);
    out << doc.toString();
    if (file.error() != QFile::NoError) {
        KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
583
        file.close();
584 585 586
        return;
    }
    file.close();
587 588 589 590 591
}

void RenderWidget::slotCopyToFavorites()
{
    QListWidgetItem *item = m_view.size_list->currentItem();
Laurent Montel's avatar
Laurent Montel committed
592 593
    if (!item)
        return;
594 595 596 597 598 599 600 601
    QString currentGroup = m_view.format_list->currentItem()->text();

    QString params = item->data(ParamsRole).toString();
    QString extension = item->data(ExtensionRole).toString();
    QString currentProfile = item->text();
    QDomDocument doc;
    QDomElement profileElement = doc.createElement("profile");
    profileElement.setAttribute("name", currentProfile);
Yuri Chornoivan's avatar
Yuri Chornoivan committed
602
    profileElement.setAttribute("category", i18nc("Category Name", "Custom"));
603 604 605
    profileElement.setAttribute("destinationid", "favorites");
    profileElement.setAttribute("extension", extension);
    profileElement.setAttribute("args", params);
606 607 608 609
    profileElement.setAttribute("bitrates", item->data(BitratesRole).toStringList().join(","));
    profileElement.setAttribute("defaultbitrate", item->data(DefaultBitrateRole).toString());
    profileElement.setAttribute("audiobitrates", item->data(AudioBitratesRole).toStringList().join(","));
    profileElement.setAttribute("defaultaudiobitrate", item->data(DefaultAudioBitrateRole).toString());
610 611 612
    doc.appendChild(profileElement);
    saveProfile(doc.documentElement());
    parseProfiles(m_view.destination_list->itemData(m_view.destination_list->currentIndex(), Qt::UserRole).toString(), currentGroup, currentProfile);
613 614
}

615 616
void RenderWidget::slotEditProfile()
{
617 618 619 620 621 622 623 624 625
    QListWidgetItem *item = m_view.size_list->currentItem();
    if (!item) return;
    QString currentGroup = m_view.format_list->currentItem()->text();

    QString params = item->data(ParamsRole).toString();
    QString extension = item->data(ExtensionRole).toString();
    QString currentProfile = item->text();

    Ui::SaveProfile_UI ui;
626
    QPointer<QDialog> d = new QDialog(this);
627
    ui.setupUi(d);
628

629
    for (int i = 0; i < m_view.destination_list->count(); ++i)
630 631 632 633 634 635
        ui.destination_list->addItem(m_view.destination_list->itemIcon(i), m_view.destination_list->itemText(i), m_view.destination_list->itemData(i, Qt::UserRole));

    ui.destination_list->setCurrentIndex(m_view.destination_list->currentIndex());
    QString dest = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();

    QString customGroup = m_view.format_list->currentItem()->text();
Yuri Chornoivan's avatar
Yuri Chornoivan committed
636
    if (customGroup.isEmpty()) customGroup = i18nc("Group Name", "Custom");
637 638
    ui.group_name->setText(customGroup);

639 640 641 642
    ui.profile_name->setText(currentProfile);
    ui.extension->setText(extension);
    ui.parameters->setText(params);
    ui.profile_name->setFocus();
643 644 645 646 647 648 649
    if (ui.parameters->toPlainText().contains("%bitrate")) {
        if ( item->data(BitratesRole).canConvert(QVariant::StringList) && item->data(BitratesRole).toStringList().count()) {
            QStringList bitrates = item->data(BitratesRole).toStringList();
	    ui.vbitrates_list->setText(bitrates.join(","));
            if (item->data(DefaultBitrateRole).canConvert(QVariant::String))
                ui.default_vbitrate->setValue(item->data(DefaultBitrateRole).toInt());
        }
Laurent Montel's avatar
Laurent Montel committed
650 651
    } else {
        ui.vbitrates->setHidden(true);
652
    }
Laurent Montel's avatar
Laurent Montel committed
653

654 655 656 657 658 659 660 661 662 663
    if (ui.parameters->toPlainText().contains("%audiobitrate")) {
      if ( item->data(AudioBitratesRole).canConvert(QVariant::StringList) && item->data(AudioBitratesRole).toStringList().count()) {
            QStringList bitrates = item->data(AudioBitratesRole).toStringList();
	    ui.abitrates_list->setText(bitrates.join(","));
            if (item->data(DefaultAudioBitrateRole).canConvert(QVariant::String))
                ui.default_abitrate->setValue(item->data(DefaultAudioBitrateRole).toInt());
        }
    }
    else ui.abitrates->setHidden(true);
    
664
    d->setWindowTitle(i18n("Edit Profile"));
665
    if (d->exec() == QDialog::Accepted) {
666
        slotDeleteProfile(false);
667
        QString exportFile = KStandardDirs::locateLocal("appdata", "export/customprofiles.xml");
668 669 670 671 672
        QDomDocument doc;
        QFile file(exportFile);
        doc.setContent(&file, false);
        file.close();
        QDomElement documentElement;
673 674 675 676 677 678 679 680 681 682 683 684 685 686 687
        QDomElement profiles = doc.documentElement();

        if (profiles.isNull() || profiles.tagName() != "profiles") {
            doc.clear();
            profiles = doc.createElement("profiles");
            profiles.setAttribute("version", 1);
            doc.appendChild(profiles);
        }

        int version = profiles.attribute("version", 0).toInt();
        if (version < 1) {
            kDebug() << "// OLD profile version";
            doc.clear();
            profiles = doc.createElement("profiles");
            profiles.setAttribute("version", 1);
688
            doc.appendChild(profiles);
689 690 691 692
        }

        QString newProfileName = ui.profile_name->text().simplified();
        QString newGroupName = ui.group_name->text().simplified();
Yuri Chornoivan's avatar
Yuri Chornoivan committed
693
        if (newGroupName.isEmpty()) newGroupName = i18nc("Group Name", "Custom");
694 695 696 697 698 699 700 701 702 703
        QString newMetaGroupId = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
        QDomNodeList profilelist = doc.elementsByTagName("profile");
        int i = 0;
        while (!profilelist.item(i).isNull()) {
            // make sure a profile with same name doesn't exist
            documentElement = profilelist.item(i).toElement();
            QString profileName = documentElement.attribute("name");
            if (profileName == newProfileName) {
                // a profile with that same name already exists
                bool ok;
Vincent PINON's avatar
Vincent PINON committed
704
                newProfileName = QInputDialog::getText(this, i18n("Profile already exists"), i18n("This profile name already exists. Change the name if you don't want to overwrite it."), KLineEdit::Normal, newProfileName, &ok);
705 706 707
                if (!ok) return;
                if (profileName == newProfileName) {
                    profiles.removeChild(profilelist.item(i));
708 709 710
                    break;
                }
            }
711
            ++i;
712
        }
713

714 715
        QDomElement profileElement = doc.createElement("profile");
        profileElement.setAttribute("name", newProfileName);
716 717
        profileElement.setAttribute("category", newGroupName);
        profileElement.setAttribute("destinationid", newMetaGroupId);
718
        profileElement.setAttribute("extension", ui.extension->text().simplified());
719 720 721 722
        QString args = ui.parameters->toPlainText().simplified();
        profileElement.setAttribute("args", args);
        if (args.contains("%bitrate")) {
            // profile has a variable bitrate
723 724
	    profileElement.setAttribute("defaultbitrate", QString::number(ui.default_vbitrate->value()));
            profileElement.setAttribute("bitrates", ui.vbitrates_list->text());
725 726 727
        }
        if (args.contains("%audiobitrate")) {
            // profile has a variable bitrate
728 729
	    profileElement.setAttribute("defaultaudiobitrate", QString::number(ui.default_abitrate->value()));
            profileElement.setAttribute("audiobitrates", ui.abitrates_list->text());
730 731
        }

732
        profiles.appendChild(profileElement);
733 734

        //QCString save = doc.toString().utf8();
735
        delete d;
736
        if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
737
            KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
738 739 740 741
            return;
        }
        QTextStream out(&file);
        out << doc.toString();
742 743 744 745 746
        if (file.error() != QFile::NoError) {
            KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
            file.close();
            return;
        }
747
        file.close();
748
        parseProfiles(newMetaGroupId, newGroupName, newProfileName);
749
    } else delete d;
750 751
}

752 753
void RenderWidget::slotDeleteProfile(bool refresh)
{
754 755 756
    //TODO: delete a profile installed by KNewStuff the easy way
    /*
    QString edit = m_view.size_list->currentItem()->data(EditableRole).toString();
757
    if (!edit.endsWith(QLatin1String("customprofiles.xml"))) {
758
        // This is a KNewStuff installed file, process through KNS
759 760 761 762 763 764
        KNS::Engine engine(0);
        if (engine.init("kdenlive_render.knsrc")) {
            KNS::Entry::List entries;
        }
        return;
    }*/
765 766
    QString currentGroup = m_view.format_list->currentItem()->text();
    QString currentProfile = m_view.size_list->currentItem()->text();
767
    QString metaGroupId = m_view.destination_list->itemData(m_view.destination_list->currentIndex(), Qt::UserRole).toString();
768

769
    QString exportFile = KStandardDirs::locateLocal("appdata", "export/customprofiles.xml");
770 771 772 773 774 775
    QDomDocument doc;
    QFile file(exportFile);
    doc.setContent(&file, false);
    file.close();

    QDomElement documentElement;
776
    QDomNodeList profiles = doc.elementsByTagName("profile");
777
    int i = 0;
778 779 780
    QString groupName;
    QString profileName;
    QString destination;
781

782 783 784 785 786 787 788 789 790
    while (!profiles.item(i).isNull()) {
        documentElement = profiles.item(i).toElement();
        profileName = documentElement.attribute("name");
        groupName = documentElement.attribute("category");
        destination = documentElement.attribute("destinationid");

        if (profileName == currentProfile && groupName == currentGroup && destination == metaGroupId) {
            kDebug() << "// GOT it: " << profileName;
            doc.documentElement().removeChild(profiles.item(i));
791 792
            break;
        }
793
        ++i;
794 795 796 797 798 799 800 801
    }

    if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
        KMessageBox::sorry(this, i18n("Unable to write to file %1", exportFile));
        return;
    }
    QTextStream out(&file);
    out << doc.toString();
802 803 804 805 806
    if (file.error() != QFile::NoError) {
        KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
        file.close();
        return;
    }
807
    file.close();
808 809 810 811
    if (refresh) {
        parseProfiles(metaGroupId, currentGroup);
        focusFirstVisibleItem();
    }
812 813
}

814 815
void RenderWidget::updateButtons()
{
816 817 818 819
    if (!m_view.size_list->currentItem() || m_view.size_list->currentItem()->isHidden()) {
        m_view.buttonSave->setEnabled(false);
        m_view.buttonDelete->setEnabled(false);
        m_view.buttonEdit->setEnabled(false);
820 821
        m_view.buttonRender->setEnabled(false);
        m_view.buttonGenerateScript->setEnabled(false);
822 823
    } else {
        m_view.buttonSave->setEnabled(true);
824 825
        m_view.buttonRender->setEnabled(m_view.size_list->currentItem()->toolTip().isEmpty());
        m_view.buttonGenerateScript->setEnabled(m_view.size_list->currentItem()->toolTip().isEmpty());
826
        QString edit = m_view.size_list->currentItem()->data(EditableRole).toString();
827
        if (edit.isEmpty() || !edit.endsWith(QLatin1String("customprofiles.xml"))) {
828 829 830
            m_view.buttonDelete->setEnabled(false);
            m_view.buttonEdit->setEnabled(false);
        } else {
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
831 832
            m_view.buttonDelete->setEnabled(true);
            m_view.buttonEdit->setEnabled(true);
833 834 835 836 837
        }
    }
}


838
void RenderWidget::focusFirstVisibleItem(const QString &profile)
839
{
840
    if (!profile.isEmpty()) {
Laurent Montel's avatar
Laurent Montel committed
841 842 843
        QList <QListWidgetItem *> child = m_view.size_list->findItems(profile, Qt::MatchExactly);
        if (!child.isEmpty())
            m_view.size_list->setCurrentItem(child.at(0));
844
    }
845
    if (m_view.size_list->currentItem()) {
846 847 848
        updateButtons();
        return;
    }
849
    m_view.size_list->setCurrentRow(0);
850
    updateButtons();
851 852
}

853 854 855 856 857 858
void RenderWidget::slotPrepareExport(bool scriptExport)
{
    if (!QFile::exists(KdenliveSettings::rendererpath())) {
        KMessageBox::sorry(this, i18n("Cannot find the melt program required for rendering (part of Mlt)"));
        return;
    }
Simon Eugster's avatar
Simon Eugster committed
859
    if (m_view.play_after->isChecked() && KdenliveSettings::defaultplayerapp().isEmpty()) {
860
        KMessageBox::sorry(this, i18n("Cannot play video after rendering because the default video player application is not set.\nPlease define it in Kdenlive settings dialog."));
Simon Eugster's avatar
Simon Eugster committed
861
    }
862 863
    QString chapterFile;
    if (m_view.create_chapter->isChecked()) chapterFile = m_view.out_file->url().path() + ".dvdchapter";
Simon Eugster's avatar
Simon Eugster committed
864 865

    // mantisbt 1051
866 867 868 869
    if (!KStandardDirs::makeDir(m_view.out_file->url().directory())) {
        KMessageBox::sorry(this, i18n("The directory %1, could not be created.\nPlease make sure you have the required permissions.", m_view.out_file->url().directory()));
        return;
    }
Simon Eugster's avatar
Simon Eugster committed
870

871 872 873 874
    emit prepareRenderingData(scriptExport, m_view.render_zone->isChecked(), chapterFile);
}


875
void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut, const QMap<QString, QString> &metadata, const QString &playlistPath, const QString &scriptPath, bool exportAudio)
876
{
877
    QListWidgetItem *item = m_view.size_list->currentItem();
Laurent Montel's avatar
Laurent Montel committed
878 879
    if (!item)
        return;
880

881
    QString dest = m_view.out_file->url().path().trimmed();
Laurent Montel's avatar
Laurent Montel committed
882 883
    if (dest.isEmpty())
        return;
884 885 886 887

    // Check whether target file has an extension.
    // If not, ask whether extension should be added or not.
    QString extension = item->data(ExtensionRole).toString();
888
    if (!dest.endsWith(extension, Qt::CaseInsensitive)) {
889
        if (KMessageBox::questionYesNo(this, i18n("File has no extension. Add extension (%1)?", extension)) == KMessageBox::Yes) {
890
            dest.append('.' + extension);
891 892 893
        }
    }

894
    QFile f(dest);
895
    if (f.exists()) {
896
        if (KMessageBox::warningYesNo(this, i18n("Output file already exists. Do you want to overwrite it?")) != KMessageBox::Yes)
897 898
            return;
    }
899

900 901 902
    QStringList overlayargs;
    if (m_view.tc_overlay->isChecked()) {
        QString filterFile = KStandardDirs::locate("appdata", "metadata.properties");
903
        overlayargs << "meta.attr.timecode=1" << "meta.attr.timecode.markup=#" + QString(m_view.tc_type->currentIndex() ? "frame" : "timecode");
904
        overlayargs << "-attach" << "data_feed:attr_check" << "-attach";
905
        overlayargs << "data_show:" + filterFile << "_loader=1" << "dynamic=1";
906
    }
907 908 909 910 911 912

    QStringList render_process_args;

    if (!scriptExport) render_process_args << "-erase";
    if (KdenliveSettings::usekuiserver()) render_process_args << "-kuiserver";

913 914 915
    // get process id
    render_process_args << QString("-pid:%1").arg(QCoreApplication::applicationPid());

916 917
    // Set locale for render process if required
    if (QLocale().decimalPoint() != QLocale::system().decimalPoint()) {
918 919
	const QString currentLocale = setlocale(LC_NUMERIC, NULL);
        render_process_args << QString("-locale:%1").arg(currentLocale);
920 921
    }

922 923 924
    if (m_view.render_zone->isChecked()) render_process_args << "in=" + QString::number(zoneIn) << "out=" + QString::number(zoneOut);
    else if (m_view.render_guide->isChecked()) {
        double fps = (double) m_profile.frame_rate_num / m_profile.frame_rate_den;
925 926
        double guideStart = m_view.guide_start->itemData(m_view.guide_start->currentIndex()).toDouble();
        double guideEnd = m_view.guide_end->itemData(m_view.guide_end->currentIndex()).toDouble();
927
        render_process_args << "in=" + QString::number((int) GenTime(guideStart).frames(fps)) << "out=" + QString::number((int) GenTime(guideEnd).frames(fps));
928
    }
929

930 931
    if (!overlayargs.isEmpty()) render_process_args << "preargs=" + overlayargs.join(" ");

932 933 934 935 936
    if (scriptExport)
        render_process_args << "$MELT";
    else
        render_process_args << KdenliveSettings::rendererpath();
    render_process_args << m_profile.path << item->data(RenderRole).toString();
937
    if (m_view.play_after->isChecked()) render_process_args << KdenliveSettings::KdenliveSettings::defaultplayerapp();
938
    else render_process_args << "-";
939

940
    QString renderArgs = m_view.advanced_params->toPlainText().simplified();
941 942 943 944 945
    
    // Project metadata
    if (m_view.export_meta->isChecked()) {
        QMap<QString, QString>::const_iterator i = metadata.constBegin();
        while (i != metadata.constEnd()) {
946
            renderArgs.append(QString(" %1=%2").arg(i.key()).arg(QString(QUrl::toPercentEncoding(i.value()))));
947 948 949
            ++i;
        }
    }
950 951 952 953 954

    // Adjust frame scale
    int width;
    int height;
    if (m_view.rescale->isChecked() && m_view.rescale->isEnabled()) {
955 956
        width = m_view.rescale_width->value();
        height = m_view.rescale_height->value();
957 958 959 960
    } else {
        width = m_profile.width;
        height = m_profile.height;
    }
961

962 963
    //renderArgs.replace("%width", QString::number((int)(m_profile.height * m_profile.display_aspect_num / (double) m_profile.display_aspect_den + 0.5)));
    //renderArgs.replace("%height", QString::number((int)m_profile.height));
964 965 966 967 968 969

    // Adjust scanning
    if (m_view.scanning_list->currentIndex() == 1) renderArgs.append(" progressive=1");
    else if (m_view.scanning_list->currentIndex() == 2) renderArgs.append(" progressive=0");

    // disable audio if requested
970
    if (!exportAudio) renderArgs.append(" an=1 ");
971

972
    // Set the thread counts
973 974 975
    if (!renderArgs.contains("threads=")) {
        renderArgs.append(QString(" threads=%1").arg(KdenliveSettings::encodethreads()));
    }
976
    renderArgs.append(QString(" real_time=-1"));
977

978 979
    // Check if the rendering profile is different from project profile,
    // in which case we need to use the producer_comsumer from MLT
980
    QString std = renderArgs;
981
    QString destination = m_view.destination_list->itemData(m_view.destination_list->currentIndex()).toString();
982 983
    const QString currentSize = QString::number(width) + 'x' + QString::number(height);
    QString subsize = currentSize;
984
    if (std.startsWith(QLatin1String("s="))) {
985
        subsize = std.section(' ', 0, 0).toLower();
986
        subsize = subsize.section('=', 1, 1);
987
    } else if (std.contains(" s=")) {
988
        subsize = std.section(" s=", 1, 1);
989
        subsize = subsize.section(' ', 0, 0).toLower();
990
    } else if (destination !=