SilentEye 0.4.1

preferencedialog.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 "preferencedialog.h"
00017 #include "modulemanager.h"
00018 #include "controller.h"
00019 
00020 namespace SilentEye {
00021 
00022     PreferenceDialog::PreferenceDialog(QWidget* parent) 
00023         : QDialog(parent)
00024     {
00025         setupUi(this);
00026 
00027         unsigned short int nbImageFormat = 0;
00028         unsigned short int nbAudioFormat = 0;
00029         unsigned short int nbCrypto = 0;
00030 
00031         if(ModuleManager::count()>0)
00032         {
00033             moduleListWidget->clear();
00034 
00035             QList<ModuleInterface*> moduleList = ModuleManager::getList();
00036             for(int i=0; i<moduleList.size(); i++)
00037             {
00038                 ModuleInterface* module = moduleList.at(i);
00039 
00040                 QListWidgetItem* item = new QListWidgetItem(module->name()+" ("+module->version()+")", moduleListWidget);
00041 
00042                 if(!module->status().startsWith("ok", Qt::CaseInsensitive))
00043                 {
00044                     QBrush brush(QColor(255, 225, 225));
00045                     item->setBackground(brush);
00046                     item->setToolTip(module->status().section("|", 1, 1));
00047                 }
00048 
00049                 ModuleManager::Category cat = ModuleManager::getCategory(module);
00050                 if (cat == ModuleManager::IMAGEFORMAT)
00051                 {
00052                     item->setIcon(QPixmap(":/icons/img/imageformat.png"));
00053                     imageFormatComboBox->addItem(module->typeSupported());
00054                     m_imageFormatMap[module->typeSupported()] = nbImageFormat++;
00055                 }
00056                 else if(cat == ModuleManager::AUDIOFORMAT)
00057                 {
00058                     item->setIcon(QPixmap(":/icons/img/play.png"));
00059                     audioFormatComboBox->addItem(module->typeSupported());
00060                     m_audioFormatMap[module->typeSupported()] = nbAudioFormat++;
00061                 }
00062                 else if(cat == ModuleManager::CRYPTO)
00063                 {
00064                     item->setIcon(QPixmap(":/icons/img/crypto.png"));
00065                     cryptoComboBox->addItem(module->typeSupported());
00066                     m_cryptoMap[module->typeSupported()] = nbCrypto++;
00067                 }
00068             }
00069         }
00070 
00071         this->setConfig();
00072 
00073         connect(this, SIGNAL(accepted()), this, SLOT(accepted()));
00074         connect(this, SIGNAL(rejected()), this, SLOT(rejected()));
00075         connect(outputToolButton, SIGNAL(pressed()), this, SLOT(selectFile()));
00076         connect(proxyCheckBox, SIGNAL(stateChanged(int)), this, SLOT(useHttpProxy(int)));
00077 
00078         proxyLoginLabel->setVisible(false);
00079         proxyLoginLineEdit->setVisible(false);
00080         proxyPasswordLabel->setVisible(false);
00081         proxyPasswordLineEdit->setVisible(false);
00082     }
00083 
00084     void PreferenceDialog::setConfig()
00085     {
00086         outputLineEdit->setText(Controller::instance()->config.get("output"));
00087 
00088         // IMAGE
00089         if(m_imageFormatMap.contains(Controller::instance()->config.get("imageformat")))
00090         {
00091             imageFormatComboBox->setCurrentIndex(
00092                     m_imageFormatMap[Controller::instance()->config.get("imageformat")]
00093                     );
00094         }
00095         else
00096             imageFormatComboBox->setCurrentIndex(0);
00097 
00098         // AUDIO
00099         if(m_imageFormatMap.contains(Controller::instance()->config.get("audioformat")))
00100         {
00101             audioFormatComboBox->setCurrentIndex(
00102                     m_audioFormatMap[Controller::instance()->config.get("audioformat")]
00103                     );
00104         }
00105         else
00106             audioFormatComboBox->setCurrentIndex(0);
00107 
00108         // CRYPTO
00109         if(m_cryptoMap.contains(Controller::instance()->config.get("encryption")))
00110         {
00111             cryptoComboBox->setCurrentIndex(
00112                     m_cryptoMap[Controller::instance()->config.get("encryption")]
00113                     );
00114         }
00115         else
00116             cryptoComboBox->setCurrentIndex(0);
00117 
00118         // CHARSET
00119         if(Controller::instance()->config.get("charset")=="Latin1")
00120             charsetComboBox->setCurrentIndex(1);
00121         else if(Controller::instance()->config.get("charset")=="ASCII")
00122             charsetComboBox->setCurrentIndex(2);
00123         else
00124             charsetComboBox->setCurrentIndex(0);
00125 
00126         // PROXY
00127         int proxy = Controller::instance()->config.get("proxyenable").toInt();
00128         if (proxy == 1)
00129         {
00130             proxyCheckBox->setChecked(true);
00131             proxyHostLineEdit->setEnabled(true);
00132             proxyPortSpinBox->setEnabled(true);
00133         }
00134         proxyHostLineEdit->setText(Controller::instance()->config.get("proxyhost"));
00135         proxyPortSpinBox->setValue(Controller::instance()->config.get("proxyport").toInt());
00136     }
00137 
00138     void PreferenceDialog::accepted()
00139     {
00140         Controller::instance()->config.set("output", outputLineEdit->text());
00141         Controller::instance()->config.set("imageformat", imageFormatComboBox->currentText());
00142         Controller::instance()->config.set("audioformat", audioFormatComboBox->currentText());
00143         Controller::instance()->config.set("charset", charsetComboBox->currentText());
00144         Controller::instance()->config.set("encryption", cryptoComboBox->currentText());
00145         Controller::instance()->config.set("proxyenable", proxyCheckBox->isChecked()?"1":"0");
00146         Controller::instance()->config.set("proxyhost", proxyHostLineEdit->text());
00147         Controller::instance()->config.set("proxyport", QString::number(proxyPortSpinBox->value()));
00148         Controller::instance()->config.save();
00149         Controller::instance()->updateProxySettings();
00150     }
00151 
00152     void PreferenceDialog::rejected()
00153     {
00154         setConfig();
00155     }
00156 
00157     void PreferenceDialog::selectFile()
00158     {
00159         setCursor(Qt::WaitCursor);
00160         QFileDialog dialog(this, tr("Select default output dir"));
00161         dialog.setViewMode(QFileDialog::List);
00162         dialog.setFileMode(QFileDialog::DirectoryOnly);
00163         dialog.setDirectory(QDir::homePath());
00164         if(dialog.exec())
00165         {
00166             QStringList fileNames = dialog.selectedFiles();
00167             if(fileNames.size()>0)
00168             {
00169                 if(QFile::exists(fileNames.at(0)))
00170                     outputLineEdit->setText(fileNames.at(0));
00171                 else
00172                     QMessageBox::warning(this, tr("Warning"),
00173                                          fileNames.at(0)+"\n"+
00174                                          "The folder selected doesn't exists.\n"+
00175                                          "Please select an other destination !");
00176             }
00177         }
00178         setCursor(Qt::ArrowCursor);
00179     }
00180 
00181 
00182     void PreferenceDialog::useHttpProxy(int value)
00183     {
00184         bool enable = (value != Qt::Unchecked);
00185         proxyHostLineEdit->setEnabled(enable);
00186         proxyPortSpinBox->setEnabled(enable);
00187     }
00188 }
00189