Quantum GIS API Documentation  1.7.4
src/gui/qgsencodingfiledialog.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002     qgsencodingfiledialog.cpp - File dialog which queries the encoding type
00003      --------------------------------------
00004     Date                 : 16-Feb-2005
00005     Copyright            : (C) 2005 by Marco Hugentobler
00006     email                : marco.hugentobler@autoform.ch
00007  ***************************************************************************
00008  *                                                                         *
00009  *   This program is free software; you can redistribute it and/or modify  *
00010  *   it under the terms of the GNU General Public License as published by  *
00011  *   the Free Software Foundation; either version 2 of the License, or     *
00012  *   (at your option) any later version.                                   *
00013  *                                                                         *
00014  ***************************************************************************/
00015 
00016 #include "qgsencodingfiledialog.h"
00017 #include "qgsproject.h"
00018 #include "qgslogger.h"
00019 #include "qgsvectordataprovider.h"
00020 
00021 #include <QSettings>
00022 #include <QComboBox>
00023 #include <QPushButton>
00024 #include <QLabel>
00025 #include <QLayout>
00026 #include <QTextCodec>
00027 
00028 QgsEncodingFileDialog::QgsEncodingFileDialog( QWidget * parent,
00029     const QString & caption, const QString & directory,
00030     const QString & filter, const QString & encoding )
00031     : QFileDialog( parent, caption, directory, filter )
00032 {
00033   mCancelAll       = false;
00034   mCancelAllButton = 0;
00035   mEncodingComboBox = new QComboBox( this );
00036   QLabel* l = new QLabel( tr( "Encoding:" ), this );
00037   layout()->addWidget( l );
00038   layout()->addWidget( mEncodingComboBox );
00039 
00040   mEncodingComboBox->addItems( QgsVectorDataProvider::availableEncodings() );
00041 
00042   // Use default encoding if none supplied
00043   QString enc = encoding;
00044   if ( encoding.isEmpty() )
00045   {
00046     QSettings settings;
00047     enc = settings.value( "/UI/encoding", QString( "System" ) ).toString();
00048   }
00049 
00050   // The specified decoding is added if not existing alread, and then set current.
00051   // This should select it.
00052   int encindex = mEncodingComboBox->findText( enc );
00053   if ( encindex < 0 )
00054   {
00055     mEncodingComboBox->insertItem( 0, enc );
00056     encindex = 0;
00057   }
00058   mEncodingComboBox->setCurrentIndex( encindex );
00059 
00060   // if this dialog is being invoked from QgisApp::findFiles_(), then we
00061   // need to force selection of the first filter since that corresponds to
00062   // the file name we're looking for; even if we're not here from
00063   // findFiles_(), it won't hurt to force selection of the first file filter
00064   selectFilter( filters().at( 0 ) );
00065 
00066   // Connect our slot to get a signal when the user is done with the file dialog
00067   connect( this, SIGNAL( accepted() ), this, SLOT( saveUsedEncoding() ) );
00068 
00069 
00070 }
00071 
00072 QgsEncodingFileDialog::~QgsEncodingFileDialog()
00073 {
00074 
00075 }
00076 
00077 QString QgsEncodingFileDialog::encoding() const
00078 {
00079   return mEncodingComboBox->currentText();
00080 }
00081 
00082 void QgsEncodingFileDialog::saveUsedEncoding()
00083 {
00084   QSettings settings;
00085   settings.setValue( "/UI/encoding", encoding() );
00086   QgsDebugMsg( QString( "Set encoding " + encoding() + " as default." ) );
00087 }
00088 
00089 void QgsEncodingFileDialog::addCancelAll()
00090 {
00091   if ( ! mCancelAllButton )
00092   {
00093     mCancelAllButton = new QPushButton( tr( "Cancel &All" ), NULL );
00094     layout()->addWidget( mCancelAllButton ); // Ownership transfered, no need to delete later on
00095     connect( mCancelAllButton, SIGNAL( clicked() ), this, SLOT( pbnCancelAll_clicked() ) );
00096   }
00097 }
00098 
00099 bool QgsEncodingFileDialog::cancelAll()
00100 {
00101   return mCancelAll;
00102 }
00103 
00104 void QgsEncodingFileDialog::pbnCancelAll_clicked()
00105 {
00106   mCancelAll = true;
00107   // Now, continue as the user clicked the cancel button
00108   reject();
00109 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines