Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

renderwidget.cpp 102 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

Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
28
#include <QDebug>
29
#include <KMessageBox>
30
#include <KRun>
31
#include <KColorScheme>
32
#include <KNotification>
33
#include <KStandardDirs>
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
34

35 36 37 38 39
#include <QDomDocument>
#include <QTreeWidgetItem>
#include <QListWidgetItem>
#include <QHeaderView>
#include <QInputDialog>
40
#include <QProcess>
41
#include <QDBusConnectionInterface>
42
#include <QThread>
43
#include <QScriptEngine>
44
#include <QKeyEvent>
45
#include <QTimer>
46
#include <QStandardPaths>
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
47

48 49
#include "locale.h"

50 51

// Render profiles roles
52 53 54 55 56 57 58 59 60 61 62 63 64
enum {GroupRole = Qt::UserRole,
      ExtensionRole,
      StandardRole,
      RenderRole,
      ParamsRole,
      EditableRole,
      MetaGroupRole,
      ExtraRole,
      BitratesRole,
      DefaultBitrateRole,
      AudioBitratesRole,
      DefaultAudioBitrateRole
     };
65

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

72 73
const int DirectRenderType = QTreeWidgetItem::Type;
const int ScriptRenderType = QTreeWidgetItem::UserType;
74 75


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


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

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


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

159
    m_view.buttonEdit->setIcon(QIcon::fromTheme("document-properties"));
160 161 162
    m_view.buttonEdit->setToolTip(i18n("Edit profile"));
    m_view.buttonEdit->setEnabled(false);

163
    m_view.buttonSave->setIcon(QIcon::fromTheme("document-new"));
164 165
    m_view.buttonSave->setToolTip(i18n("Create new profile"));

166 167
    m_view.buttonInfo->setIcon(QIcon::fromTheme("help-about"));
    m_view.hide_log->setIcon(QIcon::fromTheme("go-down"));
168

169
    m_view.buttonFavorite->setIcon(QIcon::fromTheme("favorites"));
170
    m_view.buttonFavorite->setToolTip(i18n("Copy profile to favorites"));
171
    
172 173
    m_view.show_all_profiles->setToolTip(i18n("Show profiles with different framerate"));
    
174
    m_view.advanced_params->setMaximumHeight(QFontMetrics(font()).lineSpacing() * 5);
175 176 177
    
    m_view.buttonRender->setEnabled(false);
    m_view.buttonGenerateScript->setEnabled(false);
178
    setRescaleEnabled(false);
179 180 181 182 183 184 185 186
    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);
    
187 188
    if (KdenliveSettings::showrenderparams()) {
        m_view.buttonInfo->setDown(true);
Laurent Montel's avatar
Laurent Montel committed
189 190 191
    } else {
        m_view.advanced_params->hide();
    }
192
    
193
    m_view.proxy_render->setHidden(!enableProxy);
194

195 196 197 198
    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();
199
    m_view.errorIcon->setPixmap(QIcon::fromTheme("dialog-warning").pixmap(height, height));
200 201 202 203 204 205 206 207 208 209
    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

210 211 212 213
    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)));

214 215 216
    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)));
217
    m_view.rescale_keep->setIcon(QIcon::fromTheme("insert-link"));
218 219
    m_view.rescale_keep->setToolTip(i18n("Preserve aspect ratio"));
    connect(m_view.rescale_keep, SIGNAL(clicked()), this, SLOT(slotSwitchAspectRatio()));
220

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

224 225 226 227
    m_view.abort_job->setEnabled(false);
    m_view.start_script->setEnabled(false);
    m_view.delete_script->setEnabled(false);

228 229
    m_view.format_list->setAlternatingRowColors(true);
    m_view.size_list->setAlternatingRowColors(true);
230

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

234
    parseProfiles();
235
    parseScriptFiles();
236 237
    m_view.running_jobs->setUniformRowHeights(false);
    m_view.scripts_list->setUniformRowHeights(false);
238 239
    connect(m_view.start_script, SIGNAL(clicked()), this, SLOT(slotStartScript()));
    connect(m_view.delete_script, SIGNAL(clicked()), this, SLOT(slotDeleteScript()));
240 241
    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
242
    connect(m_view.running_jobs, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), this, SLOT(slotPlayRendering(QTreeWidgetItem*,int)));
243

244 245
    connect(m_view.buttonInfo, SIGNAL(clicked()), this, SLOT(showInfoPanel()));

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

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

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

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

269 270 271 272 273 274 275
    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()));

276
    connect(m_view.tc_overlay, SIGNAL(toggled(bool)), m_view.tc_type, SLOT(setEnabled(bool)));
277

278 279
    m_view.splitter->setStretchFactor(1, 5);
    m_view.splitter->setStretchFactor(0, 2);
280

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

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

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

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

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

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

314
    focusFirstVisibleItem();
315
    adjustSize();
316 317 318 319 320 321
}

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

324 325 326 327 328 329 330 331
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;
332 333 334
#if KDE_IS_VERSION(4,7,0)
    delete m_infoMessage;
#endif
335 336
}

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

345 346
void RenderWidget::showInfoPanel()
{
347 348 349 350 351 352 353 354 355
    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
356 357
}

358
void RenderWidget::setDocumentPath(const QString &path)
359
{
360
    if (m_view.out_file->url().adjusted(QUrl::RemoveFilename).path() == QUrl(m_projectFolder).adjusted(QUrl::RemoveFilename).path()) {
361
        const QString fileName = m_view.out_file->url().fileName();
362
        m_view.out_file->setUrl(QUrl(path + fileName));
363
    }
364
    m_projectFolder = path;
365
    parseScriptFiles();
366

367 368
}

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

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

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

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

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

Simon Eugster's avatar
Simon Eugster committed
437 438 439 440
/**
 * 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!
 */
441 442
void RenderWidget::slotUpdateButtons()
{
443 444 445 446 447 448
    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
449 450
}

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

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

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

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

468
    QStringList arguments = m_view.advanced_params->toPlainText().split(' ', QString::SkipEmptyParts);
469
    ui.parameters->setText(arguments.join(" "));
470 471
    ui.extension->setText(m_view.size_list->currentItem()->data(ExtensionRole).toString());
    ui.profile_name->setFocus();
472
    QListWidgetItem *item = m_view.size_list->currentItem();
473 474 475 476 477 478 479 480
    if (ui.parameters->toPlainText().contains("%bitrate") || ui.parameters->toPlainText().contains("%quality")) {
        if (ui.parameters->toPlainText().contains("%quality")) {
            ui.vbitrates_label->setText(i18n("Qualities"));
            ui.default_vbitrate_label->setText(i18n("Default quality"));
        } else {
            ui.vbitrates_label->setText(i18n("Bitrates"));
            ui.default_vbitrate_label->setText(i18n("Default bitrate"));
        }
481 482
        if ( item && item->data(BitratesRole).canConvert(QVariant::StringList) && item->data(BitratesRole).toStringList().count()) {
            QStringList bitrates = item->data(BitratesRole).toStringList();
483
            ui.vbitrates_list->setText(bitrates.join(","));
484 485 486 487 488
            if (item->data(DefaultBitrateRole).canConvert(QVariant::String))
                ui.default_vbitrate->setValue(item->data(DefaultBitrateRole).toInt());
        }
    }
    else ui.vbitrates->setHidden(true);
489 490 491 492 493 494 495 496 497
    if (ui.parameters->toPlainText().contains("%audiobitrate") || ui.parameters->toPlainText().contains("%audioquality")) {
        if (ui.parameters->toPlainText().contains("%audioquality")) {
            ui.abitrates_label->setText(i18n("Qualities"));
            ui.default_abitrate_label->setText(i18n("Default quality"));
        } else {
            ui.abitrates_label->setText(i18n("Bitrates"));
            ui.default_abitrate_label->setText(i18n("Default bitrate"));
        }
        if ( item && item->data(AudioBitratesRole).canConvert(QVariant::StringList) && item->data(AudioBitratesRole).toStringList().count()) {
498
            QStringList bitrates = item->data(AudioBitratesRole).toStringList();
499
            ui.abitrates_list->setText(bitrates.join(","));
500 501 502 503 504
            if (item->data(DefaultAudioBitrateRole).canConvert(QVariant::String))
                ui.default_abitrate->setValue(item->data(DefaultAudioBitrateRole).toInt());
        }
    }
    else ui.abitrates->setHidden(true);
505

