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