File indexing completed on 2024-12-22 04:17:25

0001 /***************************************************************************
0002  *                                                                         *
0003  *   copyright : (C) 2009 The University of Toronto                        *
0004  *                   netterfield@astro.utoronto.ca                         *
0005  *                                                                         *
0006  *   This program is free software; you can redistribute it and/or modify  *
0007  *   it under the terms of the GNU General Public License as published by  *
0008  *   the Free Software Foundation; either version 2 of the License, or     *
0009  *   (at your option) any later version.                                   *
0010  *                                                                         *
0011  ***************************************************************************/
0012 
0013 #include <config.h>
0014 #include "baddatasourcedialog.h"
0015 #include "datasourcepluginmanager.h"
0016 #include "datasourceconfiguredialog.h"
0017 
0018 
0019 #include <QDebug>
0020 #include <QThreadPool>
0021 
0022 
0023 namespace Kst {
0024 
0025 BadDatasourceDialog::BadDatasourceDialog(QString *filename, ObjectStore *store, QWidget *parent)
0026   : QDialog(parent), _store(store), _dataSource(0), _requestID(0), _fileName(filename)  {
0027    setupUi(this);
0028 
0029    connect(_url, SIGNAL(changed(QString)), this, SLOT(fileNameChanged(QString)));
0030    connect(_configureSource, SIGNAL(clicked()), this, SLOT(showConfigWidget()));
0031    connect(_skip, SIGNAL(clicked()), this, SLOT(skip()));
0032    connect(_change, SIGNAL(clicked()), this, SLOT(change()));
0033 
0034    _label->setText(tr("%1: File not found.  ").arg(*filename));
0035    _url->setFile(*filename);
0036    filename->clear();
0037    QApplication::restoreOverrideCursor();
0038 }
0039 
0040 
0041 BadDatasourceDialog::~BadDatasourceDialog() {
0042 }
0043 
0044 void BadDatasourceDialog::showConfigWidget() {
0045   QPointer<DataSourceConfigureDialog> dialog = new DataSourceConfigureDialog(DataDialog::New, _dataSource, this);
0046   if ( dialog->exec() == QDialog::Accepted ) {
0047     fileNameChanged(_dataSource->fileName());
0048   }
0049   delete dialog;
0050 }
0051 
0052 
0053 void BadDatasourceDialog::fileNameChanged(const QString &file) {
0054   _dataSource = 0;
0055   _configureSource->setEnabled(false);
0056   _change->setEnabled(false);
0057   _fileType->setText(QString());
0058 
0059   _requestID += 1;
0060   ValidateDataSourceThread *validateDSThread = new ValidateDataSourceThread(file, _requestID);
0061   connect(validateDSThread, SIGNAL(dataSourceValid(QString,int)), this, SLOT(sourceValid(QString,int)));
0062   QThreadPool::globalInstance()->start(validateDSThread);
0063 }
0064 
0065 void BadDatasourceDialog::sourceValid(QString filename, int requestID) {
0066   if (_requestID != requestID) {
0067     return;
0068   }
0069   _dataSource = DataSourcePluginManager::findOrLoadSource(_store, filename);
0070   _fileType->setText(_dataSource->fileType());
0071   _configureSource->setEnabled(_dataSource->hasConfigWidget());
0072   _change->setEnabled(true);
0073 
0074 }
0075 
0076 void BadDatasourceDialog::skip() {
0077   _fileName->clear();
0078   close();
0079 }
0080 
0081 void BadDatasourceDialog::change() {
0082   *_fileName = _url->file();
0083   close();
0084 }
0085 
0086 }
0087 // vim: ts=2 sw=2 et