1 /***************************************************************************
2 * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
21 #include "recmonitor.h"
23 #include "kdenlivesettings.h"
24 #include "managecapturesdialog.h"
29 #include <KStandardDirs>
31 #include <KIO/NetAccess>
33 #include <KMessageBox>
34 #include <KApplication>
36 #if KDE_IS_VERSION(4,2,0)
37 #include <KDiskFreeSpaceInfo>
40 #include <QMouseEvent>
42 #include <QToolButton>
47 RecMonitor::RecMonitor(QString name, QWidget *parent) :
55 m_hdmiCapturing(false)
59 video_frame->setAttribute(Qt::WA_PaintOnScreen);
60 device_selector->setCurrentIndex(KdenliveSettings::defaultcapture());
61 connect(device_selector, SIGNAL(currentIndexChanged(int)), this, SLOT(slotVideoDeviceChanged(int)));
63 QToolBar *toolbar = new QToolBar(name, this);
64 QHBoxLayout *layout = new QHBoxLayout;
65 layout->setContentsMargins(0, 0, 0, 0);
66 m_playIcon = KIcon("media-playback-start");
67 m_pauseIcon = KIcon("media-playback-pause");
69 m_discAction = toolbar->addAction(KIcon("network-connect"), i18n("Connect"));
70 connect(m_discAction, SIGNAL(triggered()), this, SLOT(slotDisconnect()));
72 m_rewAction = toolbar->addAction(KIcon("media-seek-backward"), i18n("Rewind"));
73 connect(m_rewAction, SIGNAL(triggered()), this, SLOT(slotRewind()));
75 m_playAction = toolbar->addAction(m_playIcon, i18n("Play"));
76 connect(m_playAction, SIGNAL(triggered()), this, SLOT(slotStartCapture()));
78 m_stopAction = toolbar->addAction(KIcon("media-playback-stop"), i18n("Stop"));
79 connect(m_stopAction, SIGNAL(triggered()), this, SLOT(slotStopCapture()));
80 m_stopAction->setEnabled(false);
81 m_fwdAction = toolbar->addAction(KIcon("media-seek-forward"), i18n("Forward"));
82 connect(m_fwdAction, SIGNAL(triggered()), this, SLOT(slotForward()));
84 m_recAction = toolbar->addAction(KIcon("media-record"), i18n("Record"));
85 connect(m_recAction, SIGNAL(triggered()), this, SLOT(slotRecord()));
86 m_recAction->setCheckable(true);
88 toolbar->addSeparator();
90 QAction *configAction = toolbar->addAction(KIcon("configure"), i18n("Configure"));
91 connect(configAction, SIGNAL(triggered()), this, SLOT(slotConfigure()));
92 configAction->setCheckable(false);
94 layout->addWidget(toolbar);
95 layout->addWidget(&m_logger);
96 layout->addWidget(&m_dvinfo);
97 m_logger.setMaxCount(10);
98 m_logger.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
99 m_logger.setFrame(false);
100 //m_logger.setInsertPolicy(QComboBox::InsertAtTop);
102 #if KDE_IS_VERSION(4,2,0)
103 m_freeSpace = new KCapacityBar(KCapacityBar::DrawTextInline, this);
104 m_freeSpace->setMaximumWidth(150);
105 QFontMetricsF fontMetrics(font());
106 m_freeSpace->setMaximumHeight(fontMetrics.height() * 1.2);
107 slotUpdateFreeSpace();
108 layout->addWidget(m_freeSpace);
109 connect(&m_spaceTimer, SIGNAL(timeout()), this, SLOT(slotUpdateFreeSpace()));
110 m_spaceTimer.setInterval(30000);
111 m_spaceTimer.setSingleShot(false);
114 control_frame_firewire->setLayout(layout);
116 slotVideoDeviceChanged(device_selector->currentIndex());
117 m_displayProcess = new QProcess;
118 m_captureProcess = new QProcess;
120 connect(m_captureProcess, SIGNAL(stateChanged(QProcess::ProcessState)), this, SLOT(slotProcessStatus(QProcess::ProcessState)));
121 connect(m_captureProcess, SIGNAL(readyReadStandardError()), this, SLOT(slotReadDvgrabInfo()));
123 QStringList env = QProcess::systemEnvironment();
124 env << "SDL_WINDOWID=" + QString::number(video_frame->winId());
126 QString videoDriver = KdenliveSettings::videodrivername();
127 if (!videoDriver.isEmpty()) {
128 if (videoDriver == "x11_noaccel") {
129 env << "SDL_VIDEO_YUV_HWACCEL=0";
130 env << "SDL_VIDEODRIVER=x11";
131 } else env << "SDL_VIDEODRIVER=" + videoDriver;
133 setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 1);
135 m_displayProcess->setEnvironment(env);
137 if (KdenliveSettings::video4capture().isEmpty()) {
138 QString captureCommand;
139 if (!KdenliveSettings::video4adevice().isEmpty()) captureCommand = "-f " + KdenliveSettings::video4aformat() + " -i " + KdenliveSettings::video4adevice() + " -acodec " + KdenliveSettings::video4acodec();
141 captureCommand += " -f " + KdenliveSettings::video4vformat() + " -s " + KdenliveSettings::video4size() + " -r " + QString::number(KdenliveSettings::video4rate()) + " -i " + KdenliveSettings::video4vdevice() + " -vcodec " + KdenliveSettings::video4vcodec();;
142 KdenliveSettings::setVideo4capture(captureCommand);
145 kDebug() << "/////// BUILDING MONITOR, ID: " << video_frame->winId();
148 RecMonitor::~RecMonitor()
150 #if KDE_IS_VERSION(4,2,0)
153 delete m_captureProcess;
154 delete m_displayProcess;
157 QString RecMonitor::name() const
162 void RecMonitor::slotConfigure()
164 emit showConfigDialog(4, device_selector->currentIndex());
167 void RecMonitor::slotUpdateCaptureFolder(const QString currentProjectFolder)
169 if (KdenliveSettings::capturetoprojectfolder()) m_capturePath = currentProjectFolder;
170 else m_capturePath = KdenliveSettings::capturefolder();
171 if (m_captureProcess) m_captureProcess->setWorkingDirectory(m_capturePath);
172 if (m_captureProcess->state() != QProcess::NotRunning) {
173 if (device_selector->currentIndex() == FIREWIRE)
174 KMessageBox::information(this, i18n("You need to disconnect and reconnect in the capture monitor to apply your changes"), i18n("Capturing"));
175 else KMessageBox::information(this, i18n("You need to stop capture before your changes can be applied"), i18n("Capturing"));
176 } else slotVideoDeviceChanged(device_selector->currentIndex());
178 #if KDE_IS_VERSION(4,2,0)
179 // update free space info
180 slotUpdateFreeSpace();
184 void RecMonitor::slotVideoDeviceChanged(int ix)
188 m_fwdAction->setVisible(ix != HDMI);
189 m_discAction->setVisible(ix != HDMI);
190 m_rewAction->setVisible(ix != HDMI);
191 m_logger.setVisible(ix == HDMI);
194 m_discAction->setEnabled(false);
195 m_rewAction->setEnabled(false);
196 m_fwdAction->setEnabled(false);
197 m_recAction->setEnabled(true);
198 m_stopAction->setEnabled(false);
199 m_playAction->setEnabled(false);
200 if (KdenliveSettings::rmd_path().isEmpty()) {
201 QString rmdpath = KStandardDirs::findExe("recordmydesktop");
202 if (rmdpath.isEmpty()) video_frame->setPixmap(mergeSideBySide(KIcon("dialog-warning").pixmap(QSize(50, 50)), i18n("Recordmydesktop utility not found,\n please install it for screen grabs")));
203 else KdenliveSettings::setRmd_path(rmdpath);
205 if (!KdenliveSettings::rmd_path().isEmpty()) video_frame->setPixmap(mergeSideBySide(KIcon("video-display").pixmap(QSize(50, 50)), i18n("Press record button\nto start screen capture\nFiles will be saved in:\n%1", m_capturePath)));
206 //video_frame->setText(i18n("Press record button\nto start screen capture"));
209 m_discAction->setEnabled(false);
210 m_rewAction->setEnabled(false);
211 m_fwdAction->setEnabled(false);
212 m_recAction->setEnabled(true);
213 m_stopAction->setEnabled(false);
214 m_playAction->setEnabled(true);
215 checkDeviceAvailability();
219 m_recAction->setEnabled(false);
220 m_stopAction->setEnabled(false);
221 m_playAction->setEnabled(true);
222 video_capture->setHidden(true);
223 video_frame->setHidden(false);
225 capturefile = m_capturePath;
226 if (!capturefile.endsWith("/")) capturefile.append("/");
227 capturename = KdenliveSettings::hdmifilename();
228 capturename.append("xxx.raw");
229 capturefile.append(capturename);
230 video_frame->setPixmap(mergeSideBySide(KIcon("camera-photo").pixmap(QSize(50, 50)), i18n("Plug your camcorder and\npress play button\nto start preview.\nFiles will be saved in:\n%1", capturefile)));
233 m_discAction->setEnabled(true);
234 m_recAction->setEnabled(false);
235 m_stopAction->setEnabled(false);
236 m_playAction->setEnabled(false);
237 m_rewAction->setEnabled(false);
238 m_fwdAction->setEnabled(false);
240 // Check that dvgab is available
241 if (KdenliveSettings::dvgrab_path().isEmpty()) {
242 QString dvgrabpath = KStandardDirs::findExe("dvgrab");
243 if (dvgrabpath.isEmpty()) video_frame->setPixmap(mergeSideBySide(KIcon("dialog-warning").pixmap(QSize(50, 50)), i18n("dvgrab utility not found,\n please install it for firewire capture")));
244 else KdenliveSettings::setDvgrab_path(dvgrabpath);
247 capturefile = m_capturePath;
248 if (!capturefile.endsWith("/")) capturefile.append("/");
249 capturename = KdenliveSettings::dvgrabfilename();
250 if (capturename.isEmpty()) capturename = "capture";
252 switch (KdenliveSettings::firewireformat()) {
264 capturename.append("xxx" + extension);
265 capturefile.append(capturename);
266 video_frame->setPixmap(mergeSideBySide(KIcon("network-connect").pixmap(QSize(50, 50)), i18n("Plug your camcorder and\npress connect button\nto initialize connection\nFiles will be saved in:\n%1", capturefile)));
272 void RecMonitor::createHDMIDevice()
274 //video_capture->setVisible(true);
275 if (m_bmCapture == NULL) {
276 QVBoxLayout *lay = new QVBoxLayout;
277 m_bmCapture = new CaptureHandler(lay);
278 connect(m_bmCapture, SIGNAL(gotTimeCode(ulong)), this, SLOT(slotGotHDMIFrameNumber(ulong)));
279 connect(m_bmCapture, SIGNAL(gotMessage(const QString &)), this, SLOT(slotGotHDMIMessage(const QString &)));
280 video_capture->setLayout(lay);
284 void RecMonitor::slotGotHDMIFrameNumber(ulong ix)
286 m_dvinfo.setText(QString::number(ix));
289 void RecMonitor::slotGotHDMIMessage(const QString &message)
291 m_logger.insertItem(0, message);
294 QPixmap RecMonitor::mergeSideBySide(const QPixmap& pix, const QString txt)
297 QRect r = QApplication::fontMetrics().boundingRect(QRect(0, 0, video_frame->width(), video_frame->height()), Qt::AlignLeft, txt);
298 int strWidth = r.width();
299 int strHeight = r.height();
300 int pixWidth = pix.width();
301 int pixHeight = pix.height();
302 QPixmap res(strWidth + 8 + pixWidth, qMax(strHeight, pixHeight));
303 res.fill(Qt::transparent);
305 p.drawPixmap(0, 0, pix);
306 p.setPen(kapp->palette().text().color());
307 p.drawText(QRect(pixWidth + 8, 0, strWidth, strHeight), 0, txt);
313 void RecMonitor::checkDeviceAvailability()
315 if (!KIO::NetAccess::exists(KUrl(KdenliveSettings::video4vdevice()), KIO::NetAccess::SourceSide , this)) {
316 m_playAction->setEnabled(false);
317 m_recAction->setEnabled(false);
318 video_frame->setPixmap(mergeSideBySide(KIcon("camera-web").pixmap(QSize(50, 50)), i18n("Cannot read from device %1\nPlease check drivers and access rights.", KdenliveSettings::video4vdevice())));
319 //video_frame->setText(i18n("Cannot read from device %1\nPlease check drivers and access rights.", KdenliveSettings::video4vdevice()));
320 } else //video_frame->setText(i18n("Press play or record button\nto start video capture"));
321 video_frame->setPixmap(mergeSideBySide(KIcon("camera-web").pixmap(QSize(50, 50)), i18n("Press play or record button\nto start video capture\nFiles will be saved in:\n%1", m_capturePath)));
324 void RecMonitor::slotDisconnect()
326 if (m_captureProcess->state() == QProcess::NotRunning) {
327 m_captureTime = KDateTime::currentLocalDateTime();
328 kDebug() << "CURRENT TIME: " << m_captureTime.toString();
329 m_didCapture = false;
330 slotStartCapture(false);
331 m_discAction->setIcon(KIcon("network-disconnect"));
332 m_discAction->setText(i18n("Disconnect"));
333 m_recAction->setEnabled(true);
334 m_stopAction->setEnabled(true);
335 m_playAction->setEnabled(true);
336 m_rewAction->setEnabled(true);
337 m_fwdAction->setEnabled(true);
339 m_captureProcess->write("q", 1);
340 QTimer::singleShot(1000, m_captureProcess, SLOT(kill()));
341 if (m_didCapture) manageCapturedFiles();
342 m_didCapture = false;
346 void RecMonitor::slotRewind()
348 m_captureProcess->write("a", 1);
351 void RecMonitor::slotForward()
353 m_captureProcess->write("z", 1);
356 void RecMonitor::slotStopCapture()
359 switch (device_selector->currentIndex()) {
361 m_captureProcess->write("\e", 2);
362 m_playAction->setIcon(m_playIcon);
367 m_captureProcess->write("q\n", 3);
368 QTimer::singleShot(1000, m_captureProcess, SLOT(kill()));
371 video_capture->setHidden(true);
372 video_frame->setHidden(false);
373 m_bmCapture->stopPreview();
374 m_playAction->setEnabled(true);
375 m_stopAction->setEnabled(false);
376 m_recAction->setEnabled(false);
383 void RecMonitor::slotStartCapture(bool play)
385 if (m_captureProcess->state() != QProcess::NotRunning) {
386 if (device_selector->currentIndex() == FIREWIRE) {
388 m_captureProcess->write("k", 1);
389 //captureProcess->write("\e", 2);
390 m_playAction->setIcon(m_playIcon);
393 m_captureProcess->write("p", 1);
394 m_playAction->setIcon(m_pauseIcon);
400 m_captureArgs.clear();
401 m_displayArgs.clear();
403 QString capturename = KdenliveSettings::dvgrabfilename();
404 QStringList dvargs = KdenliveSettings::dvgrabextra().simplified().split(" ", QString::SkipEmptyParts);
406 switch (device_selector->currentIndex()) {
408 switch (KdenliveSettings::firewireformat()) {
411 m_captureArgs << "--format" << "raw";
412 m_displayArgs << "-f" << "dv";
416 m_captureArgs << "--format" << "dv1";
417 m_displayArgs << "-f" << "dv";
421 m_captureArgs << "--format" << "dv2";
422 m_displayArgs << "-f" << "dv";
426 m_captureArgs << "--format" << "hdv";
427 m_displayArgs << "-f" << KdenliveSettings::video4container();
430 if (KdenliveSettings::firewireautosplit()) m_captureArgs << "--autosplit";
431 if (KdenliveSettings::firewiretimestamp()) m_captureArgs << "--timestamp";
432 if (!dvargs.isEmpty()) {
433 m_captureArgs << dvargs;
435 m_captureArgs << "-i";
436 if (capturename.isEmpty()) capturename = "capture";
437 m_captureArgs << capturename << "-";
439 m_displayArgs << "-x" << QString::number(video_frame->width()) << "-y" << QString::number(video_frame->height()) << "-";
441 m_captureProcess->setStandardOutputProcess(m_displayProcess);
442 m_captureProcess->setWorkingDirectory(m_capturePath);
443 kDebug() << "Capture: Running dvgrab " << m_captureArgs.join(" ");
445 m_captureProcess->start(KdenliveSettings::dvgrab_path(), m_captureArgs);
446 if (play) m_captureProcess->write(" ", 1);
447 m_discAction->setEnabled(true);
450 m_captureArgs << KdenliveSettings::video4capture().simplified().split(' ') << KdenliveSettings::video4encoding().simplified().split(' ') << "-f" << KdenliveSettings::video4container() << "-";
451 m_displayArgs << "-f" << KdenliveSettings::video4container() << "-x" << QString::number(video_frame->width()) << "-y" << QString::number(video_frame->height()) << "-";
452 m_captureProcess->setStandardOutputProcess(m_displayProcess);
453 kDebug() << "Capture: Running ffmpeg " << m_captureArgs.join(" ");
454 m_captureProcess->start("ffmpeg", m_captureArgs);
457 video_capture->setVisible(true);
458 video_frame->setHidden(true);
459 m_bmCapture->startPreview(KdenliveSettings::hdmicapturedevice(), KdenliveSettings::hdmicapturemode());
460 m_playAction->setEnabled(false);
461 m_stopAction->setEnabled(true);
462 m_recAction->setEnabled(true);
468 if (device_selector->currentIndex() == FIREWIRE || device_selector->currentIndex() == VIDEO4LINUX) {
469 kDebug() << "Capture: Running ffplay " << m_displayArgs.join(" ");
470 m_displayProcess->start("ffplay", m_displayArgs);
471 video_frame->setText(i18n("Initialising..."));
473 // do something when starting screen grab
477 void RecMonitor::slotRecord()
479 if (device_selector->currentIndex() == HDMI) {
480 if (m_hdmiCapturing) {
481 // We are capturing, stop it
482 m_bmCapture->stopCapture();
483 m_hdmiCapturing = false;
486 // Start capture, get capture filename first
487 QString path = m_capturePath;
488 if (!path.endsWith("/")) path.append("/");
489 path.append(KdenliveSettings::hdmifilename());
490 m_bmCapture->startCapture(path);
491 m_hdmiCapturing = true;
496 if (m_captureProcess->state() == QProcess::NotRunning && device_selector->currentIndex() == FIREWIRE) {
500 switch (device_selector->currentIndex()) {
502 m_captureProcess->write("\e", 2);
503 m_playAction->setIcon(m_playIcon);
504 m_isCapturing = false;
506 m_recAction->setChecked(false);
509 m_captureProcess->terminate();
511 //m_isCapturing = false;
512 QTimer::singleShot(1000, this, SLOT(slotStartCapture()));
515 //captureProcess->write("q\n", 3);
516 m_captureProcess->terminate();
517 video_frame->setText(i18n("Encoding captured video..."));
518 // in case ffmpeg doesn't exit with the 'q' command, kill it one second later
519 //QTimer::singleShot(1000, captureProcess, SLOT(kill()));
523 } else if (device_selector->currentIndex() == FIREWIRE) {
524 m_isCapturing = true;
526 m_captureProcess->write("c\n", 3);
527 #if KDE_IS_VERSION(4,2,0)
528 m_spaceTimer.start();
532 if (m_captureProcess->state() == QProcess::NotRunning) {
533 m_recAction->setChecked(true);
534 QString extension = "mp4";
535 if (device_selector->currentIndex() == SCREENGRAB) extension = "ogv"; //KdenliveSettings::screengrabextension();
536 else if (device_selector->currentIndex() == VIDEO4LINUX) extension = KdenliveSettings::video4extension();
537 QString path = m_capturePath + "/capture0000." + extension;
539 while (QFile::exists(path)) {
540 QString num = QString::number(i).rightJustified(4, '0', false);
541 path = m_capturePath + "/capture" + num + '.' + extension;
544 m_captureFile = KUrl(path);
546 m_captureArgs.clear();
547 m_displayArgs.clear();
549 QString capturename = KdenliveSettings::dvgrabfilename();
550 if (capturename.isEmpty()) capturename = "capture";
552 switch (device_selector->currentIndex()) {
554 m_captureArgs << KdenliveSettings::video4capture().simplified().split(' ') << KdenliveSettings::video4encoding().simplified().split(' ') << "-y" << m_captureFile.path() << "-f" << KdenliveSettings::video4container() << "-acodec" << KdenliveSettings::video4acodec() << "-vcodec" << KdenliveSettings::video4vcodec() << "-";
555 m_displayArgs << "-f" << KdenliveSettings::video4container() << "-x" << QString::number(video_frame->width()) << "-y" << QString::number(video_frame->height()) << "-";
556 m_captureProcess->setStandardOutputProcess(m_displayProcess);
557 kDebug() << "Capture: Running ffmpeg " << m_captureArgs.join(" ");
558 m_captureProcess->start("ffmpeg", m_captureArgs);
561 switch (KdenliveSettings::rmd_capture_type()) {
563 // Full screen capture, nothing special to do
567 m_captureArgs << "--width" << QString::number(KdenliveSettings::rmd_width()) << "--height" << QString::number(KdenliveSettings::rmd_height());
568 if (!KdenliveSettings::rmd_follow_mouse()) {
569 m_captureArgs << "-x" << QString::number(KdenliveSettings::rmd_offsetx()) << "-y" << QString::number(KdenliveSettings::rmd_offsety());
571 m_captureArgs << "--follow-mouse";
572 if (KdenliveSettings::rmd_hide_frame()) m_captureArgs << "--no-frame";
576 if (KdenliveSettings::rmd_hide_mouse()) m_captureArgs << "--no-cursor";
577 m_isCapturing = true;
578 if (KdenliveSettings::rmd_capture_audio()) {
579 m_captureArgs << "--freq" << KdenliveSettings::rmd_freq();
580 m_captureArgs << "--channels" << QString::number(KdenliveSettings::rmd_audio_channels());
581 if (KdenliveSettings::rmd_use_jack()) {
582 m_captureArgs << "--use-jack";
583 QStringList ports = KdenliveSettings::rmd_jackports().split(" ", QString::SkipEmptyParts);
584 for (int i = 0; i < ports.count(); ++i) {
585 m_captureArgs << ports.at(i);
587 if (KdenliveSettings::rmd_jack_buffer() > 0.0)
588 m_captureArgs << "--ring-buffer-size" << QString::number(KdenliveSettings::rmd_jack_buffer());
590 if (!KdenliveSettings::rmd_alsadevicename().isEmpty())
591 m_captureArgs << "--device" << KdenliveSettings::rmd_alsadevicename();
592 if (KdenliveSettings::rmd_alsa_buffer() > 0)
593 m_captureArgs << "--buffer-size" << QString::number(KdenliveSettings::rmd_alsa_buffer());
595 } else m_captureArgs << "--no-sound";
597 if (KdenliveSettings::rmd_fullshots()) m_captureArgs << "--full-shots";
598 m_captureArgs << "--v_bitrate" << QString::number(KdenliveSettings::rmd_bitrate());
599 m_captureArgs << "--v_quality" << QString::number(KdenliveSettings::rmd_quality());
600 m_captureArgs << "--workdir" << KdenliveSettings::currenttmpfolder();
601 m_captureArgs << "--fps" << QString::number(KdenliveSettings::rmd_fps()) << "-o" << m_captureFile.path();
602 m_captureProcess->start(KdenliveSettings::rmd_path(), m_captureArgs);
603 kDebug() << "// RecordMyDesktop params: " << m_captureArgs;
610 if (device_selector->currentIndex() != SCREENGRAB) {
611 m_isCapturing = true;
612 kDebug() << "Capture: Running ffplay " << m_displayArgs.join(" ");
613 m_displayProcess->start("ffplay", m_displayArgs);
614 video_frame->setText(i18n("Initialising..."));
618 m_displayProcess->kill();
619 //captureProcess->kill();
620 QTimer::singleShot(1000, this, SLOT(slotRecord()));
625 void RecMonitor::slotStartGrab(const QRect &rect) {
626 rgnGrab->deleteLater();
627 QApplication::restoreOverrideCursor();
629 if (rect.isNull()) return;
630 int width = rect.width();
631 int height = rect.height();
632 if (width % 2 != 0) width--;
633 if (height % 2 != 0) height--;
634 QString args = KdenliveSettings::screengrabcapture().replace("%size", QString::number(width) + "x" + QString::number(height)).replace("%offset", "+" + QString::number(rect.x()) + "," + QString::number(rect.y()));
635 if (KdenliveSettings::screengrabenableaudio()) {
636 // also capture audio
637 if (KdenliveSettings::useosscapture()) m_captureArgs << KdenliveSettings::screengrabosscapture().simplified().split(' ');
638 else m_captureArgs << KdenliveSettings::screengrabalsacapture2().simplified().split(' ');
640 m_captureArgs << args.simplified().split(' ') << KdenliveSettings::screengrabencoding().simplified().split(' ') << m_captureFile.path();
641 m_isCapturing = true;
642 video_frame->setText(i18n("Capturing..."));
643 if (KdenliveSettings::screengrabenableaudio() && !KdenliveSettings::useosscapture()) {
644 QStringList alsaArgs = KdenliveSettings::screengrabalsacapture().simplified().split(' ');
645 alsaProcess->setStandardOutputProcess(captureProcess);
646 kDebug() << "Capture: Running arecord " << alsaArgs.join(" ");
647 alsaProcess->start("arecord", alsaArgs);
649 kDebug() << "Capture: Running ffmpeg " << m_captureArgs.join(" ");
650 captureProcess->start("ffmpeg", m_captureArgs);
653 void RecMonitor::slotProcessStatus(QProcess::ProcessState status)
655 if (status == QProcess::NotRunning) {
656 m_displayProcess->kill();
657 if (m_isCapturing && device_selector->currentIndex() != FIREWIRE)
658 if (autoaddbox->isChecked() && QFile::exists(m_captureFile.path())) emit addProjectClip(m_captureFile);
659 if (device_selector->currentIndex() == FIREWIRE) {
660 m_discAction->setIcon(KIcon("network-connect"));
661 m_discAction->setText(i18n("Connect"));
662 m_playAction->setEnabled(false);
663 m_rewAction->setEnabled(false);
664 m_fwdAction->setEnabled(false);
665 m_recAction->setEnabled(false);
668 m_playAction->setIcon(m_playIcon);
669 m_recAction->setChecked(false);
670 m_stopAction->setEnabled(false);
671 device_selector->setEnabled(true);
672 if (m_captureProcess && m_captureProcess->exitStatus() == QProcess::CrashExit) {
673 video_frame->setText(i18n("Capture crashed, please check your parameters"));
675 if (device_selector->currentIndex() != SCREENGRAB) {
676 video_frame->setText(i18n("Not connected"));
678 if (m_captureProcess->exitCode() != 0) {
679 video_frame->setText(i18n("Capture crashed, please check your parameters\nRecordMyDesktop exit code: %1", QString::number(m_captureProcess->exitCode())));
681 video_frame->setPixmap(mergeSideBySide(KIcon("video-display").pixmap(QSize(50, 50)), i18n("Press record button\nto start screen capture\nFiles will be saved in:\n%1", m_capturePath)));
685 m_isCapturing = false;
687 #if KDE_IS_VERSION(4,2,0)
689 // update free space info
690 slotUpdateFreeSpace();
694 if (device_selector->currentIndex() != SCREENGRAB) m_stopAction->setEnabled(true);
695 device_selector->setEnabled(false);
699 void RecMonitor::manageCapturedFiles()
702 switch (KdenliveSettings::firewireformat()) {
714 QDir dir(m_capturePath);
716 QString capturename = KdenliveSettings::dvgrabfilename();
717 if (capturename.isEmpty()) capturename = "capture";
718 filters << capturename + "*" + extension;
719 const QStringList result = dir.entryList(filters, QDir::Files, QDir::Time);
720 KUrl::List capturedFiles;
721 foreach(const QString & name, result) {
722 KUrl url = KUrl(dir.filePath(name));
723 if (KIO::NetAccess::exists(url, KIO::NetAccess::SourceSide, this)) {
724 KFileItem file(KFileItem::Unknown, KFileItem::Unknown, url, true);
725 if (file.time(KFileItem::ModificationTime) > m_captureTime) capturedFiles.append(url);
728 kDebug() << "Found : " << capturedFiles.count() << " new capture files";
729 kDebug() << capturedFiles;
731 if (capturedFiles.count() > 0) {
732 ManageCapturesDialog *d = new ManageCapturesDialog(capturedFiles, this);
733 if (d->exec() == QDialog::Accepted) {
734 capturedFiles = d->importFiles();
735 foreach(const KUrl & url, capturedFiles) {
736 emit addProjectClip(url);
744 void RecMonitor::mousePressEvent(QMouseEvent * /*event*/)
746 #if KDE_IS_VERSION(4,2,0)
747 if (m_freeSpace->underMouse()) slotUpdateFreeSpace();
751 void RecMonitor::slotUpdateFreeSpace()
753 #if KDE_IS_VERSION(4,2,0)
754 KDiskFreeSpaceInfo info = KDiskFreeSpaceInfo::freeSpaceInfo(m_capturePath);
755 if (info.isValid()) {
756 m_freeSpace->setValue(100 * info.used() / info.size());
757 m_freeSpace->setText(i18n("Free space: %1", KIO::convertSize(info.available())));
758 m_freeSpace->update();
763 void RecMonitor::activateRecMonitor()
765 //if (!m_isActive) m_monitorManager->activateRecMonitor(m_name);
768 void RecMonitor::stop()
774 void RecMonitor::start()
780 void RecMonitor::refreshRecMonitor(bool visible)
783 //if (!m_isActive) m_monitorManager->activateRecMonitor(m_name);
788 void RecMonitor::slotPlay()
791 //if (!m_isActive) m_monitorManager->activateRecMonitor(m_name);
795 void RecMonitor::slotReadDvgrabInfo()
797 QString data = m_captureProcess->readAllStandardError().simplified();
798 data = data.section('"', 2, 2).simplified();
799 m_dvinfo.setText(data.left(11));
800 m_dvinfo.updateGeometry();
803 #include "recmonitor.moc"