506
    if (d->exec() == QDialog::Accepted && !ui.profile_name->text().simplified().isEmpty()) {
507 508
        QString newProfileName = ui.profile_name->text().simplified();
        QString newGroupName = ui.group_name->text().simplified();
Yuri Chornoivan's avatar
Yuri Chornoivan committed
509
        if (newGroupName.isEmpty()) newGroupName = i18nc("Group Name", "Custom");
510
        QString newMetaGroupId = ui.destination_list->itemData(ui.destination_list->currentIndex(), Qt::UserRole).toString();
511 512

        QDomDocument doc;
513 514 515 516 517
        QDomElement profileElement = doc.createElement("profile");
        profileElement.setAttribute("name", newProfileName);
        profileElement.setAttribute("category", newGroupName);
        profileElement.setAttribute("destinationid", newMetaGroupId);
        profileElement.setAttribute("extension", ui.extension->text().simplified());
518 519
        QString args = ui.parameters->toPlainText().simplified();
        profileElement.setAttribute("args", args);
520
        if (args.contains("%bitrate")) {
521
            // profile has a variable bitrate
522 523
            profileElement.setAttribute("defaultbitrate", QString::number(ui.default_vbitrate->value()));
            profileElement.setAttribute("bitrates", ui.vbitrates_list->text());
524 525 526
        } else if (args.contains("%quality")) {
            profileElement.setAttribute("defaultquality", QString::number(ui.default_vbitrate->value()));
            profileElement.setAttribute("qualities", ui.vbitrates_list->text());
527
        }
528 529

        if (args.contains("%audiobitrate")) {
530
            // profile has a variable bitrate
531 532
            profileElement.setAttribute("defaultaudiobitrate", QString::number(ui.default_abitrate->value()));
            profileElement.setAttribute("audiobitrates", ui.abitrates_list->text());
533 534 535 536
        } else if (args.contains("%audioquality")) {
            // profile has a variable bitrate
            profileElement.setAttribute("defaultaudioquality", QString::number(ui.default_abitrate->value()));
            profileElement.setAttribute("audioqualities", ui.abitrates_list->text());
537
        }
538 539 540
        doc.appendChild(profileElement);
        saveProfile(doc.documentElement());

541 542 543 544 545 546
        parseProfiles(newMetaGroupId, newGroupName, newProfileName);
    }
    delete d;
}


547
void RenderWidget::saveProfile(const QDomElement &newprofile)
548
{
549
    QString exportFile = QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/export/customprofiles.xml";
550 551 552 553 554 555 556 557 558 559 560 561 562 563
    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) {
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
564
        //qDebug() << "// OLD profile version";
565 566 567 568 569
        doc.clear();
        profiles = doc.createElement("profiles");
        profiles.setAttribute("version", 1);
        doc.appendChild(profiles);
    }
570

571

572 573 574 575 576 577 578 579 580
    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;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
581
            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."), QLineEdit::Normal, profileName, &ok);
582 583 584 585
            if (!ok) return;
            if (profileName == newProfileName) {
                profiles.removeChild(profilelist.item(i));
                break;
586 587
            }
        }
588
        ++i;
589
    }
590

591
    profiles.appendChild(newprofile);
592

593
    //QCString save = doc.toString().utf8();
594

595 596 597 598 599 600 601 602
    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));
603
        file.close();
604 605 606
        return;
    }
    file.close();
607 608 609 610 611
}

void RenderWidget::slotCopyToFavorites()
{
    QListWidgetItem *item = m_view.size_list->currentItem();
Laurent Montel's avatar
Laurent Montel committed
612 613
    if (!item)
        return;
614 615 616 617 618 619 620 621
    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
622
    profileElement.setAttribute("category", i18nc("Category Name", "Custom"));
623 624 625
    profileElement.setAttribute("destinationid", "favorites");
    profileElement.setAttribute("extension", extension);
    profileElement.setAttribute("args", params);
626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642
    if (params.contains("%bitrate")) {
        // profile has a variable bitrate
        profileElement.setAttribute("defaultbitrate", item->data(DefaultBitrateRole).toString());
        profileElement.setAttribute("bitrates", item->data(BitratesRole).toStringList().join(","));
    } else if (params.contains("%quality")) {
        profileElement.setAttribute("defaultquality", item->data(DefaultBitrateRole).toString());
        profileElement.setAttribute("qualities", item->data(BitratesRole).toStringList().join(","));
    }
    if (params.contains("%audiobitrate")) {
        // profile has a variable bitrate
        profileElement.setAttribute("defaultaudiobitrate", item->data(DefaultAudioBitrateRole).toString());
        profileElement.setAttribute("audiobitrates", item->data(AudioBitratesRole).toStringList().join(","));
    } else if (params.contains("%audioquality")) {
        // profile has a variable bitrate
        profileElement.setAttribute("defaultaudioquality", item->data(DefaultAudioBitrateRole).toString());
        profileElement.setAttribute("audioqualities", item->data(AudioBitratesRole).toStringList().join(","));
    }
643 644 645
    doc.appendChild(profileElement);
    saveProfile(doc.documentElement());
    parseProfiles(m_view.destination_list->itemData(m_view.destination_list->currentIndex(), Qt::UserRole).toString(), currentGroup, currentProfile);
646 647
}

