]> git.sesse.net Git - kdenlive/blob - src/recmonitor.cpp
Fix track issues:
[kdenlive] / src / recmonitor.cpp
1 /***************************************************************************
2  *   Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
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.                                   *
8  *                                                                         *
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.                          *
13  *                                                                         *
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  ***************************************************************************/
19
20
21 #include <QMouseEvent>
22 #include <QStylePainter>
23 #include <QMenu>
24 #include <QToolButton>
25 #include <QFile>
26 #include <QDir>
27 #include <QDesktopWidget>
28
29 #include <KDebug>
30 #include <KLocale>
31 #include <KStandardDirs>
32 #include <KComboBox>
33 #include <KIO/NetAccess>
34 #include <KFileItem>
35
36 #include "gentime.h"
37 #include "kdenlivesettings.h"
38 #include "managecapturesdialog.h"
39 #include "recmonitor.h"
40
41 RecMonitor::RecMonitor(QString name, QWidget *parent)
42         : QWidget(parent), m_name(name), m_isActive(false), m_isCapturing(false), m_isPlaying(false), m_didCapture(false) {
43     ui.setupUi(this);
44
45     ui.video_frame->setAttribute(Qt::WA_PaintOnScreen);
46     ui.device_selector->setCurrentIndex(KdenliveSettings::defaultcapture());
47     connect(ui.device_selector, SIGNAL(currentIndexChanged(int)), this, SLOT(slotVideoDeviceChanged(int)));
48
49
50
51     QToolBar *toolbar = new QToolBar(name, this);
52     QHBoxLayout *layout = new QHBoxLayout;
53     layout->setContentsMargins(0, 0, 0, 0);
54     m_playIcon = KIcon("media-playback-start");
55     m_pauseIcon = KIcon("media-playback-pause");
56
57     m_discAction = toolbar->addAction(KIcon("network-connect"), i18n("Connect"));
58     connect(m_discAction, SIGNAL(triggered()), this, SLOT(slotDisconnect()));
59
60     m_rewAction = toolbar->addAction(KIcon("media-seek-backward"), i18n("Rewind"));
61     connect(m_rewAction, SIGNAL(triggered()), this, SLOT(slotRewind()));
62
63     m_playAction = toolbar->addAction(m_playIcon, i18n("Play"));
64     connect(m_playAction, SIGNAL(triggered()), this, SLOT(slotStartCapture()));
65
66     m_stopAction = toolbar->addAction(KIcon("media-playback-stop"), i18n("Stop"));
67     connect(m_stopAction, SIGNAL(triggered()), this, SLOT(slotStopCapture()));
68     m_stopAction->setEnabled(false);
69     m_fwdAction = toolbar->addAction(KIcon("media-seek-forward"), i18n("Forward"));
70     connect(m_fwdAction, SIGNAL(triggered()), this, SLOT(slotForward()));
71
72     m_recAction = toolbar->addAction(KIcon("media-record"), i18n("Record"));
73     connect(m_recAction, SIGNAL(triggered()), this, SLOT(slotRecord()));
74     m_recAction->setCheckable(true);
75
76     toolbar->addSeparator();
77
78     QAction *configAction = toolbar->addAction(KIcon("configure"), i18n("Configure"));
79     connect(configAction, SIGNAL(triggered()), this, SLOT(slotConfigure()));
80     configAction->setCheckable(false);
81
82     layout->addWidget(toolbar);
83     ui.control_frame_firewire->setLayout(layout);
84
85     slotVideoDeviceChanged(ui.device_selector->currentIndex());
86     displayProcess = new QProcess;
87     captureProcess = new QProcess;
88
89     connect(captureProcess, SIGNAL(stateChanged(QProcess::ProcessState)), this, SLOT(slotProcessStatus(QProcess::ProcessState)));
90
91     QStringList env = QProcess::systemEnvironment();
92     env << "SDL_WINDOWID=" + QString::number(ui.video_frame->winId());
93
94     QString videoDriver = KdenliveSettings::videodrivername();
95     if (!videoDriver.isEmpty()) {
96         if (videoDriver == "x11_noaccel") {
97             env << "SDL_VIDEO_YUV_HWACCEL=0";
98             env << "SDL_VIDEODRIVER=x11";
99         } else env << "SDL_VIDEODRIVER=" + videoDriver;
100     }
101     setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 1);
102
103     displayProcess->setEnvironment(env);
104
105     if (KdenliveSettings::video4capture().isEmpty()) {
106         QString captureCommand;
107         if (!KdenliveSettings::video4adevice().isEmpty()) captureCommand = "-f " + KdenliveSettings::video4aformat() + " -i " + KdenliveSettings::video4adevice();
108
109         captureCommand +=  " -f " + KdenliveSettings::video4vformat() + " -s " + KdenliveSettings::video4size() + " -r " + QString::number(KdenliveSettings::video4rate()) + " -i " + KdenliveSettings::video4vdevice();
110         KdenliveSettings::setVideo4capture(captureCommand);
111     }
112
113     kDebug() << "/////// BUILDING MONITOR, ID: " << ui.video_frame->winId();
114 }
115
116 RecMonitor::~RecMonitor() {
117     delete captureProcess;
118     delete displayProcess;
119 }
120
121 QString RecMonitor::name() const {
122     return m_name;
123 }
124
125 void RecMonitor::slotConfigure() {
126     emit showConfigDialog(4, ui.device_selector->currentIndex());
127 }
128
129 void RecMonitor::slotVideoDeviceChanged(int ix) {
130     switch (ix) {
131     case SCREENGRAB:
132         m_discAction->setEnabled(false);
133         m_rewAction->setEnabled(false);
134         m_fwdAction->setEnabled(false);
135         m_recAction->setEnabled(true);
136         m_stopAction->setEnabled(false);
137         m_playAction->setEnabled(false);
138         if (KdenliveSettings::rmd_path().isEmpty()) {
139             QString rmdpath = KStandardDirs::findExe("recordmydesktop");
140             if (rmdpath.isEmpty()) ui.video_frame->setPixmap(mergeSideBySide(KIcon("dialog-warning").pixmap(QSize(50, 50)), i18n("Recordmydesktop utility not found,\n please install it for screen grabs")));
141             else KdenliveSettings::setRmd_path(rmdpath);
142         }
143         if (!KdenliveSettings::rmd_path().isEmpty()) ui.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", KdenliveSettings::capturefolder())));
144         //ui.video_frame->setText(i18n("Press record button\nto start screen capture"));
145         break;
146     case VIDEO4LINUX:
147         m_discAction->setEnabled(false);
148         m_rewAction->setEnabled(false);
149         m_fwdAction->setEnabled(false);
150         m_recAction->setEnabled(true);
151         m_stopAction->setEnabled(false);
152         m_playAction->setEnabled(true);
153         checkDeviceAvailability();
154         break;
155     default: // FIREWIRE
156         m_discAction->setEnabled(true);
157         m_recAction->setEnabled(false);
158         m_stopAction->setEnabled(false);
159         m_playAction->setEnabled(false);
160         m_rewAction->setEnabled(false);
161         m_fwdAction->setEnabled(false);
162         //ui.video_frame->setText(i18n("Plug your camcorder and\npress connect button\nto initialize connection"));
163         if (KdenliveSettings::dvgrab_path().isEmpty()) {
164             QString dvgrabpath = KStandardDirs::findExe("dvgrab");
165             if (dvgrabpath.isEmpty()) ui.video_frame->setPixmap(mergeSideBySide(KIcon("dialog-warning").pixmap(QSize(50, 50)), i18n("dvgrab utility not found,\n please install it for firewire capture")));
166             else KdenliveSettings::setDvgrab_path(dvgrabpath);
167         }
168
169         if (!KdenliveSettings::dvgrab_path().isEmpty()) ui.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", KdenliveSettings::capturefolder())));
170         break;
171     }
172 }
173
174 QPixmap RecMonitor::mergeSideBySide(const QPixmap& pix, const QString txt) {
175     QPainter p;
176     QRect r = p.fontMetrics().boundingRect(QRect(0, 0, ui.video_frame->width(), ui.video_frame->height()), Qt::AlignLeft, txt);
177     int strWidth = r.width();
178     int strHeight = r.height();
179     int pixWidth = pix.width();
180     int pixHeight = pix.height();
181     QPixmap res(strWidth + 8 + pixWidth, qMax(strHeight, pixHeight));
182     res.fill(Qt::transparent);
183     p.begin(&res);
184     p.drawPixmap(0, 0, pix);
185     p.drawText(QRect(pixWidth + 8, 0, strWidth, strHeight), 0, txt);
186     p.end();
187     return res;
188 }
189
190
191 void RecMonitor::checkDeviceAvailability() {
192     if (!KIO::NetAccess::exists(KUrl(KdenliveSettings::video4vdevice()), KIO::NetAccess::SourceSide , this)) {
193         m_playAction->setEnabled(false);
194         m_recAction->setEnabled(false);
195         ui.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())));
196         //ui.video_frame->setText(i18n("Cannot read from device %1\nPlease check drivers and access rights.", KdenliveSettings::video4vdevice()));
197     } else //ui.video_frame->setText(i18n("Press play or record button\nto start video capture"));
198         ui.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", KdenliveSettings::capturefolder())));
199 }
200
201 void RecMonitor::slotDisconnect() {
202     if (captureProcess->state() == QProcess::NotRunning) {
203         m_captureTime = KDateTime::currentLocalDateTime();
204         kDebug() << "CURRENT TIME: " << m_captureTime.toString();
205         m_didCapture = false;
206         slotStartCapture(false);
207         m_discAction->setIcon(KIcon("network-disconnect"));
208         m_discAction->setText(i18n("Disonnect"));
209         m_recAction->setEnabled(true);
210         m_stopAction->setEnabled(true);
211         m_playAction->setEnabled(true);
212         m_rewAction->setEnabled(true);
213         m_fwdAction->setEnabled(true);
214     } else {
215         captureProcess->write("q", 1);
216         QTimer::singleShot(1000, captureProcess, SLOT(kill()));
217         if (m_didCapture) manageCapturedFiles();
218         m_didCapture = false;
219     }
220 }
221
222 void RecMonitor::slotRewind() {
223     captureProcess->write("a", 1);
224 }
225
226 void RecMonitor::slotForward() {
227     captureProcess->write("z", 1);
228 }
229
230 void RecMonitor::slotStopCapture() {
231     // stop capture
232     switch (ui.device_selector->currentIndex()) {
233     case FIREWIRE:
234         captureProcess->write("\e", 2);
235         m_playAction->setIcon(m_playIcon);
236         m_isPlaying = false;
237         break;
238     case VIDEO4LINUX:
239         captureProcess->write("q\n", 3);
240         QTimer::singleShot(1000, captureProcess, SLOT(kill()));
241
242         break;
243     case SCREENGRAB:
244         captureProcess->write("q\n", 3);
245         QTimer::singleShot(1000, captureProcess, SLOT(kill()));
246         break;
247     default:
248         break;
249     }
250 }
251
252 void RecMonitor::slotStartCapture(bool play) {
253
254     /*
255     *captureProcess<<"dvgrab";
256
257     bool isHdv = false;
258
259     switch (m_recPanel->capture_format->currentItem()){
260         case 0:
261       *captureProcess<<"--format"<<"dv1";
262      break;
263         case 1:
264       *captureProcess<<"--format"<<"dv2";
265      break;
266         case 3:
267       *captureProcess<<"--format"<<"hdv";
268      isHdv = true;
269      break;
270         default:
271             *captureProcess<<"--format"<<"raw";
272      break;
273     }
274
275     if (KdenliveSettings::autosplit()) *captureProcess<<"--autosplit";
276     if (KdenliveSettings::timestamp()) *captureProcess<<"--timestamp";
277     *captureProcess<<"-i"<<"capture"<<"-";*/
278
279     /*
280         QStringList captureArgs;
281         captureArgs<<"--format"<<"hdv"<<"-i"<<"capture"<<"-";
282         QStringList displayArgs;
283
284         displayArgs<<"-f"<<"mpegts"<<"-x"<<QString::number(ui.video_frame->width())<<"-y"<<QString::number(ui.video_frame->height())<<"-";
285
286         captureProcess->setStandardOutputProcess(displayProcess);
287         ui.video_frame->setScaledContents(false);
288         captureProcess->start("dvgrab",captureArgs);
289         displayProcess->start("ffplay",  displayArgs);*/
290
291
292     if (captureProcess->state() != QProcess::NotRunning) {
293         if (ui.device_selector->currentIndex() == FIREWIRE) {
294             if (m_isPlaying) {
295                 captureProcess->write("k", 1);
296                 //captureProcess->write("\e", 2);
297                 m_playAction->setIcon(m_playIcon);
298                 m_isPlaying = false;
299             } else {
300                 captureProcess->write("p", 1);
301                 m_playAction->setIcon(m_pauseIcon);
302                 m_isPlaying = true;
303             }
304         }
305         return;
306     }
307     m_captureArgs.clear();
308     m_displayArgs.clear();
309     m_isPlaying = false;
310
311     switch (ui.device_selector->currentIndex()) {
312     case FIREWIRE:
313         switch (KdenliveSettings::firewireformat()) {
314         case 0:
315             // RAW DV CAPTURE
316             m_captureArgs << "--format" << "raw";
317             m_displayArgs << "-f" << "dv";
318             break;
319         case 1:
320             // DV type 1
321             m_captureArgs << "--format" << "dv1";
322             m_displayArgs << "-f" << "dv";
323             break;
324         case 2:
325             // DV type 2
326             m_captureArgs << "--format" << "dv2";
327             m_displayArgs << "-f" << "dv";
328             break;
329         case 3:
330             // HDV CAPTURE
331             m_captureArgs << "--format" << "hdv";
332             m_displayArgs << "-f" << "mpegts";
333             break;
334         }
335         if (KdenliveSettings::firewireautosplit()) m_captureArgs << "--autosplit";
336         if (KdenliveSettings::firewiretimestamp()) m_captureArgs << "--timestamp";
337         m_captureArgs << "-i" << "capture" << "-";
338         m_displayArgs << "-x" << QString::number(ui.video_frame->width()) << "-y" << QString::number(ui.video_frame->height()) << "-";
339
340         captureProcess->setStandardOutputProcess(displayProcess);
341         captureProcess->setWorkingDirectory(KdenliveSettings::capturefolder());
342         kDebug() << "Capture: Running dvgrab " << m_captureArgs.join(" ");
343         captureProcess->start(KdenliveSettings::dvgrab_path(), m_captureArgs);
344         if (play) captureProcess->write(" ", 1);
345         m_discAction->setEnabled(true);
346         break;
347     case VIDEO4LINUX:
348         m_captureArgs << KdenliveSettings::video4capture().simplified().split(' ') << KdenliveSettings::video4encoding().simplified().split(' ') << "-f" << "mpegts" << "-vcodec" << "mpeg4" << "-acodec" << "mp2" << "-";
349         m_displayArgs << "-f" << "mpegts" << "-x" << QString::number(ui.video_frame->width()) << "-y" << QString::number(ui.video_frame->height()) << "-";
350         captureProcess->setStandardOutputProcess(displayProcess);
351         kDebug() << "Capture: Running ffmpeg " << m_captureArgs.join(" ");
352         captureProcess->start("ffmpeg", m_captureArgs);
353         break;
354     default:
355         break;
356     }
357
358     if (ui.device_selector->currentIndex() != SCREENGRAB) {
359         kDebug() << "Capture: Running ffplay " << m_displayArgs.join(" ");
360         displayProcess->start("ffplay", m_displayArgs);
361         ui.video_frame->setText(i18n("Initialising..."));
362     } else {
363         // do something when starting screen grab
364     }
365 }
366
367 void RecMonitor::slotRecord() {
368     if (captureProcess->state() == QProcess::NotRunning && ui.device_selector->currentIndex() == FIREWIRE) {
369         slotStartCapture();
370     }
371     if (m_isCapturing) {
372         switch (ui.device_selector->currentIndex()) {
373         case FIREWIRE:
374             captureProcess->write("\e", 2);
375             m_playAction->setIcon(m_playIcon);
376             m_isCapturing = false;
377             m_isPlaying = false;
378             m_recAction->setChecked(false);
379             break;
380         case VIDEO4LINUX:
381             captureProcess->terminate();
382             slotStopCapture();
383             //m_isCapturing = false;
384             QTimer::singleShot(1000, this, SLOT(slotStartCapture()));
385             break;
386         case SCREENGRAB:
387             //captureProcess->write("q\n", 3);
388             captureProcess->terminate();
389             ui.video_frame->setText(i18n("Encoding captured video..."));
390             // in case ffmpeg doesn't exit with the 'q' command, kill it one second later
391             //QTimer::singleShot(1000, captureProcess, SLOT(kill()));
392             break;
393         }
394         return;
395     } else if (ui.device_selector->currentIndex() == FIREWIRE) {
396         m_isCapturing = true;
397         m_didCapture = true;
398         captureProcess->write("c\n", 3);
399         return;
400     }
401     if (captureProcess->state() == QProcess::NotRunning) {
402         m_recAction->setChecked(true);
403         QString extension = "mp4";
404         if (ui.device_selector->currentIndex() == SCREENGRAB) extension = "ogv"; //KdenliveSettings::screengrabextension();
405         QString path = KdenliveSettings::capturefolder() + "/capture0000." + extension;
406         int i = 1;
407         while (QFile::exists(path)) {
408             QString num = QString::number(i).rightJustified(4, '0', false);
409             path = KdenliveSettings::capturefolder() + "/capture" + num + "." + extension;
410             i++;
411         }
412
413         m_captureFile = KUrl(path);
414
415         m_captureArgs.clear();
416         m_displayArgs.clear();
417         QString args;
418
419         switch (ui.device_selector->currentIndex()) {
420         case FIREWIRE:
421             m_captureArgs << "--format" << "hdv" << "-i" << "capture" << "-";
422             m_displayArgs << "-f" << "mpegts" << "-x" << QString::number(ui.video_frame->width()) << "-y" << QString::number(ui.video_frame->height()) << "-";
423             captureProcess->setStandardOutputProcess(displayProcess);
424             kDebug() << "Capture: Running dvgrab " << m_captureArgs.join(" ");
425             captureProcess->start(KdenliveSettings::dvgrab_path(), m_captureArgs);
426             break;
427         case VIDEO4LINUX:
428             m_captureArgs << KdenliveSettings::video4capture().simplified().split(' ') << KdenliveSettings::video4encoding().simplified().split(' ') << "-vcodec" << "mpeg4" << "-acodec" << "mp2" << "-y" << m_captureFile.path() << "-f" << "mpegts" << "-vcodec" << "mpeg4" << "-acodec" << "mp2" << "-";
429             m_displayArgs << "-f" << "mpegts" << "-x" << QString::number(ui.video_frame->width()) << "-y" << QString::number(ui.video_frame->height()) << "-";
430             captureProcess->setStandardOutputProcess(displayProcess);
431             kDebug() << "Capture: Running ffmpeg " << m_captureArgs.join(" ");
432             captureProcess->start("ffmpeg", m_captureArgs);
433             break;
434         case SCREENGRAB:
435             switch (KdenliveSettings::rmd_capture_type()) {
436             case 0:
437                 // Full screen capture, nothing special to do
438                 break;
439             default:
440                 // Region capture
441                 m_captureArgs << "-width" << QString::number(KdenliveSettings::rmd_width()) << "-height" << QString::number(KdenliveSettings::rmd_height());
442                 if (!KdenliveSettings::rmd_follow_mouse()) {
443                     m_captureArgs << "-x" << QString::number(KdenliveSettings::rmd_offsetx()) << "-y" << QString::number(KdenliveSettings::rmd_offsety());
444                 } else {
445                     m_captureArgs << "--follow-mouse";
446                     if (KdenliveSettings::rmd_hide_frame()) m_captureArgs << "--no-frame";
447                 }
448                 break;
449             }
450             m_isCapturing = true;
451             if (KdenliveSettings::rmd_capture_audio()) {
452                 m_captureArgs << "-freq" << KdenliveSettings::rmd_freq();
453                 m_captureArgs << "-channels" << QString::number(KdenliveSettings::rmd_audio_channels());
454                 if (KdenliveSettings::rmd_use_jack()) {
455                     m_captureArgs << "-use-jack" << KdenliveSettings::rmd_jackports();
456                     if (KdenliveSettings::rmd_jack_buffer() > 0.0)
457                         m_captureArgs << "-ring-buffer-size" << QString::number(KdenliveSettings::rmd_jack_buffer());
458                 } else {
459                     if (!KdenliveSettings::rmd_alsadevicename().isEmpty())
460                         m_captureArgs << "-device" << KdenliveSettings::rmd_alsadevicename();
461                     if (KdenliveSettings::rmd_alsa_buffer() > 0)
462                         m_captureArgs << "-buffer-size" << QString::number(KdenliveSettings::rmd_alsa_buffer());
463                 }
464             } else m_captureArgs << "--no-sound";
465
466             if (KdenliveSettings::rmd_fullshots()) m_captureArgs << "--full-shots";
467             m_captureArgs << "-workdir" << KdenliveSettings::currenttmpfolder();
468             m_captureArgs << "-fps" << QString::number(KdenliveSettings::rmd_fps()) << "-o" << m_captureFile.path();
469             captureProcess->start(KdenliveSettings::rmd_path(), m_captureArgs);
470             kDebug() << "// RecordMyDesktop params: " << m_captureArgs;
471             break;
472         default:
473             break;
474         }
475
476
477         if (ui.device_selector->currentIndex() != SCREENGRAB) {
478             m_isCapturing = true;
479             kDebug() << "Capture: Running ffplay " << m_displayArgs.join(" ");
480             displayProcess->start("ffplay", m_displayArgs);
481             ui.video_frame->setText(i18n("Initialising..."));
482         }
483     } else {
484         // stop capture
485         displayProcess->kill();
486         //captureProcess->kill();
487         QTimer::singleShot(1000, this, SLOT(slotRecord()));
488     }
489 }
490
491 /*
492 void RecMonitor::slotStartGrab(const QRect &rect) {
493     rgnGrab->deleteLater();
494     QApplication::restoreOverrideCursor();
495     show();
496     if (rect.isNull()) return;
497     int width = rect.width();
498     int height = rect.height();
499     if (width % 2 != 0) width--;
500     if (height % 2 != 0) height--;
501     QString args = KdenliveSettings::screengrabcapture().replace("%size", QString::number(width) + "x" + QString::number(height)).replace("%offset", "+" + QString::number(rect.x()) + "," + QString::number(rect.y()));
502     if (KdenliveSettings::screengrabenableaudio()) {
503         // also capture audio
504         if (KdenliveSettings::useosscapture()) m_captureArgs << KdenliveSettings::screengrabosscapture().simplified().split(' ');
505         else m_captureArgs << KdenliveSettings::screengrabalsacapture2().simplified().split(' ');
506     }
507     m_captureArgs << args.simplified().split(' ') << KdenliveSettings::screengrabencoding().simplified().split(' ') << m_captureFile.path();
508     m_isCapturing = true;
509     ui.video_frame->setText(i18n("Capturing..."));
510     if (KdenliveSettings::screengrabenableaudio() && !KdenliveSettings::useosscapture()) {
511         QStringList alsaArgs = KdenliveSettings::screengrabalsacapture().simplified().split(' ');
512         alsaProcess->setStandardOutputProcess(captureProcess);
513         kDebug() << "Capture: Running arecord " << alsaArgs.join(" ");
514         alsaProcess->start("arecord", alsaArgs);
515     }
516     kDebug() << "Capture: Running ffmpeg " << m_captureArgs.join(" ");
517     captureProcess->start("ffmpeg", m_captureArgs);
518 }*/
519
520 void RecMonitor::slotProcessStatus(QProcess::ProcessState status) {
521     if (status == QProcess::NotRunning) {
522         displayProcess->kill();
523         if (m_isCapturing && ui.device_selector->currentIndex() != FIREWIRE)
524             if (ui.autoaddbox->isChecked() && QFile::exists(m_captureFile.path())) emit addProjectClip(m_captureFile);
525         if (ui.device_selector->currentIndex() == FIREWIRE) {
526             m_discAction->setIcon(KIcon("network-connect"));
527             m_discAction->setText(i18n("Connect"));
528             m_playAction->setEnabled(false);
529             m_rewAction->setEnabled(false);
530             m_fwdAction->setEnabled(false);
531             m_recAction->setEnabled(false);
532         }
533         m_isPlaying = false;
534         m_playAction->setIcon(m_playIcon);
535         m_recAction->setChecked(false);
536         m_stopAction->setEnabled(false);
537         ui.device_selector->setEnabled(true);
538         if (captureProcess && captureProcess->exitStatus() == QProcess::CrashExit) {
539             ui.video_frame->setText(i18n("Capture crashed, please check your parameters"));
540         } else {
541             if (ui.device_selector->currentIndex() != SCREENGRAB) ui.video_frame->setText(i18n("Not connected"));
542             else ui.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", KdenliveSettings::capturefolder())));
543         }
544         m_isCapturing = false;
545     } else {
546         if (ui.device_selector->currentIndex() != SCREENGRAB) m_stopAction->setEnabled(true);
547         ui.device_selector->setEnabled(false);
548     }
549 }
550
551 void RecMonitor::manageCapturedFiles() {
552     QString extension;
553     switch (KdenliveSettings::firewireformat()) {
554     case 0:
555         extension = ".dv";
556         break;
557     case 1:
558     case 2:
559         extension = ".avi";
560         break;
561     case 3:
562         extension = ".m2t";
563         break;
564     }
565     QDir dir(KdenliveSettings::capturefolder());
566     QStringList filters;
567     filters << "capture*" + extension;
568     const QStringList result = dir.entryList(filters, QDir::Files, QDir::Time);
569     KUrl::List capturedFiles;
570     foreach(QString name, result) {
571         KUrl url = KUrl(dir.filePath(name));
572         if (KIO::NetAccess::exists(url, KIO::NetAccess::SourceSide, this)) {
573             KFileItem file(KFileItem::Unknown, KFileItem::Unknown, url, true);
574             if (file.time(KFileItem::ModificationTime) > m_captureTime) capturedFiles.append(url);
575         }
576     }
577     kDebug() << "Found : " << capturedFiles.count() << " new capture files";
578     kDebug() << capturedFiles;
579
580     if (capturedFiles.count() > 0) {
581         ManageCapturesDialog *d = new ManageCapturesDialog(capturedFiles, this);
582         if (d->exec() == QDialog::Accepted) {
583             capturedFiles = d->importFiles();
584             foreach(KUrl url, capturedFiles) {
585                 emit addProjectClip(url);
586             }
587         }
588         delete d;
589     }
590 }
591
592 // virtual
593 void RecMonitor::mousePressEvent(QMouseEvent * event) {
594     slotPlay();
595 }
596
597 void RecMonitor::activateRecMonitor() {
598     //if (!m_isActive) m_monitorManager->activateRecMonitor(m_name);
599 }
600
601 void RecMonitor::stop() {
602     m_isActive = false;
603
604 }
605
606 void RecMonitor::start() {
607     m_isActive = true;
608
609 }
610
611 void RecMonitor::refreshRecMonitor(bool visible) {
612     if (visible) {
613         //if (!m_isActive) m_monitorManager->activateRecMonitor(m_name);
614
615     }
616 }
617
618 void RecMonitor::slotPlay() {
619
620     //if (!m_isActive) m_monitorManager->activateRecMonitor(m_name);
621
622 }
623
624
625 #include "recmonitor.moc"