]> git.sesse.net Git - kdenlive/blobdiff - src/wizard.cpp
Display webcam pixel format in wizard
[kdenlive] / src / wizard.cpp
index 146a94ab01fe347f5735c5b350b3a6d69c30a2a1..c88f9a01a143538e95035b75ed6b7e14ab073bb4 100644 (file)
@@ -20,6 +20,7 @@
 #include "wizard.h"
 #include "kdenlivesettings.h"
 #include "profilesdialog.h"
+#include "v4l/v4lcapture.h"
 #include "kdenlive-config.h"
 
 #include <KStandardDirs>
 #include <QXmlStreamWriter>
 #include <QTimer>
 
-const double recommendedMltVersion = 46;
-static const char version[] = VERSION;
+const double recommendedMltVersion = 510;
+static const char kdenlive_version[] = VERSION;
 
 Wizard::Wizard(bool upgrade, QWidget *parent) :
-        QWizard(parent)
+    QWizard(parent)
 {
     setWindowTitle(i18n("Config Wizard"));
     setPixmap(QWizard::WatermarkPixmap, QPixmap(KStandardDirs::locate("appdata", "banner.png")));
@@ -48,7 +49,7 @@ Wizard::Wizard(bool upgrade, QWidget *parent) :
     page1->setTitle(i18n("Welcome"));
     QLabel *label;
     if (upgrade)
-        label = new QLabel(i18n("Your Kdenlive version was upgraded to version %1. Please take some time to review the basic settings", QString(version).section(' ', 0, 0)));
+        label = new QLabel(i18n("Your Kdenlive version was upgraded to version %1. Please take some time to review the basic settings", QString(kdenlive_version).section(' ', 0, 0)));
     else
         label = new QLabel(i18n("This is the first time you run Kdenlive. This wizard will let you adjust some basic settings, you will be ready to edit your first movie in a few seconds..."));
     label->setWordWrap(true);
@@ -122,6 +123,15 @@ Wizard::Wizard(bool upgrade, QWidget *parent) :
     slotCheckThumbs();
     addPage(page3);
 
+    QWizardPage *page6 = new QWizardPage;
+    page6->setTitle(i18n("Webcam"));
+    m_capture.setupUi(page6);
+    connect(m_capture.button_reload, SIGNAL(clicked()), this, SLOT(slotDetectWebcam()));
+    connect(m_capture.device_list, SIGNAL(itemSelectionChanged()), this, SLOT(slotUpdateCaptureParameters()));
+    m_capture.button_reload->setIcon(KIcon("view-refresh"));
+
+    addPage(page6);
+
 
     QWizardPage *page5 = new QWizardPage;
     page5->setTitle(i18n("Checking system"));
@@ -130,10 +140,53 @@ Wizard::Wizard(bool upgrade, QWidget *parent) :
 
     listViewDelegate = new WizardDelegate(m_check.programList);
     m_check.programList->setItemDelegate(listViewDelegate);
-
+    slotDetectWebcam();
     QTimer::singleShot(500, this, SLOT(slotCheckMlt()));
 }
 
+void Wizard::slotDetectWebcam()
+{
+    m_capture.device_list->clear();
+
+    // Video 4 Linux device detection
+    V4lCaptureHandler v4l(NULL);
+    for (int i = 0; i < 10; i++) {
+        QString path = "/dev/video" + QString::number(i);
+        if (QFile::exists(path)) {
+            QStringList deviceInfo = v4l.getDeviceName(path.toUtf8().constData());
+            if (!deviceInfo.isEmpty()) {
+                QTreeWidgetItem *item = new QTreeWidgetItem(m_capture.device_list, QStringList() << deviceInfo.at(0) << "(" + deviceInfo.at(1) + ") " + deviceInfo.at(2));
+                item->setData(0, Qt::UserRole, path);
+                item->setData(0, Qt::UserRole + 1, deviceInfo.at(1));
+            }
+        }
+    }
+    if (m_capture.device_list->topLevelItemCount() > 0) {
+        m_capture.v4l_status->setText(i18n("Select your default video4linux device"));
+        // select default device
+        bool found = false;
+        for (int i = 0; i < m_capture.device_list->topLevelItemCount(); i++) {
+            QTreeWidgetItem * item = m_capture.device_list->topLevelItem(i);
+            if (item && item->data(0, Qt::UserRole).toString() == KdenliveSettings::video4vdevice()) {
+                m_capture.device_list->setCurrentItem(item);
+                found = true;
+                break;
+            }
+        }
+        if (!found) m_capture.device_list->setCurrentItem(m_capture.device_list->topLevelItem(0));
+    } else m_capture.v4l_status->setText(i18n("No device found, plug your webcam and refresh."));
+}
+
+void Wizard::slotUpdateCaptureParameters()
+{
+    QTreeWidgetItem * item = m_capture.device_list->currentItem();
+    if (!item) return;
+    QString device = item->data(0, Qt::UserRole).toString();
+    if (!device.isEmpty()) KdenliveSettings::setVideo4vdevice(device);
+
+    QString size = item->data(0, Qt::UserRole + 1).toString();
+    if (!size.isEmpty()) KdenliveSettings::setVideo4size(size);
+}
 
 void Wizard::checkMltComponents()
 {
@@ -180,7 +233,7 @@ void Wizard::checkMltComponents()
                 } else {
                     checkProcess.waitForFinished();
                     mltVersion = checkProcess.readAllStandardOutput();
-                    version = 100 * mltVersion.section('.', 0, 0).toInt() + 10 * mltVersion.section('.', 1, 1).toInt() + mltVersion.section('.', 2, 2).toInt();
+                    version = 1000 * mltVersion.section('.', 0, 0).toInt() + 100 * mltVersion.section('.', 1, 1).toInt() + mltVersion.section('.', 2, 2).toInt();
                     kDebug() << "// FOUND MLT's pkgconfig version: " << version;
                 }
             }
