Start of Kdenlive's d-bus interface, bringing a new tab in the render dialog...

Start of Kdenlive's d-bus interface, bringing a new tab in the render dialog showing currently running renderings

svn path=/branches/KDE4/; revision=2920
parent c539149f
......@@ -33,7 +33,7 @@ public:
static QDBusConnection connection(QLatin1String(""));
RenderJob::RenderJob(bool erase, const QString &renderer, const QString &profile, const QString &rendermodule, const QString &player, const QString &scenelist, const QString &dest, const QStringList &preargs, const QStringList &args, int in, int out) : QObject(), m_jobUiserver(NULL) {
RenderJob::RenderJob(bool erase, const QString &renderer, const QString &profile, const QString &rendermodule, const QString &player, const QString &scenelist, const QString &dest, const QStringList &preargs, const QStringList &args, int in, int out) : QObject(), m_jobUiserver(NULL), m_kdenliveinterface(NULL) {
m_scenelist = scenelist;
m_dest = dest;
m_player = player;
......@@ -47,10 +47,9 @@ RenderJob::RenderJob(bool erase, const QString &renderer, const QString &profile
m_args << preargs;
//qDebug()<<"PRE ARGS: "<<preargs;
if (scenelist.startsWith("consumer:")) {
// Use MLT's producer_consumer, needs a different syntax for profile:
m_args << "profile=" + profile;
}
else m_args << "-profile" << profile;
// Use MLT's producer_consumer, needs a different syntax for profile:
m_args << "profile=" + profile;
} else m_args << "-profile" << profile;
m_args << "-consumer" << rendermodule + ":" + m_dest << "progress=1" << args;
connect(m_renderProcess, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(slotIsOver(int, QProcess::ExitStatus)));
m_renderProcess->setReadChannel(QProcess::StandardError);
......@@ -102,13 +101,18 @@ void RenderJob::receivedStderr() {
m_logstream << "ReceivedStderr from inigo: " << result << endl;
result = result.section(" ", -1);
int pro = result.toInt();
if ( m_jobUiserver && pro > m_progress) {
if (m_kdenliveinterface && pro > m_progress) {
m_dbusargs[1] = pro;
m_kdenliveinterface->callWithArgumentList(QDBus::NoBlock, "setRenderingProgress", m_dbusargs);
}
if (m_jobUiserver && pro > m_progress) {
m_progress = pro;
m_jobUiserver->call("setPercent", (uint) m_progress);
int seconds = m_startTime.secsTo(QTime::currentTime());
seconds = seconds * (100 - m_progress) / m_progress;
m_jobUiserver->call("setDescriptionField", (uint) 1, tr("Remaining time"), QTime(0, 0, seconds).toString("hh:mm:ss"));
}
}
void RenderJob::start() {
......@@ -146,6 +150,31 @@ void RenderJob::start() {
}
}
}
QString kdenliveId;
QDBusConnection connection = QDBusConnection::sessionBus();
QDBusConnectionInterface *ibus = connection.interface();
const QStringList services = ibus->registeredServiceNames();
foreach(const QString &service, services) {
if (!service.startsWith("org.kde.kdenlive"))
continue;
kdenliveId = service;
break;
}
QDBusConnection bus = QDBusConnection::sessionBus();
m_kdenliveinterface = new QDBusInterface(kdenliveId,
"/MainWindow",
"org.kdenlive.MainWindow",
bus,
this);
if (m_kdenliveinterface) {
m_dbusargs.append(m_dest);
m_dbusargs.append((int) 0);
m_kdenliveinterface->callWithArgumentList(QDBus::NoBlock, "setRenderingProgress", m_dbusargs);
}
// Because of the logging, we connect to stderr in all cases.
connect(m_renderProcess, SIGNAL(readyReadStandardError()), this, SLOT(receivedStderr()));
m_renderProcess->start(m_prog, m_args);
......@@ -162,12 +191,20 @@ void RenderJob::slotIsOver(int exitcode, QProcess::ExitStatus status) {
}
if (status == QProcess::CrashExit) {
// rendering crashed
if (m_kdenliveinterface) {
m_dbusargs[1] = -2;
m_kdenliveinterface->callWithArgumentList(QDBus::NoBlock, "setRenderingProgress", m_dbusargs);
}
QStringList args;
args << "--error" << tr("Rendering of %1 aborted, resulting video will probably be corrupted.").arg(m_dest);
m_logstream << "Rendering of " << m_dest << " aborted, resulting video will probably be corrupted." << endl;
qDebug() << "Rendering of " << m_dest << " aborted, resulting video will probably be corrupted.";
QProcess::startDetached("kdialog", args);
} else {
if (m_kdenliveinterface) {
m_dbusargs[1] = -1;
m_kdenliveinterface->callWithArgumentList(QDBus::NoBlock, "setRenderingProgress", m_dbusargs);
}
QDBusConnectionInterface* interface = QDBusConnection::sessionBus().interface();
if (interface && interface->isServiceRegistered("org.kde.knotify")) {
QDBusMessage m = QDBusMessage::createMethodCall("org.kde.knotify",
......
......@@ -51,6 +51,8 @@ private:
QStringList m_args;
bool m_erase;
QDBusInterface *m_jobUiserver;
QDBusInterface *m_kdenliveinterface;
QList<QVariant> m_dbusargs;
QTime m_startTime;
/** \brief Used to create a temporary file for logging */
QTemporaryFile m_logfile;
......
......@@ -23,7 +23,6 @@ ${NEPOMUK_LIBRARIES}
)
kde4_add_ui_files(kdenlive_UI
widgets/timeline_ui.ui
widgets/monitor_ui.ui
......@@ -154,9 +153,10 @@ else(NO_JOGSHUTTLE)
endif(NO_JOGSHUTTLE)
kde4_add_kcfg_files(kdenlive_SRCS GENERATE_MOC kdenlivesettings.kcfgc )
QT4_ADD_DBUS_ADAPTOR(kdenlive_SRCS org.kdenlive.MainWindow.xml mainwindow.h MainWindow)
kde4_add_executable(kdenlive ${kdenlive_SRCS} ${kdenlive_UI})
target_link_libraries(kdenlive
${KDE4_KDEUI_LIBS}
${KDE4_KIO_LIBS}
......@@ -166,7 +166,7 @@ target_link_libraries(kdenlive
${NEPOMUK_LIBRARIES}
${KDE4_KNOTIFYCONFIG_LIBRARY}
)
install(TARGETS kdenlive DESTINATION ${BIN_INSTALL_DIR})
install( FILES kdenliveui.rc kdenlive.notifyrc DESTINATION ${DATA_INSTALL_DIR}/kdenlive )
install (FILES kdenlivesettings.kcfg DESTINATION share/config.kcfg)
......
......@@ -57,6 +57,7 @@
#include "mainwindow.h"
#include "mainwindowadaptor.h"
#include "kdenlivesettings.h"
#include "kdenlivesettingsdialog.h"
#include "initeffects.h"
......@@ -113,6 +114,12 @@ MainWindow::MainWindow(const QString &MltPath, const KUrl & Url, QWidget *parent
m_jogProcess(NULL),
#endif /* NO_JOGSHUTTLE */
m_findActivated(false), m_initialized(false) {
// Create DBus interface
new MainWindowAdaptor(this);
QDBusConnection dbus = QDBusConnection::sessionBus();
dbus.registerObject("/MainWindow", this);
setlocale(LC_NUMERIC, "POSIX");
setFont(KGlobalSettings::toolBarFont());
parseProfiles(MltPath);
......@@ -1459,6 +1466,10 @@ void MainWindow::slotDoRender(const QString &dest, const QString &render, const
}
}
void MainWindow::setRenderingProgress(const QString &url, int progress) {
if (m_renderWidget) m_renderWidget->setRenderJob(url, progress);
}
void MainWindow::slotUpdateMousePosition(int pos) {
if (m_activeDocument)
switch (m_timecodeFormat->currentIndex()) {
......
......@@ -62,6 +62,7 @@ class Transition;
class MainWindow : public KXmlGuiWindow {
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.kdenlive.MainWindow")
public:
/** Constructor
......@@ -195,6 +196,7 @@ private:
public slots:
void openFile(const KUrl &url);
void slotGotProgressInfo(const QString &message, int progress);
Q_SCRIPTABLE void setRenderingProgress(const QString &url, int progress);
private slots:
void newFile(bool showProjectSettings = true);
......
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<interface name="org.kdenlive.MainWindow">
<method name="setRenderingProgress">
<arg name="url" type="s" direction="in"/>
<arg name="progress" type="i" direction="in"/>
</method>
</interface>
</node>
......@@ -19,6 +19,9 @@
#include <QDomDocument>
#include <QItemDelegate>
#include <QTreeWidgetItem>
#include <QHeaderView>
#include <KStandardDirs>
#include <KDebug>
......@@ -65,6 +68,8 @@ RenderWidget::RenderWidget(QWidget * parent): QDialog(parent) {
connect(m_view.buttonEdit, SIGNAL(clicked()), this, SLOT(slotEditProfile()));
connect(m_view.buttonDelete, SIGNAL(clicked()), this, SLOT(slotDeleteProfile()));
connect(m_view.buttonStart, SIGNAL(clicked()), this, SLOT(slotExport()));
connect(m_view.buttonClose, SIGNAL(clicked()), this, SLOT(hide()));
connect(m_view.buttonClose2, SIGNAL(clicked()), this, SLOT(hide()));
connect(m_view.out_file, SIGNAL(textChanged(const QString &)), this, SLOT(slotUpdateButtons()));
connect(m_view.format_list, SIGNAL(currentRowChanged(int)), this, SLOT(refreshView()));
connect(m_view.size_list, SIGNAL(currentRowChanged(int)), this, SLOT(refreshParams()));
......@@ -86,6 +91,18 @@ RenderWidget::RenderWidget(QWidget * parent): QDialog(parent) {
m_view.splitter->setStretchFactor(0, 2);
m_view.out_file->setMode(KFile::File);
m_view.running_jobs->setItemDelegate(new RenderViewDelegate(this));
QHeaderView *header = m_view.running_jobs->header();
QFontMetrics fm = fontMetrics();
//header->resizeSection(0, fm.width("typical-name-for-a-torrent.torrent"));
header->setResizeMode(0, QHeaderView::Interactive);
header->resizeSection(0, fm.width("typical-name-for-a-file.torrent"));
header->setResizeMode(1, QHeaderView::Fixed);
header->resizeSection(0, width() * 2 / 3);
header->setResizeMode(1, QHeaderView::Interactive);
//header->setResizeMode(1, QHeaderView::Fixed);
focusFirstVisibleItem();
}
......@@ -616,8 +633,31 @@ void RenderWidget::parseFile(QString exportFile, bool editable) {
}
}
void RenderWidget::setRenderJob(const QString &dest, int progress) {
QList<QTreeWidgetItem *> existing = m_view.running_jobs->findItems(dest, Qt::MatchExactly);
if (!existing.isEmpty()) {
if (progress == -1) {
// Job finished successfully
existing.at(0)->setIcon(0, KIcon("dialog-ok"));
existing.at(0)->setData(1, Qt::UserRole, 100);
} else if (progress == -2) {
// Rendering crashed
existing.at(0)->setIcon(0, KIcon("dialog-close"));
existing.at(0)->setData(1, Qt::UserRole, 0);
} else existing.at(0)->setData(1, Qt::UserRole, progress);
return;
}
QTreeWidgetItem *item = new QTreeWidgetItem(m_view.running_jobs, QStringList() << dest << QString());
if (progress == -1) {
// Job finished successfully
item->setIcon(0, KIcon("dialog-ok"));
item->setData(1, Qt::UserRole, 100);
} else if (progress == -2) {
// Rendering crashed
item->setIcon(0, KIcon("dialog-close"));
item->setData(1, Qt::UserRole, 0);
} else item->setData(1, Qt::UserRole, progress);
}
#include "renderwidget.moc"
......@@ -27,6 +27,43 @@
#include "definitions.h"
#include "ui_renderwidget_ui.h"
// RenderViewDelegate is used to draw the progress bars.
class RenderViewDelegate : public QItemDelegate {
Q_OBJECT
public:
RenderViewDelegate(QWidget *parent) : QItemDelegate(parent) {}
void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const {
if (index.column() != 1) {
QItemDelegate::paint(painter, option, index);
return;
}
// Set up a QStyleOptionProgressBar to precisely mimic the
// environment of a progress bar.
QStyleOptionProgressBar progressBarOption;
progressBarOption.state = QStyle::State_Enabled;
progressBarOption.direction = QApplication::layoutDirection();
progressBarOption.rect = option.rect;
progressBarOption.fontMetrics = QApplication::fontMetrics();
progressBarOption.minimum = 0;
progressBarOption.maximum = 100;
progressBarOption.textAlignment = Qt::AlignCenter;
progressBarOption.textVisible = true;
// Set the progress and text values of the style option.
int progress = index.data(Qt::UserRole).toInt();
progressBarOption.progress = progress < 0 ? 0 : progress;
progressBarOption.text = QString().sprintf("%d%%", progressBarOption.progress);
// Draw the progress bar onto the view.
QApplication::style()->drawControl(QStyle::CE_ProgressBar, &progressBarOption, painter);
}
};
class RenderWidget : public QDialog {
Q_OBJECT
......@@ -35,6 +72,7 @@ public:
void setGuides(QDomElement guidesxml, double duration);
void focusFirstVisibleItem();
void setProfile(MltVideoProfile profile);
void setRenderJob(const QString &dest, int progress = 0);
private slots:
void slotUpdateButtons();
......@@ -56,6 +94,7 @@ private:
void parseProfiles(QString group = QString(), QString profile = QString());
void parseFile(QString exportFile, bool editable);
void updateButtons();
signals:
void doRender(const QString&, const QString&, const QStringList &, const QStringList &, bool, bool, double, double, bool);
};
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment