From 0afebd0e3cb3da831cd5ffba1eefbe9e61e408a1 Mon Sep 17 00:00:00 2001 From: Arno Date: Sat, 27 Jul 2013 03:59:47 +0200 Subject: Read JSON from ffprobe Use JSON output from ffprobe instead of string parsing to get some kind of type safety. For doing that, some changes were needed in FileView: Use delegates for displaying Duration and Bitrate instead of mangling output in Qt::Displayrole. To reuse code, move all delegates from the new Archive to a separate file. And, of course, the initial objective: Show the accumulated size and duration of selected files in the status bar from the experimental archive. --- delegates.cpp | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 delegates.cpp (limited to 'delegates.cpp') diff --git a/delegates.cpp b/delegates.cpp new file mode 100644 index 0000000..ec1fe54 --- /dev/null +++ b/delegates.cpp @@ -0,0 +1,86 @@ +/* + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version + 2 of the License, or (at your option) any later version. +*/ + +#include +#include + +#include "delegates.h" +#include "helper.h" + +/* Delegate for File no. */ + +QString FileNoDelegate::displayText(const QVariant &value, const QLocale &locale) const{ + Q_UNUSED(locale); + int no = value.toInt(); + if(no){ + return QString::number(no); + } + return QString(); +} + +QWidget *FileNoDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const{ + Q_UNUSED(option); + QSpinBox *retval = new QSpinBox(parent); + int no = index.data().toInt(); + retval->setValue(no); + return retval; +} + +/* Delegate for Dvd no. */ + +QString DvdNoDelegate::displayText(const QVariant &value, const QLocale &locale) const{ + Q_UNUSED(locale); + int no = value.toInt(); + if(no < 0){ + return tr("(local)"); + } + QString retval = QString(tr("#%1")).arg(QString::number(no)); + return retval; +} + +/* Delegate for size */ + +QString SizeDelegate::displayText(const QVariant &value, const QLocale &locale) const{ + // locale.toString() doesn't work, maybe b/c it's const + Q_UNUSED(locale); + QLocale l; + return l.toString(value.toLongLong()); +} + +/* Delegate for duration */ + +QString DurationDelegate::displayText(const QVariant &value, const QLocale &locale) const{ + Q_UNUSED(locale); + if(value.toString().contains("x")){ + return value.toString(); + } + qint64 secs = value.toInt(); + if(secs == 0){ + return tr("n/a"); + } + Helper::Duration dur(secs); + return dur.toString(); +} + +/* Delegate for bitrate */ + +QString BitrateDelegate::displayText(const QVariant &value, const QLocale &locale) const{ + Q_UNUSED(locale); + int br = value.toInt() / 1000; + QString retval = QString("%1 kb/s").arg(QString::number(br)); + return retval; +} + +/* Empty delegate */ + +QString EmptyDelegate::displayText(const QVariant &value, const QLocale &locale) const{ + int i = value.toInt(); + if(i < 1){ + return QString(); + } + return QStyledItemDelegate::displayText(value, locale); +} -- cgit v1.2.3-70-g09d2