]> git.sesse.net Git - kdenlive/blob - src/recmonitor.cpp
Added debug outputs to recmonitor, in order to allow jmpoure to better debug http...
[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     alsaProcess = new QProcess;
89
90     connect(captureProcess, SIGNAL(stateChanged(QProcess::ProcessState)), this, SLOT(slotProcessStatus(QProcess::ProcessState)));
91
92     QStringList env = QProcess::systemEnvironment();
93     env << "SDL_WINDOWID=" + QString::number(ui.video_frame->winId());
94
95     QString videoDriver = KdenliveSettings::videodrivername();
96     if (!videoDriver.isEmpty()) {
97         if (videoDriver == "x11_noaccel") {
98             env << "SDL_VIDEO_YUV_HWACCEL=0";
99             env << "SDL_VIDEODRIVER=x11";
100         } else env << "SDL_VIDEODRIVER=" + videoDriver;
101     }
102     setenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1", 1);
103
104     displayProcess->setEnvironment(env);
105
106     if (KdenliveSettings::video4capture().isEmpty()) {
107         QString captureCommand;
108         if (!KdenliveSettings::video4adevice().isEmpty()) captureCommand = "-f " + KdenliveSettings::video4aformat() + " -i " + KdenliveSettings::video4adevice();
109
110         captureCommand +=  " -f " + KdenliveSettings::video4vformat() + " -s " + KdenliveSettings::video4size() + " -r " + QString::number(KdenliveSettings::video4rate()) + " -i " + KdenliveSettings::video4vdevice() + " -f " + KdenliveSettings::video4vencoding();
111         KdenliveSettings::setVideo4capture(captureCommand);
112     }
113
114     if (KdenliveSettings::video4playback().isEmpty()) {
115         QString playbackCommand;
116         playbackCommand =  "-f " + KdenliveSettings::video4vencoding();
117         KdenliveSettings::setVideo4playback(playbackCommand);
118     }
119     kDebug() << "/////// BUILDING MONITOR, ID: " << ui.video_frame->winId();
120 }
121
122 RecMonitor::~RecMonitor() {
123     delete captureProcess;
124     delete displayProcess;
125     delete alsaProcess;
126 }
127
128 QString RecMonitor::name() const {
129     return m_name;
130 }
131
132 void RecMonitor::slotConfigure() {
133     emit showConfigDialog(4, ui.device_selector->currentIndex());
134 }
135
136 void RecMonitor::slotVideoDeviceChanged(int ix) {
137     switch (ix) {
138     case SCREENGRAB:
139         m_discAction->setEnabled(false);
140         m_rewAction->setEnabled(false);
141         m_fwdAction->setEnabled(false);
142         m_recAction->setEnabled(true);
143         m_stopAction->setEnabled(false);
144         m_playAction->setEnabled(false);
145         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())));
146         //ui.video_frame->setText(i18n("Press record button\nto start screen capture"));
147         break;
148     case VIDEO4LINUX:
149         m_discAction->setEnabled(false);
150         m_rewAction->setEnabled(false);
151         m_fwdAction->setEnabled(false);
152         m_recAction->setEnabled(true);
153         m_stopAction->setEnabled(false);
154         m_playAction->setEnabled(true);
155         checkDeviceAvailability();
156         break;
157     default: // FIREWIRE
158         m_discAction->setEnabled(true);
159         m_recAction->setEnabled(false);
160         m_stopAction->setEnabled(false);
161         m_playAction->setEnabled(false);
162         m_rewAction->setEnabled(false);
163         m_fwdAction->setEnabled(false);
164         //ui.video_frame->setText(i18n("Plug your camcorder and\npress connect button\nto initialize connection"));
165         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())));
166         break;
167     }
168 }
169
170 QPixmap RecMonitor::mergeSideBySide(const QPixmap& pix, const QString txt) {
171     QPainter p;
172     QRect r = p.fontMetrics().boundingRect(QRect(0, 0, ui.video_frame->width(), ui.video_frame->height()), Qt::AlignLeft, txt);
173     int strWidth = r.width();
174     int strHeight = r.height();
175     int pixWidth = pix.width();
176     int pixHeight = pix.height();
177     QPixmap res(strWidth + 8 + pixWidth, qMax(strHeight, pixHeight));
178     res.fill(Qt::transparent);
179     p.begin(&res);
180     p.drawPixmap(0, 0, pix);
181     p.drawText(QRect(pixWidth + 8, 0, strWidth, strHeight), 0, txt);
182     p.end();
183     return res;
184 }
185
186
187 void RecMonitor::checkDeviceAvailability() {
188     if (!KIO::NetAccess::exists(KUrl(KdenliveSettings::video4vdevice()), KIO::NetAccess::SourceSide , this)) {
189         m_playAction->setEnabled(false);
190         m_recAction->setEnabled(false);
191         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())));
192         //ui.video_frame->setText(i18n("Cannot read from device %1\nPlease check drivers and access rights.", KdenliveSettings::video4vdevice()));
193     } else //ui.video_frame->setText(i18n("Press play or record button\nto start video capture"));
194         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())));
195 }
196
197 void RecMonitor::slotDisconnect() {
198     if (captureProcess->state() == QProcess::NotRunning) {
199         m_captureTime = KDateTime::currentLocalDateTime();
200         kDebug() << "CURRENT TIME: " << m_captureTime.toString();
201         m_didCapture = false;
202         slotStartCapture(false);
203         m_discAction->setIcon(KIcon("network-disconnect"));
204         m_discAction->setText(i18n("Disonnect"));
205         m_recAction->setEnabled(true);
206         m_stopAction->setEnabled(true);
207         m_playAction->setEnabled(true);
208         m_rewAction->setEnabled(true);
209         m_fwdAction->setEnabled(true);
210     } else {
211         captureProcess->write("q", 1);
212         QTimer::singleShot(1000, captureProcess, SLOT(kill()));
213         if (m_didCapture) manageCapturedFiles();
214         m_didCapture = false;
215     }
216 }
217
218 void RecMonitor::slotRewind() {
219     captureProcess->write("a", 1);
220 }
221
222 void RecMonitor::slotForward() {
223     captureProcess->write("z", 1);
224 }
225
226 void RecMonitor::slotStopCapture() {
227     // stop capture
228     switch (ui.device_selector->currentIndex()) {
229     case FIREWIRE:
230         captureProcess->write("\e", 2);
231         m_playAction->setIcon(m_playIcon);
232         m_isPlaying = false;
233         break;
234     case VIDEO4LINUX:
235         captureProcess->write("q\n", 3);
236         QTimer::singleShot(1000, captureProcess, SLOT(kill()));
237
238         break;
239     case SCREENGRAB:
240         captureProcess->write("q\n", 3);
241         QTimer::singleShot(1000, captureProcess, SLOT(kill()));
242         break;
243     default:
244         break;
245     }
246 }
247
248 void RecMonitor::slotStartCapture(bool play) {
249
250     /*
251     *captureProcess<<"dvgrab";
252
253     bool isHdv = false;
254
255     switch (m_recPanel->capture_format->currentItem()){
256         case 0:
257       *captureProcess<<"--format"<<"dv1";
258      break;
259         case 1:
260       *captureProcess<<"--format"<<"dv2";
261      break;
262         case 3:
263       *captureProcess<<"--format"<<"hdv";
264      isHdv = true;
265      break;
266         default:
267             *captureProcess<<"--format"<<"raw";
268      break;
269     }
270
271     if (KdenliveSettings::autosplit()) *captureProcess<<"--autosplit";
272     if (KdenliveSettings::timestamp()) *captureProcess<<"--timestamp";
273     *captureProcess<<"-i"<<"capture"<<"-";*/
274
275     /*
276         QStringList captureArgs;
277         captureArgs<<"--format"<<"hdv"<<"-i"<<"capture"<<"-";
278         QStringList displayArgs;
279
280         displayArgs<<"-f"<<"mpegts"<<"-x"<<QString::number(ui.video_frame->width())<<"-y"<<QString::number(ui.video_frame->height())<<"-";
281
282         captureProcess->setStandardOutputProcess(displayProcess);
283         ui.video_frame->setScaledContents(false);
284         captureProcess->start("dvgrab",captureArgs);
285         displayProcess->start("ffplay",  displayArgs);*/
286
287
288     if (captureProcess->state() != QProcess::NotRunning) {
289         if (ui.device_selector->currentIndex() == FIREWIRE) {
290             if (m_isPlaying) {
291                 captureProcess->write("k", 1);
292                 //captureProcess->write("\e", 2);
293                 m_playAction->setIcon(m_playIcon);
294                 m_isPlaying = false;
295             } else {
296                 captureProcess->write("p", 1);
297                 m_playAction->setIcon(m_pauseIcon);
298                 m_isPlaying = true;
299             }
300         }
301         return;
302     }
303     m_captureArgs.clear();
304     m_displayArgs.clear();
305     m_isPlaying = false;
306
307     switch (ui.device_selector->currentIndex()) {
308     case FIREWIRE:
309         switch (KdenliveSettings::firewireformat()) {
310         case 0:
311             // RAW DV CAPTURE
312             m_captureArgs << "--format" << "raw";
313             m_displayArgs << "-f" << "dv";
314             break;
315         case 1:
316             // DV type 1
317             m_captureArgs << "--format" << "dv1";
318             m_displayArgs << "-f" << "dv";
319             break;
320         case 2:
321             // DV type 2
322             m_captureArgs << "--format" << "dv2";
323             m_displayArgs << "-f" << "dv";
324             break;
325         case 3:
326             // HDV CAPTURE
327             m_captureArgs << "--format" << "hdv";
328             m_displayArgs << "-f" << "mpegts";
329             break;
330         }
331         if (KdenliveSettings::firewireautosplit()) m_captureArgs << "--autosplit";
332         if (KdenliveSettings::firewiretimestamp()) m_captureArgs << "--timestamp";
333         m_captureArgs << "-i" << "capture" << "-";
334         m_displayArgs << "-x" << QString::number(ui.video_frame->width()) << "-y" << QString::number(ui.video_frame->height()) << "-";
335
336         captureProcess->setStandardOutputProcess(displayProcess);
337         captureProcess->setWorkingDirectory(KdenliveSettings::capturefolder());
338         kDebug() << "Capture: Running dvgrab " << m_captureArgs.join(" ");
339         captureProcess->start("dvgrab", m_captureArgs);
340         if (play) captureProcess->write(" ", 1);
341         m_discAction->setEnabled(true);
342         break;
343     case VIDEO4LINUX:
344         m_captureArgs << KdenliveSettings::video4capture().simplified().split(' ') << "-";
345         m_displayArgs << KdenliveSettings::video4playback().simplified().split(' ') << "-x" << QString::number(ui.video_frame->width()) << "-y" << QString::number(ui.video_frame->height()) << "-";
346         captureProcess->setStandardOutputProcess(displayProcess);
347         kDebug() << "Capture: Running ffmpeg " << m_captureArgs.join(" ");
348         captureProcess->start("ffmpeg", m_captureArgs);
349         break;
350     default:
351         break;
352     }
353
354     if (ui.device_selector->currentIndex() != SCREENGRAB) {
355         kDebug() << "Capture: Running ffplay " << m_captureArgs.join(" ");
356         displayProcess->start("ffplay", m_displayArgs);
357         ui.video_frame->setText(i18n("Initialising..."));
358     } else {
359         // do something when starting screen grab
360     }
361 }
362
363 void RecMonitor::slotRecord() {
364     if (captureProcess->state() == QProcess::NotRunning && ui.device_selector->currentIndex() == FIREWIRE) {
365         slotStartCapture();
366     }
367     if (m_isCapturing) {
368         switch (ui.device_selector->currentIndex()) {
369         case FIREWIRE:
370             captureProcess->write("\e", 2);
371             m_playAction->setIcon(m_playIcon);
372             m_isCapturing = false;
373             m_isPlaying = false;
374             m_recAction->setChecked(false);
375             break;
376         case VIDEO4LINUX:
377             captureProcess->terminate();
378             slotStopCapture();
379             //m_isCapturing = false;
380             QTimer::singleShot(1000, this, SLOT(slotStartCapture()));
381             break;
382         case SCREENGRAB:
383             captureProcess->write("q\n", 3);
384             captureProcess->terminate();
385             alsaProcess->terminate();
386             alsaProcess->kill();
387             // in case ffmpeg doesn't exit with the 'q' command, kill it one second later
388             QTimer::singleShot(1000, captureProcess, SLOT(kill()));
389             break;
390         }
391         return;
392     } else if (ui.device_selector->currentIndex() == FIREWIRE) {
393         m_isCapturing = true;
394         m_didCapture = true;
395         captureProcess->write("c\n", 3);
396         return;
397     }
398     if (captureProcess->state() == QProcess::NotRunning) {
399         m_recAction->setChecked(true);
400         QString extension = "mpg";
401         if (ui.device_selector->currentIndex() == SCREENGRAB) extension = KdenliveSettings::screengrabextension();
402         QString path = KdenliveSettings::capturefolder() + "/capture0000." + extension;
403         int i = 1;
404         while (QFile::exists(path)) {
405             QString num = QString::number(i).rightJustified(4, '0', false);
406             path = KdenliveSettings::capturefolder() + "/capture" + num + "." + extension;
407             i++;
408         }
409
410         m_captureFile = KUrl(path);
411
412         m_captureArgs.clear();
413         m_displayArgs.clear();
414         QString args;
415
416         switch (ui.device_selector->currentIndex()) {
417         case FIREWIRE:
418             m_captureArgs << "--format" << "hdv" << "-i" << "capture" << "-";
419             m_displayArgs << "-f" << "mpegts" << "-x" << QString::number(ui.video_frame->width()) << "-y" << QString::number(ui.video_frame->height()) << "-";
420             captureProcess->setStandardOutputProcess(displayProcess);
421             kDebug() << "Capture: Running dvgrab " << m_captureArgs.join(" ");
422             captureProcess->start("dvgrab", m_captureArgs);
423             break;
424         case VIDEO4LINUX:
425             m_captureArgs << KdenliveSettings::video4capture().simplified().split(' ') << "-y" << m_captureFile.path() << "-f" << KdenliveSettings::video4vencoding() << "-";
426             m_displayArgs << KdenliveSettings::video4playback().simplified().split(' ') << "-x" << QString::number(ui.video_frame->width()) << "-y" << QString::number(ui.video_frame->height()) << "-";
427             captureProcess->setStandardOutputProcess(displayProcess);
428             kDebug() << "Capture: Running ffmpeg " << m_captureArgs.join(" ");
429             captureProcess->start("ffmpeg", m_captureArgs);
430             break;
431         case SCREENGRAB:
432             if (KdenliveSettings::fullscreengrab()) {
433                 const QRect rect = QApplication::desktop()->screenGeometry();
434                 args = KdenliveSettings::screengrabcapture().replace("%size", QString::number(rect.width()) + "x" + QString::number(rect.height())).replace("%offset", QString());
435                 if (KdenliveSettings::screengrabenableaudio()) {
436                     // also capture audio
437                     if (KdenliveSettings::useosscapture()) m_captureArgs << KdenliveSettings::screengrabosscapture().simplified().split(' ');
438                     else m_captureArgs << KdenliveSettings::screengrabalsacapture2().simplified().split(' ');
439                 }
440                 m_captureArgs << args.simplified().split(' ') << KdenliveSettings::screengrabencoding().simplified().split(' ') << m_captureFile.path();
441                 ui.video_frame->setText(i18n("Capturing..."));
442                 m_isCapturing = true;
443                 if (KdenliveSettings::screengrabenableaudio() && !KdenliveSettings::useosscapture()) {
444                     QStringList alsaArgs = KdenliveSettings::screengrabalsacapture().simplified().split(' ');
445                     alsaProcess->setStandardOutputProcess(captureProcess);
446                     kDebug() << "Capture: Running arecord " << alsaArgs.join(" ");
447                     alsaProcess->start("arecord", alsaArgs);
448                 }
449                 kDebug() << "Capture: Running ffmpeg " << m_captureArgs.join(" ");
450                 captureProcess->start("ffmpeg", m_captureArgs);
451             } else {
452                 ui.video_frame->setText(i18n("Select region..."));
453                 rgnGrab = new RegionGrabber();
454                 connect(rgnGrab, SIGNAL(regionGrabbed(const QRect&)), SLOT(slotStartGrab(const QRect &)));
455             }
456             break;
457         default:
458             break;
459         }
460
461         //ui.video_frame->setScaledContents(false);
462         if (ui.device_selector->currentIndex() != SCREENGRAB) {
463             m_isCapturing = true;
464             kDebug() << "Capture: Running ffplay " << m_displayArgs.join(" ");
465             displayProcess->start("ffplay", m_displayArgs);
466             ui.video_frame->setText(i18n("Initialising..."));
467         }
468     } else {
469         // stop capture
470         displayProcess->kill();
471         captureProcess->kill();
472         alsaProcess->kill();
473         QTimer::singleShot(1000, this, SLOT(slotRecord()));
474     }
475 }
476
477 void RecMonitor::slotStartGrab(const QRect &rect) {
478     rgnGrab->deleteLater();
479     QApplication::restoreOverrideCursor();
480     show();
481     if (rect.isNull()) return;
482     int width = rect.width();
483     int height = rect.height();
484     if (width % 2 != 0) width--;
485     if (height % 2 != 0) height--;
486     QString args = KdenliveSettings::screengrabcapture().replace("%size", QString::number(width) + "x" + QString::number(height)).replace("%offset", "+" + QString::number(rect.x()) + "," + QString::number(rect.y()));
487     if (KdenliveSettings::screengrabenableaudio()) {
488         // also capture audio
489         if (KdenliveSettings::useosscapture()) m_captureArgs << KdenliveSettings::screengrabosscapture().simplified().split(' ');
490         else m_captureArgs << KdenliveSettings::screengrabalsacapture2().simplified().split(' ');
491     }
492     m_captureArgs << args.simplified().split(' ') << KdenliveSettings::screengrabencoding().simplified().split(' ') << m_captureFile.path();
493     m_isCapturing = true;
494     ui.video_frame->setText(i18n("Capturing..."));
495     if (KdenliveSettings::screengrabenableaudio() && !KdenliveSettings::useosscapture()) {
496         QStringList alsaArgs = KdenliveSettings::screengrabalsacapture().simplified().split(' ');
497         alsaProcess->setStandardOutputProcess(captureProcess);
498         kDebug() << "Capture: Running arecord " << alsaArgs.join(" ");
499         alsaProcess->start("arecord", alsaArgs);
500     }
501     kDebug() << "Capture: Running ffmpeg " << m_captureArgs.join(" ");
502     captureProcess->start("ffmpeg", m_captureArgs);
503 }
504
505 void RecMonitor::slotProcessStatus(QProcess::ProcessState status) {
506     if (status == QProcess::NotRunning) {
507         displayProcess->kill();
508         if (m_isCapturing && ui.device_selector->currentIndex() != FIREWIRE)
509             if (ui.autoaddbox->isChecked() && QFile::exists(m_captureFile.path())) emit addProjectClip(m_captureFile);
510         if (ui.device_selector->currentIndex() == FIREWIRE) {
511             m_discAction->setIcon(KIcon("network-connect"));
512             m_discAction->setText(i18n("Connect"));
513             m_playAction->setEnabled(false);
514             m_rewAction->setEnabled(false);
515             m_fwdAction->setEnabled(false);
516             m_recAction->setEnabled(false);
517         }
518         m_isPlaying = false;
519         m_playAction->setIcon(m_playIcon);
520         m_recAction->setChecked(false);
521         m_stopAction->setEnabled(false);
522         ui.device_selector->setEnabled(true);
523         if (captureProcess && captureProcess->exitStatus() == QProcess::CrashExit) {
524             ui.video_frame->setText(i18n("Capture crashed, please check your parameters"));
525         } else {
526             ui.video_frame->setText(i18n("Not connected"));
527         }
528         m_isCapturing = false;
529     } else {
530         if (ui.device_selector->currentIndex() != SCREENGRAB) m_stopAction->setEnabled(true);
531         ui.device_selector->setEnabled(false);
532     }
533 }
534
535 void RecMonitor::manageCapturedFiles() {
536     QString extension;
537     switch (KdenliveSettings::firewireformat()) {
538     case 0:
539         extension = ".dv";
540         break;
541     case 1:
542     case 2:
543         extension = ".avi";
544         break;
545     case 3:
546         extension = ".m2t";
547         break;
548     }
549     QDir dir(KdenliveSettings::capturefolder());
550     QStringList filters;
551     filters << "capture*" + extension;
552     const QStringList result = dir.entryList(filters, QDir::Files, QDir::Time);
553     KUrl::List capturedFiles;
554     foreach(QString name, result) {
555         KUrl url = KUrl(dir.filePath(name));
556         if (KIO::NetAccess::exists(url, KIO::NetAccess::SourceSide, this)) {
557             KFileItem file(KFileItem::Unknown, KFileItem::Unknown, url, true);
558             if (file.time(KFileItem::ModificationTime) > m_captureTime) capturedFiles.append(url);
559         }
560     }
561     kDebug() << "Found : " << capturedFiles.count() << " new capture files";
562     kDebug() << capturedFiles;
563
564     if (capturedFiles.count() > 0) {
565         ManageCapturesDialog *d = new ManageCapturesDialog(capturedFiles, this);
566         if (d->exec() == QDialog::Accepted) {
567             capturedFiles = d->importFiles();
568             foreach(KUrl url, capturedFiles) {
569                 emit addProjectClip(url);
570             }
571         }
572         delete d;
573     }
574 }
575
576 // virtual
577 void RecMonitor::mousePressEvent(QMouseEvent * event) {
578     slotPlay();
579 }
580
581 void RecMonitor::activateRecMonitor() {
582     //if (!m_isActive) m_monitorManager->activateRecMonitor(m_name);
583 }
584
585 void RecMonitor::stop() {
586     m_isActive = false;
587
588 }
589
590 void RecMonitor::start() {
591     m_isActive = true;
592
593 }
594
595 void RecMonitor::refreshRecMonitor(bool visible) {
596     if (visible) {
597         //if (!m_isActive) m_monitorManager->activateRecMonitor(m_name);
598
599     }
600 }
601
602 void RecMonitor::slotPlay() {
603
604     //if (!m_isActive) m_monitorManager->activateRecMonitor(m_name);
605
606 }
607
608
609 #include "recmonitor.moc"