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