]> git.sesse.net Git - kdenlive/blob - src/recmonitor.cpp
Fix several issues with spacer tool + some indent fixes
[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(KdenliveSettings::dvgrab_path(), 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(KdenliveSettings::dvgrab_path(), 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 {
451                     m_captureArgs << "--follow-mouse";
452                     if (KdenliveSettings::rmd_hide_frame()) m_captureArgs << "--no-frame";
453                 }
454                 break;
455             }
456             m_isCapturing = true;
457             if (KdenliveSettings::rmd_capture_audio()) {
458                 m_captureArgs << "-freq" << KdenliveSettings::rmd_freq();
459                 m_captureArgs << "-channels" << QString::number(KdenliveSettings::rmd_audio_channels());
460                 if (KdenliveSettings::rmd_use_jack()) {
461                     m_captureArgs << "-use-jack" << KdenliveSettings::rmd_jackports();
462                     if (KdenliveSettings::rmd_jack_buffer() > 0.0)
463                         m_captureArgs << "-ring-buffer-size" << QString::number(KdenliveSettings::rmd_jack_buffer());
464                 } else {
465                     if (!KdenliveSettings::rmd_alsadevicename().isEmpty())
466                         m_captureArgs << "-device" << KdenliveSettings::rmd_alsadevicename();
467                     if (KdenliveSettings::rmd_alsa_buffer() > 0)
468                         m_captureArgs << "-buffer-size" << QString::number(KdenliveSettings::rmd_alsa_buffer());
469                 }
470             } else m_captureArgs << "--no-sound";
471
472             if (KdenliveSettings::rmd_fullshots()) m_captureArgs << "--full-shots";
473             m_captureArgs << "-workdir" << KdenliveSettings::currenttmpfolder();
474             m_captureArgs << "-fps" << QString::number(KdenliveSettings::rmd_fps()) << "-o" << m_captureFile.path();
475             captureProcess->start(KdenliveSettings::rmd_path(), m_captureArgs);
476             kDebug() << "// RecordMyDesktop params: " << m_captureArgs;
477             break;
478         default:
479             break;
480         }
481
482
483         if (ui.device_selector->currentIndex() != SCREENGRAB) {
484             m_isCapturing = true;
485             kDebug() << "Capture: Running ffplay " << m_displayArgs.join(" ");
486             displayProcess->start("ffplay", m_displayArgs);
487             ui.video_frame->setText(i18n("Initialising..."));
488         }
489     } else {
490         // stop capture
491         displayProcess->kill();
492         //captureProcess->kill();
493         QTimer::singleShot(1000, this, SLOT(slotRecord()));
494     }
495 }
496
497 /*
498 void RecMonitor::slotStartGrab(const QRect &rect) {
499     rgnGrab->deleteLater();
500     QApplication::restoreOverrideCursor();
501     show();
502     if (rect.isNull()) return;
503     int width = rect.width();
504     int height = rect.height();
505     if (width % 2 != 0) width--;
506     if (height % 2 != 0) height--;
507     QString args = KdenliveSettings::screengrabcapture().replace("%size", QString::number(width) + "x" + QString::number(height)).replace("%offset", "+" + QString::number(rect.x()) + "," + QString::number(rect.y()));
508     if (KdenliveSettings::screengrabenableaudio()) {
509         // also capture audio
510         if (KdenliveSettings::useosscapture()) m_captureArgs << KdenliveSettings::screengrabosscapture().simplified().split(' ');
511         else m_captureArgs << KdenliveSettings::screengrabalsacapture2().simplified().split(' ');
512     }
513     m_captureArgs << args.simplified().split(' ') << KdenliveSettings::screengrabencoding().simplified().split(' ') << m_captureFile.path();
514     m_isCapturing = true;
515     ui.video_frame->setText(i18n("Capturing..."));
516     if (KdenliveSettings::screengrabenableaudio() && !KdenliveSettings::useosscapture()) {
517         QStringList alsaArgs = KdenliveSettings::screengrabalsacapture().simplified().split(' ');
518         alsaProcess->setStandardOutputProcess(captureProcess);
519         kDebug() << "Capture: Running arecord " << alsaArgs.join(" ");
520         alsaProcess->start("arecord", alsaArgs);
521     }
522     kDebug() << "Capture: Running ffmpeg " << m_captureArgs.join(" ");
523     captureProcess->start("ffmpeg", m_captureArgs);
524 }*/
525
526 void RecMonitor::slotProcessStatus(QProcess::ProcessState status) {
527     if (status == QProcess::NotRunning) {
528         displayProcess->kill();
529         if (m_isCapturing && ui.device_selector->currentIndex() != FIREWIRE)
530             if (ui.autoaddbox->isChecked() && QFile::exists(m_captureFile.path())) emit addProjectClip(m_captureFile);
531         if (ui.device_selector->currentIndex() == FIREWIRE) {
532             m_discAction->setIcon(KIcon("network-connect"));
533             m_discAction->setText(i18n("Connect"));
534             m_playAction->setEnabled(false);
535             m_rewAction->setEnabled(false);
536             m_fwdAction->setEnabled(false);
537             m_recAction->setEnabled(false);
538         }
539         m_isPlaying = false;
540         m_playAction->setIcon(m_playIcon);
541         m_recAction->setChecked(false);
542         m_stopAction->setEnabled(false);
543         ui.device_selector->setEnabled(true);
544         if (captureProcess && captureProcess->exitStatus() == QProcess::CrashExit) {
545             ui.video_frame->setText(i18n("Capture crashed, please check your parameters"));
546         } else {
547             if (ui.device_selector->currentIndex() != SCREENGRAB) ui.video_frame->setText(i18n("Not connected"));
548             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())));
549         }
550         m_isCapturing = false;
551     } else {
552         if (ui.device_selector->currentIndex() != SCREENGRAB) m_stopAction->setEnabled(true);
553         ui.device_selector->setEnabled(false);
554     }
555 }
556
557 void RecMonitor::manageCapturedFiles() {
558     QString extension;
559     switch (KdenliveSettings::firewireformat()) {
560     case 0:
561         extension = ".dv";
562         break;
563     case 1:
564     case 2:
565         extension = ".avi";
566         break;
567     case 3:
568         extension = ".m2t";
569         break;
570     }
571     QDir dir(KdenliveSettings::capturefolder());
572     QStringList filters;
573     filters << "capture*" + extension;
574     const QStringList result = dir.entryList(filters, QDir::Files, QDir::Time);
575     KUrl::List capturedFiles;
576     foreach(QString name, result) {
577         KUrl url = KUrl(dir.filePath(name));
578         if (KIO::NetAccess::exists(url, KIO::NetAccess::SourceSide, this)) {
579             KFileItem file(KFileItem::Unknown, KFileItem::Unknown, url, true);
580             if (file.time(KFileItem::ModificationTime) > m_captureTime) capturedFiles.append(url);
581         }
582     }
583     kDebug() << "Found : " << capturedFiles.count() << " new capture files";
584     kDebug() << capturedFiles;
585
586     if (capturedFiles.count() > 0) {
587         ManageCapturesDialog *d = new ManageCapturesDialog(capturedFiles, this);
588         if (d->exec() == QDialog::Accepted) {
589             capturedFiles = d->importFiles();
590             foreach(KUrl url, capturedFiles) {
591                 emit addProjectClip(url);
592             }
593         }
594         delete d;
595     }
596 }
597
598 // virtual
599 void RecMonitor::mousePressEvent(QMouseEvent * event) {
600     slotPlay();
601 }
602
603 void RecMonitor::activateRecMonitor() {
604     //if (!m_isActive) m_monitorManager->activateRecMonitor(m_name);
605 }
606
607 void RecMonitor::stop() {
608     m_isActive = false;
609
610 }
611
612 void RecMonitor::start() {
613     m_isActive = true;
614
615 }
616
617 void RecMonitor::refreshRecMonitor(bool visible) {
618     if (visible) {
619         //if (!m_isActive) m_monitorManager->activateRecMonitor(m_name);
620
621     }
622 }
623
624 void RecMonitor::slotPlay() {
625
626     //if (!m_isActive) m_monitorManager->activateRecMonitor(m_name);
627
628 }
629
630
631 #include "recmonitor.moc"