648 649
void RenderWidget::slotEditProfile()
{
650 651 652 653 654 655 656 657 658
    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;
659
    QPointer<QDialog> d = new QDialog(this);
660
    ui.setupUi(d);
661

662
    for (int i = 0; i < m_view.destination_list->count(); ++i)
663 664 665 666 667 668
        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
669
    if (customGroup.isEmpty()) customGroup = i18nc("Group Name", "Custom");
670 671
    ui.group_name->setText(customGroup);

672 673 674 675
    ui.profile_name->setText(currentProfile);
    ui.extension->setText(extension);
    ui.parameters->setText(params);
    ui.profile_name->setFocus();
676 677 678 679 680 681 682 683
    if (ui.parameters->toPlainText().contains("%bitrate") || ui.parameters->toPlainText().contains("%quality")) {
        if (ui.parameters->toPlainText().contains("%quality")) {
            ui.vbitrates_label->setText(i18n("Qualities"));
            ui.default_vbitrate_label->setText(i18n("Default quality"));
        } else {
            ui.vbitrates_label->setText(i18n("Bitrates"));
            ui.default_vbitrate_label->setText(i18n("Default bitrate"));
        }
684 685
        if ( item->data(BitratesRole).canConvert(QVariant::StringList) && item->data(BitratesRole).toStringList().count()) {
            QStringList bitrates = item->data(BitratesRole).toStringList();
686
            ui.vbitrates_list->setText(bitrates.join(","));
687 688 689
            if (item->data(DefaultBitrateRole).canConvert(QVariant::String))
                ui.default_vbitrate->setValue(item->data(DefaultBitrateRole).toInt());
        }
Laurent Montel's avatar
Laurent Montel committed
690 691
    } else {
        ui.vbitrates->setHidden(true);
692
    }
Laurent Montel's avatar
Laurent Montel committed
693

694 695 696 697 698 699 700 701 702
    if (ui.parameters->toPlainText().contains("%audiobitrate") || ui.parameters->toPlainText().contains("%audioquality")) {
        if (ui.parameters->toPlainText().contains("%audioquality")) {
            ui.abitrates_label->setText(i18n("Qualities"));
            ui.default_abitrate_label->setText(i18n("Default quality"));
        } else {
            ui.abitrates_label->setText(i18n("Bitrates"));
            ui.default_abitrate_label->setText(i18n("Default bitrate"));
        }
        if ( item->data(AudioBitratesRole).canConvert(QVariant::StringList) && item->data(AudioBitratesRole).toStringList().count()) {
703
            QStringList bitrates = item->data(AudioBitratesRole).toStringList();
704
            ui.abitrates_list->setText(bitrates.join(","));
705 706 707 708 709 710
            if (item->data(DefaultAudioBitrateRole).canConvert(QVariant::String))
                ui.default_abitrate->setValue(item->data(DefaultAudioBitrateRole).toInt());
        }
    }
    else ui.abitrates->setHidden(true);
    
711
    d->setWindowTitle(i18n("Edit Profile"));
712
    if (d->exec() == QDialog::Accepted) {
713
        slotDeleteProfile(false);
714
        QString exportFile = QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/export/customprofiles.xml";
715 716 717 718 719
        QDomDocument doc;
        QFile file(exportFile);
        doc.setContent(&file, false);
        file.close();
        QDomElement documentElement;
720 721 722 723 724 725 726 727 728 729 730
        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) {
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
731
            //qDebug() << "// OLD profile version";
732 733 734
            doc.clear();
            profiles = doc.createElement("profiles");
            profiles.setAttribute("version", 1);
735
            doc.appendChild(profiles);
736 737 738 739
        }

        QString newProfileName = ui.profile_name->text().simplified();
        QString newGroupName = ui.group_name->text().simplified();
Yuri Chornoivan's avatar
Yuri Chornoivan committed
740
        if (newGroupName.isEmpty()) newGroupName = i18nc("Group Name", "Custom");
741 742 743 744 745 746 747 748 749 750
        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;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
751
                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."), QLineEdit::Normal, newProfileName, &ok);
752 753 754
                if (!ok) return;
                if (profileName == newProfileName) {
                    profiles.removeChild(profilelist.item(i));
755 756 757
                    break;
                }
            }