@@ -193,14 +246,14 @@ void Wizard::checkMltComponents()
                     mltVersion = checkProcess.readAllStandardError();
                     mltVersion = mltVersion.section('\n', 0, 0).simplified();
                     mltVersion = mltVersion.section(' ', -1).simplified();
-                    version = 100 * mltVersion.section('.', 0, 0).toInt() + 10 * mltVersion.section('.', 1, 1).toInt() + mltVersion.section('.', 2, 2).toInt();
+                    version = 1000 * mltVersion.section('.', 0, 0).toInt() + 100 * mltVersion.section('.', 1, 1).toInt() + mltVersion.section('.', 2, 2).toInt();
                     kDebug() << "// FOUND MLT version: " << version;
                 }
             }
 
             mltitem->setText(1, i18n("MLT version: %1", mltVersion.simplified()));
             mltitem->setSizeHint(0, itemSize);
-            if (version < 40) {
+            if (version < 506) {
                 mltitem->setData(1, Qt::UserRole, i18n("Your MLT version is unsupported!!!"));
                 mltitem->setIcon(0, m_badIcon);
             } else {
@@ -388,7 +441,7 @@ void Wizard::installExtraMimes(QString baseName, QStringList globs)
     } else {
         QStringList extensions = mime->patterns();
         QString comment = mime->comment();
-        foreach(const QString &glob, globs) {
+        foreach(const QString & glob, globs) {
             if (!extensions.contains(glob)) extensions << glob;
         }
         kDebug() << "EXTS: " << extensions;
@@ -415,7 +468,7 @@ void Wizard::installExtraMimes(QString baseName, QStringList globs)
             writer.writeEndElement(); // comment
         }
 
-        foreach(const QString& pattern, extensions) {
+        foreach(const QString & pattern, extensions) {
             writer.writeStartElement(nsUri, "glob");
             writer.writeAttribute("pattern", pattern);
             writer.writeEndElement(); // glob
@@ -558,7 +611,7 @@ void Wizard::slotCheckMlt()
     if (!result.contains("sdl") || !result.contains("sdl_preview")) errorMessage.append(i18n("MLT's SDL module not found. Please check your MLT install. Kdenlive will not work until this issue is fixed.") + '\n');
 
     if (!errorMessage.isEmpty()) {
-        errorMessage.prepend(QString("<b>%1</b><br>").arg(i18n("Fatal Error")));
+        errorMessage.prepend(QString("<b>%1</b><br />").arg(i18n("Fatal Error")));
         QLabel *pix = new QLabel();
         pix->setPixmap(KIcon("dialog-error").pixmap(30));
         QLabel *label = new QLabel(errorMessage);
@@ -581,7 +634,7 @@ bool Wizard::isOk() const
 
 void Wizard::slotShowWebInfos()
 {
-    KRun::runUrl(KUrl("http://kdenlive.org/discover/" + QString(version).section(' ', 0, 0)), "text/html", this);
+    KRun::runUrl(KUrl("http://kdenlive.org/discover/" + QString(kdenlive_version).section(' ', 0, 0)), "text/html", this);
 }
 
 #include "wizard.moc"