00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <omgdatafetcherwizardprogresspage.h>
00022 #include <omgdatafetcherwizardprogresswidget.h>
00023 #include <omgpluginmessenger.h>
00024 #include <omgscraperpluginregistry.h>
00025 #include <omgui.h>
00026
00027 #include <QSettings>
00028
00029
00030
00031
00032 #include <QWizard>
00033 #include <QVBoxLayout>
00034 #include <QFile>
00035
00036 OmgDataFetcherWizardProgressPage::OmgDataFetcherWizardProgressPage(QWidget *parent)
00037 : QWizardPage(parent),
00038 mpProgressWidget(new OmgDataFetcherWizardProgressWidget())
00039 {
00040 setTitle(tr("Search Progress"));
00041 QVBoxLayout *mypLayout = new QVBoxLayout;
00042 mypLayout->addWidget(mpProgressWidget);
00043 setLayout(mypLayout);
00044 }
00045 void OmgDataFetcherWizardProgressPage::setTaxonListWidget (QListWidget * thepWidget)
00046 {
00047 mpTaxonListWidget = thepWidget;
00048 }
00049 void OmgDataFetcherWizardProgressPage::search()
00050 {
00051 qDebug("Search called");
00052 mpProgressWidget->getTeResults()->clear();
00053 QStringList myTaxonList;
00054 for (int myListPosition=0; myListPosition < mpTaxonListWidget->count(); myListPosition++)
00055 {
00056 QListWidgetItem *item = mpTaxonListWidget->item( myListPosition );
00057 myTaxonList << item->text();
00058 }
00059 if (myTaxonList.size()==0)
00060 {
00061 setStatus(QString(tr("Search list is empty!")));
00062 return;
00063 }
00064
00065 QDir myOutputDir(field("leOutputPath").toString());
00066 if (!myOutputDir.isReadable())
00067 {
00068 setStatus(QString(tr("Output folder is invalid")));
00069 return;
00070 }
00071
00072
00073
00074 mRunningCount = 0;
00075 mNamesWithDataCount = 0;
00076 int myListSize = myTaxonList.size();
00077
00078
00079
00080 mpProgressWidget->getProgressBar()->setValue(0);
00081 mpProgressWidget->getProgressBar()->setMaximum(myListSize);
00082
00083
00085
00086
00087 QSettings mySettings;
00088
00089 QString myPluginName =
00090 mySettings.value("locScraper/scraperPluginName", "GBIF REST Web Service Plugin").toString();
00091 OmgScraperPluginInterface * mypScraperPlugin =
00092 OmgScraperPluginRegistry::instance()->getPlugin(myPluginName);
00093 if (!mypScraperPlugin)
00094 {
00095 setStatus(tr("Plugin matching this name could not be found!"));
00096 return;
00097 }
00098 if (!mypScraperPlugin)
00099 {
00100 setStatus(tr("Plugin loading failed!"));
00101 return;
00102 }
00103 qDebug (mypScraperPlugin->getName().toLocal8Bit());
00104 const OmgPluginMessenger * mypMessenger = mypScraperPlugin->getMessenger();
00105 connect(mypMessenger, SIGNAL(fileWritten(QString, QString, QString,int)),
00106 this, SLOT(fileWritten(QString, QString,QString, int)));
00107 connect(mypMessenger, SIGNAL(fileNotWritten(QString)),
00108 this, SLOT(fileNotWritten(QString)));
00109 connect(mypMessenger, SIGNAL(error(QString)),
00110 this, SLOT(setError(QString)));
00111 connect(mypMessenger, SIGNAL(message(QString)),
00112 this, SLOT(setStatus(QString)));
00113
00114 QApplication::setOverrideCursor( QCursor(Qt::WaitCursor) );
00115 qDebug(QString::number(myListSize).toLocal8Bit() + " items to be searched for...");
00116 int myMinimumRecords = mySettings.value("locScraper/minimumRecords",1).toInt();
00117 mypScraperPlugin->setMinimumRecords(myMinimumRecords);
00118 mpProgressWidget->getProgressBar()->reset();
00119 mpProgressWidget->getProgressBar()->show();
00120 mpProgressWidget->getProgressBar()->setValue(0);
00121 for (int myListPosition=0; myListPosition < myListSize; ++myListPosition)
00122 {
00123 QString mySearchString = myTaxonList.at(myListPosition);
00124 QString myFileName = field("leOutputPath").toString()
00125 + QDir::separator() +mySearchString + ".shp";
00126 qDebug(tr("Creating : ") + myFileName.toLocal8Bit());
00127 qDebug(tr("Calling search on scraper"));
00128 mypScraperPlugin->search(mySearchString, myFileName);
00129 qDebug(tr("Search completed on scraper"));
00130 mpProgressWidget->getProgressBar()->setValue(myListPosition+1);
00131 }
00132 QApplication::restoreOverrideCursor();
00133 mpProgressWidget->getProgressBar()->reset();
00134 mpProgressWidget->getProgressBar()->hide();
00135
00136 mpProgressWidget->getTeResults()->append("==================");
00137 mpProgressWidget->getTeResults()->append(tr("Summary:"));
00138 mpProgressWidget->getTeResults()->append(tr("Names searched : ") + QString::number(myListSize));
00139 mpProgressWidget->getTeResults()->append(tr("Number of taxa with more than ") +
00140 QString::number(myMinimumRecords) +
00141 tr(" record(s) : ") + QString::number(mNamesWithDataCount));
00142 mpProgressWidget->getTeResults()->append(tr("Total usable localities : ") + QString::number(mRunningCount));
00143 mpProgressWidget->getTeResults()->append("==================");
00144 disconnect(mypMessenger, SIGNAL(fileWritten(QString, QString, QString,int)),
00145 this, SLOT(fileWritten(QString, QString,QString, int)));
00146 disconnect(mypMessenger, SIGNAL(fileNotWritten(QString)),
00147 this, SLOT(fileNotWritten(QString)));
00148 disconnect(mypMessenger, SIGNAL(statusChanged(QString)),
00149 this, SLOT(setStatus(QString)));
00150 disconnect(mypMessenger, SIGNAL(error(QString)),
00151 this, SLOT(setError(QString)));
00152 setStatus("Search complete!");
00153
00154 }
00155
00156
00157 void OmgDataFetcherWizardProgressPage::fileWritten(QString theShapeFile, QString theTextFile,QString theTaxonName,int theCount)
00158 {
00159 setStatus(theShapeFile + tr(" written"));
00160
00161
00162 setStatus(theTextFile + tr(" written"));
00163 mpProgressWidget->getTeResults()->append(QString(theTaxonName + " (" + QString::number(theCount) + ")"));
00164 QSettings mySettings;
00165 int myMinimumRecords = mySettings.value("locScraper/minimumRecords",1).toInt();
00166 if (theCount >= myMinimumRecords)
00167 {
00168 ++mNamesWithDataCount;
00169 mRunningCount += theCount;
00170 }
00171 }
00172
00173 void OmgDataFetcherWizardProgressPage::fileNotWritten(QString theTaxonName)
00174 {
00175 setStatus(tr("Not enough data, file not written"));
00176 QString myMessage(theTaxonName + " - not enough data");
00177 mpProgressWidget->getTeResults()->textCursor().movePosition(QTextCursor::End);
00178 mpProgressWidget->getTeResults()->insertHtml("<br/><font color=\"red\">" + myMessage + "</font><font color=\"black\"> * </font><br/>");
00179 mpProgressWidget->getTeResults()->ensureCursorVisible();
00180 }
00181
00182
00183 void OmgDataFetcherWizardProgressPage::showPoints(QString theFileName)
00184 {
00185 QFile myFile( theFileName );
00186 if ( myFile.open( QIODevice::ReadOnly ) )
00187 {
00188 mpProgressWidget->getTeResults()->append(myFile.readAll());
00189 myFile.close();
00190 }
00191 else
00192 {
00193 setError(tr("Could not open the generated Points file") + " (" + theFileName.toLocal8Bit() + ")");
00194 }
00195 return ;
00196 }
00197
00198 void OmgDataFetcherWizardProgressPage::setStatus(QString theStatus)
00199 {
00200 mpProgressWidget->getLblStatus()->setText( theStatus );
00201
00202
00203
00204 }
00205
00206 void OmgDataFetcherWizardProgressPage::setError(QString theError)
00207 {
00208 mpProgressWidget->getTeResults()->append( theError );
00209
00210 }
00211