758
            ++i;
759
        }
760

761 762
        QDomElement profileElement = doc.createElement("profile");
        profileElement.setAttribute("name", newProfileName);
763 764
        profileElement.setAttribute("category", newGroupName);
        profileElement.setAttribute("destinationid", newMetaGroupId);
765
        profileElement.setAttribute("extension", ui.extension->text().simplified());
766 767
        QString args = ui.parameters->toPlainText().simplified();
        profileElement.setAttribute("args", args);
768
        if (args.contains("%bitrate")) {
769
            // profile has a variable bitrate
770
            profileElement.setAttribute("defaultbitrate", QString::number(ui.default_vbitrate->value()));
771
            profileElement.setAttribute("bitrates", ui.vbitrates_list->text());
772 773 774
        } else if(args.contains("%quality")) {
            profileElement.setAttribute("defaultquality", QString::number(ui.default_vbitrate->value()));
            profileElement.setAttribute("qualities", ui.vbitrates_list->text());
775
        }
776
        if (args.contains("%audiobitrate")) {
777
            // profile has a variable bitrate
778
            profileElement.setAttribute("defaultaudiobitrate", QString::number(ui.default_abitrate->value()));
779
            profileElement.setAttribute("audiobitrates", ui.abitrates_list->text());
780 781 782
        } else if (args.contains("%audioquality")) {
            profileElement.setAttribute("defaultaudioquality", QString::number(ui.default_abitrate->value()));
            profileElement.setAttribute("audioqualities", ui.abitrates_list->text());
783 784
        }

785
        profiles.appendChild(profileElement);
786 787

        //QCString save = doc.toString().utf8();
788
        delete d;
789
        if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
790
            KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
791 792 793 794
            return;
        }
        QTextStream out(&file);
        out << doc.toString();
795 796 797 798 799
        if (file.error() != QFile::NoError) {
            KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
            file.close();
            return;
        }
800
        file.close();
801
        parseProfiles(newMetaGroupId, newGroupName, newProfileName);
802
    } else delete d;
803 804
}

805 806
void RenderWidget::slotDeleteProfile(bool refresh)
{
807 808 809
    //TODO: delete a profile installed by KNewStuff the easy way
    /*
    QString edit = m_view.size_list->currentItem()->data(EditableRole).toString();
810
    if (!edit.endsWith(QLatin1String("customprofiles.xml"))) {
811
        // This is a KNewStuff installed file, process through KNS
812 813 814 815 816 817
        KNS::Engine engine(0);
        if (engine.init("kdenlive_render.knsrc")) {
            KNS::Entry::List entries;
        }
        return;
    }*/
818 819
    QString currentGroup = m_view.format_list->currentItem()->text();
    QString currentProfile = m_view.size_list->currentItem()->text();
820
    QString metaGroupId = m_view.destination_list->itemData(m_view.destination_list->currentIndex(), Qt::UserRole).toString();
821

822
    QString exportFile = QStandardPaths::writableLocation(QStandardPaths::DataLocation) + "/export/customprofiles.xml";
823 824 825 826 827 828
    QDomDocument doc;
    QFile file(exportFile);
    doc.setContent(&file, false);
    file.close();

    QDomElement documentElement;
829
    QDomNodeList profiles = doc.elementsByTagName("profile");
830
    int i = 0;
831 832 833
    QString groupName;
    QString profileName;
    QString destination;
834

835 836 837 838 839 840 841
    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) {
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
842
            //qDebug() << "// GOT it: " << profileName;
843
            doc.documentElement().removeChild(profiles.item(i));
844 845
            break;
        }
846
        ++i;
847 848 849 850 851 852 853 854
    }

    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();
855 856 857 858 859
    if (file.error() != QFile::NoError) {
        KMessageBox::error(this, i18n("Cannot write to file %1", exportFile));
        file.close();
        return;
    }
