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