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