860
    file.close();
861 862 863 864
    if (refresh) {
        parseProfiles(metaGroupId, currentGroup);
        focusFirstVisibleItem();
    }
865 866
}

867 868
void RenderWidget::updateButtons()
{
869 870 871 872
    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);
873 874
        m_view.buttonRender->setEnabled(false);
        m_view.buttonGenerateScript->setEnabled(false);
875 876
    } else {
        m_view.buttonSave->setEnabled(true);
877 878
        m_view.buttonRender->setEnabled(m_view.size_list->currentItem()->toolTip().isEmpty());
        m_view.buttonGenerateScript->setEnabled(m_view.size_list->currentItem()->toolTip().isEmpty());
879
        QString edit = m_view.size_list->currentItem()->data(EditableRole).toString();
880
        if (edit.isEmpty() || !edit.endsWith(QLatin1String("customprofiles.xml"))) {
881 882 883
            m_view.buttonDelete->setEnabled(false);
            m_view.buttonEdit->setEnabled(false);
        } else {
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
884 885
            m_view.buttonDelete->setEnabled(true);
            m_view.buttonEdit->setEnabled(true);
886 887 888 889 890
        }
    }
}


891
void RenderWidget::focusFirstVisibleItem(const QString &profile)
892
{
893
    if (!profile.isEmpty()) {
Laurent Montel's avatar
Laurent Montel committed
894 895 896
        QList <QListWidgetItem *> child = m_view.size_list->findItems(profile, Qt::MatchExactly);
        if (!child.isEmpty())
            m_view.size_list->setCurrentItem(child.at(0));
897
    }
898
    if (m_view.size_list->currentItem()) {
899 900 901
        updateButtons();
        return;
    }
902
    m_view.size_list->setCurrentRow(0);
903
    updateButtons();
904 905
}

906 907 908 909 910 911
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
912
    if (m_view.play_after->isChecked() && KdenliveSettings::defaultplayerapp().isEmpty()) {
913
        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
914
    }
915 916
    QString chapterFile;
    if (m_view.create_chapter->isChecked()) chapterFile = m_view.out_file->url().path() + ".dvdchapter";
Simon Eugster's avatar
Simon Eugster committed
917 918

    // mantisbt 1051
919 920
    if (!KStandardDirs::makeDir(m_view.out_file->url().adjusted(QUrl::RemoveFilename).path())) {
        KMessageBox::sorry(this, i18n("The directory %1, could not be created.\nPlease make sure you have the required permissions.", m_view.out_file->url().adjusted(QUrl::RemoveFilename).path()));
921 922
        return;
    }
Simon Eugster's avatar
Simon Eugster committed
923

924 925 926 927
    emit prepareRenderingData(scriptExport, m_view.render_zone->isChecked(), chapterFile);
}


928
void RenderWidget::slotExport(bool scriptExport, int zoneIn, int zoneOut, const QMap<QString, QString> &metadata, const QString &playlistPath, const QString &scriptPath, bool exportAudio)
929
{
930
    QListWidgetItem *item = m_view.size_list->currentItem();
Laurent Montel's avatar
Laurent Montel committed
931 932
    if (!item)
        return;
933

934
    QString dest = m_view.out_file->url().path().trimmed();
Laurent Montel's avatar
Laurent Montel committed
935 936
    if (dest.isEmpty())
        return;
937 938 939 940

    // Check whether target file has an extension.
    // If not, ask whether extension should be added or not.
    QString extension = item->data(ExtensionRole).toString();
941
    if (!dest.endsWith(extension, Qt::CaseInsensitive)) {
942
        if (KMessageBox::questionYesNo(this, i18n("File has no extension. Add extension (%1)?", extension)) == KMessageBox::Yes) {
943
            dest.append('.' + extension);
944 945
        }
    }
946 947 948 949 950 951 952
    // Checks for image sequence
    if (extension == "jpg" || extension == "png") {
        // format string for counter?
        if(!QRegExp(".*%[0-9]*d.*").exactMatch(dest)) {
            dest = dest.section('.',0,-2) + "_%05d." + extension;
        }
    }
953

954
    QFile f(dest);
955
    if (f.exists()) {
956
        if (KMessageBox::warningYesNo(this, i18n("Output file already exists. Do you want to overwrite it?")) != KMessageBox::Yes)
957 958
            return;
    }