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