SilentEye 0.4.1

propertydialog.cpp

Go to the documentation of this file.
00001 //  This file is part of SilentEye.
00002 //
00003 //  SilentEye is free software: you can redistribute it and/or modify
00004 //  it under the terms of the GNU General Public License as published by
00005 //  the Free Software Foundation, either version 3 of the License, or
00006 //  (at your option) any later version.
00007 //
00008 //  SilentEye is distributed in the hope that it will be useful,
00009 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 //  GNU General Public License for more details.
00012 //
00013 //  You should have received a copy of the GNU General Public License
00014 //  along with SilentEye. If not, see <http://www.gnu.org/licenses/>.
00015 
00016 #include "propertydialog.h"
00017 #include "modulemanager.h"
00018 
00019 #include <imagemoduleinterface.h>
00020 #include <audiomoduleinterface.h>
00021 #include <videomoduleinterface.h>
00022 
00023 namespace SilentEye {
00024 
00025     PropertyDialog::PropertyDialog(QWidget* parent)
00026         : QDialog(parent)
00027     {
00028         setObjectName("PropertyDialog");
00029         m_logger = new Logger(this);
00030         setupUi(this);
00031         m_md = NULL;
00032 
00033         connect(formatComboBox, SIGNAL(currentIndexChanged(const QString&)), this, SLOT(formatChanged(const QString&)));
00034     }
00035 
00036     PropertyDialog::~PropertyDialog()
00037     {
00038         if (!m_logger.isNull())
00039         {
00040             delete m_logger;
00041         }
00042     }
00043 
00044     void PropertyDialog::setMedia(Media* md)
00045     {
00046         m_md = md;
00047 
00048         pathLabel->setText(m_md->filePath());
00049 
00050         if (m_md->type() == Media::IMAGE)
00051         {
00052             Image* img = (Image*) m_md;
00053 
00054             if (img->quality() > 0)
00055             {
00056                 qualityLabel->setText(QString::number(img->quality()) + "%");
00057             }
00058             else
00059             {
00060                 qualityLabel->setText("N/A");
00061             }
00062 
00063             dimensionGroupBox->setTitle("Dimension");
00064             dimensionLabel->setText( QString::number(img->width())
00065                                      + "x"
00066                                      + QString::number(img->height()) );
00067 
00068             formatLabel->setText("N/A");
00069             qualityGroupBox->setVisible(true);
00070         }
00071         else if (m_md->type() == Media::AUDIO)
00072         {
00073             Audio* audio = (Audio*) m_md;
00074             QString format = audio->format().codec().toUpper();
00075             if (audio->format().sampleType() == QAudioFormat::UnSignedInt) {
00076                 format += " unsigned ";
00077             } else if (audio->format().sampleType() == QAudioFormat::SignedInt) {
00078                 format += " signed ";
00079             }
00080             format += QString::number(audio->format().sampleSize()) + " bit";
00081 
00082             format += ", " + QString::number(audio->format().frequency()) + " Hz";
00083             format += ", " + QString::number(floor(audio->bitRate()/1000.0)) + " kbps";
00084 
00085             if (audio->format().channels() == 1) {
00086                 format += ", mono";
00087             } else if (audio->format().channels() == 2) {
00088                 format += ", stereo";
00089             } else {
00090                 format += ", " + QString::number(audio->format().channels()) + " channels";
00091             }
00092             formatLabel->setText(format);
00093 
00094             dimensionGroupBox->setTitle("Duration");
00095             double sec = audio->duration();
00096             double val = sec/60.0;
00097             int min = floor(val);
00098             val = sec - (min*60);
00099             sec = floor(val);
00100             int mili = (val - sec)*1000;
00101 
00102             QString duration = QString::number(min).rightJustified(2, '0')
00103                                + ":" + QString::number(sec).rightJustified(2, '0')
00104                                + "." + QString::number(mili);
00105 
00106             dimensionLabel->setText(duration);
00107             qualityGroupBox->setVisible(false);
00108         }
00109 
00110         Media* media = NULL;
00111         QString capacityText = "";
00112 
00113         QMap<QString, ModuleInterface*> map;
00114         if (m_md->type() == Media::IMAGE) {
00115             map = ModuleManager::get(ModuleManager::IMAGEFORMAT);
00116         } else if (m_md->type() == Media::AUDIO) {
00117             map = ModuleManager::get(ModuleManager::AUDIOFORMAT);
00118         } else if (m_md->type() == Media::VIDEO) {
00119             map = ModuleManager::get(ModuleManager::VIDEOFORMAT);
00120         }
00121 
00122         formatComboBox->clear();
00123         m_capacityMap.clear();
00124         foreach(ModuleInterface* module, map)
00125         {
00126             if (m_md->type() == Media::IMAGE) {
00127                 Image* img = ((ImageModuleInterface*) module)->encodeImage(QPointer<Image>((Image*)m_md), true);
00128                 media = (Media*) img;
00129             } else if (m_md->type() == Media::AUDIO) {
00130                 Audio* audio = ((AudioModuleInterface*) module)->encodeAudio(QPointer<Audio>((Audio*)m_md), true);
00131                 media = (Media*) audio;
00132             } else if (m_md->type() == Media::VIDEO) {
00133                 Video* vid = ((VideoModuleInterface*) module)->encodeVideo(QPointer<Video>((Video*)m_md), true);
00134                 media = (Media*) vid;
00135             }
00136 
00137             formatComboBox->addItem(module->typeSupported());
00138             // media = ((FormatModuleInterface*)module)->encodeMedia(m_md, true);
00139             m_capacityMap[module->typeSupported()] = media->capacity();
00140             
00141             delete media;
00142         }
00143         formatChanged(formatComboBox->currentText());
00144     }
00145 
00146     void PropertyDialog::formatChanged(const QString& text) {
00147         long capacity = m_capacityMap[text];
00148         sizeLabelOctets->setText(QString::number(capacity)+" octects");
00149         sizeLabelKoctets->setText(QString::number(capacity/1024.0)+ " ko");
00150     }
00151 
00152 }